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.
30 enum class ObjectRelation {
31 /// Provably different underlying allocations.
32 Distinct,
33 /// Same underlying allocation, no offset.
34 Identical,
35 /// Cannot determine the relationship.
36 Unknown,
37 };
38
39public:
42
43 /// Return the aliasing behavior between two values.
44 ///
45 /// Returns MayAlias conservatively unless a more precise result can be
46 /// determined from CIR-specific information (e.g. distinct alloca ops,
47 /// pointer provenance, restrict attributes).
48 mlir::AliasResult alias(mlir::Value lhs, mlir::Value rhs);
49
50 /// Return the modify-reference behavior of `op` on `location`.
51 ///
52 /// Returns ModRef conservatively. CIR ops that carry explicit memory-effect
53 /// attributes or that are known to be pure/read-only can be handled here.
54 mlir::ModRefResult getModRef(mlir::Operation *op, mlir::Value location);
55
56private:
57 /// Attempt to find the underlying allocation source for `val` by walking
58 /// through pointer arithmetic, casts, and other CIR ops. Returns `val` if
59 /// no more specific source is found.
60 mlir::Value getUnderlyingObject(mlir::Value val);
61
62 /// Classify the relationship between \p lhs and \p rhs. Returns one of:
63 /// Distinct – provably different allocations
64 /// Identical – same allocation, no offset
65 /// Unknown – cannot determine
66 ObjectRelation classifyObjects(mlir::Value lhs, mlir::Value rhs);
67};
68
69} // namespace cir
70
71#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.