From: Chandler Carruth Date: Mon, 11 Feb 2019 09:25:41 +0000 (+0000) Subject: Move CFLGraph and the AA summary code over to the new `CallBase` X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65f398e46778167fc7503db1bd24f6dc69860bad;p=llvm Move CFLGraph and the AA summary code over to the new `CallBase` instruction base class rather than the `CallSite` wrapper. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353676 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/AliasAnalysisSummary.cpp b/lib/Analysis/AliasAnalysisSummary.cpp index 2b4879453be..2f3396a4411 100644 --- a/lib/Analysis/AliasAnalysisSummary.cpp +++ b/lib/Analysis/AliasAnalysisSummary.cpp @@ -73,28 +73,28 @@ AliasAttrs getExternallyVisibleAttrs(AliasAttrs Attr) { } Optional 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 -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 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}; diff --git a/lib/Analysis/AliasAnalysisSummary.h b/lib/Analysis/AliasAnalysisSummary.h index 8ac3bf935a7..fe75b03cede 100644 --- a/lib/Analysis/AliasAnalysisSummary.h +++ b/lib/Analysis/AliasAnalysisSummary.h @@ -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 namespace llvm { @@ -195,12 +195,13 @@ struct AliasSummary { SmallVector 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 instantiateInterfaceValue(InterfaceValue, CallSite); +Optional 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 instantiateExternalRelation(ExternalRelation, - CallSite); +Optional +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 instantiateExternalAttribute(ExternalAttribute, - CallSite); +Optional instantiateExternalAttribute(ExternalAttribute EAttr, + CallBase &Call); } template <> struct DenseMapInfo { diff --git a/lib/Analysis/CFLGraph.h b/lib/Analysis/CFLGraph.h index 8fa6e885c8e..5783c5bc9bd 100644 --- a/lib/Analysis/CFLGraph.h +++ b/lib/Analysis/CFLGraph.h @@ -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 class CFLGraphBuilder { // 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 &Output) { - if (auto *Fn = CS.getCalledFunction()) { + if (auto *Fn = Call.getCalledFunction()) { Output.push_back(Fn); return true; } @@ -369,11 +368,11 @@ template class CFLGraphBuilder { return !Fn->hasExactDefinition(); } - bool tryInterproceduralAnalysis(CallSite CS, + bool tryInterproceduralAnalysis(CallBase &Call, const SmallVectorImpl &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 class CFLGraphBuilder { 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 class CFLGraphBuilder { 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 class CFLGraphBuilder { 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 class CFLGraphBuilder { 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 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 class CFLGraphBuilder { } } - 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()); } }