MachineSSAContext.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //===- MachineSSAContext.cpp ------------------------------------*- 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 defines a specialization of the GenericSSAContext<X>
  11. /// template class for Machine IR.
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #include "llvm/CodeGen/MachineSSAContext.h"
  15. #include "llvm/CodeGen/MachineBasicBlock.h"
  16. #include "llvm/CodeGen/MachineInstr.h"
  17. #include "llvm/Support/raw_ostream.h"
  18. using namespace llvm;
  19. MachineBasicBlock *MachineSSAContext::getEntryBlock(MachineFunction &F) {
  20. return &F.front();
  21. }
  22. void MachineSSAContext::setFunction(MachineFunction &Fn) {
  23. MF = &Fn;
  24. RegInfo = &MF->getRegInfo();
  25. }
  26. Printable MachineSSAContext::print(MachineBasicBlock *Block) const {
  27. return Printable([Block](raw_ostream &Out) { Block->printName(Out); });
  28. }
  29. Printable MachineSSAContext::print(MachineInstr *I) const {
  30. return Printable([I](raw_ostream &Out) { I->print(Out); });
  31. }
  32. Printable MachineSSAContext::print(Register Value) const {
  33. auto *MRI = RegInfo;
  34. return Printable([MRI, Value](raw_ostream &Out) {
  35. Out << printReg(Value, MRI->getTargetRegisterInfo(), 0, MRI);
  36. if (Value) {
  37. // Try to print the definition.
  38. if (auto *Instr = MRI->getUniqueVRegDef(Value)) {
  39. Out << ": ";
  40. Instr->print(Out);
  41. }
  42. }
  43. });
  44. }