[llvm-commits] [llvm] r53295 - in /llvm/trunk: include/llvm/Target/TargetAsmInfo.h lib/Target/TargetAsmInfo.cpp lib/Target/X86/X86TargetAsmInfo.cpp lib/Target/X86/X86TargetAsmInfo.h

Anton Korobeynikov asl at math.spbu.ru
Wed Jul 9 06:19:08 PDT 2008


Author: asl
Date: Wed Jul  9 08:19:08 2008
New Revision: 53295

URL: http://llvm.org/viewvc/llvm-project?rev=53295&view=rev
Log:
Provide skeletone code for calculation of section, where global should be emitted into

Modified:
    llvm/trunk/include/llvm/Target/TargetAsmInfo.h
    llvm/trunk/lib/Target/TargetAsmInfo.cpp
    llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
    llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h

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

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Wed Jul  9 08:19:08 2008
@@ -474,7 +474,7 @@
 
     /// SectionForGlobal - This hooks returns proper section name for given
     /// global with all necessary flags and marks.
-    virtual const char* SectionForGlobal(const GlobalValue *GV) const;
+    virtual std::string SectionForGlobal(const GlobalValue *GV) const;
 
     // Accessors.
     //

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

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Wed Jul  9 08:19:08 2008
@@ -255,7 +255,7 @@
   return flags;
 }
 
-const char*
+std::string
 TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
   SectionKind::Kind kind = SectionKindForGlobal(GV);
 

Modified: llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp?rev=53295&r1=53294&r2=53295&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp Wed Jul  9 08:19:08 2008
@@ -346,8 +346,8 @@
       else {
         // 64 bit targets encode pointers in 4 bytes iff:
         // - code model is small OR
-        // - code model is medium and we're emitting externally visible symbols or
-        //   any code symbols
+        // - code model is medium and we're emitting externally visible symbols
+        //   or any code symbols
         if (CM == CodeModel::Small ||
             (CM == CodeModel::Medium && (Global ||
                                          Reason != DwarfEncoding::Data)))
@@ -375,3 +375,96 @@
   }
 }
 
+std::string X86TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
+  const X86Subtarget *Subtarget = &X86TM->getSubtarget<X86Subtarget>();
+  SectionKind::Kind kind = SectionKindForGlobal(GV);
+  unsigned flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
+  std::string Name;
+
+  // FIXME: Should we use some hashing based on section name and just check
+  // flags?
+
+  // Select section name
+  if (const Function *F = dyn_cast<Function>(GV)) {
+    // Implement here
+  } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
+    if (GVar->hasSection()) {
+      // Honour section already set, if any
+      Name = GVar->getSection();
+    } else {
+      // Use default section depending on the 'type' of global
+      // FIXME: Handle linkonce stuff
+      switch (kind) {
+       case SectionKind::Data:
+        Name = DataSection;
+        break;
+       case SectionKind::BSS:
+        Name = (BSSSection ? BSSSection : DataSection);
+        break;
+       case SectionKind::ROData:
+       case SectionKind::RODataMergeStr:
+       case SectionKind::RODataMergeConst:
+        // FIXME: Temporary
+        Name = DataSection;
+        break;
+       case SectionKind::ThreadData:
+        Name = (TLSDataSection ? TLSDataSection : DataSection);
+        break;
+       case SectionKind::ThreadBSS:
+        Name = (TLSBSSSection ? TLSBSSSection : DataSection);
+       default:
+        assert(0 && "Unsuported section kind for global");
+      }
+    }
+  } else
+    assert(0 && "Unsupported global");
+
+  // Add all special flags, etc
+  switch (Subtarget->TargetType) {
+   case X86Subtarget::isELF:
+    Name += ",\"";
+
+    if (!(flags & SectionFlags::Debug))
+      Name += 'a';
+    if (flags & SectionFlags::Code)
+      Name += 'x';
+    if (flags & SectionFlags::Writeable)
+      Name += 'w';
+    if (flags & SectionFlags::Mergeable)
+      Name += 'M';
+    if (flags & SectionFlags::Strings)
+      Name += 'S';
+    if (flags & SectionFlags::TLS)
+      Name += 'T';
+
+    Name += "\"";
+
+    // FIXME: There can be exceptions here
+    if (flags & SectionFlags::BSS)
+      Name += ", at nobits";
+    else
+      Name += ", at progbits";
+
+    // FIXME: entity size for mergeable sections
+    break;
+   case X86Subtarget::isCygwin:
+   case X86Subtarget::isMingw:
+    Name += ",\"";
+
+    if (flags & SectionFlags::Code)
+      Name += 'x';
+    if (flags & SectionFlags::Writeable)
+      Name += 'w';
+
+    Name += "\"";
+
+    break;
+   case X86Subtarget::isDarwin:
+    // Darwin does not use any special flags
+   default:
+    break;
+  }
+
+  return Name;
+}
+

Modified: llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h?rev=53295&r1=53294&r2=53295&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h Wed Jul  9 08:19:08 2008
@@ -23,10 +23,11 @@
 
   struct X86TargetAsmInfo : public TargetAsmInfo {
     explicit X86TargetAsmInfo(const X86TargetMachine &TM);
-    
+
     virtual bool ExpandInlineAsm(CallInst *CI) const;
     virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
                                            bool Global) const;
+    virtual std::string SectionForGlobal(const GlobalValue *GV) const;
 
   private:
     const X86TargetMachine* X86TM;





More information about the llvm-commits mailing list