llvm.org GIT mirror llvm / be8fe16
[X86] Move getX86ConditionCode() from X86FastISel.cpp to X86InstrInfo.cpp. NFC Summary: Move getX86ConditionCode() from X86FastISel.cpp to X86InstrInfo.cpp so it can be used by GloabalIsel instruction selector. This is a pre-commit for a patch I'm working on to support G_ICMP. NFC. Reviewers: zvi, guyblank, delena Reviewed By: guyblank, delena Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33038 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302767 91177308-0d34-0410-b5e6-96231b3b80d8 Igor Breger 3 years ago
3 changed file(s) with 46 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
178178 };
179179
180180 } // end anonymous namespace.
181
182 static std::pair
183 getX86ConditionCode(CmpInst::Predicate Predicate) {
184 X86::CondCode CC = X86::COND_INVALID;
185 bool NeedSwap = false;
186 switch (Predicate) {
187 default: break;
188 // Floating-point Predicates
189 case CmpInst::FCMP_UEQ: CC = X86::COND_E; break;
190 case CmpInst::FCMP_OLT: NeedSwap = true; LLVM_FALLTHROUGH;
191 case CmpInst::FCMP_OGT: CC = X86::COND_A; break;
192 case CmpInst::FCMP_OLE: NeedSwap = true; LLVM_FALLTHROUGH;
193 case CmpInst::FCMP_OGE: CC = X86::COND_AE; break;
194 case CmpInst::FCMP_UGT: NeedSwap = true; LLVM_FALLTHROUGH;
195 case CmpInst::FCMP_ULT: CC = X86::COND_B; break;
196 case CmpInst::FCMP_UGE: NeedSwap = true; LLVM_FALLTHROUGH;
197 case CmpInst::FCMP_ULE: CC = X86::COND_BE; break;
198 case CmpInst::FCMP_ONE: CC = X86::COND_NE; break;
199 case CmpInst::FCMP_UNO: CC = X86::COND_P; break;
200 case CmpInst::FCMP_ORD: CC = X86::COND_NP; break;
201 case CmpInst::FCMP_OEQ: LLVM_FALLTHROUGH;
202 case CmpInst::FCMP_UNE: CC = X86::COND_INVALID; break;
203
204 // Integer Predicates
205 case CmpInst::ICMP_EQ: CC = X86::COND_E; break;
206 case CmpInst::ICMP_NE: CC = X86::COND_NE; break;
207 case CmpInst::ICMP_UGT: CC = X86::COND_A; break;
208 case CmpInst::ICMP_UGE: CC = X86::COND_AE; break;
209 case CmpInst::ICMP_ULT: CC = X86::COND_B; break;
210 case CmpInst::ICMP_ULE: CC = X86::COND_BE; break;
211 case CmpInst::ICMP_SGT: CC = X86::COND_G; break;
212 case CmpInst::ICMP_SGE: CC = X86::COND_GE; break;
213 case CmpInst::ICMP_SLT: CC = X86::COND_L; break;
214 case CmpInst::ICMP_SLE: CC = X86::COND_LE; break;
215 }
216
217 return std::make_pair(CC, NeedSwap);
218 }
219181
220182 static std::pair
221183 getX86SSEConditionCode(CmpInst::Predicate Predicate) {
15581520
15591521 X86::CondCode CC;
15601522 bool SwapArgs;
1561 std::tie(CC, SwapArgs) = getX86ConditionCode(Predicate);
1523 std::tie(CC, SwapArgs) = X86::getX86ConditionCode(Predicate);
15621524 assert(CC <= X86::LAST_VALID_COND && "Unexpected condition code.");
15631525 unsigned Opc = X86::getSETFromCond(CC);
15641526
16961658
16971659 bool SwapArgs;
16981660 unsigned BranchOpc;
1699 std::tie(CC, SwapArgs) = getX86ConditionCode(Predicate);
1661 std::tie(CC, SwapArgs) = X86::getX86ConditionCode(Predicate);
17001662 assert(CC <= X86::LAST_VALID_COND && "Unexpected condition code.");
17011663
17021664 BranchOpc = X86::GetCondBranchFromCond(CC);
20692031 }
20702032
20712033 bool NeedSwap;
2072 std::tie(CC, NeedSwap) = getX86ConditionCode(Predicate);
2034 std::tie(CC, NeedSwap) = X86::getX86ConditionCode(Predicate);
20732035 assert(CC <= X86::LAST_VALID_COND && "Unexpected condition code.");
20742036
20752037 const Value *CmpLHS = CI->getOperand(0);
23182280 const auto *CI = dyn_cast(Cond);
23192281 if (CI && (CI->getParent() == I->getParent())) {
23202282 bool NeedSwap;
2321 std::tie(CC, NeedSwap) = getX86ConditionCode(CI->getPredicate());
2283 std::tie(CC, NeedSwap) = X86::getX86ConditionCode(CI->getPredicate());
23222284 if (CC > X86::LAST_VALID_COND)
23232285 return false;
23242286
57285728 }
57295729 }
57305730
5731 std::pair
5732 X86::getX86ConditionCode(CmpInst::Predicate Predicate) {
5733 X86::CondCode CC = X86::COND_INVALID;
5734 bool NeedSwap = false;
5735 switch (Predicate) {
5736 default: break;
5737 // Floating-point Predicates
5738 case CmpInst::FCMP_UEQ: CC = X86::COND_E; break;
5739 case CmpInst::FCMP_OLT: NeedSwap = true; LLVM_FALLTHROUGH;
5740 case CmpInst::FCMP_OGT: CC = X86::COND_A; break;
5741 case CmpInst::FCMP_OLE: NeedSwap = true; LLVM_FALLTHROUGH;
5742 case CmpInst::FCMP_OGE: CC = X86::COND_AE; break;
5743 case CmpInst::FCMP_UGT: NeedSwap = true; LLVM_FALLTHROUGH;
5744 case CmpInst::FCMP_ULT: CC = X86::COND_B; break;
5745 case CmpInst::FCMP_UGE: NeedSwap = true; LLVM_FALLTHROUGH;
5746 case CmpInst::FCMP_ULE: CC = X86::COND_BE; break;
5747 case CmpInst::FCMP_ONE: CC = X86::COND_NE; break;
5748 case CmpInst::FCMP_UNO: CC = X86::COND_P; break;
5749 case CmpInst::FCMP_ORD: CC = X86::COND_NP; break;
5750 case CmpInst::FCMP_OEQ: LLVM_FALLTHROUGH;
5751 case CmpInst::FCMP_UNE: CC = X86::COND_INVALID; break;
5752
5753 // Integer Predicates
5754 case CmpInst::ICMP_EQ: CC = X86::COND_E; break;
5755 case CmpInst::ICMP_NE: CC = X86::COND_NE; break;
5756 case CmpInst::ICMP_UGT: CC = X86::COND_A; break;
5757 case CmpInst::ICMP_UGE: CC = X86::COND_AE; break;
5758 case CmpInst::ICMP_ULT: CC = X86::COND_B; break;
5759 case CmpInst::ICMP_ULE: CC = X86::COND_BE; break;
5760 case CmpInst::ICMP_SGT: CC = X86::COND_G; break;
5761 case CmpInst::ICMP_SGE: CC = X86::COND_GE; break;
5762 case CmpInst::ICMP_SLT: CC = X86::COND_L; break;
5763 case CmpInst::ICMP_SLE: CC = X86::COND_LE; break;
5764 }
5765
5766 return std::make_pair(CC, NeedSwap);
5767 }
5768
57315769 /// Return a set opcode for the given condition and
57325770 /// whether it has memory operand.
57335771 unsigned X86::getSETFromCond(CondCode CC, bool HasMemoryOperand) {
6363 // Turn condition code into conditional branch opcode.
6464 unsigned GetCondBranchFromCond(CondCode CC);
6565
66 /// \brief Return a pair of condition code for the given predicate and whether
67 /// the instruction operands should be swaped to match the condition code.
68 std::pair getX86ConditionCode(CmpInst::Predicate Predicate);
69
6670 /// \brief Return a set opcode for the given condition and whether it has
6771 /// a memory operand.
6872 unsigned getSETFromCond(CondCode CC, bool HasMemoryOperand = false);