Mercurial > hg > CbC > CbC_llvm
comparison lib/Target/Mips/MipsTargetObjectFile.cpp @ 95:afa8332a0e37 LLVM3.8
LLVM 3.8
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Oct 2015 17:48:58 +0900 |
parents | 60c9769439b8 |
children | 7d135dc70f03 |
comparison
equal
deleted
inserted
replaced
84:f3e34b893a5f | 95:afa8332a0e37 |
---|---|
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 | 9 |
10 #include "MipsTargetObjectFile.h" | 10 #include "MipsTargetObjectFile.h" |
11 #include "MipsSubtarget.h" | 11 #include "MipsSubtarget.h" |
12 #include "MipsTargetMachine.h" | |
12 #include "llvm/IR/DataLayout.h" | 13 #include "llvm/IR/DataLayout.h" |
13 #include "llvm/IR/DerivedTypes.h" | 14 #include "llvm/IR/DerivedTypes.h" |
14 #include "llvm/IR/GlobalVariable.h" | 15 #include "llvm/IR/GlobalVariable.h" |
15 #include "llvm/MC/MCContext.h" | 16 #include "llvm/MC/MCContext.h" |
16 #include "llvm/MC/MCSectionELF.h" | 17 #include "llvm/MC/MCSectionELF.h" |
42 SmallDataSection = getContext().getELFSection( | 43 SmallDataSection = getContext().getELFSection( |
43 ".sdata", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC); | 44 ".sdata", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC); |
44 | 45 |
45 SmallBSSSection = getContext().getELFSection(".sbss", ELF::SHT_NOBITS, | 46 SmallBSSSection = getContext().getELFSection(".sbss", ELF::SHT_NOBITS, |
46 ELF::SHF_WRITE | ELF::SHF_ALLOC); | 47 ELF::SHF_WRITE | ELF::SHF_ALLOC); |
47 this->TM = &TM; | 48 this->TM = &static_cast<const MipsTargetMachine &>(TM); |
48 } | 49 } |
49 | 50 |
50 // A address must be loaded from a small section if its size is less than the | 51 // A address must be loaded from a small section if its size is less than the |
51 // small section size threshold. Data in this section must be addressed using | 52 // small section size threshold. Data in this section must be addressed using |
52 // gp_rel operator. | 53 // gp_rel operator. |
82 /// section. This method does all the work, except for checking the section | 83 /// section. This method does all the work, except for checking the section |
83 /// kind. | 84 /// kind. |
84 bool MipsTargetObjectFile:: | 85 bool MipsTargetObjectFile:: |
85 IsGlobalInSmallSectionImpl(const GlobalValue *GV, | 86 IsGlobalInSmallSectionImpl(const GlobalValue *GV, |
86 const TargetMachine &TM) const { | 87 const TargetMachine &TM) const { |
87 const MipsSubtarget &Subtarget = TM.getSubtarget<MipsSubtarget>(); | 88 const MipsSubtarget &Subtarget = |
89 *static_cast<const MipsTargetMachine &>(TM).getSubtargetImpl(); | |
88 | 90 |
89 // Return if small section is not available. | 91 // Return if small section is not available. |
90 if (!Subtarget.useSmallSection()) | 92 if (!Subtarget.useSmallSection()) |
91 return false; | 93 return false; |
92 | 94 |
103 if (!ExternSData && ((GV->hasExternalLinkage() && GV->isDeclaration()) || | 105 if (!ExternSData && ((GV->hasExternalLinkage() && GV->isDeclaration()) || |
104 GV->hasCommonLinkage())) | 106 GV->hasCommonLinkage())) |
105 return false; | 107 return false; |
106 | 108 |
107 Type *Ty = GV->getType()->getElementType(); | 109 Type *Ty = GV->getType()->getElementType(); |
108 return IsInSmallSection(TM.getDataLayout()->getTypeAllocSize(Ty)); | 110 return IsInSmallSection( |
111 GV->getParent()->getDataLayout().getTypeAllocSize(Ty)); | |
109 } | 112 } |
110 | 113 |
111 const MCSection *MipsTargetObjectFile:: | 114 MCSection * |
112 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, | 115 MipsTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV, |
113 Mangler &Mang, const TargetMachine &TM) const { | 116 SectionKind Kind, Mangler &Mang, |
117 const TargetMachine &TM) const { | |
114 // TODO: Could also support "weak" symbols as well with ".gnu.linkonce.s.*" | 118 // TODO: Could also support "weak" symbols as well with ".gnu.linkonce.s.*" |
115 // sections? | 119 // sections? |
116 | 120 |
117 // Handle Small Section classification here. | 121 // Handle Small Section classification here. |
118 if (Kind.isBSS() && IsGlobalInSmallSection(GV, TM, Kind)) | 122 if (Kind.isBSS() && IsGlobalInSmallSection(GV, TM, Kind)) |
123 // Otherwise, we work the same as ELF. | 127 // Otherwise, we work the same as ELF. |
124 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang,TM); | 128 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang,TM); |
125 } | 129 } |
126 | 130 |
127 /// Return true if this constant should be placed into small data section. | 131 /// Return true if this constant should be placed into small data section. |
128 bool MipsTargetObjectFile:: | 132 bool MipsTargetObjectFile::IsConstantInSmallSection( |
129 IsConstantInSmallSection(const Constant *CN, const TargetMachine &TM) const { | 133 const DataLayout &DL, const Constant *CN, const TargetMachine &TM) const { |
130 return ( | 134 return (static_cast<const MipsTargetMachine &>(TM) |
131 TM.getSubtarget<MipsSubtarget>().useSmallSection() && LocalSData && | 135 .getSubtargetImpl() |
132 IsInSmallSection(TM.getDataLayout()->getTypeAllocSize(CN->getType()))); | 136 ->useSmallSection() && |
137 LocalSData && IsInSmallSection(DL.getTypeAllocSize(CN->getType()))); | |
133 } | 138 } |
134 | 139 |
135 const MCSection *MipsTargetObjectFile:: | 140 /// Return true if this constant should be placed into small data section. |
136 getSectionForConstant(SectionKind Kind, const Constant *C) const { | 141 MCSection *MipsTargetObjectFile::getSectionForConstant( |
137 if (IsConstantInSmallSection(C, *TM)) | 142 const DataLayout &DL, SectionKind Kind, const Constant *C) const { |
143 if (IsConstantInSmallSection(DL, C, *TM)) | |
138 return SmallDataSection; | 144 return SmallDataSection; |
139 | 145 |
140 // Otherwise, we work the same as ELF. | 146 // Otherwise, we work the same as ELF. |
141 return TargetLoweringObjectFileELF::getSectionForConstant(Kind, C); | 147 return TargetLoweringObjectFileELF::getSectionForConstant(DL, Kind, C); |
142 } | 148 } |