OSDN Git Service

19785bf562515c9e8e91fe7a04a8cccfb5bc5e10
[android-x86/external-swiftshader.git] / src / IceClFlags.h
1 //===- subzero/src/IceClFlags.h - Cl Flags for translation ------*- C++ -*-===//
2 //
3 //                        The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Declares Ice::ClFlags which implements command line processing.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef SUBZERO_SRC_ICECLFLAGS_H
16 #define SUBZERO_SRC_ICECLFLAGS_H
17
18 #include "IceDefs.h"
19 #include "IceBuildDefs.h"
20 #include "IceClFlags.def"
21 #include "IceRangeSpec.h"
22 #include "IceTypes.h"
23
24 #ifdef __clang__
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Wunused-parameter"
27 #endif // __clang__
28
29 #include "llvm/IRReader/IRReader.h"
30
31 #ifdef __clang__
32 #pragma clang diagnostic pop
33 #endif // __clang__
34
35 #include <string>
36 #include <utility>
37 #include <vector>
38
39 namespace Ice {
40 // detail defines the type cl_type_traits, which is used to define the
41 // getters/setters for the ClFlags class. It converts the cl_detail::*_flag
42 // types to appropriate types for the several getters and setters created.
43 namespace detail {
44 // Base cl_type_traits.
45 template <typename B, typename CL> struct cl_type_traits {};
46
47 // cl_type_traits specialized cl::list<std::string>, non-MINIMAL build.
48 template <> struct cl_type_traits<std::string, cl_detail::dev_list_flag> {
49   using storage_type = std::vector<std::string>;
50 };
51
52 // cl_type_traits specialized cl::list<Ice::VerboseItem>, non-MINIMAL build.
53 template <> struct cl_type_traits<Ice::VerboseItem, cl_detail::dev_list_flag> {
54   using storage_type = Ice::VerboseMask;
55 };
56
57 // cl_type_traits specialized cl::opt<T>, non-MINIMAL build.
58 template <typename T> struct cl_type_traits<T, cl_detail::dev_opt_flag> {
59   using storage_type = T;
60 };
61
62 // cl_type_traits specialized cl::opt<T>, MINIMAL build.
63 template <typename T> struct cl_type_traits<T, cl_detail::release_opt_flag> {
64   using storage_type = T;
65 };
66
67 } // end of namespace detail
68
69 /// Define variables which configure translation and related support functions.
70 class ClFlags {
71   ClFlags(const ClFlags &) = delete;
72   ClFlags &operator=(const ClFlags &) = delete;
73
74 public:
75   /// User defined constructor.
76   ClFlags() { resetClFlags(); }
77
78   /// The command line flags.
79   static ClFlags Flags;
80
81   /// \brief Parse commmand line options for Subzero.
82   ///
83   /// This is done use cl::ParseCommandLineOptions() and the static variables of
84   /// type cl::opt defined in IceClFlags.cpp
85   static void parseFlags(int argc, const char *const *argv);
86
87   /// Reset all configuration options to their nominal values.
88   void resetClFlags();
89
90   /// \brief Retrieve the configuration option state
91   ///
92   /// This is defined by static variables
93   /// anonymous_namespace{IceClFlags.cpp}::AllowErrorRecoveryObj,
94   /// anonymous_namespace{IceClFlags.cpp}::AllowIacaMarksObj,
95   /// ...
96   static void getParsedClFlags(ClFlags &OutFlags);
97
98 #define X(Name, Type, ClType, ...)                                             \
99 private:                                                                       \
100   typename detail::cl_type_traits<Type, cl_detail::ClType>::storage_type Name; \
101                                                                                \
102   template <bool E>                                                            \
103   typename std::enable_if<E, void>::type set##Name##Impl(                      \
104       typename detail::cl_type_traits<Type, cl_detail::ClType>::storage_type   \
105           Value) {                                                             \
106     Name = std::move(Value);                                                   \
107   }                                                                            \
108                                                                                \
109   template <bool E>                                                            \
110   typename std::enable_if<!E, void>::type set##Name##Impl(                     \
111       typename detail::cl_type_traits<Type,                                    \
112                                       cl_detail::ClType>::storage_type) {}     \
113                                                                                \
114 public:                                                                        \
115   typename detail::cl_type_traits<Type, cl_detail::ClType>::storage_type       \
116       get##Name() const {                                                      \
117     return Name;                                                               \
118   }                                                                            \
119                                                                                \
120   void set##Name(                                                              \
121       typename detail::cl_type_traits<Type, cl_detail::ClType>::storage_type   \
122           Value) {                                                             \
123     /* TODO(jpp): figure out which optional flags are used in minimal, and     \
124        what are the defaults for them. */                                      \
125     static constexpr bool Enable =                                             \
126         std::is_same<cl_detail::ClType, cl_detail::release_opt_flag>::value || \
127         !BuildDefs::minimal() || true;                                         \
128     set##Name##Impl<Enable>(std::move(Value));                                 \
129   }                                                                            \
130                                                                                \
131 private:
132   COMMAND_LINE_FLAGS
133 #undef X
134
135 public:
136   bool isSequential() const { return NumTranslationThreads == 0; }
137   bool isParseParallel() const {
138     return getParseParallel() && !isSequential() && getBuildOnRead();
139   }
140   std::string getAppName() const { return AppName; }
141   void setAppName(const std::string &Value) { AppName = Value; }
142
143   /// \brief Get the value of ClFlags::GenerateUnitTestMessages
144   ///
145   /// Note: If dump routines have been turned off, the error messages
146   /// will not be readable. Hence, turn off.
147   bool getGenerateUnitTestMessages() const {
148     return !BuildDefs::dump() || GenerateUnitTestMessages;
149   }
150   /// Set ClFlags::GenerateUnitTestMessages to a new value
151   void setGenerateUnitTestMessages(bool NewValue) {
152     GenerateUnitTestMessages = NewValue;
153   }
154   bool matchForceO2(GlobalString Name, uint32_t Number) const {
155     return ForceO2.match(Name, Number);
156   }
157   bool matchTestStatus(GlobalString Name, uint32_t Number) const {
158     return TestStatus.match(Name, Number);
159   }
160   bool matchTimingFocus(GlobalString Name, uint32_t Number) const {
161     return TimingFocus.match(Name, Number);
162   }
163   bool matchTranslateOnly(GlobalString Name, uint32_t Number) const {
164     return TranslateOnly.match(Name, Number);
165   }
166   bool matchVerboseFocusOn(GlobalString Name, uint32_t Number) const {
167     return VerboseFocus.match(Name, Number);
168   }
169   bool matchVerboseFocusOn(const std::string &Name, uint32_t Number) const {
170     return VerboseFocus.match(Name, Number);
171   }
172
173 private:
174   std::string AppName;
175
176   /// Initialized to false; not set by the command line.
177   bool GenerateUnitTestMessages;
178
179   RangeSpec ForceO2;
180   RangeSpec TestStatus;
181   RangeSpec TimingFocus;
182   RangeSpec TranslateOnly;
183   RangeSpec VerboseFocus;
184 };
185
186 inline const ClFlags &getFlags() { return ClFlags::Flags; }
187
188 } // end of namespace Ice
189
190 #endif // SUBZERO_SRC_ICECLFLAGS_H