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