llvm.org GIT mirror llvm / a5574d6
Remove DataLayout from TargetLoweringObjectFile, redirect to Module Summary: This change is part of a series of commits dedicated to have a single DataLayout during compilation by using always the one owned by the module. Reviewers: echristo Subscribers: yaron.keren, rafael, llvm-commits, jholewinski Differential Revision: http://reviews.llvm.org/D11079 From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242385 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 5 years ago
15 changed file(s) with 61 addition(s) and 64 deletion(s). Raw diff Collapse all Expand all
4040
4141 ~TargetLoweringObjectFileELF() override {}
4242
43 void emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &TM,
43 void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
4444 const MCSymbol *Sym) const override;
4545
4646 /// Given a constant with the SectionKind, return a section that it should be
4747 /// placed in.
48 MCSection *getSectionForConstant(SectionKind Kind,
48 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
4949 const Constant *C) const override;
5050
5151 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
102102 Mangler &Mang,
103103 const TargetMachine &TM) const override;
104104
105 MCSection *getSectionForConstant(SectionKind Kind,
105 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
106106 const Constant *C) const override;
107107
108108 /// The mach-o version of this method defaults to returning a stub reference.
4141 void operator=(const TargetLoweringObjectFile&) = delete;
4242
4343 protected:
44 const DataLayout *DL;
4544 bool SupportIndirectSymViaGOTPCRel;
4645 bool SupportGOTPCRelWithOffset;
4746
4847 public:
4948 MCContext &getContext() const { return *Ctx; }
5049
51 TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(nullptr), DL(nullptr),
52 SupportIndirectSymViaGOTPCRel(false),
53 SupportGOTPCRelWithOffset(true) {}
50 TargetLoweringObjectFile()
51 : MCObjectFileInfo(), Ctx(nullptr), SupportIndirectSymViaGOTPCRel(false),
52 SupportGOTPCRelWithOffset(true) {}
5453
5554 virtual ~TargetLoweringObjectFile();
5655
5958 /// implementations a chance to set up their default sections.
6059 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
6160
62 virtual void emitPersonalityValue(MCStreamer &Streamer,
63 const TargetMachine &TM,
61 virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
6462 const MCSymbol *Sym) const;
6563
6664 /// Emit the module flags that the platform cares about.
7068
7169 /// Given a constant with the SectionKind, return a section that it should be
7270 /// placed in.
73 virtual MCSection *getSectionForConstant(SectionKind Kind,
71 virtual MCSection *getSectionForConstant(const DataLayout &DL,
72 SectionKind Kind,
7473 const Constant *C) const;
7574
7675 /// Classify the specified global variable into a set of target independent
136136
137137 /// getDataLayout - Return information about data layout.
138138 const DataLayout &AsmPrinter::getDataLayout() const {
139 return *TM.getDataLayout();
139 return MMI->getModule()->getDataLayout();
140140 }
141141
142142 unsigned AsmPrinter::getPointerSize() const { return TM.getDataLayout()->getPointerSize(); }
376376
377377 SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
378378
379 const DataLayout *DL = TM.getDataLayout();
380 uint64_t Size = DL->getTypeAllocSize(GV->getType()->getElementType());
379 const DataLayout &DL = GV->getParent()->getDataLayout();
380 uint64_t Size = DL.getTypeAllocSize(GV->getType()->getElementType());
381381
382382 // If the alignment is specified, we *must* obey it. Overaligning a global
383383 // with a specified alignment is a prompt way to break globals emitted to
384384 // sections and expected to be contiguous (e.g. ObjC metadata).
385 unsigned AlignLog = getGVAlignmentLog2(GV, *DL);
385 unsigned AlignLog = getGVAlignmentLog2(GV, DL);
386386
387387 for (const HandlerInfo &HI : Handlers) {
388388 NamedRegionTimer T(HI.TimerName, HI.TimerGroupName, TimePassesIsEnabled);
491491 // - __tlv_bootstrap - used to make sure support exists
492492 // - spare pointer, used when mapped by the runtime
493493 // - pointer to mangled symbol above with initializer
494 unsigned PtrSize = DL->getPointerTypeSize(GV->getType());
494 unsigned PtrSize = DL.getPointerTypeSize(GV->getType());
495495 OutStreamer->EmitSymbolValue(GetExternalSymbolSymbol("_tlv_bootstrap"),
496496 PtrSize);
497497 OutStreamer->EmitIntValue(0, PtrSize);
11211121
11221122 // Emit __morestack address if needed for indirect calls.
11231123 if (MMI->usesMorestackAddr()) {
1124 MCSection *ReadOnlySection =
1125 getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly(),
1126 /*C=*/nullptr);
1124 MCSection *ReadOnlySection = getObjFileLowering().getSectionForConstant(
1125 getDataLayout(), SectionKind::getReadOnly(), /*C=*/nullptr);
11271126 OutStreamer->SwitchSection(ReadOnlySection);
11281127
11291128 MCSymbol *AddrSymbol =
12141213 if (!CPE.isMachineConstantPoolEntry())
12151214 C = CPE.Val.ConstVal;
12161215
1217 MCSection *S = getObjFileLowering().getSectionForConstant(Kind, C);
1216 MCSection *S =
1217 getObjFileLowering().getSectionForConstant(getDataLayout(), Kind, C);
12181218
12191219 // The number of sections are small, just do a linear search from the
12201220 // last section to the first.
8282 if (!Personalities[i])
8383 continue;
8484 MCSymbol *Sym = Asm->getSymbol(Personalities[i]);
85 TLOF.emitPersonalityValue(*Asm->OutStreamer, Asm->TM, Sym);
85 TLOF.emitPersonalityValue(*Asm->OutStreamer, Asm->getDataLayout(), Sym);
8686 }
8787 }
8888
5757 report_fatal_error("We do not support this DWARF encoding yet!");
5858 }
5959
60 void TargetLoweringObjectFileELF::emitPersonalityValue(MCStreamer &Streamer,
61 const TargetMachine &TM,
62 const MCSymbol *Sym) const {
60 void TargetLoweringObjectFileELF::emitPersonalityValue(
61 MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym) const {
6362 SmallString<64> NameData("DW.ref.");
6463 NameData += Sym->getName();
6564 MCSymbolELF *Label =
7170 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP;
7271 MCSection *Sec = getContext().getELFSection(NameData, ELF::SHT_PROGBITS,
7372 Flags, 0, Label->getName());
74 unsigned Size = TM.getDataLayout()->getPointerSize();
73 unsigned Size = DL.getPointerSize();
7574 Streamer.SwitchSection(Sec);
76 Streamer.EmitValueToAlignment(TM.getDataLayout()->getPointerABIAlignment());
75 Streamer.EmitValueToAlignment(DL.getPointerABIAlignment());
7776 Streamer.EmitSymbolAttribute(Label, MCSA_ELF_TypeObject);
7877 const MCExpr *E = MCConstantExpr::create(Size, getContext());
7978 Streamer.emitELFSize(Label, E);
281280 // We also need alignment here.
282281 // FIXME: this is getting the alignment of the character, not the
283282 // alignment of the global!
284 unsigned Align =
285 TM.getDataLayout()->getPreferredAlignment(cast(GV));
283 unsigned Align = GV->getParent()->getDataLayout().getPreferredAlignment(
284 cast(GV));
286285
287286 std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
288287 Name = SizeSpec + utostr(Align);
349348
350349 /// Given a mergeable constant with the specified size and relocation
351350 /// information, return a section that it should be placed in.
352 MCSection *
353 TargetLoweringObjectFileELF::getSectionForConstant(SectionKind Kind,
354 const Constant *C) const {
351 MCSection *TargetLoweringObjectFileELF::getSectionForConstant(
352 const DataLayout &DL, SectionKind Kind, const Constant *C) const {
355353 if (Kind.isMergeableConst4() && MergeableConst4Section)
356354 return MergeableConst4Section;
357355 if (Kind.isMergeableConst8() && MergeableConst8Section)
588586
589587 // FIXME: Alignment check should be handled by section classifier.
590588 if (Kind.isMergeable1ByteCString() &&
591 TM.getDataLayout()->getPreferredAlignment(cast(GV)) < 32)
589 GV->getParent()->getDataLayout().getPreferredAlignment(
590 cast(GV)) < 32)
592591 return CStringSection;
593592
594593 // Do not put 16-bit arrays in the UString section if they have an
595594 // externally visible label, this runs into issues with certain linker
596595 // versions.
597596 if (Kind.isMergeable2ByteCString() && !GV->hasExternalLinkage() &&
598 TM.getDataLayout()->getPreferredAlignment(cast(GV)) < 32)
597 GV->getParent()->getDataLayout().getPreferredAlignment(
598 cast(GV)) < 32)
599599 return UStringSection;
600600
601601 // With MachO only variables whose corresponding symbol starts with 'l' or
633633 return DataSection;
634634 }
635635
636 MCSection *
637 TargetLoweringObjectFileMachO::getSectionForConstant(SectionKind Kind,
638 const Constant *C) const {
636 MCSection *TargetLoweringObjectFileMachO::getSectionForConstant(
637 const DataLayout &DL, SectionKind Kind, const Constant *C) const {
639638 // If this constant requires a relocation, we have to put it in the data
640639 // segment, not in the text segment.
641640 if (Kind.isDataRel() || Kind.isReadOnlyWithRel())
739738 // non_lazy_ptr stubs.
740739 SmallString<128> Name;
741740 StringRef Suffix = "$non_lazy_ptr";
742 Name += DL->getPrivateGlobalPrefix();
741 Name += MMI->getModule()->getDataLayout().getPrivateGlobalPrefix();
743742 Name += Sym->getName();
744743 Name += Suffix;
745744 MCSymbol *Stub = Ctx.getOrCreateSymbol(Name);
10421041 raw_string_ostream FlagOS(Flag);
10431042 Mang.getNameWithPrefix(FlagOS, GV, false);
10441043 FlagOS.flush();
1045 if (Flag[0] == DL->getGlobalPrefix())
1044 if (Flag[0] == GV->getParent()->getDataLayout().getGlobalPrefix())
10461045 OS << Flag.substr(1);
10471046 else
10481047 OS << Flag;
106106 return false;
107107
108108 Type *Ty = GV->getType()->getElementType();
109 return IsInSmallSection(TM.getDataLayout()->getTypeAllocSize(Ty));
109 return IsInSmallSection(
110 GV->getParent()->getDataLayout().getTypeAllocSize(Ty));
110111 }
111112
112113 MCSection *
136137 CN->getType())));
137138 }
138139
139 MCSection *
140 MipsTargetObjectFile::getSectionForConstant(SectionKind Kind,
141 const Constant *C) const {
140 /// Return true if this constant should be placed into small data section.
141 MCSection *MipsTargetObjectFile::getSectionForConstant(
142 const DataLayout &DL, SectionKind Kind, const Constant *C) const {
142143 if (IsConstantInSmallSection(C, *TM))
143144 return SmallDataSection;
144145
145146 // Otherwise, we work the same as ELF.
146 return TargetLoweringObjectFileELF::getSectionForConstant(Kind, C);
147 return TargetLoweringObjectFileELF::getSectionForConstant(DL, Kind, C);
147148 }
3838 bool IsConstantInSmallSection(const Constant *CN,
3939 const TargetMachine &TM) const;
4040
41 MCSection *getSectionForConstant(SectionKind Kind,
41 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
4242 const Constant *C) const override;
4343 };
4444 } // end namespace llvm
8383 new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
8484 }
8585
86 MCSection *getSectionForConstant(SectionKind Kind,
86 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
8787 const Constant *C) const override {
8888 return ReadOnlySection;
8989 }
4242 void TargetLoweringObjectFile::Initialize(MCContext &ctx,
4343 const TargetMachine &TM) {
4444 Ctx = &ctx;
45 DL = TM.getDataLayout();
4645 InitMCObjectFileInfo(TM.getTargetTriple(), TM.getRelocationModel(),
4746 TM.getCodeModel(), *Ctx);
4847 }
106105 assert(!Suffix.empty());
107106
108107 SmallString<60> NameStr;
109 NameStr += DL->getPrivateGlobalPrefix();
108 NameStr += GV->getParent()->getDataLayout().getPrivateGlobalPrefix();
110109 TM.getNameWithPrefix(NameStr, GV, Mang);
111110 NameStr.append(Suffix.begin(), Suffix.end());
112111 return Ctx->getOrCreateSymbol(NameStr);
119118 }
120119
121120 void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
122 const TargetMachine &TM,
121 const DataLayout &,
123122 const MCSymbol *Sym) const {
124123 }
125124
199198 // Otherwise, just drop it into a mergable constant section. If we have
200199 // a section for this size, use it, otherwise use the arbitrary sized
201200 // mergable section.
202 switch (TM.getDataLayout()->getTypeAllocSize(C->getType())) {
201 switch (GV->getParent()->getDataLayout().getTypeAllocSize(C->getType())) {
203202 case 4: return SectionKind::getMergeableConst4();
204203 case 8: return SectionKind::getMergeableConst8();
205204 case 16: return SectionKind::getMergeableConst16();
272271
273272 MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
274273 const Function &F, Mangler &Mang, const TargetMachine &TM) const {
275 return getSectionForConstant(SectionKind::getReadOnly(), /*C=*/nullptr);
274 return getSectionForConstant(F.getParent()->getDataLayout(),
275 SectionKind::getReadOnly(), /*C=*/nullptr);
276276 }
277277
278278 bool TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection(
295295
296296 /// Given a mergable constant with the specified size and relocation
297297 /// information, return a section that it should be placed in.
298 MCSection *
299 TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind,
300 const Constant *C) const {
298 MCSection *TargetLoweringObjectFile::getSectionForConstant(
299 const DataLayout &DL, SectionKind Kind, const Constant *C) const {
301300 if (Kind.isReadOnly() && ReadOnlySection != nullptr)
302301 return ReadOnlySection;
303302
4545 DwarfRangesSection = nullptr;
4646 }
4747
48 MCSection *getSectionForConstant(SectionKind Kind,
48 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
4949 const Constant *C) const override {
5050 return ReadOnlySection;
5151 }
564564 const MachineConstantPoolEntry &CPE =
565565 MF->getConstantPool()->getConstants()[CPID];
566566 if (!CPE.isMachineConstantPoolEntry()) {
567 SectionKind Kind = CPE.getSectionKind(TM.getDataLayout());
567 const DataLayout &DL = MF->getDataLayout();
568 SectionKind Kind = CPE.getSectionKind(&DL);
568569 const Constant *C = CPE.Val.ConstVal;
569570 if (const MCSectionCOFF *S = dyn_cast(
570 getObjFileLowering().getSectionForConstant(Kind, C))) {
571 getObjFileLowering().getSectionForConstant(DL, Kind, C))) {
571572 if (MCSymbol *Sym = S->getCOMDATSymbol()) {
572573 if (Sym->isUndefined())
573574 OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global);
151151 }
152152 }
153153
154 MCSection *
155 X86WindowsTargetObjectFile::getSectionForConstant(SectionKind Kind,
156 const Constant *C) const {
154 MCSection *X86WindowsTargetObjectFile::getSectionForConstant(
155 const DataLayout &DL, SectionKind Kind, const Constant *C) const {
157156 if (Kind.isMergeableConst() && C) {
158157 const unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
159158 COFF::IMAGE_SCN_MEM_READ |
170169 COFF::IMAGE_COMDAT_SELECT_ANY);
171170 }
172171
173 return TargetLoweringObjectFile::getSectionForConstant(Kind, C);
172 return TargetLoweringObjectFile::getSectionForConstant(DL, Kind, C);
174173 }
5757
5858 /// \brief Given a mergeable constant with the specified size and relocation
5959 /// information, return a section that it should be placed in.
60 MCSection *getSectionForConstant(SectionKind Kind,
60 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
6161 const Constant *C) const override;
6262 };
6363
141141 report_fatal_error("Target does not support TLS or Common sections");
142142 }
143143
144 MCSection *
145 XCoreTargetObjectFile::getSectionForConstant(SectionKind Kind,
146 const Constant *C) const {
144 MCSection *XCoreTargetObjectFile::getSectionForConstant(
145 const DataLayout &DL, SectionKind Kind, const Constant *C) const {
147146 if (Kind.isMergeableConst4()) return MergeableConst4Section;
148147 if (Kind.isMergeableConst8()) return MergeableConst8Section;
149148 if (Kind.isMergeableConst16()) return MergeableConst16Section;
3232 Mangler &Mang,
3333 const TargetMachine &TM) const override;
3434
35 MCSection *getSectionForConstant(SectionKind Kind,
35 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
3636 const Constant *C) const override;
3737 };
3838 } // end namespace llvm