[llvm] [VPlan] Add hidden `-vplan-print-after-all` option (PR #175839)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 27 14:50:50 PST 2026


================
@@ -33,28 +33,43 @@ class VPRecipeBuilder;
 struct VFRange;
 
 LLVM_ABI_FOR_TEST extern cl::opt<bool> VerifyEachVPlan;
+LLVM_ABI_FOR_TEST extern cl::opt<bool> PrintAfterEachVPlanPass;
 LLVM_ABI_FOR_TEST extern cl::opt<bool> EnableWideActiveLaneMask;
 
 struct VPlanTransforms {
-  /// Helper to run a VPlan transform \p Transform on \p VPlan, forwarding extra
-  /// arguments to the transform. Returns the boolean returned by the transform.
-  template <typename... ArgsTy>
-  static bool runPass(bool (*Transform)(VPlan &, ArgsTy...), VPlan &Plan,
-                      typename std::remove_reference<ArgsTy>::type &...Args) {
-    bool Res = Transform(Plan, Args...);
-    if (VerifyEachVPlan)
-      verifyVPlanIsValid(Plan);
-    return Res;
-  }
-  /// Helper to run a VPlan transform \p Transform on \p VPlan, forwarding extra
-  /// arguments to the transform.
-  template <typename... ArgsTy>
-  static void runPass(void (*Fn)(VPlan &, ArgsTy...), VPlan &Plan,
-                      typename std::remove_reference<ArgsTy>::type &...Args) {
-    Fn(Plan, Args...);
-    if (VerifyEachVPlan)
-      verifyVPlanIsValid(Plan);
+  /// Helper to run a VPlan pass \p Pass on \p VPlan, forwarding extra arguments
+  /// to the pass. Performs verification/printing after each VPlan pass if
+  /// requested via command line options.
+  template <bool EnableVerify = true, typename PassTy, typename... ArgsTy>
+  static decltype(auto) runPass(StringRef PassName, PassTy &&Pass, VPlan &Plan,
+                                ArgsTy &&...Args) {
+    auto PostTransformActions = [&]() {
+      // Make sure to print before verification, so that output is more useful
+      // in case of failures:
+      if (PrintAfterEachVPlanPass) {
+        dbgs() << "VPlan after " << PassName << '\n';
+        dbgs() << Plan << '\n';
+      }
+      if (VerifyEachVPlan && EnableVerify)
+        verifyVPlanIsValid(Plan);
+    };
+
+    using ResTy = decltype(std::forward<PassTy>(Pass)(
+        Plan, std::forward<ArgsTy>(Args)...));
+    if constexpr (std::is_same_v<ResTy, void>) {
+      std::forward<PassTy>(Pass)(Plan, std::forward<ArgsTy>(Args)...);
+      PostTransformActions();
+    } else {
+      decltype(auto) Res =
+          std::forward<PassTy>(Pass)(Plan, std::forward<ArgsTy>(Args)...);
+      PostTransformActions();
+      return Res;
+    }
   }
+#define RUN_VPLAN_PASS(PASS, ...)                                              \
+  llvm::VPlanTransforms::runPass(#PASS, PASS, __VA_ARGS__)
+#define RUN_VPLAN_PASS_NO_VERIFY(PASS, ...)                                    \
+  llvm::VPlanTransforms::runPass<false>(#PASS, PASS, __VA_ARGS__)
----------------
artagnon wrote:

Hm, just had a look at the history, and I think the macro solution is the easiest at the moment.

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


More information about the llvm-commits mailing list