24 #define SYSTEMZ_POSTREWRITE_NAME "SystemZ Post Rewrite pass" 26 #define DEBUG_TYPE "systemz-postrewrite" 27 STATISTIC(MemFoldCopies,
"Number of copies inserted before folded mem ops.");
28 STATISTIC(LOCRMuxJumps,
"Number of LOCRMux jump-sequences (lower is better)");
77 return new SystemZPostRewrite();
88 unsigned HighOpcode) {
89 Register DestReg = MBBI->getOperand(0).getReg();
90 Register SrcReg = MBBI->getOperand(2).getReg();
94 if (!DestIsHigh && !SrcIsHigh)
95 MBBI->setDesc(
TII->get(LowOpcode));
96 else if (DestIsHigh && SrcIsHigh)
97 MBBI->setDesc(
TII->get(HighOpcode));
99 expandCondMove(MBB, MBBI, NextMBBI);
109 unsigned HighOpcode) {
110 Register DestReg = MBBI->getOperand(0).getReg();
111 Register Src1Reg = MBBI->getOperand(1).getReg();
112 Register Src2Reg = MBBI->getOperand(2).getReg();
120 if (DestReg != Src1Reg && DestReg != Src2Reg) {
121 if (DestIsHigh != Src1IsHigh) {
122 BuildMI(*MBBI->getParent(), MBBI, MBBI->getDebugLoc(),
123 TII->get(SystemZ::COPY), DestReg)
124 .addReg(MBBI->getOperand(1).getReg(),
getRegState(MBBI->getOperand(1)));
125 MBBI->getOperand(1).setReg(DestReg);
127 Src1IsHigh = DestIsHigh;
128 }
else if (DestIsHigh != Src2IsHigh) {
129 BuildMI(*MBBI->getParent(), MBBI, MBBI->getDebugLoc(),
130 TII->get(SystemZ::COPY), DestReg)
131 .addReg(MBBI->getOperand(2).getReg(),
getRegState(MBBI->getOperand(2)));
132 MBBI->getOperand(2).setReg(DestReg);
134 Src2IsHigh = DestIsHigh;
139 if (DestReg != Src1Reg && DestReg == Src2Reg) {
140 TII->commuteInstruction(*MBBI,
false, 1, 2);
145 if (!DestIsHigh && !Src1IsHigh && !Src2IsHigh)
146 MBBI->setDesc(
TII->get(LowOpcode));
147 else if (DestIsHigh && Src1IsHigh && Src2IsHigh)
148 MBBI->setDesc(
TII->get(HighOpcode));
151 expandCondMove(MBB, MBBI, NextMBBI);
169 "Expected destination and first source operand to be the same.");
173 for (
auto I = std::prev(MBB.
end());
I != MBBI; --
I)
174 LiveRegs.stepBackward(*
I);
181 for (
auto I = LiveRegs.begin();
I != LiveRegs.end(); ++
I)
188 for (
auto I = LiveRegs.begin();
I != LiveRegs.end(); ++
I)
194 .addImm(CCValid).
addImm(CCMask ^ CCValid).
addMBB(RestMBB);
200 BuildMI(*MoveMBB, MoveMBB->
end(), DL,
TII->get(SystemZ::COPY), DestReg)
201 .addReg(MI.getOperand(2).getReg(),
getRegState(MI.getOperand(2)));
204 NextMBBI = MBB.
end();
205 MI.eraseFromParent();
222 if (TargetMemOpcode != -1) {
227 if (DstReg != SrcMO.
getReg()) {
237 case SystemZ::LOCRMux:
238 selectLOCRMux(MBB, MBBI, NextMBBI, SystemZ::LOCR, SystemZ::LOCFHR);
240 case SystemZ::SELRMux:
241 selectSELRMux(MBB, MBBI, NextMBBI, SystemZ::SELR, SystemZ::SELFHR);
256 Modified |= selectMI(MBB, MBBI, NMBBI);
268 Modified |= selectMBB(MBB);
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
unsigned getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
This class represents lattice values for constants.
int getTargetMemOpcode(uint16_t Opcode)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
void transferSuccessors(MachineBasicBlock *FromMBB)
Transfers all the successors from MBB to this machine basic block (i.e., copies all the successors Fr...
STATISTIC(NumFunctions, "Total number of functions")
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
INITIALIZE_PASS(SystemZPostRewrite, "systemz-post-rewrite", SYSTEMZ_POSTREWRITE_NAME, false, false) FunctionPass *llvm
Returns an instance of the Post Rewrite pass.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isHighReg(unsigned int Reg)
void setReg(Register Reg)
Change the register this operand corresponds to.
virtual const TargetInstrInfo * getInstrInfo() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
LLVM Basic Block Representation.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void addLiveOuts(const MachineBasicBlock &MBB)
Adds all live-out registers of basic block MBB.
FunctionPass * createSystemZPostRewritePass(SystemZTargetMachine &TM)
void initializeSystemZPostRewritePass(PassRegistry &)
FunctionPass class - This class is used to implement most global optimizations.
Iterator for intrusive lists based on ilist_node.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
MachineOperand class - Representation of each machine instruction operand.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
#define SYSTEMZ_POSTREWRITE_NAME
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 '...
A set of physical registers with utility functions to track liveness when walking backward/forward th...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void insert(iterator MBBI, MachineBasicBlock *MBB)
StringRef - Represent a constant reference to a string, i.e.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
Wrapper class representing virtual and physical registers.
void tieOperands(unsigned DefIdx, unsigned UseIdx)
Add a tie between the register operands at DefIdx and UseIdx.