OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #include "src/compiler/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
6 | 6 |
7 #include "src/assembler.h" | 7 #include "src/assembler.h" |
8 #include "src/base/lazy-instance.h" | 8 #include "src/base/lazy-instance.h" |
9 #include "src/compiler/linkage.h" | 9 #include "src/compiler/linkage.h" |
10 #include "src/compiler/opcodes.h" | 10 #include "src/compiler/opcodes.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 size_t ProjectionIndexOf(const Operator* const op) { | 112 size_t ProjectionIndexOf(const Operator* const op) { |
113 DCHECK_EQ(IrOpcode::kProjection, op->opcode()); | 113 DCHECK_EQ(IrOpcode::kProjection, op->opcode()); |
114 return OpParameter<size_t>(op); | 114 return OpParameter<size_t>(op); |
115 } | 115 } |
116 | 116 |
117 | 117 |
118 #define CACHED_OP_LIST(V) \ | 118 #define CACHED_OP_LIST(V) \ |
119 V(Always, Operator::kPure, 0, 0, 0, 1, 0, 0) \ | 119 V(Always, Operator::kPure, 0, 0, 0, 1, 0, 0) \ |
120 V(Dead, Operator::kFoldable, 0, 0, 0, 0, 0, 1) \ | 120 V(Dead, Operator::kFoldable, 0, 0, 0, 0, 0, 1) \ |
121 V(End, Operator::kFoldable, 0, 0, 1, 0, 0, 0) \ | 121 V(End, Operator::kKontrol, 0, 0, 1, 0, 0, 0) \ |
122 V(IfTrue, Operator::kFoldable, 0, 0, 1, 0, 0, 1) \ | 122 V(IfTrue, Operator::kKontrol, 0, 0, 1, 0, 0, 1) \ |
123 V(IfFalse, Operator::kFoldable, 0, 0, 1, 0, 0, 1) \ | 123 V(IfFalse, Operator::kKontrol, 0, 0, 1, 0, 0, 1) \ |
124 V(Throw, Operator::kFoldable, 1, 1, 1, 0, 0, 1) \ | 124 V(Throw, Operator::kFoldable, 1, 1, 1, 0, 0, 1) \ |
125 V(Return, Operator::kNoProperties, 1, 1, 1, 0, 0, 1) \ | 125 V(Return, Operator::kNoThrow, 1, 1, 1, 0, 0, 1) \ |
126 V(OsrNormalEntry, Operator::kFoldable, 0, 1, 1, 0, 1, 1) \ | 126 V(OsrNormalEntry, Operator::kFoldable, 0, 1, 1, 0, 1, 1) \ |
127 V(OsrLoopEntry, Operator::kFoldable, 0, 1, 1, 0, 1, 1) | 127 V(OsrLoopEntry, Operator::kFoldable, 0, 1, 1, 0, 1, 1) |
128 | 128 |
129 | 129 |
130 #define CACHED_LOOP_LIST(V) \ | 130 #define CACHED_LOOP_LIST(V) \ |
131 V(1) \ | 131 V(1) \ |
132 V(2) | 132 V(2) |
133 | 133 |
134 | 134 |
135 #define CACHED_MERGE_LIST(V) \ | 135 #define CACHED_MERGE_LIST(V) \ |
(...skipping 28 matching lines...) Expand all Loading... |
164 value_output_count, effect_output_count, \ | 164 value_output_count, effect_output_count, \ |
165 control_output_count) {} \ | 165 control_output_count) {} \ |
166 }; \ | 166 }; \ |
167 Name##Operator k##Name##Operator; | 167 Name##Operator k##Name##Operator; |
168 CACHED_OP_LIST(CACHED) | 168 CACHED_OP_LIST(CACHED) |
169 #undef CACHED | 169 #undef CACHED |
170 | 170 |
171 template <BranchHint kBranchHint> | 171 template <BranchHint kBranchHint> |
172 struct BranchOperator FINAL : public Operator1<BranchHint> { | 172 struct BranchOperator FINAL : public Operator1<BranchHint> { |
173 BranchOperator() | 173 BranchOperator() |
174 : Operator1<BranchHint>( // -- | 174 : Operator1<BranchHint>( // -- |
175 IrOpcode::kBranch, Operator::kFoldable, // opcode | 175 IrOpcode::kBranch, Operator::kKontrol, // opcode |
176 "Branch", // name | 176 "Branch", // name |
177 1, 0, 1, 0, 0, 2, // counts | 177 1, 0, 1, 0, 0, 2, // counts |
178 kBranchHint) {} // parameter | 178 kBranchHint) {} // parameter |
179 }; | 179 }; |
180 BranchOperator<BranchHint::kNone> kBranchNoneOperator; | 180 BranchOperator<BranchHint::kNone> kBranchNoneOperator; |
181 BranchOperator<BranchHint::kTrue> kBranchTrueOperator; | 181 BranchOperator<BranchHint::kTrue> kBranchTrueOperator; |
182 BranchOperator<BranchHint::kFalse> kBranchFalseOperator; | 182 BranchOperator<BranchHint::kFalse> kBranchFalseOperator; |
183 | 183 |
184 template <size_t kInputCount> | 184 template <size_t kInputCount> |
185 struct LoopOperator FINAL : public Operator { | 185 struct LoopOperator FINAL : public Operator { |
186 LoopOperator() | 186 LoopOperator() |
187 : Operator( // -- | 187 : Operator( // -- |
188 IrOpcode::kLoop, Operator::kFoldable, // opcode | 188 IrOpcode::kLoop, Operator::kKontrol, // opcode |
189 "Loop", // name | 189 "Loop", // name |
190 0, 0, kInputCount, 0, 0, 1) {} // counts | 190 0, 0, kInputCount, 0, 0, 1) {} // counts |
191 }; | 191 }; |
192 #define CACHED_LOOP(input_count) \ | 192 #define CACHED_LOOP(input_count) \ |
193 LoopOperator<input_count> kLoop##input_count##Operator; | 193 LoopOperator<input_count> kLoop##input_count##Operator; |
194 CACHED_LOOP_LIST(CACHED_LOOP) | 194 CACHED_LOOP_LIST(CACHED_LOOP) |
195 #undef CACHED_LOOP | 195 #undef CACHED_LOOP |
196 | 196 |
197 template <size_t kInputCount> | 197 template <size_t kInputCount> |
198 struct MergeOperator FINAL : public Operator { | 198 struct MergeOperator FINAL : public Operator { |
199 MergeOperator() | 199 MergeOperator() |
200 : Operator( // -- | 200 : Operator( // -- |
201 IrOpcode::kMerge, Operator::kFoldable, // opcode | 201 IrOpcode::kMerge, Operator::kKontrol, // opcode |
202 "Merge", // name | 202 "Merge", // name |
203 0, 0, kInputCount, 0, 0, 1) {} // counts | 203 0, 0, kInputCount, 0, 0, 1) {} // counts |
204 }; | 204 }; |
205 #define CACHED_MERGE(input_count) \ | 205 #define CACHED_MERGE(input_count) \ |
206 MergeOperator<input_count> kMerge##input_count##Operator; | 206 MergeOperator<input_count> kMerge##input_count##Operator; |
207 CACHED_MERGE_LIST(CACHED_MERGE) | 207 CACHED_MERGE_LIST(CACHED_MERGE) |
208 #undef CACHED_MERGE | 208 #undef CACHED_MERGE |
209 | 209 |
210 template <int kIndex> | 210 template <int kIndex> |
211 struct ParameterOperator FINAL : public Operator1<int> { | 211 struct ParameterOperator FINAL : public Operator1<int> { |
212 ParameterOperator() | 212 ParameterOperator() |
213 : Operator1<int>( // -- | 213 : Operator1<int>( // -- |
214 IrOpcode::kParameter, // opcode | 214 IrOpcode::kParameter, Operator::kPure, // opcode |
215 Operator::kFoldable | Operator::kNoThrow, // flags | 215 "Parameter", // name |
216 "Parameter", // name | 216 1, 0, 0, 1, 0, 0, // counts, |
217 1, 0, 0, 1, 0, 0, // counts, | 217 kIndex) {} // parameter |
218 kIndex) {} // parameter | |
219 }; | 218 }; |
220 #define CACHED_PARAMETER(index) \ | 219 #define CACHED_PARAMETER(index) \ |
221 ParameterOperator<index> kParameter##index##Operator; | 220 ParameterOperator<index> kParameter##index##Operator; |
222 CACHED_PARAMETER_LIST(CACHED_PARAMETER) | 221 CACHED_PARAMETER_LIST(CACHED_PARAMETER) |
223 #undef CACHED_PARAMETER | 222 #undef CACHED_PARAMETER |
224 }; | 223 }; |
225 | 224 |
226 | 225 |
227 static base::LazyInstance<CommonOperatorGlobalCache>::type kCache = | 226 static base::LazyInstance<CommonOperatorGlobalCache>::type kCache = |
228 LAZY_INSTANCE_INITIALIZER; | 227 LAZY_INSTANCE_INITIALIZER; |
(...skipping 21 matching lines...) Expand all Loading... |
250 return &cache_.kBranchTrueOperator; | 249 return &cache_.kBranchTrueOperator; |
251 case BranchHint::kFalse: | 250 case BranchHint::kFalse: |
252 return &cache_.kBranchFalseOperator; | 251 return &cache_.kBranchFalseOperator; |
253 } | 252 } |
254 UNREACHABLE(); | 253 UNREACHABLE(); |
255 return nullptr; | 254 return nullptr; |
256 } | 255 } |
257 | 256 |
258 | 257 |
259 const Operator* CommonOperatorBuilder::Switch(size_t control_output_count) { | 258 const Operator* CommonOperatorBuilder::Switch(size_t control_output_count) { |
260 DCHECK_GE(control_output_count, 2u); // Disallow trivial switches. | 259 DCHECK_GE(control_output_count, 2u); // Disallow trivial switches. |
261 return new (zone()) Operator( // -- | 260 return new (zone()) Operator( // -- |
262 IrOpcode::kSwitch, Operator::kFoldable, // opcode | 261 IrOpcode::kSwitch, Operator::kKontrol, // opcode |
263 "Switch", // name | 262 "Switch", // name |
264 1, 0, 1, 0, 0, control_output_count); // counts | 263 1, 0, 1, 0, 0, control_output_count); // counts |
265 } | 264 } |
266 | 265 |
267 | 266 |
268 const Operator* CommonOperatorBuilder::Case(size_t index) { | 267 const Operator* CommonOperatorBuilder::Case(size_t index) { |
269 return new (zone()) Operator1<size_t>( // -- | 268 return new (zone()) Operator1<size_t>( // -- |
270 IrOpcode::kCase, Operator::kFoldable, // opcode | 269 IrOpcode::kCase, Operator::kKontrol, // opcode |
271 "Case", // name | 270 "Case", // name |
272 0, 0, 1, 0, 0, 1, // counts | 271 0, 0, 1, 0, 0, 1, // counts |
273 index); // parameter | 272 index); // parameter |
274 } | 273 } |
275 | 274 |
276 | 275 |
277 const Operator* CommonOperatorBuilder::Start(int num_formal_parameters) { | 276 const Operator* CommonOperatorBuilder::Start(int num_formal_parameters) { |
278 // Outputs are formal parameters, plus context, receiver, and JSFunction. | 277 // Outputs are formal parameters, plus context, receiver, and JSFunction. |
279 const int value_output_count = num_formal_parameters + 3; | 278 const int value_output_count = num_formal_parameters + 3; |
280 return new (zone()) Operator( // -- | 279 return new (zone()) Operator( // -- |
281 IrOpcode::kStart, Operator::kFoldable, // opcode | 280 IrOpcode::kStart, Operator::kFoldable, // opcode |
282 "Start", // name | 281 "Start", // name |
283 0, 0, 0, value_output_count, 1, 1); // counts | 282 0, 0, 0, value_output_count, 1, 1); // counts |
284 } | 283 } |
285 | 284 |
286 | 285 |
287 const Operator* CommonOperatorBuilder::Loop(int control_input_count) { | 286 const Operator* CommonOperatorBuilder::Loop(int control_input_count) { |
288 switch (control_input_count) { | 287 switch (control_input_count) { |
289 #define CACHED_LOOP(input_count) \ | 288 #define CACHED_LOOP(input_count) \ |
290 case input_count: \ | 289 case input_count: \ |
291 return &cache_.kLoop##input_count##Operator; | 290 return &cache_.kLoop##input_count##Operator; |
292 CACHED_LOOP_LIST(CACHED_LOOP) | 291 CACHED_LOOP_LIST(CACHED_LOOP) |
293 #undef CACHED_LOOP | 292 #undef CACHED_LOOP |
294 default: | 293 default: |
295 break; | 294 break; |
296 } | 295 } |
297 // Uncached. | 296 // Uncached. |
298 return new (zone()) Operator( // -- | 297 return new (zone()) Operator( // -- |
299 IrOpcode::kLoop, Operator::kFoldable, // opcode | 298 IrOpcode::kLoop, Operator::kKontrol, // opcode |
300 "Loop", // name | 299 "Loop", // name |
301 0, 0, control_input_count, 0, 0, 1); // counts | 300 0, 0, control_input_count, 0, 0, 1); // counts |
302 } | 301 } |
303 | 302 |
304 | 303 |
305 const Operator* CommonOperatorBuilder::Merge(int control_input_count) { | 304 const Operator* CommonOperatorBuilder::Merge(int control_input_count) { |
306 switch (control_input_count) { | 305 switch (control_input_count) { |
307 #define CACHED_MERGE(input_count) \ | 306 #define CACHED_MERGE(input_count) \ |
308 case input_count: \ | 307 case input_count: \ |
309 return &cache_.kMerge##input_count##Operator; | 308 return &cache_.kMerge##input_count##Operator; |
310 CACHED_MERGE_LIST(CACHED_MERGE) | 309 CACHED_MERGE_LIST(CACHED_MERGE) |
311 #undef CACHED_MERGE | 310 #undef CACHED_MERGE |
312 default: | 311 default: |
313 break; | 312 break; |
314 } | 313 } |
315 // Uncached. | 314 // Uncached. |
316 return new (zone()) Operator( // -- | 315 return new (zone()) Operator( // -- |
317 IrOpcode::kMerge, Operator::kFoldable, // opcode | 316 IrOpcode::kMerge, Operator::kKontrol, // opcode |
318 "Merge", // name | 317 "Merge", // name |
319 0, 0, control_input_count, 0, 0, 1); // counts | 318 0, 0, control_input_count, 0, 0, 1); // counts |
320 } | 319 } |
321 | 320 |
322 | 321 |
323 const Operator* CommonOperatorBuilder::Parameter(int index) { | 322 const Operator* CommonOperatorBuilder::Parameter(int index) { |
324 switch (index) { | 323 switch (index) { |
325 #define CACHED_PARAMETER(index) \ | 324 #define CACHED_PARAMETER(index) \ |
326 case index: \ | 325 case index: \ |
327 return &cache_.kParameter##index##Operator; | 326 return &cache_.kParameter##index##Operator; |
328 CACHED_PARAMETER_LIST(CACHED_PARAMETER) | 327 CACHED_PARAMETER_LIST(CACHED_PARAMETER) |
329 #undef CACHED_PARAMETER | 328 #undef CACHED_PARAMETER |
330 default: | 329 default: |
331 break; | 330 break; |
332 } | 331 } |
333 // Uncached. | 332 // Uncached. |
334 return new (zone()) Operator1<int>( // -- | 333 return new (zone()) Operator1<int>( // -- |
335 IrOpcode::kParameter, // opcode | 334 IrOpcode::kParameter, Operator::kPure, // opcode |
336 Operator::kFoldable | Operator::kNoThrow, // flags | 335 "Parameter", // name |
337 "Parameter", // name | 336 1, 0, 0, 1, 0, 0, // counts |
338 1, 0, 0, 1, 0, 0, // counts | 337 index); // parameter |
339 index); // parameter | |
340 } | 338 } |
341 | 339 |
342 | 340 |
343 const Operator* CommonOperatorBuilder::OsrValue(int index) { | 341 const Operator* CommonOperatorBuilder::OsrValue(int index) { |
344 return new (zone()) Operator1<int>( // -- | 342 return new (zone()) Operator1<int>( // -- |
345 IrOpcode::kOsrValue, Operator::kNoProperties, // opcode | 343 IrOpcode::kOsrValue, Operator::kNoProperties, // opcode |
346 "OsrValue", // name | 344 "OsrValue", // name |
347 0, 0, 1, 1, 0, 0, // counts | 345 0, 0, 1, 1, 0, 0, // counts |
348 index); // parameter | 346 index); // parameter |
349 } | 347 } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 } else { | 533 } else { |
536 UNREACHABLE(); | 534 UNREACHABLE(); |
537 return nullptr; | 535 return nullptr; |
538 } | 536 } |
539 } | 537 } |
540 | 538 |
541 | 539 |
542 } // namespace compiler | 540 } // namespace compiler |
543 } // namespace internal | 541 } // namespace internal |
544 } // namespace v8 | 542 } // namespace v8 |
OLD | NEW |