diff options
author | Duncan Sands <baldrick@free.fr> | 2007-12-01 07:51:45 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2007-12-01 07:51:45 +0000 |
commit | 68b6f50938c6b1c2211a4a81ed3a52a4f5b594e5 (patch) | |
tree | 6405192899bb2bb1cf3474b67a87747fa6d91edc /llvm/lib/Transforms | |
parent | ae7a834e74e19f34b87c6546f5017ebb719bbad3 (diff) | |
download | bcm5719-llvm-68b6f50938c6b1c2211a4a81ed3a52a4f5b594e5.tar.gz bcm5719-llvm-68b6f50938c6b1c2211a4a81ed3a52a4f5b594e5.zip |
Integrate the readonly/readnone logic more deeply
into alias analysis. This meant updating the API
which now has versions of the getModRefBehavior,
doesNotAccessMemory and onlyReadsMemory methods
which take a callsite parameter. These should be
used unless the callsite is not known, since in
general they can do a better job than the versions
that take a function. Also, users should no longer
call the version of getModRefBehavior that takes
both a function and a callsite. To reduce the
chance of misuse it is now protected.
llvm-svn: 44487
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/ADCE.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/GVN.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/LICM.cpp | 30 |
4 files changed, 19 insertions, 27 deletions
diff --git a/llvm/lib/Transforms/Scalar/ADCE.cpp b/llvm/lib/Transforms/Scalar/ADCE.cpp index e3bd3623ce2..7f373342100 100644 --- a/llvm/lib/Transforms/Scalar/ADCE.cpp +++ b/llvm/lib/Transforms/Scalar/ADCE.cpp @@ -198,8 +198,7 @@ bool ADCE::doADCE() { for (BasicBlock::iterator II = BB->begin(), EI = BB->end(); II != EI; ) { Instruction *I = II++; if (CallInst *CI = dyn_cast<CallInst>(I)) { - Function *F = CI->getCalledFunction(); - if (F && AA.onlyReadsMemory(F)) { + if (AA.onlyReadsMemory(CI)) { if (CI->use_empty()) { BB->getInstList().erase(CI); ++NumCallRemoved; diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index b19077f1fcc..8e69d9ad689 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -306,8 +306,7 @@ bool DSE::handleEndBlock(BasicBlock& BB, // If this call does not access memory, it can't // be undeadifying any of our pointers. CallSite CS = CallSite::get(BBI); - if (CS.getCalledFunction() && - AA.doesNotAccessMemory(CS.getCalledFunction())) + if (AA.doesNotAccessMemory(CS)) continue; unsigned modRef = 0; diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index 7799befb3c2..c3d59854c65 100644 --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -341,8 +341,7 @@ Expression::ExpressionOpcode uint32_t ValueTable::hash_operand(Value* v) { if (CallInst* CI = dyn_cast<CallInst>(v)) - if (CI->getCalledFunction() && - !AA->doesNotAccessMemory(CI->getCalledFunction())) + if (!AA->doesNotAccessMemory(CI)) return nextValueNumber++; return lookup_or_add(v); @@ -485,9 +484,7 @@ uint32_t ValueTable::lookup_or_add(Value* V) { return VI->second; if (CallInst* C = dyn_cast<CallInst>(V)) { - if (C->getCalledFunction() && - (AA->doesNotAccessMemory(C->getCalledFunction()) || - AA->onlyReadsMemory(C->getCalledFunction()))) { + if (AA->onlyReadsMemory(C)) { // includes doesNotAccessMemory Expression e = create_expression(C); DenseMap<Expression, uint32_t>::iterator EI = expressionNumbering.find(e); @@ -1051,8 +1048,7 @@ bool GVN::processInstruction(Instruction* I, if (CallInst* CI = dyn_cast<CallInst>(I)) { AliasAnalysis& AA = getAnalysis<AliasAnalysis>(); - if (CI->getCalledFunction() && - !AA.doesNotAccessMemory(CI->getCalledFunction())) { + if (!AA.doesNotAccessMemory(CI)) { MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>(); if (cast<Instruction>(repl)->getParent() != CI->getParent() || MD.getDependency(CI) != MD.getDependency(cast<CallInst>(repl))) { diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index c86b4639489..0c8cb4d0273 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -375,24 +375,22 @@ bool LICM::canSinkOrHoistInst(Instruction &I) { return !pointerInvalidatedByLoop(LI->getOperand(0), Size); } else if (CallInst *CI = dyn_cast<CallInst>(&I)) { // Handle obvious cases efficiently. - if (Function *Callee = CI->getCalledFunction()) { - AliasAnalysis::ModRefBehavior Behavior =AA->getModRefBehavior(Callee, CI); - if (Behavior == AliasAnalysis::DoesNotAccessMemory) - return true; - else if (Behavior == AliasAnalysis::OnlyReadsMemory) { - // If this call only reads from memory and there are no writes to memory - // in the loop, we can hoist or sink the call as appropriate. - bool FoundMod = false; - for (AliasSetTracker::iterator I = CurAST->begin(), E = CurAST->end(); - I != E; ++I) { - AliasSet &AS = *I; - if (!AS.isForwardingAliasSet() && AS.isMod()) { - FoundMod = true; - break; - } + AliasAnalysis::ModRefBehavior Behavior = AA->getModRefBehavior(CI); + if (Behavior == AliasAnalysis::DoesNotAccessMemory) + return true; + else if (Behavior == AliasAnalysis::OnlyReadsMemory) { + // If this call only reads from memory and there are no writes to memory + // in the loop, we can hoist or sink the call as appropriate. + bool FoundMod = false; + for (AliasSetTracker::iterator I = CurAST->begin(), E = CurAST->end(); + I != E; ++I) { + AliasSet &AS = *I; + if (!AS.isForwardingAliasSet() && AS.isMod()) { + FoundMod = true; + break; } - if (!FoundMod) return true; } + if (!FoundMod) return true; } // FIXME: This should use mod/ref information to see if we can hoist or sink |