return *GlobalContext;
}
-LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl()) { }
+LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { }
LLVMContext::~LLVMContext() { delete pImpl; }
// Constant accessors
Constant* LLVMContext::getNullValue(const Type* Ty) {
switch (Ty->getTypeID()) {
case Type::IntegerTyID:
- return getConstantInt(Ty, 0);
+ return ConstantInt::get(Ty, 0);
case Type::FloatTyID:
return getConstantFP(APFloat(APInt(32, 0)));
case Type::DoubleTyID:
Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
- return getConstantInt(APInt::getAllOnesValue(ITy->getBitWidth()));
+ return ConstantInt::get(*this, APInt::getAllOnesValue(ITy->getBitWidth()));
std::vector<Constant*> Elts;
const VectorType* VTy = cast<VectorType>(Ty);
}
// ConstantInt accessors.
-ConstantInt* LLVMContext::getConstantIntTrue() {
- return ConstantInt::getTrue();
+ConstantInt* LLVMContext::getTrue() {
+ assert(this && "Context not initialized!");
+ assert(pImpl && "Context not initialized!");
+ return pImpl->getTrue();
}
-ConstantInt* LLVMContext::getConstantIntFalse() {
- return ConstantInt::getFalse();
-}
-
-Constant* LLVMContext::getConstantInt(const Type* Ty, uint64_t V,
- bool isSigned) {
- Constant *C = getConstantInt(cast<IntegerType>(Ty->getScalarType()),
- V, isSigned);
-
- // For vectors, broadcast the value.
- if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
- return
- getConstantVector(std::vector<Constant *>(VTy->getNumElements(), C));
-
- return C;
-}
-
-
-ConstantInt* LLVMContext::getConstantInt(const IntegerType* Ty, uint64_t V,
- bool isSigned) {
- return getConstantInt(APInt(Ty->getBitWidth(), V, isSigned));
-}
-
-ConstantInt* LLVMContext::getConstantIntSigned(const IntegerType* Ty,
- int64_t V) {
- return getConstantInt(Ty, V, true);
-}
-
-Constant *LLVMContext::getConstantIntSigned(const Type *Ty, int64_t V) {
- return getConstantInt(Ty, V, true);
-}
-
-ConstantInt* LLVMContext::getConstantInt(const APInt& V) {
- return ConstantInt::get(V);
-}
-
-Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
- ConstantInt *C = getConstantInt(V);
- assert(C->getType() == Ty->getScalarType() &&
- "ConstantInt type doesn't match the type implied by its value!");
-
- // For vectors, broadcast the value.
- if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
- return
- ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C));
-
- return C;
+ConstantInt* LLVMContext::getFalse() {
+ assert(this && "Context not initialized!");
+ assert(pImpl && "Context not initialized!");
+ return pImpl->getFalse();
}
// ConstantPointerNull accessors.
// ConstantStruct accessors.
Constant* LLVMContext::getConstantStruct(const StructType* T,
const std::vector<Constant*>& V) {
- return ConstantStruct::get(T, V);
+ return pImpl->getConstantStruct(T, V);
}
Constant* LLVMContext::getConstantStruct(const std::vector<Constant*>& V,
- bool Packed) {
- return ConstantStruct::get(V, Packed);
+ bool packed) {
+ std::vector<const Type*> StructEls;
+ StructEls.reserve(V.size());
+ for (unsigned i = 0, e = V.size(); i != e; ++i)
+ StructEls.push_back(V[i]->getType());
+ return getConstantStruct(getStructType(StructEls, packed), V);
}
Constant* LLVMContext::getConstantStruct(Constant* const *Vals,
unsigned NumVals, bool Packed) {
- return ConstantStruct::get(Vals, NumVals, Packed);
+ // FIXME: make this the primary ctor method.
+ return getConstantStruct(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
}
// ConstantAggregateZero accessors.
ConstantAggregateZero* LLVMContext::getConstantAggregateZero(const Type* Ty) {
- return ConstantAggregateZero::get(Ty);
+ return pImpl->getConstantAggregateZero(Ty);
}
// ConstantArray accessors.
Constant* LLVMContext::getConstantArray(const ArrayType* T,
const std::vector<Constant*>& V) {
- return ConstantArray::get(T, V);
+ return pImpl->getConstantArray(T, V);
}
Constant* LLVMContext::getConstantArray(const ArrayType* T,
Constant* const* Vals,
unsigned NumVals) {
- return ConstantArray::get(T, Vals, NumVals);
+ // FIXME: make this the primary ctor method.
+ return getConstantArray(T, std::vector<Constant*>(Vals, Vals+NumVals));
}
/// ConstantArray::get(const string&) - Return an array that is initialized to
bool AddNull) {
std::vector<Constant*> ElementVals;
for (unsigned i = 0; i < Str.length(); ++i)
- ElementVals.push_back(getConstantInt(Type::Int8Ty, Str[i]));
+ ElementVals.push_back(ConstantInt::get(Type::Int8Ty, Str[i]));
// Add a null terminator to the string...
if (AddNull) {
- ElementVals.push_back(getConstantInt(Type::Int8Ty, 0));
+ ElementVals.push_back(ConstantInt::get(Type::Int8Ty, 0));
}
ArrayType *ATy = getArrayType(Type::Int8Ty, ElementVals.size());
// alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1
const Type *AligningTy = getStructType(Type::Int8Ty, Ty, NULL);
Constant *NullPtr = getNullValue(AligningTy->getPointerTo());
- Constant *Zero = getConstantInt(Type::Int32Ty, 0);
- Constant *One = getConstantInt(Type::Int32Ty, 1);
+ Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
+ Constant *One = ConstantInt::get(Type::Int32Ty, 1);
Constant *Indices[2] = { Zero, One };
Constant *GEP = getConstantExprGetElementPtr(NullPtr, Indices, 2);
return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int32Ty);
Constant* LLVMContext::getConstantExprSizeOf(const Type* Ty) {
// sizeof is implemented as: (i64) gep (Ty*)null, 1
- Constant *GEPIdx = getConstantInt(Type::Int32Ty, 1);
+ Constant *GEPIdx = ConstantInt::get(Type::Int32Ty, 1);
Constant *GEP = getConstantExprGetElementPtr(
getNullValue(getPointerTypeUnqual(Ty)), &GEPIdx, 1);
return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int64Ty);
// ConstantFP accessors.
ConstantFP* LLVMContext::getConstantFP(const APFloat& V) {
- return ConstantFP::get(V);
+ return pImpl->getConstantFP(V);
}
static const fltSemantics *TypeToFloatSemantics(const Type *Ty) {
// ConstantVector accessors.
Constant* LLVMContext::getConstantVector(const VectorType* T,
const std::vector<Constant*>& V) {
- return ConstantVector::get(T, V);
+ return pImpl->getConstantVector(T, V);
}
Constant* LLVMContext::getConstantVector(const std::vector<Constant*>& V) {
- return ConstantVector::get(V);
+ assert(!V.empty() && "Cannot infer type if V is empty");
+ return getConstantVector(getVectorType(V.front()->getType(),V.size()), V);
}
Constant* LLVMContext::getConstantVector(Constant* const* Vals,
unsigned NumVals) {
- return ConstantVector::get(Vals, NumVals);
+ // FIXME: make this the primary ctor method.
+ return getConstantVector(std::vector<Constant*>(Vals, Vals+NumVals));
}
// MDNode accessors
MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
- return MDNode::get(Vals, NumVals);
+ return pImpl->getMDNode(Vals, NumVals);
}
// MDString accessors
-MDString* LLVMContext::getMDString(const char *StrBegin, const char *StrEnd) {
- return MDString::get(StrBegin, StrEnd);
+MDString* LLVMContext::getMDString(const char *StrBegin, unsigned StrLength) {
+ return pImpl->getMDString(StrBegin, StrLength);
}
MDString* LLVMContext::getMDString(const std::string &Str) {
- return MDString::get(Str);
+ return getMDString(Str.data(), Str.size());
}
// FunctionType accessors
}
return Type::Int1Ty;
}
+
+void LLVMContext::erase(MDString *M) {
+ pImpl->erase(M);
+}
+
+void LLVMContext::erase(MDNode *M) {
+ pImpl->erase(M);
+}
+
+void LLVMContext::erase(ConstantAggregateZero *Z) {
+ pImpl->erase(Z);
+}
+
+void LLVMContext::erase(ConstantArray *C) {
+ pImpl->erase(C);
+}
+
+void LLVMContext::erase(ConstantStruct *S) {
+ pImpl->erase(S);
+}
+
+void LLVMContext::erase(ConstantVector *V) {
+ pImpl->erase(V);
+}
+
+Constant *LLVMContext::replaceUsesOfWithOnConstant(ConstantArray *CA,
+ Value *From, Value *To, Use *U) {
+ return pImpl->replaceUsesOfWithOnConstant(CA, From, To, U);
+}
+
+Constant *LLVMContext::replaceUsesOfWithOnConstant(ConstantStruct *CS,
+ Value *From, Value *To, Use *U) {
+ return pImpl->replaceUsesOfWithOnConstant(CS, From, To, U);
+}