simplified small section logic
[oota-llvm.git] / lib / Target / Mips / MipsTargetAsmInfo.cpp
1 //===-- MipsTargetAsmInfo.cpp - Mips asm properties -------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declarations of the MipsTargetAsmInfo properties.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "MipsTargetAsmInfo.h"
15 #include "MipsTargetMachine.h"
16
17 using namespace llvm;
18
19 MipsTargetAsmInfo::MipsTargetAsmInfo(const MipsTargetMachine &TM):
20   ELFTargetAsmInfo(TM) {
21
22   MipsTM = &TM;
23
24   AlignmentIsInBytes          = false;
25   COMMDirectiveTakesAlignment = true;
26   Data16bitsDirective         = "\t.half\t";
27   Data32bitsDirective         = "\t.word\t";
28   Data64bitsDirective         = NULL;
29   PrivateGlobalPrefix         = "$";
30   JumpTableDataSection        = "\t.rdata";
31   CommentString               = "#";
32   ReadOnlySection             = "\t.rdata";
33   ZeroDirective               = "\t.space\t";
34   BSSSection                  = "\t.section\t.bss";
35   LCOMMDirective              = "\t.lcomm\t";
36   CStringSection              = ".rodata.str";
37
38   if (!TM.getSubtarget<MipsSubtarget>().hasABICall())
39     JumpTableDirective = "\t.word\t";
40   else
41     JumpTableDirective = "\t.gpword\t";
42   
43   SmallDataSection = getNamedSection("\t.sdata", SectionFlags::Writeable);
44   SmallBSSSection  = getNamedSection("\t.sbss",
45                          SectionFlags::Writeable | SectionFlags::BSS);
46 }
47
48 SectionKind::Kind
49 MipsTargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
50   SectionKind::Kind K = ELFTargetAsmInfo::SectionKindForGlobal(GV);
51
52   if (K != SectionKind::Data && K != SectionKind::BSS && 
53       K != SectionKind::RODataMergeConst)
54     return K;
55
56   if (isa<GlobalVariable>(GV)) {
57     const TargetData *TD = ETM->getTargetData();
58     unsigned Size = TD->getABITypeSize(GV->getType()->getElementType());
59     unsigned Threshold = 
60       MipsTM->getSubtarget<MipsSubtarget>().getSSectionThreshold();
61      
62     if (Size > 0 && Size <= Threshold) {
63       if (K == SectionKind::BSS)
64         return SectionKind::SmallBSS;
65       else
66         return SectionKind::SmallData;
67     }
68   }
69
70   return K;
71 }
72
73 const Section*
74 MipsTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
75   SectionKind::Kind K = SectionKindForGlobal(GV);
76   const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
77
78   if (GVA && (!GVA->isWeakForLinker()))
79     switch (K) {
80       case SectionKind::SmallData:
81         return getSmallDataSection();
82       case SectionKind::SmallBSS:
83         return getSmallBSSSection();
84       default: break;
85     }
86
87   return ELFTargetAsmInfo::SelectSectionForGlobal(GV);
88 }