mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
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. llvm-svn: 112699
This commit is contained in:
parent
67159c80d8
commit
f7e2f45e1a
@ -36,9 +36,11 @@ private:
|
|||||||
//typedef DenseMap<BasicBlock*, Value*> AvailableValsTy;
|
//typedef DenseMap<BasicBlock*, Value*> AvailableValsTy;
|
||||||
void *AV;
|
void *AV;
|
||||||
|
|
||||||
/// PrototypeValue is an arbitrary representative value, which we derive names
|
/// ProtoType holds the type of the values being rewritten.
|
||||||
/// and a type for PHI nodes.
|
const Type *ProtoType;
|
||||||
Value *PrototypeValue;
|
|
||||||
|
// PHI nodes are given a name based on ProtoName.
|
||||||
|
std::string ProtoName;
|
||||||
|
|
||||||
/// InsertedPHIs - If this is non-null, the SSAUpdater adds all PHI nodes that
|
/// InsertedPHIs - If this is non-null, the SSAUpdater adds all PHI nodes that
|
||||||
/// it creates to the vector.
|
/// it creates to the vector.
|
||||||
@ -51,8 +53,8 @@ public:
|
|||||||
~SSAUpdater();
|
~SSAUpdater();
|
||||||
|
|
||||||
/// Initialize - Reset this object to get ready for a new set of SSA
|
/// Initialize - Reset this object to get ready for a new set of SSA
|
||||||
/// updates. ProtoValue is the value used to name PHI nodes.
|
/// updates with type 'Ty'. PHI nodes get a name based on 'Name'.
|
||||||
void Initialize(Value *ProtoValue);
|
void Initialize(const Type *Ty, StringRef Name);
|
||||||
|
|
||||||
/// AddAvailableValue - Indicate that a rewritten value is available at the
|
/// AddAvailableValue - Indicate that a rewritten value is available at the
|
||||||
/// end of the specified block with the specified value.
|
/// end of the specified block with the specified value.
|
||||||
|
@ -1310,7 +1310,7 @@ static Value *ConstructSSAForLoadSet(LoadInst *LI,
|
|||||||
// Otherwise, we have to construct SSA form.
|
// Otherwise, we have to construct SSA form.
|
||||||
SmallVector<PHINode*, 8> NewPHIs;
|
SmallVector<PHINode*, 8> NewPHIs;
|
||||||
SSAUpdater SSAUpdate(&NewPHIs);
|
SSAUpdater SSAUpdate(&NewPHIs);
|
||||||
SSAUpdate.Initialize(LI);
|
SSAUpdate.Initialize(LI->getType(), LI->getName());
|
||||||
|
|
||||||
const Type *LoadTy = LI->getType();
|
const Type *LoadTy = LI->getType();
|
||||||
|
|
||||||
|
@ -1526,7 +1526,7 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB,
|
|||||||
// We found a use of I outside of BB. Rename all uses of I that are outside
|
// We found a use of I outside of BB. Rename all uses of I that are outside
|
||||||
// its block to be uses of the appropriate PHI node etc. See ValuesInBlocks
|
// its block to be uses of the appropriate PHI node etc. See ValuesInBlocks
|
||||||
// with the two values we know.
|
// with the two values we know.
|
||||||
SSAUpdate.Initialize(I);
|
SSAUpdate.Initialize(I->getType(), I->getName());
|
||||||
SSAUpdate.AddAvailableValue(BB, I);
|
SSAUpdate.AddAvailableValue(BB, I);
|
||||||
SSAUpdate.AddAvailableValue(NewBB, ValueMapping[I]);
|
SSAUpdate.AddAvailableValue(NewBB, ValueMapping[I]);
|
||||||
|
|
||||||
@ -1681,7 +1681,7 @@ bool JumpThreading::DuplicateCondBranchOnPHIIntoPred(BasicBlock *BB,
|
|||||||
// We found a use of I outside of BB. Rename all uses of I that are outside
|
// We found a use of I outside of BB. Rename all uses of I that are outside
|
||||||
// its block to be uses of the appropriate PHI node etc. See ValuesInBlocks
|
// its block to be uses of the appropriate PHI node etc. See ValuesInBlocks
|
||||||
// with the two values we know.
|
// with the two values we know.
|
||||||
SSAUpdate.Initialize(I);
|
SSAUpdate.Initialize(I->getType(), I->getName());
|
||||||
SSAUpdate.AddAvailableValue(BB, I);
|
SSAUpdate.AddAvailableValue(BB, I);
|
||||||
SSAUpdate.AddAvailableValue(PredBB, ValueMapping[I]);
|
SSAUpdate.AddAvailableValue(PredBB, ValueMapping[I]);
|
||||||
|
|
||||||
|
@ -526,7 +526,7 @@ void LICM::sink(Instruction &I) {
|
|||||||
SSAUpdater SSA(&NewPHIs);
|
SSAUpdater SSA(&NewPHIs);
|
||||||
|
|
||||||
if (!I.use_empty())
|
if (!I.use_empty())
|
||||||
SSA.Initialize(&I);
|
SSA.Initialize(I.getType(), I.getName());
|
||||||
|
|
||||||
// Insert a copy of the instruction in each exit block of the loop that is
|
// Insert a copy of the instruction in each exit block of the loop that is
|
||||||
// dominated by the instruction. Each exit block is known to only be in the
|
// dominated by the instruction. Each exit block is known to only be in the
|
||||||
@ -728,7 +728,7 @@ void LICM::PromoteAliasSet(AliasSet &AS) {
|
|||||||
SomeValue = LoopUses[0];
|
SomeValue = LoopUses[0];
|
||||||
else
|
else
|
||||||
SomeValue = cast<StoreInst>(LoopUses[0])->getOperand(0);
|
SomeValue = cast<StoreInst>(LoopUses[0])->getOperand(0);
|
||||||
SSA.Initialize(SomeValue);
|
SSA.Initialize(SomeValue->getType(), SomeValue->getName());
|
||||||
|
|
||||||
// First step: bucket up uses of the pointers by the block they occur in.
|
// First step: bucket up uses of the pointers by the block they occur in.
|
||||||
// This is important because we have to handle multiple defs/uses in a block
|
// This is important because we have to handle multiple defs/uses in a block
|
||||||
|
@ -221,7 +221,7 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
|
|||||||
|
|
||||||
// The value now exits in two versions: the initial value in the preheader
|
// The value now exits in two versions: the initial value in the preheader
|
||||||
// and the loop "next" value in the original header.
|
// and the loop "next" value in the original header.
|
||||||
SSA.Initialize(OrigHeaderVal);
|
SSA.Initialize(OrigHeaderVal->getType(), OrigHeaderVal->getName());
|
||||||
SSA.AddAvailableValue(OrigHeader, OrigHeaderVal);
|
SSA.AddAvailableValue(OrigHeader, OrigHeaderVal);
|
||||||
SSA.AddAvailableValue(OrigPreHeader, OrigPreHeaderVal);
|
SSA.AddAvailableValue(OrigPreHeader, OrigPreHeaderVal);
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ bool LCSSA::ProcessInstruction(Instruction *Inst,
|
|||||||
DomTreeNode *DomNode = DT->getNode(DomBB);
|
DomTreeNode *DomNode = DT->getNode(DomBB);
|
||||||
|
|
||||||
SSAUpdater SSAUpdate;
|
SSAUpdater SSAUpdate;
|
||||||
SSAUpdate.Initialize(Inst);
|
SSAUpdate.Initialize(Inst->getType(), Inst->getName());
|
||||||
|
|
||||||
// Insert the LCSSA phi's into all of the exit blocks dominated by the
|
// Insert the LCSSA phi's into all of the exit blocks dominated by the
|
||||||
// value, and add them to the Phi's map.
|
// value, and add them to the Phi's map.
|
||||||
|
@ -29,20 +29,21 @@ static AvailableValsTy &getAvailableVals(void *AV) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SSAUpdater::SSAUpdater(SmallVectorImpl<PHINode*> *NewPHI)
|
SSAUpdater::SSAUpdater(SmallVectorImpl<PHINode*> *NewPHI)
|
||||||
: AV(0), PrototypeValue(0), InsertedPHIs(NewPHI) {}
|
: AV(0), ProtoType(0), ProtoName(), InsertedPHIs(NewPHI) {}
|
||||||
|
|
||||||
SSAUpdater::~SSAUpdater() {
|
SSAUpdater::~SSAUpdater() {
|
||||||
delete &getAvailableVals(AV);
|
delete &getAvailableVals(AV);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize - Reset this object to get ready for a new set of SSA
|
/// Initialize - Reset this object to get ready for a new set of SSA
|
||||||
/// updates. ProtoValue is the value used to name PHI nodes.
|
/// updates with type 'Ty'. PHI nodes get a name based on 'Name'.
|
||||||
void SSAUpdater::Initialize(Value *ProtoValue) {
|
void SSAUpdater::Initialize(const Type *Ty, StringRef Name) {
|
||||||
if (AV == 0)
|
if (AV == 0)
|
||||||
AV = new AvailableValsTy();
|
AV = new AvailableValsTy();
|
||||||
else
|
else
|
||||||
getAvailableVals(AV).clear();
|
getAvailableVals(AV).clear();
|
||||||
PrototypeValue = ProtoValue;
|
ProtoType = Ty;
|
||||||
|
ProtoName = Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// HasValueForBlock - Return true if the SSAUpdater already has a value for
|
/// HasValueForBlock - Return true if the SSAUpdater already has a value for
|
||||||
@ -54,8 +55,8 @@ bool SSAUpdater::HasValueForBlock(BasicBlock *BB) const {
|
|||||||
/// AddAvailableValue - Indicate that a rewritten value is available in the
|
/// AddAvailableValue - Indicate that a rewritten value is available in the
|
||||||
/// specified block with the specified value.
|
/// specified block with the specified value.
|
||||||
void SSAUpdater::AddAvailableValue(BasicBlock *BB, Value *V) {
|
void SSAUpdater::AddAvailableValue(BasicBlock *BB, Value *V) {
|
||||||
assert(PrototypeValue != 0 && "Need to initialize SSAUpdater");
|
assert(ProtoType != 0 && "Need to initialize SSAUpdater");
|
||||||
assert(PrototypeValue->getType() == V->getType() &&
|
assert(ProtoType == V->getType() &&
|
||||||
"All rewritten values must have the same type");
|
"All rewritten values must have the same type");
|
||||||
getAvailableVals(AV)[BB] = V;
|
getAvailableVals(AV)[BB] = V;
|
||||||
}
|
}
|
||||||
@ -148,7 +149,7 @@ Value *SSAUpdater::GetValueInMiddleOfBlock(BasicBlock *BB) {
|
|||||||
|
|
||||||
// If there are no predecessors, just return undef.
|
// If there are no predecessors, just return undef.
|
||||||
if (PredValues.empty())
|
if (PredValues.empty())
|
||||||
return UndefValue::get(PrototypeValue->getType());
|
return UndefValue::get(ProtoType);
|
||||||
|
|
||||||
// Otherwise, if all the merged values are the same, just use it.
|
// Otherwise, if all the merged values are the same, just use it.
|
||||||
if (SingularValue != 0)
|
if (SingularValue != 0)
|
||||||
@ -168,9 +169,7 @@ Value *SSAUpdater::GetValueInMiddleOfBlock(BasicBlock *BB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ok, we have no way out, insert a new one now.
|
// Ok, we have no way out, insert a new one now.
|
||||||
PHINode *InsertedPHI = PHINode::Create(PrototypeValue->getType(),
|
PHINode *InsertedPHI = PHINode::Create(ProtoType, ProtoName, &BB->front());
|
||||||
PrototypeValue->getName(),
|
|
||||||
&BB->front());
|
|
||||||
InsertedPHI->reserveOperandSpace(PredValues.size());
|
InsertedPHI->reserveOperandSpace(PredValues.size());
|
||||||
|
|
||||||
// Fill in all the predecessors of the PHI.
|
// Fill in all the predecessors of the PHI.
|
||||||
@ -282,15 +281,14 @@ public:
|
|||||||
/// GetUndefVal - Get an undefined value of the same type as the value
|
/// GetUndefVal - Get an undefined value of the same type as the value
|
||||||
/// being handled.
|
/// being handled.
|
||||||
static Value *GetUndefVal(BasicBlock *BB, SSAUpdater *Updater) {
|
static Value *GetUndefVal(BasicBlock *BB, SSAUpdater *Updater) {
|
||||||
return UndefValue::get(Updater->PrototypeValue->getType());
|
return UndefValue::get(Updater->ProtoType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// CreateEmptyPHI - Create a new PHI instruction in the specified block.
|
/// CreateEmptyPHI - Create a new PHI instruction in the specified block.
|
||||||
/// Reserve space for the operands but do not fill them in yet.
|
/// Reserve space for the operands but do not fill them in yet.
|
||||||
static Value *CreateEmptyPHI(BasicBlock *BB, unsigned NumPreds,
|
static Value *CreateEmptyPHI(BasicBlock *BB, unsigned NumPreds,
|
||||||
SSAUpdater *Updater) {
|
SSAUpdater *Updater) {
|
||||||
PHINode *PHI = PHINode::Create(Updater->PrototypeValue->getType(),
|
PHINode *PHI = PHINode::Create(Updater->ProtoType, Updater->ProtoName,
|
||||||
Updater->PrototypeValue->getName(),
|
|
||||||
&BB->front());
|
&BB->front());
|
||||||
PHI->reserveOperandSpace(NumPreds);
|
PHI->reserveOperandSpace(NumPreds);
|
||||||
return PHI;
|
return PHI;
|
||||||
|
Loading…
Reference in New Issue
Block a user