[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Reader.cpp ReaderInternals.h

Chris Lattner lattner at cs.uiuc.edu
Mon Dec 1 01:06:02 PST 2003


Changes in directory llvm/lib/Bytecode/Reader:

Reader.cpp updated: 1.90 -> 1.91
ReaderInternals.h updated: 1.68 -> 1.69

---
Log message:

Emit & read more compressed bytecode by not emitting a bytecodeblock for
each basic block in function.  Instead, just emit a stream of instructions,
chopping up basic blocks based on when we find terminator instructions.  This
saves a fairly substantial chunk of bytecode space.  In stripped, sample 
cases, for example, we get this reduction in size:

197.parser: 163036 -> 137180:  18.8% reduction
254.gap   : 844936 -> 689392:  22.6%
255.vortex: 621724 -> 528444:  17.7%

...

Not bad for something this simple.  :)  Note that this doesn't require a new
bytecode version number at all, though version 1.1 should not need to support 
the old format.



---
Diffs of the changes:  (+44 -2)

Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.90 llvm/lib/Bytecode/Reader/Reader.cpp:1.91
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.90	Wed Nov 19 11:27:18 2003
+++ llvm/lib/Bytecode/Reader/Reader.cpp	Mon Dec  1 01:05:30 2003
@@ -188,7 +188,8 @@
   }
 }
 
-
+/// ParseBasicBlock - In LLVM 1.0 bytecode files, we used to output one
+/// basicblock at a time.  This method reads in one of the basicblock packets.
 BasicBlock *BytecodeParser::ParseBasicBlock(const unsigned char *&Buf,
                                             const unsigned char *EndBuf,
                                             unsigned BlockNo) {
@@ -207,6 +208,38 @@
   return BB;
 }
 
+
+/// ParseInstructionList - Parse all of the BasicBlock's & Instruction's in the
+/// body of a function.  In post 1.0 bytecode files, we no longer emit basic
+/// block individually, in order to avoid per-basic-block overhead.
+unsigned BytecodeParser::ParseInstructionList(Function *F,
+                                              const unsigned char *&Buf,
+                                              const unsigned char *EndBuf) {
+  unsigned BlockNo = 0;
+  std::vector<unsigned> Args;
+
+  while (Buf < EndBuf) {
+    BasicBlock *BB;
+    if (ParsedBasicBlocks.size() == BlockNo)
+      ParsedBasicBlocks.push_back(BB = new BasicBlock());
+    else if (ParsedBasicBlocks[BlockNo] == 0)
+      BB = ParsedBasicBlocks[BlockNo] = new BasicBlock();
+    else
+      BB = ParsedBasicBlocks[BlockNo];
+    ++BlockNo;
+    F->getBasicBlockList().push_back(BB);
+
+    // Read instructions into this basic block until we get to a terminator
+    while (Buf < EndBuf && !BB->getTerminator())
+      ParseInstruction(Buf, EndBuf, Args, BB);
+
+    if (!BB->getTerminator())
+      throw std::string("Non-terminated basic block found!");
+  }
+
+  return BlockNo;
+}
+
 void BytecodeParser::ParseSymbolTable(const unsigned char *&Buf,
                                       const unsigned char *EndBuf,
                                       SymbolTable *ST,
@@ -342,6 +375,13 @@
       BCR_TRACE(2, "BLOCK BytecodeFormat::BasicBlock: {\n");
       BasicBlock *BB = ParseBasicBlock(Buf, Buf+Size, BlockNum++);
       F->getBasicBlockList().push_back(BB);
+      break;
+    }
+
+    case BytecodeFormat::InstructionList: {
+      BCR_TRACE(2, "BLOCK BytecodeFormat::InstructionList: {\n");
+      if (BlockNum) throw std::string("Already parsed basic blocks!");
+      BlockNum = ParseInstructionList(F, Buf, Buf+Size);
       break;
     }
 


Index: llvm/lib/Bytecode/Reader/ReaderInternals.h
diff -u llvm/lib/Bytecode/Reader/ReaderInternals.h:1.68 llvm/lib/Bytecode/Reader/ReaderInternals.h:1.69
--- llvm/lib/Bytecode/Reader/ReaderInternals.h:1.68	Wed Nov 19 11:27:18 2003
+++ llvm/lib/Bytecode/Reader/ReaderInternals.h	Mon Dec  1 01:05:30 2003
@@ -162,7 +162,9 @@
   BasicBlock *ParseBasicBlock(const unsigned char *&Buf,
                               const unsigned char *End,
                               unsigned BlockNo);
-
+  unsigned ParseInstructionList(Function *F, const unsigned char *&Buf,
+                                const unsigned char *EndBuf);
+  
   void ParseInstruction(const unsigned char *&Buf, const unsigned char *End,
                         std::vector<unsigned> &Args, BasicBlock *BB);
 





More information about the llvm-commits mailing list