10eae32dcSDimitry Andric //===- MachineSSAContext.cpp ------------------------------------*- C++ -*-===//
20eae32dcSDimitry Andric //
30eae32dcSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40eae32dcSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50eae32dcSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60eae32dcSDimitry Andric //
70eae32dcSDimitry Andric //===----------------------------------------------------------------------===//
80eae32dcSDimitry Andric /// \file
90eae32dcSDimitry Andric ///
100eae32dcSDimitry Andric /// This file defines a specialization of the GenericSSAContext<X>
110eae32dcSDimitry Andric /// template class for Machine IR.
120eae32dcSDimitry Andric ///
130eae32dcSDimitry Andric //===----------------------------------------------------------------------===//
140eae32dcSDimitry Andric 
150eae32dcSDimitry Andric #include "llvm/CodeGen/MachineSSAContext.h"
160eae32dcSDimitry Andric #include "llvm/CodeGen/MachineBasicBlock.h"
170eae32dcSDimitry Andric #include "llvm/CodeGen/MachineInstr.h"
180eae32dcSDimitry Andric #include "llvm/Support/raw_ostream.h"
190eae32dcSDimitry Andric 
200eae32dcSDimitry Andric using namespace llvm;
210eae32dcSDimitry Andric 
220eae32dcSDimitry Andric MachineBasicBlock *MachineSSAContext::getEntryBlock(MachineFunction &F) {
230eae32dcSDimitry Andric   return &F.front();
240eae32dcSDimitry Andric }
250eae32dcSDimitry Andric 
260eae32dcSDimitry Andric void MachineSSAContext::setFunction(MachineFunction &Fn) {
270eae32dcSDimitry Andric   MF = &Fn;
280eae32dcSDimitry Andric   RegInfo = &MF->getRegInfo();
290eae32dcSDimitry Andric }
300eae32dcSDimitry Andric 
310eae32dcSDimitry Andric Printable MachineSSAContext::print(MachineBasicBlock *Block) const {
320eae32dcSDimitry Andric   return Printable([Block](raw_ostream &Out) { Block->printName(Out); });
330eae32dcSDimitry Andric }
340eae32dcSDimitry Andric 
350eae32dcSDimitry Andric Printable MachineSSAContext::print(MachineInstr *I) const {
360eae32dcSDimitry Andric   return Printable([I](raw_ostream &Out) { I->print(Out); });
370eae32dcSDimitry Andric }
380eae32dcSDimitry Andric 
390eae32dcSDimitry Andric Printable MachineSSAContext::print(Register Value) const {
400eae32dcSDimitry Andric   auto *MRI = RegInfo;
410eae32dcSDimitry Andric   return Printable([MRI, Value](raw_ostream &Out) {
420eae32dcSDimitry Andric     Out << printReg(Value, MRI->getTargetRegisterInfo(), 0, MRI);
430eae32dcSDimitry Andric 
440eae32dcSDimitry Andric     if (Value) {
450eae32dcSDimitry Andric       // Try to print the definition.
460eae32dcSDimitry Andric       if (auto *Instr = MRI->getUniqueVRegDef(Value)) {
470eae32dcSDimitry Andric         Out << ": ";
480eae32dcSDimitry Andric         Instr->print(Out);
490eae32dcSDimitry Andric       }
500eae32dcSDimitry Andric     }
510eae32dcSDimitry Andric   });
520eae32dcSDimitry Andric }
53