MachineSSAContext.h 2.8 KB

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