mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-03 14:21:30 +00:00
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:
@@ -25,6 +25,9 @@ namespace llvm {
|
|||||||
class GCStrategy;
|
class GCStrategy;
|
||||||
class Constant;
|
class Constant;
|
||||||
class ConstantArray;
|
class ConstantArray;
|
||||||
|
class ConstantInt;
|
||||||
|
class ConstantStruct;
|
||||||
|
class ConstantVector;
|
||||||
class GCMetadataPrinter;
|
class GCMetadataPrinter;
|
||||||
class GlobalVariable;
|
class GlobalVariable;
|
||||||
class GlobalAlias;
|
class GlobalAlias;
|
||||||
@@ -369,6 +372,11 @@ namespace llvm {
|
|||||||
const GlobalValue *findGlobalValue(const Constant* CV);
|
const GlobalValue *findGlobalValue(const Constant* CV);
|
||||||
void EmitLLVMUsedList(Constant *List);
|
void EmitLLVMUsedList(Constant *List);
|
||||||
void EmitXXStructorList(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);
|
GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -939,24 +939,26 @@ void AsmPrinter::EmitString(const ConstantArray *CVA) const {
|
|||||||
O << '\n';
|
O << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
|
void AsmPrinter::EmitGlobalConstantArray(const ConstantArray *CVA) {
|
||||||
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)) {
|
|
||||||
if (CVA->isString()) {
|
if (CVA->isString()) {
|
||||||
EmitString(CVA);
|
EmitString(CVA);
|
||||||
} else { // Not a string. Print the values in successive locations
|
} else { // Not a string. Print the values in successive locations
|
||||||
for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
|
for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
|
||||||
EmitGlobalConstant(CVA->getOperand(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!
|
// 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());
|
const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
|
||||||
uint64_t sizeSoFar = 0;
|
uint64_t sizeSoFar = 0;
|
||||||
for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
|
||||||
@@ -978,10 +980,12 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
|
|||||||
}
|
}
|
||||||
assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
|
assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
|
||||||
"Layout of constant struct may be incorrect!");
|
"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
|
// FP Constants are printed as integer constants to avoid losing
|
||||||
// precision...
|
// precision...
|
||||||
|
const TargetData *TD = TM.getTargetData();
|
||||||
if (CFP->getType() == Type::DoubleTy) {
|
if (CFP->getType() == Type::DoubleTy) {
|
||||||
double Val = CFP->getValueAPF().convertToDouble(); // for comment only
|
double Val = CFP->getValueAPF().convertToDouble(); // for comment only
|
||||||
uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
|
uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
|
||||||
@@ -1055,7 +1059,8 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
|
|||||||
<< '\t' << TAI->getCommentString()
|
<< '\t' << TAI->getCommentString()
|
||||||
<< " long double most significant halfword\n";
|
<< " 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;
|
return;
|
||||||
} else if (CFP->getType() == Type::PPC_FP128Ty) {
|
} else if (CFP->getType() == Type::PPC_FP128Ty) {
|
||||||
// all long double variants are printed as hex
|
// all long double variants are printed as hex
|
||||||
@@ -1091,9 +1096,10 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else assert(0 && "Floating point constant type not handled");
|
} 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();
|
unsigned BitWidth = CI->getBitWidth();
|
||||||
assert(isPowerOf2_32(BitWidth) &&
|
assert(isPowerOf2_32(BitWidth) &&
|
||||||
"Non-power-of-2-sized integers not handled!");
|
"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';
|
<< " 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;
|
return;
|
||||||
}
|
}
|
||||||
} else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
|
} else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
|
||||||
const VectorType *PTy = CP->getType();
|
EmitGlobalConstantVector(CP);
|
||||||
|
|
||||||
for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
|
|
||||||
EmitGlobalConstant(CP->getOperand(I));
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Type *type = CV->getType();
|
|
||||||
printDataDirective(type);
|
printDataDirective(type);
|
||||||
EmitConstantValueOnly(CV);
|
EmitConstantValueOnly(CV);
|
||||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user