blob: d1fadc0e7359c8a51500c8790272e6c145acf039 [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";
35 LCOMMDirective = "\t.lcomm\t";
Bruno Cardoso Lopes12355a82008-07-21 18:52:34 +000036 CStringSection = ".rodata.str";
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +000037 FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +000038
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +000039 if (!Subtarget->hasABICall()) {
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +000040 JumpTableDirective = "\t.word\t";
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +000041 SmallDataSection = getNamedSection("\t.sdata", SectionFlags::Writeable);
42 SmallBSSSection = getNamedSection("\t.sbss", SectionFlags::Writeable |
43 SectionFlags::BSS);
44 } else
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +000045 JumpTableDirective = "\t.gpword\t";
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +000046
Bruno Cardoso Lopes8291a622008-07-22 15:34:27 +000047}
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +000048
Bruno Cardoso Lopes8291a622008-07-22 15:34:27 +000049SectionKind::Kind
50MipsTargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
Bruno Cardoso Lopes33724392008-07-22 16:24:21 +000051 SectionKind::Kind K = ELFTargetAsmInfo::SectionKindForGlobal(GV);
Bruno Cardoso Lopes8291a622008-07-22 15:34:27 +000052
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +000053 if (Subtarget->hasABICall())
54 return K;
55
Bruno Cardoso Lopes33724392008-07-22 16:24:21 +000056 if (K != SectionKind::Data && K != SectionKind::BSS &&
57 K != SectionKind::RODataMergeConst)
58 return K;
59
60 if (isa<GlobalVariable>(GV)) {
61 const TargetData *TD = ETM->getTargetData();
62 unsigned Size = TD->getABITypeSize(GV->getType()->getElementType());
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +000063 unsigned Threshold = Subtarget->getSSectionThreshold();
Bruno Cardoso Lopes33724392008-07-22 16:24:21 +000064
65 if (Size > 0 && Size <= Threshold) {
66 if (K == SectionKind::BSS)
67 return SectionKind::SmallBSS;
68 else
69 return SectionKind::SmallData;
70 }
Bruno Cardoso Lopes8291a622008-07-22 15:34:27 +000071 }
72
Bruno Cardoso Lopes33724392008-07-22 16:24:21 +000073 return K;
Bruno Cardoso Lopes8291a622008-07-22 15:34:27 +000074}
75
76const Section*
77MipsTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
78 SectionKind::Kind K = SectionKindForGlobal(GV);
79 const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
80
81 if (GVA && (!GVA->isWeakForLinker()))
82 switch (K) {
83 case SectionKind::SmallData:
84 return getSmallDataSection();
85 case SectionKind::SmallBSS:
86 return getSmallBSSSection();
87 default: break;
88 }
89
90 return ELFTargetAsmInfo::SelectSectionForGlobal(GV);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000091}