Skip to content

Restrict CopyForwarding (and destroy hoisting) to OSSA SIL. #34841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/SILOptimizer/Transforms/CopyForwarding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,23 @@ class CopyForwardingPass : public SILFunctionTransform
if (!EnableCopyForwarding && !EnableDestroyHoisting)
return;

// This pass assumes that the ownership lifetime of a value in a memory
// locations can be determined by analyzing operations on the memory
// address. However, in non-OSSA code, this is not guaranteed. For example,
// this is valid non-OSSA SIL:
//
// bb0(%0 : $AnyObject):
// %alloc1 = alloc_stack $AnyObject
// store %0 to %objaddr : $*AnyObject
// %ref = load %objaddr : $*AnyObject
// %alloc2 = alloc_stack $ObjWrapper
// # The in-memory reference is destroyed before retaining the loaded ref.
// copy_addr [take] %alloc1 to [initialization] %alloc2 : $*ObjWrapper
// retain_value %ref : $AnyObject
// destroy_addr %alloc2 : $*ObjWrapper
if (!getFunction()->hasOwnership())
return;

LLVM_DEBUG(llvm::dbgs() << "Copy Forwarding in Func "
<< getFunction()->getName() << "\n");

Expand Down
Loading