[llvm] [CodeGen] Fix llc -start/stop-after/before bug for inserted machine passes (PR #200631)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 14 04:33:40 PDT 2026


================
@@ -562,10 +601,67 @@ template <typename DerivedT, typename TargetMachineT> class CodeGenPassBuilder {
       llvm::unique_function<void(StringRef, MachineFunctionPassManager &)>, 4>
       AfterCallbacks;
 
+  /// State class for `-start-before/-start-after/-stop-before/-stop-after`
+  struct StartStopState {
+    StartStopState(const TargetPassConfig::StartStopInfo &SSI)
+        : Info(SSI), StartTargetCount(0), StopTargetCount(0),
+          Started(SSI.StartPass.empty()), Stopped(SSI.StopPass.empty()),
+          StartAfterFlag(SSI.StartAfter), StopAfterFlag(SSI.StopAfter) {}
+
+    StartStopState() = default;
+    const TargetPassConfig::StartStopInfo &getInfo() const { return Info; }
+
+  private:
+    TargetPassConfig::StartStopInfo Info;
+
+  public:
+    unsigned StartTargetCount = 0u;
+    unsigned StopTargetCount = 0u;
+    bool Started = true;
+    bool Stopped = true;
+    bool StartAfterFlag = false;
+    bool StopAfterFlag = false;
+  };
+
+  struct AfterCallbackControl {
+    enum class Mode { Normal, Probe, ConsumeOnly };
+    Mode ModeValue = Mode::Normal;
+    unsigned InsertedTargetPassCount = 0;
+  };
+
   /// Helper variable for `-start-before/-start-after/-stop-before/-stop-after`
-  mutable bool Started = true;
-  mutable bool Stopped = true;
   mutable bool AddInCGSCCOrder = false;
+  mutable StartStopState SSState{};
+  mutable AfterCallbackControl AfterCtrl;
+
+  void runAfterCallbacks(StringRef Name,
+                         MachineFunctionPassManager &MFPM) const {
+    for (auto &C : AfterCallbacks) {
+      C(Name, MFPM);
+    }
----------------
paperchalice wrote:

Ditto.

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


More information about the llvm-commits mailing list