mirror of
https://github.com/RPCSX/llvm.git
synced 2025-04-14 05:50:43 +00:00
IPO: Remove implicit ilist iterator conversions, NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250187 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
210a154346
commit
1e2bc42eb9
@ -223,9 +223,9 @@ CallGraphNode *ArgPromotion::PromoteArguments(CallGraphNode *CGN) {
|
|||||||
|
|
||||||
// First check: see if there are any pointer arguments! If not, quick exit.
|
// First check: see if there are any pointer arguments! If not, quick exit.
|
||||||
SmallVector<Argument*, 16> PointerArgs;
|
SmallVector<Argument*, 16> PointerArgs;
|
||||||
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I)
|
for (Argument &I : F->args())
|
||||||
if (I->getType()->isPointerTy())
|
if (I.getType()->isPointerTy())
|
||||||
PointerArgs.push_back(I);
|
PointerArgs.push_back(&I);
|
||||||
if (PointerArgs.empty()) return nullptr;
|
if (PointerArgs.empty()) return nullptr;
|
||||||
|
|
||||||
// Second check: make sure that all callers are direct callers. We can't
|
// Second check: make sure that all callers are direct callers. We can't
|
||||||
@ -468,12 +468,11 @@ bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg,
|
|||||||
|
|
||||||
// First, iterate the entry block and mark loads of (geps of) arguments as
|
// First, iterate the entry block and mark loads of (geps of) arguments as
|
||||||
// safe.
|
// safe.
|
||||||
BasicBlock *EntryBlock = Arg->getParent()->begin();
|
BasicBlock &EntryBlock = Arg->getParent()->front();
|
||||||
// Declare this here so we can reuse it
|
// Declare this here so we can reuse it
|
||||||
IndicesVector Indices;
|
IndicesVector Indices;
|
||||||
for (BasicBlock::iterator I = EntryBlock->begin(), E = EntryBlock->end();
|
for (Instruction &I : EntryBlock)
|
||||||
I != E; ++I)
|
if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
|
||||||
if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
|
||||||
Value *V = LI->getPointerOperand();
|
Value *V = LI->getPointerOperand();
|
||||||
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V)) {
|
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V)) {
|
||||||
V = GEP->getPointerOperand();
|
V = GEP->getPointerOperand();
|
||||||
@ -648,13 +647,13 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
|||||||
unsigned ArgIndex = 1;
|
unsigned ArgIndex = 1;
|
||||||
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
|
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
|
||||||
++I, ++ArgIndex) {
|
++I, ++ArgIndex) {
|
||||||
if (ByValArgsToTransform.count(I)) {
|
if (ByValArgsToTransform.count(&*I)) {
|
||||||
// Simple byval argument? Just add all the struct element types.
|
// Simple byval argument? Just add all the struct element types.
|
||||||
Type *AgTy = cast<PointerType>(I->getType())->getElementType();
|
Type *AgTy = cast<PointerType>(I->getType())->getElementType();
|
||||||
StructType *STy = cast<StructType>(AgTy);
|
StructType *STy = cast<StructType>(AgTy);
|
||||||
Params.insert(Params.end(), STy->element_begin(), STy->element_end());
|
Params.insert(Params.end(), STy->element_begin(), STy->element_end());
|
||||||
++NumByValArgsPromoted;
|
++NumByValArgsPromoted;
|
||||||
} else if (!ArgsToPromote.count(I)) {
|
} else if (!ArgsToPromote.count(&*I)) {
|
||||||
// Unchanged argument
|
// Unchanged argument
|
||||||
Params.push_back(I->getType());
|
Params.push_back(I->getType());
|
||||||
AttributeSet attrs = PAL.getParamAttributes(ArgIndex);
|
AttributeSet attrs = PAL.getParamAttributes(ArgIndex);
|
||||||
@ -672,7 +671,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
|||||||
|
|
||||||
// In this table, we will track which indices are loaded from the argument
|
// In this table, we will track which indices are loaded from the argument
|
||||||
// (where direct loads are tracked as no indices).
|
// (where direct loads are tracked as no indices).
|
||||||
ScalarizeTable &ArgIndices = ScalarizedElements[I];
|
ScalarizeTable &ArgIndices = ScalarizedElements[&*I];
|
||||||
for (User *U : I->users()) {
|
for (User *U : I->users()) {
|
||||||
Instruction *UI = cast<Instruction>(U);
|
Instruction *UI = cast<Instruction>(U);
|
||||||
Type *SrcTy;
|
Type *SrcTy;
|
||||||
@ -698,7 +697,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
|||||||
else
|
else
|
||||||
// Take any load, we will use it only to update Alias Analysis
|
// Take any load, we will use it only to update Alias Analysis
|
||||||
OrigLoad = cast<LoadInst>(UI->user_back());
|
OrigLoad = cast<LoadInst>(UI->user_back());
|
||||||
OriginalLoads[std::make_pair(I, Indices)] = OrigLoad;
|
OriginalLoads[std::make_pair(&*I, Indices)] = OrigLoad;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a parameter to the function for each element passed in.
|
// Add a parameter to the function for each element passed in.
|
||||||
@ -751,7 +750,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
|||||||
NF->setAttributes(AttributeSet::get(F->getContext(), AttributesVec));
|
NF->setAttributes(AttributeSet::get(F->getContext(), AttributesVec));
|
||||||
AttributesVec.clear();
|
AttributesVec.clear();
|
||||||
|
|
||||||
F->getParent()->getFunctionList().insert(F, NF);
|
F->getParent()->getFunctionList().insert(F->getIterator(), NF);
|
||||||
NF->takeName(F);
|
NF->takeName(F);
|
||||||
|
|
||||||
// Get the callgraph information that we need to update to reflect our
|
// Get the callgraph information that we need to update to reflect our
|
||||||
@ -782,7 +781,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
|||||||
ArgIndex = 1;
|
ArgIndex = 1;
|
||||||
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end();
|
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end();
|
||||||
I != E; ++I, ++AI, ++ArgIndex)
|
I != E; ++I, ++AI, ++ArgIndex)
|
||||||
if (!ArgsToPromote.count(I) && !ByValArgsToTransform.count(I)) {
|
if (!ArgsToPromote.count(&*I) && !ByValArgsToTransform.count(&*I)) {
|
||||||
Args.push_back(*AI); // Unmodified argument
|
Args.push_back(*AI); // Unmodified argument
|
||||||
|
|
||||||
if (CallPAL.hasAttributes(ArgIndex)) {
|
if (CallPAL.hasAttributes(ArgIndex)) {
|
||||||
@ -790,7 +789,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
|||||||
AttributesVec.
|
AttributesVec.
|
||||||
push_back(AttributeSet::get(F->getContext(), Args.size(), B));
|
push_back(AttributeSet::get(F->getContext(), Args.size(), B));
|
||||||
}
|
}
|
||||||
} else if (ByValArgsToTransform.count(I)) {
|
} else if (ByValArgsToTransform.count(&*I)) {
|
||||||
// Emit a GEP and load for each element of the struct.
|
// Emit a GEP and load for each element of the struct.
|
||||||
Type *AgTy = cast<PointerType>(I->getType())->getElementType();
|
Type *AgTy = cast<PointerType>(I->getType())->getElementType();
|
||||||
StructType *STy = cast<StructType>(AgTy);
|
StructType *STy = cast<StructType>(AgTy);
|
||||||
@ -805,14 +804,14 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
|||||||
}
|
}
|
||||||
} else if (!I->use_empty()) {
|
} else if (!I->use_empty()) {
|
||||||
// Non-dead argument: insert GEPs and loads as appropriate.
|
// Non-dead argument: insert GEPs and loads as appropriate.
|
||||||
ScalarizeTable &ArgIndices = ScalarizedElements[I];
|
ScalarizeTable &ArgIndices = ScalarizedElements[&*I];
|
||||||
// Store the Value* version of the indices in here, but declare it now
|
// Store the Value* version of the indices in here, but declare it now
|
||||||
// for reuse.
|
// for reuse.
|
||||||
std::vector<Value*> Ops;
|
std::vector<Value*> Ops;
|
||||||
for (ScalarizeTable::iterator SI = ArgIndices.begin(),
|
for (ScalarizeTable::iterator SI = ArgIndices.begin(),
|
||||||
E = ArgIndices.end(); SI != E; ++SI) {
|
E = ArgIndices.end(); SI != E; ++SI) {
|
||||||
Value *V = *AI;
|
Value *V = *AI;
|
||||||
LoadInst *OrigLoad = OriginalLoads[std::make_pair(I, SI->second)];
|
LoadInst *OrigLoad = OriginalLoads[std::make_pair(&*I, SI->second)];
|
||||||
if (!SI->second.empty()) {
|
if (!SI->second.empty()) {
|
||||||
Ops.reserve(SI->second.size());
|
Ops.reserve(SI->second.size());
|
||||||
Type *ElTy = V->getType();
|
Type *ElTy = V->getType();
|
||||||
@ -904,19 +903,19 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
|||||||
//
|
//
|
||||||
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(),
|
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(),
|
||||||
I2 = NF->arg_begin(); I != E; ++I) {
|
I2 = NF->arg_begin(); I != E; ++I) {
|
||||||
if (!ArgsToPromote.count(I) && !ByValArgsToTransform.count(I)) {
|
if (!ArgsToPromote.count(&*I) && !ByValArgsToTransform.count(&*I)) {
|
||||||
// If this is an unmodified argument, move the name and users over to the
|
// If this is an unmodified argument, move the name and users over to the
|
||||||
// new version.
|
// new version.
|
||||||
I->replaceAllUsesWith(I2);
|
I->replaceAllUsesWith(&*I2);
|
||||||
I2->takeName(I);
|
I2->takeName(&*I);
|
||||||
++I2;
|
++I2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ByValArgsToTransform.count(I)) {
|
if (ByValArgsToTransform.count(&*I)) {
|
||||||
// In the callee, we create an alloca, and store each of the new incoming
|
// In the callee, we create an alloca, and store each of the new incoming
|
||||||
// arguments into the alloca.
|
// arguments into the alloca.
|
||||||
Instruction *InsertPt = NF->begin()->begin();
|
Instruction *InsertPt = &NF->begin()->front();
|
||||||
|
|
||||||
// Just add all the struct element types.
|
// Just add all the struct element types.
|
||||||
Type *AgTy = cast<PointerType>(I->getType())->getElementType();
|
Type *AgTy = cast<PointerType>(I->getType())->getElementType();
|
||||||
@ -931,12 +930,12 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
|||||||
AgTy, TheAlloca, Idxs, TheAlloca->getName() + "." + Twine(i),
|
AgTy, TheAlloca, Idxs, TheAlloca->getName() + "." + Twine(i),
|
||||||
InsertPt);
|
InsertPt);
|
||||||
I2->setName(I->getName()+"."+Twine(i));
|
I2->setName(I->getName()+"."+Twine(i));
|
||||||
new StoreInst(I2++, Idx, InsertPt);
|
new StoreInst(&*I2++, Idx, InsertPt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Anything that used the arg should now use the alloca.
|
// Anything that used the arg should now use the alloca.
|
||||||
I->replaceAllUsesWith(TheAlloca);
|
I->replaceAllUsesWith(TheAlloca);
|
||||||
TheAlloca->takeName(I);
|
TheAlloca->takeName(&*I);
|
||||||
|
|
||||||
// If the alloca is used in a call, we must clear the tail flag since
|
// If the alloca is used in a call, we must clear the tail flag since
|
||||||
// the callee now uses an alloca from the caller.
|
// the callee now uses an alloca from the caller.
|
||||||
@ -955,14 +954,14 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
|||||||
// Otherwise, if we promoted this argument, then all users are load
|
// Otherwise, if we promoted this argument, then all users are load
|
||||||
// instructions (or GEPs with only load users), and all loads should be
|
// instructions (or GEPs with only load users), and all loads should be
|
||||||
// using the new argument that we added.
|
// using the new argument that we added.
|
||||||
ScalarizeTable &ArgIndices = ScalarizedElements[I];
|
ScalarizeTable &ArgIndices = ScalarizedElements[&*I];
|
||||||
|
|
||||||
while (!I->use_empty()) {
|
while (!I->use_empty()) {
|
||||||
if (LoadInst *LI = dyn_cast<LoadInst>(I->user_back())) {
|
if (LoadInst *LI = dyn_cast<LoadInst>(I->user_back())) {
|
||||||
assert(ArgIndices.begin()->second.empty() &&
|
assert(ArgIndices.begin()->second.empty() &&
|
||||||
"Load element should sort to front!");
|
"Load element should sort to front!");
|
||||||
I2->setName(I->getName()+".val");
|
I2->setName(I->getName()+".val");
|
||||||
LI->replaceAllUsesWith(I2);
|
LI->replaceAllUsesWith(&*I2);
|
||||||
LI->eraseFromParent();
|
LI->eraseFromParent();
|
||||||
DEBUG(dbgs() << "*** Promoted load of argument '" << I->getName()
|
DEBUG(dbgs() << "*** Promoted load of argument '" << I->getName()
|
||||||
<< "' in function '" << F->getName() << "'\n");
|
<< "' in function '" << F->getName() << "'\n");
|
||||||
@ -998,7 +997,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
|||||||
// the argument specified by ArgNo.
|
// the argument specified by ArgNo.
|
||||||
while (!GEP->use_empty()) {
|
while (!GEP->use_empty()) {
|
||||||
LoadInst *L = cast<LoadInst>(GEP->user_back());
|
LoadInst *L = cast<LoadInst>(GEP->user_back());
|
||||||
L->replaceAllUsesWith(TheArg);
|
L->replaceAllUsesWith(&*TheArg);
|
||||||
L->eraseFromParent();
|
L->eraseFromParent();
|
||||||
}
|
}
|
||||||
GEP->eraseFromParent();
|
GEP->eraseFromParent();
|
||||||
|
@ -119,7 +119,7 @@ bool ConstantMerge::runOnModule(Module &M) {
|
|||||||
// First: Find the canonical constants others will be merged with.
|
// First: Find the canonical constants others will be merged with.
|
||||||
for (Module::global_iterator GVI = M.global_begin(), E = M.global_end();
|
for (Module::global_iterator GVI = M.global_begin(), E = M.global_end();
|
||||||
GVI != E; ) {
|
GVI != E; ) {
|
||||||
GlobalVariable *GV = GVI++;
|
GlobalVariable *GV = &*GVI++;
|
||||||
|
|
||||||
// If this GV is dead, remove it.
|
// If this GV is dead, remove it.
|
||||||
GV->removeDeadConstantUsers();
|
GV->removeDeadConstantUsers();
|
||||||
@ -160,7 +160,7 @@ bool ConstantMerge::runOnModule(Module &M) {
|
|||||||
// invalidating the Constant* pointers in CMap.
|
// invalidating the Constant* pointers in CMap.
|
||||||
for (Module::global_iterator GVI = M.global_begin(), E = M.global_end();
|
for (Module::global_iterator GVI = M.global_begin(), E = M.global_end();
|
||||||
GVI != E; ) {
|
GVI != E; ) {
|
||||||
GlobalVariable *GV = GVI++;
|
GlobalVariable *GV = &*GVI++;
|
||||||
|
|
||||||
// Only process constants with initializers in the default address space.
|
// Only process constants with initializers in the default address space.
|
||||||
if (!GV->isConstant() || !GV->hasDefinitiveInitializer() ||
|
if (!GV->isConstant() || !GV->hasDefinitiveInitializer() ||
|
||||||
|
@ -237,7 +237,7 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
|
|||||||
// Create the new function body and insert it into the module...
|
// Create the new function body and insert it into the module...
|
||||||
Function *NF = Function::Create(NFTy, Fn.getLinkage());
|
Function *NF = Function::Create(NFTy, Fn.getLinkage());
|
||||||
NF->copyAttributesFrom(&Fn);
|
NF->copyAttributesFrom(&Fn);
|
||||||
Fn.getParent()->getFunctionList().insert(&Fn, NF);
|
Fn.getParent()->getFunctionList().insert(Fn.getIterator(), NF);
|
||||||
NF->takeName(&Fn);
|
NF->takeName(&Fn);
|
||||||
|
|
||||||
// Loop over all of the callers of the function, transforming the call sites
|
// Loop over all of the callers of the function, transforming the call sites
|
||||||
@ -304,8 +304,8 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
|
|||||||
for (Function::arg_iterator I = Fn.arg_begin(), E = Fn.arg_end(),
|
for (Function::arg_iterator I = Fn.arg_begin(), E = Fn.arg_end(),
|
||||||
I2 = NF->arg_begin(); I != E; ++I, ++I2) {
|
I2 = NF->arg_begin(); I != E; ++I, ++I2) {
|
||||||
// Move the name and users over to the new version.
|
// Move the name and users over to the new version.
|
||||||
I->replaceAllUsesWith(I2);
|
I->replaceAllUsesWith(&*I2);
|
||||||
I2->takeName(I);
|
I2->takeName(&*I);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Patch the pointer to LLVM function in debug info descriptor.
|
// Patch the pointer to LLVM function in debug info descriptor.
|
||||||
@ -363,12 +363,9 @@ bool DAE::RemoveDeadArgumentsFromCallers(Function &Fn)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
SmallVector<unsigned, 8> UnusedArgs;
|
SmallVector<unsigned, 8> UnusedArgs;
|
||||||
for (Function::arg_iterator I = Fn.arg_begin(), E = Fn.arg_end();
|
for (Argument &Arg : Fn.args()) {
|
||||||
I != E; ++I) {
|
if (Arg.use_empty() && !Arg.hasByValOrInAllocaAttr())
|
||||||
Argument *Arg = I;
|
UnusedArgs.push_back(Arg.getArgNo());
|
||||||
|
|
||||||
if (Arg->use_empty() && !Arg->hasByValOrInAllocaAttr())
|
|
||||||
UnusedArgs.push_back(Arg->getArgNo());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UnusedArgs.empty())
|
if (UnusedArgs.empty())
|
||||||
@ -670,7 +667,7 @@ void DAE::SurveyFunction(const Function &F) {
|
|||||||
} else {
|
} else {
|
||||||
// See what the effect of this use is (recording any uses that cause
|
// See what the effect of this use is (recording any uses that cause
|
||||||
// MaybeLive in MaybeLiveArgUses).
|
// MaybeLive in MaybeLiveArgUses).
|
||||||
Result = SurveyUses(AI, MaybeLiveArgUses);
|
Result = SurveyUses(&*AI, MaybeLiveArgUses);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the result.
|
// Mark the result.
|
||||||
@ -900,7 +897,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
NF->setAttributes(NewPAL);
|
NF->setAttributes(NewPAL);
|
||||||
// Insert the new function before the old function, so we won't be processing
|
// Insert the new function before the old function, so we won't be processing
|
||||||
// it again.
|
// it again.
|
||||||
F->getParent()->getFunctionList().insert(F, NF);
|
F->getParent()->getFunctionList().insert(F->getIterator(), NF);
|
||||||
NF->takeName(F);
|
NF->takeName(F);
|
||||||
|
|
||||||
// Loop over all of the callers of the function, transforming the call sites
|
// Loop over all of the callers of the function, transforming the call sites
|
||||||
@ -999,7 +996,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
Instruction *InsertPt = Call;
|
Instruction *InsertPt = Call;
|
||||||
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
|
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
|
||||||
BasicBlock *NewEdge = SplitEdge(New->getParent(), II->getNormalDest());
|
BasicBlock *NewEdge = SplitEdge(New->getParent(), II->getNormalDest());
|
||||||
InsertPt = NewEdge->getFirstInsertionPt();
|
InsertPt = &*NewEdge->getFirstInsertionPt();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We used to return a struct or array. Instead of doing smart stuff
|
// We used to return a struct or array. Instead of doing smart stuff
|
||||||
@ -1047,8 +1044,8 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
if (ArgAlive[i]) {
|
if (ArgAlive[i]) {
|
||||||
// If this is a live argument, move the name and users over to the new
|
// If this is a live argument, move the name and users over to the new
|
||||||
// version.
|
// version.
|
||||||
I->replaceAllUsesWith(I2);
|
I->replaceAllUsesWith(&*I2);
|
||||||
I2->takeName(I);
|
I2->takeName(&*I);
|
||||||
++I2;
|
++I2;
|
||||||
} else {
|
} else {
|
||||||
// If this argument is dead, replace any uses of it with null constants
|
// If this argument is dead, replace any uses of it with null constants
|
||||||
@ -1140,7 +1137,7 @@ bool DAE::runOnModule(Module &M) {
|
|||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ) {
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ) {
|
||||||
// Increment now, because the function will probably get removed (ie.
|
// Increment now, because the function will probably get removed (ie.
|
||||||
// replaced by a new one).
|
// replaced by a new one).
|
||||||
Function *F = I++;
|
Function *F = &*I++;
|
||||||
Changed |= RemoveDeadStuffFromFunction(F);
|
Changed |= RemoveDeadStuffFromFunction(F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ namespace {
|
|||||||
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
bool Delete =
|
bool Delete =
|
||||||
deleteStuff == (bool)Named.count(I) && !I->isDeclaration();
|
deleteStuff == (bool)Named.count(&*I) && !I->isDeclaration();
|
||||||
if (!Delete) {
|
if (!Delete) {
|
||||||
if (I->hasAvailableExternallyLinkage())
|
if (I->hasAvailableExternallyLinkage())
|
||||||
continue;
|
continue;
|
||||||
@ -103,7 +103,7 @@ namespace {
|
|||||||
// Visit the Functions.
|
// Visit the Functions.
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
||||||
bool Delete =
|
bool Delete =
|
||||||
deleteStuff == (bool)Named.count(I) && !I->isDeclaration();
|
deleteStuff == (bool)Named.count(&*I) && !I->isDeclaration();
|
||||||
if (!Delete) {
|
if (!Delete) {
|
||||||
if (I->hasAvailableExternallyLinkage())
|
if (I->hasAvailableExternallyLinkage())
|
||||||
continue;
|
continue;
|
||||||
@ -124,7 +124,7 @@ namespace {
|
|||||||
Module::alias_iterator CurI = I;
|
Module::alias_iterator CurI = I;
|
||||||
++I;
|
++I;
|
||||||
|
|
||||||
bool Delete = deleteStuff == (bool)Named.count(CurI);
|
bool Delete = deleteStuff == (bool)Named.count(&*CurI);
|
||||||
makeVisible(*CurI, Delete);
|
makeVisible(*CurI, Delete);
|
||||||
|
|
||||||
if (Delete) {
|
if (Delete) {
|
||||||
@ -143,7 +143,7 @@ namespace {
|
|||||||
|
|
||||||
}
|
}
|
||||||
CurI->replaceAllUsesWith(Declaration);
|
CurI->replaceAllUsesWith(Declaration);
|
||||||
delete CurI;
|
delete &*CurI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ struct ArgumentUsesTracker : public CaptureTracker {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (PI == U) {
|
if (PI == U) {
|
||||||
Uses.push_back(AI);
|
Uses.push_back(&*AI);
|
||||||
Found = true;
|
Found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -466,7 +466,7 @@ determinePointerReadAttrs(Argument *A,
|
|||||||
return Attribute::None;
|
return Attribute::None;
|
||||||
}
|
}
|
||||||
Captures &= !CS.doesNotCapture(A - B);
|
Captures &= !CS.doesNotCapture(A - B);
|
||||||
if (SCCNodes.count(AI))
|
if (SCCNodes.count(&*AI))
|
||||||
continue;
|
continue;
|
||||||
if (!CS.onlyReadsMemory() && !CS.onlyReadsMemory(A - B))
|
if (!CS.onlyReadsMemory() && !CS.onlyReadsMemory(A - B))
|
||||||
return Attribute::None;
|
return Attribute::None;
|
||||||
@ -551,7 +551,7 @@ bool FunctionAttrs::AddArgumentAttrs(const CallGraphSCC &SCC) {
|
|||||||
bool HasNonLocalUses = false;
|
bool HasNonLocalUses = false;
|
||||||
if (!A->hasNoCaptureAttr()) {
|
if (!A->hasNoCaptureAttr()) {
|
||||||
ArgumentUsesTracker Tracker(SCCNodes);
|
ArgumentUsesTracker Tracker(SCCNodes);
|
||||||
PointerMayBeCaptured(A, &Tracker);
|
PointerMayBeCaptured(&*A, &Tracker);
|
||||||
if (!Tracker.Captured) {
|
if (!Tracker.Captured) {
|
||||||
if (Tracker.Uses.empty()) {
|
if (Tracker.Uses.empty()) {
|
||||||
// If it's trivially not captured, mark it nocapture now.
|
// If it's trivially not captured, mark it nocapture now.
|
||||||
@ -563,7 +563,7 @@ bool FunctionAttrs::AddArgumentAttrs(const CallGraphSCC &SCC) {
|
|||||||
// If it's not trivially captured and not trivially not captured,
|
// If it's not trivially captured and not trivially not captured,
|
||||||
// then it must be calling into another function in our SCC. Save
|
// then it must be calling into another function in our SCC. Save
|
||||||
// its particulars for Argument-SCC analysis later.
|
// its particulars for Argument-SCC analysis later.
|
||||||
ArgumentGraphNode *Node = AG[A];
|
ArgumentGraphNode *Node = AG[&*A];
|
||||||
for (SmallVectorImpl<Argument *>::iterator
|
for (SmallVectorImpl<Argument *>::iterator
|
||||||
UI = Tracker.Uses.begin(),
|
UI = Tracker.Uses.begin(),
|
||||||
UE = Tracker.Uses.end();
|
UE = Tracker.Uses.end();
|
||||||
@ -582,8 +582,8 @@ bool FunctionAttrs::AddArgumentAttrs(const CallGraphSCC &SCC) {
|
|||||||
// will be dependent on the iteration order through the functions in the
|
// will be dependent on the iteration order through the functions in the
|
||||||
// SCC.
|
// SCC.
|
||||||
SmallPtrSet<Argument *, 8> Self;
|
SmallPtrSet<Argument *, 8> Self;
|
||||||
Self.insert(A);
|
Self.insert(&*A);
|
||||||
Attribute::AttrKind R = determinePointerReadAttrs(A, Self);
|
Attribute::AttrKind R = determinePointerReadAttrs(&*A, Self);
|
||||||
if (R != Attribute::None) {
|
if (R != Attribute::None) {
|
||||||
AttrBuilder B;
|
AttrBuilder B;
|
||||||
B.addAttribute(R);
|
B.addAttribute(R);
|
||||||
|
@ -497,7 +497,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) {
|
|||||||
In, GV->getName()+"."+Twine(i),
|
In, GV->getName()+"."+Twine(i),
|
||||||
GV->getThreadLocalMode(),
|
GV->getThreadLocalMode(),
|
||||||
GV->getType()->getAddressSpace());
|
GV->getType()->getAddressSpace());
|
||||||
Globals.insert(GV, NGV);
|
Globals.insert(GV->getIterator(), NGV);
|
||||||
NewGlobals.push_back(NGV);
|
NewGlobals.push_back(NGV);
|
||||||
|
|
||||||
// Calculate the known alignment of the field. If the original aggregate
|
// Calculate the known alignment of the field. If the original aggregate
|
||||||
@ -530,7 +530,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) {
|
|||||||
In, GV->getName()+"."+Twine(i),
|
In, GV->getName()+"."+Twine(i),
|
||||||
GV->getThreadLocalMode(),
|
GV->getThreadLocalMode(),
|
||||||
GV->getType()->getAddressSpace());
|
GV->getType()->getAddressSpace());
|
||||||
Globals.insert(GV, NGV);
|
Globals.insert(GV->getIterator(), NGV);
|
||||||
NewGlobals.push_back(NGV);
|
NewGlobals.push_back(NGV);
|
||||||
|
|
||||||
// Calculate the known alignment of the field. If the original aggregate
|
// Calculate the known alignment of the field. If the original aggregate
|
||||||
@ -935,7 +935,7 @@ OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, CallInst *CI, Type *AllocTy,
|
|||||||
cast<StoreInst>(InitBool->user_back())->eraseFromParent();
|
cast<StoreInst>(InitBool->user_back())->eraseFromParent();
|
||||||
delete InitBool;
|
delete InitBool;
|
||||||
} else
|
} else
|
||||||
GV->getParent()->getGlobalList().insert(GV, InitBool);
|
GV->getParent()->getGlobalList().insert(GV->getIterator(), InitBool);
|
||||||
|
|
||||||
// Now the GV is dead, nuke it and the malloc..
|
// Now the GV is dead, nuke it and the malloc..
|
||||||
GV->eraseFromParent();
|
GV->eraseFromParent();
|
||||||
@ -1336,7 +1336,8 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, CallInst *CI,
|
|||||||
|
|
||||||
// Split the basic block at the old malloc.
|
// Split the basic block at the old malloc.
|
||||||
BasicBlock *OrigBB = CI->getParent();
|
BasicBlock *OrigBB = CI->getParent();
|
||||||
BasicBlock *ContBB = OrigBB->splitBasicBlock(CI, "malloc_cont");
|
BasicBlock *ContBB =
|
||||||
|
OrigBB->splitBasicBlock(CI->getIterator(), "malloc_cont");
|
||||||
|
|
||||||
// Create the block to check the first condition. Put all these blocks at the
|
// Create the block to check the first condition. Put all these blocks at the
|
||||||
// end of the function as they are unlikely to be executed.
|
// end of the function as they are unlikely to be executed.
|
||||||
@ -1499,7 +1500,8 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV, CallInst *CI,
|
|||||||
// (2048 bytes currently), as we don't want to introduce a 16M global or
|
// (2048 bytes currently), as we don't want to introduce a 16M global or
|
||||||
// something.
|
// something.
|
||||||
if (NElements->getZExtValue() * DL.getTypeAllocSize(AllocTy) < 2048) {
|
if (NElements->getZExtValue() * DL.getTypeAllocSize(AllocTy) < 2048) {
|
||||||
GVI = OptimizeGlobalAddressOfMalloc(GV, CI, AllocTy, NElements, DL, TLI);
|
GVI = OptimizeGlobalAddressOfMalloc(GV, CI, AllocTy, NElements, DL, TLI)
|
||||||
|
->getIterator();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1545,7 +1547,8 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV, CallInst *CI,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GVI = PerformHeapAllocSRoA(GV, CI, getMallocArraySize(CI, DL, TLI, true),
|
GVI = PerformHeapAllocSRoA(GV, CI, getMallocArraySize(CI, DL, TLI, true),
|
||||||
DL, TLI);
|
DL, TLI)
|
||||||
|
->getIterator();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1620,7 +1623,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
|
|||||||
GV->getName()+".b",
|
GV->getName()+".b",
|
||||||
GV->getThreadLocalMode(),
|
GV->getThreadLocalMode(),
|
||||||
GV->getType()->getAddressSpace());
|
GV->getType()->getAddressSpace());
|
||||||
GV->getParent()->getGlobalList().insert(GV, NewGV);
|
GV->getParent()->getGlobalList().insert(GV->getIterator(), NewGV);
|
||||||
|
|
||||||
Constant *InitVal = GV->getInitializer();
|
Constant *InitVal = GV->getInitializer();
|
||||||
assert(InitVal->getType() != Type::getInt1Ty(GV->getContext()) &&
|
assert(InitVal->getType() != Type::getInt1Ty(GV->getContext()) &&
|
||||||
@ -1801,7 +1804,7 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
|
|||||||
} else if (!GV->getInitializer()->getType()->isSingleValueType()) {
|
} else if (!GV->getInitializer()->getType()->isSingleValueType()) {
|
||||||
const DataLayout &DL = GV->getParent()->getDataLayout();
|
const DataLayout &DL = GV->getParent()->getDataLayout();
|
||||||
if (GlobalVariable *FirstNewGV = SRAGlobal(GV, DL)) {
|
if (GlobalVariable *FirstNewGV = SRAGlobal(GV, DL)) {
|
||||||
GVI = FirstNewGV; // Don't skip the newly produced globals!
|
GVI = FirstNewGV->getIterator(); // Don't skip the newly produced globals!
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (GS.StoredType == GlobalStatus::StoredOnce && GS.StoredOnceValue) {
|
} else if (GS.StoredType == GlobalStatus::StoredOnce && GS.StoredOnceValue) {
|
||||||
@ -1823,7 +1826,7 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
|
|||||||
GV->eraseFromParent();
|
GV->eraseFromParent();
|
||||||
++NumDeleted;
|
++NumDeleted;
|
||||||
} else {
|
} else {
|
||||||
GVI = GV;
|
GVI = GV->getIterator();
|
||||||
}
|
}
|
||||||
++NumSubstitute;
|
++NumSubstitute;
|
||||||
return true;
|
return true;
|
||||||
@ -1898,7 +1901,7 @@ bool GlobalOpt::OptimizeFunctions(Module &M) {
|
|||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
// Optimize functions.
|
// Optimize functions.
|
||||||
for (Module::iterator FI = M.begin(), E = M.end(); FI != E; ) {
|
for (Module::iterator FI = M.begin(), E = M.end(); FI != E; ) {
|
||||||
Function *F = FI++;
|
Function *F = &*FI++;
|
||||||
// Functions without names cannot be referenced outside this module.
|
// Functions without names cannot be referenced outside this module.
|
||||||
if (!F->hasName() && !F->isDeclaration() && !F->hasLocalLinkage())
|
if (!F->hasName() && !F->isDeclaration() && !F->hasLocalLinkage())
|
||||||
F->setLinkage(GlobalValue::InternalLinkage);
|
F->setLinkage(GlobalValue::InternalLinkage);
|
||||||
@ -1940,7 +1943,7 @@ bool GlobalOpt::OptimizeGlobalVars(Module &M) {
|
|||||||
|
|
||||||
for (Module::global_iterator GVI = M.global_begin(), E = M.global_end();
|
for (Module::global_iterator GVI = M.global_begin(), E = M.global_end();
|
||||||
GVI != E; ) {
|
GVI != E; ) {
|
||||||
GlobalVariable *GV = GVI++;
|
GlobalVariable *GV = &*GVI++;
|
||||||
// Global variables without names cannot be referenced outside this module.
|
// Global variables without names cannot be referenced outside this module.
|
||||||
if (!GV->hasName() && !GV->isDeclaration() && !GV->hasLocalLinkage())
|
if (!GV->hasName() && !GV->isDeclaration() && !GV->hasLocalLinkage())
|
||||||
GV->setLinkage(GlobalValue::InternalLinkage);
|
GV->setLinkage(GlobalValue::InternalLinkage);
|
||||||
@ -2438,7 +2441,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
|
|||||||
InstResult = AllocaTmps.back().get();
|
InstResult = AllocaTmps.back().get();
|
||||||
DEBUG(dbgs() << "Found an alloca. Result: " << *InstResult << "\n");
|
DEBUG(dbgs() << "Found an alloca. Result: " << *InstResult << "\n");
|
||||||
} else if (isa<CallInst>(CurInst) || isa<InvokeInst>(CurInst)) {
|
} else if (isa<CallInst>(CurInst) || isa<InvokeInst>(CurInst)) {
|
||||||
CallSite CS(CurInst);
|
CallSite CS(&*CurInst);
|
||||||
|
|
||||||
// Debug info can safely be ignored here.
|
// Debug info can safely be ignored here.
|
||||||
if (isa<DbgInfoIntrinsic>(CS.getInstruction())) {
|
if (isa<DbgInfoIntrinsic>(CS.getInstruction())) {
|
||||||
@ -2604,7 +2607,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
|
|||||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(InstResult))
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(InstResult))
|
||||||
InstResult = ConstantFoldConstantExpression(CE, DL, TLI);
|
InstResult = ConstantFoldConstantExpression(CE, DL, TLI);
|
||||||
|
|
||||||
setVal(CurInst, InstResult);
|
setVal(&*CurInst, InstResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we just processed an invoke, we finished evaluating the block.
|
// If we just processed an invoke, we finished evaluating the block.
|
||||||
@ -2635,7 +2638,7 @@ bool Evaluator::EvaluateFunction(Function *F, Constant *&RetVal,
|
|||||||
unsigned ArgNo = 0;
|
unsigned ArgNo = 0;
|
||||||
for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end(); AI != E;
|
for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end(); AI != E;
|
||||||
++AI, ++ArgNo)
|
++AI, ++ArgNo)
|
||||||
setVal(AI, ActualArgs[ArgNo]);
|
setVal(&*AI, ActualArgs[ArgNo]);
|
||||||
|
|
||||||
// ExecutedBlocks - We only handle non-looping, non-recursive code. As such,
|
// ExecutedBlocks - We only handle non-looping, non-recursive code. As such,
|
||||||
// we can only evaluate any one basic block at most once. This set keeps
|
// we can only evaluate any one basic block at most once. This set keeps
|
||||||
@ -2643,7 +2646,7 @@ bool Evaluator::EvaluateFunction(Function *F, Constant *&RetVal,
|
|||||||
SmallPtrSet<BasicBlock*, 32> ExecutedBlocks;
|
SmallPtrSet<BasicBlock*, 32> ExecutedBlocks;
|
||||||
|
|
||||||
// CurBB - The current basic block we're evaluating.
|
// CurBB - The current basic block we're evaluating.
|
||||||
BasicBlock *CurBB = F->begin();
|
BasicBlock *CurBB = &F->front();
|
||||||
|
|
||||||
BasicBlock::iterator CurInst = CurBB->begin();
|
BasicBlock::iterator CurInst = CurBB->begin();
|
||||||
|
|
||||||
@ -2894,15 +2897,15 @@ bool GlobalOpt::OptimizeGlobalAliases(Module &M) {
|
|||||||
|
|
||||||
if (RenameTarget) {
|
if (RenameTarget) {
|
||||||
// Give the aliasee the name, linkage and other attributes of the alias.
|
// Give the aliasee the name, linkage and other attributes of the alias.
|
||||||
Target->takeName(J);
|
Target->takeName(&*J);
|
||||||
Target->setLinkage(J->getLinkage());
|
Target->setLinkage(J->getLinkage());
|
||||||
Target->setVisibility(J->getVisibility());
|
Target->setVisibility(J->getVisibility());
|
||||||
Target->setDLLStorageClass(J->getDLLStorageClass());
|
Target->setDLLStorageClass(J->getDLLStorageClass());
|
||||||
|
|
||||||
if (Used.usedErase(J))
|
if (Used.usedErase(&*J))
|
||||||
Used.usedInsert(Target);
|
Used.usedInsert(Target);
|
||||||
|
|
||||||
if (Used.compilerUsedErase(J))
|
if (Used.compilerUsedErase(&*J))
|
||||||
Used.compilerUsedInsert(Target);
|
Used.compilerUsedInsert(Target);
|
||||||
} else if (mayHaveOtherReferences(*J, Used))
|
} else if (mayHaveOtherReferences(*J, Used))
|
||||||
continue;
|
continue;
|
||||||
|
@ -202,16 +202,16 @@ bool InternalizePass::runOnModule(Module &M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mark all functions not in the api as internal.
|
// Mark all functions not in the api as internal.
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
for (Function &I : M) {
|
||||||
if (!maybeInternalize(*I, ExternalComdats))
|
if (!maybeInternalize(I, ExternalComdats))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (ExternalNode)
|
if (ExternalNode)
|
||||||
// Remove a callgraph edge from the external node to this function.
|
// Remove a callgraph edge from the external node to this function.
|
||||||
ExternalNode->removeOneAbstractEdgeTo((*CG)[I]);
|
ExternalNode->removeOneAbstractEdgeTo((*CG)[&I]);
|
||||||
|
|
||||||
++NumFunctions;
|
++NumFunctions;
|
||||||
DEBUG(dbgs() << "Internalizing func " << I->getName() << "\n");
|
DEBUG(dbgs() << "Internalizing func " << I.getName() << "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never internalize the llvm.used symbol. It is used to implement
|
// Never internalize the llvm.used symbol. It is used to implement
|
||||||
|
@ -259,7 +259,7 @@ bool BlockExtractorPass::runOnModule(Module &M) {
|
|||||||
// Figure out which index the basic block is in its function.
|
// Figure out which index the basic block is in its function.
|
||||||
Function::iterator BBI = MF->begin();
|
Function::iterator BBI = MF->begin();
|
||||||
std::advance(BBI, std::distance(F->begin(), Function::iterator(BB)));
|
std::advance(BBI, std::distance(F->begin(), Function::iterator(BB)));
|
||||||
TranslatedBlocksToNotExtract.insert(BBI);
|
TranslatedBlocksToNotExtract.insert(&*BBI);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!BlocksToNotExtractByName.empty()) {
|
while (!BlocksToNotExtractByName.empty()) {
|
||||||
@ -278,7 +278,7 @@ bool BlockExtractorPass::runOnModule(Module &M) {
|
|||||||
BasicBlock &BB = *BI;
|
BasicBlock &BB = *BI;
|
||||||
if (BB.getName() != BlockName) continue;
|
if (BB.getName() != BlockName) continue;
|
||||||
|
|
||||||
TranslatedBlocksToNotExtract.insert(BI);
|
TranslatedBlocksToNotExtract.insert(&*BI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,8 +291,8 @@ bool BlockExtractorPass::runOnModule(Module &M) {
|
|||||||
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
|
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
|
||||||
SplitLandingPadPreds(&*F);
|
SplitLandingPadPreds(&*F);
|
||||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
|
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
|
||||||
if (!TranslatedBlocksToNotExtract.count(BB))
|
if (!TranslatedBlocksToNotExtract.count(&*BB))
|
||||||
BlocksToExtract.push_back(BB);
|
BlocksToExtract.push_back(&*BB);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i = 0, e = BlocksToExtract.size(); i != e; ++i) {
|
for (unsigned i = 0, e = BlocksToExtract.size(); i != e; ++i) {
|
||||||
|
@ -1121,7 +1121,7 @@ int FunctionComparator::cmpBasicBlocks(const BasicBlock *BBL,
|
|||||||
BasicBlock::const_iterator InstR = BBR->begin(), InstRE = BBR->end();
|
BasicBlock::const_iterator InstR = BBR->begin(), InstRE = BBR->end();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (int Res = cmpValues(InstL, InstR))
|
if (int Res = cmpValues(&*InstL, &*InstR))
|
||||||
return Res;
|
return Res;
|
||||||
|
|
||||||
const GetElementPtrInst *GEPL = dyn_cast<GetElementPtrInst>(InstL);
|
const GetElementPtrInst *GEPL = dyn_cast<GetElementPtrInst>(InstL);
|
||||||
@ -1139,7 +1139,7 @@ int FunctionComparator::cmpBasicBlocks(const BasicBlock *BBL,
|
|||||||
if (int Res = cmpGEPs(GEPL, GEPR))
|
if (int Res = cmpGEPs(GEPL, GEPR))
|
||||||
return Res;
|
return Res;
|
||||||
} else {
|
} else {
|
||||||
if (int Res = cmpOperations(InstL, InstR))
|
if (int Res = cmpOperations(&*InstL, &*InstR))
|
||||||
return Res;
|
return Res;
|
||||||
assert(InstL->getNumOperands() == InstR->getNumOperands());
|
assert(InstL->getNumOperands() == InstR->getNumOperands());
|
||||||
|
|
||||||
@ -1207,7 +1207,7 @@ int FunctionComparator::compare() {
|
|||||||
ArgRI = FnR->arg_begin(),
|
ArgRI = FnR->arg_begin(),
|
||||||
ArgLE = FnL->arg_end();
|
ArgLE = FnL->arg_end();
|
||||||
ArgLI != ArgLE; ++ArgLI, ++ArgRI) {
|
ArgLI != ArgLE; ++ArgLI, ++ArgRI) {
|
||||||
if (cmpValues(ArgLI, ArgRI) != 0)
|
if (cmpValues(&*ArgLI, &*ArgRI) != 0)
|
||||||
llvm_unreachable("Arguments repeat!");
|
llvm_unreachable("Arguments repeat!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1658,9 +1658,8 @@ void MergeFunctions::writeThunk(Function *F, Function *G) {
|
|||||||
SmallVector<Value *, 16> Args;
|
SmallVector<Value *, 16> Args;
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
FunctionType *FFTy = F->getFunctionType();
|
FunctionType *FFTy = F->getFunctionType();
|
||||||
for (Function::arg_iterator AI = NewG->arg_begin(), AE = NewG->arg_end();
|
for (Argument & AI : NewG->args()) {
|
||||||
AI != AE; ++AI) {
|
Args.push_back(createCast(Builder, &AI, FFTy->getParamType(i)));
|
||||||
Args.push_back(createCast(Builder, (Value*)AI, FFTy->getParamType(i)));
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ ModulePass* llvm::createPartialInliningPass() { return new PartialInliner(); }
|
|||||||
|
|
||||||
Function* PartialInliner::unswitchFunction(Function* F) {
|
Function* PartialInliner::unswitchFunction(Function* F) {
|
||||||
// First, verify that this function is an unswitching candidate...
|
// First, verify that this function is an unswitching candidate...
|
||||||
BasicBlock* entryBlock = F->begin();
|
BasicBlock *entryBlock = &F->front();
|
||||||
BranchInst *BR = dyn_cast<BranchInst>(entryBlock->getTerminator());
|
BranchInst *BR = dyn_cast<BranchInst>(entryBlock->getTerminator());
|
||||||
if (!BR || BR->isUnconditional())
|
if (!BR || BR->isUnconditional())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -89,9 +89,9 @@ Function* PartialInliner::unswitchFunction(Function* F) {
|
|||||||
// of which will go outside.
|
// of which will go outside.
|
||||||
BasicBlock* preReturn = newReturnBlock;
|
BasicBlock* preReturn = newReturnBlock;
|
||||||
newReturnBlock = newReturnBlock->splitBasicBlock(
|
newReturnBlock = newReturnBlock->splitBasicBlock(
|
||||||
newReturnBlock->getFirstNonPHI());
|
newReturnBlock->getFirstNonPHI()->getIterator());
|
||||||
BasicBlock::iterator I = preReturn->begin();
|
BasicBlock::iterator I = preReturn->begin();
|
||||||
BasicBlock::iterator Ins = newReturnBlock->begin();
|
Instruction *Ins = &newReturnBlock->front();
|
||||||
while (I != preReturn->end()) {
|
while (I != preReturn->end()) {
|
||||||
PHINode* OldPhi = dyn_cast<PHINode>(I);
|
PHINode* OldPhi = dyn_cast<PHINode>(I);
|
||||||
if (!OldPhi) break;
|
if (!OldPhi) break;
|
||||||
@ -100,7 +100,7 @@ Function* PartialInliner::unswitchFunction(Function* F) {
|
|||||||
OldPhi->replaceAllUsesWith(retPhi);
|
OldPhi->replaceAllUsesWith(retPhi);
|
||||||
Ins = newReturnBlock->getFirstNonPHI();
|
Ins = newReturnBlock->getFirstNonPHI();
|
||||||
|
|
||||||
retPhi->addIncoming(I, preReturn);
|
retPhi->addIncoming(&*I, preReturn);
|
||||||
retPhi->addIncoming(OldPhi->getIncomingValueForBlock(newEntryBlock),
|
retPhi->addIncoming(OldPhi->getIncomingValueForBlock(newEntryBlock),
|
||||||
newEntryBlock);
|
newEntryBlock);
|
||||||
OldPhi->removeIncomingValue(newEntryBlock);
|
OldPhi->removeIncomingValue(newEntryBlock);
|
||||||
@ -116,7 +116,7 @@ Function* PartialInliner::unswitchFunction(Function* F) {
|
|||||||
FE = duplicateFunction->end(); FI != FE; ++FI)
|
FE = duplicateFunction->end(); FI != FE; ++FI)
|
||||||
if (&*FI != newEntryBlock && &*FI != newReturnBlock &&
|
if (&*FI != newEntryBlock && &*FI != newReturnBlock &&
|
||||||
&*FI != newNonReturnBlock)
|
&*FI != newNonReturnBlock)
|
||||||
toExtract.push_back(FI);
|
toExtract.push_back(&*FI);
|
||||||
|
|
||||||
// The CodeExtractor needs a dominator tree.
|
// The CodeExtractor needs a dominator tree.
|
||||||
DominatorTree DT;
|
DominatorTree DT;
|
||||||
|
@ -233,7 +233,7 @@ bool PruneEH::SimplifyFunction(Function *F) {
|
|||||||
|
|
||||||
// Remove the uncond branch and add an unreachable.
|
// Remove the uncond branch and add an unreachable.
|
||||||
BB->getInstList().pop_back();
|
BB->getInstList().pop_back();
|
||||||
new UnreachableInst(BB->getContext(), BB);
|
new UnreachableInst(BB->getContext(), &*BB);
|
||||||
|
|
||||||
DeleteBasicBlock(New); // Delete the new BB.
|
DeleteBasicBlock(New); // Delete the new BB.
|
||||||
MadeChange = true;
|
MadeChange = true;
|
||||||
|
@ -47,7 +47,7 @@ bool StripDeadPrototypesPass::runOnModule(Module &M) {
|
|||||||
|
|
||||||
// Erase dead function prototypes.
|
// Erase dead function prototypes.
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ) {
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ) {
|
||||||
Function *F = I++;
|
Function *F = &*I++;
|
||||||
// Function must be a prototype and unused.
|
// Function must be a prototype and unused.
|
||||||
if (F->isDeclaration() && F->use_empty()) {
|
if (F->isDeclaration() && F->use_empty()) {
|
||||||
F->eraseFromParent();
|
F->eraseFromParent();
|
||||||
@ -59,7 +59,7 @@ bool StripDeadPrototypesPass::runOnModule(Module &M) {
|
|||||||
// Erase dead global var prototypes.
|
// Erase dead global var prototypes.
|
||||||
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
||||||
I != E; ) {
|
I != E; ) {
|
||||||
GlobalVariable *GV = I++;
|
GlobalVariable *GV = &*I++;
|
||||||
// Global must be a prototype and unused.
|
// Global must be a prototype and unused.
|
||||||
if (GV->isDeclaration() && GV->use_empty())
|
if (GV->isDeclaration() && GV->use_empty())
|
||||||
GV->eraseFromParent();
|
GV->eraseFromParent();
|
||||||
|
@ -211,13 +211,13 @@ static bool StripSymbolNames(Module &M, bool PreserveDbgInfo) {
|
|||||||
|
|
||||||
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
if (I->hasLocalLinkage() && llvmUsedValues.count(I) == 0)
|
if (I->hasLocalLinkage() && llvmUsedValues.count(&*I) == 0)
|
||||||
if (!PreserveDbgInfo || !I->getName().startswith("llvm.dbg"))
|
if (!PreserveDbgInfo || !I->getName().startswith("llvm.dbg"))
|
||||||
I->setName(""); // Internal symbols can't participate in linkage
|
I->setName(""); // Internal symbols can't participate in linkage
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
||||||
if (I->hasLocalLinkage() && llvmUsedValues.count(I) == 0)
|
if (I->hasLocalLinkage() && llvmUsedValues.count(&*I) == 0)
|
||||||
if (!PreserveDbgInfo || !I->getName().startswith("llvm.dbg"))
|
if (!PreserveDbgInfo || !I->getName().startswith("llvm.dbg"))
|
||||||
I->setName(""); // Internal symbols can't participate in linkage
|
I->setName(""); // Internal symbols can't participate in linkage
|
||||||
StripSymtab(I->getValueSymbolTable(), PreserveDbgInfo);
|
StripSymtab(I->getValueSymbolTable(), PreserveDbgInfo);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user