-
Notifications
You must be signed in to change notification settings - Fork 329
/
Copy pathTypeUtilities.hpp
44 lines (39 loc) · 1.4 KB
/
TypeUtilities.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* SPDX-License-Identifier: Apache-2.0
*/
//====---------- TypeUtilities.hpp - functions related to MLIR Type -------===//
//
// Copyright 2022-2024 The IBM Research Authors.
//
// =============================================================================
//
// This file contains support code related to MLIR Type, e.g. RankedTensorType,
// MemRefType, etc.
//
//===----------------------------------------------------------------------===//
#ifndef ONNX_MLIR_TYPE_UTILITIES_H
#define ONNX_MLIR_TYPE_UTILITIES_H
#include "mlir/IR/BuiltinTypes.h"
namespace onnx_mlir {
/// Get element type.
mlir::Type getElementType(mlir::Type ty);
/// Check if a type is ShapedType and has rank.
bool isRankedShapedType(mlir::Type ty);
/// Check if a type has static shape.
bool hasStaticShape(mlir::Type ty);
/// Get shape.
llvm::ArrayRef<int64_t> getShape(mlir::Type ty);
/// Get rank.
int64_t getRank(mlir::Type ty);
/// Get the number of elements.
int64_t getNumberOfElements(mlir::ShapedType ty);
/// Get the element size in bytes.
int64_t getEltSizeInBytes(mlir::Type ty);
/// Get the size of a tensor from its ranked type in bytes.
int64_t getSizeInBytes(mlir::ShapedType ty);
/// Check if two RankedTensorTypes have the same encoding attribute or not.
bool sameEncodingAttr(mlir::Type t1, mlir::Type t2);
/// Get the byte width of an int or float type.
unsigned getIntOrFloatByteWidth(mlir::Type ty);
} // namespace onnx_mlir
#endif