My Project
TypeUtilities.h
Go to the documentation of this file.
1 //===- TypeUtilities.h - Helper function for type queries -------*- C++ -*-===//
2 //
3 // Part of the MLIR 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 generic type utilities.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_SUPPORT_TYPEUTILITIES_H
14 #define MLIR_SUPPORT_TYPEUTILITIES_H
15 
16 #include "mlir/IR/Operation.h"
17 #include "llvm/ADT/STLExtras.h"
18 
19 namespace mlir {
20 
21 class Attribute;
22 class TupleType;
23 class Type;
24 class Value;
25 
26 //===----------------------------------------------------------------------===//
27 // Utility Functions
28 //===----------------------------------------------------------------------===//
29 
32 
34 Type getElementTypeOrSelf(Attribute attr);
35 Type getElementTypeOrSelf(Value val);
36 
39 SmallVector<Type, 10> getFlattenedTypes(TupleType t);
40 
43 bool isOpaqueTypeWithName(Type type, StringRef dialect, StringRef typeData);
44 
48 LogicalResult verifyCompatibleShape(ArrayRef<int64_t> shape1,
49  ArrayRef<int64_t> shape2);
50 
56 LogicalResult verifyCompatibleShape(Type type1, Type type2);
57 
58 //===----------------------------------------------------------------------===//
59 // Utility Iterators
60 //===----------------------------------------------------------------------===//
61 
62 // An iterator for the element types of an op's operands of shaped types.
64  : public llvm::mapped_iterator<Operation::operand_iterator,
65  Type (*)(Value)> {
66 public:
67  using reference = Type;
68 
72 
73 private:
74  static Type unwrap(Value value);
75 };
76 
78 
79 // An iterator for the tensor element types of an op's results of shaped types.
81  : public llvm::mapped_iterator<Operation::result_iterator,
82  Type (*)(Value)> {
83 public:
84  using reference = Type;
85 
89 
90 private:
91  static Type unwrap(Value value);
92 };
93 
95 
96 } // end namespace mlir
97 
98 #endif // MLIR_SUPPORT_TYPEUTILITIES_H
operand_range::iterator operand_iterator
Definition: Operation.h:214
Definition: InferTypeOpInterface.cpp:20
LogicalResult verifyCompatibleShape(ArrayRef< int64_t > shape1, ArrayRef< int64_t > shape2)
Definition: TypeUtilities.cpp:54
Definition: Attributes.h:139
SmallVector< Type, 10 > getFlattenedTypes(TupleType t)
Definition: TypeUtilities.cpp:35
bool isOpaqueTypeWithName(Type type, StringRef dialect, StringRef typeData)
Definition: TypeUtilities.cpp:43
OperandElementTypeIterator(Operation::operand_iterator it)
Definition: TypeUtilities.cpp:89
Type getElementTypeOrSelf(Type type)
Return the element type or return the type itself.
Definition: TypeUtilities.cpp:21
Definition: TypeUtilities.h:80
Definition: TypeUtilities.h:63
Definition: Types.h:84
Definition: Value.h:38
Definition: LLVM.h:50
result_range::iterator result_iterator
Definition: Operation.h:250