summaryrefslogtreecommitdiff
path: root/lib/Target/Mips/MipsTargetAsmInfo.cpp
blob: 5c671cc24a34a18d691b29858f47e20473587590 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//===-- MipsTargetAsmInfo.cpp - Mips asm properties -------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the declarations of the MipsTargetAsmInfo properties.
//
//===----------------------------------------------------------------------===//

#include "MipsTargetAsmInfo.h"
#include "MipsTargetMachine.h"

using namespace llvm;

MipsTargetAsmInfo::MipsTargetAsmInfo(const MipsTargetMachine &TM):
  ELFTargetAsmInfo(TM) {

  Subtarget = &TM.getSubtarget<MipsSubtarget>();

  AlignmentIsInBytes          = false;
  COMMDirectiveTakesAlignment = true;
  Data16bitsDirective         = "\t.half\t";
  Data32bitsDirective         = "\t.word\t";
  Data64bitsDirective         = NULL;
  PrivateGlobalPrefix         = "$";
  JumpTableDataSection        = "\t.rdata";
  CommentString               = "#";
  ReadOnlySection             = "\t.rdata";
  ZeroDirective               = "\t.space\t";
  BSSSection                  = "\t.section\t.bss";
  CStringSection              = ".rodata.str";
  FourByteConstantSection     = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";

  if (!Subtarget->hasABICall()) {
    JumpTableDirective = "\t.word\t";
    SmallDataSection = getNamedSection("\t.sdata", SectionFlags::Writeable);
    SmallBSSSection = getNamedSection("\t.sbss", SectionFlags::Writeable | 
                                      SectionFlags::BSS);
  } else 
    JumpTableDirective = "\t.gpword\t";

}

unsigned MipsTargetAsmInfo::
SectionFlagsForGlobal(const GlobalValue *GV, const char* Name) const {
  unsigned Flags = ELFTargetAsmInfo::SectionFlagsForGlobal(GV, Name);
  // Mask out Small Section flag bit, Mips doesnt support 's' section symbol
  // for its small sections.
  return (Flags & (~SectionFlags::Small));
}

SectionKind::Kind MipsTargetAsmInfo::
SectionKindForGlobal(const GlobalValue *GV) const {
  SectionKind::Kind K = ELFTargetAsmInfo::SectionKindForGlobal(GV);

  if (Subtarget->hasABICall())
    return K;

  if (K != SectionKind::Data && K != SectionKind::BSS && 
      K != SectionKind::RODataMergeConst)
    return K;

  if (isa<GlobalVariable>(GV)) {
    const TargetData *TD = ETM->getTargetData();
    unsigned Size = TD->getABITypeSize(GV->getType()->getElementType());
    unsigned Threshold = Subtarget->getSSectionThreshold();
     
    if (Size > 0 && Size <= Threshold) {
      if (K == SectionKind::BSS)
        return SectionKind::SmallBSS;
      else
        return SectionKind::SmallData;
    }
  }

  return K;
}

const Section* MipsTargetAsmInfo::
SelectSectionForGlobal(const GlobalValue *GV) const {
  SectionKind::Kind K = SectionKindForGlobal(GV);
  const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);

  if (GVA && (!GVA->isWeakForLinker()))
    switch (K) {
      case SectionKind::SmallData:
        return getSmallDataSection();
      case SectionKind::SmallBSS:
        return getSmallBSSSection();
      default: break;
    }

  return ELFTargetAsmInfo::SelectSectionForGlobal(GV);
}