[WebAssembly] Add new target feature in support of 'extended-const' proposal
[llvm-project.git] / llvm / lib / CodeGen / MachineSSAContext.cpp
blob8db893535daf8d2f0f7a321840c1464295fc964f
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 //===----------------------------------------------------------------------===//
15 #include "llvm/CodeGen/MachineSSAContext.h"
16 #include "llvm/CodeGen/MachineBasicBlock.h"
17 #include "llvm/CodeGen/MachineInstr.h"
18 #include "llvm/Support/raw_ostream.h"
20 using namespace llvm;
22 MachineBasicBlock *MachineSSAContext::getEntryBlock(MachineFunction &F) {
23 return &F.front();
26 void MachineSSAContext::setFunction(MachineFunction &Fn) {
27 MF = &Fn;
28 RegInfo = &MF->getRegInfo();
31 Printable MachineSSAContext::print(MachineBasicBlock *Block) const {
32 return Printable([Block](raw_ostream &Out) { Block->printName(Out); });
35 Printable MachineSSAContext::print(MachineInstr *I) const {
36 return Printable([I](raw_ostream &Out) { I->print(Out); });
39 Printable MachineSSAContext::print(Register Value) const {
40 auto *MRI = RegInfo;
41 return Printable([MRI, Value](raw_ostream &Out) {
42 Out << printReg(Value, MRI->getTargetRegisterInfo(), 0, MRI);
44 if (Value) {
45 // Try to print the definition.
46 if (auto *Instr = MRI->getUniqueVRegDef(Value)) {
47 Out << ": ";
48 Instr->print(Out);
51 });