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_COMPILER_CONFIG_H 18 #define BCC_SUPPORT_COMPILER_CONFIG_H 19 20 #include <string> 21 #include <vector> 22 23 #include <llvm/ADT/Optional.h> 24 #include <llvm/ADT/Triple.h> 25 #include <llvm/Support/CodeGen.h> 26 #include <llvm/Target/TargetOptions.h> 27 28 namespace llvm { 29 30 class Target; 31 32 } // end namespace llvm 33 34 namespace bcc { 35 36 class CompilerConfig { 37 private: 38 //===--------------------------------------------------------------------===// 39 // Available Configurations 40 //===--------------------------------------------------------------------===// 41 std::string mTriple; 42 43 // Optional. If given, the name of the target CPU to generate code for. 44 std::string mCPU; 45 46 llvm::TargetOptions mTargetOpts; 47 48 llvm::CodeModel::Model mCodeModel; 49 50 llvm::CodeGenOpt::Level mOptLevel; 51 52 llvm::Optional<llvm::Reloc::Model> mRelocModel; 53 54 // Are we set up to compile for full precision or something reduced? 55 bool mFullPrecision; 56 57 // The list of target specific features to enable or disable -- this should 58 // be a list of strings starting with '+' (enable) or '-' (disable). 59 std::string mFeatureString; 60 61 //===--------------------------------------------------------------------===// 62 // These are generated by CompilerConfig during initialize(). 63 //===--------------------------------------------------------------------===// 64 const llvm::Target *mTarget; 65 bool initializeTarget(); 66 67 llvm::Triple::ArchType mArchType; 68 bool initializeArch(); 69 70 public: 71 //===--------------------------------------------------------------------===// 72 // Getters 73 //===--------------------------------------------------------------------===// getTriple()74 inline const std::string &getTriple() const 75 { return mTriple; } 76 getCPU()77 inline const std::string &getCPU() const 78 { return mCPU; } setCPU(const std::string & pCPU)79 inline void setCPU(const std::string &pCPU) 80 { mCPU = pCPU; } 81 getTargetOptions()82 inline const llvm::TargetOptions &getTargetOptions() const 83 { return mTargetOpts; } getTargetOptions()84 inline llvm::TargetOptions &getTargetOptions() 85 { return mTargetOpts; } 86 getCodeModel()87 inline llvm::CodeModel::Model getCodeModel() const 88 { return mCodeModel; } setCodeModel(llvm::CodeModel::Model pCodeMode)89 inline void setCodeModel(llvm::CodeModel::Model pCodeMode) 90 { mCodeModel = pCodeMode; } 91 getOptimizationLevel()92 inline llvm::CodeGenOpt::Level getOptimizationLevel() const 93 { return mOptLevel; } setOptimizationLevel(llvm::CodeGenOpt::Level pOptLvl)94 inline void setOptimizationLevel(llvm::CodeGenOpt::Level pOptLvl) 95 { mOptLevel = pOptLvl; } 96 getRelocationModel()97 inline llvm::Optional<llvm::Reloc::Model> getRelocationModel() const 98 { return mRelocModel; } setRelocationModel(llvm::Reloc::Model pRelocModel)99 inline void setRelocationModel(llvm::Reloc::Model pRelocModel) 100 { mRelocModel = pRelocModel; } 101 getTarget()102 inline const llvm::Target *getTarget() const 103 { return mTarget; } 104 getArchType()105 inline llvm::Triple::ArchType getArchType() const 106 { return mArchType; } 107 getFullPrecision()108 inline bool getFullPrecision() const 109 { return mFullPrecision; } setFullPrecision(bool pFullPrecision)110 inline void setFullPrecision(bool pFullPrecision) { 111 mFullPrecision = pFullPrecision; 112 // Note that we have to reinitialize here to ensure that mFeatureString 113 // is up to date. 114 initializeArch(); 115 } 116 getFeatureString()117 inline const std::string &getFeatureString() const 118 { return mFeatureString; } 119 void setFeatureString(const std::vector<std::string> &pAttrs); 120 121 explicit CompilerConfig(const std::string &pTriple); 122 ~CompilerConfig()123 virtual ~CompilerConfig() { } 124 }; 125 126 } // end namespace bcc 127 128 #endif // BCC_SUPPORT_COMPILER_CONFIG_H 129