[PATCH] D62831: [CodeGen][ObjC] Add attribute "arc_retain_agnostic" to ObjC globals that are retain-agnostic

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 3 16:18:47 PDT 2019


ahatanak created this revision.
ahatanak added reviewers: rjmccall, erik.pilkington, pete, gottesmm.
ahatanak added a project: clang.
Herald added subscribers: dexonsmith, jkorous.

This is needed to enable the optimization in this patch: https://reviews.llvm.org/D62433


Repository:
  rC Clang

https://reviews.llvm.org/D62831

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenObjC/local-static-block.m
  test/CodeGenObjC/tentative-cfconstantstring.m


Index: test/CodeGenObjC/tentative-cfconstantstring.m
===================================================================
--- test/CodeGenObjC/tentative-cfconstantstring.m
+++ test/CodeGenObjC/tentative-cfconstantstring.m
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
 // rdar://13598026
 
+// CHECK: @{{.*}} = private global %struct.__NSConstantString_tag { i32* getelementptr inbounds ([24 x i32], [24 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @{{.*}}, i32 0, i32 0), i64 0 }, section "__DATA,__cfstring", align 8 #[[ATTRNUM0:.*]]
+
 @interface NSObject @end
 
 @class NSString;
@@ -40,3 +42,5 @@
 // CHECK-NEXT:   [[TWO:%.*]] = bitcast %struct._class_t* [[ZERO]] to i8*
 // CHECK-NEXT:   call void (i8*, i8*, [[T:%.*]]*, ...) bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, [[T:%.*]]*, ...)*)(i8* [[TWO]], i8* [[ONE]], [[T:%.*]]* bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_{{.*}} to [[T:%.*]]*))
 // CHECK-NEXT:   ret void
+
+// CHECK: attributes #[[ATTRNUM0]] = { "arc_retain_agnostic" }
Index: test/CodeGenObjC/local-static-block.m
===================================================================
--- test/CodeGenObjC/local-static-block.m
+++ test/CodeGenObjC/local-static-block.m
@@ -2,6 +2,8 @@
 // RUN: FileCheck -check-prefix CHECK-LP64 --input-file=%t-64.ll %s
 // rdar: // 8390455
 
+// CHECK: @{{.*}} = internal constant { i8**, i32, i32, i8*, %struct.__block_descriptor* } { i8** @_NSConcreteGlobalBlock, i32 1342177280, i32 0, i8* bitcast (%0* (i8*, %0*, i64)* @{{.*}} to i8*), %{{.*}}* bitcast ({ i64, i64, i8*, i8* }* @{{.*}} to %{{.*}}) }, align 8 #[[ATTRNUM0:.*]]
+
 @class NSArray;
 
 static  NSArray *(^ArrayRecurs)(NSArray *addresses, unsigned long level) = ^(NSArray *addresses, unsigned long level) {
@@ -74,3 +76,5 @@
 // CHECK-LP64: @FUNC.ArrayRecurs = internal global
 // CHECK-LP64: @FUNC.ArrayRecurs.1 = internal global
 // CHECK-LP64: @FUNC1.ArrayRecurs = internal global
+
+// CHECK: attributes #[[ATTRNUM0]] = { "arc_retain_agnostic" }
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -4651,6 +4651,7 @@
   GV = Fields.finishAndCreateGlobal("_unnamed_cfstring_", Alignment,
                                     /*isConstant=*/false,
                                     llvm::GlobalVariable::PrivateLinkage);
+  cast<llvm::GlobalVariable>(GV)->addAttribute("arc_retain_agnostic");
   switch (Triple.getObjectFormat()) {
   case llvm::Triple::UnknownObjectFormat:
     llvm_unreachable("unknown file format");
Index: lib/CodeGen/CGBlocks.cpp
===================================================================
--- lib/CodeGen/CGBlocks.cpp
+++ lib/CodeGen/CGBlocks.cpp
@@ -1438,6 +1438,8 @@
       "__block_literal_global", blockInfo.BlockAlign,
       /*constant*/ !IsWindows, llvm::GlobalVariable::InternalLinkage, AddrSpace);
 
+  cast<llvm::GlobalVariable>(literal)->addAttribute("arc_retain_agnostic");
+
   // Windows does not allow globals to be initialised to point to globals in
   // different DLLs.  Any such variables must run code to initialise them.
   if (IsWindows) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62831.202820.patch
Type: text/x-patch
Size: 3302 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190603/8a10c524/attachment-0001.bin>


More information about the cfe-commits mailing list