1 | //===- Unit.h - IR Unit definition--------------------*- 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_IR_UNIT_H |
10 | #define MLIR_IR_UNIT_H |
11 | |
12 | #include "mlir/IR/OperationSupport.h" |
13 | #include "llvm/ADT/PointerUnion.h" |
14 | #include "llvm/Support/raw_ostream.h" |
15 | |
16 | namespace llvm { |
17 | class raw_ostream; |
18 | } // namespace llvm |
19 | namespace mlir { |
20 | class Operation; |
21 | class Region; |
22 | class Block; |
23 | class Value; |
24 | |
25 | /// IRUnit is a union of the different types of IR objects that consistute the |
26 | /// IR structure (other than Type and Attribute), that is Operation, Region, and |
27 | /// Block. |
28 | class IRUnit : public PointerUnion<Operation *, Region *, Block *, Value> { |
29 | public: |
30 | using PointerUnion::PointerUnion; |
31 | |
32 | /// Print the IRUnit to the given stream. |
33 | void print(raw_ostream &os, |
34 | OpPrintingFlags flags = |
35 | OpPrintingFlags().skipRegions().useLocalScope()) const; |
36 | }; |
37 | |
38 | raw_ostream &operator<<(raw_ostream &os, const IRUnit &unit); |
39 | |
40 | } // end namespace mlir |
41 | |
42 | namespace llvm { |
43 | |
44 | // Allow llvm::cast style functions. |
45 | template <typename To> |
46 | struct CastInfo<To, mlir::IRUnit> |
47 | : public CastInfo<To, mlir::IRUnit::PointerUnion> {}; |
48 | |
49 | template <typename To> |
50 | struct CastInfo<To, const mlir::IRUnit> |
51 | : public CastInfo<To, const mlir::IRUnit::PointerUnion> {}; |
52 | |
53 | } // namespace llvm |
54 | |
55 | #endif // MLIR_IR_UNIT_H |
56 | |