Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 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 | |
Zonr Chang | c72c4dd | 2012-04-12 15:38:53 +0800 | [diff] [blame] | 17 | #ifndef BCC_SUPPORT_COMPILER_CONFIG_H |
| 18 | #define BCC_SUPPORT_COMPILER_CONFIG_H |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 19 | |
| 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
Pirama Arumuga Nainar | f5b49a0 | 2016-09-15 23:04:25 -0700 | [diff] [blame] | 23 | #include <llvm/ADT/Optional.h> |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 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 | |
Pirama Arumuga Nainar | f5b49a0 | 2016-09-15 23:04:25 -0700 | [diff] [blame] | 52 | llvm::Optional<llvm::Reloc::Model> mRelocModel; |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 53 | |
Stephen Hines | bde1a25 | 2014-05-15 18:02:33 -0700 | [diff] [blame] | 54 | // Are we set up to compile for full precision or something reduced? |
| 55 | bool mFullPrecision; |
| 56 | |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 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 | |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 61 | //===--------------------------------------------------------------------===// |
| 62 | // These are generated by CompilerConfig during initialize(). |
| 63 | //===--------------------------------------------------------------------===// |
| 64 | const llvm::Target *mTarget; |
| 65 | bool initializeTarget(); |
| 66 | |
| 67 | llvm::Triple::ArchType mArchType; |
Stephen Hines | bde1a25 | 2014-05-15 18:02:33 -0700 | [diff] [blame] | 68 | bool initializeArch(); |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 69 | |
| 70 | public: |
| 71 | //===--------------------------------------------------------------------===// |
| 72 | // Getters |
| 73 | //===--------------------------------------------------------------------===// |
| 74 | inline const std::string &getTriple() const |
| 75 | { return mTriple; } |
| 76 | |
| 77 | inline const std::string &getCPU() const |
| 78 | { return mCPU; } |
| 79 | inline void setCPU(const std::string &pCPU) |
| 80 | { mCPU = pCPU; } |
| 81 | |
| 82 | inline const llvm::TargetOptions &getTargetOptions() const |
| 83 | { return mTargetOpts; } |
| 84 | inline llvm::TargetOptions &getTargetOptions() |
| 85 | { return mTargetOpts; } |
| 86 | |
| 87 | inline llvm::CodeModel::Model getCodeModel() const |
| 88 | { return mCodeModel; } |
| 89 | inline void setCodeModel(llvm::CodeModel::Model pCodeMode) |
| 90 | { mCodeModel = pCodeMode; } |
| 91 | |
| 92 | inline llvm::CodeGenOpt::Level getOptimizationLevel() const |
| 93 | { return mOptLevel; } |
| 94 | inline void setOptimizationLevel(llvm::CodeGenOpt::Level pOptLvl) |
| 95 | { mOptLevel = pOptLvl; } |
| 96 | |
Pirama Arumuga Nainar | f5b49a0 | 2016-09-15 23:04:25 -0700 | [diff] [blame] | 97 | inline llvm::Optional<llvm::Reloc::Model> getRelocationModel() const |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 98 | { return mRelocModel; } |
| 99 | inline void setRelocationModel(llvm::Reloc::Model pRelocModel) |
| 100 | { mRelocModel = pRelocModel; } |
| 101 | |
| 102 | inline const llvm::Target *getTarget() const |
| 103 | { return mTarget; } |
| 104 | |
| 105 | inline llvm::Triple::ArchType getArchType() const |
| 106 | { return mArchType; } |
| 107 | |
Stephen Hines | bde1a25 | 2014-05-15 18:02:33 -0700 | [diff] [blame] | 108 | inline bool getFullPrecision() const |
| 109 | { return mFullPrecision; } |
| 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 | |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 117 | inline const std::string &getFeatureString() const |
| 118 | { return mFeatureString; } |
| 119 | void setFeatureString(const std::vector<std::string> &pAttrs); |
| 120 | |
Chih-Hung Hsieh | 8a019dd | 2016-08-12 15:49:55 -0700 | [diff] [blame] | 121 | explicit CompilerConfig(const std::string &pTriple); |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 122 | |
| 123 | virtual ~CompilerConfig() { } |
| 124 | }; |
| 125 | |
| 126 | } // end namespace bcc |
| 127 | |
Zonr Chang | c72c4dd | 2012-04-12 15:38:53 +0800 | [diff] [blame] | 128 | #endif // BCC_SUPPORT_COMPILER_CONFIG_H |