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

Side by Side Diff: src/compiler/tail-call-optimization.cc

Issue 2446543002: [turbofan] Support variable size argument popping in TF-generated functions (Closed)
Patch Set: Fix tests and arm64 Created 4 years, 1 month 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/simplified-lowering.cc ('k') | src/compiler/wasm-compiler.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/tail-call-optimization.h" 5 #include "src/compiler/tail-call-optimization.h"
6 6
7 #include "src/compiler/common-operator.h" 7 #include "src/compiler/common-operator.h"
8 #include "src/compiler/graph.h" 8 #include "src/compiler/graph.h"
9 #include "src/compiler/linkage.h" 9 #include "src/compiler/linkage.h"
10 #include "src/compiler/node-matchers.h"
10 #include "src/compiler/node-properties.h" 11 #include "src/compiler/node-properties.h"
11 12
12 namespace v8 { 13 namespace v8 {
13 namespace internal { 14 namespace internal {
14 namespace compiler { 15 namespace compiler {
15 16
16 Reduction TailCallOptimization::Reduce(Node* node) { 17 Reduction TailCallOptimization::Reduce(Node* node) {
17 if (node->opcode() != IrOpcode::kReturn) return NoChange(); 18 if (node->opcode() != IrOpcode::kReturn) return NoChange();
18 // The value which is returned must be the result of a potential tail call, 19 // The value which is returned must be the result of a potential tail call,
19 // there must be no try/catch/finally around the Call, and there must be no 20 // there must be no try/catch/finally around the Call, and there must be no
20 // other effect between the Call and the Return nodes. 21 // other effect between the Call and the Return nodes.
21 Node* const call = NodeProperties::GetValueInput(node, 0); 22 Node* const call = NodeProperties::GetValueInput(node, 1);
22 if (call->opcode() == IrOpcode::kCall && 23 if (call->opcode() == IrOpcode::kCall &&
23 CallDescriptorOf(call->op())->SupportsTailCalls() && 24 CallDescriptorOf(call->op())->SupportsTailCalls() &&
24 NodeProperties::GetEffectInput(node) == call && 25 NodeProperties::GetEffectInput(node) == call &&
25 !NodeProperties::IsExceptionalCall(call)) { 26 !NodeProperties::IsExceptionalCall(call)) {
26 Node* const control = NodeProperties::GetControlInput(node); 27 Node* const control = NodeProperties::GetControlInput(node);
28 // Ensure that no additional arguments are being popped other than those in
29 // the CallDescriptor, otherwise the tail call transformation is invalid.
30 DCHECK_EQ(0, Int32Matcher(NodeProperties::GetValueInput(node, 0)).Value());
27 if (control->opcode() == IrOpcode::kIfSuccess && 31 if (control->opcode() == IrOpcode::kIfSuccess &&
28 call->OwnedBy(node, control) && control->OwnedBy(node)) { 32 call->OwnedBy(node, control) && control->OwnedBy(node)) {
29 // Furthermore, control has to flow via an IfSuccess from the Call, so 33 // Furthermore, control has to flow via an IfSuccess from the Call, so
30 // the Return node value and effect depends directly on the Call node, 34 // the Return node value and effect depends directly on the Call node,
31 // and indirectly control depends on the Call via an IfSuccess. 35 // and indirectly control depends on the Call via an IfSuccess.
32 36
33 // Value1 ... ValueN Effect Control 37 // Value1 ... ValueN Effect Control
34 // ^ ^ ^ ^ 38 // ^ ^ ^ ^
35 // | | | | 39 // | | | |
36 // | +--+ +-+ | 40 // | +--+ +-+ |
(...skipping 18 matching lines...) Expand all
55 // ^ ^ ^ ^ 59 // ^ ^ ^ ^
56 // | | | | 60 // | | | |
57 // | +--+ +-+ | 61 // | +--+ +-+ |
58 // +----------+ | | +------+ 62 // +----------+ | | +------+
59 // \ | | / 63 // \ | | /
60 // TailCall[Descriptor] 64 // TailCall[Descriptor]
61 // ^ 65 // ^
62 // | 66 // |
63 67
64 DCHECK_EQ(call, NodeProperties::GetControlInput(control, 0)); 68 DCHECK_EQ(call, NodeProperties::GetControlInput(control, 0));
65 DCHECK_EQ(3, node->InputCount()); 69 DCHECK_EQ(4, node->InputCount());
66 node->ReplaceInput(0, NodeProperties::GetEffectInput(call)); 70 node->ReplaceInput(0, NodeProperties::GetEffectInput(call));
67 node->ReplaceInput(1, NodeProperties::GetControlInput(call)); 71 node->ReplaceInput(1, NodeProperties::GetControlInput(call));
72 node->RemoveInput(3);
68 node->RemoveInput(2); 73 node->RemoveInput(2);
69 for (int index = 0; index < call->op()->ValueInputCount(); ++index) { 74 for (int index = 0; index < call->op()->ValueInputCount(); ++index) {
70 node->InsertInput(graph()->zone(), index, 75 node->InsertInput(graph()->zone(), index,
71 NodeProperties::GetValueInput(call, index)); 76 NodeProperties::GetValueInput(call, index));
72 } 77 }
73 NodeProperties::ChangeOp( 78 NodeProperties::ChangeOp(
74 node, common()->TailCall(CallDescriptorOf(call->op()))); 79 node, common()->TailCall(CallDescriptorOf(call->op())));
75 return Changed(node); 80 return Changed(node);
76 } 81 }
77 } 82 }
78 return NoChange(); 83 return NoChange();
79 } 84 }
80 85
81 } // namespace compiler 86 } // namespace compiler
82 } // namespace internal 87 } // namespace internal
83 } // namespace v8 88 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/simplified-lowering.cc ('k') | src/compiler/wasm-compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698