[llvm-commits] CVS: llvm/lib/Bytecode/Writer/Writer.cpp WriterInternals.h
Chris Lattner
lattner at cs.uiuc.edu
Thu Jan 15 15:08:12 PST 2004
Changes in directory llvm/lib/Bytecode/Writer:
Writer.cpp updated: 1.54 -> 1.55
WriterInternals.h updated: 1.17 -> 1.18
---
Log message:
If these blocks are empty, there is no reason to even emit the bytecode blocks.
This saves about 15K in 176.gcc, coupled with another patch that I'm working on.
---
Diffs of the changes: (+24 -8)
Index: llvm/lib/Bytecode/Writer/Writer.cpp
diff -u llvm/lib/Bytecode/Writer/Writer.cpp:1.54 llvm/lib/Bytecode/Writer/Writer.cpp:1.55
--- llvm/lib/Bytecode/Writer/Writer.cpp:1.54 Thu Jan 15 11:55:09 2004
+++ llvm/lib/Bytecode/Writer/Writer.cpp Thu Jan 15 15:06:57 2004
@@ -164,7 +164,8 @@
void BytecodeWriter::outputConstants(bool isFunction) {
ConstantTotalBytes -= Out.size();
if (isFunction) FunctionConstantTotalBytes -= Out.size();
- BytecodeBlock CPool(BytecodeFormat::ConstantPool, Out);
+ BytecodeBlock CPool(BytecodeFormat::ConstantPool, Out,
+ true /* Elide block if empty */);
unsigned NumPlanes = Table.getNumPlanes();
@@ -286,7 +287,8 @@
SymTabBytes -= Out.size();
- BytecodeBlock SymTabBlock(BytecodeFormat::SymbolTable, Out);
+ BytecodeBlock SymTabBlock(BytecodeFormat::SymbolTable, Out,
+ true/* ElideIfEmpty*/);
for (SymbolTable::const_iterator TI = MST.begin(); TI != MST.end(); ++TI) {
SymbolTable::type_const_iterator I = MST.type_begin(TI->first);
Index: llvm/lib/Bytecode/Writer/WriterInternals.h
diff -u llvm/lib/Bytecode/Writer/WriterInternals.h:1.17 llvm/lib/Bytecode/Writer/WriterInternals.h:1.18
--- llvm/lib/Bytecode/Writer/WriterInternals.h:1.17 Wed Jan 14 17:36:54 2004
+++ llvm/lib/Bytecode/Writer/WriterInternals.h Thu Jan 15 15:06:57 2004
@@ -50,27 +50,41 @@
-// BytecodeBlock - Little helper class that helps us do backpatching of bytecode
-// block sizes really easily. It backpatches when it goes out of scope.
-//
+/// BytecodeBlock - Little helper class is used by the bytecode writer to help
+/// do backpatching of bytecode block sizes really easily. It backpatches when
+/// it goes out of scope.
+///
class BytecodeBlock {
unsigned Loc;
std::deque<unsigned char> &Out;
+ /// ElideIfEmpty - If this is true and the bytecode block ends up being empty,
+ /// the block can remove itself from the output stream entirely.
+ bool ElideIfEmpty;
+
BytecodeBlock(const BytecodeBlock &); // do not implement
void operator=(const BytecodeBlock &); // do not implement
public:
- inline BytecodeBlock(unsigned ID, std::deque<unsigned char> &o) : Out(o) {
+ inline BytecodeBlock(unsigned ID, std::deque<unsigned char> &o,
+ bool elideIfEmpty = false)
+ : Out(o), ElideIfEmpty(elideIfEmpty) {
output(ID, Out);
- output((unsigned)0, Out); // Reserve the space for the block size...
+ output(0U, Out); // Reserve the space for the block size...
Loc = Out.size();
}
inline ~BytecodeBlock() { // Do backpatch when block goes out
// of scope...
+ if (Loc == Out.size() && ElideIfEmpty) {
+ // If the block is empty, and we are allowed to, do not emit the block at
+ // all!
+ Out.resize(Out.size()-8);
+ return;
+ }
+
//cerr << "OldLoc = " << Loc << " NewLoc = " << NewLoc << " diff = "
// << (NewLoc-Loc) << endl;
- output((unsigned)(Out.size()-Loc), Out, (int)Loc-4);
+ output(unsigned(Out.size()-Loc), Out, int(Loc-4));
align32(Out); // Blocks must ALWAYS be aligned
}
};
More information about the llvm-commits
mailing list