Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: src/compiler/code-assembler.h

Issue 2502293002: Reland of [refactoring] Split CodeAssemblerState out of CodeAssembler (Closed)
Patch Set: fix Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/code-stubs-hydrogen.cc ('k') | src/compiler/code-assembler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 23
24 class Callable; 24 class Callable;
25 class CallInterfaceDescriptor; 25 class CallInterfaceDescriptor;
26 class Isolate; 26 class Isolate;
27 class Factory; 27 class Factory;
28 class Zone; 28 class Zone;
29 29
30 namespace compiler { 30 namespace compiler {
31 31
32 class CallDescriptor; 32 class CallDescriptor;
33 class CodeAssemblerState;
33 class Node; 34 class Node;
34 class RawMachineAssembler; 35 class RawMachineAssembler;
35 class RawMachineLabel; 36 class RawMachineLabel;
36 37
37 #define CODE_ASSEMBLER_COMPARE_BINARY_OP_LIST(V) \ 38 #define CODE_ASSEMBLER_COMPARE_BINARY_OP_LIST(V) \
38 V(Float32Equal) \ 39 V(Float32Equal) \
39 V(Float32LessThan) \ 40 V(Float32LessThan) \
40 V(Float32LessThanOrEqual) \ 41 V(Float32LessThanOrEqual) \
41 V(Float32GreaterThan) \ 42 V(Float32GreaterThan) \
42 V(Float32GreaterThanOrEqual) \ 43 V(Float32GreaterThanOrEqual) \
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // V8 components that need to generate low-level code using this interface 167 // V8 components that need to generate low-level code using this interface
167 // should include this header--and this header only--from the compiler directory 168 // should include this header--and this header only--from the compiler directory
168 // (this is actually enforced). Since all interesting data structures are 169 // (this is actually enforced). Since all interesting data structures are
169 // forward declared, it's not possible for clients to peek inside the compiler 170 // forward declared, it's not possible for clients to peek inside the compiler
170 // internals. 171 // internals.
171 // 172 //
172 // In addition to providing isolation between TurboFan and code generation 173 // In addition to providing isolation between TurboFan and code generation
173 // clients, CodeAssembler also provides an abstraction for creating variables 174 // clients, CodeAssembler also provides an abstraction for creating variables
174 // and enhanced Label functionality to merge variable values along paths where 175 // and enhanced Label functionality to merge variable values along paths where
175 // they have differing values, including loops. 176 // they have differing values, including loops.
177 //
178 // The CodeAssembler itself is stateless (and instances are expected to be
179 // temporary-scoped and short-lived); all its state is encapsulated into
180 // a CodeAssemblerState instance.
176 class V8_EXPORT_PRIVATE CodeAssembler { 181 class V8_EXPORT_PRIVATE CodeAssembler {
177 public: 182 public:
178 // Create with CallStub linkage. 183 explicit CodeAssembler(CodeAssemblerState* state) : state_(state) {}
179 // |result_size| specifies the number of results returned by the stub.
180 // TODO(rmcilroy): move result_size to the CallInterfaceDescriptor.
181 CodeAssembler(Isolate* isolate, Zone* zone,
182 const CallInterfaceDescriptor& descriptor, Code::Flags flags,
183 const char* name, size_t result_size = 1);
184
185 // Create with JSCall linkage.
186 CodeAssembler(Isolate* isolate, Zone* zone, int parameter_count,
187 Code::Flags flags, const char* name);
188 184
189 virtual ~CodeAssembler(); 185 virtual ~CodeAssembler();
190 186
191 Handle<Code> GenerateCode(); 187 static Handle<Code> GenerateCode(CodeAssemblerState* state);
192 188
193 bool Is64() const; 189 bool Is64() const;
194 bool IsFloat64RoundUpSupported() const; 190 bool IsFloat64RoundUpSupported() const;
195 bool IsFloat64RoundDownSupported() const; 191 bool IsFloat64RoundDownSupported() const;
196 bool IsFloat64RoundTruncateSupported() const; 192 bool IsFloat64RoundTruncateSupported() const;
197 193
198 class Label; 194 class Label;
199 class Variable { 195 class Variable {
200 public: 196 public:
201 explicit Variable(CodeAssembler* assembler, MachineRepresentation rep); 197 explicit Variable(CodeAssembler* assembler, MachineRepresentation rep);
202 ~Variable(); 198 ~Variable();
203 void Bind(Node* value); 199 void Bind(Node* value);
204 Node* value() const; 200 Node* value() const;
205 MachineRepresentation rep() const; 201 MachineRepresentation rep() const;
206 bool IsBound() const; 202 bool IsBound() const;
207 203
208 private: 204 private:
209 friend class CodeAssembler; 205 friend class CodeAssembler;
206 friend class CodeAssemblerState;
210 class Impl; 207 class Impl;
211 Impl* impl_; 208 Impl* impl_;
212 CodeAssembler* assembler_; 209 CodeAssemblerState* state_;
213 }; 210 };
214 211
215 typedef ZoneList<Variable*> VariableList; 212 typedef ZoneList<Variable*> VariableList;
216 213
217 // =========================================================================== 214 // ===========================================================================
218 // Base Assembler 215 // Base Assembler
219 // =========================================================================== 216 // ===========================================================================
220 217
221 // Constants. 218 // Constants.
222 Node* Int32Constant(int32_t value); 219 Node* Int32Constant(int32_t value);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 Factory* factory() const; 461 Factory* factory() const;
465 Isolate* isolate() const; 462 Isolate* isolate() const;
466 Zone* zone() const; 463 Zone* zone() const;
467 464
468 protected: 465 protected:
469 // Enables subclasses to perform operations before and after a call. 466 // Enables subclasses to perform operations before and after a call.
470 virtual void CallPrologue(); 467 virtual void CallPrologue();
471 virtual void CallEpilogue(); 468 virtual void CallEpilogue();
472 469
473 private: 470 private:
474 CodeAssembler(Isolate* isolate, Zone* zone, CallDescriptor* call_descriptor,
475 Code::Flags flags, const char* name);
476
477 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args); 471 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args);
478 Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args); 472 Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args);
479 473
480 std::unique_ptr<RawMachineAssembler> raw_assembler_; 474 RawMachineAssembler* raw_assembler() const;
481 Code::Flags flags_; 475
482 const char* name_; 476 CodeAssemblerState* state_;
483 bool code_generated_;
484 ZoneSet<Variable::Impl*> variables_;
485 477
486 DISALLOW_COPY_AND_ASSIGN(CodeAssembler); 478 DISALLOW_COPY_AND_ASSIGN(CodeAssembler);
487 }; 479 };
488 480
489 class CodeAssembler::Label { 481 class CodeAssembler::Label {
490 public: 482 public:
491 enum Type { kDeferred, kNonDeferred }; 483 enum Type { kDeferred, kNonDeferred };
492 484
493 explicit Label( 485 explicit Label(
494 CodeAssembler* assembler, 486 CodeAssembler* assembler,
(...skipping 11 matching lines...) Expand all
506 ~Label() {} 498 ~Label() {}
507 499
508 private: 500 private:
509 friend class CodeAssembler; 501 friend class CodeAssembler;
510 502
511 void Bind(); 503 void Bind();
512 void MergeVariables(); 504 void MergeVariables();
513 505
514 bool bound_; 506 bool bound_;
515 size_t merge_count_; 507 size_t merge_count_;
516 CodeAssembler* assembler_; 508 CodeAssemblerState* state_;
517 RawMachineLabel* label_; 509 RawMachineLabel* label_;
518 // Map of variables that need to be merged to their phi nodes (or placeholders 510 // Map of variables that need to be merged to their phi nodes (or placeholders
519 // for those phis). 511 // for those phis).
520 std::map<Variable::Impl*, Node*> variable_phis_; 512 std::map<Variable::Impl*, Node*> variable_phis_;
521 // Map of variables to the list of value nodes that have been added from each 513 // Map of variables to the list of value nodes that have been added from each
522 // merge path in their order of merging. 514 // merge path in their order of merging.
523 std::map<Variable::Impl*, std::vector<Node*>> variable_merges_; 515 std::map<Variable::Impl*, std::vector<Node*>> variable_merges_;
524 }; 516 };
525 517
518 class V8_EXPORT_PRIVATE CodeAssemblerState {
519 public:
520 // Create with CallStub linkage.
521 // |result_size| specifies the number of results returned by the stub.
522 // TODO(rmcilroy): move result_size to the CallInterfaceDescriptor.
523 CodeAssemblerState(Isolate* isolate, Zone* zone,
524 const CallInterfaceDescriptor& descriptor,
525 Code::Flags flags, const char* name,
526 size_t result_size = 1);
527
528 // Create with JSCall linkage.
529 CodeAssemblerState(Isolate* isolate, Zone* zone, int parameter_count,
530 Code::Flags flags, const char* name);
531
532 ~CodeAssemblerState();
533
534 private:
535 friend class CodeAssembler;
536
537 CodeAssemblerState(Isolate* isolate, Zone* zone,
538 CallDescriptor* call_descriptor, Code::Flags flags,
539 const char* name);
540
541 std::unique_ptr<RawMachineAssembler> raw_assembler_;
542 Code::Flags flags_;
543 const char* name_;
544 bool code_generated_;
545 ZoneSet<CodeAssembler::Variable::Impl*> variables_;
546
547 DISALLOW_COPY_AND_ASSIGN(CodeAssemblerState);
548 };
549
526 } // namespace compiler 550 } // namespace compiler
527 } // namespace internal 551 } // namespace internal
528 } // namespace v8 552 } // namespace v8
529 553
530 #endif // V8_COMPILER_CODE_ASSEMBLER_H_ 554 #endif // V8_COMPILER_CODE_ASSEMBLER_H_
OLDNEW
« no previous file with comments | « src/code-stubs-hydrogen.cc ('k') | src/compiler/code-assembler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698