Skip to content

Commit f670c5a

Browse files
committed
Add a new frontend flag -fswift-async-fp={auto|always|never}
Summary: Introduce a new frontend flag `-fswift-async-fp={auto|always|never}` that controls how code generation sets the Swift extended async frame info bit. There are three possibilities: * `auto`: which determines how to set the bit based on deployment target, either statically or dynamically via `swift_async_extendedFramePointerFlags`. * `always`: default, always set the bit statically, regardless of deployment target. * `never`: never set the bit, regardless of deployment target. Differential Revision: https://reviews.llvm.org/D109451
1 parent cfc7402 commit f670c5a

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed

clang/include/clang/Basic/CodeGenOptions.def

+5
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,11 @@ CODEGENOPT(AAPCSBitfieldWidth, 1, 1)
440440
/// propagate signaling NaN inputs per IEEE 754-2008 (AMDGPU Only)
441441
CODEGENOPT(EmitIEEENaNCompliantInsts, 1, 1)
442442

443+
// Whether to emit Swift Async function extended frame information: auto,
444+
// never, always.
445+
ENUM_CODEGENOPT(SwiftAsyncFramePointer, SwiftAsyncFramePointerKind, 2,
446+
SwiftAsyncFramePointerKind::Always)
447+
443448
#undef CODEGENOPT
444449
#undef ENUM_CODEGENOPT
445450
#undef VALUE_CODEGENOPT

clang/include/clang/Basic/CodeGenOptions.h

+7
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
125125
All, // Keep all frame pointers.
126126
};
127127

128+
enum class SwiftAsyncFramePointerKind {
129+
Auto, // Choose Swift async extended frame info based on deployment target.
130+
Always, // Unconditionally emit Swift async extended frame info.
131+
Never, // Don't emit Swift async extended frame info.
132+
Default = Always,
133+
};
134+
128135
enum FiniteLoopsKind {
129136
Language, // Not specified, use language standard.
130137
Always, // All loops are assumed to be finite.

clang/include/clang/Driver/Options.td

+7
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,13 @@ def fprofile_list_EQ : Joined<["-"], "fprofile-list=">,
12751275
Group<f_Group>, Flags<[CC1Option, CoreOption]>,
12761276
HelpText<"Filename defining the list of functions/files to instrument">,
12771277
MarshallingInfoStringVector<LangOpts<"ProfileListFiles">>;
1278+
def fswift_async_fp_EQ : Joined<["-"], "fswift-async-fp=">,
1279+
Group<f_Group>, Flags<[CC1Option, CC1AsOption, CoreOption]>, MetaVarName<"<option>">,
1280+
HelpText<"Control emission of Swift async extended frame info (option: auto, always, never)">,
1281+
Values<"auto,always,never">,
1282+
NormalizedValuesScope<"CodeGenOptions::SwiftAsyncFramePointerKind">,
1283+
NormalizedValues<["Auto", "Always", "Never"]>,
1284+
MarshallingInfoEnum<CodeGenOpts<"SwiftAsyncFramePointer">, "Always">;
12781285

12791286
defm addrsig : BoolFOption<"addrsig",
12801287
CodeGenOpts<"Addrsig">, DefaultFalse,

clang/lib/CodeGen/BackendUtil.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,21 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
582582
Options.XRayOmitFunctionIndex = CodeGenOpts.XRayOmitFunctionIndex;
583583
Options.LoopAlignment = CodeGenOpts.LoopAlignment;
584584

585+
switch (CodeGenOpts.getSwiftAsyncFramePointer()) {
586+
case CodeGenOptions::SwiftAsyncFramePointerKind::Auto:
587+
Options.SwiftAsyncFramePointer =
588+
SwiftAsyncFramePointerMode::DeploymentBased;
589+
break;
590+
591+
case CodeGenOptions::SwiftAsyncFramePointerKind::Always:
592+
Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Always;
593+
break;
594+
595+
case CodeGenOptions::SwiftAsyncFramePointerKind::Never:
596+
Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Never;
597+
break;
598+
}
599+
585600
Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
586601
Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
587602
Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;

clang/lib/Driver/ToolChains/Clang.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -5912,6 +5912,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
59125912
RenderSCPOptions(TC, Args, CmdArgs);
59135913
RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs);
59145914

5915+
Args.AddLastArg(CmdArgs, options::OPT_fswift_async_fp_EQ);
5916+
59155917
// Translate -mstackrealign
59165918
if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign,
59175919
false))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %clang_cc1 -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
2+
// RUN: %clang_cc1 -mframe-pointer=all -triple x86_64-apple-darwin12 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
3+
// RUN: %clang_cc1 -fswift-async-fp=never -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=NEVER-X86
4+
// RUN: %clang_cc1 -fswift-async-fp=never -mframe-pointer=all -triple x86_64-apple-darwin12 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=NEVER-X86
5+
// RUN: %clang_cc1 -fswift-async-fp=auto -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=AUTO-X86
6+
// RUN: %clang_cc1 -fswift-async-fp=auto -mframe-pointer=all -triple x86_64-apple-darwin12 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
7+
// RUN: %clang_cc1 -fswift-async-fp=always -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
8+
// RUN: %clang_cc1 -fswift-async-fp=always -mframe-pointer=all -triple x86_64-apple-darwin12 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=ALWAYS-X86
9+
10+
// RUN: %clang_cc1 -mframe-pointer=all -triple arm64-apple-ios9 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=ALWAYS-ARM64
11+
// RUN: %clang_cc1 -mframe-pointer=all -triple arm64-apple-ios15 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=ALWAYS-ARM64
12+
// RUN: %clang_cc1 -fswift-async-fp=auto -mframe-pointer=all -triple arm64-apple-ios9 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=AUTO-ARM64
13+
// RUN: %clang_cc1 -fswift-async-fp=auto -mframe-pointer=all -triple arm64-apple-ios15 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=ALWAYS-ARM64
14+
// RUN: %clang_cc1 -fswift-async-fp=never -mframe-pointer=all -triple arm64-apple-ios9 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=NEVER-ARM64
15+
// RUN: %clang_cc1 -fswift-async-fp=never -mframe-pointer=all -triple arm64-apple-ios15 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=NEVER-ARM64
16+
// RUN: %clang_cc1 -fswift-async-fp=always -mframe-pointer=all -triple arm64-apple-ios9 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=ALWAYS-ARM64
17+
// RUN: %clang_cc1 -fswift-async-fp=always -mframe-pointer=all -triple arm64-apple-ios15 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=ALWAYS-ARM64
18+
19+
// REQUIRES: aarch64-registered-target,x86-registered-target
20+
21+
#define SWIFTASYNCCALL __attribute__((swiftasynccall))
22+
#define ASYNC_CONTEXT __attribute__((swift_async_context))
23+
24+
SWIFTASYNCCALL void async_context_1(ASYNC_CONTEXT void *ctx) {}
25+
26+
// AUTO-X86: _async_context_1:
27+
// AUTO-X86: _swift_async_extendedFramePointerFlags
28+
29+
// ALWAYS-X86: _async_context_1:
30+
// ALWAYS-X86: btsq $60
31+
32+
// NEVER-X86: _async_context_1:
33+
// NEVER-X86-NOT: _swift_async_extendedFramePointerFlags
34+
// NEVER-X86-NOT: btsq $60
35+
36+
// AUTO-ARM64: _async_context_1
37+
// AUTO-ARM64: _swift_async_extendedFramePointerFlags
38+
39+
// ALWAYS-ARM64: _async_context_1
40+
// ALWAYS-ARM64: orr x29, x29, #0x1000000000000000
41+
42+
// NEVER-ARM64: _async_context_1:
43+
// NEVER-ARM64-NOT: _swift_async_extendedFramePointerFlags
44+
// NEVER-ARM64-NOT: orr x29, x29, #0x1000000000000000

0 commit comments

Comments
 (0)