diff options
Diffstat (limited to 'lib/Bytecode/Writer')
-rw-r--r-- | lib/Bytecode/Writer/SlotCalculator.cpp | 36 | ||||
-rw-r--r-- | lib/Bytecode/Writer/SlotCalculator.h | 4 | ||||
-rw-r--r-- | lib/Bytecode/Writer/Writer.cpp | 35 | ||||
-rw-r--r-- | lib/Bytecode/Writer/WriterInternals.h | 4 |
4 files changed, 45 insertions, 34 deletions
diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp index cf770c4bbc..fdf7174b85 100644 --- a/lib/Bytecode/Writer/SlotCalculator.cpp +++ b/lib/Bytecode/Writer/SlotCalculator.cpp @@ -22,6 +22,7 @@ #include "llvm/Instructions.h" #include "llvm/Module.h" #include "llvm/SymbolTable.h" +#include "llvm/TypeSymbolTable.h" #include "llvm/Type.h" #include "llvm/Analysis/ConstantsScanner.h" #include "llvm/ADT/PostOrderIterator.h" @@ -189,13 +190,14 @@ void SlotCalculator::processModule() { } getOrCreateSlot(I->getType()); } - processSymbolTableConstants(&F->getSymbolTable()); + processSymbolTableConstants(&F->getValueSymbolTable()); } // Insert constants that are named at module level into the slot pool so that // the module symbol table can refer to them... SC_DEBUG("Inserting SymbolTable values:\n"); - processSymbolTable(&TheModule->getSymbolTable()); + processTypeSymbolTable(&TheModule->getTypeSymbolTable()); + processValueSymbolTable(&TheModule->getValueSymbolTable()); // Now that we have collected together all of the information relevant to the // module, compactify the type table if it is particularly big and outputting @@ -233,16 +235,18 @@ void SlotCalculator::processModule() { SC_DEBUG("end processModule!\n"); } +// processTypeSymbolTable - Insert all of the type sin the specified symbol +// table. +void SlotCalculator::processTypeSymbolTable(const TypeSymbolTable *ST) { + for (TypeSymbolTable::const_iterator TI = ST->begin(), TE = ST->end(); + TI != TE; ++TI ) + getOrCreateSlot(TI->second); +} + // processSymbolTable - Insert all of the values in the specified symbol table // into the values table... // -void SlotCalculator::processSymbolTable(const SymbolTable *ST) { - // Do the types first. - for (SymbolTable::type_const_iterator TI = ST->type_begin(), - TE = ST->type_end(); TI != TE; ++TI ) - getOrCreateSlot(TI->second); - - // Now do the values. +void SlotCalculator::processValueSymbolTable(const SymbolTable *ST) { for (SymbolTable::plane_const_iterator PI = ST->plane_begin(), PE = ST->plane_end(); PI != PE; ++PI) for (SymbolTable::value_const_iterator VI = PI->second.begin(), @@ -251,11 +255,6 @@ void SlotCalculator::processSymbolTable(const SymbolTable *ST) { } void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) { - // Do the types first - for (SymbolTable::type_const_iterator TI = ST->type_begin(), - TE = ST->type_end(); TI != TE; ++TI ) - getOrCreateSlot(TI->second); - // Now do the constant values in all planes for (SymbolTable::plane_const_iterator PI = ST->plane_begin(), PE = ST->plane_end(); PI != PE; ++PI) @@ -306,7 +305,7 @@ void SlotCalculator::incorporateFunction(const Function *F) { // symbol table references to constants not in the output. Scan for these // constants now. // - processSymbolTableConstants(&F->getSymbolTable()); + processSymbolTableConstants(&F->getValueSymbolTable()); } SC_DEBUG("Inserting Instructions:\n"); @@ -468,13 +467,8 @@ void SlotCalculator::buildCompactionTable(const Function *F) { getOrCreateCompactionTableSlot(I->getOperand(op)); } - // Do the types in the symbol table - const SymbolTable &ST = F->getSymbolTable(); - for (SymbolTable::type_const_iterator TI = ST.type_begin(), - TE = ST.type_end(); TI != TE; ++TI) - getOrCreateCompactionTableSlot(TI->second); - // Now do the constants and global values + const SymbolTable &ST = F->getValueSymbolTable(); for (SymbolTable::plane_const_iterator PI = ST.plane_begin(), PE = ST.plane_end(); PI != PE; ++PI) for (SymbolTable::value_const_iterator VI = PI->second.begin(), diff --git a/lib/Bytecode/Writer/SlotCalculator.h b/lib/Bytecode/Writer/SlotCalculator.h index e88a88f726..405c0edbd3 100644 --- a/lib/Bytecode/Writer/SlotCalculator.h +++ b/lib/Bytecode/Writer/SlotCalculator.h @@ -30,6 +30,7 @@ class Type; class Module; class Function; class SymbolTable; +class TypeSymbolTable; class ConstantArray; class SlotCalculator { @@ -168,7 +169,8 @@ private: // processSymbolTable - Insert all of the values in the specified symbol table // into the values table... // - void processSymbolTable(const SymbolTable *ST); + void processTypeSymbolTable(const TypeSymbolTable *ST); + void processValueSymbolTable(const SymbolTable *ST); void processSymbolTableConstants(const SymbolTable *ST); void buildCompactionTable(const Function *F); diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index 58cc13a141..37e4abfae2 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/lib/Bytecode/Writer/Writer.cpp @@ -27,6 +27,7 @@ #include "llvm/Instructions.h" #include "llvm/Module.h" #include "llvm/SymbolTable.h" +#include "llvm/TypeSymbolTable.h" #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/Compressor.h" #include "llvm/Support/MathExtras.h" @@ -837,8 +838,11 @@ BytecodeWriter::BytecodeWriter(std::vector<unsigned char> &o, const Module *M) for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) outputFunction(I); - // If needed, output the symbol table for the module... - outputSymbolTable(M->getSymbolTable()); + // Output the symbole table for types + outputTypeSymbolTable(M->getTypeSymbolTable()); + + // Output the symbol table for values + outputValueSymbolTable(M->getValueSymbolTable()); } void BytecodeWriter::outputTypes(unsigned TypeNum) { @@ -1112,7 +1116,7 @@ void BytecodeWriter::outputFunction(const Function *F) { outputInstructions(F); // If needed, output the symbol table for the function... - outputSymbolTable(F->getSymbolTable()); + outputValueSymbolTable(F->getValueSymbolTable()); Table.purgeFunction(); } @@ -1187,24 +1191,33 @@ void BytecodeWriter::outputCompactionTable() { } } -void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) { - // Do not output the Bytecode block for an empty symbol table, it just wastes +void BytecodeWriter::outputTypeSymbolTable(const TypeSymbolTable &TST) { + // Do not output the block for an empty symbol table, it just wastes // space! - if (MST.isEmpty()) return; + if (TST.empty()) return; - BytecodeBlock SymTabBlock(BytecodeFormat::SymbolTableBlockID, *this, + // Create a header for the symbol table + BytecodeBlock SymTabBlock(BytecodeFormat::TypeSymbolTableBlockID, *this, true/*ElideIfEmpty*/); - // Write the number of types - output_vbr(MST.num_types()); + output_vbr(TST.size()); // Write each of the types - for (SymbolTable::type_const_iterator TI = MST.type_begin(), - TE = MST.type_end(); TI != TE; ++TI) { + for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end(); + TI != TE; ++TI) { // Symtab entry:[def slot #][name] output_typeid((unsigned)Table.getSlot(TI->second)); output(TI->first); } +} + +void BytecodeWriter::outputValueSymbolTable(const SymbolTable &MST) { + // Do not output the Bytecode block for an empty symbol table, it just wastes + // space! + if (MST.isEmpty()) return; + + BytecodeBlock SymTabBlock(BytecodeFormat::ValueSymbolTableBlockID, *this, + true/*ElideIfEmpty*/); // Now do each of the type planes in order. for (SymbolTable::plane_const_iterator PI = MST.plane_begin(), diff --git a/lib/Bytecode/Writer/WriterInternals.h b/lib/Bytecode/Writer/WriterInternals.h index f8c276e858..c518c01b94 100644 --- a/lib/Bytecode/Writer/WriterInternals.h +++ b/lib/Bytecode/Writer/WriterInternals.h @@ -25,6 +25,7 @@ namespace llvm { class InlineAsm; + class TypeSymbolTable; class BytecodeWriter { std::vector<unsigned char> &Out; @@ -64,7 +65,8 @@ private: unsigned Type) ; void outputModuleInfoBlock(const Module *C); - void outputSymbolTable(const SymbolTable &ST); + void outputTypeSymbolTable(const TypeSymbolTable &TST); + void outputValueSymbolTable(const SymbolTable &ST); void outputTypes(unsigned StartNo); void outputConstantsInPlane(const std::vector<const Value*> &Plane, unsigned StartNo); |