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. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 290 | Condition EmitTypeofIs(Label* true_label, |
| 291 | Label* false_label, |
| 292 | Register input, |
| 293 | Handle<String> type_name); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 294 | |
| 295 | // Emits optimized code for %_IsObject(x). Preserves input register. |
| 296 | // Returns the condition on which a final split to |
| 297 | // true and false label should be made, to optimize fallthrough. |
| 298 | Condition EmitIsObject(Register input, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 299 | Label* is_not_object, |
| 300 | Label* is_object); |
| 301 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 302 | // Emits optimized code for %_IsString(x). Preserves input register. |
| 303 | // Returns the condition on which a final split to |
| 304 | // true and false label should be made, to optimize fallthrough. |
| 305 | Condition EmitIsString(Register input, |
| 306 | Register temp1, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 307 | Label* is_not_string, |
| 308 | SmiCheck check_needed); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 309 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 310 | // Emits optimized code for %_IsConstructCall(). |
| 311 | // Caller should branch on equal condition. |
| 312 | void EmitIsConstructCall(Register temp); |
| 313 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 314 | // Emits code for pushing either a tagged constant, a (non-double) |
| 315 | // register, or a stack slot operand. |
| 316 | void EmitPushTaggedOperand(LOperand* operand); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 317 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 318 | // Emits optimized code to deep-copy the contents of statically known |
| 319 | // object graphs (e.g. object literal boilerplate). |
| 320 | void EmitDeepCopy(Handle<JSObject> object, |
| 321 | Register result, |
| 322 | Register source, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 323 | int* offset, |
| 324 | AllocationSiteMode mode); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 325 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 326 | void EnsureSpaceForLazyDeopt(int space_needed) V8_OVERRIDE; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 327 | void DoLoadKeyedExternalArray(LLoadKeyed* instr); |
| 328 | void DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr); |
| 329 | void DoLoadKeyedFixedArray(LLoadKeyed* instr); |
| 330 | void DoStoreKeyedExternalArray(LStoreKeyed* instr); |
| 331 | void DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr); |
| 332 | void DoStoreKeyedFixedArray(LStoreKeyed* instr); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 333 | #ifdef _MSC_VER |
| 334 | // On windows, you may not access the stack more than one page below |
| 335 | // the most recently mapped page. To make the allocated area randomly |
| 336 | // accessible, we write an arbitrary value to each page in range |
| 337 | // rsp + offset - page_size .. rsp in turn. |
| 338 | void MakeSureStackPagesMapped(int offset); |
| 339 | #endif |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 340 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 341 | ZoneList<LEnvironment*> deoptimizations_; |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 342 | ZoneList<Deoptimizer::JumpTableEntry> jump_table_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 343 | ZoneList<Handle<Object> > deoptimization_literals_; |
| 344 | int inlined_function_count_; |
| 345 | Scope* const scope_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 346 | TranslationBuffer translations_; |
| 347 | ZoneList<LDeferredCode*> deferred_; |
| 348 | int osr_pc_offset_; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 349 | bool frame_is_built_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 350 | |
| 351 | // Builder that keeps track of safepoints in the code. The table |
| 352 | // itself is emitted at the end of the generated code. |
| 353 | SafepointTableBuilder safepoints_; |
| 354 | |
| 355 | // Compiler from a set of parallel moves to a sequential list of moves. |
| 356 | LGapResolver resolver_; |
| 357 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 358 | Safepoint::Kind expected_safepoint_kind_; |
| 359 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 360 | class PushSafepointRegistersScope V8_FINAL BASE_EMBEDDED { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 361 | public: |
| 362 | explicit PushSafepointRegistersScope(LCodeGen* codegen) |
| 363 | : codegen_(codegen) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 364 | ASSERT(codegen_->info()->is_calling()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 365 | ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kSimple); |
| 366 | codegen_->masm_->PushSafepointRegisters(); |
| 367 | codegen_->expected_safepoint_kind_ = Safepoint::kWithRegisters; |
| 368 | } |
| 369 | |
| 370 | ~PushSafepointRegistersScope() { |
| 371 | ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kWithRegisters); |
| 372 | codegen_->masm_->PopSafepointRegisters(); |
| 373 | codegen_->expected_safepoint_kind_ = Safepoint::kSimple; |
| 374 | } |
| 375 | |
| 376 | private: |
| 377 | LCodeGen* codegen_; |
| 378 | }; |
| 379 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 380 | friend class LDeferredCode; |
| 381 | friend class LEnvironment; |
| 382 | friend class SafepointGenerator; |
| 383 | DISALLOW_COPY_AND_ASSIGN(LCodeGen); |
| 384 | }; |
| 385 | |
| 386 | |
| 387 | class LDeferredCode: public ZoneObject { |
| 388 | public: |
| 389 | explicit LDeferredCode(LCodeGen* codegen) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 390 | : codegen_(codegen), |
| 391 | external_exit_(NULL), |
| 392 | instruction_index_(codegen->current_instruction_) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 393 | codegen->AddDeferredCode(this); |
| 394 | } |
| 395 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 396 | virtual ~LDeferredCode() {} |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 397 | virtual void Generate() = 0; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 398 | virtual LInstruction* instr() = 0; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 399 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 400 | void SetExit(Label* exit) { external_exit_ = exit; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 401 | Label* entry() { return &entry_; } |
| 402 | Label* exit() { return external_exit_ != NULL ? external_exit_ : &exit_; } |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 403 | Label* done() { return codegen_->NeedsDeferredFrame() ? &done_ : exit(); } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 404 | int instruction_index() const { return instruction_index_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 405 | |
| 406 | protected: |
| 407 | LCodeGen* codegen() const { return codegen_; } |
| 408 | MacroAssembler* masm() const { return codegen_->masm(); } |
| 409 | |
| 410 | private: |
| 411 | LCodeGen* codegen_; |
| 412 | Label entry_; |
| 413 | Label exit_; |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 414 | Label done_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 415 | Label* external_exit_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 416 | int instruction_index_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 417 | }; |
| 418 | |
| 419 | } } // namespace v8::internal |
| 420 | |
| 421 | #endif // V8_X64_LITHIUM_CODEGEN_X64_H_ |