diff options
author | Fangrui Song <i@maskray.me> | 2024-06-11 09:18:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-11 09:18:31 -0700 |
commit | de19f7b6d46f1c38e10e604154f0fdaaffde9ebd (patch) | |
tree | c12a54c936c1a823b3589b30e1974b4bb07ef759 /llvm/lib/MC/MCAssembler.cpp | |
parent | 4cf607fa15fd9ccd79115095a1eb02e0cd83e1a9 (diff) | |
download | llvm-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.cpp | 15 |
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; |