OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_CODE_ASSEMBLER_H_ | 5 #ifndef V8_COMPILER_CODE_ASSEMBLER_H_ |
6 #define V8_COMPILER_CODE_ASSEMBLER_H_ | 6 #define V8_COMPILER_CODE_ASSEMBLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 class CallDescriptor; | 33 class CallDescriptor; |
34 class CodeAssemblerLabel; | 34 class CodeAssemblerLabel; |
35 class CodeAssemblerVariable; | 35 class CodeAssemblerVariable; |
36 class CodeAssemblerState; | 36 class CodeAssemblerState; |
37 class Node; | 37 class Node; |
38 class RawMachineAssembler; | 38 class RawMachineAssembler; |
39 class RawMachineLabel; | 39 class RawMachineLabel; |
40 | 40 |
41 typedef ZoneList<CodeAssemblerVariable*> CodeAssemblerVariableList; | 41 typedef ZoneList<CodeAssemblerVariable*> CodeAssemblerVariableList; |
42 | 42 |
| 43 typedef std::function<void()> CodeAssemblerCallback; |
| 44 |
43 #define CODE_ASSEMBLER_COMPARE_BINARY_OP_LIST(V) \ | 45 #define CODE_ASSEMBLER_COMPARE_BINARY_OP_LIST(V) \ |
44 V(Float32Equal) \ | 46 V(Float32Equal) \ |
45 V(Float32LessThan) \ | 47 V(Float32LessThan) \ |
46 V(Float32LessThanOrEqual) \ | 48 V(Float32LessThanOrEqual) \ |
47 V(Float32GreaterThan) \ | 49 V(Float32GreaterThan) \ |
48 V(Float32GreaterThanOrEqual) \ | 50 V(Float32GreaterThanOrEqual) \ |
49 V(Float64Equal) \ | 51 V(Float64Equal) \ |
50 V(Float64LessThan) \ | 52 V(Float64LessThan) \ |
51 V(Float64LessThanOrEqual) \ | 53 V(Float64LessThanOrEqual) \ |
52 V(Float64GreaterThan) \ | 54 V(Float64GreaterThan) \ |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // clients, CodeAssembler also provides an abstraction for creating variables | 184 // clients, CodeAssembler also provides an abstraction for creating variables |
183 // and enhanced Label functionality to merge variable values along paths where | 185 // and enhanced Label functionality to merge variable values along paths where |
184 // they have differing values, including loops. | 186 // they have differing values, including loops. |
185 // | 187 // |
186 // The CodeAssembler itself is stateless (and instances are expected to be | 188 // The CodeAssembler itself is stateless (and instances are expected to be |
187 // temporary-scoped and short-lived); all its state is encapsulated into | 189 // temporary-scoped and short-lived); all its state is encapsulated into |
188 // a CodeAssemblerState instance. | 190 // a CodeAssemblerState instance. |
189 class V8_EXPORT_PRIVATE CodeAssembler { | 191 class V8_EXPORT_PRIVATE CodeAssembler { |
190 public: | 192 public: |
191 explicit CodeAssembler(CodeAssemblerState* state) : state_(state) {} | 193 explicit CodeAssembler(CodeAssemblerState* state) : state_(state) {} |
192 | 194 ~CodeAssembler(); |
193 virtual ~CodeAssembler(); | |
194 | 195 |
195 static Handle<Code> GenerateCode(CodeAssemblerState* state); | 196 static Handle<Code> GenerateCode(CodeAssemblerState* state); |
196 | 197 |
197 bool Is64() const; | 198 bool Is64() const; |
198 bool IsFloat64RoundUpSupported() const; | 199 bool IsFloat64RoundUpSupported() const; |
199 bool IsFloat64RoundDownSupported() const; | 200 bool IsFloat64RoundDownSupported() const; |
200 bool IsFloat64RoundTiesEvenSupported() const; | 201 bool IsFloat64RoundTiesEvenSupported() const; |
201 bool IsFloat64RoundTruncateSupported() const; | 202 bool IsFloat64RoundTruncateSupported() const; |
202 | 203 |
203 // Shortened aliases for use in CodeAssembler subclasses. | 204 // Shortened aliases for use in CodeAssembler subclasses. |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // Helpers which delegate to RawMachineAssembler. | 368 // Helpers which delegate to RawMachineAssembler. |
368 Factory* factory() const; | 369 Factory* factory() const; |
369 Isolate* isolate() const; | 370 Isolate* isolate() const; |
370 Zone* zone() const; | 371 Zone* zone() const; |
371 | 372 |
372 CodeAssemblerState* state() { return state_; } | 373 CodeAssemblerState* state() { return state_; } |
373 | 374 |
374 void BreakOnNode(int node_id); | 375 void BreakOnNode(int node_id); |
375 | 376 |
376 protected: | 377 protected: |
377 // Enables subclasses to perform operations before and after a call. | 378 void RegisterCallGenerationCallbacks( |
378 virtual void CallPrologue(); | 379 const CodeAssemblerCallback& call_prologue, |
379 virtual void CallEpilogue(); | 380 const CodeAssemblerCallback& call_epilogue); |
| 381 void UnregisterCallGenerationCallbacks(); |
380 | 382 |
381 private: | 383 private: |
382 RawMachineAssembler* raw_assembler() const; | 384 RawMachineAssembler* raw_assembler() const; |
383 | 385 |
| 386 // Calls respective callback registered in the state. |
| 387 void CallPrologue(); |
| 388 void CallEpilogue(); |
| 389 |
384 CodeAssemblerState* state_; | 390 CodeAssemblerState* state_; |
385 | 391 |
386 DISALLOW_COPY_AND_ASSIGN(CodeAssembler); | 392 DISALLOW_COPY_AND_ASSIGN(CodeAssembler); |
387 }; | 393 }; |
388 | 394 |
389 class CodeAssemblerVariable { | 395 class CodeAssemblerVariable { |
390 public: | 396 public: |
391 explicit CodeAssemblerVariable(CodeAssembler* assembler, | 397 explicit CodeAssemblerVariable(CodeAssembler* assembler, |
392 MachineRepresentation rep); | 398 MachineRepresentation rep); |
393 ~CodeAssemblerVariable(); | 399 ~CodeAssemblerVariable(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 | 476 |
471 CodeAssemblerState(Isolate* isolate, Zone* zone, | 477 CodeAssemblerState(Isolate* isolate, Zone* zone, |
472 CallDescriptor* call_descriptor, Code::Flags flags, | 478 CallDescriptor* call_descriptor, Code::Flags flags, |
473 const char* name); | 479 const char* name); |
474 | 480 |
475 std::unique_ptr<RawMachineAssembler> raw_assembler_; | 481 std::unique_ptr<RawMachineAssembler> raw_assembler_; |
476 Code::Flags flags_; | 482 Code::Flags flags_; |
477 const char* name_; | 483 const char* name_; |
478 bool code_generated_; | 484 bool code_generated_; |
479 ZoneSet<CodeAssemblerVariable::Impl*> variables_; | 485 ZoneSet<CodeAssemblerVariable::Impl*> variables_; |
| 486 CodeAssemblerCallback call_prologue_; |
| 487 CodeAssemblerCallback call_epilogue_; |
480 | 488 |
481 DISALLOW_COPY_AND_ASSIGN(CodeAssemblerState); | 489 DISALLOW_COPY_AND_ASSIGN(CodeAssemblerState); |
482 }; | 490 }; |
483 | 491 |
484 } // namespace compiler | 492 } // namespace compiler |
485 } // namespace internal | 493 } // namespace internal |
486 } // namespace v8 | 494 } // namespace v8 |
487 | 495 |
488 #endif // V8_COMPILER_CODE_ASSEMBLER_H_ | 496 #endif // V8_COMPILER_CODE_ASSEMBLER_H_ |
OLD | NEW |