[llvm] r215087 - Update BitRecTy::convertValue to allow if expressions with bit values on both sides of the if

Pete Cooper peter_cooper at apple.com
Wed Aug 6 22:47:10 PDT 2014


Author: pete
Date: Thu Aug  7 00:47:10 2014
New Revision: 215087

URL: http://llvm.org/viewvc/llvm-project?rev=215087&view=rev
Log:
Update BitRecTy::convertValue to allow if expressions with bit values on both sides of the if

Modified:
    llvm/trunk/lib/TableGen/Record.cpp
    llvm/trunk/test/TableGen/ifbit.td

Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=215087&r1=215086&r2=215087&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Thu Aug  7 00:47:10 2014
@@ -119,6 +119,16 @@ Init *BitRecTy::convertValue(TypedInit *
   if (auto *BitsTy = dyn_cast<BitsRecTy>(Ty))
     // Accept only bits<1> expression.
     return BitsTy->getNumBits() == 1 ? VI : nullptr;
+  // Ternary !if can be converted to bit, but only if both sides are
+  // convertible to a bit.
+  if (TernOpInit *TOI = dyn_cast<TernOpInit>(VI)) {
+    if (TOI->getOpcode() != TernOpInit::TernaryOp::IF)
+      return nullptr;
+    if (!TOI->getMHS()->convertInitializerTo(BitRecTy::get()) ||
+        !TOI->getRHS()->convertInitializerTo(BitRecTy::get()))
+      return nullptr;
+    return TOI;
+  }
   return nullptr;
 }
 

Modified: llvm/trunk/test/TableGen/ifbit.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/ifbit.td?rev=215087&r1=215086&r2=215087&view=diff
==============================================================================
--- llvm/trunk/test/TableGen/ifbit.td (original)
+++ llvm/trunk/test/TableGen/ifbit.td Thu Aug  7 00:47:10 2014
@@ -5,6 +5,8 @@
 
 class A<bit b = 1> {
   int a = !if(b, 5, 6);
+  bit c = !if(b, 0, 1);
+  bits<1> d = !if(b, 0, 1);
 }
 
 def X : A<0>;





More information about the llvm-commits mailing list