Skip to content

Commit 7f90a5c

Browse files
committed
MCAsmBackend: Simplify FT_Data/FT_Relaxable code
1 parent d733c8e commit 7f90a5c

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

llvm/lib/MC/MCAsmBackend.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,9 @@ bool MCAsmBackend::isDarwinCanonicalPersonality(const MCSymbol *Sym) const {
138138

139139
const MCSubtargetInfo *MCAsmBackend::getSubtargetInfo(const MCFragment &F) {
140140
const MCSubtargetInfo *STI = nullptr;
141-
switch (F.getKind()) {
142-
case MCFragment::FT_Data: {
143-
auto &DF = cast<MCDataFragment>(F);
144-
STI = DF.getSubtargetInfo();
145-
assert(!DF.hasInstructions() || STI != nullptr);
146-
break;
147-
}
148-
case MCFragment::FT_Relaxable: {
149-
auto &RF = cast<MCRelaxableFragment>(F);
150-
STI = RF.getSubtargetInfo();
151-
assert(!RF.hasInstructions() || STI != nullptr);
152-
break;
153-
}
154-
default:
155-
break;
141+
if (auto *DF = dyn_cast<MCEncodedFragment>(&F)) {
142+
STI = DF->getSubtargetInfo();
143+
assert(!DF->hasInstructions() || STI != nullptr);
156144
}
157145
return STI;
158146
}

llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,10 @@ static size_t getSizeForInstFragment(const MCFragment *F) {
422422
if (!F || !F->hasInstructions())
423423
return 0;
424424
// MCEncodedFragmentWithContents being templated makes this tricky.
425-
switch (F->getKind()) {
426-
default:
425+
if (auto *DF = dyn_cast<MCEncodedFragment>(F))
426+
return DF->getContents().size();
427+
else
427428
llvm_unreachable("Unknown fragment with instructions!");
428-
case MCFragment::FT_Data:
429-
return cast<MCDataFragment>(*F).getContents().size();
430-
case MCFragment::FT_Relaxable:
431-
return cast<MCRelaxableFragment>(*F).getContents().size();
432-
}
433429
}
434430

435431
/// Return true if we can insert NOP or prefixes automatically before the

0 commit comments

Comments
 (0)