Index: llvm/trunk/bindings/go/llvm/DIBuilderBindings.h =================================================================== --- llvm/trunk/bindings/go/llvm/DIBuilderBindings.h +++ llvm/trunk/bindings/go/llvm/DIBuilderBindings.h @@ -33,11 +33,6 @@ LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Context); -LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef D, LLVMValueRef Val, - LLVMMetadataRef VarInfo, - LLVMMetadataRef Expr, - LLVMBasicBlockRef Block); - #ifdef __cplusplus } // extern "C" #endif Index: llvm/trunk/bindings/go/llvm/DIBuilderBindings.cpp =================================================================== --- llvm/trunk/bindings/go/llvm/DIBuilderBindings.cpp +++ llvm/trunk/bindings/go/llvm/DIBuilderBindings.cpp @@ -28,19 +28,3 @@ File ? unwrap(File) : nullptr, Line, Context ? unwrap(Context) : nullptr)); } - -LLVMValueRef LLVMDIBuilderInsertValueAtEnd(LLVMDIBuilderRef Dref, - LLVMValueRef Val, - LLVMMetadataRef VarInfo, - LLVMMetadataRef Expr, - LLVMBasicBlockRef Block) { - // Fail immediately here until the llgo folks update their bindings. The - // called function is going to assert out anyway. - llvm_unreachable("DIBuilder API change requires a DebugLoc"); - - DIBuilder *D = unwrap(Dref); - Instruction *Instr = D->insertDbgValueIntrinsic( - unwrap(Val), unwrap(VarInfo), unwrap(Expr), - /* DebugLoc */ nullptr, unwrap(Block)); - return wrap(Instr); -} Index: llvm/trunk/bindings/go/llvm/dibuilder.go =================================================================== --- llvm/trunk/bindings/go/llvm/dibuilder.go +++ llvm/trunk/bindings/go/llvm/dibuilder.go @@ -571,7 +571,7 @@ // InsertValueAtEnd inserts a call to llvm.dbg.value at the end of the // specified basic block for the given value and associated debug metadata. func (d *DIBuilder) InsertValueAtEnd(v Value, diVarInfo, expr Metadata, bb BasicBlock) Value { - result := C.LLVMDIBuilderInsertValueAtEnd(d.ref, v.C, diVarInfo.C, expr.C, bb.C) + result := C.LLVMDIBuilderInsertDbgValueAtEnd(d.ref, v.C, diVarInfo.C, expr.C, nil, bb.C) return Value{C: result} } Index: llvm/trunk/include/llvm-c/DebugInfo.h =================================================================== --- llvm/trunk/include/llvm-c/DebugInfo.h +++ llvm/trunk/include/llvm-c/DebugInfo.h @@ -717,6 +717,78 @@ int64_t *Addr, size_t Length); /** + * Create a new descriptor for the specified variable that does not have an + * address, but does have a constant value. + * \param Builder The DIBuilder. + * \param Value The constant value. + */ +LLVMMetadataRef +LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder, + int64_t Value); + +/** + * Create a new descriptor for the specified variable. + * \param Scope Variable scope. + * \param Name Name of the variable. + * \param NameLen The length of the C string passed to \c Name. + * \param Linkage Mangled name of the variable. + * \param LinkLen The length of the C string passed to \c Linkage. + * \param File File where this variable is defined. + * \param LineNo Line number. + * \param Ty Variable Type. + * \param LocalToUnit Boolean flag indicate whether this variable is + * externally visible or not. + * \param Expr The location of the global relative to the attached + * GlobalVariable. + * \param Decl Reference to the corresponding declaration. + * \param AlignInBits Variable alignment(or 0 if no alignment attr was + * specified) + */ +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); + +/** + * Create a new descriptor for the specified global variable that is temporary + * and meant to be RAUWed. + * \param Scope Variable scope. + * \param Name Name of the variable. + * \param NameLen The length of the C string passed to \c Name. + * \param Linkage Mangled name of the variable. + * \param LnkLen The length of the C string passed to \c Linkage. + * \param File File where this variable is defined. + * \param LineNo Line number. + * \param Ty Variable Type. + * \param LocalToUnit Boolean flag indicate whether this variable is + * externally visible or not. + * \param Expr The location of the global relative to the attached + * GlobalVariable. + * \param Decl Reference to the corresponding declaration. + * \param AlignInBits Variable alignment(or 0 if no alignment attr was + * specified) + */ +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); + +/** * Insert a new llvm.dbg.declare intrinsic call before the given instruction. * \param Builder The DIBuilder. * \param Storage The storage of the variable to declare. @@ -745,6 +817,40 @@ LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block); /** + * Insert a new llvm.dbg.value intrinsic call before the given instruction. + * \param Builder The DIBuilder. + * \param Val The value of the variable. + * \param VarInfo The variable's debug info descriptor. + * \param Expr A complex location expression for the variable. + * \param DebugLoc Debug info location. + * \param Instr Instruction acting as a location for the new intrinsic. + */ +LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, + LLVMValueRef Val, + LLVMMetadataRef VarInfo, + LLVMMetadataRef Expr, + LLVMMetadataRef DebugLoc, + LLVMValueRef Instr); + +/** + * Insert a new llvm.dbg.value intrinsic call at the end of the given basic + * block. If the basic block has a terminator instruction, the intrinsic is + * inserted before that terminator instruction. + * \param Builder The DIBuilder. + * \param Val The value of the variable. + * \param VarInfo The variable's debug info descriptor. + * \param Expr A complex location expression for the variable. + * \param DebugLoc Debug info location. + * \param Block Basic block acting as a location for the new intrinsic. + */ +LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder, + LLVMValueRef Val, + LLVMMetadataRef VarInfo, + LLVMMetadataRef Expr, + LLVMMetadataRef DebugLoc, + LLVMBasicBlockRef Block); + +/** * Create a new descriptor for a local auto variable. * \param Builder The DIBuilder. * \param Scope The local scope the variable is declared in. Index: llvm/trunk/lib/IR/DebugInfo.cpp =================================================================== --- llvm/trunk/lib/IR/DebugInfo.cpp +++ llvm/trunk/lib/IR/DebugInfo.cpp @@ -1042,6 +1042,48 @@ Length))); } +LLVMMetadataRef +LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder, + int64_t Value) { + return wrap(unwrap(Builder)->createConstantValueExpression(Value)); +} + +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) { + return wrap(unwrap(Builder)->createGlobalVariableExpression( + unwrapDI(Scope), {Name, NameLen}, {Linkage, LinkLen}, + unwrapDI(File), LineNo, unwrapDI(Ty), + LocalToUnit, unwrap(Expr), + unwrapDI(Decl), AlignInBits)); +} + +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) { + return wrap(unwrap(Builder)->createTempGlobalVariableFwdDecl( + unwrapDI(Scope), {Name, NameLen}, {Linkage, LnkLen}, + unwrapDI(File), LineNo, unwrapDI(Ty), + LocalToUnit, unwrapDI(Decl), AlignInBits)); +} + LLVMValueRef LLVMDIBuilderInsertDeclareBefore( LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMValueRef Instr) { @@ -1060,6 +1102,30 @@ unwrap(Block))); } +LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, + LLVMValueRef Val, + LLVMMetadataRef VarInfo, + LLVMMetadataRef Expr, + LLVMMetadataRef DebugLoc, + LLVMValueRef Instr) { + return wrap(unwrap(Builder)->insertDbgValueIntrinsic( + unwrap(Val), unwrap(VarInfo), + unwrap(Expr), unwrap(DebugLoc), + unwrap(Instr))); +} + +LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder, + LLVMValueRef Val, + LLVMMetadataRef VarInfo, + LLVMMetadataRef Expr, + LLVMMetadataRef DebugLoc, + LLVMBasicBlockRef Block) { + return wrap(unwrap(Builder)->insertDbgValueIntrinsic( + unwrap(Val), unwrap(VarInfo), + unwrap(Expr), unwrap(DebugLoc), + unwrap(Block))); +} + LLVMMetadataRef LLVMDIBuilderCreateAutoVariable( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, Index: llvm/trunk/test/Bindings/llvm-c/debug_info.ll =================================================================== --- llvm/trunk/test/Bindings/llvm-c/debug_info.ll +++ llvm/trunk/test/Bindings/llvm-c/debug_info.ll @@ -3,39 +3,44 @@ ; CHECK: ; ModuleID = 'debuginfo.c' ; CHECK-NEXT: source_filename = "debuginfo.c" -; CHECK: define i64 @foo(i64, i64, <10 x i64>) !dbg !9 { +; CHECK: define i64 @foo(i64, i64, <10 x i64>) !dbg !12 { ; CHECK-NEXT: entry: -; 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: 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: 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: } ; CHECK: declare void @llvm.dbg.declare(metadata, metadata, metadata) #0 - -; CHECK: declare !dbg !20 i64 @foo_inner_scope(i64, i64, <10 x i64>) +; CHECK: declare void @llvm.dbg.value(metadata, metadata, metadata) #0 ; CHECK: !llvm.dbg.cu = !{!0} -; CHECK: !FooType = !{!3} +; CHECK: !FooType = !{!8} -; 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: !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-NEXT: !1 = !DIFile(filename: "debuginfo.c", directory: ".") ; CHECK-NEXT: !2 = !{} -; CHECK-NEXT: !3 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 192, dwarfAddressSpace: 0) -; CHECK-NEXT: !4 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyStruct", scope: !5, file: !1, size: 192, elements: !7, runtimeLang: DW_LANG_C89, identifier: "MyStruct") -; CHECK-NEXT: !5 = !DINamespace(name: "NameSpace", scope: !6) +; CHECK-NEXT: !3 = !{!4} +; CHECK-NEXT: !4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)) +; 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 = !{!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: !15) -; CHECK-NEXT: !10 = !DISubroutineType(types: !11) -; 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) +; 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) Index: llvm/trunk/tools/llvm-c-test/debuginfo.c =================================================================== --- llvm/trunk/tools/llvm-c-test/debuginfo.c +++ llvm/trunk/tools/llvm-c-test/debuginfo.c @@ -36,11 +36,17 @@ "/test/include/llvm-c-test.h", 27, "", 0); - LLVMMetadataRef NameSpace = - LLVMDIBuilderCreateNameSpace(DIB, Module, "NameSpace", 9, false); - LLVMMetadataRef Int64Ty = LLVMDIBuilderCreateBasicType(DIB, "Int64", 5, 64, 0); + LLVMMetadataRef GlobalVarValueExpr = + LLVMDIBuilderCreateConstantValueExpression(DIB, 0); + LLVMDIBuilderCreateGlobalVariableExpression(DIB, Module, "global", 6, + "", 0, File, 1, Int64Ty, + true, GlobalVarValueExpr, + NULL, 0); + + LLVMMetadataRef NameSpace = + LLVMDIBuilderCreateNameSpace(DIB, Module, "NameSpace", 9, false); LLVMMetadataRef StructDbgElts[] = {Int64Ty, Int64Ty, Int64Ty}; LLVMMetadataRef StructDbgTy = @@ -109,14 +115,19 @@ LLVMMetadataRef FooLexicalBlock = LLVMDIBuilderCreateLexicalBlock(DIB, FunctionMetadata, File, 42, 0); - LLVMValueRef InnerFooFunction = - LLVMAddFunction(M, "foo_inner_scope", FooFuncTy); - LLVMMetadataRef InnerFunctionMetadata = - LLVMDIBuilderCreateFunction(DIB, FooLexicalBlock, "foo_inner_scope", 15, - "foo_inner_scope", 15, - File, 42, FunctionTy, true, true, - 42, 0, false); - LLVMSetSubprogram(InnerFooFunction, InnerFunctionMetadata); + LLVMBasicBlockRef FooVarBlock = LLVMAppendBasicBlock(FooFunction, "vars"); + LLVMMetadataRef FooVarsLocation = + LLVMDIBuilderCreateDebugLocation(LLVMGetGlobalContext(), 43, 0, + FunctionMetadata, NULL); + LLVMMetadataRef FooVar1 = + LLVMDIBuilderCreateAutoVariable(DIB, FooLexicalBlock, "d", 1, File, + 43, Int64Ty, true, 0, 0); + LLVMValueRef FooVal1 = LLVMConstInt(LLVMInt64Type(), 0, false); + LLVMMetadataRef FooVarValueExpr = + LLVMDIBuilderCreateConstantValueExpression(DIB, 0); + + LLVMDIBuilderInsertDbgValueAtEnd(DIB, FooVal1, FooVar1, FooVarValueExpr, + FooVarsLocation, FooVarBlock); LLVMDIBuilderFinalize(DIB);