llvm.org GIT mirror llvm / d8b4fb4
(Almost) always call reserveOperandSpace() on newly created PHINodes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128535 91177308-0d34-0410-b5e6-96231b3b80d8 Jay Foad 8 years ago
26 changed file(s) with 54 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
551551 Builder.SetInsertPoint(MergeBB);
552552 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
553553 "iftmp");
554 PN->reserveOperandSpace(2);
554555
555556 PN->addIncoming(ThenV, ThenBB);
556557 PN->addIncoming(ElseV, ElseBB);
592593
593594 // Start the PHI node with an entry for Start.
594595 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
596 Variable->reserveOperandSpace(2);
595597 Variable->addIncoming(StartVal, PreheaderBB);
596598
597599 // Within the loop, the variable is defined equal to the PHI node. If it
655655 Builder.SetInsertPoint(MergeBB);
656656 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
657657 "iftmp");
658 PN->reserveOperandSpace(2);
658659
659660 PN->addIncoming(ThenV, ThenBB);
660661 PN->addIncoming(ElseV, ElseBB);
696697
697698 // Start the PHI node with an entry for Start.
698699 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
700 Variable->reserveOperandSpace(2);
699701 Variable->addIncoming(StartVal, PreheaderBB);
700702
701703 // Within the loop, the variable is defined equal to the PHI node. If it
751751 Builder.SetInsertPoint(MergeBB);
752752 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
753753 "iftmp");
754 PN->reserveOperandSpace(2);
754755
755756 PN->addIncoming(ThenV, ThenBB);
756757 PN->addIncoming(ElseV, ElseBB);
931931 Value *StepV = expandCodeFor(Step, IntTy, L->getHeader()->begin());
932932
933933 // Create the PHI.
934 Builder.SetInsertPoint(L->getHeader(), L->getHeader()->begin());
934 BasicBlock *Header = L->getHeader();
935 Builder.SetInsertPoint(Header, Header->begin());
936 pred_iterator HPB = pred_begin(Header), HPE = pred_end(Header);
935937 PHINode *PN = Builder.CreatePHI(ExpandTy, "lsr.iv");
938 PN->reserveOperandSpace(std::distance(HPB, HPE));
936939 rememberInstruction(PN);
937940
938941 // Create the step instructions and populate the PHI.
939 BasicBlock *Header = L->getHeader();
940 for (pred_iterator HPI = pred_begin(Header), HPE = pred_end(Header);
941 HPI != HPE; ++HPI) {
942 for (pred_iterator HPI = HPB; HPI != HPE; ++HPI) {
942943 BasicBlock *Pred = *HPI;
943944
944945 // Add a start value.
11401141 // Create and insert the PHI node for the induction variable in the
11411142 // specified loop.
11421143 BasicBlock *Header = L->getHeader();
1144 pred_iterator HPB = pred_begin(Header), HPE = pred_end(Header);
11431145 CanonicalIV = PHINode::Create(Ty, "indvar", Header->begin());
1146 CanonicalIV->reserveOperandSpace(std::distance(HPB, HPE));
11441147 rememberInstruction(CanonicalIV);
11451148
11461149 Constant *One = ConstantInt::get(Ty, 1);
1147 for (pred_iterator HPI = pred_begin(Header), HPE = pred_end(Header);
1148 HPI != HPE; ++HPI) {
1150 for (pred_iterator HPI = HPB; HPI != HPE; ++HPI) {
11491151 BasicBlock *HP = *HPI;
11501152 if (L->contains(HP)) {
11511153 // Insert a unit add instruction right before the terminator
440440 // in NewBB.
441441 PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".unwind",
442442 NewBB);
443 NewPN->reserveOperandSpace(PN->getNumIncomingValues());
443444 // Add an entry for each unwind edge, using the value from the old PHI.
444445 for (pred_iterator PI = PB; PI != PE; ++PI)
445446 NewPN->addIncoming(PN->getIncomingValueForBlock(*PI), *PI);
11921192 const StructType *ST =
11931193 cast(cast(PN->getType())->getElementType());
11941194
1195 Result =
1195 PHINode *NewPN =
11961196 PHINode::Create(PointerType::getUnqual(ST->getElementType(FieldNo)),
11971197 PN->getName()+".f"+Twine(FieldNo), PN);
1198 NewPN->reserveOperandSpace(PN->getNumIncomingValues());
1199 Result = NewPN;
11981200 PHIsToRewrite.push_back(std::make_pair(PN, FieldNo));
11991201 } else {
12001202 llvm_unreachable("Unknown usable value");
431431 // splitBasicBlock call.
432432 PHINode* PHI = PHINode::Create(Type::getInt32Ty(Inst->getContext()),
433433 "SetJmpReturn", Inst);
434 PHI->reserveOperandSpace(2);
434435
435436 // Coming from a call to setjmp, the return is 0.
436437 PHI->addIncoming(Constant::getNullValue(Type::getInt32Ty(Inst->getContext())),
9595 if (!OldPhi) break;
9696
9797 PHINode* retPhi = PHINode::Create(OldPhi->getType(), "", Ins);
98 retPhi->reserveOperandSpace(2);
9899 OldPhi->replaceAllUsesWith(retPhi);
99100 Ins = newReturnBlock->getFirstNonPHI();
100101
196196 case Instruction::PHI: {
197197 PHINode *OPN = cast(I);
198198 PHINode *NPN = PHINode::Create(Ty);
199 NPN->reserveOperandSpace(OPN->getNumIncomingValues());
199200 for (unsigned i = 0, e = OPN->getNumIncomingValues(); i != e; ++i) {
200201 Value *V =EvaluateInDifferentType(OPN->getIncomingValue(i), Ty, isSigned);
201202 NPN->addIncoming(V, OPN->getIncomingBlock(i));
699699
700700 // Otherwise, Create the new PHI node for this user.
701701 EltPHI = PHINode::Create(Ty, PN->getName()+".off"+Twine(Offset), PN);
702 EltPHI->reserveOperandSpace(PN->getNumIncomingValues());
702703 assert(EltPHI->getType() != PN->getType() &&
703704 "Truncate didn't shrink phi?");
704705
928928 void PathProfiler::preparePHI(BLInstrumentationNode* node) {
929929 BasicBlock* block = node->getBlock();
930930 BasicBlock::iterator insertPoint = block->getFirstNonPHI();
931 pred_iterator PB = pred_begin(node->getBlock()),
932 PE = pred_end(node->getBlock());
931933 PHINode* phi = PHINode::Create(Type::getInt32Ty(*Context), "pathNumber",
932934 insertPoint );
935 phi->reserveOperandSpace(std::distance(PB, PE));
933936 node->setPathPHI(phi);
934937 node->setStartingPathNumber(phi);
935938 node->setEndingPathNumber(phi);
936939
937 for(pred_iterator predIt = pred_begin(node->getBlock()),
938 end = pred_end(node->getBlock()); predIt != end; predIt++) {
940 for(pred_iterator predIt = PB; predIt != PE; predIt++) {
939941 BasicBlock* pred = (*predIt);
940942
941943 if(pred != NULL)
19431943 addToLeaderTable(ValNo, PREInstr, PREPred);
19441944
19451945 // Create a PHI to make the value available in this block.
1946 pred_iterator PB = pred_begin(CurrentBlock), PE = pred_end(CurrentBlock);
19461947 PHINode* Phi = PHINode::Create(CurInst->getType(),
19471948 CurInst->getName() + ".pre-phi",
19481949 CurrentBlock->begin());
1949 for (pred_iterator PI = pred_begin(CurrentBlock),
1950 PE = pred_end(CurrentBlock); PI != PE; ++PI) {
1950 Phi->reserveOperandSpace(std::distance(PB, PE));
1951 for (pred_iterator PI = PB; PI != PE; ++PI) {
19511952 BasicBlock *P = *PI;
19521953 Phi->addIncoming(predMap[P], P);
19531954 }
10381038
10391039 // Insert new integer induction variable.
10401040 PHINode *NewPHI = PHINode::Create(Int32Ty, PN->getName()+".int", PN);
1041 NewPHI->reserveOperandSpace(2);
10411042 NewPHI->addIncoming(ConstantInt::get(Int32Ty, InitValue),
10421043 PN->getIncomingBlock(IncomingEdge));
10431044
927927 array_pod_sort(AvailablePreds.begin(), AvailablePreds.end());
928928
929929 // Create a PHI node at the start of the block for the PRE'd load value.
930 pred_iterator PB = pred_begin(LoadBB), PE = pred_end(LoadBB);
930931 PHINode *PN = PHINode::Create(LI->getType(), "", LoadBB->begin());
932 PN->reserveOperandSpace(std::distance(PB, PE));
931933 PN->takeName(LI);
932934
933935 // Insert new entries into the PHI for each predecessor. A single block may
934936 // have multiple entries here.
935 for (pred_iterator PI = pred_begin(LoadBB), E = pred_end(LoadBB); PI != E;
936 ++PI) {
937 for (pred_iterator PI = PB; PI != PE; ++PI) {
937938 BasicBlock *P = *PI;
938939 AvailablePredsTy::iterator I =
939940 std::lower_bound(AvailablePreds.begin(), AvailablePreds.end(),
14911491
14921492 /* Add new PHINode. */
14931493 PHINode *NewPH = PHINode::Create(DestTy, "IV.S.", PH);
1494 NewPH->reserveOperandSpace(2);
14941495
14951496 /* create new increment. '++d' in above example. */
14961497 Constant *CFP = ConstantFP::get(DestTy, C->getZExtValue());
12271227
12281228 const Type *LoadTy = cast(PN->getType())->getElementType();
12291229 PHINode *NewPN = PHINode::Create(LoadTy, PN->getName()+".ld", PN);
1230 NewPN->reserveOperandSpace(PN->getNumIncomingValues());
12301231
12311232 // Get the TBAA tag and alignment to use from one of the loads. It doesn't
12321233 // matter which one we get and if any differ, it doesn't matter.
258258 PHINode *RetBlockPHI = dyn_cast(RetBlock->begin());
259259 if (RetBlockPHI == 0) {
260260 Value *InVal = cast(RetBlock->getTerminator())->getOperand(0);
261 pred_iterator PB = pred_begin(RetBlock), PE = pred_end(RetBlock);
261262 RetBlockPHI = PHINode::Create(Ret->getOperand(0)->getType(), "merge",
262263 &RetBlock->front());
264 RetBlockPHI->reserveOperandSpace(std::distance(PB, PE));
263265
264 for (pred_iterator PI = pred_begin(RetBlock), E = pred_end(RetBlock);
265 PI != E; ++PI)
266 for (pred_iterator PI = PB; PI != PE; ++PI)
266267 RetBlockPHI->addIncoming(InVal, *PI);
267268 RetBlock->getTerminator()->setOperand(0, RetBlockPHI);
268269 }
497497 I != E; ++I) {
498498 PHINode *PN = PHINode::Create(I->getType(),
499499 I->getName() + ".tr", InsertPos);
500 PN->reserveOperandSpace(2);
500501 I->replaceAllUsesWith(PN); // Everyone use the PHI node now!
501502 PN->addIncoming(I, NewEntry);
502503 ArgumentPHIs.push_back(PN);
526527 if (AccumulatorRecursionEliminationInitVal) {
527528 Instruction *AccRecInstr = AccumulatorRecursionInstr;
528529 // Start by inserting a new PHI node for the accumulator.
530 pred_iterator PB = pred_begin(OldEntry), PE = pred_end(OldEntry);
529531 PHINode *AccPN =
530532 PHINode::Create(AccumulatorRecursionEliminationInitVal->getType(),
531533 "accumulator.tr", OldEntry->begin());
534 AccPN->reserveOperandSpace(std::distance(PB, PE) + 1);
532535
533536 // Loop over all of the predecessors of the tail recursion block. For the
534537 // real entry into the function we seed the PHI with the initial value,
536539 // other tail recursions eliminated) the accumulator is not modified.
537540 // Because we haven't added the branch in the current block to OldEntry yet,
538541 // it will not show up as a predecessor.
539 for (pred_iterator PI = pred_begin(OldEntry), PE = pred_end(OldEntry);
540 PI != PE; ++PI) {
542 for (pred_iterator PI = PB; PI != PE; ++PI) {
541543 BasicBlock *P = *PI;
542544 if (P == &F->getEntryBlock())
543545 AccPN->addIncoming(AccumulatorRecursionEliminationInitVal, P);
447447 // Create the new PHI node, insert it into NewBB at the end of the block
448448 PHINode *NewPHI =
449449 PHINode::Create(PN->getType(), PN->getName()+".ph", BI);
450 NewPHI->reserveOperandSpace(NumPreds);
450451 if (AA) AA->copyValue(PN, NewPHI);
451452
452453 // Move all of the PHI values for 'Preds' to the new PHI.
141141 // Otherwise a new PHI is needed. Create one and populate it.
142142 PHINode *NewPN = PHINode::Create(PN->getType(), "split",
143143 SplitBB->getTerminator());
144 NewPN->reserveOperandSpace(Preds.size());
144145 for (unsigned i = 0, e = Preds.size(); i != e; ++i)
145146 NewPN->addIncoming(V, Preds[i]);
146147 // Update the original PHI.
103103 /// region, we need to split the entry block of the region so that the PHI node
104104 /// is easier to deal with.
105105 void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) {
106 bool HasPredsFromRegion = false;
106 unsigned NumPredsFromRegion = 0;
107107 unsigned NumPredsOutsideRegion = 0;
108108
109109 if (Header != &Header->getParent()->getEntryBlock()) {
115115 // header block into two.
116116 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
117117 if (BlocksToExtract.count(PN->getIncomingBlock(i)))
118 HasPredsFromRegion = true;
118 ++NumPredsFromRegion;
119119 else
120120 ++NumPredsOutsideRegion;
121121
146146
147147 // Okay, now we need to adjust the PHI nodes and any branches from within the
148148 // region to go to the new header block instead of the old header block.
149 if (HasPredsFromRegion) {
149 if (NumPredsFromRegion) {
150150 PHINode *PN = cast(OldPred->begin());
151151 // Loop over all of the predecessors of OldPred that are in the region,
152152 // changing them to branch to NewBB instead.
164164 // from OldPred of PN.
165165 PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".ce",
166166 NewBB->begin());
167 NewPN->reserveOperandSpace(1+NumPredsFromRegion);
167168 NewPN->addIncoming(PN, OldPred);
168169
169170 // Loop over all of the incoming value in PN, moving them to NewPN if they
625625 if (!TheCall->use_empty()) {
626626 PHI = PHINode::Create(RTy, TheCall->getName(),
627627 AfterCallBB->begin());
628 PHI->reserveOperandSpace(Returns.size());
628629 // Anything that used the result of the function call should now use the
629630 // PHI node as their operand.
630631 TheCall->replaceAllUsesWith(PHI);
15971597 // in the constant and simplify the block result. Subsequent passes of
15981598 // simplifycfg will thread the block.
15991599 if (BlockIsSimpleEnoughToThreadThrough(BB)) {
1600 pred_iterator PB = pred_begin(BB), PE = pred_end(BB);
16001601 PHINode *NewPN = PHINode::Create(Type::getInt1Ty(BB->getContext()),
16011602 BI->getCondition()->getName() + ".pr",
16021603 BB->begin());
1604 NewPN->reserveOperandSpace(std::distance(PB, PE));
16031605 // Okay, we're going to insert the PHI node. Since PBI is not the only
16041606 // predecessor, compute the PHI'd conditional value for all of the preds.
16051607 // Any predecessor where the condition is not computable we keep symbolic.
1606 for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
1608 for (pred_iterator PI = PB; PI != PE; ++PI) {
16071609 BasicBlock *P = *PI;
16081610 if ((PBI = dyn_cast(P->getTerminator())) &&
16091611 PBI != BI && PBI->isConditional() &&
116116 } else {
117117 // If the function doesn't return void... add a PHI node to the block...
118118 PN = PHINode::Create(F.getReturnType(), "UnifiedRetVal");
119 PN->reserveOperandSpace(ReturningBlocks.size());
119120 NewRetBlock->getInstList().push_back(PN);
120121 ReturnInst::Create(F.getContext(), PN, NewRetBlock);
121122 }
886886
887887 PHINode *FuncPtr = PHINode::Create(NullPtr->getType(),
888888 "fp", DoCallBB);
889 FuncPtr->reserveOperandSpace(2);
889890 FuncPtr->addIncoming(CastedResolver, LookupBB);
890891 FuncPtr->addIncoming(CachedVal, EntryBB);
891892
2626
2727 builder.SetInsertPoint(bb0);
2828 PHINode *phi = builder.CreatePHI(Type::getInt32Ty(C));
29 phi->reserveOperandSpace(2);
2930 BranchInst *br0 = builder.CreateCondBr(builder.getTrue(), bb0, bb1);
3031
3132 builder.SetInsertPoint(bb1);