summaryrefslogtreecommitdiff
path: root/lib/Bytecode/Writer
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-11-12 01:33:40 +0000
committerChris Lattner <sabre@nondot.org>2005-11-12 01:33:40 +0000
commit404cddfcf9053f6170ec8e9c580dba7a35303b22 (patch)
treef865301631660d895924725c2960579243e96d5a /lib/Bytecode/Writer
parentba0ffcc1bc9daf56e7c229b59a88c4eead6e558f (diff)
downloadllvm-404cddfcf9053f6170ec8e9c580dba7a35303b22.tar.gz
llvm-404cddfcf9053f6170ec8e9c580dba7a35303b22.tar.bz2
llvm-404cddfcf9053f6170ec8e9c580dba7a35303b22.tar.xz
Read and write section info from/to .bc files
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24321 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Writer')
-rw-r--r--lib/Bytecode/Writer/Writer.cpp44
-rw-r--r--lib/Bytecode/Writer/WriterInternals.h4
2 files changed, 38 insertions, 10 deletions
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index 2bfe915b4b..879d50c86a 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -922,6 +922,11 @@ static unsigned getEncodedLinkage(const GlobalValue *GV) {
void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
BytecodeBlock ModuleInfoBlock(BytecodeFormat::ModuleGlobalInfoBlockID, *this);
+ // Give numbers to sections as we encounter them.
+ unsigned SectionIDCounter = 0;
+ std::vector<std::string> SectionNames;
+ std::map<std::string, unsigned> SectionID;
+
// Output the types for the global variables in the module...
for (Module::const_global_iterator I = M->global_begin(),
End = M->global_end(); I != End; ++I) {
@@ -933,7 +938,7 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
// Fields: bit0 = isConstant, bit1 = hasInitializer, bit2-4=Linkage,
// bit5+ = Slot # for type.
- bool HasExtensionWord = I->getAlignment() != 0;
+ bool HasExtensionWord = (I->getAlignment() != 0) || I->hasSection();
// If we need to use the extension byte, set linkage=3(internal) and
// initializer = 0 (impossible!).
@@ -947,11 +952,22 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
output_vbr(oSlot);
// The extension word has this format: bit 0 = has initializer, bit 1-3 =
- // linkage, bit 4-8 = alignment (log2), bits 10+ = future use.
+ // linkage, bit 4-8 = alignment (log2), bit 9 = has SectionID,
+ // bits 10+ = future use.
unsigned ExtWord = (unsigned)I->hasInitializer() |
(getEncodedLinkage(I) << 1) |
- ((Log2_32(I->getAlignment())+1) << 4);
+ ((Log2_32(I->getAlignment())+1) << 4) |
+ ((unsigned)I->hasSection() << 9);
output_vbr(ExtWord);
+ if (I->hasSection()) {
+ // Give section names unique ID's.
+ unsigned &Entry = SectionID[I->getSection()];
+ if (Entry == 0) {
+ Entry = ++SectionIDCounter;
+ SectionNames.push_back(I->getSection());
+ }
+ output_vbr(Entry);
+ }
}
// If we have an initializer, output it now.
@@ -975,16 +991,27 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
if (I->isExternal()) // If external, we don't have an FunctionInfo block.
ID |= 1 << 4;
- if (I->getAlignment() || (CC & ~15) != 0)
+ if (I->getAlignment() || I->hasSection() || (CC & ~15) != 0)
ID |= 1 << 31; // Do we need an extension word?
output_vbr(ID);
if (ID & (1 << 31)) {
// Extension byte: bits 0-4 = alignment, bits 5-9 = top nibble of calling
- // convention.
- ID = (Log2_32(I->getAlignment())+1) | ((CC >> 4) << 5);
+ // convention, bit 10 = hasSectionID.
+ ID = (Log2_32(I->getAlignment())+1) | ((CC >> 4) << 5) |
+ (I->hasSection() << 10);
output_vbr(ID);
+
+ // Give section names unique ID's.
+ if (I->hasSection()) {
+ unsigned &Entry = SectionID[I->getSection()];
+ if (Entry == 0) {
+ Entry = ++SectionIDCounter;
+ SectionNames.push_back(I->getSection());
+ }
+ output_vbr(Entry);
+ }
}
}
output_vbr((unsigned)Table.getSlot(Type::VoidTy) << 5);
@@ -998,6 +1025,11 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
// Output the target triple from the module
output(M->getTargetTriple());
+
+ // Emit the table of section names.
+ output_vbr((unsigned)SectionNames.size());
+ for (unsigned i = 0, e = SectionNames.size(); i != e; ++i)
+ output(SectionNames[i]);
}
void BytecodeWriter::outputInstructions(const Function *F) {
diff --git a/lib/Bytecode/Writer/WriterInternals.h b/lib/Bytecode/Writer/WriterInternals.h
index 46ad5c6710..15dd92db1e 100644
--- a/lib/Bytecode/Writer/WriterInternals.h
+++ b/lib/Bytecode/Writer/WriterInternals.h
@@ -10,10 +10,6 @@
// This header defines the interface used between components of the bytecode
// writer.
//
-// Note that the performance of this library is not terribly important, because
-// it shouldn't be used by JIT type applications... so it is not a huge focus
-// at least. :)
-//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_BYTECODE_WRITER_WRITERINTERNALS_H