Stop using getValues().

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15487 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alkis Evlogimenos
2004-08-04 08:44:43 +00:00
parent 868bbf35b0
commit 15876bb28c
7 changed files with 35 additions and 45 deletions

View File

@@ -338,7 +338,7 @@ void BytecodeWriter::outputConstant(const Constant *CPV) {
const ConstantArray *CPA = cast<ConstantArray>(CPV); const ConstantArray *CPA = cast<ConstantArray>(CPV);
assert(!CPA->isString() && "Constant strings should be handled specially!"); assert(!CPA->isString() && "Constant strings should be handled specially!");
for (unsigned i = 0; i != CPA->getNumOperands(); ++i) { for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i) {
int Slot = Table.getSlot(CPA->getOperand(i)); int Slot = Table.getSlot(CPA->getOperand(i));
assert(Slot != -1 && "Constant used but not available!!"); assert(Slot != -1 && "Constant used but not available!!");
output_vbr((unsigned)Slot); output_vbr((unsigned)Slot);
@@ -348,10 +348,9 @@ void BytecodeWriter::outputConstant(const Constant *CPV) {
case Type::StructTyID: { case Type::StructTyID: {
const ConstantStruct *CPS = cast<ConstantStruct>(CPV); const ConstantStruct *CPS = cast<ConstantStruct>(CPV);
const std::vector<Use> &Vals = CPS->getValues();
for (unsigned i = 0; i < Vals.size(); ++i) { for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i) {
int Slot = Table.getSlot(Vals[i]); int Slot = Table.getSlot(CPS->getOperand(i));
assert(Slot != -1 && "Constant used but not available!!"); assert(Slot != -1 && "Constant used but not available!!");
output_vbr((unsigned)Slot); output_vbr((unsigned)Slot);
} }

View File

@@ -446,11 +446,10 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
switch (Init->getType()->getTypeID()) { switch (Init->getType()->getTypeID()) {
case Type::ArrayTyID: { case Type::ArrayTyID: {
const ConstantArray *CPA = cast<ConstantArray>(Init); const ConstantArray *CPA = cast<ConstantArray>(Init);
const std::vector<Use> &Val = CPA->getValues();
unsigned ElementSize = unsigned ElementSize =
getTargetData().getTypeSize(cast<ArrayType>(CPA->getType())->getElementType()); getTargetData().getTypeSize(cast<ArrayType>(CPA->getType())->getElementType());
for (unsigned i = 0; i < Val.size(); ++i) for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
InitializeMemory(cast<Constant>(Val[i].get()), (char*)Addr+i*ElementSize); InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
return; return;
} }
@@ -458,10 +457,8 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
const ConstantStruct *CPS = cast<ConstantStruct>(Init); const ConstantStruct *CPS = cast<ConstantStruct>(Init);
const StructLayout *SL = const StructLayout *SL =
getTargetData().getStructLayout(cast<StructType>(CPS->getType())); getTargetData().getStructLayout(cast<StructType>(CPS->getType()));
const std::vector<Use> &Val = CPS->getValues(); for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
for (unsigned i = 0; i < Val.size(); ++i) InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->MemberOffsets[i]);
InitializeMemory(cast<Constant>(Val[i].get()),
(char*)Addr+SL->MemberOffsets[i]);
return; return;
} }

View File

@@ -365,23 +365,21 @@ void AsmPrinter::printConstantValueOnly(const Constant* CV,
toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n"; toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n";
} else { } else {
// Not a string. Print the values in successive locations // Not a string. Print the values in successive locations
const std::vector<Use> &constValues = CVA->getValues(); for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
for (unsigned i=0; i < constValues.size(); i++) printConstantValueOnly(CVA->getOperand(i));
printConstantValueOnly(cast<Constant>(constValues[i].get()));
} }
} else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) { } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
// Print the fields in successive locations. Pad to align if needed! // Print the fields in successive locations. Pad to align if needed!
const StructLayout *cvsLayout = const StructLayout *cvsLayout =
Target.getTargetData().getStructLayout(CVS->getType()); Target.getTargetData().getStructLayout(CVS->getType());
const std::vector<Use>& constValues = CVS->getValues();
unsigned sizeSoFar = 0; unsigned sizeSoFar = 0;
for (unsigned i=0, N = constValues.size(); i < N; i++) { for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
const Constant* field = cast<Constant>(constValues[i].get()); const Constant* field = CVS->getOperand(i);
// Check if padding is needed and insert one or more 0s. // Check if padding is needed and insert one or more 0s.
unsigned fieldSize = unsigned fieldSize =
Target.getTargetData().getTypeSize(field->getType()); Target.getTargetData().getTypeSize(field->getType());
int padSize = ((i == N-1? cvsLayout->StructSize int padSize = ((i == e-1? cvsLayout->StructSize
: cvsLayout->MemberOffsets[i+1]) : cvsLayout->MemberOffsets[i+1])
- cvsLayout->MemberOffsets[i]) - fieldSize; - cvsLayout->MemberOffsets[i]) - fieldSize;
sizeSoFar += (fieldSize + padSize); sizeSoFar += (fieldSize + padSize);

View File

@@ -270,22 +270,20 @@ void X86AsmPrinter::emitGlobalConstant(const Constant *CV) {
printAsCString(O, CVA); printAsCString(O, CVA);
O << "\n"; O << "\n";
} else { // Not a string. Print the values in successive locations } else { // Not a string. Print the values in successive locations
const std::vector<Use> &constValues = CVA->getValues(); for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
for (unsigned i=0; i < constValues.size(); i++) emitGlobalConstant(CVA->getOperand(i));
emitGlobalConstant(cast<Constant>(constValues[i].get()));
} }
return; return;
} else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) { } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
// Print the fields in successive locations. Pad to align if needed! // Print the fields in successive locations. Pad to align if needed!
const StructLayout *cvsLayout = TD.getStructLayout(CVS->getType()); const StructLayout *cvsLayout = TD.getStructLayout(CVS->getType());
const std::vector<Use>& constValues = CVS->getValues();
unsigned sizeSoFar = 0; unsigned sizeSoFar = 0;
for (unsigned i=0, N = constValues.size(); i < N; i++) { for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
const Constant* field = cast<Constant>(constValues[i].get()); const Constant* field = CVS->getOperand(i);
// Check if padding is needed and insert one or more 0s. // Check if padding is needed and insert one or more 0s.
unsigned fieldSize = TD.getTypeSize(field->getType()); unsigned fieldSize = TD.getTypeSize(field->getType());
unsigned padSize = ((i == N-1? cvsLayout->StructSize unsigned padSize = ((i == e-1? cvsLayout->StructSize
: cvsLayout->MemberOffsets[i+1]) : cvsLayout->MemberOffsets[i+1])
- cvsLayout->MemberOffsets[i]) - fieldSize; - cvsLayout->MemberOffsets[i]) - fieldSize;
sizeSoFar += fieldSize + padSize; sizeSoFar += fieldSize + padSize;

View File

@@ -2947,7 +2947,7 @@ static Constant *GetGEPGlobalInitializer(Constant *C, ConstantExpr *CE) {
assert(CU->getValue() < STy->getNumElements() && assert(CU->getValue() < STy->getNumElements() &&
"Struct index out of range!"); "Struct index out of range!");
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) { if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
C = cast<Constant>(CS->getValues()[CU->getValue()]); C = CS->getOperand(CU->getValue());
} else if (isa<ConstantAggregateZero>(C)) { } else if (isa<ConstantAggregateZero>(C)) {
C = Constant::getNullValue(STy->getElementType(CU->getValue())); C = Constant::getNullValue(STy->getElementType(CU->getValue()));
} else { } else {
@@ -2957,7 +2957,7 @@ static Constant *GetGEPGlobalInitializer(Constant *C, ConstantExpr *CE) {
const ArrayType *ATy = cast<ArrayType>(*I); const ArrayType *ATy = cast<ArrayType>(*I);
if ((uint64_t)CI->getRawValue() >= ATy->getNumElements()) return 0; if ((uint64_t)CI->getRawValue() >= ATy->getNumElements()) return 0;
if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) if (ConstantArray *CA = dyn_cast<ConstantArray>(C))
C = cast<Constant>(CA->getValues()[CI->getRawValue()]); C = CA->getOperand(CI->getRawValue());
else if (isa<ConstantAggregateZero>(C)) else if (isa<ConstantAggregateZero>(C))
C = Constant::getNullValue(ATy->getElementType()); C = Constant::getNullValue(ATy->getElementType());
else else

View File

@@ -753,13 +753,13 @@ static Constant *GetGEPGlobalInitializer(Constant *C, ConstantExpr *CE) {
if (ConstantUInt *CU = dyn_cast<ConstantUInt>(CE->getOperand(i))) { if (ConstantUInt *CU = dyn_cast<ConstantUInt>(CE->getOperand(i))) {
ConstantStruct *CS = dyn_cast<ConstantStruct>(C); ConstantStruct *CS = dyn_cast<ConstantStruct>(C);
if (CS == 0) return 0; if (CS == 0) return 0;
if (CU->getValue() >= CS->getValues().size()) return 0; if (CU->getValue() >= CS->getNumOperands()) return 0;
C = cast<Constant>(CS->getValues()[CU->getValue()]); C = CS->getOperand(CU->getValue());
} else if (ConstantSInt *CS = dyn_cast<ConstantSInt>(CE->getOperand(i))) { } else if (ConstantSInt *CS = dyn_cast<ConstantSInt>(CE->getOperand(i))) {
ConstantArray *CA = dyn_cast<ConstantArray>(C); ConstantArray *CA = dyn_cast<ConstantArray>(C);
if (CA == 0) return 0; if (CA == 0) return 0;
if ((uint64_t)CS->getValue() >= CA->getValues().size()) return 0; if ((uint64_t)CS->getValue() >= CA->getNumOperands()) return 0;
C = cast<Constant>(CA->getValues()[CS->getValue()]); C = CA->getOperand(CS->getValue());
} else } else
return 0; return 0;
return C; return C;

View File

@@ -34,40 +34,38 @@ Value *llvm::MapValue(const Value *V, std::map<const Value*, Value*> &VM) {
isa<ConstantPointerNull>(C) || isa<ConstantAggregateZero>(C)) isa<ConstantPointerNull>(C) || isa<ConstantAggregateZero>(C))
return VMSlot = C; // Primitive constants map directly return VMSlot = C; // Primitive constants map directly
else if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) { else if (ConstantArray *CA = dyn_cast<ConstantArray>(C)) {
const std::vector<Use> &Vals = CA->getValues(); for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i) {
for (unsigned i = 0, e = Vals.size(); i != e; ++i) { Value *MV = MapValue(CA->getOperand(i), VM);
Value *MV = MapValue(Vals[i], VM); if (MV != CA->getOperand(i)) {
if (MV != Vals[i]) {
// This array must contain a reference to a global, make a new array // This array must contain a reference to a global, make a new array
// and return it. // and return it.
// //
std::vector<Constant*> Values; std::vector<Constant*> Values;
Values.reserve(Vals.size()); Values.reserve(CA->getNumOperands());
for (unsigned j = 0; j != i; ++j) for (unsigned j = 0; j != i; ++j)
Values.push_back(cast<Constant>(Vals[j])); Values.push_back(CA->getOperand(j));
Values.push_back(cast<Constant>(MV)); Values.push_back(cast<Constant>(MV));
for (++i; i != e; ++i) for (++i; i != e; ++i)
Values.push_back(cast<Constant>(MapValue(Vals[i], VM))); Values.push_back(cast<Constant>(MapValue(CA->getOperand(i), VM)));
return VMSlot = ConstantArray::get(CA->getType(), Values); return VMSlot = ConstantArray::get(CA->getType(), Values);
} }
} }
return VMSlot = C; return VMSlot = C;
} else if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) { } else if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
const std::vector<Use> &Vals = CS->getValues(); for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i) {
for (unsigned i = 0, e = Vals.size(); i != e; ++i) { Value *MV = MapValue(CS->getOperand(i), VM);
Value *MV = MapValue(Vals[i], VM); if (MV != CS->getOperand(i)) {
if (MV != Vals[i]) {
// This struct must contain a reference to a global, make a new struct // This struct must contain a reference to a global, make a new struct
// and return it. // and return it.
// //
std::vector<Constant*> Values; std::vector<Constant*> Values;
Values.reserve(Vals.size()); Values.reserve(CS->getNumOperands());
for (unsigned j = 0; j != i; ++j) for (unsigned j = 0; j != i; ++j)
Values.push_back(cast<Constant>(Vals[j])); Values.push_back(CS->getOperand(j));
Values.push_back(cast<Constant>(MV)); Values.push_back(cast<Constant>(MV));
for (++i; i != e; ++i) for (++i; i != e; ++i)
Values.push_back(cast<Constant>(MapValue(Vals[i], VM))); Values.push_back(cast<Constant>(MapValue(CS->getOperand(i), VM)));
return VMSlot = ConstantStruct::get(CS->getType(), Values); return VMSlot = ConstantStruct::get(CS->getType(), Values);
} }
} }