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

Side by Side Diff: src/interpreter/bytecode-pipeline.h

Issue 2542903003: [Interpreter] Templatize AccumulatorUsage and OperandType for bytecode creation. (Closed)
Patch Set: Rebase Created 4 years 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
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 #ifndef V8_INTERPRETER_BYTECODE_PIPELINE_H_ 5 #ifndef V8_INTERPRETER_BYTECODE_PIPELINE_H_
6 #define V8_INTERPRETER_BYTECODE_PIPELINE_H_ 6 #define V8_INTERPRETER_BYTECODE_PIPELINE_H_
7 7
8 #include "src/base/compiler-specific.h" 8 #include "src/base/compiler-specific.h"
9 #include "src/globals.h" 9 #include "src/globals.h"
10 #include "src/interpreter/bytecode-register-allocator.h" 10 #include "src/interpreter/bytecode-register-allocator.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 operand_count_(4), 184 operand_count_(4),
185 operand_scale_(OperandScale::kSingle), 185 operand_scale_(OperandScale::kSingle),
186 source_info_(source_info) { 186 source_info_(source_info) {
187 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); 187 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
188 SetOperand(0, operand0); 188 SetOperand(0, operand0);
189 SetOperand(1, operand1); 189 SetOperand(1, operand1);
190 SetOperand(2, operand2); 190 SetOperand(2, operand2);
191 SetOperand(3, operand3); 191 SetOperand(3, operand3);
192 } 192 }
193 193
194 template <Bytecode bytecode>
195 INLINE(static BytecodeNode Create(
196 BytecodeSourceInfo source_info = BytecodeSourceInfo())) {
197 return BytecodeNode(bytecode, 0, OperandScale::kSingle, source_info);
198 }
199
200 template <Bytecode bytecode, OperandType operand0_type>
201 INLINE(static BytecodeNode Create(
202 uint32_t operand0,
203 BytecodeSourceInfo source_info = BytecodeSourceInfo())) {
204 OperandScale scale = OperandScale::kSingle;
205 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
206 return BytecodeNode(bytecode, 1, scale, source_info, operand0);
207 }
208
209 template <Bytecode bytecode, OperandType operand0_type,
210 OperandType operand1_type>
211 INLINE(static BytecodeNode Create(
212 uint32_t operand0, uint32_t operand1,
213 BytecodeSourceInfo source_info = BytecodeSourceInfo())) {
214 OperandScale scale = OperandScale::kSingle;
215 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
216 scale = std::max(scale, ScaleForOperand<operand1_type>(operand1));
217 return BytecodeNode(bytecode, 2, scale, source_info, operand0, operand1);
218 }
219
220 template <Bytecode bytecode, OperandType operand0_type,
221 OperandType operand1_type, OperandType operand2_type>
222 INLINE(static BytecodeNode Create(
223 uint32_t operand0, uint32_t operand1, uint32_t operand2,
224 BytecodeSourceInfo source_info = BytecodeSourceInfo())) {
225 OperandScale scale = OperandScale::kSingle;
226 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
227 scale = std::max(scale, ScaleForOperand<operand1_type>(operand1));
228 scale = std::max(scale, ScaleForOperand<operand2_type>(operand2));
229 return BytecodeNode(bytecode, 3, scale, source_info, operand0, operand1,
230 operand2);
231 }
232
233 template <Bytecode bytecode, OperandType operand0_type,
234 OperandType operand1_type, OperandType operand2_type,
235 OperandType operand3_type>
236 INLINE(static BytecodeNode Create(
237 uint32_t operand0, uint32_t operand1, uint32_t operand2,
238 uint32_t operand3,
239 BytecodeSourceInfo source_info = BytecodeSourceInfo())) {
240 OperandScale scale = OperandScale::kSingle;
241 scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
242 scale = std::max(scale, ScaleForOperand<operand1_type>(operand1));
243 scale = std::max(scale, ScaleForOperand<operand2_type>(operand2));
244 scale = std::max(scale, ScaleForOperand<operand3_type>(operand3));
245 return BytecodeNode(bytecode, 4, scale, source_info, operand0, operand1,
246 operand2, operand3);
247 }
248
194 // Replace the bytecode of this node with |bytecode| and keep the operands. 249 // Replace the bytecode of this node with |bytecode| and keep the operands.
195 void replace_bytecode(Bytecode bytecode) { 250 void replace_bytecode(Bytecode bytecode) {
196 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode_), 251 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode_),
197 Bytecodes::NumberOfOperands(bytecode)); 252 Bytecodes::NumberOfOperands(bytecode));
198 bytecode_ = bytecode; 253 bytecode_ = bytecode;
199 } 254 }
200 255
201 void set_bytecode(Bytecode bytecode) { 256 void update_operand0(uint32_t operand0) { SetOperand(0, operand0); }
202 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0);
203 bytecode_ = bytecode;
204 operand_count_ = 0;
205 operand_scale_ = OperandScale::kSingle;
206 }
207
208 void set_bytecode(Bytecode bytecode, uint32_t operand0) {
209 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1);
210 bytecode_ = bytecode;
211 operand_count_ = 1;
212 operand_scale_ = OperandScale::kSingle;
213 SetOperand(0, operand0);
214 }
215
216 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1) {
217 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2);
218 bytecode_ = bytecode;
219 operand_count_ = 2;
220 operand_scale_ = OperandScale::kSingle;
221 SetOperand(0, operand0);
222 SetOperand(1, operand1);
223 }
224
225 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
226 uint32_t operand2) {
227 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3);
228 bytecode_ = bytecode;
229 operand_count_ = 3;
230 operand_scale_ = OperandScale::kSingle;
231 SetOperand(0, operand0);
232 SetOperand(1, operand1);
233 SetOperand(2, operand2);
234 }
235 257
236 // Print to stream |os|. 258 // Print to stream |os|.
237 void Print(std::ostream& os) const; 259 void Print(std::ostream& os) const;
238 260
239 // Transform to a node representing |new_bytecode| which has one 261 // Transform to a node representing |new_bytecode| which has one
240 // operand more than the current bytecode. 262 // operand more than the current bytecode.
241 void Transform(Bytecode new_bytecode, uint32_t extra_operand) { 263 void Transform(Bytecode new_bytecode, uint32_t extra_operand) {
242 DCHECK_EQ(Bytecodes::NumberOfOperands(new_bytecode), 264 DCHECK_EQ(Bytecodes::NumberOfOperands(new_bytecode),
243 Bytecodes::NumberOfOperands(bytecode()) + 1); 265 Bytecodes::NumberOfOperands(bytecode()) + 1);
244 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 1 || 266 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 1 ||
(...skipping 25 matching lines...) Expand all
270 292
271 const BytecodeSourceInfo& source_info() const { return source_info_; } 293 const BytecodeSourceInfo& source_info() const { return source_info_; }
272 void set_source_info(BytecodeSourceInfo source_info) { 294 void set_source_info(BytecodeSourceInfo source_info) {
273 source_info_ = source_info; 295 source_info_ = source_info;
274 } 296 }
275 297
276 bool operator==(const BytecodeNode& other) const; 298 bool operator==(const BytecodeNode& other) const;
277 bool operator!=(const BytecodeNode& other) const { return !(*this == other); } 299 bool operator!=(const BytecodeNode& other) const { return !(*this == other); }
278 300
279 private: 301 private:
302 INLINE(BytecodeNode(Bytecode bytecode, int operand_count,
303 OperandScale operand_scale,
304 BytecodeSourceInfo source_info, uint32_t operand0 = 0,
305 uint32_t operand1 = 0, uint32_t operand2 = 0,
306 uint32_t operand3 = 0))
307 : bytecode_(bytecode),
308 operand_count_(operand_count),
309 operand_scale_(operand_scale),
310 source_info_(source_info) {
311 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count);
312 operands_[0] = operand0;
313 operands_[1] = operand1;
314 operands_[2] = operand2;
315 operands_[3] = operand3;
316 }
317
318 template <OperandType operand_type>
319 INLINE(static OperandScale ScaleForOperand(uint32_t operand)) {
320 if (BytecodeOperands::IsScalableUnsignedByte(operand_type)) {
321 return Bytecodes::ScaleForUnsignedOperand(operand);
322 } else if (BytecodeOperands::IsScalableSignedByte(operand_type)) {
323 return Bytecodes::ScaleForSignedOperand(operand);
324 } else {
325 return OperandScale::kSingle;
326 }
327 }
328
280 INLINE(void UpdateScaleForOperand(int operand_index, uint32_t operand)) { 329 INLINE(void UpdateScaleForOperand(int operand_index, uint32_t operand)) {
281 if (Bytecodes::OperandIsScalableSignedByte(bytecode(), operand_index)) { 330 if (Bytecodes::OperandIsScalableSignedByte(bytecode(), operand_index)) {
282 operand_scale_ = 331 operand_scale_ =
283 std::max(operand_scale_, Bytecodes::ScaleForSignedOperand(operand)); 332 std::max(operand_scale_, Bytecodes::ScaleForSignedOperand(operand));
284 } else if (Bytecodes::OperandIsScalableUnsignedByte(bytecode(), 333 } else if (Bytecodes::OperandIsScalableUnsignedByte(bytecode(),
285 operand_index)) { 334 operand_index)) {
286 operand_scale_ = 335 operand_scale_ =
287 std::max(operand_scale_, Bytecodes::ScaleForUnsignedOperand(operand)); 336 std::max(operand_scale_, Bytecodes::ScaleForUnsignedOperand(operand));
288 } 337 }
289 } 338 }
290 339
291 INLINE(void SetOperand(int operand_index, uint32_t operand)) { 340 INLINE(void SetOperand(int operand_index, uint32_t operand)) {
292 operands_[operand_index] = operand; 341 operands_[operand_index] = operand;
293 UpdateScaleForOperand(operand_index, operand); 342 UpdateScaleForOperand(operand_index, operand);
Leszek Swirski 2016/12/05 10:57:42 Should we now no longer do this, but instead DCHEC
rmcilroy 2016/12/09 09:21:05 We still need this for the non-templated construct
Leszek Swirski 2016/12/12 14:55:41 Ah, ok, I thought you were getting rid of the non-
rmcilroy 2016/12/15 07:52:55 Yeah I am hoping to eventually get rid of them, bu
294 } 343 }
295 344
296 Bytecode bytecode_; 345 Bytecode bytecode_;
297 uint32_t operands_[Bytecodes::kMaxOperands]; 346 uint32_t operands_[Bytecodes::kMaxOperands];
298 int operand_count_; 347 int operand_count_;
299 OperandScale operand_scale_; 348 OperandScale operand_scale_;
300 BytecodeSourceInfo source_info_; 349 BytecodeSourceInfo source_info_;
301 }; 350 };
302 351
303 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, 352 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
304 const BytecodeSourceInfo& info); 353 const BytecodeSourceInfo& info);
305 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, 354 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
306 const BytecodeNode& node); 355 const BytecodeNode& node);
307 356
308 } // namespace interpreter 357 } // namespace interpreter
309 } // namespace internal 358 } // namespace internal
310 } // namespace v8 359 } // namespace v8
311 360
312 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ 361 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698