[cfe-commits] r128937 - in /cfe/trunk: lib/CodeGen/CGObjC.cpp test/CodeGenObjC/misc-atomic-property.m
Fariborz Jahanian
fjahanian at apple.com
Tue Apr 5 14:41:23 PDT 2011
Author: fjahanian
Date: Tue Apr 5 16:41:23 2011
New Revision: 128937
URL: http://llvm.org/viewvc/llvm-project?rev=128937&view=rev
Log:
Generate atomic api for atomic properties (x86 and x86_64
targets) when load/store results in multiple instructions.
// rdar://8808439
Added:
cfe/trunk/test/CodeGenObjC/misc-atomic-property.m
Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=128937&r1=128936&r2=128937&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Tue Apr 5 16:41:23 2011
@@ -262,6 +262,22 @@
CGM.getObjCRuntime().GetGetStructFunction()) {
GenerateObjCGetterBody(Ivar, true, false);
}
+ else if (IsAtomic &&
+ (IVART->isScalarType() && !IVART->isRealFloatingType()) &&
+ Triple.getArch() == llvm::Triple::x86 &&
+ (getContext().getTypeSizeInChars(IVART)
+ > CharUnits::fromQuantity(4)) &&
+ CGM.getObjCRuntime().GetGetStructFunction()) {
+ GenerateObjCGetterBody(Ivar, true, false);
+ }
+ else if (IsAtomic &&
+ (IVART->isScalarType() && !IVART->isRealFloatingType()) &&
+ Triple.getArch() == llvm::Triple::x86_64 &&
+ (getContext().getTypeSizeInChars(IVART)
+ > CharUnits::fromQuantity(8)) &&
+ CGM.getObjCRuntime().GetGetStructFunction()) {
+ GenerateObjCGetterBody(Ivar, true, false);
+ }
else if (IVART->isAnyComplexType()) {
LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(),
Ivar, 0);
@@ -283,6 +299,21 @@
PID->getGetterCXXConstructor(),
0);
EmitReturnStmt(*Stmt);
+ } else if (IsAtomic &&
+ !IVART->isAnyComplexType() &&
+ Triple.getArch() == llvm::Triple::x86 &&
+ (getContext().getTypeSizeInChars(IVART)
+ > CharUnits::fromQuantity(4)) &&
+ CGM.getObjCRuntime().GetGetStructFunction()) {
+ GenerateObjCGetterBody(Ivar, true, false);
+ }
+ else if (IsAtomic &&
+ !IVART->isAnyComplexType() &&
+ Triple.getArch() == llvm::Triple::x86_64 &&
+ (getContext().getTypeSizeInChars(IVART)
+ > CharUnits::fromQuantity(8)) &&
+ CGM.getObjCRuntime().GetGetStructFunction()) {
+ GenerateObjCGetterBody(Ivar, true, false);
}
else {
LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(),
@@ -358,7 +389,8 @@
ObjCMethodDecl *OMD = PD->getSetterMethodDecl();
assert(OMD && "Invalid call to generate setter (empty method)");
StartObjCMethod(OMD, IMP->getClassInterface());
-
+ const llvm::Triple &Triple = getContext().Target.getTriple();
+ QualType IVART = Ivar->getType();
bool IsCopy = PD->getSetterKind() == ObjCPropertyDecl::Copy;
bool IsAtomic =
!(PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic);
@@ -414,18 +446,21 @@
FunctionType::ExtInfo()),
SetPropertyFn,
ReturnValueSlot(), Args);
- } else if (IsAtomic && hasAggregateLLVMType(Ivar->getType()) &&
- !Ivar->getType()->isAnyComplexType() &&
- IndirectObjCSetterArg(*CurFnInfo)
+ } else if (IsAtomic && hasAggregateLLVMType(IVART) &&
+ !IVART->isAnyComplexType() &&
+ ((Triple.getArch() == llvm::Triple::x86 &&
+ (getContext().getTypeSizeInChars(IVART)
+ > CharUnits::fromQuantity(4))) ||
+ (Triple.getArch() == llvm::Triple::x86_64 &&
+ (getContext().getTypeSizeInChars(IVART)
+ > CharUnits::fromQuantity(8))))
&& CGM.getObjCRuntime().GetSetStructFunction()) {
- // objc_copyStruct (&structIvar, &Arg,
- // sizeof (struct something), true, false);
+ // objc_copyStruct (&structIvar, &Arg,
+ // sizeof (struct something), true, false);
GenerateObjCAtomicSetterBody(OMD, Ivar);
} else if (PID->getSetterCXXAssignment()) {
EmitIgnoredExpr(PID->getSetterCXXAssignment());
} else {
- const llvm::Triple &Triple = getContext().Target.getTriple();
- QualType IVART = Ivar->getType();
if (IsAtomic &&
IVART->isScalarType() &&
(Triple.getArch() == llvm::Triple::arm ||
@@ -435,6 +470,22 @@
CGM.getObjCRuntime().GetGetStructFunction()) {
GenerateObjCAtomicSetterBody(OMD, Ivar);
}
+ else if (IsAtomic &&
+ (IVART->isScalarType() && !IVART->isRealFloatingType()) &&
+ Triple.getArch() == llvm::Triple::x86 &&
+ (getContext().getTypeSizeInChars(IVART)
+ > CharUnits::fromQuantity(4)) &&
+ CGM.getObjCRuntime().GetGetStructFunction()) {
+ GenerateObjCAtomicSetterBody(OMD, Ivar);
+ }
+ else if (IsAtomic &&
+ (IVART->isScalarType() && !IVART->isRealFloatingType()) &&
+ Triple.getArch() == llvm::Triple::x86_64 &&
+ (getContext().getTypeSizeInChars(IVART)
+ > CharUnits::fromQuantity(8)) &&
+ CGM.getObjCRuntime().GetGetStructFunction()) {
+ GenerateObjCAtomicSetterBody(OMD, Ivar);
+ }
else {
// FIXME: Find a clean way to avoid AST node creation.
SourceLocation Loc = PD->getLocation();
Added: cfe/trunk/test/CodeGenObjC/misc-atomic-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/misc-atomic-property.m?rev=128937&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/misc-atomic-property.m (added)
+++ cfe/trunk/test/CodeGenObjC/misc-atomic-property.m Tue Apr 5 16:41:23 2011
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// rdar: //8808439
+
+typedef struct {
+#ifdef __LP64__
+ unsigned char b[15];
+#else
+ unsigned char b[7];
+#endif
+} bools_minus_one;
+
+typedef struct {
+#ifdef __LP64__
+ unsigned char b[16];
+#else
+ unsigned char b[8];
+#endif
+} bools;
+
+
+ at interface Foo
+{
+#ifndef __LP64__
+ bools x;
+ bools_minus_one y;
+#endif
+}
+ at property(assign) bools bools_p;
+ at property(assign) bools_minus_one bools_minus_one_p;
+ at end
+
+ at implementation Foo
+ at synthesize bools_p=x;
+ at synthesize bools_minus_one_p=y;
+ at end
+
+#ifdef __LP64__
+typedef __int128_t dword;
+#else
+typedef long long int dword;
+#endif
+
+ at interface Test_dwords
+{
+#ifndef __LP64__
+ dword dw;
+#endif
+}
+ at property(assign) dword dword_p;
+ at end
+
+ at implementation Test_dwords
+ at synthesize dword_p=dw;
+ at end
+
+
+ at interface Test_floats
+{
+ float fl;
+ double d;
+ long double ld;
+}
+ at property(assign) float fl_p;
+ at property(assign) double d_p;
+ at property(assign) long double ld_p;
+ at end
+
+ at implementation Test_floats
+ at synthesize fl_p = fl;
+ at synthesize d_p = d;
+ at synthesize ld_p = ld;
+ at end
+
+// CHECK: call void @objc_copyStruct
+// CHECK: call void @objc_copyStruct
+// CHECK: call void @objc_copyStruct
+// CHECK: call void @objc_copyStruct
+// CHECK: call void @objc_copyStruct
+// CHECK: call void @objc_copyStruct
More information about the cfe-commits
mailing list