Skip to content

SIL: improve comments for the mayRead/mayWrite APIs in SILInstruction and AliasAnalysis #35262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,19 @@ class SILInstruction

/// Returns true if the instruction may write to memory, deinitialize memory,
/// or have other unknown side effects.
///
/// For details see SILInstruction::MemoryBehavior.
bool mayWriteToMemory() const {
MemoryBehavior B = getMemoryBehavior();
return B == MemoryBehavior::MayWrite ||
B == MemoryBehavior::MayReadWrite ||
B == MemoryBehavior::MayHaveSideEffects;
}

/// Returns true if the instruction may read from memory.
/// Returns true if the instruction may read from memory, or have other
/// unknown side effects.
///
/// For details see SILInstruction::MemoryBehavior.
bool mayReadFromMemory() const {
MemoryBehavior B = getMemoryBehavior();
return B == MemoryBehavior::MayRead ||
Expand All @@ -639,6 +644,8 @@ class SILInstruction

/// Returns true if the instruction may read from memory, write to memory,
/// deinitialize memory, or have other unknown side effects.
///
/// For details see SILInstruction::MemoryBehavior.
bool mayReadOrWriteMemory() const {
return getMemoryBehavior() != MemoryBehavior::None;
}
Expand Down
17 changes: 11 additions & 6 deletions include/swift/SILOptimizer/Analysis/AliasAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,26 +215,31 @@ class AliasAnalysis : public SILAnalysis {
/// respect to V.
MemoryBehavior computeMemoryBehaviorInner(SILInstruction *Inst, SILValue V);

/// Returns true if \p Inst may read from memory in a manner that
/// affects V.
/// Returns true if \p Inst may read from memory at address \p V.
///
/// For details see SILInstruction::MemoryBehavior::MayRead.
bool mayReadFromMemory(SILInstruction *Inst, SILValue V) {
auto B = computeMemoryBehavior(Inst, V);
return B == MemoryBehavior::MayRead ||
B == MemoryBehavior::MayReadWrite ||
B == MemoryBehavior::MayHaveSideEffects;
}

/// Returns true if \p Inst may write to memory, deinitialize memory, or have
/// other side effects that may affect V.
/// Returns true if \p Inst may write to memory or deinitialize memory at
/// address \p V.
///
/// For details see SILInstruction::MemoryBehavior::MayWrite.
bool mayWriteToMemory(SILInstruction *Inst, SILValue V) {
auto B = computeMemoryBehavior(Inst, V);
return B == MemoryBehavior::MayWrite ||
B == MemoryBehavior::MayReadWrite ||
B == MemoryBehavior::MayHaveSideEffects;
}

/// Returns true if \p Inst may read to memory, write to memory, deinitialize
/// memory, or have other side effects that may affect V.
/// Returns true if \p Inst may read from memory, write to memory or
/// deinitialize memory at address \p V.
///
/// For details see SILInstruction::MemoryBehavior.
bool mayReadOrWriteMemory(SILInstruction *Inst, SILValue V) {
auto B = computeMemoryBehavior(Inst, V);
return MemoryBehavior::None != B;
Expand Down