[llvm-commits] [llvm] r93891 - in /llvm/trunk: include/llvm/CodeGen/AsmPrinter.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Chris Lattner sabre at nondot.org
Tue Jan 19 11:10:44 PST 2010


Author: lattner
Date: Tue Jan 19 13:10:44 2010
New Revision: 93891

URL: http://llvm.org/viewvc/llvm-project?rev=93891&view=rev
Log:
refactor code to be static functions instead of methods on AsmPrinter.
This fixes some bugs handling address spaces.

Modified:
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=93891&r1=93890&r2=93891&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Tue Jan 19 13:10:44 2010
@@ -370,7 +370,13 @@
     /// 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 @@
     ///
     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 @@
   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);
   };
 }

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=93891&r1=93890&r2=93891&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Jan 19 13:10:44 2010
@@ -1101,57 +1101,56 @@
   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 @@
         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 @@
     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 @@
       }
       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 @@
     // 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 @@
   if (CV->isNullValue() || isa<UndefValue>(CV))
     return EmitZeros(Size, AddrSpace);
   
-  if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
-    EmitGlobalConstantArray(CVA, AddrSpace);
-    return;
-  }
+  if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV))
+    return EmitGlobalConstantArray(CVA, AddrSpace, *this);
   
-  if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
-    EmitGlobalConstantStruct(CVS, AddrSpace);
-    return;
-  }
+  if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV))
+    return EmitGlobalConstantStruct(CVS, AddrSpace, *this);
 
-  if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
-    EmitGlobalConstantFP(CFP, AddrSpace);
-    return;
-  }
+  if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV))
+    return EmitGlobalConstantFP(CFP, AddrSpace);
   
   if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
     // If we can directly emit an 8-byte constant, do it.
@@ -1450,10 +1444,8 @@
     }
   }
   
-  if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
-    EmitGlobalConstantVector(CP);
-    return;
-  }
+  if (const ConstantVector *V = dyn_cast<ConstantVector>(CV))
+    return EmitGlobalConstantVector(V, AddrSpace, *this);
 
   printDataDirective(type, AddrSpace);
   EmitConstantValueOnly(CV);





More information about the llvm-commits mailing list