Skip to content

Commit b1922e5

Browse files
committed
[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
1 parent 3f46e54 commit b1922e5

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ CUDA Support
336336
AIX Support
337337
^^^^^^^^^^^
338338

339+
- Introduced the ``-maix-small-local-exec-tls`` option to produce a faster
340+
access sequence for local-exec TLS variables where the offset from the TLS
341+
base is encoded as an immediate operand.
342+
This access sequence is not used for TLS variables larger than 32KB, and is
343+
currently only supported on 64-bit mode.
344+
339345
WebAssembly Support
340346
^^^^^^^^^^^^^^^^^^^
341347

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4723,6 +4723,12 @@ def mrop_protect : Flag<["-"], "mrop-protect">,
47234723
def mprivileged : Flag<["-"], "mprivileged">,
47244724
Group<m_ppc_Features_Group>;
47254725
} // let Flags = [TargetSpecific]
4726+
def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">,
4727+
Group<m_ppc_Features_Group>,
4728+
HelpText<"Produce a faster access sequence for local-exec TLS variables "
4729+
"where the offset from the TLS base is encoded as an "
4730+
"immediate operand (AIX 64-bit only). "
4731+
"This access sequence is not used for variables larger than 32KB.">;
47264732
def maix_struct_return : Flag<["-"], "maix-struct-return">,
47274733
Group<m_Group>, Visibility<[ClangOption, CC1Option]>,
47284734
HelpText<"Return all structs in memory (PPC32 only)">,

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
7777
HasROPProtect = true;
7878
} else if (Feature == "+privileged") {
7979
HasPrivileged = true;
80+
} else if (Feature == "+aix-small-local-exec-tls") {
81+
HasAIXSmallLocalExecTLS = true;
8082
} else if (Feature == "+isa-v206-instructions") {
8183
IsISA2_06 = true;
8284
} else if (Feature == "+isa-v207-instructions") {
@@ -541,6 +543,10 @@ bool PPCTargetInfo::initFeatureMap(
541543
// Privileged instructions are off by default.
542544
Features["privileged"] = false;
543545

546+
// The code generated by the -maix-small-local-exec-tls option is turned
547+
// off by default.
548+
Features["aix-small-local-exec-tls"] = false;
549+
544550
Features["spe"] = llvm::StringSwitch<bool>(CPU)
545551
.Case("8548", true)
546552
.Case("e500", true)
@@ -635,6 +641,14 @@ bool PPCTargetInfo::initFeatureMap(
635641
return false;
636642
}
637643

644+
if (llvm::is_contained(FeaturesVec, "+aix-small-local-exec-tls")) {
645+
if (!getTriple().isOSAIX() || !getTriple().isArch64Bit()) {
646+
Diags.Report(diag::err_opt_not_valid_on_target)
647+
<< "-maix-small-local-exec-tls";
648+
return false;
649+
}
650+
}
651+
638652
return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
639653
}
640654

@@ -676,6 +690,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
676690
.Case("mma", HasMMA)
677691
.Case("rop-protect", HasROPProtect)
678692
.Case("privileged", HasPrivileged)
693+
.Case("aix-small-local-exec-tls", HasAIXSmallLocalExecTLS)
679694
.Case("isa-v206-instructions", IsISA2_06)
680695
.Case("isa-v207-instructions", IsISA2_07)
681696
.Case("isa-v30-instructions", IsISA3_0)

clang/lib/Basic/Targets/PPC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
6060
bool HasMMA = false;
6161
bool HasROPProtect = false;
6262
bool HasPrivileged = false;
63+
bool HasAIXSmallLocalExecTLS = false;
6364
bool HasVSX = false;
6465
bool UseCRBits = false;
6566
bool HasP8Vector = false;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %clang -target powerpc64-unknown-aix -S -emit-llvm %s -o - | FileCheck %s
2+
// RUN: %clang -target powerpc-unknown-aix -S -emit-llvm %s -o - | FileCheck %s
3+
// RUN: %clang -target powerpc64le-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s
4+
// RUN: %clang -target powerpc64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s
5+
6+
// RUN: %clang -target powerpc64-unknown-aix -maix-small-local-exec-tls -S -emit-llvm \
7+
// RUN: %s -o - | FileCheck %s --check-prefix=CHECK-AIX_SMALL_LOCALEXEC_TLS
8+
9+
// RUN: not %clang -target powerpc-unknown-aix -maix-small-local-exec-tls \
10+
// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-AIX32 %s
11+
// RUN: not %clang -target powerpc64le-unknown-linux-gnu -maix-small-local-exec-tls \
12+
// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-LINUX %s
13+
// RUN: not %clang -target powerpc64-unknown-linux-gnu -maix-small-local-exec-tls \
14+
// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-LINUX %s
15+
16+
int test(void) {
17+
return 0;
18+
}
19+
20+
// CHECK: test() #0 {
21+
// CHECK: attributes #0 = {
22+
// CHECK-SAME: -aix-small-local-exec-tls
23+
24+
// CHECK-UNSUPPORTED-AIX32: option '-maix-small-local-exec-tls' cannot be specified on this target
25+
// CHECK-UNSUPPORTED-LINUX: option '-maix-small-local-exec-tls' cannot be specified on this target
26+
27+
// CHECK-AIX_SMALL_LOCALEXEC_TLS: test() #0 {
28+
// CHECK-AIX_SMALL_LOCALEXEC_TLS: attributes #0 = {
29+
// CHECK-AIX_SMALL_LOCALEXEC_TLS-SAME: +aix-small-local-exec-tls
30+

0 commit comments

Comments
 (0)