From 6629479a0e73d7752ad9fe710456c3d351847537 Mon Sep 17 00:00:00 2001 From: Mike Ash Date: Fri, 12 Dec 2025 12:53:31 -0500 Subject: [PATCH] [IRGen] Add a CMake option to configure direct retain/release enablement. The SWIFT_ENABLE_DIRECT_RETAIN_RELEASE option controls the default value of the option to enable direct retain/release. It's off by default, meaning direct RR is off by default. Setting SWIFT_ENABLE_DIRECT_RETAIN_RELEASE to true will build a compiler where direct RR is on by default. rdar://163568311 --- CMakeLists.txt | 4 ++++ include/swift/AST/IRGenOptions.h | 4 ++-- include/swift/Config.h.in | 2 ++ lib/Frontend/CompilerInvocation.cpp | 4 ++-- lib/IRGen/GenHeap.cpp | 8 ++++---- lib/IRGen/IRGenModule.cpp | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 226a44c938768..e2f99768ab142 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -804,6 +804,10 @@ option(SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION "Enable experimental SwiftParser validation by default" FALSE) +option(SWIFT_ENABLE_DIRECT_RETAIN_RELEASE + "Enable use of direct refcounting calls by default" + FALSE) + cmake_dependent_option(SWIFT_BUILD_SOURCEKIT "Build SourceKit" TRUE "SWIFT_ENABLE_DISPATCH" FALSE) diff --git a/include/swift/AST/IRGenOptions.h b/include/swift/AST/IRGenOptions.h index ced3dc4cb38c6..baa2261b156e9 100644 --- a/include/swift/AST/IRGenOptions.h +++ b/include/swift/AST/IRGenOptions.h @@ -560,7 +560,7 @@ class IRGenOptions { unsigned MergeableTraps : 1; /// Enable the use of swift_retain/releaseDirect functions. - unsigned EnableSwiftDirectRuntime : 1; + unsigned EnableSwiftDirectRetainRelease : 1; /// The number of threads for multi-threaded code generation. unsigned NumThreads = 0; @@ -689,7 +689,7 @@ class IRGenOptions { EmitAsyncFramePushPopMetadata(true), EmitTypeMallocForCoroFrame(true), AsyncFramePointerAll(false), UseProfilingMarkerThunks(false), UseCoroCCX8664(false), UseCoroCCArm64(false), MergeableTraps(false), - EnableSwiftDirectRuntime(false), + EnableSwiftDirectRetainRelease(SWIFT_ENABLE_DIRECT_RETAIN_RELEASE), DebugInfoForProfiling(false), CmdArgs(), SanitizeCoverage(llvm::SanitizerCoverageOptions()), TypeInfoFilter(TypeInfoDumpFilter::All), diff --git a/include/swift/Config.h.in b/include/swift/Config.h.in index 1884d0f95bcca..fa1e95007411d 100644 --- a/include/swift/Config.h.in +++ b/include/swift/Config.h.in @@ -16,4 +16,6 @@ #cmakedefine01 SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION +#cmakedefine01 SWIFT_ENABLE_DIRECT_RETAIN_RELEASE + #endif // SWIFT_CONFIG_H diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index c9a50ebd3cfb7..357233fe0b0d3 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -4034,10 +4034,10 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args, Opts.MergeableTraps = Args.hasArg(OPT_mergeable_traps); - Opts.EnableSwiftDirectRuntime = + Opts.EnableSwiftDirectRetainRelease = Args.hasFlag(OPT_enable_direct_retain_release, OPT_disable_direct_retain_release, - Opts.EnableSwiftDirectRuntime); + Opts.EnableSwiftDirectRetainRelease); Opts.EnableObjectiveCProtocolSymbolicReferences = Args.hasFlag(OPT_enable_objective_c_protocol_symbolic_references, diff --git a/lib/IRGen/GenHeap.cpp b/lib/IRGen/GenHeap.cpp index 111077347f1c0..5aad98ecfd9aa 100644 --- a/lib/IRGen/GenHeap.cpp +++ b/lib/IRGen/GenHeap.cpp @@ -1000,7 +1000,7 @@ void IRGenFunction::emitNativeStrongRetain(llvm::Value *value, FunctionPointer function; if (atomicity == Atomicity::Atomic && IGM.TargetInfo.HasSwiftSwiftDirectRuntimeLibrary && - getOptions().EnableSwiftDirectRuntime) + getOptions().EnableSwiftDirectRetainRelease) function = IGM.getNativeStrongRetainDirectFunctionPointer(); else if (atomicity == Atomicity::Atomic) function = IGM.getNativeStrongRetainFunctionPointer(); @@ -1265,7 +1265,7 @@ void IRGenFunction::emitNativeStrongRelease(llvm::Value *value, llvm::Constant *function; if (atomicity == Atomicity::Atomic && IGM.TargetInfo.HasSwiftSwiftDirectRuntimeLibrary && - getOptions().EnableSwiftDirectRuntime) + getOptions().EnableSwiftDirectRetainRelease) function = IGM.getNativeStrongReleaseDirectFn(); else if (atomicity == Atomicity::Atomic) function = IGM.getNativeStrongReleaseFn(); @@ -1373,7 +1373,7 @@ void IRGenFunction::emitBridgeStrongRetain(llvm::Value *value, llvm::Constant *function; if (atomicity == Atomicity::Atomic && IGM.TargetInfo.HasSwiftSwiftDirectRuntimeLibrary && - getOptions().EnableSwiftDirectRuntime) + getOptions().EnableSwiftDirectRetainRelease) function = IGM.getBridgeObjectStrongRetainDirectFn(); else if (atomicity == Atomicity::Atomic) function = IGM.getBridgeObjectStrongRetainFn(); @@ -1387,7 +1387,7 @@ void IRGenFunction::emitBridgeStrongRelease(llvm::Value *value, llvm::Constant *function; if (atomicity == Atomicity::Atomic && IGM.TargetInfo.HasSwiftSwiftDirectRuntimeLibrary && - getOptions().EnableSwiftDirectRuntime) + getOptions().EnableSwiftDirectRetainRelease) function = IGM.getBridgeObjectStrongReleaseDirectFn(); else if (atomicity == Atomicity::Atomic) function = IGM.getBridgeObjectStrongReleaseFn(); diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index 326a132bc5eb8..f878b2a8751f2 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -1743,7 +1743,7 @@ void IRGenModule::addLinkLibraries() { LinkLibrary{"objc", LibraryKind::Library, /*static=*/false}); if (TargetInfo.HasSwiftSwiftDirectRuntimeLibrary && - getOptions().EnableSwiftDirectRuntime) + getOptions().EnableSwiftDirectRetainRelease) registerLinkLibrary(LinkLibrary{"swiftSwiftDirectRuntime", LibraryKind::Library, /*static=*/true});