67 #define DEBUG_TYPE "functionattrs" 69 STATISTIC(NumReadNone,
"Number of functions marked readnone");
70 STATISTIC(NumReadOnly,
"Number of functions marked readonly");
71 STATISTIC(NumWriteOnly,
"Number of functions marked writeonly");
72 STATISTIC(NumNoCapture,
"Number of arguments marked nocapture");
73 STATISTIC(NumReturned,
"Number of arguments marked returned");
74 STATISTIC(NumReadNoneArg,
"Number of arguments marked readnone");
75 STATISTIC(NumReadOnlyArg,
"Number of arguments marked readonly");
76 STATISTIC(NumNoAlias,
"Number of function returns marked noalias");
77 STATISTIC(NumNonNullReturn,
"Number of function returns marked nonnull");
78 STATISTIC(NumNoRecurse,
"Number of functions marked as norecurse");
79 STATISTIC(NumNoUnwind,
"Number of functions marked as nounwind");
80 STATISTIC(NumNoFree,
"Number of functions marked as nofree");
84 cl::desc(
"Try to propagate nonnull argument attributes from callsites to " 85 "caller functions."));
89 cl::desc(
"Stop inferring nounwind attribute during function-attrs pass"));
93 cl::desc(
"Stop inferring nofree attribute during function-attrs pass"));
111 const SCCNodeSet &SCCNodes) {
129 bool ReadsMemory =
false;
130 bool WritesMemory =
false;
136 if (
auto *Call = dyn_cast<CallBase>(I)) {
141 if (!Call->hasOperandBundles() && Call->getCalledFunction() &&
142 SCCNodes.count(Call->getCalledFunction()))
186 }
else if (
LoadInst *LI = dyn_cast<LoadInst>(I)) {
188 if (!LI->isVolatile()) {
193 }
else if (
StoreInst *
SI = dyn_cast<StoreInst>(I)) {
195 if (!
SI->isVolatile()) {
200 }
else if (
VAArgInst *
VI = dyn_cast<VAArgInst>(I)) {
233 template <
typename AARGetterT>
234 static bool addReadAttrs(
const SCCNodeSet &SCCNodes, AARGetterT &&AARGetter) {
237 bool ReadsMemory =
false;
238 bool WritesMemory =
false;
264 if (ReadsMemory && WritesMemory)
269 bool MadeChange =
false;
272 if (
F->doesNotAccessMemory())
276 if (
F->onlyReadsMemory() && ReadsMemory)
280 if (
F->doesNotReadMemory() && WritesMemory)
286 F->removeFnAttr(Attribute::ReadOnly);
287 F->removeFnAttr(Attribute::ReadNone);
288 F->removeFnAttr(Attribute::WriteOnly);
290 if (!WritesMemory && !ReadsMemory) {
292 F->removeFnAttr(Attribute::ArgMemOnly);
293 F->removeFnAttr(Attribute::InaccessibleMemOnly);
294 F->removeFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
298 if (WritesMemory && !ReadsMemory)
299 F->addFnAttr(Attribute::WriteOnly);
301 F->addFnAttr(ReadsMemory ? Attribute::ReadOnly : Attribute::ReadNone);
303 if (WritesMemory && !ReadsMemory)
305 else if (ReadsMemory)
319 struct ArgumentGraphNode {
324 class ArgumentGraph {
327 using ArgumentMapTy = std::map<Argument *, ArgumentGraphNode>;
329 ArgumentMapTy ArgumentMap;
337 ArgumentGraphNode SyntheticRoot;
340 ArgumentGraph() { SyntheticRoot.Definition =
nullptr; }
344 iterator
begin() {
return SyntheticRoot.Uses.begin(); }
345 iterator
end() {
return SyntheticRoot.Uses.end(); }
346 ArgumentGraphNode *getEntryNode() {
return &SyntheticRoot; }
348 ArgumentGraphNode *operator[](
Argument *A) {
349 ArgumentGraphNode &Node = ArgumentMap[A];
351 SyntheticRoot.Uses.push_back(&Node);
360 ArgumentUsesTracker(
const SCCNodeSet &SCCNodes) : SCCNodes(SCCNodes) {}
362 void tooManyUses()
override { Captured =
true; }
364 bool captured(
const Use *U)
override {
366 if (!CS.getInstruction()) {
382 std::distance(const_cast<const Use *>(CS.arg_begin()), U);
384 assert(UseIndex < CS.data_operands_size() &&
385 "Indirect function calls should have been filtered above!");
387 if (UseIndex >= CS.getNumArgOperands()) {
389 assert(CS.hasOperandBundles() &&
"Must be!");
400 assert(F->
isVarArg() &&
"More params than args in non-varargs call");
405 Uses.push_back(&*std::next(F->
arg_begin(), UseIndex));
410 bool Captured =
false;
415 const SCCNodeSet &SCCNodes;
439 static ChildIteratorType
nodes_end(ArgumentGraph *AG) {
return AG->end(); }
463 while (!Worklist.
empty()) {
468 case Instruction::BitCast:
469 case Instruction::GetElementPtr:
470 case Instruction::PHI:
472 case Instruction::AddrSpaceCast:
475 if (Visited.
insert(&UU).second)
480 case Instruction::Invoke: {
481 bool Captures =
true;
486 auto AddUsersToWorklistIfCapturing = [&] {
489 if (Visited.
insert(&UU).second)
495 AddUsersToWorklistIfCapturing();
503 AddUsersToWorklistIfCapturing();
513 unsigned UseIndex = std::distance(CS.
arg_begin(), U);
520 "Data operand use expected!");
524 if (UseIndex >= F->
arg_size() && !IsOperandBundleUse) {
525 assert(F->
isVarArg() &&
"More params than args in non-varargs call");
535 if (IsOperandBundleUse ||
547 AddUsersToWorklistIfCapturing();
560 case Instruction::ICmp:
569 return IsRead ? Attribute::ReadOnly : Attribute::ReadNone;
574 bool Changed =
false;
581 if (!
F->hasExactDefinition())
584 if (
F->getReturnType()->isVoidTy())
592 auto FindRetArg = [&]() ->
Value * {
593 Value *RetArg =
nullptr;
595 if (
auto *
Ret = dyn_cast<ReturnInst>(BB.getTerminator())) {
598 Value *RetVal =
Ret->getReturnValue()->stripPointerCasts();
599 if (!isa<Argument>(RetVal) || RetVal->
getType() != F->getReturnType())
604 else if (RetArg != RetVal)
611 if (
Value *RetArg = FindRetArg()) {
612 auto *
A = cast<Argument>(RetArg);
613 A->addAttr(Attribute::Returned);
630 bool Changed =
false;
642 if (
auto *CalledFunc = CS.getCalledFunction()) {
643 for (
auto &CSArg : CalledFunc->args()) {
644 if (!CSArg.hasNonNullAttr())
651 if (FArg && !FArg->hasNonNullAttr()) {
652 FArg->addAttr(Attribute::NonNull);
666 assert((R == Attribute::ReadOnly || R == Attribute::ReadNone)
667 &&
"Must be a Read attribute.");
668 assert(A &&
"Argument must not be null.");
680 R == Attribute::ReadOnly ? ++NumReadOnlyArg : ++NumReadNoneArg;
686 bool Changed =
false;
696 if (!
F->hasExactDefinition())
703 if (
F->onlyReadsMemory() &&
F->doesNotThrow() &&
704 F->getReturnType()->isVoidTy()) {
707 if (
A->getType()->isPointerTy() && !
A->hasNoCaptureAttr()) {
708 A->addAttr(Attribute::NoCapture);
718 if (!
A->getType()->isPointerTy())
720 bool HasNonLocalUses =
false;
721 if (!
A->hasNoCaptureAttr()) {
722 ArgumentUsesTracker Tracker(SCCNodes);
724 if (!Tracker.Captured) {
725 if (Tracker.Uses.empty()) {
727 A->addAttr(Attribute::NoCapture);
734 ArgumentGraphNode *Node = AG[&*
A];
736 Node->Uses.push_back(AG[Use]);
738 HasNonLocalUses =
true;
744 if (!HasNonLocalUses && !
A->onlyReadsMemory()) {
766 const std::vector<ArgumentGraphNode *> &ArgumentSCC = *
I;
767 if (ArgumentSCC.size() == 1) {
768 if (!ArgumentSCC[0]->Definition)
772 if (ArgumentSCC[0]->Uses.size() == 1 &&
773 ArgumentSCC[0]->Uses[0] == ArgumentSCC[0]) {
774 Argument *
A = ArgumentSCC[0]->Definition;
775 A->
addAttr(Attribute::NoCapture);
782 bool SCCCaptured =
false;
783 for (
auto I = ArgumentSCC.begin(),
E = ArgumentSCC.end();
784 I !=
E && !SCCCaptured; ++
I) {
785 ArgumentGraphNode *Node = *
I;
786 if (Node->Uses.empty()) {
787 if (!Node->Definition->hasNoCaptureAttr())
797 for (ArgumentGraphNode *
I : ArgumentSCC) {
798 ArgumentSCCNodes.
insert(
I->Definition);
801 for (
auto I = ArgumentSCC.begin(),
E = ArgumentSCC.end();
802 I !=
E && !SCCCaptured; ++
I) {
803 ArgumentGraphNode *
N = *
I;
804 for (ArgumentGraphNode *
Use : N->Uses) {
815 for (
unsigned i = 0,
e = ArgumentSCC.size(); i !=
e; ++i) {
816 Argument *
A = ArgumentSCC[i]->Definition;
817 A->
addAttr(Attribute::NoCapture);
834 for (
unsigned i = 0,
e = ArgumentSCC.size(); i !=
e; ++i) {
835 Argument *
A = ArgumentSCC[i]->Definition;
837 if (K == Attribute::ReadNone)
839 if (K == Attribute::ReadOnly) {
840 ReadAttr = Attribute::ReadOnly;
848 for (
unsigned i = 0,
e = ArgumentSCC.size(); i !=
e; ++i) {
849 Argument *
A = ArgumentSCC[i]->Definition;
865 if (
ReturnInst *
Ret = dyn_cast<ReturnInst>(BB.getTerminator()))
866 FlowsToReturn.
insert(
Ret->getReturnValue());
868 for (
unsigned i = 0; i != FlowsToReturn.
size(); ++i) {
869 Value *RetVal = FlowsToReturn[i];
871 if (
Constant *
C = dyn_cast<Constant>(RetVal)) {
872 if (!
C->isNullValue() && !isa<UndefValue>(
C))
878 if (isa<Argument>(RetVal))
881 if (
Instruction *RVI = dyn_cast<Instruction>(RetVal))
882 switch (RVI->getOpcode()) {
884 case Instruction::BitCast:
885 case Instruction::GetElementPtr:
886 case Instruction::AddrSpaceCast:
887 FlowsToReturn.
insert(RVI->getOperand(0));
895 case Instruction::PHI: {
896 PHINode *PN = cast<PHINode>(RVI);
898 FlowsToReturn.
insert(IncValue);
903 case Instruction::Alloca:
906 case Instruction::Invoke: {
931 if (
F->returnDoesNotAlias())
937 if (!
F->hasExactDefinition())
942 if (!
F->getReturnType()->isPointerTy())
949 bool MadeChange =
false;
951 if (
F->returnDoesNotAlias() ||
952 !
F->getReturnType()->isPointerTy())
955 F->setReturnDoesNotAlias();
973 "nonnull only meaningful on pointer types");
978 if (
auto *
Ret = dyn_cast<ReturnInst>(BB.getTerminator()))
979 FlowsToReturn.
insert(
Ret->getReturnValue());
981 auto &DL = F->getParent()->getDataLayout();
983 for (
unsigned i = 0; i != FlowsToReturn.
size(); ++i) {
984 Value *RetVal = FlowsToReturn[i];
997 case Instruction::BitCast:
998 case Instruction::GetElementPtr:
999 case Instruction::AddrSpaceCast:
1008 case Instruction::PHI: {
1009 PHINode *PN = cast<PHINode>(RVI);
1015 case Instruction::Invoke: {
1020 if (Callee && SCCNodes.count(Callee)) {
1039 bool SCCReturnsNonNull =
true;
1041 bool MadeChange =
false;
1048 Attribute::NonNull))
1054 if (!
F->hasExactDefinition())
1059 if (!
F->getReturnType()->isPointerTy())
1062 bool Speculative =
false;
1068 <<
" as nonnull\n");
1077 SCCReturnsNonNull =
false;
1080 if (SCCReturnsNonNull) {
1083 Attribute::NonNull) ||
1084 !
F->getReturnType()->isPointerTy())
1087 LLVM_DEBUG(
dbgs() <<
"SCC marking " <<
F->getName() <<
" as nonnull\n");
1105 class AttributeInferer {
1108 struct InferenceDescriptor {
1114 std::function<bool(const Function &)> SkipFunction;
1117 std::function<bool(Instruction &)> InstrBreaksAttribute;
1120 std::function<void(Function &)> SetAttribute;
1127 bool RequiresExactDefinition;
1134 : SkipFunction(SkipFunc), InstrBreaksAttribute(InstrScan),
1135 SetAttribute(SetAttr), AKind(AK),
1136 RequiresExactDefinition(ReqExactDef) {}
1143 void registerAttrInference(InferenceDescriptor AttrInference) {
1144 InferenceDescriptors.
push_back(AttrInference);
1147 bool run(
const SCCNodeSet &SCCNodes);
1152 bool AttributeInferer::run(
const SCCNodeSet &SCCNodes) {
1160 if (InferInSCC.
empty())
1165 if (ID.SkipFunction(*
F))
1170 return F->isDeclaration() ||
1171 (ID.RequiresExactDefinition && !
F->hasExactDefinition());
1178 InferInSCC, std::back_inserter(InferInThisFunc),
1179 [
F](
const InferenceDescriptor &ID) {
return !ID.SkipFunction(*
F); });
1181 if (InferInThisFunc.empty())
1186 llvm::erase_if(InferInThisFunc, [&](
const InferenceDescriptor &ID) {
1187 if (!ID.InstrBreaksAttribute(
I))
1192 return D.AKind == ID.AKind;
1198 if (InferInThisFunc.empty())
1203 if (InferInSCC.
empty())
1206 bool Changed =
false;
1212 for (
auto &
ID : InferInSCC) {
1213 if (
ID.SkipFunction(*
F))
1216 ID.SetAttribute(*
F);
1225 const SCCNodeSet &SCCNodes) {
1236 if (
const auto *CI = dyn_cast<CallInst>(&I)) {
1241 if (SCCNodes.count(
Callee) > 0)
1261 if (SCCNodes.count(Callee) > 0)
1276 AttributeInferer AI;
1283 AI.registerAttrInference(AttributeInferer::InferenceDescriptor{
1286 [](
const Function &
F) {
return !
F.isConvergent(); },
1292 LLVM_DEBUG(
dbgs() <<
"Removing convergent attr from fn " <<
F.getName()
1294 F.setNotConvergent();
1304 AI.registerAttrInference(AttributeInferer::InferenceDescriptor{
1305 Attribute::NoUnwind,
1307 [](
const Function &
F) {
return F.doesNotThrow(); },
1314 <<
"Adding nounwind attr to fn " <<
F.getName() <<
"\n");
1315 F.setDoesNotThrow();
1327 AI.registerAttrInference(AttributeInferer::InferenceDescriptor{
1330 [](
const Function &
F) {
return F.doesNotFreeMemory(); },
1337 <<
"Adding nofree attr to fn " <<
F.getName() <<
"\n");
1338 F.setDoesNotFreeMemory();
1344 return AI.run(SCCNodes);
1359 if (SCCNodes.size() != 1)
1370 for (
auto &
I : BB.instructionsWithoutDebug())
1384 template <
typename AARGetterT>
1386 AARGetterT &&AARGetter,
1387 bool HasUnknownCall) {
1388 bool Changed =
false;
1391 if (SCCNodes.empty())
1400 if (!HasUnknownCall) {
1426 SCCNodeSet SCCNodes;
1427 bool HasUnknownCall =
false;
1433 HasUnknownCall =
true;
1440 if (!HasUnknownCall)
1443 if (!CS.getCalledFunction()) {
1444 HasUnknownCall =
true;
1448 SCCNodes.insert(&F);
1482 "Deduce function attributes",
false,
false)
1489 return new PostOrderFunctionAttrsLegacyPass();
1492 template <
typename AARGetterT>
1499 SCCNodeSet SCCNodes;
1500 bool ExternalNode =
false;
1506 ExternalNode =
true;
1516 bool PostOrderFunctionAttrsLegacyPass::runOnSCC(
CallGraphSCC &SCC) {
1524 struct ReversePostOrderFunctionAttrsLegacyPass :
public ModulePass {
1528 ReversePostOrderFunctionAttrsLegacyPass() :
ModulePass(ID) {
1533 bool runOnModule(
Module &M)
override;
1547 "Deduce function attributes in RPO",
false,
false)
1553 return new ReversePostOrderFunctionAttrsLegacyPass();
1562 "This function has already been deduced as norecurs!");
1564 "Can only do top-down deduction for internal linkage functions!");
1574 for (
auto *U : F.
users()) {
1604 bool Changed =
false;
1611 bool ReversePostOrderFunctionAttrsLegacyPass::runOnModule(
Module &M) {
1615 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 ChildIteratorType nodes_end(ArgumentGraph *AG)
Return a value (possibly void), from a function.
MemoryAccessKind
The three kinds of memory access relevant to 'readonly' and 'readnone' attributes.
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()
bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
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.
This class represents lattice values for constants.
bool hasOptNone() const
Do not optimize this function (-O0).
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 constexpr LocationSize unknown()
static bool addArgumentReturnedAttrs(const SCCNodeSet &SCCNodes)
Deduce returned attributes for the SCC.
void push_back(const T &Elt)
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 hasRetAttr(Attribute::AttrKind Kind) const
Return true if this return value has the given attribute.
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.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
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...
bool doesNotCapture(unsigned OpNo) const
Determine whether this data operand is not captured.
void initializeReversePostOrderFunctionAttrsLegacyPassPass(PassRegistry &)
static cl::opt< bool > DisableNoFreeInference("disable-nofree-inference", cl::Hidden, cl::desc("Stop inferring nofree attribute during function-attrs pass"))
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...
inst_iterator inst_begin(Function *F)
This class represents the LLVM 'select' instruction.
static bool doesNotReadMemory(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to only write memory (or not access memory ...
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...
static bool addReadAttr(Argument *A, Attribute::AttrKind R)
No attributes have been set.
bool doesNotAccessMemory() const
Determine if the call does not access memory.
scc_iterator< T > scc_begin(const T &G)
Construct the begin iterator for a deduced graph type T.
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
Return the behavior of the given call site.
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.
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
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.
initializer< Ty > init(const Ty &Val)
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.
unsigned getNumArgOperands() const
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.
bool doesNotFreeMemory() const
Determine if the call might deallocate memory.
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.
Represent the analysis usage information of a pass.
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)
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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 onlyReadsMemory(const CallBase *Call)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
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.
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)
bool isConvergent() const
Determine if the call is convergent.
static bool InstrBreaksNoFree(Instruction &I, const SCCNodeSet &SCCNodes)
Helper for NoFree inference predicate InstrBreaksAttribute.
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:
User::op_iterator arg_iterator
The type of iterator to use when looping over actual arguments at this call site. ...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
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)
amdgpu Simplify well known AMD library false FunctionCallee Callee
BBTy * getParent() const
Get the basic block containing the call site.
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to be non-zero when defined.
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...
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.
static bool deriveAttrsInPostOrder(SCCNodeSet &SCCNodes, AARGetterT &&AARGetter, bool HasUnknownCall)
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...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
LLVM_NODISCARD ModRefInfo createModRefInfo(const FunctionModRefBehavior FMRB)
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
print Print MemDeps of function
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.
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 cl::opt< bool > EnableNonnullArgPropagation("enable-nonnull-arg-prop", cl::init(true), cl::Hidden, cl::desc("Try to propagate nonnull argument attributes from callsites to " "caller functions."))
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...
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures, unsigned MaxUsesToExplore=DefaultMaxUsesToExplore)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...
LLVM_NODISCARD bool isRefSet(const ModRefInfo MRI)
unsigned data_operands_size() const