Remove some overridden functions in XCoreTargetAsmInfo that are
[oota-llvm.git] / lib / Target / XCore / XCoreTargetAsmInfo.cpp
1 //===-- XCoreTargetAsmInfo.cpp - XCore 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 XCoreTargetAsmInfo properties.
11 // We use the small section flag for the CP relative and DP relative
12 // flags. If a section is small and writable then it is DP relative. If a
13 // section is small and not writable then it is CP relative.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #include "XCoreTargetAsmInfo.h"
18 #include "XCoreTargetMachine.h"
19 #include "llvm/GlobalVariable.h"
20 #include "llvm/ADT/StringExtras.h"
21
22 using namespace llvm;
23
24 XCoreTargetAsmInfo::XCoreTargetAsmInfo(const XCoreTargetMachine &TM)
25   : ELFTargetAsmInfo(TM),
26     Subtarget(TM.getSubtargetImpl()) {
27   SupportsDebugInformation = true;
28   TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
29   DataSection = getNamedSection("\t.dp.data", SectionFlags::Writeable |
30                                 SectionFlags::Small);
31   BSSSection_  = getNamedSection("\t.dp.bss", SectionFlags::Writeable |
32                                  SectionFlags::BSS | SectionFlags::Small);
33   if (Subtarget->isXS1A()) {
34     ReadOnlySection = getNamedSection("\t.dp.rodata", SectionFlags::None |
35                                       SectionFlags::Writeable |
36                                       SectionFlags::Small);
37   } else {
38     ReadOnlySection = getNamedSection("\t.cp.rodata", SectionFlags::None |
39                                       SectionFlags::Small);
40   }
41   Data16bitsDirective = "\t.short\t";
42   Data32bitsDirective = "\t.long\t";
43   Data64bitsDirective = 0;
44   ZeroDirective = "\t.space\t";
45   CommentString = "#";
46   ConstantPoolSection = "\t.section\t.cp.rodata,\"ac\",@progbits";
47   JumpTableDataSection = "\t.section\t.dp.data,\"awd\",@progbits";
48   PrivateGlobalPrefix = ".L";
49   AscizDirective = ".asciiz";
50   WeakDefDirective = "\t.weak\t";
51   WeakRefDirective = "\t.weak\t";
52   SetDirective = "\t.set\t";
53
54   // Debug
55   HasLEB128 = true;
56   AbsoluteDebugSectionOffsets = true;
57   
58   DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
59   DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
60   DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
61   DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
62   DwarfPubNamesSection = "\t.section\t.debug_pubnames,\"\",@progbits";
63   DwarfPubTypesSection = "\t.section\t.debug_pubtypes,\"\",@progbits";
64   DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
65   DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
66   DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
67   DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
68   DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
69 }
70
71 const Section*
72 XCoreTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
73   SectionKind::Kind Kind = SectionKindForGlobal(GV);
74
75   if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
76     if (!GVar->isWeakForLinker()) {
77       switch (Kind) {
78       case SectionKind::RODataMergeConst:
79         return getReadOnlySection();
80       case SectionKind::ThreadData:
81         return DataSection;
82       case SectionKind::ThreadBSS:
83         return getBSSSection_();
84       default:
85         break;
86       }
87     }
88   }
89   return ELFTargetAsmInfo::SelectSectionForGlobal(GV);
90 }
91
92 const Section*
93 XCoreTargetAsmInfo::MergeableConstSection(const Type *Ty) const {
94   const TargetData *TD = TM.getTargetData();
95
96   unsigned Size = TD->getTypeAllocSize(Ty);
97   if (Size == 4 || Size == 8 || Size == 16) {
98     std::string Name =  ".cp.const" + utostr(Size);
99
100     return getNamedSection(Name.c_str(),
101                            SectionFlags::setEntitySize(SectionFlags::Mergeable |
102                                                        SectionFlags::Small,
103                                                        Size));
104   }
105
106   return getReadOnlySection();
107 }
108
109 unsigned XCoreTargetAsmInfo::
110 SectionFlagsForGlobal(const GlobalValue *GV, const char* Name) const {
111   unsigned Flags = ELFTargetAsmInfo::SectionFlagsForGlobal(GV, Name);
112   // Mask out unsupported flags
113   Flags &= ~(SectionFlags::Small | SectionFlags::TLS);
114
115   // Set CP / DP relative flags
116   if (GV) {
117     SectionKind::Kind Kind = SectionKindForGlobal(GV);
118     switch (Kind) {
119     case SectionKind::ThreadData:
120     case SectionKind::ThreadBSS:
121     case SectionKind::Data:
122     case SectionKind::BSS:
123     case SectionKind::SmallData:
124     case SectionKind::SmallBSS:
125       Flags |= SectionFlags::Small;
126       break;
127     case SectionKind::ROData:
128     case SectionKind::RODataMergeStr:
129     case SectionKind::SmallROData:
130       if (Subtarget->isXS1A()) {
131         Flags |= SectionFlags::Writeable;
132       }
133       Flags |=SectionFlags::Small;
134       break;
135     case SectionKind::RODataMergeConst:
136       Flags |=SectionFlags::Small;
137     default:
138       break;
139     }
140   }
141
142   return Flags;
143 }