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<double> {
28 static Type *get(llvm::LLVMContext &Ctx) { return Type::getDoubleTy(Ctx); }
29
30 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
31};
32
33template <> struct TypeMap<size_t> {
34 static Type *get(llvm::LLVMContext &Ctx) { return Type::getInt64Ty(Ctx); }
35
36 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
37};
38
39template <> struct TypeMap<int> {
40 static Type *get(llvm::LLVMContext &Ctx) { return Type::getInt32Ty(Ctx); }
41
42 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
43
44 static bool isSigned() { return true; }
45};
46
47template <> struct TypeMap<unsigned int> {
48 static Type *get(llvm::LLVMContext &Ctx) { return Type::getInt32Ty(Ctx); }
49
50 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
51
52 static bool isSigned() { return false; }
53};
54
55template <> struct TypeMap<int *> {
56 static Type *get(llvm::LLVMContext &Ctx) {
57 return PointerType::getUnqual(Ctx);
58 }
59
60 static Type *getPointerElemType(llvm::LLVMContext &Ctx) {
61 return Type::getInt32Ty(Ctx);
62 }
63};
64
65template <> struct TypeMap<unsigned int *> {
66 static Type *get(llvm::LLVMContext &Ctx) {
67 return PointerType::getUnqual(Ctx);
68 }
69
70 static Type *getPointerElemType(llvm::LLVMContext &Ctx) {
71 return Type::getInt32Ty(Ctx);
72 }
73};
74
75template <> struct TypeMap<bool> {
76 static Type *get(llvm::LLVMContext &Ctx) { return Type::getInt1Ty(Ctx); }
77
78 static Type *getPointerElemType(llvm::LLVMContext &) { return nullptr; }
79};
80
81template <> struct TypeMap<double &> {
82 static Type *get(llvm::LLVMContext &Ctx) {
83 return PointerType::getUnqual(Ctx);
84 }
85
86 static Type *getPointerElemType(llvm::LLVMContext &Ctx) {
87 return Type::getDoubleTy(Ctx);
88 }
89};
90
91template <> struct TypeMap<double *> {
92 static Type *get(llvm::LLVMContext &Ctx) {
93 return PointerType::getUnqual(Ctx);
94 }
95
96 static Type *getPointerElemType(llvm::LLVMContext &Ctx) {
97 return Type::getDoubleTy(Ctx);
98 }
99};
100
101template <> struct TypeMap<float *> {
102 static Type *get(llvm::LLVMContext &Ctx) {
103 return PointerType::getUnqual(Ctx);
104 }
105
106 static Type *getPointerElemType(llvm::LLVMContext &Ctx) {
107 return Type::getFloatTy(Ctx);
108 }
109};
110
111} // namespace proteus
112
113#endif // PROTEUS_FRONTEND_TYPEMAP_HPP
Definition Helpers.h:76
Definition CppJitModule.cpp:21
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:76
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:78
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:30
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:28
static Type * getPointerElemType(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:96
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:92
static Type * getPointerElemType(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:86
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:82
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:106
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:102
static bool isSigned()
Definition TypeMap.hpp:44
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:40
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:42
static Type * getPointerElemType(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:60
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:56
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:34
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:36
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:48
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:50
static bool isSigned()
Definition TypeMap.hpp:52
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:66
static Type * getPointerElemType(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:70
static Type * get(llvm::LLVMContext &Ctx)
Definition TypeMap.hpp:16
static Type * getPointerElemType(llvm::LLVMContext &)
Definition TypeMap.hpp:18
Definition TypeMap.hpp:13