15 #ifndef LLVM_LIB_ANALYSIS_CFLGRAPH_H 16 #define LLVM_LIB_ANALYSIS_CFLGRAPH_H 74 std::vector<NodeInfo> Levels;
78 auto NumLevels = Levels.size();
79 if (NumLevels > Level)
81 Levels.resize(Level + 1);
86 assert(Level < Levels.size());
90 assert(Level < Levels.size());
103 auto Itr = ValueImpls.
find(N.
Val);
104 if (Itr == ValueImpls.
end() || Itr->second.getNumLevels() <= N.
DerefLevel)
106 return &Itr->second.getNodeInfoAtLevel(N.
DerefLevel);
114 auto &ValInfo = ValueImpls[N.
Val];
115 auto Changed = ValInfo.addNodeToLevel(N.
DerefLevel);
116 ValInfo.getNodeInfoAtLevel(N.
DerefLevel).Attr |= Attr;
121 auto *
Info = getNode(N);
127 auto *FromInfo = getNode(From);
128 assert(FromInfo !=
nullptr);
129 auto *ToInfo = getNode(To);
130 assert(ToInfo !=
nullptr);
137 auto Itr = ValueImpls.
find(N.
Val);
138 if (Itr == ValueImpls.
end() || Itr->second.getNumLevels() <= N.
DerefLevel)
140 return &Itr->second.getNodeInfoAtLevel(N.
DerefLevel);
144 auto *
Info = getNode(N);
150 return make_range<const_value_iterator>(ValueImpls.
begin(),
174 class GetEdgesVisitor :
public InstVisitor<GetEdgesVisitor, void> {
185 return CE->
getOpcode() != Instruction::ICmp &&
191 static bool getPossibleTargets(
CallBase &Call,
206 if (
auto GVal = dyn_cast<GlobalValue>(Val)) {
210 }
else if (
auto CExpr = dyn_cast<ConstantExpr>(Val)) {
211 if (hasUsefulEdges(CExpr)) {
213 visitConstantExpr(CExpr);
220 assert(From !=
nullptr && To !=
nullptr);
231 void addDerefEdge(
Value *From,
Value *To,
bool IsRead) {
232 assert(From !=
nullptr && To !=
nullptr);
251 void addLoadEdge(
Value *From,
Value *To) { addDerefEdge(From, To,
true); }
252 void addStoreEdge(
Value *From,
Value *To) { addDerefEdge(From, To,
false); }
256 : AA(Builder.Analysis), DL(DL), TLI(Builder.TLI), Graph(Builder.Graph),
257 ReturnValues(Builder.ReturnedValues) {}
265 if (RetVal->getType()->isPointerTy()) {
282 void visitCastInst(
CastInst &Inst) {
284 addAssignEdge(Src, &Inst);
290 addAssignEdge(Op1, &Inst);
291 addAssignEdge(Op2, &Inst);
296 addAssignEdge(Src, &Inst);
302 addStoreEdge(Val, Ptr);
308 addStoreEdge(Val, Ptr);
311 void visitPHINode(
PHINode &Inst) {
313 addAssignEdge(Val, &Inst);
324 addAssignEdge(
Op, &GEPOp, Offset);
328 auto *GEPOp = cast<GEPOperator>(&Inst);
340 addAssignEdge(TrueVal, &Inst);
341 addAssignEdge(FalseVal, &Inst);
346 void visitLoadInst(
LoadInst &Inst) {
349 addLoadEdge(Ptr, Val);
355 addStoreEdge(Val, Ptr);
371 static bool isFunctionExternal(
Function *Fn) {
375 bool tryInterproceduralAnalysis(
CallBase &Call,
383 for (
auto *Fn : Fns) {
384 if (isFunctionExternal(Fn) || Fn->
isVarArg())
388 if (!AA.getAliasSummary(*Fn))
392 for (
auto *Fn : Fns) {
393 auto Summary = AA.getAliasSummary(*Fn);
394 assert(Summary !=
nullptr);
396 auto &RetParamRelations = Summary->RetParamRelations;
397 for (
auto &Relation : RetParamRelations) {
399 if (IRelation.hasValue()) {
400 Graph.
addNode(IRelation->From);
402 Graph.
addEdge(IRelation->From, IRelation->To);
406 auto &RetParamAttributes = Summary->RetParamAttributes;
407 for (
auto &
Attribute : RetParamAttributes) {
409 if (IAttr.hasValue())
410 Graph.
addNode(IAttr->IValue, IAttr->Attr);
417 void visitCallBase(
CallBase &Call) {
420 if (V->getType()->isPointerTy())
436 if (getPossibleTargets(Call, Targets))
437 if (tryInterproceduralAnalysis(Call, 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::FAdd:
563 case Instruction::Sub:
564 case Instruction::FSub:
565 case Instruction::Mul:
566 case Instruction::FMul:
567 case Instruction::UDiv:
568 case Instruction::SDiv:
569 case Instruction::FDiv:
570 case Instruction::URem:
571 case Instruction::SRem:
572 case Instruction::FRem:
573 case Instruction::And:
574 case Instruction::Or:
575 case Instruction::Xor:
576 case Instruction::Shl:
577 case Instruction::LShr:
578 case Instruction::AShr:
579 case Instruction::ICmp:
580 case Instruction::FCmp:
581 case Instruction::ShuffleVector: {
587 case Instruction::FNeg: {
604 !isa<InvokeInst>(Inst) &&
605 !isa<ReturnInst>(Inst);
606 return !isa<CmpInst>(Inst) && !isa<FenceInst>(Inst) &&
607 !IsNonInvokeRetTerminator;
625 void addInstructionToGraph(GetEdgesVisitor &Visitor,
Instruction &Inst) {
626 if (!hasUsefulEdges(&Inst))
638 for (
auto &Inst : Bb.getInstList())
639 addInstructionToGraph(Visitor, Inst);
641 for (
auto &Arg : Fn.
args())
642 addArgumentToGraph(Arg);
647 : Analysis(Analysis), TLI(TLI) {
653 return ReturnedValues;
660 #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.
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 call.
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...
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 ...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
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()
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.
Optional< InstantiatedAttr > instantiateExternalAttribute(ExternalAttribute EAttr, CallBase &Call)
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.
Optional< InstantiatedRelation > instantiateExternalRelation(ExternalRelation ERelation, CallBase &Call)
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
unsigned arg_size() 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...
std::vector< Edge > EdgeList
Value * getPointerOperand()
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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 ...
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
#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
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.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
bool onlyReadsMemory(unsigned OpNo) const
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...
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
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.