Deleted Added
full compact
MipsTargetObjectFile.cpp (198090) MipsTargetObjectFile.cpp (199511)
1//===-- MipsTargetObjectFile.cpp - Mips object files ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "MipsTargetObjectFile.h"
1//===-- MipsTargetObjectFile.cpp - Mips object files ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "MipsTargetObjectFile.h"
11#include "MipsSubtarget.h"
11#include "llvm/DerivedTypes.h"
12#include "llvm/GlobalVariable.h"
13#include "llvm/MC/MCSectionELF.h"
14#include "llvm/Target/TargetData.h"
15#include "llvm/Target/TargetMachine.h"
16#include "llvm/Support/CommandLine.h"
17using namespace llvm;
18
19static cl::opt<unsigned>
20SSThreshold("mips-ssection-threshold", cl::Hidden,
21 cl::desc("Small data and bss section threshold size (default=8)"),
22 cl::init(8));
23
24void MipsTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
25 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
26
27 SmallDataSection =
28 getELFSection(".sdata", MCSectionELF::SHT_PROGBITS,
29 MCSectionELF::SHF_WRITE | MCSectionELF::SHF_ALLOC,
30 SectionKind::getDataRel());
31
32 SmallBSSSection =
33 getELFSection(".sbss", MCSectionELF::SHT_NOBITS,
34 MCSectionELF::SHF_WRITE | MCSectionELF::SHF_ALLOC,
35 SectionKind::getBSS());
36
37}
38
39// A address must be loaded from a small section if its size is less than the
40// small section size threshold. Data in this section must be addressed using
41// gp_rel operator.
42static bool IsInSmallSection(uint64_t Size) {
43 return Size > 0 && Size <= SSThreshold;
44}
45
46bool MipsTargetObjectFile::IsGlobalInSmallSection(const GlobalValue *GV,
47 const TargetMachine &TM) const {
48 if (GV->isDeclaration() || GV->hasAvailableExternallyLinkage())
49 return false;
50
51 return IsGlobalInSmallSection(GV, TM, getKindForGlobal(GV, TM));
52}
53
54/// IsGlobalInSmallSection - Return true if this global address should be
55/// placed into small data/bss section.
56bool MipsTargetObjectFile::
57IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM,
58 SectionKind Kind) const {
12#include "llvm/DerivedTypes.h"
13#include "llvm/GlobalVariable.h"
14#include "llvm/MC/MCSectionELF.h"
15#include "llvm/Target/TargetData.h"
16#include "llvm/Target/TargetMachine.h"
17#include "llvm/Support/CommandLine.h"
18using namespace llvm;
19
20static cl::opt<unsigned>
21SSThreshold("mips-ssection-threshold", cl::Hidden,
22 cl::desc("Small data and bss section threshold size (default=8)"),
23 cl::init(8));
24
25void MipsTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
26 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
27
28 SmallDataSection =
29 getELFSection(".sdata", MCSectionELF::SHT_PROGBITS,
30 MCSectionELF::SHF_WRITE | MCSectionELF::SHF_ALLOC,
31 SectionKind::getDataRel());
32
33 SmallBSSSection =
34 getELFSection(".sbss", MCSectionELF::SHT_NOBITS,
35 MCSectionELF::SHF_WRITE | MCSectionELF::SHF_ALLOC,
36 SectionKind::getBSS());
37
38}
39
40// A address must be loaded from a small section if its size is less than the
41// small section size threshold. Data in this section must be addressed using
42// gp_rel operator.
43static bool IsInSmallSection(uint64_t Size) {
44 return Size > 0 && Size <= SSThreshold;
45}
46
47bool MipsTargetObjectFile::IsGlobalInSmallSection(const GlobalValue *GV,
48 const TargetMachine &TM) const {
49 if (GV->isDeclaration() || GV->hasAvailableExternallyLinkage())
50 return false;
51
52 return IsGlobalInSmallSection(GV, TM, getKindForGlobal(GV, TM));
53}
54
55/// IsGlobalInSmallSection - Return true if this global address should be
56/// placed into small data/bss section.
57bool MipsTargetObjectFile::
58IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM,
59 SectionKind Kind) const {
60
61 // Only use small section for non linux targets.
62 const MipsSubtarget &Subtarget = TM.getSubtarget<MipsSubtarget>();
63 if (Subtarget.isLinux())
64 return false;
65
59 // Only global variables, not functions.
60 const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
61 if (!GVA)
62 return false;
63
64 // We can only do this for datarel or BSS objects for now.
65 if (!Kind.isBSS() && !Kind.isDataRel())
66 return false;
67
68 // If this is a internal constant string, there is a special
69 // section for it, but not in small data/bss.
70 if (Kind.isMergeable1ByteCString())
71 return false;
72
73 const Type *Ty = GV->getType()->getElementType();
74 return IsInSmallSection(TM.getTargetData()->getTypeAllocSize(Ty));
75}
76
77
78
79const MCSection *MipsTargetObjectFile::
80SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
81 Mangler *Mang, const TargetMachine &TM) const {
82 // TODO: Could also support "weak" symbols as well with ".gnu.linkonce.s.*"
83 // sections?
84
85 // Handle Small Section classification here.
86 if (Kind.isBSS() && IsGlobalInSmallSection(GV, TM, Kind))
87 return SmallBSSSection;
88 if (Kind.isDataNoRel() && IsGlobalInSmallSection(GV, TM, Kind))
89 return SmallDataSection;
90
91 // Otherwise, we work the same as ELF.
92 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang,TM);
93}
66 // Only global variables, not functions.
67 const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
68 if (!GVA)
69 return false;
70
71 // We can only do this for datarel or BSS objects for now.
72 if (!Kind.isBSS() && !Kind.isDataRel())
73 return false;
74
75 // If this is a internal constant string, there is a special
76 // section for it, but not in small data/bss.
77 if (Kind.isMergeable1ByteCString())
78 return false;
79
80 const Type *Ty = GV->getType()->getElementType();
81 return IsInSmallSection(TM.getTargetData()->getTypeAllocSize(Ty));
82}
83
84
85
86const MCSection *MipsTargetObjectFile::
87SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
88 Mangler *Mang, const TargetMachine &TM) const {
89 // TODO: Could also support "weak" symbols as well with ".gnu.linkonce.s.*"
90 // sections?
91
92 // Handle Small Section classification here.
93 if (Kind.isBSS() && IsGlobalInSmallSection(GV, TM, Kind))
94 return SmallBSSSection;
95 if (Kind.isDataNoRel() && IsGlobalInSmallSection(GV, TM, Kind))
96 return SmallDataSection;
97
98 // Otherwise, we work the same as ELF.
99 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang,TM);
100}