Skip to content

Replace SILType::isTrivial(SILModule) with isTrivial(SILFunction) #23228

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 7 commits into from
Mar 12, 2019
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
3 changes: 1 addition & 2 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3538,8 +3538,7 @@ class SILResultInfo {
}

ValueOwnershipKind
getOwnershipKind(SILModule &,
CanGenericSignature sig) const; // in SILType.cpp
getOwnershipKind(SILFunction &) const; // in SILType.cpp

bool operator==(SILResultInfo rhs) const {
return TypeAndConvention == rhs.TypeAndConvention;
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/OwnershipUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ LinearLifetimeError valueHasLinearLifetime(
SmallVectorImpl<SILBasicBlock *> *leakingBlocks = nullptr);

/// Returns true if v is an address or trivial.
bool isValueAddressOrTrivial(SILValue v, SILModule &m);
bool isValueAddressOrTrivial(SILValue v);

/// These operations forward both owned and guaranteed ownership.
bool isOwnershipForwardingValueKind(SILNodeKind kind);
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/Projection.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ class ProjectionPath {

/// Return true if the given projection paths in \p CPaths does not cover
/// all the fields with non-trivial semantics, false otherwise.
static bool hasUncoveredNonTrivials(SILType B, SILModule *Mod,
static bool hasUncoveredNonTrivials(SILType B, const SILFunction &F,
ProjectionPathSet &CPaths);

/// Returns true if the two paths have a non-empty symmetric
Expand Down
12 changes: 6 additions & 6 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ class SILBuilder {
return createLoad(Loc, LV, LoadOwnershipQualifier::Unqualified);
}

if (LV->getType().isTrivial(getModule())) {
if (LV->getType().isTrivial(getFunction())) {
return createLoad(Loc, LV, LoadOwnershipQualifier::Trivial);
}
return createLoad(Loc, LV, Qualifier);
Expand Down Expand Up @@ -764,7 +764,7 @@ class SILBuilder {
return createStore(Loc, Src, DestAddr,
StoreOwnershipQualifier::Unqualified);
}
if (Src->getType().isTrivial(getModule())) {
if (Src->getType().isTrivial(getFunction())) {
return createStore(Loc, Src, DestAddr, StoreOwnershipQualifier::Trivial);
}
return createStore(Loc, Src, DestAddr, Qualifier);
Expand Down Expand Up @@ -1095,7 +1095,7 @@ class SILBuilder {
}

CopyValueInst *createCopyValue(SILLocation Loc, SILValue operand) {
assert(!operand->getType().isTrivial(getModule()) &&
assert(!operand->getType().isTrivial(getFunction()) &&
"Should not be passing trivial values to this api. Use instead "
"emitCopyValueOperation");
return insert(new (getModule())
Expand All @@ -1104,7 +1104,7 @@ class SILBuilder {

DestroyValueInst *createDestroyValue(SILLocation Loc, SILValue operand) {
assert(isLoadableOrOpaque(operand->getType()));
assert(!operand->getType().isTrivial(getModule()) &&
assert(!operand->getType().isTrivial(getFunction()) &&
"Should not be passing trivial values to this api. Use instead "
"emitDestroyValueOperation");
return insert(new (getModule())
Expand Down Expand Up @@ -1398,13 +1398,13 @@ class SILBuilder {
DestructureStructInst *createDestructureStruct(SILLocation Loc,
SILValue Operand) {
return insert(DestructureStructInst::create(
getModule(), getSILDebugLocation(Loc), Operand));
getFunction(), getSILDebugLocation(Loc), Operand));
}

DestructureTupleInst *createDestructureTuple(SILLocation Loc,
SILValue Operand) {
return insert(DestructureTupleInst::create(
getModule(), getSILDebugLocation(Loc), Operand));
getFunction(), getSILDebugLocation(Loc), Operand));
}

MultipleValueInstruction *emitDestructureValueOperation(SILLocation loc,
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/SILCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ SILCloner<ImplClass>::getMappedValue(SILValue Value) {
if (auto *U = dyn_cast<SILUndef>(Value)) {
auto type = getOpType(U->getType());
ValueBase *undef =
(type == U->getType() ? U : SILUndef::get(type, Builder.getModule()));
(type == U->getType() ? U : SILUndef::get(type, Builder.getFunction()));
return SILValue(undef);
}

Expand Down
14 changes: 8 additions & 6 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -4700,14 +4700,14 @@ class StructInst final : public InstructionBaseWithTrailingOperands<
/// Search the operands of this struct for a unique non-trivial field. If we
/// find it, return it. Otherwise return SILValue().
SILValue getUniqueNonTrivialFieldValue() {
SILModule &Mod = getModule();
auto *F = getFunction();
ArrayRef<Operand> Ops = getAllOperands();

Optional<unsigned> Index;
// For each operand...
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
// If the operand is not trivial...
if (!Ops[i].get()->getType().isTrivial(Mod)) {
if (!Ops[i].get()->getType().isTrivial(*F)) {
// And we have not found an Index yet, set index to i and continue.
if (!Index.hasValue()) {
Index = i;
Expand Down Expand Up @@ -4993,14 +4993,14 @@ class TupleInst final : public InstructionBaseWithTrailingOperands<
/// Search the operands of this tuple for a unique non-trivial elt. If we find
/// it, return it. Otherwise return SILValue().
SILValue getUniqueNonTrivialElt() {
SILModule &Mod = getModule();
auto *F = getFunction();
ArrayRef<Operand> Ops = getAllOperands();

Optional<unsigned> Index;
// For each operand...
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
// If the operand is not trivial...
if (!Ops[i].get()->getType().isTrivial(Mod)) {
if (!Ops[i].get()->getType().isTrivial(*F)) {
// And we have not found an Index yet, set index to i and continue.
if (!Index.hasValue()) {
Index = i;
Expand Down Expand Up @@ -7715,7 +7715,8 @@ class DestructureStructInst final
MultipleValueInstructionTrailingObjects(this, Types, OwnershipKinds) {}

public:
static DestructureStructInst *create(SILModule &M, SILDebugLocation Loc,
static DestructureStructInst *create(const SILFunction &F,
SILDebugLocation Loc,
SILValue Operand);
static bool classof(const SILNode *N) {
return N->getKind() == SILNodeKind::DestructureStructInst;
Expand Down Expand Up @@ -7763,7 +7764,8 @@ class DestructureTupleInst final
MultipleValueInstructionTrailingObjects(this, Types, OwnershipKinds) {}

public:
static DestructureTupleInst *create(SILModule &M, SILDebugLocation Loc,
static DestructureTupleInst *create(const SILFunction &F,
SILDebugLocation Loc,
SILValue Operand);
static bool classof(const SILNode *N) {
return N->getKind() == SILNodeKind::DestructureTupleInst;
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/SILModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class SILModule {
llvm::DenseMap<Identifier, BuiltinInfo> BuiltinIDCache;

/// This is the set of undef values we've created, for uniquing purposes.
llvm::DenseMap<SILType, SILUndef *> UndefValues;
llvm::DenseMap<std::pair<SILType, unsigned>, SILUndef *> UndefValues;

/// The stage of processing this module is at.
SILStage Stage;
Expand Down
7 changes: 2 additions & 5 deletions include/swift/SIL/SILType.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,8 @@ class SILType {
/// \p F into account (see isLoadable(SILFunction)).
bool isAddressOnly(const SILFunction &F) const;

/// True if the type, or the referenced type of an address type, is trivial.
bool isTrivial(SILModule &M) const;

/// Like isTrivial(SILModule), but takes the resilience expansion of
/// \p F into account (see isLoadable(SILFunction)).
/// True if the type, or the referenced type of an address type, is trivial,
/// meaning it is loadable and can be trivially copied, moved or detroyed.
bool isTrivial(const SILFunction &F) const;

/// True if the type, or the referenced type of an address type, is known to
Expand Down
12 changes: 7 additions & 5 deletions include/swift/SIL/SILUndef.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ class SILModule;
class SILUndef : public ValueBase {
ValueOwnershipKind ownershipKind;

SILUndef(SILType type, SILModule &m);
SILUndef(SILType type, ValueOwnershipKind ownershipKind);

public:
void operator=(const SILArgument &) = delete;
void operator delete(void *, size_t) SWIFT_DELETE_OPERATOR_DELETED;

static SILUndef *get(SILType ty, SILModule &m);
static SILUndef *get(SILType ty, SILModule *m) { return get(ty, *m); }
static SILUndef *get(SILType ty, SILModule &m, ValueOwnershipKind ownershipKind);
static SILUndef *get(SILType ty, const SILFunction &f);

template <class OwnerTy>
static SILUndef *getSentinelValue(SILType type, SILModule &m, OwnerTy owner) {
return new (*owner) SILUndef(type, m);
static SILUndef *getSentinelValue(SILType type, OwnerTy owner) {
// Ownership kind isn't used here, the value just needs to have a unique
// address.
return new (*owner) SILUndef(type, ValueOwnershipKind::Any);
}

ValueOwnershipKind getOwnershipKind() const { return ownershipKind; }
Expand Down
7 changes: 3 additions & 4 deletions include/swift/SIL/SILValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ struct ValueOwnershipKind {

ValueOwnershipKind(innerty NewValue) : Value(NewValue) {}
explicit ValueOwnershipKind(unsigned NewValue) : Value(innerty(NewValue)) {}
ValueOwnershipKind(SILModule &M, SILType Type,
ValueOwnershipKind(const SILFunction &F, SILType Type,
SILArgumentConvention Convention);

/// Parse Value into a ValueOwnershipKind.
Expand All @@ -157,7 +157,7 @@ struct ValueOwnershipKind {
/// ownership kind, and a subobject of type Proj is being projected from the
/// aggregate, return Trivial if Proj has trivial type and the aggregate's
/// ownership kind otherwise.
ValueOwnershipKind getProjectedOwnershipKind(SILModule &M,
ValueOwnershipKind getProjectedOwnershipKind(const SILFunction &F,
SILType Proj) const;

/// Return the lifetime constraint semantics for this
Expand Down Expand Up @@ -374,8 +374,7 @@ class SILValue {
ValueOwnershipKind getOwnershipKind() const;

/// Verify that this SILValue and its uses respects ownership invariants.
void verifyOwnership(SILModule &Mod,
DeadEndBlocks *DEBlocks = nullptr) const;
void verifyOwnership(DeadEndBlocks *DEBlocks = nullptr) const;
};

/// A map from a ValueOwnershipKind that an operand can accept to a
Expand Down
4 changes: 2 additions & 2 deletions include/swift/SIL/TypeSubstCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
void visitCopyValueInst(CopyValueInst *Copy) {
// If the substituted type is trivial, ignore the copy.
SILType copyTy = getOpType(Copy->getType());
if (copyTy.isTrivial(Copy->getModule())) {
if (copyTy.isTrivial(*Copy->getFunction())) {
recordFoldedValue(SILValue(Copy), getOpValue(Copy->getOperand()));
return;
}
Expand All @@ -277,7 +277,7 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
void visitDestroyValueInst(DestroyValueInst *Destroy) {
// If the substituted type is trivial, ignore the destroy.
SILType destroyTy = getOpType(Destroy->getOperand()->getType());
if (destroyTy.isTrivial(Destroy->getModule())) {
if (destroyTy.isTrivial(*Destroy->getFunction())) {
return;
}
super::visitDestroyValueInst(Destroy);
Expand Down
7 changes: 2 additions & 5 deletions include/swift/SILOptimizer/Utils/GenericCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ class GenericCloner

GenericCloner(SILOptFunctionBuilder &FuncBuilder,
SILFunction *F,
IsSerialized_t Serialized,
const ReabstractionInfo &ReInfo,
SubstitutionMap ParamSubs,
StringRef NewName,
CloneCollector::CallbackType Callback)
: SuperTy(*initCloned(FuncBuilder, F, Serialized, ReInfo, NewName), *F,
: SuperTy(*initCloned(FuncBuilder, F, ReInfo, NewName), *F,
ParamSubs), FuncBuilder(FuncBuilder), ReInfo(ReInfo), Callback(Callback) {
assert(F->getDebugScope()->Parent != getCloned()->getDebugScope()->Parent);
}
Expand All @@ -64,13 +63,12 @@ class GenericCloner
static SILFunction *
cloneFunction(SILOptFunctionBuilder &FuncBuilder,
SILFunction *F,
IsSerialized_t Serialized,
const ReabstractionInfo &ReInfo,
SubstitutionMap ParamSubs,
StringRef NewName,
CloneCollector::CallbackType Callback =nullptr) {
// Clone and specialize the function.
GenericCloner SC(FuncBuilder, F, Serialized, ReInfo, ParamSubs,
GenericCloner SC(FuncBuilder, F, ReInfo, ParamSubs,
NewName, Callback);
SC.populateCloned();
return SC.getCloned();
Expand All @@ -96,7 +94,6 @@ class GenericCloner
private:
static SILFunction *initCloned(SILOptFunctionBuilder &FuncBuilder,
SILFunction *Orig,
IsSerialized_t Serialized,
const ReabstractionInfo &ReInfo,
StringRef NewName);
/// Clone the body of the function into the empty function that was created
Expand Down
10 changes: 8 additions & 2 deletions include/swift/SILOptimizer/Utils/Generics.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class ReabstractionInfo {
// It uses interface types.
SubstitutionMap CallerInterfaceSubs;

// Is the generated specialization going to be serialized?
IsSerialized_t Serialized;

// Create a new substituted type with the updated signature.
CanSILFunctionType createSubstitutedType(SILFunction *OrigF,
SubstitutionMap SubstMap,
Expand All @@ -139,6 +142,7 @@ class ReabstractionInfo {
/// invalid type.
ReabstractionInfo(ApplySite Apply, SILFunction *Callee,
SubstitutionMap ParamSubs,
IsSerialized_t Serialized,
bool ConvertIndirectToDirect = true,
OptRemark::Emitter *ORE = nullptr);

Expand All @@ -147,6 +151,10 @@ class ReabstractionInfo {
/// conformances or same concrete type requirements.
ReabstractionInfo(SILFunction *Callee, ArrayRef<Requirement> Requirements);

IsSerialized_t isSerialized() const {
return Serialized;
}

/// Returns true if the \p ParamIdx'th (non-result) formal parameter is
/// converted from indirect to direct.
bool isParamConverted(unsigned ParamIdx) const {
Expand Down Expand Up @@ -263,7 +271,6 @@ class GenericFuncSpecializer {
SILModule &M;
SILFunction *GenericFunc;
SubstitutionMap ParamSubs;
IsSerialized_t Serialized;
const ReabstractionInfo &ReInfo;

SubstitutionMap ContextSubs;
Expand All @@ -273,7 +280,6 @@ class GenericFuncSpecializer {
GenericFuncSpecializer(SILOptFunctionBuilder &FuncBuilder,
SILFunction *GenericFunc,
SubstitutionMap ParamSubs,
IsSerialized_t Serialized,
const ReabstractionInfo &ReInfo);

/// If we already have this specialization, reuse it.
Expand Down
6 changes: 3 additions & 3 deletions include/swift/SILOptimizer/Utils/Local.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,20 +551,20 @@ bool calleesAreStaticallyKnowable(SILModule &M, SILDeclRef Decl);
// can be derived e.g.:
// - from a constructor or
// - from a successful outcome of a checked_cast_br [exact] instruction.
SILValue getInstanceWithExactDynamicType(SILValue S, SILModule &M,
SILValue getInstanceWithExactDynamicType(SILValue S,
ClassHierarchyAnalysis *CHA);

/// Try to determine the exact dynamic type of an object.
/// returns the exact dynamic type of the object, or an empty type if the exact
/// type could not be determined.
SILType getExactDynamicType(SILValue S, SILModule &M,
SILType getExactDynamicType(SILValue S,
ClassHierarchyAnalysis *CHA,
bool ForUnderlyingObject = false);

/// Try to statically determine the exact dynamic type of the underlying object.
/// returns the exact dynamic type of the underlying object, or an empty SILType
/// if the exact type could not be determined.
SILType getExactDynamicTypeOfUnderlyingObject(SILValue S, SILModule &M,
SILType getExactDynamicTypeOfUnderlyingObject(SILValue S,
ClassHierarchyAnalysis *CHA);

/// Utility class for cloning init values into the static initializer of a
Expand Down
3 changes: 0 additions & 3 deletions include/swift/SILOptimizer/Utils/SILSSAUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,12 @@ class SILSSAUpdater {
// If not null updated with inserted 'phi' nodes (SILArgument).
SmallVectorImpl<SILPhiArgument *> *InsertedPHIs;

SILModule &M;

// Not copyable.
void operator=(const SILSSAUpdater &) = delete;
SILSSAUpdater(const SILSSAUpdater &) = delete;

public:
explicit SILSSAUpdater(
SILModule &M,
SmallVectorImpl<SILPhiArgument *> *InsertedPHIs = nullptr);
~SILSSAUpdater();

Expand Down
2 changes: 1 addition & 1 deletion include/swift/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
/// Don't worry about adhering to the 80-column limit for this line.
const uint16_t SWIFTMODULE_VERSION_MINOR = 476; // Last change: prebuilt module cache
const uint16_t SWIFTMODULE_VERSION_MINOR = 477; // SILUndef serialized with ownership kind

using DeclIDField = BCFixed<31>;

Expand Down
5 changes: 3 additions & 2 deletions lib/IRGen/GenOpaque.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "swift/AST/IRGenOptions.h"
#include "swift/ABI/MetadataValues.h"
#include "swift/IRGen/ValueWitness.h"
#include "swift/SIL/TypeLowering.h"

#include "Callee.h"
#include "Explosion.h"
Expand Down Expand Up @@ -719,7 +720,7 @@ void irgen::emitDestroyArrayCall(IRGenFunction &IGF,
Address object,
llvm::Value *count) {
// If T is a trivial/POD type, nothing needs to be done.
if (T.getObjectType().isTrivial(IGF.getSILModule()))
if (IGF.IGM.getTypeLowering(T).isTrivial())
return;

auto metadata = IGF.emitTypeMetadataRefForLayout(T);
Expand Down Expand Up @@ -994,7 +995,7 @@ void irgen::emitDestroyCall(IRGenFunction &IGF,
SILType T,
Address object) {
// If T is a trivial/POD type, nothing needs to be done.
if (T.getObjectType().isTrivial(IGF.getSILModule()))
if (IGF.IGM.getTypeLowering(T).isTrivial())
return;
llvm::Value *metadata;
auto fn = IGF.emitValueWitnessFunctionRef(T, metadata,
Expand Down
Loading