summaryrefslogtreecommitdiff
path: root/deps/v8/src/maglev/maglev-vreg-allocator.h
blob: 014c69dad306b5520edef80d712e6a638c9bbefd (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
// 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_VREG_ALLOCATOR_H_
#define V8_MAGLEV_MAGLEV_VREG_ALLOCATOR_H_

#include "src/maglev/maglev-basic-block.h"
#include "src/maglev/maglev-graph.h"
#include "src/maglev/maglev-ir.h"

namespace v8 {
namespace internal {
namespace maglev {

class ProcessingState;

class MaglevVregAllocationState {
 public:
  int AllocateVirtualRegister() { return next_virtual_register_++; }
  int num_allocated_registers() const { return next_virtual_register_; }

 private:
  int next_virtual_register_ = 0;
};

class MaglevVregAllocator {
 public:
  void PreProcessGraph(Graph* graph) {}
  void PostProcessGraph(Graph* graph) {
    for (BasicBlock* block : *graph) {
      if (!block->has_phi()) continue;
      for (Phi* phi : *block->phis()) {
        phi->AllocateVregInPostProcess(&state_);
      }
    }
  }
  void PreProcessBasicBlock(BasicBlock* block) {}

#define DEF_PROCESS_NODE(NAME)                             \
  void Process(NAME* node, const ProcessingState& state) { \
    node->AllocateVreg(&state_);                           \
  }
  NODE_BASE_LIST(DEF_PROCESS_NODE)
#undef DEF_PROCESS_NODE

 private:
  MaglevVregAllocationState state_;
};

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

#endif  // V8_MAGLEV_MAGLEV_VREG_ALLOCATOR_H_