From fecbc59be6a53fb487a2405799d7a452e022142d Mon Sep 17 00:00:00 2001 From: Andreas Bolka Date: Wed, 1 Jul 2009 21:45:23 +0000 Subject: [PATCH] Use AA to check objects before LDA. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74647 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm/Analysis/LoopDependenceAnalysis.h | 2 ++ lib/Analysis/LoopDependenceAnalysis.cpp | 27 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/llvm/Analysis/LoopDependenceAnalysis.h b/include/llvm/Analysis/LoopDependenceAnalysis.h index 044270da314..67da2e7fbc1 100644 --- a/include/llvm/Analysis/LoopDependenceAnalysis.h +++ b/include/llvm/Analysis/LoopDependenceAnalysis.h @@ -26,12 +26,14 @@ namespace llvm { + class AliasAnalysis; class AnalysisUsage; class ScalarEvolution; class Value; class LoopDependenceAnalysis : public LoopPass { Loop *L; + AliasAnalysis *AA; ScalarEvolution *SE; public: diff --git a/lib/Analysis/LoopDependenceAnalysis.cpp b/lib/Analysis/LoopDependenceAnalysis.cpp index c1168eccaad..a49f18166dc 100644 --- a/lib/Analysis/LoopDependenceAnalysis.cpp +++ b/lib/Analysis/LoopDependenceAnalysis.cpp @@ -18,11 +18,13 @@ //===----------------------------------------------------------------------===// #define DEBUG_TYPE "lda" +#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/LoopDependenceAnalysis.h" #include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Instructions.h" #include "llvm/Support/Debug.h" +#include "llvm/Target/TargetData.h" using namespace llvm; LoopPass *llvm::createLoopDependenceAnalysisPass() { @@ -91,25 +93,20 @@ bool LoopDependenceAnalysis::depends(Value *src, Value *dst) { Value *dstPtr = GetPointerOperand(dst); const Value *srcObj = srcPtr->getUnderlyingObject(); const Value *dstObj = dstPtr->getUnderlyingObject(); - const Type *srcTy = srcObj->getType(); - const Type *dstTy = dstObj->getType(); + AliasAnalysis::AliasResult alias = AA->alias( + 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 - // values, as we know that their underlying memory areas will not overlap. - // MAYBE: relax this and test for aliasing? - if (!((isa(srcObj) || isa(srcObj)) && - (isa(dstObj) || isa(dstObj)) && - isa(srcTy) && - isa(dstTy) && - isa(cast(srcTy)->getElementType()) && - isa(cast(dstTy)->getElementType()))) + // If we don't know whether or not the two objects alias, assume dependence. + if (alias == AliasAnalysis::MayAlias) return true; - // If the arrays are different, the underlying memory areas do not overlap - // and the memory accesses are therefore independent. - if (srcObj != dstObj) + // If the objects noalias, they are distinct, accesses are independent. + if (alias == AliasAnalysis::NoAlias) return false; + // TODO: the underlying objects MustAlias, test for dependence + // We couldn't establish a more precise result, so we have to conservatively // assume full dependence. return true; @@ -121,12 +118,14 @@ bool LoopDependenceAnalysis::depends(Value *src, Value *dst) { bool LoopDependenceAnalysis::runOnLoop(Loop *L, LPPassManager &) { this->L = L; + AA = &getAnalysis(); SE = &getAnalysis(); return false; } void LoopDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); + AU.addRequiredTransitive(); AU.addRequiredTransitive(); }