LLVM 22.0.0git
SystemZCopyPhysRegs.cpp
Go to the documentation of this file.
1//===---------- SystemZPhysRegCopy.cpp - Handle phys reg copies -----------===//
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//
9// This pass makes sure that a COPY of a physical register will be
10// implementable after register allocation in copyPhysReg() (this could be
11// done in EmitInstrWithCustomInserter() instead if COPY instructions would
12// be passed to it).
13//
14//===----------------------------------------------------------------------===//
15
23
24using namespace llvm;
25
26namespace {
27
28class SystemZCopyPhysRegs : public MachineFunctionPass {
29public:
30 static char ID;
31 SystemZCopyPhysRegs() : MachineFunctionPass(ID), TII(nullptr), MRI(nullptr) {}
32
33 bool runOnMachineFunction(MachineFunction &MF) override;
34 void getAnalysisUsage(AnalysisUsage &AU) const override;
35
36private:
37
38 bool visitMBB(MachineBasicBlock &MBB);
39
40 const SystemZInstrInfo *TII;
41 MachineRegisterInfo *MRI;
42};
43
44char SystemZCopyPhysRegs::ID = 0;
45
46} // end anonymous namespace
47
48INITIALIZE_PASS(SystemZCopyPhysRegs, "systemz-copy-physregs",
49 "SystemZ Copy Physregs", false, false)
50
52 return new SystemZCopyPhysRegs();
53}
54
55void SystemZCopyPhysRegs::getAnalysisUsage(AnalysisUsage &AU) const {
56 AU.setPreservesCFG();
58}
59
60bool SystemZCopyPhysRegs::visitMBB(MachineBasicBlock &MBB) {
61 bool Modified = false;
62
63 // Certain special registers can only be copied from a subset of the
64 // default register class of the type. It is therefore necessary to create
65 // the target copy instructions before regalloc instead of in copyPhysReg().
67 MBBI != E; ) {
68 MachineInstr *MI = &*MBBI++;
69 if (!MI->isCopy())
70 continue;
71
72 DebugLoc DL = MI->getDebugLoc();
73 Register SrcReg = MI->getOperand(1).getReg();
74 Register DstReg = MI->getOperand(0).getReg();
75
76 if (DstReg.isVirtual() &&
77 (SrcReg == SystemZ::CC || SystemZ::AR32BitRegClass.contains(SrcReg))) {
78 Register Tmp = MRI->createVirtualRegister(&SystemZ::GR32BitRegClass);
79 if (SrcReg == SystemZ::CC)
80 BuildMI(MBB, MI, DL, TII->get(SystemZ::IPM), Tmp);
81 else
82 BuildMI(MBB, MI, DL, TII->get(SystemZ::EAR), Tmp).addReg(SrcReg);
83 MI->getOperand(1).setReg(Tmp);
84 Modified = true;
85 }
86 else if (SrcReg.isVirtual() &&
87 SystemZ::AR32BitRegClass.contains(DstReg)) {
88 Register Tmp = MRI->createVirtualRegister(&SystemZ::GR32BitRegClass);
89 MI->getOperand(0).setReg(Tmp);
90 MachineInstr *NMI =
91 BuildMI(MBB, MBBI, DL, TII->get(SystemZ::SAR), DstReg).addReg(Tmp);
92 // SAR now writes the final value to DstReg, so update debug values.
94 Modified = true;
95 }
96 }
97
98 return Modified;
99}
100
101bool SystemZCopyPhysRegs::runOnMachineFunction(MachineFunction &F) {
102 TII = F.getSubtarget<SystemZSubtarget>().getInstrInfo();
103 MRI = &F.getRegInfo();
104
105 bool Modified = false;
106 for (auto &MBB : F)
107 Modified |= visitMBB(MBB);
108
109 return Modified;
110}
111
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition MD5.cpp:55
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
Represent the analysis usage information of a pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:270
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
void substituteDebugValuesForInst(const MachineInstr &Old, MachineInstr &New, unsigned MaxOperand=UINT_MAX)
Create substitutions for any tracked values in Old, to point at New.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:74
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass * createSystemZCopyPhysRegsPass(SystemZTargetMachine &TM)