[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Analyzer.cpp Reader.cpp Reader.h

2007-04-28 Thread Anton Korobeynikov


Changes in directory llvm/lib/Bytecode/Reader:

Analyzer.cpp updated: 1.41 - 1.42
Reader.cpp updated: 1.255 - 1.256
Reader.h updated: 1.52 - 1.53
---
Log message:

Implement review feedback. Aliasees can be either GlobalValue's or 
bitcasts of them.


---
Diffs of the changes:  (+61 -10)

 Analyzer.cpp |   21 +
 Reader.cpp   |   41 +++--
 Reader.h |9 +
 3 files changed, 61 insertions(+), 10 deletions(-)


Index: llvm/lib/Bytecode/Reader/Analyzer.cpp
diff -u llvm/lib/Bytecode/Reader/Analyzer.cpp:1.41 
llvm/lib/Bytecode/Reader/Analyzer.cpp:1.42
--- llvm/lib/Bytecode/Reader/Analyzer.cpp:1.41  Tue Apr 24 12:20:52 2007
+++ llvm/lib/Bytecode/Reader/Analyzer.cpp   Sat Apr 28 08:44:59 2007
@@ -179,6 +179,27 @@
 
   }
 
+  virtual void handleGlobalAlias(
+const Type* ElemType,
+GlobalValue::LinkageTypes Linkage,
+unsigned TypeSlotNum,
+unsigned AliaseeSlot) {
+if (os) {
+  *osGA: 
+Linkage=  Linkage
+Type=;
+  //WriteTypeSymbolic(*os, ElemType, M);
+  *os   Slot=  TypeSlotNum   AliaseeSlot=  AliaseeSlot
+   \n;
+}
+
+bca.numValues++;
+if (TypeSlotNum  bca.maxValueSlot)
+  bca.maxValueSlot = TypeSlotNum;
+if (AliaseeSlot  bca.maxValueSlot)
+  bca.maxValueSlot = AliaseeSlot;
+  }
+
   virtual void handleTypeList(unsigned numEntries) {
 bca.maxTypeSlot = numEntries - 1;
   }


Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.255 
llvm/lib/Bytecode/Reader/Reader.cpp:1.256
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.255   Wed Apr 25 09:27:10 2007
+++ llvm/lib/Bytecode/Reader/Reader.cpp Sat Apr 28 08:44:59 2007
@@ -1923,12 +1923,10 @@
 // Read aliases...
 unsigned VarType = read_vbr_uint();
 while (VarType != Type::VoidTyID) { // List is terminated by Void
-  unsigned TypeSlotNo = VarType  2;
+  unsigned TypeSlotNo = VarType  3;
   unsigned EncodedLinkage = VarType  3;
-  unsigned AliaseeTypeSlotNo, AliaseeSlotNo;
-
-  AliaseeTypeSlotNo = read_vbr_uint();
-  AliaseeSlotNo = read_vbr_uint();
+  bool isConstantAliasee  = (VarType  2)  1;
+  unsigned AliaseeSlotNo  = read_vbr_uint();
 
   const Type *Ty = getType(TypeSlotNo);
   if (!Ty)
@@ -1937,11 +1935,11 @@
   if (!isaPointerType(Ty))
 error(Alias not a pointer type! Ty=  + Ty-getDescription());
   
-  Value* V = getValue(AliaseeTypeSlotNo, AliaseeSlotNo, false);
-  if (!V)
-error(Invalid aliasee! TypeSlotNo= + utostr(AliaseeTypeSlotNo) +
+  Value* V = getValue(TypeSlotNo, AliaseeSlotNo, false);
+  if (!V  !isConstantAliasee)
+error(Invalid aliasee! TypeSlotNo= + utostr(TypeSlotNo) +
SlotNo= + utostr(AliaseeSlotNo));
-  if (!isaGlobalValue(V))
+  if (!isConstantAliasee  !isaGlobalValue(V))
 error(Aliasee is not global value! SlotNo= + utostr(AliaseeSlotNo));
 
   GlobalValue::LinkageTypes Linkage;
@@ -1960,8 +1958,14 @@
   }
   
   GlobalAlias *GA = new GlobalAlias(Ty, Linkage, ,
-dyn_castGlobalValue(V), TheModule);
+dyn_cast_or_nullConstant(V),
+TheModule);
   insertValue(GA, TypeSlotNo, ModuleValues);
+  if (!V  isConstantAliasee)
+Aliasees.push_back(std::make_pair(GA, AliaseeSlotNo));
+
+  if (Handler) Handler-handleGlobalAlias(Ty, Linkage,
+  TypeSlotNo, AliaseeSlotNo);
   VarType = read_vbr_uint();
 }
   }  
@@ -2068,6 +2072,23 @@
   error(Cannot find initializer value.);
   }
 
+  // And aliasees
+  while (!Aliasees.empty()) {
+GlobalAlias *GA = Aliasees.back().first;
+unsigned Slot = Aliasees.back().second;
+Aliasees.pop_back();
+
+// Look up the aliasee value...
+const llvm::PointerType* GAType = GA-getType();
+unsigned TypeSlot = getTypeSlot(GAType);
+if (Constant *CV = getConstantValue(TypeSlot, Slot)) {
+  if (GA-getAliasee())
+error(Aliasee was *already* set?!);
+  GA-setAliasee(CV);
+} else
+  error(Cannot find aliasee value.);
+  }
+
   if (!ConstantFwdRefs.empty())
 error(Use of undefined constants in a module);
 


Index: llvm/lib/Bytecode/Reader/Reader.h
diff -u llvm/lib/Bytecode/Reader/Reader.h:1.52 
llvm/lib/Bytecode/Reader/Reader.h:1.53
--- llvm/lib/Bytecode/Reader/Reader.h:1.52  Mon Apr  9 01:14:31 2007
+++ llvm/lib/Bytecode/Reader/Reader.h   Sat Apr 28 08:44:59 2007
@@ -129,6 +129,9 @@
   /// them.
   typedef std::vectorstd::pairGlobalVariable*, unsigned  GlobalInitsList;
 
+  /// @brief A list of global aliases and the slot number for constant aliasees
+  typedef std::vectorstd::pairGlobalAlias*, unsigned  AliaseeList;
+
   /// This type maps a typeslot/valueslot pair to the corresponding Value*.
   /// It is used for dealing with 

[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Analyzer.cpp Reader.cpp Reader.h

2007-02-12 Thread Chris Lattner


Changes in directory llvm/lib/Bytecode/Reader:

Analyzer.cpp updated: 1.36 - 1.37
Reader.cpp updated: 1.235 - 1.236
Reader.h updated: 1.48 - 1.49
---
Log message:

avoid creating a temporary string when reading the symbol table for a
module.  This speeds up the bcreader 11%.


---
Diffs of the changes:  (+26 -9)

 Analyzer.cpp |4 ++--
 Reader.cpp   |   30 +++---
 Reader.h |1 +
 3 files changed, 26 insertions(+), 9 deletions(-)


Index: llvm/lib/Bytecode/Reader/Analyzer.cpp
diff -u llvm/lib/Bytecode/Reader/Analyzer.cpp:1.36 
llvm/lib/Bytecode/Reader/Analyzer.cpp:1.37
--- llvm/lib/Bytecode/Reader/Analyzer.cpp:1.36  Sat Feb 10 08:07:56 2007
+++ llvm/lib/Bytecode/Reader/Analyzer.cpp   Mon Feb 12 12:53:42 2007
@@ -250,10 +250,10 @@
   }
 
   virtual void handleSymbolTableValue(unsigned TySlot, unsigned ValSlot, 
-  const std::string name) {
+  const char *Name, unsigned NameLen) {
 if (os)
   *os  Value   TySlot   Slot=  ValSlot
-   Name:   name  \n;
+Name:   std::string(Name, Name+NameLen)  \n;
 if (ValSlot  bca.maxValueSlot)
   bca.maxValueSlot = ValSlot;
   }


Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.235 
llvm/lib/Bytecode/Reader/Reader.cpp:1.236
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.235   Wed Feb  7 15:41:01 2007
+++ llvm/lib/Bytecode/Reader/Reader.cpp Mon Feb 12 12:53:43 2007
@@ -132,6 +132,17 @@
   return std::string((char*)OldAt, Size);
 }
 
+void BytecodeReader::read_str(SmallVectorImplchar StrData) {
+  StrData.clear();
+  unsigned Size = read_vbr_uint();
+  const unsigned char *OldAt = At;
+  At += Size;
+  if (At  BlockEnd) // Size invalid?
+error(Ran out of data reading a string!);
+  StrData.append(OldAt, At);
+}
+
+
 /// Read an arbitrary block of data
 inline void BytecodeReader::read_data(void *Ptr, void *End) {
   unsigned char *Start = (unsigned char *)Ptr;
@@ -943,6 +954,8 @@
E = CurrentFunction-end(); I != E; ++I)
   BBMap.push_back(I);
 
+  SmallVectorchar, 32 NameStr;
+  
   while (moreInBlock()) {
 // Symtab block header: [num entries][type id number]
 unsigned NumEntries = read_vbr_uint();
@@ -951,19 +964,22 @@
 for (unsigned i = 0; i != NumEntries; ++i) {
   // Symtab entry: [def slot #][name]
   unsigned slot = read_vbr_uint();
-  std::string Name = read_str();
+  read_str(NameStr);
   Value *V = 0;
   if (Typ == LabelTySlot) {
-if (slot  BBMap.size())
-  V = BBMap[slot];
+V = (slot  BBMap.size()) ? BBMap[slot] : 0;
   } else {
-V = getValue(Typ, slot, false); // Find mapping...
+V = getValue(Typ, slot, false); // Find mapping.
   }
-  if (Handler) Handler-handleSymbolTableValue(Typ, slot, Name);
+  if (Handler) Handler-handleSymbolTableValue(Typ, slot,
+   NameStr[0], 
NameStr.size());
   if (V == 0)
-error(Failed value look-up for name ' + Name + ', type # + 
+error(Failed value look-up for name ' + 
+  std::string(NameStr.begin(), NameStr.end()) + ', type # + 
   utostr(Typ) +  slot # + utostr(slot));
-  V-setName(Name);
+  V-setName(NameStr[0], NameStr.size());
+  
+  NameStr.clear();
 }
   }
   checkPastBlockEnd(Symbol Table);


Index: llvm/lib/Bytecode/Reader/Reader.h
diff -u llvm/lib/Bytecode/Reader/Reader.h:1.48 
llvm/lib/Bytecode/Reader/Reader.h:1.49
--- llvm/lib/Bytecode/Reader/Reader.h:1.48  Wed Feb  7 17:46:55 2007
+++ llvm/lib/Bytecode/Reader/Reader.h   Mon Feb 12 12:53:43 2007
@@ -438,6 +438,7 @@
 
   /// @brief Read a string
   inline std::string read_str();
+  inline void read_str(SmallVectorImplchar StrData);
 
   /// @brief Read a float value
   inline void read_float(float FloatVal);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Analyzer.cpp Reader.cpp Reader.h

2007-02-06 Thread Chris Lattner


Changes in directory llvm/lib/Bytecode/Reader:

Analyzer.cpp updated: 1.31 - 1.32
Reader.cpp updated: 1.230 - 1.231
Reader.h updated: 1.44 - 1.45
---
Log message:

Eliminate std::vectors from the bcanalyzer interface.



---
Diffs of the changes:  (+45 -32)

 Analyzer.cpp |   28 ++--
 Reader.cpp   |   45 +
 Reader.h |4 ++--
 3 files changed, 45 insertions(+), 32 deletions(-)


Index: llvm/lib/Bytecode/Reader/Analyzer.cpp
diff -u llvm/lib/Bytecode/Reader/Analyzer.cpp:1.31 
llvm/lib/Bytecode/Reader/Analyzer.cpp:1.32
--- llvm/lib/Bytecode/Reader/Analyzer.cpp:1.31  Mon Feb  5 14:47:20 2007
+++ llvm/lib/Bytecode/Reader/Analyzer.cpp   Tue Feb  6 23:08:39 2007
@@ -359,13 +359,13 @@
   }
 
   virtual bool handleInstruction( unsigned Opcode, const Type* iType,
-std::vectorunsigned Operands, 
+unsigned *Operands, unsigned NumOps, 
 Instruction *Inst,
 unsigned Size){
 if (os) {
   *os  INST: OpCode=
   Instruction::getOpcodeName(Opcode);
-  for ( unsigned i = 0; i  Operands.size(); ++i )
+  for (unsigned i = 0; i != NumOps; ++i)
 *os   Op(  Operands[i]  );
   *os  *Inst;
 }
@@ -374,15 +374,15 @@
 bca.numValues++;
 bca.instructionSize += Size;
 if (Size  4 ) bca.longInstructions++;
-bca.numOperands += Operands.size();
-for (unsigned i = 0; i  Operands.size(); ++i )
+bca.numOperands += NumOps;
+for (unsigned i = 0; i != NumOps; ++i)
   if (Operands[i]  bca.maxValueSlot)
 bca.maxValueSlot = Operands[i];
 if ( currFunc ) {
   currFunc-numInstructions++;
   currFunc-instructionSize += Size;
   if (Size  4 ) currFunc-longInstructions++;
-  if ( Opcode == Instruction::PHI ) currFunc-numPhis++;
+  if (Opcode == Instruction::PHI) currFunc-numPhis++;
 }
 return Instruction::isTerminator(Opcode);
   }
@@ -397,11 +397,11 @@
   *os  BLOCK: GlobalConstants {\n;
   }
 
-  virtual void handleConstantExpression( unsigned Opcode,
-  std::vectorConstant* ArgVec, Constant* C ) {
+  virtual void handleConstantExpression(unsigned Opcode,
+  Constant**ArgVec, unsigned NumArgs, Constant* C) {
 if (os) {
   *osEXPR:   Instruction::getOpcodeName(Opcode)  \n;
-  for ( unsigned i = 0; i  ArgVec.size(); ++i ) {
+  for ( unsigned i = 0; i != NumArgs; ++i ) {
 *os  Arg#  i   ; ArgVec[i]-print(*os);
 *os  \n;
   }
@@ -424,14 +424,14 @@
   }
 
   virtual void handleConstantArray( const ArrayType* AT,
-  std::vectorConstant* Elements,
+  Constant**Elements, unsigned NumElts,
   unsigned TypeSlot,
   Constant* ArrayVal ) {
 if (os) {
   *osARRAY: ;
   WriteTypeSymbolic(*os,AT,M);
   *os   TypeSlot=  TypeSlot  \n;
-  for ( unsigned i = 0; i  Elements.size(); ++i ) {
+  for (unsigned i = 0; i != NumElts; ++i) {
 *os  #  i;
 Elements[i]-print(*os);
 *os  \n;
@@ -447,14 +447,14 @@
 
   virtual void handleConstantStruct(
 const StructType* ST,
-std::vectorConstant* Elements,
+Constant**Elements, unsigned NumElts,
 Constant* StructVal)
   {
 if (os) {
   *osSTRUC: ;
   WriteTypeSymbolic(*os,ST,M);
   *os  \n;
-  for ( unsigned i = 0; i  Elements.size(); ++i ) {
+  for ( unsigned i = 0; i != NumElts; ++i) {
 *os  #  i   ; Elements[i]-print(*os);
 *os  \n;
   }
@@ -468,7 +468,7 @@
 
   virtual void handleConstantPacked(
 const PackedType* PT,
-std::vectorConstant* Elements,
+Constant**Elements, unsigned NumElts,
 unsigned TypeSlot,
 Constant* PackedVal)
   {
@@ -476,7 +476,7 @@
   *osPACKD: ;
   WriteTypeSymbolic(*os,PT,M);
   *os   TypeSlot=  TypeSlot  \n;
-  for ( unsigned i = 0; i  Elements.size(); ++i ) {
+  for ( unsigned i = 0; i != NumElts; ++i ) {
 *os  #  i;
 Elements[i]-print(*os);
 *os  \n;


Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.230 
llvm/lib/Bytecode/Reader/Reader.cpp:1.231
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.230   Mon Feb  5 14:47:20 2007
+++ llvm/lib/Bytecode/Reader/Reader.cpp Tue Feb  6 23:08:39 2007
@@ -366,7 +366,7 @@
 /// This method parses a single instruction. The instruction is
 /// inserted at the end of the \p BB provided. The arguments of
 /// the instruction are provided in the \p Oprnds vector.
-void BytecodeReader::ParseInstruction(std::vectorunsigned Oprnds,
+void BytecodeReader::ParseInstruction(SmallVectorunsigned, 8 Oprnds,
   BasicBlock* BB) {
   BufPtr SaveAt = At;
 
@@ -859,7 +859,8 @@
 
   // We have enough info to inform the handler now.
   if (Handler) 
-

[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Analyzer.cpp Reader.cpp Reader.h

2007-01-30 Thread Reid Spencer


Changes in directory llvm/lib/Bytecode/Reader:

Analyzer.cpp updated: 1.29 - 1.30
Reader.cpp updated: 1.225 - 1.226
Reader.h updated: 1.42 - 1.43
---
Log message:

Bye, Bye Compaction Tables. The benefit compaction tables provides doesn't
outweight its computational costs. This patch removes all compaction
table handling from the bcreader and bcwriter. For the record, here's the
difference betweeen having and not having compaction tables for some tests:

Test With   Without   Size Chg
Olden/mst   5,602 5,598  +0.1%
viterbi18,02617,795  +1.3%
obsequi   162,133   166,663  -2.8%
burg  224,090   228,148  -1.8%
kimwitu++   4,933,263 5,121,159  -3.8%
176.gcc 8,470,424 9,141,539  -7.3%

It seems that it is more beneficial to larger files, but even on the largest
test case we have (176.gcc) it only amounts ot an I/O saving of 7.3%. 


---
Diffs of the changes:  (+18 -229)

 Analyzer.cpp |4 -
 Reader.cpp   |  217 ---
 Reader.h |   26 ---
 3 files changed, 18 insertions(+), 229 deletions(-)


Index: llvm/lib/Bytecode/Reader/Analyzer.cpp
diff -u llvm/lib/Bytecode/Reader/Analyzer.cpp:1.29 
llvm/lib/Bytecode/Reader/Analyzer.cpp:1.30
--- llvm/lib/Bytecode/Reader/Analyzer.cpp:1.29  Fri Jan 26 02:10:24 2007
+++ llvm/lib/Bytecode/Reader/Analyzer.cpp   Tue Jan 30 13:36:46 2007
@@ -100,7 +100,6 @@
 bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID] = 0;
 bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID] = 0;
 bca.BlockSizes[BytecodeFormat::InstructionListBlockID] = 0;
-bca.BlockSizes[BytecodeFormat::CompactionTableBlockID] = 0;
 bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID] = 0;
   }
 
@@ -635,9 +634,6 @@
   print(Out, Instruction List Bytes,
 double(bca.BlockSizes[BytecodeFormat::InstructionListBlockID]),
 double(bca.byteSize));
-  print(Out, Compaction Table Bytes,
-double(bca.BlockSizes[BytecodeFormat::CompactionTableBlockID]),
-double(bca.byteSize));
   print(Out, Value Symbol Table Bytes,
 double(bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID]),
 double(bca.byteSize));


Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.225 
llvm/lib/Bytecode/Reader/Reader.cpp:1.226
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.225   Fri Jan 26 02:10:24 2007
+++ llvm/lib/Bytecode/Reader/Reader.cpp Tue Jan 30 13:36:46 2007
@@ -186,8 +186,8 @@
   return TyID != Type::LabelTyID  TyID != Type::VoidTyID;
 }
 
-/// Obtain a type given a typeid and account for things like compaction tables,
-/// function level vs module level, and the offsetting for the primitive types.
+/// Obtain a type given a typeid and account for things like function level vs 
+/// module level, and the offsetting for the primitive types.
 const Type *BytecodeReader::getType(unsigned ID) {
   if (ID = Type::LastPrimitiveTyID)
 if (const Type *T = Type::getPrimitiveType((Type::TypeID)ID))
@@ -196,12 +196,6 @@
   // Otherwise, derived types need offset...
   ID -= Type::FirstDerivedTyID;
 
-  if (!CompactionTypes.empty()) {
-if (ID = CompactionTypes.size())
-  error(Type ID out of range for compaction table!);
-return CompactionTypes[ID].first;
-  }
-
   // Is it a module-level type?
   if (ID  ModuleTypes.size())
 return ModuleTypes[ID].get();
@@ -223,20 +217,11 @@
 }
 
 /// Get the slot number associated with a type accounting for primitive
-/// types, compaction tables, and function level vs module level.
+/// types and function level vs module level.
 unsigned BytecodeReader::getTypeSlot(const Type *Ty) {
   if (Ty-isPrimitiveType())
 return Ty-getTypeID();
 
-  // Scan the compaction table for the type if needed.
-  if (!CompactionTypes.empty()) {
-for (unsigned i = 0, e = CompactionTypes.size(); i != e; ++i)
-  if (CompactionTypes[i].first == Ty)
-return Type::FirstDerivedTyID + i;
-
-error(Couldn't find type specified in compaction table!);
-  }
-
   // Check the function level types first...
   TypeListTy::iterator I = std::find(FunctionTypes.begin(),
  FunctionTypes.end(), Ty);
@@ -266,84 +251,28 @@
   return Type::FirstDerivedTyID + IT-second;
 }
 
-/// This is just like getType, but when a compaction table is in use, it is
-/// ignored.  It also ignores function level types.
-/// @see getType
-const Type *BytecodeReader::getGlobalTableType(unsigned Slot) {
-  if (Slot  Type::FirstDerivedTyID) {
-const Type *Ty = Type::getPrimitiveType((Type::TypeID)Slot);
-if (!Ty)
-  error(Not a primitive type ID?);
-return Ty;
-  }
-  Slot -= Type::FirstDerivedTyID;
-  if (Slot = ModuleTypes.size())
-error(Illegal compaction table type reference!);
-  return ModuleTypes[Slot];
-}
-
-/// This is just like getTypeSlot, but when a compaction table is in use, it
-/// is ignored. It 

[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Analyzer.cpp Reader.cpp Reader.h

2007-01-05 Thread Reid Spencer


Changes in directory llvm/lib/Bytecode/Reader:

Analyzer.cpp updated: 1.26 - 1.27
Reader.cpp updated: 1.215 - 1.216
Reader.h updated: 1.40 - 1.41
---
Log message:

For PR411: http://llvm.org/PR411 :
Take an incremental step towards type plane elimination. This change 
separates types from values in the symbol tables by finally making use
of the TypeSymbolTable class. This yields more natural interfaces for
dealing with types and unclutters the SymbolTable class.


---
Diffs of the changes:  (+43 -22)

 Analyzer.cpp |   10 +++---
 Reader.cpp   |   47 ++-
 Reader.h |8 ++--
 3 files changed, 43 insertions(+), 22 deletions(-)


Index: llvm/lib/Bytecode/Reader/Analyzer.cpp
diff -u llvm/lib/Bytecode/Reader/Analyzer.cpp:1.26 
llvm/lib/Bytecode/Reader/Analyzer.cpp:1.27
--- llvm/lib/Bytecode/Reader/Analyzer.cpp:1.26  Fri Dec 15 15:46:37 2006
+++ llvm/lib/Bytecode/Reader/Analyzer.cpp   Sat Jan  6 01:24:43 2007
@@ -96,11 +96,12 @@
 bca.BlockSizes[BytecodeFormat::ModuleBlockID] = theSize;
 bca.BlockSizes[BytecodeFormat::FunctionBlockID] = 0;
 bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID] = 0;
-bca.BlockSizes[BytecodeFormat::SymbolTableBlockID] = 0;
+bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID] = 0;
 bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID] = 0;
 bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID] = 0;
 bca.BlockSizes[BytecodeFormat::InstructionListBlockID] = 0;
 bca.BlockSizes[BytecodeFormat::CompactionTableBlockID] = 0;
+bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID] = 0;
   }
 
   virtual void handleFinish() {
@@ -636,8 +637,11 @@
   print(Out, Compaction Table Bytes,
 double(bca.BlockSizes[BytecodeFormat::CompactionTableBlockID]),
 double(bca.byteSize));
-  print(Out, Symbol Table Bytes,
-double(bca.BlockSizes[BytecodeFormat::SymbolTableBlockID]),
+  print(Out, Value Symbol Table Bytes,
+double(bca.BlockSizes[BytecodeFormat::ValueSymbolTableBlockID]),
+double(bca.byteSize));
+  print(Out, Type Symbol Table Bytes,
+double(bca.BlockSizes[BytecodeFormat::TypeSymbolTableBlockID]),
 double(bca.byteSize));
   print(Out, Alignment Bytes,
 double(bca.numAlignment), double(bca.byteSize));


Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.215 
llvm/lib/Bytecode/Reader/Reader.cpp:1.216
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.215   Sat Dec 30 23:44:24 2006
+++ llvm/lib/Bytecode/Reader/Reader.cpp Sat Jan  6 01:24:43 2007
@@ -24,6 +24,7 @@
 #include llvm/InlineAsm.h
 #include llvm/Instructions.h
 #include llvm/SymbolTable.h
+#include llvm/TypeSymbolTable.h
 #include llvm/Bytecode/Format.h
 #include llvm/Config/alloca.h
 #include llvm/Support/GetElementPtrTypeIterator.h
@@ -1023,13 +1024,27 @@
   return BlockNo;
 }
 
-/// Parse a symbol table. This works for both module level and function
+/// Parse a type symbol table.
+void BytecodeReader::ParseTypeSymbolTable(TypeSymbolTable *TST) {
+  // Type Symtab block header: [num entries]
+  unsigned NumEntries = read_vbr_uint();
+  for (unsigned i = 0; i  NumEntries; ++i) {
+// Symtab entry: [type slot #][name]
+unsigned slot = read_vbr_uint();
+std::string Name = read_str();
+const Type* T = getType(slot);
+TST-insert(Name, T);
+  }
+}
+
+/// Parse a value symbol table. This works for both module level and function
 /// level symbol tables.  For function level symbol tables, the CurrentFunction
 /// parameter must be non-zero and the ST parameter must correspond to
 /// CurrentFunction's symbol table. For Module level symbol tables, the
 /// CurrentFunction argument must be zero.
-void BytecodeReader::ParseSymbolTable(Function *CurrentFunction,
-  SymbolTable *ST) {
+void BytecodeReader::ParseValueSymbolTable(Function *CurrentFunction,
+   SymbolTable *ST) {
+  
   if (Handler) Handler-handleSymbolTableBegin(CurrentFunction,ST);
 
   // Allow efficient basic block lookup by number.
@@ -1039,16 +1054,6 @@
E = CurrentFunction-end(); I != E; ++I)
   BBMap.push_back(I);
 
-  // Symtab block header: [num entries]
-  unsigned NumEntries = read_vbr_uint();
-  for (unsigned i = 0; i  NumEntries; ++i) {
-// Symtab entry: [def slot #][name]
-unsigned slot = read_vbr_uint();
-std::string Name = read_str();
-const Type* T = getType(slot);
-ST-insert(Name, T);
-  }
-
   while (moreInBlock()) {
 // Symtab block header: [num entries][type id number]
 unsigned NumEntries = read_vbr_uint();
@@ -1683,8 +1688,12 @@
   break;
 }
 
-case BytecodeFormat::SymbolTableBlockID:
-  ParseSymbolTable(F, F-getSymbolTable());
+case BytecodeFormat::ValueSymbolTableBlockID:
+  ParseValueSymbolTable(F, F-getValueSymbolTable());
+  break;
+
+case 

[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Analyzer.cpp Reader.cpp Reader.h

2006-11-13 Thread Reid Spencer


Changes in directory llvm/lib/Bytecode/Reader:

Analyzer.cpp updated: 1.24 - 1.25
Reader.cpp updated: 1.204 - 1.205
Reader.h updated: 1.37 - 1.38
---
Log message:

Discard code that supported old bytecode formats. This makes the Bytecode
Reader code much easier to read and maintain. Backwards compatibility from
version 5 format has been retained. Older formats will produce an error.


---
Diffs of the changes:  (+146 -550)

 Analyzer.cpp |2 
 Reader.cpp   |  617 +--
 Reader.h |   77 ---
 3 files changed, 146 insertions(+), 550 deletions(-)


Index: llvm/lib/Bytecode/Reader/Analyzer.cpp
diff -u llvm/lib/Bytecode/Reader/Analyzer.cpp:1.24 
llvm/lib/Bytecode/Reader/Analyzer.cpp:1.25
--- llvm/lib/Bytecode/Reader/Analyzer.cpp:1.24  Thu Nov  2 19:44:51 2006
+++ llvm/lib/Bytecode/Reader/Analyzer.cpp   Mon Nov 13 22:47:22 2006
@@ -532,7 +532,7 @@
 assert(BType = BytecodeFormat::ModuleBlockID);
 assert(BType  BytecodeFormat::NumberOfBlockIDs);
 bca.BlockSizes[
-  llvm::BytecodeFormat::CompressedBytecodeBlockIdentifiers(BType)] += Size;
+  llvm::BytecodeFormat::BytecodeBlockIdentifiers(BType)] += Size;
 
 if (bca.version  3) // Check for long block headers versions
   bca.BlockSizes[llvm::BytecodeFormat::Reserved_DoNotUse] += 8;


Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.204 
llvm/lib/Bytecode/Reader/Reader.cpp:1.205
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.204   Wed Nov  8 15:27:54 2006
+++ llvm/lib/Bytecode/Reader/Reader.cpp Mon Nov 13 22:47:22 2006
@@ -73,18 +73,6 @@
block.);
 }
 
-/// Align the buffer position to a 32 bit boundary
-inline void BytecodeReader::align32() {
-  if (hasAlignment) {
-BufPtr Save = At;
-At = (const unsigned char *)((intptr_t)(At+3)  (~3UL));
-if (At  Save)
-  if (Handler) Handler-handleAlignment(At - Save);
-if (At  BlockEnd)
-  error(Ran out of data while aligning!);
-  }
-}
-
 /// Read a whole unsigned integer
 inline unsigned BytecodeReader::read_uint() {
   if (At+4  BlockEnd)
@@ -179,43 +167,9 @@
 
 /// Read a block header and obtain its type and size
 inline void BytecodeReader::read_block(unsigned Type, unsigned Size) {
-  if ( hasLongBlockHeaders ) {
-Type = read_uint();
-Size = read_uint();
-switch (Type) {
-case BytecodeFormat::Reserved_DoNotUse :
-  error(Reserved_DoNotUse used as Module Type?);
-  Type = BytecodeFormat::ModuleBlockID; break;
-case BytecodeFormat::Module:
-  Type = BytecodeFormat::ModuleBlockID; break;
-case BytecodeFormat::Function:
-  Type = BytecodeFormat::FunctionBlockID; break;
-case BytecodeFormat::ConstantPool:
-  Type = BytecodeFormat::ConstantPoolBlockID; break;
-case BytecodeFormat::SymbolTable:
-  Type = BytecodeFormat::SymbolTableBlockID; break;
-case BytecodeFormat::ModuleGlobalInfo:
-  Type = BytecodeFormat::ModuleGlobalInfoBlockID; break;
-case BytecodeFormat::GlobalTypePlane:
-  Type = BytecodeFormat::GlobalTypePlaneBlockID; break;
-case BytecodeFormat::InstructionList:
-  Type = BytecodeFormat::InstructionListBlockID; break;
-case BytecodeFormat::CompactionTable:
-  Type = BytecodeFormat::CompactionTableBlockID; break;
-case BytecodeFormat::BasicBlock:
-  /// This block type isn't used after version 1.1. However, we have to
-  /// still allow the value in case this is an old bc format file.
-  /// We just let its value creep thru.
-  break;
-default:
-  error(Invalid block id found:  + utostr(Type));
-  break;
-}
-  } else {
-Size = read_uint();
-Type = Size  0x1F; // mask low order five bits
-Size = 5; // get rid of five low order bits, leaving high 27
-  }
+  Size = read_uint(); // Read the header
+  Type = Size  0x1F; // mask low order five bits to get type
+  Size = 5; // high order 27 bits is the size
   BlockStart = At;
   if (At + Size  BlockEnd)
 error(Attempt to size a block past end of memory);
@@ -223,56 +177,13 @@
   if (Handler) Handler-handleBlock(Type, BlockStart, Size);
 }
 
-
-/// In LLVM 1.2 and before, Types were derived from Value and so they were
-/// written as part of the type planes along with any other Value. In LLVM
-/// 1.3 this changed so that Type does not derive from Value. Consequently,
-/// the BytecodeReader's containers for Values can't contain Types because
-/// there's no inheritance relationship. This means that the Type Type
-/// plane is defunct along with the Type::TypeTyID TypeID. In LLVM 1.3
-/// whenever a bytecode construct must have both types and values together,
-/// the types are always read/written first and then the Values. Furthermore
-/// since Type::TypeTyID no longer exists, its value (12) now corresponds to
-/// Type::LabelTyID. In order to overcome this we must sanitize all the
-/// type TypeIDs we encounter. For LLVM 1.3 bytecode files, there's no change.