LLVM  15.0.0git
CodeGenPassBuilder.h
Go to the documentation of this file.
1 //===- Construction of codegen pass pipelines ------------------*- C++ -*--===//
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 /// \file
9 ///
10 /// Interfaces for registering analysis passes, producing common pass manager
11 /// configurations, and parsing of pass pipelines.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CODEGEN_CODEGENPASSBUILDER_H
16 #define LLVM_CODEGEN_CODEGENPASSBUILDER_H
17 
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
33 #include "llvm/IR/PassManager.h"
34 #include "llvm/IR/Verifier.h"
35 #include "llvm/MC/MCAsmInfo.h"
37 #include "llvm/Support/CodeGen.h"
38 #include "llvm/Support/Debug.h"
39 #include "llvm/Support/Error.h"
52 #include <cassert>
53 #include <type_traits>
54 #include <utility>
55 
56 namespace llvm {
57 
58 // FIXME: Dummy target independent passes definitions that have not yet been
59 // ported to new pass manager. Once they do, remove these.
60 #define DUMMY_FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
61  struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
62  template <typename... Ts> PASS_NAME(Ts &&...) {} \
63  PreservedAnalyses run(Function &, FunctionAnalysisManager &) { \
64  return PreservedAnalyses::all(); \
65  } \
66  };
67 #define DUMMY_MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
68  struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
69  template <typename... Ts> PASS_NAME(Ts &&...) {} \
70  PreservedAnalyses run(Module &, ModuleAnalysisManager &) { \
71  return PreservedAnalyses::all(); \
72  } \
73  };
74 #define DUMMY_MACHINE_MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
75  struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
76  template <typename... Ts> PASS_NAME(Ts &&...) {} \
77  Error run(Module &, MachineFunctionAnalysisManager &) { \
78  return Error::success(); \
79  } \
80  PreservedAnalyses run(MachineFunction &, \
81  MachineFunctionAnalysisManager &) { \
82  llvm_unreachable("this api is to make new PM api happy"); \
83  } \
84  static AnalysisKey Key; \
85  };
86 #define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
87  struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
88  template <typename... Ts> PASS_NAME(Ts &&...) {} \
89  PreservedAnalyses run(MachineFunction &, \
90  MachineFunctionAnalysisManager &) { \
91  return PreservedAnalyses::all(); \
92  } \
93  static AnalysisKey Key; \
94  };
95 #include "MachinePassRegistry.def"
96 
97 /// This class provides access to building LLVM's passes.
98 ///
99 /// Its members provide the baseline state available to passes during their
100 /// construction. The \c MachinePassRegistry.def file specifies how to construct
101 /// all of the built-in passes, and those may reference these members during
102 /// construction.
103 template <typename DerivedT> class CodeGenPassBuilder {
104 public:
107  : TM(TM), Opt(Opts), PIC(PIC) {
108  // Target could set CGPassBuilderOption::MISchedPostRA to true to achieve
109  // substitutePass(&PostRASchedulerID, &PostMachineSchedulerID)
110 
111  // Target should override TM.Options.EnableIPRA in their target-specific
112  // LLVMTM ctor. See TargetMachine::setGlobalISel for example.
113  if (Opt.EnableIPRA)
115 
118 
119  if (!Opt.OptimizeRegAlloc)
121  }
122 
124  raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
125  CodeGenFileType FileType) const;
126 
130  std::pair<StringRef, bool> getPassNameFromLegacyName(StringRef) const;
131 
136  }
137 
139  return PIC;
140  }
141 
142 protected:
143  template <typename PassT> using has_key_t = decltype(PassT::Key);
144 
145  template <typename PassT>
146  using is_module_pass_t = decltype(std::declval<PassT &>().run(
147  std::declval<Module &>(), std::declval<ModuleAnalysisManager &>()));
148 
149  template <typename PassT>
150  using is_function_pass_t = decltype(std::declval<PassT &>().run(
151  std::declval<Function &>(), std::declval<FunctionAnalysisManager &>()));
152 
153  // Function object to maintain state while adding codegen IR passes.
154  class AddIRPass {
155  public:
156  AddIRPass(ModulePassManager &MPM, bool DebugPM, bool Check = true)
157  : MPM(MPM) {
158  if (Check)
159  AddingFunctionPasses = false;
160  }
163  }
164 
165  // Add Function Pass
166  template <typename PassT>
167  std::enable_if_t<is_detected<is_function_pass_t, PassT>::value>
168  operator()(PassT &&Pass) {
169  if (AddingFunctionPasses && !*AddingFunctionPasses)
170  AddingFunctionPasses = true;
171  FPM.addPass(std::forward<PassT>(Pass));
172  }
173 
174  // Add Module Pass
175  template <typename PassT>
176  std::enable_if_t<is_detected<is_module_pass_t, PassT>::value &&
178  operator()(PassT &&Pass) {
179  assert((!AddingFunctionPasses || !*AddingFunctionPasses) &&
180  "could not add module pass after adding function pass");
181  MPM.addPass(std::forward<PassT>(Pass));
182  }
183 
184  private:
185  ModulePassManager &MPM;
187  // The codegen IR pipeline are mostly function passes with the exceptions of
188  // a few loop and module passes. `AddingFunctionPasses` make sures that
189  // we could only add module passes at the beginning of the pipeline. Once
190  // we begin adding function passes, we could no longer add module passes.
191  // This special-casing introduces less adaptor passes. If we have the need
192  // of adding module passes after function passes, we could change the
193  // implementation to accommodate that.
194  Optional<bool> AddingFunctionPasses;
195  };
196 
197  // Function object to maintain state while adding codegen machine passes.
199  public:
201 
202  template <typename PassT> void operator()(PassT &&Pass) {
203  static_assert(
205  "Machine function pass must define a static member variable `Key`.");
206  for (auto &C : BeforeCallbacks)
207  if (!C(&PassT::Key))
208  return;
209  PM.addPass(std::forward<PassT>(Pass));
210  for (auto &C : AfterCallbacks)
211  C(&PassT::Key);
212  }
213 
214  template <typename PassT> void insertPass(AnalysisKey *ID, PassT Pass) {
215  AfterCallbacks.emplace_back(
216  [this, ID, Pass = std::move(Pass)](AnalysisKey *PassID) {
217  if (PassID == ID)
218  this->PM.addPass(std::move(Pass));
219  });
220  }
221 
223  BeforeCallbacks.emplace_back(
224  [ID](AnalysisKey *PassID) { return PassID != ID; });
225  }
226 
228 
229  private:
231  SmallVector<llvm::unique_function<bool(AnalysisKey *)>, 4> BeforeCallbacks;
232  SmallVector<llvm::unique_function<void(AnalysisKey *)>, 4> AfterCallbacks;
233  };
234 
238 
239  /// Target override these hooks to parse target-specific analyses.
243  std::pair<StringRef, bool> getTargetPassNameFromLegacyName(StringRef) const {
244  return {"", false};
245  }
246 
247  template <typename TMC> TMC &getTM() const { return static_cast<TMC &>(TM); }
249 
250  /// Check whether or not GlobalISel should abort on error.
251  /// When this is disabled, GlobalISel will fall back on SDISel instead of
252  /// erroring out.
255  }
256 
257  /// Check whether or not a diagnostic should be emitted when GlobalISel
258  /// uses the fallback path. In other words, it will emit a diagnostic
259  /// when GlobalISel failed and isGlobalISelAbortEnabled is false.
262  }
263 
264  /// addInstSelector - This method should install an instruction selector pass,
265  /// which converts from LLVM code to machine instructions.
267  return make_error<StringError>("addInstSelector is not overridden",
269  }
270 
271  /// Add passes that optimize instruction level parallelism for out-of-order
272  /// targets. These passes are run while the machine code is still in SSA
273  /// form, so they can use MachineTraceMetrics to control their heuristics.
274  ///
275  /// All passes added here should preserve the MachineDominatorTree,
276  /// MachineLoopInfo, and MachineTraceMetrics analyses.
277  void addILPOpts(AddMachinePass &) const {}
278 
279  /// This method may be implemented by targets that want to run passes
280  /// immediately before register allocation.
282 
283  /// addPreRewrite - Add passes to the optimized register allocation pipeline
284  /// after register allocation is complete, but before virtual registers are
285  /// rewritten to physical registers.
286  ///
287  /// These passes must preserve VirtRegMap and LiveIntervals, and when running
288  /// after RABasic or RAGreedy, they should take advantage of LiveRegMatrix.
289  /// When these passes run, VirtRegMap contains legal physreg assignments for
290  /// all virtual registers.
291  ///
292  /// Note if the target overloads addRegAssignAndRewriteOptimized, this may not
293  /// be honored. This is also not generally used for the the fast variant,
294  /// where the allocation and rewriting are done in one pass.
295  void addPreRewrite(AddMachinePass &) const {}
296 
297  /// Add passes to be run immediately after virtual registers are rewritten
298  /// to physical registers.
300 
301  /// This method may be implemented by targets that want to run passes after
302  /// register allocation pass pipeline but before prolog-epilog insertion.
304 
305  /// This method may be implemented by targets that want to run passes after
306  /// prolog-epilog insertion and before the second instruction scheduling pass.
307  void addPreSched2(AddMachinePass &) const {}
308 
309  /// This pass may be implemented by targets that want to run passes
310  /// immediately before machine code is emitted.
312 
313  /// Targets may add passes immediately before machine code is emitted in this
314  /// callback. This is called even later than `addPreEmitPass`.
315  // FIXME: Rename `addPreEmitPass` to something more sensible given its actual
316  // position and remove the `2` suffix here as this callback is what
317  // `addPreEmitPass` *should* be but in reality isn't.
319 
320  /// {{@ For GlobalISel
321  ///
322 
323  /// addPreISel - This method should add any "last minute" LLVM->LLVM
324  /// passes (which are run just before instruction selector).
325  void addPreISel(AddIRPass &) const {
326  llvm_unreachable("addPreISel is not overridden");
327  }
328 
329  /// This method should install an IR translator pass, which converts from
330  /// LLVM code to machine instructions with possibly generic opcodes.
332  return make_error<StringError>("addIRTranslator is not overridden",
334  }
335 
336  /// This method may be implemented by targets that want to run passes
337  /// immediately before legalization.
339 
340  /// This method should install a legalize pass, which converts the instruction
341  /// sequence into one that can be selected by the target.
343  return make_error<StringError>("addLegalizeMachineIR is not overridden",
345  }
346 
347  /// This method may be implemented by targets that want to run passes
348  /// immediately before the register bank selection.
350 
351  /// This method should install a register bank selector pass, which
352  /// assigns register banks to virtual registers without a register
353  /// class or register banks.
355  return make_error<StringError>("addRegBankSelect is not overridden",
357  }
358 
359  /// This method may be implemented by targets that want to run passes
360  /// immediately before the (global) instruction selection.
362 
363  /// This method should install a (global) instruction selector pass, which
364  /// converts possibly generic instructions to fully target-specific
365  /// instructions, thereby constraining all generic virtual registers to
366  /// register classes.
368  return make_error<StringError>(
369  "addGlobalInstructionSelect is not overridden",
371  }
372  /// @}}
373 
374  /// High level function that adds all passes necessary to go from llvm IR
375  /// representation to the MI representation.
376  /// Adds IR based lowering and target specific optimization passes and finally
377  /// the core instruction selection passes.
378  void addISelPasses(AddIRPass &) const;
379 
380  /// Add the actual instruction selection passes. This does not include
381  /// preparation passes on IR.
382  Error addCoreISelPasses(AddMachinePass &) const;
383 
384  /// Add the complete, standard set of LLVM CodeGen passes.
385  /// Fully developed targets will not generally override this.
386  Error addMachinePasses(AddMachinePass &) const;
387 
388  /// Add passes to lower exception handling for the code generator.
389  void addPassesToHandleExceptions(AddIRPass &) const;
390 
391  /// Add common target configurable passes that perform LLVM IR to IR
392  /// transforms following machine independent optimization.
393  void addIRPasses(AddIRPass &) const;
394 
395  /// Add pass to prepare the LLVM IR for code generation. This should be done
396  /// before exception handling preparation passes.
397  void addCodeGenPrepare(AddIRPass &) const;
398 
399  /// Add common passes that perform LLVM IR to IR transforms in preparation for
400  /// instruction selection.
401  void addISelPrepare(AddIRPass &) const;
402 
403  /// Methods with trivial inline returns are convenient points in the common
404  /// codegen pass pipeline where targets may insert passes. Methods with
405  /// out-of-line standard implementations are major CodeGen stages called by
406  /// addMachinePasses. Some targets may override major stages when inserting
407  /// passes is insufficient, but maintaining overriden stages is more work.
408  ///
409 
410  /// addMachineSSAOptimization - Add standard passes that optimize machine
411  /// instructions in SSA form.
412  void addMachineSSAOptimization(AddMachinePass &) const;
413 
414  /// addFastRegAlloc - Add the minimum set of target-independent passes that
415  /// are required for fast register allocation.
416  Error addFastRegAlloc(AddMachinePass &) const;
417 
418  /// addOptimizedRegAlloc - Add passes related to register allocation.
419  /// LLVMTargetMachine provides standard regalloc passes for most targets.
420  void addOptimizedRegAlloc(AddMachinePass &) const;
421 
422  /// Add passes that optimize machine instructions after register allocation.
423  void addMachineLateOptimization(AddMachinePass &) const;
424 
425  /// addGCPasses - Add late codegen passes that analyze code for garbage
426  /// collection. This should return true if GC info should be printed after
427  /// these passes.
428  void addGCPasses(AddMachinePass &) const {}
429 
430  /// Add standard basic block placement passes.
431  void addBlockPlacement(AddMachinePass &) const;
432 
433  using CreateMCStreamer =
434  std::function<Expected<std::unique_ptr<MCStreamer>>(MCContext &)>;
436  llvm_unreachable("addAsmPrinter is not overridden");
437  }
438 
439  /// Utilities for targets to add passes to the pass manager.
440  ///
441 
442  /// createTargetRegisterAllocator - Create the register allocator pass for
443  /// this target at the current optimization level.
444  void addTargetRegisterAllocator(AddMachinePass &, bool Optimized) const;
445 
446  /// addMachinePasses helper to create the target-selected or overriden
447  /// regalloc pass.
448  void addRegAllocPass(AddMachinePass &, bool Optimized) const;
449 
450  /// Add core register alloator passes which do the actual register assignment
451  /// and rewriting. \returns true if any passes were added.
452  Error addRegAssignmentFast(AddMachinePass &) const;
453  Error addRegAssignmentOptimized(AddMachinePass &) const;
454 
455 private:
456  DerivedT &derived() { return static_cast<DerivedT &>(*this); }
457  const DerivedT &derived() const {
458  return static_cast<const DerivedT &>(*this);
459  }
460 };
461 
462 template <typename Derived>
465  raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
466  CodeGenFileType FileType) const {
467  AddIRPass addIRPass(MPM, Opt.DebugPM);
468  addISelPasses(addIRPass);
469 
470  AddMachinePass addPass(MFPM);
471  if (auto Err = addCoreISelPasses(addPass))
472  return std::move(Err);
473 
474  if (auto Err = derived().addMachinePasses(addPass))
475  return std::move(Err);
476 
477  derived().addAsmPrinter(
478  addPass, [this, &Out, DwoOut, FileType](MCContext &Ctx) {
479  return this->TM.createMCStreamer(Out, DwoOut, FileType, Ctx);
480  });
481 
482  addPass(FreeMachineFunctionPass());
483  return Error::success();
484 }
485 
487  AAManager AA;
488 
489  // The order in which these are registered determines their priority when
490  // being queried.
491 
492  switch (UseCFLAA) {
494  AA.registerFunctionAnalysis<CFLSteensAA>();
495  break;
496  case CFLAAType::Andersen:
497  AA.registerFunctionAnalysis<CFLAndersAA>();
498  break;
499  case CFLAAType::Both:
500  AA.registerFunctionAnalysis<CFLAndersAA>();
501  AA.registerFunctionAnalysis<CFLSteensAA>();
502  break;
503  default:
504  break;
505  }
506 
507  // Basic AliasAnalysis support.
508  // Add TypeBasedAliasAnalysis before BasicAliasAnalysis so that
509  // BasicAliasAnalysis wins if they disagree. This is intended to help
510  // support "obvious" type-punning idioms.
511  AA.registerFunctionAnalysis<TypeBasedAA>();
512  AA.registerFunctionAnalysis<ScopedNoAliasAA>();
513  AA.registerFunctionAnalysis<BasicAA>();
514 
515  return AA;
516 }
517 
518 template <typename Derived>
520  ModuleAnalysisManager &MAM) const {
521 #define MODULE_ANALYSIS(NAME, PASS_NAME, CONSTRUCTOR) \
522  MAM.registerPass([&] { return PASS_NAME CONSTRUCTOR; });
523 #include "MachinePassRegistry.def"
524  derived().registerTargetAnalysis(MAM);
525 }
526 
527 template <typename Derived>
529  FunctionAnalysisManager &FAM) const {
530  FAM.registerPass([this] { return registerAAAnalyses(this->Opt.UseCFLAA); });
531 
532 #define FUNCTION_ANALYSIS(NAME, PASS_NAME, CONSTRUCTOR) \
533  FAM.registerPass([&] { return PASS_NAME CONSTRUCTOR; });
534 #include "MachinePassRegistry.def"
535  derived().registerTargetAnalysis(FAM);
536 }
537 
538 template <typename Derived>
540  MachineFunctionAnalysisManager &MFAM) const {
541 #define MACHINE_FUNCTION_ANALYSIS(NAME, PASS_NAME, CONSTRUCTOR) \
542  MFAM.registerPass([&] { return PASS_NAME CONSTRUCTOR; });
543 #include "MachinePassRegistry.def"
544  derived().registerTargetAnalysis(MFAM);
545 }
546 
547 // FIXME: For new PM, use pass name directly in commandline seems good.
548 // Translate stringfied pass name to its old commandline name. Returns the
549 // matching legacy name and a boolean value indicating if the pass is a machine
550 // pass.
551 template <typename Derived>
552 std::pair<StringRef, bool>
554  std::pair<StringRef, bool> Ret;
555  if (Name.empty())
556  return Ret;
557 
558 #define FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
559  if (Name == NAME) \
560  Ret = {#PASS_NAME, false};
561 #define DUMMY_FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
562  if (Name == NAME) \
563  Ret = {#PASS_NAME, false};
564 #define MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
565  if (Name == NAME) \
566  Ret = {#PASS_NAME, false};
567 #define DUMMY_MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
568  if (Name == NAME) \
569  Ret = {#PASS_NAME, false};
570 #define MACHINE_MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
571  if (Name == NAME) \
572  Ret = {#PASS_NAME, true};
573 #define DUMMY_MACHINE_MODULE_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
574  if (Name == NAME) \
575  Ret = {#PASS_NAME, true};
576 #define MACHINE_FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
577  if (Name == NAME) \
578  Ret = {#PASS_NAME, true};
579 #define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME, CONSTRUCTOR) \
580  if (Name == NAME) \
581  Ret = {#PASS_NAME, true};
582 #include "llvm/CodeGen/MachinePassRegistry.def"
583 
584  if (Ret.first.empty())
585  Ret = derived().getTargetPassNameFromLegacyName(Name);
586 
587  if (Ret.first.empty())
589  Twine("\" pass could not be found."));
590 
591  return Ret;
592 }
593 
594 template <typename Derived>
596  if (TM.useEmulatedTLS())
597  addPass(LowerEmuTLSPass());
598 
599  addPass(PreISelIntrinsicLoweringPass());
600 
601  derived().addIRPasses(addPass);
602  derived().addCodeGenPrepare(addPass);
603  addPassesToHandleExceptions(addPass);
604  derived().addISelPrepare(addPass);
605 }
606 
607 /// Add common target configurable passes that perform LLVM IR to IR transforms
608 /// following machine independent optimization.
609 template <typename Derived>
611  // Before running any passes, run the verifier to determine if the input
612  // coming from the front-end and/or optimizer is valid.
613  if (!Opt.DisableVerify)
614  addPass(VerifierPass());
615 
616  // Run loop strength reduction before anything else.
617  if (getOptLevel() != CodeGenOpt::None && !Opt.DisableLSR) {
619  LoopStrengthReducePass(), /*UseMemorySSA*/ true, Opt.DebugPM));
620  // FIXME: use -stop-after so we could remove PrintLSR
621  if (Opt.PrintLSR)
622  addPass(PrintFunctionPass(dbgs(), "\n\n*** Code after LSR ***\n"));
623  }
624 
625  if (getOptLevel() != CodeGenOpt::None) {
626  // The MergeICmpsPass tries to create memcmp calls by grouping sequences of
627  // loads and compares. ExpandMemCmpPass then tries to expand those calls
628  // into optimally-sized loads and compares. The transforms are enabled by a
629  // target lowering hook.
630  if (!Opt.DisableMergeICmps)
631  addPass(MergeICmpsPass());
632  addPass(ExpandMemCmpPass());
633  }
634 
635  // Run GC lowering passes for builtin collectors
636  // TODO: add a pass insertion point here
637  addPass(GCLoweringPass());
638  addPass(ShadowStackGCLoweringPass());
639  addPass(LowerConstantIntrinsicsPass());
640 
641  // Make sure that no unreachable blocks are instruction selected.
642  addPass(UnreachableBlockElimPass());
643 
644  // Prepare expensive constants for SelectionDAG.
645  if (getOptLevel() != CodeGenOpt::None && !Opt.DisableConstantHoisting)
646  addPass(ConstantHoistingPass());
647 
648  // Replace calls to LLVM intrinsics (e.g., exp, log) operating on vector
649  // operands with calls to the corresponding functions in a vector library.
650  if (getOptLevel() != CodeGenOpt::None)
651  addPass(ReplaceWithVeclib());
652 
653  if (getOptLevel() != CodeGenOpt::None && !Opt.DisablePartialLibcallInlining)
654  addPass(PartiallyInlineLibCallsPass());
655 
656  // Instrument function entry and exit, e.g. with calls to mcount().
657  addPass(EntryExitInstrumenterPass(/*PostInlining=*/true));
658 
659  // Add scalarization of target's unsupported masked memory intrinsics pass.
660  // the unsupported intrinsic will be replaced with a chain of basic blocks,
661  // that stores/loads element one-by-one if the appropriate mask bit is set.
662  addPass(ScalarizeMaskedMemIntrinPass());
663 
664  // Expand reduction intrinsics into shuffle sequences if the target wants to.
665  addPass(ExpandReductionsPass());
666 }
667 
668 /// Turn exception handling constructs into something the code generators can
669 /// handle.
670 template <typename Derived>
672  AddIRPass &addPass) const {
673  const MCAsmInfo *MCAI = TM.getMCAsmInfo();
674  assert(MCAI && "No MCAsmInfo");
675  switch (MCAI->getExceptionHandlingType()) {
677  // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
678  // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
679  // catch info can get misplaced when a selector ends up more than one block
680  // removed from the parent invoke(s). This could happen when a landing
681  // pad is shared by multiple invokes and is also a target of a normal
682  // edge from elsewhere.
683  addPass(SjLjEHPreparePass());
688  addPass(DwarfEHPass(getOptLevel()));
689  break;
691  // We support using both GCC-style and MSVC-style exceptions on Windows, so
692  // add both preparation passes. Each pass will only actually run if it
693  // recognizes the personality function.
694  addPass(WinEHPass());
695  addPass(DwarfEHPass(getOptLevel()));
696  break;
698  // Wasm EH uses Windows EH instructions, but it does not need to demote PHIs
699  // on catchpads and cleanuppads because it does not outline them into
700  // funclets. Catchswitch blocks are not lowered in SelectionDAG, so we
701  // should remove PHIs there.
702  addPass(WinEHPass(/*DemoteCatchSwitchPHIOnly=*/false));
703  addPass(WasmEHPass());
704  break;
706  addPass(LowerInvokePass());
707 
708  // The lower invoke pass may create unreachable code. Remove it.
709  addPass(UnreachableBlockElimPass());
710  break;
711  }
712 }
713 
714 /// Add pass to prepare the LLVM IR for code generation. This should be done
715 /// before exception handling preparation passes.
716 template <typename Derived>
718  if (getOptLevel() != CodeGenOpt::None && !Opt.DisableCGP)
719  addPass(CodeGenPreparePass());
720  // TODO: Default ctor'd RewriteSymbolPass is no-op.
721  // addPass(RewriteSymbolPass());
722 }
723 
724 /// Add common passes that perform LLVM IR to IR transforms in preparation for
725 /// instruction selection.
726 template <typename Derived>
728  derived().addPreISel(addPass);
729 
730  // Add both the safe stack and the stack protection passes: each of them will
731  // only protect functions that have corresponding attributes.
732  addPass(SafeStackPass());
733  addPass(StackProtectorPass());
734 
735  if (Opt.PrintISelInput)
736  addPass(PrintFunctionPass(dbgs(),
737  "\n\n*** Final LLVM Code input to ISel ***\n"));
738 
739  // All passes which modify the LLVM IR are now complete; run the verifier
740  // to ensure that the IR is valid.
741  if (!Opt.DisableVerify)
742  addPass(VerifierPass());
743 }
744 
745 template <typename Derived>
747  AddMachinePass &addPass) const {
748  // Enable FastISel with -fast-isel, but allow that to be overridden.
749  TM.setO0WantsFastISel(Opt.EnableFastISelOption.getValueOr(true));
750 
751  // Determine an instruction selector.
752  enum class SelectorType { SelectionDAG, FastISel, GlobalISel };
753  SelectorType Selector;
754 
755  if (Opt.EnableFastISelOption && *Opt.EnableFastISelOption == true)
756  Selector = SelectorType::FastISel;
757  else if ((Opt.EnableGlobalISelOption &&
758  *Opt.EnableGlobalISelOption == true) ||
759  (TM.Options.EnableGlobalISel &&
760  (!Opt.EnableGlobalISelOption ||
761  *Opt.EnableGlobalISelOption == false)))
762  Selector = SelectorType::GlobalISel;
763  else if (TM.getOptLevel() == CodeGenOpt::None && TM.getO0WantsFastISel())
764  Selector = SelectorType::FastISel;
765  else
766  Selector = SelectorType::SelectionDAG;
767 
768  // Set consistently TM.Options.EnableFastISel and EnableGlobalISel.
769  if (Selector == SelectorType::FastISel) {
770  TM.setFastISel(true);
771  TM.setGlobalISel(false);
772  } else if (Selector == SelectorType::GlobalISel) {
773  TM.setFastISel(false);
774  TM.setGlobalISel(true);
775  }
776 
777  // Add instruction selector passes.
778  if (Selector == SelectorType::GlobalISel) {
779  if (auto Err = derived().addIRTranslator(addPass))
780  return std::move(Err);
781 
782  derived().addPreLegalizeMachineIR(addPass);
783 
784  if (auto Err = derived().addLegalizeMachineIR(addPass))
785  return std::move(Err);
786 
787  // Before running the register bank selector, ask the target if it
788  // wants to run some passes.
789  derived().addPreRegBankSelect(addPass);
790 
791  if (auto Err = derived().addRegBankSelect(addPass))
792  return std::move(Err);
793 
794  derived().addPreGlobalInstructionSelect(addPass);
795 
796  if (auto Err = derived().addGlobalInstructionSelect(addPass))
797  return std::move(Err);
798 
799  // Pass to reset the MachineFunction if the ISel failed.
800  addPass(ResetMachineFunctionPass(reportDiagnosticWhenGlobalISelFallback(),
801  isGlobalISelAbortEnabled()));
802 
803  // Provide a fallback path when we do not want to abort on
804  // not-yet-supported input.
805  if (!isGlobalISelAbortEnabled())
806  if (auto Err = derived().addInstSelector(addPass))
807  return std::move(Err);
808 
809  } else if (auto Err = derived().addInstSelector(addPass))
810  return std::move(Err);
811 
812  // Expand pseudo-instructions emitted by ISel. Don't run the verifier before
813  // FinalizeISel.
814  addPass(FinalizeISelPass());
815 
816  // // Print the instruction selected machine code...
817  // printAndVerify("After Instruction Selection");
818 
819  return Error::success();
820 }
821 
822 /// Add the complete set of target-independent postISel code generator passes.
823 ///
824 /// This can be read as the standard order of major LLVM CodeGen stages. Stages
825 /// with nontrivial configuration or multiple passes are broken out below in
826 /// add%Stage routines.
827 ///
828 /// Any CodeGenPassBuilder<Derived>::addXX routine may be overriden by the
829 /// Target. The addPre/Post methods with empty header implementations allow
830 /// injecting target-specific fixups just before or after major stages.
831 /// Additionally, targets have the flexibility to change pass order within a
832 /// stage by overriding default implementation of add%Stage routines below. Each
833 /// technique has maintainability tradeoffs because alternate pass orders are
834 /// not well supported. addPre/Post works better if the target pass is easily
835 /// tied to a common pass. But if it has subtle dependencies on multiple passes,
836 /// the target should override the stage instead.
837 template <typename Derived>
839  AddMachinePass &addPass) const {
840  // Add passes that optimize machine instructions in SSA form.
841  if (getOptLevel() != CodeGenOpt::None) {
842  derived().addMachineSSAOptimization(addPass);
843  } else {
844  // If the target requests it, assign local variables to stack slots relative
845  // to one another and simplify frame index references where possible.
846  addPass(LocalStackSlotPass());
847  }
848 
849  if (TM.Options.EnableIPRA)
850  addPass(RegUsageInfoPropagationPass());
851 
852  // Run pre-ra passes.
853  derived().addPreRegAlloc(addPass);
854 
855  // Run register allocation and passes that are tightly coupled with it,
856  // including phi elimination and scheduling.
857  if (*Opt.OptimizeRegAlloc) {
858  derived().addOptimizedRegAlloc(addPass);
859  } else {
860  if (auto Err = derived().addFastRegAlloc(addPass))
861  return Err;
862  }
863 
864  // Run post-ra passes.
865  derived().addPostRegAlloc(addPass);
866 
867  addPass(RemoveRedundantDebugValuesPass());
868 
869  // Insert prolog/epilog code. Eliminate abstract frame index references...
870  if (getOptLevel() != CodeGenOpt::None) {
871  addPass(PostRAMachineSinkingPass());
872  addPass(ShrinkWrapPass());
873  }
874 
875  addPass(PrologEpilogInserterPass());
876 
877  /// Add passes that optimize machine instructions after register allocation.
878  if (getOptLevel() != CodeGenOpt::None)
879  derived().addMachineLateOptimization(addPass);
880 
881  // Expand pseudo instructions before second scheduling pass.
882  addPass(ExpandPostRAPseudosPass());
883 
884  // Run pre-sched2 passes.
885  derived().addPreSched2(addPass);
886 
887  if (Opt.EnableImplicitNullChecks)
888  addPass(ImplicitNullChecksPass());
889 
890  // Second pass scheduler.
891  // Let Target optionally insert this pass by itself at some other
892  // point.
893  if (getOptLevel() != CodeGenOpt::None &&
894  !TM.targetSchedulesPostRAScheduling()) {
895  if (Opt.MISchedPostRA)
896  addPass(PostMachineSchedulerPass());
897  else
898  addPass(PostRASchedulerPass());
899  }
900 
901  // GC
902  derived().addGCPasses(addPass);
903 
904  // Basic block placement.
905  if (getOptLevel() != CodeGenOpt::None)
906  derived().addBlockPlacement(addPass);
907 
908  // Insert before XRay Instrumentation.
909  addPass(FEntryInserterPass());
910 
911  addPass(XRayInstrumentationPass());
912  addPass(PatchableFunctionPass());
913 
914  derived().addPreEmitPass(addPass);
915 
916  if (TM.Options.EnableIPRA)
917  // Collect register usage information and produce a register mask of
918  // clobbered registers, to be used to optimize call sites.
919  addPass(RegUsageInfoCollectorPass());
920 
921  addPass(FuncletLayoutPass());
922 
923  addPass(StackMapLivenessPass());
924  addPass(LiveDebugValuesPass());
925 
926  if (TM.Options.EnableMachineOutliner && getOptLevel() != CodeGenOpt::None &&
927  Opt.EnableMachineOutliner != RunOutliner::NeverOutline) {
928  bool RunOnAllFunctions =
929  (Opt.EnableMachineOutliner == RunOutliner::AlwaysOutline);
930  bool AddOutliner = RunOnAllFunctions || TM.Options.SupportsDefaultOutlining;
931  if (AddOutliner)
932  addPass(MachineOutlinerPass(RunOnAllFunctions));
933  }
934 
935  // Add passes that directly emit MI after all other MI passes.
936  derived().addPreEmitPass2(addPass);
937 
938  return Error::success();
939 }
940 
941 /// Add passes that optimize machine instructions in SSA form.
942 template <typename Derived>
944  AddMachinePass &addPass) const {
945  // Pre-ra tail duplication.
946  addPass(EarlyTailDuplicatePass());
947 
948  // Optimize PHIs before DCE: removing dead PHI cycles may make more
949  // instructions dead.
950  addPass(OptimizePHIsPass());
951 
952  // This pass merges large allocas. StackSlotColoring is a different pass
953  // which merges spill slots.
954  addPass(StackColoringPass());
955 
956  // If the target requests it, assign local variables to stack slots relative
957  // to one another and simplify frame index references where possible.
958  addPass(LocalStackSlotPass());
959 
960  // With optimization, dead code should already be eliminated. However
961  // there is one known exception: lowered code for arguments that are only
962  // used by tail calls, where the tail calls reuse the incoming stack
963  // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
964  addPass(DeadMachineInstructionElimPass());
965 
966  // Allow targets to insert passes that improve instruction level parallelism,
967  // like if-conversion. Such passes will typically need dominator trees and
968  // loop info, just like LICM and CSE below.
969  derived().addILPOpts(addPass);
970 
971  addPass(EarlyMachineLICMPass());
972  addPass(MachineCSEPass());
973 
974  addPass(MachineSinkingPass());
975 
976  addPass(PeepholeOptimizerPass());
977  // Clean-up the dead code that may have been generated by peephole
978  // rewriting.
979  addPass(DeadMachineInstructionElimPass());
980 }
981 
982 //===---------------------------------------------------------------------===//
983 /// Register Allocation Pass Configuration
984 //===---------------------------------------------------------------------===//
985 
986 /// Instantiate the default register allocator pass for this target for either
987 /// the optimized or unoptimized allocation path. This will be added to the pass
988 /// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
989 /// in the optimized case.
990 ///
991 /// A target that uses the standard regalloc pass order for fast or optimized
992 /// allocation may still override this for per-target regalloc
993 /// selection. But -regalloc=... always takes precedence.
994 template <typename Derived>
996  AddMachinePass &addPass, bool Optimized) const {
997  if (Optimized)
998  addPass(RAGreedyPass());
999  else
1000  addPass(RAFastPass());
1001 }
1002 
1003 /// Find and instantiate the register allocation pass requested by this target
1004 /// at the current optimization level. Different register allocators are
1005 /// defined as separate passes because they may require different analysis.
1006 template <typename Derived>
1008  bool Optimized) const {
1009  if (Opt.RegAlloc == RegAllocType::Default)
1010  // With no -regalloc= override, ask the target for a regalloc pass.
1011  derived().addTargetRegisterAllocator(addPass, Optimized);
1012  else if (Opt.RegAlloc == RegAllocType::Basic)
1013  addPass(RABasicPass());
1014  else if (Opt.RegAlloc == RegAllocType::Fast)
1015  addPass(RAFastPass());
1016  else if (Opt.RegAlloc == RegAllocType::Greedy)
1017  addPass(RAGreedyPass());
1018  else if (Opt.RegAlloc == RegAllocType::PBQP)
1019  addPass(RAPBQPPass());
1020  else
1021  llvm_unreachable("unknonwn register allocator type");
1022 }
1023 
1024 template <typename Derived>
1026  AddMachinePass &addPass) const {
1027  if (Opt.RegAlloc != RegAllocType::Default &&
1028  Opt.RegAlloc != RegAllocType::Fast)
1029  return make_error<StringError>(
1030  "Must use fast (default) register allocator for unoptimized regalloc.",
1032 
1033  addRegAllocPass(addPass, false);
1034  return Error::success();
1035 }
1036 
1037 template <typename Derived>
1039  AddMachinePass &addPass) const {
1040  // Add the selected register allocation pass.
1041  addRegAllocPass(addPass, true);
1042 
1043  // Allow targets to change the register assignments before rewriting.
1044  derived().addPreRewrite(addPass);
1045 
1046  // Finally rewrite virtual registers.
1047  addPass(VirtRegRewriterPass());
1048  // Perform stack slot coloring and post-ra machine LICM.
1049  //
1050  // FIXME: Re-enable coloring with register when it's capable of adding
1051  // kill markers.
1052  addPass(StackSlotColoringPass());
1053 
1054  return Error::success();
1055 }
1056 
1057 /// Add the minimum set of target-independent passes that are required for
1058 /// register allocation. No coalescing or scheduling.
1059 template <typename Derived>
1061  AddMachinePass &addPass) const {
1062  addPass(PHIEliminationPass());
1063  addPass(TwoAddressInstructionPass());
1064  return derived().addRegAssignmentFast(addPass);
1065 }
1066 
1067 /// Add standard target-independent passes that are tightly coupled with
1068 /// optimized register allocation, including coalescing, machine instruction
1069 /// scheduling, and register allocation itself.
1070 template <typename Derived>
1072  AddMachinePass &addPass) const {
1073  addPass(DetectDeadLanesPass());
1074 
1075  addPass(ProcessImplicitDefsPass());
1076 
1077  // Edge splitting is smarter with machine loop info.
1078  addPass(PHIEliminationPass());
1079 
1080  // Eventually, we want to run LiveIntervals before PHI elimination.
1081  if (Opt.EarlyLiveIntervals)
1082  addPass(LiveIntervalsPass());
1083 
1084  addPass(TwoAddressInstructionPass());
1085  addPass(RegisterCoalescerPass());
1086 
1087  // The machine scheduler may accidentally create disconnected components
1088  // when moving subregister definitions around, avoid this by splitting them to
1089  // separate vregs before. Splitting can also improve reg. allocation quality.
1090  addPass(RenameIndependentSubregsPass());
1091 
1092  // PreRA instruction scheduling.
1093  addPass(MachineSchedulerPass());
1094 
1095  if (derived().addRegAssignmentOptimized(addPass)) {
1096  // Allow targets to expand pseudo instructions depending on the choice of
1097  // registers before MachineCopyPropagation.
1098  derived().addPostRewrite(addPass);
1099 
1100  // Copy propagate to forward register uses and try to eliminate COPYs that
1101  // were not coalesced.
1102  addPass(MachineCopyPropagationPass());
1103 
1104  // Run post-ra machine LICM to hoist reloads / remats.
1105  //
1106  // FIXME: can this move into MachineLateOptimization?
1107  addPass(MachineLICMPass());
1108  }
1109 }
1110 
1111 //===---------------------------------------------------------------------===//
1112 /// Post RegAlloc Pass Configuration
1113 //===---------------------------------------------------------------------===//
1114 
1115 /// Add passes that optimize machine instructions after register allocation.
1116 template <typename Derived>
1118  AddMachinePass &addPass) const {
1119  // Branch folding must be run after regalloc and prolog/epilog insertion.
1120  addPass(BranchFolderPass());
1121 
1122  // Tail duplication.
1123  // Note that duplicating tail just increases code size and degrades
1124  // performance for targets that require Structured Control Flow.
1125  // In addition it can also make CFG irreducible. Thus we disable it.
1126  if (!TM.requiresStructuredCFG())
1127  addPass(TailDuplicatePass());
1128 
1129  // Copy propagation.
1130  addPass(MachineCopyPropagationPass());
1131 }
1132 
1133 /// Add standard basic block placement passes.
1134 template <typename Derived>
1136  AddMachinePass &addPass) const {
1137  addPass(MachineBlockPlacementPass());
1138  // Run a separate pass to collect block placement statistics.
1139  if (Opt.EnableBlockPlacementStats)
1140  addPass(MachineBlockPlacementStatsPass());
1141 }
1142 
1143 } // namespace llvm
1144 
1145 #endif // LLVM_CODEGEN_CODEGENPASSBUILDER_H
TypeBasedAliasAnalysis.h
llvm::TargetMachine::getOptLevel
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Definition: TargetMachine.cpp:186
llvm::BasicAA
Analysis pass providing a never-invalidated alias analysis result.
Definition: BasicAliasAnalysis.h:161
llvm::EntryExitInstrumenterPass
Definition: EntryExitInstrumenter.h:24
llvm::ScopedNoAliasAA
Analysis pass providing a never-invalidated alias analysis result.
Definition: ScopedNoAliasAA.h:53
llvm::AAManager
A manager for alias analyses.
Definition: AliasAnalysis.h:1299
llvm::PrintFunctionPass
Pass for printing a Function as LLVM's text IR assembly.
Definition: IRPrintingPasses.h:75
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::RegAllocType::PBQP
@ PBQP
llvm::PreISelIntrinsicLoweringPass
Definition: PreISelIntrinsicLowering.h:22
llvm::CodeGenPassBuilder::getPassInstrumentationCallbacks
PassInstrumentationCallbacks * getPassInstrumentationCallbacks() const
Definition: CodeGenPassBuilder.h:138
llvm::CodeGenPassBuilder::AddIRPass::~AddIRPass
~AddIRPass()
Definition: CodeGenPassBuilder.h:161
llvm::CodeGenPassBuilder::isGlobalISelAbortEnabled
bool isGlobalISelAbortEnabled() const
Check whether or not GlobalISel should abort on error.
Definition: CodeGenPassBuilder.h:253
llvm::ExpandReductionsPass
Definition: ExpandReductions.h:16
MCTargetOptions.h
llvm::CodeGenPassBuilder
This class provides access to building LLVM's passes.
Definition: CodeGenPassBuilder.h:103
llvm::CodeGenPassBuilder::addTargetRegisterAllocator
void addTargetRegisterAllocator(AddMachinePass &, bool Optimized) const
Utilities for targets to add passes to the pass manager.
Definition: CodeGenPassBuilder.h:995
llvm::CodeGenPassBuilder::AddMachinePass::insertPass
void insertPass(AnalysisKey *ID, PassT Pass)
Definition: CodeGenPassBuilder.h:214
llvm::CodeGenPassBuilder::addGCPasses
void addGCPasses(AddMachinePass &) const
addGCPasses - Add late codegen passes that analyze code for garbage collection.
Definition: CodeGenPassBuilder.h:428
llvm::ReplaceWithVeclib
Definition: ReplaceWithVeclib.h:24
llvm::unique_function
unique_function is a type-erasing functor similar to std::function.
Definition: FunctionExtras.h:56
llvm::ExceptionHandling::SjLj
@ SjLj
setjmp/longjmp based exceptions
llvm::CodeGenPassBuilder::addILPOpts
void addILPOpts(AddMachinePass &) const
Add passes that optimize instruction level parallelism for out-of-order targets.
Definition: CodeGenPassBuilder.h:277
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:74
StringRef.h
llvm::PassManager::addPass
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:550
llvm::CodeGenPassBuilder::CodeGenPassBuilder
CodeGenPassBuilder(LLVMTargetMachine &TM, CGPassBuilderOption Opts, PassInstrumentationCallbacks *PIC)
Definition: CodeGenPassBuilder.h:105
llvm::CodeGenPassBuilder::CreateMCStreamer
std::function< Expected< std::unique_ptr< MCStreamer > >(MCContext &)> CreateMCStreamer
Definition: CodeGenPassBuilder.h:434
llvm::CodeGenPassBuilder::addInstSelector
Error addInstSelector(AddMachinePass &) const
addInstSelector - This method should install an instruction selector pass, which converts from LLVM c...
Definition: CodeGenPassBuilder.h:266
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::RegAllocType::Basic
@ Basic
ErrorHandling.h
llvm::CodeGenPassBuilder::addPostRewrite
void addPostRewrite(AddMachinePass &) const
Add passes to be run immediately after virtual registers are rewritten to physical registers.
Definition: CodeGenPassBuilder.h:299
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::CodeGenPassBuilder::registerTargetAnalysis
void registerTargetAnalysis(ModuleAnalysisManager &) const
Target override these hooks to parse target-specific analyses.
Definition: CodeGenPassBuilder.h:240
CGPassBuilderOption.h
Error.h
llvm::VerifierPass
Create a verifier pass.
Definition: Verifier.h:137
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::CodeGenPassBuilder::addISelPrepare
void addISelPrepare(AddIRPass &) const
Add common passes that perform LLVM IR to IR transforms in preparation for instruction selection.
Definition: CodeGenPassBuilder.h:727
llvm::CodeGenPassBuilder::addIRTranslator
Error addIRTranslator(AddMachinePass &) const
This method should install an IR translator pass, which converts from LLVM code to machine instructio...
Definition: CodeGenPassBuilder.h:331
llvm::RegAllocType::Fast
@ Fast
llvm::CFLAAType::Andersen
@ Andersen
llvm::CodeGenPassBuilder::addMachinePasses
Error addMachinePasses(AddMachinePass &) const
Add the complete, standard set of LLVM CodeGen passes.
Definition: CodeGenPassBuilder.h:838
llvm::CodeGenPassBuilder::addOptimizedRegAlloc
void addOptimizedRegAlloc(AddMachinePass &) const
addOptimizedRegAlloc - Add passes related to register allocation.
Definition: CodeGenPassBuilder.h:1071
llvm::CodeGenPassBuilder::AddIRPass::operator()
std::enable_if_t< is_detected< is_module_pass_t, PassT >::value &&!is_detected< is_function_pass_t, PassT >::value > operator()(PassT &&Pass)
Definition: CodeGenPassBuilder.h:178
llvm::UseCFLAA
static cl::opt<::CFLAAType > UseCFLAA("use-cfl-aa", cl::init(::CFLAAType::None), cl::Hidden, cl::desc("Enable the new, experimental CFL alias analysis"), cl::values(clEnumValN(::CFLAAType::None, "none", "Disable CFL-AA"), clEnumValN(::CFLAAType::Steensgaard, "steens", "Enable unification-based CFL-AA"), clEnumValN(::CFLAAType::Andersen, "anders", "Enable inclusion-based CFL-AA"), clEnumValN(::CFLAAType::Both, "both", "Enable both variants of CFL-AA")))
llvm::ExceptionHandling::ARM
@ ARM
ARM EHABI.
llvm::Optional< bool >
llvm::RunOutliner::NeverOutline
@ NeverOutline
PartiallyInlineLibCalls.h
llvm::CFLAAType::Both
@ Both
llvm::CodeGenPassBuilder::getOptLevel
CodeGenOpt::Level getOptLevel() const
Definition: CodeGenPassBuilder.h:248
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:119
llvm::LoopStrengthReducePass
Performs Loop Strength Reduce Pass.
Definition: LoopStrengthReduce.h:33
BasicAliasAnalysis.h
llvm::ScalarizeMaskedMemIntrinPass
Definition: ScalarizeMaskedMemIntrin.h:23
llvm::is_detected
typename detail::detector< void, Op, Args... >::value_t is_detected
Detects if a given trait holds for some set of arguments 'Args'.
Definition: STLExtras.h:97
llvm::ExceptionHandling::AIX
@ AIX
AIX Exception Handling.
llvm::TypeBasedAA
Analysis pass providing a never-invalidated alias analysis result.
Definition: TypeBasedAliasAnalysis.h:59
AliasAnalysis.h
llvm::CodeGenPassBuilder::addCodeGenPrepare
void addCodeGenPrepare(AddIRPass &) const
Add pass to prepare the LLVM IR for code generation.
Definition: CodeGenPassBuilder.h:717
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::CodeGenPassBuilder::addPreLegalizeMachineIR
void addPreLegalizeMachineIR(AddMachinePass &) const
This method may be implemented by targets that want to run passes immediately before legalization.
Definition: CodeGenPassBuilder.h:338
llvm::CodeGenPassBuilder::addPreEmitPass2
void addPreEmitPass2(AddMachinePass &) const
Targets may add passes immediately before machine code is emitted in this callback.
Definition: CodeGenPassBuilder.h:318
llvm::registerAAAnalyses
static AAManager registerAAAnalyses(CFLAAType UseCFLAA)
Definition: CodeGenPassBuilder.h:486
TargetMachine.h
llvm::SelectionDAG
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:220
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::TargetOptions::EnableIPRA
unsigned EnableIPRA
This flag enables InterProcedural Register Allocation (IPRA).
Definition: TargetOptions.h:297
MAM
ModuleAnalysisManager MAM
Definition: PassBuilderBindings.cpp:61
llvm::CodeGenPassBuilder::registerTargetAnalysis
void registerTargetAnalysis(FunctionAnalysisManager &) const
Definition: CodeGenPassBuilder.h:241
LowerInvoke.h
Check
#define Check(C,...)
Definition: Lint.cpp:170
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:486
llvm::CodeGenPassBuilder::registerFunctionAnalyses
void registerFunctionAnalyses(FunctionAnalysisManager &) const
Definition: CodeGenPassBuilder.h:528
llvm::MachineFunctionAnalysisManager::FAM
FunctionAnalysisManager * FAM
Definition: MachinePassManager.h:99
llvm::CodeGenPassBuilder::registerAnalyses
void registerAnalyses(MachineFunctionAnalysisManager &MFAM) const
Definition: CodeGenPassBuilder.h:132
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:143
IRPrintingPasses.h
llvm::ExceptionHandling::Wasm
@ Wasm
WebAssembly Exception Handling.
llvm::CodeGenPassBuilder::is_function_pass_t
decltype(std::declval< PassT & >().run(std::declval< Function & >(), std::declval< FunctionAnalysisManager & >())) is_function_pass_t
Definition: CodeGenPassBuilder.h:151
llvm::CodeGenPassBuilder::addIRPasses
void addIRPasses(AddIRPass &) const
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
Definition: CodeGenPassBuilder.h:610
llvm::CodeGenPassBuilder::addPassesToHandleExceptions
void addPassesToHandleExceptions(AddIRPass &) const
Add passes to lower exception handling for the code generator.
Definition: CodeGenPassBuilder.h:671
llvm::CodeGenPassBuilder::is_module_pass_t
decltype(std::declval< PassT & >().run(std::declval< Module & >(), std::declval< ModuleAnalysisManager & >())) is_module_pass_t
Definition: CodeGenPassBuilder.h:147
llvm::CGPassBuilderOption
Definition: CGPassBuilderOption.h:29
ConstantHoisting.h
llvm::CFLSteensAA
Analysis pass providing a never-invalidated alias analysis result.
Definition: CFLSteensAliasAnalysis.h:109
CFLAndersAliasAnalysis.h
llvm::MachineFunctionAnalysisManager
An AnalysisManager<MachineFunction> that also exposes IR analysis results.
Definition: MachinePassManager.h:41
ScopedNoAliasAA.h
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::CodeGenPassBuilder::AddIRPass::AddIRPass
AddIRPass(ModulePassManager &MPM, bool DebugPM, bool Check=true)
Definition: CodeGenPassBuilder.h:156
llvm::CodeGenPassBuilder::addRegAssignmentOptimized
Error addRegAssignmentOptimized(AddMachinePass &) const
Definition: CodeGenPassBuilder.h:1038
llvm::dxil::PointerTypeAnalysis::run
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
Definition: PointerTypeAnalysis.cpp:101
llvm::MachO::FileType
FileType
Defines the file type this file represents.
Definition: InterfaceFile.h:53
llvm::CodeGenPassBuilder::AddIRPass
Definition: CodeGenPassBuilder.h:154
llvm::CodeGenPassBuilder::addFastRegAlloc
Error addFastRegAlloc(AddMachinePass &) const
addFastRegAlloc - Add the minimum set of target-independent passes that are required for fast registe...
Definition: CodeGenPassBuilder.h:1060
llvm::CodeGenPassBuilder::AddMachinePass::AddMachinePass
AddMachinePass(MachineFunctionPassManager &PM)
Definition: CodeGenPassBuilder.h:200
llvm::CodeGenPassBuilder::registerTargetAnalysis
void registerTargetAnalysis(MachineFunctionAnalysisManager &) const
Definition: CodeGenPassBuilder.h:242
llvm::createModuleToFunctionPassAdaptor
ModuleToFunctionPassAdaptor createModuleToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
Definition: PassManager.h:1224
llvm::CodeGenPassBuilder::has_key_t
decltype(PassT::Key) has_key_t
Definition: CodeGenPassBuilder.h:143
llvm::CodeGenPassBuilder::addGlobalInstructionSelect
Error addGlobalInstructionSelect(AddMachinePass &) const
This method should install a (global) instruction selector pass, which converts possibly generic inst...
Definition: CodeGenPassBuilder.h:367
llvm::raw_pwrite_stream
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:418
llvm::LowerInvokePass
Definition: LowerInvoke.h:22
llvm::CodeGenPassBuilder::AddMachinePass
Definition: CodeGenPassBuilder.h:198
llvm::CodeGenPassBuilder::reportDiagnosticWhenGlobalISelFallback
bool reportDiagnosticWhenGlobalISelFallback() const
Check whether or not a diagnostic should be emitted when GlobalISel uses the fallback path.
Definition: CodeGenPassBuilder.h:260
llvm::CodeGenPassBuilder::getTargetPassNameFromLegacyName
std::pair< StringRef, bool > getTargetPassNameFromLegacyName(StringRef) const
Definition: CodeGenPassBuilder.h:243
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::MachineFunctionAnalysisManager::MAM
ModuleAnalysisManager * MAM
Definition: MachinePassManager.h:100
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:69
llvm::CodeGenPassBuilder::addRegAssignmentFast
Error addRegAssignmentFast(AddMachinePass &) const
Add core register alloator passes which do the actual register assignment and rewriting.
Definition: CodeGenPassBuilder.h:1025
llvm::UnreachableBlockElimPass
Definition: UnreachableBlockElim.h:29
llvm::CodeGenPassBuilder::addISelPasses
void addISelPasses(AddIRPass &) const
High level function that adds all passes necessary to go from llvm IR representation to the MI repres...
Definition: CodeGenPassBuilder.h:595
llvm::createFunctionToLoopPassAdaptor
std::enable_if_t< is_detected< HasRunOnLoopT, LoopPassT >::value, FunctionToLoopPassAdaptor > createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA=false, bool UseBlockFrequencyInfo=false, bool UseBranchProbabilityInfo=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
Definition: LoopPassManager.h:472
llvm::TargetMachine::Options
TargetOptions Options
Definition: TargetMachine.h:118
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::CGPassBuilderOption::EnableGlobalISelAbort
Optional< GlobalISelAbortMode > EnableGlobalISelAbort
Definition: CGPassBuilderOption.h:52
llvm::RegAllocType::Greedy
@ Greedy
llvm::FastISel
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
Definition: FastISel.h:65
LoopPassManager.h
llvm::CodeGenPassBuilder::registerModuleAnalyses
void registerModuleAnalyses(ModuleAnalysisManager &) const
Definition: CodeGenPassBuilder.h:519
llvm::CodeGenPassBuilder::buildPipeline
Error buildPipeline(ModulePassManager &MPM, MachineFunctionPassManager &MFPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType) const
Definition: CodeGenPassBuilder.h:463
llvm::CFLAAType::Steensgaard
@ Steensgaard
llvm::CodeGenOpt::None
@ None
Definition: CodeGen.h:53
llvm::CodeGenPassBuilder::addBlockPlacement
void addBlockPlacement(AddMachinePass &) const
Add standard basic block placement passes.
Definition: CodeGenPassBuilder.h:1135
MCAsmInfo.h
llvm::CodeGenPassBuilder::Opt
CGPassBuilderOption Opt
Definition: CodeGenPassBuilder.h:236
llvm::CodeGenFileType
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition: CodeGen.h:63
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::CodeGenPassBuilder::addPreEmitPass
void addPreEmitPass(AddMachinePass &) const
This pass may be implemented by targets that want to run passes immediately before machine code is em...
Definition: CodeGenPassBuilder.h:311
llvm::CodeGenPassBuilder::addPreGlobalInstructionSelect
void addPreGlobalInstructionSelect(AddMachinePass &) const
This method may be implemented by targets that want to run passes immediately before the (global) ins...
Definition: CodeGenPassBuilder.h:361
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::RunOutliner::AlwaysOutline
@ AlwaysOutline
llvm::GlobalISelAbortMode::DisableWithDiag
@ DisableWithDiag
llvm::CodeGenPassBuilder::addAsmPrinter
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const
Definition: CodeGenPassBuilder.h:435
llvm::CodeGenOpt::Level
Level
Definition: CodeGen.h:52
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:280
llvm::CodeGenPassBuilder::addLegalizeMachineIR
Error addLegalizeMachineIR(AddMachinePass &) const
This method should install a legalize pass, which converts the instruction sequence into one that can...
Definition: CodeGenPassBuilder.h:342
llvm::CodeGenPassBuilder::AddMachinePass::operator()
void operator()(PassT &&Pass)
Definition: CodeGenPassBuilder.h:202
llvm::PassManager< Module >
MergeICmps.h
llvm::CodeGenPassBuilder::addPreRewrite
void addPreRewrite(AddMachinePass &) const
addPreRewrite - Add passes to the optimized register allocation pipeline after register allocation is...
Definition: CodeGenPassBuilder.h:295
llvm::CodeGenPassBuilder::addPostRegAlloc
void addPostRegAlloc(AddMachinePass &) const
This method may be implemented by targets that want to run passes after register allocation pass pipe...
Definition: CodeGenPassBuilder.h:303
MachinePassManager.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
Verifier.h
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
LoopStrengthReduce.h
llvm::CodeGenPassBuilder::PIC
PassInstrumentationCallbacks * PIC
Definition: CodeGenPassBuilder.h:237
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
llvm::CodeGenPassBuilder::registerMachineFunctionAnalyses
void registerMachineFunctionAnalyses(MachineFunctionAnalysisManager &) const
Definition: CodeGenPassBuilder.h:539
llvm::CGPassBuilderOption::OptimizeRegAlloc
Optional< bool > OptimizeRegAlloc
Definition: CGPassBuilderOption.h:30
llvm::CodeGenPassBuilder::addRegBankSelect
Error addRegBankSelect(AddMachinePass &) const
This method should install a register bank selector pass, which assigns register banks to virtual reg...
Definition: CodeGenPassBuilder.h:354
llvm::TargetOptions::GlobalISelAbort
GlobalISelAbortMode GlobalISelAbort
EnableGlobalISelAbort - Control abort behaviour when global instruction selection fails to lower/sele...
Definition: TargetOptions.h:239
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::ExceptionHandling::WinEH
@ WinEH
Windows Exception Handling.
PassManager.h
llvm::PartiallyInlineLibCallsPass
Definition: PartiallyInlineLibCalls.h:22
LowerConstantIntrinsics.h
llvm::CodeGenPassBuilder::AddMachinePass::releasePM
MachineFunctionPassManager releasePM()
Definition: CodeGenPassBuilder.h:227
llvm::MachineFunctionPassManager::addPass
void addPass(PassT &&Pass)
Definition: MachinePassManager.h:155
llvm::LLVMTargetMachine
This class describes a target machine that is implemented with the LLVM target-independent code gener...
Definition: TargetMachine.h:405
ScalarizeMaskedMemIntrin.h
UnreachableBlockElim.h
llvm::AnalysisManager::registerPass
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:842
llvm::MachineFunctionPassManager
MachineFunctionPassManager adds/removes below features to/from the base PassManager template instanti...
Definition: MachinePassManager.h:132
llvm::CodeGenPassBuilder::addCoreISelPasses
Error addCoreISelPasses(AddMachinePass &) const
Add the actual instruction selection passes.
Definition: CodeGenPassBuilder.h:746
llvm::ExceptionHandling::None
@ None
No exception support.
AA
CodeGen.h
llvm::MCAsmInfo::getExceptionHandlingType
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:777
llvm::GlobalISelAbortMode::Enable
@ Enable
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
SmallVector.h
ExpandReductions.h
llvm::CodeGenPassBuilder::addPreRegBankSelect
void addPreRegBankSelect(AddMachinePass &) const
This method may be implemented by targets that want to run passes immediately before the register ban...
Definition: CodeGenPassBuilder.h:349
llvm::LowerConstantIntrinsicsPass
Definition: LowerConstantIntrinsics.h:24
llvm::PassInstrumentationCallbacks
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
Definition: PassInstrumentation.h:66
ReplaceWithVeclib.h
llvm::CFLAAType
CFLAAType
Definition: CGPassBuilderOption.h:25
TargetTransformInfo.h
llvm::CodeGenPassBuilder::addMachineSSAOptimization
void addMachineSSAOptimization(AddMachinePass &) const
Methods with trivial inline returns are convenient points in the common codegen pass pipeline where t...
Definition: CodeGenPassBuilder.h:943
llvm::CodeGenPassBuilder::AddIRPass::operator()
std::enable_if_t< is_detected< is_function_pass_t, PassT >::value > operator()(PassT &&Pass)
Definition: CodeGenPassBuilder.h:168
llvm::CodeGenPassBuilder::addRegAllocPass
void addRegAllocPass(AddMachinePass &, bool Optimized) const
addMachinePasses helper to create the target-selected or overriden regalloc pass.
Definition: CodeGenPassBuilder.h:1007
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
llvm::CFLAndersAA
Analysis pass providing a never-invalidated alias analysis result.
Definition: CFLAndersAliasAnalysis.h:94
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::CodeGenPassBuilder::getTM
TMC & getTM() const
Definition: CodeGenPassBuilder.h:247
llvm::CodeGenPassBuilder::addPreISel
void addPreISel(AddIRPass &) const
{{@ For GlobalISel
Definition: CodeGenPassBuilder.h:325
EntryExitInstrumenter.h
llvm::RegAllocType::Default
@ Default
llvm::CodeGenPassBuilder::addMachineLateOptimization
void addMachineLateOptimization(AddMachinePass &) const
Add passes that optimize machine instructions after register allocation.
Definition: CodeGenPassBuilder.h:1117
llvm::CGPassBuilderOption::EnableIPRA
Optional< bool > EnableIPRA
Definition: CGPassBuilderOption.h:31
llvm::CodeGenPassBuilder::AddMachinePass::disablePass
void disablePass(AnalysisKey *ID)
Definition: CodeGenPassBuilder.h:222
llvm::ConstantHoistingPass
Definition: ConstantHoisting.h:123
llvm::CodeGenPassBuilder::addPreRegAlloc
void addPreRegAlloc(AddMachinePass &) const
This method may be implemented by targets that want to run passes immediately before register allocat...
Definition: CodeGenPassBuilder.h:281
MPM
ModulePassManager MPM
Definition: PassBuilderBindings.cpp:70
llvm::ExceptionHandling::DwarfCFI
@ DwarfCFI
DWARF-like instruction based exceptions.
Debug.h
llvm::MergeICmpsPass
Definition: MergeICmps.h:18
llvm::CodeGenPassBuilder::addPreSched2
void addPreSched2(AddMachinePass &) const
This method may be implemented by targets that want to run passes after prolog-epilog insertion and b...
Definition: CodeGenPassBuilder.h:307
PreISelIntrinsicLowering.h
CFLSteensAliasAnalysis.h
llvm::CodeGenPassBuilder::getPassNameFromLegacyName
std::pair< StringRef, bool > getPassNameFromLegacyName(StringRef) const
Definition: CodeGenPassBuilder.h:553
llvm::CodeGenPassBuilder::TM
LLVMTargetMachine & TM
Definition: CodeGenPassBuilder.h:235
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37