[flang] [clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-11-14 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/66702

>From f149c390f892c4e3f4b67ac9ae833b487b7c026d Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 18 Sep 2023 15:18:24 -0600
Subject: [PATCH 1/7] [flang][Driver] Support -rpath, -shared, and -static in
 the frontend

Enable -rpath, -shared, and -static for the flang frontend. This brings it in
line with clang. Fixes issue #65546.
---
 clang/include/clang/Driver/Options.td |  7 +--
 flang/test/Driver/linker-flags.f90| 16 
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d1b67a448b2a59b..885b2b0e93e88e7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5253,7 +5253,8 @@ def resource_dir : Separate<["-"], "resource-dir">,
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias;
-def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group;
+def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def rtlib_EQ : Joined<["-", "--"], "rtlib=">, Visibility<[ClangOption, 
CLOption]>,
   HelpText<"Compiler runtime library to use">;
 def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, 
Flags<[NoArgumentUnused]>,
@@ -5304,7 +5305,8 @@ def segs__read__only__addr : Separate<["-"], 
"segs_read_only_addr">;
 def segs__read__write__addr : Separate<["-"], "segs_read_write_addr">;
 def segs__read__ : Joined<["-"], "segs_read_">;
 def shared_libgcc : Flag<["-"], "shared-libgcc">;
-def shared : Flag<["-", "--"], "shared">, Group;
+def shared : Flag<["-", "--"], "shared">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def single__module : Flag<["-"], "single_module">;
 def specs_EQ : Joined<["-", "--"], "specs=">, Group;
 def specs : Separate<["-", "--"], "specs">, Flags<[Unsupported]>;
@@ -5314,6 +5316,7 @@ def start_no_unused_arguments : Flag<["--"], 
"start-no-unused-arguments">,
 def static_libgcc : Flag<["-"], "static-libgcc">;
 def static_libstdcxx : Flag<["-"], "static-libstdc++">;
 def static : Flag<["-", "--"], "static">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">,
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index a1417057d4da068..32c0f8ffb110cbe 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -88,3 +88,19 @@
 ! MSVC-DLL-DEBUG-SAME: FortranDecimal.dynamic_dbg.lib
 ! MSVC-DLL-DEBUG-SAME: /subsystem:console
 ! MSVC-DLL-DEBUG-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
+! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+
+! RUN: %flang -### -shared %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
+! CHECK-SHARED: ld{{.*}} "-shared"
+
+! RUN: %flang -### -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
+! CHECK-STATIC: ld{{.*}} "-static"
+

>From 9e24cff770e601b69e59905c132ef4534b46a286 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 07:47:28 -0600
Subject: [PATCH 2/7] Test all link flags in a single test.

---
 flang/test/Driver/linker-flags.f90 | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 32c0f8ffb110cbe..257f6fb457174a5 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -92,15 +92,11 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
-! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+! RUN: %flang -### -rpath /path/to/dir -shared -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-LINKER-FLAGS %s
+! CHECK-LINKER-FLAGS: ld
+! CHECK-LINKER-FLAGS-DAG: "-rpath" "/path/to/dir"
+! CHECK-LINKER-FLAGS-DAG: "-shared"
+! CHECK-LINKER-FLAGS-DAG: "-static"
 
-! RUN: %flang -### -shared %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
-! CHECK-SHARED: ld{{.*}} "-shared"
-
-! RUN: %flang -### -static %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
-! CHECK-STATIC: ld{{.*}} "-static"
 

>From b4d0ac573c8daa780707b92734db0ccfa47bcf1a Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 12:36:31 -0600
Subject: [PATCH 3/7] Delete trailing newlines. Rename prefix.

---
 flang/test/Driver/linker-flags.f90 | 12 +---
 1 file changed, 5 insertions(+), 7 

[flang] [clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-11-14 Thread Tarun Prabhu via cfe-commits


@@ -48,3 +48,17 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared \
+! RUN: -static %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=CHECK-LINKER-OPTIONS,GNU-LINKER-OPTIONS %s
+! RUN: %flang -### --target=x86_64-windows-msvc -rpath /path/to/dir -shared \
+! RUN: -static %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=CHECK-LINKER-OPTIONS,MSVC-LINKER-OPTIONS %s
+! CHECK-LINKER-OPTIONS-DAG: "-rpath" "/path/to/dir"
+! GNU-LINKER-OPTIONS-DAG: "-shared"
+! MSVC-LINKER-OPTIONS-DAG: "-dll"
+! GNU-LINKER-OPTIONS-DAG: "-static"

tarunprabhu wrote:

> I would separate the two things into different files.

Done.

> * Why would we test `-shared` and `-static` in one invocation?

This was because of a suggestion by @MaskRay [in an earlier 
comment](https://github.com/llvm/llvm-project/pull/66702#discussion_r1331136897)

> * We should make sure that what's being tested is indeed the linker 
> invocation.

Done.



https://github.com/llvm/llvm-project/pull/66702
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-11-14 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/66702

>From f149c390f892c4e3f4b67ac9ae833b487b7c026d Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 18 Sep 2023 15:18:24 -0600
Subject: [PATCH 1/8] [flang][Driver] Support -rpath, -shared, and -static in
 the frontend

Enable -rpath, -shared, and -static for the flang frontend. This brings it in
line with clang. Fixes issue #65546.
---
 clang/include/clang/Driver/Options.td |  7 +--
 flang/test/Driver/linker-flags.f90| 16 
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d1b67a448b2a59b..885b2b0e93e88e7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5253,7 +5253,8 @@ def resource_dir : Separate<["-"], "resource-dir">,
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias;
-def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group;
+def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def rtlib_EQ : Joined<["-", "--"], "rtlib=">, Visibility<[ClangOption, 
CLOption]>,
   HelpText<"Compiler runtime library to use">;
 def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, 
Flags<[NoArgumentUnused]>,
@@ -5304,7 +5305,8 @@ def segs__read__only__addr : Separate<["-"], 
"segs_read_only_addr">;
 def segs__read__write__addr : Separate<["-"], "segs_read_write_addr">;
 def segs__read__ : Joined<["-"], "segs_read_">;
 def shared_libgcc : Flag<["-"], "shared-libgcc">;
-def shared : Flag<["-", "--"], "shared">, Group;
+def shared : Flag<["-", "--"], "shared">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def single__module : Flag<["-"], "single_module">;
 def specs_EQ : Joined<["-", "--"], "specs=">, Group;
 def specs : Separate<["-", "--"], "specs">, Flags<[Unsupported]>;
@@ -5314,6 +5316,7 @@ def start_no_unused_arguments : Flag<["--"], 
"start-no-unused-arguments">,
 def static_libgcc : Flag<["-"], "static-libgcc">;
 def static_libstdcxx : Flag<["-"], "static-libstdc++">;
 def static : Flag<["-", "--"], "static">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">,
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index a1417057d4da068..32c0f8ffb110cbe 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -88,3 +88,19 @@
 ! MSVC-DLL-DEBUG-SAME: FortranDecimal.dynamic_dbg.lib
 ! MSVC-DLL-DEBUG-SAME: /subsystem:console
 ! MSVC-DLL-DEBUG-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
+! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+
+! RUN: %flang -### -shared %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
+! CHECK-SHARED: ld{{.*}} "-shared"
+
+! RUN: %flang -### -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
+! CHECK-STATIC: ld{{.*}} "-static"
+

>From 9e24cff770e601b69e59905c132ef4534b46a286 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 07:47:28 -0600
Subject: [PATCH 2/8] Test all link flags in a single test.

---
 flang/test/Driver/linker-flags.f90 | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 32c0f8ffb110cbe..257f6fb457174a5 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -92,15 +92,11 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
-! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+! RUN: %flang -### -rpath /path/to/dir -shared -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-LINKER-FLAGS %s
+! CHECK-LINKER-FLAGS: ld
+! CHECK-LINKER-FLAGS-DAG: "-rpath" "/path/to/dir"
+! CHECK-LINKER-FLAGS-DAG: "-shared"
+! CHECK-LINKER-FLAGS-DAG: "-static"
 
-! RUN: %flang -### -shared %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
-! CHECK-SHARED: ld{{.*}} "-shared"
-
-! RUN: %flang -### -static %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
-! CHECK-STATIC: ld{{.*}} "-static"
 

>From b4d0ac573c8daa780707b92734db0ccfa47bcf1a Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 12:36:31 -0600
Subject: [PATCH 3/8] Delete trailing newlines. Rename prefix.

---
 flang/test/Driver/linker-flags.f90 | 12 +---
 1 file changed, 5 insertions(+), 7 

[clang] [flang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-11-16 Thread Tarun Prabhu via cfe-commits




tarunprabhu wrote:

clang has a 
[test](https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/dynamic-linker.c)
 that is similar and in a file with that name.

https://github.com/llvm/llvm-project/pull/66702
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-11-16 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/66702

>From 68733f1502ba23c4c6bb2f172bd9bae8362317d3 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 18 Sep 2023 15:18:24 -0600
Subject: [PATCH] [flang][Driver] Support -rpath, -shared, and -static in the
 frontend

Enable -rpath, -shared, and -static for the flang frontend. This brings it in
line with clang. Fixes issue #65546.
---
 clang/include/clang/Driver/Options.td |  7 +--
 flang/test/Driver/dynamic-linker.f90  | 20 
 2 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 flang/test/Driver/dynamic-linker.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b9694f5662c7b07..811550416110b3d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5253,7 +5253,8 @@ def resource_dir : Separate<["-"], "resource-dir">,
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias;
-def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group;
+def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def rtlib_EQ : Joined<["-", "--"], "rtlib=">, Visibility<[ClangOption, 
CLOption]>,
   HelpText<"Compiler runtime library to use">;
 def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, 
Flags<[NoArgumentUnused]>,
@@ -5304,7 +5305,8 @@ def segs__read__only__addr : Separate<["-"], 
"segs_read_only_addr">;
 def segs__read__write__addr : Separate<["-"], "segs_read_write_addr">;
 def segs__read__ : Joined<["-"], "segs_read_">;
 def shared_libgcc : Flag<["-"], "shared-libgcc">;
-def shared : Flag<["-", "--"], "shared">, Group;
+def shared : Flag<["-", "--"], "shared">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def single__module : Flag<["-"], "single_module">;
 def specs_EQ : Joined<["-", "--"], "specs=">, Group;
 def specs : Separate<["-", "--"], "specs">, Flags<[Unsupported]>;
@@ -5314,6 +5316,7 @@ def start_no_unused_arguments : Flag<["--"], 
"start-no-unused-arguments">,
 def static_libgcc : Flag<["-"], "static-libgcc">;
 def static_libstdcxx : Flag<["-"], "static-libstdc++">;
 def static : Flag<["-", "--"], "static">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">,
diff --git a/flang/test/Driver/dynamic-linker.f90 
b/flang/test/Driver/dynamic-linker.f90
new file mode 100644
index 000..2745822dc107769
--- /dev/null
+++ b/flang/test/Driver/dynamic-linker.f90
@@ -0,0 +1,20 @@
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared \
+! RUN: -static %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=GNU-LINKER-OPTIONS %s
+! RUN: %flang -### --target=x86_64-windows-msvc -rpath /path/to/dir -shared \
+! RUN: -static %s 2>&1 | FileCheck \
+! RUN: --check-prefixes=MSVC-LINKER-OPTIONS %s
+
+! TODO: Could the linker have an extension or a suffix?
+! GNU-LINKER-OPTIONS: "{{.*}}ld{{(.exe)?}}"
+! GNU-LINKER-OPTIONS-SAME: "-shared"
+! GNU-LINKER-OPTIONS-SAME: "-static"
+! GNU-LINKER-OPTIONS-SAME: "-rpath" "/path/to/dir"
+
+! For MSVC, adding -static does not add any additional linker options.
+! MSVC-LINKER-OPTIONS: "{{.*}}link.exe"
+! MSVC-LINKER-OPTIONS-SAME: "-dll"
+! MSVC-LINKER-OPTIONS-SAME: "-rpath" "/path/to/dir"

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


[clang] [flang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-11-16 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu closed 
https://github.com/llvm/llvm-project/pull/66702
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [flang][Driver] Support -pthread in the frontend (PR #77360)

2024-01-08 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu created 
https://github.com/llvm/llvm-project/pull/77360

The -pthread option is supported by both clang and gfortran.

The -pthread option seems to be extensively tested for various platforms by 
clang. We should be able to piggy-back on those tests since we use the relevant 
parts of the clang driver. Therefore, the only test added is to ensure that the 
option is recognized by the frontend.

This has only be tested on x86 Linux.

>From 187f91dcd9e602c944b089adfb243127c31de2ca Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 8 Jan 2024 10:56:09 -0700
Subject: [PATCH] [flang][Driver] Support -pthread in the frontend

The -pthread option is supported by both clang and gfortran.
---
 clang/include/clang/Driver/Options.td|  3 ++-
 flang/test/Driver/driver-help-hidden.f90 |  1 +
 flang/test/Driver/driver-help.f90|  2 ++
 flang/test/Driver/pthread.f90| 10 ++
 4 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Driver/pthread.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6aff37f1336871..3aaf3b58f78f4a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5303,7 +5303,8 @@ def pthreads : Flag<["-"], "pthreads">;
 defm pthread : BoolOption<"", "pthread",
   LangOpts<"POSIXThreads">, DefaultFalse,
   PosFlag,
-  NegFlag, BothFlags<[], [ClangOption, CC1Option]>>;
+  NegFlag,
+  BothFlags<[], [ClangOption, CC1Option, FlangOption, FC1Option]>>;
 def pie : Flag<["-"], "pie">, Group;
 def static_pie : Flag<["-"], "static-pie">, Group;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;
diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 9a11a7a571ffcc..39c607b80ddb98 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -134,6 +134,7 @@
 ! CHECK-NEXT: -pedantic   Warn on language extensions
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
+! CHECK-NEXT: -pthreadSupport POSIX threads in generated code
 ! CHECK-NEXT: -P  Disable linemarker output in -E mode
 ! CHECK-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! CHECK-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index e0e74dc56f331e..f00b3ba47e269a 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -120,6 +120,7 @@
 ! HELP-NEXT: -pedantic   Warn on language extensions
 ! HELP-NEXT: -print-effective-triple Print the effective target triple
 ! HELP-NEXT: -print-target-triplePrint the normalized target triple
+! HELP-NEXT: -pthreadSupport POSIX threads in generated code
 ! HELP-NEXT: -P  Disable linemarker output in -E mode
 ! HELP-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! HELP-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
@@ -258,6 +259,7 @@
 ! HELP-FC1-NEXT: -pic-is-pie File is for a position independent 
executable
 ! HELP-FC1-NEXT: -pic-level   Value for __PIC__
 ! HELP-FC1-NEXT: -plugin   Use the named plugin action instead 
of the default action (use "help" to list available options)
+! HELP-FC1-NEXT: -pthreadSupport POSIX threads in generated 
code
 ! HELP-FC1-NEXT: -P  Disable linemarker output in -E mode
 ! HELP-FC1-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! HELP-FC1-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/pthread.f90 b/flang/test/Driver/pthread.f90
new file mode 100644
index 00..e3fd392ed91aff
--- /dev/null
+++ b/flang/test/Driver/pthread.f90
@@ -0,0 +1,10 @@
+! RUN: %flang -### -pthread /dev/null -o /dev/null 2>&1 | FileCheck %s
+! RUN: %flang -### -Xflang -pthread /dev/null -o /dev/null 2>&1 | FileCheck %s
+
+! How the -pthread flag is handled is very platform-specific. A lot of that
+! functionality is tested by clang, and the flag itself is handled by clang's
+! driver that flang also uses. Instead of duplicating all that testing here,
+! just check that the presence of the flag does not raise an error. If we need
+! more customized handling of -pthread, the tests for that can be added here.
+!
+! CHECK-NO

[flang] [clang] [flang][Driver] Support -pthread in the frontend (PR #77360)

2024-01-08 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

Thanks, I am not sure how I missed that. 

@banach-space, Is the intention for the `-pthread` option to be illegal in 
flang?

At the last flang community call 
([2024-01-03](https://docs.google.com/document/d/1Z2U5UAtJ-Dag5wlMaLaW1KRmNgENNAYynJqLW2j2AZQ/edit#heading=h.de8wft8m7vbj)),
 one user reported being unable to build with OpenMPI because it inserted the 
-pthread flag. I suspect that some application build systems do the same thing, 
but I can't point to an example off the top of my head. 

CC'ing @ergawy as the original author.

https://github.com/llvm/llvm-project/pull/77360
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [flang][Driver] Support -pthread in the frontend (PR #77360)

2024-01-08 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

@banach-space. 

Thanks for clarifying. I'll look into creating a test that fails without 
`-pthread`.

https://github.com/llvm/llvm-project/pull/77360
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [flang][Driver] Support -pthread in the frontend (PR #77360)

2024-01-11 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

> IIUC, this means that on older system compilation will indeed fail without 
> `-pthread`, but shouldn't be needed on newer systems. @tarunprabhu - perhaps 
> add a link to that article in your test and add a note that on many systems 
> compilation will succeed even without the flag?

I can do that. 

I was looking around to see if one could force the use of an older libc in the 
test. The only approaches I found involved some unpleasant inline assembly - 
which probably wouldn't work in Fortran. Besides, I don't think the library 
organization has anything to do with glibc's symbol versioning anyway.


https://github.com/llvm/llvm-project/pull/77360
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [flang][Driver] Support -pthread in the frontend (PR #77360)

2024-01-11 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/77360

>From 187f91dcd9e602c944b089adfb243127c31de2ca Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 8 Jan 2024 10:56:09 -0700
Subject: [PATCH 1/2] [flang][Driver] Support -pthread in the frontend

The -pthread option is supported by both clang and gfortran.
---
 clang/include/clang/Driver/Options.td|  3 ++-
 flang/test/Driver/driver-help-hidden.f90 |  1 +
 flang/test/Driver/driver-help.f90|  2 ++
 flang/test/Driver/pthread.f90| 10 ++
 4 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Driver/pthread.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6aff37f1336871..3aaf3b58f78f4a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5303,7 +5303,8 @@ def pthreads : Flag<["-"], "pthreads">;
 defm pthread : BoolOption<"", "pthread",
   LangOpts<"POSIXThreads">, DefaultFalse,
   PosFlag,
-  NegFlag, BothFlags<[], [ClangOption, CC1Option]>>;
+  NegFlag,
+  BothFlags<[], [ClangOption, CC1Option, FlangOption, FC1Option]>>;
 def pie : Flag<["-"], "pie">, Group;
 def static_pie : Flag<["-"], "static-pie">, Group;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;
diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 9a11a7a571ffcc..39c607b80ddb98 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -134,6 +134,7 @@
 ! CHECK-NEXT: -pedantic   Warn on language extensions
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
+! CHECK-NEXT: -pthreadSupport POSIX threads in generated code
 ! CHECK-NEXT: -P  Disable linemarker output in -E mode
 ! CHECK-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! CHECK-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index e0e74dc56f331e..f00b3ba47e269a 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -120,6 +120,7 @@
 ! HELP-NEXT: -pedantic   Warn on language extensions
 ! HELP-NEXT: -print-effective-triple Print the effective target triple
 ! HELP-NEXT: -print-target-triplePrint the normalized target triple
+! HELP-NEXT: -pthreadSupport POSIX threads in generated code
 ! HELP-NEXT: -P  Disable linemarker output in -E mode
 ! HELP-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! HELP-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
@@ -258,6 +259,7 @@
 ! HELP-FC1-NEXT: -pic-is-pie File is for a position independent 
executable
 ! HELP-FC1-NEXT: -pic-level   Value for __PIC__
 ! HELP-FC1-NEXT: -plugin   Use the named plugin action instead 
of the default action (use "help" to list available options)
+! HELP-FC1-NEXT: -pthreadSupport POSIX threads in generated 
code
 ! HELP-FC1-NEXT: -P  Disable linemarker output in -E mode
 ! HELP-FC1-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! HELP-FC1-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/pthread.f90 b/flang/test/Driver/pthread.f90
new file mode 100644
index 00..e3fd392ed91aff
--- /dev/null
+++ b/flang/test/Driver/pthread.f90
@@ -0,0 +1,10 @@
+! RUN: %flang -### -pthread /dev/null -o /dev/null 2>&1 | FileCheck %s
+! RUN: %flang -### -Xflang -pthread /dev/null -o /dev/null 2>&1 | FileCheck %s
+
+! How the -pthread flag is handled is very platform-specific. A lot of that
+! functionality is tested by clang, and the flag itself is handled by clang's
+! driver that flang also uses. Instead of duplicating all that testing here,
+! just check that the presence of the flag does not raise an error. If we need
+! more customized handling of -pthread, the tests for that can be added here.
+!
+! CHECK-NOT: error:

>From ae2e23569616f4cb13b4eaec902803650f0fc1b4 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 11 Jan 2024 12:40:30 -0700
Subject: [PATCH 2/2] Add comments to the test explaining why it is difficult
 to write a failing test for the -pthread option.

---
 flang/test/Driver/pthread.f90 | 12 
 1 file changed, 12 insertions(+)

diff --git a/flang

[flang] [clang] [flang][Driver] Support -pthread in the frontend (PR #77360)

2024-01-11 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

> [nit] Note that the test that you've added will run on any platform. Unless 
> that's referring to something else?

That was only highlighting that I have not tested this on AArch64 or Windows. 

Could someone test this on AArch64 and/or Windows just to make sure that it 
passes there?

https://github.com/llvm/llvm-project/pull/77360
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang] Enable polymorphic lowering by default (PR #83285)

2024-02-28 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

> A few of the tests in the gfortran-testsuite using polymorphism fail at 
> runtime. I'm happy for this PR to be merged as it is and these bugs to be 
> fixed later.

Once this is merged in, the polymorphism tests can be enabled together with the 
larger group of tests that I intend to enable in the next day or two. 

https://github.com/llvm/llvm-project/pull/83285
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [flang][Driver] Support -pthread in the frontend (PR #77360)

2024-01-16 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/77360

>From ab27280e85d6027e6ff119c0803d962753e83b52 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 8 Jan 2024 10:56:09 -0700
Subject: [PATCH] [flang][Driver] Support -pthread in the frontend

The -pthread option is supported by both clang and gfortran.
---
 clang/include/clang/Driver/Options.td|  3 ++-
 flang/test/Driver/driver-help-hidden.f90 |  1 +
 flang/test/Driver/driver-help.f90|  2 ++
 flang/test/Driver/pthread.f90| 22 ++
 4 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Driver/pthread.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d9d6ce81b4d84af..a4a988c71ec412c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5307,7 +5307,8 @@ def pthreads : Flag<["-"], "pthreads">;
 defm pthread : BoolOption<"", "pthread",
   LangOpts<"POSIXThreads">, DefaultFalse,
   PosFlag,
-  NegFlag, BothFlags<[], [ClangOption, CC1Option]>>;
+  NegFlag,
+  BothFlags<[], [ClangOption, CC1Option, FlangOption, FC1Option]>>;
 def pie : Flag<["-"], "pie">, Group;
 def static_pie : Flag<["-"], "static-pie">, Group;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;
diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index a84db70845694e6..426b0e5a1c367d7 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -139,6 +139,7 @@
 ! CHECK-NEXT: -pedantic   Warn on language extensions
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
+! CHECK-NEXT: -pthreadSupport POSIX threads in generated code
 ! CHECK-NEXT: -P  Disable linemarker output in -E mode
 ! CHECK-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! CHECK-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index e5cc8a20237651a..221da6439764b4d 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -125,6 +125,7 @@
 ! HELP-NEXT: -pedantic   Warn on language extensions
 ! HELP-NEXT: -print-effective-triple Print the effective target triple
 ! HELP-NEXT: -print-target-triplePrint the normalized target triple
+! HELP-NEXT: -pthreadSupport POSIX threads in generated code
 ! HELP-NEXT: -P  Disable linemarker output in -E mode
 ! HELP-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! HELP-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
@@ -265,6 +266,7 @@
 ! HELP-FC1-NEXT: -pic-is-pie File is for a position independent 
executable
 ! HELP-FC1-NEXT: -pic-level   Value for __PIC__
 ! HELP-FC1-NEXT: -plugin   Use the named plugin action instead 
of the default action (use "help" to list available options)
+! HELP-FC1-NEXT: -pthreadSupport POSIX threads in generated 
code
 ! HELP-FC1-NEXT: -P  Disable linemarker output in -E mode
 ! HELP-FC1-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! HELP-FC1-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/pthread.f90 b/flang/test/Driver/pthread.f90
new file mode 100644
index 000..6201f4d9f9c2177
--- /dev/null
+++ b/flang/test/Driver/pthread.f90
@@ -0,0 +1,22 @@
+! In release 2.34, glibc removed libpthread as a separate library. All the
+! pthread_* functions were subsumed into libc, so linking that is sufficient.
+! However, when linking against older glibc builds, the explicit link of
+! -pthread will be required. More details are here:
+!
+! 
https://developers.redhat.com/articles/2021/12/17/why-glibc-234-removed-libpthread#the_developer_view
+!
+! This makes it difficult to write a test that requires the -pthread flag in
+! order to pass. Checking for the presence of -lpthread in the linker flags is
+! not reliable since the linker could just skip the flag altogether if it is
+! linking against a new libc implementation.
+
+! RUN: %flang -### -pthread /dev/null -o /dev/null 2>&1 | FileCheck %s
+! RUN: %flang -### -Xflang -pthread /dev/null -o /dev/null 2>&1 | FileCheck %s
+
+! How the -pthread flag is handled is very platform-specific. A lot of that
+! function

[flang] [clang] [flang][Driver] Support -pthread in the frontend (PR #77360)

2024-01-16 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu closed 
https://github.com/llvm/llvm-project/pull/77360
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-10-19 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/66702

>From 3302fb4937d75c0920e7bcf8f215e12fbe770a36 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 18 Sep 2023 15:18:24 -0600
Subject: [PATCH 1/6] [flang][Driver] Support -rpath, -shared, and -static in
 the frontend

Enable -rpath, -shared, and -static for the flang frontend. This brings it in
line with clang. Fixes issue #65546.
---
 clang/include/clang/Driver/Options.td |  7 +--
 flang/test/Driver/linker-flags.f90| 16 
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..bf4c76d4555d152 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5165,7 +5165,8 @@ def resource_dir : Separate<["-"], "resource-dir">,
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias;
-def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group;
+def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def rtlib_EQ : Joined<["-", "--"], "rtlib=">,
   HelpText<"Compiler runtime library to use">;
 def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, 
Flags<[NoArgumentUnused]>,
@@ -5216,7 +5217,8 @@ def segs__read__only__addr : Separate<["-"], 
"segs_read_only_addr">;
 def segs__read__write__addr : Separate<["-"], "segs_read_write_addr">;
 def segs__read__ : Joined<["-"], "segs_read_">;
 def shared_libgcc : Flag<["-"], "shared-libgcc">;
-def shared : Flag<["-", "--"], "shared">, Group;
+def shared : Flag<["-", "--"], "shared">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def single__module : Flag<["-"], "single_module">;
 def specs_EQ : Joined<["-", "--"], "specs=">, Group;
 def specs : Separate<["-", "--"], "specs">, Flags<[Unsupported]>;
@@ -5226,6 +5228,7 @@ def start_no_unused_arguments : Flag<["--"], 
"start-no-unused-arguments">,
 def static_libgcc : Flag<["-"], "static-libgcc">;
 def static_libstdcxx : Flag<["-"], "static-libstdc++">;
 def static : Flag<["-", "--"], "static">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">,
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..9a9ec5d28acb9c7 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -50,3 +50,19 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
+! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+
+! RUN: %flang -### -shared %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
+! CHECK-SHARED: ld{{.*}} "-shared"
+
+! RUN: %flang -### -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
+! CHECK-STATIC: ld{{.*}} "-static"
+

>From 653d215a59fc1ab71784776d52a32005359ee93e Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 07:47:28 -0600
Subject: [PATCH 2/6] Test all link flags in a single test.

---
 flang/test/Driver/linker-flags.f90 | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 9a9ec5d28acb9c7..c9cc851fa607ae8 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -54,15 +54,11 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
-! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+! RUN: %flang -### -rpath /path/to/dir -shared -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-LINKER-FLAGS %s
+! CHECK-LINKER-FLAGS: ld
+! CHECK-LINKER-FLAGS-DAG: "-rpath" "/path/to/dir"
+! CHECK-LINKER-FLAGS-DAG: "-shared"
+! CHECK-LINKER-FLAGS-DAG: "-static"
 
-! RUN: %flang -### -shared %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
-! CHECK-SHARED: ld{{.*}} "-shared"
-
-! RUN: %flang -### -static %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
-! CHECK-STATIC: ld{{.*}} "-static"
 

>From e080beb011db6ad26c07deab0fe7178895ed3c99 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 12:36:31 -0600
Subject: [PATCH 3/6] Delete trailing newlines. Rename prefix.

---
 flang/test/Driver/linker-flags.f90 | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driv

[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-10-26 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/66702

>From ba3bb1ae28c14f6720e17d26e037c7406a638436 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 18 Sep 2023 15:18:24 -0600
Subject: [PATCH 1/6] [flang][Driver] Support -rpath, -shared, and -static in
 the frontend

Enable -rpath, -shared, and -static for the flang frontend. This brings it in
line with clang. Fixes issue #65546.
---
 clang/include/clang/Driver/Options.td |  7 +--
 flang/test/Driver/linker-flags.f90| 16 
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2eb86caa6e6d40e..bc000856f469e30 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5218,7 +5218,8 @@ def resource_dir : Separate<["-"], "resource-dir">,
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias;
-def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group;
+def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def rtlib_EQ : Joined<["-", "--"], "rtlib=">, Visibility<[ClangOption, 
CLOption]>,
   HelpText<"Compiler runtime library to use">;
 def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, 
Flags<[NoArgumentUnused]>,
@@ -5269,7 +5270,8 @@ def segs__read__only__addr : Separate<["-"], 
"segs_read_only_addr">;
 def segs__read__write__addr : Separate<["-"], "segs_read_write_addr">;
 def segs__read__ : Joined<["-"], "segs_read_">;
 def shared_libgcc : Flag<["-"], "shared-libgcc">;
-def shared : Flag<["-", "--"], "shared">, Group;
+def shared : Flag<["-", "--"], "shared">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def single__module : Flag<["-"], "single_module">;
 def specs_EQ : Joined<["-", "--"], "specs=">, Group;
 def specs : Separate<["-", "--"], "specs">, Flags<[Unsupported]>;
@@ -5279,6 +5281,7 @@ def start_no_unused_arguments : Flag<["--"], 
"start-no-unused-arguments">,
 def static_libgcc : Flag<["-"], "static-libgcc">;
 def static_libstdcxx : Flag<["-"], "static-libstdc++">;
 def static : Flag<["-", "--"], "static">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">,
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 213bc032d964504..a04a7877e52d10c 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -48,3 +48,19 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
+! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+
+! RUN: %flang -### -shared %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
+! CHECK-SHARED: ld{{.*}} "-shared"
+
+! RUN: %flang -### -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
+! CHECK-STATIC: ld{{.*}} "-static"
+

>From f80d1cb29bc595dcdf71e88864756731f7741668 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 07:47:28 -0600
Subject: [PATCH 2/6] Test all link flags in a single test.

---
 flang/test/Driver/linker-flags.f90 | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index a04a7877e52d10c..495d5ef2ebda0e2 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -52,15 +52,11 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
-! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+! RUN: %flang -### -rpath /path/to/dir -shared -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-LINKER-FLAGS %s
+! CHECK-LINKER-FLAGS: ld
+! CHECK-LINKER-FLAGS-DAG: "-rpath" "/path/to/dir"
+! CHECK-LINKER-FLAGS-DAG: "-shared"
+! CHECK-LINKER-FLAGS-DAG: "-static"
 
-! RUN: %flang -### -shared %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
-! CHECK-SHARED: ld{{.*}} "-shared"
-
-! RUN: %flang -### -static %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
-! CHECK-STATIC: ld{{.*}} "-static"
 

>From abbf9254f8789a2e9cef37208160c4b7c0b0cd9c Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 12:36:31 -0600
Subject: [PATCH 3/6] Delete trailing newlines. Rename prefix.

---
 flang/test/Driver/linker-flags.f90 | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/flang/test/Driv

[clang] 43fe6f7 - [flang] Add -fpass-plugin option to Flang frontend

2022-10-04 Thread Tarun Prabhu via cfe-commits

Author: Tarun Prabhu
Date: 2022-10-04T17:02:45-06:00
New Revision: 43fe6f7cc35ded691bbc2fa844086d321e705d46

URL: 
https://github.com/llvm/llvm-project/commit/43fe6f7cc35ded691bbc2fa844086d321e705d46
DIFF: 
https://github.com/llvm/llvm-project/commit/43fe6f7cc35ded691bbc2fa844086d321e705d46.diff

LOG: [flang] Add -fpass-plugin option to Flang frontend

Add the -fpass-plugin option to flang which dynamically loads LLVM passes from 
the
shared object passed as the argument to the flag. The behavior of the option is
designed to replicate that of the same option in clang and thus has the same
capabilities and limitations.

- Multiple instances of -fpass-plugin=path-to-file can be specified and each of 
the
  files will be loaded in that order.

- The flag can be passed to both flang-new and flang-new -fc1.

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

Added: 
flang/test/Driver/pass-plugin-not-found.f90
flang/test/Driver/pass-plugin.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/docs/FlangDriver.md
flang/docs/ReleaseNotes.md
flang/include/flang/Frontend/CodeGenOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/test/Driver/frontend-forwarding.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0b795184b7bd0..f09025d34346c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2710,7 +2710,7 @@ def fplugin_arg : Joined<["-"], "fplugin-arg-">,
   MetaVarName<"-">,
   HelpText<"Pass  to plugin ">;
 def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">,
-  Group, Flags<[CC1Option]>, MetaVarName<"">,
+  Group, Flags<[CC1Option,FlangOption,FC1Option]>, 
MetaVarName<"">,
   HelpText<"Load pass plugin from a dynamic shared object file (only with new 
pass manager).">,
   MarshallingInfoStringVector>;
 defm preserve_as_comments : BoolFOption<"preserve-as-comments",

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index b279529a33184..9fe83ed0886b4 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -55,7 +55,8 @@ void Flang::AddOtherOptions(const ArgList &Args, 
ArgStringList &CmdArgs) const {
   Args.AddAllArgs(CmdArgs,
   {options::OPT_module_dir, options::OPT_fdebug_module_writer,
options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
-   options::OPT_std_EQ, options::OPT_W_Joined});
+   options::OPT_std_EQ, options::OPT_W_Joined,
+   options::OPT_fpass_plugin_EQ});
 }
 
 void Flang::AddPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {

diff  --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index af1fddc8f750a..b44f44efc93fa 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -507,3 +507,28 @@ Lastly, if `ParseTree` modifications are performed, then 
it might be necessary
 to re-analyze expressions and modify scope or symbols. You can check
 [Semantics.md](Semantics.md) for more details on how `ParseTree` is edited
 e.g. during the semantic checks.
+
+# LLVM Pass Plugins
+
+Pass plugins are dynamic shared objects that consist of one or more LLVM IR
+passes. The `-fpass-plugin` option enables these passes to be passed to the 
+middle-end where they are added to the optimization pass pipeline and run after
+lowering to LLVM IR.The exact position of the pass in the pipeline will depend 
+on how it has been registered with the `llvm::PassBuilder`. See the 
+documentation for 
+[`llvm::PassBuilder`](https://llvm.org/doxygen/classllvm_1_1PassBuilder.html)
+for details. 
+
+The framework to enable pass plugins in `flang-new` uses the exact same 
+machinery as that used by `clang` and thus has the same capabilities and
+limitations. 
+
+In order to use a pass plugin, the pass(es) must be compiled into a dynamic 
+shared object which is then loaded using the `-fpass-plugin` option. 
+
+```
+flang-new -fpass-plugin=/path/to/plugin.so 
+```
+
+This option is available in both the compiler driver and the frontend driver. 
+Note that LLVM plugins are not officially supported on Windows.

diff  --git a/flang/docs/ReleaseNotes.md b/flang/docs/ReleaseNotes.md
index fd1db3b00eb83..0cc85db9debc5 100644
--- a/flang/docs/ReleaseNotes.md
+++ b/flang/docs/ReleaseNotes.md
@@ -24,6 +24,10 @@ page](https://llvm.org/releases/).
 
 ## Major New Features
 
+* Flang now supports loading LLVM pass plugins with the `-fpass-plugin` option
+  which is also available in clang. The option mimics the behavior of the
+  corresponding option in clang and has the same capabilities and limitations.
+
 ## Bug Fixes

[clang] c3821b8 - [flang] Add -fpass-plugin option to flang

2022-11-10 Thread Tarun Prabhu via cfe-commits

Author: Tarun Prabhu
Date: 2022-11-10T08:03:46-07:00
New Revision: c3821b8d2aacd1d7c0281db1b8db011e1158cf4d

URL: 
https://github.com/llvm/llvm-project/commit/c3821b8d2aacd1d7c0281db1b8db011e1158cf4d
DIFF: 
https://github.com/llvm/llvm-project/commit/c3821b8d2aacd1d7c0281db1b8db011e1158cf4d.diff

LOG: [flang] Add -fpass-plugin option to flang

This patch adds the -fpass-plugin option to flang which dynamically loads LLVM
passes from the shared object passed as the argument to the flag. The behavior
of the option is designed to replicate that of the same option in clang and
thus has the same capabilities and limitations.

Features:

  Multiple instances of -fpass-plugin=path-to-file can be specified and each
  of the files will be loaded in that order.

  The flag can be passed to both flang-new and flang-new -fc1.

  The flag will be listed when the -help flag is passed to both flang-new and
  flang-new -fc1. It will also be listed when the --help-hidden flag is passed.

Limitations:

  Dynamically loaded plugins are not supported in clang on Windows and are not
  supported in flang either.

Addenda:

  Some minor stylistic changes are made in the files that were modified to
  enable this functionality. Those changes make the naming of functions more
  consistent, but do not change any functionality that is not directly
  related to enabling -fpass-plugin.

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

Added: 
flang/test/Driver/pass-plugin-not-found.f90
flang/test/Driver/pass-plugin.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Driver/ToolChains/Flang.h
flang/docs/FlangDriver.md
flang/docs/ReleaseNotes.md
flang/include/flang/Frontend/CodeGenOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/CMakeLists.txt
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/test/Driver/frontend-forwarding.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index debe038196c06..a501306632afb 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2719,7 +2719,7 @@ def fplugin_arg : Joined<["-"], "fplugin-arg-">,
   MetaVarName<"-">,
   HelpText<"Pass  to plugin ">;
 def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">,
-  Group, Flags<[CC1Option]>, MetaVarName<"">,
+  Group, Flags<[CC1Option,FlangOption,FC1Option]>, 
MetaVarName<"">,
   HelpText<"Load pass plugin from a dynamic shared object file (only with new 
pass manager).">,
   MarshallingInfoStringVector>;
 defm preserve_as_comments : BoolFOption<"preserve-as-comments",

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index c9016238ee65e..588fabd560009 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -51,15 +51,15 @@ void Flang::addPreprocessingOptions(const ArgList &Args,
options::OPT_I, options::OPT_cpp, options::OPT_nocpp});
 }
 
-void Flang::forwardOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
+void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const 
{
   Args.AddAllArgs(CmdArgs,
   {options::OPT_module_dir, options::OPT_fdebug_module_writer,
options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
options::OPT_std_EQ, options::OPT_W_Joined,
-   options::OPT_fconvert_EQ});
+   options::OPT_fconvert_EQ, options::OPT_fpass_plugin_EQ});
 }
 
-void Flang::AddPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
+void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
   // ParsePICArgs parses -fPIC/-fPIE and their variants and returns a tuple of
   // (RelocationModel, PICLevel, IsPIE).
   llvm::Reloc::Model RelocationModel;
@@ -238,13 +238,13 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-fcolor-diagnostics");
 
   // -fPIC and related options.
-  AddPicOptions(Args, CmdArgs);
+  addPicOptions(Args, CmdArgs);
 
   // Floating point related options
   addFloatingPointOptions(D, Args, CmdArgs);
 
-  // Handle options which are simply forwarded to -fc1.
-  forwardOptions(Args, CmdArgs);
+  // Add other compile options
+  addOtherOptions(Args, CmdArgs);
 
   // Forward -Xflang arguments to -fc1
   Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);

diff  --git a/clang/lib/Driver/ToolChains/Flang.h 
b/clang/lib/Driver/ToolChains/Flang.h
index 4d8e2e8ee5aa9..de72ac3601f96 100644
--- a/clang/lib/Driver/ToolChains/Flang.h
+++ b/clang/lib/Driver/ToolChains/Flang.h
@@ -45,15 +45,16 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
   ///
   /// \param [in] Args The list of 

[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-18 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu created 
https://github.com/llvm/llvm-project/pull/66702

Enable -rpath, -shared, and -static for the flang frontend. This brings it in 
line with clang. Fixes issue #65546.

>From 3302fb4937d75c0920e7bcf8f215e12fbe770a36 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 18 Sep 2023 15:18:24 -0600
Subject: [PATCH] [flang][Driver] Support -rpath, -shared, and -static in the
 frontend

Enable -rpath, -shared, and -static for the flang frontend. This brings it in
line with clang. Fixes issue #65546.
---
 clang/include/clang/Driver/Options.td |  7 +--
 flang/test/Driver/linker-flags.f90| 16 
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..bf4c76d4555d152 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5165,7 +5165,8 @@ def resource_dir : Separate<["-"], "resource-dir">,
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias;
-def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group;
+def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def rtlib_EQ : Joined<["-", "--"], "rtlib=">,
   HelpText<"Compiler runtime library to use">;
 def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, 
Flags<[NoArgumentUnused]>,
@@ -5216,7 +5217,8 @@ def segs__read__only__addr : Separate<["-"], 
"segs_read_only_addr">;
 def segs__read__write__addr : Separate<["-"], "segs_read_write_addr">;
 def segs__read__ : Joined<["-"], "segs_read_">;
 def shared_libgcc : Flag<["-"], "shared-libgcc">;
-def shared : Flag<["-", "--"], "shared">, Group;
+def shared : Flag<["-", "--"], "shared">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def single__module : Flag<["-"], "single_module">;
 def specs_EQ : Joined<["-", "--"], "specs=">, Group;
 def specs : Separate<["-", "--"], "specs">, Flags<[Unsupported]>;
@@ -5226,6 +5228,7 @@ def start_no_unused_arguments : Flag<["--"], 
"start-no-unused-arguments">,
 def static_libgcc : Flag<["-"], "static-libgcc">;
 def static_libstdcxx : Flag<["-"], "static-libstdc++">;
 def static : Flag<["-", "--"], "static">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">,
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..9a9ec5d28acb9c7 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -50,3 +50,19 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
+! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+
+! RUN: %flang -### -shared %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
+! CHECK-SHARED: ld{{.*}} "-shared"
+
+! RUN: %flang -### -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
+! CHECK-STATIC: ld{{.*}} "-static"
+

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


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-20 Thread Tarun Prabhu via cfe-commits


@@ -50,3 +50,19 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \

tarunprabhu wrote:

Are you suggesting combining `-rpath -shared` in one command and `-rpath 
-static` in another? Also, there is the option of putting all three in one 
command because `shared` and `-static` may be used simultaneously? Do I 
understand you correctly? 

If so, isn't it better to have smaller commands that test one thing unless we 
explicitly want to check combinations?

https://github.com/llvm/llvm-project/pull/66702
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-21 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/66702

>From 3302fb4937d75c0920e7bcf8f215e12fbe770a36 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 18 Sep 2023 15:18:24 -0600
Subject: [PATCH 1/2] [flang][Driver] Support -rpath, -shared, and -static in
 the frontend

Enable -rpath, -shared, and -static for the flang frontend. This brings it in
line with clang. Fixes issue #65546.
---
 clang/include/clang/Driver/Options.td |  7 +--
 flang/test/Driver/linker-flags.f90| 16 
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..bf4c76d4555d152 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5165,7 +5165,8 @@ def resource_dir : Separate<["-"], "resource-dir">,
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias;
-def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group;
+def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def rtlib_EQ : Joined<["-", "--"], "rtlib=">,
   HelpText<"Compiler runtime library to use">;
 def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, 
Flags<[NoArgumentUnused]>,
@@ -5216,7 +5217,8 @@ def segs__read__only__addr : Separate<["-"], 
"segs_read_only_addr">;
 def segs__read__write__addr : Separate<["-"], "segs_read_write_addr">;
 def segs__read__ : Joined<["-"], "segs_read_">;
 def shared_libgcc : Flag<["-"], "shared-libgcc">;
-def shared : Flag<["-", "--"], "shared">, Group;
+def shared : Flag<["-", "--"], "shared">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def single__module : Flag<["-"], "single_module">;
 def specs_EQ : Joined<["-", "--"], "specs=">, Group;
 def specs : Separate<["-", "--"], "specs">, Flags<[Unsupported]>;
@@ -5226,6 +5228,7 @@ def start_no_unused_arguments : Flag<["--"], 
"start-no-unused-arguments">,
 def static_libgcc : Flag<["-"], "static-libgcc">;
 def static_libstdcxx : Flag<["-"], "static-libstdc++">;
 def static : Flag<["-", "--"], "static">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">,
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..9a9ec5d28acb9c7 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -50,3 +50,19 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
+! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+
+! RUN: %flang -### -shared %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
+! CHECK-SHARED: ld{{.*}} "-shared"
+
+! RUN: %flang -### -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
+! CHECK-STATIC: ld{{.*}} "-static"
+

>From 653d215a59fc1ab71784776d52a32005359ee93e Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 07:47:28 -0600
Subject: [PATCH 2/2] Test all link flags in a single test.

---
 flang/test/Driver/linker-flags.f90 | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 9a9ec5d28acb9c7..c9cc851fa607ae8 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -54,15 +54,11 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
-! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+! RUN: %flang -### -rpath /path/to/dir -shared -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-LINKER-FLAGS %s
+! CHECK-LINKER-FLAGS: ld
+! CHECK-LINKER-FLAGS-DAG: "-rpath" "/path/to/dir"
+! CHECK-LINKER-FLAGS-DAG: "-shared"
+! CHECK-LINKER-FLAGS-DAG: "-static"
 
-! RUN: %flang -### -shared %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
-! CHECK-SHARED: ld{{.*}} "-shared"
-
-! RUN: %flang -### -static %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
-! CHECK-STATIC: ld{{.*}} "-static"
 

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


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-21 Thread Tarun Prabhu via cfe-commits


@@ -50,3 +50,19 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \

tarunprabhu wrote:

Fair enough. Done.

https://github.com/llvm/llvm-project/pull/66702
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-21 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/66702

>From 3302fb4937d75c0920e7bcf8f215e12fbe770a36 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 18 Sep 2023 15:18:24 -0600
Subject: [PATCH 1/3] [flang][Driver] Support -rpath, -shared, and -static in
 the frontend

Enable -rpath, -shared, and -static for the flang frontend. This brings it in
line with clang. Fixes issue #65546.
---
 clang/include/clang/Driver/Options.td |  7 +--
 flang/test/Driver/linker-flags.f90| 16 
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..bf4c76d4555d152 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5165,7 +5165,8 @@ def resource_dir : Separate<["-"], "resource-dir">,
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias;
-def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group;
+def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def rtlib_EQ : Joined<["-", "--"], "rtlib=">,
   HelpText<"Compiler runtime library to use">;
 def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, 
Flags<[NoArgumentUnused]>,
@@ -5216,7 +5217,8 @@ def segs__read__only__addr : Separate<["-"], 
"segs_read_only_addr">;
 def segs__read__write__addr : Separate<["-"], "segs_read_write_addr">;
 def segs__read__ : Joined<["-"], "segs_read_">;
 def shared_libgcc : Flag<["-"], "shared-libgcc">;
-def shared : Flag<["-", "--"], "shared">, Group;
+def shared : Flag<["-", "--"], "shared">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def single__module : Flag<["-"], "single_module">;
 def specs_EQ : Joined<["-", "--"], "specs=">, Group;
 def specs : Separate<["-", "--"], "specs">, Flags<[Unsupported]>;
@@ -5226,6 +5228,7 @@ def start_no_unused_arguments : Flag<["--"], 
"start-no-unused-arguments">,
 def static_libgcc : Flag<["-"], "static-libgcc">;
 def static_libstdcxx : Flag<["-"], "static-libstdc++">;
 def static : Flag<["-", "--"], "static">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">,
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..9a9ec5d28acb9c7 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -50,3 +50,19 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
+! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+
+! RUN: %flang -### -shared %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
+! CHECK-SHARED: ld{{.*}} "-shared"
+
+! RUN: %flang -### -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
+! CHECK-STATIC: ld{{.*}} "-static"
+

>From 653d215a59fc1ab71784776d52a32005359ee93e Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 07:47:28 -0600
Subject: [PATCH 2/3] Test all link flags in a single test.

---
 flang/test/Driver/linker-flags.f90 | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 9a9ec5d28acb9c7..c9cc851fa607ae8 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -54,15 +54,11 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
-! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+! RUN: %flang -### -rpath /path/to/dir -shared -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-LINKER-FLAGS %s
+! CHECK-LINKER-FLAGS: ld
+! CHECK-LINKER-FLAGS-DAG: "-rpath" "/path/to/dir"
+! CHECK-LINKER-FLAGS-DAG: "-shared"
+! CHECK-LINKER-FLAGS-DAG: "-static"
 
-! RUN: %flang -### -shared %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
-! CHECK-SHARED: ld{{.*}} "-shared"
-
-! RUN: %flang -### -static %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
-! CHECK-STATIC: ld{{.*}} "-static"
 

>From e080beb011db6ad26c07deab0fe7178895ed3c99 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 12:36:31 -0600
Subject: [PATCH 3/3] Delete trailing newlines. Rename prefix.

---
 flang/test/Driver/linker-flags.f90 | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driv

[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-21 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/66702

>From 3302fb4937d75c0920e7bcf8f215e12fbe770a36 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 18 Sep 2023 15:18:24 -0600
Subject: [PATCH 1/4] [flang][Driver] Support -rpath, -shared, and -static in
 the frontend

Enable -rpath, -shared, and -static for the flang frontend. This brings it in
line with clang. Fixes issue #65546.
---
 clang/include/clang/Driver/Options.td |  7 +--
 flang/test/Driver/linker-flags.f90| 16 
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..bf4c76d4555d152 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5165,7 +5165,8 @@ def resource_dir : Separate<["-"], "resource-dir">,
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias;
-def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group;
+def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def rtlib_EQ : Joined<["-", "--"], "rtlib=">,
   HelpText<"Compiler runtime library to use">;
 def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, 
Flags<[NoArgumentUnused]>,
@@ -5216,7 +5217,8 @@ def segs__read__only__addr : Separate<["-"], 
"segs_read_only_addr">;
 def segs__read__write__addr : Separate<["-"], "segs_read_write_addr">;
 def segs__read__ : Joined<["-"], "segs_read_">;
 def shared_libgcc : Flag<["-"], "shared-libgcc">;
-def shared : Flag<["-", "--"], "shared">, Group;
+def shared : Flag<["-", "--"], "shared">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def single__module : Flag<["-"], "single_module">;
 def specs_EQ : Joined<["-", "--"], "specs=">, Group;
 def specs : Separate<["-", "--"], "specs">, Flags<[Unsupported]>;
@@ -5226,6 +5228,7 @@ def start_no_unused_arguments : Flag<["--"], 
"start-no-unused-arguments">,
 def static_libgcc : Flag<["-"], "static-libgcc">;
 def static_libstdcxx : Flag<["-"], "static-libstdc++">;
 def static : Flag<["-", "--"], "static">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">,
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..9a9ec5d28acb9c7 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -50,3 +50,19 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
+! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+
+! RUN: %flang -### -shared %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
+! CHECK-SHARED: ld{{.*}} "-shared"
+
+! RUN: %flang -### -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
+! CHECK-STATIC: ld{{.*}} "-static"
+

>From 653d215a59fc1ab71784776d52a32005359ee93e Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 07:47:28 -0600
Subject: [PATCH 2/4] Test all link flags in a single test.

---
 flang/test/Driver/linker-flags.f90 | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 9a9ec5d28acb9c7..c9cc851fa607ae8 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -54,15 +54,11 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
-! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+! RUN: %flang -### -rpath /path/to/dir -shared -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-LINKER-FLAGS %s
+! CHECK-LINKER-FLAGS: ld
+! CHECK-LINKER-FLAGS-DAG: "-rpath" "/path/to/dir"
+! CHECK-LINKER-FLAGS-DAG: "-shared"
+! CHECK-LINKER-FLAGS-DAG: "-static"
 
-! RUN: %flang -### -shared %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
-! CHECK-SHARED: ld{{.*}} "-shared"
-
-! RUN: %flang -### -static %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
-! CHECK-STATIC: ld{{.*}} "-static"
 

>From e080beb011db6ad26c07deab0fe7178895ed3c99 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 12:36:31 -0600
Subject: [PATCH 3/4] Delete trailing newlines. Rename prefix.

---
 flang/test/Driver/linker-flags.f90 | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driv

[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-21 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

Thanks @MaskRay and @banach-space for taking a look at this. I have marked the 
test as unsupported on windows because of a failing buildkite. I don't have 
access to a Windows machine so I can't add an equivalent test for that platform.

https://github.com/llvm/llvm-project/pull/66702
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-21 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu resolved 
https://github.com/llvm/llvm-project/pull/66702
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-21 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu resolved 
https://github.com/llvm/llvm-project/pull/66702
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-25 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

> I think Windows does not work likely because `ld` is absent in PATH. You need 
> `-Bxxx/bin` to specify a directory that contains `ld`, but I don't remember 
> whether `ld.exe` is needed instead.

I think what I saw on the buildkite was Link.exe, but I don't know if that is 
always the case.


https://github.com/llvm/llvm-project/pull/66702
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-25 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/66702

>From 3302fb4937d75c0920e7bcf8f215e12fbe770a36 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 18 Sep 2023 15:18:24 -0600
Subject: [PATCH 1/5] [flang][Driver] Support -rpath, -shared, and -static in
 the frontend

Enable -rpath, -shared, and -static for the flang frontend. This brings it in
line with clang. Fixes issue #65546.
---
 clang/include/clang/Driver/Options.td |  7 +--
 flang/test/Driver/linker-flags.f90| 16 
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..bf4c76d4555d152 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5165,7 +5165,8 @@ def resource_dir : Separate<["-"], "resource-dir">,
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias;
-def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group;
+def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def rtlib_EQ : Joined<["-", "--"], "rtlib=">,
   HelpText<"Compiler runtime library to use">;
 def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, 
Flags<[NoArgumentUnused]>,
@@ -5216,7 +5217,8 @@ def segs__read__only__addr : Separate<["-"], 
"segs_read_only_addr">;
 def segs__read__write__addr : Separate<["-"], "segs_read_write_addr">;
 def segs__read__ : Joined<["-"], "segs_read_">;
 def shared_libgcc : Flag<["-"], "shared-libgcc">;
-def shared : Flag<["-", "--"], "shared">, Group;
+def shared : Flag<["-", "--"], "shared">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def single__module : Flag<["-"], "single_module">;
 def specs_EQ : Joined<["-", "--"], "specs=">, Group;
 def specs : Separate<["-", "--"], "specs">, Flags<[Unsupported]>;
@@ -5226,6 +5228,7 @@ def start_no_unused_arguments : Flag<["--"], 
"start-no-unused-arguments">,
 def static_libgcc : Flag<["-"], "static-libgcc">;
 def static_libstdcxx : Flag<["-"], "static-libstdc++">;
 def static : Flag<["-", "--"], "static">, Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
 def std_EQ : Joined<["-", "--"], "std=">,
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 09b8a224df13828..9a9ec5d28acb9c7 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -50,3 +50,19 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
+! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+
+! RUN: %flang -### -shared %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
+! CHECK-SHARED: ld{{.*}} "-shared"
+
+! RUN: %flang -### -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
+! CHECK-STATIC: ld{{.*}} "-static"
+

>From 653d215a59fc1ab71784776d52a32005359ee93e Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 07:47:28 -0600
Subject: [PATCH 2/5] Test all link flags in a single test.

---
 flang/test/Driver/linker-flags.f90 | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 9a9ec5d28acb9c7..c9cc851fa607ae8 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -54,15 +54,11 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### -rpath /path/to/dir %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-RPATH %s
-! CHECK-RPATH: ld{{.*}} "-rpath" "/path/to/dir"
+! RUN: %flang -### -rpath /path/to/dir -shared -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-LINKER-FLAGS %s
+! CHECK-LINKER-FLAGS: ld
+! CHECK-LINKER-FLAGS-DAG: "-rpath" "/path/to/dir"
+! CHECK-LINKER-FLAGS-DAG: "-shared"
+! CHECK-LINKER-FLAGS-DAG: "-static"
 
-! RUN: %flang -### -shared %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
-! CHECK-SHARED: ld{{.*}} "-shared"
-
-! RUN: %flang -### -static %s 2>&1 \
-! RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
-! CHECK-STATIC: ld{{.*}} "-static"
 

>From e080beb011db6ad26c07deab0fe7178895ed3c99 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 21 Sep 2023 12:36:31 -0600
Subject: [PATCH 3/5] Delete trailing newlines. Rename prefix.

---
 flang/test/Driver/linker-flags.f90 | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driv

[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-25 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

The buildkite 
[fails](https://buildkite.com/llvm-project/github-pull-requests/builds/3888#018acca9-e640-47a6-bfe8-3831aeddeb41)
 yet again because the link flags seem to be mapped differently. 

The link line generated on Windows is:

`"C:\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\Hostx64\\x64\\link.exe" 
"-out:a.exe" "-libpath:c:\\ws\\src\\build\\lib" "Fortran_main.lib" 
"FortranRuntime.lib" "FortranDecimal.lib" "/subsystem:console" "-nologo" "-dll" 
"-implib:a.lib" "-rpath" "/path/to/dir" 
"C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\lit-tmp-oaf0t3ny\\linker-flags-de9f45.o"`

I don't see `-shared` or `-static`. Can someone help me with this? Is `-dll` is 
the equivalent of `-shared`? Does windows support static libraries?

https://github.com/llvm/llvm-project/pull/66702
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-10-03 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

Thanks @DavidTruby. 

For this particular patch, the main concern is how the compiler flags are 
mapped to the corresponding linker flags on Windows. All of that work is done 
by clang, and I haven't touched any of it so I am not worried about 
correctness. 

The two main concerns are:

1) What are the linker flags in Windows corresponding to -static and -shared on 
*nix. 
2) Do the checks in the test need to be expanded to account for different 
linkers on Windows.



https://github.com/llvm/llvm-project/pull/66702
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-10-16 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

> I'll try to test this patch on a Windows on ARM machine. But it may take some 
> time to setup and build flang on it.

Thanks @luporl. Any help is most appreciated.

https://github.com/llvm/llvm-project/pull/66702
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-04 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/107270

>From 2f4a8503c605f7401bf9312b59a72b6b3ccdbb7f Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Wed, 4 Sep 2024 10:24:31 -0600
Subject: [PATCH 1/2] [flang][Driver] Preliminary support for -ftime-report

The behavior is not entirely consistent with that of clang for the moment
since detailed timing information on the LLVM IR optimization and code
generation passes is not provided. The -ftime-report= option is also not enabled
since that is only relevant for information about the LLVM IR passes. However,
some code to handle that option has been included, to make it easier to support
the option when the issues blocking it are resolved. A FortranSupport library
has been created that is intended to mirror the LLVM and MLIR support libraries.
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  4 +-
 .../include/flang/Frontend/CompilerInstance.h | 59 +++
 .../flang/Frontend/CompilerInvocation.h   | 15 
 flang/include/flang/Support/StringOstream.h   | 32 
 flang/include/flang/Support/Timing.h  | 27 +++
 flang/lib/CMakeLists.txt  |  1 +
 flang/lib/Frontend/CMakeLists.txt |  1 +
 flang/lib/Frontend/CompilerInstance.cpp   | 51 -
 flang/lib/Frontend/CompilerInvocation.cpp | 18 +
 flang/lib/Frontend/FrontendActions.cpp| 73 +--
 flang/lib/Support/CMakeLists.txt  |  9 +++
 flang/lib/Support/Timing.cpp  | 67 +
 flang/test/Driver/time-report-eq.f90  | 18 +
 flang/test/Driver/time-report.f90 | 22 ++
 15 files changed, 390 insertions(+), 9 deletions(-)
 create mode 100644 flang/include/flang/Support/StringOstream.h
 create mode 100644 flang/include/flang/Support/Timing.h
 create mode 100644 flang/lib/Support/CMakeLists.txt
 create mode 100644 flang/lib/Support/Timing.cpp
 create mode 100644 flang/test/Driver/time-report-eq.f90
 create mode 100644 flang/test/Driver/time-report.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1b9b3f2c6600a3..6a0a2b40cd192e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4012,7 +4012,7 @@ defm threadsafe_statics : 
BoolFOption<"threadsafe-statics",
   "Do not emit code to make initialization of local statics thread 
safe">,
   PosFlag>;
 def ftime_report : Flag<["-"], "ftime-report">, Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   MarshallingInfoFlag>;
 def ftime_report_EQ: Joined<["-"], "ftime-report=">, Group,
   Visibility<[ClangOption, CC1Option]>, Values<"per-pass,per-pass-run">,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6ce79d27e98c48..c1e724d7761dc0 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -150,7 +150,9 @@ void Flang::addCodegenOptions(const ArgList &Args,
 options::OPT_flang_deprecated_no_hlfir,
 options::OPT_flang_experimental_integer_overflow,
 options::OPT_fno_ppc_native_vec_elem_order,
-options::OPT_fppc_native_vec_elem_order});
+options::OPT_fppc_native_vec_elem_order,
+options::OPT_ftime_report,
+options::OPT_ftime_report_EQ});
 }
 
 void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
diff --git a/flang/include/flang/Frontend/CompilerInstance.h 
b/flang/include/flang/Frontend/CompilerInstance.h
index 4fcc59f7cf577b..2844900063a9e5 100644
--- a/flang/include/flang/Frontend/CompilerInstance.h
+++ b/flang/include/flang/Frontend/CompilerInstance.h
@@ -20,6 +20,7 @@
 #include "flang/Parser/provenance.h"
 #include "flang/Semantics/runtime-type-info.h"
 #include "flang/Semantics/semantics.h"
+#include "flang/Support/StringOstream.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
 
@@ -85,6 +86,27 @@ class CompilerInstance {
   /// facilitate this. It is optional and will normally be just a nullptr.
   std::unique_ptr outputStream;
 
+  /// @name Timing
+  /// Objects needed when timing is enabled.
+  /// @{
+  /// The timing manager.
+  mlir::DefaultTimingManager timingMgr;
+
+  /// The root of the timingScope. This will be reset in @ref executeAction if
+  /// timers have been enabled.
+  mlir::TimingScope timingScopeRoot;
+
+  /// @name Timing stream
+  /// The output streams to capture the timing. Three different streams are
+  /// needed because the timing classes all work slightly differently. We 
create
+  /// these streams so we have control over when and how the timing is
+  /// displayed. Otherwise, the 

[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tarun Prabhu via cfe-commits


@@ -143,6 +144,14 @@ class CompilerInvocation : public CompilerInvocationBase {
   },
   };
 
+  /// Whether to time the invocation. Set when -ftime-report or -ftime-report=
+  /// is enabled.
+  bool enableTimers;
+
+  /// Whether to report the timing of each run of an LLVM pass. Set when
+  /// -ftime-report=per-pass-run is enabled.
+  bool timeLLVMPassesPerRun;

tarunprabhu wrote:

That is reasonable. I will remove some of the related code and add TODO's in 
their place.

https://github.com/llvm/llvm-project/pull/107270
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tarun Prabhu via cfe-commits


@@ -4,6 +4,7 @@ add_subdirectory(Decimal)
 add_subdirectory(Lower)
 add_subdirectory(Parser)
 add_subdirectory(Semantics)
+add_subdirectory(Support)

tarunprabhu wrote:

Mainly to match the layout in both `llvm` and `mlir`. In principle, it could be 
used in other tools, both in-tree and out-of-tree. It feels odd to have to link 
against the entire frontend just to get a timer. 

https://github.com/llvm/llvm-project/pull/107270
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tarun Prabhu via cfe-commits


@@ -254,6 +276,43 @@ class CompilerInstance {
   /// Produces the string which represents target feature
   std::string getTargetFeatures();
 
+  /// {
+  /// @name Timing
+  /// @{
+  bool isTimingEnabled() { return timingMgr.isEnabled(); }

tarunprabhu wrote:

Good point. I will remove it.

https://github.com/llvm/llvm-project/pull/107270
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tarun Prabhu via cfe-commits


@@ -176,6 +205,26 @@ bool CompilerInstance::executeAction(FrontendAction &act) {
   act.endSourceFile();
 }
   }
+
+  if (timingMgr.isEnabled()) {
+timingScopeRoot.stop();
+
+// Write the timings to the associated output stream and clear all timers.
+// We need to provide another stream because the TimingManager will attempt
+// to print in its destructor even if it has been cleared. By the time that
+// destructor runs, the output streams will have been destroyed, so give it
+// a null stream.
+timingMgr.print();
+timingMgr.setOutput(
+
Fortran::support::createTimingFormatterText(mlir::thread_safe_nulls()));
+
+// This is deliberately done in "reverse" order and does not match the
+// behavior of clang.

tarunprabhu wrote:

The printing of timings in the case of clang is done when the timer handler's 
destructors are run. I don't think they are guaranteed to run in a specific 
order. In this case, we are guaranteeing that the timings will be printed in 
"reverse", starting from code generation, then LLVM IR optimizations and then 
the MLIR and parsing. 

I will edit the comment.

https://github.com/llvm/llvm-project/pull/107270
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/107270

>From 2f4a8503c605f7401bf9312b59a72b6b3ccdbb7f Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Wed, 4 Sep 2024 10:24:31 -0600
Subject: [PATCH 1/3] [flang][Driver] Preliminary support for -ftime-report

The behavior is not entirely consistent with that of clang for the moment
since detailed timing information on the LLVM IR optimization and code
generation passes is not provided. The -ftime-report= option is also not enabled
since that is only relevant for information about the LLVM IR passes. However,
some code to handle that option has been included, to make it easier to support
the option when the issues blocking it are resolved. A FortranSupport library
has been created that is intended to mirror the LLVM and MLIR support libraries.
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  4 +-
 .../include/flang/Frontend/CompilerInstance.h | 59 +++
 .../flang/Frontend/CompilerInvocation.h   | 15 
 flang/include/flang/Support/StringOstream.h   | 32 
 flang/include/flang/Support/Timing.h  | 27 +++
 flang/lib/CMakeLists.txt  |  1 +
 flang/lib/Frontend/CMakeLists.txt |  1 +
 flang/lib/Frontend/CompilerInstance.cpp   | 51 -
 flang/lib/Frontend/CompilerInvocation.cpp | 18 +
 flang/lib/Frontend/FrontendActions.cpp| 73 +--
 flang/lib/Support/CMakeLists.txt  |  9 +++
 flang/lib/Support/Timing.cpp  | 67 +
 flang/test/Driver/time-report-eq.f90  | 18 +
 flang/test/Driver/time-report.f90 | 22 ++
 15 files changed, 390 insertions(+), 9 deletions(-)
 create mode 100644 flang/include/flang/Support/StringOstream.h
 create mode 100644 flang/include/flang/Support/Timing.h
 create mode 100644 flang/lib/Support/CMakeLists.txt
 create mode 100644 flang/lib/Support/Timing.cpp
 create mode 100644 flang/test/Driver/time-report-eq.f90
 create mode 100644 flang/test/Driver/time-report.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1b9b3f2c6600a3..6a0a2b40cd192e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4012,7 +4012,7 @@ defm threadsafe_statics : 
BoolFOption<"threadsafe-statics",
   "Do not emit code to make initialization of local statics thread 
safe">,
   PosFlag>;
 def ftime_report : Flag<["-"], "ftime-report">, Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   MarshallingInfoFlag>;
 def ftime_report_EQ: Joined<["-"], "ftime-report=">, Group,
   Visibility<[ClangOption, CC1Option]>, Values<"per-pass,per-pass-run">,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6ce79d27e98c48..c1e724d7761dc0 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -150,7 +150,9 @@ void Flang::addCodegenOptions(const ArgList &Args,
 options::OPT_flang_deprecated_no_hlfir,
 options::OPT_flang_experimental_integer_overflow,
 options::OPT_fno_ppc_native_vec_elem_order,
-options::OPT_fppc_native_vec_elem_order});
+options::OPT_fppc_native_vec_elem_order,
+options::OPT_ftime_report,
+options::OPT_ftime_report_EQ});
 }
 
 void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
diff --git a/flang/include/flang/Frontend/CompilerInstance.h 
b/flang/include/flang/Frontend/CompilerInstance.h
index 4fcc59f7cf577b..2844900063a9e5 100644
--- a/flang/include/flang/Frontend/CompilerInstance.h
+++ b/flang/include/flang/Frontend/CompilerInstance.h
@@ -20,6 +20,7 @@
 #include "flang/Parser/provenance.h"
 #include "flang/Semantics/runtime-type-info.h"
 #include "flang/Semantics/semantics.h"
+#include "flang/Support/StringOstream.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
 
@@ -85,6 +86,27 @@ class CompilerInstance {
   /// facilitate this. It is optional and will normally be just a nullptr.
   std::unique_ptr outputStream;
 
+  /// @name Timing
+  /// Objects needed when timing is enabled.
+  /// @{
+  /// The timing manager.
+  mlir::DefaultTimingManager timingMgr;
+
+  /// The root of the timingScope. This will be reset in @ref executeAction if
+  /// timers have been enabled.
+  mlir::TimingScope timingScopeRoot;
+
+  /// @name Timing stream
+  /// The output streams to capture the timing. Three different streams are
+  /// needed because the timing classes all work slightly differently. We 
create
+  /// these streams so we have control over when and how the timing is
+  /// displayed. Otherwise, the 

[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tarun Prabhu via cfe-commits


@@ -143,6 +144,14 @@ class CompilerInvocation : public CompilerInvocationBase {
   },
   };
 
+  /// Whether to time the invocation. Set when -ftime-report or -ftime-report=
+  /// is enabled.
+  bool enableTimers;
+
+  /// Whether to report the timing of each run of an LLVM pass. Set when
+  /// -ftime-report=per-pass-run is enabled.
+  bool timeLLVMPassesPerRun;

tarunprabhu wrote:

I ended up not adding any TODOs. It didn't seem necessary.

https://github.com/llvm/llvm-project/pull/107270
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Support --no-warnings option (PR #107455)

2024-09-05 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu created 
https://github.com/llvm/llvm-project/pull/107455

Because of the way visibility is implemented in Options.td, options that are 
aliases do not inherit the visibility of the option being aliased. Therefore, 
explicitly set the visibility of the alias to be the same as the aliased option.

This partially addresses https://github.com/llvm/llvm-project/issues/89888

>From 90fcfe2139a08677bfd1e4d735d079bcc2d6db42 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 5 Sep 2024 08:47:15 -0600
Subject: [PATCH 1/2] Throwaway commit prior to context switch

---
 clang/lib/Driver/ToolChains/Flang.cpp | 1 +
 flang/lib/Frontend/CompilerInvocation.cpp | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6ce79d27e98c48..fc6762f6bdae40 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -777,6 +777,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // Disable all warnings
   // TODO: Handle interactions between -w, -pedantic, -Wall, -WOption
   Args.AddLastArg(CmdArgs, options::OPT_w);
+  Args.AddLastArg(CmdArgs, options::OPT__no_warnings);
 
   // Forward flags for OpenMP. We don't do this if the current action is an
   // device offloading action other than OpenMP.
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 1d73397d330178..9b35d54f61a0d0 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -942,7 +942,8 @@ static bool parseDialectArgs(CompilerInvocation &res, 
llvm::opt::ArgList &args,
   }
 
   // -w
-  if (args.hasArg(clang::driver::options::OPT_w))
+  if (args.hasArg(clang::driver::options::OPT_w,
+  clang::driver::options::OPT__no_warnings))
 res.setDisableWarnings();
 
   // -std=f2018

>From 3e0f2ce417ea8193384031caa3ba17fa654293f0 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 5 Sep 2024 13:34:51 -0600
Subject: [PATCH 2/2] [flang][Driver] Support --no-warnings option

Because of the way visibility is implemented in Options.td, options that are
aliases do not inherit the visibility of the option being aliased. For now,
explicitly set the visibility of the alias to be the same as the aliased option.

This partially addresses https://github.com/llvm/llvm-project/issues/89888
---
 clang/include/clang/Driver/Options.td | 4 +++-
 flang/test/Driver/w-option.f90| 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1b9b3f2c6600a3..049c6cf4cef955 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5978,7 +5978,9 @@ def _no_line_commands : Flag<["--"], "no-line-commands">, 
Alias;
 def _no_standard_includes : Flag<["--"], "no-standard-includes">, 
Alias;
 def _no_standard_libraries : Flag<["--"], "no-standard-libraries">, 
Alias;
 def _no_undefined : Flag<["--"], "no-undefined">, Flags<[LinkerInput]>;
-def _no_warnings : Flag<["--"], "no-warnings">, Alias;
+def _no_warnings : Flag<["--"], "no-warnings">,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
+  Alias;
 def _optimize_EQ : Joined<["--"], "optimize=">, Alias;
 def _optimize : Flag<["--"], "optimize">, Alias;
 def _output_class_directory_EQ : Joined<["--"], "output-class-directory=">, 
Alias;
diff --git a/flang/test/Driver/w-option.f90 b/flang/test/Driver/w-option.f90
index e34cddaab373a1..b6aa44a06ab729 100644
--- a/flang/test/Driver/w-option.f90
+++ b/flang/test/Driver/w-option.f90
@@ -4,6 +4,9 @@
 ! Test that the warnings are not generated with `-w` option.
 ! RUN: %flang -c -w %s 2>&1 | FileCheck --allow-empty %s -check-prefix=WARNING
 
+! Test that the warnings are not generated with `--no-warnings` option.
+! RUN: %flang -c --no-warnings %s 2>&1 | FileCheck --allow-empty %s 
-check-prefix=WARNING
+
 ! Test that warnings are portability messages are generated.
 ! RUN: %flang -c -pedantic %s 2>&1 | FileCheck %s 
-check-prefixes=DEFAULT,PORTABILITY
 

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


[clang] [flang] [flang][Driver] Support --no-warnings option (PR #107455)

2024-09-05 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/107455

>From 984032c16fd7ebadf06737973ad3a165b689cc3c Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 5 Sep 2024 13:34:51 -0600
Subject: [PATCH] [flang][Driver] Support --no-warnings option

Because of the way visibility is implemented in Options.td, options that are
aliases do not inherit the visibility of the option being aliased. For now,
explicitly set the visibility of the alias to be the same as the aliased option.

This partially addresses https://github.com/llvm/llvm-project/issues/89888
---
 clang/include/clang/Driver/Options.td | 4 +++-
 flang/test/Driver/w-option.f90| 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1b9b3f2c6600a3..049c6cf4cef955 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5978,7 +5978,9 @@ def _no_line_commands : Flag<["--"], "no-line-commands">, 
Alias;
 def _no_standard_includes : Flag<["--"], "no-standard-includes">, 
Alias;
 def _no_standard_libraries : Flag<["--"], "no-standard-libraries">, 
Alias;
 def _no_undefined : Flag<["--"], "no-undefined">, Flags<[LinkerInput]>;
-def _no_warnings : Flag<["--"], "no-warnings">, Alias;
+def _no_warnings : Flag<["--"], "no-warnings">,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
+  Alias;
 def _optimize_EQ : Joined<["--"], "optimize=">, Alias;
 def _optimize : Flag<["--"], "optimize">, Alias;
 def _output_class_directory_EQ : Joined<["--"], "output-class-directory=">, 
Alias;
diff --git a/flang/test/Driver/w-option.f90 b/flang/test/Driver/w-option.f90
index e34cddaab373a1..b6aa44a06ab729 100644
--- a/flang/test/Driver/w-option.f90
+++ b/flang/test/Driver/w-option.f90
@@ -4,6 +4,9 @@
 ! Test that the warnings are not generated with `-w` option.
 ! RUN: %flang -c -w %s 2>&1 | FileCheck --allow-empty %s -check-prefix=WARNING
 
+! Test that the warnings are not generated with `--no-warnings` option.
+! RUN: %flang -c --no-warnings %s 2>&1 | FileCheck --allow-empty %s 
-check-prefix=WARNING
+
 ! Test that warnings are portability messages are generated.
 ! RUN: %flang -c -pedantic %s 2>&1 | FileCheck %s 
-check-prefixes=DEFAULT,PORTABILITY
 

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


[clang] [flang] [flang][Driver] Support -Qunused-arguments (PR #107462)

2024-09-05 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu created 
https://github.com/llvm/llvm-project/pull/107462

This partially addresses: https://github.com/llvm/llvm-project/issues/89888

>From 302ee0694f6e2528076a4e2a98ca37213e78efae Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 5 Sep 2024 14:33:50 -0600
Subject: [PATCH] [flang][Driver] Support -Qunused-arguments

This partially addresses: https://github.com/llvm/llvm-project/issues/89888
---
 clang/include/clang/Driver/Options.td| 2 +-
 flang/test/Driver/q-unused-arguments.f90 | 5 +
 2 files changed, 6 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Driver/q-unused-arguments.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1b9b3f2c6600a3..e3a98bab2a5020 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -949,7 +949,7 @@ def : Flag<["-"], "fident">, Group, Alias,
 def : Flag<["-"], "fno-ident">, Group, Alias,
   Visibility<[ClangOption, CLOption, DXCOption, CC1Option]>;
 def Qunused_arguments : Flag<["-"], "Qunused-arguments">,
-  Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
+  Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption, 
FlangOption]>,
   HelpText<"Don't emit warning for unused driver arguments">;
 def Q : Flag<["-"], "Q">, IgnoredGCCCompat;
 def S : Flag<["-"], "S">, Flags<[NoXarchOption]>,
diff --git a/flang/test/Driver/q-unused-arguments.f90 
b/flang/test/Driver/q-unused-arguments.f90
new file mode 100644
index 00..95210da888fc55
--- /dev/null
+++ b/flang/test/Driver/q-unused-arguments.f90
@@ -0,0 +1,5 @@
+! RUN: %flang -Qunused-arguments -c -o /dev/null %s -L. 2>&1 | FileCheck %s 
--allow-empty
+
+! CHECK-NOT: argument unused during compilation
+
+end program

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


[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-09-05 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/102975

>From 6df2f16e9b875f598cb00738b6fb9e8a2d7fe448 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 14 ++--
 clang/lib/Driver/CMakeLists.txt   |  1 +
 clang/lib/Driver/ToolChains/Clang.cpp | 48 ++--
 clang/lib/Driver/ToolChains/CommonUtils.cpp   | 76 +++
 clang/lib/Driver/ToolChains/CommonUtils.h | 44 +++
 clang/lib/Driver/ToolChains/Flang.cpp | 15 
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 +-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 
 flang/test/Driver/frecord-command-line.f90| 16 
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   | 10 ++-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 +
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 +
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 24 files changed, 284 insertions(+), 59 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.cpp
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.h
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1142416e227fc8..4b8d593041d113 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1981,16 +1981,18 @@ def fparse_all_comments : Flag<["-"], 
"fparse-all-comments">, Group,
   MarshallingInfoFlag>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
-  DocBrief<[{Generate a section named ".GCC.command.line" containing the clang
+  DocBrief<[{Generate a section named ".GCC.command.line" containing the
 driver command-line. After linking, the section may contain multiple command
 lines, which will be individually terminated by null bytes. Separate arguments
 within a command line are combined with spaces; spaces and backslashes within 
an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7123,6 +7125,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoString>;
 
 } // let Visibility = [CC1Option, CC1AsOption, FC1Option]
 
@@ -7143,9 +7148,6 @@ def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">,
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">,
   MarshallingInfoString>;
-def record_command_line : Separate<["-"], "record-command-line">,
-  HelpText<"The string to embed in the .LLVM.command.line section.">,
-  MarshallingInfoString>;
 def compress_debug_sections_EQ : Joined<["-", "--"], 
"compress-debug-sections=">,
 HelpText<"DWARF debug sections compression type">, 
Values<"none,zlib,zstd">,
  

[clang] [flang] [flang][Driver] Support -Xlinker in flang (PR #107472)

2024-09-05 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu edited 
https://github.com/llvm/llvm-project/pull/107472
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Support -Qunused-arguments (PR #107462)

2024-09-06 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu closed 
https://github.com/llvm/llvm-project/pull/107462
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Support -Xlinker in flang (PR #107472)

2024-09-09 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/107472

>From acb5cf2af69f7941c24c4e53b67f9f2d4a18dbc8 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 5 Sep 2024 15:41:54 -0600
Subject: [PATCH 1/2] [flang][Driver] Support -Xlinker in flang

---
 clang/include/clang/Driver/Options.td | 1 +
 flang/test/Driver/xlinker.f90 | 6 ++
 2 files changed, 7 insertions(+)
 create mode 100644 flang/test/Driver/xlinker.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1b9b3f2c6600a3..136d979ed7200e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1051,6 +1051,7 @@ def z : Separate<["-"], "z">, Flags<[LinkerInput]>,
 def offload_link : Flag<["--"], "offload-link">, Group,
   HelpText<"Use the new offloading linker to perform the link job.">;
 def Xlinker : Separate<["-"], "Xlinker">, Flags<[LinkerInput, RenderAsInput]>,
+  Visibility<[ClangOption, CLOption, FlangOption, DXCOption]>,
   HelpText<"Pass  to the linker">, MetaVarName<"">,
   Group;
 def Xoffload_linker : JoinedAndSeparate<["-"], "Xoffload-linker">,
diff --git a/flang/test/Driver/xlinker.f90 b/flang/test/Driver/xlinker.f90
new file mode 100644
index 00..8bb1f7e99ae238
--- /dev/null
+++ b/flang/test/Driver/xlinker.f90
@@ -0,0 +1,6 @@
+! RUN: %flang -### -o /dev/null %s -Xlinker -rpath=/not/a/real/path 2>&1 | 
FileCheck %s
+
+! CHECK: "-fc1"
+! CHECK-NEXT: "-rpath=/not/a/real/path"
+
+end program

>From fcfe90910382ded9e58868d8feef2195f00dd4f0 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 9 Sep 2024 09:22:44 -0600
Subject: [PATCH 2/2] Update test to address reviewer comments. Add test with
 multiple -instances of -Xlinker options

---
 flang/test/Driver/xlinker.f90 | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/flang/test/Driver/xlinker.f90 b/flang/test/Driver/xlinker.f90
index 8bb1f7e99ae238..071fc6e3dc9027 100644
--- a/flang/test/Driver/xlinker.f90
+++ b/flang/test/Driver/xlinker.f90
@@ -1,6 +1,8 @@
-! RUN: %flang -### -o /dev/null %s -Xlinker -rpath=/not/a/real/path 2>&1 | 
FileCheck %s
+! RUN: %flang -### -o /dev/null %s -Xlinker -rpath=/not/a/real/path 2>&1 | 
FileCheck --check-prefix=SINGLE %s
+! RUN: %flang -### -o /dev/null %s -Xlinker -rpath -Xlinker /not/a/real/path 
2>&1 | FileCheck --check-prefix=MULTIPLE %s
 
-! CHECK: "-fc1"
-! CHECK-NEXT: "-rpath=/not/a/real/path"
+
+! SINGLE: "-rpath=/not/a/real/path"
+! MULTIPLE: "-rpath" "/not/a/real/path"
 
 end program

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


[clang] [flang] [flang][Driver] Support -Xlinker in flang (PR #107472)

2024-09-09 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/107472

>From acb5cf2af69f7941c24c4e53b67f9f2d4a18dbc8 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 5 Sep 2024 15:41:54 -0600
Subject: [PATCH 1/3] [flang][Driver] Support -Xlinker in flang

---
 clang/include/clang/Driver/Options.td | 1 +
 flang/test/Driver/xlinker.f90 | 6 ++
 2 files changed, 7 insertions(+)
 create mode 100644 flang/test/Driver/xlinker.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1b9b3f2c6600a3..136d979ed7200e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1051,6 +1051,7 @@ def z : Separate<["-"], "z">, Flags<[LinkerInput]>,
 def offload_link : Flag<["--"], "offload-link">, Group,
   HelpText<"Use the new offloading linker to perform the link job.">;
 def Xlinker : Separate<["-"], "Xlinker">, Flags<[LinkerInput, RenderAsInput]>,
+  Visibility<[ClangOption, CLOption, FlangOption, DXCOption]>,
   HelpText<"Pass  to the linker">, MetaVarName<"">,
   Group;
 def Xoffload_linker : JoinedAndSeparate<["-"], "Xoffload-linker">,
diff --git a/flang/test/Driver/xlinker.f90 b/flang/test/Driver/xlinker.f90
new file mode 100644
index 00..8bb1f7e99ae238
--- /dev/null
+++ b/flang/test/Driver/xlinker.f90
@@ -0,0 +1,6 @@
+! RUN: %flang -### -o /dev/null %s -Xlinker -rpath=/not/a/real/path 2>&1 | 
FileCheck %s
+
+! CHECK: "-fc1"
+! CHECK-NEXT: "-rpath=/not/a/real/path"
+
+end program

>From fcfe90910382ded9e58868d8feef2195f00dd4f0 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 9 Sep 2024 09:22:44 -0600
Subject: [PATCH 2/3] Update test to address reviewer comments. Add test with
 multiple -instances of -Xlinker options

---
 flang/test/Driver/xlinker.f90 | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/flang/test/Driver/xlinker.f90 b/flang/test/Driver/xlinker.f90
index 8bb1f7e99ae238..071fc6e3dc9027 100644
--- a/flang/test/Driver/xlinker.f90
+++ b/flang/test/Driver/xlinker.f90
@@ -1,6 +1,8 @@
-! RUN: %flang -### -o /dev/null %s -Xlinker -rpath=/not/a/real/path 2>&1 | 
FileCheck %s
+! RUN: %flang -### -o /dev/null %s -Xlinker -rpath=/not/a/real/path 2>&1 | 
FileCheck --check-prefix=SINGLE %s
+! RUN: %flang -### -o /dev/null %s -Xlinker -rpath -Xlinker /not/a/real/path 
2>&1 | FileCheck --check-prefix=MULTIPLE %s
 
-! CHECK: "-fc1"
-! CHECK-NEXT: "-rpath=/not/a/real/path"
+
+! SINGLE: "-rpath=/not/a/real/path"
+! MULTIPLE: "-rpath" "/not/a/real/path"
 
 end program

>From e61e96045c2dce556afea6bcb9debe4dffa8d94a Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 9 Sep 2024 09:51:31 -0600
Subject: [PATCH 3/3] Better tests. Do look for the linker executable name on
 the line and ensure that the passed arguments are present on that line. Test
 this for a variety of linkers and targets.

---
 flang/test/Driver/xlinker.f90 | 21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/flang/test/Driver/xlinker.f90 b/flang/test/Driver/xlinker.f90
index 071fc6e3dc9027..feafadcfcec452 100644
--- a/flang/test/Driver/xlinker.f90
+++ b/flang/test/Driver/xlinker.f90
@@ -1,8 +1,21 @@
-! RUN: %flang -### -o /dev/null %s -Xlinker -rpath=/not/a/real/path 2>&1 | 
FileCheck --check-prefix=SINGLE %s
-! RUN: %flang -### -o /dev/null %s -Xlinker -rpath -Xlinker /not/a/real/path 
2>&1 | FileCheck --check-prefix=MULTIPLE %s
+! RUN: %flang -### --target=ppc64le-linux-gnu -Xlinker -rpath -Xlinker 
/not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=aarch64-apple-darwin -Xlinker -rpath -Xlinker 
/not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=sparc-sun-solaris2.11 -Xlinker -rpath -Xlinker 
/not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=x86_64-unknown-freebsd -Xlinker -rpath -Xlinker 
/not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=x86_64-unknown-netbsd -Xlinker -rpath -Xlinker 
/not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=x86_64-unknown-openbsd -Xlinker -rpath -Xlinker 
/not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=x86_64-unknown-dragonfly -Xlinker -rpath -Xlinker 
/not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=x86_64-unknown-haiku %s -Xlinker -rpath -Xlinker 
/not/a/real/path 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=x86_64-windows-gnu -Xlinker -rpath -Xlinker 
/not/a/real/path %s 2>&1 | FileCheck %s --check-prefixes=UNIX
+! RUN: %flang -### --target=aarch64-windows-msvc -Xlinker -rpath -Xlinker 
/not/a/real/path -o obscure.exe %s 2>&1 | FileCheck %s --check-prefixes=MSVC
 
+! UNIX-LABEL: "{{.*}}ld{{(\.exe)?}}"
+! UNIX-SAME: "-rpath" "/not/a/real/path"
 
-! SINGLE: "-rpath=/not/a/real/path"
-! MULTIPLE: "-rpath" "/n

[clang] [flang] [flang][Driver] Support -Xlinker in flang (PR #107472)

2024-09-09 Thread Tarun Prabhu via cfe-commits


@@ -0,0 +1,6 @@
+! RUN: %flang -### -o /dev/null %s -Xlinker -rpath=/not/a/real/path 2>&1 | 
FileCheck %s
+
+! CHECK: "-fc1"
+! CHECK-NEXT: "-rpath=/not/a/real/path"

tarunprabhu wrote:

Thanks. I have updated the tests quite extensively. There are now checks for 
various platforms and multiple occurrences of `-Xlinker`. How does this look?

https://github.com/llvm/llvm-project/pull/107472
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Support -Xlinker in flang (PR #107472)

2024-09-09 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

> Thanks for the updates. LGTM

Thanks for the reviews, Tom :-)

https://github.com/llvm/llvm-project/pull/107472
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Support -Xlinker in flang (PR #107472)

2024-09-09 Thread Tarun Prabhu via cfe-commits


@@ -0,0 +1,8 @@
+! RUN: %flang -### -o /dev/null %s -Xlinker -rpath=/not/a/real/path 2>&1 | 
FileCheck --check-prefix=SINGLE %s
+! RUN: %flang -### -o /dev/null %s -Xlinker -rpath -Xlinker /not/a/real/path 
2>&1 | FileCheck --check-prefix=MULTIPLE %s
+
+
+! SINGLE: "-rpath=/not/a/real/path"
+! MULTIPLE: "-rpath" "/not/a/real/path"

tarunprabhu wrote:

Yes. I realized that soon immediately after I pushed up the changes (sigh). 
Thanks for taking multiple looks.

https://github.com/llvm/llvm-project/pull/107472
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Support --no-warnings option (PR #107455)

2024-09-09 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu closed 
https://github.com/llvm/llvm-project/pull/107455
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-09-09 Thread Tarun Prabhu via cfe-commits


@@ -1980,9 +1980,11 @@ within a command line are combined with spaces; spaces 
and backslashes within an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,

tarunprabhu wrote:

@kiranchandramohan, gentle ping

https://github.com/llvm/llvm-project/pull/102975
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Support -Xlinker in flang (PR #107472)

2024-09-09 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu closed 
https://github.com/llvm/llvm-project/pull/107472
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-09-09 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/102975

>From d5f48306117d0e3a166837b48ba475d70e15c6c1 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH 1/2] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 14 ++--
 clang/lib/Driver/CMakeLists.txt   |  1 +
 clang/lib/Driver/ToolChains/Clang.cpp | 48 ++--
 clang/lib/Driver/ToolChains/CommonUtils.cpp   | 76 +++
 clang/lib/Driver/ToolChains/CommonUtils.h | 44 +++
 clang/lib/Driver/ToolChains/Flang.cpp | 15 
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 +-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 
 flang/test/Driver/frecord-command-line.f90| 16 
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   | 10 ++-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 +
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 +
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 24 files changed, 284 insertions(+), 59 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.cpp
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.h
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bf8569fc780d6a..06d56e21830baf 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1981,16 +1981,18 @@ def fparse_all_comments : Flag<["-"], 
"fparse-all-comments">, Group,
   MarshallingInfoFlag>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
-  DocBrief<[{Generate a section named ".GCC.command.line" containing the clang
+  DocBrief<[{Generate a section named ".GCC.command.line" containing the
 driver command-line. After linking, the section may contain multiple command
 lines, which will be individually terminated by null bytes. Separate arguments
 within a command line are combined with spaces; spaces and backslashes within 
an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7125,6 +7127,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoString>;
 
 } // let Visibility = [CC1Option, CC1AsOption, FC1Option]
 
@@ -7145,9 +7150,6 @@ def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">,
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">,
   MarshallingInfoString>;
-def record_command_line : Separate<["-"], "record-command-line">,
-  HelpText<"The string to embed in the .LLVM.command.line section.">,
-  MarshallingInfoString>;
 def compress_debug_sections_EQ : Joined<["-", "--"], 
"compress-debug-sections=">,
 HelpText<"DWARF debug sections compression type">, 
Values<"none,zlib,zstd">

[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-08-12 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu created 
https://github.com/llvm/llvm-project/pull/102975

Add support for the -frecord-command-line option that will produce the 
llvm.commandline metadata which will eventually be saved in the object file. 
This behavior is also supported in clang. Some refactoring of the code in flang 
to handle these command line options was carried out. The corresponding 
-grecord-command-line option which saves the command line in the debug 
information has not yet been enabled for flang.


Notes for reviewers: In #98517, the `tune-cpu` argument was added to the 
constructor of the lowering bridge object in flang. This PR would have required 
adding another option to it. It is possible more such arguments may be added in 
the future. To avoid having to add new arguments each time, the constructor the 
`TargetOptions` and `CodeGenOptions` objects from the frontend are now passed 
directly through to the lowering bridge. 

This required a change to `bbc` where empty `TargetOptions` and 
`CodeGenOptions` objects had to be created. 

If others have better suggestions for how to handle this, I am happy to make 
changes.

>From 4ad7fc6a206a1d4004fe11013bce9ebee0347479 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 12 +--
 clang/lib/Driver/CMakeLists.txt   |  1 +
 clang/lib/Driver/ToolChains/Clang.cpp | 48 ++--
 clang/lib/Driver/ToolChains/CommonUtils.cpp   | 76 +++
 clang/lib/Driver/ToolChains/CommonUtils.h | 44 +++
 clang/lib/Driver/ToolChains/Flang.cpp | 15 
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 +-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 
 flang/test/Driver/frecord-command-line.f90| 11 +++
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   |  7 +-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 +
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 +
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 24 files changed, 277 insertions(+), 56 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.cpp
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.h
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0b38139bd27972..670e3658b6e85c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1980,9 +1980,11 @@ within a command line are combined with spaces; spaces 
and backslashes within an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7074,6 +7076,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoStrin

[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-08-12 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/102975

>From 4ad7fc6a206a1d4004fe11013bce9ebee0347479 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH 1/2] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 12 +--
 clang/lib/Driver/CMakeLists.txt   |  1 +
 clang/lib/Driver/ToolChains/Clang.cpp | 48 ++--
 clang/lib/Driver/ToolChains/CommonUtils.cpp   | 76 +++
 clang/lib/Driver/ToolChains/CommonUtils.h | 44 +++
 clang/lib/Driver/ToolChains/Flang.cpp | 15 
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 +-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 
 flang/test/Driver/frecord-command-line.f90| 11 +++
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   |  7 +-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 +
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 +
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 24 files changed, 277 insertions(+), 56 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.cpp
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.h
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0b38139bd27972..670e3658b6e85c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1980,9 +1980,11 @@ within a command line are combined with spaces; spaces 
and backslashes within an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7074,6 +7076,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoString>;
 
 } // let Visibility = [CC1Option, CC1AsOption, FC1Option]
 
@@ -7094,9 +7099,6 @@ def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">,
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">,
   MarshallingInfoString>;
-def record_command_line : Separate<["-"], "record-command-line">,
-  HelpText<"The string to embed in the .LLVM.command.line section.">,
-  MarshallingInfoString>;
 def compress_debug_sections_EQ : Joined<["-", "--"], 
"compress-debug-sections=">,
 HelpText<"DWARF debug sections compression type">, 
Values<"none,zlib,zstd">,
 NormalizedValuesScope<"llvm::DebugCompressionType">, 
NormalizedValues<["None", "Zlib", "Zstd"]>,
diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 32a4378ab499fa..0b92077384e9bc 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -48,6 +48,7 @@ add_clang_library(clangDriver
   ToolChains/BareMetal.cpp
   ToolChains/Clang.cpp
   ToolChains/CommonArgs.cpp
+  ToolChains/CommonUtils.cpp
   ToolChains/

[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-08-12 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu edited 
https://github.com/llvm/llvm-project/pull/102975
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-08-12 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/102975

>From 4ad7fc6a206a1d4004fe11013bce9ebee0347479 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH 1/3] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 12 +--
 clang/lib/Driver/CMakeLists.txt   |  1 +
 clang/lib/Driver/ToolChains/Clang.cpp | 48 ++--
 clang/lib/Driver/ToolChains/CommonUtils.cpp   | 76 +++
 clang/lib/Driver/ToolChains/CommonUtils.h | 44 +++
 clang/lib/Driver/ToolChains/Flang.cpp | 15 
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 +-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 
 flang/test/Driver/frecord-command-line.f90| 11 +++
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   |  7 +-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 +
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 +
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 24 files changed, 277 insertions(+), 56 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.cpp
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.h
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0b38139bd27972..670e3658b6e85c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1980,9 +1980,11 @@ within a command line are combined with spaces; spaces 
and backslashes within an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7074,6 +7076,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoString>;
 
 } // let Visibility = [CC1Option, CC1AsOption, FC1Option]
 
@@ -7094,9 +7099,6 @@ def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">,
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">,
   MarshallingInfoString>;
-def record_command_line : Separate<["-"], "record-command-line">,
-  HelpText<"The string to embed in the .LLVM.command.line section.">,
-  MarshallingInfoString>;
 def compress_debug_sections_EQ : Joined<["-", "--"], 
"compress-debug-sections=">,
 HelpText<"DWARF debug sections compression type">, 
Values<"none,zlib,zstd">,
 NormalizedValuesScope<"llvm::DebugCompressionType">, 
NormalizedValues<["None", "Zlib", "Zstd"]>,
diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 32a4378ab499fa..0b92077384e9bc 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -48,6 +48,7 @@ add_clang_library(clangDriver
   ToolChains/BareMetal.cpp
   ToolChains/Clang.cpp
   ToolChains/CommonArgs.cpp
+  ToolChains/CommonUtils.cpp
   ToolChains/

[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-08-13 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/102975

>From 4ad7fc6a206a1d4004fe11013bce9ebee0347479 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH 1/4] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 12 +--
 clang/lib/Driver/CMakeLists.txt   |  1 +
 clang/lib/Driver/ToolChains/Clang.cpp | 48 ++--
 clang/lib/Driver/ToolChains/CommonUtils.cpp   | 76 +++
 clang/lib/Driver/ToolChains/CommonUtils.h | 44 +++
 clang/lib/Driver/ToolChains/Flang.cpp | 15 
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 +-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 
 flang/test/Driver/frecord-command-line.f90| 11 +++
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   |  7 +-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 +
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 +
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 24 files changed, 277 insertions(+), 56 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.cpp
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.h
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0b38139bd27972..670e3658b6e85c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1980,9 +1980,11 @@ within a command line are combined with spaces; spaces 
and backslashes within an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7074,6 +7076,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoString>;
 
 } // let Visibility = [CC1Option, CC1AsOption, FC1Option]
 
@@ -7094,9 +7099,6 @@ def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">,
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">,
   MarshallingInfoString>;
-def record_command_line : Separate<["-"], "record-command-line">,
-  HelpText<"The string to embed in the .LLVM.command.line section.">,
-  MarshallingInfoString>;
 def compress_debug_sections_EQ : Joined<["-", "--"], 
"compress-debug-sections=">,
 HelpText<"DWARF debug sections compression type">, 
Values<"none,zlib,zstd">,
 NormalizedValuesScope<"llvm::DebugCompressionType">, 
NormalizedValues<["None", "Zlib", "Zstd"]>,
diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 32a4378ab499fa..0b92077384e9bc 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -48,6 +48,7 @@ add_clang_library(clangDriver
   ToolChains/BareMetal.cpp
   ToolChains/Clang.cpp
   ToolChains/CommonArgs.cpp
+  ToolChains/CommonUtils.cpp
   ToolChains/

[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-08-13 Thread Tarun Prabhu via cfe-commits


@@ -1980,9 +1980,11 @@ within a command line are combined with spaces; spaces 
and backslashes within an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;

tarunprabhu wrote:

Nice catch. The text only contains a single reference to clang. I have removed 
it, so it should apply to both `clang` and `flang` now. 

https://github.com/llvm/llvm-project/pull/102975
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-08-13 Thread Tarun Prabhu via cfe-commits


@@ -1980,9 +1980,11 @@ within a command line are combined with spaces; spaces 
and backslashes within an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,

tarunprabhu wrote:

Could you clarify what you mean by "flang's flow"? 

I don't know exactly what `f_clang_Group` does. I haven't been able to 
determine what effect it has on things like help messages. For instance 
`-frecord-command-line` does not appear in either `clang --help`, or `clang 
--help-hidden`. 

https://github.com/llvm/llvm-project/pull/102975
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-11 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu commented:

Is there a way to test that the attribute is lowered to FIR and perhaps also on 
to LLVM? `flang/test/Lower/` has some tests which check for the presence of 
certain constructs in the LLVM IR. Could something be written similar to those?

https://github.com/llvm/llvm-project/pull/95043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-11 Thread Tarun Prabhu via cfe-commits


@@ -371,7 +371,7 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
   ctx, semanticsContext, defKinds, semanticsContext.intrinsics(),
   semanticsContext.targetCharacteristics(), parsing.allCooked(),
   targetTriple, kindMap, loweringOptions, envDefaults,
-  semanticsContext.languageFeatures(), targetMachine);
+  semanticsContext.languageFeatures(), targetMachine, ""); // FIXME

tarunprabhu wrote:

What needs to be fixed here? If it needs to be deferred to a later patch, a 
more detailed inline comment would be helpful.

https://github.com/llvm/llvm-project/pull/95043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-11 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu edited 
https://github.com/llvm/llvm-project/pull/95043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-11 Thread Tarun Prabhu via cfe-commits


@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList &Args,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)

tarunprabhu wrote:

`A` is an `llvm::Arg`. The `getValue()` method 
[returns](https://llvm.org/doxygen/classllvm_1_1opt_1_1Arg.html#ac268590692356db84db78050196b4940)
 a `const char*`, so unless it is wrapped in a `llvm::StringRef`, the `==` 
operator cannot be used for string comparison.

It is surprising though. I, too, would have expected it to return a 
`llvm::StringRef`.

https://github.com/llvm/llvm-project/pull/95043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Tarun Prabhu via cfe-commits




tarunprabhu wrote:

Why do you have the first `target-cpu` check on its own? Is it intended to 
check for the _absence_ of the `tune-cpu` attribute when `target-cpu` is 
provided on the command line? If so, there should be a `CPU-NOT` annotation as 
well. Otherwise, it is odd to test for `target-cpu` when this file is intended 
to test `tune-cpu`. 

The third test which checks the case when both `target -cpu` and `tune-cpu` are 
provided is good.

https://github.com/llvm/llvm-project/pull/95043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Tarun Prabhu via cfe-commits




tarunprabhu wrote:

Consider replacing `#0` with `#{{[0-9]+}}`. While the attributes are almost 
certainly going to be in `#0` for such a small function, you don't actually 
_require_ this to match `#0`, so you it might be better to let it match any 
number. 

Also, if the `tune-cpu` attribute is expected to be on the same line, you could 
use `CHECK-SAME`. 

https://github.com/llvm/llvm-project/pull/95043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu edited 
https://github.com/llvm/llvm-project/pull/95043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Tarun Prabhu via cfe-commits


@@ -371,7 +371,7 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
   ctx, semanticsContext, defKinds, semanticsContext.intrinsics(),
   semanticsContext.targetCharacteristics(), parsing.allCooked(),
   targetTriple, kindMap, loweringOptions, envDefaults,
-  semanticsContext.languageFeatures(), targetMachine);
+  semanticsContext.languageFeatures(), targetMachine, "");

tarunprabhu wrote:

NIT: Would it be worth creating a `constexpr const char* tuneCPU = ""` and 
using that in place of the empty string literal here? It might make it clear 
what that parameter is. 

I don't have a strong opinion on this one way or another. If you or anyone else 
has a different opinion, I'm happy to defer to it. 

https://github.com/llvm/llvm-project/pull/95043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-13 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu commented:

Thanks for the changes. LGTM, but wait for @banach-space to approve.

https://github.com/llvm/llvm-project/pull/95043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Add support for -mllvm -print-pipeline-passes (PR #106141)

2024-08-29 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/106141

>From 9b83df995dc5c1d95db63a6ad32ba612b8a52290 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 26 Aug 2024 14:51:29 -0600
Subject: [PATCH 1/3] [flang][Driver] Add support for -mllvm
 -print-pipeline-passes

The behavior deliberately mimics that of clang.
---
 flang/lib/Frontend/FrontendActions.cpp  | 16 
 flang/test/Driver/print-pipeline-passes.f90 | 10 ++
 2 files changed, 26 insertions(+)
 create mode 100644 flang/test/Driver/print-pipeline-passes.f90

diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 5c86bd947ce73f..012649b2ba16bd 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -79,6 +79,10 @@
 
 #include "flang/Tools/CLOptions.inc"
 
+namespace llvm {
+extern cl::opt PrintPipelinePasses;
+} // namespace llvm
+
 using namespace Fortran::frontend;
 
 // Declare plugin extension function declarations.
@@ -1015,6 +1019,18 @@ void 
CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
   else if (action == BackendActionTy::Backend_EmitLL)
 mpm.addPass(llvm::PrintModulePass(os));
 
+  // Print a textual, '-passes=' compatible, representation of pipeline if
+  // requested. In this case, don't run the passes. This mimics the behavior of
+  // clang.
+  if (llvm::PrintPipelinePasses) {
+mpm.printPipeline(llvm::outs(), [&pic](llvm::StringRef className) {
+  auto passName = pic.getPassNameForClassName(className);
+  return passName.empty() ? className : passName;
+});
+llvm::outs() << "\n";
+return;
+  }
+
   // Run the passes.
   mpm.run(*llvmModule, mam);
 }
diff --git a/flang/test/Driver/print-pipeline-passes.f90 
b/flang/test/Driver/print-pipeline-passes.f90
new file mode 100644
index 00..4b413cbc07b691
--- /dev/null
+++ b/flang/test/Driver/print-pipeline-passes.f90
@@ -0,0 +1,10 @@
+! Test that -print-pipeline-passes works in flang
+
+! RUN: %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null 
-mllvm -print-pipeline-passes -O0 %s 2>&1 | FileCheck %s
+
+! Don't try to check all passes, just a few to make sure that something is
+! actually printed.
+! CHECK: always-inline
+! CHECK-SAME: annotation-remarks
+
+end program

>From a8d69e724d52e9e04faba7bf128883c22d5e1614 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Tue, 27 Aug 2024 05:24:15 -0600
Subject: [PATCH 2/3] Remove unnecessary target triple from test invocation.

---
 flang/test/Driver/print-pipeline-passes.f90 | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/flang/test/Driver/print-pipeline-passes.f90 
b/flang/test/Driver/print-pipeline-passes.f90
index 4b413cbc07b691..72c213802508e5 100644
--- a/flang/test/Driver/print-pipeline-passes.f90
+++ b/flang/test/Driver/print-pipeline-passes.f90
@@ -1,9 +1,6 @@
-! Test that -print-pipeline-passes works in flang
+! RUN: %flang_fc1 -mllvm -print-pipeline-passes -emit-llvm-bc -o /dev/null -O0 
%s 2>&1 | FileCheck %s
 
-! RUN: %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null 
-mllvm -print-pipeline-passes -O0 %s 2>&1 | FileCheck %s
-
-! Don't try to check all passes, just a few to make sure that something is
-! actually printed.
+! Just check a few passes to ensure that something reasonable is being printed.
 ! CHECK: always-inline
 ! CHECK-SAME: annotation-remarks
 

>From 81d4f14e7c06173d2893db172bc99b31d6fdaa4a Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Thu, 29 Aug 2024 09:10:15 -0600
Subject: [PATCH 3/3] Add comment as a reminder that -mllvm
 -print-pipeline-passes should eventually be replaced with a proper compiler
 driver option

---
 clang/lib/CodeGen/BackendUtil.cpp  | 2 ++
 flang/lib/Frontend/FrontendActions.cpp | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 026f16484c0949..564efa3181d188 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1095,6 +1095,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   TheModule->addModuleFlag(llvm::Module::Error, "UnifiedLTO", uint32_t(1));
   }
 
+  // FIXME: This should eventually be replaced by a first-class driver option.
+  // This should be done for both clang and flang simultaneously.
   // Print a textual, '-passes=' compatible, representation of pipeline if
   // requested.
   if (PrintPipelinePasses) {
diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 012649b2ba16bd..0bdd4be10ccca3 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -1019,6 +1019,8 @@ void 
CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
   else if (action == BackendActionTy::Backend_EmitLL)
 mpm.addPass(llvm::PrintModulePass(os));
 
+  // FIXME: This should eventually be repl

[clang] [flang] [flang][Driver] Add support for -mllvm -print-pipeline-passes (PR #106141)

2024-08-29 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

> 
> To unblock you, I propose the following:
> 
> 1. Keep this as is, but add a comment saying that this should be a proper 
> compiler option instead of a secret handshake like this. Similar comment 
> should be added in Clang. I will happily approve that.
> 

I have added a comment to both `clang` and `flang` indicating that we should 
eventually replace `mllvm -print-pipeline-passes` with a proper compiler driver 
option. I am happy to implement it, but it might have to wait for a bit, and 
I'd like to get the functionality in for now.

Thanks for the review and suggestions, Andrzej.

https://github.com/llvm/llvm-project/pull/106141
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] Revert "[flang] Add basic -mtune support" (PR #96678)

2024-06-25 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu created 
https://github.com/llvm/llvm-project/pull/96678

Reverts llvm/llvm-project#95043

>From b07dae1f1b758e9f55667dac4db38c78bd609656 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Tue, 25 Jun 2024 12:56:50 -0600
Subject: [PATCH] Revert "[flang] Add basic -mtune support (#95043)"

This reverts commit a790279bf2a8be2f9c42bf80f55a63933e398d0e.
---
 clang/include/clang/Driver/Options.td |  7 +++
 clang/lib/Driver/ToolChains/Flang.cpp | 10 +-
 flang/include/flang/Frontend/TargetOptions.h  |  3 ---
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 +--
 .../Optimizer/Dialect/Support/FIRContext.h|  7 ---
 .../flang/Optimizer/Transforms/Passes.td  |  3 ---
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 +--
 flang/lib/Lower/Bridge.cpp|  3 +--
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 ---
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +---
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 +--
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 --
 flang/test/Driver/tune-cpu-fir.f90| 14 --
 flang/test/Lower/tune-cpu-llvm.f90|  6 --
 flang/tools/bbc/bbc.cpp   |  3 +--
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 ---
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 -
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 -
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 ---
 mlir/test/Target/LLVMIR/Import/tune-cpu.ll|  9 -
 mlir/test/Target/LLVMIR/tune-cpu.mlir |  7 ---
 26 files changed, 14 insertions(+), 160 deletions(-)
 delete mode 100644 flang/test/Driver/tune-cpu-fir.f90
 delete mode 100644 flang/test/Lower/tune-cpu-llvm.f90
 delete mode 100644 mlir/test/Target/LLVMIR/Import/tune-cpu.ll
 delete mode 100644 mlir/test/Target/LLVMIR/tune-cpu.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b85daa3fccc46..dd55838dcf384 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5421,7 +5421,6 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
-  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6738,6 +6737,9 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6764,9 +6766,6 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 98fe7cace058f..42b45dba2bd31 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -15,7 +15,6 @@
 #include "llvm/Frontend/Debug/Options.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
-#include "llvm/TargetParser/Host.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 
@@ -412,13 +411,6 @@ void Flang::addTargetOptions(const ArgList &Args,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
-  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
-CmdArgs.push_back("-tune-cpu");
-if (A->getValue() == StringRef{"native"})
-  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
-else
-  CmdArgs.push_back(A->getValue());
-  }
 }
 
 void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs,
@@ -810,7 +802,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   case CodeGenOptions::FramePointerKind::None:
 FPKeepKindStr = "-mframe-pointer=none";
 break;
-  case CodeGenOptions::FramePointerKind::Reserved:
+   case CodeGenOptions::FramePointerKind::Reserved:
 

[clang] [flang] [mlir] Revert "[flang] Add basic -mtune support" (PR #96678)

2024-06-25 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu closed 
https://github.com/llvm/llvm-project/pull/96678
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-09-16 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

> Why do we need the two new files?
> 
> We have clang/lib/Driver/ToolChains/CommonArgs.cpp and 
> clang/lib/Driver/ToolChain.cpp for shared code.

Since most of the code in `CommonArgs.cpp` had to do with functions in the 
`clang::driver::tools` namespace, I wasn't sure that code that is only shared 
between `Clang.cpp` and `Flang.cpp` ought to go there. The other function that 
was moved is a utility function to escape arguments and was originally declared 
`static` in `Clang.cpp`.

If it is ok to use `CommandArgs.cpp` for limited sharing and utilities, I can 
move the code there. 

https://github.com/llvm/llvm-project/pull/102975
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Driver] Support -nostdlib and -nodefaultlibs (PR #108868)

2024-09-16 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu created 
https://github.com/llvm/llvm-project/pull/108868

This partially addresses some requests in #89888

>From 612b93eda5695306293bb8ca6e27a810b06adf3d Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 16 Sep 2024 12:08:38 -0600
Subject: [PATCH] [flang][Driver] Support -nostdlib and -nodefaultlibs

This partially addresses some requests in #89888
---
 clang/include/clang/Driver/Options.td |  7 --
 clang/lib/Driver/ToolChains/AIX.cpp   |  3 ++-
 clang/lib/Driver/ToolChains/Darwin.cpp|  3 ++-
 clang/lib/Driver/ToolChains/DragonFly.cpp |  3 ++-
 clang/lib/Driver/ToolChains/FreeBSD.cpp   |  3 ++-
 clang/lib/Driver/ToolChains/Gnu.cpp   |  3 ++-
 clang/lib/Driver/ToolChains/Haiku.cpp |  3 ++-
 clang/lib/Driver/ToolChains/MSVC.cpp  |  3 ++-
 clang/lib/Driver/ToolChains/MinGW.cpp |  3 ++-
 clang/lib/Driver/ToolChains/NetBSD.cpp|  3 ++-
 clang/lib/Driver/ToolChains/OpenBSD.cpp   |  3 ++-
 clang/lib/Driver/ToolChains/Solaris.cpp   |  3 ++-
 flang/test/Driver/nostdlib.f90| 29 +++
 13 files changed, 56 insertions(+), 13 deletions(-)
 create mode 100644 flang/test/Driver/nostdlib.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f123335ce8cfa..aa3ae92fb6ae78 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5572,7 +5572,8 @@ def : Flag<["-"], "nocudalib">, Alias;
 def gpulibc : Flag<["-"], "gpulibc">, Visibility<[ClangOption, CC1Option, 
FlangOption, FC1Option]>,
   HelpText<"Link the LLVM C Library for GPUs">;
 def nogpulibc : Flag<["-"], "nogpulibc">, Visibility<[ClangOption, CC1Option, 
FlangOption, FC1Option]>;
-def nodefaultlibs : Flag<["-"], "nodefaultlibs">;
+def nodefaultlibs : Flag<["-"], "nodefaultlibs">,
+  Visibility<[ClangOption, FlangOption, CLOption, DXCOption]>;
 def nodriverkitlib : Flag<["-"], "nodriverkitlib">;
 def nofixprebinding : Flag<["-"], "nofixprebinding">;
 def nolibc : Flag<["-"], "nolibc">;
@@ -5592,7 +5593,9 @@ def nostdincxx : Flag<["-"], "nostdinc++">, 
Visibility<[ClangOption, CC1Option]>
   Group,
   HelpText<"Disable standard #include directories for the C++ standard 
library">,
   MarshallingInfoNegativeFlag>;
-def nostdlib : Flag<["-"], "nostdlib">, Group;
+def nostdlib : Flag<["-"], "nostdlib">,
+  Visibility<[ClangOption, CLOption, FlangOption, DXCOption]>,
+  Group;
 def nostdlibxx : Flag<["-"], "nostdlib++">;
 def object : Flag<["-"], "object">;
 def o : JoinedOrSeparate<["-"], "o">,
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index c2de7328c25c5d..09a8dc2f4fa5dd 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -330,7 +330,8 @@ void aix::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 }
   }
 
-  if (D.IsFlangMode()) {
+  if (D.IsFlangMode() &&
+  !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
 addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
 addFortranRuntimeLibs(ToolChain, Args, CmdArgs);
 CmdArgs.push_back("-lm");
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index ebc9ed1aadb0ab..87380869f6fdab 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -713,7 +713,8 @@ void darwin::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   // Additional linker set-up and flags for Fortran. This is required in order
   // to generate executables.
-  if (getToolChain().getDriver().IsFlangMode()) {
+  if (getToolChain().getDriver().IsFlangMode() &&
+  !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
 addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
 addFortranRuntimeLibs(getToolChain(), Args, CmdArgs);
   }
diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 1dbc46763c1156..1e0a4159bf4ad7 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -151,7 +151,8 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 // to generate executables. As Fortran runtime depends on the C runtime,
 // these dependencies need to be listed before the C runtime below (i.e.
 // AddRunTimeLibs).
-if (D.IsFlangMode()) {
+if (D.IsFlangMode() &&
+!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
   addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
   addFortranRuntimeLibs(ToolChain, Args, CmdArgs);
   CmdArgs.push_back("-lm");
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index a8ee6540001ee4..3d744bc087f467 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -313,7 +313,8 @@ void freebsd::Linker::ConstructJob(Compilation &C,

[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-09-16 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/102975

>From 4a37cec543f30bb122bf14573fdec8302a0afa3e Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH 1/3] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 14 ++--
 clang/lib/Driver/CMakeLists.txt   |  1 +
 clang/lib/Driver/ToolChains/Clang.cpp | 48 ++--
 clang/lib/Driver/ToolChains/CommonUtils.cpp   | 76 +++
 clang/lib/Driver/ToolChains/CommonUtils.h | 44 +++
 clang/lib/Driver/ToolChains/Flang.cpp | 15 
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 +-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 
 flang/test/Driver/frecord-command-line.f90| 16 
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   | 10 ++-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 +
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 +
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 24 files changed, 284 insertions(+), 59 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.cpp
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.h
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f123335ce8cfa..aebcb5f0fbef61 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1994,16 +1994,18 @@ def fparse_all_comments : Flag<["-"], 
"fparse-all-comments">, Group,
   MarshallingInfoFlag>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
-  DocBrief<[{Generate a section named ".GCC.command.line" containing the clang
+  DocBrief<[{Generate a section named ".GCC.command.line" containing the
 driver command-line. After linking, the section may contain multiple command
 lines, which will be individually terminated by null bytes. Separate arguments
 within a command line are combined with spaces; spaces and backslashes within 
an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7138,6 +7140,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoString>;
 
 } // let Visibility = [CC1Option, CC1AsOption, FC1Option]
 
@@ -7158,9 +7163,6 @@ def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">,
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">,
   MarshallingInfoString>;
-def record_command_line : Separate<["-"], "record-command-line">,
-  HelpText<"The string to embed in the .LLVM.command.line section.">,
-  MarshallingInfoString>;
 def compress_debug_sections_EQ : Joined<["-", "--"], 
"compress-debug-sections=">,
 HelpText<"DWARF debug sections compression type">, 
Values<"none,zlib,zstd">

[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-09-16 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/102975

>From 4a37cec543f30bb122bf14573fdec8302a0afa3e Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH 1/4] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 14 ++--
 clang/lib/Driver/CMakeLists.txt   |  1 +
 clang/lib/Driver/ToolChains/Clang.cpp | 48 ++--
 clang/lib/Driver/ToolChains/CommonUtils.cpp   | 76 +++
 clang/lib/Driver/ToolChains/CommonUtils.h | 44 +++
 clang/lib/Driver/ToolChains/Flang.cpp | 15 
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 +-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 
 flang/test/Driver/frecord-command-line.f90| 16 
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   | 10 ++-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 +
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 +
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 24 files changed, 284 insertions(+), 59 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.cpp
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.h
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f123335ce8cfa..aebcb5f0fbef61 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1994,16 +1994,18 @@ def fparse_all_comments : Flag<["-"], 
"fparse-all-comments">, Group,
   MarshallingInfoFlag>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
-  DocBrief<[{Generate a section named ".GCC.command.line" containing the clang
+  DocBrief<[{Generate a section named ".GCC.command.line" containing the
 driver command-line. After linking, the section may contain multiple command
 lines, which will be individually terminated by null bytes. Separate arguments
 within a command line are combined with spaces; spaces and backslashes within 
an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7138,6 +7140,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoString>;
 
 } // let Visibility = [CC1Option, CC1AsOption, FC1Option]
 
@@ -7158,9 +7163,6 @@ def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">,
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">,
   MarshallingInfoString>;
-def record_command_line : Separate<["-"], "record-command-line">,
-  HelpText<"The string to embed in the .LLVM.command.line section.">,
-  MarshallingInfoString>;
 def compress_debug_sections_EQ : Joined<["-", "--"], 
"compress-debug-sections=">,
 HelpText<"DWARF debug sections compression type">, 
Values<"none,zlib,zstd">

[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-09-16 Thread Tarun Prabhu via cfe-commits


@@ -1980,9 +1980,11 @@ within a command line are combined with spaces; spaces 
and backslashes within an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,

tarunprabhu wrote:

I have changed the group to `f_Group` since that does not suggest that the 
options are exclusive to clang.

https://github.com/llvm/llvm-project/pull/102975
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-10-14 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/109165

>From 3b926fce8dbf42577adf54e80d3383a85b170e91 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Wed, 18 Sep 2024 09:49:26 -0600
Subject: [PATCH 1/6] [clang][flang] Support -time in both clang and flang

The -time option prints timing information for the subcommands (compiler,
linker) in a format similar to that used by gcc/gfortran (we use more digits
of precision).

This partially addresses requests from #89888
---
 clang/include/clang/Driver/Options.td |  1 +
 clang/lib/Driver/Compilation.cpp  | 21 +
 clang/lib/Driver/Driver.cpp   |  3 +++
 clang/test/Driver/time.c  | 24 
 flang/test/Driver/time.f90| 22 ++
 5 files changed, 71 insertions(+)
 create mode 100644 clang/test/Driver/time.c
 create mode 100644 flang/test/Driver/time.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d306c751505e98..f7cce59105e17a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5865,6 +5865,7 @@ def print_enabled_extensions : Flag<["-", "--"], 
"print-enabled-extensions">,
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
 def time : Flag<["-"], "time">,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   HelpText<"Time individual commands">;
 def traditional_cpp : Flag<["-", "--"], "traditional-cpp">,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp
index ad077d5bbfa69a..aadaa236246a27 100644
--- a/clang/lib/Driver/Compilation.cpp
+++ b/clang/lib/Driver/Compilation.cpp
@@ -21,6 +21,9 @@
 #include "llvm/Option/OptSpecifier.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -194,11 +197,29 @@ int Compilation::ExecuteCommand(const Command &C,
   if (LogOnly)
 return 0;
 
+  // We don't use any timers or llvm::TimeGroup's because those are tied into
+  // the global static timer list which, in principle, could be cleared without
+  // us knowing about it.
+  llvm::TimeRecord StartTime;
+  if (getArgs().hasArg(options::OPT_time)) {
+StartTime = llvm::TimeRecord::getCurrentTime(true);
+  }
+
   std::string Error;
   bool ExecutionFailed;
   int Res = C.Execute(Redirects, &Error, &ExecutionFailed);
   if (PostCallback)
 PostCallback(C, Res);
+
+  if (getArgs().hasArg(options::OPT_time)) {
+llvm::TimeRecord Time = llvm::TimeRecord::getCurrentTime(false);
+Time -= StartTime;
+llvm::StringRef Name = llvm::sys::path::filename(C.getExecutable());
+llvm::errs() << "# " << Name << " "
+ << llvm::format("%0.5f", Time.getUserTime()) << " "
+ << llvm::format("%0.5f", Time.getSystemTime()) << "\n";
+  }
+
   if (!Error.empty()) {
 assert(Res && "Error string set with 0 result code!");
 getDriver().Diag(diag::err_drv_command_failure) << Error;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9878a9dad78d40..15ae86bc479010 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1318,6 +1318,9 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   // Ignore -pipe.
   Args.ClaimAllArgs(options::OPT_pipe);
 
+  // Ignore -time.
+  Args.ClaimAllArgs(options::OPT_time);
+
   // Extract -ccc args.
   //
   // FIXME: We need to figure out where this behavior should live. Most of it
diff --git a/clang/test/Driver/time.c b/clang/test/Driver/time.c
new file mode 100644
index 00..1e19f29ab76a32
--- /dev/null
+++ b/clang/test/Driver/time.c
@@ -0,0 +1,24 @@
+// The -time option prints timing information for the various subcommands in a
+// format similar to that used by gcc. When compiling and linking, this will
+// include the time to call clang-${LLVM_VERSION_MAJOR} and the linker. Since
+// the name of the linker could vary across platforms, and name of the compiler
+// could be something different, just check that whatever is printed to stderr
+// looks like timing information.
+
+// RUN: %clang -time -c -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
+// RUN: %clang -time -S -emit-llvm -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
+// RUN: %clang -time -S -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
+// RUN: %clang -time -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-AND-LINK
+
+// COMPILE-ONLY: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}
+
+// COMPILE-AND-LINK: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}
+// COMPILE-AND-LINK: # {{.+}} {{[0-9]+(.[0

[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-10-14 Thread Tarun Prabhu via cfe-commits


@@ -194,11 +197,29 @@ int Compilation::ExecuteCommand(const Command &C,
   if (LogOnly)
 return 0;
 
+  // We don't use any timers or llvm::TimeGroup's because those are tied into
+  // the global static timer list which, in principle, could be cleared without
+  // us knowing about it.
+  llvm::TimeRecord StartTime;
+  if (getArgs().hasArg(options::OPT_time)) {
+StartTime = llvm::TimeRecord::getCurrentTime(true);

tarunprabhu wrote:

Done

https://github.com/llvm/llvm-project/pull/109165
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-10-14 Thread Tarun Prabhu via cfe-commits


@@ -194,11 +197,29 @@ int Compilation::ExecuteCommand(const Command &C,
   if (LogOnly)
 return 0;
 
+  // We don't use any timers or llvm::TimeGroup's because those are tied into
+  // the global static timer list which, in principle, could be cleared without
+  // us knowing about it.
+  llvm::TimeRecord StartTime;
+  if (getArgs().hasArg(options::OPT_time)) {
+StartTime = llvm::TimeRecord::getCurrentTime(true);
+  }
+
   std::string Error;
   bool ExecutionFailed;
   int Res = C.Execute(Redirects, &Error, &ExecutionFailed);
   if (PostCallback)
 PostCallback(C, Res);
+
+  if (getArgs().hasArg(options::OPT_time)) {
+llvm::TimeRecord Time = llvm::TimeRecord::getCurrentTime(false);

tarunprabhu wrote:

Done

https://github.com/llvm/llvm-project/pull/109165
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-10-15 Thread Tarun Prabhu via cfe-commits


@@ -5865,6 +5865,7 @@ def print_enabled_extensions : Flag<["-", "--"], 
"print-enabled-extensions">,
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
 def time : Flag<["-"], "time">,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,

tarunprabhu wrote:

I don't see any reason why it should not work on Windows. But there was a 
failing Windows buildkite, so I temporarily disabled the test. I will try again 
to see if it was a transient issue. If the issue still persists, I will add a 
comment indicating that the option should work on Windows, but that the 
original author did not have a means to test it and, therefore, disabled it. 
Since some of the tests require a full toolchain to be present, @MaskRay 
suggested being conservative about where the tests were run.

I have generally kept `CLOption` and `DXCOption` when the original did not 
explicitly specify anything for compatibility.

https://github.com/llvm/llvm-project/pull/109165
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-10-15 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/109165

>From f0540da79936c008a8fea8a16cefda6398d59ed4 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Wed, 18 Sep 2024 09:49:26 -0600
Subject: [PATCH 1/7] [clang][flang] Support -time in both clang and flang

The -time option prints timing information for the subcommands (compiler,
linker) in a format similar to that used by gcc/gfortran (we use more digits
of precision).

This partially addresses requests from #89888
---
 clang/include/clang/Driver/Options.td |  1 +
 clang/lib/Driver/Compilation.cpp  | 21 +
 clang/lib/Driver/Driver.cpp   |  3 +++
 clang/test/Driver/time.c  | 24 
 flang/test/Driver/time.f90| 22 ++
 5 files changed, 71 insertions(+)
 create mode 100644 clang/test/Driver/time.c
 create mode 100644 flang/test/Driver/time.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6491e9ac73ce99..c5cfe403758bca 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5867,6 +5867,7 @@ def print_enabled_extensions : Flag<["-", "--"], 
"print-enabled-extensions">,
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
 def time : Flag<["-"], "time">,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   HelpText<"Time individual commands">;
 def traditional_cpp : Flag<["-", "--"], "traditional-cpp">,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp
index ad077d5bbfa69a..aadaa236246a27 100644
--- a/clang/lib/Driver/Compilation.cpp
+++ b/clang/lib/Driver/Compilation.cpp
@@ -21,6 +21,9 @@
 #include "llvm/Option/OptSpecifier.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -194,11 +197,29 @@ int Compilation::ExecuteCommand(const Command &C,
   if (LogOnly)
 return 0;
 
+  // We don't use any timers or llvm::TimeGroup's because those are tied into
+  // the global static timer list which, in principle, could be cleared without
+  // us knowing about it.
+  llvm::TimeRecord StartTime;
+  if (getArgs().hasArg(options::OPT_time)) {
+StartTime = llvm::TimeRecord::getCurrentTime(true);
+  }
+
   std::string Error;
   bool ExecutionFailed;
   int Res = C.Execute(Redirects, &Error, &ExecutionFailed);
   if (PostCallback)
 PostCallback(C, Res);
+
+  if (getArgs().hasArg(options::OPT_time)) {
+llvm::TimeRecord Time = llvm::TimeRecord::getCurrentTime(false);
+Time -= StartTime;
+llvm::StringRef Name = llvm::sys::path::filename(C.getExecutable());
+llvm::errs() << "# " << Name << " "
+ << llvm::format("%0.5f", Time.getUserTime()) << " "
+ << llvm::format("%0.5f", Time.getSystemTime()) << "\n";
+  }
+
   if (!Error.empty()) {
 assert(Res && "Error string set with 0 result code!");
 getDriver().Diag(diag::err_drv_command_failure) << Error;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9878a9dad78d40..15ae86bc479010 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1318,6 +1318,9 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   // Ignore -pipe.
   Args.ClaimAllArgs(options::OPT_pipe);
 
+  // Ignore -time.
+  Args.ClaimAllArgs(options::OPT_time);
+
   // Extract -ccc args.
   //
   // FIXME: We need to figure out where this behavior should live. Most of it
diff --git a/clang/test/Driver/time.c b/clang/test/Driver/time.c
new file mode 100644
index 00..1e19f29ab76a32
--- /dev/null
+++ b/clang/test/Driver/time.c
@@ -0,0 +1,24 @@
+// The -time option prints timing information for the various subcommands in a
+// format similar to that used by gcc. When compiling and linking, this will
+// include the time to call clang-${LLVM_VERSION_MAJOR} and the linker. Since
+// the name of the linker could vary across platforms, and name of the compiler
+// could be something different, just check that whatever is printed to stderr
+// looks like timing information.
+
+// RUN: %clang -time -c -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
+// RUN: %clang -time -S -emit-llvm -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
+// RUN: %clang -time -S -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
+// RUN: %clang -time -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-AND-LINK
+
+// COMPILE-ONLY: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}
+
+// COMPILE-AND-LINK: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}
+// COMPILE-AND-LINK: # {{.+}} {{[0-9]+(.[0

[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-10-15 Thread Tarun Prabhu via cfe-commits


@@ -194,11 +197,29 @@ int Compilation::ExecuteCommand(const Command &C,
   if (LogOnly)
 return 0;
 
+  // We don't use any timers or llvm::TimeGroup's because those are tied into
+  // the global static timer list which, in principle, could be cleared without
+  // us knowing about it.
+  llvm::TimeRecord StartTime;
+  if (getArgs().hasArg(options::OPT_time)) {
+StartTime = llvm::TimeRecord::getCurrentTime(/*Start=*/true);
+  }

tarunprabhu wrote:

Done

https://github.com/llvm/llvm-project/pull/109165
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-10-15 Thread Tarun Prabhu via cfe-commits


@@ -194,11 +197,29 @@ int Compilation::ExecuteCommand(const Command &C,
   if (LogOnly)
 return 0;
 
+  // We don't use any timers or llvm::TimeGroup's because those are tied into
+  // the global static timer list which, in principle, could be cleared without
+  // us knowing about it.
+  llvm::TimeRecord StartTime;
+  if (getArgs().hasArg(options::OPT_time)) {
+StartTime = llvm::TimeRecord::getCurrentTime(/*Start=*/true);
+  }
+
   std::string Error;
   bool ExecutionFailed;
   int Res = C.Execute(Redirects, &Error, &ExecutionFailed);
   if (PostCallback)
 PostCallback(C, Res);
+
+  if (getArgs().hasArg(options::OPT_time)) {
+llvm::TimeRecord Time = llvm::TimeRecord::getCurrentTime(/*Start=*/false);
+Time -= StartTime;
+llvm::StringRef Name = llvm::sys::path::filename(C.getExecutable());
+llvm::errs() << "# " << Name << " "
+ << llvm::format("%0.5f", Time.getUserTime()) << " "
+ << llvm::format("%0.5f", Time.getSystemTime()) << "\n";

tarunprabhu wrote:

Ah. Nice catch. I have changed it "%0.2" which should be compatible with GCC.

https://github.com/llvm/llvm-project/pull/109165
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-10-11 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/109165

>From 6ff1fcb6dcd55b1d77dacc8b6d117176033038c0 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Wed, 18 Sep 2024 09:49:26 -0600
Subject: [PATCH 1/5] [clang][flang] Support -time in both clang and flang

The -time option prints timing information for the subcommands (compiler,
linker) in a format similar to that used by gcc/gfortran (we use more digits
of precision).

This partially addresses requests from #89888
---
 clang/include/clang/Driver/Options.td |  1 +
 clang/lib/Driver/Compilation.cpp  | 21 +
 clang/lib/Driver/Driver.cpp   |  3 +++
 clang/test/Driver/time.c  | 24 
 flang/test/Driver/time.f90| 22 ++
 5 files changed, 71 insertions(+)
 create mode 100644 clang/test/Driver/time.c
 create mode 100644 flang/test/Driver/time.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d306c751505e98..f7cce59105e17a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5865,6 +5865,7 @@ def print_enabled_extensions : Flag<["-", "--"], 
"print-enabled-extensions">,
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
 def time : Flag<["-"], "time">,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   HelpText<"Time individual commands">;
 def traditional_cpp : Flag<["-", "--"], "traditional-cpp">,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp
index ad077d5bbfa69a..aadaa236246a27 100644
--- a/clang/lib/Driver/Compilation.cpp
+++ b/clang/lib/Driver/Compilation.cpp
@@ -21,6 +21,9 @@
 #include "llvm/Option/OptSpecifier.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -194,11 +197,29 @@ int Compilation::ExecuteCommand(const Command &C,
   if (LogOnly)
 return 0;
 
+  // We don't use any timers or llvm::TimeGroup's because those are tied into
+  // the global static timer list which, in principle, could be cleared without
+  // us knowing about it.
+  llvm::TimeRecord StartTime;
+  if (getArgs().hasArg(options::OPT_time)) {
+StartTime = llvm::TimeRecord::getCurrentTime(true);
+  }
+
   std::string Error;
   bool ExecutionFailed;
   int Res = C.Execute(Redirects, &Error, &ExecutionFailed);
   if (PostCallback)
 PostCallback(C, Res);
+
+  if (getArgs().hasArg(options::OPT_time)) {
+llvm::TimeRecord Time = llvm::TimeRecord::getCurrentTime(false);
+Time -= StartTime;
+llvm::StringRef Name = llvm::sys::path::filename(C.getExecutable());
+llvm::errs() << "# " << Name << " "
+ << llvm::format("%0.5f", Time.getUserTime()) << " "
+ << llvm::format("%0.5f", Time.getSystemTime()) << "\n";
+  }
+
   if (!Error.empty()) {
 assert(Res && "Error string set with 0 result code!");
 getDriver().Diag(diag::err_drv_command_failure) << Error;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ba850cf3803e9b..580a55720082c1 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1315,6 +1315,9 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   // Ignore -pipe.
   Args.ClaimAllArgs(options::OPT_pipe);
 
+  // Ignore -time.
+  Args.ClaimAllArgs(options::OPT_time);
+
   // Extract -ccc args.
   //
   // FIXME: We need to figure out where this behavior should live. Most of it
diff --git a/clang/test/Driver/time.c b/clang/test/Driver/time.c
new file mode 100644
index 00..1e19f29ab76a32
--- /dev/null
+++ b/clang/test/Driver/time.c
@@ -0,0 +1,24 @@
+// The -time option prints timing information for the various subcommands in a
+// format similar to that used by gcc. When compiling and linking, this will
+// include the time to call clang-${LLVM_VERSION_MAJOR} and the linker. Since
+// the name of the linker could vary across platforms, and name of the compiler
+// could be something different, just check that whatever is printed to stderr
+// looks like timing information.
+
+// RUN: %clang -time -c -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
+// RUN: %clang -time -S -emit-llvm -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
+// RUN: %clang -time -S -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
+// RUN: %clang -time -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-AND-LINK
+
+// COMPILE-ONLY: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}
+
+// COMPILE-AND-LINK: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}
+// COMPILE-AND-LINK: # {{.+}} {{[0-9]+(.[0

[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-10-11 Thread Tarun Prabhu via cfe-commits


@@ -0,0 +1,24 @@
+// The -time option prints timing information for the various subcommands in a
+// format similar to that used by gcc. When compiling and linking, this will
+// include the time to call clang-${LLVM_VERSION_MAJOR} and the linker. Since
+// the name of the linker could vary across platforms, and name of the compiler
+// could be something different, just check that whatever is printed to stderr
+// looks like timing information.
+
+// RUN: %clang -time -c -O3 -o /dev/null %s 2>&1 \

tarunprabhu wrote:

Thanks for the explanation. I have restricted the tests to only run on 
`x86_64-linux` with a comment explaining the reasoning for the restriction.

https://github.com/llvm/llvm-project/pull/109165
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [clang][flang][mlir] Reapply "Support -frecord-command-line option (#102975)" (PR #110132)

2024-10-11 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/110132

>From 8564770eaa5636abe9a3624619937b0235df0e37 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 14 +++--
 clang/lib/Driver/ToolChains/Clang.cpp | 51 ++--
 clang/lib/Driver/ToolChains/CommonArgs.cpp| 59 +++
 clang/lib/Driver/ToolChains/CommonArgs.h  | 25 
 clang/lib/Driver/ToolChains/Flang.cpp | 14 +
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 +++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 +
 flang/test/Driver/frecord-command-line.f90| 16 +
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   |  6 +-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 ++
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 ++
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 ++
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 23 files changed, 245 insertions(+), 59 deletions(-)
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d306c751505e98..6491e9ac73ce99 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2002,16 +2002,18 @@ def fparse_all_comments : Flag<["-"], 
"fparse-all-comments">, Group,
   MarshallingInfoFlag>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
-  DocBrief<[{Generate a section named ".GCC.command.line" containing the clang
+  DocBrief<[{Generate a section named ".GCC.command.line" containing the
 driver command-line. After linking, the section may contain multiple command
 lines, which will be individually terminated by null bytes. Separate arguments
 within a command line are combined with spaces; spaces and backslashes within 
an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7166,6 +7168,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoString>;
 
 } // let Visibility = [CC1Option, CC1AsOption, FC1Option]
 
@@ -7186,9 +7191,6 @@ def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">,
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">,
   MarshallingInfoString>;
-def record_command_line : Separate<["-"], "record-command-line">,
-  HelpText<"The string to embed in the .LLVM.command.line section.">,
-  MarshallingInfoString>;
 def compress_debug_sections_EQ : Joined<["-", "--"], 
"compress-debug-sections=">,
 HelpText<"DWARF debug sections compression type">, 
Values<"none,zlib,zstd">,
 NormalizedValuesScope<"llvm::DebugCompressionType">, 
NormalizedValues<["None", "Zlib", "Zstd"]>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver

[clang] [flang] [flang][Driver] Add support for -f[no-]wrapv and -f[no]-strict-overflow in the frontend (PR #110061)

2024-10-07 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu approved this pull request.

Thank you for the changes, Minato san. LGTM.

https://github.com/llvm/llvm-project/pull/110061
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-10-07 Thread Tarun Prabhu via cfe-commits


@@ -0,0 +1,24 @@
+// The -time option prints timing information for the various subcommands in a
+// format similar to that used by gcc. When compiling and linking, this will
+// include the time to call clang-${LLVM_VERSION_MAJOR} and the linker. Since
+// the name of the linker could vary across platforms, and name of the compiler
+// could be something different, just check that whatever is printed to stderr
+// looks like timing information.
+
+// RUN: %clang -time -c -O3 -o /dev/null %s 2>&1 \

tarunprabhu wrote:

@MaskRay, am I right in understanding that the changes that you have requested 
would restrict the test to run only on x86? If not, is there somewhere this is 
explained so I understand this better. Thanks.

https://github.com/llvm/llvm-project/pull/109165
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [clang][flang][mlir] Reapply "Support -frecord-command-line option (#102975)" (PR #110132)

2024-10-10 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/110132

>From e307d2d0d0407c4e6f910a77cc5ae5cd97d08647 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 14 +++--
 clang/lib/Driver/ToolChains/Clang.cpp | 51 ++--
 clang/lib/Driver/ToolChains/CommonArgs.cpp| 59 +++
 clang/lib/Driver/ToolChains/CommonArgs.h  | 25 
 clang/lib/Driver/ToolChains/Flang.cpp | 14 +
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 +++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 +
 flang/test/Driver/frecord-command-line.f90| 16 +
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   |  6 +-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 ++
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 ++
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 ++
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 23 files changed, 245 insertions(+), 59 deletions(-)
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d306c751505e98..6491e9ac73ce99 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2002,16 +2002,18 @@ def fparse_all_comments : Flag<["-"], 
"fparse-all-comments">, Group,
   MarshallingInfoFlag>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
-  DocBrief<[{Generate a section named ".GCC.command.line" containing the clang
+  DocBrief<[{Generate a section named ".GCC.command.line" containing the
 driver command-line. After linking, the section may contain multiple command
 lines, which will be individually terminated by null bytes. Separate arguments
 within a command line are combined with spaces; spaces and backslashes within 
an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7166,6 +7168,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoString>;
 
 } // let Visibility = [CC1Option, CC1AsOption, FC1Option]
 
@@ -7186,9 +7191,6 @@ def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">,
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">,
   MarshallingInfoString>;
-def record_command_line : Separate<["-"], "record-command-line">,
-  HelpText<"The string to embed in the .LLVM.command.line section.">,
-  MarshallingInfoString>;
 def compress_debug_sections_EQ : Joined<["-", "--"], 
"compress-debug-sections=">,
 HelpText<"DWARF debug sections compression type">, 
Values<"none,zlib,zstd">,
 NormalizedValuesScope<"llvm::DebugCompressionType">, 
NormalizedValues<["None", "Zlib", "Zstd"]>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver

[clang] [flang] [mlir] [clang][flang][mlir] Reapply "Support -frecord-command-line option (#102975)" (PR #110132)

2024-10-10 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/110132

>From 797927dc0858886fa5ecced02903f98bdc929121 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 14 +++--
 clang/lib/Driver/ToolChains/Clang.cpp | 51 ++--
 clang/lib/Driver/ToolChains/CommonArgs.cpp| 59 +++
 clang/lib/Driver/ToolChains/CommonArgs.h  | 25 
 clang/lib/Driver/ToolChains/Flang.cpp | 14 +
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 +++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 +
 flang/test/Driver/frecord-command-line.f90| 16 +
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   |  6 +-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 ++
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 ++
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 ++
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 23 files changed, 245 insertions(+), 59 deletions(-)
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d306c751505e98..6491e9ac73ce99 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2002,16 +2002,18 @@ def fparse_all_comments : Flag<["-"], 
"fparse-all-comments">, Group,
   MarshallingInfoFlag>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
-  DocBrief<[{Generate a section named ".GCC.command.line" containing the clang
+  DocBrief<[{Generate a section named ".GCC.command.line" containing the
 driver command-line. After linking, the section may contain multiple command
 lines, which will be individually terminated by null bytes. Separate arguments
 within a command line are combined with spaces; spaces and backslashes within 
an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7166,6 +7168,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoString>;
 
 } // let Visibility = [CC1Option, CC1AsOption, FC1Option]
 
@@ -7186,9 +7191,6 @@ def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">,
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">,
   MarshallingInfoString>;
-def record_command_line : Separate<["-"], "record-command-line">,
-  HelpText<"The string to embed in the .LLVM.command.line section.">,
-  MarshallingInfoString>;
 def compress_debug_sections_EQ : Joined<["-", "--"], 
"compress-debug-sections=">,
 HelpText<"DWARF debug sections compression type">, 
Values<"none,zlib,zstd">,
 NormalizedValuesScope<"llvm::DebugCompressionType">, 
NormalizedValues<["None", "Zlib", "Zstd"]>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver

[clang] [flang] [flang][Driver] Add support for -f[no-]wrapv and -f[no]-strict-overflow in the frontend (PR #110061)

2024-10-04 Thread Tarun Prabhu via cfe-commits


@@ -866,6 +866,17 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 }
   }
 
+  // -fno-strict-overflow implies -fwrapv if it isn't disabled, but
+  // -fstrict-overflow won't turn off an explicitly enabled -fwrapv.
+  if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) {
+if (A->getOption().matches(options::OPT_fwrapv))
+  CmdArgs.push_back("-fwrapv");
+  } else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow,
+  options::OPT_fno_strict_overflow)) {
+if (A->getOption().matches(options::OPT_fno_strict_overflow))
+  CmdArgs.push_back("-fwrapv");
+  }
+

tarunprabhu wrote:

Perhaps the function could be named `renderCommonIntegerOverflowOptions` which 
suggests that it does not handle all overflow options?

https://github.com/llvm/llvm-project/pull/110061
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [clang][flang][mlir] Reapply "Support -frecord-command-line option (#102975)" (PR #110132)

2024-10-14 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu closed 
https://github.com/llvm/llvm-project/pull/110132
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] [clang][flang][mlir] Reapply "Support -frecord-command-line option (#102975)" (PR #110132)

2024-10-14 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/110132

>From 61b13cf54de802351e785f50df77adc30d5e7695 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 14 +++--
 clang/lib/Driver/ToolChains/Clang.cpp | 51 ++--
 clang/lib/Driver/ToolChains/CommonArgs.cpp| 59 +++
 clang/lib/Driver/ToolChains/CommonArgs.h  | 25 
 clang/lib/Driver/ToolChains/Flang.cpp | 14 +
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 +++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 +
 flang/test/Driver/frecord-command-line.f90| 16 +
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   |  6 +-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 ++
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 ++
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 ++
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 23 files changed, 245 insertions(+), 59 deletions(-)
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d306c751505e98..6491e9ac73ce99 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2002,16 +2002,18 @@ def fparse_all_comments : Flag<["-"], 
"fparse-all-comments">, Group,
   MarshallingInfoFlag>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
-  DocBrief<[{Generate a section named ".GCC.command.line" containing the clang
+  DocBrief<[{Generate a section named ".GCC.command.line" containing the
 driver command-line. After linking, the section may contain multiple command
 lines, which will be individually terminated by null bytes. Separate arguments
 within a command line are combined with spaces; spaces and backslashes within 
an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7166,6 +7168,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoString>;
 
 } // let Visibility = [CC1Option, CC1AsOption, FC1Option]
 
@@ -7186,9 +7191,6 @@ def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">,
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">,
   MarshallingInfoString>;
-def record_command_line : Separate<["-"], "record-command-line">,
-  HelpText<"The string to embed in the .LLVM.command.line section.">,
-  MarshallingInfoString>;
 def compress_debug_sections_EQ : Joined<["-", "--"], 
"compress-debug-sections=">,
 HelpText<"DWARF debug sections compression type">, 
Values<"none,zlib,zstd">,
 NormalizedValuesScope<"llvm::DebugCompressionType">, 
NormalizedValues<["None", "Zlib", "Zstd"]>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver

[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-10-14 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/109165

>From 3b926fce8dbf42577adf54e80d3383a85b170e91 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Wed, 18 Sep 2024 09:49:26 -0600
Subject: [PATCH 1/5] [clang][flang] Support -time in both clang and flang

The -time option prints timing information for the subcommands (compiler,
linker) in a format similar to that used by gcc/gfortran (we use more digits
of precision).

This partially addresses requests from #89888
---
 clang/include/clang/Driver/Options.td |  1 +
 clang/lib/Driver/Compilation.cpp  | 21 +
 clang/lib/Driver/Driver.cpp   |  3 +++
 clang/test/Driver/time.c  | 24 
 flang/test/Driver/time.f90| 22 ++
 5 files changed, 71 insertions(+)
 create mode 100644 clang/test/Driver/time.c
 create mode 100644 flang/test/Driver/time.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d306c751505e98..f7cce59105e17a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5865,6 +5865,7 @@ def print_enabled_extensions : Flag<["-", "--"], 
"print-enabled-extensions">,
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
 def time : Flag<["-"], "time">,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
   HelpText<"Time individual commands">;
 def traditional_cpp : Flag<["-", "--"], "traditional-cpp">,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp
index ad077d5bbfa69a..aadaa236246a27 100644
--- a/clang/lib/Driver/Compilation.cpp
+++ b/clang/lib/Driver/Compilation.cpp
@@ -21,6 +21,9 @@
 #include "llvm/Option/OptSpecifier.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -194,11 +197,29 @@ int Compilation::ExecuteCommand(const Command &C,
   if (LogOnly)
 return 0;
 
+  // We don't use any timers or llvm::TimeGroup's because those are tied into
+  // the global static timer list which, in principle, could be cleared without
+  // us knowing about it.
+  llvm::TimeRecord StartTime;
+  if (getArgs().hasArg(options::OPT_time)) {
+StartTime = llvm::TimeRecord::getCurrentTime(true);
+  }
+
   std::string Error;
   bool ExecutionFailed;
   int Res = C.Execute(Redirects, &Error, &ExecutionFailed);
   if (PostCallback)
 PostCallback(C, Res);
+
+  if (getArgs().hasArg(options::OPT_time)) {
+llvm::TimeRecord Time = llvm::TimeRecord::getCurrentTime(false);
+Time -= StartTime;
+llvm::StringRef Name = llvm::sys::path::filename(C.getExecutable());
+llvm::errs() << "# " << Name << " "
+ << llvm::format("%0.5f", Time.getUserTime()) << " "
+ << llvm::format("%0.5f", Time.getSystemTime()) << "\n";
+  }
+
   if (!Error.empty()) {
 assert(Res && "Error string set with 0 result code!");
 getDriver().Diag(diag::err_drv_command_failure) << Error;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9878a9dad78d40..15ae86bc479010 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1318,6 +1318,9 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   // Ignore -pipe.
   Args.ClaimAllArgs(options::OPT_pipe);
 
+  // Ignore -time.
+  Args.ClaimAllArgs(options::OPT_time);
+
   // Extract -ccc args.
   //
   // FIXME: We need to figure out where this behavior should live. Most of it
diff --git a/clang/test/Driver/time.c b/clang/test/Driver/time.c
new file mode 100644
index 00..1e19f29ab76a32
--- /dev/null
+++ b/clang/test/Driver/time.c
@@ -0,0 +1,24 @@
+// The -time option prints timing information for the various subcommands in a
+// format similar to that used by gcc. When compiling and linking, this will
+// include the time to call clang-${LLVM_VERSION_MAJOR} and the linker. Since
+// the name of the linker could vary across platforms, and name of the compiler
+// could be something different, just check that whatever is printed to stderr
+// looks like timing information.
+
+// RUN: %clang -time -c -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
+// RUN: %clang -time -S -emit-llvm -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
+// RUN: %clang -time -S -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
+// RUN: %clang -time -O3 -o /dev/null %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=COMPILE-AND-LINK
+
+// COMPILE-ONLY: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}
+
+// COMPILE-AND-LINK: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}
+// COMPILE-AND-LINK: # {{.+}} {{[0-9]+(.[0

[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-10-24 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

@MaskRay, have all your comments been addressed?

https://github.com/llvm/llvm-project/pull/109165
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [clang][flang] Support -time in both clang and flang (PR #109165)

2024-11-12 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu closed 
https://github.com/llvm/llvm-project/pull/109165
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >