[llvm] 5517923 - [XCOFF][NFC] make csect properties optional for getXCOFFSection
Chen Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 17 17:51:51 PST 2021
Author: Chen Zheng
Date: 2021-02-17T20:51:42-05:00
New Revision: 5517923b1cacf3e0ace438fd536b333940c3153d
URL: https://github.com/llvm/llvm-project/commit/5517923b1cacf3e0ace438fd536b333940c3153d
DIFF: https://github.com/llvm/llvm-project/commit/5517923b1cacf3e0ace438fd536b333940c3153d.diff
LOG: [XCOFF][NFC] make csect properties optional for getXCOFFSection
We are going to support debug sections for XCOFF. So the csect
properties are not necessary. This patch makes these properties
optional.
Reviewed By: hubert.reinterpretcast
Differential Revision: https://reviews.llvm.org/D95931
Added:
Modified:
llvm/include/llvm/BinaryFormat/XCOFF.h
llvm/include/llvm/MC/MCContext.h
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/MC/MCContext.cpp
llvm/lib/MC/MCObjectFileInfo.cpp
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/BinaryFormat/XCOFF.h b/llvm/include/llvm/BinaryFormat/XCOFF.h
index 48e1baf72689..803a3ab04fc7 100644
--- a/llvm/include/llvm/BinaryFormat/XCOFF.h
+++ b/llvm/include/llvm/BinaryFormat/XCOFF.h
@@ -406,6 +406,13 @@ enum ExtendedTBTableFlag : uint8_t {
StringRef getNameForTracebackTableLanguageId(TracebackTable::LanguageID LangId);
SmallString<32> getExtendedTBTableFlagString(uint8_t Flag);
+struct CsectProperties {
+ CsectProperties(StorageMappingClass SMC, SymbolType ST)
+ : MappingClass(SMC), Type(ST) {}
+ StorageMappingClass MappingClass;
+ SymbolType Type;
+};
+
} // end namespace XCOFF
} // end namespace llvm
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 1eb31deca081..a06aabe835bc 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -579,11 +579,11 @@ namespace llvm {
const MCSymbolWasm *Group, unsigned UniqueID,
const char *BeginSymName);
- MCSectionXCOFF *getXCOFFSection(StringRef Section,
- XCOFF::StorageMappingClass MappingClass,
- XCOFF::SymbolType CSectType, SectionKind K,
- bool MultiSymbolsAllowed = false,
- const char *BeginSymName = nullptr);
+ MCSectionXCOFF *
+ getXCOFFSection(StringRef Section, SectionKind K,
+ Optional<XCOFF::CsectProperties> CsectProp = None,
+ bool MultiSymbolsAllowed = false,
+ const char *BeginSymName = nullptr);
// Create and save a copy of STI and return a reference to the copy.
MCSubtargetInfo &getSubtargetCopy(const MCSubtargetInfo &STI);
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index f0f4516b7c93..49c9d46f5872 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2157,8 +2157,9 @@ MCSection *TargetLoweringObjectFileXCOFF::getExplicitSectionGlobal(
else
report_fatal_error("XCOFF other section types not yet implemented.");
- return getContext().getXCOFFSection(SectionName, MappingClass, XCOFF::XTY_SD,
- Kind, /* MultiSymbolsAllowed*/ true);
+ return getContext().getXCOFFSection(
+ SectionName, Kind, XCOFF::CsectProperties(MappingClass, XCOFF::XTY_SD),
+ /* MultiSymbolsAllowed*/ true);
}
MCSection *TargetLoweringObjectFileXCOFF::getSectionForExternalReference(
@@ -2171,8 +2172,9 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForExternalReference(
// Externals go into a csect of type ER.
return getContext().getXCOFFSection(
- Name, isa<Function>(GO) ? XCOFF::XMC_DS : XCOFF::XMC_UA, XCOFF::XTY_ER,
- SectionKind::getMetadata());
+ Name, SectionKind::getMetadata(),
+ XCOFF::CsectProperties(isa<Function>(GO) ? XCOFF::XMC_DS : XCOFF::XMC_UA,
+ XCOFF::XTY_ER));
}
MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
@@ -2183,8 +2185,9 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
SmallString<128> Name;
getNameWithPrefix(Name, GO, TM);
return getContext().getXCOFFSection(
- Name, Kind.isBSSLocal() ? XCOFF::XMC_BS : XCOFF::XMC_RW, XCOFF::XTY_CM,
- Kind);
+ Name, Kind,
+ XCOFF::CsectProperties(
+ Kind.isBSSLocal() ? XCOFF::XMC_BS : XCOFF::XMC_RW, XCOFF::XTY_CM));
}
if (Kind.isMergeableCString()) {
@@ -2200,7 +2203,7 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
getNameWithPrefix(Name, GO, TM);
return getContext().getXCOFFSection(
- Name, XCOFF::XMC_RO, XCOFF::XTY_SD, Kind,
+ Name, Kind, XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD),
/* MultiSymbolsAllowed*/ !TM.getDataSections());
}
@@ -2223,8 +2226,9 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
if (TM.getDataSections()) {
SmallString<128> Name;
getNameWithPrefix(Name, GO, TM);
- return getContext().getXCOFFSection(Name, XCOFF::XMC_RW, XCOFF::XTY_SD,
- SectionKind::getData());
+ return getContext().getXCOFFSection(
+ Name, SectionKind::getData(),
+ XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD));
}
return DataSection;
}
@@ -2233,8 +2237,9 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
if (TM.getDataSections()) {
SmallString<128> Name;
getNameWithPrefix(Name, GO, TM);
- return getContext().getXCOFFSection(Name, XCOFF::XMC_RO, XCOFF::XTY_SD,
- SectionKind::getReadOnly());
+ return getContext().getXCOFFSection(
+ Name, SectionKind::getReadOnly(),
+ XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD));
}
return ReadOnlySection;
}
@@ -2253,8 +2258,9 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForJumpTable(
// the table doesn't prevent the removal.
SmallString<128> NameStr(".rodata.jmp..");
getNameWithPrefix(NameStr, &F, TM);
- return getContext().getXCOFFSection(NameStr, XCOFF::XMC_RO, XCOFF::XTY_SD,
- SectionKind::getReadOnly());
+ return getContext().getXCOFFSection(
+ NameStr, SectionKind::getReadOnly(),
+ XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD));
}
bool TargetLoweringObjectFileXCOFF::shouldPutJumpTableInFunctionSection(
@@ -2345,9 +2351,11 @@ MCSymbol *TargetLoweringObjectFileXCOFF::getFunctionEntryPointSymbol(
Func->isDeclaration()) &&
isa<Function>(Func)) {
return getContext()
- .getXCOFFSection(NameStr, XCOFF::XMC_PR,
- Func->isDeclaration() ? XCOFF::XTY_ER : XCOFF::XTY_SD,
- SectionKind::getText())
+ .getXCOFFSection(
+ NameStr, SectionKind::getText(),
+ XCOFF::CsectProperties(XCOFF::XMC_PR, Func->isDeclaration()
+ ? XCOFF::XTY_ER
+ : XCOFF::XTY_SD))
->getQualNameSymbol();
}
@@ -2358,8 +2366,9 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor(
const Function *F, const TargetMachine &TM) const {
SmallString<128> NameStr;
getNameWithPrefix(NameStr, F, TM);
- return getContext().getXCOFFSection(NameStr, XCOFF::XMC_DS, XCOFF::XTY_SD,
- SectionKind::getData());
+ return getContext().getXCOFFSection(
+ NameStr, SectionKind::getData(),
+ XCOFF::CsectProperties(XCOFF::XMC_DS, XCOFF::XTY_SD));
}
MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
@@ -2367,7 +2376,8 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
// Use TE storage-mapping class when large code model is enabled so that
// the chance of needing -bbigtoc is decreased.
return getContext().getXCOFFSection(
- cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(),
- TM.getCodeModel() == CodeModel::Large ? XCOFF::XMC_TE : XCOFF::XMC_TC,
- XCOFF::XTY_SD, SectionKind::getData());
+ cast<MCSymbolXCOFF>(Sym)->getSymbolTableName(), SectionKind::getData(),
+ XCOFF::CsectProperties(
+ TM.getCodeModel() == CodeModel::Large ? XCOFF::XMC_TE : XCOFF::XMC_TC,
+ XCOFF::XTY_SD));
}
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index bbff59065898..7d5a1db04358 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -671,12 +671,14 @@ MCSectionWasm *MCContext::getWasmSection(const Twine &Section, SectionKind Kind,
}
MCSectionXCOFF *
-MCContext::getXCOFFSection(StringRef Section, XCOFF::StorageMappingClass SMC,
- XCOFF::SymbolType Type, SectionKind Kind,
+MCContext::getXCOFFSection(StringRef Section, SectionKind Kind,
+ Optional<XCOFF::CsectProperties> CsectProp,
bool MultiSymbolsAllowed, const char *BeginSymName) {
// Do the lookup. If we have a hit, return it.
- auto IterBool = XCOFFUniquingMap.insert(
- std::make_pair(XCOFFSectionKey{Section.str(), SMC}, nullptr));
+ // FIXME: handle the case for non-csect sections. Non-csect section has None
+ // CsectProp.
+ auto IterBool = XCOFFUniquingMap.insert(std::make_pair(
+ XCOFFSectionKey{Section.str(), CsectProp->MappingClass}, nullptr));
auto &Entry = *IterBool.first;
if (!IterBool.second) {
MCSectionXCOFF *ExistedEntry = Entry.second;
@@ -689,7 +691,8 @@ MCContext::getXCOFFSection(StringRef Section, XCOFF::StorageMappingClass SMC,
// Otherwise, return a new section.
StringRef CachedName = Entry.first.SectionName;
MCSymbolXCOFF *QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(
- CachedName + "[" + XCOFF::getMappingClassString(SMC) + "]"));
+ CachedName + "[" + XCOFF::getMappingClassString(CsectProp->MappingClass) +
+ "]"));
MCSymbol *Begin = nullptr;
if (BeginSymName)
@@ -697,9 +700,9 @@ MCContext::getXCOFFSection(StringRef Section, XCOFF::StorageMappingClass SMC,
// QualName->getUnqualifiedName() and CachedName are the same except when
// CachedName contains invalid character(s) such as '$' for an XCOFF symbol.
- MCSectionXCOFF *Result = new (XCOFFAllocator.Allocate())
- MCSectionXCOFF(QualName->getUnqualifiedName(), SMC, Type, Kind, QualName,
- Begin, CachedName, MultiSymbolsAllowed);
+ MCSectionXCOFF *Result = new (XCOFFAllocator.Allocate()) MCSectionXCOFF(
+ QualName->getUnqualifiedName(), CsectProp->MappingClass, CsectProp->Type,
+ Kind, QualName, Begin, CachedName, MultiSymbolsAllowed);
Entry.second = Result;
auto *F = new MCDataFragment();
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 9690eafe3653..b4c4c8751f17 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -874,31 +874,37 @@ void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
// the ABI or object file format. For example, the XL compiler uses an unnamed
// csect for program code.
TextSection = Ctx->getXCOFFSection(
- ".text", XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD,
- SectionKind::getText(), /* MultiSymbolsAllowed*/ true);
+ ".text", SectionKind::getText(),
+ XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),
+ /* MultiSymbolsAllowed*/ true);
DataSection = Ctx->getXCOFFSection(
- ".data", XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD,
- SectionKind::getData(), /* MultiSymbolsAllowed*/ true);
+ ".data", SectionKind::getData(),
+ XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),
+ /* MultiSymbolsAllowed*/ true);
ReadOnlySection = Ctx->getXCOFFSection(
- ".rodata", XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD,
- SectionKind::getReadOnly(), /* MultiSymbolsAllowed*/ true);
+ ".rodata", SectionKind::getReadOnly(),
+ XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),
+ /* MultiSymbolsAllowed*/ true);
- TOCBaseSection =
- Ctx->getXCOFFSection("TOC", XCOFF::StorageMappingClass::XMC_TC0,
- XCOFF::XTY_SD, SectionKind::getData());
+ TOCBaseSection = Ctx->getXCOFFSection(
+ "TOC", SectionKind::getData(),
+ XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,
+ XCOFF::XTY_SD));
// The TOC-base always has 0 size, but 4 byte alignment.
TOCBaseSection->setAlignment(Align(4));
- LSDASection = Ctx->getXCOFFSection(".gcc_except_table",
- XCOFF::StorageMappingClass::XMC_RO,
- XCOFF::XTY_SD, SectionKind::getReadOnly());
+ LSDASection = Ctx->getXCOFFSection(
+ ".gcc_except_table", SectionKind::getReadOnly(),
+ XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,
+ XCOFF::XTY_SD));
- CompactUnwindSection =
- Ctx->getXCOFFSection(".eh_info_table", XCOFF::StorageMappingClass::XMC_RW,
- XCOFF::XTY_SD, SectionKind::getData());
+ CompactUnwindSection = Ctx->getXCOFFSection(
+ ".eh_info_table", SectionKind::getData(),
+ XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,
+ XCOFF::XTY_SD));
// DWARF sections for XCOFF are not csects. They are special STYP_DWARF
// sections, and the individual DWARF sections are distinguished by their
diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index e9cdb50492e0..116ab69fe008 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -5049,8 +5049,8 @@ static SDValue transformCallee(const SDValue &Callee, SelectionDAG &DAG,
const auto getExternalFunctionEntryPointSymbol = [&](StringRef SymName) {
auto &Context = DAG.getMachineFunction().getMMI().getContext();
MCSectionXCOFF *Sec = Context.getXCOFFSection(
- (Twine(".") + Twine(SymName)).str(), XCOFF::XMC_PR, XCOFF::XTY_ER,
- SectionKind::getMetadata());
+ (Twine(".") + Twine(SymName)).str(), SectionKind::getMetadata(),
+ XCOFF::CsectProperties(XCOFF::XMC_PR, XCOFF::XTY_ER));
return Sec->getQualNameSymbol();
};
More information about the llvm-commits
mailing list