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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: src/interpreter/bytecode-pipeline.h
diff --git a/src/interpreter/bytecode-pipeline.h b/src/interpreter/bytecode-pipeline.h
index d508defea06ba6256cb98d9ffb416cd685b337d3..c9223e4d0f3f2fb3555828414ade82a7a99d6472 100644
--- a/src/interpreter/bytecode-pipeline.h
+++ b/src/interpreter/bytecode-pipeline.h
@@ -191,48 +191,70 @@ class V8_EXPORT_PRIVATE BytecodeNode final : NON_EXPORTED_BASE(ZoneObject) {
SetOperand(3, operand3);
}
- // Replace the bytecode of this node with |bytecode| and keep the operands.
- void replace_bytecode(Bytecode bytecode) {
- DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode_),
- Bytecodes::NumberOfOperands(bytecode));
- bytecode_ = bytecode;
+ template <Bytecode bytecode>
+ INLINE(static BytecodeNode Create(
+ BytecodeSourceInfo source_info = BytecodeSourceInfo())) {
+ return BytecodeNode(bytecode, 0, OperandScale::kSingle, source_info);
}
- void set_bytecode(Bytecode bytecode) {
- DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0);
- bytecode_ = bytecode;
- operand_count_ = 0;
- operand_scale_ = OperandScale::kSingle;
+ template <Bytecode bytecode, OperandType operand0_type>
+ INLINE(static BytecodeNode Create(
+ uint32_t operand0,
+ BytecodeSourceInfo source_info = BytecodeSourceInfo())) {
+ OperandScale scale = OperandScale::kSingle;
+ scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
+ return BytecodeNode(bytecode, 1, scale, source_info, operand0);
}
- void set_bytecode(Bytecode bytecode, uint32_t operand0) {
- DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1);
- bytecode_ = bytecode;
- operand_count_ = 1;
- operand_scale_ = OperandScale::kSingle;
- SetOperand(0, operand0);
+ template <Bytecode bytecode, OperandType operand0_type,
+ OperandType operand1_type>
+ INLINE(static BytecodeNode Create(
+ uint32_t operand0, uint32_t operand1,
+ BytecodeSourceInfo source_info = BytecodeSourceInfo())) {
+ OperandScale scale = OperandScale::kSingle;
+ scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
+ scale = std::max(scale, ScaleForOperand<operand1_type>(operand1));
+ return BytecodeNode(bytecode, 2, scale, source_info, operand0, operand1);
}
- void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1) {
- DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2);
- bytecode_ = bytecode;
- operand_count_ = 2;
- operand_scale_ = OperandScale::kSingle;
- SetOperand(0, operand0);
- SetOperand(1, operand1);
+ template <Bytecode bytecode, OperandType operand0_type,
+ OperandType operand1_type, OperandType operand2_type>
+ INLINE(static BytecodeNode Create(
+ uint32_t operand0, uint32_t operand1, uint32_t operand2,
+ BytecodeSourceInfo source_info = BytecodeSourceInfo())) {
+ OperandScale scale = OperandScale::kSingle;
+ scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
+ scale = std::max(scale, ScaleForOperand<operand1_type>(operand1));
+ scale = std::max(scale, ScaleForOperand<operand2_type>(operand2));
+ return BytecodeNode(bytecode, 3, scale, source_info, operand0, operand1,
+ operand2);
}
- void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
- uint32_t operand2) {
- DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3);
+ template <Bytecode bytecode, OperandType operand0_type,
+ OperandType operand1_type, OperandType operand2_type,
+ OperandType operand3_type>
+ INLINE(static BytecodeNode Create(
+ uint32_t operand0, uint32_t operand1, uint32_t operand2,
+ uint32_t operand3,
+ BytecodeSourceInfo source_info = BytecodeSourceInfo())) {
+ OperandScale scale = OperandScale::kSingle;
+ scale = std::max(scale, ScaleForOperand<operand0_type>(operand0));
+ scale = std::max(scale, ScaleForOperand<operand1_type>(operand1));
+ scale = std::max(scale, ScaleForOperand<operand2_type>(operand2));
+ scale = std::max(scale, ScaleForOperand<operand3_type>(operand3));
+ return BytecodeNode(bytecode, 4, scale, source_info, operand0, operand1,
+ operand2, operand3);
+ }
+
+ // Replace the bytecode of this node with |bytecode| and keep the operands.
+ void replace_bytecode(Bytecode bytecode) {
+ DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode_),
+ Bytecodes::NumberOfOperands(bytecode));
bytecode_ = bytecode;
- operand_count_ = 3;
- operand_scale_ = OperandScale::kSingle;
- SetOperand(0, operand0);
- SetOperand(1, operand1);
- SetOperand(2, operand2);
}
+ void update_operand0(uint32_t operand0) { SetOperand(0, operand0); }
+
// Print to stream |os|.
void Print(std::ostream& os) const;
@@ -277,6 +299,33 @@ class V8_EXPORT_PRIVATE BytecodeNode final : NON_EXPORTED_BASE(ZoneObject) {
bool operator!=(const BytecodeNode& other) const { return !(*this == other); }
private:
+ INLINE(BytecodeNode(Bytecode bytecode, int operand_count,
+ OperandScale operand_scale,
+ BytecodeSourceInfo source_info, uint32_t operand0 = 0,
+ uint32_t operand1 = 0, uint32_t operand2 = 0,
+ uint32_t operand3 = 0))
+ : bytecode_(bytecode),
+ operand_count_(operand_count),
+ operand_scale_(operand_scale),
+ source_info_(source_info) {
+ DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count);
+ operands_[0] = operand0;
+ operands_[1] = operand1;
+ operands_[2] = operand2;
+ operands_[3] = operand3;
+ }
+
+ template <OperandType operand_type>
+ INLINE(static OperandScale ScaleForOperand(uint32_t operand)) {
+ if (BytecodeOperands::IsScalableUnsignedByte(operand_type)) {
+ return Bytecodes::ScaleForUnsignedOperand(operand);
+ } else if (BytecodeOperands::IsScalableSignedByte(operand_type)) {
+ return Bytecodes::ScaleForSignedOperand(operand);
+ } else {
+ return OperandScale::kSingle;
+ }
+ }
+
INLINE(void UpdateScaleForOperand(int operand_index, uint32_t operand)) {
if (Bytecodes::OperandIsScalableSignedByte(bytecode(), operand_index)) {
operand_scale_ =

Powered by Google App Engine
This is Rietveld 408576698