@@ -60,6 +60,7 @@ bool LiveRegMatrixWrapperLegacy::runOnMachineFunction(MachineFunction &MF) {
6060void LiveRegMatrix::init (MachineFunction &MF, LiveIntervals &pLIS,
6161 VirtRegMap &pVRM) {
6262 TRI = MF.getSubtarget ().getRegisterInfo ();
63+ MRI = &MF.getRegInfo ();
6364 LIS = &pLIS;
6465 VRM = &pVRM;
6566
@@ -83,6 +84,14 @@ void LiveRegMatrix::releaseMemory() {
8384 }
8485}
8586
87+ static LiveRange copyLiveRange (const LiveRange &LR) {
88+ LiveRange NewLR;
89+ for (auto Seg : LR.segments )
90+ NewLR.addSegment (Seg);
91+ NewLR.valnos .append (LR.vni_begin (), LR.vni_end ());
92+ return NewLR;
93+ }
94+
8695template <typename Callable>
8796static bool foreachUnit (const TargetRegisterInfo *TRI,
8897 const LiveInterval &VRegInterval, MCRegister PhysReg,
@@ -117,7 +126,12 @@ void LiveRegMatrix::assign(const LiveInterval &VirtReg, MCRegister PhysReg) {
117126 foreachUnit (
118127 TRI, VirtReg, PhysReg, [&](unsigned Unit, const LiveRange &Range) {
119128 LLVM_DEBUG (dbgs () << ' ' << printRegUnit (Unit, TRI) << ' ' << Range);
120- Matrix[Unit].unify (VirtReg, Range);
129+ LiveRange NewLR;
130+ if (TRI->enableTargetInterference () &&
131+ TRI->needUpdateECSlot (Range, NewLR = copyLiveRange (Range), *LIS))
132+ Matrix[Unit].unify (VirtReg, NewLR);
133+ else
134+ Matrix[Unit].unify (VirtReg, Range);
121135 return false ;
122136 });
123137
@@ -134,7 +148,13 @@ void LiveRegMatrix::unassign(const LiveInterval &VirtReg) {
134148 foreachUnit (TRI, VirtReg, PhysReg,
135149 [&](unsigned Unit, const LiveRange &Range) {
136150 LLVM_DEBUG (dbgs () << ' ' << printRegUnit (Unit, TRI));
137- Matrix[Unit].extract (VirtReg, Range);
151+ LiveRange NewLR;
152+ if (TRI->enableTargetInterference () &&
153+ TRI->needUpdateECSlot (Range, NewLR = copyLiveRange (Range),
154+ *LIS))
155+ Matrix[Unit].extract (VirtReg, NewLR);
156+ else
157+ Matrix[Unit].extract (VirtReg, Range);
138158 return false ;
139159 });
140160
@@ -150,6 +170,31 @@ bool LiveRegMatrix::isPhysRegUsed(MCRegister PhysReg) const {
150170 return false ;
151171}
152172
173+ SmallVector<const LiveInterval *, 8 >
174+ LiveRegMatrix::getTargetInterferenceLiveI (const LiveInterval &VirtReg,
175+ MCRegister PhysReg) const {
176+ SmallVector<const LiveInterval *, 8 > LiveIs;
177+ if (!TRI->enableTargetInterference ())
178+ return LiveIs;
179+
180+ BitVector IntfReg = TRI->getTargetInterferenceReg (VirtReg, PhysReg, MRI, VRM);
181+
182+ for (auto Reg : IntfReg.set_bits ()) {
183+ for (MCRegUnitIterator Units (Reg, TRI); Units.isValid (); ++Units) {
184+ LiveIntervalUnion LiveUnion = Matrix[*Units];
185+ LiveIntervalUnion::ConstSegmentIter LiveUnionI = LiveUnion.begin ();
186+ while (LiveUnionI != LiveUnion.end ()) {
187+ const LiveRange *LiveR = *LiveUnionI;
188+ LiveRange NewLiveR = copyLiveRange (*LiveR);
189+ if (TRI->needUpdateECSlot (LiveR, NewLiveR, *LIS))
190+ LiveIs.push_back (*LiveUnionI);
191+ ++LiveUnionI;
192+ }
193+ }
194+ }
195+ return LiveIs;
196+ }
197+
153198bool LiveRegMatrix::checkRegMaskInterference (const LiveInterval &VirtReg,
154199 MCRegister PhysReg) {
155200 // Check if the cached information is valid.
@@ -178,7 +223,12 @@ bool LiveRegMatrix::checkRegUnitInterference(const LiveInterval &VirtReg,
178223 bool Result = foreachUnit (TRI, VirtReg, PhysReg, [&](unsigned Unit,
179224 const LiveRange &Range) {
180225 const LiveRange &UnitRange = LIS->getRegUnit (Unit);
181- return Range.overlaps (UnitRange, CP, *LIS->getSlotIndexes ());
226+ LiveRange NewLR;
227+ if (TRI->enableTargetInterference () &&
228+ TRI->needUpdateECSlot (Range, NewLR = copyLiveRange (Range), *LIS))
229+ return NewLR.overlaps (UnitRange, CP, *LIS->getSlotIndexes ());
230+ else
231+ return Range.overlaps (UnitRange, CP, *LIS->getSlotIndexes ());
182232 });
183233 return Result;
184234}
@@ -204,9 +254,24 @@ LiveRegMatrix::checkInterference(const LiveInterval &VirtReg,
204254 if (checkRegUnitInterference (VirtReg, PhysReg))
205255 return IK_RegUnit;
206256
257+ if (TRI->enableTargetInterference () &&
258+ TRI->getTargetInterferenceReg (VirtReg, PhysReg, MRI, VRM).any ())
259+ return IK_VirtReg;
260+
207261 // Check the matrix for virtual register interference.
208262 bool Interference = foreachUnit (TRI, VirtReg, PhysReg,
209263 [&](MCRegUnit Unit, const LiveRange &LR) {
264+ LiveRange NewLR;
265+ if (TRI->enableTargetInterference () &&
266+ TRI->needUpdateECSlot (
267+ LR, NewLR = copyLiveRange (LR), *LIS)) {
268+ // Update LiveRange could make cache
269+ // information stable. Refresh cache to
270+ // handle it.
271+ invalidateVirtRegs ();
272+ return query (NewLR, Unit)
273+ .checkInterference ();
274+ }
210275 return query (LR, Unit).checkInterference ();
211276 });
212277 if (Interference)
0 commit comments