[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
This revision was automatically updated to reflect the committed changes. Closed by commit rL358783: [MS] Emit S_HEAPALLOCSITE debug info (authored by akhuang, committed by ). Changed prior to commit: https://reviews.llvm.org/D60800?vs=195877&id=195909#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 Files: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp llvm/trunk/include/llvm/CodeGen/MachineFunction.h llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h llvm/trunk/lib/CodeGen/MachineFunction.cpp llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp llvm/trunk/test/CodeGen/X86/label-heapallocsite.ll Index: llvm/trunk/lib/CodeGen/MachineFunction.cpp === --- llvm/trunk/lib/CodeGen/MachineFunction.cpp +++ llvm/trunk/lib/CodeGen/MachineFunction.cpp @@ -43,6 +43,7 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constant.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalValue.h" @@ -806,6 +807,16 @@ return FilterID; } +void MachineFunction::addCodeViewHeapAllocSite(MachineInstr *I, MDNode *MD) { + MCSymbol *BeginLabel = Ctx.createTempSymbol("heapallocsite", true); + MCSymbol *EndLabel = Ctx.createTempSymbol("heapallocsite", true); + I->setPreInstrSymbol(*this, BeginLabel); + I->setPostInstrSymbol(*this, EndLabel); + + DIType *DI = dyn_cast(MD); + CodeViewHeapAllocSites.push_back({BeginLabel, EndLabel, DI}); +} + /// \} //===--===// Index: llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp === --- llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp +++ llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1234,6 +1234,12 @@ if (CLI.NumResultRegs && CLI.CS) updateValueMap(CLI.CS->getInstruction(), CLI.ResultReg, CLI.NumResultRegs); + // Set labels for heapallocsite call. + if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) { +MDNode *MD = CLI.CS->getInstruction()->getMetadata("heapallocsite"); +MF->addCodeViewHeapAllocSite(CLI.Call, MD); + } + return true; } Index: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h === --- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h +++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h @@ -147,6 +147,7 @@ SmallVector ChildBlocks; std::vector> Annotations; +std::vector> HeapAllocSites; const MCSymbol *Begin = nullptr; const MCSymbol *End = nullptr; Index: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp === --- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -1072,6 +1072,23 @@ endSymbolRecord(AnnotEnd); } +for (auto HeapAllocSite : FI.HeapAllocSites) { + MCSymbol *BeginLabel = std::get<0>(HeapAllocSite); + MCSymbol *EndLabel = std::get<1>(HeapAllocSite); + DIType *DITy = std::get<2>(HeapAllocSite); + + MCSymbol *HeapAllocEnd = beginSymbolRecord(SymbolKind::S_HEAPALLOCSITE); + OS.AddComment("Call site offset"); + OS.EmitCOFFSecRel32(BeginLabel, /*Offset=*/0); + OS.AddComment("Call site section index"); + OS.EmitCOFFSectionIndex(BeginLabel); + OS.AddComment("Call instruction length"); + OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 2); + OS.AddComment("Type index"); + OS.EmitIntValue(getCompleteTypeIndex(DITy).getIndex(), 4); + endSymbolRecord(HeapAllocEnd); +} + if (SP != nullptr) emitDebugInfoForUDTs(LocalUDTs); @@ -2807,6 +2824,7 @@ } CurFn->Annotations = MF->getCodeViewAnnotations(); + CurFn->HeapAllocSites = MF->getCodeViewHeapAllocSites(); CurFn->End = Asm->getFunctionEnd(); Index: llvm/trunk/include/llvm/CodeGen/MachineFunction.h === --- llvm/trunk/include/llvm/CodeGen/MachineFunction.h +++ llvm/trunk/include/llvm/CodeGen/MachineFunction.h @@ -321,6 +321,10 @@ /// CodeView label annotations. std::vector> CodeViewAnnotations; + /// CodeView heapallocsites. + std::vector> + CodeViewHeapAllocSites; + bool CallsEHReturn = false; bool CallsUnwindInit = false; bool HasEHScopes = false; @@ -906,6 +910,14 @@ return CodeViewAnnotations; } + /// Record heapallocsites + void addCodeViewHeapAllocSite(MachineInstr *I, MDNode *MD); + + ArrayRef> + getCodeViewHeapAllocSites() const { +return CodeViewHeapAllocSites; + } + /// Return a reference to the C++ typeinfo for the current function. const std::vector &getTypeInfos() const { ret
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
akhuang updated this revision to Diff 195877. akhuang added a comment. whitespace fix Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 Files: clang/lib/CodeGen/CGDebugInfo.cpp llvm/include/llvm/CodeGen/MachineFunction.h llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h llvm/lib/CodeGen/MachineFunction.cpp llvm/lib/CodeGen/SelectionDAG/FastISel.cpp llvm/test/CodeGen/X86/label-heapallocsite.ll Index: llvm/test/CodeGen/X86/label-heapallocsite.ll === --- /dev/null +++ llvm/test/CodeGen/X86/label-heapallocsite.ll @@ -0,0 +1,68 @@ +; RUN: llc -O0 < %s | FileCheck %s +; FIXME: Add test for llc with optimizations once it is implemented. + +; Source to regenerate: +; $ clang --target=x86_64-windows-msvc -S heapallocsite.c -g -gcodeview -o t.ll \ +; -emit-llvm -O0 -Xclang -disable-llvm-passes -fms-extensions +; __declspec(allocator) char *myalloc(); +; void g(); +; void foo() { +; g(); +; myalloc() +; g(); +; } + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-windows-msvc" + +; Function Attrs: noinline nounwind optnone +define dso_local void @f() #0 !dbg !7 { +entry: + call void @g(), !dbg !11 + %call = call i8* @myalloc(), !dbg !12, !heapallocsite !13 + call void @g(), !dbg !14 + ret void, !dbg !15 +} + +; CHECK-LABEL: f: # @f +; CHECK: callq g +; CHECK: .Lheapallocsite0: +; CHECK: callq myalloc +; CHECK: .Lheapallocsite1: +; CHECK: retq + +; CHECK-LABEL: .short 4423# Record kind: S_GPROC32_ID +; CHECK: .short 4446# Record kind: S_HEAPALLOCSITE +; CHECK-NEXT: .secrel32 .Lheapallocsite0 +; CHECK-NEXT: .secidx .Lheapallocsite0 +; CHECK-NEXT: .short .Lheapallocsite1-.Lheapallocsite0 +; CHECK-NEXT: .long 112 +; CHECK-NEXT: .p2align 2 + +; CHECK-LABEL: .short 4431# Record kind: S_PROC_ID_END + +declare dso_local void @g() #1 + +declare dso_local i8* @myalloc() #1 + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 2} +!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)"} +!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!8 = !DIFile(filename: "heapallocsite.c", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!9 = !DISubroutineType(types: !10) +!10 = !{null} +!11 = !DILocation(line: 5, scope: !7) +!12 = !DILocation(line: 6, scope: !7) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !DILocation(line: 7, scope: !7) +!15 = !DILocation(line: 8, scope: !7) + Index: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp === --- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1234,6 +1234,12 @@ if (CLI.NumResultRegs && CLI.CS) updateValueMap(CLI.CS->getInstruction(), CLI.ResultReg, CLI.NumResultRegs); + // Set labels for heapallocsite call. + if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) { +MDNode *MD = CLI.CS->getInstruction()->getMetadata("heapallocsite"); +MF->addCodeViewHeapAllocSite(CLI.Call, MD); + } + return true; } Index: llvm/lib/CodeGen/MachineFunction.cpp === --- llvm/lib/CodeGen/MachineFunction.cpp +++ llvm/lib/CodeGen/MachineFunction.cpp @@ -43,6 +43,7 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constant.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalValue.h" @@ -806,6 +807,16 @@ return FilterID; } +void MachineFunction::addCodeViewHeapAllocSite(MachineInstr *I, MDNode *MD) { + MCSymbol *BeginLabel = Ctx.createTempSymbol("heapallocsite", true); + MCSymbol *EndLabel = Ctx.createTempSymbol("heapallocsite", true); + I->setPreInstrSymbol(*this, BeginLabel); + I->setPostInstrSymbol(*this, EndLabel); + + DIType *DI = dyn_cast(MD); + CodeViewHeapAllocSites.push_back({BeginLabel, EndLabel, DI}); +} + /// \}
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
rnk accepted this revision. rnk added a comment. This revision is now accepted and ready to land. lgtm with a minor whitespace issue Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1972 } - CI->setMetadata("heapallocsite", node); Please revert the white space only change to this file. Comment at: llvm/lib/CodeGen/MachineFunction.cpp:816 + + DIType *DI = dyn_cast(MD); + CodeViewHeapAllocSites.push_back({BeginLabel, EndLabel, DI}); I guess it's reasonable to treat any non-DIType as "void". The only other reasonable thing to do would be to report an error, but it's not worth it. Comment at: llvm/test/CodeGen/X86/label-heapallocsite.ll:1 +; RUN: llc -O0 < %s | FileCheck %s +; FIXME: Add test for llc with optimizations once it is implemented. akhuang wrote: > hans wrote: > > Does llc have a "-fast-isel" flag or similar that could be used instead, to > > make it more clear that it's fast-isel that's significant for the test? > I couldn't find a flag that makes llc use fast-isel; it should soon work for > both cases though. FWIW, -O0 is the typical way to enable fast isel in other codegen tests, so even if it's opaque, it's consistent. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
akhuang marked an inline comment as done. akhuang added inline comments. Comment at: llvm/test/CodeGen/X86/label-heapallocsite.ll:1 +; RUN: llc -O0 < %s | FileCheck %s +; FIXME: Add test for llc with optimizations once it is implemented. hans wrote: > Does llc have a "-fast-isel" flag or similar that could be used instead, to > make it more clear that it's fast-isel that's significant for the test? I couldn't find a flag that makes llc use fast-isel; it should soon work for both cases though. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
akhuang updated this revision to Diff 195821. akhuang marked 2 inline comments as done. akhuang added a comment. - Changed test case back to original Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 Files: clang/lib/CodeGen/CGDebugInfo.cpp llvm/include/llvm/CodeGen/MachineFunction.h llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h llvm/lib/CodeGen/MachineFunction.cpp llvm/lib/CodeGen/SelectionDAG/FastISel.cpp llvm/test/CodeGen/X86/label-heapallocsite.ll Index: llvm/test/CodeGen/X86/label-heapallocsite.ll === --- /dev/null +++ llvm/test/CodeGen/X86/label-heapallocsite.ll @@ -0,0 +1,68 @@ +; RUN: llc -O0 < %s | FileCheck %s +; FIXME: Add test for llc with optimizations once it is implemented. + +; Source to regenerate: +; $ clang --target=x86_64-windows-msvc -S heapallocsite.c -g -gcodeview -o t.ll \ +; -emit-llvm -O0 -Xclang -disable-llvm-passes -fms-extensions +; __declspec(allocator) char *myalloc(); +; void g(); +; void foo() { +; g(); +; myalloc() +; g(); +; } + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-windows-msvc" + +; Function Attrs: noinline nounwind optnone +define dso_local void @f() #0 !dbg !7 { +entry: + call void @g(), !dbg !11 + %call = call i8* @myalloc(), !dbg !12, !heapallocsite !13 + call void @g(), !dbg !14 + ret void, !dbg !15 +} + +; CHECK-LABEL: f: # @f +; CHECK: callq g +; CHECK: .Lheapallocsite0: +; CHECK: callq myalloc +; CHECK: .Lheapallocsite1: +; CHECK: retq + +; CHECK-LABEL: .short 4423# Record kind: S_GPROC32_ID +; CHECK: .short 4446# Record kind: S_HEAPALLOCSITE +; CHECK-NEXT: .secrel32 .Lheapallocsite0 +; CHECK-NEXT: .secidx .Lheapallocsite0 +; CHECK-NEXT: .short .Lheapallocsite1-.Lheapallocsite0 +; CHECK-NEXT: .long 112 +; CHECK-NEXT: .p2align 2 + +; CHECK-LABEL: .short 4431# Record kind: S_PROC_ID_END + +declare dso_local void @g() #1 + +declare dso_local i8* @myalloc() #1 + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 2} +!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)"} +!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!8 = !DIFile(filename: "heapallocsite.c", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!9 = !DISubroutineType(types: !10) +!10 = !{null} +!11 = !DILocation(line: 5, scope: !7) +!12 = !DILocation(line: 6, scope: !7) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !DILocation(line: 7, scope: !7) +!15 = !DILocation(line: 8, scope: !7) + Index: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp === --- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1234,6 +1234,12 @@ if (CLI.NumResultRegs && CLI.CS) updateValueMap(CLI.CS->getInstruction(), CLI.ResultReg, CLI.NumResultRegs); + // Set labels for heapallocsite call. + if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) { +MDNode *MD = CLI.CS->getInstruction()->getMetadata("heapallocsite"); +MF->addCodeViewHeapAllocSite(CLI.Call, MD); + } + return true; } Index: llvm/lib/CodeGen/MachineFunction.cpp === --- llvm/lib/CodeGen/MachineFunction.cpp +++ llvm/lib/CodeGen/MachineFunction.cpp @@ -43,6 +43,7 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constant.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalValue.h" @@ -806,6 +807,16 @@ return FilterID; } +void MachineFunction::addCodeViewHeapAllocSite(MachineInstr *I, MDNode *MD) { + MCSymbol *BeginLabel = Ctx.createTempSymbol("heapallocsite", true); + MCSymbol *EndLabel = Ctx.createTempSymbol("heapallocsite", true); + I->setPreInstrSymbol(*this, BeginLabel); + I->setPostInstrSymbol(*this, EndLabel); + + DIType *DI = dyn_cast(MD); + CodeViewHeapA
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
akhuang updated this revision to Diff 195818. akhuang marked 2 inline comments as done. akhuang added a comment. - Pass void metadata as null DIType Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 Files: clang/lib/CodeGen/CGDebugInfo.cpp clang/test/CodeGen/debug-info-codeview-heapallocsite.c llvm/include/llvm/CodeGen/MachineFunction.h llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h llvm/lib/CodeGen/MachineFunction.cpp llvm/lib/CodeGen/SelectionDAG/FastISel.cpp llvm/test/CodeGen/X86/label-heapallocsite.ll Index: llvm/test/CodeGen/X86/label-heapallocsite.ll === --- /dev/null +++ llvm/test/CodeGen/X86/label-heapallocsite.ll @@ -0,0 +1,68 @@ +; RUN: llc -O0 < %s | FileCheck %s +; FIXME: Add test for llc with optimizations once it is implemented. + +; Source to regenerate: +; $ clang --target=x86_64-windows-msvc -S heapallocsite.c -g -gcodeview -o t.ll \ +; -emit-llvm -O0 -Xclang -disable-llvm-passes -fms-extensions +; __declspec(allocator) char *myalloc(); +; void g(); +; void foo() { +; g(); +; myalloc() +; g(); +; } + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-windows-msvc" + +; Function Attrs: noinline nounwind optnone +define dso_local void @f() #0 !dbg !7 { +entry: + call void @g(), !dbg !11 + %call = call i8* @myalloc(), !dbg !12, !heapallocsite !13 + call void @g(), !dbg !14 + ret void, !dbg !15 +} + +; CHECK-LABEL: f: # @f +; CHECK: callq g +; CHECK: .Lheapallocsite0: +; CHECK: callq myalloc +; CHECK: .Lheapallocsite1: +; CHECK: retq + +; CHECK-LABEL: .short 4423# Record kind: S_GPROC32_ID +; CHECK: .short 4446# Record kind: S_HEAPALLOCSITE +; CHECK-NEXT: .secrel32 .Lheapallocsite0 +; CHECK-NEXT: .secidx .Lheapallocsite0 +; CHECK-NEXT: .short .Lheapallocsite1-.Lheapallocsite0 +; CHECK-NEXT: .long 112 +; CHECK-NEXT: .p2align 2 + +; CHECK-LABEL: .short 4431# Record kind: S_PROC_ID_END + +declare dso_local void @g() #1 + +declare dso_local i8* @myalloc() #1 + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 2} +!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)"} +!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!8 = !DIFile(filename: "heapallocsite.c", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!9 = !DISubroutineType(types: !10) +!10 = !{null} +!11 = !DILocation(line: 5, scope: !7) +!12 = !DILocation(line: 6, scope: !7) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !DILocation(line: 7, scope: !7) +!15 = !DILocation(line: 8, scope: !7) + Index: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp === --- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1234,6 +1234,12 @@ if (CLI.NumResultRegs && CLI.CS) updateValueMap(CLI.CS->getInstruction(), CLI.ResultReg, CLI.NumResultRegs); + // Set labels for heapallocsite call. + if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) { +MDNode *MD = CLI.CS->getInstruction()->getMetadata("heapallocsite"); +MF->addCodeViewHeapAllocSite(CLI.Call, MD); + } + return true; } Index: llvm/lib/CodeGen/MachineFunction.cpp === --- llvm/lib/CodeGen/MachineFunction.cpp +++ llvm/lib/CodeGen/MachineFunction.cpp @@ -43,6 +43,7 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constant.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalValue.h" @@ -806,6 +807,16 @@ return FilterID; } +void MachineFunction::addCodeViewHeapAllocSite(MachineInstr *I, MDNode *MD) { + MCSymbol *BeginLabel = Ctx.createTempSymbol("heapallocsite", true); + MCSymbol *EndLabel = Ctx.createTempSymbol("heapallocsite", true); + I->setPreInstrSymbol(*this, BeginLabel); + I->setPostInstrSymbol(*this, End
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
rnk added inline comments. Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1966 + QualType PointeeTy = D.getTypePtr()->getPointeeType(); + llvm::DIType *DI = getOrCreateType(PointeeTy, getOrCreateFile(Loc)); + CI->setMetadata("heapallocsite", DI); akhuang wrote: > hans wrote: > > I don't really know this code, but does this also work for void pointers, > > i.e. the if statement in the old code was unnecessary? > I think `getOrCreateType` returns null if it gets a void type, so it doesn't > quite work for void pointers. In theory we shouldn't be getting void pointers > here since the type should be cast to something but that hasn't been > implemented yet. I think in practice void will be pretty common, so I think we want to leave this as it is, and come up with some other workaround in CodeViewDebug.cpp. We can leave this as is and have the CodeViewDebug.cpp code interpret an empty tuple as a void type. In hindsight, I think this "void is null" convention wasn't such a good idea, since we can't pass it through APIs like Instruction::setMetadata. Comment at: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp:1239 + if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) { +DIType *DI = cast(CLI.CS->getInstruction()-> + getMetadata("heapallocsite")); I think you could make `addCodeViewHeapAllocSite` take an `MDNode*` and then do this cast inside, and if the cast fails, see if it's the special empty tuple that means void, and put a null `DIType*` in the pointer. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
akhuang added inline comments. Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1966 + QualType PointeeTy = D.getTypePtr()->getPointeeType(); + llvm::DIType *DI = getOrCreateType(PointeeTy, getOrCreateFile(Loc)); + CI->setMetadata("heapallocsite", DI); hans wrote: > I don't really know this code, but does this also work for void pointers, > i.e. the if statement in the old code was unnecessary? I think `getOrCreateType` returns null if it gets a void type, so it doesn't quite work for void pointers. In theory we shouldn't be getting void pointers here since the type should be cast to something but that hasn't been implemented yet. Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:1078 + MCSymbol *EndLabel = std::get<1>(HeapAllocSite); + DIType *DITy = cast(std::get<2>(HeapAllocSite)); + hans wrote: > Is the cast necessary? Couldn't the tuple member be made a DIType* in the > first place? Changed the tuple member to be a DIType. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
akhuang updated this revision to Diff 195783. akhuang marked 4 inline comments as done. akhuang added a comment. Removed extraneous information from test; changed type to DIType Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 Files: clang/lib/CodeGen/CGDebugInfo.cpp clang/test/CodeGen/debug-info-codeview-heapallocsite.c llvm/include/llvm/CodeGen/MachineFunction.h llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h llvm/lib/CodeGen/MachineFunction.cpp llvm/lib/CodeGen/SelectionDAG/FastISel.cpp llvm/test/CodeGen/X86/label-heapallocsite.ll Index: llvm/test/CodeGen/X86/label-heapallocsite.ll === --- /dev/null +++ llvm/test/CodeGen/X86/label-heapallocsite.ll @@ -0,0 +1,68 @@ +; RUN: llc -O0 < %s | FileCheck %s +; FIXME: Add test for llc with optimizations once it is implemented. + +; Source to regenerate: +; $ clang --target=x86_64-windows-msvc -S heapallocsite.c -g -gcodeview -o t.ll \ +; -emit-llvm -O0 -Xclang -disable-llvm-passes -fms-extensions +; __declspec(allocator) char *myalloc(); +; void g(); +; void foo() { +; g(); +; myalloc() +; g(); +; } + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-windows-msvc" + +; Function Attrs: noinline nounwind optnone +define dso_local void @f() #0 !dbg !7 { +entry: + call void @g(), !dbg !11 + %call = call i8* @myalloc(), !dbg !12, !heapallocsite !13 + call void @g(), !dbg !14 + ret void, !dbg !15 +} + +; CHECK-LABEL: f: # @f +; CHECK: callq g +; CHECK: .Lheapallocsite0: +; CHECK: callq myalloc +; CHECK: .Lheapallocsite1: +; CHECK: retq + +; CHECK-LABEL: .short 4423# Record kind: S_GPROC32_ID +; CHECK: .short 4446# Record kind: S_HEAPALLOCSITE +; CHECK-NEXT: .secrel32 .Lheapallocsite0 +; CHECK-NEXT: .secidx .Lheapallocsite0 +; CHECK-NEXT: .short .Lheapallocsite1-.Lheapallocsite0 +; CHECK-NEXT: .long 112 +; CHECK-NEXT: .p2align 2 + +; CHECK-LABEL: .short 4431# Record kind: S_PROC_ID_END + +declare dso_local void @g() #1 + +declare dso_local i8* @myalloc() #1 + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 2} +!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)"} +!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!8 = !DIFile(filename: "heapallocsite.c", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!9 = !DISubroutineType(types: !10) +!10 = !{null} +!11 = !DILocation(line: 5, scope: !7) +!12 = !DILocation(line: 6, scope: !7) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !DILocation(line: 7, scope: !7) +!15 = !DILocation(line: 8, scope: !7) + Index: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp === --- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1234,6 +1234,13 @@ if (CLI.NumResultRegs && CLI.CS) updateValueMap(CLI.CS->getInstruction(), CLI.ResultReg, CLI.NumResultRegs); + // Set labels for heapallocsite call. + if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) { +DIType *DI = cast(CLI.CS->getInstruction()-> + getMetadata("heapallocsite")); +MF->addCodeViewHeapAllocSite(CLI.Call, DI); + } + return true; } Index: llvm/lib/CodeGen/MachineFunction.cpp === --- llvm/lib/CodeGen/MachineFunction.cpp +++ llvm/lib/CodeGen/MachineFunction.cpp @@ -806,6 +806,14 @@ return FilterID; } +void MachineFunction::addCodeViewHeapAllocSite(MachineInstr *I, DIType *DI) { + MCSymbol *BeginLabel = Ctx.createTempSymbol("heapallocsite", true); + MCSymbol *EndLabel = Ctx.createTempSymbol("heapallocsite", true); + I->setPreInstrSymbol(*this, BeginLabel); + I->setPostInstrSymbol(*this, EndLabel); + CodeViewHeapAllocSites.push_back({BeginLabel, EndLabel, DI}); +} + /// \} //===--===// Index: llvm/lib/Co
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
hans added a comment. I don't really know about the functionality here, just adding a few comments on the code itself. Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1966 + QualType PointeeTy = D.getTypePtr()->getPointeeType(); + llvm::DIType *DI = getOrCreateType(PointeeTy, getOrCreateFile(Loc)); + CI->setMetadata("heapallocsite", DI); I don't really know this code, but does this also work for void pointers, i.e. the if statement in the old code was unnecessary? Comment at: clang/test/CodeGen/debug-info-codeview-heapallocsite.c:19 +// FIXME: Currently not testing that call_alloc_void has metadata because the +// metadata is not set when the type is void. + Is it not set with your new code though? Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:1078 + MCSymbol *EndLabel = std::get<1>(HeapAllocSite); + DIType *DITy = cast(std::get<2>(HeapAllocSite)); + Is the cast necessary? Couldn't the tuple member be made a DIType* in the first place? Comment at: llvm/test/CodeGen/X86/label-heapallocsite.ll:1 +; RUN: llc -O0 < %s | FileCheck %s +; FIXME: Add test for llc with optimizations once it is implemented. Does llc have a "-fast-isel" flag or similar that could be used instead, to make it more clear that it's fast-isel that's significant for the test? Comment at: llvm/test/CodeGen/X86/label-heapallocsite.ll:16 +; ModuleID = 'heapallocsite.c' +source_filename = "heapallocsite.c" +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" I guess the ModuleID and source_filename are unnecessary, so I'd dro pthem. Comment at: llvm/test/CodeGen/X86/label-heapallocsite.ll:51 +attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } + Both sets of attributes seem unnecessary so could probably be removed. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
akhuang updated this revision to Diff 195480. akhuang added a comment. Fix test case Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 Files: clang/lib/CodeGen/CGDebugInfo.cpp clang/test/CodeGen/debug-info-codeview-heapallocsite.c llvm/include/llvm/CodeGen/MachineFunction.h llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h llvm/lib/CodeGen/MachineFunction.cpp llvm/lib/CodeGen/SelectionDAG/FastISel.cpp llvm/test/CodeGen/X86/label-heapallocsite.ll Index: llvm/test/CodeGen/X86/label-heapallocsite.ll === --- /dev/null +++ llvm/test/CodeGen/X86/label-heapallocsite.ll @@ -0,0 +1,73 @@ +; RUN: llc -O0 < %s | FileCheck %s +; FIXME: Add test for llc with optimizations once it is implemented. + +; Source to regenerate: +; $ clang --target=x86_64-windows-msvc -S heapallocsite.c -g -gcodeview -o t.ll \ +; -emit-llvm -O0 -Xclang -disable-llvm-passes -fms-extensions +; __declspec(allocator) char *myalloc(); +; void g(); +; void foo() { +; g(); +; myalloc() +; g(); +; } + +; ModuleID = 'heapallocsite.c' +source_filename = "heapallocsite.c" +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-windows-msvc" + +; Function Attrs: noinline nounwind optnone +define dso_local void @f() #0 !dbg !7 { +entry: + call void @g(), !dbg !11 + %call = call i8* @myalloc(), !dbg !12, !heapallocsite !13 + call void @g(), !dbg !14 + ret void, !dbg !15 +} + +; CHECK-LABEL: f: # @f +; CHECK: callq g +; CHECK: .Lheapallocsite0: +; CHECK: callq myalloc +; CHECK: .Lheapallocsite1: +; CHECK: retq + +; CHECK-LABEL: .short 4423# Record kind: S_GPROC32_ID +; CHECK: .short 4446# Record kind: S_HEAPALLOCSITE +; CHECK-NEXT: .secrel32 .Lheapallocsite0 +; CHECK-NEXT: .secidx .Lheapallocsite0 +; CHECK-NEXT: .short .Lheapallocsite1-.Lheapallocsite0 +; CHECK-NEXT: .long 112 +; CHECK-NEXT: .p2align 2 + +; CHECK-LABEL: .short 4431# Record kind: S_PROC_ID_END + +declare dso_local void @g() #1 + +declare dso_local i8* @myalloc() #1 + +attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 2} +!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)"} +!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!8 = !DIFile(filename: "heapallocsite.c", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!9 = !DISubroutineType(types: !10) +!10 = !{null} +!11 = !DILocation(line: 5, scope: !7) +!12 = !DILocation(line: 6, scope: !7) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !DILocation(line: 7, scope: !7) +!15 = !DILocation(line: 8, scope: !7) + Index: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp === --- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1234,6 +1234,11 @@ if (CLI.NumResultRegs && CLI.CS) updateValueMap(CLI.CS->getInstruction(), CLI.ResultReg, CLI.NumResultRegs); + // Set labels for heapallocsite call. + if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) +MF->addCodeViewHeapAllocSite(CLI.Call, CLI.CS->get
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
akhuang updated this revision to Diff 195478. akhuang added a comment. more typos Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 Files: clang/lib/CodeGen/CGDebugInfo.cpp clang/test/CodeGen/debug-info-codeview-heapallocsite.c llvm/include/llvm/CodeGen/MachineFunction.h llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h llvm/lib/CodeGen/MachineFunction.cpp llvm/lib/CodeGen/SelectionDAG/FastISel.cpp llvm/test/CodeGen/X86/label-heapallocsite.ll Index: llvm/test/CodeGen/X86/label-heapallocsite.ll === --- /dev/null +++ llvm/test/CodeGen/X86/label-heapallocsite.ll @@ -0,0 +1,73 @@ +; RUN: llc -O0 < %s | FileCheck %s +; FIXME: Add test for llc with optimizations once it is implemented. + +; Source to regenerate: +; $ clang --target=x86_64-windows-msvc -S heapallocsite.c -g -gcodeview -o t.ll \ +; -emit-llvm -O0 -Xclang -disable-llvm-passes -fms-extensions +; __declspec(allocator) char *myalloc(); +; void g(); +; void foo() { +; g(); +; myalloc() +; g(); +; } + +; ModuleID = 'heapallocsite.c' +source_filename = "heapallocsite.c" +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-windows-msvc" + +; Function Attrs: noinline nounwind optnone +define dso_local void @f() #0 !dbg !7 { +entry: + call void @g(), !dbg !11 + %call = call i8* @myalloc(), !dbg !12, !heapallocsite !13 + call void @g(), !dbg !14 + ret void, !dbg !15 +} + +; CHECK-LABEL: f: # @f +; CHECK: callq g +; CHECK: .Lheapallocsite0: +; CHECK: callq myalloc +; CHECK: .Lheapallocsite1: +; CHECK: retq + +; CHECK-LABEL: .short 4423# Record kind: S_GPROC32_ID +; CHECK: .short 4446# Record kind: S_HEAPALLOCSITE +; CHECK-NEXT: .secrel32 .Lheapallocsite0 +; CHECK-NEXT: .secidx .Lheapallocsite0 +; CHECK-NEXT: .short .Lheapallocsite1-.Lheapallocsite0 +; CHECK-NEXT: .long 1539 +; CHECK-NEXT: .p2align 2 + +; CHECK-LABEL: .short 4431# Record kind: S_PROC_ID_END + +declare dso_local void @g() #1 + +declare dso_local i8* @myalloc() #1 + +attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 2} +!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)"} +!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!8 = !DIFile(filename: "heapallocsite.c", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!9 = !DISubroutineType(types: !10) +!10 = !{null} +!11 = !DILocation(line: 5, scope: !7) +!12 = !DILocation(line: 6, scope: !7) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !DILocation(line: 7, scope: !7) +!15 = !DILocation(line: 8, scope: !7) + Index: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp === --- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1234,6 +1234,11 @@ if (CLI.NumResultRegs && CLI.CS) updateValueMap(CLI.CS->getInstruction(), CLI.ResultReg, CLI.NumResultRegs); + // Set labels for heapallocsite call. + if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) +MF->addCodeViewHeapAllocSite(CLI.Call, CLI.CS->getIn
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
akhuang updated this revision to Diff 195475. akhuang added a comment. remove comment Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60800/new/ https://reviews.llvm.org/D60800 Files: clang/lib/CodeGen/CGDebugInfo.cpp clang/test/CodeGen/debug-info-codeview-heapallocsite.c llvm/include/llvm/CodeGen/MachineFunction.h llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h llvm/lib/CodeGen/MachineFunction.cpp llvm/lib/CodeGen/SelectionDAG/FastISel.cpp llvm/test/CodeGen/X86/label-heapallocsite.ll Index: llvm/test/CodeGen/X86/label-heapallocsite.ll === --- /dev/null +++ llvm/test/CodeGen/X86/label-heapallocsite.ll @@ -0,0 +1,73 @@ +; RUN: llc -O0 < %s | FileCheck %s +; FIXME: Add test for llc with optimizations once it is implemented. + +; Source to regenerate: +; $ clang --target=x86_64-windows-msvc -S heapallocsite.c -g -gcodeview -o t.ll \ +; -emit-llvm -O0 -Xclang -disable-llvm-passes -fms-extensions +; __declspec(allocator) char *myalloc(); +; void g(); +; void foo() { +; g(); +; myalloc() +; g(); +; } + +; ModuleID = 'heapallocsite.c' +source_filename = "heapallocsite.c" +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-windows-msvc" + +; Function Attrs: noinline nounwind optnone +define dso_local void @f() #0 !dbg !7 { +entry: + call void @g(), !dbg !11 + %call = call i8* @myalloc(), !dbg !12, !heapallocsite !13 + call void @g(), !dbg !14 + ret void, !dbg !15 +} + +; CHECK-LABEL: f: # @f +; CHECK: callq g +; CHECK: .Lheapallocsite0: +; CHECK: callq myalloc +; CHECK: .Lheapallocsite1: +; CHECK: retq + +; CHECK-LABEL: .short 4423# Record kind: S_GPROC32_ID +; CHECK: .short 4446# Record kind: S_HEAPALLOCSITE +; CHECK-NEXT: .secrel32 .Lheapallocsite0 +; CHECK-NEXT: .secidx .Lheapallocsite0 +; CHECK-NEXT: .short .Lheapallocsite1-.Lheapallocsite0 +; CHECK-NEXT: .long 1539 +; CHECK-NEXT: .p2align 2 + +; CHECK-LABEL: .short 4431# Record kind: S_PROC_ID_END + +declare dso_local void @g() #1 + +declare dso_local i8* @myalloc() #1 + +attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 2} +!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)"} +!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!8 = !DIFile(filename: "heapallocsite.c", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!9 = !DISubroutineType(types: !10) +!10 = !{null} +!11 = !DILocation(line: 5, scope: !7) +!12 = !DILocation(line: 6, scope: !7) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !DILocation(line: 7, scope: !7) +!15 = !DILocation(line: 8, scope: !7) + Index: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp === --- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1234,6 +1234,11 @@ if (CLI.NumResultRegs && CLI.CS) updateValueMap(CLI.CS->getInstruction(), CLI.ResultReg, CLI.NumResultRegs); + // Set labels for heapallocsite call. + if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) +MF->addCodeViewHeapAllocSite(CLI.Call, CLI.CS->g
[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info
akhuang created this revision. akhuang added reviewers: hans, rnk. Herald added subscribers: llvm-commits, cfe-commits, hiraditya, aprantl. Herald added projects: clang, LLVM. This emits labels around heapallocsite calls and S_HEAPALLOCSITE debug info in codeview. Currently only changes FastISel, so emitting labels still needs to be implemented in SelectionDAG. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D60800 Files: clang/lib/CodeGen/CGDebugInfo.cpp clang/test/CodeGen/debug-info-codeview-heapallocsite.c llvm/include/llvm/CodeGen/MachineFunction.h llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h llvm/lib/CodeGen/MachineFunction.cpp llvm/lib/CodeGen/SelectionDAG/FastISel.cpp llvm/test/CodeGen/X86/label-heapallocsite.ll Index: llvm/test/CodeGen/X86/label-heapallocsite.ll === --- /dev/null +++ llvm/test/CodeGen/X86/label-heapallocsite.ll @@ -0,0 +1,73 @@ +; RUN: llc -O0 < %s | FileCheck %s +; FIXME: Add test for llc with optimizations once it is implemented. + +; Source to regenerate: +; $ clang --target=x86_64-windows-msvc -S heapallocsite.c -g -gcodeview -o t.ll \ +; -emit-llvm -O0 -Xclang -disable-llvm-passes -fms-extensions +; __declspec(allocator) char *myalloc(); +; void g(); +; void foo() { +; g(); +; myalloc() +; g(); +; } + +; ModuleID = 'heapallocsite.c' +source_filename = "heapallocsite.c" +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-windows-msvc" + +; Function Attrs: noinline nounwind optnone +define dso_local void @f() #0 !dbg !7 { +entry: + call void @g(), !dbg !11 + %call = call i8* @myalloc(), !dbg !12, !heapallocsite !13 + call void @g(), !dbg !14 + ret void, !dbg !15 +} + +; CHECK-LABEL: f: # @f +; CHECK: callq g +; CHECK: .Lheapallocsite0: +; CHECK: callq myalloc +; CHECK: .Lheapallocsite1: +; CHECK: retq + +; CHECK-LABEL: .short 4423# Record kind: S_GPROC32_ID +; CHECK: .short 4446# Record kind: S_HEAPALLOCSITE +; CHECK-NEXT: .secrel32 .Lheapallocsite0 +; CHECK-NEXT: .secidx .Lheapallocsite0 +; CHECK-NEXT: .short .Lheapallocsite1-.Lheapallocsite0 +; CHECK-NEXT: .long 1539 +; CHECK-NEXT: .p2align 2 + +; CHECK-LABEL: .short 4431# Record kind: S_PROC_ID_END + +declare dso_local void @g() #1 + +declare dso_local i8* @myalloc() #1 + +attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 2} +!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)"} +!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) +!8 = !DIFile(filename: "heapallocsite.c", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9") +!9 = !DISubroutineType(types: !10) +!10 = !{null} +!11 = !DILocation(line: 5, scope: !7) +!12 = !DILocation(line: 6, scope: !7) +!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!14 = !DILocation(line: 7, scope: !7) +!15 = !DILocation(line: 8, scope: !7) + Index: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp === --- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1234,6 +1234,19 @@ if (CLI.NumResultRegs && CLI.CS) updateValueMap(CLI.CS->getInstruc