CompilerConfig.h revision c72c4ddfcd79c74f70713da91a69569451b5c19e
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
27namespace llvm {
28
29class Target;
30
31} // end namespace llvm
32
33namespace bcc {
34
35class CompilerConfig {
36private:
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  // The list of target specific features to enable or disable -- this should
54  // be a list of strings starting with '+' (enable) or '-' (disable).
55  std::string mFeatureString;
56
57private:
58  //===--------------------------------------------------------------------===//
59  // These are generated by CompilerConfig during initialize().
60  //===--------------------------------------------------------------------===//
61  const llvm::Target *mTarget;
62  bool initializeTarget();
63
64  llvm::Triple::ArchType mArchType;
65  void initializeArch();
66
67public:
68  //===--------------------------------------------------------------------===//
69  // Getters
70  //===--------------------------------------------------------------------===//
71  inline const std::string &getTriple() const
72  { return mTriple; }
73
74  inline const std::string &getCPU() const
75  { return mCPU; }
76  inline void setCPU(const std::string &pCPU)
77  { mCPU = pCPU; }
78
79  inline const llvm::TargetOptions &getTargetOptions() const
80  { return mTargetOpts; }
81  inline llvm::TargetOptions &getTargetOptions()
82  { return mTargetOpts; }
83
84  inline llvm::CodeModel::Model getCodeModel() const
85  { return mCodeModel; }
86  inline void setCodeModel(llvm::CodeModel::Model pCodeMode)
87  { mCodeModel = pCodeMode; }
88
89  inline llvm::CodeGenOpt::Level getOptimizationLevel() const
90  { return mOptLevel; }
91  inline void setOptimizationLevel(llvm::CodeGenOpt::Level pOptLvl)
92  { mOptLevel = pOptLvl; }
93
94  inline llvm::Reloc::Model getRelocationModel() const
95  { return mRelocModel; }
96  inline void setRelocationModel(llvm::Reloc::Model pRelocModel)
97  { mRelocModel = pRelocModel; }
98
99  inline const llvm::Target *getTarget() const
100  { return mTarget; }
101
102  inline llvm::Triple::ArchType getArchType() const
103  { return mArchType; }
104
105  inline const std::string &getFeatureString() const
106  { return mFeatureString; }
107  void setFeatureString(const std::vector<std::string> &pAttrs);
108
109public:
110  CompilerConfig(const std::string &pTriple);
111
112  virtual ~CompilerConfig() { }
113};
114
115} // end namespace bcc
116
117#endif  // BCC_SUPPORT_COMPILER_CONFIG_H
118