[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-21 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In D4#2706515 , @Holman wrote:

> Can someone help me get this checked in?

Sure, I went ahead and pushed it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4/new/

https://reviews.llvm.org/D4

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-21 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG77357208c46a: [CodeView] Add CodeView support for PGO debug 
information (authored by Holman, committed by rnk).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4/new/

https://reviews.llvm.org/D4

Files:
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/pgo.ll

Index: llvm/test/DebugInfo/COFF/pgo.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/pgo.ll
@@ -0,0 +1,165 @@
+; RUN: llc < %s -filetype=obj | llvm-readobj --codeview - | FileCheck %s
+
+; CHECK: Compile3Sym {
+; CHECK:   Flags [ (0x4)
+; CHECK: PGO (0x4)
+
+; CHECK: DisplayName: foo
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK:   ProfileGuidedOptimization (0x4)
+; CHECK:   ValidProfileCounts (0x8)
+
+; CHECK: DisplayName: foo2
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK:   ProfileGuidedOptimization (0x4)
+; CHECK:   ValidProfileCounts (0x8)
+
+; CHECK: DisplayName: bar
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK:   ProfileGuidedOptimization (0x4)
+; CHECK:   ValidProfileCounts (0x8)
+
+; CHECK: DisplayName: main
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK-NOT:   ProfileGuidedOptimization (0x4)
+; CHECK-NOT:   ValidProfileCounts (0x8)
+
+source_filename = "pgo.cpp"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.28.29912"
+
+define dso_local i32 @"?foo@@YAHH@Z"(i32 %b) local_unnamed_addr #1 !dbg !43 !prof !49 {
+entry:
+  call void @llvm.dbg.value(metadata i32 %b, metadata !48, metadata !DIExpression()), !dbg !50
+  %mul = mul nsw i32 %b, 10, !dbg !51
+  ret i32 %mul, !dbg !51
+}
+
+define dso_local i32 @"?foo2@@YAHH@Z"(i32 %a) local_unnamed_addr #1 !dbg !52 !prof !55 {
+entry:
+  call void @llvm.dbg.value(metadata i32 %a, metadata !54, metadata !DIExpression()), !dbg !56
+  %mul = mul nsw i32 %a, 5, !dbg !57
+  ret i32 %mul, !dbg !57
+}
+
+define dso_local i32 @"?bar@@YAHH@Z"(i32 %num) local_unnamed_addr #1 !dbg !58 !prof !55 {
+entry:
+  call void @llvm.dbg.value(metadata i32 undef, metadata !60, metadata !DIExpression()), !dbg !61
+  %call = tail call i32 @"?foo@@YAHH@Z"(i32 1) #1, !dbg !62
+  %call1 = tail call i32 @"?foo2@@YAHH@Z"(i32 2) #1, !dbg !62
+  %mul = mul nsw i32 %call1, %call, !dbg !62
+  %call2 = tail call i32 @"?foo2@@YAHH@Z"(i32 3) #1, !dbg !62
+  %mul3 = mul nsw i32 %mul, %call2, !dbg !62
+  ret i32 %mul3, !dbg !62
+}
+
+define dso_local i32 @main(i32 %argc, i8** nocapture readnone %argv) local_unnamed_addr #1 !dbg !63 !annotation !72 {
+entry:
+  call void @llvm.dbg.value(metadata i8** %argv, metadata !70, metadata !DIExpression()), !dbg !73
+  call void @llvm.dbg.value(metadata i32 %argc, metadata !71, metadata !DIExpression()), !dbg !73
+  %cmp = icmp eq i32 %argc, 2, !dbg !74
+  br i1 %cmp, label %return, label %if.end, !dbg !74
+
+if.end:   ; preds = %entry
+  %cmp1 = icmp slt i32 %argc, 5, !dbg !75
+  br i1 %cmp1, label %if.then2, label %if.else, !dbg !75
+
+if.then2: ; preds = %if.end
+  %call = tail call i32 @"?bar@@YAHH@Z"(i32 undef) #1, !dbg !76
+  br label %return, !dbg !76
+
+if.else:  ; preds = %if.end
+  %call3 = tail call i32 @"?foo@@YAHH@Z"(i32 %argc) #1, !dbg !79
+  br label %return, !dbg !79
+
+return:   ; preds = %entry, %if.else, %if.then2
+  %retval.0 = phi i32 [ %call, %if.then2 ], [ %call3, %if.else ], [ 0, %entry ], !dbg !73
+  ret i32 %retval.0, !dbg !81
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata) #3
+
+attributes #1 = { optsize }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!5, !6, !7, !8, !9, !38}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "pgo.cpp", directory: "")
+!2 = !{}
+!5 = !{i32 2, !"CodeView", i32 1}
+!6 = !{i32 2, !"Debug Info Version", i32 3}
+!7 = !{i32 1, !"wchar_size", i32 2}
+!8 = !{i32 7, !"PIC Level", i32 2}
+!9 = !{i32 1, !"ProfileSummary", !10}
+!10 = !{!11, !12, !13, !14, !15, !16, !17, !18, !19, !20}
+!11 = !{!"ProfileFormat", !"InstrProf"}
+!12 = !{!"TotalCount", i64 2}
+!13 = !{!"MaxCount", i64 1}
+!14 = !{!"MaxInternalCount", i64 1}
+!15 = !{!"MaxFunctionCount", i64 1}
+!16 = !{!"NumCounts", i64 5}
+!17 = !{!"NumFunctions", i64 4}
+!18 = !{!"IsPartialProfile", i64 0}
+!19 = !{!"PartialProfileRatio", double 0.00e+00}
+!20 = !{!"DetailedSummary", !21}
+!21 = !{!22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37}
+!22 = !{i32 1, i64 

[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-21 Thread Michael Holman via Phabricator via cfe-commits
Holman added a comment.

Can someone help me get this checked in?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4/new/

https://reviews.llvm.org/D4

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-09 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4/new/

https://reviews.llvm.org/D4

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-09 Thread Michael Holman via Phabricator via cfe-commits
Holman updated this revision to Diff 336497.
Holman added a comment.

Fix clang-format issue.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4/new/

https://reviews.llvm.org/D4

Files:
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/pgo.ll

Index: llvm/test/DebugInfo/COFF/pgo.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/pgo.ll
@@ -0,0 +1,165 @@
+; RUN: llc < %s -filetype=obj | llvm-readobj --codeview - | FileCheck %s
+
+; CHECK: Compile3Sym {
+; CHECK:   Flags [ (0x4)
+; CHECK: PGO (0x4)
+
+; CHECK: DisplayName: foo
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK:   ProfileGuidedOptimization (0x4)
+; CHECK:   ValidProfileCounts (0x8)
+
+; CHECK: DisplayName: foo2
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK:   ProfileGuidedOptimization (0x4)
+; CHECK:   ValidProfileCounts (0x8)
+
+; CHECK: DisplayName: bar
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK:   ProfileGuidedOptimization (0x4)
+; CHECK:   ValidProfileCounts (0x8)
+
+; CHECK: DisplayName: main
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK-NOT:   ProfileGuidedOptimization (0x4)
+; CHECK-NOT:   ValidProfileCounts (0x8)
+
+source_filename = "pgo.cpp"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.28.29912"
+
+define dso_local i32 @"?foo@@YAHH@Z"(i32 %b) local_unnamed_addr #1 !dbg !43 !prof !49 {
+entry:
+  call void @llvm.dbg.value(metadata i32 %b, metadata !48, metadata !DIExpression()), !dbg !50
+  %mul = mul nsw i32 %b, 10, !dbg !51
+  ret i32 %mul, !dbg !51
+}
+
+define dso_local i32 @"?foo2@@YAHH@Z"(i32 %a) local_unnamed_addr #1 !dbg !52 !prof !55 {
+entry:
+  call void @llvm.dbg.value(metadata i32 %a, metadata !54, metadata !DIExpression()), !dbg !56
+  %mul = mul nsw i32 %a, 5, !dbg !57
+  ret i32 %mul, !dbg !57
+}
+
+define dso_local i32 @"?bar@@YAHH@Z"(i32 %num) local_unnamed_addr #1 !dbg !58 !prof !55 {
+entry:
+  call void @llvm.dbg.value(metadata i32 undef, metadata !60, metadata !DIExpression()), !dbg !61
+  %call = tail call i32 @"?foo@@YAHH@Z"(i32 1) #1, !dbg !62
+  %call1 = tail call i32 @"?foo2@@YAHH@Z"(i32 2) #1, !dbg !62
+  %mul = mul nsw i32 %call1, %call, !dbg !62
+  %call2 = tail call i32 @"?foo2@@YAHH@Z"(i32 3) #1, !dbg !62
+  %mul3 = mul nsw i32 %mul, %call2, !dbg !62
+  ret i32 %mul3, !dbg !62
+}
+
+define dso_local i32 @main(i32 %argc, i8** nocapture readnone %argv) local_unnamed_addr #1 !dbg !63 !annotation !72 {
+entry:
+  call void @llvm.dbg.value(metadata i8** %argv, metadata !70, metadata !DIExpression()), !dbg !73
+  call void @llvm.dbg.value(metadata i32 %argc, metadata !71, metadata !DIExpression()), !dbg !73
+  %cmp = icmp eq i32 %argc, 2, !dbg !74
+  br i1 %cmp, label %return, label %if.end, !dbg !74
+
+if.end:   ; preds = %entry
+  %cmp1 = icmp slt i32 %argc, 5, !dbg !75
+  br i1 %cmp1, label %if.then2, label %if.else, !dbg !75
+
+if.then2: ; preds = %if.end
+  %call = tail call i32 @"?bar@@YAHH@Z"(i32 undef) #1, !dbg !76
+  br label %return, !dbg !76
+
+if.else:  ; preds = %if.end
+  %call3 = tail call i32 @"?foo@@YAHH@Z"(i32 %argc) #1, !dbg !79
+  br label %return, !dbg !79
+
+return:   ; preds = %entry, %if.else, %if.then2
+  %retval.0 = phi i32 [ %call, %if.then2 ], [ %call3, %if.else ], [ 0, %entry ], !dbg !73
+  ret i32 %retval.0, !dbg !81
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata) #3
+
+attributes #1 = { optsize }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!5, !6, !7, !8, !9, !38}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "pgo.cpp", directory: "")
+!2 = !{}
+!5 = !{i32 2, !"CodeView", i32 1}
+!6 = !{i32 2, !"Debug Info Version", i32 3}
+!7 = !{i32 1, !"wchar_size", i32 2}
+!8 = !{i32 7, !"PIC Level", i32 2}
+!9 = !{i32 1, !"ProfileSummary", !10}
+!10 = !{!11, !12, !13, !14, !15, !16, !17, !18, !19, !20}
+!11 = !{!"ProfileFormat", !"InstrProf"}
+!12 = !{!"TotalCount", i64 2}
+!13 = !{!"MaxCount", i64 1}
+!14 = !{!"MaxInternalCount", i64 1}
+!15 = !{!"MaxFunctionCount", i64 1}
+!16 = !{!"NumCounts", i64 5}
+!17 = !{!"NumFunctions", i64 4}
+!18 = !{!"IsPartialProfile", i64 0}
+!19 = !{!"PartialProfileRatio", double 0.00e+00}
+!20 = !{!"DetailedSummary", !21}
+!21 = !{!22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37}
+!22 = !{i32 1, i64 0, i32 0}
+!23 = !{i32 10, i64 0, i32 0}
+!24 = !{i32 20, i64 0, i32 0}
+!25 = !{i32 30, i64 0, i32 0}
+!26 = !{i32 40, i64 0, i32 0}
+!27 = !{i32 

[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-08 Thread Michael Holman via Phabricator via cfe-commits
Holman updated this revision to Diff 336274.
Holman set the repository for this revision to rG LLVM Github Monorepo.
Holman added a comment.

Add a test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4/new/

https://reviews.llvm.org/D4

Files:
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/pgo.ll

Index: llvm/test/DebugInfo/COFF/pgo.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/pgo.ll
@@ -0,0 +1,165 @@
+; RUN: llc < %s -filetype=obj | llvm-readobj --codeview - | FileCheck %s
+
+; CHECK: Compile3Sym {
+; CHECK:   Flags [ (0x4)
+; CHECK: PGO (0x4)
+
+; CHECK: DisplayName: foo
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK:   ProfileGuidedOptimization (0x4)
+; CHECK:   ValidProfileCounts (0x8)
+
+; CHECK: DisplayName: foo2
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK:   ProfileGuidedOptimization (0x4)
+; CHECK:   ValidProfileCounts (0x8)
+
+; CHECK: DisplayName: bar
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK:   ProfileGuidedOptimization (0x4)
+; CHECK:   ValidProfileCounts (0x8)
+
+; CHECK: DisplayName: main
+; CHECK: Kind: S_FRAMEPROC (0x1012)
+; CHECK-NOT:   ProfileGuidedOptimization (0x4)
+; CHECK-NOT:   ValidProfileCounts (0x8)
+
+source_filename = "pgo.cpp"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.28.29912"
+
+define dso_local i32 @"?foo@@YAHH@Z"(i32 %b) local_unnamed_addr #1 !dbg !43 !prof !49 {
+entry:
+  call void @llvm.dbg.value(metadata i32 %b, metadata !48, metadata !DIExpression()), !dbg !50
+  %mul = mul nsw i32 %b, 10, !dbg !51
+  ret i32 %mul, !dbg !51
+}
+
+define dso_local i32 @"?foo2@@YAHH@Z"(i32 %a) local_unnamed_addr #1 !dbg !52 !prof !55 {
+entry:
+  call void @llvm.dbg.value(metadata i32 %a, metadata !54, metadata !DIExpression()), !dbg !56
+  %mul = mul nsw i32 %a, 5, !dbg !57
+  ret i32 %mul, !dbg !57
+}
+
+define dso_local i32 @"?bar@@YAHH@Z"(i32 %num) local_unnamed_addr #1 !dbg !58 !prof !55 {
+entry:
+  call void @llvm.dbg.value(metadata i32 undef, metadata !60, metadata !DIExpression()), !dbg !61
+  %call = tail call i32 @"?foo@@YAHH@Z"(i32 1) #1, !dbg !62
+  %call1 = tail call i32 @"?foo2@@YAHH@Z"(i32 2) #1, !dbg !62
+  %mul = mul nsw i32 %call1, %call, !dbg !62
+  %call2 = tail call i32 @"?foo2@@YAHH@Z"(i32 3) #1, !dbg !62
+  %mul3 = mul nsw i32 %mul, %call2, !dbg !62
+  ret i32 %mul3, !dbg !62
+}
+
+define dso_local i32 @main(i32 %argc, i8** nocapture readnone %argv) local_unnamed_addr #1 !dbg !63 !annotation !72 {
+entry:
+  call void @llvm.dbg.value(metadata i8** %argv, metadata !70, metadata !DIExpression()), !dbg !73
+  call void @llvm.dbg.value(metadata i32 %argc, metadata !71, metadata !DIExpression()), !dbg !73
+  %cmp = icmp eq i32 %argc, 2, !dbg !74
+  br i1 %cmp, label %return, label %if.end, !dbg !74
+
+if.end:   ; preds = %entry
+  %cmp1 = icmp slt i32 %argc, 5, !dbg !75
+  br i1 %cmp1, label %if.then2, label %if.else, !dbg !75
+
+if.then2: ; preds = %if.end
+  %call = tail call i32 @"?bar@@YAHH@Z"(i32 undef) #1, !dbg !76
+  br label %return, !dbg !76
+
+if.else:  ; preds = %if.end
+  %call3 = tail call i32 @"?foo@@YAHH@Z"(i32 %argc) #1, !dbg !79
+  br label %return, !dbg !79
+
+return:   ; preds = %entry, %if.else, %if.then2
+  %retval.0 = phi i32 [ %call, %if.then2 ], [ %call3, %if.else ], [ 0, %entry ], !dbg !73
+  ret i32 %retval.0, !dbg !81
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata) #3
+
+attributes #1 = { optsize }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!5, !6, !7, !8, !9, !38}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "pgo.cpp", directory: "")
+!2 = !{}
+!5 = !{i32 2, !"CodeView", i32 1}
+!6 = !{i32 2, !"Debug Info Version", i32 3}
+!7 = !{i32 1, !"wchar_size", i32 2}
+!8 = !{i32 7, !"PIC Level", i32 2}
+!9 = !{i32 1, !"ProfileSummary", !10}
+!10 = !{!11, !12, !13, !14, !15, !16, !17, !18, !19, !20}
+!11 = !{!"ProfileFormat", !"InstrProf"}
+!12 = !{!"TotalCount", i64 2}
+!13 = !{!"MaxCount", i64 1}
+!14 = !{!"MaxInternalCount", i64 1}
+!15 = !{!"MaxFunctionCount", i64 1}
+!16 = !{!"NumCounts", i64 5}
+!17 = !{!"NumFunctions", i64 4}
+!18 = !{!"IsPartialProfile", i64 0}
+!19 = !{!"PartialProfileRatio", double 0.00e+00}
+!20 = !{!"DetailedSummary", !21}
+!21 = !{!22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37}
+!22 = !{i32 1, i64 0, i32 0}
+!23 = !{i32 10, i64 0, i32 0}
+!24 = !{i32 20, i64 0, i32 0}
+!25 = !{i32 30, i64 0, 

[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Seems reasonable, but we still need a small IR test.




Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:807
   // TODO:  Figure out which other flags need to be set.
+  if (MMI->getModule()->getProfileSummary(/* IsCS */ false) != nullptr) {
+Flags |= static_cast(CompileSym3Flags::PGO);

nit, the more common style to name parameters looks like 
`getProfileSummary(/*IsCS=*/false)`. Sort of more Python-y.



Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:1434
 FPO |= FrameProcedureOptions::OptimizedForSpeed;
+  if (GV.getEntryCount().hasValue()) {
+FPO |= FrameProcedureOptions::ValidProfileCounts;

I think the preferred spelling is `GV.hasProfileData()`, I think that's 
functionally equivalent.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4/new/

https://reviews.llvm.org/D4

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-08 Thread Michael Holman via Phabricator via cfe-commits
Holman updated this revision to Diff 336223.
Holman added a comment.

Get PGO info from Module instead of adding new field to debug info.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4/new/

https://reviews.llvm.org/D4

Files:
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp


Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -804,6 +804,9 @@
   // The low byte of the flags indicates the source language.
   Flags = MapDWLangToCVLang(CU->getSourceLanguage());
   // TODO:  Figure out which other flags need to be set.
+  if (MMI->getModule()->getProfileSummary(/* IsCS */ false) != nullptr) {
+Flags |= static_cast(CompileSym3Flags::PGO);
+  }
 
   OS.AddComment("Flags and language");
   OS.emitInt32(Flags);
@@ -1428,6 +1431,10 @@
   if (Asm->TM.getOptLevel() != CodeGenOpt::None &&
   !GV.hasOptSize() && !GV.hasOptNone())
 FPO |= FrameProcedureOptions::OptimizedForSpeed;
+  if (GV.getEntryCount().hasValue()) {
+FPO |= FrameProcedureOptions::ValidProfileCounts;
+FPO |= FrameProcedureOptions::ProfileGuidedOptimization;
+  }
   // FIXME: Set GuardCfg when it is implemented.
   CurFn->FrameProcOpts = FPO;
 


Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -804,6 +804,9 @@
   // The low byte of the flags indicates the source language.
   Flags = MapDWLangToCVLang(CU->getSourceLanguage());
   // TODO:  Figure out which other flags need to be set.
+  if (MMI->getModule()->getProfileSummary(/* IsCS */ false) != nullptr) {
+Flags |= static_cast(CompileSym3Flags::PGO);
+  }
 
   OS.AddComment("Flags and language");
   OS.emitInt32(Flags);
@@ -1428,6 +1431,10 @@
   if (Asm->TM.getOptLevel() != CodeGenOpt::None &&
   !GV.hasOptSize() && !GV.hasOptNone())
 FPO |= FrameProcedureOptions::OptimizedForSpeed;
+  if (GV.getEntryCount().hasValue()) {
+FPO |= FrameProcedureOptions::ValidProfileCounts;
+FPO |= FrameProcedureOptions::ProfileGuidedOptimization;
+  }
   // FIXME: Set GuardCfg when it is implemented.
   CurFn->FrameProcOpts = FPO;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-08 Thread Michael Holman via Phabricator via cfe-commits
Holman added a comment.

In D4#2677566 , @rnk wrote:

> IMO it's best to avoid adding fields to DICompileUnit if at all possible. 
> It's the "god object" / "katamari damacy" of module debug info. Is there 
> something about the IR module that indicates if PGO data is present or not? 
> We could check that instead. I looked, but I wasn't able to find anything 
> quickly.

Got it. It looks like MMI->getModule()->getProfileSummary() should have the 
info I need. I'll update to use that instead.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4/new/

https://reviews.llvm.org/D4

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

IMO it's best to avoid adding fields to DICompileUnit if at all possible. It's 
the "god object" / "katamari damacy" of module debug info. Is there something 
about the IR module that indicates if PGO data is present or not? We could 
check that instead. I looked, but I wasn't able to find anything quickly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4/new/

https://reviews.llvm.org/D4

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-07 Thread Amy Huang via Phabricator via cfe-commits
akhuang added a comment.

think this looks good overall; maybe it should also have an IR to codeview test?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D4/new/

https://reviews.llvm.org/D4

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99994: [CodeView] Add CodeView support for PGO debug information

2021-04-06 Thread Michael Holman via Phabricator via cfe-commits
Holman created this revision.
Herald added subscribers: dexonsmith, wenlei, hiraditya.
Holman requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This change adds debug information about whether PGO is being used or not.

Microsoft performance tooling (e.g. xperf, WPA) uses this information to show 
whether functions are optimized with PGO or not, as well as whether PGO 
information is invalid.

This information is useful for validating whether training scenarios are 
providing good coverage of real world scenarios, showing if profile data is out 
of date, etc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D4

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/DebugInfo.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/unittests/IR/MetadataTest.cpp

Index: llvm/unittests/IR/MetadataTest.cpp
===
--- llvm/unittests/IR/MetadataTest.cpp
+++ llvm/unittests/IR/MetadataTest.cpp
@@ -97,7 +97,7 @@
 Context, 1, getFile(), "clang", false, "-g", 2, "",
 DICompileUnit::FullDebug, getTuple(), getTuple(), getTuple(),
 getTuple(), getTuple(), 0, true, false,
-DICompileUnit::DebugNameTableKind::Default, false, "/", "");
+DICompileUnit::DebugNameTableKind::Default, false, "/", "", false);
   }
   DIType *getBasicType(StringRef Name) {
 return DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name);
@@ -2110,11 +2110,13 @@
   MDTuple *Macros = getTuple();
   StringRef SysRoot = "/";
   StringRef SDK = "MacOSX.sdk";
+  bool HasPGO = false;
   auto *N = DICompileUnit::getDistinct(
   Context, SourceLanguage, File, Producer, IsOptimized, Flags,
   RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
   RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId, true,
-  false, DICompileUnit::DebugNameTableKind::Default, false, SysRoot, SDK);
+  false, DICompileUnit::DebugNameTableKind::Default, false, SysRoot, SDK,
+  HasPGO);
 
   EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag());
   EXPECT_EQ(SourceLanguage, N->getSourceLanguage());
@@ -2133,6 +2135,7 @@
   EXPECT_EQ(DWOId, N->getDWOId());
   EXPECT_EQ(SysRoot, N->getSysRoot());
   EXPECT_EQ(SDK, N->getSDK());
+  EXPECT_EQ(HasPGO, N->hasPGO());
 
   TempDICompileUnit Temp = N->clone();
   EXPECT_EQ(dwarf::DW_TAG_compile_unit, Temp->getTag());
@@ -2151,6 +2154,7 @@
   EXPECT_EQ(Macros, Temp->getMacros().get());
   EXPECT_EQ(SysRoot, Temp->getSysRoot());
   EXPECT_EQ(SDK, Temp->getSDK());
+  EXPECT_EQ(HasPGO, Temp->hasPGO());
 
   auto *TempAddress = Temp.get();
   auto *Clone = MDNode::replaceWithPermanent(std::move(Temp));
@@ -2173,11 +2177,12 @@
   uint64_t DWOId = 0xc0ffee;
   StringRef SysRoot = "/";
   StringRef SDK = "MacOSX.sdk";
+  bool HasPGO = false;
   auto *N = DICompileUnit::getDistinct(
   Context, SourceLanguage, File, Producer, IsOptimized, Flags,
   RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
   RetainedTypes, nullptr, ImportedEntities, nullptr, DWOId, true, false,
-  DICompileUnit::DebugNameTableKind::Default, false, SysRoot, SDK);
+  DICompileUnit::DebugNameTableKind::Default, false, SysRoot, SDK, HasPGO);
 
   auto *GlobalVariables = MDTuple::getDistinct(Context, None);
   EXPECT_EQ(nullptr, N->getGlobalVariables().get());
Index: llvm/lib/IR/DebugInfoMetadata.cpp
===
--- llvm/lib/IR/DebugInfoMetadata.cpp
+++ llvm/lib/IR/DebugInfoMetadata.cpp
@@ -736,7 +736,7 @@
 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
 unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
-MDString *SDK, StorageType Storage, bool ShouldCreate) {
+MDString *SDK, bool HasPGO, StorageType Storage, bool ShouldCreate) {
   assert(Storage != Uniqued && "Cannot unique DICompileUnit");
   assert(isCanonical(Producer) && "Expected canonical MDString");
   assert(isCanonical(Flags) && "Expected canonical MDString");
@@ -757,7 +757,7 @@
Context, Storage, SourceLanguage, IsOptimized,
RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
-   Ops),
+   HasPGO, Ops),
Storage);
 }
 
Index: llvm/lib/IR/DebugInfo.cpp
===
--- llvm/lib/IR/DebugInfo.cpp
+++ llvm/lib/IR/DebugInfo.cpp
@@ -491,7 +491,8 @@