Skip to content

Commit 7f248f1

Browse files
committed
[CGObjC] Allow clang.arc.attachedcall on -O0 on AArch64
It is supported in GlobalISel there. It is not supported on X86 GlobalISel.
1 parent 0198e8f commit 7f248f1

File tree

2 files changed

+235
-4
lines changed

2 files changed

+235
-4
lines changed

clang/lib/CodeGen/CGObjC.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ static llvm::Value *emitOptimizedARCReturnCall(llvm::Value *value,
24172417
// Add operand bundle "clang.arc.attachedcall" to the call instead of emitting
24182418
// retainRV or claimRV calls in the IR. We currently do this only when the
24192419
// optimization level isn't -O0 since global-isel, which is currently run at
2420-
// -O0, doesn't know about the operand bundle.
2420+
// -O0, doesn't know about the operand bundle on x86_64.
24212421
ObjCEntrypoints &EPs = CGF.CGM.getObjCEntrypoints();
24222422
llvm::Function *&EP = IsRetainRV
24232423
? EPs.objc_retainAutoreleasedReturnValue
@@ -2431,9 +2431,9 @@ static llvm::Value *emitOptimizedARCReturnCall(llvm::Value *value,
24312431

24322432
// FIXME: Do this on all targets and at -O0 too. This can be enabled only if
24332433
// the target backend knows how to handle the operand bundle.
2434-
if (CGF.CGM.getCodeGenOpts().OptimizationLevel > 0 &&
2435-
(Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_32 ||
2436-
Arch == llvm::Triple::x86_64)) {
2434+
if ((CGF.CGM.getCodeGenOpts().OptimizationLevel > 0 &&
2435+
Arch == llvm::Triple::x86_64) ||
2436+
(Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_32)) {
24372437
llvm::Value *bundleArgs[] = {EP};
24382438
llvm::OperandBundleDef OB("clang.arc.attachedcall", bundleArgs);
24392439
auto *oldCall = cast<llvm::CallBase>(value);

llvm/test/CodeGen/AArch64/call-rv-marker.ll

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
22
; RUN: llc -o - %s | FileCheck --check-prefix=SELDAG --check-prefix=CHECK %s
33
; RUN: llc -global-isel -o - %s | FileCheck --check-prefix=GISEL --check-prefix=CHECK %s
4+
; RUN: llc -O0 -o - %s | FileCheck --check-prefix=O0 --check-prefix=CHECK %s
45

56
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
67
target triple = "arm64-apple-ios"
@@ -49,6 +50,18 @@ define dso_local ptr @rv_marker_1_retain() {
4950
; GISEL-NEXT: bl _objc_retainAutoreleasedReturnValue
5051
; GISEL-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
5152
; GISEL-NEXT: ret
53+
;
54+
; O0-LABEL: rv_marker_1_retain:
55+
; O0: ; %bb.0: ; %entry
56+
; O0-NEXT: stp x29, x30, [sp, #-16]! ; 16-byte Folded Spill
57+
; O0-NEXT: .cfi_def_cfa_offset 16
58+
; O0-NEXT: .cfi_offset w30, -8
59+
; O0-NEXT: .cfi_offset w29, -16
60+
; O0-NEXT: bl _foo1
61+
; O0-NEXT: mov x29, x29
62+
; O0-NEXT: bl _objc_retainAutoreleasedReturnValue
63+
; O0-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
64+
; O0-NEXT: ret
5265
entry:
5366
%call = call ptr @foo1() [ "clang.arc.attachedcall"(ptr @objc_retainAutoreleasedReturnValue) ]
5467
ret ptr %call
@@ -78,6 +91,18 @@ define dso_local ptr @rv_marker_1_unsafeClaim() {
7891
; GISEL-NEXT: bl _objc_unsafeClaimAutoreleasedReturnValue
7992
; GISEL-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
8093
; GISEL-NEXT: ret
94+
;
95+
; O0-LABEL: rv_marker_1_unsafeClaim:
96+
; O0: ; %bb.0: ; %entry
97+
; O0-NEXT: stp x29, x30, [sp, #-16]! ; 16-byte Folded Spill
98+
; O0-NEXT: .cfi_def_cfa_offset 16
99+
; O0-NEXT: .cfi_offset w30, -8
100+
; O0-NEXT: .cfi_offset w29, -16
101+
; O0-NEXT: bl _foo1
102+
; O0-NEXT: mov x29, x29
103+
; O0-NEXT: bl _objc_unsafeClaimAutoreleasedReturnValue
104+
; O0-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
105+
; O0-NEXT: ret
81106
entry:
82107
%call = call ptr @foo1() [ "clang.arc.attachedcall"(ptr @objc_unsafeClaimAutoreleasedReturnValue) ]
83108
ret ptr %call
@@ -113,6 +138,21 @@ define dso_local void @rv_marker_2_select(i32 %c) {
113138
; GISEL-NEXT: bl _objc_retainAutoreleasedReturnValue
114139
; GISEL-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
115140
; GISEL-NEXT: b _foo2
141+
;
142+
; O0-LABEL: rv_marker_2_select:
143+
; O0: ; %bb.0: ; %entry
144+
; O0-NEXT: stp x29, x30, [sp, #-16]! ; 16-byte Folded Spill
145+
; O0-NEXT: .cfi_def_cfa_offset 16
146+
; O0-NEXT: .cfi_offset w30, -8
147+
; O0-NEXT: .cfi_offset w29, -16
148+
; O0-NEXT: mov w8, #2 ; =0x2
149+
; O0-NEXT: subs w9, w0, #0
150+
; O0-NEXT: csinc w0, w8, wzr, eq
151+
; O0-NEXT: bl _foo0
152+
; O0-NEXT: mov x29, x29
153+
; O0-NEXT: bl _objc_retainAutoreleasedReturnValue
154+
; O0-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
155+
; O0-NEXT: b _foo2
116156
entry:
117157
%tobool.not = icmp eq i32 %c, 0
118158
%.sink = select i1 %tobool.not, i32 2, i32 1
@@ -247,6 +287,68 @@ define dso_local void @rv_marker_3() personality ptr @__gxx_personality_v0 {
247287
; GISEL-NEXT: .byte 0 ; On action: cleanup
248288
; GISEL-NEXT: Lcst_end0:
249289
; GISEL-NEXT: .p2align 2, 0x0
290+
;
291+
; O0-LABEL: rv_marker_3:
292+
; O0: Lfunc_begin0:
293+
; O0-NEXT: .cfi_startproc
294+
; O0-NEXT: .cfi_personality 155, ___gxx_personality_v0
295+
; O0-NEXT: .cfi_lsda 16, Lexception0
296+
; O0-NEXT: ; %bb.0: ; %entry
297+
; O0-NEXT: sub sp, sp, #32
298+
; O0-NEXT: stp x29, x30, [sp, #16] ; 16-byte Folded Spill
299+
; O0-NEXT: .cfi_def_cfa_offset 32
300+
; O0-NEXT: .cfi_offset w30, -8
301+
; O0-NEXT: .cfi_offset w29, -16
302+
; O0-NEXT: bl _foo1
303+
; O0-NEXT: mov x29, x29
304+
; O0-NEXT: bl _objc_retainAutoreleasedReturnValue
305+
; O0-NEXT: str x0, [sp, #8] ; 8-byte Folded Spill
306+
; O0-NEXT: Ltmp0: ; EH_LABEL
307+
; O0-NEXT: bl _objc_object
308+
; O0-NEXT: Ltmp1: ; EH_LABEL
309+
; O0-NEXT: b LBB3_1
310+
; O0-NEXT: LBB3_1: ; %invoke.cont
311+
; O0-NEXT: ldr x0, [sp, #8] ; 8-byte Folded Reload
312+
; O0-NEXT: adrp x1, _objc_release@GOTPAGE
313+
; O0-NEXT: ldr x1, [x1, _objc_release@GOTPAGEOFF]
314+
; O0-NEXT: ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
315+
; O0-NEXT: add sp, sp, #32
316+
; O0-NEXT: br x1
317+
; O0-NEXT: LBB3_2: ; %lpad
318+
; O0-NEXT: Ltmp2: ; EH_LABEL
319+
; O0-NEXT: mov x1, x0
320+
; O0-NEXT: ldr x0, [sp, #8] ; 8-byte Folded Reload
321+
; O0-NEXT: str x1, [sp] ; 8-byte Folded Spill
322+
; O0-NEXT: adrp x8, _objc_release@GOTPAGE
323+
; O0-NEXT: ldr x8, [x8, _objc_release@GOTPAGEOFF]
324+
; O0-NEXT: blr x8
325+
; O0-NEXT: ldr x0, [sp] ; 8-byte Folded Reload
326+
; O0-NEXT: bl __Unwind_Resume
327+
; O0-NEXT: Lfunc_end0:
328+
; O0-NEXT: .cfi_endproc
329+
; O0-NEXT: .section __TEXT,__gcc_except_tab
330+
; O0-NEXT: .p2align 2, 0x0
331+
; O0-NEXT: GCC_except_table3:
332+
; O0-NEXT: Lexception0:
333+
; O0-NEXT: .byte 255 ; @LPStart Encoding = omit
334+
; O0-NEXT: .byte 255 ; @TType Encoding = omit
335+
; O0-NEXT: .byte 1 ; Call site Encoding = uleb128
336+
; O0-NEXT: .uleb128 Lcst_end0-Lcst_begin0
337+
; O0-NEXT: Lcst_begin0:
338+
; O0-NEXT: .uleb128 Lfunc_begin0-Lfunc_begin0 ; >> Call Site 1 <<
339+
; O0-NEXT: .uleb128 Ltmp0-Lfunc_begin0 ; Call between Lfunc_begin0 and Ltmp0
340+
; O0-NEXT: .byte 0 ; has no landing pad
341+
; O0-NEXT: .byte 0 ; On action: cleanup
342+
; O0-NEXT: .uleb128 Ltmp0-Lfunc_begin0 ; >> Call Site 2 <<
343+
; O0-NEXT: .uleb128 Ltmp1-Ltmp0 ; Call between Ltmp0 and Ltmp1
344+
; O0-NEXT: .uleb128 Ltmp2-Lfunc_begin0 ; jumps to Ltmp2
345+
; O0-NEXT: .byte 0 ; On action: cleanup
346+
; O0-NEXT: .uleb128 Ltmp1-Lfunc_begin0 ; >> Call Site 3 <<
347+
; O0-NEXT: .uleb128 Lfunc_end0-Ltmp1 ; Call between Ltmp1 and Lfunc_end0
348+
; O0-NEXT: .byte 0 ; has no landing pad
349+
; O0-NEXT: .byte 0 ; On action: cleanup
350+
; O0-NEXT: Lcst_end0:
351+
; O0-NEXT: .p2align 2, 0x0
250352
entry:
251353
%call = call ptr @foo1() [ "clang.arc.attachedcall"(ptr @objc_retainAutoreleasedReturnValue) ]
252354
invoke void @objc_object(ptr %call) #5
@@ -419,6 +521,88 @@ define dso_local void @rv_marker_4() personality ptr @__gxx_personality_v0 {
419521
; GISEL-NEXT: .byte 0 ; On action: cleanup
420522
; GISEL-NEXT: Lcst_end1:
421523
; GISEL-NEXT: .p2align 2, 0x0
524+
;
525+
; O0-LABEL: rv_marker_4:
526+
; O0: Lfunc_begin1:
527+
; O0-NEXT: .cfi_startproc
528+
; O0-NEXT: .cfi_personality 155, ___gxx_personality_v0
529+
; O0-NEXT: .cfi_lsda 16, Lexception1
530+
; O0-NEXT: ; %bb.0: ; %entry
531+
; O0-NEXT: sub sp, sp, #64
532+
; O0-NEXT: stp x29, x30, [sp, #48] ; 16-byte Folded Spill
533+
; O0-NEXT: .cfi_def_cfa_offset 64
534+
; O0-NEXT: .cfi_offset w30, -8
535+
; O0-NEXT: .cfi_offset w29, -16
536+
; O0-NEXT: Ltmp3: ; EH_LABEL
537+
; O0-NEXT: bl _foo1
538+
; O0-NEXT: mov x29, x29
539+
; O0-NEXT: bl _objc_retainAutoreleasedReturnValue
540+
; O0-NEXT: str x0, [sp, #32] ; 8-byte Folded Spill
541+
; O0-NEXT: Ltmp4: ; EH_LABEL
542+
; O0-NEXT: b LBB4_1
543+
; O0-NEXT: LBB4_1: ; %invoke.cont
544+
; O0-NEXT: Ltmp6: ; EH_LABEL
545+
; O0-NEXT: ldr x0, [sp, #32] ; 8-byte Folded Reload
546+
; O0-NEXT: bl _objc_object
547+
; O0-NEXT: Ltmp7: ; EH_LABEL
548+
; O0-NEXT: b LBB4_2
549+
; O0-NEXT: LBB4_2: ; %invoke.cont2
550+
; O0-NEXT: ldr x0, [sp, #32] ; 8-byte Folded Reload
551+
; O0-NEXT: adrp x8, _objc_release@GOTPAGE
552+
; O0-NEXT: ldr x8, [x8, _objc_release@GOTPAGEOFF]
553+
; O0-NEXT: blr x8
554+
; O0-NEXT: add x0, sp, #47
555+
; O0-NEXT: bl __ZN1SD1Ev
556+
; O0-NEXT: ldp x29, x30, [sp, #48] ; 16-byte Folded Reload
557+
; O0-NEXT: add sp, sp, #64
558+
; O0-NEXT: ret
559+
; O0-NEXT: LBB4_3: ; %lpad
560+
; O0-NEXT: Ltmp5: ; EH_LABEL
561+
; O0-NEXT: str x0, [sp, #24] ; 8-byte Folded Spill
562+
; O0-NEXT: b LBB4_5
563+
; O0-NEXT: LBB4_4: ; %lpad1
564+
; O0-NEXT: Ltmp8: ; EH_LABEL
565+
; O0-NEXT: mov x1, x0
566+
; O0-NEXT: ldr x0, [sp, #32] ; 8-byte Folded Reload
567+
; O0-NEXT: str x1, [sp, #16] ; 8-byte Folded Spill
568+
; O0-NEXT: adrp x8, _objc_release@GOTPAGE
569+
; O0-NEXT: ldr x8, [x8, _objc_release@GOTPAGEOFF]
570+
; O0-NEXT: blr x8
571+
; O0-NEXT: ldr x0, [sp, #16] ; 8-byte Folded Reload
572+
; O0-NEXT: str x0, [sp, #24] ; 8-byte Folded Spill
573+
; O0-NEXT: b LBB4_5
574+
; O0-NEXT: LBB4_5: ; %ehcleanup
575+
; O0-NEXT: ldr x8, [sp, #24] ; 8-byte Folded Reload
576+
; O0-NEXT: str x8, [sp, #8] ; 8-byte Folded Spill
577+
; O0-NEXT: add x0, sp, #47
578+
; O0-NEXT: bl __ZN1SD1Ev
579+
; O0-NEXT: ldr x0, [sp, #8] ; 8-byte Folded Reload
580+
; O0-NEXT: bl __Unwind_Resume
581+
; O0-NEXT: Lfunc_end1:
582+
; O0-NEXT: .cfi_endproc
583+
; O0-NEXT: .section __TEXT,__gcc_except_tab
584+
; O0-NEXT: .p2align 2, 0x0
585+
; O0-NEXT: GCC_except_table4:
586+
; O0-NEXT: Lexception1:
587+
; O0-NEXT: .byte 255 ; @LPStart Encoding = omit
588+
; O0-NEXT: .byte 255 ; @TType Encoding = omit
589+
; O0-NEXT: .byte 1 ; Call site Encoding = uleb128
590+
; O0-NEXT: .uleb128 Lcst_end1-Lcst_begin1
591+
; O0-NEXT: Lcst_begin1:
592+
; O0-NEXT: .uleb128 Ltmp3-Lfunc_begin1 ; >> Call Site 1 <<
593+
; O0-NEXT: .uleb128 Ltmp4-Ltmp3 ; Call between Ltmp3 and Ltmp4
594+
; O0-NEXT: .uleb128 Ltmp5-Lfunc_begin1 ; jumps to Ltmp5
595+
; O0-NEXT: .byte 0 ; On action: cleanup
596+
; O0-NEXT: .uleb128 Ltmp6-Lfunc_begin1 ; >> Call Site 2 <<
597+
; O0-NEXT: .uleb128 Ltmp7-Ltmp6 ; Call between Ltmp6 and Ltmp7
598+
; O0-NEXT: .uleb128 Ltmp8-Lfunc_begin1 ; jumps to Ltmp8
599+
; O0-NEXT: .byte 0 ; On action: cleanup
600+
; O0-NEXT: .uleb128 Ltmp7-Lfunc_begin1 ; >> Call Site 3 <<
601+
; O0-NEXT: .uleb128 Lfunc_end1-Ltmp7 ; Call between Ltmp7 and Lfunc_end1
602+
; O0-NEXT: .byte 0 ; has no landing pad
603+
; O0-NEXT: .byte 0 ; On action: cleanup
604+
; O0-NEXT: Lcst_end1:
605+
; O0-NEXT: .p2align 2, 0x0
422606
entry:
423607
%s = alloca %struct.S, align 1
424608
call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %s) #2
@@ -501,6 +685,25 @@ define dso_local ptr @rv_marker_5_indirect_call() {
501685
; GISEL-NEXT: ldp x20, x19, [sp], #32 ; 16-byte Folded Reload
502686
; GISEL-NEXT: ret
503687
; GISEL-NEXT: .loh AdrpLdr Lloh8, Lloh9
688+
;
689+
; O0-LABEL: rv_marker_5_indirect_call:
690+
; O0: ; %bb.0: ; %entry
691+
; O0-NEXT: sub sp, sp, #32
692+
; O0-NEXT: stp x29, x30, [sp, #16] ; 16-byte Folded Spill
693+
; O0-NEXT: .cfi_def_cfa_offset 32
694+
; O0-NEXT: .cfi_offset w30, -8
695+
; O0-NEXT: .cfi_offset w29, -16
696+
; O0-NEXT: adrp x8, _fptr@PAGE
697+
; O0-NEXT: ldr x8, [x8, _fptr@PAGEOFF]
698+
; O0-NEXT: blr x8
699+
; O0-NEXT: mov x29, x29
700+
; O0-NEXT: bl _objc_retainAutoreleasedReturnValue
701+
; O0-NEXT: str x0, [sp, #8] ; 8-byte Folded Spill
702+
; O0-NEXT: bl _foo2
703+
; O0-NEXT: ldr x0, [sp, #8] ; 8-byte Folded Reload
704+
; O0-NEXT: ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
705+
; O0-NEXT: add sp, sp, #32
706+
; O0-NEXT: ret
504707
entry:
505708
%0 = load ptr, ptr @fptr, align 8
506709
%call = call ptr %0() [ "clang.arc.attachedcall"(ptr @objc_retainAutoreleasedReturnValue) ]
@@ -540,6 +743,23 @@ define dso_local void @rv_marker_multiarg(i64 %a, i64 %b, i64 %c) {
540743
; GISEL-NEXT: bl _objc_retainAutoreleasedReturnValue
541744
; GISEL-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
542745
; GISEL-NEXT: ret
746+
;
747+
; O0-LABEL: rv_marker_multiarg:
748+
; O0: ; %bb.0:
749+
; O0-NEXT: sub sp, sp, #32
750+
; O0-NEXT: stp x29, x30, [sp, #16] ; 16-byte Folded Spill
751+
; O0-NEXT: .cfi_def_cfa_offset 32
752+
; O0-NEXT: .cfi_offset w30, -8
753+
; O0-NEXT: .cfi_offset w29, -16
754+
; O0-NEXT: str x0, [sp, #8] ; 8-byte Folded Spill
755+
; O0-NEXT: mov x0, x2
756+
; O0-NEXT: ldr x2, [sp, #8] ; 8-byte Folded Reload
757+
; O0-NEXT: bl _foo
758+
; O0-NEXT: mov x29, x29
759+
; O0-NEXT: bl _objc_retainAutoreleasedReturnValue
760+
; O0-NEXT: ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
761+
; O0-NEXT: add sp, sp, #32
762+
; O0-NEXT: ret
543763
call ptr @foo(i64 %c, i64 %b, i64 %a) [ "clang.arc.attachedcall"(ptr @objc_retainAutoreleasedReturnValue) ]
544764
ret void
545765
}
@@ -566,6 +786,17 @@ define dso_local ptr @rv_marker_claim() {
566786
; GISEL-NEXT: bl _objc_claimAutoreleasedReturnValue
567787
; GISEL-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
568788
; GISEL-NEXT: ret
789+
;
790+
; O0-LABEL: rv_marker_claim:
791+
; O0: ; %bb.0: ; %entry
792+
; O0-NEXT: stp x29, x30, [sp, #-16]! ; 16-byte Folded Spill
793+
; O0-NEXT: .cfi_def_cfa_offset 16
794+
; O0-NEXT: .cfi_offset w30, -8
795+
; O0-NEXT: .cfi_offset w29, -16
796+
; O0-NEXT: bl _foo1
797+
; O0-NEXT: bl _objc_claimAutoreleasedReturnValue
798+
; O0-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
799+
; O0-NEXT: ret
569800
entry:
570801
%call = call ptr @foo1() [ "clang.arc.attachedcall"(ptr @objc_claimAutoreleasedReturnValue) ]
571802
ret ptr %call

0 commit comments

Comments
 (0)