From aa45f148926e3461a1fd8b10c990f0a51a908cc9 Mon Sep 17 00:00:00 2001 From: dim Date: Mon, 10 Jun 2013 20:36:52 +0000 Subject: Vendor import of llvm tags/RELEASE_33/final r183502 (effectively, 3.3 release): http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_33/final@183502 --- include/llvm/Support/PatternMatch.h | 116 ++++++++++++++++++++++++++++++++---- 1 file changed, 105 insertions(+), 11 deletions(-) (limited to 'include/llvm/Support/PatternMatch.h') diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index 9fbe434..95d9d78 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -693,6 +693,12 @@ m_ZExt(const OpTy &Op) { return CastClass_match(Op); } +/// m_UIToFP +template +inline CastClass_match +m_UIToFp(const OpTy &Op) { + return CastClass_match(Op); +} //===----------------------------------------------------------------------===// // Matchers for unary operators @@ -830,7 +836,7 @@ inline brc_match m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F) { // Matchers for max/min idioms, eg: "select (sgt x, y), x, y" -> smax(x,y). // -template +template struct MaxMin_match { LHS_t L; RHS_t R; @@ -844,7 +850,7 @@ struct MaxMin_match { SelectInst *SI = dyn_cast(V); if (!SI) return false; - ICmpInst *Cmp = dyn_cast(SI->getCondition()); + CmpInst_t *Cmp = dyn_cast(SI->getCondition()); if (!Cmp) return false; // At this point we have a select conditioned on a comparison. Check that @@ -856,7 +862,7 @@ struct MaxMin_match { if ((TrueVal != LHS || FalseVal != RHS) && (TrueVal != RHS || FalseVal != LHS)) return false; - ICmpInst::Predicate Pred = LHS == TrueVal ? + typename CmpInst_t::Predicate Pred = LHS == TrueVal ? Cmp->getPredicate() : Cmp->getSwappedPredicate(); // Does "(x pred y) ? x : y" represent the desired max/min operation? if (!Pred_t::match(Pred)) @@ -894,28 +900,116 @@ struct umin_pred_ty { } }; +/// ofmax_pred_ty - Helper class for identifying ordered max predicates. +struct ofmax_pred_ty { + static bool match(FCmpInst::Predicate Pred) { + return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE; + } +}; + +/// ofmin_pred_ty - Helper class for identifying ordered min predicates. +struct ofmin_pred_ty { + static bool match(FCmpInst::Predicate Pred) { + return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE; + } +}; + +/// ufmax_pred_ty - Helper class for identifying unordered max predicates. +struct ufmax_pred_ty { + static bool match(FCmpInst::Predicate Pred) { + return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE; + } +}; + +/// ufmin_pred_ty - Helper class for identifying unordered min predicates. +struct ufmin_pred_ty { + static bool match(FCmpInst::Predicate Pred) { + return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE; + } +}; + template -inline MaxMin_match +inline MaxMin_match m_SMax(const LHS &L, const RHS &R) { - return MaxMin_match(L, R); + return MaxMin_match(L, R); } template -inline MaxMin_match +inline MaxMin_match m_SMin(const LHS &L, const RHS &R) { - return MaxMin_match(L, R); + return MaxMin_match(L, R); } template -inline MaxMin_match +inline MaxMin_match m_UMax(const LHS &L, const RHS &R) { - return MaxMin_match(L, R); + return MaxMin_match(L, R); } template -inline MaxMin_match +inline MaxMin_match m_UMin(const LHS &L, const RHS &R) { - return MaxMin_match(L, R); + return MaxMin_match(L, R); +} + +/// \brief Match an 'ordered' floating point maximum function. +/// Floating point has one special value 'NaN'. Therefore, there is no total +/// order. However, if we can ignore the 'NaN' value (for example, because of a +/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum' +/// semantics. In the presence of 'NaN' we have to preserve the original +/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate. +/// +/// max(L, R) iff L and R are not NaN +/// m_OrdFMax(L, R) = R iff L or R are NaN +template +inline MaxMin_match +m_OrdFMax(const LHS &L, const RHS &R) { + return MaxMin_match(L, R); +} + +/// \brief Match an 'ordered' floating point minimum function. +/// Floating point has one special value 'NaN'. Therefore, there is no total +/// order. However, if we can ignore the 'NaN' value (for example, because of a +/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum' +/// semantics. In the presence of 'NaN' we have to preserve the original +/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate. +/// +/// max(L, R) iff L and R are not NaN +/// m_OrdFMin(L, R) = R iff L or R are NaN +template +inline MaxMin_match +m_OrdFMin(const LHS &L, const RHS &R) { + return MaxMin_match(L, R); +} + +/// \brief Match an 'unordered' floating point maximum function. +/// Floating point has one special value 'NaN'. Therefore, there is no total +/// order. However, if we can ignore the 'NaN' value (for example, because of a +/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum' +/// semantics. In the presence of 'NaN' we have to preserve the original +/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate. +/// +/// max(L, R) iff L and R are not NaN +/// m_UnordFMin(L, R) = L iff L or R are NaN +template +inline MaxMin_match +m_UnordFMax(const LHS &L, const RHS &R) { + return MaxMin_match(L, R); +} + +/// \brief Match an 'unordered' floating point minimum function. +/// Floating point has one special value 'NaN'. Therefore, there is no total +/// order. However, if we can ignore the 'NaN' value (for example, because of a +/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum' +/// semantics. In the presence of 'NaN' we have to preserve the original +/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate. +/// +/// max(L, R) iff L and R are not NaN +/// m_UnordFMin(L, R) = L iff L or R are NaN +template +inline MaxMin_match +m_UnordFMin(const LHS &L, const RHS &R) { + return MaxMin_match(L, R); } template -- cgit v1.1