<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 29, 2014, at 1:27 PM, Sean Silva <<a href="mailto:chisophugis@gmail.com" class="">chisophugis@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><br class=""><div class="gmail_quote">On Fri, Aug 29, 2014 at 12:41 PM, Jean-Luc Duprat <span dir="ltr" class=""><<a href="mailto:jduprat@apple.com" target="_blank" class="">jduprat@apple.com</a>></span> wrote:<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: jduprat<br class="">
Date: Fri Aug 29 14:41:04 2014<br class="">
New Revision: 216757<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=216757&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=216757&view=rev</a><br class="">
Log:<br class="">
Tablegen fixes for new syntax when initializing bits from variables.<br class="">
Followup to r215086.<br class="">
<br class="">
<br class="">
Modified:<br class="">
    llvm/trunk/lib/TableGen/TGParser.cpp<br class="">
    llvm/trunk/test/TableGen/BitsInit.td<br class="">
<br class="">
Modified: llvm/trunk/lib/TableGen/TGParser.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=216757&r1=216756&r2=216757&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=216757&r1=216756&r2=216757&view=diff</a><br class="">

==============================================================================<br class="">
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)<br class="">
+++ llvm/trunk/lib/TableGen/TGParser.cpp Fri Aug 29 14:41:04 2014<br class="">
@@ -1321,6 +1321,15 @@ Init *TGParser::ParseSimpleValue(Record<br class="">
           NewBits.push_back(BI->getBit((e - i) - 1));<br class="">
         continue;<br class="">
       }<br class="">
+      // bits<n> can also come from variable initializers.<br class="">
+      if (VarInit *VI = dyn_cast<VarInit>(Vals[i])) {<br class="">
+        if (BitsRecTy *BitsRec = dyn_cast<BitsRecTy>(VI->getType())) {<br class="">
+          for (unsigned i = 0, e = BitsRec->getNumBits(); i != e; ++i)<br class="">
+            NewBits.push_back(VI->getBit((e - i) - 1));<br class="">
+          continue;<br class="">
+        }<br class="">
+        // Fallthrough to try convert this to a bit.<br class="">
+      }<br class=""></blockquote><div class=""><br class=""></div><div class="">Please add a FIXME to this loop for removing the duplication with the one just above. That is a valuable use case that reduces the problem space for refactoring the Record.h API's.</div>
<div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
       // All other values must be convertible to just a single bit.<br class="">
       Init *Bit = Vals[i]->convertInitializerTo(BitRecTy::get());<br class="">
       if (!Bit) {<br class="">
<br class="">
Modified: llvm/trunk/test/TableGen/BitsInit.td<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/BitsInit.td?rev=216757&r1=216756&r2=216757&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/BitsInit.td?rev=216757&r1=216756&r2=216757&view=diff</a><br class="">

==============================================================================<br class="">
--- llvm/trunk/test/TableGen/BitsInit.td (original)<br class="">
+++ llvm/trunk/test/TableGen/BitsInit.td Fri Aug 29 14:41:04 2014<br class="">
@@ -16,7 +16,7 @@ def a {<br class="">
 // CHECK:   bits<2> opc = { 0, 1 };<br class="">
 // CHECK:   bits<2> opc2 = { 1, 0 };<br class="">
 // CHECK:   bits<1> opc3 = { 1 };<br class="">
-// CHECK:   bits<2> a = { ?, ? };<br class="">
+// CHECK:   bits<2> a;<br class=""></blockquote><div class=""><br class=""></div><div class="">Can you provide an explanation for why this is printing differently with this patch?</div></div></div></div></div></blockquote>I took a look at this for Jean-Luc.</div><div><br class=""></div><div>What I think is happening is that we used to reject constructing { opc, opc2 } because they were both bits<n> variables.  This caused us to hit the error when parsing the contents of { }, i.e.,</div><div><br class=""></div><div>Error(BraceLoc, "Element #" + utostr(i) + " (" + Vals[i]->getAsString()+<br class="">              ") is not convertable to a bit”);</div><div><br class=""></div><div>Now, we don’t hit that error, but instead construct a bits<4> value for the RHS of the assignment.  Later we get to setValue to try assign that to bits<2> a.  This fails because of a size mismatch and reports:</div><div><br class=""></div><div>      InitType = (Twine("' of type bit initializer with length ") +<br class="">                  Twine(BI->getNumBits())).str();</div><div><br class=""></div><div>Now for a little guessing, I believe in the original case, if we threw an error in { } parsing, we have (construct?) a default { ?, ? } value for ‘a’.  With this change, given that we throw an error in setValue, it looks like we no longer attach any initializer to ‘a’ as this is the method that was going to actually set it.</div><div><br class=""></div><div>Now whether we want to put { ?, ? } on ‘a’ in either or both cases is a valid question.  Given that there are errors in either case, i’m not too worried, as users are going to have to fix the errors anyway.</div><div><br class=""></div><div>Thanks,</div><div>Pete<br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">-- Sean Silva</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

 // CHECK:   bits<2> b = { 1, 0 };<br class="">
 // CHECK:   bits<2> c = { 1, 1 };<br class="">
 // CHECK: }<br class="">
@@ -51,6 +51,7 @@ def {<br class="">
<br class="">
   bits<16> H;<br class="">
   let H{15-0} = { { 0b11001100 }, 0b00110011 };<br class="">
+  bits<16> I = { G1, G2 };<br class="">
<br class="">
   // Make sure we can initialise ints with bits<> values.<br class="">
   int J = H;<br class="">
@@ -78,6 +79,7 @@ def {<br class="">
 // CHECK: bits<8> G2 = { 0, 1, 1, 0, 0, 1, 0, 0 };<br class="">
 // CHECK: bits<8> G3 = { 0, 1, 1, 0, 0, 1, 0, 0 };<br class="">
 // CHECK: bits<16> H = { 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 };<br class="">
+// CHECK: bits<16> I = { 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0 };<br class="">
 // CHECK: int J = 52275;<br class="">
 // CHECK: int K = 1;<br class="">
 // CHECK: }<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class="">
</blockquote></div><br class=""></div></div>
_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br class=""></div></blockquote></div><br class=""></body></html>