summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
AgeCommit message (Collapse)Author
2025-07-02MCAsmBackend: Simplify shouldForceRelocation overridesFangrui Song
2025-07-02MCAsmBackend: Merge addReloc into applyFixup (#146820)Fangrui Song
Follow-up to #141333. Relocation generation called both addReloc and applyFixup, with the default addReloc invoking shouldForceRelocation, resulting in three virtual calls. This approach was also inflexible, as targets needing additional data required extending `shouldForceRelocation` (see #73721, resolved by #141311). This change integrates relocation handling into applyFixup, eliminating two virtual calls. The prior default addReloc is renamed to maybeAddReloc. Targets overriding addReloc now call their customized addReloc implementation.
2025-05-23MCAsmBackend: Remove the MCAssembler argument from shouldForceRelocationFangrui Song
It is only required by ARM, which can now use the member variable.
2025-05-23MCAsmBackend: Simplify applyFixup (#141333)Fangrui Song
Remove the MCSubtargetInfo argument from applyFixup, introduced in https://reviews.llvm.org/D45962 , as it's only required by ARM. Instead, add const MCFragment & so that ARMAsmBackend can retrieve MCSubtargetInfo via a static member function. Additionally, remove the MCAssembler argument, which is also only required by ARM. Additionally, make applyReloc non-const. Its arguments now fully cover addReloc's functionality.
2025-05-23MCAsmBackend: Add member variable MCAssembler * and define getContextFangrui Song
A lot of member functions have the MCAssembler * argument just to call getContext. Let's cache the MCAssembler pointer.
2025-05-23[MC] Don't pass MCSubtargetInfo down to shouldForceRelocation and ↵Fangrui Song
evaluateTargetFixup (#141311) This reverts the code change in commit e87f33d9ce785668223c3bcc4e06956985cccda1 (#73721) but keeps its test. There have been many changes to lib/MC and AsmBackend.cpp files, so this is not a pure revert. #73721, a workaround to generate necessary relocations in mixed non-relax/relax code, is no longer necessary after #140692 fixed the root issue (whether two locations are separated by a fragment with indeterminate size due to linker relaxation).
2025-04-18MCFixup: Make FixupKindInfo smaller and change getFixupKindInfo to return valueFangrui Song
We will increase the use of raw relocation types and eliminate fixup kinds that correspond to relocation types. The getFixupKindInfo functions will return an rvalue instead. Let's update the return type from a const reference to a value type.
2025-04-18MCFixup: Add isRelocation/isRelocRelocation helpersFangrui Song
Add two helper functions to simplify checks for relocation types, replacing direct comparisons with FirstRelocationKind and FirstLiteralRelocationKind. Note: Some targets haven't utilized isRelocation yet. Also, update RelaxFixupKind to use 0 as the sentinel value.
2025-04-14[MC] Remove unused `MCAsmBackend::isMicroMips()` method (NFC) (#135581)Sergei Barannikov
The only use was removed by 4c892770.
2025-03-16[MC] Remove unneeded getNumFixupKindsFangrui Song
2025-03-16[MC] Rework AVR #121498 to not add extra argument to shouldForceRelocationFangrui Song
This removes the extra argument from commit 814b34f31e163e76b816194004689985f5b9fd7b. Also remove unneeded `>= FirstLiteralRelocationKind`.
2025-03-16[MC] .reloc: move FirstLiteralRelocationKind check to evaluateFixupFangrui Song
Target shouldForceRelocation checks `FirstLiteralRelocationKind` to determine whether a relocation is forced due to the .reloc directive. We should move the code to evaluateFixup so that many targets don't need to override shouldForceRelocation.
2025-03-02[MC] Move MIPS-specific gprel/tprel/dtprel from MCStreamer to MipsTargetStreamerFangrui Song
https://reviews.llvm.org/D23669 inappropriately added MIPS-specific dtprel/tprel directives to MCStreamer. In addition, llvm-mc -filetype=null parsing these directives will crash. This patch moves these functions to MipsTargetStreamer and fixes -filetype=null. gprel32 and gprel64, called by AsmPrinter, are moved to MCTargetStreamer.
2025-03-01[Mips] Allow expressions in some immediate operandsFangrui Song
e.g. `addiu $t2, $t3, .Lend-.Lstart-4` used by libdragon/boot/boot_trampoline.S To make this work, update a few places: * AsmParser: When matching a isSImm/isUImm, consider an expression that does not evaluate to an assemble-time constant an immediate. * MCCodeEmitter: If this is an I-type instruction and the expression does not evaluate to an assemble-time constant, append a `fixup_Mips_AnyImm16`. TODO: in MipsInstrInfo.td, more `Operand` should switch from the default `getMachineOpValue` to `getImmOpValue` like RISCV. * AsmBackend: If the expression does not evaluate to a constant with assembler layout information, report "unknown relocation type" like X86. If the result is not within [-32768,65535] (the bound gas uses when parsing a constant integer for ADDIU) Fix #126531 Pull Request: https://github.com/llvm/llvm-project/pull/127581
2025-03-01[Mips] Format some MCTargetDesc files. NFCFangrui Song
In preparation for #127581
2025-01-20[AVR] Force relocations for non-encodable jumps (#121498)Patryk Wychowaniec
This commit changes the branch emission logic so that instead of throwing the "branch target out of range" error, we emit a relocation instead.
2024-12-20[MC][Mips] Add MipsWinCOFFObjectWriter/MipsWinCOFFStreamer (#114611)Hervé Poussineau
llc is now able to create MIPS COFF files for simple cases.
2024-11-16[Mips] Remove unused includes (NFC) (#116499)Kazu Hirata
Identified with misc-include-cleaner.
2024-07-21*AsmBackend.cpp: Include StringSwitch.hFangrui Song
They currently get the header from MCLinkerOptimizationHint.h, which will be removed from MCAssembler.h.
2023-12-07[RISCV][MC] Pass MCSubtargetInfo down to shouldForceRelocation and ↵Craig Topper
evaluateTargetFixup. (#73721) Instead of using the STI stored in RISCVAsmBackend, try to get it from the MCFragment. This addresses the issue raised here https://discourse.llvm.org/t/possible-problem-related-to-subtarget-usage/75283
2023-10-12Use llvm::endianness::{big,little,native} (NFC)Kazu Hirata
Note that llvm::support::endianness has been renamed to llvm::endianness while becoming an enum class as opposed to an enum. This patch replaces support::{big,little,native} with llvm::endianness::{big,little,native}.
2022-12-04[MC] llvm::Optional => std::optionalFangrui Song
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-09-08[llvm] Use std::size instead of llvm::array_lengthofJoe Loser
LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Differential Revision: https://reviews.llvm.org/D133429
2022-06-30[MC][Mips] Support .reloc *, BFD_RELOC_{NONE,16,32,64}, *Fangrui Song
... to match most other common architectures which already support BFD_RELOC_*. BFD_RELOC_NONE provides a generic way indicating a dependency between two sections and is useful for some instrumentations which encode symbol index information (e.g. `.cg_profile`).
2022-01-26Revert "Rename llvm::array_lengthof into llvm::size to match std::size from ↵Benjamin Kramer
C++17" This reverts commit ef8206320769ad31422a803a0d6de6077fd231d2. - It conflicts with the existing llvm::size in STLExtras, which will now never be called. - Calling it without llvm:: breaks C++17 compat
2022-01-26Rename llvm::array_lengthof into llvm::size to match std::size from C++17serge-sans-paille
As a conquence move llvm::array_lengthof from STLExtras.h to STLForwardCompat.h (which is included by STLExtras.h so no build breakage expected).
2022-01-15[MC][ARC][Mips] Replace MCContext::reportFatalError calls with reportErrorFangrui Song
2021-09-07[MC] Use local MCSubtargetInfo in writeNopsPeter Smith
On some architectures such as Arm and X86 the encoding for a nop may change depending on the subtarget in operation at the time of encoding. This change replaces the per module MCSubtargetInfo retained by the targets AsmBackend in favour of passing through the local MCSubtargetInfo in operation at the time. On Arm using the architectural NOP instruction can have a performance benefit on some implementations. For Arm I've deleted the copy of the AsmBackend's MCSubtargetInfo to limit the chances of this causing problems in the future. I've not done this for other targets such as X86 as there is more frequent use of the MCSubtargetInfo and it looks to be for stable properties that we would not expect to vary per function. This change required threading STI through MCNopsFragment and MCBoundaryAlignFragment. I've attempted to take into account the in tree experimental backends. Differential Revision: https://reviews.llvm.org/D45962
2019-11-03[mips] Split long lines in the code. NFCSimon Atanasyan
2019-08-21[mips] Remove duplicated case from the `StringSwitch`. NFCSimon Atanasyan
llvm-svn: 369562
2019-05-17[ARM] Support .reloc *, R_ARM_NONE, *Fangrui Song
R_ARM_NONE can be used to create references among sections. When --gc-sections is used, the referenced section will be retained if the origin section is retained. Add a generic MCFixupKind FK_NONE as this kind of no-op relocation is ubiquitous on ELF and COFF, and probably available on many other binary formats. See D62014. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D61992 llvm-svn: 360980
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-11-21[mips][mc] Add basic support for R_MIPS_JALR/R_MICROMIPS_JALRVladimir Stefanovic
R_MIPS_JALR/R_MICROMIPS_JALR can now be parsed in .s files and emitted to .o. They are still not generated with JALR. Differential revision: https://reviews.llvm.org/D54721 llvm-svn: 347398
2018-10-16[mips][micromips] Fix how values in .gcc_except_table are calculatedAleksandar Beserminji
When a landing pad is calculated in a program that is compiled for micromips, it will point to an even address. Such an error will cause a segmentation fault, as the instructions in micromips are aligned on odd addresses. This patch sets the last bit of the offset where a landing pad is, to 1, which will effectively be an odd address and point to the instruction exactly. Differential Revision: https://reviews.llvm.org/D52985 llvm-svn: 344591
2018-09-17[mips] Fix MIPS N32 ABI triples supportSimon Atanasyan
Add support mips64(el)-linux-gnuabin32 triples, and set them to N32. Debian architecture name mipsn32/mipsn32el are also added. Set UseIntegratedAssembler for N32 if we can detect it. Patch by YunQiang Su. Differential revision: https://reviews.llvm.org/D51408 llvm-svn: 342416
2018-06-06[MC] Pass MCSubtargetInfo to fixupNeedsRelaxation and applyFixupPeter Smith
On targets like Arm some relaxations may only be performed when certain architectural features are available. As functions can be compiled with differing levels of architectural support we must make a judgement on whether we can relax based on the MCSubtargetInfo for the function. This change passes through the MCSubtargetInfo for the function to fixupNeedsRelaxation so that the decision on whether to relax can be made per function. In this patch, only the ARM backend makes use of this information. We must also pass the MCSubtargetInfo to applyFixup because some fixups skip error checking on the assumption that relaxation has occurred, to prevent code-generation errors applyFixup must see the same MCSubtargetInfo as fixupNeedsRelaxation. Differential Revision: https://reviews.llvm.org/D44928 llvm-svn: 334078
2018-06-01[mips] Extend list of relocations supported by the `.reloc` directiveSimon Atanasyan
Supporting GOT and TLS related relocations by the `.reloc` directive is useful for purpose of testing various tools like a linker, for example. llvm-svn: 333773
2018-05-29[mips] Emit R_MICROMIPS_GPREL16/R_MICROMIPS_SUB/R_MICROMIPS_LO16 / HI16 ↵Simon Atanasyan
relocations Emit R_MICROMIPS_GPREL16/R_MICROMIPS_SUB/R_MICROMIPS_LO16 and R_MICROMIPS_GPREL16/R_MICROMIPS_SUB/R_MICROMIPS_HI16 chains of relocations for %lo(%neg(%gp_rel())) and %hi(%neg(%gp_rel())) expressions in case of microMIPS. Differential Revision: http://reviews.llvm.org/D47220 llvm-svn: 333409
2018-05-29[mips] Emit R_MICROMIPS_HIGHER / R_MICROMIPS_HIGHEST relocationsSimon Atanasyan
Emit R_MICROMIPS_HIGHER / R_MICROMIPS_HIGHEST relocations for %higher() and %highest() expressions in case of microMIPS. These relocations do exactly the same things as R_MIPS_HIGHER / R_MIPS_HIGHEST, but for consistency it's better to write microMIPS variants. Differential Revision: http://reviews.llvm.org/D47219 llvm-svn: 333407
2018-05-21MC: Separate creating a generic object writer from creating a target object ↵Peter Collingbourne
writer. NFCI. With this we gain a little flexibility in how the generic object writer is created. Part of PR37466. Differential Revision: https://reviews.llvm.org/D47045 llvm-svn: 332868
2018-05-21MC: Change MCAsmBackend::writeNopData() to take a raw_ostream instead of an ↵Peter Collingbourne
MCObjectWriter. NFCI. To make this work I needed to add an endianness field to MCAsmBackend so that writeNopData() implementations know which endianness to use. Part of PR37466. Differential Revision: https://reviews.llvm.org/D47035 llvm-svn: 332857
2018-03-27[MIPS] Add static_assert that all Fixups are handled in getFixupKindAlexander Richardson
Summary: I recently added a new Fixup kind to our fork of LLVM but forgot to add it to the table in MipsAsmBackend.cpp. With this static_assert the error would have been caught instead of zero-initializing the array entries for the new fixups. Reviewers: sdardis, atanasyan Reviewed By: atanasyan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D44895 llvm-svn: 328616
2018-01-03Thread MCSubtargetInfo through Target::createMCAsmBackendAlex Bradbury
Currently it's not possible to access MCSubtargetInfo from a TgtMCAsmBackend. D20830 threaded an MCSubtargetInfo reference through MCAsmBackend::relaxInstruction, but this isn't the only function that would benefit from access. This patch removes the Triple and CPUString arguments from createMCAsmBackend and replaces them with MCSubtargetInfo. This patch just changes the interface without making any intentional functional changes. Once in, several cleanups are possible: * Get rid of the awkward MCSubtargetInfo handling in ARMAsmBackend * Support 16-bit instructions when valid in MipsAsmBackend::writeNopData * Get rid of the CPU string parsing in X86AsmBackend and just use a SubtargetFeature for HasNopl * Emit 16-bit nops in RISCVAsmBackend::writeNopData if the compressed instruction set extension is enabled (see D41221) This change initially exposed PR35686, which has since been resolved in r321026. Differential Revision: https://reviews.llvm.org/D41349 llvm-svn: 321692
2017-10-10[MC] Thread unique_ptr<MCObjectWriter> through the create.*ObjectWriterLang Hames
functions. This makes the ownership of the resulting MCObjectWriter clear, and allows us to remove one instance of MCObjectStreamer's bizarre "holding ownership via someone else's reference" trick. llvm-svn: 315327
2017-09-21[mips] Fix relocation record format and ELF header for N32 ABISimon Atanasyan
The N32 ABI uses RELA relocation format, do not use 3-in-1 relocation's encoding, and uses ELFCLASS32. This change passes the `IsN32` flag to the `MCAsmBackend` to distinguish usage of N32 ABI. We still do not handle some cases like providing the `-target-abi=o32` command line option with the `mips64` target triple. That's why elf_header.s contains some "FIXME" strings. This case will be fixed in a separate patch. Differential revision: https://reviews.llvm.org/D37960 llvm-svn: 313873
2017-09-07[mips] Use RegisterMCAsmBackend to register all MIPS asm backends. NFCSimon Atanasyan
This change converts the `MipsAsmBackend` constructor to the "standard" form. It makes possible to use `RegisterMCAsmBackend` for the backends registrations. Now we pass `Triple` instance to the `MipsAsmBackend` ctor and deduce all required options like endianness and bitness from the triple. We still need to implement explicit ABI checking for providing correct options to backends. Differential revision: https://reviews.llvm.org/D37519 llvm-svn: 312720
2017-07-11Fully fix the movw/movt addend.Rafael Espindola
The issue is not if the value is pcrel. It is whether we have a relocation or not. If we have a relocation, the static linker will select the upper bits. If we don't have a relocation, we have to do it. llvm-svn: 307730
2017-06-24Remove redundant argument.Rafael Espindola
llvm-svn: 306189
2017-06-23ARM: move some logic from processFixupValue to applyFixup.Rafael Espindola
processFixupValue is called on every relaxation iteration. applyFixup is only called once at the very end. applyFixup is then the correct place to do last minute changes and value checks. While here, do proper range checks again for fixup_arm_thumb_bl. We used to do it, but dropped because of thumb2. We now do it again, but use the thumb2 range. llvm-svn: 306177
2017-06-21Use a MutableArrayRef. NFC.Rafael Espindola
llvm-svn: 305968