Skip to content

Commit 97d0ffb

Browse files
committed
ScheduleDAGInstrs: Rework schedule graph builder.
Re-comitting with a change that avoids undefined uses getting put into the VRegUses list. The new algorithm remembers the uses encountered while walking backwards until a matching def is found. Contrary to the previous version this: - Works without LiveIntervals being available - Allows to increase the precision to subregisters/lanemasks (not used for now) The changes in the AMDGPU tests are necessary because the R600 scheduler is not stable with respect to the order of nodes in the ready queues. Differential Revision: http://reviews.llvm.org/D9068 llvm-svn: 254683
1 parent 8267e7d commit 97d0ffb

16 files changed

+279
-156
lines changed

llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,26 @@ namespace llvm {
3333
/// An individual mapping from virtual register number to SUnit.
3434
struct VReg2SUnit {
3535
unsigned VirtReg;
36+
LaneBitmask LaneMask;
3637
SUnit *SU;
3738

38-
VReg2SUnit(unsigned reg, SUnit *su): VirtReg(reg), SU(su) {}
39+
VReg2SUnit(unsigned VReg, LaneBitmask LaneMask, SUnit *SU)
40+
: VirtReg(VReg), LaneMask(LaneMask), SU(SU) {}
3941

4042
unsigned getSparseSetIndex() const {
4143
return TargetRegisterInfo::virtReg2Index(VirtReg);
4244
}
4345
};
4446

47+
/// Mapping from virtual register to SUnit including an operand index.
48+
struct VReg2SUnitOperIdx : public VReg2SUnit {
49+
unsigned OperandIndex;
50+
51+
VReg2SUnitOperIdx(unsigned VReg, LaneBitmask LaneMask,
52+
unsigned OperandIndex, SUnit *SU)
53+
: VReg2SUnit(VReg, LaneMask, SU), OperandIndex(OperandIndex) {}
54+
};
55+
4556
/// Record a physical register access.
4657
/// For non-data-dependent uses, OpIdx == -1.
4758
struct PhysRegSUOper {
@@ -69,7 +80,10 @@ namespace llvm {
6980
/// Track local uses of virtual registers. These uses are gathered by the DAG
7081
/// builder and may be consulted by the scheduler to avoid iterating an entire
7182
/// vreg use list.
72-
typedef SparseMultiSet<VReg2SUnit, VirtReg2IndexFunctor> VReg2UseMap;
83+
typedef SparseMultiSet<VReg2SUnit, VirtReg2IndexFunctor> VReg2SUnitMultiMap;
84+
85+
typedef SparseMultiSet<VReg2SUnitOperIdx, VirtReg2IndexFunctor>
86+
VReg2SUnitOperIdxMultiMap;
7387

7488
/// ScheduleDAGInstrs - A ScheduleDAG subclass for scheduling lists of
7589
/// MachineInstrs.
@@ -95,6 +109,9 @@ namespace llvm {
95109
/// it has taken responsibility for scheduling the terminator correctly.
96110
bool CanHandleTerminators;
97111

112+
/// Whether lane masks should get tracked.
113+
bool TrackLaneMasks;
114+
98115
/// State specific to the current scheduling region.
99116
/// ------------------------------------------------
100117

@@ -117,7 +134,7 @@ namespace llvm {
117134
/// After calling BuildSchedGraph, each vreg used in the scheduling region
118135
/// is mapped to a set of SUnits. These include all local vreg uses, not
119136
/// just the uses for a singly defined vreg.
120-
VReg2UseMap VRegUses;
137+
VReg2SUnitMultiMap VRegUses;
121138

122139
/// State internal to DAG building.
123140
/// -------------------------------
@@ -129,8 +146,12 @@ namespace llvm {
129146
Reg2SUnitsMap Defs;
130147
Reg2SUnitsMap Uses;
131148

132-
/// Track the last instruction in this region defining each virtual register.
133-
VReg2SUnitMap VRegDefs;
149+
/// Tracks the last instruction(s) in this region defining each virtual
150+
/// register. There may be multiple current definitions for a register with
151+
/// disjunct lanemasks.
152+
VReg2SUnitMultiMap CurrentVRegDefs;
153+
/// Tracks the last instructions in this region using each virtual register.
154+
VReg2SUnitOperIdxMultiMap CurrentVRegUses;
134155

135156
/// PendingLoads - Remember where unknown loads are after the most recent
136157
/// unknown store, as we iterate. As with Defs and Uses, this is here
@@ -200,7 +221,8 @@ namespace llvm {
200221
/// input.
201222
void buildSchedGraph(AliasAnalysis *AA,
202223
RegPressureTracker *RPTracker = nullptr,
203-
PressureDiffs *PDiffs = nullptr);
224+
PressureDiffs *PDiffs = nullptr,
225+
bool TrackLaneMasks = false);
204226

205227
/// addSchedBarrierDeps - Add dependencies from instructions in the current
206228
/// list of instructions being scheduled to scheduling barrier. We want to
@@ -247,6 +269,12 @@ namespace llvm {
247269
/// Other adjustments may be made to the instruction if necessary. Return
248270
/// true if the operand has been deleted, false if not.
249271
bool toggleKillFlag(MachineInstr *MI, MachineOperand &MO);
272+
273+
/// Returns a mask for which lanes get read/written by the given (register)
274+
/// machine operand.
275+
LaneBitmask getLaneMaskForMO(const MachineOperand &MO) const;
276+
277+
void collectVRegUses(SUnit *SU);
250278
};
251279

252280
/// newSUnit - Creates a new SUnit and return a ptr to it.

0 commit comments

Comments
 (0)