Use AA to check objects before LDA.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74647 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Andreas Bolka 2009-07-01 21:45:23 +00:00
parent 6cc18fedf8
commit fecbc59be6
2 changed files with 15 additions and 14 deletions

View File

@ -26,12 +26,14 @@
namespace llvm { namespace llvm {
class AliasAnalysis;
class AnalysisUsage; class AnalysisUsage;
class ScalarEvolution; class ScalarEvolution;
class Value; class Value;
class LoopDependenceAnalysis : public LoopPass { class LoopDependenceAnalysis : public LoopPass {
Loop *L; Loop *L;
AliasAnalysis *AA;
ScalarEvolution *SE; ScalarEvolution *SE;
public: public:

View File

@ -18,11 +18,13 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#define DEBUG_TYPE "lda" #define DEBUG_TYPE "lda"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/LoopDependenceAnalysis.h" #include "llvm/Analysis/LoopDependenceAnalysis.h"
#include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Target/TargetData.h"
using namespace llvm; using namespace llvm;
LoopPass *llvm::createLoopDependenceAnalysisPass() { LoopPass *llvm::createLoopDependenceAnalysisPass() {
@ -91,25 +93,20 @@ bool LoopDependenceAnalysis::depends(Value *src, Value *dst) {
Value *dstPtr = GetPointerOperand(dst); Value *dstPtr = GetPointerOperand(dst);
const Value *srcObj = srcPtr->getUnderlyingObject(); const Value *srcObj = srcPtr->getUnderlyingObject();
const Value *dstObj = dstPtr->getUnderlyingObject(); const Value *dstObj = dstPtr->getUnderlyingObject();
const Type *srcTy = srcObj->getType(); AliasAnalysis::AliasResult alias = AA->alias(
const Type *dstTy = dstObj->getType(); srcObj, AA->getTargetData().getTypeStoreSize(srcObj->getType()),
dstObj, AA->getTargetData().getTypeStoreSize(dstObj->getType()));
// For now, we only work on (pointers to) global or stack-allocated array // If we don't know whether or not the two objects alias, assume dependence.
// values, as we know that their underlying memory areas will not overlap. if (alias == AliasAnalysis::MayAlias)
// MAYBE: relax this and test for aliasing?
if (!((isa<GlobalVariable>(srcObj) || isa<AllocaInst>(srcObj)) &&
(isa<GlobalVariable>(dstObj) || isa<AllocaInst>(dstObj)) &&
isa<PointerType>(srcTy) &&
isa<PointerType>(dstTy) &&
isa<ArrayType>(cast<PointerType>(srcTy)->getElementType()) &&
isa<ArrayType>(cast<PointerType>(dstTy)->getElementType())))
return true; return true;
// If the arrays are different, the underlying memory areas do not overlap // If the objects noalias, they are distinct, accesses are independent.
// and the memory accesses are therefore independent. if (alias == AliasAnalysis::NoAlias)
if (srcObj != dstObj)
return false; return false;
// TODO: the underlying objects MustAlias, test for dependence
// We couldn't establish a more precise result, so we have to conservatively // We couldn't establish a more precise result, so we have to conservatively
// assume full dependence. // assume full dependence.
return true; return true;
@ -121,12 +118,14 @@ bool LoopDependenceAnalysis::depends(Value *src, Value *dst) {
bool LoopDependenceAnalysis::runOnLoop(Loop *L, LPPassManager &) { bool LoopDependenceAnalysis::runOnLoop(Loop *L, LPPassManager &) {
this->L = L; this->L = L;
AA = &getAnalysis<AliasAnalysis>();
SE = &getAnalysis<ScalarEvolution>(); SE = &getAnalysis<ScalarEvolution>();
return false; return false;
} }
void LoopDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { void LoopDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll(); AU.setPreservesAll();
AU.addRequiredTransitive<AliasAnalysis>();
AU.addRequiredTransitive<ScalarEvolution>(); AU.addRequiredTransitive<ScalarEvolution>();
} }