| 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" | 
| Dan Gohman | 8f613f3 | 2008-08-05 15:32:23 +0000 | [diff] [blame] | 16 | #include "llvm/GlobalVariable.h" | 
| Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 17 |  | 
 | 18 | using namespace llvm; | 
 | 19 |  | 
| Anton Korobeynikov | ae408e6 | 2008-07-19 13:16:11 +0000 | [diff] [blame] | 20 | MipsTargetAsmInfo::MipsTargetAsmInfo(const MipsTargetMachine &TM): | 
 | 21 |   ELFTargetAsmInfo(TM) { | 
| Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 22 |  | 
| Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 23 |   Subtarget = &TM.getSubtarget<MipsSubtarget>(); | 
| Bruno Cardoso Lopes | feb95cc | 2008-07-22 15:34:27 +0000 | [diff] [blame] | 24 |  | 
| Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 25 |   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 Lopes | 91fd532 | 2008-07-21 18:52:34 +0000 | [diff] [blame] | 36 |   CStringSection              = ".rodata.str"; | 
| Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 37 |   FourByteConstantSection     = "\t.section\t.rodata.cst4,\"aM\",@progbits,4"; | 
| Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 38 |  | 
| Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 39 |   if (!Subtarget->hasABICall()) { | 
| Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 40 |     JumpTableDirective = "\t.word\t"; | 
| Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 41 |     SmallDataSection = getNamedSection("\t.sdata", SectionFlags::Writeable); | 
 | 42 |     SmallBSSSection = getNamedSection("\t.sbss", SectionFlags::Writeable |  | 
 | 43 |                                       SectionFlags::BSS); | 
 | 44 |   } else  | 
| Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 45 |     JumpTableDirective = "\t.gpword\t"; | 
| Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 46 |  | 
| Bruno Cardoso Lopes | feb95cc | 2008-07-22 15:34:27 +0000 | [diff] [blame] | 47 | } | 
| Bruno Cardoso Lopes | 753a987 | 2007-11-12 19:49:57 +0000 | [diff] [blame] | 48 |  | 
| Bruno Cardoso Lopes | ea7930e | 2008-07-30 17:04:04 +0000 | [diff] [blame] | 49 | unsigned MipsTargetAsmInfo:: | 
 | 50 | SectionFlagsForGlobal(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 |  | 
 | 57 | SectionKind::Kind MipsTargetAsmInfo:: | 
 | 58 | SectionKindForGlobal(const GlobalValue *GV) const { | 
| Bruno Cardoso Lopes | c92a0e9 | 2008-07-22 16:24:21 +0000 | [diff] [blame] | 59 |   SectionKind::Kind K = ELFTargetAsmInfo::SectionKindForGlobal(GV); | 
| Bruno Cardoso Lopes | feb95cc | 2008-07-22 15:34:27 +0000 | [diff] [blame] | 60 |  | 
| Bruno Cardoso Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 61 |   if (Subtarget->hasABICall()) | 
 | 62 |     return K; | 
 | 63 |  | 
| Anton Korobeynikov | 4578862 | 2008-08-07 09:51:54 +0000 | [diff] [blame^] | 64 |   if (K != SectionKind::Data && K != SectionKind::BSS && | 
| Bruno Cardoso Lopes | c92a0e9 | 2008-07-22 16:24:21 +0000 | [diff] [blame] | 65 |       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 Lopes | 92e87f2 | 2008-07-23 16:01:50 +0000 | [diff] [blame] | 71 |     unsigned Threshold = Subtarget->getSSectionThreshold(); | 
| Anton Korobeynikov | 4578862 | 2008-08-07 09:51:54 +0000 | [diff] [blame^] | 72 |  | 
| Bruno Cardoso Lopes | c92a0e9 | 2008-07-22 16:24:21 +0000 | [diff] [blame] | 73 |     if (Size > 0 && Size <= Threshold) { | 
 | 74 |       if (K == SectionKind::BSS) | 
 | 75 |         return SectionKind::SmallBSS; | 
 | 76 |       else | 
 | 77 |         return SectionKind::SmallData; | 
 | 78 |     } | 
| Bruno Cardoso Lopes | feb95cc | 2008-07-22 15:34:27 +0000 | [diff] [blame] | 79 |   } | 
 | 80 |  | 
| Bruno Cardoso Lopes | c92a0e9 | 2008-07-22 16:24:21 +0000 | [diff] [blame] | 81 |   return K; | 
| Bruno Cardoso Lopes | feb95cc | 2008-07-22 15:34:27 +0000 | [diff] [blame] | 82 | } | 
 | 83 |  | 
| Bruno Cardoso Lopes | ea7930e | 2008-07-30 17:04:04 +0000 | [diff] [blame] | 84 | const Section* MipsTargetAsmInfo:: | 
 | 85 | SelectSectionForGlobal(const GlobalValue *GV) const { | 
| Bruno Cardoso Lopes | feb95cc | 2008-07-22 15:34:27 +0000 | [diff] [blame] | 86 |   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 Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 99 | } |