1 //===-- DarwinTargetAsmInfo.cpp - Darwin 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 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/Target/DarwinTargetAsmInfo.h"
21 #include "llvm/Target/TargetMachine.h"
22 #include "llvm/Target/TargetData.h"
26 DarwinTargetAsmInfo::DarwinTargetAsmInfo(const TargetMachine &TM) {
29 CStringSection_ = getUnnamedSection("\t.cstring",
30 SectionFlags::Mergeable | SectionFlags::Strings);
31 FourByteConstantSection_ = getUnnamedSection("\t.literal4\n",
32 SectionFlags::Mergeable);
33 EightByteConstantSection_ = getUnnamedSection("\t.literal8\n",
34 SectionFlags::Mergeable);
35 // FIXME: Check for 64 bit
36 SixteenByteConstantSection_ = getUnnamedSection("\t.literal16\n",
37 SectionFlags::Mergeable);
38 ReadOnlySection_ = getUnnamedSection("\t.const\n", SectionFlags::None);
40 // FIXME: These should be named sections, really.
42 getUnnamedSection(".section __TEXT,__textcoal_nt,coalesced,pure_instructions",
44 ConstDataCoalSection =
45 getUnnamedSection(".section __DATA,__const_coal,coalesced",
47 ConstDataSection = getUnnamedSection(".const_data", SectionFlags::None);
48 DataCoalSection = getUnnamedSection(".section __DATA,__datacoal_nt,coalesced",
49 SectionFlags::Writeable);
53 DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
54 SectionKind::Kind Kind = SectionKindForGlobal(GV);
55 bool isWeak = GV->isWeakForLinker();
56 bool isNonStatic = (ETM->getRelocationModel() != Reloc::Static);
59 case SectionKind::Text:
61 return TextCoalSection;
63 return getTextSection_();
64 case SectionKind::Data:
65 case SectionKind::ThreadData:
66 case SectionKind::BSS:
67 case SectionKind::ThreadBSS:
68 if (cast<GlobalVariable>(GV)->isConstant())
69 return (isWeak ? ConstDataCoalSection : ConstDataSection);
71 return (isWeak ? DataCoalSection : getDataSection_());
72 case SectionKind::ROData:
73 return (isWeak ? ConstDataCoalSection :
74 (isNonStatic ? ConstDataSection : getReadOnlySection_()));
75 case SectionKind::RODataMergeStr:
77 ConstDataCoalSection :
78 MergeableStringSection(cast<GlobalVariable>(GV)));
79 case SectionKind::RODataMergeConst:
82 MergeableConstSection(cast<GlobalVariable>(GV)));
84 assert(0 && "Unsuported section kind for global");
87 // FIXME: Do we have any extra special weird cases?
91 DarwinTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
92 const TargetData *TD = ETM->getTargetData();
93 Constant *C = cast<GlobalVariable>(GV)->getInitializer();
94 const Type *Type = cast<ConstantArray>(C)->getType()->getElementType();
96 unsigned Size = TD->getABITypeSize(Type);
98 const TargetData *TD = ETM->getTargetData();
99 unsigned Align = TD->getPreferredAlignment(GV);
101 return getCStringSection_();
104 return getReadOnlySection_();
108 DarwinTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const {
109 const TargetData *TD = ETM->getTargetData();
110 Constant *C = cast<GlobalVariable>(GV)->getInitializer();
112 unsigned Size = TD->getABITypeSize(C->getType());
114 return FourByteConstantSection_;
116 return EightByteConstantSection_;
118 /*else if (Size == 16 && ETM->getSubtarget<X86Subtarget>().is64Bit())
119 return SixteenByteConstantSection_;*/
121 return getReadOnlySection_();
125 DarwinTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
126 SectionKind::Kind kind) const {
127 assert(0 && "Darwin does not use unique sections");