@@ -203,7 +203,7 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
203203 case MCFragment::FT_CVDefRange:
204204 return F.getSize ();
205205 case MCFragment::FT_Fill: {
206- auto &FF = cast< MCFillFragment>(F);
206+ auto &FF = static_cast < const MCFillFragment & >(F);
207207 int64_t NumValues = 0 ;
208208 if (!FF.getNumValues ().evaluateKnownAbsolute (NumValues, *this )) {
209209 recordError (FF.getLoc (), " expected assembly-time absolute expression" );
@@ -748,22 +748,22 @@ bool MCAssembler::fixupNeedsRelaxation(const MCFragment &F,
748748 Resolved);
749749}
750750
751- bool MCAssembler::relaxInstruction (MCFragment &F) {
751+ void MCAssembler::relaxInstruction (MCFragment &F) {
752752 assert (getEmitterPtr () &&
753753 " Expected CodeEmitter defined for relaxInstruction" );
754754 // If this inst doesn't ever need relaxation, ignore it. This occurs when we
755755 // are intentionally pushing out inst fragments, or because we relaxed a
756756 // previous instruction to one that doesn't need relaxation.
757757 if (!getBackend ().mayNeedRelaxation (F.getOpcode (), F.getOperands (),
758758 *F.getSubtargetInfo ()))
759- return false ;
759+ return ;
760760
761761 bool DoRelax = false ;
762762 for (const MCFixup &Fixup : F.getVarFixups ())
763763 if ((DoRelax = fixupNeedsRelaxation (F, Fixup)))
764764 break ;
765765 if (!DoRelax)
766- return false ;
766+ return ;
767767
768768 ++stats::RelaxedInstructions;
769769
@@ -779,12 +779,10 @@ bool MCAssembler::relaxInstruction(MCFragment &F) {
779779 getEmitter ().encodeInstruction (Relaxed, Data, Fixups, *F.getSubtargetInfo ());
780780 F.setVarContents (Data);
781781 F.setVarFixups (Fixups);
782- return true ;
783782}
784783
785- bool MCAssembler::relaxLEB (MCFragment &F) {
786- const unsigned OldSize = F.getVarSize ();
787- unsigned PadTo = OldSize;
784+ void MCAssembler::relaxLEB (MCFragment &F) {
785+ unsigned PadTo = F.getVarSize ();
788786 int64_t Value;
789787 F.clearVarFixups ();
790788 // Use evaluateKnownAbsolute for Mach-O as a hack: .subsections_via_symbols
@@ -818,7 +816,6 @@ bool MCAssembler::relaxLEB(MCFragment &F) {
818816 else
819817 Size = encodeULEB128 (Value, Data, PadTo);
820818 F.setVarContents ({reinterpret_cast <char *>(Data), Size});
821- return OldSize != Size;
822819}
823820
824821// / Check if the branch crosses the boundary.
@@ -858,11 +855,11 @@ static bool needPadding(uint64_t StartAddr, uint64_t Size,
858855 isAgainstBoundary (StartAddr, Size, BoundaryAlignment);
859856}
860857
861- bool MCAssembler::relaxBoundaryAlign (MCBoundaryAlignFragment &BF) {
858+ void MCAssembler::relaxBoundaryAlign (MCBoundaryAlignFragment &BF) {
862859 // BoundaryAlignFragment that doesn't need to align any fragment should not be
863860 // relaxed.
864861 if (!BF.getLastFragment ())
865- return false ;
862+ return ;
866863
867864 uint64_t AlignedOffset = getFragmentOffset (BF);
868865 uint64_t AlignedSize = 0 ;
@@ -877,18 +874,15 @@ bool MCAssembler::relaxBoundaryAlign(MCBoundaryAlignFragment &BF) {
877874 ? offsetToAlignment (AlignedOffset, BoundaryAlignment)
878875 : 0U ;
879876 if (NewSize == BF.getSize ())
880- return false ;
877+ return ;
881878 BF.setSize (NewSize);
882- return true ;
883879}
884880
885- bool MCAssembler::relaxDwarfLineAddr (MCFragment &F) {
886- bool WasRelaxed;
887- if (getBackend ().relaxDwarfLineAddr (F, WasRelaxed))
888- return WasRelaxed;
881+ void MCAssembler::relaxDwarfLineAddr (MCFragment &F) {
882+ if (getBackend ().relaxDwarfLineAddr (F))
883+ return ;
889884
890885 MCContext &Context = getContext ();
891- auto OldSize = F.getVarSize ();
892886 int64_t AddrDelta;
893887 bool Abs = F.getDwarfAddrDelta ().evaluateKnownAbsolute (AddrDelta, *this );
894888 assert (Abs && " We created a line delta with an invalid expression" );
@@ -898,13 +892,11 @@ bool MCAssembler::relaxDwarfLineAddr(MCFragment &F) {
898892 F.getDwarfLineDelta (), AddrDelta, Data);
899893 F.setVarContents (Data);
900894 F.clearVarFixups ();
901- return OldSize != Data.size ();
902895}
903896
904- bool MCAssembler::relaxDwarfCallFrameFragment (MCFragment &F) {
905- bool WasRelaxed;
906- if (getBackend ().relaxDwarfCFA (F, WasRelaxed))
907- return WasRelaxed;
897+ void MCAssembler::relaxDwarfCallFrameFragment (MCFragment &F) {
898+ if (getBackend ().relaxDwarfCFA (F))
899+ return ;
908900
909901 MCContext &Context = getContext ();
910902 int64_t Value;
@@ -913,69 +905,60 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCFragment &F) {
913905 reportError (F.getDwarfAddrDelta ().getLoc (),
914906 " invalid CFI advance_loc expression" );
915907 F.setDwarfAddrDelta (MCConstantExpr::create (0 , Context));
916- return false ;
908+ return ;
917909 }
918910
919- auto OldSize = F.getVarContents ().size ();
920911 SmallVector<char , 8 > Data;
921912 MCDwarfFrameEmitter::encodeAdvanceLoc (Context, Value, Data);
922913 F.setVarContents (Data);
923914 F.clearVarFixups ();
924- return OldSize != Data.size ();
925- }
926-
927- bool MCAssembler::relaxCVInlineLineTable (MCCVInlineLineTableFragment &F) {
928- unsigned OldSize = F.getVarContents ().size ();
929- getContext ().getCVContext ().encodeInlineLineTable (*this , F);
930- return OldSize != F.getVarContents ().size ();
931- }
932-
933- bool MCAssembler::relaxCVDefRange (MCCVDefRangeFragment &F) {
934- unsigned OldSize = F.getVarContents ().size ();
935- getContext ().getCVContext ().encodeDefRange (*this , F);
936- return OldSize != F.getVarContents ().size ();
937- }
938-
939- bool MCAssembler::relaxFill (MCFillFragment &F) {
940- uint64_t Size = computeFragmentSize (F);
941- if (F.getSize () == Size)
942- return false ;
943- F.setSize (Size);
944- return true ;
945- }
946-
947- bool MCAssembler::relaxOrg (MCOrgFragment &F) {
948- uint64_t Size = computeFragmentSize (F);
949- if (F.getSize () == Size)
950- return false ;
951- F.setSize (Size);
952- return true ;
953915}
954916
955917bool MCAssembler::relaxFragment (MCFragment &F) {
956- switch (F.getKind ()) {
918+ size_t Size = computeFragmentSize (F);
919+ switch (F.getKind ()) {
957920 default :
958921 return false ;
959922 case MCFragment::FT_Relaxable:
960923 assert (!getRelaxAll () && " Did not expect a FT_Relaxable in RelaxAll mode" );
961- return relaxInstruction (F);
924+ relaxInstruction (F);
925+ break ;
962926 case MCFragment::FT_LEB:
963- return relaxLEB (F);
927+ relaxLEB (F);
928+ break ;
964929 case MCFragment::FT_Dwarf:
965- return relaxDwarfLineAddr (F);
930+ relaxDwarfLineAddr (F);
931+ break ;
966932 case MCFragment::FT_DwarfFrame:
967- return relaxDwarfCallFrameFragment (F);
933+ relaxDwarfCallFrameFragment (F);
934+ break ;
968935 case MCFragment::FT_BoundaryAlign:
969- return relaxBoundaryAlign (cast<MCBoundaryAlignFragment>(F));
936+ relaxBoundaryAlign (static_cast <MCBoundaryAlignFragment &>(F));
937+ break ;
970938 case MCFragment::FT_CVInlineLines:
971- return relaxCVInlineLineTable (cast<MCCVInlineLineTableFragment>(F));
939+ getContext ().getCVContext ().encodeInlineLineTable (
940+ *this , static_cast <MCCVInlineLineTableFragment &>(F));
941+ break ;
972942 case MCFragment::FT_CVDefRange:
973- return relaxCVDefRange (cast<MCCVDefRangeFragment>(F));
974- case MCFragment::FT_Fill:
975- return relaxFill (cast<MCFillFragment>(F));
976- case MCFragment::FT_Org:
977- return relaxOrg (static_cast <MCOrgFragment &>(F));
943+ getContext ().getCVContext ().encodeDefRange (
944+ *this , static_cast <MCCVDefRangeFragment &>(F));
945+ break ;
946+ case MCFragment::FT_Fill: {
947+ auto &FF = static_cast <MCFillFragment &>(F);
948+ if (FF.getSize () == Size)
949+ return false ;
950+ FF.setSize (Size);
951+ return true ;
952+ }
953+ case MCFragment::FT_Org: {
954+ auto &FF = static_cast <MCOrgFragment &>(F);
955+ if (FF.getSize () == Size)
956+ return false ;
957+ FF.setSize (Size);
958+ return true ;
959+ }
978960 }
961+ return computeFragmentSize (F) != Size;
979962}
980963
981964void MCAssembler::layoutSection (MCSection &Sec) {
@@ -1024,7 +1007,7 @@ unsigned MCAssembler::relaxOnce(unsigned FirstStable) {
10241007 for (;;) {
10251008 bool Changed = false ;
10261009 for (MCFragment &F : Sec)
1027- if (relaxFragment (F))
1010+ if (F. getKind () != MCFragment::FT_Data && relaxFragment (F))
10281011 Changed = true ;
10291012
10301013 if (!Changed)
0 commit comments