llvm.org GIT mirror llvm / 4983b99
Simplify and fix incorrect comment. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208272 91177308-0d34-0410-b5e6-96231b3b80d8 Richard Smith 6 years ago
1 changed file(s) with 15 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
135135 AU.addRequired();
136136 }
137137
138 /// CanTRE - Scan the specified basic block for alloca instructions.
139 /// If it contains any that are variable-sized or not in the entry block,
140 /// returns false.
141 static bool CanTRE(AllocaInst *AI) {
142 // Because of PR962, we don't TRE allocas outside the entry block.
143
144 // If this alloca is in the body of the function, or if it is a variable
145 // sized allocation, we cannot tail call eliminate calls marked 'tail'
146 // with this mechanism.
147 BasicBlock *BB = AI->getParent();
148 return BB == &BB->getParent()->getEntryBlock() &&
149 isa(AI->getArraySize());
138 /// \brief Scan the specified function for alloca instructions.
139 /// If it contains any dynamic allocas, returns false.
140 static bool CanTRE(Function &F) {
141 // Because of PR962, we don't TRE dynamic allocas.
142 for (auto &BB : F) {
143 for (auto &I : BB) {
144 if (AllocaInst *AI = dyn_cast(&I)) {
145 if (!AI->isStaticAlloca())
146 return false;
147 }
148 }
149 }
150
151 return true;
150152 }
151153
152154 bool TailCallElim::runOnFunction(Function &F) {
389391 // marked with the 'tail' attribute, because doing so would cause the stack
390392 // size to increase (real TRE would deallocate variable sized allocas, TRE
391393 // doesn't).
392 bool CanTRETailMarkedCall = true;
393
394 // Find dynamic allocas.
395 for (Function::iterator BB = F.begin(), EE = F.end(); BB != EE; ++BB) {
396 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
397 if (AllocaInst *AI = dyn_cast(I)) {
398 CanTRETailMarkedCall &= CanTRE(AI);
399 }
400 }
401 }
394 bool CanTRETailMarkedCall = CanTRE(F);
402395
403396 // Change any tail recursive calls to loops.
404397 //