1 //===- AliasAnalysis.cpp - Alias Analysis for MLIR ------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "mlir/Analysis/AliasAnalysis.h"
10 #include "mlir/Analysis/AliasAnalysis/LocalAliasAnalysis.h"
11 #include "mlir/IR/Operation.h"
12 #include "mlir/IR/Value.h"
13 #include "mlir/Support/LLVM.h"
18 //===----------------------------------------------------------------------===//
20 //===----------------------------------------------------------------------===//
22 /// Merge this alias result with `other` and return a new result that
23 /// represents the conservative merge of both results.
24 AliasResult
AliasResult::merge(AliasResult other
) const {
25 if (kind
== other
.kind
)
27 // A mix of PartialAlias and MustAlias is PartialAlias.
28 if ((isPartial() && other
.isMust()) || (other
.isPartial() && isMust()))
30 // Otherwise, don't assume anything.
34 void AliasResult::print(raw_ostream
&os
) const {
42 case Kind::PartialAlias
:
51 //===----------------------------------------------------------------------===//
53 //===----------------------------------------------------------------------===//
55 void ModRefResult::print(raw_ostream
&os
) const {
72 //===----------------------------------------------------------------------===//
74 //===----------------------------------------------------------------------===//
76 AliasAnalysis::AliasAnalysis(Operation
*op
) {
77 addAnalysisImplementation(LocalAliasAnalysis());
80 AliasResult
AliasAnalysis::alias(Value lhs
, Value rhs
) {
81 // Check each of the alias analysis implemenations for an alias result.
82 for (const std::unique_ptr
<Concept
> &aliasImpl
: aliasImpls
) {
83 AliasResult result
= aliasImpl
->alias(lhs
, rhs
);
87 return AliasResult::MayAlias
;
90 ModRefResult
AliasAnalysis::getModRef(Operation
*op
, Value location
) {
91 // Compute the mod-ref behavior by refining a top `ModRef` result with each of
92 // the alias analysis implementations. We early exit at the point where we
93 // refine down to a `NoModRef`.
94 ModRefResult result
= ModRefResult::getModAndRef();
95 for (const std::unique_ptr
<Concept
> &aliasImpl
: aliasImpls
) {
96 result
= result
.intersect(aliasImpl
->getModRef(op
, location
));
97 if (result
.isNoModRef())