1 //===-- llvm/BinaryOperators.h - BinaryOperator subclasses ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines various classes for working with specific BinaryOperators,
11 // exposing special properties that individual operations have.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_BINARY_OPTERATORS_H
16 #define LLVM_BINARY_OPTERATORS_H
18 #include "llvm/InstrTypes.h"
22 //===----------------------------------------------------------------------===//
23 // SpecificBinaryOperator Class
24 //===----------------------------------------------------------------------===//
26 /// SpecificBinaryOperator - This is a base class for utility classes that
27 /// provide additional information about binary operator instructions with
30 class SpecificBinaryOperator : public BinaryOperator {
32 // Do not implement any of these. The SpecificBinaryOperator class is
33 // intended to be used as a utility, and is never itself instantiated.
34 void *operator new(size_t, unsigned);
35 void *operator new(size_t s);
36 void Create(BinaryOps Op, Value *S1, Value *S2,
37 const std::string &Name = "",
38 Instruction *InsertBefore = 0);
39 void Create(BinaryOps Op, Value *S1, Value *S2,
40 const std::string &Name,
41 BasicBlock *InsertAtEnd);
42 SpecificBinaryOperator();
43 ~SpecificBinaryOperator();
44 void init(BinaryOps iType);
47 /// OverflowingBinaryOperator - Base class for integer arithmetic operators
48 /// which may exhibit overflow - Add, Sub, and Mul.
50 class OverflowingBinaryOperator : public SpecificBinaryOperator {
52 /// hasNoSignedOverflow - Test whether this operation is known to never
53 /// undergo signed overflow.
54 bool hasNoSignedOverflow() const {
55 return SubclassOptionalData & (1 << 0);
57 void setHasNoSignedOverflow(bool B) {
58 SubclassOptionalData = (SubclassOptionalData & ~(1 << 0)) | (B << 0);
61 /// hasNoUnsignedOverflow - Test whether this operation is known to never
62 /// undergo unsigned overflow.
63 bool hasNoUnsignedOverflow() const {
64 return SubclassOptionalData & (1 << 1);
66 void setHasNoUnsignedOverflow(bool B) {
67 SubclassOptionalData = (SubclassOptionalData & ~(1 << 1)) | (B << 1);
70 static inline bool classof(const OverflowingBinaryOperator *) { return true; }
71 static inline bool classof(const BinaryOperator *BO) {
72 return BO->getOpcode() == Instruction::Add ||
73 BO->getOpcode() == Instruction::Sub ||
74 BO->getOpcode() == Instruction::Mul;
76 static inline bool classof(const Instruction *I) {
77 return I->isBinaryOp() && classof(cast<BinaryOperator>(I));
79 static inline bool classof(const Value *V) {
80 return isa<Instruction>(V) && classof(cast<Instruction>(V));
84 /// UDivInst - BinaryOperators with opcode Instruction::UDiv.
86 class UDivInst : public SpecificBinaryOperator {
88 /// isExact - Test whether this division is known to be exact, with
90 bool isExact() const {
91 return SubclassOptionalData & (1 << 0);
93 void setIsExact(bool B) {
94 SubclassOptionalData = (SubclassOptionalData & ~(1 << 0)) | (B << 0);
97 // Methods for support type inquiry through isa, cast, and dyn_cast:
98 static inline bool classof(const UDivInst *) { return true; }
99 static inline bool classof(const BinaryOperator *BO) {
100 return BO->getOpcode() == Instruction::UDiv;
102 static inline bool classof(const Instruction *I) {
103 return I->isBinaryOp() && classof(cast<BinaryOperator>(I));
105 static inline bool classof(const Value *V) {
106 return isa<Instruction>(V) && classof(cast<Instruction>(V));
110 } // End llvm namespace