diff options
author | Misha Brukman <brukman+llvm@gmail.com> | 2004-03-12 06:14:22 +0000 |
---|---|---|
committer | Misha Brukman <brukman+llvm@gmail.com> | 2004-03-12 06:14:22 +0000 |
commit | a975a9ab8093f94410ff3083ace6546a90462b6a (patch) | |
tree | 6e4d7d4e0ccbaf7adac314801afd6659da48bd0f /lib/Analysis | |
parent | 8e18789ede4f1d1684e949af9dac0e033971ee27 (diff) | |
download | external_llvm-a975a9ab8093f94410ff3083ace6546a90462b6a.zip external_llvm-a975a9ab8093f94410ff3083ace6546a90462b6a.tar.gz external_llvm-a975a9ab8093f94410ff3083ace6546a90462b6a.tar.bz2 |
Implement getModRefInfo() for DSA to calculate whether a function modifies or
references a pointer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12330 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/DataStructure/DataStructureAA.cpp | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/lib/Analysis/DataStructure/DataStructureAA.cpp b/lib/Analysis/DataStructure/DataStructureAA.cpp index 1f24470..152e53c 100644 --- a/lib/Analysis/DataStructure/DataStructureAA.cpp +++ b/lib/Analysis/DataStructure/DataStructureAA.cpp @@ -12,15 +12,16 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Module.h" +#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/DataStructure.h" #include "llvm/Analysis/DSGraph.h" -#include "llvm/Analysis/AliasAnalysis.h" -#include "llvm/Module.h" using namespace llvm; namespace { class DSAA : public Pass, public AliasAnalysis { TDDataStructures *TD; + BUDataStructures *BU; public: DSAA() : TD(0) {} @@ -34,14 +35,16 @@ namespace { bool run(Module &M) { InitializeAliasAnalysis(this); TD = &getAnalysis<TDDataStructures>(); + BU = &getAnalysis<BUDataStructures>(); return false; } virtual void getAnalysisUsage(AnalysisUsage &AU) const { AliasAnalysis::getAnalysisUsage(AU); - AU.setPreservesAll(); // Does not transform code... - AU.addRequired<TDDataStructures>(); // Uses TD Datastructures - AU.addRequired<AliasAnalysis>(); // Chains to another AA impl... + AU.setPreservesAll(); // Does not transform code + AU.addRequiredTransitive<TDDataStructures>(); // Uses TD Datastructures + AU.addRequiredTransitive<BUDataStructures>(); // Uses BU Datastructures + AU.addRequired<AliasAnalysis>(); // Chains to another AA impl } //------------------------------------------------ @@ -56,6 +59,9 @@ namespace { bool pointsToConstantMemory(const Value *P) { return getAnalysis<AliasAnalysis>().pointsToConstantMemory(P); } + + AliasAnalysis::ModRefResult + getModRefInfo(CallSite CS, Value *P, unsigned Size); private: DSGraph *getGraphForValue(const Value *V); @@ -152,6 +158,34 @@ AliasAnalysis::AliasResult DSAA::alias(const Value *V1, unsigned V1Size, return getAnalysis<AliasAnalysis>().alias(V1, V1Size, V2, V2Size); } +/// getModRefInfo - does a callsite modify or reference a value? +/// +AliasAnalysis::ModRefResult +DSAA::getModRefInfo(CallSite CS, Value *P, unsigned Size) { + Function *F = CS.getCalledFunction(); + if (!F) return pointsToConstantMemory(P) ? Ref : ModRef; + if (F->isExternal()) return ModRef; + + // Clone the function TD graph, clearing off Mod/Ref flags + const Function *csParent = CS.getInstruction()->getParent()->getParent(); + DSGraph TDGraph(TD->getDSGraph(*csParent)); + TDGraph.maskNodeTypes(0); + + // Insert the callee's BU graph into the TD graph + const DSGraph &BUGraph = BU->getDSGraph(*F); + TDGraph.mergeInGraph(TDGraph.getDSCallSiteForCallSite(CS), + *F, BUGraph, 0); + + // Report the flags that have been added + const DSNodeHandle &DSH = TDGraph.getNodeForValue(P); + if (const DSNode *N = DSH.getNode()) + if (N->isModified()) + return N->isRead() ? ModRef : Mod; + else + return N->isRead() ? Ref : NoModRef; + return NoModRef; +} + /// getMustAliases - If there are any pointers known that must alias this /// pointer, return them now. This allows alias-set based alias analyses to |