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