24
24
#include " llvm/Analysis/TargetLibraryInfo.h"
25
25
#include " llvm/IR/Argument.h"
26
26
#include " llvm/IR/BasicBlock.h"
27
- #include " llvm/IR/CallSite.h"
28
27
#include " llvm/IR/Constants.h"
29
28
#include " llvm/IR/DataLayout.h"
30
29
#include " llvm/IR/Function.h"
@@ -190,9 +189,9 @@ template <typename CFLAA> class CFLGraphBuilder {
190
189
191
190
// Returns possible functions called by CS into the given SmallVectorImpl.
192
191
// Returns true if targets found, false otherwise.
193
- static bool getPossibleTargets (CallSite CS ,
192
+ static bool getPossibleTargets (CallBase &Call ,
194
193
SmallVectorImpl<Function *> &Output) {
195
- if (auto *Fn = CS .getCalledFunction ()) {
194
+ if (auto *Fn = Call .getCalledFunction ()) {
196
195
Output.push_back (Fn);
197
196
return true ;
198
197
}
@@ -369,19 +368,19 @@ template <typename CFLAA> class CFLGraphBuilder {
369
368
return !Fn->hasExactDefinition ();
370
369
}
371
370
372
- bool tryInterproceduralAnalysis (CallSite CS ,
371
+ bool tryInterproceduralAnalysis (CallBase &Call ,
373
372
const SmallVectorImpl<Function *> &Fns) {
374
373
assert (Fns.size () > 0 );
375
374
376
- if (CS .arg_size () > MaxSupportedArgsInSummary)
375
+ if (Call .arg_size () > MaxSupportedArgsInSummary)
377
376
return false ;
378
377
379
378
// Exit early if we'll fail anyway
380
379
for (auto *Fn : Fns) {
381
380
if (isFunctionExternal (Fn) || Fn->isVarArg ())
382
381
return false ;
383
382
// 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 ());
385
384
if (!AA.getAliasSummary (*Fn))
386
385
return false ;
387
386
}
@@ -392,7 +391,7 @@ template <typename CFLAA> class CFLGraphBuilder {
392
391
393
392
auto &RetParamRelations = Summary->RetParamRelations ;
394
393
for (auto &Relation : RetParamRelations) {
395
- auto IRelation = instantiateExternalRelation (Relation, CS );
394
+ auto IRelation = instantiateExternalRelation (Relation, Call );
396
395
if (IRelation.hasValue ()) {
397
396
Graph.addNode (IRelation->From );
398
397
Graph.addNode (IRelation->To );
@@ -402,7 +401,7 @@ template <typename CFLAA> class CFLGraphBuilder {
402
401
403
402
auto &RetParamAttributes = Summary->RetParamAttributes ;
404
403
for (auto &Attribute : RetParamAttributes) {
405
- auto IAttr = instantiateExternalAttribute (Attribute, CS );
404
+ auto IAttr = instantiateExternalAttribute (Attribute, Call );
406
405
if (IAttr.hasValue ())
407
406
Graph.addNode (IAttr->IValue , IAttr->Attr );
408
407
}
@@ -411,37 +410,35 @@ template <typename CFLAA> class CFLGraphBuilder {
411
410
return true ;
412
411
}
413
412
414
- void visitCallSite (CallSite CS) {
415
- auto Inst = CS.getInstruction ();
416
-
413
+ void visitCallBase (CallBase &Call) {
417
414
// 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 ())
419
416
if (V->getType ()->isPointerTy ())
420
417
addNode (V);
421
- if (Inst-> getType ()->isPointerTy ())
422
- addNode (Inst );
418
+ if (Call. getType ()->isPointerTy ())
419
+ addNode (&Call );
423
420
424
421
// Check if Inst is a call to a library function that
425
422
// allocates/deallocates on the heap. Those kinds of functions do not
426
423
// introduce any aliases.
427
424
// TODO: address other common library functions such as realloc(),
428
425
// strdup(), etc.
429
- if (isMallocOrCallocLikeFn (Inst , &TLI) || isFreeCall (Inst , &TLI))
426
+ if (isMallocOrCallocLikeFn (&Call , &TLI) || isFreeCall (&Call , &TLI))
430
427
return ;
431
428
432
429
// TODO: Add support for noalias args/all the other fun function
433
430
// attributes that we can tack on.
434
431
SmallVector<Function *, 4 > Targets;
435
- if (getPossibleTargets (CS , Targets))
436
- if (tryInterproceduralAnalysis (CS , Targets))
432
+ if (getPossibleTargets (Call , Targets))
433
+ if (tryInterproceduralAnalysis (Call , Targets))
437
434
return ;
438
435
439
436
// Because the function is opaque, we need to note that anything
440
437
// could have happened to the arguments (unless the function is marked
441
438
// readonly or readnone), and that the result could alias just about
442
439
// 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 ()) {
445
442
if (V->getType ()->isPointerTy ()) {
446
443
// The argument itself escapes.
447
444
Graph.addAttr (InstantiatedValue{V, 0 }, getAttrEscaped ());
@@ -452,12 +449,12 @@ template <typename CFLAA> class CFLGraphBuilder {
452
449
}
453
450
}
454
451
455
- if (Inst-> getType ()->isPointerTy ()) {
456
- auto *Fn = CS .getCalledFunction ();
452
+ if (Call. getType ()->isPointerTy ()) {
453
+ auto *Fn = Call .getCalledFunction ();
457
454
if (Fn == nullptr || !Fn->returnDoesNotAlias ())
458
455
// No need to call addNode() since we've added Inst at the
459
456
// 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 ());
461
458
}
462
459
}
463
460
0 commit comments