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"
64#include "llvm/CodeGen/PEI.h"
101#include "llvm/IR/PassManager.h"
102#include "llvm/IR/Verifier.h"
104#include "llvm/MC/MCAsmInfo.h"
106#include "llvm/Support/CodeGen.h"
107#include "llvm/Support/Debug.h"
108#include "llvm/Support/Error.h"
124#include <cassert>
125#include <utility>
126
127namespace llvm {
128
129// FIXME: Dummy target independent passes definitions that have not yet been
130// ported to new pass manager. Once they do, remove these.
131#define DUMMY_FUNCTION_PASS(NAME, PASS_NAME) \
132 struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
133 template <typename... Ts> PASS_NAME(Ts &&...) {} \
134 PreservedAnalyses run(Function &, FunctionAnalysisManager &) { \
135 return PreservedAnalyses::all(); \
136 } \
137 };
138#define DUMMY_MACHINE_MODULE_PASS(NAME, PASS_NAME) \
139 struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
140 template <typename... Ts> PASS_NAME(Ts &&...) {} \
141 PreservedAnalyses run(Module &, ModuleAnalysisManager &) { \
142 return PreservedAnalyses::all(); \
143 } \
144 };
145#define DUMMY_MACHINE_FUNCTION_PASS(NAME, PASS_NAME) \
146 struct PASS_NAME : public PassInfoMixin<PASS_NAME> { \
147 template <typename... Ts> PASS_NAME(Ts &&...) {} \
148 PreservedAnalyses run(MachineFunction &, \
149 MachineFunctionAnalysisManager &) { \
150 return PreservedAnalyses::all(); \
151 } \
152 };
153#include "llvm/Passes/MachinePassRegistry.def"
154
155class PassManagerWrapper {
156private:
157 PassManagerWrapper(ModulePassManager &ModulePM) : MPM(ModulePM) {};
158
162
163 template <typename DerivedT, typename TargetMachineT>
164 friend class CodeGenPassBuilder;
165};
166
168 std::function<Expected<std::unique_ptr<MCStreamer>>(TargetMachine &)>;
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 if (!Opt.OptimizeRegAlloc)
198 Opt.OptimizeRegAlloc = getOptLevel() != CodeGenOptLevel::None;
199 }
200
202 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
203 MCContext &Ctx) const;
204
208
209protected:
210 template <typename PassT>
211 using is_module_pass_t = decltype(std::declval<PassT &>().run(
212 std::declval<Module &>(), std::declval<ModuleAnalysisManager &>()));
213
214 template <typename PassT>
215 using is_function_pass_t = decltype(std::declval<PassT &>().run(
216 std::declval<Function &>(), std::declval<FunctionAnalysisManager &>()));
217
218 template <typename PassT>
219 using is_machine_function_pass_t = decltype(std::declval<PassT &>().run(
220 std::declval<MachineFunction &>(),
221 std::declval<MachineFunctionAnalysisManager &>()));
222
223 template <typename PassT>
225 bool Force = false,
226 StringRef Name = PassT::name()) const {
228 "Only function passes are supported.");
229 if (!Force && !runBeforeAdding(Name))
230 return;
231 PMW.FPM.addPass(std::forward<PassT>(Pass));
232 }
233
234 template <typename PassT>
235 void addModulePass(PassT &&Pass, PassManagerWrapper &PMW, bool Force = false,
236 StringRef Name = PassT::name()) const {
238 "Only module passes are suported.");
239 assert(PMW.FPM.isEmpty() && PMW.MFPM.isEmpty() &&
240 "You cannot insert a module pass without first flushing the current "
241 "function pipelines to the module pipeline.");
242 if (!Force && !runBeforeAdding(Name))
243 return;
244 PMW.MPM.addPass(std::forward<PassT>(Pass));
245 }
246
247 template <typename PassT>
249 bool Force = false,
250 StringRef Name = PassT::name()) const {
252 "Only machine function passes are supported.");
253
254 if (!Force && !runBeforeAdding(Name))
255 return;
256 PMW.MFPM.addPass(std::forward<PassT>(Pass));
257 for (auto &C : AfterCallbacks)
258 C(Name, PMW.MFPM);
259 }
260
262 bool FreeMachineFunctions = false) const {
263 if (PMW.FPM.isEmpty() && PMW.MFPM.isEmpty())
264 return;
265 if (!PMW.MFPM.isEmpty()) {
266 PMW.FPM.addPass(
267 createFunctionToMachineFunctionPassAdaptor(std::move(PMW.MFPM)));
268 PMW.MFPM = MachineFunctionPassManager();
269 }
270 if (FreeMachineFunctions)
272 if (AddInCGSCCOrder) {
274 createCGSCCToFunctionPassAdaptor(std::move(PMW.FPM))));
275 } else {
276 PMW.MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PMW.FPM)));
277 }
278 PMW.FPM = FunctionPassManager();
279 }
280
282 assert(!AddInCGSCCOrder);
283 assert(PMW.FPM.isEmpty() && PMW.MFPM.isEmpty() &&
284 "Requiring CGSCC ordering requires flushing the current function "
285 "pipelines to the MPM.");
286 AddInCGSCCOrder = true;
287 }
288
290 assert(AddInCGSCCOrder);
291 assert(PMW.FPM.isEmpty() && PMW.MFPM.isEmpty() &&
292 "Stopping CGSCC ordering requires flushing the current function "
293 "pipelines to the MPM.");
294 AddInCGSCCOrder = false;
295 }
296
297 TargetMachineT &TM;
300
301 template <typename TMC> TMC &getTM() const { return static_cast<TMC &>(TM); }
302 CodeGenOptLevel getOptLevel() const { return TM.getOptLevel(); }
303
304 /// Check whether or not GlobalISel should abort on error.
305 /// When this is disabled, GlobalISel will fall back on SDISel instead of
306 /// erroring out.
308 return TM.Options.GlobalISelAbort == GlobalISelAbortMode::Enable;
309 }
310
311 /// Check whether or not a diagnostic should be emitted when GlobalISel
312 /// uses the fallback path. In other words, it will emit a diagnostic
313 /// when GlobalISel failed and isGlobalISelAbortEnabled is false.
315 return TM.Options.GlobalISelAbort == GlobalISelAbortMode::DisableWithDiag;
316 }
317
318 /// addInstSelector - This method should install an instruction selector pass,
319 /// which converts from LLVM code to machine instructions.
321 return make_error<StringError>("addInstSelector is not overridden",
323 }
324
325 /// Target can override this to add GlobalMergePass before all IR passes.
327
328 /// Add passes that optimize instruction level parallelism for out-of-order
329 /// targets. These passes are run while the machine code is still in SSA
330 /// form, so they can use MachineTraceMetrics to control their heuristics.
331 ///
332 /// All passes added here should preserve the MachineDominatorTree,
333 /// MachineLoopInfo, and MachineTraceMetrics analyses.
334 void addILPOpts(PassManagerWrapper &PMW) const {}
335
336 /// This method may be implemented by targets that want to run passes
337 /// immediately before register allocation.
339
340 /// addPreRewrite - Add passes to the optimized register allocation pipeline
341 /// after register allocation is complete, but before virtual registers are
342 /// rewritten to physical registers.
343 ///
344 /// These passes must preserve VirtRegMap and LiveIntervals, and when running
345 /// after RABasic or RAGreedy, they should take advantage of LiveRegMatrix.
346 /// When these passes run, VirtRegMap contains legal physreg assignments for
347 /// all virtual registers.
348 ///
349 /// Note if the target overloads addRegAssignAndRewriteOptimized, this may not
350 /// be honored. This is also not generally used for the fast variant,
351 /// where the allocation and rewriting are done in one pass.
353
354 /// Add passes to be run immediately after virtual registers are rewritten
355 /// to physical registers.
357
358 /// This method may be implemented by targets that want to run passes after
359 /// register allocation pass pipeline but before prolog-epilog insertion.
361
362 /// This method may be implemented by targets that want to run passes after
363 /// prolog-epilog insertion and before the second instruction scheduling pass.
365
366 /// This pass may be implemented by targets that want to run passes
367 /// immediately before machine code is emitted.
369
370 /// Targets may add passes immediately before machine code is emitted in this
371 /// callback. This is called even later than `addPreEmitPass`.
372 // FIXME: Rename `addPreEmitPass` to something more sensible given its actual
373 // position and remove the `2` suffix here as this callback is what
374 // `addPreEmitPass` *should* be but in reality isn't.
376
377 /// {{@ For GlobalISel
378 ///
379
380 /// addPreISel - This method should add any "last minute" LLVM->LLVM
381 /// passes (which are run just before instruction selector).
383 llvm_unreachable("addPreISel is not overridden");
384 }
385
386 /// This method should install an IR translator pass, which converts from
387 /// LLVM code to machine instructions with possibly generic opcodes.
389 return make_error<StringError>("addIRTranslator is not overridden",
391 }
392
393 /// This method may be implemented by targets that want to run passes
394 /// immediately before legalization.
396
397 /// This method should install a legalize pass, which converts the instruction
398 /// sequence into one that can be selected by the target.
400 return make_error<StringError>("addLegalizeMachineIR is not overridden",
402 }
403
404 /// This method may be implemented by targets that want to run passes
405 /// immediately before the register bank selection.
407
408 /// This method should install a register bank selector pass, which
409 /// assigns register banks to virtual registers without a register
410 /// class or register banks.
412 return make_error<StringError>("addRegBankSelect is not overridden",
414 }
415
416 /// This method may be implemented by targets that want to run passes
417 /// immediately before the (global) instruction selection.
419
420 /// This method should install a (global) instruction selector pass, which
421 /// converts possibly generic instructions to fully target-specific
422 /// instructions, thereby constraining all generic virtual registers to
423 /// register classes.
426 "addGlobalInstructionSelect is not overridden",
428 }
429 /// @}}
430
431 /// High level function that adds all passes necessary to go from llvm IR
432 /// representation to the MI representation.
433 /// Adds IR based lowering and target specific optimization passes and finally
434 /// the core instruction selection passes.
436
437 /// Add the actual instruction selection passes. This does not include
438 /// preparation passes on IR.
440
441 /// Add the complete, standard set of LLVM CodeGen passes.
442 /// Fully developed targets will not generally override this.
444
445 /// Add passes to lower exception handling for the code generator.
447
448 /// Add common target configurable passes that perform LLVM IR to IR
449 /// transforms following machine independent optimization.
451
452 /// Add pass to prepare the LLVM IR for code generation. This should be done
453 /// before exception handling preparation passes.
455
456 /// Add common passes that perform LLVM IR to IR transforms in preparation for
457 /// instruction selection.
459
460 /// Methods with trivial inline returns are convenient points in the common
461 /// codegen pass pipeline where targets may insert passes. Methods with
462 /// out-of-line standard implementations are major CodeGen stages called by
463 /// addMachinePasses. Some targets may override major stages when inserting
464 /// passes is insufficient, but maintaining overriden stages is more work.
465 ///
466
467 /// addMachineSSAOptimization - Add standard passes that optimize machine
468 /// instructions in SSA form.
470
471 /// addFastRegAlloc - Add the minimum set of target-independent passes that
472 /// are required for fast register allocation.
474
475 /// addOptimizedRegAlloc - Add passes related to register allocation.
476 /// CodeGenTargetMachineImpl provides standard regalloc passes for most
477 /// targets.
479
480 /// Add passes that optimize machine instructions after register allocation.
482
483 /// addGCPasses - Add late codegen passes that analyze code for garbage
484 /// collection. This should return true if GC info should be printed after
485 /// these passes.
486 void addGCPasses(PassManagerWrapper &PMW) const {}
487
488 /// Add standard basic block placement passes.
490
492
494 CreateMCStreamer CreateStreamer) const {
495 llvm_unreachable("addAsmPrinterBegin is not overriden");
496 }
497
499 CreateMCStreamer CreateStreamer) const {
500 llvm_unreachable("addAsmPrinter is not overridden");
501 }
502
504 CreateMCStreamer CreateStreamer) const {
505 llvm_unreachable("addAsmPrinterEnd is not overriden");
506 }
507
508 /// Utilities for targets to add passes to the pass manager.
509 ///
510
511 /// createTargetRegisterAllocator - Create the register allocator pass for
512 /// this target at the current optimization level.
514 bool Optimized) const;
515
516 /// addMachinePasses helper to create the target-selected or overriden
517 /// regalloc pass.
518 void addRegAllocPass(PassManagerWrapper &PMW, bool Optimized) const;
519
520 /// Add core register allocator passes which do the actual register assignment
521 /// and rewriting.
524
525 /// Allow the target to disable a specific pass by default.
526 /// Backend can declare unwanted passes in constructor.
527 template <typename... PassTs> void disablePass() {
528 BeforeCallbacks.emplace_back(
529 [](StringRef Name) { return ((Name != PassTs::name()) && ...); });
530 }
531
532 /// Insert InsertedPass pass after TargetPass pass.
533 /// Only machine function passes are supported.
534 template <typename TargetPassT, typename InsertedPassT>
535 void insertPass(InsertedPassT &&Pass) const {
536 AfterCallbacks.emplace_back(
537 [&](StringRef Name, MachineFunctionPassManager &MFPM) mutable {
538 if (Name == TargetPassT::name() &&
539 runBeforeAdding(InsertedPassT::name())) {
540 MFPM.addPass(std::forward<InsertedPassT>(Pass));
541 }
542 });
543 }
544
545private:
546 DerivedT &derived() { return static_cast<DerivedT &>(*this); }
547 const DerivedT &derived() const {
548 return static_cast<const DerivedT &>(*this);
549 }
550
551 bool runBeforeAdding(StringRef Name) const {
552 bool ShouldAdd = true;
553 for (auto &C : BeforeCallbacks)
554 ShouldAdd &= C(Name);
555 return ShouldAdd;
556 }
557
558 void setStartStopPasses(const TargetPassConfig::StartStopInfo &Info) const;
559
560 Error verifyStartStop(const TargetPassConfig::StartStopInfo &Info) const;
561
562 mutable SmallVector<llvm::unique_function<bool(StringRef)>, 4>
563 BeforeCallbacks;
564 mutable SmallVector<
565 llvm::unique_function<void(StringRef, MachineFunctionPassManager &)>, 4>
566 AfterCallbacks;
567
568 /// Helper variable for `-start-before/-start-after/-stop-before/-stop-after`
569 mutable bool Started = true;
570 mutable bool Stopped = true;
571 mutable bool AddInCGSCCOrder = false;
572};
573
574template <typename Derived, typename TargetMachineT>
577 CodeGenFileType FileType, MCContext &Ctx) const {
578 auto StartStopInfo = TargetPassConfig::getStartStopInfo(*PIC);
579 if (!StartStopInfo)
580 return StartStopInfo.takeError();
581 setStartStopPasses(*StartStopInfo);
582
584 bool PrintMIR = !PrintAsm && FileType != CodeGenFileType::Null;
585
586 PassManagerWrapper PMW(MPM);
587
589 /*Force=*/true);
591 /*Force=*/true);
593 /*Force=*/true);
595 /*Force=*/true);
597 PMW,
598 /*Force=*/true);
599 addISelPasses(PMW);
600 flushFPMsToMPM(PMW);
601
602 CreateMCStreamer CreateStreamer = [&Out, DwoOut, FileType,
603 &Ctx](TargetMachine &TM) {
604 return TM.createMCStreamer(Out, DwoOut, FileType, Ctx);
605 };
606 if (PrintAsm)
607 derived().addAsmPrinterBegin(PMW, CreateStreamer);
608
609 if (PrintMIR)
610 addModulePass(PrintMIRPreparePass(Out), PMW, /*Force=*/true);
611
612 if (auto Err = addCoreISelPasses(PMW))
613 return std::move(Err);
614
615 if (auto Err = derived().addMachinePasses(PMW))
616 return std::move(Err);
617
618 if (!Opt.DisableVerify)
620
621 if (PrintAsm) {
622 derived().addAsmPrinter(PMW, CreateStreamer);
623 flushFPMsToMPM(PMW, /*FreeMachineFunctions=*/true);
624 derived().addAsmPrinterEnd(PMW, CreateStreamer);
625 } else {
626 if (PrintMIR)
627 addMachineFunctionPass(PrintMIRPass(Out), PMW, /*Force=*/true);
628 flushFPMsToMPM(PMW, /*FreeMachineFunctions=*/true);
629 }
630
631 return verifyStartStop(*StartStopInfo);
632}
633
634template <typename Derived, typename TargetMachineT>
635void CodeGenPassBuilder<Derived, TargetMachineT>::setStartStopPasses(
636 const TargetPassConfig::StartStopInfo &Info) const {
637 if (!Info.StartPass.empty()) {
638 Started = false;
639 BeforeCallbacks.emplace_back([this, &Info, AfterFlag = Info.StartAfter,
640 Count = 0u](StringRef ClassName) mutable {
641 if (Count == Info.StartInstanceNum) {
642 if (AfterFlag) {
643 AfterFlag = false;
644 Started = true;
645 }
646 return Started;
647 }
648
649 auto PassName = PIC->getPassNameForClassName(ClassName);
650 if (Info.StartPass == PassName && ++Count == Info.StartInstanceNum)
651 Started = !Info.StartAfter;
652
653 return Started;
654 });
655 }
656
657 if (!Info.StopPass.empty()) {
658 Stopped = false;
659 BeforeCallbacks.emplace_back([this, &Info, AfterFlag = Info.StopAfter,
660 Count = 0u](StringRef ClassName) mutable {
661 if (Count == Info.StopInstanceNum) {
662 if (AfterFlag) {
663 AfterFlag = false;
664 Stopped = true;
665 }
666 return !Stopped;
667 }
668
669 auto PassName = PIC->getPassNameForClassName(ClassName);
670 if (Info.StopPass == PassName && ++Count == Info.StopInstanceNum)
671 Stopped = !Info.StopAfter;
672 return !Stopped;
673 });
674 }
675}
676
677template <typename Derived, typename TargetMachineT>
678Error CodeGenPassBuilder<Derived, TargetMachineT>::verifyStartStop(
679 const TargetPassConfig::StartStopInfo &Info) const {
680 if (Started && Stopped)
681 return Error::success();
682
683 if (!Started)
685 "Can't find start pass \"" + Info.StartPass + "\".",
686 std::make_error_code(std::errc::invalid_argument));
687 if (!Stopped)
689 "Can't find stop pass \"" + Info.StopPass + "\".",
690 std::make_error_code(std::errc::invalid_argument));
691 return Error::success();
692}
693
694template <typename Derived, typename TargetMachineT>
696 PassManagerWrapper &PMW) const {
697 derived().addGlobalMergePass(PMW);
698 if (TM.useEmulatedTLS())
700
701 // ObjCARCContract operates on ObjC intrinsics and must run before
702 // PreISelIntrinsicLowering.
705 flushFPMsToMPM(PMW);
706 }
709
710 derived().addIRPasses(PMW);
711 derived().addCodeGenPrepare(PMW);
713 derived().addISelPrepare(PMW);
714}
715
716/// Add common target configurable passes that perform LLVM IR to IR transforms
717/// following machine independent optimization.
718template <typename Derived, typename TargetMachineT>
720 PassManagerWrapper &PMW) const {
721 // Before running any passes, run the verifier to determine if the input
722 // coming from the front-end and/or optimizer is valid.
723 if (!Opt.DisableVerify)
724 addFunctionPass(VerifierPass(), PMW, /*Force=*/true);
725
726 // Run loop strength reduction before anything else.
727 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableLSR) {
728 // These passes do not use MSSA.
729 LoopPassManager LPM;
730 LPM.addPass(CanonicalizeFreezeInLoopsPass());
731 LPM.addPass(LoopStrengthReducePass());
732 if (Opt.EnableLoopTermFold)
733 LPM.addPass(LoopTermFoldPass());
735 /*UseMemorySSA=*/false),
736 PMW);
737 }
738
740 // The MergeICmpsPass tries to create memcmp calls by grouping sequences of
741 // loads and compares. ExpandMemCmpPass then tries to expand those calls
742 // into optimally-sized loads and compares. The transforms are enabled by a
743 // target lowering hook.
744 if (!Opt.DisableMergeICmps)
747 }
748
749 // Run GC lowering passes for builtin collectors
750 // TODO: add a pass insertion point here
752 // Explicitly check to see if we should add ShadowStackGCLowering to avoid
753 // splitting the function pipeline if we do not have to.
754 if (runBeforeAdding(ShadowStackGCLoweringPass::name())) {
755 flushFPMsToMPM(PMW);
757 }
758
759 // Make sure that no unreachable blocks are instruction selected.
761
762 // Prepare expensive constants for SelectionDAG.
763 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableConstantHoisting)
765
766 // Replace calls to LLVM intrinsics (e.g., exp, log) operating on vector
767 // operands with calls to the corresponding functions in a vector library.
770
772 !Opt.DisablePartialLibcallInlining)
774
775 // Instrument function entry and exit, e.g. with calls to mcount().
776 addFunctionPass(EntryExitInstrumenterPass(/*PostInlining=*/true), PMW);
777
778 // Add scalarization of target's unsupported masked memory intrinsics pass.
779 // the unsupported intrinsic will be replaced with a chain of basic blocks,
780 // that stores/loads element one-by-one if the appropriate mask bit is set.
782
783 // Expand reduction intrinsics into shuffle sequences if the target wants to.
784 if (!Opt.DisableExpandReductions)
786
787 // Convert conditional moves to conditional jumps when profitable.
788 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableSelectOptimize)
790
791 if (Opt.EnableGlobalMergeFunc) {
792 flushFPMsToMPM(PMW);
794 }
795}
796
797/// Turn exception handling constructs into something the code generators can
798/// handle.
799template <typename Derived, typename TargetMachineT>
801 PassManagerWrapper &PMW) const {
802 const MCAsmInfo *MCAI = TM.getMCAsmInfo();
803 assert(MCAI && "No MCAsmInfo");
804 switch (MCAI->getExceptionHandlingType()) {
806 // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
807 // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
808 // catch info can get misplaced when a selector ends up more than one block
809 // removed from the parent invoke(s). This could happen when a landing
810 // pad is shared by multiple invokes and is also a target of a normal
811 // edge from elsewhere.
813 [[fallthrough]];
819 break;
821 // We support using both GCC-style and MSVC-style exceptions on Windows, so
822 // add both preparation passes. Each pass will only actually run if it
823 // recognizes the personality function.
826 break;
828 // Wasm EH uses Windows EH instructions, but it does not need to demote PHIs
829 // on catchpads and cleanuppads because it does not outline them into
830 // funclets. Catchswitch blocks are not lowered in SelectionDAG, so we
831 // should remove PHIs there.
832 addFunctionPass(WinEHPreparePass(/*DemoteCatchSwitchPHIOnly=*/false), PMW);
834 break;
837
838 // The lower invoke pass may create unreachable code. Remove it.
840 break;
841 }
842}
843
844/// Add pass to prepare the LLVM IR for code generation. This should be done
845/// before exception handling preparation passes.
846template <typename Derived, typename TargetMachineT>
848 PassManagerWrapper &PMW) const {
849 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableCGP)
851 // TODO: Default ctor'd RewriteSymbolPass is no-op.
852 // addPass(RewriteSymbolPass());
853}
854
855/// Add common passes that perform LLVM IR to IR transforms in preparation for
856/// instruction selection.
857template <typename Derived, typename TargetMachineT>
859 PassManagerWrapper &PMW) const {
860 derived().addPreISel(PMW);
861
862 if (Opt.RequiresCodeGenSCCOrder && !AddInCGSCCOrder)
864
866 // Add both the safe stack and the stack protection passes: each of them will
867 // only protect functions that have corresponding attributes.
870
871 if (Opt.PrintISelInput)
873 dbgs(), "\n\n*** Final LLVM Code input to ISel ***\n"),
874 PMW);
875
876 // All passes which modify the LLVM IR are now complete; run the verifier
877 // to ensure that the IR is valid.
878 if (!Opt.DisableVerify)
879 addFunctionPass(VerifierPass(), PMW, /*Force=*/true);
880}
881
882template <typename Derived, typename TargetMachineT>
884 PassManagerWrapper &PMW) const {
885 // Enable FastISel with -fast-isel, but allow that to be overridden.
886 TM.setO0WantsFastISel(Opt.EnableFastISelOption.value_or(true));
887
888 // Determine an instruction selector.
889 enum class SelectorType { SelectionDAG, FastISel, GlobalISel };
890 SelectorType Selector;
891
892 if (Opt.EnableFastISelOption && *Opt.EnableFastISelOption == true)
893 Selector = SelectorType::FastISel;
894 else if ((Opt.EnableGlobalISelOption &&
895 *Opt.EnableGlobalISelOption == true) ||
896 (TM.Options.EnableGlobalISel &&
897 (!Opt.EnableGlobalISelOption ||
898 *Opt.EnableGlobalISelOption == false)))
899 Selector = SelectorType::GlobalISel;
900 else if (TM.getOptLevel() == CodeGenOptLevel::None && TM.getO0WantsFastISel())
901 Selector = SelectorType::FastISel;
902 else
903 Selector = SelectorType::SelectionDAG;
904
905 // Set consistently TM.Options.EnableFastISel and EnableGlobalISel.
906 if (Selector == SelectorType::FastISel) {
907 TM.setFastISel(true);
908 TM.setGlobalISel(false);
909 } else if (Selector == SelectorType::GlobalISel) {
910 TM.setFastISel(false);
911 TM.setGlobalISel(true);
912 }
913
914 // Add instruction selector passes.
915 if (Selector == SelectorType::GlobalISel) {
916 if (auto Err = derived().addIRTranslator(PMW))
917 return std::move(Err);
918
919 derived().addPreLegalizeMachineIR(PMW);
920
921 if (auto Err = derived().addLegalizeMachineIR(PMW))
922 return std::move(Err);
923
924 // Before running the register bank selector, ask the target if it
925 // wants to run some passes.
926 derived().addPreRegBankSelect(PMW);
927
928 if (auto Err = derived().addRegBankSelect(PMW))
929 return std::move(Err);
930
931 derived().addPreGlobalInstructionSelect(PMW);
932
933 if (auto Err = derived().addGlobalInstructionSelect(PMW))
934 return std::move(Err);
935
936 // Pass to reset the MachineFunction if the ISel failed.
938 ResetMachineFunctionPass(reportDiagnosticWhenGlobalISelFallback(),
940 PMW);
941
942 // Provide a fallback path when we do not want to abort on
943 // not-yet-supported input.
945 if (auto Err = derived().addInstSelector(PMW))
946 return std::move(Err);
947
948 } else if (auto Err = derived().addInstSelector(PMW))
949 return std::move(Err);
950
951 // Expand pseudo-instructions emitted by ISel. Don't run the verifier before
952 // FinalizeISel.
954
955 // // Print the instruction selected machine code...
956 // printAndVerify("After Instruction Selection");
957
958 return Error::success();
959}
960
961/// Add the complete set of target-independent postISel code generator passes.
962///
963/// This can be read as the standard order of major LLVM CodeGen stages. Stages
964/// with nontrivial configuration or multiple passes are broken out below in
965/// add%Stage routines.
966///
967/// Any CodeGenPassBuilder<Derived, TargetMachine>::addXX routine may be
968/// overriden by the Target. The addPre/Post methods with empty header
969/// implementations allow injecting target-specific fixups just before or after
970/// major stages. Additionally, targets have the flexibility to change pass
971/// order within a stage by overriding default implementation of add%Stage
972/// routines below. Each technique has maintainability tradeoffs because
973/// alternate pass orders are not well supported. addPre/Post works better if
974/// the target pass is easily tied to a common pass. But if it has subtle
975/// dependencies on multiple passes, the target should override the stage
976/// instead.
977template <typename Derived, typename TargetMachineT>
979 PassManagerWrapper &PMW) const {
980 // Add passes that optimize machine instructions in SSA form.
982 derived().addMachineSSAOptimization(PMW);
983 } else {
984 // If the target requests it, assign local variables to stack slots relative
985 // to one another and simplify frame index references where possible.
987 }
988
989 if (TM.Options.EnableIPRA) {
990 flushFPMsToMPM(PMW);
992 PMW, /*Force=*/true);
994 }
995 // Run pre-ra passes.
996 derived().addPreRegAlloc(PMW);
997
998 // Run register allocation and passes that are tightly coupled with it,
999 // including phi elimination and scheduling.
1000 if (auto Err = *Opt.OptimizeRegAlloc ? derived().addOptimizedRegAlloc(PMW)
1001 : derived().addFastRegAlloc(PMW))
1002 return std::move(Err);
1003
1004 // Run post-ra passes.
1005 derived().addPostRegAlloc(PMW);
1006
1009
1010 // Insert prolog/epilog code. Eliminate abstract frame index references...
1014 }
1015
1017
1018 /// Add passes that optimize machine instructions after register allocation.
1020 derived().addMachineLateOptimization(PMW);
1021
1022 // Expand pseudo instructions before second scheduling pass.
1024
1025 // Run pre-sched2 passes.
1026 derived().addPreSched2(PMW);
1027
1028 if (Opt.EnableImplicitNullChecks)
1029 addMachineFunctionPass(ImplicitNullChecksPass(), PMW);
1030
1031 // Second pass scheduler.
1032 // Let Target optionally insert this pass by itself at some other
1033 // point.
1035 !TM.targetSchedulesPostRAScheduling()) {
1036 if (Opt.MISchedPostRA)
1038 else
1040 }
1041
1042 // GC
1043 derived().addGCPasses(PMW);
1044
1045 // Basic block placement.
1047 derived().addBlockPlacement(PMW);
1048
1049 // Insert before XRay Instrumentation.
1051
1054
1055 derived().addPreEmitPass(PMW);
1056
1057 if (TM.Options.EnableIPRA) {
1058 // Collect register usage information and produce a register mask of
1059 // clobbered registers, to be used to optimize call sites.
1061 // If -print-regusage is specified, print the collected register usage info.
1062 if (Opt.PrintRegUsage) {
1063 flushFPMsToMPM(PMW);
1065 }
1066 }
1067
1068 addMachineFunctionPass(FuncletLayoutPass(), PMW);
1069
1071 addMachineFunctionPass(StackMapLivenessPass(), PMW);
1074 getTM<TargetMachine>().Options.ShouldEmitDebugEntryValues()),
1075 PMW);
1077
1078 if (TM.Options.EnableMachineOutliner &&
1080 Opt.EnableMachineOutliner != RunOutliner::NeverOutline) {
1081 if (Opt.EnableMachineOutliner != RunOutliner::TargetDefault ||
1082 TM.Options.SupportsDefaultOutlining) {
1083 flushFPMsToMPM(PMW);
1084 addModulePass(MachineOutlinerPass(Opt.EnableMachineOutliner), PMW);
1085 }
1086 }
1087
1088 derived().addPostBBSections(PMW);
1089
1091
1092 // Add passes that directly emit MI after all other MI passes.
1093 derived().addPreEmitPass2(PMW);
1094
1095 return Error::success();
1096}
1097
1098/// Add passes that optimize machine instructions in SSA form.
1099template <typename Derived, typename TargetMachineT>
1101 PassManagerWrapper &PMW) const {
1102 // Pre-ra tail duplication.
1104
1105 // Optimize PHIs before DCE: removing dead PHI cycles may make more
1106 // instructions dead.
1108
1109 // This pass merges large allocas. StackSlotColoring is a different pass
1110 // which merges spill slots.
1112
1113 // If the target requests it, assign local variables to stack slots relative
1114 // to one another and simplify frame index references where possible.
1116
1117 // With optimization, dead code should already be eliminated. However
1118 // there is one known exception: lowered code for arguments that are only
1119 // used by tail calls, where the tail calls reuse the incoming stack
1120 // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
1122
1123 // Allow targets to insert passes that improve instruction level parallelism,
1124 // like if-conversion. Such passes will typically need dominator trees and
1125 // loop info, just like LICM and CSE below.
1126 derived().addILPOpts(PMW);
1127
1130
1131 addMachineFunctionPass(MachineSinkingPass(Opt.EnableSinkAndFold), PMW);
1132
1134 // Clean-up the dead code that may have been generated by peephole
1135 // rewriting.
1137}
1138
1139//===---------------------------------------------------------------------===//
1140/// Register Allocation Pass Configuration
1141//===---------------------------------------------------------------------===//
1142
1143/// Instantiate the default register allocator pass for this target for either
1144/// the optimized or unoptimized allocation path. This will be added to the pass
1145/// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
1146/// in the optimized case.
1147///
1148/// A target that uses the standard regalloc pass order for fast or optimized
1149/// allocation may still override this for per-target regalloc
1150/// selection. But -regalloc-npm=... always takes precedence.
1151/// If a target does not want to allow users to set -regalloc-npm=... at all,
1152/// check if Opt.RegAlloc == RegAllocType::Unset.
1153template <typename Derived, typename TargetMachineT>
1155 PassManagerWrapper &PMW, bool Optimized) const {
1156 if (Optimized)
1158 else
1160}
1161
1162/// Find and instantiate the register allocation pass requested by this target
1163/// at the current optimization level. Different register allocators are
1164/// defined as separate passes because they may require different analysis.
1165///
1166/// This helper ensures that the -regalloc-npm= option is always available,
1167/// even for targets that override the default allocator.
1168template <typename Derived, typename TargetMachineT>
1170 PassManagerWrapper &PMW, bool Optimized) const {
1171 // Use the specified -regalloc-npm={basic|greedy|fast|pbqp}
1172 if (Opt.RegAlloc > RegAllocType::Default) {
1173 switch (Opt.RegAlloc) {
1174 case RegAllocType::Fast:
1176 break;
1179 break;
1180 default:
1181 reportFatalUsageError("register allocator not supported yet");
1182 }
1183 return;
1184 }
1185 // -regalloc=default or unspecified, so pick based on the optimization level
1186 // or ask the target for the regalloc pass.
1187 derived().addTargetRegisterAllocator(PMW, Optimized);
1188}
1189
1190template <typename Derived, typename TargetMachineT>
1192 PassManagerWrapper &PMW) const {
1193 // TODO: Ensure allocator is default or fast.
1194 addRegAllocPass(PMW, false);
1195 return Error::success();
1196}
1197
1198template <typename Derived, typename TargetMachineT>
1200 PassManagerWrapper &PMW) const {
1201 // Add the selected register allocation pass.
1202 addRegAllocPass(PMW, true);
1203
1204 // Allow targets to change the register assignments before rewriting.
1205 derived().addPreRewrite(PMW);
1206
1207 // Finally rewrite virtual registers.
1209 // Perform stack slot coloring and post-ra machine LICM.
1210 //
1211 // FIXME: Re-enable coloring with register when it's capable of adding
1212 // kill markers.
1214
1215 return Error::success();
1216}
1217
1218/// Add the minimum set of target-independent passes that are required for
1219/// register allocation. No coalescing or scheduling.
1220template <typename Derived, typename TargetMachineT>
1227
1228/// Add standard target-independent passes that are tightly coupled with
1229/// optimized register allocation, including coalescing, machine instruction
1230/// scheduling, and register allocation itself.
1231template <typename Derived, typename TargetMachineT>
1233 PassManagerWrapper &PMW) const {
1235
1237
1239
1240 // LiveVariables currently requires pure SSA form.
1241 //
1242 // FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
1243 // LiveVariables can be removed completely, and LiveIntervals can be directly
1244 // computed. (We still either need to regenerate kill flags after regalloc, or
1245 // preferably fix the scavenger to not depend on them).
1246 // FIXME: UnreachableMachineBlockElim is a dependant pass of LiveVariables.
1247 // When LiveVariables is removed this has to be removed/moved either.
1248 // Explicit addition of UnreachableMachineBlockElim allows stopping before or
1249 // after it with -stop-before/-stop-after.
1253
1254 // Edge splitting is smarter with machine loop info.
1258
1259 // Eventually, we want to run LiveIntervals before PHI elimination.
1260 if (Opt.EarlyLiveIntervals)
1263
1266
1267 // The machine scheduler may accidentally create disconnected components
1268 // when moving subregister definitions around, avoid this by splitting them to
1269 // separate vregs before. Splitting can also improve reg. allocation quality.
1271
1272 // PreRA instruction scheduling.
1274
1275 if (auto E = derived().addRegAssignmentOptimized(PMW))
1276 return std::move(E);
1277
1279
1280 // Allow targets to expand pseudo instructions depending on the choice of
1281 // registers before MachineCopyPropagation.
1282 derived().addPostRewrite(PMW);
1283
1284 // Copy propagate to forward register uses and try to eliminate COPYs that
1285 // were not coalesced.
1287
1288 // Run post-ra machine LICM to hoist reloads / remats.
1289 //
1290 // FIXME: can this move into MachineLateOptimization?
1292
1293 return Error::success();
1294}
1295
1296//===---------------------------------------------------------------------===//
1297/// Post RegAlloc Pass Configuration
1298//===---------------------------------------------------------------------===//
1299
1300/// Add passes that optimize machine instructions after register allocation.
1301template <typename Derived, typename TargetMachineT>
1303 PassManagerWrapper &PMW) const {
1304 // Cleanup of redundant (identical) address/immediate loads.
1306
1307 // Branch folding must be run after regalloc and prolog/epilog insertion.
1308 addMachineFunctionPass(BranchFolderPass(Opt.EnableTailMerge), PMW);
1309
1310 // Tail duplication.
1311 // Note that duplicating tail just increases code size and degrades
1312 // performance for targets that require Structured Control Flow.
1313 // In addition it can also make CFG irreducible. Thus we disable it.
1314 if (!TM.requiresStructuredCFG())
1316
1317 // Copy propagation.
1319}
1320
1321/// Add standard basic block placement passes.
1322template <typename Derived, typename TargetMachineT>
1324 PassManagerWrapper &PMW) const {
1326 // Run a separate pass to collect block placement statistics.
1327 if (Opt.EnableBlockPlacementStats)
1329}
1330
1331} // namespace llvm
1332
1333#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.
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.
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 addAsmPrinterEnd(PassManagerWrapper &PMW, CreateMCStreamer CreateStreamer) const
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 addAsmPrinterBegin(PassManagerWrapper &PMW, CreateMCStreamer CreateStreamer) const
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 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 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...
Error buildPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, MCContext &Ctx) 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.
void addAsmPrinter(PassManagerWrapper &PMW, CreateMCStreamer CreateStreamer) const
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.
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
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:636
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
Primary interface to the complete machine description for the target machine.
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
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.
std::function< Expected< std::unique_ptr< MCStreamer > >(TargetMachine &)> CreateMCStreamer
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.
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.