blob: 5c671cc24a34a18d691b29858f47e20473587590 [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 Lopes92e87f22008-07-23 16:01:50 +000022 Subtarget = &TM.getSubtarget<MipsSubtarget>();
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000023
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";
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000035 CStringSection = ".rodata.str";
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +000036 FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000037
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000038 if (!Subtarget->hasABICall()) {
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000039 JumpTableDirective = "\t.word\t";
Bruno Cardoso Lopes92e87f22008-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 Lopes753a9872007-11-12 19:49:57 +000044 JumpTableDirective = "\t.gpword\t";
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000045
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000046}
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000047
Bruno Cardoso Lopesea7930e2008-07-30 17:04:04 +000048unsigned MipsTargetAsmInfo::
49SectionFlagsForGlobal(const GlobalValue *GV, const char* Name) const {
50 unsigned Flags = ELFTargetAsmInfo::SectionFlagsForGlobal(GV, Name);
51 // Mask out Small Section flag bit, Mips doesnt support 's' section symbol
52 // for its small sections.
53 return (Flags & (~SectionFlags::Small));
54}
55
56SectionKind::Kind MipsTargetAsmInfo::
57SectionKindForGlobal(const GlobalValue *GV) const {
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000058 SectionKind::Kind K = ELFTargetAsmInfo::SectionKindForGlobal(GV);
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000059
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000060 if (Subtarget->hasABICall())
61 return K;
62
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000063 if (K != SectionKind::Data && K != SectionKind::BSS &&
64 K != SectionKind::RODataMergeConst)
65 return K;
66
67 if (isa<GlobalVariable>(GV)) {
68 const TargetData *TD = ETM->getTargetData();
69 unsigned Size = TD->getABITypeSize(GV->getType()->getElementType());
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000070 unsigned Threshold = Subtarget->getSSectionThreshold();
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000071
72 if (Size > 0 && Size <= Threshold) {
73 if (K == SectionKind::BSS)
74 return SectionKind::SmallBSS;
75 else
76 return SectionKind::SmallData;
77 }
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000078 }
79
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000080 return K;
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000081}
82
Bruno Cardoso Lopesea7930e2008-07-30 17:04:04 +000083const Section* MipsTargetAsmInfo::
84SelectSectionForGlobal(const GlobalValue *GV) const {
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000085 SectionKind::Kind K = SectionKindForGlobal(GV);
86 const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
87
88 if (GVA && (!GVA->isWeakForLinker()))
89 switch (K) {
90 case SectionKind::SmallData:
91 return getSmallDataSection();
92 case SectionKind::SmallBSS:
93 return getSmallBSSSection();
94 default: break;
95 }
96
97 return ELFTargetAsmInfo::SelectSectionForGlobal(GV);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000098}