Eliminate #ifdef ART_USE_QUICK_COMPILER

One of several steps towards having a single compiler build.
In this CL, we introduce a compiler_backend command-line option
to select between Quick, Quick w/ GBC, Portable and Iceland
back ends.  The Iceland option is temporary, and will go away once
we combine with Portable.  The Quick variants are with
and without GBC conversion.  In time, those will converge to a
single option.

All uses of "#if defined(ART_USE_QUICK_COMPILER)" are eliminated.  All
previous uses in the Quick compiler have been converted to runtime
tests.  On the llvm side, ART_USE_QUICK_COMPILER was previously
used to differentiate between Portable and Iceland builds.  Those
usages have been replaced with ART_USE_PORTABLE_COMPILER, and in
a following CL will also be converted to run-time tests.

As of this CL, we're still generating separate libraries for
Quick and Portable/Iceland.  Next up is elminating the target-specific
libraries for Quick-arm, Quick-x86 and Quick-mips.  Once that is
complete, we will consoldate Quick and Portable into a single build.

To build either Iceland or Portable, touch USE_PORTABLE_COMPILER or
USE_LLVM_COMPILER as usual.  Otherwise, the build will default
to Quick (non-GBC).

Change-Id: Ic86c56f51710c9b06d4430b71a429ae12903cc47
diff --git a/src/compiler/Frontend.cc b/src/compiler/Frontend.cc
index c19751d..c5d5c21 100644
--- a/src/compiler/Frontend.cc
+++ b/src/compiler/Frontend.cc
@@ -21,7 +21,6 @@
 #include "object.h"
 #include "runtime.h"
 
-#if defined(ART_USE_QUICK_COMPILER)
 #include <llvm/Support/Threading.h>
 
 namespace {
@@ -32,11 +31,9 @@
     llvm::llvm_start_multithreaded();
   }
 }
-#endif
 
 namespace art {
 
-#if defined(ART_USE_QUICK_COMPILER)
 LLVMInfo::LLVMInfo() {
 #if !defined(ART_USE_LLVM_COMPILER)
   pthread_once(&llvm_multi_init, InitializeLLVMForQuick);
@@ -62,7 +59,6 @@
   delete reinterpret_cast<LLVMInfo*>(compiler.GetCompilerContext());
   compiler.SetCompilerContext(NULL);
 }
-#endif
 
 /* Default optimizer/debug setting for the compiler. */
 static uint32_t kCompilerOptimizerDisableFlags = 0 | // Disable specific optimizations
@@ -94,10 +90,8 @@
   //(1 << kDebugShowNops) |
   //(1 << kDebugCountOpcodes) |
   //(1 << kDebugDumpCheckStats) |
-#if defined(ART_USE_QUICK_COMPILER)
   //(1 << kDebugDumpBitcodeFile) |
   //(1 << kDebugVerifyBitcode) |
-#endif
   0;
 
 inline bool contentIsInsn(const u2* codePtr) {
@@ -788,14 +782,12 @@
 }
 
 CompiledMethod* compileMethod(Compiler& compiler,
+                              const CompilerBackend compilerBackend,
                               const DexFile::CodeItem* code_item,
                               uint32_t access_flags, InvokeType invoke_type,
                               uint32_t method_idx, jobject class_loader,
-                              const DexFile& dex_file
-#if defined(ART_USE_QUICK_COMPILER)
-                              , LLVMInfo* llvm_info,
-                              bool gbcOnly
-#endif
+                              const DexFile& dex_file,
+                              LLVMInfo* llvm_info
                              )
 {
   VLOG(compiler) << "Compiling " << PrettyMethod(method_idx, dex_file) << "...";
@@ -824,16 +816,18 @@
   cUnit->numIns = code_item->ins_size_;
   cUnit->numRegs = code_item->registers_size_ - cUnit->numIns;
   cUnit->numOuts = code_item->outs_size_;
-#if defined(ART_USE_QUICK_COMPILER)
   DCHECK((cUnit->instructionSet == kThumb2) ||
          (cUnit->instructionSet == kX86) ||
          (cUnit->instructionSet == kMips));
-  cUnit->llvm_info = llvm_info;
-  if (cUnit->instructionSet == kThumb2) {
-    // TODO: remove this once x86 is tested
+  if ((compilerBackend == kQuickGBC) || (compilerBackend == kPortable)) {
     cUnit->genBitcode = true;
   }
-#endif
+  DCHECK_NE(compilerBackend, kIceland);  // TODO: remove when Portable/Iceland merge complete
+  // TODO: remove this once x86 is tested
+  if (cUnit->genBitcode && (cUnit->instructionSet != kThumb2)) {
+    UNIMPLEMENTED(WARNING) << "GBC generation untested for non-Thumb targets";
+  }
+  cUnit->llvm_info = llvm_info;
   /* Adjust this value accordingly once inlining is performed */
   cUnit->numDalvikRegisters = code_item->registers_size_;
   // TODO: set this from command line
@@ -848,13 +842,9 @@
     cUnit->printMe = VLOG_IS_ON(compiler) ||
         (cUnit->enableDebug & (1 << kDebugVerbose));
   }
-#if defined(ART_USE_QUICK_COMPILER)
-  if (cUnit->genBitcode) {
 #ifndef NDEBUG
+  if (cUnit->genBitcode) {
     cUnit->enableDebug |= (1 << kDebugVerifyBitcode);
-#endif
-    //cUnit->printMe = true;
-    //cUnit->enableDebug |= (1 << kDebugDumpBitcodeFile);
   }
 #endif
 
@@ -1098,21 +1088,14 @@
   }
 
   if (cUnit->qdMode) {
-#if !defined(ART_USE_QUICK_COMPILER)
     // Bitcode generation requires full dataflow analysis
-    cUnit->disableDataflow = true;
-#endif
+    cUnit->disableDataflow = !cUnit->genBitcode;
     // Disable optimization which require dataflow/ssa
-    cUnit->disableOpt |=
-#if !defined(ART_USE_QUICK_COMPILER)
-        (1 << kNullCheckElimination) |
-#endif
-        (1 << kBBOpt) |
-        (1 << kPromoteRegs);
+    cUnit->disableOpt |= (1 << kBBOpt) | (1 << kPromoteRegs) | (1 << kNullCheckElimination);
     if (cUnit->printMe) {
         LOG(INFO) << "QD mode enabled: "
                   << PrettyMethod(method_idx, dex_file)
-                  << " too big: " << cUnit->numBlocks;
+                  << " num blocks: " << cUnit->numBlocks;
     }
   }
 
@@ -1168,12 +1151,11 @@
   /* Allocate Registers using simple local allocation scheme */
   oatSimpleRegAlloc(cUnit.get());
 
-#if defined(ART_USE_QUICK_COMPILER)
   /* Go the LLVM path? */
   if (cUnit->genBitcode) {
     // MIR->Bitcode
     oatMethodMIR2Bitcode(cUnit.get());
-    if (gbcOnly) {
+    if (compilerBackend == kPortable) {
       // all done
       oatArenaReset(cUnit.get());
       return NULL;
@@ -1181,7 +1163,6 @@
     // Bitcode->LIR
     oatMethodBitcode2LIR(cUnit.get());
   } else {
-#endif
     if (specialCase != kNoHandler) {
       /*
        * Custom codegen for special cases.  If for any reason the
@@ -1195,9 +1176,7 @@
     if (cUnit->firstLIRInsn == NULL) {
       oatMethodMIR2LIR(cUnit.get());
     }
-#if defined(ART_USE_QUICK_COMPILER)
   }
-#endif
 
   // Debugging only
   if (cUnit->enableDebug & (1 << kDebugDumpCFG)) {
@@ -1268,55 +1247,30 @@
   return result;
 }
 
-#if defined(ART_USE_QUICK_COMPILER)
 CompiledMethod* oatCompileMethod(Compiler& compiler,
+                                 const CompilerBackend backend,
                                  const DexFile::CodeItem* code_item,
                                  uint32_t access_flags, InvokeType invoke_type,
                                  uint32_t method_idx, jobject class_loader,
-                                 const DexFile& dex_file)
+                                 const DexFile& dex_file,
+                                 LLVMInfo* llvmInfo)
 {
-  return compileMethod(compiler, code_item, access_flags, invoke_type, method_idx, class_loader,
-                       dex_file, NULL, false);
+  return compileMethod(compiler, backend, code_item, access_flags, invoke_type, method_idx, class_loader,
+                       dex_file, llvmInfo);
 }
 
-/*
- * Given existing llvm module, context, intrinsic_helper and IRBuilder,
- * add the bitcode for the method described by code_item to the module.
- */
-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,
-                           LLVMInfo* llvm_info)
-{
-  compileMethod(compiler, code_item, access_flags, invoke_type, method_idx, class_loader,
-                dex_file, llvm_info, true);
-}
-#else
-CompiledMethod* oatCompileMethod(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)
-{
-  return compileMethod(compiler, code_item, access_flags, invoke_type, method_idx, class_loader,
-                       dex_file);
-}
-#endif
-
 }  // namespace art
 
-#if !defined(ART_USE_LLVM_COMPILER)
 extern "C" art::CompiledMethod*
-    ArtCompileMethod(art::Compiler& compiler,
-                     const art::DexFile::CodeItem* code_item,
-                     uint32_t access_flags, art::InvokeType invoke_type,
-                     uint32_t method_idx, jobject class_loader,
-                     const art::DexFile& dex_file)
+    ArtQuickCompileMethod(art::Compiler& compiler,
+                          const art::DexFile::CodeItem* code_item,
+                          uint32_t access_flags, art::InvokeType invoke_type,
+                          uint32_t method_idx, jobject class_loader,
+                          const art::DexFile& dex_file)
 {
   CHECK_EQ(compiler.GetInstructionSet(), art::oatInstructionSet());
-  return art::oatCompileMethod(compiler, code_item, access_flags, invoke_type,
-                               method_idx, class_loader, dex_file);
+  // TODO: check method fingerprint here to determine appropriate backend type.  Until then, use build default
+  art::CompilerBackend backend = compiler.GetCompilerBackend();
+  return art::oatCompileMethod(compiler, backend, code_item, access_flags, invoke_type,
+                               method_idx, class_loader, dex_file, NULL /* use thread llvmInfo */);
 }
-#endif