[llvm] 4c23707 - [XCOFF][NFC] make StorageMappingClass/SymbolType member optional
Chen Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 18 01:46:19 PST 2021
Author: Chen Zheng
Date: 2021-02-18T04:46:05-05:00
New Revision: 4c23707a418add9c584af5247faa5a9527632a0c
URL: https://github.com/llvm/llvm-project/commit/4c23707a418add9c584af5247faa5a9527632a0c
DIFF: https://github.com/llvm/llvm-project/commit/4c23707a418add9c584af5247faa5a9527632a0c.diff
LOG: [XCOFF][NFC] make StorageMappingClass/SymbolType member optional
This patch makes StorageMappingClass/SymbolType member optional in
class MCSectionXCOFF.
Non-csect sections like debug sections have no such properties.
Reviewed By: hubert.reinterpretcast
Differential Revision: https://reviews.llvm.org/D96641
Added:
Modified:
llvm/include/llvm/MC/MCSectionXCOFF.h
llvm/lib/MC/MCSectionXCOFF.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCSectionXCOFF.h b/llvm/include/llvm/MC/MCSectionXCOFF.h
index aa39dff07180..768e398525bc 100644
--- a/llvm/include/llvm/MC/MCSectionXCOFF.h
+++ b/llvm/include/llvm/MC/MCSectionXCOFF.h
@@ -32,8 +32,7 @@ namespace llvm {
class MCSectionXCOFF final : public MCSection {
friend class MCContext;
- XCOFF::StorageMappingClass MappingClass;
- XCOFF::SymbolType Type;
+ Optional<XCOFF::CsectProperties> CsectProp;
MCSymbolXCOFF *const QualName;
StringRef SymbolTableName;
bool MultiSymbolsAllowed;
@@ -43,19 +42,37 @@ class MCSectionXCOFF final : public MCSection {
XCOFF::SymbolType ST, SectionKind K, MCSymbolXCOFF *QualName,
MCSymbol *Begin, StringRef SymbolTableName,
bool MultiSymbolsAllowed)
- : MCSection(SV_XCOFF, Name, K, Begin), MappingClass(SMC), Type(ST),
- QualName(QualName), SymbolTableName(SymbolTableName),
+ : MCSection(SV_XCOFF, Name, K, Begin),
+ CsectProp(XCOFF::CsectProperties(SMC, ST)), QualName(QualName),
+ SymbolTableName(SymbolTableName),
MultiSymbolsAllowed(MultiSymbolsAllowed) {
- assert((ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
- "Invalid or unhandled type for csect.");
+ assert(
+ (ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) &&
+ "Invalid or unhandled type for csect.");
assert(QualName != nullptr && "QualName is needed.");
QualName->setRepresentedCsect(this);
QualName->setStorageClass(XCOFF::C_HIDEXT);
// A csect is 4 byte aligned by default, except for undefined symbol csects.
- if (Type != XCOFF::XTY_ER)
+ if (ST != XCOFF::XTY_ER)
setAlignment(Align(DefaultAlignVal));
}
+ MCSectionXCOFF(StringRef Name, SectionKind K, MCSymbolXCOFF *QualName,
+ MCSymbol *Begin, StringRef SymbolTableName,
+ bool MultiSymbolsAllowed)
+ : MCSection(SV_XCOFF, Name, K, Begin), QualName(QualName),
+ SymbolTableName(SymbolTableName),
+ MultiSymbolsAllowed(MultiSymbolsAllowed) {
+ assert(QualName != nullptr && "QualName is needed.");
+
+ // FIXME: use a more meaningful name for non csect sections.
+ QualName->setRepresentedCsect(this);
+
+ // Set default alignment 4 for all non csect sections for now.
+ // FIXME: set
diff erent alignments according to section types.
+ setAlignment(Align(DefaultAlignVal));
+ }
+
void printCsectDirective(raw_ostream &OS) const;
public:
@@ -65,11 +82,17 @@ class MCSectionXCOFF final : public MCSection {
return S->getVariant() == SV_XCOFF;
}
- XCOFF::StorageMappingClass getMappingClass() const { return MappingClass; }
+ XCOFF::StorageMappingClass getMappingClass() const {
+ assert(isCsect() && "Only csect section has mapping class property!");
+ return CsectProp->MappingClass;
+ }
XCOFF::StorageClass getStorageClass() const {
return QualName->getStorageClass();
}
- XCOFF::SymbolType getCSectType() const { return Type; }
+ XCOFF::SymbolType getCSectType() const {
+ assert(isCsect() && "Only csect section has symbol type property!");
+ return CsectProp->Type;
+ }
MCSymbolXCOFF *getQualNameSymbol() const { return QualName; }
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
@@ -79,6 +102,7 @@ class MCSectionXCOFF final : public MCSection {
bool isVirtualSection() const override;
StringRef getSymbolTableName() const { return SymbolTableName; }
bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; }
+ bool isCsect() const { return CsectProp.hasValue(); }
};
} // end namespace llvm
diff --git a/llvm/lib/MC/MCSectionXCOFF.cpp b/llvm/lib/MC/MCSectionXCOFF.cpp
index 17b7b60a04ab..5ef23ed1d894 100644
--- a/llvm/lib/MC/MCSectionXCOFF.cpp
+++ b/llvm/lib/MC/MCSectionXCOFF.cpp
@@ -75,4 +75,7 @@ void MCSectionXCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
bool MCSectionXCOFF::UseCodeAlign() const { return getKind().isText(); }
-bool MCSectionXCOFF::isVirtualSection() const { return XCOFF::XTY_CM == Type; }
+bool MCSectionXCOFF::isVirtualSection() const {
+ assert(isCsect() && "Only csect section can be virtual!");
+ return XCOFF::XTY_CM == CsectProp->Type;
+}
More information about the llvm-commits
mailing list