2017-05-05 22:30:37 +00:00
|
|
|
//===- DebugInfo.cpp - Debug Information Helper Classes -------------------===//
|
2013-11-08 08:13:15 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-11-08 08:13:15 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the helper classes used to build and interpret debug
|
|
|
|
// information in LLVM IR form.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-11-01 22:18:52 +00:00
|
|
|
#include "llvm-c/DebugInfo.h"
|
2022-11-07 11:56:36 +00:00
|
|
|
#include "LLVMContextImpl.h"
|
2017-05-05 22:30:37 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2017-11-01 22:18:52 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2013-11-08 08:13:15 +00:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2017-05-05 22:30:37 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/IR/BasicBlock.h"
|
2013-11-08 08:13:15 +00:00
|
|
|
#include "llvm/IR/Constants.h"
|
2022-01-31 22:35:07 +01:00
|
|
|
#include "llvm/IR/DIBuilder.h"
|
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2017-05-05 22:30:37 +00:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
|
|
|
#include "llvm/IR/DebugLoc.h"
|
2023-06-07 12:33:43 +01:00
|
|
|
#include "llvm/IR/DebugProgramInstruction.h"
|
2017-05-05 22:30:37 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
2016-04-18 09:17:29 +00:00
|
|
|
#include "llvm/IR/GVMaterializer.h"
|
2017-05-05 22:30:37 +00:00
|
|
|
#include "llvm/IR/Instruction.h"
|
2013-11-08 08:13:15 +00:00
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
2017-05-05 22:30:37 +00:00
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Metadata.h"
|
2013-11-08 08:13:15 +00:00
|
|
|
#include "llvm/IR/Module.h"
|
2022-11-07 17:39:40 +00:00
|
|
|
#include "llvm/IR/PassManager.h"
|
2017-05-05 22:30:37 +00:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
2022-12-03 15:55:23 -06:00
|
|
|
#include <optional>
|
2017-05-05 22:30:37 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2013-11-08 08:13:15 +00:00
|
|
|
using namespace llvm;
|
2022-11-07 11:56:36 +00:00
|
|
|
using namespace llvm::at;
|
2013-11-08 08:13:15 +00:00
|
|
|
using namespace llvm::dwarf;
|
|
|
|
|
2024-01-15 17:46:56 +00:00
|
|
|
TinyPtrVector<DbgDeclareInst *> llvm::findDbgDeclares(Value *V) {
|
|
|
|
// This function is hot. Check whether the value has any metadata to avoid a
|
Handle #dbg_values in SROA. (#94070)
This patch properly handles #dbg_values in SROA by making sure that any
#dbg_values get moved to before a store just like #dbg_declares do, or
the #dbg_value is correctly updated with the right alloca after an
aggregate alloca is broken up.
The issue stems from swift where #dbg_values are emitted and not
dbg.declares, the SROA pass doesn't handle the #dbg_values correctly and
it causes them to all have undefs
If we look at this simple-ish testcase (This is all I could reduce it
down to, and I am still relatively bad at writing llvm IR by hand so I
apologize in advance):
```
%T4main1TV13TangentVectorV = type <{ %T4main1UV13TangentVectorV, [7 x i8], %T4main1UV13TangentVectorV }>
%T4main1UV13TangentVectorV = type <{ %T1M1SVySfG, [7 x i8], %T4main1VV13TangentVectorV }>
%T1M1SVySfG = type <{ ptr, %Ts4Int8V }>
%Ts4Int8V = type <{ i8 }>
%T4main1VV13TangentVectorV = type <{ %T1M1SVySfG }>
define hidden swiftcc void @"$s4main1TV13TangentVectorV1poiyA2E_AEtFZ"(ptr noalias nocapture sret(%T4main1TV13TangentVectorV) %0, ptr noalias nocapture dereferenceable(57) %1, ptr noalias nocapture dereferenceable(57) %2) #0 !dbg !44 {
entry:
%3 = alloca %T4main1VV13TangentVectorV
%4 = alloca %T4main1UV13TangentVectorV
%5 = alloca %T4main1VV13TangentVectorV
%6 = alloca %T4main1UV13TangentVectorV
%7 = alloca %T4main1VV13TangentVectorV
%8 = alloca %T4main1UV13TangentVectorV
%9 = alloca %T4main1VV13TangentVectorV
%10 = alloca %T4main1UV13TangentVectorV
call void @llvm.lifetime.start.p0(i64 9, ptr %3)
call void @llvm.lifetime.start.p0(i64 25, ptr %4)
call void @llvm.lifetime.start.p0(i64 9, ptr %5)
call void @llvm.lifetime.start.p0(i64 25, ptr %6)
call void @llvm.lifetime.start.p0(i64 9, ptr %7)
call void @llvm.lifetime.start.p0(i64 25, ptr %8)
call void @llvm.lifetime.start.p0(i64 9, ptr %9)
call void @llvm.lifetime.start.p0(i64 25, ptr %10)
%.u1 = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %1, i32 0, i32 0
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %.u1, i64 25, i1 false)
%.u11 = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %2, i32 0, i32 0
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %.u11, i64 25, i1 false)
call void @llvm.dbg.value(metadata ptr %4, metadata !62, metadata !DIExpression(DW_OP_deref)), !dbg !75
%.s = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %4, i32 0, i32 0
%.s.c = getelementptr inbounds %T1M1SVySfG, ptr %.s, i32 0, i32 0
%11 = load ptr, ptr %.s.c
%.s.b = getelementptr inbounds %T1M1SVySfG, ptr %.s, i32 0, i32 1
%.s.b._value = getelementptr inbounds %Ts4Int8V, ptr %.s.b, i32 0, i32 0
%12 = load i8, ptr %.s.b._value
%.s2 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %6, i32 0, i32 0
%.s2.c = getelementptr inbounds %T1M1SVySfG, ptr %.s2, i32 0, i32 0
%13 = load ptr, ptr %.s2.c
%.s2.b = getelementptr inbounds %T1M1SVySfG, ptr %.s2, i32 0, i32 1
%.s2.b._value = getelementptr inbounds %Ts4Int8V, ptr %.s2.b, i32 0, i32 0
%14 = load i8, ptr %.s2.b._value
%.v = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %4, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %.v, i64 9, i1 false)
%.v3 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %6, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %.v3, i64 9, i1 false)
%.s4 = getelementptr inbounds %T4main1VV13TangentVectorV, ptr %3, i32 0, i32 0
%.s4.c = getelementptr inbounds %T1M1SVySfG, ptr %.s4, i32 0, i32 0
%18 = load ptr, ptr %.s4.c
%.s5 = getelementptr inbounds %T4main1VV13TangentVectorV, ptr %5, i32 0, i32 0
%.s5.c = getelementptr inbounds %T1M1SVySfG, ptr %.s5, i32 0, i32 0
%20 = load ptr, ptr %.s5.c
%.u2 = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %1, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %.u2, i64 25, i1 false)
%.u26 = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %2, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %.u26, i64 25, i1 false)
%.s7 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %8, i32 0, i32 0
%.s7.c = getelementptr inbounds %T1M1SVySfG, ptr %.s7, i32 0, i32 0
%25 = load ptr, ptr %.s7.c
%.s7.b = getelementptr inbounds %T1M1SVySfG, ptr %.s7, i32 0, i32 1
%.s7.b._value = getelementptr inbounds %Ts4Int8V, ptr %.s7.b, i32 0, i32 0
%26 = load i8, ptr %.s7.b._value
%.s8 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %10, i32 0, i32 0
%.s8.c = getelementptr inbounds %T1M1SVySfG, ptr %.s8, i32 0, i32 0
%27 = load ptr, ptr %.s8.c
%.s8.b = getelementptr inbounds %T1M1SVySfG, ptr %.s8, i32 0, i32 1
%.s8.b._value = getelementptr inbounds %Ts4Int8V, ptr %.s8.b, i32 0, i32 0
%28 = load i8, ptr %.s8.b._value
%.v9 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %8, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %.v9, i64 9, i1 false)
%.v10 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %10, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %.v10, i64 9, i1 false)
%.s11 = getelementptr inbounds %T4main1VV13TangentVectorV, ptr %7, i32 0, i32 0
%.s11.c = getelementptr inbounds %T1M1SVySfG, ptr %.s11, i32 0, i32 0
%32 = load ptr, ptr %.s11.c
%.s12 = getelementptr inbounds %T4main1VV13TangentVectorV, ptr %9, i32 0, i32 0
%.s12.c = getelementptr inbounds %T1M1SVySfG, ptr %.s12, i32 0, i32 0
%34 = load ptr, ptr %.s12.c
call void @llvm.lifetime.end.p0(i64 25, ptr %10)
call void @llvm.lifetime.end.p0(i64 9, ptr %9)
call void @llvm.lifetime.end.p0(i64 25, ptr %8)
call void @llvm.lifetime.end.p0(i64 9, ptr %7)
call void @llvm.lifetime.end.p0(i64 25, ptr %6)
call void @llvm.lifetime.end.p0(i64 9, ptr %5)
call void @llvm.lifetime.end.p0(i64 25, ptr %4)
call void @llvm.lifetime.end.p0(i64 9, ptr %3)
ret void
}
!llvm.module.flags = !{!0, !1, !2, !3, !4, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15}
!swift.module.flags = !{!33}
!llvm.linker.options = !{!34, !35, !36, !37, !38, !39, !40, !41, !42, !43}
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 14, i32 4]}
!1 = !{i32 1, !"Objective-C Version", i32 2}
!2 = !{i32 1, !"Objective-C Image Info Version", i32 0}
!3 = !{i32 1, !"Objective-C Image Info Section", !"__DATA, no_dead_strip"}
!4 = !{i32 1, !"Objective-C Garbage Collection", i8 0}
!6 = !{i32 7, !"Dwarf Version", i32 4}
!7 = !{i32 2, !"Debug Info Version", i32 3}
!8 = !{i32 1, !"wchar_size", i32 4}
!9 = !{i32 8, !"PIC Level", i32 2}
!10 = !{i32 7, !"uwtable", i32 1}
!11 = !{i32 7, !"frame-pointer", i32 1}
!12 = !{i32 1, !"Swift Version", i32 7}
!13 = !{i32 1, !"Swift ABI Version", i32 7}
!14 = !{i32 1, !"Swift Major Version", i8 6}
!15 = !{i32 1, !"Swift Minor Version", i8 0}
!16 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !17, imports: !18, sdk: "MacOSX14.4.sdk")
!17 = !DIFile(filename: "/Users/emilpedersen/swift2/swift/test/IRGen/debug_scope_distinct.swift", directory: "/Users/emilpedersen/swift2")
!18 = !{!19, !21, !23, !25, !27, !29, !31}
!19 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !20, file: !17)
!20 = !DIModule(scope: null, name: "main", includePath: "/Users/emilpedersen/swift2/swift/test/IRGen")
!21 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !22, file: !17)
!22 = !DIModule(scope: null, name: "Swift", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/macosx/Swift.swiftmodule/arm64-apple-macos.swiftmodule")
!23 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !24, line: 60)
!24 = !DIModule(scope: null, name: "_Differentiation", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/macosx/_Differentiation.swiftmodule/arm64-apple-macos.swiftmodule")
!25 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !26, line: 61)
!26 = !DIModule(scope: null, name: "M", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/test-macosx-arm64/IRGen/Output/debug_scope_distinct.swift.tmp/M.swiftmodule")
!27 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !28, file: !17)
!28 = !DIModule(scope: null, name: "_StringProcessing", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/macosx/_StringProcessing.swiftmodule/arm64-apple-macos.swiftmodule")
!29 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !30, file: !17)
!30 = !DIModule(scope: null, name: "_SwiftConcurrencyShims", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/shims")
!31 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !32, file: !17)
!32 = !DIModule(scope: null, name: "_Concurrency", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/macosx/_Concurrency.swiftmodule/arm64-apple-macos.swiftmodule")
!33 = !{i1 false}
!34 = !{!"-lswiftCore"}
!35 = !{!"-lswift_StringProcessing"}
!36 = !{!"-lswift_Differentiation"}
!37 = !{!"-lswiftDarwin"}
!38 = !{!"-lswift_Concurrency"}
!39 = !{!"-lswiftSwiftOnoneSupport"}
!40 = !{!"-lobjc"}
!41 = !{!"-lswiftCompatibilityConcurrency"}
!42 = !{!"-lswiftCompatibility56"}
!43 = !{!"-lswiftCompatibilityPacks"}
!44 = distinct !DISubprogram( unit: !16, declaration: !52, retainedNodes: !53)
!45 = !DIFile(filename: "<compiler-generated>", directory: "/")
!46 = !DICompositeType(tag: DW_TAG_structure_type, scope: !47, elements: !48, identifier: "$s4main1TV13TangentVectorVD")
!47 = !DICompositeType(tag: DW_TAG_structure_type, identifier: "$s4main1TVD")
!48 = !{}
!49 = !DISubroutineType(types: !50)
!50 = !{!51}
!51 = !DICompositeType(tag: DW_TAG_structure_type, identifier: "$s4main1TV13TangentVectorVXMtD")
!52 = !DISubprogram( file: !45, type: !49, spFlags: DISPFlagOptimized)
!53 = !{!54, !56, !57}
!54 = !DILocalVariable( scope: !44, type: !55, flags: DIFlagArtificial)
!55 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !46)
!56 = !DILocalVariable( scope: !44, flags: DIFlagArtificial)
!57 = !DILocalVariable( scope: !44, type: !58, flags: DIFlagArtificial)
!58 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !51)
!62 = !DILocalVariable( scope: !63, type: !72, flags: DIFlagArtificial)
!63 = distinct !DISubprogram( type: !66, unit: !16, declaration: !69, retainedNodes: !70)
!64 = !DICompositeType(tag: DW_TAG_structure_type, scope: !65, identifier: "$s4main1UV13TangentVectorVD")
!65 = !DICompositeType(tag: DW_TAG_structure_type, identifier: "$s4main1UVD")
!66 = !DISubroutineType(types: !67)
!67 = !{!68}
!68 = !DICompositeType(tag: DW_TAG_structure_type, identifier: "$s4main1UV13TangentVectorVXMtD")
!69 = !DISubprogram( spFlags: DISPFlagOptimized)
!70 = !{!71, !73}
!71 = !DILocalVariable( scope: !63, flags: DIFlagArtificial)
!72 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !64)
!73 = !DILocalVariable( scope: !63, type: !74, flags: DIFlagArtificial)
!74 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !68)
!75 = !DILocation( scope: !63, inlinedAt: !76)
!76 = distinct !DILocation( scope: !44)
```
if we run
` opt -S -passes=sroa file.ll -o -`
With this patch we will see
```
%.sroa.5.sroa.021 = alloca [7 x i8], align 8
tail call void @llvm.dbg.value(metadata ptr %.sroa.5.sroa.021, metadata !59, metadata !DIExpression(DW_OP_deref, DW_OP_LLVM_fragment, 72, 56)), !dbg !72
%.sroa.5.sroa.014 = alloca [7 x i8], align 8
```
Without this patch we will see:
```
%.sroa.5.sroa.021 = alloca [7 x i8], align 8
%.sroa.5.sroa.014 = alloca [7 x i8], align 8
```
Thus this patch ensures that llvm.dbg.values that use allocas that are broken up still have the correct metadata and debug information is preserved
This is part of a stack of patches and is preceded by: https://github.com/llvm/llvm-project/pull/94068
2024-08-21 17:52:37 -07:00
|
|
|
// DenseMap lookup. This check is a bitfield datamember lookup.
|
2024-01-15 17:46:56 +00:00
|
|
|
if (!V->isUsedByMetadata())
|
|
|
|
return {};
|
|
|
|
auto *L = LocalAsMetadata::getIfExists(V);
|
|
|
|
if (!L)
|
|
|
|
return {};
|
|
|
|
auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L);
|
|
|
|
if (!MDV)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
TinyPtrVector<DbgDeclareInst *> Declares;
|
|
|
|
for (User *U : MDV->users())
|
|
|
|
if (auto *DDI = dyn_cast<DbgDeclareInst>(U))
|
|
|
|
Declares.push_back(DDI);
|
|
|
|
|
|
|
|
return Declares;
|
|
|
|
}
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
TinyPtrVector<DbgVariableRecord *> llvm::findDVRDeclares(Value *V) {
|
2024-01-15 17:46:56 +00:00
|
|
|
// This function is hot. Check whether the value has any metadata to avoid a
|
Handle #dbg_values in SROA. (#94070)
This patch properly handles #dbg_values in SROA by making sure that any
#dbg_values get moved to before a store just like #dbg_declares do, or
the #dbg_value is correctly updated with the right alloca after an
aggregate alloca is broken up.
The issue stems from swift where #dbg_values are emitted and not
dbg.declares, the SROA pass doesn't handle the #dbg_values correctly and
it causes them to all have undefs
If we look at this simple-ish testcase (This is all I could reduce it
down to, and I am still relatively bad at writing llvm IR by hand so I
apologize in advance):
```
%T4main1TV13TangentVectorV = type <{ %T4main1UV13TangentVectorV, [7 x i8], %T4main1UV13TangentVectorV }>
%T4main1UV13TangentVectorV = type <{ %T1M1SVySfG, [7 x i8], %T4main1VV13TangentVectorV }>
%T1M1SVySfG = type <{ ptr, %Ts4Int8V }>
%Ts4Int8V = type <{ i8 }>
%T4main1VV13TangentVectorV = type <{ %T1M1SVySfG }>
define hidden swiftcc void @"$s4main1TV13TangentVectorV1poiyA2E_AEtFZ"(ptr noalias nocapture sret(%T4main1TV13TangentVectorV) %0, ptr noalias nocapture dereferenceable(57) %1, ptr noalias nocapture dereferenceable(57) %2) #0 !dbg !44 {
entry:
%3 = alloca %T4main1VV13TangentVectorV
%4 = alloca %T4main1UV13TangentVectorV
%5 = alloca %T4main1VV13TangentVectorV
%6 = alloca %T4main1UV13TangentVectorV
%7 = alloca %T4main1VV13TangentVectorV
%8 = alloca %T4main1UV13TangentVectorV
%9 = alloca %T4main1VV13TangentVectorV
%10 = alloca %T4main1UV13TangentVectorV
call void @llvm.lifetime.start.p0(i64 9, ptr %3)
call void @llvm.lifetime.start.p0(i64 25, ptr %4)
call void @llvm.lifetime.start.p0(i64 9, ptr %5)
call void @llvm.lifetime.start.p0(i64 25, ptr %6)
call void @llvm.lifetime.start.p0(i64 9, ptr %7)
call void @llvm.lifetime.start.p0(i64 25, ptr %8)
call void @llvm.lifetime.start.p0(i64 9, ptr %9)
call void @llvm.lifetime.start.p0(i64 25, ptr %10)
%.u1 = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %1, i32 0, i32 0
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %.u1, i64 25, i1 false)
%.u11 = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %2, i32 0, i32 0
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %.u11, i64 25, i1 false)
call void @llvm.dbg.value(metadata ptr %4, metadata !62, metadata !DIExpression(DW_OP_deref)), !dbg !75
%.s = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %4, i32 0, i32 0
%.s.c = getelementptr inbounds %T1M1SVySfG, ptr %.s, i32 0, i32 0
%11 = load ptr, ptr %.s.c
%.s.b = getelementptr inbounds %T1M1SVySfG, ptr %.s, i32 0, i32 1
%.s.b._value = getelementptr inbounds %Ts4Int8V, ptr %.s.b, i32 0, i32 0
%12 = load i8, ptr %.s.b._value
%.s2 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %6, i32 0, i32 0
%.s2.c = getelementptr inbounds %T1M1SVySfG, ptr %.s2, i32 0, i32 0
%13 = load ptr, ptr %.s2.c
%.s2.b = getelementptr inbounds %T1M1SVySfG, ptr %.s2, i32 0, i32 1
%.s2.b._value = getelementptr inbounds %Ts4Int8V, ptr %.s2.b, i32 0, i32 0
%14 = load i8, ptr %.s2.b._value
%.v = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %4, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %.v, i64 9, i1 false)
%.v3 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %6, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %.v3, i64 9, i1 false)
%.s4 = getelementptr inbounds %T4main1VV13TangentVectorV, ptr %3, i32 0, i32 0
%.s4.c = getelementptr inbounds %T1M1SVySfG, ptr %.s4, i32 0, i32 0
%18 = load ptr, ptr %.s4.c
%.s5 = getelementptr inbounds %T4main1VV13TangentVectorV, ptr %5, i32 0, i32 0
%.s5.c = getelementptr inbounds %T1M1SVySfG, ptr %.s5, i32 0, i32 0
%20 = load ptr, ptr %.s5.c
%.u2 = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %1, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %.u2, i64 25, i1 false)
%.u26 = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %2, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %.u26, i64 25, i1 false)
%.s7 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %8, i32 0, i32 0
%.s7.c = getelementptr inbounds %T1M1SVySfG, ptr %.s7, i32 0, i32 0
%25 = load ptr, ptr %.s7.c
%.s7.b = getelementptr inbounds %T1M1SVySfG, ptr %.s7, i32 0, i32 1
%.s7.b._value = getelementptr inbounds %Ts4Int8V, ptr %.s7.b, i32 0, i32 0
%26 = load i8, ptr %.s7.b._value
%.s8 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %10, i32 0, i32 0
%.s8.c = getelementptr inbounds %T1M1SVySfG, ptr %.s8, i32 0, i32 0
%27 = load ptr, ptr %.s8.c
%.s8.b = getelementptr inbounds %T1M1SVySfG, ptr %.s8, i32 0, i32 1
%.s8.b._value = getelementptr inbounds %Ts4Int8V, ptr %.s8.b, i32 0, i32 0
%28 = load i8, ptr %.s8.b._value
%.v9 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %8, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %.v9, i64 9, i1 false)
%.v10 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %10, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %.v10, i64 9, i1 false)
%.s11 = getelementptr inbounds %T4main1VV13TangentVectorV, ptr %7, i32 0, i32 0
%.s11.c = getelementptr inbounds %T1M1SVySfG, ptr %.s11, i32 0, i32 0
%32 = load ptr, ptr %.s11.c
%.s12 = getelementptr inbounds %T4main1VV13TangentVectorV, ptr %9, i32 0, i32 0
%.s12.c = getelementptr inbounds %T1M1SVySfG, ptr %.s12, i32 0, i32 0
%34 = load ptr, ptr %.s12.c
call void @llvm.lifetime.end.p0(i64 25, ptr %10)
call void @llvm.lifetime.end.p0(i64 9, ptr %9)
call void @llvm.lifetime.end.p0(i64 25, ptr %8)
call void @llvm.lifetime.end.p0(i64 9, ptr %7)
call void @llvm.lifetime.end.p0(i64 25, ptr %6)
call void @llvm.lifetime.end.p0(i64 9, ptr %5)
call void @llvm.lifetime.end.p0(i64 25, ptr %4)
call void @llvm.lifetime.end.p0(i64 9, ptr %3)
ret void
}
!llvm.module.flags = !{!0, !1, !2, !3, !4, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15}
!swift.module.flags = !{!33}
!llvm.linker.options = !{!34, !35, !36, !37, !38, !39, !40, !41, !42, !43}
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 14, i32 4]}
!1 = !{i32 1, !"Objective-C Version", i32 2}
!2 = !{i32 1, !"Objective-C Image Info Version", i32 0}
!3 = !{i32 1, !"Objective-C Image Info Section", !"__DATA, no_dead_strip"}
!4 = !{i32 1, !"Objective-C Garbage Collection", i8 0}
!6 = !{i32 7, !"Dwarf Version", i32 4}
!7 = !{i32 2, !"Debug Info Version", i32 3}
!8 = !{i32 1, !"wchar_size", i32 4}
!9 = !{i32 8, !"PIC Level", i32 2}
!10 = !{i32 7, !"uwtable", i32 1}
!11 = !{i32 7, !"frame-pointer", i32 1}
!12 = !{i32 1, !"Swift Version", i32 7}
!13 = !{i32 1, !"Swift ABI Version", i32 7}
!14 = !{i32 1, !"Swift Major Version", i8 6}
!15 = !{i32 1, !"Swift Minor Version", i8 0}
!16 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !17, imports: !18, sdk: "MacOSX14.4.sdk")
!17 = !DIFile(filename: "/Users/emilpedersen/swift2/swift/test/IRGen/debug_scope_distinct.swift", directory: "/Users/emilpedersen/swift2")
!18 = !{!19, !21, !23, !25, !27, !29, !31}
!19 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !20, file: !17)
!20 = !DIModule(scope: null, name: "main", includePath: "/Users/emilpedersen/swift2/swift/test/IRGen")
!21 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !22, file: !17)
!22 = !DIModule(scope: null, name: "Swift", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/macosx/Swift.swiftmodule/arm64-apple-macos.swiftmodule")
!23 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !24, line: 60)
!24 = !DIModule(scope: null, name: "_Differentiation", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/macosx/_Differentiation.swiftmodule/arm64-apple-macos.swiftmodule")
!25 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !26, line: 61)
!26 = !DIModule(scope: null, name: "M", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/test-macosx-arm64/IRGen/Output/debug_scope_distinct.swift.tmp/M.swiftmodule")
!27 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !28, file: !17)
!28 = !DIModule(scope: null, name: "_StringProcessing", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/macosx/_StringProcessing.swiftmodule/arm64-apple-macos.swiftmodule")
!29 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !30, file: !17)
!30 = !DIModule(scope: null, name: "_SwiftConcurrencyShims", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/shims")
!31 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !32, file: !17)
!32 = !DIModule(scope: null, name: "_Concurrency", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/macosx/_Concurrency.swiftmodule/arm64-apple-macos.swiftmodule")
!33 = !{i1 false}
!34 = !{!"-lswiftCore"}
!35 = !{!"-lswift_StringProcessing"}
!36 = !{!"-lswift_Differentiation"}
!37 = !{!"-lswiftDarwin"}
!38 = !{!"-lswift_Concurrency"}
!39 = !{!"-lswiftSwiftOnoneSupport"}
!40 = !{!"-lobjc"}
!41 = !{!"-lswiftCompatibilityConcurrency"}
!42 = !{!"-lswiftCompatibility56"}
!43 = !{!"-lswiftCompatibilityPacks"}
!44 = distinct !DISubprogram( unit: !16, declaration: !52, retainedNodes: !53)
!45 = !DIFile(filename: "<compiler-generated>", directory: "/")
!46 = !DICompositeType(tag: DW_TAG_structure_type, scope: !47, elements: !48, identifier: "$s4main1TV13TangentVectorVD")
!47 = !DICompositeType(tag: DW_TAG_structure_type, identifier: "$s4main1TVD")
!48 = !{}
!49 = !DISubroutineType(types: !50)
!50 = !{!51}
!51 = !DICompositeType(tag: DW_TAG_structure_type, identifier: "$s4main1TV13TangentVectorVXMtD")
!52 = !DISubprogram( file: !45, type: !49, spFlags: DISPFlagOptimized)
!53 = !{!54, !56, !57}
!54 = !DILocalVariable( scope: !44, type: !55, flags: DIFlagArtificial)
!55 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !46)
!56 = !DILocalVariable( scope: !44, flags: DIFlagArtificial)
!57 = !DILocalVariable( scope: !44, type: !58, flags: DIFlagArtificial)
!58 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !51)
!62 = !DILocalVariable( scope: !63, type: !72, flags: DIFlagArtificial)
!63 = distinct !DISubprogram( type: !66, unit: !16, declaration: !69, retainedNodes: !70)
!64 = !DICompositeType(tag: DW_TAG_structure_type, scope: !65, identifier: "$s4main1UV13TangentVectorVD")
!65 = !DICompositeType(tag: DW_TAG_structure_type, identifier: "$s4main1UVD")
!66 = !DISubroutineType(types: !67)
!67 = !{!68}
!68 = !DICompositeType(tag: DW_TAG_structure_type, identifier: "$s4main1UV13TangentVectorVXMtD")
!69 = !DISubprogram( spFlags: DISPFlagOptimized)
!70 = !{!71, !73}
!71 = !DILocalVariable( scope: !63, flags: DIFlagArtificial)
!72 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !64)
!73 = !DILocalVariable( scope: !63, type: !74, flags: DIFlagArtificial)
!74 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !68)
!75 = !DILocation( scope: !63, inlinedAt: !76)
!76 = distinct !DILocation( scope: !44)
```
if we run
` opt -S -passes=sroa file.ll -o -`
With this patch we will see
```
%.sroa.5.sroa.021 = alloca [7 x i8], align 8
tail call void @llvm.dbg.value(metadata ptr %.sroa.5.sroa.021, metadata !59, metadata !DIExpression(DW_OP_deref, DW_OP_LLVM_fragment, 72, 56)), !dbg !72
%.sroa.5.sroa.014 = alloca [7 x i8], align 8
```
Without this patch we will see:
```
%.sroa.5.sroa.021 = alloca [7 x i8], align 8
%.sroa.5.sroa.014 = alloca [7 x i8], align 8
```
Thus this patch ensures that llvm.dbg.values that use allocas that are broken up still have the correct metadata and debug information is preserved
This is part of a stack of patches and is preceded by: https://github.com/llvm/llvm-project/pull/94068
2024-08-21 17:52:37 -07:00
|
|
|
// DenseMap lookup. This check is a bitfield datamember lookup.
|
2024-01-15 17:46:56 +00:00
|
|
|
if (!V->isUsedByMetadata())
|
|
|
|
return {};
|
|
|
|
auto *L = LocalAsMetadata::getIfExists(V);
|
|
|
|
if (!L)
|
|
|
|
return {};
|
|
|
|
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
TinyPtrVector<DbgVariableRecord *> Declares;
|
|
|
|
for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers())
|
|
|
|
if (DVR->getType() == DbgVariableRecord::LocationType::Declare)
|
|
|
|
Declares.push_back(DVR);
|
2024-01-15 17:46:56 +00:00
|
|
|
|
|
|
|
return Declares;
|
|
|
|
}
|
|
|
|
|
Handle #dbg_values in SROA. (#94070)
This patch properly handles #dbg_values in SROA by making sure that any
#dbg_values get moved to before a store just like #dbg_declares do, or
the #dbg_value is correctly updated with the right alloca after an
aggregate alloca is broken up.
The issue stems from swift where #dbg_values are emitted and not
dbg.declares, the SROA pass doesn't handle the #dbg_values correctly and
it causes them to all have undefs
If we look at this simple-ish testcase (This is all I could reduce it
down to, and I am still relatively bad at writing llvm IR by hand so I
apologize in advance):
```
%T4main1TV13TangentVectorV = type <{ %T4main1UV13TangentVectorV, [7 x i8], %T4main1UV13TangentVectorV }>
%T4main1UV13TangentVectorV = type <{ %T1M1SVySfG, [7 x i8], %T4main1VV13TangentVectorV }>
%T1M1SVySfG = type <{ ptr, %Ts4Int8V }>
%Ts4Int8V = type <{ i8 }>
%T4main1VV13TangentVectorV = type <{ %T1M1SVySfG }>
define hidden swiftcc void @"$s4main1TV13TangentVectorV1poiyA2E_AEtFZ"(ptr noalias nocapture sret(%T4main1TV13TangentVectorV) %0, ptr noalias nocapture dereferenceable(57) %1, ptr noalias nocapture dereferenceable(57) %2) #0 !dbg !44 {
entry:
%3 = alloca %T4main1VV13TangentVectorV
%4 = alloca %T4main1UV13TangentVectorV
%5 = alloca %T4main1VV13TangentVectorV
%6 = alloca %T4main1UV13TangentVectorV
%7 = alloca %T4main1VV13TangentVectorV
%8 = alloca %T4main1UV13TangentVectorV
%9 = alloca %T4main1VV13TangentVectorV
%10 = alloca %T4main1UV13TangentVectorV
call void @llvm.lifetime.start.p0(i64 9, ptr %3)
call void @llvm.lifetime.start.p0(i64 25, ptr %4)
call void @llvm.lifetime.start.p0(i64 9, ptr %5)
call void @llvm.lifetime.start.p0(i64 25, ptr %6)
call void @llvm.lifetime.start.p0(i64 9, ptr %7)
call void @llvm.lifetime.start.p0(i64 25, ptr %8)
call void @llvm.lifetime.start.p0(i64 9, ptr %9)
call void @llvm.lifetime.start.p0(i64 25, ptr %10)
%.u1 = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %1, i32 0, i32 0
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %.u1, i64 25, i1 false)
%.u11 = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %2, i32 0, i32 0
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %.u11, i64 25, i1 false)
call void @llvm.dbg.value(metadata ptr %4, metadata !62, metadata !DIExpression(DW_OP_deref)), !dbg !75
%.s = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %4, i32 0, i32 0
%.s.c = getelementptr inbounds %T1M1SVySfG, ptr %.s, i32 0, i32 0
%11 = load ptr, ptr %.s.c
%.s.b = getelementptr inbounds %T1M1SVySfG, ptr %.s, i32 0, i32 1
%.s.b._value = getelementptr inbounds %Ts4Int8V, ptr %.s.b, i32 0, i32 0
%12 = load i8, ptr %.s.b._value
%.s2 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %6, i32 0, i32 0
%.s2.c = getelementptr inbounds %T1M1SVySfG, ptr %.s2, i32 0, i32 0
%13 = load ptr, ptr %.s2.c
%.s2.b = getelementptr inbounds %T1M1SVySfG, ptr %.s2, i32 0, i32 1
%.s2.b._value = getelementptr inbounds %Ts4Int8V, ptr %.s2.b, i32 0, i32 0
%14 = load i8, ptr %.s2.b._value
%.v = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %4, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %.v, i64 9, i1 false)
%.v3 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %6, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %.v3, i64 9, i1 false)
%.s4 = getelementptr inbounds %T4main1VV13TangentVectorV, ptr %3, i32 0, i32 0
%.s4.c = getelementptr inbounds %T1M1SVySfG, ptr %.s4, i32 0, i32 0
%18 = load ptr, ptr %.s4.c
%.s5 = getelementptr inbounds %T4main1VV13TangentVectorV, ptr %5, i32 0, i32 0
%.s5.c = getelementptr inbounds %T1M1SVySfG, ptr %.s5, i32 0, i32 0
%20 = load ptr, ptr %.s5.c
%.u2 = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %1, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %.u2, i64 25, i1 false)
%.u26 = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %2, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %.u26, i64 25, i1 false)
%.s7 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %8, i32 0, i32 0
%.s7.c = getelementptr inbounds %T1M1SVySfG, ptr %.s7, i32 0, i32 0
%25 = load ptr, ptr %.s7.c
%.s7.b = getelementptr inbounds %T1M1SVySfG, ptr %.s7, i32 0, i32 1
%.s7.b._value = getelementptr inbounds %Ts4Int8V, ptr %.s7.b, i32 0, i32 0
%26 = load i8, ptr %.s7.b._value
%.s8 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %10, i32 0, i32 0
%.s8.c = getelementptr inbounds %T1M1SVySfG, ptr %.s8, i32 0, i32 0
%27 = load ptr, ptr %.s8.c
%.s8.b = getelementptr inbounds %T1M1SVySfG, ptr %.s8, i32 0, i32 1
%.s8.b._value = getelementptr inbounds %Ts4Int8V, ptr %.s8.b, i32 0, i32 0
%28 = load i8, ptr %.s8.b._value
%.v9 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %8, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %.v9, i64 9, i1 false)
%.v10 = getelementptr inbounds %T4main1UV13TangentVectorV, ptr %10, i32 0, i32 2
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %.v10, i64 9, i1 false)
%.s11 = getelementptr inbounds %T4main1VV13TangentVectorV, ptr %7, i32 0, i32 0
%.s11.c = getelementptr inbounds %T1M1SVySfG, ptr %.s11, i32 0, i32 0
%32 = load ptr, ptr %.s11.c
%.s12 = getelementptr inbounds %T4main1VV13TangentVectorV, ptr %9, i32 0, i32 0
%.s12.c = getelementptr inbounds %T1M1SVySfG, ptr %.s12, i32 0, i32 0
%34 = load ptr, ptr %.s12.c
call void @llvm.lifetime.end.p0(i64 25, ptr %10)
call void @llvm.lifetime.end.p0(i64 9, ptr %9)
call void @llvm.lifetime.end.p0(i64 25, ptr %8)
call void @llvm.lifetime.end.p0(i64 9, ptr %7)
call void @llvm.lifetime.end.p0(i64 25, ptr %6)
call void @llvm.lifetime.end.p0(i64 9, ptr %5)
call void @llvm.lifetime.end.p0(i64 25, ptr %4)
call void @llvm.lifetime.end.p0(i64 9, ptr %3)
ret void
}
!llvm.module.flags = !{!0, !1, !2, !3, !4, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15}
!swift.module.flags = !{!33}
!llvm.linker.options = !{!34, !35, !36, !37, !38, !39, !40, !41, !42, !43}
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 14, i32 4]}
!1 = !{i32 1, !"Objective-C Version", i32 2}
!2 = !{i32 1, !"Objective-C Image Info Version", i32 0}
!3 = !{i32 1, !"Objective-C Image Info Section", !"__DATA, no_dead_strip"}
!4 = !{i32 1, !"Objective-C Garbage Collection", i8 0}
!6 = !{i32 7, !"Dwarf Version", i32 4}
!7 = !{i32 2, !"Debug Info Version", i32 3}
!8 = !{i32 1, !"wchar_size", i32 4}
!9 = !{i32 8, !"PIC Level", i32 2}
!10 = !{i32 7, !"uwtable", i32 1}
!11 = !{i32 7, !"frame-pointer", i32 1}
!12 = !{i32 1, !"Swift Version", i32 7}
!13 = !{i32 1, !"Swift ABI Version", i32 7}
!14 = !{i32 1, !"Swift Major Version", i8 6}
!15 = !{i32 1, !"Swift Minor Version", i8 0}
!16 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !17, imports: !18, sdk: "MacOSX14.4.sdk")
!17 = !DIFile(filename: "/Users/emilpedersen/swift2/swift/test/IRGen/debug_scope_distinct.swift", directory: "/Users/emilpedersen/swift2")
!18 = !{!19, !21, !23, !25, !27, !29, !31}
!19 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !20, file: !17)
!20 = !DIModule(scope: null, name: "main", includePath: "/Users/emilpedersen/swift2/swift/test/IRGen")
!21 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !22, file: !17)
!22 = !DIModule(scope: null, name: "Swift", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/macosx/Swift.swiftmodule/arm64-apple-macos.swiftmodule")
!23 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !24, line: 60)
!24 = !DIModule(scope: null, name: "_Differentiation", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/macosx/_Differentiation.swiftmodule/arm64-apple-macos.swiftmodule")
!25 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !26, line: 61)
!26 = !DIModule(scope: null, name: "M", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/test-macosx-arm64/IRGen/Output/debug_scope_distinct.swift.tmp/M.swiftmodule")
!27 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !28, file: !17)
!28 = !DIModule(scope: null, name: "_StringProcessing", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/macosx/_StringProcessing.swiftmodule/arm64-apple-macos.swiftmodule")
!29 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !30, file: !17)
!30 = !DIModule(scope: null, name: "_SwiftConcurrencyShims", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/shims")
!31 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !17, entity: !32, file: !17)
!32 = !DIModule(scope: null, name: "_Concurrency", includePath: "/Users/emilpedersen/swift2/_build/Ninja-RelWithDebInfoAssert+stdlib-RelWithDebInfo/swift-macosx-arm64/lib/swift/macosx/_Concurrency.swiftmodule/arm64-apple-macos.swiftmodule")
!33 = !{i1 false}
!34 = !{!"-lswiftCore"}
!35 = !{!"-lswift_StringProcessing"}
!36 = !{!"-lswift_Differentiation"}
!37 = !{!"-lswiftDarwin"}
!38 = !{!"-lswift_Concurrency"}
!39 = !{!"-lswiftSwiftOnoneSupport"}
!40 = !{!"-lobjc"}
!41 = !{!"-lswiftCompatibilityConcurrency"}
!42 = !{!"-lswiftCompatibility56"}
!43 = !{!"-lswiftCompatibilityPacks"}
!44 = distinct !DISubprogram( unit: !16, declaration: !52, retainedNodes: !53)
!45 = !DIFile(filename: "<compiler-generated>", directory: "/")
!46 = !DICompositeType(tag: DW_TAG_structure_type, scope: !47, elements: !48, identifier: "$s4main1TV13TangentVectorVD")
!47 = !DICompositeType(tag: DW_TAG_structure_type, identifier: "$s4main1TVD")
!48 = !{}
!49 = !DISubroutineType(types: !50)
!50 = !{!51}
!51 = !DICompositeType(tag: DW_TAG_structure_type, identifier: "$s4main1TV13TangentVectorVXMtD")
!52 = !DISubprogram( file: !45, type: !49, spFlags: DISPFlagOptimized)
!53 = !{!54, !56, !57}
!54 = !DILocalVariable( scope: !44, type: !55, flags: DIFlagArtificial)
!55 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !46)
!56 = !DILocalVariable( scope: !44, flags: DIFlagArtificial)
!57 = !DILocalVariable( scope: !44, type: !58, flags: DIFlagArtificial)
!58 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !51)
!62 = !DILocalVariable( scope: !63, type: !72, flags: DIFlagArtificial)
!63 = distinct !DISubprogram( type: !66, unit: !16, declaration: !69, retainedNodes: !70)
!64 = !DICompositeType(tag: DW_TAG_structure_type, scope: !65, identifier: "$s4main1UV13TangentVectorVD")
!65 = !DICompositeType(tag: DW_TAG_structure_type, identifier: "$s4main1UVD")
!66 = !DISubroutineType(types: !67)
!67 = !{!68}
!68 = !DICompositeType(tag: DW_TAG_structure_type, identifier: "$s4main1UV13TangentVectorVXMtD")
!69 = !DISubprogram( spFlags: DISPFlagOptimized)
!70 = !{!71, !73}
!71 = !DILocalVariable( scope: !63, flags: DIFlagArtificial)
!72 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !64)
!73 = !DILocalVariable( scope: !63, type: !74, flags: DIFlagArtificial)
!74 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !68)
!75 = !DILocation( scope: !63, inlinedAt: !76)
!76 = distinct !DILocation( scope: !44)
```
if we run
` opt -S -passes=sroa file.ll -o -`
With this patch we will see
```
%.sroa.5.sroa.021 = alloca [7 x i8], align 8
tail call void @llvm.dbg.value(metadata ptr %.sroa.5.sroa.021, metadata !59, metadata !DIExpression(DW_OP_deref, DW_OP_LLVM_fragment, 72, 56)), !dbg !72
%.sroa.5.sroa.014 = alloca [7 x i8], align 8
```
Without this patch we will see:
```
%.sroa.5.sroa.021 = alloca [7 x i8], align 8
%.sroa.5.sroa.014 = alloca [7 x i8], align 8
```
Thus this patch ensures that llvm.dbg.values that use allocas that are broken up still have the correct metadata and debug information is preserved
This is part of a stack of patches and is preceded by: https://github.com/llvm/llvm-project/pull/94068
2024-08-21 17:52:37 -07:00
|
|
|
TinyPtrVector<DbgVariableRecord *> llvm::findDVRValues(Value *V) {
|
|
|
|
// This function is hot. Check whether the value has any metadata to avoid a
|
|
|
|
// DenseMap lookup. This check is a bitfield datamember lookup.
|
|
|
|
if (!V->isUsedByMetadata())
|
|
|
|
return {};
|
|
|
|
auto *L = LocalAsMetadata::getIfExists(V);
|
|
|
|
if (!L)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
TinyPtrVector<DbgVariableRecord *> Values;
|
|
|
|
for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers())
|
|
|
|
if (DVR->isValueOfVariable())
|
|
|
|
Values.push_back(DVR);
|
|
|
|
|
|
|
|
return Values;
|
|
|
|
}
|
|
|
|
|
2024-04-30 08:48:24 +01:00
|
|
|
template <typename IntrinsicT, bool DbgAssignAndValuesOnly>
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
static void
|
|
|
|
findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V,
|
|
|
|
SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
|
2021-04-19 09:54:22 +01:00
|
|
|
// This function is hot. Check whether the value has any metadata to avoid a
|
|
|
|
// DenseMap lookup.
|
|
|
|
if (!V->isUsedByMetadata())
|
|
|
|
return;
|
2023-04-20 13:51:06 +01:00
|
|
|
|
|
|
|
LLVMContext &Ctx = V->getContext();
|
2021-04-19 09:54:22 +01:00
|
|
|
// TODO: If this value appears multiple times in a DIArgList, we should still
|
|
|
|
// only add the owning DbgValueInst once; use this set to track ArgListUsers.
|
|
|
|
// This behaviour can be removed when we can automatically remove duplicates.
|
2023-04-20 13:51:06 +01:00
|
|
|
// V will also appear twice in a dbg.assign if its used in the both the value
|
|
|
|
// and address components.
|
|
|
|
SmallPtrSet<IntrinsicT *, 4> EncounteredIntrinsics;
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
SmallPtrSet<DbgVariableRecord *, 4> EncounteredDbgVariableRecords;
|
2023-04-20 13:51:06 +01:00
|
|
|
|
|
|
|
/// Append IntrinsicT users of MetadataAsValue(MD).
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
auto AppendUsers = [&Ctx, &EncounteredIntrinsics,
|
|
|
|
&EncounteredDbgVariableRecords, &Result,
|
|
|
|
DbgVariableRecords](Metadata *MD) {
|
2023-04-20 13:51:06 +01:00
|
|
|
if (auto *MDV = MetadataAsValue::getIfExists(Ctx, MD)) {
|
2021-04-19 09:54:22 +01:00
|
|
|
for (User *U : MDV->users())
|
2023-04-20 13:51:06 +01:00
|
|
|
if (IntrinsicT *DVI = dyn_cast<IntrinsicT>(U))
|
|
|
|
if (EncounteredIntrinsics.insert(DVI).second)
|
|
|
|
Result.push_back(DVI);
|
2021-04-19 09:54:22 +01:00
|
|
|
}
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
if (!DbgVariableRecords)
|
2023-06-07 12:33:43 +01:00
|
|
|
return;
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
// Get DbgVariableRecords that use this as a single value.
|
2023-06-07 12:33:43 +01:00
|
|
|
if (LocalAsMetadata *L = dyn_cast<LocalAsMetadata>(MD)) {
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
for (DbgVariableRecord *DVR : L->getAllDbgVariableRecordUsers()) {
|
2024-04-30 08:48:24 +01:00
|
|
|
if (!DbgAssignAndValuesOnly || DVR->isDbgValue() || DVR->isDbgAssign())
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
if (EncounteredDbgVariableRecords.insert(DVR).second)
|
|
|
|
DbgVariableRecords->push_back(DVR);
|
2023-06-07 12:33:43 +01:00
|
|
|
}
|
|
|
|
}
|
2023-04-20 13:51:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
if (auto *L = LocalAsMetadata::getIfExists(V)) {
|
|
|
|
AppendUsers(L);
|
2023-06-07 12:33:43 +01:00
|
|
|
for (Metadata *AL : L->getAllArgListUsers()) {
|
2023-04-20 13:51:06 +01:00
|
|
|
AppendUsers(AL);
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
if (!DbgVariableRecords)
|
2023-06-07 12:33:43 +01:00
|
|
|
continue;
|
|
|
|
DIArgList *DI = cast<DIArgList>(AL);
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
for (DbgVariableRecord *DVR : DI->getAllDbgVariableRecordUsers())
|
2024-04-30 08:48:24 +01:00
|
|
|
if (!DbgAssignAndValuesOnly || DVR->isDbgValue() || DVR->isDbgAssign())
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
if (EncounteredDbgVariableRecords.insert(DVR).second)
|
|
|
|
DbgVariableRecords->push_back(DVR);
|
2023-06-07 12:33:43 +01:00
|
|
|
}
|
2021-04-19 09:54:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
void llvm::findDbgValues(
|
|
|
|
SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V,
|
|
|
|
SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
|
2024-04-30 08:48:24 +01:00
|
|
|
findDbgIntrinsics<DbgValueInst, /*DbgAssignAndValuesOnly=*/true>(
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
DbgValues, V, DbgVariableRecords);
|
2023-04-20 13:51:06 +01:00
|
|
|
}
|
|
|
|
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
void llvm::findDbgUsers(
|
|
|
|
SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers, Value *V,
|
|
|
|
SmallVectorImpl<DbgVariableRecord *> *DbgVariableRecords) {
|
2024-04-30 08:48:24 +01:00
|
|
|
findDbgIntrinsics<DbgVariableIntrinsic, /*DbgAssignAndValuesOnly=*/false>(
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
DbgUsers, V, DbgVariableRecords);
|
2021-04-19 09:54:22 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 16:38:44 +00:00
|
|
|
DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
|
|
|
|
if (auto *LocalScope = dyn_cast_or_null<DILocalScope>(Scope))
|
2015-03-31 02:06:28 +00:00
|
|
|
return LocalScope->getSubprogram();
|
|
|
|
return nullptr;
|
2013-11-08 08:13:15 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 15:12:18 +00:00
|
|
|
DebugLoc llvm::getDebugValueLoc(DbgVariableIntrinsic *DII) {
|
|
|
|
// Original dbg.declare must have a location.
|
|
|
|
const DebugLoc &DeclareLoc = DII->getDebugLoc();
|
|
|
|
MDNode *Scope = DeclareLoc.getScope();
|
|
|
|
DILocation *InlinedAt = DeclareLoc.getInlinedAt();
|
|
|
|
// Because no machine insts can come from debug intrinsics, only the scope
|
|
|
|
// and inlinedAt is significant. Zero line numbers are used in case this
|
|
|
|
// DebugLoc leaks into any adjacent instructions. Produce an unknown location
|
|
|
|
// with the correct scope / inlinedAt fields.
|
|
|
|
return DILocation::get(DII->getContext(), 0, 0, Scope, InlinedAt);
|
|
|
|
}
|
|
|
|
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
DebugLoc llvm::getDebugValueLoc(DbgVariableRecord *DVR) {
|
2024-01-22 11:05:27 +00:00
|
|
|
// Original dbg.declare must have a location.
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
const DebugLoc &DeclareLoc = DVR->getDebugLoc();
|
2024-01-22 11:05:27 +00:00
|
|
|
MDNode *Scope = DeclareLoc.getScope();
|
|
|
|
DILocation *InlinedAt = DeclareLoc.getInlinedAt();
|
|
|
|
// Because no machine insts can come from debug intrinsics, only the scope
|
|
|
|
// and inlinedAt is significant. Zero line numbers are used in case this
|
|
|
|
// DebugLoc leaks into any adjacent instructions. Produce an unknown location
|
|
|
|
// with the correct scope / inlinedAt fields.
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
return DILocation::get(DVR->getContext(), 0, 0, Scope, InlinedAt);
|
2024-01-22 11:05:27 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 08:13:15 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DebugInfoFinder implementations.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void DebugInfoFinder::reset() {
|
|
|
|
CUs.clear();
|
|
|
|
SPs.clear();
|
|
|
|
GVs.clear();
|
|
|
|
TYs.clear();
|
|
|
|
Scopes.clear();
|
|
|
|
NodesSeen.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugInfoFinder::processModule(const Module &M) {
|
2018-04-13 21:23:11 +00:00
|
|
|
for (auto *CU : M.debug_compile_units())
|
|
|
|
processCompileUnit(CU);
|
2017-04-11 13:32:11 +00:00
|
|
|
for (auto &F : M.functions()) {
|
2016-04-15 15:57:41 +00:00
|
|
|
if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram()))
|
|
|
|
processSubprogram(SP);
|
2017-04-11 13:32:11 +00:00
|
|
|
// There could be subprograms from inlined functions referenced from
|
|
|
|
// instructions only. Walk the function to find them.
|
2018-04-13 21:23:11 +00:00
|
|
|
for (const BasicBlock &BB : F)
|
|
|
|
for (const Instruction &I : BB)
|
|
|
|
processInstruction(M, I);
|
2017-04-11 13:32:11 +00:00
|
|
|
}
|
2013-11-08 08:13:15 +00:00
|
|
|
}
|
|
|
|
|
[DebugInfo][OPT] Fixing a couple of DI duplication bugs of CloneModule
As demonstrated by the regression tests added in this patch, the
following cases are valid cases:
1. A Function with no DISubprogram attached, but various debug info
related to its instructions, coming, for instance, from an inlined
function, also defined somewhere else in the same module;
2. ... or coming exclusively from the functions inlined and eliminated
from the module entirely.
The ValueMap shared between CloneFunctionInto calls within CloneModule
needs to contain identity mappings for all of the DISubprogram's to
prevent them from being duplicated by MapMetadata / RemapInstruction
calls, this is achieved via DebugInfoFinder collecting all the
DISubprogram's. However, CloneFunctionInto was missing calls into
DebugInfoFinder for functions w/o DISubprogram's attached, but still
referring DISubprogram's from within (case 1). This patch fixes that.
The fix above, however, exposes another issue: if a module contains a
DISubprogram referenced only indirectly from other debug info
metadata, but not attached to any Function defined within the module
(case 2), cloning such a module causes a DICompileUnit duplication: it
will be moved in indirecty via a DISubprogram by DebugInfoFinder first
(because of the first bug fix described above), without being
self-mapped within the shared ValueMap, and then will be copied during
named metadata cloning. So this patch makes sure DebugInfoFinder
visits DICompileUnit's referenced from DISubprogram's as it goes w/o
re-processing llvm.dbg.cu list over and over again for every function
cloned, and makes sure that CloneFunctionInto self-maps
DICompileUnit's referenced from the entire function, not just its own
DISubprogram attached that may also be missing.
The most convenient way of tesing CloneModule I found is to rely on
CloneModule call from `opt -run-twice`, instead of writing tedious
unit tests. That feature has a couple of properties that makes it hard
to use for this purpose though:
1. CloneModule doesn't copy source filename, making `opt -run-twice`
report it as a difference.
2. `opt -run-twice` does the second run on the original module, not
its clone, making the result of cloning completely invisible in opt's
actual output with and without `-run-twice` both, which directly
contradicts `opt -run-twice`s own error message.
This patch fixes this as well.
Reviewed By: aprantl
Reviewers: loladiro, GorNishanov, espindola, echristo, dexonsmith
Subscribers: vsk, debug-info, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D45593
llvm-svn: 330069
2018-04-13 21:22:24 +00:00
|
|
|
void DebugInfoFinder::processCompileUnit(DICompileUnit *CU) {
|
|
|
|
if (!addCompileUnit(CU))
|
|
|
|
return;
|
2022-08-28 23:29:00 -07:00
|
|
|
for (auto *DIG : CU->getGlobalVariables()) {
|
[DebugInfo][OPT] Fixing a couple of DI duplication bugs of CloneModule
As demonstrated by the regression tests added in this patch, the
following cases are valid cases:
1. A Function with no DISubprogram attached, but various debug info
related to its instructions, coming, for instance, from an inlined
function, also defined somewhere else in the same module;
2. ... or coming exclusively from the functions inlined and eliminated
from the module entirely.
The ValueMap shared between CloneFunctionInto calls within CloneModule
needs to contain identity mappings for all of the DISubprogram's to
prevent them from being duplicated by MapMetadata / RemapInstruction
calls, this is achieved via DebugInfoFinder collecting all the
DISubprogram's. However, CloneFunctionInto was missing calls into
DebugInfoFinder for functions w/o DISubprogram's attached, but still
referring DISubprogram's from within (case 1). This patch fixes that.
The fix above, however, exposes another issue: if a module contains a
DISubprogram referenced only indirectly from other debug info
metadata, but not attached to any Function defined within the module
(case 2), cloning such a module causes a DICompileUnit duplication: it
will be moved in indirecty via a DISubprogram by DebugInfoFinder first
(because of the first bug fix described above), without being
self-mapped within the shared ValueMap, and then will be copied during
named metadata cloning. So this patch makes sure DebugInfoFinder
visits DICompileUnit's referenced from DISubprogram's as it goes w/o
re-processing llvm.dbg.cu list over and over again for every function
cloned, and makes sure that CloneFunctionInto self-maps
DICompileUnit's referenced from the entire function, not just its own
DISubprogram attached that may also be missing.
The most convenient way of tesing CloneModule I found is to rely on
CloneModule call from `opt -run-twice`, instead of writing tedious
unit tests. That feature has a couple of properties that makes it hard
to use for this purpose though:
1. CloneModule doesn't copy source filename, making `opt -run-twice`
report it as a difference.
2. `opt -run-twice` does the second run on the original module, not
its clone, making the result of cloning completely invisible in opt's
actual output with and without `-run-twice` both, which directly
contradicts `opt -run-twice`s own error message.
This patch fixes this as well.
Reviewed By: aprantl
Reviewers: loladiro, GorNishanov, espindola, echristo, dexonsmith
Subscribers: vsk, debug-info, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D45593
llvm-svn: 330069
2018-04-13 21:22:24 +00:00
|
|
|
if (!addGlobalVariable(DIG))
|
|
|
|
continue;
|
|
|
|
auto *GV = DIG->getVariable();
|
|
|
|
processScope(GV->getScope());
|
2019-05-07 02:06:37 +00:00
|
|
|
processType(GV->getType());
|
[DebugInfo][OPT] Fixing a couple of DI duplication bugs of CloneModule
As demonstrated by the regression tests added in this patch, the
following cases are valid cases:
1. A Function with no DISubprogram attached, but various debug info
related to its instructions, coming, for instance, from an inlined
function, also defined somewhere else in the same module;
2. ... or coming exclusively from the functions inlined and eliminated
from the module entirely.
The ValueMap shared between CloneFunctionInto calls within CloneModule
needs to contain identity mappings for all of the DISubprogram's to
prevent them from being duplicated by MapMetadata / RemapInstruction
calls, this is achieved via DebugInfoFinder collecting all the
DISubprogram's. However, CloneFunctionInto was missing calls into
DebugInfoFinder for functions w/o DISubprogram's attached, but still
referring DISubprogram's from within (case 1). This patch fixes that.
The fix above, however, exposes another issue: if a module contains a
DISubprogram referenced only indirectly from other debug info
metadata, but not attached to any Function defined within the module
(case 2), cloning such a module causes a DICompileUnit duplication: it
will be moved in indirecty via a DISubprogram by DebugInfoFinder first
(because of the first bug fix described above), without being
self-mapped within the shared ValueMap, and then will be copied during
named metadata cloning. So this patch makes sure DebugInfoFinder
visits DICompileUnit's referenced from DISubprogram's as it goes w/o
re-processing llvm.dbg.cu list over and over again for every function
cloned, and makes sure that CloneFunctionInto self-maps
DICompileUnit's referenced from the entire function, not just its own
DISubprogram attached that may also be missing.
The most convenient way of tesing CloneModule I found is to rely on
CloneModule call from `opt -run-twice`, instead of writing tedious
unit tests. That feature has a couple of properties that makes it hard
to use for this purpose though:
1. CloneModule doesn't copy source filename, making `opt -run-twice`
report it as a difference.
2. `opt -run-twice` does the second run on the original module, not
its clone, making the result of cloning completely invisible in opt's
actual output with and without `-run-twice` both, which directly
contradicts `opt -run-twice`s own error message.
This patch fixes this as well.
Reviewed By: aprantl
Reviewers: loladiro, GorNishanov, espindola, echristo, dexonsmith
Subscribers: vsk, debug-info, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D45593
llvm-svn: 330069
2018-04-13 21:22:24 +00:00
|
|
|
}
|
|
|
|
for (auto *ET : CU->getEnumTypes())
|
|
|
|
processType(ET);
|
|
|
|
for (auto *RT : CU->getRetainedTypes())
|
|
|
|
if (auto *T = dyn_cast<DIType>(RT))
|
|
|
|
processType(T);
|
|
|
|
else
|
|
|
|
processSubprogram(cast<DISubprogram>(RT));
|
|
|
|
for (auto *Import : CU->getImportedEntities()) {
|
2019-05-07 02:06:37 +00:00
|
|
|
auto *Entity = Import->getEntity();
|
[DebugInfo][OPT] Fixing a couple of DI duplication bugs of CloneModule
As demonstrated by the regression tests added in this patch, the
following cases are valid cases:
1. A Function with no DISubprogram attached, but various debug info
related to its instructions, coming, for instance, from an inlined
function, also defined somewhere else in the same module;
2. ... or coming exclusively from the functions inlined and eliminated
from the module entirely.
The ValueMap shared between CloneFunctionInto calls within CloneModule
needs to contain identity mappings for all of the DISubprogram's to
prevent them from being duplicated by MapMetadata / RemapInstruction
calls, this is achieved via DebugInfoFinder collecting all the
DISubprogram's. However, CloneFunctionInto was missing calls into
DebugInfoFinder for functions w/o DISubprogram's attached, but still
referring DISubprogram's from within (case 1). This patch fixes that.
The fix above, however, exposes another issue: if a module contains a
DISubprogram referenced only indirectly from other debug info
metadata, but not attached to any Function defined within the module
(case 2), cloning such a module causes a DICompileUnit duplication: it
will be moved in indirecty via a DISubprogram by DebugInfoFinder first
(because of the first bug fix described above), without being
self-mapped within the shared ValueMap, and then will be copied during
named metadata cloning. So this patch makes sure DebugInfoFinder
visits DICompileUnit's referenced from DISubprogram's as it goes w/o
re-processing llvm.dbg.cu list over and over again for every function
cloned, and makes sure that CloneFunctionInto self-maps
DICompileUnit's referenced from the entire function, not just its own
DISubprogram attached that may also be missing.
The most convenient way of tesing CloneModule I found is to rely on
CloneModule call from `opt -run-twice`, instead of writing tedious
unit tests. That feature has a couple of properties that makes it hard
to use for this purpose though:
1. CloneModule doesn't copy source filename, making `opt -run-twice`
report it as a difference.
2. `opt -run-twice` does the second run on the original module, not
its clone, making the result of cloning completely invisible in opt's
actual output with and without `-run-twice` both, which directly
contradicts `opt -run-twice`s own error message.
This patch fixes this as well.
Reviewed By: aprantl
Reviewers: loladiro, GorNishanov, espindola, echristo, dexonsmith
Subscribers: vsk, debug-info, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D45593
llvm-svn: 330069
2018-04-13 21:22:24 +00:00
|
|
|
if (auto *T = dyn_cast<DIType>(Entity))
|
|
|
|
processType(T);
|
|
|
|
else if (auto *SP = dyn_cast<DISubprogram>(Entity))
|
|
|
|
processSubprogram(SP);
|
|
|
|
else if (auto *NS = dyn_cast<DINamespace>(Entity))
|
|
|
|
processScope(NS->getScope());
|
|
|
|
else if (auto *M = dyn_cast<DIModule>(Entity))
|
|
|
|
processScope(M->getScope());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:23:11 +00:00
|
|
|
void DebugInfoFinder::processInstruction(const Module &M,
|
|
|
|
const Instruction &I) {
|
2020-02-01 22:59:51 -08:00
|
|
|
if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I))
|
2024-01-16 16:56:24 -08:00
|
|
|
processVariable(M, DVI->getVariable());
|
2018-04-13 21:23:11 +00:00
|
|
|
|
|
|
|
if (auto DbgLoc = I.getDebugLoc())
|
|
|
|
processLocation(M, DbgLoc.get());
|
2023-11-26 21:24:29 +00:00
|
|
|
|
2024-03-12 14:53:13 +00:00
|
|
|
for (const DbgRecord &DPR : I.getDbgRecordRange())
|
2024-02-20 16:00:55 +00:00
|
|
|
processDbgRecord(M, DPR);
|
2018-04-13 21:23:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-29 16:38:44 +00:00
|
|
|
void DebugInfoFinder::processLocation(const Module &M, const DILocation *Loc) {
|
2013-11-08 08:13:15 +00:00
|
|
|
if (!Loc)
|
|
|
|
return;
|
2015-04-14 01:35:55 +00:00
|
|
|
processScope(Loc->getScope());
|
|
|
|
processLocation(M, Loc->getInlinedAt());
|
2013-11-08 08:13:15 +00:00
|
|
|
}
|
|
|
|
|
2024-02-24 10:09:38 +00:00
|
|
|
void DebugInfoFinder::processDbgRecord(const Module &M, const DbgRecord &DR) {
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
if (const DbgVariableRecord *DVR = dyn_cast<const DbgVariableRecord>(&DR))
|
|
|
|
processVariable(M, DVR->getVariable());
|
2024-02-24 10:09:38 +00:00
|
|
|
processLocation(M, DR.getDebugLoc().get());
|
2024-02-20 16:00:55 +00:00
|
|
|
}
|
|
|
|
|
2015-04-29 16:38:44 +00:00
|
|
|
void DebugInfoFinder::processType(DIType *DT) {
|
2013-11-08 08:13:15 +00:00
|
|
|
if (!addType(DT))
|
|
|
|
return;
|
2019-05-07 02:06:37 +00:00
|
|
|
processScope(DT->getScope());
|
2015-07-24 20:56:10 +00:00
|
|
|
if (auto *ST = dyn_cast<DISubroutineType>(DT)) {
|
2019-05-07 02:06:37 +00:00
|
|
|
for (DIType *Ref : ST->getTypeArray())
|
|
|
|
processType(Ref);
|
2015-07-24 20:56:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auto *DCT = dyn_cast<DICompositeType>(DT)) {
|
2019-05-07 02:06:37 +00:00
|
|
|
processType(DCT->getBaseType());
|
2015-04-14 09:18:17 +00:00
|
|
|
for (Metadata *D : DCT->getElements()) {
|
2015-04-29 16:38:44 +00:00
|
|
|
if (auto *T = dyn_cast<DIType>(D))
|
2015-04-06 23:18:49 +00:00
|
|
|
processType(T);
|
2015-04-29 16:38:44 +00:00
|
|
|
else if (auto *SP = dyn_cast<DISubprogram>(D))
|
2015-04-06 23:18:49 +00:00
|
|
|
processSubprogram(SP);
|
2013-11-08 08:13:15 +00:00
|
|
|
}
|
2015-07-24 20:56:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auto *DDT = dyn_cast<DIDerivedType>(DT)) {
|
2019-05-07 02:06:37 +00:00
|
|
|
processType(DDT->getBaseType());
|
2013-11-08 08:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-29 16:38:44 +00:00
|
|
|
void DebugInfoFinder::processScope(DIScope *Scope) {
|
2015-04-06 23:18:49 +00:00
|
|
|
if (!Scope)
|
|
|
|
return;
|
2015-04-29 16:38:44 +00:00
|
|
|
if (auto *Ty = dyn_cast<DIType>(Scope)) {
|
2013-11-08 08:13:15 +00:00
|
|
|
processType(Ty);
|
|
|
|
return;
|
|
|
|
}
|
2015-04-29 16:38:44 +00:00
|
|
|
if (auto *CU = dyn_cast<DICompileUnit>(Scope)) {
|
2015-04-06 23:18:49 +00:00
|
|
|
addCompileUnit(CU);
|
2013-11-08 08:13:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-29 16:38:44 +00:00
|
|
|
if (auto *SP = dyn_cast<DISubprogram>(Scope)) {
|
2015-04-06 23:18:49 +00:00
|
|
|
processSubprogram(SP);
|
2013-11-08 08:13:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!addScope(Scope))
|
|
|
|
return;
|
2015-04-29 16:38:44 +00:00
|
|
|
if (auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) {
|
2015-04-14 03:40:37 +00:00
|
|
|
processScope(LB->getScope());
|
2015-04-29 16:38:44 +00:00
|
|
|
} else if (auto *NS = dyn_cast<DINamespace>(Scope)) {
|
2015-04-14 03:01:27 +00:00
|
|
|
processScope(NS->getScope());
|
2015-06-29 23:03:47 +00:00
|
|
|
} else if (auto *M = dyn_cast<DIModule>(Scope)) {
|
|
|
|
processScope(M->getScope());
|
2013-11-08 08:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-29 16:38:44 +00:00
|
|
|
void DebugInfoFinder::processSubprogram(DISubprogram *SP) {
|
2013-11-08 08:13:15 +00:00
|
|
|
if (!addSubprogram(SP))
|
|
|
|
return;
|
2019-05-07 02:06:37 +00:00
|
|
|
processScope(SP->getScope());
|
[DebugInfo][OPT] Fixing a couple of DI duplication bugs of CloneModule
As demonstrated by the regression tests added in this patch, the
following cases are valid cases:
1. A Function with no DISubprogram attached, but various debug info
related to its instructions, coming, for instance, from an inlined
function, also defined somewhere else in the same module;
2. ... or coming exclusively from the functions inlined and eliminated
from the module entirely.
The ValueMap shared between CloneFunctionInto calls within CloneModule
needs to contain identity mappings for all of the DISubprogram's to
prevent them from being duplicated by MapMetadata / RemapInstruction
calls, this is achieved via DebugInfoFinder collecting all the
DISubprogram's. However, CloneFunctionInto was missing calls into
DebugInfoFinder for functions w/o DISubprogram's attached, but still
referring DISubprogram's from within (case 1). This patch fixes that.
The fix above, however, exposes another issue: if a module contains a
DISubprogram referenced only indirectly from other debug info
metadata, but not attached to any Function defined within the module
(case 2), cloning such a module causes a DICompileUnit duplication: it
will be moved in indirecty via a DISubprogram by DebugInfoFinder first
(because of the first bug fix described above), without being
self-mapped within the shared ValueMap, and then will be copied during
named metadata cloning. So this patch makes sure DebugInfoFinder
visits DICompileUnit's referenced from DISubprogram's as it goes w/o
re-processing llvm.dbg.cu list over and over again for every function
cloned, and makes sure that CloneFunctionInto self-maps
DICompileUnit's referenced from the entire function, not just its own
DISubprogram attached that may also be missing.
The most convenient way of tesing CloneModule I found is to rely on
CloneModule call from `opt -run-twice`, instead of writing tedious
unit tests. That feature has a couple of properties that makes it hard
to use for this purpose though:
1. CloneModule doesn't copy source filename, making `opt -run-twice`
report it as a difference.
2. `opt -run-twice` does the second run on the original module, not
its clone, making the result of cloning completely invisible in opt's
actual output with and without `-run-twice` both, which directly
contradicts `opt -run-twice`s own error message.
This patch fixes this as well.
Reviewed By: aprantl
Reviewers: loladiro, GorNishanov, espindola, echristo, dexonsmith
Subscribers: vsk, debug-info, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D45593
llvm-svn: 330069
2018-04-13 21:22:24 +00:00
|
|
|
// Some of the users, e.g. CloneFunctionInto / CloneModule, need to set up a
|
|
|
|
// ValueMap containing identity mappings for all of the DICompileUnit's, not
|
|
|
|
// just DISubprogram's, referenced from anywhere within the Function being
|
|
|
|
// cloned prior to calling MapMetadata / RemapInstruction to avoid their
|
|
|
|
// duplication later as DICompileUnit's are also directly referenced by
|
|
|
|
// llvm.dbg.cu list. Thefore we need to collect DICompileUnit's here as well.
|
|
|
|
// Also, DICompileUnit's may reference DISubprogram's too and therefore need
|
|
|
|
// to be at least looked through.
|
|
|
|
processCompileUnit(SP->getUnit());
|
2015-04-14 03:40:37 +00:00
|
|
|
processType(SP->getType());
|
|
|
|
for (auto *Element : SP->getTemplateParams()) {
|
2015-04-29 16:38:44 +00:00
|
|
|
if (auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) {
|
2019-05-07 02:06:37 +00:00
|
|
|
processType(TType->getType());
|
2015-04-29 16:38:44 +00:00
|
|
|
} else if (auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) {
|
2019-05-07 02:06:37 +00:00
|
|
|
processType(TVal->getType());
|
2013-11-08 08:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-16 16:56:24 -08:00
|
|
|
void DebugInfoFinder::processVariable(const Module &M,
|
|
|
|
const DILocalVariable *DV) {
|
2014-11-19 07:49:26 +00:00
|
|
|
if (!NodesSeen.insert(DV).second)
|
2013-11-08 08:13:15 +00:00
|
|
|
return;
|
2015-04-14 02:22:36 +00:00
|
|
|
processScope(DV->getScope());
|
2019-05-07 02:06:37 +00:00
|
|
|
processType(DV->getType());
|
2013-11-08 08:13:15 +00:00
|
|
|
}
|
|
|
|
|
2015-04-29 16:38:44 +00:00
|
|
|
bool DebugInfoFinder::addType(DIType *DT) {
|
2013-11-08 08:13:15 +00:00
|
|
|
if (!DT)
|
|
|
|
return false;
|
|
|
|
|
2014-11-19 07:49:26 +00:00
|
|
|
if (!NodesSeen.insert(DT).second)
|
2013-11-08 08:13:15 +00:00
|
|
|
return false;
|
|
|
|
|
2015-04-29 16:38:44 +00:00
|
|
|
TYs.push_back(const_cast<DIType *>(DT));
|
2013-11-08 08:13:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-29 16:38:44 +00:00
|
|
|
bool DebugInfoFinder::addCompileUnit(DICompileUnit *CU) {
|
2013-11-08 08:13:15 +00:00
|
|
|
if (!CU)
|
|
|
|
return false;
|
2014-11-19 07:49:26 +00:00
|
|
|
if (!NodesSeen.insert(CU).second)
|
2013-11-08 08:13:15 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
CUs.push_back(CU);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-20 02:09:43 +00:00
|
|
|
bool DebugInfoFinder::addGlobalVariable(DIGlobalVariableExpression *DIG) {
|
2014-11-19 07:49:26 +00:00
|
|
|
if (!NodesSeen.insert(DIG).second)
|
2013-11-08 08:13:15 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
GVs.push_back(DIG);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-29 16:38:44 +00:00
|
|
|
bool DebugInfoFinder::addSubprogram(DISubprogram *SP) {
|
2013-11-08 08:13:15 +00:00
|
|
|
if (!SP)
|
|
|
|
return false;
|
|
|
|
|
2014-11-19 07:49:26 +00:00
|
|
|
if (!NodesSeen.insert(SP).second)
|
2013-11-08 08:13:15 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
SPs.push_back(SP);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-29 16:38:44 +00:00
|
|
|
bool DebugInfoFinder::addScope(DIScope *Scope) {
|
2013-11-08 08:13:15 +00:00
|
|
|
if (!Scope)
|
|
|
|
return false;
|
|
|
|
// FIXME: Ocaml binding generates a scope with no content, we treat it
|
|
|
|
// as null for now.
|
|
|
|
if (Scope->getNumOperands() == 0)
|
|
|
|
return false;
|
2014-11-19 07:49:26 +00:00
|
|
|
if (!NodesSeen.insert(Scope).second)
|
2013-11-08 08:13:15 +00:00
|
|
|
return false;
|
|
|
|
Scopes.push_back(Scope);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-15 11:22:06 -08:00
|
|
|
static MDNode *updateLoopMetadataDebugLocationsImpl(
|
2021-05-26 18:23:02 -07:00
|
|
|
MDNode *OrigLoopID, function_ref<Metadata *(Metadata *)> Updater) {
|
2020-01-15 11:22:06 -08:00
|
|
|
assert(OrigLoopID && OrigLoopID->getNumOperands() > 0 &&
|
|
|
|
"Loop ID needs at least one operand");
|
|
|
|
assert(OrigLoopID && OrigLoopID->getOperand(0).get() == OrigLoopID &&
|
|
|
|
"Loop ID should refer to itself");
|
|
|
|
|
|
|
|
// Save space for the self-referential LoopID.
|
|
|
|
SmallVector<Metadata *, 4> MDs = {nullptr};
|
|
|
|
|
2024-02-05 15:30:35 -08:00
|
|
|
for (unsigned i = 1; i < OrigLoopID->getNumOperands(); ++i) {
|
|
|
|
Metadata *MD = OrigLoopID->getOperand(i);
|
2021-05-26 18:23:02 -07:00
|
|
|
if (!MD)
|
|
|
|
MDs.push_back(nullptr);
|
|
|
|
else if (Metadata *NewMD = Updater(MD))
|
|
|
|
MDs.push_back(NewMD);
|
2020-01-15 11:22:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
MDNode *NewLoopID = MDNode::getDistinct(OrigLoopID->getContext(), MDs);
|
|
|
|
// Insert the self-referential LoopID.
|
|
|
|
NewLoopID->replaceOperandWith(0, NewLoopID);
|
|
|
|
return NewLoopID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void llvm::updateLoopMetadataDebugLocations(
|
2021-05-26 18:23:02 -07:00
|
|
|
Instruction &I, function_ref<Metadata *(Metadata *)> Updater) {
|
2020-01-15 11:22:06 -08:00
|
|
|
MDNode *OrigLoopID = I.getMetadata(LLVMContext::MD_loop);
|
|
|
|
if (!OrigLoopID)
|
|
|
|
return;
|
|
|
|
MDNode *NewLoopID = updateLoopMetadataDebugLocationsImpl(OrigLoopID, Updater);
|
|
|
|
I.setMetadata(LLVMContext::MD_loop, NewLoopID);
|
|
|
|
}
|
|
|
|
|
2021-05-26 18:23:02 -07:00
|
|
|
/// Return true if a node is a DILocation or if a DILocation is
|
|
|
|
/// indirectly referenced by one of the node's children.
|
|
|
|
static bool isDILocationReachable(SmallPtrSetImpl<Metadata *> &Visited,
|
|
|
|
SmallPtrSetImpl<Metadata *> &Reachable,
|
|
|
|
Metadata *MD) {
|
|
|
|
MDNode *N = dyn_cast_or_null<MDNode>(MD);
|
|
|
|
if (!N)
|
|
|
|
return false;
|
2021-06-02 09:52:45 -07:00
|
|
|
if (isa<DILocation>(N) || Reachable.count(N))
|
2021-05-26 18:23:02 -07:00
|
|
|
return true;
|
|
|
|
if (!Visited.insert(N).second)
|
|
|
|
return false;
|
|
|
|
for (auto &OpIt : N->operands()) {
|
|
|
|
Metadata *Op = OpIt.get();
|
|
|
|
if (isDILocationReachable(Visited, Reachable, Op)) {
|
2023-01-25 09:52:48 -08:00
|
|
|
// Don't return just yet as we want to visit all MD's children to
|
|
|
|
// initialize DILocationReachable in stripDebugLocFromLoopID
|
2021-05-26 18:23:02 -07:00
|
|
|
Reachable.insert(N);
|
|
|
|
}
|
|
|
|
}
|
2023-01-25 09:52:48 -08:00
|
|
|
return Reachable.count(N);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isAllDILocation(SmallPtrSetImpl<Metadata *> &Visited,
|
|
|
|
SmallPtrSetImpl<Metadata *> &AllDILocation,
|
|
|
|
const SmallPtrSetImpl<Metadata *> &DIReachable,
|
|
|
|
Metadata *MD) {
|
|
|
|
MDNode *N = dyn_cast_or_null<MDNode>(MD);
|
|
|
|
if (!N)
|
|
|
|
return false;
|
|
|
|
if (isa<DILocation>(N) || AllDILocation.count(N))
|
|
|
|
return true;
|
|
|
|
if (!DIReachable.count(N))
|
|
|
|
return false;
|
|
|
|
if (!Visited.insert(N).second)
|
|
|
|
return false;
|
|
|
|
for (auto &OpIt : N->operands()) {
|
|
|
|
Metadata *Op = OpIt.get();
|
|
|
|
if (Op == MD)
|
|
|
|
continue;
|
|
|
|
if (!isAllDILocation(Visited, AllDILocation, DIReachable, Op)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AllDILocation.insert(N);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Metadata *
|
|
|
|
stripLoopMDLoc(const SmallPtrSetImpl<Metadata *> &AllDILocation,
|
|
|
|
const SmallPtrSetImpl<Metadata *> &DIReachable, Metadata *MD) {
|
|
|
|
if (isa<DILocation>(MD) || AllDILocation.count(MD))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if (!DIReachable.count(MD))
|
|
|
|
return MD;
|
|
|
|
|
|
|
|
MDNode *N = dyn_cast_or_null<MDNode>(MD);
|
|
|
|
if (!N)
|
|
|
|
return MD;
|
|
|
|
|
|
|
|
SmallVector<Metadata *, 4> Args;
|
|
|
|
bool HasSelfRef = false;
|
|
|
|
for (unsigned i = 0; i < N->getNumOperands(); ++i) {
|
|
|
|
Metadata *A = N->getOperand(i);
|
|
|
|
if (!A) {
|
|
|
|
Args.push_back(nullptr);
|
|
|
|
} else if (A == MD) {
|
|
|
|
assert(i == 0 && "expected i==0 for self-reference");
|
|
|
|
HasSelfRef = true;
|
|
|
|
Args.push_back(nullptr);
|
|
|
|
} else if (Metadata *NewArg =
|
|
|
|
stripLoopMDLoc(AllDILocation, DIReachable, A)) {
|
|
|
|
Args.push_back(NewArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Args.empty() || (HasSelfRef && Args.size() == 1))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
MDNode *NewMD = N->isDistinct() ? MDNode::getDistinct(N->getContext(), Args)
|
|
|
|
: MDNode::get(N->getContext(), Args);
|
|
|
|
if (HasSelfRef)
|
|
|
|
NewMD->replaceOperandWith(0, NewMD);
|
|
|
|
return NewMD;
|
2021-05-26 18:23:02 -07:00
|
|
|
}
|
|
|
|
|
2017-05-05 22:30:37 +00:00
|
|
|
static MDNode *stripDebugLocFromLoopID(MDNode *N) {
|
2019-10-07 18:14:24 +00:00
|
|
|
assert(!N->operands().empty() && "Missing self reference?");
|
2023-01-25 09:52:48 -08:00
|
|
|
SmallPtrSet<Metadata *, 8> Visited, DILocationReachable, AllDILocation;
|
2021-05-26 18:23:02 -07:00
|
|
|
// If we already visited N, there is nothing to do.
|
|
|
|
if (!Visited.insert(N).second)
|
|
|
|
return N;
|
2017-01-28 11:22:05 +00:00
|
|
|
|
2021-05-26 18:23:02 -07:00
|
|
|
// If there is no debug location, we do not have to rewrite this
|
|
|
|
// MDNode. This loop also initializes DILocationReachable, later
|
|
|
|
// needed by updateLoopMetadataDebugLocationsImpl; the use of
|
|
|
|
// count_if avoids an early exit.
|
2023-01-25 09:52:48 -08:00
|
|
|
if (!llvm::count_if(llvm::drop_begin(N->operands()),
|
2022-09-05 14:42:34 -07:00
|
|
|
[&Visited, &DILocationReachable](const MDOperand &Op) {
|
|
|
|
return isDILocationReachable(
|
|
|
|
Visited, DILocationReachable, Op.get());
|
|
|
|
}))
|
2017-01-28 11:22:05 +00:00
|
|
|
return N;
|
|
|
|
|
2023-01-25 09:52:48 -08:00
|
|
|
Visited.clear();
|
2017-03-19 13:54:57 +00:00
|
|
|
// If there is only the debug location without any actual loop metadata, we
|
2017-01-28 11:22:05 +00:00
|
|
|
// can remove the metadata.
|
2022-08-14 16:25:36 -07:00
|
|
|
if (llvm::all_of(llvm::drop_begin(N->operands()),
|
2023-01-25 09:52:48 -08:00
|
|
|
[&Visited, &AllDILocation,
|
|
|
|
&DILocationReachable](const MDOperand &Op) {
|
|
|
|
return isAllDILocation(Visited, AllDILocation,
|
|
|
|
DILocationReachable, Op.get());
|
2022-08-14 16:25:36 -07:00
|
|
|
}))
|
2017-01-28 11:22:05 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2021-05-26 18:23:02 -07:00
|
|
|
return updateLoopMetadataDebugLocationsImpl(
|
2023-01-25 09:52:48 -08:00
|
|
|
N, [&AllDILocation, &DILocationReachable](Metadata *MD) -> Metadata * {
|
|
|
|
return stripLoopMDLoc(AllDILocation, DILocationReachable, MD);
|
2021-05-26 18:23:02 -07:00
|
|
|
});
|
2017-01-28 11:22:05 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 21:36:43 +00:00
|
|
|
bool llvm::stripDebugInfo(Function &F) {
|
|
|
|
bool Changed = false;
|
2018-05-31 13:29:58 +00:00
|
|
|
if (F.hasMetadata(LLVMContext::MD_dbg)) {
|
2015-11-05 22:03:56 +00:00
|
|
|
Changed = true;
|
|
|
|
F.setSubprogram(nullptr);
|
|
|
|
}
|
2016-05-07 04:10:52 +00:00
|
|
|
|
2021-05-26 18:23:02 -07:00
|
|
|
DenseMap<MDNode *, MDNode *> LoopIDsMap;
|
2015-03-30 21:36:43 +00:00
|
|
|
for (BasicBlock &BB : F) {
|
2021-11-05 19:39:06 -07:00
|
|
|
for (Instruction &I : llvm::make_early_inc_range(BB)) {
|
2016-05-14 04:58:35 +00:00
|
|
|
if (isa<DbgInfoIntrinsic>(&I)) {
|
|
|
|
I.eraseFromParent();
|
2016-05-07 04:10:52 +00:00
|
|
|
Changed = true;
|
2016-05-07 05:07:47 +00:00
|
|
|
continue;
|
2016-05-07 04:10:52 +00:00
|
|
|
}
|
2015-03-30 21:36:43 +00:00
|
|
|
if (I.getDebugLoc()) {
|
|
|
|
Changed = true;
|
|
|
|
I.setDebugLoc(DebugLoc());
|
|
|
|
}
|
2021-02-05 14:18:13 -08:00
|
|
|
if (auto *LoopID = I.getMetadata(LLVMContext::MD_loop)) {
|
|
|
|
auto *NewLoopID = LoopIDsMap.lookup(LoopID);
|
|
|
|
if (!NewLoopID)
|
|
|
|
NewLoopID = LoopIDsMap[LoopID] = stripDebugLocFromLoopID(LoopID);
|
|
|
|
if (NewLoopID != LoopID)
|
|
|
|
I.setMetadata(LLVMContext::MD_loop, NewLoopID);
|
|
|
|
}
|
2022-11-03 09:50:31 +00:00
|
|
|
// Strip other attachments that are or use debug info.
|
|
|
|
if (I.hasMetadataOtherThanDebugLoc()) {
|
|
|
|
// Heapallocsites point into the DIType system.
|
2021-03-15 16:23:31 -07:00
|
|
|
I.setMetadata("heapallocsite", nullptr);
|
2022-11-03 09:50:31 +00:00
|
|
|
// DIAssignID are debug info metadata primitives.
|
|
|
|
I.setMetadata(LLVMContext::MD_DIAssignID, nullptr);
|
|
|
|
}
|
2024-03-12 14:53:13 +00:00
|
|
|
I.dropDbgRecords();
|
2017-01-28 11:22:05 +00:00
|
|
|
}
|
2015-03-30 21:36:43 +00:00
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2013-11-22 22:06:31 +00:00
|
|
|
bool llvm::StripDebugInfo(Module &M) {
|
|
|
|
bool Changed = false;
|
|
|
|
|
2021-02-28 10:59:23 -08:00
|
|
|
for (NamedMDNode &NMD : llvm::make_early_inc_range(M.named_metadata())) {
|
2016-10-17 20:05:35 +00:00
|
|
|
// We're stripping debug info, and without them, coverage information
|
|
|
|
// doesn't quite make sense.
|
2023-12-11 21:01:36 -08:00
|
|
|
if (NMD.getName().starts_with("llvm.dbg.") ||
|
2021-02-28 10:59:23 -08:00
|
|
|
NMD.getName() == "llvm.gcov") {
|
|
|
|
NMD.eraseFromParent();
|
2013-11-22 22:06:31 +00:00
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-30 21:36:43 +00:00
|
|
|
for (Function &F : M)
|
|
|
|
Changed |= stripDebugInfo(F);
|
|
|
|
|
2016-10-10 17:53:33 +00:00
|
|
|
for (auto &GV : M.globals()) {
|
2018-05-31 13:29:58 +00:00
|
|
|
Changed |= GV.eraseMetadata(LLVMContext::MD_dbg);
|
2016-10-10 17:53:33 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 14:44:59 +00:00
|
|
|
if (GVMaterializer *Materializer = M.getMaterializer())
|
2015-03-30 21:36:43 +00:00
|
|
|
Materializer->setStripDebugInfo();
|
2013-11-22 22:06:31 +00:00
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
2013-12-02 21:29:56 +00:00
|
|
|
|
2016-10-25 18:44:13 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// Helper class to downgrade -g metadata to -gline-tables-only metadata.
|
|
|
|
class DebugTypeInfoRemoval {
|
|
|
|
DenseMap<Metadata *, Metadata *> Replacements;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// The (void)() type.
|
|
|
|
MDNode *EmptySubroutineType;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Remember what linkage name we originally had before stripping. If we end
|
|
|
|
/// up making two subprograms identical who originally had different linkage
|
|
|
|
/// names, then we need to make one of them distinct, to avoid them getting
|
|
|
|
/// uniqued. Maps the new node to the old linkage name.
|
|
|
|
DenseMap<DISubprogram *, StringRef> NewToLinkageName;
|
|
|
|
|
|
|
|
// TODO: Remember the distinct subprogram we created for a given linkage name,
|
|
|
|
// so that we can continue to unique whenever possible. Map <newly created
|
|
|
|
// node, old linkage name> to the first (possibly distinct) mdsubprogram
|
|
|
|
// created for that combination. This is not strictly needed for correctness,
|
|
|
|
// but can cut down on the number of MDNodes and let us diff cleanly with the
|
|
|
|
// output of -gline-tables-only.
|
|
|
|
|
|
|
|
public:
|
|
|
|
DebugTypeInfoRemoval(LLVMContext &C)
|
|
|
|
: EmptySubroutineType(DISubroutineType::get(C, DINode::FlagZero, 0,
|
|
|
|
MDNode::get(C, {}))) {}
|
|
|
|
|
|
|
|
Metadata *map(Metadata *M) {
|
|
|
|
if (!M)
|
|
|
|
return nullptr;
|
|
|
|
auto Replacement = Replacements.find(M);
|
|
|
|
if (Replacement != Replacements.end())
|
|
|
|
return Replacement->second;
|
|
|
|
|
|
|
|
return M;
|
|
|
|
}
|
|
|
|
MDNode *mapNode(Metadata *N) { return dyn_cast_or_null<MDNode>(map(N)); }
|
|
|
|
|
|
|
|
/// Recursively remap N and all its referenced children. Does a DF post-order
|
|
|
|
/// traversal, so as to remap bottoms up.
|
|
|
|
void traverseAndRemap(MDNode *N) { traverse(N); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Create a new DISubprogram, to replace the one given.
|
|
|
|
DISubprogram *getReplacementSubprogram(DISubprogram *MDS) {
|
|
|
|
auto *FileAndScope = cast_or_null<DIFile>(map(MDS->getFile()));
|
|
|
|
StringRef LinkageName = MDS->getName().empty() ? MDS->getLinkageName() : "";
|
|
|
|
DISubprogram *Declaration = nullptr;
|
|
|
|
auto *Type = cast_or_null<DISubroutineType>(map(MDS->getType()));
|
2019-05-07 02:06:37 +00:00
|
|
|
DIType *ContainingType =
|
|
|
|
cast_or_null<DIType>(map(MDS->getContainingType()));
|
2016-10-25 18:44:13 +00:00
|
|
|
auto *Unit = cast_or_null<DICompileUnit>(map(MDS->getUnit()));
|
|
|
|
auto Variables = nullptr;
|
|
|
|
auto TemplateParams = nullptr;
|
|
|
|
|
|
|
|
// Make a distinct DISubprogram, for situations that warrent it.
|
|
|
|
auto distinctMDSubprogram = [&]() {
|
|
|
|
return DISubprogram::getDistinct(
|
|
|
|
MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
|
2018-11-19 18:29:28 +00:00
|
|
|
FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(),
|
|
|
|
ContainingType, MDS->getVirtualIndex(), MDS->getThisAdjustment(),
|
|
|
|
MDS->getFlags(), MDS->getSPFlags(), Unit, TemplateParams, Declaration,
|
|
|
|
Variables);
|
2016-10-25 18:44:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (MDS->isDistinct())
|
|
|
|
return distinctMDSubprogram();
|
|
|
|
|
|
|
|
auto *NewMDS = DISubprogram::get(
|
|
|
|
MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
|
2018-11-19 18:29:28 +00:00
|
|
|
FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(), ContainingType,
|
|
|
|
MDS->getVirtualIndex(), MDS->getThisAdjustment(), MDS->getFlags(),
|
|
|
|
MDS->getSPFlags(), Unit, TemplateParams, Declaration, Variables);
|
2016-10-25 18:44:13 +00:00
|
|
|
|
|
|
|
StringRef OldLinkageName = MDS->getLinkageName();
|
|
|
|
|
|
|
|
// See if we need to make a distinct one.
|
|
|
|
auto OrigLinkage = NewToLinkageName.find(NewMDS);
|
|
|
|
if (OrigLinkage != NewToLinkageName.end()) {
|
|
|
|
if (OrigLinkage->second == OldLinkageName)
|
|
|
|
// We're good.
|
|
|
|
return NewMDS;
|
|
|
|
|
|
|
|
// Otherwise, need to make a distinct one.
|
|
|
|
// TODO: Query the map to see if we already have one.
|
|
|
|
return distinctMDSubprogram();
|
|
|
|
}
|
|
|
|
|
|
|
|
NewToLinkageName.insert({NewMDS, MDS->getLinkageName()});
|
|
|
|
return NewMDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a new compile unit, to replace the one given
|
|
|
|
DICompileUnit *getReplacementCU(DICompileUnit *CU) {
|
|
|
|
// Drop skeleton CUs.
|
|
|
|
if (CU->getDWOId())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
auto *File = cast_or_null<DIFile>(map(CU->getFile()));
|
|
|
|
MDTuple *EnumTypes = nullptr;
|
|
|
|
MDTuple *RetainedTypes = nullptr;
|
|
|
|
MDTuple *GlobalVariables = nullptr;
|
|
|
|
MDTuple *ImportedEntities = nullptr;
|
|
|
|
return DICompileUnit::getDistinct(
|
|
|
|
CU->getContext(), CU->getSourceLanguage(), File, CU->getProducer(),
|
|
|
|
CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(),
|
|
|
|
CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes,
|
|
|
|
RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
|
Change debug-info-for-profiling from a TargetOption to a function attribute.
Summary: LTO requires the debug-info-for-profiling to be a function attribute.
Reviewers: echristo, mehdi_amini, dblaikie, probinson, aprantl
Reviewed By: mehdi_amini, dblaikie, aprantl
Subscribers: aprantl, probinson, ahatanak, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D29203
llvm-svn: 293833
2017-02-01 22:45:09 +00:00
|
|
|
CU->getDWOId(), CU->getSplitDebugInlining(),
|
2018-11-13 20:08:10 +00:00
|
|
|
CU->getDebugInfoForProfiling(), CU->getNameTableKind(),
|
2020-03-04 14:12:54 -08:00
|
|
|
CU->getRangesBaseAddress(), CU->getSysRoot(), CU->getSDK());
|
2016-10-25 18:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DILocation *getReplacementMDLocation(DILocation *MLD) {
|
|
|
|
auto *Scope = map(MLD->getScope());
|
|
|
|
auto *InlinedAt = map(MLD->getInlinedAt());
|
|
|
|
if (MLD->isDistinct())
|
|
|
|
return DILocation::getDistinct(MLD->getContext(), MLD->getLine(),
|
|
|
|
MLD->getColumn(), Scope, InlinedAt);
|
|
|
|
return DILocation::get(MLD->getContext(), MLD->getLine(), MLD->getColumn(),
|
|
|
|
Scope, InlinedAt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a new generic MDNode, to replace the one given
|
|
|
|
MDNode *getReplacementMDNode(MDNode *N) {
|
|
|
|
SmallVector<Metadata *, 8> Ops;
|
|
|
|
Ops.reserve(N->getNumOperands());
|
|
|
|
for (auto &I : N->operands())
|
|
|
|
if (I)
|
|
|
|
Ops.push_back(map(I));
|
|
|
|
auto *Ret = MDNode::get(N->getContext(), Ops);
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Attempt to re-map N to a newly created node.
|
|
|
|
void remap(MDNode *N) {
|
|
|
|
if (Replacements.count(N))
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto doRemap = [&](MDNode *N) -> MDNode * {
|
|
|
|
if (!N)
|
|
|
|
return nullptr;
|
|
|
|
if (auto *MDSub = dyn_cast<DISubprogram>(N)) {
|
|
|
|
remap(MDSub->getUnit());
|
|
|
|
return getReplacementSubprogram(MDSub);
|
|
|
|
}
|
|
|
|
if (isa<DISubroutineType>(N))
|
|
|
|
return EmptySubroutineType;
|
|
|
|
if (auto *CU = dyn_cast<DICompileUnit>(N))
|
|
|
|
return getReplacementCU(CU);
|
|
|
|
if (isa<DIFile>(N))
|
|
|
|
return N;
|
|
|
|
if (auto *MDLB = dyn_cast<DILexicalBlockBase>(N))
|
|
|
|
// Remap to our referenced scope (recursively).
|
|
|
|
return mapNode(MDLB->getScope());
|
|
|
|
if (auto *MLD = dyn_cast<DILocation>(N))
|
|
|
|
return getReplacementMDLocation(MLD);
|
|
|
|
|
|
|
|
// Otherwise, if we see these, just drop them now. Not strictly necessary,
|
|
|
|
// but this speeds things up a little.
|
|
|
|
if (isa<DINode>(N))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return getReplacementMDNode(N);
|
|
|
|
};
|
|
|
|
Replacements[N] = doRemap(N);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Do the remapping traversal.
|
|
|
|
void traverse(MDNode *);
|
|
|
|
};
|
|
|
|
|
2017-05-05 22:30:37 +00:00
|
|
|
} // end anonymous namespace
|
2016-10-25 18:44:13 +00:00
|
|
|
|
|
|
|
void DebugTypeInfoRemoval::traverse(MDNode *N) {
|
|
|
|
if (!N || Replacements.count(N))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// To avoid cycles, as well as for efficiency sake, we will sometimes prune
|
|
|
|
// parts of the graph.
|
|
|
|
auto prune = [](MDNode *Parent, MDNode *Child) {
|
|
|
|
if (auto *MDS = dyn_cast<DISubprogram>(Parent))
|
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 02:40:45 +00:00
|
|
|
return Child == MDS->getRetainedNodes().get();
|
2016-10-25 18:44:13 +00:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
SmallVector<MDNode *, 16> ToVisit;
|
|
|
|
DenseSet<MDNode *> Opened;
|
|
|
|
|
|
|
|
// Visit each node starting at N in post order, and map them.
|
|
|
|
ToVisit.push_back(N);
|
|
|
|
while (!ToVisit.empty()) {
|
|
|
|
auto *N = ToVisit.back();
|
|
|
|
if (!Opened.insert(N).second) {
|
|
|
|
// Close it.
|
|
|
|
remap(N);
|
|
|
|
ToVisit.pop_back();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (auto &I : N->operands())
|
|
|
|
if (auto *MDN = dyn_cast_or_null<MDNode>(I))
|
|
|
|
if (!Opened.count(MDN) && !Replacements.count(MDN) && !prune(N, MDN) &&
|
|
|
|
!isa<DICompileUnit>(MDN))
|
|
|
|
ToVisit.push_back(MDN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool llvm::stripNonLineTableDebugInfo(Module &M) {
|
|
|
|
bool Changed = false;
|
|
|
|
|
|
|
|
// First off, delete the debug intrinsics.
|
|
|
|
auto RemoveUses = [&](StringRef Name) {
|
|
|
|
if (auto *DbgVal = M.getFunction(Name)) {
|
|
|
|
while (!DbgVal->use_empty())
|
|
|
|
cast<Instruction>(DbgVal->user_back())->eraseFromParent();
|
|
|
|
DbgVal->eraseFromParent();
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
RemoveUses("llvm.dbg.declare");
|
2020-04-02 16:11:49 -07:00
|
|
|
RemoveUses("llvm.dbg.label");
|
2016-10-25 18:44:13 +00:00
|
|
|
RemoveUses("llvm.dbg.value");
|
|
|
|
|
|
|
|
// Delete non-CU debug info named metadata nodes.
|
|
|
|
for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end();
|
|
|
|
NMI != NME;) {
|
|
|
|
NamedMDNode *NMD = &*NMI;
|
|
|
|
++NMI;
|
|
|
|
// Specifically keep dbg.cu around.
|
|
|
|
if (NMD->getName() == "llvm.dbg.cu")
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Drop all dbg attachments from global variables.
|
|
|
|
for (auto &GV : M.globals())
|
|
|
|
GV.eraseMetadata(LLVMContext::MD_dbg);
|
|
|
|
|
|
|
|
DebugTypeInfoRemoval Mapper(M.getContext());
|
2017-05-05 22:30:37 +00:00
|
|
|
auto remap = [&](MDNode *Node) -> MDNode * {
|
2016-10-25 18:44:13 +00:00
|
|
|
if (!Node)
|
|
|
|
return nullptr;
|
|
|
|
Mapper.traverseAndRemap(Node);
|
|
|
|
auto *NewNode = Mapper.mapNode(Node);
|
|
|
|
Changed |= Node != NewNode;
|
|
|
|
Node = NewNode;
|
|
|
|
return NewNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Rewrite the DebugLocs to be equivalent to what
|
|
|
|
// -gline-tables-only would have created.
|
|
|
|
for (auto &F : M) {
|
|
|
|
if (auto *SP = F.getSubprogram()) {
|
|
|
|
Mapper.traverseAndRemap(SP);
|
|
|
|
auto *NewSP = cast<DISubprogram>(Mapper.mapNode(SP));
|
|
|
|
Changed |= SP != NewSP;
|
|
|
|
F.setSubprogram(NewSP);
|
|
|
|
}
|
|
|
|
for (auto &BB : F) {
|
|
|
|
for (auto &I : BB) {
|
2020-07-01 12:37:47 +01:00
|
|
|
auto remapDebugLoc = [&](const DebugLoc &DL) -> DebugLoc {
|
2017-03-30 20:10:56 +00:00
|
|
|
auto *Scope = DL.getScope();
|
|
|
|
MDNode *InlinedAt = DL.getInlinedAt();
|
|
|
|
Scope = remap(Scope);
|
|
|
|
InlinedAt = remap(InlinedAt);
|
2020-12-11 12:45:22 -08:00
|
|
|
return DILocation::get(M.getContext(), DL.getLine(), DL.getCol(),
|
|
|
|
Scope, InlinedAt);
|
2017-03-30 20:10:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (I.getDebugLoc() != DebugLoc())
|
|
|
|
I.setDebugLoc(remapDebugLoc(I.getDebugLoc()));
|
|
|
|
|
2020-04-30 13:22:22 -07:00
|
|
|
// Remap DILocations in llvm.loop attachments.
|
2021-05-26 18:23:02 -07:00
|
|
|
updateLoopMetadataDebugLocations(I, [&](Metadata *MD) -> Metadata * {
|
|
|
|
if (auto *Loc = dyn_cast_or_null<DILocation>(MD))
|
|
|
|
return remapDebugLoc(Loc).get();
|
|
|
|
return MD;
|
2020-04-30 13:22:22 -07:00
|
|
|
});
|
2021-03-15 16:16:36 -07:00
|
|
|
|
|
|
|
// Strip heapallocsite attachments, they point into the DIType system.
|
|
|
|
if (I.hasMetadataOtherThanDebugLoc())
|
|
|
|
I.setMetadata("heapallocsite", nullptr);
|
2024-01-23 10:43:37 +00:00
|
|
|
|
2024-03-13 16:39:35 +00:00
|
|
|
// Strip any DbgRecords attached.
|
2024-03-12 14:53:13 +00:00
|
|
|
I.dropDbgRecords();
|
2016-10-25 18:44:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new llvm.dbg.cu, which is equivalent to the one
|
|
|
|
// -gline-tables-only would have created.
|
2023-02-07 09:47:03 -08:00
|
|
|
for (auto &NMD : M.named_metadata()) {
|
2016-10-25 18:44:13 +00:00
|
|
|
SmallVector<MDNode *, 8> Ops;
|
|
|
|
for (MDNode *Op : NMD.operands())
|
|
|
|
Ops.push_back(remap(Op));
|
2018-07-03 12:39:52 +00:00
|
|
|
|
2016-10-25 18:44:13 +00:00
|
|
|
if (!Changed)
|
|
|
|
continue;
|
2018-07-03 12:39:52 +00:00
|
|
|
|
2016-10-25 18:44:13 +00:00
|
|
|
NMD.clearOperands();
|
|
|
|
for (auto *Op : Ops)
|
|
|
|
if (Op)
|
|
|
|
NMD.addOperand(Op);
|
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2013-12-03 00:12:14 +00:00
|
|
|
unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
|
2015-02-16 06:04:53 +00:00
|
|
|
if (auto *Val = mdconst::dyn_extract_or_null<ConstantInt>(
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-09 18:38:53 +00:00
|
|
|
M.getModuleFlag("Debug Info Version")))
|
|
|
|
return Val->getZExtValue();
|
|
|
|
return 0;
|
2013-12-02 21:29:56 +00:00
|
|
|
}
|
2017-10-02 18:13:14 +00:00
|
|
|
|
2023-05-15 07:04:59 +00:00
|
|
|
void Instruction::applyMergedLocation(DILocation *LocA, DILocation *LocB) {
|
2018-08-23 22:35:58 +00:00
|
|
|
setDebugLoc(DILocation::getMergedLocation(LocA, LocB));
|
2017-10-02 18:13:14 +00:00
|
|
|
}
|
2017-11-01 22:18:52 +00:00
|
|
|
|
2022-11-09 10:41:28 +00:00
|
|
|
void Instruction::mergeDIAssignID(
|
|
|
|
ArrayRef<const Instruction *> SourceInstructions) {
|
|
|
|
// Replace all uses (and attachments) of all the DIAssignIDs
|
|
|
|
// on SourceInstructions with a single merged value.
|
2022-11-09 13:03:12 +01:00
|
|
|
assert(getFunction() && "Uninserted instruction merged");
|
2022-11-09 10:41:28 +00:00
|
|
|
// Collect up the DIAssignID tags.
|
|
|
|
SmallVector<DIAssignID *, 4> IDs;
|
|
|
|
for (const Instruction *I : SourceInstructions) {
|
|
|
|
if (auto *MD = I->getMetadata(LLVMContext::MD_DIAssignID))
|
|
|
|
IDs.push_back(cast<DIAssignID>(MD));
|
2022-11-09 13:03:12 +01:00
|
|
|
assert(getFunction() == I->getFunction() &&
|
2022-11-09 10:41:28 +00:00
|
|
|
"Merging with instruction from another function not allowed");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add this instruction's DIAssignID too, if it has one.
|
|
|
|
if (auto *MD = getMetadata(LLVMContext::MD_DIAssignID))
|
|
|
|
IDs.push_back(cast<DIAssignID>(MD));
|
|
|
|
|
|
|
|
if (IDs.empty())
|
|
|
|
return; // No DIAssignID tags to process.
|
|
|
|
|
|
|
|
DIAssignID *MergeID = IDs[0];
|
|
|
|
for (auto It = std::next(IDs.begin()), End = IDs.end(); It != End; ++It) {
|
|
|
|
if (*It != MergeID)
|
|
|
|
at::RAUW(*It, MergeID);
|
|
|
|
}
|
|
|
|
setMetadata(LLVMContext::MD_DIAssignID, MergeID);
|
|
|
|
}
|
|
|
|
|
2020-09-08 13:39:52 -07:00
|
|
|
void Instruction::updateLocationAfterHoist() { dropLocation(); }
|
|
|
|
|
|
|
|
void Instruction::dropLocation() {
|
|
|
|
const DebugLoc &DL = getDebugLoc();
|
|
|
|
if (!DL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If this isn't a call, drop the location to allow a location from a
|
|
|
|
// preceding instruction to propagate.
|
2022-09-27 12:15:36 +00:00
|
|
|
bool MayLowerToCall = false;
|
|
|
|
if (isa<CallBase>(this)) {
|
|
|
|
auto *II = dyn_cast<IntrinsicInst>(this);
|
|
|
|
MayLowerToCall =
|
|
|
|
!II || IntrinsicInst::mayLowerToFunctionCall(II->getIntrinsicID());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!MayLowerToCall) {
|
2020-09-08 13:39:52 -07:00
|
|
|
setDebugLoc(DebugLoc());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set a line 0 location for calls to preserve scope information in case
|
|
|
|
// inlining occurs.
|
2020-12-11 12:45:22 -08:00
|
|
|
DISubprogram *SP = getFunction()->getSubprogram();
|
2020-09-08 13:39:52 -07:00
|
|
|
if (SP)
|
|
|
|
// If a function scope is available, set it on the line 0 location. When
|
|
|
|
// hoisting a call to a predecessor block, using the function scope avoids
|
|
|
|
// making it look like the callee was reached earlier than it should be.
|
2020-12-11 12:45:22 -08:00
|
|
|
setDebugLoc(DILocation::get(getContext(), 0, 0, SP));
|
2020-09-08 13:39:52 -07:00
|
|
|
else
|
|
|
|
// The parent function has no scope. Go ahead and drop the location. If
|
|
|
|
// the parent function is inlined, and the callee has a subprogram, the
|
|
|
|
// inliner will attach a location to the call.
|
|
|
|
//
|
|
|
|
// One alternative is to set a line 0 location with the existing scope and
|
|
|
|
// inlinedAt info. The location might be sensitive to when inlining occurs.
|
|
|
|
setDebugLoc(DebugLoc());
|
|
|
|
}
|
|
|
|
|
2017-11-01 22:18:52 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// LLVM C API implementations.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static unsigned map_from_llvmDWARFsourcelanguage(LLVMDWARFSourceLanguage lang) {
|
|
|
|
switch (lang) {
|
llvm-dwarfdump: Improve/fix pretty printing of array dimensions
This is to address post-commit feedback from Paul Robinson on r348954.
The original commit misinterprets count and upper bound as the same thing (I thought I saw GCC producing an upper bound the same as Clang's count, but GCC correctly produces an upper bound that's one less than the count (in C, that is, where arrays are zero indexed)).
I want to preserve the C-like output for the common case, so in the absence of a lower bound the count (or one greater than the upper bound) is rendered between []. In the trickier cases, where a lower bound is specified, a half-open range is used (eg: lower bound 1, count 2 would be "[1, 3)" and an unknown parts use a '?' (eg: "[1, ?)" or "[?, 7)" or "[?, ? + 3)").
Reviewers: aprantl, probinson, JDevlieghere
Differential Revision: https://reviews.llvm.org/D55721
llvm-svn: 349670
2018-12-19 19:34:24 +00:00
|
|
|
#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
|
|
|
|
case LLVMDWARFSourceLanguage##NAME: \
|
|
|
|
return ID;
|
2017-11-01 22:18:52 +00:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.def"
|
|
|
|
#undef HANDLE_DW_LANG
|
|
|
|
}
|
|
|
|
llvm_unreachable("Unhandled Tag");
|
|
|
|
}
|
|
|
|
|
2018-04-02 00:17:40 +00:00
|
|
|
template <typename DIT> DIT *unwrapDI(LLVMMetadataRef Ref) {
|
|
|
|
return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DINode::DIFlags map_from_llvmDIFlags(LLVMDIFlags Flags) {
|
|
|
|
return static_cast<DINode::DIFlags>(Flags);
|
|
|
|
}
|
|
|
|
|
2018-05-10 18:23:55 +00:00
|
|
|
static LLVMDIFlags map_to_llvmDIFlags(DINode::DIFlags Flags) {
|
|
|
|
return static_cast<LLVMDIFlags>(Flags);
|
|
|
|
}
|
|
|
|
|
2018-11-19 18:29:28 +00:00
|
|
|
static DISubprogram::DISPFlags
|
|
|
|
pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized) {
|
|
|
|
return DISubprogram::toSPFlags(IsLocalToUnit, IsDefinition, IsOptimized);
|
|
|
|
}
|
|
|
|
|
2017-11-01 22:18:52 +00:00
|
|
|
unsigned LLVMDebugMetadataVersion() {
|
|
|
|
return DEBUG_METADATA_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMDIBuilderRef LLVMCreateDIBuilderDisallowUnresolved(LLVMModuleRef M) {
|
|
|
|
return wrap(new DIBuilder(*unwrap(M), false));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMDIBuilderRef LLVMCreateDIBuilder(LLVMModuleRef M) {
|
|
|
|
return wrap(new DIBuilder(*unwrap(M)));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMGetModuleDebugMetadataVersion(LLVMModuleRef M) {
|
|
|
|
return getDebugMetadataVersionFromModule(*unwrap(M));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMBool LLVMStripModuleDebugInfo(LLVMModuleRef M) {
|
|
|
|
return StripDebugInfo(*unwrap(M));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeDIBuilder(LLVMDIBuilderRef Builder) {
|
|
|
|
delete unwrap(Builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder) {
|
|
|
|
unwrap(Builder)->finalize();
|
|
|
|
}
|
|
|
|
|
2021-09-30 20:57:53 -07:00
|
|
|
void LLVMDIBuilderFinalizeSubprogram(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef subprogram) {
|
|
|
|
unwrap(Builder)->finalizeSubprogram(unwrapDI<DISubprogram>(subprogram));
|
|
|
|
}
|
|
|
|
|
2017-11-01 22:18:52 +00:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang,
|
|
|
|
LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen,
|
|
|
|
LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
|
|
|
|
unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
|
|
|
|
LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
|
2020-03-04 14:12:54 -08:00
|
|
|
LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen,
|
|
|
|
const char *SDK, size_t SDKLen) {
|
2018-04-02 00:17:40 +00:00
|
|
|
auto File = unwrapDI<DIFile>(FileRef);
|
2017-11-01 22:18:52 +00:00
|
|
|
|
|
|
|
return wrap(unwrap(Builder)->createCompileUnit(
|
2020-01-14 13:37:04 -08:00
|
|
|
map_from_llvmDWARFsourcelanguage(Lang), File,
|
|
|
|
StringRef(Producer, ProducerLen), isOptimized, StringRef(Flags, FlagsLen),
|
|
|
|
RuntimeVer, StringRef(SplitName, SplitNameLen),
|
|
|
|
static_cast<DICompileUnit::DebugEmissionKind>(Kind), DWOId,
|
|
|
|
SplitDebugInlining, DebugInfoForProfiling,
|
|
|
|
DICompileUnit::DebugNameTableKind::Default, false,
|
2020-03-04 14:12:54 -08:00
|
|
|
StringRef(SysRoot, SysRootLen), StringRef(SDK, SDKLen)));
|
2017-11-01 22:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
|
|
|
|
size_t FilenameLen, const char *Directory,
|
|
|
|
size_t DirectoryLen) {
|
|
|
|
return wrap(unwrap(Builder)->createFile(StringRef(Filename, FilenameLen),
|
|
|
|
StringRef(Directory, DirectoryLen)));
|
|
|
|
}
|
|
|
|
|
2018-04-23 13:51:43 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
const char *ConfigMacros, size_t ConfigMacrosLen,
|
2020-03-03 16:05:23 -08:00
|
|
|
const char *IncludePath, size_t IncludePathLen,
|
|
|
|
const char *APINotesFile, size_t APINotesFileLen) {
|
2018-04-23 13:51:43 +00:00
|
|
|
return wrap(unwrap(Builder)->createModule(
|
|
|
|
unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen),
|
|
|
|
StringRef(ConfigMacros, ConfigMacrosLen),
|
2020-03-03 16:05:23 -08:00
|
|
|
StringRef(IncludePath, IncludePathLen),
|
|
|
|
StringRef(APINotesFile, APINotesFileLen)));
|
2018-04-23 13:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateNameSpace(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef ParentScope,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
LLVMBool ExportSymbols) {
|
|
|
|
return wrap(unwrap(Builder)->createNameSpace(
|
|
|
|
unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen), ExportSymbols));
|
|
|
|
}
|
|
|
|
|
2018-04-07 06:07:55 +00:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateFunction(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, const char *LinkageName, size_t LinkageNameLen,
|
|
|
|
LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
|
|
|
|
LLVMBool IsLocalToUnit, LLVMBool IsDefinition,
|
|
|
|
unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized) {
|
|
|
|
return wrap(unwrap(Builder)->createFunction(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, {LinkageName, LinkageNameLen},
|
2018-11-19 18:29:28 +00:00
|
|
|
unwrapDI<DIFile>(File), LineNo, unwrapDI<DISubroutineType>(Ty), ScopeLine,
|
|
|
|
map_from_llvmDIFlags(Flags),
|
|
|
|
pack_into_DISPFlags(IsLocalToUnit, IsDefinition, IsOptimized), nullptr,
|
|
|
|
nullptr, nullptr));
|
2018-04-07 06:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef File, unsigned Line, unsigned Col) {
|
|
|
|
return wrap(unwrap(Builder)->createLexicalBlock(unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DIFile>(File),
|
|
|
|
Line, Col));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef File,
|
|
|
|
unsigned Discriminator) {
|
|
|
|
return wrap(unwrap(Builder)->createLexicalBlockFile(unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DIFile>(File),
|
|
|
|
Discriminator));
|
|
|
|
}
|
|
|
|
|
2018-04-28 22:32:07 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef NS,
|
|
|
|
LLVMMetadataRef File,
|
|
|
|
unsigned Line) {
|
|
|
|
return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DINamespace>(NS),
|
|
|
|
unwrapDI<DIFile>(File),
|
|
|
|
Line));
|
|
|
|
}
|
|
|
|
|
2021-09-07 11:25:44 +05:30
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromAlias(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef ImportedEntity, LLVMMetadataRef File, unsigned Line,
|
|
|
|
LLVMMetadataRef *Elements, unsigned NumElements) {
|
|
|
|
auto Elts =
|
|
|
|
(NumElements > 0)
|
|
|
|
? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
|
|
|
|
: nullptr;
|
2018-04-28 22:32:07 +00:00
|
|
|
return wrap(unwrap(Builder)->createImportedModule(
|
2021-09-07 11:25:44 +05:30
|
|
|
unwrapDI<DIScope>(Scope), unwrapDI<DIImportedEntity>(ImportedEntity),
|
|
|
|
unwrapDI<DIFile>(File), Line, Elts));
|
2018-04-28 22:32:07 +00:00
|
|
|
}
|
|
|
|
|
2021-09-07 11:25:44 +05:30
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromModule(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef M,
|
|
|
|
LLVMMetadataRef File, unsigned Line, LLVMMetadataRef *Elements,
|
|
|
|
unsigned NumElements) {
|
|
|
|
auto Elts =
|
|
|
|
(NumElements > 0)
|
|
|
|
? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
|
|
|
|
: nullptr;
|
|
|
|
return wrap(unwrap(Builder)->createImportedModule(
|
|
|
|
unwrapDI<DIScope>(Scope), unwrapDI<DIModule>(M), unwrapDI<DIFile>(File),
|
|
|
|
Line, Elts));
|
2018-04-28 22:32:07 +00:00
|
|
|
}
|
|
|
|
|
2021-09-07 11:25:44 +05:30
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateImportedDeclaration(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef Decl,
|
|
|
|
LLVMMetadataRef File, unsigned Line, const char *Name, size_t NameLen,
|
|
|
|
LLVMMetadataRef *Elements, unsigned NumElements) {
|
|
|
|
auto Elts =
|
|
|
|
(NumElements > 0)
|
|
|
|
? unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements})
|
|
|
|
: nullptr;
|
2018-04-28 22:32:07 +00:00
|
|
|
return wrap(unwrap(Builder)->createImportedDeclaration(
|
2021-09-07 11:25:44 +05:30
|
|
|
unwrapDI<DIScope>(Scope), unwrapDI<DINode>(Decl), unwrapDI<DIFile>(File),
|
|
|
|
Line, {Name, NameLen}, Elts));
|
2018-04-28 22:32:07 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 22:18:52 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line,
|
|
|
|
unsigned Column, LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef InlinedAt) {
|
|
|
|
return wrap(DILocation::get(*unwrap(Ctx), Line, Column, unwrap(Scope),
|
|
|
|
unwrap(InlinedAt)));
|
|
|
|
}
|
2018-04-02 00:17:40 +00:00
|
|
|
|
2018-05-10 18:23:55 +00:00
|
|
|
unsigned LLVMDILocationGetLine(LLVMMetadataRef Location) {
|
|
|
|
return unwrapDI<DILocation>(Location)->getLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location) {
|
|
|
|
return unwrapDI<DILocation>(Location)->getColumn();
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location) {
|
|
|
|
return wrap(unwrapDI<DILocation>(Location)->getScope());
|
|
|
|
}
|
|
|
|
|
2019-04-10 14:19:05 +00:00
|
|
|
LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location) {
|
|
|
|
return wrap(unwrapDI<DILocation>(Location)->getInlinedAt());
|
|
|
|
}
|
|
|
|
|
2019-04-17 13:29:14 +00:00
|
|
|
LLVMMetadataRef LLVMDIScopeGetFile(LLVMMetadataRef Scope) {
|
|
|
|
return wrap(unwrapDI<DIScope>(Scope)->getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len) {
|
|
|
|
auto Dir = unwrapDI<DIFile>(File)->getDirectory();
|
|
|
|
*Len = Dir.size();
|
|
|
|
return Dir.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len) {
|
|
|
|
auto Name = unwrapDI<DIFile>(File)->getFilename();
|
|
|
|
*Len = Name.size();
|
|
|
|
return Name.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len) {
|
|
|
|
if (auto Src = unwrapDI<DIFile>(File)->getSource()) {
|
|
|
|
*Len = Src->size();
|
|
|
|
return Src->data();
|
|
|
|
}
|
|
|
|
*Len = 0;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2019-10-07 13:57:13 +00:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateMacro(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef ParentMacroFile,
|
|
|
|
unsigned Line,
|
|
|
|
LLVMDWARFMacinfoRecordType RecordType,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
const char *Value, size_t ValueLen) {
|
|
|
|
return wrap(
|
|
|
|
unwrap(Builder)->createMacro(unwrapDI<DIMacroFile>(ParentMacroFile), Line,
|
|
|
|
static_cast<MacinfoRecordType>(RecordType),
|
|
|
|
{Name, NameLen}, {Value, ValueLen}));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateTempMacroFile(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef ParentMacroFile, unsigned Line,
|
|
|
|
LLVMMetadataRef File) {
|
|
|
|
return wrap(unwrap(Builder)->createTempMacroFile(
|
|
|
|
unwrapDI<DIMacroFile>(ParentMacroFile), Line, unwrapDI<DIFile>(File)));
|
|
|
|
}
|
|
|
|
|
2019-02-17 21:25:47 +00:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
int64_t Value,
|
|
|
|
LLVMBool IsUnsigned) {
|
|
|
|
return wrap(unwrap(Builder)->createEnumerator({Name, NameLen}, Value,
|
|
|
|
IsUnsigned != 0));
|
|
|
|
}
|
|
|
|
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
|
2018-04-28 18:13:39 +00:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements,
|
2018-04-02 00:17:40 +00:00
|
|
|
unsigned NumElements, LLVMMetadataRef ClassTy) {
|
|
|
|
auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
|
|
|
|
NumElements});
|
|
|
|
return wrap(unwrap(Builder)->createEnumerationType(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
|
|
|
|
LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateUnionType(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
|
2018-04-28 18:13:39 +00:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang,
|
|
|
|
const char *UniqueId, size_t UniqueIdLen) {
|
|
|
|
auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
|
|
|
|
NumElements});
|
|
|
|
return wrap(unwrap(Builder)->createUnionType(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
|
|
|
|
LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
|
|
|
|
Elts, RunTimeLang, {UniqueId, UniqueIdLen}));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
2018-04-28 18:13:39 +00:00
|
|
|
LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, uint64_t Size,
|
|
|
|
uint32_t AlignInBits, LLVMMetadataRef Ty,
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMMetadataRef *Subscripts,
|
|
|
|
unsigned NumSubscripts) {
|
|
|
|
auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
|
|
|
|
NumSubscripts});
|
|
|
|
return wrap(unwrap(Builder)->createArrayType(Size, AlignInBits,
|
|
|
|
unwrapDI<DIType>(Ty), Subs));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
2018-04-28 18:13:39 +00:00
|
|
|
LLVMDIBuilderCreateVectorType(LLVMDIBuilderRef Builder, uint64_t Size,
|
|
|
|
uint32_t AlignInBits, LLVMMetadataRef Ty,
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMMetadataRef *Subscripts,
|
|
|
|
unsigned NumSubscripts) {
|
|
|
|
auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
|
|
|
|
NumSubscripts});
|
|
|
|
return wrap(unwrap(Builder)->createVectorType(Size, AlignInBits,
|
|
|
|
unwrapDI<DIType>(Ty), Subs));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name,
|
2018-04-28 18:13:39 +00:00
|
|
|
size_t NameLen, uint64_t SizeInBits,
|
2018-08-19 23:39:47 +00:00
|
|
|
LLVMDWARFTypeEncoding Encoding,
|
|
|
|
LLVMDIFlags Flags) {
|
2018-04-02 00:17:40 +00:00
|
|
|
return wrap(unwrap(Builder)->createBasicType({Name, NameLen},
|
2018-08-19 23:39:47 +00:00
|
|
|
SizeInBits, Encoding,
|
|
|
|
map_from_llvmDIFlags(Flags)));
|
2018-04-02 00:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreatePointerType(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy,
|
2018-04-28 18:13:39 +00:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace,
|
2018-04-02 00:17:40 +00:00
|
|
|
const char *Name, size_t NameLen) {
|
2024-03-19 09:13:17 +03:00
|
|
|
return wrap(unwrap(Builder)->createPointerType(
|
|
|
|
unwrapDI<DIType>(PointeeTy), SizeInBits, AlignInBits, AddressSpace,
|
|
|
|
{Name, NameLen}));
|
2018-04-02 00:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateStructType(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
|
2018-04-28 18:13:39 +00:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements,
|
|
|
|
unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder,
|
|
|
|
const char *UniqueId, size_t UniqueIdLen) {
|
|
|
|
auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
|
|
|
|
NumElements});
|
|
|
|
return wrap(unwrap(Builder)->createStructType(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
|
|
|
|
LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
|
|
|
|
unwrapDI<DIType>(DerivedFrom), Elts, RunTimeLang,
|
|
|
|
unwrapDI<DIType>(VTableHolder), {UniqueId, UniqueIdLen}));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateMemberType(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
2018-04-28 18:13:39 +00:00
|
|
|
size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
|
|
|
|
uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMMetadataRef Ty) {
|
|
|
|
return wrap(unwrap(Builder)->createMemberType(unwrapDI<DIScope>(Scope),
|
|
|
|
{Name, NameLen}, unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits,
|
|
|
|
OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name,
|
|
|
|
size_t NameLen) {
|
|
|
|
return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen}));
|
|
|
|
}
|
|
|
|
|
2023-11-15 09:36:47 +00:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType(
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
|
|
|
|
LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
|
2023-11-15 08:49:11 +00:00
|
|
|
uint32_t AlignInBits) {
|
2018-04-02 00:17:40 +00:00
|
|
|
return wrap(unwrap(Builder)->createStaticMemberType(
|
2023-11-15 09:36:47 +00:00
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
|
|
|
|
LineNumber, unwrapDI<DIType>(Type), map_from_llvmDIFlags(Flags),
|
|
|
|
unwrap<Constant>(ConstantVal), DW_TAG_member, AlignInBits));
|
2018-04-02 00:17:40 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 16:27:35 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
LLVMMetadataRef File, unsigned LineNo,
|
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits,
|
|
|
|
uint64_t OffsetInBits, LLVMDIFlags Flags,
|
|
|
|
LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode) {
|
|
|
|
return wrap(unwrap(Builder)->createObjCIVar(
|
|
|
|
{Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
|
|
|
|
SizeInBits, AlignInBits, OffsetInBits,
|
|
|
|
map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty),
|
|
|
|
unwrapDI<MDNode>(PropertyNode)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
LLVMMetadataRef File, unsigned LineNo,
|
|
|
|
const char *GetterName, size_t GetterNameLen,
|
|
|
|
const char *SetterName, size_t SetterNameLen,
|
|
|
|
unsigned PropertyAttributes,
|
|
|
|
LLVMMetadataRef Ty) {
|
|
|
|
return wrap(unwrap(Builder)->createObjCProperty(
|
|
|
|
{Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
|
|
|
|
{GetterName, GetterNameLen}, {SetterName, SetterNameLen},
|
|
|
|
PropertyAttributes, unwrapDI<DIType>(Ty)));
|
|
|
|
}
|
|
|
|
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Type) {
|
|
|
|
return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type)));
|
|
|
|
}
|
|
|
|
|
2018-05-10 21:10:06 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
LLVMMetadataRef File, unsigned LineNo,
|
2019-12-03 09:29:54 +05:30
|
|
|
LLVMMetadataRef Scope, uint32_t AlignInBits) {
|
2018-05-10 21:10:06 +00:00
|
|
|
return wrap(unwrap(Builder)->createTypedef(
|
2019-12-03 09:29:54 +05:30
|
|
|
unwrapDI<DIType>(Type), {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
|
|
|
|
unwrapDI<DIScope>(Scope), AlignInBits));
|
2018-05-10 21:10:06 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 16:27:35 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Ty, LLVMMetadataRef BaseTy,
|
|
|
|
uint64_t BaseOffset, uint32_t VBPtrOffset,
|
|
|
|
LLVMDIFlags Flags) {
|
|
|
|
return wrap(unwrap(Builder)->createInheritance(
|
|
|
|
unwrapDI<DIType>(Ty), unwrapDI<DIType>(BaseTy),
|
|
|
|
BaseOffset, VBPtrOffset, map_from_llvmDIFlags(Flags)));
|
|
|
|
}
|
|
|
|
|
2018-04-23 13:51:43 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateForwardDecl(
|
|
|
|
LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
|
2018-04-28 18:13:39 +00:00
|
|
|
unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
|
2018-04-23 13:51:43 +00:00
|
|
|
const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
|
|
|
|
return wrap(unwrap(Builder)->createForwardDecl(
|
|
|
|
Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
|
|
|
|
AlignInBits, {UniqueIdentifier, UniqueIdentifierLen}));
|
|
|
|
}
|
|
|
|
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateReplaceableCompositeType(
|
2018-04-02 19:11:44 +00:00
|
|
|
LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
|
2018-04-28 18:13:39 +00:00
|
|
|
unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMDIFlags Flags, const char *UniqueIdentifier,
|
2018-04-02 19:11:44 +00:00
|
|
|
size_t UniqueIdentifierLen) {
|
2018-04-02 00:17:40 +00:00
|
|
|
return wrap(unwrap(Builder)->createReplaceableCompositeType(
|
|
|
|
Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
|
|
|
|
AlignInBits, map_from_llvmDIFlags(Flags),
|
|
|
|
{UniqueIdentifier, UniqueIdentifierLen}));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag,
|
|
|
|
LLVMMetadataRef Type) {
|
|
|
|
return wrap(unwrap(Builder)->createQualifiedType(Tag,
|
|
|
|
unwrapDI<DIType>(Type)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag,
|
|
|
|
LLVMMetadataRef Type) {
|
|
|
|
return wrap(unwrap(Builder)->createReferenceType(Tag,
|
|
|
|
unwrapDI<DIType>(Type)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder) {
|
|
|
|
return wrap(unwrap(Builder)->createNullPtrType());
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateMemberPointerType(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef PointeeType,
|
|
|
|
LLVMMetadataRef ClassType,
|
2018-04-28 18:13:39 +00:00
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint32_t AlignInBits,
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMDIFlags Flags) {
|
|
|
|
return wrap(unwrap(Builder)->createMemberPointerType(
|
|
|
|
unwrapDI<DIType>(PointeeType),
|
|
|
|
unwrapDI<DIType>(ClassType), AlignInBits, SizeInBits,
|
|
|
|
map_from_llvmDIFlags(Flags)));
|
|
|
|
}
|
|
|
|
|
2018-04-28 18:13:39 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateBitFieldMemberType(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
LLVMMetadataRef File, unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t OffsetInBits,
|
|
|
|
uint64_t StorageOffsetInBits,
|
|
|
|
LLVMDIFlags Flags, LLVMMetadataRef Type) {
|
|
|
|
return wrap(unwrap(Builder)->createBitFieldMemberType(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen},
|
|
|
|
unwrapDI<DIFile>(File), LineNumber,
|
|
|
|
SizeInBits, OffsetInBits, StorageOffsetInBits,
|
|
|
|
map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Type)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateClassType(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope, const char *Name, size_t NameLen,
|
|
|
|
LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
|
|
|
|
uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
|
|
|
|
LLVMMetadataRef DerivedFrom,
|
|
|
|
LLVMMetadataRef *Elements, unsigned NumElements,
|
|
|
|
LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode,
|
|
|
|
const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
|
|
|
|
auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
|
|
|
|
NumElements});
|
|
|
|
return wrap(unwrap(Builder)->createClassType(
|
2023-11-15 12:46:06 -08:00
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
|
|
|
|
LineNumber, SizeInBits, AlignInBits, OffsetInBits,
|
|
|
|
map_from_llvmDIFlags(Flags), unwrapDI<DIType>(DerivedFrom), Elts,
|
|
|
|
/*RunTimeLang=*/0, unwrapDI<DIType>(VTableHolder),
|
|
|
|
unwrapDI<MDNode>(TemplateParamsNode),
|
|
|
|
{UniqueIdentifier, UniqueIdentifierLen}));
|
2018-04-28 18:13:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Type) {
|
|
|
|
return wrap(unwrap(Builder)->createArtificialType(unwrapDI<DIType>(Type)));
|
|
|
|
}
|
|
|
|
|
2023-02-08 16:28:34 -08:00
|
|
|
uint16_t LLVMGetDINodeTag(LLVMMetadataRef MD) {
|
|
|
|
return unwrapDI<DINode>(MD)->getTag();
|
|
|
|
}
|
|
|
|
|
2018-05-10 18:23:55 +00:00
|
|
|
const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) {
|
2023-07-07 16:50:52 +00:00
|
|
|
StringRef Str = unwrapDI<DIType>(DType)->getName();
|
2018-05-10 18:23:55 +00:00
|
|
|
*Length = Str.size();
|
|
|
|
return Str.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType) {
|
|
|
|
return unwrapDI<DIType>(DType)->getSizeInBits();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType) {
|
|
|
|
return unwrapDI<DIType>(DType)->getOffsetInBits();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType) {
|
|
|
|
return unwrapDI<DIType>(DType)->getAlignInBits();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMDITypeGetLine(LLVMMetadataRef DType) {
|
|
|
|
return unwrapDI<DIType>(DType)->getLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType) {
|
|
|
|
return map_to_llvmDIFlags(unwrapDI<DIType>(DType)->getFlags());
|
|
|
|
}
|
|
|
|
|
2018-04-23 14:29:33 +00:00
|
|
|
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef *Types,
|
|
|
|
size_t Length) {
|
|
|
|
return wrap(
|
|
|
|
unwrap(Builder)->getOrCreateTypeArray({unwrap(Types), Length}).get());
|
|
|
|
}
|
|
|
|
|
2018-04-02 00:17:40 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef File,
|
|
|
|
LLVMMetadataRef *ParameterTypes,
|
|
|
|
unsigned NumParameterTypes,
|
|
|
|
LLVMDIFlags Flags) {
|
|
|
|
auto Elts = unwrap(Builder)->getOrCreateTypeArray({unwrap(ParameterTypes),
|
|
|
|
NumParameterTypes});
|
|
|
|
return wrap(unwrap(Builder)->createSubroutineType(
|
|
|
|
Elts, map_from_llvmDIFlags(Flags)));
|
|
|
|
}
|
2018-04-07 06:07:55 +00:00
|
|
|
|
2018-04-22 19:24:44 +00:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Builder,
|
2021-12-27 14:15:30 +08:00
|
|
|
uint64_t *Addr, size_t Length) {
|
|
|
|
return wrap(
|
|
|
|
unwrap(Builder)->createExpression(ArrayRef<uint64_t>(Addr, Length)));
|
2018-04-22 19:24:44 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 22:31:49 +00:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder,
|
2021-12-27 14:15:30 +08:00
|
|
|
uint64_t Value) {
|
2018-04-23 22:31:49 +00:00
|
|
|
return wrap(unwrap(Builder)->createConstantValueExpression(Value));
|
|
|
|
}
|
|
|
|
|
2018-10-03 18:44:53 +00:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateGlobalVariableExpression(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File,
|
|
|
|
unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit,
|
|
|
|
LLVMMetadataRef Expr, LLVMMetadataRef Decl, uint32_t AlignInBits) {
|
2018-04-23 22:31:49 +00:00
|
|
|
return wrap(unwrap(Builder)->createGlobalVariableExpression(
|
2018-10-03 18:44:53 +00:00
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LinkLen},
|
|
|
|
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
|
2019-11-22 08:45:37 -08:00
|
|
|
true, unwrap<DIExpression>(Expr), unwrapDI<MDNode>(Decl),
|
2018-10-03 18:44:53 +00:00
|
|
|
nullptr, AlignInBits));
|
2018-04-23 22:31:49 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 21:39:48 +00:00
|
|
|
LLVMMetadataRef LLVMDIGlobalVariableExpressionGetVariable(LLVMMetadataRef GVE) {
|
|
|
|
return wrap(unwrapDI<DIGlobalVariableExpression>(GVE)->getVariable());
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIGlobalVariableExpressionGetExpression(
|
|
|
|
LLVMMetadataRef GVE) {
|
|
|
|
return wrap(unwrapDI<DIGlobalVariableExpression>(GVE)->getExpression());
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIVariableGetFile(LLVMMetadataRef Var) {
|
|
|
|
return wrap(unwrapDI<DIVariable>(Var)->getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIVariableGetScope(LLVMMetadataRef Var) {
|
|
|
|
return wrap(unwrapDI<DIVariable>(Var)->getScope());
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMDIVariableGetLine(LLVMMetadataRef Var) {
|
|
|
|
return unwrapDI<DIVariable>(Var)->getLine();
|
|
|
|
}
|
|
|
|
|
2018-05-10 18:09:53 +00:00
|
|
|
LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data,
|
|
|
|
size_t Count) {
|
|
|
|
return wrap(
|
|
|
|
MDTuple::getTemporary(*unwrap(Ctx), {unwrap(Data), Count}).release());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode) {
|
|
|
|
MDNode::deleteTemporary(unwrapDI<MDNode>(TempNode));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TargetMetadata,
|
|
|
|
LLVMMetadataRef Replacement) {
|
|
|
|
auto *Node = unwrapDI<MDNode>(TargetMetadata);
|
2022-11-01 22:26:40 +01:00
|
|
|
Node->replaceAllUsesWith(unwrap(Replacement));
|
2018-05-10 18:09:53 +00:00
|
|
|
MDNode::deleteTemporary(Node);
|
|
|
|
}
|
|
|
|
|
2018-10-03 18:44:53 +00:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateTempGlobalVariableFwdDecl(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, const char *Linkage, size_t LnkLen, LLVMMetadataRef File,
|
|
|
|
unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit,
|
|
|
|
LLVMMetadataRef Decl, uint32_t AlignInBits) {
|
2018-04-23 22:31:49 +00:00
|
|
|
return wrap(unwrap(Builder)->createTempGlobalVariableFwdDecl(
|
2018-10-03 18:44:53 +00:00
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LnkLen},
|
|
|
|
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
|
|
|
|
unwrapDI<MDNode>(Decl), nullptr, AlignInBits));
|
2018-04-23 22:31:49 +00:00
|
|
|
}
|
|
|
|
|
2024-03-18 11:45:14 +00:00
|
|
|
LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordBefore(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
|
|
|
|
LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMValueRef Instr) {
|
2024-03-28 08:54:27 +00:00
|
|
|
DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
|
|
|
|
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
|
|
|
|
unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
|
|
|
|
unwrap<Instruction>(Instr));
|
|
|
|
// This assert will fail if the module is in the old debug info format.
|
|
|
|
// This function should only be called if the module is in the new
|
|
|
|
// debug info format.
|
|
|
|
// See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
|
|
|
|
// LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
|
|
|
|
assert(isa<DbgRecord *>(DbgInst) &&
|
|
|
|
"Function unexpectedly in old debug info format");
|
|
|
|
return wrap(cast<DbgRecord *>(DbgInst));
|
2024-03-18 11:45:14 +00:00
|
|
|
}
|
2024-03-12 10:25:58 +00:00
|
|
|
|
2024-03-18 11:45:14 +00:00
|
|
|
LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordAtEnd(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
|
|
|
|
LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMBasicBlockRef Block) {
|
2024-03-28 08:54:27 +00:00
|
|
|
DbgInstPtr DbgInst = unwrap(Builder)->insertDeclare(
|
|
|
|
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
|
|
|
|
unwrap<DIExpression>(Expr), unwrap<DILocation>(DL), unwrap(Block));
|
|
|
|
// This assert will fail if the module is in the old debug info format.
|
|
|
|
// This function should only be called if the module is in the new
|
|
|
|
// debug info format.
|
|
|
|
// See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
|
|
|
|
// LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
|
|
|
|
assert(isa<DbgRecord *>(DbgInst) &&
|
|
|
|
"Function unexpectedly in old debug info format");
|
|
|
|
return wrap(cast<DbgRecord *>(DbgInst));
|
2024-03-18 11:45:14 +00:00
|
|
|
}
|
2024-03-12 10:25:58 +00:00
|
|
|
|
2024-03-18 11:45:14 +00:00
|
|
|
LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueRecordBefore(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
|
|
|
|
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr) {
|
2024-03-28 08:54:27 +00:00
|
|
|
DbgInstPtr DbgInst = unwrap(Builder)->insertDbgValueIntrinsic(
|
|
|
|
unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
|
|
|
|
unwrap<DILocation>(DebugLoc), unwrap<Instruction>(Instr));
|
|
|
|
// This assert will fail if the module is in the old debug info format.
|
|
|
|
// This function should only be called if the module is in the new
|
|
|
|
// debug info format.
|
|
|
|
// See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
|
|
|
|
// LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
|
|
|
|
assert(isa<DbgRecord *>(DbgInst) &&
|
|
|
|
"Function unexpectedly in old debug info format");
|
|
|
|
return wrap(cast<DbgRecord *>(DbgInst));
|
2024-03-18 11:45:14 +00:00
|
|
|
}
|
2024-03-12 10:25:58 +00:00
|
|
|
|
2024-03-18 11:45:14 +00:00
|
|
|
LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueRecordAtEnd(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
|
|
|
|
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block) {
|
2024-03-28 08:54:27 +00:00
|
|
|
DbgInstPtr DbgInst = unwrap(Builder)->insertDbgValueIntrinsic(
|
|
|
|
unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
|
|
|
|
unwrap<DILocation>(DebugLoc), unwrap(Block));
|
|
|
|
// This assert will fail if the module is in the old debug info format.
|
|
|
|
// This function should only be called if the module is in the new
|
|
|
|
// debug info format.
|
|
|
|
// See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes,
|
|
|
|
// LLVMIsNewDbgInfoFormat, and LLVMSetIsNewDbgInfoFormat for more info.
|
|
|
|
assert(isa<DbgRecord *>(DbgInst) &&
|
|
|
|
"Function unexpectedly in old debug info format");
|
|
|
|
return wrap(cast<DbgRecord *>(DbgInst));
|
2024-03-18 11:45:14 +00:00
|
|
|
}
|
2018-04-23 22:31:49 +00:00
|
|
|
|
2018-04-22 19:24:44 +00:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
|
|
|
|
LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits) {
|
|
|
|
return wrap(unwrap(Builder)->createAutoVariable(
|
|
|
|
unwrap<DIScope>(Scope), {Name, NameLen}, unwrap<DIFile>(File),
|
|
|
|
LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
|
|
|
|
map_from_llvmDIFlags(Flags), AlignInBits));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateParameterVariable(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo,
|
|
|
|
LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags) {
|
|
|
|
return wrap(unwrap(Builder)->createParameterVariable(
|
2018-08-25 19:54:39 +00:00
|
|
|
unwrap<DIScope>(Scope), {Name, NameLen}, ArgNo, unwrap<DIFile>(File),
|
2018-04-22 19:24:44 +00:00
|
|
|
LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
|
|
|
|
map_from_llvmDIFlags(Flags)));
|
|
|
|
}
|
|
|
|
|
2018-04-23 14:29:33 +00:00
|
|
|
LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Builder,
|
|
|
|
int64_t Lo, int64_t Count) {
|
|
|
|
return wrap(unwrap(Builder)->getOrCreateSubrange(Lo, Count));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef *Data,
|
|
|
|
size_t Length) {
|
|
|
|
Metadata **DataValue = unwrap(Data);
|
|
|
|
return wrap(unwrap(Builder)->getOrCreateArray({DataValue, Length}).get());
|
|
|
|
}
|
|
|
|
|
2018-04-07 06:07:55 +00:00
|
|
|
LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func) {
|
|
|
|
return wrap(unwrap<Function>(Func)->getSubprogram());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) {
|
|
|
|
unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP));
|
|
|
|
}
|
2018-10-01 13:15:09 +00:00
|
|
|
|
2019-04-16 21:39:48 +00:00
|
|
|
unsigned LLVMDISubprogramGetLine(LLVMMetadataRef Subprogram) {
|
|
|
|
return unwrapDI<DISubprogram>(Subprogram)->getLine();
|
|
|
|
}
|
|
|
|
|
2019-04-09 22:27:51 +00:00
|
|
|
LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst) {
|
|
|
|
return wrap(unwrap<Instruction>(Inst)->getDebugLoc().getAsMDNode());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc) {
|
|
|
|
if (Loc)
|
|
|
|
unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc(unwrap<MDNode>(Loc)));
|
|
|
|
else
|
|
|
|
unwrap<Instruction>(Inst)->setDebugLoc(DebugLoc());
|
|
|
|
}
|
|
|
|
|
2018-10-01 13:15:09 +00:00
|
|
|
LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata) {
|
|
|
|
switch(unwrap(Metadata)->getMetadataID()) {
|
|
|
|
#define HANDLE_METADATA_LEAF(CLASS) \
|
|
|
|
case Metadata::CLASS##Kind: \
|
|
|
|
return (LLVMMetadataKind)LLVM##CLASS##MetadataKind;
|
|
|
|
#include "llvm/IR/Metadata.def"
|
|
|
|
default:
|
|
|
|
return (LLVMMetadataKind)LLVMGenericDINodeMetadataKind;
|
|
|
|
}
|
|
|
|
}
|
2022-11-07 11:56:36 +00:00
|
|
|
|
|
|
|
AssignmentInstRange at::getAssignmentInsts(DIAssignID *ID) {
|
|
|
|
assert(ID && "Expected non-null ID");
|
|
|
|
LLVMContext &Ctx = ID->getContext();
|
|
|
|
auto &Map = Ctx.pImpl->AssignmentIDToInstrs;
|
|
|
|
|
|
|
|
auto MapIt = Map.find(ID);
|
|
|
|
if (MapIt == Map.end())
|
|
|
|
return make_range(nullptr, nullptr);
|
|
|
|
|
|
|
|
return make_range(MapIt->second.begin(), MapIt->second.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
AssignmentMarkerRange at::getAssignmentMarkers(DIAssignID *ID) {
|
|
|
|
assert(ID && "Expected non-null ID");
|
|
|
|
LLVMContext &Ctx = ID->getContext();
|
|
|
|
|
|
|
|
auto *IDAsValue = MetadataAsValue::getIfExists(Ctx, ID);
|
|
|
|
|
|
|
|
// The ID is only used wrapped in MetadataAsValue(ID), so lets check that
|
|
|
|
// one of those already exists first.
|
|
|
|
if (!IDAsValue)
|
|
|
|
return make_range(Value::user_iterator(), Value::user_iterator());
|
|
|
|
|
|
|
|
return make_range(IDAsValue->user_begin(), IDAsValue->user_end());
|
|
|
|
}
|
|
|
|
|
|
|
|
void at::deleteAssignmentMarkers(const Instruction *Inst) {
|
|
|
|
auto Range = getAssignmentMarkers(Inst);
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
SmallVector<DbgVariableRecord *> DVRAssigns = getDVRAssignmentMarkers(Inst);
|
|
|
|
if (Range.empty() && DVRAssigns.empty())
|
2022-11-07 11:56:36 +00:00
|
|
|
return;
|
|
|
|
SmallVector<DbgAssignIntrinsic *> ToDelete(Range.begin(), Range.end());
|
|
|
|
for (auto *DAI : ToDelete)
|
|
|
|
DAI->eraseFromParent();
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
for (auto *DVR : DVRAssigns)
|
|
|
|
DVR->eraseFromParent();
|
2022-11-07 11:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void at::RAUW(DIAssignID *Old, DIAssignID *New) {
|
|
|
|
// Replace attachments.
|
|
|
|
AssignmentInstRange InstRange = getAssignmentInsts(Old);
|
|
|
|
// Use intermediate storage for the instruction ptrs because the
|
|
|
|
// getAssignmentInsts range iterators will be invalidated by adding and
|
|
|
|
// removing DIAssignID attachments.
|
|
|
|
SmallVector<Instruction *> InstVec(InstRange.begin(), InstRange.end());
|
|
|
|
for (auto *I : InstVec)
|
|
|
|
I->setMetadata(LLVMContext::MD_DIAssignID, New);
|
2024-01-17 12:00:30 +00:00
|
|
|
|
|
|
|
Old->replaceAllUsesWith(New);
|
2022-11-07 11:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void at::deleteAll(Function *F) {
|
|
|
|
SmallVector<DbgAssignIntrinsic *, 12> ToDelete;
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
SmallVector<DbgVariableRecord *, 12> DPToDelete;
|
2022-11-07 11:56:36 +00:00
|
|
|
for (BasicBlock &BB : *F) {
|
|
|
|
for (Instruction &I : BB) {
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange()))
|
|
|
|
if (DVR.isDbgAssign())
|
|
|
|
DPToDelete.push_back(&DVR);
|
2022-11-07 11:56:36 +00:00
|
|
|
if (auto *DAI = dyn_cast<DbgAssignIntrinsic>(&I))
|
|
|
|
ToDelete.push_back(DAI);
|
|
|
|
else
|
|
|
|
I.setMetadata(LLVMContext::MD_DIAssignID, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto *DAI : ToDelete)
|
|
|
|
DAI->eraseFromParent();
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
for (auto *DVR : DPToDelete)
|
|
|
|
DVR->eraseFromParent();
|
2022-11-07 11:56:36 +00:00
|
|
|
}
|
2022-11-07 17:39:40 +00:00
|
|
|
|
2024-07-12 08:28:36 +01:00
|
|
|
/// FIXME: Remove this wrapper function and call
|
|
|
|
/// DIExpression::calculateFragmentIntersect directly.
|
2024-01-22 11:05:27 +00:00
|
|
|
template <typename T>
|
|
|
|
bool calculateFragmentIntersectImpl(
|
2023-04-19 13:11:22 +01:00
|
|
|
const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits,
|
2024-01-22 11:05:27 +00:00
|
|
|
uint64_t SliceSizeInBits, const T *AssignRecord,
|
2023-04-19 13:11:22 +01:00
|
|
|
std::optional<DIExpression::FragmentInfo> &Result) {
|
2024-07-12 08:28:36 +01:00
|
|
|
// No overlap if this DbgRecord describes a killed location.
|
2024-01-22 11:05:27 +00:00
|
|
|
if (AssignRecord->isKillAddress())
|
2023-04-19 13:11:22 +01:00
|
|
|
return false;
|
|
|
|
|
2024-07-12 08:28:36 +01:00
|
|
|
int64_t AddrOffsetInBits;
|
2023-04-19 13:11:22 +01:00
|
|
|
{
|
2024-07-12 08:28:36 +01:00
|
|
|
int64_t AddrOffsetInBytes;
|
|
|
|
SmallVector<uint64_t> PostOffsetOps; //< Unused.
|
|
|
|
// Bail if we can't find a constant offset (or none) in the expression.
|
|
|
|
if (!AssignRecord->getAddressExpression()->extractLeadingOffset(
|
|
|
|
AddrOffsetInBytes, PostOffsetOps))
|
2023-04-19 13:11:22 +01:00
|
|
|
return false;
|
2024-07-12 08:28:36 +01:00
|
|
|
AddrOffsetInBits = AddrOffsetInBytes * 8;
|
2023-04-19 13:11:22 +01:00
|
|
|
}
|
|
|
|
|
2024-07-12 08:28:36 +01:00
|
|
|
Value *Addr = AssignRecord->getAddress();
|
|
|
|
// FIXME: It may not always be zero.
|
|
|
|
int64_t BitExtractOffsetInBits = 0;
|
|
|
|
DIExpression::FragmentInfo VarFrag =
|
|
|
|
AssignRecord->getFragmentOrEntireVariable();
|
|
|
|
|
|
|
|
int64_t OffsetFromLocationInBits; //< Unused.
|
|
|
|
return DIExpression::calculateFragmentIntersect(
|
|
|
|
DL, Dest, SliceOffsetInBits, SliceSizeInBits, Addr, AddrOffsetInBits,
|
|
|
|
BitExtractOffsetInBits, VarFrag, Result, OffsetFromLocationInBits);
|
2023-04-19 13:11:22 +01:00
|
|
|
}
|
2024-07-12 08:28:36 +01:00
|
|
|
|
|
|
|
/// FIXME: Remove this wrapper function and call
|
|
|
|
/// DIExpression::calculateFragmentIntersect directly.
|
2024-01-22 11:05:27 +00:00
|
|
|
bool at::calculateFragmentIntersect(
|
|
|
|
const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits,
|
|
|
|
uint64_t SliceSizeInBits, const DbgAssignIntrinsic *DbgAssign,
|
|
|
|
std::optional<DIExpression::FragmentInfo> &Result) {
|
|
|
|
return calculateFragmentIntersectImpl(DL, Dest, SliceOffsetInBits,
|
|
|
|
SliceSizeInBits, DbgAssign, Result);
|
|
|
|
}
|
2024-07-12 08:28:36 +01:00
|
|
|
|
|
|
|
/// FIXME: Remove this wrapper function and call
|
|
|
|
/// DIExpression::calculateFragmentIntersect directly.
|
2024-01-22 11:05:27 +00:00
|
|
|
bool at::calculateFragmentIntersect(
|
|
|
|
const DataLayout &DL, const Value *Dest, uint64_t SliceOffsetInBits,
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
uint64_t SliceSizeInBits, const DbgVariableRecord *DVRAssign,
|
2024-01-22 11:05:27 +00:00
|
|
|
std::optional<DIExpression::FragmentInfo> &Result) {
|
|
|
|
return calculateFragmentIntersectImpl(DL, Dest, SliceOffsetInBits,
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
SliceSizeInBits, DVRAssign, Result);
|
2024-01-22 11:05:27 +00:00
|
|
|
}
|
2023-04-19 13:11:22 +01:00
|
|
|
|
2024-05-13 12:49:42 +01:00
|
|
|
/// Update inlined instructions' DIAssignID metadata. We need to do this
|
|
|
|
/// otherwise a function inlined more than once into the same function
|
|
|
|
/// will cause DIAssignID to be shared by many instructions.
|
|
|
|
void at::remapAssignID(DenseMap<DIAssignID *, DIAssignID *> &Map,
|
|
|
|
Instruction &I) {
|
|
|
|
auto GetNewID = [&Map](Metadata *Old) {
|
|
|
|
DIAssignID *OldID = cast<DIAssignID>(Old);
|
|
|
|
if (DIAssignID *NewID = Map.lookup(OldID))
|
|
|
|
return NewID;
|
|
|
|
DIAssignID *NewID = DIAssignID::getDistinct(OldID->getContext());
|
|
|
|
Map[OldID] = NewID;
|
|
|
|
return NewID;
|
|
|
|
};
|
|
|
|
// If we find a DIAssignID attachment or use, replace it with a new version.
|
|
|
|
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
|
|
|
|
if (DVR.isDbgAssign())
|
|
|
|
DVR.setAssignId(GetNewID(DVR.getAssignID()));
|
|
|
|
}
|
|
|
|
if (auto *ID = I.getMetadata(LLVMContext::MD_DIAssignID))
|
|
|
|
I.setMetadata(LLVMContext::MD_DIAssignID, GetNewID(ID));
|
|
|
|
else if (auto *DAI = dyn_cast<DbgAssignIntrinsic>(&I))
|
|
|
|
DAI->setAssignId(GetNewID(DAI->getAssignID()));
|
|
|
|
}
|
|
|
|
|
2022-11-07 17:39:40 +00:00
|
|
|
/// Collect constant properies (base, size, offset) of \p StoreDest.
|
2023-05-25 10:48:22 +01:00
|
|
|
/// Return std::nullopt if any properties are not constants or the
|
|
|
|
/// offset from the base pointer is negative.
|
2022-12-03 15:55:23 -06:00
|
|
|
static std::optional<AssignmentInfo>
|
|
|
|
getAssignmentInfoImpl(const DataLayout &DL, const Value *StoreDest,
|
2023-04-28 08:46:22 +01:00
|
|
|
TypeSize SizeInBits) {
|
|
|
|
if (SizeInBits.isScalable())
|
|
|
|
return std::nullopt;
|
2022-11-07 17:39:40 +00:00
|
|
|
APInt GEPOffset(DL.getIndexTypeSizeInBits(StoreDest->getType()), 0);
|
|
|
|
const Value *Base = StoreDest->stripAndAccumulateConstantOffsets(
|
|
|
|
DL, GEPOffset, /*AllowNonInbounds*/ true);
|
2023-05-25 10:48:22 +01:00
|
|
|
|
|
|
|
if (GEPOffset.isNegative())
|
|
|
|
return std::nullopt;
|
|
|
|
|
2022-11-07 17:39:40 +00:00
|
|
|
uint64_t OffsetInBytes = GEPOffset.getLimitedValue();
|
|
|
|
// Check for overflow.
|
|
|
|
if (OffsetInBytes == UINT64_MAX)
|
2022-12-02 20:05:20 -08:00
|
|
|
return std::nullopt;
|
2022-11-07 17:39:40 +00:00
|
|
|
if (const auto *Alloca = dyn_cast<AllocaInst>(Base))
|
|
|
|
return AssignmentInfo(DL, Alloca, OffsetInBytes * 8, SizeInBits);
|
2022-12-02 20:05:20 -08:00
|
|
|
return std::nullopt;
|
2022-11-07 17:39:40 +00:00
|
|
|
}
|
|
|
|
|
2022-12-03 15:55:23 -06:00
|
|
|
std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
|
|
|
|
const MemIntrinsic *I) {
|
2022-11-07 17:39:40 +00:00
|
|
|
const Value *StoreDest = I->getRawDest();
|
|
|
|
// Assume 8 bit bytes.
|
|
|
|
auto *ConstLengthInBytes = dyn_cast<ConstantInt>(I->getLength());
|
|
|
|
if (!ConstLengthInBytes)
|
|
|
|
// We can't use a non-const size, bail.
|
2022-12-02 20:05:20 -08:00
|
|
|
return std::nullopt;
|
2022-11-07 17:39:40 +00:00
|
|
|
uint64_t SizeInBits = 8 * ConstLengthInBytes->getZExtValue();
|
2023-11-22 08:52:53 +00:00
|
|
|
return getAssignmentInfoImpl(DL, StoreDest, TypeSize::getFixed(SizeInBits));
|
2022-11-07 17:39:40 +00:00
|
|
|
}
|
|
|
|
|
2022-12-03 15:55:23 -06:00
|
|
|
std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
|
|
|
|
const StoreInst *SI) {
|
2023-04-28 08:46:22 +01:00
|
|
|
TypeSize SizeInBits = DL.getTypeSizeInBits(SI->getValueOperand()->getType());
|
|
|
|
return getAssignmentInfoImpl(DL, SI->getPointerOperand(), SizeInBits);
|
2022-11-07 17:39:40 +00:00
|
|
|
}
|
|
|
|
|
2022-12-03 15:55:23 -06:00
|
|
|
std::optional<AssignmentInfo> at::getAssignmentInfo(const DataLayout &DL,
|
|
|
|
const AllocaInst *AI) {
|
2023-04-28 08:46:22 +01:00
|
|
|
TypeSize SizeInBits = DL.getTypeSizeInBits(AI->getAllocatedType());
|
2022-11-07 17:39:40 +00:00
|
|
|
return getAssignmentInfoImpl(DL, AI, SizeInBits);
|
|
|
|
}
|
|
|
|
|
2023-04-09 09:47:09 +01:00
|
|
|
/// Returns nullptr if the assignment shouldn't be attributed to this variable.
|
2024-01-23 16:38:49 +00:00
|
|
|
static void emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest,
|
|
|
|
Instruction &StoreLikeInst, const VarRecord &VarRec,
|
|
|
|
DIBuilder &DIB) {
|
2022-11-07 17:39:40 +00:00
|
|
|
auto *ID = StoreLikeInst.getMetadata(LLVMContext::MD_DIAssignID);
|
|
|
|
assert(ID && "Store instruction must have DIAssignID metadata");
|
2022-11-08 09:04:04 -08:00
|
|
|
(void)ID;
|
2022-11-07 17:39:40 +00:00
|
|
|
|
2023-04-11 18:03:51 +01:00
|
|
|
const uint64_t StoreStartBit = Info.OffsetInBits;
|
|
|
|
const uint64_t StoreEndBit = Info.OffsetInBits + Info.SizeInBits;
|
|
|
|
|
|
|
|
uint64_t FragStartBit = StoreStartBit;
|
|
|
|
uint64_t FragEndBit = StoreEndBit;
|
|
|
|
|
2023-04-09 09:47:09 +01:00
|
|
|
bool StoreToWholeVariable = Info.StoreToWholeAlloca;
|
|
|
|
if (auto Size = VarRec.Var->getSizeInBits()) {
|
2023-04-11 18:03:51 +01:00
|
|
|
// NOTE: trackAssignments doesn't understand base expressions yet, so all
|
|
|
|
// variables that reach here are guaranteed to start at offset 0 in the
|
|
|
|
// alloca.
|
|
|
|
const uint64_t VarStartBit = 0;
|
|
|
|
const uint64_t VarEndBit = *Size;
|
|
|
|
|
|
|
|
// FIXME: trim FragStartBit when nonzero VarStartBit is supported.
|
|
|
|
FragEndBit = std::min(FragEndBit, VarEndBit);
|
|
|
|
|
|
|
|
// Discard stores to bits outside this variable.
|
|
|
|
if (FragStartBit >= FragEndBit)
|
2024-01-23 16:38:49 +00:00
|
|
|
return;
|
2023-04-11 18:03:51 +01:00
|
|
|
|
|
|
|
StoreToWholeVariable = FragStartBit <= VarStartBit && FragEndBit >= *Size;
|
2023-04-09 09:47:09 +01:00
|
|
|
}
|
|
|
|
|
2022-12-02 20:05:20 -08:00
|
|
|
DIExpression *Expr =
|
|
|
|
DIExpression::get(StoreLikeInst.getContext(), std::nullopt);
|
2023-04-09 09:47:09 +01:00
|
|
|
if (!StoreToWholeVariable) {
|
2023-04-11 18:03:51 +01:00
|
|
|
auto R = DIExpression::createFragmentExpression(Expr, FragStartBit,
|
|
|
|
FragEndBit - FragStartBit);
|
2022-11-07 17:39:40 +00:00
|
|
|
assert(R.has_value() && "failed to create fragment expression");
|
2022-12-16 22:44:08 +00:00
|
|
|
Expr = *R;
|
2022-11-07 17:39:40 +00:00
|
|
|
}
|
2022-12-02 20:05:20 -08:00
|
|
|
DIExpression *AddrExpr =
|
|
|
|
DIExpression::get(StoreLikeInst.getContext(), std::nullopt);
|
2024-01-23 16:38:49 +00:00
|
|
|
if (StoreLikeInst.getParent()->IsNewDbgInfoFormat) {
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
auto *Assign = DbgVariableRecord::createLinkedDVRAssign(
|
2024-01-23 16:38:49 +00:00
|
|
|
&StoreLikeInst, Val, VarRec.Var, Expr, Dest, AddrExpr, VarRec.DL);
|
|
|
|
(void)Assign;
|
|
|
|
LLVM_DEBUG(if (Assign) errs() << " > INSERT: " << *Assign << "\n");
|
|
|
|
return;
|
|
|
|
}
|
2024-03-12 10:25:58 +00:00
|
|
|
auto Assign = DIB.insertDbgAssign(&StoreLikeInst, Val, VarRec.Var, Expr, Dest,
|
|
|
|
AddrExpr, VarRec.DL);
|
2024-01-23 16:38:49 +00:00
|
|
|
(void)Assign;
|
2024-03-12 10:25:58 +00:00
|
|
|
LLVM_DEBUG(if (!Assign.isNull()) {
|
|
|
|
if (Assign.is<DbgRecord *>())
|
|
|
|
errs() << " > INSERT: " << *Assign.get<DbgRecord *>() << "\n";
|
|
|
|
else
|
|
|
|
errs() << " > INSERT: " << *Assign.get<Instruction *>() << "\n";
|
|
|
|
});
|
2022-11-07 17:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef DEBUG_TYPE // Silence redefinition warning (from ConstantsContext.h).
|
|
|
|
#define DEBUG_TYPE "assignment-tracking"
|
|
|
|
|
|
|
|
void at::trackAssignments(Function::iterator Start, Function::iterator End,
|
|
|
|
const StorageToVarsMap &Vars, const DataLayout &DL,
|
|
|
|
bool DebugPrints) {
|
|
|
|
// Early-exit if there are no interesting variables.
|
|
|
|
if (Vars.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto &Ctx = Start->getContext();
|
|
|
|
auto &Module = *Start->getModule();
|
|
|
|
|
|
|
|
// Undef type doesn't matter, so long as it isn't void. Let's just use i1.
|
|
|
|
auto *Undef = UndefValue::get(Type::getInt1Ty(Ctx));
|
|
|
|
DIBuilder DIB(Module, /*AllowUnresolved*/ false);
|
|
|
|
|
|
|
|
// Scan the instructions looking for stores to local variables' storage.
|
|
|
|
LLVM_DEBUG(errs() << "# Scanning instructions\n");
|
|
|
|
for (auto BBI = Start; BBI != End; ++BBI) {
|
|
|
|
for (Instruction &I : *BBI) {
|
|
|
|
|
2022-12-20 15:53:38 -08:00
|
|
|
std::optional<AssignmentInfo> Info;
|
2022-11-07 17:39:40 +00:00
|
|
|
Value *ValueComponent = nullptr;
|
|
|
|
Value *DestComponent = nullptr;
|
|
|
|
if (auto *AI = dyn_cast<AllocaInst>(&I)) {
|
|
|
|
// We want to track the variable's stack home from its alloca's
|
|
|
|
// position onwards so we treat it as an assignment (where the stored
|
|
|
|
// value is Undef).
|
|
|
|
Info = getAssignmentInfo(DL, AI);
|
|
|
|
ValueComponent = Undef;
|
|
|
|
DestComponent = AI;
|
|
|
|
} else if (auto *SI = dyn_cast<StoreInst>(&I)) {
|
|
|
|
Info = getAssignmentInfo(DL, SI);
|
|
|
|
ValueComponent = SI->getValueOperand();
|
|
|
|
DestComponent = SI->getPointerOperand();
|
|
|
|
} else if (auto *MI = dyn_cast<MemTransferInst>(&I)) {
|
|
|
|
Info = getAssignmentInfo(DL, MI);
|
|
|
|
// May not be able to represent this value easily.
|
|
|
|
ValueComponent = Undef;
|
|
|
|
DestComponent = MI->getOperand(0);
|
|
|
|
} else if (auto *MI = dyn_cast<MemSetInst>(&I)) {
|
|
|
|
Info = getAssignmentInfo(DL, MI);
|
|
|
|
// If we're zero-initing we can state the assigned value is zero,
|
|
|
|
// otherwise use undef.
|
|
|
|
auto *ConstValue = dyn_cast<ConstantInt>(MI->getOperand(1));
|
|
|
|
if (ConstValue && ConstValue->isZero())
|
|
|
|
ValueComponent = ConstValue;
|
|
|
|
else
|
|
|
|
ValueComponent = Undef;
|
|
|
|
DestComponent = MI->getOperand(0);
|
|
|
|
} else {
|
|
|
|
// Not a store-like instruction.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(ValueComponent && DestComponent);
|
|
|
|
LLVM_DEBUG(errs() << "SCAN: Found store-like: " << I << "\n");
|
|
|
|
|
|
|
|
// Check if getAssignmentInfo failed to understand this store.
|
|
|
|
if (!Info.has_value()) {
|
|
|
|
LLVM_DEBUG(
|
|
|
|
errs()
|
|
|
|
<< " | SKIP: Untrackable store (e.g. through non-const gep)\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
LLVM_DEBUG(errs() << " | BASE: " << *Info->Base << "\n");
|
|
|
|
|
|
|
|
// Check if the store destination is a local variable with debug info.
|
|
|
|
auto LocalIt = Vars.find(Info->Base);
|
|
|
|
if (LocalIt == Vars.end()) {
|
|
|
|
LLVM_DEBUG(
|
|
|
|
errs()
|
|
|
|
<< " | SKIP: Base address not associated with local variable\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DIAssignID *ID =
|
|
|
|
cast_or_null<DIAssignID>(I.getMetadata(LLVMContext::MD_DIAssignID));
|
|
|
|
if (!ID) {
|
|
|
|
ID = DIAssignID::getDistinct(Ctx);
|
|
|
|
I.setMetadata(LLVMContext::MD_DIAssignID, ID);
|
|
|
|
}
|
|
|
|
|
2024-01-23 16:38:49 +00:00
|
|
|
for (const VarRecord &R : LocalIt->second)
|
|
|
|
emitDbgAssign(*Info, ValueComponent, DestComponent, I, R, DIB);
|
2022-11-07 17:39:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-22 16:29:44 +00:00
|
|
|
bool AssignmentTrackingPass::runOnFunction(Function &F) {
|
2023-03-29 12:54:39 +01:00
|
|
|
// No value in assignment tracking without optimisations.
|
|
|
|
if (F.hasFnAttribute(Attribute::OptimizeNone))
|
|
|
|
return /*Changed*/ false;
|
|
|
|
|
2023-02-22 16:29:44 +00:00
|
|
|
bool Changed = false;
|
2024-06-28 08:36:49 +02:00
|
|
|
auto *DL = &F.getDataLayout();
|
2022-11-07 17:39:40 +00:00
|
|
|
// Collect a map of {backing storage : dbg.declares} (currently "backing
|
|
|
|
// storage" is limited to Allocas). We'll use this to find dbg.declares to
|
|
|
|
// delete after running `trackAssignments`.
|
|
|
|
DenseMap<const AllocaInst *, SmallPtrSet<DbgDeclareInst *, 2>> DbgDeclares;
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
DenseMap<const AllocaInst *, SmallPtrSet<DbgVariableRecord *, 2>> DVRDeclares;
|
2022-11-07 17:39:40 +00:00
|
|
|
// Create another similar map of {storage : variables} that we'll pass to
|
|
|
|
// trackAssignments.
|
|
|
|
StorageToVarsMap Vars;
|
2024-01-23 16:38:49 +00:00
|
|
|
auto ProcessDeclare = [&](auto *Declare, auto &DeclareList) {
|
|
|
|
// FIXME: trackAssignments doesn't let you specify any modifiers to the
|
|
|
|
// variable (e.g. fragment) or location (e.g. offset), so we have to
|
|
|
|
// leave dbg.declares with non-empty expressions in place.
|
|
|
|
if (Declare->getExpression()->getNumElements() != 0)
|
|
|
|
return;
|
|
|
|
if (!Declare->getAddress())
|
|
|
|
return;
|
|
|
|
if (AllocaInst *Alloca =
|
|
|
|
dyn_cast<AllocaInst>(Declare->getAddress()->stripPointerCasts())) {
|
|
|
|
// FIXME: Skip VLAs for now (let these variables use dbg.declares).
|
|
|
|
if (!Alloca->isStaticAlloca())
|
|
|
|
return;
|
|
|
|
// Similarly, skip scalable vectors (use dbg.declares instead).
|
|
|
|
if (auto Sz = Alloca->getAllocationSize(*DL); Sz && Sz->isScalable())
|
|
|
|
return;
|
|
|
|
DeclareList[Alloca].insert(Declare);
|
|
|
|
Vars[Alloca].insert(VarRecord(Declare));
|
|
|
|
}
|
|
|
|
};
|
2022-11-07 17:39:40 +00:00
|
|
|
for (auto &BB : F) {
|
|
|
|
for (auto &I : BB) {
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
|
|
|
|
if (DVR.isDbgDeclare())
|
|
|
|
ProcessDeclare(&DVR, DVRDeclares);
|
2022-11-07 17:39:40 +00:00
|
|
|
}
|
2024-01-23 16:38:49 +00:00
|
|
|
if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(&I))
|
|
|
|
ProcessDeclare(DDI, DbgDeclares);
|
2022-11-07 17:39:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Locals can be backed by caller allocas (sret, byval).
|
|
|
|
// Note: trackAssignments doesn't respect dbg.declare's IR positions (as it
|
|
|
|
// doesn't "understand" dbg.declares). However, this doesn't appear to break
|
|
|
|
// any rules given this description of dbg.declare from
|
|
|
|
// llvm/docs/SourceLevelDebugging.rst:
|
|
|
|
//
|
|
|
|
// It is not control-dependent, meaning that if a call to llvm.dbg.declare
|
|
|
|
// exists and has a valid location argument, that address is considered to
|
|
|
|
// be the true home of the variable across its entire lifetime.
|
|
|
|
trackAssignments(F.begin(), F.end(), Vars, *DL);
|
|
|
|
|
|
|
|
// Delete dbg.declares for variables now tracked with assignment tracking.
|
2024-01-23 16:38:49 +00:00
|
|
|
auto DeleteSubsumedDeclare = [&](const auto &Markers, auto &Declares) {
|
2022-11-08 09:04:04 -08:00
|
|
|
(void)Markers;
|
2024-01-23 16:38:49 +00:00
|
|
|
for (auto *Declare : Declares) {
|
|
|
|
// Assert that the alloca that Declare uses is now linked to a dbg.assign
|
2023-04-12 12:28:59 +01:00
|
|
|
// describing the same variable (i.e. check that this dbg.declare has
|
|
|
|
// been replaced by a dbg.assign). Use DebugVariableAggregate to Discard
|
|
|
|
// the fragment part because trackAssignments may alter the
|
|
|
|
// fragment. e.g. if the alloca is smaller than the variable, then
|
|
|
|
// trackAssignments will create an alloca-sized fragment for the
|
|
|
|
// dbg.assign.
|
2024-01-23 16:38:49 +00:00
|
|
|
assert(llvm::any_of(Markers, [Declare](auto *Assign) {
|
|
|
|
return DebugVariableAggregate(Assign) ==
|
|
|
|
DebugVariableAggregate(Declare);
|
|
|
|
}));
|
|
|
|
// Delete Declare because the variable location is now tracked using
|
2022-11-07 17:39:40 +00:00
|
|
|
// assignment tracking.
|
2024-01-23 16:38:49 +00:00
|
|
|
Declare->eraseFromParent();
|
2023-02-22 16:29:44 +00:00
|
|
|
Changed = true;
|
2022-11-07 17:39:40 +00:00
|
|
|
}
|
2024-01-23 16:38:49 +00:00
|
|
|
};
|
|
|
|
for (auto &P : DbgDeclares)
|
|
|
|
DeleteSubsumedDeclare(at::getAssignmentMarkers(P.first), P.second);
|
[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)
This is the major rename patch that prior patches have built towards.
The DPValue class is being renamed to DbgVariableRecord, which reflects
the updated terminology for the "final" implementation of the RemoveDI
feature. This is a pure string substitution + clang-format patch. The
only manual component of this patch was determining where to perform
these string substitutions: `DPValue` and `DPV` are almost exclusively
used for DbgRecords, *except* for:
- llvm/lib/target, where 'DP' is used to mean double-precision, and so
appears as part of .td files and in variable names. NB: There is a
single existing use of `DPValue` here that refers to debug info, which
I've manually updated.
- llvm/tools/gold, where 'LDPV' is used as a prefix for symbol
visibility enums.
Outside of these places, I've applied several basic string
substitutions, with the intent that they only affect DbgRecord-related
identifiers; I've checked them as I went through to verify this, with
reasonable confidence that there are no unintended changes that slipped
through the cracks. The substitutions applied are all case-sensitive,
and are applied in the order shown:
```
DPValue -> DbgVariableRecord
DPVal -> DbgVarRec
DPV -> DVR
```
Following the previous rename patches, it should be the case that there
are no instances of any of these strings that are meant to refer to the
general case of DbgRecords, or anything other than the DPValue class.
The idea behind this patch is therefore that pure string substitution is
correct in all cases as long as these assumptions hold.
2024-03-19 20:07:07 +00:00
|
|
|
for (auto &P : DVRDeclares)
|
|
|
|
DeleteSubsumedDeclare(at::getDVRAssignmentMarkers(P.first), P.second);
|
2023-02-22 16:29:44 +00:00
|
|
|
return Changed;
|
2022-11-07 17:39:40 +00:00
|
|
|
}
|
|
|
|
|
2023-01-20 14:19:14 +00:00
|
|
|
static const char *AssignmentTrackingModuleFlag =
|
|
|
|
"debug-info-assignment-tracking";
|
|
|
|
|
|
|
|
static void setAssignmentTrackingModuleFlag(Module &M) {
|
|
|
|
M.setModuleFlag(Module::ModFlagBehavior::Max, AssignmentTrackingModuleFlag,
|
|
|
|
ConstantAsMetadata::get(
|
|
|
|
ConstantInt::get(Type::getInt1Ty(M.getContext()), 1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool getAssignmentTrackingModuleFlag(const Module &M) {
|
|
|
|
Metadata *Value = M.getModuleFlag(AssignmentTrackingModuleFlag);
|
|
|
|
return Value && !cast<ConstantAsMetadata>(Value)->getValue()->isZeroValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool llvm::isAssignmentTrackingEnabled(const Module &M) {
|
|
|
|
return getAssignmentTrackingModuleFlag(M);
|
|
|
|
}
|
|
|
|
|
2022-11-07 17:39:40 +00:00
|
|
|
PreservedAnalyses AssignmentTrackingPass::run(Function &F,
|
|
|
|
FunctionAnalysisManager &AM) {
|
2023-02-22 16:29:44 +00:00
|
|
|
if (!runOnFunction(F))
|
|
|
|
return PreservedAnalyses::all();
|
2023-01-20 14:19:14 +00:00
|
|
|
|
|
|
|
// Record that this module uses assignment tracking. It doesn't matter that
|
|
|
|
// some functons in the module may not use it - the debug info in those
|
|
|
|
// functions will still be handled properly.
|
|
|
|
setAssignmentTrackingModuleFlag(*F.getParent());
|
|
|
|
|
2022-11-07 17:39:40 +00:00
|
|
|
// Q: Can we return a less conservative set than just CFGAnalyses? Can we
|
|
|
|
// return PreservedAnalyses::all()?
|
|
|
|
PreservedAnalyses PA;
|
|
|
|
PA.preserveSet<CFGAnalyses>();
|
|
|
|
return PA;
|
|
|
|
}
|
|
|
|
|
|
|
|
PreservedAnalyses AssignmentTrackingPass::run(Module &M,
|
|
|
|
ModuleAnalysisManager &AM) {
|
2023-02-22 16:29:44 +00:00
|
|
|
bool Changed = false;
|
2022-11-07 17:39:40 +00:00
|
|
|
for (auto &F : M)
|
2023-02-22 16:29:44 +00:00
|
|
|
Changed |= runOnFunction(F);
|
|
|
|
|
|
|
|
if (!Changed)
|
|
|
|
return PreservedAnalyses::all();
|
2023-01-20 14:19:14 +00:00
|
|
|
|
|
|
|
// Record that this module uses assignment tracking.
|
|
|
|
setAssignmentTrackingModuleFlag(M);
|
|
|
|
|
2022-11-07 17:39:40 +00:00
|
|
|
// Q: Can we return a less conservative set than just CFGAnalyses? Can we
|
|
|
|
// return PreservedAnalyses::all()?
|
|
|
|
PreservedAnalyses PA;
|
|
|
|
PA.preserveSet<CFGAnalyses>();
|
|
|
|
return PA;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef DEBUG_TYPE
|