Add Compiler::ArchType. And fix the CodeModel and NoFramePointerElim.

Details: Add static member Compiler::ArchType and determine its value during the
Compiler::GlobalInitialization() according to the given triple.

Determine values of the option NoFramePointerElim and CodeModel in
CompilerOption.

Change-Id: I4432ee0c81d379a61df9355bc8079f2093936563
diff --git a/lib/ExecutionEngine/CompilerOption.h b/lib/ExecutionEngine/CompilerOption.h
index 92754f0..cb6a5de 100644
--- a/lib/ExecutionEngine/CompilerOption.h
+++ b/lib/ExecutionEngine/CompilerOption.h
@@ -18,6 +18,7 @@
 #define BCC_COMPILER_OPTION_H
 
 #include "Config.h"
+#include "Compiler.h"
 
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Support/CodeGen.h"
@@ -34,10 +35,29 @@
   // here means the configuration for running RenderScript (more specifically,
   // one can declare a CompilerOption object (call default constructor) and then
   // pass to the Compiler::compiler() without any modification for RenderScript,
-  // see Script::prepareExecutable(...))
+  // see Script::prepareExecutable(...)).
+  //
+  // Must be invoked after call Compiler::GlobalInitialization() at least once.
+  //
   CompilerOption() {
     //-- Setup options to llvm::TargetMachine --//
 
+    //-- Setup Frame Pointer Elimination Optimization --//
+#if defined(__HOST__)
+    // Disable frame pointer elimination optimization for X86_64 and X86
+    if ((Compiler::getTargetArchType() == llvm::Triple::x86_64) ||
+        (Compiler::getTargetArchType() == llvm::Triple::x86))
+      TargetOpt.NoFramePointerElim = true;
+    else
+      TargetOpt.NoFramePointerElim = false;
+#elif defined(DEFAULT_X86_64_CODEGEN)
+    TargetOpt.NoFramePointerElim = true;
+#elif defined(DEFAULT_X86_CODEGEN)
+    TargetOpt.NoFramePointerElim = true;
+#else
+    TargetOpt.NoFramePointerElim = false;
+#endif
+
     // Use hardfloat ABI
     //
     // TODO(all): Need to detect the CPU capability and decide whether to use
@@ -51,6 +71,19 @@
     //-- Setup relocation model  --//
     RelocModelOpt = llvm::Reloc::Static;
 
+    //-- Setup code model  --//
+#if defined(__HOST__)
+    // Data address in X86_64 architecture may reside in a far-away place
+    if (Compiler::getTargetArchType() == llvm::Triple::x86_64)
+      CodeModelOpt = llvm::CodeModel::Medium;
+    else
+      CodeModelOpt = llvm::CodeModel::Small;
+#elif defined(DEFAULT_X86_64_CODEGEN)
+    CodeModelOpt = llvm::CodeModel::Medium;
+#else
+    CodeModelOpt = llvm::CodeModel::Small;
+#endif
+
     //-- Load the result object after successful compilation  --//
     LoadAfterCompile = true;
   }