[llvm] b06e736 - [MC] Speed up AttemptToFoldSymbolOffsetDifference in the absence of MCAsmLayout
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri May 31 11:09:35 PDT 2024
Author: Fangrui Song
Date: 2024-05-31T11:09:31-07:00
New Revision: b06e736982a3568fe2bcea8688550f9e393b7450
URL: https://github.com/llvm/llvm-project/commit/b06e736982a3568fe2bcea8688550f9e393b7450
DIFF: https://github.com/llvm/llvm-project/commit/b06e736982a3568fe2bcea8688550f9e393b7450.diff
LOG: [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 9500a5d02e23f9b43294e5f662ac099f8989c0e4 ("[MC] Make UseAssemblerInfoForParsing mostly true")
exposed this performance pitfall, which was mitigated by
`setUseAssemblerInfoForParsing(false)` workarounds (e.g. commit
245491a9f384e4c53421196533c2a2b693efaf8d). The workaround can be removed
now.
Added:
Modified:
llvm/lib/MC/MCExpr.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 28b2cbb0e8b04..bbee2a64032a0 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -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();
More information about the llvm-commits
mailing list