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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 public: | 48 public: |
49 LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info) | 49 LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info) |
50 : zone_(info->zone()), | 50 : zone_(info->zone()), |
51 chunk_(static_cast<LPlatformChunk*>(chunk)), | 51 chunk_(static_cast<LPlatformChunk*>(chunk)), |
52 masm_(assembler), | 52 masm_(assembler), |
53 info_(info), | 53 info_(info), |
54 current_block_(-1), | 54 current_block_(-1), |
55 current_instruction_(-1), | 55 current_instruction_(-1), |
56 instructions_(chunk->instructions()), | 56 instructions_(chunk->instructions()), |
57 deoptimizations_(4, info->zone()), | 57 deoptimizations_(4, info->zone()), |
| 58 jump_table_(4, info->zone()), |
58 deoptimization_literals_(8, info->zone()), | 59 deoptimization_literals_(8, info->zone()), |
59 inlined_function_count_(0), | 60 inlined_function_count_(0), |
60 scope_(info->scope()), | 61 scope_(info->scope()), |
61 status_(UNUSED), | 62 status_(UNUSED), |
62 translations_(info->zone()), | 63 translations_(info->zone()), |
63 deferred_(8, info->zone()), | 64 deferred_(8, info->zone()), |
64 dynamic_frame_alignment_(false), | 65 dynamic_frame_alignment_(false), |
65 osr_pc_offset_(-1), | 66 osr_pc_offset_(-1), |
66 last_lazy_deopt_pc_(0), | 67 last_lazy_deopt_pc_(0), |
| 68 frame_is_built_(false), |
67 safepoints_(info->zone()), | 69 safepoints_(info->zone()), |
68 resolver_(this), | 70 resolver_(this), |
69 expected_safepoint_kind_(Safepoint::kSimple) { | 71 expected_safepoint_kind_(Safepoint::kSimple) { |
70 PopulateDeoptimizationLiteralsWithInlinedFunctions(); | 72 PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
71 } | 73 } |
72 | 74 |
73 // Simple accessors. | 75 // Simple accessors. |
74 MacroAssembler* masm() const { return masm_; } | 76 MacroAssembler* masm() const { return masm_; } |
75 CompilationInfo* info() const { return info_; } | 77 CompilationInfo* info() const { return info_; } |
76 Isolate* isolate() const { return info_->isolate(); } | 78 Isolate* isolate() const { return info_->isolate(); } |
77 Factory* factory() const { return isolate()->factory(); } | 79 Factory* factory() const { return isolate()->factory(); } |
78 Heap* heap() const { return isolate()->heap(); } | 80 Heap* heap() const { return isolate()->heap(); } |
79 Zone* zone() const { return zone_; } | 81 Zone* zone() const { return zone_; } |
80 | 82 |
| 83 bool NeedsEagerFrame() const { |
| 84 return GetStackSlotCount() > 0 || |
| 85 info()->is_non_deferred_calling() || |
| 86 !info()->IsStub(); |
| 87 } |
| 88 bool NeedsDeferredFrame() const { |
| 89 return !NeedsEagerFrame() && info()->is_deferred_calling(); |
| 90 } |
| 91 |
81 // Support for converting LOperands to assembler types. | 92 // Support for converting LOperands to assembler types. |
82 Operand ToOperand(LOperand* op) const; | 93 Operand ToOperand(LOperand* op) const; |
83 Register ToRegister(LOperand* op) const; | 94 Register ToRegister(LOperand* op) const; |
84 XMMRegister ToDoubleRegister(LOperand* op) const; | 95 XMMRegister ToDoubleRegister(LOperand* op) const; |
| 96 bool IsX87TopOfStack(LOperand* op) const; |
85 | 97 |
86 bool IsInteger32(LConstantOperand* op) const; | 98 bool IsInteger32(LConstantOperand* op) const; |
87 Immediate ToInteger32Immediate(LOperand* op) const { | 99 Immediate ToInteger32Immediate(LOperand* op) const { |
88 return Immediate(ToInteger32(LConstantOperand::cast(op))); | 100 return Immediate(ToInteger32(LConstantOperand::cast(op))); |
89 } | 101 } |
90 | 102 |
91 Handle<Object> ToHandle(LConstantOperand* op) const; | 103 Handle<Object> ToHandle(LConstantOperand* op) const; |
92 | 104 |
| 105 // A utility for instructions that return floating point values on X87. |
| 106 void HandleX87FPReturnValue(LInstruction* instr); |
| 107 |
93 // The operand denoting the second word (the one with a higher address) of | 108 // The operand denoting the second word (the one with a higher address) of |
94 // a double stack slot. | 109 // a double stack slot. |
95 Operand HighOperand(LOperand* op); | 110 Operand HighOperand(LOperand* op); |
96 | 111 |
97 // Try to generate code for the entire chunk, but it may fail if the | 112 // Try to generate code for the entire chunk, but it may fail if the |
98 // chunk contains constructs we cannot handle. Returns true if the | 113 // chunk contains constructs we cannot handle. Returns true if the |
99 // code generation attempt succeeded. | 114 // code generation attempt succeeded. |
100 bool GenerateCode(); | 115 bool GenerateCode(); |
101 | 116 |
102 // Finish the code by setting stack height, safepoint, and bailout | 117 // Finish the code by setting stack height, safepoint, and bailout |
(...skipping 12 matching lines...) Expand all Loading... |
115 void DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr); | 130 void DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr); |
116 void DoDeferredStackCheck(LStackCheck* instr); | 131 void DoDeferredStackCheck(LStackCheck* instr); |
117 void DoDeferredRandom(LRandom* instr); | 132 void DoDeferredRandom(LRandom* instr); |
118 void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); | 133 void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); |
119 void DoDeferredStringCharFromCode(LStringCharFromCode* instr); | 134 void DoDeferredStringCharFromCode(LStringCharFromCode* instr); |
120 void DoDeferredAllocateObject(LAllocateObject* instr); | 135 void DoDeferredAllocateObject(LAllocateObject* instr); |
121 void DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, | 136 void DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
122 Label* map_check); | 137 Label* map_check); |
123 | 138 |
124 void DoCheckMapCommon(Register reg, Handle<Map> map, | 139 void DoCheckMapCommon(Register reg, Handle<Map> map, |
125 CompareMapMode mode, LEnvironment* env); | 140 CompareMapMode mode, LInstruction* instr); |
126 | 141 |
127 // Parallel move support. | 142 // Parallel move support. |
128 void DoParallelMove(LParallelMove* move); | 143 void DoParallelMove(LParallelMove* move); |
129 void DoGap(LGap* instr); | 144 void DoGap(LGap* instr); |
130 | 145 |
131 // Emit frame translation commands for an environment. | 146 // Emit frame translation commands for an environment. |
132 void WriteTranslation(LEnvironment* environment, | 147 void WriteTranslation(LEnvironment* environment, |
133 Translation* translation, | 148 Translation* translation, |
134 int* arguments_index, | 149 int* arguments_index, |
135 int* arguments_count); | 150 int* arguments_count); |
(...skipping 29 matching lines...) Expand all Loading... |
165 int GetNextEmittedBlock(int block); | 180 int GetNextEmittedBlock(int block); |
166 | 181 |
167 void EmitClassOfTest(Label* if_true, | 182 void EmitClassOfTest(Label* if_true, |
168 Label* if_false, | 183 Label* if_false, |
169 Handle<String> class_name, | 184 Handle<String> class_name, |
170 Register input, | 185 Register input, |
171 Register temporary, | 186 Register temporary, |
172 Register temporary2); | 187 Register temporary2); |
173 | 188 |
174 int GetStackSlotCount() const { return chunk()->spill_slot_count(); } | 189 int GetStackSlotCount() const { return chunk()->spill_slot_count(); } |
175 int GetParameterCount() const { return scope()->num_parameters(); } | 190 int GetParameterCount() const { return info()->num_parameters(); } |
176 | 191 |
177 void Abort(const char* reason); | 192 void Abort(const char* reason); |
178 void Comment(const char* format, ...); | 193 void Comment(const char* format, ...); |
179 | 194 |
180 void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code, zone()); } | 195 void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code, zone()); } |
181 | 196 |
182 // Code generation passes. Returns true if code generation should | 197 // Code generation passes. Returns true if code generation should |
183 // continue. | 198 // continue. |
184 bool GeneratePrologue(); | 199 bool GeneratePrologue(); |
185 bool GenerateBody(); | 200 bool GenerateBody(); |
186 bool GenerateDeferredCode(); | 201 bool GenerateDeferredCode(); |
187 // Pad the reloc info to ensure that we have enough space to patch during | 202 bool GenerateJumpTable(); |
188 // deoptimization. | |
189 bool GenerateRelocPadding(); | |
190 bool GenerateSafepointTable(); | 203 bool GenerateSafepointTable(); |
191 | 204 |
192 enum SafepointMode { | 205 enum SafepointMode { |
193 RECORD_SIMPLE_SAFEPOINT, | 206 RECORD_SIMPLE_SAFEPOINT, |
194 RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS | 207 RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS |
195 }; | 208 }; |
196 | 209 |
197 void CallCode(Handle<Code> code, | 210 void CallCode(Handle<Code> code, |
198 RelocInfo::Mode mode, | 211 RelocInfo::Mode mode, |
199 LInstruction* instr); | 212 LInstruction* instr); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 362 |
350 // Emits code for pushing either a tagged constant, a (non-double) | 363 // Emits code for pushing either a tagged constant, a (non-double) |
351 // register, or a stack slot operand. | 364 // register, or a stack slot operand. |
352 void EmitPushTaggedOperand(LOperand* operand); | 365 void EmitPushTaggedOperand(LOperand* operand); |
353 | 366 |
354 Zone* zone_; | 367 Zone* zone_; |
355 LPlatformChunk* const chunk_; | 368 LPlatformChunk* const chunk_; |
356 MacroAssembler* const masm_; | 369 MacroAssembler* const masm_; |
357 CompilationInfo* const info_; | 370 CompilationInfo* const info_; |
358 | 371 |
| 372 struct JumpTableEntry { |
| 373 inline JumpTableEntry(Address entry, bool frame, bool is_lazy) |
| 374 : label(), |
| 375 address(entry), |
| 376 needs_frame(frame), |
| 377 is_lazy_deopt(is_lazy) { } |
| 378 Label label; |
| 379 Address address; |
| 380 bool needs_frame; |
| 381 bool is_lazy_deopt; |
| 382 }; |
| 383 |
359 int current_block_; | 384 int current_block_; |
360 int current_instruction_; | 385 int current_instruction_; |
361 const ZoneList<LInstruction*>* instructions_; | 386 const ZoneList<LInstruction*>* instructions_; |
362 ZoneList<LEnvironment*> deoptimizations_; | 387 ZoneList<LEnvironment*> deoptimizations_; |
| 388 ZoneList<JumpTableEntry> jump_table_; |
363 ZoneList<Handle<Object> > deoptimization_literals_; | 389 ZoneList<Handle<Object> > deoptimization_literals_; |
364 int inlined_function_count_; | 390 int inlined_function_count_; |
365 Scope* const scope_; | 391 Scope* const scope_; |
366 Status status_; | 392 Status status_; |
367 TranslationBuffer translations_; | 393 TranslationBuffer translations_; |
368 ZoneList<LDeferredCode*> deferred_; | 394 ZoneList<LDeferredCode*> deferred_; |
369 bool dynamic_frame_alignment_; | 395 bool dynamic_frame_alignment_; |
370 int osr_pc_offset_; | 396 int osr_pc_offset_; |
371 int last_lazy_deopt_pc_; | 397 int last_lazy_deopt_pc_; |
| 398 bool frame_is_built_; |
372 | 399 |
373 // Builder that keeps track of safepoints in the code. The table | 400 // Builder that keeps track of safepoints in the code. The table |
374 // itself is emitted at the end of the generated code. | 401 // itself is emitted at the end of the generated code. |
375 SafepointTableBuilder safepoints_; | 402 SafepointTableBuilder safepoints_; |
376 | 403 |
377 // Compiler from a set of parallel moves to a sequential list of moves. | 404 // Compiler from a set of parallel moves to a sequential list of moves. |
378 LGapResolver resolver_; | 405 LGapResolver resolver_; |
379 | 406 |
380 Safepoint::Kind expected_safepoint_kind_; | 407 Safepoint::Kind expected_safepoint_kind_; |
381 | 408 |
382 class PushSafepointRegistersScope BASE_EMBEDDED { | 409 class PushSafepointRegistersScope BASE_EMBEDDED { |
383 public: | 410 public: |
384 explicit PushSafepointRegistersScope(LCodeGen* codegen) | 411 explicit PushSafepointRegistersScope(LCodeGen* codegen) |
385 : codegen_(codegen) { | 412 : codegen_(codegen) { |
386 ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kSimple); | 413 ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kSimple); |
387 codegen_->masm_->PushSafepointRegisters(); | 414 codegen_->masm_->PushSafepointRegisters(); |
388 codegen_->expected_safepoint_kind_ = Safepoint::kWithRegisters; | 415 codegen_->expected_safepoint_kind_ = Safepoint::kWithRegisters; |
| 416 ASSERT(codegen_->info()->is_calling()); |
389 } | 417 } |
390 | 418 |
391 ~PushSafepointRegistersScope() { | 419 ~PushSafepointRegistersScope() { |
392 ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kWithRegisters); | 420 ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kWithRegisters); |
393 codegen_->masm_->PopSafepointRegisters(); | 421 codegen_->masm_->PopSafepointRegisters(); |
394 codegen_->expected_safepoint_kind_ = Safepoint::kSimple; | 422 codegen_->expected_safepoint_kind_ = Safepoint::kSimple; |
395 } | 423 } |
396 | 424 |
397 private: | 425 private: |
398 LCodeGen* codegen_; | 426 LCodeGen* codegen_; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 LCodeGen* codegen_; | 459 LCodeGen* codegen_; |
432 Label entry_; | 460 Label entry_; |
433 Label exit_; | 461 Label exit_; |
434 Label* external_exit_; | 462 Label* external_exit_; |
435 int instruction_index_; | 463 int instruction_index_; |
436 }; | 464 }; |
437 | 465 |
438 } } // namespace v8::internal | 466 } } // namespace v8::internal |
439 | 467 |
440 #endif // V8_IA32_LITHIUM_CODEGEN_IA32_H_ | 468 #endif // V8_IA32_LITHIUM_CODEGEN_IA32_H_ |
OLD | NEW |