Skip to content

[RemoveDIs] Change remapDbgVariableRecord to remapDbgRecord #91456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions llvm/include/llvm/Transforms/Utils/ValueMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,8 @@ class ValueMapper {
Constant *mapConstant(const Constant &C);

void remapInstruction(Instruction &I);
void remapDbgVariableRecord(Module *M, DbgVariableRecord &V);
void remapDbgVariableRecordRange(Module *M,
iterator_range<DbgRecordIterator> Range);
void remapDbgRecord(Module *M, DbgRecord &V);
void remapDbgRecordRange(Module *M, iterator_range<DbgRecordIterator> Range);
void remapFunction(Function &F);
void remapGlobalObjectMetadata(GlobalObject &GO);

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

/// Remap the Values used in the DbgVariableRecord \a V using the value map \a
/// Remap the Values used in the DbgRecord \a DR using the value map \a
/// VM.
inline void RemapDbgVariableRecord(Module *M, DbgVariableRecord *V,
ValueToValueMapTy &VM,
RemapFlags Flags = RF_None,
ValueMapTypeRemapper *TypeMapper = nullptr,
ValueMaterializer *Materializer = nullptr) {
ValueMapper(VM, Flags, TypeMapper, Materializer)
.remapDbgVariableRecord(M, *V);
inline void RemapDbgRecord(Module *M, DbgRecord *DR, ValueToValueMapTy &VM,
RemapFlags Flags = RF_None,
ValueMapTypeRemapper *TypeMapper = nullptr,
ValueMaterializer *Materializer = nullptr) {
ValueMapper(VM, Flags, TypeMapper, Materializer).remapDbgRecord(M, *DR);
}

/// Remap the Values used in the DbgVariableRecord \a V using the value map \a
/// Remap the Values used in the DbgRecords \a Range using the value map \a
/// VM.
inline void
RemapDbgVariableRecordRange(Module *M, iterator_range<DbgRecordIterator> Range,
ValueToValueMapTy &VM, RemapFlags Flags = RF_None,
ValueMapTypeRemapper *TypeMapper = nullptr,
ValueMaterializer *Materializer = nullptr) {
inline void RemapDbgRecordRange(Module *M,
iterator_range<DbgRecordIterator> Range,
ValueToValueMapTy &VM,
RemapFlags Flags = RF_None,
ValueMapTypeRemapper *TypeMapper = nullptr,
ValueMaterializer *Materializer = nullptr) {
ValueMapper(VM, Flags, TypeMapper, Materializer)
.remapDbgVariableRecordRange(M, Range);
.remapDbgRecordRange(M, Range);
}

/// Remap the operands, metadata, arguments, and instructions of a function.
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,9 +1261,8 @@ static BasicBlock *buildClonedLoopBlocks(
Module *M = ClonedPH->getParent()->getParent();
for (auto *ClonedBB : NewBlocks)
for (Instruction &I : *ClonedBB) {
RemapDbgVariableRecordRange(M, I.getDbgRecordRange(), VMap,
RF_NoModuleLevelChanges |
RF_IgnoreMissingLocals);
RemapDbgRecordRange(M, I.getDbgRecordRange(), VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
RemapInstruction(&I, VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
if (auto *II = dyn_cast<AssumeInst>(&I))
Expand Down
17 changes: 8 additions & 9 deletions llvm/lib/Transforms/Utils/CloneFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
// attached debug-info records.
for (Instruction &II : *BB) {
RemapInstruction(&II, VMap, RemapFlag, TypeMapper, Materializer);
RemapDbgVariableRecordRange(II.getModule(), II.getDbgRecordRange(), VMap,
RemapFlag, TypeMapper, Materializer);
RemapDbgRecordRange(II.getModule(), II.getDbgRecordRange(), VMap,
RemapFlag, TypeMapper, Materializer);
}

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

Expand Down Expand Up @@ -969,9 +969,8 @@ void llvm::remapInstructionsInBlocks(ArrayRef<BasicBlock *> Blocks,
// Rewrite the code to refer to itself.
for (auto *BB : Blocks) {
for (auto &Inst : *BB) {
RemapDbgVariableRecordRange(
Inst.getModule(), Inst.getDbgRecordRange(), VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
RemapDbgRecordRange(Inst.getModule(), Inst.getDbgRecordRange(), VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
RemapInstruction(&Inst, VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
}
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,8 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
!NextDbgInsts.empty()) {
auto DbgValueRange =
LoopEntryBranch->cloneDebugInfoFrom(Inst, NextDbgInsts.begin());
RemapDbgVariableRecordRange(M, DbgValueRange, ValueMap,
RF_NoModuleLevelChanges |
RF_IgnoreMissingLocals);
RemapDbgRecordRange(M, DbgValueRange, ValueMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
// Erase anything we've seen before.
for (DbgVariableRecord &DVR :
make_early_inc_range(filterDbgVars(DbgValueRange)))
Expand All @@ -666,9 +665,8 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
if (LoopEntryBranch->getParent()->IsNewDbgInfoFormat &&
!NextDbgInsts.empty()) {
auto Range = C->cloneDebugInfoFrom(Inst, NextDbgInsts.begin());
RemapDbgVariableRecordRange(M, Range, ValueMap,
RF_NoModuleLevelChanges |
RF_IgnoreMissingLocals);
RemapDbgRecordRange(M, Range, ValueMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
NextDbgInsts = DbgMarker::getEmptyDbgRecordRange();
// Erase anything we've seen before.
for (DbgVariableRecord &DVR :
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,8 @@ bool llvm::UnrollRuntimeLoopRemainder(
for (Instruction &I : *BB) {
RemapInstruction(&I, VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
RemapDbgVariableRecordRange(M, I.getDbgRecordRange(), VMap,
RF_NoModuleLevelChanges |
RF_IgnoreMissingLocals);
RemapDbgRecordRange(M, I.getDbgRecordRange(), VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
}
}

Expand Down
9 changes: 4 additions & 5 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,9 +1124,8 @@ static void CloneInstructionsIntoPredecessorBlockAndUpdateSSAUses(

NewBonusInst->insertInto(PredBlock, PTI->getIterator());
auto Range = NewBonusInst->cloneDebugInfoFrom(&BonusInst);
RemapDbgVariableRecordRange(NewBonusInst->getModule(), Range, VMap,
RF_NoModuleLevelChanges |
RF_IgnoreMissingLocals);
RemapDbgRecordRange(NewBonusInst->getModule(), Range, VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);

if (isa<DbgInfoIntrinsic>(BonusInst))
continue;
Expand Down Expand Up @@ -3860,8 +3859,8 @@ static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
PredBlock->getTerminator()->cloneDebugInfoFrom(BB->getTerminator());
for (DbgVariableRecord &DVR :
filterDbgVars(PredBlock->getTerminator()->getDbgRecordRange())) {
RemapDbgVariableRecord(M, &DVR, VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
RemapDbgRecord(M, &DVR, VMap,
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
}
}

Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Transforms/Utils/ValueMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,14 +1236,14 @@ void ValueMapper::remapInstruction(Instruction &I) {
FlushingMapper(pImpl)->remapInstruction(&I);
}

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

void ValueMapper::remapDbgVariableRecordRange(
void ValueMapper::remapDbgRecordRange(
Module *M, iterator_range<DbgRecord::self_iterator> Range) {
for (DbgVariableRecord &DVR : filterDbgVars(Range)) {
remapDbgVariableRecord(M, DVR);
for (DbgRecord &DR : Range) {
remapDbgRecord(M, DR);
}
}

Expand Down
37 changes: 37 additions & 0 deletions llvm/unittests/Transforms/Utils/CloningTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,4 +1122,41 @@ TEST_F(CloneModule, IFunc) {
EXPECT_EQ("resolver", Resolver->getName());
EXPECT_EQ(GlobalValue::PrivateLinkage, Resolver->getLinkage());
}

TEST_F(CloneModule, CloneDbgLabel) {
LLVMContext Context;

std::unique_ptr<Module> M = parseIR(Context,
R"M(
define void @noop(ptr nocapture noundef writeonly align 4 %dst) local_unnamed_addr !dbg !3 {
entry:
%call = tail call spir_func i64 @foo(i32 noundef 0)
#dbg_label(!11, !12)
store i64 %call, ptr %dst, align 4
ret void
}

declare i64 @foo(i32 noundef) local_unnamed_addr

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2}

!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 19.0.0git", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
!1 = !DIFile(filename: "<stdin>", directory: "foo")
!2 = !{i32 2, !"Debug Info Version", i32 3}
!3 = distinct !DISubprogram(name: "noop", scope: !4, file: !4, line: 17, type: !5, scopeLine: 17, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !9)
!4 = !DIFile(filename: "file", directory: "foo")
!5 = !DISubroutineType(types: !6)
!6 = !{null, !7}
!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!9 = !{}
!11 = !DILabel(scope: !3, name: "foo", file: !4, line: 23)
!12 = !DILocation(line: 23, scope: !3)
)M");

ASSERT_FALSE(verifyModule(*M, &errs()));
auto NewM = llvm::CloneModule(*M);
EXPECT_FALSE(verifyModule(*NewM, &errs()));
}
} // namespace