Skip to content

Commit 2343cd5

Browse files
[Support] Make getMaxValue and getMinValue constexpr variables (NFC)
This patch makes getMaxValue and getMinValue constexpr variables and "inlines" the calls to getMaxValue and getMinValue. We could probably make InstructionCost constexpr also, but that's left for another day.
1 parent 6e0d519 commit 2343cd5

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

llvm/include/llvm/Support/InstructionCost.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ class InstructionCost {
5959
State = Invalid;
6060
}
6161

62-
static CostType getMaxValue() { return std::numeric_limits<CostType>::max(); }
63-
static CostType getMinValue() { return std::numeric_limits<CostType>::min(); }
62+
static inline constexpr CostType MaxValue =
63+
std::numeric_limits<CostType>::max();
64+
static inline constexpr CostType MinValue =
65+
std::numeric_limits<CostType>::min();
6466

6567
public:
6668
// A default constructed InstructionCost is a valid zero cost
@@ -69,8 +71,8 @@ class InstructionCost {
6971
InstructionCost(CostState) = delete;
7072
InstructionCost(CostType Val) : Value(Val), State(Valid) {}
7173

72-
static InstructionCost getMax() { return getMaxValue(); }
73-
static InstructionCost getMin() { return getMinValue(); }
74+
static InstructionCost getMax() { return MaxValue; }
75+
static InstructionCost getMin() { return MinValue; }
7476
static InstructionCost getInvalid(CostType Val = 0) {
7577
InstructionCost Tmp(Val);
7678
Tmp.setInvalid();
@@ -102,7 +104,7 @@ class InstructionCost {
102104
// Saturating addition.
103105
InstructionCost::CostType Result;
104106
if (AddOverflow(Value, RHS.Value, Result))
105-
Result = RHS.Value > 0 ? getMaxValue() : getMinValue();
107+
Result = RHS.Value > 0 ? MaxValue : MinValue;
106108

107109
Value = Result;
108110
return *this;
@@ -120,7 +122,7 @@ class InstructionCost {
120122
// Saturating subtract.
121123
InstructionCost::CostType Result;
122124
if (SubOverflow(Value, RHS.Value, Result))
123-
Result = RHS.Value > 0 ? getMinValue() : getMaxValue();
125+
Result = RHS.Value > 0 ? MinValue : MaxValue;
124126
Value = Result;
125127
return *this;
126128
}
@@ -138,9 +140,9 @@ class InstructionCost {
138140
InstructionCost::CostType Result;
139141
if (MulOverflow(Value, RHS.Value, Result)) {
140142
if ((Value > 0 && RHS.Value > 0) || (Value < 0 && RHS.Value < 0))
141-
Result = getMaxValue();
143+
Result = MaxValue;
142144
else
143-
Result = getMinValue();
145+
Result = MinValue;
144146
}
145147

146148
Value = Result;

0 commit comments

Comments
 (0)