#include "llvm/Instruction.h"
#include "llvm/OperandTraits.h"
+#include "llvm/Operator.h"
#include "llvm/DerivedTypes.h"
namespace llvm {
virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
public:
- virtual Instruction *clone(LLVMContext &Context) const = 0;
+ virtual TerminatorInst *clone(LLVMContext &Context) const = 0;
/// getNumSuccessors - Return the number of successors that this terminator
/// has.
class UnaryInstruction : public Instruction {
void *operator new(size_t, unsigned); // Do not implement
- UnaryInstruction(const UnaryInstruction&); // Do not implement
protected:
UnaryInstruction(const Type *Ty, unsigned iType, Value *V,
#include "llvm/Instruction.def"
+ /// CreateNSWAdd - Create an Add operator with the NSW flag set.
+ ///
+ static BinaryOperator *CreateNSWAdd(Value *V1, Value *V2,
+ const Twine &Name = "") {
+ BinaryOperator *BO = CreateAdd(V1, V2, Name);
+ cast<AddOperator>(BO)->setHasNoSignedWrap(true);
+ return BO;
+ }
+ static BinaryOperator *CreateNSWAdd(Value *V1, Value *V2,
+ const Twine &Name, BasicBlock *BB) {
+ BinaryOperator *BO = CreateAdd(V1, V2, Name, BB);
+ cast<AddOperator>(BO)->setHasNoSignedWrap(true);
+ return BO;
+ }
+ static BinaryOperator *CreateNSWAdd(Value *V1, Value *V2,
+ const Twine &Name, Instruction *I) {
+ BinaryOperator *BO = CreateAdd(V1, V2, Name, I);
+ cast<AddOperator>(BO)->setHasNoSignedWrap(true);
+ return BO;
+ }
+
+ /// CreateExactSDiv - Create an SDiv operator with the exact flag set.
+ ///
+ static BinaryOperator *CreateExactSDiv(Value *V1, Value *V2,
+ const Twine &Name = "") {
+ BinaryOperator *BO = CreateSDiv(V1, V2, Name);
+ cast<SDivOperator>(BO)->setIsExact(true);
+ return BO;
+ }
+ static BinaryOperator *CreateExactSDiv(Value *V1, Value *V2,
+ const Twine &Name, BasicBlock *BB) {
+ BinaryOperator *BO = CreateSDiv(V1, V2, Name, BB);
+ cast<SDivOperator>(BO)->setIsExact(true);
+ return BO;
+ }
+ static BinaryOperator *CreateExactSDiv(Value *V1, Value *V2,
+ const Twine &Name, Instruction *I) {
+ BinaryOperator *BO = CreateSDiv(V1, V2, Name, I);
+ cast<SDivOperator>(BO)->setIsExact(true);
+ return BO;
+ }
+
/// Helper functions to construct and inspect unary operations (NEG and NOT)
/// via binary operators SUB and XOR:
///
/// CreateNeg, CreateNot - Create the NEG and NOT
/// instructions out of SUB and XOR instructions.
///
- static BinaryOperator *CreateNeg(LLVMContext &Context,
- Value *Op, const Twine &Name = "",
+ static BinaryOperator *CreateNeg(Value *Op, const Twine &Name = "",
Instruction *InsertBefore = 0);
- static BinaryOperator *CreateNeg(LLVMContext &Context,
- Value *Op, const Twine &Name,
+ static BinaryOperator *CreateNeg(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd);
- static BinaryOperator *CreateFNeg(LLVMContext &Context,
- Value *Op, const Twine &Name = "",
+ static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name = "",
Instruction *InsertBefore = 0);
- static BinaryOperator *CreateFNeg(LLVMContext &Context,
- Value *Op, const Twine &Name,
+ static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd);
- static BinaryOperator *CreateNot(LLVMContext &Context,
- Value *Op, const Twine &Name = "",
+ static BinaryOperator *CreateNot(Value *Op, const Twine &Name = "",
Instruction *InsertBefore = 0);
- static BinaryOperator *CreateNot(LLVMContext &Context,
- Value *Op, const Twine &Name,
+ static BinaryOperator *CreateNot(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd);
/// isNeg, isFNeg, isNot - Check if the given Value is a
/// 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,
/// @brief Create a result type for fcmp/icmp
static const Type* makeCmpResultType(const Type* opnd_type) {
if (const VectorType* vt = dyn_cast<const VectorType>(opnd_type)) {
- return VectorType::get(Type::Int1Ty, vt->getNumElements());
+ return VectorType::get(Type::getInt1Ty(opnd_type->getContext()),
+ vt->getNumElements());
}
- return Type::Int1Ty;
+ return Type::getInt1Ty(opnd_type->getContext());
}
};