[llvm-commits] [llvm] r54519 - in /llvm/trunk: include/llvm/Target/DarwinTargetAsmInfo.h include/llvm/Target/ELFTargetAsmInfo.h include/llvm/Target/TargetAsmInfo.h lib/Target/ARM/ARMAsmPrinter.cpp lib/Target/DarwinTargetAsmInfo.cpp lib/Target/ELFTargetAsmInfo.cpp lib/Target/Mips/MipsTargetAsmInfo.cpp lib/Target/Mips/MipsTargetAsmInfo.h lib/Target/TargetAsmInfo.cpp test/CodeGen/ARM/2008-08-07-AsmPrintBug.ll

Evan Cheng evan.cheng at apple.com
Thu Aug 7 23:56:16 PDT 2008


Author: evancheng
Date: Fri Aug  8 01:56:16 2008
New Revision: 54519

URL: http://llvm.org/viewvc/llvm-project?rev=54519&view=rev
Log:
It's not legal to output a GV in a coalesced section if it's used in an ARM PIC relative constantpool.

Added:
    llvm/trunk/test/CodeGen/ARM/2008-08-07-AsmPrintBug.ll
Modified:
    llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h
    llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h
    llvm/trunk/include/llvm/Target/TargetAsmInfo.h
    llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
    llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp
    llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp
    llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp
    llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.h
    llvm/trunk/lib/Target/TargetAsmInfo.cpp

Modified: llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h?rev=54519&r1=54518&r2=54519&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h Fri Aug  8 01:56:16 2008
@@ -30,7 +30,8 @@
     const Section* DataCoalSection;
 
     explicit DarwinTargetAsmInfo(const TargetMachine &TM);
-    virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
+    virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
+                                                 bool NoCoalesce = false) const;
     virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
                                                SectionKind::Kind kind) const;
     const Section* MergeableConstSection(const GlobalVariable *GV) const;

Modified: llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h?rev=54519&r1=54518&r2=54519&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h Fri Aug  8 01:56:16 2008
@@ -26,7 +26,8 @@
   struct ELFTargetAsmInfo: public virtual TargetAsmInfo {
     explicit ELFTargetAsmInfo(const TargetMachine &TM);
 
-    virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
+    virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
+                                                 bool NoCoalesce = false) const;
     virtual std::string PrintSectionFlags(unsigned flags) const;
     const Section* MergeableConstSection(const GlobalVariable *GV) const;
     inline const Section* MergeableConstSection(const Type *Ty) const;

Modified: llvm/trunk/include/llvm/Target/TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmInfo.h?rev=54519&r1=54518&r2=54519&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Fri Aug  8 01:56:16 2008
@@ -544,8 +544,10 @@
                           const char* name = NULL) const;
 
     /// SectionForGlobal - This hooks returns proper section name for given
-    /// global with all necessary flags and marks.
-    virtual std::string SectionForGlobal(const GlobalValue *GV) const;
+    /// global with all necessary flags and marks. If NoCoalesce is true,
+    /// do not use coalesced section.
+    virtual std::string SectionForGlobal(const GlobalValue *GV,
+                                         bool NoCoalesce = false) const;
 
     // Helper methods for SectionForGlobal
     virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
@@ -553,7 +555,8 @@
 
     virtual std::string PrintSectionFlags(unsigned flags) const { return ""; }
 
-    virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
+    virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
+                                                 bool NoCoalesce = false) const;
 
     virtual const Section* SelectSectionForMachineConst(const Type *Ty) const;
 

Modified: llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp?rev=54519&r1=54518&r2=54519&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp Fri Aug  8 01:56:16 2008
@@ -29,6 +29,7 @@
 #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/Support/Compiler.h"
@@ -65,14 +66,18 @@
     typedef std::map<const Value *, unsigned> ValueMapTy;
     ValueMapTy NumberForBB;
 
-    /// Keeps the set of GlobalValues that require non-lazy-pointers for
-    /// indirect access.
+    /// GVNonLazyPtrs - Keeps the set of GlobalValues that require
+    /// non-lazy-pointers for indirect access.
     std::set<std::string> GVNonLazyPtrs;
 
-    /// Keeps the set of external function GlobalAddresses that the asm
-    /// printer should generate stubs for.
+    /// FnStubs - Keeps the set of external function GlobalAddresses that the
+    /// asm printer should generate stubs for.
     std::set<std::string> 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;
     
@@ -124,10 +129,12 @@
     /// specified function body into.
     virtual std::string getSectionForFunction(const Function &F) const;
 
+    /// EmitMachineConstantPoolValue - Print a machine constantpool value to
+    /// the .s file.
     virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
       printDataDirective(MCPV->getType());
 
-      ARMConstantPoolValue *ACPV = (ARMConstantPoolValue*)MCPV;
+      ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV);
       GlobalValue *GV = ACPV->getGV();
       std::string Name = GV ? Mang->getValueName(GV) : TAI->getGlobalPrefix();
       if (!GV)
@@ -680,9 +687,15 @@
     const MachineConstantPoolEntry &MCPE =  // Chasing pointers is fun?
       MI->getParent()->getParent()->getConstantPool()->getConstants()[CPI];
     
-    if (MCPE.isMachineConstantPoolEntry())
+    if (MCPE.isMachineConstantPoolEntry()) {
       EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
-    else {
+      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
       if (const GlobalValue *GV = dyn_cast<GlobalValue>(MCPE.Val.ConstVal))
@@ -850,7 +863,8 @@
     return;
   }
 
-  std::string SectionName = TAI->SectionForGlobal(GVar);
+  bool NoCoalesc = PCRelGVs.count(GVar);
+  std::string SectionName = TAI->SectionForGlobal(GVar, NoCoalesc);
   std::string name = Mang->getValueName(GVar);
   Constant *C = GVar->getInitializer();
   const Type *Type = C->getType();
@@ -887,7 +901,7 @@
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
       if (TAI->getLCOMMDirective() != NULL) {
-        if (GVar->hasInternalLinkage()) {
+        if (NoCoalesc || GVar->hasInternalLinkage()) {
           O << TAI->getLCOMMDirective() << name << "," << Size;
           if (Subtarget->isTargetDarwin())
             O << "," << Align;

Modified: llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp?rev=54519&r1=54518&r2=54519&view=diff

==============================================================================
--- llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp Fri Aug  8 01:56:16 2008
@@ -51,14 +51,15 @@
 }
 
 const Section*
-DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
+DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
+                                            bool NoCoalesce) const {
   SectionKind::Kind Kind = SectionKindForGlobal(GV);
-  bool isWeak = GV->isWeakForLinker();
+  bool CanCoalesce = !NoCoalesce && GV->isWeakForLinker();
   bool isNonStatic = (DTM->getRelocationModel() != Reloc::Static);
 
   switch (Kind) {
    case SectionKind::Text:
-    if (isWeak)
+    if (CanCoalesce)
       return TextCoalSection;
     else
       return getTextSection_();
@@ -67,18 +68,18 @@
    case SectionKind::BSS:
    case SectionKind::ThreadBSS:
     if (cast<GlobalVariable>(GV)->isConstant())
-      return (isWeak ? ConstDataCoalSection : ConstDataSection);
+      return (CanCoalesce ? ConstDataCoalSection : ConstDataSection);
     else
-      return (isWeak ? DataCoalSection : getDataSection_());
+      return (CanCoalesce ? DataCoalSection : getDataSection_());
    case SectionKind::ROData:
-    return (isWeak ? ConstDataCoalSection :
+    return (CanCoalesce ? ConstDataCoalSection :
             (isNonStatic ? ConstDataSection : getReadOnlySection_()));
    case SectionKind::RODataMergeStr:
-    return (isWeak ?
+    return (CanCoalesce ?
             ConstDataCoalSection :
             MergeableStringSection(cast<GlobalVariable>(GV)));
    case SectionKind::RODataMergeConst:
-    return (isWeak ?
+    return (CanCoalesce ?
             ConstDataCoalSection:
             MergeableConstSection(cast<GlobalVariable>(GV)));
    default:

Modified: llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp?rev=54519&r1=54518&r2=54519&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp Fri Aug  8 01:56:16 2008
@@ -40,7 +40,8 @@
 }
 
 const Section*
-ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
+ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
+                                         bool NoCoalesce) const {
   SectionKind::Kind Kind = SectionKindForGlobal(GV);
 
   if (const Function *F = dyn_cast<Function>(GV)) {

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

==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.cpp Fri Aug  8 01:56:16 2008
@@ -82,7 +82,7 @@
 }
 
 const Section* MipsTargetAsmInfo::
-SelectSectionForGlobal(const GlobalValue *GV) const {
+SelectSectionForGlobal(const GlobalValue *GV, bool NoCoalesce) const {
   SectionKind::Kind K = SectionKindForGlobal(GV);
   const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
 

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

==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.h (original)
+++ llvm/trunk/lib/Target/Mips/MipsTargetAsmInfo.h Fri Aug  8 01:56:16 2008
@@ -40,7 +40,8 @@
     SectionFlagsForGlobal(const GlobalValue *GV = NULL,
                           const char* name = NULL) const;
 
-    virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
+    virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
+                                                  bool NoCoalesce) const;
 
     private:
       const MipsSubtarget *Subtarget;

Modified: llvm/trunk/lib/Target/TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetAsmInfo.cpp?rev=54519&r1=54518&r2=54519&view=diff

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Fri Aug  8 01:56:16 2008
@@ -272,7 +272,7 @@
 }
 
 std::string
-TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
+TargetAsmInfo::SectionForGlobal(const GlobalValue *GV, bool NoCoalesce) const {
   const Section* S;
   // Select section name
   if (GV->hasSection()) {
@@ -282,7 +282,7 @@
     S = getNamedSection(GV->getSection().c_str(), Flags);
   } else {
     // Use default section depending on the 'type' of global
-    S = SelectSectionForGlobal(GV);
+    S = SelectSectionForGlobal(GV, NoCoalesce);
   }
 
   if (!S->isNamed())
@@ -295,8 +295,8 @@
 }
 
 // Lame default implementation. Calculate the section name for global.
-const Section*
-TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
+const Section* TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
+                                                     bool NoCoalesce) const {
   SectionKind::Kind Kind = SectionKindForGlobal(GV);
 
   if (GV->isWeakForLinker()) {

Added: llvm/trunk/test/CodeGen/ARM/2008-08-07-AsmPrintBug.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/2008-08-07-AsmPrintBug.ll?rev=54519&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/ARM/2008-08-07-AsmPrintBug.ll (added)
+++ llvm/trunk/test/CodeGen/ARM/2008-08-07-AsmPrintBug.ll Fri Aug  8 01:56:16 2008
@@ -0,0 +1,13 @@
+; RUN: llvm-as < %s | llc -mtriple=arm-apple-darwin -mattr=+v6 -relocation-model=pic | grep lcomm
+
+	%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] }
+	%struct.__sFILEX = type opaque
+	%struct.__sbuf = type { i8*, i32 }
+ at __gcov_var = common global %struct.__gcov_var zeroinitializer		; <%struct.__gcov_var*> [#uses=1]
+
+define i32 @__gcov_close() nounwind {
+entry:
+	load i32* getelementptr (%struct.__gcov_var* @__gcov_var, i32 0, i32 5), align 4		; <i32>:0 [#uses=1]
+	ret i32 %0
+}





More information about the llvm-commits mailing list