1 //===-- XCoreTargetAsmInfo.cpp - XCore asm properties -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
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
|
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
|
37 ReadOnlySection
= getNamedSection("\t.cp.rodata", SectionFlags::None
|
40 Data16bitsDirective
= "\t.short\t";
41 Data32bitsDirective
= "\t.long\t";
42 Data64bitsDirective
= 0;
43 ZeroDirective
= "\t.space\t";
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";
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";
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()) {
78 case SectionKind::RODataMergeStr
:
79 return MergeableStringSection(GVar
);
80 case SectionKind::RODataMergeConst
:
81 return getReadOnlySection();
82 case SectionKind::ThreadData
:
84 case SectionKind::ThreadBSS
:
85 return getBSSSection_();
91 return ELFTargetAsmInfo::SelectSectionForGlobal(GV
);
95 XCoreTargetAsmInfo::SelectSectionForMachineConst(const Type
*Ty
) const {
96 return MergeableConstSection(Ty
);
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
|
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
137 SectionKind::Kind Kind
= SectionKindForGlobal(GV
);
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
;
147 case SectionKind::ROData
:
148 case SectionKind::RODataMergeStr
:
149 case SectionKind::SmallROData
:
150 if (Subtarget
->isXS1A()) {
151 Flags
|= SectionFlags::Writeable
;
153 Flags
|=SectionFlags::Small
;
155 case SectionKind::RODataMergeConst
:
156 Flags
|=SectionFlags::Small
;
165 std::string
XCoreTargetAsmInfo::
166 printSectionFlags(unsigned flags
) const {
167 std::string Flags
= ",\"";
169 if (!(flags
& SectionFlags::Debug
))
171 if (flags
& SectionFlags::Code
)
173 if (flags
& SectionFlags::Writeable
)
175 if (flags
& SectionFlags::Mergeable
)
177 if (flags
& SectionFlags::Strings
)
179 if (flags
& SectionFlags::TLS
)
181 if (flags
& SectionFlags::Small
) {
182 if (flags
& SectionFlags::Writeable
)
183 Flags
+= 'd'; // DP relative
185 Flags
+= 'c'; // CP relative
192 if (flags
& SectionFlags::BSS
)
197 if (unsigned entitySize
= SectionFlags::getEntitySize(flags
))
198 Flags
+= "," + utostr(entitySize
);