Home | History | Annotate | Download | only in Support
      1 /*
      2  * Copyright 2012, The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef BCC_SUPPORT_TARGET_COMPILER_CONFIGS_H
     18 #define BCC_SUPPORT_TARGET_COMPILER_CONFIGS_H
     19 
     20 #include "bcc/Config/Config.h"
     21 #include "bcc/Support/CompilerConfig.h"
     22 
     23 namespace bcc {
     24 
     25 //===----------------------------------------------------------------------===//
     26 // ARM
     27 //===----------------------------------------------------------------------===//
     28 #if defined(PROVIDE_ARM_CODEGEN)
     29 class ARMBaseCompilerConfig : public CompilerConfig {
     30 private:
     31   bool mEnableNEON;
     32   bool mInThumbMode;
     33 
     34   static bool HasThumb2();
     35 
     36   static void GetFeatureVector(std::vector<std::string> &pAttributes,
     37                                bool pInThumbMode, bool pEnableNEON);
     38 
     39 protected:
     40   ARMBaseCompilerConfig(const std::string &pTriple, bool pInThumbMode);
     41 
     42 public:
     43   // Return true if config has been changed after returning from this function.
     44   bool enableNEON(bool pEnable = true);
     45 
     46   bool isInThumbMode() const
     47   { return mInThumbMode; }
     48 };
     49 
     50 class ARMCompilerConfig : public ARMBaseCompilerConfig {
     51 public:
     52   ARMCompilerConfig()
     53     : ARMBaseCompilerConfig(DEFAULT_ARM_TRIPLE_STRING,
     54                             /* pInThumbMode */false) { }
     55 };
     56 
     57 class ThumbCompilerConfig : public ARMBaseCompilerConfig {
     58 public:
     59   ThumbCompilerConfig()
     60     : ARMBaseCompilerConfig(DEFAULT_THUMB_TRIPLE_STRING,
     61                             /* pInThumbMode */true) { }
     62 };
     63 #endif // defined(PROVIDE_ARM_CODEGEN)
     64 
     65 //===----------------------------------------------------------------------===//
     66 // MIPS
     67 //===----------------------------------------------------------------------===//
     68 #if defined(PROVIDE_MIPS_CODEGEN)
     69 class MipsCompilerConfig : public CompilerConfig {
     70 public:
     71   MipsCompilerConfig() : CompilerConfig(DEFAULT_MIPS_TRIPLE_STRING) {
     72     setRelocationModel(llvm::Reloc::Static);
     73   }
     74 };
     75 #endif // defined(PROVIDE_MIPS_CODEGEN)
     76 
     77 //===----------------------------------------------------------------------===//
     78 // X86 and X86_64
     79 //===----------------------------------------------------------------------===//
     80 #if defined(PROVIDE_X86_CODEGEN)
     81 class X86FamilyCompilerConfigBase : public CompilerConfig {
     82 protected:
     83   X86FamilyCompilerConfigBase(const std::string &pTriple)
     84     : CompilerConfig(pTriple) {
     85     // Disable frame pointer elimination optimization on x86 family.
     86     getTargetOptions().NoFramePointerElim = true;
     87     getTargetOptions().UseInitArray = true;
     88     return;
     89   }
     90 };
     91 
     92 class X86_32CompilerConfig : public X86FamilyCompilerConfigBase {
     93 public:
     94   X86_32CompilerConfig() :
     95       X86FamilyCompilerConfigBase(DEFAULT_X86_TRIPLE_STRING) { }
     96 };
     97 
     98 class X86_64CompilerConfig : public X86FamilyCompilerConfigBase {
     99 public:
    100   X86_64CompilerConfig() :
    101       X86FamilyCompilerConfigBase(DEFAULT_X86_64_TRIPLE_STRING) {
    102     setCodeModel(llvm::CodeModel::Medium);
    103   }
    104 };
    105 #endif // defined(PROVIDE_X86_CODEGEN)
    106 
    107 //===----------------------------------------------------------------------===//
    108 // Default target
    109 //===----------------------------------------------------------------------===//
    110 class DefaultCompilerConfig : public
    111 #if defined(DEFAULT_ARM_CODEGEN)
    112   ARMCompilerConfig
    113 #elif defined(DEFAULT_MIPS_CODEGEN)
    114   MipsCompilerConfig
    115 #elif defined(DEFAULT_X86_CODEGEN)
    116   X86_32CompilerConfig
    117 #elif defined(DEFAULT_X86_64_CODEGEN)
    118   X86_64CompilerConfig
    119 #else
    120 #  error "Unsupported Default Target!"
    121 #endif
    122 { };
    123 
    124 } // end namespace bcc
    125 
    126 #endif // BCC_SUPPORT_TARGET_COMPILER_CONFIGS_H
    127