30#define DEBUG_TYPE "systemz-post-rewrite"
31STATISTIC(MemFoldCopies,
"Number of copies inserted before folded mem ops.");
32STATISTIC(LOCRMuxJumps,
"Number of LOCRMux jump-sequences (lower is better)");
44char SystemZPostRewriteLegacy::ID = 0;
49 "SystemZ Post Rewrite pass",
false,
false)
54 return new SystemZPostRewriteLegacy();
70 unsigned CCValid =
MI.getOperand(3).getImm();
71 unsigned CCMask =
MI.getOperand(4).getImm();
72 assert(DestReg ==
MI.getOperand(1).getReg() &&
73 "Expected destination and first source operand to be the same.");
77 for (
auto I = std::prev(
MBB.end());
I !=
MBBI; --
I)
101 MBB.addSuccessor(RestMBB);
102 MBB.addSuccessor(MoveMBB);
107 BuildMI(*MoveMBB, MoveMBB->
end(),
DL,
TII->get(SystemZ::COPY), DestReg)
110 MBB.getParent()->substituteDebugValuesForInst(*
MBBI, *CopyInst, 1);
113 NextMBBI =
MBB.end();
114 MI.eraseFromParent();
126 unsigned LowOpcode,
unsigned HighOpcode,
133 if (!DestIsHigh && !SrcIsHigh)
134 MBBI->setDesc(
TII->get(LowOpcode));
135 else if (DestIsHigh && SrcIsHigh)
136 MBBI->setDesc(
TII->get(HighOpcode));
147 unsigned LowOpcode,
unsigned HighOpcode,
165 if (Src1Reg == Src2Reg) {
167 TII->get(SystemZ::COPY), DestReg)
169 MBB.getParent()->substituteDebugValuesForInst(*
MBBI, *CopyInst, 1);
170 MBBI->eraseFromParent();
177 if (DestReg != Src1Reg && DestReg != Src2Reg) {
178 if (DestIsHigh != Src1IsHigh) {
180 TII->get(SystemZ::COPY), DestReg)
184 Src1IsHigh = DestIsHigh;
185 }
else if (DestIsHigh != Src2IsHigh) {
187 TII->get(SystemZ::COPY), DestReg)
191 Src2IsHigh = DestIsHigh;
196 MBB.getParent()->substituteDebugValuesForInst(*
MBBI, *CopyInst, 1);
199 if (DestReg != Src1Reg && DestReg == Src2Reg) {
200 TII->commuteInstruction(*
MBBI,
false, 1, 2);
205 if (!DestIsHigh && !Src1IsHigh && !Src2IsHigh)
206 MBBI->setDesc(
TII->get(LowOpcode));
207 else if (DestIsHigh && Src1IsHigh && Src2IsHigh)
208 MBBI->setDesc(
TII->get(HighOpcode));
220 unsigned Opcode =
MI.getOpcode();
226 if (TargetMemOpcode != -1) {
227 MI.setDesc(
TII->get(TargetMemOpcode));
228 MI.tieOperands(0, 1);
231 if (DstReg != SrcMO.
getReg()) {
241 case SystemZ::LOCRMux:
244 case SystemZ::SELRMux:
278bool SystemZPostRewriteLegacy::runOnMachineFunction(
MachineFunction &MF) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static bool expandCondMove(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, MachineBasicBlock::iterator &NextMBBI, const TargetInstrInfo *TII)
static bool selectMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, MachineBasicBlock::iterator &NextMBBI, const TargetInstrInfo *TII)
If MBBI references a pseudo instruction that should be selected here, do it and return true.
static bool selectMBB(MachineBasicBlock &MBB, const TargetInstrInfo *TII)
Iterate over the instructions in basic block MBB and select any pseudo instructions.
static void selectSELRMux(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, MachineBasicBlock::iterator &NextMBBI, unsigned LowOpcode, unsigned HighOpcode, const TargetInstrInfo *TII)
static void selectLOCRMux(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, MachineBasicBlock::iterator &NextMBBI, unsigned LowOpcode, unsigned HighOpcode, const TargetInstrInfo *TII)
static bool runPostRewriteOnMF(MachineFunction &MF)
LLVM Basic Block Representation.
FunctionPass class - This class is used to implement most global optimizations.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
LLVM_ABI void transferSuccessors(MachineBasicBlock *FromMBB)
Transfers all the successors from MBB to this machine basic block (i.e., copies all the successors Fr...
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
BasicBlockListType::iterator iterator
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
Register getReg() const
getReg - Returns the register number.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Wrapper class representing virtual and physical registers.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
TargetInstrInfo - Interface to description of machine instruction set.
Pass manager infrastructure for declaring and invalidating analyses.
int32_t getTargetMemOpcode(uint32_t Opcode)
bool isHighReg(unsigned int Reg)
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.
RegState getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
FunctionPass * createSystemZPostRewriteLegacyPass(SystemZTargetMachine &TM)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.