jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +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 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 28 | #ifndef V8_MIPS_LITHIUM_CODEGEN_MIPS_H_ |
| 29 | #define V8_MIPS_LITHIUM_CODEGEN_MIPS_H_ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 30 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 31 | #include "deoptimizer.h" |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 32 | #include "mips/lithium-gap-resolver-mips.h" |
| 33 | #include "mips/lithium-mips.h" |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 34 | #include "lithium-codegen.h" |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 35 | #include "safepoint-table.h" |
| 36 | #include "scopes.h" |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 37 | #include "v8utils.h" |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 38 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 39 | namespace v8 { |
| 40 | namespace internal { |
| 41 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 42 | // Forward declarations. |
| 43 | class LDeferredCode; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 44 | class SafepointGenerator; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 45 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 46 | class LCodeGen: public LCodeGenBase { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 47 | public: |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 48 | LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info) |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 49 | : LCodeGenBase(chunk, assembler, info), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 50 | deoptimizations_(4, info->zone()), |
| 51 | deopt_jump_table_(4, info->zone()), |
| 52 | deoptimization_literals_(8, info->zone()), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 53 | inlined_function_count_(0), |
| 54 | scope_(info->scope()), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 55 | translations_(info->zone()), |
| 56 | deferred_(8, info->zone()), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 57 | osr_pc_offset_(-1), |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 58 | frame_is_built_(false), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 59 | safepoints_(info->zone()), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 60 | resolver_(this), |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 61 | expected_safepoint_kind_(Safepoint::kSimple) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 62 | PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 63 | } |
| 64 | |
| 65 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 66 | int LookupDestination(int block_id) const { |
| 67 | return chunk()->LookupDestination(block_id); |
| 68 | } |
| 69 | |
| 70 | bool IsNextEmittedBlock(int block_id) const { |
| 71 | return LookupDestination(block_id) == GetNextEmittedBlock(); |
| 72 | } |
| 73 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 74 | bool NeedsEagerFrame() const { |
| 75 | return GetStackSlotCount() > 0 || |
| 76 | info()->is_non_deferred_calling() || |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 77 | !info()->IsStub() || |
| 78 | info()->requires_frame(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 79 | } |
| 80 | bool NeedsDeferredFrame() const { |
| 81 | return !NeedsEagerFrame() && info()->is_deferred_calling(); |
| 82 | } |
| 83 | |
danno@chromium.org | c99cd48 | 2013-03-21 15:26:42 +0000 | [diff] [blame] | 84 | RAStatus GetRAState() const { |
| 85 | return frame_is_built_ ? kRAHasBeenSaved : kRAHasNotBeenSaved; |
| 86 | } |
| 87 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 88 | // Support for converting LOperands to assembler types. |
| 89 | // LOperand must be a register. |
| 90 | Register ToRegister(LOperand* op) const; |
| 91 | |
| 92 | // LOperand is loaded into scratch, unless already a register. |
| 93 | Register EmitLoadRegister(LOperand* op, Register scratch); |
| 94 | |
| 95 | // LOperand must be a double register. |
| 96 | DoubleRegister ToDoubleRegister(LOperand* op) const; |
| 97 | |
| 98 | // LOperand is loaded into dbl_scratch, unless already a double register. |
| 99 | DoubleRegister EmitLoadDoubleRegister(LOperand* op, |
| 100 | FloatRegister flt_scratch, |
| 101 | DoubleRegister dbl_scratch); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 102 | int32_t ToRepresentation(LConstantOperand* op, const Representation& r) const; |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 103 | int32_t ToInteger32(LConstantOperand* op) const; |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 104 | Smi* ToSmi(LConstantOperand* op) const; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 105 | double ToDouble(LConstantOperand* op) const; |
| 106 | Operand ToOperand(LOperand* op); |
| 107 | MemOperand ToMemOperand(LOperand* op) const; |
| 108 | // Returns a MemOperand pointing to the high word of a DoubleStackSlot. |
| 109 | MemOperand ToHighMemOperand(LOperand* op) const; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 110 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 111 | bool IsInteger32(LConstantOperand* op) const; |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 112 | bool IsSmi(LConstantOperand* op) const; |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 113 | Handle<Object> ToHandle(LConstantOperand* op) const; |
| 114 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 115 | // Try to generate code for the entire chunk, but it may fail if the |
| 116 | // chunk contains constructs we cannot handle. Returns true if the |
| 117 | // code generation attempt succeeded. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 118 | bool GenerateCode(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 119 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 120 | // Finish the code by setting stack height, safepoint, and bailout |
| 121 | // information on it. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 122 | void FinishCode(Handle<Code> code); |
| 123 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 124 | void DoDeferredNumberTagD(LNumberTagD* instr); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 125 | |
| 126 | enum IntegerSignedness { SIGNED_INT32, UNSIGNED_INT32 }; |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 127 | void DoDeferredNumberTagIU(LInstruction* instr, |
| 128 | LOperand* value, |
| 129 | LOperand* temp1, |
| 130 | LOperand* temp2, |
| 131 | IntegerSignedness signedness); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 132 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 133 | void DoDeferredTaggedToI(LTaggedToI* instr); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 134 | void DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 135 | void DoDeferredStackCheck(LStackCheck* instr); |
| 136 | void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); |
| 137 | void DoDeferredStringCharFromCode(LStringCharFromCode* instr); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 138 | void DoDeferredAllocate(LAllocate* instr); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 139 | void DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 140 | Label* map_check); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 141 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 142 | void DoDeferredInstanceMigration(LCheckMaps* instr, Register object); |
machenbach@chromium.org | ab43d2f | 2014-04-01 06:35:49 +0000 | [diff] [blame] | 143 | void DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr, |
| 144 | Register result, |
| 145 | Register object, |
| 146 | Register index); |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 147 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 148 | // Parallel move support. |
| 149 | void DoParallelMove(LParallelMove* move); |
| 150 | void DoGap(LGap* instr); |
| 151 | |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 152 | MemOperand PrepareKeyedOperand(Register key, |
| 153 | Register base, |
| 154 | bool key_is_constant, |
| 155 | int constant_key, |
| 156 | int element_size, |
| 157 | int shift_size, |
| 158 | int additional_index, |
| 159 | int additional_offset); |
| 160 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 161 | // Emit frame translation commands for an environment. |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 162 | void WriteTranslation(LEnvironment* environment, Translation* translation); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 163 | |
| 164 | // Declare methods that deal with the individual node types. |
| 165 | #define DECLARE_DO(type) void Do##type(L##type* node); |
| 166 | LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_DO) |
| 167 | #undef DECLARE_DO |
| 168 | |
| 169 | private: |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 170 | StrictMode strict_mode() const { return info()->strict_mode(); } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 171 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 172 | Scope* scope() const { return scope_; } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 173 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 174 | Register scratch0() { return kLithiumScratchReg; } |
| 175 | Register scratch1() { return kLithiumScratchReg2; } |
| 176 | DoubleRegister double_scratch0() { return kLithiumScratchDouble; } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 177 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 178 | LInstruction* GetNextInstruction(); |
| 179 | |
| 180 | void EmitClassOfTest(Label* if_true, |
| 181 | Label* if_false, |
| 182 | Handle<String> class_name, |
| 183 | Register input, |
| 184 | Register temporary, |
| 185 | Register temporary2); |
| 186 | |
| 187 | int GetStackSlotCount() const { return chunk()->spill_slot_count(); } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 188 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 189 | void Abort(BailoutReason reason); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 190 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 191 | void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code, zone()); } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 192 | |
machenbach@chromium.org | f984189 | 2013-11-25 12:01:13 +0000 | [diff] [blame] | 193 | void SaveCallerDoubles(); |
| 194 | void RestoreCallerDoubles(); |
| 195 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 196 | // Code generation passes. Returns true if code generation should |
| 197 | // continue. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 198 | void GenerateBodyInstructionPre(LInstruction* instr) V8_OVERRIDE; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 199 | bool GeneratePrologue(); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 200 | bool GenerateDeferredCode(); |
| 201 | bool GenerateDeoptJumpTable(); |
| 202 | bool GenerateSafepointTable(); |
| 203 | |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 204 | // Generates the custom OSR entrypoint and sets the osr_pc_offset. |
| 205 | void GenerateOsrPrologue(); |
| 206 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 207 | enum SafepointMode { |
| 208 | RECORD_SIMPLE_SAFEPOINT, |
| 209 | RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS |
| 210 | }; |
| 211 | |
| 212 | void CallCode(Handle<Code> code, |
| 213 | RelocInfo::Mode mode, |
| 214 | LInstruction* instr); |
| 215 | |
| 216 | void CallCodeGeneric(Handle<Code> code, |
| 217 | RelocInfo::Mode mode, |
| 218 | LInstruction* instr, |
| 219 | SafepointMode safepoint_mode); |
| 220 | |
| 221 | void CallRuntime(const Runtime::Function* function, |
| 222 | int num_arguments, |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 223 | LInstruction* instr, |
| 224 | SaveFPRegsMode save_doubles = kDontSaveFPRegs); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 225 | |
| 226 | void CallRuntime(Runtime::FunctionId id, |
| 227 | int num_arguments, |
| 228 | LInstruction* instr) { |
| 229 | const Runtime::Function* function = Runtime::FunctionForId(id); |
| 230 | CallRuntime(function, num_arguments, instr); |
| 231 | } |
| 232 | |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 233 | void LoadContextFromDeferred(LOperand* context); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 234 | void CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 235 | int argc, |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 236 | LInstruction* instr, |
| 237 | LOperand* context); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 238 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 239 | enum A1State { |
| 240 | A1_UNINITIALIZED, |
| 241 | A1_CONTAINS_TARGET |
| 242 | }; |
| 243 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 244 | // Generate a direct call to a known function. Expects the function |
| 245 | // to be in a1. |
| 246 | void CallKnownFunction(Handle<JSFunction> function, |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 247 | int formal_parameter_count, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 248 | int arity, |
| 249 | LInstruction* instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 250 | A1State a1_state); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 251 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 252 | void RecordSafepointWithLazyDeopt(LInstruction* instr, |
| 253 | SafepointMode safepoint_mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 254 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 255 | void RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
| 256 | Safepoint::DeoptMode mode); |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 257 | void DeoptimizeIf(Condition condition, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 258 | LEnvironment* environment, |
palfia@homejinni.com | 0410973 | 2013-05-15 09:50:32 +0000 | [diff] [blame] | 259 | Deoptimizer::BailoutType bailout_type, |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 260 | Register src1 = zero_reg, |
| 261 | const Operand& src2 = Operand(zero_reg)); |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 262 | void DeoptimizeIf(Condition condition, |
palfia@homejinni.com | 0410973 | 2013-05-15 09:50:32 +0000 | [diff] [blame] | 263 | LEnvironment* environment, |
| 264 | Register src1 = zero_reg, |
| 265 | const Operand& src2 = Operand(zero_reg)); |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 266 | void ApplyCheckIf(Condition condition, |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 267 | LBoundsCheck* check, |
| 268 | Register src1 = zero_reg, |
| 269 | const Operand& src2 = Operand(zero_reg)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 270 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 271 | void AddToTranslation(LEnvironment* environment, |
| 272 | Translation* translation, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 273 | LOperand* op, |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 274 | bool is_tagged, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 275 | bool is_uint32, |
| 276 | int* object_index_pointer, |
| 277 | int* dematerialized_index_pointer); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 278 | void PopulateDeoptimizationData(Handle<Code> code); |
| 279 | int DefineDeoptimizationLiteral(Handle<Object> literal); |
| 280 | |
| 281 | void PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 282 | |
| 283 | Register ToRegister(int index) const; |
| 284 | DoubleRegister ToDoubleRegister(int index) const; |
| 285 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 286 | MemOperand BuildSeqStringOperand(Register string, |
| 287 | LOperand* index, |
| 288 | String::Encoding encoding); |
| 289 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 290 | void EmitIntegerMathAbs(LMathAbs* instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 291 | |
| 292 | // Support for recording safepoint and position information. |
| 293 | void RecordSafepoint(LPointerMap* pointers, |
| 294 | Safepoint::Kind kind, |
| 295 | int arguments, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 296 | Safepoint::DeoptMode mode); |
| 297 | void RecordSafepoint(LPointerMap* pointers, Safepoint::DeoptMode mode); |
| 298 | void RecordSafepoint(Safepoint::DeoptMode mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 299 | void RecordSafepointWithRegisters(LPointerMap* pointers, |
| 300 | int arguments, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 301 | Safepoint::DeoptMode mode); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 302 | void RecordSafepointWithRegistersAndDoubles(LPointerMap* pointers, |
| 303 | int arguments, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 304 | Safepoint::DeoptMode mode); |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 305 | |
| 306 | void RecordAndWritePosition(int position) V8_OVERRIDE; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 307 | |
| 308 | static Condition TokenToCondition(Token::Value op, bool is_unsigned); |
| 309 | void EmitGoto(int block); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 310 | |
| 311 | // EmitBranch expects to be the last instruction of a block. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 312 | template<class InstrType> |
| 313 | void EmitBranch(InstrType instr, |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 314 | Condition condition, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 315 | Register src1, |
| 316 | const Operand& src2); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 317 | template<class InstrType> |
| 318 | void EmitBranchF(InstrType instr, |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 319 | Condition condition, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 320 | FPURegister src1, |
| 321 | FPURegister src2); |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 322 | template<class InstrType> |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 323 | void EmitFalseBranch(InstrType instr, |
| 324 | Condition condition, |
| 325 | Register src1, |
| 326 | const Operand& src2); |
| 327 | template<class InstrType> |
palfia@homejinni.com | c4c71ea | 2013-08-15 08:05:35 +0000 | [diff] [blame] | 328 | void EmitFalseBranchF(InstrType instr, |
| 329 | Condition condition, |
| 330 | FPURegister src1, |
| 331 | FPURegister src2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 332 | void EmitCmpI(LOperand* left, LOperand* right); |
| 333 | void EmitNumberUntagD(Register input, |
| 334 | DoubleRegister result, |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 335 | bool allow_undefined_as_nan, |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 336 | bool deoptimize_on_minus_zero, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 337 | LEnvironment* env, |
| 338 | NumberUntagDMode mode); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 339 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 340 | // Emits optimized code for typeof x == "y". Modifies input register. |
| 341 | // Returns the condition on which a final split to |
| 342 | // true and false label should be made, to optimize fallthrough. |
| 343 | // Returns two registers in cmp1 and cmp2 that can be used in the |
| 344 | // Branch instruction after EmitTypeofIs. |
| 345 | Condition EmitTypeofIs(Label* true_label, |
| 346 | Label* false_label, |
| 347 | Register input, |
| 348 | Handle<String> type_name, |
| 349 | Register& cmp1, |
| 350 | Operand& cmp2); |
| 351 | |
| 352 | // Emits optimized code for %_IsObject(x). Preserves input register. |
| 353 | // Returns the condition on which a final split to |
| 354 | // true and false label should be made, to optimize fallthrough. |
| 355 | Condition EmitIsObject(Register input, |
| 356 | Register temp1, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 357 | Register temp2, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 358 | Label* is_not_object, |
| 359 | Label* is_object); |
| 360 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 361 | // Emits optimized code for %_IsString(x). Preserves input register. |
| 362 | // Returns the condition on which a final split to |
| 363 | // true and false label should be made, to optimize fallthrough. |
| 364 | Condition EmitIsString(Register input, |
| 365 | Register temp1, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 366 | Label* is_not_string, |
| 367 | SmiCheck check_needed); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 368 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 369 | // Emits optimized code for %_IsConstructCall(). |
| 370 | // Caller should branch on equal condition. |
| 371 | void EmitIsConstructCall(Register temp1, Register temp2); |
| 372 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 373 | // Emits optimized code to deep-copy the contents of statically known |
| 374 | // object graphs (e.g. object literal boilerplate). |
| 375 | void EmitDeepCopy(Handle<JSObject> object, |
| 376 | Register result, |
| 377 | Register source, |
yangguo@chromium.org | 28381b4 | 2013-01-21 14:39:38 +0000 | [diff] [blame] | 378 | int* offset, |
| 379 | AllocationSiteMode mode); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 380 | // Emit optimized code for integer division. |
| 381 | // Inputs are signed. |
| 382 | // All registers are clobbered. |
| 383 | // If 'remainder' is no_reg, it is not computed. |
| 384 | void EmitSignedIntegerDivisionByConstant(Register result, |
| 385 | Register dividend, |
| 386 | int32_t divisor, |
| 387 | Register remainder, |
| 388 | Register scratch, |
| 389 | LEnvironment* environment); |
| 390 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 391 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 392 | void EnsureSpaceForLazyDeopt(int space_needed) V8_OVERRIDE; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 393 | void DoLoadKeyedExternalArray(LLoadKeyed* instr); |
| 394 | void DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr); |
| 395 | void DoLoadKeyedFixedArray(LLoadKeyed* instr); |
| 396 | void DoStoreKeyedExternalArray(LStoreKeyed* instr); |
| 397 | void DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr); |
| 398 | void DoStoreKeyedFixedArray(LStoreKeyed* instr); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 399 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 400 | ZoneList<LEnvironment*> deoptimizations_; |
palfia@homejinni.com | 0410973 | 2013-05-15 09:50:32 +0000 | [diff] [blame] | 401 | ZoneList<Deoptimizer::JumpTableEntry> deopt_jump_table_; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 402 | ZoneList<Handle<Object> > deoptimization_literals_; |
| 403 | int inlined_function_count_; |
| 404 | Scope* const scope_; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 405 | TranslationBuffer translations_; |
| 406 | ZoneList<LDeferredCode*> deferred_; |
| 407 | int osr_pc_offset_; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 408 | bool frame_is_built_; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 409 | |
| 410 | // Builder that keeps track of safepoints in the code. The table |
| 411 | // itself is emitted at the end of the generated code. |
| 412 | SafepointTableBuilder safepoints_; |
| 413 | |
| 414 | // Compiler from a set of parallel moves to a sequential list of moves. |
| 415 | LGapResolver resolver_; |
| 416 | |
| 417 | Safepoint::Kind expected_safepoint_kind_; |
| 418 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 419 | class PushSafepointRegistersScope V8_FINAL BASE_EMBEDDED { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 420 | public: |
| 421 | PushSafepointRegistersScope(LCodeGen* codegen, |
| 422 | Safepoint::Kind kind) |
| 423 | : codegen_(codegen) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 424 | ASSERT(codegen_->info()->is_calling()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 425 | ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kSimple); |
| 426 | codegen_->expected_safepoint_kind_ = kind; |
| 427 | |
| 428 | switch (codegen_->expected_safepoint_kind_) { |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 429 | case Safepoint::kWithRegisters: { |
| 430 | StoreRegistersStateStub stub1(kDontSaveFPRegs); |
| 431 | codegen_->masm_->push(ra); |
| 432 | codegen_->masm_->CallStub(&stub1); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 433 | break; |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 434 | } |
| 435 | case Safepoint::kWithRegistersAndDoubles: { |
| 436 | StoreRegistersStateStub stub2(kSaveFPRegs); |
| 437 | codegen_->masm_->push(ra); |
| 438 | codegen_->masm_->CallStub(&stub2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 439 | break; |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 440 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 441 | default: |
| 442 | UNREACHABLE(); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | ~PushSafepointRegistersScope() { |
| 447 | Safepoint::Kind kind = codegen_->expected_safepoint_kind_; |
| 448 | ASSERT((kind & Safepoint::kWithRegisters) != 0); |
| 449 | switch (kind) { |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 450 | case Safepoint::kWithRegisters: { |
| 451 | RestoreRegistersStateStub stub1(kDontSaveFPRegs); |
| 452 | codegen_->masm_->push(ra); |
| 453 | codegen_->masm_->CallStub(&stub1); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 454 | break; |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 455 | } |
| 456 | case Safepoint::kWithRegistersAndDoubles: { |
| 457 | RestoreRegistersStateStub stub2(kSaveFPRegs); |
| 458 | codegen_->masm_->push(ra); |
| 459 | codegen_->masm_->CallStub(&stub2); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 460 | break; |
yangguo@chromium.org | 4954674 | 2013-12-23 16:17:49 +0000 | [diff] [blame] | 461 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 462 | default: |
| 463 | UNREACHABLE(); |
| 464 | } |
| 465 | codegen_->expected_safepoint_kind_ = Safepoint::kSimple; |
| 466 | } |
| 467 | |
| 468 | private: |
| 469 | LCodeGen* codegen_; |
| 470 | }; |
| 471 | |
| 472 | friend class LDeferredCode; |
| 473 | friend class LEnvironment; |
| 474 | friend class SafepointGenerator; |
| 475 | DISALLOW_COPY_AND_ASSIGN(LCodeGen); |
| 476 | }; |
| 477 | |
| 478 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 479 | class LDeferredCode : public ZoneObject { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 480 | public: |
| 481 | explicit LDeferredCode(LCodeGen* codegen) |
| 482 | : codegen_(codegen), |
| 483 | external_exit_(NULL), |
| 484 | instruction_index_(codegen->current_instruction_) { |
| 485 | codegen->AddDeferredCode(this); |
| 486 | } |
| 487 | |
verwaest@chromium.org | 32cb9b2 | 2013-08-21 11:18:12 +0000 | [diff] [blame] | 488 | virtual ~LDeferredCode() {} |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 489 | virtual void Generate() = 0; |
| 490 | virtual LInstruction* instr() = 0; |
| 491 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 492 | void SetExit(Label* exit) { external_exit_ = exit; } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 493 | Label* entry() { return &entry_; } |
| 494 | Label* exit() { return external_exit_ != NULL ? external_exit_ : &exit_; } |
| 495 | int instruction_index() const { return instruction_index_; } |
| 496 | |
| 497 | protected: |
| 498 | LCodeGen* codegen() const { return codegen_; } |
| 499 | MacroAssembler* masm() const { return codegen_->masm(); } |
| 500 | |
| 501 | private: |
| 502 | LCodeGen* codegen_; |
| 503 | Label entry_; |
| 504 | Label exit_; |
| 505 | Label* external_exit_; |
| 506 | int instruction_index_; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 507 | }; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 508 | |
| 509 | } } // namespace v8::internal |
| 510 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 511 | #endif // V8_MIPS_LITHIUM_CODEGEN_MIPS_H_ |