blob: 04edd0d4b537c8031f08910dbae4ab9e922f2a71 [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"
Dan Gohman8f613f32008-08-05 15:32:23 +000016#include "llvm/GlobalVariable.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000017
18using namespace llvm;
19
Anton Korobeynikovae408e62008-07-19 13:16:11 +000020MipsTargetAsmInfo::MipsTargetAsmInfo(const MipsTargetMachine &TM):
21 ELFTargetAsmInfo(TM) {
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +000022
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000023 Subtarget = &TM.getSubtarget<MipsSubtarget>();
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000024
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +000025 AlignmentIsInBytes = false;
26 COMMDirectiveTakesAlignment = true;
27 Data16bitsDirective = "\t.half\t";
28 Data32bitsDirective = "\t.word\t";
29 Data64bitsDirective = NULL;
30 PrivateGlobalPrefix = "$";
31 JumpTableDataSection = "\t.rdata";
32 CommentString = "#";
33 ReadOnlySection = "\t.rdata";
34 ZeroDirective = "\t.space\t";
35 BSSSection = "\t.section\t.bss";
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000036 CStringSection = ".rodata.str";
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +000037 FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000038
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000039 if (!Subtarget->hasABICall()) {
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000040 JumpTableDirective = "\t.word\t";
Bruno Cardoso Lopes92e87f22008-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 Lopes753a9872007-11-12 19:49:57 +000045 JumpTableDirective = "\t.gpword\t";
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000046
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000047}
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000048
Bruno Cardoso Lopesea7930e2008-07-30 17:04:04 +000049unsigned MipsTargetAsmInfo::
50SectionFlagsForGlobal(const GlobalValue *GV, const char* Name) const {
51 unsigned Flags = ELFTargetAsmInfo::SectionFlagsForGlobal(GV, Name);
52 // Mask out Small Section flag bit, Mips doesnt support 's' section symbol
53 // for its small sections.
54 return (Flags & (~SectionFlags::Small));
55}
56
57SectionKind::Kind MipsTargetAsmInfo::
58SectionKindForGlobal(const GlobalValue *GV) const {
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000059 SectionKind::Kind K = ELFTargetAsmInfo::SectionKindForGlobal(GV);
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000060
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000061 if (Subtarget->hasABICall())
62 return K;
63
Anton Korobeynikov45788622008-08-07 09:51:54 +000064 if (K != SectionKind::Data && K != SectionKind::BSS &&
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000065 K != SectionKind::RODataMergeConst)
66 return K;
67
68 if (isa<GlobalVariable>(GV)) {
69 const TargetData *TD = ETM->getTargetData();
70 unsigned Size = TD->getABITypeSize(GV->getType()->getElementType());
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000071 unsigned Threshold = Subtarget->getSSectionThreshold();
Anton Korobeynikov45788622008-08-07 09:51:54 +000072
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000073 if (Size > 0 && Size <= Threshold) {
74 if (K == SectionKind::BSS)
75 return SectionKind::SmallBSS;
76 else
77 return SectionKind::SmallData;
78 }
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000079 }
80
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000081 return K;
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000082}
83
Bruno Cardoso Lopesea7930e2008-07-30 17:04:04 +000084const Section* MipsTargetAsmInfo::
Evan Cheng42ccc212008-08-08 17:56:50 +000085SelectSectionForGlobal(const GlobalValue *GV) const {
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000086 SectionKind::Kind K = SectionKindForGlobal(GV);
87 const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
88
89 if (GVA && (!GVA->isWeakForLinker()))
90 switch (K) {
91 case SectionKind::SmallData:
92 return getSmallDataSection();
93 case SectionKind::SmallBSS:
94 return getSmallBSSSection();
95 default: break;
96 }
97
98 return ELFTargetAsmInfo::SelectSectionForGlobal(GV);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000099}