[llvm-commits] CVS: llvm/lib/Bitcode/Writer/Writer.cpp
Changes in directory llvm/lib/Bitcode/Writer: Writer.cpp updated: 1.10 - 1.11 --- Log message: improve a comment --- Diffs of the changes: (+5 -3) Writer.cpp |8 +--- 1 files changed, 5 insertions(+), 3 deletions(-) Index: llvm/lib/Bitcode/Writer/Writer.cpp diff -u llvm/lib/Bitcode/Writer/Writer.cpp:1.10 llvm/lib/Bitcode/Writer/Writer.cpp:1.11 --- llvm/lib/Bitcode/Writer/Writer.cpp:1.10 Wed Apr 25 22:27:58 2007 +++ llvm/lib/Bitcode/Writer/Writer.cpp Wed Apr 25 22:32:43 2007 @@ -572,8 +572,9 @@ // Emit constants. WriteModuleConstants(VE, Stream); - // FIXME: Purge aggregate values from the VE, emit a record that indicates how - // many to purge. + // If we have any aggregate values in the value table, purge them - these can + // only be used to initialize global variables. Doing so makes the value + // namespace smaller for code in functions. int NumNonAggregates = VE.PurgeAggregateValues(); if (NumNonAggregates != -1) { SmallVectorunsigned, 1 Vals; @@ -583,7 +584,8 @@ // Emit function bodies. for (Module::const_iterator I = M-begin(), E = M-end(); I != E; ++I) -WriteFunction(*I, VE, Stream); +if (!I-isDeclaration()) + WriteFunction(*I, VE, Stream); // Emit the type symbol table information. WriteTypeSymbolTable(M-getTypeSymbolTable(), VE, Stream); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/Bitcode/Writer/Writer.cpp
Changes in directory llvm/lib/Bitcode/Writer: Writer.cpp updated: 1.7 - 1.8 --- Log message: implement reading and writing of constant exprs. --- Diffs of the changes: (+97 -9) Writer.cpp | 106 +++-- 1 files changed, 97 insertions(+), 9 deletions(-) Index: llvm/lib/Bitcode/Writer/Writer.cpp diff -u llvm/lib/Bitcode/Writer/Writer.cpp:1.7 llvm/lib/Bitcode/Writer/Writer.cpp:1.8 --- llvm/lib/Bitcode/Writer/Writer.cpp:1.7 Mon Apr 23 22:29:47 2007 +++ llvm/lib/Bitcode/Writer/Writer.cpp Tue Apr 24 02:07:11 2007 @@ -25,6 +25,47 @@ static const unsigned CurVersion = 0; +static unsigned GetEncodedCastOpcode(unsigned Opcode) { + switch (Opcode) { + default: assert(0 Unknown cast instruction!); + case Instruction::Trunc : return bitc::CAST_TRUNC; + case Instruction::ZExt: return bitc::CAST_ZEXT; + case Instruction::SExt: return bitc::CAST_SEXT; + case Instruction::FPToUI : return bitc::CAST_FPTOUI; + case Instruction::FPToSI : return bitc::CAST_FPTOSI; + case Instruction::UIToFP : return bitc::CAST_UITOFP; + case Instruction::SIToFP : return bitc::CAST_SITOFP; + case Instruction::FPTrunc : return bitc::CAST_FPTRUNC; + case Instruction::FPExt : return bitc::CAST_FPEXT; + case Instruction::PtrToInt: return bitc::CAST_PTRTOINT; + case Instruction::IntToPtr: return bitc::CAST_INTTOPTR; + case Instruction::BitCast : return bitc::CAST_BITCAST; + } +} + +static unsigned GetEncodedBinaryOpcode(unsigned Opcode) { + switch (Opcode) { + default: assert(0 Unknown binary instruction!); + case Instruction::Add: return bitc::BINOP_ADD; + case Instruction::Sub: return bitc::BINOP_SUB; + case Instruction::Mul: return bitc::BINOP_MUL; + case Instruction::UDiv: return bitc::BINOP_UDIV; + case Instruction::FDiv: + case Instruction::SDiv: return bitc::BINOP_SDIV; + case Instruction::URem: return bitc::BINOP_UREM; + case Instruction::FRem: + case Instruction::SRem: return bitc::BINOP_SREM; + case Instruction::Shl: return bitc::BINOP_SHL; + case Instruction::LShr: return bitc::BINOP_LSHR; + case Instruction::AShr: return bitc::BINOP_ASHR; + case Instruction::And: return bitc::BINOP_AND; + case Instruction::Or: return bitc::BINOP_OR; + case Instruction::Xor: return bitc::BINOP_XOR; + } +} + + + static void WriteStringRecord(unsigned Code, const std::string Str, unsigned AbbrevToUse, BitstreamWriter Stream) { SmallVectorunsigned, 64 Vals; @@ -408,15 +449,62 @@ for (unsigned i = 0, e = C-getNumOperands(); i != e; ++i) Record.push_back(VE.getValueID(C-getOperand(i))); } else if (const ConstantExpr *CE = dyn_castConstantExpr(C)) { - Code = bitc::CST_CODE_CONSTEXPR; - // FIXME: optimize for binops, compares, etc. - Record.push_back(CE-getOpcode()); - Record.push_back(CE-getNumOperands()); - for (unsigned i = 0, e = CE-getNumOperands(); i != e; ++i) -Record.push_back(VE.getValueID(C-getOperand(i))); - // Compares also pass their predicate. - if (CE-isCompare()) -Record.push_back((unsigned)CE-getPredicate()); + switch (CE-getOpcode()) { + default: +if (Instruction::isCast(CE-getOpcode())) { + Code = bitc::CST_CODE_CE_CAST; + Record.push_back(GetEncodedCastOpcode(CE-getOpcode())); + Record.push_back(VE.getTypeID(C-getOperand(0)-getType())); + Record.push_back(VE.getValueID(C-getOperand(0))); +} else { + assert(CE-getNumOperands() == 2 Unknown constant expr!); + Code = bitc::CST_CODE_CE_BINOP; + Record.push_back(GetEncodedBinaryOpcode(CE-getOpcode())); + Record.push_back(VE.getValueID(C-getOperand(0))); + Record.push_back(VE.getValueID(C-getOperand(1))); +} +break; + case Instruction::GetElementPtr: +Code = bitc::CST_CODE_CE_GEP; +Record.push_back(CE-getNumOperands()); +for (unsigned i = 0, e = CE-getNumOperands(); i != e; ++i) { + Record.push_back(VE.getTypeID(C-getOperand(i)-getType())); + Record.push_back(VE.getValueID(C-getOperand(i))); +} +break; + case Instruction::Select: +Code = bitc::CST_CODE_CE_SELECT; +Record.push_back(VE.getValueID(C-getOperand(0))); +Record.push_back(VE.getValueID(C-getOperand(1))); +Record.push_back(VE.getValueID(C-getOperand(2))); +break; + case Instruction::ExtractElement: +Code = bitc::CST_CODE_CE_EXTRACTELT; +Record.push_back(VE.getTypeID(C-getOperand(0)-getType())); +Record.push_back(VE.getValueID(C-getOperand(0))); +Record.push_back(VE.getValueID(C-getOperand(1))); +break; + case Instruction::InsertElement: +Code = bitc::CST_CODE_CE_INSERTELT; +Record.push_back(VE.getValueID(C-getOperand(0))); +Record.push_back(VE.getValueID(C-getOperand(1))); +
[llvm-commits] CVS: llvm/lib/Bitcode/Writer/Writer.cpp
Changes in directory llvm/lib/Bitcode/Writer: Writer.cpp updated: 1.2 - 1.3 --- Log message: first part of implementation of abbrevs. The writer isn't fully there yet and the reader doesn't handle them at all yet. --- Diffs of the changes: (+39 -6) Writer.cpp | 45 +++-- 1 files changed, 39 insertions(+), 6 deletions(-) Index: llvm/lib/Bitcode/Writer/Writer.cpp diff -u llvm/lib/Bitcode/Writer/Writer.cpp:1.2 llvm/lib/Bitcode/Writer/Writer.cpp:1.3 --- llvm/lib/Bitcode/Writer/Writer.cpp:1.2 Sun Apr 22 20:01:37 2007 +++ llvm/lib/Bitcode/Writer/Writer.cpp Mon Apr 23 11:04:05 2007 @@ -200,10 +200,14 @@ WriteStringRecord(bitc::MODULE_CODE_ASM, M-getModuleInlineAsm(), 0/*TODO*/, Stream); - // Emit information about sections. + // Emit information about sections, computing how many there are. Also + // compute the maximum alignment value. std::mapstd::string, unsigned SectionMap; + unsigned MaxAlignment = 0; for (Module::const_global_iterator GV = M-global_begin(),E = M-global_end(); GV != E; ++GV) { +MaxAlignment = std::max(MaxAlignment, GV-getAlignment()); + if (!GV-hasSection()) continue; // Give section names unique ID's. unsigned Entry = SectionMap[GV-getSection()]; @@ -213,6 +217,7 @@ Entry = SectionMap.size(); } for (Module::const_iterator F = M-begin(), E = M-end(); F != E; ++F) { +MaxAlignment = std::max(MaxAlignment, F-getAlignment()); if (!F-hasSection()) continue; // Give section names unique ID's. unsigned Entry = SectionMap[F-getSection()]; @@ -222,13 +227,37 @@ Entry = SectionMap.size(); } - // TODO: Emit abbrev, now that we know # sections. + // Emit abbrev for globals, now that we know # sections and max alignment. + unsigned SimpleGVarAbbrev = 0; + if (!M-global_empty() 0) { +// Add an abbrev for common globals with no visibility or thread localness. +BitCodeAbbrev *Abbv = new BitCodeAbbrev(); +Abbv-Add(BitCodeAbbrevOp(bitc::MODULE_CODE_GLOBALVAR)); +Abbv-Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, 1)); // Constant. +Abbv-Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// Initializer. +Abbv-Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, 3)); // Linkage. +if (MaxAlignment == 0) // Alignment. + Abbv-Add(BitCodeAbbrevOp(0)); +else { + unsigned MaxEncAlignment = Log2_32(MaxAlignment)+1; + Abbv-Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, + Log2_32_Ceil(MaxEncAlignment))); +} +if (SectionMap.empty())// Section. + Abbv-Add(BitCodeAbbrevOp(0)); +else + Abbv-Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, + Log2_32_Ceil(SectionMap.size(; +// Don't bother emitting vis + thread local. +SimpleGVarAbbrev = Stream.EmitAbbrev(Abbv); + } // Emit the global variable information. SmallVectorunsigned, 64 Vals; for (Module::const_global_iterator GV = M-global_begin(),E = M-global_end(); GV != E; ++GV) { - +unsigned AbbrevToUse = 0; + // GLOBALVAR: [type, isconst, initid, // linkage, alignment, section, visibility, threadlocal] Vals.push_back(VE.getTypeID(GV-getType())); @@ -238,10 +267,14 @@ Vals.push_back(getEncodedLinkage(GV)); Vals.push_back(Log2_32(GV-getAlignment())+1); Vals.push_back(GV-hasSection() ? SectionMap[GV-getSection()] : 0); -Vals.push_back(getEncodedVisibility(GV)); -Vals.push_back(GV-isThreadLocal()); +if (GV-isThreadLocal() || +GV-getVisibility() != GlobalValue::DefaultVisibility) { + Vals.push_back(getEncodedVisibility(GV)); + Vals.push_back(GV-isThreadLocal()); +} else { + AbbrevToUse = SimpleGVarAbbrev; +} -unsigned AbbrevToUse = 0; Stream.EmitRecord(bitc::MODULE_CODE_GLOBALVAR, Vals, AbbrevToUse); Vals.clear(); } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/Bitcode/Writer/Writer.cpp
Changes in directory llvm/lib/Bitcode/Writer: Writer.cpp updated: 1.3 - 1.4 --- Log message: implement reading of abbrevs, and writing of abbreviated global varrs. --- Diffs of the changes: (+7 -3) Writer.cpp | 10 +++--- 1 files changed, 7 insertions(+), 3 deletions(-) Index: llvm/lib/Bitcode/Writer/Writer.cpp diff -u llvm/lib/Bitcode/Writer/Writer.cpp:1.3 llvm/lib/Bitcode/Writer/Writer.cpp:1.4 --- llvm/lib/Bitcode/Writer/Writer.cpp:1.3 Mon Apr 23 11:04:05 2007 +++ llvm/lib/Bitcode/Writer/Writer.cpp Mon Apr 23 13:58:34 2007 @@ -204,9 +204,11 @@ // compute the maximum alignment value. std::mapstd::string, unsigned SectionMap; unsigned MaxAlignment = 0; + unsigned MaxGlobalType = 0; for (Module::const_global_iterator GV = M-global_begin(),E = M-global_end(); GV != E; ++GV) { MaxAlignment = std::max(MaxAlignment, GV-getAlignment()); +MaxGlobalType = std::max(MaxGlobalType, VE.getTypeID(GV-getType())); if (!GV-hasSection()) continue; // Give section names unique ID's. @@ -229,10 +231,12 @@ // Emit abbrev for globals, now that we know # sections and max alignment. unsigned SimpleGVarAbbrev = 0; - if (!M-global_empty() 0) { + if (!M-global_empty()) { // Add an abbrev for common globals with no visibility or thread localness. BitCodeAbbrev *Abbv = new BitCodeAbbrev(); Abbv-Add(BitCodeAbbrevOp(bitc::MODULE_CODE_GLOBALVAR)); +Abbv-Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, + Log2_32_Ceil(MaxGlobalType+1))); Abbv-Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, 1)); // Constant. Abbv-Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));// Initializer. Abbv-Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, 3)); // Linkage. @@ -241,7 +245,7 @@ else { unsigned MaxEncAlignment = Log2_32(MaxAlignment)+1; Abbv-Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, - Log2_32_Ceil(MaxEncAlignment))); + Log2_32_Ceil(MaxEncAlignment+1))); } if (SectionMap.empty())// Section. Abbv-Add(BitCodeAbbrevOp(0)); @@ -300,7 +304,7 @@ /// WriteModule - Emit the specified module to the bitstream. static void WriteModule(const Module *M, BitstreamWriter Stream) { - Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 2); + Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3); // Emit the version number if it is non-zero. if (CurVersion) { ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/Bitcode/Writer/Writer.cpp
Changes in directory llvm/lib/Bitcode/Writer: Writer.cpp updated: 1.4 - 1.5 --- Log message: write out the symtab for globals. --- Diffs of the changes: (+70 -33) Writer.cpp | 103 + 1 files changed, 70 insertions(+), 33 deletions(-) Index: llvm/lib/Bitcode/Writer/Writer.cpp diff -u llvm/lib/Bitcode/Writer/Writer.cpp:1.4 llvm/lib/Bitcode/Writer/Writer.cpp:1.5 --- llvm/lib/Bitcode/Writer/Writer.cpp:1.4 Mon Apr 23 13:58:34 2007 +++ llvm/lib/Bitcode/Writer/Writer.cpp Mon Apr 23 15:35:01 2007 @@ -18,6 +18,7 @@ #include llvm/DerivedTypes.h #include llvm/Module.h #include llvm/TypeSymbolTable.h +#include llvm/ValueSymbolTable.h #include llvm/Support/MathExtras.h using namespace llvm; @@ -126,39 +127,6 @@ Stream.ExitBlock(); } -/// WriteTypeSymbolTable - Emit a block for the specified type symtab. -static void WriteTypeSymbolTable(const TypeSymbolTable TST, - const ValueEnumerator VE, - BitstreamWriter Stream) { - if (TST.empty()) return; - - Stream.EnterSubblock(bitc::TYPE_SYMTAB_BLOCK_ID, 3); - - // FIXME: Set up the abbrev, we know how many types there are! - // FIXME: We know if the type names can use 7-bit ascii. - - SmallVectorunsigned, 64 NameVals; - - for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end(); - TI != TE; ++TI) { -unsigned AbbrevToUse = 0; - -// TST_ENTRY: [typeid, namelen, namechar x N] -NameVals.push_back(VE.getTypeID(TI-second)); - -const std::string Str = TI-first; -NameVals.push_back(Str.size()); -for (unsigned i = 0, e = Str.size(); i != e; ++i) - NameVals.push_back(Str[i]); - -// Emit the finished record. -Stream.EmitRecord(bitc::TST_ENTRY_CODE, NameVals, AbbrevToUse); -NameVals.clear(); - } - - Stream.ExitBlock(); -} - static unsigned getEncodedLinkage(const GlobalValue *GV) { switch (GV-getLinkage()) { default: assert(0 Invalid linkage!); @@ -302,6 +270,71 @@ } +/// WriteTypeSymbolTable - Emit a block for the specified type symtab. +static void WriteTypeSymbolTable(const TypeSymbolTable TST, + const ValueEnumerator VE, + BitstreamWriter Stream) { + if (TST.empty()) return; + + Stream.EnterSubblock(bitc::TYPE_SYMTAB_BLOCK_ID, 3); + + // FIXME: Set up the abbrev, we know how many types there are! + // FIXME: We know if the type names can use 7-bit ascii. + + SmallVectorunsigned, 64 NameVals; + + for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end(); + TI != TE; ++TI) { +unsigned AbbrevToUse = 0; + +// TST_ENTRY: [typeid, namelen, namechar x N] +NameVals.push_back(VE.getTypeID(TI-second)); + +const std::string Str = TI-first; +NameVals.push_back(Str.size()); +for (unsigned i = 0, e = Str.size(); i != e; ++i) + NameVals.push_back(Str[i]); + +// Emit the finished record. +Stream.EmitRecord(bitc::TST_ENTRY_CODE, NameVals, AbbrevToUse); +NameVals.clear(); + } + + Stream.ExitBlock(); +} + +// Emit names for globals/functions etc. +static void WriteValueSymbolTable(const ValueSymbolTable VST, + const ValueEnumerator VE, + BitstreamWriter Stream) { + if (VST.empty()) return; + Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 3); + + // FIXME: Set up the abbrev, we know how many values there are! + // FIXME: We know if the type names can use 7-bit ascii. + SmallVectorunsigned, 64 NameVals; + + for (ValueSymbolTable::const_iterator SI = VST.begin(), SE = VST.end(); + SI != SE; ++SI) { +unsigned AbbrevToUse = 0; + +// VST_ENTRY: [valueid, namelen, namechar x N] +NameVals.push_back(VE.getValueID(SI-getValue())); + +NameVals.push_back(SI-getKeyLength()); +for (const char *P = SI-getKeyData(), + *E = SI-getKeyData()+SI-getKeyLength(); P != E; ++P) + NameVals.push_back((unsigned char)*P); + +// Emit the finished record. +Stream.EmitRecord(bitc::VST_ENTRY_CODE, NameVals, AbbrevToUse); +NameVals.clear(); + } + Stream.ExitBlock(); +} + + + /// WriteModule - Emit the specified module to the bitstream. static void WriteModule(const Module *M, BitstreamWriter Stream) { Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3); @@ -327,6 +360,10 @@ // Emit the type symbol table information. WriteTypeSymbolTable(M-getTypeSymbolTable(), VE, Stream); + + // Emit names for globals/functions etc. + WriteValueSymbolTable(M-getValueSymbolTable(), VE, Stream); + Stream.ExitBlock(); } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/Bitcode/Writer/Writer.cpp
Changes in directory llvm/lib/Bitcode/Writer: Writer.cpp updated: 1.6 - 1.7 --- Log message: fix off-by-one computing size for section abbrevs --- Diffs of the changes: (+1 -1) Writer.cpp |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Bitcode/Writer/Writer.cpp diff -u llvm/lib/Bitcode/Writer/Writer.cpp:1.6 llvm/lib/Bitcode/Writer/Writer.cpp:1.7 --- llvm/lib/Bitcode/Writer/Writer.cpp:1.6 Mon Apr 23 19:16:04 2007 +++ llvm/lib/Bitcode/Writer/Writer.cpp Mon Apr 23 22:29:47 2007 @@ -220,7 +220,7 @@ Abbv-Add(BitCodeAbbrevOp(0)); else Abbv-Add(BitCodeAbbrevOp(BitCodeAbbrevOp::FixedWidth, - Log2_32_Ceil(SectionMap.size(; + Log2_32_Ceil(SectionMap.size()+1))); // Don't bother emitting vis + thread local. SimpleGVarAbbrev = Stream.EmitAbbrev(Abbv); } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/Bitcode/Writer/Writer.cpp
Changes in directory llvm/lib/Bitcode/Writer: Writer.cpp updated: 1.1 - 1.2 --- Log message: promote LLVMBitCodes to be a public header --- Diffs of the changes: (+1 -1) Writer.cpp |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Bitcode/Writer/Writer.cpp diff -u llvm/lib/Bitcode/Writer/Writer.cpp:1.1 llvm/lib/Bitcode/Writer/Writer.cpp:1.2 --- llvm/lib/Bitcode/Writer/Writer.cpp:1.1 Sun Apr 22 01:24:45 2007 +++ llvm/lib/Bitcode/Writer/Writer.cpp Sun Apr 22 20:01:37 2007 @@ -13,7 +13,7 @@ #include llvm/Bitcode/ReaderWriter.h #include llvm/Bitcode/BitstreamWriter.h -#include ../LLVMBitCodes.h +#include llvm/Bitcode/LLVMBitCodes.h #include ValueEnumerator.h #include llvm/DerivedTypes.h #include llvm/Module.h ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits