blob: 2e52a86630c31bef43519ce9660ae6886978e6d4 [file] [log] [blame]
Zonr Changf74ee192012-04-12 15:34:58 +08001/*
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 Changc72c4dd2012-04-12 15:38:53 +080017#ifndef BCC_SUPPORT_COMPILER_CONFIG_H
18#define BCC_SUPPORT_COMPILER_CONFIG_H
Zonr Changf74ee192012-04-12 15:34:58 +080019
20#include <string>
21#include <vector>
22
Pirama Arumuga Nainarf5b49a02016-09-15 23:04:25 -070023#include <llvm/ADT/Optional.h>
Zonr Changf74ee192012-04-12 15:34:58 +080024#include <llvm/ADT/Triple.h>
25#include <llvm/Support/CodeGen.h>
26#include <llvm/Target/TargetOptions.h>
27
28namespace llvm {
29
30class Target;
31
32} // end namespace llvm
33
34namespace bcc {
35
36class CompilerConfig {
37private:
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 Nainarf5b49a02016-09-15 23:04:25 -070052 llvm::Optional<llvm::Reloc::Model> mRelocModel;
Zonr Changf74ee192012-04-12 15:34:58 +080053
Stephen Hinesbde1a252014-05-15 18:02:33 -070054 // Are we set up to compile for full precision or something reduced?
55 bool mFullPrecision;
56
Zonr Changf74ee192012-04-12 15:34:58 +080057 // 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 Changf74ee192012-04-12 15:34:58 +080061 //===--------------------------------------------------------------------===//
62 // These are generated by CompilerConfig during initialize().
63 //===--------------------------------------------------------------------===//
64 const llvm::Target *mTarget;
65 bool initializeTarget();
66
67 llvm::Triple::ArchType mArchType;
Stephen Hinesbde1a252014-05-15 18:02:33 -070068 bool initializeArch();
Zonr Changf74ee192012-04-12 15:34:58 +080069
70public:
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 Nainarf5b49a02016-09-15 23:04:25 -070097 inline llvm::Optional<llvm::Reloc::Model> getRelocationModel() const
Zonr Changf74ee192012-04-12 15:34:58 +080098 { 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 Hinesbde1a252014-05-15 18:02:33 -0700108 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 Changf74ee192012-04-12 15:34:58 +0800117 inline const std::string &getFeatureString() const
118 { return mFeatureString; }
119 void setFeatureString(const std::vector<std::string> &pAttrs);
120
Chih-Hung Hsieh8a019dd2016-08-12 15:49:55 -0700121 explicit CompilerConfig(const std::string &pTriple);
Zonr Changf74ee192012-04-12 15:34:58 +0800122
123 virtual ~CompilerConfig() { }
124};
125
126} // end namespace bcc
127
Zonr Changc72c4dd2012-04-12 15:38:53 +0800128#endif // BCC_SUPPORT_COMPILER_CONFIG_H