1 //===- LLVM.h - Import and forward declare core LLVM types ------*- 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 forward declares and imports various common LLVM datatypes that
10 // MLIR wants to use unqualified.
11 //
12 // Note that most of these are forward declared and then imported into the MLIR
13 // namespace with using decls, rather than being #included.  This is because we
14 // want clients to explicitly #include the files they need.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef MLIR_SUPPORT_LLVM_H
19 #define MLIR_SUPPORT_LLVM_H
20 
21 // We include these two headers because they cannot be practically forward
22 // declared, and are effectively language features.
23 #include "llvm/ADT/None.h"
24 #include "llvm/Support/Casting.h"
25 #include <vector>
26 
27 // Workaround for clang-5 (PR41549)
28 #if defined(__clang_major__)
29 #if __clang_major__ <= 5
30 #include "llvm/ADT/DenseMapInfo.h"
31 #include "llvm/ADT/SmallVector.h"
32 #endif
33 #endif
34 
35 // Forward declarations.
36 namespace llvm {
37 // String types
38 template <unsigned N>
39 class SmallString;
40 class StringRef;
41 class StringLiteral;
42 class Twine;
43 
44 // Containers.
45 template <typename T>
46 class ArrayRef;
47 class BitVector;
48 namespace detail {
49 template <typename KeyT, typename ValueT>
50 struct DenseMapPair;
51 } // namespace detail
52 template <typename KeyT, typename ValueT, typename KeyInfoT, typename BucketT>
53 class DenseMap;
54 template <typename T, typename Enable>
55 struct DenseMapInfo;
56 template <typename ValueT, typename ValueInfoT>
57 class DenseSet;
58 class MallocAllocator;
59 template <typename T>
60 class MutableArrayRef;
61 template <typename T>
62 class Optional;
63 template <typename... PT>
64 class PointerUnion;
65 template <typename T, typename Vector, typename Set>
66 class SetVector;
67 template <typename T, unsigned N>
68 class SmallPtrSet;
69 template <typename T>
70 class SmallPtrSetImpl;
71 template <typename T, unsigned N>
72 class SmallVector;
73 template <typename T>
74 class SmallVectorImpl;
75 template <typename AllocatorTy>
76 class StringSet;
77 template <typename T, typename R>
78 class StringSwitch;
79 template <typename T>
80 class TinyPtrVector;
81 template <typename T, typename ResultT>
82 class TypeSwitch;
83 
84 // Other common classes.
85 class APInt;
86 class APSInt;
87 class APFloat;
88 template <typename Fn>
89 class function_ref;
90 template <typename IteratorT>
91 class iterator_range;
92 class raw_ostream;
93 class SMLoc;
94 class SMRange;
95 } // namespace llvm
96 
97 namespace mlir {
98 // Casting operators.
99 using llvm::cast;
100 using llvm::cast_or_null;
101 using llvm::dyn_cast;
102 using llvm::dyn_cast_or_null;
103 using llvm::isa;
104 using llvm::isa_and_nonnull;
105 
106 // String types
107 using llvm::SmallString;
108 using llvm::StringLiteral;
109 using llvm::StringRef;
110 using llvm::Twine;
111 
112 // Container Related types
113 //
114 // Containers.
115 using llvm::ArrayRef;
116 using llvm::BitVector;
117 template <typename T, typename Enable = void>
118 using DenseMapInfo = llvm::DenseMapInfo<T, Enable>;
119 template <typename KeyT, typename ValueT,
120           typename KeyInfoT = DenseMapInfo<KeyT>,
121           typename BucketT = llvm::detail::DenseMapPair<KeyT, ValueT>>
122 using DenseMap = llvm::DenseMap<KeyT, ValueT, KeyInfoT, BucketT>;
123 template <typename ValueT, typename ValueInfoT = DenseMapInfo<ValueT>>
124 using DenseSet = llvm::DenseSet<ValueT, ValueInfoT>;
125 template <typename T, typename Vector = std::vector<T>,
126           typename Set = DenseSet<T>>
127 using SetVector = llvm::SetVector<T, Vector, Set>;
128 template <typename AllocatorTy = llvm::MallocAllocator>
129 using StringSet = llvm::StringSet<AllocatorTy>;
130 using llvm::MutableArrayRef;
131 using llvm::None;
132 using llvm::Optional;
133 using llvm::PointerUnion;
134 using llvm::SmallPtrSet;
135 using llvm::SmallPtrSetImpl;
136 using llvm::SmallVector;
137 using llvm::SmallVectorImpl;
138 template <typename T, typename R = T>
139 using StringSwitch = llvm::StringSwitch<T, R>;
140 using llvm::TinyPtrVector;
141 template <typename T, typename ResultT = void>
142 using TypeSwitch = llvm::TypeSwitch<T, ResultT>;
143 
144 // Other common classes.
145 using llvm::APFloat;
146 using llvm::APInt;
147 using llvm::APSInt;
148 template <typename Fn>
149 using function_ref = llvm::function_ref<Fn>;
150 using llvm::iterator_range;
151 using llvm::raw_ostream;
152 using llvm::SMLoc;
153 using llvm::SMRange;
154 } // namespace mlir
155 
156 #endif // MLIR_SUPPORT_LLVM_H
157