Skip to content

Commit 2907c61

Browse files
committed
SILModule::hasLoweredAddress
1 parent 8457ba3 commit 2907c61

File tree

9 files changed

+39
-25
lines changed

9 files changed

+39
-25
lines changed

include/swift/SIL/SILModule.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ class SILModule {
307307
/// The stage of processing this module is at.
308308
SILStage Stage;
309309

310+
/// True if SIL conventions force address-only to be passed by address.
311+
///
312+
/// Used for bootstrapping the AddressLowering pass. This should eventually
313+
/// be inferred from the SIL stage to be true only when Stage == Lowered.
314+
bool loweredAddresses;
315+
310316
/// The set of deserialization notification handlers.
311317
DeserializationNotificationHandlerSet deserializationNotificationHandlers;
312318

@@ -796,6 +802,11 @@ class SILModule {
796802
Stage = s;
797803
}
798804

805+
/// True if SIL conventions force address-only to be passed by address.
806+
bool useLoweredAddresses() const { return loweredAddresses; }
807+
808+
void setLoweredAddresses(bool val) { loweredAddresses = val; }
809+
799810
llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
800811

801812
void setPGOReader(std::unique_ptr<llvm::IndexedInstrProfReader> IPR) {
@@ -962,15 +973,13 @@ inline bool SILOptions::supportsLexicalLifetimes(const SILModule &mod) const {
962973
// entirely.
963974
return LexicalLifetimes != LexicalLifetimesOption::Off;
964975
case SILStage::Canonical:
976+
case SILStage::Lowered:
965977
// In Canonical SIL, lexical markers are used to ensure that object
966978
// lifetimes do not get observably shortened from the end of a lexical
967979
// scope. That behavior only occurs when lexical lifetimes is (fully)
968980
// enabled. (When only diagnostic markers are enabled, the markers are
969981
// stripped as part of lowering from raw to canonical SIL.)
970982
return LexicalLifetimes == LexicalLifetimesOption::On;
971-
case SILStage::Lowered:
972-
// We do not support OSSA in Lowered SIL, so this is always false.
973-
return false;
974983
}
975984
}
976985

lib/SIL/IR/SILModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ class SILModule::SerializationCallback final
9191

9292
SILModule::SILModule(llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
9393
Lowering::TypeConverter &TC, const SILOptions &Options)
94-
: Stage(SILStage::Raw), indexTrieRoot(new IndexTrieNode()),
95-
Options(Options), serialized(false),
94+
: Stage(SILStage::Raw), loweredAddresses(!Options.EnableSILOpaqueValues),
95+
indexTrieRoot(new IndexTrieNode()), Options(Options), serialized(false),
9696
regDeserializationNotificationHandlerForNonTransparentFuncOME(false),
9797
regDeserializationNotificationHandlerForAllFuncOME(false),
9898
prespecializedFunctionDeclsImported(false), SerializeSILAction(),

lib/SIL/IR/SILType.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,7 @@ SILResultInfo::getOwnershipKind(SILFunction &F,
506506
}
507507

508508
SILModuleConventions::SILModuleConventions(SILModule &M)
509-
: M(&M),
510-
loweredAddresses(!M.getOptions().EnableSILOpaqueValues
511-
|| M.getStage() == SILStage::Lowered)
512-
{}
509+
: M(&M), loweredAddresses(M.useLoweredAddresses()) {}
513510

514511
bool SILModuleConventions::isReturnedIndirectlyInSIL(SILType type,
515512
SILModule &M) {

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6533,6 +6533,9 @@ bool SILParserState::parseDeclSILStage(Parser &P) {
65336533
}
65346534

65356535
M.setStage(stage);
6536+
if (M.getOptions().EnableSILOpaqueValues) {
6537+
M.setLoweredAddresses(stage != SILStage::Raw);
6538+
}
65366539
DidParseSILStage = true;
65376540
return false;
65386541
}

lib/SILGen/SILGenFunction.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,12 @@ void SILGenFunction::emitCaptures(SILLocation loc,
290290
// Get an address value for a SILValue if it is address only in an type
291291
// expansion context without opaque archetype substitution.
292292
auto getAddressValue = [&](SILValue entryValue) -> SILValue {
293-
if (SGM.Types
294-
.getTypeLowering(
295-
valueType,
296-
TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(
297-
expansion.getResilienceExpansion()))
298-
.isAddressOnly() &&
299-
!entryValue->getType().isAddress()) {
293+
if (SGM.Types.getTypeLowering(
294+
valueType,
295+
TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(
296+
expansion.getResilienceExpansion()))
297+
.isAddressOnly()
298+
&& !entryValue->getType().isAddress()) {
300299

301300
auto addr = emitTemporaryAllocation(vd, entryValue->getType());
302301
auto val = B.emitCopyValueOperation(vd, entryValue);

lib/SILGen/SILGenFunction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
245245
/// The SILModuleConventions for this SIL module.
246246
SILModuleConventions silConv;
247247

248+
bool useLoweredAddresses() const { return silConv.useLoweredAddresses(); }
249+
248250
/// The DeclContext corresponding to the function currently being emitted.
249251
DeclContext * const FunctionDC;
250252

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,13 +1527,15 @@ void AddressLowering::runOnFunction(SILFunction *F) {
15271527

15281528
/// The entry point to this function transformation.
15291529
void AddressLowering::run() {
1530-
if (getModule()->getOptions().EnableSILOpaqueValues) {
1531-
for (auto &F : *getModule())
1532-
runOnFunction(&F);
1530+
if (getModule()->useLoweredAddresses())
1531+
return;
1532+
1533+
for (auto &F : *getModule()) {
1534+
runOnFunction(&F);
15331535
}
1534-
// Set the SIL state before the PassManager has a chance to run
1536+
// Update the SILModule before the PassManager has a chance to run
15351537
// verification.
1536-
getModule()->setStage(SILStage::Lowered);
1538+
getModule()->setLoweredAddresses(true);
15371539
}
15381540

15391541
SILTransform *swift::createAddressLowering() { return new AddressLowering(); }

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ static void addModulePrinterPipeline(SILPassPipelinePlan &plan,
8787

8888
static void addMandatoryDebugSerialization(SILPassPipelinePlan &P) {
8989
P.startPipeline("Mandatory Debug Serialization");
90+
P.addAddressLowering();
9091
P.addOwnershipModelEliminator();
9192
P.addMandatoryInlining();
9293
}
9394

9495
static void addOwnershipModelEliminatorPipeline(SILPassPipelinePlan &P) {
9596
P.startPipeline("Ownership Model Eliminator");
97+
P.addAddressLowering();
9698
P.addOwnershipModelEliminator();
9799
}
98100

@@ -113,6 +115,7 @@ static void addDefiniteInitialization(SILPassPipelinePlan &P) {
113115
static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
114116
P.startPipeline("Mandatory Diagnostic Passes + Enabling Optimization Passes");
115117
P.addSILGenCleanup();
118+
P.addAddressLowering();
116119
P.addDiagnoseInvalidEscapingCaptures();
117120
P.addDiagnoseStaticExclusivity();
118121
P.addNestedSemanticFunctionCheck();
@@ -796,11 +799,10 @@ static void addSILDebugInfoGeneratorPipeline(SILPassPipelinePlan &P) {
796799
SILPassPipelinePlan
797800
SILPassPipelinePlan::getLoweringPassPipeline(const SILOptions &Options) {
798801
SILPassPipelinePlan P(Options);
799-
P.startPipeline("Address Lowering");
802+
P.startPipeline("Lowering");
800803
P.addLowerHopToActor(); // FIXME: earlier for more opportunities?
801804
P.addOwnershipModelEliminator();
802805
P.addIRGenPrepare();
803-
P.addAddressLowering();
804806

805807
return P;
806808
}
@@ -913,7 +915,7 @@ SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) {
913915
// depend on other passes needed for diagnostics). Thus we can run them later
914916
// and avoid having SourceKit run these passes when just emitting diagnostics
915917
// in the editor.
916-
P.startPipeline("non-Diagnostic Enabling Mandatory Optimizations");
918+
P.startPipeline("Non-Diagnostic Mandatory Optimizations");
917919
P.addForEachLoopUnroll();
918920
P.addMandatoryCombine();
919921

lib/SILOptimizer/PassManager/Passes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void swift::runSILLoweringPasses(SILModule &Module) {
213213
SILPassPipelinePlan::getLoweringPassPipeline(opts),
214214
/*isMandatory*/ true);
215215

216-
assert(Module.getStage() == SILStage::Lowered);
216+
Module.setStage(SILStage::Lowered);
217217
}
218218

219219
/// Registered briged pass run functions.

0 commit comments

Comments
 (0)