1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

Move ConstantStruct back to 2.5 API.

llvm-svn: 77266
This commit is contained in:
Owen Anderson 2009-07-27 22:29:26 +00:00
parent 1e723730cb
commit d729f993b8
16 changed files with 129 additions and 179 deletions

View File

@ -385,10 +385,15 @@ class ConstantStruct : public Constant {
friend struct ConstantCreator<ConstantStruct, StructType,
std::vector<Constant*> >;
ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
friend class LLVMContextImpl;
protected:
ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
public:
// ConstantStruct accessors
static Constant* get(const StructType* T, const std::vector<Constant*>& V);
static Constant* get(const std::vector<Constant*>& V, bool Packed = false);
static Constant* get(Constant* const *Vals, unsigned NumVals,
bool Packed = false);
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);

View File

@ -57,6 +57,7 @@ class LLVMContext {
friend class ConstantInt;
friend class ConstantFP;
friend class ConstantStruct;
public:
LLVMContext();
~LLVMContext();
@ -78,14 +79,6 @@ public:
// ConstantPointerNull accessors
ConstantPointerNull* getConstantPointerNull(const PointerType* T);
// ConstantStruct accessors
Constant* getConstantStruct(const StructType* T,
const std::vector<Constant*>& V);
Constant* getConstantStruct(const std::vector<Constant*>& V,
bool Packed = false);
Constant* getConstantStruct(Constant* const *Vals, unsigned NumVals,
bool Packed = false);
// ConstantAggregateZero accessors
ConstantAggregateZero* getConstantAggregateZero(const Type* Ty);
@ -233,14 +226,11 @@ public:
void erase(MDNode *M);
void erase(ConstantAggregateZero *Z);
void erase(ConstantArray *Z);
void erase(ConstantStruct *S);
void erase(ConstantVector *V);
// RAUW helpers
Constant *replaceUsesOfWithOnConstant(ConstantArray *CA,
Value *From, Value *To, Use *U);
Constant *replaceUsesOfWithOnConstant(ConstantStruct *CS, Value *From,
Value *To, Use *U);
};
/// FOR BACKWARDS COMPATIBILITY - Returns a global context.

View File

@ -545,8 +545,7 @@ DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
ConstantInt::get(Type::Int64Ty, Hi)
};
Constant *Init = VMContext.getConstantStruct(Elts,
sizeof(Elts)/sizeof(Elts[0]));
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
// If we already have this range, just return the uniqued version.
DIDescriptor &Entry = SimpleConstantCache[Init];
@ -587,8 +586,7 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
ConstantInt::get(Type::Int32Ty, RunTimeVer)
};
Constant *Init = VMContext.getConstantStruct(Elts,
sizeof(Elts)/sizeof(Elts[0]));
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@ -606,8 +604,7 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
ConstantInt::get(Type::Int64Ty, Val)
};
Constant *Init = VMContext.getConstantStruct(Elts,
sizeof(Elts)/sizeof(Elts[0]));
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.enumerator.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@ -640,8 +637,7 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
ConstantInt::get(Type::Int32Ty, Encoding)
};
Constant *Init = VMContext.getConstantStruct(Elts,
sizeof(Elts)/sizeof(Elts[0]));
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.basictype.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@ -676,8 +672,7 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
getCastToEmpty(DerivedFrom)
};
Constant *Init = VMContext.getConstantStruct(Elts,
sizeof(Elts)/sizeof(Elts[0]));
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.derivedtype.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@ -716,8 +711,7 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
ConstantInt::get(Type::Int32Ty, RuntimeLang)
};
Constant *Init = VMContext.getConstantStruct(Elts,
sizeof(Elts)/sizeof(Elts[0]));
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.composite.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@ -754,8 +748,7 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
ConstantInt::get(Type::Int1Ty, isDefinition)
};
Constant *Init = VMContext.getConstantStruct(Elts,
sizeof(Elts)/sizeof(Elts[0]));
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@ -788,8 +781,7 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
VMContext.getConstantExprBitCast(Val, EmptyStructPtr)
};
Constant *Init = VMContext.getConstantStruct(Elts,
sizeof(Elts)/sizeof(Elts[0]));
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@ -814,8 +806,7 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
getCastToEmpty(Type)
};
Constant *Init = VMContext.getConstantStruct(Elts,
sizeof(Elts)/sizeof(Elts[0]));
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.variable.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
@ -834,8 +825,7 @@ DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
getCastToEmpty(Context)
};
Constant *Init = VMContext.getConstantStruct(Elts,
sizeof(Elts)/sizeof(Elts[0]));
Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
M.addTypeName("llvm.dbg.block.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,

View File

@ -1737,7 +1737,7 @@ bool LLParser::ParseValID(ValID &ID) {
ParseToken(lltok::rbrace, "expected end of struct constant"))
return true;
ID.ConstantVal = Context.getConstantStruct(Elts.data(), Elts.size(), false);
ID.ConstantVal = ConstantStruct::get(Elts.data(), Elts.size(), false);
ID.Kind = ValID::t_Constant;
return false;
}
@ -1757,7 +1757,7 @@ bool LLParser::ParseValID(ValID &ID) {
if (isPackedStruct) {
ID.ConstantVal =
Context.getConstantStruct(Elts.data(), Elts.size(), true);
ConstantStruct::get(Elts.data(), Elts.size(), true);
ID.Kind = ValID::t_Constant;
return false;
}

View File

@ -291,7 +291,7 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() {
NewC = Context.getConstantArray(UserCA->getType(), &NewOps[0],
NewOps.size());
} else if (ConstantStruct *UserCS = dyn_cast<ConstantStruct>(UserC)) {
NewC = Context.getConstantStruct(&NewOps[0], NewOps.size(),
NewC = ConstantStruct::get(&NewOps[0], NewOps.size(),
UserCS->getType()->isPacked());
} else if (isa<ConstantVector>(UserC)) {
NewC = Context.getConstantVector(&NewOps[0], NewOps.size());
@ -925,7 +925,7 @@ bool BitcodeReader::ParseConstants() {
for (unsigned i = 0; i != Size; ++i)
Elts.push_back(ValueList.getConstantFwdRef(Record[i],
STy->getElementType(i)));
V = Context.getConstantStruct(STy, Elts);
V = ConstantStruct::get(STy, Elts);
} else if (const ArrayType *ATy = dyn_cast<ArrayType>(CurTy)) {
const Type *EltTy = ATy->getElementType();
for (unsigned i = 0; i != Size; ++i)

View File

@ -208,12 +208,12 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
};
Constant *DescriptorElts[] = {
Context.getConstantStruct(BaseElts, 2),
ConstantStruct::get(BaseElts, 2),
Context.getConstantArray(Context.getArrayType(VoidPtr, NumMeta),
Metadata.begin(), NumMeta)
};
Constant *FrameMap = Context.getConstantStruct(DescriptorElts, 2);
Constant *FrameMap = ConstantStruct::get(DescriptorElts, 2);
std::string TypeName("gc_map.");
TypeName += utostr(NumMeta);

View File

@ -376,7 +376,7 @@ static Value *RemapOperand(const Value *In,
Operands[i] =cast<Constant>(RemapOperand(CPS->getOperand(i), ValueMap,
Context));
Result =
Context.getConstantStruct(cast<StructType>(CPS->getType()), Operands);
ConstantStruct::get(cast<StructType>(CPS->getType()), Operands);
} else if (isa<ConstantPointerNull>(CPV) || isa<UndefValue>(CPV)) {
Result = const_cast<Constant*>(CPV);
} else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CPV)) {

View File

@ -1962,7 +1962,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
CSVals[1] = Context.getNullValue(PFTy);
CSVals[0] = ConstantInt::get(Type::Int32Ty, 2147483647);
}
CAList.push_back(Context.getConstantStruct(CSVals));
CAList.push_back(ConstantStruct::get(CSVals));
}
// Create the array initializer.
@ -2070,7 +2070,7 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
Elts[Idx] = EvaluateStoreInto(Elts[Idx], Val, Addr, OpNo+1, Context);
// Return the modified struct.
return Context.getConstantStruct(&Elts[0], Elts.size(), STy->isPacked());
return ConstantStruct::get(&Elts[0], Elts.size(), STy->isPacked());
} else {
ConstantInt *CI = cast<ConstantInt>(Addr->getOperand(OpNo));
const ArrayType *ATy = cast<ArrayType>(Init->getType());

View File

@ -76,7 +76,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext &Context) {
Values.push_back(cast<Constant>(MV));
for (++i; i != e; ++i)
Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
return VM[V] = Context.getConstantStruct(CS->getType(), Values);
return VM[V] = ConstantStruct::get(CS->getType(), Values);
}
}
return VM[V] = C;

View File

@ -519,7 +519,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
Ops[i] = const_cast<Constant*>(Op);
}
if (isa<StructType>(AggTy))
return Context.getConstantStruct(Ops);
return ConstantStruct::get(Ops);
else
return Context.getConstantArray(cast<ArrayType>(AggTy), Ops);
}
@ -548,7 +548,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
Ops[i] = const_cast<Constant*>(Op);
}
if (isa<StructType>(AggTy))
return Context.getConstantStruct(Ops);
return ConstantStruct::get(Ops);
else
return Context.getConstantArray(cast<ArrayType>(AggTy), Ops);
}
@ -565,7 +565,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
}
Constant *C;
if (isa<StructType>(Agg->getType()))
C = Context.getConstantStruct(Ops);
C = ConstantStruct::get(Ops);
else
C = Context.getConstantArray(cast<ArrayType>(Agg->getType()), Ops);
return C;

View File

@ -397,6 +397,33 @@ ConstantStruct::ConstantStruct(const StructType *T,
}
}
// ConstantStruct accessors.
Constant* ConstantStruct::get(const StructType* T,
const std::vector<Constant*>& V) {
LLVMContextImpl* pImpl = T->getContext().pImpl;
// Create a ConstantAggregateZero value if all elements are zeros...
for (unsigned i = 0, e = V.size(); i != e; ++i)
if (!V[i]->isNullValue())
// Implicitly locked.
return pImpl->StructConstants.getOrCreate(T, V);
return T->getContext().getConstantAggregateZero(T);
}
Constant* ConstantStruct::get(const std::vector<Constant*>& V, 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 get(StructType::get(StructEls, packed), V);
}
Constant* ConstantStruct::get(Constant* const *Vals, unsigned NumVals,
bool Packed) {
// FIXME: make this the primary ctor method.
return get(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
}
ConstantVector::ConstantVector(const VectorType *T,
const std::vector<Constant*> &V)
@ -981,7 +1008,7 @@ namespace llvm {
//
void ConstantStruct::destroyConstant() {
// Implicitly locked.
getType()->getContext().erase(this);
getType()->getContext().pImpl->StructConstants.remove(this);
destroyConstantImpl();
}
@ -1897,11 +1924,74 @@ void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
destroyConstant();
}
static std::vector<Constant*> getValType(ConstantStruct *CS) {
std::vector<Constant*> Elements;
Elements.reserve(CS->getNumOperands());
for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i)
Elements.push_back(cast<Constant>(CS->getOperand(i)));
return Elements;
}
void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
Use *U) {
Constant* Replacement =
getType()->getContext().replaceUsesOfWithOnConstant(this, From, To, U);
if (!Replacement) return;
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
Constant *ToC = cast<Constant>(To);
unsigned OperandToUpdate = U-OperandList;
assert(getOperand(OperandToUpdate) == From && "ReplaceAllUsesWith broken!");
std::pair<LLVMContextImpl::StructConstantsTy::MapKey, Constant*> Lookup;
Lookup.first.first = getType();
Lookup.second = this;
std::vector<Constant*> &Values = Lookup.first.second;
Values.reserve(getNumOperands()); // Build replacement struct.
// Fill values with the modified operands of the constant struct. Also,
// compute whether this turns into an all-zeros struct.
bool isAllZeros = false;
if (!ToC->isNullValue()) {
for (Use *O = OperandList, *E = OperandList + getNumOperands(); O != E; ++O)
Values.push_back(cast<Constant>(O->get()));
} else {
isAllZeros = true;
for (Use *O = OperandList, *E = OperandList+getNumOperands(); O != E; ++O) {
Constant *Val = cast<Constant>(O->get());
Values.push_back(Val);
if (isAllZeros) isAllZeros = Val->isNullValue();
}
}
Values[OperandToUpdate] = ToC;
LLVMContext &Context = getType()->getContext();
LLVMContextImpl *pImpl = Context.pImpl;
Constant *Replacement = 0;
if (isAllZeros) {
Replacement = Context.getConstantAggregateZero(getType());
} else {
// Check to see if we have this array type already.
sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
bool Exists;
LLVMContextImpl::StructConstantsTy::MapTy::iterator I =
pImpl->StructConstants.InsertOrGetItem(Lookup, Exists);
if (Exists) {
Replacement = I->second;
} else {
// Okay, the new shape doesn't exist in the system yet. Instead of
// creating a new constant struct, inserting it, replaceallusesof'ing the
// old with the new, then deleting the old... just update the current one
// in place!
pImpl->StructConstants.MoveConstantToNewSlot(this, I);
// Update to the new value.
setOperand(OperandToUpdate, ToC);
return;
}
}
assert(Replacement != this && "I didn't contain From!");
// Everyone using this now uses the replacement.
uncheckedReplaceAllUsesWith(Replacement);

View File

@ -416,8 +416,7 @@ LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
int Packed) {
return wrap(getGlobalContext().getConstantStruct(
unwrap<Constant>(ConstantVals, Count),
return wrap(ConstantStruct::get(unwrap<Constant>(ConstantVals, Count),
Count, Packed != 0));
}

View File

@ -98,29 +98,6 @@ ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) {
return ConstantPointerNull::get(T);
}
// ConstantStruct accessors.
Constant* LLVMContext::getConstantStruct(const StructType* T,
const std::vector<Constant*>& V) {
return pImpl->getConstantStruct(T, V);
}
Constant* LLVMContext::getConstantStruct(const std::vector<Constant*>& V,
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) {
// 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 pImpl->getConstantAggregateZero(Ty);
@ -552,10 +529,6 @@ void LLVMContext::erase(ConstantArray *C) {
pImpl->erase(C);
}
void LLVMContext::erase(ConstantStruct *S) {
pImpl->erase(S);
}
void LLVMContext::erase(ConstantVector *V) {
pImpl->erase(V);
}
@ -564,8 +537,3 @@ 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);
}

View File

@ -29,14 +29,6 @@ static std::vector<Constant*> getValType(ConstantArray *CA) {
return Elements;
}
static std::vector<Constant*> getValType(ConstantStruct *CS) {
std::vector<Constant*> Elements;
Elements.reserve(CS->getNumOperands());
for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i)
Elements.push_back(cast<Constant>(CS->getOperand(i)));
return Elements;
}
static std::vector<Constant*> getValType(ConstantVector *CP) {
std::vector<Constant*> Elements;
Elements.reserve(CP->getNumOperands());
@ -112,17 +104,6 @@ Constant *LLVMContextImpl::getConstantArray(const ArrayType *Ty,
return Context.getConstantAggregateZero(Ty);
}
Constant *LLVMContextImpl::getConstantStruct(const StructType *Ty,
const std::vector<Constant*> &V) {
// Create a ConstantAggregateZero value if all elements are zeros...
for (unsigned i = 0, e = V.size(); i != e; ++i)
if (!V[i]->isNullValue())
// Implicitly locked.
return StructConstants.getOrCreate(Ty, V);
return Context.getConstantAggregateZero(Ty);
}
Constant *LLVMContextImpl::getConstantVector(const VectorType *Ty,
const std::vector<Constant*> &V) {
assert(!V.empty() && "Vectors can't be empty");
@ -169,10 +150,6 @@ void LLVMContextImpl::erase(ConstantArray *C) {
ArrayConstants.remove(C);
}
void LLVMContextImpl::erase(ConstantStruct *S) {
StructConstants.remove(S);
}
void LLVMContextImpl::erase(ConstantVector *V) {
VectorConstants.remove(V);
}
@ -255,68 +232,4 @@ Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantArray *CA,
}
return Replacement;
}
Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantStruct *CS,
Value *From, Value *To, Use *U) {
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
Constant *ToC = cast<Constant>(To);
unsigned OperandToUpdate = U - CS->OperandList;
assert(CS->getOperand(OperandToUpdate) == From &&
"ReplaceAllUsesWith broken!");
std::pair<StructConstantsTy::MapKey, Constant*> Lookup;
Lookup.first.first = CS->getType();
Lookup.second = CS;
std::vector<Constant*> &Values = Lookup.first.second;
Values.reserve(CS->getNumOperands()); // Build replacement struct.
// Fill values with the modified operands of the constant struct. Also,
// compute whether this turns into an all-zeros struct.
bool isAllZeros = false;
if (!ToC->isNullValue()) {
for (Use *O = CS->OperandList, *E = CS->OperandList + CS->getNumOperands();
O != E; ++O)
Values.push_back(cast<Constant>(O->get()));
} else {
isAllZeros = true;
for (Use *O = CS->OperandList, *E = CS->OperandList + CS->getNumOperands();
O != E; ++O) {
Constant *Val = cast<Constant>(O->get());
Values.push_back(Val);
if (isAllZeros) isAllZeros = Val->isNullValue();
}
}
Values[OperandToUpdate] = ToC;
Constant *Replacement = 0;
if (isAllZeros) {
Replacement = Context.getConstantAggregateZero(CS->getType());
} else {
// Check to see if we have this array type already.
sys::SmartScopedWriter<true> Writer(ConstantsLock);
bool Exists;
StructConstantsTy::MapTy::iterator I =
StructConstants.InsertOrGetItem(Lookup, Exists);
if (Exists) {
Replacement = I->second;
} else {
// Okay, the new shape doesn't exist in the system yet. Instead of
// creating a new constant struct, inserting it, replaceallusesof'ing the
// old with the new, then deleting the old... just update the current one
// in place!
StructConstants.MoveConstantToNewSlot(CS, I);
// Update to the new value.
CS->setOperand(OperandToUpdate, ToC);
return 0;
}
}
assert(Replacement != CS && "I didn't contain From!");
return Replacement;
}
}

View File

@ -102,7 +102,7 @@ struct ConvertConstantType<ConstantStruct, StructType> {
std::vector<Constant*> C;
for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
C.push_back(cast<Constant>(OldC->getOperand(i)));
Constant *New = NewTy->getContext().getConstantStruct(NewTy, C);
Constant *New = ConstantStruct::get(NewTy, C);
assert(New != OldC && "Didn't replace constant??");
OldC->uncheckedReplaceAllUsesWith(New);
@ -458,6 +458,7 @@ class LLVMContextImpl {
friend class ConstantInt;
friend class ConstantFP;
friend class ConstantStruct;
public:
LLVMContextImpl(LLVMContext &C);
@ -470,9 +471,6 @@ public:
Constant *getConstantArray(const ArrayType *Ty,
const std::vector<Constant*> &V);
Constant *getConstantStruct(const StructType *Ty,
const std::vector<Constant*> &V);
Constant *getConstantVector(const VectorType *Ty,
const std::vector<Constant*> &V);
@ -494,15 +492,12 @@ public:
void erase(MDNode *M);
void erase(ConstantAggregateZero *Z);
void erase(ConstantArray *C);
void erase(ConstantStruct *S);
void erase(ConstantVector *V);
// RAUW helpers
Constant *replaceUsesOfWithOnConstant(ConstantArray *CA, Value *From,
Value *To, Use *U);
Constant *replaceUsesOfWithOnConstant(ConstantStruct *CS, Value *From,
Value *To, Use *U);
};
}

View File

@ -187,7 +187,7 @@ static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) {
std::vector<Constant*> Elts;
Elts.push_back(ConstantInt::get(Type::Int32Ty, TorList[i].second));
Elts.push_back(TorList[i].first);
ArrayElts.push_back(Context.getConstantStruct(Elts));
ArrayElts.push_back(ConstantStruct::get(Elts));
}
return Context.getConstantArray(Context.getArrayType(ArrayElts[0]->getType(),
ArrayElts.size()),