[llvm] [AMDGPU] MCExpr-ify MC layer kernel descriptor (PR #80855)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 08:28:11 PST 2024


================
@@ -5276,89 +5277,107 @@ bool AMDGPUAsmParser::ParseDirectiveAMDHSAKernel() {
       return TokError(".amdhsa_ directives cannot be repeated");
 
     SMLoc ValStart = getLoc();
-    int64_t IVal;
-    if (getParser().parseAbsoluteExpression(IVal))
+    const MCExpr *ExprVal;
+    if (getParser().parseExpression(ExprVal))
       return true;
     SMLoc ValEnd = getLoc();
     SMRange ValRange = SMRange(ValStart, ValEnd);
 
-    if (IVal < 0)
-      return OutOfRangeError(ValRange);
-
+    int64_t IVal = 0;
     uint64_t Val = IVal;
+    bool EvaluatableExpr;
+    if ((EvaluatableExpr = ExprVal->evaluateAsAbsolute(IVal))) {
+      if (IVal < 0)
+        return OutOfRangeError(ValRange);
+      Val = IVal;
+    }
 
 #define PARSE_BITS_ENTRY(FIELD, ENTRY, VALUE, RANGE)                           \
-  if (!isUInt<ENTRY##_WIDTH>(VALUE))                                           \
+  if (!isUInt<ENTRY##_WIDTH>(Val))                                             \
     return OutOfRangeError(RANGE);                                             \
-  AMDHSA_BITS_SET(FIELD, ENTRY, VALUE);
+  kernel_descriptor_t::bits_set(FIELD, VALUE, ENTRY##_SHIFT, ENTRY,            \
+                                getContext());
+
+#define EXPR_SHOULD_RESOLVE()                                                  \
+  if (!EvaluatableExpr)                                                        \
+    return Error(IDRange.Start, "directive should have resolvable expression", \
+                 IDRange);
----------------
arsenm wrote:

I don't like this macro relying on a random local variable. Why is this only an error for certain fields? 

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


More information about the llvm-commits mailing list