Skip to content

Commit 8c05024

Browse files
committed
SIL: move the SILInstruction::MemoryBehavior enum out of SILInstruction into the swift namespace
1 parent 4445373 commit 8c05024

File tree

15 files changed

+68
-68
lines changed

15 files changed

+68
-68
lines changed

include/swift/SIL/SILFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ class SILFunction
10911091
void copyEffects(SILFunction *from);
10921092
bool hasArgumentEffects() const;
10931093
void visitArgEffects(std::function<void(int, int, bool)> c) const;
1094-
SILInstruction::MemoryBehavior getMemoryBehavior(bool observeRetains);
1094+
MemoryBehavior getMemoryBehavior(bool observeRetains);
10951095

10961096
Purpose getSpecialPurpose() const { return specialPurpose; }
10971097

include/swift/SIL/SILInstruction.h

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,28 @@ class SILPrintContext;
135135

136136
template <typename ImplClass> class SILClonerWithScopes;
137137

138+
enum class MemoryBehavior {
139+
None,
140+
/// The instruction may read memory.
141+
MayRead,
142+
/// The instruction may write to memory.
143+
/// This includes destroying or taking from memory (e.g. destroy_addr,
144+
/// copy_addr [take], load [take]).
145+
/// Although, physically, destroying or taking does not modify the memory,
146+
/// it is important to model it is a write. Optimizations must not assume
147+
/// that the value stored in memory is still available for loading after
148+
/// the memory is destroyed or taken.
149+
MayWrite,
150+
/// The instruction may read or write memory.
151+
MayReadWrite,
152+
/// The instruction may have side effects not captured
153+
/// solely by its users. Specifically, it can return,
154+
/// release memory, or store. Note, alloc is not considered
155+
/// to have side effects because its result/users represent
156+
/// its effect.
157+
MayHaveSideEffects,
158+
};
159+
138160
// An enum class for SILInstructions that enables exhaustive switches over
139161
// instructions.
140162
enum class SILInstructionKind : std::underlying_type<SILNodeKind>::type {
@@ -445,28 +467,6 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
445467
/// scheduled to be deleted.
446468
bool isDeleted() const { return asSILNode()->isMarkedAsDeleted(); }
447469

448-
enum class MemoryBehavior {
449-
None,
450-
/// The instruction may read memory.
451-
MayRead,
452-
/// The instruction may write to memory.
453-
/// This includes destroying or taking from memory (e.g. destroy_addr,
454-
/// copy_addr [take], load [take]).
455-
/// Although, physically, destroying or taking does not modify the memory,
456-
/// it is important to model it is a write. Optimizations must not assume
457-
/// that the value stored in memory is still available for loading after
458-
/// the memory is destroyed or taken.
459-
MayWrite,
460-
/// The instruction may read or write memory.
461-
MayReadWrite,
462-
/// The instruction may have side effects not captured
463-
/// solely by its users. Specifically, it can return,
464-
/// release memory, or store. Note, alloc is not considered
465-
/// to have side effects because its result/users represent
466-
/// its effect.
467-
MayHaveSideEffects,
468-
};
469-
470470
/// Enumeration representing whether the execution of an instruction can
471471
/// result in memory being released.
472472
enum class ReleasingBehavior {
@@ -776,7 +776,7 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
776776
/// Returns true if the instruction may write to memory, deinitialize memory,
777777
/// or have other unknown side effects.
778778
///
779-
/// For details see SILInstruction::MemoryBehavior.
779+
/// For details see MemoryBehavior.
780780
bool mayWriteToMemory() const {
781781
MemoryBehavior B = getMemoryBehavior();
782782
return B == MemoryBehavior::MayWrite ||
@@ -787,7 +787,7 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
787787
/// Returns true if the instruction may read from memory, or have other
788788
/// unknown side effects.
789789
///
790-
/// For details see SILInstruction::MemoryBehavior.
790+
/// For details see MemoryBehavior.
791791
bool mayReadFromMemory() const {
792792
MemoryBehavior B = getMemoryBehavior();
793793
return B == MemoryBehavior::MayRead ||
@@ -798,7 +798,7 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
798798
/// Returns true if the instruction may read from memory, write to memory,
799799
/// deinitialize memory, or have other unknown side effects.
800800
///
801-
/// For details see SILInstruction::MemoryBehavior.
801+
/// For details see MemoryBehavior.
802802
bool mayReadOrWriteMemory() const {
803803
return getMemoryBehavior() != MemoryBehavior::None;
804804
}
@@ -1061,23 +1061,23 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
10611061
}
10621062

10631063
/// Returns the combined behavior of \p B1 and \p B2.
1064-
inline SILInstruction::MemoryBehavior
1065-
combineMemoryBehavior(SILInstruction::MemoryBehavior B1,
1066-
SILInstruction::MemoryBehavior B2) {
1064+
inline MemoryBehavior
1065+
combineMemoryBehavior(MemoryBehavior B1,
1066+
MemoryBehavior B2) {
10671067
// Basically the combined behavior is the maximum of both operands.
10681068
auto Result = std::max(B1, B2);
10691069

10701070
// With one exception: MayRead, MayWrite -> MayReadWrite.
1071-
if (Result == SILInstruction::MemoryBehavior::MayWrite &&
1072-
(B1 == SILInstruction::MemoryBehavior::MayRead ||
1073-
B2 == SILInstruction::MemoryBehavior::MayRead))
1074-
return SILInstruction::MemoryBehavior::MayReadWrite;
1071+
if (Result == MemoryBehavior::MayWrite &&
1072+
(B1 == MemoryBehavior::MayRead ||
1073+
B2 == MemoryBehavior::MayRead))
1074+
return MemoryBehavior::MayReadWrite;
10751075
return Result;
10761076
}
10771077

10781078
/// Pretty-print the MemoryBehavior.
10791079
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
1080-
SILInstruction::MemoryBehavior B);
1080+
MemoryBehavior B);
10811081
/// Pretty-print the ReleasingBehavior.
10821082
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
10831083
SILInstruction::ReleasingBehavior B);

include/swift/SILOptimizer/Analysis/AliasAnalysis.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class AliasAnalysis {
8585
/// The alias() method uses this map to cache queries.
8686
llvm::DenseMap<AliasCacheKey, AliasResult> AliasCache;
8787

88-
using MemoryBehavior = SILInstruction::MemoryBehavior;
88+
using MemoryBehavior = MemoryBehavior;
8989

9090
/// MemoryBehavior value cache.
9191
///
@@ -169,7 +169,7 @@ class AliasAnalysis {
169169

170170
/// Returns true if \p Inst may read from memory at address \p V.
171171
///
172-
/// For details see SILInstruction::MemoryBehavior::MayRead.
172+
/// For details see MemoryBehavior::MayRead.
173173
bool mayReadFromMemory(SILInstruction *Inst, SILValue V) {
174174
auto B = computeMemoryBehavior(Inst, V);
175175
return B == MemoryBehavior::MayRead ||
@@ -180,7 +180,7 @@ class AliasAnalysis {
180180
/// Returns true if \p Inst may write to memory or deinitialize memory at
181181
/// address \p V.
182182
///
183-
/// For details see SILInstruction::MemoryBehavior::MayWrite.
183+
/// For details see MemoryBehavior::MayWrite.
184184
bool mayWriteToMemory(SILInstruction *Inst, SILValue V) {
185185
auto B = computeMemoryBehavior(Inst, V);
186186
return B == MemoryBehavior::MayWrite ||
@@ -191,7 +191,7 @@ class AliasAnalysis {
191191
/// Returns true if \p Inst may read from memory, write to memory or
192192
/// deinitialize memory at address \p V.
193193
///
194-
/// For details see SILInstruction::MemoryBehavior.
194+
/// For details see MemoryBehavior.
195195
bool mayReadOrWriteMemory(SILInstruction *Inst, SILValue V) {
196196
auto B = computeMemoryBehavior(Inst, V);
197197
return MemoryBehavior::None != B;

include/swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class BasicCalleeAnalysis : public SILAnalysis {
234234
return Cache->getDestructors(type, isExactType);
235235
}
236236

237-
SILInstruction::MemoryBehavior getMemoryBehavior(ApplySite as, bool observeRetains);
237+
MemoryBehavior getMemoryBehavior(ApplySite as, bool observeRetains);
238238
};
239239

240240
bool isDeinitBarrier(SILInstruction *const instruction,

lib/SIL/IR/SILFunction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,10 +1045,10 @@ visitArgEffects(std::function<void(int, int, bool)> c) const {
10451045
}
10461046
}
10471047

1048-
SILInstruction::MemoryBehavior SILFunction::getMemoryBehavior(bool observeRetains) {
1048+
MemoryBehavior SILFunction::getMemoryBehavior(bool observeRetains) {
10491049
if (!getMemBehvaiorFunction)
1050-
return SILInstruction::MemoryBehavior::MayHaveSideEffects;
1050+
return MemoryBehavior::MayHaveSideEffects;
10511051

10521052
auto b = getMemBehvaiorFunction({this}, observeRetains);
1053-
return (SILInstruction::MemoryBehavior)b;
1053+
return (MemoryBehavior)b;
10541054
}

lib/SIL/IR/SILInstruction.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ unsigned Operand::getOperandNumber() const {
973973
return this - &cast<SILInstruction>(getUser())->getAllOperands()[0];
974974
}
975975

976-
SILInstruction::MemoryBehavior SILInstruction::getMemoryBehavior() const {
976+
MemoryBehavior SILInstruction::getMemoryBehavior() const {
977977

978978
if (auto *BI = dyn_cast<BuiltinInst>(this)) {
979979
// Handle Swift builtin functions.
@@ -1374,17 +1374,17 @@ unsigned SILInstruction::getCachedCaseIndex(EnumElementDecl *enumElement) {
13741374
//===----------------------------------------------------------------------===//
13751375

13761376
llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &OS,
1377-
SILInstruction::MemoryBehavior B) {
1377+
MemoryBehavior B) {
13781378
switch (B) {
1379-
case SILInstruction::MemoryBehavior::None:
1379+
case MemoryBehavior::None:
13801380
return OS << "None";
1381-
case SILInstruction::MemoryBehavior::MayRead:
1381+
case MemoryBehavior::MayRead:
13821382
return OS << "MayRead";
1383-
case SILInstruction::MemoryBehavior::MayWrite:
1383+
case MemoryBehavior::MayWrite:
13841384
return OS << "MayWrite";
1385-
case SILInstruction::MemoryBehavior::MayReadWrite:
1385+
case MemoryBehavior::MayReadWrite:
13861386
return OS << "MayReadWrite";
1387-
case SILInstruction::MemoryBehavior::MayHaveSideEffects:
1387+
case MemoryBehavior::MayHaveSideEffects:
13881388
return OS << "MayHaveSideEffects";
13891389
}
13901390

lib/SILOptimizer/Analysis/AccessStorageAnalysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,15 @@ bool FunctionAccessStorage::summarizeFunction(SILFunction *F) {
359359
// If FunctionSideEffects can be summarized, use that information.
360360

361361
auto b = F->getMemoryBehavior(/*observeRetains*/ false);
362-
if (b == SILInstruction::MemoryBehavior::MayHaveSideEffects) {
362+
if (b == MemoryBehavior::MayHaveSideEffects) {
363363
setWorstEffects();
364364
// May as well consider this a successful summary since there are no
365365
// instructions to visit anyway.
366366
return true;
367367
}
368-
if (b >= SILInstruction::MemoryBehavior::MayWrite) {
368+
if (b >= MemoryBehavior::MayWrite) {
369369
accessResult.setUnidentifiedAccess(SILAccessKind::Modify);
370-
} else if (b == SILInstruction::MemoryBehavior::MayRead) {
370+
} else if (b == MemoryBehavior::MayRead) {
371371
accessResult.setUnidentifiedAccess(SILAccessKind::Read);
372372
}
373373

lib/SILOptimizer/Analysis/AliasAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ void AliasAnalysis_register(AliasAnalysisGetMemEffectFn getMemEffectsFn,
724724
canReferenceSameFieldFunction = canReferenceSameFieldFn;
725725
}
726726

727-
SILInstruction::MemoryBehavior AliasAnalysis::getMemoryBehaviorOfInst(
727+
MemoryBehavior AliasAnalysis::getMemoryBehaviorOfInst(
728728
SILValue addr, SILInstruction *toInst) {
729729
if (getMemEffectsFunction) {
730730
return (MemoryBehavior)getMemEffectsFunction({PM->getSwiftPassInvocation()}, {addr},

lib/SILOptimizer/Analysis/BasicCalleeAnalysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,15 @@ void CalleeAnalysis_register(
377377
getMemBehvaiorFunction = getMemBehvaiorFn;
378378
}
379379

380-
SILInstruction::MemoryBehavior BasicCalleeAnalysis::
380+
MemoryBehavior BasicCalleeAnalysis::
381381
getMemoryBehavior(ApplySite as, bool observeRetains) {
382382
if (getMemBehvaiorFunction) {
383383
auto b = getMemBehvaiorFunction({pm->getSwiftPassInvocation()},
384384
{as.getInstruction()->asSILNode()},
385385
observeRetains);
386-
return (SILInstruction::MemoryBehavior)b;
386+
return (MemoryBehavior)b;
387387
}
388-
return SILInstruction::MemoryBehavior::MayHaveSideEffects;
388+
return MemoryBehavior::MayHaveSideEffects;
389389
}
390390

391391
bool swift::isDeinitBarrier(SILInstruction *const instruction,

lib/SILOptimizer/Analysis/MemoryBehavior.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace swift;
2929

3030
namespace {
3131

32-
using MemBehavior = SILInstruction::MemoryBehavior;
32+
using MemBehavior = MemoryBehavior;
3333

3434
/// Visitor that determines the memory behavior of an instruction relative to a
3535
/// specific SILValue (i.e. can the instruction cause the value to be read,
@@ -136,7 +136,7 @@ class MemoryBehaviorVisitor
136136
case SILAccessKind::Deinit:
137137
// For the same reason we treat a ``load [take]`` or a ``destroy_addr``
138138
// as a memory write, we do that for a ``begin_access [deinit]`` as well.
139-
// See SILInstruction::MemoryBehavior.
139+
// See MemoryBehavior.
140140
return MemBehavior::MayReadWrite;
141141
case SILAccessKind::Read:
142142
return MemBehavior::MayRead;

0 commit comments

Comments
 (0)