Merge branch 'master' into msp430
[llvm/msp430.git] / lib / Target / XCore / XCoreTargetAsmInfo.cpp
blob55137621deaed64cd868b2f88e84019cb9b0c3bc
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.
15 //===----------------------------------------------------------------------===//
17 #include "XCoreTargetAsmInfo.h"
18 #include "XCoreTargetMachine.h"
19 #include "llvm/GlobalVariable.h"
20 #include "llvm/ADT/StringExtras.h"
22 using namespace llvm;
24 XCoreTargetAsmInfo::XCoreTargetAsmInfo(const XCoreTargetMachine &TM)
25 : ELFTargetAsmInfo(TM),
26 Subtarget(TM.getSubtargetImpl()) {
27 TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
28 DataSection = getNamedSection("\t.dp.data", SectionFlags::Writeable |
29 SectionFlags::Small);
30 BSSSection_ = getNamedSection("\t.dp.bss", SectionFlags::Writeable |
31 SectionFlags::BSS | SectionFlags::Small);
32 if (Subtarget->isXS1A()) {
33 ReadOnlySection = getNamedSection("\t.dp.rodata", SectionFlags::None |
34 SectionFlags::Writeable |
35 SectionFlags::Small);
36 } else {
37 ReadOnlySection = getNamedSection("\t.cp.rodata", SectionFlags::None |
38 SectionFlags::Small);
40 Data16bitsDirective = "\t.short\t";
41 Data32bitsDirective = "\t.long\t";
42 Data64bitsDirective = 0;
43 ZeroDirective = "\t.space\t";
44 CommentString = "#";
45 ConstantPoolSection = "\t.section\t.cp.rodata,\"ac\",@progbits";
46 JumpTableDataSection = "\t.section\t.dp.data,\"awd\",@progbits";
47 PrivateGlobalPrefix = ".L";
48 AscizDirective = ".asciiz";
49 WeakDefDirective = "\t.weak\t";
50 WeakRefDirective = "\t.weak\t";
51 SetDirective = "\t.set\t";
53 // Debug
54 HasLEB128 = true;
55 AbsoluteDebugSectionOffsets = true;
57 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
58 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
59 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
60 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
61 DwarfPubNamesSection = "\t.section\t.debug_pubnames,\"\",@progbits";
62 DwarfPubTypesSection = "\t.section\t.debug_pubtypes,\"\",@progbits";
63 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
64 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
65 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
66 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
67 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
70 const Section*
71 XCoreTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
72 SectionKind::Kind Kind = SectionKindForGlobal(GV);
74 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
76 if (!GVar->isWeakForLinker()) {
77 switch (Kind) {
78 case SectionKind::RODataMergeStr:
79 return MergeableStringSection(GVar);
80 case SectionKind::RODataMergeConst:
81 return getReadOnlySection();
82 case SectionKind::ThreadData:
83 return DataSection;
84 case SectionKind::ThreadBSS:
85 return getBSSSection_();
86 default:
87 break;
91 return ELFTargetAsmInfo::SelectSectionForGlobal(GV);
94 const Section*
95 XCoreTargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
96 return MergeableConstSection(Ty);
99 const Section*
100 XCoreTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const {
101 Constant *C = GV->getInitializer();
102 return MergeableConstSection(C->getType());
105 inline const Section*
106 XCoreTargetAsmInfo::MergeableConstSection(const Type *Ty) const {
107 const TargetData *TD = TM.getTargetData();
109 unsigned Size = TD->getTypeAllocSize(Ty);
110 if (Size == 4 || Size == 8 || Size == 16) {
111 std::string Name = ".cp.const" + utostr(Size);
113 return getNamedSection(Name.c_str(),
114 SectionFlags::setEntitySize(SectionFlags::Mergeable |
115 SectionFlags::Small,
116 Size));
119 return getReadOnlySection();
122 const Section* XCoreTargetAsmInfo::
123 MergeableStringSection(const GlobalVariable *GV) const {
124 // FIXME insert in correct mergable section
125 return getReadOnlySection();
128 unsigned XCoreTargetAsmInfo::
129 SectionFlagsForGlobal(const GlobalValue *GV,
130 const char* Name) const {
131 unsigned Flags = ELFTargetAsmInfo::SectionFlagsForGlobal(GV, Name);
132 // Mask out unsupported flags
133 Flags &= ~(SectionFlags::Small | SectionFlags::TLS);
135 // Set CP / DP relative flags
136 if (GV) {
137 SectionKind::Kind Kind = SectionKindForGlobal(GV);
138 switch (Kind) {
139 case SectionKind::ThreadData:
140 case SectionKind::ThreadBSS:
141 case SectionKind::Data:
142 case SectionKind::BSS:
143 case SectionKind::SmallData:
144 case SectionKind::SmallBSS:
145 Flags |= SectionFlags::Small;
146 break;
147 case SectionKind::ROData:
148 case SectionKind::RODataMergeStr:
149 case SectionKind::SmallROData:
150 if (Subtarget->isXS1A()) {
151 Flags |= SectionFlags::Writeable;
153 Flags |=SectionFlags::Small;
154 break;
155 case SectionKind::RODataMergeConst:
156 Flags |=SectionFlags::Small;
157 default:
158 break;
162 return Flags;
165 std::string XCoreTargetAsmInfo::
166 printSectionFlags(unsigned flags) const {
167 std::string Flags = ",\"";
169 if (!(flags & SectionFlags::Debug))
170 Flags += 'a';
171 if (flags & SectionFlags::Code)
172 Flags += 'x';
173 if (flags & SectionFlags::Writeable)
174 Flags += 'w';
175 if (flags & SectionFlags::Mergeable)
176 Flags += 'M';
177 if (flags & SectionFlags::Strings)
178 Flags += 'S';
179 if (flags & SectionFlags::TLS)
180 Flags += 'T';
181 if (flags & SectionFlags::Small) {
182 if (flags & SectionFlags::Writeable)
183 Flags += 'd'; // DP relative
184 else
185 Flags += 'c'; // CP relative
188 Flags += "\",";
190 Flags += '@';
192 if (flags & SectionFlags::BSS)
193 Flags += "nobits";
194 else
195 Flags += "progbits";
197 if (unsigned entitySize = SectionFlags::getEntitySize(flags))
198 Flags += "," + utostr(entitySize);
200 return Flags;