Skip to content
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

[Flang] Add __powerpc__ macro to set c_intmax_t to c_int64_t rather than c_int128_t as PowerPC only supports up to c_int64_t. #81222

Merged
merged 2 commits into from
Feb 13, 2024

Conversation

DanielCChen
Copy link
Contributor

PowerPC only supports up to c_int64_t. Add macro __powerpc__ and preprocess it for setting c_intmax_t in iso_c_binding intrinsic module.

@DanielCChen DanielCChen self-assigned this Feb 9, 2024
@llvmbot llvmbot added flang:driver flang Flang issues not falling into any other category labels Feb 9, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 9, 2024

@llvm/pr-subscribers-flang-driver

Author: Daniel Chen (DanielCChen)

Changes

PowerPC only supports up to c_int64_t. Add macro __powerpc__ and preprocess it for setting c_intmax_t in iso_c_binding intrinsic module.


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

2 Files Affected:

  • (modified) flang/lib/Frontend/CompilerInvocation.cpp (+12-1)
  • (modified) flang/module/iso_c_binding.f90 (+4)
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index ffde7f50087e52..d49e8e283e0d40 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1326,10 +1326,21 @@ void CompilerInvocation::setDefaultPredefinitions() {
     Fortran::common::setOpenMPMacro(getLangOpts().OpenMPVersion,
                                     fortranOptions.predefinitions);
   }
+
   llvm::Triple targetTriple{llvm::Triple(this->targetOpts.triple)};
-  if (targetTriple.getArch() == llvm::Triple::ArchType::x86_64) {
+  switch (targetTriple.getArch()) {
+  default:
+    break;
+  case llvm::Triple::ArchType::x86_64:
     fortranOptions.predefinitions.emplace_back("__x86_64__", "1");
     fortranOptions.predefinitions.emplace_back("__x86_64", "1");
+    break;
+  case llvm::Triple::ArchType::ppc:
+  case llvm::Triple::ArchType::ppcle:
+  case llvm::Triple::ArchType::ppc64:
+  case llvm::Triple::ArchType::ppc64le:
+    fortranOptions.predefinitions.emplace_back("__powerpc__", "1");
+    break;
   }
 }
 
diff --git a/flang/module/iso_c_binding.f90 b/flang/module/iso_c_binding.f90
index 9a7e68f3314463..1661fd5a6dcf6a 100644
--- a/flang/module/iso_c_binding.f90
+++ b/flang/module/iso_c_binding.f90
@@ -47,7 +47,11 @@ module iso_c_binding
     c_long_long = c_int64_t, &
     c_signed_char = c_int8_t, &
     c_size_t = kind(c_sizeof(1)), &
+#if __powerpc__
+    c_intmax_t = c_int64_t, &
+#else
     c_intmax_t = c_int128_t, &
+#endif
     c_intptr_t = c_size_t, &
     c_ptrdiff_t = c_size_t
   integer, parameter, public :: &

@DanielCChen DanielCChen force-pushed the daniel_intmax branch 3 times, most recently from 8ce11c2 to f24f928 Compare February 9, 2024 16:41
@DanielCChen
Copy link
Contributor Author

The x86 build failure seems on and off to me. This PR passed the x86 build before I rebased the branch.

@DanielCChen DanielCChen force-pushed the daniel_intmax branch 2 times, most recently from a60fef0 to 5a529e5 Compare February 12, 2024 16:27
@kkwli
Copy link
Collaborator

kkwli commented Feb 12, 2024

Need to add a test like test/Driver/predefined-macros-x86.f90.

Copy link
Collaborator

@kkwli kkwli left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks

…han c_int128_t as PowerPC only supports up to c_int64_t.
… to indicate that this macro is generic for PowerPC.
@DanielCChen DanielCChen merged commit 987258f into llvm:main Feb 13, 2024
3 of 4 checks passed
@DanielCChen DanielCChen deleted the daniel_intmax branch February 13, 2024 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:driver flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants