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 if (Opt.OptimizeRegAlloc == cl::boolOrDefault::BOU_UNSET)
198 Opt.OptimizeRegAlloc = getOptLevel() != CodeGenOptLevel::None
201 }
202
205 CodeGenFileType FileType, MCContext &Ctx) const;
206
210
211protected:
212 template <typename PassT>
213 using is_module_pass_t = decltype(std::declval<PassT &>().run(
214 std::declval<Module &>(), std::declval<ModuleAnalysisManager &>()));
215
216 template <typename PassT>
217 using is_function_pass_t = decltype(std::declval<PassT &>().run(
218 std::declval<Function &>(), std::declval<FunctionAnalysisManager &>()));
219
220 template <typename PassT>
221 using is_machine_function_pass_t = decltype(std::declval<PassT &>().run(
222 std::declval<MachineFunction &>(),
223 std::declval<MachineFunctionAnalysisManager &>()));
224
225 template <typename PassT>
227 bool Force = false,
228 StringRef Name = PassT::name()) const {
230 "Only function passes are supported.");
231 if (!Force && !runBeforeAdding(Name))
232 return;
233 PMW.FPM.addPass(std::forward<PassT>(Pass));
234 }
235
236 template <typename PassT>
237 void addModulePass(PassT &&Pass, PassManagerWrapper &PMW, bool Force = false,
238 StringRef Name = PassT::name()) const {
240 "Only module passes are suported.");
241 assert(PMW.FPM.isEmpty() && PMW.MFPM.isEmpty() &&
242 "You cannot insert a module pass without first flushing the current "
243 "function pipelines to the module pipeline.");
244 if (!Force && !runBeforeAdding(Name))
245 return;
246 PMW.MPM.addPass(std::forward<PassT>(Pass));
247 }
248
249 template <typename PassT>
251 bool Force = false,
252 StringRef Name = PassT::name()) const {
254 "Only machine function passes are supported.");
255
256 if (!Force && !runBeforeAdding(Name))
257 return;
258 PMW.MFPM.addPass(std::forward<PassT>(Pass));
259 for (auto &C : AfterCallbacks)
260 C(Name, PMW.MFPM);
261 }
262
264 bool FreeMachineFunctions = false) const {
265 if (PMW.FPM.isEmpty() && PMW.MFPM.isEmpty())
266 return;
267 if (!PMW.MFPM.isEmpty()) {
268 PMW.FPM.addPass(
269 createFunctionToMachineFunctionPassAdaptor(std::move(PMW.MFPM)));
270 PMW.MFPM = MachineFunctionPassManager();
271 }
272 if (FreeMachineFunctions)
274 if (AddInCGSCCOrder) {
276 createCGSCCToFunctionPassAdaptor(std::move(PMW.FPM))));
277 } else {
278 PMW.MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PMW.FPM)));
279 }
280 PMW.FPM = FunctionPassManager();
281 }
282
284 assert(!AddInCGSCCOrder);
285 assert(PMW.FPM.isEmpty() && PMW.MFPM.isEmpty() &&
286 "Requiring CGSCC ordering requires flushing the current function "
287 "pipelines to the MPM.");
288 AddInCGSCCOrder = true;
289 }
290
292 assert(AddInCGSCCOrder);
293 assert(PMW.FPM.isEmpty() && PMW.MFPM.isEmpty() &&
294 "Stopping CGSCC ordering requires flushing the current function "
295 "pipelines to the MPM.");
296 AddInCGSCCOrder = false;
297 }
298
299 TargetMachineT &TM;
302
303 template <typename TMC> TMC &getTM() const { return static_cast<TMC &>(TM); }
304 CodeGenOptLevel getOptLevel() const { return TM.getOptLevel(); }
305
306 /// Check whether or not GlobalISel should abort on error.
307 /// When this is disabled, GlobalISel will fall back on SDISel instead of
308 /// erroring out.
310 return TM.Options.GlobalISelAbort == GlobalISelAbortMode::Enable;
311 }
312
313 /// Check whether or not a diagnostic should be emitted when GlobalISel
314 /// uses the fallback path. In other words, it will emit a diagnostic
315 /// when GlobalISel failed and isGlobalISelAbortEnabled is false.
317 return TM.Options.GlobalISelAbort == GlobalISelAbortMode::DisableWithDiag;
318 }
319
320 /// addInstSelector - This method should install an instruction selector pass,
321 /// which converts from LLVM code to machine instructions.
323 return make_error<StringError>("addInstSelector is not overridden",
325 }
326
327 /// Target can override this to add GlobalMergePass before all IR passes.
329
330 /// Add passes that optimize instruction level parallelism for out-of-order
331 /// targets. These passes are run while the machine code is still in SSA
332 /// form, so they can use MachineTraceMetrics to control their heuristics.
333 ///
334 /// All passes added here should preserve the MachineDominatorTree,
335 /// MachineLoopInfo, and MachineTraceMetrics analyses.
336 void addILPOpts(PassManagerWrapper &PMW) const {}
337
338 /// This method may be implemented by targets that want to run passes
339 /// immediately before register allocation.
341
342 /// addPreRewrite - Add passes to the optimized register allocation pipeline
343 /// after register allocation is complete, but before virtual registers are
344 /// rewritten to physical registers.
345 ///
346 /// These passes must preserve VirtRegMap and LiveIntervals, and when running
347 /// after RABasic or RAGreedy, they should take advantage of LiveRegMatrix.
348 /// When these passes run, VirtRegMap contains legal physreg assignments for
349 /// all virtual registers.
350 ///
351 /// Note if the target overloads addRegAssignAndRewriteOptimized, this may not
352 /// be honored. This is also not generally used for the fast variant,
353 /// where the allocation and rewriting are done in one pass.
355
356 /// Add passes to be run immediately after virtual registers are rewritten
357 /// to physical registers.
359
360 /// This method may be implemented by targets that want to run passes after
361 /// register allocation pass pipeline but before prolog-epilog insertion.
363
364 /// This method may be implemented by targets that want to run passes after
365 /// prolog-epilog insertion and before the second instruction scheduling pass.
367
368 /// This pass may be implemented by targets that want to run passes
369 /// immediately before machine code is emitted.
371
372 /// Targets may add passes immediately before machine code is emitted in this
373 /// callback. This is called even later than `addPreEmitPass`.
374 // FIXME: Rename `addPreEmitPass` to something more sensible given its actual
375 // position and remove the `2` suffix here as this callback is what
376 // `addPreEmitPass` *should* be but in reality isn't.
378
379 /// {{@ For GlobalISel
380 ///
381
382 /// addPreISel - This method should add any "last minute" LLVM->LLVM
383 /// passes (which are run just before instruction selector).
384 void addPreISel(PassManagerWrapper &PMW) const {}
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 llvm_unreachable("addAsmPrinterBegin is not overriden");
495 }
496
498 llvm_unreachable("addAsmPrinter is not overridden");
499 }
500
502 llvm_unreachable("addAsmPrinterEnd is not overriden");
503 }
504
505 /// Utilities for targets to add passes to the pass manager.
506 ///
507
508 /// createTargetRegisterAllocator - Create the register allocator pass for
509 /// this target at the current optimization level.
511 bool Optimized) const;
512
513 /// addMachinePasses helper to create the target-selected or overriden
514 /// regalloc pass.
515 void addRegAllocPass(PassManagerWrapper &PMW, bool Optimized) const;
516
517 /// Add core register allocator passes which do the actual register assignment
518 /// and rewriting. addRegAssignAndRewriteOptimized should return true if any
519 /// passes were added.
522
523 /// Allow the target to disable a specific pass by default.
524 /// Backend can declare unwanted passes in constructor.
525 template <typename... PassTs> void disablePass() {
526 BeforeCallbacks.emplace_back(
527 [](StringRef Name) { return ((Name != PassTs::name()) && ...); });
528 }
529
530 /// Insert InsertedPass pass after TargetPass pass.
531 /// Only machine function passes are supported.
532 template <typename TargetPassT, typename InsertedPassT>
533 void insertPass(InsertedPassT &&Pass) const {
534 AfterCallbacks.emplace_back(
535 [&](StringRef Name, MachineFunctionPassManager &MFPM) mutable {
536 if (Name == TargetPassT::name() &&
537 runBeforeAdding(InsertedPassT::name())) {
538 MFPM.addPass(std::forward<InsertedPassT>(Pass));
539 }
540 });
541 }
542
543private:
544 DerivedT &derived() { return static_cast<DerivedT &>(*this); }
545 const DerivedT &derived() const {
546 return static_cast<const DerivedT &>(*this);
547 }
548
549 bool runBeforeAdding(StringRef Name) const {
550 bool ShouldAdd = true;
551 for (auto &C : BeforeCallbacks)
552 ShouldAdd &= C(Name);
553 return ShouldAdd;
554 }
555
556 void setStartStopPasses(const TargetPassConfig::StartStopInfo &Info) const;
557
558 Error verifyStartStop(const TargetPassConfig::StartStopInfo &Info) const;
559
560 mutable SmallVector<llvm::unique_function<bool(StringRef)>, 4>
561 BeforeCallbacks;
562 mutable SmallVector<
563 llvm::unique_function<void(StringRef, MachineFunctionPassManager &)>, 4>
564 AfterCallbacks;
565
566 /// Helper variable for `-start-before/-start-after/-stop-before/-stop-after`
567 mutable bool Started = true;
568 mutable bool Stopped = true;
569 mutable bool AddInCGSCCOrder = false;
570};
571
572template <typename Derived, typename TargetMachineT>
575 raw_pwrite_stream *DwoOut, CodeGenFileType FileType, MCContext &Ctx) const {
576 auto StartStopInfo = TargetPassConfig::getStartStopInfo(*PIC);
577 if (!StartStopInfo)
578 return StartStopInfo.takeError();
579 setStartStopPasses(*StartStopInfo);
580
582 bool PrintMIR = !PrintAsm && FileType != CodeGenFileType::Null;
583
584 PassManagerWrapper PMW(MPM);
585
587 /*Force=*/true);
589 /*Force=*/true);
591 /*Force=*/true);
593 /*Force=*/true);
595 PMW,
596 /*Force=*/true);
597 addISelPasses(PMW);
598 flushFPMsToMPM(PMW);
599
600 if (PrintAsm) {
601 Expected<std::unique_ptr<MCStreamer>> MCStreamerOrErr =
602 TM.createMCStreamer(Out, DwoOut, FileType, Ctx);
603 if (!MCStreamerOrErr)
604 return MCStreamerOrErr.takeError();
605 std::unique_ptr<AsmPrinter> Printer(
606 TM.getTarget().createAsmPrinter(TM, std::move(*MCStreamerOrErr)));
607 if (!Printer)
608 return createStringError("failed to create AsmPrinter");
609 MAM.registerPass([&] { return AsmPrinterAnalysis(std::move(Printer)); });
610 derived().addAsmPrinterBegin(PMW);
611 }
612
613 if (PrintMIR)
614 addModulePass(PrintMIRPreparePass(Out), PMW, /*Force=*/true);
615
616 if (auto Err = addCoreISelPasses(PMW))
617 return std::move(Err);
618
619 if (auto Err = derived().addMachinePasses(PMW))
620 return std::move(Err);
621
622 if (!Opt.DisableVerify && TM.Options.EnableDefaultMachineVerifier)
624
625 if (PrintAsm) {
626 derived().addAsmPrinter(PMW);
627 flushFPMsToMPM(PMW, /*FreeMachineFunctions=*/true);
628 derived().addAsmPrinterEnd(PMW);
629 } else {
630 if (PrintMIR)
631 addMachineFunctionPass(PrintMIRPass(Out), PMW, /*Force=*/true);
632 flushFPMsToMPM(PMW, /*FreeMachineFunctions=*/true);
633 }
634
635 return verifyStartStop(*StartStopInfo);
636}
637
638template <typename Derived, typename TargetMachineT>
639void CodeGenPassBuilder<Derived, TargetMachineT>::setStartStopPasses(
640 const TargetPassConfig::StartStopInfo &Info) const {
641 if (!Info.StartPass.empty()) {
642 Started = false;
643 BeforeCallbacks.emplace_back([this, &Info, AfterFlag = Info.StartAfter,
644 Count = 0u](StringRef ClassName) mutable {
645 if (Count == Info.StartInstanceNum) {
646 if (AfterFlag) {
647 AfterFlag = false;
648 Started = true;
649 }
650 return Started;
651 }
652
653 auto PassName = PIC->getPassNameForClassName(ClassName);
654 if (Info.StartPass == PassName && ++Count == Info.StartInstanceNum)
655 Started = !Info.StartAfter;
656
657 return Started;
658 });
659 }
660
661 if (!Info.StopPass.empty()) {
662 Stopped = false;
663 BeforeCallbacks.emplace_back([this, &Info, AfterFlag = Info.StopAfter,
664 Count = 0u](StringRef ClassName) mutable {
665 if (Count == Info.StopInstanceNum) {
666 if (AfterFlag) {
667 AfterFlag = false;
668 Stopped = true;
669 }
670 return !Stopped;
671 }
672
673 auto PassName = PIC->getPassNameForClassName(ClassName);
674 if (Info.StopPass == PassName && ++Count == Info.StopInstanceNum)
675 Stopped = !Info.StopAfter;
676 return !Stopped;
677 });
678 }
679}
680
681template <typename Derived, typename TargetMachineT>
682Error CodeGenPassBuilder<Derived, TargetMachineT>::verifyStartStop(
683 const TargetPassConfig::StartStopInfo &Info) const {
684 if (Started && Stopped)
685 return Error::success();
686
687 if (!Started)
689 "Can't find start pass \"" + Info.StartPass + "\".",
690 std::make_error_code(std::errc::invalid_argument));
691 if (!Stopped)
693 "Can't find stop pass \"" + Info.StopPass + "\".",
694 std::make_error_code(std::errc::invalid_argument));
695 return Error::success();
696}
697
698template <typename Derived, typename TargetMachineT>
700 PassManagerWrapper &PMW) const {
701 derived().addGlobalMergePass(PMW);
702 if (TM.useEmulatedTLS())
704
705 // ObjCARCContract operates on ObjC intrinsics and must run before
706 // PreISelIntrinsicLowering.
709 flushFPMsToMPM(PMW);
710 }
713
714 derived().addIRPasses(PMW);
715 derived().addCodeGenPrepare(PMW);
717 derived().addISelPrepare(PMW);
718}
719
720/// Add common target configurable passes that perform LLVM IR to IR transforms
721/// following machine independent optimization.
722template <typename Derived, typename TargetMachineT>
724 PassManagerWrapper &PMW) const {
725 // Before running any passes, run the verifier to determine if the input
726 // coming from the front-end and/or optimizer is valid.
727 if (!Opt.DisableVerify)
728 addFunctionPass(VerifierPass(), PMW, /*Force=*/true);
729
730 // Run loop strength reduction before anything else.
731 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableLSR) {
732 // These passes do not use MSSA.
733 LoopPassManager LPM;
734 LPM.addPass(CanonicalizeFreezeInLoopsPass());
735 LPM.addPass(LoopStrengthReducePass());
736 if (Opt.EnableLoopTermFold)
737 LPM.addPass(LoopTermFoldPass());
739 /*UseMemorySSA=*/false),
740 PMW);
741 }
742
743 // Run GC lowering passes for builtin collectors
744 // TODO: add a pass insertion point here
746 // Explicitly check to see if we should add ShadowStackGCLowering to avoid
747 // splitting the function pipeline if we do not have to.
748 if (runBeforeAdding(ShadowStackGCLoweringPass::name())) {
749 flushFPMsToMPM(PMW);
751 }
752
753 // Make sure that no unreachable blocks are instruction selected.
755
756 // Prepare expensive constants for SelectionDAG.
757 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableConstantHoisting)
759
760 // Replace calls to LLVM intrinsics (e.g., exp, log) operating on vector
761 // operands with calls to the corresponding functions in a vector library.
764
766 !Opt.DisablePartialLibcallInlining)
768
769 // Instrument function entry and exit, e.g. with calls to mcount().
770 addFunctionPass(EntryExitInstrumenterPass(/*PostInlining=*/true), PMW);
771
772 // Add scalarization of target's unsupported masked memory intrinsics pass.
773 // the unsupported intrinsic will be replaced with a chain of basic blocks,
774 // that stores/loads element one-by-one if the appropriate mask bit is set.
776
777 // Expand reduction intrinsics into shuffle sequences if the target wants to.
778 if (!Opt.DisableExpandReductions)
780
781 // Convert conditional moves to conditional jumps when profitable.
782 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableSelectOptimize)
784
785 if (Opt.EnableGlobalMergeFunc) {
786 flushFPMsToMPM(PMW);
788 }
789}
790
791/// Turn exception handling constructs into something the code generators can
792/// handle.
793template <typename Derived, typename TargetMachineT>
795 PassManagerWrapper &PMW) const {
796 const MCAsmInfo &MCAI = TM.getMCAsmInfo();
797 switch (MCAI.getExceptionHandlingType()) {
799 // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
800 // Dwarf EH prepare needs to be run after SjLj prepare. Otherwise,
801 // catch info can get misplaced when a selector ends up more than one block
802 // removed from the parent invoke(s). This could happen when a landing
803 // pad is shared by multiple invokes and is also a target of a normal
804 // edge from elsewhere.
806 [[fallthrough]];
812 break;
814 // We support using both GCC-style and MSVC-style exceptions on Windows, so
815 // add both preparation passes. Each pass will only actually run if it
816 // recognizes the personality function.
819 break;
821 // Wasm EH uses Windows EH instructions, but it does not need to demote PHIs
822 // on catchpads and cleanuppads because it does not outline them into
823 // funclets. Catchswitch blocks are not lowered in SelectionDAG, so we
824 // should remove PHIs there.
825 addFunctionPass(WinEHPreparePass(/*DemoteCatchSwitchPHIOnly=*/false), PMW);
827 break;
830
831 // The lower invoke pass may create unreachable code. Remove it.
833 break;
834 }
835}
836
837/// Add pass to prepare the LLVM IR for code generation. This should be done
838/// before exception handling preparation passes.
839template <typename Derived, typename TargetMachineT>
841 PassManagerWrapper &PMW) const {
842 if (getOptLevel() != CodeGenOptLevel::None && !Opt.DisableCGP)
844 // TODO: Default ctor'd RewriteSymbolPass is no-op.
845 // addPass(RewriteSymbolPass());
846}
847
848/// Add common passes that perform LLVM IR to IR transforms in preparation for
849/// instruction selection.
850template <typename Derived, typename TargetMachineT>
852 PassManagerWrapper &PMW) const {
853 derived().addPreISel(PMW);
854
855 if (Opt.RequiresCodeGenSCCOrder && !AddInCGSCCOrder)
857
859 // Add both the safe stack and the stack protection passes: each of them will
860 // only protect functions that have corresponding attributes.
863
864 if (Opt.PrintISelInput)
866 dbgs(), "\n\n*** Final LLVM Code input to ISel ***\n"),
867 PMW);
868
869 // All passes which modify the LLVM IR are now complete; run the verifier
870 // to ensure that the IR is valid.
871 if (!Opt.DisableVerify)
872 addFunctionPass(VerifierPass(), PMW, /*Force=*/true);
873}
874
875template <typename Derived, typename TargetMachineT>
877 PassManagerWrapper &PMW) const {
878 // Enable FastISel with -fast-isel, but allow that to be overridden.
879 TM.setO0WantsFastISel(Opt.EnableFastISelOption !=
881
882 // Determine an instruction selector.
883 enum class SelectorType { SelectionDAG, FastISel, GlobalISel };
884 SelectorType Selector;
885
886 if (Opt.EnableFastISelOption == cl::boolOrDefault::BOU_TRUE)
887 Selector = SelectorType::FastISel;
888 else if (Opt.EnableGlobalISelOption == cl::boolOrDefault::BOU_TRUE ||
889 (TM.Options.EnableGlobalISel &&
890 Opt.EnableGlobalISelOption != cl::boolOrDefault::BOU_FALSE))
891 Selector = SelectorType::GlobalISel;
892 else if (TM.getOptLevel() == CodeGenOptLevel::None && TM.getO0WantsFastISel())
893 Selector = SelectorType::FastISel;
894 else
895 Selector = SelectorType::SelectionDAG;
896
897 // Set consistently TM.Options.EnableFastISel and EnableGlobalISel.
898 if (Selector == SelectorType::FastISel) {
899 TM.setFastISel(true);
900 TM.setGlobalISel(false);
901 } else if (Selector == SelectorType::GlobalISel) {
902 TM.setFastISel(false);
903 TM.setGlobalISel(true);
904 }
905
906 // Add instruction selector passes.
907 if (Selector == SelectorType::GlobalISel) {
908 if (auto Err = derived().addIRTranslator(PMW))
909 return std::move(Err);
910
911 derived().addPreLegalizeMachineIR(PMW);
912
913 if (auto Err = derived().addLegalizeMachineIR(PMW))
914 return std::move(Err);
915
916 // Before running the register bank selector, ask the target if it
917 // wants to run some passes.
918 derived().addPreRegBankSelect(PMW);
919
920 if (auto Err = derived().addRegBankSelect(PMW))
921 return std::move(Err);
922
923 derived().addPreGlobalInstructionSelect(PMW);
924
925 if (auto Err = derived().addGlobalInstructionSelect(PMW))
926 return std::move(Err);
927
928 // Pass to reset the MachineFunction if the ISel failed.
930 ResetMachineFunctionPass(reportDiagnosticWhenGlobalISelFallback(),
932 PMW);
933
934 // Provide a fallback path when we do not want to abort on
935 // not-yet-supported input.
937 if (auto Err = derived().addInstSelector(PMW))
938 return std::move(Err);
939
940 } else if (auto Err = derived().addInstSelector(PMW))
941 return std::move(Err);
942
943 // Expand pseudo-instructions emitted by ISel. Don't run the verifier before
944 // FinalizeISel.
946
947 // // Print the instruction selected machine code...
948 // printAndVerify("After Instruction Selection");
949
950 return Error::success();
951}
952
953/// Add the complete set of target-independent postISel code generator passes.
954///
955/// This can be read as the standard order of major LLVM CodeGen stages. Stages
956/// with nontrivial configuration or multiple passes are broken out below in
957/// add%Stage routines.
958///
959/// Any CodeGenPassBuilder<Derived, TargetMachine>::addXX routine may be
960/// overriden by the Target. The addPre/Post methods with empty header
961/// implementations allow injecting target-specific fixups just before or after
962/// major stages. Additionally, targets have the flexibility to change pass
963/// order within a stage by overriding default implementation of add%Stage
964/// routines below. Each technique has maintainability tradeoffs because
965/// alternate pass orders are not well supported. addPre/Post works better if
966/// the target pass is easily tied to a common pass. But if it has subtle
967/// dependencies on multiple passes, the target should override the stage
968/// instead.
969template <typename Derived, typename TargetMachineT>
971 PassManagerWrapper &PMW) const {
972 // Add passes that optimize machine instructions in SSA form.
974 derived().addMachineSSAOptimization(PMW);
975 } else {
976 // If the target requests it, assign local variables to stack slots relative
977 // to one another and simplify frame index references where possible.
979 }
980
981 if (TM.Options.EnableIPRA) {
982 flushFPMsToMPM(PMW);
984 PMW, /*Force=*/true);
986 }
987 // Run pre-ra passes.
988 derived().addPreRegAlloc(PMW);
989
990 // Run register allocation and passes that are tightly coupled with it,
991 // including phi elimination and scheduling.
992 if (auto Err = Opt.OptimizeRegAlloc == cl::boolOrDefault::BOU_TRUE
993 ? derived().addOptimizedRegAlloc(PMW)
994 : derived().addFastRegAlloc(PMW))
995 return std::move(Err);
996
997 // Run post-ra passes.
998 derived().addPostRegAlloc(PMW);
999
1002
1003 // Insert prolog/epilog code. Eliminate abstract frame index references...
1007 }
1008
1010
1011 /// Add passes that optimize machine instructions after register allocation.
1013 derived().addMachineLateOptimization(PMW);
1014
1015 // Expand pseudo instructions before second scheduling pass.
1017
1018 // Run pre-sched2 passes.
1019 derived().addPreSched2(PMW);
1020
1021 if (Opt.EnableImplicitNullChecks)
1022 addMachineFunctionPass(ImplicitNullChecksPass(), PMW);
1023
1024 // Second pass scheduler.
1025 // Let Target optionally insert this pass by itself at some other
1026 // point.
1028 !TM.targetSchedulesPostRAScheduling()) {
1029 if (Opt.MISchedPostRA)
1031 else
1033 }
1034
1035 // GC
1036 derived().addGCPasses(PMW);
1037
1038 // Basic block placement.
1040 derived().addBlockPlacement(PMW);
1041
1042 // Insert before XRay Instrumentation.
1044
1047
1048 derived().addPreEmitPass(PMW);
1049
1050 if (TM.Options.EnableIPRA) {
1051 // Collect register usage information and produce a register mask of
1052 // clobbered registers, to be used to optimize call sites.
1054 // If -print-regusage is specified, print the collected register usage info.
1055 if (Opt.PrintRegUsage) {
1056 flushFPMsToMPM(PMW);
1058 }
1059 }
1060
1061 addMachineFunctionPass(FuncletLayoutPass(), PMW);
1062
1064 addMachineFunctionPass(StackMapLivenessPass(), PMW);
1067 getTM<TargetMachine>().Options.ShouldEmitDebugEntryValues()),
1068 PMW);
1070
1071 if (TM.Options.EnableMachineOutliner &&
1073 Opt.EnableMachineOutliner != RunOutliner::NeverOutline) {
1074 if (Opt.EnableMachineOutliner != RunOutliner::TargetDefault ||
1075 TM.Options.SupportsDefaultOutlining) {
1076 flushFPMsToMPM(PMW);
1077 addModulePass(MachineOutlinerPass(Opt.EnableMachineOutliner), PMW);
1078 }
1079 }
1080
1081 if (Opt.EnableGCEmptyBlocks)
1083
1084 derived().addPostBBSections(PMW);
1085
1087
1088 // Add passes that directly emit MI after all other MI passes.
1089 derived().addPreEmitPass2(PMW);
1090
1091 return Error::success();
1092}
1093
1094/// Add passes that optimize machine instructions in SSA form.
1095template <typename Derived, typename TargetMachineT>
1097 PassManagerWrapper &PMW) const {
1098 // Pre-ra tail duplication.
1100
1101 // Optimize PHIs before DCE: removing dead PHI cycles may make more
1102 // instructions dead.
1104
1105 // This pass merges large allocas. StackSlotColoring is a different pass
1106 // which merges spill slots.
1108
1109 // If the target requests it, assign local variables to stack slots relative
1110 // to one another and simplify frame index references where possible.
1112
1113 // With optimization, dead code should already be eliminated. However
1114 // there is one known exception: lowered code for arguments that are only
1115 // used by tail calls, where the tail calls reuse the incoming stack
1116 // arguments directly (see t11 in test/CodeGen/X86/sibcall.ll).
1118
1119 // Allow targets to insert passes that improve instruction level parallelism,
1120 // like if-conversion. Such passes will typically need dominator trees and
1121 // loop info, just like LICM and CSE below.
1122 derived().addILPOpts(PMW);
1123
1126
1127 addMachineFunctionPass(MachineSinkingPass(Opt.EnableSinkAndFold), PMW);
1128
1130 // Clean-up the dead code that may have been generated by peephole
1131 // rewriting.
1133}
1134
1135//===---------------------------------------------------------------------===//
1136/// Register Allocation Pass Configuration
1137//===---------------------------------------------------------------------===//
1138
1139/// Instantiate the default register allocator pass for this target for either
1140/// the optimized or unoptimized allocation path. This will be added to the pass
1141/// manager by addFastRegAlloc in the unoptimized case or addOptimizedRegAlloc
1142/// in the optimized case.
1143///
1144/// A target that uses the standard regalloc pass order for fast or optimized
1145/// allocation may still override this for per-target regalloc
1146/// selection. But -regalloc-npm=... always takes precedence.
1147/// If a target does not want to allow users to set -regalloc-npm=... at all,
1148/// check if Opt.RegAlloc == RegAllocType::Unset.
1149template <typename Derived, typename TargetMachineT>
1151 PassManagerWrapper &PMW, bool Optimized) const {
1152 if (Optimized)
1154 else
1156}
1157
1158/// Find and instantiate the register allocation pass requested by this target
1159/// at the current optimization level. Different register allocators are
1160/// defined as separate passes because they may require different analysis.
1161///
1162/// This helper ensures that the -regalloc-npm= option is always available,
1163/// even for targets that override the default allocator.
1164template <typename Derived, typename TargetMachineT>
1166 PassManagerWrapper &PMW, bool Optimized) const {
1167 // Use the specified -regalloc-npm={basic|greedy|fast|pbqp}
1168 if (Opt.RegAlloc > RegAllocType::Default) {
1169 switch (Opt.RegAlloc) {
1170 case RegAllocType::Fast:
1172 break;
1175 break;
1176 default:
1177 reportFatalUsageError("register allocator not supported yet");
1178 }
1179 return;
1180 }
1181 // -regalloc=default or unspecified, so pick based on the optimization level
1182 // or ask the target for the regalloc pass.
1183 derived().addTargetRegisterAllocator(PMW, Optimized);
1184}
1185
1186template <typename Derived, typename TargetMachineT>
1188 PassManagerWrapper &PMW) const {
1189 // TODO: Ensure allocator is default or fast.
1190 addRegAllocPass(PMW, false);
1191 return Error::success();
1192}
1193
1194template <typename Derived, typename TargetMachineT>
1197 PassManagerWrapper &PMW) const {
1198 // Add the selected register allocation pass.
1199 addRegAllocPass(PMW, true);
1200
1201 // Allow targets to change the register assignments before rewriting.
1202 derived().addPreRewrite(PMW);
1203
1204 // Finally rewrite virtual registers.
1206
1207 return true;
1208}
1209
1210/// Add the minimum set of target-independent passes that are required for
1211/// register allocation. No coalescing or scheduling.
1212template <typename Derived, typename TargetMachineT>
1219
1220/// Add standard target-independent passes that are tightly coupled with
1221/// optimized register allocation, including coalescing, machine instruction
1222/// scheduling, and register allocation itself.
1223template <typename Derived, typename TargetMachineT>
1225 PassManagerWrapper &PMW) const {
1227
1229
1231
1232 // LiveVariables currently requires pure SSA form.
1233 //
1234 // FIXME: Once TwoAddressInstruction pass no longer uses kill flags,
1235 // LiveVariables can be removed completely, and LiveIntervals can be directly
1236 // computed. (We still either need to regenerate kill flags after regalloc, or
1237 // preferably fix the scavenger to not depend on them).
1238 // FIXME: UnreachableMachineBlockElim is a dependant pass of LiveVariables.
1239 // When LiveVariables is removed this has to be removed/moved either.
1240 // Explicit addition of UnreachableMachineBlockElim allows stopping before or
1241 // after it with -stop-before/-stop-after.
1245
1246 // Edge splitting is smarter with machine loop info.
1250
1251 // Eventually, we want to run LiveIntervals before PHI elimination.
1252 if (Opt.EarlyLiveIntervals)
1255
1258
1259 // The machine scheduler may accidentally create disconnected components
1260 // when moving subregister definitions around, avoid this by splitting them to
1261 // separate vregs before. Splitting can also improve reg. allocation quality.
1263
1264 // PreRA instruction scheduling.
1266
1267 Expected<bool> AddedPasses = derived().addRegAssignAndRewriteOptimized(PMW);
1268 if (!AddedPasses)
1269 return AddedPasses.takeError();
1270 if (!AddedPasses.get())
1271 return Error::success();
1272
1274
1275 // Allow targets to expand pseudo instructions depending on the choice of
1276 // registers before MachineCopyPropagation.
1277 derived().addPostRewrite(PMW);
1278
1279 // Copy propagate to forward register uses and try to eliminate COPYs that
1280 // were not coalesced.
1282
1283 // Run post-ra machine LICM to hoist reloads / remats.
1284 //
1285 // FIXME: can this move into MachineLateOptimization?
1287
1288 return Error::success();
1289}
1290
1291//===---------------------------------------------------------------------===//
1292/// Post RegAlloc Pass Configuration
1293//===---------------------------------------------------------------------===//
1294
1295/// Add passes that optimize machine instructions after register allocation.
1296template <typename Derived, typename TargetMachineT>
1298 PassManagerWrapper &PMW) const {
1299 // Cleanup of redundant (identical) address/immediate loads.
1301
1302 // Branch folding must be run after regalloc and prolog/epilog insertion.
1303 addMachineFunctionPass(BranchFolderPass(Opt.EnableTailMerge), PMW);
1304
1305 // Tail duplication.
1306 // Note that duplicating tail just increases code size and degrades
1307 // performance for targets that require Structured Control Flow.
1308 // In addition it can also make CFG irreducible. Thus we disable it.
1309 if (!TM.requiresStructuredCFG())
1311
1312 // Copy propagation.
1314}
1315
1316/// Add standard basic block placement passes.
1317template <typename Derived, typename TargetMachineT>
1319 PassManagerWrapper &PMW) const {
1321 // Run a separate pass to collect block placement statistics.
1322 if (Opt.EnableBlockPlacementStats)
1324}
1325
1326} // namespace llvm
1327
1328#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.
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
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:66
ExceptionHandling getExceptionHandlingType() const
Definition MCAsmInfo.h:655
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.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
ModuleToFunctionPassAdaptor createModuleToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:94
@ SjLj
setjmp/longjmp based exceptions
Definition CodeGen.h:56
@ ZOS
z/OS MVS Exception Handling.
Definition CodeGen.h:61
@ None
No exception support.
Definition CodeGen.h:54
@ AIX
AIX Exception Handling.
Definition CodeGen.h:60
@ DwarfCFI
DWARF-like instruction based exceptions.
Definition CodeGen.h:55
@ WinEH
Windows Exception Handling.
Definition CodeGen.h:58
@ Wasm
WebAssembly Exception Handling.
Definition CodeGen.h:59
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h: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: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:209
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.
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'.
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.