98 Commits

Author SHA1 Message Date
vporpo
1eacdddc0c
[SandboxVec][SeedCollector][NFC] Replace cl::opt flags with constructor args (#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-27 12:27:25 -07:00
Matt Arsenault
c91cbafad2
TargetLibraryInfo: Delete default TargetLibraryInfoImpl constructor (#145826)
It should not be possible to construct one without a triple. It would
also be nice to delete TargetLibraryInfoWrapperPass, but that is more
difficult.
2025-06-26 16:12:36 +09:00
Vasileios Porpodas
79861d2db7 Reapply "[SandboxVec] Add a simple pack reuse pass (#141848)"
This reverts commit 31abf0774232735ad7a7d45e531497305bf99fae.
2025-06-05 09:14:17 -07:00
Vasileios Porpodas
31abf07742 Revert "[SandboxVec] Add a simple pack reuse pass (#141848)"
This reverts commit 1268352656f81ea173860a8002aadb88844137e7.
2025-06-04 14:24:49 -07:00
vporpo
1268352656
[SandboxVec] Add a simple pack reuse pass (#141848)
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-06-04 14:12:06 -07:00
Kazu Hirata
e9487fed29
[llvm] Construct SmallVector with iterator ranges (NFC) (#136460) 2025-04-19 19:07:10 -07:00
Vasileios Porpodas
ead7b7be09 [SandboxVec] Fix unused variables warnings 2025-02-27 10:38:31 -08:00
vporpo
e2b0d5df84
[SandboxVec][Scheduler] Enforce scheduling SchedBundle instrs back-to-back (#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-27 10:23:50 -08:00
vporpo
4d92975b5c
[SandboxVec][Scheduler] Don't allow rescheduling of already scheduled (#128050)
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 16:16:34 -08:00
Vasileios Porpodas
2ff80d2448 [SandboxVec][Scheduler] Fix reassignment of SchedBundle to DGNode
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 15:28:16 -08:00
Vasileios Porpodas
a1a10732e4 [SandboxVec][DAG] Remove all matching nodes from bundle
This fixes a bug where `SchedBundle::eraseFromBundle()` would not erase all
matching nodes but just the first one.
2025-02-20 15:13:52 -08:00
vporpo
10b99e97ff
[SandboxVec][BottomUpVec] Separate vectorization decisions from code 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-20 10:21:25 -08:00
Vasileios Porpodas
e10ac5fc71 [SandboxVec][NFC] Fix unused variable warning in test 2025-02-18 16:49:09 -08:00
vporpo
0cc7381543
[SandboxVec][Scheduler] Don't insert scheduled instrs into the ready list (#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 16:17:46 -08:00
vporpo
426148b269
[SandboxVec][DAG] Implement DAG maintainance on Instruction removal (#127361)
This patch implements dependency maintenance upon receiveing the
notification that an instruction gets deleted.
2025-02-18 10:59:31 -08:00
vporpo
3e3af861b4
[SandboxVec][DAG] Add MemDGNode::MemSuccs (#127253)
This patch adds Memory successors to the memory nodes of the DAG. This
will help maintain the memory dependencies when nodes get removed.
2025-02-15 17:09:51 -08:00
vporpo
48c92dda00
[SandboxVec][DAG] Update DAG whenever a Use is set (#127247)
This patch implements automatic DAG updating whenever a Use is set. This
maintains the UnscheduledSuccs counter that the scheduler relies on.
2025-02-14 11:58:31 -08:00
vporpo
1c207f1b6e
[SandboxVec][DAG] Fix DAG when old interval is mem free (#126983)
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 15:06:30 -08:00
vporpo
7a7f9190d0
[SandboxVec][Legality] Fix mask on diamond reuse with shuffle (#126963)
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 12:29:09 -08:00
vporpo
07600f80c7
[SandboxVec][Scheduler] Update ready list comparator (#126160)
This patch implements a hierarchical comparator for the ready list. PHIs
have higher priority than non-phis and terminators are always last.
2025-02-11 13:52:02 -08:00
vporpo
a0d86b23c0
[SandboxVec][Scheduler] Notify scheduler about instruction creation (#126141)
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 15:45:44 -08:00
vporpo
166b2e8837
[SandboxVec][DAG] Update DAG when a new instruction is created (#126124)
The DAG will now receive a callback whenever a new instruction is
created and will update itself accordingly.
2025-02-06 14:12:03 -08:00
vporpo
788c88e2f6
[SandboxVec][DependencyGraph] Fix dependency node iterators (#125616)
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-06 12:30:49 -08:00
vporpo
c5f99e1bd4
[SandboxVec][Legality] Fix legality of SelectInst (#125005)
SelectInsts need special treatment because they are not always
straightforward to vectorize. This patch disables vectorization unless
they are trivially vectorizable.
2025-02-03 17:33:09 -08:00
vporpo
e094c0fa67
[SandboxVec][Legality] Don't vectorize when instructions repeat (#124479)
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-29 15:54:15 -08:00
vporpo
79cbad188a
[SandboxVec] Clear Context's state within runOnFunction() (#124842)
`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-28 18:28:08 -08:00
vporpo
5cb2db3b51
[SandboxVec][Scheduler] Forbid crossing BBs (#124369)
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-25 08:19:27 -08:00
vporpo
6409799bdc
[SandboxVec][Legality] Pack from different BBs (#124363)
When the inputs of the pack come from different BBs we need to make sure
we emit the pack instructions at the correct place.
2025-01-24 15:39:37 -08:00
vporpo
ac75d32280
[SandboxVec][VecUtils] Filter out instructions not in BB in VecUtils:getLowest() (#124360)
This patch changes the functionality of `VecUtils::getLowest(Vals, BB)`
such that it filters out any instructions in `Vals` that are not in BB.
This is useful when Vals contains instructions from different BBs,
because in that case we are only interested in one BB.
2025-01-24 14:52:57 -08:00
vporpo
b41987beae
[SandboxVec][DAG] Fix MemDGNode chain maintenance when move destination is non-mem (#124227)
This patch fixes a bug in the maintenance of the MemDGNode chain of the
DAG. Whenever we move a memory instruction, the DAG gets notified about
the move and maintains the chain of memory nodes. The bug was that if
the destination of the move was not a memory instruction, then the
memory node's next node would end up pointing to itself.
2025-01-24 13:59:32 -08:00
vporpo
d2234ca163
[SandboxVec][BottomUpVec] Fix packing when PHIs are present (#124206)
Before this patch we might have emitted pack instructions in between PHI
nodes. This patch fixes it by fixing the insert point of the new packs.
2025-01-23 16:29:01 -08:00
vporpo
2dc1c95595
[SandboxVec][VecUtils] Implement VecUtils::getLowest() (#124024)
VecUtils::getLowest(Valse) returns the lowest instruction in the BB among Vals.
If the instructions are not in the same BB, or if none of them is an
instruction it returns nullptr.
2025-01-22 16:08:15 -08:00
vporpo
87e4b68195
[SandboxVec][Legality] Implement ShuffleMask (#123404)
This patch implements a helper ShuffleMask data structure that helps
describe shuffles of elements across lanes.
2025-01-17 15:48:24 -08:00
Kazu Hirata
358d65463b [SandboxVectorizer] Fix a warning
This patch fixes:

  third-party/unittest/googletest/include/gtest/gtest.h:1379:11:
  error: comparison of integers of different signs: 'const unsigned
  int' and 'const int' [-Werror,-Wsign-compare]
2025-01-17 14:06:15 -08:00
vporpo
d6315afff0
[SandboxVec][InstrMaps] EraseInstr callback (#123256)
This patch hooks up InstrMaps to the Sandbox IR callbacks such that it
gets updated when instructions get erased.
2025-01-17 13:36:42 -08:00
Kazu Hirata
13c7617897 [Vectorize] Fix warnings
This patch fixes:

  third-party/unittest/googletest/include/gtest/gtest.h:1379:11:
  error: comparison of integers of different signs: 'const unsigned
  int' and 'const int' [-Werror,-Wsign-compare]

  llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/InstrMaps.h:57:12:
  error: unused variable 'Pair' [-Werror,-Wunused-variable]
2025-01-16 15:45:59 -08:00
vporpo
e902c6960c
[SandboxVec][BottomUpVec] Implement InstrMaps (#122848)
InstrMaps is a helper data structure that maps scalars to vectors and
the reverse. This is used by the vectorizer to figure out which vectors
it can extract scalar values from.
2025-01-16 15:26:35 -08:00
vporpo
6312beef78
[SandboxVec][BottomUpVec] Use SeedCollector and slice seeds (#120826)
With this patch we switch from the temporary dummy seeds to actual seeds
provided by the seed collector.
The seeds get sliced and each slice is used as the starting point for
vectorization.
2025-01-09 11:53:48 -08:00
vporpo
7a38445ee2
[SandboxVec][DAG] Register move instr callback (#120146)
This patch implements the move instruction notifier for the DAG.
Whenever an instruction moves the notifier will maintain the DAG.
2024-12-20 23:10:24 -08:00
vporpo
3769fcb3e7
[SandboxVec][Interval] Implement Interval::notifyMoveInstr() (#119471)
This patch implements the notifier for Instruction intervals. It updates
the interval's top/bottom.
2024-12-16 12:59:24 -08:00
vporpo
cafb6b99bb
[SandboxVec][DAG] Update MemDGNode chain upon instr deletion (#118921) 2024-12-10 15:10:45 -08:00
vporpo
eeb55d3af6
[SandboxVec][DAG] Update MemDGNode chain upon instr creation (#116896)
The DAG maintains a chain of MemDGNodes that links together all the
nodes that may touch memroy.
Whenever a new instruction gets created we need to make sure that this
chain gets updated. If the new instruction touches memory then its
corresponding MemDGNode should be inserted into the chain.
2024-12-05 20:23:06 -08:00
Sterling-Augustine
c0ee8e22f4
[SandboxVec][SeedCollector] Reject non-simple memory ops for memory seeds (#116891)
Load/Store isSimple is a necessary condition for VectorSeeds, but not
sufficient, so reverse the condition and return value, and continue the
check. Add relevant tests.
2024-11-20 11:53:41 -08:00
vporpo
6e4821487f
[SandboxVec][DAG] Register callback for erase instr (#116742)
This patch adds the callback registration logic in the DAG's constructor
and the corresponding deregistration logic in the destructor. It also
implements the code that makes sure that SchedBundle and DGNodes can be
safely destroyed in any order.
2024-11-19 16:20:38 -08:00
vporpo
31a4d2c2eb
[SandboxVec][DAG] Cleanup: Move callback registration from Scheduler to DAG (#116455)
This is a refactoring patch that moves the callback registration for
getting notified about new instructions from the scheduler to the DAG.
This makes sense from a design and testing point of view:
- the DAG should not rely on the scheduler for getting notified
- the notifiers don't need to be public
- it's easier to test the notifiers directly from within the DAG unit
tests
2024-11-18 20:23:10 -08:00
vporpo
3be3b33e57
[SandboxVec][BottomUpVec] Implement pack of scalars (#115549)
This patch implements packing of scalar operands when the vectorizer
decides to stop vectorizing. Packing is implemented with a sequence of
InsertElement instructions.

Packing vectors requires different instructions so it's implemented in a
follow-up patch.
2024-11-15 14:45:17 -08:00
Sterling-Augustine
7ba864b592
[SandboxVectorizer] Register erase callback for seed collection (#115951) 2024-11-12 16:03:27 -08:00
vporpo
f7ef7b2ff7
[SandboxVec][Scheduler] Implement rescheduling (#115220)
This patch adds support for re-scheduling already scheduled
instructions. For now this will clear and rebuild the DAG, and will
reschedule the code using the new DAG.
2024-11-06 20:59:49 -08:00
vporpo
5942a99f8b
[SandboxVec] Notify scheduler about new instructions (#115102)
This patch registers the "createInstr" callback that notifies the
scheduler about newly created instructions. This guarantees that all
newly created instructions have a corresponding DAG node associated with
them. Without this the pass crashes when the scheduler encounters the
newly created vector instructions.

This patch also changes the lifetime of the sandboxir Ctx variable in
the SandboxVectorizer pass. It needs to be destroyed after the passes
get destroyed. Without this change when components like the Scheduler
get destroyed Ctx will have already been freed, which is not legal.
2024-11-06 13:26:14 -08:00
Vasileios Porpodas
d047488d4c [SandboxVec] Fix build warnings in VecUtilsTest 2024-11-05 16:38:38 -08:00