1 //===- llvm/Analysis/FloatingPointPredicateUtils.h ------------*- C++ -*---===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_ANALYSIS_FLOATINGPOINTPREDICATEUTILS_H 10 #define LLVM_ANALYSIS_FLOATINGPOINTPREDICATEUTILS_H 11 12 #include "llvm/IR/GenericFloatingPointPredicateUtils.h" 13 #include "llvm/IR/SSAContext.h" 14 #include "llvm/Support/Compiler.h" 15 16 namespace llvm { 17 18 using FloatingPointPredicateUtils = 19 GenericFloatingPointPredicateUtils<SSAContext>; 20 21 template <> 22 LLVM_ABI DenormalMode 23 FloatingPointPredicateUtils::queryDenormalMode(const Function &F, Value *Val); 24 25 template <> 26 LLVM_ABI bool FloatingPointPredicateUtils::lookThroughFAbs(const Function &F, 27 Value *LHS, 28 Value *&Src); 29 30 template <> 31 LLVM_ABI std::optional<APFloat> 32 FloatingPointPredicateUtils::matchConstantFloat(const Function &F, Value *Val); 33 34 /// Returns a pair of values, which if passed to llvm.is.fpclass, returns the 35 /// same result as an fcmp with the given operands. 36 /// 37 /// If \p LookThroughSrc is true, consider the input value when computing the 38 /// mask. 39 /// 40 /// If \p LookThroughSrc is false, ignore the source value (i.e. the first pair 41 /// element will always be LHS. 42 inline std::pair<Value *, FPClassTest> 43 fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS, 44 Value *RHS, bool LookThroughSrc = true) { 45 return FloatingPointPredicateUtils::fcmpToClassTest(Pred, F, LHS, RHS, 46 LookThroughSrc = true); 47 } 48 49 /// Returns a pair of values, which if passed to llvm.is.fpclass, returns the 50 /// same result as an fcmp with the given operands. 51 /// 52 /// If \p LookThroughSrc is true, consider the input value when computing the 53 /// mask. 54 /// 55 /// If \p LookThroughSrc is false, ignore the source value (i.e. the first pair 56 /// element will always be LHS. 57 inline std::pair<Value *, FPClassTest> 58 fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS, 59 const APFloat *ConstRHS, bool LookThroughSrc = true) { 60 return FloatingPointPredicateUtils::fcmpToClassTest(Pred, F, LHS, *ConstRHS, 61 LookThroughSrc); 62 } 63 64 inline std::tuple<Value *, FPClassTest, FPClassTest> 65 fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS, 66 FPClassTest RHSClass, bool LookThroughSrc = true) { 67 return FloatingPointPredicateUtils::fcmpImpliesClass(Pred, F, LHS, RHSClass, 68 LookThroughSrc); 69 } 70 71 inline std::tuple<Value *, FPClassTest, FPClassTest> 72 fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS, 73 const APFloat &ConstRHS, bool LookThroughSrc = true) { 74 return FloatingPointPredicateUtils::fcmpImpliesClass(Pred, F, LHS, ConstRHS, 75 LookThroughSrc); 76 } 77 78 inline std::tuple<Value *, FPClassTest, FPClassTest> 79 fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS, 80 Value *RHS, bool LookThroughSrc = true) { 81 return FloatingPointPredicateUtils::fcmpImpliesClass(Pred, F, LHS, RHS, 82 LookThroughSrc); 83 } 84 85 } // namespace llvm 86 87 #endif // LLVM_ANALYSIS_FLOATINGPOINTPREDICATEUTILS_H 88