summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
AgeCommit message (Collapse)Author
2025-11-12[Mips] Remove implicit conversions of MCRegister to unsigned. NFC (#167645)Craig Topper
2025-08-17[llvm] Remove unused includes (NFC) (#154051)Kazu Hirata
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-04Reapply "MCFragment: Use trailing data for fixed-size part" (#150846)Fangrui Song
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-03Revert "MCFragment: Use trailing data for fixed-size part"Fangrui Song
This reverts commit f1aa6050bd90f8ec4273da55d362e23905ad3a81 (reland of #150846), fixing conflicts. It caused https://github.com/ClangBuiltLinux/linux/issues/2116 , which surfaced after a subsequent commit faa931b717c02d57f0814caa9133219040e6a85b decreased sizeof(MCFragment). ``` % /tmp/Debug/bin/clang "-cc1as" "-triple" "aarch64" "-filetype" "obj" "-main-file-name" "a.s" "-o" "a.o" "a.s" clang: /home/ray/llvm/llvm/lib/MC/MCAssembler.cpp:615: void llvm::MCAssembler::writeSectionData(raw_ostream &, const MCSection *) const: Assertion `getContext().hadError() || OS.tell() - Start == getSectionAddressSize(*Sec)' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: /tmp/Debug/bin/clang -cc1as -triple aarch64 -filetype obj -main-file-name a.s -o a.o a.s Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it): 0 libLLVMSupport.so.22.0git 0x00007cf91eb753cd llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 61 fish: Job 1, '/tmp/Debug/bin/clang "-cc1as" "…' terminated by signal SIGABRT (Abort) ``` The test is sensitive to precise fragment offsets. Using llvm-mc -filetype=obj -triple=aarch64 a.s does not replicate the issue. However, clang -cc1as includes an unnecessary `initSection` (adding an extra FT_Align), which causes the problem.
2025-08-03MCSymbolELF: Migrate away from classofFangrui Song
The object file format specific derived classes are used in context where the type is statically known. We don't use isa/dyn_cast and we want to eliminate MCSymbol::Kind in the base class.
2025-08-02MCFragment: Use trailing data for fixed-size partFangrui Song
Reapply after #151724 switched to `char *Data`, fixing a -fsanitize=pointer-overflow issue in MCAssembler::layout. --- 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. Pull Request: https://github.com/llvm/llvm-project/pull/150846
2025-07-30Revert "MCFragment: Use trailing data for fixed-size part" (#151383)Nikolay Panchenko
Reverts llvm/llvm-project#150846 due to unsigned underflow identifier by UBSan in several tests
2025-07-28MCFragment: Use trailing data for fixed-size partFangrui Song
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. Pull Request: https://github.com/llvm/llvm-project/pull/150846
2025-07-26MC: Move useCodeAlign from MCSection to MCAsmInfoFangrui Song
To centralize assembly-related virtual functions to MCAsmInfo and move toward making MCSection non-virtual.
2025-07-20MCStreamer: Add helpers and eliminate direct MCFragment operationsFangrui Song
To facilitate optimizing the MCFragment internals, we don't want users to access MCFragment directly.
2025-07-20MC: Replace getOrCreateDataFragment with getCurrentFragmentFangrui Song
Add an assert to ensure `CurFrag` is either null or an `FT_Data` fragment. Follow-up to 39c8cfb70d203439e3296dfdfe3d41f1cb2ec551. Extracted from #149721
2025-07-15MCFragment: Remove MCDataFragment/MCRelaxableFragment type aliasesFangrui Song
Follow-up to #148544
2025-07-05MC: Remove unneeded MCFixupKind castsFangrui Song
2025-06-29MCFragment: Add addFixup to replace getFixups().push_back()Fangrui Song
to not expose SmallVector to the callers. We will make fixup storage out of line.
2025-06-17MIPS: Replace MipsMCExpr with MCSpecifierExprFangrui Song
2025-06-15MIPS: Rename MipsMCExpr::MEK_ to Mips::S_Fangrui Song
Prepare for removing MipsMCExpr. Adopt the newer naming convention (S_) used by AMDGPU/WebAssembly/VE/M68k/PowerPC/LoongArch/RISCV.
2025-06-15MIPS: Replace MCExpr::print with MCAsmInfo::printExprFangrui Song
2025-03-05[MC] Remove unneeded VK_None argument from MCSymbolRefExpr::create. NFCFangrui Song
2025-03-05[MC] Remove unneeded MCSymbolRefExpr::create overload and add commentsFangrui Song
The StringRef overload is often error-prone as users might forget to register the MCSymbol. Add comments to MCTargetExpr and MCSymbolRefExpr::VariantKind. In the distant future the VariantKind parameter might be removed.
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-02-16[Mips] Use MCRegister. NFCCraig Topper
Use id() to get rid of some implicit conversions.
2024-11-14Fixed un-renamed CodeGenTargetMachineImpl Intheritances in Experimental ↵Matin Raayai
Targets (#116290) This PR fixes a set of build issues with experimental targets happened in result of merging #111234 to master.
2024-11-14Overhaul the TargetMachine and LLVMTargetMachine Classes (#111234)Matin Raayai
Following discussions in #110443, and the following earlier discussions in https://lists.llvm.org/pipermail/llvm-dev/2017-October/117907.html, https://reviews.llvm.org/D38482, https://reviews.llvm.org/D38489, this PR attempts to overhaul the `TargetMachine` and `LLVMTargetMachine` interface classes. More specifically: 1. Makes `TargetMachine` the only class implemented under `TargetMachine.h` in the `Target` library. 2. `TargetMachine` contains target-specific interface functions that relate to IR/CodeGen/MC constructs, whereas before (at least on paper) it was supposed to have only IR/MC constructs. Any Target that doesn't want to use the independent code generator simply does not implement them, and returns either `false` or `nullptr`. 3. Renames `LLVMTargetMachine` to `CodeGenCommonTMImpl`. This renaming aims to make the purpose of `LLVMTargetMachine` clearer. Its interface was moved under the CodeGen library, to further emphasis its usage in Targets that use CodeGen directly. 4. Makes `TargetMachine` the only interface used across LLVM and its projects. With these changes, `CodeGenCommonTMImpl` is simply a set of shared function implementations of `TargetMachine`, and CodeGen users don't need to static cast to `LLVMTargetMachine` every time they need a CodeGen-specific feature of the `TargetMachine`. 5. More importantly, does not change any requirements regarding library linking. cc @arsenm @aeubanks
2024-07-30[MC] Forward declare ELFObjectWriter (#100989)Sergei Barannikov
2024-07-22MCAssmembler: Move ELFHeaderEFlags to ELFObjectWriterFangrui Song
Now that MCELFStreamer can access ELFObjectWriter (commit 70c52b62c5669993e341664a63bfbe5245e32884), we can move ELFHeaderEFlags there.
2024-06-27[MC] Make changeSection privateFangrui Song
Using changeSection externally would cause `CurFrag` to be out of sync of `SectionStack`. Remove some uses from MipsTargetStreamer.cpp.
2024-06-23[NC,MIPS] Avoid some registerSection callsFangrui Song
Similar to abbf3bce94e0848f746e39186d36ebb938c1c5de. switchSection calls registerSection internally.
2024-03-16[Mips][NFC] Garbage collect unused code (#85499)Brad Smith
2024-02-26MIPS: fix emitDirectiveCpsetup on N32 (#80534)YunQiang Su
In gas, .cpsetup may expand to one of two code sequences (one is related to `__gnu_local_gp`), depending on -mno-shared and -msym32. Since Clang doesn't support -mno-shared or -msym32, .cpsetup expands to one code sequence. The N32 condition incorrectly leads to the incorrect `__gnu_local_gp` code sequence. ``` 00000000 <t1>: 0: ffbc0008 sd gp,8(sp) 4: 3c1c0000 lui gp,0x0 4: R_MIPS_HI16 __gnu_local_gp 8: 279c0000 addiu gp,gp,0 8: R_MIPS_LO16 __gnu_local_gp ``` Fixes: #52785
2023-07-27Adjust includes in MCTargetDesc to avoid unnecessary CodeGen deps, NFCReid Kleckner
These are small include-only changes in the X86, Mips, and SystemZ backend that seem sufficiently small to commit separately without review. See issue #64166 for more information about layering.
2023-02-17Simplify with hasFeature. NFCFangrui Song
2022-11-28[NFC] Add helper method to ensure min alignment on MCSectionGuillaume Chatelet
Follow up on D138653. Differential Revision: https://reviews.llvm.org/D138686
2022-11-24[Alignment][NFC] Use Align in MCStreamer::emitValueToAlignmentGuillaume Chatelet
Differential Revision: https://reviews.llvm.org/D138674
2022-11-24[Alignment][NFC] Use Align in MCStreamer::emitCodeAlignmentGuillaume Chatelet
This patch makes code less readable but it will clean itself after all functions are converted. Differential Revision: https://reviews.llvm.org/D138665
2022-11-24[reland][Alignment][NFC] Use the Align type in MCSectionGuillaume Chatelet
Differential Revision: https://reviews.llvm.org/D138653
2022-11-24Revert D138653 [Alignment][NFC] Use the Align type in MCSection"Guillaume Chatelet
This breaks the bolt project. This reverts commit 409f0dc4a420db1c6b259d5ae965a070c169d930.
2022-11-24[Alignment][NFC] Use the Align type in MCSectionGuillaume Chatelet
Differential Revision: https://reviews.llvm.org/D138653
2022-06-10[MC] De-capitalize SwitchSection. NFCFangrui Song
Add SwitchSection to return switchSection. The API will be removed soon.
2022-06-07[MC] De-capitalize MCStreamer functionsFangrui Song
Follow-up to c031378ce01b8485ba0ef486654bc9393c4ac024 . The class is mostly consistent now.
2022-05-11[MIPS] Remove an incorrect microMIPS instruction aliasSimon Dardis
The microMIPS instruction set is compatible with the MIPS instruction set at the assembly level but not in terms of encodings. `nop` in microMIPS is a special case as it has the same encoding as `nop` for MIPS. Fix this error by reducing the usage of NOP in the MIPS backend such that only that ISA correct variants are produced. Differential Revision: https://reviews.llvm.org/D124716
2022-03-11[MC] Fix letter case of some MCSection member functionsFangrui Song
2022-02-09Cleanup LLVMMC headersserge-sans-paille
There's a few relevant forward declarations in there that may require downstream adding explicit includes: llvm/MC/MCContext.h no longer includes llvm/BinaryFormat/ELF.h, llvm/MC/MCSubtargetInfo.h, llvm/MC/MCTargetOptions.h llvm/MC/MCObjectStreamer.h no longer include llvm/MC/MCAssembler.h llvm/MC/MCAssembler.h no longer includes llvm/MC/MCFixup.h, llvm/MC/MCFragment.h Counting preprocessed lines required to rebuild llvm-project on my setup: before: 1052436830 after: 1049293745 Which is significant and backs up the change in addition to the usual benefits of decreasing coupling between headers and compilation units. Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D119244
2021-09-07[MC] Add MCSubtargetInfo to MCAlignFragmentPeter Smith
In preparation for passing the MCSubtargetInfo (STI) through to writeNops so that it can use the STI in operation at the time, we need to record the STI in operation when a MCAlignFragment may write nops as padding. The STI is currently unused, a further patch will pass it through to writeNops. There are many places that can create an MCAlignFragment, in most cases we can find out the STI in operation at the time. In a few places this isn't possible as we are in initialisation or finalisation, or are emitting constant pools. When possible I've tried to find the most appropriate existing fragment to obtain the STI from, when none is available use the per module STI. For constant pools we don't actually need to use EmitCodeAlign as the constant pools are data anyway so falling through into it via an executable NOP is no better than falling through into data padding. This is a prerequisite for D45962 which uses the STI to emit the appropriate NOP for the STI. Which can differ per fragment. Note that involves an interface change to InitSections. It is now called initSections and requires a SubtargetInfo as a parameter. Differential Revision: https://reviews.llvm.org/D45961
2021-02-16[MC][ELF] Support for zero flag section groupsPetr Hosek
This change introduces support for zero flag ELF section groups to LLVM. LLVM already supports COMDAT sections, which in ELF are a special type of ELF section groups. These are generally useful to enable linker GC where you want a group of sections to always travel together, that is to be either retained or discarded as a whole, but without the COMDAT semantics. Other ELF assemblers already support zero flag ELF section groups and this change helps us reach feature parity. Differential Revision: https://reviews.llvm.org/D95851
2020-03-22[mips] Implement .cpadd directiveSimon Atanasyan
This directive inserts code to add $gp to the argument's register when support for position independent code is enabled. For example, this code: .cpadd $4 expands to: addu $4, $4, $gp
2020-03-17[MIPS] Implement MIPS3D vector instructionsSimon Atanasyan
Patch by Michael Roe. Differential Revision: https://reviews.llvm.org/D76247
2020-02-14[MCStreamer] De-capitalize EmitValue EmitIntValue{,InHex}Fangrui Song
2020-02-14[MC] De-capitalize another set of MCStreamer::Emit* functionsFangrui Song
Emit{ValueTo,Code}Alignment Emit{DTP,TP,GP}* EmitSymbolValue etc
2020-02-13[AsmPrinter][MCStreamer] De-capitalize EmitInstruction and EmitCFI*Fangrui Song
2019-11-27[mips] Fix sc, scs, ll, lld instructions expandingSimon Atanasyan
There are a couple of bugs with the sc, scs, ll, lld instructions expanding: 1. On R6 these instruction pack immediate offset into a 9-bit field. Now if an immediate exceeds 9-bits assembler does not perform expansion and just rejects such instruction. 2. On 64-bit non-PIC code if an operand is a symbol assembler generates incorrect sequence of instructions. It uses R_MIPS_HI16 and R_MIPS_LO16 relocations and skips R_MIPS_HIGHEST and R_MIPS_HIGHER ones. To solve these problems this patch: - Introduces `mem_simm9_exp` to mark 9-bit memory immediate operands which require expansion. Probably later all `mem_simm9` operands will be able to migrate on `mem_simm9_exp` and we rename it to `mem_simm9`. - Adds new `OPERAND_MEM_SIMM9` operand type and assigns it to the `mem_simm9_exp`. That allows to know operand size in the `processInstruction` method and decide whether we need to expand instruction. - Adds `expandMem9Inst` method to expand instructions with 9-bit memory immediate operand. This method just load immediate into a "base" register used by origibal instruction: sc $2, 256($sp) => addiu $1, $sp, 256 sc $2, 0($1) - Fix `expandMem16Inst` to support a correct set of relocations for symbol loading in case of 64-bit non-PIC code. ll $12, symbol => lui $12, 0 R_MIPS_HIGHEST symbol daddiu $12, $12, 0 R_MIPS_HIGHER symbol dsll $12, $12, 16 daddiu $12, $12, 0 R_MIPS_HI16 symbol dsll $12, $12, 16 ll $12, 0($12) R_MIPS_LO16 symbol - Fix `expandMem16Inst` to unify handling of 3 and 4 operands instructions. - Delete unused now `MipsTargetStreamer::emitSCWithSymOffset` method. Task for next patches - implement expanding for other instructions use `mem_simm9` operand and other `mem_simm##` operands. Differential Revision: https://reviews.llvm.org/D70648