[llvm-commits] [llvm] r106171 - in /llvm/trunk: docs/TableGenFundamentals.html test/TableGen/eqbit.td utils/TableGen/Record.cpp

Bruno Cardoso Lopes bruno.cardoso at gmail.com
Wed Jun 16 16:24:12 PDT 2010


Author: bruno
Date: Wed Jun 16 18:24:12 2010
New Revision: 106171

URL: http://llvm.org/viewvc/llvm-project?rev=106171&view=rev
Log:
let the '!eq' expression support 'int' and 'bit' types

Added:
    llvm/trunk/test/TableGen/eqbit.td
Modified:
    llvm/trunk/docs/TableGenFundamentals.html
    llvm/trunk/utils/TableGen/Record.cpp

Modified: llvm/trunk/docs/TableGenFundamentals.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/TableGenFundamentals.html?rev=106171&r1=106170&r2=106171&view=diff
==============================================================================
--- llvm/trunk/docs/TableGenFundamentals.html (original)
+++ llvm/trunk/docs/TableGenFundamentals.html Wed Jun 16 18:24:12 2010
@@ -425,8 +425,8 @@
   <dd>'b' if the result of integer operator 'a' is nonzero, 'c' otherwise.</dd>
 <dt><tt>!eq(a,b)</tt></dt>
   <dd>Integer one if string a is equal to string b, zero otherwise.  This
-      only operates on string objects.  Use !cast<string> to compare other
-      types of objects.</dd>
+      only operates on string, int and bit objects.  Use !cast<string> to
+      compare other types of objects.</dd>
 </dl>
 
 <p>Note that all of the values have rules specifying how they convert to values

Added: llvm/trunk/test/TableGen/eqbit.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/eqbit.td?rev=106171&view=auto
==============================================================================
--- llvm/trunk/test/TableGen/eqbit.td (added)
+++ llvm/trunk/test/TableGen/eqbit.td Wed Jun 16 18:24:12 2010
@@ -0,0 +1,11 @@
+// RUN: tblgen %s | FileCheck %s
+// XFAIL: vg_leak
+// CHECK: a = 6
+// CHECK: a = 5
+
+class A<bit b = 1> {
+  int a = !if(!eq(b, 1), 5, 6);
+}
+
+def X : A<0>;
+def Y : A;

Modified: llvm/trunk/utils/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.cpp?rev=106171&r1=106170&r2=106171&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.cpp (original)
+++ llvm/trunk/utils/TableGen/Record.cpp Wed Jun 16 18:24:12 2010
@@ -721,9 +721,20 @@
     break;
   }
   case EQ: {
-    // Make sure we've resolved
+    // try to fold eq comparison for 'bit' and 'int', otherwise fallback
+    // to string objects.
+    IntInit* L =
+      dynamic_cast<IntInit*>(LHS->convertInitializerTo(new IntRecTy()));
+    IntInit* R =
+      dynamic_cast<IntInit*>(RHS->convertInitializerTo(new IntRecTy()));
+
+    if (L && R)
+      return new IntInit(L->getValue() == R->getValue());
+
     StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
     StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
+
+    // Make sure we've resolved
     if (LHSs && RHSs)
       return new IntInit(LHSs->getValue() == RHSs->getValue());
 





More information about the llvm-commits mailing list