Skip to content

Commit b06e736

Browse files
committed
[MC] Speed up AttemptToFoldSymbolOffsetDifference in the absence of MCAsmLayout
The `FA < FB` check added by https://reviews.llvm.org/D153096 is slow. Compute an informal layout order to speed up computation when `AttemptToFoldSymbolOffsetDifference` is repeatedly called for the same section. Commit 9500a5d ("[MC] Make UseAssemblerInfoForParsing mostly true") exposed this performance pitfall, which was mitigated by `setUseAssemblerInfoForParsing(false)` workarounds (e.g. commit 245491a). The workaround can be removed now.
1 parent 3b81d9d commit b06e736

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

llvm/lib/MC/MCExpr.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,14 @@ static void AttemptToFoldSymbolOffsetDifference(
675675
if (FA == FB) {
676676
Reverse = SA.getOffset() < SB.getOffset();
677677
} else if (!isa<MCDummyFragment>(FA)) {
678-
Reverse = std::find_if(std::next(FA->getIterator()), SecA.end(),
679-
[&](auto &I) { return &I == FB; }) != SecA.end();
678+
// Testing FA < FB is slow. Use setLayoutOrder to speed up computation.
679+
// The formal layout order will be finalized in MCAssembler::layout.
680+
if (FA->getLayoutOrder() == 0 || FB->getLayoutOrder()== 0) {
681+
unsigned LayoutOrder = 0;
682+
for (MCFragment &F : *FA->getParent())
683+
F.setLayoutOrder(++LayoutOrder);
684+
}
685+
Reverse = FA->getLayoutOrder() < FB->getLayoutOrder();
680686
}
681687

682688
uint64_t SAOffset = SA.getOffset(), SBOffset = SB.getOffset();

0 commit comments

Comments
 (0)