Provide convenient helpers
[oota-llvm.git] / lib / Target / Mips / MipsTargetAsmInfo.cpp
index 78b5c4aee0e6025884d2ab14431034b5bdb6d259..04edd0d4b537c8031f08910dbae4ab9e922f2a71 100644 (file)
 
 #include "MipsTargetAsmInfo.h"
 #include "MipsTargetMachine.h"
+#include "llvm/GlobalVariable.h"
 
 using namespace llvm;
 
 MipsTargetAsmInfo::MipsTargetAsmInfo(const MipsTargetMachine &TM):
   ELFTargetAsmInfo(TM) {
 
-  MipsTM = &TM;
+  Subtarget = &TM.getSubtarget<MipsSubtarget>();
 
   AlignmentIsInBytes          = false;
   COMMDirectiveTakesAlignment = true;
@@ -32,33 +33,43 @@ MipsTargetAsmInfo::MipsTargetAsmInfo(const MipsTargetMachine &TM):
   ReadOnlySection             = "\t.rdata";
   ZeroDirective               = "\t.space\t";
   BSSSection                  = "\t.section\t.bss";
-  LCOMMDirective              = "\t.lcomm\t";
   CStringSection              = ".rodata.str";
+  FourByteConstantSection     = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
 
-  if (!TM.getSubtarget<MipsSubtarget>().hasABICall())
+  if (!Subtarget->hasABICall()) {
     JumpTableDirective = "\t.word\t";
-  else
+    SmallDataSection = getNamedSection("\t.sdata", SectionFlags::Writeable);
+    SmallBSSSection = getNamedSection("\t.sbss", SectionFlags::Writeable | 
+                                      SectionFlags::BSS);
+  } else 
     JumpTableDirective = "\t.gpword\t";
-  
-  SmallDataSection = getNamedSection("\t.sdata", SectionFlags::Writeable);
-  SmallBSSSection  = getNamedSection("\t.sbss",
-                         SectionFlags::Writeable | SectionFlags::BSS);
+
+}
+
+unsigned MipsTargetAsmInfo::
+SectionFlagsForGlobal(const GlobalValue *GV, const char* Name) const {
+  unsigned Flags = ELFTargetAsmInfo::SectionFlagsForGlobal(GV, Name);
+  // Mask out Small Section flag bit, Mips doesnt support 's' section symbol
+  // for its small sections.
+  return (Flags & (~SectionFlags::Small));
 }
 
-SectionKind::Kind
-MipsTargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
+SectionKind::Kind MipsTargetAsmInfo::
+SectionKindForGlobal(const GlobalValue *GV) const {
   SectionKind::Kind K = ELFTargetAsmInfo::SectionKindForGlobal(GV);
 
-  if (K != SectionKind::Data && K != SectionKind::BSS && 
+  if (Subtarget->hasABICall())
+    return K;
+
+  if (K != SectionKind::Data && K != SectionKind::BSS &&
       K != SectionKind::RODataMergeConst)
     return K;
 
   if (isa<GlobalVariable>(GV)) {
     const TargetData *TD = ETM->getTargetData();
     unsigned Size = TD->getABITypeSize(GV->getType()->getElementType());
-    unsigned Threshold = 
-      MipsTM->getSubtarget<MipsSubtarget>().getSSectionThreshold();
-     
+    unsigned Threshold = Subtarget->getSSectionThreshold();
+
     if (Size > 0 && Size <= Threshold) {
       if (K == SectionKind::BSS)
         return SectionKind::SmallBSS;
@@ -70,8 +81,8 @@ MipsTargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
   return K;
 }
 
-const Section*
-MipsTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
+const Section* MipsTargetAsmInfo::
+SelectSectionForGlobal(const GlobalValue *GV) const {
   SectionKind::Kind K = SectionKindForGlobal(GV);
   const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);