| 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 #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/interpreter/bytecode-register-allocator.h" | 8 #include "src/interpreter/bytecode-register-allocator.h" |
| 9 #include "src/interpreter/bytecode-register.h" | 9 #include "src/interpreter/bytecode-register.h" |
| 10 #include "src/interpreter/bytecodes.h" | 10 #include "src/interpreter/bytecodes.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 enum class PositionType : uint8_t { kNone, kExpression, kStatement }; | 133 enum class PositionType : uint8_t { kNone, kExpression, kStatement }; |
| 134 | 134 |
| 135 PositionType position_type_; | 135 PositionType position_type_; |
| 136 int source_position_; | 136 int source_position_; |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 // A container for a generated bytecode, it's operands, and source information. | 139 // A container for a generated bytecode, it's operands, and source information. |
| 140 // These must be allocated by a BytecodeNodeAllocator instance. | 140 // These must be allocated by a BytecodeNodeAllocator instance. |
| 141 class BytecodeNode final : ZoneObject { | 141 class BytecodeNode final : ZoneObject { |
| 142 public: | 142 public: |
| 143 INLINE(BytecodeNode(const Bytecode bytecode, | 143 INLINE( |
| 144 BytecodeSourceInfo* source_info = nullptr)) | 144 BytecodeNode(const Bytecode bytecode, |
| 145 const BytecodeSourceInfo source_info = BytecodeSourceInfo())) |
| 145 : bytecode_(bytecode), | 146 : bytecode_(bytecode), |
| 146 operand_count_(0), | 147 operand_count_(0), |
| 147 operand_scale_(OperandScale::kSingle) { | 148 operand_scale_(OperandScale::kSingle), |
| 149 source_info_(source_info) { |
| 148 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); | 150 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); |
| 149 AttachSourceInfo(source_info); | |
| 150 } | 151 } |
| 151 | 152 |
| 152 INLINE(BytecodeNode(const Bytecode bytecode, uint32_t operand0, | 153 INLINE( |
| 153 BytecodeSourceInfo* source_info = nullptr)) | 154 BytecodeNode(const Bytecode bytecode, uint32_t operand0, |
| 155 const BytecodeSourceInfo source_info = BytecodeSourceInfo())) |
| 154 : bytecode_(bytecode), | 156 : bytecode_(bytecode), |
| 155 operand_count_(1), | 157 operand_count_(1), |
| 156 operand_scale_(OperandScale::kSingle) { | 158 operand_scale_(OperandScale::kSingle), |
| 159 source_info_(source_info) { |
| 157 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); | 160 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); |
| 158 SetOperand(0, operand0); | 161 SetOperand(0, operand0); |
| 159 AttachSourceInfo(source_info); | |
| 160 } | 162 } |
| 161 | 163 |
| 162 INLINE(BytecodeNode(const Bytecode bytecode, uint32_t operand0, | 164 INLINE(BytecodeNode( |
| 163 uint32_t operand1, | 165 const Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| 164 BytecodeSourceInfo* source_info = nullptr)) | 166 const BytecodeSourceInfo source_info = BytecodeSourceInfo())) |
| 165 : bytecode_(bytecode), | 167 : bytecode_(bytecode), |
| 166 operand_count_(2), | 168 operand_count_(2), |
| 167 operand_scale_(OperandScale::kSingle) { | 169 operand_scale_(OperandScale::kSingle), |
| 170 source_info_(source_info) { |
| 168 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); | 171 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); |
| 169 SetOperand(0, operand0); | 172 SetOperand(0, operand0); |
| 170 SetOperand(1, operand1); | 173 SetOperand(1, operand1); |
| 171 AttachSourceInfo(source_info); | |
| 172 } | 174 } |
| 173 | 175 |
| 174 INLINE(BytecodeNode(const Bytecode bytecode, uint32_t operand0, | 176 INLINE( |
| 175 uint32_t operand1, uint32_t operand2, | 177 BytecodeNode(const Bytecode bytecode, uint32_t operand0, |
| 176 BytecodeSourceInfo* source_info = nullptr)) | 178 uint32_t operand1, uint32_t operand2, |
| 179 const BytecodeSourceInfo source_info = BytecodeSourceInfo())) |
| 177 : bytecode_(bytecode), | 180 : bytecode_(bytecode), |
| 178 operand_count_(3), | 181 operand_count_(3), |
| 179 operand_scale_(OperandScale::kSingle) { | 182 operand_scale_(OperandScale::kSingle), |
| 183 source_info_(source_info) { |
| 180 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); | 184 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); |
| 181 SetOperand(0, operand0); | 185 SetOperand(0, operand0); |
| 182 SetOperand(1, operand1); | 186 SetOperand(1, operand1); |
| 183 SetOperand(2, operand2); | 187 SetOperand(2, operand2); |
| 184 AttachSourceInfo(source_info); | |
| 185 } | 188 } |
| 186 | 189 |
| 187 INLINE(BytecodeNode(const Bytecode bytecode, uint32_t operand0, | 190 INLINE( |
| 188 uint32_t operand1, uint32_t operand2, uint32_t operand3, | 191 BytecodeNode(const Bytecode bytecode, uint32_t operand0, |
| 189 BytecodeSourceInfo* source_info = nullptr)) | 192 uint32_t operand1, uint32_t operand2, uint32_t operand3, |
| 193 const BytecodeSourceInfo source_info = BytecodeSourceInfo())) |
| 190 : bytecode_(bytecode), | 194 : bytecode_(bytecode), |
| 191 operand_count_(4), | 195 operand_count_(4), |
| 192 operand_scale_(OperandScale::kSingle) { | 196 operand_scale_(OperandScale::kSingle), |
| 197 source_info_(source_info) { |
| 193 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); | 198 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); |
| 194 SetOperand(0, operand0); | 199 SetOperand(0, operand0); |
| 195 SetOperand(1, operand1); | 200 SetOperand(1, operand1); |
| 196 SetOperand(2, operand2); | 201 SetOperand(2, operand2); |
| 197 SetOperand(3, operand3); | 202 SetOperand(3, operand3); |
| 198 AttachSourceInfo(source_info); | |
| 199 } | 203 } |
| 200 | 204 |
| 201 BytecodeNode(const BytecodeNode& other); | |
| 202 BytecodeNode& operator=(const BytecodeNode& other); | |
| 203 | |
| 204 // Replace the bytecode of this node with |bytecode| and keep the operands. | 205 // Replace the bytecode of this node with |bytecode| and keep the operands. |
| 205 void replace_bytecode(Bytecode bytecode) { | 206 void replace_bytecode(Bytecode bytecode) { |
| 206 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode_), | 207 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode_), |
| 207 Bytecodes::NumberOfOperands(bytecode)); | 208 Bytecodes::NumberOfOperands(bytecode)); |
| 208 bytecode_ = bytecode; | 209 bytecode_ = bytecode; |
| 209 } | 210 } |
| 211 |
| 210 void set_bytecode(Bytecode bytecode) { | 212 void set_bytecode(Bytecode bytecode) { |
| 211 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); | 213 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); |
| 212 bytecode_ = bytecode; | 214 bytecode_ = bytecode; |
| 213 operand_count_ = 0; | 215 operand_count_ = 0; |
| 214 operand_scale_ = OperandScale::kSingle; | 216 operand_scale_ = OperandScale::kSingle; |
| 215 } | 217 } |
| 218 |
| 216 void set_bytecode(Bytecode bytecode, uint32_t operand0) { | 219 void set_bytecode(Bytecode bytecode, uint32_t operand0) { |
| 217 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1); | 220 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1); |
| 218 bytecode_ = bytecode; | 221 bytecode_ = bytecode; |
| 219 operand_count_ = 1; | 222 operand_count_ = 1; |
| 220 operand_scale_ = OperandScale::kSingle; | 223 operand_scale_ = OperandScale::kSingle; |
| 221 SetOperand(0, operand0); | 224 SetOperand(0, operand0); |
| 222 } | 225 } |
| 226 |
| 223 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1) { | 227 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1) { |
| 224 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2); | 228 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2); |
| 225 bytecode_ = bytecode; | 229 bytecode_ = bytecode; |
| 226 operand_count_ = 2; | 230 operand_count_ = 2; |
| 227 operand_scale_ = OperandScale::kSingle; | 231 operand_scale_ = OperandScale::kSingle; |
| 228 SetOperand(0, operand0); | 232 SetOperand(0, operand0); |
| 229 SetOperand(1, operand1); | 233 SetOperand(1, operand1); |
| 230 } | 234 } |
| 235 |
| 231 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 236 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| 232 uint32_t operand2) { | 237 uint32_t operand2) { |
| 233 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3); | 238 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3); |
| 234 bytecode_ = bytecode; | 239 bytecode_ = bytecode; |
| 235 operand_count_ = 3; | 240 operand_count_ = 3; |
| 236 operand_scale_ = OperandScale::kSingle; | 241 operand_scale_ = OperandScale::kSingle; |
| 237 SetOperand(0, operand0); | 242 SetOperand(0, operand0); |
| 238 SetOperand(1, operand1); | 243 SetOperand(1, operand1); |
| 239 SetOperand(2, operand2); | 244 SetOperand(2, operand2); |
| 240 } | 245 } |
| 241 | 246 |
| 242 // Clone |other|. | |
| 243 void Clone(const BytecodeNode* const other); | |
| 244 | |
| 245 // Print to stream |os|. | 247 // Print to stream |os|. |
| 246 void Print(std::ostream& os) const; | 248 void Print(std::ostream& os) const; |
| 247 | 249 |
| 248 // Transform to a node representing |new_bytecode| which has one | 250 // Transform to a node representing |new_bytecode| which has one |
| 249 // operand more than the current bytecode. | 251 // operand more than the current bytecode. |
| 250 void Transform(Bytecode new_bytecode, uint32_t extra_operand) { | 252 void Transform(Bytecode new_bytecode, uint32_t extra_operand) { |
| 251 DCHECK_EQ(Bytecodes::NumberOfOperands(new_bytecode), | 253 DCHECK_EQ(Bytecodes::NumberOfOperands(new_bytecode), |
| 252 Bytecodes::NumberOfOperands(bytecode()) + 1); | 254 Bytecodes::NumberOfOperands(bytecode()) + 1); |
| 253 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 1 || | 255 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 1 || |
| 254 Bytecodes::GetOperandType(new_bytecode, 0) == | 256 Bytecodes::GetOperandType(new_bytecode, 0) == |
| 255 Bytecodes::GetOperandType(bytecode(), 0)); | 257 Bytecodes::GetOperandType(bytecode(), 0)); |
| 256 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 2 || | 258 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 2 || |
| 257 Bytecodes::GetOperandType(new_bytecode, 1) == | 259 Bytecodes::GetOperandType(new_bytecode, 1) == |
| 258 Bytecodes::GetOperandType(bytecode(), 1)); | 260 Bytecodes::GetOperandType(bytecode(), 1)); |
| 259 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 3 || | 261 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 3 || |
| 260 Bytecodes::GetOperandType(new_bytecode, 2) == | 262 Bytecodes::GetOperandType(new_bytecode, 2) == |
| 261 Bytecodes::GetOperandType(bytecode(), 2)); | 263 Bytecodes::GetOperandType(bytecode(), 2)); |
| 262 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 4); | 264 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 4); |
| 263 | 265 |
| 264 bytecode_ = new_bytecode; | 266 bytecode_ = new_bytecode; |
| 265 operand_count_++; | 267 operand_count_++; |
| 266 SetOperand(operand_count() - 1, extra_operand); | 268 SetOperand(operand_count() - 1, extra_operand); |
| 267 } | 269 } |
| 268 | 270 |
| 269 // Updates the operand at |operand_index| to |operand|. | |
| 270 void UpdateOperand(int operand_index, uint32_t operand) { | |
| 271 DCHECK_LE(operand_index, Bytecodes::NumberOfOperands(bytecode())); | |
| 272 operands_[operand_index] = operand; | |
| 273 if ((Bytecodes::OperandIsScalableSignedByte(bytecode(), operand_index) && | |
| 274 Bytecodes::ScaleForSignedOperand(operand) != operand_scale_) || | |
| 275 (Bytecodes::OperandIsScalableUnsignedByte(bytecode(), operand_index) && | |
| 276 Bytecodes::ScaleForUnsignedOperand(operand) != operand_scale_)) { | |
| 277 UpdateScale(); | |
| 278 } | |
| 279 } | |
| 280 | |
| 281 Bytecode bytecode() const { return bytecode_; } | 271 Bytecode bytecode() const { return bytecode_; } |
| 282 | 272 |
| 283 uint32_t operand(int i) const { | 273 uint32_t operand(int i) const { |
| 284 DCHECK_LT(i, operand_count()); | 274 DCHECK_LT(i, operand_count()); |
| 285 return operands_[i]; | 275 return operands_[i]; |
| 286 } | 276 } |
| 287 const uint32_t* operands() const { return operands_; } | 277 const uint32_t* operands() const { return operands_; } |
| 288 | 278 |
| 289 int operand_count() const { return operand_count_; } | 279 int operand_count() const { return operand_count_; } |
| 290 OperandScale operand_scale() const { return operand_scale_; } | 280 OperandScale operand_scale() const { return operand_scale_; } |
| 291 | 281 |
| 292 const BytecodeSourceInfo& source_info() const { return source_info_; } | 282 const BytecodeSourceInfo& source_info() const { return source_info_; } |
| 293 BytecodeSourceInfo* source_info_ptr() { return &source_info_; } | 283 BytecodeSourceInfo* source_info_ptr() { return &source_info_; } |
| 294 | 284 |
| 295 bool operator==(const BytecodeNode& other) const; | 285 bool operator==(const BytecodeNode& other) const; |
| 296 bool operator!=(const BytecodeNode& other) const { return !(*this == other); } | 286 bool operator!=(const BytecodeNode& other) const { return !(*this == other); } |
| 297 | 287 |
| 298 private: | 288 private: |
| 299 INLINE(void AttachSourceInfo(BytecodeSourceInfo* source_info)) { | |
| 300 if (source_info && source_info->is_valid()) { | |
| 301 // Statement positions need to be emitted immediately. Expression | |
| 302 // positions can be pushed back until a bytecode is found that can | |
| 303 // throw (if expression position filtering is turned on). We only | |
| 304 // invalidate the existing source position information if it is used. | |
| 305 if (source_info->is_statement() || | |
| 306 !FLAG_ignition_filter_expression_positions || | |
| 307 !Bytecodes::IsWithoutExternalSideEffects(bytecode())) { | |
| 308 source_info_.Clone(*source_info); | |
| 309 source_info->set_invalid(); | |
| 310 } | |
| 311 } | |
| 312 } | |
| 313 | |
| 314 INLINE(void UpdateScaleForOperand(int operand_index, uint32_t operand)) { | 289 INLINE(void UpdateScaleForOperand(int operand_index, uint32_t operand)) { |
| 315 if (Bytecodes::OperandIsScalableSignedByte(bytecode(), operand_index)) { | 290 if (Bytecodes::OperandIsScalableSignedByte(bytecode(), operand_index)) { |
| 316 operand_scale_ = | 291 operand_scale_ = |
| 317 std::max(operand_scale_, Bytecodes::ScaleForSignedOperand(operand)); | 292 std::max(operand_scale_, Bytecodes::ScaleForSignedOperand(operand)); |
| 318 } else if (Bytecodes::OperandIsScalableUnsignedByte(bytecode(), | 293 } else if (Bytecodes::OperandIsScalableUnsignedByte(bytecode(), |
| 319 operand_index)) { | 294 operand_index)) { |
| 320 operand_scale_ = | 295 operand_scale_ = |
| 321 std::max(operand_scale_, Bytecodes::ScaleForUnsignedOperand(operand)); | 296 std::max(operand_scale_, Bytecodes::ScaleForUnsignedOperand(operand)); |
| 322 } | 297 } |
| 323 } | 298 } |
| 324 | 299 |
| 325 INLINE(void SetOperand(int operand_index, uint32_t operand)) { | 300 INLINE(void SetOperand(int operand_index, uint32_t operand)) { |
| 326 operands_[operand_index] = operand; | 301 operands_[operand_index] = operand; |
| 327 UpdateScaleForOperand(operand_index, operand); | 302 UpdateScaleForOperand(operand_index, operand); |
| 328 } | 303 } |
| 329 | 304 |
| 330 void UpdateScale() { | |
| 331 operand_scale_ = OperandScale::kSingle; | |
| 332 for (int i = 0; i < operand_count(); i++) { | |
| 333 UpdateScaleForOperand(i, operands_[i]); | |
| 334 } | |
| 335 } | |
| 336 | |
| 337 Bytecode bytecode_; | 305 Bytecode bytecode_; |
| 338 uint32_t operands_[Bytecodes::kMaxOperands]; | 306 uint32_t operands_[Bytecodes::kMaxOperands]; |
| 339 int operand_count_; | 307 int operand_count_; |
| 340 OperandScale operand_scale_; | 308 OperandScale operand_scale_; |
| 341 BytecodeSourceInfo source_info_; | 309 BytecodeSourceInfo source_info_; |
| 342 }; | 310 }; |
| 343 | 311 |
| 344 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info); | 312 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info); |
| 345 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node); | 313 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node); |
| 346 | 314 |
| 347 } // namespace interpreter | 315 } // namespace interpreter |
| 348 } // namespace internal | 316 } // namespace internal |
| 349 } // namespace v8 | 317 } // namespace v8 |
| 350 | 318 |
| 351 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ | 319 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ |
| OLD | NEW |