[flang-commits] [clang] [flang] [flang] Support -mabi=vec-extabi and -mabi=vec-default on AIX (PR #113215)
Kelvin Li via flang-commits
flang-commits at lists.llvm.org
Wed Oct 23 10:37:39 PDT 2024
https://github.com/kkwli updated https://github.com/llvm/llvm-project/pull/113215
>From 3c57a70bf075d17bf9001bd6ec505170179ace9b Mon Sep 17 00:00:00 2001
From: Kelvin Li <kli at ca.ibm.com>
Date: Fri, 18 Oct 2024 23:25:27 -0400
Subject: [PATCH 1/2] [flang] Support -mabi=vec-extabi and -mabi=vec-default on
AIX
---
clang/include/clang/Driver/Options.td | 4 ++-
clang/lib/Driver/ToolChains/Flang.cpp | 29 ++++++++++++++++++++
clang/lib/Driver/ToolChains/Flang.h | 7 +++++
flang/include/flang/Frontend/TargetOptions.h | 3 ++
flang/lib/Frontend/CompilerInstance.cpp | 7 +++--
flang/lib/Frontend/CompilerInvocation.cpp | 10 +++++++
flang/test/Driver/mabi.f90 | 13 +++++++++
7 files changed, 70 insertions(+), 3 deletions(-)
create mode 100644 flang/test/Driver/mabi.f90
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 6491e9ac73ce99..1848f8cc90d8b0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4662,7 +4662,8 @@ def malign_loops_EQ : Joined<["-"], "malign-loops=">, Group<clang_ignored_m_Grou
def malign_jumps_EQ : Joined<["-"], "malign-jumps=">, Group<clang_ignored_m_Group>;
let Flags = [TargetSpecific] in {
-def mabi_EQ : Joined<["-"], "mabi=">, Group<m_Group>;
+def mabi_EQ : Joined<["-"], "mabi=">, Group<m_Group>,
+ Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
def malign_branch_EQ : CommaJoined<["-"], "malign-branch=">, Group<m_Group>,
HelpText<"Specify types of branches to align">;
def malign_branch_boundary_EQ : Joined<["-"], "malign-branch-boundary=">, Group<m_Group>,
@@ -7326,6 +7327,7 @@ def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">,
HelpText<"Use IEEE 754 quadruple-precision for long double">,
MarshallingInfoFlag<LangOpts<"PPCIEEELongDouble">>;
def mabi_EQ_vec_extabi : Flag<["-"], "mabi=vec-extabi">,
+ Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
HelpText<"Enable the extended Altivec ABI on AIX. Use volatile and nonvolatile vector registers">,
MarshallingInfoFlag<LangOpts<"EnableAIXExtendedAltivecABI">>;
def mfloat_abi : Separate<["-"], "mfloat-abi">,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index e2f8f6e0cca1c6..5900836cabcbc4 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -203,6 +203,30 @@ void Flang::AddAArch64TargetArgs(const ArgList &Args,
}
}
+void Flang::AddPPCTargetArgs(const ArgList &Args,
+ ArgStringList &CmdArgs) const {
+ bool VecExtabi = false;
+ for (const Arg *A : Args.filtered(options::OPT_mabi_EQ)) {
+ StringRef V = A->getValue();
+ if (V == "vec-default") {
+ VecExtabi = false;
+ A->claim();
+ } else if (V == "vec-extabi") {
+ VecExtabi = true;
+ A->claim();
+ }
+ }
+ const llvm::Triple &T = getToolChain().getTriple();
+ if (VecExtabi) {
+ if (!T.isOSAIX()) {
+ const Driver &D = getToolChain().getDriver();
+ D.Diag(diag::err_drv_unsupported_opt_for_target)
+ << "-mabi=vec-extabi" << T.str();
+ }
+ CmdArgs.push_back("-mabi=vec-extabi");
+ }
+}
+
void Flang::AddRISCVTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
const llvm::Triple &Triple = getToolChain().getTriple();
@@ -383,6 +407,11 @@ void Flang::addTargetOptions(const ArgList &Args,
getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
AddX86_64TargetArgs(Args, CmdArgs);
break;
+ case llvm::Triple::ppc:
+ case llvm::Triple::ppc64:
+ case llvm::Triple::ppc64le:
+ AddPPCTargetArgs(Args, CmdArgs);
+ break;
}
if (Arg *A = Args.getLastArg(options::OPT_fveclib)) {
diff --git a/clang/lib/Driver/ToolChains/Flang.h b/clang/lib/Driver/ToolChains/Flang.h
index 9f5e26b8608324..4d7d0b8cd9ea55 100644
--- a/clang/lib/Driver/ToolChains/Flang.h
+++ b/clang/lib/Driver/ToolChains/Flang.h
@@ -84,6 +84,13 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
void AddX86_64TargetArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;
+ /// Add specific options for PPC target.
+ ///
+ /// \param [in] Args The list of input driver arguments
+ /// \param [out] CmdArgs The list of output command arguments
+ void AddPPCTargetArgs(const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const;
+
/// Extract offload options from the driver arguments and add them to
/// the command arguments.
/// \param [in] C The current compilation for the driver invocation
diff --git a/flang/include/flang/Frontend/TargetOptions.h b/flang/include/flang/Frontend/TargetOptions.h
index 332adcbe6b6ac3..01c878067b921d 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -44,6 +44,9 @@ class TargetOptions {
/// The integer KINDs disabled for this target
std::vector<int> disabledIntegerKinds;
+
+ /// Extended Altivec ABI on AIX
+ bool EnableAIXExtendedAltivecABI;
};
} // end namespace Fortran::frontend
diff --git a/flang/lib/Frontend/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp
index d37430e0e5773e..35c2ae3c73e69e 100644
--- a/flang/lib/Frontend/CompilerInstance.cpp
+++ b/flang/lib/Frontend/CompilerInstance.cpp
@@ -313,7 +313,6 @@ bool CompilerInstance::setUpTargetMachine() {
<< error;
return false;
}
-
// Create `TargetMachine`
const auto &CGOpts = getInvocation().getCodeGenOpts();
std::optional<llvm::CodeGenOptLevel> OptLevelOrNone =
@@ -322,9 +321,13 @@ bool CompilerInstance::setUpTargetMachine() {
llvm::CodeGenOptLevel OptLevel = *OptLevelOrNone;
std::string featuresStr = getTargetFeatures();
std::optional<llvm::CodeModel::Model> cm = getCodeModel(CGOpts.CodeModel);
+
+ llvm::TargetOptions tOpts = llvm::TargetOptions();
+ tOpts.EnableAIXExtendedAltivecABI = targetOpts.EnableAIXExtendedAltivecABI;
+
targetMachine.reset(theTarget->createTargetMachine(
theTriple, /*CPU=*/targetOpts.cpu,
- /*Features=*/featuresStr, llvm::TargetOptions(),
+ /*Features=*/featuresStr, /*Options=*/tOpts,
/*Reloc::Model=*/CGOpts.getRelocationModel(),
/*CodeModel::Model=*/cm, OptLevel));
assert(targetMachine && "Failed to create TargetMachine");
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 4607a33ffda6cc..0e39906f32854f 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -457,6 +457,16 @@ static void parseTargetArgs(TargetOptions &opts, llvm::opt::ArgList &args) {
if (args.hasArg(clang::driver::options::OPT_fdisable_integer_16))
opts.disabledIntegerKinds.push_back(16);
+
+ if (const llvm::opt::Arg *a =
+ args.getLastArg(clang::driver::options::OPT_mabi_EQ)) {
+ llvm::StringRef V = a->getValue();
+ if (V == "vec-extabi") {
+ opts.EnableAIXExtendedAltivecABI = true;
+ } else if (V == "vec-default") {
+ opts.EnableAIXExtendedAltivecABI = false;
+ }
+ }
}
// Tweak the frontend configuration based on the frontend action
static void setUpFrontendBasedOnAction(FrontendOptions &opts) {
diff --git a/flang/test/Driver/mabi.f90 b/flang/test/Driver/mabi.f90
new file mode 100644
index 00000000000000..29f1f78e4fa07a
--- /dev/null
+++ b/flang/test/Driver/mabi.f90
@@ -0,0 +1,13 @@
+! RUN: not %flang -### -c --target=powerpc64le-unknown-linux -mabi=vec-extabi %s 2>&1 | FileCheck --check-prefix=INVALID1 %s
+! RUN: not %flang -### -c --target=x86_64-unknown-linux -mabi=vec-extabi %s 2>&1 | FileCheck --check-prefix=INVALID2 %s
+! RUN: %flang -### -c -target powerpc-unknown-aix %s 2>&1 | FileCheck --implicit-check-not=vec-extabi %s
+! RUN: %flang -### -c -target powerpc-unknown-aix -mabi=vec-default %s 2>&1 | FileCheck --implicit-check-not=vec-extabi %s
+! RUN: %flang -### -c -target powerpc-unknown-aix -mabi=vec-extabi %s 2>&1 | FileCheck --check-prefix=EXTABI %s
+
+! INVALID1: error: unsupported option '-mabi=vec-extabi' for target '{{.*}}'
+! INVALID2: error: unsupported option '-mabi=' for target '{{.*}}'
+
+! EXTABI: "-fc1"
+! EXTABI-SAME: "-mabi=vec-extabi"
+
+
>From 40919595b58836d16e2d1828ae4e93f6f8448fe8 Mon Sep 17 00:00:00 2001
From: Kelvin Li <kli at ca.ibm.com>
Date: Wed, 23 Oct 2024 13:35:33 -0400
Subject: [PATCH 2/2] Address review comments - simplify option check - add
diagnostic of wrong option arg
---
clang/lib/Driver/ToolChains/Flang.cpp | 17 ++++++++++-------
flang/test/Driver/mabi.f90 | 2 ++
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 5900836cabcbc4..ef1a80a4107229 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -205,21 +205,24 @@ void Flang::AddAArch64TargetArgs(const ArgList &Args,
void Flang::AddPPCTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
+ const Driver &D = getToolChain().getDriver();
bool VecExtabi = false;
- for (const Arg *A : Args.filtered(options::OPT_mabi_EQ)) {
+
+ if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
StringRef V = A->getValue();
- if (V == "vec-default") {
- VecExtabi = false;
- A->claim();
- } else if (V == "vec-extabi") {
+ if (V == "vec-extabi") {
VecExtabi = true;
- A->claim();
+ } else if (V == "vec-default") {
+ VecExtabi = false;
+ } else {
+ D.Diag(diag::err_drv_unsupported_option_argument)
+ << A->getSpelling() << V;
}
}
+
const llvm::Triple &T = getToolChain().getTriple();
if (VecExtabi) {
if (!T.isOSAIX()) {
- const Driver &D = getToolChain().getDriver();
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< "-mabi=vec-extabi" << T.str();
}
diff --git a/flang/test/Driver/mabi.f90 b/flang/test/Driver/mabi.f90
index 29f1f78e4fa07a..24f392e8ca99ce 100644
--- a/flang/test/Driver/mabi.f90
+++ b/flang/test/Driver/mabi.f90
@@ -1,11 +1,13 @@
! RUN: not %flang -### -c --target=powerpc64le-unknown-linux -mabi=vec-extabi %s 2>&1 | FileCheck --check-prefix=INVALID1 %s
! RUN: not %flang -### -c --target=x86_64-unknown-linux -mabi=vec-extabi %s 2>&1 | FileCheck --check-prefix=INVALID2 %s
+! RUN: not %flang -### -c --target=powerpc-unknown-aix -mabi=abc %s 2>&1 | FileCheck --check-prefix=INVALID3 %s
! RUN: %flang -### -c -target powerpc-unknown-aix %s 2>&1 | FileCheck --implicit-check-not=vec-extabi %s
! RUN: %flang -### -c -target powerpc-unknown-aix -mabi=vec-default %s 2>&1 | FileCheck --implicit-check-not=vec-extabi %s
! RUN: %flang -### -c -target powerpc-unknown-aix -mabi=vec-extabi %s 2>&1 | FileCheck --check-prefix=EXTABI %s
! INVALID1: error: unsupported option '-mabi=vec-extabi' for target '{{.*}}'
! INVALID2: error: unsupported option '-mabi=' for target '{{.*}}'
+! INVALID3: error: unsupported argument 'abc' to option '-mabi='
! EXTABI: "-fc1"
! EXTABI-SAME: "-mabi=vec-extabi"
More information about the flang-commits
mailing list