Refactor a bunch of code out of AsmPrinter::EmitGlobalConstant into separate

functions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61345 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2008-12-22 21:14:27 +00:00
parent 8044e9b3af
commit 00d448a341
2 changed files with 215 additions and 182 deletions

View File

@@ -25,6 +25,9 @@ namespace llvm {
class GCStrategy;
class Constant;
class ConstantArray;
class ConstantInt;
class ConstantStruct;
class ConstantVector;
class GCMetadataPrinter;
class GlobalVariable;
class GlobalAlias;
@@ -369,6 +372,11 @@ namespace llvm {
const GlobalValue *findGlobalValue(const Constant* CV);
void EmitLLVMUsedList(Constant *List);
void EmitXXStructorList(Constant *List);
void EmitGlobalConstantStruct(const ConstantStruct* CVS);
void EmitGlobalConstantArray(const ConstantArray* CVA);
void EmitGlobalConstantVector(const ConstantVector* CP);
void EmitGlobalConstantFP(const ConstantFP* CFP);
void EmitGlobalConstantLargeInt(const ConstantInt* CI);
GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C);
};
}

View File

@@ -939,24 +939,26 @@ void AsmPrinter::EmitString(const ConstantArray *CVA) const {
O << '\n';
}
/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
const TargetData *TD = TM.getTargetData();
unsigned Size = TD->getABITypeSize(CV->getType());
if (CV->isNullValue() || isa<UndefValue>(CV)) {
EmitZeros(Size);
return;
} else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
void AsmPrinter::EmitGlobalConstantArray(const ConstantArray *CVA) {
if (CVA->isString()) {
EmitString(CVA);
} else { // Not a string. Print the values in successive locations
for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
EmitGlobalConstant(CVA->getOperand(i));
}
return;
} else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
}
void AsmPrinter::EmitGlobalConstantVector(const ConstantVector *CP) {
const VectorType *PTy = CP->getType();
for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
EmitGlobalConstant(CP->getOperand(I));
}
void AsmPrinter::EmitGlobalConstantStruct(const ConstantStruct *CVS) {
// Print the fields in successive locations. Pad to align if needed!
const TargetData *TD = TM.getTargetData();
unsigned Size = TD->getABITypeSize(CVS->getType());
const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
uint64_t sizeSoFar = 0;
for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
@@ -978,10 +980,12 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
}
assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
"Layout of constant struct may be incorrect!");
return;
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
}
void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP) {
// FP Constants are printed as integer constants to avoid losing
// precision...
const TargetData *TD = TM.getTargetData();
if (CFP->getType() == Type::DoubleTy) {
double Val = CFP->getValueAPF().convertToDouble(); // for comment only
uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
@@ -1055,7 +1059,8 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
<< '\t' << TAI->getCommentString()
<< " long double most significant halfword\n";
}
EmitZeros(Size - TD->getTypeStoreSize(Type::X86_FP80Ty));
EmitZeros(TD->getABITypeSize(Type::X86_FP80Ty) -
TD->getTypeStoreSize(Type::X86_FP80Ty));
return;
} else if (CFP->getType() == Type::PPC_FP128Ty) {
// all long double variants are printed as hex
@@ -1091,9 +1096,10 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
}
return;
} else assert(0 && "Floating point constant type not handled");
} else if (CV->getType()->isInteger() &&
cast<IntegerType>(CV->getType())->getBitWidth() >= 64) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
}
void AsmPrinter::EmitGlobalConstantLargeInt(const ConstantInt *CI) {
const TargetData *TD = TM.getTargetData();
unsigned BitWidth = CI->getBitWidth();
assert(isPowerOf2_32(BitWidth) &&
"Non-power-of-2-sized integers not handled!");
@@ -1127,18 +1133,37 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
<< " Double-word most significant word " << Val << '\n';
}
}
}
/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
const TargetData *TD = TM.getTargetData();
const Type *type = CV->getType();
unsigned Size = TD->getABITypeSize(type);
if (CV->isNullValue() || isa<UndefValue>(CV)) {
EmitZeros(Size);
return;
} else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
EmitGlobalConstantArray(CVA);
return;
} else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
EmitGlobalConstantStruct(CVS);
return;
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
EmitGlobalConstantFP(CFP);
return;
} else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
// Small integers are handled below; large integers are handled here.
if (Size > 4) {
EmitGlobalConstantLargeInt(CI);
return;
}
} else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
const VectorType *PTy = CP->getType();
for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
EmitGlobalConstant(CP->getOperand(I));
EmitGlobalConstantVector(CP);
return;
}
const Type *type = CV->getType();
printDataDirective(type);
EmitConstantValueOnly(CV);
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {