summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.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-05-22[MC] Restore MCAsmBackend::shouldForceRelocation to falseFangrui Song
For IsPCRel fixups, we had the `A->getKind() != MCSymbolRefExpr::VK_None` condition to force relocations. The condition has then been changed to `Target.getSpecifier()` (086af836889436baffc71c743c7c8259bad8ed60). 38c3ad36be1facbe6db2dede7e93c0f12fb4e1dc updated shouldForceRelocation to test `Target.getSpecifier`. It is not a good fit as many targets with %lo/%hi style specifiers (SPARC, MIPS, PowerPC, RISC-V) do not force relocations for these specifiers. Revert the Target.getSpecifier implementation (38c3ad36be1facbe6db2dede7e93c0f12fb4e1dc) and update targets that need it (SystemZAsmBackend/X86AsmBackend) instead. Targets need customization might define addReloc instead. Note: The X86AsmBackend implementation is too conservative. GNU Assembler doesn't emit a relocation for `call local@plt; local` a3d39316764726ed9fd939550c7781199b1eb77e added missing coverage for GOT/PLT related relocations.
2025-05-22Revert "[MC] Restore MCAsmBackend::shouldForceRelocation to false"JP Lehr
This reverts commit 6f6dc1f239433393c0b09430193beb85d03464c8. Resulted in several bot failures.
2025-05-21[MC] Restore MCAsmBackend::shouldForceRelocation to falseFangrui Song
Revert the Target.getSpecifier implementation (38c3ad36be1facbe6db2dede7e93c0f12fb4e1dc) and update SystemZAsmBackend instead. Many targets with %lo/%hi style specifiers (SPARC, MIPS, PowerPC, RISC-V) do not force relocations for these specifiers. Additionally, with the introduction of the addReloc hook, shouldForceRelocation is not that necessary and should probably be phased out.
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-03-16[MC] Remove unneeded getNumFixupKindsFangrui Song
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-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-07-01[MC] Make MCAsmBackend::fixupNeedsRelaxation not pure virtualFangrui Song
This hook only needs to be implemented if mayNeedRelaxation may return true.
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}.
2023-09-29[SystemZ/zOS/GOFF] Implement GOFF writer for empty files.Kai Nacke
Set ups the infrastructure to create an empty GOFF file. Also adds a GOFF writer which writes only HDR/END records. Reviewed By: jhenderson, kpn Differential Revision: https://reviews.llvm.org/D111437
2023-07-21[SystemZ] Allow symbols in immediate asm operandsIlya Leoshkevich
Currently mentioning any symbols in immediate asm operands is not supported, for example: error: invalid operand for instruction lghi %r4,foo_end-foo The immediate problem is that is*Imm() and print*Operand() functions do not accept MCExprs, but simply relaxing these checks is not enough: after symbol addresses are computed, range checks need to run against resolved values. Add a number of SystemZ::FixupKind members for each kind of immediate value and process them in SystemZMCAsmBackend::applyFixup(). Only perform the range checks, do not change anything. Adjust the tests: move previously failing cases like the one shown above out of insn-bad.s. Reviewed By: uweigand Differential Revision: https://reviews.llvm.org/D154899
2022-12-04[MC] llvm::Optional => std::optionalFangrui Song
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02[Target] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2021-12-07[SystemZ] Add range checks for PC-relative fixups.Jonas Paulsson
The AsmParser checks the range of a PC-relative operand, but only if it is immediate. This patch adds range checks for operands in applyFixup(), at which point the offset to a label is known. The diagnostic message for an operand that is out of range is explicit (with given value and min/max limits). This is now also done for displacement fixups. Review: Ulrich Weigand Differential Revision: https://reviews.llvm.org/D114194
2021-11-15[SystemZ] Support symbolic displacements.Jonas Paulsson
This patch adds support for symbolic displacements, e.g. like 'lg %r0, sym(%r1)', which is done using relocations. This is needed to compile the kernel without disabling the integrated assembler. Review: Ulrich Weigand Differential Revision: https://reviews.llvm.org/D113341
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
2021-06-25[SystemZ] Add support for .reloc assembler directiveUlrich Weigand
Add support for the .reloc directive along the lines of other back-ends. This fixes a regression after https://reviews.llvm.org/D104080 was merged, since that patch presupposed support for .reloc.
2020-08-02[MC] Default MCAsmBackend::mayNeedRelaxation() to falseFangrui Song
2020-04-21[MC][Bugfix] Remove redundant parameter for relaxInstructionShengchen Kan
Summary: Before this patch, `relaxInstruction` takes three arguments, the first argument refers to the instruction before relaxation and the third argument is the output instruction after relaxation. There are two quite strange things: 1) The first argument's type is `const MCInst &`, the third argument's type is `MCInst &`, but they may be aliased to the same variable 2) The backends of ARM, AMDGPU, RISC-V, Hexagon assume that the third argument is a fresh uninitialized `MCInst` even if `relaxInstruction` may be called like `relaxInstruction(Relaxed, STI, Relaxed)` in a loop. In this patch, we drop the thrid argument, and let `relaxInstruction` directly modify the given instruction. Also, this patch fixes the bug https://bugs.llvm.org/show_bug.cgi?id=45580, which is introduced by D77851, and breaks the assumption of ARM, AMDGPU, RISC-V, Hexagon. Reviewers: Razer6, MaskRay, jyknight, asb, luismarques, enderby, rtaylor, colinl, bcain Reviewed By: Razer6, MaskRay, bcain Subscribers: bcain, nickdesaulniers, nathanchance, wuzish, annita.zhang, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, tpr, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, Jim, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, kerbowa, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78364
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-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-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-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-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
2017-06-06Sort the remaining #include lines in include/... and lib/....Chandler Carruth
I did this a long time ago with a janky python script, but now clang-format has built-in support for this. I fed clang-format every line with a #include and let it re-sort things according to the precise LLVM rules for include ordering baked into clang-format these days. I've reverted a number of files where the results of sorting includes isn't healthy. Either places where we have legacy code relying on particular include ordering (where possible, I'll fix these separately) or where we have particular formatting around #include lines that I didn't want to disturb in this patch. This patch is *entirely* mechanical. If you get merge conflicts or anything, just ignore the changes in this patch and run clang-format over your #include lines in the files. Sorry for any noise here, but it is important to keep these things stable. I was seeing an increasing number of patches with irrelevant re-ordering of #include lines because clang-format was used. This patch at least isolates that churn, makes it easy to skip when resolving conflicts, and gets us to a clean baseline (again). llvm-svn: 304787
2017-04-05Add MCContext argument to MCAsmBackend::applyFixup for error reportingAlex Bradbury
A number of backends (AArch64, MIPS, ARM) have been using MCContext::reportError to report issues such as out-of-range fixup values in their TgtAsmBackend. This is great, but because MCContext couldn't easily be threaded through to the adjustFixupValue helper function from its usual callsite (applyFixup), these backends ended up adding an MCContext* argument and adding another call to applyFixup to processFixupValue. Adding an MCContext parameter to applyFixup makes this unnecessary, and even better - applyFixup can take a reference to MCContext rather than a potentially null pointer. Differential Revision: https://reviews.llvm.org/D30264 llvm-svn: 299529
2016-12-01[SystemZ] Fix fallout from r288374Ulrich Weigand
Avoid undefined behavior due to too-large shift count. llvm-svn: 288391
2016-12-01[SystemZ] Fix applyFixup for 12-bit fixupsUlrich Weigand
Now that we have fixups that only fill parts of a byte, it turns out we have to mask off the bits outside the fixup area when applying them. Failing to do so caused invalid object code to be emitted for bprp with a negative 12-bit displacement. llvm-svn: 288374
2016-11-28[SystemZ] Support execution hint instructionsUlrich Weigand
This adds assembler support for the instructions provided by the execution-hint facility (NIAI and BP(R)P). This required adding support for the new relocation types for 12-bit and 24-bit PC- relative offsets used by the BP(R)P instructions. llvm-svn: 288031
2016-07-25MC] Provide an MCTargetOptions to implementors of MCAsmBackendCtorTy, NFCJoel Jones
Some targets, notably AArch64 for ILP32, have different relocation encodings based upon the ABI. This is an enabling change, so a future patch can use the ABIName from MCTargetOptions to chose which relocations to use. Tested using check-llvm. The corresponding change to clang is in: http://reviews.llvm.org/D16538 Patch by: Joel Jones Differential Revision: https://reviews.llvm.org/D16213 llvm-svn: 276654
2016-07-11Fix branch relaxation in 16-bit mode.Nirav Dave
Thread through MCSubtargetInfo to relaxInstruction function allowing relaxation to generate jumps with 16-bit sized immediates in 16-bit mode. This fixes PR22097. Reviewers: dwmw2, tstellarAMD, craig.topper, jyknight Subscribers: jfb, arsenm, jyknight, llvm-commits, dsanders Differential Revision: http://reviews.llvm.org/D20830 llvm-svn: 275068
2015-09-15Revert r247692: Replace Triple with a new TargetTuple in MCTargetDesc/* and ↵Daniel Sanders
related. NFC. Eric has replied and has demanded the patch be reverted. llvm-svn: 247702
2015-09-15Re-commit r247683: Replace Triple with a new TargetTuple in MCTargetDesc/* ↵Daniel Sanders
and related. NFC. Summary: This is the first patch in the series to migrate Triple's (which are ambiguous) to TargetTuple's (which aren't). For the moment, TargetTuple simply passes all requests to the Triple object it holds. Once it has replaced Triple, it will start to implement the interface in a more suitable way. This change makes some changes to the public C++ API. In particular, InitMCSubtargetInfo(), createMCRelocationInfo(), and createMCSymbolizer() now take TargetTuples instead of Triples. The other public C++ API's have been left as-is for the moment to reduce patch size. This commit also contains a trivial patch to clang to account for the C++ API change. Thanks go to Pavel Labath for fixing LLDB for me. Reviewers: rengolin Subscribers: jyknight, dschuff, arsenm, rampitec, danalbert, srhines, javed.absar, dsanders, echristo, emaste, jholewinski, tberghammer, ted, jfb, llvm-commits, rengolin Differential Revision: http://reviews.llvm.org/D10969 llvm-svn: 247692
2015-09-15Revert r247684 - Replace Triple with a new TargetTuple ...Daniel Sanders
LLDB needs to be updated in the same commit. llvm-svn: 247686
2015-09-15Replace Triple with a new TargetTuple in MCTargetDesc/* and related. NFC.Daniel Sanders
Summary: This is the first patch in the series to migrate Triple's (which are ambiguous) to TargetTuple's (which aren't). For the moment, TargetTuple simply passes all requests to the Triple object it holds. Once it has replaced Triple, it will start to implement the interface in a more suitable way. This change makes some changes to the public C++ API. In particular, InitMCSubtargetInfo(), createMCRelocationInfo(), and createMCSymbolizer() now take TargetTuples instead of Triples. The other public C++ API's have been left as-is for the moment to reduce patch size. This commit also contains a trivial patch to clang to account for the C++ API change. Reviewers: rengolin Subscribers: jyknight, dschuff, arsenm, rampitec, danalbert, srhines, javed.absar, dsanders, echristo, emaste, jholewinski, tberghammer, ted, jfb, llvm-commits, rengolin Differential Revision: http://reviews.llvm.org/D10969 llvm-svn: 247683
2015-06-10Replace string GNU Triples with llvm::Triple in MCAsmBackend subclasses and ↵Daniel Sanders
create*AsmBackend(). NFC. Summary: This continues the patch series to eliminate StringRef forms of GNU triples from the internals of LLVM that began in r239036. Reviewers: echristo, rafael Reviewed By: rafael Subscribers: rafael, llvm-commits, rengolin Differential Revision: http://reviews.llvm.org/D10243 llvm-svn: 239464
2015-06-04MC: Clean up naming in MCObjectWriter. NFC.Jim Grosbach
s/WriteObject/writeObject/ s/RecordRelocation/recordRelocation/ s/IsSymbolRefDifferenceFullyResolved/isSymbolRefDifferenceFullyResolved/ s/Write8/write8/ s/WriteLE16/writeLE16/ s/WriteLE32/writeLE32/ s/WriteLE64/writeLE64/ s/WriteBE16/writeBE16/ s/WriteBE32/writeBE32/ s/WriteBE64/writeBE64/ s/Write16/write16/ s/Write32/write32/ s/Write64/write64/ s/WriteZeroes/writeZeroes/ s/WriteBytes/writeBytes/ llvm-svn: 239108