1 //===- MachineSSAContext.h --------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This file declares a specialization of the GenericSSAContext<X>
11 /// template class for Machine IR.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CODEGEN_MACHINESSACONTEXT_H
16 #define LLVM_CODEGEN_MACHINESSACONTEXT_H
17 
18 #include "llvm/CodeGen/MachineBasicBlock.h"
19 #include "llvm/Support/Printable.h"
20 
21 namespace llvm {
22 class MachineRegisterInfo;
23 class MachineInstr;
24 class MachineFunction;
25 class Register;
26 template <typename _FunctionT> class GenericSSAContext;
27 template <typename, bool> class DominatorTreeBase;
28 
29 inline auto successors(MachineBasicBlock *BB) { return BB->successors(); }
30 inline auto predecessors(MachineBasicBlock *BB) { return BB->predecessors(); }
31 inline unsigned succ_size(MachineBasicBlock *BB) { return BB->succ_size(); }
32 inline unsigned pred_size(MachineBasicBlock *BB) { return BB->pred_size(); }
33 
34 template <> class GenericSSAContext<MachineFunction> {
35   const MachineRegisterInfo *RegInfo = nullptr;
36   MachineFunction *MF;
37 
38 public:
39   using BlockT = MachineBasicBlock;
40   using FunctionT = MachineFunction;
41   using InstructionT = MachineInstr;
42   using ValueRefT = Register;
43   using DominatorTreeT = DominatorTreeBase<BlockT, false>;
44 
45   static MachineBasicBlock *getEntryBlock(MachineFunction &F);
46 
47   void setFunction(MachineFunction &Fn);
48   MachineFunction *getFunction() const { return MF; }
49 
50   Printable print(MachineBasicBlock *Block) const;
51   Printable print(MachineInstr *Inst) const;
52   Printable print(Register Value) const;
53 };
54 
55 using MachineSSAContext = GenericSSAContext<MachineFunction>;
56 } // namespace llvm
57 
58 #endif // LLVM_CODEGEN_MACHINESSACONTEXT_H
59