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