llvm.org GIT mirror llvm / a87dea4
switch off of 'Section' onto MCSection. We're not properly using MCSection subclasses yet, but this is a step in the right direction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77708 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
21 changed file(s) with 193 addition(s) and 186 deletion(s). Raw diff Collapse all Expand all
3333 class MachineModuleInfo;
3434 class MCInst;
3535 class MCContext;
36 class MCSection;
3637 class MCStreamer;
3738 class DwarfWriter;
3839 class Mangler;
39 class Section;
4040 class TargetAsmInfo;
4141 class TargetLoweringObjectFile;
4242 class Type;
112112 /// CurrentSection - The current section we are emitting to. This is
113113 /// controlled and used by the SwitchSection method.
114114 std::string CurrentSection;
115 const Section* CurrentSection_;
115 const MCSection *CurrentSection_;
116116
117117 /// IsInTextSection - True if the current section we are emitting to is a
118118 /// text section.
172172
173173 /// SwitchToSection - Switch to the specified section of the executable if
174174 /// we are not already in it!
175 void SwitchToSection(const Section* NS);
175 void SwitchToSection(const MCSection *NS);
176176
177177 /// getGlobalLinkName - Returns the asm/link name of of the specified
178178 /// global variable. Should be overridden by each target asm printer to
3131 void operator=(const MCSection&); // DO NOT IMPLEMENT
3232 protected:
3333 MCSection(const StringRef &Name, MCContext &Ctx);
34 // FIXME: HACK.
35 SectionKind Kind;
3436 public:
3537 virtual ~MCSection();
3638
3739 static MCSection *Create(const StringRef &Name, MCContext &Ctx);
3840
3941 const std::string &getName() const { return Name; }
42 SectionKind getKind() const { return Kind; }
4043 };
4144
4245 /// MCSectionWithKind - This is used by targets that use the SectionKind enum
4346 /// to classify their sections.
4447 class MCSectionWithKind : public MCSection {
45 SectionKind Kind;
4648 MCSectionWithKind(const StringRef &Name, SectionKind K, MCContext &Ctx)
47 : MCSection(Name, Ctx), Kind(K) {}
49 : MCSection(Name, Ctx) {
50 Kind = K;
51 }
4852 public:
4953
5054 static MCSectionWithKind *Create(const StringRef &Name, SectionKind K,
5155 MCContext &Ctx);
5256
53 SectionKind getKind() const { return Kind; }
5457 };
5558
5659
5760
61 typedef MCSectionWithKind MCSectionELF;
62
5863 } // end namespace llvm
5964
6065 #endif
1515 #ifndef LLVM_TARGET_ASM_INFO_H
1616 #define LLVM_TARGET_ASM_INFO_H
1717
18 #include "llvm/ADT/StringMap.h"
1918 #include "llvm/Support/DataTypes.h"
2019 #include
2120
1414 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
1515 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
1616
17 // FIXME: Switch to MC.
18 #include "llvm/Target/TargetAsmInfo.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringMap.h"
1919
2020 namespace llvm {
21 class MCSection;
2122 class MCContext;
22
23 class GlobalValue;
24 class Mangler;
25 class TargetMachine;
26
2327 /// SectionKind - This is a simple POD value that classifies the properties of
2428 /// a section. A global variable is classified into the deepest possible
2529 /// classification, and then the target maps them onto their sections based on
198202 }
199203 };
200204
201 class Section {
202 public:
203
204 std::string Name;
205 SectionKind Kind;
206
207 explicit Section() { }
208 Section(const std::string &N, SectionKind K) : Name(N), Kind(K) {}
209 const std::string &getName() const { return Name; }
210 SectionKind getKind() const { return Kind; }
211 };
212
213205
214206 class TargetLoweringObjectFile {
215 private:
216 mutable StringMap
Sections;
207 MCContext *Ctx;
217208 protected:
218209
219210 TargetLoweringObjectFile();
220211
221212 /// TextSection - Section directive for standard text.
222213 ///
223 const Section *TextSection; // Defaults to ".text".
214 const MCSection *TextSection; // Defaults to ".text".
224215
225216 /// DataSection - Section directive for standard data.
226217 ///
227 const Section *DataSection; // Defaults to ".data".
218 const MCSection *DataSection; // Defaults to ".data".
228219
229220
230221
231222 // FIXME: SINK THESE.
232 const Section *BSSSection_;
223 const MCSection *BSSSection_;
233224
234225 /// ReadOnlySection - This is the directive that is emitted to switch to a
235226 /// read-only section for constant data (e.g. data declared const,
236227 /// jump tables).
237 const Section *ReadOnlySection; // Defaults to NULL
228 const MCSection *ReadOnlySection; // Defaults to NULL
238229
239230 /// TLSDataSection - Section directive for Thread Local data.
240231 ///
241 const Section *TLSDataSection; // Defaults to ".tdata".
232 const MCSection *TLSDataSection; // Defaults to ".tdata".
242233
243234 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
244235 /// Null if this target doesn't support a BSS section.
245236 ///
246 const Section *TLSBSSSection; // Defaults to ".tbss".
247
248 const Section *CStringSection_;
237 const MCSection *TLSBSSSection; // Defaults to ".tbss".
238
239 const MCSection *CStringSection_;
249240
250241 public:
251242 // FIXME: NONPUB.
252 const Section *getOrCreateSection(const char *Name,
253 bool isDirective,
254 SectionKind::Kind K) const;
243 const MCSection *getOrCreateSection(const char *Name,
244 bool isDirective,
245 SectionKind::Kind K) const;
255246 public:
256247
257248 virtual ~TargetLoweringObjectFile();
259250 /// Initialize - this method must be called before any actual lowering is
260251 /// done. This specifies the current context for codegen, and gives the
261252 /// lowering implementations a chance to set up their default sections.
262 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM) {}
263
264
265 const Section *getTextSection() const { return TextSection; }
266 const Section *getDataSection() const { return DataSection; }
253 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
254 Ctx = &ctx;
255 }
256
257
258 const MCSection *getTextSection() const { return TextSection; }
259 const MCSection *getDataSection() const { return DataSection; }
267260
268261
269262 /// getSectionForMergeableConstant - Given a mergeable constant with the
270263 /// specified size and relocation information, return a section that it
271264 /// should be placed in.
272 virtual const Section *
265 virtual const MCSection *
273266 getSectionForMergeableConstant(SectionKind Kind) const;
274267
275268 /// getKindForNamedSection - If this target wants to be able to override
284277 /// SectionForGlobal - This method computes the appropriate section to emit
285278 /// the specified global variable or function definition. This should not
286279 /// be passed external (or available externally) globals.
287 const Section *SectionForGlobal(const GlobalValue *GV,
288 Mangler *Mang,
289 const TargetMachine &TM) const;
280 const MCSection *SectionForGlobal(const GlobalValue *GV,
281 Mangler *Mang,
282 const TargetMachine &TM) const;
290283
291284 /// getSpecialCasedSectionGlobals - Allow the target to completely override
292285 /// section assignment of a global.
293286 /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
294287 /// getFlagsForNamedSection.
295 virtual const Section *
288 virtual const MCSection *
296289 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
297290 SectionKind Kind) const {
298291 return 0;
306299 }
307300
308301 protected:
309 virtual const Section *
302 virtual const MCSection *
310303 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
311304 Mangler *Mang, const TargetMachine &TM) const;
312305 };
331324 /// getSectionForMergeableConstant - Given a mergeable constant with the
332325 /// specified size and relocation information, return a section that it
333326 /// should be placed in.
334 virtual const Section *
327 virtual const MCSection *
335328 getSectionForMergeableConstant(SectionKind Kind) const;
336329
337330 virtual SectionKind::Kind getKindForNamedSection(const char *Section,
339332 void getSectionFlagsAsString(SectionKind Kind,
340333 SmallVectorImpl &Str) const;
341334
342 virtual const Section *
335 virtual const MCSection *
343336 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
344337 Mangler *Mang, const TargetMachine &TM) const;
345338 protected:
346 const Section *DataRelSection;
347 const Section *DataRelLocalSection;
348 const Section *DataRelROSection;
349 const Section *DataRelROLocalSection;
350
351 const Section *MergeableConst4Section;
352 const Section *MergeableConst8Section;
353 const Section *MergeableConst16Section;
339 const MCSection *DataRelSection;
340 const MCSection *DataRelLocalSection;
341 const MCSection *DataRelROSection;
342 const MCSection *DataRelROLocalSection;
343
344 const MCSection *MergeableConst4Section;
345 const MCSection *MergeableConst8Section;
346 const MCSection *MergeableConst16Section;
354347 };
355348
356349
357350
358351 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
359 const Section *TextCoalSection;
360 const Section *ConstTextCoalSection;
361 const Section *ConstDataCoalSection;
362 const Section *ConstDataSection;
363 const Section *DataCoalSection;
364 const Section *FourByteConstantSection;
365 const Section *EightByteConstantSection;
366 const Section *SixteenByteConstantSection;
352 const MCSection *TextCoalSection;
353 const MCSection *ConstTextCoalSection;
354 const MCSection *ConstDataCoalSection;
355 const MCSection *ConstDataSection;
356 const MCSection *DataCoalSection;
357 const MCSection *FourByteConstantSection;
358 const MCSection *EightByteConstantSection;
359 const MCSection *SixteenByteConstantSection;
367360 public:
368361
369362 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
370363
371 virtual const Section *
364 virtual const MCSection *
372365 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
373366 Mangler *Mang, const TargetMachine &TM) const;
374367
375 virtual const Section *
368 virtual const MCSection *
376369 getSectionForMergeableConstant(SectionKind Kind) const;
377370 };
378371
385378 virtual void getSectionFlagsAsString(SectionKind Kind,
386379 SmallVectorImpl &Str) const;
387380
388 virtual const Section *
381 virtual const MCSection *
389382 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
390383 Mangler *Mang, const TargetMachine &TM) const;
391384 };
2222 #include "llvm/CodeGen/DwarfWriter.h"
2323 #include "llvm/Analysis/DebugInfo.h"
2424 #include "llvm/MC/MCContext.h"
25 #include "llvm/MC/MCInst.h"
26 #include "llvm/MC/MCSection.h"
2527 #include "llvm/MC/MCStreamer.h"
26 #include "llvm/MC/MCInst.h"
2728 #include "llvm/Support/CommandLine.h"
2829 #include "llvm/Support/ErrorHandling.h"
2930 #include "llvm/Support/FormattedStream.h"
131132
132133 /// SwitchToSection - Switch to the specified section of the executable if we
133134 /// are not already in it!
134 void AsmPrinter::SwitchToSection(const Section *NS) {
135 void AsmPrinter::SwitchToSection(const MCSection *NS) {
135136 const std::string &NewSection = NS->getName();
136137
137138 // If we're already in this section, we're done.
307308 namespace {
308309 // SectionCPs - Keep track the alignment, constpool entries per Section.
309310 struct SectionCPs {
310 const Section *S;
311 const MCSection *S;
311312 unsigned Alignment;
312313 SmallVector CPEs;
313 SectionCPs(const Section *s, unsigned a) : S(s), Alignment(a) {};
314 SectionCPs(const MCSection *s, unsigned a) : S(s), Alignment(a) {};
314315 };
315316 }
316317
346347 }
347348 }
348349
349 const Section *S =getObjFileLowering().getSectionForMergeableConstant(Kind);
350 const MCSection *S =
351 getObjFileLowering().getSectionForMergeableConstant(Kind);
350352
351353 // The number of sections are small, just do a linear search from the
352354 // last section to the first.
418420 const char *JumpTableDataSection = TAI->getJumpTableDataSection();
419421 const Function *F = MF.getFunction();
420422
421 const Section *FuncSection =
423 const MCSection *FuncSection =
422424 getObjFileLowering().SectionForGlobal(F, Mang, TM);
423425
424426 bool JTInDiffSection = false;
1313 #include "DwarfDebug.h"
1414 #include "llvm/Module.h"
1515 #include "llvm/CodeGen/MachineModuleInfo.h"
16 #include "llvm/Support/Timer.h"
17 #include "llvm/System/Path.h"
16 #include "llvm/MC/MCSection.h"
1817 #include "llvm/Target/TargetAsmInfo.h"
1918 #include "llvm/Target/TargetData.h"
2019 #include "llvm/Target/TargetFrameInfo.h"
2120 #include "llvm/Target/TargetLoweringObjectFile.h"
2221 #include "llvm/Target/TargetRegisterInfo.h"
22 #include "llvm/Support/Timer.h"
23 #include "llvm/System/Path.h"
2324 using namespace llvm;
2425
2526 static TimerGroup &getDwarfTimerGroup() {
223224 DwarfDebug::DwarfDebug(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
224225 : Dwarf(OS, A, T, "dbg"), ModuleCU(0),
225226 AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(),
226 ValuesSet(InitValuesSetSize), Values(), StringPool(), SectionMap(),
227 ValuesSet(InitValuesSetSize), Values(), StringPool(),
227228 SectionSourceLines(), didInitial(false), shouldEmit(false),
228229 FunctionDbgScope(0), DebugTimer(0) {
229230 if (TimePassesIsEnabled)
21312132 const std::vector &LineInfos = SectionSourceLines[j];
21322133
21332134 if (Asm->isVerbose()) {
2134 const Section* S = SectionMap[j + 1];
2135 const MCSection *S = SectionMap[j + 1];
21352136 O << '\t' << TAI->getCommentString() << " Section"
21362137 << S->getName() << '\n';
21372138 } else {
119119
120120 /// SectionMap - Provides a unique id per text section.
121121 ///
122 UniqueVectorSection*> SectionMap;
122 UniqueVectorMCSection*> SectionMap;
123123
124124 /// SectionSourceLines - Tracks line numbers per text section.
125125 ///
4242 #include "llvm/CodeGen/MachineCodeEmitter.h"
4343 #include "llvm/CodeGen/MachineConstantPool.h"
4444 #include "llvm/MC/MCContext.h"
45 #include "llvm/MC/MCSection.h"
4546 #include "llvm/Target/TargetAsmInfo.h"
4647 #include "llvm/Target/TargetData.h"
4748 #include "llvm/Target/TargetELFWriterInfo.h"
333334 TM.getTargetLowering()->getObjFileLowering();
334335
335336 // Get the ELF section where this global belongs from TLOF
336 const Section *S = TLOF.SectionForGlobal(GV, Mang, TM);
337 unsigned SectionFlags = getElfSectionFlags(S->getKind());
337 const MCSection *S = TLOF.SectionForGlobal(GV, Mang, TM);
338 unsigned SectionFlags = getElfSectionFlags(((MCSectionELF*)S)->getKind());
338339
339340 // The symbol align should update the section alignment if needed
340341 const TargetData *TD = TM.getTargetData();
2626 #include "llvm/CodeGen/MachineModuleInfo.h"
2727 #include "llvm/CodeGen/MachineFunctionPass.h"
2828 #include "llvm/CodeGen/MachineJumpTableInfo.h"
29 #include "llvm/MC/MCSection.h"
2930 #include "llvm/Target/TargetAsmInfo.h"
3031 #include "llvm/Target/TargetData.h"
3132 #include "llvm/Target/TargetLoweringObjectFile.h"
11581159 if (Subtarget->isTargetELF())
11591160 O << "\t.type " << name << ",%object\n";
11601161
1161 const Section *TheSection =
1162 const MCSection *TheSection =
11621163 getObjFileLowering().SectionForGlobal(GVar, Mang, TM);
11631164 SwitchToSection(TheSection);
11641165
3030 #include "llvm/Support/raw_ostream.h"
3131 using namespace llvm;
3232
33
33 namespace {
3434 class TargetLoweringObjectFileAlpha : public TargetLoweringObjectFile {
3535 public:
36 TargetLoweringObjectFileAlpha() {
36 void Initialize(MCContext &Ctx, const TargetMachine &TM) {
37 TargetLoweringObjectFile::Initialize(Ctx, TM);
3738 TextSection = getOrCreateSection("_text", true, SectionKind::Text);
3839 DataSection = getOrCreateSection("_data", true, SectionKind::DataRel);
3940 }
4041 };
42 }
4143
4244
4345
1717 #include "llvm/Function.h"
1818 #include "llvm/Module.h"
1919 #include "llvm/CodeGen/DwarfWriter.h"
20 #include "llvm/Support/FormattedStream.h"
2120 #include "llvm/CodeGen/MachineFrameInfo.h"
22 #include "llvm/Support/Mangler.h"
23 #include "llvm/Support/ErrorHandling.h"
2421 #include "llvm/CodeGen/DwarfWriter.h"
2522 #include "llvm/CodeGen/MachineModuleInfo.h"
23 #include "llvm/MC/MCSection.h"
2624 #include "llvm/Target/TargetRegistry.h"
2725 #include "llvm/Target/TargetLoweringObjectFile.h"
28
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/Support/FormattedStream.h"
28 #include "llvm/Support/Mangler.h"
2929 using namespace llvm;
3030
3131 #include "PIC16GenAsmWriter.inc"
7070 std::string T = PAN::getCodeSectionName(CurrentFnName);
7171 const char *codeSection = T.c_str();
7272
73 const Section *fCodeSection =
73 const MCSection *fCodeSection =
7474 getObjFileLowering().getOrCreateSection(codeSection, false,
7575 SectionKind::Text);
7676 // Start the Code Section.
347347 std::string T = PAN::getFrameSectionName(CurrentFnName);
348348 const char *SectionName = T.c_str();
349349
350 const Section *fPDataSection =
350 const MCSection *fPDataSection =
351351 getObjFileLowering().getOrCreateSection(SectionName, false,
352352 SectionKind::DataRel);
353353 SwitchToSection(fPDataSection);
142142
143143 // PIC16TargetLowering Constructor.
144144 PIC16TargetLowering::PIC16TargetLowering(PIC16TargetMachine &TM)
145 : TargetLowering(TM, new PIC16TargetObjectFile(TM)), TmpSize(0) {
145 : TargetLowering(TM, new PIC16TargetObjectFile()), TmpSize(0) {
146146
147147 Subtarget = &TM.getSubtarget();
148148
1111 #include "PIC16TargetMachine.h"
1212 #include "llvm/DerivedTypes.h"
1313 #include "llvm/Module.h"
14 #include "llvm/MC/MCSection.h"
1415 using namespace llvm;
1516
16
17 PIC16TargetObjectFile::PIC16TargetObjectFile(const PIC16TargetMachine &tm)
18 : TM (tm) {
17 void PIC16TargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &tm){
18 TargetLoweringObjectFile::Initialize(Ctx, tm);
19 TM = &tm;
20
1921 BSSSection_ = getOrCreateSection("udata.# UDATA", false, SectionKind::BSS);
2022 ReadOnlySection = getOrCreateSection("romdata.# ROMDATA", false,
2123 SectionKind::ReadOnly);
2527 // in BeginModule, and gpasm cribbs for that .text symbol.
2628 TextSection = getOrCreateSection("", true, SectionKind::Text);
2729
28
29 PIC16Section *ROSection = new PIC16Section(ReadOnlySection);
30 ROSections.push_back(ROSection);
30 ROSections.push_back(new PIC16Section(ReadOnlySection));
3131
3232 // FIXME: I don't know what the classification of these sections really is.
3333 ExternalVarDecls = new PIC16Section(getOrCreateSection("ExternalVarDecls",
3939 }
4040
4141
42 const Section *
42 const MCSection *
4343 PIC16TargetObjectFile::getBSSSectionForGlobal(const GlobalVariable *GV) const {
4444 assert(GV->hasInitializer() && "This global doesn't need space");
4545 Constant *C = GV->getInitializer();
4646 assert(C->isNullValue() && "Unitialized globals has non-zero initializer");
4747
4848 // Find how much space this global needs.
49 const TargetData *TD = TM.getTargetData();
49 const TargetData *TD = TM->getTargetData();
5050 const Type *Ty = C->getType();
5151 unsigned ValSize = TD->getTypeAllocSize(Ty);
5252
6363 // No BSS section spacious enough was found. Crate a new one.
6464 if (!FoundBSS) {
6565 std::string name = PAN::getUdataSectionName(BSSSections.size());
66 const Section *NewSection = getOrCreateSection(name.c_str(), false,
67 // FIXME.
68 SectionKind::Metadata);
66 const MCSection *NewSection = getOrCreateSection(name.c_str(), false,
67 // FIXME.
68 SectionKind::Metadata);
6969
7070 FoundBSS = new PIC16Section(NewSection);
7171
7979 return FoundBSS->S_;
8080 }
8181
82 const Section *
82 const MCSection *
8383 PIC16TargetObjectFile::getIDATASectionForGlobal(const GlobalVariable *GV) const{
8484 assert(GV->hasInitializer() && "This global doesn't need space");
8585 Constant *C = GV->getInitializer();
8888 "can split initialized RAM data only");
8989
9090 // Find how much space this global needs.
91 const TargetData *TD = TM.getTargetData();
91 const TargetData *TD = TM->getTargetData();
9292 const Type *Ty = C->getType();
9393 unsigned ValSize = TD->getTypeAllocSize(Ty);
9494
105105 // No IDATA section spacious enough was found. Crate a new one.
106106 if (!FoundIDATA) {
107107 std::string name = PAN::getIdataSectionName(IDATASections.size());
108 const Section *NewSection = getOrCreateSection(name.c_str(),
109 false,
108 const MCSection *NewSection = getOrCreateSection(name.c_str(), false,
110109 // FIXME.
111110 SectionKind::Metadata);
112111
124123
125124 // Get the section for an automatic variable of a function.
126125 // For PIC16 they are globals only with mangled names.
127 const Section *
126 const MCSection *
128127 PIC16TargetObjectFile::getSectionForAuto(const GlobalVariable *GV) const {
129128
130129 const std::string name = PAN::getSectionNameForSym(GV->getName());
141140
142141 // No Auto section was found. Crate a new one.
143142 if (!FoundAutoSec) {
144 const Section *NewSection = getOrCreateSection(name.c_str(),
145 // FIXME.
146 false,
147 SectionKind::Metadata);
143 const MCSection *NewSection = getOrCreateSection(name.c_str(),
144 // FIXME.
145 false,
146 SectionKind::Metadata);
148147
149148 FoundAutoSec = new PIC16Section(NewSection);
150149
161160
162161 // Override default implementation to put the true globals into
163162 // multiple data sections if required.
164 const Section*
163 const MCSection *
165164 PIC16TargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV1,
166165 SectionKind Kind,
167166 Mangler *Mang,
223222
224223 /// getSpecialCasedSectionGlobals - Allow the target to completely override
225224 /// section assignment of a global.
226 const Section *
225 const MCSection *
227226 PIC16TargetObjectFile::getSpecialCasedSectionGlobals(const GlobalValue *GV,
228227 Mangler *Mang,
229228 SectionKind Kind) const {
249248
250249 // Create a new section for global variable. If Addr is given then create
251250 // section at that address else create by name.
252 const Section *
251 const MCSection *
253252 PIC16TargetObjectFile::CreateSectionForGlobal(const GlobalVariable *GV,
254253 Mangler *Mang,
255254 const std::string &Addr) const {
267266 return CreateROSectionForGlobal(GV, Addr);
268267
269268 // Else let the default implementation take care of it.
270 return TargetLoweringObjectFile::SectionForGlobal(GV, Mang, TM);
269 return TargetLoweringObjectFile::SectionForGlobal(GV, Mang, *TM);
271270 }
272271
273272 // Create uninitialized section for a variable.
274 const Section *
273 const MCSection *
275274 PIC16TargetObjectFile::CreateBSSSectionForGlobal(const GlobalVariable *GV,
276275 std::string Addr) const {
277276 assert(GV->hasInitializer() && "This global doesn't need space");
296295
297296 PIC16Section *NewBSS = FoundBSS;
298297 if (NewBSS == NULL) {
299 const Section *NewSection = getOrCreateSection(Name.c_str(),
300 false, SectionKind::BSS);
298 const MCSection *NewSection = getOrCreateSection(Name.c_str(), false,
299 SectionKind::BSS);
301300 NewBSS = new PIC16Section(NewSection);
302301 BSSSections.push_back(NewBSS);
303302 }
313312
314313 // Get rom section for a variable. Currently there can be only one rom section
315314 // unless a variable explicitly requests a section.
316 const Section *
315 const MCSection *
317316 PIC16TargetObjectFile::getROSectionForGlobal(const GlobalVariable *GV) const {
318317 ROSections[0]->Items.push_back(GV);
319318 return ROSections[0]->S_;
320319 }
321320
322321 // Create initialized data section for a variable.
323 const Section *
322 const MCSection *
324323 PIC16TargetObjectFile::CreateIDATASectionForGlobal(const GlobalVariable *GV,
325324 std::string Addr) const {
326325 assert(GV->hasInitializer() && "This global doesn't need space");
348347
349348 PIC16Section *NewIDATASec = FoundIDATASec;
350349 if (NewIDATASec == NULL) {
351 const Section *NewSection = getOrCreateSection(Name.c_str(),
352 false,
350 const MCSection *NewSection = getOrCreateSection(Name.c_str(), false,
353351 // FIXME:
354352 SectionKind::Metadata);
355353 NewIDATASec = new PIC16Section(NewSection);
364362 }
365363
366364 // Create a section in rom for a variable.
367 const Section *
365 const MCSection *
368366 PIC16TargetObjectFile::CreateROSectionForGlobal(const GlobalVariable *GV,
369367 std::string Addr) const {
370368 assert(GV->getType()->getAddressSpace() == PIC16ISD::ROM_SPACE &&
389387
390388 PIC16Section *NewRomSec = FoundROSec;
391389 if (NewRomSec == NULL) {
392 const Section *NewSection = getOrCreateSection(Name.c_str(),
393 false,
394 SectionKind::ReadOnly);
390 const MCSection *NewSection = getOrCreateSection(Name.c_str(), false,
391 SectionKind::ReadOnly);
395392 NewRomSec = new PIC16Section(NewSection);
396393 ROSections.push_back(NewRomSec);
397394 }
2828 /// FIXME: Reimplement by inheriting from MCSection.
2929 ///
3030 struct PIC16Section {
31 const Section *S_; // Connection to actual Section.
31 const MCSection *S_; // Connection to actual Section.
3232 unsigned Size; // Total size of the objects contained.
3333 bool SectionPrinted;
3434 std::vector Items;
3535
36 PIC16Section(const Section *s) {
36 PIC16Section(const MCSection *s) {
3737 S_ = s;
3838 Size = 0;
3939 SectionPrinted = false;
4343 };
4444
4545 class PIC16TargetObjectFile : public TargetLoweringObjectFile {
46 const PIC16TargetMachine &TM;
46 const TargetMachine *TM;
4747 public:
4848 mutable std::vector BSSSections;
4949 mutable std::vector IDATASections;
5252 mutable PIC16Section *ExternalVarDecls;
5353 mutable PIC16Section *ExternalVarDefs;
5454
55 PIC16TargetObjectFile(const PIC16TargetMachine &TM);
5655 ~PIC16TargetObjectFile();
56
57 void Initialize(MCContext &Ctx, const TargetMachine &TM);
58
5759
5860 /// getSpecialCasedSectionGlobals - Allow the target to completely override
5961 /// section assignment of a global.
60 virtual const Section *
62 virtual const MCSection *
6163 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
6264 SectionKind Kind) const;
63 virtual const Section *SelectSectionForGlobal(const GlobalValue *GV,
64 SectionKind Kind,
65 Mangler *Mang,
66 const TargetMachine&) const;
65 virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
66 SectionKind Kind,
67 Mangler *Mang,
68 const TargetMachine&) const;
6769 private:
6870 std::string getSectionNameForSym(const std::string &Sym) const;
6971
70 const Section *getBSSSectionForGlobal(const GlobalVariable *GV) const;
71 const Section *getIDATASectionForGlobal(const GlobalVariable *GV) const;
72 const Section *getSectionForAuto(const GlobalVariable *GV) const;
73 const Section *CreateBSSSectionForGlobal(const GlobalVariable *GV,
74 std::string Addr = "") const;
75 const Section *CreateIDATASectionForGlobal(const GlobalVariable *GV,
72 const MCSection *getBSSSectionForGlobal(const GlobalVariable *GV) const;
73 const MCSection *getIDATASectionForGlobal(const GlobalVariable *GV) const;
74 const MCSection *getSectionForAuto(const GlobalVariable *GV) const;
75 const MCSection *CreateBSSSectionForGlobal(const GlobalVariable *GV,
7676 std::string Addr = "") const;
77 const Section *getROSectionForGlobal(const GlobalVariable *GV) const;
78 const Section *CreateROSectionForGlobal(const GlobalVariable *GV,
79 std::string Addr = "") const;
80 const Section *CreateSectionForGlobal(const GlobalVariable *GV,
81 Mangler *Mang,
82 const std::string &Addr = "") const;
77 const MCSection *CreateIDATASectionForGlobal(const GlobalVariable *GV,
78 std::string Addr = "") const;
79 const MCSection *getROSectionForGlobal(const GlobalVariable *GV) const;
80 const MCSection *CreateROSectionForGlobal(const GlobalVariable *GV,
81 std::string Addr = "") const;
82 const MCSection *CreateSectionForGlobal(const GlobalVariable *GV,
83 Mangler *Mang,
84 const std::string &Addr = "") const;
8385 public:
8486 void SetSectionForGVs(Module &M);
8587 const std::vector &getBSSSections() const {
3131 #include "llvm/CodeGen/MachineFunctionPass.h"
3232 #include "llvm/CodeGen/MachineInstr.h"
3333 #include "llvm/CodeGen/MachineInstrBuilder.h"
34 #include "llvm/MC/MCSection.h"
35 #include "llvm/Target/TargetAsmInfo.h"
36 #include "llvm/Target/TargetLoweringObjectFile.h"
37 #include "llvm/Target/TargetRegisterInfo.h"
38 #include "llvm/Target/TargetInstrInfo.h"
39 #include "llvm/Target/TargetOptions.h"
40 #include "llvm/Target/TargetRegistry.h"
3441 #include "llvm/Support/Mangler.h"
3542 #include "llvm/Support/MathExtras.h"
3643 #include "llvm/Support/CommandLine.h"
3845 #include "llvm/Support/ErrorHandling.h"
3946 #include "llvm/Support/Compiler.h"
4047 #include "llvm/Support/FormattedStream.h"
41 #include "llvm/Target/TargetAsmInfo.h"
42 #include "llvm/Target/TargetLoweringObjectFile.h"
43 #include "llvm/Target/TargetRegisterInfo.h"
44 #include "llvm/Target/TargetInstrInfo.h"
45 #include "llvm/Target/TargetOptions.h"
46 #include "llvm/Target/TargetRegistry.h"
4748 #include "llvm/ADT/Statistic.h"
4849 #include "llvm/ADT/StringExtras.h"
4950 #include "llvm/ADT/StringSet.h"
891892 unsigned Size = TD->getTypeAllocSize(Type);
892893 unsigned Align = TD->getPreferredAlignmentLog(GVar);
893894
894 const Section *TheSection =
895 const MCSection *TheSection =
895896 getObjFileLowering().SectionForGlobal(GVar, Mang, TM);
896897 SwitchToSection(TheSection);
897898
1515 #include "llvm/Constants.h"
1616 #include "llvm/DerivedTypes.h"
1717 #include "llvm/GlobalVariable.h"
18 #include "llvm/Support/Mangler.h"
18 #include "llvm/MC/MCContext.h"
19 #include "llvm/MC/MCSection.h"
1920 #include "llvm/Target/TargetMachine.h"
2021 #include "llvm/Target/TargetData.h"
2122 #include "llvm/Target/TargetOptions.h"
23 #include "llvm/Support/Mangler.h"
2224 #include "llvm/ADT/StringExtras.h"
2325 using namespace llvm;
2426
2628 // Generic Code
2729 //===----------------------------------------------------------------------===//
2830
29 TargetLoweringObjectFile::TargetLoweringObjectFile() {
31 TargetLoweringObjectFile::TargetLoweringObjectFile() : Ctx(0) {
3032 TextSection = 0;
3133 DataSection = 0;
3234 BSSSection_ = 0;
175177 /// SectionForGlobal - This method computes the appropriate section to emit
176178 /// the specified global variable or function definition. This should not
177179 /// be passed external (or available externally) globals.
178 const Section *TargetLoweringObjectFile::
180 const MCSection *TargetLoweringObjectFile::
179181 SectionForGlobal(const GlobalValue *GV, Mangler *Mang,
180182 const TargetMachine &TM) const {
181183 assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() &&
191193 if (GV->hasSection()) {
192194 // If the target has special section hacks for specifically named globals,
193195 // return them now.
194 if (const Section *TS = getSpecialCasedSectionGlobals(GV, Mang, Kind))
196 if (const MCSection *TS = getSpecialCasedSectionGlobals(GV, Mang, Kind))
195197 return TS;
196198
197199 // If the target has magic semantics for certain section names, make sure to
208210 }
209211
210212 // Lame default implementation. Calculate the section name for global.
211 const Section*
213 const MCSection *
212214 TargetLoweringObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
213215 SectionKind Kind,
214216 Mangler *Mang,
230232 /// getSectionForMergableConstant - Given a mergable constant with the
231233 /// specified size and relocation information, return a section that it
232234 /// should be placed in.
233 const Section *
235 const MCSection *
234236 TargetLoweringObjectFile::
235237 getSectionForMergeableConstant(SectionKind Kind) const {
236238 if (Kind.isReadOnly() && ReadOnlySection != 0)
240242 }
241243
242244
243 const Section *TargetLoweringObjectFile::
245 const MCSection *TargetLoweringObjectFile::
244246 getOrCreateSection(const char *Name, bool isDirective,
245247 SectionKind::Kind Kind) const {
246 Section &S = Sections[Name];
247
248 // This is newly-created section, set it up properly.
249 if (S.Name.empty()) {
250 S.Kind = SectionKind::get(Kind, false /*weak*/, !isDirective);
251 S.Name = Name;
252 }
253
254 return &S;
248 if (MCSection *S = Ctx->GetSection(Name))
249 return S;
250 SectionKind K = SectionKind::get(Kind, false /*weak*/, !isDirective);
251 return MCSectionWithKind::Create(Name, K, *Ctx);
255252 }
256253
257254
262259
263260 void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
264261 const TargetMachine &TM) {
262 TargetLoweringObjectFile::Initialize(Ctx, TM);
265263 if (!HasCrazyBSS)
266264 BSSSection_ = getOrCreateSection("\t.bss", true, SectionKind::BSS);
267265 else
400398 return ".gnu.linkonce.d.rel.ro.";
401399 }
402400
403 const Section *TargetLoweringObjectFileELF::
401 const MCSection *TargetLoweringObjectFileELF::
404402 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
405403 Mangler *Mang, const TargetMachine &TM) const {
406404
457455 /// getSectionForMergeableConstant - Given a mergeable constant with the
458456 /// specified size and relocation information, return a section that it
459457 /// should be placed in.
460 const Section *TargetLoweringObjectFileELF::
458 const MCSection *TargetLoweringObjectFileELF::
461459 getSectionForMergeableConstant(SectionKind Kind) const {
462460 if (Kind.isMergeableConst4())
463461 return MergeableConst4Section;
479477
480478 void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
481479 const TargetMachine &TM) {
480 TargetLoweringObjectFile::Initialize(Ctx, TM);
482481 TextSection = getOrCreateSection("\t.text", true, SectionKind::Text);
483482 DataSection = getOrCreateSection("\t.data", true, SectionKind::DataRel);
484483
513512 false, SectionKind::DataRel);
514513 }
515514
516 const Section *TargetLoweringObjectFileMachO::
515 const MCSection *TargetLoweringObjectFileMachO::
517516 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
518517 Mangler *Mang, const TargetMachine &TM) const {
519518 assert(!Kind.isThreadLocal() && "Darwin doesn't support TLS");
568567 return DataSection;
569568 }
570569
571 const Section *
570 const MCSection *
572571 TargetLoweringObjectFileMachO::
573572 getSectionForMergeableConstant(SectionKind Kind) const {
574573 // If this constant requires a relocation, we have to put it in the data
591590
592591 void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,
593592 const TargetMachine &TM) {
593 TargetLoweringObjectFile::Initialize(Ctx, TM);
594594 TextSection = getOrCreateSection("\t.text", true, SectionKind::Text);
595595 DataSection = getOrCreateSection("\t.data", true, SectionKind::DataRel);
596596 }
617617 }
618618
619619
620 const Section *TargetLoweringObjectFileCOFF::
620 const MCSection *TargetLoweringObjectFileCOFF::
621621 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
622622 Mangler *Mang, const TargetMachine &TM) const {
623623 assert(!Kind.isThreadLocal() && "Doesn't support TLS");
634634 if (Kind.isText())
635635 return getTextSection();
636636
637 if (Kind.isBSS())
638 if (const Section *S = BSSSection_)
639 return S;
637 if (Kind.isBSS() && BSSSection_ != 0)
638 return BSSSection_;
640639
641640 if (Kind.isReadOnly() && ReadOnlySection != 0)
642641 return ReadOnlySection;
2828 #include "llvm/ADT/StringExtras.h"
2929 #include "llvm/MC/MCContext.h"
3030 #include "llvm/MC/MCInst.h"
31 #include "llvm/MC/MCSection.h"
3132 #include "llvm/MC/MCStreamer.h"
3233 #include "llvm/CodeGen/DwarfWriter.h"
3334 #include "llvm/CodeGen/MachineJumpTableInfo.h"
782783 if (Subtarget->isTargetELF())
783784 O << "\t.type\t" << name << ",@object\n";
784785
785 const Section *TheSection =
786 const MCSection *TheSection =
786787 getObjFileLowering().SectionForGlobal(GVar, Mang, TM);
787788 SwitchToSection(TheSection);
788789
5555 }
5656
5757 XCoreTargetLowering::XCoreTargetLowering(XCoreTargetMachine &XTM)
58 : TargetLowering(XTM,
59 new XCoreTargetObjectFile(XTM.getSubtargetImpl()->isXS1A())),
58 : TargetLowering(XTM, new XCoreTargetObjectFile()),
6059 TM(XTM),
6160 Subtarget(*XTM.getSubtargetImpl()) {
6261
77 //===----------------------------------------------------------------------===//
88
99 #include "XCoreTargetObjectFile.h"
10 #include "XCoreSubtarget.h"
11 #include "llvm/Target/TargetMachine.h"
1012 using namespace llvm;
1113
1214
13 XCoreTargetObjectFile::XCoreTargetObjectFile(bool isXS1A) {
15 void XCoreTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
16 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
17
1418 TextSection = getOrCreateSection("\t.text", true, SectionKind::Text);
1519 DataSection = getOrCreateSection("\t.dp.data", false, SectionKind::DataRel);
1620 BSSSection_ = getOrCreateSection("\t.dp.bss", false, SectionKind::BSS);
2125 TLSDataSection = DataSection;
2226 TLSBSSSection = BSSSection_;
2327
24 if (isXS1A)
28 if (TM.getSubtarget().isXS1A())
2529 // FIXME: Why is this writable ("datarel")???
2630 ReadOnlySection = getOrCreateSection("\t.dp.rodata", false,
2731 SectionKind::DataRel);
2832 else
2933 ReadOnlySection = getOrCreateSection("\t.cp.rodata", false,
3034 SectionKind::ReadOnly);
31 }
35 }
1515
1616 class XCoreTargetObjectFile : public TargetLoweringObjectFileELF {
1717 public:
18 XCoreTargetObjectFile(bool isXS1A);
1918
19 void Initialize(MCContext &Ctx, const TargetMachine &TM);
20
2021 // TODO: Classify globals as xcore wishes.
2122 };
2223 } // end namespace llvm
None ; RUN: llvm-as < %s | llc -march=xcore > %t1.s
1 ; RUN: grep "xor" %t1.s | count 1
0 ; RUN: llvm-as < %s | llc -march=xcore | grep "xor" | count 1
21 define i1 @test(double %F) nounwind {
32 entry:
43 %0 = fsub double -0.000000e+00, %F