summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
AgeCommit message (Collapse)Author
2025-08-22[llvm] Remove unused includes of SmallSet.h (NFC) (#154893)Kazu Hirata
We just replaced SmallSet<T *, N> with SmallPtrSet<T *, N>, bypassing the redirection found in SmallSet.h. With that, we no longer need to include SmallSet.h in many files.
2025-08-21[Scalar] Use SmallSetVector instead of SmallVector (NFC) (#154678)Kazu Hirata
insertParsePoints collects live variables and then deduplicate them while retaining the original insertion order, which is exactly what SetVector is designed for. This patch replaces SmallVector with SetSmallVector while deleting unique_unsorted. While we are at it, this patch reduces the number of inline elements to a reasonable level for linear search.
2025-08-20[Scalar] Use SmallPtrSet directly instead of SmallSet (NFC) (#154473)Kazu Hirata
I'm trying to remove the redirection in SmallSet.h: template <typename PointeeType, unsigned N> class SmallSet<PointeeType*, N> : public SmallPtrSet<PointeeType*, N> {}; to make it clear that we are using SmallPtrSet. There are only handful places that rely on this redirection. This patch replaces SmallSet to SmallPtrSet where the element type is a pointer.
2025-08-14[TTI] Add cost kind to getAddressComputationCost(). NFC. (#153342)Elvis Wang
This patch add cost kind to `getAddressComputationCost()` for #149955. Note that this patch also remove all the default value in `getAddressComputationCost()`.
2025-08-11[TTI] Consistently pass the pointer type to getAddressComputationCost. NFCI ↵Luke Lau
(#152657) In some places we were passing the type of value being accessed, in other cases we were passing the type of the pointer for the access. The most "involved" user is LoopVectorizationCostModel::getMemInstScalarizationCost, which is the only call site that passes in the SCEV, and it passes along the pointer type. This changes call sites to consistently pass the pointer type, and renames the arguments to clarify this. No target actually checks the contents of the type passed, only to see if it's a vector or not, so this shouldn't have an effect.
2025-05-06[IR] Remove the AtomicMem*Inst helper classes (#138710)Philip Reames
Migrate their usage to the `AnyMem*Inst` family, and add a isAtomic() query on the base class for that hierarchy. This matches the idioms we use for e.g. isAtomic on load, store, etc.. instructions, the existing isVolatile idioms on mem* routines, and allows us to more easily share code between atomic and non-atomic variants. As with #138568, the goal here is to simplify the class hierarchy and make it easier to reason about. I'm moving from easiest to hardest, and will stop at some point when I hit "good enough". Longer term, I'd sorta like to merge or reverse the naming on the plain Mem*Inst and the AnyMem*Inst, but that's a much larger and more risky change. Not sure I'm going to actually do that.
2025-04-19[Scalar] Avoid repeated hash lookups (NFC) (#136264)Kazu Hirata
2025-04-17[Scalar] Avoid repeated hash lookups (NFC) (#135751)Kazu Hirata
2025-04-17[Intrinsics] Add support for range attributes (#135642)Nikita Popov
Add support for specifying range attributes in Intrinsics.td. Use this to specify the ucmp/scmp range [-1,2). This case is trickier than existing intrinsic attributes, because we need to create the attribute with the correct bitwidth. As such, the attribute construction now needs to be aware of the function type. We also need to be careful to no longer assign attributes on intrinsics with invalid signatures, as we'd make invalid assumptions about the number of arguments etc otherwise. Fixes https://github.com/llvm/llvm-project/issues/130179.
2025-04-13[Scalar] Avoid repeated hash lookups (NFC) (#135585)Kazu Hirata
2025-04-13[Scalar] Avoid repeated hash lookups (NFC) (#132660)Kazu Hirata
2025-03-28[llvm] Remove extraneous calls to make_range (NFC) (#133551)Kazu Hirata
2025-03-22[llvm] Use *Set::insert_range (NFC) (#132509)Kazu Hirata
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently gained C++23-style insert_range. This patch uses insert_range in conjunction with llvm::{predecessors,successors} and MachineBasicBlock::{predecessors,successors}.
2025-03-21[Scalar] Avoid repeated hash lookups (NFC) (#132330)Kazu Hirata
2025-03-19[Transforms] Use *Set::insert_range (NFC) (#132056)Kazu Hirata
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently gained C++23-style insert_range. This patch replaces: Dest.insert(Src.begin(), Src.end()); with: Dest.insert_range(Src); This patch does not touch custom begin like succ_begin for now.
2025-03-19[Scalar] Avoid repeated hash lookups (NFC) (#131961)Kazu Hirata
2025-01-27[NFC][DebugInfo] Switch more call-sites to using iterator-insertion (#124283)Jeremy Morse
To finalise the "RemoveDIs" work removing debug intrinsics, we're updating call sites that insert instructions to use iterators instead. This set of changes are those where it's not immediately obvious that just calling getIterator to fetch an iterator is correct, and one or two places where more than one line needs to change. Overall the same rule holds though: iterators generated for the start of a block such as getFirstNonPHIIt need to be passed into insert/move methods without being unwrapped/rewrapped, everything else can use getIterator.
2025-01-24[NFC][DebugInfo] Use iterator moveBefore at many call-sites (#123583)Jeremy Morse
As part of the "RemoveDIs" project, BasicBlock::iterator now carries a debug-info bit that's needed when getFirstNonPHI and similar feed into instruction insertion positions. Call-sites where that's necessary were updated a year ago; but to ensure some type safety however, we'd like to have all calls to moveBefore use iterators. This patch adds a (guaranteed dereferenceable) iterator-taking moveBefore, and changes a bunch of call-sites where it's obviously safe to change to use it by just calling getIterator() on an instruction pointer. A follow-up patch will contain less-obviously-safe changes. We'll eventually deprecate and remove the instruction-pointer insertBefore, but not before adding concise documentation of what considerations are needed (very few).
2024-11-10Fix a warning. [-Wunused-but-set-variable]NAKAMURA Takumi
2024-11-08[Statepoint] Treat result of atomicrmw xchg as a base pointer (#97280)Csanád Hajdú
Atomic RMW Xchg wasn't handled before when searching for known base pointers in the IR.
2024-11-02[Scalar] Remove unused includes (NFC) (#114645)Kazu Hirata
Identified with misc-include-cleaner.
2024-10-11[NFC] Rename `Intrinsic::getDeclaration` to `getOrInsertDeclaration` (#111752)Rahul Joshi
Rename the function to reflect its correct behavior and to be consistent with `Module::getOrInsertFunction`. This is also in preparation of adding a new `Intrinsic::getDeclaration` that will have behavior similar to `Module::getFunction` (i.e, just lookup, no creation).
2024-09-19[LLVM] Use {} instead of std::nullopt to initialize empty ArrayRef (#109133)Jay Foad
It is almost always simpler to use {} instead of std::nullopt to initialize an empty ArrayRef. This patch changes all occurrences I could find in LLVM itself. In future the ArrayRef(std::nullopt_t) constructor could be deprecated or removed.
2024-08-26[GC] Rename gc_args to gc_live [nfc]Philip Reames
Better reflect the recent history of the code, and improve readability for when I have to glance back at this to answer a question.
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-27[IR] Add getDataLayout() helpers to BasicBlock and Instruction (#96902)Nikita Popov
This is a helper to avoid writing `getModule()->getDataLayout()`. I regularly try to use this method only to remember it doesn't exist... `getModule()->getDataLayout()` is also a common (the most common?) reason why code has to include the Module.h header.
2024-06-24Revert "[IR][NFC] Update IRBuilder to use InsertPosition (#96497)"Stephen Tozer
Reverts the above commit, as it updates a common header function and did not update all callsites: https://lab.llvm.org/buildbot/#/builders/29/builds/382 This reverts commit 6481dc57612671ebe77fe9c34214fba94e1b3b27.
2024-06-24[IR][NFC] Update IRBuilder to use InsertPosition (#96497)Stephen Tozer
Uses the new InsertPosition class (added in #94226) to simplify some of the IRBuilder interface, and removes the need to pass a BasicBlock alongside a BasicBlock::iterator, using the fact that we can now get the parent basic block from the iterator even if it points to the sentinel. This patch removes the BasicBlock argument from each constructor or call to setInsertPoint. This has no functional effect, but later on as we look to remove the `Instruction *InsertBefore` argument from instruction-creation (discussed [here](https://discourse.llvm.org/t/psa-instruction-constructors-changing-to-iterator-only-insertion/77845)), this will simplify the process by allowing us to deprecate the InsertPosition constructor directly and catch all the cases where we use instructions rather than iterators.
2024-06-14[llvm] Use llvm::unique (NFC) (#95628)Kazu Hirata
2024-06-13[llvm-project] Fix typo "seperate" (#95373)Jay Foad
2024-05-08Add interface to check if a call has a deopt bundle (NFC) (#91348)Aleksandr Popov
Encapsulate check that a call has a deopt bundle to make it easier to change the deopt scheme.
2024-05-04[Transforms] Use StringRef::operator== instead of StringRef::equals (NFC) ↵Kazu Hirata
(#91072) I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 31 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-05[NFC][RemoveDIs] Insert instruction using iterators in Transforms/Jeremy Morse
As part of the RemoveDIs project we need LLVM to insert instructions using iterators wherever possible, so that the iterators can carry a bit of debug-info. This commit implements some of that by updating the contents of llvm/lib/Transforms/Utils to always use iterator-versions of instruction constructors. There are two general flavours of update: * Almost all call-sites just call getIterator on an instruction * Several make use of an existing iterator (scenarios where the code is actually significant for debug-info) The underlying logic is that any call to getFirstInsertionPt or similar APIs that identify the start of a block need to have that iterator passed directly to the insertion function, without being converted to a bare Instruction pointer along the way. Noteworthy changes: * FindInsertedValue now takes an optional iterator rather than an instruction pointer, as we need to always insert with iterators, * I've added a few iterator-taking versions of some value-tracking and DomTree methods -- they just unwrap the iterator. These are purely convenience methods to avoid extra syntax in some passes. * A few calls to getNextNode become std::next instead (to keep in the theme of using iterators for positions), * SeparateConstOffsetFromGEP has it's insertion-position field changed. Noteworthy because it's not a purely localised spelling change. All this should be NFC.
2024-01-22[Transforms] Fix -Wunused-variable and remove redundant VerifyStates after ↵Jie Fu
#75826 (NFC) llvm-project/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:1064:18: error: unused variable 'I' [-Werror,-Wunused-variable] Instruction *I = cast<Instruction>(Pair.first); ^ llvm-project/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:1066:11: error: unused variable 'BaseValue' [-Werror,-Wunused-variable] auto *BaseValue = State.getBaseValue(); ^ 2 errors generated.
2024-01-22True fixpoint algorithm in RS4GC (#75826)Petr Maj
Fixes a problem where the explicit marking of various instructions as conflicts did not propagate to their users. An example of this: ``` %getelementptr = getelementptr i8, <2 x ptr addrspace(1)> zeroinitializer, <2 x i64> <i64 888, i64 908> %shufflevector = shufflevector <2 x ptr addrspace(1)> %getelementptr, <2 x ptr addrspace(1)> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3> %shufflevector1 = shufflevector <2 x ptr addrspace(1)> %getelementptr, <2 x ptr addrspace(1)> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3> %select = select i1 false, <4 x ptr addrspace(1)> %shufflevector1, <4 x ptr addrspace(1)> %shufflevector ``` Here the vector shuffles will get single base (gep) during the fixpoint and therefore the select will get a known base (gep). We later mark the shuffles as conflicts, but this does not change the base of select. This gets caught by an assert where the select's type will differ from its (wrong) base later on. The solution in the MR is to move the explicit conflict marking into the fixpoint phase. --------- Co-authored-by: Petr Maj <pmaj@azul.com>
2024-01-10[RewriteStatepointsForGC] Remove unnecessary bitcasts (NFCI)Nikita Popov
2023-12-22[Transforms] Use {DenseMap,SmallPtrSet}::contains (NFC)Kazu Hirata
2023-11-23Extra assertions in RS4GC (#71201)Petr Maj
Adds assertion that the base/derived pointers are of the same size. --------- Co-authored-by: Petr Maj <pmaj@azul.com>
2023-11-07[NFC] Remove Type::getInt8PtrTy (#71029)Paulo Matos
Replace this with PointerType::getUnqual(). Followup to the opaque pointer transition. Fixes an in-code TODO item.
2023-11-02Improvements to RS4GC BDV Algorithm (#69795)Petr Maj
Previously, after the algorithm fixpointed, the state was manually patched by emitting BDVs for EE instructions earlier, while marking some (but not all) vector and vector<->scalar instructions as conflict. This causes issues as not all instructions that required BDVs had them emitted and due to after-fixpoint patching, the extra BDVs did not propagate to their users. This change fixes both by rewriting the logic for BDV insertion & patching. Instead of inserting the BDV for EE earlier, it merely marks every EE instruction as a conflict. The two phase insertion algorithm (first insert empty instructions and patch the BDVState, then actually connect the BDV instructions to their input bases) then ensures correct propagation to all its users. Furthermore the shufflevector instruction as well as all instances of IE instruction are conservatively marked as conflicts as well, fixing the second problem. This change does not fix the handling of constant values and vectors in the BDV. --------- Co-authored-by: Petr Maj <pmaj@azul.com>
2023-10-16[RS4GC] Copy argument attributes from call to statepoint (#68475)Markus Böck
The current implementation completely ignores argument attributes on calls, discarding them completely when creating a statepoint from a call instruction. This is problematic in some scenarios as the argument attributes affect the ABI of the call, leading to undefined behavior if called with the wrong ABI attributes. Note that this cannot be solved either by just having the function declaration annotated with the right parameter attributes as the call might be indirect, therefore requiring them to be present on the arguments. This PR simply copies all parameter attributes over from the original call to the created statepoint. Note that some argument attributes become invalid after the lowering as they imply memory effects that no longer hold with the statepoints. These do not need to be explicitly handled in this PR as they are removed by the `stripNonValidDataFromBody`.
2023-09-11[NFC][RemoveDIs] Use iterators over inst-pointers when using IRBuilderJeremy Morse
This patch adds a two-argument SetInsertPoint method to IRBuilder that takes a block/iterator instead of an instruction, and updates many call sites to use it. The motivating reason for doing this is given here [0], we'd like to pass around more information about the position of debug-info in the iterator object. That necessitates passing iterators around most of the time. [0] https://discourse.llvm.org/t/rfc-instruction-api-changes-needed-to-eliminate-debug-intrinsics-from-ir/68939 Differential Revision: https://reviews.llvm.org/D152468
2023-08-13[LegacyPM] Drop unused includes in passes no longer supporting legacy PMBjorn Pettersson
2023-07-22[RewriteStatepointsForGC] Use poison instead of undef as placeholder [NFC]Nuno Lopes
This is used in shufflevectors where the placeholder arg is unused. It's also used when deleting invariant_start
2023-06-27[llvm] Move AttributeMask to a separate headerElliot Goodrich
Move `AttributeMask` out of `llvm/IR/Attributes.h` to a new file `llvm/IR/AttributeMask.h`. After doing this we can remove the `#include <bitset>` and `#include <set>` directives from `Attributes.h`. Since there are many headers including `Attributes.h`, but not needing the definition of `AttributeMask`, this causes unnecessary bloating of the translation units and slows down compilation. This commit adds in the include directive for `llvm/IR/AttributeMask.h` to the handful of source files that need to see the definition. This reduces the total number of preprocessing tokens across the LLVM source files in lib from (roughly) 1,917,509,187 to 1,902,982,273 - a reduction of ~0.76%. This should result in a small improvement in compilation time. Differential Revision: https://reviews.llvm.org/D153728
2023-06-11[Scalar] Remove RewriteStatepointsForGCLegacyPassKazu Hirata
Differential Revision: https://reviews.llvm.org/D152638
2023-04-16[Scalar] Use range-based for loops (NFC)Kazu Hirata
2023-03-15[llvm] Use *{Map,Set}::contains (NFC)Kazu Hirata
2023-03-14[Transforms] Use *{Set,Map}::contains (NFC)Kazu Hirata
2023-01-25[RS4GC] Remove the hardcoded GC strategy names (v2)Campbell Suter
Previously, RewriteStatepointsForGC had a hardcoded list of GC strategies for which it would run, and using it with a custom strategy required patching LLVM. The logic for selecting the variables that are considered managed was also hardcoded to use pointers in address space 1, rather than delegating to GCStrategy::isGCManagedPointer. This patch fixes both of these flaws: this pass now applies to all functions whose GCStrategy returns true for useStatepoints, and checking if a pointer is managed or not is also now done by the strategy. One potentially questionable design decision in this change: the pass will be enabled for all GC strategies that use statepoints. It seems unlikely this would be a problem - consumers that don't use this pass probably aren't adding it to the pass manager anyway - but if you had two different GC strategies and only one wants this pass enabled then that'd need a new flag in GCStrategy, which I can add if anyone thinks it's necessary. This is an updated version of D140458, rebased to account for LLVM's changes since D140504 (required by this patch) landed. Reviewed By: dantrushin Differential Revision: https://reviews.llvm.org/D141110