blob: 78b5c4aee0e6025884d2ab14431034b5bdb6d259 [file] [log] [blame]
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001//===-- MipsTargetAsmInfo.cpp - Mips asm properties -------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the declarations of the MipsTargetAsmInfo properties.
11//
12//===----------------------------------------------------------------------===//
13
14#include "MipsTargetAsmInfo.h"
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000015#include "MipsTargetMachine.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000016
17using namespace llvm;
18
Anton Korobeynikovae408e62008-07-19 13:16:11 +000019MipsTargetAsmInfo::MipsTargetAsmInfo(const MipsTargetMachine &TM):
20 ELFTargetAsmInfo(TM) {
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +000021
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000022 MipsTM = &TM;
23
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +000024 AlignmentIsInBytes = false;
25 COMMDirectiveTakesAlignment = true;
26 Data16bitsDirective = "\t.half\t";
27 Data32bitsDirective = "\t.word\t";
28 Data64bitsDirective = NULL;
29 PrivateGlobalPrefix = "$";
30 JumpTableDataSection = "\t.rdata";
31 CommentString = "#";
32 ReadOnlySection = "\t.rdata";
33 ZeroDirective = "\t.space\t";
34 BSSSection = "\t.section\t.bss";
35 LCOMMDirective = "\t.lcomm\t";
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000036 CStringSection = ".rodata.str";
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000037
Bruno Cardoso Lopesb27cb552008-07-15 02:03:36 +000038 if (!TM.getSubtarget<MipsSubtarget>().hasABICall())
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000039 JumpTableDirective = "\t.word\t";
Anton Korobeynikovae408e62008-07-19 13:16:11 +000040 else
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000041 JumpTableDirective = "\t.gpword\t";
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000042
43 SmallDataSection = getNamedSection("\t.sdata", SectionFlags::Writeable);
44 SmallBSSSection = getNamedSection("\t.sbss",
45 SectionFlags::Writeable | SectionFlags::BSS);
46}
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000047
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000048SectionKind::Kind
49MipsTargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000050 SectionKind::Kind K = ELFTargetAsmInfo::SectionKindForGlobal(GV);
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000051
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000052 if (K != SectionKind::Data && K != SectionKind::BSS &&
53 K != SectionKind::RODataMergeConst)
54 return K;
55
56 if (isa<GlobalVariable>(GV)) {
57 const TargetData *TD = ETM->getTargetData();
58 unsigned Size = TD->getABITypeSize(GV->getType()->getElementType());
59 unsigned Threshold =
60 MipsTM->getSubtarget<MipsSubtarget>().getSSectionThreshold();
61
62 if (Size > 0 && Size <= Threshold) {
63 if (K == SectionKind::BSS)
64 return SectionKind::SmallBSS;
65 else
66 return SectionKind::SmallData;
67 }
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000068 }
69
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000070 return K;
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000071}
72
73const Section*
74MipsTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
75 SectionKind::Kind K = SectionKindForGlobal(GV);
76 const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
77
78 if (GVA && (!GVA->isWeakForLinker()))
79 switch (K) {
80 case SectionKind::SmallData:
81 return getSmallDataSection();
82 case SectionKind::SmallBSS:
83 return getSmallBSSSection();
84 default: break;
85 }
86
87 return ELFTargetAsmInfo::SelectSectionForGlobal(GV);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000088}