Skip to content

Commit 1818404

Browse files
authored
[LiveDebugValues][NVPTX]VarLocBasedImpl handle vregs, enable for NVPTX (llvm#111456)
This patch handles virtual registers in the VarLocBasedImpl of the LiveDebugVariables pass, allowing it to be used on architectures that depend on virtual registers in debugging, like NVPTX. It enables the pass for NVPTX.
1 parent ff6faca commit 1818404

File tree

4 files changed

+1196
-1179
lines changed

4 files changed

+1196
-1179
lines changed

llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) {
102102
}
103103

104104
bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
105-
// Except for Wasm, all targets should be only using physical register at this
106-
// point. Wasm only use virtual registers throught its pipeline, but its
107-
// virtual registers don't participate in this LiveDebugValues analysis; only
108-
// its target indices do.
109-
assert(MF.getTarget().getTargetTriple().isWasm() ||
110-
MF.getProperties().hasProperty(
111-
MachineFunctionProperties::Property::NoVRegs));
112-
113105
bool InstrRefBased = MF.useDebugInstrRef();
114106
// Allow the user to force selection of InstrRef LDV.
115107
InstrRefBased |= ForceInstrRefLDV;

llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ struct LocIndex {
239239
/// becomes a problem.
240240
static constexpr u32_location_t kWasmLocation = kFirstInvalidRegLocation + 2;
241241

242+
/// The first location that is reserved for VarLocs with locations of kind
243+
/// VirtualRegisterKind.
244+
static constexpr u32_location_t kFirstVirtualRegLocation = 1 << 31;
245+
242246
LocIndex(u32_location_t Location, u32_index_t Index)
243247
: Location(Location), Index(Index) {}
244248

@@ -810,9 +814,10 @@ class VarLocBasedLDV : public LDVImpl {
810814
VL.getDescribingRegs(Locations);
811815
assert(all_of(Locations,
812816
[](auto RegNo) {
813-
return RegNo < LocIndex::kFirstInvalidRegLocation;
817+
return (RegNo < LocIndex::kFirstInvalidRegLocation) ||
818+
(LocIndex::kFirstVirtualRegLocation <= RegNo);
814819
}) &&
815-
"Physreg out of range?");
820+
"Physical or virtual register out of range?");
816821
if (VL.containsSpillLocs())
817822
Locations.push_back(LocIndex::kSpillLocation);
818823
if (VL.containsWasmLocs())
@@ -1240,9 +1245,9 @@ void VarLocBasedLDV::getUsedRegs(const VarLocSet &CollectFrom,
12401245
LocIndex::rawIndexForReg(LocIndex::kFirstRegLocation);
12411246
uint64_t FirstInvalidIndex =
12421247
LocIndex::rawIndexForReg(LocIndex::kFirstInvalidRegLocation);
1243-
for (auto It = CollectFrom.find(FirstRegIndex),
1244-
End = CollectFrom.find(FirstInvalidIndex);
1245-
It != End;) {
1248+
uint64_t FirstVirtualRegIndex =
1249+
LocIndex::rawIndexForReg(LocIndex::kFirstVirtualRegLocation);
1250+
auto doGetUsedRegs = [&](VarLocSet::const_iterator &It) {
12461251
// We found a VarLoc ID for a VarLoc that lives in a register. Figure out
12471252
// which register and add it to UsedRegs.
12481253
uint32_t FoundReg = LocIndex::fromRawInteger(*It).Location;
@@ -1255,6 +1260,16 @@ void VarLocBasedLDV::getUsedRegs(const VarLocSet &CollectFrom,
12551260
// guaranteed to move on to the next register (or to end()).
12561261
uint64_t NextRegIndex = LocIndex::rawIndexForReg(FoundReg + 1);
12571262
It.advanceToLowerBound(NextRegIndex);
1263+
};
1264+
for (auto It = CollectFrom.find(FirstRegIndex),
1265+
End = CollectFrom.find(FirstInvalidIndex);
1266+
It != End;) {
1267+
doGetUsedRegs(It);
1268+
}
1269+
for (auto It = CollectFrom.find(FirstVirtualRegIndex),
1270+
End = CollectFrom.end();
1271+
It != End;) {
1272+
doGetUsedRegs(It);
12581273
}
12591274
}
12601275

llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ void NVPTXPassConfig::addIRPasses() {
309309
disablePass(&MachineCopyPropagationID);
310310
disablePass(&TailDuplicateID);
311311
disablePass(&StackMapLivenessID);
312-
disablePass(&LiveDebugValuesID);
313312
disablePass(&PostRAMachineSinkingID);
314313
disablePass(&PostRASchedulerID);
315314
disablePass(&FuncletLayoutID);

0 commit comments

Comments
 (0)