Skip to content

Commit aa97472

Browse files
aganeaMaskRay
authored andcommitted
Re-land [MC] Fix quadratic behavior in addPendingLabel
This was discovered when compiling large unity/blob/jumbo files. Differential Revision: https://reviews.llvm.org/D78775 (cherry picked from commit fd773e8)
1 parent b11ecd1 commit aa97472

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_MC_MCOBJECTSTREAMER_H
1010
#define LLVM_MC_MCOBJECTSTREAMER_H
1111

12+
#include "llvm/ADT/SetVector.h"
1213
#include "llvm/ADT/SmallVector.h"
1314
#include "llvm/MC/MCAssembler.h"
1415
#include "llvm/MC/MCSection.h"
@@ -38,7 +39,7 @@ class MCObjectStreamer : public MCStreamer {
3839
bool EmitEHFrame;
3940
bool EmitDebugFrame;
4041
SmallVector<MCSymbol *, 2> PendingLabels;
41-
SmallVector<MCSection*, 2> PendingLabelSections;
42+
SmallSetVector<MCSection *, 4> PendingLabelSections;
4243
unsigned CurSubsectionIdx;
4344
struct PendingMCFixup {
4445
const MCSymbol *Sym;

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,8 @@ void MCObjectStreamer::addPendingLabel(MCSymbol* S) {
5959
CurSection->addPendingLabel(S, CurSubsectionIdx);
6060

6161
// Add this Section to the list of PendingLabelSections.
62-
auto SecIt = std::find(PendingLabelSections.begin(),
63-
PendingLabelSections.end(), CurSection);
64-
if (SecIt == PendingLabelSections.end())
65-
PendingLabelSections.push_back(CurSection);
66-
}
67-
else
62+
PendingLabelSections.insert(CurSection);
63+
} else
6864
// There is no Section / Subsection for this label yet.
6965
PendingLabels.push_back(S);
7066
}

0 commit comments

Comments
 (0)