From ababa964752d5bfa6eb608c97f19d4e68df1d243 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Tue, 20 Feb 2024 16:00:55 +0000 Subject: [RemoveDIs][NFC] Introduce DbgRecord base class [1/3] (#78252) Patch 1 of 3 to add llvm.dbg.label support to the RemoveDIs project. The patch stack adds a new base class -> 1. Add DbgRecord base class for DPValue and the not-yet-added DPLabel class. 2. Add the DPLabel class. 3. Enable dbg.label conversion and add support to passes. Patches 1 and 2 are NFC. In the near future we also will rename DPValue to DbgVariableRecord and DPLabel to DbgLabelRecord, at which point we'll overhaul the function names too. The name DPLabel keeps things consistent for now. --- llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp | 28 ++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp') diff --git a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp index f8ce8f9..7b66a85 100644 --- a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp +++ b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp @@ -82,7 +82,7 @@ template <> struct llvm::DenseMapInfo { } }; -using VarLocInsertPt = PointerUnion; +using VarLocInsertPt = PointerUnion; namespace std { template <> struct hash { @@ -218,14 +218,14 @@ void FunctionVarLocs::init(FunctionVarLocsBuilder &Builder) { // block includes VarLocs for any DPValues attached to that instruction. for (auto &P : Builder.VarLocsBeforeInst) { // Process VarLocs attached to a DPValue alongside their marker Instruction. - if (isa(P.first)) + if (isa(P.first)) continue; const Instruction *I = cast(P.first); unsigned BlockStart = VarLocRecords.size(); // Any VarLocInfos attached to a DPValue should now be remapped to their // marker Instruction, in order of DPValue appearance and prior to any // VarLocInfos attached directly to that instruction. - for (const DPValue &DPV : I->getDbgValueRange()) { + for (const DPValue &DPV : DPValue::filter(I->getDbgValueRange())) { // Even though DPV defines a variable location, VarLocsBeforeInst can // still be empty if that VarLoc was redundant. if (!Builder.VarLocsBeforeInst.count(&DPV)) @@ -829,7 +829,11 @@ class MemLocFragmentFill { void process(BasicBlock &BB, VarFragMap &LiveSet) { BBInsertBeforeMap[&BB].clear(); for (auto &I : BB) { - for (auto &DPV : I.getDbgValueRange()) { + for (DbgRecord &DR : I.getDbgValueRange()) { + // FIXME: DPValue::filter usage needs attention in this file; we need + // to make sure dbg.labels are handled correctly in RemoveDIs mode. + // Cast below to ensure this gets fixed when DPLabels are introduced. + DPValue &DPV = cast(DR); if (const auto *Locs = FnVarLocs->getWedge(&DPV)) { for (const VarLocInfo &Loc : *Locs) { addDef(Loc, &DPV, *I.getParent(), LiveSet); @@ -1492,7 +1496,7 @@ const char *locStr(AssignmentTrackingLowering::LocKind Loc) { } #endif -VarLocInsertPt getNextNode(const DPValue *DPV) { +VarLocInsertPt getNextNode(const DbgRecord *DPV) { auto NextIt = ++(DPV->getIterator()); if (NextIt == DPV->getMarker()->getDbgValueRange().end()) return DPV->getMarker()->MarkedInstr; @@ -1507,7 +1511,7 @@ VarLocInsertPt getNextNode(const Instruction *Inst) { VarLocInsertPt getNextNode(VarLocInsertPt InsertPt) { if (isa(InsertPt)) return getNextNode(cast(InsertPt)); - return getNextNode(cast(InsertPt)); + return getNextNode(cast(InsertPt)); } DbgAssignIntrinsic *CastToDbgAssign(DbgVariableIntrinsic *DVI) { @@ -1915,7 +1919,7 @@ void AssignmentTrackingLowering::process(BasicBlock &BB, BlockInfo *LiveSet) { // attached DPValues, or a non-debug instruction with attached unprocessed // DPValues. if (II != EI && II->hasDbgValues()) { - for (DPValue &DPV : II->getDbgValueRange()) { + for (DPValue &DPV : DPValue::filter(II->getDbgValueRange())) { resetInsertionPoint(DPV); processDPValue(DPV, LiveSet); assert(LiveSet->isValid()); @@ -2172,7 +2176,7 @@ static AssignmentTrackingLowering::OverlapMap buildOverlapMapAndRecordDeclares( }; for (auto &BB : Fn) { for (auto &I : BB) { - for (auto &DPV : I.getDbgValueRange()) + for (DPValue &DPV : DPValue::filter(I.getDbgValueRange())) ProcessDbgRecord(&DPV, DPDeclares); if (auto *DII = dyn_cast(&I)) { ProcessDbgRecord(DII, InstDeclares); @@ -2462,7 +2466,7 @@ bool AssignmentTrackingLowering::emitPromotedVarLocs( for (auto &BB : Fn) { for (auto &I : BB) { // Skip instructions other than dbg.values and dbg.assigns. - for (DPValue &DPV : I.getDbgValueRange()) + for (DPValue &DPV : DPValue::filter(I.getDbgValueRange())) if (DPV.isDbgValue() || DPV.isDbgAssign()) TranslateDbgRecord(&DPV); auto *DVI = dyn_cast(&I); @@ -2564,7 +2568,7 @@ removeRedundantDbgLocsUsingBackwardScan(const BasicBlock *BB, } }; HandleLocsForWedge(&I); - for (DPValue &DPV : reverse(I.getDbgValueRange())) + for (DPValue &DPV : reverse(DPValue::filter(I.getDbgValueRange()))) HandleLocsForWedge(&DPV); } @@ -2629,7 +2633,7 @@ removeRedundantDbgLocsUsingForwardScan(const BasicBlock *BB, } }; - for (DPValue &DPV : I.getDbgValueRange()) + for (DPValue &DPV : DPValue::filter(I.getDbgValueRange())) HandleLocsForWedge(&DPV); HandleLocsForWedge(&I); } @@ -2715,7 +2719,7 @@ removeUndefDbgLocsFromEntryBlock(const BasicBlock *BB, Changed = true; } }; - for (DPValue &DPV : I.getDbgValueRange()) + for (DPValue &DPV : DPValue::filter(I.getDbgValueRange())) HandleLocsForWedge(&DPV); HandleLocsForWedge(&I); } -- cgit v1.1