blob: f8a14c66da12a742c5db0d8e570615737200278e [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- MipsTargetAsmInfo.cpp - Mips asm properties -------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the declarations of the MipsTargetAsmInfo properties.
11//
12//===----------------------------------------------------------------------===//
13
14#include "MipsTargetAsmInfo.h"
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +000015#include "MipsTargetMachine.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000016
17using namespace llvm;
18
asldedcd842008-07-19 13:16:11 +000019MipsTargetAsmInfo::MipsTargetAsmInfo(const MipsTargetMachine &TM):
20 ELFTargetAsmInfo(TM) {
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +000021
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +000022 Subtarget = &TM.getSubtarget<MipsSubtarget>();
Bruno Cardoso Lopes8291a622008-07-22 15:34:27 +000023
Bruno Cardoso Lopes29c15352008-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";
Bruno Cardoso Lopes12355a82008-07-21 18:52:34 +000035 CStringSection = ".rodata.str";
Bruno Cardoso Lopes8642dfd2008-07-28 19:11:24 +000036 FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +000037
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +000038 if (!Subtarget->hasABICall()) {
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +000039 JumpTableDirective = "\t.word\t";
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +000040 SmallDataSection = getNamedSection("\t.sdata", SectionFlags::Writeable);
41 SmallBSSSection = getNamedSection("\t.sbss", SectionFlags::Writeable |
42 SectionFlags::BSS);
43 } else
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +000044 JumpTableDirective = "\t.gpword\t";
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +000045
Bruno Cardoso Lopes8291a622008-07-22 15:34:27 +000046}
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +000047
Bruno Cardoso Lopes8291a622008-07-22 15:34:27 +000048SectionKind::Kind
49MipsTargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
Bruno Cardoso Lopes33724392008-07-22 16:24:21 +000050 SectionKind::Kind K = ELFTargetAsmInfo::SectionKindForGlobal(GV);
Bruno Cardoso Lopes8291a622008-07-22 15:34:27 +000051
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +000052 if (Subtarget->hasABICall())
53 return K;
54
Bruno Cardoso Lopes33724392008-07-22 16:24:21 +000055 if (K != SectionKind::Data && K != SectionKind::BSS &&
56 K != SectionKind::RODataMergeConst)
57 return K;
58
59 if (isa<GlobalVariable>(GV)) {
60 const TargetData *TD = ETM->getTargetData();
61 unsigned Size = TD->getABITypeSize(GV->getType()->getElementType());
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +000062 unsigned Threshold = Subtarget->getSSectionThreshold();
Bruno Cardoso Lopes33724392008-07-22 16:24:21 +000063
64 if (Size > 0 && Size <= Threshold) {
65 if (K == SectionKind::BSS)
66 return SectionKind::SmallBSS;
67 else
68 return SectionKind::SmallData;
69 }
Bruno Cardoso Lopes8291a622008-07-22 15:34:27 +000070 }
71
Bruno Cardoso Lopes33724392008-07-22 16:24:21 +000072 return K;
Bruno Cardoso Lopes8291a622008-07-22 15:34:27 +000073}
74
75const Section*
76MipsTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
77 SectionKind::Kind K = SectionKindForGlobal(GV);
78 const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
79
80 if (GVA && (!GVA->isWeakForLinker()))
81 switch (K) {
82 case SectionKind::SmallData:
83 return getSmallDataSection();
84 case SectionKind::SmallBSS:
85 return getSmallBSSSection();
86 default: break;
87 }
88
89 return ELFTargetAsmInfo::SelectSectionForGlobal(GV);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000090}