@@ -135,6 +135,28 @@ class SILPrintContext;
135135
136136template <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.
140162enum 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.
10791079llvm::raw_ostream &operator <<(llvm::raw_ostream &OS,
1080- SILInstruction:: MemoryBehavior B);
1080+ MemoryBehavior B);
10811081// / Pretty-print the ReleasingBehavior.
10821082llvm::raw_ostream &operator <<(llvm::raw_ostream &OS,
10831083 SILInstruction::ReleasingBehavior B);
0 commit comments