llvm.org GIT mirror llvm / 231cbcb
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 } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36640 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
1 changed file(s) with 38 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
10051005 ValueList.push_back(I);
10061006
10071007 unsigned NextValueNo = ValueList.size();
1008
1008 BasicBlock *CurBB = 0;
1009 unsigned CurBBNo = 0;
1010
10091011 // Read all the records.
10101012 SmallVector Record;
10111013 while (1) {
10411043 // Read a record.
10421044 Record.clear();
10431045 Instruction *I = 0;
1044 BasicBlock *CurBB = 0;
1045 unsigned CurBBNo = 0;
10461046 switch (Stream.ReadRecord(Code, Record)) {
10471047 default: // Default behavior: reject
10481048 return Error("Unknown instruction");
10561056 CurBB = FunctionBBs[0];
10571057 continue;
10581058
1059 case bitc::FUNC_CODE_INST_BINOP: {
1060 // BINOP: [opcode, ty, opval, opval]
1059 case bitc::FUNC_CODE_INST_BINOP: { // BINOP: [opcode, ty, opval, opval]
10611060 if (Record.size() < 4) return Error("Invalid BINOP record");
10621061 const Type *Ty = getTypeByID(Record[1]);
10631062 int Opc = GetDecodedBinaryOpcode(Record[0], Ty);
10681067 I = BinaryOperator::create((Instruction::BinaryOps)Opc, LHS, RHS);
10691068 break;
10701069 }
1070 case bitc::FUNC_CODE_INST_CAST: { // CAST: [opcode, ty, opty, opval]
1071 if (Record.size() < 4) return Error("Invalid CAST record");
1072 int Opc = GetDecodedCastOpcode(Record[0]);
1073 const Type *ResTy = getTypeByID(Record[1]);
1074 const Type *OpTy = getTypeByID(Record[2]);
1075 Value *Op = getFnValueByID(Record[3], OpTy);
1076 if (Opc == -1 || ResTy == 0 || OpTy == 0 || Op == 0)
1077 return Error("Invalid CAST record");
1078 I = CastInst::create((Instruction::CastOps)Opc, Op, ResTy);
1079 break;
1080 }
10711081 #if 0
1072 case bitc::FUNC_CODE_INST_CAST:
1073 // CAST: [opcode, ty, opty, opval]
10741082 case bitc::FUNC_CODE_INST_GEP:
10751083 // GEP: [n, n x operands]
10761084 case bitc::FUNC_CODE_INST_SELECT:
10831091 // SHUFFLEVEC: [ty, opval, opval, opval]
10841092 case bitc::FUNC_CODE_INST_CMP:
10851093 // CMP: [opty, opval, opval, pred]
1086
1087 case bitc::FUNC_CODE_INST_RET:
1088 // RET: [opty,opval]
1094 #endif
1095
1096 case bitc::FUNC_CODE_INST_RET: // RET: [opty,opval]
1097 if (Record.size() == 0) {
1098 I = new ReturnInst();
1099 break;
1100 }
1101 if (Record.size() == 2) {
1102 const Type *OpTy = getTypeByID(Record[0]);
1103 Value *Op = getFnValueByID(Record[1], OpTy);
1104 if (OpTy && Op);
1105 I = new ReturnInst(Op);
1106 break;
1107 }
1108 return Error("Invalid RET record");
1109 #if 0
10891110 case bitc::FUNC_CODE_INST_BR:
10901111 // BR: [opval, bb#, bb#] or [bb#]
10911112 case bitc::FUNC_CODE_INST_SWITCH:
10921113 // SWITCH: [opty, opval, n, n x ops]
10931114 case bitc::FUNC_CODE_INST_INVOKE:
10941115 // INVOKE: [fnty, op0,op1,op2, ...]
1095 case bitc::FUNC_CODE_INST_UNWIND:
1096 // UNWIND
1097 case bitc::FUNC_CODE_INST_UNREACHABLE:
1098 // UNREACHABLE
1099
1116 case bitc::FUNC_CODE_INST_UNWIND: // UNWIND
1117 I = new UnwindInst();
1118 break;
1119 case bitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE
1120 I = new UnreachableInst();
1121 break;
1122
11001123 case bitc::FUNC_CODE_INST_PHI:
11011124 // PHI: [ty, #ops, val0,bb0, ...]
11021125 case bitc::FUNC_CODE_INST_MALLOC: