LLVM  13.0.0git
InstrProfiling.cpp
Go to the documentation of this file.
1 //===-- InstrProfiling.cpp - Frontend instrumentation based profiling -----===//
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 lowers instrprof_* intrinsics emitted by a frontend for profiling.
10 // It also builds the data structures and initialization code needed for
11 // updating execution counts and emitting the profile at runtime.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/ADT/Twine.h"
23 #include "llvm/Analysis/LoopInfo.h"
25 #include "llvm/IR/Attributes.h"
26 #include "llvm/IR/BasicBlock.h"
27 #include "llvm/IR/Constant.h"
28 #include "llvm/IR/Constants.h"
29 #include "llvm/IR/DerivedTypes.h"
30 #include "llvm/IR/Dominators.h"
31 #include "llvm/IR/Function.h"
32 #include "llvm/IR/GlobalValue.h"
33 #include "llvm/IR/GlobalVariable.h"
34 #include "llvm/IR/IRBuilder.h"
35 #include "llvm/IR/Instruction.h"
36 #include "llvm/IR/Instructions.h"
37 #include "llvm/IR/IntrinsicInst.h"
38 #include "llvm/IR/Module.h"
39 #include "llvm/IR/Type.h"
40 #include "llvm/InitializePasses.h"
41 #include "llvm/Pass.h"
43 #include "llvm/Support/Casting.h"
45 #include "llvm/Support/Error.h"
50 #include <algorithm>
51 #include <cassert>
52 #include <cstddef>
53 #include <cstdint>
54 #include <string>
55 
56 using namespace llvm;
57 
58 #define DEBUG_TYPE "instrprof"
59 
60 namespace {
61 
62 cl::opt<bool> DoHashBasedCounterSplit(
63  "hash-based-counter-split",
64  cl::desc("Rename counter variable of a comdat function based on cfg hash"),
65  cl::init(true));
66 
67 cl::opt<bool> RuntimeCounterRelocation(
68  "runtime-counter-relocation",
69  cl::desc("Enable relocating counters at runtime."),
70  cl::init(false));
71 
72 cl::opt<bool> ValueProfileStaticAlloc(
73  "vp-static-alloc",
74  cl::desc("Do static counter allocation for value profiler"),
75  cl::init(true));
76 
77 cl::opt<double> NumCountersPerValueSite(
78  "vp-counters-per-site",
79  cl::desc("The average number of profile counters allocated "
80  "per value profiling site."),
81  // This is set to a very small value because in real programs, only
82  // a very small percentage of value sites have non-zero targets, e.g, 1/30.
83  // For those sites with non-zero profile, the average number of targets
84  // is usually smaller than 2.
85  cl::init(1.0));
86 
87 cl::opt<bool> AtomicCounterUpdateAll(
88  "instrprof-atomic-counter-update-all", cl::ZeroOrMore,
89  cl::desc("Make all profile counter updates atomic (for testing only)"),
90  cl::init(false));
91 
92 cl::opt<bool> AtomicCounterUpdatePromoted(
93  "atomic-counter-update-promoted", cl::ZeroOrMore,
94  cl::desc("Do counter update using atomic fetch add "
95  " for promoted counters only"),
96  cl::init(false));
97 
98 cl::opt<bool> AtomicFirstCounter(
99  "atomic-first-counter", cl::ZeroOrMore,
100  cl::desc("Use atomic fetch add for first counter in a function (usually "
101  "the entry counter)"),
102  cl::init(false));
103 
104 // If the option is not specified, the default behavior about whether
105 // counter promotion is done depends on how instrumentaiton lowering
106 // pipeline is setup, i.e., the default value of true of this option
107 // does not mean the promotion will be done by default. Explicitly
108 // setting this option can override the default behavior.
109 cl::opt<bool> DoCounterPromotion("do-counter-promotion", cl::ZeroOrMore,
110  cl::desc("Do counter register promotion"),
111  cl::init(false));
112 cl::opt<unsigned> MaxNumOfPromotionsPerLoop(
113  cl::ZeroOrMore, "max-counter-promotions-per-loop", cl::init(20),
114  cl::desc("Max number counter promotions per loop to avoid"
115  " increasing register pressure too much"));
116 
117 // A debug option
119  MaxNumOfPromotions(cl::ZeroOrMore, "max-counter-promotions", cl::init(-1),
120  cl::desc("Max number of allowed counter promotions"));
121 
122 cl::opt<unsigned> SpeculativeCounterPromotionMaxExiting(
123  cl::ZeroOrMore, "speculative-counter-promotion-max-exiting", cl::init(3),
124  cl::desc("The max number of exiting blocks of a loop to allow "
125  " speculative counter promotion"));
126 
127 cl::opt<bool> SpeculativeCounterPromotionToLoop(
128  cl::ZeroOrMore, "speculative-counter-promotion-to-loop", cl::init(false),
129  cl::desc("When the option is false, if the target block is in a loop, "
130  "the promotion will be disallowed unless the promoted counter "
131  " update can be further/iteratively promoted into an acyclic "
132  " region."));
133 
134 cl::opt<bool> IterativeCounterPromotion(
135  cl::ZeroOrMore, "iterative-counter-promotion", cl::init(true),
136  cl::desc("Allow counter promotion across the whole loop nest."));
137 
138 cl::opt<bool> SkipRetExitBlock(
139  cl::ZeroOrMore, "skip-ret-exit-block", cl::init(true),
140  cl::desc("Suppress counter promotion if exit blocks contain ret."));
141 
142 class InstrProfilingLegacyPass : public ModulePass {
143  InstrProfiling InstrProf;
144 
145 public:
146  static char ID;
147 
148  InstrProfilingLegacyPass() : ModulePass(ID) {}
149  InstrProfilingLegacyPass(const InstrProfOptions &Options, bool IsCS = false)
150  : ModulePass(ID), InstrProf(Options, IsCS) {
152  }
153 
154  StringRef getPassName() const override {
155  return "Frontend instrumentation-based coverage lowering";
156  }
157 
158  bool runOnModule(Module &M) override {
159  auto GetTLI = [this](Function &F) -> TargetLibraryInfo & {
160  return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
161  };
162  return InstrProf.run(M, GetTLI);
163  }
164 
165  void getAnalysisUsage(AnalysisUsage &AU) const override {
166  AU.setPreservesCFG();
168  }
169 };
170 
171 ///
172 /// A helper class to promote one counter RMW operation in the loop
173 /// into register update.
174 ///
175 /// RWM update for the counter will be sinked out of the loop after
176 /// the transformation.
177 ///
178 class PGOCounterPromoterHelper : public LoadAndStorePromoter {
179 public:
180  PGOCounterPromoterHelper(
182  BasicBlock *PH, ArrayRef<BasicBlock *> ExitBlocks,
183  ArrayRef<Instruction *> InsertPts,
185  LoopInfo &LI)
186  : LoadAndStorePromoter({L, S}, SSA), Store(S), ExitBlocks(ExitBlocks),
187  InsertPts(InsertPts), LoopToCandidates(LoopToCands), LI(LI) {
188  assert(isa<LoadInst>(L));
189  assert(isa<StoreInst>(S));
190  SSA.AddAvailableValue(PH, Init);
191  }
192 
193  void doExtraRewritesBeforeFinalDeletion() override {
194  for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
195  BasicBlock *ExitBlock = ExitBlocks[i];
196  Instruction *InsertPos = InsertPts[i];
197  // Get LiveIn value into the ExitBlock. If there are multiple
198  // predecessors, the value is defined by a PHI node in this
199  // block.
200  Value *LiveInValue = SSA.GetValueInMiddleOfBlock(ExitBlock);
201  Value *Addr = cast<StoreInst>(Store)->getPointerOperand();
202  Type *Ty = LiveInValue->getType();
203  IRBuilder<> Builder(InsertPos);
204  if (AtomicCounterUpdatePromoted)
205  // automic update currently can only be promoted across the current
206  // loop, not the whole loop nest.
207  Builder.CreateAtomicRMW(AtomicRMWInst::Add, Addr, LiveInValue,
208  MaybeAlign(),
210  else {
211  LoadInst *OldVal = Builder.CreateLoad(Ty, Addr, "pgocount.promoted");
212  auto *NewVal = Builder.CreateAdd(OldVal, LiveInValue);
213  auto *NewStore = Builder.CreateStore(NewVal, Addr);
214 
215  // Now update the parent loop's candidate list:
216  if (IterativeCounterPromotion) {
217  auto *TargetLoop = LI.getLoopFor(ExitBlock);
218  if (TargetLoop)
219  LoopToCandidates[TargetLoop].emplace_back(OldVal, NewStore);
220  }
221  }
222  }
223  }
224 
225 private:
227  ArrayRef<BasicBlock *> ExitBlocks;
228  ArrayRef<Instruction *> InsertPts;
230  LoopInfo &LI;
231 };
232 
233 /// A helper class to do register promotion for all profile counter
234 /// updates in a loop.
235 ///
236 class PGOCounterPromoter {
237 public:
238  PGOCounterPromoter(
240  Loop &CurLoop, LoopInfo &LI, BlockFrequencyInfo *BFI)
241  : LoopToCandidates(LoopToCands), ExitBlocks(), InsertPts(), L(CurLoop),
242  LI(LI), BFI(BFI) {
243 
244  // Skip collection of ExitBlocks and InsertPts for loops that will not be
245  // able to have counters promoted.
246  SmallVector<BasicBlock *, 8> LoopExitBlocks;
248 
249  L.getExitBlocks(LoopExitBlocks);
250  if (!isPromotionPossible(&L, LoopExitBlocks))
251  return;
252 
253  for (BasicBlock *ExitBlock : LoopExitBlocks) {
254  if (BlockSet.insert(ExitBlock).second) {
255  ExitBlocks.push_back(ExitBlock);
256  InsertPts.push_back(&*ExitBlock->getFirstInsertionPt());
257  }
258  }
259  }
260 
261  bool run(int64_t *NumPromoted) {
262  // Skip 'infinite' loops:
263  if (ExitBlocks.size() == 0)
264  return false;
265 
266  // Skip if any of the ExitBlocks contains a ret instruction.
267  // This is to prevent dumping of incomplete profile -- if the
268  // the loop is a long running loop and dump is called in the middle
269  // of the loop, the result profile is incomplete.
270  // FIXME: add other heuristics to detect long running loops.
271  if (SkipRetExitBlock) {
272  for (auto BB : ExitBlocks)
273  if (isa<ReturnInst>(BB->getTerminator()))
274  return false;
275  }
276 
277  unsigned MaxProm = getMaxNumOfPromotionsInLoop(&L);
278  if (MaxProm == 0)
279  return false;
280 
281  unsigned Promoted = 0;
282  for (auto &Cand : LoopToCandidates[&L]) {
283 
285  SSAUpdater SSA(&NewPHIs);
286  Value *InitVal = ConstantInt::get(Cand.first->getType(), 0);
287 
288  // If BFI is set, we will use it to guide the promotions.
289  if (BFI) {
290  auto *BB = Cand.first->getParent();
291  auto InstrCount = BFI->getBlockProfileCount(BB);
292  if (!InstrCount)
293  continue;
294  auto PreheaderCount = BFI->getBlockProfileCount(L.getLoopPreheader());
295  // If the average loop trip count is not greater than 1.5, we skip
296  // promotion.
297  if (PreheaderCount &&
298  (PreheaderCount.getValue() * 3) >= (InstrCount.getValue() * 2))
299  continue;
300  }
301 
302  PGOCounterPromoterHelper Promoter(Cand.first, Cand.second, SSA, InitVal,
303  L.getLoopPreheader(), ExitBlocks,
304  InsertPts, LoopToCandidates, LI);
305  Promoter.run(SmallVector<Instruction *, 2>({Cand.first, Cand.second}));
306  Promoted++;
307  if (Promoted >= MaxProm)
308  break;
309 
310  (*NumPromoted)++;
311  if (MaxNumOfPromotions != -1 && *NumPromoted >= MaxNumOfPromotions)
312  break;
313  }
314 
315  LLVM_DEBUG(dbgs() << Promoted << " counters promoted for loop (depth="
316  << L.getLoopDepth() << ")\n");
317  return Promoted != 0;
318  }
319 
320 private:
321  bool allowSpeculativeCounterPromotion(Loop *LP) {
322  SmallVector<BasicBlock *, 8> ExitingBlocks;
323  L.getExitingBlocks(ExitingBlocks);
324  // Not considierered speculative.
325  if (ExitingBlocks.size() == 1)
326  return true;
327  if (ExitingBlocks.size() > SpeculativeCounterPromotionMaxExiting)
328  return false;
329  return true;
330  }
331 
332  // Check whether the loop satisfies the basic conditions needed to perform
333  // Counter Promotions.
334  bool isPromotionPossible(Loop *LP,
335  const SmallVectorImpl<BasicBlock *> &LoopExitBlocks) {
336  // We can't insert into a catchswitch.
337  if (llvm::any_of(LoopExitBlocks, [](BasicBlock *Exit) {
338  return isa<CatchSwitchInst>(Exit->getTerminator());
339  }))
340  return false;
341 
342  if (!LP->hasDedicatedExits())
343  return false;
344 
345  BasicBlock *PH = LP->getLoopPreheader();
346  if (!PH)
347  return false;
348 
349  return true;
350  }
351 
352  // Returns the max number of Counter Promotions for LP.
353  unsigned getMaxNumOfPromotionsInLoop(Loop *LP) {
354  SmallVector<BasicBlock *, 8> LoopExitBlocks;
355  LP->getExitBlocks(LoopExitBlocks);
356  if (!isPromotionPossible(LP, LoopExitBlocks))
357  return 0;
358 
359  SmallVector<BasicBlock *, 8> ExitingBlocks;
360  LP->getExitingBlocks(ExitingBlocks);
361 
362  // If BFI is set, we do more aggressive promotions based on BFI.
363  if (BFI)
364  return (unsigned)-1;
365 
366  // Not considierered speculative.
367  if (ExitingBlocks.size() == 1)
368  return MaxNumOfPromotionsPerLoop;
369 
370  if (ExitingBlocks.size() > SpeculativeCounterPromotionMaxExiting)
371  return 0;
372 
373  // Whether the target block is in a loop does not matter:
374  if (SpeculativeCounterPromotionToLoop)
375  return MaxNumOfPromotionsPerLoop;
376 
377  // Now check the target block:
378  unsigned MaxProm = MaxNumOfPromotionsPerLoop;
379  for (auto *TargetBlock : LoopExitBlocks) {
380  auto *TargetLoop = LI.getLoopFor(TargetBlock);
381  if (!TargetLoop)
382  continue;
383  unsigned MaxPromForTarget = getMaxNumOfPromotionsInLoop(TargetLoop);
384  unsigned PendingCandsInTarget = LoopToCandidates[TargetLoop].size();
385  MaxProm =
386  std::min(MaxProm, std::max(MaxPromForTarget, PendingCandsInTarget) -
387  PendingCandsInTarget);
388  }
389  return MaxProm;
390  }
391 
393  SmallVector<BasicBlock *, 8> ExitBlocks;
395  Loop &L;
396  LoopInfo &LI;
398 };
399 
400 enum class ValueProfilingCallType {
401  // Individual values are tracked. Currently used for indiret call target
402  // profiling.
403  Default,
404 
405  // MemOp: the memop size value profiling.
406  MemOp
407 };
408 
409 } // end anonymous namespace
410 
414  auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {
416  };
417  if (!run(M, GetTLI))
418  return PreservedAnalyses::all();
419 
420  return PreservedAnalyses::none();
421 }
422 
425  InstrProfilingLegacyPass, "instrprof",
426  "Frontend instrumentation-based coverage lowering.", false, false)
429  InstrProfilingLegacyPass, "instrprof",
430  "Frontend instrumentation-based coverage lowering.", false, false)
431 
432 ModulePass *
434  bool IsCS) {
435  return new InstrProfilingLegacyPass(Options, IsCS);
436 }
437 
439  InstrProfIncrementInst *Inc = dyn_cast<InstrProfIncrementInstStep>(Instr);
440  if (Inc)
441  return Inc;
442  return dyn_cast<InstrProfIncrementInst>(Instr);
443 }
444 
445 bool InstrProfiling::lowerIntrinsics(Function *F) {
446  bool MadeChange = false;
447  PromotionCandidates.clear();
448  for (BasicBlock &BB : *F) {
449  for (auto I = BB.begin(), E = BB.end(); I != E;) {
450  auto Instr = I++;
452  if (Inc) {
453  lowerIncrement(Inc);
454  MadeChange = true;
455  } else if (auto *Ind = dyn_cast<InstrProfValueProfileInst>(Instr)) {
456  lowerValueProfileInst(Ind);
457  MadeChange = true;
458  }
459  }
460  }
461 
462  if (!MadeChange)
463  return false;
464 
465  promoteCounterLoadStores(F);
466  return true;
467 }
468 
469 bool InstrProfiling::isRuntimeCounterRelocationEnabled() const {
470  if (RuntimeCounterRelocation.getNumOccurrences() > 0)
471  return RuntimeCounterRelocation;
472 
473  return TT.isOSFuchsia();
474 }
475 
476 bool InstrProfiling::isCounterPromotionEnabled() const {
477  if (DoCounterPromotion.getNumOccurrences() > 0)
478  return DoCounterPromotion;
479 
480  return Options.DoCounterPromotion;
481 }
482 
483 void InstrProfiling::promoteCounterLoadStores(Function *F) {
484  if (!isCounterPromotionEnabled())
485  return;
486 
487  DominatorTree DT(*F);
488  LoopInfo LI(DT);
489  DenseMap<Loop *, SmallVector<LoadStorePair, 8>> LoopPromotionCandidates;
490 
491  std::unique_ptr<BlockFrequencyInfo> BFI;
492  if (Options.UseBFIInPromotion) {
493  std::unique_ptr<BranchProbabilityInfo> BPI;
494  BPI.reset(new BranchProbabilityInfo(*F, LI, &GetTLI(*F)));
495  BFI.reset(new BlockFrequencyInfo(*F, *BPI, LI));
496  }
497 
498  for (const auto &LoadStore : PromotionCandidates) {
499  auto *CounterLoad = LoadStore.first;
500  auto *CounterStore = LoadStore.second;
501  BasicBlock *BB = CounterLoad->getParent();
502  Loop *ParentLoop = LI.getLoopFor(BB);
503  if (!ParentLoop)
504  continue;
505  LoopPromotionCandidates[ParentLoop].emplace_back(CounterLoad, CounterStore);
506  }
507 
508  SmallVector<Loop *, 4> Loops = LI.getLoopsInPreorder();
509 
510  // Do a post-order traversal of the loops so that counter updates can be
511  // iteratively hoisted outside the loop nest.
512  for (auto *Loop : llvm::reverse(Loops)) {
513  PGOCounterPromoter Promoter(LoopPromotionCandidates, *Loop, LI, BFI.get());
514  Promoter.run(&TotalCountersPromoted);
515  }
516 }
517 
518 /// Check if the module contains uses of any profiling intrinsics.
520  if (auto *F = M.getFunction(
521  Intrinsic::getName(llvm::Intrinsic::instrprof_increment)))
522  if (!F->use_empty())
523  return true;
524  if (auto *F = M.getFunction(
525  Intrinsic::getName(llvm::Intrinsic::instrprof_increment_step)))
526  if (!F->use_empty())
527  return true;
528  if (auto *F = M.getFunction(
529  Intrinsic::getName(llvm::Intrinsic::instrprof_value_profile)))
530  if (!F->use_empty())
531  return true;
532  return false;
533 }
534 
536  Module &M, std::function<const TargetLibraryInfo &(Function &F)> GetTLI) {
537  this->M = &M;
538  this->GetTLI = std::move(GetTLI);
539  NamesVar = nullptr;
540  NamesSize = 0;
541  ProfileDataMap.clear();
542  CompilerUsedVars.clear();
543  UsedVars.clear();
544  TT = Triple(M.getTargetTriple());
545 
546  // Emit the runtime hook even if no counters are present.
547  bool MadeChange = emitRuntimeHook();
548 
549  // Improve compile time by avoiding linear scans when there is no work.
550  GlobalVariable *CoverageNamesVar =
551  M.getNamedGlobal(getCoverageUnusedNamesVarName());
552  if (!containsProfilingIntrinsics(M) && !CoverageNamesVar)
553  return MadeChange;
554 
555  // We did not know how many value sites there would be inside
556  // the instrumented function. This is counting the number of instrumented
557  // target value sites to enter it as field in the profile data variable.
558  for (Function &F : M) {
559  InstrProfIncrementInst *FirstProfIncInst = nullptr;
560  for (BasicBlock &BB : F)
561  for (auto I = BB.begin(), E = BB.end(); I != E; I++)
562  if (auto *Ind = dyn_cast<InstrProfValueProfileInst>(I))
563  computeNumValueSiteCounts(Ind);
564  else if (FirstProfIncInst == nullptr)
565  FirstProfIncInst = dyn_cast<InstrProfIncrementInst>(I);
566 
567  // Value profiling intrinsic lowering requires per-function profile data
568  // variable to be created first.
569  if (FirstProfIncInst != nullptr)
570  static_cast<void>(getOrCreateRegionCounters(FirstProfIncInst));
571  }
572 
573  for (Function &F : M)
574  MadeChange |= lowerIntrinsics(&F);
575 
576  if (CoverageNamesVar) {
577  lowerCoverageData(CoverageNamesVar);
578  MadeChange = true;
579  }
580 
581  if (!MadeChange)
582  return false;
583 
584  emitVNodes();
585  emitNameData();
586  emitRegistration();
587  emitUses();
588  emitInitialization();
589  return true;
590 }
591 
593  Module &M, const TargetLibraryInfo &TLI,
594  ValueProfilingCallType CallType = ValueProfilingCallType::Default) {
595  LLVMContext &Ctx = M.getContext();
596  auto *ReturnTy = Type::getVoidTy(M.getContext());
597 
599  if (auto AK = TLI.getExtAttrForI32Param(false))
600  AL = AL.addParamAttribute(M.getContext(), 2, AK);
601 
603  CallType == ValueProfilingCallType::MemOp) &&
604  "Must be Default or MemOp");
605  Type *ParamTypes[] = {
606 #define VALUE_PROF_FUNC_PARAM(ParamType, ParamName, ParamLLVMType) ParamLLVMType
608  };
609  auto *ValueProfilingCallTy =
610  FunctionType::get(ReturnTy, makeArrayRef(ParamTypes), false);
611  StringRef FuncName = CallType == ValueProfilingCallType::Default
614  return M.getOrInsertFunction(FuncName, ValueProfilingCallTy, AL);
615 }
616 
617 void InstrProfiling::computeNumValueSiteCounts(InstrProfValueProfileInst *Ind) {
618  GlobalVariable *Name = Ind->getName();
619  uint64_t ValueKind = Ind->getValueKind()->getZExtValue();
620  uint64_t Index = Ind->getIndex()->getZExtValue();
621  auto It = ProfileDataMap.find(Name);
622  if (It == ProfileDataMap.end()) {
623  PerFunctionProfileData PD;
624  PD.NumValueSites[ValueKind] = Index + 1;
625  ProfileDataMap[Name] = PD;
626  } else if (It->second.NumValueSites[ValueKind] <= Index)
627  It->second.NumValueSites[ValueKind] = Index + 1;
628 }
629 
630 void InstrProfiling::lowerValueProfileInst(InstrProfValueProfileInst *Ind) {
631  GlobalVariable *Name = Ind->getName();
632  auto It = ProfileDataMap.find(Name);
633  assert(It != ProfileDataMap.end() && It->second.DataVar &&
634  "value profiling detected in function with no counter incerement");
635 
636  GlobalVariable *DataVar = It->second.DataVar;
637  uint64_t ValueKind = Ind->getValueKind()->getZExtValue();
638  uint64_t Index = Ind->getIndex()->getZExtValue();
639  for (uint32_t Kind = IPVK_First; Kind < ValueKind; ++Kind)
640  Index += It->second.NumValueSites[Kind];
641 
642  IRBuilder<> Builder(Ind);
643  bool IsMemOpSize = (Ind->getValueKind()->getZExtValue() ==
644  llvm::InstrProfValueKind::IPVK_MemOPSize);
645  CallInst *Call = nullptr;
646  auto *TLI = &GetTLI(*Ind->getFunction());
647 
648  // To support value profiling calls within Windows exception handlers, funclet
649  // information contained within operand bundles needs to be copied over to
650  // the library call. This is required for the IR to be processed by the
651  // WinEHPrepare pass.
653  Ind->getOperandBundlesAsDefs(OpBundles);
654  if (!IsMemOpSize) {
655  Value *Args[3] = {Ind->getTargetValue(),
656  Builder.CreateBitCast(DataVar, Builder.getInt8PtrTy()),
657  Builder.getInt32(Index)};
658  Call = Builder.CreateCall(getOrInsertValueProfilingCall(*M, *TLI), Args,
659  OpBundles);
660  } else {
661  Value *Args[3] = {Ind->getTargetValue(),
662  Builder.CreateBitCast(DataVar, Builder.getInt8PtrTy()),
663  Builder.getInt32(Index)};
664  Call = Builder.CreateCall(
665  getOrInsertValueProfilingCall(*M, *TLI, ValueProfilingCallType::MemOp),
666  Args, OpBundles);
667  }
668  if (auto AK = TLI->getExtAttrForI32Param(false))
669  Call->addParamAttr(2, AK);
670  Ind->replaceAllUsesWith(Call);
671  Ind->eraseFromParent();
672 }
673 
674 void InstrProfiling::lowerIncrement(InstrProfIncrementInst *Inc) {
675  GlobalVariable *Counters = getOrCreateRegionCounters(Inc);
676 
677  IRBuilder<> Builder(Inc);
678  uint64_t Index = Inc->getIndex()->getZExtValue();
679  Value *Addr = Builder.CreateConstInBoundsGEP2_64(Counters->getValueType(),
680  Counters, 0, Index);
681 
682  if (isRuntimeCounterRelocationEnabled()) {
683  Type *Int64Ty = Type::getInt64Ty(M->getContext());
684  Type *Int64PtrTy = Type::getInt64PtrTy(M->getContext());
685  Function *Fn = Inc->getParent()->getParent();
686  Instruction &I = Fn->getEntryBlock().front();
687  LoadInst *LI = dyn_cast<LoadInst>(&I);
688  if (!LI) {
690  Type *Int64Ty = Type::getInt64Ty(M->getContext());
691  GlobalVariable *Bias = M->getGlobalVariable(getInstrProfCounterBiasVarName());
692  if (!Bias) {
693  Bias = new GlobalVariable(*M, Int64Ty, false, GlobalValue::LinkOnceODRLinkage,
694  Constant::getNullValue(Int64Ty),
697  }
698  LI = Builder.CreateLoad(Int64Ty, Bias);
699  }
700  auto *Add = Builder.CreateAdd(Builder.CreatePtrToInt(Addr, Int64Ty), LI);
701  Addr = Builder.CreateIntToPtr(Add, Int64PtrTy);
702  }
703 
704  if (Options.Atomic || AtomicCounterUpdateAll ||
705  (Index == 0 && AtomicFirstCounter)) {
706  Builder.CreateAtomicRMW(AtomicRMWInst::Add, Addr, Inc->getStep(),
708  } else {
709  Value *IncStep = Inc->getStep();
710  Value *Load = Builder.CreateLoad(IncStep->getType(), Addr, "pgocount");
711  auto *Count = Builder.CreateAdd(Load, Inc->getStep());
712  auto *Store = Builder.CreateStore(Count, Addr);
713  if (isCounterPromotionEnabled())
714  PromotionCandidates.emplace_back(cast<Instruction>(Load), Store);
715  }
716  Inc->eraseFromParent();
717 }
718 
719 void InstrProfiling::lowerCoverageData(GlobalVariable *CoverageNamesVar) {
720  ConstantArray *Names =
721  cast<ConstantArray>(CoverageNamesVar->getInitializer());
722  for (unsigned I = 0, E = Names->getNumOperands(); I < E; ++I) {
723  Constant *NC = Names->getOperand(I);
724  Value *V = NC->stripPointerCasts();
725  assert(isa<GlobalVariable>(V) && "Missing reference to function name");
726  GlobalVariable *Name = cast<GlobalVariable>(V);
727 
728  Name->setLinkage(GlobalValue::PrivateLinkage);
729  ReferencedNames.push_back(Name);
730  NC->dropAllReferences();
731  }
732  CoverageNamesVar->eraseFromParent();
733 }
734 
735 /// Get the name of a profiling variable for a particular function.
737  StringRef NamePrefix = getInstrProfNameVarPrefix();
738  StringRef Name = Inc->getName()->getName().substr(NamePrefix.size());
739  Function *F = Inc->getParent()->getParent();
740  Module *M = F->getParent();
741  if (!DoHashBasedCounterSplit || !isIRPGOFlagSet(M) ||
743  return (Prefix + Name).str();
744  uint64_t FuncHash = Inc->getHash()->getZExtValue();
745  SmallVector<char, 24> HashPostfix;
746  if (Name.endswith((Twine(".") + Twine(FuncHash)).toStringRef(HashPostfix)))
747  return (Prefix + Name).str();
748  return (Prefix + Name + "." + Twine(FuncHash)).str();
749 }
750 
751 static uint64_t getIntModuleFlagOrZero(const Module &M, StringRef Flag) {
752  auto *MD = dyn_cast_or_null<ConstantAsMetadata>(M.getModuleFlag(Flag));
753  if (!MD)
754  return 0;
755 
756  // If the flag is a ConstantAsMetadata, it should be an integer representable
757  // in 64-bits.
758  return cast<ConstantInt>(MD->getValue())->getZExtValue();
759 }
760 
761 static bool enablesValueProfiling(const Module &M) {
762  return isIRPGOFlagSet(&M) ||
763  getIntModuleFlagOrZero(M, "EnableValueProfiling") != 0;
764 }
765 
766 // Conservatively returns true if data variables may be referenced by code.
767 static bool profDataReferencedByCode(const Module &M) {
768  return enablesValueProfiling(M);
769 }
770 
771 static inline bool shouldRecordFunctionAddr(Function *F) {
772  // Only record function addresses if IR PGO is enabled or if clang value
773  // profiling is enabled. Recording function addresses greatly increases object
774  // file size, because it prevents the inliner from deleting functions that
775  // have been inlined everywhere.
776  if (!profDataReferencedByCode(*F->getParent()))
777  return false;
778 
779  // Check the linkage
780  bool HasAvailableExternallyLinkage = F->hasAvailableExternallyLinkage();
781  if (!F->hasLinkOnceLinkage() && !F->hasLocalLinkage() &&
782  !HasAvailableExternallyLinkage)
783  return true;
784 
785  // A function marked 'alwaysinline' with available_externally linkage can't
786  // have its address taken. Doing so would create an undefined external ref to
787  // the function, which would fail to link.
788  if (HasAvailableExternallyLinkage &&
789  F->hasFnAttribute(Attribute::AlwaysInline))
790  return false;
791 
792  // Prohibit function address recording if the function is both internal and
793  // COMDAT. This avoids the profile data variable referencing internal symbols
794  // in COMDAT.
795  if (F->hasLocalLinkage() && F->hasComdat())
796  return false;
797 
798  // Check uses of this function for other than direct calls or invokes to it.
799  // Inline virtual functions have linkeOnceODR linkage. When a key method
800  // exists, the vtable will only be emitted in the TU where the key method
801  // is defined. In a TU where vtable is not available, the function won't
802  // be 'addresstaken'. If its address is not recorded here, the profile data
803  // with missing address may be picked by the linker leading to missing
804  // indirect call target info.
805  return F->hasAddressTaken() || F->hasLinkOnceLinkage();
806 }
807 
809  // Don't do this for Darwin. compiler-rt uses linker magic.
810  if (TT.isOSDarwin())
811  return false;
812  // Use linker script magic to get data/cnts/name start/end.
813  if (TT.isOSLinux() || TT.isOSFreeBSD() || TT.isOSNetBSD() ||
814  TT.isOSSolaris() || TT.isOSFuchsia() || TT.isPS4CPU() ||
815  TT.isOSWindows())
816  return false;
817 
818  return true;
819 }
820 
822 InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) {
823  GlobalVariable *NamePtr = Inc->getName();
824  auto It = ProfileDataMap.find(NamePtr);
825  PerFunctionProfileData PD;
826  if (It != ProfileDataMap.end()) {
827  if (It->second.RegionCounters)
828  return It->second.RegionCounters;
829  PD = It->second;
830  }
831 
832  // Match the linkage and visibility of the name global.
833  Function *Fn = Inc->getParent()->getParent();
835  GlobalValue::VisibilityTypes Visibility = NamePtr->getVisibility();
836 
837  // Move the name variable to the right section. Place them in a COMDAT group
838  // if the associated function is a COMDAT. This will make sure that only one
839  // copy of counters of the COMDAT function will be emitted after linking. Keep
840  // in mind that this pass may run before the inliner, so we need to create a
841  // new comdat group for the counters and profiling data. If we use the comdat
842  // of the parent function, that will result in relocations against discarded
843  // sections.
844  //
845  // If the data variable is referenced by code, counters and data have to be
846  // in different comdats for COFF because the Visual C++ linker will report
847  // duplicate symbol errors if there are multiple external symbols with the
848  // same name marked IMAGE_COMDAT_SELECT_ASSOCIATIVE.
849  //
850  // For ELF, when not using COMDAT, put counters, data and values into a
851  // noduplicates COMDAT which is lowered to a zero-flag section group. This
852  // allows -z start-stop-gc to discard the entire group when the function is
853  // discarded.
854  bool DataReferencedByCode = profDataReferencedByCode(*M);
855  bool NeedComdat = needsComdatForCounter(*Fn, *M);
856  std::string CntsVarName = getVarName(Inc, getInstrProfCountersVarPrefix());
857  std::string DataVarName = getVarName(Inc, getInstrProfDataVarPrefix());
858  auto MaybeSetComdat = [&](GlobalVariable *GV) {
859  bool UseComdat = (NeedComdat || TT.isOSBinFormatELF());
860  if (UseComdat) {
861  StringRef GroupName = TT.isOSBinFormatCOFF() && DataReferencedByCode
862  ? GV->getName()
863  : CntsVarName;
864  Comdat *C = M->getOrInsertComdat(GroupName);
865  if (!NeedComdat)
866  C->setSelectionKind(Comdat::NoDuplicates);
867  GV->setComdat(C);
868  }
869  };
870 
871  uint64_t NumCounters = Inc->getNumCounters()->getZExtValue();
872  LLVMContext &Ctx = M->getContext();
873  ArrayType *CounterTy = ArrayType::get(Type::getInt64Ty(Ctx), NumCounters);
874 
875  // Create the counters variable.
876  auto *CounterPtr =
877  new GlobalVariable(*M, CounterTy, false, Linkage,
878  Constant::getNullValue(CounterTy), CntsVarName);
879  CounterPtr->setVisibility(Visibility);
880  CounterPtr->setSection(
881  getInstrProfSectionName(IPSK_cnts, TT.getObjectFormat()));
882  CounterPtr->setAlignment(Align(8));
883  MaybeSetComdat(CounterPtr);
884  CounterPtr->setLinkage(Linkage);
885 
886  auto *Int8PtrTy = Type::getInt8PtrTy(Ctx);
887  // Allocate statically the array of pointers to value profile nodes for
888  // the current function.
889  Constant *ValuesPtrExpr = ConstantPointerNull::get(Int8PtrTy);
890  if (ValueProfileStaticAlloc && !needsRuntimeRegistrationOfSectionRange(TT)) {
891  uint64_t NS = 0;
892  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
893  NS += PD.NumValueSites[Kind];
894  if (NS) {
895  ArrayType *ValuesTy = ArrayType::get(Type::getInt64Ty(Ctx), NS);
896 
897  auto *ValuesVar =
898  new GlobalVariable(*M, ValuesTy, false, Linkage,
899  Constant::getNullValue(ValuesTy),
901  ValuesVar->setVisibility(Visibility);
902  ValuesVar->setSection(
903  getInstrProfSectionName(IPSK_vals, TT.getObjectFormat()));
904  ValuesVar->setAlignment(Align(8));
905  MaybeSetComdat(ValuesVar);
906  ValuesPtrExpr =
908  }
909  }
910 
911  // Create data variable.
912  auto *Int16Ty = Type::getInt16Ty(Ctx);
913  auto *Int16ArrayTy = ArrayType::get(Int16Ty, IPVK_Last + 1);
914  Type *DataTypes[] = {
915 #define INSTR_PROF_DATA(Type, LLVMType, Name, Init) LLVMType,
917  };
918  auto *DataTy = StructType::get(Ctx, makeArrayRef(DataTypes));
919 
920  Constant *FunctionAddr = shouldRecordFunctionAddr(Fn)
921  ? ConstantExpr::getBitCast(Fn, Int8PtrTy)
922  : ConstantPointerNull::get(Int8PtrTy);
923 
924  Constant *Int16ArrayVals[IPVK_Last + 1];
925  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
926  Int16ArrayVals[Kind] = ConstantInt::get(Int16Ty, PD.NumValueSites[Kind]);
927 
928  Constant *DataVals[] = {
929 #define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Init,
931  };
932  // If code never references data variables (the symbol is unneeded), and
933  // linker GC cannot discard data variables while the text section is retained,
934  // data variables can be private. This optimization applies on COFF and ELF.
935  if (!DataReferencedByCode && !TT.isOSBinFormatMachO()) {
937  Visibility = GlobalValue::DefaultVisibility;
938  }
939  auto *Data =
940  new GlobalVariable(*M, DataTy, false, Linkage,
941  ConstantStruct::get(DataTy, DataVals), DataVarName);
942  Data->setVisibility(Visibility);
943  Data->setSection(getInstrProfSectionName(IPSK_data, TT.getObjectFormat()));
944  Data->setAlignment(Align(INSTR_PROF_DATA_ALIGNMENT));
945  MaybeSetComdat(Data);
946  Data->setLinkage(Linkage);
947 
948  PD.RegionCounters = CounterPtr;
949  PD.DataVar = Data;
950  ProfileDataMap[NamePtr] = PD;
951 
952  // Mark the data variable as used so that it isn't stripped out.
953  CompilerUsedVars.push_back(Data);
954  // Now that the linkage set by the FE has been passed to the data and counter
955  // variables, reset Name variable's linkage and visibility to private so that
956  // it can be removed later by the compiler.
958  // Collect the referenced names to be used by emitNameData.
959  ReferencedNames.push_back(NamePtr);
960 
961  return CounterPtr;
962 }
963 
964 void InstrProfiling::emitVNodes() {
965  if (!ValueProfileStaticAlloc)
966  return;
967 
968  // For now only support this on platforms that do
969  // not require runtime registration to discover
970  // named section start/end.
972  return;
973 
974  size_t TotalNS = 0;
975  for (auto &PD : ProfileDataMap) {
976  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
977  TotalNS += PD.second.NumValueSites[Kind];
978  }
979 
980  if (!TotalNS)
981  return;
982 
983  uint64_t NumCounters = TotalNS * NumCountersPerValueSite;
984 // Heuristic for small programs with very few total value sites.
985 // The default value of vp-counters-per-site is chosen based on
986 // the observation that large apps usually have a low percentage
987 // of value sites that actually have any profile data, and thus
988 // the average number of counters per site is low. For small
989 // apps with very few sites, this may not be true. Bump up the
990 // number of counters in this case.
991 #define INSTR_PROF_MIN_VAL_COUNTS 10
992  if (NumCounters < INSTR_PROF_MIN_VAL_COUNTS)
993  NumCounters = std::max(INSTR_PROF_MIN_VAL_COUNTS, (int)NumCounters * 2);
994 
995  auto &Ctx = M->getContext();
996  Type *VNodeTypes[] = {
997 #define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Init) LLVMType,
999  };
1000  auto *VNodeTy = StructType::get(Ctx, makeArrayRef(VNodeTypes));
1001 
1002  ArrayType *VNodesTy = ArrayType::get(VNodeTy, NumCounters);
1003  auto *VNodesVar = new GlobalVariable(
1004  *M, VNodesTy, false, GlobalValue::PrivateLinkage,
1006  VNodesVar->setSection(
1007  getInstrProfSectionName(IPSK_vnodes, TT.getObjectFormat()));
1008  // VNodesVar is used by runtime but not referenced via relocation by other
1009  // sections. Conservatively make it linker retained.
1010  UsedVars.push_back(VNodesVar);
1011 }
1012 
1013 void InstrProfiling::emitNameData() {
1014  std::string UncompressedData;
1015 
1016  if (ReferencedNames.empty())
1017  return;
1018 
1019  std::string CompressedNameStr;
1020  if (Error E = collectPGOFuncNameStrings(ReferencedNames, CompressedNameStr,
1023  }
1024 
1025  auto &Ctx = M->getContext();
1026  auto *NamesVal = ConstantDataArray::getString(
1027  Ctx, StringRef(CompressedNameStr), false);
1028  NamesVar = new GlobalVariable(*M, NamesVal->getType(), true,
1029  GlobalValue::PrivateLinkage, NamesVal,
1031  NamesSize = CompressedNameStr.size();
1032  NamesVar->setSection(
1033  getInstrProfSectionName(IPSK_name, TT.getObjectFormat()));
1034  // On COFF, it's important to reduce the alignment down to 1 to prevent the
1035  // linker from inserting padding before the start of the names section or
1036  // between names entries.
1037  NamesVar->setAlignment(Align(1));
1038  // NamesVar is used by runtime but not referenced via relocation by other
1039  // sections. Conservatively make it linker retained.
1040  UsedVars.push_back(NamesVar);
1041 
1042  for (auto *NamePtr : ReferencedNames)
1043  NamePtr->eraseFromParent();
1044 }
1045 
1046 void InstrProfiling::emitRegistration() {
1048  return;
1049 
1050  // Construct the function.
1051  auto *VoidTy = Type::getVoidTy(M->getContext());
1052  auto *VoidPtrTy = Type::getInt8PtrTy(M->getContext());
1053  auto *Int64Ty = Type::getInt64Ty(M->getContext());
1054  auto *RegisterFTy = FunctionType::get(VoidTy, false);
1055  auto *RegisterF = Function::Create(RegisterFTy, GlobalValue::InternalLinkage,
1057  RegisterF->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
1058  if (Options.NoRedZone)
1059  RegisterF->addFnAttr(Attribute::NoRedZone);
1060 
1061  auto *RuntimeRegisterTy = FunctionType::get(VoidTy, VoidPtrTy, false);
1062  auto *RuntimeRegisterF =
1065 
1066  IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", RegisterF));
1067  for (Value *Data : CompilerUsedVars)
1068  if (!isa<Function>(Data))
1069  IRB.CreateCall(RuntimeRegisterF, IRB.CreateBitCast(Data, VoidPtrTy));
1070  for (Value *Data : UsedVars)
1071  if (Data != NamesVar && !isa<Function>(Data))
1072  IRB.CreateCall(RuntimeRegisterF, IRB.CreateBitCast(Data, VoidPtrTy));
1073 
1074  if (NamesVar) {
1075  Type *ParamTypes[] = {VoidPtrTy, Int64Ty};
1076  auto *NamesRegisterTy =
1077  FunctionType::get(VoidTy, makeArrayRef(ParamTypes), false);
1078  auto *NamesRegisterF =
1081  IRB.CreateCall(NamesRegisterF, {IRB.CreateBitCast(NamesVar, VoidPtrTy),
1082  IRB.getInt64(NamesSize)});
1083  }
1084 
1085  IRB.CreateRetVoid();
1086 }
1087 
1088 bool InstrProfiling::emitRuntimeHook() {
1089  // We expect the linker to be invoked with -u<hook_var> flag for Linux or
1090  // Fuchsia, in which case there is no need to emit the user function.
1091  if (TT.isOSLinux() || TT.isOSFuchsia())
1092  return false;
1093 
1094  // If the module's provided its own runtime, we don't need to do anything.
1095  if (M->getGlobalVariable(getInstrProfRuntimeHookVarName()))
1096  return false;
1097 
1098  // Declare an external variable that will pull in the runtime initialization.
1099  auto *Int32Ty = Type::getInt32Ty(M->getContext());
1100  auto *Var =
1102  nullptr, getInstrProfRuntimeHookVarName());
1103 
1104  // Make a function that uses it.
1108  User->addFnAttr(Attribute::NoInline);
1109  if (Options.NoRedZone)
1110  User->addFnAttr(Attribute::NoRedZone);
1111  User->setVisibility(GlobalValue::HiddenVisibility);
1112  if (TT.supportsCOMDAT())
1113  User->setComdat(M->getOrInsertComdat(User->getName()));
1114 
1115  IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", User));
1116  auto *Load = IRB.CreateLoad(Int32Ty, Var);
1117  IRB.CreateRet(Load);
1118 
1119  // Mark the user variable as used so that it isn't stripped out.
1120  CompilerUsedVars.push_back(User);
1121  return true;
1122 }
1123 
1124 void InstrProfiling::emitUses() {
1125  // The metadata sections are parallel arrays. Optimizers (e.g.
1126  // GlobalOpt/ConstantMerge) may not discard associated sections as a unit, so
1127  // we conservatively retain all unconditionally in the compiler.
1128  //
1129  // On ELF, the linker can guarantee the associated sections will be retained
1130  // or discarded as a unit, so llvm.compiler.used is sufficient. Similarly on
1131  // COFF, if prof data is not referenced by code we use one comdat and ensure
1132  // this GC property as well. Otherwise, we have to conservatively make all of
1133  // the sections retained by the linker.
1134  if (TT.isOSBinFormatELF() ||
1136  appendToCompilerUsed(*M, CompilerUsedVars);
1137  else
1138  appendToUsed(*M, CompilerUsedVars);
1139 
1140  // We do not add proper references from used metadata sections to NamesVar and
1141  // VNodesVar, so we have to be conservative and place them in llvm.used
1142  // regardless of the target,
1143  appendToUsed(*M, UsedVars);
1144 }
1145 
1146 void InstrProfiling::emitInitialization() {
1147  // Create ProfileFileName variable. Don't don't this for the
1148  // context-sensitive instrumentation lowering: This lowering is after
1149  // LTO/ThinLTO linking. Pass PGOInstrumentationGenCreateVar should
1150  // have already create the variable before LTO/ThinLTO linking.
1151  if (!IsCS)
1153  Function *RegisterF = M->getFunction(getInstrProfRegFuncsName());
1154  if (!RegisterF)
1155  return;
1156 
1157  // Create the initialization function.
1158  auto *VoidTy = Type::getVoidTy(M->getContext());
1159  auto *F = Function::Create(FunctionType::get(VoidTy, false),
1162  F->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
1163  F->addFnAttr(Attribute::NoInline);
1164  if (Options.NoRedZone)
1165  F->addFnAttr(Attribute::NoRedZone);
1166 
1167  // Add the basic block and the necessary calls.
1168  IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", F));
1169  IRB.CreateCall(RegisterF, {});
1170  IRB.CreateRetVoid();
1171 
1172  appendToGlobalCtors(*M, F, 0);
1173 }
llvm::createInstrProfilingLegacyPass
ModulePass * createInstrProfilingLegacyPass(const InstrProfOptions &Options=InstrProfOptions(), bool IsCS=false)
Insert frontend instrumentation based profiling. Parameter IsCS indicates if.
Definition: InstrProfiling.cpp:433
INSTR_PROF_MIN_VAL_COUNTS
#define INSTR_PROF_MIN_VAL_COUNTS
i
i
Definition: README.txt:29
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
Int32Ty
IntegerType * Int32Ty
Definition: NVVMIntrRange.cpp:67
llvm::GlobalVariable::eraseFromParent
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:385
instrumentation
xray instrumentation
Definition: XRayInstrumentation.cpp:267
llvm
Definition: AllocatorList.h:23
llvm::CallBase::getOperandBundlesAsDefs
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
Definition: Instructions.cpp:361
llvm::InstrProfIncrementInst::getStep
Value * getStep() const
Definition: IntrinsicInst.cpp:181
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(InstrProfilingLegacyPass, "instrprof", "Frontend instrumentation-based coverage lowering.", false, false) INITIALIZE_PASS_END(InstrProfilingLegacyPass
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::AArch64CC::AL
@ AL
Definition: AArch64BaseInfo.h:250
llvm::LoopBase::getExitBlocks
void getExitBlocks(SmallVectorImpl< BlockT * > &ExitBlocks) const
Return all of the successor blocks of this loop.
Definition: LoopInfoImpl.h:62
llvm::StructType::get
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition: Type.cpp:366
llvm::Comdat::NoDuplicates
@ NoDuplicates
No other Module may specify this COMDAT.
Definition: Comdat.h:37
llvm::Type::getInt8PtrTy
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:249
llvm::getInstrProfNamesVarName
StringRef getInstrProfNamesVarName()
Return the name of the variable holding the strings (possibly compressed) of all function's PGO names...
Definition: InstrProf.h:100
llvm::ModulePass
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:238
llvm::BasicBlock::getParent
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:107
IntrinsicInst.h
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:769
llvm::Triple::isOSBinFormatCOFF
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Definition: Triple.h:637
llvm::cl::Prefix
@ Prefix
Definition: CommandLine.h:164
llvm::LoadAndStorePromoter
Helper class for promoting a collection of loads and stores into SSA Form using the SSAUpdater.
Definition: SSAUpdater.h:136
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition: GlobalValue.h:461
llvm::GlobalValue::HiddenVisibility
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
llvm::InstrProfOptions::UseBFIInPromotion
bool UseBFIInPromotion
Definition: Instrumentation.h:132
llvm::Function
Definition: Function.h:61
llvm::Loop
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:530
StringRef.h
llvm::ConstantStruct::get
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:1325
llvm::NVPTX::LoadStore
LoadStore
Definition: NVPTX.h:99
Pass.h
llvm::X86II::PD
@ PD
Definition: X86BaseInfo.h:782
Loops
Hexagon Hardware Loops
Definition: HexagonHardwareLoops.cpp:372
llvm::needsComdatForCounter
bool needsComdatForCounter(const Function &F, const Module &M)
Check if we can use Comdat for profile variables.
Definition: InstrProf.cpp:1071
llvm::toString
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Definition: Error.h:991
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1167
ErrorHandling.h
llvm::Function::getEntryBlock
const BasicBlock & getEntryBlock() const
Definition: Function.h:762
llvm::Intrinsic::getName
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:840
llvm::IRBuilder<>
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::ConstantExpr::getBitCast
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2220
llvm::FunctionType::get
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:321
Error.h
llvm::AtomicOrdering::SequentiallyConsistent
@ SequentiallyConsistent
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::getInstrProfRuntimeHookVarName
StringRef getInstrProfRuntimeHookVarName()
Return the name of the hook variable defined in profile runtime library.
Definition: InstrProf.h:148
llvm::MemOp
Definition: TargetLowering.h:111
InstrCount
static unsigned InstrCount
Definition: DFAPacketizer.cpp:53
llvm::PreservedAnalyses::none
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: PassManager.h:158
llvm::SPII::Load
@ Load
Definition: SparcInstrInfo.h:32
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
containsProfilingIntrinsics
static bool containsProfilingIntrinsics(Module &M)
Check if the module contains uses of any profiling intrinsics.
Definition: InstrProfiling.cpp:519
Module.h
llvm::reverse
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
Definition: STLExtras.h:329
llvm::AttributeList
Definition: Attributes.h:385
llvm::TargetLibraryInfo::getExtAttrForI32Param
Attribute::AttrKind getExtAttrForI32Param(bool Signed=true) const
Returns extension attribute kind to be used for i32 parameters corresponding to C-level int or unsign...
Definition: TargetLibraryInfo.h:382
llvm::InstrProfOptions::Atomic
bool Atomic
Definition: Instrumentation.h:129
llvm::getInstrProfNamesRegFuncName
StringRef getInstrProfNamesRegFuncName()
Return the name of the runtime interface that registers the PGO name strings.
Definition: InstrProf.h:135
llvm::GlobalValue::UnnamedAddr::Global
@ Global
llvm::GlobalValue::DefaultVisibility
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:63
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:449
llvm::Triple::isOSLinux
bool isOSLinux() const
Tests whether the OS is Linux.
Definition: Triple.h:595
llvm::GlobalValue::LinkageTypes
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
llvm::ArrayType
Class to represent array types.
Definition: DerivedTypes.h:359
llvm::createProfileFileNameVar
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput)
Definition: InstrProf.cpp:1160
llvm::Data
@ Data
Definition: SIMachineScheduler.h:56
llvm::Type::getInt32Ty
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:197
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:122
llvm::InstrProfiling
Instrumentation based profiling lowering pass.
Definition: InstrProfiling.h:35
F
#define F(x, y, z)
Definition: MD5.cpp:56
InstrProfData.inc
llvm::AtomicOrdering::Monotonic
@ Monotonic
getIntModuleFlagOrZero
static uint64_t getIntModuleFlagOrZero(const Module &M, StringRef Flag)
Definition: InstrProfiling.cpp:751
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::InstrProfValueProfileInst::getValueKind
ConstantInt * getValueKind() const
Definition: IntrinsicInst.h:1149
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
llvm::StringRef::substr
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:609
llvm::ConstantPointerNull
A constant pointer value that points to null.
Definition: Constants.h:533
Instruction.h
CommandLine.h
llvm::AMDGPU::HSAMD::ValueKind
ValueKind
Value kinds.
Definition: AMDGPUMetadata.h:73
llvm::BlockFrequencyInfo
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Definition: BlockFrequencyInfo.h:37
llvm::Triple::isOSBinFormatELF
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:632
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::VisibilityTypes
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition: GlobalValue.h:62
Constants.h
InstrProfiling.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::getInstrProfValuesVarPrefix
StringRef getInstrProfValuesVarPrefix()
Return the name prefix of value profile variables.
Definition: InstrProf.h:93
llvm::GlobalObject::setSection
void setSection(StringRef S)
Change the section for this global.
Definition: Globals.cpp:212
llvm::User
Definition: User.h:44
instrprof
instrprof
Definition: InstrProfiling.cpp:429
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
Twine.h
llvm::InstrProfValueProfileInst::getTargetValue
Value * getTargetValue() const
Definition: IntrinsicInst.h:1145
llvm::BranchProbabilityInfo
Analysis providing branch probability information.
Definition: BranchProbabilityInfo.h:115
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::canRenameComdatFunc
bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken=false)
Check if we can safely rename this Comdat function.
Definition: InstrProf.cpp:1115
TargetLibraryInfo.h
llvm::getInstrProfCountersVarPrefix
StringRef getInstrProfCountersVarPrefix()
Return the name prefix of profile counter variables.
Definition: InstrProf.h:90
llvm::Triple::supportsCOMDAT
bool supportsCOMDAT() const
Tests whether the target supports comdat.
Definition: Triple.h:815
false
Definition: StackSlotColoring.cpp:142
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:109
llvm::dwarf::toStringRef
StringRef toStringRef(const Optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
Definition: DWARFFormValue.h:177
llvm::getInstrProfInitFuncName
StringRef getInstrProfInitFuncName()
Return the name of the runtime initialization method that is generated by the compiler.
Definition: InstrProf.h:143
llvm::ConstantArray
ConstantArray - Constant Array Declarations.
Definition: Constants.h:407
llvm::Triple::isOSBinFormatMachO
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:645
llvm::Instruction
Definition: Instruction.h:45
llvm::MCID::Flag
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:146
InstrProf.h
llvm::Triple::getObjectFormat
ObjectFormatType getObjectFormat() const
getFormat - Get the object format for this triple.
Definition: Triple.h:337
llvm::appendToCompilerUsed
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
Definition: ModuleUtils.cpp:110
llvm::report_fatal_error
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
llvm::LoopBase::getExitingBlocks
void getExitingBlocks(SmallVectorImpl< BlockT * > &ExitingBlocks) const
Return all blocks inside the loop that have successors outside of the loop.
Definition: LoopInfoImpl.h:34
llvm::ConstantInt::get
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:898
llvm::InstrProfValueProfileInst::getIndex
ConstantInt * getIndex() const
Definition: IntrinsicInst.h:1154
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::InstrProfOptions::DoCounterPromotion
bool DoCounterPromotion
Definition: Instrumentation.h:126
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:55
llvm::Comdat
Definition: Comdat.h:31
llvm::MCID::Call
@ Call
Definition: MCInstrDesc.h:153
llvm::AtomicRMWInst::Add
@ Add
*p = old + v
Definition: Instructions.h:744
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
Type.h
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
LoopInfo.h
llvm::Triple::isOSFuchsia
bool isOSFuchsia() const
Definition: Triple.h:514
llvm::getInstrProfVNodesVarName
StringRef getInstrProfVNodesVarName()
Return the name of value profile node array variables:
Definition: InstrProf.h:96
llvm::cl::ZeroOrMore
@ ZeroOrMore
Definition: CommandLine.h:120
llvm::getInstrProfNameVarPrefix
StringRef getInstrProfNameVarPrefix()
Return the name prefix of variables containing instrumented function names.
Definition: InstrProf.h:84
BasicBlock.h
llvm::cl::opt< bool >
SSA
Memory SSA
Definition: MemorySSA.cpp:73
llvm::GlobalVariable::getInitializer
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Definition: GlobalVariable.h:136
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
getVarName
static std::string getVarName(InstrProfIncrementInst *Inc, StringRef Prefix)
Get the name of a profiling variable for a particular function.
Definition: InstrProfiling.cpp:736
llvm::Instruction::eraseFromParent
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:78
BranchProbabilityInfo.h
llvm::InstrProfValueProfileInst
This represents the llvm.instrprof_value_profile intrinsic.
Definition: IntrinsicInst.h:1127
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:463
llvm::GlobalValue::getVisibility
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:229
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
llvm::ConstantPointerNull::get
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1769
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::InstrProfOptions::InstrProfileOutput
std::string InstrProfileOutput
Definition: Instrumentation.h:135
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
profDataReferencedByCode
static bool profDataReferencedByCode(const Module &M)
Definition: InstrProfiling.cpp:767
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::DenseMap
Definition: DenseMap.h:714
shouldRecordFunctionAddr
static bool shouldRecordFunctionAddr(Function *F)
Definition: InstrProfiling.cpp:771
llvm::isIRPGOFlagSet
bool isIRPGOFlagSet(const Module *M)
Check if INSTR_PROF_RAW_VERSION_VAR is defined.
Definition: InstrProf.cpp:1097
llvm::LoopInfoBase::getLoopFor
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Definition: LoopInfo.h:964
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::Type::getInt64PtrTy
static PointerType * getInt64PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:261
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::appendToUsed
void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
Definition: ModuleUtils.cpp:106
llvm::LoopBase::getLoopPreheader
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
Definition: LoopInfoImpl.h:167
llvm::InstrProfIncrementInst::getIndex
ConstantInt * getIndex() const
Definition: IntrinsicInst.h:1109
llvm::GlobalValue::setLinkage
void setLinkage(LinkageTypes LT)
Definition: GlobalValue.h:454
ArrayRef.h
llvm::InstrProfOptions
Options for the frontend instrumentation based profiling pass.
Definition: Instrumentation.h:121
llvm::Function::Create
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:137
llvm::LoopBase::hasDedicatedExits
bool hasDedicatedExits() const
Return true if no exit block for the loop has a predecessor that is outside the loop.
Definition: LoopInfoImpl.h:92
llvm::getInstrProfRuntimeHookVarUseFuncName
StringRef getInstrProfRuntimeHookVarUseFuncName()
Return the name of the compiler generated function that references the runtime hook variable.
Definition: InstrProf.h:154
IRBuilder.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
lowering
Frontend instrumentation based coverage lowering
Definition: InstrProfiling.cpp:430
llvm::ArrayType::get
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Definition: Type.cpp:598
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::InstrProfIncrementInst::getNumCounters
ConstantInt * getNumCounters() const
Definition: IntrinsicInst.h:1105
llvm::collectPGOFuncNameStrings
Error collectPGOFuncNameStrings(ArrayRef< std::string > NameStrs, bool doCompression, std::string &Result)
Given a vector of strings (function PGO names) NameStrs, the method generates a combined string Resul...
Definition: InstrProf.cpp:400
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
Triple.h
llvm::getInstrProfRegFuncsName
StringRef getInstrProfRegFuncsName()
Return the name of function that registers all the per-function control data at program startup time ...
Definition: InstrProf.h:124
llvm::InstrProfIncrementInst::getHash
ConstantInt * getHash() const
Definition: IntrinsicInst.h:1101
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:1080
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
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:1489
llvm::AnalysisUsage::setPreservesCFG
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:253
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
if
if(llvm_vc STREQUAL "") set(fake_version_inc "$
Definition: CMakeLists.txt:14
llvm::Instruction::getFunction
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:70
llvm::Value::replaceAllUsesWith
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:517
llvm::BasicBlock::Create
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:100
uint32_t
llvm::ConstantDataArray::getString
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
Definition: Constants.cpp:3053
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
SSAUpdater.h
BlockFrequencyInfo.h
llvm::AMDGPUISD::BFI
@ BFI
Definition: AMDGPUISelLowering.h:418
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:294
llvm::LoadInst
An instruction for reading from memory.
Definition: Instructions.h:174
llvm::BasicBlock::getTerminator
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:148
llvm::Init
Definition: Record.h:271
llvm::ConstantInt::getZExtValue
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:140
llvm::BasicBlock::front
const Instruction & front() const
Definition: BasicBlock.h:308
llvm::DoInstrProfNameCompression
cl::opt< bool > DoInstrProfNameCompression
Attributes.h
Constant.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
llvm::Type::getInt64Ty
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:198
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::Constant::getNullValue
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:346
get
Should compile to something r4 addze r3 instead we get
Definition: README.txt:24
NC
#define NC
Definition: regutils.h:42
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:161
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
GlobalVariable.h
getOrInsertValueProfilingCall
static FunctionCallee getOrInsertValueProfilingCall(Module &M, const TargetLibraryInfo &TLI, ValueProfilingCallType CallType=ValueProfilingCallType::Default)
Definition: InstrProfiling.cpp:592
Casting.h
Function.h
enablesValueProfiling
static bool enablesValueProfiling(const Module &M)
Definition: InstrProfiling.cpp:761
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:219
llvm::TargetStackID::Default
@ Default
Definition: TargetFrameLowering.h:28
llvm::InstrProfiling::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition: InstrProfiling.cpp:411
llvm::MCID::Add
@ Add
Definition: MCInstrDesc.h:183
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::InstrProfIncrementInst
This represents the llvm.instrprof_increment intrinsic.
Definition: IntrinsicInst.h:1087
llvm::getInstrProfSectionName
std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
Definition: InstrProf.cpp:174
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::SPII::Store
@ Store
Definition: SparcInstrInfo.h:33
castToIncrementInst
static InstrProfIncrementInst * castToIncrementInst(Instruction *Instr)
Definition: InstrProfiling.cpp:438
llvm::Type::getVoidTy
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:180
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:56
Instructions.h
llvm::getInstrProfValueProfMemOpFuncName
StringRef getInstrProfValueProfMemOpFuncName()
Return the name profile runtime entry point to do memop size value profiling.
Definition: InstrProf.h:79
llvm::User::getNumOperands
unsigned getNumOperands() const
Definition: User.h:191
needsRuntimeRegistrationOfSectionRange
static bool needsRuntimeRegistrationOfSectionRange(const Triple &TT)
Definition: InstrProfiling.cpp:808
SmallVector.h
llvm::InstrProfOptions::NoRedZone
bool NoRedZone
Definition: Instrumentation.h:123
Dominators.h
llvm::getCoverageUnusedNamesVarName
StringRef getCoverageUnusedNamesVarName()
Return the name of the internal variable recording the array of PGO name vars referenced by the cover...
Definition: InstrProf.h:115
ModuleUtils.h
llvm::getInstrProfCounterBiasVarName
StringRef getInstrProfCounterBiasVarName()
Definition: InstrProf.h:158
llvm::Instruction::getParent
const BasicBlock * getParent() const
Definition: Instruction.h:94
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::InstrProfValueProfileInst::getName
GlobalVariable * getName() const
Definition: IntrinsicInst.h:1136
llvm::FunctionCallee
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:164
llvm::SmallVectorImpl< BasicBlock * >
llvm::Type::getInt16Ty
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:196
DerivedTypes.h
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::GlobalValue::getValueType
Type * getValueType() const
Definition: GlobalValue.h:273
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:926
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1478
llvm::getInstrProfValueProfFuncName
StringRef getInstrProfValueProfFuncName()
Return the name profile runtime entry point to do value profiling for a given site.
Definition: InstrProf.h:73
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::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
llvm::appendToGlobalCtors
void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Append F to the list of global ctors of module M with the given Priority.
Definition: ModuleUtils.cpp:66
llvm::User::getOperand
Value * getOperand(unsigned i) const
Definition: User.h:169
llvm::getInstrProfDataVarPrefix
StringRef getInstrProfDataVarPrefix()
Return the name prefix of variables containing per-function control data.
Definition: InstrProf.h:87
llvm::cl::desc
Definition: CommandLine.h:414
llvm::GlobalObject::setAlignment
void setAlignment(MaybeAlign Align)
Definition: Globals.cpp:117
llvm::InstrProfIncrementInst::getName
GlobalVariable * getName() const
Definition: IntrinsicInst.h:1096
llvm::SSAUpdater
Helper class for SSA formation on a set of values defined in multiple blocks.
Definition: SSAUpdater.h:38
llvm::StringRef::size
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:157
BasicBlockUtils.h
llvm::initializeInstrProfilingLegacyPassPass
void initializeInstrProfilingLegacyPassPass(PassRegistry &)
llvm::GlobalValue::LinkOnceODRLinkage
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:51
llvm::GlobalValue::setVisibility
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:235
InitializePasses.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::getInstrProfRegFuncName
StringRef getInstrProfRegFuncName()
Return the name of the runtime interface that registers per-function control data for one instrumente...
Definition: InstrProf.h:130
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:438
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:38