1 //===- AliasAnalysis.cpp - Alias Analysis for MLIR ------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "mlir/Analysis/AliasAnalysis.h" 10 #include "mlir/Analysis/AliasAnalysis/LocalAliasAnalysis.h" 11 12 using namespace mlir; 13 14 //===----------------------------------------------------------------------===// 15 // AliasResult 16 //===----------------------------------------------------------------------===// 17 18 /// Merge this alias result with `other` and return a new result that 19 /// represents the conservative merge of both results. 20 AliasResult AliasResult::merge(AliasResult other) const { 21 if (kind == other.kind) 22 return *this; 23 // A mix of PartialAlias and MustAlias is PartialAlias. 24 if ((isPartial() && other.isMust()) || (other.isPartial() && isMust())) 25 return PartialAlias; 26 // Otherwise, don't assume anything. 27 return MayAlias; 28 } 29 30 //===----------------------------------------------------------------------===// 31 // AliasAnalysis 32 //===----------------------------------------------------------------------===// 33 34 AliasAnalysis::AliasAnalysis(Operation *op) { 35 addAnalysisImplementation(LocalAliasAnalysis()); 36 } 37 38 /// Given the two values, return their aliasing behavior. 39 AliasResult AliasAnalysis::alias(Value lhs, Value rhs) { 40 // Check each of the alias analysis implemenations for an alias result. 41 for (const std::unique_ptr<Concept> &aliasImpl : aliasImpls) { 42 AliasResult result = aliasImpl->alias(lhs, rhs); 43 if (!result.isMay()) 44 return result; 45 } 46 return AliasResult::MayAlias; 47 } 48