Skip to content

Commit e6260ec

Browse files
committed
[ConstraintElim] Use enum class to differentiate fact/check types (NFC).
Use an enum to clarify the type of fact or check in FactOrCheck, as suggested in D158837.
1 parent 2a82da8 commit e6260ec

File tree

1 file changed

+40
-24
lines changed

1 file changed

+40
-24
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,59 +84,75 @@ static Instruction *getContextInstForUse(Use &U) {
8484

8585
namespace {
8686
/// Represents either
87-
/// * a condition that holds on entry to a block (=conditional fact)
87+
/// * a condition that holds on entry to a block (=condition fact)
8888
/// * an assume (=assume fact)
8989
/// * a use of a compare instruction to simplify.
9090
/// It also tracks the Dominator DFS in and out numbers for each entry.
9191
struct FactOrCheck {
92+
enum class EntryTy {
93+
ConditionFact, /// A condition that holds on entry to a block.
94+
InstFact, /// A fact that holds after Inst executed (e.g. an assume or
95+
/// min/mix intrinsic.
96+
InstCheck, /// An instruction to simplify (e.g. an overflow math
97+
/// intrinsics).
98+
UseCheck /// An use of a compare instruction to simplify.
99+
};
100+
92101
union {
93102
Instruction *Inst;
94103
Use *U;
95104
};
105+
96106
unsigned NumIn;
97107
unsigned NumOut;
98-
bool HasInst;
108+
EntryTy Ty;
99109
bool Not;
100110

101-
FactOrCheck(DomTreeNode *DTN, Instruction *Inst, bool Not)
111+
FactOrCheck(EntryTy Ty, DomTreeNode *DTN, Instruction *Inst, bool Not)
102112
: Inst(Inst), NumIn(DTN->getDFSNumIn()), NumOut(DTN->getDFSNumOut()),
103-
HasInst(true), Not(Not) {}
113+
Ty(Ty), Not(Not) {}
104114

105115
FactOrCheck(DomTreeNode *DTN, Use *U)
106116
: U(U), NumIn(DTN->getDFSNumIn()), NumOut(DTN->getDFSNumOut()),
107-
HasInst(false), Not(false) {}
117+
Ty(EntryTy::UseCheck), Not(false) {}
118+
119+
static FactOrCheck getConditionFact(DomTreeNode *DTN, CmpInst *Inst,
120+
bool Not = false) {
121+
return FactOrCheck(EntryTy::ConditionFact, DTN, Inst, Not);
122+
}
108123

109-
static FactOrCheck getFact(DomTreeNode *DTN, Instruction *Inst,
110-
bool Not = false) {
111-
return FactOrCheck(DTN, Inst, Not);
124+
static FactOrCheck getInstFact(DomTreeNode *DTN, Instruction *Inst,
125+
bool Not = false) {
126+
return FactOrCheck(EntryTy::InstFact, DTN, Inst, Not);
112127
}
113128

114129
static FactOrCheck getCheck(DomTreeNode *DTN, Use *U) {
115130
return FactOrCheck(DTN, U);
116131
}
117132

118133
static FactOrCheck getCheck(DomTreeNode *DTN, CallInst *CI) {
119-
return FactOrCheck(DTN, CI, false);
134+
return FactOrCheck(EntryTy::InstCheck, DTN, CI, false);
120135
}
121136

122137
bool isCheck() const {
123-
return !HasInst ||
124-
match(Inst, m_Intrinsic<Intrinsic::ssub_with_overflow>());
138+
return Ty == EntryTy::InstCheck || Ty == EntryTy::UseCheck;
125139
}
126140

127141
Instruction *getContextInst() const {
128-
if (HasInst)
129-
return Inst;
130-
return getContextInstForUse(*U);
142+
if (Ty == EntryTy::UseCheck)
143+
return getContextInstForUse(*U);
144+
return Inst;
131145
}
146+
132147
Instruction *getInstructionToSimplify() const {
133148
assert(isCheck());
134-
if (HasInst)
149+
if (Ty == EntryTy::InstCheck)
135150
return Inst;
136151
// The use may have been simplified to a constant already.
137152
return dyn_cast<Instruction>(*U);
138153
}
139-
bool isConditionFact() const { return !isCheck() && isa<CmpInst>(Inst); }
154+
155+
bool isConditionFact() const { return Ty == EntryTy::ConditionFact; }
140156
};
141157

142158
/// Keep state required to build worklist.
@@ -785,7 +801,7 @@ void State::addInfoFor(BasicBlock &BB) {
785801
}
786802

787803
if (isa<MinMaxIntrinsic>(&I)) {
788-
WorkList.push_back(FactOrCheck::getFact(DT.getNode(&BB), &I));
804+
WorkList.push_back(FactOrCheck::getInstFact(DT.getNode(&BB), &I));
789805
continue;
790806
}
791807

@@ -796,11 +812,11 @@ void State::addInfoFor(BasicBlock &BB) {
796812
if (GuaranteedToExecute) {
797813
// The assume is guaranteed to execute when BB is entered, hence Cond
798814
// holds on entry to BB.
799-
WorkList.emplace_back(FactOrCheck::getFact(DT.getNode(I.getParent()),
800-
cast<Instruction>(Cond)));
815+
WorkList.emplace_back(FactOrCheck::getConditionFact(
816+
DT.getNode(I.getParent()), cast<CmpInst>(Cond)));
801817
} else {
802818
WorkList.emplace_back(
803-
FactOrCheck::getFact(DT.getNode(I.getParent()), &I));
819+
FactOrCheck::getInstFact(DT.getNode(I.getParent()), &I));
804820
}
805821
}
806822
GuaranteedToExecute &= isGuaranteedToTransferExecutionToSuccessor(&I);
@@ -838,7 +854,7 @@ void State::addInfoFor(BasicBlock &BB) {
838854
Value *Cur = CondWorkList.pop_back_val();
839855
if (auto *Cmp = dyn_cast<ICmpInst>(Cur)) {
840856
WorkList.emplace_back(
841-
FactOrCheck::getFact(DT.getNode(Successor), Cmp, IsOr));
857+
FactOrCheck::getConditionFact(DT.getNode(Successor), Cmp, IsOr));
842858
continue;
843859
}
844860
if (IsOr && match(Cur, m_LogicalOr(m_Value(Op0), m_Value(Op1)))) {
@@ -861,10 +877,10 @@ void State::addInfoFor(BasicBlock &BB) {
861877
return;
862878
if (canAddSuccessor(BB, Br->getSuccessor(0)))
863879
WorkList.emplace_back(
864-
FactOrCheck::getFact(DT.getNode(Br->getSuccessor(0)), CmpI));
880+
FactOrCheck::getConditionFact(DT.getNode(Br->getSuccessor(0)), CmpI));
865881
if (canAddSuccessor(BB, Br->getSuccessor(1)))
866-
WorkList.emplace_back(
867-
FactOrCheck::getFact(DT.getNode(Br->getSuccessor(1)), CmpI, true));
882+
WorkList.emplace_back(FactOrCheck::getConditionFact(
883+
DT.getNode(Br->getSuccessor(1)), CmpI, true));
868884
}
869885

870886
namespace {

0 commit comments

Comments
 (0)