55 Commits

Author SHA1 Message Date
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
Sterling-Augustine
3f5039323c
[SandboxVectorizer][NFC] Remove unused include (#111418) 2024-10-07 11:47:00 -07:00
Sterling-Augustine
93bfa7886b
[SandboxVectorizer] Define SeedBundle: a set of instructions to be vectorized [retry] (#111073)
[Retry 110696 with a proper rebase.]

Seed collection will assemble instructions to be vectorized into
SeedBundles. This data structure is not intended to be used directly,
but will be the basis for load bundles, store bundles, and so on.
2024-10-07 11:20:50 -07:00
Vasileios Porpodas
45582ed240 [SandboxVec][DAG][NFC] Rename isMemDepCandidate() to isMemDepNodeCandidate() 2024-10-03 10:39:10 -07:00
vporpo
fd5e220fa6
[SandboxVec][DAG] MemDGNode for memory-dependency candidate nodes (#109684)
This patch implements the MemDGNode class for DAG nodes that are
candidates
for memory dependencies. These nodes form a chain that is accessible by
`getPrevNode()` and `getNextNode()`.

It also implements a builder class that creates MemDGNode intervals from
Instructions.
2024-10-01 15:40:54 -07:00
vporpo
e22b07e766
[SandboxIR][NFC] Move Function class to a separate file (#110526) 2024-09-30 10:12:47 -07:00
Vasileios Porpodas
2018f4ccf2 Reapply "[SandboxIR][NFC] Delete SandboxIR.h (#110309)"
This reverts commit 8dfeb4ef5d60a5c764f0ce249cc4ec69e012ff93.
2024-09-27 13:18:44 -07:00
Vasileios Porpodas
8dfeb4ef5d Revert "[SandboxIR][NFC] Delete SandboxIR.h (#110309)"
This reverts commit ca47f48a5c9e81ef8b5c4a5b1fbc473ea5d5497c.
2024-09-27 12:53:25 -07:00
vporpo
ca47f48a5c
[SandboxIR][NFC] Delete SandboxIR.h (#110309) 2024-09-27 12:20:08 -07:00
vporpo
eba106d461
[SandboxIR][NFC] Move Instruction classes into a separate file (#110294) 2024-09-27 10:54:11 -07:00
Jorge Gorbe Moya
9efc761d42
Reapply "[SandboxIR][NFC] Move Region from SandboxVectorizer to SandboxIR." (#110173) (#110181)
Re-applies llvm/llvm-project#110173 after fixing build break.
2024-09-26 18:12:31 -07:00
vporpo
3c66a51054
[SandboxVec][Interval] Convert InstrInterval class to a class template (#110021)
This patch converts InstrInterval class to a class template and renames
InstrInterval to Itnerval.

This change will allow us to reuse the Interval for dependency graph
nodes.
2024-09-26 17:47:25 -07:00
Jorge Gorbe Moya
74f276dd0f
Revert "[SandboxIR][NFC] Move Region from SandboxVectorizer to SandboxIR." (#110177)
Reverts llvm/llvm-project#110173. Missed an #include with the old path.
2024-09-26 14:56:19 -07:00
Jorge Gorbe Moya
3d9ed92630
[SandboxIR][NFC] Move Region from SandboxVectorizer to SandboxIR. (#110173)
I'm planning to add RegionPass and RegionPassManager next to the
equivalent FunctionPass and FunctionPassManager in SandboxIR, which
means that SandboxIR has to know about Regions.

There's nothing vectorizer-specific about the Region class, and the only
thing using Regions at this moment is the unit test, so this is a
straightforward file move.
2024-09-26 14:48:28 -07:00
Jorge Gorbe Moya
3bb92b530f
[SandboxVec] Tag insts in a Region with metadata. (#109353)
For each region, we create a metadata node. Then when an instruction is
added to the Region, it gets tagged with the metadata node for that
region. In the following example, we have a Region that contains only
the `%t0` instruction.

```
define i8 @foo(i8 %v0, i8 %v1) {
  %t0 = add i8 %v0, 1, !sbvec !0
  %t1 = add i8 %t0, %v1
  ret i8 %t1
}

!0 = distinct !{!"region"}
```

This commit also adds a function to create regions from metadata already
present in a Function.

This metadata can be used for debugging: if we dump IR before a Region
pass, the IR will contain enough info to re-create the Region and run
the pass by itself in a later invocation.

---------

Co-authored-by: Alina Sbirlea <alina.g.simion@gmail.com>
2024-09-23 16:59:02 -07:00
vporpo
0c9f7ef527
[SandboxVec][DAG] Implement extend(ArrayRef) (#109493)
This builds the DAG from an ArrayRef of Instructions.
2024-09-20 19:09:00 -07:00
Jorge Gorbe Moya
71e434d302
[SandboxVec] Reapply "Add barebones Region class. (#108899)" (#109059)
A `#ifndef NDEBUG` in the wrong place caused an error in release builds.
2024-09-18 11:36:45 -07:00
vporpo
42c5a301f5
[SandboxVec] Legality boilerplate (#108650)
This patch adds the basic API for the Legality component of the
vectorizer. It also adds some very basic code in the bottom-up
vectorizer that uses the API.
2024-09-17 17:06:29 -07:00
Jorge Gorbe Moya
aa2e6b8734
Revert "[SandboxVec] Add barebones Region class." (#109058)
Reverts llvm/llvm-project#108899

It broke the llvm-clang-x86_64-win-fast buildbot.
2024-09-17 15:47:30 -07:00
Jorge Gorbe Moya
3aecf41c2b
[SandboxVec] Add barebones Region class. (#108899)
A region identifies a set of vector instructions generated by
vectorization passes. The vectorizer can then run a series of
RegionPasses on the region, evaluate the cost, and commit/reject the
transforms on a region-by-region basis, instead of an entire basic
block.

This is heavily based ov @vporpo's prototype. In particular, the doc
comment for the Region class is all his. The rest of this commit is
mostly boilerplate around a SetVector: getters, iterators, and some
debug helpers.
2024-09-17 15:40:24 -07:00
vporpo
318d2f5e5d
[SandboxVec][DAG] Boilerplate (#108862)
This patch adds a very basic implementation of the Dependency Graph to
be used by the vectorizer.
2024-09-17 12:03:52 -07:00
vporpo
5130f3236f
[SandboxVec] User-defined pass pipeline (#108625)
This patch adds support for a user-defined pass-pipeline that overrides
the default pipeline of the vectorizer.
This will commonly be used by lit tests.
2024-09-13 13:14:06 -07:00