[llvm-commits] [llvm] r54538 - in /llvm/trunk/lib/Target/PowerPC: PPCAsmPrinter.cpp PPCTargetAsmInfo.cpp PPCTargetAsmInfo.h

Anton Korobeynikov asl at math.spbu.ru
Fri Aug 8 11:23:49 PDT 2008


Author: asl
Date: Fri Aug  8 13:23:49 2008
New Revision: 54538

URL: http://llvm.org/viewvc/llvm-project?rev=54538&view=rev
Log:
Convert PPC/Linux to new section printing stuff

Modified:
    llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
    llvm/trunk/lib/Target/PowerPC/PPCTargetAsmInfo.cpp
    llvm/trunk/lib/Target/PowerPC/PPCTargetAsmInfo.h

Modified: llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp?rev=54538&r1=54537&r2=54538&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp Fri Aug  8 13:23:49 2008
@@ -317,6 +317,7 @@
     /// getSectionForFunction - Return the section that we should emit the
     /// specified function body into.
     virtual std::string getSectionForFunction(const Function &F) const;
+    void printModuleLevelGV(const GlobalVariable* GVar);
   };
 
   /// PPCDarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac
@@ -657,111 +658,95 @@
       OS << *Name;
 }
 
-bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
+void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
   const TargetData *TD = TM.getTargetData();
 
-  // Print out module-level global variables here.
-  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
-       I != E; ++I) {
-    if (!I->hasInitializer()) continue;   // External global require no code
+  if (!GVar->hasInitializer())
+    return;   // External global require no code
+
+  // Check to see if this is a special global used by LLVM, if so, emit it.
+  if (EmitSpecialLLVMGlobal(GVar))
+    return;
 
-    // Check to see if this is a special global used by LLVM, if so, emit it.
-    if (EmitSpecialLLVMGlobal(I))
-      continue;
-
-    std::string name = Mang->getValueName(I);
-
-    if (I->hasHiddenVisibility())
-      if (const char *Directive = TAI->getHiddenDirective())
-        O << Directive << name << "\n";
-
-    Constant *C = I->getInitializer();
-    unsigned Size = TD->getABITypeSize(C->getType());
-    unsigned Align = TD->getPreferredAlignmentLog(I);
-
-    if (C->isNullValue() && /* FIXME: Verify correct */
-        !I->hasSection() && (I->hasCommonLinkage() ||
-         I->hasInternalLinkage() || I->hasWeakLinkage() ||
-         I->hasLinkOnceLinkage() || I->hasExternalLinkage())) {
+  std::string name = Mang->getValueName(GVar);
+  std::string SectionName = TAI->SectionForGlobal(GVar);
+
+  if (GVar->hasHiddenVisibility())
+    if (const char *Directive = TAI->getHiddenDirective())
+      O << Directive << name << "\n";
+
+  Constant *C = GVar->getInitializer();
+  const Type *Type = C->getType();
+  unsigned Size = TD->getABITypeSize(Type);
+  unsigned Align = TD->getPreferredAlignmentLog(GVar);
+
+  SwitchToDataSection(SectionName.c_str());
+
+  if (C->isNullValue() && /* FIXME: Verify correct */
+      !GVar->hasSection() &&
+      (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
+       GVar->isWeakForLinker())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
-      if (I->hasExternalLinkage()) {
+
+      if (GVar->hasExternalLinkage()) {
         O << "\t.global " << name << '\n';
         O << "\t.type " << name << ", @object\n";
-        if (TAI->getBSSSection())
-          SwitchToDataSection(TAI->getBSSSection(), I);
         O << name << ":\n";
         O << "\t.zero " << Size << "\n";
-      } else if (I->hasInternalLinkage()) {
-        SwitchToDataSection("\t.data", I);
+      } else if (GVar->hasInternalLinkage()) {
         O << TAI->getLCOMMDirective() << name << "," << Size;
       } else {
-        SwitchToDataSection("\t.data", I);
         O << ".comm " << name << "," << Size;
       }
       O << "\t\t" << TAI->getCommentString() << " '";
-      PrintUnmangledNameSafely(I, O);
+      PrintUnmangledNameSafely(GVar, O);
       O << "'\n";
-    } else {
-      switch (I->getLinkage()) {
-      case GlobalValue::LinkOnceLinkage:
-      case GlobalValue::WeakLinkage:
-      case GlobalValue::CommonLinkage:
-        O << "\t.global " << name << '\n'
-          << "\t.type " << name << ", @object\n"
-          << "\t.weak " << name << '\n';
-        SwitchToDataSection("\t.data", I);
-        break;
-      case GlobalValue::AppendingLinkage:
-        // FIXME: appending linkage variables should go into a section of
-        // their name or something.  For now, just emit them as external.
-      case GlobalValue::ExternalLinkage:
-        // If external or appending, declare as a global symbol
-        O << "\t.global " << name << "\n"
-          << "\t.type " << name << ", @object\n";
-        // FALL THROUGH
-      case GlobalValue::InternalLinkage:
-        if (I->isConstant()) {
-          const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
-          if (TAI->getCStringSection() && CVA && CVA->isCString()) {
-            SwitchToDataSection(TAI->getCStringSection(), I);
-            break;
-          }
-        }
-
-        // FIXME: special handling for ".ctors" & ".dtors" sections
-        if (I->hasSection() &&
-            (I->getSection() == ".ctors" ||
-             I->getSection() == ".dtors")) {
-          std::string SectionName = ".section " + I->getSection()
-                                                + ",\"aw\", at progbits";
-          SwitchToDataSection(SectionName.c_str());
-        } else {
-          if (I->isConstant() && TAI->getReadOnlySection())
-            SwitchToDataSection(TAI->getReadOnlySection(), I);
-          else
-            SwitchToDataSection(TAI->getDataSection(), I);
-        }
-        break;
-      default:
-        cerr << "Unknown linkage type!";
-        abort();
-      }
+      return;
+  }
 
-      EmitAlignment(Align, I);
-      O << name << ":\t\t\t\t" << TAI->getCommentString() << " '";
-      PrintUnmangledNameSafely(I, O);
-      O << "'\n";
+  switch (GVar->getLinkage()) {
+   case GlobalValue::LinkOnceLinkage:
+   case GlobalValue::WeakLinkage:
+   case GlobalValue::CommonLinkage:
+    O << "\t.global " << name << '\n'
+      << "\t.type " << name << ", @object\n"
+      << "\t.weak " << name << '\n';
+    break;
+   case GlobalValue::AppendingLinkage:
+    // FIXME: appending linkage variables should go into a section of
+    // their name or something.  For now, just emit them as external.
+   case GlobalValue::ExternalLinkage:
+    // If external or appending, declare as a global symbol
+    O << "\t.global " << name << "\n"
+      << "\t.type " << name << ", @object\n";
+    // FALL THROUGH
+   case GlobalValue::InternalLinkage:
+    break;
+   default:
+    cerr << "Unknown linkage type!";
+    abort();
+  }
 
-      // If the initializer is a extern weak symbol, remember to emit the weak
-      // reference!
-      if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
-        if (GV->hasExternalWeakLinkage())
-          ExtWeakSymbols.insert(GV);
+  EmitAlignment(Align, GVar);
+  O << name << ":\t\t\t\t" << TAI->getCommentString() << " '";
+  PrintUnmangledNameSafely(GVar, O);
+  O << "'\n";
 
-      EmitGlobalConstant(C);
-      O << '\n';
-    }
-  }
+  // If the initializer is a extern weak symbol, remember to emit the weak
+  // reference!
+  if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
+    if (GV->hasExternalWeakLinkage())
+      ExtWeakSymbols.insert(GV);
+
+  EmitGlobalConstant(C);
+  O << '\n';
+}
+
+bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
+  // Print out module-level global variables here.
+  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
+       I != E; ++I)
+    printModuleLevelGV(I);
 
   // TODO
 
@@ -783,7 +768,6 @@
 /// method to print assembly for each instruction.
 ///
 bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
-
   SetupMachineFunction(MF);
   O << "\n\n";
 

Modified: llvm/trunk/lib/Target/PowerPC/PPCTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCTargetAsmInfo.cpp?rev=54538&r1=54537&r2=54538&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCTargetAsmInfo.cpp Fri Aug  8 13:23:49 2008
@@ -104,9 +104,8 @@
 }
 
 
-PPCLinuxTargetAsmInfo::PPCLinuxTargetAsmInfo(const PPCTargetMachine &TM)
-: PPCTargetAsmInfo(TM)
-{
+PPCLinuxTargetAsmInfo::PPCLinuxTargetAsmInfo(const PPCTargetMachine &TM) :
+  PPCTargetAsmInfo(TM), ELFTargetAsmInfo(TM) {
   CommentString = "#";
   GlobalPrefix = "";
   PrivateGlobalPrefix = "";

Modified: llvm/trunk/lib/Target/PowerPC/PPCTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCTargetAsmInfo.h?rev=54538&r1=54537&r2=54538&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCTargetAsmInfo.h (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCTargetAsmInfo.h Fri Aug  8 13:23:49 2008
@@ -16,6 +16,7 @@
 
 #include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/DarwinTargetAsmInfo.h"
+#include "llvm/Target/ELFTargetAsmInfo.h"
 
 namespace llvm {
 
@@ -27,13 +28,14 @@
   };
 
   struct PPCDarwinTargetAsmInfo : public PPCTargetAsmInfo,
-                                  public DarwinTargetAsmInfo{
+                                  public DarwinTargetAsmInfo {
     explicit PPCDarwinTargetAsmInfo(const PPCTargetMachine &TM);
     virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
                                            bool Global) const;
   };
 
-  struct PPCLinuxTargetAsmInfo : public PPCTargetAsmInfo {
+  struct PPCLinuxTargetAsmInfo : public PPCTargetAsmInfo,
+                                 public ELFTargetAsmInfo {
     explicit PPCLinuxTargetAsmInfo(const PPCTargetMachine &TM);
     virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
                                            bool Global) const;





More information about the llvm-commits mailing list