Proteus
Programmable JIT compilation and optimization for C/C++ using LLVM
Loading...
Searching...
No Matches
RuntimeConstantTypeHelpers.h
Go to the documentation of this file.
1#ifndef PROTEUS_RUNTIME_CONSTANT_TYPE_HELPERS_H
2#define PROTEUS_RUNTIME_CONSTANT_TYPE_HELPERS_H
3
4#include <string>
5
6#include <llvm/IR/DerivedTypes.h>
7#include <llvm/IR/Type.h>
8
10#include "proteus/Error.h"
11
12namespace proteus {
13
14using namespace llvm;
15
18 LLVMContext &Ctx);
19inline std::string toString(const RuntimeConstantType RCType);
20
22 if (Ty->isIntegerTy(1))
24 if (Ty->isIntegerTy(8))
26 if (Ty->isIntegerTy(32))
28 if (Ty->isIntegerTy(64))
30 if (Ty->isFloatTy())
32 if (Ty->isDoubleTy())
34 if (Ty->isFP128Ty() || Ty->isPPC_FP128Ty() || Ty->isX86_FP80Ty())
36 if (Ty->isPointerTy())
38 if (Ty->isArrayTy())
40 if (Ty->isVectorTy())
42
43 std::string TypeString;
44 raw_string_ostream TypeOstream(TypeString);
45 Ty->print(TypeOstream);
46 PROTEUS_FATAL_ERROR("Unknown Type " + TypeOstream.str());
47}
48
50 LLVMContext &Ctx) {
51 switch (RCType) {
53 return Type::getInt1Ty(Ctx);
55 return Type::getInt8Ty(Ctx);
57 return Type::getInt32Ty(Ctx);
59 return Type::getInt64Ty(Ctx);
61 return Type::getFloatTy(Ctx);
63 return Type::getDoubleTy(Ctx);
65 PROTEUS_FATAL_ERROR("Unsupported");
67 return PointerType::getUnqual(Ctx);
68 default:
69 PROTEUS_FATAL_ERROR("Unknown RuntimeConstantType " + toString(RCType));
70 }
71}
72
73inline size_t getSizeInBytes(RuntimeConstantType RCType) {
74 switch (RCType) {
76 return sizeof(bool);
78 return sizeof(int8_t);
80 return sizeof(int32_t);
82 return sizeof(int64_t);
84 return sizeof(float);
86 return sizeof(double);
88 return sizeof(long double);
89 default:
90 PROTEUS_FATAL_ERROR("Unknown size for RuntimeConstantType " +
91 toString(RCType));
92 }
93}
94
95template <typename T> T getValue(const RuntimeConstant &RC) {
96 switch (RC.Type) {
98 return RC.Value.BoolVal;
100 return RC.Value.Int8Val;
102 return RC.Value.Int32Val;
104 return RC.Value.Int64Val;
106 return RC.Value.FloatVal;
108 return RC.Value.DoubleVal;
110 return RC.Value.LongDoubleVal;
111 default:
112 PROTEUS_FATAL_ERROR("Cannot get value for RuntimeConstantType " +
113 toString(RC.Type));
114 }
115}
116
117inline std::string toString(const RuntimeConstantType RCType) {
118 switch (RCType) {
120 return "BOOL";
122 return "INT8";
124 return "INT32";
126 return "INT64";
128 return "FLOAT";
130 return "DOUBLE";
132 return "LONG_DOUBLE";
134 return "PTR";
136 return "STATIC_ARRAY";
138 return "VECTOR";
140 return "ARRAY";
142 return "OBJECT";
143 default:
144 PROTEUS_FATAL_ERROR("Unknown RCType " + std::to_string(RCType));
145 }
146}
147
149 return (RCType >= RuntimeConstantType::BOOL &&
150 RCType <= RuntimeConstantType::PTR);
151}
152
153} // namespace proteus
154
155#endif
#define PROTEUS_FATAL_ERROR(x)
Definition Error.h:7
Definition Helpers.h:76
Definition CppJitModule.cpp:21
Type * convertRuntimeConstantTypeToLLVMType(RuntimeConstantType RCType, LLVMContext &Ctx)
Definition RuntimeConstantTypeHelpers.h:49
RuntimeConstantType
Definition CompilerInterfaceTypes.h:20
@ ARRAY
Definition CompilerInterfaceTypes.h:33
@ VECTOR
Definition CompilerInterfaceTypes.h:32
@ INT32
Definition CompilerInterfaceTypes.h:25
@ INT64
Definition CompilerInterfaceTypes.h:26
@ FLOAT
Definition CompilerInterfaceTypes.h:27
@ STATIC_ARRAY
Definition CompilerInterfaceTypes.h:31
@ LONG_DOUBLE
Definition CompilerInterfaceTypes.h:29
@ INT8
Definition CompilerInterfaceTypes.h:24
@ BOOL
Definition CompilerInterfaceTypes.h:23
@ OBJECT
Definition CompilerInterfaceTypes.h:34
@ PTR
Definition CompilerInterfaceTypes.h:30
@ DOUBLE
Definition CompilerInterfaceTypes.h:28
T getValue(const RuntimeConstant &RC)
Definition RuntimeConstantTypeHelpers.h:95
RuntimeConstantType convertTypeToRuntimeConstantType(Type *Ty)
Definition RuntimeConstantTypeHelpers.h:21
std::string toString(CodegenOption Option)
Definition Config.hpp:23
bool isScalarRuntimeConstantType(RuntimeConstantType RCType)
Definition RuntimeConstantTypeHelpers.h:148
size_t getSizeInBytes(RuntimeConstantType RCType)
Definition RuntimeConstantTypeHelpers.h:73
Definition CompilerInterfaceTypes.h:72
RuntimeConstantValue Value
Definition CompilerInterfaceTypes.h:73
RuntimeConstantType Type
Definition CompilerInterfaceTypes.h:74
double DoubleVal
Definition CompilerInterfaceTypes.h:65
int64_t Int64Val
Definition CompilerInterfaceTypes.h:63
bool BoolVal
Definition CompilerInterfaceTypes.h:60
int8_t Int8Val
Definition CompilerInterfaceTypes.h:61
int32_t Int32Val
Definition CompilerInterfaceTypes.h:62
float FloatVal
Definition CompilerInterfaceTypes.h:64
long double LongDoubleVal
Definition CompilerInterfaceTypes.h:66