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 #include "src/maglev/maglev-compilation-unit.h"
6
7 #include "src/compiler/js-heap-broker.h"
8 #include "src/maglev/maglev-compilation-info.h"
9 #include "src/maglev/maglev-graph-labeller.h"
10 #include "src/objects/js-function-inl.h"
11
12 namespace v8 {
13 namespace internal {
14 namespace maglev {
15
MaglevCompilationUnit(MaglevCompilationInfo * info,Handle<JSFunction> function)16 MaglevCompilationUnit::MaglevCompilationUnit(MaglevCompilationInfo* info,
17 Handle<JSFunction> function)
18 : info_(info),
19 shared_function_info_(MakeRef(broker(), function->shared())),
20 bytecode_(shared_function_info_.GetBytecodeArray()),
21 feedback_(MakeRef(broker(), function->feedback_vector())),
22 bytecode_analysis_(bytecode_.object(), zone(), BytecodeOffset::None(),
23 true),
24 register_count_(bytecode_.register_count()),
25 parameter_count_(bytecode_.parameter_count()),
26 stack_value_repr_(info->zone()) {}
27
broker() const28 compiler::JSHeapBroker* MaglevCompilationUnit::broker() const {
29 return info_->broker();
30 }
31
isolate() const32 Isolate* MaglevCompilationUnit::isolate() const { return info_->isolate(); }
33
zone() const34 Zone* MaglevCompilationUnit::zone() const { return info_->zone(); }
35
has_graph_labeller() const36 bool MaglevCompilationUnit::has_graph_labeller() const {
37 return info_->has_graph_labeller();
38 }
39
graph_labeller() const40 MaglevGraphLabeller* MaglevCompilationUnit::graph_labeller() const {
41 DCHECK(has_graph_labeller());
42 return info_->graph_labeller();
43 }
44
RegisterNodeInGraphLabeller(const Node * node)45 void MaglevCompilationUnit::RegisterNodeInGraphLabeller(const Node* node) {
46 if (has_graph_labeller()) {
47 graph_labeller()->RegisterNode(node);
48 }
49 }
50
51 } // namespace maglev
52 } // namespace internal
53 } // namespace v8
54