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