Skip to content

Commit fa64a36

Browse files
committed
Add -Xfrontend -enable-address-dependencies
Temporary option to bootstrap '@'_addressable enforcement. Once all the SILGen cases are handled, we won't need this option.
1 parent 1b51aa8 commit fa64a36

File tree

8 files changed

+29
-1
lines changed

8 files changed

+29
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceInsertion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private extension LifetimeDependentApply.LifetimeSourceInfo {
218218
bases.append(source.value)
219219
case .result, .inParameter, .inoutParameter:
220220
// addressable dependencies directly depend on the incoming address.
221-
if source.convention.isAddressable {
221+
if context.options.enableAddressDependencies() && source.convention.isAddressable {
222222
bases.append(source.value)
223223
return
224224
}

SwiftCompilerSources/Sources/Optimizer/PassManager/Options.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ struct Options {
3232
_bridged.enableSimplificationFor(inst.bridged)
3333
}
3434

35+
func enableAddressDependencies() -> Bool {
36+
_bridged.enableAddressDependencies()
37+
}
38+
3539
var enableEmbeddedSwift: Bool {
3640
_bridged.hasFeature(.Embedded)
3741
}

include/swift/AST/SILOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ class SILOptions {
331331
/// optimizer.
332332
bool UseAggressiveReg2MemForCodeSize = true;
333333

334+
/// Enable enforcement of lifetime dependencies on addressable arguments.
335+
/// Temporarily used to bootstrap the AddressableParameters feature.
336+
bool EnableAddressDependencies = false;
337+
334338
SILOptions() {}
335339

336340
/// Return a hash code of any components from these options that should

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,9 @@ def platform_availability_inheritance_map_path
14891489
: Separate<["-"], "platform-availability-inheritance-map-path">, MetaVarName<"<path>">,
14901490
HelpText<"Path of the platform inheritance platform map">;
14911491

1492+
def enable_address_dependencies : Flag<["-"], "enable-address-dependencies">,
1493+
HelpText<"Enable enforcement of lifetime dependencies on addressable values.">;
1494+
14921495
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]
14931496

14941497
def disable_experimental_parser_round_trip : Flag<["-"],

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ struct BridgedPassContext {
382382
bool enableSimplificationFor(BridgedInstruction inst) const;
383383
BRIDGED_INLINE bool enableWMORequiredDiagnostics() const;
384384

385+
// Temporary for AddressableParameters Bootstrapping.
386+
BRIDGED_INLINE bool enableAddressDependencies() const;
387+
385388
// Closure specializer
386389
SWIFT_IMPORT_UNSAFE BridgedFunction ClosureSpecializer_createEmptyFunctionWithSpecializedSignature(BridgedStringRef specializedName,
387390
const BridgedParameterInfo * _Nullable specializedBridgedParams,

include/swift/SILOptimizer/OptimizerBridgingImpl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ bool BridgedPassContext::enableWMORequiredDiagnostics() const {
573573
return mod->getOptions().EnableWMORequiredDiagnostics;
574574
}
575575

576+
bool BridgedPassContext::enableAddressDependencies() const {
577+
swift::SILModule *mod = invocation->getPassManager()->getModule();
578+
return mod->getOptions().EnableAddressDependencies;
579+
}
580+
576581
static_assert((int)BridgedPassContext::SILStage::Raw == (int)swift::SILStage::Raw);
577582
static_assert((int)BridgedPassContext::SILStage::Canonical == (int)swift::SILStage::Canonical);
578583
static_assert((int)BridgedPassContext::SILStage::Lowered == (int)swift::SILStage::Lowered);

lib/DriverTool/sil_opt_main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,10 @@ struct SILOptOptions {
592592
"swift-version",
593593
llvm::cl::desc(
594594
"The swift version to assume AST declarations correspond to"));
595+
596+
llvm::cl::opt<bool> EnableAddressDependencies = llvm::cl::opt<bool>(
597+
"enable-address-dependencies",
598+
llvm::cl::desc("Enable enforcement of lifetime dependencies on addressable values."));
595599
};
596600

597601
/// Regular expression corresponding to the value given in one of the
@@ -909,6 +913,8 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
909913
SILOpts.EnablePackMetadataStackPromotion =
910914
options.EnablePackMetadataStackPromotion;
911915

916+
SILOpts.EnableAddressDependencies = options.EnableAddressDependencies;
917+
912918
if (options.OptModeFlag == OptimizationMode::NotSet) {
913919
if (options.OptimizationGroup == OptGroup::Diagnostics)
914920
SILOpts.OptMode = OptimizationMode::NoOptimization;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,6 +3013,9 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
30133013
Opts.ShouldFunctionsBePreservedToDebugger &=
30143014
LTOKind.value() == IRGenLLVMLTOKind::None;
30153015

3016+
3017+
Opts.EnableAddressDependencies = Args.hasArg(OPT_enable_address_dependencies);
3018+
30163019
return false;
30173020
}
30183021

0 commit comments

Comments
 (0)