Skip to content

Commit 5847e16

Browse files
committed
SIL: Use better type lowering APIs in a couple of spots
1 parent bb97dbf commit 5847e16

File tree

12 files changed

+55
-48
lines changed

12 files changed

+55
-48
lines changed

lib/IRGen/GenKeyPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ emitKeyPathComponent(IRGenModule &IGM,
11501150
case KeyPathPatternComponent::Kind::TupleElement:
11511151
assert(baseTy->is<TupleType>() && "not a tuple");
11521152

1153-
SILType loweredTy = IGM.getSILTypes().getLoweredType(baseTy);
1153+
SILType loweredTy = IGM.getLoweredType(baseTy);
11541154

11551155
// Tuple with fixed layout
11561156
//

lib/SIL/SILFunctionType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,10 @@ class DestructureInputs {
627627
return false;
628628

629629
auto foreignErrorTy =
630-
M.Types.getLoweredType(Foreign.Error->getErrorParameterType());
630+
M.Types.getLoweredRValueType(Foreign.Error->getErrorParameterType());
631631

632632
// Assume the error parameter doesn't have interesting lowering.
633-
Inputs.push_back(SILParameterInfo(foreignErrorTy.getASTType(),
633+
Inputs.push_back(SILParameterInfo(foreignErrorTy,
634634
ParameterConvention::Direct_Unowned));
635635
NextOrigParamIndex++;
636636
return true;

lib/SIL/SILVerifier.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,14 @@ void verifyKeyPathComponent(SILModule &M,
128128
bool forPropertyDescriptor,
129129
bool hasIndices) {
130130
auto &C = M.getASTContext();
131-
131+
132+
auto opaque = AbstractionPattern::getOpaque();
132133
auto loweredBaseTy =
133-
M.Types.getLoweredType(AbstractionPattern::getOpaque(), baseTy);
134+
M.Types.getLoweredType(opaque, baseTy, expansion);
134135
auto componentTy = component.getComponentType().subst(patternSubs)
135136
->getCanonicalType();
136137
auto loweredComponentTy =
137-
M.Types.getLoweredType(AbstractionPattern::getOpaque(), componentTy);
138+
M.Types.getLoweredType(opaque, componentTy, expansion);
138139

139140
auto checkIndexEqualsAndHash = [&]{
140141
if (!component.getSubscriptIndices().empty()) {
@@ -386,15 +387,14 @@ void verifyKeyPathComponent(SILModule &M,
386387
require(loweredBaseTy.is<TupleType>(),
387388
"invalid baseTy, should have been a TupleType");
388389

389-
auto tupleTy = loweredBaseTy.getAs<TupleType>();
390+
auto tupleTy = loweredBaseTy.castTo<TupleType>();
390391
auto eltIdx = component.getTupleIndex();
391392

392393
require(eltIdx < tupleTy->getNumElements(),
393394
"invalid element index, greater than # of tuple elements");
394395

395-
auto eltTy = tupleTy->getElementType(eltIdx)
396-
->getReferenceStorageReferent()
397-
->getCanonicalType();
396+
auto eltTy = tupleTy.getElementType(eltIdx)
397+
.getReferenceStorageReferent();
398398

399399
require(eltTy == componentTy,
400400
"tuple element type should match the type of the component");

lib/SILGen/SILGenExpr.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,28 +2698,26 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
26982698
: nullptr;
26992699

27002700
// Build the signature of the thunk as expected by the keypath runtime.
2701-
SILType loweredBaseTy, loweredPropTy;
2701+
CanType loweredBaseTy, loweredPropTy;
27022702
{
27032703
GenericContextScope scope(SGM.Types, genericSig);
2704-
loweredBaseTy = SGM.Types.getLoweredType(AbstractionPattern::getOpaque(),
2705-
baseType);
2706-
loweredPropTy = SGM.Types.getLoweredType(AbstractionPattern::getOpaque(),
2707-
propertyType);
2704+
AbstractionPattern opaque = AbstractionPattern::getOpaque();
2705+
2706+
loweredBaseTy = SGM.Types.getLoweredRValueType(opaque, baseType);
2707+
loweredPropTy = SGM.Types.getLoweredRValueType(opaque, propertyType);
27082708
}
27092709

27102710
auto paramConvention = ParameterConvention::Indirect_In_Guaranteed;
27112711

27122712
SmallVector<SILParameterInfo, 2> params;
2713-
params.push_back({loweredBaseTy.getASTType(),
2714-
paramConvention});
2713+
params.push_back({loweredBaseTy, paramConvention});
27152714
auto &C = SGM.getASTContext();
27162715
if (!indexes.empty())
27172716
params.push_back({C.getUnsafeRawPointerDecl()->getDeclaredType()
27182717
->getCanonicalType(),
27192718
ParameterConvention::Direct_Unowned});
27202719

2721-
SILResultInfo result(loweredPropTy.getASTType(),
2722-
ResultConvention::Indirect);
2720+
SILResultInfo result(loweredPropTy, ResultConvention::Indirect);
27232721

27242722
auto signature = SILFunctionType::get(genericSig,
27252723
SILFunctionType::ExtInfo(SILFunctionType::Representation::Thin,
@@ -2828,13 +2826,13 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
28282826
: nullptr;
28292827

28302828
// Build the signature of the thunk as expected by the keypath runtime.
2831-
SILType loweredBaseTy, loweredPropTy;
2829+
CanType loweredBaseTy, loweredPropTy;
28322830
{
28332831
GenericContextScope scope(SGM.Types, genericSig);
2834-
loweredBaseTy = SGM.Types.getLoweredType(AbstractionPattern::getOpaque(),
2835-
baseType);
2836-
loweredPropTy = SGM.Types.getLoweredType(AbstractionPattern::getOpaque(),
2837-
propertyType);
2832+
AbstractionPattern opaque = AbstractionPattern::getOpaque();
2833+
2834+
loweredBaseTy = SGM.Types.getLoweredRValueType(opaque, baseType);
2835+
loweredPropTy = SGM.Types.getLoweredRValueType(opaque, propertyType);
28382836
}
28392837

28402838
auto &C = SGM.getASTContext();
@@ -2843,10 +2841,9 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
28432841

28442842
SmallVector<SILParameterInfo, 3> params;
28452843
// property value
2846-
params.push_back({loweredPropTy.getASTType(),
2847-
paramConvention});
2844+
params.push_back({loweredPropTy, paramConvention});
28482845
// base
2849-
params.push_back({loweredBaseTy.getASTType(),
2846+
params.push_back({loweredBaseTy,
28502847
property->isSetterMutating()
28512848
? ParameterConvention::Indirect_Inout
28522849
: paramConvention});
@@ -3007,7 +3004,10 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
30073004
->getCanonicalType();
30083005
RValue indexValue(indexTupleTy);
30093006

3010-
auto indexLoweredTy = SGM.Types.getLoweredType(indexTupleTy);
3007+
auto indexLoweredTy =
3008+
SILType::getPrimitiveAddressType(
3009+
SGM.Types.getLoweredRValueType(indexTupleTy));
3010+
30113011
// Get or create the equals witness
30123012
[unsafeRawPointerTy, boolTy, genericSig, &C, &indexTypes, &equals, loc,
30133013
&SGM, genericEnv, expansion, indexLoweredTy, indexes]{
@@ -3052,10 +3052,10 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
30523052
Scope scope(subSGF, loc);
30533053

30543054
auto lhsAddr = subSGF.B.createPointerToAddress(loc, lhsPtr,
3055-
indexLoweredTy.getAddressType(),
3055+
indexLoweredTy,
30563056
/*isStrict*/ false);
30573057
auto rhsAddr = subSGF.B.createPointerToAddress(loc, rhsPtr,
3058-
indexLoweredTy.getAddressType(),
3058+
indexLoweredTy,
30593059
/*isStrict*/ false);
30603060

30613061
// Compare each pair of index values using the == witness from the
@@ -3229,7 +3229,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
32293229

32303230
// Extract the index value.
32313231
SILValue indexAddr = subSGF.B.createPointerToAddress(loc, indexPtr,
3232-
indexLoweredTy.getAddressType(),
3232+
indexLoweredTy,
32333233
/*isStrict*/ false);
32343234
if (indexes.size() > 1) {
32353235
indexAddr = subSGF.B.createTupleElementAddr(loc, indexAddr, 0);

lib/SILOptimizer/Analysis/ArraySemantic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ bool swift::ArraySemanticsCall::replaceByValue(SILValue V) {
694694
return false;
695695

696696
SILBuilderWithScope Builder(SemanticsCall);
697-
auto &ValLowering = Builder.getModule().getTypeLowering(V->getType());
697+
auto &ValLowering = Builder.getTypeLowering(V->getType());
698698
if (hasGetElementDirectResult()) {
699699
ValLowering.emitCopyValue(Builder, SemanticsCall->getLoc(), V);
700700
SemanticsCall->replaceAllUsesWith(V);
@@ -756,7 +756,7 @@ bool swift::ArraySemanticsCall::replaceByAppendingValues(
756756

757757
for (SILValue V : Vals) {
758758
auto SubTy = V->getType();
759-
auto &ValLowering = Builder.getModule().getTypeLowering(SubTy);
759+
auto &ValLowering = Builder.getTypeLowering(SubTy);
760760
auto CopiedVal = ValLowering.emitCopyValue(Builder, Loc, V);
761761
auto *AllocStackInst = Builder.createAllocStack(Loc, SubTy);
762762

lib/SILOptimizer/IPO/CapturePromotion.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,7 @@ ClosureCloner::visitStrongReleaseInst(StrongReleaseInst *Inst) {
544544
if (I != BoxArgumentMap.end()) {
545545
// Releases of the box arguments get replaced with ReleaseValue of the new
546546
// object type argument.
547-
SILFunction &F = getBuilder().getFunction();
548-
auto &typeLowering = F.getModule().getTypeLowering(I->second->getType());
547+
auto &typeLowering = getBuilder().getTypeLowering(I->second->getType());
549548
SILBuilderWithPostProcess<ClosureCloner, 1> B(this, Inst);
550549
typeLowering.emitDestroyValue(B, Inst->getLoc(), I->second);
551550
return;
@@ -567,7 +566,7 @@ void ClosureCloner::visitDestroyValueInst(DestroyValueInst *Inst) {
567566
// Releases of the box arguments get replaced with an end_borrow,
568567
// destroy_value of the new object type argument.
569568
SILFunction &F = getBuilder().getFunction();
570-
auto &typeLowering = F.getModule().getTypeLowering(I->second->getType());
569+
auto &typeLowering = F.getTypeLowering(I->second->getType());
571570
SILBuilderWithPostProcess<ClosureCloner, 1> B(this, Inst);
572571

573572
SILValue Value = I->second;
@@ -1240,6 +1239,7 @@ static SILFunction *
12401239
processPartialApplyInst(SILOptFunctionBuilder &FuncBuilder,
12411240
PartialApplyInst *PAI, IndicesSet &PromotableIndices,
12421241
SmallVectorImpl<SILFunction*> &Worklist) {
1242+
SILFunction *F = PAI->getFunction();
12431243
SILModule &M = PAI->getModule();
12441244

12451245
auto *FRI = dyn_cast<FunctionRefInst>(PAI->getCallee());
@@ -1284,7 +1284,7 @@ processPartialApplyInst(SILOptFunctionBuilder &FuncBuilder,
12841284
SILValue Box = PAI->getOperand(OpNo);
12851285
SILValue Addr = getOrCreateProjectBoxHelper(Box);
12861286

1287-
auto &typeLowering = M.getTypeLowering(Addr->getType());
1287+
auto &typeLowering = F->getTypeLowering(Addr->getType());
12881288
auto newCaptured =
12891289
typeLowering.emitLoadOfCopy(B, PAI->getLoc(), Addr, IsNotTake);
12901290
Args.push_back(newCaptured);

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ void ApplyRewriter::canonicalizeResults(
841841
}
842842
SILBuilder B(destroyInst);
843843
B.setSILConventions(SILModuleConventions::getLoweredAddressConventions());
844-
auto &TL = pass.F->getModule().getTypeLowering(result->getType());
844+
auto &TL = pass.F->getTypeLowering(result->getType());
845845
TL.emitDestroyValue(B, destroyInst->getLoc(), result);
846846
}
847847
destroyInst->eraseFromParent();

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,9 @@ void AvailableValueDataflowContext::explodeCopyAddr(CopyAddrInst *CAI) {
11541154
LLVM_DEBUG(llvm::dbgs() << " -- Exploding copy_addr: " << *CAI << "\n");
11551155

11561156
SILType ValTy = CAI->getDest()->getType().getObjectType();
1157-
auto &TL = getModule().getTypeLowering(ValTy);
1157+
1158+
SILFunction *F = CAI->getFunction();
1159+
auto &TL = F->getTypeLowering(ValTy);
11581160

11591161
// Keep track of the new instructions emitted.
11601162
SmallVector<SILInstruction *, 4> NewInsts;

lib/SILOptimizer/Transforms/AllocBoxToStack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
452452

453453
assert(ABI->getBoxType()->getLayout()->getFields().size() == 1
454454
&& "promoting multi-field box not implemented");
455-
auto &Lowering = ABI->getModule()
456-
.getTypeLowering(ABI->getBoxType()->getFieldType(ABI->getModule(), 0));
455+
auto &Lowering = ABI->getFunction()
456+
->getTypeLowering(ABI->getBoxType()->getFieldType(ABI->getModule(), 0));
457457
auto Loc = CleanupLocation::get(ABI->getLoc());
458458

459459
for (auto LastRelease : FinalReleases) {

lib/SILOptimizer/Transforms/SILLowerAggregateInstrs.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ STATISTIC(NumExpand, "Number of instructions expanded");
7272
/// store %new to %1 : $*T
7373
static bool expandCopyAddr(CopyAddrInst *CA) {
7474
SILModule &M = CA->getModule();
75+
SILFunction *F = CA->getFunction();
7576
SILValue Source = CA->getSrc();
7677

7778
// If we have an address only type don't do anything.
@@ -95,7 +96,7 @@ static bool expandCopyAddr(CopyAddrInst *CA) {
9596
// If our object type is not trivial, we may need to release the old value and
9697
// retain the new one.
9798

98-
auto &TL = M.getTypeLowering(SrcType);
99+
auto &TL = F->getTypeLowering(SrcType);
99100

100101
// If we have a non-trivial type...
101102
if (!TL.isTrivial()) {
@@ -136,6 +137,7 @@ static bool expandCopyAddr(CopyAddrInst *CA) {
136137
}
137138

138139
static bool expandDestroyAddr(DestroyAddrInst *DA) {
140+
SILFunction *F = DA->getFunction();
139141
SILModule &Module = DA->getModule();
140142
SILBuilderWithScope Builder(DA);
141143

@@ -155,7 +157,7 @@ static bool expandDestroyAddr(DestroyAddrInst *DA) {
155157
// If we have a type with reference semantics, emit a load/strong release.
156158
LoadInst *LI = Builder.createLoad(DA->getLoc(), Addr,
157159
LoadOwnershipQualifier::Unqualified);
158-
auto &TL = Module.getTypeLowering(Type);
160+
auto &TL = F->getTypeLowering(Type);
159161
using TypeExpansionKind = Lowering::TypeLowering::TypeExpansionKind;
160162
auto expansionKind = expand ? TypeExpansionKind::MostDerivedDescendents
161163
: TypeExpansionKind::None;
@@ -167,6 +169,7 @@ static bool expandDestroyAddr(DestroyAddrInst *DA) {
167169
}
168170

169171
static bool expandReleaseValue(ReleaseValueInst *DV) {
172+
SILFunction *F = DV->getFunction();
170173
SILModule &Module = DV->getModule();
171174
SILBuilderWithScope Builder(DV);
172175

@@ -183,7 +186,7 @@ static bool expandReleaseValue(ReleaseValueInst *DV) {
183186
if (!shouldExpand(Module, Type.getObjectType()))
184187
return false;
185188

186-
auto &TL = Module.getTypeLowering(Type);
189+
auto &TL = F->getTypeLowering(Type);
187190
TL.emitLoweredDestroyValueMostDerivedDescendents(Builder, DV->getLoc(),
188191
Value);
189192

@@ -194,6 +197,7 @@ static bool expandReleaseValue(ReleaseValueInst *DV) {
194197
}
195198

196199
static bool expandRetainValue(RetainValueInst *CV) {
200+
SILFunction *F = CV->getFunction();
197201
SILModule &Module = CV->getModule();
198202
SILBuilderWithScope Builder(CV);
199203

@@ -210,7 +214,7 @@ static bool expandRetainValue(RetainValueInst *CV) {
210214
if (!shouldExpand(Module, Type.getObjectType()))
211215
return false;
212216

213-
auto &TL = Module.getTypeLowering(Type);
217+
auto &TL = F->getTypeLowering(Type);
214218
TL.emitLoweredCopyValueMostDerivedDescendents(Builder, CV->getLoc(), Value);
215219

216220
LLVM_DEBUG(llvm::dbgs() << " Expanding Copy Value: " << *CV);

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ static void replaceDestroy(DestroyAddrInst *DAI, SILValue NewValue) {
376376
SILBuilderWithScope Builder(DAI);
377377

378378
auto Ty = DAI->getOperand()->getType();
379-
auto &TL = DAI->getModule().getTypeLowering(Ty);
379+
SILFunction *F = DAI->getFunction();
380+
auto &TL = F->getTypeLowering(Ty);
380381

381382
bool expand = shouldExpand(DAI->getModule(),
382383
DAI->getOperand()->getType().getObjectType());

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ SILInstruction *CastOptimizer::simplifyCheckedCastAddrBranchInst(
705705

706706
if (Feasibility == DynamicCastFeasibility::WillFail) {
707707
if (shouldDestroyOnFailure(Inst->getConsumptionKind())) {
708-
auto &srcTL = Builder.getModule().getTypeLowering(Src->getType());
708+
auto &srcTL = Builder.getTypeLowering(Src->getType());
709709
srcTL.emitDestroyAddress(Builder, Loc, Src);
710710
}
711711
auto NewI = Builder.createBranch(Loc, FailureBB);
@@ -748,7 +748,7 @@ SILInstruction *CastOptimizer::simplifyCheckedCastAddrBranchInst(
748748
// is not used afterwards.
749749
if (ResultNotUsed) {
750750
if (shouldTakeOnSuccess(Inst->getConsumptionKind())) {
751-
auto &srcTL = Builder.getModule().getTypeLowering(Src->getType());
751+
auto &srcTL = Builder.getTypeLowering(Src->getType());
752752
srcTL.emitDestroyAddress(Builder, Loc, Src);
753753
}
754754
EraseInstAction(Inst);

0 commit comments

Comments
 (0)