Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1 | // Copyright 2011 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 | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 61 | resolver_(this), |
| 62 | expected_safepoint_kind_(Safepoint::kSimple) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 63 | PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 64 | } |
| 65 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 66 | |
| 67 | // Simple accessors. |
| 68 | MacroAssembler* masm() const { return masm_; } |
| 69 | CompilationInfo* info() const { return info_; } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 70 | Isolate* isolate() const { return info_->isolate(); } |
| 71 | Factory* factory() const { return isolate()->factory(); } |
| 72 | Heap* heap() const { return isolate()->heap(); } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 73 | |
| 74 | // Support for converting LOperands to assembler types. |
| 75 | // LOperand must be a register. |
| 76 | Register ToRegister(LOperand* op) const; |
| 77 | |
| 78 | // LOperand is loaded into scratch, unless already a register. |
| 79 | Register EmitLoadRegister(LOperand* op, Register scratch); |
| 80 | |
| 81 | // LOperand must be a double register. |
| 82 | DoubleRegister ToDoubleRegister(LOperand* op) const; |
| 83 | |
| 84 | // LOperand is loaded into dbl_scratch, unless already a double register. |
| 85 | DoubleRegister EmitLoadDoubleRegister(LOperand* op, |
| 86 | SwVfpRegister flt_scratch, |
| 87 | DoubleRegister dbl_scratch); |
| 88 | int ToInteger32(LConstantOperand* op) const; |
| 89 | Operand ToOperand(LOperand* op); |
| 90 | MemOperand ToMemOperand(LOperand* op) const; |
| 91 | // Returns a MemOperand pointing to the high word of a DoubleStackSlot. |
| 92 | MemOperand ToHighMemOperand(LOperand* op) const; |
| 93 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 94 | // Try to generate code for the entire chunk, but it may fail if the |
| 95 | // chunk contains constructs we cannot handle. Returns true if the |
| 96 | // code generation attempt succeeded. |
| 97 | bool GenerateCode(); |
| 98 | |
| 99 | // Finish the code by setting stack height, safepoint, and bailout |
| 100 | // information on it. |
| 101 | void FinishCode(Handle<Code> code); |
| 102 | |
| 103 | // Deferred code support. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 104 | template<int T> |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 105 | void DoDeferredBinaryOpStub(LTemplateInstruction<1, 2, T>* instr, |
| 106 | Token::Value op); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 107 | void DoDeferredNumberTagD(LNumberTagD* instr); |
| 108 | void DoDeferredNumberTagI(LNumberTagI* instr); |
| 109 | void DoDeferredTaggedToI(LTaggedToI* instr); |
| 110 | void DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr); |
| 111 | void DoDeferredStackCheck(LGoto* instr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 112 | void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 113 | void DoDeferredStringCharFromCode(LStringCharFromCode* instr); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 114 | void DoDeferredLInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 115 | Label* map_check); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 116 | |
| 117 | // Parallel move support. |
| 118 | void DoParallelMove(LParallelMove* move); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 119 | void DoGap(LGap* instr); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 120 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 121 | // Emit frame translation commands for an environment. |
| 122 | void WriteTranslation(LEnvironment* environment, Translation* translation); |
| 123 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 124 | // Declare methods that deal with the individual node types. |
| 125 | #define DECLARE_DO(type) void Do##type(L##type* node); |
| 126 | LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_DO) |
| 127 | #undef DECLARE_DO |
| 128 | |
| 129 | private: |
| 130 | enum Status { |
| 131 | UNUSED, |
| 132 | GENERATING, |
| 133 | DONE, |
| 134 | ABORTED |
| 135 | }; |
| 136 | |
| 137 | bool is_unused() const { return status_ == UNUSED; } |
| 138 | bool is_generating() const { return status_ == GENERATING; } |
| 139 | bool is_done() const { return status_ == DONE; } |
| 140 | bool is_aborted() const { return status_ == ABORTED; } |
| 141 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 142 | int strict_mode_flag() const { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 143 | return info()->is_strict_mode() ? kStrictMode : kNonStrictMode; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 144 | } |
| 145 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 146 | LChunk* chunk() const { return chunk_; } |
| 147 | Scope* scope() const { return scope_; } |
| 148 | HGraph* graph() const { return chunk_->graph(); } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 149 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 150 | Register scratch0() { return r9; } |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 151 | DwVfpRegister double_scratch0() { return d0; } |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 152 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 153 | int GetNextEmittedBlock(int block); |
| 154 | LInstruction* GetNextInstruction(); |
| 155 | |
| 156 | void EmitClassOfTest(Label* if_true, |
| 157 | Label* if_false, |
| 158 | Handle<String> class_name, |
| 159 | Register input, |
| 160 | Register temporary, |
| 161 | Register temporary2); |
| 162 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 163 | int GetStackSlotCount() const { return chunk()->spill_slot_count(); } |
| 164 | int GetParameterCount() const { return scope()->num_parameters(); } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 165 | |
| 166 | void Abort(const char* format, ...); |
| 167 | void Comment(const char* format, ...); |
| 168 | |
| 169 | void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code); } |
| 170 | |
| 171 | // Code generation passes. Returns true if code generation should |
| 172 | // continue. |
| 173 | bool GeneratePrologue(); |
| 174 | bool GenerateBody(); |
| 175 | bool GenerateDeferredCode(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 176 | bool GenerateDeoptJumpTable(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 177 | bool GenerateSafepointTable(); |
| 178 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 179 | enum SafepointMode { |
| 180 | RECORD_SIMPLE_SAFEPOINT, |
| 181 | RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS |
| 182 | }; |
| 183 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 184 | void CallCode(Handle<Code> code, |
| 185 | RelocInfo::Mode mode, |
| 186 | LInstruction* instr); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 187 | |
| 188 | void CallCodeGeneric(Handle<Code> code, |
| 189 | RelocInfo::Mode mode, |
| 190 | LInstruction* instr, |
| 191 | SafepointMode safepoint_mode); |
| 192 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 193 | void CallRuntime(const Runtime::Function* function, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 194 | int num_arguments, |
| 195 | LInstruction* instr); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 196 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 197 | void CallRuntime(Runtime::FunctionId id, |
| 198 | int num_arguments, |
| 199 | LInstruction* instr) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 200 | const Runtime::Function* function = Runtime::FunctionForId(id); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 201 | CallRuntime(function, num_arguments, instr); |
| 202 | } |
| 203 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 204 | void CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 205 | int argc, |
| 206 | LInstruction* instr); |
| 207 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 208 | // Generate a direct call to a known function. Expects the function |
| 209 | // to be in edi. |
| 210 | void CallKnownFunction(Handle<JSFunction> function, |
| 211 | int arity, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 212 | LInstruction* instr, |
| 213 | CallKind call_kind); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 214 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 215 | void LoadHeapObject(Register result, Handle<HeapObject> object); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 216 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 217 | void RegisterLazyDeoptimization(LInstruction* instr, |
| 218 | SafepointMode safepoint_mode); |
| 219 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 220 | void RegisterEnvironmentForDeoptimization(LEnvironment* environment); |
| 221 | void DeoptimizeIf(Condition cc, LEnvironment* environment); |
| 222 | |
| 223 | void AddToTranslation(Translation* translation, |
| 224 | LOperand* op, |
| 225 | bool is_tagged); |
| 226 | void PopulateDeoptimizationData(Handle<Code> code); |
| 227 | int DefineDeoptimizationLiteral(Handle<Object> literal); |
| 228 | |
| 229 | void PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 230 | |
| 231 | Register ToRegister(int index) const; |
| 232 | DoubleRegister ToDoubleRegister(int index) const; |
| 233 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 234 | // Specific math operations - used from DoUnaryMathOperation. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 235 | void EmitIntegerMathAbs(LUnaryMathOperation* instr); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 236 | void DoMathAbs(LUnaryMathOperation* instr); |
| 237 | void DoMathFloor(LUnaryMathOperation* instr); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 238 | void DoMathRound(LUnaryMathOperation* instr); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 239 | void DoMathSqrt(LUnaryMathOperation* instr); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 240 | void DoMathPowHalf(LUnaryMathOperation* instr); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 241 | void DoMathLog(LUnaryMathOperation* instr); |
| 242 | void DoMathCos(LUnaryMathOperation* instr); |
| 243 | void DoMathSin(LUnaryMathOperation* instr); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 244 | |
| 245 | // Support for recording safepoint and position information. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 246 | void RecordSafepoint(LPointerMap* pointers, |
| 247 | Safepoint::Kind kind, |
| 248 | int arguments, |
| 249 | int deoptimization_index); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 250 | void RecordSafepoint(LPointerMap* pointers, int deoptimization_index); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 251 | void RecordSafepoint(int deoptimization_index); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 252 | void RecordSafepointWithRegisters(LPointerMap* pointers, |
| 253 | int arguments, |
| 254 | int deoptimization_index); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 255 | void RecordSafepointWithRegistersAndDoubles(LPointerMap* pointers, |
| 256 | int arguments, |
| 257 | int deoptimization_index); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 258 | void RecordPosition(int position); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 259 | int LastSafepointEnd() { |
| 260 | return static_cast<int>(safepoints_.GetPcAfterGap()); |
| 261 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 262 | |
| 263 | static Condition TokenToCondition(Token::Value op, bool is_unsigned); |
| 264 | void EmitGoto(int block, LDeferredCode* deferred_stack_check = NULL); |
| 265 | void EmitBranch(int left_block, int right_block, Condition cc); |
| 266 | void EmitCmpI(LOperand* left, LOperand* right); |
| 267 | void EmitNumberUntagD(Register input, |
| 268 | DoubleRegister result, |
Ben Murdoch | 7d3e7fc | 2011-07-12 16:37:06 +0100 | [diff] [blame] | 269 | bool deoptimize_on_undefined, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 270 | LEnvironment* env); |
| 271 | |
| 272 | // Emits optimized code for typeof x == "y". Modifies input register. |
| 273 | // Returns the condition on which a final split to |
| 274 | // true and false label should be made, to optimize fallthrough. |
| 275 | Condition EmitTypeofIs(Label* true_label, Label* false_label, |
| 276 | Register input, Handle<String> type_name); |
| 277 | |
| 278 | // Emits optimized code for %_IsObject(x). Preserves input register. |
| 279 | // Returns the condition on which a final split to |
| 280 | // true and false label should be made, to optimize fallthrough. |
| 281 | Condition EmitIsObject(Register input, |
| 282 | Register temp1, |
| 283 | Register temp2, |
| 284 | Label* is_not_object, |
| 285 | Label* is_object); |
| 286 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 287 | // Emits optimized code for %_IsConstructCall(). |
| 288 | // Caller should branch on equal condition. |
| 289 | void EmitIsConstructCall(Register temp1, Register temp2); |
| 290 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 291 | void EmitLoadFieldOrConstantFunction(Register result, |
| 292 | Register object, |
| 293 | Handle<Map> type, |
| 294 | Handle<String> name); |
| 295 | |
| 296 | struct JumpTableEntry { |
| 297 | explicit inline JumpTableEntry(Address entry) |
| 298 | : label(), |
| 299 | address(entry) { } |
| 300 | Label label; |
| 301 | Address address; |
| 302 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 303 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 304 | LChunk* const chunk_; |
| 305 | MacroAssembler* const masm_; |
| 306 | CompilationInfo* const info_; |
| 307 | |
| 308 | int current_block_; |
| 309 | int current_instruction_; |
| 310 | const ZoneList<LInstruction*>* instructions_; |
| 311 | ZoneList<LEnvironment*> deoptimizations_; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 312 | ZoneList<JumpTableEntry> deopt_jump_table_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 313 | ZoneList<Handle<Object> > deoptimization_literals_; |
| 314 | int inlined_function_count_; |
| 315 | Scope* const scope_; |
| 316 | Status status_; |
| 317 | TranslationBuffer translations_; |
| 318 | ZoneList<LDeferredCode*> deferred_; |
| 319 | int osr_pc_offset_; |
| 320 | |
| 321 | // Builder that keeps track of safepoints in the code. The table |
| 322 | // itself is emitted at the end of the generated code. |
| 323 | SafepointTableBuilder safepoints_; |
| 324 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 325 | // Compiler from a set of parallel moves to a sequential list of moves. |
| 326 | LGapResolver resolver_; |
| 327 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 328 | Safepoint::Kind expected_safepoint_kind_; |
| 329 | |
| 330 | class PushSafepointRegistersScope BASE_EMBEDDED { |
| 331 | public: |
| 332 | PushSafepointRegistersScope(LCodeGen* codegen, |
| 333 | Safepoint::Kind kind) |
| 334 | : codegen_(codegen) { |
| 335 | ASSERT(codegen_->expected_safepoint_kind_ == Safepoint::kSimple); |
| 336 | codegen_->expected_safepoint_kind_ = kind; |
| 337 | |
| 338 | switch (codegen_->expected_safepoint_kind_) { |
| 339 | case Safepoint::kWithRegisters: |
| 340 | codegen_->masm_->PushSafepointRegisters(); |
| 341 | break; |
| 342 | case Safepoint::kWithRegistersAndDoubles: |
| 343 | codegen_->masm_->PushSafepointRegistersAndDoubles(); |
| 344 | break; |
| 345 | default: |
| 346 | UNREACHABLE(); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | ~PushSafepointRegistersScope() { |
| 351 | Safepoint::Kind kind = codegen_->expected_safepoint_kind_; |
| 352 | ASSERT((kind & Safepoint::kWithRegisters) != 0); |
| 353 | switch (kind) { |
| 354 | case Safepoint::kWithRegisters: |
| 355 | codegen_->masm_->PopSafepointRegisters(); |
| 356 | break; |
| 357 | case Safepoint::kWithRegistersAndDoubles: |
| 358 | codegen_->masm_->PopSafepointRegistersAndDoubles(); |
| 359 | break; |
| 360 | default: |
| 361 | UNREACHABLE(); |
| 362 | } |
| 363 | codegen_->expected_safepoint_kind_ = Safepoint::kSimple; |
| 364 | } |
| 365 | |
| 366 | private: |
| 367 | LCodeGen* codegen_; |
| 368 | }; |
| 369 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 370 | friend class LDeferredCode; |
| 371 | friend class LEnvironment; |
| 372 | friend class SafepointGenerator; |
| 373 | DISALLOW_COPY_AND_ASSIGN(LCodeGen); |
| 374 | }; |
| 375 | |
| 376 | |
| 377 | class LDeferredCode: public ZoneObject { |
| 378 | public: |
| 379 | explicit LDeferredCode(LCodeGen* codegen) |
| 380 | : codegen_(codegen), external_exit_(NULL) { |
| 381 | codegen->AddDeferredCode(this); |
| 382 | } |
| 383 | |
| 384 | virtual ~LDeferredCode() { } |
| 385 | virtual void Generate() = 0; |
| 386 | |
| 387 | void SetExit(Label *exit) { external_exit_ = exit; } |
| 388 | Label* entry() { return &entry_; } |
| 389 | Label* exit() { return external_exit_ != NULL ? external_exit_ : &exit_; } |
| 390 | |
| 391 | protected: |
| 392 | LCodeGen* codegen() const { return codegen_; } |
| 393 | MacroAssembler* masm() const { return codegen_->masm(); } |
| 394 | |
| 395 | private: |
| 396 | LCodeGen* codegen_; |
| 397 | Label entry_; |
| 398 | Label exit_; |
| 399 | Label* external_exit_; |
| 400 | }; |
| 401 | |
| 402 | } } // namespace v8::internal |
| 403 | |
| 404 | #endif // V8_ARM_LITHIUM_CODEGEN_ARM_H_ |