Define a no-pointer-overflow flag for GetElementPtr instructions.
[oota-llvm.git] / include / llvm / BinaryOperators.h
1 //===-- llvm/BinaryOperators.h - BinaryOperator subclasses ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines various classes for working with specific BinaryOperators,
11 // exposing special properties that individual operations have.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_BINARY_OPTERATORS_H
16 #define LLVM_BINARY_OPTERATORS_H
17
18 #include "llvm/InstrTypes.h"
19
20 namespace llvm {
21
22 //===----------------------------------------------------------------------===//
23 //                      SpecificBinaryOperator Class
24 //===----------------------------------------------------------------------===//
25
26 /// SpecificBinaryOperator - This is a base class for utility classes that
27 /// provide additional information about binary operator instructions with
28 /// specific opcodes.
29 ///
30 class SpecificBinaryOperator : public BinaryOperator {
31 private:
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);
45 };
46
47 /// OverflowingBinaryOperator - Base class for integer arithmetic operators
48 /// which may exhibit overflow - Add, Sub, and Mul.
49 ///
50 class OverflowingBinaryOperator : public SpecificBinaryOperator {
51 public:
52   /// hasNoSignedOverflow - Test whether this operation is known to never
53   /// undergo signed overflow.
54   bool hasNoSignedOverflow() const {
55     return SubclassOptionalData & (1 << 0);
56   }
57   void setHasNoSignedOverflow(bool B) {
58     SubclassOptionalData = (SubclassOptionalData & ~(1 << 0)) | (B << 0);
59   }
60
61   /// hasNoUnsignedOverflow - Test whether this operation is known to never
62   /// undergo unsigned overflow.
63   bool hasNoUnsignedOverflow() const {
64     return SubclassOptionalData & (1 << 1);
65   }
66   void setHasNoUnsignedOverflow(bool B) {
67     SubclassOptionalData = (SubclassOptionalData & ~(1 << 1)) | (B << 1);
68   }
69
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;
75   }
76   static inline bool classof(const Instruction *I) {
77     return I->isBinaryOp() && classof(cast<BinaryOperator>(I));
78   }
79   static inline bool classof(const Value *V) {
80     return isa<Instruction>(V) && classof(cast<Instruction>(V));
81   }
82 };
83
84 /// UDivInst - BinaryOperators with opcode Instruction::UDiv.
85 ///
86 class UDivInst : public SpecificBinaryOperator {
87 public:
88   /// isExact - Test whether this division is known to be exact, with
89   /// zero remainder.
90   bool isExact() const {
91     return SubclassOptionalData & (1 << 0);
92   }
93   void setIsExact(bool B) {
94     SubclassOptionalData = (SubclassOptionalData & ~(1 << 0)) | (B << 0);
95   }
96
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;
101   }
102   static inline bool classof(const Instruction *I) {
103     return I->isBinaryOp() && classof(cast<BinaryOperator>(I));
104   }
105   static inline bool classof(const Value *V) {
106     return isa<Instruction>(V) && classof(cast<Instruction>(V));
107   }
108 };
109
110 } // End llvm namespace
111
112 #endif