Remove unnecessary inheritance for CompilerConfig, as we switch to offline bcc.

Change-Id: Id4a5be7b2b4627bfa7ef6279eb3b5b8e75915a7d
diff --git a/include/bcc/Support/CompilerConfig.h b/include/bcc/Support/CompilerConfig.h
index fec645b..f1ab339 100644
--- a/include/bcc/Support/CompilerConfig.h
+++ b/include/bcc/Support/CompilerConfig.h
@@ -50,11 +50,13 @@
 
   llvm::Reloc::Model mRelocModel;
 
+  // Are we set up to compile for full precision or something reduced?
+  bool mFullPrecision;
+
   // The list of target specific features to enable or disable -- this should
   // be a list of strings starting with '+' (enable) or '-' (disable).
   std::string mFeatureString;
 
-private:
   //===--------------------------------------------------------------------===//
   // These are generated by CompilerConfig during initialize().
   //===--------------------------------------------------------------------===//
@@ -62,7 +64,7 @@
   bool initializeTarget();
 
   llvm::Triple::ArchType mArchType;
-  void initializeArch();
+  bool initializeArch();
 
 public:
   //===--------------------------------------------------------------------===//
@@ -102,11 +104,19 @@
   inline llvm::Triple::ArchType getArchType() const
   { return mArchType; }
 
+  inline bool getFullPrecision() const
+  { return mFullPrecision; }
+  inline void setFullPrecision(bool pFullPrecision) {
+    mFullPrecision = pFullPrecision;
+    // Note that we have to reinitialize here to ensure that mFeatureString
+    // is up to date.
+    initializeArch();
+  }
+
   inline const std::string &getFeatureString() const
   { return mFeatureString; }
   void setFeatureString(const std::vector<std::string> &pAttrs);
 
-public:
   CompilerConfig(const std::string &pTriple);
 
   virtual ~CompilerConfig() { }
diff --git a/include/bcc/Support/TargetCompilerConfigs.h b/include/bcc/Support/TargetCompilerConfigs.h
deleted file mode 100644
index 9a2aadb..0000000
--- a/include/bcc/Support/TargetCompilerConfigs.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright 2012, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef BCC_SUPPORT_TARGET_COMPILER_CONFIGS_H
-#define BCC_SUPPORT_TARGET_COMPILER_CONFIGS_H
-
-#include "bcc/Config/Config.h"
-#include "bcc/Support/CompilerConfig.h"
-
-namespace bcc {
-
-//===----------------------------------------------------------------------===//
-// ARM
-//===----------------------------------------------------------------------===//
-#if defined(PROVIDE_ARM_CODEGEN)
-class ARMBaseCompilerConfig : public CompilerConfig {
-private:
-  bool mEnableNEON;
-  bool mInThumbMode;
-
-  static bool HasThumb2();
-
-  static void GetFeatureVector(std::vector<std::string> &pAttributes,
-                               bool pInThumbMode, bool pEnableNEON);
-
-protected:
-  ARMBaseCompilerConfig(const std::string &pTriple, bool pInThumbMode);
-
-public:
-  // Return true if config has been changed after returning from this function.
-  bool enableNEON(bool pEnable = true);
-
-  bool isInThumbMode() const
-  { return mInThumbMode; }
-};
-
-class ARMCompilerConfig : public ARMBaseCompilerConfig {
-public:
-  ARMCompilerConfig()
-    : ARMBaseCompilerConfig(DEFAULT_ARM_TRIPLE_STRING,
-                            /* pInThumbMode */false) { }
-};
-
-class ThumbCompilerConfig : public ARMBaseCompilerConfig {
-public:
-  ThumbCompilerConfig()
-    : ARMBaseCompilerConfig(DEFAULT_THUMB_TRIPLE_STRING,
-                            /* pInThumbMode */true) { }
-};
-#endif // defined(PROVIDE_ARM_CODEGEN)
-
-//===----------------------------------------------------------------------===//
-// ARM64
-//===----------------------------------------------------------------------===//
-#if defined(PROVIDE_ARM64_CODEGEN)
-class ARM64CompilerConfig : public CompilerConfig {
-public:
-  ARM64CompilerConfig() : CompilerConfig(DEFAULT_ARM64_TRIPLE_STRING) {
-
-  }
-};
-#endif // defined(PROVIDE_ARM64_CODEGEN)
-
-//===----------------------------------------------------------------------===//
-// MIPS
-//===----------------------------------------------------------------------===//
-#if defined(PROVIDE_MIPS_CODEGEN)
-class MipsCompilerConfig : public CompilerConfig {
-public:
-  MipsCompilerConfig() : CompilerConfig(DEFAULT_MIPS_TRIPLE_STRING) {
-    setRelocationModel(llvm::Reloc::Static);
-  }
-};
-#endif // defined(PROVIDE_MIPS_CODEGEN)
-
-//===----------------------------------------------------------------------===//
-// X86 and X86_64
-//===----------------------------------------------------------------------===//
-#if defined(PROVIDE_X86_CODEGEN)
-class X86FamilyCompilerConfigBase : public CompilerConfig {
-protected:
-  X86FamilyCompilerConfigBase(const std::string &pTriple)
-    : CompilerConfig(pTriple) {
-    // Disable frame pointer elimination optimization on x86 family.
-    getTargetOptions().NoFramePointerElim = true;
-    getTargetOptions().UseInitArray = true;
-    return;
-  }
-};
-
-class X86_32CompilerConfig : public X86FamilyCompilerConfigBase {
-public:
-  X86_32CompilerConfig() :
-      X86FamilyCompilerConfigBase(DEFAULT_X86_TRIPLE_STRING) { }
-};
-
-class X86_64CompilerConfig : public X86FamilyCompilerConfigBase {
-public:
-  X86_64CompilerConfig() :
-      X86FamilyCompilerConfigBase(DEFAULT_X86_64_TRIPLE_STRING) {
-    setCodeModel(llvm::CodeModel::Medium);
-  }
-};
-#endif // defined(PROVIDE_X86_CODEGEN)
-
-//===----------------------------------------------------------------------===//
-// Default target
-//===----------------------------------------------------------------------===//
-class DefaultCompilerConfig : public
-#if defined(DEFAULT_ARM_CODEGEN)
-  ARMCompilerConfig
-#elif defined(DEFAULT_MIPS_CODEGEN)
-  MipsCompilerConfig
-#elif defined(DEFAULT_X86_CODEGEN)
-  X86_32CompilerConfig
-#elif defined(DEFAULT_X86_64_CODEGEN)
-  X86_64CompilerConfig
-#elif defined(DEFAULT_ARM64_CODEGEN)
-  ARM64CompilerConfig
-#else
-#  error "Unsupported Default Target!"
-#endif
-{ };
-
-} // end namespace bcc
-
-#endif // BCC_SUPPORT_TARGET_COMPILER_CONFIGS_H
diff --git a/lib/Renderscript/RSCompilerDriver.cpp b/lib/Renderscript/RSCompilerDriver.cpp
index 346bd2f..dc04c2a 100644
--- a/lib/Renderscript/RSCompilerDriver.cpp
+++ b/lib/Renderscript/RSCompilerDriver.cpp
@@ -24,10 +24,10 @@
 #include "bcinfo/BitcodeWrapper.h"
 
 #include "bcc/Compiler.h"
+#include "bcc/Config/Config.h"
 #include "bcc/Renderscript/RSExecutable.h"
 #include "bcc/Renderscript/RSScript.h"
 #include "bcc/Support/CompilerConfig.h"
-#include "bcc/Support/TargetCompilerConfigs.h"
 #include "bcc/Source.h"
 #include "bcc/Support/FileMutex.h"
 #include "bcc/Support/Log.h"
@@ -150,7 +150,7 @@
   return result;
 }
 
-#if defined(DEFAULT_ARM_CODEGEN)
+#if defined(PROVIDE_ARM_CODEGEN)
 extern llvm::cl::opt<bool> EnableGlobalMerge;
 #endif
 
@@ -160,7 +160,7 @@
   const llvm::CodeGenOpt::Level script_opt_level =
       static_cast<llvm::CodeGenOpt::Level>(pScript.getOptimizationLevel());
 
-#if defined(DEFAULT_ARM_CODEGEN)
+#if defined(PROVIDE_ARM_CODEGEN)
   EnableGlobalMerge = mEnableGlobalMerge;
 #endif
 
@@ -173,7 +173,7 @@
     }
   } else {
     // Haven't run the compiler ever.
-    mConfig = new (std::nothrow) DefaultCompilerConfig();
+    mConfig = new (std::nothrow) CompilerConfig(DEFAULT_TARGET_TRIPLE_STRING);
     if (mConfig == NULL) {
       // Return false since mConfig remains NULL and out-of-memory.
       return false;
@@ -182,13 +182,13 @@
     changed = true;
   }
 
-#if defined(DEFAULT_ARM_CODEGEN)
-  // NEON should be disable when full-precision floating point is required.
+#if defined(PROVIDE_ARM_CODEGEN)
   assert((pScript.getInfo() != NULL) && "NULL RS info!");
-  if (pScript.getInfo()->getFloatPrecisionRequirement() == RSInfo::FP_Full) {
-    // Must be ARMCompilerConfig.
-    ARMCompilerConfig *arm_config = static_cast<ARMCompilerConfig *>(mConfig);
-    changed |= arm_config->enableNEON(/* pEnable */false);
+  bool script_full_prec = (pScript.getInfo()->getFloatPrecisionRequirement() ==
+                           RSInfo::FP_Full);
+  if (mConfig->getFullPrecision() != script_full_prec) {
+    mConfig->setFullPrecision(script_full_prec);
+    changed = true;
   }
 #endif
 
diff --git a/lib/Support/Android.mk b/lib/Support/Android.mk
index eb240c2..a4eee40 100644
--- a/lib/Support/Android.mk
+++ b/lib/Support/Android.mk
@@ -28,8 +28,7 @@
   Initialization.cpp \
   InputFile.cpp \
   OutputFile.cpp \
-  Sha1Util.cpp \
-  TargetCompilerConfigs.cpp
+  Sha1Util.cpp
 
 #=====================================================================
 # Device Static Library: libbccSupport
diff --git a/lib/Support/CompilerConfig.cpp b/lib/Support/CompilerConfig.cpp
index 8465fec..220628e 100644
--- a/lib/Support/CompilerConfig.cpp
+++ b/lib/Support/CompilerConfig.cpp
@@ -15,18 +15,19 @@
  */
 
 #include "bcc/Support/CompilerConfig.h"
+#include "bcc/Support/Properties.h"
 
 #include <llvm/CodeGen/SchedulerRegistry.h>
 #include <llvm/MC/SubtargetFeature.h>
+#include <llvm/Support/Host.h>
 #include <llvm/Support/TargetRegistry.h>
 
 #include "bcc/Support/Log.h"
-#include "bcc/Support/TargetCompilerConfigs.h"
 
 using namespace bcc;
 
 CompilerConfig::CompilerConfig(const std::string &pTriple)
-  : mTriple(pTriple), mTarget(NULL) {
+  : mTriple(pTriple), mFullPrecision(true), mTarget(NULL) {
   //===--------------------------------------------------------------------===//
   // Default setting of register sheduler
   //===--------------------------------------------------------------------===//
@@ -86,13 +87,103 @@
   }
 }
 
-void CompilerConfig::initializeArch() {
+bool CompilerConfig::initializeArch() {
   if (mTarget != NULL) {
     mArchType = llvm::Triple::getArchTypeForLLVMName(mTarget->getName());
   } else {
     mArchType = llvm::Triple::UnknownArch;
+    return false;
   }
-  return;
+
+  // Configure each architecture for any necessary additional flags.
+  switch (mArchType) {
+#if defined(PROVIDE_ARM_CODEGEN)
+  case llvm::Triple::arm: {
+    llvm::StringMap<bool> features;
+    llvm::sys::getHostCPUFeatures(features);
+    std::vector<std::string> attributes;
+
+#if defined(__HOST__) || defined(ARCH_ARM_HAVE_VFP)
+    attributes.push_back("+vfp3");
+#if !defined(__HOST__) && !defined(ARCH_ARM_HAVE_VFP_D32)
+    attributes.push_back("+d16");
+#endif  // !__HOST__ && !ARCH_ARM_HAVE_VFP_D32
+#endif  // __HOST__ || ARCH_ARM_HAVE_VFP
+
+#if defined(__HOST__) || defined(ARCH_ARM_HAVE_NEON)
+    // Only enable NEON on ARM if we have relaxed precision floats.
+    if (!mFullPrecision) {
+      attributes.push_back("+neon");
+    } else {
+#endif  // __HOST__ || ARCH_ARM_HAVE_NEON
+      attributes.push_back("-neon");
+      attributes.push_back("-neonfp");
+#if defined(__HOST__) || defined(ARCH_ARM_HAVE_NEON)
+    }
+#endif  // __HOST__ || ARCH_ARM_HAVE_NEON
+
+    if (!getProperty("debug.rs.arm-no-hwdiv")) {
+      if (features.count("hwdiv-arm") && features["hwdiv-arm"])
+        attributes.push_back("+hwdiv-arm");
+
+      if (features.count("hwdiv") && features["hwdiv"])
+        attributes.push_back("+hwdiv");
+    }
+
+    setFeatureString(attributes);
+
+#if defined(TARGET_BUILD)
+    if (!getProperty("debug.rs.arm-no-tune-for-cpu")) {
+      setCPU(llvm::sys::getHostCPUName());
+    }
+#endif  // TARGET_BUILD
+
+    break;
+  }
+#endif  // PROVIDE_ARM_CODEGEN
+
+#if defined(PROVIDE_ARM64_CODEGEN)
+  case llvm::Triple::aarch64:
+#if defined(TARGET_BUILD)
+    if (!getProperty("debug.rs.arm-no-tune-for-cpu")) {
+      setCPU(llvm::sys::getHostCPUName());
+    }
+#endif  // TARGET_BUILD
+    break;
+#endif  // PROVIDE_ARM64_CODEGEN
+
+#if defined (PROVIDE_MIPS_CODEGEN)
+  case llvm::Triple::mips:
+  case llvm::Triple::mipsel:
+  case llvm::Triple::mips64:
+  case llvm::Triple::mips64el:
+    setRelocationModel(llvm::Reloc::Static);
+    break;
+#endif  // PROVIDE_MIPS_CODEGEN
+
+#if defined (PROVIDE_X86_CODEGEN)
+  case llvm::Triple::x86:
+    // Disable frame pointer elimination optimization on x86 family.
+    getTargetOptions().NoFramePointerElim = true;
+    getTargetOptions().UseInitArray = true;
+    break;
+#endif  // PROVIDE_X86_CODEGEN
+
+#if defined (PROVIDE_X86_CODEGEN)
+  case llvm::Triple::x86_64:
+    setCodeModel(llvm::CodeModel::Medium);
+    // Disable frame pointer elimination optimization on x86 family.
+    getTargetOptions().NoFramePointerElim = true;
+    getTargetOptions().UseInitArray = true;
+    break;
+#endif  // PROVIDE_X86_CODEGEN
+
+  default:
+    ALOGE("Unsupported architecture type: %s", mTarget->getName());
+    return false;
+  }
+
+  return true;
 }
 
 void CompilerConfig::setFeatureString(const std::vector<std::string> &pAttrs) {
diff --git a/lib/Support/TargetCompilerConfigs.cpp b/lib/Support/TargetCompilerConfigs.cpp
deleted file mode 100644
index 102b031..0000000
--- a/lib/Support/TargetCompilerConfigs.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2012, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "bcc/Support/Properties.h"
-#include "bcc/Support/TargetCompilerConfigs.h"
-
-#include "llvm/ADT/StringMap.h"
-#include "llvm/Support/Host.h"
-
-// Get ARM version number (i.e., __ARM_ARCH__)
-#ifdef __arm__
-#include <machine/cpu-features.h>
-#endif
-
-using namespace bcc;
-
-//===----------------------------------------------------------------------===//
-// ARM
-//===----------------------------------------------------------------------===//
-#if defined(PROVIDE_ARM_CODEGEN)
-
-bool ARMBaseCompilerConfig::HasThumb2() {
-#if !defined(TARGET_BUILD)
-  // Cross-compiler can always generate Thumb-2 instructions.
-  return true;
-#else // defined(TARGET_BUILD)
-#  if (__ARM_ARCH__ >= 7) || defined(__ARM_ARCH_6T2__)
-  return true;
-#  else
-  // ARM prior to V6T2 doesn't support Thumb-2.
-  return false;
-#  endif
-#endif
-}
-
-void
-ARMBaseCompilerConfig::GetFeatureVector(std::vector<std::string> &pAttributes,
-                                        bool pInThumbMode, bool pEnableNEON) {
-  llvm::StringMap<bool> Features;
-  llvm::sys::getHostCPUFeatures(Features);
-
-#if defined(ARCH_ARM_HAVE_VFP)
-  pAttributes.push_back("+vfp3");
-#  if !defined(ARCH_ARM_HAVE_VFP_D32)
-  pAttributes.push_back("+d16");
-#  endif
-#endif
-
-  if (pInThumbMode) {
-    if (HasThumb2()) {
-      pAttributes.push_back("+thumb2");
-    } else {
-      pAttributes.push_back("-thumb2");
-    }
-  }
-
-#if defined(ARCH_ARM_HAVE_NEON)
-  if (pEnableNEON) {
-    pAttributes.push_back("+neon");
-  } else {
-#endif
-    pAttributes.push_back("-neon");
-    pAttributes.push_back("-neonfp");
-#if defined(ARCH_ARM_HAVE_NEON)
-  }
-#endif
-
-  if (!getProperty("debug.rs.arm-no-hwdiv")) {
-    if (Features.count("hwdiv-arm") && Features["hwdiv-arm"])
-      pAttributes.push_back("+hwdiv-arm");
-
-    if (Features.count("hwdiv") && Features["hwdiv"])
-      pAttributes.push_back("+hwdiv");
-  }
-
-  return;
-}
-
-ARMBaseCompilerConfig::ARMBaseCompilerConfig(const std::string &pTriple,
-                                             bool pInThumbMode)
-  : CompilerConfig(pTriple), mInThumbMode(pInThumbMode) {
-
-  // Enable NEON by default.
-  mEnableNEON = true;
-
-  if (!getProperty("debug.rs.arm-no-tune-for-cpu"))
-    setCPU(llvm::sys::getHostCPUName());
-
-  std::vector<std::string> attributes;
-  GetFeatureVector(attributes, mInThumbMode, mEnableNEON);
-  setFeatureString(attributes);
-
-  return;
-}
-
-bool ARMBaseCompilerConfig::enableNEON(bool pEnable) {
-#if defined(ARCH_ARM_HAVE_NEON)
-  if (mEnableNEON != pEnable) {
-    std::vector<std::string> attributes;
-    GetFeatureVector(attributes, mInThumbMode, pEnable);
-    setFeatureString(attributes);
-    mEnableNEON = pEnable;
-    return true;
-  }
-  // Fall-through
-#endif
-  return false;
-}
-#endif // defined(PROVIDE_ARM_CODEGEN)
diff --git a/tools/bcc/Main.cpp b/tools/bcc/Main.cpp
index 8426430..3133c47 100644
--- a/tools/bcc/Main.cpp
+++ b/tools/bcc/Main.cpp
@@ -46,7 +46,6 @@
 #include <bcc/Support/Initialization.h>
 #include <bcc/Support/InputFile.h>
 #include <bcc/Support/OutputFile.h>
-#include <bcc/Support/TargetCompilerConfigs.h>
 
 using namespace bcc;
 
diff --git a/tools/bcc_compat/Main.cpp b/tools/bcc_compat/Main.cpp
index 1391de8..914a9e5 100644
--- a/tools/bcc_compat/Main.cpp
+++ b/tools/bcc_compat/Main.cpp
@@ -41,7 +41,6 @@
 #include <bcc/Support/Initialization.h>
 #include <bcc/Support/InputFile.h>
 #include <bcc/Support/OutputFile.h>
-#include <bcc/Support/TargetCompilerConfigs.h>
 
 using namespace bcc;
 
@@ -62,7 +61,6 @@
 OptRuntimePath("rt-path", llvm::cl::desc("Specify the runtime library path"),
                llvm::cl::value_desc("path"));
 
-#ifndef TARGET_BUILD
 llvm::cl::opt<std::string>
 OptTargetTriple("mtriple",
                 llvm::cl::desc("Specify the target triple (default: "
@@ -73,7 +71,6 @@
 llvm::cl::alias OptTargetTripleC("C", llvm::cl::NotHidden,
                                  llvm::cl::desc("Alias for -mtriple"),
                                  llvm::cl::aliasopt(OptTargetTriple));
-#endif
 
 //===----------------------------------------------------------------------===//
 // Compiler Options
@@ -165,11 +162,7 @@
   RSCompiler *compiler = pCompilerDriver.getCompiler();
   CompilerConfig *config = NULL;
 
-#ifdef TARGET_BUILD
-  config = new (std::nothrow) DefaultCompilerConfig();
-#else
   config = new (std::nothrow) CompilerConfig(OptTargetTriple);
-#endif
   if (config == NULL) {
     llvm::errs() << "Out of memory when create the compiler configuration!\n";
     return false;