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

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

Issue 2351763002: [Interpreter] Optimize BytecodeArrayBuilder and BytecodeArrayWriter. (Closed)
Patch Set: Fix Chromium Windows bots. Created 4 years, 2 months 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
« no previous file with comments | « src/interpreter/bytecode-peephole-optimizer.cc ('k') | src/interpreter/bytecode-pipeline.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 29 matching lines...) Expand all
40 // written to the next stage. 40 // written to the next stage.
41 virtual void BindLabel(BytecodeLabel* label) = 0; 41 virtual void BindLabel(BytecodeLabel* label) = 0;
42 42
43 // Binds |label| to the location of |target|. This call implicitly 43 // Binds |label| to the location of |target|. This call implicitly
44 // ends the current basic block and so any deferred bytecodes should be 44 // ends the current basic block and so any deferred bytecodes should be
45 // written to the next stage. 45 // written to the next stage.
46 virtual void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) = 0; 46 virtual void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) = 0;
47 47
48 // Flush the pipeline and generate a bytecode array. 48 // Flush the pipeline and generate a bytecode array.
49 virtual Handle<BytecodeArray> ToBytecodeArray( 49 virtual Handle<BytecodeArray> ToBytecodeArray(
50 Isolate* isolate, int fixed_register_count, int parameter_count, 50 Isolate* isolate, int register_count, int parameter_count,
51 Handle<FixedArray> handler_table) = 0; 51 Handle<FixedArray> handler_table) = 0;
52 }; 52 };
53 53
54 // Source code position information. 54 // Source code position information.
55 class BytecodeSourceInfo final { 55 class BytecodeSourceInfo final {
56 public: 56 public:
57 static const int kUninitializedPosition = -1; 57 static const int kUninitializedPosition = -1;
58 58
59 BytecodeSourceInfo() 59 BytecodeSourceInfo()
60 : position_type_(PositionType::kNone), 60 : position_type_(PositionType::kNone),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 bool operator!=(const BytecodeSourceInfo& other) const { 127 bool operator!=(const BytecodeSourceInfo& other) const {
128 return position_type_ != other.position_type_ || 128 return position_type_ != other.position_type_ ||
129 source_position_ != other.source_position_; 129 source_position_ != other.source_position_;
130 } 130 }
131 131
132 private: 132 private:
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
138 DISALLOW_COPY_AND_ASSIGN(BytecodeSourceInfo);
139 }; 137 };
140 138
141 // 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.
142 // These must be allocated by a BytecodeNodeAllocator instance. 140 // These must be allocated by a BytecodeNodeAllocator instance.
143 class BytecodeNode final : ZoneObject { 141 class BytecodeNode final : ZoneObject {
144 public: 142 public:
145 explicit BytecodeNode(Bytecode bytecode = Bytecode::kIllegal); 143 INLINE(BytecodeNode(const Bytecode bytecode,
146 BytecodeNode(Bytecode bytecode, uint32_t operand0); 144 BytecodeSourceInfo* source_info = nullptr))
147 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1); 145 : bytecode_(bytecode),
148 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, 146 operand_count_(0),
149 uint32_t operand2); 147 operand_scale_(OperandScale::kSingle) {
150 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, 148 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
151 uint32_t operand2, uint32_t operand3); 149 AttachSourceInfo(source_info);
150 }
151
152 INLINE(BytecodeNode(const Bytecode bytecode, uint32_t operand0,
153 BytecodeSourceInfo* source_info = nullptr))
154 : bytecode_(bytecode),
155 operand_count_(1),
156 operand_scale_(OperandScale::kSingle) {
157 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
158 SetOperand(0, operand0);
159 AttachSourceInfo(source_info);
160 }
161
162 INLINE(BytecodeNode(const Bytecode bytecode, uint32_t operand0,
163 uint32_t operand1,
164 BytecodeSourceInfo* source_info = nullptr))
165 : bytecode_(bytecode),
166 operand_count_(2),
167 operand_scale_(OperandScale::kSingle) {
168 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
169 SetOperand(0, operand0);
170 SetOperand(1, operand1);
171 AttachSourceInfo(source_info);
172 }
173
174 INLINE(BytecodeNode(const Bytecode bytecode, uint32_t operand0,
175 uint32_t operand1, uint32_t operand2,
176 BytecodeSourceInfo* source_info = nullptr))
177 : bytecode_(bytecode),
178 operand_count_(3),
179 operand_scale_(OperandScale::kSingle) {
180 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
181 SetOperand(0, operand0);
182 SetOperand(1, operand1);
183 SetOperand(2, operand2);
184 AttachSourceInfo(source_info);
185 }
186
187 INLINE(BytecodeNode(const Bytecode bytecode, uint32_t operand0,
188 uint32_t operand1, uint32_t operand2, uint32_t operand3,
189 BytecodeSourceInfo* source_info = nullptr))
190 : bytecode_(bytecode),
191 operand_count_(4),
192 operand_scale_(OperandScale::kSingle) {
193 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
194 SetOperand(0, operand0);
195 SetOperand(1, operand1);
196 SetOperand(2, operand2);
197 SetOperand(3, operand3);
198 AttachSourceInfo(source_info);
199 }
152 200
153 BytecodeNode(const BytecodeNode& other); 201 BytecodeNode(const BytecodeNode& other);
154 BytecodeNode& operator=(const BytecodeNode& other); 202 BytecodeNode& operator=(const BytecodeNode& other);
155 203
156 // Replace the bytecode of this node with |bytecode| and keep the operands. 204 // Replace the bytecode of this node with |bytecode| and keep the operands.
157 void replace_bytecode(Bytecode bytecode) { 205 void replace_bytecode(Bytecode bytecode) {
158 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode_), 206 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode_),
159 Bytecodes::NumberOfOperands(bytecode)); 207 Bytecodes::NumberOfOperands(bytecode));
160 bytecode_ = bytecode; 208 bytecode_ = bytecode;
161 } 209 }
162 void set_bytecode(Bytecode bytecode) { 210 void set_bytecode(Bytecode bytecode) {
163 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); 211 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0);
164 bytecode_ = bytecode; 212 bytecode_ = bytecode;
213 operand_count_ = 0;
214 operand_scale_ = OperandScale::kSingle;
165 } 215 }
166 void set_bytecode(Bytecode bytecode, uint32_t operand0) { 216 void set_bytecode(Bytecode bytecode, uint32_t operand0) {
167 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1); 217 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1);
168 bytecode_ = bytecode; 218 bytecode_ = bytecode;
169 operands_[0] = operand0; 219 operand_count_ = 1;
220 operand_scale_ = OperandScale::kSingle;
221 SetOperand(0, operand0);
170 } 222 }
171 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1) { 223 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1) {
172 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2); 224 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2);
173 bytecode_ = bytecode; 225 bytecode_ = bytecode;
174 operands_[0] = operand0; 226 operand_count_ = 2;
175 operands_[1] = operand1; 227 operand_scale_ = OperandScale::kSingle;
228 SetOperand(0, operand0);
229 SetOperand(1, operand1);
176 } 230 }
177 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, 231 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
178 uint32_t operand2) { 232 uint32_t operand2) {
179 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3); 233 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3);
180 bytecode_ = bytecode; 234 bytecode_ = bytecode;
181 operands_[0] = operand0; 235 operand_count_ = 3;
182 operands_[1] = operand1; 236 operand_scale_ = OperandScale::kSingle;
183 operands_[2] = operand2; 237 SetOperand(0, operand0);
238 SetOperand(1, operand1);
239 SetOperand(2, operand2);
184 } 240 }
185 241
186 // Clone |other|. 242 // Clone |other|.
187 void Clone(const BytecodeNode* const other); 243 void Clone(const BytecodeNode* const other);
188 244
189 // Print to stream |os|. 245 // Print to stream |os|.
190 void Print(std::ostream& os) const; 246 void Print(std::ostream& os) const;
191 247
192 // Transform to a node representing |new_bytecode| which has one 248 // Transform to a node representing |new_bytecode| which has one
193 // operand more than the current bytecode. 249 // operand more than the current bytecode.
194 void Transform(Bytecode new_bytecode, uint32_t extra_operand); 250 void Transform(Bytecode new_bytecode, uint32_t extra_operand) {
251 DCHECK_EQ(Bytecodes::NumberOfOperands(new_bytecode),
252 Bytecodes::NumberOfOperands(bytecode()) + 1);
253 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 1 ||
254 Bytecodes::GetOperandType(new_bytecode, 0) ==
255 Bytecodes::GetOperandType(bytecode(), 0));
256 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 2 ||
257 Bytecodes::GetOperandType(new_bytecode, 1) ==
258 Bytecodes::GetOperandType(bytecode(), 1));
259 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 3 ||
260 Bytecodes::GetOperandType(new_bytecode, 2) ==
261 Bytecodes::GetOperandType(bytecode(), 2));
262 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 4);
263
264 bytecode_ = new_bytecode;
265 operand_count_++;
266 SetOperand(operand_count() - 1, extra_operand);
267 }
268
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 }
195 280
196 Bytecode bytecode() const { return bytecode_; } 281 Bytecode bytecode() const { return bytecode_; }
197 282
198 uint32_t operand(int i) const { 283 uint32_t operand(int i) const {
199 DCHECK_LT(i, operand_count()); 284 DCHECK_LT(i, operand_count());
200 return operands_[i]; 285 return operands_[i];
201 } 286 }
202 uint32_t* operands() { return operands_; }
203 const uint32_t* operands() const { return operands_; } 287 const uint32_t* operands() const { return operands_; }
204 288
205 int operand_count() const { return Bytecodes::NumberOfOperands(bytecode_); } 289 int operand_count() const { return operand_count_; }
290 OperandScale operand_scale() const { return operand_scale_; }
206 291
207 const BytecodeSourceInfo& source_info() const { return source_info_; } 292 const BytecodeSourceInfo& source_info() const { return source_info_; }
208 BytecodeSourceInfo& source_info() { return source_info_; } 293 BytecodeSourceInfo* source_info_ptr() { return &source_info_; }
209 294
210 bool operator==(const BytecodeNode& other) const; 295 bool operator==(const BytecodeNode& other) const;
211 bool operator!=(const BytecodeNode& other) const { return !(*this == other); } 296 bool operator!=(const BytecodeNode& other) const { return !(*this == other); }
212 297
213 private: 298 private:
214 static const int kInvalidPosition = kMinInt; 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)) {
315 if (Bytecodes::OperandIsScalableSignedByte(bytecode(), operand_index)) {
316 operand_scale_ =
317 std::max(operand_scale_, Bytecodes::ScaleForSignedOperand(operand));
318 } else if (Bytecodes::OperandIsScalableUnsignedByte(bytecode(),
319 operand_index)) {
320 operand_scale_ =
321 std::max(operand_scale_, Bytecodes::ScaleForUnsignedOperand(operand));
322 }
323 }
324
325 INLINE(void SetOperand(int operand_index, uint32_t operand)) {
326 operands_[operand_index] = operand;
327 UpdateScaleForOperand(operand_index, operand);
328 }
329
330 void UpdateScale() {
331 operand_scale_ = OperandScale::kSingle;
332 for (int i = 0; i < operand_count(); i++) {
333 UpdateScaleForOperand(i, operands_[i]);
334 }
335 }
215 336
216 Bytecode bytecode_; 337 Bytecode bytecode_;
217 uint32_t operands_[Bytecodes::kMaxOperands]; 338 uint32_t operands_[Bytecodes::kMaxOperands];
339 int operand_count_;
340 OperandScale operand_scale_;
218 BytecodeSourceInfo source_info_; 341 BytecodeSourceInfo source_info_;
219 }; 342 };
220 343
221 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info); 344 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info);
222 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node); 345 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node);
223 346
224 } // namespace interpreter 347 } // namespace interpreter
225 } // namespace internal 348 } // namespace internal
226 } // namespace v8 349 } // namespace v8
227 350
228 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ 351 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-peephole-optimizer.cc ('k') | src/interpreter/bytecode-pipeline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698