1// Copyright 2021 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_COMPILER_H_
6#define V8_MAGLEV_MAGLEV_COMPILER_H_
7
8#include "src/common/globals.h"
9#include "src/compiler/bytecode-analysis.h"
10#include "src/compiler/heap-refs.h"
11#include "src/maglev/maglev-compilation-unit.h"
12
13namespace v8 {
14namespace internal {
15
16namespace compiler {
17class JSHeapBroker;
18}
19
20namespace maglev {
21
22class Graph;
23
24class MaglevCompiler {
25 public:
26  // May be called from any thread.
27  static void Compile(LocalIsolate* local_isolate,
28                      MaglevCompilationUnit* toplevel_compilation_unit);
29
30  // Called on the main thread after Compile has completed.
31  // TODO(v8:7700): Move this to a different class?
32  static MaybeHandle<CodeT> GenerateCode(
33      MaglevCompilationUnit* toplevel_compilation_unit);
34
35 private:
36  explicit MaglevCompiler(LocalIsolate* local_isolate,
37                          MaglevCompilationUnit* toplevel_compilation_unit)
38      : local_isolate_(local_isolate),
39        toplevel_compilation_unit_(toplevel_compilation_unit) {}
40
41  void Compile();
42
43  compiler::JSHeapBroker* broker() const {
44    return toplevel_compilation_unit_->broker();
45  }
46  Zone* zone() { return toplevel_compilation_unit_->zone(); }
47  LocalIsolate* local_isolate() { return local_isolate_; }
48
49  LocalIsolate* const local_isolate_;
50  MaglevCompilationUnit* const toplevel_compilation_unit_;
51};
52
53}  // namespace maglev
54}  // namespace internal
55}  // namespace v8
56
57#endif  // V8_MAGLEV_MAGLEV_COMPILER_H_
58