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 Func;
10
11using namespace llvm;
12
13struct Var {
14 AllocaInst *Alloca;
17
18 Var(AllocaInst *Alloca, Func &Fn, Type *PointerElemType = nullptr);
19
20 StringRef getName();
21
22 Value *getValue() const;
23 Type *getValueType() const;
24 void storeValue(Value *Val);
25 void storePointer(Value *Ptr);
26
27 bool isPointer() const;
28
29 // Declare member Operators.
30
31 Var &operator+(const Var &Other) const;
32 Var &operator-(const Var &Other) const;
33 Var &operator*(const Var &Other) const;
34 Var &operator/(const Var &Other) const;
35
36 template <typename T>
37 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
38 operator+(const T &ConstValue) const;
39
40 template <typename T>
41 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
42 operator-(const T &ConstValue) const;
43
44 template <typename T>
45 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
46 operator*(const T &ConstValue) const;
47
48 template <typename T>
49 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
50 operator/(const T &ConstValue) const;
51
52 Var &operator+=(Var &Other);
53 Var &operator-=(Var &Other);
54 Var &operator*=(Var &Other);
55 Var &operator/=(Var &Other);
56
57 template <typename T>
58 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
59 operator+=(const T &ConstValue);
60
61 template <typename T>
62 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
63 operator-=(const T &ConstValue);
64
65 template <typename T>
66 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
67 operator*=(const T &ConstValue);
68
69 template <typename T>
70 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
71 operator/=(const T &ConstValue);
72
73 Var &operator>(const Var &Other) const;
74 Var &operator<(const Var &Other) const;
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
80 template <typename T>
81 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
82 operator>(const T &ConstValue) const;
83
84 template <typename T>
85 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
86 operator>=(const T &ConstValue) const;
87
88 template <typename T>
89 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
90 operator<(const T &ConstValue) const;
91
92 template <typename T>
93 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
94 operator<=(const T &ConstValue) const;
95
96 template <typename T>
97 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
98 operator==(const T &ConstValue) const;
99
100 template <typename T>
101 std::enable_if_t<std::is_arithmetic_v<T>, Var &>
102 operator!=(const T &ConstValue) const;
103
104 Var &operator=(const Var &Other);
105
106 template <typename T, typename = std::enable_if<std::is_arithmetic_v<T>>>
107 Var &operator=(const T &ConstValue);
108
109 Var &operator[](size_t I);
110 Var &operator[](const Var &I);
111};
112
113// Declare non-member operators.
114template <typename T>
115std::enable_if_t<std::is_arithmetic_v<T>, Var &> operator+(const T &ConstValue,
116 const Var &Other);
117template <typename T>
118std::enable_if_t<std::is_arithmetic_v<T>, Var &> operator-(const T &ConstValue,
119 const Var &Other);
120template <typename T>
121std::enable_if_t<std::is_arithmetic_v<T>, Var &> operator*(const T &ConstValue,
122 const Var &Other);
123template <typename T>
124std::enable_if_t<std::is_arithmetic_v<T>, Var &> operator/(const T &ConstValue,
125 const Var &Other);
126
127// Declare usual arithmetic conversion helper functions.
128Value *convert(IRBuilderBase IRB, Value *V, Type *TargetType);
129Type *getCommonType(const DataLayout &DL, Type *T1, Type *T2);
130
131// Declare intrinsic math functions.
132Var &powf(const Var &L, const Var &R);
133Var &sqrtf(const Var &R);
134
135} // namespace proteus
136
137#endif // PROTEUS_FRONTEND_VAR_HPP
Definition Func.hpp:19
Definition Dispatcher.cpp:14
Type * getCommonType(const DataLayout &DL, Type *T1, Type *T2)
Get the common type following C++ usual arithmetic conversions.
Definition Var.cpp:530
std::enable_if_t< std::is_arithmetic_v< T >, Var & > operator/(const T &ConstValue, const Var &V)
Definition Var.cpp:490
Var & powf(const Var &L, const Var &R)
Definition Var.cpp:551
Var & sqrtf(const Var &R)
Definition Var.cpp:574
std::enable_if_t< std::is_arithmetic_v< T >, Var & > operator*(const T &ConstValue, const Var &V)
Definition Var.cpp:480
std::enable_if_t< std::is_arithmetic_v< T >, Var & > operator-(const T &ConstValue, const Var &V)
Definition Var.cpp:470
Value * convert(IRBuilderBase IRB, Value *V, Type *TargetType)
Definition Var.cpp:499
std::enable_if_t< std::is_arithmetic_v< T >, Var & > operator+(const T &ConstValue, const Var &V)
Definition Var.cpp:460
Definition Var.hpp:13
Var & operator-(const Var &Other) const
Definition Var.cpp:127
Var & operator*=(Var &Other)
Definition Var.cpp:188
Var & operator/=(Var &Other)
Definition Var.cpp:208
Var & operator!=(const Var &Other) const
Definition Var.cpp:350
Var & operator=(const Var &Other)
Definition Var.cpp:264
Var & operator<=(const Var &Other) const
Definition Var.cpp:326
Var & operator<(const Var &Other) const
Definition Var.cpp:314
void storePointer(Value *Ptr)
Definition Var.cpp:113
Var & operator+=(Var &Other)
Definition Var.cpp:148
bool isPointer() const
Definition Var.cpp:92
Var & operator+(const Var &Other) const
Definition Var.cpp:120
AllocaInst * Alloca
Definition Var.hpp:14
StringRef getName()
Definition Var.cpp:90
Type * PointerElemType
Definition Var.hpp:16
void storeValue(Value *Val)
Definition Var.cpp:102
Var & operator-=(Var &Other)
Definition Var.cpp:168
Var & operator[](size_t I)
End of comparison operators.
Definition Var.cpp:424
Var & operator==(const Var &Other) const
Definition Var.cpp:338
Var & operator*(const Var &Other) const
Definition Var.cpp:134
Var & operator>(const Var &Other) const
Define comparison operators.
Definition Var.cpp:290
Var & operator/(const Var &Other) const
Definition Var.cpp:141
Value * getValue() const
Definition Var.cpp:72
Func & Fn
Definition Var.hpp:15
Var & operator>=(const Var &Other) const
Definition Var.cpp:302
Type * getValueType() const
Definition Var.cpp:82