35 #define DEBUG_TYPE "module-summary-analysis"
45 while (!Worklist.
empty()) {
48 if (!Visited.
insert(U).second)
53 for (
const auto &OI : U->
operands()) {
57 if (isa<BlockAddress>(Operand))
59 if (
auto *GV = dyn_cast<GlobalValue>(Operand)) {
96 unsigned NumInsts = 0;
104 bool HasInlineAsmMaybeReferencingInternal =
false;
108 if (isa<DbgInfoIntrinsic>(
I))
122 if (HasLocalsInUsed && CI && CI->isInlineAsm())
123 HasInlineAsmMaybeReferencingInternal =
true;
125 auto *CalledValue = CS.getCalledValue();
126 auto *CalledFunction = CS.getCalledFunction();
129 if (
auto *GA = dyn_cast<GlobalAlias>(CalledValue)) {
130 assert(!CalledFunction &&
"Expected null called function in callsite for alias");
135 if (CalledFunction) {
136 if (CalledFunction->isIntrinsic()) {
137 if (CalledFunction->getIntrinsicID() != Intrinsic::type_test)
147 Function *F = AssumeCI->getCalledFunction();
150 if (HasNonAssumeUses) {
151 auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(1));
152 if (
auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata()))
157 assert(CalledFunction->hasName());
159 auto Hotness = ScaledCount ?
getHotness(ScaledCount.getValue(), PSI)
166 CallGraphEdges[cast<GlobalValue>(CalledValue)].updateHotness(Hotness);
169 if (CI && CI->isInlineAsm())
172 if (!CS.getCalledValue() || isa<Constant>(CS.getCalledValue()))
177 auto CandidateProfileData =
179 &
I, NumVals, TotalCount, NumCandidates);
180 for (
auto &Candidate : CandidateProfileData)
181 CallGraphEdges[Candidate.Value].updateHotness(
187 bool NotEligibleForImport =
188 NonRenamableLocal || HasInlineAsmMaybeReferencingInternal ||
194 auto FuncSummary = llvm::make_unique<FunctionSummary>(
197 if (NonRenamableLocal)
198 CantBePromoted.
insert(F.getGUID());
213 if (NonRenamableLocal)
227 assert(AliaseeSummary &&
"Alias expects aliasee summary to be parsed");
228 AS->setAliasee(AliaseeSummary);
229 if (NonRenamableLocal)
238 if (SummaryList == Index.
end())
240 for (
auto &Summary : SummaryList->second)
241 Summary->setLiveRoot();
262 for (
auto *V : Used) {
263 if (V->hasLocalLinkage()) {
265 CantBePromoted.
insert(V->getGUID());
276 std::unique_ptr<BlockFrequencyInfo> BFIPtr;
278 BFI = GetBFICallback(F);
282 BFIPtr = llvm::make_unique<BlockFrequencyInfo>(
F, BPI, LI);
293 if (
G.isDeclaration())
303 for (
auto *V : LocalsUsed) {
305 assert(Summary &&
"Missing summary for global value");
306 Summary->setNotEligibleToImport();
318 if (!M.getModuleInlineAsm().empty()) {
329 Triple(M.getTargetTriple()), M.getModuleInlineAsm(),
345 if (isa<Function>(GV)) {
346 std::unique_ptr<FunctionSummary> Summary =
347 llvm::make_unique<FunctionSummary>(
351 Index.addGlobalValueSummary(Name, std::move(Summary));
353 std::unique_ptr<GlobalVarSummary> Summary =
354 llvm::make_unique<GlobalVarSummary>(GVFlags,
356 Index.addGlobalValueSummary(Name, std::move(Summary));
361 for (
auto &GlobalList : Index) {
362 assert(GlobalList.second.size() == 1 &&
363 "Expected module's index to have one summary per GUID");
364 auto &Summary = GlobalList.second[0];
365 bool AllRefsCanBeExternallyReferenced =
367 return !CantBePromoted.
count(
VI.getValue()->getGUID());
369 if (!AllRefsCanBeExternallyReferenced) {
370 Summary->setNotEligibleToImport();
374 if (
auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
377 auto GUID = Edge.first.isGUID() ? Edge.first.getGUID()
378 : Edge.first.getValue()->getGUID();
379 return !CantBePromoted.
count(GUID);
381 if (!AllCallsCanBeExternallyReferenced)
382 Summary->setNotEligibleToImport();
406 "Module Summary Analysis",
false,
true)
413 return new ModuleSummaryIndexWrapperPass();
422 auto &PSI = *getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
426 return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
void push_back(const T &Elt)
LinkageTypes getLinkage() const
static void findRefEdges(const User *CurUser, SetVector< ValueInfo > &RefEdges, SmallPtrSet< const User *, 8 > &Visited)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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 ...
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.
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.
module summary Module Summary false
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...
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)
struct fuzzer::@269 Flags
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
A Use represents the edge between a Value definition and its users.
Legacy analysis pass which computes BlockFrequencyInfo.
LLVM_NODISCARD bool empty() const
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...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM Basic Block Representation.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
const const_gvsummary_iterator findGlobalValueSummaryList(StringRef ValueName) const
Get the list of global value summary objects for a given value name.
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 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.
Triple - Helper class for working with autoconf configuration names.
Struct to hold value either by GUID or GlobalValue*.
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 a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
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...
Result run(Module &M, ModuleAnalysisManager &AM)
void setPreservesAll()
Set by analyses that do not transform their input at all.
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.
size_type count(const ValueT &V) const
Return 1 if the specified key is in the set, 0 otherwise.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
ModuleSummaryIndexWrapperPass()
ImmutableCallSite - 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).
bool hasLocalLinkage() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ModulePass * createModuleSummaryIndexWrapperPass()
static void CollectAsmSymbols(const Triple &TheTriple, StringRef InlineAsm, function_ref< void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol)
Parse inline ASM and collect the symbols that are defined or referenced in the current module...
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.
Optional< uint64_t > getBlockProfileCount(const BasicBlock *BB) const
Returns the estimated profile count of BB.
static void computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M, const Function &F, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, bool HasLocalsInUsed, DenseSet< GlobalValue::GUID > &CantBePromoted)
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
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)
Legacy wrapper pass to provide the ModuleSummaryIndex object.
bool isCallee(Value::const_user_iterator UI) const
isCallee - 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...