LLVM  7.0.0svn
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/ArrayRef.h"
17 #include "llvm/ADT/DenseSet.h"
18 #include "llvm/ADT/MapVector.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/SetVector.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringRef.h"
27 #include "llvm/Analysis/LoopInfo.h"
30 #include "llvm/IR/Attributes.h"
31 #include "llvm/IR/BasicBlock.h"
32 #include "llvm/IR/CallSite.h"
33 #include "llvm/IR/Constant.h"
34 #include "llvm/IR/Constants.h"
35 #include "llvm/IR/Dominators.h"
36 #include "llvm/IR/Function.h"
37 #include "llvm/IR/GlobalAlias.h"
38 #include "llvm/IR/GlobalValue.h"
39 #include "llvm/IR/GlobalVariable.h"
40 #include "llvm/IR/Instructions.h"
41 #include "llvm/IR/IntrinsicInst.h"
42 #include "llvm/IR/Intrinsics.h"
43 #include "llvm/IR/Metadata.h"
44 #include "llvm/IR/Module.h"
46 #include "llvm/IR/Use.h"
47 #include "llvm/IR/User.h"
50 #include "llvm/Pass.h"
51 #include "llvm/Support/Casting.h"
53 #include <algorithm>
54 #include <cassert>
55 #include <cstdint>
56 #include <vector>
57 
58 using namespace llvm;
59 
60 #define DEBUG_TYPE "module-summary-analysis"
61 
62 // Option to force edges cold which will block importing when the
63 // -import-cold-multiplier is set to 0. Useful for debugging.
67  "force-summary-edges-cold", cl::Hidden, cl::location(ForceSummaryEdgesCold),
68  cl::desc("Force all edges in the function summary to cold"),
71  "all-non-critical", "All non-critical edges."),
72  clEnumValN(FunctionSummary::FSHT_All, "all", "All edges.")));
73 
74 // Walk through the operands of a given User via worklist iteration and populate
75 // the set of GlobalValue references encountered. Invoked either on an
76 // Instruction or a GlobalVariable (which walks its initializer).
77 static void findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
78  SetVector<ValueInfo> &RefEdges,
81  Worklist.push_back(CurUser);
82 
83  while (!Worklist.empty()) {
84  const User *U = Worklist.pop_back_val();
85 
86  if (!Visited.insert(U).second)
87  continue;
88 
89  ImmutableCallSite CS(U);
90 
91  for (const auto &OI : U->operands()) {
92  const User *Operand = dyn_cast<User>(OI);
93  if (!Operand)
94  continue;
95  if (isa<BlockAddress>(Operand))
96  continue;
97  if (auto *GV = dyn_cast<GlobalValue>(Operand)) {
98  // We have a reference to a global value. This should be added to
99  // the reference set unless it is a callee. Callees are handled
100  // specially by WriteFunction and are added to a separate list.
101  if (!(CS && CS.isCallee(&OI)))
102  RefEdges.insert(Index.getOrInsertValueInfo(GV));
103  continue;
104  }
105  Worklist.push_back(Operand);
106  }
107  }
108 }
109 
111  ProfileSummaryInfo *PSI) {
112  if (!PSI)
114  if (PSI->isHotCount(ProfileCount))
116  if (PSI->isColdCount(ProfileCount))
119 }
120 
121 static bool isNonRenamableLocal(const GlobalValue &GV) {
122  return GV.hasSection() && GV.hasLocalLinkage();
123 }
124 
125 /// Determine whether this call has all constant integer arguments (excluding
126 /// "this") and summarize it to VCalls or ConstVCalls as appropriate.
130  std::vector<uint64_t> Args;
131  // Start from the second argument to skip the "this" pointer.
132  for (auto &Arg : make_range(Call.CS.arg_begin() + 1, Call.CS.arg_end())) {
133  auto *CI = dyn_cast<ConstantInt>(Arg);
134  if (!CI || CI->getBitWidth() > 64) {
135  VCalls.insert({Guid, Call.Offset});
136  return;
137  }
138  Args.push_back(CI->getZExtValue());
139  }
140  ConstVCalls.insert({{Guid, Call.Offset}, std::move(Args)});
141 }
142 
143 /// If this intrinsic call requires that we add information to the function
144 /// summary, do so via the non-constant reference arguments.
146  const CallInst *CI, SetVector<GlobalValue::GUID> &TypeTests,
147  SetVector<FunctionSummary::VFuncId> &TypeTestAssumeVCalls,
148  SetVector<FunctionSummary::VFuncId> &TypeCheckedLoadVCalls,
149  SetVector<FunctionSummary::ConstVCall> &TypeTestAssumeConstVCalls,
150  SetVector<FunctionSummary::ConstVCall> &TypeCheckedLoadConstVCalls) {
151  switch (CI->getCalledFunction()->getIntrinsicID()) {
152  case Intrinsic::type_test: {
153  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(1));
154  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
155  if (!TypeId)
156  break;
157  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
158 
159  // Produce a summary from type.test intrinsics. We only summarize type.test
160  // intrinsics that are used other than by an llvm.assume intrinsic.
161  // Intrinsics that are assumed are relevant only to the devirtualization
162  // pass, not the type test lowering pass.
163  bool HasNonAssumeUses = llvm::any_of(CI->uses(), [](const Use &CIU) {
164  auto *AssumeCI = dyn_cast<CallInst>(CIU.getUser());
165  if (!AssumeCI)
166  return true;
167  Function *F = AssumeCI->getCalledFunction();
168  return !F || F->getIntrinsicID() != Intrinsic::assume;
169  });
170  if (HasNonAssumeUses)
171  TypeTests.insert(Guid);
172 
173  SmallVector<DevirtCallSite, 4> DevirtCalls;
175  findDevirtualizableCallsForTypeTest(DevirtCalls, Assumes, CI);
176  for (auto &Call : DevirtCalls)
177  addVCallToSet(Call, Guid, TypeTestAssumeVCalls,
178  TypeTestAssumeConstVCalls);
179 
180  break;
181  }
182 
183  case Intrinsic::type_checked_load: {
184  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(2));
185  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
186  if (!TypeId)
187  break;
188  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
189 
190  SmallVector<DevirtCallSite, 4> DevirtCalls;
193  bool HasNonCallUses = false;
194  findDevirtualizableCallsForTypeCheckedLoad(DevirtCalls, LoadedPtrs, Preds,
195  HasNonCallUses, CI);
196  // Any non-call uses of the result of llvm.type.checked.load will
197  // prevent us from optimizing away the llvm.type.test.
198  if (HasNonCallUses)
199  TypeTests.insert(Guid);
200  for (auto &Call : DevirtCalls)
201  addVCallToSet(Call, Guid, TypeCheckedLoadVCalls,
202  TypeCheckedLoadConstVCalls);
203 
204  break;
205  }
206  default:
207  break;
208  }
209 }
210 
211 static void
213  const Function &F, BlockFrequencyInfo *BFI,
214  ProfileSummaryInfo *PSI, bool HasLocalsInUsedOrAsm,
215  DenseSet<GlobalValue::GUID> &CantBePromoted) {
216  // Summary not currently supported for anonymous functions, they should
217  // have been named.
218  assert(F.hasName());
219 
220  unsigned NumInsts = 0;
221  // Map from callee ValueId to profile count. Used to accumulate profile
222  // counts for all static calls to a given callee.
223  MapVector<ValueInfo, CalleeInfo> CallGraphEdges;
224  SetVector<ValueInfo> RefEdges;
226  SetVector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
227  TypeCheckedLoadVCalls;
228  SetVector<FunctionSummary::ConstVCall> TypeTestAssumeConstVCalls,
229  TypeCheckedLoadConstVCalls;
230  ICallPromotionAnalysis ICallAnalysis;
232 
233  // Add personality function, prefix data and prologue data to function's ref
234  // list.
235  findRefEdges(Index, &F, RefEdges, Visited);
236 
237  bool HasInlineAsmMaybeReferencingInternal = false;
238  for (const BasicBlock &BB : F)
239  for (const Instruction &I : BB) {
240  if (isa<DbgInfoIntrinsic>(I))
241  continue;
242  ++NumInsts;
243  findRefEdges(Index, &I, RefEdges, Visited);
244  auto CS = ImmutableCallSite(&I);
245  if (!CS)
246  continue;
247 
248  const auto *CI = dyn_cast<CallInst>(&I);
249  // Since we don't know exactly which local values are referenced in inline
250  // assembly, conservatively mark the function as possibly referencing
251  // a local value from inline assembly to ensure we don't export a
252  // reference (which would require renaming and promotion of the
253  // referenced value).
254  if (HasLocalsInUsedOrAsm && CI && CI->isInlineAsm())
255  HasInlineAsmMaybeReferencingInternal = true;
256 
257  auto *CalledValue = CS.getCalledValue();
258  auto *CalledFunction = CS.getCalledFunction();
259  if (CalledValue && !CalledFunction) {
260  CalledValue = CalledValue->stripPointerCastsNoFollowAliases();
261  // Stripping pointer casts can reveal a called function.
262  CalledFunction = dyn_cast<Function>(CalledValue);
263  }
264  // Check if this is an alias to a function. If so, get the
265  // called aliasee for the checks below.
266  if (auto *GA = dyn_cast<GlobalAlias>(CalledValue)) {
267  assert(!CalledFunction && "Expected null called function in callsite for alias");
268  CalledFunction = dyn_cast<Function>(GA->getBaseObject());
269  }
270  // Check if this is a direct call to a known function or a known
271  // intrinsic, or an indirect call with profile data.
272  if (CalledFunction) {
273  if (CI && CalledFunction->isIntrinsic()) {
275  CI, TypeTests, TypeTestAssumeVCalls, TypeCheckedLoadVCalls,
276  TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls);
277  continue;
278  }
279  // We should have named any anonymous globals
280  assert(CalledFunction->hasName());
281  auto ScaledCount = PSI->getProfileCount(&I, BFI);
282  auto Hotness = ScaledCount ? getHotness(ScaledCount.getValue(), PSI)
286 
287  // Use the original CalledValue, in case it was an alias. We want
288  // to record the call edge to the alias in that case. Eventually
289  // an alias summary will be created to associate the alias and
290  // aliasee.
291  auto &ValueInfo = CallGraphEdges[Index.getOrInsertValueInfo(
292  cast<GlobalValue>(CalledValue))];
293  ValueInfo.updateHotness(Hotness);
294  // Add the relative block frequency to CalleeInfo if there is no profile
295  // information.
296  if (BFI != nullptr && Hotness == CalleeInfo::HotnessType::Unknown) {
297  uint64_t BBFreq = BFI->getBlockFreq(&BB).getFrequency();
298  uint64_t EntryFreq = BFI->getEntryFreq();
299  ValueInfo.updateRelBlockFreq(BBFreq, EntryFreq);
300  }
301  } else {
302  // Skip inline assembly calls.
303  if (CI && CI->isInlineAsm())
304  continue;
305  // Skip direct calls.
306  if (!CalledValue || isa<Constant>(CalledValue))
307  continue;
308 
309  // Check if the instruction has a callees metadata. If so, add callees
310  // to CallGraphEdges to reflect the references from the metadata, and
311  // to enable importing for subsequent indirect call promotion and
312  // inlining.
313  if (auto *MD = I.getMetadata(LLVMContext::MD_callees)) {
314  for (auto &Op : MD->operands()) {
315  Function *Callee = mdconst::extract_or_null<Function>(Op);
316  if (Callee)
317  CallGraphEdges[Index.getOrInsertValueInfo(Callee)];
318  }
319  }
320 
321  uint32_t NumVals, NumCandidates;
322  uint64_t TotalCount;
323  auto CandidateProfileData =
325  &I, NumVals, TotalCount, NumCandidates);
326  for (auto &Candidate : CandidateProfileData)
327  CallGraphEdges[Index.getOrInsertValueInfo(Candidate.Value)]
328  .updateHotness(getHotness(Candidate.Count, PSI));
329  }
330  }
331 
332  // Explicit add hot edges to enforce importing for designated GUIDs for
333  // sample PGO, to enable the same inlines as the profiled optimized binary.
334  for (auto &I : F.getImportGUIDs())
335  CallGraphEdges[Index.getOrInsertValueInfo(I)].updateHotness(
339 
340  bool NonRenamableLocal = isNonRenamableLocal(F);
341  bool NotEligibleForImport =
342  NonRenamableLocal || HasInlineAsmMaybeReferencingInternal ||
343  // Inliner doesn't handle variadic functions.
344  // FIXME: refactor this to use the same code that inliner is using.
345  F.isVarArg() ||
346  // Don't try to import functions with noinline attribute.
347  F.getAttributes().hasFnAttribute(Attribute::NoInline);
348  GlobalValueSummary::GVFlags Flags(F.getLinkage(), NotEligibleForImport,
349  /* Live = */ false, F.isDSOLocal());
350  FunctionSummary::FFlags FunFlags{
351  F.hasFnAttribute(Attribute::ReadNone),
352  F.hasFnAttribute(Attribute::ReadOnly),
353  F.hasFnAttribute(Attribute::NoRecurse),
354  F.returnDoesNotAlias(),
355  };
356  auto FuncSummary = llvm::make_unique<FunctionSummary>(
357  Flags, NumInsts, FunFlags, RefEdges.takeVector(),
358  CallGraphEdges.takeVector(), TypeTests.takeVector(),
359  TypeTestAssumeVCalls.takeVector(), TypeCheckedLoadVCalls.takeVector(),
360  TypeTestAssumeConstVCalls.takeVector(),
361  TypeCheckedLoadConstVCalls.takeVector());
362  if (NonRenamableLocal)
363  CantBePromoted.insert(F.getGUID());
364  Index.addGlobalValueSummary(F.getName(), std::move(FuncSummary));
365 }
366 
367 static void
369  DenseSet<GlobalValue::GUID> &CantBePromoted) {
370  SetVector<ValueInfo> RefEdges;
372  findRefEdges(Index, &V, RefEdges, Visited);
373  bool NonRenamableLocal = isNonRenamableLocal(V);
374  GlobalValueSummary::GVFlags Flags(V.getLinkage(), NonRenamableLocal,
375  /* Live = */ false, V.isDSOLocal());
376  auto GVarSummary =
377  llvm::make_unique<GlobalVarSummary>(Flags, RefEdges.takeVector());
378  if (NonRenamableLocal)
379  CantBePromoted.insert(V.getGUID());
380  Index.addGlobalValueSummary(V.getName(), std::move(GVarSummary));
381 }
382 
383 static void
385  DenseSet<GlobalValue::GUID> &CantBePromoted) {
386  bool NonRenamableLocal = isNonRenamableLocal(A);
387  GlobalValueSummary::GVFlags Flags(A.getLinkage(), NonRenamableLocal,
388  /* Live = */ false, A.isDSOLocal());
389  auto AS = llvm::make_unique<AliasSummary>(Flags);
390  auto *Aliasee = A.getBaseObject();
391  auto *AliaseeSummary = Index.getGlobalValueSummary(*Aliasee);
392  assert(AliaseeSummary && "Alias expects aliasee summary to be parsed");
393  AS->setAliasee(AliaseeSummary);
394  if (NonRenamableLocal)
395  CantBePromoted.insert(A.getGUID());
396  Index.addGlobalValueSummary(A.getName(), std::move(AS));
397 }
398 
399 // Set LiveRoot flag on entries matching the given value name.
401  if (ValueInfo VI = Index.getValueInfo(GlobalValue::getGUID(Name)))
402  for (auto &Summary : VI.getSummaryList())
403  Summary->setLive(true);
404 }
405 
407  const Module &M,
408  std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
409  ProfileSummaryInfo *PSI) {
410  assert(PSI);
411  ModuleSummaryIndex Index(/*IsPerformingAnalysis=*/true);
412 
413  // Identify the local values in the llvm.used and llvm.compiler.used sets,
414  // which should not be exported as they would then require renaming and
415  // promotion, but we may have opaque uses e.g. in inline asm. We collect them
416  // here because we use this information to mark functions containing inline
417  // assembly calls as not importable.
420  // First collect those in the llvm.used set.
421  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);
422  // Next collect those in the llvm.compiler.used set.
423  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ true);
424  DenseSet<GlobalValue::GUID> CantBePromoted;
425  for (auto *V : Used) {
426  if (V->hasLocalLinkage()) {
427  LocalsUsed.insert(V);
428  CantBePromoted.insert(V->getGUID());
429  }
430  }
431 
432  bool HasLocalInlineAsmSymbol = false;
433  if (!M.getModuleInlineAsm().empty()) {
434  // Collect the local values defined by module level asm, and set up
435  // summaries for these symbols so that they can be marked as NoRename,
436  // to prevent export of any use of them in regular IR that would require
437  // renaming within the module level asm. Note we don't need to create a
438  // summary for weak or global defs, as they don't need to be flagged as
439  // NoRename, and defs in module level asm can't be imported anyway.
440  // Also, any values used but not defined within module level asm should
441  // be listed on the llvm.used or llvm.compiler.used global and marked as
442  // referenced from there.
445  // Symbols not marked as Weak or Global are local definitions.
446  if (Flags & (object::BasicSymbolRef::SF_Weak |
448  return;
449  HasLocalInlineAsmSymbol = true;
450  GlobalValue *GV = M.getNamedValue(Name);
451  if (!GV)
452  return;
453  assert(GV->isDeclaration() && "Def in module asm already has definition");
455  /* NotEligibleToImport = */ true,
456  /* Live = */ true,
457  /* Local */ GV->isDSOLocal());
458  CantBePromoted.insert(GlobalValue::getGUID(Name));
459  // Create the appropriate summary type.
460  if (Function *F = dyn_cast<Function>(GV)) {
461  std::unique_ptr<FunctionSummary> Summary =
462  llvm::make_unique<FunctionSummary>(
463  GVFlags, 0,
465  F->hasFnAttribute(Attribute::ReadNone),
466  F->hasFnAttribute(Attribute::ReadOnly),
467  F->hasFnAttribute(Attribute::NoRecurse),
468  F->returnDoesNotAlias()},
475  Index.addGlobalValueSummary(Name, std::move(Summary));
476  } else {
477  std::unique_ptr<GlobalVarSummary> Summary =
478  llvm::make_unique<GlobalVarSummary>(GVFlags,
480  Index.addGlobalValueSummary(Name, std::move(Summary));
481  }
482  });
483  }
484 
485  // Compute summaries for all functions defined in module, and save in the
486  // index.
487  for (auto &F : M) {
488  if (F.isDeclaration())
489  continue;
490 
491  BlockFrequencyInfo *BFI = nullptr;
492  std::unique_ptr<BlockFrequencyInfo> BFIPtr;
493  if (GetBFICallback)
494  BFI = GetBFICallback(F);
495  else if (F.hasProfileData()) {
496  LoopInfo LI{DominatorTree(const_cast<Function &>(F))};
497  BranchProbabilityInfo BPI{F, LI};
498  BFIPtr = llvm::make_unique<BlockFrequencyInfo>(F, BPI, LI);
499  BFI = BFIPtr.get();
500  }
501 
502  computeFunctionSummary(Index, M, F, BFI, PSI,
503  !LocalsUsed.empty() || HasLocalInlineAsmSymbol,
504  CantBePromoted);
505  }
506 
507  // Compute summaries for all variables defined in module, and save in the
508  // index.
509  for (const GlobalVariable &G : M.globals()) {
510  if (G.isDeclaration())
511  continue;
512  computeVariableSummary(Index, G, CantBePromoted);
513  }
514 
515  // Compute summaries for all aliases defined in module, and save in the
516  // index.
517  for (const GlobalAlias &A : M.aliases())
518  computeAliasSummary(Index, A, CantBePromoted);
519 
520  for (auto *V : LocalsUsed) {
521  auto *Summary = Index.getGlobalValueSummary(*V);
522  assert(Summary && "Missing summary for global value");
523  Summary->setNotEligibleToImport();
524  }
525 
526  // The linker doesn't know about these LLVM produced values, so we need
527  // to flag them as live in the index to ensure index-based dead value
528  // analysis treats them as live roots of the analysis.
529  setLiveRoot(Index, "llvm.used");
530  setLiveRoot(Index, "llvm.compiler.used");
531  setLiveRoot(Index, "llvm.global_ctors");
532  setLiveRoot(Index, "llvm.global_dtors");
533  setLiveRoot(Index, "llvm.global.annotations");
534 
535  bool IsThinLTO = true;
536  if (auto *MD =
537  mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("ThinLTO")))
538  IsThinLTO = MD->getZExtValue();
539 
540  for (auto &GlobalList : Index) {
541  // Ignore entries for references that are undefined in the current module.
542  if (GlobalList.second.SummaryList.empty())
543  continue;
544 
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];
548  if (!IsThinLTO) {
549  Summary->setNotEligibleToImport();
550  continue;
551  }
552 
553  bool AllRefsCanBeExternallyReferenced =
554  llvm::all_of(Summary->refs(), [&](const ValueInfo &VI) {
555  return !CantBePromoted.count(VI.getGUID());
556  });
557  if (!AllRefsCanBeExternallyReferenced) {
558  Summary->setNotEligibleToImport();
559  continue;
560  }
561 
562  if (auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
563  bool AllCallsCanBeExternallyReferenced = llvm::all_of(
564  FuncSummary->calls(), [&](const FunctionSummary::EdgeTy &Edge) {
565  return !CantBePromoted.count(Edge.first.getGUID());
566  });
567  if (!AllCallsCanBeExternallyReferenced)
568  Summary->setNotEligibleToImport();
569  }
570  }
571 
572  return Index;
573 }
574 
575 AnalysisKey ModuleSummaryIndexAnalysis::Key;
576 
580  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
582  M,
583  [&FAM](const Function &F) {
584  return &FAM.getResult<BlockFrequencyAnalysis>(
585  *const_cast<Function *>(&F));
586  },
587  &PSI);
588 }
589 
591 
592 INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis",
593  "Module Summary Analysis", false, true)
597  "Module Summary Analysis", false, true)
598 
600  return new ModuleSummaryIndexWrapperPass();
601 }
602 
604  : ModulePass(ID) {
606 }
607 
609  auto &PSI = *getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
610  Index = buildModuleSummaryIndex(
611  M,
612  [this](const Function &F) {
613  return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
614  *const_cast<Function *>(&F))
615  .getBFI());
616  },
617  &PSI);
618  return false;
619 }
620 
622  Index.reset();
623  return false;
624 }
625 
627  AU.setPreservesAll();
630 }
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.
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()
Definition: Value.h:354
bool hasLocalLinkage() const
Definition: GlobalValue.h:435
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.
Definition: PassManager.h:687
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Definition: GlobalValue.h:492
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
ValueInfo getValueInfo(GlobalValue::GUID GUID) const
Return a ValueInfo for GUID if it exists, otherwise return ValueInfo().
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
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.
Definition: DenseSet.h:221
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&#39;s calling convention.
This file contains the declarations for metadata subclasses.
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.
Definition: Function.h:307
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:908
Optional< uint64_t > getProfileCount(const Instruction *CallInst, BlockFrequencyInfo *BFI)
Returns the profile count for CallInst.
F(f)
void initializeModuleSummaryIndexWrapperPassPass(PassRegistry &)
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 ...
bool hasSection() const
Definition: GlobalValue.h:269
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
bool isDSOLocal() const
Definition: GlobalValue.h:279
static AnalysisKey * ID()
Returns an opaque, unique ID for this analysis type.
Definition: PassManager.h:398
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
IterTy arg_end() const
Definition: CallSite.h:575
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.
Definition: SetVector.h:142
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. ...
Definition: Module.cpp:112
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
module summary analysis
LinkageTypes getLinkage() const
Definition: GlobalValue.h:450
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:142
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)
Interface to identify indirect call promotion candidates.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
bool hasName() const
Definition: Value.h:251
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.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:630
LLVM_NODISCARD bool empty() const
Definition: SmallPtrSet.h:92
bool returnDoesNotAlias() const
Determine if the parameter or return value is marked with NoAlias attribute.
Definition: Function.h:572
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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:371
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:915
INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis", "Module Summary Analysis", false, true) INITIALIZE_PASS_END(ModuleSummaryIndexWrapperPass
op_range operands()
Definition: User.h:238
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:496
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...
const AMDGPUAS & AS
static void computeVariableSummary(ModuleSummaryIndex &Index, const GlobalVariable &V, DenseSet< GlobalValue::GUID > &CantBePromoted)
Class to represent profile counts.
Definition: Function.h:247
VectorType takeVector()
Clear the MapVector and return the underlying vector.
Definition: MapVector.h:56
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
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)
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:529
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:418
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
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...
IterTy arg_begin() const
Definition: CallSite.h:571
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:862
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)
const DataFlowGraph & G
Definition: RDFGraph.cpp:211
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:383
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:180
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.
Definition: GlobalValue.h:500
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID)
Return a ValueInfo for GUID.
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:605
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...
Basic Alias true
Analysis providing branch probability information.
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:61
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:224
Establish a view to a call site for examination.
Definition: CallSite.h:713
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:225
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
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.
Definition: Module.h:246
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:201
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.
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)
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 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.
Definition: Function.h:294
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:70
LocationClass< Ty > location(Ty &L)
Definition: CommandLine.h:426
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...
Definition: PassManager.h:946
bool isCallee(Value::const_user_iterator UI) const
Determine whether the passed iterator points to the callee operand&#39;s Use.
Definition: CallSite.h:143