[llvm] r323807 - [TableGen] Make sure !if is evaluated throughout class inheritance.

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 30 11:29:21 PST 2018


Author: tra
Date: Tue Jan 30 11:29:21 2018
New Revision: 323807

URL: http://llvm.org/viewvc/llvm-project?rev=323807&view=rev
Log:
[TableGen] Make sure !if is evaluated throughout class inheritance.

Without the patch !if() is only evaluated if it's used directly.
If it's passed through more than one level of class inheritance,
we end up with a reference to an anonymous record with unresolved
references to the original arguments !if may have used.

The root cause of the problem is that TernOpInit::isComplete()
was always returning false and that prevented use of the folded
value of !if() as an initializer for the record at the next level
of inheritance.

Differential Revision: https://reviews.llvm.org/D42695

Modified:
    llvm/trunk/include/llvm/TableGen/Record.h
    llvm/trunk/test/TableGen/if.td

Modified: llvm/trunk/include/llvm/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/Record.h?rev=323807&r1=323806&r2=323807&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/Record.h (original)
+++ llvm/trunk/include/llvm/TableGen/Record.h Tue Jan 30 11:29:21 2018
@@ -905,7 +905,9 @@ public:
   // possible to fold.
   Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
 
-  bool isComplete() const override { return false; }
+  bool isComplete() const override {
+    return LHS->isComplete() && MHS->isComplete() && RHS->isComplete();
+  }
 
   Init *resolveReferences(Record &R, const RecordVal *RV) const override;
 

Modified: llvm/trunk/test/TableGen/if.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/if.td?rev=323807&r1=323806&r2=323807&view=diff
==============================================================================
--- llvm/trunk/test/TableGen/if.td (original)
+++ llvm/trunk/test/TableGen/if.td Tue Jan 30 11:29:21 2018
@@ -56,6 +56,23 @@ def D128: S<128>;
 // CHECK: def D8
 // CHECK-NEXT: bits<2> val = { 0, 0 };
 
+// Make sure !if gets propagated across multiple layers of inheritance.
+class getInt<int c> {
+  int ret = !if(c, 0, 1);
+}
+class I1<int c> {
+  int i = getInt<c>.ret;
+}
+class I2<int c> : I1<c>;
+
+// CHECK: def DI1 {     // I1
+// CHECK-NEXT: int i = 0;
+def DI1: I1<1>;
+
+// CHECK: def DI2 {     // I1 I2
+// CHECK-NEXT: int i = 0;
+def DI2: I2<1>;
+
 // CHECK:      def One
 // CHECK-NEXT: list<int> first = [1, 2, 3];
 // CHECK-NEXT: list<int> rest = [1, 2, 3];




More information about the llvm-commits mailing list