Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / compiler / luci / pass / src / helpers / TypeMapper.h
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __LUCI_PASS_HELPERS_TYPE_MAPPER_H__
18 #define __LUCI_PASS_HELPERS_TYPE_MAPPER_H__
19
20 #include <loco/IR/DataType.h>
21
22 #include <cstdint>
23
24 namespace luci
25 {
26
27 /**
28  * @brief TypeMapper maps between c++ primitive data type and loco::DataType.
29  */
30 template <typename T> struct TypeMapper
31 {
32   static constexpr loco::DataType get() { return loco::DataType::Unknown; }
33 };
34
35 template <> struct TypeMapper<float>
36 {
37   static constexpr loco::DataType get() { return loco::DataType::FLOAT32; }
38 };
39
40 template <> struct TypeMapper<uint8_t>
41 {
42   static constexpr loco::DataType get() { return loco::DataType::U8; }
43 };
44
45 template <> struct TypeMapper<uint16_t>
46 {
47   static constexpr loco::DataType get() { return loco::DataType::U16; }
48 };
49
50 template <> struct TypeMapper<uint32_t>
51 {
52   static constexpr loco::DataType get() { return loco::DataType::U32; }
53 };
54
55 template <> struct TypeMapper<uint64_t>
56 {
57   static constexpr loco::DataType get() { return loco::DataType::U64; }
58 };
59
60 template <> struct TypeMapper<int8_t>
61 {
62   static constexpr loco::DataType get() { return loco::DataType::S8; }
63 };
64
65 template <> struct TypeMapper<int16_t>
66 {
67   static constexpr loco::DataType get() { return loco::DataType::S16; }
68 };
69
70 template <> struct TypeMapper<int32_t>
71 {
72   static constexpr loco::DataType get() { return loco::DataType::S32; }
73 };
74
75 template <> struct TypeMapper<int64_t>
76 {
77   static constexpr loco::DataType get() { return loco::DataType::S64; }
78 };
79
80 } // namespace luci
81
82 #endif // __LUCI_PASS_HELPERS_TYPE_MAPPER_H__