aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC
AgeCommit message (Collapse)AuthorFilesLines
22 hours[Support] Deprecate one form of support::endian::byte_swap (NFC) (#161045)Kazu Hirata1-3/+2
This is a follow-up to #156140 and #160979, which deprecated one form of write and read, respectively. We have two forms of byte_swap: template <typename value_type> [[nodiscard]] inline value_type byte_swap(value_type value, endianness endian) template <typename value_type, endianness endian> [[nodiscard]] inline value_type byte_swap(value_type value) The difference is that endian is a function parameter in the former but a template parameter in the latter. This patch streamlines the code by migrating the use of the latter to the former while deprecating the latter because the latter is just forwarded to the former.
3 days[DirectX] Updating DXContainer Yaml to represent Root Signature 1.2 (#159659)joaosaffran1-3/+8
This PR updates the YAML representation of DXContainer to support Root Signature 1.2, this also requires updating the write logic to support testing.
3 days[NFC][LLVM] Pass/return SMLoc by value instead of const reference (#160797)Rahul Joshi1-1/+1
SMLoc itself encapsulates just a pointer, so there is no need to pass or return it by reference.
5 days[SFrames] Implement .cfi_restore, remember_state, and restore_state (#159832)Sterling-Augustine1-5/+24
As in the description. Very straightforward.
5 days[MC][COFF] Add missing sections for DWO (#157239)Tomohiro Kashiwada1-0/+8
Add DWO sections `.debug_loclists.dwo` and `.debug_rnglists.dwo` to the COFF targets. This enables building with `-DLLVM_USE_SPLIT_DWARF=ON` on the Cygwin target, which previously failed due to compiler crashes.
6 days[NFC][MC][CodeEmitterGen] Extract error reporting into a helper function ↵Rahul Joshi1-0/+19
(#159778) Extract error reporting code emitted by CodeEmitterGen into MCCodeEmitter static members functions. Additionally, remove unused ErrorHandling.h header from several files.
11 days[SFrames] reland Emit and relax FREs #158154 (#159643)Sterling-Augustine4-18/+198
[Previously reverted due to msan failures on two uninitialized padding bits.] This PR emits and relaxes the FREs generated in the previous PR. After this change llvm emits usable sframe sections that can be linked with the gnu linker. There are a few remaining cfi directives to handle before they are generally usable, however. The output isn't identical with gnu-gas in every case (this code produces fewer identical FREs in a row than gas), but I'm reasonably sure that they are correct regardless. There are even more size optimizations that can be done later. Also, while working on the tests, I found a few bugs in older portions and cleaned those up. This is a fairly big commit, but I'm not sure how to make it smaller.
12 daysRevert "[SFrames] Emit and relax FREs (#158154)" (#159436)Sterling-Augustine4-197/+17
Breaks some buildbots This reverts commit c9285166214db4236f26312f68bba91f6437bd6f.
12 days[SFrames] Emit and relax FREs (#158154)Sterling-Augustine4-17/+197
This PR emits and relaxes the FREs generated in the previous PR. After this change llvm emits usable sframe sections that can be linked with the gnu linker. There are a few remaining cfi directives to handle before they are generally usable, however. The output isn't identical with gnu-gas in every case (this code produces fewer identical FREs in a row than gas), but I'm reasonably sure that they are correct regardless. There are even more size optimizations that can be done later. Also, while working on the tests, I found a few bugs in older portions and cleaned those up. This is a fairly big commit, but I'm not sure how to make it smaller.
13 daysReapply "[DebugLine] Correct debug line emittion" (#158343) (#158379)Peter Rong1-10/+20
This reverts commit aabf18d7184298566993e3141606cd79ff617d2d. #157529 included a test that used clang, which doesn't exists in some CI. #158343 reverts it. This PR reapplies the original patch with the incorrect test removed. ### Context #99710 introduced `.loc_label` so we can terminate a line sequence. However, it did not advance PC properly. This is problematic for 1-instruction functions as it will have zero-length sequence. The test checked in that PR shows the problem: ``` # CHECK-LINE-TABLE: Address Line Column File ISA Discriminator OpIndex Flags # CHECK-LINE-TABLE-NEXT: ------------------ ------ ------ ------ --- ------------- ------- ------------- # CHECK-LINE-TABLE-NEXT: 0x00000028: 05 DW_LNS_set_column (1) # CHECK-LINE-TABLE-NEXT: 0x0000002a: 00 DW_LNE_set_address (0x0000000000000000) # CHECK-LINE-TABLE-NEXT: 0x00000035: 01 DW_LNS_copy # CHECK-LINE-TABLE-NEXT: 0x0000000000000000 1 1 1 0 0 0 is_stmt # CHECK-LINE-TABLE-NEXT: 0x00000036: 00 DW_LNE_end_sequence # CHECK-LINE-TABLE-NEXT: 0x0000000000000000 1 1 1 0 0 0 is_stmt end_sequence ``` Both rows having PC 0x0 is incorrect, and parsers won't be able to parse them. See more explanation why this is wrong in #154851. ### Design This PR attempts to fix this by advancing the PC to the next available Label, and advance to the end of the section if no Label is available. ### Implementation - `emitDwarfLineEndEntry` will advance PC to the `CurrLabel` - If `CurrLabel` is null, its probably a fake LineEntry we introduced in #110192. In that case look for the next Label - If still not label can be found, use `null` and `emitDwarfLineEndEntry` is smart enough to advance PC to the end of the section - Rename `LastLabel` to `PrevLabel`, "last" can mean "previous" or "final", this is ambigous. - Updated the tests to emit a correct label. ### Note This fix should render #154986 and #154851 obsolete, they were temporary fixes and don't resolve the root cause.
13 daysMC: Better handle backslash-escaped symbols (#158780)Fangrui Song8-42/+47
The MCContext::getOrCreateSymbol change in #138817 was a workaround. With #158106, we can replace `getOrCreateSymbol` with `parseSymbol`, in llvm/lib/MC/MCParser to handle backslash-escaped symbols.
2025-09-12Revert "[DebugLine] Correct debug line emittion" (#158343)David Blaikie1-20/+10
Reverts llvm/llvm-project#157529 Sorry, I missed that the missed that the LLVM test was using clang - layering dictates thats not OK. Please readjust the test case to work like the existing test coverage (or perhaps the existing test coverage is sufficient?) and post a new PR.
2025-09-12[DebugLine] Correct debug line emittion (#157529)Peter Rong1-10/+20
### Context #99710 introduced `.loc_label` so we can terminate a line sequence. However, it did not advance PC properly. This is problematic for 1-instruction functions as it will have zero-length sequence. The test checked in that PR shows the problem: ``` # CHECK-LINE-TABLE: Address Line Column File ISA Discriminator OpIndex Flags # CHECK-LINE-TABLE-NEXT: ------------------ ------ ------ ------ --- ------------- ------- ------------- # CHECK-LINE-TABLE-NEXT: 0x00000028: 05 DW_LNS_set_column (1) # CHECK-LINE-TABLE-NEXT: 0x0000002a: 00 DW_LNE_set_address (0x0000000000000000) # CHECK-LINE-TABLE-NEXT: 0x00000035: 01 DW_LNS_copy # CHECK-LINE-TABLE-NEXT: 0x0000000000000000 1 1 1 0 0 0 is_stmt # CHECK-LINE-TABLE-NEXT: 0x00000036: 00 DW_LNE_end_sequence # CHECK-LINE-TABLE-NEXT: 0x0000000000000000 1 1 1 0 0 0 is_stmt end_sequence ``` Both rows having PC 0x0 is incorrect, and parsers won't be able to parse them. See more explanation why this is wrong in #154851. ### Design This PR attempts to fix this by advancing the PC to the next available Label, and advance to the end of the section if no Label is available. ### Implementation - `emitDwarfLineEndEntry` will advance PC to the `CurrLabel` - If `CurrLabel` is null, its probably a fake LineEntry we introduced in #110192. In that case look for the next Label - If still not label can be found, use `null` and `emitDwarfLineEndEntry` is smart enough to advance PC to the end of the section - Rename `LastLabel` to `PrevLabel`, "last" can mean "previous" or "final", this is ambigous. - Updated the tests to emit a correct label. ### Note This fix should render #154986 and #154851 obsolete, they were temporary fixes and don't resolve the root cause. --------- Signed-off-by: Peter Rong <PeterRong@meta.com>
2025-09-12[MC] Add parseSymbol() helper (NFC) (#158106)Nikita Popov8-156/+94
This combines parseIdentifier() + getOrCreateSymbol(). This should make it a bit easier if we want to change the parseIdentifier() API.
2025-09-10[DirectX] Removing dxbc DescriptorRange from mcbxdc (#154629)joaosaffran1-1/+2
MC Descriptor Range Representation currently depend on Object structures. This PR removes that dependency and in order to facilitate removing to_underlying usage in follow-up PRs.
2025-09-09MC: Use Triple form of lookupTarget in more places (#157591)Matt Arsenault1-2/+3
2025-09-08Parse CFI instructions to create SFrame FREs (#155496)Sterling-Augustine1-5/+191
This PR parses CFI instructions to generate FREs. Unfortunately, actually emitting the FREs into the object file is somewhat involved and would make this PR quite a bit harder to review. And the dumper itself properly errors if the FRE count is included in the header or FDEs, but they are not actually emitted. So actually testing that the proper FREs are generated will have to wait for a subsequent PR. For now, just check for common issues with CFI that sframe doesn't support, and that proper error handling is done.
2025-09-08MC: Add Triple overloads for more MC constructors (#157321)Matt Arsenault1-7/+10
Avoids more Triple->string->Triple round trip. This is a continuation of f137c3d592e96330e450a8fd63ef7e8877fc1908
2025-09-01[PseudoProbe] Support emitting to COFF object (#123870)Haohai Wen1-31/+65
RFC: https://discourse.llvm.org/t/rfc-support-pseudo-probe-for-windows-coff/83820 Support emitting pseudo probe to .pseudo_probe and .pseudo_probe_desc COFF sections.
2025-08-29[DirectX] Removing dxbc RootSignature and RootDescriptor from mcbxdc (#154585)joaosaffran1-2/+2
2025-08-29[win][x64] Various fixes for unwind v2 (#154834)Daniel Paoliello1-9/+15
* `SetFrame` does not count as a stack allocation. * `mov` in the epilog undoes `SetFrame` (but is not required), it does not deallocate a stack allocation. * `mov` in the epilog MUST be before any stack deallocation or register popping. * Remove assert for having a prolog without any epilogs (this is possible for `noreturn` functions, for instance). * Improve the errors in `MC` to include the problematic function name.
2025-08-29[llvm] Support building with c++23 (#154372)Kyle Krüger1-0/+6
closes #154331 This PR addresses all minimum changes needed to compile LLVM and MLIR with the c++23 standard. It is a work in progress and to be reviewed for better methods of handling the parts of the build broken by c++23.
2025-08-28[DirectX] Don't byte-swap returned byte-offset (#155860)Finn Plummer1-2/+3
- The returned byte offset from `rewriteOffsetToCurrentByte` should not be byte-swapped as it will be compared and interpreted as a uint32_t in its uses This commit corrects build failures that hit an assert on big-endian builds
2025-08-28Disassembler: Remove unused include (#155771)Matt Arsenault1-1/+0
2025-08-27[DirectX][ObectYAML] Make `RootParameterOffset` and `StaticSamplersOffset` ↵Finn Plummer1-34/+42
behaviour consistent (#155521) This pr fixes some inconsistencies in behaviour of how we handle `StaticSamplersOffset` with respect to DXC and `RootParameterOffset`. Namely: 1. Make codegen of `RTS0` always compute the `StaticSamplersOffset` regardless if there are any `StaticSampler`s. This is to be consistent and produce an identical `DXContainer` as DXC. 2. Make the `StaticSamplersOffset` and `RootParametersOffset` optional parameters in the yaml description. This means it will be used when it is specified (which was not necassarily the case before). 3. Enforce that the provided `StaticSamplersOffset` and `RootParametersOffset` in a yaml description match the computed value. For more context see: https://github.com/llvm/llvm-project/issues/155299. Description of existing test updates updates: - `CodeGen/DirectX/ContainerData`: Updated to codegen computed values (previously unspecified) - `llvm-objcopy/DXContainer`: Updated to `yaml2obj` computed values (previously unspecified) - `ObjectYAML/DXContainer`: Updated to `yaml2obj` computed values (previously incorrect) - `ObjectYAML/DXContainerYAMLTest`: Updated to `yaml2obj` computed values (previously incorrect) See newly added tests for testing of optional parameter functionality and `StaticSamplersOffset` computation. Resolves: https://github.com/llvm/llvm-project/issues/155299
2025-08-25[DirectX] Refactor RootSignature Backend to remove `to_underlying` from Root ↵joaosaffran1-21/+19
Parameter Header (#154249) This patch is refactoring Root Parameter Header in DX Container backend to remove the usage of `to_underlying`. This requires some changes: first, MC Root Signature should not depend on Object/DXContainer.h; Second, we need to assume data to be valid in scenarios where it was originally not expected, this made some tests be removed.
2025-08-24[WebAssembly] Implement the `.reloc` directive for WASM (#146952)SingleAccretion1-2/+6
The implementation follows what is done for ELF on other targets. Fixes #100733.
2025-08-23MCAssembler: Simplify relaxation of FT_Fill and FT_OrgFangrui Song1-15/+4
2025-08-23MCAssembler: Simplify fragment relaxationFangrui Song1-67/+50
* FT_Data: skip relaxFragment * Others: Call relaxFragment, which computes the old size, calls the relevant relaxXXX function, then compares the size.
2025-08-23MCAssembler: Simplify getSectionAddressSizeFangrui Song1-3/+2
The tail fragment must be of type FT_Data. Reduce a computeFragmentSize use.
2025-08-22[SFrames] Add FDEs for functions with .cfi_startproc (#154213)Sterling-Augustine1-3/+80
This continues the sframe implementation. This change tracks and fills out the necessary fields for FDEs, but doesn't create or add FREs.
2025-08-22MCSymbol: Move isExported/setExported to MCSymbol{COFF,MachO,Wasm}Fangrui Song1-1/+0
Make it clear that other object file formats (e.g. ELF) do not use this field.
2025-08-22MCSymbol: Avoid isExported/setExportedFangrui Song3-15/+19
The next change will move these methods from the base class.
2025-08-22[RISCV] Add initial assembler/MC layer support for big-endian (#146534)Djordje Todorovic1-1/+7
This patch adds basic assembler and MC layer infrastructure for RISC-V big-endian targets (riscv32be/riscv64be): - Register big-endian targets in RISCVTargetMachine - Add big-endian data layout strings - Implement endianness-aware fixup application in assembler backend - Add byte swapping for data fixups on BE cores - Update MC layer components (AsmInfo, MCTargetDesc, Disassembler, AsmParser) This provides the foundation for BE support but does not yet include: - Codegen patterns for BE - Load/store instruction handling - BE-specific subtarget features
2025-08-22MCSymbol: Avoid isExported/setExportedFangrui Song3-10/+13
The next change will move it to MCSymbol{COFF,MachO,Wasm} to make it clear that other object file formats (e.g. ELF) do not use this field.
2025-08-21MC: Avoid MCSymbol::isExportedFangrui Song1-19/+20
This bit is only used by COFF/MachO. The upcoming change will move isExported/setExported to MCSymbolCOFF/MCSymbolMachO.
2025-08-17[llvm] Remove unused includes (NFC) (#154051)Kazu Hirata12-12/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-08-17MCSymbol: Remove setUndefinedFangrui Song1-1/+1
The name is misleading, as setting Fragment to nullptr does not necessarily make it undefined - common and equated symbols have a nullptr fragment as well.
2025-08-16MCSymbol: Remove AMDGPU-specific Kind::TargetCommonFangrui Song1-4/+4
The SymContentsTargetCommon kind introduced by https://reviews.llvm.org/D61493 lackes significant and should be treated as a regular common symbol with a different section index. Update ELFObjectWriter to respect the specified section index. The new representation also works with Hexagon's SHN_HEXAGON_SCOMMON.
2025-08-16MCSymbol: Rename SymContents to kindFangrui Song1-5/+4
The names "SymbolContents" and "SymContents*" members are confusing. Rename to kind and Kind::XXX similar to lld/ELF/Symbols.h Rename SymContentsVariable to Kind::Equated as the former term is "equated symbol", not "variable".
2025-08-16MCSymbol: Decrease the bitfield size of SymbolContentsFangrui Song1-0/+4
Follow-up to 57b0843f68f5f349c73d1bf54e321a1a6d1800bf The size of MCSymbol has been reduced to 24 bytes on 64-bit systems.
2025-08-13[NFC][MC][GOFF] Use `llvm_unreachable` for unreachable case (#152930)Abhishek Kaushik1-2/+2
2025-08-12Generate an .sframe section with a skeleton header (#151223)Sterling-Augustine4-1/+123
This continues the sframe implementation discussed previously. Of note, this also adds some target dependent functions to the object file. Additional fields will be needed later. It would be possible to do all of this inside the sframe implementation itself if it feels a little messy and specialized, but generally I think that target info goes with target info. Another question is if we want a sentinel value for unimplemented sframe abi arches, or a std::optional. Both work.
2025-08-12[RISCV] Track Linker Relaxable through Assembly Relaxation (#152602)Sam Elliott3-3/+19
Span-dependent instructions on RISC-V interact in a complex manner with linker relaxation. The span-dependent assembler algorithm implemented in LLVM has to start with the smallest version of an instruction and then only make it larger, so we compress instructions before emitting them to the streamer. When the instruction is streamed, the information that the instruction (or rather, the fixup on the instruction) is linker relaxable must be accurate, even though the assembler relaxation process may transform a not-linker-relaxable instruction/fixup into one that that is linker relaxable, for instance `c.jal` becoming `qc.e.jal`, or `bne` getting turned into `beq; jal` (the `jal` is linker relaxable). In order for this to work, the following things have to happen: - Any instruction/fixup which might be relaxed to a linker-relaxable instruction/fixup, gets marked as `RelaxCandidate = true` in RISCVMCCodeEmitter. - In RISCVAsmBackend, when emitting the `R_RISCV_RELAX` relocation, we have to check that the relocation/fixup kind is one that may need a relax relocation, as well as that it is marked as linker relaxable (the latter will not be set if relaxation is disabled). - Linker Relaxable instructions streamed to a Relaxable fragment need to mark the fragment and its section as linker relaxable. I also added more debug output for Sections/Fixups which are marked Linker Relaxable. This results in more relocations, when these PC-relative fixups cross an instruction with a fixup that is resolved as not linker-relaxable but caused the fragment to be marked linker relaxable at streaming time (i.e. `c.j`). Fixes: #150071
2025-08-10Revert "[NFC][MC] Removed unused switch case in `emitCATTR`" (#152929)Abhishek Kaushik1-0/+2
Reverts llvm/llvm-project#152907 This is causing some build failures.
2025-08-10[NFC][MC] Removed unused switch case in `emitCATTR` (#152907)Abhishek Kaushik1-2/+0
The switch statement `switch (Rmode)` is in an if-block that checks if `Rmode != GOFF::ESD_RMODE_None` making the `case GOFF::ESD_RMODE_None:` unnecessary.
2025-08-07MC: Refine ALIGN relocation conditionsFangrui Song2-2/+2
Each section now tracks the index of the first linker-relaxable fragment, enabling two changes: * Delete redundant ALIGN relocations before the first linker-relaxable instruction in a section. The primary example is the offset 0 R_RISCV_ALIGN relocation for a text section aligned by 4. * For alignments larger than the NOP size after the first linker-relaxable instruction, ALIGN relocations are now generated, even in norelax regions. This fixes the issue #150159. The new test llvm/test/MC/RISCV/Relocations/align-after-relax.s verifies the required ALIGN in a norelax region following linker-relaxable instructions. By using a fragment index within the subsection (which is less than or equal to the section's index), the implementation may generate redundant ALIGN relocations in lower-numbered subsections before the first linker-relaxable instruction. align-option-relax.s demonstrates the ALIGN optimization. Add an initial `call` to a few tests to prevent the ALIGN optimization. --- When the alignment exceeds 2, we insert $alignment-2 bytes of NOPs, even in non-RVC code. This enables non-RVC code following RVC code to handle a 2-byte adjustment without requiring an additional state in MCSection or AsmParser. ``` .globl _start _start: // GNU ld can relax this to 6505 lui a0, 0x1 // LLD hasn't implemented this transformation. lui a0, %hi(foo) .option push .option norelax .option norvc // Now we generate R_RISCV_ALIGN with addend 2, even if this is a norvc region. .balign 4 b0: .word 0x3a393837 .option pop foo: ``` Pull Request: https://github.com/llvm/llvm-project/pull/150816
2025-08-06MC,AMDGPU: Don't pad .text with s_code_end if it would otherwise be empty ↵Tim Renouf1-0/+5
(#147980) We don't want that padding in a module that only contains data, not code. Also fix MCSection::hasInstructions() so it works with the asm streamer too.
2025-08-04Reapply "MCFragment: Use trailing data for fixed-size part" (#150846)Fangrui Song3-18/+105
The fixed-size content of the MCFragment object is now stored as trailing data, replacing ContentStart/ContentEnd with ContentSize. The available space for trailing data is tracked using `FragSpace`. If the available space is insufficient, a new block is allocated within the bump allocator `MCObjectStreamer::FragStorage`. FragList::Tail cannot be reused when switching sections or subsections, as it is not associated with the fragment space tracked by `FragSpace`. Instead, allocate a new fragment, which becomes less expensive after #150574. Data can only be appended to the tail fragment of a subsection, not to fragments in the middle. Post-assembler-layout adjustments (such as .llvm_addrsig and .llvm.call-graph-profile) have been updated to use the variable-size part instead. --- This reverts commit a2fef664c29a53bfa8a66927fcf8b2e5c9da4876, which reverted the innocent f1aa6050bd90f8ec4273da55d362e23905ad3a81 . Commit df71243fa885cd3db701dc35a0c8d157adaf93b3, the MCOrgFragment fix, has fixed the root cause of https://github.com/ClangBuiltLinux/linux/issues/2116
2025-08-04MC: Evaluate .org during fragment relaxationFangrui Song1-0/+10
Similar to 742ecfc13e8aa34cfff2900e31838f657fcafe30 for MCFillFragment, ensure `.org` directives with expressions are re-evaluated during fragment relaxation, as their sizes may change. Continue iteration to prevent stale, incorrect sizes. While I knew MCOrgFragment likely needed to be re-evaluated at all, I did not have a motivation to add it;-) This fixes the root cause of https://github.com/ClangBuiltLinux/linux/issues/2116 (writeSectionData assertion failure when building the Linux kernel for arm64) The issue cannot be reliably replicated. The specific test case would not replicate if any of the following condition was not satisfied: * .org was not re-evaluated. Fixed by this commit. * clang -cc1as has a redundant `initSections` call, leading to a redundant initial FT_Align fragment. llvm-mc -filetype=obj, lacking the redundant `initSections`, doesn't replicate. * faa931b717c02d57f0814caa9133219040e6a85b decreased sizeof(MCFragment). * f1aa6050bd90f8ec4273da55d362e23905ad3a81 added more fragments