diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -336,6 +336,12 @@ 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 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4723,6 +4723,12 @@ def mprivileged : Flag<["-"], "mprivileged">, Group; } // let Flags = [TargetSpecific] +def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">, + 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, Visibility<[ClangOption, CC1Option]>, HelpText<"Return all structs in memory (PPC32 only)">, diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h --- a/clang/lib/Basic/Targets/PPC.h +++ b/clang/lib/Basic/Targets/PPC.h @@ -60,6 +60,7 @@ 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/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp --- a/clang/lib/Basic/Targets/PPC.cpp +++ b/clang/lib/Basic/Targets/PPC.cpp @@ -77,6 +77,8 @@ 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 @@ // 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(CPU) .Case("8548", true) .Case("e500", true) @@ -635,6 +641,14 @@ 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 @@ .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/test/Driver/aix-small-local-exec-tls.c b/clang/test/Driver/aix-small-local-exec-tls.c new file mode 100644 --- /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 +