Skip to content

[5.6] Upstream defer handling for the move function #40783

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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
278d72e
[mv-func-addr-check] Refactor unsupported move diagnostics into helpe…
gottesmm Dec 14, 2021
121c59a
[gardening] Refactor code to use getDebugVarName().
gottesmm Dec 15, 2021
1a57035
[move-function] Convert MoveKillsCopyableAddressesObjectChecker.visit…
gottesmm Dec 16, 2021
a4737d8
[move-function] Move addressesToCheck out of MoveKillsCopyableAddress…
gottesmm Dec 16, 2021
638e8e3
[gardening] Move a utility function into the utility section of the f…
gottesmm Dec 16, 2021
d4692b3
[move-function] Refactor out the main dataflow computation into a hel…
gottesmm Dec 16, 2021
ae71ab2
[move-function] Move the single basic block dataflow also onto that h…
gottesmm Dec 16, 2021
23e7025
[gardening] Make count on BlotSetVector const.
gottesmm Jan 6, 2022
2756d35
[move-function] Add a test to the copyable values test suite that I a…
gottesmm Dec 29, 2021
2f6cd90
[move-function] Shrink the size of UseState since to handle closures …
gottesmm Dec 17, 2021
86cdaa8
[move-function] SILCloner/mangling changes to support converting inou…
gottesmm Dec 30, 2021
e518a86
[move-function] Implement SILFunction::isDefer().
gottesmm Dec 30, 2021
5cd7132
[move-function] Implement Closure Argument Dataflow.
gottesmm Jan 5, 2022
36b8e39
[addr-move-function] Wire up the closure argument analysis to the mai…
gottesmm Jan 5, 2022
79afbd9
[addr-move-function] Implement the Closure Cloner.
gottesmm Jan 6, 2022
1cf66b3
[move-function] Wire up the closure cloner to the main move checker s…
gottesmm Jan 6, 2022
a1cc26f
[move-function] Add casting tests for all 4 cases of (loadable, addre…
gottesmm Jan 9, 2022
ada26f6
Fix thinko
gottesmm Jan 9, 2022
0ee4eb7
[addr-move-function] Rename ConsumingClosure* -> Closure.
gottesmm Jan 9, 2022
18c6484
Fix thinko
gottesmm Jan 9, 2022
c2a9995
[move-function] Eliminate unnecessary state from ClosureOperandState.
gottesmm Jan 9, 2022
9a796d8
[addr-move-function] Move caller use gatherer next to the caller data…
gottesmm Jan 9, 2022
2eb9343
[addr-move-function] Make sure that we handle closure arguments in mu…
gottesmm Jan 9, 2022
2dc81ed
Add more tests around geps/partial apply capture of vars
gottesmm Jan 9, 2022
c920101
[addr-move-function] Fix a bug where I was inferring a value from cer…
gottesmm Jan 9, 2022
7935ced
[addr-move-function] Added tests for lets for partial_apply to make s…
gottesmm Jan 9, 2022
1d4302e
[addr-move-function] Add some simple defer tests for lets. We always …
gottesmm Jan 9, 2022
f584b3a
[move-function] Add some tests that show we can handle a defer captur…
gottesmm Jan 10, 2022
bc6abd2
[move-function] Make sure that we error if the user re-initializes a …
gottesmm Jan 10, 2022
4302167
[5.6] IsNotDistributed isn't on 5.6 and isn't an arg to SILFunction's…
gottesmm Jan 11, 2022
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
2 changes: 1 addition & 1 deletion include/swift/Basic/BlotSetVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class BlotSetVector {
return {index, true};
}

bool count(const ValueT &value) { return map.count(value); }
bool count(const ValueT &value) const { return map.count(value); }

/// Replace \p value1 with \p value2 placing \p value2 into the position in
/// the array where value1 used to be. If \p value2 is already in the set,
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Demangling/Demangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ enum class FunctionSigSpecializationParamKind : unsigned {
ClosureProp = 5,
BoxToValue = 6,
BoxToStack = 7,
InOutToOut = 8,

// Option Set Flags use bits 6-31. This gives us 26 bits to use for option
// flags.
Expand Down Expand Up @@ -144,6 +145,7 @@ enum class SpecializationPass : uint8_t {
CapturePropagation,
FunctionSignatureOpts,
GenericSpecializer,
MoveDiagnosticInOutToOut,
};

static inline char encodeSpecializationPass(SpecializationPass Pass) {
Expand Down
31 changes: 31 additions & 0 deletions include/swift/SIL/SILCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
ArrayRef<SILValue> entryArgs,
bool replaceOriginalFunctionInPlace = false);

/// The same as clone function body, except the caller can provide a callback
/// that allows for an entry arg to be assigned to a custom old argument. This
/// is useful if one re-arranges parameters when converting from inout to out.
void
cloneFunctionBody(SILFunction *F, SILBasicBlock *clonedEntryBB,
ArrayRef<SILValue> entryArgs,
llvm::function_ref<SILValue(SILValue)> entryArgToOldArgMap);

/// MARK: Callback utilities used from CRTP extensions during cloning.
/// These should only be called from within an instruction cloning visitor.

Expand Down Expand Up @@ -613,6 +621,29 @@ void SILCloner<ImplClass>::cloneFunctionBody(SILFunction *F,
commonFixUp(F);
}

template <typename ImplClass>
void SILCloner<ImplClass>::cloneFunctionBody(
SILFunction *F, SILBasicBlock *clonedEntryBB, ArrayRef<SILValue> entryArgs,
llvm::function_ref<SILValue(SILValue)> entryArgIndexToOldArgIndex) {
assert(F != clonedEntryBB->getParent() && "Must clone into a new function.");
assert(BBMap.empty() && "This API does not allow clients to map blocks.");
assert(ValueMap.empty() && "Stale ValueMap.");

assert(entryArgs.size() == F->getArguments().size());
for (unsigned i = 0, e = entryArgs.size(); i != e; ++i) {
ValueMap[entryArgIndexToOldArgIndex(entryArgs[i])] = entryArgs[i];
}

BBMap.insert(std::make_pair(&*F->begin(), clonedEntryBB));

Builder.setInsertionPoint(clonedEntryBB);

// This will layout all newly cloned blocks immediate after clonedEntryBB.
visitBlocksDepthFirst(&*F->begin());

commonFixUp(F);
}

template<typename ImplClass>
void SILCloner<ImplClass>::clonePhiArgs(SILBasicBlock *oldBB) {
auto *mappedBB = BBMap[oldBB];
Expand Down
13 changes: 13 additions & 0 deletions include/swift/SIL/SILFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,19 @@ class SILFunction
/// generic.
SubstitutionMap getForwardingSubstitutionMap();

/// Returns true if this SILFunction must be a defer statement.
///
/// NOTE: This may return false for defer statements that have been
/// deserialized without a DeclContext. This means that this is guaranteed to
/// be correct for SILFunctions in Raw SIL that were not deserialized as
/// canonical. Thus one can use it for diagnostics.
bool isDefer() const {
if (auto *dc = getDeclContext())
if (auto *decl = dyn_cast_or_null<FuncDecl>(dc->getAsDecl()))
return decl->isDeferBody();
return false;
}

//===--------------------------------------------------------------------===//
// Block List Access
//===--------------------------------------------------------------------===//
Expand Down
29 changes: 17 additions & 12 deletions include/swift/SILOptimizer/Utils/SpecializationMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,24 @@ class FunctionSignatureSpecializationMangler : public SpecializationMangler {
using ArgumentModifierIntBase = uint16_t;
enum class ArgumentModifier : ArgumentModifierIntBase {
// Option Space 4 bits (i.e. 16 options).
Unmodified=0,
ConstantProp=1,
ClosureProp=2,
BoxToValue=3,
BoxToStack=4,
First_Option=0, Last_Option=31,
Unmodified = 0,
ConstantProp = 1,
ClosureProp = 2,
BoxToValue = 3,
BoxToStack = 4,
InOutToOut = 5,

First_Option = 0,
Last_Option = 31,

// Option Set Space. 12 bits (i.e. 12 option).
Dead=32,
OwnedToGuaranteed=64,
SROA=128,
GuaranteedToOwned=256,
ExistentialToGeneric=512,
First_OptionSetEntry=32, LastOptionSetEntry=32768,
Dead = 32,
OwnedToGuaranteed = 64,
SROA = 128,
GuaranteedToOwned = 256,
ExistentialToGeneric = 512,
First_OptionSetEntry = 32,
LastOptionSetEntry = 32768,
};

using ArgInfo = std::pair<ArgumentModifierIntBase,
Expand All @@ -102,6 +106,7 @@ class FunctionSignatureSpecializationMangler : public SpecializationMangler {
void setArgumentSROA(unsigned OrigArgIdx);
void setArgumentBoxToValue(unsigned OrigArgIdx);
void setArgumentBoxToStack(unsigned OrigArgIdx);
void setArgumentInOutToOut(unsigned OrigArgIdx);
void setReturnValueOwnedToUnowned();

std::string mangle();
Expand Down
5 changes: 5 additions & 0 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2939,6 +2939,11 @@ NodePointer Demangler::demangleFuncSpecParam(Node::Kind Kind) {
return addChild(Param, createNode(
Node::Kind::FunctionSignatureSpecializationParamKind,
unsigned(FunctionSigSpecializationParamKind::BoxToStack)));
case 'r':
return addChild(
Param,
createNode(Node::Kind::FunctionSignatureSpecializationParamKind,
unsigned(FunctionSigSpecializationParamKind::InOutToOut)));
default:
return nullptr;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ void NodePrinter::printFunctionSigSpecializationParams(NodePointer Node,
switch (K) {
case FunctionSigSpecializationParamKind::BoxToValue:
case FunctionSigSpecializationParamKind::BoxToStack:
case FunctionSigSpecializationParamKind::InOutToOut:
print(Node->getChild(Idx++), depth + 1);
break;
case FunctionSigSpecializationParamKind::ConstantPropFunction:
Expand Down Expand Up @@ -1582,6 +1583,9 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
case FunctionSigSpecializationParamKind::BoxToStack:
Printer << "Stack Promoted from Box";
return nullptr;
case FunctionSigSpecializationParamKind::InOutToOut:
Printer << "InOut Converted to Out";
return nullptr;
case FunctionSigSpecializationParamKind::ConstantPropFunction:
Printer << "Constant Propagated Function";
return nullptr;
Expand Down
5 changes: 5 additions & 0 deletions lib/Demangling/OldDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,11 @@ class OldDemangler {
if (!result)
return nullptr;
param->addChild(result, Factory);
} else if (Mangled.nextIf("r_")) {
auto result = FUNCSIGSPEC_CREATE_PARAM_KIND(InOutToOut);
if (!result)
return nullptr;
param->addChild(result, Factory);
} else {
// Otherwise handle option sets.
unsigned Value = 0;
Expand Down
3 changes: 3 additions & 0 deletions lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,9 @@ Remangler::mangleFunctionSignatureSpecializationParam(Node *node,
case FunctionSigSpecializationParamKind::BoxToStack:
Buffer << 's';
break;
case FunctionSigSpecializationParamKind::InOutToOut:
Buffer << 'r';
break;
case FunctionSigSpecializationParamKind::SROA:
Buffer << 'x';
break;
Expand Down
Loading