reimplement Constant::ContainsRelocations as
[oota-llvm.git] / lib / Target / TargetAsmInfo.cpp
index 5b7ddbfa4a7eaac929b0f80833f53e44d0bb4d67..96814fee4c94eb9b11c7f115e01890bccd75e00e 100644 (file)
@@ -49,7 +49,7 @@ TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm)
   MaxOperandLength = 0;
   GlobalPrefix = "";
   PrivateGlobalPrefix = ".";
-  LessPrivateGlobalPrefix = "";
+  LinkerPrivateGlobalPrefix = "";
   JumpTableSpecialLabelPrefix = 0;
   GlobalVarAddrPrefix = "";
   GlobalVarAddrSuffix = "";
@@ -190,13 +190,6 @@ static bool isConstantString(const Constant *C) {
   return false;
 }
 
-unsigned TargetAsmInfo::RelocBehaviour() const {
-  // By default - all relocations in PIC mode would force symbol to be
-  // placed in r/w section.
-  return (TM.getRelocationModel() != Reloc::Static ?
-          Reloc::LocalOrGlobal : Reloc::None);
-}
-
 SectionKind::Kind
 TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
   // Early exit - functions should be always in text sections.
@@ -209,26 +202,18 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
 
   if (isSuitableForBSS(GVar)) {
     // Variable can be easily put to BSS section.
-    return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS);
+    return isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS;
   } else if (GVar->isConstant() && !isThreadLocal) {
-    // Now we know, that varible has initializer and it is constant. We need to
+    // Now we know, that variable has initializer and it is constant. We need to
     // check its initializer to decide, which section to output it into. Also
     // note, there is no thread-local r/o section.
     Constant *C = GVar->getInitializer();
-    if (C->ContainsRelocations(Reloc::LocalOrGlobal)) {
-      // Decide, whether it is still possible to put symbol into r/o section.
-      unsigned Reloc = RelocBehaviour();
-
-      // We already did a query for 'all' relocs, thus - early exits.
-      if (Reloc == Reloc::LocalOrGlobal)
+    if (C->getRelocationInfo() != 0) {
+      // Decide whether it is still possible to put symbol into r/o section.
+      if (TM.getRelocationModel() != Reloc::Static)
         return SectionKind::Data;
-      else if (Reloc == Reloc::None)
+      else
         return SectionKind::ROData;
-      else {
-        // Ok, target wants something funny. Honour it.
-        return (C->ContainsRelocations(Reloc) ?
-                SectionKind::Data : SectionKind::ROData);
-      }
     } else {
       // Check, if initializer is a null-terminated string
       if (isConstantString(C))
@@ -251,34 +236,34 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
   if (GV) {
     SectionKind::Kind Kind = SectionKindForGlobal(GV);
     switch (Kind) {
-     case SectionKind::Text:
+    case SectionKind::Text:
       Flags |= SectionFlags::Code;
       break;
-     case SectionKind::ThreadData:
-     case SectionKind::ThreadBSS:
+    case SectionKind::ThreadData:
+    case SectionKind::ThreadBSS:
       Flags |= SectionFlags::TLS;
       // FALLS THROUGH
-     case SectionKind::Data:
-     case SectionKind::DataRel:
-     case SectionKind::DataRelLocal:
-     case SectionKind::DataRelRO:
-     case SectionKind::DataRelROLocal:
-     case SectionKind::BSS:
+    case SectionKind::Data:
+    case SectionKind::DataRel:
+    case SectionKind::DataRelLocal:
+    case SectionKind::DataRelRO:
+    case SectionKind::DataRelROLocal:
+    case SectionKind::BSS:
       Flags |= SectionFlags::Writeable;
       break;
-     case SectionKind::ROData:
-     case SectionKind::RODataMergeStr:
-     case SectionKind::RODataMergeConst:
+    case SectionKind::ROData:
+    case SectionKind::RODataMergeStr:
+    case SectionKind::RODataMergeConst:
       // No additional flags here
       break;
-     case SectionKind::SmallData:
-     case SectionKind::SmallBSS:
+    case SectionKind::SmallData:
+    case SectionKind::SmallBSS:
       Flags |= SectionFlags::Writeable;
       // FALLS THROUGH
-     case SectionKind::SmallROData:
+    case SectionKind::SmallROData:
       Flags |= SectionFlags::Small;
       break;
-     default:
+    default:
       llvm_unreachable("Unexpected section kind!");
     }
 
@@ -311,21 +296,16 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
   return Flags;
 }
 
-const Section*
-TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
-  const Section* S;
+const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
   // Select section name
   if (GV->hasSection()) {
-    // Honour section already set, if any
-    unsigned Flags = SectionFlagsForGlobal(GV,
-                                           GV->getSection().c_str());
-    S = getNamedSection(GV->getSection().c_str(), Flags);
-  } else {
-    // Use default section depending on the 'type' of global
-    S = SelectSectionForGlobal(GV);
+    // Honour section already set, if any.
+    unsigned Flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
+    return getNamedSection(GV->getSection().c_str(), Flags);
   }
-
-  return S;
+  
+  // Use default section depending on the 'type' of global
+  return SelectSectionForGlobal(GV);
 }
 
 // Lame default implementation. Calculate the section name for global.
@@ -394,10 +374,9 @@ TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
   return NULL;
 }
 
-const Section*
-TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
-                               bool Override) const {
-  Section& S = Sections[Name];
+const Section *TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
+                                              bool Override) const {
+  Section &S = Sections[Name];
 
   // This is newly-created section, set it up properly.
   if (S.Flags == SectionFlags::Invalid || Override) {