diff --git a/llvm/include/llvm/BinaryOperators.h b/llvm/include/llvm/BinaryOperators.h deleted file mode 100644 index 4dce9af56e54..000000000000 --- a/llvm/include/llvm/BinaryOperators.h +++ /dev/null @@ -1,112 +0,0 @@ -//===-- llvm/BinaryOperators.h - BinaryOperator subclasses ------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines various classes for working with specific BinaryOperators, -// exposing special properties that individual operations have. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_BINARY_OPTERATORS_H -#define LLVM_BINARY_OPTERATORS_H - -#include "llvm/InstrTypes.h" - -namespace llvm { - -//===----------------------------------------------------------------------===// -// SpecificBinaryOperator Class -//===----------------------------------------------------------------------===// - -/// SpecificBinaryOperator - This is a base class for utility classes that -/// provide additional information about binary operator instructions with -/// specific opcodes. -/// -class SpecificBinaryOperator : public BinaryOperator { -private: - // Do not implement any of these. The SpecificBinaryOperator class is - // intended to be used as a utility, and is never itself instantiated. - void *operator new(size_t, unsigned); - void *operator new(size_t s); - void Create(BinaryOps Op, Value *S1, Value *S2, - const std::string &Name = "", - Instruction *InsertBefore = 0); - void Create(BinaryOps Op, Value *S1, Value *S2, - const std::string &Name, - BasicBlock *InsertAtEnd); - SpecificBinaryOperator(); - ~SpecificBinaryOperator(); - void init(BinaryOps iType); -}; - -/// OverflowingBinaryOperator - Base class for integer arithmetic operators -/// which may exhibit overflow - Add, Sub, and Mul. -/// -class OverflowingBinaryOperator : public SpecificBinaryOperator { -public: - /// hasNoSignedOverflow - Test whether this operation is known to never - /// undergo signed overflow. - bool hasNoSignedOverflow() const { - return SubclassOptionalData & (1 << 0); - } - void setHasNoSignedOverflow(bool B) { - SubclassOptionalData = (SubclassOptionalData & ~(1 << 0)) | (B << 0); - } - - /// hasNoUnsignedOverflow - Test whether this operation is known to never - /// undergo unsigned overflow. - bool hasNoUnsignedOverflow() const { - return SubclassOptionalData & (1 << 1); - } - void setHasNoUnsignedOverflow(bool B) { - SubclassOptionalData = (SubclassOptionalData & ~(1 << 1)) | (B << 1); - } - - static inline bool classof(const OverflowingBinaryOperator *) { return true; } - static inline bool classof(const BinaryOperator *BO) { - return BO->getOpcode() == Instruction::Add || - BO->getOpcode() == Instruction::Sub || - BO->getOpcode() == Instruction::Mul; - } - static inline bool classof(const Instruction *I) { - return I->isBinaryOp() && classof(cast(I)); - } - static inline bool classof(const Value *V) { - return isa(V) && classof(cast(V)); - } -}; - -/// UDivInst - BinaryOperators with opcode Instruction::UDiv. -/// -class UDivInst : public SpecificBinaryOperator { -public: - /// isExact - Test whether this division is known to be exact, with - /// zero remainder. - bool isExact() const { - return SubclassOptionalData & (1 << 0); - } - void setIsExact(bool B) { - SubclassOptionalData = (SubclassOptionalData & ~(1 << 0)) | (B << 0); - } - - // Methods for support type inquiry through isa, cast, and dyn_cast: - static inline bool classof(const UDivInst *) { return true; } - static inline bool classof(const BinaryOperator *BO) { - return BO->getOpcode() == Instruction::UDiv; - } - static inline bool classof(const Instruction *I) { - return I->isBinaryOp() && classof(cast(I)); - } - static inline bool classof(const Value *V) { - return isa(V) && classof(cast(V)); - } -}; - -} // End llvm namespace - -#endif diff --git a/llvm/include/llvm/Operator.h b/llvm/include/llvm/Operator.h new file mode 100644 index 000000000000..4da19219d2f4 --- /dev/null +++ b/llvm/include/llvm/Operator.h @@ -0,0 +1,132 @@ +//===-- llvm/Operator.h - Operator utility subclass -------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines various classes for working with Instructions and +// ConstantExprs. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OPERATOR_H +#define LLVM_OPERATOR_H + +#include "llvm/Instruction.h" +#include "llvm/Constants.h" + +namespace llvm { + +/// Operator - This is a utility class that provides an abstraction for the +/// common functionality between Instructions and ConstantExprs. +/// +class Operator : public User { +private: + // Do not implement any of these. The Operator class is intended to be used + // as a utility, and is never itself instantiated. + void *operator new(size_t, unsigned); + void *operator new(size_t s); + Operator(); + ~Operator(); + +public: + /// getOpcode - Return the opcode for this Instruction or ConstantExpr. + /// + unsigned getOpcode() const { + if (const Instruction *I = dyn_cast(this)) + return I->getOpcode(); + return cast(this)->getOpcode(); + } + + /// getOpcode - If V is an Instruction or ConstantExpr, return its + /// opcode. Otherwise return UserOp1. + /// + static unsigned getOpcode(const Value *V) { + if (const Instruction *I = dyn_cast(V)) + return I->getOpcode(); + if (const ConstantExpr *CE = dyn_cast(V)) + return CE->getOpcode(); + return Instruction::UserOp1; + } + + static inline bool classof(const Operator *) { return true; } + static inline bool classof(const Instruction *I) { return true; } + static inline bool classof(const ConstantExpr *I) { return true; } + static inline bool classof(const Value *V) { + return isa(V) || isa(V); + } +}; + +/// OverflowingBinaryOperator - Utility class for integer arithmetic operators +/// which may exhibit overflow - Add, Sub, and Mul. +/// +class OverflowingBinaryOperator : public Operator { +public: + /// hasNoSignedOverflow - Test whether this operation is known to never + /// undergo signed overflow. + bool hasNoSignedOverflow() const { + return SubclassOptionalData & (1 << 0); + } + void setHasNoSignedOverflow(bool B) { + SubclassOptionalData = (SubclassOptionalData & ~(1 << 0)) | (B << 0); + } + + /// hasNoUnsignedOverflow - Test whether this operation is known to never + /// undergo unsigned overflow. + bool hasNoUnsignedOverflow() const { + return SubclassOptionalData & (1 << 1); + } + void setHasNoUnsignedOverflow(bool B) { + SubclassOptionalData = (SubclassOptionalData & ~(1 << 1)) | (B << 1); + } + + static inline bool classof(const OverflowingBinaryOperator *) { return true; } + static inline bool classof(const Instruction *I) { + return I->getOpcode() == Instruction::Add || + I->getOpcode() == Instruction::Sub || + I->getOpcode() == Instruction::Mul; + } + static inline bool classof(const ConstantExpr *CE) { + return CE->getOpcode() == Instruction::Add || + CE->getOpcode() == Instruction::Sub || + CE->getOpcode() == Instruction::Mul; + } + static inline bool classof(const Value *V) { + return (isa(V) && classof(cast(V))) || + (isa(V) && classof(cast(V))); + } +}; + +/// UDivOperator - An Operator with opcode Instruction::UDiv. +/// +class UDivOperator : public Operator { +public: + /// isExact - Test whether this division is known to be exact, with + /// zero remainder. + bool isExact() const { + return SubclassOptionalData & (1 << 0); + } + void setIsExact(bool B) { + SubclassOptionalData = (SubclassOptionalData & ~(1 << 0)) | (B << 0); + } + + // Methods for support type inquiry through isa, cast, and dyn_cast: + static inline bool classof(const UDivOperator *) { return true; } + static inline bool classof(const ConstantExpr *CE) { + return CE->getOpcode() == Instruction::UDiv; + } + static inline bool classof(const Instruction *I) { + return I->getOpcode() == Instruction::UDiv; + } + static inline bool classof(const Value *V) { + return (isa(V) && classof(cast(V))) || + (isa(V) && classof(cast(V))); + } +}; + +} // End llvm namespace + +#endif diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 1b0b37ba0105..6c23f401c5b1 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -66,6 +66,7 @@ #include "llvm/GlobalVariable.h" #include "llvm/Instructions.h" #include "llvm/LLVMContext.h" +#include "llvm/Operator.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/LoopInfo.h" @@ -2430,7 +2431,7 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) { /// createNodeForGEP - Expand GEP instructions into add and multiply /// operations. This allows them to be analyzed by regular SCEV code. /// -const SCEV *ScalarEvolution::createNodeForGEP(User *GEP) { +const SCEV *ScalarEvolution::createNodeForGEP(Operator *GEP) { const Type *IntPtrTy = TD->getIntPtrType(); Value *Base = GEP->getOperand(0); @@ -2779,7 +2780,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) { else return getUnknown(V); - User *U = cast(V); + Operator *U = cast(V); switch (Opcode) { case Instruction::Add: return getAddExpr(getSCEV(U->getOperand(0)), diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index ddf17524497f..4cca313101f8 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -18,24 +18,13 @@ #include "llvm/GlobalVariable.h" #include "llvm/IntrinsicInst.h" #include "llvm/LLVMContext.h" +#include "llvm/Operator.h" #include "llvm/Target/TargetData.h" #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/MathExtras.h" #include using namespace llvm; -/// getOpcode - If this is an Instruction or a ConstantExpr, return the -/// opcode value. Otherwise return UserOp1. -static unsigned getOpcode(const Value *V) { - if (const Instruction *I = dyn_cast(V)) - return I->getOpcode(); - if (const ConstantExpr *CE = dyn_cast(V)) - return CE->getOpcode(); - // Use UserOp1 to mean there's no opcode. - return Instruction::UserOp1; -} - - /// ComputeMaskedBits - Determine which of the bits specified in Mask are /// known to be either zero or one and return them in the KnownZero/KnownOne /// bit sets. This code only analyzes bits in Mask, in order to short-circuit @@ -108,11 +97,11 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask, if (Depth == MaxDepth || Mask == 0) return; // Limit search depth. - User *I = dyn_cast(V); + Operator *I = dyn_cast(V); if (!I) return; APInt KnownZero2(KnownZero), KnownOne2(KnownOne); - switch (getOpcode(I)) { + switch (I->getOpcode()) { default: break; case Instruction::And: { // If either the LHS or the RHS are Zero, the result is zero. @@ -383,7 +372,7 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask, // Determine which operand has more trailing zeros, and use that // many bits from the other operand. if (LHSKnownZeroOut > RHSKnownZeroOut) { - if (getOpcode(I) == Instruction::Add) { + if (I->getOpcode() == Instruction::Add) { APInt Mask = APInt::getLowBitsSet(BitWidth, LHSKnownZeroOut); KnownZero |= KnownZero2 & Mask; KnownOne |= KnownOne2 & Mask; @@ -523,10 +512,10 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask, for (unsigned i = 0; i != 2; ++i) { Value *L = P->getIncomingValue(i); Value *R = P->getIncomingValue(!i); - User *LU = dyn_cast(L); + Operator *LU = dyn_cast(L); if (!LU) continue; - unsigned Opcode = getOpcode(LU); + unsigned Opcode = LU->getOpcode(); // Check for operations that have the property that if // both their operands have low zero bits, the result // will have low zero bits. @@ -643,8 +632,8 @@ unsigned llvm::ComputeNumSignBits(Value *V, TargetData *TD, unsigned Depth) { if (Depth == 6) return 1; // Limit search depth. - User *U = dyn_cast(V); - switch (getOpcode(V)) { + Operator *U = dyn_cast(V); + switch (Operator::getOpcode(V)) { default: break; case Instruction::SExt: Tmp = TyBits-cast(U->getOperand(0)->getType())->getBitWidth(); @@ -790,7 +779,7 @@ bool llvm::CannotBeNegativeZero(const Value *V, unsigned Depth) { if (Depth == 6) return 1; // Limit search depth. - const Instruction *I = dyn_cast(V); + const Operator *I = dyn_cast(V); if (I == 0) return false; // (add x, 0.0) is guaranteed to return +0.0, not -0.0. diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 2b7ca6bbaaa6..1c25bec304b0 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -40,6 +40,7 @@ #include "llvm/Pass.h" #include "llvm/DerivedTypes.h" #include "llvm/GlobalVariable.h" +#include "llvm/Operator.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/Target/TargetData.h" @@ -650,17 +651,6 @@ static User *dyn_castGetElementPtr(Value *V) { return false; } -/// getOpcode - If this is an Instruction or a ConstantExpr, return the -/// opcode value. Otherwise return UserOp1. -static unsigned getOpcode(const Value *V) { - if (const Instruction *I = dyn_cast(V)) - return I->getOpcode(); - if (const ConstantExpr *CE = dyn_cast(V)) - return CE->getOpcode(); - // Use UserOp1 to mean there's no opcode. - return Instruction::UserOp1; -} - /// AddOne - Add one to a ConstantInt static Constant *AddOne(Constant *C, LLVMContext *Context) { return Context->getConstantExprAdd(C, @@ -8710,7 +8700,7 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) { // See if the value being truncated is already sign extended. If so, just // eliminate the trunc/sext pair. - if (getOpcode(Src) == Instruction::Trunc) { + if (Operator::getOpcode(Src) == Instruction::Trunc) { Value *Op = cast(Src)->getOperand(0); unsigned OpBits = Op->getType()->getScalarSizeInBits(); unsigned MidBits = Src->getType()->getScalarSizeInBits(); @@ -9625,7 +9615,7 @@ static unsigned EnforceKnownAlignment(Value *V, User *U = dyn_cast(V); if (!U) return Align; - switch (getOpcode(U)) { + switch (Operator::getOpcode(U)) { default: break; case Instruction::BitCast: return EnforceKnownAlignment(U->getOperand(0), Align, PrefAlign);