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

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

Issue 1245523002: [turbofan]: Fix tail calls edge cases and add tests (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@1220823004
Patch Set: Fix ASAN again Created 5 years, 5 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 | « no previous file | test/unittests/compiler/linkage-tail-call-unittest.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/linkage.h" 8 #include "src/compiler/linkage.h"
9 #include "src/compiler/node.h" 9 #include "src/compiler/node.h"
10 #include "src/compiler/pipeline.h" 10 #include "src/compiler/pipeline.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 const CallDescriptor* other) const { 46 const CallDescriptor* other) const {
47 if (ReturnCount() != other->ReturnCount()) return false; 47 if (ReturnCount() != other->ReturnCount()) return false;
48 for (size_t i = 0; i < ReturnCount(); ++i) { 48 for (size_t i = 0; i < ReturnCount(); ++i) {
49 if (GetReturnLocation(i) != other->GetReturnLocation(i)) return false; 49 if (GetReturnLocation(i) != other->GetReturnLocation(i)) return false;
50 } 50 }
51 return true; 51 return true;
52 } 52 }
53 53
54 54
55 bool CallDescriptor::CanTailCall(const Node* node) const { 55 bool CallDescriptor::CanTailCall(const Node* node) const {
56 // Determine the number of stack parameters passed in
57 size_t stack_params = 0;
58 for (size_t i = 0; i < InputCount(); ++i) {
59 if (!GetInputLocation(i).is_register()) {
60 ++stack_params;
61 }
62 }
63 // Ensure the input linkage contains the stack parameters in the right order
64 size_t current_stack_param = 0;
65 for (size_t i = 0; i < InputCount(); ++i) {
66 if (!GetInputLocation(i).is_register()) {
67 if (GetInputLocation(i) !=
68 LinkageLocation(static_cast<int>(current_stack_param) -
69 static_cast<int>(stack_params))) {
70 return false;
71 }
72 ++current_stack_param;
73 }
74 }
56 // Tail calling is currently allowed if return locations match and all 75 // Tail calling is currently allowed if return locations match and all
57 // parameters are either in registers or on the stack but match exactly in 76 // parameters are either in registers or on the stack but match exactly in
58 // number and content. 77 // number and content.
59 CallDescriptor const* other = OpParameter<CallDescriptor const*>(node); 78 CallDescriptor const* other = OpParameter<CallDescriptor const*>(node);
60 if (!HasSameReturnLocationsAs(other)) return false; 79 if (!HasSameReturnLocationsAs(other)) return false;
61 size_t current_input = 0; 80 size_t current_input = 0;
62 size_t other_input = 0; 81 size_t other_input = 0;
63 size_t stack_parameter = 0;
64 while (true) { 82 while (true) {
65 if (other_input >= other->InputCount()) { 83 if (other_input >= other->InputCount()) {
66 while (current_input <= InputCount()) { 84 while (current_input < InputCount()) {
67 if (!GetInputLocation(current_input).is_register()) { 85 if (!GetInputLocation(current_input).is_register()) {
68 return false; 86 return false;
69 } 87 }
70 ++current_input; 88 ++current_input;
71 } 89 }
72 return true; 90 return true;
73 } 91 }
74 if (current_input >= InputCount()) { 92 if (current_input >= InputCount()) {
75 while (other_input < other->InputCount()) { 93 while (other_input < other->InputCount()) {
76 if (!other->GetInputLocation(other_input).is_register()) { 94 if (!other->GetInputLocation(other_input).is_register()) {
(...skipping 12 matching lines...) Expand all
89 continue; 107 continue;
90 } 108 }
91 if (GetInputLocation(current_input) != 109 if (GetInputLocation(current_input) !=
92 other->GetInputLocation(other_input)) { 110 other->GetInputLocation(other_input)) {
93 return false; 111 return false;
94 } 112 }
95 Node* input = node->InputAt(static_cast<int>(other_input)); 113 Node* input = node->InputAt(static_cast<int>(other_input));
96 if (input->opcode() != IrOpcode::kParameter) { 114 if (input->opcode() != IrOpcode::kParameter) {
97 return false; 115 return false;
98 } 116 }
117 // Make sure that the parameter input passed through to the tail call
118 // corresponds to the correct stack slot.
99 size_t param_index = ParameterIndexOf(input->op()); 119 size_t param_index = ParameterIndexOf(input->op());
100 if (param_index != stack_parameter) { 120 if (param_index != current_input - 1) {
101 return false; 121 return false;
102 } 122 }
103 ++stack_parameter;
104 ++current_input; 123 ++current_input;
105 ++other_input; 124 ++other_input;
106 } 125 }
107 UNREACHABLE(); 126 UNREACHABLE();
108 return false; 127 return false;
109 } 128 }
110 129
111 130
112 CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) { 131 CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) {
113 if (info->code_stub() != NULL) { 132 if (info->code_stub() != NULL) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 282
264 CallDescriptor* Linkage::GetSimplifiedCDescriptor(Zone* zone, 283 CallDescriptor* Linkage::GetSimplifiedCDescriptor(Zone* zone,
265 const MachineSignature* sig) { 284 const MachineSignature* sig) {
266 UNIMPLEMENTED(); 285 UNIMPLEMENTED();
267 return NULL; 286 return NULL;
268 } 287 }
269 #endif // !V8_TURBOFAN_BACKEND 288 #endif // !V8_TURBOFAN_BACKEND
270 } // namespace compiler 289 } // namespace compiler
271 } // namespace internal 290 } // namespace internal
272 } // namespace v8 291 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/unittests/compiler/linkage-tail-call-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698