@@ -109,9 +109,9 @@ namespace llvm {
109
109
// / construction. The \c MachinePassRegistry.def file specifies how to construct
110
110
// / all of the built-in passes, and those may reference these members during
111
111
// / construction.
112
- template <typename DerivedT> class CodeGenPassBuilder {
112
+ template <typename DerivedT, typename TargetMachineT > class CodeGenPassBuilder {
113
113
public:
114
- explicit CodeGenPassBuilder (LLVMTargetMachine &TM,
114
+ explicit CodeGenPassBuilder (TargetMachineT &TM,
115
115
const CGPassBuilderOption &Opts,
116
116
PassInstrumentationCallbacks *PIC)
117
117
: TM(TM), Opt(Opts), PIC(PIC) {
@@ -237,7 +237,7 @@ template <typename DerivedT> class CodeGenPassBuilder {
237
237
const DerivedT &PB;
238
238
};
239
239
240
- LLVMTargetMachine &TM;
240
+ TargetMachineT &TM;
241
241
CGPassBuilderOption Opt;
242
242
PassInstrumentationCallbacks *PIC;
243
243
@@ -498,8 +498,8 @@ template <typename DerivedT> class CodeGenPassBuilder {
498
498
mutable bool Stopped = true ;
499
499
};
500
500
501
- template <typename Derived>
502
- Error CodeGenPassBuilder<Derived>::buildPipeline(
501
+ template <typename Derived, typename TargetMachineT >
502
+ Error CodeGenPassBuilder<Derived, TargetMachineT >::buildPipeline(
503
503
ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
504
504
CodeGenFileType FileType) const {
505
505
auto StartStopInfo = TargetPassConfig::getStartStopInfo (*PIC);
@@ -542,8 +542,8 @@ Error CodeGenPassBuilder<Derived>::buildPipeline(
542
542
return verifyStartStop (*StartStopInfo);
543
543
}
544
544
545
- template <typename Derived>
546
- void CodeGenPassBuilder<Derived>::setStartStopPasses(
545
+ template <typename Derived, typename TargetMachineT >
546
+ void CodeGenPassBuilder<Derived, TargetMachineT >::setStartStopPasses(
547
547
const TargetPassConfig::StartStopInfo &Info) const {
548
548
if (!Info.StartPass .empty ()) {
549
549
Started = false ;
@@ -585,8 +585,8 @@ void CodeGenPassBuilder<Derived>::setStartStopPasses(
585
585
}
586
586
}
587
587
588
- template <typename Derived>
589
- Error CodeGenPassBuilder<Derived>::verifyStartStop(
588
+ template <typename Derived, typename TargetMachineT >
589
+ Error CodeGenPassBuilder<Derived, TargetMachineT >::verifyStartStop(
590
590
const TargetPassConfig::StartStopInfo &Info) const {
591
591
if (Started && Stopped)
592
592
return Error::success ();
@@ -604,8 +604,9 @@ Error CodeGenPassBuilder<Derived>::verifyStartStop(
604
604
return Error::success ();
605
605
}
606
606
607
- template <typename Derived>
608
- void CodeGenPassBuilder<Derived>::addISelPasses(AddIRPass &addPass) const {
607
+ template <typename Derived, typename TargetMachineT>
608
+ void CodeGenPassBuilder<Derived, TargetMachineT>::addISelPasses(
609
+ AddIRPass &addPass) const {
609
610
derived ().addGlobalMergePass (addPass);
610
611
if (TM.useEmulatedTLS ())
611
612
addPass (LowerEmuTLSPass ());
@@ -620,8 +621,9 @@ void CodeGenPassBuilder<Derived>::addISelPasses(AddIRPass &addPass) const {
620
621
621
622
// / Add common target configurable passes that perform LLVM IR to IR transforms
622
623
// / following machine independent optimization.
623
- template <typename Derived>
624
- void CodeGenPassBuilder<Derived>::addIRPasses(AddIRPass &addPass) const {
624
+ template <typename Derived, typename TargetMachineT>
625
+ void CodeGenPassBuilder<Derived, TargetMachineT>::addIRPasses(
626
+ AddIRPass &addPass) const {
625
627
// Before running any passes, run the verifier to determine if the input
626
628
// coming from the front-end and/or optimizer is valid.
627
629
if (!Opt.DisableVerify )
@@ -686,8 +688,8 @@ void CodeGenPassBuilder<Derived>::addIRPasses(AddIRPass &addPass) const {
686
688
687
689
// / Turn exception handling constructs into something the code generators can
688
690
// / handle.
689
- template <typename Derived>
690
- void CodeGenPassBuilder<Derived>::addPassesToHandleExceptions(
691
+ template <typename Derived, typename TargetMachineT >
692
+ void CodeGenPassBuilder<Derived, TargetMachineT >::addPassesToHandleExceptions(
691
693
AddIRPass &addPass) const {
692
694
const MCAsmInfo *MCAI = TM.getMCAsmInfo ();
693
695
assert (MCAI && " No MCAsmInfo" );
@@ -733,8 +735,9 @@ void CodeGenPassBuilder<Derived>::addPassesToHandleExceptions(
733
735
734
736
// / Add pass to prepare the LLVM IR for code generation. This should be done
735
737
// / before exception handling preparation passes.
736
- template <typename Derived>
737
- void CodeGenPassBuilder<Derived>::addCodeGenPrepare(AddIRPass &addPass) const {
738
+ template <typename Derived, typename TargetMachineT>
739
+ void CodeGenPassBuilder<Derived, TargetMachineT>::addCodeGenPrepare(
740
+ AddIRPass &addPass) const {
738
741
if (getOptLevel () != CodeGenOptLevel::None && !Opt.DisableCGP )
739
742
addPass (CodeGenPreparePass (&TM));
740
743
// TODO: Default ctor'd RewriteSymbolPass is no-op.
@@ -743,8 +746,9 @@ void CodeGenPassBuilder<Derived>::addCodeGenPrepare(AddIRPass &addPass) const {
743
746
744
747
// / Add common passes that perform LLVM IR to IR transforms in preparation for
745
748
// / instruction selection.
746
- template <typename Derived>
747
- void CodeGenPassBuilder<Derived>::addISelPrepare(AddIRPass &addPass) const {
749
+ template <typename Derived, typename TargetMachineT>
750
+ void CodeGenPassBuilder<Derived, TargetMachineT>::addISelPrepare(
751
+ AddIRPass &addPass) const {
748
752
derived ().addPreISel (addPass);
749
753
750
754
addPass (CallBrPreparePass ());
@@ -763,8 +767,8 @@ void CodeGenPassBuilder<Derived>::addISelPrepare(AddIRPass &addPass) const {
763
767
addPass (VerifierPass ());
764
768
}
765
769
766
- template <typename Derived>
767
- Error CodeGenPassBuilder<Derived>::addCoreISelPasses(
770
+ template <typename Derived, typename TargetMachineT >
771
+ Error CodeGenPassBuilder<Derived, TargetMachineT >::addCoreISelPasses(
768
772
AddMachinePass &addPass) const {
769
773
// Enable FastISel with -fast-isel, but allow that to be overridden.
770
774
TM.setO0WantsFastISel (Opt.EnableFastISelOption .value_or (true ));
@@ -846,17 +850,18 @@ Error CodeGenPassBuilder<Derived>::addCoreISelPasses(
846
850
// / with nontrivial configuration or multiple passes are broken out below in
847
851
// / add%Stage routines.
848
852
// /
849
- // / Any CodeGenPassBuilder<Derived>::addXX routine may be overriden by the
850
- // / Target. The addPre/Post methods with empty header implementations allow
851
- // / injecting target-specific fixups just before or after major stages.
852
- // / Additionally, targets have the flexibility to change pass order within a
853
- // / stage by overriding default implementation of add%Stage routines below. Each
854
- // / technique has maintainability tradeoffs because alternate pass orders are
855
- // / not well supported. addPre/Post works better if the target pass is easily
856
- // / tied to a common pass. But if it has subtle dependencies on multiple passes,
857
- // / the target should override the stage instead.
858
- template <typename Derived>
859
- Error CodeGenPassBuilder<Derived>::addMachinePasses(
853
+ // / Any CodeGenPassBuilder<Derived, TargetMachine>::addXX routine may be
854
+ // / overriden by the Target. The addPre/Post methods with empty header
855
+ // / implementations allow injecting target-specific fixups just before or after
856
+ // / major stages. Additionally, targets have the flexibility to change pass
857
+ // / order within a stage by overriding default implementation of add%Stage
858
+ // / routines below. Each technique has maintainability tradeoffs because
859
+ // / alternate pass orders are not well supported. addPre/Post works better if
860
+ // / the target pass is easily tied to a common pass. But if it has subtle
861
+ // / dependencies on multiple passes, the target should override the stage
862
+ // / instead.
863
+ template <typename Derived, typename TargetMachineT>
864
+ Error CodeGenPassBuilder<Derived, TargetMachineT>::addMachinePasses(
860
865
AddMachinePass &addPass) const {
861
866
// Add passes that optimize machine instructions in SSA form.
862
867
if (getOptLevel () != CodeGenOptLevel::None) {
@@ -962,8 +967,8 @@ Error CodeGenPassBuilder<Derived>::addMachinePasses(
962
967
}
963
968
964
969
// / Add passes that optimize machine instructions in SSA form.
965
- template <typename Derived>
966
- void CodeGenPassBuilder<Derived>::addMachineSSAOptimization(
970
+ template <typename Derived, typename TargetMachineT >
971
+ void CodeGenPassBuilder<Derived, TargetMachineT >::addMachineSSAOptimization(
967
972
AddMachinePass &addPass) const {
968
973
// Pre-ra tail duplication.
969
974
addPass (EarlyTailDuplicatePass ());
@@ -1014,8 +1019,8 @@ void CodeGenPassBuilder<Derived>::addMachineSSAOptimization(
1014
1019
// / A target that uses the standard regalloc pass order for fast or optimized
1015
1020
// / allocation may still override this for per-target regalloc
1016
1021
// / selection. But -regalloc=... always takes precedence.
1017
- template <typename Derived>
1018
- void CodeGenPassBuilder<Derived>::addTargetRegisterAllocator(
1022
+ template <typename Derived, typename TargetMachineT >
1023
+ void CodeGenPassBuilder<Derived, TargetMachineT >::addTargetRegisterAllocator(
1019
1024
AddMachinePass &addPass, bool Optimized) const {
1020
1025
if (Optimized)
1021
1026
addPass (RAGreedyPass ());
@@ -1026,22 +1031,22 @@ void CodeGenPassBuilder<Derived>::addTargetRegisterAllocator(
1026
1031
// / Find and instantiate the register allocation pass requested by this target
1027
1032
// / at the current optimization level. Different register allocators are
1028
1033
// / defined as separate passes because they may require different analysis.
1029
- template <typename Derived>
1030
- void CodeGenPassBuilder<Derived>::addRegAllocPass(AddMachinePass &addPass,
1031
- bool Optimized) const {
1034
+ template <typename Derived, typename TargetMachineT >
1035
+ void CodeGenPassBuilder<Derived, TargetMachineT >::addRegAllocPass(
1036
+ AddMachinePass &addPass, bool Optimized) const {
1032
1037
// TODO: Parse Opt.RegAlloc to add register allocator.
1033
1038
}
1034
1039
1035
- template <typename Derived>
1036
- Error CodeGenPassBuilder<Derived>::addRegAssignmentFast(
1040
+ template <typename Derived, typename TargetMachineT >
1041
+ Error CodeGenPassBuilder<Derived, TargetMachineT >::addRegAssignmentFast(
1037
1042
AddMachinePass &addPass) const {
1038
1043
// TODO: Ensure allocator is default or fast.
1039
1044
addRegAllocPass (addPass, false );
1040
1045
return Error::success ();
1041
1046
}
1042
1047
1043
- template <typename Derived>
1044
- Error CodeGenPassBuilder<Derived>::addRegAssignmentOptimized(
1048
+ template <typename Derived, typename TargetMachineT >
1049
+ Error CodeGenPassBuilder<Derived, TargetMachineT >::addRegAssignmentOptimized(
1045
1050
AddMachinePass &addPass) const {
1046
1051
// Add the selected register allocation pass.
1047
1052
addRegAllocPass (addPass, true );
@@ -1062,8 +1067,8 @@ Error CodeGenPassBuilder<Derived>::addRegAssignmentOptimized(
1062
1067
1063
1068
// / Add the minimum set of target-independent passes that are required for
1064
1069
// / register allocation. No coalescing or scheduling.
1065
- template <typename Derived>
1066
- Error CodeGenPassBuilder<Derived>::addFastRegAlloc(
1070
+ template <typename Derived, typename TargetMachineT >
1071
+ Error CodeGenPassBuilder<Derived, TargetMachineT >::addFastRegAlloc(
1067
1072
AddMachinePass &addPass) const {
1068
1073
addPass (PHIEliminationPass ());
1069
1074
addPass (TwoAddressInstructionPass ());
@@ -1073,8 +1078,8 @@ Error CodeGenPassBuilder<Derived>::addFastRegAlloc(
1073
1078
// / Add standard target-independent passes that are tightly coupled with
1074
1079
// / optimized register allocation, including coalescing, machine instruction
1075
1080
// / scheduling, and register allocation itself.
1076
- template <typename Derived>
1077
- void CodeGenPassBuilder<Derived>::addOptimizedRegAlloc(
1081
+ template <typename Derived, typename TargetMachineT >
1082
+ void CodeGenPassBuilder<Derived, TargetMachineT >::addOptimizedRegAlloc(
1078
1083
AddMachinePass &addPass) const {
1079
1084
addPass (DetectDeadLanesPass ());
1080
1085
@@ -1121,8 +1126,8 @@ void CodeGenPassBuilder<Derived>::addOptimizedRegAlloc(
1121
1126
// ===---------------------------------------------------------------------===//
1122
1127
1123
1128
// / Add passes that optimize machine instructions after register allocation.
1124
- template <typename Derived>
1125
- void CodeGenPassBuilder<Derived>::addMachineLateOptimization(
1129
+ template <typename Derived, typename TargetMachineT >
1130
+ void CodeGenPassBuilder<Derived, TargetMachineT >::addMachineLateOptimization(
1126
1131
AddMachinePass &addPass) const {
1127
1132
// Branch folding must be run after regalloc and prolog/epilog insertion.
1128
1133
addPass (BranchFolderPass ());
@@ -1142,8 +1147,8 @@ void CodeGenPassBuilder<Derived>::addMachineLateOptimization(
1142
1147
}
1143
1148
1144
1149
// / Add standard basic block placement passes.
1145
- template <typename Derived>
1146
- void CodeGenPassBuilder<Derived>::addBlockPlacement(
1150
+ template <typename Derived, typename TargetMachineT >
1151
+ void CodeGenPassBuilder<Derived, TargetMachineT >::addBlockPlacement(
1147
1152
AddMachinePass &addPass) const {
1148
1153
addPass (MachineBlockPlacementPass ());
1149
1154
// Run a separate pass to collect block placement statistics.
0 commit comments