LLVM  5.0.0
ModuleSummaryAnalysis.cpp
Go to the documentation of this file.
1 //===- ModuleSummaryAnalysis.cpp - Module summary index builder -----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This pass builds a ModuleSummaryIndex object for the module, to be written
11 // to bitcode or LLVM assembly.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "llvm/ADT/MapVector.h"
17 #include "llvm/ADT/SetVector.h"
18 #include "llvm/ADT/Triple.h"
23 #include "llvm/Analysis/LoopInfo.h"
26 #include "llvm/IR/CallSite.h"
27 #include "llvm/IR/Dominators.h"
28 #include "llvm/IR/InstIterator.h"
29 #include "llvm/IR/IntrinsicInst.h"
32 #include "llvm/Pass.h"
33 using namespace llvm;
34 
35 #define DEBUG_TYPE "module-summary-analysis"
36 
37 // Walk through the operands of a given User via worklist iteration and populate
38 // the set of GlobalValue references encountered. Invoked either on an
39 // Instruction or a GlobalVariable (which walks its initializer).
40 static void findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
41  SetVector<ValueInfo> &RefEdges,
44  Worklist.push_back(CurUser);
45 
46  while (!Worklist.empty()) {
47  const User *U = Worklist.pop_back_val();
48 
49  if (!Visited.insert(U).second)
50  continue;
51 
52  ImmutableCallSite CS(U);
53 
54  for (const auto &OI : U->operands()) {
55  const User *Operand = dyn_cast<User>(OI);
56  if (!Operand)
57  continue;
58  if (isa<BlockAddress>(Operand))
59  continue;
60  if (auto *GV = dyn_cast<GlobalValue>(Operand)) {
61  // We have a reference to a global value. This should be added to
62  // the reference set unless it is a callee. Callees are handled
63  // specially by WriteFunction and are added to a separate list.
64  if (!(CS && CS.isCallee(&OI)))
65  RefEdges.insert(Index.getOrInsertValueInfo(GV));
66  continue;
67  }
68  Worklist.push_back(Operand);
69  }
70  }
71 }
72 
73 static CalleeInfo::HotnessType getHotness(uint64_t ProfileCount,
74  ProfileSummaryInfo *PSI) {
75  if (!PSI)
77  if (PSI->isHotCount(ProfileCount))
79  if (PSI->isColdCount(ProfileCount))
82 }
83 
84 static bool isNonRenamableLocal(const GlobalValue &GV) {
85  return GV.hasSection() && GV.hasLocalLinkage();
86 }
87 
88 /// Determine whether this call has all constant integer arguments (excluding
89 /// "this") and summarize it to VCalls or ConstVCalls as appropriate.
93  std::vector<uint64_t> Args;
94  // Start from the second argument to skip the "this" pointer.
95  for (auto &Arg : make_range(Call.CS.arg_begin() + 1, Call.CS.arg_end())) {
96  auto *CI = dyn_cast<ConstantInt>(Arg);
97  if (!CI || CI->getBitWidth() > 64) {
98  VCalls.insert({Guid, Call.Offset});
99  return;
100  }
101  Args.push_back(CI->getZExtValue());
102  }
103  ConstVCalls.insert({{Guid, Call.Offset}, std::move(Args)});
104 }
105 
106 /// If this intrinsic call requires that we add information to the function
107 /// summary, do so via the non-constant reference arguments.
109  const CallInst *CI, SetVector<GlobalValue::GUID> &TypeTests,
110  SetVector<FunctionSummary::VFuncId> &TypeTestAssumeVCalls,
111  SetVector<FunctionSummary::VFuncId> &TypeCheckedLoadVCalls,
112  SetVector<FunctionSummary::ConstVCall> &TypeTestAssumeConstVCalls,
113  SetVector<FunctionSummary::ConstVCall> &TypeCheckedLoadConstVCalls) {
114  switch (CI->getCalledFunction()->getIntrinsicID()) {
115  case Intrinsic::type_test: {
116  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(1));
117  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
118  if (!TypeId)
119  break;
120  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
121 
122  // Produce a summary from type.test intrinsics. We only summarize type.test
123  // intrinsics that are used other than by an llvm.assume intrinsic.
124  // Intrinsics that are assumed are relevant only to the devirtualization
125  // pass, not the type test lowering pass.
126  bool HasNonAssumeUses = llvm::any_of(CI->uses(), [](const Use &CIU) {
127  auto *AssumeCI = dyn_cast<CallInst>(CIU.getUser());
128  if (!AssumeCI)
129  return true;
130  Function *F = AssumeCI->getCalledFunction();
131  return !F || F->getIntrinsicID() != Intrinsic::assume;
132  });
133  if (HasNonAssumeUses)
134  TypeTests.insert(Guid);
135 
136  SmallVector<DevirtCallSite, 4> DevirtCalls;
138  findDevirtualizableCallsForTypeTest(DevirtCalls, Assumes, CI);
139  for (auto &Call : DevirtCalls)
140  addVCallToSet(Call, Guid, TypeTestAssumeVCalls,
141  TypeTestAssumeConstVCalls);
142 
143  break;
144  }
145 
146  case Intrinsic::type_checked_load: {
147  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(2));
148  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
149  if (!TypeId)
150  break;
151  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
152 
153  SmallVector<DevirtCallSite, 4> DevirtCalls;
156  bool HasNonCallUses = false;
157  findDevirtualizableCallsForTypeCheckedLoad(DevirtCalls, LoadedPtrs, Preds,
158  HasNonCallUses, CI);
159  // Any non-call uses of the result of llvm.type.checked.load will
160  // prevent us from optimizing away the llvm.type.test.
161  if (HasNonCallUses)
162  TypeTests.insert(Guid);
163  for (auto &Call : DevirtCalls)
164  addVCallToSet(Call, Guid, TypeCheckedLoadVCalls,
165  TypeCheckedLoadConstVCalls);
166 
167  break;
168  }
169  default:
170  break;
171  }
172 }
173 
174 static void
176  const Function &F, BlockFrequencyInfo *BFI,
177  ProfileSummaryInfo *PSI, bool HasLocalsInUsed,
178  DenseSet<GlobalValue::GUID> &CantBePromoted) {
179  // Summary not currently supported for anonymous functions, they should
180  // have been named.
181  assert(F.hasName());
182 
183  unsigned NumInsts = 0;
184  // Map from callee ValueId to profile count. Used to accumulate profile
185  // counts for all static calls to a given callee.
186  MapVector<ValueInfo, CalleeInfo> CallGraphEdges;
187  SetVector<ValueInfo> RefEdges;
189  SetVector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
190  TypeCheckedLoadVCalls;
191  SetVector<FunctionSummary::ConstVCall> TypeTestAssumeConstVCalls,
192  TypeCheckedLoadConstVCalls;
193  ICallPromotionAnalysis ICallAnalysis;
194 
195  bool HasInlineAsmMaybeReferencingInternal = false;
197  for (const BasicBlock &BB : F)
198  for (const Instruction &I : BB) {
199  if (isa<DbgInfoIntrinsic>(I))
200  continue;
201  ++NumInsts;
202  findRefEdges(Index, &I, RefEdges, Visited);
203  auto CS = ImmutableCallSite(&I);
204  if (!CS)
205  continue;
206 
207  const auto *CI = dyn_cast<CallInst>(&I);
208  // Since we don't know exactly which local values are referenced in inline
209  // assembly, conservatively mark the function as possibly referencing
210  // a local value from inline assembly to ensure we don't export a
211  // reference (which would require renaming and promotion of the
212  // referenced value).
213  if (HasLocalsInUsed && CI && CI->isInlineAsm())
214  HasInlineAsmMaybeReferencingInternal = true;
215 
216  auto *CalledValue = CS.getCalledValue();
217  auto *CalledFunction = CS.getCalledFunction();
218  // Check if this is an alias to a function. If so, get the
219  // called aliasee for the checks below.
220  if (auto *GA = dyn_cast<GlobalAlias>(CalledValue)) {
221  assert(!CalledFunction && "Expected null called function in callsite for alias");
222  CalledFunction = dyn_cast<Function>(GA->getBaseObject());
223  }
224  // Check if this is a direct call to a known function or a known
225  // intrinsic, or an indirect call with profile data.
226  if (CalledFunction) {
227  if (CI && CalledFunction->isIntrinsic()) {
229  CI, TypeTests, TypeTestAssumeVCalls, TypeCheckedLoadVCalls,
230  TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls);
231  continue;
232  }
233  // We should have named any anonymous globals
234  assert(CalledFunction->hasName());
235  auto ScaledCount = PSI->getProfileCount(&I, BFI);
236  auto Hotness = ScaledCount ? getHotness(ScaledCount.getValue(), PSI)
238 
239  // Use the original CalledValue, in case it was an alias. We want
240  // to record the call edge to the alias in that case. Eventually
241  // an alias summary will be created to associate the alias and
242  // aliasee.
243  CallGraphEdges[Index.getOrInsertValueInfo(
244  cast<GlobalValue>(CalledValue))]
245  .updateHotness(Hotness);
246  } else {
247  // Skip inline assembly calls.
248  if (CI && CI->isInlineAsm())
249  continue;
250  // Skip direct calls.
251  if (!CS.getCalledValue() || isa<Constant>(CS.getCalledValue()))
252  continue;
253 
254  uint32_t NumVals, NumCandidates;
255  uint64_t TotalCount;
256  auto CandidateProfileData =
258  &I, NumVals, TotalCount, NumCandidates);
259  for (auto &Candidate : CandidateProfileData)
260  CallGraphEdges[Index.getOrInsertValueInfo(Candidate.Value)]
261  .updateHotness(getHotness(Candidate.Count, PSI));
262  }
263  }
264 
265  // Explicit add hot edges to enforce importing for designated GUIDs for
266  // sample PGO, to enable the same inlines as the profiled optimized binary.
267  for (auto &I : F.getImportGUIDs())
268  CallGraphEdges[Index.getOrInsertValueInfo(I)].updateHotness(
270 
271  bool NonRenamableLocal = isNonRenamableLocal(F);
272  bool NotEligibleForImport =
273  NonRenamableLocal || HasInlineAsmMaybeReferencingInternal ||
274  // Inliner doesn't handle variadic functions.
275  // FIXME: refactor this to use the same code that inliner is using.
276  F.isVarArg();
277  GlobalValueSummary::GVFlags Flags(F.getLinkage(), NotEligibleForImport,
278  /* Live = */ false);
279  auto FuncSummary = llvm::make_unique<FunctionSummary>(
280  Flags, NumInsts, RefEdges.takeVector(), CallGraphEdges.takeVector(),
281  TypeTests.takeVector(), TypeTestAssumeVCalls.takeVector(),
282  TypeCheckedLoadVCalls.takeVector(),
283  TypeTestAssumeConstVCalls.takeVector(),
284  TypeCheckedLoadConstVCalls.takeVector());
285  if (NonRenamableLocal)
286  CantBePromoted.insert(F.getGUID());
287  Index.addGlobalValueSummary(F.getName(), std::move(FuncSummary));
288 }
289 
290 static void
292  DenseSet<GlobalValue::GUID> &CantBePromoted) {
293  SetVector<ValueInfo> RefEdges;
295  findRefEdges(Index, &V, RefEdges, Visited);
296  bool NonRenamableLocal = isNonRenamableLocal(V);
297  GlobalValueSummary::GVFlags Flags(V.getLinkage(), NonRenamableLocal,
298  /* Live = */ false);
299  auto GVarSummary =
300  llvm::make_unique<GlobalVarSummary>(Flags, RefEdges.takeVector());
301  if (NonRenamableLocal)
302  CantBePromoted.insert(V.getGUID());
303  Index.addGlobalValueSummary(V.getName(), std::move(GVarSummary));
304 }
305 
306 static void
308  DenseSet<GlobalValue::GUID> &CantBePromoted) {
309  bool NonRenamableLocal = isNonRenamableLocal(A);
310  GlobalValueSummary::GVFlags Flags(A.getLinkage(), NonRenamableLocal,
311  /* Live = */ false);
312  auto AS = llvm::make_unique<AliasSummary>(Flags, ArrayRef<ValueInfo>{});
313  auto *Aliasee = A.getBaseObject();
314  auto *AliaseeSummary = Index.getGlobalValueSummary(*Aliasee);
315  assert(AliaseeSummary && "Alias expects aliasee summary to be parsed");
316  AS->setAliasee(AliaseeSummary);
317  if (NonRenamableLocal)
318  CantBePromoted.insert(A.getGUID());
319  Index.addGlobalValueSummary(A.getName(), std::move(AS));
320 }
321 
322 // Set LiveRoot flag on entries matching the given value name.
324  if (ValueInfo VI = Index.getValueInfo(GlobalValue::getGUID(Name)))
325  for (auto &Summary : VI.getSummaryList())
326  Summary->setLive(true);
327 }
328 
330  const Module &M,
331  std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
332  ProfileSummaryInfo *PSI) {
333  assert(PSI);
334  ModuleSummaryIndex Index;
335 
336  // Identify the local values in the llvm.used and llvm.compiler.used sets,
337  // which should not be exported as they would then require renaming and
338  // promotion, but we may have opaque uses e.g. in inline asm. We collect them
339  // here because we use this information to mark functions containing inline
340  // assembly calls as not importable.
343  // First collect those in the llvm.used set.
344  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);
345  // Next collect those in the llvm.compiler.used set.
346  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ true);
347  DenseSet<GlobalValue::GUID> CantBePromoted;
348  for (auto *V : Used) {
349  if (V->hasLocalLinkage()) {
350  LocalsUsed.insert(V);
351  CantBePromoted.insert(V->getGUID());
352  }
353  }
354 
355  // Compute summaries for all functions defined in module, and save in the
356  // index.
357  for (auto &F : M) {
358  if (F.isDeclaration())
359  continue;
360 
361  BlockFrequencyInfo *BFI = nullptr;
362  std::unique_ptr<BlockFrequencyInfo> BFIPtr;
363  if (GetBFICallback)
364  BFI = GetBFICallback(F);
365  else if (F.getEntryCount().hasValue()) {
366  LoopInfo LI{DominatorTree(const_cast<Function &>(F))};
367  BranchProbabilityInfo BPI{F, LI};
368  BFIPtr = llvm::make_unique<BlockFrequencyInfo>(F, BPI, LI);
369  BFI = BFIPtr.get();
370  }
371 
372  computeFunctionSummary(Index, M, F, BFI, PSI, !LocalsUsed.empty(),
373  CantBePromoted);
374  }
375 
376  // Compute summaries for all variables defined in module, and save in the
377  // index.
378  for (const GlobalVariable &G : M.globals()) {
379  if (G.isDeclaration())
380  continue;
381  computeVariableSummary(Index, G, CantBePromoted);
382  }
383 
384  // Compute summaries for all aliases defined in module, and save in the
385  // index.
386  for (const GlobalAlias &A : M.aliases())
387  computeAliasSummary(Index, A, CantBePromoted);
388 
389  for (auto *V : LocalsUsed) {
390  auto *Summary = Index.getGlobalValueSummary(*V);
391  assert(Summary && "Missing summary for global value");
392  Summary->setNotEligibleToImport();
393  }
394 
395  // The linker doesn't know about these LLVM produced values, so we need
396  // to flag them as live in the index to ensure index-based dead value
397  // analysis treats them as live roots of the analysis.
398  setLiveRoot(Index, "llvm.used");
399  setLiveRoot(Index, "llvm.compiler.used");
400  setLiveRoot(Index, "llvm.global_ctors");
401  setLiveRoot(Index, "llvm.global_dtors");
402  setLiveRoot(Index, "llvm.global.annotations");
403 
404  if (!M.getModuleInlineAsm().empty()) {
405  // Collect the local values defined by module level asm, and set up
406  // summaries for these symbols so that they can be marked as NoRename,
407  // to prevent export of any use of them in regular IR that would require
408  // renaming within the module level asm. Note we don't need to create a
409  // summary for weak or global defs, as they don't need to be flagged as
410  // NoRename, and defs in module level asm can't be imported anyway.
411  // Also, any values used but not defined within module level asm should
412  // be listed on the llvm.used or llvm.compiler.used global and marked as
413  // referenced from there.
415  M, [&M, &Index, &CantBePromoted](StringRef Name,
417  // Symbols not marked as Weak or Global are local definitions.
418  if (Flags & (object::BasicSymbolRef::SF_Weak |
420  return;
421  GlobalValue *GV = M.getNamedValue(Name);
422  if (!GV)
423  return;
424  assert(GV->isDeclaration() && "Def in module asm already has definition");
426  /* NotEligibleToImport = */ true,
427  /* Live = */ true);
428  CantBePromoted.insert(GlobalValue::getGUID(Name));
429  // Create the appropriate summary type.
430  if (isa<Function>(GV)) {
431  std::unique_ptr<FunctionSummary> Summary =
432  llvm::make_unique<FunctionSummary>(
433  GVFlags, 0, ArrayRef<ValueInfo>{},
440  Index.addGlobalValueSummary(Name, std::move(Summary));
441  } else {
442  std::unique_ptr<GlobalVarSummary> Summary =
443  llvm::make_unique<GlobalVarSummary>(GVFlags,
445  Index.addGlobalValueSummary(Name, std::move(Summary));
446  }
447  });
448  }
449 
450  bool IsThinLTO = true;
451  if (auto *MD =
452  mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("ThinLTO")))
453  IsThinLTO = MD->getZExtValue();
454 
455  for (auto &GlobalList : Index) {
456  // Ignore entries for references that are undefined in the current module.
457  if (GlobalList.second.SummaryList.empty())
458  continue;
459 
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];
463  if (!IsThinLTO) {
464  Summary->setNotEligibleToImport();
465  continue;
466  }
467 
468  bool AllRefsCanBeExternallyReferenced =
469  llvm::all_of(Summary->refs(), [&](const ValueInfo &VI) {
470  return !CantBePromoted.count(VI.getGUID());
471  });
472  if (!AllRefsCanBeExternallyReferenced) {
473  Summary->setNotEligibleToImport();
474  continue;
475  }
476 
477  if (auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
478  bool AllCallsCanBeExternallyReferenced = llvm::all_of(
479  FuncSummary->calls(), [&](const FunctionSummary::EdgeTy &Edge) {
480  return !CantBePromoted.count(Edge.first.getGUID());
481  });
482  if (!AllCallsCanBeExternallyReferenced)
483  Summary->setNotEligibleToImport();
484  }
485  }
486 
487  return Index;
488 }
489 
490 AnalysisKey ModuleSummaryIndexAnalysis::Key;
491 
495  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
497  M,
498  [&FAM](const Function &F) {
499  return &FAM.getResult<BlockFrequencyAnalysis>(
500  *const_cast<Function *>(&F));
501  },
502  &PSI);
503 }
504 
506 INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis",
507  "Module Summary Analysis", false, true)
511  "Module Summary Analysis", false, true)
512 
514  return new ModuleSummaryIndexWrapperPass();
515 }
516 
518  : ModulePass(ID) {
520 }
521 
523  auto &PSI = *getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
524  Index = buildModuleSummaryIndex(
525  M,
526  [this](const Function &F) {
527  return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
528  *const_cast<Function *>(&F))
529  .getBFI());
530  },
531  &PSI);
532  return false;
533 }
534 
536  Index.reset();
537  return false;
538 }
539 
541  AU.setPreservesAll();
544 }
IterTy arg_end() const
Definition: CallSite.h:549
ArrayRef< InstrProfValueData > getPromotionCandidatesForInstruction(const Instruction *I, uint32_t &NumVals, uint64_t &TotalCount, uint32_t &NumCandidates)
Returns reference to array of InstrProfValueData for the given instruction I.
LinkageTypes getLinkage() const
Definition: GlobalValue.h:430
iterator_range< use_iterator > uses()
Definition: Value.h:350
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool hasName() const
Definition: Value.h:251
bool hasValue() const
Definition: Optional.h:133
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Definition: GlobalValue.h:472
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 ...
Definition: Module.cpp:513
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. ...
Definition: Module.h:63
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:480
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.
Definition: DenseSet.h:221
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...
Definition: MapVector.h:38
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:818
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.
Definition: Value.cpp:218
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
bool hasSection() const
Definition: GlobalValue.h:256
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:687
Legacy analysis pass which computes BlockFrequencyInfo.
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
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...
#define F(x, y, z)
Definition: MD5.cpp:55
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:142
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)...
Definition: APInt.h:33
module summary analysis
Optional< uint64_t > getEntryCount() const
Get the entry count for this function.
Definition: Function.cpp:1325
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...
Definition: Dominators.h:134
INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass,"module-summary-analysis","Module Summary Analysis", false, true) INITIALIZE_PASS_END(ModuleSummaryIndexWrapperPass
const char * Name
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)
Interface to identify indirect call promotion candidates.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
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.
#define A
Definition: LargeTest.cpp:12
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:372
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...
Definition: STLExtras.h:825
const GlobalObject * getBaseObject() const
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
op_range operands()
Definition: User.h:222
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:476
LLVM_NODISCARD bool empty() const
Definition: SmallPtrSet.h:92
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.
Definition: MapVector.h:52
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.
IterTy arg_begin() const
Definition: CallSite.h:545
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.
Definition: SetVector.h:67
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:423
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
const DataFlowGraph & G
Definition: RDFGraph.cpp:206
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:382
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...
Definition: Function.h:167
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
Definition: FlagsTest.cpp:8
Basic Alias true
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...
Definition: Globals.cpp:200
Establish a view to a call site for examination.
Definition: CallSite.h:687
module summary Module Summary Analysis
#define I(x, y, z)
Definition: MD5.cpp:58
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:235
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
Rename collisions when linking (static functions).
Definition: GlobalValue.h:56
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:91
bool hasLocalLinkage() const
Definition: GlobalValue.h:416
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ModulePass * createModuleSummaryIndexWrapperPass()
A vector that has set insertion semantics.
Definition: SetVector.h:41
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.
Definition: StringRef.h:49
A single uniqued string.
Definition: Metadata.h:602
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...
Definition: PassManager.h:70
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.
Definition: CallSite.h:140
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:946