LLVM 24.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"
66#include "llvm/CodeGen/PEI.h"
103#include "llvm/IR/PassManager.h"
104#include "llvm/IR/Verifier.h"
106#include "llvm/MC/MCAsmInfo.h"
109#include "llvm/Support/CodeGen.h"
110#include "llvm/Support/Debug.h"
111#include "llvm/Support/Error.h"
127#include <cassert>
128#include <utility>
129
130namespace llvm {
131
132// FIXME: Dummy target independent passes definitions that have not yet been
133// ported to new pass manager. Once they do, remove these.
134#define DUMMY_FUNCTION_PASS(NAME, PASS_NAME) \
135 struct PASS_NAME : public OptionalPassInfoMixin<PASS_NAME> { \
136 template <typename... Ts> PASS_NAME(Ts &&...) {} \
137 PreservedAnalyses run(Function &, FunctionAnalysisManager &) { \
138 return PreservedAnalyses::all(); \
139 } \
140 };
141#define DUMMY_MACHINE_MODULE_PASS(NAME, PASS_NAME) \
142 struct PASS_NAME : public OptionalPassInfoMixin<PASS_NAME> { \
143 template <typename... Ts> PASS_NAME(Ts &&...) {} \
144 PreservedAnalyses run(Module &, ModuleAnalysisManager &) { \
145 return PreservedAnalyses::all(); \
146 } \
147 };
148#define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME) \
149 struct PASS_NAME : public OptionalPassInfoMixin<PASS_NAME> { \
150 template <typename... Ts> PASS_NAME(Ts &&...) {} \
151 PreservedAnalyses run(MachineFunction &, \
152 MachineFunctionAnalysisManager &) { \
153 return PreservedAnalyses::all(); \
154 } \
155 };
156#include "llvm/Passes/MachinePassRegistry.def"
157
158class PassManagerWrapper {
159private:
160 PassManagerWrapper(ModulePassManager &ModulePM) : MPM(ModulePM) {};
161
165
166 template <typename DerivedT, typename TargetMachineT>
167 friend class CodeGenPassBuilder;
168};
169
170/// This class provides access to building LLVM's passes.
171///
172/// Its members provide the baseline state available to passes during their
173/// construction. The \c MachinePassRegistry.def file specifies how to construct
174/// all of the built-in passes, and those may reference these members during
175/// construction.
176template <typename DerivedT, typename TargetMachineT> class CodeGenPassBuilder {
177public:
178 explicit CodeGenPassBuilder(TargetMachineT &TM,
179 const CGPassBuilderOption &Opts,
181 : TM(TM), Opt(Opts), PIC(PIC) {
182 // Target could set CGPassBuilderOption::MISchedPostRA to true to achieve
183 // substitutePass(&PostRASchedulerID, &PostMachineSchedulerID)
184
185 // Target should override TM.Options.EnableIPRA in their target-specific
186 // LLVMTM ctor. See TargetMachine::setGlobalISel for example.
187 if (Opt.EnableIPRA) {
188 TM.Options.EnableIPRA = *Opt.EnableIPRA;
189 } else {
190 // If not explicitly specified, use target default.
191 TM.Options.EnableIPRA |= TM.useIPRA();
192 }
193
194 if (Opt.EnableGlobalISelAbort)
195 TM.Options.GlobalISelAbort = *Opt.EnableGlobalISelAbort;
196
197 // An explicit RegAlloc choice implies its pipeline: only the fast
198 // allocator uses the unoptimized one.
199 if (Opt.OptimizeRegAlloc == cl::boolOrDefault::BOU_UNSET) {
200 bool Optimized = Opt.RegAlloc > RegAllocType::Default
201 ? Opt.RegAlloc != RegAllocType::Fast
202 : getOptLevel() != CodeGenOptLevel::None;
203 Opt.OptimizeRegAlloc = Optimized ? cl::boolOrDefault::BOU_TRUE
204 : cl::boolOrDefault::BOU_FALSE;
205 }
206 }
207
210 CodeGenFileType FileType, MCContext &Ctx) const;
211
215
216protected:
217 template <typename PassT>
218 using is_module_pass_t = decltype(std::declval<PassT &>().run(
219 std::declval<Module &>(), std::declval<ModuleAnalysisManager &>()));
220
221 template <typename PassT>
222 using is_function_pass_t = decltype(std::declval<PassT &>().run(
223 std::declval<Function &>(), std::declval<FunctionAnalysisManager &>()));
224
225 template <typename PassT>
226 using is_machine_function_pass_t = decltype(std::declval<PassT &>().run(
227 std::declval<MachineFunction &>(),
228 std::declval<MachineFunctionAnalysisManager &>()));
229
230 template <typename PassT>
232 bool Force = false,
233 StringRef Name = PassT::name()) const {
235 "Only function passes are supported.");
236 if (!Force && !runBeforeAdding(Name))
237 return;
238 PMW.FPM.addPass(std::forward<PassT>(Pass));
239 }
240
241 template <typename PassT>
242 void addModulePass(PassT &&Pass, PassManagerWrapper &PMW, bool Force = false,
243 StringRef Name = PassT::name()) const {
245 "Only module passes are suported.");
246 assert(PMW.FPM.isEmpty() && PMW.MFPM.isEmpty() &&
247 "You cannot insert a module pass without first flushing the current "
248 "function pipelines to the module pipeline.");
249 if (!Force && !runBeforeAdding(Name))
250 return;
251 PMW.MPM.addPass(std::forward<PassT>(Pass));
252 }
253
254 template <typename PassT>
256 bool Force = false,
257 StringRef Name = PassT::name()) const {
259 "Only machine function passes are supported.");
260
261 if (!Force && !runBeforeAdding(Name))
262 return;
263 PMW.MFPM.addPass(std::forward<PassT>(Pass));
264 for (auto &C : AfterCallbacks)
265 C(Name, PMW.MFPM);
266 }
267
269 bool FreeMachineFunctions = false) const {
270 if (PMW.FPM.isEmpty() && PMW.MFPM.isEmpty())
271 return;
272 if (!PMW.MFPM.isEmpty()) {
273 PMW.FPM.addPass(
274 createFunctionToMachineFunctionPassAdaptor(std::move(PMW.MFPM)));
275 PMW.MFPM = MachineFunctionPassManager();
276 }
277 if (FreeMachineFunctions)
279 if (AddInCGSCCOrder) {
281 createCGSCCToFunctionPassAdaptor(std::move(PMW.FPM))));
282 } else {
283 PMW.MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PMW.FPM)));
284 }
285 PMW.FPM = FunctionPassManager();
286 }
287
289 assert(!AddInCGSCCOrder);
290 assert(PMW.FPM.isEmpty() && PMW.MFPM.isEmpty() &&
291 "Requiring CGSCC ordering requires flushing the current function "
292 "pipelines to the MPM.");
293 AddInCGSCCOrder = true;
294 }
295
297 assert(AddInCGSCCOrder);
298 assert(PMW.FPM.isEmpty() && PMW.MFPM.isEmpty() &&
299 "Stopping CGSCC ordering requires flushing the current function "
300 "pipelines to the MPM.");
301 AddInCGSCCOrder = false;
302 }
303
304 TargetMachineT &TM;
307
308 template <typename TMC> TMC &getTM() const { return static_cast<TMC &>(TM); }
309 CodeGenOptLevel getOptLevel() const { return TM.getOptLevel(); }
310
311 /// Check whether or not GlobalISel should abort on error.
312 /// When this is disabled, GlobalISel will fall back on SDISel instead of
313 /// erroring out.
315 return TM.Options.GlobalISelAbort == GlobalISelAbortMode::Enable;
316 }
317
318 /// Check whether or not a diagnostic should be emitted when GlobalISel
319 /// uses the fallback path. In other words, it will emit a diagnostic
320 /// when GlobalISel failed and isGlobalISelAbortEnabled is false.
322 return TM.Options.GlobalISelAbort == GlobalISelAbortMode::DisableWithDiag;
323 }
324
325 /// addInstSelector - This method should install an instruction selector pass,
326 /// which converts from LLVM code to machine instructions.
328 return make_error<StringError>("addInstSelector is not overridden",
330 }
331
332 /// Target can override this to add GlobalMergePass before all IR passes.
334
335 /// Add passes that optimize instruction level parallelism for out-of-order
336 /// targets. These passes are run while the machine code is still in SSA
337 /// form, so they can use MachineTraceMetrics to control their heuristics.
338 ///
339 /// All passes added here should preserve the MachineDominatorTree,
340 /// MachineLoopInfo, and MachineTraceMetrics analyses.
341 void addILPOpts(PassManagerWrapper &PMW) const {}
342
343 /// This method may be implemented by targets that want to run passes
344 /// immediately before register allocation.
346
347 /// addPreRewrite - Add passes to the optimized register allocation pipeline
348 /// after register allocation is complete, but before virtual registers are
349 /// rewritten to physical registers.
350 ///
351 /// These passes must preserve VirtRegMap and LiveIntervals, and when running
352 /// after RABasic or RAGreedy, they should take advantage of LiveRegMatrix.
353 /// When these passes run, VirtRegMap contains legal physreg assignments for
354 /// all virtual registers.
355 ///
356 /// Note if the target overloads addRegAssignAndRewriteOptimized, this may not
357 /// be honored. This is also not generally used for the fast variant,
358 /// where the allocation and rewriting are done in one pass.
360
361 /// Add passes to be run immediately after virtual registers are rewritten
362 /// to physical registers.
364
365 /// This method may be implemented by targets that want to run passes after
366 /// register allocation pass pipeline but before prolog-epilog insertion.
368
369 /// This method may be implemented by targets that want to run passes after
370 /// prolog-epilog insertion and before the second instruction scheduling pass.
372
373 /// This pass may be implemented by targets that want to run passes
374 /// immediately before machine code is emitted.
376
377 /// Targets may add passes immediately before machine code is emitted in this
378 /// callback. This is called even later than `addPreEmitPass`.
379 // FIXME: Rename `addPreEmitPass` to something more sensible given its actual
380 // position and remove the `2` suffix here as this callback is what
381 // `addPreEmitPass` *should* be but in reality isn't.
383
384 /// {{@ For GlobalISel
385 ///
386
387 /// addPreISel - This method should add any "last minute" LLVM->LLVM
388 /// passes (which are run just before instruction selector).
389 void addPreISel(PassManagerWrapper &PMW) const {}
390
391 /// This method should install an IR translator pass, which converts from
392 /// LLVM code to machine instructions with possibly generic opcodes.
394 return make_error<StringError>("addIRTranslator is not overridden",
396 }
397
398 /// This method may be implemented by targets that want to run passes
399 /// immediately before legalization.
401
402 /// This method should install a legalize pass, which converts the instruction
403 /// sequence into one that can be selected by the target.
405 return make_error<StringError>("addLegalizeMachineIR is not overridden",
407 }
408
409 /// This method may be implemented by targets that want to run passes
410 /// immediately before the register bank selection.
412
413 /// This method should install a register bank selector pass, which
414 /// assigns register banks to virtual registers without a register
415 /// class or register banks.
417 return make_error<StringError>("addRegBankSelect is not overridden",
419 }
420
421 /// This method may be implemented by targets that want to run passes
422 /// immediately before the (global) instruction selection.
424
425 /// This method should install a (global) instruction selector pass, which
426 /// converts possibly generic instructions to fully target-specific
427 /// instructions, thereby constraining all generic virtual registers to
428 /// register classes.
431 "addGlobalInstructionSelect is not overridden",
433 }
434 /// @}}
435
436 /// High level function that adds all passes necessary to go from llvm IR
437 /// representation to the MI representation.
438 /// Adds IR based lowering and target specific optimization passes and finally
439 /// the core instruction selection passes.
441
442 /// Add the actual instruction selection passes. This does not include
443 /// preparation passes on IR.
445
446 /// Add the complete, standard set of LLVM CodeGen passes.
447 /// Fully developed targets will not generally override this.
449
450 /// Add passes to lower exception handling for the code generator.
452
453 /// Add common target configurable passes that perform LLVM IR to IR
454 /// transforms following machine independent optimization.
456
457 /// Add pass to prepare the LLVM IR for code generation. This should be done
458 /// before exception handling preparation passes.
460
461 /// Add common passes that perform LLVM IR to IR transforms in preparation for
462 /// instruction selection.
464
465 /// Methods with trivial inline returns are convenient points in the common
466 /// codegen pass pipeline where targets may insert passes. Methods with
467 /// out-of-line standard implementations are major CodeGen stages called by
468 /// addMachinePasses. Some targets may override major stages when inserting
469 /// passes is insufficient, but maintaining overriden stages is more work.
470 ///
471
472 /// addMachineSSAOptimization - Add standard passes that optimize machine
473 /// instructions in SSA form.
475
476 /// addFastRegAlloc - Add the minimum set of target-independent passes that
477 /// are required for fast register allocation.
479
480 /// addOptimizedRegAlloc - Add passes related to register allocation.
481 /// CodeGenTargetMachineImpl provides standard regalloc passes for most
482 /// targets.
484
485 /// Add passes that optimize machine instructions after register allocation.
487
488 /// addGCPasses - Add late codegen passes that analyze code for garbage
489 /// collection. This should return true if GC info should be printed after
490 /// these passes.
491 void addGCPasses(PassManagerWrapper &PMW) const {}
492
493 /// Add standard basic block placement passes.
495
497
499 llvm_unreachable("addAsmPrinterBegin is not overriden");
500 }
501
503 llvm_unreachable("addAsmPrinter is not overridden");
504 }
505
507 llvm_unreachable("addAsmPrinterEnd is not overriden");
508 }
509
510 /// Utilities for targets to add passes to the pass manager.
511 ///
512
513 /// createTargetRegisterAllocator - Create the register allocator pass for
514 /// this target at the current optimization level.
516 bool Optimized) const;
517
518 /// addMachinePasses helper to create the target-selected or overriden
519 /// regalloc pass.
520 void addRegAllocPass(PassManagerWrapper &PMW, bool Optimized) const;
521
522 /// Add core register allocator passes which do the actual register assignment
523 /// and rewriting. addRegAssignAndRewriteOptimized should return true if any
524 /// passes were added.
527
528 /// Allow the target to disable a specific pass by default.
529 /// Backend can declare unwanted passes in constructor.
530 template <typename... PassTs> void disablePass() {
531 BeforeCallbacks.emplace_back(
532 [](StringRef Name) { return ((Name != PassTs::name()) && ...); });
533 }
534
535 /// Insert InsertedPass pass after TargetPass pass.
536 /// Only machine function passes are supported.
537 template <typename TargetPassT, typename InsertedPassT>
538 void insertPass(InsertedPassT &&Pass) const {
539 AfterCallbacks.emplace_back(
540 [&](StringRef Name, MachineFunctionPassManager &MFPM) mutable {
541 if (Name == TargetPassT::name() &&
542 runBeforeAdding(InsertedPassT::name())) {
543 MFPM.addPass(std::forward<InsertedPassT>(Pass));
544 }
545 });
546 }
547
548private:
549 DerivedT &derived() { return static_cast<DerivedT &>(*this); }
550 const DerivedT &derived() const {
551 return static_cast<const DerivedT &>(*this);
552 }
553
554 bool runBeforeAdding(StringRef Name) const {
555 bool ShouldAdd = true;
556 for (auto &C : BeforeCallbacks)
557 ShouldAdd &= C(Name);
558 return ShouldAdd;
559 }
560
561 void setStartStopPasses(const TargetPassConfig::StartStopInfo &Info) const;
562
563 Error verifyStartStop(const TargetPassConfig::StartStopInfo &Info) const;
564
565 mutable SmallVector<llvm::unique_function<bool(StringRef)>, 4>
566 BeforeCallbacks;
567 mutable SmallVector<
568 llvm::unique_function<void(StringRef, MachineFunctionPassManager &)>, 4>
569 AfterCallbacks;
570
571 /// Helper variable for `-start-before/-start-after/-stop-before/-stop-after`
572 mutable bool Started = true;
573 mutable bool Stopped = true;
574 mutable bool AddInCGSCCOrder = false;
575};
576
577template <typename Derived, typename TargetMachineT>
580 raw_pwrite_stream *DwoOut, CodeGenFileType FileType, MCContext &Ctx) const {
581 auto StartStopInfo = TargetPassConfig::getStartStopInfo(*PIC);
582 if (!StartStopInfo)
583 return StartStopInfo.takeError();
584 setStartStopPasses(*StartStopInfo);
585
587 bool PrintMIR = !PrintAsm && FileType != CodeGenFileType::Null;
588
589 PassManagerWrapper PMW(MPM);
590
592 /*Force=*/true);
594 /*Force=*/true);
596 /*Force=*/true);
598 /*Force=*/true);
600 PMW,
601 /*Force=*/true);
602 addISelPasses(PMW);
603 flushFPMsToMPM(PMW);
604
605 if (PrintAsm) {
606 Expected<std::unique_ptr<MCStreamer>> MCStreamerOrErr =
607 TM.createMCStreamer(Out, DwoOut, FileType, Ctx);
608 if (!MCStreamerOrErr)
609 return MCStreamerOrErr.takeError();
610 std::unique_ptr<AsmPrinter> Printer(
611 TM.getTarget().createAsmPrinter(TM, std::move(*MCStreamerOrErr)));
612 if (!Printer)
613 return createStringError("failed to create AsmPrinter");
614 MAM.registerPass([&] { return AsmPrinterAnalysis(std::move(Printer)); });
615 derived().addAsmPrinterBegin(PMW);
616 }
617
618 if (PrintMIR)
619 addModulePass(PrintMIRPreparePass(Out), PMW, /*Force=*/true);
620
621 if (auto Err = addCoreISelPasses(PMW))
622 return std::move(Err);
623
624 if (auto Err = derived().addMachinePasses(PMW))
625 return std::move(Err);
626
627 if (!Opt.DisableVerify && TM.Options.EnableDefaultMachineVerifier)
629
630 // We add AsmPrinter regardless if we are emitting MIR or Assembly as the
631 // final output so that -stop-before=<target>-asm-printer works. When printing
632 // MIR as the final output, we never end up running AsmPrinter.
633 derived().addAsmPrinter(PMW);
634
635 if (PrintAsm) {
636 flushFPMsToMPM(PMW, /*FreeMachineFunctions=*/true);
637 derived().addAsmPrinterEnd(PMW);
638 } else {
639 if (PrintMIR)
640 addMachineFunctionPass(PrintMIRPass(Out), PMW, /*Force=*/true);
641 flushFPMsToMPM(PMW, /*FreeMachineFunctions=*/true);
642 }
643
644 return verifyStartStop(*StartStopInfo);
645}
646
647template <typename Derived, typename TargetMachineT>
648void CodeGenPassBuilder<Derived, TargetMachineT>::setStartStopPasses(
649 const TargetPassConfig::StartStopInfo &Info) const {
650 if (!Info.StartPass.empty()) {
651 Started = false;
652 BeforeCallbacks.emplace_back([this, &Info, AfterFlag = Info.StartAfter,
653 Count = 0u](StringRef ClassName) mutable {
654 if (Count == Info.StartInstanceNum) {
655 if (AfterFlag) {
656 AfterFlag = false;
657 Started = true;
658 }
659 return Started;
660 }
661
662 auto PassName = PIC->getPassNameForClassName(ClassName);
663 if (Info.StartPass == PassName && ++Count == Info.StartInstanceNum)
664 Started = !Info.StartAfter;
665
666 return Started;
667 });
668 }
669
670 if (!Info.StopPass.empty()) {
671 Stopped = false;
672 BeforeCallbacks.emplace_back([this, &Info, AfterFlag = Info.StopAfter,
673 Count = 0u](StringRef ClassName) mutable {
674 if (Count == Info.StopInstanceNum) {
675 if (AfterFlag) {
676 AfterFlag = false;
677 Stopped = true;
678 }
679 return !Stopped;
680 }
681
682 auto PassName = PIC->getPassNameForClassName(ClassName);
683 if (Info.StopPass == PassName && ++Count == Info.StopInstanceNum)
684 Stopped = !Info.StopAfter;
685 return !Stopped;
686 });
687 }
688}
689
690template <typename Derived, typename TargetMachineT>
691Error CodeGenPassBuilder<Derived, TargetMachineT>::verifyStartStop(
692 const TargetPassConfig::StartStopInfo &Info) const {
693 if (Started && Stopped)
694 return Error::success();
695
696 if (!Started)
698 "Can't find start pass \"" + Info.StartPass + "\".",
699 std::make_error_code(std::errc::invalid_argument));
700 if (!Stopped)
702 "Can't find stop pass \"" + Info.StopPass + "\".",
703 std::make_error_code(std::errc::invalid_argument));
704 return Error::success();
705}
706
707template <typename Derived, typename TargetMachineT>
709 PassManagerWrapper &PMW) const {
710 derived().addGlobalMergePass(PMW);
711 if (TM.useEmulatedTLS())
713
714 // ObjCARCContract operates on ObjC intrinsics and must run before
715 // PreISelIntrinsicLowering.
718 flushFPMsToMPM(PMW);
719 }
722
723 derived().addIRPasses(PMW);
724 derived().addCodeGenPrepare(PMW);
726 derived().addISelPrepare(PMW);
727}
728
729/// Add common target configurable passes that perform LLVM IR to IR transforms
730/// following machine independent optimization.
731template <typename Derived, typename TargetMachineT>
733 PassManagerWrapper &PMW) const {
734 // Before running any passes, run the verifier to determine if the input
735 // coming from the front-end and/or optimizer is valid.
736 if (!Opt.DisableVerify)
737 addFunctionPass(VerifierPass(), PMW, /*Force=*/true);
738
739 // Run loop strength reduction before anything else.
740 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableLSR) {
741 // These passes do not use MSSA.
742 LoopPassManager LPM;
743 LPM.addPass(CanonicalizeFreezeInLoopsPass());
744 LPM.addPass(LoopStrengthReducePass());
745 if (Opt.EnableLoopTermFold)
746 LPM.addPass(LoopTermFoldPass());
748 /*UseMemorySSA=*/false),
749 PMW);
750 }
751
752 // Run GC lowering passes for builtin collectors
753 // TODO: add a pass insertion point here
755 // Explicitly check to see if we should add ShadowStackGCLowering to avoid
756 // splitting the function pipeline if we do not have to.
757 if (runBeforeAdding(ShadowStackGCLoweringPass::name())) {
758 flushFPMsToMPM(PMW);
760 }
761
762 // Make sure that no unreachable blocks are instruction selected.
764
765 // Prepare expensive constants for SelectionDAG.
766 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableConstantHoisting)
768
769 // Replace calls to LLVM intrinsics (e.g., exp, log) operating on vector
770 // operands with calls to the corresponding functions in a vector library.
773
775 !Opt.DisablePartialLibcallInlining)
777
778 // Instrument function entry and exit, e.g. with calls to mcount().
779 addFunctionPass(EntryExitInstrumenterPass(/*PostInlining=*/true), PMW);
780
781 // Add scalarization of target's unsupported masked memory intrinsics pass.
782 // the unsupported intrinsic will be replaced with a chain of basic blocks,
783 // that stores/loads element one-by-one if the appropriate mask bit is set.
785
786 // Expand reduction intrinsics into shuffle sequences if the target wants to.
787 if (!Opt.DisableExpandReductions)
789
790 // Convert conditional moves to conditional jumps when profitable.
791 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableSelectOptimize)
793
794 if (Opt.EnableGlobalMergeFunc) {
795 flushFPMsToMPM(PMW);
797 }
798}
799
800/// Turn exception handling constructs into something the code generators can
801/// handle.
802template <typename Derived, typename TargetMachineT>
804 PassManagerWrapper &PMW) const {
805 const MCAsmInfo &MCAI = TM.getMCAsmInfo();
806 switch (MCAI.getExceptionHandlingType()) {
808 // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
809 // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
810 // catch info can get misplaced when a selector ends up more than one block
811 // removed from the parent invoke(s). This could happen when a landing
812 // pad is shared by multiple invokes and is also a target of a normal
813 // edge from elsewhere.
815 [[fallthrough]];
821 break;
823 // We support using both GCC-style and MSVC-style exceptions on Windows, so
824 // add both preparation passes. Each pass will only actually run if it
825 // recognizes the personality function.
828 break;
830 // Wasm EH uses Windows EH instructions, but it does not need to demote PHIs
831 // on catchpads and cleanuppads because it does not outline them into
832 // funclets. Catchswitch blocks are not lowered in SelectionDAG, so we
833 // should remove PHIs there.
834 addFunctionPass(WinEHPreparePass(/*DemoteCatchSwitchPHIOnly=*/false), PMW);
836 break;
839
840 // The lower invoke pass may create unreachable code. Remove it.
842 break;
843 }
844}
845
846/// Add pass to prepare the LLVM IR for code generation. This should be done
847/// before exception handling preparation passes.
848template <typename Derived, typename TargetMachineT>
850 PassManagerWrapper &PMW) const {
851 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableCGP)
853 // TODO: Default ctor'd RewriteSymbolPass is no-op.
854 // addPass(RewriteSymbolPass());
855}
856
857/// Add common passes that perform LLVM IR to IR transforms in preparation for
858/// instruction selection.
859template <typename Derived, typename TargetMachineT>
861 PassManagerWrapper &PMW) const {
862 derived().addPreISel(PMW);
863
864 if (Opt.RequiresCodeGenSCCOrder && !AddInCGSCCOrder)
866
868 // Add both the safe stack and the stack protection passes: each of them will
869 // only protect functions that have corresponding attributes.
872
873 if (Opt.PrintISelInput)
875 dbgs(), "\n\n*** Final LLVM Code input to ISel ***\n"),
876 PMW);
877
878 // All passes which modify the LLVM IR are now complete; run the verifier
879 // to ensure that the IR is valid.
880 if (!Opt.DisableVerify)
881 addFunctionPass(VerifierPass(), PMW, /*Force=*/true);
882}
883
884template <typename Derived, typename TargetMachineT>
886 PassManagerWrapper &PMW) const {
887 // Enable FastISel with -fast-isel, but allow that to be overridden.
888 TM.setO0WantsFastISel(Opt.EnableFastISelOption !=
890
891 // Determine an instruction selector.
892 enum class SelectorType { SelectionDAG, FastISel, GlobalISel };
893 SelectorType Selector;
894
895 if (Opt.EnableFastISelOption == cl::boolOrDefault::BOU_TRUE)
896 Selector = SelectorType::FastISel;
897 else if (Opt.EnableGlobalISelOption == cl::boolOrDefault::BOU_TRUE ||
898 (TM.Options.EnableGlobalISel &&
899 Opt.EnableGlobalISelOption != cl::boolOrDefault::BOU_FALSE))
900 Selector = SelectorType::GlobalISel;
901 else if (TM.getOptLevel() == CodeGenOptLevel::None && TM.getO0WantsFastISel())
902 Selector = SelectorType::FastISel;
903 else
904 Selector = SelectorType::SelectionDAG;
905
906 // Set consistently TM.Options.EnableFastISel and EnableGlobalISel.
907 if (Selector == SelectorType::FastISel) {
908 TM.setFastISel(true);
909 TM.setGlobalISel(false);
910 } else if (Selector == SelectorType::GlobalISel) {
911 TM.setFastISel(false);
912 TM.setGlobalISel(true);
913 }
914
915 // Add instruction selector passes.
916 if (Selector == SelectorType::GlobalISel) {
917 if (auto Err = derived().addIRTranslator(PMW))
918 return std::move(Err);
919
920 derived().addPreLegalizeMachineIR(PMW);
921
922 if (auto Err = derived().addLegalizeMachineIR(PMW))
923 return std::move(Err);
924
925 // Before running the register bank selector, ask the target if it
926 // wants to run some passes.
927 derived().addPreRegBankSelect(PMW);
928
929 if (auto Err = derived().addRegBankSelect(PMW))
930 return std::move(Err);
931
932 derived().addPreGlobalInstructionSelect(PMW);
933
934 if (auto Err = derived().addGlobalInstructionSelect(PMW))
935 return std::move(Err);
936
937 // Pass to reset the MachineFunction if the ISel failed.
939 ResetMachineFunctionPass(reportDiagnosticWhenGlobalISelFallback(),
941 PMW);
942
943 // Provide a fallback path when we do not want to abort on
944 // not-yet-supported input.
946 if (auto Err = derived().addInstSelector(PMW))
947 return std::move(Err);
948
949 } else if (auto Err = derived().addInstSelector(PMW))
950 return std::move(Err);
951
952 // Expand pseudo-instructions emitted by ISel. Don't run the verifier before
953 // FinalizeISel.
955
956 // // Print the instruction selected machine code...
957 // printAndVerify("After Instruction Selection");
958
959 return Error::success();
960}
961
962/// Add the complete set of target-independent postISel code generator passes.
963///
964/// This can be read as the standard order of major LLVM CodeGen stages. Stages
965/// with nontrivial configuration or multiple passes are broken out below in
966/// add%Stage routines.
967///
968/// Any CodeGenPassBuilder<Derived, TargetMachine>::addXX routine may be
969/// overriden by the Target. The addPre/Post methods with empty header
970/// implementations allow injecting target-specific fixups just before or after
971/// major stages. Additionally, targets have the flexibility to change pass
972/// order within a stage by overriding default implementation of add%Stage
973/// routines below. Each technique has maintainability tradeoffs because
974/// alternate pass orders are not well supported. addPre/Post works better if
975/// the target pass is easily tied to a common pass. But if it has subtle
976/// dependencies on multiple passes, the target should override the stage
977/// instead.
978template <typename Derived, typename TargetMachineT>
980 PassManagerWrapper &PMW) const {
981 // Add passes that optimize machine instructions in SSA form.
983 derived().addMachineSSAOptimization(PMW);
984 } else {
985 // If the target requests it, assign local variables to stack slots relative
986 // to one another and simplify frame index references where possible.
988 }
989
990 if (TM.Options.EnableIPRA) {
991 flushFPMsToMPM(PMW);
993 PMW, /*Force=*/true);
995 }
996 // Run pre-ra passes.
997 derived().addPreRegAlloc(PMW);
998
999 // Run register allocation and passes that are tightly coupled with it,
1000 // including phi elimination and scheduling.
1001 if (auto Err = Opt.OptimizeRegAlloc == cl::boolOrDefault::BOU_TRUE
1002 ? derived().addOptimizedRegAlloc(PMW)
1003 : derived().addFastRegAlloc(PMW))
1004 return std::move(Err);
1005
1006 // Run post-ra passes.
1007 derived().addPostRegAlloc(PMW);
1008
1011
1012 // Insert prolog/epilog code. Eliminate abstract frame index references...
1016 }
1017
1019
1020 /// Add passes that optimize machine instructions after register allocation.
1022 derived().addMachineLateOptimization(PMW);
1023
1024 // Expand pseudo instructions before second scheduling pass.
1026
1027 // Run pre-sched2 passes.
1028 derived().addPreSched2(PMW);
1029
1030 if (Opt.EnableImplicitNullChecks)
1031 addMachineFunctionPass(ImplicitNullChecksPass(), PMW);
1032
1033 // Second pass scheduler.
1034 // Let Target optionally insert this pass by itself at some other
1035 // point.
1037 !TM.targetSchedulesPostRAScheduling()) {
1038 if (Opt.MISchedPostRA)
1040 else
1042 }
1043
1044 // GC
1045 derived().addGCPasses(PMW);
1046
1047 // Basic block placement.
1049 derived().addBlockPlacement(PMW);
1050
1051 // Insert before XRay Instrumentation.
1053
1056
1057 derived().addPreEmitPass(PMW);
1058
1059 if (TM.Options.EnableIPRA) {
1060 // Collect register usage information and produce a register mask of
1061 // clobbered registers, to be used to optimize call sites.
1063 // If -print-regusage is specified, print the collected register usage info.
1064 if (Opt.PrintRegUsage) {
1065 flushFPMsToMPM(PMW);
1067 }
1068 }
1069
1070 addMachineFunctionPass(FuncletLayoutPass(), PMW);
1071
1073 addMachineFunctionPass(StackMapLivenessPass(), PMW);
1076 getTM<TargetMachine>().Options.ShouldEmitDebugEntryValues()),
1077 PMW);
1079
1080 if (TM.Options.EnableMachineOutliner &&
1082 Opt.EnableMachineOutliner != RunOutliner::NeverOutline) {
1083 if (Opt.EnableMachineOutliner != RunOutliner::TargetDefault ||
1084 TM.Options.SupportsDefaultOutlining) {
1085 flushFPMsToMPM(PMW);
1086 addModulePass(MachineOutlinerPass(Opt.EnableMachineOutliner), PMW);
1087 }
1088 }
1089
1090 if (Opt.EnableGCEmptyBlocks)
1092
1093 derived().addPostBBSections(PMW);
1094
1096
1097 // Add passes that directly emit MI after all other MI passes.
1098 derived().addPreEmitPass2(PMW);
1099
1100 return Error::success();
1101}
1102
1103/// Add passes that optimize machine instructions in SSA form.
1104template <typename Derived, typename TargetMachineT>
1106 PassManagerWrapper &PMW) const {
1107 // Pre-ra tail duplication.
1109
1110 // Optimize PHIs before DCE: removing dead PHI cycles may make more
1111 // instructions dead.
1113
1114 // This pass merges large allocas. StackSlotColoring is a different pass
1115 // which merges spill slots.
1117
1118 // If the target requests it, assign local variables to stack slots relative
1119 // to one another and simplify frame index references where possible.
1121
1122 // With optimization, dead code should already be eliminated. However
1123 // there is one known exception: lowered code for arguments that are only
1124 // used by tail calls, where the tail calls reuse the incoming stack
1125 // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
1127
1128 // Allow targets to insert passes that improve instruction level parallelism,
1129 // like if-conversion. Such passes will typically need dominator trees and
1130 // loop info, just like LICM and CSE below.
1131 derived().addILPOpts(PMW);
1132
1135
1136 addMachineFunctionPass(MachineSinkingPass(Opt.EnableSinkAndFold), PMW);
1137
1139 // Clean-up the dead code that may have been generated by peephole
1140 // rewriting.
1142}
1143
1144//===---------------------------------------------------------------------===//
1145/// Register Allocation Pass Configuration
1146//===---------------------------------------------------------------------===//
1147
1148/// Instantiate the default register allocator pass for this target for either
1149/// the optimized or unoptimized allocation path. This will be added to the pass
1150/// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
1151/// in the optimized case.
1152///
1153/// A target that uses the standard regalloc pass order for fast or optimized
1154/// allocation may still override this for per-target regalloc
1155/// selection. But -regalloc-npm=... always takes precedence.
1156/// If a target does not want to allow users to set -regalloc-npm=... at all,
1157/// check if Opt.RegAlloc == RegAllocType::Unset.
1158template <typename Derived, typename TargetMachineT>
1160 PassManagerWrapper &PMW, bool Optimized) const {
1161 if (Optimized)
1163 else
1165}
1166
1167/// Find and instantiate the register allocation pass requested by this target
1168/// at the current optimization level. Different register allocators are
1169/// defined as separate passes because they may require different analysis.
1170///
1171/// This helper ensures that the -regalloc-npm= option is always available,
1172/// even for targets that override the default allocator.
1173template <typename Derived, typename TargetMachineT>
1175 PassManagerWrapper &PMW, bool Optimized) const {
1176 // Use the specified -regalloc-npm={basic|greedy|fast|pbqp}
1177 if (Opt.RegAlloc > RegAllocType::Default) {
1178 switch (Opt.RegAlloc) {
1179 case RegAllocType::Fast:
1181 break;
1184 break;
1185 default:
1186 reportFatalUsageError("register allocator not supported yet");
1187 }
1188 return;
1189 }
1190 // -regalloc=default or unspecified, so pick based on the optimization level
1191 // or ask the target for the regalloc pass.
1192 derived().addTargetRegisterAllocator(PMW, Optimized);
1193}
1194
1195template <typename Derived, typename TargetMachineT>
1197 PassManagerWrapper &PMW) const {
1198 // TODO: Ensure allocator is default or fast.
1199 addRegAllocPass(PMW, false);
1200 return Error::success();
1201}
1202
1203template <typename Derived, typename TargetMachineT>
1206 PassManagerWrapper &PMW) const {
1207 // Add the selected register allocation pass.
1208 addRegAllocPass(PMW, true);
1209
1210 // Allow targets to change the register assignments before rewriting.
1211 derived().addPreRewrite(PMW);
1212
1213 // Finally rewrite virtual registers.
1215
1216 return true;
1217}
1218
1219/// Add the minimum set of target-independent passes that are required for
1220/// register allocation. No coalescing or scheduling.
1221template <typename Derived, typename TargetMachineT>
1228
1229/// Add standard target-independent passes that are tightly coupled with
1230/// optimized register allocation, including coalescing, machine instruction
1231/// scheduling, and register allocation itself.
1232template <typename Derived, typename TargetMachineT>
1234 PassManagerWrapper &PMW) const {
1236
1238
1240
1241 // LiveVariables currently requires pure SSA form.
1242 //
1243 // FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
1244 // LiveVariables can be removed completely, and LiveIntervals can be directly
1245 // computed. (We still either need to regenerate kill flags after regalloc, or
1246 // preferably fix the scavenger to not depend on them).
1247 // FIXME: UnreachableMachineBlockElim is a dependant pass of LiveVariables.
1248 // When LiveVariables is removed this has to be removed/moved either.
1249 // Explicit addition of UnreachableMachineBlockElim allows stopping before or
1250 // after it with -stop-before/-stop-after.
1254
1255 // Edge splitting is smarter with machine loop info.
1259
1260 // Eventually, we want to run LiveIntervals before PHI elimination.
1261 if (Opt.EarlyLiveIntervals)
1264
1267
1268 // The machine scheduler may accidentally create disconnected components
1269 // when moving subregister definitions around, avoid this by splitting them to
1270 // separate vregs before. Splitting can also improve reg. allocation quality.
1272
1273 // PreRA instruction scheduling.
1275
1276 Expected<bool> AddedPasses = derived().addRegAssignAndRewriteOptimized(PMW);
1277 if (!AddedPasses)
1278 return AddedPasses.takeError();
1279 if (!AddedPasses.get())
1280 return Error::success();
1281
1283
1284 // Allow targets to expand pseudo instructions depending on the choice of
1285 // registers before MachineCopyPropagation.
1286 derived().addPostRewrite(PMW);
1287
1288 // Copy propagate to forward register uses and try to eliminate COPYs that
1289 // were not coalesced.
1291
1292 // Run post-ra machine LICM to hoist reloads / remats.
1293 //
1294 // FIXME: can this move into MachineLateOptimization?
1296
1297 return Error::success();
1298}
1299
1300//===---------------------------------------------------------------------===//
1301/// Post RegAlloc Pass Configuration
1302//===---------------------------------------------------------------------===//
1303
1304/// Add passes that optimize machine instructions after register allocation.
1305template <typename Derived, typename TargetMachineT>
1307 PassManagerWrapper &PMW) const {
1308 // Cleanup of redundant (identical) address/immediate loads.
1310
1311 // Branch folding must be run after regalloc and prolog/epilog insertion.
1312 addMachineFunctionPass(BranchFolderPass(Opt.EnableTailMerge), PMW);
1313
1314 // Tail duplication.
1315 // Note that duplicating tail just increases code size and degrades
1316 // performance for targets that require Structured Control Flow.
1317 // In addition it can also make CFG irreducible. Thus we disable it.
1318 if (!TM.requiresStructuredCFG())
1320
1321 // Copy propagation.
1323}
1324
1325/// Add standard basic block placement passes.
1326template <typename Derived, typename TargetMachineT>
1328 PassManagerWrapper &PMW) const {
1330 // Run a separate pass to collect block placement statistics.
1331 if (Opt.EnableBlockPlacementStats)
1333}
1334
1335} // namespace llvm
1336
1337#endif // LLVM_PASSES_CODEGENPASSBUILDER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
amdgpu next use AMDGPU Next Use Analysis Printer
This is the interface for LLVM's primary stateless and local alias analysis.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This header provides classes for managing passes over SCCs of the call graph.
Defines an IR pass for CodeGen Prepare.
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...
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
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
Expected< bool > addRegAssignAndRewriteOptimized(PassManagerWrapper &PMW) const
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.
Error addRegAssignAndRewriteFast(PassManagerWrapper &PMW) const
Add core register allocator passes which do the actual register assignment and rewriting.
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
CodeGenOptLevel getOptLevel() 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
reference get()
Returns a reference to the stored T value.
Definition Error.h:582
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
Definition FastISel.h:67
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:67
ExceptionHandling getExceptionHandlingType() const
Definition MCAsmInfo.h:656
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...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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:133
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.
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
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
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:178
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:209
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:149
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.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
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'.
@ SjLj
setjmp/longjmp based exceptions
Definition CodeGen.h:57
@ ZOS
z/OS MVS Exception Handling.
Definition CodeGen.h:62
@ None
No exception support.
Definition CodeGen.h:55
@ AIX
AIX Exception Handling.
Definition CodeGen.h:61
@ DwarfCFI
DWARF-like instruction based exceptions.
Definition CodeGen.h:56
@ WinEH
Windows Exception Handling.
Definition CodeGen.h:59
@ Wasm
WebAssembly Exception Handling.
Definition CodeGen.h:60
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.