blob: 27ca5826136378041c1f97ed72b7e60428b9290a [file] [log] [blame]
Karl Schimpf8d7abae2014-07-07 14:50:30 -07001//===- 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 Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
Reed Kotlercb0d47b2015-12-17 16:30:26 -080011/// \brief Declares Ice::ClFlags which implements command line processing.
Andrew Scull9612d322015-07-06 14:53:25 -070012///
Karl Schimpf8d7abae2014-07-07 14:50:30 -070013//===----------------------------------------------------------------------===//
14
15#ifndef SUBZERO_SRC_ICECLFLAGS_H
16#define SUBZERO_SRC_ICECLFLAGS_H
17
Jan Voung44c3a802015-03-27 16:29:08 -070018#include "IceDefs.h"
John Portoc5bc5cb2016-03-21 11:18:02 -070019#include "IceBuildDefs.h"
20#include "IceClFlags.def"
Jim Stichnothdd6dcfa2016-04-18 12:52:09 -070021#include "IceRangeSpec.h"
Jan Voung1f47ad02015-03-20 15:01:26 -070022#include "IceTypes.h"
Karl Schimpf5ee234a2014-09-12 10:41:40 -070023
John Portoc5bc5cb2016-03-21 11:18:02 -070024#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 Stichnothf5fdd232016-05-09 12:24:36 -070039#ifndef PNACL_LLVM
40namespace llvm {
41// \brief Define the expected format of the file.
42enum 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 Schimpf8d7abae2014-07-07 14:50:30 -070053namespace Ice {
John Portoc5bc5cb2016-03-21 11:18:02 -070054// 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.
57namespace detail {
58// Base cl_type_traits.
59template <typename B, typename CL> struct cl_type_traits {};
Karl Schimpf8d7abae2014-07-07 14:50:30 -070060
John Portoc5bc5cb2016-03-21 11:18:02 -070061// cl_type_traits specialized cl::list<std::string>, non-MINIMAL build.
62template <> struct cl_type_traits<std::string, cl_detail::dev_list_flag> {
63 using storage_type = std::vector<std::string>;
64};
Jim Stichnoth98ba0062016-03-07 09:26:22 -080065
John Portoc5bc5cb2016-03-21 11:18:02 -070066// cl_type_traits specialized cl::list<Ice::VerboseItem>, non-MINIMAL build.
67template <> 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.
72template <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.
77template <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 Voung44c3a802015-03-27 16:29:08 -070082
Reed Kotlercb0d47b2015-12-17 16:30:26 -080083/// Define variables which configure translation and related support functions.
Karl Schimpf8d7abae2014-07-07 14:50:30 -070084class ClFlags {
Karl Schimpfdf80eb82015-02-09 14:20:22 -080085 ClFlags(const ClFlags &) = delete;
86 ClFlags &operator=(const ClFlags &) = delete;
87
Karl Schimpf8d7abae2014-07-07 14:50:30 -070088public:
Reed Kotlercb0d47b2015-12-17 16:30:26 -080089 /// User defined constructor.
John Portoc5bc5cb2016-03-21 11:18:02 -070090 ClFlags() { resetClFlags(); }
Karl Schimpfdf80eb82015-02-09 14:20:22 -080091
Karl Schimpfd4699942016-04-02 09:55:31 -070092 /// The command line flags.
93 static ClFlags Flags;
94
Reed Kotlercb0d47b2015-12-17 16:30:26 -080095 /// \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 Stichnothfd07ad02016-04-20 10:12:46 -070099 static void parseFlags(int argc, const char *const *argv);
John Portoc5bc5cb2016-03-21 11:18:02 -0700100
Reed Kotlercb0d47b2015-12-17 16:30:26 -0800101 /// Reset all configuration options to their nominal values.
John Portoc5bc5cb2016-03-21 11:18:02 -0700102 void resetClFlags();
103
Reed Kotlercb0d47b2015-12-17 16:30:26 -0800104 /// \brief Retrieve the configuration option state
105 ///
106 /// This is defined by static variables
John Portoc5bc5cb2016-03-21 11:18:02 -0700107 /// anonymous_namespace{IceClFlags.cpp}::AllowErrorRecoveryObj,
108 /// anonymous_namespace{IceClFlags.cpp}::AllowIacaMarksObj,
Reed Kotlercb0d47b2015-12-17 16:30:26 -0800109 /// ...
Jan Voung44c3a802015-03-27 16:29:08 -0700110 static void getParsedClFlags(ClFlags &OutFlags);
Jan Voung44c3a802015-03-27 16:29:08 -0700111
John Portoc5bc5cb2016-03-21 11:18:02 -0700112#define X(Name, Type, ClType, ...) \
113private: \
Nicolas Capensa0b720d2016-09-01 11:29:43 -0400114 using Name##StorageType = \
115 detail::cl_type_traits<Type, cl_detail::ClType>::storage_type; \
116 \
117 Name##StorageType Name; \
John Portoc5bc5cb2016-03-21 11:18:02 -0700118 \
119 template <bool E> \
120 typename std::enable_if<E, void>::type set##Name##Impl( \
Nicolas Capensa0b720d2016-09-01 11:29:43 -0400121 Name##StorageType Value) { \
John Portoc5bc5cb2016-03-21 11:18:02 -0700122 Name = std::move(Value); \
123 } \
124 \
125 template <bool E> \
Nicolas Capensa0b720d2016-09-01 11:29:43 -0400126 typename std::enable_if<!E, void>::type set##Name##Impl(Name##StorageType) { \
John Portoc5bc5cb2016-03-21 11:18:02 -0700127 } \
128 \
Nicolas Capensa0b720d2016-09-01 11:29:43 -0400129public: \
130 Name##StorageType get##Name() const { return Name; } \
131 void set##Name(Name##StorageType Value) { \
John Portoc5bc5cb2016-03-21 11:18:02 -0700132 /* 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 \
140private:
141 COMMAND_LINE_FLAGS
142#undef X
Karl Schimpfdf80eb82015-02-09 14:20:22 -0800143
John Portoc5bc5cb2016-03-21 11:18:02 -0700144public:
145 bool isSequential() const { return NumTranslationThreads == 0; }
Karl Schimpf3dd127e2016-03-31 13:22:11 -0700146 bool isParseParallel() const {
147 return getParseParallel() && !isSequential() && getBuildOnRead();
148 }
John Portoc5bc5cb2016-03-21 11:18:02 -0700149 std::string getAppName() const { return AppName; }
150 void setAppName(const std::string &Value) { AppName = Value; }
Karl Schimpfdf80eb82015-02-09 14:20:22 -0800151
Reed Kotlercb0d47b2015-12-17 16:30:26 -0800152 /// \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 Schimpfdf80eb82015-02-09 14:20:22 -0800156 bool getGenerateUnitTestMessages() const {
Jim Stichnoth20b71f52015-06-24 15:52:24 -0700157 return !BuildDefs::dump() || GenerateUnitTestMessages;
Karl Schimpfdf80eb82015-02-09 14:20:22 -0800158 }
Reed Kotlercb0d47b2015-12-17 16:30:26 -0800159 /// Set ClFlags::GenerateUnitTestMessages to a new value
Karl Schimpfdf80eb82015-02-09 14:20:22 -0800160 void setGenerateUnitTestMessages(bool NewValue) {
161 GenerateUnitTestMessages = NewValue;
162 }
Jim Stichnothdd6dcfa2016-04-18 12:52:09 -0700163 bool matchForceO2(GlobalString Name, uint32_t Number) const {
164 return ForceO2.match(Name, Number);
165 }
Jim Stichnothb9a84722016-08-01 13:18:36 -0700166 bool matchSplitInsts(const std::string &Name, uint32_t Number) const {
167 return SplitInsts.match(Name, Number);
168 }
Jim Stichnothdd6dcfa2016-04-18 12:52:09 -0700169 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 Schimpfdf80eb82015-02-09 14:20:22 -0800184
Karl Schimpfdf80eb82015-02-09 14:20:22 -0800185private:
John Portoc5bc5cb2016-03-21 11:18:02 -0700186 std::string AppName;
187
Reed Kotlercb0d47b2015-12-17 16:30:26 -0800188 /// Initialized to false; not set by the command line.
Karl Schimpfdf80eb82015-02-09 14:20:22 -0800189 bool GenerateUnitTestMessages;
Jim Stichnothdd6dcfa2016-04-18 12:52:09 -0700190
191 RangeSpec ForceO2;
Jim Stichnothb9a84722016-08-01 13:18:36 -0700192 RangeSpec SplitInsts;
Jim Stichnothdd6dcfa2016-04-18 12:52:09 -0700193 RangeSpec TestStatus;
194 RangeSpec TimingFocus;
195 RangeSpec TranslateOnly;
196 RangeSpec VerboseFocus;
Karl Schimpf8d7abae2014-07-07 14:50:30 -0700197};
Jim Stichnoth989a7032014-08-08 10:13:44 -0700198
Karl Schimpfd4699942016-04-02 09:55:31 -0700199inline const ClFlags &getFlags() { return ClFlags::Flags; }
200
Jim Stichnoth989a7032014-08-08 10:13:44 -0700201} // end of namespace Ice
Karl Schimpf8d7abae2014-07-07 14:50:30 -0700202
203#endif // SUBZERO_SRC_ICECLFLAGS_H