Integrating portable path with the Frontend.

(1) Connect the new interface oatCompileMethodToGBC and gbc_expander.
(2) Need to fix Android.common.mk for fly2iceland: Portable path has
    frontend: USE_QUICK_COMPILER and backend: USE_LLVM_COMPILER.
(3) Fix Android.libart-compiler-llvm.mk so we can call the new interface.

Change-Id: I7216f378bdb5e42a35fd6fa10c1d5d161a912401
diff --git a/build/Android.common.mk b/build/Android.common.mk
index e2152df..f031562 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -61,11 +61,7 @@
 ifeq ($(words $(filter true,$(ART_USE_LLVM_COMPILER) $(ART_USE_GREENLAND_COMPILER) $(ART_USE_QUICK_COMPILER))),0)
 ART_REQUIRE_LLVM := false
 else #!0
-ifeq ($(words $(filter true,$(ART_USE_LLVM_COMPILER) $(ART_USE_GREENLAND_COMPILER) $(ART_USE_QUICK_COMPILER))),1)
 ART_REQUIRE_LLVM := true
-else #!1
-$(error Cannot enable combinations of art-greenland, art-llvm, and art-quick compiler simultaneously!)
-endif #!1
 endif #!0
 
 ifeq ($(ART_REQUIRE_LLVM),true)
diff --git a/build/Android.libart-compiler-llvm.mk b/build/Android.libart-compiler-llvm.mk
index f39b3ea..79665e5 100644
--- a/build/Android.libart-compiler-llvm.mk
+++ b/build/Android.libart-compiler-llvm.mk
@@ -15,9 +15,12 @@
 #
 
 
-LIBART_COMPILER_LLVM_CFLAGS := -DART_USE_LLVM_COMPILER=1
+LIBART_COMPILER_LLVM_CFLAGS := -DART_USE_LLVM_COMPILER
 ifeq ($(ART_USE_DEXLANG_FRONTEND),true)
-  LIBART_COMPILER_LLVM_CFLAGS += -DART_USE_DEXLANG_FRONTEND=1
+  LIBART_COMPILER_LLVM_CFLAGS += -DART_USE_DEXLANG_FRONTEND
+endif
+ifeq ($(ART_USE_QUICK_COMPILER),true)
+  LIBART_COMPILER_LLVM_CFLAGS += -DART_USE_QUICK_COMPILER
 endif
 
 LIBART_COMPILER_LLVM_SRC_FILES += \
@@ -43,9 +46,31 @@
     src/greenland/intrinsic_helper.cc \
     src/greenland/ir_builder.cc
 else
-  LIBART_COMPILER_LLVM_SRC_FILES += \
-	  src/compiler_llvm/dalvik_reg.cc \
-	  src/compiler_llvm/method_compiler.cc
+  ifeq ($(ART_USE_QUICK_COMPILER),true)
+    LIBART_COMPILER_LLVM_SRC_FILES += \
+      src/compiler/Dataflow.cc \
+      src/compiler/Frontend.cc \
+      src/compiler/IntermediateRep.cc \
+      src/compiler/Ralloc.cc \
+      src/compiler/SSATransformation.cc \
+      src/compiler/Utility.cc \
+      src/compiler/codegen/RallocUtil.cc \
+      src/compiler/codegen/arm/ArchUtility.cc \
+      src/compiler/codegen/arm/ArmRallocUtil.cc \
+      src/compiler/codegen/arm/Assemble.cc \
+      src/compiler/codegen/arm/armv7-a/Codegen.cc \
+      src/compiler_llvm/dalvik_reg.cc \
+      src/compiler_llvm/gbc_expander.cc \
+      src/compiler_llvm/method_compiler.cc \
+      src/greenland/dalvik_reg.cc \
+      src/greenland/dex_lang.cc \
+      src/greenland/intrinsic_helper.cc \
+      src/greenland/ir_builder.cc
+  else
+    LIBART_COMPILER_LLVM_SRC_FILES += \
+      src/compiler_llvm/dalvik_reg.cc \
+      src/compiler_llvm/method_compiler.cc
+  endif
 endif
 
 # $(1): target or host
diff --git a/src/compiler_llvm/compilation_unit.cc b/src/compiler_llvm/compilation_unit.cc
index b5ff67c..eaa8be1 100644
--- a/src/compiler_llvm/compilation_unit.cc
+++ b/src/compiler_llvm/compilation_unit.cc
@@ -150,10 +150,14 @@
 namespace art {
 namespace compiler_llvm {
 
-#ifdef ART_USE_DEXLANG_FRONTEND
+#if defined(ART_USE_DEXLANG_FRONTEND) || defined(ART_USE_QUICK_COMPILER)
 llvm::FunctionPass*
 CreateGBCExpanderPass(const greenland::IntrinsicHelper& intrinsic_helper,
                       IRBuilder& irb);
+
+llvm::FunctionPass*
+CreateGBCExpanderPass(const greenland::IntrinsicHelper& intrinsic_helper, IRBuilder& irb,
+                      Compiler* compiler, OatCompilationUnit* oat_compilation_unit);
 #endif
 
 llvm::Module* makeLLVMModuleContents(llvm::Module* module);
@@ -168,9 +172,13 @@
   module_ = new llvm::Module("art", *context_);
   makeLLVMModuleContents(module_);
 
-#ifdef ART_USE_DEXLANG_FRONTEND
+#if defined(ART_USE_DEXLANG_FRONTEND) || defined(ART_USE_QUICK_COMPILER)
   dex_lang_ctx_ = new greenland::DexLang::Context(*module_);
 #endif
+#if defined(ART_USE_QUICK_COMPILER)
+  compiler_ = NULL;
+  oat_compilation_unit_ = NULL;
+#endif
 
   // Create IRBuilder
   irb_.reset(new IRBuilder(*context_, *module_));
@@ -196,7 +204,7 @@
 
 
 CompilationUnit::~CompilationUnit() {
-#ifdef ART_USE_DEXLANG_FRONTEND
+#if defined(ART_USE_DEXLANG_FRONTEND) || defined(ART_USE_QUICK_COMPILER)
   delete dex_lang_ctx_;
 #endif
 }
@@ -316,15 +324,21 @@
   if (bitcode_filename_.empty()) {
     // If we don't need write the bitcode to file, add the AddSuspendCheckToLoopLatchPass to the
     // regular FunctionPass.
-#ifdef ART_USE_DEXLANG_FRONTEND
+#if defined(ART_USE_DEXLANG_FRONTEND)
     fpm.add(CreateGBCExpanderPass(dex_lang_ctx_->GetIntrinsicHelper(), *irb_.get()));
+#elif defined(ART_USE_QUICK_COMPILER)
+    fpm.add(CreateGBCExpanderPass(dex_lang_ctx_->GetIntrinsicHelper(), *irb_.get(),
+                                  compiler_, oat_compilation_unit_));
 #endif
     fpm.add(new ::AddSuspendCheckToLoopLatchPass(irb_.get()));
   } else {
     // Run AddSuspendCheckToLoopLatchPass before we write the bitcode to file.
     llvm::FunctionPassManager fpm2(module_);
-#ifdef ART_USE_DEXLANG_FRONTEND
+#if defined(ART_USE_DEXLANG_FRONTEND)
     fpm2.add(CreateGBCExpanderPass(dex_lang_ctx_->GetIntrinsicHelper(), *irb_.get()));
+#elif defined(ART_USE_QUICK_COMPILER)
+    fpm2.add(CreateGBCExpanderPass(dex_lang_ctx_->GetIntrinsicHelper(), *irb_.get(),
+                                   compiler_, oat_compilation_unit_));
 #endif
     fpm2.add(new ::AddSuspendCheckToLoopLatchPass(irb_.get()));
     fpm2.doInitialization();
diff --git a/src/compiler_llvm/compilation_unit.h b/src/compiler_llvm/compilation_unit.h
index d1dfa0c..6244eea 100644
--- a/src/compiler_llvm/compilation_unit.h
+++ b/src/compiler_llvm/compilation_unit.h
@@ -19,7 +19,7 @@
 
 #include "../mutex.h"
 #include "globals.h"
-#ifdef ART_USE_DEXLANG_FRONTEND
+#if defined(ART_USE_DEXLANG_FRONTEND) || defined(ART_USE_QUICK_COMPILER)
 # include "greenland/dex_lang.h"
 #endif
 #include "instruction_set.h"
@@ -28,6 +28,11 @@
 #include "runtime_support_func.h"
 #include "safe_map.h"
 
+#if defined(ART_USE_QUICK_COMPILER)
+# include "compiler.h"
+# include "oat_compilation_unit.h"
+#endif
+
 #include <UniquePtr.h>
 #include <string>
 #include <vector>
@@ -74,7 +79,7 @@
     return irb_.get();
   }
 
-#ifdef ART_USE_DEXLANG_FRONTEND
+#if defined(ART_USE_DEXLANG_FRONTEND) || defined(ART_USE_QUICK_COMPILER)
   greenland::DexLang::Context* GetDexLangContext() const {
     return dex_lang_ctx_;
   }
@@ -84,6 +89,15 @@
     bitcode_filename_ = bitcode_filename;
   }
 
+#if defined(ART_USE_QUICK_COMPILER)
+  void SetCompiler(Compiler* compiler) {
+    compiler_ = compiler;
+  }
+  void SetOatCompilationUnit(OatCompilationUnit* oat_compilation_unit) {
+    oat_compilation_unit_ = oat_compilation_unit;
+  }
+#endif
+
   bool Materialize();
 
   bool IsMaterialized() const {
@@ -103,9 +117,13 @@
   UniquePtr<IRBuilder> irb_;
   UniquePtr<RuntimeSupportBuilder> runtime_support_;
   llvm::Module* module_;
-#ifdef ART_USE_DEXLANG_FRONTEND
+#if defined(ART_USE_DEXLANG_FRONTEND) || defined(ART_USE_QUICK_COMPILER)
   greenland::DexLang::Context* dex_lang_ctx_;
 #endif
+#if defined(ART_USE_QUICK_COMPILER)
+  Compiler* compiler_;
+  OatCompilationUnit* oat_compilation_unit_;
+#endif
 
   std::string bitcode_filename_;
 
diff --git a/src/compiler_llvm/compiler_llvm.cc b/src/compiler_llvm/compiler_llvm.cc
index 3a1bebc..b290d2c 100644
--- a/src/compiler_llvm/compiler_llvm.cc
+++ b/src/compiler_llvm/compiler_llvm.cc
@@ -38,6 +38,20 @@
 #include <llvm/Support/TargetSelect.h>
 #include <llvm/Support/Threading.h>
 
+#if defined(ART_USE_QUICK_COMPILER)
+namespace art {
+void oatCompileMethodToGBC(Compiler& compiler,
+                           const DexFile::CodeItem* code_item,
+                           uint32_t access_flags, InvokeType invoke_type,
+                           uint32_t method_idx, jobject class_loader,
+                           const DexFile& dex_file,
+                           llvm::Module* module,
+                           llvm::LLVMContext* context,
+                           greenland::IntrinsicHelper* intrinsic_helper,
+                           greenland::IRBuilder* irb);
+}
+#endif
+
 namespace llvm {
   extern bool TimePassesIsEnabled;
 }
@@ -125,10 +139,10 @@
 
 
 CompiledMethod* CompilerLLVM::
-CompileDexMethod(OatCompilationUnit* oat_compilation_unit) {
+CompileDexMethod(OatCompilationUnit* oat_compilation_unit, InvokeType invoke_type) {
   UniquePtr<CompilationUnit> cunit(AllocateCompilationUnit());
 
-#ifdef ART_USE_DEXLANG_FRONTEND
+#if defined(ART_USE_DEXLANG_FRONTEND)
   // Run DexLang for Dex to Greenland Bitcode
   UniquePtr<greenland::DexLang> dex_lang(
       new greenland::DexLang(*cunit->GetDexLangContext(), *compiler_,
@@ -141,6 +155,47 @@
 
   return new CompiledMethod(cunit->GetInstructionSet(),
                             cunit->GetCompiledCode());
+#elif defined(ART_USE_QUICK_COMPILER)
+  std::string methodName(PrettyMethod(oat_compilation_unit->GetDexMethodIndex(),
+                                      *oat_compilation_unit->GetDexFile()));
+  if ((methodName.find("gdata2.AndroidGDataClient.createAndExecuteMethod")
+      != std::string::npos) || (methodName.find("hG.a") != std::string::npos)
+      || (methodName.find("hT.a(hV, java.lang.String, java.lang.String, java")
+      != std::string::npos) || (methodName.find("AndroidHttpTransport.exchange")
+      != std::string::npos)) {
+    // Use iceland
+    UniquePtr<MethodCompiler> method_compiler(
+        new MethodCompiler(cunit.get(), compiler_, oat_compilation_unit));
+
+    return method_compiler->Compile();
+  } else {
+    // Use quick
+    llvm::LLVMContext* context = cunit->GetLLVMContext();
+    llvm::Module* module = cunit->GetModule();
+    greenland::IntrinsicHelper* intrinsic_helper = &cunit->GetDexLangContext()->GetIntrinsicHelper();
+    UniquePtr<greenland::IRBuilder> greenland_irbuilder(
+        new greenland::IRBuilder(*context, *module, *intrinsic_helper));
+    oatCompileMethodToGBC(*compiler_,
+                          oat_compilation_unit->GetCodeItem(),
+                          oat_compilation_unit->access_flags_,
+                          invoke_type,
+                          oat_compilation_unit->GetDexMethodIndex(),
+                          oat_compilation_unit->GetClassLoader(),
+                          *oat_compilation_unit->GetDexFile(),
+                          module,
+                          context,
+                          intrinsic_helper,
+                          greenland_irbuilder.get()
+                          );
+
+    cunit->SetCompiler(compiler_);
+    cunit->SetOatCompilationUnit(oat_compilation_unit);
+
+    cunit->Materialize();
+
+    return new CompiledMethod(cunit->GetInstructionSet(),
+                              cunit->GetCompiledCode());
+  }
 #else
   UniquePtr<MethodCompiler> method_compiler(
       new MethodCompiler(cunit.get(), compiler_, oat_compilation_unit));
@@ -223,7 +278,7 @@
     class_loader, class_linker, dex_file, code_item,
     method_idx, access_flags);
   art::compiler_llvm::CompilerLLVM* compiler_llvm = ContextOf(compiler);
-  art::CompiledMethod* result = compiler_llvm->CompileDexMethod(&oat_compilation_unit);
+  art::CompiledMethod* result = compiler_llvm->CompileDexMethod(&oat_compilation_unit, invoke_type);
   return result;
 }
 
diff --git a/src/compiler_llvm/compiler_llvm.h b/src/compiler_llvm/compiler_llvm.h
index 4680648..dabd7be 100644
--- a/src/compiler_llvm/compiler_llvm.h
+++ b/src/compiler_llvm/compiler_llvm.h
@@ -74,7 +74,12 @@
     bitcode_filename_ = filename;
   }
 
-  CompiledMethod* CompileDexMethod(OatCompilationUnit* oat_compilation_unit);
+  CompiledMethod* CompileDexMethod(OatCompilationUnit* oat_compilation_unit,
+                                   InvokeType invoke_type);
+
+#if defined(ART_USE_LLVM_COMPILER) && defined(ART_USE_QUICK_COMPILER)
+  CompiledMethod* CompileGBCMethod(OatCompilationUnit* oat_compilation_unit, std::string* func);
+#endif
 
   CompiledMethod* CompileNativeMethod(OatCompilationUnit* oat_compilation_unit);
 
diff --git a/src/compiler_llvm/gbc_expander.cc b/src/compiler_llvm/gbc_expander.cc
index 9d7f1ae..3dcd793 100644
--- a/src/compiler_llvm/gbc_expander.cc
+++ b/src/compiler_llvm/gbc_expander.cc
@@ -59,7 +59,6 @@
   Compiler* compiler_;
 
   const DexFile* dex_file_;
-  DexCache* dex_cache_;
   const DexFile::CodeItem* code_item_;
 
   OatCompilationUnit* oat_compilation_unit_;
@@ -326,14 +325,25 @@
   GBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb)
       : llvm::FunctionPass(ID), intrinsic_helper_(intrinsic_helper), irb_(irb),
         context_(irb.getContext()), rtb_(irb.Runtime()),
-
-        // TODO: Initialize these fields correctly.
         shadow_frame_(NULL), old_shadow_frame_(NULL), shadow_frame_size_(0),
-        compiler_(NULL), dex_file_(NULL), dex_cache_(NULL), code_item_(NULL),
+        compiler_(NULL), dex_file_(NULL), code_item_(NULL),
         oat_compilation_unit_(NULL), method_idx_(-1u), func_(NULL),
         changed_(false)
   { }
 
+  GBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb,
+                  Compiler* compiler, OatCompilationUnit* oat_compilation_unit)
+      : llvm::FunctionPass(ID), intrinsic_helper_(intrinsic_helper), irb_(irb),
+        context_(irb.getContext()), rtb_(irb.Runtime()),
+        shadow_frame_(NULL), old_shadow_frame_(NULL), shadow_frame_size_(0),
+        compiler_(compiler),
+        dex_file_(oat_compilation_unit->GetDexFile()),
+        code_item_(oat_compilation_unit->GetCodeItem()),
+        oat_compilation_unit_(oat_compilation_unit),
+        method_idx_(oat_compilation_unit->GetDexMethodIndex()),
+        func_(NULL), changed_(false)
+  { }
+
   bool runOnFunction(llvm::Function& func);
 
  private:
@@ -359,6 +369,21 @@
   func_ = &func;
   changed_ = false; // Assume unchanged
 
+#if defined(ART_USE_QUICK_COMPILER)
+  basic_blocks_.resize(code_item_->insns_size_in_code_units_);
+  basic_block_landing_pads_.resize(code_item_->tries_size_, NULL);
+  basic_block_unwind_ = NULL;
+  for (llvm::Function::iterator bb_iter = func_->begin(), bb_end = func_->end();
+       bb_iter != bb_end;
+       ++bb_iter) {
+    if (bb_iter->begin()->getMetadata("DexOff") == NULL) {
+      continue;
+    }
+    uint32_t dex_pc = LV2UInt(bb_iter->begin()->getMetadata("DexOff")->getOperand(0));
+    basic_blocks_[dex_pc] = bb_iter;
+  }
+#endif
+
   // Insert stack overflow check
   InsertStackOverflowCheck(func); // TODO: Use intrinsic.
 
@@ -1138,6 +1163,11 @@
 }
 
 void GBCExpanderPass::Expand_PopShadowFrame() {
+#if defined(ART_USE_QUICK_COMPILER)
+  if (old_shadow_frame_ == NULL) {
+    return;
+  }
+#endif
   rtb_.EmitPopShadowFrame(irb_.CreateLoad(old_shadow_frame_, kTBAARegister));
   return;
 }
@@ -1317,6 +1347,8 @@
 
   case kBoolean:
   case kChar:
+  case kByte:
+  case kShort:
     new_value = irb_.CreateTrunc(new_value, irb_.getJType(elem_jty, kArray));
     break;
 
@@ -1412,8 +1444,8 @@
 void GBCExpanderPass::Expand_HLIPut(llvm::CallInst& call_inst,
                                     JType field_jty) {
   uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
-  llvm::Value* object_addr = call_inst.getArgOperand(1);
-  llvm::Value* new_value = call_inst.getArgOperand(2);
+  llvm::Value* new_value = call_inst.getArgOperand(1);
+  llvm::Value* object_addr = call_inst.getArgOperand(2);
   uint32_t field_idx = LV2UInt(call_inst.getArgOperand(3));
 
   if (field_jty == kFloat || field_jty == kDouble) {
@@ -1475,8 +1507,7 @@
 
 llvm::Value* GBCExpanderPass::EmitLoadConstantClass(uint32_t dex_pc,
                                                     uint32_t type_idx) {
-  if (!compiler_->CanAccessTypeWithoutChecks(method_idx_, dex_cache_,
-                                             *dex_file_, type_idx)) {
+  if (!compiler_->CanAccessTypeWithoutChecks(method_idx_, *dex_file_, type_idx)) {
     llvm::Value* type_idx_value = irb_.getInt32(type_idx);
 
     llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
@@ -1502,7 +1533,7 @@
 
     llvm::Value* type_object_addr = irb_.CreateLoad(type_field_addr, kTBAAJRuntime);
 
-    if (compiler_->CanAssumeTypeIsPresentInDexCache(dex_cache_, type_idx)) {
+    if (compiler_->CanAssumeTypeIsPresentInDexCache(*dex_file_, type_idx)) {
       return type_object_addr;
     }
 
@@ -1774,7 +1805,7 @@
 
   llvm::Value* string_addr = irb_.CreateLoad(string_field_addr, kTBAAJRuntime);
 
-  if (!compiler_->CanAssumeStringIsPresentInDexCache(dex_cache_, string_idx)) {
+  if (!compiler_->CanAssumeStringIsPresentInDexCache(*dex_file_, string_idx)) {
     llvm::BasicBlock* block_str_exist =
       CreateBasicBlockWithDexPC(dex_pc, "str_exist");
 
@@ -1809,6 +1840,9 @@
 
     EmitGuard_ExceptionLandingPad(dex_pc);
 
+    irb_.CreateBr(block_cont);
+
+
     llvm::BasicBlock* block_pre_cont = irb_.GetInsertBlock();
 
     irb_.SetInsertPoint(block_cont);
@@ -1995,8 +2029,7 @@
   uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
 
   llvm::Function* runtime_func;
-  if (compiler_->CanAccessInstantiableTypeWithoutChecks(
-        method_idx_, dex_cache_, *dex_file_, type_idx)) {
+  if (compiler_->CanAccessInstantiableTypeWithoutChecks(method_idx_, *dex_file_, type_idx)) {
     runtime_func = irb_.GetRuntime(runtime_support::AllocObject);
   } else {
     runtime_func = irb_.GetRuntime(runtime_support::AllocObjectWithAccessCheck);
@@ -2245,8 +2278,7 @@
   llvm::Function* runtime_func;
 
   bool skip_access_check =
-    compiler_->CanAccessTypeWithoutChecks(method_idx_, dex_cache_,
-                                          *dex_file_, type_idx);
+    compiler_->CanAccessTypeWithoutChecks(method_idx_, *dex_file_, type_idx);
 
 
   if (is_filled_new_array) {
@@ -2342,6 +2374,11 @@
 }
 
 void GBCExpanderPass::EmitUpdateDexPC(uint32_t dex_pc) {
+#if defined(ART_USE_QUICK_COMPILER)
+  if (shadow_frame_ == NULL) {
+    return;
+  }
+#endif
   irb_.StoreToObjectOffset(shadow_frame_,
                            ShadowFrame::DexPCOffset(),
                            irb_.getInt32(dex_pc),
@@ -2434,7 +2471,18 @@
   CHECK_GE(shorty_size, 1u);
 
   // Get return type
-  llvm::Type* ret_type = irb_.getJType(shorty[0], kAccurate);
+
+  char ret_shorty = shorty[0];
+#if defined(ART_USE_QUICK_COMPILER)
+  switch(ret_shorty) {
+    case 'Z' : ret_shorty = 'I'; break;
+    case 'B' : ret_shorty = 'I'; break;
+    case 'S' : ret_shorty = 'I'; break;
+    case 'C' : ret_shorty = 'I'; break;
+    default: break;
+  }
+#endif
+  llvm::Type* ret_type = irb_.getJType(ret_shorty, kAccurate);
 
   // Get argument type
   std::vector<llvm::Type*> args_type;
@@ -2478,7 +2526,7 @@
 
 llvm::BasicBlock* GBCExpanderPass::GetBasicBlock(uint32_t dex_pc) {
   DCHECK(dex_pc < code_item_->insns_size_in_code_units_);
-
+  CHECK(basic_blocks_[dex_pc] != NULL);
   return basic_blocks_[dex_pc];
 }
 
@@ -2588,6 +2636,15 @@
 
   // Emit the code to return default value (zero) for the given return type.
   char ret_shorty = oat_compilation_unit_->GetShorty()[0];
+#if defined(ART_USE_QUICK_COMPILER)
+  switch(ret_shorty) {
+    case 'Z' : ret_shorty = 'I'; break;
+    case 'B' : ret_shorty = 'I'; break;
+    case 'S' : ret_shorty = 'I'; break;
+    case 'C' : ret_shorty = 'I'; break;
+    default: break;
+  }
+#endif
   if (ret_shorty == 'V') {
     irb_.CreateRetVoid();
   } else {
@@ -3472,8 +3529,8 @@
                                 irb_.getJDoubleTy());
     }
     case greenland::IntrinsicHelper::ConstObj: {
-      LOG(FATAL) << "ConstObj should not occur at all";
-      return NULL;
+      CHECK(LV2UInt(call_inst.getArgOperand(0)) == 0);
+      return irb_.getJNull();
     }
 
     //==- Method Info ------------------------------------------------------==//
@@ -3560,5 +3617,16 @@
   return new GBCExpanderPass(intrinsic_helper, irb);
 }
 
+llvm::FunctionPass*
+CreateGBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb,
+                      Compiler* compiler, OatCompilationUnit* oat_compilation_unit) {
+  if (compiler != NULL) {
+    return new GBCExpanderPass(intrinsic_helper, irb,
+                               compiler, oat_compilation_unit);
+  } else {
+    return new GBCExpanderPass(intrinsic_helper, irb);
+  }
+}
+
 } // namespace compiler_llvm
 } // namespace art
diff --git a/src/greenland/dalvik_reg.h b/src/greenland/dalvik_reg.h
index b93ef7e..83157f3 100644
--- a/src/greenland/dalvik_reg.h
+++ b/src/greenland/dalvik_reg.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_SRC_COMPILER_LLVM_DALVIK_REG_H_
-#define ART_SRC_COMPILER_LLVM_DALVIK_REG_H_
+#ifndef ART_SRC_GREENLAND_DALVIK_REG_H_
+#define ART_SRC_GREENLAND_DALVIK_REG_H_
 
 #include "backend_types.h"
 
@@ -76,4 +76,4 @@
 } // namespace greenland
 } // namespace art
 
-#endif // ART_SRC_COMPILER_LLVM_DALVIK_REG_H_
+#endif // ART_SRC_GREENLAND_DALVIK_REG_H_
diff --git a/src/greenland/dex_lang.cc b/src/greenland/dex_lang.cc
index 8568130..f0ecdc6 100644
--- a/src/greenland/dex_lang.cc
+++ b/src/greenland/dex_lang.cc
@@ -59,7 +59,7 @@
                  OatCompilationUnit& cunit)
     : dex_lang_ctx_(context), compiler_(compiler), cunit_(cunit),
       dex_file_(cunit.GetDexFile()), code_item_(cunit.GetCodeItem()),
-      dex_cache_(cunit.GetDexCache()), method_idx_(cunit.GetDexMethodIndex()),
+      method_idx_(cunit.GetDexMethodIndex()),
       context_(context.GetLLVMContext()), module_(context.GetOutputModule()),
       intrinsic_helper_(context.GetIntrinsicHelper()),
       irb_(context.GetLLVMContext(), context.GetOutputModule(),
@@ -889,8 +889,7 @@
 
   llvm::Value* thread_object_addr = EmitGetCurrentThread();
 
-  if (!compiler_.CanAccessTypeWithoutChecks(method_idx_, dex_cache_,
-                                            *dex_file_, type_idx)) {
+  if (!compiler_.CanAccessTypeWithoutChecks(method_idx_, *dex_file_, type_idx)) {
     return EmitInvokeIntrinsic3(dex_pc, false, IntrinsicHelper::InitializeTypeAndVerifyAccess,
                                 type_idx_value, method_object_addr,
                                 thread_object_addr);
@@ -900,7 +899,7 @@
         EmitInvokeIntrinsicNoThrow(IntrinsicHelper::LoadTypeFromDexCache,
                                    type_idx_value);
 
-    if (compiler_.CanAssumeTypeIsPresentInDexCache(dex_cache_, type_idx)) {
+    if (compiler_.CanAssumeTypeIsPresentInDexCache(*dex_file_, type_idx)) {
       return type_object_addr;
     }
 
@@ -951,7 +950,6 @@
                                         uint32_t type_idx,
                                         bool is_filled_new_array) {
   bool skip_access_check = compiler_.CanAccessTypeWithoutChecks(method_idx_,
-                                                                dex_cache_,
                                                                 *dex_file_,
                                                                 type_idx);
 
@@ -1340,7 +1338,7 @@
       EmitInvokeIntrinsicNoThrow(IntrinsicHelper::LoadStringFromDexCache,
                                  string_idx_value);
 
-  if (!compiler_.CanAssumeStringIsPresentInDexCache(dex_cache_, string_idx)) {
+  if (!compiler_.CanAssumeStringIsPresentInDexCache(*dex_file_, string_idx)) {
     llvm::BasicBlock* block_str_exist =
         CreateBasicBlockWithDexPC(dex_pc, "str_exist");
 
@@ -1543,7 +1541,6 @@
 
   IntrinsicHelper::IntrinsicId alloc_intrinsic;
   if (compiler_.CanAccessInstantiableTypeWithoutChecks(method_idx_,
-                                                       dex_cache_,
                                                        *dex_file_,
                                                        dec_insn.vB)) {
     alloc_intrinsic = IntrinsicHelper::AllocObject;
@@ -3941,7 +3938,7 @@
     case Instruction::CONST_STRING:
     case Instruction::CONST_STRING_JUMBO:
       // TODO: Will the ResolveString throw exception?
-      if (!compiler_.CanAssumeStringIsPresentInDexCache(dex_cache_, dec_insn.vB)) {
+      if (!compiler_.CanAssumeStringIsPresentInDexCache(*dex_file_, dec_insn.vB)) {
         may_throw_exception = true;
       }
       set_to_another_object[dec_insn.vA] = true;
diff --git a/src/greenland/dex_lang.h b/src/greenland/dex_lang.h
index fdc0a0a..70ad5bf 100644
--- a/src/greenland/dex_lang.h
+++ b/src/greenland/dex_lang.h
@@ -95,7 +95,6 @@
 
   const DexFile* dex_file_;
   const DexFile::CodeItem* code_item_;
-  DexCache* dex_cache_;
   uint32_t method_idx_;
 
   llvm::LLVMContext& context_;