summaryrefslogtreecommitdiff
path: root/deps/v8/src/maglev/maglev-code-generator.h
blob: 53b1f5279e3e616b78ea87c2d915e62e19873823 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_MAGLEV_MAGLEV_CODE_GENERATOR_H_
#define V8_MAGLEV_MAGLEV_CODE_GENERATOR_H_

#include "src/codegen/maglev-safepoint-table.h"
#include "src/common/globals.h"
#include "src/deoptimizer/translation-array.h"
#include "src/maglev/maglev-assembler.h"
#include "src/maglev/maglev-code-gen-state.h"
#include "src/utils/identity-map.h"

namespace v8 {
namespace internal {
namespace maglev {

class Graph;
class MaglevCompilationInfo;

class MaglevCodeGenerator final {
 public:
  MaglevCodeGenerator(LocalIsolate* isolate,
                      MaglevCompilationInfo* compilation_info, Graph* graph);

  void Assemble();

  MaybeHandle<Code> Generate(Isolate* isolate);

 private:
  void EmitCode();
  void EmitDeferredCode();
  void EmitDeopts();
  void EmitExceptionHandlerTrampolines();
  void EmitMetadata();
  void RecordInlinedFunctions();

  MaybeHandle<Code> BuildCodeObject(Isolate* isolate);
  Handle<DeoptimizationData> GenerateDeoptimizationData(Isolate* isolate);

  int stack_slot_count() const { return code_gen_state_.stack_slots(); }
  int stack_slot_count_with_fixed_frame() const {
    return stack_slot_count() + StandardFrameConstants::kFixedSlotCount;
  }

  MaglevAssembler* masm() { return &masm_; }

  LocalIsolate* local_isolate_;
  MaglevSafepointTableBuilder safepoint_table_builder_;
  TranslationArrayBuilder translation_array_builder_;
  MaglevCodeGenState code_gen_state_;
  MaglevAssembler masm_;
  Graph* const graph_;

  IdentityMap<int, base::DefaultAllocationPolicy> deopt_literals_;
  int deopt_exit_start_offset_ = -1;
  int handler_table_offset_ = 0;
  int inlined_function_count_ = 0;

  bool code_gen_failed_ = false;
};

}  // namespace maglev
}  // namespace internal
}  // namespace v8

#endif  // V8_MAGLEV_MAGLEV_CODE_GENERATOR_H_