return getSelectTy(V1->getType(), C, V1, V2);
}
+ /// getSizeOf constant expr - computes the size of a type in a
+ /// target independent way
+ ///
+ static Constant *getSizeOf(const Type *Ty);
/// ConstantExpr::get - Return a binary or shift operator constant expression,
/// folding if possible.
return ConstantExpr::getCast(C, Ty);
}
+Constant *ConstantExpr::getSizeOf(const Type *Ty) {
+ // sizeof is implemented as: (unsigned) gep (Ty)null, 1
+ return getCast(
+ getGetElementPtr(
+ getNullValue(Ty),
+ std::vector<Constant*>(1, ConstantInt::get(Type::UByteTy, 1))),
+ Type::UIntTy);
+}
+
Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
Constant *C1, Constant *C2) {
if (Opcode == Instruction::Shl || Opcode == Instruction::Shr)