[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-05-17 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.49 -> 1.50
BitcodeReader.h updated: 1.20 -> 1.21
---
Log message:

Fix PR1434: http://llvm.org/PR1434  and test/Linker/link-archive.ll, this is a 
regression from 1.9.


---
Diffs of the changes:  (+91 -54)

 BitcodeReader.cpp |  135 --
 BitcodeReader.h   |   10 +++-
 2 files changed, 91 insertions(+), 54 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.49 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.50
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.49  Tue May 15 01:29:44 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May 17 23:02:46 2007
@@ -24,8 +24,15 @@
 #include "llvm/Support/MemoryBuffer.h"
 using namespace llvm;
 
-BitcodeReader::~BitcodeReader() {
+void BitcodeReader::FreeState() {
   delete Buffer;
+  Buffer = 0;
+  std::vector().swap(TypeList);
+  ValueList.clear();
+  std::vector().swap(ParamAttrs);
+  std::vector().swap(FunctionBBs);
+  std::vector().swap(FunctionsWithBodies);
+  DeferredFunctionInfo.clear();
 }
 
 
//===--===//
@@ -1102,53 +1109,6 @@
 }
 
 
-bool BitcodeReader::materializeFunction(Function *F, std::string *ErrInfo) {
-  // If it already is material, ignore the request.
-  if (!F->hasNotBeenReadFromBytecode()) return false;
-
-  DenseMap >::iterator DFII = 
-DeferredFunctionInfo.find(F);
-  assert(DFII != DeferredFunctionInfo.end() && "Deferred function not found!");
-  
-  // Move the bit stream to the saved position of the deferred function body 
and
-  // restore the real linkage type for the function.
-  Stream.JumpToBit(DFII->second.first);
-  F->setLinkage((GlobalValue::LinkageTypes)DFII->second.second);
-  
-  if (ParseFunctionBody(F)) {
-if (ErrInfo) *ErrInfo = ErrorString;
-return true;
-  }
-  
-  return false;
-}
-
-void BitcodeReader::dematerializeFunction(Function *F) {
-  // If this function isn't materialized, or if it is a proto, this is a noop.
-  if (F->hasNotBeenReadFromBytecode() || F->isDeclaration())
-return;
-  
-  assert(DeferredFunctionInfo.count(F) && "No info to read function later?");
-  
-  // Just forget the function body, we can remat it later.
-  F->deleteBody();
-  F->setLinkage(GlobalValue::GhostLinkage);
-}
-
-
-Module *BitcodeReader::materializeModule(std::string *ErrInfo) {
-  for (DenseMap >::iterator I = 
-   DeferredFunctionInfo.begin(), E = DeferredFunctionInfo.end(); I != E;
-   ++I) {
-Function *F = I->first;
-if (F->hasNotBeenReadFromBytecode() &&
-materializeFunction(F, ErrInfo))
-  return 0;
-  }
-  return TheModule;
-}
-
-
 /// ParseFunctionBody - Lazily parse the specified function body block.
 bool BitcodeReader::ParseFunctionBody(Function *F) {
   if (Stream.EnterSubBlock(bitc::FUNCTION_BLOCK_ID))
@@ -1597,6 +1557,69 @@
   return false;
 }
 
+//===--===//
+// ModuleProvider implementation
+//===--===//
+
+
+bool BitcodeReader::materializeFunction(Function *F, std::string *ErrInfo) {
+  // If it already is material, ignore the request.
+  if (!F->hasNotBeenReadFromBytecode()) return false;
+  
+  DenseMap >::iterator DFII = 
+DeferredFunctionInfo.find(F);
+  assert(DFII != DeferredFunctionInfo.end() && "Deferred function not found!");
+  
+  // Move the bit stream to the saved position of the deferred function body 
and
+  // restore the real linkage type for the function.
+  Stream.JumpToBit(DFII->second.first);
+  F->setLinkage((GlobalValue::LinkageTypes)DFII->second.second);
+  
+  if (ParseFunctionBody(F)) {
+if (ErrInfo) *ErrInfo = ErrorString;
+return true;
+  }
+  
+  return false;
+}
+
+void BitcodeReader::dematerializeFunction(Function *F) {
+  // If this function isn't materialized, or if it is a proto, this is a noop.
+  if (F->hasNotBeenReadFromBytecode() || F->isDeclaration())
+return;
+  
+  assert(DeferredFunctionInfo.count(F) && "No info to read function later?");
+  
+  // Just forget the function body, we can remat it later.
+  F->deleteBody();
+  F->setLinkage(GlobalValue::GhostLinkage);
+}
+
+
+Module *BitcodeReader::materializeModule(std::string *ErrInfo) {
+  for (DenseMap >::iterator I = 
+   DeferredFunctionInfo.begin(), E = DeferredFunctionInfo.end(); I != E;
+   ++I) {
+Function *F = I->first;
+if (F->hasNotBeenReadFromBytecode() &&
+materializeFunction(F, ErrInfo))
+  return 0;
+  }
+  return TheModule;
+}
+
+
+/// This method is provided by the parent ModuleProvde class and overriden
+/// here. It simply releases the module from its provided and frees up our
+/// state.
+/// @brief Release our hold on the generated module
+Module *BitcodeReader::releaseModule(std::string *ErrInfo) {
+  // Since we're losing

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-05-14 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.48 -> 1.49
BitcodeReader.h updated: 1.19 -> 1.20
---
Log message:

implement the ModuleProvider::dematerializeFunction hook


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

 BitcodeReader.cpp |   27 +++
 BitcodeReader.h   |3 ++-
 2 files changed, 21 insertions(+), 9 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.48 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.49
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.48  Tue May  8 00:38:01 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Tue May 15 01:29:44 2007
@@ -1114,7 +1114,6 @@
   // restore the real linkage type for the function.
   Stream.JumpToBit(DFII->second.first);
   F->setLinkage((GlobalValue::LinkageTypes)DFII->second.second);
-  DeferredFunctionInfo.erase(DFII);
   
   if (ParseFunctionBody(F)) {
 if (ErrInfo) *ErrInfo = ErrorString;
@@ -1124,14 +1123,26 @@
   return false;
 }
 
+void BitcodeReader::dematerializeFunction(Function *F) {
+  // If this function isn't materialized, or if it is a proto, this is a noop.
+  if (F->hasNotBeenReadFromBytecode() || F->isDeclaration())
+return;
+  
+  assert(DeferredFunctionInfo.count(F) && "No info to read function later?");
+  
+  // Just forget the function body, we can remat it later.
+  F->deleteBody();
+  F->setLinkage(GlobalValue::GhostLinkage);
+}
+
+
 Module *BitcodeReader::materializeModule(std::string *ErrInfo) {
-  DenseMap >::iterator I = 
-DeferredFunctionInfo.begin();
-  while (!DeferredFunctionInfo.empty()) {
-Function *F = (*I++).first;
-assert(F->hasNotBeenReadFromBytecode() &&
-   "Deserialized function found in map!");
-if (materializeFunction(F, ErrInfo))
+  for (DenseMap >::iterator I = 
+   DeferredFunctionInfo.begin(), E = DeferredFunctionInfo.end(); I != E;
+   ++I) {
+Function *F = I->first;
+if (F->hasNotBeenReadFromBytecode() &&
+materializeFunction(F, ErrInfo))
   return 0;
   }
   return TheModule;


Index: llvm/lib/Bitcode/Reader/BitcodeReader.h
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.h:1.19 
llvm/lib/Bitcode/Reader/BitcodeReader.h:1.20
--- llvm/lib/Bitcode/Reader/BitcodeReader.h:1.19Sat May  5 22:23:14 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.h Tue May 15 01:29:44 2007
@@ -123,7 +123,8 @@
   
   virtual bool materializeFunction(Function *F, std::string *ErrInfo = 0);
   virtual Module *materializeModule(std::string *ErrInfo = 0);
-  
+  virtual void dematerializeFunction(Function *F);
+
   bool Error(const char *Str) {
 ErrorString = Str;
 return true;



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-07 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.47 -> 1.48
---
Log message:

Make a preemptive bitcode format change to support PR1146: 
http://llvm.org/PR1146 .  This lets us do
pr1146: http://llvm.org/PR1146  in llvm 2.1 without ugly code to emulate old 
behavior.  This should
be merged into the 2.0 release branch.


---
Diffs of the changes:  (+25 -16)

 BitcodeReader.cpp |   41 +
 1 files changed, 25 insertions(+), 16 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.47 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.48
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.47  Sun May  6 14:27:46 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Tue May  8 00:38:01 2007
@@ -985,10 +985,10 @@
 GlobalInits.push_back(std::make_pair(NewGV, InitID-1));
   break;
 }
-// FUNCTION:  [type, callingconv, isproto, linkage, alignment, section,
-// visibility]
+// FUNCTION:  [type, callingconv, isproto, linkage, paramattr,
+// alignment, section, visibility]
 case bitc::MODULE_CODE_FUNCTION: {
-  if (Record.size() < 7)
+  if (Record.size() < 8)
 return Error("Invalid MODULE_CODE_FUNCTION record");
   const Type *Ty = getTypeByID(Record[0]);
   if (!isa(Ty))
@@ -1004,13 +1004,17 @@
   Func->setCallingConv(Record[1]);
   bool isProto = Record[2];
   Func->setLinkage(GetDecodedLinkage(Record[3]));
-  Func->setAlignment((1 << Record[4]) >> 1);
-  if (Record[5]) {
-if (Record[5]-1 >= SectionTable.size())
+  
+  assert(Func->getFunctionType()->getParamAttrs() == 
+ getParamAttrs(Record[4]));
+  
+  Func->setAlignment((1 << Record[5]) >> 1);
+  if (Record[6]) {
+if (Record[6]-1 >= SectionTable.size())
   return Error("Invalid section ID");
-Func->setSection(SectionTable[Record[5]-1]);
+Func->setSection(SectionTable[Record[6]-1]);
   }
-  Func->setVisibility(GetDecodedVisibility(Record[6]));
+  Func->setVisibility(GetDecodedVisibility(Record[7]));
   
   ValueList.push_back(Func);
   
@@ -1364,12 +1368,12 @@
 }
   
 case bitc::FUNC_CODE_INST_INVOKE: { // INVOKE: [cc,fnty, op0,op1,op2, ...]
-  if (Record.size() < 3) return Error("Invalid INVOKE record");
-  unsigned CCInfo = Record[0];
-  BasicBlock *NormalBB = getBasicBlock(Record[1]);
-  BasicBlock *UnwindBB = getBasicBlock(Record[2]);
+  if (Record.size() < 4) return Error("Invalid INVOKE record");
+  unsigned CCInfo = Record[1];
+  BasicBlock *NormalBB = getBasicBlock(Record[2]);
+  BasicBlock *UnwindBB = getBasicBlock(Record[3]);
   
-  unsigned OpNum = 3;
+  unsigned OpNum = 4;
   Value *Callee;
   if (getValueTypePair(Record, OpNum, NextValueNo, Callee))
 return Error("Invalid INVOKE record");
@@ -1383,6 +1387,8 @@
   Record.size() < OpNum+FTy->getNumParams())
 return Error("Invalid INVOKE record");
   
+  assert(FTy->getParamAttrs() == getParamAttrs(Record[0]));
+
   SmallVector Ops;
   for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
 Ops.push_back(getFnValueByID(Record[OpNum], FTy->getParamType(i)));
@@ -1484,11 +1490,12 @@
   break;
 }
 case bitc::FUNC_CODE_INST_CALL: { // CALL: [cc, fnty, fnid, arg0, arg1...]
-  if (Record.size() < 1)
+  if (Record.size() < 2)
 return Error("Invalid CALL record");
-  unsigned CCInfo = Record[0];
   
-  unsigned OpNum = 1;
+  unsigned CCInfo = Record[1];
+  
+  unsigned OpNum = 2;
   Value *Callee;
   if (getValueTypePair(Record, OpNum, NextValueNo, Callee))
 return Error("Invalid CALL record");
@@ -1499,6 +1506,8 @@
   if (!FTy || Record.size() < FTy->getNumParams()+OpNum)
 return Error("Invalid CALL record");
   
+  assert(FTy->getParamAttrs() == getParamAttrs(Record[0]));
+  
   SmallVector Args;
   // Read the fixed params.
   for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-06 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.46 -> 1.47
---
Log message:

fix off-by-one that caused the llvm2cpp test to fail


---
Diffs of the changes:  (+4 -2)

 BitcodeReader.cpp |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.46 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.47
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.46  Sun May  6 03:21:50 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sun May  6 14:27:46 2007
@@ -964,9 +964,11 @@
 Section = SectionTable[Record[5]-1];
   }
   GlobalValue::VisibilityTypes Visibility = GlobalValue::DefaultVisibility;
-  if (Record.size() >= 6) Visibility = GetDecodedVisibility(Record[6]);
+  if (Record.size() > 6)
+Visibility = GetDecodedVisibility(Record[6]);
   bool isThreadLocal = false;
-  if (Record.size() >= 7) isThreadLocal = Record[7];
+  if (Record.size() > 7)
+isThreadLocal = Record[7];
 
   GlobalVariable *NewGV =
 new GlobalVariable(Ty, isConstant, Linkage, 0, "", TheModule);



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-06 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.45 -> 1.46
---
Log message:

Allow structs with zero fields.



---
Diffs of the changes:  (+1 -1)

 BitcodeReader.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.45 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.46
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.45  Sun May  6 02:33:01 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sun May  6 03:21:50 2007
@@ -326,7 +326,7 @@
   break;
 }
 case bitc::TYPE_CODE_STRUCT: {  // STRUCT: [ispacked, eltty x N]
-  if (Record.size() < 2)
+  if (Record.size() < 1)
 return Error("Invalid STRUCT type record");
   std::vector EltTys;
   for (unsigned i = 1, e = Record.size(); i != e; ++i)



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-06 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.44 -> 1.45
---
Log message:

add a missing check


---
Diffs of the changes:  (+1 -0)

 BitcodeReader.cpp |1 +
 1 files changed, 1 insertion(+)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.44 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.45
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.44  Sat May  5 20:58:20 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sun May  6 02:33:01 2007
@@ -691,6 +691,7 @@
 V = UndefValue::get(CurTy);  // Unknown cast.
   } else {
 const Type *OpTy = getTypeByID(Record[1]);
+if (!OpTy) return Error("Invalid CE_CAST record");
 Constant *Op = ValueList.getConstantFwdRef(Record[2], OpTy);
 V = ConstantExpr::getCast(Opc, Op, CurTy);
   }



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-05 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.43 -> 1.44
---
Log message:

implement reading/writing of inlineasm objects


---
Diffs of the changes:  (+21 -0)

 BitcodeReader.cpp |   21 +
 1 files changed, 21 insertions(+)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.43 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.44
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.43  Sat May  5 19:53:07 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sat May  5 20:58:20 2007
@@ -15,6 +15,7 @@
 #include "BitcodeReader.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/ParameterAttributes.h"
@@ -759,6 +760,26 @@
 V = ConstantExpr::getICmp(Record[3], Op0, Op1);
   break;
 }
+case bitc::CST_CODE_INLINEASM: {
+  if (Record.size() < 2) return Error("Invalid INLINEASM record");
+  std::string AsmStr, ConstrStr;
+  bool HasSideEffects = Record[0];
+  unsigned AsmStrSize = Record[1];
+  if (2+AsmStrSize >= Record.size())
+return Error("Invalid INLINEASM record");
+  unsigned ConstStrSize = Record[2+AsmStrSize];
+  if (3+AsmStrSize+ConstStrSize > Record.size())
+return Error("Invalid INLINEASM record");
+  
+  for (unsigned i = 0; i != AsmStrSize; ++i)
+AsmStr += (char)Record[2+i];
+  for (unsigned i = 0; i != ConstStrSize; ++i)
+ConstrStr += (char)Record[3+AsmStrSize+i];
+  const PointerType *PTy = cast(CurTy);
+  V = InlineAsm::get(cast(PTy->getElementType()),
+ AsmStr, ConstrStr, HasSideEffects);
+  break;
+}
 }
 
 ValueList.AssignValue(V, NextCstNo);



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-05 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.42 -> 1.43
---
Log message:

add a denser encoding for null terminated strings, add a 6-bit abbrev as
well.  This shrinks kc++ from 2724088 to 2717360 bytes.



---
Diffs of the changes:  (+14 -0)

 BitcodeReader.cpp |   14 ++
 1 files changed, 14 insertions(+)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.42 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.43
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.42  Sat May  5 19:35:24 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sat May  5 19:53:07 2007
@@ -651,9 +651,23 @@
   
   unsigned Size = Record.size();
   std::vector Elts;
+  for (unsigned i = 0; i != Size; ++i)
+Elts.push_back(ConstantInt::get(EltTy, Record[i]));
+  V = ConstantArray::get(ATy, Elts);
+  break;
+}
+case bitc::CST_CODE_CSTRING: { // CSTRING: [values]
+  if (Record.empty())
+return Error("Invalid CST_AGGREGATE record");
+  
+  const ArrayType *ATy = cast(CurTy);
+  const Type *EltTy = ATy->getElementType();
   
+  unsigned Size = Record.size();
+  std::vector Elts;
   for (unsigned i = 0; i != Size; ++i)
 Elts.push_back(ConstantInt::get(EltTy, Record[i]));
+  Elts.push_back(Constant::getNullValue(EltTy));
   V = ConstantArray::get(ATy, Elts);
   break;
 }



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-05 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.41 -> 1.42
---
Log message:

implement the 'string constant' optimization.  This shrinks kc.bit from
2878544 to 2815788


---
Diffs of the changes:  (+15 -1)

 BitcodeReader.cpp |   16 +++-
 1 files changed, 15 insertions(+), 1 deletion(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.41 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.42
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.41  Sat May  5 19:21:25 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sat May  5 19:35:24 2007
@@ -642,7 +642,21 @@
   }
   break;
 }
-
+case bitc::CST_CODE_STRING: { // STRING: [values]
+  if (Record.empty())
+return Error("Invalid CST_AGGREGATE record");
+
+  const ArrayType *ATy = cast(CurTy);
+  const Type *EltTy = ATy->getElementType();
+  
+  unsigned Size = Record.size();
+  std::vector Elts;
+  
+  for (unsigned i = 0; i != Size; ++i)
+Elts.push_back(ConstantInt::get(EltTy, Record[i]));
+  V = ConstantArray::get(ATy, Elts);
+  break;
+}
 case bitc::CST_CODE_CE_BINOP: {  // CE_BINOP: [opcode, opval, opval]
   if (Record.size() < 3) return Error("Invalid CE_BINOP record");
   int Opc = GetDecodedBinaryOpcode(Record[0], CurTy);



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-05 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.40 -> 1.41
---
Log message:

further reduce the redundancy of types in the instruction encoding.  This
shrinks function bodies in kc++ from 891913B to 884073B


---
Diffs of the changes:  (+65 -64)

 BitcodeReader.cpp |  129 +++---
 1 files changed, 65 insertions(+), 64 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.40 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.41
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.40  Sat May  5 19:00:00 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sat May  5 19:21:25 2007
@@ -1145,24 +1145,29 @@
   CurBB = FunctionBBs[0];
   continue;
   
-case bitc::FUNC_CODE_INST_BINOP: {// BINOP: [opcode, ty, opval, opval]
-  if (Record.size() < 4) return Error("Invalid BINOP record");
-  const Type *Ty = getTypeByID(Record[1]);
-  int Opc = GetDecodedBinaryOpcode(Record[0], Ty);
-  Value *LHS = getFnValueByID(Record[2], Ty);
-  Value *RHS = getFnValueByID(Record[3], Ty);
-  if (Opc == -1 || Ty == 0 || LHS == 0 || RHS == 0)
- return Error("Invalid BINOP record");
+case bitc::FUNC_CODE_INST_BINOP: {// BINOP: [opval, ty, opval, opcode]
+  unsigned OpNum = 0;
+  Value *LHS, *RHS;
+  if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
+  getValue(Record, OpNum, LHS->getType(), RHS) ||
+  OpNum+1 != Record.size())
+return Error("Invalid BINOP record");
+  
+  int Opc = GetDecodedBinaryOpcode(Record[OpNum], LHS->getType());
+  if (Opc == -1) return Error("Invalid BINOP record");
   I = BinaryOperator::create((Instruction::BinaryOps)Opc, LHS, RHS);
   break;
 }
-case bitc::FUNC_CODE_INST_CAST: {// CAST: [opcode, ty, opty, opval]
-  if (Record.size() < 4) return Error("Invalid CAST record");
-  int Opc = GetDecodedCastOpcode(Record[0]);
-  const Type *ResTy = getTypeByID(Record[1]);
-  const Type *OpTy = getTypeByID(Record[2]);
-  Value *Op = getFnValueByID(Record[3], OpTy);
-  if (Opc == -1 || ResTy == 0 || OpTy == 0 || Op == 0)
+case bitc::FUNC_CODE_INST_CAST: {// CAST: [opval, opty, destty, 
castopc]
+  unsigned OpNum = 0;
+  Value *Op;
+  if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
+  OpNum+2 != Record.size())
+return Error("Invalid CAST record");
+  
+  const Type *ResTy = getTypeByID(Record[OpNum]);
+  int Opc = GetDecodedCastOpcode(Record[OpNum+1]);
+  if (Opc == -1 || ResTy == 0)
 return Error("Invalid CAST record");
   I = CastInst::create((Instruction::CastOps)Opc, Op, ResTy);
   break;
@@ -1185,54 +1190,52 @@
   break;
 }
   
-case bitc::FUNC_CODE_INST_SELECT: { // SELECT: [ty, opval, opval, opval]
-  if (Record.size() < 4) return Error("Invalid SELECT record");
-  const Type *Ty = getTypeByID(Record[0]);
-  Value *Cond = getFnValueByID(Record[1], Type::Int1Ty);
-  Value *LHS = getFnValueByID(Record[2], Ty);
-  Value *RHS = getFnValueByID(Record[3], Ty);
-  if (Ty == 0 || Cond == 0 || LHS == 0 || RHS == 0)
+case bitc::FUNC_CODE_INST_SELECT: { // SELECT: [opval, ty, opval, opval]
+  unsigned OpNum = 0;
+  Value *TrueVal, *FalseVal, *Cond;
+  if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal) ||
+  getValue(Record, OpNum, TrueVal->getType(), FalseVal) ||
+  getValue(Record, OpNum, Type::Int1Ty, Cond))
 return Error("Invalid SELECT record");
-  I = new SelectInst(Cond, LHS, RHS);
+  
+  I = new SelectInst(Cond, TrueVal, FalseVal);
   break;
 }
   
 case bitc::FUNC_CODE_INST_EXTRACTELT: { // EXTRACTELT: [opty, opval, opval]
-  if (Record.size() < 3) return Error("Invalid EXTRACTELT record");
-  const Type *OpTy = getTypeByID(Record[0]);
-  Value *Vec = getFnValueByID(Record[1], OpTy);
-  Value *Idx = getFnValueByID(Record[2], Type::Int32Ty);
-  if (OpTy == 0 || Vec == 0 || Idx == 0)
+  unsigned OpNum = 0;
+  Value *Vec, *Idx;
+  if (getValueTypePair(Record, OpNum, NextValueNo, Vec) ||
+  getValue(Record, OpNum, Type::Int32Ty, Idx))
 return Error("Invalid EXTRACTELT record");
   I = new ExtractElementInst(Vec, Idx);
   break;
 }
   
 case bitc::FUNC_CODE_INST_INSERTELT: { // INSERTELT: [ty, 
opval,opval,opval]
-  if (Record.size() < 4) return Error("Invalid INSERTELT record");
-  const VectorType *OpTy = 
-dyn_cast_or_null(getTypeByID(Record[0]));
-  if (OpTy == 0) return Error("Invalid INSERTELT record");
-  Value *Vec = getFnValueByID(Record[1], OpTy);
-  Value *Elt = getFnValueByID(Record[2], OpTy->getElementType());
-  Value *Idx = getFnValueByID(Record[3], Type::Int32Ty);
-  if (Vec == 0 || Elt == 0 || Idx == 0)
+  unsigned OpNum

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-05-05 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.39 -> 1.40
BitcodeReader.h updated: 1.17 -> 1.18
---
Log message:

stop encoding type/value pairs when the type is implied by the value.
This shrinks the function block of kc++ from 1055K to 906K


---
Diffs of the changes:  (+97 -75)

 BitcodeReader.cpp |  144 +-
 BitcodeReader.h   |   28 ++
 2 files changed, 97 insertions(+), 75 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.39 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.40
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.39  Sat May  5 13:57:30 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sat May  5 19:00:00 2007
@@ -1168,23 +1168,20 @@
   break;
 }
 case bitc::FUNC_CODE_INST_GEP: { // GEP: [n x operands]
-  if (Record.size() < 2 || (Record.size() & 1))
-return Error("Invalid GEP record");
-  const Type *OpTy = getTypeByID(Record[0]);
-  Value *Op = getFnValueByID(Record[1], OpTy);
-  if (OpTy == 0 || Op == 0)
+  unsigned OpNum = 0;
+  Value *BasePtr;
+  if (getValueTypePair(Record, OpNum, NextValueNo, BasePtr))
 return Error("Invalid GEP record");
 
   SmallVector GEPIdx;
-  for (unsigned i = 1, e = Record.size()/2; i != e; ++i) {
-const Type *IdxTy = getTypeByID(Record[i*2]);
-Value *Idx = getFnValueByID(Record[i*2+1], IdxTy);
-if (IdxTy == 0 || Idx == 0)
+  while (OpNum != Record.size()) {
+Value *Op;
+if (getValueTypePair(Record, OpNum, NextValueNo, Op))
   return Error("Invalid GEP record");
-GEPIdx.push_back(Idx);
+GEPIdx.push_back(Op);
   }
 
-  I = new GetElementPtrInst(Op, &GEPIdx[0], GEPIdx.size());
+  I = new GetElementPtrInst(BasePtr, &GEPIdx[0], GEPIdx.size());
   break;
 }
   
@@ -1242,16 +1239,17 @@
 }
   
 case bitc::FUNC_CODE_INST_CMP: { // CMP: [opty, opval, opval, pred]
-  if (Record.size() < 4) return Error("Invalid CMP record");
-  const Type *OpTy = getTypeByID(Record[0]);
-  Value *LHS = getFnValueByID(Record[1], OpTy);
-  Value *RHS = getFnValueByID(Record[2], OpTy);
-  if (OpTy == 0 || LHS == 0 || RHS == 0)
+  unsigned OpNum = 0;
+  Value *LHS, *RHS;
+  if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
+  getValue(Record, OpNum, LHS->getType(), RHS) ||
+  OpNum+1 != Record.size())
 return Error("Invalid CMP record");
-  if (OpTy->isFPOrFPVector())
-I = new FCmpInst((FCmpInst::Predicate)Record[3], LHS, RHS);
+  
+  if (LHS->getType()->isFPOrFPVector())
+I = new FCmpInst((FCmpInst::Predicate)Record[OpNum], LHS, RHS);
   else
-I = new ICmpInst((ICmpInst::Predicate)Record[3], LHS, RHS);
+I = new ICmpInst((ICmpInst::Predicate)Record[OpNum], LHS, RHS);
   break;
 }
 
@@ -1259,16 +1257,15 @@
   if (Record.size() == 0) {
 I = new ReturnInst();
 break;
-  }
-  if (Record.size() == 2) {
-const Type *OpTy = getTypeByID(Record[0]);
-Value *Op = getFnValueByID(Record[1], OpTy);
-if (!OpTy || !Op)
+  } else {
+unsigned OpNum = 0;
+Value *Op;
+if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
+OpNum != Record.size())
   return Error("Invalid RET record");
 I = new ReturnInst(Op);
 break;
   }
-  return Error("Invalid RET record");
 case bitc::FUNC_CODE_INST_BR: { // BR: [bb#, bb#, opval] or [bb#]
   if (Record.size() != 1 && Record.size() != 3)
 return Error("Invalid BR record");
@@ -1312,46 +1309,42 @@
 }
   
 case bitc::FUNC_CODE_INST_INVOKE: { // INVOKE: [cc,fnty, op0,op1,op2, ...]
-  if (Record.size() < 5)
-return Error("Invalid INVOKE record");
+  if (Record.size() < 3) return Error("Invalid INVOKE record");
   unsigned CCInfo = Record[0];
-  const PointerType *CalleeTy =
-dyn_cast_or_null(getTypeByID(Record[1]));
-  Value *Callee = getFnValueByID(Record[2], CalleeTy);
-  BasicBlock *NormalBB = getBasicBlock(Record[3]);
-  BasicBlock *UnwindBB = getBasicBlock(Record[4]);
-  if (CalleeTy == 0 || Callee == 0 || NormalBB == 0 || UnwindBB == 0)
+  BasicBlock *NormalBB = getBasicBlock(Record[1]);
+  BasicBlock *UnwindBB = getBasicBlock(Record[2]);
+  
+  unsigned OpNum = 3;
+  Value *Callee;
+  if (getValueTypePair(Record, OpNum, NextValueNo, Callee))
 return Error("Invalid INVOKE record");
   
-  const FunctionType *FTy =
+  const PointerType *CalleeTy = dyn_cast(Callee->getType());
+  const FunctionType *FTy = !CalleeTy ? 0 :
 dyn_cast(CalleeTy->getElementType());
 
   // Check that the right number of fixed parameters are here.
-  if (FTy == 0 || Record.size() < 5+FTy->getNum

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-05 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.38 -> 1.39
---
Log message:

add support for BLOCKINFO records at the module level.  This fixes the reader
issues reid noticed last night.



---
Diffs of the changes:  (+4 -0)

 BitcodeReader.cpp |4 
 1 files changed, 4 insertions(+)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.38 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.39
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.38  Fri May  4 19:17:00 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sat May  5 13:57:30 2007
@@ -805,6 +805,10 @@
 if (Stream.SkipBlock())
   return Error("Malformed block record");
 break;
+  case bitc::BLOCKINFO_BLOCK_ID:
+if (Stream.ReadBlockInfoBlock())
+  return Error("Malformed BlockInfoBlock");
+break;
   case bitc::PARAMATTR_BLOCK_ID:
 if (ParseParamAttrBlock())
   return true;



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-04 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.37 -> 1.38
---
Log message:

Implement support for globally associating abbrevs with block IDs, which
relieves us from having to emit the abbrevs into each instance of the block.
This shrinks kc.bit from 3368K to K, but will be a more significant win
once instructions are abbreviated.

The VST went from:

  Block ID #14 (VALUE_SYMTAB):
  Num Instances: 2345
 Total Size: 1.29508e+07b/1.61885e+06B/404713W
   Average Size: 5522.73b/690.342B/172.585W
  % of file: 48.0645
  Tot/Avg SubBlocks: 0/0
Tot/Avg Abbrevs: 7035/3
Tot/Avg Records: 120924/51.5667
  % Abbrev Recs: 100

to:

  Block ID #14 (VALUE_SYMTAB):
  Num Instances: 2345
 Total Size: 1.26713e+07b/1.58391e+06B/395978W
   Average Size: 5403.53b/675.442B/168.86W
  % of file: 47.5198
  Tot/Avg SubBlocks: 0/0
Tot/Avg Abbrevs: 0/0
Tot/Avg Records: 120924/51.5667
  % Abbrev Recs: 100

because we didn't emit the same 3 abbrevs 2345 times :)



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

 BitcodeReader.cpp |   28 ++--
 1 files changed, 18 insertions(+), 10 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.37 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.38
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.37  Fri May  4 14:11:41 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Fri May  4 19:17:00 2007
@@ -182,7 +182,7 @@
 
//===--===//
 
 bool BitcodeReader::ParseParamAttrBlock() {
-  if (Stream.EnterSubBlock())
+  if (Stream.EnterSubBlock(bitc::PARAMATTR_BLOCK_ID))
 return Error("Malformed block record");
   
   if (!ParamAttrs.empty())
@@ -239,7 +239,7 @@
 
 
 bool BitcodeReader::ParseTypeTable() {
-  if (Stream.EnterSubBlock())
+  if (Stream.EnterSubBlock(bitc::TYPE_BLOCK_ID))
 return Error("Malformed block record");
   
   if (!TypeList.empty())
@@ -378,7 +378,7 @@
 
 
 bool BitcodeReader::ParseTypeSymbolTable() {
-  if (Stream.EnterSubBlock())
+  if (Stream.EnterSubBlock(bitc::TYPE_SYMTAB_BLOCK_ID))
 return Error("Malformed block record");
   
   SmallVector Record;
@@ -426,7 +426,7 @@
 }
 
 bool BitcodeReader::ParseValueSymbolTable() {
-  if (Stream.EnterSubBlock())
+  if (Stream.EnterSubBlock(bitc::VALUE_SYMTAB_BLOCK_ID))
 return Error("Malformed block record");
 
   SmallVector Record;
@@ -536,7 +536,7 @@
 
 
 bool BitcodeReader::ParseConstants() {
-  if (Stream.EnterSubBlock())
+  if (Stream.EnterSubBlock(bitc::CONSTANTS_BLOCK_ID))
 return Error("Malformed block record");
 
   SmallVector Record;
@@ -768,7 +768,7 @@
   if (TheModule)
 return Error("Multiple MODULE_BLOCKs in same stream");
   
-  if (Stream.EnterSubBlock())
+  if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID))
 return Error("Malformed block record");
 
   // Otherwise, create the module.
@@ -1022,11 +1022,19 @@
 unsigned BlockID = Stream.ReadSubBlockID();
 
 // We only know the MODULE subblock ID.
-if (BlockID == bitc::MODULE_BLOCK_ID) {
+switch (BlockID) {
+case bitc::BLOCKINFO_BLOCK_ID:
+  if (Stream.ReadBlockInfoBlock())
+return Error("Malformed BlockInfoBlock");
+  break;
+case bitc::MODULE_BLOCK_ID:
   if (ParseModule(Buffer->getBufferIdentifier()))
 return true;
-} else if (Stream.SkipBlock()) {
-  return Error("Malformed block record");
+  break;
+default:
+  if (Stream.SkipBlock())
+return Error("Malformed block record");
+  break;
 }
   }
   
@@ -1072,7 +1080,7 @@
 
 /// ParseFunctionBody - Lazily parse the specified function body block.
 bool BitcodeReader::ParseFunctionBody(Function *F) {
-  if (Stream.EnterSubBlock())
+  if (Stream.EnterSubBlock(bitc::FUNCTION_BLOCK_ID))
 return Error("Malformed block record");
   
   unsigned ModuleValueListSize = ValueList.size();



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-04 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.36 -> 1.37
---
Log message:

eliminate internal length fields from record.  Records already know their
total length



---
Diffs of the changes:  (+36 -37)

 BitcodeReader.cpp |   73 ++
 1 files changed, 36 insertions(+), 37 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.36 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.37
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.36  Thu May  3 22:57:30 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Fri May  4 14:11:41 2007
@@ -36,11 +36,11 @@
 template
 static bool ConvertToString(SmallVector &Record, unsigned Idx,
 StrTy &Result) {
-  if (Record.size() < Idx+1 || Record.size() < Record[Idx]+Idx+1)
+  if (Idx > Record.size())
 return true;
   
-  for (unsigned i = 0, e = Record[Idx]; i != e; ++i)
-Result += (char)Record[Idx+i+1];
+  for (unsigned i = Idx, e = Record.size(); i != e; ++i)
+Result += (char)Record[i];
   return false;
 }
 
@@ -313,23 +313,23 @@
   ResultTy = PointerType::get(getTypeByID(Record[0], true));
   break;
 case bitc::TYPE_CODE_FUNCTION: {
-  // FUNCTION: [vararg, attrid, retty, #pararms, paramty N]
-  if (Record.size() < 4 || Record.size() < Record[3]+4)
+  // FUNCTION: [vararg, attrid, retty, paramty x N]
+  if (Record.size() < 3)
 return Error("Invalid FUNCTION type record");
   std::vector ArgTys;
-  for (unsigned i = 0, e = Record[3]; i != e; ++i)
-ArgTys.push_back(getTypeByID(Record[4+i], true));
+  for (unsigned i = 3, e = Record.size(); i != e; ++i)
+ArgTys.push_back(getTypeByID(Record[i], true));
   
   ResultTy = FunctionType::get(getTypeByID(Record[2], true), ArgTys,
Record[0], getParamAttrs(Record[1]));
   break;
 }
-case bitc::TYPE_CODE_STRUCT: {  // STRUCT: [ispacked, #elts, eltty x N]
-  if (Record.size() < 2 || Record.size() < Record[1]+2)
+case bitc::TYPE_CODE_STRUCT: {  // STRUCT: [ispacked, eltty x N]
+  if (Record.size() < 2)
 return Error("Invalid STRUCT type record");
   std::vector EltTys;
-  for (unsigned i = 0, e = Record[1]; i != e; ++i)
-EltTys.push_back(getTypeByID(Record[2+i], true));
+  for (unsigned i = 1, e = Record.size(); i != e; ++i)
+EltTys.push_back(getTypeByID(Record[i], true));
   ResultTy = StructType::get(EltTys, Record[0]);
   break;
 }
@@ -411,7 +411,7 @@
 switch (Stream.ReadRecord(Code, Record)) {
 default:  // Default behavior: unknown type.
   break;
-case bitc::TST_CODE_ENTRY:// TST_ENTRY: [typeid, namelen, namechar x N]
+case bitc::TST_CODE_ENTRY:// TST_ENTRY: [typeid, namechar x N]
   if (ConvertToString(Record, 1, TypeName))
 return Error("Invalid TST_ENTRY record");
   unsigned TypeID = Record[0];
@@ -458,7 +458,7 @@
 switch (Stream.ReadRecord(Code, Record)) {
 default:  // Default behavior: unknown type.
   break;
-case bitc::VST_CODE_ENTRY: {  // VST_ENTRY: [valueid, namelen, namechar x 
N]
+case bitc::VST_CODE_ENTRY: {  // VST_ENTRY: [valueid, namechar x N]
   if (ConvertToString(Record, 1, ValueName))
 return Error("Invalid TST_ENTRY record");
   unsigned ValueID = Record[0];
@@ -591,16 +591,15 @@
 return Error("Invalid CST_INTEGER record");
   V = ConstantInt::get(CurTy, DecodeSignRotatedValue(Record[0]));
   break;
-case bitc::CST_CODE_WIDE_INTEGER: {// WIDE_INTEGER: [n, n x intval]
-  if (!isa(CurTy) || Record.empty() ||
-  Record.size() < Record[0]+1)
+case bitc::CST_CODE_WIDE_INTEGER: {// WIDE_INTEGER: [n x intval]
+  if (!isa(CurTy) || Record.empty())
 return Error("Invalid WIDE_INTEGER record");
   
-  unsigned NumWords = Record[0];
+  unsigned NumWords = Record.size();
   SmallVector Words;
   Words.resize(NumWords);
   for (unsigned i = 0; i != NumWords; ++i)
-Words[i] = DecodeSignRotatedValue(Record[i+1]);
+Words[i] = DecodeSignRotatedValue(Record[i]);
   V = ConstantInt::get(APInt(cast(CurTy)->getBitWidth(),
  NumWords, &Words[0]));
   break;
@@ -616,27 +615,27 @@
 V = UndefValue::get(CurTy);
   break;
   
-case bitc::CST_CODE_AGGREGATE: {// AGGREGATE: [n, n x value number]
-  if (Record.empty() || Record.size() < Record[0]+1)
+case bitc::CST_CODE_AGGREGATE: {// AGGREGATE: [n x value number]
+  if (Record.empty())
 return Error("Invalid CST_AGGREGATE record");
   
-  unsigned Size = Record[0];
+  unsigned Size = Record.size();
   std::vector Elts;
   
   if (const StructType *STy = dyn_cast(CurTy)) {
 for (unsigned i = 0; i != Size; ++i)
-  Elts.push_back(ValueList.getConstantF

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.35 -> 1.36
---
Log message:

storeinst ctor takes isvolatile before alignment.  With this, 176.gcc roundtrips


---
Diffs of the changes:  (+1 -1)

 BitcodeReader.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.35 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.36
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.35  Thu May  3 22:50:29 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May  3 22:57:30 2007
@@ -1423,7 +1423,7 @@
   Value *Ptr = getFnValueByID(Record[2], OpTy);
   if (!OpTy || !Op || !Ptr)
 return Error("Invalid STORE record");
-  I = new StoreInst(Op, Ptr, (1 << Record[3]) >> 1, Record[4]);
+  I = new StoreInst(Op, Ptr, Record[4], (1 << Record[3]) >> 1);
   break;
 }
 case bitc::FUNC_CODE_INST_CALL: { // CALL: [cc, fnty, fnid, arg0, arg1...]



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.34 -> 1.35
---
Log message:

fix a misplaced error


---
Diffs of the changes:  (+1 -1)

 BitcodeReader.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.34 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.35
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.34  Thu May  3 22:41:34 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May  3 22:50:29 2007
@@ -1508,8 +1508,8 @@
   delete A;
 }
   }
+  return Error("Never resolved value found in function!");
 }
-return Error("Never resolved value found in function!");
   }
   
   // Trim the value list down to the size it was before we parsed this 
function.



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.33 -> 1.34
---
Log message:

encode and read param attrs along with function type.  WE can now roundtrip 
Olden/voronoi loslessly


---
Diffs of the changes:  (+6 -7)

 BitcodeReader.cpp |   13 ++---
 1 files changed, 6 insertions(+), 7 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.33 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.34
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.33  Thu May  3 22:30:17 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May  3 22:41:34 2007
@@ -313,16 +313,15 @@
   ResultTy = PointerType::get(getTypeByID(Record[0], true));
   break;
 case bitc::TYPE_CODE_FUNCTION: {
-  // FUNCTION: [vararg, retty, #pararms, paramty N]
-  if (Record.size() < 3 || Record.size() < Record[2]+3)
+  // FUNCTION: [vararg, attrid, retty, #pararms, paramty N]
+  if (Record.size() < 4 || Record.size() < Record[3]+4)
 return Error("Invalid FUNCTION type record");
   std::vector ArgTys;
-  for (unsigned i = 0, e = Record[2]; i != e; ++i)
-ArgTys.push_back(getTypeByID(Record[3+i], true));
+  for (unsigned i = 0, e = Record[3]; i != e; ++i)
+ArgTys.push_back(getTypeByID(Record[4+i], true));
   
-  // FIXME: PARAM TYS.
-  ResultTy = FunctionType::get(getTypeByID(Record[1], true), ArgTys,
-   Record[0]);
+  ResultTy = FunctionType::get(getTypeByID(Record[2], true), ArgTys,
+   Record[0], getParamAttrs(Record[1]));
   break;
 }
 case bitc::TYPE_CODE_STRUCT: {  // STRUCT: [ispacked, #elts, eltty x N]



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-05-03 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.32 -> 1.33
BitcodeReader.h updated: 1.16 -> 1.17
---
Log message:

add support for reading the param attrs block


---
Diffs of the changes:  (+82 -0)

 BitcodeReader.cpp |   69 ++
 BitcodeReader.h   |   13 ++
 2 files changed, 82 insertions(+)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.32 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.33
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.32  Thu May  3 22:02:54 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May  3 22:30:17 2007
@@ -17,6 +17,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
+#include "llvm/ParameterAttributes.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -26,6 +27,9 @@
   delete Buffer;
 }
 
+//===--===//
+//  Helper functions to implement forward reference resolution, etc.
+//===--===//
 
 /// ConvertToString - Convert a string from a record into an std::string, 
return
 /// true on failure.
@@ -173,6 +177,67 @@
   return TypeList.back().get();
 }
 
+//===--===//
+//  Functions for parsing blocks from the bitcode file
+//===--===//
+
+bool BitcodeReader::ParseParamAttrBlock() {
+  if (Stream.EnterSubBlock())
+return Error("Malformed block record");
+  
+  if (!ParamAttrs.empty())
+return Error("Multiple PARAMATTR blocks found!");
+  
+  SmallVector Record;
+  
+  ParamAttrsVector Attrs;
+  
+  // Read all the records.
+  while (1) {
+unsigned Code = Stream.ReadCode();
+if (Code == bitc::END_BLOCK) {
+  if (Stream.ReadBlockEnd())
+return Error("Error at end of PARAMATTR block");
+  return false;
+}
+
+if (Code == bitc::ENTER_SUBBLOCK) {
+  // No known subblocks, always skip them.
+  Stream.ReadSubBlockID();
+  if (Stream.SkipBlock())
+return Error("Malformed block record");
+  continue;
+}
+
+if (Code == bitc::DEFINE_ABBREV) {
+  Stream.ReadAbbrevRecord();
+  continue;
+}
+
+// Read a record.
+Record.clear();
+switch (Stream.ReadRecord(Code, Record)) {
+default:  // Default behavior: ignore.
+  break;
+case bitc::PARAMATTR_CODE_ENTRY: { // ENTRY: [paramidx0, attr0, ...]
+  if (Record.size() & 1)
+return Error("Invalid ENTRY record");
+
+  ParamAttrsWithIndex PAWI;
+  for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
+PAWI.index = Record[i];
+PAWI.attrs = Record[i+1];
+Attrs.push_back(PAWI);
+  }
+  ParamAttrs.push_back(ParamAttrsList::get(Attrs));
+  Attrs.clear();
+  break;
+}
+}
+  }
+}
+
+
 bool BitcodeReader::ParseTypeTable() {
   if (Stream.EnterSubBlock())
 return Error("Malformed block record");
@@ -742,6 +807,10 @@
 if (Stream.SkipBlock())
   return Error("Malformed block record");
 break;
+  case bitc::PARAMATTR_BLOCK_ID:
+if (ParseParamAttrBlock())
+  return true;
+break;
   case bitc::TYPE_BLOCK_ID:
 if (ParseTypeTable())
   return true;


Index: llvm/lib/Bitcode/Reader/BitcodeReader.h
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.h:1.16 
llvm/lib/Bitcode/Reader/BitcodeReader.h:1.17
--- llvm/lib/Bitcode/Reader/BitcodeReader.h:1.16Wed May  2 00:46:45 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.h Thu May  3 22:30:17 2007
@@ -24,6 +24,7 @@
 
 namespace llvm {
   class MemoryBuffer;
+  class ParamAttrsList;
   
 class BitcodeReaderValueList : public User {
   std::vector Uses;
@@ -85,6 +86,11 @@
   std::vector > GlobalInits;
   std::vector > AliasInits;
   
+  /// ParamAttrs - The set of parameter attributes by index.  Index zero in the
+  /// file is for null, and is thus not represented here.  As such all indices
+  /// are off by one.
+  std::vector ParamAttrs;
+  
   /// FunctionBBs - While parsing a function body, this is a list of the basic
   /// blocks for the function.
   std::vector FunctionBBs;
@@ -136,8 +142,15 @@
 if (ID >= FunctionBBs.size()) return 0; // Invalid ID
 return FunctionBBs[ID];
   }
+  const ParamAttrsList *getParamAttrs(unsigned i) const {
+if (i-1 < ParamAttrs.size())
+  return ParamAttrs[i-1];
+return 0;
+  }
+
   
   bool ParseModule(const std::string &ModuleID);
+  bool ParseParamAttrBlock();
   bool ParseTypeTable();
   bool ParseTypeSymbolTable();
   bool ParseValueSymbolTable();



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

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.31 -> 1.32
---
Log message:

remove dead code


---
Diffs of the changes:  (+0 -6)

 BitcodeReader.cpp |6 --
 1 files changed, 6 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.31 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.32
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.31  Thu May  3 20:43:33 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May  3 22:02:54 2007
@@ -221,12 +221,6 @@
 return Error("Invalid TYPE_CODE_NUMENTRY record");
   TypeList.reserve(Record[0]);
   continue;
-case bitc::TYPE_CODE_META:  // TYPE_CODE_META: [metacode]...
-  // No metadata supported yet.
-  if (Record.size() < 1)
-return Error("Invalid TYPE_CODE_META record");
-  continue;
-  
 case bitc::TYPE_CODE_VOID:  // VOID
   ResultTy = Type::VoidTy;
   break;



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


Re: [llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Chris Lattner

On May 3, 2007, at 7:32 PM, Reid Spencer wrote:

> On Thu, 3 May 2007 19:28:14 -0700
>  Chris Lattner <[EMAIL PROTECTED]> wrote:
>>>
>>> Allow this to compile with gcc 4.0.X
>>
>> Doh, thanks Reid, FWIW, that bug is fixed in apple gcc 4.2.  Now they
>> just need to finish it :)
>
> Yeah, plight of the "compiler poor" like me :)

By fixing it, I mean gcc 4.2 will actually catch and emit an error  
about this stuff.

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


Re: [llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Reid Spencer
On Thu, 3 May 2007 19:28:14 -0700
 Chris Lattner <[EMAIL PROTECTED]> wrote:
>>
>> Allow this to compile with gcc 4.0.X
>
>Doh, thanks Reid, FWIW, that bug is fixed in apple gcc 4.2.  Now they  
>just need to finish it :)

Yeah, plight of the "compiler poor" like me :)

>
>-Chris
>
>>
>> ---
>> Diffs of the changes:  (+4 -2)
>>
>>  BitcodeReader.cpp |6 --
>>  1 files changed, 4 insertions(+), 2 deletions(-)
>>
>>
>> Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
>> diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.30 llvm/lib/ 
>> Bitcode/Reader/BitcodeReader.cpp:1.31
>> --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.30   Thu May  3  
>> 17:34:03 2007
>> +++ llvm/lib/Bitcode/Reader/BitcodeReader.cppThu May  3 20:43:33 2007
>> @@ -400,7 +400,7 @@
>>  switch (Stream.ReadRecord(Code, Record)) {
>>  default:  // Default behavior: unknown type.
>>break;
>> -case bitc::VST_CODE_ENTRY:// VST_ENTRY: [valueid, namelen,  
>> namechar x N]
>> +case bitc::VST_CODE_ENTRY: {  // VST_ENTRY: [valueid, namelen,  
>> namechar x N]
>>if (ConvertToString(Record, 1, ValueName))
>>  return Error("Invalid TST_ENTRY record");
>>unsigned ValueID = Record[0];
>> @@ -411,7 +411,8 @@
>>V->setName(&ValueName[0], ValueName.size());
>>ValueName.clear();
>>break;
>> -case bitc::VST_CODE_BBENTRY:
>> +}
>> +case bitc::VST_CODE_BBENTRY: {
>>if (ConvertToString(Record, 1, ValueName))
>>  return Error("Invalid VST_BBENTRY record");
>>BasicBlock *BB = getBasicBlock(Record[0]);
>> @@ -422,6 +423,7 @@
>>ValueName.clear();
>>break;
>>  }
>> +}
>>}
>>  }
>>
>>
>>
>>
>> ___
>> llvm-commits mailing list
>> llvm-commits@cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>___
>llvm-commits mailing list
>llvm-commits@cs.uiuc.edu
>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

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


Re: [llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Chris Lattner
>
> Allow this to compile with gcc 4.0.X

Doh, thanks Reid, FWIW, that bug is fixed in apple gcc 4.2.  Now they  
just need to finish it :)

-Chris

>
> ---
> Diffs of the changes:  (+4 -2)
>
>  BitcodeReader.cpp |6 --
>  1 files changed, 4 insertions(+), 2 deletions(-)
>
>
> Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
> diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.30 llvm/lib/ 
> Bitcode/Reader/BitcodeReader.cpp:1.31
> --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.30Thu May  3  
> 17:34:03 2007
> +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp Thu May  3 20:43:33 2007
> @@ -400,7 +400,7 @@
>  switch (Stream.ReadRecord(Code, Record)) {
>  default:  // Default behavior: unknown type.
>break;
> -case bitc::VST_CODE_ENTRY:// VST_ENTRY: [valueid, namelen,  
> namechar x N]
> +case bitc::VST_CODE_ENTRY: {  // VST_ENTRY: [valueid, namelen,  
> namechar x N]
>if (ConvertToString(Record, 1, ValueName))
>  return Error("Invalid TST_ENTRY record");
>unsigned ValueID = Record[0];
> @@ -411,7 +411,8 @@
>V->setName(&ValueName[0], ValueName.size());
>ValueName.clear();
>break;
> -case bitc::VST_CODE_BBENTRY:
> +}
> +case bitc::VST_CODE_BBENTRY: {
>if (ConvertToString(Record, 1, ValueName))
>  return Error("Invalid VST_BBENTRY record");
>BasicBlock *BB = getBasicBlock(Record[0]);
> @@ -422,6 +423,7 @@
>ValueName.clear();
>break;
>  }
> +}
>}
>  }
>
>
>
>
> ___
> llvm-commits mailing list
> llvm-commits@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Reid Spencer


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.30 -> 1.31
---
Log message:

Allow this to compile with gcc 4.0.X


---
Diffs of the changes:  (+4 -2)

 BitcodeReader.cpp |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.30 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.31
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.30  Thu May  3 17:34:03 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May  3 20:43:33 2007
@@ -400,7 +400,7 @@
 switch (Stream.ReadRecord(Code, Record)) {
 default:  // Default behavior: unknown type.
   break;
-case bitc::VST_CODE_ENTRY:// VST_ENTRY: [valueid, namelen, namechar x 
N]
+case bitc::VST_CODE_ENTRY: {  // VST_ENTRY: [valueid, namelen, namechar x 
N]
   if (ConvertToString(Record, 1, ValueName))
 return Error("Invalid TST_ENTRY record");
   unsigned ValueID = Record[0];
@@ -411,7 +411,8 @@
   V->setName(&ValueName[0], ValueName.size());
   ValueName.clear();
   break;
-case bitc::VST_CODE_BBENTRY:
+}
+case bitc::VST_CODE_BBENTRY: {
   if (ConvertToString(Record, 1, ValueName))
 return Error("Invalid VST_BBENTRY record");
   BasicBlock *BB = getBasicBlock(Record[0]);
@@ -422,6 +423,7 @@
   ValueName.clear();
   break;
 }
+}
   }
 }
 



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.29 -> 1.30
---
Log message:

Encoding calling conv info in call/invoke instrs, tree add now round trips 
completely


---
Diffs of the changes:  (+21 -16)

 BitcodeReader.cpp |   37 +
 1 files changed, 21 insertions(+), 16 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.29 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.30
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.29  Thu May  3 17:21:59 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May  3 17:34:03 2007
@@ -1236,14 +1236,15 @@
   break;
 }
   
-case bitc::FUNC_CODE_INST_INVOKE: { // INVOKE: [fnty, op0,op1,op2, ...]
-  if (Record.size() < 4)
+case bitc::FUNC_CODE_INST_INVOKE: { // INVOKE: [cc,fnty, op0,op1,op2, ...]
+  if (Record.size() < 5)
 return Error("Invalid INVOKE record");
+  unsigned CCInfo = Record[0];
   const PointerType *CalleeTy =
-dyn_cast_or_null(getTypeByID(Record[0]));
-  Value *Callee = getFnValueByID(Record[1], CalleeTy);
-  BasicBlock *NormalBB = getBasicBlock(Record[2]);
-  BasicBlock *UnwindBB = getBasicBlock(Record[3]);
+dyn_cast_or_null(getTypeByID(Record[1]));
+  Value *Callee = getFnValueByID(Record[2], CalleeTy);
+  BasicBlock *NormalBB = getBasicBlock(Record[3]);
+  BasicBlock *UnwindBB = getBasicBlock(Record[4]);
   if (CalleeTy == 0 || Callee == 0 || NormalBB == 0 || UnwindBB == 0)
 return Error("Invalid INVOKE record");
   
@@ -1251,17 +1252,17 @@
 dyn_cast(CalleeTy->getElementType());
 
   // Check that the right number of fixed parameters are here.
-  if (FTy == 0 || Record.size() < 4+FTy->getNumParams())
+  if (FTy == 0 || Record.size() < 5+FTy->getNumParams())
 return Error("Invalid INVOKE record");
 
   SmallVector Ops;
   for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
-Ops.push_back(getFnValueByID(Record[4+i], FTy->getParamType(4+i)));
+Ops.push_back(getFnValueByID(Record[5+i], FTy->getParamType(i)));
 if (Ops.back() == 0)
   return Error("Invalid INVOKE record");
   }
   
-  unsigned FirstVarargParam = 4+FTy->getNumParams();
+  unsigned FirstVarargParam = 5+FTy->getNumParams();
   if (FTy->isVarArg()) {
 // Read type/value pairs for varargs params.
 if ((Record.size()-FirstVarargParam) & 1)
@@ -1279,6 +1280,7 @@
   }
   
   I = new InvokeInst(Callee, NormalBB, UnwindBB, &Ops[0], Ops.size());
+  cast(I)->setCallingConv(CCInfo);
   break;
 }
 case bitc::FUNC_CODE_INST_UNWIND: // UNWIND
@@ -1360,27 +1362,28 @@
   I = new StoreInst(Op, Ptr, (1 << Record[3]) >> 1, Record[4]);
   break;
 }
-case bitc::FUNC_CODE_INST_CALL: { // CALL: [fnty, fnid, arg0, arg1...]
-  if (Record.size() < 2)
+case bitc::FUNC_CODE_INST_CALL: { // CALL: [cc, fnty, fnid, arg0, arg1...]
+  if (Record.size() < 3)
 return Error("Invalid CALL record");
+  unsigned CCInfo = Record[0];
   const PointerType *OpTy = 
-dyn_cast_or_null(getTypeByID(Record[0]));
+dyn_cast_or_null(getTypeByID(Record[1]));
   const FunctionType *FTy = 0;
   if (OpTy) FTy = dyn_cast(OpTy->getElementType());
-  Value *Callee = getFnValueByID(Record[1], OpTy);
-  if (!FTy || !Callee || Record.size() < FTy->getNumParams()+2)
+  Value *Callee = getFnValueByID(Record[2], OpTy);
+  if (!FTy || !Callee || Record.size() < FTy->getNumParams()+3)
 return Error("Invalid CALL record");
   
   SmallVector Args;
   // Read the fixed params.
   for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
-Args.push_back(getFnValueByID(Record[i+2], FTy->getParamType(i)));
+Args.push_back(getFnValueByID(Record[i+3], FTy->getParamType(i)));
 if (Args.back() == 0) return Error("Invalid CALL record");
   }
   
   
   // Read type/value pairs for varargs params.
-  unsigned NextArg = FTy->getNumParams()+2;
+  unsigned NextArg = FTy->getNumParams()+3;
   if (!FTy->isVarArg()) {
 if (NextArg != Record.size())
   return Error("Invalid CALL record");
@@ -1395,6 +1398,8 @@
   }
   
   I = new CallInst(Callee, &Args[0], Args.size());
+  cast(I)->setCallingConv(CCInfo>>1);
+  cast(I)->setTailCall(CCInfo & 1);
   break;
 }
 case bitc::FUNC_CODE_INST_VAARG: { // VAARG: [valistty, valist, instty]



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


Re: [llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Reid Spencer
On Thu, 3 May 2007 17:22:17 -0500
 Chris Lattner <[EMAIL PROTECTED]> wrote:
>
>
>Changes in directory llvm/lib/Bitcode/Reader:
>
>BitcodeReader.cpp updated: 1.28 -> 1.29
>---
>Log message:
>
>the type field for a store is the type of the pointer, not the value.
>
>With this fix I can round trip treeaadd, only losing calling conv info.

Nice. Sounds like you're getting close.

Reid.

>
>
>---
>Diffs of the changes:  (+4 -3)
>
> BitcodeReader.cpp |7 ---
> 1 files changed, 4 insertions(+), 3 deletions(-)
>
>
>Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
>diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.28 
>llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.29
>--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.28 Thu May  3 17:18:21 2007
>+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp  Thu May  3 17:21:59 2007
>@@ -1351,9 +1351,10 @@
> case bitc::FUNC_CODE_INST_STORE: { // STORE:[ptrty,val,ptr, align, vol]
>   if (Record.size() < 5)
> return Error("Invalid LOAD record");
>-  const Type *OpTy = getTypeByID(Record[0]);
>-  Value *Op = getFnValueByID(Record[1], OpTy);
>-  Value *Ptr = getFnValueByID(Record[2], PointerType::get(OpTy));
>+  const PointerType *OpTy = 
>+dyn_cast_or_null(getTypeByID(Record[0]));
>+  Value *Op = getFnValueByID(Record[1], OpTy ? OpTy->getElementType() : 
>0);
>+  Value *Ptr = getFnValueByID(Record[2], OpTy);
>   if (!OpTy || !Op || !Ptr)
> return Error("Invalid STORE record");
>   I = new StoreInst(Op, Ptr, (1 << Record[3]) >> 1, Record[4]);
>
>
>
>___
>llvm-commits mailing list
>llvm-commits@cs.uiuc.edu
>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.28 -> 1.29
---
Log message:

the type field for a store is the type of the pointer, not the value.

With this fix I can round trip treeaadd, only losing calling conv info.


---
Diffs of the changes:  (+4 -3)

 BitcodeReader.cpp |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.28 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.29
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.28  Thu May  3 17:18:21 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May  3 17:21:59 2007
@@ -1351,9 +1351,10 @@
 case bitc::FUNC_CODE_INST_STORE: { // STORE:[ptrty,val,ptr, align, vol]
   if (Record.size() < 5)
 return Error("Invalid LOAD record");
-  const Type *OpTy = getTypeByID(Record[0]);
-  Value *Op = getFnValueByID(Record[1], OpTy);
-  Value *Ptr = getFnValueByID(Record[2], PointerType::get(OpTy));
+  const PointerType *OpTy = 
+dyn_cast_or_null(getTypeByID(Record[0]));
+  Value *Op = getFnValueByID(Record[1], OpTy ? OpTy->getElementType() : 0);
+  Value *Ptr = getFnValueByID(Record[2], OpTy);
   if (!OpTy || !Op || !Ptr)
 return Error("Invalid STORE record");
   I = new StoreInst(Op, Ptr, (1 << Record[3]) >> 1, Record[4]);



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.27 -> 1.28
---
Log message:

fix encoding of BB names in the symtab


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

 BitcodeReader.cpp |   10 ++
 1 files changed, 10 insertions(+)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.27 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.28
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.27  Thu May  3 17:09:51 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May  3 17:18:21 2007
@@ -411,6 +411,16 @@
   V->setName(&ValueName[0], ValueName.size());
   ValueName.clear();
   break;
+case bitc::VST_CODE_BBENTRY:
+  if (ConvertToString(Record, 1, ValueName))
+return Error("Invalid VST_BBENTRY record");
+  BasicBlock *BB = getBasicBlock(Record[0]);
+  if (BB == 0)
+return Error("Invalid BB ID in VST_BBENTRY record");
+  
+  BB->setName(&ValueName[0], ValueName.size());
+  ValueName.clear();
+  break;
 }
   }
 }



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.26 -> 1.27
---
Log message:

bug fixes


---
Diffs of the changes:  (+3 -3)

 BitcodeReader.cpp |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.26 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.27
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.26  Thu May  3 17:04:19 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May  3 17:09:51 2007
@@ -400,7 +400,7 @@
 switch (Stream.ReadRecord(Code, Record)) {
 default:  // Default behavior: unknown type.
   break;
-case bitc::TST_CODE_ENTRY:// VST_ENTRY: [valueid, namelen, namechar x 
N]
+case bitc::VST_CODE_ENTRY:// VST_ENTRY: [valueid, namelen, namechar x 
N]
   if (ConvertToString(Record, 1, ValueName))
 return Error("Invalid TST_ENTRY record");
   unsigned ValueID = Record[0];
@@ -1054,7 +1054,7 @@
   if (Record.size() < 1 || Record[0] == 0)
 return Error("Invalid DECLAREBLOCKS record");
   // Create all the basic blocks for the function.
-  FunctionBBs.resize(Record.size());
+  FunctionBBs.resize(Record[0]);
   for (unsigned i = 0, e = FunctionBBs.size(); i != e; ++i)
 FunctionBBs[i] = new BasicBlock("", F);
   CurBB = FunctionBBs[0];
@@ -1185,7 +1185,7 @@
   }
   return Error("Invalid RET record");
 case bitc::FUNC_CODE_INST_BR: { // BR: [bb#, bb#, opval] or [bb#]
-  if (Record.size() != 1 || Record.size() != 3)
+  if (Record.size() != 1 && Record.size() != 3)
 return Error("Invalid BR record");
   BasicBlock *TrueDest = getBasicBlock(Record[0]);
   if (TrueDest == 0)



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.25 -> 1.26
---
Log message:

implement the rest of the instructions


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

 BitcodeReader.cpp |   78 +++---
 1 files changed, 68 insertions(+), 10 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.25 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.26
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.25  Thu May  3 13:58:09 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May  3 17:04:19 2007
@@ -1328,17 +1328,75 @@
   I = new AllocaInst(Ty->getElementType(), Size, (1 << Align) >> 1);
   break;
 }
-#if 0
-case bitc::FUNC_CODE_INST_LOAD:
-  // LOAD:   [opty, op, align, vol]
-case bitc::FUNC_CODE_INST_STORE:
-  // STORE:  [ptrty,val,ptr, align, vol]
-case bitc::FUNC_CODE_INST_CALL:
-  // CALL:   [fnty, fnid, arg0, arg1...]
-case bitc::FUNC_CODE_INST_VAARG:
-  // VAARG:  [valistty, valist, instty]
+case bitc::FUNC_CODE_INST_LOAD: { // LOAD: [opty, op, align, vol]
+  if (Record.size() < 4)
+return Error("Invalid LOAD record");
+  const Type *OpTy = getTypeByID(Record[0]);
+  Value *Op = getFnValueByID(Record[1], OpTy);
+  if (!OpTy || !Op)
+return Error("Invalid LOAD record");
+  I = new LoadInst(Op, "", Record[3], (1 << Record[2]) >> 1);
   break;
-#endif
+}
+case bitc::FUNC_CODE_INST_STORE: { // STORE:[ptrty,val,ptr, align, vol]
+  if (Record.size() < 5)
+return Error("Invalid LOAD record");
+  const Type *OpTy = getTypeByID(Record[0]);
+  Value *Op = getFnValueByID(Record[1], OpTy);
+  Value *Ptr = getFnValueByID(Record[2], PointerType::get(OpTy));
+  if (!OpTy || !Op || !Ptr)
+return Error("Invalid STORE record");
+  I = new StoreInst(Op, Ptr, (1 << Record[3]) >> 1, Record[4]);
+  break;
+}
+case bitc::FUNC_CODE_INST_CALL: { // CALL: [fnty, fnid, arg0, arg1...]
+  if (Record.size() < 2)
+return Error("Invalid CALL record");
+  const PointerType *OpTy = 
+dyn_cast_or_null(getTypeByID(Record[0]));
+  const FunctionType *FTy = 0;
+  if (OpTy) FTy = dyn_cast(OpTy->getElementType());
+  Value *Callee = getFnValueByID(Record[1], OpTy);
+  if (!FTy || !Callee || Record.size() < FTy->getNumParams()+2)
+return Error("Invalid CALL record");
+  
+  SmallVector Args;
+  // Read the fixed params.
+  for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
+Args.push_back(getFnValueByID(Record[i+2], FTy->getParamType(i)));
+if (Args.back() == 0) return Error("Invalid CALL record");
+  }
+  
+  
+  // Read type/value pairs for varargs params.
+  unsigned NextArg = FTy->getNumParams()+2;
+  if (!FTy->isVarArg()) {
+if (NextArg != Record.size())
+  return Error("Invalid CALL record");
+  } else {
+if ((Record.size()-NextArg) & 1)
+  return Error("Invalid CALL record");
+for (unsigned e = Record.size(); NextArg != e; NextArg += 2) {
+  Args.push_back(getFnValueByID(Record[NextArg+1], 
+getTypeByID(Record[NextArg])));
+  if (Args.back() == 0) return Error("Invalid CALL record");
+}
+  }
+  
+  I = new CallInst(Callee, &Args[0], Args.size());
+  break;
+}
+case bitc::FUNC_CODE_INST_VAARG: { // VAARG: [valistty, valist, instty]
+  if (Record.size() < 3)
+return Error("Invalid VAARG record");
+  const Type *OpTy = getTypeByID(Record[0]);
+  Value *Op = getFnValueByID(Record[1], OpTy);
+  const Type *ResTy = getTypeByID(Record[2]);
+  if (!OpTy || !Op || !ResTy)
+return Error("Invalid VAARG record");
+  I = new VAArgInst(Op, ResTy);
+  break;
+}
 }
 
 // Add instruction to end of current BB.  If there is no current BB, reject



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-03 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.24 -> 1.25
---
Log message:

add a few more instructions, getting close



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

 BitcodeReader.cpp |   63 +-
 1 files changed, 53 insertions(+), 10 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.24 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.25
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.24  Wed May  2 00:46:45 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Thu May  3 13:58:09 2007
@@ -1178,7 +1178,8 @@
   if (Record.size() == 2) {
 const Type *OpTy = getTypeByID(Record[0]);
 Value *Op = getFnValueByID(Record[1], OpTy);
-if (OpTy && Op);
+if (!OpTy || !Op)
+  return Error("Invalid RET record");
 I = new ReturnInst(Op);
 break;
   }
@@ -1276,16 +1277,58 @@
 case bitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE
   I = new UnreachableInst();
   break;
+case bitc::FUNC_CODE_INST_PHI: { // PHI: [ty, #ops, val0,bb0, ...]
+  if (Record.size() < 2 || Record.size() < 2+Record[1] || (Record[1]&1))
+return Error("Invalid PHI record");
+  const Type *Ty = getTypeByID(Record[0]);
+  if (!Ty) return Error("Invalid PHI record");
+  
+  PHINode *PN = new PHINode(Ty);
+  PN->reserveOperandSpace(Record[1]);
+  
+  for (unsigned i = 0, e = Record[1]; i != e; i += 2) {
+Value *V = getFnValueByID(Record[2+i], Ty);
+BasicBlock *BB = getBasicBlock(Record[3+i]);
+if (!V || !BB) return Error("Invalid PHI record");
+PN->addIncoming(V, BB);
+  }
+  I = PN;
+  break;
+}
+  
+case bitc::FUNC_CODE_INST_MALLOC: { // MALLOC: [instty, op, align]
+  if (Record.size() < 3)
+return Error("Invalid MALLOC record");
+  const PointerType *Ty =
+dyn_cast_or_null(getTypeByID(Record[0]));
+  Value *Size = getFnValueByID(Record[1], Type::Int32Ty);
+  unsigned Align = Record[2];
+  if (!Ty || !Size) return Error("Invalid MALLOC record");
+  I = new MallocInst(Ty->getElementType(), Size, (1 << Align) >> 1);
+  break;
+}
+case bitc::FUNC_CODE_INST_FREE: { // FREE: [opty, op]
+  if (Record.size() < 2)
+return Error("Invalid FREE record");
+  const Type *OpTy = getTypeByID(Record[0]);
+  Value *Op = getFnValueByID(Record[1], OpTy);
+  if (!OpTy || !Op)
+return Error("Invalid FREE record");
+  I = new FreeInst(Op);
+  break;
+}
+case bitc::FUNC_CODE_INST_ALLOCA: { // ALLOCA: [instty, op, align]
+  if (Record.size() < 3)
+return Error("Invalid ALLOCA record");
+  const PointerType *Ty =
+dyn_cast_or_null(getTypeByID(Record[0]));
+  Value *Size = getFnValueByID(Record[1], Type::Int32Ty);
+  unsigned Align = Record[2];
+  if (!Ty || !Size) return Error("Invalid ALLOCA record");
+  I = new AllocaInst(Ty->getElementType(), Size, (1 << Align) >> 1);
+  break;
+}
 #if 0
-
-case bitc::FUNC_CODE_INST_PHI:
-  // PHI:[ty, #ops, val0,bb0, ...]
-case bitc::FUNC_CODE_INST_MALLOC:
-  // MALLOC: [instty, op, align]
-case bitc::FUNC_CODE_INST_FREE:
-  // FREE:   [opty, op]
-case bitc::FUNC_CODE_INST_ALLOCA:
-  // ALLOCA: [instty, op, align]
 case bitc::FUNC_CODE_INST_LOAD:
   // LOAD:   [opty, op, align, vol]
 case bitc::FUNC_CODE_INST_STORE:



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-05-01 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.23 -> 1.24
BitcodeReader.h updated: 1.15 -> 1.16
---
Log message:

add reader logic for terminator instrs.


---
Diffs of the changes:  (+93 -8)

 BitcodeReader.cpp |   97 +-
 BitcodeReader.h   |4 ++
 2 files changed, 93 insertions(+), 8 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.23 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.24
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.23  Wed May  2 00:16:49 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Wed May  2 00:46:45 2007
@@ -1090,7 +1090,7 @@
   if (OpTy == 0 || Op == 0)
 return Error("Invalid GEP record");
 
-  SmallVector GEPIdx;
+  SmallVector GEPIdx;
   for (unsigned i = 1, e = Record.size()/2; i != e; ++i) {
 const Type *IdxTy = getTypeByID(Record[i*2]);
 Value *Idx = getFnValueByID(Record[i*2+1], IdxTy);
@@ -1183,19 +1183,100 @@
 break;
   }
   return Error("Invalid RET record");
-#if 0
-case bitc::FUNC_CODE_INST_BR:
-  // BR: [opval, bb#, bb#] or [bb#]
-case bitc::FUNC_CODE_INST_SWITCH:
-  // SWITCH: [opty, opval, n, n x ops]
-case bitc::FUNC_CODE_INST_INVOKE:
-  // INVOKE: [fnty, op0,op1,op2, ...]
+case bitc::FUNC_CODE_INST_BR: { // BR: [bb#, bb#, opval] or [bb#]
+  if (Record.size() != 1 || Record.size() != 3)
+return Error("Invalid BR record");
+  BasicBlock *TrueDest = getBasicBlock(Record[0]);
+  if (TrueDest == 0)
+return Error("Invalid BR record");
+
+  if (Record.size() == 1)
+I = new BranchInst(TrueDest);
+  else {
+BasicBlock *FalseDest = getBasicBlock(Record[1]);
+Value *Cond = getFnValueByID(Record[2], Type::Int1Ty);
+if (FalseDest == 0 || Cond == 0)
+  return Error("Invalid BR record");
+I = new BranchInst(TrueDest, FalseDest, Cond);
+  }
+  break;
+}
+case bitc::FUNC_CODE_INST_SWITCH: { // SWITCH: [opty, opval, n, n x ops]
+  if (Record.size() < 3 || (Record.size() & 1) == 0)
+return Error("Invalid SWITCH record");
+  const Type *OpTy = getTypeByID(Record[0]);
+  Value *Cond = getFnValueByID(Record[1], OpTy);
+  BasicBlock *Default = getBasicBlock(Record[2]);
+  if (OpTy == 0 || Cond == 0 || Default == 0)
+return Error("Invalid SWITCH record");
+  unsigned NumCases = (Record.size()-3)/2;
+  SwitchInst *SI = new SwitchInst(Cond, Default, NumCases);
+  for (unsigned i = 0, e = NumCases; i != e; ++i) {
+ConstantInt *CaseVal = 
+  dyn_cast_or_null(getFnValueByID(Record[3+i*2], OpTy));
+BasicBlock *DestBB = getBasicBlock(Record[1+3+i*2]);
+if (CaseVal == 0 || DestBB == 0) {
+  delete SI;
+  return Error("Invalid SWITCH record!");
+}
+SI->addCase(CaseVal, DestBB);
+  }
+  I = SI;
+  break;
+}
+  
+case bitc::FUNC_CODE_INST_INVOKE: { // INVOKE: [fnty, op0,op1,op2, ...]
+  if (Record.size() < 4)
+return Error("Invalid INVOKE record");
+  const PointerType *CalleeTy =
+dyn_cast_or_null(getTypeByID(Record[0]));
+  Value *Callee = getFnValueByID(Record[1], CalleeTy);
+  BasicBlock *NormalBB = getBasicBlock(Record[2]);
+  BasicBlock *UnwindBB = getBasicBlock(Record[3]);
+  if (CalleeTy == 0 || Callee == 0 || NormalBB == 0 || UnwindBB == 0)
+return Error("Invalid INVOKE record");
+  
+  const FunctionType *FTy =
+dyn_cast(CalleeTy->getElementType());
+
+  // Check that the right number of fixed parameters are here.
+  if (FTy == 0 || Record.size() < 4+FTy->getNumParams())
+return Error("Invalid INVOKE record");
+
+  SmallVector Ops;
+  for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
+Ops.push_back(getFnValueByID(Record[4+i], FTy->getParamType(4+i)));
+if (Ops.back() == 0)
+  return Error("Invalid INVOKE record");
+  }
+  
+  unsigned FirstVarargParam = 4+FTy->getNumParams();
+  if (FTy->isVarArg()) {
+// Read type/value pairs for varargs params.
+if ((Record.size()-FirstVarargParam) & 1)
+  return Error("Invalid INVOKE record");
+
+for (unsigned i = FirstVarargParam, e = Record.size(); i != e; i += 2) 
{
+  const Type *ArgTy = getTypeByID(Record[i]);
+  Ops.push_back(getFnValueByID(Record[i+1], ArgTy));
+  if (Ops.back() == 0 || ArgTy == 0)
+return Error("Invalid INVOKE record");
+}
+  } else {
+if (Record.size() != FirstVarargParam)
+  return Error("Invalid INVOKE record");
+  }
+  
+  I = new InvokeInst(Callee, NormalBB, UnwindBB, &Ops[0], Ops.size());
+  break;
+}
 case bitc::FUNC_CODE_INST_UNWIND: // UNWIND
   I = new UnwindInst();
  

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-01 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.22 -> 1.23
---
Log message:

add reader support for a bunch of new instructions


---
Diffs of the changes:  (+90 -14)

 BitcodeReader.cpp |  104 ++
 1 files changed, 90 insertions(+), 14 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.22 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.23
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.22  Tue May  1 23:27:25 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Wed May  2 00:16:49 2007
@@ -150,6 +150,9 @@
 return V;
   }
   
+  // No type specified, must be invalid reference.
+  if (Ty == 0) return 0;
+  
   // Create and return a placeholder, which will later be RAUW'd.
   Value *V = new Argument(Ty);
   Uses[Idx].init(V, this);
@@ -1079,21 +1082,94 @@
   I = CastInst::create((Instruction::CastOps)Opc, Op, ResTy);
   break;
 }
-#if 0
-case bitc::FUNC_CODE_INST_GEP:
-  // GEP:[n, n x operands]
-case bitc::FUNC_CODE_INST_SELECT:
-  // SELECT: [ty, opval, opval, opval]
-case bitc::FUNC_CODE_INST_EXTRACTELT:
-  // EXTRACTELT: [opty, opval, opval]
-case bitc::FUNC_CODE_INST_INSERTELT:
-  // INSERTELT:  [ty, opval, opval, opval]
-case bitc::FUNC_CODE_INST_SHUFFLEVEC:
-  // SHUFFLEVEC: [ty, opval, opval, opval]
-case bitc::FUNC_CODE_INST_CMP:
-  // CMP:[opty, opval, opval, pred]
-#endif
+case bitc::FUNC_CODE_INST_GEP: { // GEP: [n, n x operands]
+  if (Record.size() < 2 || (Record.size() & 1))
+return Error("Invalid GEP record");
+  const Type *OpTy = getTypeByID(Record[0]);
+  Value *Op = getFnValueByID(Record[1], OpTy);
+  if (OpTy == 0 || Op == 0)
+return Error("Invalid GEP record");
+
+  SmallVector GEPIdx;
+  for (unsigned i = 1, e = Record.size()/2; i != e; ++i) {
+const Type *IdxTy = getTypeByID(Record[i*2]);
+Value *Idx = getFnValueByID(Record[i*2+1], IdxTy);
+if (IdxTy == 0 || Idx == 0)
+  return Error("Invalid GEP record");
+GEPIdx.push_back(Idx);
+  }
+
+  I = new GetElementPtrInst(Op, &GEPIdx[0], GEPIdx.size());
+  break;
+}
   
+case bitc::FUNC_CODE_INST_SELECT: { // SELECT: [ty, opval, opval, opval]
+  if (Record.size() < 4) return Error("Invalid SELECT record");
+  const Type *Ty = getTypeByID(Record[0]);
+  Value *Cond = getFnValueByID(Record[1], Type::Int1Ty);
+  Value *LHS = getFnValueByID(Record[2], Ty);
+  Value *RHS = getFnValueByID(Record[3], Ty);
+  if (Ty == 0 || Cond == 0 || LHS == 0 || RHS == 0)
+return Error("Invalid SELECT record");
+  I = new SelectInst(Cond, LHS, RHS);
+  break;
+}
+  
+case bitc::FUNC_CODE_INST_EXTRACTELT: { // EXTRACTELT: [opty, opval, opval]
+  if (Record.size() < 3) return Error("Invalid EXTRACTELT record");
+  const Type *OpTy = getTypeByID(Record[0]);
+  Value *Vec = getFnValueByID(Record[1], OpTy);
+  Value *Idx = getFnValueByID(Record[2], Type::Int32Ty);
+  if (OpTy == 0 || Vec == 0 || Idx == 0)
+return Error("Invalid EXTRACTELT record");
+  I = new ExtractElementInst(Vec, Idx);
+  break;
+}
+  
+case bitc::FUNC_CODE_INST_INSERTELT: { // INSERTELT: [ty, 
opval,opval,opval]
+  if (Record.size() < 4) return Error("Invalid INSERTELT record");
+  const VectorType *OpTy = 
+dyn_cast_or_null(getTypeByID(Record[0]));
+  if (OpTy == 0) return Error("Invalid INSERTELT record");
+  Value *Vec = getFnValueByID(Record[1], OpTy);
+  Value *Elt = getFnValueByID(Record[2], OpTy->getElementType());
+  Value *Idx = getFnValueByID(Record[3], Type::Int32Ty);
+  if (Vec == 0 || Elt == 0 || Idx == 0)
+return Error("Invalid INSERTELT record");
+  I = new InsertElementInst(Vec, Elt, Idx);
+  break;
+}
+  
+case bitc::FUNC_CODE_INST_SHUFFLEVEC: {// SHUFFLEVEC: 
[ty,opval,opval,opval]
+  if (Record.size() < 4) return Error("Invalid SHUFFLEVEC record");
+  const VectorType *OpTy = 
+dyn_cast_or_null(getTypeByID(Record[0]));
+  if (OpTy == 0) return Error("Invalid SHUFFLEVEC record");
+  Value *Vec1 = getFnValueByID(Record[1], OpTy);
+  Value *Vec2 = getFnValueByID(Record[2], OpTy);
+  Value *Mask = getFnValueByID(Record[3],
+   VectorType::get(Type::Int32Ty,
+   OpTy->getNumElements()));
+  if (Vec1 == 0 || Vec2 == 0 || Mask == 0)
+return Error("Invalid SHUFFLEVEC record");
+  I = new ShuffleVectorInst(Vec1, Vec2, Mask);
+  break;
+}
+  
+case bitc::FUNC_CODE_INST_CMP: { // CMP: [opty, opval, opval, pred]
+  if (Record.size() < 4) return Error("Invalid CMP record");
+  const Type *OpTy = getTypeByID(Record[0]);
+  Value *LHS = getFnValu

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-05-01 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.21 -> 1.22
---
Log message:

read a few instructions, fix some bugs.  This is enough to be able to round
trip function bodies like this:

define <2 x i64> @foo(<2 x i64> %x, <2 x i64> %y) {
%tmp4 = bitcast <2 x i64> %y to <8 x i16>   ; <<8 x i16>> 
[#uses=1]
%tmp5 = bitcast <2 x i64> %x to <8 x i16>   ; <<8 x i16>> 
[#uses=1]
%tmp = add <8 x i16> %tmp5, %tmp4   ; <<8 x i16>> [#uses=1]
%tmp6 = bitcast <8 x i16> %tmp to <2 x i64> ; <<2 x i64>> 
[#uses=1]
ret <2 x i64> %tmp6
}



---
Diffs of the changes:  (+38 -15)

 BitcodeReader.cpp |   53 ++---
 1 files changed, 38 insertions(+), 15 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.21 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.22
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.21  Tue May  1 02:01:57 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Tue May  1 23:27:25 2007
@@ -1006,7 +1006,9 @@
 ValueList.push_back(I);
   
   unsigned NextValueNo = ValueList.size();
-  
+  BasicBlock *CurBB = 0;
+  unsigned CurBBNo = 0;
+
   // Read all the records.
   SmallVector Record;
   while (1) {
@@ -1042,8 +1044,6 @@
 // Read a record.
 Record.clear();
 Instruction *I = 0;
-BasicBlock *CurBB = 0;
-unsigned CurBBNo = 0;
 switch (Stream.ReadRecord(Code, Record)) {
 default: // Default behavior: reject
   return Error("Unknown instruction");
@@ -1057,8 +1057,7 @@
   CurBB = FunctionBBs[0];
   continue;
   
-case bitc::FUNC_CODE_INST_BINOP: {
-  // BINOP:  [opcode, ty, opval, opval]
+case bitc::FUNC_CODE_INST_BINOP: {// BINOP: [opcode, ty, opval, opval]
   if (Record.size() < 4) return Error("Invalid BINOP record");
   const Type *Ty = getTypeByID(Record[1]);
   int Opc = GetDecodedBinaryOpcode(Record[0], Ty);
@@ -1069,9 +1068,18 @@
   I = BinaryOperator::create((Instruction::BinaryOps)Opc, LHS, RHS);
   break;
 }
+case bitc::FUNC_CODE_INST_CAST: {// CAST: [opcode, ty, opty, opval]
+  if (Record.size() < 4) return Error("Invalid CAST record");
+  int Opc = GetDecodedCastOpcode(Record[0]);
+  const Type *ResTy = getTypeByID(Record[1]);
+  const Type *OpTy = getTypeByID(Record[2]);
+  Value *Op = getFnValueByID(Record[3], OpTy);
+  if (Opc == -1 || ResTy == 0 || OpTy == 0 || Op == 0)
+return Error("Invalid CAST record");
+  I = CastInst::create((Instruction::CastOps)Opc, Op, ResTy);
+  break;
+}
 #if 0
-case bitc::FUNC_CODE_INST_CAST:
-  // CAST:   [opcode, ty, opty, opval]
 case bitc::FUNC_CODE_INST_GEP:
   // GEP:[n, n x operands]
 case bitc::FUNC_CODE_INST_SELECT:
@@ -1084,20 +1092,35 @@
   // SHUFFLEVEC: [ty, opval, opval, opval]
 case bitc::FUNC_CODE_INST_CMP:
   // CMP:[opty, opval, opval, pred]
-
-case bitc::FUNC_CODE_INST_RET:
-  // RET:[opty,opval]
+#endif
+  
+case bitc::FUNC_CODE_INST_RET: // RET: [opty,opval]
+  if (Record.size() == 0) {
+I = new ReturnInst();
+break;
+  }
+  if (Record.size() == 2) {
+const Type *OpTy = getTypeByID(Record[0]);
+Value *Op = getFnValueByID(Record[1], OpTy);
+if (OpTy && Op);
+I = new ReturnInst(Op);
+break;
+  }
+  return Error("Invalid RET record");
+#if 0
 case bitc::FUNC_CODE_INST_BR:
   // BR: [opval, bb#, bb#] or [bb#]
 case bitc::FUNC_CODE_INST_SWITCH:
   // SWITCH: [opty, opval, n, n x ops]
 case bitc::FUNC_CODE_INST_INVOKE:
   // INVOKE: [fnty, op0,op1,op2, ...]
-case bitc::FUNC_CODE_INST_UNWIND:
-  // UNWIND
-case bitc::FUNC_CODE_INST_UNREACHABLE:
-  // UNREACHABLE
-
+case bitc::FUNC_CODE_INST_UNWIND: // UNWIND
+  I = new UnwindInst();
+  break;
+case bitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE
+  I = new UnreachableInst();
+  break;
+
 case bitc::FUNC_CODE_INST_PHI:
   // PHI:[ty, #ops, val0,bb0, ...]
 case bitc::FUNC_CODE_INST_MALLOC:



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-05-01 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.20 -> 1.21
BitcodeReader.h updated: 1.14 -> 1.15
---
Log message:

handle function-level forward references, read binops.


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

 BitcodeReader.cpp |  150 ++
 BitcodeReader.h   |   19 ++
 2 files changed, 147 insertions(+), 22 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.20 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.21
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.20  Tue May  1 00:52:21 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Tue May  1 02:01:57 2007
@@ -15,6 +15,7 @@
 #include "BitcodeReader.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/MathExtras.h"
@@ -125,10 +126,9 @@
 NumOperands = Idx+1;
   }
 
-  if (Uses[Idx]) {
-assert(Ty == getOperand(Idx)->getType() &&
-   "Type mismatch in constant table!");
-return cast(getOperand(Idx));
+  if (Value *V = Uses[Idx]) {
+assert(Ty == V->getType() && "Type mismatch in constant table!");
+return cast(V);
   }
 
   // Create and return a placeholder, which will later be RAUW'd.
@@ -137,6 +137,25 @@
   return C;
 }
 
+Value *BitcodeReaderValueList::getValueFwdRef(unsigned Idx, const Type *Ty) {
+  if (Idx >= size()) {
+// Insert a bunch of null values.
+Uses.resize(Idx+1);
+OperandList = &Uses[0];
+NumOperands = Idx+1;
+  }
+  
+  if (Value *V = Uses[Idx]) {
+assert((Ty == 0 || Ty == V->getType()) && "Type mismatch in value table!");
+return V;
+  }
+  
+  // Create and return a placeholder, which will later be RAUW'd.
+  Value *V = new Argument(Ty);
+  Uses[Idx].init(V, this);
+  return V;
+}
+
 
 const Type *BitcodeReader::getTypeByID(unsigned ID, bool isTypeTable) {
   // If the TypeID is in range, return it.
@@ -151,7 +170,6 @@
   return TypeList.back().get();
 }
 
-
 bool BitcodeReader::ParseTypeTable() {
   if (Stream.EnterSubBlock())
 return Error("Malformed block record");
@@ -643,18 +661,7 @@
 }
 }
 
-if (NextCstNo == ValueList.size())
-  ValueList.push_back(V);
-else if (ValueList[NextCstNo] == 0)
-  ValueList.initVal(NextCstNo, V);
-else {
-  // If there was a forward reference to this constant, 
-  Value *OldV = ValueList[NextCstNo];
-  ValueList.setOperand(NextCstNo, V);
-  OldV->replaceAllUsesWith(V);
-  delete OldV;
-}
-
+ValueList.AssignValue(V, NextCstNo);
 ++NextCstNo;
   }
 }
@@ -998,6 +1005,8 @@
   for(Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I)
 ValueList.push_back(I);
   
+  unsigned NextValueNo = ValueList.size();
+  
   // Read all the records.
   SmallVector Record;
   while (1) {
@@ -1016,6 +1025,7 @@
 break;
   case bitc::CONSTANTS_BLOCK_ID:
 if (ParseConstants()) return true;
+NextValueNo = ValueList.size();
 break;
   case bitc::VALUE_SYMTAB_BLOCK_ID:
 if (ParseValueSymbolTable()) return true;
@@ -1031,19 +1041,115 @@
 
 // Read a record.
 Record.clear();
+Instruction *I = 0;
+BasicBlock *CurBB = 0;
+unsigned CurBBNo = 0;
 switch (Stream.ReadRecord(Code, Record)) {
-default:  // Default behavior: unknown constant
+default: // Default behavior: reject
+  return Error("Unknown instruction");
 case bitc::FUNC_CODE_DECLAREBLOCKS: // DECLAREBLOCKS: [nblocks]
-  if (Record.size() < 1)
-return Error("Invalid FUNC_CODE_DECLAREBLOCKS record");
+  if (Record.size() < 1 || Record[0] == 0)
+return Error("Invalid DECLAREBLOCKS record");
   // Create all the basic blocks for the function.
   FunctionBBs.resize(Record.size());
   for (unsigned i = 0, e = FunctionBBs.size(); i != e; ++i)
 FunctionBBs[i] = new BasicBlock("", F);
-  break;
-}
+  CurBB = FunctionBBs[0];
+  continue;
+  
+case bitc::FUNC_CODE_INST_BINOP: {
+  // BINOP:  [opcode, ty, opval, opval]
+  if (Record.size() < 4) return Error("Invalid BINOP record");
+  const Type *Ty = getTypeByID(Record[1]);
+  int Opc = GetDecodedBinaryOpcode(Record[0], Ty);
+  Value *LHS = getFnValueByID(Record[2], Ty);
+  Value *RHS = getFnValueByID(Record[3], Ty);
+  if (Opc == -1 || Ty == 0 || LHS == 0 || RHS == 0)
+ return Error("Invalid BINOP record");
+  I = BinaryOperator::create((Instruction::BinaryOps)Opc, LHS, RHS);
+  break;
+}
+#if 0
+case bitc::FUNC_CODE_INST_CAST:
+  // CAST:   [opcode, ty, opty, opval]
+case bitc::FUNC_CODE_INST_GEP:
+  // GEP:[n, n x operands]
+case bitc::FUNC_CODE_INST_SELECT:
+  // SELECT: [ty, opval, opval, opval]
+case bitc::FUNC_CODE_INST_EXTRACTELT:
+  // EXTRACTELT: [op

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-04-30 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.19 -> 1.20
BitcodeReader.h updated: 1.13 -> 1.14
---
Log message:

implement materializeModule, force deallocation of vector memory when we 
are done with them, start implementing ParseFunctionBody



---
Diffs of the changes:  (+107 -15)

 BitcodeReader.cpp |  105 ++
 BitcodeReader.h   |   17 
 2 files changed, 107 insertions(+), 15 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.19 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.20
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.19  Tue May  1 00:01:34 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Tue May  1 00:52:21 2007
@@ -659,9 +659,10 @@
   }
 }
 
-/// ParseFunction - When we see the block for a function body, remember where 
it
-/// is and then skip it.  This lets us lazily deserialize the functions.
-bool BitcodeReader::ParseFunction() {
+/// RememberAndSkipFunctionBody - When we see the block for a function body,
+/// remember where it is and then skip it.  This lets us lazily deserialize the
+/// functions.
+bool BitcodeReader::RememberAndSkipFunctionBody() {
   // Get the function we are talking about.
   if (FunctionsWithBodies.empty())
 return Error("Insufficient function protos");
@@ -701,13 +702,21 @@
   while (!Stream.AtEndOfStream()) {
 unsigned Code = Stream.ReadCode();
 if (Code == bitc::END_BLOCK) {
+  if (Stream.ReadBlockEnd())
+return Error("Error at end of module block");
+
+  // Patch the initializers for globals and aliases up.
   ResolveGlobalAndAliasInits();
   if (!GlobalInits.empty() || !AliasInits.empty())
 return Error("Malformed global initializer set");
   if (!FunctionsWithBodies.empty())
 return Error("Too few function bodies found");
-  if (Stream.ReadBlockEnd())
-return Error("Error at end of module block");
+
+  // Force deallocation of memory for these vectors to favor the client 
that
+  // want lazy deserialization.
+  std::vector >().swap(GlobalInits);
+  std::vector >().swap(AliasInits);
+  std::vector().swap(FunctionsWithBodies);
   return false;
 }
 
@@ -741,7 +750,7 @@
   HasReversedFunctionsWithBodies = true;
 }
 
-if (ParseFunction())
+if (RememberAndSkipFunctionBody())
   return true;
 break;
   }
@@ -956,6 +965,90 @@
   F->setLinkage((GlobalValue::LinkageTypes)DFII->second.second);
   DeferredFunctionInfo.erase(DFII);
   
+  if (ParseFunctionBody(F)) {
+if (ErrInfo) *ErrInfo = ErrorString;
+return true;
+  }
+  
+  return false;
+}
+
+Module *BitcodeReader::materializeModule(std::string *ErrInfo) {
+  DenseMap >::iterator I = 
+DeferredFunctionInfo.begin();
+  while (!DeferredFunctionInfo.empty()) {
+Function *F = (*I++).first;
+assert(F->hasNotBeenReadFromBytecode() &&
+   "Deserialized function found in map!");
+if (materializeFunction(F, ErrInfo))
+  return 0;
+  }
+  return TheModule;
+}
+
+
+/// ParseFunctionBody - Lazily parse the specified function body block.
+bool BitcodeReader::ParseFunctionBody(Function *F) {
+  if (Stream.EnterSubBlock())
+return Error("Malformed block record");
+  
+  unsigned ModuleValueListSize = ValueList.size();
+  
+  // Add all the function arguments to the value table.
+  for(Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I)
+ValueList.push_back(I);
+  
+  // Read all the records.
+  SmallVector Record;
+  while (1) {
+unsigned Code = Stream.ReadCode();
+if (Code == bitc::END_BLOCK) {
+  if (Stream.ReadBlockEnd())
+return Error("Error at end of function block");
+  break;
+}
+
+if (Code == bitc::ENTER_SUBBLOCK) {
+  switch (Stream.ReadSubBlockID()) {
+  default:  // Skip unknown content.
+if (Stream.SkipBlock())
+  return Error("Malformed block record");
+break;
+  case bitc::CONSTANTS_BLOCK_ID:
+if (ParseConstants()) return true;
+break;
+  case bitc::VALUE_SYMTAB_BLOCK_ID:
+if (ParseValueSymbolTable()) return true;
+break;
+  }
+  continue;
+}
+
+if (Code == bitc::DEFINE_ABBREV) {
+  Stream.ReadAbbrevRecord();
+  continue;
+}
+
+// Read a record.
+Record.clear();
+switch (Stream.ReadRecord(Code, Record)) {
+default:  // Default behavior: unknown constant
+case bitc::FUNC_CODE_DECLAREBLOCKS: // DECLAREBLOCKS: [nblocks]
+  if (Record.size() < 1)
+return Error("Invalid FUNC_CODE_DECLAREBLOCKS record");
+  // Create all the basic blocks for the function.
+  FunctionBBs.resize(Record.size());
+  for (unsigned i = 0, e = FunctionBBs.size(); i != e; ++i)
+FunctionBBs[i] = new BasicBlock("", F);
+  break;
+}
+  }
+  
+  
+  // Trim the va

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-04-30 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.18 -> 1.19
BitcodeReader.h updated: 1.12 -> 1.13
---
Log message:

The stream to read from is now an ivar


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

 BitcodeReader.cpp |   25 -
 BitcodeReader.h   |   13 ++---
 2 files changed, 18 insertions(+), 20 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.18 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.19
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.18  Mon Apr 30 23:59:48 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Tue May  1 00:01:34 2007
@@ -152,7 +152,7 @@
 }
 
 
-bool BitcodeReader::ParseTypeTable(BitstreamReader &Stream) {
+bool BitcodeReader::ParseTypeTable() {
   if (Stream.EnterSubBlock())
 return Error("Malformed block record");
   
@@ -298,7 +298,7 @@
 }
 
 
-bool BitcodeReader::ParseTypeSymbolTable(BitstreamReader &Stream) {
+bool BitcodeReader::ParseTypeSymbolTable() {
   if (Stream.EnterSubBlock())
 return Error("Malformed block record");
   
@@ -346,7 +346,7 @@
   }
 }
 
-bool BitcodeReader::ParseValueSymbolTable(BitstreamReader &Stream) {
+bool BitcodeReader::ParseValueSymbolTable() {
   if (Stream.EnterSubBlock())
 return Error("Malformed block record");
 
@@ -444,7 +444,7 @@
 }
 
 
-bool BitcodeReader::ParseConstants(BitstreamReader &Stream) {
+bool BitcodeReader::ParseConstants() {
   if (Stream.EnterSubBlock())
 return Error("Malformed block record");
 
@@ -661,7 +661,7 @@
 
 /// ParseFunction - When we see the block for a function body, remember where 
it
 /// is and then skip it.  This lets us lazily deserialize the functions.
-bool BitcodeReader::ParseFunction(BitstreamReader &Stream) {
+bool BitcodeReader::ParseFunction() {
   // Get the function we are talking about.
   if (FunctionsWithBodies.empty())
 return Error("Insufficient function protos");
@@ -683,8 +683,7 @@
   return false;
 }
 
-bool BitcodeReader::ParseModule(BitstreamReader &Stream,
-const std::string &ModuleID) {
+bool BitcodeReader::ParseModule(const std::string &ModuleID) {
   // Reject multiple MODULE_BLOCK's in a single bitstream.
   if (TheModule)
 return Error("Multiple MODULE_BLOCKs in same stream");
@@ -719,19 +718,19 @@
   return Error("Malformed block record");
 break;
   case bitc::TYPE_BLOCK_ID:
-if (ParseTypeTable(Stream))
+if (ParseTypeTable())
   return true;
 break;
   case bitc::TYPE_SYMTAB_BLOCK_ID:
-if (ParseTypeSymbolTable(Stream))
+if (ParseTypeSymbolTable())
   return true;
 break;
   case bitc::VALUE_SYMTAB_BLOCK_ID:
-if (ParseValueSymbolTable(Stream))
+if (ParseValueSymbolTable())
   return true;
 break;
   case bitc::CONSTANTS_BLOCK_ID:
-if (ParseConstants(Stream) || ResolveGlobalAndAliasInits())
+if (ParseConstants() || ResolveGlobalAndAliasInits())
   return true;
 break;
   case bitc::FUNCTION_BLOCK_ID:
@@ -742,7 +741,7 @@
   HasReversedFunctionsWithBodies = true;
 }
 
-if (ParseFunction(Stream))
+if (ParseFunction())
   return true;
 break;
   }
@@ -932,7 +931,7 @@
 
 // We only know the MODULE subblock ID.
 if (BlockID == bitc::MODULE_BLOCK_ID) {
-  if (ParseModule(Stream, Buffer->getBufferIdentifier()))
+  if (ParseModule(Buffer->getBufferIdentifier()))
 return true;
 } else if (Stream.SkipBlock()) {
   return Error("Malformed block record");


Index: llvm/lib/Bitcode/Reader/BitcodeReader.h
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.h:1.12 
llvm/lib/Bitcode/Reader/BitcodeReader.h:1.13
--- llvm/lib/Bitcode/Reader/BitcodeReader.h:1.12Mon Apr 30 23:59:48 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.h Tue May  1 00:01:34 2007
@@ -23,7 +23,6 @@
 #include 
 
 namespace llvm {
-  class BitstreamReader;
   class MemoryBuffer;
   
 class BitcodeReaderValueList : public User {
@@ -117,12 +116,12 @@
 private:
   const Type *getTypeByID(unsigned ID, bool isTypeTable = false);
   
-  bool ParseModule(BitstreamReader &Stream, const std::string &ModuleID);
-  bool ParseTypeTable(BitstreamReader &Stream);
-  bool ParseTypeSymbolTable(BitstreamReader &Stream);
-  bool ParseValueSymbolTable(BitstreamReader &Stream);
-  bool ParseConstants(BitstreamReader &Stream);
-  bool ParseFunction(BitstreamReader &Stream);
+  bool ParseModule(const std::string &ModuleID);
+  bool ParseTypeTable();
+  bool ParseTypeSymbolTable();
+  bool ParseValueSymbolTable();
+  bool ParseConstants();
+  bool ParseFunction();
   bool ResolveGlobalAndAliasInits();
 };
   



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-04-30 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.17 -> 1.18
BitcodeReader.h updated: 1.11 -> 1.12
---
Log message:

implement scafolding for lazy deserialization of function bodies


---
Diffs of the changes:  (+85 -7)

 BitcodeReader.cpp |   65 --
 BitcodeReader.h   |   27 ++
 2 files changed, 85 insertions(+), 7 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.17 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.18
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.17  Sun Apr 29 15:56:48 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Mon Apr 30 23:59:48 2007
@@ -13,7 +13,6 @@
 
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "BitcodeReader.h"
-#include "llvm/Bitcode/BitstreamReader.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
@@ -660,6 +659,30 @@
   }
 }
 
+/// ParseFunction - When we see the block for a function body, remember where 
it
+/// is and then skip it.  This lets us lazily deserialize the functions.
+bool BitcodeReader::ParseFunction(BitstreamReader &Stream) {
+  // Get the function we are talking about.
+  if (FunctionsWithBodies.empty())
+return Error("Insufficient function protos");
+  
+  Function *Fn = FunctionsWithBodies.back();
+  FunctionsWithBodies.pop_back();
+  
+  // Save the current stream state.
+  uint64_t CurBit = Stream.GetCurrentBitNo();
+  DeferredFunctionInfo[Fn] = std::make_pair(CurBit, Fn->getLinkage());
+  
+  // Set the functions linkage to GhostLinkage so we know it is lazily
+  // deserialized.
+  Fn->setLinkage(GlobalValue::GhostLinkage);
+  
+  // Skip over the function block for now.
+  if (Stream.SkipBlock())
+return Error("Malformed block record");
+  return false;
+}
+
 bool BitcodeReader::ParseModule(BitstreamReader &Stream,
 const std::string &ModuleID) {
   // Reject multiple MODULE_BLOCK's in a single bitstream.
@@ -682,6 +705,8 @@
   ResolveGlobalAndAliasInits();
   if (!GlobalInits.empty() || !AliasInits.empty())
 return Error("Malformed global initializer set");
+  if (!FunctionsWithBodies.empty())
+return Error("Too few function bodies found");
   if (Stream.ReadBlockEnd())
 return Error("Error at end of module block");
   return false;
@@ -709,6 +734,17 @@
 if (ParseConstants(Stream) || ResolveGlobalAndAliasInits())
   return true;
 break;
+  case bitc::FUNCTION_BLOCK_ID:
+// If this is the first function body we've seen, reverse the
+// FunctionsWithBodies list.
+if (!HasReversedFunctionsWithBodies) {
+  std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end());
+  HasReversedFunctionsWithBodies = true;
+}
+
+if (ParseFunction(Stream))
+  return true;
+break;
   }
   continue;
 }
@@ -819,6 +855,7 @@
 "", TheModule);
 
   Func->setCallingConv(Record[1]);
+  bool isProto = Record[2];
   Func->setLinkage(GetDecodedLinkage(Record[3]));
   Func->setAlignment((1 << Record[4]) >> 1);
   if (Record[5]) {
@@ -829,6 +866,11 @@
   Func->setVisibility(GetDecodedVisibility(Record[6]));
   
   ValueList.push_back(Func);
+  
+  // If this is a function with a body, remember the prototype we are
+  // creating now, so that we can match up the body with them later.
+  if (!isProto)
+FunctionsWithBodies.push_back(Func);
   break;
 }
 // ALIAS: [alias type, aliasee val#, linkage]
@@ -867,7 +909,7 @@
 return Error("Bitcode stream should be a multiple of 4 bytes in length");
   
   unsigned char *BufPtr = (unsigned char *)Buffer->getBufferStart();
-  BitstreamReader Stream(BufPtr, BufPtr+Buffer->getBufferSize());
+  Stream.init(BufPtr, BufPtr+Buffer->getBufferSize());
   
   // Sniff for the signature.
   if (Stream.Read(8) != 'B' ||
@@ -900,6 +942,25 @@
   return false;
 }
 
+
+bool BitcodeReader::materializeFunction(Function *F, std::string *ErrInfo) {
+  // If it already is material, ignore the request.
+  if (!F->hasNotBeenReadFromBytecode()) return false;
+
+  DenseMap >::iterator DFII = 
+DeferredFunctionInfo.find(F);
+  assert(DFII != DeferredFunctionInfo.end() && "Deferred function not found!");
+  
+  // Move the bit stream to the saved position of the deferred function body 
and
+  // restore the real linkage type for the function.
+  Stream.JumpToBit(DFII->second.first);
+  F->setLinkage((GlobalValue::LinkageTypes)DFII->second.second);
+  DeferredFunctionInfo.erase(DFII);
+  
+  return false;
+}
+
+
 
//===--===//
 // External interface
 
//===--===//


Index: llvm/lib/Bitcode/Reader/BitcodeRea

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-04-29 Thread Anton Korobeynikov


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.16 -> 1.17
---
Log message:

Implement visibility checking during linking. Also implement protected 
visibility support for bitcode.


---
Diffs of the changes:  (+1 -0)

 BitcodeReader.cpp |1 +
 1 files changed, 1 insertion(+)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.16 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.17
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.16  Sun Apr 29 02:54:31 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sun Apr 29 15:56:48 2007
@@ -59,6 +59,7 @@
   default: // Map unknown visibilities to default.
   case 0: return GlobalValue::DefaultVisibility;
   case 1: return GlobalValue::HiddenVisibility;
+  case 2: return GlobalValue::ProtectedVisibility;
   }
 }
 



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h ReaderWrappers.cpp

2007-04-29 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.15 -> 1.16
BitcodeReader.h updated: 1.10 -> 1.11
ReaderWrappers.cpp (r1.2) removed
---
Log message:

Switch the bitcode reader interface to take a MemoryBuffer instead of knowing
anything about disk I/O itself.  This greatly simplifies its interface -
eliminating the need for the ReaderWrappers.cpp file.

This adds a new option to llvm-dis (-bitcode) which instructs it to read
the input file as bitcode.  Until/unless the bytecode reader is taught to
read from MemoryBuffer, there is no way to handle stdin reading without it.

I don't plan to switch the bytecode reader over, I'd rather delete it :),
so the option will stay around temporarily.



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

 BitcodeReader.cpp |   55 +-
 BitcodeReader.h   |   17 +++-
 2 files changed, 62 insertions(+), 10 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.15 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.16
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.15  Sat Apr 28 09:57:59 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sun Apr 29 02:54:31 2007
@@ -11,6 +11,7 @@
 //
 
//===--===//
 
+#include "llvm/Bitcode/ReaderWriter.h"
 #include "BitcodeReader.h"
 #include "llvm/Bitcode/BitstreamReader.h"
 #include "llvm/Constants.h"
@@ -18,8 +19,14 @@
 #include "llvm/Module.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/MemoryBuffer.h"
 using namespace llvm;
 
+BitcodeReader::~BitcodeReader() {
+  delete Buffer;
+}
+
+
 /// ConvertToString - Convert a string from a record into an std::string, 
return
 /// true on failure.
 template
@@ -852,14 +859,14 @@
 }
 
 
-bool BitcodeReader::ParseBitcode(unsigned char *Buf, unsigned Length,
- const std::string &ModuleID) {
+bool BitcodeReader::ParseBitcode() {
   TheModule = 0;
   
-  if (Length & 3)
+  if (Buffer->getBufferSize() & 3)
 return Error("Bitcode stream should be a multiple of 4 bytes in length");
   
-  BitstreamReader Stream(Buf, Buf+Length);
+  unsigned char *BufPtr = (unsigned char *)Buffer->getBufferStart();
+  BitstreamReader Stream(BufPtr, BufPtr+Buffer->getBufferSize());
   
   // Sniff for the signature.
   if (Stream.Read(8) != 'B' ||
@@ -882,7 +889,7 @@
 
 // We only know the MODULE subblock ID.
 if (BlockID == bitc::MODULE_BLOCK_ID) {
-  if (ParseModule(Stream, ModuleID))
+  if (ParseModule(Stream, Buffer->getBufferIdentifier()))
 return true;
 } else if (Stream.SkipBlock()) {
   return Error("Malformed block record");
@@ -891,3 +898,41 @@
   
   return false;
 }
+
+//===--===//
+// External interface
+//===--===//
+
+/// getBitcodeModuleProvider - lazy function-at-a-time loading from a file.
+///
+ModuleProvider *llvm::getBitcodeModuleProvider(MemoryBuffer *Buffer,
+   std::string *ErrMsg) {
+  BitcodeReader *R = new BitcodeReader(Buffer);
+  if (R->ParseBitcode()) {
+if (ErrMsg)
+  *ErrMsg = R->getErrorString();
+
+// Don't let the BitcodeReader dtor delete 'Buffer'.
+R->releaseMemoryBuffer();
+delete R;
+return 0;
+  }
+  return R;
+}
+
+/// ParseBitcodeFile - Read the specified bitcode file, returning the module.
+/// If an error occurs, return null and fill in *ErrMsg if non-null.
+Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, std::string *ErrMsg){
+  BitcodeReader *R;
+  R = static_cast(getBitcodeModuleProvider(Buffer, ErrMsg));
+  if (!R) return 0;
+  
+  // Read the whole module, get a pointer to it, tell ModuleProvider not to
+  // delete it when its dtor is run.
+  Module *M = R->releaseModule(ErrMsg);
+  
+  // Don't let the BitcodeReader dtor delete 'Buffer'.
+  R->releaseMemoryBuffer();
+  delete R;
+  return M;
+}


Index: llvm/lib/Bitcode/Reader/BitcodeReader.h
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.h:1.10 
llvm/lib/Bitcode/Reader/BitcodeReader.h:1.11
--- llvm/lib/Bitcode/Reader/BitcodeReader.h:1.10Wed Apr 25 22:27:58 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.h Sun Apr 29 02:54:31 2007
@@ -22,6 +22,7 @@
 
 namespace llvm {
   class BitstreamReader;
+  class MemoryBuffer;
   
 class BitcodeReaderValueList : public User {
   std::vector Uses;
@@ -57,6 +58,7 @@
   
 
 class BitcodeReader : public ModuleProvider {
+  MemoryBuffer *Buffer;
   const char *ErrorString;
   
   std::vector TypeList;
@@ -64,10 +66,16 @@
   std::vector > GlobalInits;
   std::vector > AliasInits;
 public:
-  BitcodeReader() : ErrorString(0) {}
-  virtual ~BitcodeReader() {}
+  BitcodeReader(MemoryBuffer *buffer) : Buffer(buffer), ErrorString(0) {}
+  ~Bitcode

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-04-28 Thread Anton Korobeynikov


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.14 -> 1.15
---
Log message:

This is not "FIXME" anymore


---
Diffs of the changes:  (+1 -3)

 BitcodeReader.cpp |4 +---
 1 files changed, 1 insertion(+), 3 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.14 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.15
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.14  Wed Apr 25 22:27:58 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sat Apr 28 09:57:59 2007
@@ -427,9 +427,7 @@
   AliasInits.push_back(AliasInitWorklist.back());
 } else {
   if (Constant *C = dyn_cast(ValueList[ValID]))
-AliasInitWorklist.back().first->setAliasee(
-// FIXME:
-cast(C));
+AliasInitWorklist.back().first->setAliasee(C);
   else
 return Error("Alias initializer is not a constant!");
 }



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-04-25 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.13 -> 1.14
BitcodeReader.h updated: 1.9 -> 1.10
---
Log message:

move some code around, fix a bug in the reader reading globalinits (which
I just introduced), stub out function reading, purge aggregate values from
the value table before reading functions.


---
Diffs of the changes:  (+16 -3)

 BitcodeReader.cpp |   14 +++---
 BitcodeReader.h   |5 +
 2 files changed, 16 insertions(+), 3 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.13 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.14
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.13  Wed Apr 25 21:46:40 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Wed Apr 25 22:27:58 2007
@@ -408,10 +408,10 @@
   AliasInitWorklist.swap(AliasInits);
 
   while (!GlobalInitWorklist.empty()) {
-unsigned ValID = GlobalInits.back().second;
+unsigned ValID = GlobalInitWorklist.back().second;
 if (ValID >= ValueList.size()) {
   // Not ready to resolve this yet, it requires something later in the 
file.
-  GlobalInitWorklist.push_back(GlobalInits.back());
+  GlobalInits.push_back(GlobalInitWorklist.back());
 } else {
   if (Constant *C = dyn_cast(ValueList[ValID]))
 GlobalInitWorklist.back().first->setInitializer(C);
@@ -826,7 +826,7 @@
   break;
 }
 // ALIAS: [alias type, aliasee val#, linkage]
-case bitc::MODULE_CODE_ALIAS:
+case bitc::MODULE_CODE_ALIAS: {
   if (Record.size() < 3)
 return Error("Invalid MODULE_ALIAS record");
   const Type *Ty = getTypeByID(Record[0]);
@@ -839,6 +839,14 @@
   AliasInits.push_back(std::make_pair(NewGA, Record[1]));
   break;
 }
+/// MODULE_CODE_PURGEVALS: [numvals]
+case bitc::MODULE_CODE_PURGEVALS:
+  // Trim down the value list to the specified size.
+  if (Record.size() < 1 || Record[0] > ValueList.size())
+return Error("Invalid MODULE_PURGEVALS record");
+  ValueList.shrinkTo(Record[0]);
+  break;
+}
 Record.clear();
   }
   


Index: llvm/lib/Bitcode/Reader/BitcodeReader.h
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.h:1.9 
llvm/lib/Bitcode/Reader/BitcodeReader.h:1.10
--- llvm/lib/Bitcode/Reader/BitcodeReader.h:1.9 Wed Apr 25 21:46:40 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.h Wed Apr 25 22:27:58 2007
@@ -41,6 +41,11 @@
   Value *back() const { return Uses.back(); }
   void pop_back() { Uses.pop_back(); --NumOperands; }
   bool empty() const { return NumOperands == 0; }
+  void shrinkTo(unsigned N) {
+assert(N < NumOperands && "Invalid shrinkTo request!");
+Uses.resize(N);
+NumOperands = N;
+  }
   virtual void print(std::ostream&) const {}
   
   Constant *getConstantFwdRef(unsigned Idx, const Type *Ty);



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-04-25 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.12 -> 1.13
BitcodeReader.h updated: 1.8 -> 1.9
---
Log message:

add bitcode alias support



---
Diffs of the changes:  (+59 -17)

 BitcodeReader.cpp |   74 +-
 BitcodeReader.h   |2 +
 2 files changed, 59 insertions(+), 17 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.12 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.13
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.12  Tue Apr 24 13:15:21 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Wed Apr 25 21:46:40 2007
@@ -398,6 +398,47 @@
   return 1ULL << 63;
 }
 
+/// ResolveGlobalAndAliasInits - Resolve all of the initializers for global
+/// values and aliases that we can.
+bool BitcodeReader::ResolveGlobalAndAliasInits() {
+  std::vector > GlobalInitWorklist;
+  std::vector > AliasInitWorklist;
+  
+  GlobalInitWorklist.swap(GlobalInits);
+  AliasInitWorklist.swap(AliasInits);
+
+  while (!GlobalInitWorklist.empty()) {
+unsigned ValID = GlobalInits.back().second;
+if (ValID >= ValueList.size()) {
+  // Not ready to resolve this yet, it requires something later in the 
file.
+  GlobalInitWorklist.push_back(GlobalInits.back());
+} else {
+  if (Constant *C = dyn_cast(ValueList[ValID]))
+GlobalInitWorklist.back().first->setInitializer(C);
+  else
+return Error("Global variable initializer is not a constant!");
+}
+GlobalInitWorklist.pop_back(); 
+  }
+
+  while (!AliasInitWorklist.empty()) {
+unsigned ValID = AliasInitWorklist.back().second;
+if (ValID >= ValueList.size()) {
+  AliasInits.push_back(AliasInitWorklist.back());
+} else {
+  if (Constant *C = dyn_cast(ValueList[ValID]))
+AliasInitWorklist.back().first->setAliasee(
+// FIXME:
+cast(C));
+  else
+return Error("Alias initializer is not a constant!");
+}
+AliasInitWorklist.pop_back(); 
+  }
+  return false;
+}
+
+
 bool BitcodeReader::ParseConstants(BitstreamReader &Stream) {
   if (Stream.EnterSubBlock())
 return Error("Malformed block record");
@@ -410,20 +451,6 @@
   while (1) {
 unsigned Code = Stream.ReadCode();
 if (Code == bitc::END_BLOCK) {
-  // If there are global var inits to process, do so now.
-  if (!GlobalInits.empty()) {
-while (!GlobalInits.empty()) {
-  unsigned ValID = GlobalInits.back().second;
-  if (ValID >= ValueList.size())
-return Error("Invalid value ID for global var init!");
-  if (Constant *C = dyn_cast(ValueList[ValID]))
-GlobalInits.back().first->setInitializer(C);
-  else
-return Error("Global variable initializer is not a constant!");
-  GlobalInits.pop_back(); 
-}
-  }
-  
   if (NextCstNo != ValueList.size())
 return Error("Invalid constant reference!");
   
@@ -646,7 +673,8 @@
   while (!Stream.AtEndOfStream()) {
 unsigned Code = Stream.ReadCode();
 if (Code == bitc::END_BLOCK) {
-  if (!GlobalInits.empty())
+  ResolveGlobalAndAliasInits();
+  if (!GlobalInits.empty() || !AliasInits.empty())
 return Error("Malformed global initializer set");
   if (Stream.ReadBlockEnd())
 return Error("Error at end of module block");
@@ -672,7 +700,7 @@
   return true;
 break;
   case bitc::CONSTANTS_BLOCK_ID:
-if (ParseConstants(Stream))
+if (ParseConstants(Stream) || ResolveGlobalAndAliasInits())
   return true;
 break;
   }
@@ -795,9 +823,21 @@
   Func->setVisibility(GetDecodedVisibility(Record[6]));
   
   ValueList.push_back(Func);
-  // TODO: remember initializer/global pair for later substitution.
   break;
 }
+// ALIAS: [alias type, aliasee val#, linkage]
+case bitc::MODULE_CODE_ALIAS:
+  if (Record.size() < 3)
+return Error("Invalid MODULE_ALIAS record");
+  const Type *Ty = getTypeByID(Record[0]);
+  if (!isa(Ty))
+return Error("Function not a pointer type!");
+  
+  GlobalAlias *NewGA = new GlobalAlias(Ty, GetDecodedLinkage(Record[2]),
+   "", 0, TheModule);
+  ValueList.push_back(NewGA);
+  AliasInits.push_back(std::make_pair(NewGA, Record[1]));
+  break;
 }
 Record.clear();
   }


Index: llvm/lib/Bitcode/Reader/BitcodeReader.h
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.h:1.8 
llvm/lib/Bitcode/Reader/BitcodeReader.h:1.9
--- llvm/lib/Bitcode/Reader/BitcodeReader.h:1.8 Tue Apr 24 13:15:21 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.h Wed Apr 25 21:46:40 2007
@@ -57,6 +57,7 @@
   std::vector TypeList;
   BitcodeReaderValueList ValueList;
   std::vector > GlobalInits;
+  std::vector > AliasInits;
 public:
   BitcodeRead

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h ReaderWrappers.cpp

2007-04-24 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.11 -> 1.12
BitcodeReader.h updated: 1.7 -> 1.8
ReaderWrappers.cpp updated: 1.1 -> 1.2
---
Log message:

ensure that every error return sets a message (and goes through Error, for
easy breakpointing).

Fix bugs reading constantexpr geps.  We now can disassemble kc++ global 
initializers.


---
Diffs of the changes:  (+37 -19)

 BitcodeReader.cpp  |   54 ++---
 BitcodeReader.h|1 
 ReaderWrappers.cpp |1 
 3 files changed, 37 insertions(+), 19 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.11 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.12
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.11  Tue Apr 24 12:22:05 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Tue Apr 24 13:15:21 2007
@@ -161,7 +161,9 @@
 if (Code == bitc::END_BLOCK) {
   if (NumRecords != TypeList.size())
 return Error("Invalid type forward reference in TYPE_BLOCK");
-  return Stream.ReadBlockEnd();
+  if (Stream.ReadBlockEnd())
+return Error("Error at end of type table block");
+  return false;
 }
 
 if (Code == bitc::ENTER_SUBBLOCK) {
@@ -299,8 +301,11 @@
   std::string TypeName;
   while (1) {
 unsigned Code = Stream.ReadCode();
-if (Code == bitc::END_BLOCK)
-  return Stream.ReadBlockEnd();
+if (Code == bitc::END_BLOCK) {
+  if (Stream.ReadBlockEnd())
+return Error("Error at end of type symbol table block");
+  return false;
+}
 
 if (Code == bitc::ENTER_SUBBLOCK) {
   // No known subblocks, always skip them.
@@ -344,9 +349,11 @@
   SmallString<128> ValueName;
   while (1) {
 unsigned Code = Stream.ReadCode();
-if (Code == bitc::END_BLOCK)
-  return Stream.ReadBlockEnd();
-
+if (Code == bitc::END_BLOCK) {
+  if (Stream.ReadBlockEnd())
+return Error("Error at end of value symbol table block");
+  return false;
+}
 if (Code == bitc::ENTER_SUBBLOCK) {
   // No known subblocks, always skip them.
   Stream.ReadSubBlockID();
@@ -420,7 +427,9 @@
   if (NextCstNo != ValueList.size())
 return Error("Invalid constant reference!");
   
-  return Stream.ReadBlockEnd();
+  if (Stream.ReadBlockEnd())
+return Error("Error at end of constants block");
+  return false;
 }
 
 if (Code == bitc::ENTER_SUBBLOCK) {
@@ -515,21 +524,25 @@
 case bitc::CST_CODE_CE_BINOP: {  // CE_BINOP: [opcode, opval, opval]
   if (Record.size() < 3) return Error("Invalid CE_BINOP record");
   int Opc = GetDecodedBinaryOpcode(Record[0], CurTy);
-  if (Opc < 0) return UndefValue::get(CurTy);  // Unknown binop.
-  
-  Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
-  Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy);
-  V = ConstantExpr::get(Opc, LHS, RHS);
+  if (Opc < 0) {
+V = UndefValue::get(CurTy);  // Unknown binop.
+  } else {
+Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
+Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy);
+V = ConstantExpr::get(Opc, LHS, RHS);
+  }
   break;
 }  
 case bitc::CST_CODE_CE_CAST: {  // CE_CAST: [opcode, opty, opval]
   if (Record.size() < 3) return Error("Invalid CE_CAST record");
   int Opc = GetDecodedCastOpcode(Record[0]);
-  if (Opc < 0) return UndefValue::get(CurTy);  // Unknown cast.
-  
-  const Type *OpTy = getTypeByID(Record[1]);
-  Constant *Op = ValueList.getConstantFwdRef(Record[2], OpTy);
-  V = ConstantExpr::getCast(Opc, Op, CurTy);
+  if (Opc < 0) {
+V = UndefValue::get(CurTy);  // Unknown cast.
+  } else {
+const Type *OpTy = getTypeByID(Record[1]);
+Constant *Op = ValueList.getConstantFwdRef(Record[2], OpTy);
+V = ConstantExpr::getCast(Opc, Op, CurTy);
+  }
   break;
 }  
 case bitc::CST_CODE_CE_GEP: {  // CE_GEP:[n x operands]
@@ -540,7 +553,8 @@
 if (!ElTy) return Error("Invalid CE_GEP record");
 Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
   }
-  return ConstantExpr::getGetElementPtr(Elts[0], &Elts[1], Elts.size()-1);
+  V = ConstantExpr::getGetElementPtr(Elts[0], &Elts[1], Elts.size()-1);
+  break;
 }
 case bitc::CST_CODE_CE_SELECT:  // CE_SELECT: [opval#, opval#, opval#]
   if (Record.size() < 3) return Error("Invalid CE_SELECT record");
@@ -634,7 +648,9 @@
 if (Code == bitc::END_BLOCK) {
   if (!GlobalInits.empty())
 return Error("Malformed global initializer set");
-  return Stream.ReadBlockEnd();
+  if (Stream.ReadBlockEnd())
+return Error("Error at end of module block");
+  return false;
 }
 
 if (Code == bitc::ENTER_SUBBLOCK) {


Index: llvm/lib/Bitcode/Reader/BitcodeRea

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-04-24 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.10 -> 1.11
---
Log message:

fix memory leak


---
Diffs of the changes:  (+4 -3)

 BitcodeReader.cpp |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.10 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.11
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.10  Tue Apr 24 02:07:11 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Tue Apr 24 12:22:05 2007
@@ -465,11 +465,12 @@
 return Error("Invalid WIDE_INTEGER record");
   
   unsigned NumWords = Record[0];
-  uint64_t *Data = new uint64_t[NumWords];
+  SmallVector Words;
+  Words.resize(NumWords);
   for (unsigned i = 0; i != NumWords; ++i)
-Data[i] = DecodeSignRotatedValue(Record[i+1]);
+Words[i] = DecodeSignRotatedValue(Record[i+1]);
   V = ConstantInt::get(APInt(cast(CurTy)->getBitWidth(),
- NumWords, Data));
+ NumWords, &Words[0]));
   break;
 }
 case bitc::CST_CODE_FLOAT: // FLOAT: [fpval]



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-04-24 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.9 -> 1.10
---
Log message:

implement reading and writing of constant exprs.


---
Diffs of the changes:  (+133 -6)

 BitcodeReader.cpp |  139 +++---
 1 files changed, 133 insertions(+), 6 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.9 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.10
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.9   Tue Apr 24 00:48:56 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Tue Apr 24 02:07:11 2007
@@ -55,17 +55,56 @@
   }
 }
 
+static int GetDecodedCastOpcode(unsigned Val) {
+  switch (Val) {
+  default: return -1;
+  case bitc::CAST_TRUNC   : return Instruction::Trunc;
+  case bitc::CAST_ZEXT: return Instruction::ZExt;
+  case bitc::CAST_SEXT: return Instruction::SExt;
+  case bitc::CAST_FPTOUI  : return Instruction::FPToUI;
+  case bitc::CAST_FPTOSI  : return Instruction::FPToSI;
+  case bitc::CAST_UITOFP  : return Instruction::UIToFP;
+  case bitc::CAST_SITOFP  : return Instruction::SIToFP;
+  case bitc::CAST_FPTRUNC : return Instruction::FPTrunc;
+  case bitc::CAST_FPEXT   : return Instruction::FPExt;
+  case bitc::CAST_PTRTOINT: return Instruction::PtrToInt;
+  case bitc::CAST_INTTOPTR: return Instruction::IntToPtr;
+  case bitc::CAST_BITCAST : return Instruction::BitCast;
+  }
+}
+static int GetDecodedBinaryOpcode(unsigned Val, const Type *Ty) {
+  switch (Val) {
+  default: return -1;
+  case bitc::BINOP_ADD:  return Instruction::Add;
+  case bitc::BINOP_SUB:  return Instruction::Sub;
+  case bitc::BINOP_MUL:  return Instruction::Mul;
+  case bitc::BINOP_UDIV: return Instruction::UDiv;
+  case bitc::BINOP_SDIV:
+return Ty->isFPOrFPVector() ? Instruction::FDiv : Instruction::SDiv;
+  case bitc::BINOP_UREM: return Instruction::URem;
+  case bitc::BINOP_SREM:
+return Ty->isFPOrFPVector() ? Instruction::FRem : Instruction::SRem;
+  case bitc::BINOP_SHL:  return Instruction::Shl;
+  case bitc::BINOP_LSHR: return Instruction::LShr;
+  case bitc::BINOP_ASHR: return Instruction::AShr;
+  case bitc::BINOP_AND:  return Instruction::And;
+  case bitc::BINOP_OR:   return Instruction::Or;
+  case bitc::BINOP_XOR:  return Instruction::Xor;
+  }
+}
+
+
 namespace {
   /// @brief A class for maintaining the slot number definition
   /// as a placeholder for the actual definition for forward constants defs.
   class ConstantPlaceHolder : public ConstantExpr {
 ConstantPlaceHolder();   // DO NOT IMPLEMENT
 void operator=(const ConstantPlaceHolder &); // DO NOT IMPLEMENT
-public:
-  Use Op;
-  ConstantPlaceHolder(const Type *Ty)
-: ConstantExpr(Ty, Instruction::UserOp1, &Op, 1),
-  Op(UndefValue::get(Type::Int32Ty), this) {
+  public:
+Use Op;
+ConstantPlaceHolder(const Type *Ty)
+  : ConstantExpr(Ty, Instruction::UserOp1, &Op, 1),
+Op(UndefValue::get(Type::Int32Ty), this) {
 }
   };
 }
@@ -79,8 +118,11 @@
 NumOperands = Idx+1;
   }
 
-  if (Uses[Idx])
+  if (Uses[Idx]) {
+assert(Ty == getOperand(Idx)->getType() &&
+   "Type mismatch in constant table!");
 return cast(getOperand(Idx));
+  }
 
   // Create and return a placeholder, which will later be RAUW'd.
   Constant *C = new ConstantPlaceHolder(Ty);
@@ -466,6 +508,91 @@
   } else {
 V = UndefValue::get(CurTy);
   }
+  break;
+}
+
+case bitc::CST_CODE_CE_BINOP: {  // CE_BINOP: [opcode, opval, opval]
+  if (Record.size() < 3) return Error("Invalid CE_BINOP record");
+  int Opc = GetDecodedBinaryOpcode(Record[0], CurTy);
+  if (Opc < 0) return UndefValue::get(CurTy);  // Unknown binop.
+  
+  Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
+  Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy);
+  V = ConstantExpr::get(Opc, LHS, RHS);
+  break;
+}  
+case bitc::CST_CODE_CE_CAST: {  // CE_CAST: [opcode, opty, opval]
+  if (Record.size() < 3) return Error("Invalid CE_CAST record");
+  int Opc = GetDecodedCastOpcode(Record[0]);
+  if (Opc < 0) return UndefValue::get(CurTy);  // Unknown cast.
+  
+  const Type *OpTy = getTypeByID(Record[1]);
+  Constant *Op = ValueList.getConstantFwdRef(Record[2], OpTy);
+  V = ConstantExpr::getCast(Opc, Op, CurTy);
+  break;
+}  
+case bitc::CST_CODE_CE_GEP: {  // CE_GEP:[n x operands]
+  if ((Record.size() & 1) == 0) return Error("Invalid CE_GEP record");
+  SmallVector Elts;
+  for (unsigned i = 1, e = Record.size(); i != e; i += 2) {
+const Type *ElTy = getTypeByID(Record[i]);
+if (!ElTy) return Error("Invalid CE_GEP record");
+Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
+  }
+  return ConstantExpr::getGetElementPtr(Elts[0], &Elts[1], Elts.size()-1);
+}
+case bitc::CST_CODE_CE_SELECT:  // CE_SELECT: [

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-04-23 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.8 -> 1.9
BitcodeReader.h updated: 1.6 -> 1.7
---
Log message:

implement support for reading aggregate constants, including handling forward
constant references, etc.


---
Diffs of the changes:  (+108 -5)

 BitcodeReader.cpp |   78 +-
 BitcodeReader.h   |   35 +---
 2 files changed, 108 insertions(+), 5 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.8 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.9
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.8   Mon Apr 23 23:04:35 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Tue Apr 24 00:48:56 2007
@@ -55,6 +55,39 @@
   }
 }
 
+namespace {
+  /// @brief A class for maintaining the slot number definition
+  /// as a placeholder for the actual definition for forward constants defs.
+  class ConstantPlaceHolder : public ConstantExpr {
+ConstantPlaceHolder();   // DO NOT IMPLEMENT
+void operator=(const ConstantPlaceHolder &); // DO NOT IMPLEMENT
+public:
+  Use Op;
+  ConstantPlaceHolder(const Type *Ty)
+: ConstantExpr(Ty, Instruction::UserOp1, &Op, 1),
+  Op(UndefValue::get(Type::Int32Ty), this) {
+}
+  };
+}
+
+Constant *BitcodeReaderValueList::getConstantFwdRef(unsigned Idx,
+const Type *Ty) {
+  if (Idx >= size()) {
+// Insert a bunch of null values.
+Uses.resize(Idx+1);
+OperandList = &Uses[0];
+NumOperands = Idx+1;
+  }
+
+  if (Uses[Idx])
+return cast(getOperand(Idx));
+
+  // Create and return a placeholder, which will later be RAUW'd.
+  Constant *C = new ConstantPlaceHolder(Ty);
+  Uses[Idx].init(C, this);
+  return C;
+}
+
 
 const Type *BitcodeReader::getTypeByID(unsigned ID, bool isTypeTable) {
   // If the TypeID is in range, return it.
@@ -324,6 +357,7 @@
   
   // Read all the records for this value table.
   const Type *CurTy = Type::Int32Ty;
+  unsigned NextCstNo = ValueList.size();
   while (1) {
 unsigned Code = Stream.ReadCode();
 if (Code == bitc::END_BLOCK) {
@@ -341,6 +375,9 @@
 }
   }
   
+  if (NextCstNo != ValueList.size())
+return Error("Invalid constant reference!");
+  
   return Stream.ReadBlockEnd();
 }
 
@@ -403,9 +440,48 @@
   else
 V = UndefValue::get(CurTy);
   break;
+  
+case bitc::CST_CODE_AGGREGATE: {// AGGREGATE: [n, n x value number]
+  if (Record.empty() || Record.size() < Record[0]+1)
+return Error("Invalid CST_AGGREGATE record");
+  
+  unsigned Size = Record[0];
+  std::vector Elts;
+  
+  if (const StructType *STy = dyn_cast(CurTy)) {
+for (unsigned i = 0; i != Size; ++i)
+  Elts.push_back(ValueList.getConstantFwdRef(Record[i+1],
+ STy->getElementType(i)));
+V = ConstantStruct::get(STy, Elts);
+  } else if (const ArrayType *ATy = dyn_cast(CurTy)) {
+const Type *EltTy = ATy->getElementType();
+for (unsigned i = 0; i != Size; ++i)
+  Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], EltTy));
+V = ConstantArray::get(ATy, Elts);
+  } else if (const VectorType *VTy = dyn_cast(CurTy)) {
+const Type *EltTy = VTy->getElementType();
+for (unsigned i = 0; i != Size; ++i)
+  Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], EltTy));
+V = ConstantVector::get(Elts);
+  } else {
+V = UndefValue::get(CurTy);
+  }
+}
+}
+
+if (NextCstNo == ValueList.size())
+  ValueList.push_back(V);
+else if (ValueList[NextCstNo] == 0)
+  ValueList.initVal(NextCstNo, V);
+else {
+  // If there was a forward reference to this constant, 
+  Value *OldV = ValueList[NextCstNo];
+  ValueList.setOperand(NextCstNo, V);
+  OldV->replaceAllUsesWith(V);
+  delete OldV;
 }
 
-ValueList.push_back(V);
+++NextCstNo;
   }
 }
 


Index: llvm/lib/Bitcode/Reader/BitcodeReader.h
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.h:1.6 
llvm/lib/Bitcode/Reader/BitcodeReader.h:1.7
--- llvm/lib/Bitcode/Reader/BitcodeReader.h:1.6 Mon Apr 23 22:30:34 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.h Tue Apr 24 00:48:56 2007
@@ -14,21 +14,48 @@
 #ifndef BITCODE_READER_H
 #define BITCODE_READER_H
 
-#include "llvm/Type.h"
 #include "llvm/ModuleProvider.h"
+#include "llvm/Type.h"
+#include "llvm/User.h"
 #include "llvm/Bitcode/LLVMBitCodes.h"
 #include 
 
 namespace llvm {
   class BitstreamReader;
-  class Value;
-  class GlobalVariable;
+  
+class BitcodeReaderValueList : public User {
+  std::vector Uses;
+public:
+  BitcodeReaderValueList() : User(Type::VoidTy, Value::ArgumentVal, 0, 0) {}
+  
+  // vector compatibility methods
+  unsigned size() const { return getNumOperands(); }
+  void push_back(

[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-04-23 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.7 -> 1.8
---
Log message:

add supprot for FP constants, wide integers, and fix the encoding of MININT


---
Diffs of the changes:  (+40 -8)

 BitcodeReader.cpp |   48 
 1 files changed, 40 insertions(+), 8 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.7 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.8
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.7   Mon Apr 23 22:30:34 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Mon Apr 23 23:04:35 2007
@@ -17,6 +17,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/Support/MathExtras.h"
 using namespace llvm;
 
 /// ConvertToString - Convert a string from a record into an std::string, 
return
@@ -204,8 +205,8 @@
   const_cast(OldTy)->refineAbstractTypeTo(ResultTy);
   
   // This should have replaced the old opaque type with the new type in the
-  // value table... or with a preexisting type that was already in the 
system.
-  // Let's just make sure it did.
+  // value table... or with a preexisting type that was already in the
+  // system.  Let's just make sure it did.
   assert(TypeList[NumRecords-1].get() != OldTy &&
  "refineAbstractType didn't work!");
 }
@@ -304,6 +305,17 @@
   }
 }
 
+/// DecodeSignRotatedValue - Decode a signed value stored with the sign bit in
+/// the LSB for dense VBR encoding.
+static uint64_t DecodeSignRotatedValue(uint64_t V) {
+  if ((V & 1) == 0)
+return V >> 1;
+  if (V != 1) 
+return -(V >> 1);
+  // There is no such thing as -0 with integers.  "-0" really means MININT.
+  return 1ULL << 63;
+}
+
 bool BitcodeReader::ParseConstants(BitstreamReader &Stream) {
   if (Stream.EnterSubBlock())
 return Error("Malformed block record");
@@ -359,17 +371,37 @@
   if (Record[0] >= TypeList.size())
 return Error("Invalid Type ID in CST_SETTYPE record");
   CurTy = TypeList[Record[0]];
-  continue;
+  continue;  // Skip the ValueList manipulation.
 case bitc::CST_CODE_NULL:  // NULL
   V = Constant::getNullValue(CurTy);
   break;
 case bitc::CST_CODE_INTEGER:   // INTEGER: [intval]
-  if (!isa(CurTy))
-return Error("Invalid type for CST_INTEGER");
-  if (Record[0] & 1)
-V = ConstantInt::get(CurTy, -(Record[0]>>1));
+  if (!isa(CurTy) || Record.empty())
+return Error("Invalid CST_INTEGER record");
+  V = ConstantInt::get(CurTy, DecodeSignRotatedValue(Record[0]));
+  break;
+case bitc::CST_CODE_WIDE_INTEGER: {// WIDE_INTEGER: [n, n x intval]
+  if (!isa(CurTy) || Record.empty() ||
+  Record.size() < Record[0]+1)
+return Error("Invalid WIDE_INTEGER record");
+  
+  unsigned NumWords = Record[0];
+  uint64_t *Data = new uint64_t[NumWords];
+  for (unsigned i = 0; i != NumWords; ++i)
+Data[i] = DecodeSignRotatedValue(Record[i+1]);
+  V = ConstantInt::get(APInt(cast(CurTy)->getBitWidth(),
+ NumWords, Data));
+  break;
+}
+case bitc::CST_CODE_FLOAT: // FLOAT: [fpval]
+  if (Record.empty())
+return Error("Invalid FLOAT record");
+  if (CurTy == Type::FloatTy)
+V = ConstantFP::get(CurTy, BitsToFloat(Record[0]));
+  else if (CurTy == Type::DoubleTy)
+V = ConstantFP::get(CurTy, BitsToDouble(Record[0]));
   else
-V = ConstantInt::get(CurTy, Record[0]>>1);
+V = UndefValue::get(CurTy);
   break;
 }
 



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-04-23 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.6 -> 1.7
BitcodeReader.h updated: 1.5 -> 1.6
---
Log message:

read basic constants: null, undef, integers <= 64bits


---
Diffs of the changes:  (+80 -2)

 BitcodeReader.cpp |   77 ++
 BitcodeReader.h   |5 ++-
 2 files changed, 80 insertions(+), 2 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.6 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.7
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.6   Mon Apr 23 19:21:45 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Mon Apr 23 22:30:34 2007
@@ -13,6 +13,7 @@
 
 #include "BitcodeReader.h"
 #include "llvm/Bitcode/BitstreamReader.h"
+#include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/ADT/SmallString.h"
@@ -303,6 +304,78 @@
   }
 }
 
+bool BitcodeReader::ParseConstants(BitstreamReader &Stream) {
+  if (Stream.EnterSubBlock())
+return Error("Malformed block record");
+
+  SmallVector Record;
+  
+  // Read all the records for this value table.
+  const Type *CurTy = Type::Int32Ty;
+  while (1) {
+unsigned Code = Stream.ReadCode();
+if (Code == bitc::END_BLOCK) {
+  // If there are global var inits to process, do so now.
+  if (!GlobalInits.empty()) {
+while (!GlobalInits.empty()) {
+  unsigned ValID = GlobalInits.back().second;
+  if (ValID >= ValueList.size())
+return Error("Invalid value ID for global var init!");
+  if (Constant *C = dyn_cast(ValueList[ValID]))
+GlobalInits.back().first->setInitializer(C);
+  else
+return Error("Global variable initializer is not a constant!");
+  GlobalInits.pop_back(); 
+}
+  }
+  
+  return Stream.ReadBlockEnd();
+}
+
+if (Code == bitc::ENTER_SUBBLOCK) {
+  // No known subblocks, always skip them.
+  Stream.ReadSubBlockID();
+  if (Stream.SkipBlock())
+return Error("Malformed block record");
+  continue;
+}
+
+if (Code == bitc::DEFINE_ABBREV) {
+  Stream.ReadAbbrevRecord();
+  continue;
+}
+
+// Read a record.
+Record.clear();
+Value *V = 0;
+switch (Stream.ReadRecord(Code, Record)) {
+default:  // Default behavior: unknown constant
+case bitc::CST_CODE_UNDEF: // UNDEF
+  V = UndefValue::get(CurTy);
+  break;
+case bitc::CST_CODE_SETTYPE:   // SETTYPE: [typeid]
+  if (Record.empty())
+return Error("Malformed CST_SETTYPE record");
+  if (Record[0] >= TypeList.size())
+return Error("Invalid Type ID in CST_SETTYPE record");
+  CurTy = TypeList[Record[0]];
+  continue;
+case bitc::CST_CODE_NULL:  // NULL
+  V = Constant::getNullValue(CurTy);
+  break;
+case bitc::CST_CODE_INTEGER:   // INTEGER: [intval]
+  if (!isa(CurTy))
+return Error("Invalid type for CST_INTEGER");
+  if (Record[0] & 1)
+V = ConstantInt::get(CurTy, -(Record[0]>>1));
+  else
+V = ConstantInt::get(CurTy, Record[0]>>1);
+  break;
+}
+
+ValueList.push_back(V);
+  }
+}
 
 bool BitcodeReader::ParseModule(BitstreamReader &Stream,
 const std::string &ModuleID) {
@@ -346,6 +419,10 @@
 if (ParseValueSymbolTable(Stream))
   return true;
 break;
+  case bitc::CONSTANTS_BLOCK_ID:
+if (ParseConstants(Stream))
+  return true;
+break;
   }
   continue;
 }


Index: llvm/lib/Bitcode/Reader/BitcodeReader.h
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.h:1.5 
llvm/lib/Bitcode/Reader/BitcodeReader.h:1.6
--- llvm/lib/Bitcode/Reader/BitcodeReader.h:1.5 Mon Apr 23 19:18:21 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.h Mon Apr 23 22:30:34 2007
@@ -22,14 +22,14 @@
 namespace llvm {
   class BitstreamReader;
   class Value;
-  class GlobalValue;
+  class GlobalVariable;
 
 class BitcodeReader : public ModuleProvider {
   const char *ErrorString;
   
   std::vector TypeList;
   std::vector ValueList;
-  std::vector > GlobalInits;
+  std::vector > GlobalInits;
 public:
   virtual ~BitcodeReader() {}
   
@@ -64,6 +64,7 @@
   bool ParseTypeTable(BitstreamReader &Stream);
   bool ParseTypeSymbolTable(BitstreamReader &Stream);
   bool ParseValueSymbolTable(BitstreamReader &Stream);
+  bool ParseConstants(BitstreamReader &Stream);
 };
   
 } // End llvm namespace



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-04-23 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.5 -> 1.6
---
Log message:

move check to the right place :)


---
Diffs of the changes:  (+4 -3)

 BitcodeReader.cpp |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.5 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.6
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.5   Mon Apr 23 19:18:21 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Mon Apr 23 19:21:45 2007
@@ -322,8 +322,11 @@
   // Read all the records for this module.
   while (!Stream.AtEndOfStream()) {
 unsigned Code = Stream.ReadCode();
-if (Code == bitc::END_BLOCK)
+if (Code == bitc::END_BLOCK) {
+  if (!GlobalInits.empty())
+return Error("Malformed global initializer set");
   return Stream.ReadBlockEnd();
+}
 
 if (Code == bitc::ENTER_SUBBLOCK) {
   switch (Stream.ReadSubBlockID()) {
@@ -358,8 +361,6 @@
 case bitc::MODULE_CODE_VERSION:  // VERSION: [version#]
   if (Record.size() < 1)
 return Error("Malformed MODULE_CODE_VERSION");
-  if (!GlobalInits.empty())
-return Error("Malformed global initializer set");
   // Only version #0 is supported so far.
   if (Record[0] != 0)
 return Error("Unknown bitstream version!");



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-04-23 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.4 -> 1.5
BitcodeReader.h updated: 1.4 -> 1.5
---
Log message:

track global inits


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

 BitcodeReader.cpp |   10 +++---
 BitcodeReader.h   |2 ++
 2 files changed, 9 insertions(+), 3 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.4 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.5
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.4   Mon Apr 23 16:26:05 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Mon Apr 23 19:18:21 2007
@@ -243,7 +243,7 @@
 switch (Stream.ReadRecord(Code, Record)) {
 default:  // Default behavior: unknown type.
   break;
-case bitc::TST_ENTRY_CODE:// TST_ENTRY: [typeid, namelen, namechar x N]
+case bitc::TST_CODE_ENTRY:// TST_ENTRY: [typeid, namelen, namechar x N]
   if (ConvertToString(Record, 1, TypeName))
 return Error("Invalid TST_ENTRY record");
   unsigned TypeID = Record[0];
@@ -288,7 +288,7 @@
 switch (Stream.ReadRecord(Code, Record)) {
 default:  // Default behavior: unknown type.
   break;
-case bitc::VST_ENTRY_CODE:// VST_ENTRY: [valueid, namelen, namechar x 
N]
+case bitc::TST_CODE_ENTRY:// VST_ENTRY: [valueid, namelen, namechar x 
N]
   if (ConvertToString(Record, 1, ValueName))
 return Error("Invalid TST_ENTRY record");
   unsigned ValueID = Record[0];
@@ -358,6 +358,8 @@
 case bitc::MODULE_CODE_VERSION:  // VERSION: [version#]
   if (Record.size() < 1)
 return Error("Malformed MODULE_CODE_VERSION");
+  if (!GlobalInits.empty())
+return Error("Malformed global initializer set");
   // Only version #0 is supported so far.
   if (Record[0] != 0)
 return Error("Unknown bitstream version!");
@@ -431,7 +433,9 @@
   
   ValueList.push_back(NewGV);
   
-  // TODO: remember initializer/global pair for later substitution.
+  // Remember which value to use for the global initializer.
+  if (unsigned InitID = Record[2])
+GlobalInits.push_back(std::make_pair(NewGV, InitID-1));
   break;
 }
 // FUNCTION:  [type, callingconv, isproto, linkage, alignment, section,


Index: llvm/lib/Bitcode/Reader/BitcodeReader.h
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.h:1.4 
llvm/lib/Bitcode/Reader/BitcodeReader.h:1.5
--- llvm/lib/Bitcode/Reader/BitcodeReader.h:1.4 Mon Apr 23 16:26:05 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.h Mon Apr 23 19:18:21 2007
@@ -22,12 +22,14 @@
 namespace llvm {
   class BitstreamReader;
   class Value;
+  class GlobalValue;
 
 class BitcodeReader : public ModuleProvider {
   const char *ErrorString;
   
   std::vector TypeList;
   std::vector ValueList;
+  std::vector > GlobalInits;
 public:
   virtual ~BitcodeReader() {}
   



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

2007-04-23 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.3 -> 1.4
BitcodeReader.h updated: 1.3 -> 1.4
---
Log message:

Read global symtab


---
Diffs of the changes:  (+59 -3)

 BitcodeReader.cpp |   59 +++---
 BitcodeReader.h   |3 ++
 2 files changed, 59 insertions(+), 3 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.3 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.4
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.3   Mon Apr 23 13:58:34 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Mon Apr 23 16:26:05 2007
@@ -15,12 +15,14 @@
 #include "llvm/Bitcode/BitstreamReader.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
+#include "llvm/ADT/SmallString.h"
 using namespace llvm;
 
 /// ConvertToString - Convert a string from a record into an std::string, 
return
 /// true on failure.
+template
 static bool ConvertToString(SmallVector &Record, unsigned Idx,
-std::string &Result) {
+StrTy &Result) {
   if (Record.size() < Idx+1 || Record.size() < Record[Idx]+Idx+1)
 return true;
   
@@ -255,6 +257,52 @@
   }
 }
 
+bool BitcodeReader::ParseValueSymbolTable(BitstreamReader &Stream) {
+  if (Stream.EnterSubBlock())
+return Error("Malformed block record");
+
+  SmallVector Record;
+  
+  // Read all the records for this value table.
+  SmallString<128> ValueName;
+  while (1) {
+unsigned Code = Stream.ReadCode();
+if (Code == bitc::END_BLOCK)
+  return Stream.ReadBlockEnd();
+
+if (Code == bitc::ENTER_SUBBLOCK) {
+  // No known subblocks, always skip them.
+  Stream.ReadSubBlockID();
+  if (Stream.SkipBlock())
+return Error("Malformed block record");
+  continue;
+}
+
+if (Code == bitc::DEFINE_ABBREV) {
+  Stream.ReadAbbrevRecord();
+  continue;
+}
+
+// Read a record.
+Record.clear();
+switch (Stream.ReadRecord(Code, Record)) {
+default:  // Default behavior: unknown type.
+  break;
+case bitc::VST_ENTRY_CODE:// VST_ENTRY: [valueid, namelen, namechar x 
N]
+  if (ConvertToString(Record, 1, ValueName))
+return Error("Invalid TST_ENTRY record");
+  unsigned ValueID = Record[0];
+  if (ValueID >= ValueList.size())
+return Error("Invalid Value ID in VST_ENTRY record");
+  Value *V = ValueList[ValueID];
+  
+  V->setName(&ValueName[0], ValueName.size());
+  ValueName.clear();
+  break;
+}
+  }
+}
+
 
 bool BitcodeReader::ParseModule(BitstreamReader &Stream,
 const std::string &ModuleID) {
@@ -291,6 +339,10 @@
 if (ParseTypeSymbolTable(Stream))
   return true;
 break;
+  case bitc::VALUE_SYMTAB_BLOCK_ID:
+if (ParseValueSymbolTable(Stream))
+  return true;
+break;
   }
   continue;
 }
@@ -377,7 +429,8 @@
   NewGV->setVisibility(Visibility);
   NewGV->setThreadLocal(isThreadLocal);
   
-  // TODO: Add to value table.
+  ValueList.push_back(NewGV);
+  
   // TODO: remember initializer/global pair for later substitution.
   break;
 }
@@ -407,7 +460,7 @@
   }
   Func->setVisibility(GetDecodedVisibility(Record[6]));
   
-  // TODO: Add to value table.
+  ValueList.push_back(Func);
   // TODO: remember initializer/global pair for later substitution.
   break;
 }


Index: llvm/lib/Bitcode/Reader/BitcodeReader.h
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.h:1.3 
llvm/lib/Bitcode/Reader/BitcodeReader.h:1.4
--- llvm/lib/Bitcode/Reader/BitcodeReader.h:1.3 Sun Apr 22 20:01:37 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.h Mon Apr 23 16:26:05 2007
@@ -21,11 +21,13 @@
 
 namespace llvm {
   class BitstreamReader;
+  class Value;
 
 class BitcodeReader : public ModuleProvider {
   const char *ErrorString;
   
   std::vector TypeList;
+  std::vector ValueList;
 public:
   virtual ~BitcodeReader() {}
   
@@ -59,6 +61,7 @@
   bool ParseModule(BitstreamReader &Stream, const std::string &ModuleID);
   bool ParseTypeTable(BitstreamReader &Stream);
   bool ParseTypeSymbolTable(BitstreamReader &Stream);
+  bool ParseValueSymbolTable(BitstreamReader &Stream);
 };
   
 } // End llvm namespace



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-04-23 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.2 -> 1.3
---
Log message:

implement reading of abbrevs, and writing of abbreviated global varrs.


---
Diffs of the changes:  (+6 -3)

 BitcodeReader.cpp |9 ++---
 1 files changed, 6 insertions(+), 3 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.2 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.3
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.2   Mon Apr 23 11:04:05 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Mon Apr 23 13:58:34 2007
@@ -94,7 +94,8 @@
 }
 
 if (Code == bitc::DEFINE_ABBREV) {
-  assert(0 && "Abbrevs not implemented yet!");
+  Stream.ReadAbbrevRecord();
+  continue;
 }
 
 // Read a record.
@@ -231,7 +232,8 @@
 }
 
 if (Code == bitc::DEFINE_ABBREV) {
-  assert(0 && "Abbrevs not implemented yet!");
+  Stream.ReadAbbrevRecord();
+  continue;
 }
 
 // Read a record.
@@ -294,7 +296,8 @@
 }
 
 if (Code == bitc::DEFINE_ABBREV) {
-  assert(0 && "Abbrevs not implemented yet!");
+  Stream.ReadAbbrevRecord();
+  continue;
 }
 
 // Read a record.



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

2007-04-23 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.1 -> 1.2
---
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:  (+8 -6)

 BitcodeReader.cpp |   14 --
 1 files changed, 8 insertions(+), 6 deletions(-)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.1 
llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.2
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.1   Sun Apr 22 01:23:29 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Mon Apr 23 11:04:05 2007
@@ -93,7 +93,7 @@
   continue;
 }
 
-if (Code == bitc::DEFINE_ABBREVS) {
+if (Code == bitc::DEFINE_ABBREV) {
   assert(0 && "Abbrevs not implemented yet!");
 }
 
@@ -230,7 +230,7 @@
   continue;
 }
 
-if (Code == bitc::DEFINE_ABBREVS) {
+if (Code == bitc::DEFINE_ABBREV) {
   assert(0 && "Abbrevs not implemented yet!");
 }
 
@@ -293,7 +293,7 @@
   continue;
 }
 
-if (Code == bitc::DEFINE_ABBREVS) {
+if (Code == bitc::DEFINE_ABBREV) {
   assert(0 && "Abbrevs not implemented yet!");
 }
 
@@ -345,7 +345,7 @@
 // GLOBALVAR: [type, isconst, initid, 
 // linkage, alignment, section, visibility, threadlocal]
 case bitc::MODULE_CODE_GLOBALVAR: {
-  if (Record.size() < 8)
+  if (Record.size() < 6)
 return Error("Invalid MODULE_CODE_GLOBALVAR record");
   const Type *Ty = getTypeByID(Record[0]);
   if (!isa(Ty))
@@ -361,8 +361,10 @@
   return Error("Invalid section ID");
 Section = SectionTable[Record[5]-1];
   }
-  GlobalValue::VisibilityTypes Visibility = 
GetDecodedVisibility(Record[6]);
-  bool isThreadLocal = Record[7];
+  GlobalValue::VisibilityTypes Visibility = GlobalValue::DefaultVisibility;
+  if (Record.size() >= 6) Visibility = GetDecodedVisibility(Record[6]);
+  bool isThreadLocal = false;
+  if (Record.size() >= 7) isThreadLocal = Record[7];
 
   GlobalVariable *NewGV =
 new GlobalVariable(Ty, isConstant, Linkage, 0, "", TheModule);



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


[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h Makefile ReaderWrappers.cpp

2007-04-21 Thread Chris Lattner


Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp added (r1.1)
BitcodeReader.h added (r1.1)
Makefile added (r1.1)
ReaderWrappers.cpp added (r1.1)
---
Log message:

Initial support for reading bitcode files.  They currently only read types,
the type symtab, and global/function protos, and are missing the important
size optimization, but it is a place to start.


---
Diffs of the changes:  (+633 -0)

 BitcodeReader.cpp  |  455 +
 BitcodeReader.h|   66 +++
 Makefile   |   15 +
 ReaderWrappers.cpp |   97 +++
 4 files changed, 633 insertions(+)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -c /dev/null llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.1
*** /dev/null   Sun Apr 22 01:23:39 2007
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp   Sun Apr 22 01:23:29 2007
***
*** 0 
--- 1,455 
+ //===- BitcodeReader.cpp - Internal BitcodeReader implementation 
--===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by Chris Lattner and is distributed under
+ // the University of Illinois Open Source License.  See LICENSE.TXT for 
details.
+ //
+ 
//===--===//
+ //
+ // This header defines the BitcodeReader class.
+ //
+ 
//===--===//
+ 
+ #include "BitcodeReader.h"
+ #include "llvm/Bitcode/BitstreamReader.h"
+ #include "llvm/DerivedTypes.h"
+ #include "llvm/Module.h"
+ using namespace llvm;
+ 
+ /// ConvertToString - Convert a string from a record into an std::string, 
return
+ /// true on failure.
+ static bool ConvertToString(SmallVector &Record, unsigned Idx,
+ std::string &Result) {
+   if (Record.size() < Idx+1 || Record.size() < Record[Idx]+Idx+1)
+ return true;
+   
+   for (unsigned i = 0, e = Record[Idx]; i != e; ++i)
+ Result += (char)Record[Idx+i+1];
+   return false;
+ }
+ 
+ static GlobalValue::LinkageTypes GetDecodedLinkage(unsigned Val) {
+   switch (Val) {
+   default: // Map unknown/new linkages to external
+   case 0: return GlobalValue::ExternalLinkage;
+   case 1: return GlobalValue::WeakLinkage;
+   case 2: return GlobalValue::AppendingLinkage;
+   case 3: return GlobalValue::InternalLinkage;
+   case 4: return GlobalValue::LinkOnceLinkage;
+   case 5: return GlobalValue::DLLImportLinkage;
+   case 6: return GlobalValue::DLLExportLinkage;
+   case 7: return GlobalValue::ExternalWeakLinkage;
+   }
+ }
+ 
+ static GlobalValue::VisibilityTypes GetDecodedVisibility(unsigned Val) {
+   switch (Val) {
+   default: // Map unknown visibilities to default.
+   case 0: return GlobalValue::DefaultVisibility;
+   case 1: return GlobalValue::HiddenVisibility;
+   }
+ }
+ 
+ 
+ const Type *BitcodeReader::getTypeByID(unsigned ID, bool isTypeTable) {
+   // If the TypeID is in range, return it.
+   if (ID < TypeList.size())
+ return TypeList[ID].get();
+   if (!isTypeTable) return 0;
+   
+   // The type table allows forward references.  Push as many Opaque types as
+   // needed to get up to ID.
+   while (TypeList.size() <= ID)
+ TypeList.push_back(OpaqueType::get());
+   return TypeList.back().get();
+ }
+ 
+ 
+ bool BitcodeReader::ParseTypeTable(BitstreamReader &Stream) {
+   if (Stream.EnterSubBlock())
+ return Error("Malformed block record");
+   
+   if (!TypeList.empty())
+ return Error("Multiple TYPE_BLOCKs found!");
+ 
+   SmallVector Record;
+   unsigned NumRecords = 0;
+ 
+   // Read all the records for this type table.
+   while (1) {
+ unsigned Code = Stream.ReadCode();
+ if (Code == bitc::END_BLOCK) {
+   if (NumRecords != TypeList.size())
+ return Error("Invalid type forward reference in TYPE_BLOCK");
+   return Stream.ReadBlockEnd();
+ }
+ 
+ if (Code == bitc::ENTER_SUBBLOCK) {
+   // No known subblocks, always skip them.
+   Stream.ReadSubBlockID();
+   if (Stream.SkipBlock())
+ return Error("Malformed block record");
+   continue;
+ }
+ 
+ if (Code == bitc::DEFINE_ABBREVS) {
+   assert(0 && "Abbrevs not implemented yet!");
+ }
+ 
+ // Read a record.
+ Record.clear();
+ const Type *ResultTy = 0;
+ switch (Stream.ReadRecord(Code, Record)) {
+ default:  // Default behavior: unknown type.
+   ResultTy = 0;
+   break;
+ case bitc::TYPE_CODE_NUMENTRY: // TYPE_CODE_NUMENTRY: [numentries]
+   // TYPE_CODE_NUMENTRY contains a count of the number of types in the
+   // type list.  This allows us to reserve space.
+   if (Record.size() < 1)
+ return Error("Invalid TYPE_CODE_NUMENTRY record");
+   TypeList.reserve(Record[0]);
+   continue;
+ case bitc::TYPE_CODE_META:  // TYPE_CODE_META: [metacode]...
+   // No metadata supported yet.
+   if (Record.size() < 1)
+ return Error("Invalid T