65 #define DEBUG_TYPE "functionattrs" 67 STATISTIC(NumReadNone,
"Number of functions marked readnone");
68 STATISTIC(NumReadOnly,
"Number of functions marked readonly");
69 STATISTIC(NumNoCapture,
"Number of arguments marked nocapture");
70 STATISTIC(NumReturned,
"Number of arguments marked returned");
71 STATISTIC(NumReadNoneArg,
"Number of arguments marked readnone");
72 STATISTIC(NumReadOnlyArg,
"Number of arguments marked readonly");
73 STATISTIC(NumNoAlias,
"Number of function returns marked noalias");
74 STATISTIC(NumNonNullReturn,
"Number of function returns marked nonnull");
75 STATISTIC(NumNoRecurse,
"Number of functions marked as norecurse");
76 STATISTIC(NumNoUnwind,
"Number of functions marked as nounwind");
83 cl::desc(
"Try to propagate nonnull argument attributes from callsites to " 84 "caller functions."));
88 cl::desc(
"Stop inferring nounwind attribute during function-attrs pass"));
106 const SCCNodeSet &SCCNodes) {
121 bool ReadsMemory =
false;
178 }
else if (
LoadInst *LI = dyn_cast<LoadInst>(I)) {
180 if (!LI->isVolatile()) {
185 }
else if (
StoreInst *
SI = dyn_cast<StoreInst>(I)) {
187 if (!
SI->isVolatile()) {
192 }
else if (
VAArgInst *
VI = dyn_cast<VAArgInst>(I)) {
218 template <
typename AARGetterT>
219 static bool addReadAttrs(
const SCCNodeSet &SCCNodes, AARGetterT &&AARGetter) {
222 bool ReadsMemory =
false;
245 bool MadeChange =
false;
247 if (
F->doesNotAccessMemory())
251 if (
F->onlyReadsMemory() && ReadsMemory)
258 F->removeFnAttr(Attribute::ReadOnly);
259 F->removeFnAttr(Attribute::ReadNone);
262 F->addFnAttr(ReadsMemory ? Attribute::ReadOnly : Attribute::ReadNone);
278 struct ArgumentGraphNode {
283 class ArgumentGraph {
286 using ArgumentMapTy = std::map<Argument *, ArgumentGraphNode>;
288 ArgumentMapTy ArgumentMap;
296 ArgumentGraphNode SyntheticRoot;
299 ArgumentGraph() { SyntheticRoot.Definition =
nullptr; }
303 iterator
begin() {
return SyntheticRoot.Uses.begin(); }
304 iterator
end() {
return SyntheticRoot.Uses.end(); }
305 ArgumentGraphNode *getEntryNode() {
return &SyntheticRoot; }
307 ArgumentGraphNode *operator[](
Argument *A) {
308 ArgumentGraphNode &Node = ArgumentMap[A];
310 SyntheticRoot.Uses.push_back(&Node);
319 ArgumentUsesTracker(
const SCCNodeSet &SCCNodes) : SCCNodes(SCCNodes) {}
321 void tooManyUses()
override { Captured =
true; }
323 bool captured(
const Use *U)
override {
325 if (!CS.getInstruction()) {
341 std::distance(const_cast<const Use *>(CS.arg_begin()), U);
343 assert(UseIndex < CS.data_operands_size() &&
344 "Indirect function calls should have been filtered above!");
346 if (UseIndex >= CS.getNumArgOperands()) {
348 assert(CS.hasOperandBundles() &&
"Must be!");
359 assert(F->
isVarArg() &&
"More params than args in non-varargs call");
364 Uses.push_back(&*std::next(F->
arg_begin(), UseIndex));
369 bool Captured =
false;
374 const SCCNodeSet &SCCNodes;
398 static ChildIteratorType
nodes_end(ArgumentGraph *AG) {
return AG->end(); }
422 while (!Worklist.
empty()) {
427 case Instruction::BitCast:
428 case Instruction::GetElementPtr:
429 case Instruction::PHI:
431 case Instruction::AddrSpaceCast:
434 if (Visited.
insert(&UU).second)
439 case Instruction::Invoke: {
440 bool Captures =
true;
445 auto AddUsersToWorklistIfCapturing = [&] {
448 if (Visited.
insert(&UU).second)
454 AddUsersToWorklistIfCapturing();
462 AddUsersToWorklistIfCapturing();
472 unsigned UseIndex = std::distance(CS.
arg_begin(), U);
479 "Data operand use expected!");
483 if (UseIndex >= F->
arg_size() && !IsOperandBundleUse) {
484 assert(F->
isVarArg() &&
"More params than args in non-varargs call");
494 if (IsOperandBundleUse ||
506 AddUsersToWorklistIfCapturing();
519 case Instruction::ICmp:
528 return IsRead ? Attribute::ReadOnly : Attribute::ReadNone;
533 bool Changed =
false;
540 if (!
F->hasExactDefinition())
543 if (
F->getReturnType()->isVoidTy())
551 auto FindRetArg = [&]() ->
Value * {
552 Value *RetArg =
nullptr;
554 if (
auto *
Ret = dyn_cast<ReturnInst>(BB.getTerminator())) {
557 Value *RetVal =
Ret->getReturnValue()->stripPointerCasts();
558 if (!isa<Argument>(RetVal) || RetVal->
getType() != F->getReturnType())
563 else if (RetArg != RetVal)
570 if (
Value *RetArg = FindRetArg()) {
571 auto *
A = cast<Argument>(RetArg);
572 A->addAttr(Attribute::Returned);
589 bool Changed =
false;
601 if (
auto *CalledFunc = CS.getCalledFunction()) {
602 for (
auto &CSArg : CalledFunc->args()) {
603 if (!CSArg.hasNonNullAttr())
610 if (FArg && !FArg->hasNonNullAttr()) {
611 FArg->addAttr(Attribute::NonNull);
626 bool Changed =
false;
636 if (!
F->hasExactDefinition())
643 if (
F->onlyReadsMemory() &&
F->doesNotThrow() &&
644 F->getReturnType()->isVoidTy()) {
647 if (
A->getType()->isPointerTy() && !
A->hasNoCaptureAttr()) {
648 A->addAttr(Attribute::NoCapture);
658 if (!
A->getType()->isPointerTy())
660 bool HasNonLocalUses =
false;
661 if (!
A->hasNoCaptureAttr()) {
662 ArgumentUsesTracker Tracker(SCCNodes);
664 if (!Tracker.Captured) {
665 if (Tracker.Uses.empty()) {
667 A->addAttr(Attribute::NoCapture);
674 ArgumentGraphNode *Node = AG[&*
A];
676 Node->Uses.push_back(AG[Use]);
678 HasNonLocalUses =
true;
684 if (!HasNonLocalUses && !
A->onlyReadsMemory()) {
695 R == Attribute::ReadOnly ? ++NumReadOnlyArg : ++NumReadNoneArg;
709 const std::vector<ArgumentGraphNode *> &ArgumentSCC = *
I;
710 if (ArgumentSCC.size() == 1) {
711 if (!ArgumentSCC[0]->Definition)
715 if (ArgumentSCC[0]->Uses.size() == 1 &&
716 ArgumentSCC[0]->Uses[0] == ArgumentSCC[0]) {
717 Argument *
A = ArgumentSCC[0]->Definition;
718 A->
addAttr(Attribute::NoCapture);
725 bool SCCCaptured =
false;
726 for (
auto I = ArgumentSCC.begin(),
E = ArgumentSCC.end();
727 I !=
E && !SCCCaptured; ++
I) {
728 ArgumentGraphNode *Node = *
I;
729 if (Node->Uses.empty()) {
730 if (!Node->Definition->hasNoCaptureAttr())
740 for (ArgumentGraphNode *
I : ArgumentSCC) {
741 ArgumentSCCNodes.
insert(
I->Definition);
744 for (
auto I = ArgumentSCC.begin(),
E = ArgumentSCC.end();
745 I !=
E && !SCCCaptured; ++
I) {
746 ArgumentGraphNode *
N = *
I;
747 for (ArgumentGraphNode *
Use : N->Uses) {
758 for (
unsigned i = 0, e = ArgumentSCC.size(); i != e; ++i) {
759 Argument *
A = ArgumentSCC[i]->Definition;
760 A->
addAttr(Attribute::NoCapture);
777 for (
unsigned i = 0, e = ArgumentSCC.size(); i != e; ++i) {
778 Argument *
A = ArgumentSCC[i]->Definition;
780 if (K == Attribute::ReadNone)
782 if (K == Attribute::ReadOnly) {
783 ReadAttr = Attribute::ReadOnly;
791 for (
unsigned i = 0, e = ArgumentSCC.size(); i != e; ++i) {
792 Argument *
A = ArgumentSCC[i]->Definition;
797 ReadAttr == Attribute::ReadOnly ? ++NumReadOnlyArg : ++NumReadNoneArg;
813 if (
ReturnInst *
Ret = dyn_cast<ReturnInst>(BB.getTerminator()))
814 FlowsToReturn.
insert(
Ret->getReturnValue());
816 for (
unsigned i = 0; i != FlowsToReturn.
size(); ++i) {
817 Value *RetVal = FlowsToReturn[i];
819 if (
Constant *
C = dyn_cast<Constant>(RetVal)) {
820 if (!
C->isNullValue() && !isa<UndefValue>(
C))
826 if (isa<Argument>(RetVal))
829 if (
Instruction *RVI = dyn_cast<Instruction>(RetVal))
830 switch (RVI->getOpcode()) {
832 case Instruction::BitCast:
833 case Instruction::GetElementPtr:
834 case Instruction::AddrSpaceCast:
835 FlowsToReturn.
insert(RVI->getOperand(0));
843 case Instruction::PHI: {
844 PHINode *PN = cast<PHINode>(RVI);
846 FlowsToReturn.
insert(IncValue);
851 case Instruction::Alloca:
854 case Instruction::Invoke: {
879 if (
F->returnDoesNotAlias())
885 if (!
F->hasExactDefinition())
890 if (!
F->getReturnType()->isPointerTy())
897 bool MadeChange =
false;
899 if (
F->returnDoesNotAlias() ||
900 !
F->getReturnType()->isPointerTy())
903 F->setReturnDoesNotAlias();
921 "nonnull only meaningful on pointer types");
926 if (
auto *
Ret = dyn_cast<ReturnInst>(BB.getTerminator()))
927 FlowsToReturn.
insert(
Ret->getReturnValue());
929 auto &DL = F->getParent()->getDataLayout();
931 for (
unsigned i = 0; i != FlowsToReturn.
size(); ++i) {
932 Value *RetVal = FlowsToReturn[i];
945 case Instruction::BitCast:
946 case Instruction::GetElementPtr:
947 case Instruction::AddrSpaceCast:
956 case Instruction::PHI: {
957 PHINode *PN = cast<PHINode>(RVI);
963 case Instruction::Invoke: {
968 if (Callee && SCCNodes.count(Callee)) {
987 bool SCCReturnsNonNull =
true;
989 bool MadeChange =
false;
1002 if (!
F->hasExactDefinition())
1007 if (!
F->getReturnType()->isPointerTy())
1010 bool Speculative =
false;
1016 <<
" as nonnull\n");
1025 SCCReturnsNonNull =
false;
1028 if (SCCReturnsNonNull) {
1031 Attribute::NonNull) ||
1032 !
F->getReturnType()->isPointerTy())
1035 LLVM_DEBUG(
dbgs() <<
"SCC marking " <<
F->getName() <<
" as nonnull\n");
1053 class AttributeInferer {
1056 struct InferenceDescriptor {
1062 std::function<bool(const Function &)> SkipFunction;
1065 std::function<bool(Instruction &)> InstrBreaksAttribute;
1068 std::function<void(Function &)> SetAttribute;
1075 bool RequiresExactDefinition;
1082 : SkipFunction(SkipFunc), InstrBreaksAttribute(InstrScan),
1083 SetAttribute(SetAttr), AKind(AK),
1084 RequiresExactDefinition(ReqExactDef) {}
1091 void registerAttrInference(InferenceDescriptor AttrInference) {
1092 InferenceDescriptors.
push_back(AttrInference);
1095 bool run(
const SCCNodeSet &SCCNodes);
1100 bool AttributeInferer::run(
const SCCNodeSet &SCCNodes) {
1108 if (InferInSCC.
empty())
1113 if (ID.SkipFunction(*
F))
1118 return F->isDeclaration() ||
1119 (ID.RequiresExactDefinition && !
F->hasExactDefinition());
1126 InferInSCC, std::back_inserter(InferInThisFunc),
1127 [
F](
const InferenceDescriptor &ID) {
return !ID.SkipFunction(*
F); });
1129 if (InferInThisFunc.empty())
1134 llvm::erase_if(InferInThisFunc, [&](
const InferenceDescriptor &ID) {
1135 if (!ID.InstrBreaksAttribute(
I))
1140 return D.AKind == ID.AKind;
1146 if (InferInThisFunc.empty())
1151 if (InferInSCC.
empty())
1154 bool Changed =
false;
1160 for (
auto &
ID : InferInSCC) {
1161 if (
ID.SkipFunction(*
F))
1164 ID.SetAttribute(*
F);
1173 const SCCNodeSet &SCCNodes) {
1184 if (
const auto *CI = dyn_cast<CallInst>(&I)) {
1189 if (SCCNodes.count(
Callee) > 0)
1205 AttributeInferer AI;
1212 AI.registerAttrInference(AttributeInferer::InferenceDescriptor{
1215 [](
const Function &
F) {
return !
F.isConvergent(); },
1221 LLVM_DEBUG(
dbgs() <<
"Removing convergent attr from fn " <<
F.getName()
1223 F.setNotConvergent();
1233 AI.registerAttrInference(AttributeInferer::InferenceDescriptor{
1234 Attribute::NoUnwind,
1236 [](
const Function &
F) {
return F.doesNotThrow(); },
1243 <<
"Adding nounwind attr to fn " <<
F.getName() <<
"\n");
1244 F.setDoesNotThrow();
1250 return AI.run(SCCNodes);
1265 if (SCCNodes.size() != 1)
1305 SCCNodeSet SCCNodes;
1306 bool HasUnknownCall =
false;
1313 HasUnknownCall =
true;
1320 if (!HasUnknownCall)
1323 if (!CS.getCalledFunction()) {
1324 HasUnknownCall =
true;
1328 SCCNodes.insert(&F);
1331 bool Changed =
false;
1338 if (!HasUnknownCall) {
1373 "Deduce function attributes",
false,
false)
1380 return new PostOrderFunctionAttrsLegacyPass();
1383 template <
typename AARGetterT>
1385 bool Changed =
false;
1391 SCCNodeSet SCCNodes;
1392 bool ExternalNode =
false;
1399 ExternalNode =
true;
1407 if (SCCNodes.empty())
1416 if (!ExternalNode) {
1426 bool PostOrderFunctionAttrsLegacyPass::runOnSCC(
CallGraphSCC &SCC) {
1434 struct ReversePostOrderFunctionAttrsLegacyPass :
public ModulePass {
1438 ReversePostOrderFunctionAttrsLegacyPass() :
ModulePass(ID) {
1443 bool runOnModule(
Module &M)
override;
1457 "Deduce function attributes in RPO",
false,
false)
1463 return new ReversePostOrderFunctionAttrsLegacyPass();
1472 "This function has already been deduced as norecurs!");
1474 "Can only do top-down deduction for internal linkage functions!");
1484 for (
auto *U : F.
users()) {
1514 bool Changed =
false;
1521 bool ReversePostOrderFunctionAttrsLegacyPass::runOnModule(
Module &M) {
1525 auto &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
Pass interface - Implemented by all 'passes'.
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
static cl::opt< bool > EnableNonnullArgPropagation("enable-nonnull-arg-prop", cl::Hidden, cl::desc("Try to propagate nonnull argument attributes from callsites to " "caller functions."))
static ChildIteratorType nodes_end(ArgumentGraph *AG)
Return a value (possibly void), from a function.
User::op_iterator arg_iterator
The type of iterator to use when looping over actual arguments at this call site. ...
MemoryAccessKind
The three kinds of memory access relevant to 'readonly' and 'readnone' attributes.
void push_back(const T &Elt)
This builds on the llvm/ADT/GraphTraits.h file to find the strongly connected components (SCCs) of a ...
const_iterator end(StringRef path)
Get end iterator over path.
iterator_range< use_iterator > uses()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents an incoming formal argument to a Function.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
This callback is used in conjunction with PointerMayBeCaptured.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Compute iterated dominance frontiers using a linear time algorithm.
size_type size() const
Determine the number of elements in the SetVector.
void removeAttr(Attribute::AttrKind Kind)
Remove attributes from an argument.
static bool isFunctionMallocLike(Function *F, const SCCNodeSet &SCCNodes)
Tests whether a function is "malloc-like".
A Module instance is used to store all the information related to an LLVM module. ...
OutputIt copy_if(R &&Range, OutputIt Out, UnaryPredicate P)
Provide wrappers to std::copy_if which take ranges instead of having to pass begin/end explicitly...
static bool addArgumentReturnedAttrs(const SCCNodeSet &SCCNodes)
Deduce returned attributes for the SCC.
static bool setDoesNotRecurse(Function &F)
Implements a lazy call graph analysis and related passes for the new pass manager.
An immutable pass that tracks lazily created AssumptionCache objects.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
const Value * getTrueValue() const
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
The two locations do not alias at all.
bool onlyReadsMemory(ImmutableCallSite CS)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
STATISTIC(NumFunctions, "Total number of functions")
An instruction for reading from memory.
This defines the Use class.
MemoryAccessKind computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR)
Returns the memory access properties of this copy of the function.
A proxy from a FunctionAnalysisManager to an SCC.
A node in the call graph for a module.
void getAnalysisUsage(AnalysisUsage &Info) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph...
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
void initializeReversePostOrderFunctionAttrsLegacyPassPass(PassRegistry &)
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
static bool addNonNullAttrs(const SCCNodeSet &SCCNodes)
Deduce nonnull attributes for the SCC.
static MemoryAccessKind checkFunctionMemoryAccess(Function &F, bool ThisBody, AAResults &AAR, const SCCNodeSet &SCCNodes)
Returns the memory access attribute for function F using AAR for AA results, where SCCNodes is the cu...
unsigned data_operands_size() const
inst_iterator inst_begin(Function *F)
This class represents the LLVM 'select' instruction.
ArgumentGraphNode * NodeRef
A Use represents the edge between a Value definition and its users.
static ChildIteratorType child_end(NodeRef N)
static bool runImpl(CallGraphSCC &SCC, AARGetterT AARGetter)
This class is a functor to be used in legacy module or SCC passes for computing AA results for a func...
This file contains the simple types necessary to represent the attributes associated with functions a...
No attributes have been set.
scc_iterator< T > scc_begin(const T &G)
Construct the begin iterator for a deduced graph type T.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
Type * getType() const
All values are typed, get the type of this value.
bool insert(const value_type &X)
Insert a new element into the SetVector.
FunctionModRefBehavior
Summary of how a function affects memory in the program.
A lazily constructed view of the call graph of a module.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
An instruction for storing to memory.
amdgpu Simplify well known AMD library false Value * Callee
Value * getOperand(unsigned i) const
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static bool addReadAttrs(const SCCNodeSet &SCCNodes, AARGetterT &&AARGetter)
Deduce readonly/readnone attributes for the SCC.
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal=false)
Checks whether the given location points to constant memory, or if OrLocal is true whether it points ...
bool isVoidTy() const
Return true if this is 'void'.
const BasicBlock & getEntryBlock() const
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
Fills the AAMDNodes structure with AA metadata from this instruction.
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
Type * getReturnType() const
Returns the type of the ret val.
typename ArgumentGraphNode *::UnknownGraphTypeError NodeRef
void addAttr(Attribute::AttrKind Kind)
A set of analyses that are preserved following a run of a transformation pass.
unsigned const MachineRegisterInfo * MRI
The ModulePass which wraps up a CallGraph and the logic to build it.
LLVM Basic Block Representation.
INITIALIZE_PASS_BEGIN(PostOrderFunctionAttrsLegacyPass, "functionattrs", "Deduce function attributes", false, false) INITIALIZE_PASS_END(PostOrderFunctionAttrsLegacyPass
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
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.
static bool InstrBreaksNonThrowing(Instruction &I, const SCCNodeSet &SCCNodes)
Helper for NoUnwind inference predicate InstrBreaksAttribute.
A manager for alias analyses.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool mayThrow() const
Return true if this instruction may throw an exception.
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS)
Return the behavior of the given call site.
Represent the analysis usage information of a pass.
bool hasOperandBundles() const
static bool addNoRecurseAttrs(const SCCNodeSet &SCCNodes)
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
bool hasInternalLinkage() const
static bool addNoRecurseAttrsTopDown(Function &F)
A node in the call graph.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Pass * createReversePostOrderFunctionAttrsPass()
createReversePostOrderFunctionAttrsPass - This pass walks SCCs of the call graph in RPO to deduce and...
bool doesNotCapture(unsigned OpNo) const
Determine whether this data operand is not captured.
bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
Pass * createPostOrderFunctionAttrsLegacyPass()
Create a legacy pass manager instance of a pass to compute function attrs in post-order.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
unsigned getNumArgOperands() const
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
void getAAResultsAnalysisUsage(AnalysisUsage &AU)
A helper for the legacy pass manager to populate AU to add uses to make sure the analyses required by...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This function does not perform any non-local loads or stores to memory.
static cl::opt< bool > DisableNoUnwindInference("disable-nounwind-inference", cl::Hidden, cl::desc("Stop inferring nounwind attribute during function-attrs pass"))
bool doesNotRecurse() const
Determine if the function is known not to recurse, directly or indirectly.
Representation for a specific memory location.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
A SetVector that performs no allocations if smaller than a certain size.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
SmallVectorImpl< ArgumentGraphNode * >::iterator ChildIteratorType
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static NodeRef getEntryNode(ArgumentGraph *AG)
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
LLVM_NODISCARD T pop_back_val()
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
void setPreservesCFG()
This function should be called by the pass, iff they do not:
unsigned getNumIncomingValues() const
Return the number of incoming edges.
BBTy * getParent() const
Get the basic block containing the call site.
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static ChildIteratorType child_begin(NodeRef N)
typename SuperClass::iterator iterator
iterator_range< user_iterator > users()
LLVM_NODISCARD bool isNoModRef(const ModRefInfo MRI)
static bool addNoAliasAttrs(const SCCNodeSet &SCCNodes)
Deduce noalias attributes for the SCC.
const Value * getFalseValue() const
static bool addArgumentAttrs(const SCCNodeSet &SCCNodes)
Deduce nocapture attributes for the SCC.
static bool inferAttrsFromFunctionBodies(const SCCNodeSet &SCCNodes)
Infer attributes from all functions in the SCC by scanning every instruction for compliance to the at...
bool doesNotAccessMemory() const
Determine if the call does not access memory.
amdgpu Simplify well known AMD library false Value Value * Arg
An analysis pass to compute the CallGraph for a Module.
LLVM_NODISCARD bool isModSet(const ModRefInfo MRI)
static bool onlyAccessesArgPointees(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from objects poin...
The basic data container for the call graph of a Module of IR.
static bool addArgumentAttrsFromCallsites(Function &F)
If a callsite has arguments that are also arguments to the parent function, try to propagate attribut...
LLVM_NODISCARD bool empty() const
This file provides utility analysis objects describing memory locations.
void initializePostOrderFunctionAttrsLegacyPassPass(PassRegistry &)
bool hasExactDefinition() const
Return true if this global has an exact defintion.
const Function * getParent() const
Return the enclosing method, or null if none.
static NodeRef getEntryNode(NodeRef A)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
bool mayReadFromMemory() const
Return true if this instruction may read memory.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Deduce function attributes
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void preserve()
Mark an analysis as preserved.
Provides passes for computing function attributes based on interprocedural analyses.
static bool isReturnNonNull(Function *F, const SCCNodeSet &SCCNodes, bool &Speculative)
Tests whether this function is known to not return null.
This header provides classes for managing passes over SCCs of the call graph.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
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())
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if this return value has the given attribute.
LLVM Value Representation.
An SCC of the call graph.
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
rpo Deduce function attributes in RPO
static ChildIteratorType nodes_begin(ArgumentGraph *AG)
LLVM_NODISCARD ModRefInfo createModRefInfo(const FunctionModRefBehavior FMRB)
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given value is known to be non-zero when defined.
print Print MemDeps of function
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
This is the interface for LLVM's primary stateless and local alias analysis.
inst_range instructions(Function *F)
inst_iterator inst_end(Function *F)
A container for analyses that lazily runs them and caches their results.
bool isConvergent() const
Determine if the call is convergent.
static bool isVolatile(Instruction *Inst)
This header defines various interfaces for pass management in LLVM.
bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute.
static bool InstrBreaksNonConvergent(Instruction &I, const SCCNodeSet &SCCNodes)
Helper for non-Convergent inference predicate InstrBreaksAttribute.
op_range incoming_values()
static Attribute::AttrKind determinePointerReadAttrs(Argument *A, const SmallPtrSet< Argument *, 8 > &SCCNodes)
Returns Attribute::None, Attribute::ReadOnly or Attribute::ReadNone.
static bool deduceFunctionAttributeInRPO(Module &M, CallGraph &CG)
Enumerate the SCCs of a directed graph in reverse topological order of the SCC DAG.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
LLVM_NODISCARD bool isRefSet(const ModRefInfo MRI)