Skip to content

Commit e007ded

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`: the default, which determines how to set the bit based on deployment target, either statically or dynamically via `swift_async_extendedFramePointerFlags`. * `always`: 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 6504c66 commit e007ded

File tree

6 files changed

+78
-0
lines changed

6 files changed

+78
-0
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,18 @@ CODEGENOPT(PassByValueIsNoAlias, 1, 0)
433433
/// according to the field declaring type width.
434434
CODEGENOPT(AAPCSBitfieldWidth, 1, 1)
435435

436+
436437
/// Sets the IEEE bit in the expected default floating point mode register.
437438
/// Floating point opcodes that support exception flag gathering quiet and
438439
/// propagate signaling NaN inputs per IEEE 754-2008 (AMDGPU Only)
439440
CODEGENOPT(EmitIEEENaNCompliantInsts, 1, 1)
440441

442+
// Whether to emit Swift Async function extended frame information: auto,
443+
// never, always.
444+
ENUM_CODEGENOPT(SwiftAsyncFramePointer, SwiftAsyncFramePointerKind, 2,
445+
SwiftAsyncFramePointerKind::Auto)
446+
447+
441448
#undef CODEGENOPT
442449
#undef ENUM_CODEGENOPT
443450
#undef VALUE_CODEGENOPT

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
126126
All, // Keep all frame pointers.
127127
};
128128

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

clang/include/clang/Driver/Options.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,13 @@ def fprofile_list_EQ : Joined<["-"], "fprofile-list=">,
12611261
Group<f_Group>, Flags<[CC1Option, CoreOption]>,
12621262
HelpText<"Filename defining the list of functions/files to instrument">,
12631263
MarshallingInfoStringVector<LangOpts<"ProfileListFiles">>;
1264+
def fswift_async_fp_EQ : Joined<["-"], "fswift-async-fp=">,
1265+
Group<f_Group>, Flags<[CC1Option, CC1AsOption, CoreOption]>, MetaVarName<"<option>">,
1266+
HelpText<"Control emission of Swift async extended frame info (option: auto, always, never)">,
1267+
Values<"auto,always,never">,
1268+
NormalizedValuesScope<"CodeGenOptions::SwiftAsyncFramePointerKind">,
1269+
NormalizedValues<["Auto", "Always", "Never"]>,
1270+
MarshallingInfoEnum<CodeGenOpts<"SwiftAsyncFramePointer">, "Auto">;
12641271

12651272
defm apinotes : BoolOption<"f", "apinotes",
12661273
LangOpts<"APINotes">, DefaultFalse,

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,21 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
586586
CodeGenOpts.ValueTrackingVariableLocations;
587587
Options.XRayOmitFunctionIndex = CodeGenOpts.XRayOmitFunctionIndex;
588588

589+
switch (CodeGenOpts.getSwiftAsyncFramePointer()) {
590+
case CodeGenOptions::SwiftAsyncFramePointerKind::Auto:
591+
Options.SwiftAsyncFramePointer =
592+
SwiftAsyncFramePointerMode::DeploymentBased;
593+
break;
594+
595+
case CodeGenOptions::SwiftAsyncFramePointerKind::Always:
596+
Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Always;
597+
break;
598+
599+
case CodeGenOptions::SwiftAsyncFramePointerKind::Never:
600+
Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Never;
601+
break;
602+
}
603+
589604
Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
590605
Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
591606
Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5902,6 +5902,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
59025902
RenderSCPOptions(TC, Args, CmdArgs);
59035903
RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs);
59045904

5905+
Args.AddLastArg(CmdArgs, options::OPT_fswift_async_fp_EQ);
5906+
59055907
// Translate -mstackrealign
59065908
if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign,
59075909
false))
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %clang_cc1 -mframe-pointer=all -triple x86_64-apple-darwin10 -target-cpu core2 -S -o - %s | FileCheck %s --check-prefix=AUTO-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=AUTO-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=never -mframe-pointer=all -triple arm64-apple-ios9 -target-cpu cyclone -S -o - %s | FileCheck %s --check-prefix=NEVER-ARM64
13+
// 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
14+
15+
// REQUIRES: aarch64-registered-target,x86-registered-target
16+
17+
#define SWIFTASYNCCALL __attribute__((swiftasynccall))
18+
#define ASYNC_CONTEXT __attribute__((swift_async_context))
19+
20+
SWIFTASYNCCALL void async_context_1(ASYNC_CONTEXT void *ctx) {}
21+
22+
// AUTO-X86: _async_context_1:
23+
// AUTO-X86: _swift_async_extendedFramePointerFlags
24+
25+
// ALWAYS-X86: _async_context_1:
26+
// ALWAYS-X86: btsq $60
27+
28+
// NEVER-X86: _async_context_1:
29+
// NEVER-X86-NOT: _swift_async_extendedFramePointerFlags
30+
// NEVER-X86-NOT: btsq $60
31+
32+
// AUTO-ARM64: _async_context_1
33+
// AUTO-ARM64: _swift_async_extendedFramePointerFlags
34+
35+
// ALWAYS-ARM64: _async_context_1
36+
// ALWAYS-ARM64: orr x29, x29, #0x1000000000000000
37+
38+
// NEVER-ARM64: _async_context_1:
39+
// NEVER-ARM64-NOT: _swift_async_extendedFramePointerFlags
40+
// NEVER-ARM64-NOT: orr x29, x29, #0x1000000000000000

0 commit comments

Comments
 (0)