diff --git a/llvm/include/llvm/CodeGen/MachineTraceMetrics.h b/llvm/include/llvm/CodeGen/MachineTraceMetrics.h index d51de24d64e8d..74b051d0cddc6 100644 --- a/llvm/include/llvm/CodeGen/MachineTraceMetrics.h +++ b/llvm/include/llvm/CodeGen/MachineTraceMetrics.h @@ -83,6 +83,8 @@ struct LiveRegUnit { LiveRegUnit(unsigned RU) : RegUnit(RU) {} }; +using LiveRegUnitSet = SparseSet; + /// Strategies for selecting traces. enum class MachineTraceStrategy { /// Select the trace through a block that has the fewest instructions. @@ -380,16 +382,15 @@ class MachineTraceMetrics { Trace getTrace(const MachineBasicBlock *MBB); /// Updates the depth of an machine instruction, given RegUnits. - void updateDepth(TraceBlockInfo &TBI, const MachineInstr&, - SparseSet &RegUnits); - void updateDepth(const MachineBasicBlock *, const MachineInstr&, - SparseSet &RegUnits); + void updateDepth(TraceBlockInfo &TBI, const MachineInstr &, + LiveRegUnitSet &RegUnits); + void updateDepth(const MachineBasicBlock *, const MachineInstr &, + LiveRegUnitSet &RegUnits); /// Updates the depth of the instructions from Start to End. void updateDepths(MachineBasicBlock::iterator Start, MachineBasicBlock::iterator End, - SparseSet &RegUnits); - + LiveRegUnitSet &RegUnits); }; /// Get the trace ensemble representing the given trace selection strategy. diff --git a/llvm/lib/CodeGen/MachineCombiner.cpp b/llvm/lib/CodeGen/MachineCombiner.cpp index 54e2a009b464d..205c79e71854f 100644 --- a/llvm/lib/CodeGen/MachineCombiner.cpp +++ b/llvm/lib/CodeGen/MachineCombiner.cpp @@ -482,9 +482,8 @@ insertDeleteInstructions(MachineBasicBlock *MBB, MachineInstr &MI, SmallVectorImpl &InsInstrs, SmallVectorImpl &DelInstrs, MachineTraceMetrics::Ensemble *TraceEnsemble, - SparseSet &RegUnits, - const TargetInstrInfo *TII, unsigned Pattern, - bool IncrementalUpdate) { + LiveRegUnitSet &RegUnits, const TargetInstrInfo *TII, + unsigned Pattern, bool IncrementalUpdate) { // If we want to fix up some placeholder for some target, do it now. // We need this because in genAlternativeCodeSequence, we have not decided the // better pattern InsInstrs or DelInstrs, so we don't want generate some @@ -565,7 +564,7 @@ bool MachineCombiner::combineInstructions(MachineBasicBlock *MBB) { if (!TraceEnsemble) TraceEnsemble = Traces->getEnsemble(TII->getMachineCombinerTraceStrategy()); - SparseSet RegUnits; + LiveRegUnitSet RegUnits; RegUnits.setUniverse(TRI->getNumRegUnits()); bool OptForSize = llvm::shouldOptimizeForSize(MBB, PSI, MBFI); diff --git a/llvm/lib/CodeGen/MachineTraceMetrics.cpp b/llvm/lib/CodeGen/MachineTraceMetrics.cpp index c40bd1c83f34a..0312a8e33d669 100644 --- a/llvm/lib/CodeGen/MachineTraceMetrics.cpp +++ b/llvm/lib/CodeGen/MachineTraceMetrics.cpp @@ -737,7 +737,7 @@ static void getPHIDeps(const MachineInstr &UseMI, // tracking set when scanning instructions downwards. static void updatePhysDepsDownwards(const MachineInstr *UseMI, SmallVectorImpl &Deps, - SparseSet &RegUnits, + LiveRegUnitSet &RegUnits, const TargetRegisterInfo *TRI) { SmallVector Kills; SmallVector LiveDefOps; @@ -758,7 +758,7 @@ static void updatePhysDepsDownwards(const MachineInstr *UseMI, if (!MO.readsReg()) continue; for (MCRegUnit Unit : TRI->regunits(Reg)) { - SparseSet::iterator I = RegUnits.find(Unit); + LiveRegUnitSet::iterator I = RegUnits.find(Unit); if (I == RegUnits.end()) continue; Deps.push_back(DataDep(I->MI, I->Op, MO.getOperandNo())); @@ -813,9 +813,9 @@ computeCrossBlockCriticalPath(const TraceBlockInfo &TBI) { return MaxLen; } -void MachineTraceMetrics::Ensemble:: -updateDepth(MachineTraceMetrics::TraceBlockInfo &TBI, const MachineInstr &UseMI, - SparseSet &RegUnits) { +void MachineTraceMetrics::Ensemble::updateDepth(TraceBlockInfo &TBI, + const MachineInstr &UseMI, + LiveRegUnitSet &RegUnits) { SmallVector Deps; // Collect all data dependencies. if (UseMI.isPHI()) @@ -852,18 +852,17 @@ updateDepth(MachineTraceMetrics::TraceBlockInfo &TBI, const MachineInstr &UseMI, } } -void MachineTraceMetrics::Ensemble:: -updateDepth(const MachineBasicBlock *MBB, const MachineInstr &UseMI, - SparseSet &RegUnits) { +void MachineTraceMetrics::Ensemble::updateDepth(const MachineBasicBlock *MBB, + const MachineInstr &UseMI, + LiveRegUnitSet &RegUnits) { updateDepth(BlockInfo[MBB->getNumber()], UseMI, RegUnits); } -void MachineTraceMetrics::Ensemble:: -updateDepths(MachineBasicBlock::iterator Start, - MachineBasicBlock::iterator End, - SparseSet &RegUnits) { - for (; Start != End; Start++) - updateDepth(Start->getParent(), *Start, RegUnits); +void MachineTraceMetrics::Ensemble::updateDepths( + MachineBasicBlock::iterator Start, MachineBasicBlock::iterator End, + LiveRegUnitSet &RegUnits) { + for (; Start != End; Start++) + updateDepth(Start->getParent(), *Start, RegUnits); } /// Compute instruction depths for all instructions above or in MBB in its @@ -887,7 +886,7 @@ computeInstrDepths(const MachineBasicBlock *MBB) { // in the trace. We should track any live-out physregs that were defined in // the trace. This is quite rare in SSA form, typically created by CSE // hoisting a compare. - SparseSet RegUnits; + LiveRegUnitSet RegUnits; RegUnits.setUniverse(MTM.TRI->getNumRegUnits()); // Go through trace blocks in top-down order, stopping after the center block. @@ -925,7 +924,7 @@ computeInstrDepths(const MachineBasicBlock *MBB) { // Return the issue height of MI after considering any live regunits. // Height is the issue height computed from virtual register dependencies alone. static unsigned updatePhysDepsUpwards(const MachineInstr &MI, unsigned Height, - SparseSet &RegUnits, + LiveRegUnitSet &RegUnits, const TargetSchedModel &SchedModel, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) { @@ -944,7 +943,7 @@ static unsigned updatePhysDepsUpwards(const MachineInstr &MI, unsigned Height, // This is a def of Reg. Remove corresponding entries from RegUnits, and // update MI Height to consider the physreg dependencies. for (MCRegUnit Unit : TRI->regunits(Reg.asMCReg())) { - SparseSet::iterator I = RegUnits.find(Unit); + LiveRegUnitSet::iterator I = RegUnits.find(Unit); if (I == RegUnits.end()) continue; unsigned DepHeight = I->Cycle; @@ -1048,7 +1047,7 @@ computeInstrHeights(const MachineBasicBlock *MBB) { // For physregs, the def isn't known when we see the use. // Instead, keep track of the highest use of each regunit. - SparseSet RegUnits; + LiveRegUnitSet RegUnits; RegUnits.setUniverse(MTM.TRI->getNumRegUnits()); // If the bottom of the trace was already precomputed, initialize heights