1 //===- Operator.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_SANDBOXIR_OPERATOR_H 10 #define LLVM_SANDBOXIR_OPERATOR_H 11 12 #include "llvm/IR/Operator.h" 13 #include "llvm/SandboxIR/Instruction.h" 14 #include "llvm/SandboxIR/User.h" 15 16 namespace llvm::sandboxir { 17 18 class Operator : public User { 19 public: 20 // The Operator class is intended to be used as a utility, and is never itself 21 // instantiated. 22 Operator() = delete; 23 void *operator new(size_t s) = delete; 24 classof(const Instruction *)25 static bool classof(const Instruction *) { return true; } classof(const ConstantExpr *)26 static bool classof(const ConstantExpr *) { return true; } classof(const Value * From)27 static bool classof(const Value *From) { 28 return llvm::Operator::classof(From->Val); 29 } hasPoisonGeneratingFlags()30 bool hasPoisonGeneratingFlags() const { 31 return cast<llvm::Operator>(Val)->hasPoisonGeneratingFlags(); 32 } 33 }; 34 35 class OverflowingBinaryOperator : public Operator { 36 public: hasNoUnsignedWrap()37 bool hasNoUnsignedWrap() const { 38 return cast<llvm::OverflowingBinaryOperator>(Val)->hasNoUnsignedWrap(); 39 } hasNoSignedWrap()40 bool hasNoSignedWrap() const { 41 return cast<llvm::OverflowingBinaryOperator>(Val)->hasNoSignedWrap(); 42 } getNoWrapKind()43 unsigned getNoWrapKind() const { 44 return cast<llvm::OverflowingBinaryOperator>(Val)->getNoWrapKind(); 45 } classof(const Instruction * From)46 static bool classof(const Instruction *From) { 47 return llvm::OverflowingBinaryOperator::classof( 48 cast<llvm::Instruction>(From->Val)); 49 } classof(const ConstantExpr * From)50 static bool classof(const ConstantExpr *From) { 51 return llvm::OverflowingBinaryOperator::classof( 52 cast<llvm::ConstantExpr>(From->Val)); 53 } classof(const Value * From)54 static bool classof(const Value *From) { 55 return llvm::OverflowingBinaryOperator::classof(From->Val); 56 } 57 }; 58 59 class FPMathOperator : public Operator { 60 public: isFast()61 bool isFast() const { return cast<llvm::FPMathOperator>(Val)->isFast(); } hasAllowReassoc()62 bool hasAllowReassoc() const { 63 return cast<llvm::FPMathOperator>(Val)->hasAllowReassoc(); 64 } hasNoNaNs()65 bool hasNoNaNs() const { 66 return cast<llvm::FPMathOperator>(Val)->hasNoNaNs(); 67 } hasNoInfs()68 bool hasNoInfs() const { 69 return cast<llvm::FPMathOperator>(Val)->hasNoInfs(); 70 } hasNoSignedZeros()71 bool hasNoSignedZeros() const { 72 return cast<llvm::FPMathOperator>(Val)->hasNoSignedZeros(); 73 } hasAllowReciprocal()74 bool hasAllowReciprocal() const { 75 return cast<llvm::FPMathOperator>(Val)->hasAllowReciprocal(); 76 } hasAllowContract()77 bool hasAllowContract() const { 78 return cast<llvm::FPMathOperator>(Val)->hasAllowContract(); 79 } hasApproxFunc()80 bool hasApproxFunc() const { 81 return cast<llvm::FPMathOperator>(Val)->hasApproxFunc(); 82 } getFastMathFlags()83 FastMathFlags getFastMathFlags() const { 84 return cast<llvm::FPMathOperator>(Val)->getFastMathFlags(); 85 } getFPAccuracy()86 float getFPAccuracy() const { 87 return cast<llvm::FPMathOperator>(Val)->getFPAccuracy(); 88 } isSupportedFloatingPointType(Type * Ty)89 static bool isSupportedFloatingPointType(Type *Ty) { 90 return llvm::FPMathOperator::isSupportedFloatingPointType(Ty->LLVMTy); 91 } classof(const Value * V)92 static bool classof(const Value *V) { 93 return llvm::FPMathOperator::classof(V->Val); 94 } 95 }; 96 97 } // namespace llvm::sandboxir 98 99 #endif // LLVM_SANDBOXIR_OPERATOR_H 100