[llvm] r331123 - [LLVM-C] Add DIBuilder bindings to create import declarations

Robert Widmann via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 28 15:32:07 PDT 2018


Author: codafi
Date: Sat Apr 28 15:32:07 2018
New Revision: 331123

URL: http://llvm.org/viewvc/llvm-project?rev=331123&view=rev
Log:
[LLVM-C] Add DIBuilder bindings to create import declarations

Summary: Add bindings to create import declarations for modules, functions, types, and other entities.  This wraps the conveniences available in the existing DIBuilder API, but these seem C++-specific.

Reviewers: whitequark, harlanhaskins, deadalnix

Reviewed By: whitequark

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D46167

Modified:
    llvm/trunk/include/llvm-c/DebugInfo.h
    llvm/trunk/lib/IR/DebugInfo.cpp
    llvm/trunk/test/Bindings/llvm-c/debug_info.ll
    llvm/trunk/tools/llvm-c-test/debuginfo.c

Modified: llvm/trunk/include/llvm-c/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/DebugInfo.h?rev=331123&r1=331122&r2=331123&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/DebugInfo.h (original)
+++ llvm/trunk/include/llvm-c/DebugInfo.h Sat Apr 28 15:32:07 2018
@@ -304,6 +304,72 @@ LLVMDIBuilderCreateLexicalBlockFile(LLVM
                                     unsigned Discriminator);
 
 /**
+ * Create a descriptor for an imported namespace. Suitable for e.g. C++
+ * using declarations.
+ * \param Builder    The \c DIBuilder.
+ * \param Scope      The scope this module is imported into
+ * \param File       File where the declaration is located.
+ * \param Line       Line number of the declaration.
+ */
+LLVMMetadataRef
+LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder,
+                                               LLVMMetadataRef Scope,
+                                               LLVMMetadataRef NS,
+                                               LLVMMetadataRef File,
+                                               unsigned Line);
+
+/**
+ * Create a descriptor for an imported module that aliases another
+ * imported entity descriptor.
+ * \param Builder        The \c DIBuilder.
+ * \param Scope          The scope this module is imported into
+ * \param ImportedEntity Previous imported entity to alias.
+ * \param File           File where the declaration is located.
+ * \param Line           Line number of the declaration.
+ */
+LLVMMetadataRef
+LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder,
+                                           LLVMMetadataRef Scope,
+                                           LLVMMetadataRef ImportedEntity,
+                                           LLVMMetadataRef File,
+                                           unsigned Line);
+
+/**
+ * Create a descriptor for an imported module.
+ * \param Builder    The \c DIBuilder.
+ * \param Scope      The scope this module is imported into
+ * \param M          The module being imported here
+ * \param File       File where the declaration is located.
+ * \param Line       Line number of the declaration.
+ */
+LLVMMetadataRef
+LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder,
+                                            LLVMMetadataRef Scope,
+                                            LLVMMetadataRef M,
+                                            LLVMMetadataRef File,
+                                            unsigned Line);
+
+/**
+ * Create a descriptor for an imported function, type, or variable.  Suitable
+ * for e.g. FORTRAN-style USE declarations.
+ * \param Builder    The DIBuilder.
+ * \param Scope      The scope this module is imported into.
+ * \param Decl       The declaration (or definition) of a function, type,
+                     or variable.
+ * \param File       File where the declaration is located.
+ * \param Line       Line number of the declaration.
+ * \param Name       A name that uniquely identifies this imported declaration.
+ * \param NameLen    The length of the C string passed to \c Name.
+ */
+LLVMMetadataRef
+LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder,
+                                       LLVMMetadataRef Scope,
+                                       LLVMMetadataRef Decl,
+                                       LLVMMetadataRef File,
+                                       unsigned Line,
+                                       const char *Name, size_t NameLen);
+
+/**
  * Creates a new DebugLocation that describes a source location.
  * \param Line The line in the source file.
  * \param Column The column in the source file.

Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=331123&r1=331122&r2=331123&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Sat Apr 28 15:32:07 2018
@@ -829,6 +829,55 @@ LLVMDIBuilderCreateLexicalBlockFile(LLVM
 }
 
 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));
+}
+
+LLVMMetadataRef
+LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder,
+                                           LLVMMetadataRef Scope,
+                                           LLVMMetadataRef ImportedEntity,
+                                           LLVMMetadataRef File,
+                                           unsigned Line) {
+  return wrap(unwrap(Builder)->createImportedModule(
+                  unwrapDI<DIScope>(Scope),
+                  unwrapDI<DIImportedEntity>(ImportedEntity),
+                  unwrapDI<DIFile>(File), Line));
+}
+
+LLVMMetadataRef
+LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder,
+                                            LLVMMetadataRef Scope,
+                                            LLVMMetadataRef M,
+                                            LLVMMetadataRef File,
+                                            unsigned Line) {
+  return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope),
+                                                    unwrapDI<DIModule>(M),
+                                                    unwrapDI<DIFile>(File),
+                                                    Line));
+}
+
+LLVMMetadataRef
+LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder,
+                                       LLVMMetadataRef Scope,
+                                       LLVMMetadataRef Decl,
+                                       LLVMMetadataRef File,
+                                       unsigned Line,
+                                       const char *Name, size_t NameLen) {
+  return wrap(unwrap(Builder)->createImportedDeclaration(
+                  unwrapDI<DIScope>(Scope),
+                  unwrapDI<DINode>(Decl),
+                  unwrapDI<DIFile>(File), Line, {Name, NameLen}));
+}
+
+LLVMMetadataRef
 LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line,
                                  unsigned Column, LLVMMetadataRef Scope,
                                  LLVMMetadataRef InlinedAt) {

Modified: llvm/trunk/test/Bindings/llvm-c/debug_info.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/llvm-c/debug_info.ll?rev=331123&r1=331122&r2=331123&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/llvm-c/debug_info.ll (original)
+++ llvm/trunk/test/Bindings/llvm-c/debug_info.ll Sat Apr 28 15:32:07 2018
@@ -3,22 +3,22 @@
 ; CHECK: ; ModuleID = 'debuginfo.c'
 ; CHECK-NEXT: source_filename = "debuginfo.c"
 
-; CHECK:      define i64 @foo(i64, i64, <10 x i64>) !dbg !12 {
+; CHECK:      define i64 @foo(i64, i64, <10 x i64>) !dbg !16 {
 ; CHECK-NEXT: entry:
-; CHECK-NEXT:   call void @llvm.dbg.declare(metadata i64 0, metadata !19, metadata !DIExpression()), !dbg !24
-; CHECK-NEXT:   call void @llvm.dbg.declare(metadata i64 0, metadata !20, metadata !DIExpression()), !dbg !24
-; CHECK-NEXT:   call void @llvm.dbg.declare(metadata i64 0, metadata !21, metadata !DIExpression()), !dbg !24
+; CHECK-NEXT:   call void @llvm.dbg.declare(metadata i64 0, metadata !23, metadata !DIExpression()), !dbg !28
+; CHECK-NEXT:   call void @llvm.dbg.declare(metadata i64 0, metadata !24, metadata !DIExpression()), !dbg !28
+; CHECK-NEXT:   call void @llvm.dbg.declare(metadata i64 0, metadata !25, metadata !DIExpression()), !dbg !28
 ; CHECK:      vars:
-; CHECK-NEXT:   call void @llvm.dbg.value(metadata i64 0, metadata !22, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !25
+; CHECK-NEXT:   call void @llvm.dbg.value(metadata i64 0, metadata !26, metadata !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)), !dbg !29
 ; CHECK-NEXT: }
 
 ; CHECK: declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
 ; CHECK: declare void @llvm.dbg.value(metadata, metadata, metadata) #0
 
 ; CHECK: !llvm.dbg.cu = !{!0}
-; CHECK: !FooType = !{!8}
+; CHECK: !FooType = !{!12}
 
-; CHECK:      !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, splitDebugInlining: false)
+; CHECK:      !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, imports: !8, splitDebugInlining: false)
 ; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
 ; CHECK-NEXT: !2 = !{}
 ; CHECK-NEXT: !3 = !{!4}
@@ -26,21 +26,25 @@
 ; CHECK-NEXT: !5 = distinct !DIGlobalVariable(name: "global", scope: !6, file: !1, line: 1, type: !7, isLocal: true, isDefinition: true)
 ; CHECK-NEXT: !6 = !DIModule(scope: null, name: "llvm-c-test", includePath: "/test/include/llvm-c-test.h")
 ; CHECK-NEXT: !7 = !DIBasicType(name: "Int64", size: 64)
-; CHECK-NEXT: !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 192, dwarfAddressSpace: 0)
-; CHECK-NEXT: !9 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !10, file: !1, size: 192, elements: !11, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
-; CHECK-NEXT: !10 = !DINamespace(name: "NameSpace", scope: !6)
-; CHECK-NEXT: !11 = !{!7, !7, !7}
-; CHECK-NEXT: !12 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !13, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !18)
-; CHECK-NEXT: !13 = !DISubroutineType(types: !14)
-; CHECK-NEXT: !14 = !{!7, !7, !15}
-; CHECK-NEXT: !15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 640, flags: DIFlagVector, elements: !16)
-; CHECK-NEXT: !16 = !{!17}
-; CHECK-NEXT: !17 = !DISubrange(count: 10)
-; CHECK-NEXT: !18 = !{!19, !20, !21, !22}
-; CHECK-NEXT: !19 = !DILocalVariable(name: "a", arg: 1, scope: !12, file: !1, line: 42, type: !7)
-; CHECK-NEXT: !20 = !DILocalVariable(name: "b", arg: 2, scope: !12, file: !1, line: 42, type: !7)
-; CHECK-NEXT: !21 = !DILocalVariable(name: "c", arg: 3, scope: !12, file: !1, line: 42, type: !15)
-; CHECK-NEXT: !22 = !DILocalVariable(name: "d", scope: !23, file: !1, line: 43, type: !7)
-; CHECK-NEXT: !23 = distinct !DILexicalBlock(scope: !12, file: !1, line: 42)
-; CHECK-NEXT: !24 = !DILocation(line: 42, scope: !12)
-; CHECK-NEXT: !25 = !DILocation(line: 43, scope: !12)
+; CHECK-NEXT: !8 = !{!9, !11}
+; CHECK-NEXT: !9 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !10, file: !1, line: 42)
+; CHECK-NEXT: !10 = !DIModule(scope: null, name: "llvm-c-test-import", includePath: "/test/include/llvm-c-test-import.h")
+; CHECK-NEXT: !11 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !6, entity: !9, file: !1, line: 42)
+; CHECK-NEXT: !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 192, dwarfAddressSpace: 0)
+; CHECK-NEXT: !13 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !14, file: !1, size: 192, elements: !15, runtimeLang: DW_LANG_C89, identifier: "MyStruct")
+; CHECK-NEXT: !14 = !DINamespace(name: "NameSpace", scope: !6)
+; CHECK-NEXT: !15 = !{!7, !7, !7}
+; CHECK-NEXT: !16 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !17, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !22)
+; CHECK-NEXT: !17 = !DISubroutineType(types: !18)
+; CHECK-NEXT: !18 = !{!7, !7, !19}
+; CHECK-NEXT: !19 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 640, flags: DIFlagVector, elements: !20)
+; CHECK-NEXT: !20 = !{!21}
+; CHECK-NEXT: !21 = !DISubrange(count: 10)
+; CHECK-NEXT: !22 = !{!23, !24, !25, !26}
+; CHECK-NEXT: !23 = !DILocalVariable(name: "a", arg: 1, scope: !16, file: !1, line: 42, type: !7)
+; CHECK-NEXT: !24 = !DILocalVariable(name: "b", arg: 2, scope: !16, file: !1, line: 42, type: !7)
+; CHECK-NEXT: !25 = !DILocalVariable(name: "c", arg: 3, scope: !16, file: !1, line: 42, type: !19)
+; CHECK-NEXT: !26 = !DILocalVariable(name: "d", scope: !27, file: !1, line: 43, type: !7)
+; CHECK-NEXT: !27 = distinct !DILexicalBlock(scope: !16, file: !1, line: 42)
+; CHECK-NEXT: !28 = !DILocation(line: 42, scope: !16)
+; CHECK-NEXT: !29 = !DILocation(line: 43, scope: !16)

Modified: llvm/trunk/tools/llvm-c-test/debuginfo.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/debuginfo.c?rev=331123&r1=331122&r2=331123&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-c-test/debuginfo.c (original)
+++ llvm/trunk/tools/llvm-c-test/debuginfo.c Sat Apr 28 15:32:07 2018
@@ -36,6 +36,19 @@ int llvm_test_dibuilder(void) {
                               "/test/include/llvm-c-test.h", 27,
                               "", 0);
 
+  LLVMMetadataRef OtherModule =
+    LLVMDIBuilderCreateModule(DIB, CompileUnit,
+                              "llvm-c-test-import", 18,
+                              "", 0,
+                              "/test/include/llvm-c-test-import.h", 34,
+                              "", 0);
+  LLVMMetadataRef ImportedModule =
+    LLVMDIBuilderCreateImportedModuleFromModule(DIB, Module, OtherModule,
+                                                File, 42);
+  LLVMMetadataRef AliasImportedModule =
+    LLVMDIBuilderCreateImportedModuleFromAlias(DIB, Module, ImportedModule,
+                                               File, 42);
+
   LLVMMetadataRef Int64Ty =
     LLVMDIBuilderCreateBasicType(DIB, "Int64", 5, 64, 0);
   LLVMMetadataRef GlobalVarValueExpr =




More information about the llvm-commits mailing list