FLANG

KindMapping.h
1 //===-- Optimizer/Support/KindMapping.h -- support kind mapping -*- 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 #ifndef OPTIMIZER_SUPPORT_KINDMAPPING_H
10 #define OPTIMIZER_SUPPORT_KINDMAPPING_H
11
12 #include "mlir/IR/OpDefinition.h"
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/IR/Type.h"
15
16 namespace llvm {
17 struct fltSemantics;
18 } // namespace llvm
19
20 namespace fir {
21
43 class KindMapping {
44 public:
45 using KindTy = unsigned;
46 using Bitsize = unsigned;
47 using LLVMTypeID = llvm::Type::TypeID;
48 using MatchResult = mlir::ParseResult;
49
50 explicit KindMapping(mlir::MLIRContext *context);
51 explicit KindMapping(mlir::MLIRContext *context, llvm::StringRef map);
52
54 Bitsize getCharacterBitsize(KindTy kind) const;
55
57 Bitsize getIntegerBitsize(KindTy kind) const;
58
60 Bitsize getLogicalBitsize(KindTy kind) const;
61
63 Bitsize getRealBitsize(KindTy kind) const;
64
66 LLVMTypeID getRealTypeID(KindTy kind) const;
67
69 LLVMTypeID getComplexTypeID(KindTy kind) const;
70
71 mlir::MLIRContext *getContext() const { return context; }
72
74 const llvm::fltSemantics &getFloatSemantics(KindTy kind) const;
75
76 private:
77 MatchResult badMapString(const llvm::Twine &ptr);
78 MatchResult parse(llvm::StringRef kindMap);
79
80 mlir::MLIRContext *context;
81 llvm::DenseMap<std::pair<char, KindTy>, Bitsize> intMap;
82 llvm::DenseMap<std::pair<char, KindTy>, LLVMTypeID> floatMap;
83 };
84
85 } // namespace fir
86
87 #endif // OPTIMIZER_SUPPORT_KINDMAPPING_H
fir::KindMapping::getRealTypeID
LLVMTypeID getRealTypeID(KindTy kind) const
Get the LLVM Type::TypeID of !fir.real<kind>
Definition: KindMapping.cpp:233
fir::KindMapping::getIntegerBitsize
Bitsize getIntegerBitsize(KindTy kind) const
Get the size in bits of !fir.int<kind>
Definition: KindMapping.cpp:225
fir::KindMapping::getCharacterBitsize
Bitsize getCharacterBitsize(KindTy kind) const
Get the size in bits of !fir.char<kind>
Definition: KindMapping.cpp:221
fir::KindMapping::getFloatSemantics
const llvm::fltSemantics & getFloatSemantics(KindTy kind) const
Get the float semantics of !fir.real<kind>
Definition: KindMapping.cpp:248
fir::KindMapping::getLogicalBitsize
Bitsize getLogicalBitsize(KindTy kind) const
Get the size in bits of !fir.logical<kind>
Definition: KindMapping.cpp:229
fir::KindMapping
Definition: KindMapping.h:43
fir::KindMapping::getComplexTypeID
LLVMTypeID getComplexTypeID(KindTy kind) const
Get the LLVM Type::TypeID of !fir.complex<kind>
Definition: KindMapping.cpp:237
fir::KindMapping::getRealBitsize
Bitsize getRealBitsize(KindTy kind) const
Get the size in bits of !fir.real<kind>
Definition: KindMapping.cpp:241