LLVM  14.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/Intrinsics.h"
42 #include "llvm/IR/Metadata.h"
43 #include "llvm/IR/Module.h"
45 #include "llvm/IR/Use.h"
46 #include "llvm/IR/User.h"
47 #include "llvm/InitializePasses.h"
50 #include "llvm/Pass.h"
51 #include "llvm/Support/Casting.h"
54 #include <algorithm>
55 #include <cassert>
56 #include <cstdint>
57 #include <vector>
58 
59 using namespace llvm;
60 
61 #define DEBUG_TYPE "module-summary-analysis"
62 
63 // Option to force edges cold which will block importing when the
64 // -import-cold-multiplier is set to 0. Useful for debugging.
68  "force-summary-edges-cold", cl::Hidden, cl::location(ForceSummaryEdgesCold),
69  cl::desc("Force all edges in the function summary to cold"),
72  "all-non-critical", "All non-critical edges."),
73  clEnumValN(FunctionSummary::FSHT_All, "all", "All edges.")));
74 
76  "module-summary-dot-file", cl::init(""), cl::Hidden,
77  cl::value_desc("filename"),
78  cl::desc("File to emit dot graph of new summary into."));
79 
80 // Walk through the operands of a given User via worklist iteration and populate
81 // the set of GlobalValue references encountered. Invoked either on an
82 // Instruction or a GlobalVariable (which walks its initializer).
83 // Return true if any of the operands contains blockaddress. This is important
84 // to know when computing summary for global var, because if global variable
85 // references basic block address we can't import it separately from function
86 // containing that basic block. For simplicity we currently don't import such
87 // global vars at all. When importing function we aren't interested if any
88 // instruction in it takes an address of any basic block, because instruction
89 // can only take an address of basic block located in the same function.
90 static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
91  SetVector<ValueInfo> &RefEdges,
93  bool HasBlockAddress = false;
95  if (Visited.insert(CurUser).second)
96  Worklist.push_back(CurUser);
97 
98  while (!Worklist.empty()) {
99  const User *U = Worklist.pop_back_val();
100  const auto *CB = dyn_cast<CallBase>(U);
101 
102  for (const auto &OI : U->operands()) {
103  const User *Operand = dyn_cast<User>(OI);
104  if (!Operand)
105  continue;
106  if (isa<BlockAddress>(Operand)) {
107  HasBlockAddress = true;
108  continue;
109  }
110  if (auto *GV = dyn_cast<GlobalValue>(Operand)) {
111  // We have a reference to a global value. This should be added to
112  // the reference set unless it is a callee. Callees are handled
113  // specially by WriteFunction and are added to a separate list.
114  if (!(CB && CB->isCallee(&OI)))
115  RefEdges.insert(Index.getOrInsertValueInfo(GV));
116  continue;
117  }
118  if (Visited.insert(Operand).second)
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 : drop_begin(Call.CB.args())) {
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  return !isa<AssumeInst>(CIU.getUser());
181  });
182  if (HasNonAssumeUses)
183  TypeTests.insert(Guid);
184 
185  SmallVector<DevirtCallSite, 4> DevirtCalls;
187  findDevirtualizableCallsForTypeTest(DevirtCalls, Assumes, CI, DT);
188  for (auto &Call : DevirtCalls)
189  addVCallToSet(Call, Guid, TypeTestAssumeVCalls,
190  TypeTestAssumeConstVCalls);
191 
192  break;
193  }
194 
195  case Intrinsic::type_checked_load: {
196  auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(2));
197  auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
198  if (!TypeId)
199  break;
200  GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
201 
202  SmallVector<DevirtCallSite, 4> DevirtCalls;
205  bool HasNonCallUses = false;
206  findDevirtualizableCallsForTypeCheckedLoad(DevirtCalls, LoadedPtrs, Preds,
207  HasNonCallUses, CI, DT);
208  // Any non-call uses of the result of llvm.type.checked.load will
209  // prevent us from optimizing away the llvm.type.test.
210  if (HasNonCallUses)
211  TypeTests.insert(Guid);
212  for (auto &Call : DevirtCalls)
213  addVCallToSet(Call, Guid, TypeCheckedLoadVCalls,
214  TypeCheckedLoadConstVCalls);
215 
216  break;
217  }
218  default:
219  break;
220  }
221 }
222 
223 static bool isNonVolatileLoad(const Instruction *I) {
224  if (const auto *LI = dyn_cast<LoadInst>(I))
225  return !LI->isVolatile();
226 
227  return false;
228 }
229 
230 static bool isNonVolatileStore(const Instruction *I) {
231  if (const auto *SI = dyn_cast<StoreInst>(I))
232  return !SI->isVolatile();
233 
234  return false;
235 }
236 
238  ModuleSummaryIndex &Index, const Module &M, const Function &F,
240  bool HasLocalsInUsedOrAsm, DenseSet<GlobalValue::GUID> &CantBePromoted,
241  bool IsThinLTO,
242  std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback) {
243  // Summary not currently supported for anonymous functions, they should
244  // have been named.
245  assert(F.hasName());
246 
247  unsigned NumInsts = 0;
248  // Map from callee ValueId to profile count. Used to accumulate profile
249  // counts for all static calls to a given callee.
250  MapVector<ValueInfo, CalleeInfo> CallGraphEdges;
251  SetVector<ValueInfo> RefEdges, LoadRefEdges, StoreRefEdges;
253  SetVector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
254  TypeCheckedLoadVCalls;
255  SetVector<FunctionSummary::ConstVCall> TypeTestAssumeConstVCalls,
256  TypeCheckedLoadConstVCalls;
257  ICallPromotionAnalysis ICallAnalysis;
259 
260  // Add personality function, prefix data and prologue data to function's ref
261  // list.
262  findRefEdges(Index, &F, RefEdges, Visited);
263  std::vector<const Instruction *> NonVolatileLoads;
264  std::vector<const Instruction *> NonVolatileStores;
265 
266  bool HasInlineAsmMaybeReferencingInternal = false;
267  bool HasIndirBranchToBlockAddress = false;
268  for (const BasicBlock &BB : F) {
269  // We don't allow inlining of function with indirect branch to blockaddress.
270  // If the blockaddress escapes the function, e.g., via a global variable,
271  // inlining may lead to an invalid cross-function reference. So we shouldn't
272  // import such function either.
273  if (BB.hasAddressTaken()) {
274  for (User *U : BlockAddress::get(const_cast<BasicBlock *>(&BB))->users())
275  if (!isa<CallBrInst>(*U)) {
276  HasIndirBranchToBlockAddress = true;
277  break;
278  }
279  }
280 
281  for (const Instruction &I : BB) {
282  if (I.isDebugOrPseudoInst())
283  continue;
284  ++NumInsts;
285  // Regular LTO module doesn't participate in ThinLTO import,
286  // so no reference from it can be read/writeonly, since this
287  // would require importing variable as local copy
288  if (IsThinLTO) {
289  if (isNonVolatileLoad(&I)) {
290  // Postpone processing of non-volatile load instructions
291  // See comments below
292  Visited.insert(&I);
293  NonVolatileLoads.push_back(&I);
294  continue;
295  } else if (isNonVolatileStore(&I)) {
296  Visited.insert(&I);
297  NonVolatileStores.push_back(&I);
298  // All references from second operand of store (destination address)
299  // can be considered write-only if they're not referenced by any
300  // non-store instruction. References from first operand of store
301  // (stored value) can't be treated either as read- or as write-only
302  // so we add them to RefEdges as we do with all other instructions
303  // except non-volatile load.
304  Value *Stored = I.getOperand(0);
305  if (auto *GV = dyn_cast<GlobalValue>(Stored))
306  // findRefEdges will try to examine GV operands, so instead
307  // of calling it we should add GV to RefEdges directly.
308  RefEdges.insert(Index.getOrInsertValueInfo(GV));
309  else if (auto *U = dyn_cast<User>(Stored))
310  findRefEdges(Index, U, RefEdges, Visited);
311  continue;
312  }
313  }
314  findRefEdges(Index, &I, RefEdges, Visited);
315  const auto *CB = dyn_cast<CallBase>(&I);
316  if (!CB)
317  continue;
318 
319  const auto *CI = dyn_cast<CallInst>(&I);
320  // Since we don't know exactly which local values are referenced in inline
321  // assembly, conservatively mark the function as possibly referencing
322  // a local value from inline assembly to ensure we don't export a
323  // reference (which would require renaming and promotion of the
324  // referenced value).
325  if (HasLocalsInUsedOrAsm && CI && CI->isInlineAsm())
326  HasInlineAsmMaybeReferencingInternal = true;
327 
328  auto *CalledValue = CB->getCalledOperand();
329  auto *CalledFunction = CB->getCalledFunction();
330  if (CalledValue && !CalledFunction) {
331  CalledValue = CalledValue->stripPointerCasts();
332  // Stripping pointer casts can reveal a called function.
333  CalledFunction = dyn_cast<Function>(CalledValue);
334  }
335  // Check if this is an alias to a function. If so, get the
336  // called aliasee for the checks below.
337  if (auto *GA = dyn_cast<GlobalAlias>(CalledValue)) {
338  assert(!CalledFunction && "Expected null called function in callsite for alias");
339  CalledFunction = dyn_cast<Function>(GA->getBaseObject());
340  }
341  // Check if this is a direct call to a known function or a known
342  // intrinsic, or an indirect call with profile data.
343  if (CalledFunction) {
344  if (CI && CalledFunction->isIntrinsic()) {
346  CI, TypeTests, TypeTestAssumeVCalls, TypeCheckedLoadVCalls,
347  TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls, DT);
348  continue;
349  }
350  // We should have named any anonymous globals
351  assert(CalledFunction->hasName());
352  auto ScaledCount = PSI->getProfileCount(*CB, BFI);
353  auto Hotness = ScaledCount ? getHotness(ScaledCount.getValue(), PSI)
357 
358  // Use the original CalledValue, in case it was an alias. We want
359  // to record the call edge to the alias in that case. Eventually
360  // an alias summary will be created to associate the alias and
361  // aliasee.
362  auto &ValueInfo = CallGraphEdges[Index.getOrInsertValueInfo(
363  cast<GlobalValue>(CalledValue))];
364  ValueInfo.updateHotness(Hotness);
365  // Add the relative block frequency to CalleeInfo if there is no profile
366  // information.
367  if (BFI != nullptr && Hotness == CalleeInfo::HotnessType::Unknown) {
368  uint64_t BBFreq = BFI->getBlockFreq(&BB).getFrequency();
369  uint64_t EntryFreq = BFI->getEntryFreq();
370  ValueInfo.updateRelBlockFreq(BBFreq, EntryFreq);
371  }
372  } else {
373  // Skip inline assembly calls.
374  if (CI && CI->isInlineAsm())
375  continue;
376  // Skip direct calls.
377  if (!CalledValue || isa<Constant>(CalledValue))
378  continue;
379 
380  // Check if the instruction has a callees metadata. If so, add callees
381  // to CallGraphEdges to reflect the references from the metadata, and
382  // to enable importing for subsequent indirect call promotion and
383  // inlining.
384  if (auto *MD = I.getMetadata(LLVMContext::MD_callees)) {
385  for (auto &Op : MD->operands()) {
386  Function *Callee = mdconst::extract_or_null<Function>(Op);
387  if (Callee)
388  CallGraphEdges[Index.getOrInsertValueInfo(Callee)];
389  }
390  }
391 
392  uint32_t NumVals, NumCandidates;
393  uint64_t TotalCount;
394  auto CandidateProfileData =
396  &I, NumVals, TotalCount, NumCandidates);
397  for (auto &Candidate : CandidateProfileData)
398  CallGraphEdges[Index.getOrInsertValueInfo(Candidate.Value)]
399  .updateHotness(getHotness(Candidate.Count, PSI));
400  }
401  }
402  }
403  Index.addBlockCount(F.size());
404 
405  std::vector<ValueInfo> Refs;
406  if (IsThinLTO) {
407  auto AddRefEdges = [&](const std::vector<const Instruction *> &Instrs,
408  SetVector<ValueInfo> &Edges,
410  for (const auto *I : Instrs) {
411  Cache.erase(I);
412  findRefEdges(Index, I, Edges, Cache);
413  }
414  };
415 
416  // By now we processed all instructions in a function, except
417  // non-volatile loads and non-volatile value stores. Let's find
418  // ref edges for both of instruction sets
419  AddRefEdges(NonVolatileLoads, LoadRefEdges, Visited);
420  // We can add some values to the Visited set when processing load
421  // instructions which are also used by stores in NonVolatileStores.
422  // For example this can happen if we have following code:
423  //
424  // store %Derived* @foo, %Derived** bitcast (%Base** @bar to %Derived**)
425  // %42 = load %Derived*, %Derived** bitcast (%Base** @bar to %Derived**)
426  //
427  // After processing loads we'll add bitcast to the Visited set, and if
428  // we use the same set while processing stores, we'll never see store
429  // to @bar and @bar will be mistakenly treated as readonly.
431  AddRefEdges(NonVolatileStores, StoreRefEdges, StoreCache);
432 
433  // If both load and store instruction reference the same variable
434  // we won't be able to optimize it. Add all such reference edges
435  // to RefEdges set.
436  for (auto &VI : StoreRefEdges)
437  if (LoadRefEdges.remove(VI))
438  RefEdges.insert(VI);
439 
440  unsigned RefCnt = RefEdges.size();
441  // All new reference edges inserted in two loops below are either
442  // read or write only. They will be grouped in the end of RefEdges
443  // vector, so we can use a single integer value to identify them.
444  for (auto &VI : LoadRefEdges)
445  RefEdges.insert(VI);
446 
447  unsigned FirstWORef = RefEdges.size();
448  for (auto &VI : StoreRefEdges)
449  RefEdges.insert(VI);
450 
451  Refs = RefEdges.takeVector();
452  for (; RefCnt < FirstWORef; ++RefCnt)
453  Refs[RefCnt].setReadOnly();
454 
455  for (; RefCnt < Refs.size(); ++RefCnt)
456  Refs[RefCnt].setWriteOnly();
457  } else {
458  Refs = RefEdges.takeVector();
459  }
460  // Explicit add hot edges to enforce importing for designated GUIDs for
461  // sample PGO, to enable the same inlines as the profiled optimized binary.
462  for (auto &I : F.getImportGUIDs())
463  CallGraphEdges[Index.getOrInsertValueInfo(I)].updateHotness(
467 
468  bool NonRenamableLocal = isNonRenamableLocal(F);
469  bool NotEligibleForImport = NonRenamableLocal ||
470  HasInlineAsmMaybeReferencingInternal ||
471  HasIndirBranchToBlockAddress;
473  F.getLinkage(), F.getVisibility(), NotEligibleForImport,
474  /* Live = */ false, F.isDSOLocal(),
475  F.hasLinkOnceODRLinkage() && F.hasGlobalUnnamedAddr());
476  FunctionSummary::FFlags FunFlags{
477  F.hasFnAttribute(Attribute::ReadNone),
478  F.hasFnAttribute(Attribute::ReadOnly),
479  F.hasFnAttribute(Attribute::NoRecurse), F.returnDoesNotAlias(),
480  // FIXME: refactor this to use the same code that inliner is using.
481  // Don't try to import functions with noinline attribute.
482  F.getAttributes().hasFnAttr(Attribute::NoInline),
483  F.hasFnAttribute(Attribute::AlwaysInline)};
484  std::vector<FunctionSummary::ParamAccess> ParamAccesses;
485  if (auto *SSI = GetSSICallback(F))
486  ParamAccesses = SSI->getParamAccesses(Index);
487  auto FuncSummary = std::make_unique<FunctionSummary>(
488  Flags, NumInsts, FunFlags, /*EntryCount=*/0, std::move(Refs),
489  CallGraphEdges.takeVector(), TypeTests.takeVector(),
490  TypeTestAssumeVCalls.takeVector(), TypeCheckedLoadVCalls.takeVector(),
491  TypeTestAssumeConstVCalls.takeVector(),
492  TypeCheckedLoadConstVCalls.takeVector(), std::move(ParamAccesses));
493  if (NonRenamableLocal)
494  CantBePromoted.insert(F.getGUID());
495  Index.addGlobalValueSummary(F, std::move(FuncSummary));
496 }
497 
498 /// Find function pointers referenced within the given vtable initializer
499 /// (or subset of an initializer) \p I. The starting offset of \p I within
500 /// the vtable initializer is \p StartingOffset. Any discovered function
501 /// pointers are added to \p VTableFuncs along with their cumulative offset
502 /// within the initializer.
503 static void findFuncPointers(const Constant *I, uint64_t StartingOffset,
504  const Module &M, ModuleSummaryIndex &Index,
505  VTableFuncList &VTableFuncs) {
506  // First check if this is a function pointer.
507  if (I->getType()->isPointerTy()) {
508  auto Fn = dyn_cast<Function>(I->stripPointerCasts());
509  // We can disregard __cxa_pure_virtual as a possible call target, as
510  // calls to pure virtuals are UB.
511  if (Fn && Fn->getName() != "__cxa_pure_virtual")
512  VTableFuncs.push_back({Index.getOrInsertValueInfo(Fn), StartingOffset});
513  return;
514  }
515 
516  // Walk through the elements in the constant struct or array and recursively
517  // look for virtual function pointers.
518  const DataLayout &DL = M.getDataLayout();
519  if (auto *C = dyn_cast<ConstantStruct>(I)) {
520  StructType *STy = dyn_cast<StructType>(C->getType());
521  assert(STy);
522  const StructLayout *SL = DL.getStructLayout(C->getType());
523 
524  for (auto EI : llvm::enumerate(STy->elements())) {
525  auto Offset = SL->getElementOffset(EI.index());
526  unsigned Op = SL->getElementContainingOffset(Offset);
527  findFuncPointers(cast<Constant>(I->getOperand(Op)),
528  StartingOffset + Offset, M, Index, VTableFuncs);
529  }
530  } else if (auto *C = dyn_cast<ConstantArray>(I)) {
531  ArrayType *ATy = C->getType();
532  Type *EltTy = ATy->getElementType();
533  uint64_t EltSize = DL.getTypeAllocSize(EltTy);
534  for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) {
535  findFuncPointers(cast<Constant>(I->getOperand(i)),
536  StartingOffset + i * EltSize, M, Index, VTableFuncs);
537  }
538  }
539 }
540 
541 // Identify the function pointers referenced by vtable definition \p V.
543  const GlobalVariable &V, const Module &M,
544  VTableFuncList &VTableFuncs) {
545  if (!V.isConstant())
546  return;
547 
548  findFuncPointers(V.getInitializer(), /*StartingOffset=*/0, M, Index,
549  VTableFuncs);
550 
551 #ifndef NDEBUG
552  // Validate that the VTableFuncs list is ordered by offset.
553  uint64_t PrevOffset = 0;
554  for (auto &P : VTableFuncs) {
555  // The findVFuncPointers traversal should have encountered the
556  // functions in offset order. We need to use ">=" since PrevOffset
557  // starts at 0.
558  assert(P.VTableOffset >= PrevOffset);
559  PrevOffset = P.VTableOffset;
560  }
561 #endif
562 }
563 
564 /// Record vtable definition \p V for each type metadata it references.
565 static void
567  const GlobalVariable &V,
568  SmallVectorImpl<MDNode *> &Types) {
569  for (MDNode *Type : Types) {
570  auto TypeID = Type->getOperand(1).get();
571 
572  uint64_t Offset =
573  cast<ConstantInt>(
574  cast<ConstantAsMetadata>(Type->getOperand(0))->getValue())
575  ->getZExtValue();
576 
577  if (auto *TypeId = dyn_cast<MDString>(TypeID))
578  Index.getOrInsertTypeIdCompatibleVtableSummary(TypeId->getString())
579  .push_back({Offset, Index.getOrInsertValueInfo(&V)});
580  }
581 }
582 
584  const GlobalVariable &V,
585  DenseSet<GlobalValue::GUID> &CantBePromoted,
586  const Module &M,
587  SmallVectorImpl<MDNode *> &Types) {
588  SetVector<ValueInfo> RefEdges;
590  bool HasBlockAddress = findRefEdges(Index, &V, RefEdges, Visited);
591  bool NonRenamableLocal = isNonRenamableLocal(V);
593  V.getLinkage(), V.getVisibility(), NonRenamableLocal,
594  /* Live = */ false, V.isDSOLocal(),
596 
597  VTableFuncList VTableFuncs;
598  // If splitting is not enabled, then we compute the summary information
599  // necessary for index-based whole program devirtualization.
600  if (!Index.enableSplitLTOUnit()) {
601  Types.clear();
602  V.getMetadata(LLVMContext::MD_type, Types);
603  if (!Types.empty()) {
604  // Identify the function pointers referenced by this vtable definition.
605  computeVTableFuncs(Index, V, M, VTableFuncs);
606 
607  // Record this vtable definition for each type metadata it references.
609  }
610  }
611 
612  // Don't mark variables we won't be able to internalize as read/write-only.
613  bool CanBeInternalized =
614  !V.hasComdat() && !V.hasAppendingLinkage() && !V.isInterposable() &&
616  bool Constant = V.isConstant();
617  GlobalVarSummary::GVarFlags VarFlags(CanBeInternalized,
618  Constant ? false : CanBeInternalized,
620  auto GVarSummary = std::make_unique<GlobalVarSummary>(Flags, VarFlags,
621  RefEdges.takeVector());
622  if (NonRenamableLocal)
623  CantBePromoted.insert(V.getGUID());
624  if (HasBlockAddress)
625  GVarSummary->setNotEligibleToImport();
626  if (!VTableFuncs.empty())
627  GVarSummary->setVTableFuncs(VTableFuncs);
628  Index.addGlobalValueSummary(V, std::move(GVarSummary));
629 }
630 
631 static void
633  DenseSet<GlobalValue::GUID> &CantBePromoted) {
634  bool NonRenamableLocal = isNonRenamableLocal(A);
636  A.getLinkage(), A.getVisibility(), NonRenamableLocal,
637  /* Live = */ false, A.isDSOLocal(),
638  A.hasLinkOnceODRLinkage() && A.hasGlobalUnnamedAddr());
639  auto AS = std::make_unique<AliasSummary>(Flags);
640  auto *Aliasee = A.getBaseObject();
641  auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
642  assert(AliaseeVI && "Alias expects aliasee summary to be available");
643  assert(AliaseeVI.getSummaryList().size() == 1 &&
644  "Expected a single entry per aliasee in per-module index");
645  AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
646  if (NonRenamableLocal)
647  CantBePromoted.insert(A.getGUID());
648  Index.addGlobalValueSummary(A, std::move(AS));
649 }
650 
651 // Set LiveRoot flag on entries matching the given value name.
653  if (ValueInfo VI = Index.getValueInfo(GlobalValue::getGUID(Name)))
654  for (auto &Summary : VI.getSummaryList())
655  Summary->setLive(true);
656 }
657 
659  const Module &M,
660  std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
661  ProfileSummaryInfo *PSI,
662  std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback) {
663  assert(PSI);
664  bool EnableSplitLTOUnit = false;
665  if (auto *MD = mdconst::extract_or_null<ConstantInt>(
666  M.getModuleFlag("EnableSplitLTOUnit")))
667  EnableSplitLTOUnit = MD->getZExtValue();
668  ModuleSummaryIndex Index(/*HaveGVs=*/true, EnableSplitLTOUnit);
669 
670  // Identify the local values in the llvm.used and llvm.compiler.used sets,
671  // which should not be exported as they would then require renaming and
672  // promotion, but we may have opaque uses e.g. in inline asm. We collect them
673  // here because we use this information to mark functions containing inline
674  // assembly calls as not importable.
677  // First collect those in the llvm.used set.
678  collectUsedGlobalVariables(M, Used, /*CompilerUsed=*/false);
679  // Next collect those in the llvm.compiler.used set.
680  collectUsedGlobalVariables(M, Used, /*CompilerUsed=*/true);
681  DenseSet<GlobalValue::GUID> CantBePromoted;
682  for (auto *V : Used) {
683  if (V->hasLocalLinkage()) {
684  LocalsUsed.insert(V);
685  CantBePromoted.insert(V->getGUID());
686  }
687  }
688 
689  bool HasLocalInlineAsmSymbol = false;
690  if (!M.getModuleInlineAsm().empty()) {
691  // Collect the local values defined by module level asm, and set up
692  // summaries for these symbols so that they can be marked as NoRename,
693  // to prevent export of any use of them in regular IR that would require
694  // renaming within the module level asm. Note we don't need to create a
695  // summary for weak or global defs, as they don't need to be flagged as
696  // NoRename, and defs in module level asm can't be imported anyway.
697  // Also, any values used but not defined within module level asm should
698  // be listed on the llvm.used or llvm.compiler.used global and marked as
699  // referenced from there.
702  // Symbols not marked as Weak or Global are local definitions.
703  if (Flags & (object::BasicSymbolRef::SF_Weak |
705  return;
706  HasLocalInlineAsmSymbol = true;
707  GlobalValue *GV = M.getNamedValue(Name);
708  if (!GV)
709  return;
710  assert(GV->isDeclaration() && "Def in module asm already has definition");
713  /* NotEligibleToImport = */ true,
714  /* Live = */ true,
715  /* Local */ GV->isDSOLocal(),
717  CantBePromoted.insert(GV->getGUID());
718  // Create the appropriate summary type.
719  if (Function *F = dyn_cast<Function>(GV)) {
720  std::unique_ptr<FunctionSummary> Summary =
721  std::make_unique<FunctionSummary>(
722  GVFlags, /*InstCount=*/0,
724  F->hasFnAttribute(Attribute::ReadNone),
725  F->hasFnAttribute(Attribute::ReadOnly),
726  F->hasFnAttribute(Attribute::NoRecurse),
727  F->returnDoesNotAlias(),
728  /* NoInline = */ false,
729  F->hasFnAttribute(Attribute::AlwaysInline)},
730  /*EntryCount=*/0, ArrayRef<ValueInfo>{},
738  Index.addGlobalValueSummary(*GV, std::move(Summary));
739  } else {
740  std::unique_ptr<GlobalVarSummary> Summary =
741  std::make_unique<GlobalVarSummary>(
742  GVFlags,
744  false, false, cast<GlobalVariable>(GV)->isConstant(),
747  Index.addGlobalValueSummary(*GV, std::move(Summary));
748  }
749  });
750  }
751 
752  bool IsThinLTO = true;
753  if (auto *MD =
754  mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("ThinLTO")))
755  IsThinLTO = MD->getZExtValue();
756 
757  // Compute summaries for all functions defined in module, and save in the
758  // index.
759  for (auto &F : M) {
760  if (F.isDeclaration())
761  continue;
762 
763  DominatorTree DT(const_cast<Function &>(F));
764  BlockFrequencyInfo *BFI = nullptr;
765  std::unique_ptr<BlockFrequencyInfo> BFIPtr;
766  if (GetBFICallback)
767  BFI = GetBFICallback(F);
768  else if (F.hasProfileData()) {
769  LoopInfo LI{DT};
770  BranchProbabilityInfo BPI{F, LI};
771  BFIPtr = std::make_unique<BlockFrequencyInfo>(F, BPI, LI);
772  BFI = BFIPtr.get();
773  }
774 
775  computeFunctionSummary(Index, M, F, BFI, PSI, DT,
776  !LocalsUsed.empty() || HasLocalInlineAsmSymbol,
777  CantBePromoted, IsThinLTO, GetSSICallback);
778  }
779 
780  // Compute summaries for all variables defined in module, and save in the
781  // index.
783  for (const GlobalVariable &G : M.globals()) {
784  if (G.isDeclaration())
785  continue;
786  computeVariableSummary(Index, G, CantBePromoted, M, Types);
787  }
788 
789  // Compute summaries for all aliases defined in module, and save in the
790  // index.
791  for (const GlobalAlias &A : M.aliases())
792  computeAliasSummary(Index, A, CantBePromoted);
793 
794  for (auto *V : LocalsUsed) {
795  auto *Summary = Index.getGlobalValueSummary(*V);
796  assert(Summary && "Missing summary for global value");
797  Summary->setNotEligibleToImport();
798  }
799 
800  // The linker doesn't know about these LLVM produced values, so we need
801  // to flag them as live in the index to ensure index-based dead value
802  // analysis treats them as live roots of the analysis.
803  setLiveRoot(Index, "llvm.used");
804  setLiveRoot(Index, "llvm.compiler.used");
805  setLiveRoot(Index, "llvm.global_ctors");
806  setLiveRoot(Index, "llvm.global_dtors");
807  setLiveRoot(Index, "llvm.global.annotations");
808 
809  for (auto &GlobalList : Index) {
810  // Ignore entries for references that are undefined in the current module.
811  if (GlobalList.second.SummaryList.empty())
812  continue;
813 
814  assert(GlobalList.second.SummaryList.size() == 1 &&
815  "Expected module's index to have one summary per GUID");
816  auto &Summary = GlobalList.second.SummaryList[0];
817  if (!IsThinLTO) {
818  Summary->setNotEligibleToImport();
819  continue;
820  }
821 
822  bool AllRefsCanBeExternallyReferenced =
823  llvm::all_of(Summary->refs(), [&](const ValueInfo &VI) {
824  return !CantBePromoted.count(VI.getGUID());
825  });
826  if (!AllRefsCanBeExternallyReferenced) {
827  Summary->setNotEligibleToImport();
828  continue;
829  }
830 
831  if (auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
832  bool AllCallsCanBeExternallyReferenced = llvm::all_of(
833  FuncSummary->calls(), [&](const FunctionSummary::EdgeTy &Edge) {
834  return !CantBePromoted.count(Edge.first.getGUID());
835  });
836  if (!AllCallsCanBeExternallyReferenced)
837  Summary->setNotEligibleToImport();
838  }
839  }
840 
841  if (!ModuleSummaryDotFile.empty()) {
842  std::error_code EC;
844  if (EC)
845  report_fatal_error(Twine("Failed to open dot file ") +
846  ModuleSummaryDotFile + ": " + EC.message() + "\n");
847  Index.exportToDot(OSDot, {});
848  }
849 
850  return Index;
851 }
852 
853 AnalysisKey ModuleSummaryIndexAnalysis::Key;
854 
858  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
859  bool NeedSSI = needsParamAccessSummary(M);
861  M,
862  [&FAM](const Function &F) {
864  *const_cast<Function *>(&F));
865  },
866  &PSI,
867  [&FAM, NeedSSI](const Function &F) -> const StackSafetyInfo * {
868  return NeedSSI ? &FAM.getResult<StackSafetyAnalysis>(
869  const_cast<Function &>(F))
870  : nullptr;
871  });
872 }
873 
875 
876 INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis",
877  "Module Summary Analysis", false, true)
882  "Module Summary Analysis", false, true)
883 
885  return new ModuleSummaryIndexWrapperPass();
886 }
887 
889  : ModulePass(ID) {
891 }
892 
894  auto *PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
895  bool NeedSSI = needsParamAccessSummary(M);
896  Index.emplace(buildModuleSummaryIndex(
897  M,
898  [this](const Function &F) {
899  return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
900  *const_cast<Function *>(&F))
901  .getBFI());
902  },
903  PSI,
904  [&](const Function &F) -> const StackSafetyInfo * {
905  return NeedSSI ? &getAnalysis<StackSafetyInfoWrapperPass>(
906  const_cast<Function &>(F))
907  .getResult()
908  : nullptr;
909  }));
910  return false;
911 }
912 
914  Index.reset();
915  return false;
916 }
917 
919  AU.setPreservesAll();
923 }
924 
926 
928  const ModuleSummaryIndex *Index)
929  : ImmutablePass(ID), Index(Index) {
932 }
933 
935  AnalysisUsage &AU) const {
936  AU.setPreservesAll();
937 }
938 
940  const ModuleSummaryIndex *Index) {
942 }
943 
945  "Module summary info", false, true)
i
i
Definition: README.txt:29
StackSafetyAnalysis.h
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
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:266
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
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:238
IntrinsicInst.h
llvm::ImmutablePass
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:269
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:779
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition: GlobalValue.h:461
llvm::Function
Definition: Function.h:61
llvm::cl::location
LocationClass< Ty > location(Ty &L)
Definition: CommandLine.h:459
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:1168
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:1977
ForceSummaryEdgesCold
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
Definition: ModuleSummaryAnalysis.cpp:65
llvm::CalleeInfo::HotnessType::Cold
@ Cold
MapVector.h
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::GlobalObject::getMetadata
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Metadata.cpp:1197
llvm::GlobalAlias
Definition: GlobalAlias.h:27
llvm::ModuleSummaryIndexWrapperPass::ModuleSummaryIndexWrapperPass
ModuleSummaryIndexWrapperPass()
Definition: ModuleSummaryAnalysis.cpp:888
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
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:1032
Module.h
llvm::GlobalValue::hasSection
bool hasSection() const
Definition: GlobalValue.h:267
llvm::createImmutableModuleSummaryIndexWrapperPass
ImmutablePass * createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index)
Definition: ModuleSummaryAnalysis.cpp:939
llvm::object::BasicSymbolRef::Flags
Flags
Definition: SymbolicFile.h:106
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:77
llvm::GlobalValue::DefaultVisibility
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:63
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
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:449
llvm::FunctionSummary::FSHT_AllNonCritical
@ FSHT_AllNonCritical
Definition: ModuleSummaryIndex.h:521
STLExtras.h
llvm::SmallVectorImpl::pop_back_val
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:635
ModuleSummaryAnalysis.h
llvm::ArrayType
Class to represent array types.
Definition: DerivedTypes.h:357
llvm::object::BasicSymbolRef::SF_Weak
@ SF_Weak
Definition: SymbolicFile.h:110
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:160
Use.h
ModuleSummaryIndex.h
llvm::ICallPromotionAnalysis
Definition: IndirectCallPromotionAnalysis.h:24
llvm::StackSafetyAnalysis
StackSafetyInfo wrapper for the new pass manager.
Definition: StackSafetyAnalysis.h:89
F
#define F(x, y, z)
Definition: MD5.cpp:56
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:778
findRefEdges
static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser, SetVector< ValueInfo > &RefEdges, SmallPtrSet< const User *, 8 > &Visited)
Definition: ModuleSummaryAnalysis.cpp:90
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::GlobalValueSummary::GVFlags
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
Definition: ModuleSummaryIndex.h:296
IndirectCallPromotionAnalysis.h
computeVTableFuncs
static void computeVTableFuncs(ModuleSummaryIndex &Index, const GlobalVariable &V, const Module &M, VTableFuncList &VTableFuncs)
Definition: ModuleSummaryAnalysis.cpp:542
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:237
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
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:1547
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:294
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:228
llvm::ArrayType::getNumElements
uint64_t getNumElements() const
Definition: DerivedTypes.h:369
llvm::GlobalVarSummary::GVarFlags
Definition: ModuleSummaryIndex.h:841
llvm::GlobalValue::hasAppendingLinkage
bool hasAppendingLinkage() const
Definition: GlobalValue.h:442
getHotness
static CalleeInfo::HotnessType getHotness(uint64_t ProfileCount, ProfileSummaryInfo *PSI)
Definition: ModuleSummaryAnalysis.cpp:125
Constants.h
llvm::FunctionSummary::EdgeTy
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
Definition: ModuleSummaryIndex.h:516
llvm::User
Definition: User.h:44
Intrinsics.h
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.
Definition: InstrTypes.h:1393
llvm::BranchProbabilityInfo
Analysis providing branch probability information.
Definition: BranchProbabilityInfo.h:115
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:519
llvm::Value::uses
iterator_range< use_iterator > uses()
Definition: Value.h:377
DenseSet.h
false
Definition: StackSlotColoring.cpp:142
llvm::CalleeInfo::HotnessType
HotnessType
Definition: ModuleSummaryIndex.h:58
llvm::ModuleSummaryIndexAnalysis::run
Result run(Module &M, ModuleAnalysisManager &AM)
Definition: ModuleSummaryAnalysis.cpp:856
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:934
llvm::Instruction
Definition: Instruction.h:45
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:140
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:142
llvm::GlobalObject::VCallVisibilityPublic
@ VCallVisibilityPublic
Definition: GlobalObject.h:35
SmallPtrSet.h
llvm::ImmutableModuleSummaryIndexWrapperPass::ImmutableModuleSummaryIndexWrapperPass
ImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index=nullptr)
Definition: ModuleSummaryAnalysis.cpp:927
llvm::GlobalValue::hasGlobalUnnamedAddr
bool hasGlobalUnnamedAddr() const
Definition: GlobalValue.h:196
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:507
isNonRenamableLocal
static bool isNonRenamableLocal(const GlobalValue &GV)
Definition: ModuleSummaryAnalysis.cpp:136
llvm::ValueInfo
Struct that holds a reference to a particular GUID in a global value summary.
Definition: ModuleSummaryIndex.h:168
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:202
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:1434
llvm::GlobalValue::hasAvailableExternallyLinkage
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:432
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:136
VI
@ VI
Definition: SIInstrInfo.cpp:7679
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:699
BranchProbabilityInfo.h
llvm::ProfileSummaryInfo::isHotCount
bool isHotCount(uint64_t C) const
Returns true if count C is considered hot.
Definition: ProfileSummaryInfo.cpp:290
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::StructLayout
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition: DataLayout.h:604
uint64_t
ProfileSummaryInfo.h
llvm::GlobalValue::getVisibility
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:229
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:881
isConstant
static bool isConstant(const MachineInstr &MI)
Definition: AMDGPUInstructionSelector.cpp:2311
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:72
llvm::VTableFuncList
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
Definition: ModuleSummaryIndex.h:823
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::ProfileSummaryInfoWrapperPass
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
Definition: ProfileSummaryInfo.h:185
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:82
ArrayRef.h
computeVariableSummary
static void computeVariableSummary(ModuleSummaryIndex &Index, const GlobalVariable &V, DenseSet< GlobalValue::GUID > &CantBePromoted, const Module &M, SmallVectorImpl< MDNode * > &Types)
Definition: ModuleSummaryAnalysis.cpp:583
llvm::DevirtCallSite
A call site that could be devirtualized.
Definition: TypeMetadataUtils.h:37
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SI
StandardInstrumentations SI(Debug, VerifyEach)
llvm::GlobalValue::hasLocalLinkage
bool hasLocalLinkage() const
Definition: GlobalValue.h:445
llvm::MapVector::takeVector
VectorType takeVector()
Clear the MapVector and return the underlying vector.
Definition: MapVector.h:55
llvm::initializeModuleSummaryIndexWrapperPassPass
void initializeModuleSummaryIndexWrapperPassPass(PassRegistry &)
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::initializeImmutableModuleSummaryIndexWrapperPassPass
void initializeImmutableModuleSummaryIndexWrapperPassPass(PassRegistry &)
setLiveRoot
static void setLiveRoot(ModuleSummaryIndex &Index, StringRef Name)
Definition: ModuleSummaryAnalysis.cpp:652
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MDNode
Metadata node.
Definition: Metadata.h:901
isNonVolatileStore
static bool isNonVolatileStore(const Instruction *I)
Definition: ModuleSummaryAnalysis.cpp:230
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:563
llvm::GlobalObject::hasComdat
bool hasComdat() const
Definition: GlobalObject.h:122
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:206
llvm::ProfileSummaryAnalysis
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
Definition: ProfileSummaryInfo.h:203
ModuleSymbolTable.h
llvm::StackSafetyInfoWrapperPass
StackSafetyInfo wrapper for the legacy pass manager.
Definition: StackSafetyAnalysis.h:108
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:1083
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:1554
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:503
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:913
uint32_t
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
clEnumValN
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:674
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:566
BlockFrequencyInfo.h
llvm::FunctionSummary::FSHT_None
@ FSHT_None
Definition: ModuleSummaryIndex.h:520
llvm::AMDGPUISD::BFI
@ BFI
Definition: AMDGPUISelLowering.h:421
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:92
llvm::raw_fd_ostream
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:443
users
iv users
Definition: IVUsers.cpp:52
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:206
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::GlobalValue::hasLinkOnceODRLinkage
bool hasLinkOnceODRLinkage() const
Definition: GlobalValue.h:436
llvm::createModuleSummaryIndexWrapperPass
ModulePass * createModuleSummaryIndexWrapperPass()
Definition: ModuleSummaryAnalysis.cpp:884
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
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:262
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:95
llvm::StructType::elements
ArrayRef< Type * > elements() const
Definition: DerivedTypes.h:319
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:321
llvm::StructLayout::getElementOffset
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:634
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:511
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:658
llvm::cl::value_desc
Definition: CommandLine.h:424
llvm::orc::ReadOnly
static constexpr sys::Memory::ProtectionFlags ReadOnly
Definition: DebugObjectManagerPlugin.cpp:111
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:585
GlobalAlias.h
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:893
SmallVector.h
isNonVolatileLoad
static bool isNonVolatileLoad(const Instruction *I)
Definition: ModuleSummaryAnalysis.cpp:223
User.h
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition: ModuleSummaryIndex.h:1028
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:153
Dominators.h
llvm::FunctionSummary::FSHT_All
@ FSHT_All
Definition: ModuleSummaryIndex.h:522
llvm::CallBase::getArgOperand
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1338
llvm::SmallPtrSetImplBase::empty
LLVM_NODISCARD bool empty() const
Definition: SmallPtrSet.h:91
llvm::object::BasicSymbolRef::SF_Global
@ SF_Global
Definition: SymbolicFile.h:109
llvm::GlobalObject::getVCallVisibility
VCallVisibility getVCallVisibility() const
Definition: Metadata.cpp:1517
llvm::BlockAddress::get
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Definition: Constants.cpp:1809
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:918
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:936
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1475
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:389
llvm::Function::ProfileCount
Class to represent profile counts.
Definition: Function.h:254
llvm::cl::desc
Definition: CommandLine.h:414
llvm::SetVector
A vector that has set insertion semantics.
Definition: SetVector.h:40
llvm::GlobalValue::isDSOLocal
bool isDSOLocal() const
Definition: GlobalValue.h:282
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
InitializePasses.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
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:75
SetVector.h
computeAliasSummary
static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A, DenseSet< GlobalValue::GUID > &CantBePromoted)
Definition: ModuleSummaryAnalysis.cpp:632
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition: Use.h:44
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:364
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37
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:133