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