Skip to content

Commit 6f8865b

Browse files
committed
Two changes:
1. Don't scan to the end of alloca instructions in the caller function to insert inlined allocas, just insert at the top. This saves a lot of time inlining into functions with a lot of allocas. 2. Use splice to move the alloca instructions over, instead of remove/insert. This allows us to transfer a block at a time, and eliminates a bunch of silly symbol table manipulations. This speeds up the inliner on the testcase in PR209 from 1.73s -> 1.04s (67%) llvm-svn: 11118
1 parent dbf4b42 commit 6f8865b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool llvm::InlineFunction(CallSite CS) {
7373
// Clone the entire body of the callee into the caller.
7474
CloneFunctionInto(Caller, CalledFunc, ValueMap, Returns, ".i");
7575
}
76-
76+
7777
// Remember the first block that is newly cloned over.
7878
Function::iterator FirstNewBlock = LastBlock; ++FirstNewBlock;
7979

@@ -84,14 +84,21 @@ bool llvm::InlineFunction(CallSite CS) {
8484
//
8585
if (isa<AllocaInst>(FirstNewBlock->begin())) {
8686
BasicBlock::iterator InsertPoint = Caller->begin()->begin();
87-
while (isa<AllocaInst>(InsertPoint)) ++InsertPoint;
88-
8987
for (BasicBlock::iterator I = FirstNewBlock->begin(),
9088
E = FirstNewBlock->end(); I != E; )
9189
if (AllocaInst *AI = dyn_cast<AllocaInst>(I++))
9290
if (isa<Constant>(AI->getArraySize())) {
93-
FirstNewBlock->getInstList().remove(AI);
94-
Caller->front().getInstList().insert(InsertPoint, AI);
91+
// Scan for the block of allocas that we can move over.
92+
while (isa<AllocaInst>(I) &&
93+
isa<Constant>(cast<AllocaInst>(I)->getArraySize()))
94+
++I;
95+
96+
// Transfer all of the allocas over in a block. Using splice means
97+
// that they instructions aren't removed from the symbol table, then
98+
// reinserted.
99+
Caller->front().getInstList().splice(InsertPoint,
100+
FirstNewBlock->getInstList(),
101+
AI, I);
95102
}
96103
}
97104

0 commit comments

Comments
 (0)