@@ -206,6 +206,7 @@ class RegAllocFastImpl {
206
206
bool Error = false ; // /< Could not allocate.
207
207
208
208
explicit LiveReg (Register VirtReg) : VirtReg(VirtReg) {}
209
+ explicit LiveReg () {}
209
210
210
211
unsigned getSparseSetIndex () const { return VirtReg.virtRegIndex (); }
211
212
};
@@ -216,7 +217,7 @@ class RegAllocFastImpl {
216
217
LiveRegMap LiveVirtRegs;
217
218
218
219
// / Stores assigned virtual registers present in the bundle MI.
219
- DenseMap<Register, MCPhysReg > BundleVirtRegsMap;
220
+ DenseMap<Register, LiveReg > BundleVirtRegsMap;
220
221
221
222
DenseMap<unsigned , SmallVector<MachineOperand *, 2 >> LiveDbgValueMap;
222
223
// / List of DBG_VALUE that we encountered without the vreg being assigned
@@ -374,7 +375,8 @@ class RegAllocFastImpl {
374
375
SmallSet<Register, 2 > &PrologLiveIns) const ;
375
376
376
377
void reloadAtBegin (MachineBasicBlock &MBB);
377
- bool setPhysReg (MachineInstr &MI, MachineOperand &MO, MCPhysReg PhysReg);
378
+ bool setPhysReg (MachineInstr &MI, MachineOperand &MO,
379
+ const LiveReg &Assignment);
378
380
379
381
Register traceCopies (Register VirtReg) const ;
380
382
Register traceCopyChain (Register Reg) const ;
@@ -1005,7 +1007,7 @@ void RegAllocFastImpl::allocVirtRegUndef(MachineOperand &MO) {
1005
1007
MO.setSubReg (0 );
1006
1008
}
1007
1009
MO.setReg (PhysReg);
1008
- MO.setIsRenamable (true );
1010
+ MO.setIsRenamable (!LRI-> Error );
1009
1011
}
1010
1012
1011
1013
// / Variation of defineVirtReg() with special handling for livethrough regs
@@ -1109,10 +1111,10 @@ bool RegAllocFastImpl::defineVirtReg(MachineInstr &MI, unsigned OpNum,
1109
1111
LRI->Reloaded = false ;
1110
1112
}
1111
1113
if (MI.getOpcode () == TargetOpcode::BUNDLE) {
1112
- BundleVirtRegsMap[VirtReg] = PhysReg ;
1114
+ BundleVirtRegsMap[VirtReg] = *LRI ;
1113
1115
}
1114
1116
markRegUsedInInstr (PhysReg);
1115
- return setPhysReg (MI, MO, PhysReg );
1117
+ return setPhysReg (MI, MO, *LRI );
1116
1118
}
1117
1119
1118
1120
// / Allocates a register for a VirtReg use.
@@ -1158,10 +1160,10 @@ bool RegAllocFastImpl::useVirtReg(MachineInstr &MI, MachineOperand &MO,
1158
1160
LRI->LastUse = &MI;
1159
1161
1160
1162
if (MI.getOpcode () == TargetOpcode::BUNDLE) {
1161
- BundleVirtRegsMap[VirtReg] = LRI-> PhysReg ;
1163
+ BundleVirtRegsMap[VirtReg] = * LRI;
1162
1164
}
1163
1165
markRegUsedInInstr (LRI->PhysReg );
1164
- return setPhysReg (MI, MO, LRI-> PhysReg );
1166
+ return setPhysReg (MI, MO, * LRI);
1165
1167
}
1166
1168
1167
1169
// / Query a physical register to use as a filler in contexts where the
@@ -1215,16 +1217,27 @@ MCPhysReg RegAllocFastImpl::getErrorAssignment(const LiveReg &LR,
1215
1217
// / Changes operand OpNum in MI the refer the PhysReg, considering subregs.
1216
1218
// / \return true if MI's MachineOperands were re-arranged/invalidated.
1217
1219
bool RegAllocFastImpl::setPhysReg (MachineInstr &MI, MachineOperand &MO,
1218
- MCPhysReg PhysReg) {
1220
+ const LiveReg &Assignment) {
1221
+ MCPhysReg PhysReg = Assignment.PhysReg ;
1222
+ assert (PhysReg && " assignments should always be to a valid physreg" );
1223
+
1224
+ if (LLVM_UNLIKELY (Assignment.Error )) {
1225
+ // Make sure we don't set renamable in error scenarios, as we may have
1226
+ // assigned to a reserved register.
1227
+ if (MO.isUse ())
1228
+ MO.setIsUndef (true );
1229
+ }
1230
+
1219
1231
if (!MO.getSubReg ()) {
1220
1232
MO.setReg (PhysReg);
1221
- MO.setIsRenamable (true );
1233
+ MO.setIsRenamable (!Assignment. Error );
1222
1234
return false ;
1223
1235
}
1224
1236
1225
1237
// Handle subregister index.
1226
- MO.setReg (PhysReg ? TRI->getSubReg (PhysReg, MO.getSubReg ()) : MCRegister ());
1227
- MO.setIsRenamable (true );
1238
+ MO.setReg (TRI->getSubReg (PhysReg, MO.getSubReg ()));
1239
+ MO.setIsRenamable (!Assignment.Error );
1240
+
1228
1241
// Note: We leave the subreg number around a little longer in case of defs.
1229
1242
// This is so that the register freeing logic in allocateInstruction can still
1230
1243
// recognize this as subregister defs. The code there will clear the number.
@@ -1706,7 +1719,7 @@ void RegAllocFastImpl::handleDebugValue(MachineInstr &MI) {
1706
1719
if (LRI != LiveVirtRegs.end () && LRI->PhysReg ) {
1707
1720
// Update every use of Reg within MI.
1708
1721
for (auto &RegMO : DbgOps)
1709
- setPhysReg (MI, *RegMO, LRI-> PhysReg );
1722
+ setPhysReg (MI, *RegMO, * LRI);
1710
1723
} else {
1711
1724
DanglingDbgValues[Reg].push_back (&MI);
1712
1725
}
@@ -1729,8 +1742,7 @@ void RegAllocFastImpl::handleBundle(MachineInstr &MI) {
1729
1742
if (!Reg.isVirtual () || !shouldAllocateRegister (Reg))
1730
1743
continue ;
1731
1744
1732
- DenseMap<Register, MCPhysReg>::iterator DI;
1733
- DI = BundleVirtRegsMap.find (Reg);
1745
+ DenseMap<Register, LiveReg>::iterator DI = BundleVirtRegsMap.find (Reg);
1734
1746
assert (DI != BundleVirtRegsMap.end () && " Unassigned virtual register" );
1735
1747
1736
1748
setPhysReg (MI, MO, DI->second );
0 commit comments