mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Similarly to how we've always handled parameter types, we now recursively expand tuples in result types and separately determine a result convention for each result. The most important code-generation change here is that indirect results are now returned separately from each other and from any direct results. It is generally far better, when receiving an indirect result, to receive it as an independent result; the caller is much more likely to be able to directly receive the result in the address they want to initialize, rather than having to receive it in temporary memory and then copy parts of it into the target. The most important conceptual change here that clients and producers of SIL must be aware of is the new distinction between a SILFunctionType's *parameters* and its *argument list*. The former is just the formal parameters, derived purely from the parameter types of the original function; indirect results are no longer in this list. The latter includes the indirect result arguments; as always, all the indirect results strictly precede the parameters. Apply instructions and entry block arguments follow the argument list, not the parameter list. A relatively minor change is that there can now be multiple direct results, each with its own result convention. This is a minor change because I've chosen to leave return instructions as taking a single operand and apply instructions as producing a single result; when the type describes multiple results, they are implicitly bound up in a tuple. It might make sense to split these up and allow e.g. return instructions to take a list of operands; however, it's not clear what to do on the caller side, and this would be a major change that can be separated out from this already over-large patch. Unsurprisingly, the most invasive changes here are in SILGen; this requires substantial reworking of both call emission and reabstraction. It also proved important to switch several SILGen operations over to work with RValue instead of ManagedValue, since otherwise they would be forced to spuriously "implode" buffers.
156 lines
5.3 KiB
C++
156 lines
5.3 KiB
C++
//===--- RCStateTransition.h ------------------------------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_SILOPTIMIZER_PASSMANAGER_ARC_RCSTATETRANSITION_H
|
|
#define SWIFT_SILOPTIMIZER_PASSMANAGER_ARC_RCSTATETRANSITION_H
|
|
|
|
#include "swift/Basic/type_traits.h"
|
|
#include "swift/Basic/ImmutablePointerSet.h"
|
|
#include "swift/SIL/SILArgument.h"
|
|
#include "swift/SIL/SILInstruction.h"
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
#include <cstdint>
|
|
|
|
namespace swift {
|
|
|
|
class RCIdentityFunctionInfo;
|
|
class ConsumedArgToEpilogueReleaseMatcher;
|
|
|
|
} // end swift namespace
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// RCStateTransitionKind
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
namespace swift {
|
|
|
|
/// The kind of a RCStateTransition.
|
|
enum class RCStateTransitionKind : uint8_t {
|
|
#define KIND(K) K,
|
|
#define ABSTRACT_VALUE(Name, StartKind, EndKind) \
|
|
Name ## _Start = StartKind, Name ## _End = EndKind,
|
|
#include "RCStateTransition.def"
|
|
};
|
|
|
|
/// \returns the RCStateTransitionKind corresponding to \p V.
|
|
RCStateTransitionKind getRCStateTransitionKind(ValueBase *V);
|
|
|
|
/// Define predicates to test for RCStateTransition abstract value kinds.
|
|
#define ABSTRACT_VALUE(Name, Start, End) \
|
|
bool isRCStateTransition ## Name(RCStateTransitionKind Kind); \
|
|
static inline bool isRCStateTransition ## Name(ValueBase *V) { \
|
|
return isRCStateTransition ## Name(getRCStateTransitionKind(V)); \
|
|
}
|
|
#define KIND(Name) \
|
|
static inline bool isRCStateTransition ## Name(ValueBase *V) { \
|
|
return RCStateTransitionKind::Name == getRCStateTransitionKind(V); \
|
|
}
|
|
#include "RCStateTransition.def"
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// RCStateTransition
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
class RefCountState;
|
|
class BottomUpRefCountState;
|
|
class TopDownRefCountState;
|
|
|
|
/// Represents a transition in the RC history of a ref count.
|
|
class RCStateTransition {
|
|
friend class RefCountState;
|
|
friend class BottomUpRefCountState;
|
|
friend class TopDownRefCountState;
|
|
|
|
/// An RCStateTransition can represent either an RC end point (i.e. an initial
|
|
/// or terminal RC transition) or a ptr set of Mutators.
|
|
ValueBase *EndPoint;
|
|
ImmutablePointerSet<SILInstruction> *Mutators =
|
|
ImmutablePointerSetFactory<SILInstruction>::getEmptySet();
|
|
RCStateTransitionKind Kind;
|
|
|
|
// Should only be constructed be default RefCountState.
|
|
RCStateTransition() = default;
|
|
|
|
public:
|
|
~RCStateTransition() = default;
|
|
RCStateTransition(const RCStateTransition &R) = default;
|
|
|
|
RCStateTransition(ImmutablePointerSet<SILInstruction> *I) {
|
|
assert(I->size() == 1);
|
|
SILInstruction *Inst = *I->begin();
|
|
Kind = getRCStateTransitionKind(Inst);
|
|
if (isRCStateTransitionEndPoint(Kind)) {
|
|
EndPoint = Inst;
|
|
return;
|
|
}
|
|
|
|
if (isRCStateTransitionMutator(Kind)) {
|
|
Mutators = I;
|
|
return;
|
|
}
|
|
|
|
// Unknown kind.
|
|
}
|
|
|
|
RCStateTransition(SILArgument *A)
|
|
: EndPoint(A), Kind(RCStateTransitionKind::StrongEntrance) {
|
|
assert(A->hasConvention(SILArgumentConvention::Direct_Owned) &&
|
|
"Expected owned argument");
|
|
}
|
|
|
|
RCStateTransitionKind getKind() const { return Kind; }
|
|
|
|
/// Define test functions for the various abstract categorizations we have.
|
|
#define ABSTRACT_VALUE(Name, StartKind, EndKind) bool is ## Name() const;
|
|
#include "RCStateTransition.def"
|
|
|
|
/// Return true if this Transition is a mutator transition that contains I.
|
|
bool containsMutator(SILInstruction *I) const {
|
|
assert(isMutator() && "This should only be called if we are of mutator "
|
|
"kind");
|
|
return Mutators->count(I);
|
|
}
|
|
|
|
using mutator_range =
|
|
iterator_range<std::remove_pointer<decltype(Mutators)>::type::iterator>;
|
|
|
|
/// Returns a Range of Mutators. Asserts if this transition is not a mutator
|
|
/// transition.
|
|
mutator_range getMutators() const {
|
|
assert(isMutator() && "This should never be called given mutators");
|
|
return {Mutators->begin(), Mutators->end()};
|
|
}
|
|
|
|
/// Return true if Inst is an instruction that causes a transition that can be
|
|
/// paired with this transition.
|
|
bool matchingInst(SILInstruction *Inst) const;
|
|
|
|
/// Attempt to merge \p Other into \p this. Returns true if we succeeded,
|
|
/// false otherwise.
|
|
bool merge(const RCStateTransition &Other);
|
|
|
|
/// Return true if the kind of this RCStateTransition is not 'Invalid'.
|
|
bool isValid() const { return getKind() != RCStateTransitionKind::Invalid; }
|
|
};
|
|
|
|
// These static assert checks are here for performance reasons.
|
|
static_assert(IsTriviallyCopyable<RCStateTransition>::value,
|
|
"RCStateTransitions must be trivially copyable");
|
|
|
|
} // end swift namespace
|
|
|
|
namespace llvm {
|
|
raw_ostream &operator<<(raw_ostream &os, swift::RCStateTransitionKind Kind);
|
|
} // end llvm namespace
|
|
|
|
#endif
|