Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: src/compiler/common-operator.cc

Issue 1015053002: [turbofan] Cache more common operators. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/common-operator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 V(IfSuccess, Operator::kKontrol, 0, 0, 1, 0, 0, 1) \ 118 V(IfSuccess, Operator::kKontrol, 0, 0, 1, 0, 0, 1) \
119 V(IfException, Operator::kKontrol, 0, 0, 1, 0, 0, 1) \ 119 V(IfException, Operator::kKontrol, 0, 0, 1, 0, 0, 1) \
120 V(IfDefault, Operator::kKontrol, 0, 0, 1, 0, 0, 1) \ 120 V(IfDefault, Operator::kKontrol, 0, 0, 1, 0, 0, 1) \
121 V(Throw, Operator::kFoldable, 1, 1, 1, 0, 0, 1) \ 121 V(Throw, Operator::kFoldable, 1, 1, 1, 0, 0, 1) \
122 V(Deoptimize, Operator::kNoThrow, 1, 1, 1, 0, 0, 1) \ 122 V(Deoptimize, Operator::kNoThrow, 1, 1, 1, 0, 0, 1) \
123 V(Return, Operator::kNoThrow, 1, 1, 1, 0, 0, 1) \ 123 V(Return, Operator::kNoThrow, 1, 1, 1, 0, 0, 1) \
124 V(OsrNormalEntry, Operator::kFoldable, 0, 1, 1, 0, 1, 1) \ 124 V(OsrNormalEntry, Operator::kFoldable, 0, 1, 1, 0, 1, 1) \
125 V(OsrLoopEntry, Operator::kFoldable, 0, 1, 1, 0, 1, 1) 125 V(OsrLoopEntry, Operator::kFoldable, 0, 1, 1, 0, 1, 1)
126 126
127 127
128 #define CACHED_EFFECT_PHI_LIST(V) \
129 V(1) \
130 V(2) \
131 V(3) \
132 V(4) \
133 V(5) \
134 V(6)
135
136
128 #define CACHED_LOOP_LIST(V) \ 137 #define CACHED_LOOP_LIST(V) \
129 V(1) \ 138 V(1) \
130 V(2) 139 V(2)
131 140
132 141
133 #define CACHED_MERGE_LIST(V) \ 142 #define CACHED_MERGE_LIST(V) \
134 V(1) \ 143 V(1) \
135 V(2) \ 144 V(2) \
136 V(3) \ 145 V(3) \
137 V(4) \ 146 V(4) \
138 V(5) \ 147 V(5) \
139 V(6) \ 148 V(6) \
140 V(7) \ 149 V(7) \
141 V(8) 150 V(8)
142 151
143 152
144 #define CACHED_PARAMETER_LIST(V) \ 153 #define CACHED_PARAMETER_LIST(V) \
145 V(0) \ 154 V(0) \
146 V(1) \ 155 V(1) \
147 V(2) \ 156 V(2) \
148 V(3) \ 157 V(3) \
149 V(4) \ 158 V(4) \
150 V(5) \ 159 V(5) \
151 V(6) 160 V(6)
152 161
153 162
163 #define CACHED_PHI_LIST(V) \
164 V(kMachAnyTagged, 1) \
165 V(kMachAnyTagged, 2) \
166 V(kMachAnyTagged, 3) \
167 V(kMachAnyTagged, 4) \
168 V(kMachAnyTagged, 5) \
169 V(kMachAnyTagged, 6) \
170 V(kMachBool, 2) \
171 V(kMachFloat64, 2) \
172 V(kMachInt32, 2)
173
174
175 #define CACHED_PROJECTION_LIST(V) \
176 V(0) \
177 V(1)
178
179
180 #define CACHED_STATE_VALUES_LIST(V) \
181 V(0) \
182 V(1) \
183 V(2) \
184 V(3) \
185 V(4) \
186 V(5) \
187 V(6) \
188 V(7) \
189 V(8) \
190 V(10) \
191 V(11) \
192 V(12) \
193 V(13) \
194 V(14)
195
196
154 struct CommonOperatorGlobalCache FINAL { 197 struct CommonOperatorGlobalCache FINAL {
155 #define CACHED(Name, properties, value_input_count, effect_input_count, \ 198 #define CACHED(Name, properties, value_input_count, effect_input_count, \
156 control_input_count, value_output_count, effect_output_count, \ 199 control_input_count, value_output_count, effect_output_count, \
157 control_output_count) \ 200 control_output_count) \
158 struct Name##Operator FINAL : public Operator { \ 201 struct Name##Operator FINAL : public Operator { \
159 Name##Operator() \ 202 Name##Operator() \
160 : Operator(IrOpcode::k##Name, properties, #Name, value_input_count, \ 203 : Operator(IrOpcode::k##Name, properties, #Name, value_input_count, \
161 effect_input_count, control_input_count, \ 204 effect_input_count, control_input_count, \
162 value_output_count, effect_output_count, \ 205 value_output_count, effect_output_count, \
163 control_output_count) {} \ 206 control_output_count) {} \
164 }; \ 207 }; \
165 Name##Operator k##Name##Operator; 208 Name##Operator k##Name##Operator;
166 CACHED_OP_LIST(CACHED) 209 CACHED_OP_LIST(CACHED)
167 #undef CACHED 210 #undef CACHED
168 211
169 template <BranchHint kBranchHint> 212 template <BranchHint kBranchHint>
170 struct BranchOperator FINAL : public Operator1<BranchHint> { 213 struct BranchOperator FINAL : public Operator1<BranchHint> {
171 BranchOperator() 214 BranchOperator()
172 : Operator1<BranchHint>( // -- 215 : Operator1<BranchHint>( // --
173 IrOpcode::kBranch, Operator::kKontrol, // opcode 216 IrOpcode::kBranch, Operator::kKontrol, // opcode
174 "Branch", // name 217 "Branch", // name
175 1, 0, 1, 0, 0, 2, // counts 218 1, 0, 1, 0, 0, 2, // counts
176 kBranchHint) {} // parameter 219 kBranchHint) {} // parameter
177 }; 220 };
178 BranchOperator<BranchHint::kNone> kBranchNoneOperator; 221 BranchOperator<BranchHint::kNone> kBranchNoneOperator;
179 BranchOperator<BranchHint::kTrue> kBranchTrueOperator; 222 BranchOperator<BranchHint::kTrue> kBranchTrueOperator;
180 BranchOperator<BranchHint::kFalse> kBranchFalseOperator; 223 BranchOperator<BranchHint::kFalse> kBranchFalseOperator;
181 224
225 template <int kEffectInputCount>
226 struct EffectPhiOperator FINAL : public Operator {
227 EffectPhiOperator()
228 : Operator( // --
229 IrOpcode::kEffectPhi, Operator::kPure, // opcode
230 "EffectPhi", // name
231 0, kEffectInputCount, 1, 0, 1, 0) {} // counts
232 };
233 #define CACHED_EFFECT_PHI(input_count) \
234 EffectPhiOperator<input_count> kEffectPhi##input_count##Operator;
235 CACHED_EFFECT_PHI_LIST(CACHED_EFFECT_PHI)
236 #undef CACHED_EFFECT_PHI
237
182 template <size_t kInputCount> 238 template <size_t kInputCount>
183 struct LoopOperator FINAL : public Operator { 239 struct LoopOperator FINAL : public Operator {
184 LoopOperator() 240 LoopOperator()
185 : Operator( // -- 241 : Operator( // --
186 IrOpcode::kLoop, Operator::kKontrol, // opcode 242 IrOpcode::kLoop, Operator::kKontrol, // opcode
187 "Loop", // name 243 "Loop", // name
188 0, 0, kInputCount, 0, 0, 1) {} // counts 244 0, 0, kInputCount, 0, 0, 1) {} // counts
189 }; 245 };
190 #define CACHED_LOOP(input_count) \ 246 #define CACHED_LOOP(input_count) \
191 LoopOperator<input_count> kLoop##input_count##Operator; 247 LoopOperator<input_count> kLoop##input_count##Operator;
192 CACHED_LOOP_LIST(CACHED_LOOP) 248 CACHED_LOOP_LIST(CACHED_LOOP)
193 #undef CACHED_LOOP 249 #undef CACHED_LOOP
194 250
195 template <size_t kInputCount> 251 template <size_t kInputCount>
196 struct MergeOperator FINAL : public Operator { 252 struct MergeOperator FINAL : public Operator {
197 MergeOperator() 253 MergeOperator()
198 : Operator( // -- 254 : Operator( // --
199 IrOpcode::kMerge, Operator::kKontrol, // opcode 255 IrOpcode::kMerge, Operator::kKontrol, // opcode
200 "Merge", // name 256 "Merge", // name
201 0, 0, kInputCount, 0, 0, 1) {} // counts 257 0, 0, kInputCount, 0, 0, 1) {} // counts
202 }; 258 };
203 #define CACHED_MERGE(input_count) \ 259 #define CACHED_MERGE(input_count) \
204 MergeOperator<input_count> kMerge##input_count##Operator; 260 MergeOperator<input_count> kMerge##input_count##Operator;
205 CACHED_MERGE_LIST(CACHED_MERGE) 261 CACHED_MERGE_LIST(CACHED_MERGE)
206 #undef CACHED_MERGE 262 #undef CACHED_MERGE
207 263
264 template <MachineType kType, int kInputCount>
265 struct PhiOperator FINAL : public Operator1<MachineType> {
266 PhiOperator()
267 : Operator1<MachineType>( //--
268 IrOpcode::kPhi, Operator::kPure, // opcode
269 "Phi", // name
270 kInputCount, 0, 1, 1, 0, 0, // counts
271 kType) {} // parameter
272 };
273 #define CACHED_PHI(type, input_count) \
274 PhiOperator<type, input_count> kPhi##type##input_count##Operator;
275 CACHED_PHI_LIST(CACHED_PHI)
276 #undef CACHED_PHI
277
208 template <int kIndex> 278 template <int kIndex>
209 struct ParameterOperator FINAL : public Operator1<int> { 279 struct ParameterOperator FINAL : public Operator1<int> {
210 ParameterOperator() 280 ParameterOperator()
211 : Operator1<int>( // -- 281 : Operator1<int>( // --
212 IrOpcode::kParameter, Operator::kPure, // opcode 282 IrOpcode::kParameter, Operator::kPure, // opcode
213 "Parameter", // name 283 "Parameter", // name
214 1, 0, 0, 1, 0, 0, // counts, 284 1, 0, 0, 1, 0, 0, // counts,
215 kIndex) {} // parameter 285 kIndex) {} // parameter
216 }; 286 };
217 #define CACHED_PARAMETER(index) \ 287 #define CACHED_PARAMETER(index) \
218 ParameterOperator<index> kParameter##index##Operator; 288 ParameterOperator<index> kParameter##index##Operator;
219 CACHED_PARAMETER_LIST(CACHED_PARAMETER) 289 CACHED_PARAMETER_LIST(CACHED_PARAMETER)
220 #undef CACHED_PARAMETER 290 #undef CACHED_PARAMETER
291
292 template <size_t kIndex>
293 struct ProjectionOperator FINAL : public Operator1<size_t> {
294 ProjectionOperator()
295 : Operator1<size_t>( // --
296 IrOpcode::kProjection, // opcode
297 Operator::kFoldable | Operator::kNoThrow, // flags
298 "Projection", // name
299 1, 0, 0, 1, 0, 0, // counts,
300 kIndex) {} // parameter
301 };
302 #define CACHED_PROJECTION(index) \
303 ProjectionOperator<index> kProjection##index##Operator;
304 CACHED_PROJECTION_LIST(CACHED_PROJECTION)
305 #undef CACHED_PROJECTION
306
307 template <int kInputCount>
308 struct StateValuesOperator FINAL : public Operator {
309 StateValuesOperator()
310 : Operator( // --
311 IrOpcode::kStateValues, // opcode
312 Operator::kPure, // flags
313 "StateValues", // name
314 kInputCount, 0, 0, 1, 0, 0) {} // counts
315 };
316 #define CACHED_STATE_VALUES(input_count) \
317 StateValuesOperator<input_count> kStateValues##input_count##Operator;
318 CACHED_STATE_VALUES_LIST(CACHED_STATE_VALUES)
319 #undef CACHED_STATE_VALUES
221 }; 320 };
222 321
223 322
224 static base::LazyInstance<CommonOperatorGlobalCache>::type kCache = 323 static base::LazyInstance<CommonOperatorGlobalCache>::type kCache =
225 LAZY_INSTANCE_INITIALIZER; 324 LAZY_INSTANCE_INITIALIZER;
226 325
227 326
228 CommonOperatorBuilder::CommonOperatorBuilder(Zone* zone) 327 CommonOperatorBuilder::CommonOperatorBuilder(Zone* zone)
229 : cache_(kCache.Get()), zone_(zone) {} 328 : cache_(kCache.Get()), zone_(zone) {}
230 329
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 const Operator* CommonOperatorBuilder::Select(MachineType type, 515 const Operator* CommonOperatorBuilder::Select(MachineType type,
417 BranchHint hint) { 516 BranchHint hint) {
418 return new (zone()) Operator1<SelectParameters>( // -- 517 return new (zone()) Operator1<SelectParameters>( // --
419 IrOpcode::kSelect, Operator::kPure, // opcode 518 IrOpcode::kSelect, Operator::kPure, // opcode
420 "Select", // name 519 "Select", // name
421 3, 0, 0, 1, 0, 0, // counts 520 3, 0, 0, 1, 0, 0, // counts
422 SelectParameters(type, hint)); // parameter 521 SelectParameters(type, hint)); // parameter
423 } 522 }
424 523
425 524
426 const Operator* CommonOperatorBuilder::Phi(MachineType type, int arguments) { 525 const Operator* CommonOperatorBuilder::Phi(MachineType type,
427 DCHECK(arguments > 0); // Disallow empty phis. 526 int value_input_count) {
527 DCHECK(value_input_count > 0); // Disallow empty phis.
528 #define CACHED_PHI(kType, kValueInputCount) \
529 if (kType == type && kValueInputCount == value_input_count) { \
530 return &cache_.kPhi##kType##kValueInputCount##Operator; \
531 }
532 CACHED_PHI_LIST(CACHED_PHI)
533 #undef CACHED_PHI
534 // Uncached.
428 return new (zone()) Operator1<MachineType>( // -- 535 return new (zone()) Operator1<MachineType>( // --
429 IrOpcode::kPhi, Operator::kPure, // opcode 536 IrOpcode::kPhi, Operator::kPure, // opcode
430 "Phi", // name 537 "Phi", // name
431 arguments, 0, 1, 1, 0, 0, // counts 538 value_input_count, 0, 1, 1, 0, 0, // counts
432 type); // parameter 539 type); // parameter
433 } 540 }
434 541
435 542
436 const Operator* CommonOperatorBuilder::EffectPhi(int arguments) { 543 const Operator* CommonOperatorBuilder::EffectPhi(int effect_input_count) {
437 DCHECK(arguments > 0); // Disallow empty phis. 544 DCHECK(effect_input_count > 0); // Disallow empty effect phis.
545 switch (effect_input_count) {
546 #define CACHED_EFFECT_PHI(input_count) \
547 case input_count: \
548 return &cache_.kEffectPhi##input_count##Operator;
549 CACHED_EFFECT_PHI_LIST(CACHED_EFFECT_PHI)
550 #undef CACHED_EFFECT_PHI
551 default:
552 break;
553 }
554 // Uncached.
438 return new (zone()) Operator( // -- 555 return new (zone()) Operator( // --
439 IrOpcode::kEffectPhi, Operator::kPure, // opcode 556 IrOpcode::kEffectPhi, Operator::kPure, // opcode
440 "EffectPhi", // name 557 "EffectPhi", // name
441 0, arguments, 1, 0, 1, 0); // counts 558 0, effect_input_count, 1, 0, 1, 0); // counts
442 } 559 }
443 560
444 561
445 const Operator* CommonOperatorBuilder::EffectSet(int arguments) { 562 const Operator* CommonOperatorBuilder::EffectSet(int arguments) {
446 DCHECK(arguments > 1); // Disallow empty/singleton sets. 563 DCHECK(arguments > 1); // Disallow empty/singleton sets.
447 return new (zone()) Operator( // -- 564 return new (zone()) Operator( // --
448 IrOpcode::kEffectSet, Operator::kPure, // opcode 565 IrOpcode::kEffectSet, Operator::kPure, // opcode
449 "EffectSet", // name 566 "EffectSet", // name
450 0, arguments, 0, 0, 1, 0); // counts 567 0, arguments, 0, 0, 1, 0); // counts
451 } 568 }
(...skipping 11 matching lines...) Expand all
463 const Operator* CommonOperatorBuilder::Finish(int arguments) { 580 const Operator* CommonOperatorBuilder::Finish(int arguments) {
464 DCHECK(arguments > 0); // Disallow empty finishes. 581 DCHECK(arguments > 0); // Disallow empty finishes.
465 return new (zone()) Operator( // -- 582 return new (zone()) Operator( // --
466 IrOpcode::kFinish, Operator::kPure, // opcode 583 IrOpcode::kFinish, Operator::kPure, // opcode
467 "Finish", // name 584 "Finish", // name
468 1, arguments, 0, 1, 0, 0); // counts 585 1, arguments, 0, 1, 0, 0); // counts
469 } 586 }
470 587
471 588
472 const Operator* CommonOperatorBuilder::StateValues(int arguments) { 589 const Operator* CommonOperatorBuilder::StateValues(int arguments) {
590 switch (arguments) {
591 #define CACHED_STATE_VALUES(arguments) \
592 case arguments: \
593 return &cache_.kStateValues##arguments##Operator;
594 CACHED_STATE_VALUES_LIST(CACHED_STATE_VALUES)
595 #undef CACHED_STATE_VALUES
596 default:
597 break;
598 }
599 // Uncached.
473 return new (zone()) Operator( // -- 600 return new (zone()) Operator( // --
474 IrOpcode::kStateValues, Operator::kPure, // opcode 601 IrOpcode::kStateValues, Operator::kPure, // opcode
475 "StateValues", // name 602 "StateValues", // name
476 arguments, 0, 0, 1, 0, 0); // counts 603 arguments, 0, 0, 1, 0, 0); // counts
477 } 604 }
478 605
479 606
480 const Operator* CommonOperatorBuilder::FrameState( 607 const Operator* CommonOperatorBuilder::FrameState(
481 FrameStateType type, BailoutId bailout_id, 608 FrameStateType type, BailoutId bailout_id,
482 OutputFrameStateCombine state_combine, MaybeHandle<JSFunction> jsfunction) { 609 OutputFrameStateCombine state_combine, MaybeHandle<JSFunction> jsfunction) {
(...skipping 20 matching lines...) Expand all
503 630
504 void PrintParameter(std::ostream& os) const OVERRIDE { 631 void PrintParameter(std::ostream& os) const OVERRIDE {
505 os << "[" << *parameter() << "]"; 632 os << "[" << *parameter() << "]";
506 } 633 }
507 }; 634 };
508 return new (zone()) CallOperator(descriptor, "Call"); 635 return new (zone()) CallOperator(descriptor, "Call");
509 } 636 }
510 637
511 638
512 const Operator* CommonOperatorBuilder::Projection(size_t index) { 639 const Operator* CommonOperatorBuilder::Projection(size_t index) {
640 switch (index) {
641 #define CACHED_PROJECTION(index) \
642 case index: \
643 return &cache_.kProjection##index##Operator;
644 CACHED_PROJECTION_LIST(CACHED_PROJECTION)
645 #undef CACHED_PROJECTION
646 default:
647 break;
648 }
649 // Uncached.
513 return new (zone()) Operator1<size_t>( // -- 650 return new (zone()) Operator1<size_t>( // --
514 IrOpcode::kProjection, // opcode 651 IrOpcode::kProjection, // opcode
515 Operator::kFoldable | Operator::kNoThrow, // flags 652 Operator::kFoldable | Operator::kNoThrow, // flags
516 "Projection", // name 653 "Projection", // name
517 1, 0, 0, 1, 0, 0, // counts 654 1, 0, 0, 1, 0, 0, // counts
518 index); // parameter 655 index); // parameter
519 } 656 }
520 657
521 658
522 const Operator* CommonOperatorBuilder::ResizeMergeOrPhi(const Operator* op, 659 const Operator* CommonOperatorBuilder::ResizeMergeOrPhi(const Operator* op,
523 int size) { 660 int size) {
524 if (op->opcode() == IrOpcode::kPhi) { 661 if (op->opcode() == IrOpcode::kPhi) {
525 return Phi(OpParameter<MachineType>(op), size); 662 return Phi(OpParameter<MachineType>(op), size);
526 } else if (op->opcode() == IrOpcode::kEffectPhi) { 663 } else if (op->opcode() == IrOpcode::kEffectPhi) {
527 return EffectPhi(size); 664 return EffectPhi(size);
528 } else if (op->opcode() == IrOpcode::kMerge) { 665 } else if (op->opcode() == IrOpcode::kMerge) {
529 return Merge(size); 666 return Merge(size);
530 } else if (op->opcode() == IrOpcode::kLoop) { 667 } else if (op->opcode() == IrOpcode::kLoop) {
531 return Loop(size); 668 return Loop(size);
532 } else { 669 } else {
533 UNREACHABLE(); 670 UNREACHABLE();
534 return nullptr; 671 return nullptr;
535 } 672 }
536 } 673 }
537 674
538 675
539 } // namespace compiler 676 } // namespace compiler
540 } // namespace internal 677 } // namespace internal
541 } // namespace v8 678 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/common-operator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698