Skip to content

Commit 515660d

Browse files
[Support] Make getMaxValue and getMinValue constexpr variables (NFC) (#161480)
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 09dbb3e commit 515660d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

llvm/include/llvm/Support/InstructionCost.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ 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 constexpr CostType MaxValue = std::numeric_limits<CostType>::max();
63+
static constexpr CostType MinValue = std::numeric_limits<CostType>::min();
6464

6565
public:
6666
// A default constructed InstructionCost is a valid zero cost
@@ -69,8 +69,8 @@ class InstructionCost {
6969
InstructionCost(CostState) = delete;
7070
InstructionCost(CostType Val) : Value(Val), State(Valid) {}
7171

72-
static InstructionCost getMax() { return getMaxValue(); }
73-
static InstructionCost getMin() { return getMinValue(); }
72+
static InstructionCost getMax() { return MaxValue; }
73+
static InstructionCost getMin() { return MinValue; }
7474
static InstructionCost getInvalid(CostType Val = 0) {
7575
InstructionCost Tmp(Val);
7676
Tmp.setInvalid();
@@ -102,7 +102,7 @@ class InstructionCost {
102102
// Saturating addition.
103103
InstructionCost::CostType Result;
104104
if (AddOverflow(Value, RHS.Value, Result))
105-
Result = RHS.Value > 0 ? getMaxValue() : getMinValue();
105+
Result = RHS.Value > 0 ? MaxValue : MinValue;
106106

107107
Value = Result;
108108
return *this;
@@ -120,7 +120,7 @@ class InstructionCost {
120120
// Saturating subtract.
121121
InstructionCost::CostType Result;
122122
if (SubOverflow(Value, RHS.Value, Result))
123-
Result = RHS.Value > 0 ? getMinValue() : getMaxValue();
123+
Result = RHS.Value > 0 ? MinValue : MaxValue;
124124
Value = Result;
125125
return *this;
126126
}
@@ -138,9 +138,9 @@ class InstructionCost {
138138
InstructionCost::CostType Result;
139139
if (MulOverflow(Value, RHS.Value, Result)) {
140140
if ((Value > 0 && RHS.Value > 0) || (Value < 0 && RHS.Value < 0))
141-
Result = getMaxValue();
141+
Result = MaxValue;
142142
else
143-
Result = getMinValue();
143+
Result = MinValue;
144144
}
145145

146146
Value = Result;

0 commit comments

Comments
 (0)