Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1 | //===-- MipsTargetAsmInfo.cpp - Mips asm properties -------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the declarations of the MipsTargetAsmInfo properties. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "MipsTargetAsmInfo.h" |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 15 | #include "MipsTargetMachine.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 16 | |
| 17 | using namespace llvm; |
| 18 | |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 19 | MipsTargetAsmInfo::MipsTargetAsmInfo(const MipsTargetMachine &TM): |
| 20 | ELFTargetAsmInfo(TM) { |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 21 | |
Bruno Cardoso Lopes | feb95cc | 2008-07-22 15:34:27 +0000 | [diff] [blame] | 22 | MipsTM = &TM; |
| 23 | |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 24 | 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 Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 36 | CStringSection = ".rodata.str"; |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 37 | |
Bruno Cardoso Lopes | b27cb55 | 2008-07-15 02:03:36 +0000 | [diff] [blame] | 38 | if (!TM.getSubtarget<MipsSubtarget>().hasABICall()) |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 39 | JumpTableDirective = "\t.word\t"; |
Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 40 | else |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 41 | JumpTableDirective = "\t.gpword\t"; |
Bruno Cardoso Lopes | feb95cc | 2008-07-22 15:34:27 +0000 | [diff] [blame] | 42 | |
| 43 | SmallDataSection = getNamedSection("\t.sdata", SectionFlags::Writeable); |
| 44 | SmallBSSSection = getNamedSection("\t.sbss", |
| 45 | SectionFlags::Writeable | SectionFlags::BSS); |
| 46 | } |
Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 47 | |
Bruno Cardoso Lopes | feb95cc | 2008-07-22 15:34:27 +0000 | [diff] [blame] | 48 | static bool isSuitableForBSS(const GlobalVariable *GV) { |
| 49 | if (!GV->hasInitializer()) |
| 50 | return true; |
| 51 | |
| 52 | // Leave constant zeros in readonly constant sections, so they can be shared |
| 53 | Constant *C = GV->getInitializer(); |
| 54 | return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS); |
| 55 | } |
| 56 | |
| 57 | SectionKind::Kind |
| 58 | MipsTargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const { |
| 59 | const TargetData *TD = ETM->getTargetData(); |
| 60 | const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV); |
| 61 | |
| 62 | if (!GVA) |
| 63 | return ELFTargetAsmInfo::SectionKindForGlobal(GV); |
| 64 | |
| 65 | // if this is a internal constant string, there is a special |
| 66 | // section for it, but not in small data/bss. |
| 67 | if (GVA->hasInitializer() && GV->hasInternalLinkage()) { |
| 68 | Constant *C = GVA->getInitializer(); |
| 69 | const ConstantArray *CVA = dyn_cast<ConstantArray>(C); |
| 70 | if (CVA && CVA->isCString()) |
| 71 | return ELFTargetAsmInfo::SectionKindForGlobal(GV); |
| 72 | } |
| 73 | |
| 74 | const Type *Ty = GV->getType()->getElementType(); |
| 75 | unsigned Size = TD->getABITypeSize(Ty); |
| 76 | unsigned Threshold = |
| 77 | MipsTM->getSubtarget<MipsSubtarget>().getSSectionThreshold(); |
| 78 | |
| 79 | if (Size > 0 && Size <= Threshold) { |
| 80 | if (isSuitableForBSS(GVA)) |
| 81 | return SectionKind::SmallBSS; |
| 82 | else |
| 83 | return SectionKind::SmallData; |
| 84 | } |
| 85 | |
| 86 | return ELFTargetAsmInfo::SectionKindForGlobal(GV); |
| 87 | } |
| 88 | |
| 89 | const Section* |
| 90 | MipsTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { |
| 91 | SectionKind::Kind K = SectionKindForGlobal(GV); |
| 92 | const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV); |
| 93 | |
| 94 | if (GVA && (!GVA->isWeakForLinker())) |
| 95 | switch (K) { |
| 96 | case SectionKind::SmallData: |
| 97 | return getSmallDataSection(); |
| 98 | case SectionKind::SmallBSS: |
| 99 | return getSmallBSSSection(); |
| 100 | default: break; |
| 101 | } |
| 102 | |
| 103 | return ELFTargetAsmInfo::SelectSectionForGlobal(GV); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 104 | } |