aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCAssembler.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-06-11 09:18:31 -0700
committerGitHub <noreply@github.com>2024-06-11 09:18:31 -0700
commitde19f7b6d46f1c38e10e604154f0fdaaffde9ebd (patch)
treec12a54c936c1a823b3589b30e1974b4bb07ef759 /llvm/lib/MC/MCAssembler.cpp
parent4cf607fa15fd9ccd79115095a1eb02e0cd83e1a9 (diff)
downloadllvm-de19f7b6d46f1c38e10e604154f0fdaaffde9ebd.zip
llvm-de19f7b6d46f1c38e10e604154f0fdaaffde9ebd.tar.gz
llvm-de19f7b6d46f1c38e10e604154f0fdaaffde9ebd.tar.bz2
[MC] Replace fragment ilist with singly-linked lists
Fragments are allocated with `operator new` and stored in an ilist with Prev/Next/Parent pointers. A more efficient representation would be an array of fragments without the overhead of Prev/Next pointers. As the first step, replace ilist with singly-linked lists. * `getPrevNode` uses have been eliminated by previous changes. * The last use of the `Prev` pointer remains: for each subsection, there is an insertion point and the current insertion point is stored at `CurInsertionPoint`. * `HexagonAsmBackend::finishLayout` needs a backward iterator. Save all fragments within `Frags`. Hexagon programs are usually small, and the performance does not matter that much. To eliminate `Prev`, change the subsection representation to singly-linked lists for subsections and a pointer to the active singly-linked list. The fragments from all subsections will be chained together at layout time. Since fragment lists are disconnected before layout time, we can remove `MCFragment::SubsectionNumber` (https://reviews.llvm.org/D69411). The current implementation of `AttemptToFoldSymbolOffsetDifference` requires future improvement for robustness. Pull Request: https://github.com/llvm/llvm-project/pull/95077
Diffstat (limited to 'llvm/lib/MC/MCAssembler.cpp')
-rw-r--r--llvm/lib/MC/MCAssembler.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 8490853e..4ff606d 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -831,6 +831,19 @@ void MCAssembler::layout(MCAsmLayout &Layout) {
MCSection *Sec = Layout.getSectionOrder()[i];
Sec->setLayoutOrder(i);
+ // Chain together fragments from all subsections.
+ MCDummyFragment Dummy(Sec);
+ MCFragment *Tail = &Dummy;
+ for (auto &[_, List] : Sec->Subsections) {
+ if (!List.Head)
+ continue;
+ Tail->Next = List.Head;
+ Tail = List.Tail;
+ }
+ Sec->Subsections.clear();
+ Sec->Subsections.push_back({0u, {Dummy.getNext(), Tail}});
+ Sec->CurFragList = &Sec->Subsections[0].second;
+
unsigned FragmentIndex = 0;
for (MCFragment &Frag : *Sec)
Frag.setLayoutOrder(FragmentIndex++);
@@ -1094,7 +1107,7 @@ bool MCAssembler::relaxBoundaryAlign(MCAsmLayout &Layout,
uint64_t AlignedOffset = Layout.getFragmentOffset(&BF);
uint64_t AlignedSize = 0;
- for (const MCFragment *F = BF.getNextNode();; F = F->getNextNode()) {
+ for (const MCFragment *F = BF.getNext();; F = F->getNext()) {
AlignedSize += computeFragmentSize(Layout, *F);
if (F == BF.getLastFragment())
break;