Skip to content

Commit 682f07b

Browse files
committed
Rework based on reviewer comment.
1 parent 1ca5fdc commit 682f07b

11 files changed

+258
-260
lines changed

llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ class TargetLoweringObjectFileXCOFF : public TargetLoweringObjectFile {
316316
};
317317

318318
class TargetLoweringObjectFileGOFF : public TargetLoweringObjectFile {
319+
std::string DefaultRootSDName;
320+
std::string DefaultADAPRName;
319321
public:
320322
TargetLoweringObjectFileGOFF();
321323
~TargetLoweringObjectFileGOFF() override = default;

llvm/include/llvm/MC/MCContext.h

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,21 @@ class MCContext {
270270
}
271271
};
272272

273+
struct GOFFSectionKey {
274+
std::string SectionName;
275+
GOFF::ESDSymbolType SymbolType;
276+
277+
GOFFSectionKey(StringRef SectionName, GOFF::ESDSymbolType SymbolType)
278+
: SectionName(SectionName), SymbolType(SymbolType) {}
279+
280+
bool operator<(const GOFFSectionKey &Other) const {
281+
if (SymbolType == Other.SymbolType) {
282+
return SectionName < Other.SectionName;
283+
}
284+
return SymbolType < Other.SymbolType;
285+
}
286+
};
287+
273288
struct WasmSectionKey {
274289
std::string SectionName;
275290
StringRef GroupName;
@@ -323,7 +338,7 @@ class MCContext {
323338
StringMap<MCSectionMachO *> MachOUniquingMap;
324339
std::map<COFFSectionKey, MCSectionCOFF *> COFFUniquingMap;
325340
StringMap<MCSectionELF *> ELFUniquingMap;
326-
std::map<std::string, MCSectionGOFF *> GOFFUniquingMap;
341+
std::map<GOFFSectionKey, MCSectionGOFF *> GOFFUniquingMap;
327342
std::map<WasmSectionKey, MCSectionWasm *> WasmUniquingMap;
328343
std::map<XCOFFSectionKey, MCSectionXCOFF *> XCOFFUniquingMap;
329344
StringMap<MCSectionDXContainer *> DXCUniquingMap;
@@ -601,35 +616,22 @@ class MCContext {
601616
unsigned EntrySize);
602617

603618
private:
604-
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef SDName,
605-
GOFF::SDAttr SDAttributes, StringRef EDName,
606-
GOFF::EDAttr EDAttributes, StringRef LDorPRName,
607-
GOFF::LDAttr LDAttributes,
608-
GOFF::PRAttr PRAttributes,
609-
MCSectionGOFF::SectionFlags Flags);
619+
MCSectionGOFF *getGOFFSection(SectionKind Kind,
620+
GOFF::ESDSymbolType SymbolType, StringRef Name,
621+
GOFF::SDAttr SDAttributes,
622+
GOFF::EDAttr EDAttributes,
623+
GOFF::PRAttr PRAttributes, MCSection *Parent);
610624

611625
public:
612-
// Create a section with SD/ED/LD symbols.
613-
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef SDName,
614-
GOFF::SDAttr SDAttributes, StringRef EDName,
615-
GOFF::EDAttr EDAttributes, StringRef LDorPRName,
616-
GOFF::LDAttr LDAttributes);
617-
// Create a section with SD/ED/PR symbols.
618-
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef SDName,
619-
GOFF::SDAttr SDAttributes, StringRef EDName,
620-
GOFF::EDAttr EDAttributes, StringRef LDorPRName,
621-
GOFF::PRAttr PRAttributes);
622-
// Create a section with root-SD/ED/LD symbols.
623-
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef EDName,
624-
GOFF::EDAttr EDAttributes, StringRef LDorPRName,
625-
GOFF::LDAttr LDAttributes);
626-
// Create a section with root-SD/ED/PR symbols.
627-
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef EDName,
628-
GOFF::EDAttr EDAttributes, StringRef PRName,
629-
GOFF::PRAttr PRAttributes);
630-
// Create a section with root-SD/ED symbols.
631-
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef EDName,
632-
GOFF::EDAttr EDAttributes);
626+
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
627+
GOFF::SDAttr SDAttributes,
628+
MCSection *Parent = nullptr);
629+
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
630+
GOFF::EDAttr EDAttributes,
631+
MCSection *Parent = nullptr);
632+
MCSectionGOFF *getGOFFSection(SectionKind Kind, StringRef Name,
633+
GOFF::PRAttr PRAttributes,
634+
MCSection *Parent = nullptr);
633635

634636
MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
635637
StringRef COMDATSymName, int Selection,

llvm/include/llvm/MC/MCGOFFStreamer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class MCGOFFStreamer : public MCObjectStreamer {
2929
~MCGOFFStreamer() override;
3030

3131
void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override;
32+
void changeSection(MCSection *Section, uint32_t Subsection = 0) override;
3233

3334
GOFFObjectWriter &getWriter();
3435

llvm/include/llvm/MC/MCObjectFileInfo.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,11 @@ class MCObjectFileInfo {
230230
MCSection *GLJMPSection = nullptr;
231231

232232
// GOFF specific sections.
233-
MCSection *PPA2ListSection = nullptr;
234-
MCSection *ADASection = nullptr;
233+
MCSection *RootSDSection = nullptr;
234+
MCSection *PPA2ListEDSection = nullptr;
235+
MCSection *PPA2ListPRSection = nullptr;
236+
MCSection *ADAEDSection = nullptr;
237+
MCSection *ADAPRSection = nullptr;
235238
MCSection *IDRLSection = nullptr;
236239

237240
// XCOFF specific sections
@@ -436,8 +439,11 @@ class MCObjectFileInfo {
436439
MCSection *getGLJMPSection() const { return GLJMPSection; }
437440

438441
// GOFF specific sections.
439-
MCSection *getPPA2ListSection() const { return PPA2ListSection; }
440-
MCSection *getADASection() const { return ADASection; }
442+
MCSection *getRootSDSection() const { return RootSDSection; }
443+
MCSection *getPPA2ListEDSection() const { return PPA2ListEDSection; }
444+
MCSection *getPPA2ListSection() const { return PPA2ListPRSection; }
445+
MCSection *getADAEDSection() const { return ADAEDSection; }
446+
MCSection *getADASection() const { return ADAPRSection; }
441447
MCSection *getIDRLSection() const { return IDRLSection; }
442448

443449
// XCOFF specific sections

llvm/include/llvm/MC/MCSectionGOFF.h

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,96 +15,96 @@
1515
#ifndef LLVM_MC_MCSECTIONGOFF_H
1616
#define LLVM_MC_MCSECTIONGOFF_H
1717

18-
#include "llvm/ADT/BitmaskEnum.h"
1918
#include "llvm/BinaryFormat/GOFF.h"
2019
#include "llvm/MC/MCGOFFAttributes.h"
2120
#include "llvm/MC/MCSection.h"
21+
#include "llvm/Support/ErrorHandling.h"
2222
#include "llvm/Support/raw_ostream.h"
2323

2424
namespace llvm {
2525

2626
class MCExpr;
2727

2828
class MCSectionGOFF final : public MCSection {
29-
private:
30-
// The names of the GOFF symbols.
31-
StringRef SDName;
32-
StringRef EDName;
33-
StringRef LDorPRName;
29+
// Parent of this section. Implies that the parent is emitted first.
30+
MCSectionGOFF *Parent;
3431

3532
// The attributes of the GOFF symbols.
3633
GOFF::SDAttr SDAttributes;
3734
GOFF::EDAttr EDAttributes;
38-
GOFF::LDAttr LDAttributes;
3935
GOFF::PRAttr PRAttributes;
4036

41-
public:
42-
enum SectionFlags {
43-
UsesRootSD = 1, // Uses the common root SD.
44-
HasLD = 2, // Has a LD symbol.
45-
HasPR = 4, // Has a PR symbol.
46-
LDorPRNameIsSD = 8, // The LD or PR name is the same as the SD name.
47-
LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ 8)
48-
};
37+
// The type of this section.
38+
GOFF::ESDSymbolType SymbolType;
39+
40+
// Indicates that the ED symbol needs to set the length of the section.
41+
unsigned RequiresLength : 1;
4942

50-
private:
51-
SectionFlags Flags;
43+
// Indicates that the PR symbol needs to set the length of the section to a
44+
// non-zero value.
45+
unsigned RequiresNonZeroLength : 1;
5246

5347
friend class MCContext;
54-
MCSectionGOFF(StringRef SynName, SectionKind K, SectionFlags Flags,
55-
StringRef SDName, GOFF::SDAttr SDAttributes, StringRef EDName,
56-
GOFF::EDAttr EDAttributes, StringRef LDorPRName,
57-
GOFF::LDAttr LDAttributes, GOFF::PRAttr PRAttributes)
58-
: MCSection(SV_GOFF, SynName, K.isText(), /*IsVirtual=*/false, nullptr),
59-
SDName(SDName), EDName(EDName), LDorPRName(LDorPRName),
60-
SDAttributes(SDAttributes), EDAttributes(EDAttributes),
61-
LDAttributes(LDAttributes), PRAttributes(PRAttributes), Flags(Flags) {}
48+
MCSectionGOFF(StringRef Name, SectionKind K, GOFF::ESDSymbolType SymbolType,
49+
GOFF::SDAttr SDAttributes, GOFF::EDAttr EDAttributes,
50+
GOFF::PRAttr PRAttributes, MCSectionGOFF *Parent = nullptr)
51+
: MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
52+
Parent(Parent), SDAttributes(SDAttributes), EDAttributes(EDAttributes),
53+
PRAttributes(PRAttributes), SymbolType(SymbolType) {}
6254

6355
public:
6456
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
6557
raw_ostream &OS,
6658
uint32_t /*Subsection*/) const override {
67-
if (!usesRootSD())
68-
OS << getSDName() << " CSECT\n";
69-
OS << getEDName() << " CATTR\n";
70-
if ((hasLD() || hasPR()) && !getLDorPRName().empty())
71-
OS << getLDorPRName() << " XATTR\n";
59+
;
60+
switch (SymbolType) {
61+
case GOFF::ESD_ST_SectionDefinition:
62+
OS << Name << " CSECT\n";
63+
break;
64+
case GOFF::ESD_ST_ElementDefinition:
65+
OS << Name << " CATTR\n";
66+
break;
67+
case GOFF::ESD_ST_PartReference:
68+
OS << Name << " XATTR\n";
69+
break;
70+
default:
71+
llvm_unreachable("Wrong section type");
72+
}
7273
}
7374

7475
bool useCodeAlign() const override { return false; }
7576

76-
// Accessors to the various symbol names.
77-
StringRef getSDName() const { return SDName; };
78-
StringRef getEDName() const { return EDName; };
79-
StringRef getLDorPRName() const {
80-
assert(Flags & (HasLD | HasPR) && "LD/PR name not available");
81-
return (Flags & LDorPRNameIsSD) ? SDName : LDorPRName;
82-
};
83-
84-
// Setters for the SD and LD/PR symbol names.
85-
void setSDName(StringRef Name) {
86-
assert(!(Flags & UsesRootSD) && "Uses root SD");
87-
SDName = Name;
77+
// Return the id of the section. It is the 1-based ordinal number.
78+
unsigned getId() const { return getOrdinal() + 1; }
79+
80+
// Return the parent section.
81+
MCSectionGOFF *getParent() const { return Parent; }
82+
83+
// Returns the type of this section.
84+
GOFF::ESDSymbolType getSymbolType() const { return SymbolType; }
85+
86+
bool isSD() const { return SymbolType == GOFF::ESD_ST_SectionDefinition; }
87+
bool isED() const { return SymbolType == GOFF::ESD_ST_ElementDefinition; }
88+
bool isPR() const { return SymbolType == GOFF::ESD_ST_PartReference; }
89+
90+
// Accessors to the attributes.
91+
GOFF::SDAttr getSDAttributes() const {
92+
assert(SymbolType == GOFF::ESD_ST_SectionDefinition && "Not PR symbol");
93+
return SDAttributes;
8894
}
89-
void setLDorPRName(StringRef Name) { LDorPRName = Name; }
90-
91-
// Accessors to the various attributes.
92-
GOFF::SDAttr getSDAttributes() const { return SDAttributes; }
93-
GOFF::EDAttr getEDAttributes() const { return EDAttributes; }
94-
GOFF::LDAttr getLDAttributes() const {
95-
assert(Flags & HasLD && "LD not available");
96-
return LDAttributes;
95+
GOFF::EDAttr getEDAttributes() const {
96+
assert(SymbolType == GOFF::ESD_ST_ElementDefinition && "Not PR symbol");
97+
return EDAttributes;
9798
}
9899
GOFF::PRAttr getPRAttributes() const {
99-
assert(Flags & HasPR && "PR not available");
100+
assert(SymbolType == GOFF::ESD_ST_PartReference && "Not PR symbol");
100101
return PRAttributes;
101102
}
102103

103-
// Query various flags.
104-
bool usesRootSD() const { return Flags & UsesRootSD; }
105-
bool hasLD() const { return Flags & HasLD; }
106-
bool hasPR() const { return Flags & HasPR; }
107-
bool isLDorPRNameTheSD() const { return Flags & LDorPRNameIsSD; }
104+
bool requiresLength() const { return RequiresLength; }
105+
bool requiresNonZeroLength() const { return RequiresNonZeroLength; }
106+
107+
void setName(StringRef SectionName) { Name = SectionName; }
108108

109109
static bool classof(const MCSection *S) { return S->getVariant() == SV_GOFF; }
110110
};

llvm/include/llvm/MC/MCSymbolGOFF.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,38 @@
1313
#ifndef LLVM_MC_MCSYMBOLGOFF_H
1414
#define LLVM_MC_MCSYMBOLGOFF_H
1515

16+
#include "llvm/BinaryFormat/GOFF.h"
17+
#include "llvm/MC/MCGOFFAttributes.h"
18+
#include "llvm/MC/MCSectionGOFF.h"
1619
#include "llvm/MC/MCSymbol.h"
1720
#include "llvm/MC/MCSymbolTableEntry.h"
1821

1922
namespace llvm {
2023

2124
class MCSymbolGOFF : public MCSymbol {
25+
// Associated data area of the section. Needs to be emitted first.
26+
MCSectionGOFF *ADA;
27+
28+
GOFF::LDAttr LDAttributes;
29+
30+
enum SymbolFlags : uint16_t {
31+
SF_LD = 0x01, // LD attributes are set.
32+
};
33+
2234
public:
2335
MCSymbolGOFF(const MCSymbolTableEntry *Name, bool IsTemporary)
2436
: MCSymbol(SymbolKindGOFF, Name, IsTemporary) {}
37+
38+
void setLDAttributes(GOFF::LDAttr Attr) {
39+
modifyFlags(SF_LD, SF_LD);
40+
LDAttributes = Attr;
41+
}
42+
GOFF::LDAttr getLDAttributes() const { return LDAttributes; }
43+
bool hasLDAttributes() const { return getFlags() & SF_LD; }
44+
45+
void setADA(MCSectionGOFF *AssociatedDataArea) { ADA = AssociatedDataArea; }
46+
MCSectionGOFF *getADA() const { return ADA; }
47+
2548
static bool classof(const MCSymbol *S) { return S->isGOFF(); }
2649
};
2750
} // end namespace llvm

0 commit comments

Comments
 (0)