From a975a9ab8093f94410ff3083ace6546a90462b6a Mon Sep 17 00:00:00 2001 From: Misha Brukman Date: Fri, 12 Mar 2004 06:14:22 +0000 Subject: [PATCH] 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 --- .../DataStructure/DataStructureAA.cpp | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/lib/Analysis/DataStructure/DataStructureAA.cpp b/lib/Analysis/DataStructure/DataStructureAA.cpp index 1f244708bd3..152e53ca555 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(); + BU = &getAnalysis(); return false; } virtual void getAnalysisUsage(AnalysisUsage &AU) const { AliasAnalysis::getAnalysisUsage(AU); - AU.setPreservesAll(); // Does not transform code... - AU.addRequired(); // Uses TD Datastructures - AU.addRequired(); // Chains to another AA impl... + AU.setPreservesAll(); // Does not transform code + AU.addRequiredTransitive(); // Uses TD Datastructures + AU.addRequiredTransitive(); // Uses BU Datastructures + AU.addRequired(); // Chains to another AA impl } //------------------------------------------------ @@ -56,6 +59,9 @@ namespace { bool pointsToConstantMemory(const Value *P) { return getAnalysis().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().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