[llvm] eca4bfe - [MC] Pull out a relaxFragment helper [NFC]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 26 13:37:22 PST 2020
Author: Philip Reames
Date: 2020-02-26T13:37:12-08:00
New Revision: eca4bfea3d380f56652a19bfe4746663601050cb
URL: https://github.com/llvm/llvm-project/commit/eca4bfea3d380f56652a19bfe4746663601050cb
DIFF: https://github.com/llvm/llvm-project/commit/eca4bfea3d380f56652a19bfe4746663601050cb.diff
LOG: [MC] Pull out a relaxFragment helper [NFC]
Having this as it's own function helps to reduce indentation and allows use of return instead of wiring a value over the switch. A lambda would have also worked, but with slightly deeper nesting.
Added:
Modified:
llvm/include/llvm/MC/MCAssembler.h
llvm/lib/MC/MCAssembler.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h
index 791ebcdde4e6..b57439f02ca5 100644
--- a/llvm/include/llvm/MC/MCAssembler.h
+++ b/llvm/include/llvm/MC/MCAssembler.h
@@ -190,6 +190,9 @@ class MCAssembler {
/// if any offsets were adjusted.
bool layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec);
+ /// Perform relaxation on a single fragment - returns true if the fragment
+ /// changes as a result of relaxation.
+ bool relaxFragment(MCAsmLayout &Layout, MCFragment &F);
bool relaxInstruction(MCAsmLayout &Layout, MCRelaxableFragment &IF);
bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF);
bool relaxBoundaryAlign(MCAsmLayout &Layout, MCBoundaryAlignFragment &BF);
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 75ec27975564..b3adaea5a953 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -1106,6 +1106,30 @@ bool MCAssembler::relaxCVDefRange(MCAsmLayout &Layout,
return OldSize != F.getContents().size();
}
+bool MCAssembler::relaxFragment(MCAsmLayout &Layout, MCFragment &F) {
+ switch(F.getKind()) {
+ default:
+ return false;
+ case MCFragment::FT_Relaxable:
+ assert(!getRelaxAll() &&
+ "Did not expect a MCRelaxableFragment in RelaxAll mode");
+ return relaxInstruction(Layout, cast<MCRelaxableFragment>(F));
+ case MCFragment::FT_Dwarf:
+ return relaxDwarfLineAddr(Layout, cast<MCDwarfLineAddrFragment>(F));
+ case MCFragment::FT_DwarfFrame:
+ return relaxDwarfCallFrameFragment(Layout,
+ cast<MCDwarfCallFrameFragment>(F));
+ case MCFragment::FT_LEB:
+ return relaxLEB(Layout, cast<MCLEBFragment>(F));
+ case MCFragment::FT_BoundaryAlign:
+ return relaxBoundaryAlign(Layout, cast<MCBoundaryAlignFragment>(F));
+ case MCFragment::FT_CVInlineLines:
+ return relaxCVInlineLineTable(Layout, cast<MCCVInlineLineTableFragment>(F));
+ case MCFragment::FT_CVDefRange:
+ return relaxCVDefRange(Layout, cast<MCCVDefRangeFragment>(F));
+ }
+}
+
bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec) {
// Holds the first fragment which needed relaxing during this layout. It will
// remain NULL if none were relaxed.
@@ -1116,39 +1140,7 @@ bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec) {
// Attempt to relax all the fragments in the section.
for (MCSection::iterator I = Sec.begin(), IE = Sec.end(); I != IE; ++I) {
// Check if this is a fragment that needs relaxation.
- bool RelaxedFrag = false;
- switch(I->getKind()) {
- default:
- break;
- case MCFragment::FT_Relaxable:
- assert(!getRelaxAll() &&
- "Did not expect a MCRelaxableFragment in RelaxAll mode");
- RelaxedFrag = relaxInstruction(Layout, *cast<MCRelaxableFragment>(I));
- break;
- case MCFragment::FT_Dwarf:
- RelaxedFrag = relaxDwarfLineAddr(Layout,
- *cast<MCDwarfLineAddrFragment>(I));
- break;
- case MCFragment::FT_DwarfFrame:
- RelaxedFrag =
- relaxDwarfCallFrameFragment(Layout,
- *cast<MCDwarfCallFrameFragment>(I));
- break;
- case MCFragment::FT_LEB:
- RelaxedFrag = relaxLEB(Layout, *cast<MCLEBFragment>(I));
- break;
- case MCFragment::FT_BoundaryAlign:
- RelaxedFrag =
- relaxBoundaryAlign(Layout, *cast<MCBoundaryAlignFragment>(I));
- break;
- case MCFragment::FT_CVInlineLines:
- RelaxedFrag =
- relaxCVInlineLineTable(Layout, *cast<MCCVInlineLineTableFragment>(I));
- break;
- case MCFragment::FT_CVDefRange:
- RelaxedFrag = relaxCVDefRange(Layout, *cast<MCCVDefRangeFragment>(I));
- break;
- }
+ bool RelaxedFrag = relaxFragment(Layout, *I);
if (RelaxedFrag && !FirstRelaxedFragment)
FirstRelaxedFragment = &*I;
}
More information about the llvm-commits
mailing list