Unbreak
[llvm/systemz.git] / lib / Target / DarwinTargetAsmInfo.cpp
blob7ab3967c0d1bf2bd0c006d223ce927ac402a78ee
1 //===-- DarwinTargetAsmInfo.cpp - Darwin 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 defines target asm properties related what form asm statements
11 // should take in general on Darwin-based targets
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Constants.h"
16 #include "llvm/DerivedTypes.h"
17 #include "llvm/Function.h"
18 #include "llvm/GlobalVariable.h"
19 #include "llvm/ADT/StringExtras.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/Mangler.h"
22 #include "llvm/Target/DarwinTargetAsmInfo.h"
23 #include "llvm/Target/TargetMachine.h"
24 #include "llvm/Target/TargetData.h"
26 using namespace llvm;
28 DarwinTargetAsmInfo::DarwinTargetAsmInfo(const TargetMachine &TM)
29 : TargetAsmInfo(TM) {
31 CStringSection_ = getUnnamedSection("\t.cstring",
32 SectionFlags::Mergeable | SectionFlags::Strings);
33 FourByteConstantSection = getUnnamedSection("\t.literal4\n",
34 SectionFlags::Mergeable);
35 EightByteConstantSection = getUnnamedSection("\t.literal8\n",
36 SectionFlags::Mergeable);
38 // Note: 16-byte constant section is subtarget specific and should be provided
39 // there, if needed.
40 SixteenByteConstantSection = 0;
42 ReadOnlySection = getUnnamedSection("\t.const\n", SectionFlags::None);
44 TextCoalSection =
45 getNamedSection("\t__TEXT,__textcoal_nt,coalesced,pure_instructions",
46 SectionFlags::Code);
47 ConstTextCoalSection = getNamedSection("\t__TEXT,__const_coal,coalesced",
48 SectionFlags::None);
49 ConstDataCoalSection = getNamedSection("\t__DATA,__const_coal,coalesced",
50 SectionFlags::None);
51 ConstDataSection = getUnnamedSection(".const_data", SectionFlags::None);
52 DataCoalSection = getNamedSection("\t__DATA,__datacoal_nt,coalesced",
53 SectionFlags::Writeable);
56 // Common settings for all Darwin targets.
57 // Syntax:
58 GlobalPrefix = "_";
59 PrivateGlobalPrefix = "L";
60 LessPrivateGlobalPrefix = "l"; // Marker for some ObjC metadata
61 NeedsSet = true;
62 NeedsIndirectEncoding = true;
63 AllowQuotesInName = true;
64 HasSingleParameterDotFile = false;
66 // In non-PIC modes, emit a special label before jump tables so that the
67 // linker can perform more accurate dead code stripping. We do not check the
68 // relocation model here since it can be overridden later.
69 JumpTableSpecialLabelPrefix = "l";
71 // Directives:
72 WeakDefDirective = "\t.weak_definition ";
73 WeakRefDirective = "\t.weak_reference ";
74 HiddenDirective = "\t.private_extern ";
76 // Sections:
77 CStringSection = "\t.cstring";
78 JumpTableDataSection = "\t.const\n";
79 BSSSection = 0;
81 if (TM.getRelocationModel() == Reloc::Static) {
82 StaticCtorsSection = ".constructor";
83 StaticDtorsSection = ".destructor";
84 } else {
85 StaticCtorsSection = ".mod_init_func";
86 StaticDtorsSection = ".mod_term_func";
89 DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
90 DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
91 DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
92 DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
93 DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
94 DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
95 DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
96 DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
97 DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
98 DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
99 DwarfMacroInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
102 /// emitUsedDirectiveFor - On Darwin, internally linked data beginning with
103 /// the PrivateGlobalPrefix or the LessPrivateGlobalPrefix does not have the
104 /// directive emitted (this occurs in ObjC metadata).
105 bool
106 DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV,
107 Mangler *Mang) const {
108 if (GV==0)
109 return false;
111 /// FIXME: WHAT IS THIS?
113 if (GV->hasLocalLinkage() && !isa<Function>(GV) &&
114 ((strlen(getPrivateGlobalPrefix()) != 0 &&
115 Mang->getMangledName(GV).substr(0,strlen(getPrivateGlobalPrefix())) ==
116 getPrivateGlobalPrefix()) ||
117 (strlen(getLessPrivateGlobalPrefix()) != 0 &&
118 Mang->getMangledName(GV).substr(0,
119 strlen(getLessPrivateGlobalPrefix())) ==
120 getLessPrivateGlobalPrefix())))
121 return false;
122 return true;
125 const Section*
126 DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
127 SectionKind::Kind Kind = SectionKindForGlobal(GV);
128 bool isWeak = GV->isWeakForLinker();
129 bool isNonStatic = TM.getRelocationModel() != Reloc::Static;
131 switch (Kind) {
132 case SectionKind::Text:
133 if (isWeak)
134 return TextCoalSection;
135 else
136 return TextSection;
137 case SectionKind::Data:
138 case SectionKind::ThreadData:
139 case SectionKind::BSS:
140 case SectionKind::ThreadBSS:
141 if (cast<GlobalVariable>(GV)->isConstant())
142 return (isWeak ? ConstDataCoalSection : ConstDataSection);
143 else
144 return (isWeak ? DataCoalSection : DataSection);
145 case SectionKind::ROData:
146 return (isWeak ? ConstDataCoalSection :
147 (isNonStatic ? ConstDataSection : getReadOnlySection()));
148 case SectionKind::RODataMergeStr:
149 return (isWeak ?
150 ConstTextCoalSection :
151 MergeableStringSection(cast<GlobalVariable>(GV)));
152 case SectionKind::RODataMergeConst:
153 return (isWeak ?
154 ConstDataCoalSection:
155 MergeableConstSection(cast<GlobalVariable>(GV)));
156 default:
157 llvm_unreachable("Unsuported section kind for global");
160 // FIXME: Do we have any extra special weird cases?
161 return NULL;
164 const Section*
165 DarwinTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
166 const TargetData *TD = TM.getTargetData();
167 Constant *C = cast<GlobalVariable>(GV)->getInitializer();
168 const Type *Ty = cast<ArrayType>(C->getType())->getElementType();
170 unsigned Size = TD->getTypeAllocSize(Ty);
171 if (Size) {
172 unsigned Align = TD->getPreferredAlignment(GV);
173 if (Align <= 32)
174 return getCStringSection_();
177 return getReadOnlySection();
180 const Section*
181 DarwinTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const {
182 Constant *C = GV->getInitializer();
184 return MergeableConstSection(C->getType());
187 inline const Section*
188 DarwinTargetAsmInfo::MergeableConstSection(const Type *Ty) const {
189 const TargetData *TD = TM.getTargetData();
191 unsigned Size = TD->getTypeAllocSize(Ty);
192 if (Size == 4)
193 return FourByteConstantSection;
194 else if (Size == 8)
195 return EightByteConstantSection;
196 else if (Size == 16 && SixteenByteConstantSection)
197 return SixteenByteConstantSection;
199 return getReadOnlySection();
202 const Section*
203 DarwinTargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
204 const Section* S = MergeableConstSection(Ty);
206 // Handle weird special case, when compiling PIC stuff.
207 if (S == getReadOnlySection() &&
208 TM.getRelocationModel() != Reloc::Static)
209 return ConstDataSection;
211 return S;
214 std::string
215 DarwinTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
216 SectionKind::Kind kind) const {
217 llvm_unreachable("Darwin does not use unique sections");
218 return "";