Skip to content

Commit ea0eec6

Browse files
committed
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).
1 parent 079bbea commit ea0eec6

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

+575
-30
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
@@ -239,6 +239,7 @@ enum Kind {
239239
kw_strictfp,
240240
kw_swifterror,
241241
kw_swiftself,
242+
kw_swiftasync,
242243
kw_uwtable,
243244
kw_vscale_range,
244245
kw_willreturn,

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ enum AttributeKindCodes {
665665
ATTR_KIND_HOT = 72,
666666
ATTR_KIND_NO_PROFILE = 73,
667667
ATTR_KIND_VSCALE_RANGE = 74,
668+
ATTR_KIND_SWIFT_ASYNC = 75,
668669
};
669670

670671
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
@@ -284,6 +284,7 @@ class TargetLoweringBase {
284284
bool IsPreallocated : 1;
285285
bool IsReturned : 1;
286286
bool IsSwiftSelf : 1;
287+
bool IsSwiftAsync : 1;
287288
bool IsSwiftError : 1;
288289
bool IsCFGuardTarget : 1;
289290
MaybeAlign Alignment = None;
@@ -294,7 +295,7 @@ class TargetLoweringBase {
294295
: IsSExt(false), IsZExt(false), IsInReg(false), IsSRet(false),
295296
IsNest(false), IsByVal(false), IsByRef(false), IsInAlloca(false),
296297
IsPreallocated(false), IsReturned(false), IsSwiftSelf(false),
297-
IsSwiftError(false), IsCFGuardTarget(false) {}
298+
IsSwiftAsync(false), IsSwiftError(false), IsCFGuardTarget(false) {}
298299

299300
void setAttributes(const CallBase *Call, unsigned ArgIdx);
300301
};

llvm/include/llvm/IR/Attributes.td

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

247+
/// Argument is swift async context.
248+
def SwiftAsync : EnumAttr<"swiftasync">;
249+
247250
/// Function must be in a unwind table.
248251
def UWTable : EnumAttr<"uwtable">;
249252

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,12 @@ def int_objc_arc_annotation_bottomup_bbstart : Intrinsic<[],
479479
def int_objc_arc_annotation_bottomup_bbend : Intrinsic<[],
480480
[llvm_ptrptr_ty,
481481
llvm_ptrptr_ty]>;
482+
//===--------------- Swift asynchronous context intrinsics ----------------===//
482483

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

484489
//===--------------------- Code Generator Intrinsics ----------------------===//
485490
//

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
@@ -696,6 +696,7 @@ lltok::Kind LLLexer::LexIdentifier() {
696696
KEYWORD(speculative_load_hardening);
697697
KEYWORD(swifterror);
698698
KEYWORD(swiftself);
699+
KEYWORD(swiftasync);
699700
KEYWORD(uwtable);
700701
KEYWORD(vscale_range);
701702
KEYWORD(willreturn);

0 commit comments

Comments
 (0)