[clang] 45ffe63 - [clang/objc] Optimize getters for non-atomic, copied properties
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 13 06:37:07 PDT 2021
Author: Dave MacLachlan
Date: 2021-07-13T09:22:13-04:00
New Revision: 45ffe6341d9642487785b0d0028166e6fbdbe5d7
URL: https://github.com/llvm/llvm-project/commit/45ffe6341d9642487785b0d0028166e6fbdbe5d7
DIFF: https://github.com/llvm/llvm-project/commit/45ffe6341d9642487785b0d0028166e6fbdbe5d7.diff
LOG: [clang/objc] Optimize getters for non-atomic, copied properties
Properties that were declared `@property(copy, nonatomic) id foo` make an
unnecessary call to objc_get_property(). This call can be replaced with a
direct access to the backing variable identical to how a `@property(nonatomic)
id foo` would do it.
This reduces codegen by 4 bytes (x86_64/arm64) and removes a cross linkage unit
function call per property declared as copy/nonatomic.
Differential Revision: https://reviews.llvm.org/D105311
Added:
Modified:
clang/lib/CodeGen/CGObjC.cpp
clang/test/CodeGenObjC/arc-blocks.m
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index b865780ffe93c..2f0acd440e50d 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -925,10 +925,11 @@ PropertyImplStrategy::PropertyImplStrategy(CodeGenModule &CGM,
IvarSize = TInfo.Width;
IvarAlignment = TInfo.Align;
- // If we have a copy property, we always have to use getProperty/setProperty.
- // TODO: we could actually use setProperty and an expression for non-atomics.
+ // If we have a copy property, we always have to use setProperty.
+ // If the property is atomic we need to use getProperty, but in
+ // the nonatomic case we can just use expression.
if (IsCopy) {
- Kind = GetSetProperty;
+ Kind = IsAtomic ? GetSetProperty : SetPropertyAndExpressionGet;
return;
}
diff --git a/clang/test/CodeGenObjC/arc-blocks.m b/clang/test/CodeGenObjC/arc-blocks.m
index 078408bc1d6c0..ab0ee3789cba8 100644
--- a/clang/test/CodeGenObjC/arc-blocks.m
+++ b/clang/test/CodeGenObjC/arc-blocks.m
@@ -477,7 +477,7 @@ @implementation Test12
// CHECK: call void @objc_setProperty(i8* {{%.*}}, i8* {{%.*}}, i64 {{%.*}}, i8* {{%.*}}, i1 zeroext true, i1 zeroext true)
// CHECK: define internal void ()* @"\01-[Test12 nblock]"(
-// CHECK: call i8* @objc_getProperty(i8* {{%.*}}, i8* {{%.*}}, i64 {{%.*}}, i1 zeroext false)
+// CHECK: %add.ptr = getelementptr inbounds i8, i8* %1, i64 %ivar
// CHECK: define internal void @"\01-[Test12 setNblock:]"(
// CHECK: call void @objc_setProperty(i8* {{%.*}}, i8* {{%.*}}, i64 {{%.*}}, i8* {{%.*}}, i1 zeroext false, i1 zeroext true)
More information about the cfe-commits
mailing list