Proteus
Programmable JIT compilation and optimization for C/C++ using LLVM
Loading...
Searching...
No Matches
Var.hpp
Go to the documentation of this file.
1#ifndef PROTEUS_FRONTEND_VAR_HPP
2#define PROTEUS_FRONTEND_VAR_HPP
3
4#include <llvm/IR/IRBuilder.h>
5#include <llvm/IR/Module.h>
6
7namespace proteus {
8
9class FuncBase;
10
11using namespace llvm;
12
13template <typename T> struct VarT {};
14
15struct Var {
16 AllocaInst *Alloca;
19
20 Var(AllocaInst *Alloca, FuncBase &Fn, Type *PointerElemType = nullptr);
21
22 StringRef getName();
23
24 Value *getValue() const;
25 Type *getValueType() const;
26 void storeValue(Value *Val);
27 void storePointer(Value *Ptr);
28
29 bool isPointer() const;
30
31 // Declare member Operators.
32
33 Var &operator+(const Var &Other) const;
34 Var &operator-(const Var &Other) const;
35 Var &operator*(const Var &Other) const;
36 Var &operator/(const Var &Other) const;
37
38 template <typename T>
39 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
40 operator+(const T &ConstValue) const;
41
42 template <typename T>
43 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
44 operator-(const T &ConstValue) const;
45
46 template <typename T>
47 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
48 operator*(const T &ConstValue) const;
49
50 template <typename T>
51 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
52 operator/(const T &ConstValue) const;
53
54 Var &operator+=(Var &Other);
55 Var &operator-=(Var &Other);
56 Var &operator*=(Var &Other);
57 Var &operator/=(Var &Other);
58
59 template <typename T>
60 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
61 operator+=(const T &ConstValue);
62
63 template <typename T>
64 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
65 operator-=(const T &ConstValue);
66
67 template <typename T>
68 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
69 operator*=(const T &ConstValue);
70
71 template <typename T>
72 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
73 operator/=(const T &ConstValue);
74
75 Var &operator>(const Var &Other) const;
76 Var &operator<(const Var &Other) const;
77 Var &operator>=(const Var &Other) const;
78 Var &operator<=(const Var &Other) const;
79 Var &operator==(const Var &Other) const;
80 Var &operator!=(const Var &Other) const;
81
82 template <typename T>
83 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
84 operator>(const T &ConstValue) const;
85
86 template <typename T>
87 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
88 operator>=(const T &ConstValue) const;
89
90 template <typename T>
91 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
92 operator<(const T &ConstValue) const;
93
94 template <typename T>
95 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
96 operator<=(const T &ConstValue) const;
97
98 template <typename T>
99 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
100 operator==(const T &ConstValue) const;
101
102 template <typename T>
103 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
104 operator!=(const T &ConstValue) const;
105
106 Var &operator=(const Var &Other);
107
108 template <typename T, typename = std::enable_if<std::is_arithmetic_v<T>>>
109 Var &operator=(const T &ConstValue);
110
111 Var &operator[](size_t I);
112 Var &operator[](const Var &I);
113};
114
115// Declare non-member operators.
116template <typename T>
117std::enable_if_t<std::is_arithmetic_v<T>, Var &> operator+(const T &ConstValue,
118 const Var &Other);
119template <typename T>
120std::enable_if_t<std::is_arithmetic_v<T>, Var &> operator-(const T &ConstValue,
121 const Var &Other);
122template <typename T>
123std::enable_if_t<std::is_arithmetic_v<T>, Var &> operator*(const T &ConstValue,
124 const Var &Other);
125template <typename T>
126std::enable_if_t<std::is_arithmetic_v<T>, Var &> operator/(const T &ConstValue,
127 const Var &Other);
128
129// Declare usual arithmetic conversion helper functions.
130Value *convert(IRBuilderBase IRB, Value *V, Type *TargetType);
131Type *getCommonType(const DataLayout &DL, Type *T1, Type *T2);
132
133// Declare intrinsic math functions.
134Var &powf(const Var &L, const Var &R);
135Var &sqrtf(const Var &R);
136
137} // namespace proteus
138
139#endif // PROTEUS_FRONTEND_VAR_HPP
Definition Func.hpp:22
Definition Helpers.h:76
Definition CppJitModule.cpp:21
Type * getCommonType(const DataLayout &DL, Type *T1, Type *T2)
Get the common type following C++ usual arithmetic conversions.
Definition Var.cpp:538
std::enable_if_t< std::is_arithmetic_v< T >, Var & > operator/(const T &ConstValue, const Var &V)
Definition Var.cpp:498
Var & powf(const Var &L, const Var &R)
Definition Var.cpp:559
Var & sqrtf(const Var &R)
Definition Var.cpp:582
std::enable_if_t< std::is_arithmetic_v< T >, Var & > operator*(const T &ConstValue, const Var &V)
Definition Var.cpp:488
std::enable_if_t< std::is_arithmetic_v< T >, Var & > operator-(const T &ConstValue, const Var &V)
Definition Var.cpp:478
Value * convert(IRBuilderBase IRB, Value *V, Type *TargetType)
Definition Var.cpp:507
std::enable_if_t< std::is_arithmetic_v< T >, Var & > operator+(const T &ConstValue, const Var &V)
Definition Var.cpp:468
Definition Var.hpp:13
Definition Var.hpp:15
Var & operator-(const Var &Other) const
Definition Var.cpp:135
Var & operator*=(Var &Other)
Definition Var.cpp:196
Var & operator/=(Var &Other)
Definition Var.cpp:216
Var & operator!=(const Var &Other) const
Definition Var.cpp:358
Var & operator=(const Var &Other)
Definition Var.cpp:272
Var & operator<=(const Var &Other) const
Definition Var.cpp:334
Var & operator<(const Var &Other) const
Definition Var.cpp:322
void storePointer(Value *Ptr)
Definition Var.cpp:121
Var & operator+=(Var &Other)
Definition Var.cpp:156
bool isPointer() const
Definition Var.cpp:92
Var & operator+(const Var &Other) const
Definition Var.cpp:128
AllocaInst * Alloca
Definition Var.hpp:16
StringRef getName()
Definition Var.cpp:90
Type * PointerElemType
Definition Var.hpp:18
void storeValue(Value *Val)
Definition Var.cpp:102
Var & operator-=(Var &Other)
Definition Var.cpp:176
Var & operator[](size_t I)
End of comparison operators.
Definition Var.cpp:432
FuncBase & Fn
Definition Var.hpp:17
Var & operator==(const Var &Other) const
Definition Var.cpp:346
Var & operator*(const Var &Other) const
Definition Var.cpp:142
Var & operator>(const Var &Other) const
Define comparison operators.
Definition Var.cpp:298
Var & operator/(const Var &Other) const
Definition Var.cpp:149
Value * getValue() const
Definition Var.cpp:72
Var & operator>=(const Var &Other) const
Definition Var.cpp:310
Type * getValueType() const
Definition Var.cpp:82