60 #define DEBUG_TYPE "module-summary-analysis" 68 cl::desc(
"Force all edges in the function summary to cold"),
71 "all-non-critical",
"All non-critical edges."),
83 while (!Worklist.
empty()) {
86 if (!Visited.
insert(U).second)
91 for (
const auto &OI : U->
operands()) {
95 if (isa<BlockAddress>(Operand))
97 if (
auto *GV = dyn_cast<GlobalValue>(Operand)) {
130 std::vector<uint64_t>
Args;
134 if (!CI || CI->getBitWidth() > 64) {
138 Args.push_back(CI->getZExtValue());
140 ConstVCalls.
insert({{Guid, Call.
Offset}, std::move(Args)});
152 case Intrinsic::type_test: {
153 auto *TypeMDVal = cast<MetadataAsValue>(CI->
getArgOperand(1));
167 Function *
F = AssumeCI->getCalledFunction();
170 if (HasNonAssumeUses)
176 for (
auto &Call : DevirtCalls)
178 TypeTestAssumeConstVCalls);
183 case Intrinsic::type_checked_load: {
184 auto *TypeMDVal = cast<MetadataAsValue>(CI->
getArgOperand(2));
193 bool HasNonCallUses =
false;
200 for (
auto &Call : DevirtCalls)
202 TypeCheckedLoadConstVCalls);
220 unsigned NumInsts = 0;
227 TypeCheckedLoadVCalls;
229 TypeCheckedLoadConstVCalls;
237 bool HasInlineAsmMaybeReferencingInternal =
false;
240 if (isa<DbgInfoIntrinsic>(
I))
254 if (HasLocalsInUsedOrAsm && CI && CI->isInlineAsm())
255 HasInlineAsmMaybeReferencingInternal =
true;
257 auto *CalledValue = CS.getCalledValue();
258 auto *CalledFunction = CS.getCalledFunction();
259 if (CalledValue && !CalledFunction) {
260 CalledValue = CalledValue->stripPointerCastsNoFollowAliases();
266 if (
auto *GA = dyn_cast<GlobalAlias>(CalledValue)) {
267 assert(!CalledFunction &&
"Expected null called function in callsite for alias");
272 if (CalledFunction) {
273 if (CI && CalledFunction->isIntrinsic()) {
275 CI, TypeTests, TypeTestAssumeVCalls, TypeCheckedLoadVCalls,
276 TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls);
280 assert(CalledFunction->hasName());
282 auto Hotness = ScaledCount ?
getHotness(ScaledCount.getValue(), PSI)
292 cast<GlobalValue>(CalledValue))];
299 ValueInfo.updateRelBlockFreq(BBFreq, EntryFreq);
303 if (CI && CI->isInlineAsm())
306 if (!CalledValue || isa<Constant>(CalledValue))
314 for (
auto &
Op : MD->operands()) {
323 auto CandidateProfileData =
325 &
I, NumVals, TotalCount, NumCandidates);
326 for (
auto &Candidate : CandidateProfileData)
328 .updateHotness(
getHotness(Candidate.Count, PSI));
334 for (
auto &
I : F.getImportGUIDs())
341 bool NotEligibleForImport =
342 NonRenamableLocal || HasInlineAsmMaybeReferencingInternal ||
347 F.getAttributes().hasFnAttribute(Attribute::NoInline);
349 false, F.isDSOLocal());
351 F.hasFnAttribute(Attribute::ReadNone),
352 F.hasFnAttribute(Attribute::ReadOnly),
353 F.hasFnAttribute(Attribute::NoRecurse),
354 F.returnDoesNotAlias(),
356 auto FuncSummary = llvm::make_unique<FunctionSummary>(
357 Flags, NumInsts, FunFlags, RefEdges.
takeVector(),
362 if (NonRenamableLocal)
363 CantBePromoted.
insert(F.getGUID());
377 llvm::make_unique<GlobalVarSummary>(Flags, RefEdges.
takeVector());
378 if (NonRenamableLocal)
389 auto AS = llvm::make_unique<AliasSummary>(Flags);
392 assert(AliaseeSummary &&
"Alias expects aliasee summary to be parsed");
393 AS->setAliasee(AliaseeSummary);
394 if (NonRenamableLocal)
402 for (
auto &Summary :
VI.getSummaryList())
403 Summary->setLive(
true);
425 for (
auto *V : Used) {
426 if (V->hasLocalLinkage()) {
428 CantBePromoted.
insert(V->getGUID());
432 bool HasLocalInlineAsmSymbol =
false;
449 HasLocalInlineAsmSymbol =
true;
460 if (
Function *F = dyn_cast<Function>(GV)) {
461 std::unique_ptr<FunctionSummary> Summary =
462 llvm::make_unique<FunctionSummary>(
477 std::unique_ptr<GlobalVarSummary> Summary =
478 llvm::make_unique<GlobalVarSummary>(GVFlags,
492 std::unique_ptr<BlockFrequencyInfo> BFIPtr;
494 BFI = GetBFICallback(F);
498 BFIPtr = llvm::make_unique<BlockFrequencyInfo>(
F, BPI, LI);
503 !LocalsUsed.
empty() || HasLocalInlineAsmSymbol,
510 if (
G.isDeclaration())
520 for (
auto *V : LocalsUsed) {
522 assert(Summary &&
"Missing summary for global value");
523 Summary->setNotEligibleToImport();
535 bool IsThinLTO =
true;
537 mdconst::extract_or_null<ConstantInt>(M.getModuleFlag(
"ThinLTO")))
538 IsThinLTO = MD->getZExtValue();
540 for (
auto &GlobalList : Index) {
542 if (GlobalList.second.SummaryList.empty())
545 assert(GlobalList.second.SummaryList.size() == 1 &&
546 "Expected module's index to have one summary per GUID");
547 auto &Summary = GlobalList.second.SummaryList[0];
549 Summary->setNotEligibleToImport();
553 bool AllRefsCanBeExternallyReferenced =
555 return !CantBePromoted.
count(
VI.getGUID());
557 if (!AllRefsCanBeExternallyReferenced) {
558 Summary->setNotEligibleToImport();
562 if (
auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
565 return !CantBePromoted.
count(Edge.first.getGUID());
567 if (!AllCallsCanBeExternallyReferenced)
568 Summary->setNotEligibleToImport();
593 "Module Summary Analysis",
false,
true)
600 return new ModuleSummaryIndexWrapperPass();
609 auto &PSI = *getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
613 return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
void push_back(const T &Elt)
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
const GlobalObject * getBaseObject() const
iterator_range< use_iterator > uses()
bool hasLocalLinkage() const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Compute iterated dominance frontiers using a linear time algorithm.
A Module instance is used to store all the information related to an LLVM module. ...
GlobalValueSummary * getGlobalValueSummary(const GlobalValue &GV, bool PerModuleIndex=true) const
Returns the first GlobalValueSummary for GV, asserting that there is only one if PerModuleIndex.
CallSite CS
The call site itself.
This is the interface to build a ModuleSummaryIndex for a module.
Implements a dense probed hash-table based set.
bool isColdCount(uint64_t C)
Returns true if count C is considered cold.
Analysis providing profile information.
This class represents a function call, abstracting a target machine's calling convention.
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
uint64_t Offset
The offset from the address point to the virtual function.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
This class implements a map that also provides access to all stored values in a deterministic order...
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
Optional< uint64_t > getProfileCount(const Instruction *CallInst, BlockFrequencyInfo *BFI)
Returns the profile count for CallInst.
void initializeModuleSummaryIndexWrapperPassPass(PassRegistry &)
block Block Frequency true
This defines the Use class.
bool isHotCount(uint64_t C)
Returns true if F is a hot function.
ModuleSummaryIndex buildModuleSummaryIndex(const Module &M, std::function< BlockFrequencyInfo *(const Function &F)> GetBFICallback, ProfileSummaryInfo *PSI)
Direct function to compute a ModuleSummaryIndex from a given module.
void findDevirtualizableCallsForTypeTest(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< CallInst *> &Assumes, const CallInst *CI)
Given a call to the intrinsic @llvm.type.test, find all devirtualizable call sites based on the call ...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
static AnalysisKey * ID()
Returns an opaque, unique ID for this analysis type.
A Use represents the edge between a Value definition and its users.
This file contains the simple types necessary to represent the attributes associated with functions a...
Legacy analysis pass which computes BlockFrequencyInfo.
static void CollectAsmSymbols(const Module &M, function_ref< void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol)
Parse inline ASM and collect the symbols that are defined or referenced in the current module...
bool insert(const value_type &X)
Insert a new element into the SetVector.
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LinkageTypes getLinkage() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
amdgpu Simplify well known AMD library false Value * Callee
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, DenseSet< GlobalValue::GUID > &CantBePromoted)
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
LLVM Basic Block Representation.
A call site that could be devirtualized.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
LLVM_NODISCARD bool empty() 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...
std::pair< iterator, bool > insert(const ValueT &V)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Represent the analysis usage information of a pass.
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis", "Module Summary Analysis", false, true) INITIALIZE_PASS_END(ModuleSummaryIndexWrapperPass
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
static void addVCallToSet(DevirtCallSite Call, GlobalValue::GUID Guid, SetVector< FunctionSummary::VFuncId > &VCalls, SetVector< FunctionSummary::ConstVCall > &ConstVCalls)
Determine whether this call has all constant integer arguments (excluding "this") and summarize it to...
static void computeVariableSummary(ModuleSummaryIndex &Index, const GlobalVariable &V, DenseSet< GlobalValue::GUID > &CantBePromoted)
Class to represent profile counts.
VectorType takeVector()
Clear the MapVector and return the underlying vector.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
Struct that holds a reference to a particular GUID in a global value summary.
uint64_t getEntryFreq() const
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static bool isNonRenamableLocal(const GlobalValue &GV)
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallPtrSetImpl< GlobalValue *> &Set, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
Analysis pass which computes BlockFrequencyInfo.
Vector takeVector()
Clear the SetVector and return the underlying vector.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
void findDevirtualizableCallsForTypeCheckedLoad(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< Instruction *> &LoadedPtrs, SmallVectorImpl< Instruction *> &Preds, bool &HasNonCallUses, const CallInst *CI)
Given a call to the intrinsic @llvm.type.checked.load, find all devirtualizable call sites based on t...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
static void computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M, const Function &F, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, bool HasLocalsInUsedOrAsm, DenseSet< GlobalValue::GUID > &CantBePromoted)
LLVM_NODISCARD T pop_back_val()
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
Result run(Module &M, ModuleAnalysisManager &AM)
void setPreservesAll()
Set by analyses that do not transform their input at all.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const
Return a ValueInfo for the index value_type (convenient when iterating index).
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID)
Return a ValueInfo for GUID.
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
amdgpu Simplify well known AMD library false Value Value * Arg
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Analysis providing branch probability information.
LLVM_NODISCARD bool empty() const
void addGlobalValueSummary(const GlobalValue &GV, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value.
ModuleSummaryIndexWrapperPass()
Establish a view to a call site for examination.
module summary Module Summary Analysis
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Rename collisions when linking (static functions).
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Function attribute flags.
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
cl::opt< FunctionSummary::ForceSummaryHotnessType, true > FSEC("force-summary-edges-cold", cl::Hidden, cl::location(ForceSummaryEdgesCold), cl::desc("Force all edges in the function summary to cold"), cl::values(clEnumValN(FunctionSummary::FSHT_None, "none", "None."), clEnumValN(FunctionSummary::FSHT_AllNonCritical, "all-non-critical", "All non-critical edges."), clEnumValN(FunctionSummary::FSHT_All, "all", "All edges.")))
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
ModulePass * createModuleSummaryIndexWrapperPass()
A vector that has set insertion semantics.
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on...
static void setLiveRoot(ModuleSummaryIndex &Index, StringRef Name)
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
A container for analyses that lazily runs them and caches their results.
static void addIntrinsicToSummary(const CallInst *CI, SetVector< GlobalValue::GUID > &TypeTests, SetVector< FunctionSummary::VFuncId > &TypeTestAssumeVCalls, SetVector< FunctionSummary::VFuncId > &TypeCheckedLoadVCalls, SetVector< FunctionSummary::ConstVCall > &TypeTestAssumeConstVCalls, SetVector< FunctionSummary::ConstVCall > &TypeCheckedLoadConstVCalls)
If this intrinsic call requires that we add information to the function summary, do so via the non-co...
bool hasProfileData() const
Return true if the function is annotated with profile data.
A special type used by analysis passes to provide an address that identifies that particular analysis...
LocationClass< Ty > location(Ty &L)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static CalleeInfo::HotnessType getHotness(uint64_t ProfileCount, ProfileSummaryInfo *PSI)
static void findRefEdges(ModuleSummaryIndex &Index, const User *CurUser, SetVector< ValueInfo > &RefEdges, SmallPtrSet< const User *, 8 > &Visited)
Legacy wrapper pass to provide the ModuleSummaryIndex object.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
bool isCallee(Value::const_user_iterator UI) const
Determine whether the passed iterator points to the callee operand's Use.