xref: /freebsd/contrib/llvm-project/llvm/lib/CodeGen/MachineSSAContext.cpp (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
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 
15 #include "llvm/CodeGen/MachineSSAContext.h"
16 #include "llvm/CodeGen/MachineBasicBlock.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MachineInstr.h"
19 #include "llvm/CodeGen/MachineRegisterInfo.h"
20 #include "llvm/Support/raw_ostream.h"
21 
22 using namespace llvm;
23 
24 MachineBasicBlock *MachineSSAContext::getEntryBlock(MachineFunction &F) {
25   return &F.front();
26 }
27 
28 void MachineSSAContext::setFunction(MachineFunction &Fn) {
29   MF = &Fn;
30   RegInfo = &MF->getRegInfo();
31 }
32 
33 Printable MachineSSAContext::print(MachineBasicBlock *Block) const {
34   return Printable([Block](raw_ostream &Out) { Block->printName(Out); });
35 }
36 
37 Printable MachineSSAContext::print(MachineInstr *I) const {
38   return Printable([I](raw_ostream &Out) { I->print(Out); });
39 }
40 
41 Printable MachineSSAContext::print(Register Value) const {
42   auto *MRI = RegInfo;
43   return Printable([MRI, Value](raw_ostream &Out) {
44     Out << printReg(Value, MRI->getTargetRegisterInfo(), 0, MRI);
45 
46     if (Value) {
47       // Try to print the definition.
48       if (auto *Instr = MRI->getUniqueVRegDef(Value)) {
49         Out << ": ";
50         Instr->print(Out);
51       }
52     }
53   });
54 }
55