LLVM 24.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
16#include "SystemZ.h"
26#include "llvm/IR/Analysis.h"
27
28using namespace llvm;
29
30namespace {
31
32class SystemZCopyPhysRegsLegacy : public MachineFunctionPass {
33public:
34 static char ID;
35 SystemZCopyPhysRegsLegacy() : MachineFunctionPass(ID) {}
36
37 bool runOnMachineFunction(MachineFunction &MF) override;
38 void getAnalysisUsage(AnalysisUsage &AU) const override;
39};
40
41char SystemZCopyPhysRegsLegacy::ID = 0;
42
43} // end anonymous namespace
44
45INITIALIZE_PASS(SystemZCopyPhysRegsLegacy, "systemz-copy-physregs",
46 "SystemZ Copy Physregs", false, false)
47
50 return new SystemZCopyPhysRegsLegacy();
51}
52
53void SystemZCopyPhysRegsLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
54 AU.setPreservesCFG();
56}
57
59 const TargetInstrInfo *TII) {
60 bool Modified = false;
61
62 // Certain special registers can only be copied from a subset of the
63 // default register class of the type. It is therefore necessary to create
64 // the target copy instructions before regalloc instead of in copyPhysReg().
65 for (MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
66 MBBI != E; ) {
67 MachineInstr *MI = &*MBBI++;
68 if (!MI->isCopy())
69 continue;
70
71 DebugLoc DL = MI->getDebugLoc();
72 Register SrcReg = MI->getOperand(1).getReg();
73 Register DstReg = MI->getOperand(0).getReg();
74
75 if (DstReg.isVirtual() &&
76 (SrcReg == SystemZ::CC || SystemZ::AR32BitRegClass.contains(SrcReg))) {
77 Register Tmp = MRI->createVirtualRegister(&SystemZ::GR32BitRegClass);
78 if (SrcReg == SystemZ::CC)
79 BuildMI(MBB, MI, DL, TII->get(SystemZ::IPM), Tmp);
80 else
81 BuildMI(MBB, MI, DL, TII->get(SystemZ::EAR), Tmp).addReg(SrcReg);
82 MI->getOperand(1).setReg(Tmp);
83 Modified = true;
84 }
85 else if (SrcReg.isVirtual() &&
86 SystemZ::AR32BitRegClass.contains(DstReg)) {
87 Register Tmp = MRI->createVirtualRegister(&SystemZ::GR32BitRegClass);
88 MI->getOperand(0).setReg(Tmp);
89 MachineInstr *NMI =
90 BuildMI(MBB, MBBI, DL, TII->get(SystemZ::SAR), DstReg).addReg(Tmp);
91 // SAR now writes the final value to DstReg, so update debug values.
92 MBB.getParent()->substituteDebugValuesForInst(*MI, *NMI);
93 Modified = true;
94 }
95 }
96
97 return Modified;
98}
99
101 const TargetInstrInfo *TII =
102 F.getSubtarget<SystemZSubtarget>().getInstrInfo();
103 MachineRegisterInfo *MRI = &F.getRegInfo();
104
105 bool Modified = false;
106 for (auto &MBB : F)
108
109 return Modified;
110}
111
112bool SystemZCopyPhysRegsLegacy::runOnMachineFunction(MachineFunction &MF) {
113 return runCopyPhysRegsOnMF(MF);
114}
115
116PreservedAnalyses
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:54
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
MachineRegisterInfo & MRI
static bool visitMBB(MachineBasicBlock &MBB, MachineRegisterInfo *MRI, const TargetInstrInfo *TII)
static bool runCopyPhysRegsOnMF(MachineFunction &F)
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:280
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
A debug info location.
Definition DebugLoc.h:126
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
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.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
TargetInstrInfo - Interface to description of machine instruction set.
Pass manager infrastructure for declaring and invalidating analyses.
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.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
FunctionPass * createSystemZCopyPhysRegsLegacyPass(SystemZTargetMachine &TM)