Clean up some ARM GV asm printing out; minor fixes to match what gcc does.
authorEvan Cheng <evan.cheng@apple.com>
Sat, 6 Dec 2008 02:00:55 +0000 (02:00 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Sat, 6 Dec 2008 02:00:55 +0000 (02:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60621 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMTargetAsmInfo.cpp
lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
test/CodeGen/ARM/2008-08-07-AsmPrintBug.ll
test/CodeGen/ARM/hidden-vis-2.ll [new file with mode: 0644]
test/CodeGen/ARM/hidden-vis-3.ll [new file with mode: 0644]
test/CodeGen/ARM/hidden-vis.ll [new file with mode: 0644]

index e0c81d61cbd24ece5e563fa2a9912238b7a85242..d2965fe80f0e97a7bb09f8b0b96e07685d223939 100644 (file)
@@ -56,6 +56,7 @@ ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM):
   ZeroFillDirective = "\t.zerofill\t";  // Uses .zerofill
   SetDirective = "\t.set\t";
   WeakRefDirective = "\t.weak_reference\t";
+  WeakDefDirective = "\t.weak_definition ";
   HiddenDirective = "\t.private_extern\t";
   ProtectedDirective = NULL;
   JumpTableDataSection = ".const";
index 9d81acdb11702e48113dbee1876cc9b9a4777315..f44b9a1cee7d5f2edebe13fc3a43d4e0d75ae880 100644 (file)
@@ -29,7 +29,6 @@
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
-#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSet.h"
@@ -84,10 +83,6 @@ namespace {
     /// asm printer should generate stubs for.
     StringSet<> FnStubs;
 
-    /// PCRelGVs - Keeps the set of GlobalValues used in pc relative
-    /// constantpool.
-    SmallPtrSet<const GlobalValue*, 8> PCRelGVs;
-
     /// True if asm printer is printing a series of CONSTPOOL_ENTRY.
     bool InCPMode;
     
@@ -677,12 +672,6 @@ void ARMAsmPrinter::printCPInstOperand(const MachineInstr *MI, int OpNo,
     
     if (MCPE.isMachineConstantPoolEntry()) {
       EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
-      ARMConstantPoolValue *ACPV =
-        static_cast<ARMConstantPoolValue*>(MCPE.Val.MachineCPVal);
-      if (ACPV->getPCAdjustment() != 0) {
-        const GlobalValue *GV = ACPV->getGV();
-        PCRelGVs.insert(GV);
-      }
     } else {
       EmitGlobalConstant(MCPE.Val.ConstVal);
       // remember to emit the weak reference
@@ -841,18 +830,18 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
   const Type *Type = C->getType();
   unsigned Size = TD->getABITypeSize(Type);
   unsigned Align = TD->getPreferredAlignmentLog(GVar);
+  bool isDarwin = Subtarget->isTargetDarwin();
 
   printVisibility(name, GVar->getVisibility());
 
   if (Subtarget->isTargetELF())
     O << "\t.type " << name << ",%object\n";
 
-  SwitchToSection(TAI->SectionForGlobal(GVar));
-
   if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal()) {
     // FIXME: This seems to be pretty darwin-specific
 
     if (GVar->hasExternalLinkage()) {
+      SwitchToSection(TAI->SectionForGlobal(GVar));
       if (const char *Directive = TAI->getZeroFillDirective()) {
         O << "\t.globl\t" << name << "\n";
         O << Directive << "__DATA, __common, " << name << ", "
@@ -864,14 +853,34 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
     if (GVar->hasInternalLinkage() || GVar->mayBeOverridden()) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
-      if (TAI->getLCOMMDirective() != NULL) {
-        if (PCRelGVs.count(GVar) || GVar->hasInternalLinkage()) {
+      if (isDarwin) {
+        if (GVar->hasInternalLinkage()) {
+          O << TAI->getLCOMMDirective()  << name << "," << Size
+            << ',' << Align;
+        } else if (GVar->hasCommonLinkage()) {
+          O << TAI->getCOMMDirective()  << name << "," << Size
+            << ',' << Align;
+        } else {
+          SwitchToSection(TAI->SectionForGlobal(GVar));
+          O << "\t.globl " << name << '\n'
+            << TAI->getWeakDefDirective() << name << '\n';
+          EmitAlignment(Align, GVar);
+          O << name << ":\t\t\t\t" << TAI->getCommentString() << ' ';
+          PrintUnmangledNameSafely(GVar, O);
+          O << '\n';
+          EmitGlobalConstant(C);
+          return;
+        }
+      } else if (TAI->getLCOMMDirective() != NULL) {
+        if (GVar->hasInternalLinkage()) {
           O << TAI->getLCOMMDirective() << name << "," << Size;
-          if (Subtarget->isTargetDarwin())
-            O << "," << Align;
-        } else
+        } else {
           O << TAI->getCOMMDirective()  << name << "," << Size;
+          if (TAI->getCOMMDirectiveTakesAlignment())
+            O << ',' << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
+        }
       } else {
+        SwitchToSection(TAI->SectionForGlobal(GVar));
         if (GVar->hasInternalLinkage())
           O << "\t.local\t" << name << "\n";
         O << TAI->getCOMMDirective()  << name << "," << Size;
@@ -885,10 +894,12 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
     }
   }
 
+  SwitchToSection(TAI->SectionForGlobal(GVar));
   switch (GVar->getLinkage()) {
+   case GlobalValue::CommonLinkage:
    case GlobalValue::LinkOnceLinkage:
    case GlobalValue::WeakLinkage:
-    if (Subtarget->isTargetDarwin()) {
+    if (isDarwin) {
       O << "\t.globl " << name << "\n"
         << "\t.weak_definition " << name << "\n";
     } else {
@@ -980,7 +991,7 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
 
     // Output non-lazy-pointers for external and common global variables.
     if (!GVNonLazyPtrs.empty()) {
-      SwitchToDataSection(".non_lazy_symbol_pointer", 0);
+      SwitchToDataSection("\t.non_lazy_symbol_pointer", 0);
       for (StringSet<>::iterator i =  GVNonLazyPtrs.begin(),
              e = GVNonLazyPtrs.end(); i != e; ++i) {
         const char *p = i->getKeyData();
index d2a8bb24cad08142dacf6138b693eb2a9f4e3ac7..0a79e8665a75e0e98557bb118ec60362f6a39490 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin -mattr=+v6 -relocation-model=pic | grep lcomm
+; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin -mattr=+v6 -relocation-model=pic | grep comm
 
        %struct.FILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 }
        %struct.__gcov_var = type { %struct.FILE*, i32, i32, i32, i32, i32, i32, [1025 x i32] }
diff --git a/test/CodeGen/ARM/hidden-vis-2.ll b/test/CodeGen/ARM/hidden-vis-2.ll
new file mode 100644 (file)
index 0000000..6cf69aa
--- /dev/null
@@ -0,0 +1,9 @@
+; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin | grep ldr | count 2
+
+@x = weak hidden global i32 0          ; <i32*> [#uses=1]
+
+define i32 @t() nounwind readonly {
+entry:
+       %0 = load i32* @x, align 4              ; <i32> [#uses=1]
+       ret i32 %0
+}
diff --git a/test/CodeGen/ARM/hidden-vis-3.ll b/test/CodeGen/ARM/hidden-vis-3.ll
new file mode 100644 (file)
index 0000000..4477f2a
--- /dev/null
@@ -0,0 +1,14 @@
+; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin | grep ldr | count 6
+; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin | grep non_lazy_ptr
+; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin | grep long | count 4
+
+@x = external hidden global i32                ; <i32*> [#uses=1]
+@y = extern_weak hidden global i32     ; <i32*> [#uses=1]
+
+define i32 @t() nounwind readonly {
+entry:
+       %0 = load i32* @x, align 4              ; <i32> [#uses=1]
+       %1 = load i32* @y, align 4              ; <i32> [#uses=1]
+       %2 = add i32 %1, %0             ; <i32> [#uses=1]
+       ret i32 %2
+}
diff --git a/test/CodeGen/ARM/hidden-vis.ll b/test/CodeGen/ARM/hidden-vis.ll
new file mode 100644 (file)
index 0000000..93f81ec
--- /dev/null
@@ -0,0 +1,18 @@
+; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin | \
+; RUN:   grep .private_extern | count 2
+
+%struct.Person = type { i32 }
+@a = hidden global i32 0
+@b = external global i32
+
+
+define weak hidden void @_ZN6Person13privateMethodEv(%struct.Person* %this) {
+  ret void
+}
+
+declare void @function(i32)
+
+define weak void @_ZN6PersonC1Ei(%struct.Person* %this, i32 %_c) {
+  ret void
+}
+