Path: blob/main/contrib/llvm-project/llvm/lib/Target/SystemZ/SystemZCopyPhysRegs.cpp
35294 views
//===---------- SystemZPhysRegCopy.cpp - Handle phys reg copies -----------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This pass makes sure that a COPY of a physical register will be9// implementable after register allocation in copyPhysReg() (this could be10// done in EmitInstrWithCustomInserter() instead if COPY instructions would11// be passed to it).12//13//===----------------------------------------------------------------------===//1415#include "SystemZMachineFunctionInfo.h"16#include "SystemZTargetMachine.h"17#include "llvm/CodeGen/MachineDominators.h"18#include "llvm/CodeGen/MachineFunctionPass.h"19#include "llvm/CodeGen/MachineInstrBuilder.h"20#include "llvm/CodeGen/MachineRegisterInfo.h"21#include "llvm/CodeGen/TargetInstrInfo.h"22#include "llvm/CodeGen/TargetRegisterInfo.h"23#include "llvm/Target/TargetMachine.h"2425using namespace llvm;2627namespace {2829class SystemZCopyPhysRegs : public MachineFunctionPass {30public:31static char ID;32SystemZCopyPhysRegs()33: MachineFunctionPass(ID), TII(nullptr), MRI(nullptr) {34initializeSystemZCopyPhysRegsPass(*PassRegistry::getPassRegistry());35}3637bool runOnMachineFunction(MachineFunction &MF) override;38void getAnalysisUsage(AnalysisUsage &AU) const override;3940private:4142bool visitMBB(MachineBasicBlock &MBB);4344const SystemZInstrInfo *TII;45MachineRegisterInfo *MRI;46};4748char SystemZCopyPhysRegs::ID = 0;4950} // end anonymous namespace5152INITIALIZE_PASS(SystemZCopyPhysRegs, "systemz-copy-physregs",53"SystemZ Copy Physregs", false, false)5455FunctionPass *llvm::createSystemZCopyPhysRegsPass(SystemZTargetMachine &TM) {56return new SystemZCopyPhysRegs();57}5859void SystemZCopyPhysRegs::getAnalysisUsage(AnalysisUsage &AU) const {60AU.setPreservesCFG();61MachineFunctionPass::getAnalysisUsage(AU);62}6364bool SystemZCopyPhysRegs::visitMBB(MachineBasicBlock &MBB) {65bool Modified = false;6667// Certain special registers can only be copied from a subset of the68// default register class of the type. It is therefore necessary to create69// the target copy instructions before regalloc instead of in copyPhysReg().70for (MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();71MBBI != E; ) {72MachineInstr *MI = &*MBBI++;73if (!MI->isCopy())74continue;7576DebugLoc DL = MI->getDebugLoc();77Register SrcReg = MI->getOperand(1).getReg();78Register DstReg = MI->getOperand(0).getReg();79if (DstReg.isVirtual() &&80(SrcReg == SystemZ::CC || SystemZ::AR32BitRegClass.contains(SrcReg))) {81Register Tmp = MRI->createVirtualRegister(&SystemZ::GR32BitRegClass);82if (SrcReg == SystemZ::CC)83BuildMI(MBB, MI, DL, TII->get(SystemZ::IPM), Tmp);84else85BuildMI(MBB, MI, DL, TII->get(SystemZ::EAR), Tmp).addReg(SrcReg);86MI->getOperand(1).setReg(Tmp);87Modified = true;88}89else if (SrcReg.isVirtual() &&90SystemZ::AR32BitRegClass.contains(DstReg)) {91Register Tmp = MRI->createVirtualRegister(&SystemZ::GR32BitRegClass);92MI->getOperand(0).setReg(Tmp);93BuildMI(MBB, MBBI, DL, TII->get(SystemZ::SAR), DstReg).addReg(Tmp);94Modified = true;95}96}9798return Modified;99}100101bool SystemZCopyPhysRegs::runOnMachineFunction(MachineFunction &F) {102TII = F.getSubtarget<SystemZSubtarget>().getInstrInfo();103MRI = &F.getRegInfo();104105bool Modified = false;106for (auto &MBB : F)107Modified |= visitMBB(MBB);108109return Modified;110}111112113114