| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 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_IA32_LITHIUM_CODEGEN_IA32_H_ |
| 29 #define V8_IA32_LITHIUM_CODEGEN_IA32_H_ |
| 30 |
| 31 #include "ia32/lithium-ia32.h" |
| 32 |
| 33 #include "checks.h" |
| 34 #include "deoptimizer.h" |
| 35 #include "safepoint-table.h" |
| 36 #include "scopes.h" |
| 37 |
| 38 namespace v8 { |
| 39 namespace internal { |
| 40 |
| 41 // Forward declarations. |
| 42 class LDeferredCode; |
| 43 class SafepointGenerator; |
| 44 |
| 45 |
| 46 class LCodeGen BASE_EMBEDDED { |
| 47 public: |
| 48 LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info) |
| 49 : chunk_(chunk), |
| 50 masm_(assembler), |
| 51 info_(info), |
| 52 current_block_(-1), |
| 53 current_instruction_(-1), |
| 54 instructions_(chunk->instructions()), |
| 55 deoptimizations_(4), |
| 56 deoptimization_literals_(8), |
| 57 inlined_function_count_(0), |
| 58 scope_(chunk->graph()->info()->scope()), |
| 59 status_(UNUSED), |
| 60 deferred_(8), |
| 61 osr_pc_offset_(-1) { |
| 62 PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 63 } |
| 64 |
| 65 // Try to generate code for the entire chunk, but it may fail if the |
| 66 // chunk contains constructs we cannot handle. Returns true if the |
| 67 // code generation attempt succeeded. |
| 68 bool GenerateCode(); |
| 69 |
| 70 // Finish the code by setting stack height, safepoint, and bailout |
| 71 // information on it. |
| 72 void FinishCode(Handle<Code> code); |
| 73 |
| 74 // Deferred code support. |
| 75 void DoDeferredNumberTagD(LNumberTagD* instr); |
| 76 void DoDeferredNumberTagI(LNumberTagI* instr); |
| 77 void DoDeferredTaggedToI(LTaggedToI* instr); |
| 78 void DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr); |
| 79 void DoDeferredStackCheck(LGoto* instr); |
| 80 |
| 81 // Parallel move support. |
| 82 void DoParallelMove(LParallelMove* move); |
| 83 |
| 84 // Declare methods that deal with the individual node types. |
| 85 #define DECLARE_DO(type) void Do##type(L##type* node); |
| 86 LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_DO) |
| 87 #undef DECLARE_DO |
| 88 |
| 89 private: |
| 90 enum Status { |
| 91 UNUSED, |
| 92 GENERATING, |
| 93 DONE, |
| 94 ABORTED |
| 95 }; |
| 96 |
| 97 bool is_unused() const { return status_ == UNUSED; } |
| 98 bool is_generating() const { return status_ == GENERATING; } |
| 99 bool is_done() const { return status_ == DONE; } |
| 100 bool is_aborted() const { return status_ == ABORTED; } |
| 101 |
| 102 LChunk* chunk() const { return chunk_; } |
| 103 Scope* scope() const { return scope_; } |
| 104 HGraph* graph() const { return chunk_->graph(); } |
| 105 MacroAssembler* masm() const { return masm_; } |
| 106 |
| 107 int GetNextEmittedBlock(int block); |
| 108 LInstruction* GetNextInstruction(); |
| 109 |
| 110 void EmitClassOfTest(Label* if_true, |
| 111 Label* if_false, |
| 112 Handle<String> class_name, |
| 113 Register input, |
| 114 Register temporary, |
| 115 Register temporary2); |
| 116 |
| 117 int StackSlotCount() const { return chunk()->spill_slot_count(); } |
| 118 int ParameterCount() const { return scope()->num_parameters(); } |
| 119 |
| 120 void Abort(const char* format, ...); |
| 121 void Comment(const char* format, ...); |
| 122 |
| 123 void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code); } |
| 124 |
| 125 // Code generation passes. Returns true if code generation should |
| 126 // continue. |
| 127 bool GeneratePrologue(); |
| 128 bool GenerateBody(); |
| 129 bool GenerateDeferredCode(); |
| 130 bool GenerateSafepointTable(); |
| 131 |
| 132 void CallCode(Handle<Code> code, |
| 133 RelocInfo::Mode mode, |
| 134 LInstruction* instr); |
| 135 void CallRuntime(const Runtime::Function* function, |
| 136 int num_arguments, |
| 137 LInstruction* instr); |
| 138 void CallRuntime(Runtime::FunctionId id, |
| 139 int num_arguments, |
| 140 LInstruction* instr) { |
| 141 const Runtime::Function* function = Runtime::FunctionForId(id); |
| 142 CallRuntime(function, num_arguments, instr); |
| 143 } |
| 144 |
| 145 // Generate a direct call to a known function. Expects the function |
| 146 // to be in edi. |
| 147 void CallKnownFunction(Handle<JSFunction> function, |
| 148 int arity, |
| 149 LInstruction* instr); |
| 150 |
| 151 void LoadPrototype(Register result, Handle<JSObject> prototype); |
| 152 |
| 153 void RegisterLazyDeoptimization(LInstruction* instr); |
| 154 void RegisterEnvironmentForDeoptimization(LEnvironment* environment); |
| 155 void DeoptimizeIf(Condition cc, LEnvironment* environment); |
| 156 |
| 157 void AddToTranslation(Translation* translation, |
| 158 LOperand* op, |
| 159 bool is_tagged); |
| 160 void PopulateDeoptimizationData(Handle<Code> code); |
| 161 int DefineDeoptimizationLiteral(Handle<Object> literal); |
| 162 |
| 163 void PopulateDeoptimizationLiteralsWithInlinedFunctions(); |
| 164 |
| 165 Register ToRegister(int index) const; |
| 166 XMMRegister ToDoubleRegister(int index) const; |
| 167 Register ToRegister(LOperand* op) const; |
| 168 XMMRegister ToDoubleRegister(LOperand* op) const; |
| 169 int ToInteger32(LConstantOperand* op) const; |
| 170 Operand ToOperand(LOperand* op) const; |
| 171 Immediate ToImmediate(LOperand* op); |
| 172 |
| 173 // Specific math operations - used from DoUnaryMathOperation. |
| 174 void DoMathAbs(LUnaryMathOperation* instr); |
| 175 void DoMathFloor(LUnaryMathOperation* instr); |
| 176 void DoMathRound(LUnaryMathOperation* instr); |
| 177 void DoMathSqrt(LUnaryMathOperation* instr); |
| 178 |
| 179 // Support for recording safepoint and position information. |
| 180 void RecordSafepoint(LPointerMap* pointers, int deoptimization_index); |
| 181 void RecordSafepointWithRegisters(LPointerMap* pointers, |
| 182 int arguments, |
| 183 int deoptimization_index); |
| 184 void RecordPosition(int position); |
| 185 |
| 186 static Condition TokenToCondition(Token::Value op, bool is_unsigned); |
| 187 void EmitGoto(int block, LDeferredCode* deferred_stack_check = NULL); |
| 188 void EmitBranch(int left_block, int right_block, Condition cc); |
| 189 void EmitCmpI(LOperand* left, LOperand* right); |
| 190 void EmitNumberUntagD(Register input, XMMRegister result, LEnvironment* env); |
| 191 |
| 192 // Emits optimized code for typeof x == "y". Modifies input register. |
| 193 // Returns the condition on which a final split to |
| 194 // true and false label should be made, to optimize fallthrough. |
| 195 Condition EmitTypeofIs(Label* true_label, Label* false_label, |
| 196 Register input, Handle<String> type_name); |
| 197 |
| 198 LChunk* const chunk_; |
| 199 MacroAssembler* const masm_; |
| 200 CompilationInfo* const info_; |
| 201 |
| 202 int current_block_; |
| 203 int current_instruction_; |
| 204 const ZoneList<LInstruction*>* instructions_; |
| 205 ZoneList<LEnvironment*> deoptimizations_; |
| 206 ZoneList<Handle<Object> > deoptimization_literals_; |
| 207 int inlined_function_count_; |
| 208 Scope* const scope_; |
| 209 Status status_; |
| 210 TranslationBuffer translations_; |
| 211 ZoneList<LDeferredCode*> deferred_; |
| 212 int osr_pc_offset_; |
| 213 |
| 214 // Builder that keeps track of safepoints in the code. The table |
| 215 // itself is emitted at the end of the generated code. |
| 216 SafepointTableBuilder safepoints_; |
| 217 |
| 218 friend class LDeferredCode; |
| 219 friend class LEnvironment; |
| 220 friend class SafepointGenerator; |
| 221 DISALLOW_COPY_AND_ASSIGN(LCodeGen); |
| 222 }; |
| 223 |
| 224 |
| 225 class LDeferredCode: public ZoneObject { |
| 226 public: |
| 227 explicit LDeferredCode(LCodeGen* codegen) |
| 228 : codegen_(codegen), external_exit_(NULL) { |
| 229 codegen->AddDeferredCode(this); |
| 230 } |
| 231 |
| 232 virtual ~LDeferredCode() { } |
| 233 virtual void Generate() = 0; |
| 234 |
| 235 void SetExit(Label *exit) { external_exit_ = exit; } |
| 236 Label* entry() { return &entry_; } |
| 237 Label* exit() { return external_exit_ != NULL ? external_exit_ : &exit_; } |
| 238 |
| 239 protected: |
| 240 LCodeGen* codegen() const { return codegen_; } |
| 241 MacroAssembler* masm() const { return codegen_->masm(); } |
| 242 |
| 243 private: |
| 244 LCodeGen* codegen_; |
| 245 Label entry_; |
| 246 Label exit_; |
| 247 Label* external_exit_; |
| 248 }; |
| 249 |
| 250 } } // namespace v8::internal |
| 251 |
| 252 #endif // V8_IA32_LITHIUM_CODEGEN_IA32_H_ |
| OLD | NEW |