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."),
87 bool HasBlockAddress =
false;
91 while (!Worklist.
empty()) {
94 if (!Visited.
insert(U).second)
99 for (
const auto &OI : U->
operands()) {
103 if (isa<BlockAddress>(Operand)) {
104 HasBlockAddress =
true;
107 if (
auto *GV = dyn_cast<GlobalValue>(Operand)) {
118 return HasBlockAddress;
141 std::vector<uint64_t>
Args;
145 if (!CI || CI->getBitWidth() > 64) {
149 Args.push_back(CI->getZExtValue());
151 ConstVCalls.
insert({{Guid, Call.
Offset}, std::move(Args)});
165 auto *TypeMDVal = cast<MetadataAsValue>(CI->
getArgOperand(1));
179 Function *
F = AssumeCI->getCalledFunction();
182 if (HasNonAssumeUses)
188 for (
auto &Call : DevirtCalls)
190 TypeTestAssumeConstVCalls);
196 auto *TypeMDVal = cast<MetadataAsValue>(CI->
getArgOperand(2));
205 bool HasNonCallUses =
false;
207 HasNonCallUses, CI, DT);
212 for (
auto &Call : DevirtCalls)
214 TypeCheckedLoadConstVCalls);
224 if (
const auto *LI = dyn_cast<LoadInst>(I))
225 return !LI->isVolatile();
233 bool HasLocalsInUsedOrAsm,
240 unsigned NumInsts = 0;
247 TypeCheckedLoadVCalls;
249 TypeCheckedLoadConstVCalls;
256 std::vector<const Instruction *> NonVolatileLoads;
258 bool HasInlineAsmMaybeReferencingInternal =
false;
261 if (isa<DbgInfoIntrinsic>(
I))
268 NonVolatileLoads.push_back(&
I);
282 if (HasLocalsInUsedOrAsm && CI && CI->isInlineAsm())
283 HasInlineAsmMaybeReferencingInternal =
true;
285 auto *CalledValue = CS.getCalledValue();
286 auto *CalledFunction = CS.getCalledFunction();
287 if (CalledValue && !CalledFunction) {
288 CalledValue = CalledValue->stripPointerCastsNoFollowAliases();
294 if (
auto *GA = dyn_cast<GlobalAlias>(CalledValue)) {
295 assert(!CalledFunction &&
"Expected null called function in callsite for alias");
300 if (CalledFunction) {
301 if (CI && CalledFunction->isIntrinsic()) {
303 CI, TypeTests, TypeTestAssumeVCalls, TypeCheckedLoadVCalls,
304 TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls, DT);
308 assert(CalledFunction->hasName());
310 auto Hotness = ScaledCount ?
getHotness(ScaledCount.getValue(), PSI)
320 cast<GlobalValue>(CalledValue))];
327 ValueInfo.updateRelBlockFreq(BBFreq, EntryFreq);
331 if (CI && CI->isInlineAsm())
334 if (!CalledValue || isa<Constant>(CalledValue))
342 for (
auto &
Op : MD->operands()) {
351 auto CandidateProfileData =
353 &
I, NumVals, TotalCount, NumCandidates);
354 for (
auto &Candidate : CandidateProfileData)
356 .updateHotness(
getHotness(Candidate.Count, PSI));
365 unsigned RefCnt = RefEdges.
size();
370 std::vector<ValueInfo> Refs = RefEdges.
takeVector();
375 for (; RefCnt < Refs.size(); ++RefCnt)
376 Refs[RefCnt].setReadOnly();
380 for (
auto &
I : F.getImportGUIDs())
387 bool NotEligibleForImport =
388 NonRenamableLocal || HasInlineAsmMaybeReferencingInternal;
390 false, F.isDSOLocal());
398 auto FuncSummary = llvm::make_unique<FunctionSummary>(
399 Flags, NumInsts, FunFlags, 0, std::move(Refs),
404 if (NonRenamableLocal)
405 CantBePromoted.
insert(F.getGUID());
414 bool HasBlockAddress =
findRefEdges(Index, &V, RefEdges, Visited);
423 auto GVarSummary = llvm::make_unique<GlobalVarSummary>(Flags, VarFlags,
425 if (NonRenamableLocal)
428 GVarSummary->setNotEligibleToImport();
438 auto AS = llvm::make_unique<AliasSummary>(Flags);
441 assert(AliaseeSummary &&
"Alias expects aliasee summary to be parsed");
442 AS->setAliasee(AliaseeSummary);
443 if (NonRenamableLocal)
451 for (
auto &Summary :
VI.getSummaryList())
452 Summary->setLive(
true);
460 bool EnableSplitLTOUnit =
false;
461 if (
auto *MD = mdconst::extract_or_null<ConstantInt>(
463 EnableSplitLTOUnit = MD->getZExtValue();
478 for (
auto *V : Used) {
479 if (V->hasLocalLinkage()) {
481 CantBePromoted.
insert(V->getGUID());
485 bool HasLocalInlineAsmSymbol =
false;
502 HasLocalInlineAsmSymbol =
true;
513 if (
Function *F = dyn_cast<Function>(GV)) {
514 std::unique_ptr<FunctionSummary> Summary =
515 llvm::make_unique<FunctionSummary>(
532 std::unique_ptr<GlobalVarSummary> Summary =
533 llvm::make_unique<GlobalVarSummary>(
541 bool IsThinLTO =
true;
543 mdconst::extract_or_null<ConstantInt>(M.
getModuleFlag(
"ThinLTO")))
544 IsThinLTO = MD->getZExtValue();
554 std::unique_ptr<BlockFrequencyInfo> BFIPtr;
556 BFI = GetBFICallback(F);
560 BFIPtr = llvm::make_unique<BlockFrequencyInfo>(
F, BPI, LI);
565 !LocalsUsed.
empty() || HasLocalInlineAsmSymbol,
566 CantBePromoted, IsThinLTO);
572 if (
G.isDeclaration())
582 for (
auto *V : LocalsUsed) {
584 assert(Summary &&
"Missing summary for global value");
585 Summary->setNotEligibleToImport();
597 for (
auto &GlobalList : Index) {
599 if (GlobalList.second.SummaryList.empty())
602 assert(GlobalList.second.SummaryList.size() == 1 &&
603 "Expected module's index to have one summary per GUID");
604 auto &Summary = GlobalList.second.SummaryList[0];
606 Summary->setNotEligibleToImport();
610 bool AllRefsCanBeExternallyReferenced =
612 return !CantBePromoted.
count(
VI.getGUID());
614 if (!AllRefsCanBeExternallyReferenced) {
615 Summary->setNotEligibleToImport();
619 if (
auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
622 return !CantBePromoted.
count(Edge.first.getGUID());
624 if (!AllCallsCanBeExternallyReferenced)
625 Summary->setNotEligibleToImport();
650 "Module Summary Analysis",
false,
true)
657 return new ModuleSummaryIndexWrapperPass();
666 auto *PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
670 return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
const GlobalObject * getBaseObject() const
bool hasDLLExportStorageClass() 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.
This class represents lattice values for constants.
size_type size() const
Determine the number of elements in the SetVector.
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.
void findDevirtualizableCallsForTypeTest(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< CallInst *> &Assumes, const CallInst *CI, DominatorTree &DT)
Given a call to the intrinsic @llvm.type.test, find all devirtualizable call sites based on the call ...
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.
void push_back(const T &Elt)
Analysis providing profile information.
This class represents a function call, abstracting a target machine's calling convention.
bool hasAvailableExternallyLinkage() const
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 isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time...
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 count C is considered hot.
ModuleSummaryIndex buildModuleSummaryIndex(const Module &M, std::function< BlockFrequencyInfo *(const Function &F)> GetBFICallback, ProfileSummaryInfo *PSI)
Direct function to compute a ModuleSummaryIndex from a given module.
Value * getArgOperand(unsigned i) const
void findDevirtualizableCallsForTypeCheckedLoad(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< Instruction *> &LoadedPtrs, SmallVectorImpl< Instruction *> &Preds, bool &HasNonCallUses, const CallInst *CI, DominatorTree &DT)
Given a call to the intrinsic @llvm.type.checked.load, find all devirtualizable call sites based on t...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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...
bool hasAppendingLinkage() const
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.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
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 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, DominatorTree &DT)
If this intrinsic call requires that we add information to the function summary, do so via the non-co...
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.
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false...
static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser, SetVector< ValueInfo > &RefEdges, SmallPtrSet< const User *, 8 > &Visited)
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.
LLVM_NODISCARD T pop_back_val()
static void computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M, const Function &F, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, DominatorTree &DT, bool HasLocalsInUsedOrAsm, DenseSet< GlobalValue::GUID > &CantBePromoted, bool IsThinLTO)
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.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
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.
Flags specific to function summaries.
static bool isNonVolatileLoad(const Instruction *I)
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())
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.
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)
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.