OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_OPERATOR_H_ | 5 #ifndef V8_COMPILER_OPERATOR_H_ |
6 #define V8_COMPILER_OPERATOR_H_ | 6 #define V8_COMPILER_OPERATOR_H_ |
7 | 7 |
8 #include <ostream> // NOLINT(readability/streams) | 8 #include <ostream> // NOLINT(readability/streams) |
9 | 9 |
10 #include "src/base/flags.h" | 10 #include "src/base/flags.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 kNoWrite = 1 << 4, // Does not modify any Effects and thereby | 43 kNoWrite = 1 << 4, // Does not modify any Effects and thereby |
44 // create new scheduling dependencies. | 44 // create new scheduling dependencies. |
45 kNoThrow = 1 << 5, // Can never generate an exception. | 45 kNoThrow = 1 << 5, // Can never generate an exception. |
46 kNoDeopt = 1 << 6, // Can never generate an eager deoptimization exit. | 46 kNoDeopt = 1 << 6, // Can never generate an eager deoptimization exit. |
47 kFoldable = kNoRead | kNoWrite, | 47 kFoldable = kNoRead | kNoWrite, |
48 kKontrol = kNoDeopt | kFoldable | kNoThrow, | 48 kKontrol = kNoDeopt | kFoldable | kNoThrow, |
49 kEliminatable = kNoDeopt | kNoWrite | kNoThrow, | 49 kEliminatable = kNoDeopt | kNoWrite | kNoThrow, |
50 kPure = kNoDeopt | kNoRead | kNoWrite | kNoThrow | kIdempotent | 50 kPure = kNoDeopt | kNoRead | kNoWrite | kNoThrow | kIdempotent |
51 }; | 51 }; |
52 typedef base::Flags<Property, uint8_t> Properties; | 52 typedef base::Flags<Property, uint8_t> Properties; |
| 53 enum class PrintVerbosity { kVerbose, kSilent }; |
53 | 54 |
54 // Constructor. | 55 // Constructor. |
55 Operator(Opcode opcode, Properties properties, const char* mnemonic, | 56 Operator(Opcode opcode, Properties properties, const char* mnemonic, |
56 size_t value_in, size_t effect_in, size_t control_in, | 57 size_t value_in, size_t effect_in, size_t control_in, |
57 size_t value_out, size_t effect_out, size_t control_out); | 58 size_t value_out, size_t effect_out, size_t control_out); |
58 | 59 |
59 virtual ~Operator() {} | 60 virtual ~Operator() {} |
60 | 61 |
61 // A small integer unique to all instances of a particular kind of operator, | 62 // A small integer unique to all instances of a particular kind of operator, |
62 // useful for quick matching for specific kinds of operators. For fast access | 63 // useful for quick matching for specific kinds of operators. For fast access |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 105 |
105 static size_t ZeroIfNoThrow(Properties properties) { | 106 static size_t ZeroIfNoThrow(Properties properties) { |
106 return (properties & kNoThrow) == kNoThrow ? 0 : 2; | 107 return (properties & kNoThrow) == kNoThrow ? 0 : 2; |
107 } | 108 } |
108 | 109 |
109 static size_t ZeroIfPure(Properties properties) { | 110 static size_t ZeroIfPure(Properties properties) { |
110 return (properties & kPure) == kPure ? 0 : 1; | 111 return (properties & kPure) == kPure ? 0 : 1; |
111 } | 112 } |
112 | 113 |
113 // TODO(titzer): API for input and output types, for typechecking graph. | 114 // TODO(titzer): API for input and output types, for typechecking graph. |
114 protected: | 115 |
115 // Print the full operator into the given stream, including any | 116 // Print the full operator into the given stream, including any |
116 // static parameters. Useful for debugging and visualizing the IR. | 117 // static parameters. Useful for debugging and visualizing the IR. |
117 virtual void PrintTo(std::ostream& os) const; | 118 void PrintTo(std::ostream& os, |
118 friend std::ostream& operator<<(std::ostream& os, const Operator& op); | 119 PrintVerbosity verbose = PrintVerbosity::kVerbose) const { |
| 120 // We cannot make PrintTo virtual, because default arguments to virtual |
| 121 // methods are banned in the style guide. |
| 122 return PrintToImpl(os, verbose); |
| 123 } |
| 124 |
| 125 protected: |
| 126 virtual void PrintToImpl(std::ostream& os, PrintVerbosity verbose) const; |
119 | 127 |
120 private: | 128 private: |
121 Opcode opcode_; | 129 Opcode opcode_; |
122 Properties properties_; | 130 Properties properties_; |
123 const char* mnemonic_; | 131 const char* mnemonic_; |
124 uint32_t value_in_; | 132 uint32_t value_in_; |
125 uint16_t effect_in_; | 133 uint16_t effect_in_; |
126 uint16_t control_in_; | 134 uint16_t control_in_; |
127 uint16_t value_out_; | 135 uint16_t value_out_; |
128 uint8_t effect_out_; | 136 uint8_t effect_out_; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 173 |
166 bool Equals(const Operator* other) const final { | 174 bool Equals(const Operator* other) const final { |
167 if (opcode() != other->opcode()) return false; | 175 if (opcode() != other->opcode()) return false; |
168 const Operator1<T, Pred, Hash>* that = | 176 const Operator1<T, Pred, Hash>* that = |
169 reinterpret_cast<const Operator1<T, Pred, Hash>*>(other); | 177 reinterpret_cast<const Operator1<T, Pred, Hash>*>(other); |
170 return this->pred_(this->parameter(), that->parameter()); | 178 return this->pred_(this->parameter(), that->parameter()); |
171 } | 179 } |
172 size_t HashCode() const final { | 180 size_t HashCode() const final { |
173 return base::hash_combine(this->opcode(), this->hash_(this->parameter())); | 181 return base::hash_combine(this->opcode(), this->hash_(this->parameter())); |
174 } | 182 } |
175 virtual void PrintParameter(std::ostream& os) const { | 183 // For most parameter types, we have only a verbose way to print them, namely |
176 os << "[" << this->parameter() << "]"; | 184 // ostream << parameter. But for some types it is particularly useful to have |
| 185 // a shorter way to print them for the node labels in Turbolizer. The |
| 186 // following method can be overridden to provide a concise and a verbose |
| 187 // printing of a parameter. |
| 188 |
| 189 virtual void PrintParameter(std::ostream& os, PrintVerbosity verbose) const { |
| 190 os << "[" << parameter() << "]"; |
177 } | 191 } |
178 | 192 |
179 protected: | 193 virtual void PrintToImpl(std::ostream& os, PrintVerbosity verbose) const { |
180 void PrintTo(std::ostream& os) const final { | |
181 os << mnemonic(); | 194 os << mnemonic(); |
182 PrintParameter(os); | 195 PrintParameter(os, verbose); |
183 } | 196 } |
184 | 197 |
185 private: | 198 private: |
186 T const parameter_; | 199 T const parameter_; |
187 Pred const pred_; | 200 Pred const pred_; |
188 Hash const hash_; | 201 Hash const hash_; |
189 }; | 202 }; |
190 | 203 |
191 | 204 |
192 // Helper to extract parameters from Operator1<*> operator. | 205 // Helper to extract parameters from Operator1<*> operator. |
(...skipping 30 matching lines...) Expand all Loading... |
223 template <> | 236 template <> |
224 struct OpEqualTo<Handle<ScopeInfo>> : public Handle<ScopeInfo>::equal_to {}; | 237 struct OpEqualTo<Handle<ScopeInfo>> : public Handle<ScopeInfo>::equal_to {}; |
225 template <> | 238 template <> |
226 struct OpHash<Handle<ScopeInfo>> : public Handle<ScopeInfo>::hash {}; | 239 struct OpHash<Handle<ScopeInfo>> : public Handle<ScopeInfo>::hash {}; |
227 | 240 |
228 } // namespace compiler | 241 } // namespace compiler |
229 } // namespace internal | 242 } // namespace internal |
230 } // namespace v8 | 243 } // namespace v8 |
231 | 244 |
232 #endif // V8_COMPILER_OPERATOR_H_ | 245 #endif // V8_COMPILER_OPERATOR_H_ |
OLD | NEW |