//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
}
// Get a ConstantInt from an APInt. Note that the value stored in the DenseMap
-// as the key, is a DensMapAPIntKeyInfo::KeyTy which has provided the
+// as the key, is a DenseMapAPIntKeyInfo::KeyTy which has provided the
// operator== and operator!= to ensure that the DenseMap doesn't attempt to
// compare APInt's of different widths, which would violate an APInt class
// invariant which generates an assertion.
}
unsigned ConstantExpr::getPredicate() const {
assert(getOpcode() == Instruction::FCmp || getOpcode() == Instruction::ICmp);
- return dynamic_cast<const CompareConstantExpr*>(this)->predicate;
+ return ((const CompareConstantExpr*)this)->predicate;
}
Constant *ConstantExpr::getShl(Constant *C1, Constant *C2) {
return get(Instruction::Shl, C1, C2);
ConstantExpr> > ExprConstants;
/// This is a utility function to handle folding of casts and lookup of the
-/// cast in the ExprConstants map. It is usedby the various get* methods below.
+/// cast in the ExprConstants map. It is used by the various get* methods below.
static inline Constant *getFoldedCast(
Instruction::CastOps opc, Constant *C, const Type *Ty) {
assert(Ty->isFirstClassType() && "Cannot cast to an aggregate type!");
}
Constant *ConstantExpr::getUIToFP(Constant *C, const Type *Ty) {
- assert(C->getType()->isInteger() && Ty->isFloatingPoint() &&
- "This is an illegal i32 to floating point cast!");
+ bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
+ bool toVec = Ty->getTypeID() == Type::VectorTyID;
+ assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
+ assert(C->getType()->isIntOrIntVector() && Ty->isFPOrFPVector() &&
+ "This is an illegal uint to floating point cast!");
return getFoldedCast(Instruction::UIToFP, C, Ty);
}
Constant *ConstantExpr::getSIToFP(Constant *C, const Type *Ty) {
- assert(C->getType()->isInteger() && Ty->isFloatingPoint() &&
+ bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
+ bool toVec = Ty->getTypeID() == Type::VectorTyID;
+ assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
+ assert(C->getType()->isIntOrIntVector() && Ty->isFPOrFPVector() &&
"This is an illegal sint to floating point cast!");
return getFoldedCast(Instruction::SIToFP, C, Ty);
}
Constant *ConstantExpr::getFPToUI(Constant *C, const Type *Ty) {
- assert(C->getType()->isFloatingPoint() && Ty->isInteger() &&
- "This is an illegal floating point to i32 cast!");
+ bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
+ bool toVec = Ty->getTypeID() == Type::VectorTyID;
+ assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
+ assert(C->getType()->isFPOrFPVector() && Ty->isIntOrIntVector() &&
+ "This is an illegal floating point to uint cast!");
return getFoldedCast(Instruction::FPToUI, C, Ty);
}
Constant *ConstantExpr::getFPToSI(Constant *C, const Type *Ty) {
- assert(C->getType()->isFloatingPoint() && Ty->isInteger() &&
- "This is an illegal floating point to i32 cast!");
+ bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
+ bool toVec = Ty->getTypeID() == Type::VectorTyID;
+ assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
+ assert(C->getType()->isFPOrFPVector() && Ty->isIntOrIntVector() &&
+ "This is an illegal floating point to sint cast!");
return getFoldedCast(Instruction::FPToSI, C, Ty);
}
// sizeof is implemented as: (i64) gep (Ty*)null, 1
Constant *GEPIdx = ConstantInt::get(Type::Int32Ty, 1);
Constant *GEP =
- getGetElementPtr(getNullValue(PointerType::get(Ty)), &GEPIdx, 1);
+ getGetElementPtr(getNullValue(PointerType::getUnqual(Ty)), &GEPIdx, 1);
return getCast(Instruction::PtrToInt, GEP, Type::Int64Ty);
}
const Type *Ty =
GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx, true);
assert(Ty && "GEP indices invalid!");
- return getGetElementPtrTy(PointerType::get(Ty), C, Idxs, NumIdx);
+ unsigned As = cast<PointerType>(C->getType())->getAddressSpace();
+ return getGetElementPtrTy(PointerType::get(Ty, As), C, Idxs, NumIdx);
}
Constant *ConstantExpr::getGetElementPtr(Constant *C, Constant* const *Idxs,
}
}
}
- } else if (Constant *C = dyn_cast<Constant>(this)) {
- if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
- return GV->getStringValue(Chop, Offset);
- else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
- if (CE->getOpcode() == Instruction::GetElementPtr) {
- // Turn a gep into the specified offset.
- if (CE->getNumOperands() == 3 &&
- cast<Constant>(CE->getOperand(1))->isNullValue() &&
- isa<ConstantInt>(CE->getOperand(2))) {
- Offset += cast<ConstantInt>(CE->getOperand(2))->getZExtValue();
- return CE->getOperand(0)->getStringValue(Chop, Offset);
- }
+ } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(this)) {
+ if (CE->getOpcode() == Instruction::GetElementPtr) {
+ // Turn a gep into the specified offset.
+ if (CE->getNumOperands() == 3 &&
+ cast<Constant>(CE->getOperand(1))->isNullValue() &&
+ isa<ConstantInt>(CE->getOperand(2))) {
+ Offset += cast<ConstantInt>(CE->getOperand(2))->getZExtValue();
+ return CE->getOperand(0)->getStringValue(Chop, Offset);
}
}
}