76 Commits

Author SHA1 Message Date
Vasileios Porpodas
25b90c4ef6 [SandboxVec][SeedCollector][NFC] Remove redundant 'else' and move the assertion within the 'if' 2025-01-10 14:54:44 -08:00
vporpo
9248428db7
[SandboxVec][DAG][NFC] Refactor setNextNode() and setPrevNode() (#122363)
This patch updates DAG's `setNextNode()` and `setPrevNode()` to update
both nodes of the link.
2025-01-10 13:32:33 -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
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
1be9827754
[SandboxVec][BottomUpVec] Implement packing of vectors (#116447)
Up until now we could only support packing of scalar elements. This
patch fixes this by implementing packing of vector elements, by
generating extractelement and insertelement instruction pairs.
2024-11-15 16:12:22 -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
7dffc96a54
[SandboxVec][BottomUpVec] Clean up dead instructions (#115267)
When scalars get replaced by vectors the original scalars may become
dead. In that case erase them.
2024-11-08 12:50:53 -08:00
Kazu Hirata
b02e5bc5b1
[Transforms] Remove unused includes (NFC) (#115263)
Identified with misc-include-cleaner.
2024-11-07 10:58:58 -08:00
Simon Pilgrim
490e58a98e Fix MSVC "not all control paths return a value" warning. NFC 2024-11-07 10:22:05 +00: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
11b768af3e [SandboxVec][BottomUpVec] Fix bug in invalidation of analyses
This makes sure we don't preserve analyses when we modify the IR.
This was causing errors in the EXPENSIVE_CHECKS build.
2024-11-05 18:01:31 -08:00
vporpo
320389d428
[SandboxVec][BottomUpVec] Generate vector instructions (#115087)
This patch implements some very basic code generation, for some opcodes.
2024-11-05 16:27:24 -08:00
vporpo
ce0d085842
[SandboxVec][Legality] Query the scheduler for legality (#114616)
This patch adds the legality check of whether the candidate instructions
can be scheduled together. This uses a Scheduler object.
2024-11-05 14:54:21 -08:00
vporpo
083369fd99
[SandboxVec][Legality] Per opcode checks (#114145)
This patch adds more opcode-specific legality checks.
2024-11-01 15:04:03 -07:00
vporpo
ca998b071e
[SandboxVec][Legality] Check wrap flags (#113975) 2024-10-29 15:37:03 -07:00
vporpo
a461869db3
[SandboxIR][Pass] Implement Analyses class (#113962)
The Analyses class provides a way to pass around commonly used Analyses
to SandboxIR passes throught `runOnFunction()` and `runOnRegion()`
functions.
2024-10-28 18:00:52 -07:00
vporpo
bf4b31ad54
[SandboxVec][Legality] Check Fastmath flags (#113967) 2024-10-28 15:32:20 -07:00
vporpo
5ea694816b
[SandboxVec][Legality] Check opcodes and types (#113741) 2024-10-28 14:05:58 -07:00
Vasileios Porpodas
1540f772c7 Reapply "[SandboxVec][Legality] Reject non-instructions (#113190)"
This reverts commit eb9f4756bc3daaa4b19f4f46521dc05180814de4.
2024-10-25 12:55:58 -07:00
Vasileios Porpodas
eb9f4756bc Revert "[SandboxVec][Legality] Reject non-instructions (#113190)"
This reverts commit 6c9bbbc818ae8a0d2849dbc1ebd84a220cc27d20.
2024-10-25 12:52:31 -07:00
vporpo
6c9bbbc818
[SandboxVec][Legality] Reject non-instructions (#113190) 2024-10-25 12:47:19 -07:00
Sterling-Augustine
f1be516223
[SandboxVectorizer] New class to actually collect and manage seeds (#113386)
This relands d91318b643188bb855f115b02af9532f87c787b7, with test-only
changes to make gcc-10 happy.
2024-10-23 10:26:18 -07:00
Sterling-Augustine
0de8de1b84
[SandboxVectorizer] revert New class to actually collect and manage s… (#113231)
…eeds (#112979)

This reverts commit d91318b643188bb855f115b02af9532f87c787b7.
2024-10-21 16:00:35 -07:00
Sterling-Augustine
d91318b643
[SandboxVectorizer] New class to actually collect and manage seeds (#112979)
There are many more tests to add, but I would like to get this reviewed
and the details sorted out before it grows too big.
2024-10-21 15:39:51 -07:00
vporpo
54c93aabec
[SandboxVec][Legality] Scaffolding for Legality (#112623)
This patch adds a LegalityResultWithReason class for describing the
reason why legality decided not to vectorize the code.
2024-10-21 09:17:46 -07:00
vporpo
1d09925b4a
[SandboxVec][Scheduler] Boilerplate and initial implementation. (#112449)
This patch implements a ready-list-based scheduler that operates on
DependencyGraph.
It is used by the sandbox vectorizer to test the legality of vectorizing
a group of instrs.

SchedBundle is a helper container, containing all DGNodes that
correspond to the instructions that we are attempting to schedule with
trySchedule(Instrs).
2024-10-18 16:18:43 -07:00
Sterling-Augustine
ec24e23d84
[SandboxVectorizer][NFC] Make SeedContainer dump follow preferred approach (#112634) 2024-10-16 17:06:23 -07:00
Jorge Gorbe Moya
2e8ad49e7c
[SandboxVec] Add pass to create Regions from metadata. Generalize SandboxVec pass pipelines. (#112288)
My previous attempt (#111904) hacked creation of Regions from metadata
into the bottom-up vectorizer. I got some feedback that it should be its
own pass. So now we have two SandboxIR function passes (`BottomUpVec`
and `RegionsFromMetadata`) that are interchangeable, and we could have
other SandboxIR function passes doing other kinds of transforms, so this
commit revamps pipeline creation and parsing.

First, `sandboxir::PassManager::setPassPipeline` now accepts pass
arguments in angle brackets. Pass arguments are arbitrary strings that
must be parsed by each pass, the only requirement is that nested angle
bracket pairs must be balanced, to allow for nested pipelines with more
arguments. For example:
```
    bottom-up-vec<region-pass-1,region-pass-2<arg>,region-pass-3>
```
This has complicated the parser a little bit (the loop over pipeline
characters now contains a small state machine), and we now have some new
test cases to exercise the new features.

The main SandboxVectorizerPass now contains a customizable pipeline of
SandboxIR function passes, defined by the `sbvec-passes` flag. Region
passes for the bottom-up vectorizer pass are now in pass arguments (like
in the example above).

Because we have now several classes that can build sub-pass pipelines,
I've moved the logic that interacts with PassRegistry.def into its own
files (PassBuilder.{h,cpp} so it can be easily reused.

Finally, I've added a `RegionsFromMetadata` function pass, which will
allow us to run region passes in isolation from lit tests without
relying on the bottom-up vectorizer, and a new lit test that does
exactly this.

Note that the new pipeline parser now allows empty pipelines. This is
useful for testing. For example, if we use
```
  -sbvec-passes="bottom-up-vec<>"
```
SandboxVectorizer converts LLVM IR to SandboxIR and runs the bottom-up
vectorizer, but no region passes afterwards.
```
  -sbvec-passes=""
```
SandboxVectorizer converts LLVM IR to SandboxIR and runs no passes on
it. This is useful to exercise SandboxIR conversion on its own.
2024-10-15 14:51:31 -07:00
Sterling-Augustine
b26c514b2c
[SandboxVectorizer] Add container class to track and manage SeedBundles (#112048) 2024-10-14 16:36:05 -07:00
vporpo
fc08ad6610
[SandboxVec][DAG] Implement UnscheduledSuccs (#112255)
This patch implements the UnscheduledSuccs counter in DGNode. It counts
the number of unscheduled successors and is used by the scheduler to
determine when a node is ready.
2024-10-14 16:23:22 -07:00
vporpo
08bfc9b0ae
[SandboxVec][DAG] Avoid unnecessary dependency scan and improve description (#112057)
When NewInterval is below DAGInterval we used to revisit instructions
already visited. This patch fixes this by separating the scan in two:
1. The full scan of the NewInterval, and
2. The cross-interval scan for DAGInterval.

This is further explained in the new description.
2024-10-14 12:50:21 -07:00
vporpo
31b85c6ead
[SandboxVec][Interval] Implement Interval::comesBefore() (#112026)
This patch implements `Interval::comesBefore(const Interval &Other)`
which returns true if this interval is strictly before Other in program
order. The function asserts that the intervals are disjoint.
2024-10-11 11:51:38 -07:00
vporpo
e8dd95e97b
[SandboxVec][DAG] Extend DAG (#111908)
This patch implements growing the DAG towards the top or bottom. This
does the necessary dependency checks and adds new mem dependencies.
2024-10-11 08:12:29 -07:00
vporpo
69c0067927
[SandboxVec][DAG] Refactoring: Outline code that looks for mem nodes (#111750) 2024-10-10 13:25:03 -07:00
vporpo
a4916d2005
[SandboxVec][DAG] Refactoring: Move MemPreds from DGNode to MemDGNode (#111897) 2024-10-10 12:42:28 -07:00
vporpo
747d8f3fc9
[SandboxVec][DAG] Implement PredIterator (#111604)
This patch implements an iterator for iterating over both use-def and
mem dependencies of MemDGNodes.
2024-10-10 12:01:56 -07:00
Jorge Gorbe Moya
756ec99c36
[SandboxVec] Re-land "Use sbvec-passes flag to create a pipeline of Region passes after BottomUpVec. (#111223)" (#111772)
https://github.com/llvm/llvm-project/pull/111223 was reverted because of
a build failure with `-DBUILD_SHARED_LIBS=on`.

The Passes component depends on Vectorizer (because PassBuilder needs to
be able to instantiate SandboxVectorizerPass). This resulted in CMake
doing this

1. when it builds lib/libLLVMVectorize.so.20.0git it adds
lib/libLLVMSandboxIR.so.20.0git to the command line, because it's listed
as a dependency (as expected)
2. when it's trying to build lib/libLLVMPasses.so.20.0git it adds
lib/libLLVMVectorize.so.20.0git to the command line, because it's listed
as a dependency (also as expected). But not libLLVMSandboxIR.so.

When SandboxVectorizerPass has its ctors/dtors defined inline, this
caused "undefined reference to vtable" linker errors. This change works
around that by moving ctors/dtors out of line.

Also fix a bazel build problem by adding the new
`llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def`
as a textual header in the Vectorizer target.
2024-10-09 18:00:17 -07:00
Jorge Gorbe Moya
102c384b57
Revert "[SandboxVectorizer] Use sbvec-passes flag to create a pipeline of Region passes after BottomUpVec." (#111727)
Reverts llvm/llvm-project#111223

It broke one of the build bots:

LLVM Buildbot has detected a new failure on builder flang-aarch64-libcxx
running on linaro-flang-aarch64-libcxx while building llvm at step 5
"build-unified-tree".

Full details are available at:
https://lab.llvm.org/buildbot/#/builders/89/builds/8127
2024-10-09 10:45:23 -07:00
Jorge Gorbe Moya
10ada4ae73
[SandboxVectorizer] Use sbvec-passes flag to create a pipeline of Region passes after BottomUpVec. (#111223)
The main change is that the main SandboxVectorizer pass no longer has a
pipeline of function passes. Now it is a wrapper that creates sandbox IR
from functions before calling BottomUpVec.

BottomUpVec now builds its own RegionPassManager from the `sbvec-passes`
flag, using a PassRegistry.def file. For now, these region passes are
not run (BottomUpVec doesn't create Regions yet), and only a null pass
for testing exists.

This commit also changes the ownership model for sandboxir::PassManager:
instead of having a PassRegistry that owns passes, and PassManagers that
contain non-owning pointers to the passes, now PassManager owns (via
unique pointers) the passes it contains.

PassRegistry is now deleted, and the logic to parse and create a pass
pipeline is now in PassManager::setPassPipeline.
2024-10-09 10:37:05 -07:00
vporpo
ee0e17a4d8
[SandboxVec][DAG] Drop RAR and fix dependency scanning loop (#111715) 2024-10-09 10:29:48 -07:00
Simon Pilgrim
00c1c589e0 DependencyGraph.cpp - mix MSVC "not all control paths return a value" warning. NFC. 2024-10-09 11:47:43 +01:00
Vasileios Porpodas
267e852109 [SandboxVec][DAG][NFC] Rename enumerators 2024-10-08 20:01:43 -07:00
vporpo
04a8bffdf7
[SandboxVec][DAG] Build actual dependencies (#111094)
This patch implements actual dependencies checking using BatchAA. This
adds memory dep edges between MemDGNodes.
2024-10-08 16:18:57 -07:00
Vasileios Porpodas
56d2c626f7 [SandboxVec][Interval] Add print() and dump() 2024-10-08 15:27:07 -07:00