aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCAssembler.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-07-22MCAssembler: Remove getWriterPtrFangrui Song1-4/+4
Commit 8728e097dfbec3630a1dd907431c0f14274a1ae8 (2018) introduced getWriterPtr, which might be nullptr for MCAsmStreamer. This lured call sites to use getWriterPtr when it's guaranteed to be non-null for MCObjectstreamer. Remove this misleading API.
2024-07-22MCAssembler: Move LinkerOptions to MachObjectWriterFangrui Song1-1/+0
2024-07-22MCAssembler: Move FileNames and CompilerVersion to MCObjectWriterFangrui Song1-1/+0
2024-07-22MCAssmembler: Move ELFHeaderEFlags to ELFObjectWriterFangrui Song1-1/+0
Now that MCELFStreamer can access ELFObjectWriter (commit 70c52b62c5669993e341664a63bfbe5245e32884), we can move ELFHeaderEFlags there.
2024-07-21[MC] Compute fragment offsets eagerlyFangrui Song1-37/+40
This builds on top of commit 9d0754ada5dbbc0c009bcc2f7824488419cc5530 ("[MC] Relax fragments eagerly") and relaxes fragments eagerly to eliminate MCSection::HasLayout and `getFragmentOffset` overhead. Note: The removed `#ifndef NDEBUG` code (disabled by default) in X86AsmBackend::finishLayout was problematic, as (a) !NDEBUG and NDEBUG builds evaluated fragment offsets at different times before this patch (b) one iteration might not be sufficient to converge. There might be some edge cases that it did not handle. Anyhow, this patch probably makes it work for more cases.
2024-07-21[MC] Move VersionInfo to MachObjectWriterFangrui Song1-8/+1
2024-07-21[MC] Export llvm::WinCOFFObjectWriter and access it from MCWinCOFFStreamerFangrui Song1-1/+0
Similar to commit 28fcafb50274be2520117eacb0a886adafefe59d (2011) for MachObjectWriter. MCWinCOFFStreamer can now access WinCOFFObjectWriter directly without holding object file format specific inforamtion in MCAssembler (e.g. IncrementalLinkerCompatible).
2024-07-21[MC] Move LOHContainer to MachObjectwriterFangrui Song1-2/+0
2024-07-05MCAssembler: Remove unneeded non-const iterators for Sections and misleading ↵Fangrui Song1-4/+8
size() The pointers cannot be mutated even if the dereferenced MCSection can.
2024-07-05MCAssembler: Clean up iterator types for SymbolsFangrui Song1-4/+8
2024-07-04[MC] Move MCAssembler::DataRegions to MachObjectWriterFangrui Song1-1/+0
and make some cleanup.
2024-07-04[MC] Move MCAssembler::IndirectSymbols to MachObjectWriterFangrui Song1-1/+0
2024-07-03[MC] Move MCAssembler::isSymbolLinkerVisible to MCSymbolMachOFangrui Song1-11/+0
2024-07-02Remove llvm/MC/MCAsmLayout.h and the unused parameter in MCAssembler::layoutFangrui Song1-5/+2
This restores 63ec52f867ada8d841dd872acf3d0cb62e2a99e8 and 46f7929879a59ec72dc75679b4201e2d314efba9, NFC changes that were unnecessarily reverted. This completes the work that merges MCAsmLayout into MCAssembler. Pull Request: https://github.com/llvm/llvm-project/pull/97449
2024-07-02[MC] Use a stub ctor for MCAsmLayoutFangrui Song1-5/+4
and replace MCAssembler::Layout with a bool. This mostly completes "[MC] Start merging MCAsmLayout into MCAssembler". Note: BOLT used a dummy `MCAsmLayout` to call `getSymbolOffset`, which is technically not supported. There is some discussion in https://reviews.llvm.org/D154604 . The revert f80a4072ced41b52363c63df28fea9a649f7f89e is incorrect and actually broke bots.
2024-07-02Revert "[MC] Use a stub ctor for MCAsmLayout"Davide Italiano1-5/+5
This reverts commit bbb50369a149d9a7d1f91efaaabf75c260a220c7. This breaks BOLT.
2024-07-02Revert "MCAssembler::layout: remove the unused MCAsmLayout parameter"Davide Italiano1-2/+5
This reverts commit 63ec52f867ada8d841dd872acf3d0cb62e2a99e8.
2024-07-02Revert "[MC] Remove assert to work around BOLT"Davide Italiano1-0/+1
This reverts commit c72cb2766cec0ac519a051780ae5aed42485e012. The patch was not reviewed, and this assertion guards against incorrect values for symbols if the linker decides to modify the layout as it happens on some platforms. getSymbolOffset() is used for code size estimation, among others. Reverting for now, until we get proper code review and undersatnding of the implications.
2024-07-01[MC] Remove assert to work around BOLTFangrui Song1-1/+0
BOLT used a dummy `MCAsmLayout` to call `getSymbolOffset`, which is technically not supported. There is some discussion in https://reviews.llvm.org/D154604 that this is not ideal. For now, remove the assert. The assert was added by bbb50369a149d9a7d1f91efaaabf75c260a220c7.
2024-07-01MCAssembler::layout: remove the unused MCAsmLayout parameterFangrui Song1-5/+2
Almost complete the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95.
2024-07-01[MC] Use a stub ctor for MCAsmLayoutFangrui Song1-5/+5
and replace MCAssembler::Layout with a bool. This mostly completes "[MC] Start merging MCAsmLayout into MCAssembler".
2024-07-01[MC] Remove the MCAsmLayout parameter from MCAsmBackend::finishLayoutFangrui Song1-6/+1
And remove unnecessary MCAssembler::finishLayout.
2024-07-01MCCodeView: replace the MCAsmLayout parameter with MCAssemblerFangrui Song1-2/+2
2024-07-01MCExpr::evaluateKnownAbsolute: replace the MCAsmLayout parameter with ↵Fangrui Song1-4/+4
MCAssembler and add a comment.
2024-07-01MCExpr::evaluateAsRelocatable: replace the MCAsmLayout parameter with ↵Fangrui Song1-1/+1
MCAssembler Continue the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95.
2024-07-01[MC] Remove the evaluateAsAbsolute overload that takes a MCAsmLayout parameterFangrui Song1-2/+2
Continue the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95.
2024-07-01[MC] Remove the MCAsmLayout parameter from MCAsmBackend::relax*Fangrui Song1-5/+3
finishLayout is now the only member function that has a MCAsmLayout parameter.
2024-07-01[MC] Move MCAsmLayout::SectionOrder to MachObjectWriter::SectionOrderFangrui Song1-22/+9
Follow-up to 2c1fb411ce3aed148a278660d215e0f88ff9b9be. SectionOrder is Mach-O specific to place zerofill sections after non-zerofill sections in the object writer.
2024-07-01[MC] Remove MCAsmLayout::{getSymbolOffset,getBaseSymbol}Fangrui Song1-7/+0
The MCAsmLayout::* forwarders added by 67957a45ee1ec42ae1671cdbfa0d73127346cc95 have all been removed.
2024-07-01[MC] Remove MCAsmLayout::{getSectionFileSize,getSectionAddressSize}Fangrui Song1-6/+0
2024-07-01[MC] Remove the MCAsmLayout parameter from evaluateTargetFixupFangrui Song1-2/+2
2024-07-01[MC] Remove MCAsmLayout::getFragmentAddressFangrui Song1-4/+0
2024-07-01[MC] Remove the MCAsmLayout parameter from ↵Fangrui Song1-1/+1
MCObjectWriter::executePostLayoutBinding
2024-07-01[MC] Remove the MCAsmLayout parameter from ↵Fangrui Song1-7/+7
MCObjectWriter::{writeObject,writeSectionData}
2024-07-01[MC] Remove the MCAsmLayout parameter from relocation related functionsFangrui Song1-4/+4
2024-06-30[MC] Remove the MCAsmLayout parameter from MCObjectWriter::recordRelocationFangrui Song1-1/+1
2024-06-30[MC] Start merging MCAsmLayout into MCAssemblerFangrui Song1-110/+116
Follow-up to 10c894cffd0f4bef21b54a43b5780240532e44cf. MCAsmLayout, introduced by ac8a95498a99eb16dff9d3d0186616645d200b6e (2010), provides APIs to compute fragment/symbol/section offsets. The separate class is cumbersome and passing it around has overhead. Let's remove it as the underlying implementation is tightly coupled with MCAsmLayout anyway. Some forwarders are added to ease migration.
2024-06-30[MC] Move MCAsmLayout from MCFragment.cpp to MCAssembler.cpp. NFCFangrui Song1-5/+127
8d736236d36ca5c98832b7631aea2e538f6a54aa (2015) moved these MCAsmLayout functions to MCFragment.cpp, but the original placement is better as these functions are tightly coupled with MCAssembler.cpp.
2024-06-30[MC] Move Mach-O specific getAtom and isSectionAtomizableBySymbols to Mach-O ↵Fangrui Song1-19/+0
files and devirtualize isSectionAtomizableBySymbols.
2024-06-30[MC] Move bool members earlier. NFCFangrui Song1-6/+4
RelaxAll/SubsectionsViaSyms are used more frequently then vector members like Sections/Symbols. The size of MCAssembler doesn't particularly matter, so avoid bit fields.
2024-06-27[MC] Ensure subsections have a MCDataFragmentFangrui Song1-2/+1
Similar to 21fac2d1d060b0f9b11a746718e58d4cd1ee97e5 for sections. This makes it feasible to cache the current fragment in MCStreamer.
2024-06-27[MC] Chain together fragments only if Subsections.size() > 1Fangrui Song1-15/+16
and delete an unneeded setParent call.
2024-06-23[MC] Ensure all new sections have a MCDataFragmentFangrui Song1-10/+2
MCAssembler::layout ensures that every section has at least one fragment, which simplifies MCAsmLayout::getSectionAddressSize (see e73353c7201a3080851d99a16f5fe2c17f7697c6 from 2010). It's better to ensure the condition is satisfied at create time (COFF, GOFF, Mach-O) to simplify more fragment processing.
2024-06-22[MC] Move computeBundlePadding closer to its only caller. NFCFangrui Song1-2/+42
There is only one caller after #95188.
2024-06-22[MC] Remove pending labelsFangrui Song1-2/+7
This commit removes the complexity introduced by pending labels in https://reviews.llvm.org/D5915 by using a simpler approach. D5915 aimed to ensure padding placement before `.Ltmp0` for the following code, but at the cost of expensive per-instruction `flushPendingLabels`. ``` // similar to llvm/test/MC/X86/AlignedBundling/labeloffset.s .bundle_lock align_to_end calll .L0$pb .bundle_unlock .L0$pb: popl %eax .Ltmp0: //// padding should be inserted before this label instead of after addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %eax ``` (D5915 was adjusted by https://reviews.llvm.org/D8072 and https://reviews.llvm.org/D71368) This patch achieves the same goal by setting the offset of the empty MCDataFragment (`Prev`) in `layoutBundle`. This eliminates the need for pending labels and simplifies the code. llvm/test/MC/MachO/pending-labels.s (D71368): relocation symbols are changed, but the result is still supported by linkers.
2024-06-21[MC] Remove the Parent parameter from MCFragment ctor callers. NFCFangrui Song1-1/+2
2024-06-14[MC] Aligned bundling: remove special handling for RelaxAllFangrui Song1-7/+1
When both aligned bundling and RelaxAll are enabled, bundle padding is directly written into fragments (https://reviews.llvm.org/D8072). (The original motivation was memory usage, which has been achieved from different angles with recent assembler improvement). The code presents challenges with the work to replace fragment representation (e.g. #94950 #95077). This patch removes the special handling. RelaxAll still works but the behavior seems slightly different as revealed by 2 changed tests. However, most `-mc-relax-all` tests are unchanged. RelaxAll used to be the default for clang -O0. This mode has significant code size drawbacks and newer Clang doesn't use it (#90013). --- flushPendingLabels: The FOffset parameter can be removed: pending labels will be assigned to the incoming fragment at offset 0. Pull Request: https://github.com/llvm/llvm-project/pull/95188
2024-06-14[MC] Add MCFragment allocation helpersFangrui Song1-2/+5
`allocFragment` might be changed to a placement new when the allocation strategy changes. `allocInitialFragment` is to deduplicate the following pattern ``` auto *F = new MCDataFragment(); Result->addFragment(*F); F->setParent(Result); ``` Pull Request: https://github.com/llvm/llvm-project/pull/95197
2024-06-11[MC] Replace fragment ilist with singly-linked listsFangrui Song1-1/+14
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
2024-06-10[MC] Remove getFragmentList uses. NFCFangrui Song1-1/+1