[clang] [ObjC] Defer to the LLVM backend for unaligned atomic load and stores (PR #79191)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 14 07:10:50 PST 2024
https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/79191
>From 1c54c1e9767e9a53fde23e5717b834b30b228867 Mon Sep 17 00:00:00 2001
From: Rose <83477269+AtariDreams at users.noreply.github.com>
Date: Tue, 23 Jan 2024 13:59:05 -0500
Subject: [PATCH] [ObjC] Defer to the LLVM backend for unaligned atomic load
and stores
LLVM can codegen correctly for atomics of any alignment in IR, on any architecture (via using libcalls when necessary).
So, the ObjC code's hasUnalignedAtomics can be removed. We can use copyStruct if the size is too big.
---
clang/lib/CodeGen/CGObjC.cpp | 17 -----------------
clang/test/CodeGenObjC/objc_copyStruct.m | 3 +--
clang/test/CodeGenObjC/property-aggregate.m | 15 ++-------------
3 files changed, 3 insertions(+), 32 deletions(-)
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index f3a948cf13f9c9..ccda7ce8f41b9f 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -842,15 +842,6 @@ static void emitStructGetterCall(CodeGenFunction &CGF, ObjCIvarDecl *ivar,
callee, ReturnValueSlot(), args);
}
-/// Determine whether the given architecture supports unaligned atomic
-/// accesses. They don't have to be fast, just faster than a function
-/// call and a mutex.
-static bool hasUnalignedAtomics(llvm::Triple::ArchType arch) {
- // FIXME: Allow unaligned atomic load/store on x86. (It is not
- // currently supported by the backend.)
- return false;
-}
-
/// Return the maximum size that permits atomic accesses for the given
/// architecture.
static CharUnits getMaxAtomicAccessSize(CodeGenModule &CGM,
@@ -1023,14 +1014,6 @@ PropertyImplStrategy::PropertyImplStrategy(CodeGenModule &CGM,
llvm::Triple::ArchType arch =
CGM.getTarget().getTriple().getArch();
- // Most architectures require memory to fit within a single cache
- // line, so the alignment has to be at least the size of the access.
- // Otherwise we have to grab a lock.
- if (IvarAlignment < IvarSize && !hasUnalignedAtomics(arch)) {
- Kind = CopyStruct;
- return;
- }
-
// If the ivar's size exceeds the architecture's maximum atomic
// access size, we have to use CopyStruct.
if (IvarSize > getMaxAtomicAccessSize(CGM, arch)) {
diff --git a/clang/test/CodeGenObjC/objc_copyStruct.m b/clang/test/CodeGenObjC/objc_copyStruct.m
index 7bbad866e2b1fb..8e52815a308abc 100644
--- a/clang/test/CodeGenObjC/objc_copyStruct.m
+++ b/clang/test/CodeGenObjC/objc_copyStruct.m
@@ -2,7 +2,7 @@
// RUN: %clang -target x86_64-apple-ios -fobjc-runtime=ios -Wno-objc-root-class -S -o - -emit-llvm %s | FileCheck %s
struct S {
- float f, g;
+ double f, g;
};
@interface I
@@ -13,4 +13,3 @@ @implementation I
@end
// CHECK: declare {{.*}}void @objc_copyStruct(ptr, ptr, i64, i1, i1)
-
diff --git a/clang/test/CodeGenObjC/property-aggregate.m b/clang/test/CodeGenObjC/property-aggregate.m
index f4211b6b62bd50..4c8c8893f920f4 100644
--- a/clang/test/CodeGenObjC/property-aggregate.m
+++ b/clang/test/CodeGenObjC/property-aggregate.m
@@ -1,13 +1,8 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck %s
-// This structure's size is not a power of two, so the property does
-// not get native atomics, even though x86-64 can do unaligned atomics
-// with a lock prefix.
struct s3 { char c[3]; };
// This structure's size is, so it does, because it can.
-// FIXME: But we don't at the moment; the backend doesn't know how to generate
-// correct code.
struct s4 { char c[4]; };
@interface Test0
@@ -18,14 +13,8 @@ @implementation Test0
@synthesize s3, s4;
@end
-// CHECK: define internal i24 @"\01-[Test0 s3]"(
-// CHECK: call void @objc_copyStruct
-// CHECK: define internal void @"\01-[Test0 setS3:]"(
-// CHECK: call void @objc_copyStruct
-// CHECK: define internal i32 @"\01-[Test0 s4]"(
-// CHECK: call void @objc_copyStruct
-// CHECK: define internal void @"\01-[Test0 setS4:]"(
-// CHECK: call void @objc_copyStruct
+//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+// CHECK: {{.*}}
More information about the cfe-commits
mailing list