1 //===- subzero/src/IceClFlags.h - Cl Flags for translation ------*- C++ -*-===//
3 // The Subzero Code Generator
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Declares Ice::ClFlags which implements command line processing.
13 //===----------------------------------------------------------------------===//
15 #ifndef SUBZERO_SRC_ICECLFLAGS_H
16 #define SUBZERO_SRC_ICECLFLAGS_H
19 #include "IceBuildDefs.h"
20 #include "IceClFlags.def"
21 #include "IceRangeSpec.h"
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Wunused-parameter"
29 #include "llvm/IRReader/IRReader.h"
32 #pragma clang diagnostic pop
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.
44 // Base cl_type_traits.
45 template <typename B, typename CL> struct cl_type_traits {};
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>;
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;
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;
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;
67 } // end of namespace detail
69 /// Define variables which configure translation and related support functions.
71 ClFlags(const ClFlags &) = delete;
72 ClFlags &operator=(const ClFlags &) = delete;
75 /// User defined constructor.
76 ClFlags() { resetClFlags(); }
78 /// The command line flags.
81 /// \brief Parse commmand line options for Subzero.
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);
87 /// Reset all configuration options to their nominal values.
90 /// \brief Retrieve the configuration option state
92 /// This is defined by static variables
93 /// anonymous_namespace{IceClFlags.cpp}::AllowErrorRecoveryObj,
94 /// anonymous_namespace{IceClFlags.cpp}::AllowIacaMarksObj,
96 static void getParsedClFlags(ClFlags &OutFlags);
98 #define X(Name, Type, ClType, ...) \
100 typename detail::cl_type_traits<Type, cl_detail::ClType>::storage_type Name; \
103 typename std::enable_if<E, void>::type set##Name##Impl( \
104 typename detail::cl_type_traits<Type, cl_detail::ClType>::storage_type \
106 Name = std::move(Value); \
110 typename std::enable_if<!E, void>::type set##Name##Impl( \
111 typename detail::cl_type_traits<Type, \
112 cl_detail::ClType>::storage_type) {} \
115 typename detail::cl_type_traits<Type, cl_detail::ClType>::storage_type \
116 get##Name() const { \
121 typename detail::cl_type_traits<Type, cl_detail::ClType>::storage_type \
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)); \
136 bool isSequential() const { return NumTranslationThreads == 0; }
137 bool isParseParallel() const {
138 return getParseParallel() && !isSequential() && getBuildOnRead();
140 std::string getAppName() const { return AppName; }
141 void setAppName(const std::string &Value) { AppName = Value; }
143 /// \brief Get the value of ClFlags::GenerateUnitTestMessages
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;
150 /// Set ClFlags::GenerateUnitTestMessages to a new value
151 void setGenerateUnitTestMessages(bool NewValue) {
152 GenerateUnitTestMessages = NewValue;
154 bool matchForceO2(GlobalString Name, uint32_t Number) const {
155 return ForceO2.match(Name, Number);
157 bool matchTestStatus(GlobalString Name, uint32_t Number) const {
158 return TestStatus.match(Name, Number);
160 bool matchTimingFocus(GlobalString Name, uint32_t Number) const {
161 return TimingFocus.match(Name, Number);
163 bool matchTranslateOnly(GlobalString Name, uint32_t Number) const {
164 return TranslateOnly.match(Name, Number);
166 bool matchVerboseFocusOn(GlobalString Name, uint32_t Number) const {
167 return VerboseFocus.match(Name, Number);
169 bool matchVerboseFocusOn(const std::string &Name, uint32_t Number) const {
170 return VerboseFocus.match(Name, Number);
176 /// Initialized to false; not set by the command line.
177 bool GenerateUnitTestMessages;
180 RangeSpec TestStatus;
181 RangeSpec TimingFocus;
182 RangeSpec TranslateOnly;
183 RangeSpec VerboseFocus;
186 inline const ClFlags &getFlags() { return ClFlags::Flags; }
188 } // end of namespace Ice
190 #endif // SUBZERO_SRC_ICECLFLAGS_H