Proteus
Programmable JIT compilation and optimization for C/C++ using LLVM
Loading...
Searching...
No Matches
TypeMap.hpp
Go to the documentation of this file.
1#ifndef PROTEUS_FRONTEND_TYPEMAP_HPP
2#define PROTEUS_FRONTEND_TYPEMAP_HPP
3
4#include <llvm/IR/DerivedTypes.h>
5#include <llvm/IR/LLVMContext.h>
6#include <llvm/IR/Type.h>
7
8#include <cstddef>
9
10namespace proteus {
11using namespace llvm;
12
13template <typename T> struct TypeMap;
14
15template <> struct TypeMap<void> {
16 static Type *get(llvm::LLVMContext &Ctx) { return Type::getVoidTy(Ctx); }
17
18 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
19};
20
21template <> struct TypeMap<float> {
22 static Type *get(llvm::LLVMContext &Ctx) { return Type::getFloatTy(Ctx); }
23
24 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
25};
26
27template <> struct TypeMap<float[]> {
28 static Type *get(llvm::LLVMContext &Ctx, size_t NElem) {
29 return ArrayType::get(Type::getFloatTy(Ctx), NElem);
30 }
31
32 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
33};
34
35template <> struct TypeMap<double> {
36 static Type *get(llvm::LLVMContext &Ctx) { return Type::getDoubleTy(Ctx); }
37
38 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
39};
40
41template <> struct TypeMap<double[]> {
42 static Type *get(llvm::LLVMContext &Ctx, size_t NElem) {
43 return ArrayType::get(Type::getDoubleTy(Ctx), NElem);
44 }
45
46 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
47};
48
49template <> struct TypeMap<size_t> {
50 static Type *get(llvm::LLVMContext &Ctx) { return Type::getInt64Ty(Ctx); }
51
52 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
53};
54
55template <> struct TypeMap<size_t[]> {
56 static Type *get(llvm::LLVMContext &Ctx, size_t NElem) {
57 return ArrayType::get(Type::getInt64Ty(Ctx), NElem);
58 }
59
60 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
61};
62
63template <> struct TypeMap<int> {
64 static Type *get(llvm::LLVMContext &Ctx) { return Type::getInt32Ty(Ctx); }
65
66 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
67
68 static bool isSigned() { return true; }
69};
70
71template <> struct TypeMap<int[]> {
72 static Type *get(llvm::LLVMContext &Ctx, size_t NElem) {
73 return ArrayType::get(Type::getInt32Ty(Ctx), NElem);
74 }
75
76 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
77};
78
79template <> struct TypeMap<unsigned int> {
80 static Type *get(llvm::LLVMContext &Ctx) { return Type::getInt32Ty(Ctx); }
81
82 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
83
84 static bool isSigned() { return false; }
85};
86
87template <> struct TypeMap<unsigned int[]> {
88 static Type *get(llvm::LLVMContext &Ctx, size_t NElem) {
89 return ArrayType::get(Type::getInt32Ty(Ctx), NElem);
90 }
91
92 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
93};
94
95template <> struct TypeMap<int *> {
96 static Type *get(llvm::LLVMContext &Ctx) {
97 return PointerType::getUnqual(Ctx);
98 }
99
101 return Type::getInt32Ty(Ctx);
102 }
103};
104
105template <> struct TypeMap<unsigned int *> {
106 static Type *get(llvm::LLVMContext &Ctx) {
107 return PointerType::getUnqual(Ctx);
108 }
109
111 return Type::getInt32Ty(Ctx);
112 }
113};
114
115template <> struct TypeMap<bool> {
116 static Type *get(llvm::LLVMContext &Ctx) { return Type::getInt1Ty(Ctx); }
117
118 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
119};
120
121template <> struct TypeMap<bool[]> {
122 static Type *get(llvm::LLVMContext &Ctx, size_t NElem) {
123 return ArrayType::get(Type::getInt1Ty(Ctx), NElem);
124 }
125
126 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
127};
128
129template <> struct TypeMap<double &> {
130 static Type *get(llvm::LLVMContext &Ctx) {
131 return PointerType::getUnqual(Ctx);
132 }
133
135 return Type::getDoubleTy(Ctx);
136 }
137};
138
139template <> struct TypeMap<double *> {
140 static Type *get(llvm::LLVMContext &Ctx) {
141 return PointerType::getUnqual(Ctx);
142 }
143
145 return Type::getDoubleTy(Ctx);
146 }
147};
148
149template <> struct TypeMap<float *> {
150 static Type *get(llvm::LLVMContext &Ctx) {
151 return PointerType::getUnqual(Ctx);
152 }
153
155 return Type::getFloatTy(Ctx);
156 }
157};
158
159} // namespace proteus
160
161#endif // PROTEUS_FRONTEND_TYPEMAP_HPP
Definition Helpers.h:138
Definition BuiltinsCUDA.cpp:4
T getRuntimeConstantValue(void *Arg)
Definition CompilerInterfaceRuntimeConstantInfo.h:114
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:116
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:118
static Type * get(llvm::LLVMContext &Ctx, size_t NElem)
Definition TypeMap.hpp:122
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:126
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:38
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:36
static Type * getPointerElemType(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:144
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:140
static Type * getPointerElemType(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:134
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:130
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:46
static Type * get(llvm::LLVMContext &Ctx, size_t NElem)
Definition TypeMap.hpp:42
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:24
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:22
static Type * getPointerElemType(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:154
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:150
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:32
static Type * get(llvm::LLVMContext &Ctx, size_t NElem)
Definition TypeMap.hpp:28
static bool isSigned()
Definition TypeMap.hpp:68
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:64
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:66
static Type * getPointerElemType(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:100
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:96
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:76
static Type * get(llvm::LLVMContext &Ctx, size_t NElem)
Definition TypeMap.hpp:72
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:50
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:52
static Type * get(llvm::LLVMContext &Ctx, size_t NElem)
Definition TypeMap.hpp:56
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:60
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:80
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:82
static bool isSigned()
Definition TypeMap.hpp:84
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:106
static Type * getPointerElemType(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:110
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:92
static Type * get(llvm::LLVMContext &Ctx, size_t NElem)
Definition TypeMap.hpp:88
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:16
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:18
Definition TypeMap.hpp:13