Skip to content

Commit a617190

Browse files
hvdijkPietroGhg
andauthored
[RemoveDIs] Change remapDbgVariableRecord to remapDbgRecord (#91456)
We need to remap any DbgRecord, not just DbgVariableRecords. This is the followup to #91447. Co-authored-by: PietroGhg <[email protected]>
1 parent 2ceb129 commit a617190

File tree

8 files changed

+78
-49
lines changed

8 files changed

+78
-49
lines changed

llvm/include/llvm/Transforms/Utils/ValueMapper.h

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,8 @@ class ValueMapper {
180180
Constant *mapConstant(const Constant &C);
181181

182182
void remapInstruction(Instruction &I);
183-
void remapDbgVariableRecord(Module *M, DbgVariableRecord &V);
184-
void remapDbgVariableRecordRange(Module *M,
185-
iterator_range<DbgRecordIterator> Range);
183+
void remapDbgRecord(Module *M, DbgRecord &V);
184+
void remapDbgRecordRange(Module *M, iterator_range<DbgRecordIterator> Range);
186185
void remapFunction(Function &F);
187186
void remapGlobalObjectMetadata(GlobalObject &GO);
188187

@@ -268,26 +267,25 @@ inline void RemapInstruction(Instruction *I, ValueToValueMapTy &VM,
268267
ValueMapper(VM, Flags, TypeMapper, Materializer).remapInstruction(*I);
269268
}
270269

271-
/// Remap the Values used in the DbgVariableRecord \a V using the value map \a
270+
/// Remap the Values used in the DbgRecord \a DR using the value map \a
272271
/// VM.
273-
inline void RemapDbgVariableRecord(Module *M, DbgVariableRecord *V,
274-
ValueToValueMapTy &VM,
275-
RemapFlags Flags = RF_None,
276-
ValueMapTypeRemapper *TypeMapper = nullptr,
277-
ValueMaterializer *Materializer = nullptr) {
278-
ValueMapper(VM, Flags, TypeMapper, Materializer)
279-
.remapDbgVariableRecord(M, *V);
272+
inline void RemapDbgRecord(Module *M, DbgRecord *DR, ValueToValueMapTy &VM,
273+
RemapFlags Flags = RF_None,
274+
ValueMapTypeRemapper *TypeMapper = nullptr,
275+
ValueMaterializer *Materializer = nullptr) {
276+
ValueMapper(VM, Flags, TypeMapper, Materializer).remapDbgRecord(M, *DR);
280277
}
281278

282-
/// Remap the Values used in the DbgVariableRecord \a V using the value map \a
279+
/// Remap the Values used in the DbgRecords \a Range using the value map \a
283280
/// VM.
284-
inline void
285-
RemapDbgVariableRecordRange(Module *M, iterator_range<DbgRecordIterator> Range,
286-
ValueToValueMapTy &VM, RemapFlags Flags = RF_None,
287-
ValueMapTypeRemapper *TypeMapper = nullptr,
288-
ValueMaterializer *Materializer = nullptr) {
281+
inline void RemapDbgRecordRange(Module *M,
282+
iterator_range<DbgRecordIterator> Range,
283+
ValueToValueMapTy &VM,
284+
RemapFlags Flags = RF_None,
285+
ValueMapTypeRemapper *TypeMapper = nullptr,
286+
ValueMaterializer *Materializer = nullptr) {
289287
ValueMapper(VM, Flags, TypeMapper, Materializer)
290-
.remapDbgVariableRecordRange(M, Range);
288+
.remapDbgRecordRange(M, Range);
291289
}
292290

293291
/// Remap the operands, metadata, arguments, and instructions of a function.

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,9 +1261,8 @@ static BasicBlock *buildClonedLoopBlocks(
12611261
Module *M = ClonedPH->getParent()->getParent();
12621262
for (auto *ClonedBB : NewBlocks)
12631263
for (Instruction &I : *ClonedBB) {
1264-
RemapDbgVariableRecordRange(M, I.getDbgRecordRange(), VMap,
1265-
RF_NoModuleLevelChanges |
1266-
RF_IgnoreMissingLocals);
1264+
RemapDbgRecordRange(M, I.getDbgRecordRange(), VMap,
1265+
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
12671266
RemapInstruction(&I, VMap,
12681267
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
12691268
if (auto *II = dyn_cast<AssumeInst>(&I))

llvm/lib/Transforms/Utils/CloneFunction.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
278278
// attached debug-info records.
279279
for (Instruction &II : *BB) {
280280
RemapInstruction(&II, VMap, RemapFlag, TypeMapper, Materializer);
281-
RemapDbgVariableRecordRange(II.getModule(), II.getDbgRecordRange(), VMap,
282-
RemapFlag, TypeMapper, Materializer);
281+
RemapDbgRecordRange(II.getModule(), II.getDbgRecordRange(), VMap,
282+
RemapFlag, TypeMapper, Materializer);
283283
}
284284

285285
// Only update !llvm.dbg.cu for DifferentModule (not CloneModule). In the
@@ -867,10 +867,10 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
867867
Function::iterator Begin = cast<BasicBlock>(VMap[StartingBB])->getIterator();
868868
for (BasicBlock &BB : make_range(Begin, NewFunc->end())) {
869869
for (Instruction &I : BB) {
870-
RemapDbgVariableRecordRange(I.getModule(), I.getDbgRecordRange(), VMap,
871-
ModuleLevelChanges ? RF_None
872-
: RF_NoModuleLevelChanges,
873-
TypeMapper, Materializer);
870+
RemapDbgRecordRange(I.getModule(), I.getDbgRecordRange(), VMap,
871+
ModuleLevelChanges ? RF_None
872+
: RF_NoModuleLevelChanges,
873+
TypeMapper, Materializer);
874874
}
875875
}
876876

@@ -969,9 +969,8 @@ void llvm::remapInstructionsInBlocks(ArrayRef<BasicBlock *> Blocks,
969969
// Rewrite the code to refer to itself.
970970
for (auto *BB : Blocks) {
971971
for (auto &Inst : *BB) {
972-
RemapDbgVariableRecordRange(
973-
Inst.getModule(), Inst.getDbgRecordRange(), VMap,
974-
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
972+
RemapDbgRecordRange(Inst.getModule(), Inst.getDbgRecordRange(), VMap,
973+
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
975974
RemapInstruction(&Inst, VMap,
976975
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
977976
}

llvm/lib/Transforms/Utils/LoopRotationUtils.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,8 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
639639
!NextDbgInsts.empty()) {
640640
auto DbgValueRange =
641641
LoopEntryBranch->cloneDebugInfoFrom(Inst, NextDbgInsts.begin());
642-
RemapDbgVariableRecordRange(M, DbgValueRange, ValueMap,
643-
RF_NoModuleLevelChanges |
644-
RF_IgnoreMissingLocals);
642+
RemapDbgRecordRange(M, DbgValueRange, ValueMap,
643+
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
645644
// Erase anything we've seen before.
646645
for (DbgVariableRecord &DVR :
647646
make_early_inc_range(filterDbgVars(DbgValueRange)))
@@ -666,9 +665,8 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
666665
if (LoopEntryBranch->getParent()->IsNewDbgInfoFormat &&
667666
!NextDbgInsts.empty()) {
668667
auto Range = C->cloneDebugInfoFrom(Inst, NextDbgInsts.begin());
669-
RemapDbgVariableRecordRange(M, Range, ValueMap,
670-
RF_NoModuleLevelChanges |
671-
RF_IgnoreMissingLocals);
668+
RemapDbgRecordRange(M, Range, ValueMap,
669+
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
672670
NextDbgInsts = DbgMarker::getEmptyDbgRecordRange();
673671
// Erase anything we've seen before.
674672
for (DbgVariableRecord &DVR :

llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,8 @@ bool llvm::UnrollRuntimeLoopRemainder(
917917
for (Instruction &I : *BB) {
918918
RemapInstruction(&I, VMap,
919919
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
920-
RemapDbgVariableRecordRange(M, I.getDbgRecordRange(), VMap,
921-
RF_NoModuleLevelChanges |
922-
RF_IgnoreMissingLocals);
920+
RemapDbgRecordRange(M, I.getDbgRecordRange(), VMap,
921+
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
923922
}
924923
}
925924

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,9 +1124,8 @@ static void CloneInstructionsIntoPredecessorBlockAndUpdateSSAUses(
11241124

11251125
NewBonusInst->insertInto(PredBlock, PTI->getIterator());
11261126
auto Range = NewBonusInst->cloneDebugInfoFrom(&BonusInst);
1127-
RemapDbgVariableRecordRange(NewBonusInst->getModule(), Range, VMap,
1128-
RF_NoModuleLevelChanges |
1129-
RF_IgnoreMissingLocals);
1127+
RemapDbgRecordRange(NewBonusInst->getModule(), Range, VMap,
1128+
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
11301129

11311130
if (isa<DbgInfoIntrinsic>(BonusInst))
11321131
continue;
@@ -3860,8 +3859,8 @@ static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
38603859
PredBlock->getTerminator()->cloneDebugInfoFrom(BB->getTerminator());
38613860
for (DbgVariableRecord &DVR :
38623861
filterDbgVars(PredBlock->getTerminator()->getDbgRecordRange())) {
3863-
RemapDbgVariableRecord(M, &DVR, VMap,
3864-
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
3862+
RemapDbgRecord(M, &DVR, VMap,
3863+
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
38653864
}
38663865
}
38673866

llvm/lib/Transforms/Utils/ValueMapper.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,14 +1236,14 @@ void ValueMapper::remapInstruction(Instruction &I) {
12361236
FlushingMapper(pImpl)->remapInstruction(&I);
12371237
}
12381238

1239-
void ValueMapper::remapDbgVariableRecord(Module *M, DbgVariableRecord &V) {
1240-
FlushingMapper(pImpl)->remapDbgRecord(V);
1239+
void ValueMapper::remapDbgRecord(Module *M, DbgRecord &DR) {
1240+
FlushingMapper(pImpl)->remapDbgRecord(DR);
12411241
}
12421242

1243-
void ValueMapper::remapDbgVariableRecordRange(
1243+
void ValueMapper::remapDbgRecordRange(
12441244
Module *M, iterator_range<DbgRecord::self_iterator> Range) {
1245-
for (DbgVariableRecord &DVR : filterDbgVars(Range)) {
1246-
remapDbgVariableRecord(M, DVR);
1245+
for (DbgRecord &DR : Range) {
1246+
remapDbgRecord(M, DR);
12471247
}
12481248
}
12491249

llvm/unittests/Transforms/Utils/CloningTest.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,4 +1122,41 @@ TEST_F(CloneModule, IFunc) {
11221122
EXPECT_EQ("resolver", Resolver->getName());
11231123
EXPECT_EQ(GlobalValue::PrivateLinkage, Resolver->getLinkage());
11241124
}
1125+
1126+
TEST_F(CloneModule, CloneDbgLabel) {
1127+
LLVMContext Context;
1128+
1129+
std::unique_ptr<Module> M = parseIR(Context,
1130+
R"M(
1131+
define void @noop(ptr nocapture noundef writeonly align 4 %dst) local_unnamed_addr !dbg !3 {
1132+
entry:
1133+
%call = tail call spir_func i64 @foo(i32 noundef 0)
1134+
#dbg_label(!11, !12)
1135+
store i64 %call, ptr %dst, align 4
1136+
ret void
1137+
}
1138+
1139+
declare i64 @foo(i32 noundef) local_unnamed_addr
1140+
1141+
!llvm.dbg.cu = !{!0}
1142+
!llvm.module.flags = !{!2}
1143+
1144+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 19.0.0git", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
1145+
!1 = !DIFile(filename: "<stdin>", directory: "foo")
1146+
!2 = !{i32 2, !"Debug Info Version", i32 3}
1147+
!3 = distinct !DISubprogram(name: "noop", scope: !4, file: !4, line: 17, type: !5, scopeLine: 17, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !9)
1148+
!4 = !DIFile(filename: "file", directory: "foo")
1149+
!5 = !DISubroutineType(types: !6)
1150+
!6 = !{null, !7}
1151+
!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
1152+
!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
1153+
!9 = !{}
1154+
!11 = !DILabel(scope: !3, name: "foo", file: !4, line: 23)
1155+
!12 = !DILocation(line: 23, scope: !3)
1156+
)M");
1157+
1158+
ASSERT_FALSE(verifyModule(*M, &errs()));
1159+
auto NewM = llvm::CloneModule(*M);
1160+
EXPECT_FALSE(verifyModule(*NewM, &errs()));
11251161
}
1162+
} // namespace

0 commit comments

Comments
 (0)