llvm.org GIT mirror llvm / 4d588bc
If PrototypeValue is erased in the middle of using the SSAUpdator then the SSAUpdator may access freed memory. Instead, simply pass in the type and name explicitly, which is all that was used anyway. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112699 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 10 years ago
7 changed file(s) with 25 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
3535 //typedef DenseMap AvailableValsTy;
3636 void *AV;
3737
38 /// PrototypeValue is an arbitrary representative value, which we derive names
39 /// and a type for PHI nodes.
40 Value *PrototypeValue;
38 /// ProtoType holds the type of the values being rewritten.
39 const Type *ProtoType;
40
41 // PHI nodes are given a name based on ProtoName.
42 std::string ProtoName;
4143
4244 /// InsertedPHIs - If this is non-null, the SSAUpdater adds all PHI nodes that
4345 /// it creates to the vector.
5052 ~SSAUpdater();
5153
5254 /// Initialize - Reset this object to get ready for a new set of SSA
53 /// updates. ProtoValue is the value used to name PHI nodes.
54 void Initialize(Value *ProtoValue);
55 /// updates with type 'Ty'. PHI nodes get a name based on 'Name'.
56 void Initialize(const Type *Ty, StringRef Name);
5557
5658 /// AddAvailableValue - Indicate that a rewritten value is available at the
5759 /// end of the specified block with the specified value.
13091309 // Otherwise, we have to construct SSA form.
13101310 SmallVector NewPHIs;
13111311 SSAUpdater SSAUpdate(&NewPHIs);
1312 SSAUpdate.Initialize(LI);
1312 SSAUpdate.Initialize(LI->getType(), LI->getName());
13131313
13141314 const Type *LoadTy = LI->getType();
13151315
15251525 // We found a use of I outside of BB. Rename all uses of I that are outside
15261526 // its block to be uses of the appropriate PHI node etc. See ValuesInBlocks
15271527 // with the two values we know.
1528 SSAUpdate.Initialize(I);
1528 SSAUpdate.Initialize(I->getType(), I->getName());
15291529 SSAUpdate.AddAvailableValue(BB, I);
15301530 SSAUpdate.AddAvailableValue(NewBB, ValueMapping[I]);
15311531
16801680 // We found a use of I outside of BB. Rename all uses of I that are outside
16811681 // its block to be uses of the appropriate PHI node etc. See ValuesInBlocks
16821682 // with the two values we know.
1683 SSAUpdate.Initialize(I);
1683 SSAUpdate.Initialize(I->getType(), I->getName());
16841684 SSAUpdate.AddAvailableValue(BB, I);
16851685 SSAUpdate.AddAvailableValue(PredBB, ValueMapping[I]);
16861686
525525 SSAUpdater SSA(&NewPHIs);
526526
527527 if (!I.use_empty())
528 SSA.Initialize(&I);
528 SSA.Initialize(I.getType(), I.getName());
529529
530530 // Insert a copy of the instruction in each exit block of the loop that is
531531 // dominated by the instruction. Each exit block is known to only be in the
727727 SomeValue = LoopUses[0];
728728 else
729729 SomeValue = cast(LoopUses[0])->getOperand(0);
730 SSA.Initialize(SomeValue);
730 SSA.Initialize(SomeValue->getType(), SomeValue->getName());
731731
732732 // First step: bucket up uses of the pointers by the block they occur in.
733733 // This is important because we have to handle multiple defs/uses in a block
220220
221221 // The value now exits in two versions: the initial value in the preheader
222222 // and the loop "next" value in the original header.
223 SSA.Initialize(OrigHeaderVal);
223 SSA.Initialize(OrigHeaderVal->getType(), OrigHeaderVal->getName());
224224 SSA.AddAvailableValue(OrigHeader, OrigHeaderVal);
225225 SSA.AddAvailableValue(OrigPreHeader, OrigPreHeaderVal);
226226
205205 DomTreeNode *DomNode = DT->getNode(DomBB);
206206
207207 SSAUpdater SSAUpdate;
208 SSAUpdate.Initialize(Inst);
208 SSAUpdate.Initialize(Inst->getType(), Inst->getName());
209209
210210 // Insert the LCSSA phi's into all of the exit blocks dominated by the
211211 // value, and add them to the Phi's map.
2828 }
2929
3030 SSAUpdater::SSAUpdater(SmallVectorImpl *NewPHI)
31 : AV(0), PrototypeValue(0), InsertedPHIs(NewPHI) {}
31 : AV(0), ProtoType(0), ProtoName(), InsertedPHIs(NewPHI) {}
3232
3333 SSAUpdater::~SSAUpdater() {
3434 delete &getAvailableVals(AV);
3535 }
3636
3737 /// Initialize - Reset this object to get ready for a new set of SSA
38 /// updates. ProtoValue is the value used to name PHI nodes.
39 void SSAUpdater::Initialize(Value *ProtoValue) {
38 /// updates with type 'Ty'. PHI nodes get a name based on 'Name'.
39 void SSAUpdater::Initialize(const Type *Ty, StringRef Name) {
4040 if (AV == 0)
4141 AV = new AvailableValsTy();
4242 else
4343 getAvailableVals(AV).clear();
44 PrototypeValue = ProtoValue;
44 ProtoType = Ty;
45 ProtoName = Name;
4546 }
4647
4748 /// HasValueForBlock - Return true if the SSAUpdater already has a value for
5354 /// AddAvailableValue - Indicate that a rewritten value is available in the
5455 /// specified block with the specified value.
5556 void SSAUpdater::AddAvailableValue(BasicBlock *BB, Value *V) {
56 assert(PrototypeValue != 0 && "Need to initialize SSAUpdater");
57 assert(PrototypeValue->getType() == V->getType() &&
57 assert(ProtoType != 0 && "Need to initialize SSAUpdater");
58 assert(ProtoType == V->getType() &&
5859 "All rewritten values must have the same type");
5960 getAvailableVals(AV)[BB] = V;
6061 }
147148
148149 // If there are no predecessors, just return undef.
149150 if (PredValues.empty())
150 return UndefValue::get(PrototypeValue->getType());
151 return UndefValue::get(ProtoType);
151152
152153 // Otherwise, if all the merged values are the same, just use it.
153154 if (SingularValue != 0)
167168 }
168169
169170 // Ok, we have no way out, insert a new one now.
170 PHINode *InsertedPHI = PHINode::Create(PrototypeValue->getType(),
171 PrototypeValue->getName(),
172 &BB->front());
171 PHINode *InsertedPHI = PHINode::Create(ProtoType, ProtoName, &BB->front());
173172 InsertedPHI->reserveOperandSpace(PredValues.size());
174173
175174 // Fill in all the predecessors of the PHI.
281280 /// GetUndefVal - Get an undefined value of the same type as the value
282281 /// being handled.
283282 static Value *GetUndefVal(BasicBlock *BB, SSAUpdater *Updater) {
284 return UndefValue::get(Updater->PrototypeValue->getType());
283 return UndefValue::get(Updater->ProtoType);
285284 }
286285
287286 /// CreateEmptyPHI - Create a new PHI instruction in the specified block.
288287 /// Reserve space for the operands but do not fill them in yet.
289288 static Value *CreateEmptyPHI(BasicBlock *BB, unsigned NumPreds,
290289 SSAUpdater *Updater) {
291 PHINode *PHI = PHINode::Create(Updater->PrototypeValue->getType(),
292 Updater->PrototypeValue->getName(),
290 PHINode *PHI = PHINode::Create(Updater->ProtoType, Updater->ProtoName,
293291 &BB->front());
294292 PHI->reserveOperandSpace(NumPreds);
295293 return PHI;