OLD | NEW |
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/linkage.h" | 5 #include "src/compiler/linkage.h" |
6 #include "src/compiler/tail-call-optimization.h" | 6 #include "src/compiler/tail-call-optimization.h" |
7 #include "test/unittests/compiler/graph-unittest.h" | 7 #include "test/unittests/compiler/graph-unittest.h" |
8 #include "test/unittests/compiler/node-test-utils.h" | 8 #include "test/unittests/compiler/node-test-utils.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 | 27 |
28 TEST_F(TailCallOptimizationTest, CallCodeObject0) { | 28 TEST_F(TailCallOptimizationTest, CallCodeObject0) { |
29 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; | 29 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; |
30 LinkageLocation kLocationSignature[] = {LinkageLocation(0), | 30 LinkageLocation kLocationSignature[] = {LinkageLocation(0), |
31 LinkageLocation(1)}; | 31 LinkageLocation(1)}; |
32 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( | 32 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( |
33 CallDescriptor::kCallCodeObject, kMachAnyTagged, LinkageLocation(0), | 33 CallDescriptor::kCallCodeObject, kMachAnyTagged, LinkageLocation(0), |
34 new (zone()) MachineSignature(1, 1, kMachineSignature), | 34 new (zone()) MachineSignature(1, 1, kMachineSignature), |
35 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, | 35 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, |
36 Operator::kNoProperties, 0, CallDescriptor::kNoFlags); | 36 Operator::kNoProperties, 0, 0, CallDescriptor::kNoFlags); |
37 Node* p0 = Parameter(0); | 37 Node* p0 = Parameter(0); |
38 Node* p1 = Parameter(1); | 38 Node* p1 = Parameter(1); |
39 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, | 39 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, |
40 graph()->start(), graph()->start()); | 40 graph()->start(), graph()->start()); |
41 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); | 41 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); |
42 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); | 42 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); |
43 Reduction r = Reduce(ret); | 43 Reduction r = Reduce(ret); |
44 ASSERT_FALSE(r.Changed()); | 44 ASSERT_FALSE(r.Changed()); |
45 } | 45 } |
46 | 46 |
47 | 47 |
48 TEST_F(TailCallOptimizationTest, CallCodeObject1) { | 48 TEST_F(TailCallOptimizationTest, CallCodeObject1) { |
49 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; | 49 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; |
50 LinkageLocation kLocationSignature[] = {LinkageLocation(0), | 50 LinkageLocation kLocationSignature[] = {LinkageLocation(0), |
51 LinkageLocation(1)}; | 51 LinkageLocation(1)}; |
52 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( | 52 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( |
53 CallDescriptor::kCallCodeObject, kMachAnyTagged, LinkageLocation(0), | 53 CallDescriptor::kCallCodeObject, kMachAnyTagged, LinkageLocation(0), |
54 new (zone()) MachineSignature(1, 1, kMachineSignature), | 54 new (zone()) MachineSignature(1, 1, kMachineSignature), |
55 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, | 55 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, |
56 Operator::kNoProperties, 0, CallDescriptor::kSupportsTailCalls); | 56 Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls); |
57 Node* p0 = Parameter(0); | 57 Node* p0 = Parameter(0); |
58 Node* p1 = Parameter(1); | 58 Node* p1 = Parameter(1); |
59 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, | 59 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, |
60 graph()->start(), graph()->start()); | 60 graph()->start(), graph()->start()); |
61 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); | 61 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); |
62 Node* if_exception = graph()->NewNode( | 62 Node* if_exception = graph()->NewNode( |
63 common()->IfException(IfExceptionHint::kLocallyUncaught), call, call); | 63 common()->IfException(IfExceptionHint::kLocallyUncaught), call, call); |
64 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); | 64 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); |
65 Node* end = graph()->NewNode(common()->End(1), if_exception); | 65 Node* end = graph()->NewNode(common()->End(1), if_exception); |
66 graph()->SetEnd(end); | 66 graph()->SetEnd(end); |
67 Reduction r = Reduce(ret); | 67 Reduction r = Reduce(ret); |
68 ASSERT_FALSE(r.Changed()); | 68 ASSERT_FALSE(r.Changed()); |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 TEST_F(TailCallOptimizationTest, CallCodeObject2) { | 72 TEST_F(TailCallOptimizationTest, CallCodeObject2) { |
73 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; | 73 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; |
74 LinkageLocation kLocationSignature[] = {LinkageLocation(0), | 74 LinkageLocation kLocationSignature[] = {LinkageLocation(0), |
75 LinkageLocation(1)}; | 75 LinkageLocation(1)}; |
76 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( | 76 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( |
77 CallDescriptor::kCallCodeObject, kMachAnyTagged, LinkageLocation(0), | 77 CallDescriptor::kCallCodeObject, kMachAnyTagged, LinkageLocation(0), |
78 new (zone()) MachineSignature(1, 1, kMachineSignature), | 78 new (zone()) MachineSignature(1, 1, kMachineSignature), |
79 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, | 79 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, |
80 Operator::kNoProperties, 0, CallDescriptor::kSupportsTailCalls); | 80 Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls); |
81 Node* p0 = Parameter(0); | 81 Node* p0 = Parameter(0); |
82 Node* p1 = Parameter(1); | 82 Node* p1 = Parameter(1); |
83 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, | 83 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, |
84 graph()->start(), graph()->start()); | 84 graph()->start(), graph()->start()); |
85 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); | 85 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); |
86 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); | 86 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); |
87 Reduction r = Reduce(ret); | 87 Reduction r = Reduce(ret); |
88 ASSERT_TRUE(r.Changed()); | 88 ASSERT_TRUE(r.Changed()); |
89 EXPECT_THAT(r.replacement(), IsTailCall(kCallDescriptor, p0, p1, | 89 EXPECT_THAT(r.replacement(), IsTailCall(kCallDescriptor, p0, p1, |
90 graph()->start(), graph()->start())); | 90 graph()->start(), graph()->start())); |
91 } | 91 } |
92 | 92 |
93 | 93 |
94 TEST_F(TailCallOptimizationTest, CallJSFunction0) { | 94 TEST_F(TailCallOptimizationTest, CallJSFunction0) { |
95 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; | 95 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; |
96 LinkageLocation kLocationSignature[] = {LinkageLocation(0), | 96 LinkageLocation kLocationSignature[] = {LinkageLocation(0), |
97 LinkageLocation(1)}; | 97 LinkageLocation(1)}; |
98 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( | 98 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( |
99 CallDescriptor::kCallJSFunction, kMachAnyTagged, LinkageLocation(0), | 99 CallDescriptor::kCallJSFunction, kMachAnyTagged, LinkageLocation(0), |
100 new (zone()) MachineSignature(1, 1, kMachineSignature), | 100 new (zone()) MachineSignature(1, 1, kMachineSignature), |
101 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, | 101 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, |
102 Operator::kNoProperties, 0, CallDescriptor::kNoFlags); | 102 Operator::kNoProperties, 0, 0, CallDescriptor::kNoFlags); |
103 Node* p0 = Parameter(0); | 103 Node* p0 = Parameter(0); |
104 Node* p1 = Parameter(1); | 104 Node* p1 = Parameter(1); |
105 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, | 105 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, |
106 graph()->start(), graph()->start()); | 106 graph()->start(), graph()->start()); |
107 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); | 107 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); |
108 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); | 108 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); |
109 Reduction r = Reduce(ret); | 109 Reduction r = Reduce(ret); |
110 ASSERT_FALSE(r.Changed()); | 110 ASSERT_FALSE(r.Changed()); |
111 } | 111 } |
112 | 112 |
113 | 113 |
114 TEST_F(TailCallOptimizationTest, CallJSFunction1) { | 114 TEST_F(TailCallOptimizationTest, CallJSFunction1) { |
115 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; | 115 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; |
116 LinkageLocation kLocationSignature[] = {LinkageLocation(0), | 116 LinkageLocation kLocationSignature[] = {LinkageLocation(0), |
117 LinkageLocation(1)}; | 117 LinkageLocation(1)}; |
118 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( | 118 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( |
119 CallDescriptor::kCallJSFunction, kMachAnyTagged, LinkageLocation(0), | 119 CallDescriptor::kCallJSFunction, kMachAnyTagged, LinkageLocation(0), |
120 new (zone()) MachineSignature(1, 1, kMachineSignature), | 120 new (zone()) MachineSignature(1, 1, kMachineSignature), |
121 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, | 121 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, |
122 Operator::kNoProperties, 0, CallDescriptor::kSupportsTailCalls); | 122 Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls); |
123 Node* p0 = Parameter(0); | 123 Node* p0 = Parameter(0); |
124 Node* p1 = Parameter(1); | 124 Node* p1 = Parameter(1); |
125 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, | 125 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, |
126 graph()->start(), graph()->start()); | 126 graph()->start(), graph()->start()); |
127 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); | 127 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); |
128 Node* if_exception = graph()->NewNode( | 128 Node* if_exception = graph()->NewNode( |
129 common()->IfException(IfExceptionHint::kLocallyUncaught), call, call); | 129 common()->IfException(IfExceptionHint::kLocallyUncaught), call, call); |
130 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); | 130 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); |
131 Node* end = graph()->NewNode(common()->End(1), if_exception); | 131 Node* end = graph()->NewNode(common()->End(1), if_exception); |
132 graph()->SetEnd(end); | 132 graph()->SetEnd(end); |
133 Reduction r = Reduce(ret); | 133 Reduction r = Reduce(ret); |
134 ASSERT_FALSE(r.Changed()); | 134 ASSERT_FALSE(r.Changed()); |
135 } | 135 } |
136 | 136 |
137 | 137 |
138 TEST_F(TailCallOptimizationTest, CallJSFunction2) { | 138 TEST_F(TailCallOptimizationTest, CallJSFunction2) { |
139 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; | 139 MachineType kMachineSignature[] = {kMachAnyTagged, kMachAnyTagged}; |
140 LinkageLocation kLocationSignature[] = {LinkageLocation(0), | 140 LinkageLocation kLocationSignature[] = {LinkageLocation(0), |
141 LinkageLocation(1)}; | 141 LinkageLocation(1)}; |
142 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( | 142 const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor( |
143 CallDescriptor::kCallJSFunction, kMachAnyTagged, LinkageLocation(0), | 143 CallDescriptor::kCallJSFunction, kMachAnyTagged, LinkageLocation(0), |
144 new (zone()) MachineSignature(1, 1, kMachineSignature), | 144 new (zone()) MachineSignature(1, 1, kMachineSignature), |
145 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, | 145 new (zone()) LocationSignature(1, 1, kLocationSignature), 0, |
146 Operator::kNoProperties, 0, CallDescriptor::kSupportsTailCalls); | 146 Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls); |
147 Node* p0 = Parameter(0); | 147 Node* p0 = Parameter(0); |
148 Node* p1 = Parameter(1); | 148 Node* p1 = Parameter(1); |
149 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, | 149 Node* call = graph()->NewNode(common()->Call(kCallDescriptor), p0, p1, |
150 graph()->start(), graph()->start()); | 150 graph()->start(), graph()->start()); |
151 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); | 151 Node* if_success = graph()->NewNode(common()->IfSuccess(), call); |
152 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); | 152 Node* ret = graph()->NewNode(common()->Return(), call, call, if_success); |
153 Reduction r = Reduce(ret); | 153 Reduction r = Reduce(ret); |
154 ASSERT_TRUE(r.Changed()); | 154 ASSERT_TRUE(r.Changed()); |
155 EXPECT_THAT(r.replacement(), IsTailCall(kCallDescriptor, p0, p1, | 155 EXPECT_THAT(r.replacement(), IsTailCall(kCallDescriptor, p0, p1, |
156 graph()->start(), graph()->start())); | 156 graph()->start(), graph()->start())); |
157 } | 157 } |
158 | 158 |
159 | 159 |
160 } // namespace compiler | 160 } // namespace compiler |
161 } // namespace internal | 161 } // namespace internal |
162 } // namespace v8 | 162 } // namespace v8 |
OLD | NEW |