Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Reed Kotler | cb0d47b | 2015-12-17 16:30:26 -0800 | [diff] [blame] | 11 | /// \brief Declares Ice::ClFlags which implements command line processing. |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 12 | /// |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef SUBZERO_SRC_ICECLFLAGS_H |
| 16 | #define SUBZERO_SRC_ICECLFLAGS_H |
| 17 | |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 18 | #include "IceDefs.h" |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 19 | #include "IceBuildDefs.h" |
| 20 | #include "IceClFlags.def" |
Jim Stichnoth | dd6dcfa | 2016-04-18 12:52:09 -0700 | [diff] [blame] | 21 | #include "IceRangeSpec.h" |
Jan Voung | 1f47ad0 | 2015-03-20 15:01:26 -0700 | [diff] [blame] | 22 | #include "IceTypes.h" |
Karl Schimpf | 5ee234a | 2014-09-12 10:41:40 -0700 | [diff] [blame] | 23 | |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 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 | |
Jim Stichnoth | f5fdd23 | 2016-05-09 12:24:36 -0700 | [diff] [blame] | 39 | #ifndef PNACL_LLVM |
| 40 | namespace llvm { |
| 41 | // \brief Define the expected format of the file. |
| 42 | enum NaClFileFormat { |
| 43 | // LLVM IR source or bitcode file (as appropriate). |
| 44 | LLVMFormat, |
| 45 | // PNaCl bitcode file. |
| 46 | PNaClFormat, |
| 47 | // Autodetect if PNaCl or LLVM format. |
| 48 | AutodetectFileFormat |
| 49 | }; |
| 50 | } // end of namespace llvm |
| 51 | #endif // !PNACL_LLVM |
| 52 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 53 | namespace Ice { |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 54 | // detail defines the type cl_type_traits, which is used to define the |
| 55 | // getters/setters for the ClFlags class. It converts the cl_detail::*_flag |
| 56 | // types to appropriate types for the several getters and setters created. |
| 57 | namespace detail { |
| 58 | // Base cl_type_traits. |
| 59 | template <typename B, typename CL> struct cl_type_traits {}; |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 60 | |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 61 | // cl_type_traits specialized cl::list<std::string>, non-MINIMAL build. |
| 62 | template <> struct cl_type_traits<std::string, cl_detail::dev_list_flag> { |
| 63 | using storage_type = std::vector<std::string>; |
| 64 | }; |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 65 | |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 66 | // cl_type_traits specialized cl::list<Ice::VerboseItem>, non-MINIMAL build. |
| 67 | template <> struct cl_type_traits<Ice::VerboseItem, cl_detail::dev_list_flag> { |
| 68 | using storage_type = Ice::VerboseMask; |
| 69 | }; |
| 70 | |
| 71 | // cl_type_traits specialized cl::opt<T>, non-MINIMAL build. |
| 72 | template <typename T> struct cl_type_traits<T, cl_detail::dev_opt_flag> { |
| 73 | using storage_type = T; |
| 74 | }; |
| 75 | |
| 76 | // cl_type_traits specialized cl::opt<T>, MINIMAL build. |
| 77 | template <typename T> struct cl_type_traits<T, cl_detail::release_opt_flag> { |
| 78 | using storage_type = T; |
| 79 | }; |
| 80 | |
| 81 | } // end of namespace detail |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 82 | |
Reed Kotler | cb0d47b | 2015-12-17 16:30:26 -0800 | [diff] [blame] | 83 | /// Define variables which configure translation and related support functions. |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 84 | class ClFlags { |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 85 | ClFlags(const ClFlags &) = delete; |
| 86 | ClFlags &operator=(const ClFlags &) = delete; |
| 87 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 88 | public: |
Reed Kotler | cb0d47b | 2015-12-17 16:30:26 -0800 | [diff] [blame] | 89 | /// User defined constructor. |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 90 | ClFlags() { resetClFlags(); } |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 91 | |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 92 | /// The command line flags. |
| 93 | static ClFlags Flags; |
| 94 | |
Reed Kotler | cb0d47b | 2015-12-17 16:30:26 -0800 | [diff] [blame] | 95 | /// \brief Parse commmand line options for Subzero. |
| 96 | /// |
| 97 | /// This is done use cl::ParseCommandLineOptions() and the static variables of |
| 98 | /// type cl::opt defined in IceClFlags.cpp |
Jim Stichnoth | fd07ad0 | 2016-04-20 10:12:46 -0700 | [diff] [blame] | 99 | static void parseFlags(int argc, const char *const *argv); |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 100 | |
Reed Kotler | cb0d47b | 2015-12-17 16:30:26 -0800 | [diff] [blame] | 101 | /// Reset all configuration options to their nominal values. |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 102 | void resetClFlags(); |
| 103 | |
Reed Kotler | cb0d47b | 2015-12-17 16:30:26 -0800 | [diff] [blame] | 104 | /// \brief Retrieve the configuration option state |
| 105 | /// |
| 106 | /// This is defined by static variables |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 107 | /// anonymous_namespace{IceClFlags.cpp}::AllowErrorRecoveryObj, |
| 108 | /// anonymous_namespace{IceClFlags.cpp}::AllowIacaMarksObj, |
Reed Kotler | cb0d47b | 2015-12-17 16:30:26 -0800 | [diff] [blame] | 109 | /// ... |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 110 | static void getParsedClFlags(ClFlags &OutFlags); |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 111 | |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 112 | #define X(Name, Type, ClType, ...) \ |
| 113 | private: \ |
Nicolas Capens | a0b720d | 2016-09-01 11:29:43 -0400 | [diff] [blame] | 114 | using Name##StorageType = \ |
| 115 | detail::cl_type_traits<Type, cl_detail::ClType>::storage_type; \ |
| 116 | \ |
| 117 | Name##StorageType Name; \ |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 118 | \ |
| 119 | template <bool E> \ |
| 120 | typename std::enable_if<E, void>::type set##Name##Impl( \ |
Nicolas Capens | a0b720d | 2016-09-01 11:29:43 -0400 | [diff] [blame] | 121 | Name##StorageType Value) { \ |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 122 | Name = std::move(Value); \ |
| 123 | } \ |
| 124 | \ |
| 125 | template <bool E> \ |
Nicolas Capens | a0b720d | 2016-09-01 11:29:43 -0400 | [diff] [blame] | 126 | typename std::enable_if<!E, void>::type set##Name##Impl(Name##StorageType) { \ |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 127 | } \ |
| 128 | \ |
Nicolas Capens | a0b720d | 2016-09-01 11:29:43 -0400 | [diff] [blame] | 129 | public: \ |
| 130 | Name##StorageType get##Name() const { return Name; } \ |
| 131 | void set##Name(Name##StorageType Value) { \ |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 132 | /* TODO(jpp): figure out which optional flags are used in minimal, and \ |
| 133 | what are the defaults for them. */ \ |
| 134 | static constexpr bool Enable = \ |
| 135 | std::is_same<cl_detail::ClType, cl_detail::release_opt_flag>::value || \ |
| 136 | !BuildDefs::minimal() || true; \ |
| 137 | set##Name##Impl<Enable>(std::move(Value)); \ |
| 138 | } \ |
| 139 | \ |
| 140 | private: |
| 141 | COMMAND_LINE_FLAGS |
| 142 | #undef X |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 143 | |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 144 | public: |
| 145 | bool isSequential() const { return NumTranslationThreads == 0; } |
Karl Schimpf | 3dd127e | 2016-03-31 13:22:11 -0700 | [diff] [blame] | 146 | bool isParseParallel() const { |
| 147 | return getParseParallel() && !isSequential() && getBuildOnRead(); |
| 148 | } |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 149 | std::string getAppName() const { return AppName; } |
| 150 | void setAppName(const std::string &Value) { AppName = Value; } |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 151 | |
Reed Kotler | cb0d47b | 2015-12-17 16:30:26 -0800 | [diff] [blame] | 152 | /// \brief Get the value of ClFlags::GenerateUnitTestMessages |
| 153 | /// |
| 154 | /// Note: If dump routines have been turned off, the error messages |
| 155 | /// will not be readable. Hence, turn off. |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 156 | bool getGenerateUnitTestMessages() const { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 157 | return !BuildDefs::dump() || GenerateUnitTestMessages; |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 158 | } |
Reed Kotler | cb0d47b | 2015-12-17 16:30:26 -0800 | [diff] [blame] | 159 | /// Set ClFlags::GenerateUnitTestMessages to a new value |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 160 | void setGenerateUnitTestMessages(bool NewValue) { |
| 161 | GenerateUnitTestMessages = NewValue; |
| 162 | } |
Jim Stichnoth | dd6dcfa | 2016-04-18 12:52:09 -0700 | [diff] [blame] | 163 | bool matchForceO2(GlobalString Name, uint32_t Number) const { |
| 164 | return ForceO2.match(Name, Number); |
| 165 | } |
Jim Stichnoth | b9a8472 | 2016-08-01 13:18:36 -0700 | [diff] [blame] | 166 | bool matchSplitInsts(const std::string &Name, uint32_t Number) const { |
| 167 | return SplitInsts.match(Name, Number); |
| 168 | } |
Jim Stichnoth | dd6dcfa | 2016-04-18 12:52:09 -0700 | [diff] [blame] | 169 | bool matchTestStatus(GlobalString Name, uint32_t Number) const { |
| 170 | return TestStatus.match(Name, Number); |
| 171 | } |
| 172 | bool matchTimingFocus(GlobalString Name, uint32_t Number) const { |
| 173 | return TimingFocus.match(Name, Number); |
| 174 | } |
| 175 | bool matchTranslateOnly(GlobalString Name, uint32_t Number) const { |
| 176 | return TranslateOnly.match(Name, Number); |
| 177 | } |
| 178 | bool matchVerboseFocusOn(GlobalString Name, uint32_t Number) const { |
| 179 | return VerboseFocus.match(Name, Number); |
| 180 | } |
| 181 | bool matchVerboseFocusOn(const std::string &Name, uint32_t Number) const { |
| 182 | return VerboseFocus.match(Name, Number); |
| 183 | } |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 184 | |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 185 | private: |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 186 | std::string AppName; |
| 187 | |
Reed Kotler | cb0d47b | 2015-12-17 16:30:26 -0800 | [diff] [blame] | 188 | /// Initialized to false; not set by the command line. |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 189 | bool GenerateUnitTestMessages; |
Jim Stichnoth | dd6dcfa | 2016-04-18 12:52:09 -0700 | [diff] [blame] | 190 | |
| 191 | RangeSpec ForceO2; |
Jim Stichnoth | b9a8472 | 2016-08-01 13:18:36 -0700 | [diff] [blame] | 192 | RangeSpec SplitInsts; |
Jim Stichnoth | dd6dcfa | 2016-04-18 12:52:09 -0700 | [diff] [blame] | 193 | RangeSpec TestStatus; |
| 194 | RangeSpec TimingFocus; |
| 195 | RangeSpec TranslateOnly; |
| 196 | RangeSpec VerboseFocus; |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 197 | }; |
Jim Stichnoth | 989a703 | 2014-08-08 10:13:44 -0700 | [diff] [blame] | 198 | |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 199 | inline const ClFlags &getFlags() { return ClFlags::Flags; } |
| 200 | |
Jim Stichnoth | 989a703 | 2014-08-08 10:13:44 -0700 | [diff] [blame] | 201 | } // end of namespace Ice |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 202 | |
| 203 | #endif // SUBZERO_SRC_ICECLFLAGS_H |