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

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


Author: asl
Date: Wed Jul  9 08:16:59 2008
New Revision: 53290

URL: http://llvm.org/viewvc/llvm-project?rev=53290&view=rev
Log:
Add code for default section falgs computation

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

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

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Wed Jul  9 08:16:59 2008
@@ -30,6 +30,7 @@
 
   namespace SectionKind {
     enum Kind {
+      Unknown = 0,      ///< Custom section
       Text,             ///< Text section
       Data,             ///< Data section
       BSS,              ///< BSS section
@@ -41,6 +42,25 @@
     };
   }
 
+  namespace SectionFlags {
+    enum Flags {
+      None       = 0,
+      Code       = 1 << 0, ///< Section contains code
+      Writeable  = 1 << 1, ///< Section is writeable
+      BSS        = 1 << 2, ///< Section contains only zeroes
+      Mergeable  = 1 << 3, ///< Section contains mergeable data
+      Strings    = 1 << 4, ///< Section contains null-terminated strings
+      TLS        = 1 << 5, ///< Section contains thread-local data
+      Debug      = 1 << 6, ///< Section contains debug data
+      Linkonce   = 1 << 7  ///< Section is linkonce
+    };
+  }
+
+  struct SectionInfo {
+    SectionKind::Kind   kind;
+    SectionFlags::Flags flags;
+  };
+
   class TargetMachine;
   class CallInst;
   class GlobalValue;
@@ -444,6 +464,13 @@
     /// section kind used for global emission.
     SectionKind::Kind SectionKindForGlobal(const GlobalValue *GV) const;
 
+
+    /// SectionFlagsForGlobal - This hook allows the target to select proper
+    /// section flags either for given global or for section.
+    unsigned
+    SectionFlagsForGlobal(const GlobalValue *GV = NULL,
+                          const char* name = NULL);
+
     // Accessors.
     //
     const char *getTextSection() const {

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

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Wed Jul  9 08:16:59 2008
@@ -191,3 +191,66 @@
   // Variable is not constant or thread-local - emit to generic data section.
   return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
 }
+
+unsigned
+TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
+                                     const char* name) {
+  unsigned flags = SectionFlags::None;
+
+  // Decode flags from global itself.
+  if (GV) {
+    SectionKind::Kind kind = SectionKindForGlobal(GV);
+    switch (kind) {
+     case SectionKind::Text:
+      flags |= SectionFlags::Code;
+      break;
+     case SectionKind::ThreadData:
+      flags |= SectionFlags::TLS;
+      // FALLS THROUGH
+     case SectionKind::Data:
+      flags |= SectionFlags::Writeable;
+      break;
+     case SectionKind::ThreadBSS:
+      flags |= SectionFlags::TLS;
+      // FALLS THROUGH
+     case SectionKind::BSS:
+      flags |= SectionFlags::BSS;
+      break;
+     case SectionKind::ROData:
+      // No additional flags here
+      break;
+     case SectionKind::RODataMergeStr:
+      flags |= SectionFlags::Strings;
+      // FALLS THROUGH
+     case SectionKind::RODataMergeConst:
+      flags |= SectionFlags::Mergeable;
+      break;
+     default:
+      assert(0 && "Unexpected section kind!");
+    }
+
+    if (GV->hasLinkOnceLinkage() ||
+        GV->hasWeakLinkage() ||
+        GV->hasCommonLinkage())
+      flags |= SectionFlags::Linkonce;
+  }
+
+  // Add flags from sections, if any.
+  if (name) {
+    // Some lame default implementation
+    if (strcmp(name, ".bss") == 0 ||
+        strncmp(name, ".bss.", 5) == 0 ||
+        strncmp(name, ".gnu.linkonce.b.", 16) == 0)
+      flags |= SectionFlags::BSS;
+    else if (strcmp(name, ".tdata") == 0 ||
+             strncmp(name, ".tdata.", 7) == 0 ||
+             strncmp(name, ".gnu.linkonce.td.", 17) == 0)
+      flags |= SectionFlags::TLS;
+    else if (strcmp(name, ".tbss") == 0 ||
+             strncmp(name, ".tbss.", 6) == 0 ||
+             strncmp(name, ".gnu.linkonce.tb.", 17) == 0)
+      flags |= SectionFlags::BSS | SectionFlags::TLS;
+  }
+
+  return flags;
+}





More information about the llvm-commits mailing list