OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "lithium-allocator.h" | 32 #include "lithium-allocator.h" |
33 #include "lithium.h" | 33 #include "lithium.h" |
34 #include "safepoint-table.h" | 34 #include "safepoint-table.h" |
35 | 35 |
36 namespace v8 { | 36 namespace v8 { |
37 namespace internal { | 37 namespace internal { |
38 | 38 |
39 // Forward declarations. | 39 // Forward declarations. |
40 class LCodeGen; | 40 class LCodeGen; |
41 | 41 |
42 | |
43 #define LITHIUM_ALL_INSTRUCTION_LIST(V) \ | |
44 V(ControlInstruction) \ | |
45 V(Call) \ | |
46 LITHIUM_CONCRETE_INSTRUCTION_LIST(V) | |
47 | |
48 | |
49 #define LITHIUM_CONCRETE_INSTRUCTION_LIST(V) \ | 42 #define LITHIUM_CONCRETE_INSTRUCTION_LIST(V) \ |
50 V(AccessArgumentsAt) \ | 43 V(AccessArgumentsAt) \ |
51 V(AddI) \ | 44 V(AddI) \ |
52 V(ApplyArguments) \ | 45 V(ApplyArguments) \ |
53 V(ArgumentsElements) \ | 46 V(ArgumentsElements) \ |
54 V(ArgumentsLength) \ | 47 V(ArgumentsLength) \ |
55 V(ArithmeticD) \ | 48 V(ArithmeticD) \ |
56 V(ArithmeticT) \ | 49 V(ArithmeticT) \ |
57 V(ArrayLiteral) \ | 50 V(ArrayLiteral) \ |
58 V(BitI) \ | 51 V(BitI) \ |
(...skipping 28 matching lines...) Expand all Loading... | |
87 V(ConstantI) \ | 80 V(ConstantI) \ |
88 V(ConstantT) \ | 81 V(ConstantT) \ |
89 V(Context) \ | 82 V(Context) \ |
90 V(DeleteProperty) \ | 83 V(DeleteProperty) \ |
91 V(Deoptimize) \ | 84 V(Deoptimize) \ |
92 V(DivI) \ | 85 V(DivI) \ |
93 V(DoubleToI) \ | 86 V(DoubleToI) \ |
94 V(ExternalArrayLength) \ | 87 V(ExternalArrayLength) \ |
95 V(FixedArrayLength) \ | 88 V(FixedArrayLength) \ |
96 V(FunctionLiteral) \ | 89 V(FunctionLiteral) \ |
97 V(Gap) \ | |
98 V(GetCachedArrayIndex) \ | 90 V(GetCachedArrayIndex) \ |
99 V(GlobalObject) \ | 91 V(GlobalObject) \ |
100 V(GlobalReceiver) \ | 92 V(GlobalReceiver) \ |
101 V(Goto) \ | 93 V(Goto) \ |
102 V(HasCachedArrayIndex) \ | 94 V(HasCachedArrayIndex) \ |
103 V(HasCachedArrayIndexAndBranch) \ | 95 V(HasCachedArrayIndexAndBranch) \ |
104 V(HasInstanceType) \ | 96 V(HasInstanceType) \ |
105 V(HasInstanceTypeAndBranch) \ | 97 V(HasInstanceTypeAndBranch) \ |
106 V(InstanceOf) \ | 98 V(InstanceOf) \ |
107 V(InstanceOfAndBranch) \ | 99 V(InstanceOfAndBranch) \ |
108 V(InstanceOfKnownGlobal) \ | 100 V(InstanceOfKnownGlobal) \ |
101 V(InstructionGap) \ | |
109 V(Integer32ToDouble) \ | 102 V(Integer32ToDouble) \ |
110 V(InvokeFunction) \ | 103 V(InvokeFunction) \ |
111 V(IsNull) \ | 104 V(IsNull) \ |
112 V(IsNullAndBranch) \ | 105 V(IsNullAndBranch) \ |
113 V(IsObject) \ | 106 V(IsObject) \ |
114 V(IsObjectAndBranch) \ | 107 V(IsObjectAndBranch) \ |
115 V(IsSmi) \ | 108 V(IsSmi) \ |
116 V(IsSmiAndBranch) \ | 109 V(IsSmiAndBranch) \ |
117 V(IsConstructCall) \ | 110 V(IsConstructCall) \ |
118 V(IsConstructCallAndBranch) \ | 111 V(IsConstructCallAndBranch) \ |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 V(Throw) \ | 158 V(Throw) \ |
166 V(ToFastProperties) \ | 159 V(ToFastProperties) \ |
167 V(Typeof) \ | 160 V(Typeof) \ |
168 V(TypeofIs) \ | 161 V(TypeofIs) \ |
169 V(TypeofIsAndBranch) \ | 162 V(TypeofIsAndBranch) \ |
170 V(UnaryMathOperation) \ | 163 V(UnaryMathOperation) \ |
171 V(UnknownOSRValue) \ | 164 V(UnknownOSRValue) \ |
172 V(ValueOf) | 165 V(ValueOf) |
173 | 166 |
174 | 167 |
175 #define DECLARE_INSTRUCTION(type) \ | 168 #define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \ |
176 virtual bool Is##type() const { return true; } \ | 169 virtual Opcode opcode() const { return LInstruction::k##type; } \ |
177 static L##type* cast(LInstruction* instr) { \ | 170 virtual void CompileToNative(LCodeGen* generator); \ |
178 ASSERT(instr->Is##type()); \ | 171 virtual const char* Mnemonic() const { return mnemonic; } \ |
179 return reinterpret_cast<L##type*>(instr); \ | 172 static L##type* cast(LInstruction* instr) { \ |
173 ASSERT(instr->Is##type()); \ | |
174 return reinterpret_cast<L##type*>(instr); \ | |
180 } | 175 } |
181 | 176 |
182 | 177 |
183 #define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \ | |
184 virtual void CompileToNative(LCodeGen* generator); \ | |
185 virtual const char* Mnemonic() const { return mnemonic; } \ | |
186 DECLARE_INSTRUCTION(type) | |
187 | |
188 | |
189 #define DECLARE_HYDROGEN_ACCESSOR(type) \ | 178 #define DECLARE_HYDROGEN_ACCESSOR(type) \ |
190 H##type* hydrogen() const { \ | 179 H##type* hydrogen() const { \ |
191 return H##type::cast(hydrogen_value()); \ | 180 return H##type::cast(hydrogen_value()); \ |
192 } | 181 } |
193 | 182 |
194 | 183 |
195 class LInstruction: public ZoneObject { | 184 class LInstruction: public ZoneObject { |
196 public: | 185 public: |
197 LInstruction() | 186 LInstruction() |
198 : environment_(NULL), | 187 : environment_(NULL), |
199 hydrogen_value_(NULL), | 188 hydrogen_value_(NULL), |
200 is_call_(false), | 189 is_call_(false), |
201 is_save_doubles_(false) { } | 190 is_save_doubles_(false) { } |
202 virtual ~LInstruction() { } | 191 virtual ~LInstruction() { } |
203 | 192 |
204 virtual void CompileToNative(LCodeGen* generator) = 0; | 193 virtual void CompileToNative(LCodeGen* generator) = 0; |
205 virtual const char* Mnemonic() const = 0; | 194 virtual const char* Mnemonic() const = 0; |
206 virtual void PrintTo(StringStream* stream); | 195 virtual void PrintTo(StringStream* stream); |
207 virtual void PrintDataTo(StringStream* stream) = 0; | 196 virtual void PrintDataTo(StringStream* stream) = 0; |
208 virtual void PrintOutputOperandTo(StringStream* stream) = 0; | 197 virtual void PrintOutputOperandTo(StringStream* stream) = 0; |
209 | 198 |
210 // Declare virtual type testers. | 199 enum Opcode { |
211 #define DECLARE_DO(type) virtual bool Is##type() const { return false; } | 200 // Declare a unique enum value for each instruction. |
212 LITHIUM_ALL_INSTRUCTION_LIST(DECLARE_DO) | 201 #define DECLARE_OPCODE(type) k##type, |
Kevin Millikin (Chromium)
2011/04/26 15:06:53
I guess we usually write #define and #undef with a
| |
213 #undef DECLARE_DO | 202 LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_OPCODE) |
203 kNumberOfInstructions | |
204 #undef DECLARE_OPCODE | |
205 }; | |
206 | |
207 virtual Opcode opcode() const = 0; | |
208 | |
209 // Declare non-virtual type testers for all leaf IR classes. | |
210 #define DECLARE_PREDICATE(type) \ | |
211 bool Is##type() const { return opcode() == k##type; } | |
212 LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_PREDICATE) | |
213 #undef DECLARE_PREDICATE | |
214 | |
215 // Declare virtual predicates for instructions that don't have | |
216 // an opcode. | |
217 virtual bool IsGap() const { return false; } | |
214 | 218 |
215 virtual bool IsControl() const { return false; } | 219 virtual bool IsControl() const { return false; } |
216 virtual void SetBranchTargets(int true_block_id, int false_block_id) { } | 220 virtual void SetBranchTargets(int true_block_id, int false_block_id) { } |
217 | 221 |
218 void set_environment(LEnvironment* env) { environment_ = env; } | 222 void set_environment(LEnvironment* env) { environment_ = env; } |
219 LEnvironment* environment() const { return environment_; } | 223 LEnvironment* environment() const { return environment_; } |
220 bool HasEnvironment() const { return environment_ != NULL; } | 224 bool HasEnvironment() const { return environment_ != NULL; } |
221 | 225 |
222 void set_pointer_map(LPointerMap* p) { pointer_map_.set(p); } | 226 void set_pointer_map(LPointerMap* p) { pointer_map_.set(p); } |
223 LPointerMap* pointer_map() const { return pointer_map_.get(); } | 227 LPointerMap* pointer_map() const { return pointer_map_.get(); } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 | 327 |
324 protected: | 328 protected: |
325 OperandContainer<LOperand*, R> results_; | 329 OperandContainer<LOperand*, R> results_; |
326 OperandContainer<LOperand*, I> inputs_; | 330 OperandContainer<LOperand*, I> inputs_; |
327 OperandContainer<LOperand*, T> temps_; | 331 OperandContainer<LOperand*, T> temps_; |
328 }; | 332 }; |
329 | 333 |
330 | 334 |
331 class LGap: public LTemplateInstruction<0, 0, 0> { | 335 class LGap: public LTemplateInstruction<0, 0, 0> { |
332 public: | 336 public: |
333 explicit LGap(HBasicBlock* block) | 337 explicit LGap(HBasicBlock* block) : block_(block) { |
334 : block_(block) { | |
335 parallel_moves_[BEFORE] = NULL; | 338 parallel_moves_[BEFORE] = NULL; |
336 parallel_moves_[START] = NULL; | 339 parallel_moves_[START] = NULL; |
337 parallel_moves_[END] = NULL; | 340 parallel_moves_[END] = NULL; |
338 parallel_moves_[AFTER] = NULL; | 341 parallel_moves_[AFTER] = NULL; |
339 } | 342 } |
340 | 343 |
341 DECLARE_CONCRETE_INSTRUCTION(Gap, "gap") | 344 // Can't use the DECLARE-macro here because of sub-classes. |
345 virtual bool IsGap() const { return true; } | |
342 virtual void PrintDataTo(StringStream* stream); | 346 virtual void PrintDataTo(StringStream* stream); |
347 static LGap* cast(LInstruction* instr) { | |
348 ASSERT(instr->IsGap()); | |
349 return reinterpret_cast<LGap*>(instr); | |
350 } | |
343 | 351 |
344 bool IsRedundant() const; | 352 bool IsRedundant() const; |
345 | 353 |
346 HBasicBlock* block() const { return block_; } | 354 HBasicBlock* block() const { return block_; } |
347 | 355 |
348 enum InnerPosition { | 356 enum InnerPosition { |
349 BEFORE, | 357 BEFORE, |
350 START, | 358 START, |
351 END, | 359 END, |
352 AFTER, | 360 AFTER, |
353 FIRST_INNER_POSITION = BEFORE, | 361 FIRST_INNER_POSITION = BEFORE, |
354 LAST_INNER_POSITION = AFTER | 362 LAST_INNER_POSITION = AFTER |
355 }; | 363 }; |
356 | 364 |
357 LParallelMove* GetOrCreateParallelMove(InnerPosition pos) { | 365 LParallelMove* GetOrCreateParallelMove(InnerPosition pos) { |
358 if (parallel_moves_[pos] == NULL) parallel_moves_[pos] = new LParallelMove; | 366 if (parallel_moves_[pos] == NULL) parallel_moves_[pos] = new LParallelMove; |
359 return parallel_moves_[pos]; | 367 return parallel_moves_[pos]; |
360 } | 368 } |
361 | 369 |
362 LParallelMove* GetParallelMove(InnerPosition pos) { | 370 LParallelMove* GetParallelMove(InnerPosition pos) { |
363 return parallel_moves_[pos]; | 371 return parallel_moves_[pos]; |
364 } | 372 } |
365 | 373 |
366 private: | 374 private: |
367 LParallelMove* parallel_moves_[LAST_INNER_POSITION + 1]; | 375 LParallelMove* parallel_moves_[LAST_INNER_POSITION + 1]; |
368 HBasicBlock* block_; | 376 HBasicBlock* block_; |
369 }; | 377 }; |
370 | 378 |
371 | 379 |
380 class LInstructionGap: public LGap { | |
381 public: | |
382 explicit LInstructionGap(HBasicBlock* block) : LGap(block) { } | |
383 | |
384 DECLARE_CONCRETE_INSTRUCTION(InstructionGap, "gap") | |
385 }; | |
386 | |
387 | |
388 class LLabel: public LGap { | |
389 public: | |
390 explicit LLabel(HBasicBlock* block) | |
391 : LGap(block), replacement_(NULL) { } | |
392 | |
393 DECLARE_CONCRETE_INSTRUCTION(Label, "label") | |
394 | |
395 virtual void PrintDataTo(StringStream* stream); | |
396 | |
397 int block_id() const { return block()->block_id(); } | |
398 bool is_loop_header() const { return block()->IsLoopHeader(); } | |
399 Label* label() { return &label_; } | |
400 LLabel* replacement() const { return replacement_; } | |
401 void set_replacement(LLabel* label) { replacement_ = label; } | |
402 bool HasReplacement() const { return replacement_ != NULL; } | |
403 | |
404 private: | |
405 Label label_; | |
406 LLabel* replacement_; | |
407 }; | |
408 | |
409 | |
372 class LGoto: public LTemplateInstruction<0, 0, 0> { | 410 class LGoto: public LTemplateInstruction<0, 0, 0> { |
373 public: | 411 public: |
374 LGoto(int block_id, bool include_stack_check = false) | 412 LGoto(int block_id, bool include_stack_check = false) |
375 : block_id_(block_id), include_stack_check_(include_stack_check) { } | 413 : block_id_(block_id), include_stack_check_(include_stack_check) { } |
376 | 414 |
377 DECLARE_CONCRETE_INSTRUCTION(Goto, "goto") | 415 DECLARE_CONCRETE_INSTRUCTION(Goto, "goto") |
378 virtual void PrintDataTo(StringStream* stream); | 416 virtual void PrintDataTo(StringStream* stream); |
379 virtual bool IsControl() const { return true; } | 417 virtual bool IsControl() const { return true; } |
380 | 418 |
381 int block_id() const { return block_id_; } | 419 int block_id() const { return block_id_; } |
(...skipping 20 matching lines...) Expand all Loading... | |
402 int gap_instructions_size_; | 440 int gap_instructions_size_; |
403 }; | 441 }; |
404 | 442 |
405 | 443 |
406 class LDeoptimize: public LTemplateInstruction<0, 0, 0> { | 444 class LDeoptimize: public LTemplateInstruction<0, 0, 0> { |
407 public: | 445 public: |
408 DECLARE_CONCRETE_INSTRUCTION(Deoptimize, "deoptimize") | 446 DECLARE_CONCRETE_INSTRUCTION(Deoptimize, "deoptimize") |
409 }; | 447 }; |
410 | 448 |
411 | 449 |
412 class LLabel: public LGap { | |
413 public: | |
414 explicit LLabel(HBasicBlock* block) | |
415 : LGap(block), replacement_(NULL) { } | |
416 | |
417 DECLARE_CONCRETE_INSTRUCTION(Label, "label") | |
418 | |
419 virtual void PrintDataTo(StringStream* stream); | |
420 | |
421 int block_id() const { return block()->block_id(); } | |
422 bool is_loop_header() const { return block()->IsLoopHeader(); } | |
423 Label* label() { return &label_; } | |
424 LLabel* replacement() const { return replacement_; } | |
425 void set_replacement(LLabel* label) { replacement_ = label; } | |
426 bool HasReplacement() const { return replacement_ != NULL; } | |
427 | |
428 private: | |
429 Label label_; | |
430 LLabel* replacement_; | |
431 }; | |
432 | |
433 | |
434 class LParameter: public LTemplateInstruction<1, 0, 0> { | 450 class LParameter: public LTemplateInstruction<1, 0, 0> { |
435 public: | 451 public: |
436 DECLARE_CONCRETE_INSTRUCTION(Parameter, "parameter") | 452 DECLARE_CONCRETE_INSTRUCTION(Parameter, "parameter") |
437 }; | 453 }; |
438 | 454 |
439 | 455 |
440 class LCallStub: public LTemplateInstruction<1, 1, 0> { | 456 class LCallStub: public LTemplateInstruction<1, 1, 0> { |
441 public: | 457 public: |
442 explicit LCallStub(LOperand* context) { | 458 explicit LCallStub(LOperand* context) { |
443 inputs_[0] = context; | 459 inputs_[0] = context; |
(...skipping 12 matching lines...) Expand all Loading... | |
456 | 472 |
457 class LUnknownOSRValue: public LTemplateInstruction<1, 0, 0> { | 473 class LUnknownOSRValue: public LTemplateInstruction<1, 0, 0> { |
458 public: | 474 public: |
459 DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown-osr-value") | 475 DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown-osr-value") |
460 }; | 476 }; |
461 | 477 |
462 | 478 |
463 template<int I, int T> | 479 template<int I, int T> |
464 class LControlInstruction: public LTemplateInstruction<0, I, T> { | 480 class LControlInstruction: public LTemplateInstruction<0, I, T> { |
465 public: | 481 public: |
466 DECLARE_INSTRUCTION(ControlInstruction) | |
467 virtual bool IsControl() const { return true; } | 482 virtual bool IsControl() const { return true; } |
468 | 483 |
469 int true_block_id() const { return true_block_id_; } | 484 int true_block_id() const { return true_block_id_; } |
470 int false_block_id() const { return false_block_id_; } | 485 int false_block_id() const { return false_block_id_; } |
471 void SetBranchTargets(int true_block_id, int false_block_id) { | 486 void SetBranchTargets(int true_block_id, int false_block_id) { |
472 true_block_id_ = true_block_id; | 487 true_block_id_ = true_block_id; |
473 false_block_id_ = false_block_id; | 488 false_block_id_ = false_block_id; |
474 } | 489 } |
475 | 490 |
476 private: | 491 private: |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1126 class LArithmeticD: public LTemplateInstruction<1, 2, 0> { | 1141 class LArithmeticD: public LTemplateInstruction<1, 2, 0> { |
1127 public: | 1142 public: |
1128 LArithmeticD(Token::Value op, LOperand* left, LOperand* right) | 1143 LArithmeticD(Token::Value op, LOperand* left, LOperand* right) |
1129 : op_(op) { | 1144 : op_(op) { |
1130 inputs_[0] = left; | 1145 inputs_[0] = left; |
1131 inputs_[1] = right; | 1146 inputs_[1] = right; |
1132 } | 1147 } |
1133 | 1148 |
1134 Token::Value op() const { return op_; } | 1149 Token::Value op() const { return op_; } |
1135 | 1150 |
1151 virtual Opcode opcode() const { return LInstruction::kArithmeticD; } | |
1136 virtual void CompileToNative(LCodeGen* generator); | 1152 virtual void CompileToNative(LCodeGen* generator); |
1137 virtual const char* Mnemonic() const; | 1153 virtual const char* Mnemonic() const; |
1138 | 1154 |
1139 private: | 1155 private: |
1140 Token::Value op_; | 1156 Token::Value op_; |
1141 }; | 1157 }; |
1142 | 1158 |
1143 | 1159 |
1144 class LArithmeticT: public LTemplateInstruction<1, 2, 0> { | 1160 class LArithmeticT: public LTemplateInstruction<1, 2, 0> { |
1145 public: | 1161 public: |
1146 LArithmeticT(Token::Value op, LOperand* left, LOperand* right) | 1162 LArithmeticT(Token::Value op, LOperand* left, LOperand* right) |
1147 : op_(op) { | 1163 : op_(op) { |
1148 inputs_[0] = left; | 1164 inputs_[0] = left; |
1149 inputs_[1] = right; | 1165 inputs_[1] = right; |
1150 } | 1166 } |
1151 | 1167 |
1168 virtual Opcode opcode() const { return LInstruction::kArithmeticT; } | |
1152 virtual void CompileToNative(LCodeGen* generator); | 1169 virtual void CompileToNative(LCodeGen* generator); |
1153 virtual const char* Mnemonic() const; | 1170 virtual const char* Mnemonic() const; |
1154 | 1171 |
1155 Token::Value op() const { return op_; } | 1172 Token::Value op() const { return op_; } |
1156 | 1173 |
1157 private: | 1174 private: |
1158 Token::Value op_; | 1175 Token::Value op_; |
1159 }; | 1176 }; |
1160 | 1177 |
1161 | 1178 |
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2261 int argument_count_; | 2278 int argument_count_; |
2262 LAllocator* allocator_; | 2279 LAllocator* allocator_; |
2263 int position_; | 2280 int position_; |
2264 LInstruction* instruction_pending_deoptimization_environment_; | 2281 LInstruction* instruction_pending_deoptimization_environment_; |
2265 int pending_deoptimization_ast_id_; | 2282 int pending_deoptimization_ast_id_; |
2266 | 2283 |
2267 DISALLOW_COPY_AND_ASSIGN(LChunkBuilder); | 2284 DISALLOW_COPY_AND_ASSIGN(LChunkBuilder); |
2268 }; | 2285 }; |
2269 | 2286 |
2270 #undef DECLARE_HYDROGEN_ACCESSOR | 2287 #undef DECLARE_HYDROGEN_ACCESSOR |
2271 #undef DECLARE_INSTRUCTION | |
2272 #undef DECLARE_CONCRETE_INSTRUCTION | 2288 #undef DECLARE_CONCRETE_INSTRUCTION |
2273 | 2289 |
2274 } } // namespace v8::internal | 2290 } } // namespace v8::internal |
2275 | 2291 |
2276 #endif // V8_IA32_LITHIUM_IA32_H_ | 2292 #endif // V8_IA32_LITHIUM_IA32_H_ |
OLD | NEW |