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