Implement Div/Rem/fptosi.

Change-Id: I90be4c1139a9f11ad2378a293e5c243e57843bd9
diff --git a/src/compiler/codegen/MethodBitcode.cc b/src/compiler/codegen/MethodBitcode.cc
index a034b6b..055a99d 100644
--- a/src/compiler/codegen/MethodBitcode.cc
+++ b/src/compiler/codegen/MethodBitcode.cc
@@ -794,11 +794,13 @@
   defineValue(cUnit, res, rlDest.origSReg);
 }
 
-void convertFPToInt(CompilationUnit* cUnit, llvm::Type* ty, RegLocation rlDest,
+void convertFPToInt(CompilationUnit* cUnit,
+                    greenland::IntrinsicHelper::IntrinsicId id,
+                    RegLocation rlDest,
                     RegLocation rlSrc)
 {
-  llvm::Value* res =
-      cUnit->irb->CreateFPToSI(getLLVMValue(cUnit, rlSrc.origSReg), ty);
+  llvm::Function* intr = cUnit->intrinsic_helper->GetIntrinsicFunction(id);
+  llvm::Value* res = cUnit->irb->CreateCall(intr, getLLVMValue(cUnit, rlSrc.origSReg));
   defineValue(cUnit, res, rlDest.origSReg);
 }
 
@@ -1592,13 +1594,19 @@
       break;
 
     case Instruction::FLOAT_TO_INT:
+      convertFPToInt(cUnit, greenland::IntrinsicHelper::F2I, rlDest, rlSrc[0]);
+      break;
+
     case Instruction::DOUBLE_TO_INT:
-      convertFPToInt(cUnit, cUnit->irb->getInt32Ty(), rlDest, rlSrc[0]);
+      convertFPToInt(cUnit, greenland::IntrinsicHelper::D2I, rlDest, rlSrc[0]);
       break;
 
     case Instruction::FLOAT_TO_LONG:
+      convertFPToInt(cUnit, greenland::IntrinsicHelper::F2L, rlDest, rlSrc[0]);
+      break;
+
     case Instruction::DOUBLE_TO_LONG:
-      convertFPToInt(cUnit, cUnit->irb->getInt64Ty(), rlDest, rlSrc[0]);
+      convertFPToInt(cUnit, greenland::IntrinsicHelper::D2L, rlDest, rlSrc[0]);
       break;
 
     case Instruction::CMPL_FLOAT:
@@ -2282,10 +2290,10 @@
   genConversion(cUnit, opcode, rlDest, rlSrc);
 }
 
-void cvtFPToInt(CompilationUnit* cUnit, llvm::Instruction* inst)
+void cvtFPToInt(CompilationUnit* cUnit, llvm::CallInst* call_inst)
 {
-  RegLocation rlDest = getLoc(cUnit, inst);
-  RegLocation rlSrc = getLoc(cUnit, inst->getOperand(0));
+  RegLocation rlDest = getLoc(cUnit, call_inst);
+  RegLocation rlSrc = getLoc(cUnit, call_inst->getOperand(0));
   Instruction::Code opcode;
   if (rlDest.wide) {
     if (rlSrc.wide) {
@@ -3198,6 +3206,13 @@
                 cvtIntNarrowing(cUnit, callInst, Instruction::INT_TO_BYTE);
                 break;
 
+              case greenland::IntrinsicHelper::F2I:
+              case greenland::IntrinsicHelper::D2I:
+              case greenland::IntrinsicHelper::F2L:
+              case greenland::IntrinsicHelper::D2L:
+                cvtFPToInt(cUnit, callInst);
+                break;
+
               case greenland::IntrinsicHelper::CmplFloat:
                 cvtFPCompare(cUnit, callInst, Instruction::CMPL_FLOAT);
                 break;
@@ -3278,7 +3293,6 @@
         case llvm::Instruction::FDiv: cvtBinFPOp(cUnit, kOpDiv, inst); break;
         case llvm::Instruction::FRem: cvtBinFPOp(cUnit, kOpRem, inst); break;
         case llvm::Instruction::SIToFP: cvtIntToFP(cUnit, inst); break;
-        case llvm::Instruction::FPToSI: cvtFPToInt(cUnit, inst); break;
         case llvm::Instruction::FPTrunc: cvtDoubleToFloat(cUnit, inst); break;
         case llvm::Instruction::FPExt: cvtFloatToDouble(cUnit, inst); break;
         case llvm::Instruction::Trunc: cvtTrunc(cUnit, inst); break;
@@ -3298,6 +3312,7 @@
         case llvm::Instruction::AShr:
         case llvm::Instruction::Invoke:
         case llvm::Instruction::FPToUI:
+        case llvm::Instruction::FPToSI:
         case llvm::Instruction::UIToFP:
         case llvm::Instruction::PtrToInt:
         case llvm::Instruction::IntToPtr:
diff --git a/src/compiler_llvm/gbc_expander.cc b/src/compiler_llvm/gbc_expander.cc
index 8baa58f..672014c 100644
--- a/src/compiler_llvm/gbc_expander.cc
+++ b/src/compiler_llvm/gbc_expander.cc
@@ -197,8 +197,7 @@
 
   llvm::Value* Expand_Invoke(llvm::CallInst& call_inst);
 
-  llvm::Value* Expand_DivRem(llvm::Value* dividend, llvm::Value* divisor,
-                             bool is_div, JType op_jty);
+  llvm::Value* Expand_DivRem(llvm::CallInst& call_inst, bool is_div, JType op_jty);
 
   void Expand_AllocaShadowFrame(llvm::Value* num_entry_value);
 
@@ -944,9 +943,14 @@
   return retval;
 }
 
-llvm::Value* GBCExpanderPass::Expand_DivRem(llvm::Value* dividend,
-                                            llvm::Value* divisor,
+llvm::Value* GBCExpanderPass::Expand_DivRem(llvm::CallInst& call_inst,
                                             bool is_div, JType op_jty) {
+  llvm::Value* dividend = call_inst.getArgOperand(0);
+  llvm::Value* divisor = call_inst.getArgOperand(1);
+#if defined(ART_USE_QUICK_COMPILER)
+  uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
+  EmitGuard_DivZeroException(dex_pc, divisor, op_jty);
+#endif
   // Most of the codes refer to MethodCompiler::EmitIntDivRemResultComputation
 
   // Check the special case: MININT / -1 = MININT
@@ -3241,24 +3245,16 @@
 
     //==- Math -------------------------------------------------------------==//
     case IntrinsicHelper::DivInt: {
-      return Expand_DivRem(call_inst.getArgOperand(0),
-                           call_inst.getArgOperand(1),
-                           /* is_div */true, kInt);
+      return Expand_DivRem(call_inst, /* is_div */true, kInt);
     }
     case IntrinsicHelper::RemInt: {
-      return Expand_DivRem(call_inst.getArgOperand(0),
-                           call_inst.getArgOperand(1),
-                           /* is_div */false, kInt);
+      return Expand_DivRem(call_inst, /* is_div */false, kInt);
     }
     case IntrinsicHelper::DivLong: {
-      return Expand_DivRem(call_inst.getArgOperand(0),
-                           call_inst.getArgOperand(1),
-                           /* is_div */true, kLong);
+      return Expand_DivRem(call_inst, /* is_div */true, kLong);
     }
     case IntrinsicHelper::RemLong: {
-      return Expand_DivRem(call_inst.getArgOperand(0),
-                           call_inst.getArgOperand(1),
-                           /* is_div */false, kLong);
+      return Expand_DivRem(call_inst, /* is_div */false, kLong);
     }
     case IntrinsicHelper::D2L: {
       return ExpandToRuntime(runtime_support::art_d2l, call_inst);