[llvm] [AArch64][SVE] Tweak how SVE CFI expressions are emitted (PR #151677)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 4 03:20:42 PDT 2025


================
@@ -5861,33 +5861,41 @@ void AArch64InstrInfo::decomposeStackOffsetForFrameOffsets(
   }
 }
 
-// Convenience function to create a DWARF expression for
-//   Expr + NumBytes + NumVGScaledBytes * AArch64::VG
-static void appendVGScaledOffsetExpr(SmallVectorImpl<char> &Expr, int NumBytes,
-                                     int NumVGScaledBytes, unsigned VG,
-                                     llvm::raw_string_ostream &Comment) {
-  uint8_t buffer[16];
-
-  if (NumBytes) {
+// Convenience function to create a DWARF expression for `Operation` Value.
+// This helper emits compact sequences for common cases.
+static void appendConstantExpr(SmallVectorImpl<char> &Expr, int64_t Value,
+                               uint8_t Operation) {
+  // + -constant (<= 31)
+  if (Operation == dwarf::DW_OP_plus && Value < 0 && -Value <= 31) {
+    Expr.push_back(dwarf::DW_OP_lit0 - Value);
+    Operation = dwarf::DW_OP_minus;
+  } else if (Value >= 0 && Value <= 31) {
+    // `Op` literal value 0 to 31
+    Expr.push_back(dwarf::DW_OP_lit0 + Value);
+  } else {
+    // `Op` constant
     Expr.push_back(dwarf::DW_OP_consts);
-    Expr.append(buffer, buffer + encodeSLEB128(NumBytes, buffer));
-    Expr.push_back((uint8_t)dwarf::DW_OP_plus);
-    Comment << (NumBytes < 0 ? " - " : " + ") << std::abs(NumBytes);
+    appendLEB128<LEB128Sign::Signed>(Expr, Value);
   }
+  return Expr.push_back(Operation);
+}
 
-  if (NumVGScaledBytes) {
-    Expr.push_back((uint8_t)dwarf::DW_OP_consts);
-    Expr.append(buffer, buffer + encodeSLEB128(NumVGScaledBytes, buffer));
-
-    Expr.push_back((uint8_t)dwarf::DW_OP_bregx);
-    Expr.append(buffer, buffer + encodeULEB128(VG, buffer));
-    Expr.push_back(0);
-
-    Expr.push_back((uint8_t)dwarf::DW_OP_mul);
-    Expr.push_back((uint8_t)dwarf::DW_OP_plus);
+// Convenience function to create a DWARF expression for VG
+static void appendReadVGRegExpr(SmallVectorImpl<char> &Expr,
+                                unsigned VGRegNum) {
----------------
sdesmalen-arm wrote:

nit: My first thought was: why pass in `VGRegNum` if it's always a constant? I guess that's because you'll need `TRI`, but maybe you can generalise the name to `appendReadRegExpr` instead.

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


More information about the llvm-commits mailing list