summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MachineCopyPropagation.cpp
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2018-09-25 04:45:25 +0000
committerJustin Bogner <mail@justinbogner.com>2018-09-25 04:45:25 +0000
commitdb02d3d4b38e513593dbe562f94ecb6fad345314 (patch)
tree8ebe6e8fe734be582f14153be02e2a497cbf0b65 /llvm/lib/CodeGen/MachineCopyPropagation.cpp
parent0e5b60326e306cba3f4434692e5d37ffee8a2ae9 (diff)
downloadbcm5719-llvm-db02d3d4b38e513593dbe562f94ecb6fad345314.tar.gz
bcm5719-llvm-db02d3d4b38e513593dbe562f94ecb6fad345314.zip
[MachineCopyPropagation] Rework how we manage RegMask clobbers
Instead of updating the CopyTracker's maps each time we come across a RegMask, defer checking for this kind of interference until we're actually trying to propagate a copy. This avoids the need to repeatedly iterate over maps in the cases where we don't end up doing any work. This is a slight compile time improvement for MachineCopyPropagation as is, but it also enables a much bigger improvement that I'll follow up with soon. Differential Revision: https://reviews.llvm.org/D52370 llvm-svn: 342940
Diffstat (limited to 'llvm/lib/CodeGen/MachineCopyPropagation.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineCopyPropagation.cpp58
1 files changed, 23 insertions, 35 deletions
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 0e06ddf06cf..b5309087d50 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -99,33 +99,6 @@ public:
}
}
- /// Remove any entry in the tracker's copy maps that is marked clobbered in \p
- /// RegMask. The map will typically have a lot fewer entries than the regmask
- /// clobbers, so this is more efficient than iterating the clobbered registers
- /// and calling ClobberRegister() on them.
- void removeClobberedRegs(const MachineOperand &RegMask,
- const TargetRegisterInfo &TRI) {
- auto RemoveFromMap = [&RegMask](Reg2MIMap &Map) {
- for (Reg2MIMap::iterator I = Map.begin(), E = Map.end(), Next; I != E;
- I = Next) {
- Next = std::next(I);
- if (RegMask.clobbersPhysReg(I->first))
- Map.erase(I);
- }
- };
- RemoveFromMap(AvailCopyMap);
- RemoveFromMap(CopyMap);
-
- for (SourceMap::iterator I = SrcMap.begin(), E = SrcMap.end(), Next; I != E;
- I = Next) {
- Next = std::next(I);
- if (RegMask.clobbersPhysReg(I->first)) {
- markRegsUnavailable(I->second, TRI);
- SrcMap.erase(I);
- }
- }
- }
-
/// Clobber a single register, removing it from the tracker's copy maps.
void clobberRegister(unsigned Reg, const TargetRegisterInfo &TRI) {
for (MCRegAliasIterator AI(Reg, &TRI, true); AI.isValid(); ++AI) {
@@ -163,11 +136,24 @@ public:
bool hasAvailableCopies() { return !AvailCopyMap.empty(); }
- MachineInstr *findAvailCopy(unsigned Reg) {
+ MachineInstr *findAvailCopy(MachineInstr &DestCopy, unsigned Reg) {
auto CI = AvailCopyMap.find(Reg);
- if (CI != AvailCopyMap.end())
- return CI->second;
- return nullptr;
+ if (CI == AvailCopyMap.end())
+ return nullptr;
+ MachineInstr &AvailCopy = *CI->second;
+
+ // Check that the available copy isn't clobbered by any regmasks between
+ // itself and the destination.
+ unsigned AvailSrc = AvailCopy.getOperand(1).getReg();
+ unsigned AvailDef = AvailCopy.getOperand(0).getReg();
+ for (const MachineInstr &MI :
+ make_range(AvailCopy.getIterator(), DestCopy.getIterator()))
+ for (const MachineOperand &MO : MI.operands())
+ if (MO.isRegMask())
+ if (MO.clobbersPhysReg(AvailSrc) || MO.clobbersPhysReg(AvailDef))
+ return nullptr;
+
+ return &AvailCopy;
}
MachineInstr *findCopy(unsigned Reg) {
@@ -277,7 +263,7 @@ bool MachineCopyPropagation::eraseIfRedundant(MachineInstr &Copy, unsigned Src,
return false;
// Search for an existing copy.
- MachineInstr *PrevCopy = Tracker.findAvailCopy(Def);
+ MachineInstr *PrevCopy = Tracker.findAvailCopy(Copy, Def);
if (!PrevCopy)
return false;
@@ -398,7 +384,7 @@ void MachineCopyPropagation::forwardUses(MachineInstr &MI) {
if (!MOUse.isRenamable())
continue;
- MachineInstr *Copy = Tracker.findAvailCopy(MOUse.getReg());
+ MachineInstr *Copy = Tracker.findAvailCopy(MI, MOUse.getReg());
if (!Copy)
continue;
@@ -586,6 +572,10 @@ void MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
LLVM_DEBUG(dbgs() << "MCP: Removing copy due to regmask clobbering: ";
MaybeDead->dump());
+ // Make sure we invalidate any entries in the copy maps before erasing
+ // the instruction.
+ Tracker.clobberRegister(Reg, *TRI);
+
// erase() will return the next valid iterator pointing to the next
// element after the erased one.
DI = MaybeDeadCopies.erase(DI);
@@ -593,8 +583,6 @@ void MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
Changed = true;
++NumDeletes;
}
-
- Tracker.removeClobberedRegs(*RegMask, *TRI);
}
// Any previous copy definition or reading the Defs is no longer available.
OpenPOWER on IntegriCloud