LLVM  15.0.0git
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"
30 #include "llvm/IR/Attributes.h"
31 #include "llvm/IR/BasicBlock.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/Metadata.h"
42 #include "llvm/IR/Module.h"
44 #include "llvm/IR/Use.h"
45 #include "llvm/IR/User.h"
46 #include "llvm/InitializePasses.h"
49 #include "llvm/Pass.h"
50 #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  if (Visited.insert(CurUser).second)
95  Worklist.push_back(CurUser);
96 
97  while (!Worklist.empty()) {
98  const User *U = Worklist.pop_back_val();
99  const auto *CB = dyn_cast<CallBase>(U);
100 
101  for (const auto &OI : U->operands()) {
102  const User *Operand = dyn_cast<User>(OI);
103  if (!Operand)
104  continue;
105  if (isa<BlockAddress>(Operand)) {
106  HasBlockAddress = true;
107  continue;
108  }
109  if (auto *GV = dyn_cast<GlobalValue>(Operand)) {
110  // We have a reference to a global value. This should be added to
111  // the reference set unless it is a callee. Callees are handled
112  // specially by WriteFunction and are added to a separate list.
113  if (!(CB && CB->isCallee(&OI)))
114  RefEdges.insert(Index.getOrInsertValueInfo(GV));
115  continue;
116  }
117  if (Visited.insert(Operand).second)
118  Worklist.push_back(Operand);
119  }
120  }
121  return HasBlockAddress;
122 }
123 
125  ProfileSummaryInfo *PSI) {
126  if (!PSI)
128  if (PSI->isHotCount(ProfileCount))
130  if (PSI->isColdCount(ProfileCount))
133 }
134 
135 static bool isNonRenamableLocal(const GlobalValue &GV) {
136  return GV.hasSection() && GV.hasLocalLinkage();
137 }
138 
139 /// Determine whether this call has all constant integer arguments (excluding
140 /// "this") and summarize it to VCalls or ConstVCalls as appropriate.
144  std::vector<uint64_t> Args;
145  // Start from the second argument to skip the "this" pointer.
146  for (auto &Arg : drop_begin(Call.CB.args())) {
147  auto *CI = dyn_cast<ConstantInt>(Arg);
148  if (!CI || CI->getBitWidth() > 64) {
149  VCalls.insert({Guid, Call.Offset});
150  return;
151  }
152  Args.push_back(CI->getZExtValue());
153  }
154  ConstVCalls.insert({{Guid, Call.Offset}, std::move(Args)});
155 }
156 
157 /// If this intrinsic call requires that we add information to the function
158 /// summary, do so via the non-constant reference arguments.
160  const CallInst *CI, SetVector<GlobalValue::GUID> &TypeTests,
161  SetVector<FunctionSummary::VFuncId> &TypeTestAssumeVCalls,
162  SetVector<FunctionSummary::VFuncId> &TypeCheckedLoadVCalls,
163  SetVector<FunctionSummary::ConstVCall> &TypeTestAssumeConstVCalls,
164  SetVector<FunctionSummary::ConstVCall> &TypeCheckedLoadConstVCalls,
165  DominatorTree &DT) {
166  switch (CI->getCalledFunction()->getIntrinsicID()) {
167  case Intrinsic::type_test: {
168  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(1));
169  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
170  if (!TypeId)
171  break;
172  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
173 
174  // Produce a summary from type.test intrinsics. We only summarize type.test
175  // intrinsics that are used other than by an llvm.assume intrinsic.
176  // Intrinsics that are assumed are relevant only to the devirtualization
177  // pass, not the type test lowering pass.
178  bool HasNonAssumeUses = llvm::any_of(CI->uses(), [](const Use &CIU) {
179  return !isa<AssumeInst>(CIU.getUser());
180  });
181  if (HasNonAssumeUses)
182  TypeTests.insert(Guid);
183 
184  SmallVector<DevirtCallSite, 4> DevirtCalls;
186  findDevirtualizableCallsForTypeTest(DevirtCalls, Assumes, CI, DT);
187  for (auto &Call : DevirtCalls)
188  addVCallToSet(Call, Guid, TypeTestAssumeVCalls,
189  TypeTestAssumeConstVCalls);
190 
191  break;
192  }
193 
194  case Intrinsic::type_checked_load: {
195  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(2));
196  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
197  if (!TypeId)
198  break;
199  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
200 
201  SmallVector<DevirtCallSite, 4> DevirtCalls;
204  bool HasNonCallUses = false;
205  findDevirtualizableCallsForTypeCheckedLoad(DevirtCalls, LoadedPtrs, Preds,
206  HasNonCallUses, CI, DT);
207  // Any non-call uses of the result of llvm.type.checked.load will
208  // prevent us from optimizing away the llvm.type.test.
209  if (HasNonCallUses)
210  TypeTests.insert(Guid);
211  for (auto &Call : DevirtCalls)
212  addVCallToSet(Call, Guid, TypeCheckedLoadVCalls,
213  TypeCheckedLoadConstVCalls);
214 
215  break;
216  }
217  default:
218  break;
219  }
220 }
221 
222 static bool isNonVolatileLoad(const Instruction *I) {
223  if (const auto *LI = dyn_cast<LoadInst>(I))
224  return !LI->isVolatile();
225 
226  return false;
227 }
228 
229 static bool isNonVolatileStore(const Instruction *I) {
230  if (const auto *SI = dyn_cast<StoreInst>(I))
231  return !SI->isVolatile();
232 
233  return false;
234 }
235 
236 // Returns true if the function definition must be unreachable.
237 //
238 // Note if this helper function returns true, `F` is guaranteed
239 // to be unreachable; if it returns false, `F` might still
240 // be unreachable but not covered by this helper function.
241 static bool mustBeUnreachableFunction(const Function &F) {
242  // A function must be unreachable if its entry block ends with an
243  // 'unreachable'.
244  assert(!F.isDeclaration());
245  return isa<UnreachableInst>(F.getEntryBlock().getTerminator());
246 }
247 
249  ModuleSummaryIndex &Index, const Module &M, const Function &F,
251  bool HasLocalsInUsedOrAsm, DenseSet<GlobalValue::GUID> &CantBePromoted,
252  bool IsThinLTO,
253  std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback) {
254  // Summary not currently supported for anonymous functions, they should
255  // have been named.
256  assert(F.hasName());
257 
258  unsigned NumInsts = 0;
259  // Map from callee ValueId to profile count. Used to accumulate profile
260  // counts for all static calls to a given callee.
261  MapVector<ValueInfo, CalleeInfo> CallGraphEdges;
262  SetVector<ValueInfo> RefEdges, LoadRefEdges, StoreRefEdges;
264  SetVector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
265  TypeCheckedLoadVCalls;
266  SetVector<FunctionSummary::ConstVCall> TypeTestAssumeConstVCalls,
267  TypeCheckedLoadConstVCalls;
268  ICallPromotionAnalysis ICallAnalysis;
270 
271  // Add personality function, prefix data and prologue data to function's ref
272  // list.
273  findRefEdges(Index, &F, RefEdges, Visited);
274  std::vector<const Instruction *> NonVolatileLoads;
275  std::vector<const Instruction *> NonVolatileStores;
276 
277  bool HasInlineAsmMaybeReferencingInternal = false;
278  bool HasIndirBranchToBlockAddress = false;
279  bool HasUnknownCall = false;
280  bool MayThrow = false;
281  for (const BasicBlock &BB : F) {
282  // We don't allow inlining of function with indirect branch to blockaddress.
283  // If the blockaddress escapes the function, e.g., via a global variable,
284  // inlining may lead to an invalid cross-function reference. So we shouldn't
285  // import such function either.
286  if (BB.hasAddressTaken()) {
287  for (User *U : BlockAddress::get(const_cast<BasicBlock *>(&BB))->users())
288  if (!isa<CallBrInst>(*U)) {
289  HasIndirBranchToBlockAddress = true;
290  break;
291  }
292  }
293 
294  for (const Instruction &I : BB) {
295  if (I.isDebugOrPseudoInst())
296  continue;
297  ++NumInsts;
298 
299  // Regular LTO module doesn't participate in ThinLTO import,
300  // so no reference from it can be read/writeonly, since this
301  // would require importing variable as local copy
302  if (IsThinLTO) {
303  if (isNonVolatileLoad(&I)) {
304  // Postpone processing of non-volatile load instructions
305  // See comments below
306  Visited.insert(&I);
307  NonVolatileLoads.push_back(&I);
308  continue;
309  } else if (isNonVolatileStore(&I)) {
310  Visited.insert(&I);
311  NonVolatileStores.push_back(&I);
312  // All references from second operand of store (destination address)
313  // can be considered write-only if they're not referenced by any
314  // non-store instruction. References from first operand of store
315  // (stored value) can't be treated either as read- or as write-only
316  // so we add them to RefEdges as we do with all other instructions
317  // except non-volatile load.
318  Value *Stored = I.getOperand(0);
319  if (auto *GV = dyn_cast<GlobalValue>(Stored))
320  // findRefEdges will try to examine GV operands, so instead
321  // of calling it we should add GV to RefEdges directly.
322  RefEdges.insert(Index.getOrInsertValueInfo(GV));
323  else if (auto *U = dyn_cast<User>(Stored))
324  findRefEdges(Index, U, RefEdges, Visited);
325  continue;
326  }
327  }
328  findRefEdges(Index, &I, RefEdges, Visited);
329  const auto *CB = dyn_cast<CallBase>(&I);
330  if (!CB) {
331  if (I.mayThrow())
332  MayThrow = true;
333  continue;
334  }
335 
336  const auto *CI = dyn_cast<CallInst>(&I);
337  // Since we don't know exactly which local values are referenced in inline
338  // assembly, conservatively mark the function as possibly referencing
339  // a local value from inline assembly to ensure we don't export a
340  // reference (which would require renaming and promotion of the
341  // referenced value).
342  if (HasLocalsInUsedOrAsm && CI && CI->isInlineAsm())
343  HasInlineAsmMaybeReferencingInternal = true;
344 
345  auto *CalledValue = CB->getCalledOperand();
346  auto *CalledFunction = CB->getCalledFunction();
347  if (CalledValue && !CalledFunction) {
348  CalledValue = CalledValue->stripPointerCasts();
349  // Stripping pointer casts can reveal a called function.
350  CalledFunction = dyn_cast<Function>(CalledValue);
351  }
352  // Check if this is an alias to a function. If so, get the
353  // called aliasee for the checks below.
354  if (auto *GA = dyn_cast<GlobalAlias>(CalledValue)) {
355  assert(!CalledFunction && "Expected null called function in callsite for alias");
356  CalledFunction = dyn_cast<Function>(GA->getAliaseeObject());
357  }
358  // Check if this is a direct call to a known function or a known
359  // intrinsic, or an indirect call with profile data.
360  if (CalledFunction) {
361  if (CI && CalledFunction->isIntrinsic()) {
363  CI, TypeTests, TypeTestAssumeVCalls, TypeCheckedLoadVCalls,
364  TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls, DT);
365  continue;
366  }
367  // We should have named any anonymous globals
368  assert(CalledFunction->hasName());
369  auto ScaledCount = PSI->getProfileCount(*CB, BFI);
370  auto Hotness = ScaledCount ? getHotness(ScaledCount.getValue(), PSI)
374 
375  // Use the original CalledValue, in case it was an alias. We want
376  // to record the call edge to the alias in that case. Eventually
377  // an alias summary will be created to associate the alias and
378  // aliasee.
379  auto &ValueInfo = CallGraphEdges[Index.getOrInsertValueInfo(
380  cast<GlobalValue>(CalledValue))];
381  ValueInfo.updateHotness(Hotness);
382  // Add the relative block frequency to CalleeInfo if there is no profile
383  // information.
384  if (BFI != nullptr && Hotness == CalleeInfo::HotnessType::Unknown) {
385  uint64_t BBFreq = BFI->getBlockFreq(&BB).getFrequency();
386  uint64_t EntryFreq = BFI->getEntryFreq();
387  ValueInfo.updateRelBlockFreq(BBFreq, EntryFreq);
388  }
389  } else {
390  HasUnknownCall = true;
391  // Skip inline assembly calls.
392  if (CI && CI->isInlineAsm())
393  continue;
394  // Skip direct calls.
395  if (!CalledValue || isa<Constant>(CalledValue))
396  continue;
397 
398  // Check if the instruction has a callees metadata. If so, add callees
399  // to CallGraphEdges to reflect the references from the metadata, and
400  // to enable importing for subsequent indirect call promotion and
401  // inlining.
402  if (auto *MD = I.getMetadata(LLVMContext::MD_callees)) {
403  for (auto &Op : MD->operands()) {
404  Function *Callee = mdconst::extract_or_null<Function>(Op);
405  if (Callee)
406  CallGraphEdges[Index.getOrInsertValueInfo(Callee)];
407  }
408  }
409 
410  uint32_t NumVals, NumCandidates;
411  uint64_t TotalCount;
412  auto CandidateProfileData =
414  &I, NumVals, TotalCount, NumCandidates);
415  for (auto &Candidate : CandidateProfileData)
416  CallGraphEdges[Index.getOrInsertValueInfo(Candidate.Value)]
417  .updateHotness(getHotness(Candidate.Count, PSI));
418  }
419  }
420  }
421  Index.addBlockCount(F.size());
422 
423  std::vector<ValueInfo> Refs;
424  if (IsThinLTO) {
425  auto AddRefEdges = [&](const std::vector<const Instruction *> &Instrs,
426  SetVector<ValueInfo> &Edges,
428  for (const auto *I : Instrs) {
429  Cache.erase(I);
430  findRefEdges(Index, I, Edges, Cache);
431  }
432  };
433 
434  // By now we processed all instructions in a function, except
435  // non-volatile loads and non-volatile value stores. Let's find
436  // ref edges for both of instruction sets
437  AddRefEdges(NonVolatileLoads, LoadRefEdges, Visited);
438  // We can add some values to the Visited set when processing load
439  // instructions which are also used by stores in NonVolatileStores.
440  // For example this can happen if we have following code:
441  //
442  // store %Derived* @foo, %Derived** bitcast (%Base** @bar to %Derived**)
443  // %42 = load %Derived*, %Derived** bitcast (%Base** @bar to %Derived**)
444  //
445  // After processing loads we'll add bitcast to the Visited set, and if
446  // we use the same set while processing stores, we'll never see store
447  // to @bar and @bar will be mistakenly treated as readonly.
449  AddRefEdges(NonVolatileStores, StoreRefEdges, StoreCache);
450 
451  // If both load and store instruction reference the same variable
452  // we won't be able to optimize it. Add all such reference edges
453  // to RefEdges set.
454  for (auto &VI : StoreRefEdges)
455  if (LoadRefEdges.remove(VI))
456  RefEdges.insert(VI);
457 
458  unsigned RefCnt = RefEdges.size();
459  // All new reference edges inserted in two loops below are either
460  // read or write only. They will be grouped in the end of RefEdges
461  // vector, so we can use a single integer value to identify them.
462  for (auto &VI : LoadRefEdges)
463  RefEdges.insert(VI);
464 
465  unsigned FirstWORef = RefEdges.size();
466  for (auto &VI : StoreRefEdges)
467  RefEdges.insert(VI);
468 
469  Refs = RefEdges.takeVector();
470  for (; RefCnt < FirstWORef; ++RefCnt)
471  Refs[RefCnt].setReadOnly();
472 
473  for (; RefCnt < Refs.size(); ++RefCnt)
474  Refs[RefCnt].setWriteOnly();
475  } else {
476  Refs = RefEdges.takeVector();
477  }
478  // Explicit add hot edges to enforce importing for designated GUIDs for
479  // sample PGO, to enable the same inlines as the profiled optimized binary.
480  for (auto &I : F.getImportGUIDs())
481  CallGraphEdges[Index.getOrInsertValueInfo(I)].updateHotness(
485 
486  bool NonRenamableLocal = isNonRenamableLocal(F);
487  bool NotEligibleForImport = NonRenamableLocal ||
488  HasInlineAsmMaybeReferencingInternal ||
489  HasIndirBranchToBlockAddress;
491  F.getLinkage(), F.getVisibility(), NotEligibleForImport,
492  /* Live = */ false, F.isDSOLocal(), F.canBeOmittedFromSymbolTable());
493  FunctionSummary::FFlags FunFlags{
494  F.hasFnAttribute(Attribute::ReadNone),
495  F.hasFnAttribute(Attribute::ReadOnly),
496  F.hasFnAttribute(Attribute::NoRecurse), F.returnDoesNotAlias(),
497  // FIXME: refactor this to use the same code that inliner is using.
498  // Don't try to import functions with noinline attribute.
499  F.getAttributes().hasFnAttr(Attribute::NoInline),
500  F.hasFnAttribute(Attribute::AlwaysInline),
501  F.hasFnAttribute(Attribute::NoUnwind), MayThrow, HasUnknownCall,
503  std::vector<FunctionSummary::ParamAccess> ParamAccesses;
504  if (auto *SSI = GetSSICallback(F))
505  ParamAccesses = SSI->getParamAccesses(Index);
506  auto FuncSummary = std::make_unique<FunctionSummary>(
507  Flags, NumInsts, FunFlags, /*EntryCount=*/0, std::move(Refs),
508  CallGraphEdges.takeVector(), TypeTests.takeVector(),
509  TypeTestAssumeVCalls.takeVector(), TypeCheckedLoadVCalls.takeVector(),
510  TypeTestAssumeConstVCalls.takeVector(),
511  TypeCheckedLoadConstVCalls.takeVector(), std::move(ParamAccesses));
512  if (NonRenamableLocal)
513  CantBePromoted.insert(F.getGUID());
514  Index.addGlobalValueSummary(F, std::move(FuncSummary));
515 }
516 
517 /// Find function pointers referenced within the given vtable initializer
518 /// (or subset of an initializer) \p I. The starting offset of \p I within
519 /// the vtable initializer is \p StartingOffset. Any discovered function
520 /// pointers are added to \p VTableFuncs along with their cumulative offset
521 /// within the initializer.
522 static void findFuncPointers(const Constant *I, uint64_t StartingOffset,
523  const Module &M, ModuleSummaryIndex &Index,
524  VTableFuncList &VTableFuncs) {
525  // First check if this is a function pointer.
526  if (I->getType()->isPointerTy()) {
527  auto Fn = dyn_cast<Function>(I->stripPointerCasts());
528  // We can disregard __cxa_pure_virtual as a possible call target, as
529  // calls to pure virtuals are UB.
530  if (Fn && Fn->getName() != "__cxa_pure_virtual")
531  VTableFuncs.push_back({Index.getOrInsertValueInfo(Fn), StartingOffset});
532  return;
533  }
534 
535  // Walk through the elements in the constant struct or array and recursively
536  // look for virtual function pointers.
537  const DataLayout &DL = M.getDataLayout();
538  if (auto *C = dyn_cast<ConstantStruct>(I)) {
539  StructType *STy = dyn_cast<StructType>(C->getType());
540  assert(STy);
541  const StructLayout *SL = DL.getStructLayout(C->getType());
542 
543  for (auto EI : llvm::enumerate(STy->elements())) {
544  auto Offset = SL->getElementOffset(EI.index());
545  unsigned Op = SL->getElementContainingOffset(Offset);
546  findFuncPointers(cast<Constant>(I->getOperand(Op)),
547  StartingOffset + Offset, M, Index, VTableFuncs);
548  }
549  } else if (auto *C = dyn_cast<ConstantArray>(I)) {
550  ArrayType *ATy = C->getType();
551  Type *EltTy = ATy->getElementType();
552  uint64_t EltSize = DL.getTypeAllocSize(EltTy);
553  for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) {
554  findFuncPointers(cast<Constant>(I->getOperand(i)),
555  StartingOffset + i * EltSize, M, Index, VTableFuncs);
556  }
557  }
558 }
559 
560 // Identify the function pointers referenced by vtable definition \p V.
562  const GlobalVariable &V, const Module &M,
563  VTableFuncList &VTableFuncs) {
564  if (!V.isConstant())
565  return;
566 
567  findFuncPointers(V.getInitializer(), /*StartingOffset=*/0, M, Index,
568  VTableFuncs);
569 
570 #ifndef NDEBUG
571  // Validate that the VTableFuncs list is ordered by offset.
572  uint64_t PrevOffset = 0;
573  for (auto &P : VTableFuncs) {
574  // The findVFuncPointers traversal should have encountered the
575  // functions in offset order. We need to use ">=" since PrevOffset
576  // starts at 0.
577  assert(P.VTableOffset >= PrevOffset);
578  PrevOffset = P.VTableOffset;
579  }
580 #endif
581 }
582 
583 /// Record vtable definition \p V for each type metadata it references.
584 static void
586  const GlobalVariable &V,
587  SmallVectorImpl<MDNode *> &Types) {
588  for (MDNode *Type : Types) {
589  auto TypeID = Type->getOperand(1).get();
590 
591  uint64_t Offset =
592  cast<ConstantInt>(
593  cast<ConstantAsMetadata>(Type->getOperand(0))->getValue())
594  ->getZExtValue();
595 
596  if (auto *TypeId = dyn_cast<MDString>(TypeID))
597  Index.getOrInsertTypeIdCompatibleVtableSummary(TypeId->getString())
598  .push_back({Offset, Index.getOrInsertValueInfo(&V)});
599  }
600 }
601 
603  const GlobalVariable &V,
604  DenseSet<GlobalValue::GUID> &CantBePromoted,
605  const Module &M,
606  SmallVectorImpl<MDNode *> &Types) {
607  SetVector<ValueInfo> RefEdges;
609  bool HasBlockAddress = findRefEdges(Index, &V, RefEdges, Visited);
610  bool NonRenamableLocal = isNonRenamableLocal(V);
612  V.getLinkage(), V.getVisibility(), NonRenamableLocal,
613  /* Live = */ false, V.isDSOLocal(), V.canBeOmittedFromSymbolTable());
614 
615  VTableFuncList VTableFuncs;
616  // If splitting is not enabled, then we compute the summary information
617  // necessary for index-based whole program devirtualization.
618  if (!Index.enableSplitLTOUnit()) {
619  Types.clear();
620  V.getMetadata(LLVMContext::MD_type, Types);
621  if (!Types.empty()) {
622  // Identify the function pointers referenced by this vtable definition.
623  computeVTableFuncs(Index, V, M, VTableFuncs);
624 
625  // Record this vtable definition for each type metadata it references.
627  }
628  }
629 
630  // Don't mark variables we won't be able to internalize as read/write-only.
631  bool CanBeInternalized =
632  !V.hasComdat() && !V.hasAppendingLinkage() && !V.isInterposable() &&
634  bool Constant = V.isConstant();
635  GlobalVarSummary::GVarFlags VarFlags(CanBeInternalized,
636  Constant ? false : CanBeInternalized,
638  auto GVarSummary = std::make_unique<GlobalVarSummary>(Flags, VarFlags,
639  RefEdges.takeVector());
640  if (NonRenamableLocal)
641  CantBePromoted.insert(V.getGUID());
642  if (HasBlockAddress)
643  GVarSummary->setNotEligibleToImport();
644  if (!VTableFuncs.empty())
645  GVarSummary->setVTableFuncs(VTableFuncs);
646  Index.addGlobalValueSummary(V, std::move(GVarSummary));
647 }
648 
649 static void
651  DenseSet<GlobalValue::GUID> &CantBePromoted) {
652  bool NonRenamableLocal = isNonRenamableLocal(A);
654  A.getLinkage(), A.getVisibility(), NonRenamableLocal,
655  /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
656  auto AS = std::make_unique<AliasSummary>(Flags);
657  auto *Aliasee = A.getAliaseeObject();
658  auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
659  assert(AliaseeVI && "Alias expects aliasee summary to be available");
660  assert(AliaseeVI.getSummaryList().size() == 1 &&
661  "Expected a single entry per aliasee in per-module index");
662  AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
663  if (NonRenamableLocal)
664  CantBePromoted.insert(A.getGUID());
665  Index.addGlobalValueSummary(A, std::move(AS));
666 }
667 
668 // Set LiveRoot flag on entries matching the given value name.
670  if (ValueInfo VI = Index.getValueInfo(GlobalValue::getGUID(Name)))
671  for (auto &Summary : VI.getSummaryList())
672  Summary->setLive(true);
673 }
674 
676  const Module &M,
677  std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
678  ProfileSummaryInfo *PSI,
679  std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback) {
680  assert(PSI);
681  bool EnableSplitLTOUnit = false;
682  if (auto *MD = mdconst::extract_or_null<ConstantInt>(
683  M.getModuleFlag("EnableSplitLTOUnit")))
684  EnableSplitLTOUnit = MD->getZExtValue();
685  ModuleSummaryIndex Index(/*HaveGVs=*/true, EnableSplitLTOUnit);
686 
687  // Identify the local values in the llvm.used and llvm.compiler.used sets,
688  // which should not be exported as they would then require renaming and
689  // promotion, but we may have opaque uses e.g. in inline asm. We collect them
690  // here because we use this information to mark functions containing inline
691  // assembly calls as not importable.
694  // First collect those in the llvm.used set.
695  collectUsedGlobalVariables(M, Used, /*CompilerUsed=*/false);
696  // Next collect those in the llvm.compiler.used set.
697  collectUsedGlobalVariables(M, Used, /*CompilerUsed=*/true);
698  DenseSet<GlobalValue::GUID> CantBePromoted;
699  for (auto *V : Used) {
700  if (V->hasLocalLinkage()) {
701  LocalsUsed.insert(V);
702  CantBePromoted.insert(V->getGUID());
703  }
704  }
705 
706  bool HasLocalInlineAsmSymbol = false;
707  if (!M.getModuleInlineAsm().empty()) {
708  // Collect the local values defined by module level asm, and set up
709  // summaries for these symbols so that they can be marked as NoRename,
710  // to prevent export of any use of them in regular IR that would require
711  // renaming within the module level asm. Note we don't need to create a
712  // summary for weak or global defs, as they don't need to be flagged as
713  // NoRename, and defs in module level asm can't be imported anyway.
714  // Also, any values used but not defined within module level asm should
715  // be listed on the llvm.used or llvm.compiler.used global and marked as
716  // referenced from there.
719  // Symbols not marked as Weak or Global are local definitions.
720  if (Flags & (object::BasicSymbolRef::SF_Weak |
722  return;
723  HasLocalInlineAsmSymbol = true;
724  GlobalValue *GV = M.getNamedValue(Name);
725  if (!GV)
726  return;
727  assert(GV->isDeclaration() && "Def in module asm already has definition");
730  /* NotEligibleToImport = */ true,
731  /* Live = */ true,
732  /* Local */ GV->isDSOLocal(), GV->canBeOmittedFromSymbolTable());
733  CantBePromoted.insert(GV->getGUID());
734  // Create the appropriate summary type.
735  if (Function *F = dyn_cast<Function>(GV)) {
736  std::unique_ptr<FunctionSummary> Summary =
737  std::make_unique<FunctionSummary>(
738  GVFlags, /*InstCount=*/0,
740  F->hasFnAttribute(Attribute::ReadNone),
741  F->hasFnAttribute(Attribute::ReadOnly),
742  F->hasFnAttribute(Attribute::NoRecurse),
743  F->returnDoesNotAlias(),
744  /* NoInline = */ false,
745  F->hasFnAttribute(Attribute::AlwaysInline),
746  F->hasFnAttribute(Attribute::NoUnwind),
747  /* MayThrow */ true,
748  /* HasUnknownCall */ true,
749  /* MustBeUnreachable */ false},
750  /*EntryCount=*/0, ArrayRef<ValueInfo>{},
758  Index.addGlobalValueSummary(*GV, std::move(Summary));
759  } else {
760  std::unique_ptr<GlobalVarSummary> Summary =
761  std::make_unique<GlobalVarSummary>(
762  GVFlags,
764  false, false, cast<GlobalVariable>(GV)->isConstant(),
767  Index.addGlobalValueSummary(*GV, std::move(Summary));
768  }
769  });
770  }
771 
772  bool IsThinLTO = true;
773  if (auto *MD =
774  mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("ThinLTO")))
775  IsThinLTO = MD->getZExtValue();
776 
777  // Compute summaries for all functions defined in module, and save in the
778  // index.
779  for (auto &F : M) {
780  if (F.isDeclaration())
781  continue;
782 
783  DominatorTree DT(const_cast<Function &>(F));
784  BlockFrequencyInfo *BFI = nullptr;
785  std::unique_ptr<BlockFrequencyInfo> BFIPtr;
786  if (GetBFICallback)
787  BFI = GetBFICallback(F);
788  else if (F.hasProfileData()) {
789  LoopInfo LI{DT};
790  BranchProbabilityInfo BPI{F, LI};
791  BFIPtr = std::make_unique<BlockFrequencyInfo>(F, BPI, LI);
792  BFI = BFIPtr.get();
793  }
794 
795  computeFunctionSummary(Index, M, F, BFI, PSI, DT,
796  !LocalsUsed.empty() || HasLocalInlineAsmSymbol,
797  CantBePromoted, IsThinLTO, GetSSICallback);
798  }
799 
800  // Compute summaries for all variables defined in module, and save in the
801  // index.
803  for (const GlobalVariable &G : M.globals()) {
804  if (G.isDeclaration())
805  continue;
806  computeVariableSummary(Index, G, CantBePromoted, M, Types);
807  }
808 
809  // Compute summaries for all aliases defined in module, and save in the
810  // index.
811  for (const GlobalAlias &A : M.aliases())
812  computeAliasSummary(Index, A, CantBePromoted);
813 
814  for (auto *V : LocalsUsed) {
815  auto *Summary = Index.getGlobalValueSummary(*V);
816  assert(Summary && "Missing summary for global value");
817  Summary->setNotEligibleToImport();
818  }
819 
820  // The linker doesn't know about these LLVM produced values, so we need
821  // to flag them as live in the index to ensure index-based dead value
822  // analysis treats them as live roots of the analysis.
823  setLiveRoot(Index, "llvm.used");
824  setLiveRoot(Index, "llvm.compiler.used");
825  setLiveRoot(Index, "llvm.global_ctors");
826  setLiveRoot(Index, "llvm.global_dtors");
827  setLiveRoot(Index, "llvm.global.annotations");
828 
829  for (auto &GlobalList : Index) {
830  // Ignore entries for references that are undefined in the current module.
831  if (GlobalList.second.SummaryList.empty())
832  continue;
833 
834  assert(GlobalList.second.SummaryList.size() == 1 &&
835  "Expected module's index to have one summary per GUID");
836  auto &Summary = GlobalList.second.SummaryList[0];
837  if (!IsThinLTO) {
838  Summary->setNotEligibleToImport();
839  continue;
840  }
841 
842  bool AllRefsCanBeExternallyReferenced =
843  llvm::all_of(Summary->refs(), [&](const ValueInfo &VI) {
844  return !CantBePromoted.count(VI.getGUID());
845  });
846  if (!AllRefsCanBeExternallyReferenced) {
847  Summary->setNotEligibleToImport();
848  continue;
849  }
850 
851  if (auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
852  bool AllCallsCanBeExternallyReferenced = llvm::all_of(
853  FuncSummary->calls(), [&](const FunctionSummary::EdgeTy &Edge) {
854  return !CantBePromoted.count(Edge.first.getGUID());
855  });
856  if (!AllCallsCanBeExternallyReferenced)
857  Summary->setNotEligibleToImport();
858  }
859  }
860 
861  if (!ModuleSummaryDotFile.empty()) {
862  std::error_code EC;
864  if (EC)
865  report_fatal_error(Twine("Failed to open dot file ") +
866  ModuleSummaryDotFile + ": " + EC.message() + "\n");
867  Index.exportToDot(OSDot, {});
868  }
869 
870  return Index;
871 }
872 
873 AnalysisKey ModuleSummaryIndexAnalysis::Key;
874 
878  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
879  bool NeedSSI = needsParamAccessSummary(M);
881  M,
882  [&FAM](const Function &F) {
884  *const_cast<Function *>(&F));
885  },
886  &PSI,
887  [&FAM, NeedSSI](const Function &F) -> const StackSafetyInfo * {
888  return NeedSSI ? &FAM.getResult<StackSafetyAnalysis>(
889  const_cast<Function &>(F))
890  : nullptr;
891  });
892 }
893 
895 
896 INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis",
897  "Module Summary Analysis", false, true)
902  "Module Summary Analysis", false, true)
903 
905  return new ModuleSummaryIndexWrapperPass();
906 }
907 
909  : ModulePass(ID) {
911 }
912 
914  auto *PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
915  bool NeedSSI = needsParamAccessSummary(M);
916  Index.emplace(buildModuleSummaryIndex(
917  M,
918  [this](const Function &F) {
919  return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
920  *const_cast<Function *>(&F))
921  .getBFI());
922  },
923  PSI,
924  [&](const Function &F) -> const StackSafetyInfo * {
925  return NeedSSI ? &getAnalysis<StackSafetyInfoWrapperPass>(
926  const_cast<Function &>(F))
927  .getResult()
928  : nullptr;
929  }));
930  return false;
931 }
932 
934  Index.reset();
935  return false;
936 }
937 
939  AU.setPreservesAll();
943 }
944 
946 
948  const ModuleSummaryIndex *Index)
949  : ImmutablePass(ID), Index(Index) {
952 }
953 
955  AnalysisUsage &AU) const {
956  AU.setPreservesAll();
957 }
958 
960  const ModuleSummaryIndex *Index) {
961  return new ImmutableModuleSummaryIndexWrapperPass(Index);
962 }
963 
965  "Module summary info", false, true)
i
i
Definition: README.txt:29
StackSafetyAnalysis.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::drop_begin
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition: STLExtras.h:280
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
FileSystem.h
llvm::sys::fs::OF_None
@ OF_None
Definition: FileSystem.h:757
Metadata.h
llvm::User::operands
op_range operands()
Definition: User.h:242
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis", "Module Summary Analysis", false, true) INITIALIZE_PASS_END(ModuleSummaryIndexWrapperPass
llvm::ModulePass
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:248
IntrinsicInst.h
llvm::ImmutablePass
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:279
llvm::AnalysisManager::getResult
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:780
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition: GlobalValue.h:466
llvm::Function
Definition: Function.h:60
llvm::cl::location
LocationClass< Ty > location(Ty &L)
Definition: CommandLine.h:447
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
Pass.h
llvm::BlockFrequencyInfoWrapperPass
Legacy analysis pass which computes BlockFrequencyInfo.
Definition: BlockFrequencyInfo.h:138
llvm::SetVector::size
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:77
ModuleSummaryDotFile
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."))
llvm::ImmutableModuleSummaryIndexWrapperPass
Legacy wrapper pass to provide the ModuleSummaryIndex object.
Definition: ModuleSummaryAnalysis.h:82
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::enumerate
detail::enumerator< R > enumerate(R &&TheRange)
Given an input range, returns a new range whose values are are pair (A,B) such that A is the 0-based ...
Definition: STLExtras.h:2045
ForceSummaryEdgesCold
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
Definition: ModuleSummaryAnalysis.cpp:64
llvm::CalleeInfo::HotnessType::Cold
@ Cold
MapVector.h
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::GlobalObject::getMetadata
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Metadata.cpp:1229
llvm::GlobalAlias
Definition: GlobalAlias.h:28
llvm::ModuleSummaryIndexWrapperPass::ModuleSummaryIndexWrapperPass
ModuleSummaryIndexWrapperPass()
Definition: ModuleSummaryAnalysis.cpp:908
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:139
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1909
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::needsParamAccessSummary
bool needsParamAccessSummary(const Module &M)
Definition: StackSafetyAnalysis.cpp:1094
Module.h
llvm::GlobalValue::hasSection
bool hasSection() const
Definition: GlobalValue.h:266
llvm::createImmutableModuleSummaryIndexWrapperPass
ImmutablePass * createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index)
Definition: ModuleSummaryAnalysis.cpp:959
llvm::object::BasicSymbolRef::Flags
Flags
Definition: SymbolicFile.h:108
llvm::ProfileSummaryInfo::getProfileCount
Optional< uint64_t > getProfileCount(const CallBase &CallInst, BlockFrequencyInfo *BFI, bool AllowSynthetic=false) const
Returns the profile count for CallInst.
Definition: ProfileSummaryInfo.cpp:76
llvm::GlobalValue::DefaultVisibility
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:63
llvm::MapVector
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:37
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:450
llvm::FunctionSummary::FSHT_AllNonCritical
@ FSHT_AllNonCritical
Definition: ModuleSummaryIndex.h:520
STLExtras.h
llvm::SmallVectorImpl::pop_back_val
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:654
ModuleSummaryAnalysis.h
llvm::ArrayType
Class to represent array types.
Definition: DerivedTypes.h:357
llvm::object::BasicSymbolRef::SF_Weak
@ SF_Weak
Definition: SymbolicFile.h:112
SymbolicFile.h
llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
addIntrinsicToSummary
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...
Definition: ModuleSummaryAnalysis.cpp:159
Use.h
ModuleSummaryIndex.h
llvm::ICallPromotionAnalysis
Definition: IndirectCallPromotionAnalysis.h:24
llvm::StackSafetyAnalysis
StackSafetyInfo wrapper for the new pass manager.
Definition: StackSafetyAnalysis.h:92
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::collectUsedGlobalVariables
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
Definition: Module.cpp:786
findRefEdges
static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser, SetVector< ValueInfo > &RefEdges, SmallPtrSet< const User *, 8 > &Visited)
Definition: ModuleSummaryAnalysis.cpp:89
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
llvm::GlobalValueSummary::GVFlags
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
Definition: ModuleSummaryIndex.h:295
IndirectCallPromotionAnalysis.h
computeVTableFuncs
static void computeVTableFuncs(ModuleSummaryIndex &Index, const GlobalVariable &V, const Module &M, VTableFuncList &VTableFuncs)
Definition: ModuleSummaryAnalysis.cpp:561
computeFunctionSummary
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, std::function< const StackSafetyInfo *(const Function &F)> GetSSICallback)
Definition: ModuleSummaryAnalysis.cpp:248
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:186
CommandLine.h
llvm::ImmutableModuleSummaryIndexWrapperPass::ID
static char ID
Definition: ModuleSummaryAnalysis.h:86
llvm::SetVector::remove
bool remove(const value_type &X)
Remove an item from the set vector.
Definition: SetVector.h:157
llvm::all_of
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:1605
llvm::BlockFrequencyInfo
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Definition: BlockFrequencyInfo.h:37
llvm::ProfileSummaryInfo::isColdCount
bool isColdCount(uint64_t C) const
Returns true if count C is considered cold.
Definition: ProfileSummaryInfo.cpp:293
GlobalValue.h
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::GlobalValue::isDeclaration
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:241
llvm::ArrayType::getNumElements
uint64_t getNumElements() const
Definition: DerivedTypes.h:369
llvm::GlobalVarSummary::GVarFlags
Definition: ModuleSummaryIndex.h:900
llvm::GlobalValue::hasAppendingLinkage
bool hasAppendingLinkage() const
Definition: GlobalValue.h:447
getHotness
static CalleeInfo::HotnessType getHotness(uint64_t ProfileCount, ProfileSummaryInfo *PSI)
Definition: ModuleSummaryAnalysis.cpp:124
Constants.h
llvm::FunctionSummary::EdgeTy
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
Definition: ModuleSummaryIndex.h:515
llvm::User
Definition: User.h:44
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1396
llvm::BranchProbabilityInfo
Analysis providing branch probability information.
Definition: BranchProbabilityInfo.h:113
INITIALIZE_PASS
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:37
TypeMetadataUtils.h
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::FunctionSummary::ForceSummaryHotnessType
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
Definition: ModuleSummaryIndex.h:518
llvm::Value::uses
iterator_range< use_iterator > uses()
Definition: Value.h:376
DenseSet.h
false
Definition: StackSlotColoring.cpp:141
llvm::CalleeInfo::HotnessType
HotnessType
Definition: ModuleSummaryIndex.h:57
llvm::ModuleSummaryIndexAnalysis::run
Result run(Module &M, ModuleAnalysisManager &AM)
Definition: ModuleSummaryAnalysis.cpp:876
llvm::ImmutableModuleSummaryIndexWrapperPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: ModuleSummaryAnalysis.cpp:954
llvm::Instruction
Definition: Instruction.h:42
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:143
addVCallToSet
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...
Definition: ModuleSummaryAnalysis.cpp:141
llvm::GlobalObject::VCallVisibilityPublic
@ VCallVisibilityPublic
Definition: GlobalObject.h:34
SmallPtrSet.h
llvm::ImmutableModuleSummaryIndexWrapperPass::ImmutableModuleSummaryIndexWrapperPass
ImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index=nullptr)
Definition: ModuleSummaryAnalysis.cpp:947
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:55
llvm::BlockFrequencyAnalysis
Analysis pass which computes BlockFrequencyInfo.
Definition: BlockFrequencyInfo.h:112
llvm::GlobalValue::getGUID
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:512
isNonRenamableLocal
static bool isNonRenamableLocal(const GlobalValue &GV)
Definition: ModuleSummaryAnalysis.cpp:135
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::ValueInfo
Struct that holds a reference to a particular GUID in a global value summary.
Definition: ModuleSummaryIndex.h:167
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::CalleeInfo::HotnessType::None
@ None
LoopInfo.h
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition: ProfileSummaryInfo.h:39
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:200
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
FSEC
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.")))
BasicBlock.h
llvm::cl::opt
Definition: CommandLine.h:1392
llvm::GlobalValue::hasAvailableExternallyLinkage
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:434
llvm::CalleeInfo::HotnessType::Hot
@ Hot
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::GlobalVariable::getInitializer
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Definition: GlobalVariable.h:135
VI
@ VI
Definition: SIInstrInfo.cpp:7830
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::cl::values
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:685
BranchProbabilityInfo.h
llvm::ProfileSummaryInfo::isHotCount
bool isHotCount(uint64_t C) const
Returns true if count C is considered hot.
Definition: ProfileSummaryInfo.cpp:289
llvm::StructLayout
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition: DataLayout.h:622
uint64_t
ProfileSummaryInfo.h
llvm::GlobalValue::getVisibility
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:228
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::ModuleSummaryIndexWrapperPass::ID
static char ID
Definition: ModuleSummaryAnalysis.h:61
analysis
module summary analysis
Definition: ModuleSummaryAnalysis.cpp:901
isConstant
static bool isConstant(const MachineInstr &MI)
Definition: AMDGPUInstructionSelector.cpp:2299
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:69
llvm::VTableFuncList
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
Definition: ModuleSummaryIndex.h:882
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:432
llvm::ProfileSummaryInfoWrapperPass
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
Definition: ProfileSummaryInfo.h:193
llvm::StructLayout::getElementContainingOffset
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it.
Definition: DataLayout.cpp:83
ArrayRef.h
computeVariableSummary
static void computeVariableSummary(ModuleSummaryIndex &Index, const GlobalVariable &V, DenseSet< GlobalValue::GUID > &CantBePromoted, const Module &M, SmallVectorImpl< MDNode * > &Types)
Definition: ModuleSummaryAnalysis.cpp:602
llvm::DevirtCallSite
A call site that could be devirtualized.
Definition: TypeMetadataUtils.h:38
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SI
StandardInstrumentations SI(Debug, VerifyEach)
llvm::GlobalValue::hasLocalLinkage
bool hasLocalLinkage() const
Definition: GlobalValue.h:450
llvm::MapVector::takeVector
VectorType takeVector()
Clear the MapVector and return the underlying vector.
Definition: MapVector.h:56
llvm::initializeModuleSummaryIndexWrapperPassPass
void initializeModuleSummaryIndexWrapperPassPass(PassRegistry &)
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::initializeImmutableModuleSummaryIndexWrapperPassPass
void initializeImmutableModuleSummaryIndexWrapperPassPass(PassRegistry &)
setLiveRoot
static void setLiveRoot(ModuleSummaryIndex &Index, StringRef Name)
Definition: ModuleSummaryAnalysis.cpp:669
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MDNode
Metadata node.
Definition: Metadata.h:926
isNonVolatileStore
static bool isNonVolatileStore(const Instruction *I)
Definition: ModuleSummaryAnalysis.cpp:229
llvm::StackSafetyInfo
Interface to access stack safety analysis results for single function.
Definition: StackSafetyAnalysis.h:26
llvm::FunctionSummary::FFlags
Flags specific to function summaries.
Definition: ModuleSummaryIndex.h:562
llvm::GlobalObject::hasComdat
bool hasComdat() const
Definition: GlobalObject.h:121
llvm::SetVector::insert
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
llvm::Function::getIntrinsicID
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:205
llvm::ProfileSummaryAnalysis
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
Definition: ProfileSummaryInfo.h:211
ModuleSymbolTable.h
llvm::GlobalValue::canBeOmittedFromSymbolTable
bool canBeOmittedFromSymbolTable() const
True if GV can be left out of the object symbol table.
Definition: Globals.cpp:354
llvm::StackSafetyInfoWrapperPass
StackSafetyInfo wrapper for the legacy pass manager.
Definition: StackSafetyAnalysis.h:111
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::LoopInfo
Definition: LoopInfo.h:1086
llvm::CalleeInfo::HotnessType::Unknown
@ Unknown
llvm::any_of
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:1612
llvm::StructType
Class to represent struct types.
Definition: DerivedTypes.h:213
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
findFuncPointers
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...
Definition: ModuleSummaryAnalysis.cpp:522
llvm::ModuleSummaryIndexWrapperPass::doFinalization
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: ModuleSummaryAnalysis.cpp:933
uint32_t
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
clEnumValN
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:660
recordTypeIdCompatibleVtableReferences
static void recordTypeIdCompatibleVtableReferences(ModuleSummaryIndex &Index, const GlobalVariable &V, SmallVectorImpl< MDNode * > &Types)
Record vtable definition V for each type metadata it references.
Definition: ModuleSummaryAnalysis.cpp:585
BlockFrequencyInfo.h
llvm::FunctionSummary::FSHT_None
@ FSHT_None
Definition: ModuleSummaryIndex.h:519
llvm::AMDGPUISD::BFI
@ BFI
Definition: AMDGPUISelLowering.h:429
llvm::ICallPromotionAnalysis::getPromotionCandidatesForInstruction
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.
Definition: IndirectCallPromotionAnalysis.cpp:87
llvm::raw_fd_ostream
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:444
users
iv users
Definition: IVUsers.cpp:48
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:186
llvm::GlobalValue::isInterposable
bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
Definition: Globals.cpp:98
llvm::CalleeInfo::HotnessType::Critical
@ Critical
Attributes.h
Constant.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::createModuleSummaryIndexWrapperPass
ModulePass * createModuleSummaryIndexWrapperPass()
Definition: ModuleSummaryAnalysis.cpp:904
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
llvm::GlobalValue::hasDLLExportStorageClass
bool hasDLLExportStorageClass() const
Definition: GlobalValue.h:261
llvm::findDevirtualizableCallsForTypeCheckedLoad
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...
Definition: TypeMetadataUtils.cpp:94
llvm::StructType::elements
ArrayRef< Type * > elements() const
Definition: DerivedTypes.h:319
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:326
llvm::StructLayout::getElementOffset
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:652
GlobalVariable.h
llvm::GlobalValue::getGUID
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:516
Casting.h
Function.h
llvm::buildModuleSummaryIndex
ModuleSummaryIndex buildModuleSummaryIndex(const Module &M, std::function< BlockFrequencyInfo *(const Function &F)> GetBFICallback, ProfileSummaryInfo *PSI, std::function< const StackSafetyInfo *(const Function &F)> GetSSICallback=[](const Function &F) -> const StackSafetyInfo *{ return nullptr;})
Direct function to compute a ModuleSummaryIndex from a given module.
Definition: ModuleSummaryAnalysis.cpp:675
llvm::cl::value_desc
Definition: CommandLine.h:414
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:591
GlobalAlias.h
mustBeUnreachableFunction
static bool mustBeUnreachableFunction(const Function &F)
Definition: ModuleSummaryAnalysis.cpp:241
Instructions.h
llvm::ModuleSummaryIndexWrapperPass::runOnModule
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
Definition: ModuleSummaryAnalysis.cpp:913
SmallVector.h
isNonVolatileLoad
static bool isNonVolatileLoad(const Instruction *I)
Definition: ModuleSummaryAnalysis.cpp:222
User.h
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition: ModuleSummaryIndex.h:1087
llvm::GlobalVariable::isConstant
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
Definition: GlobalVariable.h:152
Dominators.h
llvm::FunctionSummary::FSHT_All
@ FSHT_All
Definition: ModuleSummaryIndex.h:521
llvm::CallBase::getArgOperand
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1341
llvm::SmallPtrSetImplBase::empty
LLVM_NODISCARD bool empty() const
Definition: SmallPtrSet.h:92
llvm::object::BasicSymbolRef::SF_Global
@ SF_Global
Definition: SymbolicFile.h:111
llvm::GlobalObject::getVCallVisibility
VCallVisibility getVCallVisibility() const
Definition: Metadata.cpp:1558
llvm::BlockAddress::get
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Definition: Constants.cpp:1807
llvm::ModuleSummaryIndexWrapperPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: ModuleSummaryAnalysis.cpp:938
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:937
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1474
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::SetVector::takeVector
Vector takeVector()
Clear the SetVector and return the underlying vector.
Definition: SetVector.h:66
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::ModuleSummaryIndexWrapperPass
Legacy wrapper pass to provide the ModuleSummaryIndex object.
Definition: ModuleSummaryAnalysis.h:57
llvm::Type::TypeID
TypeID
Definitions of all of the base types for the Type system.
Definition: Type.h:54
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::Function::ProfileCount
Class to represent profile counts.
Definition: Function.h:253
llvm::cl::desc
Definition: CommandLine.h:405
llvm::SetVector
A vector that has set insertion semantics.
Definition: SetVector.h:40
llvm::GlobalValue::isDSOLocal
bool isDSOLocal() const
Definition: GlobalValue.h:281
InitializePasses.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::ArrayType::getElementType
Type * getElementType() const
Definition: DerivedTypes.h:370
llvm::findDevirtualizableCallsForTypeTest
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 ...
Definition: TypeMetadataUtils.cpp:74
SetVector.h
computeAliasSummary
static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, DenseSet< GlobalValue::GUID > &CantBePromoted)
Definition: ModuleSummaryAnalysis.cpp:650
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
llvm::SmallPtrSetImpl::insert
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:365
llvm::ModuleSymbolTable::CollectAsmSymbols
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.
Definition: ModuleSymbolTable.cpp:130