llvm.org GIT mirror
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 } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215086 91177308-0d34-0410-b5e6-96231b3b80d8 Pete Cooper 5 years ago
2 changed file(s) with 39 addition(s) and 4 deletion(s).
 1301 1301 } 1302 1302 Lex.Lex(); // eat the '}' 1303 1303 1304 SmallVector NewBits(Vals.size()); 1305 ⏎ 1304 SmallVector NewBits;⏎ 1305 1306 // As we parse { a, b, ... }, 'a' is the highest bit, but we parse it 1307 // first. We'll first read everything in to a vector, then we can reverse 1308 // it to get the bits in the correct order for the BitsInit value. 1306 1309 for (unsigned i = 0, e = Vals.size(); i != e; ++i) { 1310 // bits values are allowed to initialize n bits. 1311 if (BitsInit *BI = dyn_cast(Vals[i])) { 1312 for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i) 1313 NewBits.push_back(BI->getBit((e - i) - 1)); 1314 continue; 1315 } 1316 // All other values must be convertible to just a single bit. 1307 1317 Init *Bit = Vals[i]->convertInitializerTo(BitRecTy::get()); 1308 1318 if (!Bit) { 1309 1319 Error(BraceLoc, "Element #" + utostr(i) + " (" + Vals[i]->getAsString()+ 1310 1320 ") is not convertable to a bit"); 1311 1321 return nullptr; 1312 1322 } 1313 NewBits[Vals.size()-i-1] = Bit; 1314 }⏎ 1323 NewBits.push_back(Bit);⏎ 1324 } 1325 std::reverse(NewBits.begin(), NewBits.end()); 1315 1326 return BitsInit::get(NewBits); 1316 1327 } 1317 1328 case tgtok::l_square: { // Value ::= '[' ValueList ']'
 39 39 bits<8> E; 40 40 let E{7-0} = {0,0,1,?,?,?,?,?}; 41 41 let E{3-0} = 0b0010; 42 43 bits<8> F1 = { 0, 1, 0b1001, 0, 0b0 }; // ok 44 bits<7> F2 = { 0, 1, 0b1001, 0, 0b0 }; // LHS doesn't have enough bits 45 bits<9> F3 = { 0, 1, 0b1001, 0, 0b0 }; // RHS doesn't have enough bits 46 47 bits<8> G1 = { 0, { 1, 0b1001, 0 }, 0b0 }; // ok 48 bits<8> G2 = { 0, { 1, 0b1001 }, 0, 0b0 }; // ok 49 bits<8> G3 = { 0, 1, { 0b1001 }, 0, 0b0 }; // ok 50 51 bits<16> H; 52 let H{15-0} = { { 0b11001100 }, 0b00110011 }; 53 54 // Make sure we can initialise ints with bits<> values. 55 int J = H; 56 int K = { 0, 1 }; 42 57 } 43 58 44 59 // CHECK: def {{.*}} { 55 70 // CHECK: bits<1> D7 = { ? }; 56 71 // CHECK: bits<2> D8; 57 72 // CHECK: bits<8> E = { 0, 0, 1, ?, 0, 0, 1, 0 }; 73 // CHECK: bits<8> F1 = { 0, 1, 1, 0, 0, 1, 0, 0 }; 74 // CHECK: bits<7> F2; 75 // CHECK: bits<9> F3; 76 // CHECK: bits<8> G1 = { 0, 1, 1, 0, 0, 1, 0, 0 }; 77 // CHECK: bits<8> G2 = { 0, 1, 1, 0, 0, 1, 0, 0 }; 78 // CHECK: bits<8> G3 = { 0, 1, 1, 0, 0, 1, 0, 0 }; 79 // CHECK: bits<16> H = { 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 }; 80 // CHECK: int J = 52275; 81 // CHECK: int K = 1; 58 82 // CHECK: }