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

Side by Side Diff: src/compiler/linkage.cc

Issue 1439613003: [turbofan] Better and more sane support for tail calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Skip test in ignition configuration Created 5 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/linkage.h ('k') | src/compiler/mips/code-generator-mips.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 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/code-stubs.h" 5 #include "src/code-stubs.h"
6 #include "src/compiler.h" 6 #include "src/compiler.h"
7 #include "src/compiler/common-operator.h" 7 #include "src/compiler/common-operator.h"
8 #include "src/compiler/frame.h" 8 #include "src/compiler/frame.h"
9 #include "src/compiler/linkage.h" 9 #include "src/compiler/linkage.h"
10 #include "src/compiler/node.h" 10 #include "src/compiler/node.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 bool CallDescriptor::HasSameReturnLocationsAs( 82 bool CallDescriptor::HasSameReturnLocationsAs(
83 const CallDescriptor* other) const { 83 const CallDescriptor* other) const {
84 if (ReturnCount() != other->ReturnCount()) return false; 84 if (ReturnCount() != other->ReturnCount()) return false;
85 for (size_t i = 0; i < ReturnCount(); ++i) { 85 for (size_t i = 0; i < ReturnCount(); ++i) {
86 if (GetReturnLocation(i) != other->GetReturnLocation(i)) return false; 86 if (GetReturnLocation(i) != other->GetReturnLocation(i)) return false;
87 } 87 }
88 return true; 88 return true;
89 } 89 }
90 90
91 91
92 bool CallDescriptor::CanTailCall(const Node* node) const { 92 bool CallDescriptor::CanTailCall(const Node* node,
93 // Determine the number of stack parameters passed in 93 int* stack_param_delta) const {
94 size_t stack_params = 0; 94 // TODO(danno): TF only current supports tail calls where the number of stack
95 for (size_t i = 0; i < InputCount(); ++i) { 95 // parameters of the callee is the same or fewer of the caller.
96 if (!GetInputLocation(i).IsRegister()) {
97 ++stack_params;
98 }
99 }
100 // Ensure the input linkage contains the stack parameters in the right order
101 size_t current_stack_param = 0;
102 for (size_t i = 0; i < InputCount(); ++i) {
103 if (!GetInputLocation(i).IsRegister()) {
104 if (GetInputLocation(i) != LinkageLocation::ForCallerFrameSlot(
105 static_cast<int>(current_stack_param) -
106 static_cast<int>(stack_params))) {
107 return false;
108 }
109 ++current_stack_param;
110 }
111 }
112 // Tail calling is currently allowed if return locations match and all
113 // parameters are either in registers or on the stack but match exactly in
114 // number and content.
115 CallDescriptor const* other = OpParameter<CallDescriptor const*>(node); 96 CallDescriptor const* other = OpParameter<CallDescriptor const*>(node);
116 if (!HasSameReturnLocationsAs(other)) return false; 97 if (!HasSameReturnLocationsAs(other)) return false;
117 size_t current_input = 0; 98 size_t current_input = 0;
118 size_t other_input = 0; 99 size_t other_input = 0;
119 while (true) { 100 *stack_param_delta = 0;
120 if (other_input >= other->InputCount()) { 101 bool more_other = true;
121 while (current_input < InputCount()) { 102 bool more_this = true;
122 if (!GetInputLocation(current_input).IsRegister()) { 103 while (more_other || more_this) {
123 return false; 104 if (other_input < other->InputCount()) {
124 } 105 if (!other->GetInputLocation(other_input).IsRegister()) {
125 ++current_input; 106 (*stack_param_delta)++;
126 } 107 }
127 return true; 108 } else {
109 more_other = false;
128 } 110 }
129 if (current_input >= InputCount()) { 111 if (current_input < InputCount()) {
130 while (other_input < other->InputCount()) { 112 if (!GetInputLocation(current_input).IsRegister()) {
131 if (!other->GetInputLocation(other_input).IsRegister()) { 113 (*stack_param_delta)--;
132 return false;
133 }
134 ++other_input;
135 } 114 }
136 return true; 115 } else {
137 } 116 more_this = false;
138 if (GetInputLocation(current_input).IsRegister()) {
139 ++current_input;
140 continue;
141 }
142 if (other->GetInputLocation(other_input).IsRegister()) {
143 ++other_input;
144 continue;
145 }
146 if (GetInputLocation(current_input) !=
147 other->GetInputLocation(other_input)) {
148 return false;
149 }
150 Node* input = node->InputAt(static_cast<int>(other_input));
151 if (input->opcode() != IrOpcode::kParameter) {
152 return false;
153 }
154 // Make sure that the parameter input passed through to the tail call
155 // corresponds to the correct stack slot.
156 size_t param_index = ParameterIndexOf(input->op());
157 if (param_index != current_input - 1) {
158 return false;
159 } 117 }
160 ++current_input; 118 ++current_input;
161 ++other_input; 119 ++other_input;
162 } 120 }
163 UNREACHABLE(); 121 return *stack_param_delta <= 0;
164 return false;
165 } 122 }
166 123
167 124
168 CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) { 125 CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) {
169 if (info->code_stub() != NULL) { 126 if (info->code_stub() != NULL) {
170 // Use the code stub interface descriptor. 127 // Use the code stub interface descriptor.
171 CodeStub* stub = info->code_stub(); 128 CodeStub* stub = info->code_stub();
172 CallInterfaceDescriptor descriptor = stub->GetCallInterfaceDescriptor(); 129 CallInterfaceDescriptor descriptor = stub->GetCallInterfaceDescriptor();
173 return GetStubCallDescriptor( 130 return GetStubCallDescriptor(
174 info->isolate(), zone, descriptor, stub->GetStackParameterCount(), 131 info->isolate(), zone, descriptor, stub->GetStackParameterCount(),
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 case Runtime::kInlineToLength: 208 case Runtime::kInlineToLength:
252 case Runtime::kInlineToName: 209 case Runtime::kInlineToName:
253 case Runtime::kInlineToNumber: 210 case Runtime::kInlineToNumber:
254 case Runtime::kInlineToObject: 211 case Runtime::kInlineToObject:
255 case Runtime::kInlineToPrimitive_Number: 212 case Runtime::kInlineToPrimitive_Number:
256 case Runtime::kInlineToPrimitive_String: 213 case Runtime::kInlineToPrimitive_String:
257 case Runtime::kInlineToPrimitive: 214 case Runtime::kInlineToPrimitive:
258 case Runtime::kInlineToString: 215 case Runtime::kInlineToString:
259 return 1; 216 return 1;
260 case Runtime::kInlineCall: 217 case Runtime::kInlineCall:
218 case Runtime::kInlineTailCall:
261 case Runtime::kInlineDeoptimizeNow: 219 case Runtime::kInlineDeoptimizeNow:
262 case Runtime::kInlineThrowNotDateError: 220 case Runtime::kInlineThrowNotDateError:
263 return 2; 221 return 2;
264 default: 222 default:
265 break; 223 break;
266 } 224 }
267 225
268 // Most inlined runtime functions (except the ones listed above) can be called 226 // Most inlined runtime functions (except the ones listed above) can be called
269 // without a FrameState or will be lowered by JSIntrinsicLowering internally. 227 // without a FrameState or will be lowered by JSIntrinsicLowering internally.
270 const Runtime::Function* const f = Runtime::FunctionForId(function); 228 const Runtime::Function* const f = Runtime::FunctionForId(function);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 return LinkageLocation::ForCalleeFrameSlot(spill_index); 520 return LinkageLocation::ForCalleeFrameSlot(spill_index);
563 } else { 521 } else {
564 // Parameter. Use the assigned location from the incoming call descriptor. 522 // Parameter. Use the assigned location from the incoming call descriptor.
565 int parameter_index = 1 + index; // skip index 0, which is the target. 523 int parameter_index = 1 + index; // skip index 0, which is the target.
566 return incoming_->GetInputLocation(parameter_index); 524 return incoming_->GetInputLocation(parameter_index);
567 } 525 }
568 } 526 }
569 } // namespace compiler 527 } // namespace compiler
570 } // namespace internal 528 } // namespace internal
571 } // namespace v8 529 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/linkage.h ('k') | src/compiler/mips/code-generator-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698