summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
AgeCommit message (Collapse)Author
2025-06-23AMDGPU: Remove legacy pass manager version of AMDGPUAttributor (#145262)Matt Arsenault
2025-05-23[IPO] Teach AbstractAttribute::getName to return StringRef (NFC) (#141313)Kazu Hirata
This patch addresses clang-tidy's readability-const-return-type by dropping const from the return type while switching to StringRef at the same time because these functions just return string constants.
2025-05-17[AMDGPU] Fix a warningKazu Hirata
This patch fixes: llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp:1139:17: error: unused variable 'Func' [-Werror,-Wunused-variable]
2025-05-17[AMDGPU][Attributor] Rework update of `AAAMDWavesPerEU` (#123995)Shilei Tian
Currently, we use `AAAMDWavesPerEU` to iteratively update values based on attributes from the associated function, potentially propagating user-annotated values, along with `AAAMDFlatWorkGroupSize`. Similarly, we have `AAAMDFlatWorkGroupSize`. However, since the value calculated through the flat workgroup size always dominates the user annotation (i.e., the attribute), running `AAAMDWavesPerEU` iteratively is unnecessary if no user-annotated value exists. This PR completely rewrites how the `amdgpu-waves-per-eu` attribute is handled in `AMDGPUAttributor`. The key changes are as follows: - `AAAMDFlatWorkGroupSize` remains unchanged. - `AAAMDWavesPerEU` now only propagates user-annotated values. - A new function is added to check and update `amdgpu-waves-per-eu` based on the following rules: - No waves per eu, no flat workgroup size: Assume a flat workgroup size of `1,1024` and compute waves per eu based on this. - No waves per eu, flat workgroup size exists: Use the provided flat workgroup size to compute waves-per-eu. - Waves per eu exists, no flat workgroup size: This is a tricky case. In this PR, we assume a flat workgroup size of `1,1024`, but this can be adjusted if a different approach is preferred. Alternatively, we could directly use the user-annotated value. - Both waves per eu and flat workgroup size exist: If there’s a conflict, the value derived from the flat workgroup size takes precedence over waves per eu. This PR also updates the logic for merging two waves per eu pairs. The current implementation, which uses `clampStateAndIndicateChange` to compute a union, might not be ideal. If we think from ensure proper resource allocation perspective, for instance, if one pair specifies a minimum of 2 waves per eu, and another specifies a minimum of 4, we should guarantee that 4 waves per eu can be supported, as failing to do so could result in excessive resource allocation per wave. A similar principle applies to the upper bound. Thus, the PR uses the following approach for merging two pairs, `lo_a,up_a` and `lo_b,up_b`: `max(lo_a, lo_b), max(up_a, up_b)`. This ensures that resource allocation adheres to the stricter constraints from both inputs. Fix #123092.
2025-05-11[AMDGPU] Move kernarg preload logic to separate pass (#130434)Austin Kerbow
Moves kernarg preload logic to its own module pass. Cloned function declarations are removed when preloading hidden arguments. The inreg attribute is now added in this pass instead of AMDGPUAttributor. The rest of the logic is copied from AMDGPULowerKernelArguments which now only check whether an arguments is marked inreg to avoid replacing direct uses of preloaded arguments. This change requires test updates to remove inreg from lit tests with kernels that don't actually want preloading.
2025-05-02[AMDGPU][Attributor] Add `ThinOrFullLTOPhase` as an argument (#123994)Shilei Tian
2025-05-01[AMDGPU] Max. WG size-induced occupancy limits max. waves/EU (#137807)Lucas Ramirez
The default maximum waves/EU returned by the family of `AMDGPUSubtarget::getWavesPerEU` is currently the maximum number of waves/EU supported by the subtarget (only a valid occupancy range in "amdgpu-waves-per-eu" may lower that maximum). This ignores maximum achievable occupancy imposed by flat workgroup size and LDS usage, resulting in situations where `AMDGPUSubtarget::getWavesPerEU` produces a maximum higher than the one from `AMDGPUSubtarget::getOccupancyWithWorkGroupSizes`. This limits the waves/EU range's maximum to the maximum achievable occupancy derived from flat workgroup sizes and LDS usage. This only has an impact on functions which restrict flat workgroup size with "amdgpu-flat-work-group-size", since the default range of flat workgroup sizes achieves the maximum number of waves/EU supported by the subtarget. Improvements to the handling of "amdgpu-waves-per-eu" are left for a follow up PR (e.g., I think the attribute should be able to lower the full range of waves/EU produced by these methods).
2025-04-07[NFC][LLVM][AMDGPU] Cleanup pass initialization for AMDGPU (#134410)Rahul Joshi
- Remove calls to pass initialization from pass constructors. - https://github.com/llvm/llvm-project/issues/111767
2025-03-19AMDGPU: Fix attributor not handling all trap intrinsics (#131758)Matt Arsenault
2025-03-06AMDGPU: Replace amdgpu-no-agpr with amdgpu-agpr-alloc (#129893)Matt Arsenault
This performs the minimal replacment of amdgpu-no-agpr to amdgpu-agpr-alloc=0. Most of the test diffs are due to the new attribute sorting later alphabetically. We could do better by trying to perform range merging in the attributor, and trying to pick non-0 values.
2024-12-20AMDGPU: Fix mishandling of search for constantexpr addrspacecasts (#120346)Matt Arsenault
2024-12-11[AMDGPU][Attributor] Make `AAAMDWavesPerEU` honor existing attribute (#114438)Shilei Tian
2024-12-11[AMDGPU][Attributor] Make `AAAMDFlatWorkGroupSize` honor existing attribute ↵Shilei Tian
(#114357) If a function has `amdgpu-flat-work-group-size`, honor it in `initialize` by taking its value directly; otherwise, it uses the default range as a starting point. We will no longer manipulate the known range, which can cause issues because the known range is a "throttle" to the assumed range such that the assumed range can't get widened properly in `updateImpl` if the known range is not set properly for whatever reasons. Another benefit of not touching the known range is, if we indicate pessimistic state, it also invalidates the AA such that `manifest` will not be called. Since we honor the attribute, we don't want and will not add any half-baked attribute added to a function.
2024-12-10[AMDGPU] Re-enable closed-world assumption as an opt-in feature (#115371)Shilei Tian
Although the ABI (if one exists) doesn’t explicitly prohibit cross-code-object function calls—particularly since our loader can handle them—such calls are not actually allowed in any of the officially supported programming models. However, this limitation has some nuances. For instance, the loader can handle cross-code-object global variables, which complicates the situation further. Given this complexity, assuming a closed-world model at link time isn’t always safe. To address this, this PR introduces an option that enables this assumption, providing end users the flexibility to enable it for improved compiler optimizations. However, it is the user’s responsibility to ensure they do not violate this assumption.
2024-12-09Reapply "[AMDGPU] Infer amdgpu-no-flat-scratch-init attribute in ↵Jun Wang
AMDGPUAttributor (#94647)" (#118907) This reverts commit 1ef9410a96c1d9669a6feaf03fcab8d0a4a13bd5. This fixes the test file attributor-flatscratchinit-globalisel.ll.
2024-12-09AMDGPU: Propagate amdgpu-max-num-workgroups attribute (#113018)Matt Arsenault
I'm not sure what the interpretation of 0 is supposed to be, AMDGPUUsage doesn't say.
2024-12-04Revert "[AMDGPU] Infer amdgpu-no-flat-scratch-init attribute in ↵Philip Reames
AMDGPUAttributor (#94647)" This reverts commit e6aec2c12095cc7debd1a8004c8535eef41f4c36. Commit breaks "ninja check-llvm" on x86 host.
2024-12-04[AMDGPU] Infer amdgpu-no-flat-scratch-init attribute in AMDGPUAttributor ↵Jun Wang
(#94647) The AMDGPUAnnotateKernelFeatures pass infers the "amdgpu-calls" and "amdgpu-stack-objects" attributes, which are used to infer whether we need to initialize flat scratch. This is, however, not precise. Instead, we should use AMDGPUAttributor and infer amdgpu-no-flat-scratch-init on kernels. Refer to https://github.com/llvm/llvm-project/issues/63586 .
2024-10-31[NFC] clang-format -i llvm/lib/Target/AMDGPU/AMDGPUAttributor.cppShilei Tian
2024-10-30Revert "[NFC][AMDGPU][Attributor] Exit earlier if entry CC (#114177)"Shilei Tian
This reverts commit 922a0d3dfe2db7a2ef50e8cef4537fa94a7b95bb.
2024-10-30[NFC][AMDGPU][Attributor] Exit earlier if entry CC (#114177)Shilei Tian
Avoid calling TTI or other stuff unnecessarily
2024-10-29[AMDGPU][Attributor] Check the validity of a dependent AA before using its ↵Shilei Tian
value (#114165) Even though the Attributor framework will invalidate all its dependent AAs after the current iteration, a dependent AA can still use the worst state of a depending AA if it doesn't check the state of the depending AA in current iteration.
2024-09-12[NFC][AMDGPU][Attributor] Only iterate over filtered functions when creating ↵Shilei Tian
AAs (#108417)
2024-09-06[Attributor] Add support for atomic operations in `AAAddressSpace` (#106927)Shilei Tian
2024-09-01Revert "[AMDGPU][LTO] Assume closed world after linking (#105845)" (#106889)Shilei Tian
We can't assume closed world even in full LTO post-link stage. It is only true if we are building a "GPU executable". However, AMDGPU does support "dyamic library". I'm not aware of any approach to tell if it is relocatable link when we create the pass. For now let's revert the patch as it is currently breaking things. We can re-enable it once we can handle it correctly.
2024-08-27[AMDGPU][Attributor] Remove uniformity check in the indirect call ↵Shilei Tian
specialization callback (#106177) This patch removes the conservative uniformity check in the indirect call specialization callback, as whether the function pointer is uniform doesn't matter too much. Instead, we add an argument to control specialization.
2024-08-25Revert "Revert "[AMDGPU][LTO] Assume closed world after linking (#105845)" ↵Anshil Gandhi
(#106000)" (#106001) This reverts commit 4b6c064dd124c70ff163411dff120c6174e0e022. Add a requirement for an amdgpu target in the test.
2024-08-25Revert "[AMDGPU][LTO] Assume closed world after linking (#105845)" (#106000)Anshil Gandhi
This reverts commit 33f3ebc86e7d3afcb65c551feba5bbc2421b42ed.
2024-08-25[AMDGPU][LTO] Assume closed world after linking (#105845)Anshil Gandhi
2024-08-14Reapply "[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor ↵Shilei Tian
(#100952)" This reverts commit 36467bfe89f231458eafda3edb916c028f1f0619.
2024-08-09[AMDGPU][Attributor] Add a pass parameter `closed-world` for ↵Shilei Tian
AMDGPUAttributor pass (#101760)
2024-08-07Revert "Reapply "[Attributor][AMDGPU] Enable AAIndirectCallInfo for ↵Shilei Tian
AMDAttributor (#100952)"" This reverts commit 7a68449a82ab1c1ab005caa72c1d986ca5deca36. https://lab.llvm.org/buildbot/#/builders/123/builds/3205
2024-08-06Reapply "[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor ↵Shilei Tian
(#100952)" This reverts commit 874cd100a076f3b98aaae09f90ef224682501538.
2024-08-06[AMDGPU] Enable `AAAddressSpace` in `AMDGPUAttributor` (#101593)Shilei Tian
2024-08-02Revert "[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor ↵Shilei Tian
(#100952)" This reverts commit ab819d7cf86932e4a47b5bf6aadea9d714a313a9.
2024-08-02[Attributor][AMDGPU] Enable AAIndirectCallInfo for AMDAttributor (#100952)Shilei Tian
2024-08-02[NFC][AMDGPU] Reformat code for creating AA (#101591)Shilei Tian
2024-07-16[AMDGPU] Fix and add namespace closing comments. NFC.Jay Foad
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-03-21AMDGPU: Infer no-agpr usage in AMDGPUAttributor (#85948)Matt Arsenault
SIMachineFunctionInfo has a scan of the function body for inline asm which may use AGPRs, or callees in SIMachineFunctionInfo. Move this into the attributor, so it actually works interprocedurally. Could probably avoid most of the test churn if this bothered to avoid adding this on subtargets without AGPRs. We should also probably try to delete the MIR scan in usesAGPRs but it seems to be trickier to eliminate.
2024-01-21[AMDGPU] Add an asm directive to track code_object_version (#76267)Emma Pilkington
Named '.amdhsa_code_object_version'. This directive sets the e_ident[ABIVERSION] in the ELF header, and should be used as the assumed COV for the rest of the asm file. This commit also weakens the --amdhsa-code-object-version CL flag. Previously, the CL flag took precedence over the IR flag. Now the IR flag/asm directive take precedence over the CL flag. This is implemented by merging a few COV-checking functions in AMDGPUBaseInfo.h.
2023-11-07AMDGPU: Port AMDGPUAttributor to new pass manager (#71349)Matt Arsenault
2023-09-19[AMDGPU] Use inreg for hint to preload kernel argumentsAustin Kerbow
This patch is the first in a series that adds support for pre-loading kernel arguments into SGPRs. The command-line argument 'amdgpu-kernarg-preload-count' is used to specify the number of arguments sequentially from the first that we should attempt to preload, the default is 0. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D156852
2023-07-19[AMDGPUAttributor][FIX] No endless recursion for recursive initializersJohannes Doerfert
Fixes: https://github.com/llvm/llvm-project/issues/63956
2023-07-09[Attributor] Port AANonNull to the isImpliedByIR interfaceJohannes Doerfert
AANonNull is now the first AA that is always queried via the new APIs and not created manually. Others will follow shortly to avoid trivial AAs whenever possible. This commit introduced some helper logic that will make it simpler to port the next one. It also untangles AADereferenceable and AANonNull such that the former does not keep a handle on the latter. Finally, we stop deducing `nonnull` for `undef`, which was incorrect.
2023-07-03[Attributor][NFCI] Move attribute collection and manifest to AttributorJohannes Doerfert
Before, we checked and manifested attributes right in the IR. This was bad as we modified the IR before the manifest stage. Now we can add/remove/inspect attributes w/o going to the IR (except for the initial query).
2023-06-29[Attributor] Introduce helpers to judge AAs prior to creationJohannes Doerfert
This is a partial cleanup to centralize the initialization and update decisions for AAs. Lifting the burdon and boilerplate on users and making it harder to accidentally perform unsound deductions. The two static helpers show how we can lift the decisions to generate an AA into the Attributor, avoiding trivial AAs that just cost us compile time and maintenance code (to check for pre-conditions).
2023-06-29[AAAMDAttributes] AAPointerInfo depends on AAUnderlyingObjectsJohannes Doerfert
2023-06-29[AMDGPUAttributor][NFC] Make the debug output meaningfulJohannes Doerfert
2023-06-23[Attributor][NFCI] Use pointers to pass around AAsJohannes Doerfert
This will make it easier to create less trivial AAs in the future as we can simply return `nullptr` rather than an AA with in invalid state.