38#define DEBUG_TYPE "ppc-vsx-fma-mutate"
53 const PPCInstrInfo *TII;
60 const TargetRegisterInfo *
TRI = &TII->getRegisterInfo();
63 MachineInstr &
MI = *
I;
94 SlotIndex FMAIdx = LIS->getInstructionIndex(
MI);
97 LIS->getInterval(
MI.getOperand(1).getReg()).Query(FMAIdx).valueIn();
103 MachineInstr *AddendMI = LIS->getInstructionFromIndex(AddendValNo->
def);
146 bool OtherUsers =
false, KillsAddendSrc =
false;
153 if (J->modifiesRegister(AddendSrcReg,
TRI) ||
154 J->killsRegister(AddendSrcReg,
TRI)) {
155 KillsAddendSrc =
true;
160 if (OtherUsers || KillsAddendSrc)
171 Register OldFMAReg =
MI.getOperand(0).getReg();
174 unsigned KilledProdOp = 0, OtherProdOp = 0;
177 if (LIS->getInterval(Reg2).Query(FMAIdx).isKill()
178 && Reg2 != OldFMAReg) {
181 }
else if (LIS->getInterval(Reg3).Query(FMAIdx).isKill()
182 && Reg3 != OldFMAReg) {
198 !LIS->getInterval(AddendSrcReg).liveAt(FMAIdx))
203 Register KilledProdReg =
MI.getOperand(KilledProdOp).getReg();
204 Register OtherProdReg =
MI.getOperand(OtherProdOp).getReg();
207 unsigned KilledProdSubReg =
MI.getOperand(KilledProdOp).getSubReg();
208 unsigned OtherProdSubReg =
MI.getOperand(OtherProdOp).getSubReg();
211 bool KilledProdRegKill =
MI.getOperand(KilledProdOp).isKill();
212 bool OtherProdRegKill =
MI.getOperand(OtherProdOp).isKill();
215 bool KilledProdRegUndef =
MI.getOperand(KilledProdOp).isUndef();
216 bool OtherProdRegUndef =
MI.getOperand(OtherProdOp).isUndef();
227 "Addend copy not tied to old FMA output!");
231 MI.getOperand(0).setReg(KilledProdReg);
232 MI.getOperand(1).setReg(KilledProdReg);
233 MI.getOperand(3).setReg(AddendSrcReg);
235 MI.getOperand(0).setSubReg(KilledProdSubReg);
236 MI.getOperand(1).setSubReg(KilledProdSubReg);
239 MI.getOperand(1).setIsKill(KilledProdRegKill);
240 MI.getOperand(3).setIsKill(AddRegKill);
242 MI.getOperand(1).setIsUndef(KilledProdRegUndef);
243 MI.getOperand(3).setIsUndef(AddRegUndef);
245 MI.setDesc(TII->get(AltOpc));
250 MI.getOperand(2).setReg(AddendSrcReg);
252 MI.getOperand(2).setIsKill(AddRegKill);
253 MI.getOperand(2).setIsUndef(AddRegUndef);
255 MI.getOperand(2).setReg(OtherProdReg);
256 MI.getOperand(2).setSubReg(OtherProdSubReg);
257 MI.getOperand(2).setIsKill(OtherProdRegKill);
258 MI.getOperand(2).setIsUndef(OtherProdRegUndef);
266 LiveInterval &FMAInt = LIS->getInterval(OldFMAReg);
270 MachineOperand &UseMO = *UI;
275 if (
UseMI == AddendMI)
282 LIS->removeInterval(KilledProdReg);
283 LiveInterval &NewFMAInt =
284 LIS->createAndComputeVirtRegInterval(KilledProdReg);
293 for (MCRegUnit Unit :
TRI->regunits(AddendSrcReg.
asMCReg())) {
294 LiveRange &AddendSrcRange = LIS->getRegUnit(Unit);
306 LIS->RemoveMachineInstrFromMaps(*AddendMI);
322 const PPCSubtarget &STI = MF.
getSubtarget<PPCSubtarget>();
326 LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS();
342 void getAnalysisUsage(AnalysisUsage &AU)
const override {
347 AU.
addPreserved<MachineBlockFrequencyInfoWrapperPass>();
355 "PowerPC VSX FMA Mutation",
false,
false)
363char PPCVSXFMAMutate::ID = 0;
365 return new PPCVSXFMAMutate();
MachineInstrBuilder & UseMI
static const MachineInstrBuilder & AddSubReg(const MachineInstrBuilder &MIB, MCRegister Reg, unsigned SubIdx, RegState State, const TargetRegisterInfo *TRI)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Register const TargetRegisterInfo * TRI
Promote Memory to Register
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
MachineRegisterInfo & MRI
SI Optimize VGPR LiveRange
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
static bool processBlock(MachineBasicBlock &MBB, const SystemZInstrInfo *TII, const TargetRegisterInfo *TRI)
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
FunctionPass class - This class is used to implement most global optimizations.
LLVM_ABI void removeValNo(VNInfo *ValNo)
removeValNo - Remove all the segments defined by the specified value#.
LLVM_ABI std::pair< VNInfo *, bool > extendInBlock(ArrayRef< SlotIndex > Undefs, SlotIndex StartIdx, SlotIndex Kill)
Attempt to extend a value defined after StartIdx to include Use.
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
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.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineBasicBlock * getParent() const
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getSubReg() const
LLVM_ABI void substVirtReg(Register Reg, unsigned SubIdx, const TargetRegisterInfo &)
substVirtReg - Substitute the current register with the virtual subregister Reg:SubReg.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
Register getReg() const
getReg - Returns the register number.
reg_nodbg_iterator reg_nodbg_begin(Register RegNo) const
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
static reg_nodbg_iterator reg_nodbg_end()
LLVM_ABI const TargetRegisterClass * constrainRegClass(Register Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
const PPCOptions & getCLOpts() const
const PPCInstrInfo * getInstrInfo() const override
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
SlotIndex def
The index of the defining instruction.
Define some predicates that are used for node matching.
int32_t getAltVSXFMAOpcode(uint32_t Opcode)
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createPPCVSXFMAMutatePass()
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.