LLVM: include/llvm/Support/InstructionCost.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef LLVM_SUPPORT_INSTRUCTIONCOST_H
19#define LLVM_SUPPORT_INSTRUCTIONCOST_H
20
23#include
24#include
25
26namespace llvm {
27
29
31public:
33
34
52
53private:
54 CostType Value = 0;
55 CostState State = Valid;
56
60 }
61
62 static constexpr CostType MaxValue = std::numeric_limits::max();
63 static constexpr CostType MinValue = std::numeric_limits::min();
64
65public:
66
68
71
79
84
85
86
87
92
93
94
95
96
97
98
100 propagateState(RHS);
101
102
105 Result = RHS.Value > 0 ? MaxValue : MinValue;
106
107 Value = Result;
108 return *this;
109 }
110
113 *this += RHS2;
114 return *this;
115 }
116
118 propagateState(RHS);
119
120
123 Result = RHS.Value > 0 ? MinValue : MaxValue;
124 Value = Result;
125 return *this;
126 }
127
130 *this -= RHS2;
131 return *this;
132 }
133
135 propagateState(RHS);
136
137
140 if ((Value > 0 && RHS.Value > 0) || (Value < 0 && RHS.Value < 0))
141 Result = MaxValue;
142 else
143 Result = MinValue;
144 }
145
146 Value = Result;
147 return *this;
148 }
149
152 *this *= RHS2;
153 return *this;
154 }
155
157 propagateState(RHS);
158 Value /= RHS.Value;
159 return *this;
160 }
161
164 *this /= RHS2;
165 return *this;
166 }
167
169 *this += 1;
170 return *this;
171 }
172
175 ++*this;
176 return Copy;
177 }
178
180 *this -= 1;
181 return *this;
182 }
183
186 --*this;
187 return Copy;
188 }
189
190
191
192
193
194
196 return std::tie(State, Value) < std::tie(RHS.State, RHS.Value);
197 }
198
200 return State == RHS.State && Value == RHS.Value;
201 }
202
204
207 return *this == RHS2;
208 }
209
211
213
215
217
220 return *this < RHS2;
221 }
222
225 return *this > RHS2;
226 }
227
230 return *this <= RHS2;
231 }
232
235 return *this >= RHS2;
236 }
237
239
240 template
243 return F(Value);
245 }
246};
247
251 LHS2 += RHS;
252 return LHS2;
253}
254
258 LHS2 -= RHS;
259 return LHS2;
260}
261
265 LHS2 *= RHS;
266 return LHS2;
267}
268
272 LHS2 /= RHS;
273 return LHS2;
274}
275
277 V.print(OS);
278 return OS;
279}
280
281}
282
283#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Definition InstructionCost.h:30
void setInvalid()
Definition InstructionCost.h:82
InstructionCost & operator+=(const CostType RHS)
Definition InstructionCost.h:111
bool operator!=(const CostType RHS) const
Definition InstructionCost.h:210
bool operator==(const InstructionCost &RHS) const
Definition InstructionCost.h:199
InstructionCost & operator*=(const InstructionCost &RHS)
Definition InstructionCost.h:134
auto map(const Function &F) const -> InstructionCost
Definition InstructionCost.h:241
InstructionCost & operator--()
Definition InstructionCost.h:179
InstructionCost & operator++()
Definition InstructionCost.h:168
static InstructionCost getMin()
Definition InstructionCost.h:73
InstructionCost operator++(int)
Definition InstructionCost.h:173
static InstructionCost getInvalid(CostType Val=0)
Definition InstructionCost.h:74
int64_t CostType
Definition InstructionCost.h:32
InstructionCost & operator-=(const CostType RHS)
Definition InstructionCost.h:128
LLVM_ABI void print(raw_ostream &OS) const
bool operator>(const InstructionCost &RHS) const
Definition InstructionCost.h:212
InstructionCost operator--(int)
Definition InstructionCost.h:184
static InstructionCost getMax()
Definition InstructionCost.h:72
InstructionCost & operator+=(const InstructionCost &RHS)
For all of the arithmetic operators provided here any invalid state is perpetuated and cannot be remo...
Definition InstructionCost.h:99
bool operator>=(const CostType RHS) const
Definition InstructionCost.h:233
bool operator<=(const CostType RHS) const
Definition InstructionCost.h:228
void setValid()
Definition InstructionCost.h:81
bool operator!=(const InstructionCost &RHS) const
Definition InstructionCost.h:203
InstructionCost & operator-=(const InstructionCost &RHS)
Definition InstructionCost.h:117
CostState
CostState describes the state of a cost.
Definition InstructionCost.h:35
@ Invalid
< The cost value represents a valid cost, even when the cost-value is large.
Definition InstructionCost.h:38
@ Valid
Definition InstructionCost.h:36
InstructionCost & operator/=(const InstructionCost &RHS)
Definition InstructionCost.h:156
bool operator>=(const InstructionCost &RHS) const
Definition InstructionCost.h:216
InstructionCost(CostType Val)
Definition InstructionCost.h:70
bool operator<(const InstructionCost &RHS) const
For the comparison operators we have chosen to use lexicographical ordering where valid costs are alw...
Definition InstructionCost.h:195
InstructionCost & operator*=(const CostType RHS)
Definition InstructionCost.h:150
InstructionCost(CostState)=delete
bool operator==(const CostType RHS) const
Definition InstructionCost.h:205
bool operator<=(const InstructionCost &RHS) const
Definition InstructionCost.h:214
bool operator<(const CostType RHS) const
Definition InstructionCost.h:218
bool operator>(const CostType RHS) const
Definition InstructionCost.h:223
CostType getValue() const
This function is intended to be used as sparingly as possible, since the class provides the full rang...
Definition InstructionCost.h:88
CostState getState() const
Definition InstructionCost.h:83
bool isValid() const
Definition InstructionCost.h:80
InstructionCost()=default
InstructionCost & operator/=(const CostType RHS)
Definition InstructionCost.h:162
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
std::enable_if_t< std::is_signed_v< T >, T > MulOverflow(T X, T Y, T &Result)
Multiply two signed integers, computing the two's complement truncated result, returning true if an o...
APInt operator*(APInt a, uint64_t RHS)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
std::enable_if_t< std::is_signed_v< T >, T > AddOverflow(T X, T Y, T &Result)
Add two signed integers, computing the two's complement truncated result, returning true if overflow ...
APInt operator+(APInt a, const APInt &b)
std::enable_if_t< std::is_signed_v< T >, T > SubOverflow(T X, T Y, T &Result)
Subtract two signed integers, computing the two's complement truncated result, returning true if an o...
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt operator/(const DynamicAPInt &A, int64_t B)