[PATCH] D80197: [DebugInfo] Upgrade DISubrange to support Fortran dynamic arrays

2020-05-28 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok marked an inline comment as done.
alok added a comment.

In D80197#2059591 , @thakis wrote:

> This breaks check-llvm on Windows: http://45.33.8.238/win/16214/step_11.txt
>
> Please take a look and revert if it takes a while to investigate.


Fixed in 7716681cfd0ea2dadbddae6f1983e130c2fa4247 
 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80197



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


[PATCH] D80197: [DebugInfo] Upgrade DISubrange to support Fortran dynamic arrays

2020-05-28 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok marked 2 inline comments as done.
alok added inline comments.



Comment at: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:1522
 
 static uint64_t rotateSign(int64_t I) {
   uint64_t U = I;

melver wrote:
> rotateSign() is no longer used in this file. If there are no plans to use it 
> again, please remove it.
> Thanks!
Thanks. It is fixed in a0d847c6cdcbe167213d91313577c57073d5c013 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80197



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


[PATCH] D111521: [DebugInfo] Mark OpenMP generated functions as artificial

2022-08-02 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 449239.
alok added a comment.

Re-based and updated to incorporate comments from @dblaikie


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

https://reviews.llvm.org/D111521

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/OpenMP/outlined_artificial.c


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined..1"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4097,8 +4097,12 @@
   if (Name.startswith("\01"))
 Name = Name.substr(1);
 
+  assert((!D || !isa(D) ||
+  GD.getDynamicInitKind() != DynamicInitKind::NoStub) &&
+ "Unexpected DynamicInitKind !");
+
   if (!HasDecl || D->isImplicit() || D->hasAttr() ||
-  (isa(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub)) 
{
+  isa(D) || isa(D)) {
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined..1"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
Index: clang/lib/CodeGen/CGDebugInfo.cpp
=

[PATCH] D111521: [DebugInfo] Mark OpenMP generated functions as artificial

2022-08-02 Thread Alok Kumar Sharma 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 rG5ec6ea3dfded: [clang][OpenMP][DebugInfo] Mark OpenMP 
generated functions as artificial (authored by alok).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111521

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/OpenMP/outlined_artificial.c


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined..1"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4097,8 +4097,12 @@
   if (Name.startswith("\01"))
 Name = Name.substr(1);
 
+  assert((!D || !isa(D) ||
+  GD.getDynamicInitKind() != DynamicInitKind::NoStub) &&
+ "Unexpected DynamicInitKind !");
+
   if (!HasDecl || D->isImplicit() || D->hasAttr() ||
-  (isa(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub)) 
{
+  isa(D) || isa(D)) {
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DI

[PATCH] D123787: [clang][OpenMP][DebugInfo] Debug support for TLS variables when present in OpenMP consructs

2022-04-14 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok created this revision.
alok added reviewers: jmorse, aprantl, djtodoro, jini.susan.
alok added a project: debug-info.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
alok requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

In case of OpenMP programs, thread local variables can be present in any clause 
pertaining to
OpenMP constructs, as we know that compiler generates artificial functions and 
in some cases
values are passed to those artificial functions thru parameters.
 For an example, if thread local variable is present in copyin clause (testcase 
attached with the
patch), parameter with same name is generated as parameter to artificial 
function. When user
inquires the thread Local variable, its debug info is hidden by the parameter. 
The debug info
for parameters (for thread local) must be suppressed.

Without the patch, attached testcase behaves wrongly under debuggers.

  Thread 3 "a.out" hit Breakpoint 3, .omp_outlined._debug__ 
(.global_tid.=0x155547ffde20, .bound_tid.=0x155547ffde18, nt=@0x7fffe2b8: 
4, gbl_int=@0x155c: 65)
  at simple.c:29
  29  printf ("In parallel region total threads = %d, thread id 
= %d data=%d gbl_addr = %p\n", nt, tid, data, &gbl_int);
  (gdb) p tid
  $1 = 2
  (gdb) p &gbl_int
  $2 = (int *) 0x155c
  (gdb) c
  Continuing.
  [Switching to Thread 0x13ad2b80 (LWP 12279)]
  
  Thread 2 "a.out" hit Breakpoint 2, .omp_outlined._debug__ 
(.global_tid.=0x13ad1de0, .bound_tid.=0x13ad1dd8, nt=@0x7fffe2b8: 
4, gbl_int=@0x155c: 65)
  at simple.c:27
  27  printf ("In parallel region total threads = %d, thread id 
= %d data=%d gbl_addr = %p\n", nt, tid, data, &gbl_int);
  (gdb) p tid
  $3 = 1
  (gdb) p &gbl_int
  $4 = (int *) 0x155c

Please note that same address is shown for all the threads which is wrong (for 
thread local variable).

With the current patch, the issue is fixed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123787

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug_threadprivate_copyin.c

Index: clang/test/OpenMP/debug_threadprivate_copyin.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_threadprivate_copyin.c
@@ -0,0 +1,59 @@
+// This testcase checks emission of debug info for threadprivate variables
+// present in any clause of OpenMP construct.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: define internal void @.omp_outlined._debug__(
+// CHECK: call void @llvm.dbg.declare(metadata i32** %.global_tid..addr,
+// CHECK: call void @llvm.dbg.declare(metadata i32** %.bound_tid..addr,
+// CHECK: call void @llvm.dbg.declare(metadata i32** %nt.addr
+// CHECK: store i32* %gbl_dynamic_int, i32** %gbl_dynamic_int.addr, align 8
+// CHECK-NOT: call void @llvm.dbg.declare(metadata i32** %gbl_dynamic_int.addr
+// CHECK-NOT: call void @llvm.dbg.declare(metadata i32** %gbl_static_int.addr
+
+extern int printf(const char *, ...);
+extern void omp_set_num_threads(int);
+extern int omp_get_num_threads(void);
+extern int omp_get_thread_num(void);
+
+int gbl_dynamic_int;
+__thread int gbl_static_int;
+
+#pragma omp threadprivate(gbl_dynamic_int)
+
+int main() {
+  int nt = 0;
+  int offset = 10;
+  gbl_dynamic_int = 55;
+  gbl_static_int = 77;
+
+  omp_set_num_threads(4);
+#pragma omp parallel copyin(gbl_dynamic_int, gbl_static_int)
+  {
+int data;
+int tid;
+nt = omp_get_num_threads();
+tid = omp_get_thread_num();
+data = gbl_dynamic_int + gbl_static_int;
+gbl_dynamic_int += 10;
+gbl_static_int += 20;
+#pragma omp barrier
+if (tid == 0)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 1)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 2)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 3)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+  }
+
+  return 0;
+}
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGS

[PATCH] D123787: [clang][OpenMP][DebugInfo] Debug support for TLS variables when present in OpenMP consructs

2022-04-18 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok added a comment.

In D123787#3452970 , @aprantl wrote:

>> For an example, if thread local variable is present in copyin clause 
>> (testcase attached with the
>
> patch), parameter with same name is generated as parameter to artificial 
> function. When user
> inquires the thread Local variable, its debug info is hidden by the 
> parameter. The debug info
> for parameters (for thread local) must be suppressed.
>
> What does the dwarfdump output for the old behavior look like? Are the two in 
> the same scope?

The dwarfdump output looks like below. DIE (0x0023) is for actual user 
defined variable and artificial one DIE (0x00b1) is at local scope, the one 
at local scope gets precedence.

  0x000c: DW_TAG_compile_unit
DW_AT_producer("clang version 14.0.0")
DW_AT_language(DW_LANG_C99)
DW_AT_name("debug_threadprivate_copyin.c")
DW_AT_str_offsets_base(0x0008)
DW_AT_stmt_list   (0x)
DW_AT_comp_dir("/home/alok/amdllvm/build.llvm.d")
DW_AT_low_pc  (0x)
DW_AT_high_pc (0x029b)
DW_AT_addr_base   (0x0008)
  
  0x0023:   DW_TAG_variable
  DW_AT_name  ("gbl_dynamic_int")
  DW_AT_type  (0x0036 "int")
  DW_AT_external  (true)
  DW_AT_decl_file ("debug_threadprivate_copyin.c")
  DW_AT_decl_line (22)
  DW_AT_location  (DW_OP_const8u 0x0, 
DW_OP_GNU_push_tls_address)
  
  0x0089:   DW_TAG_subprogram
  DW_AT_low_pc(0x0090)
  DW_AT_high_pc   (0x0260)
  DW_AT_frame_base(DW_OP_reg6 RBP)
  DW_AT_call_all_calls(true)
  DW_AT_name  (".omp_outlined._debug__")
  DW_AT_decl_file ("debug_threadprivate_copyin.c")
  DW_AT_decl_line (35)
  DW_AT_prototyped(true)
  
  0x00b1: DW_TAG_formal_parameter
DW_AT_location(DW_OP_fbreg -32)
DW_AT_name("gbl_dynamic_int")
DW_AT_decl_file   ("debug_threadprivate_copyin.c")
DW_AT_decl_line   (22)
DW_AT_type(0x0154 "int &")


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123787

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


[PATCH] D123787: [clang][OpenMP][DebugInfo] Debug support for TLS variables when present in OpenMP consructs

2022-04-18 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 423362.
alok added a comment.

Re-based.


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

https://reviews.llvm.org/D123787

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug_threadprivate_copyin.c

Index: clang/test/OpenMP/debug_threadprivate_copyin.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_threadprivate_copyin.c
@@ -0,0 +1,59 @@
+// This testcase checks emission of debug info for threadprivate variables
+// present in any clause of OpenMP construct.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: define internal void @.omp_outlined._debug__(
+// CHECK: call void @llvm.dbg.declare(metadata ptr %.global_tid..addr,
+// CHECK: call void @llvm.dbg.declare(metadata ptr %.bound_tid..addr,
+// CHECK: call void @llvm.dbg.declare(metadata ptr %nt.addr
+// CHECK: store ptr %gbl_dynamic_int, ptr %gbl_dynamic_int.addr, align 8
+// CHECK-NOT: call void @llvm.dbg.declare(metadata ptr %gbl_dynamic_int.addr
+// CHECK-NOT: call void @llvm.dbg.declare(metadata ptr %gbl_static_int.addr
+
+extern int printf(const char *, ...);
+extern void omp_set_num_threads(int);
+extern int omp_get_num_threads(void);
+extern int omp_get_thread_num(void);
+
+int gbl_dynamic_int;
+__thread int gbl_static_int;
+
+#pragma omp threadprivate(gbl_dynamic_int)
+
+int main() {
+  int nt = 0;
+  int offset = 10;
+  gbl_dynamic_int = 55;
+  gbl_static_int = 77;
+
+  omp_set_num_threads(4);
+#pragma omp parallel copyin(gbl_dynamic_int, gbl_static_int)
+  {
+int data;
+int tid;
+nt = omp_get_num_threads();
+tid = omp_get_thread_num();
+data = gbl_dynamic_int + gbl_static_int;
+gbl_dynamic_int += 10;
+gbl_static_int += 20;
+#pragma omp barrier
+if (tid == 0)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 1)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 2)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 3)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+  }
+
+  return 0;
+}
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -481,7 +481,11 @@
 if (ArgType->isVariablyModifiedType())
   ArgType = getCanonicalParamType(Ctx, ArgType);
 VarDecl *Arg;
-if (DebugFunctionDecl && (CapVar || I->capturesThis())) {
+if (CapVar && (CapVar->getTLSKind() != clang::VarDecl::TLS_None)) {
+  Arg = ImplicitParamDecl::Create(Ctx, /*DC=*/nullptr, FD->getLocation(),
+  II, ArgType,
+  ImplicitParamDecl::ThreadPrivateVar);
+} else if (DebugFunctionDecl && (CapVar || I->capturesThis())) {
   Arg = ParmVarDecl::Create(
   Ctx, DebugFunctionDecl,
   CapVar ? CapVar->getBeginLoc() : FD->getBeginLoc(),
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2442,6 +2442,7 @@
 /// for the specified parameter and set up LocalDeclMap.
 void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
unsigned ArgNo) {
+  bool NoDebugInfo = false;
   // FIXME: Why isn't ImplicitParamDecl a ParmVarDecl?
   assert((isa(D) || isa(D)) &&
  "Invalid argument to EmitParmDecl");
@@ -2461,6 +2462,10 @@
   setBlockContextParameter(IPD, ArgNo, V);
   return;
 }
+// Suppressing debug info for ThreadPrivateVar parameters, else it hides
+// debug info of TLS variables.
+NoDebugInfo =
+(IPD->getParameterKind() == ImplicitParamDecl::ThreadPrivateVar);
   }
 
   Address DeclPtr = Address::invalid();
@@ -2591,7 +2596,8 @@
 
   // Emit debug info for param declarations in non-thunk functions.
   if (CGDebugInfo *DI = getDebugInfo()) {
-if (CGM.getCodeGenOpts().hasReducedDebugInfo() && !CurFuncIsThunk) {
+if (CGM.getCodeGenOpts().hasReducedDebugInfo() && !CurFuncIsThunk &&
+!NoDebugInfo) {
   llvm::DILocalVariable *DILocalVar = DI->EmitDeclareOfArgVariab

[PATCH] D123787: [clang][OpenMP][DebugInfo] Debug support for TLS variables when present in OpenMP consructs

2022-04-23 Thread Alok Kumar Sharma via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa48300aee570: [clang][OpenMP][DebugInfo] Debug support for 
TLS variables present in OpenMP… (authored by alok).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123787

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug_threadprivate_copyin.c

Index: clang/test/OpenMP/debug_threadprivate_copyin.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_threadprivate_copyin.c
@@ -0,0 +1,59 @@
+// This testcase checks emission of debug info for threadprivate variables
+// present in any clause of OpenMP construct.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: define internal void @.omp_outlined._debug__(
+// CHECK: call void @llvm.dbg.declare(metadata ptr %.global_tid..addr,
+// CHECK: call void @llvm.dbg.declare(metadata ptr %.bound_tid..addr,
+// CHECK: call void @llvm.dbg.declare(metadata ptr %nt.addr
+// CHECK: store ptr %gbl_dynamic_int, ptr %gbl_dynamic_int.addr, align 8
+// CHECK-NOT: call void @llvm.dbg.declare(metadata ptr %gbl_dynamic_int.addr
+// CHECK-NOT: call void @llvm.dbg.declare(metadata ptr %gbl_static_int.addr
+
+extern int printf(const char *, ...);
+extern void omp_set_num_threads(int);
+extern int omp_get_num_threads(void);
+extern int omp_get_thread_num(void);
+
+int gbl_dynamic_int;
+__thread int gbl_static_int;
+
+#pragma omp threadprivate(gbl_dynamic_int)
+
+int main() {
+  int nt = 0;
+  int offset = 10;
+  gbl_dynamic_int = 55;
+  gbl_static_int = 77;
+
+  omp_set_num_threads(4);
+#pragma omp parallel copyin(gbl_dynamic_int, gbl_static_int)
+  {
+int data;
+int tid;
+nt = omp_get_num_threads();
+tid = omp_get_thread_num();
+data = gbl_dynamic_int + gbl_static_int;
+gbl_dynamic_int += 10;
+gbl_static_int += 20;
+#pragma omp barrier
+if (tid == 0)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 1)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 2)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 3)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+  }
+
+  return 0;
+}
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -481,7 +481,11 @@
 if (ArgType->isVariablyModifiedType())
   ArgType = getCanonicalParamType(Ctx, ArgType);
 VarDecl *Arg;
-if (DebugFunctionDecl && (CapVar || I->capturesThis())) {
+if (CapVar && (CapVar->getTLSKind() != clang::VarDecl::TLS_None)) {
+  Arg = ImplicitParamDecl::Create(Ctx, /*DC=*/nullptr, FD->getLocation(),
+  II, ArgType,
+  ImplicitParamDecl::ThreadPrivateVar);
+} else if (DebugFunctionDecl && (CapVar || I->capturesThis())) {
   Arg = ParmVarDecl::Create(
   Ctx, DebugFunctionDecl,
   CapVar ? CapVar->getBeginLoc() : FD->getBeginLoc(),
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2442,6 +2442,7 @@
 /// for the specified parameter and set up LocalDeclMap.
 void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
unsigned ArgNo) {
+  bool NoDebugInfo = false;
   // FIXME: Why isn't ImplicitParamDecl a ParmVarDecl?
   assert((isa(D) || isa(D)) &&
  "Invalid argument to EmitParmDecl");
@@ -2461,6 +2462,10 @@
   setBlockContextParameter(IPD, ArgNo, V);
   return;
 }
+// Suppressing debug info for ThreadPrivateVar parameters, else it hides
+// debug info of TLS variables.
+NoDebugInfo =
+(IPD->getParameterKind() == ImplicitParamDecl::ThreadPrivateVar);
   }
 
   Address DeclPtr = Address::invalid();
@@ -2591,7 +2596,8 @@
 
   // Emit debug info for param declarations in non-thunk functions.
   if (CGDebugInfo *DI = getDebugInfo()) {
-if (CGM.getCodeGenOpts().hasReducedDebugInfo() && !CurFuncIsThunk) {

[PATCH] D124982: [clang][OpenMP][DebugInfo] Debug support for variables in containing scope of OMP constructs

2022-05-04 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok created this revision.
alok added reviewers: aprantl, djtodoro, jmorse, jini.susan.
alok added a project: debug-info.
Herald added subscribers: guansong, hiraditya, yaxunl.
Herald added a project: All.
alok requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

In case of OpenMP, compilers generate encapsulates code present in
OpenMP construct to artificial functions. This is done to apply parallelism
to block of code. In context of these blocks, currently containing scope
variables are not accessible. This is due to new artificial function DIE being
in global scope.
As from user point of view, containing scope is same lexical scope, there
must be correct DIE hierarchy for artificial functions, which should be child
of containing scope.
Please consider below testcase.

   1  #include 
   2  #include 
   3
   4  int global_var1;
   5  int global_var2 = 99;
   6  int foo(int n) {
   7int same_var = 5;
   8int other_var = 21;
   9int share = 9, priv, i;
  10global_var1 = 99;
  11
  12if (n < 2)
  13  return n;
  14else {
  15  int same_var = rand() % 5;
  16  int local_var = 31;
  17  #pragma omp parallel for
  18  for (i = 0; i < n; i++) {
  19share += i;  // <-- (A)
  20  }
  21  return share;
  22}
  23  }
  24
  25  int main() {
  26int n = 10;
  27printf("foo(%d) = %d\n", n, foo(n));
  28return 0;
  29  }

Please consider the line# 19, user expects variables "same_var", "local_var", 
"other_var" to be
accessible inside debugger but which is not possible.

  (gdb) p same_var
  No symbol "same_var" in current context.
  (gdb) p other_var
  No symbol "other_var" in current context.
  (gdb) p local_var
  No symbol "local_var" in current context.

After current patch.

  (gdb) thr 1
  [Switching to thread 1 (Thread 0x77c1c400 (LWP 17992))]
  #0  .omp_outlined._debug__ (.global_tid.=0x7fffdad0, 
.bound_tid.=0x7fffdac8, n=@0x7fffdf18: 10, share=@0x7fffdf0c: 9) at 
1.c:19
  19share += i;
  (gdb) p same_var
  $1 = 3
  (gdb) p local_var
  $2 = 31
  (gdb) p other_var
  $3 = 21


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124982

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/OpenMP/debug_containing_scope.c
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h

Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -237,6 +237,7 @@
   DIE *getOrCreateNameSpace(const DINamespace *NS);
   DIE *getOrCreateModule(const DIModule *M);
   DIE *getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal = false);
+  DIE *getOrCreateLexicalScopeDIE(const DILexicalBlock *LS);
 
   void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie,
  bool SkipSPAttributes = false);
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -554,6 +554,8 @@
 return getOrCreateSubprogramDIE(SP);
   if (auto *M = dyn_cast(Context))
 return getOrCreateModule(M);
+  if (auto *LS = dyn_cast(Context))
+return getOrCreateLexicalScopeDIE(LS);
   return getDIE(Context);
 }
 
@@ -1181,6 +1183,17 @@
   return &SPDie;
 }
 
+DIE *DwarfUnit::getOrCreateLexicalScopeDIE(const DILexicalBlock *LS) {
+  DIE *ContextDIE = getOrCreateContextDIE(LS->getScope());
+
+  if (DIE *LSDie = getDIE(LS))
+return LSDie;
+
+  DIE &LSDie = createAndAddDIE(dwarf::DW_TAG_lexical_block, *ContextDIE, LS);
+
+  return &LSDie;
+}
+
 bool DwarfUnit::applySubprogramDefinitionAttributes(const DISubprogram *SP,
 DIE &SPDie, bool Minimal) {
   DIE *DeclDie = nullptr;
Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -686,6 +686,7 @@
 return nullptr;
 
   auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block);
+  insertDIE(Scope->getScopeNode(), ScopeDIE);
   if (Scope->isAbstractScope())
 return ScopeDIE;
 
Index: clang/test/OpenMP/debug_containing_scope.c
===
--- /dev/null
+++ clang/test/OpenMP

[PATCH] D124982: [clang][OpenMP][DebugInfo] Debug support for variables in containing scope of OMP constructs

2022-05-05 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 427237.
alok added a comment.

re-based.


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

https://reviews.llvm.org/D124982

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/OpenMP/debug_containing_scope.c
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h

Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -237,6 +237,7 @@
   DIE *getOrCreateNameSpace(const DINamespace *NS);
   DIE *getOrCreateModule(const DIModule *M);
   DIE *getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal = false);
+  DIE *getOrCreateLexicalScopeDIE(const DILexicalBlock *LS);
 
   void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie,
  bool SkipSPAttributes = false);
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -554,6 +554,8 @@
 return getOrCreateSubprogramDIE(SP);
   if (auto *M = dyn_cast(Context))
 return getOrCreateModule(M);
+  if (auto *LS = dyn_cast(Context))
+return getOrCreateLexicalScopeDIE(LS);
   return getDIE(Context);
 }
 
@@ -1181,6 +1183,17 @@
   return &SPDie;
 }
 
+DIE *DwarfUnit::getOrCreateLexicalScopeDIE(const DILexicalBlock *LS) {
+  DIE *ContextDIE = getOrCreateContextDIE(LS->getScope());
+
+  if (DIE *LSDie = getDIE(LS))
+return LSDie;
+
+  DIE &LSDie = createAndAddDIE(dwarf::DW_TAG_lexical_block, *ContextDIE, LS);
+
+  return &LSDie;
+}
+
 bool DwarfUnit::applySubprogramDefinitionAttributes(const DISubprogram *SP,
 DIE &SPDie, bool Minimal) {
   DIE *DeclDie = nullptr;
Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -686,6 +686,7 @@
 return nullptr;
 
   auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block);
+  insertDIE(Scope->getScopeNode(), ScopeDIE);
   if (Scope->isAbstractScope())
 return ScopeDIE;
 
Index: clang/test/OpenMP/debug_containing_scope.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_containing_scope.c
@@ -0,0 +1,68 @@
+// This testcase checks parent child relationship for OpenMP generated
+// functions.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// expected-no-diagnostics
+
+// CHECK-DAG: call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @8, i32 5, ptr @[[OUTLINED2:.omp_outlined..[0-9]]]
+// CHECK-LABEL: distinct !DICompileUnit
+// CHECK-DAG: [[FOO:![0-9]+]] = distinct !DISubprogram(name: "foo",
+// CHECK-DAG: [[LEX1:![0-9]+]] = distinct !DILexicalBlock(scope: [[FOO]]
+// CHECK-DAG: [[LEX2:![0-9]+]] = distinct !DILexicalBlock(scope: [[LEX1]]
+// CHECK-DAG: [[LEX3:![0-9]+]] = distinct !DILexicalBlock(scope: [[LEX2]]
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_privates_map.", scope: [[LEX3]]
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry.", scope: [[LEX3]]
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined.", scope: [[LEX2]]
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__", scope: [[LEX2]]
+// CHECK-DAG: !DISubprogram(name: "[[OUTLINED2]]", scope: [[LEX2]]
+
+extern int printf(const char *, ...);
+extern int rand(void);
+
+int global_var1;
+int global_var2 = 99;
+int foo(int n) {
+  int same_var = 5;
+  int other_var = 21;
+  int share = 9, priv, i;
+  global_var1 = 99;
+
+  if (n < 2)
+return n;
+  else {
+int same_var = rand() % 5;
+int local_var = 31;
+#pragma omp task shared(share) private(priv)
+{
+  priv = n;
+  printf("share = %d\n", share);
+  printf("global_var1 = %d\n", global_var1);
+  printf("global_var2 = %d\n", global_var2);
+  printf("same_var = %d\n", same_var);
+  printf("other_var = %d\n", other_var);
+  printf("local_var = %d\n", local_var);
+  share = priv + foo(n - 1);
+}
+#pragma omp taskwait
+
+#pragma omp parallel for
+for (i = 0; i < n; i++) {
+  share += i;
+  printf("share = %d\n", share);
+  printf("global_var1 = %d\n", global_var1);
+  printf("global_var2 = %d\n", global_var2);
+  printf

[PATCH] D124982: [clang][OpenMP][DebugInfo] Debug support for variables in containing scope of OMP constructs

2022-05-10 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 428322.
alok added a comment.

Re-based.


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

https://reviews.llvm.org/D124982

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/OpenMP/debug_containing_scope.c
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h

Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -237,6 +237,7 @@
   DIE *getOrCreateNameSpace(const DINamespace *NS);
   DIE *getOrCreateModule(const DIModule *M);
   DIE *getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal = false);
+  DIE *getOrCreateLexicalScopeDIE(const DILexicalBlock *LS);
 
   void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie,
  bool SkipSPAttributes = false);
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -554,6 +554,8 @@
 return getOrCreateSubprogramDIE(SP);
   if (auto *M = dyn_cast(Context))
 return getOrCreateModule(M);
+  if (auto *LS = dyn_cast(Context))
+return getOrCreateLexicalScopeDIE(LS);
   return getDIE(Context);
 }
 
@@ -1181,6 +1183,17 @@
   return &SPDie;
 }
 
+DIE *DwarfUnit::getOrCreateLexicalScopeDIE(const DILexicalBlock *LS) {
+  DIE *ContextDIE = getOrCreateContextDIE(LS->getScope());
+
+  if (DIE *LSDie = getDIE(LS))
+return LSDie;
+
+  DIE &LSDie = createAndAddDIE(dwarf::DW_TAG_lexical_block, *ContextDIE, LS);
+
+  return &LSDie;
+}
+
 bool DwarfUnit::applySubprogramDefinitionAttributes(const DISubprogram *SP,
 DIE &SPDie, bool Minimal) {
   DIE *DeclDie = nullptr;
Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -686,6 +686,7 @@
 return nullptr;
 
   auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block);
+  insertDIE(Scope->getScopeNode(), ScopeDIE);
   if (Scope->isAbstractScope())
 return ScopeDIE;
 
Index: clang/test/OpenMP/debug_containing_scope.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_containing_scope.c
@@ -0,0 +1,68 @@
+// This testcase checks parent child relationship for OpenMP generated
+// functions.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// expected-no-diagnostics
+
+// CHECK-DAG: call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @8, i32 5, ptr @[[OUTLINED2:.omp_outlined..[0-9]]]
+// CHECK-LABEL: distinct !DICompileUnit
+// CHECK-DAG: [[FOO:![0-9]+]] = distinct !DISubprogram(name: "foo",
+// CHECK-DAG: [[LEX1:![0-9]+]] = distinct !DILexicalBlock(scope: [[FOO]]
+// CHECK-DAG: [[LEX2:![0-9]+]] = distinct !DILexicalBlock(scope: [[LEX1]]
+// CHECK-DAG: [[LEX3:![0-9]+]] = distinct !DILexicalBlock(scope: [[LEX2]]
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_privates_map.", scope: [[LEX3]]
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry.", scope: [[LEX3]]
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined.", scope: [[LEX2]]
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__", scope: [[LEX2]]
+// CHECK-DAG: !DISubprogram(name: "[[OUTLINED2]]", scope: [[LEX2]]
+
+extern int printf(const char *, ...);
+extern int rand(void);
+
+int global_var1;
+int global_var2 = 99;
+int foo(int n) {
+  int same_var = 5;
+  int other_var = 21;
+  int share = 9, priv, i;
+  global_var1 = 99;
+
+  if (n < 2)
+return n;
+  else {
+int same_var = rand() % 5;
+int local_var = 31;
+#pragma omp task shared(share) private(priv)
+{
+  priv = n;
+  printf("share = %d\n", share);
+  printf("global_var1 = %d\n", global_var1);
+  printf("global_var2 = %d\n", global_var2);
+  printf("same_var = %d\n", same_var);
+  printf("other_var = %d\n", other_var);
+  printf("local_var = %d\n", local_var);
+  share = priv + foo(n - 1);
+}
+#pragma omp taskwait
+
+#pragma omp parallel for
+for (i = 0; i < n; i++) {
+  share += i;
+  printf("share = %d\n", share);
+  printf("global_var1 = %d\n", global_var1);
+  printf("global_var2 = %d\n", global_var2);
+  printf

[PATCH] D121100: [clang][DebugInfo] clang should not generate DW_TAG_subprogram entry without DW_AT_name

2022-05-22 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok abandoned this revision.
alok added a comment.

GNU gdb is now modified to accept functions with linkage name.

  commit 6f9b09edaee43ea34d34b1998fe7b844834f251a
  Author: Alok Kumar Sharma 
  Date:   Sun May 22 21:46:06 2022 +0530


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121100

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


[PATCH] D99160: [X86][FastISEL] Support DW_TAG_call_site_parameter with FastISEL

2021-05-13 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok added a comment.

In D99160#2700326 , @alok wrote:

> In D99160#2699038 , @dblaikie wrote:
>
>> In D99160#2698980 , @alok wrote:
>>
>>> In D99160#2671899 , @dblaikie 
>>> wrote:
>>>
 In D99160#2670460 , @djtodoro 
 wrote:

> In D99160#2669576 , @dblaikie 
> wrote:
>
>> In D99160#2668977 , @djtodoro 
>> wrote:
>>
>>> I think that the Debug Entry Values feature should not be enabled by 
>>> default for non optimized code, so the 
>>> `TargetOptions::ShouldEmitDebugEntryValues()` should be patched with 
>>> checking of optimization level (it should be > 0).
>>
>> That's currently intended to be already handled by the frontend, right? 
>> (clang only sets `EnableDebugEntryValues` (which 
>> `ShouldEmitDebugEntryValues` checks (hmm, it checks under 'or', not 
>> 'and', so I'm not sure where the "only above -O0" is implemented, but it 
>> is implemented somewhere?) if optimizations are enabled, yeah?)
>>
>> Oh, is entry_values actually not conditionalized? It's only the 
>> call_site support that's currently conditionalized on "above -O0"?
>
> Looks like there is no explicit check of optimization level (above 
> "-O0"), neither on frontend nor backend for entry-values generation. I 
> think it is the situation since there should not be any optimization (at 
> least that I am aware of, in the case of C/C++) that would cause the 
> entry-values generation...
>
>> Hmm - If that's the case, and we currently have some cases where 
>> entry_values are emitted at -O0, I'm not sure /not/ emitting those is 
>> the right call either. If we believe/have data to show that there are so 
>> few useful uses of entry_value at -O0 that it's not worth the DWARF size 
>> growth to put call_sites in at -O0, then I think it might still be worth 
>> leaving the entry_values in (unless they take up a bunch of extra space) 
>> for the cases of mixed optimization compilation (-O0 some code you're 
>> debugging, but building the rest with optimizations).
>
> Yeah... That is valuable example... I am thinking in that direction as 
> well, and I am closer to the enabling it for -O0 case if that is useful 
> (and there is no dramatic cost in terms of DWARF size).

 Does anyone have this example (where DW_OP_entry_value is used at -O0)? 
 It'd be great to look at it & see if it's a case of unnecessarily losing 
 the location, or legitimately losing it and using entry_value for 
 best-effort recovery (& then a question of whether the loss is appropriate 
 at -O0, or if we want to pessimize -O0 further to avoid the loss).
>>
>> I think this ^ still needs understanding/investigation. Do you have an 
>> example with OP_entry_value at -O0?
>>
 I'd worry about turning on call_sites at -O0 - there'd be a lot more calls 
 (especially for C++ code with lots of implicit operations), but numbers 
 will be needed in any case, so not worth much speculation.
>>>
>>> Sorry for late response.
>>> I tried building  
>>> https://github.com/flang-compiler/classic-flang-llvm-project.git (branch 
>>> release_11x) with compiler (current patch (https://reviews.llvm.org/D99160) 
>>> and https://reviews.llvm.org/D99238) with -O0 -g . 
>>> Interestingly there was no difference.
>>> Reason: https://reviews.llvm.org/D99238 is not sufficient for clang/clang++ 
>>> to enable call-site generation with FastISel though it is sufficient for 
>>> Flang compiler.
>>> Below additional patch is needed to generate call-sites
>>>
>>>   `
>>>
>>> diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
>>> b/clang/lib/CodeGen/CGDebugInfo.cpp
>>> index a77f52bd235b..8d4e11faa018 100644
>>>
>>> - a/clang/lib/CodeGen/CGDebugInfo.cpp
>>>
>>> +++ b/clang/lib/CodeGen/CGDebugInfo.cpp
>>> @@ -5149,9 +5149,9 @@ llvm::DebugLoc 
>>> CGDebugInfo::SourceLocToDebugLoc(SourceLocation Loc) {
>>>  }
>>>
>>> llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const {
>>>
>>> - // Call site-related attributes are only useful in optimized programs, and
>>> - // when there's a possibility of debugging backtraces.
>>> - if (!CGM.getLangOpts().Optimize || DebugKind == 
>>> codegenoptions::NoDebugInfo ||
>>>
>>> +  // Call site-related attributes are useful when there's a possibility of
>>> +  // debugging backtraces.
>>> +  if (DebugKind == codegenoptions::NoDebugInfo ||
>>>
>>> DebugKind == codegenoptions::LocTrackingOnly)
>>>   return llvm::DINode::FlagZero;
>>>
>>>   `
>>>
>>> With this patch Clang/Clang++ turn on LLVM IR flag 
>>> "DIFlagAllCal

[PATCH] D114504: [clang][DebugInfo] Debug support for private variables inside an OpenMP task construct

2021-11-23 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok created this revision.
alok added reviewers: aprantl, djtodoro.
alok added a project: debug-info.
Herald added subscribers: pengfei, guansong, yaxunl.
alok requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Currently variables appearing inside private/firstprivate/lastprivate
clause of openmp task construct are not visible inside lldb debugger.
This is because compiler does not generate debug info for it.

Please consider the testcase debug_private.c attached with patch.

  ```

(lldb) b 34
Breakpoint 1: where = a.out`.omp_task_entry. + 243 [inlined] .omp_outlined. + 
157 at debug_private.c:28, address = 0x004008f3
(lldb) r
Process 18475 launched: '/tmp/a.out' (x86_64)
Task n=10,priv1=10,priv2=12,fpriv=14
Process 18475 stopped

- thread #1, name = 'a.out', stop reason = breakpoint 1.1 frame #0: 
0x004008f3 a.out`.omp_task_entry. [inlined] 
.omp_outlined.(.global_tid.=0, .part_id.=0x0070d3d0, 
.privates.=0x0070d3e8, .copy_fn.=(a.out`.omp_task_privates_map. at 
debug_private.c:28), .task_t.=0x0070d3c0, __context=0x0070d3f8) 
at debug_private.c:34:13 31 priv2 = n + 2; 32 printf("Task 
n=%d,priv1=%d,priv2=%d,fpriv=%d\n",n,priv1,priv2,fpriv); 33

-> 34 res = priv1 + priv2 + fpriv + foo(n - 1);

  35   }
  36   #pragma omp taskwait
  37   return res;

(lldb) p priv1
error: :1:1: use of undeclared identifier 'priv1'
priv1
^
(lldb) p priv2
error: :1:1: use of undeclared identifier 'priv2'
priv2
^
(lldb) p fpriv
error: :1:1: use of undeclared identifier 'fpriv'
fpriv
^

  

After the current patch, lldb is able to show the variables

  

(lldb) p priv1
(int) $0 = 10
(lldb) p priv2
(int) $1 = 12
(lldb) p fpriv
(int) $2 = 14

  ``


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114504

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug_private.c


Index: clang/test/OpenMP/debug_private.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_private.c
@@ -0,0 +1,45 @@
+// This testcase checks emission of debug info for variables inside
+// private/firstprivate/lastprivate.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: define internal i32 @.omp_task_entry.
+
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr.i, 
metadata [[PRIV1:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr1.i, 
metadata [[PRIV2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.firstpriv.ptr.addr.i, 
metadata [[FPRIV:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+
+// CHECK: [[PRIV1]] = !DILocalVariable(name: "priv1"
+// CHECK: [[PRIV2]] = !DILocalVariable(name: "priv2"
+// CHECK: [[FPRIV]] = !DILocalVariable(name: "fpriv"
+
+extern int printf(const char *, ...);
+
+int foo(int n) {
+  int res, priv1, priv2, fpriv;
+  fpriv = n + 4;
+
+  if (n < 2)
+return n;
+  else {
+#pragma omp task shared(res) private(priv1, priv2) firstprivate(fpriv)
+{
+  priv1 = n;
+  priv2 = n + 2;
+  printf("Task n=%d,priv1=%d,priv2=%d,fpriv=%d\n",n,priv1,priv2,fpriv);
+
+  res = priv1 + priv2 + fpriv + foo(n - 1);
+}
+#pragma omp taskwait
+return res;
+  }
+}
+
+int main() {
+  int n = 10;
+  printf("foo(%d) = %d\n", n, foo(n));
+  return 0;
+}
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4510,6 +4510,10 @@
 Address Replacement(CGF.Builder.CreateLoad(Pair.second),
 CGF.getContext().getDeclAlign(Pair.first));
 Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; });
+if (auto *DI = CGF.getDebugInfo()) {
+  DI->EmitDeclareOfAutoVariable(Pair.first, Pair.second.getPointer(),
+CGF.Builder, true);
+}
   }
   // Adjust mapping for internal locals by mapping actual memory instead of
   // a pointer to this memory.


Index: clang/test/OpenMP/debug_private.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_private.c
@@ -0,0 +1,45 @@
+// This testcase checks emission of debug info for variables inside
+// private/firstprivate/lastprivate.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: define internal i32 @.omp_task_entry.
+
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv

[PATCH] D114504: [clang][DebugInfo] Debug support for private variables inside an OpenMP task construct

2021-11-24 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok added a comment.

In D114504#3151332 , @djtodoro wrote:

> Thanks for doing this! Can you please update the summary, since it hard to 
> read with the format like this (at least, just try to reformat the debugger 
> output properly with the Phabricator formatters)?

Sorry for the bad formatting. I have corrected it now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114504

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


[PATCH] D114504: [clang][DebugInfo] Debug support for private variables inside an OpenMP task construct

2021-11-25 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:4513
 Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; });
+if (auto *DI = CGF.getDebugInfo()) {
+  DI->EmitDeclareOfAutoVariable(Pair.first, Pair.second.getPointer(),

djtodoro wrote:
> I think we can get rid of curly brackets.
Sure, I am doing it.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:4515
+  DI->EmitDeclareOfAutoVariable(Pair.first, Pair.second.getPointer(),
+CGF.Builder, true);
+}

djtodoro wrote:
> 
Thanks. I am updating it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114504

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


[PATCH] D114504: [clang][DebugInfo] Debug support for private variables inside an OpenMP task construct

2021-11-25 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 389699.
alok added a comment.

Re-based and incorporated comments from @djtodoro


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

https://reviews.llvm.org/D114504

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug_private.c


Index: clang/test/OpenMP/debug_private.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_private.c
@@ -0,0 +1,45 @@
+// This testcase checks emission of debug info for variables inside
+// private/firstprivate/lastprivate.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: define internal i32 @.omp_task_entry.
+
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr.i, 
metadata [[PRIV1:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr1.i, 
metadata [[PRIV2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.firstpriv.ptr.addr.i, 
metadata [[FPRIV:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+
+// CHECK: [[PRIV1]] = !DILocalVariable(name: "priv1"
+// CHECK: [[PRIV2]] = !DILocalVariable(name: "priv2"
+// CHECK: [[FPRIV]] = !DILocalVariable(name: "fpriv"
+
+extern int printf(const char *, ...);
+
+int foo(int n) {
+  int res, priv1, priv2, fpriv;
+  fpriv = n + 4;
+
+  if (n < 2)
+return n;
+  else {
+#pragma omp task shared(res) private(priv1, priv2) firstprivate(fpriv)
+{
+  priv1 = n;
+  priv2 = n + 2;
+  printf("Task n=%d,priv1=%d,priv2=%d,fpriv=%d\n", n, priv1, priv2, fpriv);
+
+  res = priv1 + priv2 + fpriv + foo(n - 1);
+}
+#pragma omp taskwait
+return res;
+  }
+}
+
+int main() {
+  int n = 10;
+  printf("foo(%d) = %d\n", n, foo(n));
+  return 0;
+}
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4510,6 +4510,9 @@
 Address Replacement(CGF.Builder.CreateLoad(Pair.second),
 CGF.getContext().getDeclAlign(Pair.first));
 Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; });
+if (auto *DI = CGF.getDebugInfo())
+  DI->EmitDeclareOfAutoVariable(Pair.first, Pair.second.getPointer(),
+CGF.Builder, /*UsePointerValue*/ true);
   }
   // Adjust mapping for internal locals by mapping actual memory instead of
   // a pointer to this memory.


Index: clang/test/OpenMP/debug_private.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_private.c
@@ -0,0 +1,45 @@
+// This testcase checks emission of debug info for variables inside
+// private/firstprivate/lastprivate.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: define internal i32 @.omp_task_entry.
+
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr.i, metadata [[PRIV1:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr1.i, metadata [[PRIV2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.firstpriv.ptr.addr.i, metadata [[FPRIV:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+
+// CHECK: [[PRIV1]] = !DILocalVariable(name: "priv1"
+// CHECK: [[PRIV2]] = !DILocalVariable(name: "priv2"
+// CHECK: [[FPRIV]] = !DILocalVariable(name: "fpriv"
+
+extern int printf(const char *, ...);
+
+int foo(int n) {
+  int res, priv1, priv2, fpriv;
+  fpriv = n + 4;
+
+  if (n < 2)
+return n;
+  else {
+#pragma omp task shared(res) private(priv1, priv2) firstprivate(fpriv)
+{
+  priv1 = n;
+  priv2 = n + 2;
+  printf("Task n=%d,priv1=%d,priv2=%d,fpriv=%d\n", n, priv1, priv2, fpriv);
+
+  res = priv1 + priv2 + fpriv + foo(n - 1);
+}
+#pragma omp taskwait
+return res;
+  }
+}
+
+int main() {
+  int n = 10;
+  printf("foo(%d) = %d\n", n, foo(n));
+  return 0;
+}
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4510,6 +4510,9 @@
 Address Replacement(CGF.Builder.CreateLoad(Pair.second),
 CGF.getContext().getDeclAlign(Pair.first));
 Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; });
+if (auto *DI = CGF.getDebugInfo())
+  DI->EmitDeclareOfAutoVariable(Pair.first, Pair.second.getPointer(),
+CGF.Builder, /*U

[PATCH] D114504: [clang][DebugInfo] Debug support for private variables inside an OpenMP task construct

2021-11-25 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok added a comment.

Thanks @djtodoro . I have incorporated all your comments.


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

https://reviews.llvm.org/D114504

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


[PATCH] D114504: [clang][DebugInfo] Debug support for private variables inside an OpenMP task construct

2021-11-25 Thread Alok Kumar Sharma 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 rG36cb7477d1d4: [clang][OpenMP][DebugInfo] Debug support for 
private variables inside an OpenMP… (authored by alok).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114504

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug_private.c


Index: clang/test/OpenMP/debug_private.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_private.c
@@ -0,0 +1,45 @@
+// This testcase checks emission of debug info for variables inside
+// private/firstprivate/lastprivate.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: define internal i32 @.omp_task_entry.
+
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr.i, 
metadata [[PRIV1:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr1.i, 
metadata [[PRIV2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.firstpriv.ptr.addr.i, 
metadata [[FPRIV:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+
+// CHECK: [[PRIV1]] = !DILocalVariable(name: "priv1"
+// CHECK: [[PRIV2]] = !DILocalVariable(name: "priv2"
+// CHECK: [[FPRIV]] = !DILocalVariable(name: "fpriv"
+
+extern int printf(const char *, ...);
+
+int foo(int n) {
+  int res, priv1, priv2, fpriv;
+  fpriv = n + 4;
+
+  if (n < 2)
+return n;
+  else {
+#pragma omp task shared(res) private(priv1, priv2) firstprivate(fpriv)
+{
+  priv1 = n;
+  priv2 = n + 2;
+  printf("Task n=%d,priv1=%d,priv2=%d,fpriv=%d\n", n, priv1, priv2, fpriv);
+
+  res = priv1 + priv2 + fpriv + foo(n - 1);
+}
+#pragma omp taskwait
+return res;
+  }
+}
+
+int main() {
+  int n = 10;
+  printf("foo(%d) = %d\n", n, foo(n));
+  return 0;
+}
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4510,6 +4510,9 @@
 Address Replacement(CGF.Builder.CreateLoad(Pair.second),
 CGF.getContext().getDeclAlign(Pair.first));
 Scope.addPrivate(Pair.first, [Replacement]() { return Replacement; });
+if (auto *DI = CGF.getDebugInfo())
+  DI->EmitDeclareOfAutoVariable(Pair.first, Pair.second.getPointer(),
+CGF.Builder, /*UsePointerValue*/ true);
   }
   // Adjust mapping for internal locals by mapping actual memory instead of
   // a pointer to this memory.


Index: clang/test/OpenMP/debug_private.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_private.c
@@ -0,0 +1,45 @@
+// This testcase checks emission of debug info for variables inside
+// private/firstprivate/lastprivate.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: define internal i32 @.omp_task_entry.
+
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr.i, metadata [[PRIV1:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.priv.ptr.addr1.i, metadata [[PRIV2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK:  call void @llvm.dbg.declare(metadata i32** %.firstpriv.ptr.addr.i, metadata [[FPRIV:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+
+// CHECK: [[PRIV1]] = !DILocalVariable(name: "priv1"
+// CHECK: [[PRIV2]] = !DILocalVariable(name: "priv2"
+// CHECK: [[FPRIV]] = !DILocalVariable(name: "fpriv"
+
+extern int printf(const char *, ...);
+
+int foo(int n) {
+  int res, priv1, priv2, fpriv;
+  fpriv = n + 4;
+
+  if (n < 2)
+return n;
+  else {
+#pragma omp task shared(res) private(priv1, priv2) firstprivate(fpriv)
+{
+  priv1 = n;
+  priv2 = n + 2;
+  printf("Task n=%d,priv1=%d,priv2=%d,fpriv=%d\n", n, priv1, priv2, fpriv);
+
+  res = priv1 + priv2 + fpriv + foo(n - 1);
+}
+#pragma omp taskwait
+return res;
+  }
+}
+
+int main() {
+  int n = 10;
+  printf("foo(%d) = %d\n", n, foo(n));
+  return 0;
+}
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4510,6 +4510,9 @@
 Address Replacement(CGF.Builder.CreateLoad(Pair.second),
 CGF.getContext().getDeclAlign(Pair.first));
 Scope.addPrivate(Pair.first, [Replacement]() { return Replacemen

[PATCH] D111521: [DebugInfo] Mark OpenMP generated functions as artificial

2022-06-15 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 437064.
alok added a comment.
Herald added a project: All.

Re-based and updated to include one negative testcase.
I could not find a test for VarDecl with DynamicInitKind::NoStub. There are 
constructors for other DynamicInitKind but not for NoStub. Please help me in 
case you are aware of the condition when it is produced.


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

https://reviews.llvm.org/D111521

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/OpenMP/outlined_artificial.c


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined..1"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4096,7 +4096,8 @@
 Name = Name.substr(1);
 
   if (!HasDecl || D->isImplicit() || D->hasAttr() ||
-  (isa(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub)) 
{
+  (isa(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub) 
||
+  isa(D)) {
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,67 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// foo_simd is not artificial.
+// CHECK-DAG: !DISubprogram(name: "foo_simd"
+// CHECK-DAG-SAME: flags: DIFlagPrototyped,
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: "__captured_stmt"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubprogram(name: ".omp_outlined."
+// CHECK-DAG-SAME: flags: DIFlagArtificial
+
+// CHECK-DAG: !DISubpr

[PATCH] D121100: [clang][DebugInfo] clang should not generate DW_TAG_subprogram entry without DW_AT_name

2022-03-07 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok created this revision.
alok added reviewers: aprantl, djtodoro, jini.susan.
alok added a project: debug-info.
Herald added a project: All.
alok requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently Clang is generating subprograms without DW_AT_name. which is fine for 
LLDB but other debuggers (GNU gdb) can not be forced to accept such DWARF due 
to DWARF standard mandating DW_AT_name attribute for subprograms.

As per DWARF standard Subroutine must have DW_AT_name attribute.
Please consider below lines from DWARF(5) document

  3.3.1 General Subroutine and Entry Point Information
   The subroutine or entry point entry has a DW_AT_name attribute whose value is
   a null-terminated string containing the subroutine or entry point name. It 
may
   also have a DW_AT_linkage_name attribute as described in Section 2.22 on
   page 56.

Current behavior of Clang prevents gdb to show variables in shared/private 
clause of Openmp task construct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121100

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/constructor-attribute.c
  clang/test/CodeGen/debug-info-oslog.c
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/debug-info-blocks.cpp
  clang/test/CodeGenCXX/debug-info-thunk.cpp
  clang/test/CodeGenCXX/difile_entry.cpp
  clang/test/CodeGenCXX/globalinit-loc.cpp
  clang/test/CodeGenObjC/block-byref-debuginfo.m
  clang/test/CodeGenObjC/debug-info-block-helper.m
  clang/test/CodeGenObjC/debug-info-blocks.m
  clang/test/CodeGenObjC/nontrivial-c-struct-exception.m
  clang/test/OpenMP/master_taskloop_reduction_codegen.cpp
  clang/test/OpenMP/master_taskloop_simd_reduction_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_reduction_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_reduction_codegen.cpp
  clang/test/OpenMP/simd_codegen.cpp
  clang/test/OpenMP/taskgroup_task_reduction_codegen.cpp
  clang/test/OpenMP/taskloop_reduction_codegen.cpp
  clang/test/OpenMP/taskloop_simd_reduction_codegen.cpp

Index: clang/test/OpenMP/taskloop_simd_reduction_codegen.cpp
===
--- clang/test/OpenMP/taskloop_simd_reduction_codegen.cpp
+++ clang/test/OpenMP/taskloop_simd_reduction_codegen.cpp
@@ -213,12 +213,12 @@
 // CHECK: store float %{{.+}}, float* %
 // CHECK: ret void
 
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT1]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB1]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT2]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_FINI2]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB2]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT3]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB3]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT4]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB4]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT1]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB1]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT2]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_FINI2]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB2]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT3]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB3]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT4]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB4]]"
Index: clang/test/OpenMP/taskloop_reduction_codegen.cpp
===
--- clang/test/OpenMP/taskloop_reduction_codegen.cpp
+++ clang/test/OpenMP/taskloop_reduction_codegen.cpp
@@ -220,13 +220,13 @@
 // CHECK: call i8* @__kmpc_task_reduction_get_th_data(
 // CHECK: call i8* @__kmpc_task_reduction_get_th_data(
 
-// CHECK-DAG: distinct !DISubprogram(linkageName: "[[TASK]]", scope: !
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT1]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB1]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT2]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_FINI2]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB2]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT3]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB3]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT4]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB4]]"
+// CHECK-DAG: distinct !DISubprogram(name: "[[TASK]]", scope: !
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT1]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB1]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT2]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_FINI2]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB2]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT3]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB3]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT4]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB4]]"
Index: clang/test/OpenMP/taskgroup_task_reduction_codegen.cpp

[PATCH] D115510: [clang][OpenMP][DebugInfo] Debug support for variables in shared clause of OpenMP task construct

2021-12-10 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok created this revision.
alok added reviewers: aprantl, djtodoro, jdoerfert, jini.susan.george.
alok added a project: debug-info.
Herald added subscribers: guansong, yaxunl.
alok requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Currently variables appearing inside shared clause of OpenMP task construct are 
not visible inside lldb debugger.
This is because compiler does not generate debug info for it.

  * thread #1, name = 'a.out', stop reason = breakpoint 1.1
  frame #0: 0x00400934 a.out`.omp_task_entry. [inlined] 
.omp_outlined.(.global_tid.=0, .part_id.=0x0071f0d0, 
.privates.=0x0071f0e8, .copy_fn.=(a.out`.omp_task_privates_map. at 
testshared.cxx:8), .task_t.=0x0071f0c0, __context=0x0071f0f0) 
at testshared.cxx:10:34
 7  else {
 8#pragma omp task shared(svar) firstprivate(n)
 9{
  -> 10 printf("Task svar = %d\n", svar);
 11 printf("Task n = %d\n", n);
 12 svar = fib(n - 1);
 13   }
  (lldb) p svar
  error: :1:1: use of undeclared identifier 'svar'
  svar
  ^
  (lldb)

After the current patch, lldb is able to show the variable

  * thread #1, name = 'a.out', stop reason = breakpoint 1.1
  frame #0: 0x00400934 a.out`.omp_task_entry. [inlined] 
.omp_outlined.(.global_tid.=0, .part_id.=0x0071f0d0, 
.privates.=0x0071f0e8, .copy_fn.=(a.out`.omp_task_privates_map. at 
testshared.cxx:8), .task_t.=0x0071f0c0, __context=0x0071f0f0) 
at testshared.cxx:10:34
 7  else {
 8#pragma omp task shared(svar) firstprivate(n)
 9{
  -> 10 printf("Task svar = %d\n", svar);
 11 printf("Task n = %d\n", n);
 12 svar = fib(n - 1);
 13   }
  (lldb) p svar
  (int) $0 = 9
  (lldb)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115510

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/debug_task_shared.c

Index: clang/test/OpenMP/debug_task_shared.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_task_shared.c
@@ -0,0 +1,55 @@
+// This testcase checks emission of debug info for variables
+// inside shared clause of task construct.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=NEG
+// expected-no-diagnostics
+
+// CHECK-LABEL: define internal i32 @.omp_task_entry.
+
+// CHECK-DAG:  [[CONTEXT:%[0-9]+]] = load %struct.anon*, %struct.anon** %__context.addr.i, align 8
+// CHECK-DAG:  call void @llvm.dbg.declare(metadata %struct.anon* [[CONTEXT]], metadata [[SHARE2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK-DAG:  call void @llvm.dbg.declare(metadata %struct.anon* [[CONTEXT]], metadata [[SHARE3:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 8, DW_OP_deref))
+// CHECK-DAG:  call void @llvm.dbg.declare(metadata %struct.anon* [[CONTEXT]], metadata [[SHARE1:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_deref))
+
+// CHECK-DAG: [[SHARE2]] = !DILocalVariable(name: "share2"
+// CHECK-DAG: [[SHARE3]] = !DILocalVariable(name: "share3"
+// CHECK-DAG: [[SHARE1]] = !DILocalVariable(name: "share1"
+
+// NEG-LABEL: define internal i32 @.omp_task_entry.
+// NEG:  [[CONTEXT:%[0-9]+]] = load %struct.anon*, %struct.anon** %__context.addr.i, align 8
+// NEG-NOT: call void @llvm.dbg.declare(metadata %struct.anon* [[CONTEXT]], metadata {{![0-9]+}}, metadata !DIExpression(DW_OP_deref))
+
+extern int printf(const char *, ...);
+
+int foo(int n) {
+  int share1 = 9, share2 = 11, share3 = 13, priv1, priv2, fpriv;
+  fpriv = n + 4;
+
+  if (n < 2)
+return n;
+  else {
+#if SHARED
+#pragma omp task shared(share1, share2) private(priv1, priv2) firstprivate(fpriv) shared(share3)
+#else
+#pragma omp task private(priv1, priv2) firstprivate(fpriv)
+#endif
+{
+  priv1 = n;
+  priv2 = n + 2;
+  share2 += share3;
+  printf("share1 = %d, share2 = %d, share3 = %d\n", share1, share2, share3);
+  share1 = priv1 + priv2 + fpriv + foo(n - 1) + share2 + share3;
+}
+#pragma omp taskwait
+return share1 + share2 + share3;
+  }
+}
+
+int main() {
+  int n = 10;
+  printf("foo(%d) = %d\n", n, foo(n));
+  return 0;
+}
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -459,6 +459,11 @@
 /// Get the name of the capture helper.
 virtual StringRef getHelperName() const { return "__captured_stmt"; }
 
+/// Get the CaptureFields
+llvm::SmallDenseMap get

[PATCH] D115510: [clang][OpenMP][DebugInfo] Debug support for variables in shared clause of OpenMP task construct

2021-12-20 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok added a comment.

PING !!!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115510

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


[PATCH] D115510: [clang][OpenMP][DebugInfo] Debug support for variables in shared clause of OpenMP task construct

2021-12-22 Thread Alok Kumar Sharma via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5eb271880c8f: [clang][OpenMP][DebugInfo] Debug support for 
variables in shared clause of… (authored by alok).

Changed prior to commit:
  https://reviews.llvm.org/D115510?vs=393447&id=395860#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115510

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/debug_task_shared.c

Index: clang/test/OpenMP/debug_task_shared.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_task_shared.c
@@ -0,0 +1,55 @@
+// This testcase checks emission of debug info for variables
+// inside shared clause of task construct.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -DSHARED -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=NEG
+// expected-no-diagnostics
+
+// CHECK-LABEL: define internal i32 @.omp_task_entry.
+
+// CHECK-DAG:  [[CONTEXT:%[0-9]+]] = load %struct.anon*, %struct.anon** %__context.addr.i, align 8
+// CHECK-DAG:  call void @llvm.dbg.declare(metadata %struct.anon* [[CONTEXT]], metadata [[SHARE2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+// CHECK-DAG:  call void @llvm.dbg.declare(metadata %struct.anon* [[CONTEXT]], metadata [[SHARE3:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 8, DW_OP_deref))
+// CHECK-DAG:  call void @llvm.dbg.declare(metadata %struct.anon* [[CONTEXT]], metadata [[SHARE1:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_deref))
+
+// CHECK-DAG: [[SHARE2]] = !DILocalVariable(name: "share2"
+// CHECK-DAG: [[SHARE3]] = !DILocalVariable(name: "share3"
+// CHECK-DAG: [[SHARE1]] = !DILocalVariable(name: "share1"
+
+// NEG-LABEL: define internal i32 @.omp_task_entry.
+// NEG:  [[CONTEXT:%[0-9]+]] = load %struct.anon*, %struct.anon** %__context.addr.i, align 8
+// NEG-NOT: call void @llvm.dbg.declare(metadata %struct.anon* [[CONTEXT]], metadata {{![0-9]+}}, metadata !DIExpression(DW_OP_deref))
+
+extern int printf(const char *, ...);
+
+int foo(int n) {
+  int share1 = 9, share2 = 11, share3 = 13, priv1, priv2, fpriv;
+  fpriv = n + 4;
+
+  if (n < 2)
+return n;
+  else {
+#if SHARED
+#pragma omp task shared(share1, share2) private(priv1, priv2) firstprivate(fpriv) shared(share3)
+#else
+#pragma omp task private(priv1, priv2) firstprivate(fpriv)
+#endif
+{
+  priv1 = n;
+  priv2 = n + 2;
+  share2 += share3;
+  printf("share1 = %d, share2 = %d, share3 = %d\n", share1, share2, share3);
+  share1 = priv1 + priv2 + fpriv + foo(n - 1) + share2 + share3;
+}
+#pragma omp taskwait
+return share1 + share2 + share3;
+  }
+}
+
+int main() {
+  int n = 10;
+  printf("foo(%d) = %d\n", n, foo(n));
+  return 0;
+}
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -459,6 +459,11 @@
 /// Get the name of the capture helper.
 virtual StringRef getHelperName() const { return "__captured_stmt"; }
 
+/// Get the CaptureFields
+llvm::SmallDenseMap getCaptureFields() {
+  return CaptureFields;
+}
+
   private:
 /// The kind of captured statement being generated.
 CapturedRegionKind Kind;
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -24,10 +24,13 @@
 #include "clang/AST/StmtVisitor.h"
 #include "clang/Basic/OpenMPKinds.h"
 #include "clang/Basic/PrettyStackTrace.h"
+#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
 #include "llvm/IR/Constants.h"
+#include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/Instructions.h"
+#include "llvm/IR/Metadata.h"
 #include "llvm/Support/AtomicOrdering.h"
 using namespace clang;
 using namespace CodeGen;
@@ -4431,6 +4434,53 @@
 UntiedLocalVars;
 // Set proper addresses for generated private copies.
 OMPPrivateScope Scope(CGF);
+// Generate debug info for variables present in shared clause.
+if (auto *DI = CGF.getDebugInfo()) {
+  llvm::SmallDenseMap CaptureFields =
+  CGF.CapturedStmtInfo->getCaptureFields();
+  llvm::Value *ContextValue = CGF.CapturedStmtInfo->getContextValue();
+  if (CaptureFields.size() && ContextValue) {
+unsigned CharWidth = CGF.getContext().getCharWidth();
+// The shared variables are packed together as members of structure.
+// So the address of each shared variable can be comp

[PATCH] D115510: [clang][OpenMP][DebugInfo] Debug support for variables in shared clause of OpenMP task construct

2021-12-22 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok marked an inline comment as done.
alok added a comment.

Thanks @djtodoro .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115510

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


[PATCH] D99160: [X86][FastISEL] Support DW_TAG_call_site_parameter with FastISEL

2021-03-23 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok created this revision.
alok added reviewers: aprantl, jmorse, djtodoro.
alok added a project: debug-info.
Herald added subscribers: jansvoboda11, pengfei, ormris, hiraditya.
Herald added a reviewer: sscalpone.
alok requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

DW_OP_entry_value and DW_TAG_call_site_parameter work together to preserve 
optimized out paramters value for debugging purpose.
There is always some level of optimization happening even with -O0.
 Currently DW_OP_entry_value is generated at all the options but 
DW_TAG_call_site_parameter is not generated with FastISEL.
 This causes debuggers to show optimized out parameters value at higher 
optimization but not at lower optimization.

Adding support to it now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99160

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
  llvm/lib/Target/X86/X86FastISel.cpp
  llvm/test/CodeGen/X86/call-site-info-output.ll
  llvm/test/DebugInfo/X86/callsitepar-fastisel.ll

Index: llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
@@ -0,0 +1,215 @@
+;; This test checks if DW_TAG_GNU_call_site_parameter is generated for fastIsel.
+; REQUIRES: x86_64-linux
+;RUN: llc -mtriple=x86_64-pc-linux-gnu -emit-call-site-info -fast-isel=true -filetype=obj %s -o - | llvm-dwarfdump - | FileCheck %s
+;CHECK: DW_TAG_GNU_call_site
+;CHECK: DW_AT_abstract_origin
+;CHECK-SAME: "foo"
+;CHECK: DW_AT_low_pc
+;CHECK: DW_TAG_GNU_call_site_parameter
+;CHECK: DW_AT_location (DW_OP_reg4 RSI)
+;CHECK: DW_AT_GNU_call_site_value
+
+;; This test checks if DW_TAG_GNU_call_site_parameter is generated for option -O0
+;RUN: clang -cc1 -triple x86_64-unknown-linux-gnu -emit-obj  -main-file-name %s -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -O0 -x ir %s -o - | llvm-dwarfdump - | FileCheck %s --check-prefix=CLANG
+
+;CLANG: DW_TAG_GNU_call_site
+;CLANG: DW_AT_abstract_origin
+;CLANG-SAME: "foo"
+;CLANG: DW_AT_low_pc
+;CLANG: DW_TAG_GNU_call_site_parameter
+;CLANG: DW_AT_location (DW_OP_reg4 RSI)
+;CLANG: DW_AT_GNU_call_site_value
+
+;;The IR is generated from below source program
+;
+;;subroutine foo (array)
+;;  integer :: array(:,:)
+;;  array(:,:) = 5
+;;  array(1,1) = 30
+;;end subroutine
+;;
+;;program vla_sub
+;;  interface
+;;subroutine foo (array)
+;;  integer :: array (:,:)
+;;end subroutine
+;;  end interface
+;;
+;;  integer :: sub_arr(42,42)
+;;  sub_arr(:,:) = 1
+;;  call foo(sub_arr)
+;;end program vla_sub
+;
+
+; ModuleID = 'fast.ll'
+source_filename = "/tmp/fast.ll"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.BSS2 = type <{ [7056 x i8] }>
+
+@.BSS2 = internal global %struct.BSS2 zeroinitializer, align 32, !dbg !0
+@.C359_MAIN_ = internal constant i64 42
+@.C333_MAIN_ = internal constant i64 1
+@.C368_MAIN_ = internal constant i64 4
+@.C367_MAIN_ = internal constant i64 25
+@.C331_MAIN_ = internal constant i64 0
+@.C330_MAIN_ = internal constant i32 0
+
+; Function Attrs: nofree norecurse nounwind
+define void @foo_(i64* noalias nocapture %array, i64* noalias nocapture readonly %"array$sd") local_unnamed_addr #0 !dbg !15 {
+L.entry:
+  call void @llvm.dbg.value(metadata i64* %array, metadata !28, metadata !DIExpression()), !dbg !29
+  call void @llvm.dbg.declare(metadata i64* %"array$sd", metadata !30, metadata !DIExpression()), !dbg !29
+  %0 = getelementptr i64, i64* %"array$sd", i64 11
+  %1 = load i64, i64* %0, align 8
+  call void @llvm.dbg.value(metadata i64 %1, metadata !21, metadata !DIExpression()), !dbg !29
+  %2 = getelementptr i64, i64* %"array$sd", i64 20
+  %3 = load i64, i64* %2, align 8
+  %4 = getelementptr i64, i64* %"array$sd", i64 17
+  %5 = load i64, i64* %4, align 8
+  call void @llvm.dbg.value(metadata i64 %5, metadata !24, metadata !DIExpression()), !dbg !29
+  %6 = getelementptr i64, i64* %"array$sd", i64 7
+  %7 = load i64, i64* %6, align 8
+  %8 = getelementptr i64, i64* %"array$sd", i64 16
+  %9 = load i64, i64* %8, align 8
+  %10 = add nsw i64 %9, -1
+  %11 = mul nsw i64 %10, %3
+  %12 = getelementptr i64, i64* %"array$sd", i64 10
+  %13 = load i64, i64* %12, align 8
+  %14 = add i64 %7, -1
+  %15 = add i64 %14, %13
+  %16 = add i64 %15, %11
+  %17 = icmp slt i64 %1, 1, !dbg !35
+  %18 = icmp slt i64 %5, 1, !dbg !35
+  %19 = or i1 %17, %18, !dbg !35
+  br i1 %19, label %L.LB1_372, label %L.LB1_371.preheader, !dbg !35
+
+L.LB1_371.preheader:  ; preds = %L.entry
+  %20 = bitcast i64* %array to i8*
+  %21 = getelementptr i8, i8* %20, i64 -4
+  %22 = bitcast i8* %21 to i32*
+  br label %L.LB1_371
+
+L.LB1_371:  

[PATCH] D99160: [X86][FastISEL] Support DW_TAG_call_site_parameter with FastISEL

2021-03-23 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1645
 
-  if (Opts.OptimizationLevel > 0 && Opts.hasReducedDebugInfo() &&
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))

djtodoro wrote:
> I think this should be a different patch.
> 
> Are you saying this is useful for some -O0 cases? Can you please provide a 
> test case? Is this related to Fortran only?
Sure. I shall move this in separate patch.

Yes this is useful in -O0 case. the testcase is added with the current patch as 
"callsitepar-fastisel.ll". Though the IR is generated from fortran program 
(mentioned in test case). But I think it is not specific to fortran. Since even 
with -O0 many optimizations work, it is very much possible that parameter gets 
optimized out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99160

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


[PATCH] D99160: [X86][FastISEL] Support DW_TAG_call_site_parameter with FastISEL

2021-03-23 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 332867.
alok added a comment.

Updated to incorporate comments from @djtodoro

- to split out separate patch for clang change.

and fixed clang-format issue.


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

https://reviews.llvm.org/D99160

Files:
  llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
  llvm/lib/Target/X86/X86FastISel.cpp
  llvm/test/CodeGen/X86/call-site-info-output.ll
  llvm/test/DebugInfo/X86/callsitepar-fastisel.ll

Index: llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
@@ -0,0 +1,204 @@
+;; This test checks if DW_TAG_GNU_call_site_parameter is generated for fastIsel.
+; REQUIRES: x86_64-linux
+;RUN: llc -mtriple=x86_64-pc-linux-gnu -emit-call-site-info -fast-isel=true -filetype=obj %s -o - | llvm-dwarfdump - | FileCheck %s
+;CHECK: DW_TAG_GNU_call_site
+;CHECK: DW_AT_abstract_origin
+;CHECK-SAME: "foo"
+;CHECK: DW_AT_low_pc
+;CHECK: DW_TAG_GNU_call_site_parameter
+;CHECK: DW_AT_location (DW_OP_reg4 RSI)
+;CHECK: DW_AT_GNU_call_site_value
+
+;;The IR is generated from below source program
+;
+;;subroutine foo (array)
+;;  integer :: array(:,:)
+;;  array(:,:) = 5
+;;  array(1,1) = 30
+;;end subroutine
+;;
+;;program vla_sub
+;;  interface
+;;subroutine foo (array)
+;;  integer :: array (:,:)
+;;end subroutine
+;;  end interface
+;;
+;;  integer :: sub_arr(42,42)
+;;  sub_arr(:,:) = 1
+;;  call foo(sub_arr)
+;;end program vla_sub
+;
+
+; ModuleID = 'fast.ll'
+source_filename = "/tmp/fast.ll"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.BSS2 = type <{ [7056 x i8] }>
+
+@.BSS2 = internal global %struct.BSS2 zeroinitializer, align 32, !dbg !0
+@.C359_MAIN_ = internal constant i64 42
+@.C333_MAIN_ = internal constant i64 1
+@.C368_MAIN_ = internal constant i64 4
+@.C367_MAIN_ = internal constant i64 25
+@.C331_MAIN_ = internal constant i64 0
+@.C330_MAIN_ = internal constant i32 0
+
+; Function Attrs: nofree norecurse nounwind
+define void @foo_(i64* noalias nocapture %array, i64* noalias nocapture readonly %"array$sd") local_unnamed_addr #0 !dbg !15 {
+L.entry:
+  call void @llvm.dbg.value(metadata i64* %array, metadata !28, metadata !DIExpression()), !dbg !29
+  call void @llvm.dbg.declare(metadata i64* %"array$sd", metadata !30, metadata !DIExpression()), !dbg !29
+  %0 = getelementptr i64, i64* %"array$sd", i64 11
+  %1 = load i64, i64* %0, align 8
+  call void @llvm.dbg.value(metadata i64 %1, metadata !21, metadata !DIExpression()), !dbg !29
+  %2 = getelementptr i64, i64* %"array$sd", i64 20
+  %3 = load i64, i64* %2, align 8
+  %4 = getelementptr i64, i64* %"array$sd", i64 17
+  %5 = load i64, i64* %4, align 8
+  call void @llvm.dbg.value(metadata i64 %5, metadata !24, metadata !DIExpression()), !dbg !29
+  %6 = getelementptr i64, i64* %"array$sd", i64 7
+  %7 = load i64, i64* %6, align 8
+  %8 = getelementptr i64, i64* %"array$sd", i64 16
+  %9 = load i64, i64* %8, align 8
+  %10 = add nsw i64 %9, -1
+  %11 = mul nsw i64 %10, %3
+  %12 = getelementptr i64, i64* %"array$sd", i64 10
+  %13 = load i64, i64* %12, align 8
+  %14 = add i64 %7, -1
+  %15 = add i64 %14, %13
+  %16 = add i64 %15, %11
+  %17 = icmp slt i64 %1, 1, !dbg !35
+  %18 = icmp slt i64 %5, 1, !dbg !35
+  %19 = or i1 %17, %18, !dbg !35
+  br i1 %19, label %L.LB1_372, label %L.LB1_371.preheader, !dbg !35
+
+L.LB1_371.preheader:  ; preds = %L.entry
+  %20 = bitcast i64* %array to i8*
+  %21 = getelementptr i8, i8* %20, i64 -4
+  %22 = bitcast i8* %21 to i32*
+  br label %L.LB1_371
+
+L.LB1_371:; preds = %L.LB1_371.preheader, %L.LB1_426
+  %"i$a_368.0" = phi i64 [ %28, %L.LB1_426 ], [ 1, %L.LB1_371.preheader ], !dbg !35
+  %23 = mul nsw i64 %"i$a_368.0", %3
+  %24 = add i64 %23, %16
+  br label %L.LB1_374
+
+L.LB1_374:; preds = %L.LB1_374, %L.LB1_371
+  %"i$b_369.0" = phi i64 [ 1, %L.LB1_371 ], [ %27, %L.LB1_374 ], !dbg !35
+  %25 = add i64 %24, %"i$b_369.0", !dbg !35
+  %26 = getelementptr i32, i32* %22, i64 %25, !dbg !35
+  store i32 5, i32* %26, align 4, !dbg !35
+  %27 = add nuw i64 %"i$b_369.0", 1, !dbg !35
+  %exitcond.not = icmp eq i64 %"i$b_369.0", %1, !dbg !35
+  br i1 %exitcond.not, label %L.LB1_426, label %L.LB1_374, !dbg !35
+
+L.LB1_426:; preds = %L.LB1_374
+  %28 = add nuw i64 %"i$a_368.0", 1, !dbg !35
+  %exitcond9.not = icmp eq i64 %"i$a_368.0", %5, !dbg !35
+  br i1 %exitcond9.not, label %L.LB1_372, label %L.LB1_371, !dbg !35
+
+L.LB1_372:; preds = %L.LB1_426, %L.entry
+  %29 = add nsw i64 %16, %3, !dbg !36
+  %30 = bitcast i64* %array to i32*, !dbg !36
+  %31 = geteleme

[PATCH] D99238: [DebugInfo] Enable the call site parameter feature by default

2021-03-23 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok created this revision.
alok added reviewers: djtodoro, aprantl, jmorse, SouraVX, jini.susan.george, 
bhuvanendrakumarn.
alok added a project: debug-info.
Herald added subscribers: jansvoboda11, dexonsmith.
alok requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This works with debug entry value feature, which works by default.
Without call site parameter feature, debug entry value feature is of no use.
With current changes, debuggers should be able to show optimized out parameters 
by default.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99238

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Target/TargetOptions.h
  llvm/test/DebugInfo/X86/callsitepar-fastisel.ll


Index: llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
===
--- llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
+++ llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
@@ -9,6 +9,17 @@
 ;CHECK: DW_AT_location (DW_OP_reg4 RSI)
 ;CHECK: DW_AT_GNU_call_site_value
 
+;; This test checks if DW_TAG_GNU_call_site_parameter is generated for option 
-O0
+;RUN: clang -cc1 -triple x86_64-unknown-linux-gnu -emit-obj  -main-file-name 
%s -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -O0 -x ir %s 
-o - | llvm-dwarfdump - | FileCheck %s --check-prefix=CLANG
+
+;CLANG: DW_TAG_GNU_call_site
+;CLANG: DW_AT_abstract_origin
+;CLANG-SAME: "foo"
+;CLANG: DW_AT_low_pc
+;CLANG: DW_TAG_GNU_call_site_parameter
+;CLANG: DW_AT_location (DW_OP_reg4 RSI)
+;CLANG: DW_AT_GNU_call_site_value
+
 ;;The IR is generated from below source program
 ;
 ;;subroutine foo (array)
Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -302,8 +302,8 @@
 std::shared_ptr BBSectionsFuncListBuf;
 
 /// The flag enables call site info production. It is used only for debug
-/// info, and it is restricted only to optimized code. This can be used for
-/// something else, so that should be controlled in the frontend.
+/// info. This can be used for something else, so that should be controlled
+/// in the frontend.
 unsigned EmitCallSiteInfo : 1;
 /// Set if the target supports the debug entry values by default.
 unsigned SupportsDebugEntryValues : 1;
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1642,7 +1642,7 @@
   llvm::Triple::arm, llvm::Triple::armeb, llvm::Triple::mips,
   llvm::Triple::mipsel, llvm::Triple::mips64, llvm::Triple::mips64el};
 
-  if (Opts.OptimizationLevel > 0 && Opts.hasReducedDebugInfo() &&
+  if (Opts.hasReducedDebugInfo() &&
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -68,8 +68,7 @@
 CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
///< pass manager.
 CODEGENOPT(DisableRedZone, 1, 0) ///< Set when -mno-red-zone is enabled.
-CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of
-   ///< '-g' + 'O>0' level.
+CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info.
 CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs
  ///< is specified.
 CODEGENOPT(DisableTailCalls  , 1, 0) ///< Do not emit tail calls.


Index: llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
===
--- llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
+++ llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
@@ -9,6 +9,17 @@
 ;CHECK: DW_AT_location (DW_OP_reg4 RSI)
 ;CHECK: DW_AT_GNU_call_site_value
 
+;; This test checks if DW_TAG_GNU_call_site_parameter is generated for option -O0
+;RUN: clang -cc1 -triple x86_64-unknown-linux-gnu -emit-obj  -main-file-name %s -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -O0 -x ir %s -o - | llvm-dwarfdump - | FileCheck %s --check-prefix=CLANG
+
+;CLANG: DW_TAG_GNU_call_site
+;CLANG: DW_AT_abstract_origin
+;CLANG-SAME: "foo"
+;CLANG: DW_AT_low_pc
+;CLANG: DW_TAG_GNU_call_site_parameter
+;CLANG: DW_AT_location (DW_OP_reg4 RSI)
+;CLANG: DW_AT_GNU_call_site_value
+
 ;;The IR is generated from below source program
 ;
 ;;subroutine foo (array)
Index: llvm/include/llvm/Target/TargetOptions.h

[PATCH] D99238: [DebugInfo] Enable the call site parameter feature by default

2021-03-23 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 332870.
alok added a comment.

Re-based after setting the parent patch.


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

https://reviews.llvm.org/D99238

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Target/TargetOptions.h
  llvm/test/DebugInfo/X86/callsitepar-fastisel.ll


Index: llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
===
--- llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
+++ llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
@@ -9,6 +9,17 @@
 ;CHECK: DW_AT_location (DW_OP_reg4 RSI)
 ;CHECK: DW_AT_GNU_call_site_value
 
+;; This test checks if DW_TAG_GNU_call_site_parameter is generated for option 
-O0
+;RUN: clang -cc1 -triple x86_64-unknown-linux-gnu -emit-obj  -main-file-name 
%s -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -O0 -x ir %s 
-o - | llvm-dwarfdump - | FileCheck %s --check-prefix=CLANG
+
+;CLANG: DW_TAG_GNU_call_site
+;CLANG: DW_AT_abstract_origin
+;CLANG-SAME: "foo"
+;CLANG: DW_AT_low_pc
+;CLANG: DW_TAG_GNU_call_site_parameter
+;CLANG: DW_AT_location (DW_OP_reg4 RSI)
+;CLANG: DW_AT_GNU_call_site_value
+
 ;;The IR is generated from below source program
 ;
 ;;subroutine foo (array)
Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -302,8 +302,8 @@
 std::shared_ptr BBSectionsFuncListBuf;
 
 /// The flag enables call site info production. It is used only for debug
-/// info, and it is restricted only to optimized code. This can be used for
-/// something else, so that should be controlled in the frontend.
+/// info. This can be used for something else, so that should be controlled
+/// in the frontend.
 unsigned EmitCallSiteInfo : 1;
 /// Set if the target supports the debug entry values by default.
 unsigned SupportsDebugEntryValues : 1;
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1642,7 +1642,7 @@
   llvm::Triple::arm, llvm::Triple::armeb, llvm::Triple::mips,
   llvm::Triple::mipsel, llvm::Triple::mips64, llvm::Triple::mips64el};
 
-  if (Opts.OptimizationLevel > 0 && Opts.hasReducedDebugInfo() &&
+  if (Opts.hasReducedDebugInfo() &&
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -68,8 +68,7 @@
 CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
///< pass manager.
 CODEGENOPT(DisableRedZone, 1, 0) ///< Set when -mno-red-zone is enabled.
-CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of
-   ///< '-g' + 'O>0' level.
+CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info.
 CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs
  ///< is specified.
 CODEGENOPT(DisableTailCalls  , 1, 0) ///< Do not emit tail calls.


Index: llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
===
--- llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
+++ llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
@@ -9,6 +9,17 @@
 ;CHECK: DW_AT_location (DW_OP_reg4 RSI)
 ;CHECK: DW_AT_GNU_call_site_value
 
+;; This test checks if DW_TAG_GNU_call_site_parameter is generated for option -O0
+;RUN: clang -cc1 -triple x86_64-unknown-linux-gnu -emit-obj  -main-file-name %s -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -O0 -x ir %s -o - | llvm-dwarfdump - | FileCheck %s --check-prefix=CLANG
+
+;CLANG: DW_TAG_GNU_call_site
+;CLANG: DW_AT_abstract_origin
+;CLANG-SAME: "foo"
+;CLANG: DW_AT_low_pc
+;CLANG: DW_TAG_GNU_call_site_parameter
+;CLANG: DW_AT_location (DW_OP_reg4 RSI)
+;CLANG: DW_AT_GNU_call_site_value
+
 ;;The IR is generated from below source program
 ;
 ;;subroutine foo (array)
Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -302,8 +302,8 @@
 std::shared_ptr BBSectionsFuncListBuf;
 
 /// The flag enables call site info production. It is used only for debug
-/// info, and it is restricted only to optimized code. This can be used for
-/// something else, so that should be controlled in th

[PATCH] D99160: [X86][FastISEL] Support DW_TAG_call_site_parameter with FastISEL

2021-04-01 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 334636.
alok added a comment.

Re-based and minor changes.


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

https://reviews.llvm.org/D99160

Files:
  llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
  llvm/lib/Target/X86/X86FastISel.cpp
  llvm/test/CodeGen/X86/call-site-info-output.ll
  llvm/test/DebugInfo/X86/callsitepar-fastisel.ll

Index: llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
@@ -0,0 +1,200 @@
+;; This test checks if DW_TAG_GNU_call_site_parameter is generated for fastIsel.
+; REQUIRES: x86_64-linux
+;RUN: llc -mtriple=x86_64-pc-linux-gnu -emit-call-site-info -fast-isel=true -filetype=obj %s -o - | llvm-dwarfdump - | FileCheck %s
+;CHECK: DW_TAG_GNU_call_site
+;CHECK: DW_AT_abstract_origin
+;CHECK-SAME: "foo"
+;CHECK: DW_AT_low_pc
+;CHECK: DW_TAG_GNU_call_site_parameter
+;CHECK: DW_AT_location (DW_OP_reg4 RSI)
+;CHECK: DW_AT_GNU_call_site_value
+
+;;The IR is generated from below source program
+;
+;;subroutine foo (array)
+;;  integer :: array(:,:)
+;;  array(:,:) = 5
+;;  array(1,1) = 30
+;;end subroutine
+;;
+;;program vla_sub
+;;  interface
+;;subroutine foo (array)
+;;  integer :: array (:,:)
+;;end subroutine
+;;  end interface
+;;
+;;  integer :: sub_arr(42,42)
+;;  sub_arr(:,:) = 1
+;;  call foo(sub_arr)
+;;end program vla_sub
+;
+
+; ModuleID = 'fast.ll'
+source_filename = "/tmp/fast.ll"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.BSS2 = type <{ [7056 x i8] }>
+
+@.BSS2 = internal global %struct.BSS2 zeroinitializer, align 32, !dbg !0
+@.C359_MAIN_ = internal constant i64 42
+@.C333_MAIN_ = internal constant i64 1
+@.C368_MAIN_ = internal constant i64 4
+@.C367_MAIN_ = internal constant i64 25
+@.C331_MAIN_ = internal constant i64 0
+@.C330_MAIN_ = internal constant i32 0
+
+; Function Attrs: nofree norecurse nounwind
+define void @foo_(i64* noalias nocapture %array, i64* noalias nocapture readonly %"array$sd") local_unnamed_addr !dbg !15 {
+L.entry:
+  call void @llvm.dbg.value(metadata i64* %array, metadata !28, metadata !DIExpression()), !dbg !29
+  call void @llvm.dbg.declare(metadata i64* %"array$sd", metadata !30, metadata !DIExpression()), !dbg !29
+  %0 = getelementptr i64, i64* %"array$sd", i64 11
+  %1 = load i64, i64* %0, align 8
+  call void @llvm.dbg.value(metadata i64 %1, metadata !21, metadata !DIExpression()), !dbg !29
+  %2 = getelementptr i64, i64* %"array$sd", i64 20
+  %3 = load i64, i64* %2, align 8
+  %4 = getelementptr i64, i64* %"array$sd", i64 17
+  %5 = load i64, i64* %4, align 8
+  call void @llvm.dbg.value(metadata i64 %5, metadata !24, metadata !DIExpression()), !dbg !29
+  %6 = getelementptr i64, i64* %"array$sd", i64 7
+  %7 = load i64, i64* %6, align 8
+  %8 = getelementptr i64, i64* %"array$sd", i64 16
+  %9 = load i64, i64* %8, align 8
+  %10 = add nsw i64 %9, -1
+  %11 = mul nsw i64 %10, %3
+  %12 = getelementptr i64, i64* %"array$sd", i64 10
+  %13 = load i64, i64* %12, align 8
+  %14 = add i64 %7, -1
+  %15 = add i64 %14, %13
+  %16 = add i64 %15, %11
+  %17 = icmp slt i64 %1, 1, !dbg !35
+  %18 = icmp slt i64 %5, 1, !dbg !35
+  %19 = or i1 %17, %18, !dbg !35
+  br i1 %19, label %L.LB1_372, label %L.LB1_371.preheader, !dbg !35
+
+L.LB1_371.preheader:  ; preds = %L.entry
+  %20 = bitcast i64* %array to i8*
+  %21 = getelementptr i8, i8* %20, i64 -4
+  %22 = bitcast i8* %21 to i32*
+  br label %L.LB1_371
+
+L.LB1_371:; preds = %L.LB1_371.preheader, %L.LB1_426
+  %"i$a_368.0" = phi i64 [ %28, %L.LB1_426 ], [ 1, %L.LB1_371.preheader ], !dbg !35
+  %23 = mul nsw i64 %"i$a_368.0", %3
+  %24 = add i64 %23, %16
+  br label %L.LB1_374
+
+L.LB1_374:; preds = %L.LB1_374, %L.LB1_371
+  %"i$b_369.0" = phi i64 [ 1, %L.LB1_371 ], [ %27, %L.LB1_374 ], !dbg !35
+  %25 = add i64 %24, %"i$b_369.0", !dbg !35
+  %26 = getelementptr i32, i32* %22, i64 %25, !dbg !35
+  store i32 5, i32* %26, align 4, !dbg !35
+  %27 = add nuw i64 %"i$b_369.0", 1, !dbg !35
+  %exitcond.not = icmp eq i64 %"i$b_369.0", %1, !dbg !35
+  br i1 %exitcond.not, label %L.LB1_426, label %L.LB1_374, !dbg !35
+
+L.LB1_426:; preds = %L.LB1_374
+  %28 = add nuw i64 %"i$a_368.0", 1, !dbg !35
+  %exitcond9.not = icmp eq i64 %"i$a_368.0", %5, !dbg !35
+  br i1 %exitcond9.not, label %L.LB1_372, label %L.LB1_371, !dbg !35
+
+L.LB1_372:; preds = %L.LB1_426, %L.entry
+  %29 = add nsw i64 %16, %3, !dbg !36
+  %30 = bitcast i64* %array to i32*, !dbg !36
+  %31 = getelementptr i32, i32* %30, i64 %29, !dbg !36
+  store i32 30, i32* %31, align 4, !dbg !36
+  ret void, !dbg 

[PATCH] D99238: [DebugInfo] Enable the call site parameter feature by default

2021-04-01 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1645
 
-  if (Opts.OptimizationLevel > 0 && Opts.hasReducedDebugInfo() &&
+  if (Opts.hasReducedDebugInfo() &&
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))

djtodoro wrote:
> I am a bit confused now :)
> Is `flang` using this clang's library?
> I think we should be careful here, since I am not sure C/C++ -O0 code has any 
> benefits of using this, but the DWARF size might be increased insanely.
Classic flang calls same library. Below is the verbose output of "flang" 
command.
**flang** -g -O0 -v vla-sub.f90
 "/tmp/bin/**flang1**" vla-sub.f90 -x 47 0x1000 -opt 0 -terse 1 -inform 
warn -nohpf -nostatic -cmdline "'+flang -g -O0 -v vla-sub.f90'" -inform warn 
-disable-vectorize-pragmas -x 120 0x100 -debug -y 129 2 -x 19 0x40 
-quad -x 7 0x10 -x 68 0x1 -x 59 4 -x 15 2 -x 49 0x44 -x 51 0x20 -x 57 
0x48 -x 58 0x1 -x 124 0x1000 -tp px -x 57 0xfb -x 58 0x78031040 -x 47 
0x08 -x 48 4608 -x 49 0x100 -stdinc 
/tmp/bin/../include:/usr/local/include:/tmp/d/lib/clang/13.0.0/include:/usr/include/x86_64-linux-gnu:/include:/usr/include
 -def unix -def __unix -def __unix__ -def linux -def __linux -def __linux__ 
-def __NO_MATH_INLINES -def __LP64__ -def __LONG_MAX__=9223372036854775807L 
-def "__SIZE_TYPE__=unsigned long int" -def "__PTRDIFF_TYPE__=long int" -def 
__x86_64 -def __x86_64__ -def __amd_64__amd64__ -def __k8 -def __k8__ -def 
__THROW= -def __extension__= -def __PGLLVM__ -freeform -vect 48 -x 54 1 -x 70 
0x4000 -y 163 0xc000 -x 189 0x10 -stbfile vla-sub-051e06.stb -modexport 
vla-sub-051e06.cmod -modindex vla-sub-051e06.cmdx -output vla-sub-051e06.ilm
 "/tmp/bin/**flang2**" vla-sub-051e06.ilm -y 129 2 -x 6 0x100 -x 42 0x40 -y 
129 4 -x 129 0x400 -y 216 1 -ieee 1 -fn vla-sub.f90 -opt 0 -terse 1 -inform 
warn -cmdline "'+flang -g -O0 -v vla-sub.f90'" -inform warn 
-disable-vectorize-pragmas -x 120 0x100 -debug -y 129 2 -x 68 0x1 -x 51 
0x20 -x 119 0xa1 -x 122 0x40 -x 123 0x1000 -x 127 4 -x 127 17 -x 19 
0x40 -x 28 0x4 -x 120 0x1000 -x 70 0x8000 -x 122 1 -x 125 0x2 
-x 164 0x80 -quad -x 59 4 -tp px -x 120 0x1000 -x 124 0x1400 -y 15 2 -x 57 
0x3b -x 58 0x4800 -x 49 0x100 -astype 0 -x 183 4 -x 121 0x800 -x 54 
0x10 -x 70 0x4000 -x 249 1023 -x 124 1 -y 163 0xc000 -x 189 0x10 -y 189 
0x400 -x 183 0x10 -stbfile vla-sub-051e06.stb -asm /tmp/vla-sub-051e06.ll
 "/tmp/bin/**clang-12**" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj 
-mrelax-all --mrelax-relocations -disable-free -main-file-name vla-sub.f90 
-mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math 
-mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic 
-debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -v 
-fcoverage-compilation-dir=/tmp/build.shared.d -resource-dir 
/tmp/lib/clang/13.0.0 -O0 -fdebug-compilation-dir=/tmp/build.shared.d 
-ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -itodcalls 
-itodcallsbyclone -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o 
/tmp/vla-sub-cdf94f.o -x ir /tmp/vla-sub-051e06.ll
clang -cc1 version 13.0.0 based upon LLVM 13.0.0git default target 
x86_64-unknown-linux-gnu
 "/tmp/bin/**ld.lld**" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 
-dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out 
/usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o 
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/crtbegin.o 
-L/usr/lib/gcc/x86_64-linux-gnu/7.5.0 -L/lib/x86_64-linux-gnu -L/lib/../lib64 
-L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../.. 
-L/home/alok/amdllvm/install/d/bin/../lib -L/lib -L/usr/lib 
/tmp/vla-sub-cdf94f.o -lflangmain -lflang -lflangrti -lpgmath -lquadmath 
-lompstub -lm -lrt -lpthread -rpath /tmp/bin/../lib -lgcc --as-needed -lgcc_s 
--no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed 
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/crtend.o /usr/lib/x86_64-linux-gnu/crtn.o


Yes, I agree. I think there should be cases when even in C/C++ code this will 
be beneficial but not sure how frequent it shall be. We need to think about 
trade-off. Do you think it should be enabled only for Fortran or a command line 
option should be introduced to enable this otherwise it should disabled by 
default ? 



Comment at: llvm/test/DebugInfo/X86/callsitepar-fastisel.ll:12
 
+;; This test checks if DW_TAG_GNU_call_site_parameter is generated for option 
-O0
+;RUN: clang -cc1 -triple x86_64-unknown-linux-gnu -emit-obj  -main-file-name 
%s -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -O0 -x ir %s 
-o - | llvm-dwarfdump - | FileCheck %s --check-prefix=CLANG

djtodoro wrote:
> I don't think this should be tested this way. We should be testing `Driver` 
> itself.
Sure, I shall remove this test from here.


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

https://revi

[PATCH] D99238: [DebugInfo] Enable the call site parameter feature by default

2021-04-01 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 334642.
alok added a comment.

Updated to address comments from @djtodoro


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

https://reviews.llvm.org/D99238

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Target/TargetOptions.h


Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -303,8 +303,8 @@
 std::shared_ptr BBSectionsFuncListBuf;
 
 /// The flag enables call site info production. It is used only for debug
-/// info, and it is restricted only to optimized code. This can be used for
-/// something else, so that should be controlled in the frontend.
+/// info. This can be used for something else, so that should be controlled
+/// in the frontend.
 unsigned EmitCallSiteInfo : 1;
 /// Set if the target supports the debug entry values by default.
 unsigned SupportsDebugEntryValues : 1;
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1645,7 +1645,7 @@
   llvm::Triple::arm, llvm::Triple::armeb, llvm::Triple::mips,
   llvm::Triple::mipsel, llvm::Triple::mips64, llvm::Triple::mips64el};
 
-  if (Opts.OptimizationLevel > 0 && Opts.hasReducedDebugInfo() &&
+  if (Opts.hasReducedDebugInfo() &&
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -68,8 +68,7 @@
 CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
///< pass manager.
 CODEGENOPT(DisableRedZone, 1, 0) ///< Set when -mno-red-zone is enabled.
-CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of
-   ///< '-g' + 'O>0' level.
+CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info.
 CODEGENOPT(EnableDIPreservationVerify, 1, 0) ///< Enable di preservation verify
  ///< each (it means check
  ///< the original debug info


Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -303,8 +303,8 @@
 std::shared_ptr BBSectionsFuncListBuf;
 
 /// The flag enables call site info production. It is used only for debug
-/// info, and it is restricted only to optimized code. This can be used for
-/// something else, so that should be controlled in the frontend.
+/// info. This can be used for something else, so that should be controlled
+/// in the frontend.
 unsigned EmitCallSiteInfo : 1;
 /// Set if the target supports the debug entry values by default.
 unsigned SupportsDebugEntryValues : 1;
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1645,7 +1645,7 @@
   llvm::Triple::arm, llvm::Triple::armeb, llvm::Triple::mips,
   llvm::Triple::mipsel, llvm::Triple::mips64, llvm::Triple::mips64el};
 
-  if (Opts.OptimizationLevel > 0 && Opts.hasReducedDebugInfo() &&
+  if (Opts.hasReducedDebugInfo() &&
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -68,8 +68,7 @@
 CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
///< pass manager.
 CODEGENOPT(DisableRedZone, 1, 0) ///< Set when -mno-red-zone is enabled.
-CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of
-   ///< '-g' + 'O>0' level.
+CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info.
 CODEGENOPT(EnableDIPreservationVerify, 1, 0) ///< Enable di preservation verify
  ///< each (it means check
  ///< the original debug info
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99160: [X86][FastISEL] Support DW_TAG_call_site_parameter with FastISEL

2021-04-02 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok updated this revision to Diff 334931.
alok added a comment.

Updated testcase to use option "-O0", earlier default option was being used 
instead.


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

https://reviews.llvm.org/D99160

Files:
  llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
  llvm/lib/Target/X86/X86FastISel.cpp
  llvm/test/CodeGen/X86/call-site-info-output.ll
  llvm/test/DebugInfo/X86/callsitepar-fastisel.ll

Index: llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/callsitepar-fastisel.ll
@@ -0,0 +1,317 @@
+;; This test checks if DW_TAG_GNU_call_site_parameter is generated for fastIsel.
+; REQUIRES: x86_64-linux
+;RUN: llc -O0 -mtriple=x86_64-pc-linux-gnu -emit-call-site-info -filetype=obj %s -o - | llvm-dwarfdump - | FileCheck %s
+
+;; This should be genenerated now.
+;CHECK: DW_TAG_GNU_call_site
+;CHECK: DW_AT_abstract_origin
+;CHECK-SAME: "foo"
+;CHECK: DW_AT_low_pc
+;CHECK: DW_TAG_GNU_call_site_parameter
+;CHECK: DW_AT_location (DW_OP_reg4 RSI)
+;CHECK: DW_AT_GNU_call_site_value
+
+;; This was already being generated.
+;CHECK: DW_OP_GNU_entry_value
+
+;;The IR is generated from below source program
+;
+;;subroutine foo (array)
+;;  integer :: array(:,:)
+;;  array(:,:) = 5
+;;  array(1,1) = 30
+;;end subroutine
+;;
+;;program vla_sub
+;;  interface
+;;subroutine foo (array)
+;;  integer :: array (:,:)
+;;end subroutine
+;;  end interface
+;;
+;;  integer :: sub_arr(42,42)
+;;  sub_arr(:,:) = 1
+;;  call foo(sub_arr)
+;;end program vla_sub
+;
+
+; ModuleID = 'fast.ll'
+source_filename = "/tmp/fast.ll"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.BSS2 = type <{ [7056 x i8] }>
+
+@.BSS2 = internal global %struct.BSS2 zeroinitializer, align 32, !dbg !0
+@.C359_MAIN_ = internal constant i64 42
+@.C333_MAIN_ = internal constant i64 1
+@.C368_MAIN_ = internal constant i64 4
+@.C367_MAIN_ = internal constant i64 25
+@.C331_MAIN_ = internal constant i64 0
+@.C330_MAIN_ = internal constant i32 0
+
+define void @foo_(i64* noalias %array, i64* noalias %"array$sd") !dbg !15 {
+L.entry:
+  %z_b_1_350 = alloca i64, align 8
+  %z_b_2_351 = alloca i64, align 8
+  %z_b_4_352 = alloca i64, align 8
+  %z_b_6_354 = alloca i64, align 8
+  %.dY0001_373 = alloca i64, align 8
+  %"i$a_368" = alloca i64, align 8
+  %.dY0002_376 = alloca i64, align 8
+  %"i$b_369" = alloca i64, align 8
+  call void @llvm.dbg.value(metadata i64* %array, metadata !28, metadata !DIExpression()), !dbg !29
+  call void @llvm.dbg.declare(metadata i64* %"array$sd", metadata !30, metadata !DIExpression()), !dbg !29
+  %0 = bitcast i64* %"array$sd" to i8*
+  %1 = getelementptr i8, i8* %0, i64 88
+  %2 = bitcast i8* %1 to i64*
+  %3 = load i64, i64* %2, align 8
+  call void @llvm.dbg.declare(metadata i64* %z_b_1_350, metadata !21, metadata !DIExpression()), !dbg !29
+  store i64 %3, i64* %z_b_1_350, align 8
+  %4 = bitcast i64* %"array$sd" to i8*
+  %5 = getelementptr i8, i8* %4, i64 160
+  %6 = bitcast i8* %5 to i64*
+  %7 = load i64, i64* %6, align 8
+  call void @llvm.dbg.declare(metadata i64* %z_b_2_351, metadata !35, metadata !DIExpression()), !dbg !29
+  store i64 %7, i64* %z_b_2_351, align 8
+  %8 = bitcast i64* %"array$sd" to i8*
+  %9 = getelementptr i8, i8* %8, i64 136
+  %10 = bitcast i8* %9 to i64*
+  %11 = load i64, i64* %10, align 8
+  call void @llvm.dbg.declare(metadata i64* %z_b_4_352, metadata !24, metadata !DIExpression()), !dbg !29
+  store i64 %11, i64* %z_b_4_352, align 8
+  %12 = bitcast i64* %"array$sd" to i8*
+  %13 = getelementptr i8, i8* %12, i64 56
+  %14 = bitcast i8* %13 to i64*
+  %15 = load i64, i64* %14, align 8
+  %16 = bitcast i64* %"array$sd" to i8*
+  %17 = getelementptr i8, i8* %16, i64 160
+  %18 = bitcast i8* %17 to i64*
+  %19 = load i64, i64* %18, align 8
+  %20 = bitcast i64* %"array$sd" to i8*
+  %21 = getelementptr i8, i8* %20, i64 128
+  %22 = bitcast i8* %21 to i64*
+  %23 = load i64, i64* %22, align 8
+  %24 = sub nsw i64 %23, 1
+  %25 = mul nsw i64 %19, %24
+  %26 = bitcast i64* %"array$sd" to i8*
+  %27 = getelementptr i8, i8* %26, i64 80
+  %28 = bitcast i8* %27 to i64*
+  %29 = load i64, i64* %28, align 8
+  %30 = sub nsw i64 %29, 1
+  %31 = add nsw i64 %25, %30
+  %32 = add nsw i64 %15, %31
+  call void @llvm.dbg.declare(metadata i64* %z_b_6_354, metadata !36, metadata !DIExpression()), !dbg !29
+  store i64 %32, i64* %z_b_6_354, align 8
+  %33 = load i64, i64* %z_b_4_352, align 8, !dbg !37
+  call void @llvm.dbg.declare(metadata i64* %z_b_4_352, metadata !38, metadata !DIExpression()), !dbg !29
+  store i64 %33, i64* %.dY0001_373, align 8, !dbg !37
+  call void @llvm.dbg.declare(metadata i64* %"i$a_368", metadata !39, metadata !DIExpression()), !dbg !29
+  store i64 1, i64* %"i$a_368", alig

[PATCH] D99160: [X86][FastISEL] Support DW_TAG_call_site_parameter with FastISEL

2021-04-02 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok added a comment.

In D99160#2665580 , @probinson wrote:

> FastISel is normally used only at -O0, I wouldn't expect any parameters to be 
> optimized out at -O0.
> The test is running llc with default optimization, which is -O2, and forcing 
> fast-isel; this is not a usual combination and I wouldn't expect us to spend 
> any effort making sure debug info works well with that combination.
>
> If flang is forcing fast-isel even with optimization, that sounds like a 
> problem for flang to solve, not LLVM.

Thanks for your comments. I am sorry as the earlier used options in test case 
were more confusing than helpful. I have changed that now.
The updated testcase at "-O0" with FastISel does have optimized out parameter, 
this is because generation of "DW_OP_GNU_entry_value" is enabled starting from 
"-O0". This causes llvm to generate it whenever it gets opportunity (more local 
variables to preserve may be the reason). 
The concern here is only DW_OP_GNU_entry_value is not sufficient and should be 
supported with "DW_TAG_GNU_call_site_parameter", which I tried in current patch.


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

https://reviews.llvm.org/D99160

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


[PATCH] D99160: [X86][FastISEL] Support DW_TAG_call_site_parameter with FastISEL

2021-04-02 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok added a comment.

In D99160#2666068 , @djtodoro wrote:

> In D99160#2666066 , @alok wrote:
>
>> In D99160#2665580 , @probinson 
>> wrote:
>>
>>> FastISel is normally used only at -O0, I wouldn't expect any parameters to 
>>> be optimized out at -O0.
>>> The test is running llc with default optimization, which is -O2, and 
>>> forcing fast-isel; this is not a usual combination and I wouldn't expect us 
>>> to spend any effort making sure debug info works well with that combination.
>>>
>>> If flang is forcing fast-isel even with optimization, that sounds like a 
>>> problem for flang to solve, not LLVM.
>>
>> Thanks for your comments. I am sorry as the earlier used options in test 
>> case were more confusing than helpful. I have changed that now.
>> The updated testcase at "-O0" with FastISel does have optimized out 
>> parameter, this is because generation of "DW_OP_GNU_entry_value" is enabled 
>> starting from "-O0". This causes llvm to generate it whenever it gets 
>> opportunity (more local variables to preserve may be the reason). 
>> The concern here is only DW_OP_GNU_entry_value is not sufficient and should 
>> be supported with "DW_TAG_GNU_call_site_parameter", which I tried in current 
>> patch.
>
>
>
>> "DW_OP_GNU_entry_value" is enabled starting from "-O0".
>
> I am wondering if this is true...

You can try with testcase attached with this patch.

bash$ llc -O0 -filetype=obj llvm/test/DebugInfo/X86/callsitepar-fastisel.ll -o 
callsitepar-fastisel.o
bash$ llvm-dwarfdump callsitepar-fastisel.o | grep DW_OP_GNU_entry_value

  [0x00bf, 0x0101): DW_OP_GNU_entry_value(DW_OP_reg4 
RSI))


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

https://reviews.llvm.org/D99160

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


[PATCH] D99238: [DebugInfo] Enable the call site parameter feature by default

2021-04-02 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok marked 2 inline comments as done.
alok added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1648
 
-  if (Opts.OptimizationLevel > 0 && Opts.hasReducedDebugInfo() &&
+  if (Opts.hasReducedDebugInfo() &&
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))

dblaikie wrote:
> probinson wrote:
> > I think we don't want this enabled by default at -O0.  It doesn't run any 
> > optimizations that should eliminate parameters, so this is going to 
> > increase debug info size for no real benefit to the debugging experience.
> +1 to @probinson here. That's generally been the thinking behind why this was 
> only enabled when optimizations are enabled. (there's some minor tradeoff 
> here: call site descriptions in unoptimized code can still be useful if they 
> call into optimized code, so this is a bit heuristical - assuming that all 
> code will be compiled with the same optimization level)
> 
> If flang is in a different situation and enables some optimizations at -O0 
> that make call site parameter descriptions beneficial even there, then maybe 
> we'll need some different way to differentiate optimizations V no 
> optimizations for the purpose of this feature.
Thanks Paul for the comment. I shall probably add an option to enable in such 
cases which should remain off by default, Flang driver can pass that to 
compiler to turn it on.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1648
 
-  if (Opts.OptimizationLevel > 0 && Opts.hasReducedDebugInfo() &&
+  if (Opts.hasReducedDebugInfo() &&
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))

alok wrote:
> dblaikie wrote:
> > probinson wrote:
> > > I think we don't want this enabled by default at -O0.  It doesn't run any 
> > > optimizations that should eliminate parameters, so this is going to 
> > > increase debug info size for no real benefit to the debugging experience.
> > +1 to @probinson here. That's generally been the thinking behind why this 
> > was only enabled when optimizations are enabled. (there's some minor 
> > tradeoff here: call site descriptions in unoptimized code can still be 
> > useful if they call into optimized code, so this is a bit heuristical - 
> > assuming that all code will be compiled with the same optimization level)
> > 
> > If flang is in a different situation and enables some optimizations at -O0 
> > that make call site parameter descriptions beneficial even there, then 
> > maybe we'll need some different way to differentiate optimizations V no 
> > optimizations for the purpose of this feature.
> Thanks Paul for the comment. I shall probably add an option to enable in such 
> cases which should remain off by default, Flang driver can pass that to 
> compiler to turn it on.
Thanks David for your explanation and thoughts. Please also look at trigger to 
this https://reviews.llvm.org/D99160

It is needed in a Fortran case. I shall probably drop to enable it by default 
and add an option which by default is disabled and Fortran driver can pass that 
to make use of it.


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

https://reviews.llvm.org/D99238

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


[PATCH] D99238: [DebugInfo] Enable the call site parameter feature by default

2021-04-02 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok marked an inline comment as done.
alok added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1648
 
-  if (Opts.OptimizationLevel > 0 && Opts.hasReducedDebugInfo() &&
+  if (Opts.hasReducedDebugInfo() &&
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))

dblaikie wrote:
> alok wrote:
> > alok wrote:
> > > dblaikie wrote:
> > > > probinson wrote:
> > > > > I think we don't want this enabled by default at -O0.  It doesn't run 
> > > > > any optimizations that should eliminate parameters, so this is going 
> > > > > to increase debug info size for no real benefit to the debugging 
> > > > > experience.
> > > > +1 to @probinson here. That's generally been the thinking behind why 
> > > > this was only enabled when optimizations are enabled. (there's some 
> > > > minor tradeoff here: call site descriptions in unoptimized code can 
> > > > still be useful if they call into optimized code, so this is a bit 
> > > > heuristical - assuming that all code will be compiled with the same 
> > > > optimization level)
> > > > 
> > > > If flang is in a different situation and enables some optimizations at 
> > > > -O0 that make call site parameter descriptions beneficial even there, 
> > > > then maybe we'll need some different way to differentiate optimizations 
> > > > V no optimizations for the purpose of this feature.
> > > Thanks Paul for the comment. I shall probably add an option to enable in 
> > > such cases which should remain off by default, Flang driver can pass that 
> > > to compiler to turn it on.
> > Thanks David for your explanation and thoughts. Please also look at trigger 
> > to this https://reviews.llvm.org/D99160
> > 
> > It is needed in a Fortran case. I shall probably drop to enable it by 
> > default and add an option which by default is disabled and Fortran driver 
> > can pass that to make use of it.
> Sounds like @djtodoro is suggesting in 
> https://reviews.llvm.org/D99160#2666106 that the "Bug" to fix here is the 
> presence of DW_OP_call_value at -O0, it seems that could be an issue for the 
> existing/original use of call_site_parameter/call_value (in C++/clang) as it 
> would be for flang - so the fix should probably not be flang-specific if the 
> issue isn't flang-specific. Understanding why we produce DW_OP_call_values at 
> -O0, whether we can/should avoid that, what it costs (how much larger the 
> debug info gets by adding DW_TAG_call_sites at -O0) would be necessary to 
> determine the right path forward here.
Thanks David for clarification. I shall look at it and get back.


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

https://reviews.llvm.org/D99238

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


[PATCH] D99160: [X86][FastISEL] Support DW_TAG_call_site_parameter with FastISEL

2021-04-19 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok added a comment.

In D99160#2671899 , @dblaikie wrote:

> In D99160#2670460 , @djtodoro wrote:
>
>> In D99160#2669576 , @dblaikie wrote:
>>
>>> In D99160#2668977 , @djtodoro 
>>> wrote:
>>>
 I think that the Debug Entry Values feature should not be enabled by 
 default for non optimized code, so the 
 `TargetOptions::ShouldEmitDebugEntryValues()` should be patched with 
 checking of optimization level (it should be > 0).
>>>
>>> That's currently intended to be already handled by the frontend, right? 
>>> (clang only sets `EnableDebugEntryValues` (which 
>>> `ShouldEmitDebugEntryValues` checks (hmm, it checks under 'or', not 'and', 
>>> so I'm not sure where the "only above -O0" is implemented, but it is 
>>> implemented somewhere?) if optimizations are enabled, yeah?)
>>>
>>> Oh, is entry_values actually not conditionalized? It's only the call_site 
>>> support that's currently conditionalized on "above -O0"?
>>
>> Looks like there is no explicit check of optimization level (above "-O0"), 
>> neither on frontend nor backend for entry-values generation. I think it is 
>> the situation since there should not be any optimization (at least that I am 
>> aware of, in the case of C/C++) that would cause the entry-values 
>> generation...
>>
>>> Hmm - If that's the case, and we currently have some cases where 
>>> entry_values are emitted at -O0, I'm not sure /not/ emitting those is the 
>>> right call either. If we believe/have data to show that there are so few 
>>> useful uses of entry_value at -O0 that it's not worth the DWARF size growth 
>>> to put call_sites in at -O0, then I think it might still be worth leaving 
>>> the entry_values in (unless they take up a bunch of extra space) for the 
>>> cases of mixed optimization compilation (-O0 some code you're debugging, 
>>> but building the rest with optimizations).
>>
>> Yeah... That is valuable example... I am thinking in that direction as well, 
>> and I am closer to the enabling it for -O0 case if that is useful (and there 
>> is no dramatic cost in terms of DWARF size).
>
> Does anyone have this example (where DW_OP_entry_value is used at -O0)? It'd 
> be great to look at it & see if it's a case of unnecessarily losing the 
> location, or legitimately losing it and using entry_value for best-effort 
> recovery (& then a question of whether the loss is appropriate at -O0, or if 
> we want to pessimize -O0 further to avoid the loss).
>
> I'd worry about turning on call_sites at -O0 - there'd be a lot more calls 
> (especially for C++ code with lots of implicit operations), but numbers will 
> be needed in any case, so not worth much speculation.

Sorry for late response.
I tried building  
https://github.com/flang-compiler/classic-flang-llvm-project.git (branch 
release_11x) with compiler (current patch (https://reviews.llvm.org/D99160) and 
https://reviews.llvm.org/D99238) with -O0 -g . 
Interestingly there was no difference.
Reason: https://reviews.llvm.org/D99238 is not sufficient for clang/clang++ to 
enable call-site generation with FastISel though it is sufficient for Flang 
compiler.
Below additional patch is needed to generate call-sites

  `

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index a77f52bd235b..8d4e11faa018 100644

- a/clang/lib/CodeGen/CGDebugInfo.cpp

+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5149,9 +5149,9 @@ llvm::DebugLoc 
CGDebugInfo::SourceLocToDebugLoc(SourceLocation Loc) {
 }

llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const {

- // Call site-related attributes are only useful in optimized programs, and
- // when there's a possibility of debugging backtraces.
- if (!CGM.getLangOpts().Optimize || DebugKind == codegenoptions::NoDebugInfo ||

+  // Call site-related attributes are useful when there's a possibility of
+  // debugging backtraces.
+  if (DebugKind == codegenoptions::NoDebugInfo ||

DebugKind == codegenoptions::LocTrackingOnly)
  return llvm::DINode::FlagZero;

  `

With this patch Clang/Clang++ turn on LLVM IR flag "DIFlagAllCallsDescribed", 
in absence of this LLVM does not generate call-site.

With the above patch applied below is the comparison of sizes of shared 
libraries.

Name of shared library - Size (without callsite) - Size (with callsites) - % 
incresase in size

  
```

PipSqueak.so 73192 75048 2%
SecondLib.so 73192 75048 2%
TestPlugin.so 1694024 1700704 0%
libLLVMDlltoolDriver.so 336568 347872 3%
libLLVMDebugInfoPDB.so 14463832 15360784 6%
libLLVMOrcError.so 108880 84 2%
libLLVMTarget.so 2645104 2677448 1%
libLLVMFrontendOpenMP.so 2354728 2505232 6%
li

[PATCH] D99160: [X86][FastISEL] Support DW_TAG_call_site_parameter with FastISEL

2021-04-19 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok added a comment.

In D99160#2699038 , @dblaikie wrote:

> In D99160#2698980 , @alok wrote:
>
>> In D99160#2671899 , @dblaikie wrote:
>>
>>> In D99160#2670460 , @djtodoro 
>>> wrote:
>>>
 In D99160#2669576 , @dblaikie 
 wrote:

> In D99160#2668977 , @djtodoro 
> wrote:
>
>> I think that the Debug Entry Values feature should not be enabled by 
>> default for non optimized code, so the 
>> `TargetOptions::ShouldEmitDebugEntryValues()` should be patched with 
>> checking of optimization level (it should be > 0).
>
> That's currently intended to be already handled by the frontend, right? 
> (clang only sets `EnableDebugEntryValues` (which 
> `ShouldEmitDebugEntryValues` checks (hmm, it checks under 'or', not 
> 'and', so I'm not sure where the "only above -O0" is implemented, but it 
> is implemented somewhere?) if optimizations are enabled, yeah?)
>
> Oh, is entry_values actually not conditionalized? It's only the call_site 
> support that's currently conditionalized on "above -O0"?

 Looks like there is no explicit check of optimization level (above "-O0"), 
 neither on frontend nor backend for entry-values generation. I think it is 
 the situation since there should not be any optimization (at least that I 
 am aware of, in the case of C/C++) that would cause the entry-values 
 generation...

> Hmm - If that's the case, and we currently have some cases where 
> entry_values are emitted at -O0, I'm not sure /not/ emitting those is the 
> right call either. If we believe/have data to show that there are so few 
> useful uses of entry_value at -O0 that it's not worth the DWARF size 
> growth to put call_sites in at -O0, then I think it might still be worth 
> leaving the entry_values in (unless they take up a bunch of extra space) 
> for the cases of mixed optimization compilation (-O0 some code you're 
> debugging, but building the rest with optimizations).

 Yeah... That is valuable example... I am thinking in that direction as 
 well, and I am closer to the enabling it for -O0 case if that is useful 
 (and there is no dramatic cost in terms of DWARF size).
>>>
>>> Does anyone have this example (where DW_OP_entry_value is used at -O0)? 
>>> It'd be great to look at it & see if it's a case of unnecessarily losing 
>>> the location, or legitimately losing it and using entry_value for 
>>> best-effort recovery (& then a question of whether the loss is appropriate 
>>> at -O0, or if we want to pessimize -O0 further to avoid the loss).
>
> I think this ^ still needs understanding/investigation. Do you have an 
> example with OP_entry_value at -O0?
>
>>> I'd worry about turning on call_sites at -O0 - there'd be a lot more calls 
>>> (especially for C++ code with lots of implicit operations), but numbers 
>>> will be needed in any case, so not worth much speculation.
>>
>> Sorry for late response.
>> I tried building  
>> https://github.com/flang-compiler/classic-flang-llvm-project.git (branch 
>> release_11x) with compiler (current patch (https://reviews.llvm.org/D99160) 
>> and https://reviews.llvm.org/D99238) with -O0 -g . 
>> Interestingly there was no difference.
>> Reason: https://reviews.llvm.org/D99238 is not sufficient for clang/clang++ 
>> to enable call-site generation with FastISel though it is sufficient for 
>> Flang compiler.
>> Below additional patch is needed to generate call-sites
>>
>>   `
>>
>> diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
>> b/clang/lib/CodeGen/CGDebugInfo.cpp
>> index a77f52bd235b..8d4e11faa018 100644
>>
>> - a/clang/lib/CodeGen/CGDebugInfo.cpp
>>
>> +++ b/clang/lib/CodeGen/CGDebugInfo.cpp
>> @@ -5149,9 +5149,9 @@ llvm::DebugLoc 
>> CGDebugInfo::SourceLocToDebugLoc(SourceLocation Loc) {
>>  }
>>
>> llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const {
>>
>> - // Call site-related attributes are only useful in optimized programs, and
>> - // when there's a possibility of debugging backtraces.
>> - if (!CGM.getLangOpts().Optimize || DebugKind == 
>> codegenoptions::NoDebugInfo ||
>>
>> +  // Call site-related attributes are useful when there's a possibility of
>> +  // debugging backtraces.
>> +  if (DebugKind == codegenoptions::NoDebugInfo ||
>>
>> DebugKind == codegenoptions::LocTrackingOnly)
>>   return llvm::DINode::FlagZero;
>>
>>   `
>>
>> With this patch Clang/Clang++ turn on LLVM IR flag 
>> "DIFlagAllCallsDescribed", in absence of this LLVM does not generate 
>> call-site.
>>
>> With the above patch applied below is the comparison of sizes of shared 
>> libraries.
>>
>> Name of shared

[PATCH] D111521: [DebugInfo] Mark OpenMP generated functions as artificial

2021-10-10 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok created this revision.
alok added reviewers: aprantl, djtodoro, jmorse, dblaikie, jini.susan, 
jini.susan.george.
alok added a project: debug-info.
Herald added subscribers: guansong, yaxunl.
alok requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

The OpenMP generates many functions which are not in user program.

Example: "__captured_stmt_debug_", "__captured_stmt", ".omp_outlined._debug__",
 ".omp_task_entry.", ".omp_outlined.", ".omp_outlined..1"

Current patch marks these all as artificial.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111521

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/OpenMP/outlined_artificial.c


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,63 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// CHECK: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-SAME: DIFlagArtificial
+
+// CHECK: !DISubprogram(name: "__captured_stmt"
+// CHECK-SAME: DIFlagArtificial
+
+// CHECK: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-SAME: DIFlagArtificial
+
+// CHECK: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-SAME: DIFlagArtificial
+
+// CHECK: !DISubprogram(name: ".omp_outlined."
+// CHECK-SAME: DIFlagArtificial
+
+// CHECK: !DISubprogram(name: ".omp_outlined..1"
+// CHECK-SAME: DIFlagArtificial
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4020,7 +4020,8 @@
 Name = Name.substr(1);
 
   if (!HasDecl || D->isImplicit() || D->hasAttr() ||
-  (isa(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub)) 
{
+  (isa(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub) 
||
+  isa(D)) {
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();


Index: clang/test/OpenMP/outlined_artificial.c
===
--- /dev/null
+++ clang/test/OpenMP/outlined_artificial.c
@@ -0,0 +1,63 @@
+// This testcase checks emission of DIFlagArtificial flag for outlined
+// subroutines generated by compiler.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#if defined(_WIN32)
+#define __KAI_KMPC_CONVENTION __cdecl
+#else
+#define __KAI_KMPC_CONVENTION
+#endif
+
+extern int printf(const char *, ...);
+extern void __KAI_KMPC_CONVENTION omp_set_num_threads(int);
+extern int __KAI_KMPC_CONVENTION omp_get_thread_num(void);
+
+#define N 10
+
+float f[10];
+void foo_simd(int low, int up) {
+  for (int i = low; i < up; ++i) {
+f[i] = 0.0;
+#pragma omp ordered simd
+f[i] = 1.0;
+  }
+}
+
+int main() {
+  int arr[10];
+  int i;
+  omp_set_num_threads(2);
+#pragma omp parallel
+#pragma omp single
+#pragma omp taskloop num_tasks(10)
+  for (i = 0; i < N; i++) {
+arr[i] = i * i;
+  }
+
+  for (int j = 0; j < N; j++) {
+printf("%d\n", arr[j]);
+  }
+  return 0;
+}
+
+// CHECK: !DISubprogram(name: "__captured_stmt_debug__"
+// CHECK-SAME: DIFlagArtificial
+
+// CHECK: !DISubprogram(name: "__captured_stmt"
+// CHECK-SAME: DIFlagArtificial
+
+// CHECK: !DISubprogram(name: ".omp_outlined._debug__"
+// CHECK-SAME: DIFlagArtificial
+
+// CHECK: !DISubprogram(linkageName: ".omp_task_entry."
+// CHECK-SAME: DIFlagArtificial
+
+// CHECK: !DISubprogram(name: ".omp_outlined."
+// CHECK-SAME: DIFlagArtificial
+
+// CHECK: !DISubprogram(name: ".omp_outlined..1"
+// CHECK-SAME: DIFlagArtificial
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugI