[llvm] [clang] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-26 Thread Amy Kwan via cfe-commits

https://github.com/amy-kwan closed 
https://github.com/llvm/llvm-project/pull/79252
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-26 Thread Amy Kwan via cfe-commits


@@ -124,10 +124,23 @@ void PPCSubtarget::initSubtargetFeatures(StringRef CPU, 
StringRef TuneCPU,
   // Determine endianness.
   IsLittleEndian = TM.isLittleEndian();
 
-  if (HasAIXSmallLocalExecTLS && (!TargetTriple.isOSAIX() || !IsPPC64))
-report_fatal_error(
-  "The aix-small-local-exec-tls attribute is only supported on AIX in "
-  "64-bit mode.\n", false);
+  if (HasAIXSmallLocalExecTLS) {
+if (!TargetTriple.isOSAIX() || !IsPPC64)
+  report_fatal_error(
+  "The aix-small-local-exec-tls attribute is only supported on AIX in "
+  "64-bit mode.\n",
+  false);
+// The aix-small-local-exec-tls attribute should only be used with
+// -data-sections, as having data sections turned off with this option
+// is not ideal for performance. Moreover, the small-local-exec-tls region
+// is a limited resource, and should not be used for variables that may
+// be replaced.
+if (!TM.getDataSections())
+  report_fatal_error(
+  "The aix-small-local-exec-tls attribute can only be specified with "
+  "-data-sections.\n",

amy-kwan wrote:

I kept the llvm portion as `-data-sections` since the option for llc is 
`-data-sections` rather than `-fdata-sections` (which is the option for clang).

https://github.com/llvm/llvm-project/pull/79252
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-25 Thread Amy Kwan via cfe-commits

https://github.com/amy-kwan updated 
https://github.com/llvm/llvm-project/pull/79252

>From 3efadc26e156d8412972ce35cc52559295131eb8 Mon Sep 17 00:00:00 2001
From: Amy Kwan 
Date: Tue, 23 Jan 2024 22:19:49 -0600
Subject: [PATCH 1/2] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls
 and -fno-data-sections

This patch disallows the use of the -maix-small-local-exec-tls and
-fno-data-sections options within clang, and also disallows the use of the
aix-small-local-exec-tls attribute with the -data-sections=false option in llc.

This is because having data sections off when using the aix-small-local-exec-tls
feature is not ideal for performance. As the small-local-exec-tls region is a
limited resource, this space should not used for variables that may be replaced.

Note, that on AIX, data sections is turned on by default, so this patch makes it
so that a diagnostic is emitted when users explicitly turn off data sections
while using the aix-small-local-exec-tls feature.
---
 clang/lib/Basic/Targets/PPC.cpp   |  8 ---
 clang/lib/Driver/ToolChains/Arch/PPC.cpp  | 19 +
 clang/test/Driver/aix-small-local-exec-tls.c  |  7 +++
 llvm/lib/Target/PowerPC/PPCSubtarget.cpp  | 21 +++
 ...ix-small-local-exec-tls-opt-IRattribute.ll |  7 +++
 5 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 65909eb79fa7f5..85046bffbc1ef9 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -671,14 +671,6 @@ 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);
 }
 
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index ab24d14992cd7a..5ffe73236205d3 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -122,6 +122,25 @@ void ppc::getPPCTargetFeatures(const Driver , const 
llvm::Triple ,
   ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
   if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
 Features.push_back("+secure-plt");
+
+  bool UseSeparateSections = isUseSeparateSections(Triple);
+  bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
+  if (Args.hasArg(options::OPT_maix_small_local_exec_tls)) {
+if (!Triple.isOSAIX() || !Triple.isArch64Bit())
+  D.Diag(diag::err_opt_not_valid_on_target) << 
"-maix-small-local-exec-tls";
+
+// The -maix-small-local-exec-tls option should only be used with
+// -fdata-sections, as having data sections turned off with this option
+// is not ideal for performance. Moreover, the small-local-exec-tls region
+// is a limited resource, and should not be used for variables that may
+// be replaced.
+if (!Args.hasFlag(options::OPT_fdata_sections,
+  options::OPT_fno_data_sections,
+  UseSeparateSections || HasDefaultDataSections))
+  D.Diag(diag::err_drv_argument_only_allowed_with)
+  << "-maix-small-local-exec-tls"
+  << "-fdata-sections";
+  }
 }
 
 ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver , const 
llvm::Triple ,
diff --git a/clang/test/Driver/aix-small-local-exec-tls.c 
b/clang/test/Driver/aix-small-local-exec-tls.c
index 7a2eec6989eef8..e6719502a3babc 100644
--- a/clang/test/Driver/aix-small-local-exec-tls.c
+++ b/clang/test/Driver/aix-small-local-exec-tls.c
@@ -12,6 +12,12 @@
 // 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
+// RUN: not %clang -target powerpc64-unknown-aix -maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
+// RUN: not %clang -target powerpc64-unknown-linux-gnu 
-maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
 
 int test(void) {
   return 0;
@@ -23,6 +29,7 @@ int test(void) {
 
 // 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-UNSUPPORTED-NO-DATASEC: invalid argument '-maix-small-local-exec-tls' 
only allowed with '-fdata-sections'
 
 // CHECK-AIX_SMALL_LOCALEXEC_TLS: test() #0 {
 // CHECK-AIX_SMALL_LOCALEXEC_TLS: attributes #0 = {
diff --git 

[llvm] [clang] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-25 Thread Amy Kwan via cfe-commits

https://github.com/amy-kwan updated 
https://github.com/llvm/llvm-project/pull/79252

>From 7e56809d82d1a1f64cee5f88607a0e279e56daca Mon Sep 17 00:00:00 2001
From: Amy Kwan 
Date: Tue, 23 Jan 2024 22:19:49 -0600
Subject: [PATCH 1/2] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls
 and -fno-data-sections

This patch disallows the use of the -maix-small-local-exec-tls and
-fno-data-sections options within clang, and also disallows the use of the
aix-small-local-exec-tls attribute with the -data-sections=false option in llc.

This is because having data sections off when using the aix-small-local-exec-tls
feature is not ideal for performance. As the small-local-exec-tls region is a
limited resource, this space should not used for variables that may be replaced.

Note, that on AIX, data sections is turned on by default, so this patch makes it
so that a diagnostic is emitted when users explicitly turn off data sections
while using the aix-small-local-exec-tls feature.
---
 clang/lib/Basic/Targets/PPC.cpp   |  8 ---
 clang/lib/Driver/ToolChains/Arch/PPC.cpp  | 19 +
 clang/test/Driver/aix-small-local-exec-tls.c  |  7 +++
 llvm/lib/Target/PowerPC/PPCSubtarget.cpp  | 21 +++
 ...ix-small-local-exec-tls-opt-IRattribute.ll |  7 +++
 5 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 41935abfb65d3b9..911b80c98f7ad62 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -646,14 +646,6 @@ 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);
 }
 
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index ab24d14992cd7a1..5ffe73236205d3b 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -122,6 +122,25 @@ void ppc::getPPCTargetFeatures(const Driver , const 
llvm::Triple ,
   ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
   if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
 Features.push_back("+secure-plt");
+
+  bool UseSeparateSections = isUseSeparateSections(Triple);
+  bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
+  if (Args.hasArg(options::OPT_maix_small_local_exec_tls)) {
+if (!Triple.isOSAIX() || !Triple.isArch64Bit())
+  D.Diag(diag::err_opt_not_valid_on_target) << 
"-maix-small-local-exec-tls";
+
+// The -maix-small-local-exec-tls option should only be used with
+// -fdata-sections, as having data sections turned off with this option
+// is not ideal for performance. Moreover, the small-local-exec-tls region
+// is a limited resource, and should not be used for variables that may
+// be replaced.
+if (!Args.hasFlag(options::OPT_fdata_sections,
+  options::OPT_fno_data_sections,
+  UseSeparateSections || HasDefaultDataSections))
+  D.Diag(diag::err_drv_argument_only_allowed_with)
+  << "-maix-small-local-exec-tls"
+  << "-fdata-sections";
+  }
 }
 
 ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver , const 
llvm::Triple ,
diff --git a/clang/test/Driver/aix-small-local-exec-tls.c 
b/clang/test/Driver/aix-small-local-exec-tls.c
index 7a2eec6989eef89..e6719502a3babc3 100644
--- a/clang/test/Driver/aix-small-local-exec-tls.c
+++ b/clang/test/Driver/aix-small-local-exec-tls.c
@@ -12,6 +12,12 @@
 // 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
+// RUN: not %clang -target powerpc64-unknown-aix -maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
+// RUN: not %clang -target powerpc64-unknown-linux-gnu 
-maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
 
 int test(void) {
   return 0;
@@ -23,6 +29,7 @@ int test(void) {
 
 // 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-UNSUPPORTED-NO-DATASEC: invalid argument '-maix-small-local-exec-tls' 
only allowed with '-fdata-sections'
 
 // CHECK-AIX_SMALL_LOCALEXEC_TLS: test() #0 {
 // CHECK-AIX_SMALL_LOCALEXEC_TLS: attributes #0 = {
diff 

[llvm] [clang] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-25 Thread Amy Kwan via cfe-commits

https://github.com/amy-kwan updated 
https://github.com/llvm/llvm-project/pull/79252

>From dc55bb565e6f778803604dfaa2874ce1d5fbdc86 Mon Sep 17 00:00:00 2001
From: Amy Kwan 
Date: Tue, 23 Jan 2024 22:19:49 -0600
Subject: [PATCH 1/2] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls
 and -fno-data-sections

This patch disallows the use of the -maix-small-local-exec-tls and
-fno-data-sections options within clang, and also disallows the use of the
aix-small-local-exec-tls attribute with the -data-sections=false option in llc.

This is because having data sections off when using the aix-small-local-exec-tls
feature is not ideal for performance. As the small-local-exec-tls region is a
limited resource, this space should not used for variables that may be replaced.

Note, that on AIX, data sections is turned on by default, so this patch makes it
so that a diagnostic is emitted when users explicitly turn off data sections
while using the aix-small-local-exec-tls feature.
---
 clang/lib/Basic/Targets/PPC.cpp   |  8 ---
 clang/lib/Driver/ToolChains/Arch/PPC.cpp  | 19 +
 clang/test/Driver/aix-small-local-exec-tls.c  |  7 +++
 llvm/lib/Target/PowerPC/PPCSubtarget.cpp  | 21 +++
 ...ix-small-local-exec-tls-opt-IRattribute.ll |  7 +++
 5 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 41935abfb65d3b9..911b80c98f7ad62 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -646,14 +646,6 @@ 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);
 }
 
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index ab24d14992cd7a1..5ffe73236205d3b 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -122,6 +122,25 @@ void ppc::getPPCTargetFeatures(const Driver , const 
llvm::Triple ,
   ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
   if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
 Features.push_back("+secure-plt");
+
+  bool UseSeparateSections = isUseSeparateSections(Triple);
+  bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
+  if (Args.hasArg(options::OPT_maix_small_local_exec_tls)) {
+if (!Triple.isOSAIX() || !Triple.isArch64Bit())
+  D.Diag(diag::err_opt_not_valid_on_target) << 
"-maix-small-local-exec-tls";
+
+// The -maix-small-local-exec-tls option should only be used with
+// -fdata-sections, as having data sections turned off with this option
+// is not ideal for performance. Moreover, the small-local-exec-tls region
+// is a limited resource, and should not be used for variables that may
+// be replaced.
+if (!Args.hasFlag(options::OPT_fdata_sections,
+  options::OPT_fno_data_sections,
+  UseSeparateSections || HasDefaultDataSections))
+  D.Diag(diag::err_drv_argument_only_allowed_with)
+  << "-maix-small-local-exec-tls"
+  << "-fdata-sections";
+  }
 }
 
 ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver , const 
llvm::Triple ,
diff --git a/clang/test/Driver/aix-small-local-exec-tls.c 
b/clang/test/Driver/aix-small-local-exec-tls.c
index 7a2eec6989eef89..e6719502a3babc3 100644
--- a/clang/test/Driver/aix-small-local-exec-tls.c
+++ b/clang/test/Driver/aix-small-local-exec-tls.c
@@ -12,6 +12,12 @@
 // 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
+// RUN: not %clang -target powerpc64-unknown-aix -maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
+// RUN: not %clang -target powerpc64-unknown-linux-gnu 
-maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
 
 int test(void) {
   return 0;
@@ -23,6 +29,7 @@ int test(void) {
 
 // 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-UNSUPPORTED-NO-DATASEC: invalid argument '-maix-small-local-exec-tls' 
only allowed with '-fdata-sections'
 
 // CHECK-AIX_SMALL_LOCALEXEC_TLS: test() #0 {
 // CHECK-AIX_SMALL_LOCALEXEC_TLS: attributes #0 = {
diff 

[llvm] [clang] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-25 Thread Amy Kwan via cfe-commits

https://github.com/amy-kwan updated 
https://github.com/llvm/llvm-project/pull/79252

>From 87d6776702976983d0757390811c84142d345591 Mon Sep 17 00:00:00 2001
From: Amy Kwan 
Date: Tue, 23 Jan 2024 22:19:49 -0600
Subject: [PATCH 1/2] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls
 and -fno-data-sections

This patch disallows the use of the -maix-small-local-exec-tls and
-fno-data-sections options within clang, and also disallows the use of the
aix-small-local-exec-tls attribute with the -data-sections=false option in llc.

This is because having data sections off when using the aix-small-local-exec-tls
feature is not ideal for performance. As the small-local-exec-tls region is a
limited resource, this space should not used for variables that may be replaced.

Note, that on AIX, data sections is turned on by default, so this patch makes it
so that a diagnostic is emitted when users explicitly turn off data sections
while using the aix-small-local-exec-tls feature.
---
 clang/lib/Basic/Targets/PPC.cpp   |  8 ---
 clang/lib/Driver/ToolChains/Arch/PPC.cpp  | 19 +
 clang/test/Driver/aix-small-local-exec-tls.c  |  7 +++
 llvm/lib/Target/PowerPC/PPCSubtarget.cpp  | 21 +++
 ...ix-small-local-exec-tls-opt-IRattribute.ll |  7 +++
 5 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 41935abfb65d3b..911b80c98f7ad6 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -646,14 +646,6 @@ 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);
 }
 
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index ab24d14992cd7a..5ffe73236205d3 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -122,6 +122,25 @@ void ppc::getPPCTargetFeatures(const Driver , const 
llvm::Triple ,
   ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
   if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
 Features.push_back("+secure-plt");
+
+  bool UseSeparateSections = isUseSeparateSections(Triple);
+  bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
+  if (Args.hasArg(options::OPT_maix_small_local_exec_tls)) {
+if (!Triple.isOSAIX() || !Triple.isArch64Bit())
+  D.Diag(diag::err_opt_not_valid_on_target) << 
"-maix-small-local-exec-tls";
+
+// The -maix-small-local-exec-tls option should only be used with
+// -fdata-sections, as having data sections turned off with this option
+// is not ideal for performance. Moreover, the small-local-exec-tls region
+// is a limited resource, and should not be used for variables that may
+// be replaced.
+if (!Args.hasFlag(options::OPT_fdata_sections,
+  options::OPT_fno_data_sections,
+  UseSeparateSections || HasDefaultDataSections))
+  D.Diag(diag::err_drv_argument_only_allowed_with)
+  << "-maix-small-local-exec-tls"
+  << "-fdata-sections";
+  }
 }
 
 ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver , const 
llvm::Triple ,
diff --git a/clang/test/Driver/aix-small-local-exec-tls.c 
b/clang/test/Driver/aix-small-local-exec-tls.c
index 7a2eec6989eef8..e6719502a3babc 100644
--- a/clang/test/Driver/aix-small-local-exec-tls.c
+++ b/clang/test/Driver/aix-small-local-exec-tls.c
@@ -12,6 +12,12 @@
 // 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
+// RUN: not %clang -target powerpc64-unknown-aix -maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
+// RUN: not %clang -target powerpc64-unknown-linux-gnu 
-maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
 
 int test(void) {
   return 0;
@@ -23,6 +29,7 @@ int test(void) {
 
 // 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-UNSUPPORTED-NO-DATASEC: invalid argument '-maix-small-local-exec-tls' 
only allowed with '-fdata-sections'
 
 // CHECK-AIX_SMALL_LOCALEXEC_TLS: test() #0 {
 // CHECK-AIX_SMALL_LOCALEXEC_TLS: attributes #0 = {
diff --git 

[llvm] [clang] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-25 Thread Amy Kwan via cfe-commits


@@ -4,6 +4,9 @@
 ; RUN:   < %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-SUPPORTED
 ; RUN: not llc -mtriple powerpc64le-unknown-linux-gnu -ppc-asm-full-reg-names \
 ; RUN:   < %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-SUPPORTED
+; RUN: not llc -mtriple powerpc64-ibm-aix-xcoff -ppc-asm-full-reg-names \
+; RUN:   -data-sections=false < %s 2>&1 | \
+; RUN: FileCheck %s --check-prefix=CHECK-NOT-SUPPORTED-NO-DATASEC

amy-kwan wrote:

Sure, that is a good point. Let me update that.

https://github.com/llvm/llvm-project/pull/79252
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-25 Thread Stefan Pintilie via cfe-commits


@@ -4,6 +4,9 @@
 ; RUN:   < %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-SUPPORTED
 ; RUN: not llc -mtriple powerpc64le-unknown-linux-gnu -ppc-asm-full-reg-names \
 ; RUN:   < %s 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-SUPPORTED
+; RUN: not llc -mtriple powerpc64-ibm-aix-xcoff -ppc-asm-full-reg-names \
+; RUN:   -data-sections=false < %s 2>&1 | \
+; RUN: FileCheck %s --check-prefix=CHECK-NOT-SUPPORTED-NO-DATASEC

stefanp-ibm wrote:

nit:
I realize that this is how things are done above but using CHECK-NOT-SOMETHING 
is really confusing. I had to wrap my brain around it and realize that this was 
indeed a CHECK and not a CHECK-NOT.

How about `CHECK-UNSUPPORTED-NO-DATASEC` like the first test case.

https://github.com/llvm/llvm-project/pull/79252
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [AIX][TLS] Disallow the use of -maix-small-local-exec-tls and -fno-data-sections (PR #79252)

2024-01-23 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Amy Kwan (amy-kwan)


Changes



This patch disallows the use of the -maix-small-local-exec-tls and 
-fno-data-sections options within clang, and also disallows the use of the 
aix-small-local-exec-tls attribute with the -data-sections=false option in llc.

This is because having data sections off when using the 
aix-small-local-exec-tls feature is not ideal for performance. As the 
small-local-exec-tls region is a limited resource, this space should not used 
for variables that may be replaced.

Note, that on AIX, data sections is turned on by default, so this patch makes 
it so that a diagnostic is emitted when users explicitly turn off data sections 
while using the aix-small-local-exec-tls feature.

---
Full diff: https://github.com/llvm/llvm-project/pull/79252.diff


5 Files Affected:

- (modified) clang/lib/Basic/Targets/PPC.cpp (-8) 
- (modified) clang/lib/Driver/ToolChains/Arch/PPC.cpp (+19) 
- (modified) clang/test/Driver/aix-small-local-exec-tls.c (+7) 
- (modified) llvm/lib/Target/PowerPC/PPCSubtarget.cpp (+17-4) 
- (modified) 
llvm/test/CodeGen/PowerPC/check-aix-small-local-exec-tls-opt-IRattribute.ll 
(+7) 


``diff
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 41935abfb65d3b9..911b80c98f7ad62 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -646,14 +646,6 @@ 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);
 }
 
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index ab24d14992cd7a1..5ffe73236205d3b 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -122,6 +122,25 @@ void ppc::getPPCTargetFeatures(const Driver , const 
llvm::Triple ,
   ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
   if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
 Features.push_back("+secure-plt");
+
+  bool UseSeparateSections = isUseSeparateSections(Triple);
+  bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
+  if (Args.hasArg(options::OPT_maix_small_local_exec_tls)) {
+if (!Triple.isOSAIX() || !Triple.isArch64Bit())
+  D.Diag(diag::err_opt_not_valid_on_target) << 
"-maix-small-local-exec-tls";
+
+// The -maix-small-local-exec-tls option should only be used with
+// -fdata-sections, as having data sections turned off with this option
+// is not ideal for performance. Moreover, the small-local-exec-tls region
+// is a limited resource, and should not be used for variables that may
+// be replaced.
+if (!Args.hasFlag(options::OPT_fdata_sections,
+  options::OPT_fno_data_sections,
+  UseSeparateSections || HasDefaultDataSections))
+  D.Diag(diag::err_drv_argument_only_allowed_with)
+  << "-maix-small-local-exec-tls"
+  << "-fdata-sections";
+  }
 }
 
 ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver , const 
llvm::Triple ,
diff --git a/clang/test/Driver/aix-small-local-exec-tls.c 
b/clang/test/Driver/aix-small-local-exec-tls.c
index 7a2eec6989eef89..e6719502a3babc3 100644
--- a/clang/test/Driver/aix-small-local-exec-tls.c
+++ b/clang/test/Driver/aix-small-local-exec-tls.c
@@ -12,6 +12,12 @@
 // 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
+// RUN: not %clang -target powerpc64-unknown-aix -maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
+// RUN: not %clang -target powerpc64-unknown-linux-gnu 
-maix-small-local-exec-tls \
+// RUN:-fsyntax-only -fno-data-sections %s 2>&1 | \
+// RUN:FileCheck --check-prefix=CHECK-UNSUPPORTED-NO-DATASEC %s
 
 int test(void) {
   return 0;
@@ -23,6 +29,7 @@ int test(void) {
 
 // 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-UNSUPPORTED-NO-DATASEC: invalid argument '-maix-small-local-exec-tls' 
only allowed with '-fdata-sections'
 
 // CHECK-AIX_SMALL_LOCALEXEC_TLS: test() #0 {
 // CHECK-AIX_SMALL_LOCALEXEC_TLS: attributes #0 = {
diff --git a/llvm/lib/Target/PowerPC/PPCSubtarget.cpp 
b/llvm/lib/Target/PowerPC/PPCSubtarget.cpp
index