Skip to content

Commit

Permalink
[MC] Speed up AttemptToFoldSymbolOffsetDifference in the absence of M…
Browse files Browse the repository at this point in the history
…CAsmLayout

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.
  • Loading branch information
MaskRay committed May 31, 2024
1 parent 3b81d9d commit b06e736
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions llvm/lib/MC/MCExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,14 @@ static void AttemptToFoldSymbolOffsetDifference(
if (FA == FB) {
Reverse = SA.getOffset() < SB.getOffset();
} else if (!isa<MCDummyFragment>(FA)) {
Reverse = std::find_if(std::next(FA->getIterator()), SecA.end(),
[&](auto &I) { return &I == FB; }) != SecA.end();
// Testing FA < FB is slow. Use setLayoutOrder to speed up computation.
// The formal layout order will be finalized in MCAssembler::layout.
if (FA->getLayoutOrder() == 0 || FB->getLayoutOrder()== 0) {
unsigned LayoutOrder = 0;
for (MCFragment &F : *FA->getParent())
F.setLayoutOrder(++LayoutOrder);
}
Reverse = FA->getLayoutOrder() < FB->getLayoutOrder();
}

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

0 comments on commit b06e736

Please sign in to comment.