diff options
105 files changed, 6683 insertions, 3646 deletions
diff --git a/include/llvm/Analysis/ScalarEvolutionExpander.h b/include/llvm/Analysis/ScalarEvolutionExpander.h index 391c12b2ba..163d35761c 100644 --- a/include/llvm/Analysis/ScalarEvolutionExpander.h +++ b/include/llvm/Analysis/ScalarEvolutionExpander.h @@ -27,7 +27,7 @@ namespace llvm { /// rewrite expressions in canonical form. /// /// Clients should create an instance of this class when rewriting is needed, - /// and destroying it when finished to allow the release of the associated + /// and destroy it when finished to allow the release of the associated /// memory. struct SCEVExpander : public SCEVVisitor<SCEVExpander, Value*> { ScalarEvolution &SE; @@ -115,12 +115,12 @@ namespace llvm { Value *visitTruncateExpr(SCEVTruncateExpr *S) { Value *V = expand(S->getOperand()); - return new CastInst(V, S->getType(), "tmp.", InsertPt); + return CastInst::createInferredCast(V, S->getType(), "tmp.", InsertPt); } Value *visitZeroExtendExpr(SCEVZeroExtendExpr *S) { Value *V = expandInTy(S->getOperand(),S->getType()->getUnsignedVersion()); - return new CastInst(V, S->getType(), "tmp.", InsertPt); + return CastInst::createInferredCast(V, S->getType(), "tmp.", InsertPt); } Value *visitAddExpr(SCEVAddExpr *S) { diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index 20f36438b1..f78ace36f8 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -516,9 +516,33 @@ public: /// Cast constant expr /// + static Constant *getTrunc (Constant *C, const Type *Ty); + static Constant *getSignExtend (Constant *C, const Type *Ty); + static Constant *getZeroExtend (Constant *C, const Type *Ty); + static Constant *getFPTrunc (Constant *C, const Type *Ty); + static Constant *getFPExtend (Constant *C, const Type *Ty); + static Constant *getUIToFP (Constant *C, const Type *Ty); + static Constant *getSIToFP (Constant *C, const Type *Ty); + static Constant *getFPToUI (Constant *C, const Type *Ty); + static Constant *getFPToSI (Constant *C, const Type *Ty); + static Constant *getPtrToInt (Constant *C, const Type *Ty); + static Constant *getIntToPtr (Constant *C, const Type *Ty); + static Constant *getBitCast (Constant *C, const Type *Ty); + + // @brief Convenience function for getting one of the casting operations + // using a CastOps opcode. + static Constant *getCast( + unsigned ops, ///< The opcode for the conversion + Constant *C, ///< The constant to be converted + const Type *Ty ///< The type to which the constant is converted + ); + + // @brief Get a ConstantExpr Conversion operator that casts C to Ty static Constant *getCast(Constant *C, const Type *Ty); - static Constant *getSignExtend(Constant *C, const Type *Ty); - static Constant *getZeroExtend(Constant *C, const Type *Ty); + + /// @brief Return true if this is a convert constant expression + bool isCast() const; + /// Select constant expr /// diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index 627aad4304..0a489f3d08 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -244,6 +244,161 @@ public: }; //===----------------------------------------------------------------------===// +// CastInst Class +//===----------------------------------------------------------------------===// + +/// CastInst - This is the base class for all instructions that perform data +/// casts. It is simply provided so that instruction category testing +/// can be performed with code like: +/// +/// if (isa<CastInst>(Instr)) { ... } +/// @brief Base class of casting instructions. +class CastInst : public UnaryInstruction { + /// @brief Copy constructor + CastInst(const CastInst &CI) + : UnaryInstruction(CI.getType(), CI.getOpcode(), CI.getOperand(0)) { + } + /// @brief Do not allow default construction + CastInst(); +protected: + /// @brief Constructor with insert-before-instruction semantics for subclasses + CastInst(const Type *Ty, unsigned iType, Value *S, + const std::string &Name = "", Instruction *InsertBefore = 0) + : UnaryInstruction(Ty, iType, S, Name, InsertBefore) { + } + /// @brief Constructor with insert-at-end-of-block semantics for subclasses + CastInst(const Type *Ty, unsigned iType, Value *S, + const std::string &Name, BasicBlock *InsertAtEnd) + : UnaryInstruction(Ty, iType, S, Name, InsertAtEnd) { + } +public: + /// Provides a wa |