diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h index c12113ec7a3..4d03d42b499 100644 --- a/include/llvm/CodeGen/AsmPrinter.h +++ b/include/llvm/CodeGen/AsmPrinter.h @@ -370,7 +370,13 @@ namespace llvm { /// MachineBasicBlock, an alignment (if present) and a comment describing /// it if appropriate. void EmitBasicBlockStart(const MachineBasicBlock *MBB) const; - protected: + + + // Data emission. + + /// EmitGlobalConstant - Print a general LLVM constant to the .s file. + void EmitGlobalConstant(const Constant* CV, unsigned AddrSpace = 0); + /// EmitZeros - Emit a block of zeros. /// void EmitZeros(uint64_t NumZeros, unsigned AddrSpace = 0) const; @@ -379,13 +385,11 @@ namespace llvm { /// virtual void EmitString(const ConstantArray *CVA) const; + protected: /// EmitConstantValueOnly - Print out the specified constant, without a /// storage class. Only constants of first-class type are allowed here. void EmitConstantValueOnly(const Constant *CV); - /// EmitGlobalConstant - Print a general LLVM constant to the .s file. - void EmitGlobalConstant(const Constant* CV, unsigned AddrSpace = 0); - virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV); /// processDebugLoc - Processes the debug information of each machine @@ -427,12 +431,8 @@ namespace llvm { private: void EmitLLVMUsedList(Constant *List); void EmitXXStructorList(Constant *List); - void EmitGlobalConstantStruct(const ConstantStruct* CVS, - unsigned AddrSpace); - void EmitGlobalConstantArray(const ConstantArray* CVA, unsigned AddrSpace); - void EmitGlobalConstantVector(const ConstantVector* CP); - void EmitGlobalConstantFP(const ConstantFP* CFP, unsigned AddrSpace); void EmitGlobalConstantLargeInt(const ConstantInt* CI, unsigned AddrSpace); + void EmitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace); GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C); }; } diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 48add10b352..54a93095ed2 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1101,57 +1101,56 @@ void AsmPrinter::EmitString(const ConstantArray *CVA) const { O << '\n'; } -void AsmPrinter::EmitGlobalConstantArray(const ConstantArray *CVA, - unsigned AddrSpace) { - if (CVA->isString()) { - EmitString(CVA); +static void EmitGlobalConstantArray(const ConstantArray *CA, unsigned AddrSpace, + AsmPrinter &AP) { + if (AddrSpace == 0 && CA->isString()) { + AP.EmitString(CA); } else { // Not a string. Print the values in successive locations - for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i) - EmitGlobalConstant(CVA->getOperand(i), AddrSpace); + for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i) + AP.EmitGlobalConstant(CA->getOperand(i), AddrSpace); } } -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)); +static void EmitGlobalConstantVector(const ConstantVector *CV, + unsigned AddrSpace, AsmPrinter &AP) { + const VectorType *VTy = CV->getType(); + for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) + AP.EmitGlobalConstant(CV->getOperand(i), AddrSpace); } -void AsmPrinter::EmitGlobalConstantStruct(const ConstantStruct *CVS, - unsigned AddrSpace) { +static void EmitGlobalConstantStruct(const ConstantStruct *CS, + unsigned AddrSpace, AsmPrinter &AP) { // Print the fields in successive locations. Pad to align if needed! - const TargetData *TD = TM.getTargetData(); - unsigned Size = TD->getTypeAllocSize(CVS->getType()); - const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType()); - uint64_t sizeSoFar = 0; - for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) { - const Constant* field = CVS->getOperand(i); + const TargetData *TD = AP.TM.getTargetData(); + unsigned Size = TD->getTypeAllocSize(CS->getType()); + const StructLayout *cvsLayout = TD->getStructLayout(CS->getType()); + uint64_t SizeSoFar = 0; + for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i) { + const Constant *field = CS->getOperand(i); // Check if padding is needed and insert one or more 0s. uint64_t fieldSize = TD->getTypeAllocSize(field->getType()); uint64_t padSize = ((i == e-1 ? Size : cvsLayout->getElementOffset(i+1)) - cvsLayout->getElementOffset(i)) - fieldSize; - sizeSoFar += fieldSize + padSize; + SizeSoFar += fieldSize + padSize; // Now print the actual field value. - EmitGlobalConstant(field, AddrSpace); + AP.EmitGlobalConstant(field, AddrSpace); // Insert padding - this may include padding to increase the size of the // current field up to the ABI size (if the struct is not packed) as well // as padding to ensure that the next field starts at the right offset. - EmitZeros(padSize, AddrSpace); + AP.EmitZeros(padSize, AddrSpace); } - assert(sizeSoFar == cvsLayout->getSizeInBytes() && + assert(SizeSoFar == cvsLayout->getSizeInBytes() && "Layout of constant struct may be incorrect!"); } -void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, +void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace) { // FP Constants are printed as integer constants to avoid losing // precision... - LLVMContext &Context = CFP->getContext(); - const TargetData *TD = TM.getTargetData(); + const TargetData &TD = *TM.getTargetData(); if (CFP->getType()->isDoubleTy()) { double Val = CFP->getValueAPF().convertToDouble(); // for comment only uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue(); @@ -1162,7 +1161,7 @@ void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, O << MAI->getCommentString() << " double " << Val; } O << '\n'; - } else if (TD->isBigEndian()) { + } else if (TD.isBigEndian()) { O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32); if (VerboseAsm) { O.PadToColumn(MAI->getCommentColumn()); @@ -1218,7 +1217,7 @@ void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, bool ignored; DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &ignored); - if (TD->isBigEndian()) { + if (TD.isBigEndian()) { O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]); if (VerboseAsm) { O.PadToColumn(MAI->getCommentColumn()); @@ -1290,8 +1289,9 @@ void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, } O << '\n'; } - EmitZeros(TD->getTypeAllocSize(Type::getX86_FP80Ty(Context)) - - TD->getTypeStoreSize(Type::getX86_FP80Ty(Context)), AddrSpace); + LLVMContext &Context = CFP->getContext(); + EmitZeros(TD.getTypeAllocSize(Type::getX86_FP80Ty(Context)) - + TD.getTypeStoreSize(Type::getX86_FP80Ty(Context)), AddrSpace); return; } @@ -1300,7 +1300,7 @@ void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, // api needed to prevent premature destruction APInt api = CFP->getValueAPF().bitcastToAPInt(); const uint64_t *p = api.getRawData(); - if (TD->isBigEndian()) { + if (TD.isBigEndian()) { O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32); if (VerboseAsm) { O.PadToColumn(MAI->getCommentColumn()); @@ -1420,20 +1420,14 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) { if (CV->isNullValue() || isa(CV)) return EmitZeros(Size, AddrSpace); - if (const ConstantArray *CVA = dyn_cast(CV)) { - EmitGlobalConstantArray(CVA, AddrSpace); - return; - } + if (const ConstantArray *CVA = dyn_cast(CV)) + return EmitGlobalConstantArray(CVA, AddrSpace, *this); - if (const ConstantStruct *CVS = dyn_cast(CV)) { - EmitGlobalConstantStruct(CVS, AddrSpace); - return; - } + if (const ConstantStruct *CVS = dyn_cast(CV)) + return EmitGlobalConstantStruct(CVS, AddrSpace, *this); - if (const ConstantFP *CFP = dyn_cast(CV)) { - EmitGlobalConstantFP(CFP, AddrSpace); - return; - } + if (const ConstantFP *CFP = dyn_cast(CV)) + return EmitGlobalConstantFP(CFP, AddrSpace); if (const ConstantInt *CI = dyn_cast(CV)) { // If we can directly emit an 8-byte constant, do it. @@ -1450,10 +1444,8 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) { } } - if (const ConstantVector *CP = dyn_cast(CV)) { - EmitGlobalConstantVector(CP); - return; - } + if (const ConstantVector *V = dyn_cast(CV)) + return EmitGlobalConstantVector(V, AddrSpace, *this); printDataDirective(type, AddrSpace); EmitConstantValueOnly(CV);