1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00
llvm-mirror/lib/CodeGen/SelectionDAG
Akira Hatanaka 4055195f29 [ObjC][ARC] Use operand bundle 'clang.arc.attachedcall' instead of
explicitly emitting retainRV or claimRV calls in the IR

This reapplies ed4718eccb12bd42214ca4fb17d196d49561c0c7, which was reverted
because it was causing a miscompile. The bug that was causing the miscompile
has been fixed in 75805dce5ff874676f3559c069fcd6737838f5c0.

Original commit message:

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. The backend changes are in
https://reviews.llvm.org/D92569.

https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue

What this patch does to fix the problem:

- The front-end adds operand bundle "clang.arc.attachedcall" to calls,
  which indicates the call is implicitly followed by a marker
  instruction and an implicit retainRV/claimRV call that consumes the
  call result. In addition, it emits a call to
  @llvm.objc.clang.arc.noop.use, which consumes the call result, to
  prevent the middle-end passes from changing the return type of the
  called function. This is currently done only when the target is arm64
  and the optimization level is higher than -O0.

- ARC optimizer temporarily emits retainRV/claimRV calls after the calls
  with the operand bundle in the IR and removes the inserted calls after
  processing the function.

- ARC contract pass emits retainRV/claimRV calls after the call with the
  operand bundle. It doesn't remove the operand bundle on the call since
  the backend needs it to emit the marker instruction. The retainRV and
  claimRV calls are emitted 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 function inliner removes an autoreleaseRV call in the callee if
  nothing in the callee prevents it from being paired up with the
  retainRV/claimRV call in the caller. It then inserts a release call if
  claimRV is attached to the call since autoreleaseRV+claimRV is
  equivalent to a release. If it cannot find an autoreleaseRV call, it
  tries to transfer the operand bundle to a function call in the callee.
  This is important since the ARC optimizer can remove the autoreleaseRV
  returning the callee result, which makes it impossible to pair it up
  with the retainRV/claimRV call in the caller. If that fails, it simply
  emits a retain call in the IR if retainRV is attached to the call and
  does nothing if claimRV is attached to it.

- SCCP refrains from replacing the return value of a call with a
  constant value if the call has the operand bundle. This ensures the
  call always has at least one user (the call to
  @llvm.objc.clang.arc.noop.use).

- This patch also fixes a bug in replaceUsesOfNonProtoConstant where
  multiple operand bundles of the same kind were being added to a call.

Future work:

- Use the operand bundle on x86-64.

- Fix the auto upgrader to convert call+retainRV/claimRV pairs into
  calls with the operand bundles.

rdar://71443534

Differential Revision: https://reviews.llvm.org/D92808
2021-03-04 11:22:30 -08:00
..
CMakeLists.txt llvmbuildectomy - replace llvm-build by plain cmake 2020-11-13 10:35:24 +01:00
DAGCombiner.cpp [SDAG] allow partial undef vector constants with select->logic folds 2021-03-02 14:29:15 -05:00
FastISel.cpp Introduce llvm.noalias.decl intrinsic 2021-01-16 09:20:45 +01:00
FunctionLoweringInfo.cpp [WebAssembly] Fix reverse mapping in WasmEHFuncInfo 2021-02-26 17:12:10 -08:00
InstrEmitter.cpp [CSSPGO] Pseudo probes for function calls. 2020-12-02 13:45:20 -08:00
InstrEmitter.h [CodeGen] Forward-declare TargetMachine (NFC) 2021-01-24 12:18:54 -08:00
LegalizeDAG.cpp [RISCV][LegalizeTypes] Try to expand BITREVERSE before promoting if the promoted BITREVERSE would expand anyway. 2021-02-15 12:33:16 -08:00
LegalizeFloatTypes.cpp [Legalizer] Promote result type in expanding FP_TO_XINT 2021-01-18 11:56:11 +08:00
LegalizeIntegerTypes.cpp [LegalizeTypes] Improve ExpandIntRes_XMULO codegen. 2021-03-01 09:54:32 -08:00
LegalizeTypes.cpp [SelectionDAG] Use range-based for loops (NFC) 2021-02-09 22:14:30 -08:00
LegalizeTypes.h [CodeGen][SelectionDAG]Add new intrinsic experimental.vector.reverse 2021-02-15 13:39:43 +00:00
LegalizeTypesGeneric.cpp
LegalizeVectorOps.cpp Add intrinsics for saturating float to int casts 2020-12-18 11:09:41 +01:00
LegalizeVectorTypes.cpp [LegalizeVectorTypes] Remove a tautological compare. 2021-03-03 23:26:00 -08:00
ResourcePriorityQueue.cpp
ScheduleDAGFast.cpp [DebugInstrRef] Create DBG_INSTR_REFs in SelectionDAG 2020-10-14 14:24:08 +01:00
ScheduleDAGRRList.cpp Revert "[NFC][ScheduleDAG] Remove unused EntrySU SUnit" 2020-09-21 13:33:05 +02:00
ScheduleDAGSDNodes.cpp [SelectionDAG] Use range-based for loops (NFC) 2021-02-09 22:14:30 -08:00
ScheduleDAGSDNodes.h
ScheduleDAGVLIW.cpp [SelectionDAG] Use range-based for loops (NFC) 2021-02-09 22:14:30 -08:00
SDNodeDbgValue.h
SelectionDAG.cpp [SDAG] allow partial undef vector constants with select->logic folds 2021-03-02 14:29:15 -05:00
SelectionDAGAddressAnalysis.cpp [SelectionDAG] Avoid aliasing analysis if the object size is unknown. 2020-11-25 06:13:37 +08:00
SelectionDAGBuilder.cpp [ObjC][ARC] Use operand bundle 'clang.arc.attachedcall' instead of 2021-03-04 11:22:30 -08:00
SelectionDAGBuilder.h [CodeGen][SelectionDAG]Add new intrinsic experimental.vector.reverse 2021-02-15 13:39:43 +00:00
SelectionDAGDumper.cpp [CodeGen] Use range-based for loops (NFC) 2021-02-20 21:46:02 -08:00
SelectionDAGISel.cpp [TableGen][SelectionDAG] Improve efficiency of encoding negative immediates for isel's CheckInteger opcode. 2021-02-18 08:53:17 -08:00
SelectionDAGPrinter.cpp [SelectionDAG] Drop unnecessary const from a return type (NFC) 2021-02-07 09:49:33 -08:00
SelectionDAGTargetInfo.cpp
StatepointLowering.cpp [Statepoint Lowering] Consider dead deopt gc values together with other gc values 2021-03-01 17:23:02 +07:00
StatepointLowering.h
TargetLowering.cpp [DAG] TargetLowering::BuildUDIV - use APInt as const ref. NFCI. 2021-03-04 12:15:08 +00:00