[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Chris Lattner
sabre at nondot.org
Tue May 1 21:27:44 PDT 2007
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<uint64_t, 64> 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<optional>]
+#endif
+
+ case bitc::FUNC_CODE_INST_RET: // RET: [opty,opval<optional>]
+ 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:
More information about the llvm-commits
mailing list