LLVM 20.0.0git
Classes | Namespaces | Macros | Functions | Variables
Attributor.cpp File Reference
#include "llvm/Transforms/IPO/Attributor.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/MustExecute.h"
#include "llvm/IR/AttributeMask.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/ConstantFold.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugCounter.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/GraphWriter.h"
#include "llvm/Support/ModRef.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/Local.h"
#include <cstdint>
#include <memory>
#include <cassert>
#include <optional>
#include <string>

Go to the source code of this file.

Classes

struct  llvm::GraphTraits< AADepGraphNode * >
 
struct  llvm::GraphTraits< AADepGraph * >
 
struct  llvm::DOTGraphTraits< AADepGraph * >
 

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
 

Macros

#define DEBUG_TYPE   "attributor"
 
#define VERBOSE_DEBUG_TYPE   DEBUG_TYPE "-verbose"
 

Functions

 DEBUG_COUNTER (ManifestDBGCounter, "attributor-manifest", "Determine what attributes are manifested in the IR")
 
 STATISTIC (NumFnDeleted, "Number of function deleted")
 
 STATISTIC (NumFnWithExactDefinition, "Number of functions with exact definitions")
 
 STATISTIC (NumFnWithoutExactDefinition, "Number of functions without exact definitions")
 
 STATISTIC (NumFnShallowWrappersCreated, "Number of shallow wrappers created")
 
 STATISTIC (NumAttributesTimedOut, "Number of abstract attributes timed out before fixpoint")
 
 STATISTIC (NumAttributesValidFixpoint, "Number of abstract attributes in a valid fixpoint state")
 
 STATISTIC (NumAttributesManifested, "Number of abstract attributes manifested in IR")
 
template<bool IsLoad, typename Ty >
static bool getPotentialCopiesOfMemoryValue (Attributor &A, Ty &I, SmallSetVector< Value *, 4 > &PotentialCopies, SmallSetVector< Instruction *, 4 > *PotentialValueOrigins, const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, bool OnlyExact)
 
static bool isAssumedReadOnlyOrReadNone (Attributor &A, const IRPosition &IRP, const AbstractAttribute &QueryingAA, bool RequireReadNone, bool &IsKnown)
 
static bool isPotentiallyReachable (Attributor &A, const Instruction &FromI, const Instruction *ToI, const Function &ToFn, const AbstractAttribute &QueryingAA, const AA::InstExclusionSetTy *ExclusionSet, std::function< bool(const Function &F)> GoBackwardsCB)
 
static bool isEqualOrWorse (const Attribute &New, const Attribute &Old)
 Return true if New is equal or worse than Old.
 
static bool addIfNotExistent (LLVMContext &Ctx, const Attribute &Attr, AttributeSet AttrSet, bool ForceReplace, AttrBuilder &AB)
 Return true if the information provided by Attr was added to the attribute set AttrSet.
 
bool canMarkAsVisited (const User *Usr)
 
static bool checkForAllInstructionsImpl (Attributor *A, InformationCache::OpcodeInstMapTy &OpcodeInstMap, function_ref< bool(Instruction &)> Pred, const AbstractAttribute *QueryingAA, const AAIsDead *LivenessAA, ArrayRef< unsigned > Opcodes, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, bool CheckPotentiallyDead=false)
 
static bool runAttributorOnFunctions (InformationCache &InfoCache, SetVector< Function * > &Functions, AnalysisGetter &AG, CallGraphUpdater &CGUpdater, bool DeleteFns, bool IsModulePass)
 }
 
static bool runAttributorLightOnFunctions (InformationCache &InfoCache, SetVector< Function * > &Functions, AnalysisGetter &AG, CallGraphUpdater &CGUpdater, FunctionAnalysisManager &FAM, bool IsModulePass)
 

Variables

static cl::opt< unsignedSetFixpointIterations ("attributor-max-iterations", cl::Hidden, cl::desc("Maximal number of fixpoint iterations."), cl::init(32))
 
static cl::opt< unsignedMaxSpecializationPerCB ("attributor-max-specializations-per-call-base", cl::Hidden, cl::desc("Maximal number of callees specialized for " "a call base"), cl::init(UINT32_MAX))
 
static cl::opt< unsigned, trueMaxInitializationChainLengthX ("attributor-max-initialization-chain-length", cl::Hidden, cl::desc("Maximal number of chained initializations (to avoid stack overflows)"), cl::location(MaxInitializationChainLength), cl::init(1024))
 
static cl::opt< boolAnnotateDeclarationCallSites ("attributor-annotate-decl-cs", cl::Hidden, cl::desc("Annotate call sites of function declarations."), cl::init(false))
 
static cl::opt< boolEnableHeapToStack ("enable-heap-to-stack-conversion", cl::init(true), cl::Hidden)
 
static cl::opt< boolAllowShallowWrappers ("attributor-allow-shallow-wrappers", cl::Hidden, cl::desc("Allow the Attributor to create shallow " "wrappers for non-exact definitions."), cl::init(false))
 
static cl::opt< boolAllowDeepWrapper ("attributor-allow-deep-wrappers", cl::Hidden, cl::desc("Allow the Attributor to use IP information " "derived from non-exact functions via cloning"), cl::init(false))
 
static cl::list< std::string > SeedAllowList ("attributor-seed-allow-list", cl::Hidden, cl::desc("Comma separated list of attribute names that are " "allowed to be seeded."), cl::CommaSeparated)
 
static cl::list< std::string > FunctionSeedAllowList ("attributor-function-seed-allow-list", cl::Hidden, cl::desc("Comma separated list of function names that are " "allowed to be seeded."), cl::CommaSeparated)
 
static cl::opt< boolDumpDepGraph ("attributor-dump-dep-graph", cl::Hidden, cl::desc("Dump the dependency graph to dot files."), cl::init(false))
 
static cl::opt< std::string > DepGraphDotFileNamePrefix ("attributor-depgraph-dot-filename-prefix", cl::Hidden, cl::desc("The prefix used for the CallGraph dot file names."))
 
static cl::opt< boolViewDepGraph ("attributor-view-dep-graph", cl::Hidden, cl::desc("View the dependency graph."), cl::init(false))
 
static cl::opt< boolPrintDependencies ("attributor-print-dep", cl::Hidden, cl::desc("Print attribute dependencies"), cl::init(false))
 
static cl::opt< boolEnableCallSiteSpecific ("attributor-enable-call-site-specific-deduction", cl::Hidden, cl::desc("Allow the Attributor to do call site specific analysis"), cl::init(false))
 
static cl::opt< boolPrintCallGraph ("attributor-print-call-graph", cl::Hidden, cl::desc("Print Attributor's internal call graph"), cl::init(false))
 
static cl::opt< boolSimplifyAllLoads ("attributor-simplify-all-loads", cl::Hidden, cl::desc("Try to simplify all loads."), cl::init(true))
 
static cl::opt< boolCloseWorldAssumption ("attributor-assume-closed-world", cl::Hidden, cl::desc("Should a closed world be assumed, or not. Default if not set."))
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "attributor"

Definition at line 66 of file Attributor.cpp.

◆ VERBOSE_DEBUG_TYPE

#define VERBOSE_DEBUG_TYPE   DEBUG_TYPE "-verbose"

Definition at line 67 of file Attributor.cpp.

Function Documentation

◆ addIfNotExistent()

static bool addIfNotExistent ( LLVMContext Ctx,
const Attribute Attr,
AttributeSet  AttrSet,
bool  ForceReplace,
AttrBuilder AB 
)
static

◆ canMarkAsVisited()

bool canMarkAsVisited ( const User Usr)

Definition at line 1752 of file Attributor.cpp.

Referenced by llvm::Attributor::checkForAllUses().

◆ checkForAllInstructionsImpl()

static bool checkForAllInstructionsImpl ( Attributor A,
InformationCache::OpcodeInstMapTy OpcodeInstMap,
function_ref< bool(Instruction &)>  Pred,
const AbstractAttribute QueryingAA,
const AAIsDead LivenessAA,
ArrayRef< unsigned Opcodes,
bool UsedAssumedInformation,
bool  CheckBBLivenessOnly = false,
bool  CheckPotentiallyDead = false 
)
static

◆ DEBUG_COUNTER()

DEBUG_COUNTER ( ManifestDBGCounter  ,
"attributor-manifest"  ,
"Determine what attributes are manifested in the IR"   
)

◆ getPotentialCopiesOfMemoryValue()

template<bool IsLoad, typename Ty >
static bool getPotentialCopiesOfMemoryValue ( Attributor A,
Ty &  I,
SmallSetVector< Value *, 4 > &  PotentialCopies,
SmallSetVector< Instruction *, 4 > *  PotentialValueOrigins,
const AbstractAttribute QueryingAA,
bool UsedAssumedInformation,
bool  OnlyExact 
)
static

◆ isAssumedReadOnlyOrReadNone()

static bool isAssumedReadOnlyOrReadNone ( Attributor A,
const IRPosition IRP,
const AbstractAttribute QueryingAA,
bool  RequireReadNone,
bool IsKnown 
)
static

◆ isEqualOrWorse()

static bool isEqualOrWorse ( const Attribute New,
const Attribute Old 
)
static

Return true if New is equal or worse than Old.

Definition at line 946 of file Attributor.cpp.

References llvm::Attribute::getValueAsInt(), and llvm::Attribute::isIntAttribute().

Referenced by addIfNotExistent().

◆ isPotentiallyReachable()

static bool isPotentiallyReachable ( Attributor A,
const Instruction FromI,
const Instruction ToI,
const Function ToFn,
const AbstractAttribute QueryingAA,
const AA::InstExclusionSetTy ExclusionSet,
std::function< bool(const Function &F)>  GoBackwardsCB 
)
static

◆ runAttributorLightOnFunctions()

static bool runAttributorLightOnFunctions ( InformationCache InfoCache,
SetVector< Function * > &  Functions,
AnalysisGetter AG,
CallGraphUpdater CGUpdater,
FunctionAnalysisManager FAM,
bool  IsModulePass 
)
static

◆ runAttributorOnFunctions()

static bool runAttributorOnFunctions ( InformationCache InfoCache,
SetVector< Function * > &  Functions,
AnalysisGetter AG,
CallGraphUpdater CGUpdater,
bool  DeleteFns,
bool  IsModulePass 
)
static

◆ STATISTIC() [1/7]

STATISTIC ( NumAttributesManifested  ,
"Number of abstract attributes manifested in IR"   
)

◆ STATISTIC() [2/7]

STATISTIC ( NumAttributesTimedOut  ,
"Number of abstract attributes timed out before fixpoint"   
)

◆ STATISTIC() [3/7]

STATISTIC ( NumAttributesValidFixpoint  ,
"Number of abstract attributes in a valid fixpoint state"   
)

◆ STATISTIC() [4/7]

STATISTIC ( NumFnDeleted  ,
"Number of function deleted"   
)

◆ STATISTIC() [5/7]

STATISTIC ( NumFnShallowWrappersCreated  ,
"Number of shallow wrappers created"   
)

◆ STATISTIC() [6/7]

STATISTIC ( NumFnWithExactDefinition  ,
"Number of functions with exact definitions"   
)

◆ STATISTIC() [7/7]

STATISTIC ( NumFnWithoutExactDefinition  ,
"Number of functions without exact definitions"   
)

Variable Documentation

◆ AllowDeepWrapper

cl::opt< bool > AllowDeepWrapper("attributor-allow-deep-wrappers", cl::Hidden, cl::desc("Allow the Attributor to use IP information " "derived from non-exact functions via cloning"), cl::init(false)) ( "attributor-allow-deep-wrappers"  ,
cl::Hidden  ,
cl::desc("Allow the Attributor to use IP information " "derived from non-exact functions via cloning")  ,
cl::init(false)   
)
static

◆ AllowShallowWrappers

cl::opt< bool > AllowShallowWrappers("attributor-allow-shallow-wrappers", cl::Hidden, cl::desc("Allow the Attributor to create shallow " "wrappers for non-exact definitions."), cl::init(false)) ( "attributor-allow-shallow-wrappers"  ,
cl::Hidden  ,
cl::desc("Allow the Attributor to create shallow " "wrappers for non-exact definitions.")  ,
cl::init(false)   
)
static

◆ AnnotateDeclarationCallSites

cl::opt< bool > AnnotateDeclarationCallSites("attributor-annotate-decl-cs", cl::Hidden, cl::desc("Annotate call sites of function declarations."), cl::init(false)) ( "attributor-annotate-decl-cs"  ,
cl::Hidden  ,
cl::desc("Annotate call sites of function declarations.")  ,
cl::init(false)   
)
static

◆ CloseWorldAssumption

cl::opt< bool > CloseWorldAssumption("attributor-assume-closed-world", cl::Hidden, cl::desc("Should a closed world be assumed, or not. Default if not set.")) ( "attributor-assume-closed-world"  ,
cl::Hidden  ,
cl::desc("Should a closed world be assumed, or not. Default if not set.")   
)
static

◆ DepGraphDotFileNamePrefix

cl::opt< std::string > DepGraphDotFileNamePrefix("attributor-depgraph-dot-filename-prefix", cl::Hidden, cl::desc("The prefix used for the CallGraph dot file names.")) ( "attributor-depgraph-dot-filename-prefix"  ,
cl::Hidden  ,
cl::desc("The prefix used for the CallGraph dot file names.")   
)
static

◆ DumpDepGraph

cl::opt< bool > DumpDepGraph("attributor-dump-dep-graph", cl::Hidden, cl::desc("Dump the dependency graph to dot files."), cl::init(false)) ( "attributor-dump-dep-graph"  ,
cl::Hidden  ,
cl::desc("Dump the dependency graph to dot files.")  ,
cl::init(false)   
)
static

Referenced by llvm::Attributor::run().

◆ EnableCallSiteSpecific

cl::opt< bool > EnableCallSiteSpecific("attributor-enable-call-site-specific-deduction", cl::Hidden, cl::desc("Allow the Attributor to do call site specific analysis"), cl::init(false)) ( "attributor-enable-call-site-specific-deduction"  ,
cl::Hidden  ,
cl::desc("Allow the Attributor to do call site specific analysis")  ,
cl::init(false)   
)
static

◆ EnableHeapToStack

cl::opt< bool > EnableHeapToStack("enable-heap-to-stack-conversion", cl::init(true), cl::Hidden) ( "enable-heap-to-stack-conversion"  ,
cl::init(true ,
cl::Hidden   
)
static

◆ FunctionSeedAllowList

cl::list< std::string > FunctionSeedAllowList("attributor-function-seed-allow-list", cl::Hidden, cl::desc("Comma separated list of function names that are " "allowed to be seeded."), cl::CommaSeparated) ( "attributor-function-seed-allow-list"  ,
cl::Hidden  ,
cl::desc("Comma separated list of function names that are " "allowed to be seeded.")  ,
cl::CommaSeparated   
)
static

◆ MaxInitializationChainLengthX

cl::opt< unsigned, true > MaxInitializationChainLengthX("attributor-max-initialization-chain-length", cl::Hidden, cl::desc( "Maximal number of chained initializations (to avoid stack overflows)"), cl::location(MaxInitializationChainLength), cl::init(1024)) ( "attributor-max-initialization-chain-length"  ,
cl::Hidden  ,
cl::desc( "Maximal number of chained initializations (to avoid stack overflows)")  ,
cl::location(MaxInitializationChainLength)  ,
cl::init(1024)   
)
static

◆ MaxSpecializationPerCB

cl::opt< unsigned > MaxSpecializationPerCB("attributor-max-specializations-per-call-base", cl::Hidden, cl::desc("Maximal number of callees specialized for " "a call base"), cl::init(UINT32_MAX)) ( "attributor-max-specializations-per-call-base"  ,
cl::Hidden  ,
cl::desc("Maximal number of callees specialized for " "a call base")  ,
cl::init(UINT32_MAX)   
)
static

◆ PrintCallGraph

cl::opt< bool > PrintCallGraph("attributor-print-call-graph", cl::Hidden, cl::desc("Print Attributor's internal call graph"), cl::init(false)) ( "attributor-print-call-graph"  ,
cl::Hidden  ,
cl::desc("Print Attributor's internal call graph")  ,
cl::init(false)   
)
static

Referenced by llvm::Attributor::run().

◆ PrintDependencies

cl::opt< bool > PrintDependencies("attributor-print-dep", cl::Hidden, cl::desc("Print attribute dependencies"), cl::init(false)) ( "attributor-print-dep"  ,
cl::Hidden  ,
cl::desc("Print attribute dependencies")  ,
cl::init(false)   
)
static

Referenced by llvm::Attributor::run().

◆ SeedAllowList

cl::list< std::string > SeedAllowList("attributor-seed-allow-list", cl::Hidden, cl::desc("Comma separated list of attribute names that are " "allowed to be seeded."), cl::CommaSeparated) ( "attributor-seed-allow-list"  ,
cl::Hidden  ,
cl::desc("Comma separated list of attribute names that are " "allowed to be seeded.")  ,
cl::CommaSeparated   
)
static

◆ SetFixpointIterations

cl::opt< unsigned > SetFixpointIterations("attributor-max-iterations", cl::Hidden, cl::desc("Maximal number of fixpoint iterations."), cl::init(32)) ( "attributor-max-iterations"  ,
cl::Hidden  ,
cl::desc("Maximal number of fixpoint iterations.")  ,
cl::init(32)   
)
static

◆ SimplifyAllLoads

cl::opt< bool > SimplifyAllLoads("attributor-simplify-all-loads", cl::Hidden, cl::desc("Try to simplify all loads."), cl::init(true)) ( "attributor-simplify-all-loads"  ,
cl::Hidden  ,
cl::desc("Try to simplify all loads.")  ,
cl::init(true  
)
static

◆ ViewDepGraph

cl::opt< bool > ViewDepGraph("attributor-view-dep-graph", cl::Hidden, cl::desc("View the dependency graph."), cl::init(false)) ( "attributor-view-dep-graph"  ,
cl::Hidden  ,
cl::desc("View the dependency graph.")  ,
cl::init(false)   
)
static

Referenced by llvm::Attributor::run().