We always bounds check the bit set, there is no need to emit zero bytes at the end.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 23 Jul 2011 02:49:37 +0000 (02:49 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 23 Jul 2011 02:49:37 +0000 (02:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135841 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/RegisterInfoEmitter.cpp

index 8ec45d41f27a698bb5c5e28b22ad59e944071467..f56dcd5b8c596e26ebd65f5ada22d30f38d5c3fa 100644 (file)
@@ -206,23 +206,20 @@ RegisterInfoEmitter::EmitRegMapping(raw_ostream &OS,
 // Helper to emit a set of bits into a constant byte array.
 class BitVectorEmitter {
   BitVector Values;
-  unsigned Len;
 public:
-  BitVectorEmitter(unsigned L) : Len(L%8 ? ((L/8)+1)*8 : L) {
-    Values.resize(Len);
+  void add(unsigned v) {
+    if (v >= Values.size())
+      Values.resize(((v/8)+1)*8); // Round up to the next byte.
+    Values[v] = true;
   }
 
-  void add(unsigned v) { Values[v] = true; }
-
   void print(raw_ostream &OS) {
-    for (unsigned i = 0, e = Len / 8; i != e; ++i) {
+    for (unsigned i = 0, e = Values.size() / 8; i != e; ++i) {
       unsigned char out = 0;
-      for (unsigned ii = 0, ie = 8; ii != ie; ++ii)
-        if (Values[i * 8 + ii])
-          out |= 1 << ii;
-      OS << "0x";
-      OS.write_hex(out);
-      OS << ", ";
+      for (unsigned j = 0; j != 8; ++j)
+        if (Values[i * 8 + j])
+          out |= 1 << j;
+      OS << format("0x%02x, ", out);
     }
   }
 };
@@ -349,7 +346,7 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target,
     OS << "  // " << Name << " Bit set.\n"
        << "  static const unsigned char " << Name
        << "Bits[] = {\n    ";
-    BitVectorEmitter BVE(Target.getRegBank().getRegisters().size()+1);
+    BitVectorEmitter BVE;
     for (unsigned i = 0, e = Order.size(); i != e; ++i) {
       Record *Reg = Order[i];
       BVE.add(Target.getRegBank().getReg(Reg)->EnumValue);