summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
AgeCommit message (Collapse)Author
2025-06-27PowerPC: Remove redundant MCSymbolRefExpr::VariantKind castsFangrui Song
2025-06-26PowerPC: Move PPCMCExpr into PPCMCAsmInfoFangrui Song
to align with targets that have made the transition.
2025-06-17[llvm] annotate interfaces in llvm/Target for DLL export (#143615)Andrew Rogers
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/Target` library. These annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). A sub-set of these changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. The bulk of this change is manual additions of `LLVM_ABI` to `LLVMInitializeX` functions defined in .cpp files under llvm/lib/Target. Adding `LLVM_ABI` to the function implementation is required here because they do not `#include "llvm/Support/TargetSelect.h"`, which contains the declarations for this functions and was already updated with `LLVM_ABI` in a previous patch. I considered patching these files with `#include "llvm/Support/TargetSelect.h"` instead, but since TargetSelect.h is a large file with a bunch of preprocessor x-macro stuff in it I was concerned it would unnecessarily impact compile times. In addition, a number of unit tests under llvm/unittests/Target required additional dependencies to make them build correctly against the LLVM DLL on Windows using MSVC. ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
2025-06-15PowerPC: Migrate to newer relocation specifier representationFangrui Song
* Use MCAsmInfo::printSpecifierExpr instead of MCExpr::print. * Replace PPCMCExpr with MCSpecifierExpr.
2025-06-15PowerPC: Rename PPCMCExpr::VK_ to PPC::S_Fangrui Song
Prepare for removing PPCMCExpr. Adopt the newer naming convention with AMDGPU/WebAssembly/VE/M68k.
2025-05-06Register assembly printer passes (#138348)Matthias Braun
Register assembly printer passes in the pass registry. This makes it possible to use `llc -start-before=<target>-asm-printer ...` in tests. Adds a `char &ID` parameter to the AssemblyPrinter constructor to allow targets to use the `INITIALIZE_PASS` macros and register the pass in the pass registry. This currently has a default parameter so it won't break any targets that have not been updated.
2025-04-28Clean up external users of GlobalValue::getGUID(StringRef) (#129644)Owen Rodley
See https://discourse.llvm.org/t/rfc-keep-globalvalue-guids-stable/84801 for context. This is a non-functional change which just changes the interface of GlobalValue, in preparation for future functional changes. This part touches a fair few users, so is split out for ease of review. Future changes to the GlobalValue implementation can then be focused purely on that class. This does the following: * Rename GlobalValue::getGUID(StringRef) to getGUIDAssumingExternalLinkage. This is simply making explicit at the callsite what is currently implicit. * Where possible, migrate users to directly calling getGUID on a GlobalValue instance. * Otherwise, where possible, have them call the newly renamed getGUIDAssumingExternalLinkage, to make the assumption explicit. There are a few cases where neither of the above are possible, as the caller saves and reconstructs the necessary information to compute the GUID themselves. We want to migrate these callers eventually, but for this first step we leave them be.
2025-04-07PowerPC32:PIC: Update to bcl to fix branch prediction mis-predict issue ↵Lei Huang
(#134140) Update `bl` to `bcl 20, 31, .+4` for 32bit PIC code gen so the link stack is not corrupted and cause mis-predict for the branch predictor. fixes: https://github.com/llvm/llvm-project/issues/128644
2025-03-22[PowerPC] Avoid repeated hash lookups (NFC) (#132514)Kazu Hirata
2025-03-20[PowerPC] Rename VariantKind to SpecifierFangrui Song
Follow the X86 and Mips renaming. > "Relocation modifier" suggests adjustments happen during the linker's relocation step rather than the assembler's expression evaluation. > "Relocation specifier" is clear, aligns with Arm and IBM’s usage, and fits the assembler's role seamlessly. In addition, rename *MCExpr::getKind, which confusingly shadows the base class getKind.
2025-03-12Move PowerPC-specific MCSymbolRefExpr::VariantKind to PPCMCExprFangrui Song
Most changes are mechanic, except: * ELFObjectWriter::shouldRelocateWithSymbol: .TOC.@tocbase does not register the undefined symbol. Move the handling into the Sym->isUndefined() code path. * ELFObjectWriter::fixSymbolsInTLSFixups's VK_PPC* cases are moved to PPCELFObjectWriter::getRelocType. We should do similar refactoring for other targets and eventually remove fixSymbolsInTLSFixups. In the future, we should classify PPCMCExpr similar to AArch64MCExpr.
2025-03-12[PowerPC] Rename PPCMCExpr's VK_PPC_ to VK_. NFCFangrui Song
Make the name conciser. PPC-specific MCSymbolRefExpr::VariantKind members will be moved to PPCMCExpr and we will not ue MCSymbolRefExpr::VariantKind's "generic" members, so there won't be mix-and-match.
2025-03-11[MC] Remove MCSymbolRefExpr::VK_Invalid in favor of getVaraintKindForName ↵Fangrui Song
returning std::optional so that when the enum members are moved to XXXTargetExpr::VariantKind,, they do not need to implement an invalid value.
2025-03-06[MC] Remove unneeded VK_None argument from MCSymbolRefExpr::create. NFCFangrui Song
2025-03-05[MC] Remove unneeded VK_None argument from MCSymbolRefExpr::create. NFCFangrui Song
2025-03-04Move PowerPC-specific absolute MCSymbolRefExpr::VariantKind to PPCMCExprFangrui Song
This cleans up @l @ha optimization in PPCAsmParser and is also the first step toward removing VK_PPC_* from the generic MCSymbolRefExpr::VariantKind. Basically we ensure that @l @ha family modifiers always lead to PPCMCExpr and avoid MCSymbolRefExpr::VariantKind. This allows us to delete a lot of switch statements that involve a long list of VK_PPC_LO/VK_PPC_HI/...
2025-03-02[PowerPC] Remove VK_PPC_TLSGD and VK_PPC_TLSLDFangrui Song
52cf8e44880bcf614068b66b63393aa8da1edd76 (2013) introduced the VK_PPC_TLSGD workaround to prevent unconditional reference to _GLOBAL_OFFSET_TABLE_ in ELFObjectWriter. e2b355d651ed8f2cbe61672c4c39b6419e471265 (2015) removed the `_GLOBAL_OFFSET_TABLE_` hack for the generic VK_TLSGD, making the VK_PPC_TLSGD workaround unneeded.
2025-02-18[PowerPC] Use MCRegister. NFCCraig Topper
2025-02-17[Targets] Move *TargetStreamer.h files into their MCTargetDesc directory. ↵Craig Topper
(#127433) These files are included from MCTargetDesc so should be there instead of in the main directory for the target.
2024-12-26[MC] Move AIX specific function to PPCAsmPrinterFangrui Song
https://reviews.llvm.org/D95518 used switchSectionNoPrint, which seems buggy as .ll -> .s -> .o will be different from .ll -> .o, but this change intends to be a NFC.
2024-12-24MCAsmInfo: replace AIX-specific variables with IsAIXFangrui Song
AIX assembly is very different from the gas syntax. We don't expect other targets to share these differences. Unify the numerous, essentially AIX-specific variables.
2024-12-10[PowerPC][AIX] Emit PowerPC version for XCOFF (#113214)Amy Kwan
This PR emits implements the ability to emit the PPC version for both assembly and object files on AIX.
2024-11-14[PowerPC] Remove unused includes (NFC) (#116163)Kazu Hirata
Identified with misc-include-cleaner.
2024-10-17[PGO] Initialize GCOV Writeout and Reset Functions in the Runtime on AIX ↵Qiongsi Wu
(#108570) This PR registers the writeout and reset functions for `gcov` for all modules in the PGO runtime, instead of registering them using global constructors in each module. The change is made for AIX only, but the same mechanism works on Linux on Power. When registering such functions using global constructors in each module without `-ffunction-sections`, the AIX linker cannot garbage collect unused undefined symbols, because such symbols are grouped in the same section as the `__sinit` symbol. Keeping such undefined symbols causes link errors (see test case https://github.com/llvm/llvm-project/pull/108570/files#diff-500a7e1ba871e1b6b61b523700d5e30987900002add306e1b5e4972cf6d5a4f1R1 for this scenario). This PR implements the initialization in the runtime, hence avoiding introducing `__sinit` into each module. The implementation adds a new global variable `__llvm_covinit_functions` to each module. This new global variable contains the function pointers to the `Writeout` and `Reset` functions. `__llvm_covinit_functions`'s section is the named section `__llvm_covinit`. The linker will aggregate all the `__llvm_covinit` sections from each module to form one single named section in the final binary. The pair of functions ``` const __llvm_gcov_init_func_struct *__llvm_profile_begin_covinit(); const __llvm_gcov_init_func_struct *__llvm_profile_end_covinit(); ``` are implemented to return the start and end address of this named section in the final binary, and they are used in function ``` __llvm_profile_gcov_initialize() ``` (which is a constructor function in the runtime) so the runtime knows the addresses of all the `Writeout` and `Reset` functions from all the modules. One noticeable implementation detail relevant to AIX is that to preserve the `__llvm_covinit` from the linker's garbage collection, a `.ref` pseudo instruction is inserted into them, referring to the section that contains the `__llvm_gcov_ctr` variables, which are used in the instrumented code. The `__llvm_gcov_ctr` variables did not belong to named sections before, but this PR added them to the `__llvm_gcov_ctr_section` named section, so we can add a `.ref` pseudo instruction that refers to them in the `__llvm_covinit` section.
2024-09-20[llvm] Don't call raw_string_ostream::flush() (NFC)Youngsuk Kim
Don't call raw_string_ostream::flush(), which is essentially a no-op. As specified in the docs, raw_string_ostream is always unbuffered. ( 65b13610a5226b84889b923bae884ba395ad084d for further reference )
2024-07-26CodeGen: Remove MachineModuleInfo reference from MachineFunction (#100357)Matt Arsenault
This avoids another unserializable field. Move the DbgInfoAvailable field into the AsmPrinter, which is only really a cache/convenience bit for checking a direct IR module metadata check.
2024-07-22[PowerPC]fix XRAY failures in ↵Chen Zheng
https://lab.llvm.org/buildbot/#/builders/145/builds/726 Regression caused by 43213002b99e32d618f2afbbaaeb2ff8dfc84e33.
2024-07-22[PowerPC] Support -fpatchable-function-entry (#92997)Chen Zheng
For now only PPC big endian Linux 32 and 64 bit are supported. PPC little endian Linux has XRAY support for 64-bit. PPC AIX has different patchable function entry implementations. Fixes #63220 Fixes #57031
2024-06-28[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)Nikita Popov
Similar to https://github.com/llvm/llvm-project/pull/96902, this adds `getDataLayout()` helpers to Function and GlobalValue, replacing the current `getParent()->getDataLayout()` pattern.
2024-06-06[PowerPC] Adjust operand order of ADDItoc to be consistent with other ADDI* ↵Kai Luo
nodes (#93642) Simultaneously, the `ADDItoc` machineinstr is generated in `PPCISelDAGToDAG::Select` so the pattern is not used and can be removed.
2024-05-22[PowerPC] Fix assembler error with toc-data and data-sections (#91976)Zaara Syeda
We should not emit the label for the toc-data variable when data-sections=false.
2024-05-21[PowerPC][AIX] 64-bit large code-model support for toc-data (#90619)Zaara Syeda
This patch adds support for toc-data for 64-bit large code-model on AIX. The sequence ADDIStocHA8/ADDItocL8 is used to access the data directly from the TOC. When emitting the instruction ADDIStocHA8, we check if the symbol has toc-data attribute before creating a toc entry for it. When emitting the instruction ADDItocL8, we use the LA8 instruction to load the address.
2024-05-09[PowerPC] Tune AIX shared library TLS model at function level (#84132)Felix (Ting Wang)
Under some circumstance (library loaded with the main program), TLS initial-exec model can be applied to local-dynamic access(es). We could use some simple heuristic to decide the update at function level: * If there is equal or less than a number of TLS local-dynamic access(es) in the function, use TLS initial-exec model. (the threshold which default to 1 is controlled by hidden option)
2024-05-08[PowerPC][AIX] Refactor existing logic to handle non-zero offsets for ↵Felix (Ting Wang)
aix-small-local-dynamic-tls (#89182) To enable optimized small local-dynamic access sequence for non-zero offsets, this patch refactors existing 2a50921553798d2db52ca6330c89f0f8a5bc2215.
2024-05-05[Target] Use StringRef::operator== instead of StringRef::equals (NFC) ↵Kazu Hirata
(#91072) (#91138) I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 38 under llvm/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
2024-04-25[PowerPC] Use `SmallSetVector` to enable deterministic build (#89875)Kai Luo
This is to address the issue in https://lab.llvm.org/buildbot/#/builders/54. `SmallSetVector` interfaces as set and can be iterated in a deterministic order.
2024-04-17[PowerPC] 32-bit large code-model support for toc-data (#85129)Zaara Syeda
This patch adds the pseudo op ADDItocL for 32-bit large code-model support for toc-data.
2024-04-12[PowerPC][AIX] Enable aix-small-local-dynamic-tls target attribute (#86641)Felix (Ting Wang)
Following the aix-small-local-exec-tls target attribute, this patch adds a target attribute for an AIX-specific option in llc that informs the compiler that it can use a faster access sequence for the local-dynamic TLS model (formally named aix-small-local-dynamic-tls) when TLS variables are less than ~32KB in size. The patch either produces an addi/la with a displacement off of module handle (return value from .__tls_get_mod) when the address is calculated, or it produces an addi/la followed by a load/store when the address is calculated and used for further accesses. --------- Co-authored-by: Amy Kwan <amy.kwan1@ibm.com>
2024-03-22[PowerPC][AIX] support explicit sections for -ffunction-sections (#85351)Chen Zheng
Fix crashes in https://godbolt.org/z/6voEa1o6Y
2024-03-15[AIX] Support per global code model. (#79202)Sean Fertile
Exploit the per global code model attribute on AIX. On AIX we need to update both the code sequence used to access the global (either 1 or 2 instructions for small and large code model respectively) and the storage mapping class that we emit the toc entry. --------- Co-authored-by: Amy Kwan <akwan0907@gmail.com>
2024-03-14[AIX][TOC] Fix buildbot failures from commit b4ae8df (#85303)Zaara Syeda
The following tests fail when built with Address and Undefined sanitizers: CodeGen/PowerPC/basic-toc-data-def.ll CodeGen/PowerPC/toc-data-large-array2.ll Subtarget may be null in emitGlobalVariable, for example in the testcase where we have no functions in the IR. The fix moves this function from PPCSubtarget to a static helper function. This only fails with sanitizers because the Subtarget is not used in the member function.
2024-03-13[PowerPC][NFC] Rename ADDItocL to match the 64-bit naming convention (#85099)Zaara Syeda
In preparation of adding a similar instruction for large code model on AIX for 32-bit, rename the exisitng ADDItocL 64-instruction to ADDItocL8 to match the naming convention of other instructions with 32-bit and 64-bit variants.
2024-03-13[AIX][TOC] Add -mtocdata/-mno-tocdata options on AIX (#67999)Zaara Syeda
This patch enables support that the XL compiler had for AIX under -qdatalocal/-qdataimported.
2024-03-01[PowerPC] Support local-dynamic TLS relocation on AIX (#66316)Felix (Ting Wang)
Supports TLS local-dynamic on AIX, generates below sequence of code: ``` .tc foo[TC],foo[TL]@ld # Variable offset, ld relocation specifier .tc mh[TC],mh[TC]@ml # Module handle for the caller lwz 3,mh[TC]\(2\) $$ For 64-bit: ld 3,mh[TC]\(2\) bla .__tls_get_mod # Modifies r0,r3,r4,r5,r11,lr,cr0 #r3 = &TLS for module lwz 4,foo[TC]\(2\) $$ For 64-bit: ld 4,foo[TC]\(2\) add 5,3,4 # Compute &foo .rename mh[TC], "\_$TLSML" # Symbol for the module handle must have the name "_$TLSML" ``` --------- Co-authored-by: tingwang <tingwang@tingwangs-MBP.lan> Co-authored-by: tingwang <tingwang@tingwangs-MacBook-Pro.local>
2024-02-05[PowerPC] Fix assertion of InstDisp for local-exec TLS. NFC.Kai Luo
Fixes https://github.com/llvm/llvm-project/issues/80557.
2024-02-02[PowerPC] Fix gcc -Wparentheses warning [NFC]Mikael Holmen
Without this gcc warns like ../lib/Target/PowerPC/PPCAsmPrinter.cpp:1650:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses] 1650 | (InstDisp >= -32768) && | ~~~~~~~~~~~~~~~~~~~~~^~ 1651 | "Expecting the instruction displacement for local-exec TLS " | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1652 | "variables to be between [-32768, 32768)!"); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2024-02-01[PowerPC] Fix -Wunused-variable in PPCAsmPrinter.cpp and PPCISelDAGToDAG.cpp ↵Jie Fu
(NFC) llvm-project/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp:1648:15: error: unused variable 'InstDisp' [-Werror,-Wunused-variable] ptrdiff_t InstDisp = TLSVarAddress + Offset - Delta; ^ llvm-project/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp:7624:19: error: unused variable 'TPReg' [-Werror,-Wunused-variable] RegisterSDNode *TPReg = dyn_cast<RegisterSDNode>(TPRegNode.getNode()); ^ llvm-project/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp:7625:23: error: unused variable 'Subtarget' [-Werror,-Wunused-variable] const PPCSubtarget &Subtarget = ^
2024-02-01[AIX][TLS] Optimize the small local-exec access sequence for non-zero ↵Amy Kwan
offsets (#71485) This patch utilizes the -maix-small-local-exec-tls option to produce a faster, non-TOC-based access sequence for the local-exec TLS model. Specifically, for when the offsets from the TLS variable are non-zero. In particular, this patch produces either a single: - addi/la with a displacement off of R13 plus a non-zero offset for when an address is calculated, or - load or store off of R13 plus a non-zero offset for when an address is calculated and used for further access where R13 is the thread pointer, respectively. In order to produce a single addi or load/store off of the thread pointer with a non-zero offset, this patch also adds the necessary support in the assembly printer when printing these instructions. Specifically: - The non-zero offset is added to the TLS variable address when the address of the TLS variable + it's offset is less than 32KB. - Otherwise, when the address of the TLS variable + its offset is greater than 32KB, the non-zero offset (and a multiple of 64KB) is subtracted from the TLS address. This handling in the assembly printer is necessary to ensure that the TLS address + the non-zero offset is between [-32768, 32768), so that the total displacement can fit within the addi/load/store instructions. This patch is meant to be a follow-up to 3f46e5453d9310b15d974e876f6132e3cf50c4b1 (where the optimization occurs for when the offset is zero).
2024-01-31[AIX] [XCOFF] Add support for common and local common symbols in the TOC ↵Zaara Syeda
(#79530) This patch adds support for common and local symbols in the TOC for AIX. Note that we need to update isVirtualSection so as a common symbol in TOC will have the symbol type XTY_CM and will be initialized when placed in the TOC so sections with this type are no longer virtual. --------- Co-authored-by: Zaara Syeda <syzaara@ca.ibm.com>
2024-01-26[PowerPC][X86] Make cpu id builtins target independent and lower for PPC ↵Nemanja Ivanovic
(#68919) Make __builtin_cpu_{init|supports|is} target independent and provide an opt-in query for targets that want to support it. Each target is still responsible for their specific lowering/code-gen. Also provide code-gen for PowerPC. I originally proposed this in https://reviews.llvm.org/D152914 and this addresses the comments I received there. --------- Co-authored-by: Nemanja Ivanovic <nemanjaivanovic@nemanjas-air.kpn> Co-authored-by: Nemanja Ivanovic <nemanja@synopsys.com>