[llvm] r215086 - Change the { } expression in tablegen to accept sized binary literals which are not just 0 and 1.
Pete Cooper
peter_cooper at apple.com
Wed Aug 6 22:47:07 PDT 2014
Author: pete
Date: Thu Aug 7 00:47:07 2014
New Revision: 215086
URL: http://llvm.org/viewvc/llvm-project?rev=215086&view=rev
Log:
Change the { } expression in tablegen to accept sized binary literals which are not just 0 and 1.
It also allows nested { } expressions, as now that they are sized, we can merge pull bits from the nested value.
In the current behaviour, everything in { } must have been convertible to a single bit.
However, now that binary literals are sized, its useful to be able to initialize a range of bits.
So, for example, its now possible to do
bits<8> x = { 0, 1, { 0b1001 }, 0, 0b0 }
Modified:
llvm/trunk/lib/TableGen/TGParser.cpp
llvm/trunk/test/TableGen/BitsInit.td
Modified: llvm/trunk/lib/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=215086&r1=215085&r2=215086&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)
+++ llvm/trunk/lib/TableGen/TGParser.cpp Thu Aug 7 00:47:07 2014
@@ -1302,17 +1302,28 @@ Init *TGParser::ParseSimpleValue(Record
}
Lex.Lex(); // eat the '}'
- SmallVector<Init *, 16> NewBits(Vals.size());
+ SmallVector<Init *, 16> NewBits;
+ // As we parse { a, b, ... }, 'a' is the highest bit, but we parse it
+ // first. We'll first read everything in to a vector, then we can reverse
+ // it to get the bits in the correct order for the BitsInit value.
for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
+ // bits<n> values are allowed to initialize n bits.
+ if (BitsInit *BI = dyn_cast<BitsInit>(Vals[i])) {
+ for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
+ NewBits.push_back(BI->getBit((e - i) - 1));
+ continue;
+ }
+ // All other values must be convertible to just a single bit.
Init *Bit = Vals[i]->convertInitializerTo(BitRecTy::get());
if (!Bit) {
Error(BraceLoc, "Element #" + utostr(i) + " (" + Vals[i]->getAsString()+
") is not convertable to a bit");
return nullptr;
}
- NewBits[Vals.size()-i-1] = Bit;
+ NewBits.push_back(Bit);
}
+ std::reverse(NewBits.begin(), NewBits.end());
return BitsInit::get(NewBits);
}
case tgtok::l_square: { // Value ::= '[' ValueList ']'
Modified: llvm/trunk/test/TableGen/BitsInit.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/BitsInit.td?rev=215086&r1=215085&r2=215086&view=diff
==============================================================================
--- llvm/trunk/test/TableGen/BitsInit.td (original)
+++ llvm/trunk/test/TableGen/BitsInit.td Thu Aug 7 00:47:07 2014
@@ -40,6 +40,21 @@ def {
bits<8> E;
let E{7-0} = {0,0,1,?,?,?,?,?};
let E{3-0} = 0b0010;
+
+ bits<8> F1 = { 0, 1, 0b1001, 0, 0b0 }; // ok
+ bits<7> F2 = { 0, 1, 0b1001, 0, 0b0 }; // LHS doesn't have enough bits
+ bits<9> F3 = { 0, 1, 0b1001, 0, 0b0 }; // RHS doesn't have enough bits
+
+ bits<8> G1 = { 0, { 1, 0b1001, 0 }, 0b0 }; // ok
+ bits<8> G2 = { 0, { 1, 0b1001 }, 0, 0b0 }; // ok
+ bits<8> G3 = { 0, 1, { 0b1001 }, 0, 0b0 }; // ok
+
+ bits<16> H;
+ let H{15-0} = { { 0b11001100 }, 0b00110011 };
+
+ // Make sure we can initialise ints with bits<> values.
+ int J = H;
+ int K = { 0, 1 };
}
// CHECK: def {{.*}} {
@@ -56,4 +71,13 @@ def {
// CHECK: bits<1> D7 = { ? };
// CHECK: bits<2> D8;
// CHECK: bits<8> E = { 0, 0, 1, ?, 0, 0, 1, 0 };
+// CHECK: bits<8> F1 = { 0, 1, 1, 0, 0, 1, 0, 0 };
+// CHECK: bits<7> F2;
+// CHECK: bits<9> F3;
+// CHECK: bits<8> G1 = { 0, 1, 1, 0, 0, 1, 0, 0 };
+// CHECK: bits<8> G2 = { 0, 1, 1, 0, 0, 1, 0, 0 };
+// CHECK: bits<8> G3 = { 0, 1, 1, 0, 0, 1, 0, 0 };
+// CHECK: bits<16> H = { 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 };
+// CHECK: int J = 52275;
+// CHECK: int K = 1;
// CHECK: }
More information about the llvm-commits
mailing list