Skip to content

Commit 16efd2a

Browse files
author
Felix (Ting Wang)
authored
[AIX][TLS][clang] Add -maix-small-local-dynamic-tls clang option (llvm#88829)
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-dynamic TLS model (formally named aix-small-local-dynamic-tls). This patch mainly references Amy's work on small local-exec TLS support.
1 parent 1effa19 commit 16efd2a

File tree

6 files changed

+51
-14
lines changed

6 files changed

+51
-14
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,12 @@ CUDA Support
659659
AIX Support
660660
^^^^^^^^^^^
661661

662+
- Introduced the ``-maix-small-local-dynamic-tls`` option to produce a faster
663+
access sequence for local-dynamic TLS variables where the offset from the TLS
664+
base is encoded as an immediate operand.
665+
This access sequence is not used for TLS variables larger than 32KB, and is
666+
currently only supported on 64-bit mode.
667+
662668
WebAssembly Support
663669
^^^^^^^^^^^^^^^^^^^
664670

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5041,6 +5041,12 @@ def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">,
50415041
"where the offset from the TLS base is encoded as an "
50425042
"immediate operand (AIX 64-bit only). "
50435043
"This access sequence is not used for variables larger than 32KB.">;
5044+
def maix_small_local_dynamic_tls : Flag<["-"], "maix-small-local-dynamic-tls">,
5045+
Group<m_ppc_Features_Group>,
5046+
HelpText<"Produce a faster access sequence for local-dynamic TLS variables "
5047+
"where the offset from the TLS base is encoded as an "
5048+
"immediate operand (AIX 64-bit only). "
5049+
"This access sequence is not used for variables larger than 32KB.">;
50445050
def maix_struct_return : Flag<["-"], "maix-struct-return">,
50455051
Group<m_Group>, Visibility<[ClangOption, CC1Option]>,
50465052
HelpText<"Return all structs in memory (PPC32 only)">,

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
7979
HasPrivileged = true;
8080
} else if (Feature == "+aix-small-local-exec-tls") {
8181
HasAIXSmallLocalExecTLS = true;
82+
} else if (Feature == "+aix-small-local-dynamic-tls") {
83+
HasAIXSmallLocalDynamicTLS = true;
8284
} else if (Feature == "+isa-v206-instructions") {
8385
IsISA2_06 = true;
8486
} else if (Feature == "+isa-v207-instructions") {
@@ -573,9 +575,10 @@ bool PPCTargetInfo::initFeatureMap(
573575
// Privileged instructions are off by default.
574576
Features["privileged"] = false;
575577

576-
// The code generated by the -maix-small-local-exec-tls option is turned
577-
// off by default.
578+
// The code generated by the -maix-small-local-[exec|dynamic]-tls option is
579+
// turned off by default.
578580
Features["aix-small-local-exec-tls"] = false;
581+
Features["aix-small-local-dynamic-tls"] = false;
579582

580583
Features["spe"] = llvm::StringSwitch<bool>(CPU)
581584
.Case("8548", true)
@@ -713,6 +716,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
713716
.Case("rop-protect", HasROPProtect)
714717
.Case("privileged", HasPrivileged)
715718
.Case("aix-small-local-exec-tls", HasAIXSmallLocalExecTLS)
719+
.Case("aix-small-local-dynamic-tls", HasAIXSmallLocalDynamicTLS)
716720
.Case("isa-v206-instructions", IsISA2_06)
717721
.Case("isa-v207-instructions", IsISA2_07)
718722
.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
@@ -61,6 +61,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
6161
bool HasROPProtect = false;
6262
bool HasPrivileged = false;
6363
bool HasAIXSmallLocalExecTLS = false;
64+
bool HasAIXSmallLocalDynamicTLS = false;
6465
bool HasVSX = false;
6566
bool UseCRBits = false;
6667
bool HasP8Vector = false;

clang/lib/Driver/ToolChains/Arch/PPC.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,22 @@ void ppc::getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
125125

126126
bool UseSeparateSections = isUseSeparateSections(Triple);
127127
bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
128-
if (Args.hasArg(options::OPT_maix_small_local_exec_tls)) {
128+
if (Args.hasArg(options::OPT_maix_small_local_exec_tls) ||
129+
Args.hasArg(options::OPT_maix_small_local_dynamic_tls)) {
129130
if (!Triple.isOSAIX() || !Triple.isArch64Bit())
130-
D.Diag(diag::err_opt_not_valid_on_target) << "-maix-small-local-exec-tls";
131+
D.Diag(diag::err_opt_not_valid_on_target)
132+
<< "-maix-small-local-[exec|dynamic]-tls";
131133

132-
// The -maix-small-local-exec-tls option should only be used with
134+
// The -maix-small-local-[exec|dynamic]-tls option should only be used with
133135
// -fdata-sections, as having data sections turned off with this option
134-
// is not ideal for performance. Moreover, the small-local-exec-tls region
135-
// is a limited resource, and should not be used for variables that may
136-
// be replaced.
136+
// is not ideal for performance. Moreover, the
137+
// small-local-[exec|dynamic]-tls region is a limited resource, and should
138+
// not be used for variables that may be replaced.
137139
if (!Args.hasFlag(options::OPT_fdata_sections,
138140
options::OPT_fno_data_sections,
139141
UseSeparateSections || HasDefaultDataSections))
140142
D.Diag(diag::err_drv_argument_only_allowed_with)
141-
<< "-maix-small-local-exec-tls"
142-
<< "-fdata-sections";
143+
<< "-maix-small-local-[exec|dynamic]-tls" << "-fdata-sections";
143144
}
144145
}
145146

clang/test/Driver/aix-small-local-exec-tls.c renamed to clang/test/Driver/aix-small-local-exec-dynamic-tls.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
// RUN: %clang -target powerpc64-unknown-aix -maix-small-local-exec-tls -S -emit-llvm \
77
// RUN: %s -o - | FileCheck %s --check-prefix=CHECK-AIX_SMALL_LOCALEXEC_TLS
88

9+
// RUN: %clang -target powerpc64-unknown-aix -maix-small-local-dynamic-tls -S -emit-llvm \
10+
// RUN: %s -o - | FileCheck %s --check-prefix=CHECK-AIX_SMALL_LOCALDYNAMIC_TLS
11+
912
// RUN: not %clang -target powerpc-unknown-aix -maix-small-local-exec-tls \
1013
// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-AIX32 %s
1114
// RUN: not %clang -target powerpc64le-unknown-linux-gnu -maix-small-local-exec-tls \
@@ -19,19 +22,35 @@
1922
// RUN: -fsyntax-only -fno-data-sections %s 2>&1 | \
2023
// RUN: FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
2124

25+
// RUN: not %clang -target powerpc-unknown-aix -maix-small-local-dynamic-tls \
26+
// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-AIX32 %s
27+
// RUN: not %clang -target powerpc64le-unknown-linux-gnu -maix-small-local-dynamic-tls \
28+
// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-LINUX %s
29+
// RUN: not %clang -target powerpc64-unknown-linux-gnu -maix-small-local-dynamic-tls \
30+
// RUN: -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-LINUX %s
31+
// RUN: not %clang -target powerpc64-unknown-aix -maix-small-local-dynamic-tls \
32+
// RUN: -fsyntax-only -fno-data-sections %s 2>&1 | \
33+
// RUN: FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
34+
// RUN: not %clang -target powerpc64-unknown-linux-gnu -maix-small-local-dynamic-tls \
35+
// RUN: -fsyntax-only -fno-data-sections %s 2>&1 | \
36+
// RUN: FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
37+
2238
int test(void) {
2339
return 0;
2440
}
2541

2642
// CHECK: test() #0 {
2743
// CHECK: attributes #0 = {
28-
// CHECK-SAME: -aix-small-local-exec-tls
44+
// CHECK-SAME: {{-aix-small-local-exec-tls,.*-aix-small-local-dynamic-tls|-aix-small-local-dynamic-tls,.*-aix-small-local-exec-tls}}
2945

30-
// CHECK-UNSUPPORTED-AIX32: option '-maix-small-local-exec-tls' cannot be specified on this target
31-
// CHECK-UNSUPPORTED-LINUX: option '-maix-small-local-exec-tls' cannot be specified on this target
32-
// CHECK-UNSUPPORTED-NO-DATASEC: invalid argument '-maix-small-local-exec-tls' only allowed with '-fdata-sections'
46+
// CHECK-UNSUPPORTED-AIX32: option '-maix-small-local-[exec|dynamic]-tls' cannot be specified on this target
47+
// CHECK-UNSUPPORTED-LINUX: option '-maix-small-local-[exec|dynamic]-tls' cannot be specified on this target
48+
// CHECK-UNSUPPORTED-NO-DATASEC: invalid argument '-maix-small-local-[exec|dynamic]-tls' only allowed with '-fdata-sections'
3349

3450
// CHECK-AIX_SMALL_LOCALEXEC_TLS: test() #0 {
3551
// CHECK-AIX_SMALL_LOCALEXEC_TLS: attributes #0 = {
3652
// CHECK-AIX_SMALL_LOCALEXEC_TLS-SAME: +aix-small-local-exec-tls
3753

54+
// CHECK-AIX_SMALL_LOCALDYNAMIC_TLS: test() #0 {
55+
// CHECK-AIX_SMALL_LOCALDYNAMIC_TLS: attributes #0 = {
56+
// CHECK-AIX_SMALL_LOCALDYNAMIC_TLS-SAME: +aix-small-local-dynamic-tls

0 commit comments

Comments
 (0)