1089b8ecfSHal Finkel //===--------------- PPCVSXFMAMutate.cpp - VSX FMA Mutation ---------------===// 2089b8ecfSHal Finkel // 3089b8ecfSHal Finkel // The LLVM Compiler Infrastructure 4089b8ecfSHal Finkel // 5089b8ecfSHal Finkel // This file is distributed under the University of Illinois Open Source 6089b8ecfSHal Finkel // License. See LICENSE.TXT for details. 7089b8ecfSHal Finkel // 8089b8ecfSHal Finkel //===----------------------------------------------------------------------===// 9089b8ecfSHal Finkel // 10089b8ecfSHal Finkel // This pass mutates the form of VSX FMA instructions to avoid unnecessary 11089b8ecfSHal Finkel // copies. 12089b8ecfSHal Finkel // 13089b8ecfSHal Finkel //===----------------------------------------------------------------------===// 14089b8ecfSHal Finkel 15089b8ecfSHal Finkel #include "PPCInstrInfo.h" 16089b8ecfSHal Finkel #include "MCTargetDesc/PPCPredicates.h" 17089b8ecfSHal Finkel #include "PPC.h" 18089b8ecfSHal Finkel #include "PPCInstrBuilder.h" 19089b8ecfSHal Finkel #include "PPCMachineFunctionInfo.h" 20089b8ecfSHal Finkel #include "PPCTargetMachine.h" 21089b8ecfSHal Finkel #include "llvm/ADT/STLExtras.h" 22089b8ecfSHal Finkel #include "llvm/ADT/Statistic.h" 23089b8ecfSHal Finkel #include "llvm/CodeGen/LiveIntervalAnalysis.h" 24089b8ecfSHal Finkel #include "llvm/CodeGen/MachineFrameInfo.h" 25089b8ecfSHal Finkel #include "llvm/CodeGen/MachineFunctionPass.h" 26089b8ecfSHal Finkel #include "llvm/CodeGen/MachineInstrBuilder.h" 27089b8ecfSHal Finkel #include "llvm/CodeGen/MachineMemOperand.h" 28089b8ecfSHal Finkel #include "llvm/CodeGen/MachineRegisterInfo.h" 29089b8ecfSHal Finkel #include "llvm/CodeGen/PseudoSourceValue.h" 30089b8ecfSHal Finkel #include "llvm/CodeGen/ScheduleDAG.h" 31089b8ecfSHal Finkel #include "llvm/CodeGen/SlotIndexes.h" 32089b8ecfSHal Finkel #include "llvm/MC/MCAsmInfo.h" 33089b8ecfSHal Finkel #include "llvm/Support/CommandLine.h" 34089b8ecfSHal Finkel #include "llvm/Support/Debug.h" 35089b8ecfSHal Finkel #include "llvm/Support/ErrorHandling.h" 36089b8ecfSHal Finkel #include "llvm/Support/TargetRegistry.h" 37089b8ecfSHal Finkel #include "llvm/Support/raw_ostream.h" 38089b8ecfSHal Finkel 39089b8ecfSHal Finkel using namespace llvm; 40089b8ecfSHal Finkel 41089b8ecfSHal Finkel static cl::opt<bool> DisableVSXFMAMutate("disable-ppc-vsx-fma-mutation", 42089b8ecfSHal Finkel cl::desc("Disable VSX FMA instruction mutation"), cl::Hidden); 43089b8ecfSHal Finkel 44089b8ecfSHal Finkel #define DEBUG_TYPE "ppc-vsx-fma-mutate" 45089b8ecfSHal Finkel 46089b8ecfSHal Finkel namespace llvm { namespace PPC { 47089b8ecfSHal Finkel int getAltVSXFMAOpcode(uint16_t Opcode); 48089b8ecfSHal Finkel } } 49089b8ecfSHal Finkel 50089b8ecfSHal Finkel namespace { 51089b8ecfSHal Finkel // PPCVSXFMAMutate pass - For copies between VSX registers and non-VSX registers 52089b8ecfSHal Finkel // (Altivec and scalar floating-point registers), we need to transform the 53089b8ecfSHal Finkel // copies into subregister copies with other restrictions. 54089b8ecfSHal Finkel struct PPCVSXFMAMutate : public MachineFunctionPass { 55089b8ecfSHal Finkel static char ID; 56089b8ecfSHal Finkel PPCVSXFMAMutate() : MachineFunctionPass(ID) { 57089b8ecfSHal Finkel initializePPCVSXFMAMutatePass(*PassRegistry::getPassRegistry()); 58089b8ecfSHal Finkel } 59089b8ecfSHal Finkel 60089b8ecfSHal Finkel LiveIntervals *LIS; 61089b8ecfSHal Finkel const PPCInstrInfo *TII; 62089b8ecfSHal Finkel 63089b8ecfSHal Finkel protected: 64089b8ecfSHal Finkel bool processBlock(MachineBasicBlock &MBB) { 65089b8ecfSHal Finkel bool Changed = false; 66089b8ecfSHal Finkel 67089b8ecfSHal Finkel MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo(); 68089b8ecfSHal Finkel const TargetRegisterInfo *TRI = &TII->getRegisterInfo(); 69089b8ecfSHal Finkel for (MachineBasicBlock::iterator I = MBB.begin(), IE = MBB.end(); 70089b8ecfSHal Finkel I != IE; ++I) { 71089b8ecfSHal Finkel MachineInstr *MI = I; 72089b8ecfSHal Finkel 73089b8ecfSHal Finkel // The default (A-type) VSX FMA form kills the addend (it is taken from 74089b8ecfSHal Finkel // the target register, which is then updated to reflect the result of 75089b8ecfSHal Finkel // the FMA). If the instruction, however, kills one of the registers 76089b8ecfSHal Finkel // used for the product, then we can use the M-form instruction (which 77089b8ecfSHal Finkel // will take that value from the to-be-defined register). 78089b8ecfSHal Finkel 79089b8ecfSHal Finkel int AltOpc = PPC::getAltVSXFMAOpcode(MI->getOpcode()); 80089b8ecfSHal Finkel if (AltOpc == -1) 81089b8ecfSHal Finkel continue; 82089b8ecfSHal Finkel 83089b8ecfSHal Finkel // This pass is run after register coalescing, and so we're looking for 84089b8ecfSHal Finkel // a situation like this: 85089b8ecfSHal Finkel // ... 86089b8ecfSHal Finkel // %vreg5<def> = COPY %vreg9; VSLRC:%vreg5,%vreg9 87089b8ecfSHal Finkel // %vreg5<def,tied1> = XSMADDADP %vreg5<tied0>, %vreg17, %vreg16, 88089b8ecfSHal Finkel // %RM<imp-use>; VSLRC:%vreg5,%vreg17,%vreg16 89089b8ecfSHal Finkel // ... 90089b8ecfSHal Finkel // %vreg9<def,tied1> = XSMADDADP %vreg9<tied0>, %vreg17, %vreg19, 91089b8ecfSHal Finkel // %RM<imp-use>; VSLRC:%vreg9,%vreg17,%vreg19 92089b8ecfSHal Finkel // ... 93089b8ecfSHal Finkel // Where we can eliminate the copy by changing from the A-type to the 94089b8ecfSHal Finkel // M-type instruction. Specifically, for this example, this means: 95089b8ecfSHal Finkel // %vreg5<def,tied1> = XSMADDADP %vreg5<tied0>, %vreg17, %vreg16, 96089b8ecfSHal Finkel // %RM<imp-use>; VSLRC:%vreg5,%vreg17,%vreg16 97089b8ecfSHal Finkel // is replaced by: 98089b8ecfSHal Finkel // %vreg16<def,tied1> = XSMADDMDP %vreg16<tied0>, %vreg18, %vreg9, 99089b8ecfSHal Finkel // %RM<imp-use>; VSLRC:%vreg16,%vreg18,%vreg9 100089b8ecfSHal Finkel // and we remove: %vreg5<def> = COPY %vreg9; VSLRC:%vreg5,%vreg9 101089b8ecfSHal Finkel 102*3ac9cc61SDuncan P. N. Exon Smith SlotIndex FMAIdx = LIS->getInstructionIndex(*MI); 103089b8ecfSHal Finkel 104089b8ecfSHal Finkel VNInfo *AddendValNo = 105089b8ecfSHal Finkel LIS->getInterval(MI->getOperand(1).getReg()).Query(FMAIdx).valueIn(); 1067ffe55aeSHal Finkel 107ff9639d6SHal Finkel // This can be null if the register is undef. 1087ffe55aeSHal Finkel if (!AddendValNo) 109ff9639d6SHal Finkel continue; 110ff9639d6SHal Finkel 111089b8ecfSHal Finkel MachineInstr *AddendMI = LIS->getInstructionFromIndex(AddendValNo->def); 112089b8ecfSHal Finkel 113089b8ecfSHal Finkel // The addend and this instruction must be in the same block. 114089b8ecfSHal Finkel 115089b8ecfSHal Finkel if (!AddendMI || AddendMI->getParent() != MI->getParent()) 116089b8ecfSHal Finkel continue; 117089b8ecfSHal Finkel 118089b8ecfSHal Finkel // The addend must be a full copy within the same register class. 119089b8ecfSHal Finkel 120089b8ecfSHal Finkel if (!AddendMI->isFullCopy()) 121089b8ecfSHal Finkel continue; 122089b8ecfSHal Finkel 123089b8ecfSHal Finkel unsigned AddendSrcReg = AddendMI->getOperand(1).getReg(); 124089b8ecfSHal Finkel if (TargetRegisterInfo::isVirtualRegister(AddendSrcReg)) { 125089b8ecfSHal Finkel if (MRI.getRegClass(AddendMI->getOperand(0).getReg()) != 126089b8ecfSHal Finkel MRI.getRegClass(AddendSrcReg)) 127089b8ecfSHal Finkel continue; 128089b8ecfSHal Finkel } else { 129089b8ecfSHal Finkel // If AddendSrcReg is a physical register, make sure the destination 130089b8ecfSHal Finkel // register class contains it. 131089b8ecfSHal Finkel if (!MRI.getRegClass(AddendMI->getOperand(0).getReg()) 132089b8ecfSHal Finkel ->contains(AddendSrcReg)) 133089b8ecfSHal Finkel continue; 134089b8ecfSHal Finkel } 135089b8ecfSHal Finkel 136089b8ecfSHal Finkel // In theory, there could be other uses of the addend copy before this 137089b8ecfSHal Finkel // fma. We could deal with this, but that would require additional 138089b8ecfSHal Finkel // logic below and I suspect it will not occur in any relevant 139089b8ecfSHal Finkel // situations. Additionally, check whether the copy source is killed 140089b8ecfSHal Finkel // prior to the fma. In order to replace the addend here with the 141089b8ecfSHal Finkel // source of the copy, it must still be live here. We can't use 142089b8ecfSHal Finkel // interval testing for a physical register, so as long as we're 143089b8ecfSHal Finkel // walking the MIs we may as well test liveness here. 1448acae527SHal Finkel // 1458acae527SHal Finkel // FIXME: There is a case that occurs in practice, like this: 1468acae527SHal Finkel // %vreg9<def> = COPY %F1; VSSRC:%vreg9 1478acae527SHal Finkel // ... 1488acae527SHal Finkel // %vreg6<def> = COPY %vreg9; VSSRC:%vreg6,%vreg9 1498acae527SHal Finkel // %vreg7<def> = COPY %vreg9; VSSRC:%vreg7,%vreg9 1508acae527SHal Finkel // %vreg9<def,tied1> = XSMADDASP %vreg9<tied0>, %vreg1, %vreg4; VSSRC: 1518acae527SHal Finkel // %vreg6<def,tied1> = XSMADDASP %vreg6<tied0>, %vreg1, %vreg2; VSSRC: 1528acae527SHal Finkel // %vreg7<def,tied1> = XSMADDASP %vreg7<tied0>, %vreg1, %vreg3; VSSRC: 1538acae527SHal Finkel // which prevents an otherwise-profitable transformation. 154089b8ecfSHal Finkel bool OtherUsers = false, KillsAddendSrc = false; 155089b8ecfSHal Finkel for (auto J = std::prev(I), JE = MachineBasicBlock::iterator(AddendMI); 156089b8ecfSHal Finkel J != JE; --J) { 157089b8ecfSHal Finkel if (J->readsVirtualRegister(AddendMI->getOperand(0).getReg())) { 158089b8ecfSHal Finkel OtherUsers = true; 159089b8ecfSHal Finkel break; 160089b8ecfSHal Finkel } 161089b8ecfSHal Finkel if (J->modifiesRegister(AddendSrcReg, TRI) || 162089b8ecfSHal Finkel J->killsRegister(AddendSrcReg, TRI)) { 163089b8ecfSHal Finkel KillsAddendSrc = true; 164089b8ecfSHal Finkel break; 165089b8ecfSHal Finkel } 166089b8ecfSHal Finkel } 167089b8ecfSHal Finkel 168089b8ecfSHal Finkel if (OtherUsers || KillsAddendSrc) 169089b8ecfSHal Finkel continue; 170089b8ecfSHal Finkel 171089b8ecfSHal Finkel 172d62d8b77SKyle Butt // The transformation doesn't work well with things like: 173d62d8b77SKyle Butt // %vreg5 = A-form-op %vreg5, %vreg11, %vreg5; 174d62d8b77SKyle Butt // unless vreg11 is also a kill, so skip when it is not, 175d62d8b77SKyle Butt // and check operand 3 to see it is also a kill to handle the case: 176d62d8b77SKyle Butt // %vreg5 = A-form-op %vreg5, %vreg5, %vreg11; 177d62d8b77SKyle Butt // where vreg5 and vreg11 are both kills. This case would be skipped 178d62d8b77SKyle Butt // otherwise. 179d62d8b77SKyle Butt unsigned OldFMAReg = MI->getOperand(0).getReg(); 180d62d8b77SKyle Butt 181d62d8b77SKyle Butt // Find one of the product operands that is killed by this instruction. 182089b8ecfSHal Finkel unsigned KilledProdOp = 0, OtherProdOp = 0; 183d62d8b77SKyle Butt unsigned Reg2 = MI->getOperand(2).getReg(); 184d62d8b77SKyle Butt unsigned Reg3 = MI->getOperand(3).getReg(); 185d62d8b77SKyle Butt if (LIS->getInterval(Reg2).Query(FMAIdx).isKill() 186d62d8b77SKyle Butt && Reg2 != OldFMAReg) { 187089b8ecfSHal Finkel KilledProdOp = 2; 188089b8ecfSHal Finkel OtherProdOp = 3; 189d62d8b77SKyle Butt } else if (LIS->getInterval(Reg3).Query(FMAIdx).isKill() 190d62d8b77SKyle Butt && Reg3 != OldFMAReg) { 191089b8ecfSHal Finkel KilledProdOp = 3; 192089b8ecfSHal Finkel OtherProdOp = 2; 193089b8ecfSHal Finkel } 194089b8ecfSHal Finkel 195d62d8b77SKyle Butt // If there are no usable killed product operands, then this 196d62d8b77SKyle Butt // transformation is likely not profitable. 197089b8ecfSHal Finkel if (!KilledProdOp) 198089b8ecfSHal Finkel continue; 199089b8ecfSHal Finkel 2000f2ddcb8SHal Finkel // If the addend copy is used only by this MI, then the addend source 2010f2ddcb8SHal Finkel // register is likely not live here. This could be fixed (based on the 2020f2ddcb8SHal Finkel // legality checks above, the live range for the addend source register 2030f2ddcb8SHal Finkel // could be extended), but it seems likely that such a trivial copy can 2040f2ddcb8SHal Finkel // be coalesced away later, and thus is not worth the effort. 2050f2ddcb8SHal Finkel if (TargetRegisterInfo::isVirtualRegister(AddendSrcReg) && 2060f2ddcb8SHal Finkel !LIS->getInterval(AddendSrcReg).liveAt(FMAIdx)) 2070f2ddcb8SHal Finkel continue; 208089b8ecfSHal Finkel 209089b8ecfSHal Finkel // Transform: (O2 * O3) + O1 -> (O2 * O1) + O3. 210089b8ecfSHal Finkel 211089b8ecfSHal Finkel unsigned KilledProdReg = MI->getOperand(KilledProdOp).getReg(); 212089b8ecfSHal Finkel unsigned OtherProdReg = MI->getOperand(OtherProdOp).getReg(); 213089b8ecfSHal Finkel 214089b8ecfSHal Finkel unsigned AddSubReg = AddendMI->getOperand(1).getSubReg(); 215089b8ecfSHal Finkel unsigned KilledProdSubReg = MI->getOperand(KilledProdOp).getSubReg(); 216089b8ecfSHal Finkel unsigned OtherProdSubReg = MI->getOperand(OtherProdOp).getSubReg(); 217089b8ecfSHal Finkel 218089b8ecfSHal Finkel bool AddRegKill = AddendMI->getOperand(1).isKill(); 219089b8ecfSHal Finkel bool KilledProdRegKill = MI->getOperand(KilledProdOp).isKill(); 220089b8ecfSHal Finkel bool OtherProdRegKill = MI->getOperand(OtherProdOp).isKill(); 221089b8ecfSHal Finkel 222089b8ecfSHal Finkel bool AddRegUndef = AddendMI->getOperand(1).isUndef(); 223089b8ecfSHal Finkel bool KilledProdRegUndef = MI->getOperand(KilledProdOp).isUndef(); 224089b8ecfSHal Finkel bool OtherProdRegUndef = MI->getOperand(OtherProdOp).isUndef(); 225089b8ecfSHal Finkel 22628b01a51SKyle Butt // If there isn't a class that fits, we can't perform the transform. 22728b01a51SKyle Butt // This is needed for correctness with a mixture of VSX and Altivec 22828b01a51SKyle Butt // instructions to make sure that a low VSX register is not assigned to 22928b01a51SKyle Butt // the Altivec instruction. 23028b01a51SKyle Butt if (!MRI.constrainRegClass(KilledProdReg, 23128b01a51SKyle Butt MRI.getRegClass(OldFMAReg))) 23228b01a51SKyle Butt continue; 23328b01a51SKyle Butt 234089b8ecfSHal Finkel assert(OldFMAReg == AddendMI->getOperand(0).getReg() && 235089b8ecfSHal Finkel "Addend copy not tied to old FMA output!"); 236089b8ecfSHal Finkel 237089b8ecfSHal Finkel DEBUG(dbgs() << "VSX FMA Mutation:\n " << *MI;); 238089b8ecfSHal Finkel 239089b8ecfSHal Finkel MI->getOperand(0).setReg(KilledProdReg); 240089b8ecfSHal Finkel MI->getOperand(1).setReg(KilledProdReg); 241673b493eSHal Finkel MI->getOperand(3).setReg(AddendSrcReg); 242089b8ecfSHal Finkel 243089b8ecfSHal Finkel MI->getOperand(0).setSubReg(KilledProdSubReg); 244089b8ecfSHal Finkel MI->getOperand(1).setSubReg(KilledProdSubReg); 245089b8ecfSHal Finkel MI->getOperand(3).setSubReg(AddSubReg); 246089b8ecfSHal Finkel 247089b8ecfSHal Finkel MI->getOperand(1).setIsKill(KilledProdRegKill); 248089b8ecfSHal Finkel MI->getOperand(3).setIsKill(AddRegKill); 249089b8ecfSHal Finkel 250089b8ecfSHal Finkel MI->getOperand(1).setIsUndef(KilledProdRegUndef); 251089b8ecfSHal Finkel MI->getOperand(3).setIsUndef(AddRegUndef); 252089b8ecfSHal Finkel 253089b8ecfSHal Finkel MI->setDesc(TII->get(AltOpc)); 254089b8ecfSHal Finkel 255d62d8b77SKyle Butt // If the addend is also a multiplicand, replace it with the addend 256d62d8b77SKyle Butt // source in both places. 257d62d8b77SKyle Butt if (OtherProdReg == AddendMI->getOperand(0).getReg()) { 258d62d8b77SKyle Butt MI->getOperand(2).setReg(AddendSrcReg); 259d62d8b77SKyle Butt MI->getOperand(2).setSubReg(AddSubReg); 260d62d8b77SKyle Butt MI->getOperand(2).setIsKill(AddRegKill); 261d62d8b77SKyle Butt MI->getOperand(2).setIsUndef(AddRegUndef); 262d62d8b77SKyle Butt } else { 263d62d8b77SKyle Butt MI->getOperand(2).setReg(OtherProdReg); 264d62d8b77SKyle Butt MI->getOperand(2).setSubReg(OtherProdSubReg); 265d62d8b77SKyle Butt MI->getOperand(2).setIsKill(OtherProdRegKill); 266d62d8b77SKyle Butt MI->getOperand(2).setIsUndef(OtherProdRegUndef); 267d62d8b77SKyle Butt } 268d62d8b77SKyle Butt 269089b8ecfSHal Finkel DEBUG(dbgs() << " -> " << *MI); 270089b8ecfSHal Finkel 271089b8ecfSHal Finkel // The killed product operand was killed here, so we can reuse it now 272089b8ecfSHal Finkel // for the result of the fma. 273089b8ecfSHal Finkel 274089b8ecfSHal Finkel LiveInterval &FMAInt = LIS->getInterval(OldFMAReg); 275089b8ecfSHal Finkel VNInfo *FMAValNo = FMAInt.getVNInfoAt(FMAIdx.getRegSlot()); 276089b8ecfSHal Finkel for (auto UI = MRI.reg_nodbg_begin(OldFMAReg), UE = MRI.reg_nodbg_end(); 277089b8ecfSHal Finkel UI != UE;) { 278089b8ecfSHal Finkel MachineOperand &UseMO = *UI; 279089b8ecfSHal Finkel MachineInstr *UseMI = UseMO.getParent(); 280089b8ecfSHal Finkel ++UI; 281089b8ecfSHal Finkel 282089b8ecfSHal Finkel // Don't replace the result register of the copy we're about to erase. 283089b8ecfSHal Finkel if (UseMI == AddendMI) 284089b8ecfSHal Finkel continue; 285089b8ecfSHal Finkel 28628b01a51SKyle Butt UseMO.substVirtReg(KilledProdReg, KilledProdSubReg, *TRI); 287089b8ecfSHal Finkel } 288089b8ecfSHal Finkel 289089b8ecfSHal Finkel // Extend the live intervals of the killed product operand to hold the 290089b8ecfSHal Finkel // fma result. 291089b8ecfSHal Finkel 292089b8ecfSHal Finkel LiveInterval &NewFMAInt = LIS->getInterval(KilledProdReg); 293089b8ecfSHal Finkel for (LiveInterval::iterator AI = FMAInt.begin(), AE = FMAInt.end(); 294089b8ecfSHal Finkel AI != AE; ++AI) { 295089b8ecfSHal Finkel // Don't add the segment that corresponds to the original copy. 296089b8ecfSHal Finkel if (AI->valno == AddendValNo) 297089b8ecfSHal Finkel continue; 298089b8ecfSHal Finkel 299089b8ecfSHal Finkel VNInfo *NewFMAValNo = 300089b8ecfSHal Finkel NewFMAInt.getNextValue(AI->start, 301089b8ecfSHal Finkel LIS->getVNInfoAllocator()); 302089b8ecfSHal Finkel 303089b8ecfSHal Finkel NewFMAInt.addSegment(LiveInterval::Segment(AI->start, AI->end, 304089b8ecfSHal Finkel NewFMAValNo)); 305089b8ecfSHal Finkel } 306089b8ecfSHal Finkel DEBUG(dbgs() << " extended: " << NewFMAInt << '\n'); 307089b8ecfSHal Finkel 308673b493eSHal Finkel // Extend the live interval of the addend source (it might end at the 309673b493eSHal Finkel // copy to be removed, or somewhere in between there and here). This 310673b493eSHal Finkel // is necessary only if it is a physical register. 311673b493eSHal Finkel if (!TargetRegisterInfo::isVirtualRegister(AddendSrcReg)) 312673b493eSHal Finkel for (MCRegUnitIterator Units(AddendSrcReg, TRI); Units.isValid(); 313673b493eSHal Finkel ++Units) { 314673b493eSHal Finkel unsigned Unit = *Units; 315673b493eSHal Finkel 316673b493eSHal Finkel LiveRange &AddendSrcRange = LIS->getRegUnit(Unit); 317673b493eSHal Finkel AddendSrcRange.extendInBlock(LIS->getMBBStartIdx(&MBB), 318673b493eSHal Finkel FMAIdx.getRegSlot()); 319673b493eSHal Finkel DEBUG(dbgs() << " extended: " << AddendSrcRange << '\n'); 320673b493eSHal Finkel } 321673b493eSHal Finkel 322089b8ecfSHal Finkel FMAInt.removeValNo(FMAValNo); 323089b8ecfSHal Finkel DEBUG(dbgs() << " trimmed: " << FMAInt << '\n'); 324089b8ecfSHal Finkel 325089b8ecfSHal Finkel // Remove the (now unused) copy. 326089b8ecfSHal Finkel 327089b8ecfSHal Finkel DEBUG(dbgs() << " removing: " << *AddendMI << '\n'); 328*3ac9cc61SDuncan P. N. Exon Smith LIS->RemoveMachineInstrFromMaps(*AddendMI); 329089b8ecfSHal Finkel AddendMI->eraseFromParent(); 330089b8ecfSHal Finkel 331089b8ecfSHal Finkel Changed = true; 332089b8ecfSHal Finkel } 333089b8ecfSHal Finkel 334089b8ecfSHal Finkel return Changed; 335089b8ecfSHal Finkel } 336089b8ecfSHal Finkel 337089b8ecfSHal Finkel public: 338089b8ecfSHal Finkel bool runOnMachineFunction(MachineFunction &MF) override { 339089b8ecfSHal Finkel // If we don't have VSX then go ahead and return without doing 340089b8ecfSHal Finkel // anything. 341089b8ecfSHal Finkel const PPCSubtarget &STI = MF.getSubtarget<PPCSubtarget>(); 342089b8ecfSHal Finkel if (!STI.hasVSX()) 343089b8ecfSHal Finkel return false; 344089b8ecfSHal Finkel 345089b8ecfSHal Finkel LIS = &getAnalysis<LiveIntervals>(); 346089b8ecfSHal Finkel 347089b8ecfSHal Finkel TII = STI.getInstrInfo(); 348089b8ecfSHal Finkel 349089b8ecfSHal Finkel bool Changed = false; 350089b8ecfSHal Finkel 351089b8ecfSHal Finkel if (DisableVSXFMAMutate) 352089b8ecfSHal Finkel return Changed; 353089b8ecfSHal Finkel 354089b8ecfSHal Finkel for (MachineFunction::iterator I = MF.begin(); I != MF.end();) { 355089b8ecfSHal Finkel MachineBasicBlock &B = *I++; 356089b8ecfSHal Finkel if (processBlock(B)) 357089b8ecfSHal Finkel Changed = true; 358089b8ecfSHal Finkel } 359089b8ecfSHal Finkel 360089b8ecfSHal Finkel return Changed; 361089b8ecfSHal Finkel } 362089b8ecfSHal Finkel 363089b8ecfSHal Finkel void getAnalysisUsage(AnalysisUsage &AU) const override { 364089b8ecfSHal Finkel AU.addRequired<LiveIntervals>(); 365089b8ecfSHal Finkel AU.addPreserved<LiveIntervals>(); 366089b8ecfSHal Finkel AU.addRequired<SlotIndexes>(); 367089b8ecfSHal Finkel AU.addPreserved<SlotIndexes>(); 368089b8ecfSHal Finkel MachineFunctionPass::getAnalysisUsage(AU); 369089b8ecfSHal Finkel } 370089b8ecfSHal Finkel }; 371f00654e3SAlexander Kornienko } 372089b8ecfSHal Finkel 373089b8ecfSHal Finkel INITIALIZE_PASS_BEGIN(PPCVSXFMAMutate, DEBUG_TYPE, 374089b8ecfSHal Finkel "PowerPC VSX FMA Mutation", false, false) 375089b8ecfSHal Finkel INITIALIZE_PASS_DEPENDENCY(LiveIntervals) 376089b8ecfSHal Finkel INITIALIZE_PASS_DEPENDENCY(SlotIndexes) 377089b8ecfSHal Finkel INITIALIZE_PASS_END(PPCVSXFMAMutate, DEBUG_TYPE, 378089b8ecfSHal Finkel "PowerPC VSX FMA Mutation", false, false) 379089b8ecfSHal Finkel 380089b8ecfSHal Finkel char &llvm::PPCVSXFMAMutateID = PPCVSXFMAMutate::ID; 381089b8ecfSHal Finkel 382089b8ecfSHal Finkel char PPCVSXFMAMutate::ID = 0; 38370ad98acSNAKAMURA Takumi FunctionPass *llvm::createPPCVSXFMAMutatePass() { 38470ad98acSNAKAMURA Takumi return new PPCVSXFMAMutate(); 38570ad98acSNAKAMURA Takumi } 386