Skip to content

Commit

Permalink
[IR] Move repeated asserts in FCmpInst constructor to a helper method…
Browse files Browse the repository at this point in the history
… like we do for ICmpInst and other classes. NFC

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306249 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
topperc committed Jun 25, 2017
1 parent 61b5c7b commit 3758200
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions include/llvm/IR/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,16 @@ class ICmpInst: public CmpInst {
/// vectors of floating point values. The operands must be identical types.
/// Represents a floating point comparison operator.
class FCmpInst: public CmpInst {
void AssertOK() {
assert(getPredicate() <= FCmpInst::LAST_FCMP_PREDICATE &&
"Invalid FCmp predicate value");
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
"Both operands to FCmp instruction are not of the same type!");
// Check that the operands are the right type
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
"Invalid operand types for FCmp instruction");
}

protected:
// Note: Instruction needs to be a friend here to call cloneImpl.
friend class Instruction;
Expand All @@ -1261,13 +1271,7 @@ class FCmpInst: public CmpInst {
) : CmpInst(makeCmpResultType(LHS->getType()),
Instruction::FCmp, pred, LHS, RHS, NameStr,
InsertBefore) {
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
"Invalid FCmp predicate value");
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
"Both operands to FCmp instruction are not of the same type!");
// Check that the operands are the right type
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
"Invalid operand types for FCmp instruction");
AssertOK();
}

/// Constructor with insert-at-end semantics.
Expand All @@ -1280,13 +1284,7 @@ class FCmpInst: public CmpInst {
) : CmpInst(makeCmpResultType(LHS->getType()),
Instruction::FCmp, pred, LHS, RHS, NameStr,
&InsertAtEnd) {
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
"Invalid FCmp predicate value");
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
"Both operands to FCmp instruction are not of the same type!");
// Check that the operands are the right type
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
"Invalid operand types for FCmp instruction");
AssertOK();
}

/// Constructor with no-insertion semantics
Expand All @@ -1297,13 +1295,7 @@ class FCmpInst: public CmpInst {
const Twine &NameStr = "" ///< Name of the instruction
) : CmpInst(makeCmpResultType(LHS->getType()),
Instruction::FCmp, pred, LHS, RHS, NameStr) {
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
"Invalid FCmp predicate value");
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
"Both operands to FCmp instruction are not of the same type!");
// Check that the operands are the right type
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
"Invalid operand types for FCmp instruction");
AssertOK();
}

/// @returns true if the predicate of this instruction is EQ or NE.
Expand Down

0 comments on commit 3758200

Please sign in to comment.