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 unsigned succ_size(const MachineBasicBlock *BB) { 30 return BB->succ_size(); 31 } 32 inline unsigned pred_size(const MachineBasicBlock *BB) { 33 return BB->pred_size(); 34 } 35 inline auto instrs(const MachineBasicBlock &BB) { return BB.instrs(); } 36 37 template <> class GenericSSAContext<MachineFunction> { 38 const MachineRegisterInfo *RegInfo = nullptr; 39 MachineFunction *MF = nullptr; 40 41 public: 42 using BlockT = MachineBasicBlock; 43 using FunctionT = MachineFunction; 44 using InstructionT = MachineInstr; 45 using ValueRefT = Register; 46 using ConstValueRefT = Register; 47 using UseT = MachineOperand; 48 using DominatorTreeT = DominatorTreeBase<BlockT, false>; 49 50 static constexpr Register ValueRefNull = 0; 51 52 void setFunction(MachineFunction &Fn); 53 MachineFunction *getFunction() const { return MF; } 54 55 static MachineBasicBlock *getEntryBlock(MachineFunction &F); 56 static void appendBlockDefs(SmallVectorImpl<Register> &defs, 57 const MachineBasicBlock &block); 58 static void appendBlockTerms(SmallVectorImpl<MachineInstr *> &terms, 59 MachineBasicBlock &block); 60 static void appendBlockTerms(SmallVectorImpl<const MachineInstr *> &terms, 61 const MachineBasicBlock &block); 62 MachineBasicBlock *getDefBlock(Register) const; 63 static bool isConstantOrUndefValuePhi(const MachineInstr &Phi); 64 65 Printable print(const MachineBasicBlock *Block) const; 66 Printable print(const MachineInstr *Inst) const; 67 Printable print(Register Value) const; 68 }; 69 70 using MachineSSAContext = GenericSSAContext<MachineFunction>; 71 } // namespace llvm 72 73 #endif // LLVM_CODEGEN_MACHINESSACONTEXT_H 74