Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 65f398e

Browse files
committed
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
1 parent b041a36 commit 65f398e

File tree

3 files changed

+36
-38
lines changed

3 files changed

+36
-38
lines changed

lib/Analysis/AliasAnalysisSummary.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,28 @@ AliasAttrs getExternallyVisibleAttrs(AliasAttrs Attr) {
7373
}
7474

7575
Optional<InstantiatedValue> instantiateInterfaceValue(InterfaceValue IValue,
76-
CallSite CS) {
76+
CallBase &Call) {
7777
auto Index = IValue.Index;
78-
auto Value = (Index == 0) ? CS.getInstruction() : CS.getArgument(Index - 1);
79-
if (Value->getType()->isPointerTy())
80-
return InstantiatedValue{Value, IValue.DerefLevel};
78+
auto *V = (Index == 0) ? &Call : Call.getArgOperand(Index - 1);
79+
if (V->getType()->isPointerTy())
80+
return InstantiatedValue{V, IValue.DerefLevel};
8181
return None;
8282
}
8383

8484
Optional<InstantiatedRelation>
85-
instantiateExternalRelation(ExternalRelation ERelation, CallSite CS) {
86-
auto From = instantiateInterfaceValue(ERelation.From, CS);
85+
instantiateExternalRelation(ExternalRelation ERelation, CallBase &Call) {
86+
auto From = instantiateInterfaceValue(ERelation.From, Call);
8787
if (!From)
8888
return None;
89-
auto To = instantiateInterfaceValue(ERelation.To, CS);
89+
auto To = instantiateInterfaceValue(ERelation.To, Call);
9090
if (!To)
9191
return None;
9292
return InstantiatedRelation{*From, *To, ERelation.Offset};
9393
}
9494

9595
Optional<InstantiatedAttr> instantiateExternalAttribute(ExternalAttribute EAttr,
96-
CallSite CS) {
97-
auto Value = instantiateInterfaceValue(EAttr.IValue, CS);
96+
CallBase &Call) {
97+
auto Value = instantiateInterfaceValue(EAttr.IValue, Call);
9898
if (!Value)
9999
return None;
100100
return InstantiatedAttr{*Value, EAttr.Attr};

lib/Analysis/AliasAnalysisSummary.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include "llvm/ADT/DenseMapInfo.h"
3838
#include "llvm/ADT/Optional.h"
3939
#include "llvm/ADT/SmallVector.h"
40-
#include "llvm/IR/CallSite.h"
40+
#include "llvm/IR/InstrTypes.h"
4141
#include <bitset>
4242

4343
namespace llvm {
@@ -195,12 +195,13 @@ struct AliasSummary {
195195
SmallVector<ExternalAttribute, 8> RetParamAttributes;
196196
};
197197

198-
/// This is the result of instantiating InterfaceValue at a particular callsite
198+
/// This is the result of instantiating InterfaceValue at a particular call
199199
struct InstantiatedValue {
200200
Value *Val;
201201
unsigned DerefLevel;
202202
};
203-
Optional<InstantiatedValue> instantiateInterfaceValue(InterfaceValue, CallSite);
203+
Optional<InstantiatedValue> instantiateInterfaceValue(InterfaceValue IValue,
204+
CallBase &Call);
204205

205206
inline bool operator==(InstantiatedValue LHS, InstantiatedValue RHS) {
206207
return LHS.Val == RHS.Val && LHS.DerefLevel == RHS.DerefLevel;
@@ -228,17 +229,17 @@ struct InstantiatedRelation {
228229
InstantiatedValue From, To;
229230
int64_t Offset;
230231
};
231-
Optional<InstantiatedRelation> instantiateExternalRelation(ExternalRelation,
232-
CallSite);
232+
Optional<InstantiatedRelation>
233+
instantiateExternalRelation(ExternalRelation ERelation, CallBase &Call);
233234

234235
/// This is the result of instantiating ExternalAttribute at a particular
235236
/// callsite
236237
struct InstantiatedAttr {
237238
InstantiatedValue IValue;
238239
AliasAttrs Attr;
239240
};
240-
Optional<InstantiatedAttr> instantiateExternalAttribute(ExternalAttribute,
241-
CallSite);
241+
Optional<InstantiatedAttr> instantiateExternalAttribute(ExternalAttribute EAttr,
242+
CallBase &Call);
242243
}
243244

244245
template <> struct DenseMapInfo<cflaa::InstantiatedValue> {

lib/Analysis/CFLGraph.h

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "llvm/Analysis/TargetLibraryInfo.h"
2525
#include "llvm/IR/Argument.h"
2626
#include "llvm/IR/BasicBlock.h"
27-
#include "llvm/IR/CallSite.h"
2827
#include "llvm/IR/Constants.h"
2928
#include "llvm/IR/DataLayout.h"
3029
#include "llvm/IR/Function.h"
@@ -190,9 +189,9 @@ template <typename CFLAA> class CFLGraphBuilder {
190189

191190
// Returns possible functions called by CS into the given SmallVectorImpl.
192191
// Returns true if targets found, false otherwise.
193-
static bool getPossibleTargets(CallSite CS,
192+
static bool getPossibleTargets(CallBase &Call,
194193
SmallVectorImpl<Function *> &Output) {
195-
if (auto *Fn = CS.getCalledFunction()) {
194+
if (auto *Fn = Call.getCalledFunction()) {
196195
Output.push_back(Fn);
197196
return true;
198197
}
@@ -369,19 +368,19 @@ template <typename CFLAA> class CFLGraphBuilder {
369368
return !Fn->hasExactDefinition();
370369
}
371370

372-
bool tryInterproceduralAnalysis(CallSite CS,
371+
bool tryInterproceduralAnalysis(CallBase &Call,
373372
const SmallVectorImpl<Function *> &Fns) {
374373
assert(Fns.size() > 0);
375374

376-
if (CS.arg_size() > MaxSupportedArgsInSummary)
375+
if (Call.arg_size() > MaxSupportedArgsInSummary)
377376
return false;
378377

379378
// Exit early if we'll fail anyway
380379
for (auto *Fn : Fns) {
381380
if (isFunctionExternal(Fn) || Fn->isVarArg())
382381
return false;
383382
// Fail if the caller does not provide enough arguments
384-
assert(Fn->arg_size() <= CS.arg_size());
383+
assert(Fn->arg_size() <= Call.arg_size());
385384
if (!AA.getAliasSummary(*Fn))
386385
return false;
387386
}
@@ -392,7 +391,7 @@ template <typename CFLAA> class CFLGraphBuilder {
392391

393392
auto &RetParamRelations = Summary->RetParamRelations;
394393
for (auto &Relation : RetParamRelations) {
395-
auto IRelation = instantiateExternalRelation(Relation, CS);
394+
auto IRelation = instantiateExternalRelation(Relation, Call);
396395
if (IRelation.hasValue()) {
397396
Graph.addNode(IRelation->From);
398397
Graph.addNode(IRelation->To);
@@ -402,7 +401,7 @@ template <typename CFLAA> class CFLGraphBuilder {
402401

403402
auto &RetParamAttributes = Summary->RetParamAttributes;
404403
for (auto &Attribute : RetParamAttributes) {
405-
auto IAttr = instantiateExternalAttribute(Attribute, CS);
404+
auto IAttr = instantiateExternalAttribute(Attribute, Call);
406405
if (IAttr.hasValue())
407406
Graph.addNode(IAttr->IValue, IAttr->Attr);
408407
}
@@ -411,37 +410,35 @@ template <typename CFLAA> class CFLGraphBuilder {
411410
return true;
412411
}
413412

414-
void visitCallSite(CallSite CS) {
415-
auto Inst = CS.getInstruction();
416-
413+
void visitCallBase(CallBase &Call) {
417414
// Make sure all arguments and return value are added to the graph first
418-
for (Value *V : CS.args())
415+
for (Value *V : Call.args())
419416
if (V->getType()->isPointerTy())
420417
addNode(V);
421-
if (Inst->getType()->isPointerTy())
422-
addNode(Inst);
418+
if (Call.getType()->isPointerTy())
419+
addNode(&Call);
423420

424421
// Check if Inst is a call to a library function that
425422
// allocates/deallocates on the heap. Those kinds of functions do not
426423
// introduce any aliases.
427424
// TODO: address other common library functions such as realloc(),
428425
// strdup(), etc.
429-
if (isMallocOrCallocLikeFn(Inst, &TLI) || isFreeCall(Inst, &TLI))
426+
if (isMallocOrCallocLikeFn(&Call, &TLI) || isFreeCall(&Call, &TLI))
430427
return;
431428

432429
// TODO: Add support for noalias args/all the other fun function
433430
// attributes that we can tack on.
434431
SmallVector<Function *, 4> Targets;
435-
if (getPossibleTargets(CS, Targets))
436-
if (tryInterproceduralAnalysis(CS, Targets))
432+
if (getPossibleTargets(Call, Targets))
433+
if (tryInterproceduralAnalysis(Call, Targets))
437434
return;
438435

439436
// Because the function is opaque, we need to note that anything
440437
// could have happened to the arguments (unless the function is marked
441438
// readonly or readnone), and that the result could alias just about
442439
// anything, too (unless the result is marked noalias).
443-
if (!CS.onlyReadsMemory())
444-
for (Value *V : CS.args()) {
440+
if (!Call.onlyReadsMemory())
441+
for (Value *V : Call.args()) {
445442
if (V->getType()->isPointerTy()) {
446443
// The argument itself escapes.
447444
Graph.addAttr(InstantiatedValue{V, 0}, getAttrEscaped());
@@ -452,12 +449,12 @@ template <typename CFLAA> class CFLGraphBuilder {
452449
}
453450
}
454451

455-
if (Inst->getType()->isPointerTy()) {
456-
auto *Fn = CS.getCalledFunction();
452+
if (Call.getType()->isPointerTy()) {
453+
auto *Fn = Call.getCalledFunction();
457454
if (Fn == nullptr || !Fn->returnDoesNotAlias())
458455
// No need to call addNode() since we've added Inst at the
459456
// beginning of this function and we know it is not a global.
460-
Graph.addAttr(InstantiatedValue{Inst, 0}, getAttrUnknown());
457+
Graph.addAttr(InstantiatedValue{&Call, 0}, getAttrUnknown());
461458
}
462459
}
463460

0 commit comments

Comments
 (0)