[llvm] [CodeGen] Allow multiple location for the same CSR. (PR #168531)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 18 05:08:21 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/CodeGen/CFIInstrInserter.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/CodeGen/CFIInstrInserter.cpp b/llvm/lib/CodeGen/CFIInstrInserter.cpp
index 667928304..20fe26afe 100644
--- a/llvm/lib/CodeGen/CFIInstrInserter.cpp
+++ b/llvm/lib/CodeGen/CFIInstrInserter.cpp
@@ -65,104 +65,104 @@ class CFIInstrInserter : public MachineFunctionPass {
     return insertedCFI;
   }
 
- private:
+private:
 #define INVALID_REG UINT_MAX
 #define INVALID_OFFSET INT_MAX
-   /// contains the location where CSR register is saved.
-   struct CSRSavedLocation {
-     enum Kind { INVALID, REGISTER, CFA_OFFSET };
-     CSRSavedLocation() {
-       K = Kind::INVALID;
-       Reg = 0;
-       Offset = 0;
-     }
-     Kind K;
-     // Dwarf register number
-     unsigned Reg;
-     // CFA offset
-     int64_t Offset;
-     bool isValid() const { return K != Kind::INVALID; }
-     bool operator==(const CSRSavedLocation &RHS) const {
-       switch (K) {
-       case Kind::INVALID:
-         return !RHS.isValid();
-       case Kind::REGISTER:
-         return Reg == RHS.Reg;
-       case Kind::CFA_OFFSET:
-         return Offset == RHS.Offset;
-       }
-       llvm_unreachable("Unknown CSRSavedLocation Kind!");
-     }
-     void dump(raw_ostream &OS) const {
-       switch (K) {
-       case Kind::INVALID:
-         OS << "INVALID";
-         break;
-       case Kind::REGISTER:
-         OS << "In Dwarf register: " << Reg;
-         break;
-       case Kind::CFA_OFFSET:
-         OS << "At CFA offset: " << Offset;
-         break;
-       }
-     }
-   };
-
-   struct MBBCFAInfo {
-     MachineBasicBlock *MBB;
-     /// Value of cfa offset valid at basic block entry.
-     int64_t IncomingCFAOffset = -1;
-     /// Value of cfa offset valid at basic block exit.
-     int64_t OutgoingCFAOffset = -1;
-     /// Value of cfa register valid at basic block entry.
-     unsigned IncomingCFARegister = 0;
-     /// Value of cfa register valid at basic block exit.
-     unsigned OutgoingCFARegister = 0;
-     /// Set of locations where the callee saved registers are at basic block
-     /// entry.
-     SmallVector<CSRSavedLocation> IncomingCSRLocations;
-     /// Set of locations where the callee saved registers are at basic block
-     /// exit.
-     SmallVector<CSRSavedLocation> OutgoingCSRLocations;
-     /// If in/out cfa offset and register values for this block have already
-     /// been set or not.
-     bool Processed = false;
-   };
-
-   /// Contains cfa offset and register values valid at entry and exit of basic
-   /// blocks.
-   std::vector<MBBCFAInfo> MBBVector;
-
-   /// Calculate cfa offset and register values valid at entry and exit for all
-   /// basic blocks in a function.
-   void calculateCFAInfo(MachineFunction &MF);
-   /// Calculate cfa offset and register values valid at basic block exit by
-   /// checking the block for CFI instructions. Block's incoming CFA info
-   /// remains the same.
-   void calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo);
-   /// Update in/out cfa offset and register values for successors of the basic
-   /// block.
-   void updateSuccCFAInfo(MBBCFAInfo &MBBInfo);
-
-   /// Check if incoming CFA information of a basic block matches outgoing CFA
-   /// information of the previous block. If it doesn't, insert CFI instruction
-   /// at the beginning of the block that corrects the CFA calculation rule for
-   /// that block.
-   bool insertCFIInstrs(MachineFunction &MF);
-   /// Return the cfa offset value that should be set at the beginning of a MBB
-   /// if needed. The negated value is needed when creating CFI instructions
-   /// that set absolute offset.
-   int64_t getCorrectCFAOffset(MachineBasicBlock *MBB) {
-     return MBBVector[MBB->getNumber()].IncomingCFAOffset;
-   }
-
-   void reportCFAError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
-   void reportCSRError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
-   /// Go through each MBB in a function and check that outgoing offset and
-   /// register of its predecessors match incoming offset and register of that
-   /// MBB, as well as that incoming offset and register of its successors match
-   /// outgoing offset and register of the MBB.
-   unsigned verify(MachineFunction &MF);
+  /// contains the location where CSR register is saved.
+  struct CSRSavedLocation {
+    enum Kind { INVALID, REGISTER, CFA_OFFSET };
+    CSRSavedLocation() {
+      K = Kind::INVALID;
+      Reg = 0;
+      Offset = 0;
+    }
+    Kind K;
+    // Dwarf register number
+    unsigned Reg;
+    // CFA offset
+    int64_t Offset;
+    bool isValid() const { return K != Kind::INVALID; }
+    bool operator==(const CSRSavedLocation &RHS) const {
+      switch (K) {
+      case Kind::INVALID:
+        return !RHS.isValid();
+      case Kind::REGISTER:
+        return Reg == RHS.Reg;
+      case Kind::CFA_OFFSET:
+        return Offset == RHS.Offset;
+      }
+      llvm_unreachable("Unknown CSRSavedLocation Kind!");
+    }
+    void dump(raw_ostream &OS) const {
+      switch (K) {
+      case Kind::INVALID:
+        OS << "INVALID";
+        break;
+      case Kind::REGISTER:
+        OS << "In Dwarf register: " << Reg;
+        break;
+      case Kind::CFA_OFFSET:
+        OS << "At CFA offset: " << Offset;
+        break;
+      }
+    }
+  };
+
+  struct MBBCFAInfo {
+    MachineBasicBlock *MBB;
+    /// Value of cfa offset valid at basic block entry.
+    int64_t IncomingCFAOffset = -1;
+    /// Value of cfa offset valid at basic block exit.
+    int64_t OutgoingCFAOffset = -1;
+    /// Value of cfa register valid at basic block entry.
+    unsigned IncomingCFARegister = 0;
+    /// Value of cfa register valid at basic block exit.
+    unsigned OutgoingCFARegister = 0;
+    /// Set of locations where the callee saved registers are at basic block
+    /// entry.
+    SmallVector<CSRSavedLocation> IncomingCSRLocations;
+    /// Set of locations where the callee saved registers are at basic block
+    /// exit.
+    SmallVector<CSRSavedLocation> OutgoingCSRLocations;
+    /// If in/out cfa offset and register values for this block have already
+    /// been set or not.
+    bool Processed = false;
+  };
+
+  /// Contains cfa offset and register values valid at entry and exit of basic
+  /// blocks.
+  std::vector<MBBCFAInfo> MBBVector;
+
+  /// Calculate cfa offset and register values valid at entry and exit for all
+  /// basic blocks in a function.
+  void calculateCFAInfo(MachineFunction &MF);
+  /// Calculate cfa offset and register values valid at basic block exit by
+  /// checking the block for CFI instructions. Block's incoming CFA info
+  /// remains the same.
+  void calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo);
+  /// Update in/out cfa offset and register values for successors of the basic
+  /// block.
+  void updateSuccCFAInfo(MBBCFAInfo &MBBInfo);
+
+  /// Check if incoming CFA information of a basic block matches outgoing CFA
+  /// information of the previous block. If it doesn't, insert CFI instruction
+  /// at the beginning of the block that corrects the CFA calculation rule for
+  /// that block.
+  bool insertCFIInstrs(MachineFunction &MF);
+  /// Return the cfa offset value that should be set at the beginning of a MBB
+  /// if needed. The negated value is needed when creating CFI instructions
+  /// that set absolute offset.
+  int64_t getCorrectCFAOffset(MachineBasicBlock *MBB) {
+    return MBBVector[MBB->getNumber()].IncomingCFAOffset;
+  }
+
+  void reportCFAError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
+  void reportCSRError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
+  /// Go through each MBB in a function and check that outgoing offset and
+  /// register of its predecessors match incoming offset and register of that
+  /// MBB, as well as that incoming offset and register of its successors match
+  /// outgoing offset and register of the MBB.
+  unsigned verify(MachineFunction &MF);
 };
 }  // namespace
 

``````````

</details>


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


More information about the llvm-commits mailing list