• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_VREG_ALLOCATOR_H_
6 #define V8_MAGLEV_MAGLEV_VREG_ALLOCATOR_H_
7 
8 #include "src/maglev/maglev-basic-block.h"
9 #include "src/maglev/maglev-graph.h"
10 #include "src/maglev/maglev-ir.h"
11 
12 namespace v8 {
13 namespace internal {
14 namespace maglev {
15 
16 class ProcessingState;
17 
18 class MaglevVregAllocationState {
19  public:
AllocateVirtualRegister()20   int AllocateVirtualRegister() { return next_virtual_register_++; }
num_allocated_registers()21   int num_allocated_registers() const { return next_virtual_register_; }
22 
23  private:
24   int next_virtual_register_ = 0;
25 };
26 
27 class MaglevVregAllocator {
28  public:
PreProcessGraph(MaglevCompilationUnit *,Graph * graph)29   void PreProcessGraph(MaglevCompilationUnit*, Graph* graph) {}
PostProcessGraph(MaglevCompilationUnit *,Graph * graph)30   void PostProcessGraph(MaglevCompilationUnit*, Graph* graph) {
31     for (BasicBlock* block : *graph) {
32       if (!block->has_phi()) continue;
33       for (Phi* phi : *block->phis()) {
34         phi->AllocateVregInPostProcess(&state_);
35       }
36     }
37   }
PreProcessBasicBlock(MaglevCompilationUnit *,BasicBlock * block)38   void PreProcessBasicBlock(MaglevCompilationUnit*, BasicBlock* block) {}
39 
40 #define DEF_PROCESS_NODE(NAME)                             \
41   void Process(NAME* node, const ProcessingState& state) { \
42     node->AllocateVreg(&state_, state);                    \
43   }
44   NODE_BASE_LIST(DEF_PROCESS_NODE)
45 #undef DEF_PROCESS_NODE
46 
47  private:
48   MaglevVregAllocationState state_;
49 };
50 
51 }  // namespace maglev
52 }  // namespace internal
53 }  // namespace v8
54 
55 #endif  // V8_MAGLEV_MAGLEV_VREG_ALLOCATOR_H_
56