Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_ARM_LITHIUM_CODEGEN_ARM_H_ |
| 29 | #define V8_ARM_LITHIUM_CODEGEN_ARM_H_ |
| 30 | |
| 31 | #include "arm/lithium-arm.h" |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 32 | #include "arm/lithium-gap-resolver-arm.h" |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 33 | #include "deoptimizer.h" |
| 34 | #include "safepoint-table.h" |
| 35 | #include "scopes.h" |
| 36 | |
| 37 | namespace v8 { |
| 38 | namespace internal { |
| 39 | |
| 40 | // Forward declarations. |
| 41 | class LDeferredCode; |
| 42 | class SafepointGenerator; |
| 43 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 44 | class LCodeGen BASE_EMBEDDED { |
| 45 | public: |
| 46 | LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info) |
| 47 | : chunk_(chunk), |
| 48 | masm_(assembler), |
| 49 | info_(info), |
| 50 | current_block_(-1), |
| 51 | current_instruction_(-1), |
| 52 | instructions_(chunk->instructions()), |
| 53 | deoptimizations_(4), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 54 | deopt_jump_table_(4), |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 55 | deoptimization_literals_(8), |
| 56 | inlined_function_count_(0), |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 57 | scope_(info->scope()), |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 58 | status_(UNUSED), |
| 59 | deferred_(8), |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 60 | osr_pc_offset_(-1), |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 61 | last_lazy_deopt_pc_(0), |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 62 | resolver_(this), |
| 63 | expected_safepoint_kind_(Safepoint::kSimple) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 64 | PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 65 | } |
| 66 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 67 | |
| 68 | // Simple accessors. |
| 69 | MacroAssembler* masm() const { return masm_; } |
| 70 | CompilationInfo* info() const { return info_; } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 71 | Isolate* isolate() const { return info_->isolate(); } |
| 72 | Factory* factory() const { return isolate()->factory(); } |
| 73 | Heap* heap() const { return isolate()->heap(); } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 74 | |
| 75 | // Support for converting LOperands to assembler types. |
| 76 | // LOperand must be a register. |
| 77 | Register ToRegister(LOperand* op) const; |
| 78 | |
| 79 | // LOperand is loaded into scratch, unless already a register. |
| 80 | Register EmitLoadRegister(LOperand* op, Register scratch); |
| 81 | |
| 82 | // LOperand must be a double register. |
| 83 | DoubleRegister ToDoubleRegister(LOperand* op) const; |
| 84 | |
| 85 | // LOperand is loaded into dbl_scratch, unless already a double register. |
| 86 | DoubleRegister EmitLoadDoubleRegister(LOperand* op, |
| 87 | SwVfpRegister flt_scratch, |
| 88 | DoubleRegister dbl_scratch); |
| 89 | int ToInteger32(LConstantOperand* op) const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 90 | double ToDouble(LConstantOperand* op) const; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 91 | Operand ToOperand(LOperand* op); |
| 92 | MemOperand ToMemOperand(LOperand* op) const; |
| 93 | // Returns a MemOperand pointing to the high word of a DoubleStackSlot. |
| 94 | MemOperand ToHighMemOperand(LOperand* op) const; |
| 95 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 96 | bool IsInteger32(LConstantOperand* op) const; |
| 97 | Handle<Object> ToHandle(LConstantOperand* op) const; |
| 98 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 99 | // Try to generate code for the entire chunk, but it may fail if the |
| 100 | // chunk contains constructs we cannot handle. Returns true if the |
| 101 | // code generation attempt succeeded. |
| 102 | bool GenerateCode(); |
| 103 | |
| 104 | // Finish the code by setting stack height, safepoint, and bailout |
| 105 | // information on it. |
| 106 | void FinishCode(Handle<Code> code); |
| 107 | |
| 108 | // Deferred code support. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 109 | template<int T> |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 110 | void DoDeferredBinaryOpStub(LTemplateInstruction<1, 2, T>* instr, |
| 111 | Token::Value op); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 112 | void DoDeferredNumberTagD(LNumberTagD* instr); |
| 113 | void DoDeferredNumberTagI(LNumberTagI* instr); |
| 114 | void DoDeferredTaggedToI(LTaggedToI* instr); |
| 115 | void DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 116 | void DoDeferredStackCheck(LStackCheck* instr); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 117 | void DoDeferredRandom(LRandom* instr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 118 | void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 119 | void DoDeferredStringCharFromCode(LStringCharFromCode* instr); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 120 | void DoDeferredAllocateObject(LAllocateObject* instr); |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 121 | void DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 122 | Label* map_check); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 123 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 124 | void DoCheckMapCommon(Register reg, Register scratch, Handle<Map> map, |
| 125 | CompareMapMode mode, LEnvironment* env); |
| 126 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 127 | // Parallel move support. |
| 128 | void DoParallelMove(LParallelMove* move); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 129 | void DoGap(LGap* instr); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 130 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 131 | // Emit frame translation commands for an environment. |
| 132 | void WriteTranslation(LEnvironment* environment, Translation* translation); |
| 133 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 134 | // Declare methods that deal with the individual node types. |
| 135 | #define DECLARE_DO(type) void Do##type(L##type* node); |
| 136 | LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_DO) |
| 137 | #undef DECLARE_DO |
| 138 | |
| 139 | private: |
| 140 | enum Status { |
| 141 | UNUSED, |
| 142 | GENERATING, |
| 143 | DONE, |
| 144 | ABORTED |
| 145 | }; |
| 146 | |
| 147 | bool is_unused() const { return status_ == UNUSED; } |
| 148 | bool is_generating() const { return status_ == GENERATING; } |
| 149 | bool is_done() const { return status_ == DONE; } |
| 150 | bool is_aborted() const { return status_ == ABORTED; } |
| 151 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 152 | StrictModeFlag strict_mode_flag() const { |
| 153 | return info()->is_classic_mode() ? kNonStrictMode : kStrictMode; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 156 | LChunk* chunk() const { return chunk_; } |
| 157 | Scope* scope() const { return scope_; } |
| 158 | HGraph* graph() const { return chunk_->graph(); } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 159 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 160 | Register scratch0() { return r9; } |
Ben Murdoch | 692be65 | 2012-01-10 18:47:50 +0000 | [diff] [blame] | 161 | DwVfpRegister double_scratch0() { return kScratchDoubleReg; } |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 162 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 163 | int GetNextEmittedBlock(int block); |
| 164 | LInstruction* GetNextInstruction(); |
| 165 | |
| 166 | void EmitClassOfTest(Label* if_true, |
| 167 | Label* if_false, |
| 168 | Handle<String> class_name, |
| 169 | Register input, |
| 170 | Register temporary, |
| 171 | Register temporary2); |
| 172 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 173 | int GetStackSlotCount() const { return chunk()->spill_slot_count(); } |
| 174 | int GetParameterCount() const { return scope()->num_parameters(); } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 175 | |
| 176 | void Abort(const char* format, ...); |
| 177 | void Comment(const char* format, ...); |
| 178 | |
| 179 | void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code); } |
| 180 | |
| 181 | // Code generation passes. Returns true if code generation should |
| 182 | // continue. |
| 183 | bool GeneratePrologue(); |
| 184 | bool GenerateBody(); |
| 185 | bool GenerateDeferredCode(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 186 | bool GenerateDeoptJumpTable(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 187 | bool GenerateSafepointTable(); |
| 188 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 189 | enum SafepointMode { |
| 190 | RECORD_SIMPLE_SAFEPOINT, |
| 191 | RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS |
| 192 | }; |
| 193 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 194 | void CallCode(Handle<Code> code, |
| 195 | RelocInfo::Mode mode, |
| 196 | LInstruction* instr); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 197 | |
| 198 | void CallCodeGeneric(Handle<Code> code, |
| 199 | RelocInfo::Mode mode, |
| 200 | LInstruction* instr, |
| 201 | SafepointMode safepoint_mode); |
| 202 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 203 | void CallRuntime(const Runtime::Function* function, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 204 | int num_arguments, |
| 205 | LInstruction* instr); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 206 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 207 | void CallRuntime(Runtime::FunctionId id, |
| 208 | int num_arguments, |
| 209 | LInstruction* instr) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 210 | const Runtime::Function* function = Runtime::FunctionForId(id); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 211 | CallRuntime(function, num_arguments, instr); |
| 212 | } |
| 213 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 214 | void CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 215 | int argc, |
| 216 | LInstruction* instr); |
| 217 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 218 | // Generate a direct call to a known function. Expects the function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 219 | // to be in r1. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 220 | void CallKnownFunction(Handle<JSFunction> function, |
| 221 | int arity, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 222 | LInstruction* instr, |
| 223 | CallKind call_kind); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 224 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 225 | void LoadHeapObject(Register result, Handle<HeapObject> object); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 226 | |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 227 | void RecordSafepointWithLazyDeopt(LInstruction* instr, |
| 228 | SafepointMode safepoint_mode); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 229 | |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 230 | void RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
| 231 | Safepoint::DeoptMode mode); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 232 | void DeoptimizeIf(Condition cc, LEnvironment* environment); |
| 233 | |
| 234 | void AddToTranslation(Translation* translation, |
| 235 | LOperand* op, |
| 236 | bool is_tagged); |
| 237 | void PopulateDeoptimizationData(Handle<Code> code); |
| 238 | int DefineDeoptimizationLiteral(Handle<Object> literal); |
| 239 | |
| 240 | void PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 241 | |
| 242 | Register ToRegister(int index) const; |
| 243 | DoubleRegister ToDoubleRegister(int index) const; |
| 244 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 245 | // Specific math operations - used from DoUnaryMathOperation. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 246 | void EmitIntegerMathAbs(LUnaryMathOperation* instr); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 247 | void DoMathAbs(LUnaryMathOperation* instr); |
| 248 | void DoMathFloor(LUnaryMathOperation* instr); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 249 | void DoMathRound(LUnaryMathOperation* instr); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 250 | void DoMathSqrt(LUnaryMathOperation* instr); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 251 | void DoMathPowHalf(LUnaryMathOperation* instr); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 252 | void DoMathLog(LUnaryMathOperation* instr); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 253 | void DoMathTan(LUnaryMathOperation* instr); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 254 | void DoMathCos(LUnaryMathOperation* instr); |
| 255 | void DoMathSin(LUnaryMathOperation* instr); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 256 | |
| 257 | // Support for recording safepoint and position information. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 258 | void RecordSafepoint(LPointerMap* pointers, |
| 259 | Safepoint::Kind kind, |
| 260 | int arguments, |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 261 | Safepoint::DeoptMode mode); |
| 262 | void RecordSafepoint(LPointerMap* pointers, Safepoint::DeoptMode mode); |
| 263 | void RecordSafepoint(Safepoint::DeoptMode mode); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 264 | void RecordSafepointWithRegisters(LPointerMap* pointers, |
| 265 | int arguments, |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 266 | Safepoint::DeoptMode mode); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 267 | void RecordSafepointWithRegistersAndDoubles(LPointerMap* pointers, |
| 268 | int arguments, |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 269 | Safepoint::DeoptMode mode); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 270 | void RecordPosition(int position); |
| 271 | |
| 272 | static Condition TokenToCondition(Token::Value op, bool is_unsigned); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 273 | void EmitGoto(int block); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 274 | void EmitBranch(int left_block, int right_block, Condition cc); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 275 | void EmitNumberUntagD(Register input, |
| 276 | DoubleRegister result, |
Ben Murdoch | 7d3e7fc | 2011-07-12 16:37:06 +0100 | [diff] [blame] | 277 | bool deoptimize_on_undefined, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 278 | bool deoptimize_on_minus_zero, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 279 | LEnvironment* env); |
| 280 | |
| 281 | // Emits optimized code for typeof x == "y". Modifies input register. |
| 282 | // Returns the condition on which a final split to |
| 283 | // true and false label should be made, to optimize fallthrough. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 284 | Condition EmitTypeofIs(Label* true_label, |
| 285 | Label* false_label, |
| 286 | Register input, |
| 287 | Handle<String> type_name); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 288 | |
| 289 | // Emits optimized code for %_IsObject(x). Preserves input register. |
| 290 | // Returns the condition on which a final split to |
| 291 | // true and false label should be made, to optimize fallthrough. |
| 292 | Condition EmitIsObject(Register input, |
| 293 | Register temp1, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 294 | Label* is_not_object, |
| 295 | Label* is_object); |
| 296 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 297 | // Emits optimized code for %_IsString(x). Preserves input register. |
| 298 | // Returns the condition on which a final split to |
| 299 | // true and false label should be made, to optimize fallthrough. |
| 300 | Condition EmitIsString(Register input, |
| 301 | Register temp1, |
| 302 | Label* is_not_string); |
| 303 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 304 | // Emits optimized code for %_IsConstructCall(). |
| 305 | // Caller should branch on equal condition. |
| 306 | void EmitIsConstructCall(Register temp1, Register temp2); |
| 307 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 308 | void EmitLoadFieldOrConstantFunction(Register result, |
| 309 | Register object, |
| 310 | Handle<Map> type, |
| 311 | Handle<String> name); |
| 312 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 313 | // Emits optimized code to deep-copy the contents of statically known |
| 314 | // object graphs (e.g. object literal boilerplate). |
| 315 | void EmitDeepCopy(Handle<JSObject> object, |
| 316 | Register result, |
| 317 | Register source, |
| 318 | int* offset); |
| 319 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 320 | struct JumpTableEntry { |
| 321 | explicit inline JumpTableEntry(Address entry) |
| 322 | : label(), |
| 323 | address(entry) { } |
| 324 | Label label; |
| 325 | Address address; |
| 326 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 327 | |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 328 | void EnsureSpaceForLazyDeopt(); |
| 329 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 330 | LChunk* const chunk_; |
| 331 | MacroAssembler* const masm_; |
| 332 | CompilationInfo* const info_; |
| 333 | |
| 334 | int current_block_; |
| 335 | int current_instruction_; |
| 336 | const ZoneList<LInstruction*>* instructions_; |
| 337 | ZoneList<LEnvironment*> deoptimizations_; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 338 | ZoneList<JumpTableEntry> deopt_jump_table_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 339 | ZoneList<Handle<Object> > deoptimization_literals_; |
| 340 | int inlined_function_count_; |
| 341 | Scope* const scope_; |
| 342 | Status status_; |
| 343 | TranslationBuffer translations_; |
| 344 | ZoneList<LDeferredCode*> deferred_; |
| 345 | int osr_pc_offset_; |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 346 | int last_lazy_deopt_pc_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 347 | |
| 348 | // Builder that keeps track of safepoints in the code. The table |
| 349 | // itself is emitted at the end of the generated code. |
| 350 | SafepointTableBuilder safepoints_; |
| 351 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 352 | // Compiler from a set of parallel moves to a sequential list of moves. |
| 353 | LGapResolver resolver_; |
| 354 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 355 | Safepoint::Kind expected_safepoint_kind_; |
| 356 | |
| 357 | class PushSafepointRegistersScope BASE_EMBEDDED { |
| 358 | public: |
| 359 | PushSafepointRegistersScope(LCodeGen* codegen, |
| 360 | Safepoint::Kind kind) |
| 361 | : codegen_(codegen) { |
| 362 | ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kSimple); |
| 363 | codegen_->expected_safepoint_kind_ = kind; |
| 364 | |
| 365 | switch (codegen_->expected_safepoint_kind_) { |
| 366 | case Safepoint::kWithRegisters: |
| 367 | codegen_->masm_->PushSafepointRegisters(); |
| 368 | break; |
| 369 | case Safepoint::kWithRegistersAndDoubles: |
| 370 | codegen_->masm_->PushSafepointRegistersAndDoubles(); |
| 371 | break; |
| 372 | default: |
| 373 | UNREACHABLE(); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | ~PushSafepointRegistersScope() { |
| 378 | Safepoint::Kind kind = codegen_->expected_safepoint_kind_; |
| 379 | ASSERT((kind & Safepoint::kWithRegisters) != 0); |
| 380 | switch (kind) { |
| 381 | case Safepoint::kWithRegisters: |
| 382 | codegen_->masm_->PopSafepointRegisters(); |
| 383 | break; |
| 384 | case Safepoint::kWithRegistersAndDoubles: |
| 385 | codegen_->masm_->PopSafepointRegistersAndDoubles(); |
| 386 | break; |
| 387 | default: |
| 388 | UNREACHABLE(); |
| 389 | } |
| 390 | codegen_->expected_safepoint_kind_ = Safepoint::kSimple; |
| 391 | } |
| 392 | |
| 393 | private: |
| 394 | LCodeGen* codegen_; |
| 395 | }; |
| 396 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 397 | friend class LDeferredCode; |
| 398 | friend class LEnvironment; |
| 399 | friend class SafepointGenerator; |
| 400 | DISALLOW_COPY_AND_ASSIGN(LCodeGen); |
| 401 | }; |
| 402 | |
| 403 | |
| 404 | class LDeferredCode: public ZoneObject { |
| 405 | public: |
| 406 | explicit LDeferredCode(LCodeGen* codegen) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 407 | : codegen_(codegen), |
| 408 | external_exit_(NULL), |
| 409 | instruction_index_(codegen->current_instruction_) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 410 | codegen->AddDeferredCode(this); |
| 411 | } |
| 412 | |
| 413 | virtual ~LDeferredCode() { } |
| 414 | virtual void Generate() = 0; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 415 | virtual LInstruction* instr() = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 416 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 417 | void SetExit(Label* exit) { external_exit_ = exit; } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 418 | Label* entry() { return &entry_; } |
| 419 | Label* exit() { return external_exit_ != NULL ? external_exit_ : &exit_; } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 420 | int instruction_index() const { return instruction_index_; } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 421 | |
| 422 | protected: |
| 423 | LCodeGen* codegen() const { return codegen_; } |
| 424 | MacroAssembler* masm() const { return codegen_->masm(); } |
| 425 | |
| 426 | private: |
| 427 | LCodeGen* codegen_; |
| 428 | Label entry_; |
| 429 | Label exit_; |
| 430 | Label* external_exit_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 431 | int instruction_index_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 432 | }; |
| 433 | |
| 434 | } } // namespace v8::internal |
| 435 | |
| 436 | #endif // V8_ARM_LITHIUM_CODEGEN_ARM_H_ |