summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Vectorize/SandboxVectorizer
AgeCommit message (Collapse)Author
2025-11-02[llvm] Remove "const" in the presence of "constexpr" (NFC) (#166109)Kazu Hirata
"const" is extraneous in the presence of "constexpr" for simple variables and arrays.
2025-08-22[SandboxVec][SeedCollector] Implement collection of seeds with different ↵vporpo
types (#146171) Up until now the seed collector could only collect seeds with the same element type. For example, `i32` and <2 x i32>`. This patch implements the collection of seeds with different types, like `i32` and `i8`.
2025-08-08[IR] Introduce the `ptrtoaddr` instructionAlexander Richardson
This introduces a new `ptrtoaddr` instruction which is similar to `ptrtoint` but has two differences: 1) Unlike `ptrtoint`, `ptrtoaddr` does not capture provenance 2) `ptrtoaddr` only extracts (and then extends/truncates) the low index-width bits of the pointer For most architectures, difference 2) does not matter since index (address) width and pointer representation width are the same, but this does make a difference for architectures that have pointers that aren't just plain integer addresses such as AMDGPU fat pointers or CHERI capabilities. This commit introduces textual and bitcode IR support as well as basic code generation, but optimization passes do not handle the new instruction yet so it may result in worse code than using ptrtoint. Follow-up changes will update capture tracking, etc. for the new instruction. RFC: https://discourse.llvm.org/t/clarifiying-the-semantics-of-ptrtoint/83987/54 Reviewed By: nikic Pull Request: https://github.com/llvm/llvm-project/pull/139357
2025-06-27[SandboxVec][SeedCollector][NFC] Replace cl::opt flags with constructor args ↵vporpo
(#143206) The `SeedCollector` class gets two new arguments: `CollectStores` and `CollectLoads`. These replace the `sbvec-collect-seeds` cl::opt flag. This is done to help with reusing the SeedCollector class in a future pass. The cl::opt flag is moved to the seed collection pass: Passes/SeedCollection.cpp
2025-06-10[llvm] annotate interfaces in llvm/Transforms for DLL export (#143413)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/Transforms` 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). The bulk 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 following manual adjustments were also applied after running IDS on Linux: - Removed a redundant `operator<<` from Attributor.h. IDS only auto-annotates the 1st declaration, and the 2nd declaration being un-annotated resulted in an "inconsistent linkage" error on Windows when building LLVM as a DLL. - `#include` the `VirtualFileSystem.h` in PGOInstrumentation.h and remove the local declaration of the `vfs::FileSystem` class. This is required because exporting the `PGOInstrumentationUse` constructor requires the class be fully defined because it is used by an argument. - Add #include "llvm/Support/Compiler.h" to files where it was not auto-added by IDS due to no pre-existing block of include statements. - Add `LLVM_TEMPLATE_ABI` and `LLVM_EXPORT_TEMPLATE` to exported instantiated templates. ## 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-06[SandboxVec][BottomUpVec] Fix ownership of Legality (#143018)vporpo
Fix the ownership of `Legality` member variable of BottomUpVec. It should get created in runOnFunction() and get destroyed when the function returns.
2025-06-05Reapply "[SandboxVec] Add a simple pack reuse pass (#141848)"Vasileios Porpodas
This reverts commit 31abf0774232735ad7a7d45e531497305bf99fae.
2025-06-04Revert "[SandboxVec] Add a simple pack reuse pass (#141848)"Vasileios Porpodas
This reverts commit 1268352656f81ea173860a8002aadb88844137e7.
2025-06-04[SandboxVec] Add a simple pack reuse pass (#141848)vporpo
This patch implements a simple pass that tries to de-duplicate packs. If there are two packing patterns inserting the exact same values in the exact same order, then we will keep the top-most one of them. Even though such patterns may be optimized away by subsequent passes it is still useful to do this within the vectorizer because otherwise the cost estimation may be off, making the vectorizer over conservative.
2025-05-28[SandboxVec] Add TransactionAlwaysRevert pass (#141688)vporpo
This patch adds a region pass that reverts the IR state unconditionally. This is used for testing.
2025-05-24[Transforms] Remove unused includes (NFC) (#141357)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-04-19[llvm] Use range-based for loops with llvm::drop_begin (NFC) (#136417)Kazu Hirata
2025-04-02[SandboxVec][NFC] Replace std::regex with llvm::Regex (#134110)vporpo
2025-03-29[SandboxVec] Add print-region pass (#131019)vporpo
This patch implements a simple printing pass for regions. This is meant to be used in tests and for debugging.
2025-03-27[Transforms] Use range constructors of *Set (NFC) (#133203)Kazu Hirata
2025-03-12[SandboxVec][SeedCollector][NFC] Fix typo in bannerVasileios Porpodas
2025-03-08[SandboxVec] Add region-from-bbs helper pass (#130153)vporpo
RegionFromBBs is a helper Sandbox IR function pass that builds a region for each BB. This helps test region passes in isolation without relying on other parts of the vectorizer, which is especially useful for stress-testing.
2025-03-03[NFC]Make file-local cl::opt global variables static (#126486)chrisPyr
#125983
2025-03-01[Vectorize] Fix unused variable warnings (NFC)Jie Fu
/llvm-project/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAcceptOrRevert.cpp:24:8: error: unused variable 'CostBefore' [-Werror,-Wunused-variable] auto CostBefore = SB.getBeforeCost(); ^ /llvm-project/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAcceptOrRevert.cpp:25:8: error: unused variable 'CostAfter' [-Werror,-Wunused-variable] auto CostAfter = SB.getAfterCost(); ^ 2 errors generated.
2025-02-28[SandboxVec][NFC] Add LLVM_DEBUG dumps (#129335)vporpo
This patch updates/adds LLVM_DEBUG dumps. It moves the DEBUG_TYPE into SandboxVectorizer/Debug.h such that it can be shared across all components of the vectorizer.
2025-02-28[SandboxVec][BottomUpVec] Fix vectorization of vector constants (#129290)vporpo
This patch fixes the value we generate when we vectorize constants.
2025-02-28[SandboxVec][BottomUpVec] Add -sbvec-stop-bndl flag for debugging (#129132)vporpo
This patch adds a helper flag for bisection debugging. This flag force-stops vectorization after this many bundles have been considered for vectorization. Using -sbvec-stop-bndl=0 will not vectorize the code at all.
2025-02-27[SandboxVec] Add option -sbvec-allow-file for bisection debugging (#129127)vporpo
This new option lets you specify an allow-list of source files and disables vectorization if the IR is not in the list. This can be used for debugging miscompiles.
2025-02-27[SandboxVec][BottomUpVec] Add -sbvec-stop-at flag for debugging (#129097)vporpo
When debugging miscompiles we need a way to force-stop the vectorizer early. This helps figure out which invocation is generating incorrect code.
2025-02-27[SandboxVec][Scheduler] Enforce scheduling SchedBundle instrs back-to-back ↵vporpo
(#128092) This patch fixes the behavior of the scheduler by making sure the instrs that are part of a SchedBundle are scheduled back-to-back.
2025-02-20[SandboxVec][Scheduler] Don't allow rescheduling of already scheduled (#128050)vporpo
This patch implements the check for not allowing re-scheduling of instructions that have already been scheduled in a scheduling bundle. Rescheduling should only happen if the instructions were temporarily scheduled in singleton bundles during a previous call to `trySchedule()`.
2025-02-20[SandboxVec][Scheduler] Fix reassignment of SchedBundle to DGNodeVasileios Porpodas
When assigning a bundle to a DAG Node that is already assigned to a SchedBundle we need to remove the node from the old bundle.
2025-02-20[SandboxVec][BottomUpVec] Separate vectorization decisions from code ↵vporpo
generation (#127727) Up until now the generation of vector instructions was taking place during the top-down post-order traversal of vectorizeRec(). The issue with this approach is that the vector instructions emitted during the traversal can be reordered by the scheduler, making it challenging to place them without breaking the def-before-uses rule. With this patch we separate the vectorization decisions (done in `vectorizeRec()`) from the code generation phase (`emitVectors()`). The vectorization decisions are stored in the `Actions` vector and are used by `emitVectors()` to drive code generation.
2025-02-18[SandboxVec][Scheduler] Don't insert scheduled instrs into the ready list ↵vporpo
(#127688) In a particular scenario (see test) we used to insert scheduled instructions into the ready list. This patch fixes this by fixing the trimSchedule() function.
2025-02-18[SandboxVec] Replace hard-coded context save() with transaction-save pass ↵vporpo
(#127690) This patch implements a small region pass that saves the context's state. The patch is now used in the default pipeline to save the context state instead of the hard-coded call to Context::save(). The concept behind this is that the passes themselves should not have to do the actual saving/restoring of the IR state, because that would make it challenging to reorder them in the pipeline. Having separate save/restore passes makes the transformation passes more composable as parts of arbitrary pipelines.
2025-02-18[SandboxVec] Move seed collection into its own separate pass (#127132)vporpo
This patch moves the seed collection logic from the BottomUpVec pass into a new Sandbox IR Function pass. The new "seed-collection" pass collects the seeds, builds a region and runs the region pass pipeline.
2025-02-18[SandboxVec][DAG] Implement DAG maintainance on Instruction removal (#127361)vporpo
This patch implements dependency maintenance upon receiveing the notification that an instruction gets deleted.
2025-02-14[SandboxVec][DAG] Update DAG whenever a Use is set (#127247)vporpo
This patch implements automatic DAG updating whenever a Use is set. This maintains the UnscheduledSuccs counter that the scheduler relies on.
2025-02-12[SandboxVec][DAG] Fix DAG when old interval is mem free (#126983)vporpo
This patch fixes a bug in `DependencyGraph::extend()` when the old interval contains no memory instructions. When this is the case we should do a full dependency scan of the new interval.
2025-02-12[SanbdoxVec][BottomUpVec] Fix diamond shuffle with multiple vector inputs ↵vporpo
(#126965) When the operand comes from multiple inputs then we need additional packing code. When the operands are scalar then we can use a single InsertElementInst. But when the operands are vectors then we need a chain of ExtractElementInst and InsertElementInst instructions to insert the vector value into the destination vector. This is what this patch implements.
2025-02-12[SandboxVec] Fix warnings introduced by 7a7f9190d03eVasileios Porpodas
2025-02-12[SandboxVec][Legality] Fix mask on diamond reuse with shuffle (#126963)vporpo
This patch fixes a bug in the creation of shuffle masks when vectorizing vectors in case of a diamond reuse with shuffle. The mask needs to enumerate all elements of a vector, not treat the original vector value as a single element. That is: if vectorizing two <2 x float> vectors into a <4 x float> the mask needs to have 4 indices, not just 2.
2025-02-12[SandboxVec][Scheduler] Fix top of schedule (#126820)vporpo
This patch fixes the way the top-of-schedule variable gets set and updated. Before this patch it used to get updated whenever we scheduled a bundle, which is wrong, as the top-of-schedule needs to be maintained across scheduling attempts. It should get reset only when we clear the schedule or when we destroy the current schedule and re-schedule.
2025-02-08[SandboxVec][BottomUpVec] Add cost estimation and tr-accept-or-revert pass ↵vporpo
(#126325) The TransactionAcceptOrRevert pass is the final pass in the Sandbox Vectorizer's default pass pipeline. It's job is to check the cost before/after vectorization and accept or revert the IR to its original state. Since we are now starting the transaction in BottomUpVec, tests that run a custom pipeline need to accept the transaction. This is done with the help of the TransactionAlwaysAccept pass (tr-accept).
2025-02-06[SandboxVec][Scheduler] Notify scheduler about instruction creation (#126141)vporpo
This patch implements the vectorizer's callback for getting notified about new instructions being created. This updates the scheduler state, which may involve removing dependent instructions from the ready list and update the "scheduled" flag. Since we need to remove elements from the ready list, this patch also implements the `remove()` operation.
2025-02-06[SandboxVec][DAG] Update DAG when a new instruction is created (#126124)vporpo
The DAG will now receive a callback whenever a new instruction is created and will update itself accordingly.
2025-02-06[SandboxVec][DependencyGraph] Fix dependency node iterators (#125616)vporpo
This patch fixes a bug in the dependency node iterators that would incorrectly not skip nodes that are not in the current DAG. This resulted in iterators returning nullptr when dereferenced. The fix is to update the existing "skip" function to not only skip non-instruction values but also to skip instructions not in the DAG.
2025-02-03[SandboxVec][Legality] Fix legality of SelectInst (#125005)vporpo
SelectInsts need special treatment because they are not always straightforward to vectorize. This patch disables vectorization unless they are trivially vectorizable.
2025-01-29[SandboxVec][Legality] Don't vectorize when instructions repeat (#124479)vporpo
This patch adds a legality check that checks for repeated instrs in a bundle and won't vectorize if such pattern is found.
2025-01-28[SandboxVec] Clear Context's state within runOnFunction() (#124842)vporpo
`sandboxir::Context` is defined at a pass-level scope with the `SandboxVectorizerPass` class because the function pass manager `FPM` object depends on it, and that is in pass-level scope to avoid recreating the pass pipeline every single time `runOnFunction()` is called. This means that the Context's state lives on across function passes. The problem is twofold: (i) the LLVM IR to Sandbox IR map can grow very large including objects from different functions, which is of no use to the vectorizer, as it's a function-level pass. (ii) this can result in stale data in the LLVM IR to Sandbox IR object map, as other passes may delete LLVM IR objects. To fix both issues this patch introduces a `Context::clear()` function that clears the `LLVMValueToValueMap`.
2025-01-27[SandboxIR] createFunction() should always create a function (#124665)vporpo
This patch removes the assertion that checks for an existing function. If one exists it will remove it and create a new one. This helps remove a crash when a function declaration object already exists and we are about to create a SandboxIR object for the definition.
2025-01-26[SandboxVec][DAG] Fix interval check without NodeVasileios Porpodas
This patch moves the check of whether a node exists before the check of whether it is contained in the interval.
2025-01-25[SandboxVec][DAG] Fix trim scheduleVasileios Porpodas
Fix trimSchedule by skipping instructions without a DAG Node.
2025-01-25[SandboxVec][Scheduler] Forbid crossing BBs (#124369)vporpo
This patch updates the scheduler to forbid scheduling across BBs. It should eventually be able to handle this, but we disable it for now.
2025-01-24[SandboxVec][Legality] Pack from different BBs (#124363)vporpo
When the inputs of the pack come from different BBs we need to make sure we emit the pack instructions at the correct place.