[Mlir-commits] [llvm] [mlir] [IR] Make Instruction::DebugMarker private behind getDbgMarker(). NFC (PR #224190)
Fangrui Song
llvmlistbot at llvm.org
Wed Sep 16 21:01:17 PDT 2026
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/224190
Make it private and add getDbgMarker(); only BasicBlock and DbgMarker,
which maintain the marker links, write it. This enables experiments to
change the data representation.
Aided by Opus 5
>From 89941d007c75f07bd7d43f2eade4d5f5044c4fe8 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Wed, 16 Sep 2026 10:33:24 -0700
Subject: [PATCH] [IR] Make Instruction::DebugMarker private behind
getDbgMarker(). NFC
Make it private and add getDbgMarker(); only BasicBlock and DbgMarker,
which maintain the marker links, write it. This enables experiments to
change the data representation.
Aided by Opus 5
---
llvm/include/llvm/IR/Instruction.h | 8 +-
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 +-
llvm/lib/IR/BasicBlock.cpp | 35 +++++----
llvm/lib/IR/Core.cpp | 16 ++--
llvm/lib/IR/Verifier.cpp | 6 +-
llvm/unittests/IR/BasicBlockDbgInfoTest.cpp | 74 +++++++++---------
llvm/unittests/IR/DebugInfoTest.cpp | 75 ++++++++++---------
llvm/unittests/Transforms/Utils/LocalTest.cpp | 2 +-
mlir/lib/Target/LLVMIR/ModuleImport.cpp | 5 +-
9 files changed, 113 insertions(+), 110 deletions(-)
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index 0c5fc3e532283..8a37f25238de7 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -37,7 +37,6 @@ class FastMathFlags;
class MDNode;
class Module;
struct AAMDNodes;
-class DbgMarker;
class DbgRecord;
template <> struct ilist_alloc_traits<Instruction> {
@@ -112,12 +111,14 @@ class Instruction : public User,
/// O(1) local dominance checks between instructions.
mutable unsigned Order = 0;
-public:
/// Optional marker recording the position for debugging information that
/// takes effect immediately before this instruction. Null unless there is
/// debugging information present.
DbgMarker *DebugMarker = nullptr;
+public:
+ DbgMarker *getDbgMarker() const { return DebugMarker; }
+
/// Clone any debug-info attached to \p From onto this instruction. Used to
/// copy debugging information from one block to another, when copying entire
/// blocks. \see DebugProgramInstruction.h , because the ordering of
@@ -1101,7 +1102,8 @@ class Instruction : public User,
private:
friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<true>,
ilist_parent<BasicBlock>>;
- friend class BasicBlock; // For renumbering.
+ friend class BasicBlock; // For renumbering and DebugMarker.
+ friend class DbgMarker; // For DebugMarker.
// Shadow Value::setValueSubclassData with a private forwarding method so that
// subclasses cannot accidentally use it.
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index e33b6e0050318..c99a1edd31fb4 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -3936,7 +3936,7 @@ void ModuleBitcodeWriter::writeFunction(
// Write out non-instruction debug information attached to this
// instruction. Write it after the instruction so that it's easy to
// re-attach to the instruction reading the records in.
- for (DbgRecord &DR : I.DebugMarker->getDbgRecordRange()) {
+ for (DbgRecord &DR : I.getDbgMarker()->getDbgRecordRange()) {
if (DbgLabelRecord *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
Vals.push_back(VE.getMetadataID(&*DLR->getDebugLoc()));
Vals.push_back(VE.getMetadataID(DLR->getLabel()));
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index ada2dcfa0c4c3..d4141adf65a84 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -31,8 +31,8 @@ using namespace llvm;
STATISTIC(NumInstrRenumberings, "Number of renumberings across all blocks");
DbgMarker *BasicBlock::createMarker(Instruction *I) {
- if (I->DebugMarker)
- return I->DebugMarker;
+ if (DbgMarker *Marker = I->getDbgMarker())
+ return Marker;
DbgMarker *Marker = new DbgMarker();
Marker->MarkedInstr = I;
I->DebugMarker = Marker;
@@ -77,7 +77,7 @@ void BasicBlock::convertToNewDbgValues() {
// Create a marker to store DbgRecords in.
createMarker(&I);
- DbgMarker *Marker = I.DebugMarker;
+ DbgMarker *Marker = I.getDbgMarker();
for (DbgRecord *DVR : DbgVarRecs)
Marker->insertDbgRecord(DVR, false);
@@ -94,15 +94,15 @@ bool BasicBlock::convertFromNewDbgValues() {
// Convert any attached DbgRecords to debug intrinsics and insert ahead of
// the instruction.
for (auto &Inst : *this) {
- if (!Inst.DebugMarker)
+ DbgMarker *Marker = Inst.getDbgMarker();
+ if (!Marker)
continue;
- DbgMarker &Marker = *Inst.DebugMarker;
- for (DbgRecord &DR : Marker.getDbgRecordRange())
+ for (DbgRecord &DR : Marker->getDbgRecordRange())
InstList.insert(Inst.getIterator(),
DR.createDebugIntrinsic(getModule(), nullptr));
- Marker.eraseFromParent();
+ Marker->eraseFromParent();
Modified = true;
}
@@ -116,11 +116,12 @@ bool BasicBlock::convertFromNewDbgValues() {
#ifndef NDEBUG
void BasicBlock::dumpDbgValues() const {
for (auto &Inst : *this) {
- if (!Inst.DebugMarker)
+ DbgMarker *Marker = Inst.getDbgMarker();
+ if (!Marker)
continue;
- dbgs() << "@ " << Inst.DebugMarker << " ";
- Inst.DebugMarker->dump();
+ dbgs() << "@ " << Marker << " ";
+ Marker->dump();
};
}
#endif
@@ -188,11 +189,9 @@ BasicBlock::~BasicBlock() {
assert(getParent() == nullptr && "BasicBlock still linked into the program!");
dropAllReferences();
- for (auto &Inst : *this) {
- if (!Inst.DebugMarker)
- continue;
- Inst.DebugMarker->eraseFromParent();
- }
+ for (auto &Inst : *this)
+ if (DbgMarker *Marker = Inst.getDbgMarker())
+ Marker->eraseFromParent();
InstList.clear();
}
@@ -667,7 +666,7 @@ void BasicBlock::flushTerminatorDbgRecords() {
// Transfer DbgRecords from the trailing position onto the terminator.
createMarker(Term);
- Term->DebugMarker->absorbDebugValues(*TrailingDbgRecords, false);
+ Term->getDbgMarker()->absorbDebugValues(*TrailingDbgRecords, false);
TrailingDbgRecords->eraseFromParent();
deleteTrailingDbgRecords();
}
@@ -720,7 +719,7 @@ void BasicBlock::spliceDebugInfoEmptyBlock(BasicBlock::iterator Dest,
if (!First->hasDbgRecords())
return;
- createMarker(Dest)->absorbDebugValues(*First->DebugMarker, InsertAtHead);
+ createMarker(Dest)->absorbDebugValues(*First->getDbgMarker(), InsertAtHead);
}
void BasicBlock::spliceDebugInfo(BasicBlock::iterator Dest, BasicBlock *Src,
@@ -998,7 +997,7 @@ DbgMarker *BasicBlock::getMarker(InstListType::iterator It) {
DbgMarker *DM = getTrailingDbgRecords();
return DM;
}
- return It->DebugMarker;
+ return It->getDbgMarker();
}
void BasicBlock::reinsertInstInDbgRecords(
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 59d27f4b15510..e6064fa466a16 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -3094,20 +3094,20 @@ LLVMValueRef LLVMIsATerminatorInst(LLVMValueRef Inst) {
LLVMDbgRecordRef LLVMGetFirstDbgRecord(LLVMValueRef Inst) {
Instruction *Instr = unwrap<Instruction>(Inst);
- if (!Instr->DebugMarker)
+ if (!Instr->getDbgMarker())
return nullptr;
- auto I = Instr->DebugMarker->StoredDbgRecords.begin();
- if (I == Instr->DebugMarker->StoredDbgRecords.end())
+ auto I = Instr->getDbgMarker()->StoredDbgRecords.begin();
+ if (I == Instr->getDbgMarker()->StoredDbgRecords.end())
return nullptr;
return wrap(&*I);
}
LLVMDbgRecordRef LLVMGetLastDbgRecord(LLVMValueRef Inst) {
Instruction *Instr = unwrap<Instruction>(Inst);
- if (!Instr->DebugMarker)
+ if (!Instr->getDbgMarker())
return nullptr;
- auto I = Instr->DebugMarker->StoredDbgRecords.rbegin();
- if (I == Instr->DebugMarker->StoredDbgRecords.rend())
+ auto I = Instr->getDbgMarker()->StoredDbgRecords.rbegin();
+ if (I == Instr->getDbgMarker()->StoredDbgRecords.rend())
return nullptr;
return wrap(&*I);
}
@@ -3115,7 +3115,7 @@ LLVMDbgRecordRef LLVMGetLastDbgRecord(LLVMValueRef Inst) {
LLVMDbgRecordRef LLVMGetNextDbgRecord(LLVMDbgRecordRef Rec) {
DbgRecord *Record = unwrap<DbgRecord>(Rec);
simple_ilist<DbgRecord>::iterator I(Record);
- if (++I == Record->getInstruction()->DebugMarker->StoredDbgRecords.end())
+ if (++I == Record->getInstruction()->getDbgMarker()->StoredDbgRecords.end())
return nullptr;
return wrap(&*I);
}
@@ -3123,7 +3123,7 @@ LLVMDbgRecordRef LLVMGetNextDbgRecord(LLVMDbgRecordRef Rec) {
LLVMDbgRecordRef LLVMGetPreviousDbgRecord(LLVMDbgRecordRef Rec) {
DbgRecord *Record = unwrap<DbgRecord>(Rec);
simple_ilist<DbgRecord>::iterator I(Record);
- if (I == Record->getInstruction()->DebugMarker->StoredDbgRecords.begin())
+ if (I == Record->getInstruction()->getDbgMarker()->StoredDbgRecords.begin())
return nullptr;
return wrap(&*--I);
}
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 8fc72bdf2f4f4..3343aed4d92d4 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -530,14 +530,14 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
} while (false)
void Verifier::visitDbgRecords(Instruction &I) {
- if (!I.DebugMarker)
+ if (!I.getDbgMarker())
return;
- CheckDI(I.DebugMarker->MarkedInstr == &I,
+ CheckDI(I.getDbgMarker()->MarkedInstr == &I,
"Instruction has invalid DebugMarker", &I);
CheckDI(!isa<PHINode>(&I) || !I.hasDbgRecords(),
"PHI Node must not have any attached DbgRecords", &I);
for (DbgRecord &DR : I.getDbgRecordRange()) {
- CheckDI(DR.getMarker() == I.DebugMarker,
+ CheckDI(DR.getMarker() == I.getDbgMarker(),
"DbgRecord had invalid DebugMarker", &I, &DR);
if (auto *Loc =
dyn_cast_or_null<DILocation>(DR.getDebugLoc().getAsMDNode()))
diff --git a/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp b/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
index 7780bbaf66f4f..8125f54909447 100644
--- a/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
+++ b/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
@@ -244,8 +244,8 @@ TEST(BasicBlockDbgInfoTest, MarkerOperations) {
// Fetch out our two markers,
Instruction *Instr1 = &*BB.begin();
Instruction *Instr2 = Instr1->getNextNode();
- DbgMarker *Marker1 = Instr1->DebugMarker;
- DbgMarker *Marker2 = Instr2->DebugMarker;
+ DbgMarker *Marker1 = Instr1->getDbgMarker();
+ DbgMarker *Marker2 = Instr2->getDbgMarker();
// There's no TrailingDbgRecords marker allocated yet.
DbgMarker *EndMarker = nullptr;
@@ -315,7 +315,7 @@ TEST(BasicBlockDbgInfoTest, MarkerOperations) {
// Inserting at end(): should dislodge the DbgVariableRecords, if they were
// dbg.values then they would sit "above" the new instruction.
Instr1->insertBefore(BB, BB.end());
- EXPECT_EQ(Instr1->DebugMarker->StoredDbgRecords.size(), 2u);
+ EXPECT_EQ(Instr1->getDbgMarker()->StoredDbgRecords.size(), 2u);
// We should de-allocate the trailing marker when something is inserted
// at end().
EXPECT_EQ(BB.getTrailingDbgRecords(), nullptr);
@@ -330,7 +330,7 @@ TEST(BasicBlockDbgInfoTest, MarkerOperations) {
// this be the final instr in the block, and DbgVariableRecords aren't allowed
// to live off the end forever.
Instr2->insertBefore(BB, BB.begin());
- EXPECT_EQ(Instr2->DebugMarker->StoredDbgRecords.size(), 2u);
+ EXPECT_EQ(Instr2->getDbgMarker()->StoredDbgRecords.size(), 2u);
EXPECT_EQ(BB.getTrailingDbgRecords(), nullptr);
// Teardown,
@@ -387,27 +387,27 @@ TEST(BasicBlockDbgInfoTest, HeadBitOperations) {
Instruction *CInst = BInst->getNextNode();
Instruction *DInst = CInst->getNextNode();
// CInst should have debug-info.
- ASSERT_TRUE(CInst->DebugMarker);
- EXPECT_FALSE(CInst->DebugMarker->StoredDbgRecords.empty());
+ ASSERT_TRUE(CInst->getDbgMarker());
+ EXPECT_FALSE(CInst->getDbgMarker()->StoredDbgRecords.empty());
// If we move "c" to the start of the block, just normally, then the
// DbgVariableRecords should fall down to "d".
CInst->moveBefore(BB, BeginIt2);
- EXPECT_TRUE(!CInst->DebugMarker ||
- CInst->DebugMarker->StoredDbgRecords.empty());
- ASSERT_TRUE(DInst->DebugMarker);
- EXPECT_FALSE(DInst->DebugMarker->StoredDbgRecords.empty());
+ EXPECT_TRUE(!CInst->getDbgMarker() ||
+ CInst->getDbgMarker()->StoredDbgRecords.empty());
+ ASSERT_TRUE(DInst->getDbgMarker());
+ EXPECT_FALSE(DInst->getDbgMarker()->StoredDbgRecords.empty());
// Wheras if we move D to the start of the block with moveBeforePreserving,
// the DbgVariableRecords should move with it.
DInst->moveBeforePreserving(BB, BB.begin());
- EXPECT_FALSE(DInst->DebugMarker->StoredDbgRecords.empty());
+ EXPECT_FALSE(DInst->getDbgMarker()->StoredDbgRecords.empty());
EXPECT_EQ(&*BB.begin(), DInst);
// Similarly, moveAfterPreserving "D" to "C" should move DbgVariableRecords
// with "D".
DInst->moveAfterPreserving(CInst);
- EXPECT_FALSE(DInst->DebugMarker->StoredDbgRecords.empty());
+ EXPECT_FALSE(DInst->getDbgMarker()->StoredDbgRecords.empty());
// (move back to the start...)
DInst->moveBeforePreserving(BB, BB.begin());
@@ -416,9 +416,9 @@ TEST(BasicBlockDbgInfoTest, HeadBitOperations) {
// If we move "C" to the beginning of the block, it should go before the
// DbgVariableRecords. They'll stay on "D".
CInst->moveBefore(BB, BB.begin());
- EXPECT_TRUE(!CInst->DebugMarker ||
- CInst->DebugMarker->StoredDbgRecords.empty());
- EXPECT_FALSE(DInst->DebugMarker->StoredDbgRecords.empty());
+ EXPECT_TRUE(!CInst->getDbgMarker() ||
+ CInst->getDbgMarker()->StoredDbgRecords.empty());
+ EXPECT_FALSE(DInst->getDbgMarker()->StoredDbgRecords.empty());
EXPECT_EQ(&*BB.begin(), CInst);
EXPECT_EQ(CInst->getNextNode(), DInst);
@@ -434,9 +434,9 @@ TEST(BasicBlockDbgInfoTest, HeadBitOperations) {
// run of dbg.values and the next instruction.
CInst->moveBefore(BB, DInst->getIterator());
// CInst gains the DbgVariableRecords.
- EXPECT_TRUE(!DInst->DebugMarker ||
- DInst->DebugMarker->StoredDbgRecords.empty());
- EXPECT_FALSE(CInst->DebugMarker->StoredDbgRecords.empty());
+ EXPECT_TRUE(!DInst->getDbgMarker() ||
+ DInst->getDbgMarker()->StoredDbgRecords.empty());
+ EXPECT_FALSE(CInst->getDbgMarker()->StoredDbgRecords.empty());
EXPECT_EQ(&*BB.begin(), CInst);
}
@@ -476,18 +476,18 @@ TEST(BasicBlockDbgInfoTest, InstrDbgAccess) {
Instruction *CInst = BInst->getNextNode();
Instruction *DInst = CInst->getNextNode();
- ASSERT_FALSE(BInst->DebugMarker);
- ASSERT_TRUE(CInst->DebugMarker);
- ASSERT_EQ(CInst->DebugMarker->StoredDbgRecords.size(), 1u);
- DbgRecord *DVR1 = &*CInst->DebugMarker->StoredDbgRecords.begin();
+ ASSERT_FALSE(BInst->getDbgMarker());
+ ASSERT_TRUE(CInst->getDbgMarker());
+ ASSERT_EQ(CInst->getDbgMarker()->StoredDbgRecords.size(), 1u);
+ DbgRecord *DVR1 = &*CInst->getDbgMarker()->StoredDbgRecords.begin();
ASSERT_TRUE(DVR1);
EXPECT_FALSE(BInst->hasDbgRecords());
// Clone DbgVariableRecords from one inst to another. Other arguments to clone
// are tested in DbgMarker test.
auto Range1 = BInst->cloneDebugInfoFrom(CInst);
- EXPECT_EQ(BInst->DebugMarker->StoredDbgRecords.size(), 1u);
- DbgRecord *DVR2 = &*BInst->DebugMarker->StoredDbgRecords.begin();
+ EXPECT_EQ(BInst->getDbgMarker()->StoredDbgRecords.size(), 1u);
+ DbgRecord *DVR2 = &*BInst->getDbgMarker()->StoredDbgRecords.begin();
EXPECT_EQ(std::distance(Range1.begin(), Range1.end()), 1u);
EXPECT_EQ(&*Range1.begin(), DVR2);
EXPECT_NE(DVR1, DVR2);
@@ -505,12 +505,12 @@ TEST(BasicBlockDbgInfoTest, InstrDbgAccess) {
// Dropping should be easy,
BInst->dropDbgRecords();
EXPECT_FALSE(BInst->hasDbgRecords());
- EXPECT_EQ(BInst->DebugMarker->StoredDbgRecords.size(), 0u);
+ EXPECT_EQ(BInst->getDbgMarker()->StoredDbgRecords.size(), 0u);
// And we should be able to drop individual DbgVariableRecords.
CInst->dropOneDbgRecord(DVR1);
EXPECT_FALSE(CInst->hasDbgRecords());
- EXPECT_EQ(CInst->DebugMarker->StoredDbgRecords.size(), 0u);
+ EXPECT_EQ(CInst->getDbgMarker()->StoredDbgRecords.size(), 0u);
}
/* Let's recall the big illustration from BasicBlock::spliceDebugInfo:
@@ -615,20 +615,20 @@ class DbgSpliceTest : public ::testing::Test {
Branch = &*Last;
CInst = &*Dest;
- DVRA =
- cast<DbgVariableRecord>(&*BInst->DebugMarker->StoredDbgRecords.begin());
+ DVRA = cast<DbgVariableRecord>(
+ &*BInst->getDbgMarker()->StoredDbgRecords.begin());
DVRB = cast<DbgVariableRecord>(
- &*Branch->DebugMarker->StoredDbgRecords.begin());
- DVRConst =
- cast<DbgVariableRecord>(&*CInst->DebugMarker->StoredDbgRecords.begin());
+ &*Branch->getDbgMarker()->StoredDbgRecords.begin());
+ DVRConst = cast<DbgVariableRecord>(
+ &*CInst->getDbgMarker()->StoredDbgRecords.begin());
}
bool InstContainsDbgVariableRecord(Instruction *I, DbgVariableRecord *DVR) {
for (DbgRecord &D : I->getDbgRecordRange()) {
if (&D == DVR) {
// Confirm too that the links between the records are correct.
- EXPECT_EQ(DVR->Marker, I->DebugMarker);
- EXPECT_EQ(I->DebugMarker->MarkedInstr, I);
+ EXPECT_EQ(DVR->Marker, I->getDbgMarker());
+ EXPECT_EQ(I->getDbgMarker()->MarkedInstr, I);
return true;
}
}
@@ -1250,8 +1250,8 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceTrailing) {
// The trailing DbgVariableRecord should have been placed at the front of
// what's been spliced in.
Instruction *BInst = &*Entry.begin();
- ASSERT_TRUE(BInst->DebugMarker);
- EXPECT_EQ(BInst->DebugMarker->StoredDbgRecords.size(), 1u);
+ ASSERT_TRUE(BInst->getDbgMarker());
+ EXPECT_EQ(BInst->getDbgMarker()->StoredDbgRecords.size(), 1u);
}
// When we remove instructions from the program, adjacent DbgVariableRecords
@@ -1454,7 +1454,7 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty1) {
// should be in the correct order of %a, then 0.
Instruction *BInst = &*Entry.begin();
ASSERT_TRUE(BInst->hasDbgRecords());
- EXPECT_EQ(BInst->DebugMarker->StoredDbgRecords.size(), 2u);
+ EXPECT_EQ(BInst->getDbgMarker()->StoredDbgRecords.size(), 2u);
SmallVector<DbgVariableRecord *, 2> DbgVariableRecords;
for (DbgRecord &DVR : BInst->getDbgRecordRange())
DbgVariableRecords.push_back(cast<DbgVariableRecord>(&DVR));
@@ -1519,7 +1519,7 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty2) {
// We should now have one dbg.values on the first instruction, %a.
Instruction *BInst = &*Entry.begin();
ASSERT_TRUE(BInst->hasDbgRecords());
- EXPECT_EQ(BInst->DebugMarker->StoredDbgRecords.size(), 1u);
+ EXPECT_EQ(BInst->getDbgMarker()->StoredDbgRecords.size(), 1u);
SmallVector<DbgVariableRecord *, 2> DbgVariableRecords;
for (DbgRecord &DVR : BInst->getDbgRecordRange())
DbgVariableRecords.push_back(cast<DbgVariableRecord>(&DVR));
diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp
index 2de3906db0ee8..5b68354119e3a 100644
--- a/llvm/unittests/IR/DebugInfoTest.cpp
+++ b/llvm/unittests/IR/DebugInfoTest.cpp
@@ -1042,62 +1042,63 @@ TEST(MetadataTest, ConvertDbgToDbgVariableRecord) {
ExitBlock->createMarker(RetInst);
// Insert DbgRecords into markers, order should come out DVR2, DVR1.
- FirstInst->DebugMarker->insertDbgRecord(DVR1, false);
- FirstInst->DebugMarker->insertDbgRecord(DVR2, true);
+ FirstInst->getDbgMarker()->insertDbgRecord(DVR1, false);
+ FirstInst->getDbgMarker()->insertDbgRecord(DVR2, true);
unsigned int ItCount = 0;
- for (DbgRecord &Item : FirstInst->DebugMarker->getDbgRecordRange()) {
+ for (DbgRecord &Item : FirstInst->getDbgMarker()->getDbgRecordRange()) {
EXPECT_TRUE((&Item == DVR2 && ItCount == 0) ||
(&Item == DVR1 && ItCount == 1));
- EXPECT_EQ(Item.getMarker(), FirstInst->DebugMarker);
+ EXPECT_EQ(Item.getMarker(), FirstInst->getDbgMarker());
++ItCount;
}
// Clone them onto the second marker -- should allocate new DVRs.
- RetInst->DebugMarker->cloneDebugInfoFrom(FirstInst->DebugMarker, std::nullopt,
- false);
- EXPECT_EQ(RetInst->DebugMarker->StoredDbgRecords.size(), 2u);
+ RetInst->getDbgMarker()->cloneDebugInfoFrom(FirstInst->getDbgMarker(),
+ std::nullopt, false);
+ EXPECT_EQ(RetInst->getDbgMarker()->StoredDbgRecords.size(), 2u);
ItCount = 0;
// Check these things store the same information; but that they're not the same
// objects.
for (DbgVariableRecord &Item :
- filterDbgVars(RetInst->DebugMarker->getDbgRecordRange())) {
+ filterDbgVars(RetInst->getDbgMarker()->getDbgRecordRange())) {
EXPECT_TRUE(
(Item.getRawLocation() == DVR2->getRawLocation() && ItCount == 0) ||
(Item.getRawLocation() == DVR1->getRawLocation() && ItCount == 1));
- EXPECT_EQ(Item.getMarker(), RetInst->DebugMarker);
+ EXPECT_EQ(Item.getMarker(), RetInst->getDbgMarker());
EXPECT_NE(&Item, DVR1);
EXPECT_NE(&Item, DVR2);
++ItCount;
}
- RetInst->DebugMarker->dropDbgRecords();
- EXPECT_EQ(RetInst->DebugMarker->StoredDbgRecords.size(), 0u);
+ RetInst->getDbgMarker()->dropDbgRecords();
+ EXPECT_EQ(RetInst->getDbgMarker()->StoredDbgRecords.size(), 0u);
// Try cloning one single DbgVariableRecord.
- auto DIIt = std::next(FirstInst->DebugMarker->getDbgRecordRange().begin());
- RetInst->DebugMarker->cloneDebugInfoFrom(FirstInst->DebugMarker, DIIt, false);
- EXPECT_EQ(RetInst->DebugMarker->StoredDbgRecords.size(), 1u);
+ auto DIIt = std::next(FirstInst->getDbgMarker()->getDbgRecordRange().begin());
+ RetInst->getDbgMarker()->cloneDebugInfoFrom(FirstInst->getDbgMarker(), DIIt,
+ false);
+ EXPECT_EQ(RetInst->getDbgMarker()->StoredDbgRecords.size(), 1u);
// The second DbgVariableRecord should have been cloned; it should have the
// same values as DVR1.
EXPECT_EQ(
- cast<DbgVariableRecord>(RetInst->DebugMarker->StoredDbgRecords.begin())
+ cast<DbgVariableRecord>(RetInst->getDbgMarker()->StoredDbgRecords.begin())
->getRawLocation(),
DVR1->getRawLocation());
// We should be able to drop individual DbgRecords.
- RetInst->DebugMarker->dropOneDbgRecord(
- &*RetInst->DebugMarker->StoredDbgRecords.begin());
+ RetInst->getDbgMarker()->dropOneDbgRecord(
+ &*RetInst->getDbgMarker()->StoredDbgRecords.begin());
// "Aborb" a DbgMarker: this means pretend that the instruction it's attached
// to is disappearing so it needs to be transferred into "this" marker.
- RetInst->DebugMarker->absorbDebugValues(*FirstInst->DebugMarker, true);
- EXPECT_EQ(RetInst->DebugMarker->StoredDbgRecords.size(), 2u);
+ RetInst->getDbgMarker()->absorbDebugValues(*FirstInst->getDbgMarker(), true);
+ EXPECT_EQ(RetInst->getDbgMarker()->StoredDbgRecords.size(), 2u);
// Should be the DVR1 and DVR2 objects.
ItCount = 0;
- for (DbgRecord &Item : RetInst->DebugMarker->getDbgRecordRange()) {
+ for (DbgRecord &Item : RetInst->getDbgMarker()->getDbgRecordRange()) {
EXPECT_TRUE((&Item == DVR2 && ItCount == 0) ||
(&Item == DVR1 && ItCount == 1));
- EXPECT_EQ(Item.getMarker(), RetInst->DebugMarker);
+ EXPECT_EQ(Item.getMarker(), RetInst->getDbgMarker());
++ItCount;
}
@@ -1105,9 +1106,9 @@ TEST(MetadataTest, ConvertDbgToDbgVariableRecord) {
// evrything in the basic block, then they should sink down into the
// "TrailingDbgRecords" container for dangling debug-info. Future facilities
// will restore them back when a terminator is inserted.
- FirstInst->DebugMarker->removeMarker();
+ FirstInst->getDbgMarker()->removeMarker();
FirstInst->eraseFromParent();
- RetInst->DebugMarker->removeMarker();
+ RetInst->getDbgMarker()->removeMarker();
RetInst->eraseFromParent();
DbgMarker *EndMarker = ExitBlock->getTrailingDbgRecords();
@@ -1195,23 +1196,23 @@ TEST(MetadataTest, DbgVariableRecordConversionRoutines) {
EXPECT_EQ(BB1->size(), 2u);
Instruction *FirstInst = &BB1->front();
Instruction *SecondInst = FirstInst->getNextNode();
- ASSERT_TRUE(FirstInst->DebugMarker);
- ASSERT_TRUE(SecondInst->DebugMarker);
- EXPECT_NE(FirstInst->DebugMarker, SecondInst->DebugMarker);
- EXPECT_EQ(FirstInst, FirstInst->DebugMarker->MarkedInstr);
- EXPECT_EQ(SecondInst, SecondInst->DebugMarker->MarkedInstr);
+ ASSERT_TRUE(FirstInst->getDbgMarker());
+ ASSERT_TRUE(SecondInst->getDbgMarker());
+ EXPECT_NE(FirstInst->getDbgMarker(), SecondInst->getDbgMarker());
+ EXPECT_EQ(FirstInst, FirstInst->getDbgMarker()->MarkedInstr);
+ EXPECT_EQ(SecondInst, SecondInst->getDbgMarker()->MarkedInstr);
- EXPECT_EQ(FirstInst->DebugMarker->StoredDbgRecords.size(), 1u);
+ EXPECT_EQ(FirstInst->getDbgMarker()->StoredDbgRecords.size(), 1u);
DbgVariableRecord *DVR1 = cast<DbgVariableRecord>(
- &*FirstInst->DebugMarker->getDbgRecordRange().begin());
- EXPECT_EQ(DVR1->getMarker(), FirstInst->DebugMarker);
+ &*FirstInst->getDbgMarker()->getDbgRecordRange().begin());
+ EXPECT_EQ(DVR1->getMarker(), FirstInst->getDbgMarker());
// Should point at %a, an argument.
EXPECT_TRUE(isa<Argument>(DVR1->getVariableLocationOp(0)));
- EXPECT_EQ(SecondInst->DebugMarker->StoredDbgRecords.size(), 1u);
+ EXPECT_EQ(SecondInst->getDbgMarker()->StoredDbgRecords.size(), 1u);
DbgVariableRecord *DVR2 = cast<DbgVariableRecord>(
- &*SecondInst->DebugMarker->getDbgRecordRange().begin());
- EXPECT_EQ(DVR2->getMarker(), SecondInst->DebugMarker);
+ &*SecondInst->getDbgMarker()->getDbgRecordRange().begin());
+ EXPECT_EQ(DVR2->getMarker(), SecondInst->getDbgMarker());
// Should point at FirstInst.
EXPECT_EQ(DVR2->getVariableLocationOp(0), FirstInst);
@@ -1220,8 +1221,8 @@ TEST(MetadataTest, DbgVariableRecordConversionRoutines) {
BasicBlock *BB2 = BB1->getNextNode();
for (auto &Inst : *BB2)
// Either there should be no marker, or it should be empty.
- EXPECT_TRUE(!Inst.DebugMarker ||
- Inst.DebugMarker->StoredDbgRecords.empty());
+ EXPECT_TRUE(!Inst.getDbgMarker() ||
+ Inst.getDbgMarker()->StoredDbgRecords.empty());
// Validating the first block should continue to not be a problem,
Error = verifyModule(*M, &errs(), &BrokenDebugInfo);
@@ -1235,7 +1236,7 @@ TEST(MetadataTest, DbgVariableRecordConversionRoutines) {
Error = verifyModule(*M, &errs(), &BrokenDebugInfo);
EXPECT_FALSE(Error);
EXPECT_TRUE(BrokenDebugInfo);
- DVR1->setMarker(FirstInst->DebugMarker);
+ DVR1->setMarker(FirstInst->getDbgMarker());
DILocalVariable *DLV1 = DVR1->getVariable();
DIExpression *Expr1 = DVR1->getExpression();
diff --git a/llvm/unittests/Transforms/Utils/LocalTest.cpp b/llvm/unittests/Transforms/Utils/LocalTest.cpp
index 5fbc28e9430f3..a497f75c00896 100644
--- a/llvm/unittests/Transforms/Utils/LocalTest.cpp
+++ b/llvm/unittests/Transforms/Utils/LocalTest.cpp
@@ -1367,5 +1367,5 @@ TEST(Local, ReplaceDbgVariableRecord) {
EXPECT_EQ(DVR->getVariableLocationOp(0), FooInst);
// Teardown.
- RetInst->DebugMarker->eraseFromParent();
+ RetInst->getDbgMarker()->eraseFromParent();
}
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index ce6da7b1b6c3d..fa40b51c22f05 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -2788,8 +2788,9 @@ LogicalResult ModuleImport::processInstruction(llvm::Instruction *inst) {
// Process debug records attached to this instruction. Debug variable records
// are stored for later processing after all SSA values are converted, while
// debug label records can be converted immediately.
- if (inst->DebugMarker) {
- for (llvm::DbgRecord &dbgRecord : inst->DebugMarker->getDbgRecordRange()) {
+ if (inst->getDbgMarker()) {
+ for (llvm::DbgRecord &dbgRecord :
+ inst->getDbgMarker()->getDbgRecordRange()) {
// Store debug variable records for later processing.
if (auto *dbgVariableRecord =
dyn_cast<llvm::DbgVariableRecord>(&dbgRecord)) {
More information about the Mlir-commits
mailing list