Skip to content

Commit ae1cb4b

Browse files
authored
Merge pull request #3255 from aschwaighofer/swift_async_extended_frame_info_incremental_part2
Swift async extended frame info (clang only, part2)
2 parents 70b82c8 + 381d453 commit ae1cb4b

File tree

6 files changed

+81
-0
lines changed

6 files changed

+81
-0
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ CODEGENOPT(PassByValueIsNoAlias, 1, 0)
416416
/// according to the field declaring type width.
417417
CODEGENOPT(AAPCSBitfieldWidth, 1, 1)
418418

419+
// Whether to emit Swift Async function extended frame information: auto,
420+
// never, always.
421+
ENUM_CODEGENOPT(SwiftAsyncFramePointer, SwiftAsyncFramePointerKind, 2,
422+
SwiftAsyncFramePointerKind::Always)
423+
419424
#undef CODEGENOPT
420425
#undef ENUM_CODEGENOPT
421426
#undef VALUE_CODEGENOPT

clang/include/clang/Basic/CodeGenOptions.h

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

138+
enum class SwiftAsyncFramePointerKind {
139+
Auto, // Choose Swift async extended frame info based on deployment target.
140+
Always, // Unconditionally emit Swift async extended frame info.
141+
Never, // Don't emit Swift async extended frame info.
142+
Default = Always,
143+
};
144+
138145
enum FiniteLoopsKind {
139146
Language, // Not specified, use language standard.
140147
Always, // All loops are assumed to be finite.

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,14 @@ defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
11851185
def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
11861186
Group<f_Group>, Flags<[CC1Option, CoreOption]>,
11871187
HelpText<"Generate instrumented code to collect order file into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;
1188+
def fswift_async_fp_EQ : Joined<["-"], "fswift-async-fp=">,
1189+
Group<f_Group>, Flags<[CC1Option, CC1AsOption, CoreOption]>, MetaVarName<"<option>">,
1190+
HelpText<"Control emission of Swift async extended frame info (option: auto, always, never)">,
1191+
Values<"auto,always,never">,
1192+
NormalizedValuesScope<"CodeGenOptions::SwiftAsyncFramePointerKind">,
1193+
NormalizedValues<["Auto", "Always", "Never"]>,
1194+
MarshallingInfoFlag<"CodeGenOpts.SwiftAsyncFramePointer", "Always">,
1195+
AutoNormalizeEnum;
11881196

11891197
def fapinotes : Flag<["-"], "fapinotes">, Group<f_clang_Group>,
11901198
Flags<[CC1Option]>, HelpText<"Enable external API notes support">;

clang/lib/CodeGen/BackendUtil.cpp

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

569+
switch (CodeGenOpts.getSwiftAsyncFramePointer()) {
570+
case CodeGenOptions::SwiftAsyncFramePointerKind::Auto:
571+
Options.SwiftAsyncFramePointer =
572+
SwiftAsyncFramePointerMode::DeploymentBased;
573+
break;
574+
575+
case CodeGenOptions::SwiftAsyncFramePointerKind::Always:
576+
Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Always;
577+
break;
578+
579+
case CodeGenOptions::SwiftAsyncFramePointerKind::Never:
580+
Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Never;
581+
break;
582+
}
583+
569584
Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
570585
Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
571586
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
@@ -5605,6 +5605,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
56055605
RenderSCPOptions(TC, Args, CmdArgs);
56065606
RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs);
56075607

5608+
Args.AddLastArg(CmdArgs, options::OPT_fswift_async_fp_EQ);
5609+
56085610
// Translate -mstackrealign
56095611
if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign,
56105612
false))
Lines changed: 44 additions & 0 deletions
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)