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