@@ -1063,7 +1063,9 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addMachineSSAOptimization(
10631063// /
10641064// / A target that uses the standard regalloc pass order for fast or optimized
10651065// / allocation may still override this for per-target regalloc
1066- // / selection. But -regalloc=... always takes precedence.
1066+ // / selection. But -regalloc-npm=... always takes precedence.
1067+ // / If a target does not want to allow users to set -regalloc-npm=... at all,
1068+ // / check if Opt.RegAlloc == RegAllocType::Unset.
10671069template <typename Derived, typename TargetMachineT>
10681070void CodeGenPassBuilder<Derived, TargetMachineT>::addTargetRegisterAllocator(
10691071 AddMachinePass &addPass, bool Optimized) const {
@@ -1076,10 +1078,29 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addTargetRegisterAllocator(
10761078// / Find and instantiate the register allocation pass requested by this target
10771079// / at the current optimization level. Different register allocators are
10781080// / defined as separate passes because they may require different analysis.
1081+ // /
1082+ // / This helper ensures that the -regalloc-npm= option is always available,
1083+ // / even for targets that override the default allocator.
10791084template <typename Derived, typename TargetMachineT>
10801085void CodeGenPassBuilder<Derived, TargetMachineT>::addRegAllocPass(
10811086 AddMachinePass &addPass, bool Optimized) const {
1082- // TODO: Parse Opt.RegAlloc to add register allocator.
1087+ // Use the specified -regalloc-npm={basic|greedy|fast|pbqp}
1088+ if (Opt.RegAlloc > RegAllocType::Default) {
1089+ switch (Opt.RegAlloc ) {
1090+ case RegAllocType::Fast:
1091+ addPass (RegAllocFastPass ());
1092+ break ;
1093+ case RegAllocType::Greedy:
1094+ addPass (RAGreedyPass ());
1095+ break ;
1096+ default :
1097+ report_fatal_error (" register allocator not supported yet" , false );
1098+ }
1099+ return ;
1100+ }
1101+ // -regalloc=default or unspecified, so pick based on the optimization level
1102+ // or ask the target for the regalloc pass.
1103+ derived ().addTargetRegisterAllocator (addPass, Optimized);
10831104}
10841105
10851106template <typename Derived, typename TargetMachineT>
@@ -1150,20 +1171,22 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addOptimizedRegAlloc(
11501171 // PreRA instruction scheduling.
11511172 addPass (MachineSchedulerPass (&TM));
11521173
1153- if (derived ().addRegAssignmentOptimized (addPass)) {
1154- // Allow targets to expand pseudo instructions depending on the choice of
1155- // registers before MachineCopyPropagation.
1156- derived ().addPostRewrite (addPass);
1174+ if (auto E = derived ().addRegAssignmentOptimized (addPass)) {
1175+ // addRegAssignmentOptimized did not add a reg alloc pass, so do nothing.
1176+ return ;
1177+ }
1178+ // Allow targets to expand pseudo instructions depending on the choice of
1179+ // registers before MachineCopyPropagation.
1180+ derived ().addPostRewrite (addPass);
11571181
1158- // Copy propagate to forward register uses and try to eliminate COPYs that
1159- // were not coalesced.
1160- addPass (MachineCopyPropagationPass ());
1182+ // Copy propagate to forward register uses and try to eliminate COPYs that
1183+ // were not coalesced.
1184+ addPass (MachineCopyPropagationPass ());
11611185
1162- // Run post-ra machine LICM to hoist reloads / remats.
1163- //
1164- // FIXME: can this move into MachineLateOptimization?
1165- addPass (MachineLICMPass ());
1166- }
1186+ // Run post-ra machine LICM to hoist reloads / remats.
1187+ //
1188+ // FIXME: can this move into MachineLateOptimization?
1189+ addPass (MachineLICMPass ());
11671190}
11681191
11691192// ===---------------------------------------------------------------------===//
0 commit comments