Quick compiler - NOT_LONG and verification fixes
We continue to have issues when the verifier rewrites Dalvik
byte codes. This is a workaround to fix the GBC -> LIR
conversion, but I suspect I'm going to have to add a dead code
elimination pass to get things working properly for llvm. The
basic problem is that if the re-written instruction defined a
Dalvik virtual register, then we lose the definition. The
MIR to GBC converter doesn't handle uses without definitions
very well.
Change-Id: Ia235c299b686ce080755f9bb4c05c719c16c0d77
diff --git a/src/compiler/codegen/MethodBitcode.cc b/src/compiler/codegen/MethodBitcode.cc
index 3ec4a11..79501a4 100644
--- a/src/compiler/codegen/MethodBitcode.cc
+++ b/src/compiler/codegen/MethodBitcode.cc
@@ -49,7 +49,11 @@
void defineValue(CompilationUnit* cUnit, llvm::Value* val, int sReg)
{
llvm::Value* placeholder = getLLVMValue(cUnit, sReg);
- CHECK(placeholder != NULL) << "Null placeholder - shouldn't happen";
+ if (placeholder == NULL) {
+ // This can happen on instruction rewrite on verification failure
+ LOG(WARNING) << "Null placeholder - invalid CFG";
+ return;
+ }
placeholder->replaceAllUsesWith(val);
val->takeName(placeholder);
cUnit->llvmValues.elemList[sReg] = (intptr_t)val;
@@ -1299,7 +1303,13 @@
case Instruction::MOVE_RESULT:
case Instruction::MOVE_RESULT_OBJECT:
#if defined(TARGET_ARM)
- CHECK(false) << "Unexpected MOVE_RESULT";
+ /*
+ * Instruction rewriting on verification failure can eliminate
+ * the invoke that feeds this move0result. It won't ever be reached,
+ * so we can ignore it.
+ * TODO: verify that previous instruction if THROW_VERIFICATION_ERROR
+ */
+ UNIMPLEMENTED(WARNING) << "Need to verify previous inst was rewritten";
#else
UNIMPLEMENTED(WARNING) << "need x86 move-result fusing";
#endif
@@ -2262,12 +2272,19 @@
DCHECK(lhsImm == NULL);
RegLocation rlSrc1 = getLoc(cUnit, inst->getOperand(0));
llvm::Value* rhs = inst->getOperand(1);
- if (llvm::ConstantInt* src2 = llvm::dyn_cast<llvm::ConstantInt>(rhs)) {
+ llvm::ConstantInt* constRhs = llvm::dyn_cast<llvm::ConstantInt>(rhs);
+ if (!rlDest.wide && (constRhs != NULL)) {
Instruction::Code dalvikOp = getDalvikOpcode(op, true, false);
- genArithOpIntLit(cUnit, dalvikOp, rlDest, rlSrc1, src2->getSExtValue());
+ genArithOpIntLit(cUnit, dalvikOp, rlDest, rlSrc1, constRhs->getSExtValue());
} else {
Instruction::Code dalvikOp = getDalvikOpcode(op, false, rlDest.wide);
- RegLocation rlSrc2 = getLoc(cUnit, rhs);
+ RegLocation rlSrc2;
+ if (constRhs != NULL) {
+ DCHECK_EQ(dalvikOp, Instruction::NOT_LONG);
+ rlSrc2 = rlSrc1;
+ } else {
+ rlSrc2 = getLoc(cUnit, rhs);
+ }
if (rlDest.wide) {
genArithOpLong(cUnit, dalvikOp, rlDest, rlSrc1, rlSrc2);
} else {