[llvm] r338469 - Simplify selectELFSectionForGlobal by pulling out the entry size
Eric Christopher via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 31 18:29:31 PDT 2018
Author: echristo
Date: Tue Jul 31 18:29:30 2018
New Revision: 338469
URL: http://llvm.org/viewvc/llvm-project?rev=338469&view=rev
Log:
Simplify selectELFSectionForGlobal by pulling out the entry size
determination for mergeable sections into a small static function.
Modified:
llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=338469&r1=338468&r2=338469&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Tue Jul 31 18:29:30 2018
@@ -422,32 +422,34 @@ static StringRef getSectionPrefixForGlob
return ".data.rel.ro";
}
+static unsigned getEntrySizeForKind(SectionKind Kind) {
+ if (Kind.isMergeable1ByteCString())
+ return 1;
+ else if (Kind.isMergeable2ByteCString())
+ return 2;
+ else if (Kind.isMergeable4ByteCString())
+ return 4;
+ else if (Kind.isMergeableConst4())
+ return 4;
+ else if (Kind.isMergeableConst8())
+ return 8;
+ else if (Kind.isMergeableConst16())
+ return 16;
+ else if (Kind.isMergeableConst32())
+ return 32;
+ else {
+ // We shouldn't have mergeable C strings or mergeable constants that we
+ // didn't handle above.
+ assert(!Kind.isMergeableCString() && "unknown string width");
+ assert(!Kind.isMergeableConst() && "unknown data width");
+ return 0;
+ }
+}
+
static MCSectionELF *selectELFSectionForGlobal(
MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol) {
- unsigned EntrySize = 0;
- if (Kind.isMergeableCString()) {
- if (Kind.isMergeable2ByteCString()) {
- EntrySize = 2;
- } else if (Kind.isMergeable4ByteCString()) {
- EntrySize = 4;
- } else {
- EntrySize = 1;
- assert(Kind.isMergeable1ByteCString() && "unknown string width");
- }
- } else if (Kind.isMergeableConst()) {
- if (Kind.isMergeableConst4()) {
- EntrySize = 4;
- } else if (Kind.isMergeableConst8()) {
- EntrySize = 8;
- } else if (Kind.isMergeableConst16()) {
- EntrySize = 16;
- } else {
- assert(Kind.isMergeableConst32() && "unknown data width");
- EntrySize = 32;
- }
- }
StringRef Group = "";
if (const Comdat *C = getELFComdat(GO)) {
@@ -455,6 +457,9 @@ static MCSectionELF *selectELFSectionFor
Group = C->getName();
}
+ // Get the section entry size based on the kind.
+ unsigned EntrySize = getEntrySizeForKind(Kind);
+
SmallString<128> Name;
if (Kind.isMergeableCString()) {
// We also need alignment here.
More information about the llvm-commits
mailing list