llvm.org GIT mirror llvm / 240b0e1
Use CmpInst::Predicate instead of 'unsigned short' in some places. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255623 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 3 years ago
5 changed file(s) with 46 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
873873 /// This class is the base class for the comparison instructions.
874874 /// @brief Abstract base class of comparison instructions.
875875 class CmpInst : public Instruction {
876 void *operator new(size_t, unsigned) = delete;
877 CmpInst() = delete;
878
879 protected:
880 CmpInst(Type *ty, Instruction::OtherOps op, unsigned short pred,
881 Value *LHS, Value *RHS, const Twine &Name = "",
882 Instruction *InsertBefore = nullptr);
883
884 CmpInst(Type *ty, Instruction::OtherOps op, unsigned short pred,
885 Value *LHS, Value *RHS, const Twine &Name,
886 BasicBlock *InsertAtEnd);
887
888 void anchor() override; // Out of line virtual method.
889
890876 public:
891877 /// This enumeration lists the possible predicates for CmpInst subclasses.
892878 /// Values in the range 0-31 are reserved for FCmpInst, while values in the
928914 BAD_ICMP_PREDICATE = ICMP_SLE + 1
929915 };
930916
917 private:
918 void *operator new(size_t, unsigned) = delete;
919 CmpInst() = delete;
920
921 protected:
922 CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred,
923 Value *LHS, Value *RHS, const Twine &Name = "",
924 Instruction *InsertBefore = nullptr);
925
926 CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred,
927 Value *LHS, Value *RHS, const Twine &Name,
928 BasicBlock *InsertAtEnd);
929
930 void anchor() override; // Out of line virtual method.
931
932 public:
931933 // allocate space for exactly two operands
932934 void *operator new(size_t s) {
933935 return User::operator new(s, 2);
938940 /// The specified Instruction is allowed to be a dereferenced end iterator.
939941 /// @brief Create a CmpInst
940942 static CmpInst *Create(OtherOps Op,
941 unsigned short predicate, Value *S1,
943 Predicate predicate, Value *S1,
942944 Value *S2, const Twine &Name = "",
943945 Instruction *InsertBefore = nullptr);
944946
946948 /// two operands. Also automatically insert this instruction to the end of
947949 /// the BasicBlock specified.
948950 /// @brief Create a CmpInst
949 static CmpInst *Create(OtherOps Op, unsigned short predicate, Value *S1,
951 static CmpInst *Create(OtherOps Op, Predicate predicate, Value *S1,
950952 Value *S2, const Twine &Name, BasicBlock *InsertAtEnd);
951953
952954 /// @brief Get the opcode casted to the right type
10571059
10581060 /// @returns true if the predicate is unsigned, false otherwise.
10591061 /// @brief Determine if the predicate is an unsigned operation.
1060 static bool isUnsigned(unsigned short predicate);
1062 static bool isUnsigned(Predicate predicate);
10611063
10621064 /// @returns true if the predicate is signed, false otherwise.
10631065 /// @brief Determine if the predicate is an signed operation.
1064 static bool isSigned(unsigned short predicate);
1066 static bool isSigned(Predicate predicate);
10651067
10661068 /// @brief Determine if the predicate is an ordered operation.
1067 static bool isOrdered(unsigned short predicate);
1069 static bool isOrdered(Predicate predicate);
10681070
10691071 /// @brief Determine if the predicate is an unordered operation.
1070 static bool isUnordered(unsigned short predicate);
1072 static bool isUnordered(Predicate predicate);
10711073
10721074 /// Determine if the predicate is true when comparing a value with itself.
1073 static bool isTrueWhenEqual(unsigned short predicate);
1075 static bool isTrueWhenEqual(Predicate predicate);
10741076
10751077 /// Determine if the predicate is false when comparing a value with itself.
1076 static bool isFalseWhenEqual(unsigned short predicate);
1078 static bool isFalseWhenEqual(Predicate predicate);
10771079
10781080 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
10791081 static inline bool classof(const Instruction *I) {
16841684 // Otherwise, for integer compare, pick the same value as the non-undef
16851685 // operand, and fold it to true or false.
16861686 if (isIntegerPredicate)
1687 return ConstantInt::get(ResultTy, CmpInst::isTrueWhenEqual(pred));
1687 return ConstantInt::get(ResultTy, CmpInst::isTrueWhenEqual(Predicate));
16881688
16891689 // Choosing NaN for the undef will always make unordered comparison succeed
16901690 // and ordered comparison fails.
18681868 } else {
18691869 // Evaluate the relation between the two constants, per the predicate.
18701870 int Result = -1; // -1 = unknown, 0 = known false, 1 = known true.
1871 switch (evaluateICmpRelation(C1, C2, CmpInst::isSigned(pred))) {
1871 switch (evaluateICmpRelation(C1, C2,
1872 CmpInst::isSigned((CmpInst::Predicate)pred))) {
18721873 default: llvm_unreachable("Unknown relational!");
18731874 case ICmpInst::BAD_ICMP_PREDICATE:
18741875 break; // Couldn't determine anything about these constants.
19491950
19501951 // If the left hand side is an extension, try eliminating it.
19511952 if (ConstantExpr *CE1 = dyn_cast(C1)) {
1952 if ((CE1->getOpcode() == Instruction::SExt && ICmpInst::isSigned(pred)) ||
1953 (CE1->getOpcode() == Instruction::ZExt && !ICmpInst::isSigned(pred))){
1953 if ((CE1->getOpcode() == Instruction::SExt &&
1954 ICmpInst::isSigned((ICmpInst::Predicate)pred)) ||
1955 (CE1->getOpcode() == Instruction::ZExt &&
1956 !ICmpInst::isSigned((ICmpInst::Predicate)pred))){
19541957 Constant *CE1Op0 = CE1->getOperand(0);
19551958 Constant *CE1Inverse = ConstantExpr::getTrunc(CE1, CE1Op0->getType());
19561959 if (CE1Inverse == CE1Op0) {
30203020 case Instruction::ICmp:
30213021 case Instruction::FCmp:
30223022 return CmpInst::Create((Instruction::OtherOps)getOpcode(),
3023 getPredicate(), Ops[0], Ops[1]);
3023 (CmpInst::Predicate)getPredicate(), Ops[0], Ops[1]);
30243024
30253025 default:
30263026 assert(getNumOperands() == 2 && "Must be binary operator?");
32813281
32823282 void CmpInst::anchor() {}
32833283
3284 CmpInst::CmpInst(Type *ty, OtherOps op, unsigned short predicate,
3285 Value *LHS, Value *RHS, const Twine &Name,
3286 Instruction *InsertBefore)
3284 CmpInst::CmpInst(Type *ty, OtherOps op, Predicate predicate, Value *LHS,
3285 Value *RHS, const Twine &Name, Instruction *InsertBefore)
32873286 : Instruction(ty, op,
32883287 OperandTraits::op_begin(this),
32893288 OperandTraits::operands(this),
32943293 setName(Name);
32953294 }
32963295
3297 CmpInst::CmpInst(Type *ty, OtherOps op, unsigned short predicate,
3298 Value *LHS, Value *RHS, const Twine &Name,
3299 BasicBlock *InsertAtEnd)
3296 CmpInst::CmpInst(Type *ty, OtherOps op, Predicate predicate, Value *LHS,
3297 Value *RHS, const Twine &Name, BasicBlock *InsertAtEnd)
33003298 : Instruction(ty, op,
33013299 OperandTraits::op_begin(this),
33023300 OperandTraits::operands(this),
33083306 }
33093307
33103308 CmpInst *
3311 CmpInst::Create(OtherOps Op, unsigned short predicate,
3312 Value *S1, Value *S2,
3309 CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
33133310 const Twine &Name, Instruction *InsertBefore) {
33143311 if (Op == Instruction::ICmp) {
33153312 if (InsertBefore)
33293326 }
33303327
33313328 CmpInst *
3332 CmpInst::Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2,
3329 CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
33333330 const Twine &Name, BasicBlock *InsertAtEnd) {
33343331 if (Op == Instruction::ICmp) {
33353332 return new ICmpInst(*InsertAtEnd, CmpInst::Predicate(predicate),
35303527 }
35313528 }
35323529
3533 bool CmpInst::isUnsigned(unsigned short predicate) {
3530 bool CmpInst::isUnsigned(Predicate predicate) {
35343531 switch (predicate) {
35353532 default: return false;
35363533 case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_ULE: case ICmpInst::ICMP_UGT:
35383535 }
35393536 }
35403537
3541 bool CmpInst::isSigned(unsigned short predicate) {
3538 bool CmpInst::isSigned(Predicate predicate) {
35423539 switch (predicate) {
35433540 default: return false;
35443541 case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_SLE: case ICmpInst::ICMP_SGT:
35463543 }
35473544 }
35483545
3549 bool CmpInst::isOrdered(unsigned short predicate) {
3546 bool CmpInst::isOrdered(Predicate predicate) {
35503547 switch (predicate) {
35513548 default: return false;
35523549 case FCmpInst::FCMP_OEQ: case FCmpInst::FCMP_ONE: case FCmpInst::FCMP_OGT:
35553552 }
35563553 }
35573554
3558 bool CmpInst::isUnordered(unsigned short predicate) {
3555 bool CmpInst::isUnordered(Predicate predicate) {
35593556 switch (predicate) {
35603557 default: return false;
35613558 case FCmpInst::FCMP_UEQ: case FCmpInst::FCMP_UNE: case FCmpInst::FCMP_UGT:
35643561 }
35653562 }
35663563
3567 bool CmpInst::isTrueWhenEqual(unsigned short predicate) {
3564 bool CmpInst::isTrueWhenEqual(Predicate predicate) {
35683565 switch(predicate) {
35693566 default: return false;
35703567 case ICMP_EQ: case ICMP_UGE: case ICMP_ULE: case ICMP_SGE: case ICMP_SLE:
35723569 }
35733570 }
35743571
3575 bool CmpInst::isFalseWhenEqual(unsigned short predicate) {
3572 bool CmpInst::isFalseWhenEqual(Predicate predicate) {
35763573 switch(predicate) {
35773574 case ICMP_NE: case ICMP_UGT: case ICMP_ULT: case ICMP_SGT: case ICMP_SLT:
35783575 case FCMP_FALSE: case FCMP_ONE: case FCMP_OGT: case FCMP_OLT: return true;
611611 }
612612
613613 Value *V = CmpInst::Create(fp ? Instruction::FCmp : Instruction::ICmp,
614 op, Val0, Val1, "Cmp", BB->getTerminator());
614 (CmpInst::Predicate)op, Val0, Val1, "Cmp",
615 BB->getTerminator());
615616 return PT->push_back(V);
616617 }
617618 };