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/Compiler.h b/src/compiler/Compiler.h
index 7eb32c2..11214cf 100644
--- a/src/compiler/Compiler.h
+++ b/src/compiler/Compiler.h
@@ -20,20 +20,16 @@
 #include "dex_file.h"
 #include "dex_instruction.h"
 
-#if defined(ART_USE_QUICK_COMPILER)
 namespace llvm {
   class Module;
   class LLVMContext;
 }
-#endif
 
 namespace art {
-#if defined(ART_USE_QUICK_COMPILER)
 namespace greenland {
   class IntrinsicHelper;
   class IRBuilder;
 }
-#endif
 
 #define COMPILER_TRACED(X)
 #define COMPILER_TRACEE(X)
@@ -141,10 +137,8 @@
   kDebugShowNops,
   kDebugCountOpcodes,
   kDebugDumpCheckStats,
-#if defined(ART_USE_QUICK_COMPILER)
   kDebugDumpBitcodeFile,
   kDebugVerifyBitcode,
-#endif
 };
 
 enum OatMethodAttributes {
@@ -177,7 +171,6 @@
   kReversePostOrderTraversal, // Depth-First-Search / reverse Post-Order
 };
 
-#if defined(ART_USE_QUICK_COMPILER)
 class LLVMInfo {
   public:
     LLVMInfo();
@@ -205,7 +198,6 @@
     UniquePtr<art::greenland::IntrinsicHelper> intrinsic_helper_;
     UniquePtr<art::greenland::IRBuilder> ir_builder_;
 };
-#endif
 
 struct CompilationUnit;
 struct BasicBlock;
diff --git a/src/compiler/CompilerIR.h b/src/compiler/CompilerIR.h
index 5a10831..d08af07 100644
--- a/src/compiler/CompilerIR.h
+++ b/src/compiler/CompilerIR.h
@@ -23,10 +23,8 @@
 #include "CompilerUtility.h"
 #include "oat_compilation_unit.h"
 #include "safe_map.h"
-#if defined(ART_USE_QUICK_COMPILER)
 #include "greenland/ir_builder.h"
 #include "llvm/Module.h"
-#endif
 
 namespace art {
 
@@ -262,9 +260,7 @@
   bool catchEntry;
   bool explicitThrow;
   bool conditionalBranch;
-#if defined(ART_USE_QUICK_COMPILER)
   bool hasReturn;
-#endif
   uint16_t startOffset;
   uint16_t nestingDepth;
   BBType blockType;
@@ -384,7 +380,6 @@
       numArenaBlocks(0),
       mstats(NULL),
       checkstats(NULL),
-#if defined(ART_USE_QUICK_COMPILER)
       genBitcode(false),
       context(NULL),
       module(NULL),
@@ -397,7 +392,6 @@
       tempName(0),
       numShadowFrameEntries(0),
       shadowMap(NULL),
-#endif
 #ifndef NDEBUG
       liveSReg(0),
 #endif
@@ -547,7 +541,6 @@
   int numArenaBlocks;
   Memstats* mstats;
   Checkstats* checkstats;
-#if defined(ART_USE_QUICK_COMPILER)
   bool genBitcode;
   LLVMInfo* llvm_info;
   llvm::LLVMContext* context;
@@ -567,7 +560,6 @@
   int numShadowFrameEntries;
   int* shadowMap;
   std::set<llvm::BasicBlock*> llvmBlocks;
-#endif
 #ifndef NDEBUG
   /*
    * Sanity checking for the register temp tracking.  The same ssa
diff --git a/src/compiler/Dataflow.cc b/src/compiler/Dataflow.cc
index 0058575..c59b637 100644
--- a/src/compiler/Dataflow.cc
+++ b/src/compiler/Dataflow.cc
@@ -1854,12 +1854,10 @@
       case Instruction::CMPG_FLOAT:
       case Instruction::CMPG_DOUBLE:
       case Instruction::CMP_LONG:
-#if defined(ART_USE_QUICK_COMPILER)
         if (cUnit->genBitcode) {
           // Bitcode doesn't allow this optimization.
           break;
         }
-#endif
         if (mir->next != NULL) {
           MIR* mirNext = mir->next;
           Instruction::Code brOpcode = mirNext->dalvikInsn.opcode;
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
diff --git a/src/compiler/Ralloc.cc b/src/compiler/Ralloc.cc
index bf69ce4..ca25b38 100644
--- a/src/compiler/Ralloc.cc
+++ b/src/compiler/Ralloc.cc
@@ -485,19 +485,12 @@
       }
   }
 
-#if defined(ART_USE_QUICK_COMPILER)
   if (!cUnit->genBitcode) {
     /* Remap names */
     oatDataFlowAnalysisDispatcher(cUnit, remapNames,
                                   kPreOrderDFSTraversal,
                                   false /* isIterative */);
   }
-#else
-  /* Remap names */
-  oatDataFlowAnalysisDispatcher(cUnit, remapNames,
-                                kPreOrderDFSTraversal,
-                                false /* isIterative */);
-#endif
 
   /* Do type & size inference pass */
   oatDataFlowAnalysisDispatcher(cUnit, inferTypeAndSize,
diff --git a/src/compiler/codegen/MethodBitcode.cc b/src/compiler/codegen/MethodBitcode.cc
index cf07ea4..7920883 100644
--- a/src/compiler/codegen/MethodBitcode.cc
+++ b/src/compiler/codegen/MethodBitcode.cc
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 
-#if defined(ART_USE_QUICK_COMPILER)
 #include "object_utils.h"
 
 #include <llvm/Support/ToolOutputFile.h>
@@ -3537,5 +3536,3 @@
 
 
 }  // namespace art
-
-#endif  // ART_USE_QUICK_COMPILER