[llvm] [CFIInserter] Improve `CSRSavedLocation` struct. (PR #168869)

Mikhail Gudim via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 16 08:46:07 PST 2025


================
@@ -277,10 +319,19 @@ void CFIInstrInserter::calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo) {
       case MCCFIInstruction::OpValOffset:
         break;
       }
-      if (CSRReg || CSROffset) {
-        CSRSavedLocation Loc(CSRReg, CSROffset);
-        auto [It, Inserted] = CSRLocMap.insert({CFI.getRegister(), Loc});
-        if (!Inserted && It->second != Loc) {
+      assert((bool)CSRReg + (bool)CSROffset <= 1 &&
+             "A register can only be at an offset from CFA or in another "
+             "register, but not both!");
+      CSRSavedLocation CSRLoc;
+      if (CSRReg)
+        CSRLoc = CSRSavedLocation::createRegister(*CSRReg);
+      else if (CSROffset)
+        CSRLoc = CSRSavedLocation::createCFAOffset(*CSROffset);
+      if (CSRLoc.isValid()) {
----------------
mgudim wrote:

It will be needed here: https://github.com/llvm/llvm-project/pull/168531/files#diff-54d9d06f60ce6c927ea0f2c1380a50bdf93c689d1781186966ef2234660e47c9R421

Unless we want to collect all callee-saved registers in a vector before we come to this line. But... we also need CFIs for exception handling (or something else) and I suspect it may require emitting CFIs for non-callee saved registers.

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


More information about the llvm-commits mailing list