Skip to content

Commit 4504aee

Browse files
committed
SIL: Use SILFunction type lowering APIs in various places
1 parent 354ce41 commit 4504aee

15 files changed

+43
-43
lines changed

lib/IRGen/GenType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ llvm::PointerType *IRGenModule::getStoragePointerTypeForLowered(CanType T) {
14561456
}
14571457

14581458
llvm::Type *IRGenModule::getStorageTypeForUnlowered(Type subst) {
1459-
return getStorageType(getSILTypes().getLoweredType(subst));
1459+
return getStorageType(getLoweredType(subst));
14601460
}
14611461

14621462
llvm::Type *IRGenModule::getStorageType(SILType T) {
@@ -1486,7 +1486,7 @@ IRGenModule::getTypeInfoForUnlowered(AbstractionPattern orig, Type subst) {
14861486
/// have yet undergone SIL type lowering.
14871487
const TypeInfo &
14881488
IRGenModule::getTypeInfoForUnlowered(AbstractionPattern orig, CanType subst) {
1489-
return getTypeInfo(getSILTypes().getLoweredType(orig, subst));
1489+
return getTypeInfo(getLoweredType(orig, subst));
14901490
}
14911491

14921492
/// Get the fragile type information for the given type, which is known

lib/IRGen/LoadableByAddress.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,8 +2221,8 @@ static void rewriteFunction(StructLoweringState &pass,
22212221
retBuilder.createStore(regLoc, retOp, retArg,
22222222
getStoreInitOwnership(pass, retOp->getType()));
22232223
}
2224-
auto emptyTy = retBuilder.getModule().Types.getLoweredType(
2225-
TupleType::getEmpty(retBuilder.getModule().getASTContext()));
2224+
auto emptyTy = SILType::getPrimitiveObjectType(
2225+
retBuilder.getModule().getASTContext().TheEmptyTupleType);
22262226
auto newRetTuple = retBuilder.createTuple(regLoc, emptyTy, {});
22272227
retBuilder.createReturn(newRetTuple->getLoc(), newRetTuple);
22282228
instr->eraseFromParent();

lib/ParseSIL/ParseSIL.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4767,8 +4767,9 @@ bool SILParser::parseSILInstruction(SILBuilder &B) {
47674767
= OpenedArchetypeType::get(Val->getType().getASTType())
47684768
->getCanonicalType();
47694769

4770-
SILType LoweredTy = SILMod.Types.getLoweredType(
4771-
Lowering::AbstractionPattern(archetype), Ty)
4770+
auto &F = B.getFunction();
4771+
SILType LoweredTy = F.getLoweredType(
4772+
Lowering::AbstractionPattern(archetype), Ty)
47724773
.getAddressType();
47734774

47744775
// Collect conformances for the type.

lib/SIL/DynamicCasts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ namespace {
798798

799799
private:
800800
const TypeLowering &getTypeLowering(SILType type) {
801-
return M.Types.getTypeLowering(type);
801+
return B.getFunction().getTypeLowering(type);
802802
}
803803

804804
SILValue getOwnedScalar(Source source, const TypeLowering &srcTL) {

lib/SIL/SILOpenedArchetypesTracker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ bool SILOpenedArchetypesTracker::registerUsedOpenedArchetypes(CanType Ty) {
7070
SILBuilder B(CurF->getEntryBlock()->begin());
7171
Placeholder =
7272
B.createGlobalAddr(ArtificialUnreachableLocation(),
73-
SILMod.Types.getLoweredType(archetypeTy));
73+
SILType::getPrimitiveAddressType(archetypeTy));
7474
} else {
7575
SILBuilder B(CurF->getEntryBlock());
7676
Placeholder =
7777
B.createGlobalAddr(ArtificialUnreachableLocation(),
78-
SILMod.Types.getLoweredType(archetypeTy));
78+
SILType::getPrimitiveAddressType(archetypeTy));
7979
}
8080
// Make it available to SILBuilder, so that instructions using this
8181
// archetype can be constructed.

lib/SIL/SILVerifier.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,10 +2069,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
20692069
SILType exType = AEBI->getExistentialType();
20702070
auto archetype = OpenedArchetypeType::get(exType.getASTType());
20712071

2072-
auto loweredTy = F.getModule().Types.getLoweredType(
2073-
Lowering::AbstractionPattern(archetype),
2074-
AEBI->getFormalConcreteType())
2075-
.getAddressType();
2072+
auto loweredTy = F.getLoweredType(Lowering::AbstractionPattern(archetype),
2073+
AEBI->getFormalConcreteType())
2074+
.getAddressType();
20762075

20772076
requireSameType(loweredTy, PEBI->getType(),
20782077
"project_existential_box result should be the lowered "
@@ -3120,9 +3119,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
31203119
// The lowered type must be the properly-abstracted form of the AST type.
31213120
auto archetype = OpenedArchetypeType::get(exType.getASTType());
31223121

3123-
auto loweredTy = F.getModule().Types.getLoweredType(
3124-
Lowering::AbstractionPattern(archetype),
3125-
AEI->getFormalConcreteType())
3122+
auto loweredTy = F.getLoweredType(Lowering::AbstractionPattern(archetype),
3123+
AEI->getFormalConcreteType())
31263124
.getAddressType();
31273125

31283126
requireSameType(loweredTy, AEI->getLoweredConcreteType(),
@@ -3149,8 +3147,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
31493147
// The operand must be at the right abstraction level for the existential.
31503148
SILType exType = IEI->getType();
31513149
auto archetype = OpenedArchetypeType::get(exType.getASTType());
3152-
auto loweredTy = F.getModule().Types.getLoweredType(
3153-
Lowering::AbstractionPattern(archetype), IEI->getFormalConcreteType());
3150+
auto loweredTy = F.getLoweredType(Lowering::AbstractionPattern(archetype),
3151+
IEI->getFormalConcreteType());
31543152
requireSameType(
31553153
concreteType, loweredTy,
31563154
"init_existential_value operand must be lowered to the right "
@@ -3181,9 +3179,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
31813179
// The operand must be at the right abstraction level for the existential.
31823180
SILType exType = IEI->getType();
31833181
auto archetype = OpenedArchetypeType::get(exType.getASTType());
3184-
auto loweredTy = F.getModule().Types.getLoweredType(
3185-
Lowering::AbstractionPattern(archetype),
3186-
IEI->getFormalConcreteType());
3182+
auto loweredTy = F.getLoweredType(Lowering::AbstractionPattern(archetype),
3183+
IEI->getFormalConcreteType());
31873184
requireSameType(concreteType, loweredTy,
31883185
"init_existential_ref operand must be lowered to the right "
31893186
"abstraction level for the existential");
@@ -3333,8 +3330,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
33333330
"downcast operand must be a class type");
33343331
require(toCanTy.getClassOrBoundGenericClass(),
33353332
"downcast must convert to a class type");
3336-
require(SILType::getPrimitiveObjectType(fromCanTy).
3337-
isBindableToSuperclassOf(SILType::getPrimitiveObjectType(toCanTy)),
3333+
require(fromCanTy->isBindableToSuperclassOf(toCanTy),
33383334
"downcast must convert to a subclass");
33393335
}
33403336
}

lib/SILGen/ArgumentSource.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ ManagedValue ArgumentSource::materialize(SILGenFunction &SGF,
189189
SILType destType) && {
190190
auto substFormalType = getSubstRValueType();
191191
assert(!destType || destType.getObjectType() ==
192-
SGF.SGM.Types.getLoweredType(origFormalType,
193-
substFormalType).getObjectType());
192+
SGF.getLoweredType(origFormalType,
193+
substFormalType).getObjectType());
194194

195195
// Fast path: if the types match exactly, no abstraction difference
196196
// is possible and we can just materialize as normal.

lib/SILGen/SILGenApply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
904904
// If we are already the right rep, just return.
905905
auto givenMetatypeRep = givenMetatype->getRepresentation();
906906
if (givenMetatypeRep == destMetatypeRep) {
907-
return {selfMeta, SGF.SGM.getLoweredType(instanceType)};
907+
return {selfMeta, SGF.getLoweredType(instanceType)};
908908
}
909909

910910
CanAnyMetatypeType destMetatype;
@@ -939,7 +939,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
939939
}
940940

941941
auto result = ManagedValue::forUnmanaged(convertedValue);
942-
return {result, SGF.SGM.getLoweredType(instanceType)};
942+
return {result, SGF.getLoweredType(instanceType)};
943943
}
944944

945945
/// Given a metatype value for the type, allocate an Objective-C

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,7 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
25772577

25782578
baseType = opened->getCanonicalType();
25792579
auto openedOpaqueValue = subSGF.emitOpenExistential(loc, paramSubstValue,
2580-
opened, subSGF.SGM.getLoweredType(baseType),
2580+
opened, subSGF.getLoweredType(baseType),
25812581
AccessKind::Read);
25822582
// Maybe we could peephole this if we know the property load can borrow the
25832583
// base value…

lib/SILGen/SILGenLValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2452,7 +2452,7 @@ void LValue::addNonMemberVarComponent(SILGenFunction &SGF, SILLocation loc,
24522452
void emitUsingAddressor(SILDeclRef addressor, bool isDirect,
24532453
LValueTypeData typeData) {
24542454
SILType storageType =
2455-
SGF.SGM.Types.getLoweredType(Storage->getType()).getAddressType();
2455+
SGF.getLoweredType(Storage->getType()).getAddressType();
24562456
LV.add<AddressorComponent>(Storage, addressor,
24572457
/*isSuper=*/false, isDirect, getSubs(),
24582458
CanType(), typeData, storageType, nullptr,

lib/SILOptimizer/FunctionSignatureTransforms/ExistentialTransform.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void ExistentialSpecializerCloner::cloneAndPopulateFunction() {
109109
if (iter != ArgToGenericTypeMap.end()) {
110110
auto GenericParam = iter->second;
111111
SILType GenericSILType =
112-
M.Types.getLoweredType(NewF.mapTypeIntoContext(GenericParam));
112+
NewF.getLoweredType(NewF.mapTypeIntoContext(GenericParam));
113113
NewArg = ClonedEntryBB->createFunctionArgument(GenericSILType);
114114
NewArg->setOwnershipKind(ValueOwnershipKind(
115115
M, GenericSILType, ArgDesc.Arg->getArgumentConvention()));
@@ -173,7 +173,7 @@ void ExistentialSpecializerCloner::cloneAndPopulateFunction() {
173173
} else {
174174
/// Arguments that are not rewritten.
175175
auto Ty = params[ArgDesc.Index].getType();
176-
auto LoweredTy = M.Types.getLoweredType(NewF.mapTypeIntoContext(Ty));
176+
auto LoweredTy = NewF.getLoweredType(NewF.mapTypeIntoContext(Ty));
177177
auto MappedTy = LoweredTy.getCategoryType(ArgDesc.Arg->getType().getCategory());
178178
NewArg = ClonedEntryBB->createFunctionArgument(MappedTy, ArgDesc.Decl);
179179
NewArg->setOwnershipKind(ValueOwnershipKind(
@@ -389,7 +389,7 @@ void ExistentialTransform::populateThunkBody() {
389389
auto SwiftType = ArgDesc.Arg->getType().getASTType();
390390
auto OpenedType =
391391
SwiftType->openAnyExistentialType(Opened)->getCanonicalType();
392-
auto OpenedSILType = NewF->getModule().Types.getLoweredType(OpenedType);
392+
auto OpenedSILType = NewF->getLoweredType(OpenedType);
393393
SILValue archetypeValue;
394394
auto ExistentialRepr =
395395
ArgDesc.Arg->getType().getPreferredExistentialRepresentation(M);

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ SILValue AddressMaterialization::materializeProjection(Operand *operand) {
669669
SILValue containerAddr = materializeAddress(initExistentialValue);
670670
auto canTy = initExistentialValue->getFormalConcreteType();
671671
auto opaque = Lowering::AbstractionPattern::getOpaque();
672-
auto &concreteTL = pass.F->getModule().Types.getTypeLowering(opaque, canTy);
672+
auto &concreteTL = pass.F->getTypeLowering(opaque, canTy);
673673
return B.createInitExistentialAddr(
674674
initExistentialValue->getLoc(), containerAddr, canTy,
675675
concreteTL.getLoweredType(), initExistentialValue->getConformances());
@@ -1134,8 +1134,8 @@ void ReturnRewriter::rewriteReturn(ReturnInst *returnInst) {
11341134
== pass.loweredFnConv.getNumDirectSILResults());
11351135
SILValue newReturnVal;
11361136
if (newDirectResults.empty()) {
1137-
SILType emptyTy = B.getModule().Types.getLoweredType(
1138-
TupleType::getEmpty(B.getModule().getASTContext()));
1137+
SILType emptyTy = SILType::getPrimitiveObjectType(
1138+
B.getModule().getASTContext().TheEmptyTupleType);
11391139
newReturnVal = B.createTuple(returnInst->getLoc(), emptyTy, {});
11401140
} else if (newDirectResults.size() == 1) {
11411141
newReturnVal = newDirectResults[0];

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ SILCombiner::buildConcreteOpenedExistentialInfoFromSoleConformingType(
668668
Operand &ArgOperand) {
669669
SILInstruction *AI = ArgOperand.getUser();
670670
SILModule &M = AI->getModule();
671+
SILFunction *F = AI->getFunction();
671672

672673
// SoleConformingType is only applicable in whole-module compilation.
673674
if (!M.isWholeModule())
@@ -716,7 +717,7 @@ SILCombiner::buildConcreteOpenedExistentialInfoFromSoleConformingType(
716717
return COAI;
717718

718719
// Create SIL type for the concrete type.
719-
SILType concreteSILType = M.Types.getLoweredType(ConcreteType);
720+
SILType concreteSILType = F->getLoweredType(ConcreteType);
720721

721722
// Prepare the code by adding UncheckedCast instructions that cast opened
722723
// existentials to concrete types. Set the ConcreteValue of CEI.
@@ -729,7 +730,7 @@ SILCombiner::buildConcreteOpenedExistentialInfoFromSoleConformingType(
729730
// Bail if ConcreteSILType is not the same SILType as the type stored in the
730731
// existential after maximal reabstraction.
731732
auto abstractionPattern = Lowering::AbstractionPattern::getOpaque();
732-
auto abstractTy = M.Types.getLoweredType(abstractionPattern, ConcreteType);
733+
auto abstractTy = F->getLoweredType(abstractionPattern, ConcreteType);
733734
if (abstractTy != concreteSILType)
734735
return None;
735736

lib/SILOptimizer/SILCombiner/SILCombinerBuiltinVisitors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ SILInstruction *SILCombiner::visitBuiltinInst(BuiltinInst *I) {
614614
// Check if the element type is a trivial type.
615615
if (Substs.getReplacementTypes().size() == 1) {
616616
Type ElemType = Substs.getReplacementTypes()[0];
617-
auto &SILElemTy = I->getModule().Types.getTypeLowering(ElemType);
617+
auto &SILElemTy = I->getFunction()->getTypeLowering(ElemType);
618618
// Destroying an array of trivial types is a no-op.
619619
if (SILElemTy.isTrivial())
620620
return eraseInstFromFunction(*I);

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ SILInstruction *CastOptimizer::optimizeBridgedObjCToSwiftCast(
7373
SILInstruction *Inst, bool isConditional, SILValue Src, SILValue Dest,
7474
CanType Source, CanType Target, Type BridgedSourceTy, Type BridgedTargetTy,
7575
SILBasicBlock *SuccessBB, SILBasicBlock *FailureBB) {
76+
auto *F = Inst->getFunction();
7677
auto &M = Inst->getModule();
7778
auto Loc = Inst->getLoc();
7879

@@ -146,7 +147,7 @@ SILInstruction *CastOptimizer::optimizeBridgedObjCToSwiftCast(
146147
// equal, there is no need to generate the conversion
147148
// from ObjCTy to _ObjectiveCBridgeable._ObjectiveCType.
148149
if (isConditional) {
149-
SILBasicBlock *CastSuccessBB = Inst->getFunction()->createBasicBlock();
150+
SILBasicBlock *CastSuccessBB = F->createBasicBlock();
150151
CastSuccessBB->createPhiArgument(SILBridgedTy,
151152
ValueOwnershipKind::Owned);
152153
Builder.createBranch(Loc, CastSuccessBB, SILValue(Load));
@@ -156,7 +157,7 @@ SILInstruction *CastOptimizer::optimizeBridgedObjCToSwiftCast(
156157
SrcOp = Load;
157158
}
158159
} else if (isConditional) {
159-
SILBasicBlock *CastSuccessBB = Inst->getFunction()->createBasicBlock();
160+
SILBasicBlock *CastSuccessBB = F->createBasicBlock();
160161
CastSuccessBB->createPhiArgument(SILBridgedTy, ValueOwnershipKind::Owned);
161162
auto *CCBI = Builder.createCheckedCastBranch(Loc, false, Load,
162163
SILBridgedTy, CastSuccessBB, ConvFailBB);
@@ -189,7 +190,7 @@ SILInstruction *CastOptimizer::optimizeBridgedObjCToSwiftCast(
189190
auto *FuncRef = Builder.createFunctionRef(Loc, BridgedFunc);
190191

191192
auto MetaTy = MetatypeType::get(Target, MetatypeRepresentation::Thick);
192-
auto SILMetaTy = M.Types.getTypeLowering(MetaTy).getLoweredType();
193+
auto SILMetaTy = F->getTypeLowering(MetaTy).getLoweredType();
193194
auto *MetaTyVal = Builder.createMetatype(Loc, SILMetaTy);
194195
SmallVector<SILValue, 1> Args;
195196

@@ -219,7 +220,7 @@ SILInstruction *CastOptimizer::optimizeBridgedObjCToSwiftCast(
219220

220221
(void)ParamTypes;
221222
assert(ParamTypes[0].getConvention() == ParameterConvention::Direct_Guaranteed &&
222-
"Parameter should be @guaranteed");
223+
"Parameter should be @guaranteed");
223224

224225
// Emit a retain.
225226
Builder.createRetainValue(Loc, SrcOp, Builder.getDefaultAtomicity());
@@ -1482,6 +1483,7 @@ SILInstruction *CastOptimizer::optimizeUnconditionalCheckedCastAddrInst(
14821483
auto SourceType = Inst->getSourceType();
14831484
auto TargetType = Inst->getTargetType();
14841485
auto &Mod = Inst->getModule();
1486+
auto *F = Inst->getFunction();
14851487

14861488
bool isSourceTypeExact = isa<MetatypeInst>(Src);
14871489

@@ -1503,7 +1505,7 @@ SILInstruction *CastOptimizer::optimizeUnconditionalCheckedCastAddrInst(
15031505
// mem2reg's invariants get unhappy if we don't try to
15041506
// initialize a loadable result.
15051507
auto DestType = Dest->getType();
1506-
auto &resultTL = Mod.Types.getTypeLowering(DestType);
1508+
auto &resultTL = F->getTypeLowering(DestType);
15071509
if (!resultTL.isAddressOnly()) {
15081510
auto undef = SILValue(
15091511
SILUndef::get(DestType.getObjectType(), Builder.getModule()));

0 commit comments

Comments
 (0)