}
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};
#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 {
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;
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
InstantiatedValue IValue;
AliasAttrs Attr;
};
-Optional<InstantiatedAttr> instantiateExternalAttribute(ExternalAttribute,
- CallSite);
+Optional<InstantiatedAttr> instantiateExternalAttribute(ExternalAttribute EAttr,
+ CallBase &Call);
}
template <> struct DenseMapInfo<cflaa::InstantiatedValue> {
#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"
// 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;
}
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
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;
}
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);
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);
}
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());
}
}
- 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());
}
}