Skip to content

Commit 97a01f1

Browse files
committed
[LiveDebugValues][NVPTX] handle vregs in VarLocBasedImpl, enable pass for NVPTX
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 39ac121 commit 97a01f1

File tree

4 files changed

+1191
-1178
lines changed

4 files changed

+1191
-1178
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: 15 additions & 4 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,15 @@ void VarLocBasedLDV::getUsedRegs(const VarLocSet &CollectFrom,
12401245
LocIndex::rawIndexForReg(LocIndex::kFirstRegLocation);
12411246
uint64_t FirstInvalidIndex =
12421247
LocIndex::rawIndexForReg(LocIndex::kFirstInvalidRegLocation);
1248+
uint64_t FirstVirtualRegIndex =
1249+
LocIndex::rawIndexForReg(LocIndex::kFirstVirtualRegLocation);
12431250
for (auto It = CollectFrom.find(FirstRegIndex),
1244-
End = CollectFrom.find(FirstInvalidIndex);
1245-
It != End;) {
1251+
PhysEnd = CollectFrom.find(FirstInvalidIndex);
1252+
It != CollectFrom.end();) {
1253+
if (It == PhysEnd) {
1254+
It = CollectFrom.find(FirstVirtualRegIndex);
1255+
continue;
1256+
}
12461257
// We found a VarLoc ID for a VarLoc that lives in a register. Figure out
12471258
// which register and add it to UsedRegs.
12481259
uint32_t FoundReg = LocIndex::fromRawInteger(*It).Location;

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)