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