| 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 20 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 #include "deoptimizer.h" | 33 #include "deoptimizer.h" |
| 34 #include "safepoint-table.h" | 34 #include "safepoint-table.h" |
| 35 #include "scopes.h" | 35 #include "scopes.h" |
| 36 | 36 |
| 37 namespace v8 { | 37 namespace v8 { |
| 38 namespace internal { | 38 namespace internal { |
| 39 | 39 |
| 40 // Forward declarations. | 40 // Forward declarations. |
| 41 class LDeferredCode; | 41 class LDeferredCode; |
| 42 class LGapNode; |
| 42 class SafepointGenerator; | 43 class SafepointGenerator; |
| 43 | 44 |
| 45 class LGapResolver BASE_EMBEDDED { |
| 46 public: |
| 47 LGapResolver(); |
| 48 const ZoneList<LMoveOperands>* Resolve(const ZoneList<LMoveOperands>* moves, |
| 49 LOperand* marker_operand); |
| 50 |
| 51 private: |
| 52 LGapNode* LookupNode(LOperand* operand); |
| 53 bool CanReach(LGapNode* a, LGapNode* b, int visited_id); |
| 54 bool CanReach(LGapNode* a, LGapNode* b); |
| 55 void RegisterMove(LMoveOperands move); |
| 56 void AddResultMove(LOperand* from, LOperand* to); |
| 57 void AddResultMove(LGapNode* from, LGapNode* to); |
| 58 void ResolveCycle(LGapNode* start, LOperand* marker_operand); |
| 59 |
| 60 ZoneList<LGapNode*> nodes_; |
| 61 ZoneList<LGapNode*> identified_cycles_; |
| 62 ZoneList<LMoveOperands> result_; |
| 63 int next_visited_id_; |
| 64 }; |
| 65 |
| 44 | 66 |
| 45 class LCodeGen BASE_EMBEDDED { | 67 class LCodeGen BASE_EMBEDDED { |
| 46 public: | 68 public: |
| 47 LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info) | 69 LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info) |
| 48 : chunk_(chunk), | 70 : chunk_(chunk), |
| 49 masm_(assembler), | 71 masm_(assembler), |
| 50 info_(info), | 72 info_(info), |
| 51 current_block_(-1), | 73 current_block_(-1), |
| 52 current_instruction_(-1), | 74 current_instruction_(-1), |
| 53 instructions_(chunk->instructions()), | 75 instructions_(chunk->instructions()), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 64 // Try to generate code for the entire chunk, but it may fail if the | 86 // Try to generate code for the entire chunk, but it may fail if the |
| 65 // chunk contains constructs we cannot handle. Returns true if the | 87 // chunk contains constructs we cannot handle. Returns true if the |
| 66 // code generation attempt succeeded. | 88 // code generation attempt succeeded. |
| 67 bool GenerateCode(); | 89 bool GenerateCode(); |
| 68 | 90 |
| 69 // Finish the code by setting stack height, safepoint, and bailout | 91 // Finish the code by setting stack height, safepoint, and bailout |
| 70 // information on it. | 92 // information on it. |
| 71 void FinishCode(Handle<Code> code); | 93 void FinishCode(Handle<Code> code); |
| 72 | 94 |
| 73 // Deferred code support. | 95 // Deferred code support. |
| 96 template<int T> |
| 97 void DoDeferredGenericBinaryStub(LTemplateInstruction<1, 2, T>* instr, |
| 98 Token::Value op); |
| 74 void DoDeferredNumberTagD(LNumberTagD* instr); | 99 void DoDeferredNumberTagD(LNumberTagD* instr); |
| 75 void DoDeferredNumberTagI(LNumberTagI* instr); | 100 void DoDeferredNumberTagI(LNumberTagI* instr); |
| 76 void DoDeferredTaggedToI(LTaggedToI* instr); | 101 void DoDeferredTaggedToI(LTaggedToI* instr); |
| 77 void DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr); | 102 void DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr); |
| 78 void DoDeferredStackCheck(LGoto* instr); | 103 void DoDeferredStackCheck(LGoto* instr); |
| 104 void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); |
| 105 void DoDeferredLInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
| 106 Label* map_check); |
| 79 | 107 |
| 80 // Parallel move support. | 108 // Parallel move support. |
| 81 void DoParallelMove(LParallelMove* move); | 109 void DoParallelMove(LParallelMove* move); |
| 82 | 110 |
| 111 // Emit frame translation commands for an environment. |
| 112 void WriteTranslation(LEnvironment* environment, Translation* translation); |
| 113 |
| 83 // Declare methods that deal with the individual node types. | 114 // Declare methods that deal with the individual node types. |
| 84 #define DECLARE_DO(type) void Do##type(L##type* node); | 115 #define DECLARE_DO(type) void Do##type(L##type* node); |
| 85 LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_DO) | 116 LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_DO) |
| 86 #undef DECLARE_DO | 117 #undef DECLARE_DO |
| 87 | 118 |
| 88 private: | 119 private: |
| 89 enum Status { | 120 enum Status { |
| 90 UNUSED, | 121 UNUSED, |
| 91 GENERATING, | 122 GENERATING, |
| 92 DONE, | 123 DONE, |
| 93 ABORTED | 124 ABORTED |
| 94 }; | 125 }; |
| 95 | 126 |
| 96 bool is_unused() const { return status_ == UNUSED; } | 127 bool is_unused() const { return status_ == UNUSED; } |
| 97 bool is_generating() const { return status_ == GENERATING; } | 128 bool is_generating() const { return status_ == GENERATING; } |
| 98 bool is_done() const { return status_ == DONE; } | 129 bool is_done() const { return status_ == DONE; } |
| 99 bool is_aborted() const { return status_ == ABORTED; } | 130 bool is_aborted() const { return status_ == ABORTED; } |
| 100 | 131 |
| 132 int strict_mode_flag() const { |
| 133 return info_->is_strict() ? kStrictMode : kNonStrictMode; |
| 134 } |
| 135 |
| 101 LChunk* chunk() const { return chunk_; } | 136 LChunk* chunk() const { return chunk_; } |
| 102 Scope* scope() const { return scope_; } | 137 Scope* scope() const { return scope_; } |
| 103 HGraph* graph() const { return chunk_->graph(); } | 138 HGraph* graph() const { return chunk_->graph(); } |
| 104 MacroAssembler* masm() const { return masm_; } | 139 MacroAssembler* masm() const { return masm_; } |
| 105 | 140 |
| 106 Register scratch0() { return r9; } | 141 Register scratch0() { return r9; } |
| 142 DwVfpRegister double_scratch0() { return d0; } |
| 107 | 143 |
| 108 int GetNextEmittedBlock(int block); | 144 int GetNextEmittedBlock(int block); |
| 109 LInstruction* GetNextInstruction(); | 145 LInstruction* GetNextInstruction(); |
| 110 | 146 |
| 111 void EmitClassOfTest(Label* if_true, | 147 void EmitClassOfTest(Label* if_true, |
| 112 Label* if_false, | 148 Label* if_false, |
| 113 Handle<String> class_name, | 149 Handle<String> class_name, |
| 114 Register input, | 150 Register input, |
| 115 Register temporary, | 151 Register temporary, |
| 116 Register temporary2); | 152 Register temporary2); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 142 Runtime::Function* function = Runtime::FunctionForId(id); | 178 Runtime::Function* function = Runtime::FunctionForId(id); |
| 143 CallRuntime(function, num_arguments, instr); | 179 CallRuntime(function, num_arguments, instr); |
| 144 } | 180 } |
| 145 | 181 |
| 146 // Generate a direct call to a known function. Expects the function | 182 // Generate a direct call to a known function. Expects the function |
| 147 // to be in edi. | 183 // to be in edi. |
| 148 void CallKnownFunction(Handle<JSFunction> function, | 184 void CallKnownFunction(Handle<JSFunction> function, |
| 149 int arity, | 185 int arity, |
| 150 LInstruction* instr); | 186 LInstruction* instr); |
| 151 | 187 |
| 152 void LoadPrototype(Register result, Handle<JSObject> prototype); | 188 void LoadHeapObject(Register result, Handle<HeapObject> object); |
| 153 | 189 |
| 154 void RegisterLazyDeoptimization(LInstruction* instr); | 190 void RegisterLazyDeoptimization(LInstruction* instr); |
| 155 void RegisterEnvironmentForDeoptimization(LEnvironment* environment); | 191 void RegisterEnvironmentForDeoptimization(LEnvironment* environment); |
| 156 void DeoptimizeIf(Condition cc, LEnvironment* environment); | 192 void DeoptimizeIf(Condition cc, LEnvironment* environment); |
| 157 | 193 |
| 158 void AddToTranslation(Translation* translation, | 194 void AddToTranslation(Translation* translation, |
| 159 LOperand* op, | 195 LOperand* op, |
| 160 bool is_tagged); | 196 bool is_tagged); |
| 161 void PopulateDeoptimizationData(Handle<Code> code); | 197 void PopulateDeoptimizationData(Handle<Code> code); |
| 162 int DefineDeoptimizationLiteral(Handle<Object> literal); | 198 int DefineDeoptimizationLiteral(Handle<Object> literal); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 178 // LOperand is loaded into dbl_scratch, unless already a double register. | 214 // LOperand is loaded into dbl_scratch, unless already a double register. |
| 179 DoubleRegister EmitLoadDoubleRegister(LOperand* op, | 215 DoubleRegister EmitLoadDoubleRegister(LOperand* op, |
| 180 SwVfpRegister flt_scratch, | 216 SwVfpRegister flt_scratch, |
| 181 DoubleRegister dbl_scratch); | 217 DoubleRegister dbl_scratch); |
| 182 | 218 |
| 183 int ToInteger32(LConstantOperand* op) const; | 219 int ToInteger32(LConstantOperand* op) const; |
| 184 Operand ToOperand(LOperand* op); | 220 Operand ToOperand(LOperand* op); |
| 185 MemOperand ToMemOperand(LOperand* op) const; | 221 MemOperand ToMemOperand(LOperand* op) const; |
| 186 | 222 |
| 187 // Specific math operations - used from DoUnaryMathOperation. | 223 // Specific math operations - used from DoUnaryMathOperation. |
| 224 void EmitIntegerMathAbs(LUnaryMathOperation* instr); |
| 188 void DoMathAbs(LUnaryMathOperation* instr); | 225 void DoMathAbs(LUnaryMathOperation* instr); |
| 226 void EmitVFPTruncate(VFPRoundingMode rounding_mode, |
| 227 SwVfpRegister result, |
| 228 DwVfpRegister double_input, |
| 229 Register scratch1, |
| 230 Register scratch2); |
| 189 void DoMathFloor(LUnaryMathOperation* instr); | 231 void DoMathFloor(LUnaryMathOperation* instr); |
| 190 void DoMathSqrt(LUnaryMathOperation* instr); | 232 void DoMathSqrt(LUnaryMathOperation* instr); |
| 191 | 233 |
| 192 // Support for recording safepoint and position information. | 234 // Support for recording safepoint and position information. |
| 235 void RecordSafepoint(LPointerMap* pointers, |
| 236 Safepoint::Kind kind, |
| 237 int arguments, |
| 238 int deoptimization_index); |
| 193 void RecordSafepoint(LPointerMap* pointers, int deoptimization_index); | 239 void RecordSafepoint(LPointerMap* pointers, int deoptimization_index); |
| 194 void RecordSafepointWithRegisters(LPointerMap* pointers, | 240 void RecordSafepointWithRegisters(LPointerMap* pointers, |
| 195 int arguments, | 241 int arguments, |
| 196 int deoptimization_index); | 242 int deoptimization_index); |
| 243 void RecordSafepointWithRegistersAndDoubles(LPointerMap* pointers, |
| 244 int arguments, |
| 245 int deoptimization_index); |
| 197 void RecordPosition(int position); | 246 void RecordPosition(int position); |
| 198 | 247 |
| 199 static Condition TokenToCondition(Token::Value op, bool is_unsigned); | 248 static Condition TokenToCondition(Token::Value op, bool is_unsigned); |
| 200 void EmitGoto(int block, LDeferredCode* deferred_stack_check = NULL); | 249 void EmitGoto(int block, LDeferredCode* deferred_stack_check = NULL); |
| 201 void EmitBranch(int left_block, int right_block, Condition cc); | 250 void EmitBranch(int left_block, int right_block, Condition cc); |
| 202 void EmitCmpI(LOperand* left, LOperand* right); | 251 void EmitCmpI(LOperand* left, LOperand* right); |
| 203 void EmitNumberUntagD(Register input, | 252 void EmitNumberUntagD(Register input, |
| 204 DoubleRegister result, | 253 DoubleRegister result, |
| 205 LEnvironment* env); | 254 LEnvironment* env); |
| 206 | 255 |
| 207 // Emits optimized code for typeof x == "y". Modifies input register. | 256 // Emits optimized code for typeof x == "y". Modifies input register. |
| 208 // Returns the condition on which a final split to | 257 // Returns the condition on which a final split to |
| 209 // true and false label should be made, to optimize fallthrough. | 258 // true and false label should be made, to optimize fallthrough. |
| 210 Condition EmitTypeofIs(Label* true_label, Label* false_label, | 259 Condition EmitTypeofIs(Label* true_label, Label* false_label, |
| 211 Register input, Handle<String> type_name); | 260 Register input, Handle<String> type_name); |
| 212 | 261 |
| 213 // Emits optimized code for %_IsObject(x). Preserves input register. | 262 // Emits optimized code for %_IsObject(x). Preserves input register. |
| 214 // Returns the condition on which a final split to | 263 // Returns the condition on which a final split to |
| 215 // true and false label should be made, to optimize fallthrough. | 264 // true and false label should be made, to optimize fallthrough. |
| 216 Condition EmitIsObject(Register input, | 265 Condition EmitIsObject(Register input, |
| 217 Register temp1, | 266 Register temp1, |
| 218 Register temp2, | 267 Register temp2, |
| 219 Label* is_not_object, | 268 Label* is_not_object, |
| 220 Label* is_object); | 269 Label* is_object); |
| 221 | 270 |
| 271 // Emits optimized code for %_IsConstructCall(). |
| 272 // Caller should branch on equal condition. |
| 273 void EmitIsConstructCall(Register temp1, Register temp2); |
| 274 |
| 222 LChunk* const chunk_; | 275 LChunk* const chunk_; |
| 223 MacroAssembler* const masm_; | 276 MacroAssembler* const masm_; |
| 224 CompilationInfo* const info_; | 277 CompilationInfo* const info_; |
| 225 | 278 |
| 226 int current_block_; | 279 int current_block_; |
| 227 int current_instruction_; | 280 int current_instruction_; |
| 228 const ZoneList<LInstruction*>* instructions_; | 281 const ZoneList<LInstruction*>* instructions_; |
| 229 ZoneList<LEnvironment*> deoptimizations_; | 282 ZoneList<LEnvironment*> deoptimizations_; |
| 230 ZoneList<Handle<Object> > deoptimization_literals_; | 283 ZoneList<Handle<Object> > deoptimization_literals_; |
| 231 int inlined_function_count_; | 284 int inlined_function_count_; |
| 232 Scope* const scope_; | 285 Scope* const scope_; |
| 233 Status status_; | 286 Status status_; |
| 234 TranslationBuffer translations_; | 287 TranslationBuffer translations_; |
| 235 ZoneList<LDeferredCode*> deferred_; | 288 ZoneList<LDeferredCode*> deferred_; |
| 236 int osr_pc_offset_; | 289 int osr_pc_offset_; |
| 237 | 290 |
| 238 // Builder that keeps track of safepoints in the code. The table | 291 // Builder that keeps track of safepoints in the code. The table |
| 239 // itself is emitted at the end of the generated code. | 292 // itself is emitted at the end of the generated code. |
| 240 SafepointTableBuilder safepoints_; | 293 SafepointTableBuilder safepoints_; |
| 241 | 294 |
| 295 // Compiler from a set of parallel moves to a sequential list of moves. |
| 296 LGapResolver resolver_; |
| 297 |
| 242 friend class LDeferredCode; | 298 friend class LDeferredCode; |
| 243 friend class LEnvironment; | 299 friend class LEnvironment; |
| 244 friend class SafepointGenerator; | 300 friend class SafepointGenerator; |
| 245 DISALLOW_COPY_AND_ASSIGN(LCodeGen); | 301 DISALLOW_COPY_AND_ASSIGN(LCodeGen); |
| 246 }; | 302 }; |
| 247 | 303 |
| 248 | 304 |
| 249 class LDeferredCode: public ZoneObject { | 305 class LDeferredCode: public ZoneObject { |
| 250 public: | 306 public: |
| 251 explicit LDeferredCode(LCodeGen* codegen) | 307 explicit LDeferredCode(LCodeGen* codegen) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 267 private: | 323 private: |
| 268 LCodeGen* codegen_; | 324 LCodeGen* codegen_; |
| 269 Label entry_; | 325 Label entry_; |
| 270 Label exit_; | 326 Label exit_; |
| 271 Label* external_exit_; | 327 Label* external_exit_; |
| 272 }; | 328 }; |
| 273 | 329 |
| 274 } } // namespace v8::internal | 330 } } // namespace v8::internal |
| 275 | 331 |
| 276 #endif // V8_ARM_LITHIUM_CODEGEN_ARM_H_ | 332 #endif // V8_ARM_LITHIUM_CODEGEN_ARM_H_ |
| OLD | NEW |