|
| 1 | +//===--- AliasAnalysis.swift - the alias analysis -------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +import OptimizerBridging |
| 14 | +import SIL |
| 15 | + |
| 16 | +struct AliasAnalysis { |
| 17 | + let bridged: BridgedAliasAnalysis |
| 18 | + |
| 19 | + func mayRead(_ inst: Instruction, fromAddress: Value) -> Bool { |
| 20 | + switch AliasAnalysis_getMemBehavior(bridged, inst.bridged, fromAddress.bridged) { |
| 21 | + case MayReadBehavior, MayReadWriteBehavior, MayHaveSideEffectsBehavior: |
| 22 | + return true |
| 23 | + default: |
| 24 | + return false |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + func mayWrite(_ inst: Instruction, toAddress: Value) -> Bool { |
| 29 | + switch AliasAnalysis_getMemBehavior(bridged, inst.bridged, toAddress.bridged) { |
| 30 | + case MayWriteBehavior, MayReadWriteBehavior, MayHaveSideEffectsBehavior: |
| 31 | + return true |
| 32 | + default: |
| 33 | + return false |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + func mayReadOrWrite(_ inst: Instruction, address: Value) -> Bool { |
| 38 | + switch AliasAnalysis_getMemBehavior(bridged, inst.bridged, address.bridged) { |
| 39 | + case MayReadBehavior, MayWriteBehavior, MayReadWriteBehavior, |
| 40 | + MayHaveSideEffectsBehavior: |
| 41 | + return true |
| 42 | + default: |
| 43 | + return false |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments