aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-05-31 11:09:31 -0700
committerFangrui Song <i@maskray.me>2024-05-31 11:09:31 -0700
commitb06e736982a3568fe2bcea8688550f9e393b7450 (patch)
tree04d0ffafd6e738ea4af9e7f2a0a273685cb44635 /llvm/lib/MC
parent3b81d9d91b18c2bd06bd36d8512a3a284a8980a9 (diff)
downloadllvm-b06e736982a3568fe2bcea8688550f9e393b7450.zip
llvm-b06e736982a3568fe2bcea8688550f9e393b7450.tar.gz
llvm-b06e736982a3568fe2bcea8688550f9e393b7450.tar.bz2
[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.
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r--llvm/lib/MC/MCExpr.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 28b2cbb..bbee2a6 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();