[PATCH] D104931: [AArch64] Wire up ILP32 ABI support in Clang

Amanieu d'Antras via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 25 10:50:12 PDT 2021


Amanieu created this revision.
Amanieu added reviewers: t.p.northover, aemerson, kristof.beyls.
Herald added a subscriber: danielkiss.
Amanieu requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a follow-up to D94143 <https://reviews.llvm.org/D94143> which added the necessary support in LLVM.

ILP32 mode is enabled by specifying an ILP32 target (aarch64[_be]-*-gnu_ilp32) with -target.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104931

Files:
  clang/lib/Basic/Targets/AArch64.cpp


Index: clang/lib/Basic/Targets/AArch64.cpp
===================================================================
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -43,7 +43,8 @@
 AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple,
                                      const TargetOptions &Opts)
     : TargetInfo(Triple), ABI("aapcs") {
-  if (getTriple().isOSOpenBSD()) {
+  if (getTriple().isOSOpenBSD() ||
+      getTriple().getEnvironment() == llvm::Triple::GNUILP32) {
     Int64Type = SignedLongLong;
     IntMaxType = SignedLongLong;
   } else {
@@ -58,7 +59,8 @@
   HasLegalHalfType = true;
   HasFloat16 = true;
 
-  if (Triple.isArch64Bit())
+  if (Triple.isArch64Bit() &&
+      getTriple().getEnvironment() != llvm::Triple::GNUILP32)
     LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
   else
     LongWidth = LongAlign = PointerWidth = PointerAlign = 32;
@@ -213,10 +215,15 @@
     Builder.defineMacro("__ELF__");
 
   // Target properties.
-  if (!getTriple().isOSWindows() && getTriple().isArch64Bit()) {
+  if (!getTriple().isOSWindows() && getTriple().isArch64Bit() &&
+      getTriple().getEnvironment() != llvm::Triple::GNUILP32) {
     Builder.defineMacro("_LP64");
     Builder.defineMacro("__LP64__");
   }
+  if (getTriple().getEnvironment() == llvm::Triple::GNUILP32) {
+    Builder.defineMacro("_ILP32");
+    Builder.defineMacro("__ILP32__");
+  }
 
   std::string CodeModel = getTargetOpts().CodeModel;
   if (CodeModel == "default")
@@ -780,8 +787,13 @@
       resetDataLayout("e-m:o-p:32:32-i64:64-i128:128-n32:64-S128", "_");
     else
       resetDataLayout("e-m:o-i64:64-i128:128-n32:64-S128", "_");
-  } else
-    resetDataLayout("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+  } else {
+    if (getTriple().getEnvironment() == llvm::Triple::GNUILP32)
+      resetDataLayout(
+          "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+    else
+      resetDataLayout("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+  }
 }
 
 void AArch64leTargetInfo::getTargetDefines(const LangOptions &Opts,
@@ -804,7 +816,11 @@
 
 void AArch64beTargetInfo::setDataLayout() {
   assert(!getTriple().isOSBinFormatMachO());
-  resetDataLayout("E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+  if (getTriple().getEnvironment() == llvm::Triple::GNUILP32)
+    resetDataLayout(
+        "E-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+  else
+    resetDataLayout("E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
 }
 
 WindowsARM64TargetInfo::WindowsARM64TargetInfo(const llvm::Triple &Triple,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104931.354550.patch
Type: text/x-patch
Size: 2633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210625/a60bbe57/attachment.bin>


More information about the cfe-commits mailing list