OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/factory.h" | 7 #include "src/factory.h" |
8 #include "src/interpreter/bytecode-label.h" | 8 #include "src/interpreter/bytecode-label.h" |
9 #include "src/interpreter/bytecode-register-optimizer.h" | 9 #include "src/interpreter/bytecode-register-optimizer.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 BytecodeNode node(Bytecode::kNop); | 86 BytecodeNode node(Bytecode::kNop); |
87 node.source_info().Update({3, true}); | 87 node.source_info().Update({3, true}); |
88 optimizer()->Write(&node); | 88 optimizer()->Write(&node); |
89 CHECK_EQ(write_count(), 1); | 89 CHECK_EQ(write_count(), 1); |
90 CHECK_EQ(node, last_written()); | 90 CHECK_EQ(node, last_written()); |
91 } | 91 } |
92 | 92 |
93 TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForJump) { | 93 TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForJump) { |
94 Initialize(1, 1); | 94 Initialize(1, 1); |
95 Register temp = NewTemporary(); | 95 Register temp = NewTemporary(); |
96 BytecodeNode node(Bytecode::kStar, temp.ToOperand(), OperandScale::kSingle); | 96 BytecodeNode node(Bytecode::kStar, temp.ToOperand()); |
97 optimizer()->Write(&node); | 97 optimizer()->Write(&node); |
98 CHECK_EQ(write_count(), 0); | 98 CHECK_EQ(write_count(), 0); |
99 BytecodeLabel label; | 99 BytecodeLabel label; |
100 BytecodeNode jump(Bytecode::kJump, 0, OperandScale::kSingle); | 100 BytecodeNode jump(Bytecode::kJump, 0); |
101 optimizer()->WriteJump(&jump, &label); | 101 optimizer()->WriteJump(&jump, &label); |
102 CHECK_EQ(write_count(), 2); | 102 CHECK_EQ(write_count(), 2); |
103 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); | 103 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); |
104 CHECK_EQ(output()->at(0).operand(0), temp.ToOperand()); | 104 CHECK_EQ(output()->at(0).operand(0), temp.ToOperand()); |
105 CHECK_EQ(output()->at(0).operand_scale(), OperandScale::kSingle); | |
106 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kJump); | 105 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kJump); |
107 } | 106 } |
108 | 107 |
109 TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForBind) { | 108 TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForBind) { |
110 Initialize(1, 1); | 109 Initialize(1, 1); |
111 Register temp = NewTemporary(); | 110 Register temp = NewTemporary(); |
112 BytecodeNode node(Bytecode::kStar, temp.ToOperand(), OperandScale::kSingle); | 111 BytecodeNode node(Bytecode::kStar, temp.ToOperand()); |
113 optimizer()->Write(&node); | 112 optimizer()->Write(&node); |
114 CHECK_EQ(write_count(), 0); | 113 CHECK_EQ(write_count(), 0); |
115 BytecodeLabel label; | 114 BytecodeLabel label; |
116 optimizer()->BindLabel(&label); | 115 optimizer()->BindLabel(&label); |
117 CHECK_EQ(write_count(), 1); | 116 CHECK_EQ(write_count(), 1); |
118 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); | 117 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kStar); |
119 CHECK_EQ(output()->at(0).operand(0), temp.ToOperand()); | 118 CHECK_EQ(output()->at(0).operand(0), temp.ToOperand()); |
120 CHECK_EQ(output()->at(0).operand_scale(), OperandScale::kSingle); | |
121 } | 119 } |
122 | 120 |
123 // Basic Register Optimizations | 121 // Basic Register Optimizations |
124 | 122 |
125 TEST_F(BytecodeRegisterOptimizerTest, TemporaryNotEmitted) { | 123 TEST_F(BytecodeRegisterOptimizerTest, TemporaryNotEmitted) { |
126 Initialize(3, 1); | 124 Initialize(3, 1); |
127 Register parameter = Register::FromParameterIndex(1, 3); | 125 Register parameter = Register::FromParameterIndex(1, 3); |
128 BytecodeNode node0(Bytecode::kLdar, parameter.ToOperand(), | 126 BytecodeNode node0(Bytecode::kLdar, parameter.ToOperand()); |
129 OperandScale::kSingle); | |
130 optimizer()->Write(&node0); | 127 optimizer()->Write(&node0); |
131 CHECK_EQ(write_count(), 0); | 128 CHECK_EQ(write_count(), 0); |
132 Register temp = NewTemporary(); | 129 Register temp = NewTemporary(); |
133 BytecodeNode node1(Bytecode::kStar, NewTemporary().ToOperand(), | 130 BytecodeNode node1(Bytecode::kStar, NewTemporary().ToOperand()); |
134 OperandScale::kSingle); | |
135 optimizer()->Write(&node1); | 131 optimizer()->Write(&node1); |
136 CHECK_EQ(write_count(), 0); | 132 CHECK_EQ(write_count(), 0); |
137 KillTemporary(temp); | 133 KillTemporary(temp); |
138 CHECK_EQ(write_count(), 0); | 134 CHECK_EQ(write_count(), 0); |
139 BytecodeNode node2(Bytecode::kReturn); | 135 BytecodeNode node2(Bytecode::kReturn); |
140 optimizer()->Write(&node2); | 136 optimizer()->Write(&node2); |
141 CHECK_EQ(write_count(), 2); | 137 CHECK_EQ(write_count(), 2); |
142 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kLdar); | 138 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kLdar); |
143 CHECK_EQ(output()->at(0).operand(0), parameter.ToOperand()); | 139 CHECK_EQ(output()->at(0).operand(0), parameter.ToOperand()); |
144 CHECK_EQ(output()->at(0).operand_scale(), OperandScale::kSingle); | |
145 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kReturn); | 140 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kReturn); |
146 } | 141 } |
147 | 142 |
148 TEST_F(BytecodeRegisterOptimizerTest, StoresToLocalsImmediate) { | 143 TEST_F(BytecodeRegisterOptimizerTest, StoresToLocalsImmediate) { |
149 Initialize(3, 1); | 144 Initialize(3, 1); |
150 Register parameter = Register::FromParameterIndex(1, 3); | 145 Register parameter = Register::FromParameterIndex(1, 3); |
151 BytecodeNode node0(Bytecode::kLdar, parameter.ToOperand(), | 146 BytecodeNode node0(Bytecode::kLdar, parameter.ToOperand()); |
152 OperandScale::kSingle); | |
153 optimizer()->Write(&node0); | 147 optimizer()->Write(&node0); |
154 CHECK_EQ(write_count(), 0); | 148 CHECK_EQ(write_count(), 0); |
155 Register local = Register(0); | 149 Register local = Register(0); |
156 BytecodeNode node1(Bytecode::kStar, local.ToOperand(), OperandScale::kSingle); | 150 BytecodeNode node1(Bytecode::kStar, local.ToOperand()); |
157 optimizer()->Write(&node1); | 151 optimizer()->Write(&node1); |
158 CHECK_EQ(write_count(), 1); | 152 CHECK_EQ(write_count(), 1); |
159 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kMov); | 153 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kMov); |
160 CHECK_EQ(output()->at(0).operand(0), parameter.ToOperand()); | 154 CHECK_EQ(output()->at(0).operand(0), parameter.ToOperand()); |
161 CHECK_EQ(output()->at(0).operand(1), local.ToOperand()); | 155 CHECK_EQ(output()->at(0).operand(1), local.ToOperand()); |
162 CHECK_EQ(output()->at(0).operand_scale(), OperandScale::kSingle); | |
163 | 156 |
164 BytecodeNode node2(Bytecode::kReturn); | 157 BytecodeNode node2(Bytecode::kReturn); |
165 optimizer()->Write(&node2); | 158 optimizer()->Write(&node2); |
166 CHECK_EQ(write_count(), 3); | 159 CHECK_EQ(write_count(), 3); |
167 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kLdar); | 160 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kLdar); |
168 CHECK_EQ(output()->at(1).operand(0), local.ToOperand()); | 161 CHECK_EQ(output()->at(1).operand(0), local.ToOperand()); |
169 CHECK_EQ(output()->at(1).operand_scale(), OperandScale::kSingle); | |
170 CHECK_EQ(output()->at(2).bytecode(), Bytecode::kReturn); | 162 CHECK_EQ(output()->at(2).bytecode(), Bytecode::kReturn); |
171 } | 163 } |
172 | 164 |
173 TEST_F(BytecodeRegisterOptimizerTest, TemporaryNotMaterializedForInput) { | 165 TEST_F(BytecodeRegisterOptimizerTest, TemporaryNotMaterializedForInput) { |
174 Initialize(3, 1); | 166 Initialize(3, 1); |
175 Register parameter = Register::FromParameterIndex(1, 3); | 167 Register parameter = Register::FromParameterIndex(1, 3); |
176 Register temp0 = NewTemporary(); | 168 Register temp0 = NewTemporary(); |
177 Register temp1 = NewTemporary(); | 169 Register temp1 = NewTemporary(); |
178 BytecodeNode node0(Bytecode::kMov, parameter.ToOperand(), temp0.ToOperand(), | 170 BytecodeNode node0(Bytecode::kMov, parameter.ToOperand(), temp0.ToOperand()); |
179 OperandScale::kSingle); | |
180 optimizer()->Write(&node0); | 171 optimizer()->Write(&node0); |
181 BytecodeNode node1(Bytecode::kMov, parameter.ToOperand(), temp1.ToOperand(), | 172 BytecodeNode node1(Bytecode::kMov, parameter.ToOperand(), temp1.ToOperand()); |
182 OperandScale::kSingle); | |
183 optimizer()->Write(&node1); | 173 optimizer()->Write(&node1); |
184 CHECK_EQ(write_count(), 0); | 174 CHECK_EQ(write_count(), 0); |
185 BytecodeNode node2(Bytecode::kCallJSRuntime, 0, temp0.ToOperand(), 1, | 175 BytecodeNode node2(Bytecode::kCallJSRuntime, 0, temp0.ToOperand(), 1); |
186 OperandScale::kSingle); | |
187 optimizer()->Write(&node2); | 176 optimizer()->Write(&node2); |
188 CHECK_EQ(write_count(), 1); | 177 CHECK_EQ(write_count(), 1); |
189 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kCallJSRuntime); | 178 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kCallJSRuntime); |
190 CHECK_EQ(output()->at(0).operand(0), 0); | 179 CHECK_EQ(output()->at(0).operand(0), 0); |
191 CHECK_EQ(output()->at(0).operand(1), parameter.ToOperand()); | 180 CHECK_EQ(output()->at(0).operand(1), parameter.ToOperand()); |
192 CHECK_EQ(output()->at(0).operand(2), 1); | 181 CHECK_EQ(output()->at(0).operand(2), 1); |
193 CHECK_EQ(output()->at(0).operand_scale(), OperandScale::kSingle); | |
194 } | 182 } |
195 | 183 |
196 TEST_F(BytecodeRegisterOptimizerTest, RangeOfTemporariesMaterializedForInput) { | 184 TEST_F(BytecodeRegisterOptimizerTest, RangeOfTemporariesMaterializedForInput) { |
197 Initialize(3, 1); | 185 Initialize(3, 1); |
198 Register parameter = Register::FromParameterIndex(1, 3); | 186 Register parameter = Register::FromParameterIndex(1, 3); |
199 Register temp0 = NewTemporary(); | 187 Register temp0 = NewTemporary(); |
200 Register temp1 = NewTemporary(); | 188 Register temp1 = NewTemporary(); |
201 BytecodeNode node0(Bytecode::kLdaSmi, 3, OperandScale::kSingle); | 189 BytecodeNode node0(Bytecode::kLdaSmi, 3); |
202 optimizer()->Write(&node0); | 190 optimizer()->Write(&node0); |
203 CHECK_EQ(write_count(), 1); | 191 CHECK_EQ(write_count(), 1); |
204 BytecodeNode node1(Bytecode::kStar, temp0.ToOperand(), OperandScale::kSingle); | 192 BytecodeNode node1(Bytecode::kStar, temp0.ToOperand()); |
205 optimizer()->Write(&node1); | 193 optimizer()->Write(&node1); |
206 BytecodeNode node2(Bytecode::kMov, parameter.ToOperand(), temp1.ToOperand(), | 194 BytecodeNode node2(Bytecode::kMov, parameter.ToOperand(), temp1.ToOperand()); |
207 OperandScale::kSingle); | |
208 optimizer()->Write(&node2); | 195 optimizer()->Write(&node2); |
209 CHECK_EQ(write_count(), 1); | 196 CHECK_EQ(write_count(), 1); |
210 BytecodeNode node3(Bytecode::kCallJSRuntime, 0, temp0.ToOperand(), 2, | 197 BytecodeNode node3(Bytecode::kCallJSRuntime, 0, temp0.ToOperand(), 2); |
211 OperandScale::kSingle); | |
212 optimizer()->Write(&node3); | 198 optimizer()->Write(&node3); |
213 CHECK_EQ(write_count(), 4); | 199 CHECK_EQ(write_count(), 4); |
214 | 200 |
215 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kLdaSmi); | 201 CHECK_EQ(output()->at(0).bytecode(), Bytecode::kLdaSmi); |
216 CHECK_EQ(output()->at(0).operand(0), 3); | 202 CHECK_EQ(output()->at(0).operand(0), 3); |
217 CHECK_EQ(output()->at(0).operand_scale(), OperandScale::kSingle); | |
218 | 203 |
219 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kStar); | 204 CHECK_EQ(output()->at(1).bytecode(), Bytecode::kStar); |
220 CHECK_EQ(output()->at(1).operand(0), temp0.ToOperand()); | 205 CHECK_EQ(output()->at(1).operand(0), temp0.ToOperand()); |
221 CHECK_EQ(output()->at(1).operand_scale(), OperandScale::kSingle); | |
222 | 206 |
223 CHECK_EQ(output()->at(2).bytecode(), Bytecode::kMov); | 207 CHECK_EQ(output()->at(2).bytecode(), Bytecode::kMov); |
224 CHECK_EQ(output()->at(2).operand(0), parameter.ToOperand()); | 208 CHECK_EQ(output()->at(2).operand(0), parameter.ToOperand()); |
225 CHECK_EQ(output()->at(2).operand(1), temp1.ToOperand()); | 209 CHECK_EQ(output()->at(2).operand(1), temp1.ToOperand()); |
226 CHECK_EQ(output()->at(2).operand_scale(), OperandScale::kSingle); | |
227 | 210 |
228 CHECK_EQ(output()->at(3).bytecode(), Bytecode::kCallJSRuntime); | 211 CHECK_EQ(output()->at(3).bytecode(), Bytecode::kCallJSRuntime); |
229 CHECK_EQ(output()->at(3).operand(0), 0); | 212 CHECK_EQ(output()->at(3).operand(0), 0); |
230 CHECK_EQ(output()->at(3).operand(1), temp0.ToOperand()); | 213 CHECK_EQ(output()->at(3).operand(1), temp0.ToOperand()); |
231 CHECK_EQ(output()->at(3).operand(2), 2); | 214 CHECK_EQ(output()->at(3).operand(2), 2); |
232 CHECK_EQ(output()->at(3).operand_scale(), OperandScale::kSingle); | |
233 } | 215 } |
234 | 216 |
235 } // namespace interpreter | 217 } // namespace interpreter |
236 } // namespace internal | 218 } // namespace internal |
237 } // namespace v8 | 219 } // namespace v8 |
OLD | NEW |