Author: Amy Kwan Date: 2023-09-07T20:05:29-05:00 New Revision: b1922e55ab3b35dff99238fd0b74be00df0472e7
URL: https://github.com/llvm/llvm-project/commit/b1922e55ab3b35dff99238fd0b74be00df0472e7 DIFF: https://github.com/llvm/llvm-project/commit/b1922e55ab3b35dff99238fd0b74be00df0472e7.diff LOG: [AIX][TLS][clang] Add -maix-small-local-exec-tls clang option. This patch adds the clang portion of an AIX-specific option to inform the compiler that it can use a faster access sequence for the local-exec TLS model (formally named aix-small-local-exec-tls). This patch only adds the frontend portion of the option, building upon: Backend portion of the option (D156203) Backend patch that utilizes this option to actually produce the faster access sequence (D155600) Differential Revision: https://reviews.llvm.org/D155544 Added: clang/test/Driver/aix-small-local-exec-tls.c Modified: clang/docs/ReleaseNotes.rst clang/include/clang/Driver/Options.td clang/lib/Basic/Targets/PPC.cpp clang/lib/Basic/Targets/PPC.h Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index acce35e231e714d..1ac0cb2fac72a79 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -336,6 +336,12 @@ CUDA Support AIX Support ^^^^^^^^^^^ +- Introduced the ``-maix-small-local-exec-tls`` option to produce a faster + access sequence for local-exec TLS variables where the offset from the TLS + base is encoded as an immediate operand. + This access sequence is not used for TLS variables larger than 32KB, and is + currently only supported on 64-bit mode. + WebAssembly Support ^^^^^^^^^^^^^^^^^^^ diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 9a6e7e9929f5f2f..b29e2e53f938544 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4723,6 +4723,12 @@ def mrop_protect : Flag<["-"], "mrop-protect">, def mprivileged : Flag<["-"], "mprivileged">, Group<m_ppc_Features_Group>; } // let Flags = [TargetSpecific] +def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">, + Group<m_ppc_Features_Group>, + HelpText<"Produce a faster access sequence for local-exec TLS variables " + "where the offset from the TLS base is encoded as an " + "immediate operand (AIX 64-bit only). " + "This access sequence is not used for variables larger than 32KB.">; def maix_struct_return : Flag<["-"], "maix-struct-return">, Group<m_Group>, Visibility<[ClangOption, CC1Option]>, HelpText<"Return all structs in memory (PPC32 only)">, diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp index 89aa9bd585119cd..e0abc069032e1ce 100644 --- a/clang/lib/Basic/Targets/PPC.cpp +++ b/clang/lib/Basic/Targets/PPC.cpp @@ -77,6 +77,8 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features, HasROPProtect = true; } else if (Feature == "+privileged") { HasPrivileged = true; + } else if (Feature == "+aix-small-local-exec-tls") { + HasAIXSmallLocalExecTLS = true; } else if (Feature == "+isa-v206-instructions") { IsISA2_06 = true; } else if (Feature == "+isa-v207-instructions") { @@ -541,6 +543,10 @@ bool PPCTargetInfo::initFeatureMap( // Privileged instructions are off by default. Features["privileged"] = false; + // The code generated by the -maix-small-local-exec-tls option is turned + // off by default. + Features["aix-small-local-exec-tls"] = false; + Features["spe"] = llvm::StringSwitch<bool>(CPU) .Case("8548", true) .Case("e500", true) @@ -635,6 +641,14 @@ bool PPCTargetInfo::initFeatureMap( return false; } + if (llvm::is_contained(FeaturesVec, "+aix-small-local-exec-tls")) { + if (!getTriple().isOSAIX() || !getTriple().isArch64Bit()) { + Diags.Report(diag::err_opt_not_valid_on_target) + << "-maix-small-local-exec-tls"; + return false; + } + } + return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec); } @@ -676,6 +690,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const { .Case("mma", HasMMA) .Case("rop-protect", HasROPProtect) .Case("privileged", HasPrivileged) + .Case("aix-small-local-exec-tls", HasAIXSmallLocalExecTLS) .Case("isa-v206-instructions", IsISA2_06) .Case("isa-v207-instructions", IsISA2_07) .Case("isa-v30-instructions", IsISA3_0) diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h index bc06e7978ac3bc3..ef667b3d511f0e6 100644 --- a/clang/lib/Basic/Targets/PPC.h +++ b/clang/lib/Basic/Targets/PPC.h @@ -60,6 +60,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo { bool HasMMA = false; bool HasROPProtect = false; bool HasPrivileged = false; + bool HasAIXSmallLocalExecTLS = false; bool HasVSX = false; bool UseCRBits = false; bool HasP8Vector = false; diff --git a/clang/test/Driver/aix-small-local-exec-tls.c b/clang/test/Driver/aix-small-local-exec-tls.c new file mode 100644 index 000000000000000..7a2eec6989eef89 --- /dev/null +++ b/clang/test/Driver/aix-small-local-exec-tls.c @@ -0,0 +1,30 @@ +// RUN: %clang -target powerpc64-unknown-aix -S -emit-llvm %s -o - | FileCheck %s +// RUN: %clang -target powerpc-unknown-aix -S -emit-llvm %s -o - | FileCheck %s +// RUN: %clang -target powerpc64le-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s +// RUN: %clang -target powerpc64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s + +// RUN: %clang -target powerpc64-unknown-aix -maix-small-local-exec-tls -S -emit-llvm \ +// RUN: %s -o - | FileCheck %s --check-prefix=CHECK-AIX_SMALL_LOCALEXEC_TLS + +// RUN: not %clang -target powerpc-unknown-aix -maix-small-local-exec-tls \ +// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-AIX32 %s +// RUN: not %clang -target powerpc64le-unknown-linux-gnu -maix-small-local-exec-tls \ +// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-LINUX %s +// RUN: not %clang -target powerpc64-unknown-linux-gnu -maix-small-local-exec-tls \ +// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-LINUX %s + +int test(void) { + return 0; +} + +// CHECK: test() #0 { +// CHECK: attributes #0 = { +// CHECK-SAME: -aix-small-local-exec-tls + +// CHECK-UNSUPPORTED-AIX32: option '-maix-small-local-exec-tls' cannot be specified on this target +// CHECK-UNSUPPORTED-LINUX: option '-maix-small-local-exec-tls' cannot be specified on this target + +// CHECK-AIX_SMALL_LOCALEXEC_TLS: test() #0 { +// CHECK-AIX_SMALL_LOCALEXEC_TLS: attributes #0 = { +// CHECK-AIX_SMALL_LOCALEXEC_TLS-SAME: +aix-small-local-exec-tls + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits