[llvm] [TableGen] Resolve arguments with fields in records (PR #107829)

Akshat Oke via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 15 23:40:59 PDT 2024


================
@@ -2289,9 +2289,12 @@ class RecordResolver final : public Resolver {
   DenseMap<Init *, Init *> Cache;
   SmallVector<Init *, 4> Stack;
   Init *Name = nullptr;
+  // Cache is for fields, ArgumentResolver is for arguments.
+  MapResolver *ArgumentResolver;
 
 public:
-  explicit RecordResolver(Record &R) : Resolver(&R) {}
+  explicit RecordResolver(Record &R, MapResolver *ArgumentResolver = nullptr)
----------------
Akshat-Oke wrote:

Yes, that would be ideal since the two-step resolution happens everywhere (in `def R : C<n>` as well).

This limitation of inaccessible arguments has forced the `!if` resolution to forego short-circuiting and resolve the MHS and RHS regardless of the condition. And so, the following case fails with a stack overflow:
```
class C<int n> {
    int v = n; 
    // !if ignores v==0 and evaluates C<n-1>.ret everytime
    // Ideally should short-circuit to 3
    int ret = !if(!eq(v, 0), 3, C<!sub(n, 1)>.ret);
}
def R : C<0>;
```

I think `Record` should contain arguments from each sub-class along with their fields as usual. Will see how that goes.

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


More information about the llvm-commits mailing list