FLANG
TypeCode.h
1//===-- Optimizer/Support/TypeCode.h ----------------------------*- 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// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef FORTRAN_OPTIMIZER_SUPPORT_TYPECODE_H
14#define FORTRAN_OPTIMIZER_SUPPORT_TYPECODE_H
15
16#include "flang/ISO_Fortran_binding_wrapper.h"
17#include "llvm/Support/ErrorHandling.h"
18
19namespace fir {
20
21//===----------------------------------------------------------------------===//
22// Translations of category and bitwidths to the type codes defined in flang's
23// ISO_Fortran_binding.h.
24//===----------------------------------------------------------------------===//
25
26inline int characterBitsToTypeCode(unsigned bitwidth) {
27 // clang-format off
28 switch (bitwidth) {
29 case 8: return CFI_type_char;
30 case 16: return CFI_type_char16_t;
31 case 32: return CFI_type_char32_t;
32 default: llvm_unreachable("unsupported character size");
33 }
34 // clang-format on
35}
36
37inline int complexBitsToTypeCode(unsigned bitwidth) {
38 // clang-format off
39 switch (bitwidth) {
40 case 16: return CFI_type_half_float_Complex; // CFI_type_bfloat_Complex ?
41 case 32: return CFI_type_float_Complex;
42 case 64: return CFI_type_double_Complex;
43 case 80: return CFI_type_extended_double_Complex;
44 case 128: return CFI_type_float128_Complex;
45 default: llvm_unreachable("unsupported complex size");
46 }
47 // clang-format on
48}
49
50inline int integerBitsToTypeCode(unsigned bitwidth) {
51 // clang-format off
52 switch (bitwidth) {
53 case 8: return CFI_type_int8_t;
54 case 16: return CFI_type_int16_t;
55 case 32: return CFI_type_int32_t;
56 case 64: return CFI_type_int64_t;
57 case 128: return CFI_type_int128_t;
58 default: llvm_unreachable("unsupported integer size");
59 }
60 // clang-format on
61}
62
63inline int logicalBitsToTypeCode(unsigned bitwidth) {
64 // clang-format off
65 switch (bitwidth) {
66 case 8: return CFI_type_Bool;
67 case 16: return CFI_type_int_least16_t;
68 case 32: return CFI_type_int_least32_t;
69 case 64: return CFI_type_int_least64_t;
70 default: llvm_unreachable("unsupported logical size");
71 }
72 // clang-format on
73}
74
75inline int realBitsToTypeCode(unsigned bitwidth) {
76 // clang-format off
77 switch (bitwidth) {
78 case 16: return CFI_type_half_float; // CFI_type_bfloat ?
79 case 32: return CFI_type_float;
80 case 64: return CFI_type_double;
81 case 80: return CFI_type_extended_double;
82 case 128: return CFI_type_float128;
83 default: llvm_unreachable("unsupported real size");
84 }
85 // clang-format on
86}
87
88static constexpr int derivedToTypeCode() { return CFI_type_struct; }
89
90} // namespace fir
91
92#endif // FORTRAN_OPTIMIZER_SUPPORT_TYPECODE_H
Definition: AbstractConverter.h:31