[llvm] [TableGen] Add let append/prepend syntax for field concatenation (PR #182382)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 6 08:15:50 PST 2026
================
@@ -0,0 +1,219 @@
+// RUN: llvm-tblgen %s | FileCheck %s
+// XFAIL: vg_leak
+
+// Test 'let append' and 'let prepend' syntax.
+
+def op;
+
+class Base {
+ list<int> items = [1, 2];
+ string text = "hello";
+ dag d = (op);
+}
+
+class WithCode {
+ code body = [{ int x = 0; }];
+}
+
+class WithUnset {
+ list<int> vals = ?;
+ string msg = ?;
+}
+
+// Multi-level inheritance accumulation.
+class Middle : Base {
+ let append items = [3];
+ let append text = " world";
+}
+
+// Multiple inheritance classes.
+class BaseA {
+ list<int> items = [1, 2];
+ string text = "a";
+}
+
+class BaseB {
+ list<int> items = [3, 4];
+ string text = "b";
+}
+
+// Diamond inheritance classes.
+class DiamondBase {
+ list<int> items = [1];
+}
+
+class Left : DiamondBase {
+ let append items = [2]; // items = [1, 2]
+}
+
+class Right : DiamondBase {
+ let append items = [3]; // items = [1, 3]
+}
+
+// Template argument class.
+class Parameterized<list<int> init> {
+ list<int> items = init;
+}
+
+// Multiclass with append/prepend in body.
+multiclass MC<list<int> extra> {
+ def _a : Base {
+ let append items = extra;
+ }
+ def _b : Base {
+ let prepend items = extra;
+ }
+}
+
+// Test that 'append' and 'prepend' can be used as field names
+// (contextual keywords, not reserved).
+class HasAppendField {
+ list<int> append = [1, 2];
+ list<int> prepend = [3, 4];
+}
+
+// --- Definitions (CHECK lines in alphabetical order of def names) ---
+
+// CHECK: def AppendCode
+// CHECK: code body = [{ int x = 0; int y = 1; }]
+def AppendCode : WithCode {
+ let append body = [{ int y = 1; }];
+}
+
+// CHECK: def AppendDag
+// CHECK: dag d = (op 3:$a);
+def AppendDag : Base {
+ let append d = (op 3:$a);
+}
+
+// CHECK: def AppendList
+// CHECK: list<int> items = [1, 2, 3, 4];
+def AppendList : Base {
+ let append items = [3, 4];
+}
+
+// CHECK: def AppendString
+// CHECK: string text = "hello world";
+def AppendString : Base {
+ let append text = " world";
+}
+
+// CHECK: def AppendUnset
+// CHECK: list<int> vals = [1];
+// CHECK: string msg = "hi";
+def AppendUnset : WithUnset {
+ let append vals = [1];
+ let append msg = "hi";
+}
+
+// Test sequential append + prepend on the same field.
+// CHECK: def Both
+// CHECK: list<int> items = [0, 1, 2, 3];
+def Both : Base {
+ let append items = [3];
+ let prepend items = [0];
+}
+
+// CHECK: def ContextualKeyword
+// CHECK: list<int> append = [1, 2, 5];
+// CHECK: list<int> prepend = [0, 3, 4];
+def ContextualKeyword : HasAppendField {
+ let append append = [5];
----------------
jurahul wrote:
Looks like you already have these unit tests :) What about similar tests for top-level let?
https://github.com/llvm/llvm-project/pull/182382
More information about the llvm-commits
mailing list