diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-06-30 00:01:54 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-06-30 00:01:54 +0000 |
commit | 9cfc75c214d42eebd74f9f5f5d20d453404d5db4 (patch) | |
tree | 0f9f9110f564b6287a4db4cdf9e6097d19085c7e /llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp | |
parent | c3701e8b9252498e2ed27a99238f71cb07dd43a4 (diff) | |
download | llvm-9cfc75c214d42eebd74f9f5f5d20d453404d5db4.zip llvm-9cfc75c214d42eebd74f9f5f5d20d453404d5db4.tar.gz llvm-9cfc75c214d42eebd74f9f5f5d20d453404d5db4.tar.bz2 |
CodeGen: Use MachineInstr& in TargetInstrInfo, NFC
This is mostly a mechanical change to make TargetInstrInfo API take
MachineInstr& (instead of MachineInstr* or MachineBasicBlock::iterator)
when the argument is expected to be a valid MachineInstr. This is a
general API improvement.
Although it would be possible to do this one function at a time, that
would demand a quadratic amount of churn since many of these functions
call each other. Instead I've done everything as a block and just
updated what was necessary.
This is mostly mechanical fixes: adding and removing `*` and `&`
operators. The only non-mechanical change is to split
ARMBaseInstrInfo::getOperandLatencyImpl out from
ARMBaseInstrInfo::getOperandLatency. Previously, the latter took a
`MachineInstr*` which it updated to the instruction bundle leader; now,
the latter calls the former either with the same `MachineInstr&` or the
bundle leader.
As a side effect, this removes a bunch of MachineInstr* to
MachineBasicBlock::iterator implicit conversions, a necessary step
toward fixing PR26753.
Note: I updated WebAssembly, Lanai, and AVR (despite being
off-by-default) since it turned out to be easy. I couldn't run tests
for AVR since llc doesn't link with it turned on.
llvm-svn: 274189
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp index 12431be..0709668 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp @@ -217,10 +217,9 @@ static void Query(const MachineInstr *MI, AliasAnalysis &AA, } // Test whether Def is safe and profitable to rematerialize. -static bool ShouldRematerialize(const MachineInstr *Def, AliasAnalysis &AA, +static bool ShouldRematerialize(const MachineInstr &Def, AliasAnalysis &AA, const WebAssemblyInstrInfo *TII) { - return Def->isAsCheapAsAMove() && - TII->isTriviallyReMaterializable(Def, &AA); + return Def.isAsCheapAsAMove() && TII->isTriviallyReMaterializable(Def, &AA); } // Identify the definition for this register at this point. This is a @@ -475,19 +474,18 @@ static MachineInstr *MoveForSingleUse(unsigned Reg, MachineOperand& Op, /// A trivially cloneable instruction; clone it and nest the new copy with the /// current instruction. -static MachineInstr * -RematerializeCheapDef(unsigned Reg, MachineOperand &Op, MachineInstr *Def, - MachineBasicBlock &MBB, MachineInstr *Insert, - LiveIntervals &LIS, WebAssemblyFunctionInfo &MFI, - MachineRegisterInfo &MRI, const WebAssemblyInstrInfo *TII, - const WebAssemblyRegisterInfo *TRI) { - DEBUG(dbgs() << "Rematerializing cheap def: "; Def->dump()); +static MachineInstr *RematerializeCheapDef( + unsigned Reg, MachineOperand &Op, MachineInstr &Def, MachineBasicBlock &MBB, + MachineBasicBlock::instr_iterator Insert, LiveIntervals &LIS, + WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI, + const WebAssemblyInstrInfo *TII, const WebAssemblyRegisterInfo *TRI) { + DEBUG(dbgs() << "Rematerializing cheap def: "; Def.dump()); DEBUG(dbgs() << " - for use in "; Op.getParent()->dump()); unsigned NewReg = MRI.createVirtualRegister(MRI.getRegClass(Reg)); TII->reMaterialize(MBB, Insert, NewReg, 0, Def, *TRI); Op.setReg(NewReg); - MachineInstr *Clone = &*std::prev(MachineBasicBlock::instr_iterator(Insert)); + MachineInstr *Clone = &*std::prev(Insert); LIS.InsertMachineInstrInMaps(*Clone); LIS.createAndComputeVirtRegInterval(NewReg); MFI.stackifyVReg(NewReg); @@ -500,17 +498,17 @@ RematerializeCheapDef(unsigned Reg, MachineOperand &Op, MachineInstr *Def, if (!IsDead) { LiveInterval &LI = LIS.getInterval(Reg); ShrinkToUses(LI, LIS); - IsDead = !LI.liveAt(LIS.getInstructionIndex(*Def).getDeadSlot()); + IsDead = !LI.liveAt(LIS.getInstructionIndex(Def).getDeadSlot()); } // If that was the last use of the original, delete the original. if (IsDead) { DEBUG(dbgs() << " - Deleting original\n"); - SlotIndex Idx = LIS.getInstructionIndex(*Def).getRegSlot(); + SlotIndex Idx = LIS.getInstructionIndex(Def).getRegSlot(); LIS.removePhysRegDefAt(WebAssembly::ARGUMENTS, Idx); LIS.removeInterval(Reg); - LIS.RemoveMachineInstrFromMaps(*Def); - Def->eraseFromParent(); + LIS.RemoveMachineInstrFromMaps(Def); + Def.eraseFromParent(); } return Clone; @@ -678,15 +676,15 @@ public: assert(!Declined && "Don't decline commuting until you've finished trying it"); // Commuting didn't help. Revert it. - TII->commuteInstruction(Insert, /*NewMI=*/false, Operand0, Operand1); + TII->commuteInstruction(*Insert, /*NewMI=*/false, Operand0, Operand1); TentativelyCommuting = false; Declined = true; } else if (!Declined && TreeWalker.HasRemainingOperands(Insert)) { Operand0 = TargetInstrInfo::CommuteAnyOperandIndex; Operand1 = TargetInstrInfo::CommuteAnyOperandIndex; - if (TII->findCommutedOpIndices(Insert, Operand0, Operand1)) { + if (TII->findCommutedOpIndices(*Insert, Operand0, Operand1)) { // Tentatively commute the operands and try again. - TII->commuteInstruction(Insert, /*NewMI=*/false, Operand0, Operand1); + TII->commuteInstruction(*Insert, /*NewMI=*/false, Operand0, Operand1); TreeWalker.ResetTopOperands(Insert); TentativelyCommuting = true; Declined = false; @@ -782,9 +780,10 @@ bool WebAssemblyRegStackify::runOnMachineFunction(MachineFunction &MF) { !TreeWalker.IsOnStack(Reg); if (CanMove && HasOneUse(Reg, Def, MRI, MDT, LIS)) { Insert = MoveForSingleUse(Reg, Op, Def, MBB, Insert, LIS, MFI, MRI); - } else if (ShouldRematerialize(Def, AA, TII)) { - Insert = RematerializeCheapDef(Reg, Op, Def, MBB, Insert, LIS, MFI, - MRI, TII, TRI); + } else if (ShouldRematerialize(*Def, AA, TII)) { + Insert = + RematerializeCheapDef(Reg, Op, *Def, MBB, Insert->getIterator(), + LIS, MFI, MRI, TII, TRI); } else if (CanMove && OneUseDominatesOtherUses(Reg, Op, MBB, MRI, MDT, LIS, MFI)) { Insert = MoveAndTeeForMultiUse(Reg, Op, Def, MBB, Insert, LIS, MFI, |