blob: f086db02d266f7b0df6c29d0c217b049d6d24f79 [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 = "#";
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +000033 ZeroDirective = "\t.space\t";
34 BSSSection = "\t.section\t.bss";
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000035 CStringSection = ".rodata.str";
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000036
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000037 if (!Subtarget->hasABICall()) {
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +000038 JumpTableDirective = "\t.word\t";
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000039 SmallDataSection = getNamedSection("\t.sdata", SectionFlags::Writeable);
Anton Korobeynikov00181a32008-09-24 22:20:27 +000040 SmallBSSSection = getNamedSection("\t.sbss",
41 SectionFlags::Writeable |
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000042 SectionFlags::BSS);
Anton Korobeynikov00181a32008-09-24 22:20:27 +000043 } 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 +000048SectionKind::Kind MipsTargetAsmInfo::
49SectionKindForGlobal(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 Lopes92e87f22008-07-23 16:01:50 +000052 if (Subtarget->hasABICall())
53 return K;
54
Anton Korobeynikov45788622008-08-07 09:51:54 +000055 if (K != SectionKind::Data && K != SectionKind::BSS &&
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000056 K != SectionKind::RODataMergeConst)
57 return K;
58
59 if (isa<GlobalVariable>(GV)) {
Dan Gohman8f092252008-11-03 18:22:42 +000060 const TargetData *TD = TM.getTargetData();
Duncan Sands777d2302009-05-09 07:06:46 +000061 unsigned Size = TD->getTypeAllocSize(GV->getType()->getElementType());
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +000062 unsigned Threshold = Subtarget->getSSectionThreshold();
Anton Korobeynikov45788622008-08-07 09:51:54 +000063
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000064 if (Size > 0 && Size <= Threshold) {
65 if (K == SectionKind::BSS)
66 return SectionKind::SmallBSS;
67 else
68 return SectionKind::SmallData;
69 }
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000070 }
71
Bruno Cardoso Lopesc92a0e92008-07-22 16:24:21 +000072 return K;
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000073}
74
Bruno Cardoso Lopesea7930e2008-07-30 17:04:04 +000075const Section* MipsTargetAsmInfo::
Evan Cheng42ccc212008-08-08 17:56:50 +000076SelectSectionForGlobal(const GlobalValue *GV) const {
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000077 SectionKind::Kind K = SectionKindForGlobal(GV);
78 const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
79
Duncan Sands667d4b82009-03-07 15:45:40 +000080 if (GVA && (!GVA->isWeakForLinker()))
Bruno Cardoso Lopesfeb95cc2008-07-22 15:34:27 +000081 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);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000090}