[llvm] [NewPM] Adds a port for AArch64O0PreLegalizerCombiner (PR #189776)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 01:54:30 PDT 2026


================
@@ -161,32 +190,63 @@ bool AArch64O0PreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
       getAnalysis<LibcallLoweringInfoWrapper>().getLibcallLowering(
           *F.getParent(), ST);
 
-  CombinerInfo CInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
-                     /*LegalizerInfo*/ nullptr, /*EnableOpt*/ false,
-                     F.hasOptSize(), F.hasMinSize());
-  // Disable fixed-point iteration in the Combiner. This improves compile-time
-  // at the cost of possibly missing optimizations. See PR#94291 for details.
-  CInfo.MaxIterations = 1;
-
-  AArch64O0PreLegalizerCombinerImpl Impl(MF, CInfo, *VT,
-                                         /*CSEInfo*/ nullptr, RuleConfig, ST,
-                                         Libcalls);
-  return Impl.combineMachineInstrs();
+  return runCombiner(MF, VT, Libcalls, RuleConfig);
 }
 
-char AArch64O0PreLegalizerCombiner::ID = 0;
-INITIALIZE_PASS_BEGIN(AArch64O0PreLegalizerCombiner, DEBUG_TYPE,
+char AArch64O0PreLegalizerCombinerLegacy::ID = 0;
+INITIALIZE_PASS_BEGIN(AArch64O0PreLegalizerCombinerLegacy, DEBUG_TYPE,
                       "Combine AArch64 machine instrs before legalization",
                       false, false)
 INITIALIZE_PASS_DEPENDENCY(GISelValueTrackingAnalysisLegacy)
 INITIALIZE_PASS_DEPENDENCY(GISelCSEAnalysisWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(LibcallLoweringInfoWrapper)
-INITIALIZE_PASS_END(AArch64O0PreLegalizerCombiner, DEBUG_TYPE,
+INITIALIZE_PASS_END(AArch64O0PreLegalizerCombinerLegacy, DEBUG_TYPE,
                     "Combine AArch64 machine instrs before legalization", false,
                     false)
 
+AArch64O0PreLegalizerCombinerPass::AArch64O0PreLegalizerCombinerPass()
+    : RuleConfig(
+          std::make_unique<AArch64O0PreLegalizerCombinerImplRuleConfig>()) {
+  if (!RuleConfig->parseCommandLineOption())
+    report_fatal_error("Invalid rule identifier");
+}
+
+AArch64O0PreLegalizerCombinerPass::AArch64O0PreLegalizerCombinerPass(
+    AArch64O0PreLegalizerCombinerPass &&) = default;
+
+AArch64O0PreLegalizerCombinerPass::~AArch64O0PreLegalizerCombinerPass() =
+    default;
+
+PreservedAnalyses
+AArch64O0PreLegalizerCombinerPass::run(MachineFunction &MF,
+                                       MachineFunctionAnalysisManager &MFAM) {
+  if (MF.getProperties().hasFailedISel())
+    return PreservedAnalyses::all();
+
+  GISelValueTracking &VT = MFAM.getResult<GISelValueTrackingAnalysis>(MF);
+
+  const AArch64Subtarget &ST = MF.getSubtarget<AArch64Subtarget>();
+  auto &MAMProxy =
+      MFAM.getResult<ModuleAnalysisManagerMachineFunctionProxy>(MF);
+  const LibcallLoweringModuleAnalysisResult *LibcallResult =
+      MAMProxy.getCachedResult<LibcallLoweringModuleAnalysis>(
+          *MF.getFunction().getParent());
+  if (!LibcallResult)
+    report_fatal_error("LibcallLoweringModuleAnalysis result not available");
----------------
arsenm wrote:

```suggestion
    reportFatalUsageError("LibcallLoweringModuleAnalysis result not available");
```

We really need to get a helper function in ModuleAnalysisManagerMachineFunctionProxy to get required module analyses 

https://github.com/llvm/llvm-project/pull/189776


More information about the llvm-commits mailing list