LLVM API Documentation
00001 //===-- XCoreTargetAsmInfo.cpp - XCore asm properties -----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the declarations of the XCoreTargetAsmInfo properties. 00011 // We use the small section flag for the CP relative and DP relative 00012 // flags. If a section is small and writable then it is DP relative. If a 00013 // section is small and not writable then it is CP relative. 00014 // 00015 //===----------------------------------------------------------------------===// 00016 00017 #include "XCoreTargetAsmInfo.h" 00018 #include "XCoreTargetMachine.h" 00019 #include "llvm/GlobalVariable.h" 00020 #include "llvm/ADT/StringExtras.h" 00021 00022 using namespace llvm; 00023 00024 XCoreTargetAsmInfo::XCoreTargetAsmInfo(const XCoreTargetMachine &TM) 00025 : ELFTargetAsmInfo(TM), 00026 Subtarget(TM.getSubtargetImpl()) { 00027 TextSection = getUnnamedSection("\t.text", SectionFlags::Code); 00028 DataSection = getNamedSection("\t.dp.data", SectionFlags::Writeable | 00029 SectionFlags::Small); 00030 BSSSection_ = getNamedSection("\t.dp.bss", SectionFlags::Writeable | 00031 SectionFlags::BSS | SectionFlags::Small); 00032 if (Subtarget->isXS1A()) { 00033 ReadOnlySection = getNamedSection("\t.dp.rodata", SectionFlags::None | 00034 SectionFlags::Writeable | 00035 SectionFlags::Small); 00036 } else { 00037 ReadOnlySection = getNamedSection("\t.cp.rodata", SectionFlags::None | 00038 SectionFlags::Small); 00039 } 00040 Data16bitsDirective = "\t.short\t"; 00041 Data32bitsDirective = "\t.long\t"; 00042 Data64bitsDirective = 0; 00043 ZeroDirective = "\t.space\t"; 00044 CommentString = "#"; 00045 ConstantPoolSection = "\t.section\t.cp.rodata,\"ac\",@progbits"; 00046 JumpTableDataSection = "\t.section\t.dp.data,\"awd\",@progbits"; 00047 PrivateGlobalPrefix = ".L"; 00048 AscizDirective = ".asciiz"; 00049 WeakDefDirective = "\t.weak\t"; 00050 WeakRefDirective = "\t.weak\t"; 00051 SetDirective = "\t.set\t"; 00052 00053 // Debug 00054 HasLEB128 = true; 00055 AbsoluteDebugSectionOffsets = true; 00056 00057 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits"; 00058 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits"; 00059 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits"; 00060 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits"; 00061 DwarfPubNamesSection = "\t.section\t.debug_pubnames,\"\",@progbits"; 00062 DwarfPubTypesSection = "\t.section\t.debug_pubtypes,\"\",@progbits"; 00063 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits"; 00064 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits"; 00065 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits"; 00066 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits"; 00067 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits"; 00068 } 00069 00070 const Section* 00071 XCoreTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { 00072 SectionKind::Kind Kind = SectionKindForGlobal(GV); 00073 00074 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) 00075 { 00076 if (!GVar->mayBeOverridden()) { 00077 switch (Kind) { 00078 case SectionKind::RODataMergeStr: 00079 return MergeableStringSection(GVar); 00080 case SectionKind::RODataMergeConst: 00081 return getReadOnlySection(); 00082 case SectionKind::ThreadData: 00083 return DataSection; 00084 case SectionKind::ThreadBSS: 00085 return getBSSSection_(); 00086 default: 00087 break; 00088 } 00089 } 00090 } 00091 return ELFTargetAsmInfo::SelectSectionForGlobal(GV); 00092 } 00093 00094 const Section* 00095 XCoreTargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const { 00096 return MergeableConstSection(Ty); 00097 } 00098 00099 const Section* 00100 XCoreTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const { 00101 Constant *C = GV->getInitializer(); 00102 return MergeableConstSection(C->getType()); 00103 } 00104 00105 inline const Section* 00106 XCoreTargetAsmInfo::MergeableConstSection(const Type *Ty) const { 00107 const TargetData *TD = TM.getTargetData(); 00108 00109 unsigned Size = TD->getTypePaddedSize(Ty); 00110 if (Size == 4 || Size == 8 || Size == 16) { 00111 std::string Name = ".cp.const" + utostr(Size); 00112 00113 return getNamedSection(Name.c_str(), 00114 SectionFlags::setEntitySize(SectionFlags::Mergeable | 00115 SectionFlags::Small, 00116 Size)); 00117 } 00118 00119 return getReadOnlySection(); 00120 } 00121 00122 const Section* XCoreTargetAsmInfo:: 00123 MergeableStringSection(const GlobalVariable *GV) const { 00124 // FIXME insert in correct mergable section 00125 return getReadOnlySection(); 00126 } 00127 00128 unsigned XCoreTargetAsmInfo:: 00129 SectionFlagsForGlobal(const GlobalValue *GV, 00130 const char* Name) const { 00131 unsigned Flags = ELFTargetAsmInfo::SectionFlagsForGlobal(GV, Name); 00132 // Mask out unsupported flags 00133 Flags &= ~(SectionFlags::Small | SectionFlags::TLS); 00134 00135 // Set CP / DP relative flags 00136 if (GV) { 00137 SectionKind::Kind Kind = SectionKindForGlobal(GV); 00138 switch (Kind) { 00139 case SectionKind::ThreadData: 00140 case SectionKind::ThreadBSS: 00141 case SectionKind::Data: 00142 case SectionKind::BSS: 00143 case SectionKind::SmallData: 00144 case SectionKind::SmallBSS: 00145 Flags |= SectionFlags::Small; 00146 break; 00147 case SectionKind::ROData: 00148 case SectionKind::RODataMergeStr: 00149 case SectionKind::SmallROData: 00150 if (Subtarget->isXS1A()) { 00151 Flags |= SectionFlags::Writeable; 00152 } 00153 Flags |=SectionFlags::Small; 00154 break; 00155 case SectionKind::RODataMergeConst: 00156 Flags |=SectionFlags::Small; 00157 default: 00158 break; 00159 } 00160 } 00161 00162 return Flags; 00163 } 00164 00165 std::string XCoreTargetAsmInfo:: 00166 printSectionFlags(unsigned flags) const { 00167 std::string Flags = ",\""; 00168 00169 if (!(flags & SectionFlags::Debug)) 00170 Flags += 'a'; 00171 if (flags & SectionFlags::Code) 00172 Flags += 'x'; 00173 if (flags & SectionFlags::Writeable) 00174 Flags += 'w'; 00175 if (flags & SectionFlags::Mergeable) 00176 Flags += 'M'; 00177 if (flags & SectionFlags::Strings) 00178 Flags += 'S'; 00179 if (flags & SectionFlags::TLS) 00180 Flags += 'T'; 00181 if (flags & SectionFlags::Small) { 00182 if (flags & SectionFlags::Writeable) 00183 Flags += 'd'; // DP relative 00184 else 00185 Flags += 'c'; // CP relative 00186 } 00187 00188 Flags += "\","; 00189 00190 Flags += '@'; 00191 00192 if (flags & SectionFlags::BSS) 00193 Flags += "nobits"; 00194 else 00195 Flags += "progbits"; 00196 00197 if (unsigned entitySize = SectionFlags::getEntitySize(flags)) 00198 Flags += "," + utostr(entitySize); 00199 00200 return Flags; 00201 }