LLVM  6.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 
97 static CalleeInfo::HotnessType getHotness(uint64_t ProfileCount,
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  CallGraphEdges[Index.getOrInsertValueInfo(
277  cast<GlobalValue>(CalledValue))]
278  .updateHotness(Hotness);
279  } else {
280  // Skip inline assembly calls.
281  if (CI && CI->isInlineAsm())
282  continue;
283  // Skip direct calls.
284  if (!CalledValue || isa<Constant>(CalledValue))
285  continue;
286 
287  uint32_t NumVals, NumCandidates;
288  uint64_t TotalCount;
289  auto CandidateProfileData =
291  &I, NumVals, TotalCount, NumCandidates);
292  for (auto &Candidate : CandidateProfileData)
293  CallGraphEdges[Index.getOrInsertValueInfo(Candidate.Value)]
294  .updateHotness(getHotness(Candidate.Count, PSI));
295  }
296  }
297 
298  // Explicit add hot edges to enforce importing for designated GUIDs for
299  // sample PGO, to enable the same inlines as the profiled optimized binary.
300  for (auto &I : F.getImportGUIDs())
301  CallGraphEdges[Index.getOrInsertValueInfo(I)].updateHotness(
303 
304  bool NonRenamableLocal = isNonRenamableLocal(F);
305  bool NotEligibleForImport =
306  NonRenamableLocal || HasInlineAsmMaybeReferencingInternal ||
307  // Inliner doesn't handle variadic functions.
308  // FIXME: refactor this to use the same code that inliner is using.
309  F.isVarArg();
310  GlobalValueSummary::GVFlags Flags(F.getLinkage(), NotEligibleForImport,
311  /* Live = */ false, F.isDSOLocal());
312  FunctionSummary::FFlags FunFlags{
313  F.hasFnAttribute(Attribute::ReadNone),
314  F.hasFnAttribute(Attribute::ReadOnly),
315  F.hasFnAttribute(Attribute::NoRecurse),
316  F.returnDoesNotAlias(),
317  };
318  auto FuncSummary = llvm::make_unique<FunctionSummary>(
319  Flags, NumInsts, FunFlags, RefEdges.takeVector(),
320  CallGraphEdges.takeVector(), TypeTests.takeVector(),
321  TypeTestAssumeVCalls.takeVector(), TypeCheckedLoadVCalls.takeVector(),
322  TypeTestAssumeConstVCalls.takeVector(),
323  TypeCheckedLoadConstVCalls.takeVector());
324  if (NonRenamableLocal)
325  CantBePromoted.insert(F.getGUID());
326  Index.addGlobalValueSummary(F.getName(), std::move(FuncSummary));
327 }
328 
329 static void
331  DenseSet<GlobalValue::GUID> &CantBePromoted) {
332  SetVector<ValueInfo> RefEdges;
334  findRefEdges(Index, &V, RefEdges, Visited);
335  bool NonRenamableLocal = isNonRenamableLocal(V);
336  GlobalValueSummary::GVFlags Flags(V.getLinkage(), NonRenamableLocal,
337  /* Live = */ false, V.isDSOLocal());
338  auto GVarSummary =
339  llvm::make_unique<GlobalVarSummary>(Flags, RefEdges.takeVector());
340  if (NonRenamableLocal)
341  CantBePromoted.insert(V.getGUID());
342  Index.addGlobalValueSummary(V.getName(), std::move(GVarSummary));
343 }
344 
345 static void
347  DenseSet<GlobalValue::GUID> &CantBePromoted) {
348  bool NonRenamableLocal = isNonRenamableLocal(A);
349  GlobalValueSummary::GVFlags Flags(A.getLinkage(), NonRenamableLocal,
350  /* Live = */ false, A.isDSOLocal());
351  auto AS = llvm::make_unique<AliasSummary>(Flags);
352  auto *Aliasee = A.getBaseObject();
353  auto *AliaseeSummary = Index.getGlobalValueSummary(*Aliasee);
354  assert(AliaseeSummary && "Alias expects aliasee summary to be parsed");
355  AS->setAliasee(AliaseeSummary);
356  if (NonRenamableLocal)
357  CantBePromoted.insert(A.getGUID());
358  Index.addGlobalValueSummary(A.getName(), std::move(AS));
359 }
360 
361 // Set LiveRoot flag on entries matching the given value name.
363  if (ValueInfo VI = Index.getValueInfo(GlobalValue::getGUID(Name)))
364  for (auto &Summary : VI.getSummaryList())
365  Summary->setLive(true);
366 }
367 
369  const Module &M,
370  std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
371  ProfileSummaryInfo *PSI) {
372  assert(PSI);
373  ModuleSummaryIndex Index;
374 
375  // Identify the local values in the llvm.used and llvm.compiler.used sets,
376  // which should not be exported as they would then require renaming and
377  // promotion, but we may have opaque uses e.g. in inline asm. We collect them
378  // here because we use this information to mark functions containing inline
379  // assembly calls as not importable.
382  // First collect those in the llvm.used set.
383  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);
384  // Next collect those in the llvm.compiler.used set.
385  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ true);
386  DenseSet<GlobalValue::GUID> CantBePromoted;
387  for (auto *V : Used) {
388  if (V->hasLocalLinkage()) {
389  LocalsUsed.insert(V);
390  CantBePromoted.insert(V->getGUID());
391  }
392  }
393 
394  bool HasLocalInlineAsmSymbol = false;
395  if (!M.getModuleInlineAsm().empty()) {
396  // Collect the local values defined by module level asm, and set up
397  // summaries for these symbols so that they can be marked as NoRename,
398  // to prevent export of any use of them in regular IR that would require
399  // renaming within the module level asm. Note we don't need to create a
400  // summary for weak or global defs, as they don't need to be flagged as
401  // NoRename, and defs in module level asm can't be imported anyway.
402  // Also, any values used but not defined within module level asm should
403  // be listed on the llvm.used or llvm.compiler.used global and marked as
404  // referenced from there.
407  // Symbols not marked as Weak or Global are local definitions.
408  if (Flags & (object::BasicSymbolRef::SF_Weak |
410  return;
411  HasLocalInlineAsmSymbol = true;
412  GlobalValue *GV = M.getNamedValue(Name);
413  if (!GV)
414  return;
415  assert(GV->isDeclaration() && "Def in module asm already has definition");
417  /* NotEligibleToImport = */ true,
418  /* Live = */ true,
419  /* Local */ GV->isDSOLocal());
420  CantBePromoted.insert(GlobalValue::getGUID(Name));
421  // Create the appropriate summary type.
422  if (Function *F = dyn_cast<Function>(GV)) {
423  std::unique_ptr<FunctionSummary> Summary =
424  llvm::make_unique<FunctionSummary>(
425  GVFlags, 0,
427  F->hasFnAttribute(Attribute::ReadNone),
428  F->hasFnAttribute(Attribute::ReadOnly),
429  F->hasFnAttribute(Attribute::NoRecurse),
430  F->returnDoesNotAlias()},
437  Index.addGlobalValueSummary(Name, std::move(Summary));
438  } else {
439  std::unique_ptr<GlobalVarSummary> Summary =
440  llvm::make_unique<GlobalVarSummary>(GVFlags,
442  Index.addGlobalValueSummary(Name, std::move(Summary));
443  }
444  });
445  }
446 
447  // Compute summaries for all functions defined in module, and save in the
448  // index.
449  for (auto &F : M) {
450  if (F.isDeclaration())
451  continue;
452 
453  BlockFrequencyInfo *BFI = nullptr;
454  std::unique_ptr<BlockFrequencyInfo> BFIPtr;
455  if (GetBFICallback)
456  BFI = GetBFICallback(F);
457  else if (F.getEntryCount().hasValue()) {
458  LoopInfo LI{DominatorTree(const_cast<Function &>(F))};
459  BranchProbabilityInfo BPI{F, LI};
460  BFIPtr = llvm::make_unique<BlockFrequencyInfo>(F, BPI, LI);
461  BFI = BFIPtr.get();
462  }
463 
464  computeFunctionSummary(Index, M, F, BFI, PSI,
465  !LocalsUsed.empty() || HasLocalInlineAsmSymbol,
466  CantBePromoted);
467  }
468 
469  // Compute summaries for all variables defined in module, and save in the
470  // index.
471  for (const GlobalVariable &G : M.globals()) {
472  if (G.isDeclaration())
473  continue;
474  computeVariableSummary(Index, G, CantBePromoted);
475  }
476 
477  // Compute summaries for all aliases defined in module, and save in the
478  // index.
479  for (const GlobalAlias &A : M.aliases())
480  computeAliasSummary(Index, A, CantBePromoted);
481 
482  for (auto *V : LocalsUsed) {
483  auto *Summary = Index.getGlobalValueSummary(*V);
484  assert(Summary && "Missing summary for global value");
485  Summary->setNotEligibleToImport();
486  }
487 
488  // The linker doesn't know about these LLVM produced values, so we need
489  // to flag them as live in the index to ensure index-based dead value
490  // analysis treats them as live roots of the analysis.
491  setLiveRoot(Index, "llvm.used");
492  setLiveRoot(Index, "llvm.compiler.used");
493  setLiveRoot(Index, "llvm.global_ctors");
494  setLiveRoot(Index, "llvm.global_dtors");
495  setLiveRoot(Index, "llvm.global.annotations");
496 
497  bool IsThinLTO = true;
498  if (auto *MD =
499  mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("ThinLTO")))
500  IsThinLTO = MD->getZExtValue();
501 
502  for (auto &GlobalList : Index) {
503  // Ignore entries for references that are undefined in the current module.
504  if (GlobalList.second.SummaryList.empty())
505  continue;
506 
507  assert(GlobalList.second.SummaryList.size() == 1 &&
508  "Expected module's index to have one summary per GUID");
509  auto &Summary = GlobalList.second.SummaryList[0];
510  if (!IsThinLTO) {
511  Summary->setNotEligibleToImport();
512  continue;
513  }
514 
515  bool AllRefsCanBeExternallyReferenced =
516  llvm::all_of(Summary->refs(), [&](const ValueInfo &VI) {
517  return !CantBePromoted.count(VI.getGUID());
518  });
519  if (!AllRefsCanBeExternallyReferenced) {
520  Summary->setNotEligibleToImport();
521  continue;
522  }
523 
524  if (auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
525  bool AllCallsCanBeExternallyReferenced = llvm::all_of(
526  FuncSummary->calls(), [&](const FunctionSummary::EdgeTy &Edge) {
527  return !CantBePromoted.count(Edge.first.getGUID());
528  });
529  if (!AllCallsCanBeExternallyReferenced)
530  Summary->setNotEligibleToImport();
531  }
532  }
533 
534  return Index;
535 }
536 
537 AnalysisKey ModuleSummaryIndexAnalysis::Key;
538 
542  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
544  M,
545  [&FAM](const Function &F) {
546  return &FAM.getResult<BlockFrequencyAnalysis>(
547  *const_cast<Function *>(&F));
548  },
549  &PSI);
550 }
551 
553 
554 INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis",
555  "Module Summary Analysis", false, true)
559  "Module Summary Analysis", false, true)
560 
562  return new ModuleSummaryIndexWrapperPass();
563 }
564 
566  : ModulePass(ID) {
568 }
569 
571  auto &PSI = *getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
572  Index = buildModuleSummaryIndex(
573  M,
574  [this](const Function &F) {
575  return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
576  *const_cast<Function *>(&F))
577  .getBFI());
578  },
579  &PSI);
580  return false;
581 }
582 
584  Index.reset();
585  return false;
586 }
587 
589  AU.setPreservesAll();
592 }
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.
const GlobalObject * getBaseObject() const
iterator_range< use_iterator > uses()
Definition: Value.h:356
bool hasLocalLinkage() const
Definition: GlobalValue.h:427
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:483
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 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:262
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:813
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:261
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:271
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:441
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:140
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:518
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:820
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:487
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...
Optional< uint64_t > getEntryCount() const
Get the entry count for this function.
Definition: Function.cpp:1330
const AMDGPUAS & AS
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
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:513
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:864
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:385
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
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:491
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...
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
Basic Alias true
bool hasValue() const
Definition: Optional.h:137
Analysis providing branch probability information.
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:61
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:220
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())
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...
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