//===----------------------------------------------------------------------===//
/// This is the shared class of boolean and integer constants. This class
/// represents both boolean and integral constants.
/// @brief Class for constant integers.
class ConstantInt : public Constant {
//===----------------------------------------------------------------------===//
/// This is the shared class of boolean and integer constants. This class
/// represents both boolean and integral constants.
/// @brief Class for constant integers.
class ConstantInt : public Constant {
/// get() - This returns a ConstantFP, or a vector containing a splat of a
/// ConstantFP, for the specified value in the specified type. This should
/// only be used for simple constant values like 2.0/1.0 etc, that are
/// known-valid both as host double and as the target format.
/// get() - This returns a ConstantFP, or a vector containing a splat of a
/// ConstantFP, for the specified value in the specified type. This should
/// only be used for simple constant values like 2.0/1.0 etc, that are
/// known-valid both as host double and as the target format.
- static Constant* get(const Type* Ty, double V);
- static ConstantFP* get(LLVMContext &Context, const APFloat& V);
- static ConstantFP* getNegativeZero(const Type* Ty);
+ static Constant *get(const Type* Ty, double V);
+ static Constant *get(const Type* Ty, StringRef Str);
+ static ConstantFP *get(LLVMContext &Context, const APFloat &V);
+ static ConstantFP *getNegativeZero(const Type* Ty);
+ static ConstantFP *getInfinity(const Type *Ty, bool Negative = false);
/// isExactlyValue - We don't rely on operator== working on double values, as
/// it returns true for things that are clearly not equal, like -0.0 and 0.0.
/// As such, this method can be used to do an exact bit-for-bit comparison of
/// two floating point values. The version with a double operand is retained
/// because it's so convenient to write isExactlyValue(2.0), but please use
/// it only for simple constants.
/// isExactlyValue - We don't rely on operator== working on double values, as
/// it returns true for things that are clearly not equal, like -0.0 and 0.0.
/// As such, this method can be used to do an exact bit-for-bit comparison of
/// two floating point values. The version with a double operand is retained
/// because it's so convenient to write isExactlyValue(2.0), but please use
/// it only for simple constants.
- static Constant* get(const StructType* T, const std::vector<Constant*>& V);
- static Constant* get(LLVMContext &Context,
- const std::vector<Constant*>& V, bool Packed = false);
- static Constant* get(LLVMContext &Context,
- Constant* const *Vals, unsigned NumVals,
- bool Packed = false);
-
+ static Constant *get(const StructType *T, const std::vector<Constant*> &V);
+ static Constant *get(LLVMContext &Context,
+ const std::vector<Constant*> &V, bool Packed);
+ static Constant *get(LLVMContext &Context,
+ Constant *const *Vals, unsigned NumVals, bool Packed);
+
+/// BlockAddress - The address of a basic block.
+///
+class BlockAddress : public Constant {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
+ void *operator new(size_t s) { return User::operator new(s, 2); }
+ BlockAddress(Function *F, BasicBlock *BB);
+public:
+ /// get - Return a BlockAddress for the specified function and basic block.
+ static BlockAddress *get(Function *F, BasicBlock *BB);
+
+ /// get - Return a BlockAddress for the specified basic block. The basic
+ /// block must be embedded into a function.
+ static BlockAddress *get(BasicBlock *BB);
+
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
+ Function *getFunction() const { return (Function*)Op<0>().get(); }
+ BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); }
+
+ /// isNullValue - Return true if this is the value that would be returned by
+ /// getNullValue.
+ virtual bool isNullValue() const { return false; }
+
+ virtual void destroyConstant();
+ virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
+
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool classof(const BlockAddress *) { return true; }
+ static inline bool classof(const Value *V) {
+ return V->getValueID() == BlockAddressVal;
+ }
+};
+
+template <>
+struct OperandTraits<BlockAddress> : public FixedNumOperandTraits<2> {
+};
class ConstantExpr : public Constant {
friend struct ConstantCreator<ConstantExpr,Type,
std::pair<unsigned, std::vector<Constant*> > >;
class ConstantExpr : public Constant {
friend struct ConstantCreator<ConstantExpr,Type,
std::pair<unsigned, std::vector<Constant*> > >;
protected:
ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
: Constant(ty, ConstantExprVal, Ops, NumOps) {
// Operation type (an Instruction opcode) is stored as the SubclassData.
protected:
ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
: Constant(ty, ConstantExprVal, Ops, NumOps) {
// Operation type (an Instruction opcode) is stored as the SubclassData.
static Constant *getCompareTy(unsigned short pred, Constant *C1,
Constant *C2);
static Constant *getSelectTy(const Type *Ty,
Constant *C1, Constant *C2, Constant *C3);
static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
Value* const *Idxs, unsigned NumIdxs);
static Constant *getCompareTy(unsigned short pred, Constant *C1,
Constant *C2);
static Constant *getSelectTy(const Type *Ty,
Constant *C1, Constant *C2, Constant *C3);
static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
Value* const *Idxs, unsigned NumIdxs);
+ static Constant *getAlignOf(const Type* Ty);
+
+ /// getSizeOf constant expr - computes the (alloc) size of a type (in
+ /// address-units, not bits) in a target independent way (Note: the return
+ /// type is an i64).
+ ///
+ static Constant *getSizeOf(const Type* Ty);
+
+ /// getOffsetOf constant expr - computes the offset of a struct field in a
+ /// target independent way (Note: the return type is an i64).
+ ///
+ static Constant *getOffsetOf(const StructType* STy, unsigned FieldNo);
+
+ /// getOffsetOf constant expr - This is a generalized form of getOffsetOf,
+ /// which supports any aggregate type, and any Constant index.
- static Constant* getNeg(Constant* C);
- static Constant* getFNeg(Constant* C);
- static Constant* getNot(Constant* C);
- static Constant* getAdd(Constant* C1, Constant* C2);
- static Constant* getFAdd(Constant* C1, Constant* C2);
- static Constant* getSub(Constant* C1, Constant* C2);
- static Constant* getFSub(Constant* C1, Constant* C2);
- static Constant* getMul(Constant* C1, Constant* C2);
- static Constant* getFMul(Constant* C1, Constant* C2);
- static Constant* getUDiv(Constant* C1, Constant* C2);
- static Constant* getSDiv(Constant* C1, Constant* C2);
- static Constant* getFDiv(Constant* C1, Constant* C2);
- static Constant* getURem(Constant* C1, Constant* C2);
- static Constant* getSRem(Constant* C1, Constant* C2);
- static Constant* getFRem(Constant* C1, Constant* C2);
- static Constant* getAnd(Constant* C1, Constant* C2);
- static Constant* getOr(Constant* C1, Constant* C2);
- static Constant* getXor(Constant* C1, Constant* C2);
- static Constant* getShl(Constant* C1, Constant* C2);
- static Constant* getLShr(Constant* C1, Constant* C2);
- static Constant* getAShr(Constant* C1, Constant* C2);
+ static Constant *getNeg(Constant *C);
+ static Constant *getFNeg(Constant *C);
+ static Constant *getNot(Constant *C);
+ static Constant *getAdd(Constant *C1, Constant *C2);
+ static Constant *getFAdd(Constant *C1, Constant *C2);
+ static Constant *getSub(Constant *C1, Constant *C2);
+ static Constant *getFSub(Constant *C1, Constant *C2);
+ static Constant *getMul(Constant *C1, Constant *C2);
+ static Constant *getFMul(Constant *C1, Constant *C2);
+ static Constant *getUDiv(Constant *C1, Constant *C2);
+ static Constant *getSDiv(Constant *C1, Constant *C2);
+ static Constant *getFDiv(Constant *C1, Constant *C2);
+ static Constant *getURem(Constant *C1, Constant *C2);
+ static Constant *getSRem(Constant *C1, Constant *C2);
+ static Constant *getFRem(Constant *C1, Constant *C2);
+ static Constant *getAnd(Constant *C1, Constant *C2);
+ static Constant *getOr(Constant *C1, Constant *C2);
+ static Constant *getXor(Constant *C1, Constant *C2);
+ static Constant *getShl(Constant *C1, Constant *C2);
+ static Constant *getLShr(Constant *C1, Constant *C2);
+ static Constant *getAShr(Constant *C1, Constant *C2);
static Constant *getTrunc (Constant *C, const Type *Ty);
static Constant *getSExt (Constant *C, const Type *Ty);
static Constant *getZExt (Constant *C, const Type *Ty);
static Constant *getTrunc (Constant *C, const Type *Ty);
static Constant *getSExt (Constant *C, const Type *Ty);
static Constant *getZExt (Constant *C, const Type *Ty);
- static Constant* getExactSDiv(Constant* C1, Constant* C2);
+ static Constant *getNSWNeg(Constant *C);
+ static Constant *getNUWNeg(Constant *C);
+ static Constant *getNSWAdd(Constant *C1, Constant *C2);
+ static Constant *getNUWAdd(Constant *C1, Constant *C2);
+ static Constant *getNSWSub(Constant *C1, Constant *C2);
+ static Constant *getNUWSub(Constant *C1, Constant *C2);
+ static Constant *getNSWMul(Constant *C1, Constant *C2);
+ static Constant *getNUWMul(Constant *C1, Constant *C2);
+ static Constant *getExactSDiv(Constant *C1, Constant *C2);
static Constant *getGetElementPtr(Constant *C,
Value* const *IdxList, unsigned NumIdx);
/// Create an "inbounds" getelementptr. See the documentation for the
/// "inbounds" flag in LangRef.html for details.
static Constant *getInBoundsGetElementPtr(Constant *C,
static Constant *getGetElementPtr(Constant *C,
Value* const *IdxList, unsigned NumIdx);
/// Create an "inbounds" getelementptr. See the documentation for the
/// "inbounds" flag in LangRef.html for details.
static Constant *getInBoundsGetElementPtr(Constant *C,