LLVM 23.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 producing common pass manager configurations.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_PASSES_CODEGENPASSBUILDER_H
15#define LLVM_PASSES_CODEGENPASSBUILDER_H
16
18#include "llvm/ADT/StringRef.h"
65#include "llvm/CodeGen/PEI.h"
102#include "llvm/IR/PassManager.h"
103#include "llvm/IR/Verifier.h"
105#include "llvm/MC/MCAsmInfo.h"
108#include "llvm/Support/CodeGen.h"
109#include "llvm/Support/Debug.h"
110#include "llvm/Support/Error.h"
126#include <cassert>
127#include <utility>
128
129namespace llvm {
130
131// FIXME: Dummy target independent passes definitions that have not yet been
132// ported to new pass manager. Once they do, remove these.
133#define DUMMY_FUNCTION_PASS(NAME, PASS_NAME) \
134 struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
135 template <typename... Ts> PASS_NAME(Ts &&...) {} \
136 PreservedAnalyses run(Function &, FunctionAnalysisManager &) { \
137 return PreservedAnalyses::all(); \
138 } \
139 };
140#define DUMMY_MACHINE_MODULE_PASS(NAME, PASS_NAME) \
141 struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
142 template <typename... Ts> PASS_NAME(Ts &&...) {} \
143 PreservedAnalyses run(Module &, ModuleAnalysisManager &) { \
144 return PreservedAnalyses::all(); \
145 } \
146 };
147#define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME) \
148 struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
149 template <typename... Ts> PASS_NAME(Ts &&...) {} \
150 PreservedAnalyses run(MachineFunction &, \
151 MachineFunctionAnalysisManager &) { \
152 return PreservedAnalyses::all(); \
153 } \
154 };
155#include "llvm/Passes/MachinePassRegistry.def"
156
157class PassManagerWrapper {
158private:
159 PassManagerWrapper(ModulePassManager &ModulePM) : MPM(ModulePM) {};
160
164
165 template <typename DerivedT, typename TargetMachineT>
166 friend class CodeGenPassBuilder;
167};
168
169/// This class provides access to building LLVM's passes.
170///
171/// Its members provide the baseline state available to passes during their
172/// construction. The \c MachinePassRegistry.def file specifies how to construct
173/// all of the built-in passes, and those may reference these members during
174/// construction.
175template <typename DerivedT, typename TargetMachineT> class CodeGenPassBuilder {
176public:
177 explicit CodeGenPassBuilder(TargetMachineT &TM,
178 const CGPassBuilderOption &Opts,
180 : TM(TM), Opt(Opts), PIC(PIC) {
181 // Target could set CGPassBuilderOption::MISchedPostRA to true to achieve
182 // substitutePass(&PostRASchedulerID, &PostMachineSchedulerID)
183
184 // Target should override TM.Options.EnableIPRA in their target-specific
185 // LLVMTM ctor. See TargetMachine::setGlobalISel for example.
186 if (Opt.EnableIPRA) {
187 TM.Options.EnableIPRA = *Opt.EnableIPRA;
188 } else {
189 // If not explicitly specified, use target default.
190 TM.Options.EnableIPRA |= TM.useIPRA();
191 }
192
193 if (Opt.EnableGlobalISelAbort)
194 TM.Options.GlobalISelAbort = *Opt.EnableGlobalISelAbort;
195
196 if (!Opt.OptimizeRegAlloc)
197 Opt.OptimizeRegAlloc = getOptLevel() != CodeGenOptLevel::None;
198 }
199
202 CodeGenFileType FileType, MCContext &Ctx) const;
203
207
208protected:
209 template <typename PassT>
210 using is_module_pass_t = decltype(std::declval<PassT &>().run(
211 std::declval<Module &>(), std::declval<ModuleAnalysisManager &>()));
212
213 template <typename PassT>
214 using is_function_pass_t = decltype(std::declval<PassT &>().run(
215 std::declval<Function &>(), std::declval<FunctionAnalysisManager &>()));
216
217 template <typename PassT>
218 using is_machine_function_pass_t = decltype(std::declval<PassT &>().run(
219 std::declval<MachineFunction &>(),
220 std::declval<MachineFunctionAnalysisManager &>()));
221
222 template <typename PassT>
224 bool Force = false,
225 StringRef Name = PassT::name()) const {
227 "Only function passes are supported.");
228 if (!Force && !runBeforeAdding(Name))
229 return;
230 PMW.FPM.addPass(std::forward<PassT>(Pass));
231 }
232
233 template <typename PassT>
234 void addModulePass(PassT &&Pass, PassManagerWrapper &PMW, bool Force = false,
235 StringRef Name = PassT::name()) const {
237 "Only module passes are suported.");
238 assert(PMW.FPM.isEmpty() && PMW.MFPM.isEmpty() &&
239 "You cannot insert a module pass without first flushing the current "
240 "function pipelines to the module pipeline.");
241 if (!Force && !runBeforeAdding(Name))
242 return;
243 PMW.MPM.addPass(std::forward<PassT>(Pass));
244 }
245
246 template <typename PassT>
248 bool Force = false,
249 StringRef Name = PassT::name()) const {
251 "Only machine function passes are supported.");
252
253 if (!Force && !runBeforeAdding(Name))
254 return;
255 PMW.MFPM.addPass(std::forward<PassT>(Pass));
256 for (auto &C : AfterCallbacks)
257 C(Name, PMW.MFPM);
258 }
259
261 bool FreeMachineFunctions = false) const {
262 if (PMW.FPM.isEmpty() && PMW.MFPM.isEmpty())
263 return;
264 if (!PMW.MFPM.isEmpty()) {
265 PMW.FPM.addPass(
266 createFunctionToMachineFunctionPassAdaptor(std::move(PMW.MFPM)));
267 PMW.MFPM = MachineFunctionPassManager();
268 }
269 if (FreeMachineFunctions)
271 if (AddInCGSCCOrder) {
273 createCGSCCToFunctionPassAdaptor(std::move(PMW.FPM))));
274 } else {
275 PMW.MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PMW.FPM)));
276 }
277 PMW.FPM = FunctionPassManager();
278 }
279
281 assert(!AddInCGSCCOrder);
282 assert(PMW.FPM.isEmpty() && PMW.MFPM.isEmpty() &&
283 "Requiring CGSCC ordering requires flushing the current function "
284 "pipelines to the MPM.");
285 AddInCGSCCOrder = true;
286 }
287
289 assert(AddInCGSCCOrder);
290 assert(PMW.FPM.isEmpty() && PMW.MFPM.isEmpty() &&
291 "Stopping CGSCC ordering requires flushing the current function "
292 "pipelines to the MPM.");
293 AddInCGSCCOrder = false;
294 }
295
296 TargetMachineT &TM;
299
300 template <typename TMC> TMC &getTM() const { return static_cast<TMC &>(TM); }
301 CodeGenOptLevel getOptLevel() const { return TM.getOptLevel(); }
302
303 /// Check whether or not GlobalISel should abort on error.
304 /// When this is disabled, GlobalISel will fall back on SDISel instead of
305 /// erroring out.
307 return TM.Options.GlobalISelAbort == GlobalISelAbortMode::Enable;
308 }
309
310 /// Check whether or not a diagnostic should be emitted when GlobalISel
311 /// uses the fallback path. In other words, it will emit a diagnostic
312 /// when GlobalISel failed and isGlobalISelAbortEnabled is false.
314 return TM.Options.GlobalISelAbort == GlobalISelAbortMode::DisableWithDiag;
315 }
316
317 /// addInstSelector - This method should install an instruction selector pass,
318 /// which converts from LLVM code to machine instructions.
320 return make_error<StringError>("addInstSelector is not overridden",
322 }
323
324 /// Target can override this to add GlobalMergePass before all IR passes.
326
327 /// Add passes that optimize instruction level parallelism for out-of-order
328 /// targets. These passes are run while the machine code is still in SSA
329 /// form, so they can use MachineTraceMetrics to control their heuristics.
330 ///
331 /// All passes added here should preserve the MachineDominatorTree,
332 /// MachineLoopInfo, and MachineTraceMetrics analyses.
333 void addILPOpts(PassManagerWrapper &PMW) const {}
334
335 /// This method may be implemented by targets that want to run passes
336 /// immediately before register allocation.
338
339 /// addPreRewrite - Add passes to the optimized register allocation pipeline
340 /// after register allocation is complete, but before virtual registers are
341 /// rewritten to physical registers.
342 ///
343 /// These passes must preserve VirtRegMap and LiveIntervals, and when running
344 /// after RABasic or RAGreedy, they should take advantage of LiveRegMatrix.
345 /// When these passes run, VirtRegMap contains legal physreg assignments for
346 /// all virtual registers.
347 ///
348 /// Note if the target overloads addRegAssignAndRewriteOptimized, this may not
349 /// be honored. This is also not generally used for the fast variant,
350 /// where the allocation and rewriting are done in one pass.
352
353 /// Add passes to be run immediately after virtual registers are rewritten
354 /// to physical registers.
356
357 /// This method may be implemented by targets that want to run passes after
358 /// register allocation pass pipeline but before prolog-epilog insertion.
360
361 /// This method may be implemented by targets that want to run passes after
362 /// prolog-epilog insertion and before the second instruction scheduling pass.
364
365 /// This pass may be implemented by targets that want to run passes
366 /// immediately before machine code is emitted.
368
369 /// Targets may add passes immediately before machine code is emitted in this
370 /// callback. This is called even later than `addPreEmitPass`.
371 // FIXME: Rename `addPreEmitPass` to something more sensible given its actual
372 // position and remove the `2` suffix here as this callback is what
373 // `addPreEmitPass` *should* be but in reality isn't.
375
376 /// {{@ For GlobalISel
377 ///
378
379 /// addPreISel - This method should add any "last minute" LLVM->LLVM
380 /// passes (which are run just before instruction selector).
382 llvm_unreachable("addPreISel is not overridden");
383 }
384
385 /// This method should install an IR translator pass, which converts from
386 /// LLVM code to machine instructions with possibly generic opcodes.
388 return make_error<StringError>("addIRTranslator is not overridden",
390 }
391
392 /// This method may be implemented by targets that want to run passes
393 /// immediately before legalization.
395
396 /// This method should install a legalize pass, which converts the instruction
397 /// sequence into one that can be selected by the target.
399 return make_error<StringError>("addLegalizeMachineIR is not overridden",
401 }
402
403 /// This method may be implemented by targets that want to run passes
404 /// immediately before the register bank selection.
406
407 /// This method should install a register bank selector pass, which
408 /// assigns register banks to virtual registers without a register
409 /// class or register banks.
411 return make_error<StringError>("addRegBankSelect is not overridden",
413 }
414
415 /// This method may be implemented by targets that want to run passes
416 /// immediately before the (global) instruction selection.
418
419 /// This method should install a (global) instruction selector pass, which
420 /// converts possibly generic instructions to fully target-specific
421 /// instructions, thereby constraining all generic virtual registers to
422 /// register classes.
425 "addGlobalInstructionSelect is not overridden",
427 }
428 /// @}}
429
430 /// High level function that adds all passes necessary to go from llvm IR
431 /// representation to the MI representation.
432 /// Adds IR based lowering and target specific optimization passes and finally
433 /// the core instruction selection passes.
435
436 /// Add the actual instruction selection passes. This does not include
437 /// preparation passes on IR.
439
440 /// Add the complete, standard set of LLVM CodeGen passes.
441 /// Fully developed targets will not generally override this.
443
444 /// Add passes to lower exception handling for the code generator.
446
447 /// Add common target configurable passes that perform LLVM IR to IR
448 /// transforms following machine independent optimization.
450
451 /// Add pass to prepare the LLVM IR for code generation. This should be done
452 /// before exception handling preparation passes.
454
455 /// Add common passes that perform LLVM IR to IR transforms in preparation for
456 /// instruction selection.
458
459 /// Methods with trivial inline returns are convenient points in the common
460 /// codegen pass pipeline where targets may insert passes. Methods with
461 /// out-of-line standard implementations are major CodeGen stages called by
462 /// addMachinePasses. Some targets may override major stages when inserting
463 /// passes is insufficient, but maintaining overriden stages is more work.
464 ///
465
466 /// addMachineSSAOptimization - Add standard passes that optimize machine
467 /// instructions in SSA form.
469
470 /// addFastRegAlloc - Add the minimum set of target-independent passes that
471 /// are required for fast register allocation.
473
474 /// addOptimizedRegAlloc - Add passes related to register allocation.
475 /// CodeGenTargetMachineImpl provides standard regalloc passes for most
476 /// targets.
478
479 /// Add passes that optimize machine instructions after register allocation.
481
482 /// addGCPasses - Add late codegen passes that analyze code for garbage
483 /// collection. This should return true if GC info should be printed after
484 /// these passes.
485 void addGCPasses(PassManagerWrapper &PMW) const {}
486
487 /// Add standard basic block placement passes.
489
491
493 llvm_unreachable("addAsmPrinterBegin is not overriden");
494 }
495
497 llvm_unreachable("addAsmPrinter is not overridden");
498 }
499
501 llvm_unreachable("addAsmPrinterEnd is not overriden");
502 }
503
504 /// Utilities for targets to add passes to the pass manager.
505 ///
506
507 /// createTargetRegisterAllocator - Create the register allocator pass for
508 /// this target at the current optimization level.
510 bool Optimized) const;
511
512 /// addMachinePasses helper to create the target-selected or overriden
513 /// regalloc pass.
514 void addRegAllocPass(PassManagerWrapper &PMW, bool Optimized) const;
515
516 /// Add core register allocator passes which do the actual register assignment
517 /// and rewriting.
520
521 /// Allow the target to disable a specific pass by default.
522 /// Backend can declare unwanted passes in constructor.
523 template <typename... PassTs> void disablePass() {
524 BeforeCallbacks.emplace_back(
525 [](StringRef Name) { return ((Name != PassTs::name()) && ...); });
526 }
527
528 /// Insert InsertedPass pass after TargetPass pass.
529 /// Only machine function passes are supported.
530 template <typename TargetPassT, typename InsertedPassT>
531 void insertPass(InsertedPassT &&Pass) const {
532 AfterCallbacks.emplace_back(
533 [&](StringRef Name, MachineFunctionPassManager &MFPM) mutable {
534 if (Name == TargetPassT::name() &&
535 runBeforeAdding(InsertedPassT::name())) {
536 MFPM.addPass(std::forward<InsertedPassT>(Pass));
537 }
538 });
539 }
540
541private:
542 DerivedT &derived() { return static_cast<DerivedT &>(*this); }
543 const DerivedT &derived() const {
544 return static_cast<const DerivedT &>(*this);
545 }
546
547 bool runBeforeAdding(StringRef Name) const {
548 bool ShouldAdd = true;
549 for (auto &C : BeforeCallbacks)
550 ShouldAdd &= C(Name);
551 return ShouldAdd;
552 }
553
554 void setStartStopPasses(const TargetPassConfig::StartStopInfo &Info) const;
555
556 Error verifyStartStop(const TargetPassConfig::StartStopInfo &Info) const;
557
558 mutable SmallVector<llvm::unique_function<bool(StringRef)>, 4>
559 BeforeCallbacks;
560 mutable SmallVector<
561 llvm::unique_function<void(StringRef, MachineFunctionPassManager &)>, 4>
562 AfterCallbacks;
563
564 /// Helper variable for `-start-before/-start-after/-stop-before/-stop-after`
565 mutable bool Started = true;
566 mutable bool Stopped = true;
567 mutable bool AddInCGSCCOrder = false;
568};
569
570template <typename Derived, typename TargetMachineT>
573 raw_pwrite_stream *DwoOut, CodeGenFileType FileType, MCContext &Ctx) const {
574 auto StartStopInfo = TargetPassConfig::getStartStopInfo(*PIC);
575 if (!StartStopInfo)
576 return StartStopInfo.takeError();
577 setStartStopPasses(*StartStopInfo);
578
580 bool PrintMIR = !PrintAsm && FileType != CodeGenFileType::Null;
581
582 PassManagerWrapper PMW(MPM);
583
585 /*Force=*/true);
587 /*Force=*/true);
589 /*Force=*/true);
591 /*Force=*/true);
593 PMW,
594 /*Force=*/true);
595 addISelPasses(PMW);
596 flushFPMsToMPM(PMW);
597
598 if (PrintAsm) {
599 Expected<std::unique_ptr<MCStreamer>> MCStreamerOrErr =
600 TM.createMCStreamer(Out, DwoOut, FileType, Ctx);
601 if (!MCStreamerOrErr)
602 return MCStreamerOrErr.takeError();
603 std::unique_ptr<AsmPrinter> Printer(
604 TM.getTarget().createAsmPrinter(TM, std::move(*MCStreamerOrErr)));
605 if (!Printer)
606 return createStringError("failed to create AsmPrinter");
607 MAM.registerPass([&] { return AsmPrinterAnalysis(std::move(Printer)); });
608 derived().addAsmPrinterBegin(PMW);
609 }
610
611 if (PrintMIR)
612 addModulePass(PrintMIRPreparePass(Out), PMW, /*Force=*/true);
613
614 if (auto Err = addCoreISelPasses(PMW))
615 return std::move(Err);
616
617 if (auto Err = derived().addMachinePasses(PMW))
618 return std::move(Err);
619
620 if (!Opt.DisableVerify)
622
623 if (PrintAsm) {
624 derived().addAsmPrinter(PMW);
625 flushFPMsToMPM(PMW, /*FreeMachineFunctions=*/true);
626 derived().addAsmPrinterEnd(PMW);
627 } else {
628 if (PrintMIR)
629 addMachineFunctionPass(PrintMIRPass(Out), PMW, /*Force=*/true);
630 flushFPMsToMPM(PMW, /*FreeMachineFunctions=*/true);
631 }
632
633 return verifyStartStop(*StartStopInfo);
634}
635
636template <typename Derived, typename TargetMachineT>
637void CodeGenPassBuilder<Derived, TargetMachineT>::setStartStopPasses(
638 const TargetPassConfig::StartStopInfo &Info) const {
639 if (!Info.StartPass.empty()) {
640 Started = false;
641 BeforeCallbacks.emplace_back([this, &Info, AfterFlag = Info.StartAfter,
642 Count = 0u](StringRef ClassName) mutable {
643 if (Count == Info.StartInstanceNum) {
644 if (AfterFlag) {
645 AfterFlag = false;
646 Started = true;
647 }
648 return Started;
649 }
650
651 auto PassName = PIC->getPassNameForClassName(ClassName);
652 if (Info.StartPass == PassName && ++Count == Info.StartInstanceNum)
653 Started = !Info.StartAfter;
654
655 return Started;
656 });
657 }
658
659 if (!Info.StopPass.empty()) {
660 Stopped = false;
661 BeforeCallbacks.emplace_back([this, &Info, AfterFlag = Info.StopAfter,
662 Count = 0u](StringRef ClassName) mutable {
663 if (Count == Info.StopInstanceNum) {
664 if (AfterFlag) {
665 AfterFlag = false;
666 Stopped = true;
667 }
668 return !Stopped;
669 }
670
671 auto PassName = PIC->getPassNameForClassName(ClassName);
672 if (Info.StopPass == PassName && ++Count == Info.StopInstanceNum)
673 Stopped = !Info.StopAfter;
674 return !Stopped;
675 });
676 }
677}
678
679template <typename Derived, typename TargetMachineT>
680Error CodeGenPassBuilder<Derived, TargetMachineT>::verifyStartStop(
681 const TargetPassConfig::StartStopInfo &Info) const {
682 if (Started && Stopped)
683 return Error::success();
684
685 if (!Started)
687 "Can't find start pass \"" + Info.StartPass + "\".",
688 std::make_error_code(std::errc::invalid_argument));
689 if (!Stopped)
691 "Can't find stop pass \"" + Info.StopPass + "\".",
692 std::make_error_code(std::errc::invalid_argument));
693 return Error::success();
694}
695
696template <typename Derived, typename TargetMachineT>
698 PassManagerWrapper &PMW) const {
699 derived().addGlobalMergePass(PMW);
700 if (TM.useEmulatedTLS())
702
703 // ObjCARCContract operates on ObjC intrinsics and must run before
704 // PreISelIntrinsicLowering.
707 flushFPMsToMPM(PMW);
708 }
711
712 derived().addIRPasses(PMW);
713 derived().addCodeGenPrepare(PMW);
715 derived().addISelPrepare(PMW);
716}
717
718/// Add common target configurable passes that perform LLVM IR to IR transforms
719/// following machine independent optimization.
720template <typename Derived, typename TargetMachineT>
722 PassManagerWrapper &PMW) const {
723 // Before running any passes, run the verifier to determine if the input
724 // coming from the front-end and/or optimizer is valid.
725 if (!Opt.DisableVerify)
726 addFunctionPass(VerifierPass(), PMW, /*Force=*/true);
727
728 // Run loop strength reduction before anything else.
729 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableLSR) {
730 // These passes do not use MSSA.
731 LoopPassManager LPM;
732 LPM.addPass(CanonicalizeFreezeInLoopsPass());
733 LPM.addPass(LoopStrengthReducePass());
734 if (Opt.EnableLoopTermFold)
735 LPM.addPass(LoopTermFoldPass());
737 /*UseMemorySSA=*/false),
738 PMW);
739 }
740
741 // Run GC lowering passes for builtin collectors
742 // TODO: add a pass insertion point here
744 // Explicitly check to see if we should add ShadowStackGCLowering to avoid
745 // splitting the function pipeline if we do not have to.
746 if (runBeforeAdding(ShadowStackGCLoweringPass::name())) {
747 flushFPMsToMPM(PMW);
749 }
750
751 // Make sure that no unreachable blocks are instruction selected.
753
754 // Prepare expensive constants for SelectionDAG.
755 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableConstantHoisting)
757
758 // Replace calls to LLVM intrinsics (e.g., exp, log) operating on vector
759 // operands with calls to the corresponding functions in a vector library.
762
764 !Opt.DisablePartialLibcallInlining)
766
767 // Instrument function entry and exit, e.g. with calls to mcount().
768 addFunctionPass(EntryExitInstrumenterPass(/*PostInlining=*/true), PMW);
769
770 // Add scalarization of target's unsupported masked memory intrinsics pass.
771 // the unsupported intrinsic will be replaced with a chain of basic blocks,
772 // that stores/loads element one-by-one if the appropriate mask bit is set.
774
775 // Expand reduction intrinsics into shuffle sequences if the target wants to.
776 if (!Opt.DisableExpandReductions)
778
779 // Convert conditional moves to conditional jumps when profitable.
780 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableSelectOptimize)
782
783 if (Opt.EnableGlobalMergeFunc) {
784 flushFPMsToMPM(PMW);
786 }
787}
788
789/// Turn exception handling constructs into something the code generators can
790/// handle.
791template <typename Derived, typename TargetMachineT>
793 PassManagerWrapper &PMW) const {
794 const MCAsmInfo *MCAI = TM.getMCAsmInfo();
795 assert(MCAI && "No MCAsmInfo");
796 switch (MCAI->getExceptionHandlingType()) {
798 // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
799 // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
800 // catch info can get misplaced when a selector ends up more than one block
801 // removed from the parent invoke(s). This could happen when a landing
802 // pad is shared by multiple invokes and is also a target of a normal
803 // edge from elsewhere.
805 [[fallthrough]];
811 break;
813 // We support using both GCC-style and MSVC-style exceptions on Windows, so
814 // add both preparation passes. Each pass will only actually run if it
815 // recognizes the personality function.
818 break;
820 // Wasm EH uses Windows EH instructions, but it does not need to demote PHIs
821 // on catchpads and cleanuppads because it does not outline them into
822 // funclets. Catchswitch blocks are not lowered in SelectionDAG, so we
823 // should remove PHIs there.
824 addFunctionPass(WinEHPreparePass(/*DemoteCatchSwitchPHIOnly=*/false), PMW);
826 break;
829
830 // The lower invoke pass may create unreachable code. Remove it.
832 break;
833 }
834}
835
836/// Add pass to prepare the LLVM IR for code generation. This should be done
837/// before exception handling preparation passes.
838template <typename Derived, typename TargetMachineT>
840 PassManagerWrapper &PMW) const {
841 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableCGP)
843 // TODO: Default ctor'd RewriteSymbolPass is no-op.
844 // addPass(RewriteSymbolPass());
845}
846
847/// Add common passes that perform LLVM IR to IR transforms in preparation for
848/// instruction selection.
849template <typename Derived, typename TargetMachineT>
851 PassManagerWrapper &PMW) const {
852 derived().addPreISel(PMW);
853
854 if (Opt.RequiresCodeGenSCCOrder && !AddInCGSCCOrder)
856
858 // Add both the safe stack and the stack protection passes: each of them will
859 // only protect functions that have corresponding attributes.
862
863 if (Opt.PrintISelInput)
865 dbgs(), "\n\n*** Final LLVM Code input to ISel ***\n"),
866 PMW);
867
868 // All passes which modify the LLVM IR are now complete; run the verifier
869 // to ensure that the IR is valid.
870 if (!Opt.DisableVerify)
871 addFunctionPass(VerifierPass(), PMW, /*Force=*/true);
872}
873
874template <typename Derived, typename TargetMachineT>
876 PassManagerWrapper &PMW) const {
877 // Enable FastISel with -fast-isel, but allow that to be overridden.
878 TM.setO0WantsFastISel(Opt.EnableFastISelOption.value_or(true));
879
880 // Determine an instruction selector.
881 enum class SelectorType { SelectionDAG, FastISel, GlobalISel };
882 SelectorType Selector;
883
884 if (Opt.EnableFastISelOption && *Opt.EnableFastISelOption == true)
885 Selector = SelectorType::FastISel;
886 else if ((Opt.EnableGlobalISelOption &&
887 *Opt.EnableGlobalISelOption == true) ||
888 (TM.Options.EnableGlobalISel &&
889 (!Opt.EnableGlobalISelOption ||
890 *Opt.EnableGlobalISelOption == false)))
891 Selector = SelectorType::GlobalISel;
892 else if (TM.getOptLevel() == CodeGenOptLevel::None && TM.getO0WantsFastISel())
893 Selector = SelectorType::FastISel;
894 else
895 Selector = SelectorType::SelectionDAG;
896
897 // Set consistently TM.Options.EnableFastISel and EnableGlobalISel.
898 if (Selector == SelectorType::FastISel) {
899 TM.setFastISel(true);
900 TM.setGlobalISel(false);
901 } else if (Selector == SelectorType::GlobalISel) {
902 TM.setFastISel(false);
903 TM.setGlobalISel(true);
904 }
905
906 // Add instruction selector passes.
907 if (Selector == SelectorType::GlobalISel) {
908 if (auto Err = derived().addIRTranslator(PMW))
909 return std::move(Err);
910
911 derived().addPreLegalizeMachineIR(PMW);
912
913 if (auto Err = derived().addLegalizeMachineIR(PMW))
914 return std::move(Err);
915
916 // Before running the register bank selector, ask the target if it
917 // wants to run some passes.
918 derived().addPreRegBankSelect(PMW);
919
920 if (auto Err = derived().addRegBankSelect(PMW))
921 return std::move(Err);
922
923 derived().addPreGlobalInstructionSelect(PMW);
924
925 if (auto Err = derived().addGlobalInstructionSelect(PMW))
926 return std::move(Err);
927
928 // Pass to reset the MachineFunction if the ISel failed.
930 ResetMachineFunctionPass(reportDiagnosticWhenGlobalISelFallback(),
932 PMW);
933
934 // Provide a fallback path when we do not want to abort on
935 // not-yet-supported input.
937 if (auto Err = derived().addInstSelector(PMW))
938 return std::move(Err);
939
940 } else if (auto Err = derived().addInstSelector(PMW))
941 return std::move(Err);
942
943 // Expand pseudo-instructions emitted by ISel. Don't run the verifier before
944 // FinalizeISel.
946
947 // // Print the instruction selected machine code...
948 // printAndVerify("After Instruction Selection");
949
950 return Error::success();
951}
952
953/// Add the complete set of target-independent postISel code generator passes.
954///
955/// This can be read as the standard order of major LLVM CodeGen stages. Stages
956/// with nontrivial configuration or multiple passes are broken out below in
957/// add%Stage routines.
958///
959/// Any CodeGenPassBuilder<Derived, TargetMachine>::addXX routine may be
960/// overriden by the Target. The addPre/Post methods with empty header
961/// implementations allow injecting target-specific fixups just before or after
962/// major stages. Additionally, targets have the flexibility to change pass
963/// order within a stage by overriding default implementation of add%Stage
964/// routines below. Each technique has maintainability tradeoffs because
965/// alternate pass orders are not well supported. addPre/Post works better if
966/// the target pass is easily tied to a common pass. But if it has subtle
967/// dependencies on multiple passes, the target should override the stage
968/// instead.
969template <typename Derived, typename TargetMachineT>
971 PassManagerWrapper &PMW) const {
972 // Add passes that optimize machine instructions in SSA form.
974 derived().addMachineSSAOptimization(PMW);
975 } else {
976 // If the target requests it, assign local variables to stack slots relative
977 // to one another and simplify frame index references where possible.
979 }
980
981 if (TM.Options.EnableIPRA) {
982 flushFPMsToMPM(PMW);
984 PMW, /*Force=*/true);
986 }
987 // Run pre-ra passes.
988 derived().addPreRegAlloc(PMW);
989
990 // Run register allocation and passes that are tightly coupled with it,
991 // including phi elimination and scheduling.
992 if (auto Err = *Opt.OptimizeRegAlloc ? derived().addOptimizedRegAlloc(PMW)
993 : derived().addFastRegAlloc(PMW))
994 return std::move(Err);
995
996 // Run post-ra passes.
997 derived().addPostRegAlloc(PMW);
998
1001
1002 // Insert prolog/epilog code. Eliminate abstract frame index references...
1006 }
1007
1009
1010 /// Add passes that optimize machine instructions after register allocation.
1012 derived().addMachineLateOptimization(PMW);
1013
1014 // Expand pseudo instructions before second scheduling pass.
1016
1017 // Run pre-sched2 passes.
1018 derived().addPreSched2(PMW);
1019
1020 if (Opt.EnableImplicitNullChecks)
1021 addMachineFunctionPass(ImplicitNullChecksPass(), PMW);
1022
1023 // Second pass scheduler.
1024 // Let Target optionally insert this pass by itself at some other
1025 // point.
1027 !TM.targetSchedulesPostRAScheduling()) {
1028 if (Opt.MISchedPostRA)
1030 else
1032 }
1033
1034 // GC
1035 derived().addGCPasses(PMW);
1036
1037 // Basic block placement.
1039 derived().addBlockPlacement(PMW);
1040
1041 // Insert before XRay Instrumentation.
1043
1046
1047 derived().addPreEmitPass(PMW);
1048
1049 if (TM.Options.EnableIPRA) {
1050 // Collect register usage information and produce a register mask of
1051 // clobbered registers, to be used to optimize call sites.
1053 // If -print-regusage is specified, print the collected register usage info.
1054 if (Opt.PrintRegUsage) {
1055 flushFPMsToMPM(PMW);
1057 }
1058 }
1059
1060 addMachineFunctionPass(FuncletLayoutPass(), PMW);
1061
1063 addMachineFunctionPass(StackMapLivenessPass(), PMW);
1066 getTM<TargetMachine>().Options.ShouldEmitDebugEntryValues()),
1067 PMW);
1069
1070 if (TM.Options.EnableMachineOutliner &&
1072 Opt.EnableMachineOutliner != RunOutliner::NeverOutline) {
1073 if (Opt.EnableMachineOutliner != RunOutliner::TargetDefault ||
1074 TM.Options.SupportsDefaultOutlining) {
1075 flushFPMsToMPM(PMW);
1076 addModulePass(MachineOutlinerPass(Opt.EnableMachineOutliner), PMW);
1077 }
1078 }
1079
1080 derived().addPostBBSections(PMW);
1081
1083
1084 // Add passes that directly emit MI after all other MI passes.
1085 derived().addPreEmitPass2(PMW);
1086
1087 return Error::success();
1088}
1089
1090/// Add passes that optimize machine instructions in SSA form.
1091template <typename Derived, typename TargetMachineT>
1093 PassManagerWrapper &PMW) const {
1094 // Pre-ra tail duplication.
1096
1097 // Optimize PHIs before DCE: removing dead PHI cycles may make more
1098 // instructions dead.
1100
1101 // This pass merges large allocas. StackSlotColoring is a different pass
1102 // which merges spill slots.
1104
1105 // If the target requests it, assign local variables to stack slots relative
1106 // to one another and simplify frame index references where possible.
1108
1109 // With optimization, dead code should already be eliminated. However
1110 // there is one known exception: lowered code for arguments that are only
1111 // used by tail calls, where the tail calls reuse the incoming stack
1112 // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
1114
1115 // Allow targets to insert passes that improve instruction level parallelism,
1116 // like if-conversion. Such passes will typically need dominator trees and
1117 // loop info, just like LICM and CSE below.
1118 derived().addILPOpts(PMW);
1119
1122
1123 addMachineFunctionPass(MachineSinkingPass(Opt.EnableSinkAndFold), PMW);
1124
1126 // Clean-up the dead code that may have been generated by peephole
1127 // rewriting.
1129}
1130
1131//===---------------------------------------------------------------------===//
1132/// Register Allocation Pass Configuration
1133//===---------------------------------------------------------------------===//
1134
1135/// Instantiate the default register allocator pass for this target for either
1136/// the optimized or unoptimized allocation path. This will be added to the pass
1137/// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
1138/// in the optimized case.
1139///
1140/// A target that uses the standard regalloc pass order for fast or optimized
1141/// allocation may still override this for per-target regalloc
1142/// selection. But -regalloc-npm=... always takes precedence.
1143/// If a target does not want to allow users to set -regalloc-npm=... at all,
1144/// check if Opt.RegAlloc == RegAllocType::Unset.
1145template <typename Derived, typename TargetMachineT>
1147 PassManagerWrapper &PMW, bool Optimized) const {
1148 if (Optimized)
1150 else
1152}
1153
1154/// Find and instantiate the register allocation pass requested by this target
1155/// at the current optimization level. Different register allocators are
1156/// defined as separate passes because they may require different analysis.
1157///
1158/// This helper ensures that the -regalloc-npm= option is always available,
1159/// even for targets that override the default allocator.
1160template <typename Derived, typename TargetMachineT>
1162 PassManagerWrapper &PMW, bool Optimized) const {
1163 // Use the specified -regalloc-npm={basic|greedy|fast|pbqp}
1164 if (Opt.RegAlloc > RegAllocType::Default) {
1165 switch (Opt.RegAlloc) {
1166 case RegAllocType::Fast:
1168 break;
1171 break;
1172 default:
1173 reportFatalUsageError("register allocator not supported yet");
1174 }
1175 return;
1176 }
1177 // -regalloc=default or unspecified, so pick based on the optimization level
1178 // or ask the target for the regalloc pass.
1179 derived().addTargetRegisterAllocator(PMW, Optimized);
1180}
1181
1182template <typename Derived, typename TargetMachineT>
1184 PassManagerWrapper &PMW) const {
1185 // TODO: Ensure allocator is default or fast.
1186 addRegAllocPass(PMW, false);
1187 return Error::success();
1188}
1189
1190template <typename Derived, typename TargetMachineT>
1192 PassManagerWrapper &PMW) const {
1193 // Add the selected register allocation pass.
1194 addRegAllocPass(PMW, true);
1195
1196 // Allow targets to change the register assignments before rewriting.
1197 derived().addPreRewrite(PMW);
1198
1199 // Finally rewrite virtual registers.
1201 // Perform stack slot coloring and post-ra machine LICM.
1202 //
1203 // FIXME: Re-enable coloring with register when it's capable of adding
1204 // kill markers.
1206
1207 return Error::success();
1208}
1209
1210/// Add the minimum set of target-independent passes that are required for
1211/// register allocation. No coalescing or scheduling.
1212template <typename Derived, typename TargetMachineT>
1219
1220/// Add standard target-independent passes that are tightly coupled with
1221/// optimized register allocation, including coalescing, machine instruction
1222/// scheduling, and register allocation itself.
1223template <typename Derived, typename TargetMachineT>
1225 PassManagerWrapper &PMW) const {
1227
1229
1231
1232 // LiveVariables currently requires pure SSA form.
1233 //
1234 // FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
1235 // LiveVariables can be removed completely, and LiveIntervals can be directly
1236 // computed. (We still either need to regenerate kill flags after regalloc, or
1237 // preferably fix the scavenger to not depend on them).
1238 // FIXME: UnreachableMachineBlockElim is a dependant pass of LiveVariables.
1239 // When LiveVariables is removed this has to be removed/moved either.
1240 // Explicit addition of UnreachableMachineBlockElim allows stopping before or
1241 // after it with -stop-before/-stop-after.
1245
1246 // Edge splitting is smarter with machine loop info.
1250
1251 // Eventually, we want to run LiveIntervals before PHI elimination.
1252 if (Opt.EarlyLiveIntervals)
1255
1258
1259 // The machine scheduler may accidentally create disconnected components
1260 // when moving subregister definitions around, avoid this by splitting them to
1261 // separate vregs before. Splitting can also improve reg. allocation quality.
1263
1264 // PreRA instruction scheduling.
1266
1267 if (auto E = derived().addRegAssignmentOptimized(PMW))
1268 return std::move(E);
1269
1271
1272 // Allow targets to expand pseudo instructions depending on the choice of
1273 // registers before MachineCopyPropagation.
1274 derived().addPostRewrite(PMW);
1275
1276 // Copy propagate to forward register uses and try to eliminate COPYs that
1277 // were not coalesced.
1279
1280 // Run post-ra machine LICM to hoist reloads / remats.
1281 //
1282 // FIXME: can this move into MachineLateOptimization?
1284
1285 return Error::success();
1286}
1287
1288//===---------------------------------------------------------------------===//
1289/// Post RegAlloc Pass Configuration
1290//===---------------------------------------------------------------------===//
1291
1292/// Add passes that optimize machine instructions after register allocation.
1293template <typename Derived, typename TargetMachineT>
1295 PassManagerWrapper &PMW) const {
1296 // Cleanup of redundant (identical) address/immediate loads.
1298
1299 // Branch folding must be run after regalloc and prolog/epilog insertion.
1300 addMachineFunctionPass(BranchFolderPass(Opt.EnableTailMerge), PMW);
1301
1302 // Tail duplication.
1303 // Note that duplicating tail just increases code size and degrades
1304 // performance for targets that require Structured Control Flow.
1305 // In addition it can also make CFG irreducible. Thus we disable it.
1306 if (!TM.requiresStructuredCFG())
1308
1309 // Copy propagation.
1311}
1312
1313/// Add standard basic block placement passes.
1314template <typename Derived, typename TargetMachineT>
1316 PassManagerWrapper &PMW) const {
1318 // Run a separate pass to collect block placement statistics.
1319 if (Opt.EnableBlockPlacementStats)
1321}
1322
1323} // namespace llvm
1324
1325#endif // LLVM_PASSES_CODEGENPASSBUILDER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This is the interface for LLVM's primary stateless and local alias analysis.
This header provides classes for managing passes over SCCs of the call graph.
Defines an IR pass for CodeGen Prepare.
dxil pretty DXIL Metadata Pretty Printer
Analysis that tracks defined/used subregister lanes across COPY instructions and instructions that ge...
This file defines passes to print out IR in various granularities.
This header defines various interfaces for pass management in LLVM.
This file contains the declaration of the InterleavedAccessPass class, its corresponding pass name is...
static LVOptions Options
Definition LVOptions.cpp:25
This header provides classes for managing a pipeline of passes over loops in LLVM IR.
The header file for the LowerConstantIntrinsics pass as used by the new pass manager.
ModuleAnalysisManager MAM
if(PassOpts->AAPipeline)
PassInstrumentationCallbacks PIC
This pass is required to take advantage of the interprocedural register allocation infrastructure.
This is the interface for a metadata-based scoped no-alias analysis.
This file contains the declaration of the SelectOptimizePass class, its corresponding pass name is se...
This file defines the SmallVector class.
Target-Independent Code Generator Pass Configuration Options pass.
This pass exposes codegen information to IR-level passes.
This is the interface for a metadata-based TBAA.
static const char PassName[]
A pass that canonicalizes freeze instructions in a loop.
void addPostRegAlloc(PassManagerWrapper &PMW) const
This method may be implemented by targets that want to run passes after register allocation pass pipe...
void addGlobalMergePass(PassManagerWrapper &PMW) const
Target can override this to add GlobalMergePass before all IR passes.
Error addOptimizedRegAlloc(PassManagerWrapper &PMW) const
addOptimizedRegAlloc - Add passes related to register allocation.
void addModulePass(PassT &&Pass, PassManagerWrapper &PMW, bool Force=false, StringRef Name=PassT::name()) const
decltype(std::declval< PassT & >().run( std::declval< Function & >(), std::declval< FunctionAnalysisManager & >())) is_function_pass_t
void flushFPMsToMPM(PassManagerWrapper &PMW, bool FreeMachineFunctions=false) const
void addPreGlobalInstructionSelect(PassManagerWrapper &PMW) const
This method may be implemented by targets that want to run passes immediately before the (global) ins...
Error addRegAssignmentFast(PassManagerWrapper &PMW) const
Add core register allocator passes which do the actual register assignment and rewriting.
void requireCGSCCOrder(PassManagerWrapper &PMW) const
void addISelPrepare(PassManagerWrapper &PMW) const
Add common passes that perform LLVM IR to IR transforms in preparation for instruction selection.
void addTargetRegisterAllocator(PassManagerWrapper &PMW, bool Optimized) const
Utilities for targets to add passes to the pass manager.
bool isGlobalISelAbortEnabled() const
Check whether or not GlobalISel should abort on error.
Error addMachinePasses(PassManagerWrapper &PMW) const
Add the complete, standard set of LLVM CodeGen passes.
void insertPass(InsertedPassT &&Pass) const
Insert InsertedPass pass after TargetPass pass.
void addPreRewrite(PassManagerWrapper &PMW) const
addPreRewrite - Add passes to the optimized register allocation pipeline after register allocation is...
Error addFastRegAlloc(PassManagerWrapper &PMW) const
addFastRegAlloc - Add the minimum set of target-independent passes that are required for fast registe...
Error buildPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, MCContext &Ctx) const
Error addRegAssignmentOptimized(PassManagerWrapper &PMW) const
void addPreISel(PassManagerWrapper &PMW) const
{{@ For GlobalISel
Error addCoreISelPasses(PassManagerWrapper &PMW) const
Add the actual instruction selection passes.
void stopAddingInCGSCCOrder(PassManagerWrapper &PMW) const
void addPreLegalizeMachineIR(PassManagerWrapper &PMW) const
This method may be implemented by targets that want to run passes immediately before legalization.
void addCodeGenPrepare(PassManagerWrapper &PMW) const
Add pass to prepare the LLVM IR for code generation.
void addPreEmitPass(PassManagerWrapper &PMW) const
This pass may be implemented by targets that want to run passes immediately before machine code is em...
void addMachineSSAOptimization(PassManagerWrapper &PMW) const
Methods with trivial inline returns are convenient points in the common codegen pass pipeline where t...
void addIRPasses(PassManagerWrapper &PMW) const
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
decltype(std::declval< PassT & >().run( std::declval< MachineFunction & >(), std::declval< MachineFunctionAnalysisManager & >())) is_machine_function_pass_t
void addMachineLateOptimization(PassManagerWrapper &PMW) const
Add passes that optimize machine instructions after register allocation.
Error addLegalizeMachineIR(PassManagerWrapper &PMW) const
This method should install a legalize pass, which converts the instruction sequence into one that can...
CodeGenPassBuilder(TargetMachineT &TM, const CGPassBuilderOption &Opts, PassInstrumentationCallbacks *PIC)
void addPreEmitPass2(PassManagerWrapper &PMW) const
Targets may add passes immediately before machine code is emitted in this callback.
Error addIRTranslator(PassManagerWrapper &PMW) const
This method should install an IR translator pass, which converts from LLVM code to machine instructio...
void addGCPasses(PassManagerWrapper &PMW) const
addGCPasses - Add late codegen passes that analyze code for garbage collection.
void addRegAllocPass(PassManagerWrapper &PMW, bool Optimized) const
addMachinePasses helper to create the target-selected or overriden regalloc pass.
Error addRegBankSelect(PassManagerWrapper &PMW) const
This method should install a register bank selector pass, which assigns register banks to virtual reg...
void addMachineFunctionPass(PassT &&Pass, PassManagerWrapper &PMW, bool Force=false, StringRef Name=PassT::name()) const
void addISelPasses(PassManagerWrapper &PMW) const
High level function that adds all passes necessary to go from llvm IR representation to the MI repres...
void disablePass()
Allow the target to disable a specific pass by default.
Error addInstSelector(PassManagerWrapper &PMW) const
addInstSelector - This method should install an instruction selector pass, which converts from LLVM c...
void addPreRegAlloc(PassManagerWrapper &PMW) const
This method may be implemented by targets that want to run passes immediately before register allocat...
void addPassesToHandleExceptions(PassManagerWrapper &PMW) const
Add passes to lower exception handling for the code generator.
void addBlockPlacement(PassManagerWrapper &PMW) const
Add standard basic block placement passes.
void addAsmPrinterEnd(PassManagerWrapper &PMW) const
void addPreRegBankSelect(PassManagerWrapper &PMW) const
This method may be implemented by targets that want to run passes immediately before the register ban...
void addPreSched2(PassManagerWrapper &PMW) const
This method may be implemented by targets that want to run passes after prolog-epilog insertion and b...
Error addGlobalInstructionSelect(PassManagerWrapper &PMWM) const
This method should install a (global) instruction selector pass, which converts possibly generic inst...
void addAsmPrinterBegin(PassManagerWrapper &PMW) const
void addFunctionPass(PassT &&Pass, PassManagerWrapper &PMW, bool Force=false, StringRef Name=PassT::name()) const
void addILPOpts(PassManagerWrapper &PMW) const
Add passes that optimize instruction level parallelism for out-of-order targets.
decltype(std::declval< PassT & >().run( std::declval< Module & >(), std::declval< ModuleAnalysisManager & >())) is_module_pass_t
void addPostBBSections(PassManagerWrapper &PMW) const
void addPostRewrite(PassManagerWrapper &PMW) const
Add passes to be run immediately after virtual registers are rewritten to physical registers.
void addAsmPrinter(PassManagerWrapper &PMW) const
PassInstrumentationCallbacks * getPassInstrumentationCallbacks() const
bool reportDiagnosticWhenGlobalISelFallback() const
Check whether or not a diagnostic should be emitted when GlobalISel uses the fallback path.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
Error takeError()
Take ownership of the stored error.
Definition Error.h:612
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
Definition FastISel.h:66
LowerIntrinsics - This pass rewrites calls to the llvm.gcread or llvm.gcwrite intrinsics,...
Definition GCMetadata.h:229
Performs Loop Strength Reduce Pass.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:64
ExceptionHandling getExceptionHandlingType() const
Definition MCAsmInfo.h:646
Context object for machine code objects.
Definition MCContext.h:83
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
LLVM_ABI StringRef getPassNameForClassName(StringRef ClassName)
Get the pass name for a given pass class name. Empty if no match found.
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
bool isEmpty() const
Returns if the pass manager contains any passes.
Pass interface - Implemented by all 'passes'.
Definition Pass.h:99
Pass (for the new pass manager) for printing a Function as LLVM's text IR assembly.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
static Expected< StartStopInfo > getStartStopInfo(PassInstrumentationCallbacks &PIC)
Returns pass name in -stop-before or -stop-after NOTE: New pass manager migration only.
static bool willCompleteCodeGenPipeline()
Returns true if none of the -stop-before and -stop-after options is set.
Create a verifier pass.
Definition Verifier.h:134
An abstract base class for streams implementations that also support a pwrite operation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
ModuleToFunctionPassAdaptor createModuleToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:94
@ SjLj
setjmp/longjmp based exceptions
Definition CodeGen.h:56
@ ZOS
z/OS MVS Exception Handling.
Definition CodeGen.h:61
@ None
No exception support.
Definition CodeGen.h:54
@ AIX
AIX Exception Handling.
Definition CodeGen.h:60
@ DwarfCFI
DWARF-like instruction based exceptions.
Definition CodeGen.h:55
@ WinEH
Windows Exception Handling.
Definition CodeGen.h:58
@ Wasm
WebAssembly Exception Handling.
Definition CodeGen.h:59
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1328
PassManager< Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, LPMUpdater & > LoopPassManager
The Loop pass manager.
ModuleToPostOrderCGSCCPassAdaptor createModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT &&Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
FunctionToLoopPassAdaptor createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
CGSCCToFunctionPassAdaptor createCGSCCToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false, bool NoRerun=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition CodeGen.h:111
FunctionToMachineFunctionPassAdaptor createFunctionToMachineFunctionPassAdaptor(MachineFunctionPassT &&Pass)
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
PassManager< Function > FunctionPassManager
Convenience typedef for a pass manager over functions.
typename detail::detector< void, Op, Args... >::value_t is_detected
Detects if a given trait holds for some set of arguments 'Args'.
PassManager< MachineFunction > MachineFunctionPassManager
Convenience typedef for a pass manager over functions.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
Global function merging pass for new pass manager.
A utility pass template to force an analysis result to be available.