Skip to content

[Clang codegen][PPC] Produce AIX-specific "target features" only for AIX #130864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

hubert-reinterpretcast
Copy link
Collaborator

Listing AIX-specific "target features" in the IR are a source of
confusion on PPC Linux. Generate them only for AIX (at least by
default).

@hubert-reinterpretcast hubert-reinterpretcast added the clang:codegen IR generation bugs: mangling, exceptions, etc. label Mar 11, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:PowerPC clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 11, 2025

@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-backend-powerpc

@llvm/pr-subscribers-clang-codegen

Author: Hubert Tong (hubert-reinterpretcast)

Changes

Listing AIX-specific "target features" in the IR are a source of
confusion on PPC Linux. Generate them only for AIX (at least by
default).


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

3 Files Affected:

  • (modified) clang/lib/Basic/Targets/PPC.cpp (+8-6)
  • (added) clang/test/Driver/aix-shared-lib-tls-model-opt.c (+28)
  • (modified) clang/test/Driver/aix-small-local-exec-dynamic-tls.c (+8-7)
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 2d8891a739ca3..facf095d7fcf1 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -609,13 +609,15 @@ bool PPCTargetInfo::initFeatureMap(
   // Privileged instructions are off by default.
   Features["privileged"] = false;
 
-  // The code generated by the -maix-small-local-[exec|dynamic]-tls option is
-  // turned off by default.
-  Features["aix-small-local-exec-tls"] = false;
-  Features["aix-small-local-dynamic-tls"] = false;
+  if (getTriple().isOSAIX()) {
+    // The code generated by the -maix-small-local-[exec|dynamic]-tls option is
+    // turned off by default.
+    Features["aix-small-local-exec-tls"] = false;
+    Features["aix-small-local-dynamic-tls"] = false;
 
-  // Turn off TLS model opt by default.
-  Features["aix-shared-lib-tls-model-opt"] = false;
+    // Turn off TLS model opt by default.
+    Features["aix-shared-lib-tls-model-opt"] = false;
+  }
 
   Features["spe"] = llvm::StringSwitch<bool>(CPU)
                         .Case("8548", true)
diff --git a/clang/test/Driver/aix-shared-lib-tls-model-opt.c b/clang/test/Driver/aix-shared-lib-tls-model-opt.c
new file mode 100644
index 0000000000000..e610bb6d15d9d
--- /dev/null
+++ b/clang/test/Driver/aix-shared-lib-tls-model-opt.c
@@ -0,0 +1,28 @@
+// RUN: %clang -target powerpc64-unknown-aix -S -emit-llvm %s -o - | FileCheck --check-prefixes=CHECK-AIX,CHECK-AIX-OFF %s
+// RUN: %clang -target powerpc-unknown-aix -S -emit-llvm %s -o - | FileCheck --check-prefixes=CHECK-AIX,CHECK-AIX-OFF %s
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck --check-prefix=CHECK-LINUX %s
+// RUN: %clang -target powerpc64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck --check-prefix=CHECK-LINUX %s
+
+// RUN: %clang -target powerpc64-unknown-aix -maix-shared-lib-tls-model-opt -S -emit-llvm \
+// RUN:    %s -o - | FileCheck %s --check-prefixes=CHECK-AIX,CHECK-AIX-ON
+
+// FIXME: Clang driver diagnostic not implemented.
+// RUN: true || not %clang -target powerpc-unknown-aix -maix-shared-lib-tls-model-opt \
+// RUN:    -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-TARGET %s
+// RUN: true || not %clang -target powerpc64le-unknown-linux-gnu -maix-shared-lib-tls-model-opt \
+// RUN:    -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-TARGET %s
+// RUN: true || not %clang -target powerpc64-unknown-linux-gnu -maix-shared-lib-tls-model-opt \
+// RUN:    -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-UNSUPPORTED-TARGET %s
+
+int test(void) {
+  return 0;
+}
+
+// CHECK-AIX: test() #0 {
+// CHECK-AIX: attributes #0 = {
+// CHECK-AIX-OFF-SAME: -aix-shared-lib-tls-model-opt
+// CHECK-AIX-ON-SAME: +aix-shared-lib-tls-model-opt
+
+// CHECK-LINUX-NOT: {{[-+]aix-shared-lib-tls-model-opt}}
+
+// CHECK-UNSUPPORTED-TARGET: option '-maix-shared-lib-tls-model-opt' cannot be specified on this target
diff --git a/clang/test/Driver/aix-small-local-exec-dynamic-tls.c b/clang/test/Driver/aix-small-local-exec-dynamic-tls.c
index e8ee07bff35f5..1a0619b58e891 100644
--- a/clang/test/Driver/aix-small-local-exec-dynamic-tls.c
+++ b/clang/test/Driver/aix-small-local-exec-dynamic-tls.c
@@ -1,7 +1,7 @@
-// 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 -S -emit-llvm %s -o - | FileCheck --check-prefix=CHECK-AIX-DEFAULT %s
+// RUN: %clang -target powerpc-unknown-aix -S -emit-llvm %s -o - | FileCheck --check-prefix=CHECK-AIX-DEFAULT %s
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck --check-prefix=CHECK-LINUX %s
+// RUN: %clang -target powerpc64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck --check-prefix=CHECK-LINUX %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
@@ -39,9 +39,10 @@ int test(void) {
   return 0;
 }
 
-// CHECK: test() #0 {
-// CHECK: attributes #0 = {
-// CHECK-SAME: {{-aix-small-local-exec-tls,.*-aix-small-local-dynamic-tls|-aix-small-local-dynamic-tls,.*-aix-small-local-exec-tls}}
+// CHECK-AIX-DEFAULT: test() #0 {
+// CHECK-AIX-DEFAULT: attributes #0 = {
+// CHECK-AIX-DEFAULT-SAME: {{-aix-small-local-exec-tls,.*-aix-small-local-dynamic-tls|-aix-small-local-dynamic-tls,.*-aix-small-local-exec-tls}}
+// CHECK-LINUX-NOT: {{[-+]aix-small-local-exec-tls,.*[-+]aix-small-local-dynamic-tls|[-+]aix-small-local-dynamic-tls,.*[-+]aix-small-local-exec-tls}}
 
 // CHECK-UNSUPPORTED-AIX32: option '-maix-small-local-[exec|dynamic]-tls' cannot be specified on this target
 // CHECK-UNSUPPORTED-LINUX: option '-maix-small-local-[exec|dynamic]-tls' cannot be specified on this target

// RUN: %clang -target powerpc64-unknown-aix -maix-shared-lib-tls-model-opt -S -emit-llvm \
// RUN: %s -o - | FileCheck %s --check-prefixes=CHECK-AIX,CHECK-AIX-ON

// FIXME: Clang driver diagnostic not implemented.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#130865 addresses this FIXME.

Copy link
Member

@daltenty daltenty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// turned off by default.
Features["aix-small-local-exec-tls"] = false;
Features["aix-small-local-dynamic-tls"] = false;
if (getTriple().isOSAIX()) {
Copy link
Contributor

@diggerlin diggerlin Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I understand correct, we do not need to set Features["aix-small-local-exec-tls"] = false; for AIX too, since we do not use the HasAIXSmallLocalExecTLS,HasAIXShLibTLSModelOpt,HasAIXSmallLocalDynamicTLS in the frontend .
and I also has upstream patch to remove all the unused variable which defined in the PPC.h #130994

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As seen from the proposed change to the test cases, listing here or not affects whether the IR lists the feature. The scope of this patch does not involve changing the behaviour on AIX (which may be controversial).

Any further desired changes for what features are listed for the IR still require further discussion. This patch makes a reasonable change against the status quo.

@hubert-reinterpretcast hubert-reinterpretcast merged commit e0e80db into main Mar 13, 2025
17 checks passed
@hubert-reinterpretcast hubert-reinterpretcast deleted the users/hubert-reinterpretcast/powerpc-aix-specific-target-features-clang-cleanup branch March 13, 2025 22:13
frederik-h pushed a commit to frederik-h/llvm-project that referenced this pull request Mar 18, 2025
…AIX (llvm#130864)

Listing AIX-specific "target features" in the IR are a source of
confusion on PPC Linux. Generate them only for AIX (at least by
default).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:PowerPC clang:codegen IR generation bugs: mangling, exceptions, etc. clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants