From ca877dfdc36b6087eea2173958080d587a1abd8b Mon Sep 17 00:00:00 2001 From: Ana Marija Date: Mon, 27 Oct 2025 09:09:58 +0100 Subject: [PATCH 1/3] Added counter and deleter passes for debug info --- foo_00.ll | 81 +++++++++++++++++++ .../Transforms/Utils/DebugRecordCounter.h | 15 ++++ .../Transforms/Utils/DebugRecordDeleter.h | 15 ++++ llvm/lib/Passes/PassBuilder.cpp | 2 + llvm/lib/Passes/PassRegistry.def | 2 + llvm/lib/Transforms/Utils/CMakeLists.txt | 2 + .../Transforms/Utils/DebugRecordCounter.cpp | 31 +++++++ .../Transforms/Utils/DebugRecordDeleter.cpp | 16 ++++ 8 files changed, 164 insertions(+) create mode 100644 foo_00.ll create mode 100644 llvm/include/llvm/Transforms/Utils/DebugRecordCounter.h create mode 100644 llvm/include/llvm/Transforms/Utils/DebugRecordDeleter.h create mode 100644 llvm/lib/Transforms/Utils/DebugRecordCounter.cpp create mode 100644 llvm/lib/Transforms/Utils/DebugRecordDeleter.cpp diff --git a/foo_00.ll b/foo_00.ll new file mode 100644 index 0000000000000..6a9cff3891632 --- /dev/null +++ b/foo_00.ll @@ -0,0 +1,81 @@ +; ModuleID = '/home/ana-marija/Documents/foo.c' +source_filename = "/home/ana-marija/Documents/foo.c" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local i32 @foo() #0 !dbg !10 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + %3 = alloca i32, align 4 + #dbg_declare(ptr %1, !16, !DIExpression(), !17) + store i32 21, ptr %1, align 4, !dbg !17 + #dbg_declare(ptr %2, !18, !DIExpression(), !19) + store i32 22, ptr %2, align 4, !dbg !19 + #dbg_declare(ptr %3, !20, !DIExpression(), !22) + store i32 23, ptr %3, align 4, !dbg !22 + %4 = load i32, ptr %1, align 4, !dbg !23 + store i32 %4, ptr %3, align 4, !dbg !24 + %5 = load i32, ptr %2, align 4, !dbg !25 + store i32 %5, ptr %1, align 4, !dbg !26 + %6 = load i32, ptr %1, align 4, !dbg !27 + %7 = load i32, ptr %2, align 4, !dbg !28 + %8 = add nsw i32 %6, %7, !dbg !29 + ret i32 %8, !dbg !30 +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local i32 @main() #0 !dbg !31 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + store i32 0, ptr %1, align 4 + #dbg_declare(ptr %2, !32, !DIExpression(), !33) + %3 = call i32 @foo(), !dbg !34 + store i32 %3, ptr %2, align 4, !dbg !33 + %4 = load i32, ptr %2, align 4, !dbg !35 + ret i32 %4, !dbg !36 +} + +attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8} +!llvm.ident = !{!9} + +!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 22.0.0git (https://github.com/anamaoh/llvm-project.git 782a91e1fc94d9c82495f60afc5ed5edd72de776)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "/home/ana-marija/Documents/foo.c", directory: "/home/ana-marija/Desktop/LLVM/llvm-project", checksumkind: CSK_MD5, checksum: "22bc4641d6e8e63df371a758d86cafff") +!2 = !{i32 7, !"Dwarf Version", i32 5} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = !{i32 1, !"wchar_size", i32 4} +!5 = !{i32 8, !"PIC Level", i32 2} +!6 = !{i32 7, !"PIE Level", i32 2} +!7 = !{i32 7, !"uwtable", i32 2} +!8 = !{i32 7, !"frame-pointer", i32 2} +!9 = !{!"clang version 22.0.0git (https://github.com/anamaoh/llvm-project.git 782a91e1fc94d9c82495f60afc5ed5edd72de776)"} +!10 = distinct !DISubprogram(name: "foo", scope: !11, file: !11, line: 1, type: !12, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !15) +!11 = !DIFile(filename: "Documents/foo.c", directory: "/home/ana-marija", checksumkind: CSK_MD5, checksum: "22bc4641d6e8e63df371a758d86cafff") +!12 = !DISubroutineType(types: !13) +!13 = !{!14} +!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!15 = !{} +!16 = !DILocalVariable(name: "X", scope: !10, file: !11, line: 2, type: !14) +!17 = !DILocation(line: 2, column: 6, scope: !10) +!18 = !DILocalVariable(name: "Y", scope: !10, file: !11, line: 3, type: !14) +!19 = !DILocation(line: 3, column: 6, scope: !10) +!20 = !DILocalVariable(name: "Z", scope: !21, file: !11, line: 5, type: !14) +!21 = distinct !DILexicalBlock(scope: !10, file: !11, line: 4, column: 2) +!22 = !DILocation(line: 5, column: 8, scope: !21) +!23 = !DILocation(line: 6, column: 8, scope: !21) +!24 = !DILocation(line: 6, column: 6, scope: !21) +!25 = !DILocation(line: 8, column: 6, scope: !10) +!26 = !DILocation(line: 8, column: 4, scope: !10) +!27 = !DILocation(line: 9, column: 9, scope: !10) +!28 = !DILocation(line: 9, column: 13, scope: !10) +!29 = !DILocation(line: 9, column: 11, scope: !10) +!30 = !DILocation(line: 9, column: 2, scope: !10) +!31 = distinct !DISubprogram(name: "main", scope: !11, file: !11, line: 12, type: !12, scopeLine: 12, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !15) +!32 = !DILocalVariable(name: "A", scope: !31, file: !11, line: 13, type: !14) +!33 = !DILocation(line: 13, column: 6, scope: !31) +!34 = !DILocation(line: 13, column: 10, scope: !31) +!35 = !DILocation(line: 14, column: 9, scope: !31) +!36 = !DILocation(line: 14, column: 2, scope: !31) diff --git a/llvm/include/llvm/Transforms/Utils/DebugRecordCounter.h b/llvm/include/llvm/Transforms/Utils/DebugRecordCounter.h new file mode 100644 index 0000000000000..f8a4e5bd671e7 --- /dev/null +++ b/llvm/include/llvm/Transforms/Utils/DebugRecordCounter.h @@ -0,0 +1,15 @@ +#ifndef LLVM_TRANSFORMS_UTILS_DEBUG_RECORD_COUNTER_H +#define LLVM_TRANSFORMS_UTILS_DEBUG_RECORD_COUNTER_H + +#include "llvm/IR/PassManager.h" + +namespace llvm { + + class DebugRecordCounterPass : public PassInfoMixin { + public: + PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); + }; + +} // namespace llvm + +#endif // LLVM_TRANSFORMS_UTILS_DEBUG_RECORD_COUNTER_H diff --git a/llvm/include/llvm/Transforms/Utils/DebugRecordDeleter.h b/llvm/include/llvm/Transforms/Utils/DebugRecordDeleter.h new file mode 100644 index 0000000000000..e40ed00b8095e --- /dev/null +++ b/llvm/include/llvm/Transforms/Utils/DebugRecordDeleter.h @@ -0,0 +1,15 @@ +#ifndef LLVM_TRANSFORMS_UTILS_DEBUG_RECORD_DELETER_H +#define LLVM_TRANSFORMS_UTILS_DEBUG_RECORD_DELETER_H + +#include "llvm/IR/PassManager.h" + +namespace llvm { + + class DebugRecordDeleterPass : public PassInfoMixin { + public: + PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); + }; + +} // namespace llvm + +#endif // LLVM_TRANSFORMS_UTILS_DEBUG_RECORD_DELETER_H diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index 53cf0046bd858..0723a6b8b92e0 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -350,6 +350,8 @@ #include "llvm/Transforms/Utils/CountVisits.h" #include "llvm/Transforms/Utils/DXILUpgrade.h" #include "llvm/Transforms/Utils/Debugify.h" +#include "llvm/Transforms/Utils/DebugRecordCounter.h" +#include "llvm/Transforms/Utils/DebugRecordDeleter.h" #include "llvm/Transforms/Utils/DeclareRuntimeLibcalls.h" #include "llvm/Transforms/Utils/EntryExitInstrumenter.h" #include "llvm/Transforms/Utils/FixIrreducible.h" diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 1b1652555cd28..e34866485fba3 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -49,6 +49,8 @@ MODULE_ALIAS_ANALYSIS("globals-aa", GlobalsAA()) #ifndef MODULE_PASS #define MODULE_PASS(NAME, CREATE_PASS) #endif +MODULE_PASS("dbg-counter", DebugRecordCounterPass()) +MODULE_PASS("dbg-deleter", DebugRecordDeleterPass()) MODULE_PASS("always-inline", AlwaysInlinerPass()) MODULE_PASS("annotation2metadata", Annotation2MetadataPass()) MODULE_PASS("assign-guid", AssignGUIDPass()) diff --git a/llvm/lib/Transforms/Utils/CMakeLists.txt b/llvm/lib/Transforms/Utils/CMakeLists.txt index f367ca2fdf56b..d6bc72055a5ef 100644 --- a/llvm/lib/Transforms/Utils/CMakeLists.txt +++ b/llvm/lib/Transforms/Utils/CMakeLists.txt @@ -20,6 +20,8 @@ add_llvm_component_library(LLVMTransformUtils CtorUtils.cpp CountVisits.cpp Debugify.cpp + DebugRecordCounter.cpp + DebugRecordDeleter.cpp DebugSSAUpdater.cpp DeclareRuntimeLibcalls.cpp DemoteRegToStack.cpp diff --git a/llvm/lib/Transforms/Utils/DebugRecordCounter.cpp b/llvm/lib/Transforms/Utils/DebugRecordCounter.cpp new file mode 100644 index 0000000000000..9b05585f81123 --- /dev/null +++ b/llvm/lib/Transforms/Utils/DebugRecordCounter.cpp @@ -0,0 +1,31 @@ +#include "llvm/Transforms/Utils/DebugRecordCounter.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/Module.h" + +using namespace llvm; + +// build/bin/opt -disable-output /home/ana-marija/Documents/foo_00.ll -passes=dbg-counter +PreservedAnalyses DebugRecordCounterPass::run(Module &M, ModuleAnalysisManager &AM) { + + int dbg_values, dbg_declares, dbg_assigns; + + for (Function &F : M) { + errs() << "Function: " << F.getName() << "\n"; + + dbg_assigns = dbg_declares = dbg_values = 0; + + for(BasicBlock &BB : F) { + for(Instruction &I : BB) { + for(DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) { + if(DVR.isDbgDeclare()) dbg_declares++; + if(DVR.isDbgValue()) dbg_values++; + if(DVR.isDbgAssign()) dbg_assigns++; + } + } + } + errs() << "\t#dbg_value: " << dbg_values << "\n"; + errs() << "\t#dbg_declare: " << dbg_declares << "\n"; + errs() << "\t#dbg_assign: " << dbg_assigns << "\n"; + } + return PreservedAnalyses::all(); +} diff --git a/llvm/lib/Transforms/Utils/DebugRecordDeleter.cpp b/llvm/lib/Transforms/Utils/DebugRecordDeleter.cpp new file mode 100644 index 0000000000000..78a51054f05bf --- /dev/null +++ b/llvm/lib/Transforms/Utils/DebugRecordDeleter.cpp @@ -0,0 +1,16 @@ +#include "llvm/Transforms/Utils/DebugRecordDeleter.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/DebugInfo.h" +#include "llvm/IR/DebugInfoMetadata.h" + +using namespace llvm; + +// build/bin/opt -S /home/ana-marija/Documents/foo_00.ll -passes=dbg-deleter +PreservedAnalyses DebugRecordDeleterPass::run(Module &M, ModuleAnalysisManager &AM) { + + bool modified = StripDebugInfo(M); + + return PreservedAnalyses::all(); + +} \ No newline at end of file From 5e5886eb129f79a55ce1c16389b7b9b971e0d237 Mon Sep 17 00:00:00 2001 From: Ana Marija Date: Tue, 28 Oct 2025 12:45:32 +0100 Subject: [PATCH 2/3] Added tests for new passes (dbg-counter & dbg-deleter) --- .gitignore | 2 +- llvm/lib/CMakeLists.txt | 2 +- llvm/test/Transforms/Util/dbgi-counter-1.ll | 91 +++++++++ llvm/test/Transforms/Util/dbgi-counter-2.ll | 183 +++++++++++++++++ llvm/test/Transforms/Util/dbgi-deleter-1.ll | 109 +++++++++++ llvm/test/Transforms/Util/dbgi-deleter-2.ll | 206 ++++++++++++++++++++ 6 files changed, 591 insertions(+), 2 deletions(-) create mode 100644 llvm/test/Transforms/Util/dbgi-counter-1.ll create mode 100644 llvm/test/Transforms/Util/dbgi-counter-2.ll create mode 100644 llvm/test/Transforms/Util/dbgi-deleter-1.ll create mode 100644 llvm/test/Transforms/Util/dbgi-deleter-2.ll diff --git a/.gitignore b/.gitignore index 860b8ea12abd4..2fe0cdf332236 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,7 @@ /*/CMakeUserPresets.json # Nested build directory -/build* +/build* #==============================================================================# # Explicit files to ignore (only matches one). diff --git a/llvm/lib/CMakeLists.txt b/llvm/lib/CMakeLists.txt index a9432977718c6..7667a279bf504 100644 --- a/llvm/lib/CMakeLists.txt +++ b/llvm/lib/CMakeLists.txt @@ -68,6 +68,6 @@ else() add_llvm_component_group(NativeCodeGen) endif() -# Component post-processing +# Component post-processing LLVMBuildResolveComponentsLink() LLVMBuildGenerateCFragment(OUTPUT ${LLVMCONFIGLIBRARYDEPENDENCIESINC}) diff --git a/llvm/test/Transforms/Util/dbgi-counter-1.ll b/llvm/test/Transforms/Util/dbgi-counter-1.ll new file mode 100644 index 0000000000000..000436ff88623 --- /dev/null +++ b/llvm/test/Transforms/Util/dbgi-counter-1.ll @@ -0,0 +1,91 @@ +; RUN: opt -S -passes=dbg-counter < %s 2>&1 | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK: Function: foo +; CHECK-NEXT: #dbg_value: 0 +; CHECK-NEXT: #dbg_declare: 3 +; CHECK-NEXT: #dbg_assign: 0 + +define dso_local i32 @foo() #0 !dbg !10 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + %3 = alloca i32, align 4 + #dbg_declare(ptr %1, !16, !DIExpression(), !17) + store i32 21, ptr %1, align 4, !dbg !17 + #dbg_declare(ptr %2, !18, !DIExpression(), !19) + store i32 22, ptr %2, align 4, !dbg !19 + #dbg_declare(ptr %3, !20, !DIExpression(), !22) + store i32 23, ptr %3, align 4, !dbg !22 + %4 = load i32, ptr %1, align 4, !dbg !23 + store i32 %4, ptr %3, align 4, !dbg !24 + %5 = load i32, ptr %2, align 4, !dbg !25 + store i32 %5, ptr %1, align 4, !dbg !26 + %6 = load i32, ptr %1, align 4, !dbg !27 + %7 = load i32, ptr %2, align 4, !dbg !28 + %8 = add nsw i32 %6, %7, !dbg !29 + ret i32 %8, !dbg !30 +} + +; Function Attrs: noinline nounwind optnone uwtable + +; CHECK: Function: main +; CHECK-NEXT: #dbg_value: 0 +; CHECK-NEXT: #dbg_declare: 1 +; CHECK-NEXT: #dbg_assign: 0 + +define dso_local i32 @main() #0 !dbg !31 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + store i32 0, ptr %1, align 4 + #dbg_declare(ptr %2, !32, !DIExpression(), !33) + %3 = call i32 @foo(), !dbg !34 + store i32 %3, ptr %2, align 4, !dbg !33 + %4 = load i32, ptr %2, align 4, !dbg !35 + ret i32 %4, !dbg !36 +} + +attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8} +!llvm.ident = !{!9} + +!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 22.0.0git (https://github.com/anamaoh/llvm-project.git 782a91e1fc94d9c82495f60afc5ed5edd72de776)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "/home/ana-marija/Documents/foo.c", directory: "/home/ana-marija/Desktop/LLVM/llvm-project", checksumkind: CSK_MD5, checksum: "22bc4641d6e8e63df371a758d86cafff") +!2 = !{i32 7, !"Dwarf Version", i32 5} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = !{i32 1, !"wchar_size", i32 4} +!5 = !{i32 8, !"PIC Level", i32 2} +!6 = !{i32 7, !"PIE Level", i32 2} +!7 = !{i32 7, !"uwtable", i32 2} +!8 = !{i32 7, !"frame-pointer", i32 2} +!9 = !{!"clang version 22.0.0git (https://github.com/anamaoh/llvm-project.git 782a91e1fc94d9c82495f60afc5ed5edd72de776)"} +!10 = distinct !DISubprogram(name: "foo", scope: !11, file: !11, line: 1, type: !12, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !15) +!11 = !DIFile(filename: "Documents/foo.c", directory: "/home/ana-marija", checksumkind: CSK_MD5, checksum: "22bc4641d6e8e63df371a758d86cafff") +!12 = !DISubroutineType(types: !13) +!13 = !{!14} +!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!15 = !{} +!16 = !DILocalVariable(name: "X", scope: !10, file: !11, line: 2, type: !14) +!17 = !DILocation(line: 2, column: 6, scope: !10) +!18 = !DILocalVariable(name: "Y", scope: !10, file: !11, line: 3, type: !14) +!19 = !DILocation(line: 3, column: 6, scope: !10) +!20 = !DILocalVariable(name: "Z", scope: !21, file: !11, line: 5, type: !14) +!21 = distinct !DILexicalBlock(scope: !10, file: !11, line: 4, column: 2) +!22 = !DILocation(line: 5, column: 8, scope: !21) +!23 = !DILocation(line: 6, column: 8, scope: !21) +!24 = !DILocation(line: 6, column: 6, scope: !21) +!25 = !DILocation(line: 8, column: 6, scope: !10) +!26 = !DILocation(line: 8, column: 4, scope: !10) +!27 = !DILocation(line: 9, column: 9, scope: !10) +!28 = !DILocation(line: 9, column: 13, scope: !10) +!29 = !DILocation(line: 9, column: 11, scope: !10) +!30 = !DILocation(line: 9, column: 2, scope: !10) +!31 = distinct !DISubprogram(name: "main", scope: !11, file: !11, line: 12, type: !12, scopeLine: 12, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !15) +!32 = !DILocalVariable(name: "A", scope: !31, file: !11, line: 13, type: !14) +!33 = !DILocation(line: 13, column: 6, scope: !31) +!34 = !DILocation(line: 13, column: 10, scope: !31) +!35 = !DILocation(line: 14, column: 9, scope: !31) +!36 = !DILocation(line: 14, column: 2, scope: !31) \ No newline at end of file diff --git a/llvm/test/Transforms/Util/dbgi-counter-2.ll b/llvm/test/Transforms/Util/dbgi-counter-2.ll new file mode 100644 index 0000000000000..69756bcf80b08 --- /dev/null +++ b/llvm/test/Transforms/Util/dbgi-counter-2.ll @@ -0,0 +1,183 @@ +; RUN: opt -S -passes=dbg-counter < %s 2>&1 | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK: Function: main +; CHECK-NEXT: #dbg_value: 30 +; CHECK-NEXT: #dbg_declare: 0 +; CHECK-NEXT: #dbg_assign: 0 + +%struct.student = type { [50 x i8], i32, float } + +@s = dso_local local_unnamed_addr global [10 x %struct.student] zeroinitializer, align 16, !dbg !0 + +define dso_local noundef i32 @main() local_unnamed_addr #0 !dbg !28 { + #dbg_value(i32 2, !32, !DIExpression(), !43) + #dbg_value(i32 3, !33, !DIExpression(), !43) + #dbg_value(i32 4, !34, !DIExpression(), !43) + #dbg_value(ptr poison, !35, !DIExpression(), !43) + #dbg_value(ptr poison, !37, !DIExpression(), !43) + #dbg_value(ptr poison, !38, !DIExpression(), !43) + #dbg_value(i32 5, !34, !DIExpression(), !43) + #dbg_value(i32 0, !39, !DIExpression(), !44) + #dbg_value(i64 0, !39, !DIExpression(), !44) + store i32 6, ptr getelementptr inbounds nuw (i8, ptr @s, i64 52), align 4, !dbg !45, !tbaa !48 + #dbg_value(i64 1, !39, !DIExpression(), !44) + store i32 7, ptr getelementptr inbounds nuw (i8, ptr @s, i64 112), align 16, !dbg !54, !tbaa !48 + #dbg_value(i64 2, !39, !DIExpression(), !44) + store i32 8, ptr getelementptr inbounds nuw (i8, ptr @s, i64 172), align 4, !dbg !55, !tbaa !48 + #dbg_value(i64 3, !39, !DIExpression(), !44) + store i32 9, ptr getelementptr inbounds nuw (i8, ptr @s, i64 232), align 8, !dbg !56, !tbaa !48 + #dbg_value(i64 4, !39, !DIExpression(), !44) + store i32 10, ptr getelementptr inbounds nuw (i8, ptr @s, i64 292), align 4, !dbg !57, !tbaa !48 + #dbg_value(i64 5, !39, !DIExpression(), !44) + store i32 11, ptr getelementptr inbounds nuw (i8, ptr @s, i64 352), align 16, !dbg !58, !tbaa !48 + #dbg_value(i64 6, !39, !DIExpression(), !44) + store i32 12, ptr getelementptr inbounds nuw (i8, ptr @s, i64 412), align 4, !dbg !59, !tbaa !48 + #dbg_value(i64 7, !39, !DIExpression(), !44) + store i32 13, ptr getelementptr inbounds nuw (i8, ptr @s, i64 472), align 8, !dbg !60, !tbaa !48 + #dbg_value(i64 8, !39, !DIExpression(), !44) + store i32 14, ptr getelementptr inbounds nuw (i8, ptr @s, i64 532), align 4, !dbg !61, !tbaa !48 + #dbg_value(i64 9, !39, !DIExpression(), !44) + store i32 15, ptr getelementptr inbounds nuw (i8, ptr @s, i64 592), align 16, !dbg !62, !tbaa !48 + #dbg_value(i64 10, !39, !DIExpression(), !44) + #dbg_value(i64 0, !41, !DIExpression(), !63) + %1 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 56), align 8, !dbg !64, !tbaa !67 + %2 = fadd float %1, 1.000000e+00, !dbg !68 + store float %2, ptr getelementptr inbounds nuw (i8, ptr @s, i64 56), align 8, !dbg !69, !tbaa !67 + #dbg_value(i64 1, !41, !DIExpression(), !63) + %3 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 116), align 4, !dbg !64, !tbaa !67 + %4 = fadd float %3, 1.000000e+00, !dbg !70 + store float %4, ptr getelementptr inbounds nuw (i8, ptr @s, i64 116), align 4, !dbg !71, !tbaa !67 + #dbg_value(i64 2, !41, !DIExpression(), !63) + %5 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 176), align 16, !dbg !64, !tbaa !67 + %6 = fadd float %5, 1.000000e+00, !dbg !72 + store float %6, ptr getelementptr inbounds nuw (i8, ptr @s, i64 176), align 16, !dbg !73, !tbaa !67 + #dbg_value(i64 3, !41, !DIExpression(), !63) + %7 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 236), align 4, !dbg !64, !tbaa !67 + %8 = fadd float %7, 1.000000e+00, !dbg !74 + store float %8, ptr getelementptr inbounds nuw (i8, ptr @s, i64 236), align 4, !dbg !75, !tbaa !67 + #dbg_value(i64 4, !41, !DIExpression(), !63) + %9 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 296), align 8, !dbg !64, !tbaa !67 + %10 = fadd float %9, 1.000000e+00, !dbg !76 + store float %10, ptr getelementptr inbounds nuw (i8, ptr @s, i64 296), align 8, !dbg !77, !tbaa !67 + #dbg_value(i64 5, !41, !DIExpression(), !63) + %11 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 356), align 4, !dbg !64, !tbaa !67 + %12 = fadd float %11, 1.000000e+00, !dbg !78 + store float %12, ptr getelementptr inbounds nuw (i8, ptr @s, i64 356), align 4, !dbg !79, !tbaa !67 + #dbg_value(i64 6, !41, !DIExpression(), !63) + %13 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 416), align 16, !dbg !64, !tbaa !67 + %14 = fadd float %13, 1.000000e+00, !dbg !80 + store float %14, ptr getelementptr inbounds nuw (i8, ptr @s, i64 416), align 16, !dbg !81, !tbaa !67 + #dbg_value(i64 7, !41, !DIExpression(), !63) + %15 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 476), align 4, !dbg !64, !tbaa !67 + %16 = fadd float %15, 1.000000e+00, !dbg !82 + store float %16, ptr getelementptr inbounds nuw (i8, ptr @s, i64 476), align 4, !dbg !83, !tbaa !67 + #dbg_value(i64 8, !41, !DIExpression(), !63) + %17 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 536), align 8, !dbg !64, !tbaa !67 + %18 = fadd float %17, 1.000000e+00, !dbg !84 + store float %18, ptr getelementptr inbounds nuw (i8, ptr @s, i64 536), align 8, !dbg !85, !tbaa !67 + #dbg_value(i64 9, !41, !DIExpression(), !63) + %19 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 596), align 4, !dbg !64, !tbaa !67 + %20 = fadd float %19, 1.000000e+00, !dbg !86 + store float %20, ptr getelementptr inbounds nuw (i8, ptr @s, i64 596), align 4, !dbg !87, !tbaa !67 + #dbg_value(i64 10, !41, !DIExpression(), !63) + ret i32 0, !dbg !88 +} + +attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!20, !21, !22, !23, !24, !25, !26} +!llvm.ident = !{!27} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "s", scope: !2, file: !5, line: 8, type: !6, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 22.0.0git (https://github.com/anamaoh/llvm-project.git 782a91e1fc94d9c82495f60afc5ed5edd72de776)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None) +!3 = !DIFile(filename: "/home/ana-marija/Documents/load.cpp", directory: "/home/ana-marija/Desktop/LLVM/llvm-project", checksumkind: CSK_MD5, checksum: "1bce1e274606359bd3ee799e44db5ab7") +!4 = !{!0} +!5 = !DIFile(filename: "Documents/load.cpp", directory: "/home/ana-marija", checksumkind: CSK_MD5, checksum: "1bce1e274606359bd3ee799e44db5ab7") +!6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 4800, elements: !18) +!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "student", file: !5, line: 3, size: 480, flags: DIFlagTypePassByValue, elements: !8, identifier: "_ZTS7student") +!8 = !{!9, !14, !16} +!9 = !DIDerivedType(tag: DW_TAG_member, name: "name", scope: !7, file: !5, line: 5, baseType: !10, size: 400) +!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 400, elements: !12) +!11 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!12 = !{!13} +!13 = !DISubrange(count: 50) +!14 = !DIDerivedType(tag: DW_TAG_member, name: "roll", scope: !7, file: !5, line: 6, baseType: !15, size: 32, offset: 416) +!15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!16 = !DIDerivedType(tag: DW_TAG_member, name: "marks", scope: !7, file: !5, line: 7, baseType: !17, size: 32, offset: 448) +!17 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float) +!18 = !{!19} +!19 = !DISubrange(count: 10) +!20 = !{i32 7, !"Dwarf Version", i32 5} +!21 = !{i32 2, !"Debug Info Version", i32 3} +!22 = !{i32 1, !"wchar_size", i32 4} +!23 = !{i32 8, !"PIC Level", i32 2} +!24 = !{i32 7, !"PIE Level", i32 2} +!25 = !{i32 7, !"uwtable", i32 2} +!26 = !{i32 7, !"debug-info-assignment-tracking", i1 true} +!27 = !{!"clang version 22.0.0git (https://github.com/anamaoh/llvm-project.git 782a91e1fc94d9c82495f60afc5ed5edd72de776)"} +!28 = distinct !DISubprogram(name: "main", scope: !5, file: !5, line: 10, type: !29, scopeLine: 11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !31, keyInstructions: true) +!29 = !DISubroutineType(types: !30) +!30 = !{!15} +!31 = !{!32, !33, !34, !35, !37, !38, !39, !41} +!32 = !DILocalVariable(name: "x", scope: !28, file: !5, line: 12, type: !15) +!33 = !DILocalVariable(name: "y", scope: !28, file: !5, line: 12, type: !15) +!34 = !DILocalVariable(name: "z", scope: !28, file: !5, line: 12, type: !15) +!35 = !DILocalVariable(name: "px", scope: !28, file: !5, line: 13, type: !36) +!36 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64) +!37 = !DILocalVariable(name: "py", scope: !28, file: !5, line: 13, type: !36) +!38 = !DILocalVariable(name: "pz", scope: !28, file: !5, line: 13, type: !36) +!39 = !DILocalVariable(name: "i", scope: !40, file: !5, line: 17, type: !15) +!40 = distinct !DILexicalBlock(scope: !28, file: !5, line: 17, column: 5) +!41 = !DILocalVariable(name: "i", scope: !42, file: !5, line: 23, type: !15) +!42 = distinct !DILexicalBlock(scope: !28, file: !5, line: 23, column: 5) +!43 = !DILocation(line: 0, scope: !28) +!44 = !DILocation(line: 0, scope: !40) +!45 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 11, atomRank: 1) +!46 = distinct !DILexicalBlock(scope: !47, file: !5, line: 18, column: 5) +!47 = distinct !DILexicalBlock(scope: !40, file: !5, line: 17, column: 5) +!48 = !{!49, !52, i64 52} +!49 = !{!"_ZTS7student", !50, i64 0, !52, i64 52, !53, i64 56} +!50 = !{!"omnipotent char", !51, i64 0} +!51 = !{!"Simple C++ TBAA"} +!52 = !{!"int", !50, i64 0} +!53 = !{!"float", !50, i64 0} +!54 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 26, atomRank: 1) +!55 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 29, atomRank: 1) +!56 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 32, atomRank: 1) +!57 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 35, atomRank: 1) +!58 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 38, atomRank: 1) +!59 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 41, atomRank: 1) +!60 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 44, atomRank: 1) +!61 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 47, atomRank: 1) +!62 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 50, atomRank: 1) +!63 = !DILocation(line: 0, scope: !42) +!64 = !DILocation(line: 25, column: 19, scope: !65) +!65 = distinct !DILexicalBlock(scope: !66, file: !5, line: 24, column: 5) +!66 = distinct !DILexicalBlock(scope: !42, file: !5, line: 23, column: 5) +!67 = !{!49, !53, i64 56} +!68 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 17, atomRank: 2) +!69 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 17, atomRank: 1) +!70 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 53, atomRank: 2) +!71 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 53, atomRank: 1) +!72 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 57, atomRank: 2) +!73 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 57, atomRank: 1) +!74 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 61, atomRank: 2) +!75 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 61, atomRank: 1) +!76 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 65, atomRank: 2) +!77 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 65, atomRank: 1) +!78 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 69, atomRank: 2) +!79 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 69, atomRank: 1) +!80 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 73, atomRank: 2) +!81 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 73, atomRank: 1) +!82 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 77, atomRank: 2) +!83 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 77, atomRank: 1) +!84 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 81, atomRank: 2) +!85 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 81, atomRank: 1) +!86 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 85, atomRank: 2) +!87 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 85, atomRank: 1) +!88 = !DILocation(line: 28, column: 5, scope: !28, atomGroup: 21, atomRank: 1) \ No newline at end of file diff --git a/llvm/test/Transforms/Util/dbgi-deleter-1.ll b/llvm/test/Transforms/Util/dbgi-deleter-1.ll new file mode 100644 index 0000000000000..e9e2f99487351 --- /dev/null +++ b/llvm/test/Transforms/Util/dbgi-deleter-1.ll @@ -0,0 +1,109 @@ +; RUN: opt -S -passes=dbg-deleter < %s 2>&1 | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + + +define dso_local i32 @foo() #0 !dbg !10 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + %3 = alloca i32, align 4 + #dbg_declare(ptr %1, !16, !DIExpression(), !17) + store i32 21, ptr %1, align 4, !dbg !17 + #dbg_declare(ptr %2, !18, !DIExpression(), !19) + store i32 22, ptr %2, align 4, !dbg !19 + #dbg_declare(ptr %3, !20, !DIExpression(), !22) + store i32 23, ptr %3, align 4, !dbg !22 + %4 = load i32, ptr %1, align 4, !dbg !23 + store i32 %4, ptr %3, align 4, !dbg !24 + %5 = load i32, ptr %2, align 4, !dbg !25 + store i32 %5, ptr %1, align 4, !dbg !26 + %6 = load i32, ptr %1, align 4, !dbg !27 + %7 = load i32, ptr %2, align 4, !dbg !28 + %8 = add nsw i32 %6, %7, !dbg !29 + ret i32 %8, !dbg !30 + +; CHECK: @foo() +; CHECK-NOT: #dbg_declare +; CHECK-NOT: !dbg +; CHECK: ret i32 + +} + +; Function Attrs: noinline nounwind optnone uwtable + +define dso_local i32 @main() #0 !dbg !31 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + store i32 0, ptr %1, align 4 + #dbg_declare(ptr %2, !32, !DIExpression(), !33) + %3 = call i32 @foo(), !dbg !34 + store i32 %3, ptr %2, align 4, !dbg !33 + %4 = load i32, ptr %2, align 4, !dbg !35 + ret i32 %4, !dbg !36 + +; CHECK: @main() +; CHECK-NOT: #dbg_declare +; CHECK: ret i32 + +} + +attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8} +!llvm.ident = !{!9} + +; CHECK: attributes #0 +; CHECK-NOT: !llvm.dbg.cu +; CHECK: !llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6} +; CHECK: !llvm.ident = !{!7} + + +!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 22.0.0git (https://github.com/anamaoh/llvm-project.git 782a91e1fc94d9c82495f60afc5ed5edd72de776)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "/home/ana-marija/Documents/foo.c", directory: "/home/ana-marija/Desktop/LLVM/llvm-project", checksumkind: CSK_MD5, checksum: "22bc4641d6e8e63df371a758d86cafff") +!2 = !{i32 7, !"Dwarf Version", i32 5} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = !{i32 1, !"wchar_size", i32 4} +!5 = !{i32 8, !"PIC Level", i32 2} +!6 = !{i32 7, !"PIE Level", i32 2} +!7 = !{i32 7, !"uwtable", i32 2} +!8 = !{i32 7, !"frame-pointer", i32 2} +!9 = !{!"clang version 22.0.0git (https://github.com/anamaoh/llvm-project.git 782a91e1fc94d9c82495f60afc5ed5edd72de776)"} +!10 = distinct !DISubprogram(name: "foo", scope: !11, file: !11, line: 1, type: !12, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !15) +!11 = !DIFile(filename: "Documents/foo.c", directory: "/home/ana-marija", checksumkind: CSK_MD5, checksum: "22bc4641d6e8e63df371a758d86cafff") +!12 = !DISubroutineType(types: !13) +!13 = !{!14} +!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!15 = !{} +!16 = !DILocalVariable(name: "X", scope: !10, file: !11, line: 2, type: !14) +!17 = !DILocation(line: 2, column: 6, scope: !10) +!18 = !DILocalVariable(name: "Y", scope: !10, file: !11, line: 3, type: !14) +!19 = !DILocation(line: 3, column: 6, scope: !10) +!20 = !DILocalVariable(name: "Z", scope: !21, file: !11, line: 5, type: !14) +!21 = distinct !DILexicalBlock(scope: !10, file: !11, line: 4, column: 2) +!22 = !DILocation(line: 5, column: 8, scope: !21) +!23 = !DILocation(line: 6, column: 8, scope: !21) +!24 = !DILocation(line: 6, column: 6, scope: !21) +!25 = !DILocation(line: 8, column: 6, scope: !10) +!26 = !DILocation(line: 8, column: 4, scope: !10) +!27 = !DILocation(line: 9, column: 9, scope: !10) +!28 = !DILocation(line: 9, column: 13, scope: !10) +!29 = !DILocation(line: 9, column: 11, scope: !10) +!30 = !DILocation(line: 9, column: 2, scope: !10) +!31 = distinct !DISubprogram(name: "main", scope: !11, file: !11, line: 12, type: !12, scopeLine: 12, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !15) +!32 = !DILocalVariable(name: "A", scope: !31, file: !11, line: 13, type: !14) +!33 = !DILocation(line: 13, column: 6, scope: !31) +!34 = !DILocation(line: 13, column: 10, scope: !31) +!35 = !DILocation(line: 14, column: 9, scope: !31) +!36 = !DILocation(line: 14, column: 2, scope: !31) + + +; CHECK-NOT: !DICompileUnit +; CHECK-NOT: !DIFile +; CHECK-NOT: !DISubprogram +; CHECK-NOT: !DIFile +; CHECK-NOT: !DISubroutineType +; CHECK-NOT: !DIBasicType +; CHECK-NOT: !DILocalVariable +; CHECK-NOT: !DILocation \ No newline at end of file diff --git a/llvm/test/Transforms/Util/dbgi-deleter-2.ll b/llvm/test/Transforms/Util/dbgi-deleter-2.ll new file mode 100644 index 0000000000000..a34c642f351bb --- /dev/null +++ b/llvm/test/Transforms/Util/dbgi-deleter-2.ll @@ -0,0 +1,206 @@ +; RUN: opt -S -passes=dbg-deleter < %s 2>&1 | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +%struct.student = type { [50 x i8], i32, float } + +@s = dso_local local_unnamed_addr global [10 x %struct.student] zeroinitializer, align 16, !dbg !0 + +define dso_local noundef i32 @main() local_unnamed_addr #0 !dbg !28 { + #dbg_value(i32 2, !32, !DIExpression(), !43) + #dbg_value(i32 3, !33, !DIExpression(), !43) + #dbg_value(i32 4, !34, !DIExpression(), !43) + #dbg_value(ptr poison, !35, !DIExpression(), !43) + #dbg_value(ptr poison, !37, !DIExpression(), !43) + #dbg_value(ptr poison, !38, !DIExpression(), !43) + #dbg_value(i32 5, !34, !DIExpression(), !43) + #dbg_value(i32 0, !39, !DIExpression(), !44) + #dbg_value(i64 0, !39, !DIExpression(), !44) + store i32 6, ptr getelementptr inbounds nuw (i8, ptr @s, i64 52), align 4, !dbg !45, !tbaa !48 + #dbg_value(i64 1, !39, !DIExpression(), !44) + store i32 7, ptr getelementptr inbounds nuw (i8, ptr @s, i64 112), align 16, !dbg !54, !tbaa !48 + #dbg_value(i64 2, !39, !DIExpression(), !44) + store i32 8, ptr getelementptr inbounds nuw (i8, ptr @s, i64 172), align 4, !dbg !55, !tbaa !48 + #dbg_value(i64 3, !39, !DIExpression(), !44) + store i32 9, ptr getelementptr inbounds nuw (i8, ptr @s, i64 232), align 8, !dbg !56, !tbaa !48 + #dbg_value(i64 4, !39, !DIExpression(), !44) + store i32 10, ptr getelementptr inbounds nuw (i8, ptr @s, i64 292), align 4, !dbg !57, !tbaa !48 + #dbg_value(i64 5, !39, !DIExpression(), !44) + store i32 11, ptr getelementptr inbounds nuw (i8, ptr @s, i64 352), align 16, !dbg !58, !tbaa !48 + #dbg_value(i64 6, !39, !DIExpression(), !44) + store i32 12, ptr getelementptr inbounds nuw (i8, ptr @s, i64 412), align 4, !dbg !59, !tbaa !48 + #dbg_value(i64 7, !39, !DIExpression(), !44) + store i32 13, ptr getelementptr inbounds nuw (i8, ptr @s, i64 472), align 8, !dbg !60, !tbaa !48 + #dbg_value(i64 8, !39, !DIExpression(), !44) + store i32 14, ptr getelementptr inbounds nuw (i8, ptr @s, i64 532), align 4, !dbg !61, !tbaa !48 + #dbg_value(i64 9, !39, !DIExpression(), !44) + store i32 15, ptr getelementptr inbounds nuw (i8, ptr @s, i64 592), align 16, !dbg !62, !tbaa !48 + #dbg_value(i64 10, !39, !DIExpression(), !44) + #dbg_value(i64 0, !41, !DIExpression(), !63) + %1 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 56), align 8, !dbg !64, !tbaa !67 + %2 = fadd float %1, 1.000000e+00, !dbg !68 + store float %2, ptr getelementptr inbounds nuw (i8, ptr @s, i64 56), align 8, !dbg !69, !tbaa !67 + #dbg_value(i64 1, !41, !DIExpression(), !63) + %3 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 116), align 4, !dbg !64, !tbaa !67 + %4 = fadd float %3, 1.000000e+00, !dbg !70 + store float %4, ptr getelementptr inbounds nuw (i8, ptr @s, i64 116), align 4, !dbg !71, !tbaa !67 + #dbg_value(i64 2, !41, !DIExpression(), !63) + %5 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 176), align 16, !dbg !64, !tbaa !67 + %6 = fadd float %5, 1.000000e+00, !dbg !72 + store float %6, ptr getelementptr inbounds nuw (i8, ptr @s, i64 176), align 16, !dbg !73, !tbaa !67 + #dbg_value(i64 3, !41, !DIExpression(), !63) + %7 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 236), align 4, !dbg !64, !tbaa !67 + %8 = fadd float %7, 1.000000e+00, !dbg !74 + store float %8, ptr getelementptr inbounds nuw (i8, ptr @s, i64 236), align 4, !dbg !75, !tbaa !67 + #dbg_value(i64 4, !41, !DIExpression(), !63) + %9 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 296), align 8, !dbg !64, !tbaa !67 + %10 = fadd float %9, 1.000000e+00, !dbg !76 + store float %10, ptr getelementptr inbounds nuw (i8, ptr @s, i64 296), align 8, !dbg !77, !tbaa !67 + #dbg_value(i64 5, !41, !DIExpression(), !63) + %11 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 356), align 4, !dbg !64, !tbaa !67 + %12 = fadd float %11, 1.000000e+00, !dbg !78 + store float %12, ptr getelementptr inbounds nuw (i8, ptr @s, i64 356), align 4, !dbg !79, !tbaa !67 + #dbg_value(i64 6, !41, !DIExpression(), !63) + %13 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 416), align 16, !dbg !64, !tbaa !67 + %14 = fadd float %13, 1.000000e+00, !dbg !80 + store float %14, ptr getelementptr inbounds nuw (i8, ptr @s, i64 416), align 16, !dbg !81, !tbaa !67 + #dbg_value(i64 7, !41, !DIExpression(), !63) + %15 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 476), align 4, !dbg !64, !tbaa !67 + %16 = fadd float %15, 1.000000e+00, !dbg !82 + store float %16, ptr getelementptr inbounds nuw (i8, ptr @s, i64 476), align 4, !dbg !83, !tbaa !67 + #dbg_value(i64 8, !41, !DIExpression(), !63) + %17 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 536), align 8, !dbg !64, !tbaa !67 + %18 = fadd float %17, 1.000000e+00, !dbg !84 + store float %18, ptr getelementptr inbounds nuw (i8, ptr @s, i64 536), align 8, !dbg !85, !tbaa !67 + #dbg_value(i64 9, !41, !DIExpression(), !63) + %19 = load float, ptr getelementptr inbounds nuw (i8, ptr @s, i64 596), align 4, !dbg !64, !tbaa !67 + %20 = fadd float %19, 1.000000e+00, !dbg !86 + store float %20, ptr getelementptr inbounds nuw (i8, ptr @s, i64 596), align 4, !dbg !87, !tbaa !67 + #dbg_value(i64 10, !41, !DIExpression(), !63) + ret i32 0, !dbg !88 + +; CHECK: @main() +; CHECK-NOT: #dbg_value +; CHECK-NOT: !dbg +; CHECK: ret i32 + +} + +attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!20, !21, !22, !23, !24, !25, !26} +!llvm.ident = !{!27} + +; CHECK: attributes #0 +; CHECK-NOT: !llvm.dbg.cu +; CHECK: !llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6} +; CHECK: !llvm.ident = !{!7} + + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "s", scope: !2, file: !5, line: 8, type: !6, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 22.0.0git (https://github.com/anamaoh/llvm-project.git 782a91e1fc94d9c82495f60afc5ed5edd72de776)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None) +!3 = !DIFile(filename: "/home/ana-marija/Documents/load.cpp", directory: "/home/ana-marija/Desktop/LLVM/llvm-project", checksumkind: CSK_MD5, checksum: "1bce1e274606359bd3ee799e44db5ab7") +!4 = !{!0} +!5 = !DIFile(filename: "Documents/load.cpp", directory: "/home/ana-marija", checksumkind: CSK_MD5, checksum: "1bce1e274606359bd3ee799e44db5ab7") +!6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 4800, elements: !18) +!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "student", file: !5, line: 3, size: 480, flags: DIFlagTypePassByValue, elements: !8, identifier: "_ZTS7student") +!8 = !{!9, !14, !16} +!9 = !DIDerivedType(tag: DW_TAG_member, name: "name", scope: !7, file: !5, line: 5, baseType: !10, size: 400) +!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 400, elements: !12) +!11 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!12 = !{!13} +!13 = !DISubrange(count: 50) +!14 = !DIDerivedType(tag: DW_TAG_member, name: "roll", scope: !7, file: !5, line: 6, baseType: !15, size: 32, offset: 416) +!15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!16 = !DIDerivedType(tag: DW_TAG_member, name: "marks", scope: !7, file: !5, line: 7, baseType: !17, size: 32, offset: 448) +!17 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float) +!18 = !{!19} +!19 = !DISubrange(count: 10) +!20 = !{i32 7, !"Dwarf Version", i32 5} +!21 = !{i32 2, !"Debug Info Version", i32 3} +!22 = !{i32 1, !"wchar_size", i32 4} +!23 = !{i32 8, !"PIC Level", i32 2} +!24 = !{i32 7, !"PIE Level", i32 2} +!25 = !{i32 7, !"uwtable", i32 2} +!26 = !{i32 7, !"debug-info-assignment-tracking", i1 true} +!27 = !{!"clang version 22.0.0git (https://github.com/anamaoh/llvm-project.git 782a91e1fc94d9c82495f60afc5ed5edd72de776)"} +!28 = distinct !DISubprogram(name: "main", scope: !5, file: !5, line: 10, type: !29, scopeLine: 11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !31, keyInstructions: true) +!29 = !DISubroutineType(types: !30) +!30 = !{!15} +!31 = !{!32, !33, !34, !35, !37, !38, !39, !41} +!32 = !DILocalVariable(name: "x", scope: !28, file: !5, line: 12, type: !15) +!33 = !DILocalVariable(name: "y", scope: !28, file: !5, line: 12, type: !15) +!34 = !DILocalVariable(name: "z", scope: !28, file: !5, line: 12, type: !15) +!35 = !DILocalVariable(name: "px", scope: !28, file: !5, line: 13, type: !36) +!36 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64) +!37 = !DILocalVariable(name: "py", scope: !28, file: !5, line: 13, type: !36) +!38 = !DILocalVariable(name: "pz", scope: !28, file: !5, line: 13, type: !36) +!39 = !DILocalVariable(name: "i", scope: !40, file: !5, line: 17, type: !15) +!40 = distinct !DILexicalBlock(scope: !28, file: !5, line: 17, column: 5) +!41 = !DILocalVariable(name: "i", scope: !42, file: !5, line: 23, type: !15) +!42 = distinct !DILexicalBlock(scope: !28, file: !5, line: 23, column: 5) +!43 = !DILocation(line: 0, scope: !28) +!44 = !DILocation(line: 0, scope: !40) +!45 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 11, atomRank: 1) +!46 = distinct !DILexicalBlock(scope: !47, file: !5, line: 18, column: 5) +!47 = distinct !DILexicalBlock(scope: !40, file: !5, line: 17, column: 5) +!48 = !{!49, !52, i64 52} +!49 = !{!"_ZTS7student", !50, i64 0, !52, i64 52, !53, i64 56} +!50 = !{!"omnipotent char", !51, i64 0} +!51 = !{!"Simple C++ TBAA"} +!52 = !{!"int", !50, i64 0} +!53 = !{!"float", !50, i64 0} +!54 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 26, atomRank: 1) +!55 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 29, atomRank: 1) +!56 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 32, atomRank: 1) +!57 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 35, atomRank: 1) +!58 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 38, atomRank: 1) +!59 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 41, atomRank: 1) +!60 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 44, atomRank: 1) +!61 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 47, atomRank: 1) +!62 = !DILocation(line: 19, column: 19, scope: !46, atomGroup: 50, atomRank: 1) +!63 = !DILocation(line: 0, scope: !42) +!64 = !DILocation(line: 25, column: 19, scope: !65) +!65 = distinct !DILexicalBlock(scope: !66, file: !5, line: 24, column: 5) +!66 = distinct !DILexicalBlock(scope: !42, file: !5, line: 23, column: 5) +!67 = !{!49, !53, i64 56} +!68 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 17, atomRank: 2) +!69 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 17, atomRank: 1) +!70 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 53, atomRank: 2) +!71 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 53, atomRank: 1) +!72 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 57, atomRank: 2) +!73 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 57, atomRank: 1) +!74 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 61, atomRank: 2) +!75 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 61, atomRank: 1) +!76 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 65, atomRank: 2) +!77 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 65, atomRank: 1) +!78 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 69, atomRank: 2) +!79 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 69, atomRank: 1) +!80 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 73, atomRank: 2) +!81 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 73, atomRank: 1) +!82 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 77, atomRank: 2) +!83 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 77, atomRank: 1) +!84 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 81, atomRank: 2) +!85 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 81, atomRank: 1) +!86 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 85, atomRank: 2) +!87 = !DILocation(line: 25, column: 19, scope: !65, atomGroup: 85, atomRank: 1) +!88 = !DILocation(line: 28, column: 5, scope: !28, atomGroup: 21, atomRank: 1) + + +; CHECK-NOT: !DICompileUnit +; CHECK-NOT: !DIFile +; CHECK-NOT: !DISubprogram +; CHECK-NOT: !DIFile +; CHECK-NOT: !DISubroutineType +; CHECK-NOT: !DIBasicType +; CHECK-NOT: !DILocalVariable +; CHECK-NOT: !DILocation +; CHECK-NOT: !DIGlobalVariableExpression +; CHECK-NOT: !DIGlobalVariable +; CHECK-NOT: !DICompositeType +; CHECK-NOT: !DIDerivedType +; CHECK-NOT: !DISubrange +; CHECK-NOT: !DILexicalBlock \ No newline at end of file From d42e0d1f29126f0c16b88cd4b112683784f067e9 Mon Sep 17 00:00:00 2001 From: Ana Marija Date: Wed, 29 Oct 2025 10:10:30 +0100 Subject: [PATCH 3/3] Included the DebugRecordDeleter pass into the -O2 pipeline. --- llvm/lib/Passes/PassBuilderPipelines.cpp | 9 ++++++++- llvm/lib/Transforms/Utils/DebugRecordCounter.cpp | 8 ++++---- llvm/lib/Transforms/Utils/DebugRecordDeleter.cpp | 4 ++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index fea0d255cc91a..912baacb64053 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -148,6 +148,8 @@ #include "llvm/Transforms/Vectorize/SLPVectorizer.h" #include "llvm/Transforms/Vectorize/VectorCombine.h" +#include "llvm/Transforms/Utils/DebugRecordDeleter.h" + using namespace llvm; namespace llvm { @@ -1676,6 +1678,11 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level, // Now add the optimization pipeline. MPM.addPass(buildModuleOptimizationPipeline(Level, Phase)); + // Include the DebugRecordDeleter passinto the -O2 pipeline. + if(Level == OptimizationLevel::O2) { + MPM.addPass(DebugRecordDeleterPass()); + } + if (PGOOpt && PGOOpt->PseudoProbeForProfiling && PGOOpt->Action == PGOOptions::SampleUse) MPM.addPass(PseudoProbeUpdatePass()); @@ -1684,7 +1691,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level, addAnnotationRemarksPass(MPM); if (isLTOPreLink(Phase)) - addRequiredLTOPreLinkPasses(MPM); + addRequiredLTOPreLinkPasses(MPM); return MPM; } diff --git a/llvm/lib/Transforms/Utils/DebugRecordCounter.cpp b/llvm/lib/Transforms/Utils/DebugRecordCounter.cpp index 9b05585f81123..2aa9fc2e044fe 100644 --- a/llvm/lib/Transforms/Utils/DebugRecordCounter.cpp +++ b/llvm/lib/Transforms/Utils/DebugRecordCounter.cpp @@ -18,14 +18,14 @@ PreservedAnalyses DebugRecordCounterPass::run(Module &M, ModuleAnalysisManager & for(Instruction &I : BB) { for(DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) { if(DVR.isDbgDeclare()) dbg_declares++; - if(DVR.isDbgValue()) dbg_values++; - if(DVR.isDbgAssign()) dbg_assigns++; + if(DVR.isDbgValue()) dbg_values++; + if(DVR.isDbgAssign()) dbg_assigns++; } } } - errs() << "\t#dbg_value: " << dbg_values << "\n"; + errs() << "\t#dbg_value: " << dbg_values << "\n"; errs() << "\t#dbg_declare: " << dbg_declares << "\n"; - errs() << "\t#dbg_assign: " << dbg_assigns << "\n"; + errs() << "\t#dbg_assign: " << dbg_assigns << "\n"; } return PreservedAnalyses::all(); } diff --git a/llvm/lib/Transforms/Utils/DebugRecordDeleter.cpp b/llvm/lib/Transforms/Utils/DebugRecordDeleter.cpp index 78a51054f05bf..9ac6a43a7a202 100644 --- a/llvm/lib/Transforms/Utils/DebugRecordDeleter.cpp +++ b/llvm/lib/Transforms/Utils/DebugRecordDeleter.cpp @@ -4,6 +4,10 @@ #include "llvm/IR/DebugInfo.h" #include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/Passes/PassBuilder.h" +#include "llvm/Passes/PassPlugin.h" +#include "llvm/Passes/OptimizationLevel.h" + using namespace llvm; // build/bin/opt -S /home/ana-marija/Documents/foo_00.ll -passes=dbg-deleter