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"
52 #include <algorithm>
53 #include <cassert>
54 #include <cstdint>
55 #include <vector>
56 
57 using namespace llvm;
58 
59 #define DEBUG_TYPE "module-summary-analysis"
60 
61 // Walk through the operands of a given User via worklist iteration and populate
62 // the set of GlobalValue references encountered. Invoked either on an
63 // Instruction or a GlobalVariable (which walks its initializer).
64 static void findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
65  SetVector<ValueInfo> &RefEdges,
68  Worklist.push_back(CurUser);
69 
70  while (!Worklist.empty()) {
71  const User *U = Worklist.pop_back_val();
72 
73  if (!Visited.insert(U).second)
74  continue;
75 
76  ImmutableCallSite CS(U);
77 
78  for (const auto &OI : U->operands()) {
79  const User *Operand = dyn_cast<User>(OI);
80  if (!Operand)
81  continue;
82  if (isa<BlockAddress>(Operand))
83  continue;
84  if (auto *GV = dyn_cast<GlobalValue>(Operand)) {
85  // We have a reference to a global value. This should be added to
86  // the reference set unless it is a callee. Callees are handled
87  // specially by WriteFunction and are added to a separate list.
88  if (!(CS && CS.isCallee(&OI)))
89  RefEdges.insert(Index.getOrInsertValueInfo(GV));
90  continue;
91  }
92  Worklist.push_back(Operand);
93  }
94  }
95 }
96 
98  ProfileSummaryInfo *PSI) {
99  if (!PSI)
101  if (PSI->isHotCount(ProfileCount))
103  if (PSI->isColdCount(ProfileCount))
106 }
107 
108 static bool isNonRenamableLocal(const GlobalValue &GV) {
109  return GV.hasSection() && GV.hasLocalLinkage();
110 }
111 
112 /// Determine whether this call has all constant integer arguments (excluding
113 /// "this") and summarize it to VCalls or ConstVCalls as appropriate.
117  std::vector<uint64_t> Args;
118  // Start from the second argument to skip the "this" pointer.
119  for (auto &Arg : make_range(Call.CS.arg_begin() + 1, Call.CS.arg_end())) {
120  auto *CI = dyn_cast<ConstantInt>(Arg);
121  if (!CI || CI->getBitWidth() > 64) {
122  VCalls.insert({Guid, Call.Offset});
123  return;
124  }
125  Args.push_back(CI->getZExtValue());
126  }
127  ConstVCalls.insert({{Guid, Call.Offset}, std::move(Args)});
128 }
129 
130 /// If this intrinsic call requires that we add information to the function
131 /// summary, do so via the non-constant reference arguments.
133  const CallInst *CI, SetVector<GlobalValue::GUID> &TypeTests,
134  SetVector<FunctionSummary::VFuncId> &TypeTestAssumeVCalls,
135  SetVector<FunctionSummary::VFuncId> &TypeCheckedLoadVCalls,
136  SetVector<FunctionSummary::ConstVCall> &TypeTestAssumeConstVCalls,
137  SetVector<FunctionSummary::ConstVCall> &TypeCheckedLoadConstVCalls) {
138  switch (CI->getCalledFunction()->getIntrinsicID()) {
139  case Intrinsic::type_test: {
140  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(1));
141  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
142  if (!TypeId)
143  break;
144  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
145 
146  // Produce a summary from type.test intrinsics. We only summarize type.test
147  // intrinsics that are used other than by an llvm.assume intrinsic.
148  // Intrinsics that are assumed are relevant only to the devirtualization
149  // pass, not the type test lowering pass.
150  bool HasNonAssumeUses = llvm::any_of(CI->uses(), [](const Use &CIU) {
151  auto *AssumeCI = dyn_cast<CallInst>(CIU.getUser());
152  if (!AssumeCI)
153  return true;
154  Function *F = AssumeCI->getCalledFunction();
155  return !F || F->getIntrinsicID() != Intrinsic::assume;
156  });
157  if (HasNonAssumeUses)
158  TypeTests.insert(Guid);
159 
160  SmallVector<DevirtCallSite, 4> DevirtCalls;
162  findDevirtualizableCallsForTypeTest(DevirtCalls, Assumes, CI);
163  for (auto &Call : DevirtCalls)
164  addVCallToSet(Call, Guid, TypeTestAssumeVCalls,
165  TypeTestAssumeConstVCalls);
166 
167  break;
168  }
169 
170  case Intrinsic::type_checked_load: {
171  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(2));
172  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
173  if (!TypeId)
174  break;
175  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
176 
177  SmallVector<DevirtCallSite, 4> DevirtCalls;
180  bool HasNonCallUses = false;
181  findDevirtualizableCallsForTypeCheckedLoad(DevirtCalls, LoadedPtrs, Preds,
182  HasNonCallUses, CI);
183  // Any non-call uses of the result of llvm.type.checked.load will
184  // prevent us from optimizing away the llvm.type.test.
185  if (HasNonCallUses)
186  TypeTests.insert(Guid);
187  for (auto &Call : DevirtCalls)
188  addVCallToSet(Call, Guid, TypeCheckedLoadVCalls,
189  TypeCheckedLoadConstVCalls);
190 
191  break;
192  }
193  default:
194  break;
195  }
196 }
197 
198 static void
200  const Function &F, BlockFrequencyInfo *BFI,
201  ProfileSummaryInfo *PSI, bool HasLocalsInUsedOrAsm,
202  DenseSet<GlobalValue::GUID> &CantBePromoted) {
203  // Summary not currently supported for anonymous functions, they should
204  // have been named.
205  assert(F.hasName());
206 
207  unsigned NumInsts = 0;
208  // Map from callee ValueId to profile count. Used to accumulate profile
209  // counts for all static calls to a given callee.
210  MapVector<ValueInfo, CalleeInfo> CallGraphEdges;
211  SetVector<ValueInfo> RefEdges;
213  SetVector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
214  TypeCheckedLoadVCalls;
215  SetVector<FunctionSummary::ConstVCall> TypeTestAssumeConstVCalls,
216  TypeCheckedLoadConstVCalls;
217  ICallPromotionAnalysis ICallAnalysis;
219 
220  // Add personality function, prefix data and prologue data to function's ref
221  // list.
222  findRefEdges(Index, &F, RefEdges, Visited);
223 
224  bool HasInlineAsmMaybeReferencingInternal = false;
225  for (const BasicBlock &BB : F)
226  for (const Instruction &I : BB) {
227  if (isa<DbgInfoIntrinsic>(I))
228  continue;
229  ++NumInsts;
230  findRefEdges(Index, &I, RefEdges, Visited);
231  auto CS = ImmutableCallSite(&I);
232  if (!CS)
233  continue;
234 
235  const auto *CI = dyn_cast<CallInst>(&I);
236  // Since we don't know exactly which local values are referenced in inline
237  // assembly, conservatively mark the function as possibly referencing
238  // a local value from inline assembly to ensure we don't export a
239  // reference (which would require renaming and promotion of the
240  // referenced value).
241  if (HasLocalsInUsedOrAsm && CI && CI->isInlineAsm())
242  HasInlineAsmMaybeReferencingInternal = true;
243 
244  auto *CalledValue = CS.getCalledValue();
245  auto *CalledFunction = CS.getCalledFunction();
246  if (CalledValue && !CalledFunction) {
247  CalledValue = CalledValue->stripPointerCastsNoFollowAliases();
248  // Stripping pointer casts can reveal a called function.
249  CalledFunction = dyn_cast<Function>(CalledValue);
250  }
251  // Check if this is an alias to a function. If so, get the
252  // called aliasee for the checks below.
253  if (auto *GA = dyn_cast<GlobalAlias>(CalledValue)) {
254  assert(!CalledFunction && "Expected null called function in callsite for alias");
255  CalledFunction = dyn_cast<Function>(GA->getBaseObject());
256  }
257  // Check if this is a direct call to a known function or a known
258  // intrinsic, or an indirect call with profile data.
259  if (CalledFunction) {
260  if (CI && CalledFunction->isIntrinsic()) {
262  CI, TypeTests, TypeTestAssumeVCalls, TypeCheckedLoadVCalls,
263  TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls);
264  continue;
265  }
266  // We should have named any anonymous globals
267  assert(CalledFunction->hasName());
268  auto ScaledCount = PSI->getProfileCount(&I, BFI);
269  auto Hotness = ScaledCount ? getHotness(ScaledCount.getValue(), PSI)
271 
272  // Use the original CalledValue, in case it was an alias. We want
273  // to record the call edge to the alias in that case. Eventually
274  // an alias summary will be created to associate the alias and
275  // aliasee.
276  auto &ValueInfo = CallGraphEdges[Index.getOrInsertValueInfo(
277  cast<GlobalValue>(CalledValue))];
278  ValueInfo.updateHotness(Hotness);
279  // Add the relative block frequency to CalleeInfo if there is no profile
280  // information.
281  if (BFI != nullptr && Hotness == CalleeInfo::HotnessType::Unknown) {
282  uint64_t BBFreq = BFI->getBlockFreq(&BB).getFrequency();
283  uint64_t EntryFreq = BFI->getEntryFreq();
284  ValueInfo.updateRelBlockFreq(BBFreq, EntryFreq);
285  }
286  } else {
287  // Skip inline assembly calls.
288  if (CI && CI->isInlineAsm())
289  continue;
290  // Skip direct calls.
291  if (!CalledValue || isa<Constant>(CalledValue))
292  continue;
293 
294  uint32_t NumVals, NumCandidates;
295  uint64_t TotalCount;
296  auto CandidateProfileData =
298  &I, NumVals, TotalCount, NumCandidates);
299  for (auto &Candidate : CandidateProfileData)
300  CallGraphEdges[Index.getOrInsertValueInfo(Candidate.Value)]
301  .updateHotness(getHotness(Candidate.Count, PSI));
302  }
303  }
304 
305  // Explicit add hot edges to enforce importing for designated GUIDs for
306  // sample PGO, to enable the same inlines as the profiled optimized binary.
307  for (auto &I : F.getImportGUIDs())
308  CallGraphEdges[Index.getOrInsertValueInfo(I)].updateHotness(
310 
311  bool NonRenamableLocal = isNonRenamableLocal(F);
312  bool NotEligibleForImport =
313  NonRenamableLocal || HasInlineAsmMaybeReferencingInternal ||
314  // Inliner doesn't handle variadic functions.
315  // FIXME: refactor this to use the same code that inliner is using.
316  F.isVarArg() ||
317  // Don't try to import functions with noinline attribute.
318  F.getAttributes().hasFnAttribute(Attribute::NoInline);
319  GlobalValueSummary::GVFlags Flags(F.getLinkage(), NotEligibleForImport,
320  /* Live = */ false, F.isDSOLocal());
321  FunctionSummary::FFlags FunFlags{
322  F.hasFnAttribute(Attribute::ReadNone),
323  F.hasFnAttribute(Attribute::ReadOnly),
324  F.hasFnAttribute(Attribute::NoRecurse),
325  F.returnDoesNotAlias(),
326  };
327  auto FuncSummary = llvm::make_unique<FunctionSummary>(
328  Flags, NumInsts, FunFlags, RefEdges.takeVector(),
329  CallGraphEdges.takeVector(), TypeTests.takeVector(),
330  TypeTestAssumeVCalls.takeVector(), TypeCheckedLoadVCalls.takeVector(),
331  TypeTestAssumeConstVCalls.takeVector(),
332  TypeCheckedLoadConstVCalls.takeVector());
333  if (NonRenamableLocal)
334  CantBePromoted.insert(F.getGUID());
335  Index.addGlobalValueSummary(F.getName(), std::move(FuncSummary));
336 }
337 
338 static void
340  DenseSet<GlobalValue::GUID> &CantBePromoted) {
341  SetVector<ValueInfo> RefEdges;
343  findRefEdges(Index, &V, RefEdges, Visited);
344  bool NonRenamableLocal = isNonRenamableLocal(V);
345  GlobalValueSummary::GVFlags Flags(V.getLinkage(), NonRenamableLocal,
346  /* Live = */ false, V.isDSOLocal());
347  auto GVarSummary =
348  llvm::make_unique<GlobalVarSummary>(Flags, RefEdges.takeVector());
349  if (NonRenamableLocal)
350  CantBePromoted.insert(V.getGUID());
351  Index.addGlobalValueSummary(V.getName(), std::move(GVarSummary));
352 }
353 
354 static void
356  DenseSet<GlobalValue::GUID> &CantBePromoted) {
357  bool NonRenamableLocal = isNonRenamableLocal(A);
358  GlobalValueSummary::GVFlags Flags(A.getLinkage(), NonRenamableLocal,
359  /* Live = */ false, A.isDSOLocal());
360  auto AS = llvm::make_unique<AliasSummary>(Flags);
361  auto *Aliasee = A.getBaseObject();
362  auto *AliaseeSummary = Index.getGlobalValueSummary(*Aliasee);
363  assert(AliaseeSummary && "Alias expects aliasee summary to be parsed");
364  AS->setAliasee(AliaseeSummary);
365  if (NonRenamableLocal)
366  CantBePromoted.insert(A.getGUID());
367  Index.addGlobalValueSummary(A.getName(), std::move(AS));
368 }
369 
370 // Set LiveRoot flag on entries matching the given value name.
372  if (ValueInfo VI = Index.getValueInfo(GlobalValue::getGUID(Name)))
373  for (auto &Summary : VI.getSummaryList())
374  Summary->setLive(true);
375 }
376 
378  const Module &M,
379  std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
380  ProfileSummaryInfo *PSI) {
381  assert(PSI);
382  ModuleSummaryIndex Index(/*IsPerformingAnalysis=*/true);
383 
384  // Identify the local values in the llvm.used and llvm.compiler.used sets,
385  // which should not be exported as they would then require renaming and
386  // promotion, but we may have opaque uses e.g. in inline asm. We collect them
387  // here because we use this information to mark functions containing inline
388  // assembly calls as not importable.
391  // First collect those in the llvm.used set.
392  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);
393  // Next collect those in the llvm.compiler.used set.
394  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ true);
395  DenseSet<GlobalValue::GUID> CantBePromoted;
396  for (auto *V : Used) {
397  if (V->hasLocalLinkage()) {
398  LocalsUsed.insert(V);
399  CantBePromoted.insert(V->getGUID());
400  }
401  }
402 
403  bool HasLocalInlineAsmSymbol = false;
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.
416  // Symbols not marked as Weak or Global are local definitions.
417  if (Flags & (object::BasicSymbolRef::SF_Weak |
419  return;
420  HasLocalInlineAsmSymbol = true;
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  /* Local */ GV->isDSOLocal());
429  CantBePromoted.insert(GlobalValue::getGUID(Name));
430  // Create the appropriate summary type.
431  if (Function *F = dyn_cast<Function>(GV)) {
432  std::unique_ptr<FunctionSummary> Summary =
433  llvm::make_unique<FunctionSummary>(
434  GVFlags, 0,
436  F->hasFnAttribute(Attribute::ReadNone),
437  F->hasFnAttribute(Attribute::ReadOnly),
438  F->hasFnAttribute(Attribute::NoRecurse),
439  F->returnDoesNotAlias()},
446  Index.addGlobalValueSummary(Name, std::move(Summary));
447  } else {
448  std::unique_ptr<GlobalVarSummary> Summary =
449  llvm::make_unique<GlobalVarSummary>(GVFlags,
451  Index.addGlobalValueSummary(Name, std::move(Summary));
452  }
453  });
454  }
455 
456  // Compute summaries for all functions defined in module, and save in the
457  // index.
458  for (auto &F : M) {
459  if (F.isDeclaration())
460  continue;
461 
462  BlockFrequencyInfo *BFI = nullptr;
463  std::unique_ptr<BlockFrequencyInfo> BFIPtr;
464  if (GetBFICallback)
465  BFI = GetBFICallback(F);
466  else if (F.hasProfileData()) {
467  LoopInfo LI{DominatorTree(const_cast<Function &>(F))};
468  BranchProbabilityInfo BPI{F, LI};
469  BFIPtr = llvm::make_unique<BlockFrequencyInfo>(F, BPI, LI);
470  BFI = BFIPtr.get();
471  }
472 
473  computeFunctionSummary(Index, M, F, BFI, PSI,
474  !LocalsUsed.empty() || HasLocalInlineAsmSymbol,
475  CantBePromoted);
476  }
477 
478  // Compute summaries for all variables defined in module, and save in the
479  // index.
480  for (const GlobalVariable &G : M.globals()) {
481  if (G.isDeclaration())
482  continue;
483  computeVariableSummary(Index, G, CantBePromoted);
484  }
485 
486  // Compute summaries for all aliases defined in module, and save in the
487  // index.
488  for (const GlobalAlias &A : M.aliases())
489  computeAliasSummary(Index, A, CantBePromoted);
490 
491  for (auto *V : LocalsUsed) {
492  auto *Summary = Index.getGlobalValueSummary(*V);
493  assert(Summary && "Missing summary for global value");
494  Summary->setNotEligibleToImport();
495  }
496 
497  // The linker doesn't know about these LLVM produced values, so we need
498  // to flag them as live in the index to ensure index-based dead value
499  // analysis treats them as live roots of the analysis.
500  setLiveRoot(Index, "llvm.used");
501  setLiveRoot(Index, "llvm.compiler.used");
502  setLiveRoot(Index, "llvm.global_ctors");
503  setLiveRoot(Index, "llvm.global_dtors");
504  setLiveRoot(Index, "llvm.global.annotations");
505 
506  bool IsThinLTO = true;
507  if (auto *MD =
508  mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("ThinLTO")))
509  IsThinLTO = MD->getZExtValue();
510 
511  for (auto &GlobalList : Index) {
512  // Ignore entries for references that are undefined in the current module.
513  if (GlobalList.second.SummaryList.empty())
514  continue;
515 
516  assert(GlobalList.second.SummaryList.size() == 1 &&
517  "Expected module's index to have one summary per GUID");
518  auto &Summary = GlobalList.second.SummaryList[0];
519  if (!IsThinLTO) {
520  Summary->setNotEligibleToImport();
521  continue;
522  }
523 
524  bool AllRefsCanBeExternallyReferenced =
525  llvm::all_of(Summary->refs(), [&](const ValueInfo &VI) {
526  return !CantBePromoted.count(VI.getGUID());
527  });
528  if (!AllRefsCanBeExternallyReferenced) {
529  Summary->setNotEligibleToImport();
530  continue;
531  }
532 
533  if (auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
534  bool AllCallsCanBeExternallyReferenced = llvm::all_of(
535  FuncSummary->calls(), [&](const FunctionSummary::EdgeTy &Edge) {
536  return !CantBePromoted.count(Edge.first.getGUID());
537  });
538  if (!AllCallsCanBeExternallyReferenced)
539  Summary->setNotEligibleToImport();
540  }
541  }
542 
543  return Index;
544 }
545 
546 AnalysisKey ModuleSummaryIndexAnalysis::Key;
547 
551  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
553  M,
554  [&FAM](const Function &F) {
555  return &FAM.getResult<BlockFrequencyAnalysis>(
556  *const_cast<Function *>(&F));
557  },
558  &PSI);
559 }
560 
562 
563 INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis",
564  "Module Summary Analysis", false, true)
568  "Module Summary Analysis", false, true)
569 
571  return new ModuleSummaryIndexWrapperPass();
572 }
573 
575  : ModulePass(ID) {
577 }
578 
580  auto &PSI = *getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
581  Index = buildModuleSummaryIndex(
582  M,
583  [this](const Function &F) {
584  return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
585  *const_cast<Function *>(&F))
586  .getBFI());
587  },
588  &PSI);
589  return false;
590 }
591 
593  Index.reset();
594  return false;
595 }
596 
598  AU.setPreservesAll();
601 }
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:360
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:302
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:814
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 .type.test, find all devirtualizable call sites based on the call and r...
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
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...
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.
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:564
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:821
INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis", "Module Summary Analysis", false, true) INITIALIZE_PASS_END(ModuleSummaryIndexWrapperPass
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: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:242
VectorType takeVector()
Clear the MapVector and return the underlying vector.
Definition: MapVector.h:52
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:522
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 .type.checked.load, find all devirtualizable call sites based on the ca...
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:175
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.
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.
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
Definition: Module.h:241
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:289
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:70
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