16 #ifndef LLVM_LIB_ANALYSIS_CFLGRAPH_H 17 #define LLVM_LIB_ANALYSIS_CFLGRAPH_H 76 std::vector<NodeInfo> Levels;
80 auto NumLevels = Levels.size();
81 if (NumLevels > Level)
83 Levels.resize(Level + 1);
88 assert(Level < Levels.size());
92 assert(Level < Levels.size());
105 auto Itr = ValueImpls.
find(N.
Val);
106 if (Itr == ValueImpls.
end() || Itr->second.getNumLevels() <= N.
DerefLevel)
108 return &Itr->second.getNodeInfoAtLevel(N.
DerefLevel);
116 auto &ValInfo = ValueImpls[N.
Val];
117 auto Changed = ValInfo.addNodeToLevel(N.
DerefLevel);
118 ValInfo.getNodeInfoAtLevel(N.
DerefLevel).Attr |= Attr;
123 auto *
Info = getNode(N);
129 auto *FromInfo = getNode(From);
130 assert(FromInfo !=
nullptr);
131 auto *ToInfo = getNode(To);
132 assert(ToInfo !=
nullptr);
139 auto Itr = ValueImpls.
find(N.
Val);
140 if (Itr == ValueImpls.
end() || Itr->second.getNumLevels() <= N.
DerefLevel)
142 return &Itr->second.getNodeInfoAtLevel(N.
DerefLevel);
146 auto *
Info = getNode(N);
152 return make_range<const_value_iterator>(ValueImpls.
begin(),
176 class GetEdgesVisitor :
public InstVisitor<GetEdgesVisitor, void> {
188 return CE->
getOpcode() != Instruction::ICmp &&
194 static bool getPossibleTargets(
CallSite CS,
209 if (
auto GVal = dyn_cast<GlobalValue>(Val)) {
213 }
else if (
auto CExpr = dyn_cast<ConstantExpr>(Val)) {
214 if (hasUsefulEdges(CExpr)) {
216 visitConstantExpr(CExpr);
223 assert(From !=
nullptr && To !=
nullptr);
234 void addDerefEdge(
Value *From,
Value *To,
bool IsRead) {
235 assert(From !=
nullptr && To !=
nullptr);
254 void addLoadEdge(
Value *From,
Value *To) { addDerefEdge(From, To,
true); }
255 void addStoreEdge(
Value *From,
Value *To) { addDerefEdge(From, To,
false); }
259 : AA(Builder.Analysis), DL(DL), TLI(Builder.TLI), Graph(Builder.Graph),
260 ReturnValues(Builder.ReturnedValues) {}
268 if (RetVal->getType()->isPointerTy()) {
285 void visitCastInst(
CastInst &Inst) {
287 addAssignEdge(Src, &Inst);
293 addAssignEdge(Op1, &Inst);
294 addAssignEdge(Op2, &Inst);
300 addStoreEdge(Val, Ptr);
306 addStoreEdge(Val, Ptr);
309 void visitPHINode(
PHINode &Inst) {
311 addAssignEdge(Val, &Inst);
322 addAssignEdge(
Op, &GEPOp, Offset);
326 auto *GEPOp = cast<GEPOperator>(&Inst);
338 addAssignEdge(TrueVal, &Inst);
339 addAssignEdge(FalseVal, &Inst);
344 void visitLoadInst(
LoadInst &Inst) {
347 addLoadEdge(Ptr, Val);
353 addStoreEdge(Val, Ptr);
369 static bool isFunctionExternal(
Function *Fn) {
373 bool tryInterproceduralAnalysis(
CallSite CS,
381 for (
auto *Fn : Fns) {
382 if (isFunctionExternal(Fn) || Fn->
isVarArg())
386 if (!AA.getAliasSummary(*Fn))
390 for (
auto *Fn : Fns) {
391 auto Summary = AA.getAliasSummary(*Fn);
392 assert(Summary !=
nullptr);
394 auto &RetParamRelations = Summary->RetParamRelations;
395 for (
auto &Relation : RetParamRelations) {
397 if (IRelation.hasValue()) {
398 Graph.
addNode(IRelation->From);
400 Graph.
addEdge(IRelation->From, IRelation->To);
404 auto &RetParamAttributes = Summary->RetParamAttributes;
405 for (
auto &
Attribute : RetParamAttributes) {
407 if (IAttr.hasValue())
408 Graph.
addNode(IAttr->IValue, IAttr->Attr);
420 if (V->getType()->isPointerTy())
436 if (getPossibleTargets(CS, Targets))
437 if (tryInterproceduralAnalysis(CS, Targets))
446 if (V->getType()->isPointerTy()) {
472 addLoadEdge(Ptr, Val);
478 addAssignEdge(Vec, &Inst);
479 addStoreEdge(Val, &Inst);
493 addAssignEdge(Agg, &Inst);
494 addStoreEdge(Val, &Inst);
499 addLoadEdge(Ptr, &Inst);
505 addAssignEdge(From1, &Inst);
506 addAssignEdge(From2, &Inst);
511 case Instruction::GetElementPtr: {
512 auto GEPOp = cast<GEPOperator>(CE);
517 case Instruction::PtrToInt: {
522 case Instruction::IntToPtr: {
527 case Instruction::BitCast:
528 case Instruction::AddrSpaceCast:
529 case Instruction::Trunc:
530 case Instruction::ZExt:
531 case Instruction::SExt:
532 case Instruction::FPExt:
533 case Instruction::FPTrunc:
534 case Instruction::UIToFP:
535 case Instruction::SIToFP:
536 case Instruction::FPToUI:
537 case Instruction::FPToSI: {
548 case Instruction::InsertElement:
549 case Instruction::InsertValue: {
555 case Instruction::ExtractElement:
556 case Instruction::ExtractValue: {
562 case Instruction::Sub:
563 case Instruction::FSub:
564 case Instruction::Mul:
565 case Instruction::FMul:
566 case Instruction::UDiv:
567 case Instruction::SDiv:
568 case Instruction::FDiv:
569 case Instruction::URem:
570 case Instruction::SRem:
571 case Instruction::FRem:
572 case Instruction::And:
573 case Instruction::Or:
574 case Instruction::Xor:
575 case Instruction::Shl:
576 case Instruction::LShr:
577 case Instruction::AShr:
578 case Instruction::ICmp:
579 case Instruction::FCmp:
580 case Instruction::ShuffleVector: {
598 !isa<InvokeInst>(Inst) &&
599 !isa<ReturnInst>(Inst);
600 return !isa<CmpInst>(Inst) && !isa<FenceInst>(Inst) &&
601 !IsNonInvokeRetTerminator;
619 void addInstructionToGraph(GetEdgesVisitor &Visitor,
Instruction &Inst) {
620 if (!hasUsefulEdges(&Inst))
632 for (
auto &Inst : Bb.getInstList())
633 addInstructionToGraph(Visitor, Inst);
635 for (
auto &Arg : Fn.
args())
636 addArgumentToGraph(Arg);
641 : Analysis(Analysis), TLI(TLI) {
647 return ReturnedValues;
654 #endif // LLVM_LIB_ANALYSIS_CFLGRAPH_H bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Return a value (possibly void), from a function.
Value * getValueOperand()
A parsed version of the target data layout string in and methods for querying it. ...
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
This class represents an incoming formal argument to a Function.
Base class for instruction visitors.
unsigned arg_size() const
This class represents lattice values for constants.
const NodeInfo * getNode(Node N) const
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
void push_back(const T &Elt)
This is the result of instantiating InterfaceValue at a particular callsite.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
The Program Expression Graph (PEG) of CFL analysis CFLGraph is auxiliary data structure used by CFL-b...
iterator_range< IterTy > args() const
const Value * getTrueValue() const
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
bool addNodeToLevel(unsigned Level)
This instruction constructs a fixed permutation of two input vectors.
bool isTerminator() const
Value * getNewValOperand()
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
An instruction for reading from memory.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
DenseMapIterator< Value *, ValueInfo, DenseMapInfo< Value * >, llvm::detail::DenseMapPair< Value *, ValueInfo >, true > const_iterator
This class represents the LLVM 'select' instruction.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
This is the base class for all instructions that perform data casts.
InstrTy * getInstruction() const
This file implements a class to represent arbitrary precision integral constant values and operations...
This class represents a cast from a pointer to an integer.
Value * getPointerOperand()
A constant value that is initialized with an expression using other constant values.
int64_t getSExtValue() const
Get sign extended value.
Type * getType() const
All values are typed, get the type of this value.
void addAttr(Node N, AliasAttrs Attr)
An instruction for storing to memory.
Value * getOperand(unsigned i) const
Analysis containing CSE Info
iterator find(const_arg_type_t< KeyT > Val)
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
CFLGraphBuilder(CFLAA &Analysis, const TargetLibraryInfo &TLI, Function &Fn)
This instruction inserts a single (scalar) element into a VectorType value.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
const NodeInfo & getNodeInfoAtLevel(unsigned Level) const
bool returnDoesNotAlias() const
Determine if the parameter or return value is marked with NoAlias attribute.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
bool addNode(Node N, AliasAttrs Attr=AliasAttrs())
AliasAttrs getAttrEscaped()
AttrEscaped represent whether the said pointer comes from a known source but escapes to the unknown w...
Optional< InstantiatedAttr > instantiateExternalAttribute(ExternalAttribute EAttr, CallSite CS)
std::vector< Edge > EdgeList
Value * getPointerOperand()
Value * getPointerOperand()
unsigned getNumLevels() const
This class represents a cast from an integer to a pointer.
const SmallVector< Value *, 4 > & getReturnValues() const
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
AliasAttrs getAttrUnknown()
AttrUnknown represent whether the said pointer comes from a source not known to alias analyses (such ...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
BlockVerifier::State From
A builder class used to create CFLGraph instance from a given function The CFL-AA that uses this buil...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Provides information about what library functions are available for the current target.
iterator_range< const_value_iterator > value_mappings() const
void addEdge(Node From, Node To, int64_t Offset=0)
This file defines various utility types and functions useful to summary-based alias analysis...
A range adaptor for a pair of iterators.
Class for arbitrary precision integers.
NodeInfo & getNodeInfoAtLevel(unsigned Level)
const Value * getFalseValue() const
amdgpu Simplify well known AMD library false Value Value * Arg
block Block Frequency Analysis
static const int64_t UnknownOffset
AliasAttrs getGlobalOrArgAttrFromValue(const Value &Val)
AttrGlobal represent whether the said pointer is a global value.
bool isMallocOrCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory similar to malloc or...
Value * getPointerOperand()
bool hasExactDefinition() const
Return true if this global has an exact defintion.
AliasAttrs attrFor(Node N) const
std::bitset< NumAliasAttrs > AliasAttrs
These are attributes that an alias analysis can use to mark certain special properties of a given poi...
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
AliasAttrs getAttrCaller()
AttrCaller represent whether the said pointer comes from a source not known to the current function b...
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
const CFLGraph & getCFLGraph() const
Optional< InstantiatedRelation > instantiateExternalRelation(ExternalRelation ERelation, CallSite CS)
static const unsigned MaxSupportedArgsInSummary
The maximum number of arguments we can put into a summary.
op_range incoming_values()
Value * getPointerOperand()
iterator_range< arg_iterator > args()
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.