[PATCH] D158857: Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr for aarch64

2023-08-25 Thread Aleksandr Vorobev via Phabricator via cfe-commits
a_vorobev created this revision.
a_vorobev added reviewers: clang, akhuang, rnk.
a_vorobev added a project: clang.
Herald added subscribers: pengfei, hiraditya, kristof.beyls, arichardson.
Herald added a project: All.
a_vorobev requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, aheejin.
Herald added a project: LLVM.

This is frontend patch for the issue : 62536 
 . This patch adds 
-p270:32:32-p271:32:32-p272:64:64 to the aarch64 data layout string, which are 
used in X86 for implementing mixed pointer sizes. This patch also changes the 
datalayout string in aarch64 backend target, because the datalayout specified 
in the frontend has to match the backend target datalayout.

Additionally, the patch adds changes to clang/basic/target/aarch64 for the 
correct size of the pointer and its address in the IR. The address spaces: 
270,271 and 271 already choised in X86 platform.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158857

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/CodeGen/ms-mixed-ptr-sizes.c
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -260,15 +260,15 @@
  bool LittleEndian) {
   if (TT.isOSBinFormatMachO()) {
 if (TT.getArch() == Triple::aarch64_32)
-  return "e-m:o-p:32:32-i64:64-i128:128-n32:64-S128";
-return "e-m:o-i64:64-i128:128-n32:64-S128";
+   return "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128";
+return "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128";
   }
   if (TT.isOSBinFormatCOFF())
-return "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128";
+return "e-m:w-i32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128";
   std::string Endian = LittleEndian ? "e" : "E";
   std::string Ptr32 = TT.getEnvironment() == Triple::GNUILP32 ? "-p:32:32" : "";
   return Endian + "-m:e" + Ptr32 +
- "-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128";
+ "-i8:8:32-i16:16:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128";
 }
 
 static StringRef computeDefaultCPU(const Triple &TT, StringRef CPU) { 
Index: clang/test/CodeGen/ms-mixed-ptr-sizes.c
===
--- clang/test/CodeGen/ms-mixed-ptr-sizes.c
+++ clang/test/CodeGen/ms-mixed-ptr-sizes.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefixes=X64,ALL
 // RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefixes=X86,ALL
+// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -fms-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefixes=AARCH64,ALL
 
 struct Foo {
   int * __ptr32 p32;
@@ -9,32 +10,40 @@
 void test_sign_ext(struct Foo *f, int * __ptr32 __sptr i) {
 // X64-LABEL: define dso_local void @test_sign_ext({{.*}}ptr addrspace(270) noundef %i)
 // X86-LABEL: define dso_local void @test_sign_ext(ptr noundef %f, ptr noundef %i)
+// AARCH64-LABEL: define dso_local void @test_sign_ext({{.*}}ptr addrspace(270) noundef %i) local_unnamed_addr #0
 // X64: %{{.+}} = addrspacecast ptr addrspace(270) %i to ptr
 // X86: %{{.+}} = addrspacecast ptr %i to ptr addrspace(272)
+// AARCH64: %{{.+}} = addrspacecast ptr addrspace(270) %i to ptr
   f->p64 = i;
   use_foo(f);
 }
 void test_zero_ext(struct Foo *f, int * __ptr32 __uptr i) {
 // X64-LABEL: define dso_local void @test_zero_ext({{.*}}ptr addrspace(271) noundef %i)
 // X86-LABEL: define dso_local void @test_zero_ext({{.*}}ptr addrspace(271) noundef %i)
+// AARCH64-LABEL: define dso_local void @test_zero_ext({{.*}}ptr addrspace(271) noundef %i) local_unnamed_addr #0
 // X64: %{{.+}} = addrspacecast ptr addrspace(271) %i to ptr
 // X86: %{{.+}} = addrspacecast ptr addrspace(271) %i to ptr addrspace(272)
+// AARCH64: %{{.+}} = addrspacecast ptr addrspace(271) %i to ptr
   f->p64 = i;
   use_foo(f);
 }
 void test_trunc(struct Foo *f, int * __ptr64 i) {
 // X64-LABEL: define dso_local void @test_trunc(ptr noundef %f, ptr noundef %i)
 // X86-LABEL: define dso_local void @test_trunc({{.*}}ptr addrspace(272) noundef %i)
+// AARCH64-LABEL: define dso_local void @test_trunc(ptr noundef %f, ptr noundef %i) local_unnamed_addr #0
 // X64: %{{.+}} = addrspacecast ptr %i to ptr addrspace(270)
 // X86: %{{.+}} = addrspacecast ptr addrspace(272) %i to ptr
+// AARCH64: %{{.+}} = addrspacecast ptr %i to ptr addrspace(270)
   f->p32 = i;
   use_foo(f);
 }
 void test_noop(struct Foo *f, int * __ptr32 i) {
 // X64-LABEL: define dso_local void @test_noop({{.*}}ptr addrspace(270) noundef %i)
 // X86-LABEL: define dso

[PATCH] D158857: [clang][aarch64] Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr for aarch64

2023-08-25 Thread Aleksandr Vorobev via Phabricator via cfe-commits
a_vorobev updated this revision to Diff 553518.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158857/new/

https://reviews.llvm.org/D158857

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/CodeGen/ms-mixed-ptr-sizes.c
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -260,15 +260,15 @@
  bool LittleEndian) {
   if (TT.isOSBinFormatMachO()) {
 if (TT.getArch() == Triple::aarch64_32)
-  return "e-m:o-p:32:32-i64:64-i128:128-n32:64-S128";
-return "e-m:o-i64:64-i128:128-n32:64-S128";
+   return "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128";
+return "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128";
   }
   if (TT.isOSBinFormatCOFF())
-return "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128";
+return "e-m:w-i32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128";
   std::string Endian = LittleEndian ? "e" : "E";
   std::string Ptr32 = TT.getEnvironment() == Triple::GNUILP32 ? "-p:32:32" : "";
   return Endian + "-m:e" + Ptr32 +
- "-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128";
+ "-i8:8:32-i16:16:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128";
 }
 
 static StringRef computeDefaultCPU(const Triple &TT, StringRef CPU) {
Index: clang/test/CodeGen/ms-mixed-ptr-sizes.c
===
--- clang/test/CodeGen/ms-mixed-ptr-sizes.c
+++ clang/test/CodeGen/ms-mixed-ptr-sizes.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefixes=X64,ALL
 // RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefixes=X86,ALL
+// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -fms-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefixes=AARCH64,ALL
 
 struct Foo {
   int * __ptr32 p32;
@@ -9,32 +10,40 @@
 void test_sign_ext(struct Foo *f, int * __ptr32 __sptr i) {
 // X64-LABEL: define dso_local void @test_sign_ext({{.*}}ptr addrspace(270) noundef %i)
 // X86-LABEL: define dso_local void @test_sign_ext(ptr noundef %f, ptr noundef %i)
+// AARCH64-LABEL: define dso_local void @test_sign_ext({{.*}}ptr addrspace(270) noundef %i) local_unnamed_addr #0
 // X64: %{{.+}} = addrspacecast ptr addrspace(270) %i to ptr
 // X86: %{{.+}} = addrspacecast ptr %i to ptr addrspace(272)
+// AARCH64: %{{.+}} = addrspacecast ptr addrspace(270) %i to ptr
   f->p64 = i;
   use_foo(f);
 }
 void test_zero_ext(struct Foo *f, int * __ptr32 __uptr i) {
 // X64-LABEL: define dso_local void @test_zero_ext({{.*}}ptr addrspace(271) noundef %i)
 // X86-LABEL: define dso_local void @test_zero_ext({{.*}}ptr addrspace(271) noundef %i)
+// AARCH64-LABEL: define dso_local void @test_zero_ext({{.*}}ptr addrspace(271) noundef %i) local_unnamed_addr #0
 // X64: %{{.+}} = addrspacecast ptr addrspace(271) %i to ptr
 // X86: %{{.+}} = addrspacecast ptr addrspace(271) %i to ptr addrspace(272)
+// AARCH64: %{{.+}} = addrspacecast ptr addrspace(271) %i to ptr
   f->p64 = i;
   use_foo(f);
 }
 void test_trunc(struct Foo *f, int * __ptr64 i) {
 // X64-LABEL: define dso_local void @test_trunc(ptr noundef %f, ptr noundef %i)
 // X86-LABEL: define dso_local void @test_trunc({{.*}}ptr addrspace(272) noundef %i)
+// AARCH64-LABEL: define dso_local void @test_trunc(ptr noundef %f, ptr noundef %i) local_unnamed_addr #0
 // X64: %{{.+}} = addrspacecast ptr %i to ptr addrspace(270)
 // X86: %{{.+}} = addrspacecast ptr addrspace(272) %i to ptr
+// AARCH64: %{{.+}} = addrspacecast ptr %i to ptr addrspace(270)
   f->p32 = i;
   use_foo(f);
 }
 void test_noop(struct Foo *f, int * __ptr32 i) {
 // X64-LABEL: define dso_local void @test_noop({{.*}}ptr addrspace(270) noundef %i)
 // X86-LABEL: define dso_local void @test_noop({{.*}}ptr noundef %i)
+// AARCH64-LABEL: define dso_local void @test_noop({{.*}}ptr addrspace(270) noundef %i) local_unnamed_addr #0
 // X64-NOT: addrspacecast
 // X86-NOT: addrspacecast
+// AARCH64-NOT: addrspacecast
   f->p32 = i;
   use_foo(f);
 }
@@ -42,8 +51,10 @@
 void test_other(struct Foo *f, __attribute__((address_space(10))) int *i) {
 // X64-LABEL: define dso_local void @test_other({{.*}}ptr addrspace(10) noundef %i)
 // X86-LABEL: define dso_local void @test_other({{.*}}ptr addrspace(10) noundef %i)
+// AARCH64-LABEL: define dso_local void @test_other({{.*}}ptr addrspace(10) noundef %i) local_unnamed_addr #0
 // X64: %{{.+}} = addrspacecast ptr addrspace(10) %i to ptr addrspace(270)
 // X86: %{{.+}} = addrspacecast ptr addrspace(10) %i to ptr
+// AARCH64: %{{.+}} = addrspacecast ptr addrspace(10) %i to ptr addrspace(270)
   f->p32 = (int * __ptr32)i;