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