[PATCH] D92808: [ObjC][ARC] Annotate calls with attributes instead of emitting retainRV or claimRV calls in the IR
Akira Hatanaka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 7 19:15:16 PST 2020
ahatanak created this revision.
ahatanak added reviewers: rjmccall, smeenai, dexonsmith, pete, fhahn.
ahatanak added projects: clang, LLVM.
Herald added subscribers: ributzka, pengfei, jkorous, hiraditya, kristof.beyls.
ahatanak requested review of this revision.
Background:
===========
This fixes a longstanding problem where llvm breaks ARC's autorelease optimization (see the link below) by separating calls from the marker instructions or retainRV/claimRV calls.
https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue
What this patch does to fix the problem:
========================================
- The front-end annotates calls with attribute retainRV/claimRV, which indicates the call result is implicitly consumed by a retainRV/claimRV call, and attribute rv_marker, which indicates a marker instruction should immediately follow the call. This is currently done only when the target is arm64, the optimization level is higher than -O0, and the OS isn't windows.
- ARC optimizer temporarily emits retainRV/claimRV calls in the IR if it finds a call annotated with the attributes and removes the inserted calls after processing the function.
- ARC contract pass emits the retainRV/claimRV calls in the IR and removes the retainRV/claimRV attribute from the call, but leaves the rv_marker attribute on the call. This is done late in the pipeline to prevent optimization passes from transforming the IR in a way that makes it harder for the ARC middle-end passes to figure out the def-use relationship between the call and the retainRV/claimRV calls (which is the cause of PR31925).
- The backend emits a pseudo instruction when it sees a call annotated with rv_marker and expands it later in the pipeline to a bundled instruction (see https://reviews.llvm.org/D92569).
Future work:
============
- Use the attribute on x86-64.
- Use the attribute on windows too.
- Fix the auto upgrader to convert call+retainRV/claimRV pairs into calls annotated with the attributes.
rdar://problem/32902328
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D92808
Files:
clang/lib/CodeGen/CGObjC.cpp
clang/test/CodeGenObjC/arc-rv-attr.m
clang/test/CodeGenObjC/arc-unsafeclaim.m
llvm/include/llvm/Analysis/ObjCARCRVAttr.h
llvm/include/llvm/IR/InstrTypes.h
llvm/lib/IR/Instruction.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
llvm/lib/Transforms/ObjCARC/ObjCARC.h
llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
llvm/lib/Transforms/ObjCARC/PtrState.cpp
llvm/lib/Transforms/ObjCARC/PtrState.h
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Transforms/DeadArgElim/deadretval.ll
llvm/test/Transforms/Inline/inline-retainRV-call.ll
llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
llvm/test/Transforms/ObjCARC/rv.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92808.310075.patch
Type: text/x-patch
Size: 49603 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201208/adcd5acb/attachment-0001.bin>
More information about the cfe-commits
mailing list