Mercurial > hg > CbC > CbC_llvm
comparison lib/Target/TargetLoweringObjectFile.cpp @ 121:803732b1fca8
LLVM 5.0
author | kono |
---|---|
date | Fri, 27 Oct 2017 17:07:41 +0900 |
parents | 1172e4bd9c6f |
children | 3a76565eade5 |
comparison
equal
deleted
inserted
replaced
120:1172e4bd9c6f | 121:803732b1fca8 |
---|---|
11 // object file formats. | 11 // object file formats. |
12 // | 12 // |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #include "llvm/Target/TargetLoweringObjectFile.h" | 15 #include "llvm/Target/TargetLoweringObjectFile.h" |
16 #include "llvm/BinaryFormat/Dwarf.h" | |
16 #include "llvm/IR/Constants.h" | 17 #include "llvm/IR/Constants.h" |
17 #include "llvm/IR/DataLayout.h" | 18 #include "llvm/IR/DataLayout.h" |
18 #include "llvm/IR/DerivedTypes.h" | 19 #include "llvm/IR/DerivedTypes.h" |
19 #include "llvm/IR/Function.h" | 20 #include "llvm/IR/Function.h" |
20 #include "llvm/IR/GlobalVariable.h" | 21 #include "llvm/IR/GlobalVariable.h" |
22 #include "llvm/MC/MCAsmInfo.h" | 23 #include "llvm/MC/MCAsmInfo.h" |
23 #include "llvm/MC/MCContext.h" | 24 #include "llvm/MC/MCContext.h" |
24 #include "llvm/MC/MCExpr.h" | 25 #include "llvm/MC/MCExpr.h" |
25 #include "llvm/MC/MCStreamer.h" | 26 #include "llvm/MC/MCStreamer.h" |
26 #include "llvm/MC/MCSymbol.h" | 27 #include "llvm/MC/MCSymbol.h" |
27 #include "llvm/Support/Dwarf.h" | |
28 #include "llvm/Support/ErrorHandling.h" | 28 #include "llvm/Support/ErrorHandling.h" |
29 #include "llvm/Support/raw_ostream.h" | 29 #include "llvm/Support/raw_ostream.h" |
30 #include "llvm/Target/TargetLowering.h" | 30 #include "llvm/Target/TargetLowering.h" |
31 #include "llvm/Target/TargetMachine.h" | 31 #include "llvm/Target/TargetMachine.h" |
32 #include "llvm/Target/TargetOptions.h" | 32 #include "llvm/Target/TargetOptions.h" |
42 /// lowering implementations a chance to set up their default sections. | 42 /// lowering implementations a chance to set up their default sections. |
43 void TargetLoweringObjectFile::Initialize(MCContext &ctx, | 43 void TargetLoweringObjectFile::Initialize(MCContext &ctx, |
44 const TargetMachine &TM) { | 44 const TargetMachine &TM) { |
45 Ctx = &ctx; | 45 Ctx = &ctx; |
46 // `Initialize` can be called more than once. | 46 // `Initialize` can be called more than once. |
47 if (Mang != nullptr) delete Mang; | 47 delete Mang; |
48 Mang = new Mangler(); | 48 Mang = new Mangler(); |
49 InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(), | 49 InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(), *Ctx, |
50 TM.getCodeModel(), *Ctx); | 50 TM.getCodeModel() == CodeModel::Large); |
51 } | 51 } |
52 | 52 |
53 TargetLoweringObjectFile::~TargetLoweringObjectFile() { | 53 TargetLoweringObjectFile::~TargetLoweringObjectFile() { |
54 delete Mang; | 54 delete Mang; |
55 } | 55 } |
238 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { | 238 const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { |
239 // Select section name. | 239 // Select section name. |
240 if (GO->hasSection()) | 240 if (GO->hasSection()) |
241 return getExplicitSectionGlobal(GO, Kind, TM); | 241 return getExplicitSectionGlobal(GO, Kind, TM); |
242 | 242 |
243 if (auto *GVar = dyn_cast<GlobalVariable>(GO)) { | |
244 auto Attrs = GVar->getAttributes(); | |
245 if ((Attrs.hasAttribute("bss-section") && Kind.isBSS()) || | |
246 (Attrs.hasAttribute("data-section") && Kind.isData()) || | |
247 (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())) { | |
248 return getExplicitSectionGlobal(GO, Kind, TM); | |
249 } | |
250 } | |
251 | |
252 if (auto *F = dyn_cast<Function>(GO)) { | |
253 if (F->hasFnAttribute("implicit-section-name")) | |
254 return getExplicitSectionGlobal(GO, Kind, TM); | |
255 } | |
256 | |
243 // Use default section depending on the 'type' of global | 257 // Use default section depending on the 'type' of global |
244 return SelectSectionForGlobal(GO, Kind, TM); | 258 return SelectSectionForGlobal(GO, Kind, TM); |
245 } | 259 } |
246 | 260 |
247 MCSection *TargetLoweringObjectFile::getSectionForJumpTable( | 261 MCSection *TargetLoweringObjectFile::getSectionForJumpTable( |
262 | 276 |
263 // We should also do if the section name is NULL or function is declared | 277 // We should also do if the section name is NULL or function is declared |
264 // in discardable section | 278 // in discardable section |
265 // FIXME: this isn't the right predicate, should be based on the MCSection | 279 // FIXME: this isn't the right predicate, should be based on the MCSection |
266 // for the function. | 280 // for the function. |
267 if (F.isWeakForLinker()) | 281 return F.isWeakForLinker(); |
268 return true; | |
269 | |
270 return false; | |
271 } | 282 } |
272 | 283 |
273 /// Given a mergable constant with the specified size and relocation | 284 /// Given a mergable constant with the specified size and relocation |
274 /// information, return a section that it should be placed in. | 285 /// information, return a section that it should be placed in. |
275 MCSection *TargetLoweringObjectFile::getSectionForConstant( | 286 MCSection *TargetLoweringObjectFile::getSectionForConstant( |