LLVM  10.0.0
ModuleSummaryAnalysis.cpp
Go to the documentation of this file.
1 //===- ModuleSummaryAnalysis.cpp - Module summary index builder -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass builds a ModuleSummaryIndex object for the module, to be written
10 // to bitcode or LLVM assembly.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/DenseSet.h"
17 #include "llvm/ADT/MapVector.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/SetVector.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
26 #include "llvm/Analysis/LoopInfo.h"
29 #include "llvm/IR/Attributes.h"
30 #include "llvm/IR/BasicBlock.h"
31 #include "llvm/IR/CallSite.h"
32 #include "llvm/IR/Constant.h"
33 #include "llvm/IR/Constants.h"
34 #include "llvm/IR/Dominators.h"
35 #include "llvm/IR/Function.h"
36 #include "llvm/IR/GlobalAlias.h"
37 #include "llvm/IR/GlobalValue.h"
38 #include "llvm/IR/GlobalVariable.h"
39 #include "llvm/IR/Instructions.h"
40 #include "llvm/IR/IntrinsicInst.h"
41 #include "llvm/IR/Intrinsics.h"
42 #include "llvm/IR/Metadata.h"
43 #include "llvm/IR/Module.h"
45 #include "llvm/IR/Use.h"
46 #include "llvm/IR/User.h"
47 #include "llvm/InitializePasses.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 
75  "module-summary-dot-file", cl::init(""), cl::Hidden,
76  cl::value_desc("filename"),
77  cl::desc("File to emit dot graph of new summary into."));
78 
79 // Walk through the operands of a given User via worklist iteration and populate
80 // the set of GlobalValue references encountered. Invoked either on an
81 // Instruction or a GlobalVariable (which walks its initializer).
82 // Return true if any of the operands contains blockaddress. This is important
83 // to know when computing summary for global var, because if global variable
84 // references basic block address we can't import it separately from function
85 // containing that basic block. For simplicity we currently don't import such
86 // global vars at all. When importing function we aren't interested if any
87 // instruction in it takes an address of any basic block, because instruction
88 // can only take an address of basic block located in the same function.
89 static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
90  SetVector<ValueInfo> &RefEdges,
92  bool HasBlockAddress = false;
94  Worklist.push_back(CurUser);
95 
96  while (!Worklist.empty()) {
97  const User *U = Worklist.pop_back_val();
98 
99  if (!Visited.insert(U).second)
100  continue;
101 
102  ImmutableCallSite CS(U);
103 
104  for (const auto &OI : U->operands()) {
105  const User *Operand = dyn_cast<User>(OI);
106  if (!Operand)
107  continue;
108  if (isa<BlockAddress>(Operand)) {
109  HasBlockAddress = true;
110  continue;
111  }
112  if (auto *GV = dyn_cast<GlobalValue>(Operand)) {
113  // We have a reference to a global value. This should be added to
114  // the reference set unless it is a callee. Callees are handled
115  // specially by WriteFunction and are added to a separate list.
116  if (!(CS && CS.isCallee(&OI)))
117  RefEdges.insert(Index.getOrInsertValueInfo(GV));
118  continue;
119  }
120  Worklist.push_back(Operand);
121  }
122  }
123  return HasBlockAddress;
124 }
125 
127  ProfileSummaryInfo *PSI) {
128  if (!PSI)
130  if (PSI->isHotCount(ProfileCount))
132  if (PSI->isColdCount(ProfileCount))
135 }
136 
137 static bool isNonRenamableLocal(const GlobalValue &GV) {
138  return GV.hasSection() && GV.hasLocalLinkage();
139 }
140 
141 /// Determine whether this call has all constant integer arguments (excluding
142 /// "this") and summarize it to VCalls or ConstVCalls as appropriate.
146  std::vector<uint64_t> Args;
147  // Start from the second argument to skip the "this" pointer.
148  for (auto &Arg : make_range(Call.CS.arg_begin() + 1, Call.CS.arg_end())) {
149  auto *CI = dyn_cast<ConstantInt>(Arg);
150  if (!CI || CI->getBitWidth() > 64) {
151  VCalls.insert({Guid, Call.Offset});
152  return;
153  }
154  Args.push_back(CI->getZExtValue());
155  }
156  ConstVCalls.insert({{Guid, Call.Offset}, std::move(Args)});
157 }
158 
159 /// If this intrinsic call requires that we add information to the function
160 /// summary, do so via the non-constant reference arguments.
162  const CallInst *CI, SetVector<GlobalValue::GUID> &TypeTests,
163  SetVector<FunctionSummary::VFuncId> &TypeTestAssumeVCalls,
164  SetVector<FunctionSummary::VFuncId> &TypeCheckedLoadVCalls,
165  SetVector<FunctionSummary::ConstVCall> &TypeTestAssumeConstVCalls,
166  SetVector<FunctionSummary::ConstVCall> &TypeCheckedLoadConstVCalls,
167  DominatorTree &DT) {
168  switch (CI->getCalledFunction()->getIntrinsicID()) {
169  case Intrinsic::type_test: {
170  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(1));
171  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
172  if (!TypeId)
173  break;
174  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
175 
176  // Produce a summary from type.test intrinsics. We only summarize type.test
177  // intrinsics that are used other than by an llvm.assume intrinsic.
178  // Intrinsics that are assumed are relevant only to the devirtualization
179  // pass, not the type test lowering pass.
180  bool HasNonAssumeUses = llvm::any_of(CI->uses(), [](const Use &CIU) {
181  auto *AssumeCI = dyn_cast<CallInst>(CIU.getUser());
182  if (!AssumeCI)
183  return true;
184  Function *F = AssumeCI->getCalledFunction();
185  return !F || F->getIntrinsicID() != Intrinsic::assume;
186  });
187  if (HasNonAssumeUses)
188  TypeTests.insert(Guid);
189 
190  SmallVector<DevirtCallSite, 4> DevirtCalls;
192  findDevirtualizableCallsForTypeTest(DevirtCalls, Assumes, CI, DT);
193  for (auto &Call : DevirtCalls)
194  addVCallToSet(Call, Guid, TypeTestAssumeVCalls,
195  TypeTestAssumeConstVCalls);
196 
197  break;
198  }
199 
200  case Intrinsic::type_checked_load: {
201  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(2));
202  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
203  if (!TypeId)
204  break;
205  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
206 
207  SmallVector<DevirtCallSite, 4> DevirtCalls;
210  bool HasNonCallUses = false;
211  findDevirtualizableCallsForTypeCheckedLoad(DevirtCalls, LoadedPtrs, Preds,
212  HasNonCallUses, CI, DT);
213  // Any non-call uses of the result of llvm.type.checked.load will
214  // prevent us from optimizing away the llvm.type.test.
215  if (HasNonCallUses)
216  TypeTests.insert(Guid);
217  for (auto &Call : DevirtCalls)
218  addVCallToSet(Call, Guid, TypeCheckedLoadVCalls,
219  TypeCheckedLoadConstVCalls);
220 
221  break;
222  }
223  default:
224  break;
225  }
226 }
227 
228 static bool isNonVolatileLoad(const Instruction *I) {
229  if (const auto *LI = dyn_cast<LoadInst>(I))
230  return !LI->isVolatile();
231 
232  return false;
233 }
234 
235 static bool isNonVolatileStore(const Instruction *I) {
236  if (const auto *SI = dyn_cast<StoreInst>(I))
237  return !SI->isVolatile();
238 
239  return false;
240 }
241 
243  const Function &F, BlockFrequencyInfo *BFI,
245  bool HasLocalsInUsedOrAsm,
246  DenseSet<GlobalValue::GUID> &CantBePromoted,
247  bool IsThinLTO) {
248  // Summary not currently supported for anonymous functions, they should
249  // have been named.
250  assert(F.hasName());
251 
252  unsigned NumInsts = 0;
253  // Map from callee ValueId to profile count. Used to accumulate profile
254  // counts for all static calls to a given callee.
255  MapVector<ValueInfo, CalleeInfo> CallGraphEdges;
256  SetVector<ValueInfo> RefEdges, LoadRefEdges, StoreRefEdges;
258  SetVector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
259  TypeCheckedLoadVCalls;
260  SetVector<FunctionSummary::ConstVCall> TypeTestAssumeConstVCalls,
261  TypeCheckedLoadConstVCalls;
262  ICallPromotionAnalysis ICallAnalysis;
264 
265  // Add personality function, prefix data and prologue data to function's ref
266  // list.
267  findRefEdges(Index, &F, RefEdges, Visited);
268  std::vector<const Instruction *> NonVolatileLoads;
269  std::vector<const Instruction *> NonVolatileStores;
270 
271  bool HasInlineAsmMaybeReferencingInternal = false;
272  for (const BasicBlock &BB : F)
273  for (const Instruction &I : BB) {
274  if (isa<DbgInfoIntrinsic>(I))
275  continue;
276  ++NumInsts;
277  // Regular LTO module doesn't participate in ThinLTO import,
278  // so no reference from it can be read/writeonly, since this
279  // would require importing variable as local copy
280  if (IsThinLTO) {
281  if (isNonVolatileLoad(&I)) {
282  // Postpone processing of non-volatile load instructions
283  // See comments below
284  Visited.insert(&I);
285  NonVolatileLoads.push_back(&I);
286  continue;
287  } else if (isNonVolatileStore(&I)) {
288  Visited.insert(&I);
289  NonVolatileStores.push_back(&I);
290  // All references from second operand of store (destination address)
291  // can be considered write-only if they're not referenced by any
292  // non-store instruction. References from first operand of store
293  // (stored value) can't be treated either as read- or as write-only
294  // so we add them to RefEdges as we do with all other instructions
295  // except non-volatile load.
296  Value *Stored = I.getOperand(0);
297  if (auto *GV = dyn_cast<GlobalValue>(Stored))
298  // findRefEdges will try to examine GV operands, so instead
299  // of calling it we should add GV to RefEdges directly.
300  RefEdges.insert(Index.getOrInsertValueInfo(GV));
301  else if (auto *U = dyn_cast<User>(Stored))
302  findRefEdges(Index, U, RefEdges, Visited);
303  continue;
304  }
305  }
306  findRefEdges(Index, &I, RefEdges, Visited);
307  auto CS = ImmutableCallSite(&I);
308  if (!CS)
309  continue;
310 
311  const auto *CI = dyn_cast<CallInst>(&I);
312  // Since we don't know exactly which local values are referenced in inline
313  // assembly, conservatively mark the function as possibly referencing
314  // a local value from inline assembly to ensure we don't export a
315  // reference (which would require renaming and promotion of the
316  // referenced value).
317  if (HasLocalsInUsedOrAsm && CI && CI->isInlineAsm())
318  HasInlineAsmMaybeReferencingInternal = true;
319 
320  auto *CalledValue = CS.getCalledValue();
321  auto *CalledFunction = CS.getCalledFunction();
322  if (CalledValue && !CalledFunction) {
323  CalledValue = CalledValue->stripPointerCasts();
324  // Stripping pointer casts can reveal a called function.
325  CalledFunction = dyn_cast<Function>(CalledValue);
326  }
327  // Check if this is an alias to a function. If so, get the
328  // called aliasee for the checks below.
329  if (auto *GA = dyn_cast<GlobalAlias>(CalledValue)) {
330  assert(!CalledFunction && "Expected null called function in callsite for alias");
331  CalledFunction = dyn_cast<Function>(GA->getBaseObject());
332  }
333  // Check if this is a direct call to a known function or a known
334  // intrinsic, or an indirect call with profile data.
335  if (CalledFunction) {
336  if (CI && CalledFunction->isIntrinsic()) {
338  CI, TypeTests, TypeTestAssumeVCalls, TypeCheckedLoadVCalls,
339  TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls, DT);
340  continue;
341  }
342  // We should have named any anonymous globals
343  assert(CalledFunction->hasName());
344  auto ScaledCount = PSI->getProfileCount(&I, BFI);
345  auto Hotness = ScaledCount ? getHotness(ScaledCount.getValue(), PSI)
349 
350  // Use the original CalledValue, in case it was an alias. We want
351  // to record the call edge to the alias in that case. Eventually
352  // an alias summary will be created to associate the alias and
353  // aliasee.
354  auto &ValueInfo = CallGraphEdges[Index.getOrInsertValueInfo(
355  cast<GlobalValue>(CalledValue))];
356  ValueInfo.updateHotness(Hotness);
357  // Add the relative block frequency to CalleeInfo if there is no profile
358  // information.
359  if (BFI != nullptr && Hotness == CalleeInfo::HotnessType::Unknown) {
360  uint64_t BBFreq = BFI->getBlockFreq(&BB).getFrequency();
361  uint64_t EntryFreq = BFI->getEntryFreq();
362  ValueInfo.updateRelBlockFreq(BBFreq, EntryFreq);
363  }
364  } else {
365  // Skip inline assembly calls.
366  if (CI && CI->isInlineAsm())
367  continue;
368  // Skip direct calls.
369  if (!CalledValue || isa<Constant>(CalledValue))
370  continue;
371 
372  // Check if the instruction has a callees metadata. If so, add callees
373  // to CallGraphEdges to reflect the references from the metadata, and
374  // to enable importing for subsequent indirect call promotion and
375  // inlining.
376  if (auto *MD = I.getMetadata(LLVMContext::MD_callees)) {
377  for (auto &Op : MD->operands()) {
378  Function *Callee = mdconst::extract_or_null<Function>(Op);
379  if (Callee)
380  CallGraphEdges[Index.getOrInsertValueInfo(Callee)];
381  }
382  }
383 
384  uint32_t NumVals, NumCandidates;
385  uint64_t TotalCount;
386  auto CandidateProfileData =
388  &I, NumVals, TotalCount, NumCandidates);
389  for (auto &Candidate : CandidateProfileData)
390  CallGraphEdges[Index.getOrInsertValueInfo(Candidate.Value)]
391  .updateHotness(getHotness(Candidate.Count, PSI));
392  }
393  }
394 
395  std::vector<ValueInfo> Refs;
396  if (IsThinLTO) {
397  auto AddRefEdges = [&](const std::vector<const Instruction *> &Instrs,
398  SetVector<ValueInfo> &Edges,
400  for (const auto *I : Instrs) {
401  Cache.erase(I);
402  findRefEdges(Index, I, Edges, Cache);
403  }
404  };
405 
406  // By now we processed all instructions in a function, except
407  // non-volatile loads and non-volatile value stores. Let's find
408  // ref edges for both of instruction sets
409  AddRefEdges(NonVolatileLoads, LoadRefEdges, Visited);
410  // We can add some values to the Visited set when processing load
411  // instructions which are also used by stores in NonVolatileStores.
412  // For example this can happen if we have following code:
413  //
414  // store %Derived* @foo, %Derived** bitcast (%Base** @bar to %Derived**)
415  // %42 = load %Derived*, %Derived** bitcast (%Base** @bar to %Derived**)
416  //
417  // After processing loads we'll add bitcast to the Visited set, and if
418  // we use the same set while processing stores, we'll never see store
419  // to @bar and @bar will be mistakenly treated as readonly.
421  AddRefEdges(NonVolatileStores, StoreRefEdges, StoreCache);
422 
423  // If both load and store instruction reference the same variable
424  // we won't be able to optimize it. Add all such reference edges
425  // to RefEdges set.
426  for (auto &VI : StoreRefEdges)
427  if (LoadRefEdges.remove(VI))
428  RefEdges.insert(VI);
429 
430  unsigned RefCnt = RefEdges.size();
431  // All new reference edges inserted in two loops below are either
432  // read or write only. They will be grouped in the end of RefEdges
433  // vector, so we can use a single integer value to identify them.
434  for (auto &VI : LoadRefEdges)
435  RefEdges.insert(VI);
436 
437  unsigned FirstWORef = RefEdges.size();
438  for (auto &VI : StoreRefEdges)
439  RefEdges.insert(VI);
440 
441  Refs = RefEdges.takeVector();
442  for (; RefCnt < FirstWORef; ++RefCnt)
443  Refs[RefCnt].setReadOnly();
444 
445  for (; RefCnt < Refs.size(); ++RefCnt)
446  Refs[RefCnt].setWriteOnly();
447  } else {
448  Refs = RefEdges.takeVector();
449  }
450  // Explicit add hot edges to enforce importing for designated GUIDs for
451  // sample PGO, to enable the same inlines as the profiled optimized binary.
452  for (auto &I : F.getImportGUIDs())
453  CallGraphEdges[Index.getOrInsertValueInfo(I)].updateHotness(
457 
458  bool NonRenamableLocal = isNonRenamableLocal(F);
459  bool NotEligibleForImport =
460  NonRenamableLocal || HasInlineAsmMaybeReferencingInternal;
461  GlobalValueSummary::GVFlags Flags(F.getLinkage(), NotEligibleForImport,
462  /* Live = */ false, F.isDSOLocal(),
463  F.hasLinkOnceODRLinkage() && F.hasGlobalUnnamedAddr());
464  FunctionSummary::FFlags FunFlags{
465  F.hasFnAttribute(Attribute::ReadNone),
466  F.hasFnAttribute(Attribute::ReadOnly),
467  F.hasFnAttribute(Attribute::NoRecurse), F.returnDoesNotAlias(),
468  // FIXME: refactor this to use the same code that inliner is using.
469  // Don't try to import functions with noinline attribute.
470  F.getAttributes().hasFnAttribute(Attribute::NoInline),
471  F.hasFnAttribute(Attribute::AlwaysInline)};
472  auto FuncSummary = std::make_unique<FunctionSummary>(
473  Flags, NumInsts, FunFlags, /*EntryCount=*/0, std::move(Refs),
474  CallGraphEdges.takeVector(), TypeTests.takeVector(),
475  TypeTestAssumeVCalls.takeVector(), TypeCheckedLoadVCalls.takeVector(),
476  TypeTestAssumeConstVCalls.takeVector(),
477  TypeCheckedLoadConstVCalls.takeVector());
478  if (NonRenamableLocal)
479  CantBePromoted.insert(F.getGUID());
480  Index.addGlobalValueSummary(F, std::move(FuncSummary));
481 }
482 
483 /// Find function pointers referenced within the given vtable initializer
484 /// (or subset of an initializer) \p I. The starting offset of \p I within
485 /// the vtable initializer is \p StartingOffset. Any discovered function
486 /// pointers are added to \p VTableFuncs along with their cumulative offset
487 /// within the initializer.
488 static void findFuncPointers(const Constant *I, uint64_t StartingOffset,
489  const Module &M, ModuleSummaryIndex &Index,
490  VTableFuncList &VTableFuncs) {
491  // First check if this is a function pointer.
492  if (I->getType()->isPointerTy()) {
493  auto Fn = dyn_cast<Function>(I->stripPointerCasts());
494  // We can disregard __cxa_pure_virtual as a possible call target, as
495  // calls to pure virtuals are UB.
496  if (Fn && Fn->getName() != "__cxa_pure_virtual")
497  VTableFuncs.push_back({Index.getOrInsertValueInfo(Fn), StartingOffset});
498  return;
499  }
500 
501  // Walk through the elements in the constant struct or array and recursively
502  // look for virtual function pointers.
503  const DataLayout &DL = M.getDataLayout();
504  if (auto *C = dyn_cast<ConstantStruct>(I)) {
505  StructType *STy = dyn_cast<StructType>(C->getType());
506  assert(STy);
507  const StructLayout *SL = DL.getStructLayout(C->getType());
508 
509  for (StructType::element_iterator EB = STy->element_begin(), EI = EB,
510  EE = STy->element_end();
511  EI != EE; ++EI) {
512  auto Offset = SL->getElementOffset(EI - EB);
513  unsigned Op = SL->getElementContainingOffset(Offset);
514  findFuncPointers(cast<Constant>(I->getOperand(Op)),
515  StartingOffset + Offset, M, Index, VTableFuncs);
516  }
517  } else if (auto *C = dyn_cast<ConstantArray>(I)) {
518  ArrayType *ATy = C->getType();
519  Type *EltTy = ATy->getElementType();
520  uint64_t EltSize = DL.getTypeAllocSize(EltTy);
521  for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) {
522  findFuncPointers(cast<Constant>(I->getOperand(i)),
523  StartingOffset + i * EltSize, M, Index, VTableFuncs);
524  }
525  }
526 }
527 
528 // Identify the function pointers referenced by vtable definition \p V.
530  const GlobalVariable &V, const Module &M,
531  VTableFuncList &VTableFuncs) {
532  if (!V.isConstant())
533  return;
534 
535  findFuncPointers(V.getInitializer(), /*StartingOffset=*/0, M, Index,
536  VTableFuncs);
537 
538 #ifndef NDEBUG
539  // Validate that the VTableFuncs list is ordered by offset.
540  uint64_t PrevOffset = 0;
541  for (auto &P : VTableFuncs) {
542  // The findVFuncPointers traversal should have encountered the
543  // functions in offset order. We need to use ">=" since PrevOffset
544  // starts at 0.
545  assert(P.VTableOffset >= PrevOffset);
546  PrevOffset = P.VTableOffset;
547  }
548 #endif
549 }
550 
551 /// Record vtable definition \p V for each type metadata it references.
552 static void
554  const GlobalVariable &V,
555  SmallVectorImpl<MDNode *> &Types) {
556  for (MDNode *Type : Types) {
557  auto TypeID = Type->getOperand(1).get();
558 
559  uint64_t Offset =
560  cast<ConstantInt>(
561  cast<ConstantAsMetadata>(Type->getOperand(0))->getValue())
562  ->getZExtValue();
563 
564  if (auto *TypeId = dyn_cast<MDString>(TypeID))
565  Index.getOrInsertTypeIdCompatibleVtableSummary(TypeId->getString())
566  .push_back({Offset, Index.getOrInsertValueInfo(&V)});
567  }
568 }
569 
571  const GlobalVariable &V,
572  DenseSet<GlobalValue::GUID> &CantBePromoted,
573  const Module &M,
574  SmallVectorImpl<MDNode *> &Types) {
575  SetVector<ValueInfo> RefEdges;
577  bool HasBlockAddress = findRefEdges(Index, &V, RefEdges, Visited);
578  bool NonRenamableLocal = isNonRenamableLocal(V);
579  GlobalValueSummary::GVFlags Flags(V.getLinkage(), NonRenamableLocal,
580  /* Live = */ false, V.isDSOLocal(),
582 
583  VTableFuncList VTableFuncs;
584  // If splitting is not enabled, then we compute the summary information
585  // necessary for index-based whole program devirtualization.
586  if (!Index.enableSplitLTOUnit()) {
587  Types.clear();
588  V.getMetadata(LLVMContext::MD_type, Types);
589  if (!Types.empty()) {
590  // Identify the function pointers referenced by this vtable definition.
591  computeVTableFuncs(Index, V, M, VTableFuncs);
592 
593  // Record this vtable definition for each type metadata it references.
595  }
596  }
597 
598  // Don't mark variables we won't be able to internalize as read/write-only.
599  bool CanBeInternalized =
600  !V.hasComdat() && !V.hasAppendingLinkage() && !V.isInterposable() &&
602  GlobalVarSummary::GVarFlags VarFlags(CanBeInternalized, CanBeInternalized);
603  auto GVarSummary = std::make_unique<GlobalVarSummary>(Flags, VarFlags,
604  RefEdges.takeVector());
605  if (NonRenamableLocal)
606  CantBePromoted.insert(V.getGUID());
607  if (HasBlockAddress)
608  GVarSummary->setNotEligibleToImport();
609  if (!VTableFuncs.empty())
610  GVarSummary->setVTableFuncs(VTableFuncs);
611  Index.addGlobalValueSummary(V, std::move(GVarSummary));
612 }
613 
614 static void
616  DenseSet<GlobalValue::GUID> &CantBePromoted) {
617  bool NonRenamableLocal = isNonRenamableLocal(A);
618  GlobalValueSummary::GVFlags Flags(A.getLinkage(), NonRenamableLocal,
619  /* Live = */ false, A.isDSOLocal(),
621  auto AS = std::make_unique<AliasSummary>(Flags);
622  auto *Aliasee = A.getBaseObject();
623  auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
624  assert(AliaseeVI && "Alias expects aliasee summary to be available");
625  assert(AliaseeVI.getSummaryList().size() == 1 &&
626  "Expected a single entry per aliasee in per-module index");
627  AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
628  if (NonRenamableLocal)
629  CantBePromoted.insert(A.getGUID());
630  Index.addGlobalValueSummary(A, std::move(AS));
631 }
632 
633 // Set LiveRoot flag on entries matching the given value name.
635  if (ValueInfo VI = Index.getValueInfo(GlobalValue::getGUID(Name)))
636  for (auto &Summary : VI.getSummaryList())
637  Summary->setLive(true);
638 }
639 
641  const Module &M,
642  std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
643  ProfileSummaryInfo *PSI) {
644  assert(PSI);
645  bool EnableSplitLTOUnit = false;
646  if (auto *MD = mdconst::extract_or_null<ConstantInt>(
647  M.getModuleFlag("EnableSplitLTOUnit")))
648  EnableSplitLTOUnit = MD->getZExtValue();
649  ModuleSummaryIndex Index(/*HaveGVs=*/true, EnableSplitLTOUnit);
650 
651  // Identify the local values in the llvm.used and llvm.compiler.used sets,
652  // which should not be exported as they would then require renaming and
653  // promotion, but we may have opaque uses e.g. in inline asm. We collect them
654  // here because we use this information to mark functions containing inline
655  // assembly calls as not importable.
658  // First collect those in the llvm.used set.
659  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);
660  // Next collect those in the llvm.compiler.used set.
661  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ true);
662  DenseSet<GlobalValue::GUID> CantBePromoted;
663  for (auto *V : Used) {
664  if (V->hasLocalLinkage()) {
665  LocalsUsed.insert(V);
666  CantBePromoted.insert(V->getGUID());
667  }
668  }
669 
670  bool HasLocalInlineAsmSymbol = false;
671  if (!M.getModuleInlineAsm().empty()) {
672  // Collect the local values defined by module level asm, and set up
673  // summaries for these symbols so that they can be marked as NoRename,
674  // to prevent export of any use of them in regular IR that would require
675  // renaming within the module level asm. Note we don't need to create a
676  // summary for weak or global defs, as they don't need to be flagged as
677  // NoRename, and defs in module level asm can't be imported anyway.
678  // Also, any values used but not defined within module level asm should
679  // be listed on the llvm.used or llvm.compiler.used global and marked as
680  // referenced from there.
683  // Symbols not marked as Weak or Global are local definitions.
684  if (Flags & (object::BasicSymbolRef::SF_Weak |
686  return;
687  HasLocalInlineAsmSymbol = true;
688  GlobalValue *GV = M.getNamedValue(Name);
689  if (!GV)
690  return;
691  assert(GV->isDeclaration() && "Def in module asm already has definition");
693  /* NotEligibleToImport = */ true,
694  /* Live = */ true,
695  /* Local */ GV->isDSOLocal(),
697  CantBePromoted.insert(GV->getGUID());
698  // Create the appropriate summary type.
699  if (Function *F = dyn_cast<Function>(GV)) {
700  std::unique_ptr<FunctionSummary> Summary =
701  std::make_unique<FunctionSummary>(
702  GVFlags, /*InstCount=*/0,
704  F->hasFnAttribute(Attribute::ReadNone),
705  F->hasFnAttribute(Attribute::ReadOnly),
706  F->hasFnAttribute(Attribute::NoRecurse),
707  F->returnDoesNotAlias(),
708  /* NoInline = */ false,
709  F->hasFnAttribute(Attribute::AlwaysInline)},
710  /*EntryCount=*/0, ArrayRef<ValueInfo>{},
717  Index.addGlobalValueSummary(*GV, std::move(Summary));
718  } else {
719  std::unique_ptr<GlobalVarSummary> Summary =
720  std::make_unique<GlobalVarSummary>(
721  GVFlags, GlobalVarSummary::GVarFlags(false, false),
723  Index.addGlobalValueSummary(*GV, std::move(Summary));
724  }
725  });
726  }
727 
728  bool IsThinLTO = true;
729  if (auto *MD =
730  mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("ThinLTO")))
731  IsThinLTO = MD->getZExtValue();
732 
733  // Compute summaries for all functions defined in module, and save in the
734  // index.
735  for (auto &F : M) {
736  if (F.isDeclaration())
737  continue;
738 
739  DominatorTree DT(const_cast<Function &>(F));
740  BlockFrequencyInfo *BFI = nullptr;
741  std::unique_ptr<BlockFrequencyInfo> BFIPtr;
742  if (GetBFICallback)
743  BFI = GetBFICallback(F);
744  else if (F.hasProfileData()) {
745  LoopInfo LI{DT};
746  BranchProbabilityInfo BPI{F, LI};
747  BFIPtr = std::make_unique<BlockFrequencyInfo>(F, BPI, LI);
748  BFI = BFIPtr.get();
749  }
750 
751  computeFunctionSummary(Index, M, F, BFI, PSI, DT,
752  !LocalsUsed.empty() || HasLocalInlineAsmSymbol,
753  CantBePromoted, IsThinLTO);
754  }
755 
756  // Compute summaries for all variables defined in module, and save in the
757  // index.
759  for (const GlobalVariable &G : M.globals()) {
760  if (G.isDeclaration())
761  continue;
762  computeVariableSummary(Index, G, CantBePromoted, M, Types);
763  }
764 
765  // Compute summaries for all aliases defined in module, and save in the
766  // index.
767  for (const GlobalAlias &A : M.aliases())
768  computeAliasSummary(Index, A, CantBePromoted);
769 
770  for (auto *V : LocalsUsed) {
771  auto *Summary = Index.getGlobalValueSummary(*V);
772  assert(Summary && "Missing summary for global value");
773  Summary->setNotEligibleToImport();
774  }
775 
776  // The linker doesn't know about these LLVM produced values, so we need
777  // to flag them as live in the index to ensure index-based dead value
778  // analysis treats them as live roots of the analysis.
779  setLiveRoot(Index, "llvm.used");
780  setLiveRoot(Index, "llvm.compiler.used");
781  setLiveRoot(Index, "llvm.global_ctors");
782  setLiveRoot(Index, "llvm.global_dtors");
783  setLiveRoot(Index, "llvm.global.annotations");
784 
785  for (auto &GlobalList : Index) {
786  // Ignore entries for references that are undefined in the current module.
787  if (GlobalList.second.SummaryList.empty())
788  continue;
789 
790  assert(GlobalList.second.SummaryList.size() == 1 &&
791  "Expected module's index to have one summary per GUID");
792  auto &Summary = GlobalList.second.SummaryList[0];
793  if (!IsThinLTO) {
794  Summary->setNotEligibleToImport();
795  continue;
796  }
797 
798  bool AllRefsCanBeExternallyReferenced =
799  llvm::all_of(Summary->refs(), [&](const ValueInfo &VI) {
800  return !CantBePromoted.count(VI.getGUID());
801  });
802  if (!AllRefsCanBeExternallyReferenced) {
803  Summary->setNotEligibleToImport();
804  continue;
805  }
806 
807  if (auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
808  bool AllCallsCanBeExternallyReferenced = llvm::all_of(
809  FuncSummary->calls(), [&](const FunctionSummary::EdgeTy &Edge) {
810  return !CantBePromoted.count(Edge.first.getGUID());
811  });
812  if (!AllCallsCanBeExternallyReferenced)
813  Summary->setNotEligibleToImport();
814  }
815  }
816 
817  if (!ModuleSummaryDotFile.empty()) {
818  std::error_code EC;
820  if (EC)
821  report_fatal_error(Twine("Failed to open dot file ") +
822  ModuleSummaryDotFile + ": " + EC.message() + "\n");
823  Index.exportToDot(OSDot, {});
824  }
825 
826  return Index;
827 }
828 
829 AnalysisKey ModuleSummaryIndexAnalysis::Key;
830 
834  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
836  M,
837  [&FAM](const Function &F) {
838  return &FAM.getResult<BlockFrequencyAnalysis>(
839  *const_cast<Function *>(&F));
840  },
841  &PSI);
842 }
843 
845 
846 INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis",
847  "Module Summary Analysis", false, true)
851  "Module Summary Analysis", false, true)
852 
854  return new ModuleSummaryIndexWrapperPass();
855 }
856 
858  : ModulePass(ID) {
860 }
861 
863  auto *PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
864  Index.emplace(buildModuleSummaryIndex(
865  M,
866  [this](const Function &F) {
867  return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
868  *const_cast<Function *>(&F))
869  .getBFI());
870  },
871  PSI));
872  return false;
873 }
874 
876  Index.reset();
877  return false;
878 }
879 
881  AU.setPreservesAll();
884 }
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.
IterTy arg_end() const
Definition: CallSite.h:588
uint64_t CallInst * C
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
bool hasDLLExportStorageClass() const
Definition: GlobalValue.h:268
iterator_range< use_iterator > uses()
Definition: Value.h:375
bool hasLocalLinkage() const
Definition: GlobalValue.h:445
static void computeVariableSummary(ModuleSummaryIndex &Index, const GlobalVariable &V, DenseSet< GlobalValue::GUID > &CantBePromoted, const Module &M, SmallVectorImpl< MDNode *> &Types)
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:777
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Definition: GlobalValue.h:502
IterTy arg_begin() const
Definition: CallSite.h:584
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:23
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:77
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
GlobalValueSummary * getGlobalValueSummary(const GlobalValue &GV, bool PerModuleIndex=true) const
Returns the first GlobalValueSummary for GV, asserting that there is only one if PerModuleIndex.
void findDevirtualizableCallsForTypeTest(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< CallInst *> &Assumes, const CallInst *CI, DominatorTree &DT)
Given a call to the intrinsic @llvm.type.test, find all devirtualizable call sites based on the call ...
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:249
bool isColdCount(uint64_t C)
Returns true if count C is considered cold.
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
Definition: DataLayout.cpp:613
Analysis providing profile information.
This class represents a function call, abstracting a target machine&#39;s calling convention.
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:432
static void findFuncPointers(const Constant *I, uint64_t StartingOffset, const Module &M, ModuleSummaryIndex &Index, VTableFuncList &VTableFuncs)
Find function pointers referenced within the given vtable initializer (or subset of an initializer) I...
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 isInterposable() const
Return true if this global&#39;s definition can be substituted with an arbitrary definition at link time...
Definition: GlobalValue.h:429
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:323
This class implements a map that also provides access to all stored values in a deterministic order...
Definition: MapVector.h:37
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:1182
Metadata node.
Definition: Metadata.h:872
F(f)
void initializeModuleSummaryIndexWrapperPassPass(PassRegistry &)
block Block Frequency true
VectorType::iterator erase(typename VectorType::iterator Iterator)
Remove the element given by Iterator.
Definition: MapVector.h:173
This defines the Use class.
bool isHotCount(uint64_t C)
Returns true if count C is considered hot.
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it...
Definition: DataLayout.cpp:80
ModuleSummaryIndex buildModuleSummaryIndex(const Module &M, std::function< BlockFrequencyInfo *(const Function &F)> GetBFICallback, ProfileSummaryInfo *PSI)
Direct function to compute a ModuleSummaryIndex from a given module.
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1246
void findDevirtualizableCallsForTypeCheckedLoad(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< Instruction *> &LoadedPtrs, SmallVectorImpl< Instruction *> &Preds, bool &HasNonCallUses, const CallInst *CI, DominatorTree &DT)
Given a call to the intrinsic @llvm.type.checked.load, find all devirtualizable call sites based on t...
bool hasSection() const
Definition: GlobalValue.h:273
AnalysisUsage & addRequired()
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition: DataLayout.h:585
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:50
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:369
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
bool isDSOLocal() const
Definition: GlobalValue.h:283
static AnalysisKey * ID()
Returns an opaque, unique ID for this analysis type.
Definition: PassManager.h:406
Class to represent struct types.
Definition: DerivedTypes.h:238
A Use represents the edge between a Value definition and its users.
Definition: Use.h:55
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
static void computeVTableFuncs(ModuleSummaryIndex &Index, const GlobalVariable &V, const Module &M, VTableFuncList &VTableFuncs)
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Metadata.cpp:1443
This file contains the simple types necessary to represent the attributes associated with functions a...
TypeID
Definitions of all of the base types for the Type system.
Definition: Type.h:55
Legacy analysis pass which computes BlockFrequencyInfo.
uint64_t getNumElements() const
For scalable vectors, this will return the minimum number of elements in the vector.
Definition: DerivedTypes.h:398
bool remove(const value_type &X)
Remove an item from the set vector.
Definition: SetVector.h:157
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...
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:246
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
Class to represent array types.
Definition: DerivedTypes.h:408
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
Definition: Module.cpp:113
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
module summary analysis
const GlobalObject * getBaseObject() const
Definition: Globals.cpp:467
LinkageTypes getLinkage() const
Definition: GlobalValue.h:460
Type::subtype_iterator element_iterator
Definition: DerivedTypes.h:338
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:144
Value * getOperand(unsigned i) const
Definition: User.h:169
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
bool hasAppendingLinkage() const
Definition: GlobalValue.h:442
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 hasLinkOnceODRLinkage() const
Definition: GlobalValue.h:436
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:435
bool hasName() const
Definition: Value.h:252
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
A call site that could be devirtualized.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition: Module.cpp:310
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
This is an important base class in LLVM.
Definition: Constant.h:41
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:692
LLVM_NODISCARD bool empty() const
Definition: SmallPtrSet.h:91
bool returnDoesNotAlias() const
Determine if the parameter or return value is marked with NoAlias attribute.
Definition: Function.h:618
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:224
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:486
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:370
element_iterator element_end() const
Definition: DerivedTypes.h:341
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:1189
INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis", "Module Summary Analysis", false, true) INITIALIZE_PASS_END(ModuleSummaryIndexWrapperPass
TypeIdCompatibleVtableInfo & getOrInsertTypeIdCompatibleVtableSummary(StringRef TypeId)
Return an existing or new TypeIdCompatibleVtableMap entry for TypeId.
constexpr double e
Definition: MathExtras.h:57
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, DominatorTree &DT)
If this intrinsic call requires that we add information to the function summary, do so via the non-co...
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
op_range operands()
Definition: User.h:237
bool hasProfileData(bool IncludeSynthetic=false) const
Return true if the function is annotated with profile data.
Definition: Function.h:308
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:506
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 Constant * stripPointerCasts() const
Definition: Constant.h:189
Class to represent profile counts.
Definition: Function.h:260
VectorType takeVector()
Clear the MapVector and return the underlying vector.
Definition: MapVector.h:55
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
Optional< uint64_t > getProfileCount(const Instruction *CallInst, BlockFrequencyInfo *BFI, bool AllowSynthetic=false)
Returns the profile count for CallInst.
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:614
Analysis pass which computes BlockFrequencyInfo.
Vector takeVector()
Clear the SetVector and return the underlying vector.
Definition: SetVector.h:66
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:443
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser, SetVector< ValueInfo > &RefEdges, SmallPtrSet< const User *, 8 > &Visited)
cl::opt< std::string > ModuleSummaryDotFile("module-summary-dot-file", cl::init(""), cl::Hidden, cl::value_desc("filename"), cl::desc("File to emit dot graph of new summary into."))
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
Module.h This file contains the declarations for the Module class.
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:374
static void computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M, const Function &F, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, DominatorTree &DT, bool HasLocalsInUsedOrAsm, DenseSet< GlobalValue::GUID > &CantBePromoted, bool IsThinLTO)
bool hasGlobalUnnamedAddr() const
Definition: GlobalValue.h:203
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:193
BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
Result run(Module &M, ModuleAnalysisManager &AM)
amdgpu Simplify well known AMD library false FunctionCallee Callee
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:510
ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const
Return a ValueInfo for the index value_type (convenient when iterating index).
bool hasComdat() const
Definition: GlobalObject.h:119
element_iterator element_begin() const
Definition: DerivedTypes.h:340
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID)
Return a ValueInfo for GUID.
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:667
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Analysis providing branch probability information.
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:397
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:607
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
void addGlobalValueSummary(const GlobalValue &GV, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value.
Establish a view to a call site for examination.
Definition: CallSite.h:697
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
Definition: InstrTypes.h:1305
#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:222
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:332
Rename collisions when linking (static functions).
Definition: GlobalValue.h:55
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
Flags specific to function summaries.
static bool isNonVolatileLoad(const Instruction *I)
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:249
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:231
bool isCallee(Value::const_user_iterator UI) const
Determine whether the passed iterator points to the callee operand&#39;s Use.
Definition: CallSite.h:150
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()
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
LLVM Value Representation.
Definition: Value.h:74
static bool isNonVolatileStore(const Instruction *I)
A vector that has set insertion semantics.
Definition: SetVector.h:40
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.
Type * getElementType() const
Definition: DerivedTypes.h:399
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
A single uniqued string.
Definition: Metadata.h:604
A container for analyses that lazily runs them and caches their results.
static void recordTypeIdCompatibleVtableReferences(ModuleSummaryIndex &Index, const GlobalVariable &V, SmallVectorImpl< MDNode *> &Types)
Record vtable definition V for each type metadata it references.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:71
LocationClass< Ty > location(Ty &L)
Definition: CommandLine.h:451
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static CalleeInfo::HotnessType getHotness(uint64_t ProfileCount, ProfileSummaryInfo *PSI)
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:1045