erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_IA32_LITHIUM_CODEGEN_IA32_H_ |
| 29 | #define V8_IA32_LITHIUM_CODEGEN_IA32_H_ |
| 30 | |
| 31 | #include "ia32/lithium-ia32.h" |
| 32 | |
| 33 | #include "checks.h" |
| 34 | #include "deoptimizer.h" |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 35 | #include "ia32/lithium-gap-resolver-ia32.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 36 | #include "safepoint-table.h" |
| 37 | #include "scopes.h" |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 38 | #include "v8utils.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 39 | |
| 40 | namespace v8 { |
| 41 | namespace internal { |
| 42 | |
| 43 | // Forward declarations. |
| 44 | class LDeferredCode; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 45 | class LGapNode; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 46 | class SafepointGenerator; |
| 47 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 48 | class LCodeGen BASE_EMBEDDED { |
| 49 | public: |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 50 | LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info) |
| 51 | : zone_(info->zone()), |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 52 | chunk_(static_cast<LPlatformChunk*>(chunk)), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 53 | masm_(assembler), |
| 54 | info_(info), |
| 55 | current_block_(-1), |
| 56 | current_instruction_(-1), |
| 57 | instructions_(chunk->instructions()), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 58 | deoptimizations_(4, info->zone()), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 59 | jump_table_(4, info->zone()), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 60 | deoptimization_literals_(8, info->zone()), |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 61 | prototype_maps_(0, info->zone()), |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 62 | transition_maps_(0, info->zone()), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 63 | inlined_function_count_(0), |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 64 | scope_(info->scope()), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 65 | status_(UNUSED), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 66 | translations_(info->zone()), |
| 67 | deferred_(8, info->zone()), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 68 | dynamic_frame_alignment_(false), |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 69 | support_aligned_spilled_doubles_(false), |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 70 | osr_pc_offset_(-1), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 71 | last_lazy_deopt_pc_(0), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 72 | frame_is_built_(false), |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 73 | x87_stack_depth_(0), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 74 | safepoints_(info->zone()), |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 75 | resolver_(this), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 76 | expected_safepoint_kind_(Safepoint::kSimple) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 77 | PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 78 | } |
| 79 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 80 | // Simple accessors. |
| 81 | MacroAssembler* masm() const { return masm_; } |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 82 | CompilationInfo* info() const { return info_; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 83 | Isolate* isolate() const { return info_->isolate(); } |
| 84 | Factory* factory() const { return isolate()->factory(); } |
| 85 | Heap* heap() const { return isolate()->heap(); } |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 86 | Zone* zone() const { return zone_; } |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 87 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 88 | // TODO(svenpanne) Use this consistently. |
| 89 | int LookupDestination(int block_id) const { |
| 90 | return chunk()->LookupDestination(block_id); |
| 91 | } |
| 92 | |
| 93 | bool IsNextEmittedBlock(int block_id) const { |
| 94 | return LookupDestination(block_id) == GetNextEmittedBlock(); |
| 95 | } |
| 96 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 97 | bool NeedsEagerFrame() const { |
| 98 | return GetStackSlotCount() > 0 || |
| 99 | info()->is_non_deferred_calling() || |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 100 | !info()->IsStub() || |
| 101 | info()->requires_frame(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 102 | } |
| 103 | bool NeedsDeferredFrame() const { |
| 104 | return !NeedsEagerFrame() && info()->is_deferred_calling(); |
| 105 | } |
| 106 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 107 | // Support for converting LOperands to assembler types. |
| 108 | Operand ToOperand(LOperand* op) const; |
| 109 | Register ToRegister(LOperand* op) const; |
| 110 | XMMRegister ToDoubleRegister(LOperand* op) const; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 111 | bool IsX87TopOfStack(LOperand* op) const; |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 112 | |
| 113 | bool IsInteger32(LConstantOperand* op) const; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 114 | bool IsSmi(LConstantOperand* op) const; |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 115 | Immediate ToInteger32Immediate(LOperand* op) const { |
| 116 | return Immediate(ToInteger32(LConstantOperand::cast(op))); |
| 117 | } |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 118 | Immediate ToSmiImmediate(LOperand* op) const { |
| 119 | return Immediate(Smi::FromInt(ToInteger32(LConstantOperand::cast(op)))); |
| 120 | } |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 121 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 122 | // Support for non-sse2 (x87) floating point stack handling. |
| 123 | // These functions maintain the depth of the stack (either 0 or 1) |
| 124 | void PushX87DoubleOperand(Operand src); |
| 125 | void PushX87FloatOperand(Operand src); |
| 126 | void ReadX87Operand(Operand dst); |
| 127 | bool X87StackNonEmpty() const { return x87_stack_depth_ > 0; } |
| 128 | void PopX87(); |
| 129 | void CurrentInstructionReturnsX87Result(); |
| 130 | void FlushX87StackIfNecessary(LInstruction* instr); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 131 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 132 | Handle<Object> ToHandle(LConstantOperand* op) const; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 133 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 134 | // The operand denoting the second word (the one with a higher address) of |
| 135 | // a double stack slot. |
| 136 | Operand HighOperand(LOperand* op); |
| 137 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 138 | // Try to generate code for the entire chunk, but it may fail if the |
| 139 | // chunk contains constructs we cannot handle. Returns true if the |
| 140 | // code generation attempt succeeded. |
| 141 | bool GenerateCode(); |
| 142 | |
| 143 | // Finish the code by setting stack height, safepoint, and bailout |
| 144 | // information on it. |
| 145 | void FinishCode(Handle<Code> code); |
| 146 | |
| 147 | // Deferred code support. |
| 148 | void DoDeferredNumberTagD(LNumberTagD* instr); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 149 | |
| 150 | enum IntegerSignedness { SIGNED_INT32, UNSIGNED_INT32 }; |
| 151 | void DoDeferredNumberTagI(LInstruction* instr, |
| 152 | LOperand* value, |
| 153 | IntegerSignedness signedness); |
| 154 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 155 | void DoDeferredTaggedToI(LTaggedToI* instr); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 156 | void DoDeferredTaggedToINoSSE2(LTaggedToINoSSE2* instr); |
| 157 | void DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 158 | void DoDeferredStackCheck(LStackCheck* instr); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 159 | void DoDeferredRandom(LRandom* instr); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 160 | void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 161 | void DoDeferredStringCharFromCode(LStringCharFromCode* instr); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 162 | void DoDeferredAllocateObject(LAllocateObject* instr); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 163 | void DoDeferredAllocate(LAllocate* instr); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 164 | void DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 165 | Label* map_check); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 166 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 167 | void DoCheckMapCommon(Register reg, Handle<Map> map, LInstruction* instr); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 168 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 169 | // Parallel move support. |
| 170 | void DoParallelMove(LParallelMove* move); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 171 | void DoGap(LGap* instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 172 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 173 | // Emit frame translation commands for an environment. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 174 | void WriteTranslation(LEnvironment* environment, |
| 175 | Translation* translation, |
| 176 | int* arguments_index, |
| 177 | int* arguments_count); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 178 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 179 | void EnsureRelocSpaceForDeoptimization(); |
| 180 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 181 | // Declare methods that deal with the individual node types. |
| 182 | #define DECLARE_DO(type) void Do##type(L##type* node); |
| 183 | LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_DO) |
| 184 | #undef DECLARE_DO |
| 185 | |
| 186 | private: |
| 187 | enum Status { |
| 188 | UNUSED, |
| 189 | GENERATING, |
| 190 | DONE, |
| 191 | ABORTED |
| 192 | }; |
| 193 | |
| 194 | bool is_unused() const { return status_ == UNUSED; } |
| 195 | bool is_generating() const { return status_ == GENERATING; } |
| 196 | bool is_done() const { return status_ == DONE; } |
| 197 | bool is_aborted() const { return status_ == ABORTED; } |
| 198 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 199 | StrictModeFlag strict_mode_flag() const { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 200 | return info()->is_classic_mode() ? kNonStrictMode : kStrictMode; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 201 | } |
| 202 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 203 | LPlatformChunk* chunk() const { return chunk_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 204 | Scope* scope() const { return scope_; } |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 205 | HGraph* graph() const { return chunk()->graph(); } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 206 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 207 | int GetNextEmittedBlock() const; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 208 | |
| 209 | void EmitClassOfTest(Label* if_true, |
| 210 | Label* if_false, |
| 211 | Handle<String> class_name, |
| 212 | Register input, |
| 213 | Register temporary, |
| 214 | Register temporary2); |
| 215 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 216 | int GetStackSlotCount() const { return chunk()->spill_slot_count(); } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 217 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 218 | void Abort(const char* reason); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 219 | void FPRINTF_CHECKING Comment(const char* format, ...); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 220 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 221 | void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code, zone()); } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 222 | |
| 223 | // Code generation passes. Returns true if code generation should |
| 224 | // continue. |
| 225 | bool GeneratePrologue(); |
| 226 | bool GenerateBody(); |
| 227 | bool GenerateDeferredCode(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 228 | bool GenerateJumpTable(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 229 | bool GenerateSafepointTable(); |
| 230 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 231 | enum SafepointMode { |
| 232 | RECORD_SIMPLE_SAFEPOINT, |
| 233 | RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS |
| 234 | }; |
| 235 | |
| 236 | void CallCode(Handle<Code> code, |
| 237 | RelocInfo::Mode mode, |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 238 | LInstruction* instr); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 239 | |
| 240 | void CallCodeGeneric(Handle<Code> code, |
| 241 | RelocInfo::Mode mode, |
| 242 | LInstruction* instr, |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 243 | SafepointMode safepoint_mode); |
| 244 | |
| 245 | void CallRuntime(const Runtime::Function* fun, |
| 246 | int argc, |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 247 | LInstruction* instr); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 248 | |
| 249 | void CallRuntime(Runtime::FunctionId id, |
| 250 | int argc, |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 251 | LInstruction* instr) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 252 | const Runtime::Function* function = Runtime::FunctionForId(id); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 253 | CallRuntime(function, argc, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 254 | } |
| 255 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 256 | void CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 257 | int argc, |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 258 | LInstruction* instr, |
| 259 | LOperand* context); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 260 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 261 | void LoadContextFromDeferred(LOperand* context); |
| 262 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 263 | enum EDIState { |
| 264 | EDI_UNINITIALIZED, |
| 265 | EDI_CONTAINS_TARGET |
| 266 | }; |
| 267 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 268 | // Generate a direct call to a known function. Expects the function |
| 269 | // to be in edi. |
| 270 | void CallKnownFunction(Handle<JSFunction> function, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 271 | int formal_parameter_count, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 272 | int arity, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 273 | LInstruction* instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 274 | CallKind call_kind, |
| 275 | EDIState edi_state); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 276 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 277 | void RecordSafepointWithLazyDeopt(LInstruction* instr, |
| 278 | SafepointMode safepoint_mode); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 279 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 280 | void RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
| 281 | Safepoint::DeoptMode mode); |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 282 | void DeoptimizeIf(Condition cc, |
| 283 | LEnvironment* environment, |
| 284 | Deoptimizer::BailoutType bailout_type); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 285 | void DeoptimizeIf(Condition cc, LEnvironment* environment); |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 286 | void SoftDeoptimize(LEnvironment* environment); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 287 | |
| 288 | void AddToTranslation(Translation* translation, |
| 289 | LOperand* op, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 290 | bool is_tagged, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 291 | bool is_uint32, |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 292 | bool arguments_known, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 293 | int arguments_index, |
| 294 | int arguments_count); |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 295 | void RegisterDependentCodeForEmbeddedMaps(Handle<Code> code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 296 | void PopulateDeoptimizationData(Handle<Code> code); |
| 297 | int DefineDeoptimizationLiteral(Handle<Object> literal); |
| 298 | |
| 299 | void PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 300 | |
| 301 | Register ToRegister(int index) const; |
| 302 | XMMRegister ToDoubleRegister(int index) const; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 303 | int ToInteger32(LConstantOperand* op) const; |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 304 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 305 | double ToDouble(LConstantOperand* op) const; |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 306 | Operand BuildFastArrayOperand(LOperand* elements_pointer, |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 307 | LOperand* key, |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 308 | Representation key_representation, |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 309 | ElementsKind elements_kind, |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 310 | uint32_t offset, |
| 311 | uint32_t additional_index = 0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 312 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 313 | void EmitIntegerMathAbs(LMathAbs* instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 314 | |
| 315 | // Support for recording safepoint and position information. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 316 | void RecordSafepoint(LPointerMap* pointers, |
| 317 | Safepoint::Kind kind, |
| 318 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 319 | Safepoint::DeoptMode mode); |
| 320 | void RecordSafepoint(LPointerMap* pointers, Safepoint::DeoptMode mode); |
| 321 | void RecordSafepoint(Safepoint::DeoptMode mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 322 | void RecordSafepointWithRegisters(LPointerMap* pointers, |
| 323 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 324 | Safepoint::DeoptMode mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 325 | void RecordPosition(int position); |
| 326 | |
| 327 | static Condition TokenToCondition(Token::Value op, bool is_unsigned); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 328 | void EmitGoto(int block); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 329 | void EmitBranch(int left_block, int right_block, Condition cc); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 330 | void EmitNumberUntagD( |
| 331 | Register input, |
| 332 | Register temp, |
| 333 | XMMRegister result, |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame^] | 334 | bool allow_undefined_as_nan, |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 335 | bool deoptimize_on_minus_zero, |
| 336 | LEnvironment* env, |
| 337 | NumberUntagDMode mode = NUMBER_CANDIDATE_IS_ANY_TAGGED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 338 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 339 | void EmitNumberUntagDNoSSE2( |
| 340 | Register input, |
| 341 | Register temp, |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame^] | 342 | bool allow_undefined_as_nan, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 343 | bool deoptimize_on_minus_zero, |
| 344 | LEnvironment* env, |
| 345 | NumberUntagDMode mode = NUMBER_CANDIDATE_IS_ANY_TAGGED); |
| 346 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 347 | // Emits optimized code for typeof x == "y". Modifies input register. |
| 348 | // Returns the condition on which a final split to |
| 349 | // true and false label should be made, to optimize fallthrough. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 350 | Condition EmitTypeofIs(Label* true_label, |
| 351 | Label* false_label, |
| 352 | Register input, |
| 353 | Handle<String> type_name); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 354 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 355 | // Emits optimized code for %_IsObject(x). Preserves input register. |
| 356 | // Returns the condition on which a final split to |
| 357 | // true and false label should be made, to optimize fallthrough. |
| 358 | Condition EmitIsObject(Register input, |
| 359 | Register temp1, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 360 | Label* is_not_object, |
| 361 | Label* is_object); |
| 362 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 363 | // Emits optimized code for %_IsString(x). Preserves input register. |
| 364 | // Returns the condition on which a final split to |
| 365 | // true and false label should be made, to optimize fallthrough. |
| 366 | Condition EmitIsString(Register input, |
| 367 | Register temp1, |
| 368 | Label* is_not_string); |
| 369 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 370 | // Emits optimized code for %_IsConstructCall(). |
| 371 | // Caller should branch on equal condition. |
| 372 | void EmitIsConstructCall(Register temp); |
| 373 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 374 | void EmitLoadFieldOrConstantFunction(Register result, |
| 375 | Register object, |
| 376 | Handle<Map> type, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 377 | Handle<String> name, |
| 378 | LEnvironment* env); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 379 | |
| 380 | // Emits optimized code to deep-copy the contents of statically known |
| 381 | // object graphs (e.g. object literal boilerplate). |
| 382 | void EmitDeepCopy(Handle<JSObject> object, |
| 383 | Register result, |
| 384 | Register source, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 385 | int* offset, |
| 386 | AllocationSiteMode mode); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 387 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 388 | void EnsureSpaceForLazyDeopt(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 389 | void DoLoadKeyedExternalArray(LLoadKeyed* instr); |
| 390 | void DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr); |
| 391 | void DoLoadKeyedFixedArray(LLoadKeyed* instr); |
| 392 | void DoStoreKeyedExternalArray(LStoreKeyed* instr); |
| 393 | void DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr); |
| 394 | void DoStoreKeyedFixedArray(LStoreKeyed* instr); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 395 | |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 396 | void EmitReturn(LReturn* instr, bool dynamic_frame_alignment); |
| 397 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 398 | // Emits code for pushing either a tagged constant, a (non-double) |
| 399 | // register, or a stack slot operand. |
| 400 | void EmitPushTaggedOperand(LOperand* operand); |
| 401 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 402 | Zone* zone_; |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 403 | LPlatformChunk* const chunk_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 404 | MacroAssembler* const masm_; |
| 405 | CompilationInfo* const info_; |
| 406 | |
| 407 | int current_block_; |
| 408 | int current_instruction_; |
| 409 | const ZoneList<LInstruction*>* instructions_; |
| 410 | ZoneList<LEnvironment*> deoptimizations_; |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 411 | ZoneList<Deoptimizer::JumpTableEntry> jump_table_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 412 | ZoneList<Handle<Object> > deoptimization_literals_; |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 413 | ZoneList<Handle<Map> > prototype_maps_; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 414 | ZoneList<Handle<Map> > transition_maps_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 415 | int inlined_function_count_; |
| 416 | Scope* const scope_; |
| 417 | Status status_; |
| 418 | TranslationBuffer translations_; |
| 419 | ZoneList<LDeferredCode*> deferred_; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 420 | bool dynamic_frame_alignment_; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 421 | bool support_aligned_spilled_doubles_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 422 | int osr_pc_offset_; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 423 | int last_lazy_deopt_pc_; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 424 | bool frame_is_built_; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 425 | int x87_stack_depth_; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 426 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 427 | // Builder that keeps track of safepoints in the code. The table |
| 428 | // itself is emitted at the end of the generated code. |
| 429 | SafepointTableBuilder safepoints_; |
| 430 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 431 | // Compiler from a set of parallel moves to a sequential list of moves. |
| 432 | LGapResolver resolver_; |
| 433 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 434 | Safepoint::Kind expected_safepoint_kind_; |
| 435 | |
| 436 | class PushSafepointRegistersScope BASE_EMBEDDED { |
| 437 | public: |
| 438 | explicit PushSafepointRegistersScope(LCodeGen* codegen) |
| 439 | : codegen_(codegen) { |
| 440 | ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kSimple); |
| 441 | codegen_->masm_->PushSafepointRegisters(); |
| 442 | codegen_->expected_safepoint_kind_ = Safepoint::kWithRegisters; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 443 | ASSERT(codegen_->info()->is_calling()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | ~PushSafepointRegistersScope() { |
| 447 | ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kWithRegisters); |
| 448 | codegen_->masm_->PopSafepointRegisters(); |
| 449 | codegen_->expected_safepoint_kind_ = Safepoint::kSimple; |
| 450 | } |
| 451 | |
| 452 | private: |
| 453 | LCodeGen* codegen_; |
| 454 | }; |
| 455 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 456 | friend class LDeferredCode; |
| 457 | friend class LEnvironment; |
| 458 | friend class SafepointGenerator; |
| 459 | DISALLOW_COPY_AND_ASSIGN(LCodeGen); |
| 460 | }; |
| 461 | |
| 462 | |
| 463 | class LDeferredCode: public ZoneObject { |
| 464 | public: |
| 465 | explicit LDeferredCode(LCodeGen* codegen) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 466 | : codegen_(codegen), |
| 467 | external_exit_(NULL), |
| 468 | instruction_index_(codegen->current_instruction_) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 469 | codegen->AddDeferredCode(this); |
| 470 | } |
| 471 | |
| 472 | virtual ~LDeferredCode() { } |
| 473 | virtual void Generate() = 0; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 474 | virtual LInstruction* instr() = 0; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 475 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 476 | void SetExit(Label* exit) { external_exit_ = exit; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 477 | Label* entry() { return &entry_; } |
| 478 | Label* exit() { return external_exit_ != NULL ? external_exit_ : &exit_; } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 479 | int instruction_index() const { return instruction_index_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 480 | |
| 481 | protected: |
| 482 | LCodeGen* codegen() const { return codegen_; } |
| 483 | MacroAssembler* masm() const { return codegen_->masm(); } |
| 484 | |
| 485 | private: |
| 486 | LCodeGen* codegen_; |
| 487 | Label entry_; |
| 488 | Label exit_; |
| 489 | Label* external_exit_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 490 | int instruction_index_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 491 | }; |
| 492 | |
| 493 | } } // namespace v8::internal |
| 494 | |
| 495 | #endif // V8_IA32_LITHIUM_CODEGEN_IA32_H_ |