1 // Copyright 2022 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_MAGLEV_MAGLEV_COMPILATION_UNIT_H_ 6 #define V8_MAGLEV_MAGLEV_COMPILATION_UNIT_H_ 7 8 #include "src/common/globals.h" 9 #include "src/compiler/bytecode-analysis.h" 10 #include "src/compiler/heap-refs.h" 11 12 namespace v8 { 13 namespace internal { 14 namespace maglev { 15 16 enum class ValueRepresentation; 17 class MaglevCompilationInfo; 18 class MaglevGraphLabeller; 19 class Node; 20 21 // Per-unit data, i.e. once per top-level function and once per inlined 22 // function. 23 class MaglevCompilationUnit : public ZoneObject { 24 public: New(Zone * zone,MaglevCompilationInfo * data,Handle<JSFunction> function)25 static MaglevCompilationUnit* New(Zone* zone, MaglevCompilationInfo* data, 26 Handle<JSFunction> function) { 27 return zone->New<MaglevCompilationUnit>(data, function); 28 } 29 MaglevCompilationUnit(MaglevCompilationInfo* data, 30 Handle<JSFunction> function); 31 info()32 MaglevCompilationInfo* info() const { return info_; } 33 compiler::JSHeapBroker* broker() const; 34 Isolate* isolate() const; 35 LocalIsolate* local_isolate() const; 36 Zone* zone() const; register_count()37 int register_count() const { return register_count_; } parameter_count()38 int parameter_count() const { return parameter_count_; } 39 bool has_graph_labeller() const; 40 MaglevGraphLabeller* graph_labeller() const; shared_function_info()41 const compiler::SharedFunctionInfoRef& shared_function_info() const { 42 return shared_function_info_; 43 } bytecode()44 const compiler::BytecodeArrayRef& bytecode() const { return bytecode_; } feedback()45 const compiler::FeedbackVectorRef& feedback() const { return feedback_; } bytecode_analysis()46 const compiler::BytecodeAnalysis& bytecode_analysis() const { 47 return bytecode_analysis_; 48 } 49 50 void RegisterNodeInGraphLabeller(const Node* node); 51 stack_value_repr()52 const ZoneVector<ValueRepresentation>& stack_value_repr() const { 53 return stack_value_repr_; 54 } 55 push_stack_value_repr(ValueRepresentation r)56 void push_stack_value_repr(ValueRepresentation r) { 57 stack_value_repr_.push_back(r); 58 } 59 60 private: 61 MaglevCompilationInfo* const info_; 62 const compiler::SharedFunctionInfoRef shared_function_info_; 63 const compiler::BytecodeArrayRef bytecode_; 64 const compiler::FeedbackVectorRef feedback_; 65 const compiler::BytecodeAnalysis bytecode_analysis_; 66 const int register_count_; 67 const int parameter_count_; 68 69 // TODO(victorgomes): Compress these values, if only tagged/untagged, we could 70 // use a binary vector? We might also want to deal with safepoints properly. 71 ZoneVector<ValueRepresentation> stack_value_repr_; 72 }; 73 74 } // namespace maglev 75 } // namespace internal 76 } // namespace v8 77 78 #endif // V8_MAGLEV_MAGLEV_COMPILATION_UNIT_H_ 79