Skip to content

Commit 7a70be6

Browse files
committed
Simplify selectELFSectionForGlobal by pulling out the entry size
determination for mergeable sections into a small static function. llvm-svn: 338469
1 parent ad36c74 commit 7a70be6

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -422,39 +422,44 @@ static StringRef getSectionPrefixForGlobal(SectionKind Kind) {
422422
return ".data.rel.ro";
423423
}
424424

425+
static unsigned getEntrySizeForKind(SectionKind Kind) {
426+
if (Kind.isMergeable1ByteCString())
427+
return 1;
428+
else if (Kind.isMergeable2ByteCString())
429+
return 2;
430+
else if (Kind.isMergeable4ByteCString())
431+
return 4;
432+
else if (Kind.isMergeableConst4())
433+
return 4;
434+
else if (Kind.isMergeableConst8())
435+
return 8;
436+
else if (Kind.isMergeableConst16())
437+
return 16;
438+
else if (Kind.isMergeableConst32())
439+
return 32;
440+
else {
441+
// We shouldn't have mergeable C strings or mergeable constants that we
442+
// didn't handle above.
443+
assert(!Kind.isMergeableCString() && "unknown string width");
444+
assert(!Kind.isMergeableConst() && "unknown data width");
445+
return 0;
446+
}
447+
}
448+
425449
static MCSectionELF *selectELFSectionForGlobal(
426450
MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
427451
const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
428452
unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol) {
429-
unsigned EntrySize = 0;
430-
if (Kind.isMergeableCString()) {
431-
if (Kind.isMergeable2ByteCString()) {
432-
EntrySize = 2;
433-
} else if (Kind.isMergeable4ByteCString()) {
434-
EntrySize = 4;
435-
} else {
436-
EntrySize = 1;
437-
assert(Kind.isMergeable1ByteCString() && "unknown string width");
438-
}
439-
} else if (Kind.isMergeableConst()) {
440-
if (Kind.isMergeableConst4()) {
441-
EntrySize = 4;
442-
} else if (Kind.isMergeableConst8()) {
443-
EntrySize = 8;
444-
} else if (Kind.isMergeableConst16()) {
445-
EntrySize = 16;
446-
} else {
447-
assert(Kind.isMergeableConst32() && "unknown data width");
448-
EntrySize = 32;
449-
}
450-
}
451453

452454
StringRef Group = "";
453455
if (const Comdat *C = getELFComdat(GO)) {
454456
Flags |= ELF::SHF_GROUP;
455457
Group = C->getName();
456458
}
457459

460+
// Get the section entry size based on the kind.
461+
unsigned EntrySize = getEntrySizeForKind(Kind);
462+
458463
SmallString<128> Name;
459464
if (Kind.isMergeableCString()) {
460465
// We also need alignment here.

0 commit comments

Comments
 (0)