mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 06:29:05 +00:00
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
This commit is contained in:
@@ -1006,6 +1006,8 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
|
|||||||
ValueList.push_back(I);
|
ValueList.push_back(I);
|
||||||
|
|
||||||
unsigned NextValueNo = ValueList.size();
|
unsigned NextValueNo = ValueList.size();
|
||||||
|
BasicBlock *CurBB = 0;
|
||||||
|
unsigned CurBBNo = 0;
|
||||||
|
|
||||||
// Read all the records.
|
// Read all the records.
|
||||||
SmallVector<uint64_t, 64> Record;
|
SmallVector<uint64_t, 64> Record;
|
||||||
@@ -1042,8 +1044,6 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
|
|||||||
// Read a record.
|
// Read a record.
|
||||||
Record.clear();
|
Record.clear();
|
||||||
Instruction *I = 0;
|
Instruction *I = 0;
|
||||||
BasicBlock *CurBB = 0;
|
|
||||||
unsigned CurBBNo = 0;
|
|
||||||
switch (Stream.ReadRecord(Code, Record)) {
|
switch (Stream.ReadRecord(Code, Record)) {
|
||||||
default: // Default behavior: reject
|
default: // Default behavior: reject
|
||||||
return Error("Unknown instruction");
|
return Error("Unknown instruction");
|
||||||
@@ -1057,8 +1057,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
|
|||||||
CurBB = FunctionBBs[0];
|
CurBB = FunctionBBs[0];
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case bitc::FUNC_CODE_INST_BINOP: {
|
case bitc::FUNC_CODE_INST_BINOP: { // BINOP: [opcode, ty, opval, opval]
|
||||||
// BINOP: [opcode, ty, opval, opval]
|
|
||||||
if (Record.size() < 4) return Error("Invalid BINOP record");
|
if (Record.size() < 4) return Error("Invalid BINOP record");
|
||||||
const Type *Ty = getTypeByID(Record[1]);
|
const Type *Ty = getTypeByID(Record[1]);
|
||||||
int Opc = GetDecodedBinaryOpcode(Record[0], Ty);
|
int Opc = GetDecodedBinaryOpcode(Record[0], Ty);
|
||||||
@@ -1069,9 +1068,18 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
|
|||||||
I = BinaryOperator::create((Instruction::BinaryOps)Opc, LHS, RHS);
|
I = BinaryOperator::create((Instruction::BinaryOps)Opc, LHS, RHS);
|
||||||
break;
|
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
|
#if 0
|
||||||
case bitc::FUNC_CODE_INST_CAST:
|
|
||||||
// CAST: [opcode, ty, opty, opval]
|
|
||||||
case bitc::FUNC_CODE_INST_GEP:
|
case bitc::FUNC_CODE_INST_GEP:
|
||||||
// GEP: [n, n x operands]
|
// GEP: [n, n x operands]
|
||||||
case bitc::FUNC_CODE_INST_SELECT:
|
case bitc::FUNC_CODE_INST_SELECT:
|
||||||
@@ -1084,19 +1092,34 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
|
|||||||
// SHUFFLEVEC: [ty, opval, opval, opval]
|
// SHUFFLEVEC: [ty, opval, opval, opval]
|
||||||
case bitc::FUNC_CODE_INST_CMP:
|
case bitc::FUNC_CODE_INST_CMP:
|
||||||
// CMP: [opty, opval, opval, pred]
|
// CMP: [opty, opval, opval, pred]
|
||||||
|
#endif
|
||||||
|
|
||||||
case bitc::FUNC_CODE_INST_RET:
|
case bitc::FUNC_CODE_INST_RET: // RET: [opty,opval<optional>]
|
||||||
// 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:
|
case bitc::FUNC_CODE_INST_BR:
|
||||||
// BR: [opval, bb#, bb#] or [bb#]
|
// BR: [opval, bb#, bb#] or [bb#]
|
||||||
case bitc::FUNC_CODE_INST_SWITCH:
|
case bitc::FUNC_CODE_INST_SWITCH:
|
||||||
// SWITCH: [opty, opval, n, n x ops]
|
// SWITCH: [opty, opval, n, n x ops]
|
||||||
case bitc::FUNC_CODE_INST_INVOKE:
|
case bitc::FUNC_CODE_INST_INVOKE:
|
||||||
// INVOKE: [fnty, op0,op1,op2, ...]
|
// INVOKE: [fnty, op0,op1,op2, ...]
|
||||||
case bitc::FUNC_CODE_INST_UNWIND:
|
case bitc::FUNC_CODE_INST_UNWIND: // UNWIND
|
||||||
// UNWIND
|
I = new UnwindInst();
|
||||||
case bitc::FUNC_CODE_INST_UNREACHABLE:
|
break;
|
||||||
// UNREACHABLE
|
case bitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE
|
||||||
|
I = new UnreachableInst();
|
||||||
|
break;
|
||||||
|
|
||||||
case bitc::FUNC_CODE_INST_PHI:
|
case bitc::FUNC_CODE_INST_PHI:
|
||||||
// PHI: [ty, #ops, val0,bb0, ...]
|
// PHI: [ty, #ops, val0,bb0, ...]
|
||||||
|
Reference in New Issue
Block a user