LLVM 19.0.0git
MachineSSAContext.cpp
Go to the documentation of this file.
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
22
23using namespace llvm;
24
25template <>
27 const MachineBasicBlock &block) {
28 for (auto &instr : block.instrs()) {
29 for (auto &op : instr.all_defs())
30 defs.push_back(op.getReg());
31 }
32}
33
34template <>
37 for (auto &T : block.terminators())
38 terms.push_back(&T);
39}
40
41template <>
44 const MachineBasicBlock &block) {
45 for (auto &T : block.terminators())
46 terms.push_back(&T);
47}
48
49/// Get the defining block of a value.
50template <>
52 if (!value)
53 return nullptr;
54 return F->getRegInfo().getVRegDef(value)->getParent();
55}
56
57template <>
59 return Phi.isConstantValuePHI();
60}
61
62template <>
64 if (auto *GI = dyn_cast<GIntrinsic>(&MI))
65 return GI->getIntrinsicID();
67}
68
69template <>
71 if (!Block)
72 return Printable([](raw_ostream &Out) { Out << "<nullptr>"; });
73 return Printable([Block](raw_ostream &Out) { Block->printName(Out); });
74}
75
76template <> Printable MachineSSAContext::print(const MachineInstr *I) const {
77 return Printable([I](raw_ostream &Out) { I->print(Out); });
78}
79
81 auto *MRI = &F->getRegInfo();
82 return Printable([MRI, Value](raw_ostream &Out) {
83 Out << printReg(Value, MRI->getTargetRegisterInfo(), 0, MRI);
84
85 if (Value) {
86 // Try to print the definition.
87 if (auto *Instr = MRI->getUniqueVRegDef(Value)) {
88 Out << ": ";
89 Instr->print(Out);
90 }
91 }
92 });
93}
94
95template <>
97 return Printable([BB](raw_ostream &Out) { BB->printAsOperand(Out); });
98}
unsigned const MachineRegisterInfo * MRI
Given that RA is a live value
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
#define op(i)
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition: MD5.cpp:58
This file declares a specialization of the GenericSSAContext<X> template class for Machine IR.
unify loop Fixup each natural loop to have a single exit block
static void appendBlockDefs(SmallVectorImpl< ValueRefT > &defs, BlockT &block)
static bool isConstantOrUndefValuePhi(const InstructionT &Instr)
static void appendBlockTerms(SmallVectorImpl< InstructionT * > &terms, BlockT &block)
static Intrinsic::ID getIntrinsicID(const InstructionT &I)
Printable print(const BlockT *block) const
const BlockT * getDefBlock(ConstValueRefT value) const
Printable printAsOperand(const BlockT *BB) const
void printAsOperand(raw_ostream &OS, bool PrintType=true) const
Representation of each machine instruction.
Definition: MachineInstr.h:69
Simple wrapper around std::function<void(raw_ostream&)>.
Definition: Printable.h:38
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
void push_back(const T &Elt)
Definition: SmallVector.h:426
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
NodeAddr< InstrNode * > Instr
Definition: RDFGraph.h:389
NodeAddr< PhiNode * > Phi
Definition: RDFGraph.h:390
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.