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

Side by Side Diff: src/interpreter/bytecode-array-builder.cc

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 #include "src/interpreter/bytecode-array-builder.h" 5 #include "src/interpreter/bytecode-array-builder.h"
6 6
7 #include "src/globals.h" 7 #include "src/globals.h"
8 #include "src/interpreter/bytecode-array-writer.h" 8 #include "src/interpreter/bytecode-array-writer.h"
9 #include "src/interpreter/bytecode-dead-code-optimizer.h" 9 #include "src/interpreter/bytecode-dead-code-optimizer.h"
10 #include "src/interpreter/bytecode-label.h" 10 #include "src/interpreter/bytecode-label.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 136 }
137 }; 137 };
138 138
139 template <OperandType> 139 template <OperandType>
140 class OperandHelper {}; 140 class OperandHelper {};
141 141
142 #define DEFINE_UNSIGNED_OPERAND_HELPER(Name, Type) \ 142 #define DEFINE_UNSIGNED_OPERAND_HELPER(Name, Type) \
143 template <> \ 143 template <> \
144 class OperandHelper<OperandType::k##Name> \ 144 class OperandHelper<OperandType::k##Name> \
145 : public UnsignedOperandHelper<Type> {}; 145 : public UnsignedOperandHelper<Type> {};
146 UNSIGNED_SCALAR_OPERAND_TYPE_LIST(DEFINE_UNSIGNED_OPERAND_HELPER) 146 UNSIGNED_FIXED_SCALAR_OPERAND_TYPE_LIST(DEFINE_UNSIGNED_OPERAND_HELPER)
147 UNSIGNED_SCALABLE_SCALAR_OPERAND_TYPE_LIST(DEFINE_UNSIGNED_OPERAND_HELPER)
147 #undef DEFINE_UNSIGNED_OPERAND_HELPER 148 #undef DEFINE_UNSIGNED_OPERAND_HELPER
148 149
149 template <> 150 template <>
150 class OperandHelper<OperandType::kImm> { 151 class OperandHelper<OperandType::kImm> {
151 public: 152 public:
152 INLINE(static uint32_t Convert(BytecodeArrayBuilder* builder, int value)) { 153 INLINE(static uint32_t Convert(BytecodeArrayBuilder* builder, int value)) {
153 return static_cast<uint32_t>(value); 154 return static_cast<uint32_t>(value);
154 } 155 }
155 }; 156 };
156 157
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 public: 205 public:
205 INLINE(static uint32_t Convert(BytecodeArrayBuilder* builder, 206 INLINE(static uint32_t Convert(BytecodeArrayBuilder* builder,
206 RegisterList reg_list)) { 207 RegisterList reg_list)) {
207 DCHECK_EQ(3, reg_list.register_count()); 208 DCHECK_EQ(3, reg_list.register_count());
208 return builder->GetOutputRegisterListOperand(reg_list); 209 return builder->GetOutputRegisterListOperand(reg_list);
209 } 210 }
210 }; 211 };
211 212
212 } // namespace 213 } // namespace
213 214
214 template <OperandType... operand_types> 215 template <Bytecode bytecode, AccumulatorUse accumulator_use,
216 OperandType... operand_types>
215 class BytecodeNodeBuilder { 217 class BytecodeNodeBuilder {
216 public: 218 public:
217 template <typename... Operands> 219 template <typename... Operands>
218 INLINE(static BytecodeNode Make(BytecodeArrayBuilder* builder, 220 INLINE(static BytecodeNode Make(BytecodeArrayBuilder* builder,
219 BytecodeSourceInfo source_info, 221 BytecodeSourceInfo source_info,
220 Bytecode bytecode, Operands... operands)) { 222 Operands... operands)) {
221 builder->PrepareToOutputBytecode(bytecode); 223 builder->PrepareToOutputBytecode<bytecode, accumulator_use>();
222 // The "OperandHelper<operand_types>::Convert(builder, operands)..." will 224 // The "OperandHelper<operand_types>::Convert(builder, operands)..." will
223 // expand both the OperandType... and Operands... parameter packs e.g. for: 225 // expand both the OperandType... and Operands... parameter packs e.g. for:
224 // BytecodeNodeBuilder<OperandType::kReg, OperandType::kImm>::Make< 226 // BytecodeNodeBuilder<OperandType::kReg, OperandType::kImm>::Make<
225 // Register, int>(..., Register reg, int immediate) 227 // Register, int>(..., Register reg, int immediate)
226 // the code will expand into: 228 // the code will expand into:
227 // OperandHelper<OperandType::kReg>::Convert(builder, reg), 229 // OperandHelper<OperandType::kReg>::Convert(builder, reg),
228 // OperandHelper<OperandType::kImm>::Convert(builder, immediate), 230 // OperandHelper<OperandType::kImm>::Convert(builder, immediate),
229 return BytecodeNode( 231 return BytecodeNode::Create<bytecode, operand_types...>(
230 bytecode, OperandHelper<operand_types>::Convert(builder, operands)..., 232 OperandHelper<operand_types>::Convert(builder, operands)...,
231 source_info); 233 source_info);
232 } 234 }
233 }; 235 };
234 236
235 #define DEFINE_BYTECODE_OUTPUT(name, accumulator_use, ...) \ 237 #define DEFINE_BYTECODE_OUTPUT(name, ...) \
236 template <typename... Operands> \ 238 template <typename... Operands> \
237 void BytecodeArrayBuilder::Output##name(Operands... operands) { \ 239 void BytecodeArrayBuilder::Output##name(Operands... operands) { \
238 BytecodeNode node(BytecodeNodeBuilder<__VA_ARGS__>::Make<Operands...>( \ 240 BytecodeNode node( \
239 this, CurrentSourcePosition(Bytecode::k##name), Bytecode::k##name, \ 241 BytecodeNodeBuilder<Bytecode::k##name, __VA_ARGS__>::Make< \
240 operands...)); \ 242 Operands...>(this, CurrentSourcePosition(Bytecode::k##name), \
241 pipeline()->Write(&node); \ 243 operands...)); \
242 } \ 244 pipeline()->Write(&node); \
243 \ 245 } \
244 template <typename... Operands> \ 246 \
245 void BytecodeArrayBuilder::Output##name(BytecodeLabel* label, \ 247 template <typename... Operands> \
246 Operands... operands) { \ 248 void BytecodeArrayBuilder::Output##name(BytecodeLabel* label, \
247 DCHECK(Bytecodes::IsJump(Bytecode::k##name)); \ 249 Operands... operands) { \
248 BytecodeNode node(BytecodeNodeBuilder<__VA_ARGS__>::Make<Operands...>( \ 250 DCHECK(Bytecodes::IsJump(Bytecode::k##name)); \
249 this, CurrentSourcePosition(Bytecode::k##name), Bytecode::k##name, \ 251 BytecodeNode node( \
250 operands...)); \ 252 BytecodeNodeBuilder<Bytecode::k##name, __VA_ARGS__>::Make< \
251 pipeline()->WriteJump(&node, label); \ 253 Operands...>(this, CurrentSourcePosition(Bytecode::k##name), \
252 LeaveBasicBlock(); \ 254 operands...)); \
255 pipeline()->WriteJump(&node, label); \
256 LeaveBasicBlock(); \
253 } 257 }
254 BYTECODE_LIST(DEFINE_BYTECODE_OUTPUT) 258 BYTECODE_LIST(DEFINE_BYTECODE_OUTPUT)
255 #undef DEFINE_BYTECODE_OUTPUT 259 #undef DEFINE_BYTECODE_OUTPUT
256 260
257 BytecodeArrayBuilder& BytecodeArrayBuilder::BinaryOperation(Token::Value op, 261 BytecodeArrayBuilder& BytecodeArrayBuilder::BinaryOperation(Token::Value op,
258 Register reg, 262 Register reg,
259 int feedback_slot) { 263 int feedback_slot) {
260 switch (op) { 264 switch (op) {
261 case Token::Value::ADD: 265 case Token::Value::ADD:
262 OutputAdd(reg, feedback_slot); 266 OutputAdd(reg, feedback_slot);
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 int first_reg_index = reg_list.first_register().index(); 984 int first_reg_index = reg_list.first_register().index();
981 for (int i = 0; i < reg_list.register_count(); i++) { 985 for (int i = 0; i < reg_list.register_count(); i++) {
982 if (!RegisterIsValid(Register(first_reg_index + i))) { 986 if (!RegisterIsValid(Register(first_reg_index + i))) {
983 return false; 987 return false;
984 } 988 }
985 } 989 }
986 return true; 990 return true;
987 } 991 }
988 } 992 }
989 993
990 void BytecodeArrayBuilder::PrepareToOutputBytecode(Bytecode bytecode) { 994 template <Bytecode bytecode, AccumulatorUse accumulator_use>
991 if (register_optimizer_) register_optimizer_->PrepareForBytecode(bytecode); 995 void BytecodeArrayBuilder::PrepareToOutputBytecode() {
996 if (register_optimizer_)
997 register_optimizer_->PrepareForBytecode<bytecode, accumulator_use>();
992 } 998 }
993 999
994 uint32_t BytecodeArrayBuilder::GetInputRegisterOperand(Register reg) { 1000 uint32_t BytecodeArrayBuilder::GetInputRegisterOperand(Register reg) {
995 DCHECK(RegisterIsValid(reg)); 1001 DCHECK(RegisterIsValid(reg));
996 if (register_optimizer_) reg = register_optimizer_->GetInputRegister(reg); 1002 if (register_optimizer_) reg = register_optimizer_->GetInputRegister(reg);
997 return static_cast<uint32_t>(reg.ToOperand()); 1003 return static_cast<uint32_t>(reg.ToOperand());
998 } 1004 }
999 1005
1000 uint32_t BytecodeArrayBuilder::GetOutputRegisterOperand(Register reg) { 1006 uint32_t BytecodeArrayBuilder::GetOutputRegisterOperand(Register reg) {
1001 DCHECK(RegisterIsValid(reg)); 1007 DCHECK(RegisterIsValid(reg));
(...skipping 13 matching lines...) Expand all
1015 RegisterList reg_list) { 1021 RegisterList reg_list) {
1016 DCHECK(RegisterListIsValid(reg_list)); 1022 DCHECK(RegisterListIsValid(reg_list));
1017 if (register_optimizer_) 1023 if (register_optimizer_)
1018 register_optimizer_->PrepareOutputRegisterList(reg_list); 1024 register_optimizer_->PrepareOutputRegisterList(reg_list);
1019 return static_cast<uint32_t>(reg_list.first_register().ToOperand()); 1025 return static_cast<uint32_t>(reg_list.first_register().ToOperand());
1020 } 1026 }
1021 1027
1022 } // namespace interpreter 1028 } // namespace interpreter
1023 } // namespace internal 1029 } // namespace internal
1024 } // namespace v8 1030 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698