//
//===----------------------------------------------------------------------===//
-#include "llvm/Analysis/DataStructure.h"
-#include "llvm/Analysis/DSGraph.h"
-#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Module.h"
+#include "llvm/Analysis/AliasAnalysis.h"
+#include "llvm/Analysis/DataStructure/DataStructure.h"
+#include "llvm/Analysis/DataStructure/DSGraph.h"
using namespace llvm;
namespace {
class DSAA : public Pass, public AliasAnalysis {
TDDataStructures *TD;
+ BUDataStructures *BU;
public:
DSAA() : TD(0) {}
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
}
//------------------------------------------------
void getMustAliases(Value *P, std::vector<Value*> &RetVals);
- bool pointsToConstantMemory(const Value *P) {
- return getAnalysis<AliasAnalysis>().pointsToConstantMemory(P);
- }
+ ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size);
private:
DSGraph *getGraphForValue(const Value *V);
const DSGraph::ScalarMapTy &GSM = G.getScalarMap();
DSGraph::ScalarMapTy::const_iterator I = GSM.find((Value*)V1);
- if (I != GSM.end()) {
- assert(I->second.getNode() && "Scalar map points to null node?");
- DSGraph::ScalarMapTy::const_iterator J = GSM.find((Value*)V2);
- if (J != GSM.end()) {
- assert(J->second.getNode() && "Scalar map points to null node?");
-
- DSNode *N1 = I->second.getNode(), *N2 = J->second.getNode();
- unsigned O1 = I->second.getOffset(), O2 = J->second.getOffset();
+ if (I == GSM.end()) return NoAlias;
+
+ assert(I->second.getNode() && "Scalar map points to null node?");
+ DSGraph::ScalarMapTy::const_iterator J = GSM.find((Value*)V2);
+ if (J == GSM.end()) return NoAlias;
+
+ assert(J->second.getNode() && "Scalar map points to null node?");
+
+ DSNode *N1 = I->second.getNode(), *N2 = J->second.getNode();
+ unsigned O1 = I->second.getOffset(), O2 = J->second.getOffset();
- // We can only make a judgment of one of the nodes is complete...
- if (N1->isComplete() || N2->isComplete()) {
- if (N1 != N2)
- return NoAlias; // Completely different nodes.
+ // We can only make a judgment of one of the nodes is complete...
+ if (N1->isComplete() || N2->isComplete()) {
+ if (N1 != N2)
+ return NoAlias; // Completely different nodes.
#if 0 // This does not correctly handle arrays!
- // Both point to the same node and same offset, and there is only one
- // physical memory object represented in the node, return must alias.
- //
- // FIXME: This isn't correct because we do not handle array indexing
- // correctly.
-
- if (O1 == O2 && isSinglePhysicalObject(N1))
- return MustAlias; // Exactly the same object & offset
+ // Both point to the same node and same offset, and there is only one
+ // physical memory object represented in the node, return must alias.
+ //
+ // FIXME: This isn't correct because we do not handle array indexing
+ // correctly.
+
+ if (O1 == O2 && isSinglePhysicalObject(N1))
+ return MustAlias; // Exactly the same object & offset
#endif
- // See if they point to different offsets... if so, we may be able to
- // determine that they do not alias...
- if (O1 != O2) {
- if (O2 < O1) { // Ensure that O1 <= O2
- std::swap(V1, V2);
- std::swap(O1, O2);
- std::swap(V1Size, V2Size);
- }
-
- // FIXME: This is not correct because we do not handle array
- // indexing correctly with this check!
- //if (O1+V1Size <= O2) return NoAlias;
- }
+ // See if they point to different offsets... if so, we may be able to
+ // determine that they do not alias...
+ if (O1 != O2) {
+ if (O2 < O1) { // Ensure that O1 <= O2
+ std::swap(V1, V2);
+ std::swap(O1, O2);
+ std::swap(V1Size, V2Size);
}
+
+ // FIXME: This is not correct because we do not handle array
+ // indexing correctly with this check!
+ //if (O1+V1Size <= O2) return NoAlias;
}
}
// FIXME: we could improve on this by checking the globals graph for aliased
// global queries...
- return getAnalysis<AliasAnalysis>().alias(V1, V1Size, V2, V2Size);
+ return 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;
}
}
}
#endif
- return getAnalysis<AliasAnalysis>().getMustAliases(P, RetVals);
+ return AliasAnalysis::getMustAliases(P, RetVals);
}