Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 2a1c1c9

Browse files
committed
Refactor duplicated code.
No intended functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224935 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9798b27 commit 2a1c1c9

15 files changed

+74
-104
lines changed

include/llvm/CodeGen/TargetLoweringObjectFileImpl.h

-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
8989
ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
9090
Mangler &Mang, const TargetMachine &TM) const override;
9191

92-
bool isSectionAtomizableBySymbols(const MCSection &Section) const override;
93-
9492
const MCSection *
9593
SelectSectionForGlobal(const GlobalValue *GV,
9694
SectionKind Kind, Mangler &Mang,

include/llvm/MC/MCAsmBackend.h

-8
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ class MCAsmBackend {
6767
return false;
6868
}
6969

70-
/// isSectionAtomizable - Check whether the given section can be split into
71-
/// atoms.
72-
///
73-
/// \see MCAssembler::isSymbolLinkerVisible().
74-
virtual bool isSectionAtomizable(const MCSection &Section) const {
75-
return true;
76-
}
77-
7870
/// @name Target Fixup Interfaces
7971
/// @{
8072

include/llvm/MC/MCAsmInfo.h

+6
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,12 @@ class MCAsmInfo {
382382
return nullptr;
383383
}
384384

385+
/// \brief True if the section is atomized using the symbols in it.
386+
/// This is false if the section is not atomized at all (most ELF sections) or
387+
/// if it is atomized based on its contents (MachO' __TEXT,__cstring for
388+
/// example).
389+
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const;
390+
385391
virtual const MCExpr *getExprForPersonalitySymbol(const MCSymbol *Sym,
386392
unsigned Encoding,
387393
MCStreamer &Streamer) const;

include/llvm/MC/MCAsmInfoDarwin.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
namespace llvm {
2121
class MCAsmInfoDarwin : public MCAsmInfo {
22-
virtual void anchor();
2322
public:
2423
explicit MCAsmInfoDarwin();
24+
bool isSectionAtomizableBySymbols(const MCSection &Section) const override;
2525
};
2626
}
2727

include/llvm/Target/TargetLoweringObjectFile.h

-6
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,6 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
151151
return nullptr;
152152
}
153153

154-
/// \brief True if the section is atomized using the symbols in it.
155-
/// This is false if the section is not atomized at all (most ELF sections) or
156-
/// if it is atomized based on its contents (MachO' __TEXT,__cstring for
157-
/// example).
158-
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const;
159-
160154
protected:
161155
virtual const MCSection *
162156
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,

lib/CodeGen/TargetLoweringObjectFileImpl.cpp

-54
Original file line numberDiff line numberDiff line change
@@ -573,60 +573,6 @@ const MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal(
573573
return S;
574574
}
575575

576-
bool TargetLoweringObjectFileMachO::isSectionAtomizableBySymbols(
577-
const MCSection &Section) const {
578-
const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
579-
580-
// Sections holding 1 byte strings are atomized based on the data
581-
// they contain.
582-
// Sections holding 2 byte strings require symbols in order to be
583-
// atomized.
584-
// There is no dedicated section for 4 byte strings.
585-
if (SMO.getKind().isMergeable1ByteCString())
586-
return false;
587-
588-
if (SMO.getSegmentName() == "__TEXT" &&
589-
SMO.getSectionName() == "__objc_classname" &&
590-
SMO.getType() == MachO::S_CSTRING_LITERALS)
591-
return false;
592-
593-
if (SMO.getSegmentName() == "__TEXT" &&
594-
SMO.getSectionName() == "__objc_methname" &&
595-
SMO.getType() == MachO::S_CSTRING_LITERALS)
596-
return false;
597-
598-
if (SMO.getSegmentName() == "__TEXT" &&
599-
SMO.getSectionName() == "__objc_methtype" &&
600-
SMO.getType() == MachO::S_CSTRING_LITERALS)
601-
return false;
602-
603-
if (SMO.getSegmentName() == "__DATA" &&
604-
SMO.getSectionName() == "__cfstring")
605-
return false;
606-
607-
// no_dead_strip sections are not atomized in practice.
608-
if (SMO.hasAttribute(MachO::S_ATTR_NO_DEAD_STRIP))
609-
return false;
610-
611-
switch (SMO.getType()) {
612-
default:
613-
return true;
614-
615-
// These sections are atomized at the element boundaries without using
616-
// symbols.
617-
case MachO::S_4BYTE_LITERALS:
618-
case MachO::S_8BYTE_LITERALS:
619-
case MachO::S_16BYTE_LITERALS:
620-
case MachO::S_LITERAL_POINTERS:
621-
case MachO::S_NON_LAZY_SYMBOL_POINTERS:
622-
case MachO::S_LAZY_SYMBOL_POINTERS:
623-
case MachO::S_MOD_INIT_FUNC_POINTERS:
624-
case MachO::S_MOD_TERM_FUNC_POINTERS:
625-
case MachO::S_INTERPOSING:
626-
return false;
627-
}
628-
}
629-
630576
const MCSection *TargetLoweringObjectFileMachO::
631577
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
632578
Mangler &Mang, const TargetMachine &TM) const {

lib/MC/MCAsmInfo.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ MCAsmInfo::MCAsmInfo() {
109109
MCAsmInfo::~MCAsmInfo() {
110110
}
111111

112+
bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const {
113+
return false;
114+
}
115+
112116
const MCExpr *
113117
MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
114118
unsigned Encoding,

lib/MC/MCAsmInfoDarwin.cpp

+52-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,61 @@
1515
#include "llvm/MC/MCAsmInfoDarwin.h"
1616
#include "llvm/MC/MCContext.h"
1717
#include "llvm/MC/MCExpr.h"
18+
#include "llvm/MC/MCSectionMachO.h"
1819
#include "llvm/MC/MCStreamer.h"
1920
using namespace llvm;
2021

21-
void MCAsmInfoDarwin::anchor() { }
22+
bool MCAsmInfoDarwin::isSectionAtomizableBySymbols(
23+
const MCSection &Section) const {
24+
const MCSectionMachO &SMO = static_cast<const MCSectionMachO &>(Section);
25+
26+
// Sections holding 1 byte strings are atomized based on the data they
27+
// contain.
28+
// Sections holding 2 byte strings require symbols in order to be atomized.
29+
// There is no dedicated section for 4 byte strings.
30+
if (SMO.getKind().isMergeable1ByteCString())
31+
return false;
32+
33+
if (SMO.getSegmentName() == "__TEXT" &&
34+
SMO.getSectionName() == "__objc_classname" &&
35+
SMO.getType() == MachO::S_CSTRING_LITERALS)
36+
return false;
37+
38+
if (SMO.getSegmentName() == "__TEXT" &&
39+
SMO.getSectionName() == "__objc_methname" &&
40+
SMO.getType() == MachO::S_CSTRING_LITERALS)
41+
return false;
42+
43+
if (SMO.getSegmentName() == "__TEXT" &&
44+
SMO.getSectionName() == "__objc_methtype" &&
45+
SMO.getType() == MachO::S_CSTRING_LITERALS)
46+
return false;
47+
48+
if (SMO.getSegmentName() == "__DATA" && SMO.getSectionName() == "__cfstring")
49+
return false;
50+
51+
// no_dead_strip sections are not atomized in practice.
52+
if (SMO.hasAttribute(MachO::S_ATTR_NO_DEAD_STRIP))
53+
return false;
54+
55+
switch (SMO.getType()) {
56+
default:
57+
return true;
58+
59+
// These sections are atomized at the element boundaries without using
60+
// symbols.
61+
case MachO::S_4BYTE_LITERALS:
62+
case MachO::S_8BYTE_LITERALS:
63+
case MachO::S_16BYTE_LITERALS:
64+
case MachO::S_LITERAL_POINTERS:
65+
case MachO::S_NON_LAZY_SYMBOL_POINTERS:
66+
case MachO::S_LAZY_SYMBOL_POINTERS:
67+
case MachO::S_MOD_INIT_FUNC_POINTERS:
68+
case MachO::S_MOD_TERM_FUNC_POINTERS:
69+
case MachO::S_INTERPOSING:
70+
return false;
71+
}
72+
}
2273

2374
MCAsmInfoDarwin::MCAsmInfoDarwin() {
2475
// Common settings for all Darwin targets.

lib/MC/MCAssembler.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "llvm/ADT/StringExtras.h"
1313
#include "llvm/ADT/Twine.h"
1414
#include "llvm/MC/MCAsmBackend.h"
15+
#include "llvm/MC/MCAsmInfo.h"
1516
#include "llvm/MC/MCAsmLayout.h"
1617
#include "llvm/MC/MCCodeEmitter.h"
1718
#include "llvm/MC/MCContext.h"
@@ -448,8 +449,8 @@ const MCSymbolData *MCAssembler::getAtom(const MCSymbolData *SD) const {
448449

449450
// Non-linker visible symbols in sections which can't be atomized have no
450451
// defining atom.
451-
if (!getBackend().isSectionAtomizable(
452-
SD->getFragment()->getParent()->getSection()))
452+
if (!getContext().getAsmInfo()->isSectionAtomizableBySymbols(
453+
SD->getFragment()->getParent()->getSection()))
453454
return nullptr;
454455

455456
// Otherwise, return the atom for the containing fragment.

lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
namespace llvm {
2222

2323
class ARMMCAsmInfoDarwin : public MCAsmInfoDarwin {
24-
void anchor() override;
24+
virtual void anchor();
25+
2526
public:
2627
explicit ARMMCAsmInfoDarwin(StringRef TT);
2728
};

lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace llvm {
2121
class Triple;
2222

2323
class PPCMCAsmInfoDarwin : public MCAsmInfoDarwin {
24-
void anchor() override;
24+
virtual void anchor();
25+
2526
public:
2627
explicit PPCMCAsmInfoDarwin(bool is64Bit, const Triple&);
2728
};

lib/Target/TargetLoweringObjectFile.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,6 @@ SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
270270
return SelectSectionForGlobal(GV, Kind, Mang, TM);
271271
}
272272

273-
bool TargetLoweringObjectFile::isSectionAtomizableBySymbols(
274-
const MCSection &Section) const {
275-
return false;
276-
}
277-
278-
279273
/// getSectionForConstant - Given a mergable constant with the
280274
/// specified size and relocation information, return a section that it
281275
/// should be placed in.

lib/Target/TargetMachine.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ void TargetMachine::getNameWithPrefix(SmallVectorImpl<char> &Name,
182182
const TargetLoweringObjectFile &TLOF =
183183
getSubtargetImpl()->getTargetLowering()->getObjFileLowering();
184184
const MCSection *TheSection = TLOF.SectionForGlobal(GV, GVKind, Mang, *this);
185-
bool CannotUsePrivateLabel = TLOF.isSectionAtomizableBySymbols(*TheSection);
185+
bool CannotUsePrivateLabel =
186+
AsmInfo->isSectionAtomizableBySymbols(*TheSection);
186187
Mang.getNameWithPrefix(Name, GV, CannotUsePrivateLabel);
187188
}
188189

lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -790,26 +790,6 @@ class DarwinX86_64AsmBackend : public DarwinX86AsmBackend {
790790
return SMO.getType() == MachO::S_CSTRING_LITERALS;
791791
}
792792

793-
bool isSectionAtomizable(const MCSection &Section) const override {
794-
const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
795-
// Fixed sized data sections are uniqued, they cannot be diced into atoms.
796-
switch (SMO.getType()) {
797-
default:
798-
return true;
799-
800-
case MachO::S_4BYTE_LITERALS:
801-
case MachO::S_8BYTE_LITERALS:
802-
case MachO::S_16BYTE_LITERALS:
803-
case MachO::S_LITERAL_POINTERS:
804-
case MachO::S_NON_LAZY_SYMBOL_POINTERS:
805-
case MachO::S_LAZY_SYMBOL_POINTERS:
806-
case MachO::S_MOD_INIT_FUNC_POINTERS:
807-
case MachO::S_MOD_TERM_FUNC_POINTERS:
808-
case MachO::S_INTERPOSING:
809-
return false;
810-
}
811-
}
812-
813793
/// \brief Generate the compact unwind encoding for the CFI instructions.
814794
uint32_t generateCompactUnwindEncoding(
815795
ArrayRef<MCCFIInstruction> Instrs) const override {

lib/Target/X86/MCTargetDesc/X86MCAsmInfo.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ namespace llvm {
2323
class Triple;
2424

2525
class X86MCAsmInfoDarwin : public MCAsmInfoDarwin {
26-
void anchor() override;
26+
virtual void anchor();
27+
2728
public:
2829
explicit X86MCAsmInfoDarwin(const Triple &Triple);
2930
};

0 commit comments

Comments
 (0)