Skip to content

Commit ab48dbb

Browse files
TNorthoverarichardson
authored andcommitted
IR+AArch64: add a "swiftasync" argument attribute.
This extends any frame record created in the function to include that parameter, passed in X22. The new record looks like [X22, FP, LR] in memory, and FP is stored with 0b0001 in bits 63:60 (CodeGen assumes they are 0b0000 in normal operation). The effect of this is that tools walking the stack should expect to see one of three values there: * 0b0000 => a normal, non-extended record with just [FP, LR] * 0b0001 => the extended record [X22, FP, LR] * 0b1111 => kernel space, and a non-extended record. All other values are currently reserved. If compiling for arm64e this context pointer is address-discriminated with the discriminator 0xc31a and the DB (process-specific) key. There is also an "i8** @llvm.swift.async.context.addr()" intrinsic providing front-ends access to this slot (and forcing its creation initialized to nullptr if necessary).
2 parents 7387e73 + ea0eec6 commit ab48dbb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+577
-32
lines changed

llvm/docs/LangRef.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,12 @@ Currently, only the following parameter attributes are defined:
12781278
a valid attribute for return values and can only be applied to one
12791279
parameter.
12801280

1281+
``swiftasync``
1282+
This indicates that the parameter is the asynchronous context parameter and
1283+
triggers the creation of a target-specific extended frame record to store
1284+
this pointer. This is not a valid attribute for return values and can only
1285+
be applied to one parameter.
1286+
12811287
``swifterror``
12821288
This attribute is motivated to model and optimize Swift error handling. It
12831289
can be applied to a parameter with pointer to pointer type or a
@@ -12360,6 +12366,29 @@ Note that calling this intrinsic does not prevent function inlining or
1236012366
other aggressive transformations, so the value returned may not be that
1236112367
of the obvious source-language caller.
1236212368

12369+
'``llvm.swift.async.context.addr``' Intrinsic
12370+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12371+
12372+
Syntax:
12373+
"""""""
12374+
12375+
::
12376+
12377+
declare i8** @llvm.swift.async.context.addr()
12378+
12379+
Overview:
12380+
"""""""""
12381+
12382+
The '``llvm.swift.async.context.addr``' intrinsic returns a pointer to
12383+
the part of the extended frame record containing the asynchronous
12384+
context of a Swift execution.
12385+
12386+
Semantics:
12387+
""""""""""
12388+
12389+
If the function has a ``swiftasync`` parameter, that argument will initially
12390+
be stored at the returned address. If not, it will be initialized to null.
12391+
1236312392
'``llvm.localescape``' and '``llvm.localrecover``' Intrinsics
1236412393
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1236512394

llvm/include/llvm/AsmParser/LLToken.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ enum Kind {
243243
kw_strictfp,
244244
kw_swifterror,
245245
kw_swiftself,
246+
kw_swiftasync,
246247
kw_uwtable,
247248
kw_vscale_range,
248249
kw_willreturn,

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,9 @@ enum AttributeKindCodes {
665665
ATTR_KIND_HOT = 72,
666666
ATTR_KIND_NO_PROFILE = 73,
667667
ATTR_KIND_VSCALE_RANGE = 74,
668-
ATTR_KIND_HAS_SIDE_EFFECTS = 75,
669-
ATTR_KIND_MUST_PRESERVE_CHERI_TAGS = 76,
668+
ATTR_KIND_SWIFT_ASYNC = 75,
669+
ATTR_KIND_HAS_SIDE_EFFECTS = 76,
670+
ATTR_KIND_MUST_PRESERVE_CHERI_TAGS = 77,
670671
};
671672

672673
enum ComdatSelectionKindCodes {

llvm/include/llvm/CodeGen/TargetCallingConv.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace ISD {
3939
unsigned IsPreallocated : 1; ///< ByVal without the copy
4040
unsigned IsSplitEnd : 1; ///< Last part of a split
4141
unsigned IsSwiftSelf : 1; ///< Swift self parameter
42+
unsigned IsSwiftAsync : 1; ///< Swift async context parameter
4243
unsigned IsSwiftError : 1; ///< Swift error parameter
4344
unsigned IsCFGuardTarget : 1; ///< Control Flow Guard target
4445
unsigned IsHva : 1; ///< HVA field for
@@ -58,11 +59,12 @@ namespace ISD {
5859

5960
public:
6061
ArgFlagsTy()
61-
: IsZExt(0), IsSExt(0), IsInReg(0), IsSRet(0), IsByVal(0), IsByRef(0),
62-
IsNest(0), IsReturned(0), IsSplit(0), IsInAlloca(0), IsPreallocated(0),
63-
IsSplitEnd(0), IsSwiftSelf(0), IsSwiftError(0), IsCFGuardTarget(0),
64-
IsHva(0), IsHvaStart(0), IsSecArgPass(0), MemAlign(0),
65-
OrigAlign(0), IsInConsecutiveRegsLast(0), IsInConsecutiveRegs(0),
62+
: IsZExt(0), IsSExt(0), IsInReg(0), IsSRet(0), IsByVal(0), IsByRef(0),
63+
IsNest(0), IsReturned(0), IsSplit(0), IsInAlloca(0),
64+
IsPreallocated(0), IsSplitEnd(0), IsSwiftSelf(0), IsSwiftAsync(0),
65+
IsSwiftError(0), IsCFGuardTarget(0), IsHva(0), IsHvaStart(0),
66+
IsSecArgPass(0), MemAlign(0), OrigAlign(0),
67+
IsInConsecutiveRegsLast(0), IsInConsecutiveRegs(0),
6668
IsCopyElisionCandidate(0), IsPointer(0), ByValOrByRefSize(0),
6769
PointerAddrSpace(0) {
6870
static_assert(sizeof(*this) == 3 * sizeof(unsigned), "flags are too big");
@@ -95,6 +97,9 @@ namespace ISD {
9597
bool isSwiftSelf() const { return IsSwiftSelf; }
9698
void setSwiftSelf() { IsSwiftSelf = 1; }
9799

100+
bool isSwiftAsync() const { return IsSwiftAsync; }
101+
void setSwiftAsync() { IsSwiftAsync = 1; }
102+
98103
bool isSwiftError() const { return IsSwiftError; }
99104
void setSwiftError() { IsSwiftError = 1; }
100105

llvm/include/llvm/CodeGen/TargetFrameLowering.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ class TargetFrameLowering {
149149
/// returns false, spill slots will be assigned using generic implementation.
150150
/// assignCalleeSavedSpillSlots() may add, delete or rearrange elements of
151151
/// CSI.
152+
virtual bool assignCalleeSavedSpillSlots(MachineFunction &MF,
153+
const TargetRegisterInfo *TRI,
154+
std::vector<CalleeSavedInfo> &CSI,
155+
unsigned &MinCSFrameIndex,
156+
unsigned &MaxCSFrameIndex) const {
157+
return assignCalleeSavedSpillSlots(MF, TRI, CSI);
158+
}
159+
152160
virtual bool
153161
assignCalleeSavedSpillSlots(MachineFunction &MF,
154162
const TargetRegisterInfo *TRI,

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ class TargetLoweringBase {
290290
bool IsPreallocated : 1;
291291
bool IsReturned : 1;
292292
bool IsSwiftSelf : 1;
293+
bool IsSwiftAsync : 1;
293294
bool IsSwiftError : 1;
294295
bool IsCFGuardTarget : 1;
295296
MaybeAlign Alignment = None;
@@ -300,7 +301,7 @@ class TargetLoweringBase {
300301
: IsSExt(false), IsZExt(false), IsInReg(false), IsSRet(false),
301302
IsNest(false), IsByVal(false), IsByRef(false), IsInAlloca(false),
302303
IsPreallocated(false), IsReturned(false), IsSwiftSelf(false),
303-
IsSwiftError(false), IsCFGuardTarget(false) {}
304+
IsSwiftAsync(false), IsSwiftError(false), IsCFGuardTarget(false) {}
304305

305306
void setAttributes(const CallBase *Call, unsigned ArgIdx);
306307
};

llvm/include/llvm/IR/Attributes.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ def SwiftError : EnumAttr<"swifterror">;
247247
/// Argument is swift self/context.
248248
def SwiftSelf : EnumAttr<"swiftself">;
249249

250+
/// Argument is swift async context.
251+
def SwiftAsync : EnumAttr<"swiftasync">;
252+
250253
/// Function must be in a unwind table.
251254
def UWTable : EnumAttr<"uwtable">;
252255

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,12 @@ def int_objc_arc_annotation_bottomup_bbstart : Intrinsic<[],
491491
def int_objc_arc_annotation_bottomup_bbend : Intrinsic<[],
492492
[llvm_ptrptr_ty,
493493
llvm_ptrptr_ty]>;
494+
//===--------------- Swift asynchronous context intrinsics ----------------===//
494495

496+
// Returns the location of the Swift asynchronous context (usually stored just
497+
// before the frame pointer), and triggers the creation of a null context if it
498+
// would otherwise be unneeded.
499+
def int_swift_async_context_addr : Intrinsic<[llvm_ptrptr_ty], [], [IntrNoMem]>;
495500

496501
//===--------------------- Code Generator Intrinsics ----------------------===//
497502
//

llvm/include/llvm/Target/TargetCallingConv.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class CCIfPreallocated<CCAction A> : CCIf<"ArgFlags.isPreallocated()", A> {
5151
class CCIfSwiftSelf<CCAction A> : CCIf<"ArgFlags.isSwiftSelf()", A> {
5252
}
5353

54+
/// CCIfSwiftAsync - If the current argument has swiftasync parameter attribute,
55+
/// apply Action A.
56+
class CCIfSwiftAsync<CCAction A> : CCIf<"ArgFlags.isSwiftAsync()", A> {
57+
}
58+
5459
/// CCIfSwiftError - If the current argument has swifterror parameter attribute,
5560
/// apply Action A.
5661
class CCIfSwiftError<CCAction A> : CCIf<"ArgFlags.isSwiftError()", A> {

llvm/lib/AsmParser/LLLexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ lltok::Kind LLLexer::LexIdentifier() {
700700
KEYWORD(speculative_load_hardening);
701701
KEYWORD(swifterror);
702702
KEYWORD(swiftself);
703+
KEYWORD(swiftasync);
703704
KEYWORD(uwtable);
704705
KEYWORD(vscale_range);
705706
KEYWORD(willreturn);

0 commit comments

Comments
 (0)