X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FPatternMatch.h;h=f02bc347a17ec102db137b560247f3359cb05899;hb=070c07f2c881c9f005c411fb113011a2d5af4057;hp=f085b0ff510faef3f9ba59b5cce412a6312c8a66;hpb=4ae5126d041768ab9665cf2f11c024becd76c41f;p=oota-llvm.git diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index f085b0ff510..f02bc347a17 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -58,7 +58,7 @@ struct constantint_ty { if (const ConstantInt *CI = dyn_cast(V)) { const APInt &CIV = CI->getValue(); if (Val >= 0) - return CIV == Val; + return CIV == static_cast(Val); // If Val is negative, and CI is shorter than it, truncate to the right // number of bits. If it is larger, then we have to sign extend. Just // compare their negated values. @@ -87,6 +87,18 @@ struct zero_ty { /// m_Zero() - Match an arbitrary zero/null constant. inline zero_ty m_Zero() { return zero_ty(); } +struct one_ty { + template + bool match(ITy *V) { + if (const ConstantInt *C = dyn_cast(V)) + return C->isOne(); + return false; + } +}; + +/// m_One() - Match a an integer 1. +inline one_ty m_One() { return one_ty(); } + template struct bind_ty { @@ -411,7 +423,7 @@ m_Select(const Cond &C, const LHS &L, const RHS &R) { } /// m_SelectCst - This matches a select of two constants, e.g.: -/// m_SelectCst(m_Value(V), -1, 0) +/// m_SelectCst<-1, 0>(m_Value(V)) template inline SelectClass_match, constantint_ty > m_SelectCst(const Cond &C) { @@ -425,7 +437,7 @@ m_SelectCst(const Cond &C) { // Matchers for CastInst classes // -template +template struct CastClass_match { Op_t Op; @@ -433,17 +445,42 @@ struct CastClass_match { template bool match(OpTy *V) { - if (Class *I = dyn_cast(V)) - return Op.match(I->getOperand(0)); + if (CastInst *I = dyn_cast(V)) + return I->getOpcode() == Opcode && Op.match(I->getOperand(0)); + if (ConstantExpr *CE = dyn_cast(V)) + return CE->getOpcode() == Opcode && Op.match(CE->getOperand(0)); return false; } }; -template -inline CastClass_match m_Cast(const OpTy &Op) { - return CastClass_match(Op); +/// m_PtrToInt +template +inline CastClass_match +m_PtrToInt(const OpTy &Op) { + return CastClass_match(Op); +} + +/// m_Trunc +template +inline CastClass_match +m_Trunc(const OpTy &Op) { + return CastClass_match(Op); } +/// m_SExt +template +inline CastClass_match +m_SExt(const OpTy &Op) { + return CastClass_match(Op); +} + +/// m_ZExt +template +inline CastClass_match +m_ZExt(const OpTy &Op) { + return CastClass_match(Op); +} + //===----------------------------------------------------------------------===// // Matchers for unary operators