aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode/Writer/Writer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-11-06 07:11:04 +0000
committerChris Lattner <sabre@nondot.org>2005-11-06 07:11:04 +0000
commit8eb52dd7341909b16e961371a48eb353150a45b1 (patch)
treee6f3b2a55d3b48fee17fc2ca68985c1b28123378 /lib/Bytecode/Writer/Writer.cpp
parentabdf0f5327010c880612ff5d74a298a330ccf8fd (diff)
Read/write global variable alignments if present
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24216 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Writer/Writer.cpp')
-rw-r--r--lib/Bytecode/Writer/Writer.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index d314231828..b66ab55792 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -416,7 +416,6 @@ void BytecodeWriter::outputConstantStrings() {
//===----------------------------------------------------------------------===//
//=== Instruction Output ===//
//===----------------------------------------------------------------------===//
-typedef unsigned char uchar;
// outputInstructionFormat0 - Output those weird instructions that have a large
// number of operands or have large operands themselves.
@@ -925,15 +924,35 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
// 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) {
+ End = M->global_end(); I != End; ++I) {
int Slot = Table.getSlot(I->getType());
assert(Slot != -1 && "Module global vars is broken!");
+ assert((I->hasInitializer() || !I->hasInternalLinkage()) &&
+ "Global must have an initializer or have external linkage!");
+
// Fields: bit0 = isConstant, bit1 = hasInitializer, bit2-4=Linkage,
- // bit5+ = Slot # for type
- unsigned oSlot = ((unsigned)Slot << 5) | (getEncodedLinkage(I) << 2) |
- (I->hasInitializer() << 1) | (unsigned)I->isConstant();
- output_vbr(oSlot);
+ // bit5+ = Slot # for type.
+ bool HasExtensionWord = I->getAlignment() != 0;
+
+ // If we need to use the extension byte, set linkage=3(internal) and
+ // initializer = 0 (impossible!).
+ if (!HasExtensionWord) {
+ unsigned oSlot = ((unsigned)Slot << 5) | (getEncodedLinkage(I) << 2) |
+ (I->hasInitializer() << 1) | (unsigned)I->isConstant();
+ output_vbr(oSlot);
+ } else {
+ unsigned oSlot = ((unsigned)Slot << 5) | (3 << 2) |
+ (0 << 1) | (unsigned)I->isConstant();
+ 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.
+ unsigned ExtWord = I->hasInitializer() | (getEncodedLinkage(I) << 1) |
+ (Log2_32(I->getAlignment())+1) << 4;
+ output_vbr(ExtWord);
+
+ }
// If we have an initializer, output it now.
if (I->hasInitializer()) {