llvm.org GIT mirror llvm / 3ecfc86
Remove PHINode::reserveOperandSpace(). Instead, add a parameter to PHINode::Create() giving the (known or expected) number of operands. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128537 91177308-0d34-0410-b5e6-96231b3b80d8 Jay Foad 8 years ago
42 changed file(s) with 94 addition(s) and 128 deletion(s). Raw diff Collapse all Expand all
471471 // Emit merge block.
472472 TheFunction->getBasicBlockList().push_back(MergeBB);
473473 Builder.SetInsertPoint(MergeBB);
474 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
474 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
475475 "iftmp");
476476
477477 PN->addIncoming(ThenV, ThenBB);
745745 Builder.SetInsertPoint(LoopBB);
746746
747747 // Start the PHI node with an entry for Start.
748 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
748 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, VarName.c_str());
749749 Variable->addIncoming(StartVal, PreheaderBB);
750750
751751
14511451 // Emit merge block.
14521452 TheFunction->getBasicBlockList().push_back(MergeBB);
14531453 Builder.SetInsertPoint(MergeBB);
1454 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
1454 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
14551455 "iftmp");
14561456
14571457 PN->addIncoming(ThenV, ThenBB);
14931493 Builder.SetInsertPoint(LoopBB);
14941494
14951495 // Start the PHI node with an entry for Start.
1496 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
1496 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, VarName.c_str());
14971497 Variable->addIncoming(StartVal, PreheaderBB);
14981498
14991499 // Within the loop, the variable is defined equal to the PHI node. If it
14741474 // Emit merge block.
14751475 TheFunction->getBasicBlockList().push_back(MergeBB);
14761476 Builder.SetInsertPoint(MergeBB);
1477 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
1477 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
14781478 "iftmp");
14791479
14801480 PN->addIncoming(ThenV, ThenBB);
15161516 Builder.SetInsertPoint(LoopBB);
15171517
15181518 // Start the PHI node with an entry for Start.
1519 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
1519 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, VarName.c_str());
15201520 Variable->addIncoming(StartVal, PreheaderBB);
15211521
15221522 // Within the loop, the variable is defined equal to the PHI node. If it
17541754 // Emit merge block.
17551755 TheFunction->getBasicBlockList().push_back(MergeBB);
17561756 Builder.SetInsertPoint(MergeBB);
1757 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
1757 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
17581758 "iftmp");
17591759
17601760 PN->addIncoming(ThenV, ThenBB);
293293 // Make part of PHI instruction now, wait until end of loop to finish
294294 PHINode *phi_0 =
295295 PHINode::Create(PointerType::getUnqual(IntegerType::getInt8Ty(C)),
296 headreg, testbb);
297 phi_0->reserveOperandSpace(2);
296 2, headreg, testbb);
298297 phi_0->addIncoming(curhead, bb_0);
299298 curhead = phi_0;
300299
448447
449448 //%head.%d = phi i8 *[%head.%d, %main.%d]
450449 PHINode *phi_1 = builder->
451 CreatePHI(PointerType::getUnqual(IntegerType::getInt8Ty(C)), headreg);
452 phi_1->reserveOperandSpace(1);
450 CreatePHI(PointerType::getUnqual(IntegerType::getInt8Ty(C)), 1,
451 headreg);
453452 phi_1->addIncoming(head_0, testbb);
454453 curhead = phi_1;
455454 }
549549 // Emit merge block.
550550 TheFunction->getBasicBlockList().push_back(MergeBB);
551551 Builder.SetInsertPoint(MergeBB);
552 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
552 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
553553 "iftmp");
554 PN->reserveOperandSpace(2);
555554
556555 PN->addIncoming(ThenV, ThenBB);
557556 PN->addIncoming(ElseV, ElseBB);
592591 Builder.SetInsertPoint(LoopBB);
593592
594593 // Start the PHI node with an entry for Start.
595 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
596 Variable->reserveOperandSpace(2);
594 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, VarName.c_str());
597595 Variable->addIncoming(StartVal, PreheaderBB);
598596
599597 // Within the loop, the variable is defined equal to the PHI node. If it
653653 // Emit merge block.
654654 TheFunction->getBasicBlockList().push_back(MergeBB);
655655 Builder.SetInsertPoint(MergeBB);
656 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
656 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
657657 "iftmp");
658 PN->reserveOperandSpace(2);
659658
660659 PN->addIncoming(ThenV, ThenBB);
661660 PN->addIncoming(ElseV, ElseBB);
696695 Builder.SetInsertPoint(LoopBB);
697696
698697 // Start the PHI node with an entry for Start.
699 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
700 Variable->reserveOperandSpace(2);
698 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, VarName.c_str());
701699 Variable->addIncoming(StartVal, PreheaderBB);
702700
703701 // Within the loop, the variable is defined equal to the PHI node. If it
749749 // Emit merge block.
750750 TheFunction->getBasicBlockList().push_back(MergeBB);
751751 Builder.SetInsertPoint(MergeBB);
752 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
752 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2,
753753 "iftmp");
754 PN->reserveOperandSpace(2);
755754
756755 PN->addIncoming(ThenV, ThenBB);
757756 PN->addIncoming(ElseV, ElseBB);
18101810 void *operator new(size_t s) {
18111811 return User::operator new(s, 0);
18121812 }
1813 explicit PHINode(const Type *Ty, const Twine &NameStr = "",
1814 Instruction *InsertBefore = 0)
1813 explicit PHINode(const Type *Ty, unsigned NumReservedValues,
1814 const Twine &NameStr = "", Instruction *InsertBefore = 0)
18151815 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
1816 ReservedSpace(0) {
1816 ReservedSpace(NumReservedValues * 2) {
18171817 setName(NameStr);
1818 }
1819
1820 PHINode(const Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd)
1818 OperandList = allocHungoffUses(ReservedSpace);
1819 }
1820
1821 PHINode(const Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
1822 BasicBlock *InsertAtEnd)
18211823 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
1822 ReservedSpace(0) {
1824 ReservedSpace(NumReservedValues * 2) {
18231825 setName(NameStr);
1826 OperandList = allocHungoffUses(ReservedSpace);
18241827 }
18251828 protected:
18261829 virtual PHINode *clone_impl() const;
18271830 public:
1828 static PHINode *Create(const Type *Ty, const Twine &NameStr = "",
1831 static PHINode *Create(const Type *Ty, unsigned NumReservedValues,
1832 const Twine &NameStr = "",
18291833 Instruction *InsertBefore = 0) {
1830 return new PHINode(Ty, NameStr, InsertBefore);
1831 }
1832 static PHINode *Create(const Type *Ty, const Twine &NameStr,
1833 BasicBlock *InsertAtEnd) {
1834 return new PHINode(Ty, NameStr, InsertAtEnd);
1834 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
1835 }
1836 static PHINode *Create(const Type *Ty, unsigned NumReservedValues,
1837 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1838 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
18351839 }
18361840 ~PHINode();
1837
1838 /// reserveOperandSpace - This method can be used to avoid repeated
1839 /// reallocation of PHI operand lists by reserving space for the correct
1840 /// number of operands before adding them. Unlike normal vector reserves,
1841 /// this method can also be used to trim the operand space.
1842 void reserveOperandSpace(unsigned NumValues) {
1843 resizeOperands(NumValues*2);
1844 }
18451841
18461842 /// Provide fast operand accessors
18471843 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
10691069 // Instruction creation methods: Other Instructions
10701070 //===--------------------------------------------------------------------===//
10711071
1072 PHINode *CreatePHI(const Type *Ty, const Twine &Name = "") {
1073 return Insert(PHINode::Create(Ty), Name);
1072 PHINode *CreatePHI(const Type *Ty, unsigned NumReservedValues,
1073 const Twine &Name = "") {
1074 return Insert(PHINode::Create(Ty, NumReservedValues), Name);
10741075 }
10751076
10761077 CallInst *CreateCall(Value *Callee, const Twine &Name = "") {
934934 BasicBlock *Header = L->getHeader();
935935 Builder.SetInsertPoint(Header, Header->begin());
936936 pred_iterator HPB = pred_begin(Header), HPE = pred_end(Header);
937 PHINode *PN = Builder.CreatePHI(ExpandTy, "lsr.iv");
938 PN->reserveOperandSpace(std::distance(HPB, HPE));
937 PHINode *PN = Builder.CreatePHI(ExpandTy, std::distance(HPB, HPE), "lsr.iv");
939938 rememberInstruction(PN);
940939
941940 // Create the step instructions and populate the PHI.
11421141 // specified loop.
11431142 BasicBlock *Header = L->getHeader();
11441143 pred_iterator HPB = pred_begin(Header), HPE = pred_end(Header);
1145 CanonicalIV = PHINode::Create(Ty, "indvar", Header->begin());
1146 CanonicalIV->reserveOperandSpace(std::distance(HPB, HPE));
1144 CanonicalIV = PHINode::Create(Ty, std::distance(HPB, HPE), "indvar",
1145 Header->begin());
11471146 rememberInstruction(CanonicalIV);
11481147
11491148 Constant *One = ConstantInt::get(Ty, 1);
36333633 if (!Ty->isFirstClassType())
36343634 return Error(TypeLoc, "phi node must have first class type");
36353635
3636 PHINode *PN = PHINode::Create(Ty);
3637 PN->reserveOperandSpace(PHIVals.size());
3636 PHINode *PN = PHINode::Create(Ty, PHIVals.size());
36383637 for (unsigned i = 0, e = PHIVals.size(); i != e; ++i)
36393638 PN->addIncoming(PHIVals[i].first, PHIVals[i].second);
36403639 Inst = PN;
22872287 const Type *Ty = getTypeByID(Record[0]);
22882288 if (!Ty) return Error("Invalid PHI record");
22892289
2290 PHINode *PN = PHINode::Create(Ty);
2290 PHINode *PN = PHINode::Create(Ty, (Record.size()-1)/2);
22912291 InstructionList.push_back(PN);
2292 PN->reserveOperandSpace((Record.size()-1)/2);
22932292
22942293 for (unsigned i = 0, e = Record.size()-1; i != e; i += 2) {
22952294 Value *V = getFnValueByID(Record[1+i], Ty);
438438 if (InVal == 0) {
439439 // Different unwind edges have different values. Create a new PHI node
440440 // in NewBB.
441 PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".unwind",
442 NewBB);
443 NewPN->reserveOperandSpace(PN->getNumIncomingValues());
441 PHINode *NewPN = PHINode::Create(PN->getType(),
442 PN->getNumIncomingValues(),
443 PN->getName()+".unwind", NewBB);
444444 // Add an entry for each unwind edge, using the value from the old PHI.
445445 for (pred_iterator PI = PB; PI != PE; ++PI)
446446 NewPN->addIncoming(PN->getIncomingValueForBlock(*PI), *PI);
13471347 const PHINode* phi = cast(I);
13481348
13491349 Out << "PHINode* " << iName << " = PHINode::Create("
1350 << getCppName(phi->getType()) << ", \"";
1350 << getCppName(phi->getType()) << ", \""
1351 << phi->getNumIncomingValues() << ", \"";
13511352 printEscapedString(phi->getName());
13521353 Out << "\", " << bbname << ");";
1353 nl(Out) << iName << "->reserveOperandSpace("
1354 << phi->getNumIncomingValues()
1355 << ");";
13561354 nl(Out);
13571355 for (unsigned i = 0; i < phi->getNumOperands(); i+=2) {
13581356 Out << iName << "->addIncoming("
11941194
11951195 PHINode *NewPN =
11961196 PHINode::Create(PointerType::getUnqual(ST->getElementType(FieldNo)),
1197 PN->getNumIncomingValues(),
11971198 PN->getName()+".f"+Twine(FieldNo), PN);
1198 NewPN->reserveOperandSpace(PN->getNumIncomingValues());
11991199 Result = NewPN;
12001200 PHIsToRewrite.push_back(std::make_pair(PN, FieldNo));
12011201 } else {
429429
430430 // This PHI node will be in the new block created from the
431431 // splitBasicBlock call.
432 PHINode* PHI = PHINode::Create(Type::getInt32Ty(Inst->getContext()),
432 PHINode* PHI = PHINode::Create(Type::getInt32Ty(Inst->getContext()), 2,
433433 "SetJmpReturn", Inst);
434 PHI->reserveOperandSpace(2);
435434
436435 // Coming from a call to setjmp, the return is 0.
437436 PHI->addIncoming(Constant::getNullValue(Type::getInt32Ty(Inst->getContext())),
9494 PHINode* OldPhi = dyn_cast(I);
9595 if (!OldPhi) break;
9696
97 PHINode* retPhi = PHINode::Create(OldPhi->getType(), "", Ins);
98 retPhi->reserveOperandSpace(2);
97 PHINode* retPhi = PHINode::Create(OldPhi->getType(), 2, "", Ins);
9998 OldPhi->replaceAllUsesWith(retPhi);
10099 Ins = newReturnBlock->getFirstNonPHI();
101100
195195 }
196196 case Instruction::PHI: {
197197 PHINode *OPN = cast(I);
198 PHINode *NPN = PHINode::Create(Ty);
199 NPN->reserveOperandSpace(OPN->getNumIncomingValues());
198 PHINode *NPN = PHINode::Create(Ty, OPN->getNumIncomingValues());
200199 for (unsigned i = 0, e = OPN->getNumIncomingValues(); i != e; ++i) {
201200 Value *V =EvaluateInDifferentType(OPN->getIncomingValue(i), Ty, isSigned);
202201 NPN->addIncoming(V, OPN->getIncomingBlock(i));
590590 // Insert a PHI node now if we need it.
591591 Value *MergedVal = OtherStore->getOperand(0);
592592 if (MergedVal != SI.getOperand(0)) {
593 PHINode *PN = PHINode::Create(MergedVal->getType(), "storemerge");
594 PN->reserveOperandSpace(2);
593 PHINode *PN = PHINode::Create(MergedVal->getType(), 2, "storemerge");
595594 PN->addIncoming(SI.getOperand(0), SI.getParent());
596595 PN->addIncoming(OtherStore->getOperand(0), OtherBB);
597596 MergedVal = InsertNewInstBefore(PN, DestBB->front());
7979 Value *InRHS = FirstInst->getOperand(1);
8080 PHINode *NewLHS = 0, *NewRHS = 0;
8181 if (LHSVal == 0) {
82 NewLHS = PHINode::Create(LHSType,
82 NewLHS = PHINode::Create(LHSType, PN.getNumIncomingValues(),
8383 FirstInst->getOperand(0)->getName() + ".pn");
84 NewLHS->reserveOperandSpace(PN.getNumIncomingValues());
8584 NewLHS->addIncoming(InLHS, PN.getIncomingBlock(0));
8685 InsertNewInstBefore(NewLHS, PN);
8786 LHSVal = NewLHS;
8887 }
8988
9089 if (RHSVal == 0) {
91 NewRHS = PHINode::Create(RHSType,
90 NewRHS = PHINode::Create(RHSType, PN.getNumIncomingValues(),
9291 FirstInst->getOperand(1)->getName() + ".pn");
93 NewRHS->reserveOperandSpace(PN.getNumIncomingValues());
9492 NewRHS->addIncoming(InRHS, PN.getIncomingBlock(0));
9593 InsertNewInstBefore(NewRHS, PN);
9694 RHSVal = NewRHS;
201199 for (unsigned i = 0, e = FixedOperands.size(); i != e; ++i) {
202200 if (FixedOperands[i]) continue; // operand doesn't need a phi.
203201 Value *FirstOp = FirstInst->getOperand(i);
204 PHINode *NewPN = PHINode::Create(FirstOp->getType(),
202 PHINode *NewPN = PHINode::Create(FirstOp->getType(), e,
205203 FirstOp->getName()+".pn");
206204 InsertNewInstBefore(NewPN, PN);
207205
208 NewPN->reserveOperandSpace(e);
209206 NewPN->addIncoming(FirstOp, PN.getIncomingBlock(0));
210207 OperandPhis[i] = NewPN;
211208 FixedOperands[i] = NewPN;
339336 // Okay, they are all the same operation. Create a new PHI node of the
340337 // correct type, and PHI together all of the LHS's of the instructions.
341338 PHINode *NewPN = PHINode::Create(FirstLI->getOperand(0)->getType(),
339 PN.getNumIncomingValues(),
342340 PN.getName()+".in");
343 NewPN->reserveOperandSpace(PN.getNumIncomingValues());
344341
345342 Value *InVal = FirstLI->getOperand(0);
346343 NewPN->addIncoming(InVal, PN.getIncomingBlock(0));
445442 // Okay, they are all the same operation. Create a new PHI node of the
446443 // correct type, and PHI together all of the LHS's of the instructions.
447444 PHINode *NewPN = PHINode::Create(FirstInst->getOperand(0)->getType(),
445 PN.getNumIncomingValues(),
448446 PN.getName()+".in");
449 NewPN->reserveOperandSpace(PN.getNumIncomingValues());
450447
451448 Value *InVal = FirstInst->getOperand(0);
452449 NewPN->addIncoming(InVal, PN.getIncomingBlock(0));
698695 if ((EltPHI = ExtractedVals[LoweredPHIRecord(PN, Offset, Ty)]) == 0) {
699696
700697 // Otherwise, Create the new PHI node for this user.
701 EltPHI = PHINode::Create(Ty, PN->getName()+".off"+Twine(Offset), PN);
702 EltPHI->reserveOperandSpace(PN->getNumIncomingValues());
698 EltPHI = PHINode::Create(Ty, PN->getNumIncomingValues(),
699 PN->getName()+".off"+Twine(Offset), PN);
703700 assert(EltPHI->getType() != PN->getType() &&
704701 "Truncate didn't shrink phi?");
705702
599599 }
600600
601601 // Okay, we can do the transformation: create the new PHI node.
602 PHINode *NewPN = PHINode::Create(I.getType(), "");
603 NewPN->reserveOperandSpace(PN->getNumIncomingValues());
602 PHINode *NewPN = PHINode::Create(I.getType(), PN->getNumIncomingValues(), "");
604603 InsertNewInstBefore(NewPN, *PN);
605604 NewPN->takeName(PN);
606605
930930 BasicBlock::iterator insertPoint = block->getFirstNonPHI();
931931 pred_iterator PB = pred_begin(node->getBlock()),
932932 PE = pred_end(node->getBlock());
933 PHINode* phi = PHINode::Create(Type::getInt32Ty(*Context), "pathNumber",
933 PHINode* phi = PHINode::Create(Type::getInt32Ty(*Context),
934 std::distance(PB, PE), "pathNumber",
934935 insertPoint );
935 phi->reserveOperandSpace(std::distance(PB, PE));
936936 node->setPathPHI(phi);
937937 node->setStartingPathNumber(phi);
938938 node->setEndingPathNumber(phi);
19441944
19451945 // Create a PHI to make the value available in this block.
19461946 pred_iterator PB = pred_begin(CurrentBlock), PE = pred_end(CurrentBlock);
1947 PHINode* Phi = PHINode::Create(CurInst->getType(),
1947 PHINode* Phi = PHINode::Create(CurInst->getType(), std::distance(PB, PE),
19481948 CurInst->getName() + ".pre-phi",
19491949 CurrentBlock->begin());
1950 Phi->reserveOperandSpace(std::distance(PB, PE));
19511950 for (pred_iterator PI = PB; PI != PE; ++PI) {
19521951 BasicBlock *P = *PI;
19531952 Phi->addIncoming(predMap[P], P);
10371037 const IntegerType *Int32Ty = Type::getInt32Ty(PN->getContext());
10381038
10391039 // Insert new integer induction variable.
1040 PHINode *NewPHI = PHINode::Create(Int32Ty, PN->getName()+".int", PN);
1041 NewPHI->reserveOperandSpace(2);
1040 PHINode *NewPHI = PHINode::Create(Int32Ty, 2, PN->getName()+".int", PN);
10421041 NewPHI->addIncoming(ConstantInt::get(Int32Ty, InitValue),
10431042 PN->getIncomingBlock(IncomingEdge));
10441043
928928
929929 // Create a PHI node at the start of the block for the PRE'd load value.
930930 pred_iterator PB = pred_begin(LoadBB), PE = pred_end(LoadBB);
931 PHINode *PN = PHINode::Create(LI->getType(), "", LoadBB->begin());
932 PN->reserveOperandSpace(std::distance(PB, PE));
931 PHINode *PN = PHINode::Create(LI->getType(), std::distance(PB, PE), "",
932 LoadBB->begin());
933933 PN->takeName(LI);
934934
935935 // Insert new entries into the PHI for each predecessor. A single block may
14901490 if (!C->getValue().isStrictlyPositive()) continue;
14911491
14921492 /* Add new PHINode. */
1493 PHINode *NewPH = PHINode::Create(DestTy, "IV.S.", PH);
1494 NewPH->reserveOperandSpace(2);
1493 PHINode *NewPH = PHINode::Create(DestTy, 2, "IV.S.", PH);
14951494
14961495 /* create new increment. '++d' in above example. */
14971496 Constant *CFP = ConstantFP::get(DestTy, C->getZExtValue());
12261226 }
12271227
12281228 const Type *LoadTy = cast(PN->getType())->getElementType();
1229 PHINode *NewPN = PHINode::Create(LoadTy, PN->getName()+".ld", PN);
1230 NewPN->reserveOperandSpace(PN->getNumIncomingValues());
1229 PHINode *NewPN = PHINode::Create(LoadTy, PN->getNumIncomingValues(),
1230 PN->getName()+".ld", PN);
12311231
12321232 // Get the TBAA tag and alignment to use from one of the loads. It doesn't
12331233 // matter which one we get and if any differ, it doesn't matter.
259259 if (RetBlockPHI == 0) {
260260 Value *InVal = cast(RetBlock->getTerminator())->getOperand(0);
261261 pred_iterator PB = pred_begin(RetBlock), PE = pred_end(RetBlock);
262 RetBlockPHI = PHINode::Create(Ret->getOperand(0)->getType(), "merge",
262 RetBlockPHI = PHINode::Create(Ret->getOperand(0)->getType(),
263 std::distance(PB, PE), "merge",
263264 &RetBlock->front());
264 RetBlockPHI->reserveOperandSpace(std::distance(PB, PE));
265265
266266 for (pred_iterator PI = PB; PI != PE; ++PI)
267267 RetBlockPHI->addIncoming(InVal, *PI);
495495 Instruction *InsertPos = OldEntry->begin();
496496 for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end();
497497 I != E; ++I) {
498 PHINode *PN = PHINode::Create(I->getType(),
498 PHINode *PN = PHINode::Create(I->getType(), 2,
499499 I->getName() + ".tr", InsertPos);
500 PN->reserveOperandSpace(2);
501500 I->replaceAllUsesWith(PN); // Everyone use the PHI node now!
502501 PN->addIncoming(I, NewEntry);
503502 ArgumentPHIs.push_back(PN);
530529 pred_iterator PB = pred_begin(OldEntry), PE = pred_end(OldEntry);
531530 PHINode *AccPN =
532531 PHINode::Create(AccumulatorRecursionEliminationInitVal->getType(),
532 std::distance(PB, PE) + 1,
533533 "accumulator.tr", OldEntry->begin());
534 AccPN->reserveOperandSpace(std::distance(PB, PE) + 1);
535534
536535 // Loop over all of the predecessors of the tail recursion block. For the
537536 // real entry into the function we seed the PHI with the initial value,
446446 // If the values coming into the block are not the same, we need a PHI.
447447 // Create the new PHI node, insert it into NewBB at the end of the block
448448 PHINode *NewPHI =
449 PHINode::Create(PN->getType(), PN->getName()+".ph", BI);
450 NewPHI->reserveOperandSpace(NumPreds);
449 PHINode::Create(PN->getType(), NumPreds, PN->getName()+".ph", BI);
451450 if (AA) AA->copyValue(PN, NewPHI);
452451
453452 // Move all of the PHI values for 'Preds' to the new PHI.
139139 if (VP->getParent() == SplitBB)
140140 continue;
141141 // Otherwise a new PHI is needed. Create one and populate it.
142 PHINode *NewPN = PHINode::Create(PN->getType(), "split",
142 PHINode *NewPN = PHINode::Create(PN->getType(), Preds.size(), "split",
143143 SplitBB->getTerminator());
144 NewPN->reserveOperandSpace(Preds.size());
145144 for (unsigned i = 0, e = Preds.size(); i != e; ++i)
146145 NewPN->addIncoming(V, Preds[i]);
147146 // Update the original PHI.
162162 PHINode *PN = cast(AfterPHIs);
163163 // Create a new PHI node in the new region, which has an incoming value
164164 // from OldPred of PN.
165 PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".ce",
166 NewBB->begin());
167 NewPN->reserveOperandSpace(1+NumPredsFromRegion);
165 PHINode *NewPN = PHINode::Create(PN->getType(), 1 + NumPredsFromRegion,
166 PN->getName()+".ce", NewBB->begin());
168167 NewPN->addIncoming(PN, OldPred);
169168
170169 // Loop over all of the incoming value in PN, moving them to NewPN if they
623623 // The PHI node should go at the front of the new basic block to merge all
624624 // possible incoming values.
625625 if (!TheCall->use_empty()) {
626 PHI = PHINode::Create(RTy, TheCall->getName(),
626 PHI = PHINode::Create(RTy, Returns.size(), TheCall->getName(),
627627 AfterCallBB->begin());
628 PHI->reserveOperandSpace(Returns.size());
629628 // Anything that used the result of the function call should now use the
630629 // PHI node as their operand.
631630 TheCall->replaceAllUsesWith(PHI);
221221 // If we already inserted something for this BB, don't reprocess it.
222222 if (SSAUpdate.HasValueForBlock(ExitBB)) continue;
223223
224 PHINode *PN = PHINode::Create(Inst->getType(), Inst->getName()+".lcssa",
224 PHINode *PN = PHINode::Create(Inst->getType(),
225 PredCache.GetNumPreds(ExitBB),
226 Inst->getName()+".lcssa",
225227 ExitBB->begin());
226 PN->reserveOperandSpace(PredCache.GetNumPreds(ExitBB));
227228
228229 // Add inputs from inside the loop for this PHI.
229230 for (BasicBlock **PI = PredCache.GetPreds(ExitBB); *PI; ++PI) {
647647 // the backedge block which correspond to any PHI nodes in the header block.
648648 for (BasicBlock::iterator I = Header->begin(); isa(I); ++I) {
649649 PHINode *PN = cast(I);
650 PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".be",
651 BETerminator);
652 NewPN->reserveOperandSpace(BackedgeBlocks.size());
650 PHINode *NewPN = PHINode::Create(PN->getType(), BackedgeBlocks.size(),
651 PN->getName()+".be", BETerminator);
653652 if (AA) AA->copyValue(PN, NewPN);
654653
655654 // Loop over the PHI node, moving all entries except the one for the
960960
961961 // Create a PhiNode using the dereferenced type... and add the phi-node to the
962962 // BasicBlock.
963 PN = PHINode::Create(Allocas[AllocaNo]->getAllocatedType(),
963 PN = PHINode::Create(Allocas[AllocaNo]->getAllocatedType(), getNumPreds(BB),
964964 Allocas[AllocaNo]->getName() + "." + Twine(Version++),
965965 BB->begin());
966966 ++NumPHIInsert;
967967 PhiToAllocaMap[PN] = AllocaNo;
968 PN->reserveOperandSpace(getNumPreds(BB));
969968
970969 if (AST && PN->getType()->isPointerTy())
971970 AST->copyValue(PointerAllocaValues[AllocaNo], PN);
169169 }
170170
171171 // Ok, we have no way out, insert a new one now.
172 PHINode *InsertedPHI = PHINode::Create(ProtoType, ProtoName, &BB->front());
173 InsertedPHI->reserveOperandSpace(PredValues.size());
172 PHINode *InsertedPHI = PHINode::Create(ProtoType, PredValues.size(),
173 ProtoName, &BB->front());
174174
175175 // Fill in all the predecessors of the PHI.
176176 for (unsigned i = 0, e = PredValues.size(); i != e; ++i)
288288 /// Reserve space for the operands but do not fill them in yet.
289289 static Value *CreateEmptyPHI(BasicBlock *BB, unsigned NumPreds,
290290 SSAUpdater *Updater) {
291 PHINode *PHI = PHINode::Create(Updater->ProtoType, Updater->ProtoName,
292 &BB->front());
293 PHI->reserveOperandSpace(NumPreds);
291 PHINode *PHI = PHINode::Create(Updater->ProtoType, NumPreds,
292 Updater->ProtoName, &BB->front());
294293 return PHI;
295294 }
296295
15991599 if (BlockIsSimpleEnoughToThreadThrough(BB)) {
16001600 pred_iterator PB = pred_begin(BB), PE = pred_end(BB);
16011601 PHINode *NewPN = PHINode::Create(Type::getInt1Ty(BB->getContext()),
1602 std::distance(PB, PE),
16021603 BI->getCondition()->getName() + ".pr",
16031604 BB->begin());
1604 NewPN->reserveOperandSpace(std::distance(PB, PE));
16051605 // Okay, we're going to insert the PHI node. Since PBI is not the only
16061606 // predecessor, compute the PHI'd conditional value for all of the preds.
16071607 // Any predecessor where the condition is not computable we keep symbolic.
115115 ReturnInst::Create(F.getContext(), NULL, NewRetBlock);
116116 } else {
117117 // If the function doesn't return void... add a PHI node to the block...
118 PN = PHINode::Create(F.getReturnType(), "UnifiedRetVal");
119 PN->reserveOperandSpace(ReturningBlocks.size());
118 PN = PHINode::Create(F.getReturnType(), ReturningBlocks.size(),
119 "UnifiedRetVal");
120120 NewRetBlock->getInstList().push_back(PN);
121121 ReturnInst::Create(F.getContext(), PN, NewRetBlock);
122122 }
20812081 /*--.. Miscellaneous instructions ..........................................--*/
20822082
20832083 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) {
2084 return wrap(unwrap(B)->CreatePHI(unwrap(Ty), Name));
2084 return wrap(unwrap(B)->CreatePHI(unwrap(Ty), 0, Name));
20852085 }
20862086
20872087 LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
884884 new StoreInst(CastedResolver, Cache, LookupBB);
885885 BranchInst::Create(DoCallBB, LookupBB);
886886
887 PHINode *FuncPtr = PHINode::Create(NullPtr->getType(),
887 PHINode *FuncPtr = PHINode::Create(NullPtr->getType(), 2,
888888 "fp", DoCallBB);
889 FuncPtr->reserveOperandSpace(2);
890889 FuncPtr->addIncoming(CastedResolver, LookupBB);
891890 FuncPtr->addIncoming(CachedVal, EntryBB);
892891
2525 BasicBlock *bb1 = BasicBlock::Create(C);
2626
2727 builder.SetInsertPoint(bb0);
28 PHINode *phi = builder.CreatePHI(Type::getInt32Ty(C));
29 phi->reserveOperandSpace(2);
28 PHINode *phi = builder.CreatePHI(Type::getInt32Ty(C), 2);
3029 BranchInst *br0 = builder.CreateCondBr(builder.getTrue(), bb0, bb1);
3130
3231 builder.SetInsertPoint(bb1);
4342 EXPECT_EQ(&bb1->front(), br1);
4443
4544 builder.SetInsertPoint(bb0);
46 phi = builder.CreatePHI(Type::getInt32Ty(C));
45 phi = builder.CreatePHI(Type::getInt32Ty(C), 0);
4746
4847 EXPECT_TRUE(RecursivelyDeleteDeadPHINode(phi));
4948
5049 builder.SetInsertPoint(bb0);
51 phi = builder.CreatePHI(Type::getInt32Ty(C));
50 phi = builder.CreatePHI(Type::getInt32Ty(C), 0);
5251 builder.CreateAdd(phi, phi);
5352
5453 EXPECT_TRUE(RecursivelyDeleteDeadPHINode(phi));