clang 24.0.0git
CIRBasicAliasAnalysis.h
Go to the documentation of this file.
1//===- CIRBasicAliasAnalysis.h - Basic CIR Alias Analysis -------*- C++ -*-===//
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// This file defines CIRBasicAliasAnalysis, a CIR-specific alias analysis
10// implementation based on pointer provenance and distinct allocation sites.
11// Register with an mlir::AliasAnalysis aggregate via
12// addAnalysisImplementation(), or use registerCIRAliasAnalyses() to add the
13// full suite of CIR analyses at once.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef CLANG_CIR_DIALECT_ANALYSIS_CIRBASICALIASANALYSIS_H
18#define CLANG_CIR_DIALECT_ANALYSIS_CIRBASICALIASANALYSIS_H
19
20#include "mlir/Analysis/AliasAnalysis.h"
21#include "mlir/IR/Operation.h"
22#include "mlir/IR/Value.h"
23
24namespace cir {
25
26/// Basic CIR alias analysis based on pointer provenance and distinct allocation
27/// sites. Conservative defaults (MayAlias / ModRef) are returned for cases
28/// that are not yet handled.
30public:
33
34 /// Return the aliasing behavior between two values.
35 ///
36 /// Returns MayAlias conservatively unless a more precise result can be
37 /// determined from CIR-specific information (e.g. distinct alloca ops,
38 /// pointer provenance, restrict attributes).
39 mlir::AliasResult alias(mlir::Value lhs, mlir::Value rhs);
40
41 /// Return the modify-reference behavior of `op` on `location`.
42 ///
43 /// Returns ModRef conservatively. CIR ops that carry explicit memory-effect
44 /// attributes or that are known to be pure/read-only can be handled here.
45 mlir::ModRefResult getModRef(mlir::Operation *op, mlir::Value location);
46
47private:
48 /// Attempt to find the underlying allocation source for `val` by walking
49 /// through pointer arithmetic, casts, and other CIR ops. Returns `val` if
50 /// no more specific source is found.
51 mlir::Value getUnderlyingObject(mlir::Value val);
52
53 /// Return true if `lhs` and `rhs` are provably different allocations and
54 /// therefore cannot alias.
55 bool areDistinctObjects(mlir::Value lhs, mlir::Value rhs);
56};
57
58} // namespace cir
59
60#endif // CLANG_CIR_DIALECT_ANALYSIS_CIRBASICALIASANALYSIS_H
mlir::ModRefResult getModRef(mlir::Operation *op, mlir::Value location)
Return the modify-reference behavior of op on location.
CIRBasicAliasAnalysis(CIRBasicAliasAnalysis &&)=default
mlir::AliasResult alias(mlir::Value lhs, mlir::Value rhs)
Return the aliasing behavior between two values.