mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-27 15:57:13 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10889 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d5c59d5c84
commit
0baa0af861
@ -164,7 +164,8 @@ void BytecodeWriter::outputConstantsInPlane(const std::vector<const Value*>
|
|||||||
void BytecodeWriter::outputConstants(bool isFunction) {
|
void BytecodeWriter::outputConstants(bool isFunction) {
|
||||||
ConstantTotalBytes -= Out.size();
|
ConstantTotalBytes -= Out.size();
|
||||||
if (isFunction) FunctionConstantTotalBytes -= 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();
|
unsigned NumPlanes = Table.getNumPlanes();
|
||||||
|
|
||||||
@ -286,7 +287,8 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
|
|||||||
|
|
||||||
SymTabBytes -= Out.size();
|
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) {
|
for (SymbolTable::const_iterator TI = MST.begin(); TI != MST.end(); ++TI) {
|
||||||
SymbolTable::type_const_iterator I = MST.type_begin(TI->first);
|
SymbolTable::type_const_iterator I = MST.type_begin(TI->first);
|
||||||
|
@ -50,27 +50,41 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// BytecodeBlock - Little helper class that helps us do backpatching of bytecode
|
/// BytecodeBlock - Little helper class is used by the bytecode writer to help
|
||||||
// block sizes really easily. It backpatches when it goes out of scope.
|
/// do backpatching of bytecode block sizes really easily. It backpatches when
|
||||||
//
|
/// it goes out of scope.
|
||||||
|
///
|
||||||
class BytecodeBlock {
|
class BytecodeBlock {
|
||||||
unsigned Loc;
|
unsigned Loc;
|
||||||
std::deque<unsigned char> &Out;
|
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
|
BytecodeBlock(const BytecodeBlock &); // do not implement
|
||||||
void operator=(const BytecodeBlock &); // do not implement
|
void operator=(const BytecodeBlock &); // do not implement
|
||||||
public:
|
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(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();
|
Loc = Out.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ~BytecodeBlock() { // Do backpatch when block goes out
|
inline ~BytecodeBlock() { // Do backpatch when block goes out
|
||||||
// of scope...
|
// 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 = "
|
//cerr << "OldLoc = " << Loc << " NewLoc = " << NewLoc << " diff = "
|
||||||
// << (NewLoc-Loc) << endl;
|
// << (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
|
align32(Out); // Blocks must ALWAYS be aligned
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user