From 05333b4d40bf65a4f3ee3b33907335230143bc57 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sat, 24 Jun 2017 07:02:52 +0000 Subject: [PATCH] [IR] Remove BinOp2_match and replace its usage with the more capable BinOpPred_match. llvm-svn: 306207 --- llvm/include/llvm/IR/PatternMatch.h | 97 ++++++++++++++--------------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 84dc2a1fa482..791dbb8dc869 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -659,50 +659,6 @@ m_NUWShl(const LHS &L, const RHS &R) { L, R); } -//===----------------------------------------------------------------------===// -// Class that matches two different binary ops. -// -template -struct BinOp2_match { - LHS_t L; - RHS_t R; - - BinOp2_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {} - - template bool match(OpTy *V) { - if (V->getValueID() == Value::InstructionVal + Opc1 || - V->getValueID() == Value::InstructionVal + Opc2) { - auto *I = cast(V); - return L.match(I->getOperand(0)) && R.match(I->getOperand(1)); - } - if (auto *CE = dyn_cast(V)) - return (CE->getOpcode() == Opc1 || CE->getOpcode() == Opc2) && - L.match(CE->getOperand(0)) && R.match(CE->getOperand(1)); - return false; - } -}; - -/// \brief Matches LShr or AShr. -template -inline BinOp2_match -m_Shr(const LHS &L, const RHS &R) { - return BinOp2_match(L, R); -} - -/// \brief Matches LShr or Shl. -template -inline BinOp2_match -m_LogicalShift(const LHS &L, const RHS &R) { - return BinOp2_match(L, R); -} - -/// \brief Matches UDiv and SDiv. -template -inline BinOp2_match -m_IDiv(const LHS &L, const RHS &R) { - return BinOp2_match(L, R); -} - //===----------------------------------------------------------------------===// // Class that matches a group of binary opcodes. // @@ -715,9 +671,11 @@ struct BinOpPred_match : Predicate { template bool match(OpTy *V) { if (auto *I = dyn_cast(V)) - return this->isOpType(I->getOpcode()) && L.match(I->getOperand(0)) && R.match(I->getOperand(1)); + return this->isOpType(I->getOpcode()) && L.match(I->getOperand(0)) && + R.match(I->getOperand(1)); if (auto *CE = dyn_cast(V)) - return this->isOpType(CE->getOpcode()) && L.match(CE->getOperand(0)) && R.match(CE->getOperand(1)); + return this->isOpType(CE->getOpcode()) && L.match(CE->getOperand(0)) && + R.match(CE->getOperand(1)); return false; } }; @@ -726,17 +684,51 @@ struct is_shift_op { bool isOpType(unsigned Opcode) { return Instruction::isShift(Opcode); } }; +struct is_right_shift_op { + bool isOpType(unsigned Opcode) { + return Opcode == Instruction::LShr || Opcode == Instruction::AShr; + } +}; + +struct is_logical_shift_op { + bool isOpType(unsigned Opcode) { + return Opcode == Instruction::LShr || Opcode == Instruction::Shl; + } +}; + struct is_bitwiselogic_op { - bool isOpType(unsigned Opcode) { return Instruction::isBitwiseLogicOp(Opcode); } + bool isOpType(unsigned Opcode) { + return Instruction::isBitwiseLogicOp(Opcode); + } +}; + +struct is_idiv_op { + bool isOpType(unsigned Opcode) { + return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv; + } }; /// \brief Matches shift operations. template -inline BinOpPred_match -m_Shift(const LHS &L, const RHS &R) { +inline BinOpPred_match m_Shift(const LHS &L, + const RHS &R) { return BinOpPred_match(L, R); } +/// \brief Matches logical shift operations. +template +inline BinOpPred_match m_Shr(const LHS &L, + const RHS &R) { + return BinOpPred_match(L, R); +} + +/// \brief Matches logical shift operations. +template +inline BinOpPred_match +m_LogicalShift(const LHS &L, const RHS &R) { + return BinOpPred_match(L, R); +} + /// \brief Matches bitwise logic operations. template inline BinOpPred_match @@ -744,6 +736,13 @@ m_BitwiseLogic(const LHS &L, const RHS &R) { return BinOpPred_match(L, R); } +/// \brief Matches integer division operations. +template +inline BinOpPred_match m_IDiv(const LHS &L, + const RHS &R) { + return BinOpPred_match(L, R); +} + //===----------------------------------------------------------------------===// // Class that matches exact binary ops. // -- GitLab