| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 27 matching lines...) Expand all Loading... |
| 38 #include "v8utils.h" | 38 #include "v8utils.h" |
| 39 | 39 |
| 40 namespace v8 { | 40 namespace v8 { |
| 41 namespace internal { | 41 namespace internal { |
| 42 | 42 |
| 43 // Forward declarations. | 43 // Forward declarations. |
| 44 class LDeferredCode; | 44 class LDeferredCode; |
| 45 class LGapNode; | 45 class LGapNode; |
| 46 class SafepointGenerator; | 46 class SafepointGenerator; |
| 47 | 47 |
| 48 class LCodeGen BASE_EMBEDDED { | 48 class LCodeGen V8_FINAL BASE_EMBEDDED { |
| 49 public: | 49 public: |
| 50 LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info) | 50 LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info) |
| 51 : zone_(info->zone()), | 51 : zone_(info->zone()), |
| 52 chunk_(static_cast<LPlatformChunk*>(chunk)), | 52 chunk_(static_cast<LPlatformChunk*>(chunk)), |
| 53 masm_(assembler), | 53 masm_(assembler), |
| 54 info_(info), | 54 info_(info), |
| 55 current_block_(-1), | 55 current_block_(-1), |
| 56 current_instruction_(-1), | 56 current_instruction_(-1), |
| 57 instructions_(chunk->instructions()), | 57 instructions_(chunk->instructions()), |
| 58 deoptimizations_(4, info->zone()), | 58 deoptimizations_(4, info->zone()), |
| 59 jump_table_(4, info->zone()), | 59 jump_table_(4, info->zone()), |
| 60 deoptimization_literals_(8, info->zone()), | 60 deoptimization_literals_(8, info->zone()), |
| 61 inlined_function_count_(0), | 61 inlined_function_count_(0), |
| 62 scope_(info->scope()), | 62 scope_(info->scope()), |
| 63 status_(UNUSED), | 63 status_(UNUSED), |
| 64 translations_(info->zone()), | 64 translations_(info->zone()), |
| 65 deferred_(8, info->zone()), | 65 deferred_(8, info->zone()), |
| 66 dynamic_frame_alignment_(false), | 66 dynamic_frame_alignment_(false), |
| 67 support_aligned_spilled_doubles_(false), | 67 support_aligned_spilled_doubles_(false), |
| 68 osr_pc_offset_(-1), | 68 osr_pc_offset_(-1), |
| 69 last_lazy_deopt_pc_(0), | 69 last_lazy_deopt_pc_(0), |
| 70 frame_is_built_(false), | 70 frame_is_built_(false), |
| 71 x87_stack_depth_(0), | 71 x87_stack_(assembler), |
| 72 safepoints_(info->zone()), | 72 safepoints_(info->zone()), |
| 73 resolver_(this), | 73 resolver_(this), |
| 74 expected_safepoint_kind_(Safepoint::kSimple), | 74 expected_safepoint_kind_(Safepoint::kSimple), |
| 75 old_position_(RelocInfo::kNoPosition) { | 75 old_position_(RelocInfo::kNoPosition) { |
| 76 PopulateDeoptimizationLiteralsWithInlinedFunctions(); | 76 PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Simple accessors. | 79 // Simple accessors. |
| 80 MacroAssembler* masm() const { return masm_; } | 80 MacroAssembler* masm() const { return masm_; } |
| 81 CompilationInfo* info() const { return info_; } | 81 CompilationInfo* info() const { return info_; } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } | 115 } |
| 116 double ToDouble(LConstantOperand* op) const; | 116 double ToDouble(LConstantOperand* op) const; |
| 117 | 117 |
| 118 // Support for non-sse2 (x87) floating point stack handling. | 118 // Support for non-sse2 (x87) floating point stack handling. |
| 119 // These functions maintain the mapping of physical stack registers to our | 119 // These functions maintain the mapping of physical stack registers to our |
| 120 // virtual registers between instructions. | 120 // virtual registers between instructions. |
| 121 enum X87OperandType { kX87DoubleOperand, kX87FloatOperand, kX87IntOperand }; | 121 enum X87OperandType { kX87DoubleOperand, kX87FloatOperand, kX87IntOperand }; |
| 122 | 122 |
| 123 void X87Mov(X87Register reg, Operand src, | 123 void X87Mov(X87Register reg, Operand src, |
| 124 X87OperandType operand = kX87DoubleOperand); | 124 X87OperandType operand = kX87DoubleOperand); |
| 125 void X87Mov(Operand src, X87Register reg); | 125 void X87Mov(Operand src, X87Register reg, |
| 126 X87OperandType operand = kX87DoubleOperand); |
| 126 | 127 |
| 127 void X87PrepareBinaryOp( | 128 void X87PrepareBinaryOp( |
| 128 X87Register left, X87Register right, X87Register result); | 129 X87Register left, X87Register right, X87Register result); |
| 129 | 130 |
| 130 void X87LoadForUsage(X87Register reg); | 131 void X87LoadForUsage(X87Register reg); |
| 131 void X87PrepareToWrite(X87Register reg); | 132 void X87PrepareToWrite(X87Register reg) { x87_stack_.PrepareToWrite(reg); } |
| 132 void X87CommitWrite(X87Register reg); | 133 void X87CommitWrite(X87Register reg) { x87_stack_.CommitWrite(reg); } |
| 134 |
| 135 void X87Fxch(X87Register reg, int other_slot = 0) { |
| 136 x87_stack_.Fxch(reg, other_slot); |
| 137 } |
| 138 |
| 139 bool X87StackEmpty() { |
| 140 return x87_stack_.depth() == 0; |
| 141 } |
| 133 | 142 |
| 134 Handle<Object> ToHandle(LConstantOperand* op) const; | 143 Handle<Object> ToHandle(LConstantOperand* op) const; |
| 135 | 144 |
| 136 // The operand denoting the second word (the one with a higher address) of | 145 // The operand denoting the second word (the one with a higher address) of |
| 137 // a double stack slot. | 146 // a double stack slot. |
| 138 Operand HighOperand(LOperand* op); | 147 Operand HighOperand(LOperand* op); |
| 139 | 148 |
| 140 // Try to generate code for the entire chunk, but it may fail if the | 149 // Try to generate code for the entire chunk, but it may fail if the |
| 141 // chunk contains constructs we cannot handle. Returns true if the | 150 // chunk contains constructs we cannot handle. Returns true if the |
| 142 // code generation attempt succeeded. | 151 // code generation attempt succeeded. |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 int arguments, | 331 int arguments, |
| 323 Safepoint::DeoptMode mode); | 332 Safepoint::DeoptMode mode); |
| 324 void RecordPosition(int position); | 333 void RecordPosition(int position); |
| 325 | 334 |
| 326 void RecordAndUpdatePosition(int position); | 335 void RecordAndUpdatePosition(int position); |
| 327 | 336 |
| 328 static Condition TokenToCondition(Token::Value op, bool is_unsigned); | 337 static Condition TokenToCondition(Token::Value op, bool is_unsigned); |
| 329 void EmitGoto(int block); | 338 void EmitGoto(int block); |
| 330 template<class InstrType> | 339 template<class InstrType> |
| 331 void EmitBranch(InstrType instr, Condition cc); | 340 void EmitBranch(InstrType instr, Condition cc); |
| 341 template<class InstrType> |
| 342 void EmitFalseBranch(InstrType instr, Condition cc); |
| 332 void EmitNumberUntagD( | 343 void EmitNumberUntagD( |
| 333 Register input, | 344 Register input, |
| 334 Register temp, | 345 Register temp, |
| 335 XMMRegister result, | 346 XMMRegister result, |
| 336 bool allow_undefined_as_nan, | 347 bool allow_undefined_as_nan, |
| 337 bool deoptimize_on_minus_zero, | 348 bool deoptimize_on_minus_zero, |
| 338 LEnvironment* env, | 349 LEnvironment* env, |
| 339 NumberUntagDMode mode = NUMBER_CANDIDATE_IS_ANY_TAGGED); | 350 NumberUntagDMode mode = NUMBER_CANDIDATE_IS_ANY_TAGGED); |
| 340 | 351 |
| 341 void EmitNumberUntagDNoSSE2( | 352 void EmitNumberUntagDNoSSE2( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 368 // true and false label should be made, to optimize fallthrough. | 379 // true and false label should be made, to optimize fallthrough. |
| 369 Condition EmitIsString(Register input, | 380 Condition EmitIsString(Register input, |
| 370 Register temp1, | 381 Register temp1, |
| 371 Label* is_not_string, | 382 Label* is_not_string, |
| 372 SmiCheck check_needed); | 383 SmiCheck check_needed); |
| 373 | 384 |
| 374 // Emits optimized code for %_IsConstructCall(). | 385 // Emits optimized code for %_IsConstructCall(). |
| 375 // Caller should branch on equal condition. | 386 // Caller should branch on equal condition. |
| 376 void EmitIsConstructCall(Register temp); | 387 void EmitIsConstructCall(Register temp); |
| 377 | 388 |
| 378 void EmitLoadFieldOrConstant(Register result, | |
| 379 Register object, | |
| 380 Handle<Map> type, | |
| 381 Handle<String> name, | |
| 382 LEnvironment* env); | |
| 383 | |
| 384 // Emits optimized code to deep-copy the contents of statically known | 389 // Emits optimized code to deep-copy the contents of statically known |
| 385 // object graphs (e.g. object literal boilerplate). | 390 // object graphs (e.g. object literal boilerplate). |
| 386 void EmitDeepCopy(Handle<JSObject> object, | 391 void EmitDeepCopy(Handle<JSObject> object, |
| 387 Register result, | 392 Register result, |
| 388 Register source, | 393 Register source, |
| 389 int* offset, | 394 int* offset, |
| 390 AllocationSiteMode mode); | 395 AllocationSiteMode mode); |
| 391 | 396 |
| 392 void EnsureSpaceForLazyDeopt(); | 397 void EnsureSpaceForLazyDeopt(); |
| 393 void DoLoadKeyedExternalArray(LLoadKeyed* instr); | 398 void DoLoadKeyedExternalArray(LLoadKeyed* instr); |
| 394 void DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr); | 399 void DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr); |
| 395 void DoLoadKeyedFixedArray(LLoadKeyed* instr); | 400 void DoLoadKeyedFixedArray(LLoadKeyed* instr); |
| 396 void DoStoreKeyedExternalArray(LStoreKeyed* instr); | 401 void DoStoreKeyedExternalArray(LStoreKeyed* instr); |
| 397 void DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr); | 402 void DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr); |
| 398 void DoStoreKeyedFixedArray(LStoreKeyed* instr); | 403 void DoStoreKeyedFixedArray(LStoreKeyed* instr); |
| 399 | 404 |
| 400 void EmitReturn(LReturn* instr, bool dynamic_frame_alignment); | 405 void EmitReturn(LReturn* instr, bool dynamic_frame_alignment); |
| 401 | 406 |
| 402 // Emits code for pushing either a tagged constant, a (non-double) | 407 // Emits code for pushing either a tagged constant, a (non-double) |
| 403 // register, or a stack slot operand. | 408 // register, or a stack slot operand. |
| 404 void EmitPushTaggedOperand(LOperand* operand); | 409 void EmitPushTaggedOperand(LOperand* operand); |
| 405 | 410 |
| 406 void X87Fxch(X87Register reg, int other_slot = 0); | |
| 407 void X87Fld(Operand src, X87OperandType opts); | 411 void X87Fld(Operand src, X87OperandType opts); |
| 408 void X87Free(X87Register reg); | |
| 409 | 412 |
| 410 void FlushX87StackIfNecessary(LInstruction* instr); | |
| 411 void EmitFlushX87ForDeopt(); | 413 void EmitFlushX87ForDeopt(); |
| 412 bool X87StackContains(X87Register reg); | 414 void FlushX87StackIfNecessary(LInstruction* instr) { |
| 413 int X87ArrayIndex(X87Register reg); | 415 x87_stack_.FlushIfNecessary(instr, this); |
| 414 int x87_st2idx(int pos); | 416 } |
| 417 friend class LGapResolver; |
| 415 | 418 |
| 416 #ifdef _MSC_VER | 419 #ifdef _MSC_VER |
| 417 // On windows, you may not access the stack more than one page below | 420 // On windows, you may not access the stack more than one page below |
| 418 // the most recently mapped page. To make the allocated area randomly | 421 // the most recently mapped page. To make the allocated area randomly |
| 419 // accessible, we write an arbitrary value to each page in range | 422 // accessible, we write an arbitrary value to each page in range |
| 420 // esp + offset - page_size .. esp in turn. | 423 // esp + offset - page_size .. esp in turn. |
| 421 void MakeSureStackPagesMapped(int offset); | 424 void MakeSureStackPagesMapped(int offset); |
| 422 #endif | 425 #endif |
| 423 | 426 |
| 424 Zone* zone_; | 427 Zone* zone_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 435 int inlined_function_count_; | 438 int inlined_function_count_; |
| 436 Scope* const scope_; | 439 Scope* const scope_; |
| 437 Status status_; | 440 Status status_; |
| 438 TranslationBuffer translations_; | 441 TranslationBuffer translations_; |
| 439 ZoneList<LDeferredCode*> deferred_; | 442 ZoneList<LDeferredCode*> deferred_; |
| 440 bool dynamic_frame_alignment_; | 443 bool dynamic_frame_alignment_; |
| 441 bool support_aligned_spilled_doubles_; | 444 bool support_aligned_spilled_doubles_; |
| 442 int osr_pc_offset_; | 445 int osr_pc_offset_; |
| 443 int last_lazy_deopt_pc_; | 446 int last_lazy_deopt_pc_; |
| 444 bool frame_is_built_; | 447 bool frame_is_built_; |
| 445 X87Register x87_stack_[X87Register::kNumAllocatableRegisters]; | 448 |
| 446 int x87_stack_depth_; | 449 class X87Stack { |
| 450 public: |
| 451 explicit X87Stack(MacroAssembler* masm) : stack_depth_(0), masm_(masm) { } |
| 452 explicit X87Stack(const X87Stack& other) |
| 453 : stack_depth_(0), masm_(other.masm_) { |
| 454 stack_depth_ = other.stack_depth_; |
| 455 for (int i = 0; i < stack_depth_; i++) { |
| 456 stack_[i] = other.stack_[i]; |
| 457 } |
| 458 } |
| 459 bool operator==(const X87Stack& other) const { |
| 460 if (stack_depth_ != other.stack_depth_) return false; |
| 461 for (int i = 0; i < stack_depth_; i++) { |
| 462 if (!stack_[i].is(other.stack_[i])) return false; |
| 463 } |
| 464 return true; |
| 465 } |
| 466 bool Contains(X87Register reg); |
| 467 void Fxch(X87Register reg, int other_slot = 0); |
| 468 void Free(X87Register reg); |
| 469 void PrepareToWrite(X87Register reg); |
| 470 void CommitWrite(X87Register reg); |
| 471 void FlushIfNecessary(LInstruction* instr, LCodeGen* cgen); |
| 472 int depth() const { return stack_depth_; } |
| 473 void pop() { stack_depth_--; } |
| 474 void push(X87Register reg) { |
| 475 ASSERT(stack_depth_ < X87Register::kNumAllocatableRegisters); |
| 476 stack_[stack_depth_] = reg; |
| 477 stack_depth_++; |
| 478 } |
| 479 |
| 480 MacroAssembler* masm() const { return masm_; } |
| 481 |
| 482 private: |
| 483 int ArrayIndex(X87Register reg); |
| 484 int st2idx(int pos); |
| 485 X87Register stack_[X87Register::kNumAllocatableRegisters]; |
| 486 int stack_depth_; |
| 487 MacroAssembler* const masm_; |
| 488 }; |
| 489 X87Stack x87_stack_; |
| 447 | 490 |
| 448 // Builder that keeps track of safepoints in the code. The table | 491 // Builder that keeps track of safepoints in the code. The table |
| 449 // itself is emitted at the end of the generated code. | 492 // itself is emitted at the end of the generated code. |
| 450 SafepointTableBuilder safepoints_; | 493 SafepointTableBuilder safepoints_; |
| 451 | 494 |
| 452 // Compiler from a set of parallel moves to a sequential list of moves. | 495 // Compiler from a set of parallel moves to a sequential list of moves. |
| 453 LGapResolver resolver_; | 496 LGapResolver resolver_; |
| 454 | 497 |
| 455 Safepoint::Kind expected_safepoint_kind_; | 498 Safepoint::Kind expected_safepoint_kind_; |
| 456 | 499 |
| 457 int old_position_; | 500 int old_position_; |
| 458 | 501 |
| 459 class PushSafepointRegistersScope BASE_EMBEDDED { | 502 class PushSafepointRegistersScope V8_FINAL BASE_EMBEDDED { |
| 460 public: | 503 public: |
| 461 explicit PushSafepointRegistersScope(LCodeGen* codegen) | 504 explicit PushSafepointRegistersScope(LCodeGen* codegen) |
| 462 : codegen_(codegen) { | 505 : codegen_(codegen) { |
| 463 ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kSimple); | 506 ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kSimple); |
| 464 codegen_->masm_->PushSafepointRegisters(); | 507 codegen_->masm_->PushSafepointRegisters(); |
| 465 codegen_->expected_safepoint_kind_ = Safepoint::kWithRegisters; | 508 codegen_->expected_safepoint_kind_ = Safepoint::kWithRegisters; |
| 466 ASSERT(codegen_->info()->is_calling()); | 509 ASSERT(codegen_->info()->is_calling()); |
| 467 } | 510 } |
| 468 | 511 |
| 469 ~PushSafepointRegistersScope() { | 512 ~PushSafepointRegistersScope() { |
| 470 ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kWithRegisters); | 513 ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kWithRegisters); |
| 471 codegen_->masm_->PopSafepointRegisters(); | 514 codegen_->masm_->PopSafepointRegisters(); |
| 472 codegen_->expected_safepoint_kind_ = Safepoint::kSimple; | 515 codegen_->expected_safepoint_kind_ = Safepoint::kSimple; |
| 473 } | 516 } |
| 474 | 517 |
| 475 private: | 518 private: |
| 476 LCodeGen* codegen_; | 519 LCodeGen* codegen_; |
| 477 }; | 520 }; |
| 478 | 521 |
| 479 friend class LDeferredCode; | 522 friend class LDeferredCode; |
| 480 friend class LEnvironment; | 523 friend class LEnvironment; |
| 481 friend class SafepointGenerator; | 524 friend class SafepointGenerator; |
| 482 DISALLOW_COPY_AND_ASSIGN(LCodeGen); | 525 DISALLOW_COPY_AND_ASSIGN(LCodeGen); |
| 483 }; | 526 }; |
| 484 | 527 |
| 485 | 528 |
| 486 class LDeferredCode: public ZoneObject { | 529 class LDeferredCode : public ZoneObject { |
| 487 public: | 530 public: |
| 488 explicit LDeferredCode(LCodeGen* codegen) | 531 explicit LDeferredCode(LCodeGen* codegen) |
| 489 : codegen_(codegen), | 532 : codegen_(codegen), |
| 490 external_exit_(NULL), | 533 external_exit_(NULL), |
| 491 instruction_index_(codegen->current_instruction_) { | 534 instruction_index_(codegen->current_instruction_) { |
| 492 codegen->AddDeferredCode(this); | 535 codegen->AddDeferredCode(this); |
| 493 } | 536 } |
| 494 | 537 |
| 495 virtual ~LDeferredCode() { } | 538 virtual ~LDeferredCode() {} |
| 496 virtual void Generate() = 0; | 539 virtual void Generate() = 0; |
| 497 virtual LInstruction* instr() = 0; | 540 virtual LInstruction* instr() = 0; |
| 498 | 541 |
| 499 void SetExit(Label* exit) { external_exit_ = exit; } | 542 void SetExit(Label* exit) { external_exit_ = exit; } |
| 500 Label* entry() { return &entry_; } | 543 Label* entry() { return &entry_; } |
| 501 Label* exit() { return external_exit_ != NULL ? external_exit_ : &exit_; } | 544 Label* exit() { return external_exit_ != NULL ? external_exit_ : &exit_; } |
| 502 int instruction_index() const { return instruction_index_; } | 545 int instruction_index() const { return instruction_index_; } |
| 503 | 546 |
| 504 protected: | 547 protected: |
| 505 LCodeGen* codegen() const { return codegen_; } | 548 LCodeGen* codegen() const { return codegen_; } |
| 506 MacroAssembler* masm() const { return codegen_->masm(); } | 549 MacroAssembler* masm() const { return codegen_->masm(); } |
| 507 | 550 |
| 508 private: | 551 private: |
| 509 LCodeGen* codegen_; | 552 LCodeGen* codegen_; |
| 510 Label entry_; | 553 Label entry_; |
| 511 Label exit_; | 554 Label exit_; |
| 512 Label* external_exit_; | 555 Label* external_exit_; |
| 513 int instruction_index_; | 556 int instruction_index_; |
| 514 }; | 557 }; |
| 515 | 558 |
| 516 } } // namespace v8::internal | 559 } } // namespace v8::internal |
| 517 | 560 |
| 518 #endif // V8_IA32_LITHIUM_CODEGEN_IA32_H_ | 561 #endif // V8_IA32_LITHIUM_CODEGEN_IA32_H_ |
| OLD | NEW |