double V;
uint64_t I;
} T2;
- T2.V = Val;
+ T2.V = V;
return T1.I == T2.I;
}
}
};
+//===---------------------------------------------------------------------------
+/// ConstantAggregateZero - All zero aggregate value
+///
+class ConstantAggregateZero : public Constant {
+ friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
+ ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
+protected:
+ ConstantAggregateZero(const Type *Ty) : Constant(Ty) {}
+public:
+ /// get() - static factory method for creating a null aggregate. It is
+ /// illegal to call this method with a non-aggregate type.
+ static Constant *get(const Type *Ty);
+
+ /// isNullValue - Return true if this is the value that would be returned by
+ /// getNullValue.
+ virtual bool isNullValue() const { return true; }
+
+ virtual void destroyConstant();
+ virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
+ bool DisableChecking = false);
+
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
+ ///
+ static inline bool classof(const ConstantAggregateZero *) { return true; }
+ static bool classof(const Constant *CPV);
+ static inline bool classof(const Value *V) {
+ return isa<Constant>(V) && classof(cast<Constant>(V));
+ }
+};
+
//===---------------------------------------------------------------------------
/// ConstantArray - Constant Array Declarations
ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
public:
/// get() - Static factory methods - Return objects of the specified value
- static ConstantArray *get(const ArrayType *T, const std::vector<Constant*> &);
- static ConstantArray *get(const std::string &Initializer);
+ static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
+ static Constant *get(const std::string &Initializer);
/// getType - Specialize the getType() method to always return an ArrayType,
/// which reduces the amount of casting needed in parts of the compiler.
inline const std::vector<Use> &getValues() const { return Operands; }
/// isNullValue - Return true if this is the value that would be returned by
- /// getNullValue.
- virtual bool isNullValue() const {
- // FIXME: This should be made to be MUCH faster. Just check against well
- // known null value!
- if (getNumOperands()) {
- const Constant *First = cast<Constant>(getOperand(0));
- if (!First->isNullValue()) return false;
- for (unsigned i = 1, e = getNumOperands(); i != e; ++i)
- if (cast<Constant>(getOperand(i)) != First)
- return false;
- }
- return true;
- }
+ /// getNullValue. This always returns false because zero arrays are always
+ /// created as ConstantAggregateZero objects.
+ virtual bool isNullValue() const { return false; }
virtual void destroyConstant();
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To,
ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
public:
/// get() - Static factory methods - Return objects of the specified value
- static ConstantStruct *get(const StructType *T,
- const std::vector<Constant*> &V);
+ static Constant *get(const StructType *T, const std::vector<Constant*> &V);
/// getType() specialization - Reduce amount of casting...
inline const StructType *getType() const {
inline const std::vector<Use> &getValues() const { return Operands; }
/// isNullValue - Return true if this is the value that would be returned by
- /// getNullValue.
+ /// getNullValue. This always returns false because zero structs are always
+ /// created as ConstantAggregateZero objects.
virtual bool isNullValue() const {
- // FIXME: This should be made to be MUCH faster. Just check against well
- // known null value!
- for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
- if (!cast<Constant>(getOperand(i))->isNullValue())
- return false;
- return true;
+ return false;
}
virtual void destroyConstant();
ConstantExpr(unsigned Opcode, Constant *C, const Type *Ty);
// Binary/Shift instruction creation ctor
ConstantExpr(unsigned Opcode, Constant *C1, Constant *C2);
+ // Select instruction creation ctor
+ ConstantExpr(Constant *C, Constant *V1, Constant *V2);
// GEP instruction creation ctor
ConstantExpr(Constant *C, const std::vector<Constant*> &IdxList,
const Type *DestTy);
Constant *C1, Constant *C2);
static Constant *getShiftTy(const Type *Ty,
unsigned Opcode, Constant *C1, Constant *C2);
+ static Constant *getSelectTy(const Type *Ty,
+ Constant *C1, Constant *C2, Constant *C3);
static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
const std::vector<Constant*> &IdxList);
/// Cast constant expr
///
static Constant *getCast(Constant *C, const Type *Ty);
+ static Constant *getSignExtend(Constant *C, const Type *Ty);
+ static Constant *getZeroExtend(Constant *C, const Type *Ty);
+
+ /// Select constant expr
+ ///
+ static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
+ return getSelectTy(V1->getType(), C, V1, V2);
+ }
+
/// ConstantExpr::get - Return a binary or shift operator constant expression,
/// folding if possible.
return getTy(C1->getType(), Opcode, C1, C2);
}
+ /// ConstantExpr::get* - Return some common constants without having to
+ /// specify the full Instruction::OPCODE identifier.
+ ///
+ static Constant *getNeg(Constant *C);
+ static Constant *getNot(Constant *C);
+ static Constant *getAdd(Constant *C1, Constant *C2);
+ static Constant *getSub(Constant *C1, Constant *C2);
+ static Constant *getMul(Constant *C1, Constant *C2);
+ static Constant *getDiv(Constant *C1, Constant *C2);
+ static Constant *getRem(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 *getSetEQ(Constant *C1, Constant *C2);
+ static Constant *getSetNE(Constant *C1, Constant *C2);
+ static Constant *getSetLT(Constant *C1, Constant *C2);
+ static Constant *getSetGT(Constant *C1, Constant *C2);
+ static Constant *getSetLE(Constant *C1, Constant *C2);
+ static Constant *getSetGE(Constant *C1, Constant *C2);
+ static Constant *getShl(Constant *C1, Constant *C2);
+ static Constant *getShr(Constant *C1, Constant *C2);
+
/// Getelementptr form...
///
static Constant *getGetElementPtr(Constant *C,