Skip to content

Commit ad70cbb

Browse files
committed
[SIL] Added no-stack-pack-metadata annotation.
1 parent 7a474ac commit ad70cbb

File tree

5 files changed

+52
-19
lines changed

5 files changed

+52
-19
lines changed

include/swift/SIL/SILFunction.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ enum ForceEnableLexicalLifetimes_t {
7676
DoForceEnableLexicalLifetimes
7777
};
7878

79+
enum UseStackForPackMetadata_t {
80+
DoNotUseStackForPackMetadata,
81+
DoUseStackForPackMetadata,
82+
};
83+
7984
enum class PerformanceConstraints : uint8_t {
8085
None = 0,
8186
NoAllocation = 1,
@@ -418,6 +423,10 @@ class SILFunction
418423
/// If true, the function has lexical lifetimes even if the module does not.
419424
unsigned ForceEnableLexicalLifetimes : 1;
420425

426+
/// If true, the function contains an instruction that prevents stack nesting
427+
/// from running with pack metadata markers in place.
428+
unsigned UseStackForPackMetadata : 1;
429+
421430
static void
422431
validateSubclassScope(SubclassScope scope, IsThunk_t isThunk,
423432
const GenericSpecializationInformation *genericInfo) {
@@ -693,6 +702,14 @@ class SILFunction
693702
ForceEnableLexicalLifetimes = value;
694703
}
695704

705+
UseStackForPackMetadata_t useStackForPackMetadata() const {
706+
return UseStackForPackMetadata_t(UseStackForPackMetadata);
707+
}
708+
709+
void setUseStackForPackMetadata(UseStackForPackMetadata_t value) {
710+
UseStackForPackMetadata = value;
711+
}
712+
696713
/// Returns true if this is a reabstraction thunk of escaping function type
697714
/// whose single argument is a potentially non-escaping closure. i.e. the
698715
/// thunks' function argument may itself have @inout_aliasable parameters.

lib/SIL/IR/SILFunction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ void SILFunction::init(
211211
this->IsDistributed = isDistributed;
212212
this->IsRuntimeAccessible = isRuntimeAccessible;
213213
this->ForceEnableLexicalLifetimes = DoNotForceEnableLexicalLifetimes;
214+
this->UseStackForPackMetadata = DoUseStackForPackMetadata;
214215
this->stackProtection = false;
215216
this->Inlined = false;
216217
this->Zombie = false;

lib/SIL/IR/SILPrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,6 +3169,9 @@ void SILFunction::print(SILPrintContext &PrintCtx) const {
31693169
if (forceEnableLexicalLifetimes()) {
31703170
OS << "[lexical_lifetimes] ";
31713171
}
3172+
if (!useStackForPackMetadata()) {
3173+
OS << "[no_onstack_pack_metadata] ";
3174+
}
31723175

31733176
if (isExactSelfClass()) {
31743177
OS << "[exact_self_class] ";

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,7 @@ static bool parseDeclSILOptional(bool *isTransparent,
10261026
IsDistributed_t *isDistributed,
10271027
IsRuntimeAccessible_t *isRuntimeAccessible,
10281028
ForceEnableLexicalLifetimes_t *forceEnableLexicalLifetimes,
1029+
UseStackForPackMetadata_t *useStackForPackMetadata,
10291030
IsExactSelfClass_t *isExactSelfClass,
10301031
SILFunction **dynamicallyReplacedFunction,
10311032
SILFunction **usedAdHocRequirementWitness,
@@ -1069,6 +1070,9 @@ static bool parseDeclSILOptional(bool *isTransparent,
10691070
else if (forceEnableLexicalLifetimes &&
10701071
SP.P.Tok.getText() == "lexical_lifetimes")
10711072
*forceEnableLexicalLifetimes = DoForceEnableLexicalLifetimes;
1073+
else if (useStackForPackMetadata &&
1074+
SP.P.Tok.getText() == "no_onstack_pack_metadata")
1075+
*useStackForPackMetadata = DoNotUseStackForPackMetadata;
10721076
else if (isExactSelfClass && SP.P.Tok.getText() == "exact_self_class")
10731077
*isExactSelfClass = IsExactSelfClass;
10741078
else if (isCanonical && SP.P.Tok.getText() == "canonical")
@@ -6971,6 +6975,7 @@ bool SILParserState::parseDeclSIL(Parser &P) {
69716975
IsRuntimeAccessible_t isRuntimeAccessible = IsNotRuntimeAccessible;
69726976
ForceEnableLexicalLifetimes_t forceEnableLexicalLifetimes =
69736977
DoNotForceEnableLexicalLifetimes;
6978+
UseStackForPackMetadata_t useStackForPackMetadata = DoUseStackForPackMetadata;
69746979
IsExactSelfClass_t isExactSelfClass = IsNotExactSelfClass;
69756980
bool hasOwnershipSSA = false;
69766981
IsThunk_t isThunk = IsNotThunk;
@@ -6995,13 +7000,13 @@ bool SILParserState::parseDeclSIL(Parser &P) {
69957000
parseDeclSILOptional(
69967001
&isTransparent, &isSerialized, &isCanonical, &hasOwnershipSSA,
69977002
&isThunk, &isDynamic, &isDistributed, &isRuntimeAccessible,
6998-
&forceEnableLexicalLifetimes, &isExactSelfClass,
6999-
&DynamicallyReplacedFunction, &AdHocWitnessFunction,
7000-
&objCReplacementFor, &specialPurpose, &inlineStrategy,
7001-
&optimizationMode, &perfConstr, &markedAsUsed, &section, nullptr,
7002-
&isWeakImported,
7003-
&needStackProtection, &availability, &isWithoutActuallyEscapingThunk,
7004-
&Semantics, &SpecAttrs, &ClangDecl, &MRK, FunctionState, M) ||
7003+
&forceEnableLexicalLifetimes, &useStackForPackMetadata,
7004+
&isExactSelfClass, &DynamicallyReplacedFunction,
7005+
&AdHocWitnessFunction, &objCReplacementFor, &specialPurpose,
7006+
&inlineStrategy, &optimizationMode, &perfConstr, &markedAsUsed,
7007+
&section, nullptr, &isWeakImported, &needStackProtection,
7008+
&availability, &isWithoutActuallyEscapingThunk, &Semantics,
7009+
&SpecAttrs, &ClangDecl, &MRK, FunctionState, M) ||
70057010
P.parseToken(tok::at_sign, diag::expected_sil_function_name) ||
70067011
P.parseIdentifier(FnName, FnNameLoc, /*diagnoseDollarPrefix=*/false,
70077012
diag::expected_sil_function_name) ||
@@ -7035,6 +7040,7 @@ bool SILParserState::parseDeclSIL(Parser &P) {
70357040
FunctionState.F->setIsRuntimeAccessible(isRuntimeAccessible);
70367041
FunctionState.F->setForceEnableLexicalLifetimes(
70377042
forceEnableLexicalLifetimes);
7043+
FunctionState.F->setUseStackForPackMetadata(useStackForPackMetadata);
70387044
FunctionState.F->setIsExactSelfClass(isExactSelfClass);
70397045
FunctionState.F->setDynamicallyReplacedFunction(
70407046
DynamicallyReplacedFunction);
@@ -7245,9 +7251,9 @@ bool SILParserState::parseSILGlobal(Parser &P) {
72457251
parseDeclSILOptional(nullptr, &isSerialized, nullptr, nullptr, nullptr,
72467252
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
72477253
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7248-
nullptr, nullptr,
7249-
&isLet, nullptr, nullptr, nullptr, nullptr, nullptr,
7250-
nullptr, nullptr, nullptr, State, M) ||
7254+
nullptr, nullptr, nullptr, &isLet, nullptr, nullptr,
7255+
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7256+
State, M) ||
72517257
P.parseToken(tok::at_sign, diag::expected_sil_value_name) ||
72527258
P.parseIdentifier(GlobalName, NameLoc, /*diagnoseDollarPrefix=*/false,
72537259
diag::expected_sil_value_name) ||
@@ -7297,9 +7303,9 @@ bool SILParserState::parseSILProperty(Parser &P) {
72977303
if (parseDeclSILOptional(nullptr, &Serialized, nullptr, nullptr, nullptr,
72987304
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
72997305
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7300-
nullptr, nullptr,
73017306
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7302-
nullptr, nullptr, nullptr, SP, M))
7307+
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7308+
SP, M))
73037309
return true;
73047310

73057311
ValueDecl *VD;
@@ -7367,9 +7373,9 @@ bool SILParserState::parseSILVTable(Parser &P) {
73677373
if (parseDeclSILOptional(nullptr, &Serialized, nullptr, nullptr, nullptr,
73687374
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
73697375
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7370-
nullptr, nullptr,
73717376
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7372-
nullptr, nullptr, nullptr, VTableState, M))
7377+
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7378+
VTableState, M))
73737379
return true;
73747380

73757381
// Parse the class name.
@@ -7478,10 +7484,9 @@ bool SILParserState::parseSILMoveOnlyDeinit(Parser &parser) {
74787484
if (parseDeclSILOptional(nullptr, &Serialized, nullptr, nullptr, nullptr,
74797485
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
74807486
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7481-
nullptr, nullptr,
74827487
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7483-
nullptr, nullptr, nullptr, moveOnlyDeinitTableState,
7484-
M))
7488+
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7489+
moveOnlyDeinitTableState, M))
74857490
return true;
74867491

74877492
// Parse the class name.
@@ -7966,9 +7971,9 @@ bool SILParserState::parseSILWitnessTable(Parser &P) {
79667971
if (parseDeclSILOptional(nullptr, &isSerialized, nullptr, nullptr, nullptr,
79677972
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
79687973
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7969-
nullptr, nullptr,
79707974
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7971-
nullptr, nullptr, nullptr, WitnessState, M))
7975+
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
7976+
WitnessState, M))
79727977
return true;
79737978

79747979
// Parse the protocol conformance.

test/SIL/Parser/pack_metadata.sil

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ entry:
1212
%retval = tuple ()
1313
return %retval : $()
1414
}
15+
16+
// CHECK-LABEL: sil [no_onstack_pack_metadata] @annotation : {{.*}} {
17+
// CHECK-LABEL: } // end sil function 'annotation'
18+
sil [no_onstack_pack_metadata] @annotation : $() -> () {
19+
%retval = tuple ()
20+
return %retval : $()
21+
}

0 commit comments

Comments
 (0)