[llvm] r353676 - Move CFLGraph and the AA summary code over to the new `CallBase`
Chandler Carruth via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 11 01:25:41 PST 2019
Author: chandlerc
Date: Mon Feb 11 01:25:41 2019
New Revision: 353676
URL: http://llvm.org/viewvc/llvm-project?rev=353676&view=rev
Log:
Move CFLGraph and the AA summary code over to the new `CallBase`
instruction base class rather than the `CallSite` wrapper.
Modified:
llvm/trunk/lib/Analysis/AliasAnalysisSummary.cpp
llvm/trunk/lib/Analysis/AliasAnalysisSummary.h
llvm/trunk/lib/Analysis/CFLGraph.h
Modified: llvm/trunk/lib/Analysis/AliasAnalysisSummary.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AliasAnalysisSummary.cpp?rev=353676&r1=353675&r2=353676&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/AliasAnalysisSummary.cpp (original)
+++ llvm/trunk/lib/Analysis/AliasAnalysisSummary.cpp Mon Feb 11 01:25:41 2019
@@ -73,28 +73,28 @@ AliasAttrs getExternallyVisibleAttrs(Ali
}
Optional<InstantiatedValue> instantiateInterfaceValue(InterfaceValue IValue,
- CallSite CS) {
+ CallBase &Call) {
auto Index = IValue.Index;
- auto Value = (Index == 0) ? CS.getInstruction() : CS.getArgument(Index - 1);
- if (Value->getType()->isPointerTy())
- return InstantiatedValue{Value, IValue.DerefLevel};
+ auto *V = (Index == 0) ? &Call : Call.getArgOperand(Index - 1);
+ if (V->getType()->isPointerTy())
+ return InstantiatedValue{V, IValue.DerefLevel};
return None;
}
Optional<InstantiatedRelation>
-instantiateExternalRelation(ExternalRelation ERelation, CallSite CS) {
- auto From = instantiateInterfaceValue(ERelation.From, CS);
+instantiateExternalRelation(ExternalRelation ERelation, CallBase &Call) {
+ auto From = instantiateInterfaceValue(ERelation.From, Call);
if (!From)
return None;
- auto To = instantiateInterfaceValue(ERelation.To, CS);
+ auto To = instantiateInterfaceValue(ERelation.To, Call);
if (!To)
return None;
return InstantiatedRelation{*From, *To, ERelation.Offset};
}
Optional<InstantiatedAttr> instantiateExternalAttribute(ExternalAttribute EAttr,
- CallSite CS) {
- auto Value = instantiateInterfaceValue(EAttr.IValue, CS);
+ CallBase &Call) {
+ auto Value = instantiateInterfaceValue(EAttr.IValue, Call);
if (!Value)
return None;
return InstantiatedAttr{*Value, EAttr.Attr};
Modified: llvm/trunk/lib/Analysis/AliasAnalysisSummary.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AliasAnalysisSummary.h?rev=353676&r1=353675&r2=353676&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/AliasAnalysisSummary.h (original)
+++ llvm/trunk/lib/Analysis/AliasAnalysisSummary.h Mon Feb 11 01:25:41 2019
@@ -37,7 +37,7 @@
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/IR/CallSite.h"
+#include "llvm/IR/InstrTypes.h"
#include <bitset>
namespace llvm {
@@ -195,12 +195,13 @@ struct AliasSummary {
SmallVector<ExternalAttribute, 8> RetParamAttributes;
};
-/// This is the result of instantiating InterfaceValue at a particular callsite
+/// This is the result of instantiating InterfaceValue at a particular call
struct InstantiatedValue {
Value *Val;
unsigned DerefLevel;
};
-Optional<InstantiatedValue> instantiateInterfaceValue(InterfaceValue, CallSite);
+Optional<InstantiatedValue> instantiateInterfaceValue(InterfaceValue IValue,
+ CallBase &Call);
inline bool operator==(InstantiatedValue LHS, InstantiatedValue RHS) {
return LHS.Val == RHS.Val && LHS.DerefLevel == RHS.DerefLevel;
@@ -228,8 +229,8 @@ struct InstantiatedRelation {
InstantiatedValue From, To;
int64_t Offset;
};
-Optional<InstantiatedRelation> instantiateExternalRelation(ExternalRelation,
- CallSite);
+Optional<InstantiatedRelation>
+instantiateExternalRelation(ExternalRelation ERelation, CallBase &Call);
/// This is the result of instantiating ExternalAttribute at a particular
/// callsite
@@ -237,8 +238,8 @@ struct InstantiatedAttr {
InstantiatedValue IValue;
AliasAttrs Attr;
};
-Optional<InstantiatedAttr> instantiateExternalAttribute(ExternalAttribute,
- CallSite);
+Optional<InstantiatedAttr> instantiateExternalAttribute(ExternalAttribute EAttr,
+ CallBase &Call);
}
template <> struct DenseMapInfo<cflaa::InstantiatedValue> {
Modified: llvm/trunk/lib/Analysis/CFLGraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CFLGraph.h?rev=353676&r1=353675&r2=353676&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CFLGraph.h (original)
+++ llvm/trunk/lib/Analysis/CFLGraph.h Mon Feb 11 01:25:41 2019
@@ -24,7 +24,6 @@
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/BasicBlock.h"
-#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
@@ -190,9 +189,9 @@ template <typename CFLAA> class CFLGraph
// Returns possible functions called by CS into the given SmallVectorImpl.
// Returns true if targets found, false otherwise.
- static bool getPossibleTargets(CallSite CS,
+ static bool getPossibleTargets(CallBase &Call,
SmallVectorImpl<Function *> &Output) {
- if (auto *Fn = CS.getCalledFunction()) {
+ if (auto *Fn = Call.getCalledFunction()) {
Output.push_back(Fn);
return true;
}
@@ -369,11 +368,11 @@ template <typename CFLAA> class CFLGraph
return !Fn->hasExactDefinition();
}
- bool tryInterproceduralAnalysis(CallSite CS,
+ bool tryInterproceduralAnalysis(CallBase &Call,
const SmallVectorImpl<Function *> &Fns) {
assert(Fns.size() > 0);
- if (CS.arg_size() > MaxSupportedArgsInSummary)
+ if (Call.arg_size() > MaxSupportedArgsInSummary)
return false;
// Exit early if we'll fail anyway
@@ -381,7 +380,7 @@ template <typename CFLAA> class CFLGraph
if (isFunctionExternal(Fn) || Fn->isVarArg())
return false;
// Fail if the caller does not provide enough arguments
- assert(Fn->arg_size() <= CS.arg_size());
+ assert(Fn->arg_size() <= Call.arg_size());
if (!AA.getAliasSummary(*Fn))
return false;
}
@@ -392,7 +391,7 @@ template <typename CFLAA> class CFLGraph
auto &RetParamRelations = Summary->RetParamRelations;
for (auto &Relation : RetParamRelations) {
- auto IRelation = instantiateExternalRelation(Relation, CS);
+ auto IRelation = instantiateExternalRelation(Relation, Call);
if (IRelation.hasValue()) {
Graph.addNode(IRelation->From);
Graph.addNode(IRelation->To);
@@ -402,7 +401,7 @@ template <typename CFLAA> class CFLGraph
auto &RetParamAttributes = Summary->RetParamAttributes;
for (auto &Attribute : RetParamAttributes) {
- auto IAttr = instantiateExternalAttribute(Attribute, CS);
+ auto IAttr = instantiateExternalAttribute(Attribute, Call);
if (IAttr.hasValue())
Graph.addNode(IAttr->IValue, IAttr->Attr);
}
@@ -411,37 +410,35 @@ template <typename CFLAA> class CFLGraph
return true;
}
- void visitCallSite(CallSite CS) {
- auto Inst = CS.getInstruction();
-
+ void visitCallBase(CallBase &Call) {
// Make sure all arguments and return value are added to the graph first
- for (Value *V : CS.args())
+ for (Value *V : Call.args())
if (V->getType()->isPointerTy())
addNode(V);
- if (Inst->getType()->isPointerTy())
- addNode(Inst);
+ if (Call.getType()->isPointerTy())
+ addNode(&Call);
// Check if Inst is a call to a library function that
// allocates/deallocates on the heap. Those kinds of functions do not
// introduce any aliases.
// TODO: address other common library functions such as realloc(),
// strdup(), etc.
- if (isMallocOrCallocLikeFn(Inst, &TLI) || isFreeCall(Inst, &TLI))
+ if (isMallocOrCallocLikeFn(&Call, &TLI) || isFreeCall(&Call, &TLI))
return;
// TODO: Add support for noalias args/all the other fun function
// attributes that we can tack on.
SmallVector<Function *, 4> Targets;
- if (getPossibleTargets(CS, Targets))
- if (tryInterproceduralAnalysis(CS, Targets))
+ if (getPossibleTargets(Call, Targets))
+ if (tryInterproceduralAnalysis(Call, Targets))
return;
// Because the function is opaque, we need to note that anything
// could have happened to the arguments (unless the function is marked
// readonly or readnone), and that the result could alias just about
// anything, too (unless the result is marked noalias).
- if (!CS.onlyReadsMemory())
- for (Value *V : CS.args()) {
+ if (!Call.onlyReadsMemory())
+ for (Value *V : Call.args()) {
if (V->getType()->isPointerTy()) {
// The argument itself escapes.
Graph.addAttr(InstantiatedValue{V, 0}, getAttrEscaped());
@@ -452,12 +449,12 @@ template <typename CFLAA> class CFLGraph
}
}
- if (Inst->getType()->isPointerTy()) {
- auto *Fn = CS.getCalledFunction();
+ if (Call.getType()->isPointerTy()) {
+ auto *Fn = Call.getCalledFunction();
if (Fn == nullptr || !Fn->returnDoesNotAlias())
// No need to call addNode() since we've added Inst at the
// beginning of this function and we know it is not a global.
- Graph.addAttr(InstantiatedValue{Inst, 0}, getAttrUnknown());
+ Graph.addAttr(InstantiatedValue{&Call, 0}, getAttrUnknown());
}
}
More information about the llvm-commits
mailing list