Index: llvm/trunk/include/llvm/IR/PatternMatch.h =================================================================== --- llvm/trunk/include/llvm/IR/PatternMatch.h +++ llvm/trunk/include/llvm/IR/PatternMatch.h @@ -991,116 +991,111 @@ } //===----------------------------------------------------------------------===// -// Matchers for SelectInst classes +// Matchers for instructions with a given opcode and number of operands. // -template -struct SelectClass_match { - Cond_t C; - LHS_t L; - RHS_t R; +/// Matches instructions with Opcode and three operands. +template struct OneOps_match { + T0 Op1; + + OneOps_match(const T0 &Op1) : Op1(Op1) {} + + template bool match(OpTy *V) { + if (V->getValueID() == Value::InstructionVal + Opcode) { + auto *I = cast(V); + return Op1.match(I->getOperand(0)); + } + return false; + } +}; + +/// Matches instructions with Opcode and three operands. +template struct TwoOps_match { + T0 Op1; + T1 Op2; - SelectClass_match(const Cond_t &Cond, const LHS_t &LHS, const RHS_t &RHS) - : C(Cond), L(LHS), R(RHS) {} + TwoOps_match(const T0 &Op1, const T1 &Op2) : Op1(Op1), Op2(Op2) {} template bool match(OpTy *V) { - if (auto *I = dyn_cast(V)) - return C.match(I->getOperand(0)) && L.match(I->getOperand(1)) && - R.match(I->getOperand(2)); + if (V->getValueID() == Value::InstructionVal + Opcode) { + auto *I = cast(V); + return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)); + } + return false; + } +}; + +/// Matches instructions with Opcode and three operands. +template +struct ThreeOps_match { + T0 Op1; + T1 Op2; + T2 Op3; + + ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3) + : Op1(Op1), Op2(Op2), Op3(Op3) {} + + template bool match(OpTy *V) { + if (V->getValueID() == Value::InstructionVal + Opcode) { + auto *I = cast(V); + return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) && + Op3.match(I->getOperand(2)); + } return false; } }; +/// Matches SelectInst. template -inline SelectClass_match m_Select(const Cond &C, const LHS &L, - const RHS &R) { - return SelectClass_match(C, L, R); +inline ThreeOps_match +m_Select(const Cond &C, const LHS &L, const RHS &R) { + return ThreeOps_match(C, L, R); } /// This matches a select of two constants, e.g.: /// m_SelectCst<-1, 0>(m_Value(V)) template -inline SelectClass_match, constantint_match> +inline ThreeOps_match, constantint_match, + Instruction::Select> m_SelectCst(const Cond &C) { return m_Select(C, m_ConstantInt(), m_ConstantInt()); } -//===----------------------------------------------------------------------===// -// Matchers for InsertElementInst classes -// - +/// Matches InsertElementInst. template -struct InsertElementClass_match { - Val_t V; - Elt_t E; - Idx_t I; - - InsertElementClass_match(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) - : V(Val), E(Elt), I(Idx) {} - - template bool match(OpTy *VV) { - if (auto *II = dyn_cast(VV)) - return V.match(II->getOperand(0)) && E.match(II->getOperand(1)) && - I.match(II->getOperand(2)); - return false; - } -}; - -template -inline InsertElementClass_match +inline ThreeOps_match m_InsertElement(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) { - return InsertElementClass_match(Val, Elt, Idx); + return ThreeOps_match( + Val, Elt, Idx); } -//===----------------------------------------------------------------------===// -// Matchers for ExtractElementInst classes -// - -template struct ExtractElementClass_match { - Val_t V; - Idx_t I; - - ExtractElementClass_match(const Val_t &Val, const Idx_t &Idx) - : V(Val), I(Idx) {} - - template bool match(OpTy *VV) { - if (auto *II = dyn_cast(VV)) - return V.match(II->getOperand(0)) && I.match(II->getOperand(1)); - return false; - } -}; - +/// Matches ExtractElementInst. template -inline ExtractElementClass_match +inline TwoOps_match m_ExtractElement(const Val_t &Val, const Idx_t &Idx) { - return ExtractElementClass_match(Val, Idx); + return TwoOps_match(Val, Idx); } -//===----------------------------------------------------------------------===// -// Matchers for ShuffleVectorInst classes -// - +/// Matches ShuffleVectorInst. template -struct ShuffleVectorClass_match { - V1_t V1; - V2_t V2; - Mask_t M; - - ShuffleVectorClass_match(const V1_t &v1, const V2_t &v2, const Mask_t &m) - : V1(v1), V2(v2), M(m) {} +inline ThreeOps_match +m_ShuffleVector(const V1_t &v1, const V2_t &v2, const Mask_t &m) { + return ThreeOps_match(v1, v2, + m); +} - template bool match(OpTy *V) { - if (auto *SI = dyn_cast(V)) - return V1.match(SI->getOperand(0)) && V2.match(SI->getOperand(1)) && - M.match(SI->getOperand(2)); - return false; - } -}; +/// Matches LoadInst. +template +inline OneOps_match m_Load(const OpTy &Op) { + return OneOps_match(Op); +} -template -inline ShuffleVectorClass_match -m_ShuffleVector(const V1_t &v1, const V2_t &v2, const Mask_t &m) { - return ShuffleVectorClass_match(v1, v2, m); +/// Matches StoreInst. +template +inline TwoOps_match +m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) { + return TwoOps_match(ValueOp, + PointerOp); } //===----------------------------------------------------------------------===// @@ -1181,54 +1176,6 @@ } //===----------------------------------------------------------------------===// -// Matcher for LoadInst classes -// - -template struct LoadClass_match { - Op_t Op; - - LoadClass_match(const Op_t &OpMatch) : Op(OpMatch) {} - - template bool match(OpTy *V) { - if (auto *LI = dyn_cast(V)) - return Op.match(LI->getPointerOperand()); - return false; - } -}; - -/// Matches LoadInst. -template inline LoadClass_match m_Load(const OpTy &Op) { - return LoadClass_match(Op); -} - -//===----------------------------------------------------------------------===// -// Matcher for StoreInst classes -// - -template struct StoreClass_match { - ValueOp_t ValueOp; - PointerOp_t PointerOp; - - StoreClass_match(const ValueOp_t &ValueOpMatch, - const PointerOp_t &PointerOpMatch) : - ValueOp(ValueOpMatch), PointerOp(PointerOpMatch) {} - - template bool match(OpTy *V) { - if (auto *LI = dyn_cast(V)) - return ValueOp.match(LI->getValueOperand()) && - PointerOp.match(LI->getPointerOperand()); - return false; - } -}; - -/// Matches StoreInst. -template -inline StoreClass_match -m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) { - return StoreClass_match(ValueOp, PointerOp); -} - -//===----------------------------------------------------------------------===// // Matchers for control flow. //