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

Side by Side Diff: src/compiler/js-intrinsic-lowering.cc

Issue 1366753003: [turbofan] Make Node::set_op safer via wrapper. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments. Created 5 years, 3 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/js-inlining.cc ('k') | src/compiler/js-typed-lowering.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/js-intrinsic-lowering.h" 5 #include "src/compiler/js-intrinsic-lowering.h"
6 6
7 #include <stack> 7 #include <stack>
8 8
9 #include "src/compiler/access-builder.h" 9 #include "src/compiler/access-builder.h"
10 #include "src/compiler/js-graph.h" 10 #include "src/compiler/js-graph.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if (mode() != kDeoptimizationEnabled) return NoChange(); 142 if (mode() != kDeoptimizationEnabled) return NoChange();
143 Node* const frame_state = NodeProperties::GetFrameStateInput(node, 0); 143 Node* const frame_state = NodeProperties::GetFrameStateInput(node, 0);
144 Node* const effect = NodeProperties::GetEffectInput(node); 144 Node* const effect = NodeProperties::GetEffectInput(node);
145 Node* const control = NodeProperties::GetControlInput(node); 145 Node* const control = NodeProperties::GetControlInput(node);
146 146
147 // TODO(bmeurer): Move MergeControlToEnd() to the AdvancedReducer. 147 // TODO(bmeurer): Move MergeControlToEnd() to the AdvancedReducer.
148 Node* deoptimize = 148 Node* deoptimize =
149 graph()->NewNode(common()->Deoptimize(), frame_state, effect, control); 149 graph()->NewNode(common()->Deoptimize(), frame_state, effect, control);
150 NodeProperties::MergeControlToEnd(graph(), common(), deoptimize); 150 NodeProperties::MergeControlToEnd(graph(), common(), deoptimize);
151 151
152 node->set_op(common()->Dead());
153 node->TrimInputCount(0); 152 node->TrimInputCount(0);
153 NodeProperties::ChangeOp(node, common()->Dead());
154 return Changed(node); 154 return Changed(node);
155 } 155 }
156 156
157 157
158 Reduction JSIntrinsicLowering::ReduceDoubleHi(Node* node) { 158 Reduction JSIntrinsicLowering::ReduceDoubleHi(Node* node) {
159 return Change(node, machine()->Float64ExtractHighWord32()); 159 return Change(node, machine()->Float64ExtractHighWord32());
160 } 160 }
161 161
162 162
163 Reduction JSIntrinsicLowering::ReduceDoubleLo(Node* node) { 163 Reduction JSIntrinsicLowering::ReduceDoubleLo(Node* node) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 276
277 Reduction JSIntrinsicLowering::ReduceMathSqrt(Node* node) { 277 Reduction JSIntrinsicLowering::ReduceMathSqrt(Node* node) {
278 return Change(node, machine()->Float64Sqrt()); 278 return Change(node, machine()->Float64Sqrt());
279 } 279 }
280 280
281 281
282 Reduction JSIntrinsicLowering::ReduceSeqStringGetChar( 282 Reduction JSIntrinsicLowering::ReduceSeqStringGetChar(
283 Node* node, String::Encoding encoding) { 283 Node* node, String::Encoding encoding) {
284 Node* effect = NodeProperties::GetEffectInput(node); 284 Node* effect = NodeProperties::GetEffectInput(node);
285 Node* control = NodeProperties::GetControlInput(node); 285 Node* control = NodeProperties::GetControlInput(node);
286 node->set_op(
287 simplified()->LoadElement(AccessBuilder::ForSeqStringChar(encoding)));
288 node->ReplaceInput(2, effect); 286 node->ReplaceInput(2, effect);
289 node->ReplaceInput(3, control); 287 node->ReplaceInput(3, control);
290 node->TrimInputCount(4); 288 node->TrimInputCount(4);
289 NodeProperties::ChangeOp(
290 node,
291 simplified()->LoadElement(AccessBuilder::ForSeqStringChar(encoding)));
291 RelaxControls(node); 292 RelaxControls(node);
292 return Changed(node); 293 return Changed(node);
293 } 294 }
294 295
295 296
296 Reduction JSIntrinsicLowering::ReduceSeqStringSetChar( 297 Reduction JSIntrinsicLowering::ReduceSeqStringSetChar(
297 Node* node, String::Encoding encoding) { 298 Node* node, String::Encoding encoding) {
298 // Note: The intrinsic has a strange argument order, so we need to reshuffle. 299 // Note: The intrinsic has a strange argument order, so we need to reshuffle.
299 Node* index = NodeProperties::GetValueInput(node, 0); 300 Node* index = NodeProperties::GetValueInput(node, 0);
300 Node* chr = NodeProperties::GetValueInput(node, 1); 301 Node* chr = NodeProperties::GetValueInput(node, 1);
301 Node* string = NodeProperties::GetValueInput(node, 2); 302 Node* string = NodeProperties::GetValueInput(node, 2);
302 Node* effect = NodeProperties::GetEffectInput(node); 303 Node* effect = NodeProperties::GetEffectInput(node);
303 Node* control = NodeProperties::GetControlInput(node); 304 Node* control = NodeProperties::GetControlInput(node);
304 node->set_op(
305 simplified()->StoreElement(AccessBuilder::ForSeqStringChar(encoding)));
306 node->ReplaceInput(0, string); 305 node->ReplaceInput(0, string);
307 node->ReplaceInput(1, index); 306 node->ReplaceInput(1, index);
308 node->ReplaceInput(2, chr); 307 node->ReplaceInput(2, chr);
309 node->ReplaceInput(3, effect); 308 node->ReplaceInput(3, effect);
310 node->ReplaceInput(4, control); 309 node->ReplaceInput(4, control);
311 node->TrimInputCount(5); 310 node->TrimInputCount(5);
311 NodeProperties::ChangeOp(
312 node,
313 simplified()->StoreElement(AccessBuilder::ForSeqStringChar(encoding)));
312 NodeProperties::RemoveType(node); 314 NodeProperties::RemoveType(node);
313 ReplaceWithValue(node, string, node); 315 ReplaceWithValue(node, string, node);
314 return Changed(node); 316 return Changed(node);
315 } 317 }
316 318
317 319
318 Reduction JSIntrinsicLowering::ReduceStringGetLength(Node* node) { 320 Reduction JSIntrinsicLowering::ReduceStringGetLength(Node* node) {
319 Node* value = NodeProperties::GetValueInput(node, 0); 321 Node* value = NodeProperties::GetValueInput(node, 0);
320 Node* effect = NodeProperties::GetEffectInput(node); 322 Node* effect = NodeProperties::GetEffectInput(node);
321 Node* control = NodeProperties::GetControlInput(node); 323 Node* control = NodeProperties::GetControlInput(node);
322 return Change(node, simplified()->LoadField( 324 return Change(node, simplified()->LoadField(
323 AccessBuilder::ForStringLength(graph()->zone())), 325 AccessBuilder::ForStringLength(graph()->zone())),
324 value, effect, control); 326 value, effect, control);
325 } 327 }
326 328
327 329
328 Reduction JSIntrinsicLowering::ReduceUnLikely(Node* node, BranchHint hint) { 330 Reduction JSIntrinsicLowering::ReduceUnLikely(Node* node, BranchHint hint) {
329 std::stack<Node*> nodes_to_visit; 331 std::stack<Node*> nodes_to_visit;
330 nodes_to_visit.push(node); 332 nodes_to_visit.push(node);
331 while (!nodes_to_visit.empty()) { 333 while (!nodes_to_visit.empty()) {
332 Node* current = nodes_to_visit.top(); 334 Node* current = nodes_to_visit.top();
333 nodes_to_visit.pop(); 335 nodes_to_visit.pop();
334 for (Node* use : current->uses()) { 336 for (Node* use : current->uses()) {
335 if (use->opcode() == IrOpcode::kJSToBoolean) { 337 if (use->opcode() == IrOpcode::kJSToBoolean) {
336 // We have to "look through" ToBoolean calls. 338 // We have to "look through" ToBoolean calls.
337 nodes_to_visit.push(use); 339 nodes_to_visit.push(use);
338 } else if (use->opcode() == IrOpcode::kBranch) { 340 } else if (use->opcode() == IrOpcode::kBranch) {
339 // Actually set the hint on any branch using the intrinsic node. 341 // Actually set the hint on any branch using the intrinsic node.
340 use->set_op(common()->Branch(hint)); 342 NodeProperties::ChangeOp(use, common()->Branch(hint));
341 } 343 }
342 } 344 }
343 } 345 }
344 // Apart from adding hints to branchs nodes, this is the identity function. 346 // Apart from adding hints to branchs nodes, this is the identity function.
345 Node* value = NodeProperties::GetValueInput(node, 0); 347 Node* value = NodeProperties::GetValueInput(node, 0);
346 ReplaceWithValue(node, value); 348 ReplaceWithValue(node, value);
347 return Changed(value); 349 return Changed(value);
348 } 350 }
349 351
350 352
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 return Change(node, phi_op, vtrue0, vfalse0, merge0); 412 return Change(node, phi_op, vtrue0, vfalse0, merge0);
411 } 413 }
412 414
413 415
414 Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op) { 416 Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op) {
415 // Replace all effect uses of {node} with the effect dependency. 417 // Replace all effect uses of {node} with the effect dependency.
416 RelaxEffectsAndControls(node); 418 RelaxEffectsAndControls(node);
417 // Remove the inputs corresponding to context, effect and control. 419 // Remove the inputs corresponding to context, effect and control.
418 NodeProperties::RemoveNonValueInputs(node); 420 NodeProperties::RemoveNonValueInputs(node);
419 // Finally update the operator to the new one. 421 // Finally update the operator to the new one.
420 node->set_op(op); 422 NodeProperties::ChangeOp(node, op);
421 return Changed(node); 423 return Changed(node);
422 } 424 }
423 425
424 426
425 Reduction JSIntrinsicLowering::ReduceIsMinusZero(Node* node) { 427 Reduction JSIntrinsicLowering::ReduceIsMinusZero(Node* node) {
426 Node* value = NodeProperties::GetValueInput(node, 0); 428 Node* value = NodeProperties::GetValueInput(node, 0);
427 Node* effect = NodeProperties::GetEffectInput(node); 429 Node* effect = NodeProperties::GetEffectInput(node);
428 430
429 Node* double_lo = 431 Node* double_lo =
430 graph()->NewNode(machine()->Float64ExtractLowWord32(), value); 432 graph()->NewNode(machine()->Float64ExtractLowWord32(), value);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 if (mode() != kDeoptimizationEnabled) return NoChange(); 514 if (mode() != kDeoptimizationEnabled) return NoChange();
513 Node* const frame_state = NodeProperties::GetFrameStateInput(node, 1); 515 Node* const frame_state = NodeProperties::GetFrameStateInput(node, 1);
514 Node* const effect = NodeProperties::GetEffectInput(node); 516 Node* const effect = NodeProperties::GetEffectInput(node);
515 Node* const control = NodeProperties::GetControlInput(node); 517 Node* const control = NodeProperties::GetControlInput(node);
516 518
517 // TODO(bmeurer): Move MergeControlToEnd() to the AdvancedReducer. 519 // TODO(bmeurer): Move MergeControlToEnd() to the AdvancedReducer.
518 Node* deoptimize = 520 Node* deoptimize =
519 graph()->NewNode(common()->Deoptimize(), frame_state, effect, control); 521 graph()->NewNode(common()->Deoptimize(), frame_state, effect, control);
520 NodeProperties::MergeControlToEnd(graph(), common(), deoptimize); 522 NodeProperties::MergeControlToEnd(graph(), common(), deoptimize);
521 523
522 node->set_op(common()->Dead());
523 node->TrimInputCount(0); 524 node->TrimInputCount(0);
525 NodeProperties::ChangeOp(node, common()->Dead());
524 return Changed(node); 526 return Changed(node);
525 } 527 }
526 528
527 529
528 Reduction JSIntrinsicLowering::ReduceToObject(Node* node) { 530 Reduction JSIntrinsicLowering::ReduceToObject(Node* node) {
529 node->set_op(javascript()->ToObject()); 531 NodeProperties::ChangeOp(node, javascript()->ToObject());
530 return Changed(node); 532 return Changed(node);
531 } 533 }
532 534
533 535
534 Reduction JSIntrinsicLowering::ReduceCallFunction(Node* node) { 536 Reduction JSIntrinsicLowering::ReduceCallFunction(Node* node) {
535 CallRuntimeParameters params = OpParameter<CallRuntimeParameters>(node->op()); 537 CallRuntimeParameters params = OpParameter<CallRuntimeParameters>(node->op());
536 size_t arity = params.arity(); 538 size_t arity = params.arity();
537 node->set_op(javascript()->CallFunction(arity, NO_CALL_FUNCTION_FLAGS, STRICT,
538 VectorSlotPair(), ALLOW_TAIL_CALLS));
539 Node* function = node->InputAt(static_cast<int>(arity - 1)); 539 Node* function = node->InputAt(static_cast<int>(arity - 1));
540 while (--arity != 0) { 540 while (--arity != 0) {
541 node->ReplaceInput(static_cast<int>(arity), 541 node->ReplaceInput(static_cast<int>(arity),
542 node->InputAt(static_cast<int>(arity - 1))); 542 node->InputAt(static_cast<int>(arity - 1)));
543 } 543 }
544 node->ReplaceInput(0, function); 544 node->ReplaceInput(0, function);
545 NodeProperties::ChangeOp(
546 node,
547 javascript()->CallFunction(params.arity(), NO_CALL_FUNCTION_FLAGS, STRICT,
548 VectorSlotPair(), ALLOW_TAIL_CALLS));
545 return Changed(node); 549 return Changed(node);
546 } 550 }
547 551
548 552
549 Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a, 553 Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a,
550 Node* b) { 554 Node* b) {
551 node->set_op(op);
552 node->ReplaceInput(0, a); 555 node->ReplaceInput(0, a);
553 node->ReplaceInput(1, b); 556 node->ReplaceInput(1, b);
554 node->TrimInputCount(2); 557 node->TrimInputCount(2);
558 NodeProperties::ChangeOp(node, op);
555 RelaxControls(node); 559 RelaxControls(node);
556 return Changed(node); 560 return Changed(node);
557 } 561 }
558 562
559 563
560 Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a, 564 Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a,
561 Node* b, Node* c) { 565 Node* b, Node* c) {
562 node->set_op(op);
563 node->ReplaceInput(0, a); 566 node->ReplaceInput(0, a);
564 node->ReplaceInput(1, b); 567 node->ReplaceInput(1, b);
565 node->ReplaceInput(2, c); 568 node->ReplaceInput(2, c);
566 node->TrimInputCount(3); 569 node->TrimInputCount(3);
570 NodeProperties::ChangeOp(node, op);
567 RelaxControls(node); 571 RelaxControls(node);
568 return Changed(node); 572 return Changed(node);
569 } 573 }
570 574
571 575
572 Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a, 576 Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a,
573 Node* b, Node* c, Node* d) { 577 Node* b, Node* c, Node* d) {
574 node->set_op(op);
575 node->ReplaceInput(0, a); 578 node->ReplaceInput(0, a);
576 node->ReplaceInput(1, b); 579 node->ReplaceInput(1, b);
577 node->ReplaceInput(2, c); 580 node->ReplaceInput(2, c);
578 node->ReplaceInput(3, d); 581 node->ReplaceInput(3, d);
579 node->TrimInputCount(4); 582 node->TrimInputCount(4);
583 NodeProperties::ChangeOp(node, op);
580 RelaxControls(node); 584 RelaxControls(node);
581 return Changed(node); 585 return Changed(node);
582 } 586 }
583 587
584 588
585 Reduction JSIntrinsicLowering::ChangeToUndefined(Node* node, Node* effect) { 589 Reduction JSIntrinsicLowering::ChangeToUndefined(Node* node, Node* effect) {
586 ReplaceWithValue(node, jsgraph()->UndefinedConstant(), effect); 590 ReplaceWithValue(node, jsgraph()->UndefinedConstant(), effect);
587 return Changed(node); 591 return Changed(node);
588 } 592 }
589 593
(...skipping 10 matching lines...) Expand all
600 } 604 }
601 605
602 606
603 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { 607 MachineOperatorBuilder* JSIntrinsicLowering::machine() const {
604 return jsgraph()->machine(); 608 return jsgraph()->machine();
605 } 609 }
606 610
607 } // namespace compiler 611 } // namespace compiler
608 } // namespace internal 612 } // namespace internal
609 } // namespace v8 613 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-inlining.cc ('k') | src/compiler/js-typed-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698