Skip to content

Commit 860e17f

Browse files
authored
Merge pull request #40819 from atrick/remove-applymacro
2 parents a1e2ebb + 08b445f commit 860e17f

File tree

3 files changed

+41
-156
lines changed

3 files changed

+41
-156
lines changed

include/swift/SIL/ApplySite.h

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ class FullApplySite;
3838

3939
struct ApplySiteKind {
4040
enum innerty : std::underlying_type<SILInstructionKind>::type {
41-
#define APPLYSITE_INST(ID, PARENT) ID = unsigned(SILInstructionKind::ID),
42-
#include "swift/SIL/SILNodes.def"
41+
ApplyInst = unsigned(SILInstructionKind::ApplyInst),
42+
PartialApplyInst = unsigned(SILInstructionKind::PartialApplyInst),
43+
TryApplyInst = unsigned(SILInstructionKind::TryApplyInst),
44+
BeginApplyInst = unsigned(SILInstructionKind::BeginApplyInst),
4345
} value;
4446

4547
explicit ApplySiteKind(SILInstructionKind kind) {
@@ -60,10 +62,14 @@ struct ApplySiteKind {
6062
private:
6163
static Optional<innerty> fromNodeKindHelper(SILInstructionKind kind) {
6264
switch (kind) {
63-
#define APPLYSITE_INST(ID, PARENT) \
64-
case SILInstructionKind::ID: \
65-
return ApplySiteKind::ID;
66-
#include "swift/SIL/SILNodes.def"
65+
case SILInstructionKind::ApplyInst:
66+
return ApplySiteKind::ApplyInst;
67+
case SILInstructionKind::PartialApplyInst:
68+
return ApplySiteKind::PartialApplyInst;
69+
case SILInstructionKind::TryApplyInst:
70+
return ApplySiteKind::TryApplyInst;
71+
case SILInstructionKind::BeginApplyInst:
72+
return ApplySiteKind::BeginApplyInst;
6773
default:
6874
return None;
6975
}
@@ -497,8 +503,9 @@ class ApplySite {
497503

498504
struct FullApplySiteKind {
499505
enum innerty : std::underlying_type<SILInstructionKind>::type {
500-
#define FULLAPPLYSITE_INST(ID, PARENT) ID = unsigned(SILInstructionKind::ID),
501-
#include "swift/SIL/SILNodes.def"
506+
ApplyInst = unsigned(SILInstructionKind::ApplyInst),
507+
TryApplyInst = unsigned(SILInstructionKind::TryApplyInst),
508+
BeginApplyInst = unsigned(SILInstructionKind::BeginApplyInst),
502509
} value;
503510

504511
explicit FullApplySiteKind(SILInstructionKind kind) {
@@ -519,10 +526,12 @@ struct FullApplySiteKind {
519526
private:
520527
static Optional<innerty> fromNodeKindHelper(SILInstructionKind kind) {
521528
switch (kind) {
522-
#define FULLAPPLYSITE_INST(ID, PARENT) \
523-
case SILInstructionKind::ID: \
524-
return FullApplySiteKind::ID;
525-
#include "swift/SIL/SILNodes.def"
529+
case SILInstructionKind::ApplyInst:
530+
return FullApplySiteKind::ApplyInst;
531+
case SILInstructionKind::TryApplyInst:
532+
return FullApplySiteKind::TryApplyInst;
533+
case SILInstructionKind::BeginApplyInst:
534+
return FullApplySiteKind::BeginApplyInst;
526535
default:
527536
return None;
528537
}

include/swift/SIL/SILNodes.def

Lines changed: 16 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -16,14 +16,12 @@
1616
/// supports changing how macros expand by #defining an auxillary variable
1717
/// before including SILNodes.def as summarized in the chart below:
1818
///
19-
/// | #define | Operation |
20-
/// |--------------------+---------------------------------------------------------|
21-
/// | N/A | Visit single value insts as insts |
22-
/// | VALUE | Visit single value insts as values |
23-
/// | ABSTRACT_VALUE | Visit abstract single value insts as values |
24-
/// | APPLYSITE_INST | Visit full and partial apply site insts as apply sites. |
25-
/// | FULLAPPLYSITE_INST | Visit full apply site insts as apply sites. |
26-
/// | DYNAMICCAST_INST | Visit dynamic casts as dynamic casts. |
19+
/// | #define | Operation |
20+
/// |--------------------+-----------------------------------------------------|
21+
/// | N/A | Visit single value insts as insts |
22+
/// | VALUE | Visit single value insts as values |
23+
/// | ABSTRACT_VALUE | Visit abstract single value insts as values |
24+
/// | DYNAMICCAST_INST | Visit dynamic casts as dynamic casts. |
2725
///
2826
/// We describe the triggering variables below:
2927
///
@@ -37,29 +35,7 @@
3735
/// If defined this will cause ABSTRACT_SINGLE_VALUE_INST to expand to
3836
/// ABSTRACT_VALUE INSTEAD OF ABSTRACT_INST.
3937
///
40-
/// 3. FULLAPPLYSITE_INST(ID, PARENT).
41-
///
42-
/// If defined this will cause:
43-
///
44-
/// * FULLAPPLYSITE_SINGLE_VALUE_INST,
45-
/// * FULLAPPLYSITE_MULTIPLE_VALUE_INST,
46-
/// * FULLAPPLYSITE_TERMINATOR_INST,
47-
///
48-
/// To expand to FULLAPPLYSITE_INST(ID, PARENT) instead of SINGLE_VALUE_INST,
49-
/// MULTIPLE_VALUE_INST, or TERMINATOR_INST.
50-
///
51-
/// 4. APPLYSITE_INST(ID, PARENT)
52-
///
53-
/// If defined this will cause:
54-
///
55-
/// * APPLYSITE_SINGLE_VALUE_INST
56-
/// * APPLYSITE_MULTIPLE_VALUE_INST
57-
/// * APPLYSITE_TERMINATOR_INST
58-
///
59-
/// to expand to APPLYSITE_INST(ID, PARENT) instead of delegating to
60-
/// SINGLE_VALUE_INST.
61-
///
62-
/// 5. DYNAMICCAST_INST(ID, PARENT)
38+
/// 3. DYNAMICCAST_INST(ID, PARENT)
6339
///
6440
/// If defined this will cause:
6541
///
@@ -72,12 +48,6 @@
7248
///
7349
//===----------------------------------------------------------------------===//
7450

75-
#ifdef APPLYSITE_INST
76-
#ifdef FULLAPPLYSITE_INST
77-
#error "Can not query for apply site and full apply site in one include"
78-
#endif
79-
#endif
80-
8151
/// NODE(ID, PARENT)
8252
///
8353
/// A concrete subclass of SILNode. ID is the name of the class as well
@@ -121,36 +91,6 @@
12191
#endif
12292
#endif
12393

124-
/// APPLYSITE_SINGLE_VALUE_INST(ID, TEXTUALNAME, PARENT, MEMBEHAVIOR,
125-
/// MAYRELEASE)
126-
///
127-
/// A SINGLE_VALUE_INST that is a partial or full apply site. ID is a member
128-
/// of ApplySiteKind.
129-
#ifndef APPLYSITE_SINGLE_VALUE_INST
130-
#ifdef APPLYSITE_INST
131-
#define APPLYSITE_SINGLE_VALUE_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE) \
132-
APPLYSITE_INST(ID, PARENT)
133-
#else
134-
#define APPLYSITE_SINGLE_VALUE_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE) \
135-
BRIDGED_SINGLE_VALUE_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE)
136-
#endif
137-
#endif
138-
139-
/// FULLAPPLYSITE_SINGLE_VALUE_INST(ID, TEXTUALNAME, PARENT, MEMBEHAVIOR,
140-
/// MAYRELEASE)
141-
///
142-
/// A SINGLE_VALUE_INST that is a full apply site. ID is a member of
143-
/// FullApplySiteKind and ApplySiteKind.
144-
#ifndef FULLAPPLYSITE_SINGLE_VALUE_INST
145-
#ifdef FULLAPPLYSITE_INST
146-
#define FULLAPPLYSITE_SINGLE_VALUE_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE) \
147-
FULLAPPLYSITE_INST(ID, PARENT)
148-
#else
149-
#define FULLAPPLYSITE_SINGLE_VALUE_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE) \
150-
APPLYSITE_SINGLE_VALUE_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE)
151-
#endif
152-
#endif
153-
15494
/// MULTIPLE_VALUE_INST(Id, TextualName, Parent, MemBehavior, MayRelease)
15595
///
15696
/// A concrete subclass of MultipleValueInstruction. ID is a member of
@@ -161,36 +101,6 @@
161101
FULL_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE)
162102
#endif
163103

164-
/// APPLYSITE_MULTIPLE_VALUE_INST(ID, TEXTUALNAME, PARENT, MEMBEHAVIOR,
165-
/// MAYRELEASE)
166-
///
167-
/// A MULTIPLE_VALUE_INST that is additionally either a partial or full apply
168-
/// site. ID is a member of ApplySiteKind.
169-
#ifndef APPLYSITE_MULTIPLE_VALUE_INST
170-
#ifdef APPLYSITE_INST
171-
#define APPLYSITE_MULTIPLE_VALUE_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE) \
172-
APPLYSITE_INST(ID, PARENT)
173-
#else
174-
#define APPLYSITE_MULTIPLE_VALUE_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE) \
175-
MULTIPLE_VALUE_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE)
176-
#endif
177-
#endif
178-
179-
/// FULLAPPLYSITE_MULTIPLE_VALUE_INST(ID, TEXTUALNAME, PARENT, MEMBEHAVIOR,
180-
/// MAYRELEASE)
181-
///
182-
/// A MULTIPLE_VALUE_INST that is additionally a full apply site. ID is a
183-
/// member of FullApplySiteKind and ApplySiteKind.
184-
#ifndef FULLAPPLYSITE_MULTIPLE_VALUE_INST
185-
#ifdef FULLAPPLYSITE_INST
186-
#define FULLAPPLYSITE_MULTIPLE_VALUE_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE) \
187-
FULLAPPLYSITE_INST(ID, PARENT)
188-
#else
189-
#define FULLAPPLYSITE_MULTIPLE_VALUE_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE) \
190-
APPLYSITE_MULTIPLE_VALUE_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE)
191-
#endif
192-
#endif
193-
194104
/// MULTIPLE_VALUE_INST_RESULT(ID, PARENT)
195105
///
196106
/// A concrete subclass of MultipleValueInstructionResult. ID is a member of
@@ -286,34 +196,6 @@
286196
#endif
287197
#endif
288198

289-
/// APPLYSITE_TERMINATOR_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE)
290-
///
291-
/// ID is a member of ApplySiteKind, TerminatorKind, and ApplySiteKind and name
292-
/// of a subclass of TermInst.
293-
#ifndef APPLYSITE_TERMINATOR_INST
294-
#ifdef APPLYSITE_INST
295-
#define APPLYSITE_TERMINATOR_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE) \
296-
APPLYSITE_INST(ID, NAME)
297-
#else
298-
#define APPLYSITE_TERMINATOR_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE) \
299-
TERMINATOR(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE)
300-
#endif
301-
#endif
302-
303-
/// FULLAPPLYSITE_TERMINATOR(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE)
304-
///
305-
/// ID is a member of FullApplySiteKind, TerminatorKind, and ApplySiteKind and
306-
/// name of a subclass of TermInst.
307-
#ifndef FULLAPPLYSITE_TERMINATOR_INST
308-
#ifdef FULLAPPLYSITE_INST
309-
#define FULLAPPLYSITE_TERMINATOR_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE) \
310-
FULLAPPLYSITE_INST(ID, PARENT)
311-
#else
312-
#define FULLAPPLYSITE_TERMINATOR_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE) \
313-
APPLYSITE_TERMINATOR_INST(ID, NAME, PARENT, MEMBEHAVIOR, MAYRELEASE)
314-
#endif
315-
#endif
316-
317199
/// ABSTRACT_NODE(ID, PARENT)
318200
///
319201
/// An abstract class in the SILNode hierarchy. It does not have an
@@ -640,12 +522,12 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
640522
SingleValueInstruction, None, DoesNotRelease)
641523

642524
// Function Application
643-
FULLAPPLYSITE_SINGLE_VALUE_INST(ApplyInst, apply,
644-
SingleValueInstruction, MayHaveSideEffects, MayRelease)
525+
BRIDGED_SINGLE_VALUE_INST(ApplyInst, apply,
526+
SingleValueInstruction, MayHaveSideEffects, MayRelease)
645527
BRIDGED_SINGLE_VALUE_INST(BuiltinInst, builtin,
646528
SingleValueInstruction, MayHaveSideEffects, MayRelease)
647-
APPLYSITE_SINGLE_VALUE_INST(PartialApplyInst, partial_apply,
648-
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
529+
BRIDGED_SINGLE_VALUE_INST(PartialApplyInst, partial_apply,
530+
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
649531

650532
// Metatypes
651533
SINGLE_VALUE_INST(MetatypeInst, metatype,
@@ -780,8 +662,8 @@ ABSTRACT_INST(TermInst, SILInstruction)
780662
TermInst, MayHaveSideEffects, MayRelease)
781663
TERMINATOR(UnwindInst, unwind,
782664
TermInst, None, DoesNotRelease)
783-
FULLAPPLYSITE_TERMINATOR_INST(TryApplyInst, try_apply,
784-
TermInst, MayHaveSideEffects, MayRelease)
665+
TERMINATOR(TryApplyInst, try_apply,
666+
TermInst, MayHaveSideEffects, MayRelease)
785667
TERMINATOR(BranchInst, br,
786668
TermInst, None, DoesNotRelease)
787669
TERMINATOR(CondBranchInst, cond_br,
@@ -923,8 +805,8 @@ BRIDGED_NON_VALUE_INST(CondFailInst, cond_fail,
923805
NODE_RANGE(NonValueInstruction, UnreachableInst, CondFailInst)
924806

925807
ABSTRACT_INST(MultipleValueInstruction, SILInstruction)
926-
FULLAPPLYSITE_MULTIPLE_VALUE_INST(BeginApplyInst, begin_apply,
927-
MultipleValueInstruction, MayHaveSideEffects, MayRelease)
808+
MULTIPLE_VALUE_INST(BeginApplyInst, begin_apply,
809+
MultipleValueInstruction, MayHaveSideEffects, MayRelease)
928810

929811
// begin_cow_mutation is defined to have side effects, because it has
930812
// dependencies with instructions which retain the buffer operand. This prevents
@@ -952,19 +834,13 @@ NODE_RANGE(SILNode, SILPhiArgument, DestructureTupleInst)
952834
#undef ABSTRACT_VALUE
953835
#undef ABSTRACT_NODE
954836
#undef ABSTRACT_VALUE_AND_INST
955-
#undef FULLAPPLYSITE_TERMINATOR_INST
956-
#undef APPLYSITE_TERMINATOR_INST
957837
#undef DYNAMICCAST_TERMINATOR
958838
#undef TERMINATOR
959839
#undef NON_VALUE_INST
960840
#undef BRIDGED_NON_VALUE_INST
961841
#undef DYNAMICCAST_NON_VALUE_INST
962842
#undef MULTIPLE_VALUE_INST_RESULT
963-
#undef FULLAPPLYSITE_MULTIPLE_VALUE_INST
964-
#undef APPLYSITE_MULTIPLE_VALUE_INST
965843
#undef MULTIPLE_VALUE_INST
966-
#undef FULLAPPLYSITE_SINGLE_VALUE_INST
967-
#undef APPLYSITE_SINGLE_VALUE_INST
968844
#undef DYNAMICCAST_SINGLE_VALUE_INST
969845
#undef DYNAMICCAST_INST
970846
#undef SINGLE_VALUE_INST
@@ -974,5 +850,3 @@ NODE_RANGE(SILNode, SILPhiArgument, DestructureTupleInst)
974850
#undef ARGUMENT
975851
#undef VALUE
976852
#undef NODE
977-
#undef APPLYSITE_INST
978-
#undef FULLAPPLYSITE_INST

lib/SILOptimizer/Transforms/AllocBoxToStack.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,10 @@ class PromotedParamCloner : public SILClonerWithScopes<PromotedParamCloner> {
637637
void visitCopyValueInst(CopyValueInst *Inst);
638638
void visitProjectBoxInst(ProjectBoxInst *Inst);
639639
void checkNoPromotedBoxInApply(ApplySite Apply);
640-
#define APPLYSITE_INST(Name, Parent) void visit##Name(Name *Inst);
641-
#include "swift/SIL/SILNodes.def"
640+
void visitApplyInst(ApplyInst *Inst);
641+
void visitBeginApplyInst(BeginApplyInst *Inst);
642+
void visitPartialApplyInst(PartialApplyInst *Inst);
643+
void visitTryApplyInst(TryApplyInst *Inst);
642644
};
643645
} // end anonymous namespace
644646

0 commit comments

Comments
 (0)