Changes in directory llvm/lib/Bytecode/Writer:
SlotCalculator.cpp updated: 1.111 -> 1.112 SlotCalculator.h updated: 1.50 -> 1.51 Writer.cpp updated: 1.170 -> 1.171 WriterInternals.h updated: 1.33 -> 1.34 --- Log message: For PR1146: http://llvm.org/PR1146 : Use ParamAttrsList for writing parameter attributes. Since they are sparse now, we also write them sparsely (saves a few bytes). Unfortunately, this is a bytecode file format change. --- Diffs of the changes: (+36 -17) SlotCalculator.cpp | 9 ++++++--- SlotCalculator.h | 2 +- Writer.cpp | 40 +++++++++++++++++++++++++++------------- WriterInternals.h | 2 ++ 4 files changed, 36 insertions(+), 17 deletions(-) Index: llvm/lib/Bytecode/Writer/SlotCalculator.cpp diff -u llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.111 llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.112 --- llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.111 Sun Feb 11 23:18:08 2007 +++ llvm/lib/Bytecode/Writer/SlotCalculator.cpp Mon Apr 9 01:14:31 2007 @@ -332,6 +332,10 @@ SC_DEBUG("end purgeFunction!\n"); } +inline static bool hasImplicitNull(const Type* Ty) { + return Ty != Type::LabelTy && Ty != Type::VoidTy && !isa<OpaqueType>(Ty); +} + void SlotCalculator::CreateFunctionValueSlot(const Value *V) { assert(!NodeMap.count(V) && "Function-local value can't be inserted!"); @@ -353,7 +357,7 @@ // to insert the implicit null value. if (Table[TyPlane].empty()) { // Label's and opaque types can't have a null value. - if (Ty != Type::LabelTy && !isa<OpaqueType>(Ty)) { + if (hasImplicitNull(Ty)) { Value *ZeroInitializer = Constant::getNullValue(Ty); // If we are pushing zeroinit, it will be handled below. @@ -370,5 +374,4 @@ SC_DEBUG(" Inserting value [" << TyPlane << "] = " << *V << " slot=" << NodeMap[V] << "\n"); -} - +} Index: llvm/lib/Bytecode/Writer/SlotCalculator.h diff -u llvm/lib/Bytecode/Writer/SlotCalculator.h:1.50 llvm/lib/Bytecode/Writer/SlotCalculator.h:1.51 --- llvm/lib/Bytecode/Writer/SlotCalculator.h:1.50 Sat Feb 10 01:42:59 2007 +++ llvm/lib/Bytecode/Writer/SlotCalculator.h Mon Apr 9 01:14:31 2007 @@ -73,7 +73,7 @@ SlotCalculator(const Module *M); /// getSlot - Return the slot number of the specified value in it's type - /// plane. This returns < 0 on error! + /// plane. /// unsigned getSlot(const Value *V) const { NodeMapType::const_iterator I = NodeMap.find(V); Index: llvm/lib/Bytecode/Writer/Writer.cpp diff -u llvm/lib/Bytecode/Writer/Writer.cpp:1.170 llvm/lib/Bytecode/Writer/Writer.cpp:1.171 --- llvm/lib/Bytecode/Writer/Writer.cpp:1.170 Sun Apr 8 22:37:36 2007 +++ llvm/lib/Bytecode/Writer/Writer.cpp Mon Apr 9 01:14:31 2007 @@ -17,12 +17,13 @@ // //===----------------------------------------------------------------------===// -#define DEBUG_TYPE "bytecodewriter" +#define DEBUG_TYPE "bcwriter" #include "WriterInternals.h" #include "llvm/Bytecode/WriteBytecodePass.h" #include "llvm/CallingConv.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/ParameterAttributes.h" #include "llvm/InlineAsm.h" #include "llvm/Instructions.h" #include "llvm/Module.h" @@ -197,6 +198,21 @@ //=== Constant Output ===// //===----------------------------------------------------------------------===// +void BytecodeWriter::outputParamAttrsList(const ParamAttrsList *Attrs) { + if (!Attrs) { + output_vbr(unsigned(0)); + return; + } + unsigned numAttrs = Attrs->size(); + output_vbr(numAttrs); + for (unsigned i = 0; i < numAttrs; ++i) { + uint16_t index = Attrs->getParamIndex(i); + uint16_t attrs = Attrs->getParamAttrs(index); + output_vbr(uint32_t(index)); + output_vbr(uint32_t(attrs)); + } +} + void BytecodeWriter::outputType(const Type *T) { const StructType* STy = dyn_cast<StructType>(T); if(STy && STy->isPacked()) @@ -213,25 +229,23 @@ output_vbr(cast<IntegerType>(T)->getBitWidth()); break; case Type::FunctionTyID: { - const FunctionType *MT = cast<FunctionType>(T); - output_typeid(Table.getTypeSlot(MT->getReturnType())); - output_vbr(unsigned(MT->getParamAttrs(0))); + const FunctionType *FT = cast<FunctionType>(T); + output_typeid(Table.getTypeSlot(FT->getReturnType())); // Output the number of arguments to function (+1 if varargs): - output_vbr((unsigned)MT->getNumParams()+MT->isVarArg()); + output_vbr((unsigned)FT->getNumParams()+FT->isVarArg()); // Output all of the arguments... - FunctionType::param_iterator I = MT->param_begin(); - unsigned Idx = 1; - for (; I != MT->param_end(); ++I) { + FunctionType::param_iterator I = FT->param_begin(); + for (; I != FT->param_end(); ++I) output_typeid(Table.getTypeSlot(*I)); - output_vbr(unsigned(MT->getParamAttrs(Idx))); - Idx++; - } // Terminate list with VoidTy if we are a varargs function... - if (MT->isVarArg()) + if (FT->isVarArg()) output_typeid((unsigned)Type::VoidTyID); + + // Put out all the parameter attributes + outputParamAttrsList(FT->getParamAttrs()); break; } @@ -1107,7 +1121,7 @@ // Organize the symbol table by type typedef SmallVector<const ValueName*, 8> PlaneMapVector; - typedef DenseMap<const Type*, PlaneMapVector > PlaneMap; + typedef DenseMap<const Type*, PlaneMapVector> PlaneMap; PlaneMap Planes; for (ValueSymbolTable::const_iterator SI = VST.begin(), SE = VST.end(); SI != SE; ++SI) Index: llvm/lib/Bytecode/Writer/WriterInternals.h diff -u llvm/lib/Bytecode/Writer/WriterInternals.h:1.33 llvm/lib/Bytecode/Writer/WriterInternals.h:1.34 --- llvm/lib/Bytecode/Writer/WriterInternals.h:1.33 Sun Feb 11 23:18:08 2007 +++ llvm/lib/Bytecode/Writer/WriterInternals.h Mon Apr 9 01:14:31 2007 @@ -24,6 +24,7 @@ class InlineAsm; class TypeSymbolTable; class ValueSymbolTable; + class ParamAttrsList; class BytecodeWriter { std::vector<unsigned char> &Out; @@ -61,6 +62,7 @@ void outputTypeSymbolTable(const TypeSymbolTable &TST); void outputValueSymbolTable(const ValueSymbolTable &ST); void outputTypes(unsigned StartNo); + void outputParamAttrsList(const ParamAttrsList* Attrs); void outputConstantsInPlane(const Value *const*Plane, unsigned PlaneSize, unsigned StartNo); void outputConstant(const Constant *CPV); _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits