[lld] [llvm] [LLD][RISCV] Use ISA mapping symbols for per-region RVC relaxation (PR #201310)

Kito Cheng via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 24 07:21:06 PDT 2026


================
@@ -1030,27 +1085,28 @@ static bool relax(Ctx &ctx, int pass, InputSection &sec) {
       // Prevent oscillation between states by disallowing the increment of
       // `remove` after a few passes. The previous `remove` value is
       // `cur-delta`.
-      if (relaxable(relocs, i)) {
+      if (std::optional<RISCVRelaxCapability> cap =
+              capMgr.relaxable(ctx, sec, relocs, i)) {
         remove = pass < 4 ? 6 : cur - delta;
-        relaxCall(ctx, sec, i, loc, r, remove);
+        relaxCall(ctx, sec, i, loc, r, remove, *cap);
       }
       break;
     case R_RISCV_TPREL_HI20:
     case R_RISCV_TPREL_ADD:
     case R_RISCV_TPREL_LO12_I:
     case R_RISCV_TPREL_LO12_S:
-      if (relaxable(relocs, i))
+      if (capMgr.relaxable(ctx, sec, relocs, i))
         relaxTlsLe(ctx, sec, i, loc, r, remove);
       break;
     case R_RISCV_HI20:
     case R_RISCV_LO12_I:
     case R_RISCV_LO12_S:
-      if (relaxable(relocs, i))
+      if (capMgr.relaxable(ctx, sec, relocs, i))
         relaxHi20Lo12(ctx, sec, i, loc, r, remove);
       break;
     case R_RISCV_TLSDESC_HI20:
       // For TLSDESC=>LE, we can use the short form if hi20 is zero.
-      tlsdescRelax = relaxable(relocs, i);
+      tlsdescRelax = capMgr.relaxable(ctx, sec, relocs, i).has_value();
----------------
kito-cheng wrote:

No, std::optional<T>::operator bool is explicit, so...I need that has_value here, the `if` is another story in C++ (I am suppress that too, my C++ knowledge base is mostly around C++11), I checked https://llvm.org/docs/CodingStandards.html but not found any rule around there, interested thing is here is some rule in flang's C++ coding style doc https://github.com/sifive/riscv-llvm-internal/blob/sifive-dev/flang/docs/C%2B%2Bstyle.md?plain=1#L220 (Okay I know here is lld not flang, but it's the only doc I found talking about std::optional)

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


More information about the llvm-commits mailing list