Merge "Code cleanup to avoid LLVM dependency when building with quick only."
diff --git a/build/Android.common.mk b/build/Android.common.mk
index 1299beb..704da68 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -127,6 +127,8 @@
 	-Wall \
 	-Werror \
 	-Wextra \
+	-Wno-sign-promo \
+	-Wno-unused-parameter \
 	-Wstrict-aliasing \
 	-fstrict-aliasing
 
diff --git a/compiler/Android.mk b/compiler/Android.mk
index 49fb05e..77dc367 100644
--- a/compiler/Android.mk
+++ b/compiler/Android.mk
@@ -49,7 +49,6 @@
 	dex/quick/x86/int_x86.cc \
 	dex/quick/x86/target_x86.cc \
 	dex/quick/x86/utility_x86.cc \
-	dex/portable/mir_to_gbc.cc \
 	dex/dex_to_dex_compiler.cc \
 	dex/mir_dataflow.cc \
 	dex/mir_optimization.cc \
@@ -64,22 +63,11 @@
 	dex/ssa_transformation.cc \
 	driver/compiler_driver.cc \
 	driver/dex_compilation_unit.cc \
-	jni/portable/jni_compiler.cc \
 	jni/quick/arm/calling_convention_arm.cc \
 	jni/quick/mips/calling_convention_mips.cc \
 	jni/quick/x86/calling_convention_x86.cc \
 	jni/quick/calling_convention.cc \
 	jni/quick/jni_compiler.cc \
-	llvm/compiler_llvm.cc \
-	llvm/gbc_expander.cc \
-	llvm/generated/art_module.cc \
-	llvm/intrinsic_helper.cc \
-	llvm/ir_builder.cc \
-	llvm/llvm_compilation_unit.cc \
-	llvm/md_builder.cc \
-	llvm/runtime_support_builder.cc \
-	llvm/runtime_support_builder_arm.cc \
-	llvm/runtime_support_builder_x86.cc \
 	optimizing/builder.cc \
 	optimizing/nodes.cc \
 	trampolines/trampoline_compiler.cc \
@@ -115,8 +103,22 @@
 endif
 
 LIBART_COMPILER_CFLAGS :=
+
 ifeq ($(ART_USE_PORTABLE_COMPILER),true)
-  LIBART_COMPILER_SRC_FILES += elf_writer_mclinker.cc
+LIBART_COMPILER_SRC_FILES +=
+	dex/portable/mir_to_gbc.cc \
+	elf_writer_mclinker.cc \
+	jni/portable/jni_compiler.cc \
+	llvm/compiler_llvm.cc \
+	llvm/gbc_expander.cc \
+	llvm/generated/art_module.cc \
+	llvm/intrinsic_helper.cc \
+	llvm/ir_builder.cc \
+	llvm/llvm_compilation_unit.cc \
+	llvm/md_builder.cc \
+	llvm/runtime_support_builder.cc \
+	llvm/runtime_support_builder_arm.cc \
+	llvm/runtime_support_builder_x86.cc
   LIBART_COMPILER_CFLAGS += -DART_USE_PORTABLE_COMPILER=1
 endif
 
@@ -197,8 +199,8 @@
     endif
     LOCAL_SHARED_LIBRARIES += libart
   endif
-  LOCAL_SHARED_LIBRARIES += libbcc libbcinfo libLLVM
   ifeq ($(ART_USE_PORTABLE_COMPILER),true)
+    LOCAL_SHARED_LIBRARIES += libbcc libbcinfo libLLVM
     LOCAL_CFLAGS += -DART_USE_PORTABLE_COMPILER=1
     ifeq ($$(art_target_or_host),target)
       LOCAL_STATIC_LIBRARIES_arm += libmcldARMInfo libmcldARMTarget
diff --git a/compiler/compiler_backend.cc b/compiler/compiler_backend.cc
index b8f21a9..eaa39f8 100644
--- a/compiler/compiler_backend.cc
+++ b/compiler/compiler_backend.cc
@@ -177,7 +177,9 @@
 #ifdef ART_USE_PORTABLE_COMPILER
 
 extern "C" void ArtInitCompilerContext(art::CompilerDriver& driver);
+
 extern "C" void ArtUnInitCompilerContext(art::CompilerDriver& driver);
+
 extern "C" art::CompiledMethod* ArtCompileMethod(art::CompilerDriver& driver,
                                                  const art::DexFile::CodeItem* code_item,
                                                  uint32_t access_flags,
@@ -186,10 +188,14 @@
                                                  uint32_t method_idx,
                                                  jobject class_loader,
                                                  const art::DexFile& dex_file);
+
 extern "C" art::CompiledMethod* ArtLLVMJniCompileMethod(art::CompilerDriver& driver,
                                                         uint32_t access_flags, uint32_t method_idx,
                                                         const art::DexFile& dex_file);
 
+extern "C" void compilerLLVMSetBitcodeFileName(art::CompilerDriver& driver,
+                                               std::string const& filename);
+
 
 class LLVMBackend : public CompilerBackend {
  public:
@@ -267,6 +273,15 @@
 
   bool isPortable() const { return true; }
 
+  void SetBitcodeFileName(std::string const& filename) {
+    typedef void (*SetBitcodeFileNameFn)(CompilerDriver&, std::string const&);
+
+    SetBitcodeFileNameFn set_bitcode_file_name =
+      reinterpret_cast<SetBitcodeFileNameFn>(compilerLLVMSetBitcodeFileName);
+
+    set_bitcode_file_name(*this, filename);
+  }
+
  private:
   DISALLOW_COPY_AND_ASSIGN(LLVMBackend);
 };
diff --git a/compiler/compiler_backend.h b/compiler/compiler_backend.h
index b20c125..01a69af 100644
--- a/compiler/compiler_backend.h
+++ b/compiler/compiler_backend.h
@@ -80,6 +80,9 @@
   }
 
   virtual bool IsPortable() const { return false; }
+  void SetBitcodeFileName(std::string const& filename) {
+    UNUSED(filename);
+  }
 
   virtual void InitCompilationUnit(CompilationUnit& cu) const = 0;
 
diff --git a/compiler/dex/compiler_ir.h b/compiler/dex/compiler_ir.h
index ded8005..8447d23 100644
--- a/compiler/dex/compiler_ir.h
+++ b/compiler/dex/compiler_ir.h
@@ -18,25 +18,18 @@
 #define ART_COMPILER_DEX_COMPILER_IR_H_
 
 #include <vector>
-#include <llvm/IR/Module.h>
+
 #include "compiler_enums.h"
 #include "dex/quick/mir_to_lir.h"
 #include "dex_instruction.h"
 #include "driver/compiler_driver.h"
 #include "driver/dex_compilation_unit.h"
-#include "llvm/intrinsic_helper.h"
-#include "llvm/ir_builder.h"
 #include "safe_map.h"
 #include "base/timing_logger.h"
 #include "utils/arena_allocator.h"
 
 namespace art {
 
-class LLVMInfo;
-namespace llvm {
-class LlvmCompilationUnit;
-}  // namespace llvm
-
 struct ArenaMemBlock;
 class Backend;
 struct Memstats;
diff --git a/compiler/dex/mir_graph.cc b/compiler/dex/mir_graph.cc
index dfd8e63..e4550d1 100644
--- a/compiler/dex/mir_graph.cc
+++ b/compiler/dex/mir_graph.cc
@@ -14,14 +14,16 @@
  * limitations under the License.
  */
 
+#include "mir_graph.h"
+
+#include <inttypes.h>
+
 #include "base/stl_util.h"
 #include "compiler_internals.h"
 #include "dex_file-inl.h"
-#include "leb128.h"
-#include "mir_graph.h"
-
 #include "dex/quick/dex_file_to_method_inliner_map.h"
 #include "dex/quick/dex_file_method_inliner.h"
+#include "leb128.h"
 
 namespace art {
 
diff --git a/compiler/dex/quick/x86/target_x86.cc b/compiler/dex/quick/x86/target_x86.cc
index 8e04e64..fa9a944 100644
--- a/compiler/dex/quick/x86/target_x86.cc
+++ b/compiler/dex/quick/x86/target_x86.cc
@@ -14,13 +14,14 @@
  * limitations under the License.
  */
 
+#include <string>
+#include <inttypes.h>
+
 #include "codegen_x86.h"
 #include "dex/compiler_internals.h"
 #include "dex/quick/mir_to_lir-inl.h"
 #include "x86_lir.h"
 
-#include <string>
-
 namespace art {
 
 // FIXME: restore "static" when usage uncovered
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index b46ae2b..5adb792 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -293,9 +293,6 @@
                                               jobject class_loader,
                                               const art::DexFile& dex_file);
 
-extern "C" void compilerLLVMSetBitcodeFileName(art::CompilerDriver& driver,
-                                               std::string const& filename);
-
 CompilerDriver::CompilerDriver(VerificationResults* verification_results,
                                DexFileToMethodInlinerMap* method_inliner_map,
                                CompilerBackend::Kind compiler_backend_kind,
@@ -2017,16 +2014,6 @@
   return it->second;
 }
 
-void CompilerDriver::SetBitcodeFileName(std::string const& filename) {
-  typedef void (*SetBitcodeFileNameFn)(CompilerDriver&, std::string const&);
-
-  SetBitcodeFileNameFn set_bitcode_file_name =
-    reinterpret_cast<SetBitcodeFileNameFn>(compilerLLVMSetBitcodeFileName);
-
-  set_bitcode_file_name(*this, filename);
-}
-
-
 void CompilerDriver::AddRequiresConstructorBarrier(Thread* self, const DexFile* dex_file,
                                                    uint16_t class_def_index) {
   WriterMutexLock mu(self, freezing_constructor_lock_);
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index da4b69d..092fe52 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -260,8 +260,6 @@
                      size_t literal_offset)
       LOCKS_EXCLUDED(compiled_methods_lock_);
 
-  void SetBitcodeFileName(std::string const& filename);
-
   bool GetSupportBootImageFixup() const {
     return support_boot_image_fixup_;
   }
diff --git a/compiler/elf_writer.cc b/compiler/elf_writer.cc
index ba5f1cb..6db3fa1 100644
--- a/compiler/elf_writer.cc
+++ b/compiler/elf_writer.cc
@@ -23,7 +23,6 @@
 #include "driver/compiler_driver.h"
 #include "elf_file.h"
 #include "invoke_type.h"
-#include "llvm/utils_llvm.h"
 #include "mirror/art_method-inl.h"
 #include "mirror/object-inl.h"
 #include "oat.h"
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 7f88471..dab419f 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -287,9 +287,7 @@
                                                         dump_passes,
                                                         &compiler_phases_timings));
 
-    if (compiler_backend_ == CompilerBackend::kPortable) {
-      driver->SetBitcodeFileName(bitcode_filename);
-    }
+    driver->GetCompilerBackend()->SetBitcodeFileName(bitcode_filename);
 
     driver->CompileAll(class_loader, dex_files, timings);