am 63acc68f: Reconcile with ics-mr1-release

* commit '63acc68fdda04376dbba33b875be49ba0897d1cd':
diff --git a/Android.mk b/Android.mk
index 2d1245b..b02b51b 100644
--- a/Android.mk
+++ b/Android.mk
@@ -73,9 +73,11 @@
 
 LOCAL_SRC_FILES := lib/ExecutionEngine/bcc.cpp
 
-LOCAL_WHOLE_STATIC_LIBRARIES += \
-  $(libbcc_WHOLE_STATIC_LIBRARIES) \
-  libbccCompilerRT
+LOCAL_WHOLE_STATIC_LIBRARIES := $(libbcc_WHOLE_STATIC_LIBRARIES)
+
+ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm x86))
+LOCAL_WHOLE_STATIC_LIBRARIES += libbccCompilerRT
+endif
 
 ifeq ($(libbcc_USE_MCJIT),1)
   LOCAL_STATIC_LIBRARIES += librsloader
@@ -87,11 +89,15 @@
       libLLVMARMDisassembler \
       libLLVMARMAsmPrinter
   else
-    ifeq ($(TARGET_ARCH),x86)
-      LOCAL_STATIC_LIBRARIES += \
-        libLLVMX86Disassembler
+    ifeq ($(TARGET_ARCH),mips)
+	  $(error "Disassembler is not available for MIPS architecture")
     else
-      $(error Unsupported TARGET_ARCH $(TARGET_ARCH))
+      ifeq ($(TARGET_ARCH),x86)
+        LOCAL_STATIC_LIBRARIES += \
+          libLLVMX86Disassembler
+      else
+        $(error Unsupported TARGET_ARCH $(TARGET_ARCH))
+      endif
     endif
   endif
 endif
@@ -102,15 +108,23 @@
     libLLVMARMDesc \
     libLLVMARMInfo
 else
-  ifeq ($(TARGET_ARCH),x86) # We don't support x86-64 right now
+  ifeq ($(TARGET_ARCH), mips)
     LOCAL_STATIC_LIBRARIES += \
-      libLLVMX86CodeGen \
-      libLLVMX86Desc \
-      libLLVMX86Info \
-      libLLVMX86Utils \
-      libLLVMX86AsmPrinter
+      libLLVMMipsCodeGen \
+      libLLVMMipsAsmPrinter \
+      libLLVMMipsDesc \
+      libLLVMMipsInfo
   else
-    $(error Unsupported TARGET_ARCH $(TARGET_ARCH))
+    ifeq ($(TARGET_ARCH),x86) # We don't support x86-64 right now
+      LOCAL_STATIC_LIBRARIES += \
+        libLLVMX86CodeGen \
+        libLLVMX86Desc \
+        libLLVMX86Info \
+        libLLVMX86Utils \
+        libLLVMX86AsmPrinter
+    else
+      $(error Unsupported TARGET_ARCH $(TARGET_ARCH))
+    endif
   endif
 endif
 
@@ -135,13 +149,19 @@
 
 LOCAL_SHARED_LIBRARIES := libdl libcutils libutils libstlport
 
-# Modules that need get installed if and only if the target libbcc.so is installed.
+# Modules that need get installed if and only if the target libbcc.so is
+# installed.
 LOCAL_REQUIRED_MODULES := libclcore.bc libbcc.so.sha1
 
-# -Wl,--exclude-libs=ALL only applies to library archives. It would hide most of
-# the symbols in this shared library. As a result, it reduced the size of libbcc.so
-# by about 800k in 2010.
-# Note that libLLVMBitReader:libLLVMCore:libLLVMSupport are used by pixelflinger2.
+# Link-Time Optimization on libbcc.so
+#
+# -Wl,--exclude-libs=ALL only applies to library archives. It would hide most
+# of the symbols in this shared library. As a result, it reduced the size of
+# libbcc.so by about 800k in 2010.
+#
+# Note that libLLVMBitReader:libLLVMCore:libLLVMSupport are used by
+# pixelflinger2.
+
 LOCAL_LDFLAGS += -Wl,--exclude-libs=libLLVMARMDisassembler:libLLVMARMAsmPrinter:libLLVMX86Disassembler:libLLVMX86AsmPrinter:libLLVMMCParser:libLLVMARMCodeGen:libLLVMARMDesc:libLLVMARMInfo:libLLVMSelectionDAG:libLLVMAsmPrinter:libLLVMCodeGen:libLLVMLinker:libLLVMJIT:libLLVMTarget:libLLVMMC:libLLVMScalarOpts:libLLVMInstCombine:libLLVMipo:libLLVMipa:libLLVMTransformUtils:libLLVMAnalysis
 
 # Generate build stamp (Build time + Build git revision + Build Semi SHA1)
@@ -155,6 +175,7 @@
 #=====================================================================
 # Host Shared Library libbcc
 #=====================================================================
+
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := libbcc
@@ -163,6 +184,7 @@
 LOCAL_IS_HOST_MODULE := true
 
 LOCAL_CFLAGS := $(libbcc_CFLAGS)
+LOCAL_CFLAGS += -D__HOST__
 LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
 
 LOCAL_SRC_FILES := lib/ExecutionEngine/bcc.cpp
@@ -182,16 +204,24 @@
 endif
 
 LOCAL_STATIC_LIBRARIES += \
-  libcutils \
-  libutils \
   libLLVMARMCodeGen \
   libLLVMARMDesc \
-  libLLVMARMInfo \
+  libLLVMARMInfo
+
+LOCAL_STATIC_LIBRARIES += \
+  libLLVMMipsCodeGen \
+  libLLVMMipsAsmPrinter \
+  libLLVMMipsDesc \
+  libLLVMMipsInfo
+
+LOCAL_STATIC_LIBRARIES += \
   libLLVMX86CodeGen \
   libLLVMX86Desc \
-  libLLVMX86Info \
-  libLLVMX86Utils \
   libLLVMX86AsmPrinter \
+  libLLVMX86Info \
+  libLLVMX86Utils
+
+LOCAL_STATIC_LIBRARIES += \
   libLLVMAsmPrinter \
   libLLVMBitReader \
   libLLVMSelectionDAG \
@@ -210,24 +240,15 @@
   libLLVMCore \
   libLLVMSupport
 
+LOCAL_STATIC_LIBRARIES += \
+  libcutils \
+  libutils
+
 LOCAL_LDLIBS := -ldl -lpthread
 
 # Generate build stamp (Build time + Build git revision + Build Semi SHA1)
 include $(LOCAL_PATH)/libbcc-gen-build-stamp.mk
 
-# definitions for LLVM
-LOCAL_CFLAGS += -DDEBUG_CODEGEN=1
-
-ifeq ($(TARGET_ARCH),arm)
-  LOCAL_CFLAGS += -DFORCE_ARM_CODEGEN=1
-else
-  ifeq ($(TARGET_ARCH),x86)
-    LOCAL_CFLAGS += -DFORCE_X86_CODEGEN=1
-  else
-    $(error Unsupported TARGET_ARCH $(TARGET_ARCH))
-  endif
-endif
-
 include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
 include $(LLVM_ROOT_PATH)/llvm-host-build.mk
 include $(BUILD_HOST_SHARED_LIBRARY)
diff --git a/Config.h b/Config.h
index 4141491..ebe0044 100644
--- a/Config.h
+++ b/Config.h
@@ -30,13 +30,20 @@
 #define USE_DISASSEMBLER 0
 #endif
 
+#if defined(__HOST__)
+#define DEBUG_OLD_JIT_DISASSEMBLER_FILE "/tmp/oldjit-dis.s"
+#define DEBUG_MCJIT_DISASSEMBLER_FILE "/tmp/mcjit-dis.s"
+#else
 #define DEBUG_OLD_JIT_DISASSEMBLER_FILE "/data/local/tmp/oldjit-dis.s"
 #define DEBUG_MCJIT_DISASSEMBLER_FILE "/data/local/tmp/mcjit-dis.s"
+#endif // defined(__HOST__)
 
 //---------------------------------------------------------------------------
 // Configuration for ContextManager
 //---------------------------------------------------------------------------
 
+#if USE_OLD_JIT
+
 // Note: Most of the code should NOT use these constants.  Use the public
 // static member of ContextManager instead, which is type-safe.  For example,
 // if you need BCC_CONTEXT_FIXED_ADDR_, then you should write:
@@ -50,6 +57,8 @@
 
 #define BCC_CONTEXT_DATA_SIZE_ (128 * 1024)
 
+#endif // USE_OLD_JIT
+
 //---------------------------------------------------------------------------
 // Configuration for CodeGen and CompilerRT
 //---------------------------------------------------------------------------
@@ -58,6 +67,10 @@
   #define PROVIDE_ARM_CODEGEN
   #define DEFAULT_ARM_CODEGEN
 
+#elif defined(FORCE_MIPS_CODEGEN)
+  #define PROVIDE_MIPS_CODEGEN
+  #define DEFAULT_MIPS_CODEGEN
+
 #elif defined(FORCE_X86_CODEGEN)
   #define PROVIDE_X86_CODEGEN
 
@@ -69,10 +82,13 @@
 
 #else
   #define PROVIDE_ARM_CODEGEN
+  #define PROVIDE_MIPS_CODEGEN
   #define PROVIDE_X86_CODEGEN
 
   #if defined(__arm__)
     #define DEFAULT_ARM_CODEGEN
+  #elif defined(__mips__)
+    #define DEFAULT_MIPS_CODEGEN
   #elif defined(__i386__)
     #define DEFAULT_X86_CODEGEN
   #elif defined(__x86_64__)
@@ -81,11 +97,13 @@
 #endif
 
 #if defined(DEFAULT_ARM_CODEGEN)
-  #define TARGET_TRIPLE_STRING "armv7-none-linux-gnueabi"
+  #define DEFAULT_TARGET_TRIPLE_STRING "armv7-none-linux-gnueabi"
+#elif defined(DEFAULT_MIPS_CODEGEN)
+  #define DEFAULT_TARGET_TRIPLE_STRING "mipsel-none-linux-gnueabi"
 #elif defined(DEFAULT_X86_CODEGEN)
-  #define TARGET_TRIPLE_STRING "i686-unknown-linux"
+  #define DEFAULT_TARGET_TRIPLE_STRING "i686-unknown-linux"
 #elif defined(DEFAULT_X86_64_CODEGEN)
-  #define TARGET_TRIPLE_STRING "x86_64-unknown-linux"
+  #define DEFAULT_TARGET_TRIPLE_STRING "x86_64-unknown-linux"
 #endif
 
 #if (defined(__VFP_FP__) && !defined(__SOFTFP__))
diff --git a/bcinfo/BitReader_2_7/Android.mk b/bcinfo/BitReader_2_7/Android.mk
index 9ccc99f..b738000 100644
--- a/bcinfo/BitReader_2_7/Android.mk
+++ b/bcinfo/BitReader_2_7/Android.mk
@@ -13,6 +13,8 @@
 
 LOCAL_SRC_FILES := $(bitcode_reader_2_7_SRC_FILES)
 
+LOCAL_CFLAGS += -D__HOST__
+
 LOCAL_MODULE:= libLLVMBitReader_2_7
 
 LOCAL_MODULE_TAGS := optional
diff --git a/bcinfo/BitReader_2_7/BitcodeReader.cpp b/bcinfo/BitReader_2_7/BitcodeReader.cpp
index d2449de..2edb153 100644
--- a/bcinfo/BitReader_2_7/BitcodeReader.cpp
+++ b/bcinfo/BitReader_2_7/BitcodeReader.cpp
@@ -590,7 +590,7 @@
       ResultTy = PointerType::get(ResultTy, AddressSpace);
       break;
     }
-    case bitc::TYPE_CODE_FUNCTION: {
+    case bitc::TYPE_CODE_FUNCTION_OLD: {
       // FIXME: attrid is dead, remove it in LLVM 3.0
       // FUNCTION: [vararg, attrid, retty, paramty x N]
       if (Record.size() < 3)
@@ -846,7 +846,7 @@
         ResultTy = PointerType::get(ResultTy, AddressSpace);
       break;
     }
-    case bitc::TYPE_CODE_FUNCTION: {
+    case bitc::TYPE_CODE_FUNCTION_OLD: {
       // FIXME: attrid is dead, remove it in LLVM 3.0
       // FUNCTION: [vararg, attrid, retty, paramty x N]
       if (Record.size() < 3)
diff --git a/bcinfo/tools/Android.mk b/bcinfo/tools/Android.mk
index 08b9ad7..0d99f71 100644
--- a/bcinfo/tools/Android.mk
+++ b/bcinfo/tools/Android.mk
@@ -28,6 +28,8 @@
 LOCAL_SHARED_LIBRARIES := \
   libbcinfo
 
+LOCAL_CFLAGS += -D__HOST__
+
 LOCAL_C_INCLUDES := \
   $(LOCAL_PATH)/../../include
 
diff --git a/helper/Android.mk b/helper/Android.mk
index b19c131..ecba95f 100644
--- a/helper/Android.mk
+++ b/helper/Android.mk
@@ -52,6 +52,8 @@
 LOCAL_IS_HOST_MODULE := true
 
 LOCAL_CFLAGS += $(libbcc_CFLAGS)
+LOCAL_CFLAGS += -D__HOST__
+
 LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
 
 LOCAL_SRC_FILES := \
diff --git a/helper/DebugHelper.c b/helper/DebugHelper.c
index 87f0102..5c01b1b 100644
--- a/helper/DebugHelper.c
+++ b/helper/DebugHelper.c
@@ -24,6 +24,6 @@
     tag = "";
   }
 
-  return fprintf(stderr, "[%s] %s", tag, msg);
+  return fprintf(stderr, "[%s] %s\n", tag, msg);
 }
 #endif // USE_LOGGER && !defined(__arm__)
diff --git a/helper/DebugHelper.h b/helper/DebugHelper.h
index 475ed2e..c66e87f 100644
--- a/helper/DebugHelper.h
+++ b/helper/DebugHelper.h
@@ -26,14 +26,14 @@
 
 #else // !USE_LOGGER
 
-#undef LOGV
+#undef ALOGV
 #undef LOGI
 #undef LOGD
 #undef LOGW
 #undef LOGE
 #undef LOGA
 
-#define LOGV(...)
+#define ALOGV(...)
 #define LOGI(...)
 #define LOGD(...)
 #define LOGW(...)
diff --git a/lib/CodeGen/Android.mk b/lib/CodeGen/Android.mk
index 1e293b2..0eacfa1 100644
--- a/lib/CodeGen/Android.mk
+++ b/lib/CodeGen/Android.mk
@@ -60,6 +60,7 @@
 LOCAL_IS_HOST_MODULE := true
 
 LOCAL_CFLAGS += $(libbcc_CFLAGS)
+LOCAL_CFLAGS += -D__HOST__
 LOCAL_C_INCLUDES += $(libbcc_C_INCLUDES)
 
 LOCAL_SRC_FILES := $(libbcc_codegen_SRC_FILES)
diff --git a/lib/CodeGen/CodeEmitter.cpp b/lib/CodeGen/CodeEmitter.cpp
index fedb65b..c3f37e1 100644
--- a/lib/CodeGen/CodeEmitter.cpp
+++ b/lib/CodeGen/CodeEmitter.cpp
@@ -53,7 +53,7 @@
 
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/Target/TargetRegistry.h"
+#include "llvm/Support/TargetRegistry.h"
 #include "llvm/Target/TargetJITInfo.h"
 
 #include "llvm/Constant.h"
diff --git a/lib/Disassembler/Android.mk b/lib/Disassembler/Android.mk
index 1b5ff4d..1d925ed 100644
--- a/lib/Disassembler/Android.mk
+++ b/lib/Disassembler/Android.mk
@@ -59,6 +59,7 @@
 LOCAL_IS_HOST_MODULE := true
 
 LOCAL_CFLAGS += $(libbcc_CFLAGS)
+LOCAL_CFLAGS += -D__HOST__
 LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
 
 LOCAL_SRC_FILES := $(libbcc_disassembler_SRC_FILES)
diff --git a/lib/Disassembler/Disassembler.cpp b/lib/Disassembler/Disassembler.cpp
index d0e6000..5011fa3 100644
--- a/lib/Disassembler/Disassembler.cpp
+++ b/lib/Disassembler/Disassembler.cpp
@@ -32,8 +32,8 @@
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
-#include "llvm/Target/TargetRegistry.h"
-#include "llvm/Target/TargetSelect.h"
+#include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/TargetSelect.h"
 
 #include "llvm/LLVMContext.h"
 
@@ -98,13 +98,15 @@
   OS << "Disassembled code: " << Name << "\n";
 
   const llvm::MCAsmInfo *AsmInfo;
+  const llvm::MCSubtargetInfo *SubtargetInfo;
   const llvm::MCDisassembler *Disassmbler;
   llvm::MCInstPrinter *IP;
 
   AsmInfo = Target->createMCAsmInfo(Compiler::getTargetTriple());
-  Disassmbler = Target->createMCDisassembler();
+  SubtargetInfo = Target->createMCSubtargetInfo(Compiler::getTargetTriple(), "", "");
+  Disassmbler = Target->createMCDisassembler(*SubtargetInfo);
   IP = Target->createMCInstPrinter(AsmInfo->getAssemblerDialect(),
-                                   *AsmInfo);
+                                   *AsmInfo, *SubtargetInfo);
 
   const BufferMemoryObject *BufferMObj = new BufferMemoryObject(Func, FuncSize);
 
@@ -115,13 +117,13 @@
     llvm::MCInst Inst;
 
     if (Disassmbler->getInstruction(Inst, Size, *BufferMObj, Index,
-                                    /* REMOVED */ llvm::nulls())) {
+                           /* REMOVED */ llvm::nulls(), llvm::nulls())) {
       OS.indent(4);
       OS.write("0x", 2);
       OS.write_hex((uint32_t)Func + Index);
       OS.write(": 0x", 4);
       OS.write_hex(*(uint32_t *)(Func + Index));
-      IP->printInst(&Inst, OS);
+      IP->printInst(&Inst, OS, "");
       OS << "\n";
     } else {
       if (Size == 0)
diff --git a/lib/ExecutionEngine/Android.mk b/lib/ExecutionEngine/Android.mk
index 695a975..e222a41 100644
--- a/lib/ExecutionEngine/Android.mk
+++ b/lib/ExecutionEngine/Android.mk
@@ -89,6 +89,7 @@
 LOCAL_IS_HOST_MODULE := true
 
 LOCAL_CFLAGS += $(libbcc_CFLAGS)
+LOCAL_CFLAGS += -D__HOST__
 LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
 
 LOCAL_SRC_FILES := $(libbcc_executionengine_SRC_FILES)
diff --git a/lib/ExecutionEngine/Compiler.cpp b/lib/ExecutionEngine/Compiler.cpp
index be67bdf..f456066 100644
--- a/lib/ExecutionEngine/Compiler.cpp
+++ b/lib/ExecutionEngine/Compiler.cpp
@@ -91,6 +91,20 @@
 
 bool Compiler::GlobalInitialized = false;
 
+
+#if !defined(__HOST__)
+  #define TARGET_TRIPLE_STRING  DEFAULT_TARGET_TRIPLE_STRING
+#else
+// In host TARGET_TRIPLE_STRING is a variable to allow cross-compilation.
+  #if defined(__cplusplus)
+    extern "C" {
+  #endif
+      char *TARGET_TRIPLE_STRING = (char*)DEFAULT_TARGET_TRIPLE_STRING;
+  #if defined(__cplusplus)
+    };
+  #endif
+#endif
+
 // Code generation optimization level for the compiler
 llvm::CodeGenOpt::Level Compiler::CodeGenOptLevel;
 
@@ -121,8 +135,10 @@
 //////////////////////////////////////////////////////////////////////////////
 
 void Compiler::GlobalInitialization() {
-  if (GlobalInitialized)
+  if (GlobalInitialized) {
     return;
+  }
+
   // if (!llvm::llvm_is_multithreaded())
   //   llvm::llvm_start_multithreaded();
 
@@ -138,19 +154,19 @@
 #endif
 #endif
 
-  // NOTE: Currently, we have to turn off the support for NEON explicitly.
-  // Since the ARMCodeEmitter.cpp is not ready for JITing NEON
-  // instructions.
-
-  // FIXME: Re-enable NEON when ARMCodeEmitter supports NEON.
-#define USE_ARM_NEON 0
-#if USE_ARM_NEON
+#if defined(ARCH_ARM_HAVE_NEON)
   Features.push_back("+neon");
   Features.push_back("+neonfp");
 #else
   Features.push_back("-neon");
   Features.push_back("-neonfp");
-#endif // USE_ARM_NEON
+#endif
+
+#if defined(DISABLE_ARCH_ARM_HAVE_NEON)
+  Features.push_back("-neon");
+  Features.push_back("-neonfp");
+#endif
+
 #endif // DEFAULT_ARM_CODEGEN
 
 #if defined(PROVIDE_ARM_CODEGEN)
@@ -160,6 +176,13 @@
   LLVMInitializeARMTarget();
 #endif
 
+#if defined(PROVIDE_MIPS_CODEGEN)
+  LLVMInitializeMipsAsmPrinter();
+  LLVMInitializeMipsTargetMC();
+  LLVMInitializeMipsTargetInfo();
+  LLVMInitializeMipsTarget();
+#endif
+
 #if defined(PROVIDE_X86_CODEGEN)
   LLVMInitializeX86AsmPrinter();
   LLVMInitializeX86TargetMC();
@@ -202,7 +225,7 @@
   llvm::RegisterRegAlloc::setDefault
     ((CodeGenOptLevel == llvm::CodeGenOpt::None) ?
      llvm::createFastRegisterAllocator :
-     llvm::createLinearScanRegisterAllocator);
+     llvm::createGreedyRegisterAllocator);
 
 #if USE_CACHE
   // Read in SHA1 checksum of libbcc and libRS.
@@ -663,8 +686,7 @@
 
   // Add MC code generation passes to pass manager
   llvm::MCContext *Ctx;
-  if (TM->addPassesToEmitMC(MCCodeGenPasses, Ctx, OutSVOS,
-                            CodeGenOptLevel, false)) {
+  if (TM->addPassesToEmitMC(MCCodeGenPasses, Ctx, OutSVOS, false)) {
     setError("Fail to add passes to emit file");
     return 1;
   }
diff --git a/lib/ExecutionEngine/FileHandle.cpp b/lib/ExecutionEngine/FileHandle.cpp
index 1055ea7..7238025 100644
--- a/lib/ExecutionEngine/FileHandle.cpp
+++ b/lib/ExecutionEngine/FileHandle.cpp
@@ -94,7 +94,7 @@
     }
 
     // Good, we have open and lock the file correctly.
-    LOGV("File opened. fd=%d\n", mFD);
+    ALOGV("File opened. fd=%d\n", mFD);
     return mFD;
   }
 
@@ -107,7 +107,7 @@
   if (mFD >= 0) {
     flock(mFD, LOCK_UN);
     ::close(mFD);
-    LOGV("File closed. fd=%d\n", mFD);
+    ALOGV("File closed. fd=%d\n", mFD);
     mFD = -1;
   }
 }
diff --git a/lib/ExecutionEngine/Runtime.c b/lib/ExecutionEngine/Runtime.c
index f940c35..6b9e20d 100644
--- a/lib/ExecutionEngine/Runtime.c
+++ b/lib/ExecutionEngine/Runtime.c
@@ -27,7 +27,7 @@
   void *mPtr;
 } RuntimeFunction;
 
-#if defined(__arm__)
+#if defined(__arm__) || defined(__mips__)
   #define DEF_GENERIC_RUNTIME(func)   \
     extern void *func;
   #define DEF_VFP_RUNTIME(func) \
@@ -38,7 +38,7 @@
 #endif
 
 static const RuntimeFunction gRuntimes[] = {
-#if defined(__arm__)
+#if defined(__arm__) || defined(__mips__)
   #define DEF_GENERIC_RUNTIME(func)   \
     { #func, (void*) &func },
   // TODO: enable only when target support VFP
diff --git a/lib/ExecutionEngine/Runtime.def b/lib/ExecutionEngine/Runtime.def
index e15aa11..e4a6875 100644
--- a/lib/ExecutionEngine/Runtime.def
+++ b/lib/ExecutionEngine/Runtime.def
@@ -93,9 +93,12 @@
 #if !defined(__i386__) && !defined(__SSE2__)
     DEF_LLVM_RUNTIME(__ashldi3)
 #endif
-#ifndef ANDROID // has one in bionic
+#if !defined(ANDROID) /* has one in bionic */
     DEF_LLVM_RUNTIME(__ashrdi3)
 #endif
+#if defined(__mips__)
+    DEF_GENERIC_RUNTIME(__ashrdi3)
+#endif
 
 #ifdef USE_VFP_RUNTIME
 //    DEF_GENERIC_RUNTIME(__bswapdi2)
@@ -108,7 +111,7 @@
 DEF_LLVM_RUNTIME(__ctzdi2)
 DEF_LLVM_RUNTIME(__ctzsi2)
 
-#ifndef ANDROID // no complex extension
+#if !defined(ANDROID) /* no complex extension */
     DEF_LLVM_RUNTIME(__divdc3)
 #endif
 
@@ -119,7 +122,7 @@
 #endif
 DEF_LLVM_RUNTIME(__divsi3)
 
-#ifndef ANDROID // no complex extension
+#if !defined(ANDROID) /* no complex extension */
     DEF_LLVM_RUNTIME(__divsc3)
 #endif
 
diff --git a/libbcc-build-rules.mk b/libbcc-build-rules.mk
index 898002c..a065ed6 100644
--- a/libbcc-build-rules.mk
+++ b/libbcc-build-rules.mk
@@ -37,10 +37,14 @@
       LOCAL_CFLAGS += -DARCH_ARM_HAVE_NEON
     endif
   else
-    ifeq ($(TARGET_ARCH),x86)
-      LOCAL_CFLAGS += -DFORCE_X86_CODEGEN
+    ifeq ($(TARGET_ARCH),mips)
+      LOCAL_CFLAGS += -DFORCE_MIPS_CODEGEN
     else
-      $(error Unsupported architecture $(TARGET_ARCH))
+      ifeq ($(TARGET_ARCH),x86)
+        LOCAL_CFLAGS += -DFORCE_X86_CODEGEN
+      else
+        $(error Unsupported architecture $(TARGET_ARCH))
+      endif
     endif
   endif
 
diff --git a/runtime/Android.mk b/runtime/Android.mk
index 39e662a..c2051ec 100644
--- a/runtime/Android.mk
+++ b/runtime/Android.mk
@@ -22,6 +22,8 @@
 # Device Static Library: libbccCompilerRT
 #=====================================================================
 
+ifneq ($(TARGET_ARCH),mips)
+
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := libbccCompilerRT
@@ -88,3 +90,5 @@
 
 include $(LIBBCC_ROOT_PATH)/libbcc-build-rules.mk
 include $(BUILD_STATIC_LIBRARY)
+
+endif # ifneq($(TARGET_ARCH),mips)
diff --git a/tests/Android.mk b/tests/Android.mk
index f57fe47..19637a5 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -35,6 +35,8 @@
 
 LOCAL_LDLIBS = -ldl
 
+LOCAL_CFLAGS += -D__HOST__
+
 include $(BUILD_HOST_EXECUTABLE)
 
 # Executable for target
diff --git a/tests/main.cpp b/tests/main.cpp
index 189d7e6..2e85d27 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -29,6 +29,20 @@
 
 #include <unistd.h>
 
+#if defined(__HOST__)
+  #if defined(__cplusplus)
+    extern "C" {
+  #endif
+      extern char *TARGET_TRIPLE_STRING;
+  #if defined(__cplusplus)
+    };
+  #endif
+#define GETOPT_OPTIONS  "C:RST"
+#else
+#define GETOPT_OPTIONS  "RST"
+#endif
+
+
 #if defined(__arm__)
 #define PROVIDE_ARM_DISASSEMBLY
 #endif
@@ -124,10 +138,16 @@
 static int parseOption(int argc, char** argv)
 {
   int c;
-  while ((c = getopt (argc, argv, "RST")) != -1) {
+  while ((c = getopt (argc, argv, GETOPT_OPTIONS)) != -1) {
     opterr = 0;
 
     switch(c) {
+    #if defined(__HOST__)
+      case 'C':
+        TARGET_TRIPLE_STRING = optarg;
+        break;
+    #endif
+
       case 'R':
         runResults = true;
         break;