LLVM  10.0.0svn
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"
49 #include "llvm/Pass.h"
50 #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 // Option to force edges cold which will block importing when the
62 // -import-cold-multiplier is set to 0. Useful for debugging.
66  "force-summary-edges-cold", cl::Hidden, cl::location(ForceSummaryEdgesCold),
67  cl::desc("Force all edges in the function summary to cold"),
70  "all-non-critical", "All non-critical edges."),
71  clEnumValN(FunctionSummary::FSHT_All, "all", "All edges.")));
72 
74  "module-summary-dot-file", cl::init(""), cl::Hidden,
75  cl::value_desc("filename"),
76  cl::desc("File to emit dot graph of new summary into."));
77 
78 // Walk through the operands of a given User via worklist iteration and populate
79 // the set of GlobalValue references encountered. Invoked either on an
80 // Instruction or a GlobalVariable (which walks its initializer).
81 // Return true if any of the operands contains blockaddress. This is important
82 // to know when computing summary for global var, because if global variable
83 // references basic block address we can't import it separately from function
84 // containing that basic block. For simplicity we currently don't import such
85 // global vars at all. When importing function we aren't interested if any
86 // instruction in it takes an address of any basic block, because instruction
87 // can only take an address of basic block located in the same function.
88 static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
89  SetVector<ValueInfo> &RefEdges,
91  bool HasBlockAddress = false;
93  Worklist.push_back(CurUser);
94 
95  while (!Worklist.empty()) {
96  const User *U = Worklist.pop_back_val();
97 
98  if (!Visited.insert(U).second)
99  continue;
100 
101  ImmutableCallSite CS(U);
102 
103  for (const auto &OI : U->operands()) {
104  const User *Operand = dyn_cast<User>(OI);
105  if (!Operand)
106  continue;
107  if (isa<BlockAddress>(Operand)) {
108  HasBlockAddress = true;
109  continue;
110  }
111  if (auto *GV = dyn_cast<GlobalValue>(Operand)) {
112  // We have a reference to a global value. This should be added to
113  // the reference set unless it is a callee. Callees are handled
114  // specially by WriteFunction and are added to a separate list.
115  if (!(CS && CS.isCallee(&OI)))
116  RefEdges.insert(Index.getOrInsertValueInfo(GV));
117  continue;
118  }
119  Worklist.push_back(Operand);
120  }
121  }
122  return HasBlockAddress;
123 }
124 
126  ProfileSummaryInfo *PSI) {
127  if (!PSI)
129  if (PSI->isHotCount(ProfileCount))
131  if (PSI->isColdCount(ProfileCount))
134 }
135 
136 static bool isNonRenamableLocal(const GlobalValue &GV) {
137  return GV.hasSection() && GV.hasLocalLinkage();
138 }
139 
140 /// Determine whether this call has all constant integer arguments (excluding
141 /// "this") and summarize it to VCalls or ConstVCalls as appropriate.
145  std::vector<uint64_t> Args;
146  // Start from the second argument to skip the "this" pointer.
147  for (auto &Arg : make_range(Call.CS.arg_begin() + 1, Call.CS.arg_end())) {
148  auto *CI = dyn_cast<ConstantInt>(Arg);
149  if (!CI || CI->getBitWidth() > 64) {
150  VCalls.insert({Guid, Call.Offset});
151  return;
152  }
153  Args.push_back(CI->getZExtValue());
154  }
155  ConstVCalls.insert({{Guid, Call.Offset}, std::move(Args)});
156 }
157 
158 /// If this intrinsic call requires that we add information to the function
159 /// summary, do so via the non-constant reference arguments.
161  const CallInst *CI, SetVector<GlobalValue::GUID> &TypeTests,
162  SetVector<FunctionSummary::VFuncId> &TypeTestAssumeVCalls,
163  SetVector<FunctionSummary::VFuncId> &TypeCheckedLoadVCalls,
164  SetVector<FunctionSummary::ConstVCall> &TypeTestAssumeConstVCalls,
165  SetVector<FunctionSummary::ConstVCall> &TypeCheckedLoadConstVCalls,
166  DominatorTree &DT) {
167  switch (CI->getCalledFunction()->getIntrinsicID()) {
168  case Intrinsic::type_test: {
169  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(1));
170  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
171  if (!TypeId)
172  break;
173  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
174 
175  // Produce a summary from type.test intrinsics. We only summarize type.test
176  // intrinsics that are used other than by an llvm.assume intrinsic.
177  // Intrinsics that are assumed are relevant only to the devirtualization
178  // pass, not the type test lowering pass.
179  bool HasNonAssumeUses = llvm::any_of(CI->uses(), [](const Use &CIU) {
180  auto *AssumeCI = dyn_cast<CallInst>(CIU.getUser());
181  if (!AssumeCI)
182  return true;
183  Function *F = AssumeCI->getCalledFunction();
184  return !F || F->getIntrinsicID() != Intrinsic::assume;
185  });
186  if (HasNonAssumeUses)
187  TypeTests.insert(Guid);
188 
189  SmallVector<DevirtCallSite, 4> DevirtCalls;
191  findDevirtualizableCallsForTypeTest(DevirtCalls, Assumes, CI, DT);
192  for (auto &Call : DevirtCalls)
193  addVCallToSet(Call, Guid, TypeTestAssumeVCalls,
194  TypeTestAssumeConstVCalls);
195 
196  break;
197  }
198 
199  case Intrinsic::type_checked_load: {
200  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(2));
201  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
202  if (!TypeId)
203  break;
204  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
205 
206  SmallVector<DevirtCallSite, 4> DevirtCalls;
209  bool HasNonCallUses = false;
210  findDevirtualizableCallsForTypeCheckedLoad(DevirtCalls, LoadedPtrs, Preds,
211  HasNonCallUses, CI, DT);
212  // Any non-call uses of the result of llvm.type.checked.load will
213  // prevent us from optimizing away the llvm.type.test.
214  if (HasNonCallUses)
215  TypeTests.insert(Guid);
216  for (auto &Call : DevirtCalls)
217  addVCallToSet(Call, Guid, TypeCheckedLoadVCalls,
218  TypeCheckedLoadConstVCalls);
219 
220  break;
221  }
222  default:
223  break;
224  }
225 }
226 
227 static bool isNonVolatileLoad(const Instruction *I) {
228  if (const auto *LI = dyn_cast<LoadInst>(I))
229  return !LI->isVolatile();
230 
231  return false;
232 }
233 
234 static bool isNonVolatileStore(const Instruction *I) {
235  if (const auto *SI = dyn_cast<StoreInst>(I))
236  return !SI->isVolatile();
237 
238  return false;
239 }
240 
242  const Function &F, BlockFrequencyInfo *BFI,
244  bool HasLocalsInUsedOrAsm,
245  DenseSet<GlobalValue::GUID> &CantBePromoted,
246  bool IsThinLTO) {
247  // Summary not currently supported for anonymous functions, they should
248  // have been named.
249  assert(F.hasName());
250 
251  unsigned NumInsts = 0;
252  // Map from callee ValueId to profile count. Used to accumulate profile
253  // counts for all static calls to a given callee.
254  MapVector<ValueInfo, CalleeInfo> CallGraphEdges;
255  SetVector<ValueInfo> RefEdges, LoadRefEdges, StoreRefEdges;
257  SetVector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
258  TypeCheckedLoadVCalls;
259  SetVector<FunctionSummary::ConstVCall> TypeTestAssumeConstVCalls,
260  TypeCheckedLoadConstVCalls;
261  ICallPromotionAnalysis ICallAnalysis;
263 
264  // Add personality function, prefix data and prologue data to function's ref
265  // list.
266  findRefEdges(Index, &F, RefEdges, Visited);
267  std::vector<const Instruction *> NonVolatileLoads;
268  std::vector<const Instruction *> NonVolatileStores;
269 
270  bool HasInlineAsmMaybeReferencingInternal = false;
271  for (const BasicBlock &BB : F)
272  for (const Instruction &I : BB) {
273  if (isa<DbgInfoIntrinsic>(I))
274  continue;
275  ++NumInsts;
276  // Regular LTO module doesn't participate in ThinLTO import,
277  // so no reference from it can be read/writeonly, since this
278  // would require importing variable as local copy
279  if (IsThinLTO) {
280  if (isNonVolatileLoad(&I)) {
281  // Postpone processing of non-volatile load instructions
282  // See comments below
283  Visited.insert(&I);
284  NonVolatileLoads.push_back(&I);
285  continue;
286  } else if (isNonVolatileStore(&I)) {
287  Visited.insert(&I);
288  NonVolatileStores.push_back(&I);
289  // All references from second operand of store (destination address)
290  // can be considered write-only if they're not referenced by any
291  // non-store instruction. References from first operand of store
292  // (stored value) can't be treated either as read- or as write-only
293  // so we add them to RefEdges as we do with all other instructions
294  // except non-volatile load.
295  Value *Stored = I.getOperand(0);
296  if (auto *GV = dyn_cast<GlobalValue>(Stored))
297  // findRefEdges will try to examine GV operands, so instead
298  // of calling it we should add GV to RefEdges directly.
299  RefEdges.insert(Index.getOrInsertValueInfo(GV));
300  else if (auto *U = dyn_cast<User>(Stored))
301  findRefEdges(Index, U, RefEdges, Visited);
302  continue;
303  }
304  }
305  findRefEdges(Index, &I, RefEdges, Visited);
306  auto CS = ImmutableCallSite(&I);
307  if (!CS)
308  continue;
309 
310  const auto *CI = dyn_cast<CallInst>(&I);
311  // Since we don't know exactly which local values are referenced in inline
312  // assembly, conservatively mark the function as possibly referencing
313  // a local value from inline assembly to ensure we don't export a
314  // reference (which would require renaming and promotion of the
315  // referenced value).
316  if (HasLocalsInUsedOrAsm && CI && CI->isInlineAsm())
317  HasInlineAsmMaybeReferencingInternal = true;
318 
319  auto *CalledValue = CS.getCalledValue();
320  auto *CalledFunction = CS.getCalledFunction();
321  if (CalledValue && !CalledFunction) {
322  CalledValue = CalledValue->stripPointerCasts();
323  // Stripping pointer casts can reveal a called function.
324  CalledFunction = dyn_cast<Function>(CalledValue);
325  }
326  // Check if this is an alias to a function. If so, get the
327  // called aliasee for the checks below.
328  if (auto *GA = dyn_cast<GlobalAlias>(CalledValue)) {
329  assert(!CalledFunction && "Expected null called function in callsite for alias");
330  CalledFunction = dyn_cast<Function>(GA->getBaseObject());
331  }
332  // Check if this is a direct call to a known function or a known
333  // intrinsic, or an indirect call with profile data.
334  if (CalledFunction) {
335  if (CI && CalledFunction->isIntrinsic()) {
337  CI, TypeTests, TypeTestAssumeVCalls, TypeCheckedLoadVCalls,
338  TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls, DT);
339  continue;
340  }
341  // We should have named any anonymous globals
342  assert(CalledFunction->hasName());
343  auto ScaledCount = PSI->getProfileCount(&I, BFI);
344  auto Hotness = ScaledCount ? getHotness(ScaledCount.getValue(), PSI)
348 
349  // Use the original CalledValue, in case it was an alias. We want
350  // to record the call edge to the alias in that case. Eventually
351  // an alias summary will be created to associate the alias and
352  // aliasee.
353  auto &ValueInfo = CallGraphEdges[Index.getOrInsertValueInfo(
354  cast<GlobalValue>(CalledValue))];
355  ValueInfo.updateHotness(Hotness);
356  // Add the relative block frequency to CalleeInfo if there is no profile
357  // information.
358  if (BFI != nullptr && Hotness == CalleeInfo::HotnessType::Unknown) {
359  uint64_t BBFreq = BFI->getBlockFreq(&BB).getFrequency();
360  uint64_t EntryFreq = BFI->getEntryFreq();
361  ValueInfo.updateRelBlockFreq(BBFreq, EntryFreq);
362  }
363  } else {
364  // Skip inline assembly calls.
365  if (CI && CI->isInlineAsm())
366  continue;
367  // Skip direct calls.
368  if (!CalledValue || isa<Constant>(CalledValue))
369  continue;
370 
371  // Check if the instruction has a callees metadata. If so, add callees
372  // to CallGraphEdges to reflect the references from the metadata, and
373  // to enable importing for subsequent indirect call promotion and
374  // inlining.
375  if (auto *MD = I.getMetadata(LLVMContext::MD_callees)) {
376  for (auto &Op : MD->operands()) {
377  Function *Callee = mdconst::extract_or_null<Function>(Op);
378  if (Callee)
379  CallGraphEdges[Index.getOrInsertValueInfo(Callee)];
380  }
381  }
382 
383  uint32_t NumVals, NumCandidates;
384  uint64_t TotalCount;
385  auto CandidateProfileData =
387  &I, NumVals, TotalCount, NumCandidates);
388  for (auto &Candidate : CandidateProfileData)
389  CallGraphEdges[Index.getOrInsertValueInfo(Candidate.Value)]
390  .updateHotness(getHotness(Candidate.Count, PSI));
391  }
392  }
393 
394  std::vector<ValueInfo> Refs;
395  if (IsThinLTO) {
396  auto AddRefEdges = [&](const std::vector<const Instruction *> &Instrs,
397  SetVector<ValueInfo> &Edges,
399  for (const auto *I : Instrs) {
400  Cache.erase(I);
401  findRefEdges(Index, I, Edges, Cache);
402  }
403  };
404 
405  // By now we processed all instructions in a function, except
406  // non-volatile loads and non-volatile value stores. Let's find
407  // ref edges for both of instruction sets
408  AddRefEdges(NonVolatileLoads, LoadRefEdges, Visited);
409  // We can add some values to the Visited set when processing load
410  // instructions which are also used by stores in NonVolatileStores.
411  // For example this can happen if we have following code:
412  //
413  // store %Derived* @foo, %Derived** bitcast (%Base** @bar to %Derived**)
414  // %42 = load %Derived*, %Derived** bitcast (%Base** @bar to %Derived**)
415  //
416  // After processing loads we'll add bitcast to the Visited set, and if
417  // we use the same set while processing stores, we'll never see store
418  // to @bar and @bar will be mistakenly treated as readonly.
420  AddRefEdges(NonVolatileStores, StoreRefEdges, StoreCache);
421 
422  // If both load and store instruction reference the same variable
423  // we won't be able to optimize it. Add all such reference edges
424  // to RefEdges set.
425  for (auto &VI : StoreRefEdges)
426  if (LoadRefEdges.remove(VI))
427  RefEdges.insert(VI);
428 
429  unsigned RefCnt = RefEdges.size();
430  // All new reference edges inserted in two loops below are either
431  // read or write only. They will be grouped in the end of RefEdges
432  // vector, so we can use a single integer value to identify them.
433  for (auto &VI : LoadRefEdges)
434  RefEdges.insert(VI);
435 
436  unsigned FirstWORef = RefEdges.size();
437  for (auto &VI : StoreRefEdges)
438  RefEdges.insert(VI);
439 
440  Refs = RefEdges.takeVector();
441  for (; RefCnt < FirstWORef; ++RefCnt)
442  Refs[RefCnt].setReadOnly();
443 
444  for (; RefCnt < Refs.size(); ++RefCnt)
445  Refs[RefCnt].setWriteOnly();
446  } else {
447  Refs = RefEdges.takeVector();
448  }
449  // Explicit add hot edges to enforce importing for designated GUIDs for
450  // sample PGO, to enable the same inlines as the profiled optimized binary.
451  for (auto &I : F.getImportGUIDs())
452  CallGraphEdges[Index.getOrInsertValueInfo(I)].updateHotness(
456 
457  bool NonRenamableLocal = isNonRenamableLocal(F);
458  bool NotEligibleForImport =
459  NonRenamableLocal || HasInlineAsmMaybeReferencingInternal;
460  GlobalValueSummary::GVFlags Flags(F.getLinkage(), NotEligibleForImport,
461  /* Live = */ false, F.isDSOLocal(),
462  F.hasLinkOnceODRLinkage() && F.hasGlobalUnnamedAddr());
463  FunctionSummary::FFlags FunFlags{
464  F.hasFnAttribute(Attribute::ReadNone),
465  F.hasFnAttribute(Attribute::ReadOnly),
466  F.hasFnAttribute(Attribute::NoRecurse), F.returnDoesNotAlias(),
467  // FIXME: refactor this to use the same code that inliner is using.
468  // Don't try to import functions with noinline attribute.
469  F.getAttributes().hasFnAttribute(Attribute::NoInline)};
470  auto FuncSummary = std::make_unique<FunctionSummary>(
471  Flags, NumInsts, FunFlags, /*EntryCount=*/0, std::move(Refs),
472  CallGraphEdges.takeVector(), TypeTests.takeVector(),
473  TypeTestAssumeVCalls.takeVector(), TypeCheckedLoadVCalls.takeVector(),
474  TypeTestAssumeConstVCalls.takeVector(),
475  TypeCheckedLoadConstVCalls.takeVector());
476  if (NonRenamableLocal)
477  CantBePromoted.insert(F.getGUID());
478  Index.addGlobalValueSummary(F, std::move(FuncSummary));
479 }
480 
481 /// Find function pointers referenced within the given vtable initializer
482 /// (or subset of an initializer) \p I. The starting offset of \p I within
483 /// the vtable initializer is \p StartingOffset. Any discovered function
484 /// pointers are added to \p VTableFuncs along with their cumulative offset
485 /// within the initializer.
486 static void findFuncPointers(const Constant *I, uint64_t StartingOffset,
487  const Module &M, ModuleSummaryIndex &Index,
488  VTableFuncList &VTableFuncs) {
489  // First check if this is a function pointer.
490  if (I->getType()->isPointerTy()) {
491  auto Fn = dyn_cast<Function>(I->stripPointerCasts());
492  // We can disregard __cxa_pure_virtual as a possible call target, as
493  // calls to pure virtuals are UB.
494  if (Fn && Fn->getName() != "__cxa_pure_virtual")
495  VTableFuncs.push_back({Index.getOrInsertValueInfo(Fn), StartingOffset});
496  return;
497  }
498 
499  // Walk through the elements in the constant struct or array and recursively
500  // look for virtual function pointers.
501  const DataLayout &DL = M.getDataLayout();
502  if (auto *C = dyn_cast<ConstantStruct>(I)) {
503  StructType *STy = dyn_cast<StructType>(C->getType());
504  assert(STy);
505  const StructLayout *SL = DL.getStructLayout(C->getType());
506 
507  for (StructType::element_iterator EB = STy->element_begin(), EI = EB,
508  EE = STy->element_end();
509  EI != EE; ++EI) {
510  auto Offset = SL->getElementOffset(EI - EB);
511  unsigned Op = SL->getElementContainingOffset(Offset);
512  findFuncPointers(cast<Constant>(I->getOperand(Op)),
513  StartingOffset + Offset, M, Index, VTableFuncs);
514  }
515  } else if (auto *C = dyn_cast<ConstantArray>(I)) {
516  ArrayType *ATy = C->getType();
517  Type *EltTy = ATy->getElementType();
518  uint64_t EltSize = DL.getTypeAllocSize(EltTy);
519  for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) {
520  findFuncPointers(cast<Constant>(I->getOperand(i)),
521  StartingOffset + i * EltSize, M, Index, VTableFuncs);
522  }
523  }
524 }
525 
526 // Identify the function pointers referenced by vtable definition \p V.
528  const GlobalVariable &V, const Module &M,
529  VTableFuncList &VTableFuncs) {
530  if (!V.isConstant())
531  return;
532 
533  findFuncPointers(V.getInitializer(), /*StartingOffset=*/0, M, Index,
534  VTableFuncs);
535 
536 #ifndef NDEBUG
537  // Validate that the VTableFuncs list is ordered by offset.
538  uint64_t PrevOffset = 0;
539  for (auto &P : VTableFuncs) {
540  // The findVFuncPointers traversal should have encountered the
541  // functions in offset order. We need to use ">=" since PrevOffset
542  // starts at 0.
543  assert(P.VTableOffset >= PrevOffset);
544  PrevOffset = P.VTableOffset;
545  }
546 #endif
547 }
548 
549 /// Record vtable definition \p V for each type metadata it references.
550 static void
552  const GlobalVariable &V,
553  SmallVectorImpl<MDNode *> &Types) {
554  for (MDNode *Type : Types) {
555  auto TypeID = Type->getOperand(1).get();
556 
557  uint64_t Offset =
558  cast<ConstantInt>(
559  cast<ConstantAsMetadata>(Type->getOperand(0))->getValue())
560  ->getZExtValue();
561 
562  if (auto *TypeId = dyn_cast<MDString>(TypeID))
563  Index.getOrInsertTypeIdCompatibleVtableSummary(TypeId->getString())
564  .push_back({Offset, Index.getOrInsertValueInfo(&V)});
565  }
566 }
567 
569  const GlobalVariable &V,
570  DenseSet<GlobalValue::GUID> &CantBePromoted,
571  const Module &M,
572  SmallVectorImpl<MDNode *> &Types) {
573  SetVector<ValueInfo> RefEdges;
575  bool HasBlockAddress = findRefEdges(Index, &V, RefEdges, Visited);
576  bool NonRenamableLocal = isNonRenamableLocal(V);
577  GlobalValueSummary::GVFlags Flags(V.getLinkage(), NonRenamableLocal,
578  /* Live = */ false, V.isDSOLocal(),
580 
581  VTableFuncList VTableFuncs;
582  // If splitting is not enabled, then we compute the summary information
583  // necessary for index-based whole program devirtualization.
584  if (!Index.enableSplitLTOUnit()) {
585  Types.clear();
586  V.getMetadata(LLVMContext::MD_type, Types);
587  if (!Types.empty()) {
588  // Identify the function pointers referenced by this vtable definition.
589  computeVTableFuncs(Index, V, M, VTableFuncs);
590 
591  // Record this vtable definition for each type metadata it references.
593  }
594  }
595 
596  // Don't mark variables we won't be able to internalize as read/write-only.
597  bool CanBeInternalized =
598  !V.hasComdat() && !V.hasAppendingLinkage() && !V.isInterposable() &&
600  GlobalVarSummary::GVarFlags VarFlags(CanBeInternalized, CanBeInternalized);
601  auto GVarSummary = std::make_unique<GlobalVarSummary>(Flags, VarFlags,
602  RefEdges.takeVector());
603  if (NonRenamableLocal)
604  CantBePromoted.insert(V.getGUID());
605  if (HasBlockAddress)
606  GVarSummary->setNotEligibleToImport();
607  if (!VTableFuncs.empty())
608  GVarSummary->setVTableFuncs(VTableFuncs);
609  Index.addGlobalValueSummary(V, std::move(GVarSummary));
610 }
611 
612 static void
614  DenseSet<GlobalValue::GUID> &CantBePromoted) {
615  bool NonRenamableLocal = isNonRenamableLocal(A);
616  GlobalValueSummary::GVFlags Flags(A.getLinkage(), NonRenamableLocal,
617  /* Live = */ false, A.isDSOLocal(),
619  auto AS = std::make_unique<AliasSummary>(Flags);
620  auto *Aliasee = A.getBaseObject();
621  auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
622  assert(AliaseeVI && "Alias expects aliasee summary to be available");
623  assert(AliaseeVI.getSummaryList().size() == 1 &&
624  "Expected a single entry per aliasee in per-module index");
625  AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
626  if (NonRenamableLocal)
627  CantBePromoted.insert(A.getGUID());
628  Index.addGlobalValueSummary(A, std::move(AS));
629 }
630 
631 // Set LiveRoot flag on entries matching the given value name.
633  if (ValueInfo VI = Index.getValueInfo(GlobalValue::getGUID(Name)))
634  for (auto &Summary : VI.getSummaryList())
635  Summary->setLive(true);
636 }
637 
639  const Module &M,
640  std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
641  ProfileSummaryInfo *PSI) {
642  assert(PSI);
643  bool EnableSplitLTOUnit = false;
644  if (auto *MD = mdconst::extract_or_null<ConstantInt>(
645  M.getModuleFlag("EnableSplitLTOUnit")))
646  EnableSplitLTOUnit = MD->getZExtValue();
647  ModuleSummaryIndex Index(/*HaveGVs=*/true, EnableSplitLTOUnit);
648 
649  // Identify the local values in the llvm.used and llvm.compiler.used sets,
650  // which should not be exported as they would then require renaming and
651  // promotion, but we may have opaque uses e.g. in inline asm. We collect them
652  // here because we use this information to mark functions containing inline
653  // assembly calls as not importable.
656  // First collect those in the llvm.used set.
657  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);
658  // Next collect those in the llvm.compiler.used set.
659  collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ true);
660  DenseSet<GlobalValue::GUID> CantBePromoted;
661  for (auto *V : Used) {
662  if (V->hasLocalLinkage()) {
663  LocalsUsed.insert(V);
664  CantBePromoted.insert(V->getGUID());
665  }
666  }
667 
668  bool HasLocalInlineAsmSymbol = false;
669  if (!M.getModuleInlineAsm().empty()) {
670  // Collect the local values defined by module level asm, and set up
671  // summaries for these symbols so that they can be marked as NoRename,
672  // to prevent export of any use of them in regular IR that would require
673  // renaming within the module level asm. Note we don't need to create a
674  // summary for weak or global defs, as they don't need to be flagged as
675  // NoRename, and defs in module level asm can't be imported anyway.
676  // Also, any values used but not defined within module level asm should
677  // be listed on the llvm.used or llvm.compiler.used global and marked as
678  // referenced from there.
681  // Symbols not marked as Weak or Global are local definitions.
682  if (Flags & (object::BasicSymbolRef::SF_Weak |
684  return;
685  HasLocalInlineAsmSymbol = true;
686  GlobalValue *GV = M.getNamedValue(Name);
687  if (!GV)
688  return;
689  assert(GV->isDeclaration() && "Def in module asm already has definition");
691  /* NotEligibleToImport = */ true,
692  /* Live = */ true,
693  /* Local */ GV->isDSOLocal(),
695  CantBePromoted.insert(GV->getGUID());
696  // Create the appropriate summary type.
697  if (Function *F = dyn_cast<Function>(GV)) {
698  std::unique_ptr<FunctionSummary> Summary =
699  std::make_unique<FunctionSummary>(
700  GVFlags, /*InstCount=*/0,
702  F->hasFnAttribute(Attribute::ReadNone),
703  F->hasFnAttribute(Attribute::ReadOnly),
704  F->hasFnAttribute(Attribute::NoRecurse),
705  F->returnDoesNotAlias(),
706  /* NoInline = */ false},
707  /*EntryCount=*/0, ArrayRef<ValueInfo>{},
714  Index.addGlobalValueSummary(*GV, std::move(Summary));
715  } else {
716  std::unique_ptr<GlobalVarSummary> Summary =
717  std::make_unique<GlobalVarSummary>(
718  GVFlags, GlobalVarSummary::GVarFlags(false, false),
720  Index.addGlobalValueSummary(*GV, std::move(Summary));
721  }
722  });
723  }
724 
725  bool IsThinLTO = true;
726  if (auto *MD =
727  mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("ThinLTO")))
728  IsThinLTO = MD->getZExtValue();
729 
730  // Compute summaries for all functions defined in module, and save in the
731  // index.
732  for (auto &F : M) {
733  if (F.isDeclaration())
734  continue;
735 
736  DominatorTree DT(const_cast<Function &>(F));
737  BlockFrequencyInfo *BFI = nullptr;
738  std::unique_ptr<BlockFrequencyInfo> BFIPtr;
739  if (GetBFICallback)
740  BFI = GetBFICallback(F);
741  else if (F.hasProfileData()) {
742  LoopInfo LI{DT};
743  BranchProbabilityInfo BPI{F, LI};
744  BFIPtr = std::make_unique<BlockFrequencyInfo>(F, BPI, LI);
745  BFI = BFIPtr.get();
746  }
747 
748  computeFunctionSummary(Index, M, F, BFI, PSI, DT,
749  !LocalsUsed.empty() || HasLocalInlineAsmSymbol,
750  CantBePromoted, IsThinLTO);
751  }
752 
753  // Compute summaries for all variables defined in module, and save in the
754  // index.
756  for (const GlobalVariable &G : M.globals()) {
757  if (G.isDeclaration())
758  continue;
759  computeVariableSummary(Index, G, CantBePromoted, M, Types);
760  }
761 
762  // Compute summaries for all aliases defined in module, and save in the
763  // index.
764  for (const GlobalAlias &A : M.aliases())
765  computeAliasSummary(Index, A, CantBePromoted);
766 
767  for (auto *V : LocalsUsed) {
768  auto *Summary = Index.getGlobalValueSummary(*V);
769  assert(Summary && "Missing summary for global value");
770  Summary->setNotEligibleToImport();
771  }
772 
773  // The linker doesn't know about these LLVM produced values, so we need
774  // to flag them as live in the index to ensure index-based dead value
775  // analysis treats them as live roots of the analysis.
776  setLiveRoot(Index, "llvm.used");
777  setLiveRoot(Index, "llvm.compiler.used");
778  setLiveRoot(Index, "llvm.global_ctors");
779  setLiveRoot(Index, "llvm.global_dtors");
780  setLiveRoot(Index, "llvm.global.annotations");
781 
782  for (auto &GlobalList : Index) {
783  // Ignore entries for references that are undefined in the current module.
784  if (GlobalList.second.SummaryList.empty())
785  continue;
786 
787  assert(GlobalList.second.SummaryList.size() == 1 &&
788  "Expected module's index to have one summary per GUID");
789  auto &Summary = GlobalList.second.SummaryList[0];
790  if (!IsThinLTO) {
791  Summary->setNotEligibleToImport();
792  continue;
793  }
794 
795  bool AllRefsCanBeExternallyReferenced =
796  llvm::all_of(Summary->refs(), [&](const ValueInfo &VI) {
797  return !CantBePromoted.count(VI.getGUID());
798  });
799  if (!AllRefsCanBeExternallyReferenced) {
800  Summary->setNotEligibleToImport();
801  continue;
802  }
803 
804  if (auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
805  bool AllCallsCanBeExternallyReferenced = llvm::all_of(
806  FuncSummary->calls(), [&](const FunctionSummary::EdgeTy &Edge) {
807  return !CantBePromoted.count(Edge.first.getGUID());
808  });
809  if (!AllCallsCanBeExternallyReferenced)
810  Summary->setNotEligibleToImport();
811  }
812  }
813 
814  if (!ModuleSummaryDotFile.empty()) {
815  std::error_code EC;
817  if (EC)
818  report_fatal_error(Twine("Failed to open dot file ") +
819  ModuleSummaryDotFile + ": " + EC.message() + "\n");
820  Index.exportToDot(OSDot);
821  }
822 
823  return Index;
824 }
825 
826 AnalysisKey ModuleSummaryIndexAnalysis::Key;
827 
831  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
833  M,
834  [&FAM](const Function &F) {
835  return &FAM.getResult<BlockFrequencyAnalysis>(
836  *const_cast<Function *>(&F));
837  },
838  &PSI);
839 }
840 
842 
843 INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis",
844  "Module Summary Analysis", false, true)
848  "Module Summary Analysis", false, true)
849 
851  return new ModuleSummaryIndexWrapperPass();
852 }
853 
855  : ModulePass(ID) {
857 }
858 
860  auto *PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
861  Index.emplace(buildModuleSummaryIndex(
862  M,
863  [this](const Function &F) {
864  return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
865  *const_cast<Function *>(&F))
866  .getBFI());
867  },
868  PSI));
869  return false;
870 }
871 
873  Index.reset();
874  return false;
875 }
876 
878  AU.setPreservesAll();
881 }
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:139
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.
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:1165
Metadata node.
Definition: Metadata.h:863
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:1241
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:41
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:1440
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:432
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:652
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:612
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(const ValueT &V)
Definition: DenseSet.h:187
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:1172
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:183
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:598
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:417
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:627
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:384
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:906
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
Definition: InstrTypes.h:1287
#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:224
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:48
A single uniqued string.
Definition: Metadata.h:603
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:448
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