Skip to content

Commit 8452767

Browse files
committed
[LLVM-C] Support debug info for enumerators of arbitrary sizes
1 parent 120ad25 commit 8452767

File tree

5 files changed

+94
-42
lines changed

5 files changed

+94
-42
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ Changes to the C API
246246
the fast-math flags of an instruction, as well as ``LLVMCanValueUseFastMathFlags``
247247
for checking if an instruction can use such flags
248248

249+
* Added ``LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision`` for creating
250+
debugging metadata of enumerators larger than 64 bits.
251+
249252
Changes to the CodeGen infrastructure
250253
-------------------------------------
251254

llvm/include/llvm-c/DebugInfo.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,19 @@ LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder,
611611
int64_t Value,
612612
LLVMBool IsUnsigned);
613613

614+
/**
615+
* Create debugging information entry for an enumerator of arbitrary precision.
616+
* @param Builder The DIBuilder.
617+
* @param Name Enumerator name.
618+
* @param NameLen Length of enumerator name.
619+
* @param SizeInBits Number of bits of the value.
620+
* @param Words The words that make up the value.
621+
* @param IsUnsigned True if the value is unsigned.
622+
*/
623+
LLVMMetadataRef LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision(
624+
LLVMDIBuilderRef Builder, const char *Name, size_t NameLen,
625+
uint64_t SizeInBits, const uint64_t Words[], LLVMBool IsUnsigned);
626+
614627
/**
615628
* Create debugging information entry for an enumeration.
616629
* \param Builder The DIBuilder.

llvm/lib/IR/DebugInfo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "llvm-c/DebugInfo.h"
1515
#include "LLVMContextImpl.h"
16+
#include "llvm/ADT/APSInt.h"
1617
#include "llvm/ADT/DenseMap.h"
1718
#include "llvm/ADT/DenseSet.h"
1819
#include "llvm/ADT/STLExtras.h"
@@ -1226,6 +1227,15 @@ LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder,
12261227
IsUnsigned != 0));
12271228
}
12281229

1230+
LLVMMetadataRef LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision(
1231+
LLVMDIBuilderRef Builder, const char *Name, size_t NameLen,
1232+
uint64_t SizeInBits, const uint64_t Words[], LLVMBool IsUnsigned) {
1233+
uint64_t NumWords = (SizeInBits + 63) / 64;
1234+
return wrap(unwrap(Builder)->createEnumerator(
1235+
{Name, NameLen},
1236+
APSInt(APInt(SizeInBits, ArrayRef(Words, NumWords)), IsUnsigned != 0)));
1237+
}
1238+
12291239
LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
12301240
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
12311241
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,

llvm/test/Bindings/llvm-c/debug_info.ll

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
; CHECK: ; ModuleID = 'debuginfo.c'
44
; CHECK-NEXT: source_filename = "debuginfo.c"
55

6-
; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !31 {
6+
; CHECK: define i64 @foo(i64 %0, i64 %1, <10 x i64> %2) !dbg !36 {
77
; CHECK-NEXT: entry:
8-
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !38, metadata !DIExpression()), !dbg !43
9-
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !39, metadata !DIExpression()), !dbg !43
10-
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !40, metadata !DIExpression()), !dbg !43
8+
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !43, metadata !DIExpression()), !dbg !48
9+
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !44, metadata !DIExpression()), !dbg !48
10+
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !45, metadata !DIExpression()), !dbg !48
1111
; CHECK: vars: ; No predecessors!
12-
; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 0, metadata !41, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !44
12+
; CHECK-NEXT: call void @llvm.dbg.value(metadata i64 0, metadata !46, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !49
1313
; CHECK-NEXT: }
1414

1515
; CHECK: ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
@@ -21,12 +21,13 @@
2121
; CHECK: attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
2222

2323
; CHECK: !llvm.dbg.cu = !{!0}
24-
; CHECK-NEXT: !FooType = !{!28}
24+
; CHECK-NEXT: !FooType = !{!33}
2525
; CHECK-NEXT: !EnumTest = !{!3}
26+
; CHECK-NEXT: !LargeEnumTest = !{!11}
2627

27-
; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !11, imports: !19, macros: !23, splitDebugInlining: false, sysroot: "/")
28+
; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !16, imports: !24, macros: !28, splitDebugInlining: false, sysroot: "/")
2829
; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
29-
; CHECK-NEXT: !2 = !{!3}
30+
; CHECK-NEXT: !2 = !{!3, !11}
3031
; CHECK-NEXT: !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "EnumTest", scope: !4, file: !1, baseType: !6, size: 64, elements: !7)
3132
; CHECK-NEXT: !4 = !DINamespace(name: "NameSpace", scope: !5)
3233
; CHECK-NEXT: !5 = !DIModule(scope: null, name: "llvm-c-test", includePath: "/test/include/llvm-c-test.h")
@@ -35,37 +36,42 @@
3536
; CHECK-NEXT: !8 = !DIEnumerator(name: "Test_A", value: 0, isUnsigned: true)
3637
; CHECK-NEXT: !9 = !DIEnumerator(name: "Test_B", value: 1, isUnsigned: true)
3738
; CHECK-NEXT: !10 = !DIEnumerator(name: "Test_B", value: 2, isUnsigned: true)
38-
; CHECK-NEXT: !11 = !{!12, !16}
39-
; CHECK-NEXT: !12 = !DIGlobalVariableExpression(var: !13, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
40-
; CHECK-NEXT: !13 = distinct !DIGlobalVariable(name: "globalClass", scope: !5, file: !1, line: 1, type: !14, isLocal: true, isDefinition: true)
41-
; CHECK-NEXT: !14 = !DICompositeType(tag: DW_TAG_structure_type, name: "TestClass", scope: !1, file: !1, line: 42, size: 64, flags: DIFlagObjcClassComplete, elements: !15)
42-
; CHECK-NEXT: !15 = !{}
43-
; CHECK-NEXT: !16 = !DIGlobalVariableExpression(var: !17, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
44-
; CHECK-NEXT: !17 = distinct !DIGlobalVariable(name: "global", scope: !5, file: !1, line: 1, type: !18, isLocal: true, isDefinition: true)
45-
; CHECK-NEXT: !18 = !DIDerivedType(tag: DW_TAG_typedef, name: "int64_t", scope: !1, file: !1, line: 42, baseType: !6)
46-
; CHECK-NEXT: !19 = !{!20, !22}
47-
; CHECK-NEXT: !20 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !5, entity: !21, file: !1, line: 42)
48-
; CHECK-NEXT: !21 = !DIModule(scope: null, name: "llvm-c-test-import", includePath: "/test/include/llvm-c-test-import.h")
49-
; CHECK-NEXT: !22 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !5, entity: !20, file: !1, line: 42)
50-
; CHECK-NEXT: !23 = !{!24}
51-
; CHECK-NEXT: !24 = !DIMacroFile(file: !1, nodes: !25)
52-
; CHECK-NEXT: !25 = !{!26, !27}
53-
; CHECK-NEXT: !26 = !DIMacro(type: DW_MACINFO_define, name: "SIMPLE_DEFINE")
54-
; CHECK-NEXT: !27 = !DIMacro(type: DW_MACINFO_define, name: "VALUE_DEFINE", value: "1")
55-
; CHECK-NEXT: !28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !29, size: 192, dwarfAddressSpace: 0)
56-
; CHECK-NEXT: !29 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !4, file: !1, size: 192, elements: !30, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
57-
; CHECK-NEXT: !30 = !{!6, !6, !6}
58-
; CHECK-NEXT: !31 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !32, scopeLine: 42, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !37)
59-
; CHECK-NEXT: !32 = !DISubroutineType(types: !33)
60-
; CHECK-NEXT: !33 = !{!6, !6, !34}
61-
; CHECK-NEXT: !34 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, flags: DIFlagVector, elements: !35)
62-
; CHECK-NEXT: !35 = !{!36}
63-
; CHECK-NEXT: !36 = !DISubrange(count: 10, lowerBound: 0)
64-
; CHECK-NEXT: !37 = !{!38, !39, !40, !41}
65-
; CHECK-NEXT: !38 = !DILocalVariable(name: "a", arg: 1, scope: !31, file: !1, line: 42, type: !6)
66-
; CHECK-NEXT: !39 = !DILocalVariable(name: "b", arg: 2, scope: !31, file: !1, line: 42, type: !6)
67-
; CHECK-NEXT: !40 = !DILocalVariable(name: "c", arg: 3, scope: !31, file: !1, line: 42, type: !34)
68-
; CHECK-NEXT: !41 = !DILocalVariable(name: "d", scope: !42, file: !1, line: 43, type: !6)
69-
; CHECK-NEXT: !42 = distinct !DILexicalBlock(scope: !31, file: !1, line: 42)
70-
; CHECK-NEXT: !43 = !DILocation(line: 42, scope: !31)
71-
; CHECK-NEXT: !44 = !DILocation(line: 43, scope: !31)
39+
; CHECK-NEXT: !11 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "LargeEnumTest", scope: !4, file: !1, baseType: !12, size: 128, elements: !13)
40+
; CHECK-NEXT: !12 = !DIBasicType(name: "UInt128", size: 128)
41+
; CHECK-NEXT: !13 = !{!14, !15}
42+
; CHECK-NEXT: !14 = !DIEnumerator(name: "Test_D", value: 100000000000000000000000000000000000000)
43+
; CHECK-NEXT: !15 = !DIEnumerator(name: "Test_E", value: -1)
44+
; CHECK-NEXT: !16 = !{!17, !21}
45+
; CHECK-NEXT: !17 = !DIGlobalVariableExpression(var: !18, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
46+
; CHECK-NEXT: !18 = distinct !DIGlobalVariable(name: "globalClass", scope: !5, file: !1, line: 1, type: !19, isLocal: true, isDefinition: true)
47+
; CHECK-NEXT: !19 = !DICompositeType(tag: DW_TAG_structure_type, name: "TestClass", scope: !1, file: !1, line: 42, size: 64, flags: DIFlagObjcClassComplete, elements: !20)
48+
; CHECK-NEXT: !20 = !{}
49+
; CHECK-NEXT: !21 = !DIGlobalVariableExpression(var: !22, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
50+
; CHECK-NEXT: !22 = distinct !DIGlobalVariable(name: "global", scope: !5, file: !1, line: 1, type: !23, isLocal: true, isDefinition: true)
51+
; CHECK-NEXT: !23 = !DIDerivedType(tag: DW_TAG_typedef, name: "int64_t", scope: !1, file: !1, line: 42, baseType: !6)
52+
; CHECK-NEXT: !24 = !{!25, !27}
53+
; CHECK-NEXT: !25 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !5, entity: !26, file: !1, line: 42)
54+
; CHECK-NEXT: !26 = !DIModule(scope: null, name: "llvm-c-test-import", includePath: "/test/include/llvm-c-test-import.h")
55+
; CHECK-NEXT: !27 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !5, entity: !25, file: !1, line: 42)
56+
; CHECK-NEXT: !28 = !{!29}
57+
; CHECK-NEXT: !29 = !DIMacroFile(file: !1, nodes: !30)
58+
; CHECK-NEXT: !30 = !{!31, !32}
59+
; CHECK-NEXT: !31 = !DIMacro(type: DW_MACINFO_define, name: "SIMPLE_DEFINE")
60+
; CHECK-NEXT: !32 = !DIMacro(type: DW_MACINFO_define, name: "VALUE_DEFINE", value: "1")
61+
; CHECK-NEXT: !33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !34, size: 192, dwarfAddressSpace: 0)
62+
; CHECK-NEXT: !34 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !4, file: !1, size: 192, elements: !35, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
63+
; CHECK-NEXT: !35 = !{!6, !6, !6}
64+
; CHECK-NEXT: !36 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !37, scopeLine: 42, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !42)
65+
; CHECK-NEXT: !37 = !DISubroutineType(types: !38)
66+
; CHECK-NEXT: !38 = !{!6, !6, !39}
67+
; CHECK-NEXT: !39 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 640, flags: DIFlagVector, elements: !40)
68+
; CHECK-NEXT: !40 = !{!41}
69+
; CHECK-NEXT: !41 = !DISubrange(count: 10, lowerBound: 0)
70+
; CHECK-NEXT: !42 = !{!43, !44, !45, !46}
71+
; CHECK-NEXT: !43 = !DILocalVariable(name: "a", arg: 1, scope: !36, file: !1, line: 42, type: !6)
72+
; CHECK-NEXT: !44 = !DILocalVariable(name: "b", arg: 2, scope: !36, file: !1, line: 42, type: !6)
73+
; CHECK-NEXT: !45 = !DILocalVariable(name: "c", arg: 3, scope: !36, file: !1, line: 42, type: !39)
74+
; CHECK-NEXT: !46 = !DILocalVariable(name: "d", scope: !47, file: !1, line: 43, type: !6)
75+
; CHECK-NEXT: !47 = distinct !DILexicalBlock(scope: !36, file: !1, line: 42)
76+
; CHECK-NEXT: !48 = !DILocation(line: 42, scope: !36)
77+
; CHECK-NEXT: !49 = !DILocation(line: 43, scope: !36)

llvm/tools/llvm-c-test/debuginfo.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,26 @@ int llvm_test_dibuilder(void) {
191191
LLVMAddNamedMetadataOperand(
192192
M, "EnumTest", LLVMMetadataAsValue(LLVMGetModuleContext(M), EnumTest));
193193

194+
LLVMMetadataRef UInt128Ty = LLVMDIBuilderCreateBasicType(
195+
DIB, "UInt128", strlen("UInt128"), 128, 0, LLVMDIFlagZero);
196+
const uint64_t WordsTestD[] = {0x098a224000000000ull, 0x4b3b4ca85a86c47aull};
197+
const uint64_t WordsTestE[] = {0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFFFFFFFFFFull};
198+
199+
LLVMMetadataRef LargeEnumeratorTestD =
200+
LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision(
201+
DIB, "Test_D", strlen("Test_D"), 128, WordsTestD, false);
202+
LLVMMetadataRef LargeEnumeratorTestE =
203+
LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision(
204+
DIB, "Test_E", strlen("Test_E"), 128, WordsTestE, false);
205+
LLVMMetadataRef LargeEnumeratorsTest[] = {LargeEnumeratorTestD,
206+
LargeEnumeratorTestE};
207+
LLVMMetadataRef LargeEnumTest = LLVMDIBuilderCreateEnumerationType(
208+
DIB, NameSpace, "LargeEnumTest", strlen("LargeEnumTest"), File, 0, 128, 0,
209+
LargeEnumeratorsTest, 2, UInt128Ty);
210+
LLVMAddNamedMetadataOperand(
211+
M, "LargeEnumTest",
212+
LLVMMetadataAsValue(LLVMGetModuleContext(M), LargeEnumTest));
213+
194214
LLVMDIBuilderFinalize(DIB);
195215

196216
char *MStr = LLVMPrintModuleToString(M);

0 commit comments

Comments
 (0)