• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- BufferAliasAnalysis.h - Buffer alias analysis for MLIR ---*- 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 #ifndef MLIR_ANALYSIS_BUFFERALIASANALYSIS_H
10 #define MLIR_ANALYSIS_BUFFERALIASANALYSIS_H
11 
12 #include "mlir/IR/Operation.h"
13 #include "llvm/ADT/SmallPtrSet.h"
14 
15 namespace mlir {
16 
17 /// A straight-forward alias analysis which ensures that all aliases of all
18 /// values will be determined. This is a requirement for the BufferPlacement
19 /// class since you need to determine safe positions to place alloc and
20 /// deallocs.
21 class BufferAliasAnalysis {
22 public:
23   using ValueSetT = SmallPtrSet<Value, 16>;
24   using ValueMapT = llvm::DenseMap<Value, ValueSetT>;
25 
26 public:
27   /// Constructs a new alias analysis using the op provided.
28   BufferAliasAnalysis(Operation *op);
29 
30   /// Find all immediate aliases this value could potentially have.
find(Value value)31   ValueMapT::const_iterator find(Value value) const {
32     return aliases.find(value);
33   }
34 
35   /// Returns the begin iterator to iterate over all aliases.
begin()36   ValueMapT::const_iterator begin() const { return aliases.begin(); }
37 
38   /// Returns the end iterator that can be used in combination with find.
end()39   ValueMapT::const_iterator end() const { return aliases.end(); }
40 
41   /// Find all immediate and indirect aliases this value could potentially
42   /// have. Note that the resulting set will also contain the value provided as
43   /// it is an alias of itself.
44   ValueSetT resolve(Value value) const;
45 
46   /// Removes the given values from all alias sets.
47   void remove(const SmallPtrSetImpl<Value> &aliasValues);
48 
49 private:
50   /// This function constructs a mapping from values to its immediate aliases.
51   void build(Operation *op);
52 
53   /// Maps values to all immediate aliases this value can have.
54   ValueMapT aliases;
55 };
56 
57 } // namespace mlir
58 
59 #endif // MLIR_ANALYSIS_BUFFERALIASANALYSIS_H
60