Skip to content

Commit

Permalink
[LLVM-C] DIBuilderBindings for Subrange and Arrays
Browse files Browse the repository at this point in the history
Summary: Move Go bindings for subranges and DINode arrays.

Reviewers: harlanhaskins, whitequark, deadalnix

Reviewed By: whitequark

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330594 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
CodaFi committed Apr 23, 2018
1 parent 5a0bf25 commit cd997a7
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 54 deletions.
26 changes: 0 additions & 26 deletions bindings/go/llvm/DIBuilderBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,6 @@ LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
Context ? unwrap<DIScope>(Context) : nullptr));
}

LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
int64_t Lo, int64_t Count) {
DIBuilder *D = unwrap(Dref);
return wrap(D->getOrCreateSubrange(Lo, Count));
}

LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref,
LLVMMetadataRef *Data,
size_t Length) {
DIBuilder *D = unwrap(Dref);
Metadata **DataValue = unwrap(Data);
ArrayRef<Metadata *> Elements(DataValue, Length);
DINodeArray A = D->getOrCreateArray(Elements);
return wrap(A.get());
}

LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref,
LLVMMetadataRef *Data,
size_t Length) {
DIBuilder *D = unwrap(Dref);
Metadata **DataValue = unwrap(Data);
ArrayRef<Metadata *> Elements(DataValue, Length);
DITypeRefArray A = D->getOrCreateTypeArray(Elements);
return wrap(A.get());
}

LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref,
LLVMValueRef Val,
LLVMMetadataRef VarInfo,
Expand Down
11 changes: 0 additions & 11 deletions bindings/go/llvm/DIBuilderBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef D,
LLVMMetadataRef File, unsigned Line,
LLVMMetadataRef Context);

LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef D, int64_t Lo,
int64_t Count);

LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef D,
LLVMMetadataRef *Data,
size_t Length);

LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef D,
LLVMMetadataRef *Data,
size_t Length);

LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef D, LLVMValueRef Val,
LLVMMetadataRef VarInfo,
LLVMMetadataRef Expr,
Expand Down
30 changes: 30 additions & 0 deletions include/llvm-c/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,16 @@ LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line,
unsigned Column, LLVMMetadataRef Scope,
LLVMMetadataRef InlinedAt);

/**
* Create a type array.
* \param Builder The DIBuilder.
* \param Data The type elements.
* \param NumElements Number of type elements.
*/
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder,
LLVMMetadataRef *Data,
size_t NumElements);

/**
* Create subroutine type.
* \param Builder The DIBuilder.
Expand Down Expand Up @@ -676,6 +686,26 @@ LLVMMetadataRef
LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder,
LLVMMetadataRef Type);

/**
* Create a descriptor for a value range.
* \param Builder The DIBuilder.
* \param LowerBound Lower bound of the subrange, e.g. 0 for C, 1 for Fortran.
* \param Count Count of elements in the subrange.
*/
LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Builder,
int64_t LowerBound,
int64_t Count);

/**
* Create an array of DI Nodes.
* \param Builder The DIBuilder.
* \param Data The DI Node elements.
* \param NumElements Number of DI Node elements.
*/
LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder,
LLVMMetadataRef *Data,
size_t NumElements);

/**
* Create a new descriptor for the specified variable which has a complex
* address expression for its address.
Expand Down
19 changes: 19 additions & 0 deletions lib/IR/DebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,13 @@ LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder,
return wrap(unwrap(Builder)->createArtificialType(unwrapDI<DIType>(Type)));
}

LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder,
LLVMMetadataRef *Types,
size_t Length) {
return wrap(
unwrap(Builder)->getOrCreateTypeArray({unwrap(Types), Length}).get());
}

LLVMMetadataRef
LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder,
LLVMMetadataRef File,
Expand Down Expand Up @@ -1073,6 +1080,18 @@ LLVMMetadataRef LLVMDIBuilderCreateParameterVariable(
map_from_llvmDIFlags(Flags)));
}

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());
}

LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func) {
return wrap(unwrap<Function>(Func)->getSubprogram());
}
Expand Down
31 changes: 18 additions & 13 deletions test/Bindings/llvm-c/debug_info.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
; CHECK: ; ModuleID = 'debuginfo.c'
; CHECK-NEXT: source_filename = "debuginfo.c"

; CHECK: define i64 @foo(i64, i64) !dbg !9 {
; CHECK: define i64 @foo(i64, i64, <10 x i64>) !dbg !9 {
; CHECK-NEXT: entry:
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !13, metadata !DIExpression()), !dbg !15
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !14, metadata !DIExpression()), !dbg !15
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !16, metadata !DIExpression()), !dbg !19
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !17, metadata !DIExpression()), !dbg !19
; CHECK-NEXT: call void @llvm.dbg.declare(metadata i64 0, metadata !18, metadata !DIExpression()), !dbg !19
; CHECK-NEXT: }

; CHECK: declare void @llvm.dbg.declare(metadata, metadata, metadata) #0

; CHECK: declare !dbg !16 i64 @foo_inner_scope(i64, i64)
; CHECK: declare !dbg !20 i64 @foo_inner_scope(i64, i64, <10 x i64>)

; CHECK: !llvm.dbg.cu = !{!0}
; CHECK-NEXT: !FooType = !{!3}
; CHECK: !FooType = !{!3}

; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm-c-test", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false)
; CHECK-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".")
Expand All @@ -25,12 +26,16 @@
; CHECK-NEXT: !6 = !DIModule(scope: null, name: "llvm-c-test", includePath: "/test/include/llvm-c-test.h")
; CHECK-NEXT: !7 = !{!8, !8, !8}
; CHECK-NEXT: !8 = !DIBasicType(name: "Int64", size: 64)
; CHECK-NEXT: !9 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !10, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !12)
; CHECK-NEXT: !9 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 42, type: !10, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !15)
; CHECK-NEXT: !10 = !DISubroutineType(types: !11)
; CHECK-NEXT: !11 = !{!8, !8}
; CHECK-NEXT: !12 = !{!13, !14}
; CHECK-NEXT: !13 = !DILocalVariable(name: "a", arg: 1, scope: !9, file: !1, line: 42, type: !8)
; CHECK-NEXT: !14 = !DILocalVariable(name: "b", arg: 2, scope: !9, file: !1, line: 42, type: !8)
; CHECK-NEXT: !15 = !DILocation(line: 42, scope: !9)
; CHECK-NEXT: !16 = distinct !DISubprogram(name: "foo_inner_scope", linkageName: "foo_inner_scope", scope: !17, file: !1, line: 42, type: !10, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !2)
; CHECK-NEXT: !17 = distinct !DILexicalBlock(scope: !9, file: !1, line: 42)
; CHECK-NEXT: !11 = !{!8, !8, !12}
; CHECK-NEXT: !12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 640, flags: DIFlagVector, elements: !13)
; CHECK-NEXT: !13 = !{!14}
; CHECK-NEXT: !14 = !DISubrange(count: 10)
; CHECK-NEXT: !15 = !{!16, !17, !18}
; CHECK-NEXT: !16 = !DILocalVariable(name: "a", arg: 1, scope: !9, file: !1, line: 42, type: !8)
; CHECK-NEXT: !17 = !DILocalVariable(name: "b", arg: 2, scope: !9, file: !1, line: 42, type: !8)
; CHECK-NEXT: !18 = !DILocalVariable(name: "c", arg: 3, scope: !9, file: !1, line: 42, type: !12)
; CHECK-NEXT: !19 = !DILocation(line: 42, scope: !9)
; CHECK-NEXT: !20 = distinct !DISubprogram(name: "foo_inner_scope", linkageName: "foo_inner_scope", scope: !21, file: !1, line: 42, type: !10, isLocal: true, isDefinition: true, scopeLine: 42, isOptimized: false, unit: !0, variables: !2)
; CHECK-NEXT: !21 = distinct !DILexicalBlock(scope: !9, file: !1, line: 42)
28 changes: 24 additions & 4 deletions tools/llvm-c-test/debuginfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,31 @@ int llvm_test_dibuilder(void) {
LLVMMetadataAsValue(LLVMGetModuleContext(M), StructDbgPtrTy));


LLVMTypeRef FooParamTys[] = { LLVMInt64Type(), LLVMInt64Type() };
LLVMTypeRef FooFuncTy = LLVMFunctionType(LLVMInt64Type(), FooParamTys, 2, 0);
LLVMTypeRef FooParamTys[] = {
LLVMInt64Type(),
LLVMInt64Type(),
LLVMVectorType(LLVMInt64Type(), 10),
};
LLVMTypeRef FooFuncTy = LLVMFunctionType(LLVMInt64Type(), FooParamTys, 3, 0);
LLVMValueRef FooFunction = LLVMAddFunction(M, "foo", FooFuncTy);
LLVMBasicBlockRef FooEntryBlock = LLVMAppendBasicBlock(FooFunction, "entry");

LLVMMetadataRef ParamTypes[] = {Int64Ty, Int64Ty};
LLVMMetadataRef Subscripts[] = {
LLVMDIBuilderGetOrCreateSubrange(DIB, 0, 10),
};
LLVMMetadataRef VectorTy =
LLVMDIBuilderCreateVectorType(DIB, 64 * 10, 0,
Int64Ty, Subscripts, 1);


LLVMMetadataRef ParamTypes[] = {Int64Ty, Int64Ty, VectorTy};
LLVMMetadataRef FunctionTy =
LLVMDIBuilderCreateSubroutineType(DIB, File, ParamTypes, 2, 0);
LLVMDIBuilderCreateSubroutineType(DIB, File, ParamTypes, 3, 0);
LLVMMetadataRef FunctionMetadata =
LLVMDIBuilderCreateFunction(DIB, File, "foo", 3, "foo", 3,
File, 42, FunctionTy, true, true,
42, 0, false);

LLVMMetadataRef FooParamLocation =
LLVMDIBuilderCreateDebugLocation(LLVMGetGlobalContext(), 42, 0,
FunctionMetadata, NULL);
Expand All @@ -84,6 +97,13 @@ int llvm_test_dibuilder(void) {
LLVMDIBuilderInsertDeclareAtEnd(DIB, LLVMConstInt(LLVMInt64Type(), 0, false),
FooParamVar2, FooParamExpression,
FooParamLocation, FooEntryBlock);
LLVMMetadataRef FooParamVar3 =
LLVMDIBuilderCreateParameterVariable(DIB, FunctionMetadata, "c", 1, 3, File,
42, VectorTy, true, 0);
LLVMDIBuilderInsertDeclareAtEnd(DIB, LLVMConstInt(LLVMInt64Type(), 0, false),
FooParamVar3, FooParamExpression,
FooParamLocation, FooEntryBlock);

LLVMSetSubprogram(FooFunction, FunctionMetadata);

LLVMMetadataRef FooLexicalBlock =
Expand Down

0 comments on commit cd997a7

Please sign in to comment.