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_X64_LITHIUM_CODEGEN_X64_H_ |
| 29 | #define V8_X64_LITHIUM_CODEGEN_X64_H_ |
| 30 | |
| 31 | #include "x64/lithium-x64.h" |
| 32 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 33 | #include "checks.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 34 | #include "deoptimizer.h" |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 35 | #include "lithium-codegen.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" |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 39 | #include "x64/lithium-gap-resolver-x64.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 40 | |
| 41 | namespace v8 { |
| 42 | namespace internal { |
| 43 | |
| 44 | // Forward declarations. |
| 45 | class LDeferredCode; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 46 | class SafepointGenerator; |
| 47 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 48 | class LCodeGen: public LCodeGenBase { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 49 | public: |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 50 | LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info) |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 51 | : LCodeGenBase(chunk, assembler, info), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 52 | deoptimizations_(4, info->zone()), |
| 53 | jump_table_(4, info->zone()), |
| 54 | deoptimization_literals_(8, info->zone()), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 55 | inlined_function_count_(0), |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 56 | scope_(info->scope()), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 57 | translations_(info->zone()), |
| 58 | deferred_(8, info->zone()), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 59 | osr_pc_offset_(-1), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 60 | frame_is_built_(false), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 61 | safepoints_(info->zone()), |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 62 | resolver_(this), |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 63 | expected_safepoint_kind_(Safepoint::kSimple) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 64 | PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 65 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 66 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 67 | int LookupDestination(int block_id) const { |
| 68 | return chunk()->LookupDestination(block_id); |
| 69 | } |
| 70 | |
| 71 | bool IsNextEmittedBlock(int block_id) const { |
| 72 | return LookupDestination(block_id) == GetNextEmittedBlock(); |
| 73 | } |
| 74 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 75 | bool NeedsEagerFrame() const { |
| 76 | return GetStackSlotCount() > 0 || |
| 77 | info()->is_non_deferred_calling() || |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 78 | !info()->IsStub() || |
| 79 | info()->requires_frame(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 80 | } |
| 81 | bool NeedsDeferredFrame() const { |
| 82 | return !NeedsEagerFrame() && info()->is_deferred_calling(); |
| 83 | } |
| 84 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 85 | // Support for converting LOperands to assembler types. |
| 86 | Register ToRegister(LOperand* op) const; |
| 87 | XMMRegister ToDoubleRegister(LOperand* op) const; |
| 88 | bool IsInteger32Constant(LConstantOperand* op) const; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 89 | bool IsSmiConstant(LConstantOperand* op) const; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 90 | int32_t ToInteger32(LConstantOperand* op) const; |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 91 | Smi* ToSmi(LConstantOperand* op) const; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 92 | double ToDouble(LConstantOperand* op) const; |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 93 | ExternalReference ToExternalReference(LConstantOperand* op) const; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 94 | bool IsTaggedConstant(LConstantOperand* op) const; |
| 95 | Handle<Object> ToHandle(LConstantOperand* op) const; |
| 96 | Operand ToOperand(LOperand* op) const; |
| 97 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 98 | // Try to generate code for the entire chunk, but it may fail if the |
| 99 | // chunk contains constructs we cannot handle. Returns true if the |
| 100 | // code generation attempt succeeded. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 101 | bool GenerateCode(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 102 | |
| 103 | // Finish the code by setting stack height, safepoint, and bailout |
| 104 | // information on it. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 105 | void FinishCode(Handle<Code> code); |
| 106 | |
| 107 | // Deferred code support. |
| 108 | void DoDeferredNumberTagD(LNumberTagD* instr); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 109 | void DoDeferredNumberTagU(LNumberTagU* instr); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 110 | void DoDeferredTaggedToI(LTaggedToI* instr, Label* done); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 111 | void DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 112 | void DoDeferredStackCheck(LStackCheck* instr); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 113 | void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 114 | void DoDeferredStringCharFromCode(LStringCharFromCode* instr); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 115 | void DoDeferredAllocate(LAllocate* instr); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 116 | void DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 117 | Label* map_check); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 118 | void DoDeferredInstanceMigration(LCheckMaps* instr, Register object); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 119 | |
| 120 | // Parallel move support. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 121 | void DoParallelMove(LParallelMove* move); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 122 | void DoGap(LGap* instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 123 | |
| 124 | // Emit frame translation commands for an environment. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 125 | void WriteTranslation(LEnvironment* environment, Translation* translation); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 126 | |
| 127 | // Declare methods that deal with the individual node types. |
| 128 | #define DECLARE_DO(type) void Do##type(L##type* node); |
| 129 | LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_DO) |
| 130 | #undef DECLARE_DO |
| 131 | |
| 132 | private: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 133 | StrictModeFlag strict_mode_flag() const { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 134 | return info()->is_classic_mode() ? kNonStrictMode : kStrictMode; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 135 | } |
| 136 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 137 | LPlatformChunk* chunk() const { return chunk_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 138 | Scope* scope() const { return scope_; } |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 139 | HGraph* graph() const { return chunk()->graph(); } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 140 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 141 | XMMRegister double_scratch0() const { return xmm0; } |
| 142 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 143 | void EmitClassOfTest(Label* if_true, |
| 144 | Label* if_false, |
| 145 | Handle<String> class_name, |
| 146 | Register input, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 147 | Register temporary, |
| 148 | Register scratch); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 149 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 150 | int GetStackSlotCount() const { return chunk()->spill_slot_count(); } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 151 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 152 | void Abort(BailoutReason reason); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 153 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 154 | void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code, zone()); } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 155 | |
| 156 | // Code generation passes. Returns true if code generation should |
| 157 | // continue. |
| 158 | bool GeneratePrologue(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 159 | bool GenerateDeferredCode(); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 160 | bool GenerateJumpTable(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 161 | bool GenerateSafepointTable(); |
| 162 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 163 | // Generates the custom OSR entrypoint and sets the osr_pc_offset. |
| 164 | void GenerateOsrPrologue(); |
| 165 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 166 | enum SafepointMode { |
| 167 | RECORD_SIMPLE_SAFEPOINT, |
| 168 | RECORD_SAFEPOINT_WITH_REGISTERS |
| 169 | }; |
| 170 | |
| 171 | void CallCodeGeneric(Handle<Code> code, |
| 172 | RelocInfo::Mode mode, |
| 173 | LInstruction* instr, |
| 174 | SafepointMode safepoint_mode, |
| 175 | int argc); |
| 176 | |
| 177 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 178 | void CallCode(Handle<Code> code, |
| 179 | RelocInfo::Mode mode, |
| 180 | LInstruction* instr); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 181 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 182 | void CallRuntime(const Runtime::Function* function, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 183 | int num_arguments, |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 184 | LInstruction* instr, |
| 185 | SaveFPRegsMode save_doubles = kDontSaveFPRegs); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 186 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 187 | void CallRuntime(Runtime::FunctionId id, |
| 188 | int num_arguments, |
| 189 | LInstruction* instr) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 190 | const Runtime::Function* function = Runtime::FunctionForId(id); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 191 | CallRuntime(function, num_arguments, instr); |
| 192 | } |
| 193 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 194 | void CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 195 | int argc, |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 196 | LInstruction* instr, |
| 197 | LOperand* context); |
| 198 | |
| 199 | void LoadContextFromDeferred(LOperand* context); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 200 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 201 | enum RDIState { |
| 202 | RDI_UNINITIALIZED, |
| 203 | RDI_CONTAINS_TARGET |
| 204 | }; |
| 205 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 206 | // Generate a direct call to a known function. Expects the function |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 207 | // to be in rdi. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 208 | void CallKnownFunction(Handle<JSFunction> function, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 209 | int formal_parameter_count, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 210 | int arity, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 211 | LInstruction* instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 212 | CallKind call_kind, |
| 213 | RDIState rdi_state); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 214 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 215 | void RecordSafepointWithLazyDeopt(LInstruction* instr, |
| 216 | SafepointMode safepoint_mode, |
| 217 | int argc); |
| 218 | void RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
| 219 | Safepoint::DeoptMode mode); |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 220 | void DeoptimizeIf(Condition cc, |
| 221 | LEnvironment* environment, |
| 222 | Deoptimizer::BailoutType bailout_type); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 223 | void DeoptimizeIf(Condition cc, LEnvironment* environment); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 224 | void ApplyCheckIf(Condition cc, LBoundsCheck* check); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 225 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 226 | bool DeoptEveryNTimes() { |
| 227 | return FLAG_deopt_every_n_times != 0 && !info()->IsStub(); |
| 228 | } |
| 229 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 230 | void AddToTranslation(LEnvironment* environment, |
| 231 | Translation* translation, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 232 | LOperand* op, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 233 | bool is_tagged, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 234 | bool is_uint32, |
| 235 | int* object_index_pointer, |
| 236 | int* dematerialized_index_pointer); |
ulan@chromium.org | 6ba1fd0 | 2013-02-14 14:56:11 +0000 | [diff] [blame] | 237 | void RegisterDependentCodeForEmbeddedMaps(Handle<Code> code); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 238 | void PopulateDeoptimizationData(Handle<Code> code); |
| 239 | int DefineDeoptimizationLiteral(Handle<Object> literal); |
| 240 | |
| 241 | void PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 242 | |
| 243 | Register ToRegister(int index) const; |
| 244 | XMMRegister ToDoubleRegister(int index) const; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 245 | Operand BuildFastArrayOperand( |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 246 | LOperand* elements_pointer, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 247 | LOperand* key, |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 248 | ElementsKind elements_kind, |
ulan@chromium.org | 0e3f88b | 2012-05-22 09:16:05 +0000 | [diff] [blame] | 249 | uint32_t offset, |
| 250 | uint32_t additional_index = 0); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 251 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 252 | Operand BuildSeqStringOperand(Register string, |
| 253 | LOperand* index, |
| 254 | String::Encoding encoding); |
| 255 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 256 | void EmitIntegerMathAbs(LMathAbs* instr); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 257 | void EmitSmiMathAbs(LMathAbs* instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 258 | |
| 259 | // Support for recording safepoint and position information. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 260 | void RecordSafepoint(LPointerMap* pointers, |
| 261 | Safepoint::Kind kind, |
| 262 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 263 | Safepoint::DeoptMode mode); |
| 264 | void RecordSafepoint(LPointerMap* pointers, Safepoint::DeoptMode mode); |
| 265 | void RecordSafepoint(Safepoint::DeoptMode mode); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 266 | void RecordSafepointWithRegisters(LPointerMap* pointers, |
| 267 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 268 | Safepoint::DeoptMode mode); |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 269 | void RecordAndWritePosition(int position) V8_OVERRIDE; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 270 | |
| 271 | static Condition TokenToCondition(Token::Value op, bool is_unsigned); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 272 | void EmitGoto(int block); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 273 | |
| 274 | // EmitBranch expects to be the last instruction of a block. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 275 | template<class InstrType> |
| 276 | void EmitBranch(InstrType instr, Condition cc); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 277 | template<class InstrType> |
| 278 | void EmitFalseBranch(InstrType instr, Condition cc); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 279 | void EmitNumberUntagD( |
| 280 | Register input, |
| 281 | XMMRegister result, |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 282 | bool allow_undefined_as_nan, |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 283 | bool deoptimize_on_minus_zero, |
| 284 | LEnvironment* env, |
| 285 | NumberUntagDMode mode = NUMBER_CANDIDATE_IS_ANY_TAGGED); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 286 | |
| 287 | // Emits optimized code for typeof x == "y". Modifies input register. |
| 288 | // Returns the condition on which a final split to |
| 289 | // true and false label should be made, to optimize fallthrough. |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 290 | Condition EmitTypeofIs(LTypeofIsAndBranch* instr, Register input); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 291 | |
| 292 | // Emits optimized code for %_IsObject(x). Preserves input register. |
| 293 | // Returns the condition on which a final split to |
| 294 | // true and false label should be made, to optimize fallthrough. |
| 295 | Condition EmitIsObject(Register input, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 296 | Label* is_not_object, |
| 297 | Label* is_object); |
| 298 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 299 | // Emits optimized code for %_IsString(x). Preserves input register. |
| 300 | // Returns the condition on which a final split to |
| 301 | // true and false label should be made, to optimize fallthrough. |
| 302 | Condition EmitIsString(Register input, |
| 303 | Register temp1, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 304 | Label* is_not_string, |
| 305 | SmiCheck check_needed); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 306 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 307 | // Emits optimized code for %_IsConstructCall(). |
| 308 | // Caller should branch on equal condition. |
| 309 | void EmitIsConstructCall(Register temp); |
| 310 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 311 | // Emits code for pushing either a tagged constant, a (non-double) |
| 312 | // register, or a stack slot operand. |
| 313 | void EmitPushTaggedOperand(LOperand* operand); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 314 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 315 | // Emits optimized code to deep-copy the contents of statically known |
| 316 | // object graphs (e.g. object literal boilerplate). |
| 317 | void EmitDeepCopy(Handle<JSObject> object, |
| 318 | Register result, |
| 319 | Register source, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 320 | int* offset, |
| 321 | AllocationSiteMode mode); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 322 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 323 | void EnsureSpaceForLazyDeopt(int space_needed) V8_OVERRIDE; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 324 | void DoLoadKeyedExternalArray(LLoadKeyed* instr); |
| 325 | void DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr); |
| 326 | void DoLoadKeyedFixedArray(LLoadKeyed* instr); |
| 327 | void DoStoreKeyedExternalArray(LStoreKeyed* instr); |
| 328 | void DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr); |
| 329 | void DoStoreKeyedFixedArray(LStoreKeyed* instr); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 330 | #ifdef _MSC_VER |
| 331 | // On windows, you may not access the stack more than one page below |
| 332 | // the most recently mapped page. To make the allocated area randomly |
| 333 | // accessible, we write an arbitrary value to each page in range |
| 334 | // rsp + offset - page_size .. rsp in turn. |
| 335 | void MakeSureStackPagesMapped(int offset); |
| 336 | #endif |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 337 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 338 | ZoneList<LEnvironment*> deoptimizations_; |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 339 | ZoneList<Deoptimizer::JumpTableEntry> jump_table_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 340 | ZoneList<Handle<Object> > deoptimization_literals_; |
| 341 | int inlined_function_count_; |
| 342 | Scope* const scope_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 343 | TranslationBuffer translations_; |
| 344 | ZoneList<LDeferredCode*> deferred_; |
| 345 | int osr_pc_offset_; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 346 | bool frame_is_built_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 347 | |
| 348 | // Builder that keeps track of safepoints in the code. The table |
| 349 | // itself is emitted at the end of the generated code. |
| 350 | SafepointTableBuilder safepoints_; |
| 351 | |
| 352 | // Compiler from a set of parallel moves to a sequential list of moves. |
| 353 | LGapResolver resolver_; |
| 354 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 355 | Safepoint::Kind expected_safepoint_kind_; |
| 356 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 357 | class PushSafepointRegistersScope V8_FINAL BASE_EMBEDDED { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 358 | public: |
| 359 | explicit PushSafepointRegistersScope(LCodeGen* codegen) |
| 360 | : codegen_(codegen) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 361 | ASSERT(codegen_->info()->is_calling()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 362 | ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kSimple); |
| 363 | codegen_->masm_->PushSafepointRegisters(); |
| 364 | codegen_->expected_safepoint_kind_ = Safepoint::kWithRegisters; |
| 365 | } |
| 366 | |
| 367 | ~PushSafepointRegistersScope() { |
| 368 | ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kWithRegisters); |
| 369 | codegen_->masm_->PopSafepointRegisters(); |
| 370 | codegen_->expected_safepoint_kind_ = Safepoint::kSimple; |
| 371 | } |
| 372 | |
| 373 | private: |
| 374 | LCodeGen* codegen_; |
| 375 | }; |
| 376 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 377 | friend class LDeferredCode; |
| 378 | friend class LEnvironment; |
| 379 | friend class SafepointGenerator; |
| 380 | DISALLOW_COPY_AND_ASSIGN(LCodeGen); |
| 381 | }; |
| 382 | |
| 383 | |
| 384 | class LDeferredCode: public ZoneObject { |
| 385 | public: |
| 386 | explicit LDeferredCode(LCodeGen* codegen) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 387 | : codegen_(codegen), |
| 388 | external_exit_(NULL), |
| 389 | instruction_index_(codegen->current_instruction_) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 390 | codegen->AddDeferredCode(this); |
| 391 | } |
| 392 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 393 | virtual ~LDeferredCode() {} |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 394 | virtual void Generate() = 0; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 395 | virtual LInstruction* instr() = 0; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 396 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 397 | void SetExit(Label* exit) { external_exit_ = exit; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 398 | Label* entry() { return &entry_; } |
| 399 | Label* exit() { return external_exit_ != NULL ? external_exit_ : &exit_; } |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 400 | Label* done() { return codegen_->NeedsDeferredFrame() ? &done_ : exit(); } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 401 | int instruction_index() const { return instruction_index_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 402 | |
| 403 | protected: |
| 404 | LCodeGen* codegen() const { return codegen_; } |
| 405 | MacroAssembler* masm() const { return codegen_->masm(); } |
| 406 | |
| 407 | private: |
| 408 | LCodeGen* codegen_; |
| 409 | Label entry_; |
| 410 | Label exit_; |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 411 | Label done_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 412 | Label* external_exit_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 413 | int instruction_index_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 414 | }; |
| 415 | |
| 416 | } } // namespace v8::internal |
| 417 | |
| 418 | #endif // V8_X64_LITHIUM_CODEGEN_X64_H_ |