erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +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 | |
| 28 | #ifndef V8_ARM_LITHIUM_CODEGEN_ARM_H_ |
| 29 | #define V8_ARM_LITHIUM_CODEGEN_ARM_H_ |
| 30 | |
| 31 | #include "arm/lithium-arm.h" |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 32 | #include "arm/lithium-gap-resolver-arm.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [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 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +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)), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +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()), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 57 | inlined_function_count_(0), |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 58 | scope_(info->scope()), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 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()), |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 62 | osr_pc_offset_(-1), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 63 | last_lazy_deopt_pc_(0), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +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()), |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 66 | resolver_(this), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 67 | expected_safepoint_kind_(Safepoint::kSimple) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 68 | PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 69 | } |
| 70 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 71 | |
| 72 | // Simple accessors. |
| 73 | MacroAssembler* masm() const { return masm_; } |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 74 | CompilationInfo* info() const { return info_; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 75 | Isolate* isolate() const { return info_->isolate(); } |
| 76 | Factory* factory() const { return isolate()->factory(); } |
| 77 | Heap* heap() const { return isolate()->heap(); } |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 78 | Zone* zone() const { return zone_; } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 79 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +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 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +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. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame^] | 97 | DwVfpRegister ToDoubleRegister(LOperand* op) const; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 98 | |
| 99 | // LOperand is loaded into dbl_scratch, unless already a double register. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame^] | 100 | DwVfpRegister EmitLoadDoubleRegister(LOperand* op, |
| 101 | SwVfpRegister flt_scratch, |
| 102 | DwVfpRegister dbl_scratch); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 103 | int ToInteger32(LConstantOperand* op) const; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 104 | double ToDouble(LConstantOperand* op) const; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 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; |
| 109 | |
danno@chromium.org | bf0c820 | 2011-12-27 10:09:42 +0000 | [diff] [blame] | 110 | bool IsInteger32(LConstantOperand* op) const; |
| 111 | Handle<Object> ToHandle(LConstantOperand* op) const; |
| 112 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +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. |
| 116 | bool GenerateCode(); |
| 117 | |
| 118 | // Finish the code by setting stack height, safepoint, and bailout |
| 119 | // information on it. |
| 120 | void FinishCode(Handle<Code> code); |
| 121 | |
| 122 | // Deferred code support. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 123 | void DoDeferredBinaryOpStub(LPointerMap* pointer_map, |
| 124 | LOperand* left_argument, |
| 125 | LOperand* right_argument, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 126 | Token::Value op); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 127 | void DoDeferredNumberTagD(LNumberTagD* instr); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 128 | |
| 129 | enum IntegerSignedness { SIGNED_INT32, UNSIGNED_INT32 }; |
| 130 | void DoDeferredNumberTagI(LInstruction* instr, |
| 131 | LOperand* value, |
| 132 | IntegerSignedness signedness); |
| 133 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 134 | void DoDeferredTaggedToI(LTaggedToI* instr); |
| 135 | void DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 136 | void DoDeferredStackCheck(LStackCheck* instr); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 137 | void DoDeferredRandom(LRandom* instr); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 138 | void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 139 | void DoDeferredStringCharFromCode(LStringCharFromCode* instr); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 140 | void DoDeferredAllocateObject(LAllocateObject* instr); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 141 | void DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 142 | Label* map_check); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 143 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame^] | 144 | void DoCheckMapCommon(Register map_reg, Handle<Map> map, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 145 | CompareMapMode mode, LEnvironment* env); |
| 146 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 147 | // Parallel move support. |
| 148 | void DoParallelMove(LParallelMove* move); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 149 | void DoGap(LGap* instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 150 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 151 | MemOperand PrepareKeyedOperand(Register key, |
| 152 | Register base, |
| 153 | bool key_is_constant, |
| 154 | int constant_key, |
| 155 | int element_size, |
| 156 | int shift_size, |
| 157 | int additional_index, |
| 158 | int additional_offset); |
| 159 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 160 | // Emit frame translation commands for an environment. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 161 | void WriteTranslation(LEnvironment* environment, |
| 162 | Translation* translation, |
| 163 | int* arguments_index, |
| 164 | int* arguments_count); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 165 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 166 | // Declare methods that deal with the individual node types. |
| 167 | #define DECLARE_DO(type) void Do##type(L##type* node); |
| 168 | LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_DO) |
| 169 | #undef DECLARE_DO |
| 170 | |
| 171 | private: |
| 172 | enum Status { |
| 173 | UNUSED, |
| 174 | GENERATING, |
| 175 | DONE, |
| 176 | ABORTED |
| 177 | }; |
| 178 | |
| 179 | bool is_unused() const { return status_ == UNUSED; } |
| 180 | bool is_generating() const { return status_ == GENERATING; } |
| 181 | bool is_done() const { return status_ == DONE; } |
| 182 | bool is_aborted() const { return status_ == ABORTED; } |
| 183 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 184 | StrictModeFlag strict_mode_flag() const { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 185 | return info()->is_classic_mode() ? kNonStrictMode : kStrictMode; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 186 | } |
| 187 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 188 | LPlatformChunk* chunk() const { return chunk_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 189 | Scope* scope() const { return scope_; } |
| 190 | HGraph* graph() const { return chunk_->graph(); } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 191 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 192 | Register scratch0() { return r9; } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 193 | DwVfpRegister double_scratch0() { return kScratchDoubleReg; } |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 194 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 195 | int GetNextEmittedBlock(int block); |
| 196 | LInstruction* GetNextInstruction(); |
| 197 | |
| 198 | void EmitClassOfTest(Label* if_true, |
| 199 | Label* if_false, |
| 200 | Handle<String> class_name, |
| 201 | Register input, |
| 202 | Register temporary, |
| 203 | Register temporary2); |
| 204 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 205 | int GetStackSlotCount() const { return chunk()->spill_slot_count(); } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame^] | 206 | int GetParameterCount() const { return info()->num_parameters(); } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 207 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 208 | void Abort(const char* reason); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 209 | void Comment(const char* format, ...); |
| 210 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 211 | void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code, zone()); } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 212 | |
| 213 | // Code generation passes. Returns true if code generation should |
| 214 | // continue. |
| 215 | bool GeneratePrologue(); |
| 216 | bool GenerateBody(); |
| 217 | bool GenerateDeferredCode(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 218 | bool GenerateDeoptJumpTable(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 219 | bool GenerateSafepointTable(); |
| 220 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 221 | enum SafepointMode { |
| 222 | RECORD_SIMPLE_SAFEPOINT, |
| 223 | RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS |
| 224 | }; |
| 225 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 226 | void CallCode( |
| 227 | Handle<Code> code, |
| 228 | RelocInfo::Mode mode, |
| 229 | LInstruction* instr, |
| 230 | TargetAddressStorageMode storage_mode = CAN_INLINE_TARGET_ADDRESS); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 231 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 232 | void CallCodeGeneric( |
| 233 | Handle<Code> code, |
| 234 | RelocInfo::Mode mode, |
| 235 | LInstruction* instr, |
| 236 | SafepointMode safepoint_mode, |
| 237 | TargetAddressStorageMode storage_mode = CAN_INLINE_TARGET_ADDRESS); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 238 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 239 | void CallRuntime(const Runtime::Function* function, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 240 | int num_arguments, |
| 241 | LInstruction* instr); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 242 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 243 | void CallRuntime(Runtime::FunctionId id, |
| 244 | int num_arguments, |
| 245 | LInstruction* instr) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 246 | const Runtime::Function* function = Runtime::FunctionForId(id); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 247 | CallRuntime(function, num_arguments, instr); |
| 248 | } |
| 249 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 250 | void CallRuntimeFromDeferred(Runtime::FunctionId id, |
| 251 | int argc, |
| 252 | LInstruction* instr); |
| 253 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 254 | enum R1State { |
| 255 | R1_UNINITIALIZED, |
| 256 | R1_CONTAINS_TARGET |
| 257 | }; |
| 258 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 259 | // Generate a direct call to a known function. Expects the function |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 260 | // to be in r1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 261 | void CallKnownFunction(Handle<JSFunction> function, |
| 262 | int arity, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 263 | LInstruction* instr, |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 264 | CallKind call_kind, |
| 265 | R1State r1_state); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 266 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 267 | void LoadHeapObject(Register result, Handle<HeapObject> object); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 268 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 269 | void RecordSafepointWithLazyDeopt(LInstruction* instr, |
| 270 | SafepointMode safepoint_mode); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 271 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 272 | void RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
| 273 | Safepoint::DeoptMode mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 274 | void DeoptimizeIf(Condition cc, LEnvironment* environment); |
| 275 | |
| 276 | void AddToTranslation(Translation* translation, |
| 277 | LOperand* op, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 278 | bool is_tagged, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 279 | bool is_uint32, |
| 280 | int arguments_index, |
| 281 | int arguments_count); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 282 | void PopulateDeoptimizationData(Handle<Code> code); |
| 283 | int DefineDeoptimizationLiteral(Handle<Object> literal); |
| 284 | |
| 285 | void PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 286 | |
| 287 | Register ToRegister(int index) const; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame^] | 288 | DwVfpRegister ToDoubleRegister(int index) const; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 289 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 290 | // Specific math operations - used from DoUnaryMathOperation. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 291 | void EmitIntegerMathAbs(LUnaryMathOperation* instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 292 | void DoMathAbs(LUnaryMathOperation* instr); |
| 293 | void DoMathFloor(LUnaryMathOperation* instr); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 294 | void DoMathRound(LUnaryMathOperation* instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 295 | void DoMathSqrt(LUnaryMathOperation* instr); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 296 | void DoMathPowHalf(LUnaryMathOperation* instr); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 297 | void DoMathLog(LUnaryMathOperation* instr); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 298 | void DoMathTan(LUnaryMathOperation* instr); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 299 | void DoMathCos(LUnaryMathOperation* instr); |
| 300 | void DoMathSin(LUnaryMathOperation* instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 301 | |
| 302 | // Support for recording safepoint and position information. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 303 | void RecordSafepoint(LPointerMap* pointers, |
| 304 | Safepoint::Kind kind, |
| 305 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 306 | Safepoint::DeoptMode mode); |
| 307 | void RecordSafepoint(LPointerMap* pointers, Safepoint::DeoptMode mode); |
| 308 | void RecordSafepoint(Safepoint::DeoptMode mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 309 | void RecordSafepointWithRegisters(LPointerMap* pointers, |
| 310 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 311 | Safepoint::DeoptMode mode); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 312 | void RecordSafepointWithRegistersAndDoubles(LPointerMap* pointers, |
| 313 | int arguments, |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 314 | Safepoint::DeoptMode mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 315 | void RecordPosition(int position); |
| 316 | |
| 317 | static Condition TokenToCondition(Token::Value op, bool is_unsigned); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 318 | void EmitGoto(int block); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 319 | void EmitBranch(int left_block, int right_block, Condition cc); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 320 | void EmitNumberUntagD(Register input, |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame^] | 321 | DwVfpRegister result, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 322 | bool deoptimize_on_undefined, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 323 | bool deoptimize_on_minus_zero, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 324 | LEnvironment* env); |
| 325 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 326 | void DeoptIfTaggedButNotSmi(LEnvironment* environment, |
| 327 | HValue* value, |
| 328 | LOperand* operand); |
| 329 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 330 | // Emits optimized code for typeof x == "y". Modifies input register. |
| 331 | // Returns the condition on which a final split to |
| 332 | // true and false label should be made, to optimize fallthrough. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 333 | Condition EmitTypeofIs(Label* true_label, |
| 334 | Label* false_label, |
| 335 | Register input, |
| 336 | Handle<String> type_name); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 337 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 338 | // Emits optimized code for %_IsObject(x). Preserves input register. |
| 339 | // Returns the condition on which a final split to |
| 340 | // true and false label should be made, to optimize fallthrough. |
| 341 | Condition EmitIsObject(Register input, |
| 342 | Register temp1, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 343 | Label* is_not_object, |
| 344 | Label* is_object); |
| 345 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 346 | // Emits optimized code for %_IsString(x). Preserves input register. |
| 347 | // Returns the condition on which a final split to |
| 348 | // true and false label should be made, to optimize fallthrough. |
| 349 | Condition EmitIsString(Register input, |
| 350 | Register temp1, |
| 351 | Label* is_not_string); |
| 352 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 353 | // Emits optimized code for %_IsConstructCall(). |
| 354 | // Caller should branch on equal condition. |
| 355 | void EmitIsConstructCall(Register temp1, Register temp2); |
| 356 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 357 | void EmitLoadFieldOrConstantFunction(Register result, |
| 358 | Register object, |
| 359 | Handle<Map> type, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 360 | Handle<String> name, |
| 361 | LEnvironment* env); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 362 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 363 | // Emits optimized code to deep-copy the contents of statically known |
| 364 | // object graphs (e.g. object literal boilerplate). |
| 365 | void EmitDeepCopy(Handle<JSObject> object, |
| 366 | Register result, |
| 367 | Register source, |
| 368 | int* offset); |
| 369 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 370 | // Emit optimized code for integer division. |
| 371 | // Inputs are signed. |
| 372 | // All registers are clobbered. |
| 373 | // If 'remainder' is no_reg, it is not computed. |
| 374 | void EmitSignedIntegerDivisionByConstant(Register result, |
| 375 | Register dividend, |
| 376 | int32_t divisor, |
| 377 | Register remainder, |
| 378 | Register scratch, |
| 379 | LEnvironment* environment); |
| 380 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 381 | struct JumpTableEntry { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame^] | 382 | inline JumpTableEntry(Address entry, bool frame, bool is_lazy) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 383 | : label(), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame^] | 384 | address(entry), |
| 385 | needs_frame(frame), |
| 386 | is_lazy_deopt(is_lazy) { } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 387 | Label label; |
| 388 | Address address; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame^] | 389 | bool needs_frame; |
| 390 | bool is_lazy_deopt; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 391 | }; |
| 392 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 393 | void EnsureSpaceForLazyDeopt(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +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); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +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_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +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_; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 410 | ZoneList<JumpTableEntry> deopt_jump_table_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 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_; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 418 | int last_lazy_deopt_pc_; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame^] | 419 | bool frame_is_built_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +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 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 425 | // Compiler from a set of parallel moves to a sequential list of moves. |
| 426 | LGapResolver resolver_; |
| 427 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 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) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame^] | 435 | ASSERT(codegen_->info()->is_calling()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +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 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 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) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 481 | : codegen_(codegen), |
| 482 | external_exit_(NULL), |
| 483 | instruction_index_(codegen->current_instruction_) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 484 | codegen->AddDeferredCode(this); |
| 485 | } |
| 486 | |
| 487 | virtual ~LDeferredCode() { } |
| 488 | virtual void Generate() = 0; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 489 | virtual LInstruction* instr() = 0; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 490 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 491 | void SetExit(Label* exit) { external_exit_ = exit; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 492 | Label* entry() { return &entry_; } |
| 493 | Label* exit() { return external_exit_ != NULL ? external_exit_ : &exit_; } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 494 | int instruction_index() const { return instruction_index_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 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_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 505 | int instruction_index_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 506 | }; |
| 507 | |
| 508 | } } // namespace v8::internal |
| 509 | |
| 510 | #endif // V8_ARM_LITHIUM_CODEGEN_ARM_H_ |