mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Implement @owned to @unowned retain value conversion.
If a value is returned as @owned, we can move the epilogue retain to the caller and convert the return value to @unowned. This gives ARC optimizer more freedom to optimize the retain out on the caller's side. It appears that epilgue retains are harder to find than epilogue releases. Most of the time they are not in the return block. (1) Sometimes, they are in predecessors (2) Sometimes they come from a call which returns an @owned return value. This should be improved if we fix (1) and go bottom up. (3) We do not handle exploded retain_value. Currently, this catches a small number of opportunities. We probably need to improve epilogue retain matcher if we are to handle more cases. This is part of rdar://24022375. We also need some refactoring in the pass. e.g. break functions into smaller functions. I will do with subsequent commit.
This commit is contained in:
@@ -139,6 +139,18 @@ class FunctionSignatureSpecializationMangler
|
||||
|
||||
friend class SpecializationMangler<FunctionSignatureSpecializationMangler>;
|
||||
|
||||
using ReturnValueModifierIntBase = uint16_t;
|
||||
enum class ReturnValueModifier : ReturnValueModifierIntBase {
|
||||
// Option Space 4 bits (i.e. 16 options).
|
||||
Unmodified=0,
|
||||
First_Option=0, Last_Option=31,
|
||||
|
||||
// Option Set Space. 12 bits (i.e. 12 option).
|
||||
Dead=32,
|
||||
OwnedToUnowned=64,
|
||||
First_OptionSetEntry=32, LastOptionSetEntry=32768,
|
||||
};
|
||||
|
||||
// We use this private typealias to make it easy to expand ArgumentModifier's
|
||||
// size if we need to.
|
||||
using ArgumentModifierIntBase = uint16_t;
|
||||
@@ -162,6 +174,8 @@ class FunctionSignatureSpecializationMangler
|
||||
NullablePtr<SILInstruction>>;
|
||||
llvm::SmallVector<ArgInfo, 8> Args;
|
||||
|
||||
ReturnValueModifierIntBase ReturnValue;
|
||||
|
||||
public:
|
||||
FunctionSignatureSpecializationMangler(SpecializationPass Pass,
|
||||
Mangle::Mangler &M, SILFunction *F);
|
||||
@@ -173,6 +187,7 @@ public:
|
||||
void setArgumentSROA(unsigned ArgNo);
|
||||
void setArgumentBoxToValue(unsigned ArgNo);
|
||||
void setArgumentBoxToStack(unsigned ArgNo);
|
||||
void setReturnValueOwnedToUnowned();
|
||||
|
||||
private:
|
||||
void mangleSpecialization();
|
||||
@@ -181,6 +196,7 @@ private:
|
||||
void mangleClosureProp(ThinToThickFunctionInst *TTTFI);
|
||||
void mangleArgument(ArgumentModifierIntBase ArgMod,
|
||||
NullablePtr<SILInstruction> Inst);
|
||||
void mangleReturnValue(ReturnValueModifierIntBase RetMod);
|
||||
};
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
Reference in New Issue
Block a user