[llvm-commits] [llvm] r53585 - in /llvm/trunk/lib/Target/Mips: MipsAsmPrinter.cpp MipsISelLowering.cpp MipsRegisterInfo.cpp MipsTargetAsmInfo.cpp MipsTargetMachine.cpp

Bruno Cardoso Lopes bruno.cardoso at gmail.com
Mon Jul 14 19:03:36 PDT 2008


Author: bruno
Date: Mon Jul 14 21:03:36 2008
New Revision: 53585

URL: http://llvm.org/viewvc/llvm-project?rev=53585&view=rev
Log:
Fixed call stack alignment. Improved AsmPrinter alignment issues.

Modified:
    llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
    llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp
    llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp
    llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp
    llvm/trunk/lib/Target/Mips/MipsTargetMachine.cpp

Modified: llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp?rev=53585&r1=53584&r2=53585&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp Mon Jul 14 21:03:36 2008
@@ -486,9 +486,24 @@
       
       O << "\n\n";
       std::string name = Mang->getValueName(I);
-      Constant *C      = I->getInitializer();
-      unsigned Size    = TD->getABITypeSize(C->getType());
-      unsigned Align   = TD->getPreferredAlignmentLog(I);
+      Constant *C = I->getInitializer();
+      const Type *CTy = C->getType();
+      unsigned Size = TD->getABITypeSize(CTy);
+      bool printSizeAndType = true;
+
+      // A data structure or array is aligned in memory to the largest 
+      // alignment boundary required by any data type inside it (this matches
+      // the Preferred Type Alignment). For integral types, the alignment is 
+      // the type size. 
+      //unsigned Align = TD->getPreferredAlignmentLog(I);
+      //unsigned Align = TD->getPrefTypeAlignment(C->getType());
+      unsigned Align;
+      if (CTy->getTypeID() == Type::IntegerTyID || 
+          CTy->getTypeID() == Type::VoidTyID) {
+        assert(!(Size & (Size-1)) && "Alignment is not a power of two!");
+        Align = Log2_32(Size);
+      } else
+        Align = TD->getPreferredTypeAlignmentShift(CTy);
 
       // Is this correct ?
       if (C->isNullValue() && (I->hasLinkOnceLinkage() || 
@@ -549,10 +564,20 @@
               else if (!I->isConstant())
                 SwitchToDataSection(TAI->getDataSection(), I);
               else {
-                // Read-only data.
-                if (TAI->getReadOnlySection())
+                // Read-only data. We have two possible scenary here
+                // 1) Readonly section for strings (char arrays).
+                // 2) for other types.
+                if (TAI->getReadOnlySection()) {
+                  const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
+                  if (CVA && CVA->isString()) {
+                      std::string SectionName = "\t.section\t.rodata.str1.4,"
+                                                "\"aMS\", at progbits,1";
+                      SwitchToDataSection(SectionName.c_str());
+                      printSizeAndType = false;
+                      break;
+                  }
                   SwitchToDataSection(TAI->getReadOnlySection(), I);
-                else
+                } else
                   SwitchToDataSection(TAI->getDataSection(), I);
               }
             }
@@ -568,17 +593,18 @@
             abort();
           default:
             assert(0 && "Unknown linkage type!");          
-        }
+        } 
 
-        O << "\t.align " << Align << "\n";
+        if (Align)
+          O << "\t.align " << Align << "\n";
 
-        if (TAI->hasDotTypeDotSizeDirective()) {
+        if (TAI->hasDotTypeDotSizeDirective() && printSizeAndType) {
           O << "\t.type " << name << ", at object\n";
           O << "\t.size " << name << "," << Size << "\n";
         }
         O << name << ":\n";
         EmitGlobalConstant(C);
-    }
+    } 
   }
 
   O << "\n";

Modified: llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp?rev=53585&r1=53584&r2=53585&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp Mon Jul 14 21:03:36 2008
@@ -370,10 +370,12 @@
   SmallVector<CCValAssign, 16> ArgLocs;
   CCState CCInfo(CC, isVarArg, getTargetMachine(), ArgLocs);
 
-  // To meet ABI, Mips must always allocate 16 bytes on
+  // To meet O32 ABI, Mips must always allocate 16 bytes on
   // the stack (even if less than 4 are used as arguments)
-  int VTsize = MVT(MVT::i32).getSizeInBits()/8;
-  MFI->CreateFixedObject(VTsize, (VTsize*3));
+  if (Subtarget->isABI_O32()) {
+    int VTsize = MVT(MVT::i32).getSizeInBits()/8;
+    MFI->CreateFixedObject(VTsize, (VTsize*3));
+  }
 
   CCInfo.AnalyzeCallOperands(Op.Val, CC_Mips);
   

Modified: llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp?rev=53585&r1=53584&r2=53585&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp Mon Jul 14 21:03:36 2008
@@ -267,7 +267,7 @@
   #endif
 
   // No need to allocate space on the stack.
-  if (NumBytes == 0) return;
+  if (NumBytes == 0 && !MFI->hasCalls()) return;
 
   int FPOffset, RAOffset;
   
@@ -389,7 +389,8 @@
 processFunctionBeforeFrameFinalized(MachineFunction &MF) const {
   // Set the SPOffset on the FI where GP must be saved/loaded.
   MachineFrameInfo *MFI = MF.getFrameInfo();
-  if (MFI->hasCalls()) { 
+  bool isPIC = (MF.getTarget().getRelocationModel() == Reloc::PIC_);
+  if (MFI->hasCalls() && isPIC) { 
     MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
     #ifndef NDEBUG
     DOUT << "processFunctionBeforeFrameFinalized\n";

Modified: llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp?rev=53585&r1=53584&r2=53585&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp Mon Jul 14 21:03:36 2008
@@ -31,7 +31,7 @@
   BSSSection                  = "\t.section\t.bss";
   LCOMMDirective              = "\t.lcomm\t";
 
-  if (TM.getRelocationModel() == Reloc::Static)
+  if (!TM.getSubtarget<MipsSubtarget>().hasABICall())
     JumpTableDirective = "\t.word\t";
   else    
     JumpTableDirective = "\t.gpword\t";

Modified: llvm/trunk/lib/Target/Mips/MipsTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsTargetMachine.cpp?rev=53585&r1=53584&r2=53585&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsTargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsTargetMachine.cpp Mon Jul 14 21:03:36 2008
@@ -38,8 +38,8 @@
 MipsTargetMachine::
 MipsTargetMachine(const Module &M, const std::string &FS, bool isLittle=false):
   Subtarget(*this, M, FS, isLittle), 
-  DataLayout(isLittle ? std::string("e-p:32:32:32") :
-                        std::string("E-p:32:32:32")), 
+  DataLayout(isLittle ? std::string("e-p:32:32:32-i8:8:32-i16:16:32") :
+                        std::string("E-p:32:32:32-i8:8:32-i16:16:32")), 
   InstrInfo(*this), 
   FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0),
   TLInfo(*this) 





More information about the llvm-commits mailing list