35 #define DEBUG_TYPE "module-summary-analysis"
46 while (!Worklist.
empty()) {
49 if (!Visited.
insert(U).second)
54 for (
const auto &OI : U->
operands()) {
58 if (isa<BlockAddress>(Operand))
60 if (
auto *GV = dyn_cast<GlobalValue>(Operand)) {
93 std::vector<uint64_t>
Args;
97 if (!CI || CI->getBitWidth() > 64) {
101 Args.push_back(CI->getZExtValue());
103 ConstVCalls.
insert({{Guid, Call.
Offset}, std::move(Args)});
115 case Intrinsic::type_test: {
116 auto *TypeMDVal = cast<MetadataAsValue>(CI->
getArgOperand(1));
130 Function *
F = AssumeCI->getCalledFunction();
133 if (HasNonAssumeUses)
139 for (
auto &Call : DevirtCalls)
141 TypeTestAssumeConstVCalls);
146 case Intrinsic::type_checked_load: {
147 auto *TypeMDVal = cast<MetadataAsValue>(CI->
getArgOperand(2));
156 bool HasNonCallUses =
false;
163 for (
auto &Call : DevirtCalls)
165 TypeCheckedLoadConstVCalls);
183 unsigned NumInsts = 0;
190 TypeCheckedLoadVCalls;
192 TypeCheckedLoadConstVCalls;
195 bool HasInlineAsmMaybeReferencingInternal =
false;
199 if (isa<DbgInfoIntrinsic>(
I))
213 if (HasLocalsInUsed && CI && CI->isInlineAsm())
214 HasInlineAsmMaybeReferencingInternal =
true;
216 auto *CalledValue = CS.getCalledValue();
217 auto *CalledFunction = CS.getCalledFunction();
220 if (
auto *GA = dyn_cast<GlobalAlias>(CalledValue)) {
221 assert(!CalledFunction &&
"Expected null called function in callsite for alias");
226 if (CalledFunction) {
227 if (CI && CalledFunction->isIntrinsic()) {
229 CI, TypeTests, TypeTestAssumeVCalls, TypeCheckedLoadVCalls,
230 TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls);
234 assert(CalledFunction->hasName());
236 auto Hotness = ScaledCount ?
getHotness(ScaledCount.getValue(), PSI)
244 cast<GlobalValue>(CalledValue))]
245 .updateHotness(Hotness);
248 if (CI && CI->isInlineAsm())
251 if (!CS.getCalledValue() || isa<Constant>(CS.getCalledValue()))
256 auto CandidateProfileData =
258 &
I, NumVals, TotalCount, NumCandidates);
259 for (
auto &Candidate : CandidateProfileData)
261 .updateHotness(
getHotness(Candidate.Count, PSI));
267 for (
auto &
I : F.getImportGUIDs())
272 bool NotEligibleForImport =
273 NonRenamableLocal || HasInlineAsmMaybeReferencingInternal ||
279 auto FuncSummary = llvm::make_unique<FunctionSummary>(
285 if (NonRenamableLocal)
286 CantBePromoted.
insert(F.getGUID());
301 if (NonRenamableLocal)
315 assert(AliaseeSummary &&
"Alias expects aliasee summary to be parsed");
316 AS->setAliasee(AliaseeSummary);
317 if (NonRenamableLocal)
325 for (
auto &Summary :
VI.getSummaryList())
326 Summary->setLive(
true);
348 for (
auto *V : Used) {
349 if (V->hasLocalLinkage()) {
351 CantBePromoted.
insert(V->getGUID());
362 std::unique_ptr<BlockFrequencyInfo> BFIPtr;
364 BFI = GetBFICallback(F);
368 BFIPtr = llvm::make_unique<BlockFrequencyInfo>(
F, BPI, LI);
379 if (
G.isDeclaration())
389 for (
auto *V : LocalsUsed) {
391 assert(Summary &&
"Missing summary for global value");
392 Summary->setNotEligibleToImport();
404 if (!M.getModuleInlineAsm().empty()) {
430 if (isa<Function>(GV)) {
431 std::unique_ptr<FunctionSummary> Summary =
432 llvm::make_unique<FunctionSummary>(
442 std::unique_ptr<GlobalVarSummary> Summary =
443 llvm::make_unique<GlobalVarSummary>(GVFlags,
450 bool IsThinLTO =
true;
452 mdconst::extract_or_null<ConstantInt>(M.getModuleFlag(
"ThinLTO")))
453 IsThinLTO = MD->getZExtValue();
455 for (
auto &GlobalList : Index) {
457 if (GlobalList.second.SummaryList.empty())
460 assert(GlobalList.second.SummaryList.size() == 1 &&
461 "Expected module's index to have one summary per GUID");
462 auto &Summary = GlobalList.second.SummaryList[0];
464 Summary->setNotEligibleToImport();
468 bool AllRefsCanBeExternallyReferenced =
470 return !CantBePromoted.
count(
VI.getGUID());
472 if (!AllRefsCanBeExternallyReferenced) {
473 Summary->setNotEligibleToImport();
477 if (
auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
480 return !CantBePromoted.
count(Edge.first.getGUID());
482 if (!AllCallsCanBeExternallyReferenced)
483 Summary->setNotEligibleToImport();
507 "Module Summary Analysis",
false,
true)
514 return new ModuleSummaryIndexWrapperPass();
523 auto &PSI = *getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
527 return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
void push_back(const T &Elt)
LinkageTypes getLinkage() const
iterator_range< use_iterator > uses()
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
ValueInfo getValueInfo(GlobalValue::GUID GUID) const
Return a ValueInfo for GUID if it exists, otherwise return ValueInfo().
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 ...
void findDevirtualizableCallsForTypeTest(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< CallInst * > &Assumes, const CallInst *CI)
Given a call to the intrinsic .type.test, find all devirtualizable call sites based on the call and r...
A Module instance is used to store all the information related to an LLVM module. ...
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
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.
void findDevirtualizableCallsForTypeCheckedLoad(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< Instruction * > &LoadedPtrs, SmallVectorImpl< Instruction * > &Preds, bool &HasNonCallUses, const CallInst *CI)
Given a call to the intrinsic .type.checked.load, find all devirtualizable call sites based on the ca...
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.
module summary Module Summary false
uint64_t Offset
The offset from the address point to the virtual function.
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 &)
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.
StringRef getName() const
Return a constant reference to the value's name.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
A Use represents the edge between a Value definition and its users.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Legacy analysis pass which computes BlockFrequencyInfo.
LLVM_NODISCARD bool empty() const
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.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Optional< uint64_t > getEntryCount() const
Get the entry count for this function.
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...
INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass,"module-summary-analysis","Module Summary Analysis", false, true) INITIALIZE_PASS_END(ModuleSummaryIndexWrapperPass
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)
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.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
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...
const GlobalObject * getBaseObject() const
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
LLVM_NODISCARD bool empty() const
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)
VectorType takeVector()
Clear the MapVector and return the underlying vector.
void addGlobalValueSummary(StringRef ValueName, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value of the given name.
Struct that holds a reference to a particular GUID in a global value summary.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static bool isNonRenamableLocal(const GlobalValue &GV)
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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LLVM_NODISCARD T pop_back_val()
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
Result run(Module &M, ModuleAnalysisManager &AM)
void setPreservesAll()
Set by analyses that do not transform their input at all.
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID)
Return a ValueInfo for GUID.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static std::vector< std::string > Flags
Analysis providing branch probability information.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
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.
bool hasLocalLinkage() const
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)
GlobalValueSummary * getGlobalValueSummary(const GlobalValue &GV, bool PerModuleIndex=true) const
Returns the first GlobalValueSummary for GV, asserting that there is only one if PerModuleIndex.
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 computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M, const Function &F, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, bool HasLocalsInUsed, DenseSet< GlobalValue::GUID > &CantBePromoted)
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...
A special type used by analysis passes to provide an address that identifies that particular analysis...
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.
bool isCallee(Value::const_user_iterator UI) const
Determine whether the passed iterator points to the callee operand's Use.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...