mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-23 17:24:48 +00:00
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
This commit is contained in:
@ -12,15 +12,16 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/Module.h"
|
||||||
|
#include "llvm/Analysis/AliasAnalysis.h"
|
||||||
#include "llvm/Analysis/DataStructure.h"
|
#include "llvm/Analysis/DataStructure.h"
|
||||||
#include "llvm/Analysis/DSGraph.h"
|
#include "llvm/Analysis/DSGraph.h"
|
||||||
#include "llvm/Analysis/AliasAnalysis.h"
|
|
||||||
#include "llvm/Module.h"
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class DSAA : public Pass, public AliasAnalysis {
|
class DSAA : public Pass, public AliasAnalysis {
|
||||||
TDDataStructures *TD;
|
TDDataStructures *TD;
|
||||||
|
BUDataStructures *BU;
|
||||||
public:
|
public:
|
||||||
DSAA() : TD(0) {}
|
DSAA() : TD(0) {}
|
||||||
|
|
||||||
@ -34,14 +35,16 @@ namespace {
|
|||||||
bool run(Module &M) {
|
bool run(Module &M) {
|
||||||
InitializeAliasAnalysis(this);
|
InitializeAliasAnalysis(this);
|
||||||
TD = &getAnalysis<TDDataStructures>();
|
TD = &getAnalysis<TDDataStructures>();
|
||||||
|
BU = &getAnalysis<BUDataStructures>();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AliasAnalysis::getAnalysisUsage(AU);
|
AliasAnalysis::getAnalysisUsage(AU);
|
||||||
AU.setPreservesAll(); // Does not transform code...
|
AU.setPreservesAll(); // Does not transform code
|
||||||
AU.addRequired<TDDataStructures>(); // Uses TD Datastructures
|
AU.addRequiredTransitive<TDDataStructures>(); // Uses TD Datastructures
|
||||||
AU.addRequired<AliasAnalysis>(); // Chains to another AA impl...
|
AU.addRequiredTransitive<BUDataStructures>(); // Uses BU Datastructures
|
||||||
|
AU.addRequired<AliasAnalysis>(); // Chains to another AA impl
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------
|
//------------------------------------------------
|
||||||
@ -56,6 +59,9 @@ namespace {
|
|||||||
bool pointsToConstantMemory(const Value *P) {
|
bool pointsToConstantMemory(const Value *P) {
|
||||||
return getAnalysis<AliasAnalysis>().pointsToConstantMemory(P);
|
return getAnalysis<AliasAnalysis>().pointsToConstantMemory(P);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AliasAnalysis::ModRefResult
|
||||||
|
getModRefInfo(CallSite CS, Value *P, unsigned Size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DSGraph *getGraphForValue(const Value *V);
|
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);
|
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
|
/// getMustAliases - If there are any pointers known that must alias this
|
||||||
/// pointer, return them now. This allows alias-set based alias analyses to
|
/// pointer, return them now. This allows alias-set based alias analyses to
|
||||||
|
Reference in New Issue
Block a user