mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-07 20:40:46 +00:00
Add support for getelementptr, load, and correctly reject volatile stores.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23441 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d44b0ff038
commit
04de1cfb2b
@ -1263,6 +1263,23 @@ static void CommitValueTo(Constant *Val, Constant *Addr) {
|
|||||||
GV->setInitializer(Val);
|
GV->setInitializer(Val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Constant *ComputeLoadResult(Constant *P,
|
||||||
|
const std::map<Constant*, Constant*> &Memory) {
|
||||||
|
// If this memory location has been recently stored, use the stored value: it
|
||||||
|
// is the most up-to-date.
|
||||||
|
std::map<Constant*, Constant*>::const_iterator I = Memory.find(P);
|
||||||
|
if (I != Memory.end()) return I->second;
|
||||||
|
|
||||||
|
// Access it.
|
||||||
|
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(P)) {
|
||||||
|
if (GV->hasInitializer())
|
||||||
|
return GV->getInitializer();
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 0; // don't know how to evaluate.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// EvaluateStaticConstructor - Evaluate static constructors in the function, if
|
/// EvaluateStaticConstructor - Evaluate static constructors in the function, if
|
||||||
/// we can. Return true if we can, false otherwise.
|
/// we can. Return true if we can, false otherwise.
|
||||||
static bool EvaluateStaticConstructor(Function *F) {
|
static bool EvaluateStaticConstructor(Function *F) {
|
||||||
@ -1288,6 +1305,7 @@ static bool EvaluateStaticConstructor(Function *F) {
|
|||||||
Constant *InstResult = 0;
|
Constant *InstResult = 0;
|
||||||
|
|
||||||
if (StoreInst *SI = dyn_cast<StoreInst>(CurInst)) {
|
if (StoreInst *SI = dyn_cast<StoreInst>(CurInst)) {
|
||||||
|
if (SI->isVolatile()) return false; // no volatile accesses.
|
||||||
Constant *Ptr = getVal(Values, SI->getOperand(1));
|
Constant *Ptr = getVal(Values, SI->getOperand(1));
|
||||||
if (!isSimpleEnoughPointerToCommit(Ptr))
|
if (!isSimpleEnoughPointerToCommit(Ptr))
|
||||||
// If this is too complex for us to commit, reject it.
|
// If this is too complex for us to commit, reject it.
|
||||||
@ -1309,6 +1327,17 @@ static bool EvaluateStaticConstructor(Function *F) {
|
|||||||
InstResult = ConstantExpr::getSelect(getVal(Values, SI->getOperand(0)),
|
InstResult = ConstantExpr::getSelect(getVal(Values, SI->getOperand(0)),
|
||||||
getVal(Values, SI->getOperand(1)),
|
getVal(Values, SI->getOperand(1)),
|
||||||
getVal(Values, SI->getOperand(2)));
|
getVal(Values, SI->getOperand(2)));
|
||||||
|
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(CurInst)) {
|
||||||
|
Constant *P = getVal(Values, GEP->getOperand(0));
|
||||||
|
std::vector<Constant*> GEPOps;
|
||||||
|
for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i)
|
||||||
|
GEPOps.push_back(getVal(Values, GEP->getOperand(i)));
|
||||||
|
InstResult = ConstantExpr::getGetElementPtr(P, GEPOps);
|
||||||
|
} else if (LoadInst *LI = dyn_cast<LoadInst>(CurInst)) {
|
||||||
|
if (LI->isVolatile()) return false; // no volatile accesses.
|
||||||
|
InstResult = ComputeLoadResult(getVal(Values, LI->getOperand(0)),
|
||||||
|
MutatedMemory);
|
||||||
|
if (InstResult == 0) return false; // Could not evaluate load.
|
||||||
} else if (TerminatorInst *TI = dyn_cast<TerminatorInst>(CurInst)) {
|
} else if (TerminatorInst *TI = dyn_cast<TerminatorInst>(CurInst)) {
|
||||||
BasicBlock *NewBB = 0;
|
BasicBlock *NewBB = 0;
|
||||||
if (BranchInst *BI = dyn_cast<BranchInst>(CurInst)) {
|
if (BranchInst *BI = dyn_cast<BranchInst>(CurInst)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user