@@ -203,7 +203,7 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
203
203
case MCFragment::FT_CVDefRange:
204
204
return F.getSize ();
205
205
case MCFragment::FT_Fill: {
206
- auto &FF = cast< MCFillFragment>(F);
206
+ auto &FF = static_cast < const MCFillFragment & >(F);
207
207
int64_t NumValues = 0 ;
208
208
if (!FF.getNumValues ().evaluateKnownAbsolute (NumValues, *this )) {
209
209
recordError (FF.getLoc (), " expected assembly-time absolute expression" );
@@ -748,22 +748,22 @@ bool MCAssembler::fixupNeedsRelaxation(const MCFragment &F,
748
748
Resolved);
749
749
}
750
750
751
- bool MCAssembler::relaxInstruction (MCFragment &F) {
751
+ void MCAssembler::relaxInstruction (MCFragment &F) {
752
752
assert (getEmitterPtr () &&
753
753
" Expected CodeEmitter defined for relaxInstruction" );
754
754
// If this inst doesn't ever need relaxation, ignore it. This occurs when we
755
755
// are intentionally pushing out inst fragments, or because we relaxed a
756
756
// previous instruction to one that doesn't need relaxation.
757
757
if (!getBackend ().mayNeedRelaxation (F.getOpcode (), F.getOperands (),
758
758
*F.getSubtargetInfo ()))
759
- return false ;
759
+ return ;
760
760
761
761
bool DoRelax = false ;
762
762
for (const MCFixup &Fixup : F.getVarFixups ())
763
763
if ((DoRelax = fixupNeedsRelaxation (F, Fixup)))
764
764
break ;
765
765
if (!DoRelax)
766
- return false ;
766
+ return ;
767
767
768
768
++stats::RelaxedInstructions;
769
769
@@ -779,12 +779,10 @@ bool MCAssembler::relaxInstruction(MCFragment &F) {
779
779
getEmitter ().encodeInstruction (Relaxed, Data, Fixups, *F.getSubtargetInfo ());
780
780
F.setVarContents (Data);
781
781
F.setVarFixups (Fixups);
782
- return true ;
783
782
}
784
783
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 ();
788
786
int64_t Value;
789
787
F.clearVarFixups ();
790
788
// Use evaluateKnownAbsolute for Mach-O as a hack: .subsections_via_symbols
@@ -818,7 +816,6 @@ bool MCAssembler::relaxLEB(MCFragment &F) {
818
816
else
819
817
Size = encodeULEB128 (Value, Data, PadTo);
820
818
F.setVarContents ({reinterpret_cast <char *>(Data), Size});
821
- return OldSize != Size;
822
819
}
823
820
824
821
// / Check if the branch crosses the boundary.
@@ -858,11 +855,11 @@ static bool needPadding(uint64_t StartAddr, uint64_t Size,
858
855
isAgainstBoundary (StartAddr, Size, BoundaryAlignment);
859
856
}
860
857
861
- bool MCAssembler::relaxBoundaryAlign (MCBoundaryAlignFragment &BF) {
858
+ void MCAssembler::relaxBoundaryAlign (MCBoundaryAlignFragment &BF) {
862
859
// BoundaryAlignFragment that doesn't need to align any fragment should not be
863
860
// relaxed.
864
861
if (!BF.getLastFragment ())
865
- return false ;
862
+ return ;
866
863
867
864
uint64_t AlignedOffset = getFragmentOffset (BF);
868
865
uint64_t AlignedSize = 0 ;
@@ -877,18 +874,15 @@ bool MCAssembler::relaxBoundaryAlign(MCBoundaryAlignFragment &BF) {
877
874
? offsetToAlignment (AlignedOffset, BoundaryAlignment)
878
875
: 0U ;
879
876
if (NewSize == BF.getSize ())
880
- return false ;
877
+ return ;
881
878
BF.setSize (NewSize);
882
- return true ;
883
879
}
884
880
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 ;
889
884
890
885
MCContext &Context = getContext ();
891
- auto OldSize = F.getVarSize ();
892
886
int64_t AddrDelta;
893
887
bool Abs = F.getDwarfAddrDelta ().evaluateKnownAbsolute (AddrDelta, *this );
894
888
assert (Abs && " We created a line delta with an invalid expression" );
@@ -898,13 +892,11 @@ bool MCAssembler::relaxDwarfLineAddr(MCFragment &F) {
898
892
F.getDwarfLineDelta (), AddrDelta, Data);
899
893
F.setVarContents (Data);
900
894
F.clearVarFixups ();
901
- return OldSize != Data.size ();
902
895
}
903
896
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 ;
908
900
909
901
MCContext &Context = getContext ();
910
902
int64_t Value;
@@ -913,69 +905,49 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCFragment &F) {
913
905
reportError (F.getDwarfAddrDelta ().getLoc (),
914
906
" invalid CFI advance_loc expression" );
915
907
F.setDwarfAddrDelta (MCConstantExpr::create (0 , Context));
916
- return false ;
908
+ return ;
917
909
}
918
910
919
- auto OldSize = F.getVarContents ().size ();
920
911
SmallVector<char , 8 > Data;
921
912
MCDwarfFrameEmitter::encodeAdvanceLoc (Context, Value, Data);
922
913
F.setVarContents (Data);
923
914
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 ;
953
915
}
954
916
955
917
bool MCAssembler::relaxFragment (MCFragment &F) {
956
- switch (F.getKind ()) {
918
+ auto Size = computeFragmentSize (F);
919
+ switch (F.getKind ()) {
957
920
default :
958
921
return false ;
959
922
case MCFragment::FT_Relaxable:
960
923
assert (!getRelaxAll () && " Did not expect a FT_Relaxable in RelaxAll mode" );
961
- return relaxInstruction (F);
924
+ relaxInstruction (F);
925
+ break ;
962
926
case MCFragment::FT_LEB:
963
- return relaxLEB (F);
927
+ relaxLEB (F);
928
+ break ;
964
929
case MCFragment::FT_Dwarf:
965
- return relaxDwarfLineAddr (F);
930
+ relaxDwarfLineAddr (F);
931
+ break ;
966
932
case MCFragment::FT_DwarfFrame:
967
- return relaxDwarfCallFrameFragment (F);
933
+ relaxDwarfCallFrameFragment (F);
934
+ break ;
968
935
case MCFragment::FT_BoundaryAlign:
969
- return relaxBoundaryAlign (cast<MCBoundaryAlignFragment>(F));
936
+ relaxBoundaryAlign (static_cast <MCBoundaryAlignFragment &>(F));
937
+ break ;
970
938
case MCFragment::FT_CVInlineLines:
971
- return relaxCVInlineLineTable (cast<MCCVInlineLineTableFragment>(F));
939
+ getContext ().getCVContext ().encodeInlineLineTable (
940
+ *this , static_cast <MCCVInlineLineTableFragment &>(F));
941
+ break ;
972
942
case MCFragment::FT_CVDefRange:
973
- return relaxCVDefRange (cast<MCCVDefRangeFragment>(F));
943
+ getContext ().getCVContext ().encodeDefRange (
944
+ *this , static_cast <MCCVDefRangeFragment &>(F));
945
+ break ;
974
946
case MCFragment::FT_Fill:
975
- return relaxFill (cast<MCFillFragment>(F));
976
947
case MCFragment::FT_Org:
977
- return relaxOrg ( static_cast <MCOrgFragment &>(F)) ;
948
+ return F. getNext ()-> Offset - F. Offset != Size ;
978
949
}
950
+ return computeFragmentSize (F) != Size;
979
951
}
980
952
981
953
void MCAssembler::layoutSection (MCSection &Sec) {
@@ -1024,7 +996,7 @@ unsigned MCAssembler::relaxOnce(unsigned FirstStable) {
1024
996
for (;;) {
1025
997
bool Changed = false ;
1026
998
for (MCFragment &F : Sec)
1027
- if (relaxFragment (F))
999
+ if (F. getKind () != MCFragment::FT_Data && relaxFragment (F))
1028
1000
Changed = true ;
1029
1001
1030
1002
if (!Changed)
0 commit comments