[clang] [z/OS] Add option to target older versions of LE on z/OS (PR #123399)
https://github.com/perry-ca closed https://github.com/llvm/llvm-project/pull/123399 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [z/OS] Add option to target older versions of LE on z/OS (PR #123399)
https://github.com/perry-ca updated
https://github.com/llvm/llvm-project/pull/123399
>From 9f5763faa81691f540af42721147daf50042e549 Mon Sep 17 00:00:00 2001
From: Sean Perry
Date: Wed, 27 Nov 2024 18:33:09 -0600
Subject: [PATCH 1/3] Add -mzos-target
---
.../clang/Basic/DiagnosticDriverKinds.td | 5 ++
clang/include/clang/Driver/Options.td | 1 +
clang/lib/Basic/Targets/SystemZ.cpp | 15
clang/lib/Driver/Driver.cpp | 72 +++
clang/lib/Driver/ToolChain.cpp| 15
clang/test/Preprocessor/zos-target.c | 18 +
6 files changed, 126 insertions(+)
create mode 100644 clang/test/Preprocessor/zos-target.c
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 5155b23d151c04..140bc52af12b25 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,6 +277,11 @@ def err_cpu_unsupported_isa
def err_arch_unsupported_isa
: Error<"architecture '%0' does not support '%1' execution mode">;
+def err_zos_target_release_discontinued
+ : Error<"z/OS target level \"%0\" is discontinued. Unexpected behavior
might occur if an out-of-support target level is specified. Use z/OS target
level \"zOSv2r4\", or later instead">;
+def err_zos_target_unrecognized_release
+ : Error<"\"%0\" is not recognized as a valid z/OS target level. The z/OS
target level must be \"current\", or of the form \"zosvVrR\", where \"V\" is
the version and \"R\" is the release, or given as a \"0x\"-prefixed eight digit
hexadecimal value">;
+
def err_drv_I_dash_not_supported : Error<
"'%0' not supported, please use -iquote instead">;
def err_drv_unknown_argument : Error<"unknown argument: '%0'">;
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 40fd48761928b3..ddbd857414e714 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4734,6 +4734,7 @@ def mwatchsimulator_version_min_EQ : Joined<["-"],
"mwatchsimulator-version-min=
def march_EQ : Joined<["-"], "march=">, Group,
Flags<[TargetSpecific]>, Visibility<[ClangOption, CLOption, DXCOption,
FlangOption]>,
HelpText<"For a list of available architectures for the target use
'-mcpu=help'">;
+def mzos_target_EQ : Joined<["-"], "mzos-target=">, Group,
Visibility<[ClangOption, CC1Option]>, HelpText<"Set the z/OS release of the
runtime environment">;
def masm_EQ : Joined<["-"], "masm=">, Group, Visibility<[ClangOption,
FlangOption]>;
def inline_asm_EQ : Joined<["-"], "inline-asm=">, Group,
Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Basic/Targets/SystemZ.cpp
b/clang/lib/Basic/Targets/SystemZ.cpp
index 06f08db2eadd47..2c749c0ba76937 100644
--- a/clang/lib/Basic/Targets/SystemZ.cpp
+++ b/clang/lib/Basic/Targets/SystemZ.cpp
@@ -168,6 +168,21 @@ void SystemZTargetInfo::getTargetDefines(const LangOptions
&Opts,
Builder.defineMacro("__VX__");
if (Opts.ZVector)
Builder.defineMacro("__VEC__", "10304");
+
+ /* Set __TARGET_LIB__ only if a value was given. If no value was given */
+ /* we rely on the LE headers to define __TARGET_LIB__. */
+ if (!getTriple().getOSVersion().empty()) {
+llvm::VersionTuple V = getTriple().getOSVersion();
+// Create string with form: 0xPVRR, where P=4
+std::string Str("0x");
+unsigned int Librel = 0x4000;
+Librel |= V.getMajor() << 24;
+Librel |= (V.getMinor() ? V.getMinor().value() : 1) << 16;
+Librel |= V.getSubminor() ? V.getSubminor().value() : 0;
+Str += llvm::utohexstr(Librel);
+
+Builder.defineMacro("__TARGET_LIB__", Str.c_str());
+ }
}
ArrayRef SystemZTargetInfo::getTargetBuiltins() const {
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ad14b5c9b6dc80..eebe60648ed22b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -517,6 +517,72 @@ DerivedArgList *Driver::TranslateInputArgs(const
InputArgList &Args) const {
return DAL;
}
+static void setZosTargetVersion(const Driver &D, llvm::Triple &Target,
+StringRef ArgTarget) {
+
+ static bool BeSilent = false;
+ auto IsTooOldToBeSupported = [](int v, int r) -> bool {
+return ((v < 2) || ((v == 2) && (r < 4)));
+ };
+
+ /* expect CURRENT, zOSV2R[45], or 0x */
+ if (ArgTarget.equals_insensitive("CURRENT")) {
+/* If the user gives CURRENT, then we rely on the LE to set */
+/* __TARGET_LIB__. There's nothing more we need to do. */
+ } else {
+unsigned int Version = 0;
+unsigned int Release = 0;
+unsigned int Modification = 0;
+bool IsOk = true;
+llvm::Regex ZOsvRegex("[zZ][oO][sS][vV]([0-9])[rR]([0-9])");
+llvm::Regex HexRegex(
+"0x4" /* product */
+"([0-9a-fA-F])"/* version *
[clang] [z/OS] Add option to target older versions of LE on z/OS (PR #123399)
@@ -277,6 +277,11 @@ def err_cpu_unsupported_isa def err_arch_unsupported_isa : Error<"architecture '%0' does not support '%1' execution mode">; +def err_zos_target_release_discontinued + : Error<"z/OS target level \"%0\" is discontinued. Unexpected behavior might occur if an out-of-support target level is specified. Use z/OS target level \"zOSv2r4\", or later instead">; abhina-sree wrote: minor nit: these lines are very long and could be broken up to multiple lines https://github.com/llvm/llvm-project/pull/123399 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [z/OS] Add option to target older versions of LE on z/OS (PR #123399)
https://github.com/abhina-sree approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/123399 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [z/OS] Add option to target older versions of LE on z/OS (PR #123399)
https://github.com/perry-ca edited https://github.com/llvm/llvm-project/pull/123399 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [z/OS] Add option to target older versions of LE on z/OS (PR #123399)
llvmbot wrote:
@llvm/pr-subscribers-clang-driver
Author: Sean Perry (perry-ca)
Changes
Add an option similar to the -qtarget option in XL to allow the user to say
they want to be able to run the generated program on an older version of the LE
environment. This option will do two things:
- set the `__TARGET_LIBS` macro so the system headers exclude newer interfaces
when targeting older environments
- set the arch level to match the minimum arch level for that older version of
LE. It some happens right now all of the supported LE versions have a the same
minimum ach level so the option doesn't change this yet.
The user can specify three different kinds of arguments:
1. -mzos-target=zosv*V*r*R* - where V & R are the version and release
2. -mzos-target=0x4vrr - v, r, m, p are the hex values for the version,
release, and modlevel
3. -mzos-target=current - uses the latest version of LE the system headers have
support for
---
Full diff: https://github.com/llvm/llvm-project/pull/123399.diff
6 Files Affected:
- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+5)
- (modified) clang/include/clang/Driver/Options.td (+1)
- (modified) clang/lib/Basic/Targets/SystemZ.cpp (+16)
- (modified) clang/lib/Driver/Driver.cpp (+72)
- (modified) clang/lib/Driver/ToolChain.cpp (+20-4)
- (added) clang/test/Preprocessor/zos-target.c (+18)
``diff
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 42c39ac6606c7f..603b6656ee8cb1 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,6 +277,11 @@ def err_cpu_unsupported_isa
def err_arch_unsupported_isa
: Error<"architecture '%0' does not support '%1' execution mode">;
+def err_zos_target_release_discontinued
+ : Error<"z/OS target level \"%0\" is discontinued. Unexpected behavior
might occur if an out-of-support target level is specified. Use z/OS target
level \"zOSv2r4\", or later instead">;
+def err_zos_target_unrecognized_release
+ : Error<"\"%0\" is not recognized as a valid z/OS target level. The z/OS
target level must be \"current\", or of the form \"zosvVrR\", where \"V\" is
the version and \"R\" is the release, or given as a \"0x\"-prefixed eight digit
hexadecimal value">;
+
def err_drv_I_dash_not_supported : Error<
"'%0' not supported, please use -iquote instead">;
def err_drv_unknown_argument : Error<"unknown argument: '%0'">;
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index d38dd2b4e3cf09..2023764287092a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4774,6 +4774,7 @@ def mwatchsimulator_version_min_EQ : Joined<["-"],
"mwatchsimulator-version-min=
def march_EQ : Joined<["-"], "march=">, Group,
Flags<[TargetSpecific]>, Visibility<[ClangOption, CLOption, DXCOption,
FlangOption]>,
HelpText<"For a list of available architectures for the target use
'-mcpu=help'">;
+def mzos_target_EQ : Joined<["-"], "mzos-target=">, Group,
Visibility<[ClangOption, CC1Option]>, HelpText<"Set the z/OS release of the
runtime environment">;
def masm_EQ : Joined<["-"], "masm=">, Group, Visibility<[ClangOption,
FlangOption]>;
def inline_asm_EQ : Joined<["-"], "inline-asm=">, Group,
Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Basic/Targets/SystemZ.cpp
b/clang/lib/Basic/Targets/SystemZ.cpp
index 06f08db2eadd47..2731cb596fd27a 100644
--- a/clang/lib/Basic/Targets/SystemZ.cpp
+++ b/clang/lib/Basic/Targets/SystemZ.cpp
@@ -15,6 +15,7 @@
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/MacroBuilder.h"
#include "clang/Basic/TargetBuiltins.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
using namespace clang;
@@ -168,6 +169,21 @@ void SystemZTargetInfo::getTargetDefines(const LangOptions
&Opts,
Builder.defineMacro("__VX__");
if (Opts.ZVector)
Builder.defineMacro("__VEC__", "10304");
+
+ /* Set __TARGET_LIB__ only if a value was given. If no value was given */
+ /* we rely on the LE headers to define __TARGET_LIB__. */
+ if (!getTriple().getOSVersion().empty()) {
+llvm::VersionTuple V = getTriple().getOSVersion();
+// Create string with form: 0xPVRR, where P=4
+std::string Str("0x");
+unsigned int Librel = 0x4000;
+Librel |= V.getMajor() << 24;
+Librel |= (V.getMinor() ? V.getMinor().value() : 1) << 16;
+Librel |= V.getSubminor() ? V.getSubminor().value() : 0;
+Str += llvm::utohexstr(Librel);
+
+Builder.defineMacro("__TARGET_LIB__", Str.c_str());
+ }
}
ArrayRef SystemZTargetInfo::getTargetBuiltins() const {
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 87855fdb799710..bea16edb152f52 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -564,6 +564,72 @@ DerivedArgList *Driver
[clang] [z/OS] Add option to target older versions of LE on z/OS (PR #123399)
https://github.com/perry-ca created
https://github.com/llvm/llvm-project/pull/123399
Add an option similar to the -qtarget option in XL to allow the user to say
they want to be able to run the generated program on an older version of the LE
environment. This option will do two things:
- set the `__TARGET_LIBS` macro so the system headers exclude newer interfaces
when targeting older environments
- set the arch level to match the minimum arch level for that older version of
LE. It some happens right now all of the supported LE versions have a the same
minimum ach level so the option doesn't change this yet.
The user can specify three different kinds of arguments:
1. -mzos-target=zosv*V*r*R* - where V & R are the version and release
2. -mzos-target=0x4vrr - v, r, m, p are the hex values for the version,
release, and modlevel
3. -mzos-target=current - uses the latest version of LE the system headers have
support for
>From 9f5763faa81691f540af42721147daf50042e549 Mon Sep 17 00:00:00 2001
From: Sean Perry
Date: Wed, 27 Nov 2024 18:33:09 -0600
Subject: [PATCH 1/2] Add -mzos-target
---
.../clang/Basic/DiagnosticDriverKinds.td | 5 ++
clang/include/clang/Driver/Options.td | 1 +
clang/lib/Basic/Targets/SystemZ.cpp | 15
clang/lib/Driver/Driver.cpp | 72 +++
clang/lib/Driver/ToolChain.cpp| 15
clang/test/Preprocessor/zos-target.c | 18 +
6 files changed, 126 insertions(+)
create mode 100644 clang/test/Preprocessor/zos-target.c
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 5155b23d151c04..140bc52af12b25 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,6 +277,11 @@ def err_cpu_unsupported_isa
def err_arch_unsupported_isa
: Error<"architecture '%0' does not support '%1' execution mode">;
+def err_zos_target_release_discontinued
+ : Error<"z/OS target level \"%0\" is discontinued. Unexpected behavior
might occur if an out-of-support target level is specified. Use z/OS target
level \"zOSv2r4\", or later instead">;
+def err_zos_target_unrecognized_release
+ : Error<"\"%0\" is not recognized as a valid z/OS target level. The z/OS
target level must be \"current\", or of the form \"zosvVrR\", where \"V\" is
the version and \"R\" is the release, or given as a \"0x\"-prefixed eight digit
hexadecimal value">;
+
def err_drv_I_dash_not_supported : Error<
"'%0' not supported, please use -iquote instead">;
def err_drv_unknown_argument : Error<"unknown argument: '%0'">;
diff --git a/clang/include/clang/Driver/Options.td
b/clang/include/clang/Driver/Options.td
index 40fd48761928b3..ddbd857414e714 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4734,6 +4734,7 @@ def mwatchsimulator_version_min_EQ : Joined<["-"],
"mwatchsimulator-version-min=
def march_EQ : Joined<["-"], "march=">, Group,
Flags<[TargetSpecific]>, Visibility<[ClangOption, CLOption, DXCOption,
FlangOption]>,
HelpText<"For a list of available architectures for the target use
'-mcpu=help'">;
+def mzos_target_EQ : Joined<["-"], "mzos-target=">, Group,
Visibility<[ClangOption, CC1Option]>, HelpText<"Set the z/OS release of the
runtime environment">;
def masm_EQ : Joined<["-"], "masm=">, Group, Visibility<[ClangOption,
FlangOption]>;
def inline_asm_EQ : Joined<["-"], "inline-asm=">, Group,
Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Basic/Targets/SystemZ.cpp
b/clang/lib/Basic/Targets/SystemZ.cpp
index 06f08db2eadd47..2c749c0ba76937 100644
--- a/clang/lib/Basic/Targets/SystemZ.cpp
+++ b/clang/lib/Basic/Targets/SystemZ.cpp
@@ -168,6 +168,21 @@ void SystemZTargetInfo::getTargetDefines(const LangOptions
&Opts,
Builder.defineMacro("__VX__");
if (Opts.ZVector)
Builder.defineMacro("__VEC__", "10304");
+
+ /* Set __TARGET_LIB__ only if a value was given. If no value was given */
+ /* we rely on the LE headers to define __TARGET_LIB__. */
+ if (!getTriple().getOSVersion().empty()) {
+llvm::VersionTuple V = getTriple().getOSVersion();
+// Create string with form: 0xPVRR, where P=4
+std::string Str("0x");
+unsigned int Librel = 0x4000;
+Librel |= V.getMajor() << 24;
+Librel |= (V.getMinor() ? V.getMinor().value() : 1) << 16;
+Librel |= V.getSubminor() ? V.getSubminor().value() : 0;
+Str += llvm::utohexstr(Librel);
+
+Builder.defineMacro("__TARGET_LIB__", Str.c_str());
+ }
}
ArrayRef SystemZTargetInfo::getTargetBuiltins() const {
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ad14b5c9b6dc80..eebe60648ed22b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -517,6 +517,72 @@ DerivedArgList *Driver::TranslateInputArgs(const
InputArgList &Args) const {
return DAL
