xref: /llvm-project/mlir/include/mlir/Analysis/DataLayoutAnalysis.h (revision 7557530f428a2f226d8d925c33d527dfcfdcb0c5)
1 //===- DataLayoutAnalysis.h - API for Querying Nested Data Layout -*- 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_DATALAYOUTANALYSIS_H
10 #define MLIR_ANALYSIS_DATALAYOUTANALYSIS_H
11 
12 #include "mlir/Support/LLVM.h"
13 #include "llvm/ADT/DenseMap.h"
14 
15 #include <memory>
16 
17 namespace mlir {
18 
19 class Operation;
20 class DataLayout;
21 
22 /// Stores data layout objects for each operation that specifies the data layout
23 /// above and below the given operation.
24 class DataLayoutAnalysis {
25 public:
26   /// Constructs the data layouts.
27   explicit DataLayoutAnalysis(Operation *root);
28 
29   /// Returns the data layout active at the given operation, that is the
30   /// data layout specified by the closest ancestor that can specify one, or the
31   /// default layout if there is no such ancestor.
32   const DataLayout &getAbove(Operation *operation) const;
33 
34   /// Returns the data layout specified by the given operation or its closest
35   /// ancestor that can specify one.
36   const DataLayout &getAtOrAbove(Operation *operation) const;
37 
38 private:
39   /// Storage for individual data layouts.
40   DenseMap<Operation *, std::unique_ptr<DataLayout>> layouts;
41 
42   /// Default data layout in case no operations specify one.
43   std::unique_ptr<DataLayout> defaultLayout;
44 };
45 
46 } // namespace mlir
47 
48 #endif // MLIR_ANALYSIS_DATALAYOUTANALYSIS_H
49