47 Commits

Author SHA1 Message Date
Philip Reames
f14224d92b
[RISCV] Rename schedule classes for vmv.s.x, vmv.x.s, vfmv.s.f, and vfmv.f.s [nfc] (#84563)
The prior naming scheme is incredibly hard to make sense out of. I
suspect the usage was actually backwards from intent - though that
didn't matter for any in tree schedule model.
2024-03-11 07:52:28 -07:00
Michael Maitland
be083dba95
[RISCV][NFC] Allow SchedVar to be a def inside our scheduler model files. (#82634)
All SchedModel files have a line that looks like:

```
def SomeModel : SchedMachineModel;
let SchedModel = SomeModel in {
  ...
}
```

TableGen requires that all records defined within the top level `let`
must have a field `SchedModel` somewhere in their nested record
hierarchy (i.e. the record has a field `SchedModel : SchedMachineModel`
or recursively, one of its members has a field `SchedModel :
SchedMachineModel`).

Classes such as `SchedPredicate` have added a field `SchedModel :
SchedMachineModel`, even though the field is never used, just to supress
**errors** (not warnings) caused from having the top level let in the
model files. This decision was made to avoid having hundreds of the same
`let` statement littered in every scheduler model file.

The reason we have never seen an error for `SchedVar` before is because
`SchedVar` is never instantiated with a `def`. Instead, it is only
created as a value that is consumed by `SchedWriteVariant`:

```
... : SchedWriteVariant<[SchedVar<...>, SchedVar<...>]>;
```

There is a problem with this style of instantiation. In particular, the
problem arises as we try to take a class based approach to building
scheduler models. I will describe the problem from the bottom up.

The `LMULWriteResMXVariant` multiclass takes in a `SchedPredicateBase
Pred`. Today, the RISCVSchedSiFive7.td file defines `VLDSX0Pred` outside
the scope of any class. That means that `VLDSX0Pred` exists before
`LMULWriteResMXVariant` multiclass is instantiated. With this approach,
there is no error since the predicate is instantated in entirety before
the variant multiclass is instantiated. However, I have the intention to
move the definition of both the predicate and the variant multiclass
records inside a multiclass to factor out common parts between multiple
scheduler models.

I plan to have something like:

```
multiclass SiFive7Base<SiFive7BaseConfig c> {
  def VLDSX0Pred : ...;
  // Need defvar since record is prefixed with NAME.
  defvar VLDSX0Pred = !cast<...>(NAME # VLDSX0Pred);
  defm SiFive7 : LMULWriteResMXVariant<VLDSX0Pred>;
}

defm "SiFive7Version1" : SiFive7Base<SiFive7BaseConfig<...>>;
defm "SiFive7Version2" : SiFive7Base<SiFive7BaseConfig<...>>;
```

In this scheme, VLDSX0Pred is defined within the same multiclass
transaction that the `LMULWriteResMXVariant` is defined in. For some
reason, TableGen does not allow `Values` to reference records that were
created in the same parent record construction. If the `SchedVar` is not
a `def`, then it will not be able to find the record `NAME #
VLDSX0Pred`. Making it a def, allows TableGen to find `NAME #
VLDSX0Pred` in scope.

The simplest example of this is:

```
class A {}
class B<A a> { A x = a;}
class C<B b> { B y = b;}
multiclass D {
  def MyA : A;
  defvar aa = !cast<A>(NAME # MyA);
  // This works
  def : B<aa>;
  // This does not work because constructing B by value cannot find `NAME # MyA`
  // error: Undefined reference to record: 'MyA'
  def : C<B<aa>>;
  // To fix it, define it like such:
  def MyB : B<aa>;
  defvar bb = !cast<B>(NAME # MyB);
  def : C<bb>;
}
defm "" : D;
```

In summary, in order to use a class based approach to creating scheduler
resources to promote resusability, `SchedVar`s must be created using
defs instead of being instantiated by value so that it can resolve
records that were part of the instantiation of the parent record being
created. In order to do this without refactoring the top level `let`
statement that all scheduler model files use, we add an unused field
`SchedModel : SchedMachineModel` to `SchedVar`, similiar to what has
been done in `SchedPredicate`.
2024-02-23 09:15:48 -05:00
Craig Topper
2a4f715b07
[RISCV] Adjust a few vector scheduler class names. NFC (#80795)
Shortening Iota to Iot seemed strange to me.

I also remove the M from VMIota and VMIdx. The instruction for viota
does have an m at the end of it, but vid.v does not. The M didn't seem
very important for viota.
2024-02-06 09:38:50 -08:00
Michael Maitland
d9570babf1
[RISCV] Remove SiFive7PipeV and replace it with SiFive7VCQ (#73969)
The Arithmetic, Load, and Store sequencers can accept instructions in
parallel. The PipeV blocked that from happening since it became busy if
any of the sequencers were busy. This change allows the sequencers to
accept instructions in parallel.

The VCQ accepts instructions from the the A Pipe and holds them until
the vector unit is ready to dequeue them. The unit dequeues up to one
instruction per cycle, in order, as soon as the sequencer for that type
of instruction is avaliable. This resource is meant to be used for 1
cycle by all vector instructions, to model that only one vector
instruction may be dequed at a time. The actual dequeueing into the
sequencer is modeled by the VA, VL, and VS sequencer resources below.
Each of them will only accept a single instruction at a time and remain
busy for the number of cycles associated with that instruction.
2023-12-04 17:21:02 -05:00
Michael Maitland
093bc6b61a
[RISCV] SiFive7 VLDS Sched should not depend on VL when stride is x0. (#70266)
When stride is x0, a strided load should behave like a unit stride load,
which uses the VLDE sched class.

---------

Co-authored-by: Wang Pengcheng <wangpengcheng.pp@bytedance.com>
2023-10-30 15:47:45 -04:00
Michael Maitland
3a602236c7 [RISCV] Add SchedRead for Merge operands on MASK Pseudos
For Pseudos that end in _MASK or should be forceMasked,
which means that in the case that the instruction should be
mask undisturbed the destination register must be read to
determine the undisturbed values. This patch adds a SchedRead
that gets passed to MASK pseudos to represent this extra read that
must occur.

A future patch should do something similiar for when a pseudo is TU,
since those instructions must also read their destination to preserve
undisturbed-ness.

Differential Revision: https://reviews.llvm.org/D155654
2023-07-26 10:57:07 -07:00
wangpc
69fc6bf631 [NFC][RISCV] Rewrite TableGen files using named arguments
To simplify code and show the usage of named arguments.

Reviewed By: michaelmaitland, MaskRay

Differential Revision: https://reviews.llvm.org/D154067
2023-07-20 17:17:49 +08:00
Craig Topper
d43ccffdc7 [RISCV] Split scheduler class for integer min/max reduction from other integer reductions. NFC
Our downstream needs to give different scheduling for min/max from
other reductions.

Reviewed By: michaelmaitland

Differential Revision: https://reviews.llvm.org/D155108
2023-07-12 12:58:01 -07:00
Michael Maitland
845ea71d0b [RISCV] Separate scheduler calsses for vfredmax/min
vfredmax/min may have different scheduling behavior on different
microarchitectures compared to other reductions. This different
behavior can be described by giving vfredmax/min separate
scheduling resources.

Differential Revision: https://reviews.llvm.org/D153450
2023-06-21 19:56:23 -07:00
Craig Topper
8dd28c5682 [RISCV] Split scheduler classes for vector min/max from compares.
Compares write a mask result. Min/max write a full result. This
makes them sufficiently different to have their own classes.

Reviewed By: pcwang-thead

Differential Revision: https://reviews.llvm.org/D152020
2023-06-06 22:25:22 -07:00
wangpc
78a2240172 [RISCV][NFC] Add isF argument to SchedSEWSet
So that we can remove `SchedSEWSetF` and simplify some code.

Reviewed By: michaelmaitland

Differential Revision: https://reviews.llvm.org/D151790
2023-06-01 12:44:49 +08:00
Michael Maitland
d70573b18e [RISCV][NFC] Make Reduction scheduler resources SEW aware
Create SchedWrites, WriteRes for reduction instructions that
are SEW specific. Future patches can use these resources
to customize the behavior of these resources depending on SEW.

Differential Revision: https://reviews.llvm.org/D151470
2023-05-30 07:27:25 -07:00
Nitin John Raj
4c6ae6e0aa [RISCV][NFC] Remove LMUL from vmv.s.x and vmv.x.s scheduler classes
These instructions don't read or write register groups. We only pretend they do in intrinsics and pseudoinstructions.

Differential Revision: https://reviews.llvm.org/D150238
2023-05-17 03:53:07 -07:00
Michael Maitland
1a855819a8 [RISCV] Add support for V extenstion in SiFive7
Add scheduling information for vector extension in SiFive7,
while using new LMUL & SEW scheduling constructs.

Differential Revision: https://reviews.llvm.org/D149495
2023-05-10 10:33:55 -07:00
wangpc
1c96847242 [RISCV] Remove SEW=8 case for floating-point
For floating-point instructions, SEW won't be 8. So we don't need
to generate scheduling resources for it.

Reviewed By: michaelmaitland

Differential Revision: https://reviews.llvm.org/D148317
2023-04-19 10:46:07 +08:00
Nitin John Raj
ff32671917 [RISCV][Tablegen] Remove LMUL from ReadVLDX, ReadVSTX, ReadVLDSX, ReadVSTSX scheduler classes
This read is for a gpr pointer, and doesn't need to be LMUL aware.

Differential Revision: https://reviews.llvm.org/D147799
2023-04-11 10:53:40 -07:00
Craig Topper
29463612d2 [RISCV] Replace RISCV -> RISC-V in comments. NFC
To be consistent with RISC-V branding guidelines
https://riscv.org/about/risc-v-branding-guidelines/
Think we should be using RISC-V where possible.

More patches will follow.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D146449
2023-03-27 09:50:17 -07:00
Michael Maitland
2e2093aa15 [RISCV] Remove UpperBound from SchedMxList and create WorstCaseBehavior records
Prior to this patch, UpperBound refered to the largest LMUL
supported. Instructions used UpperBound to assign the worst
case behaviour to records, since Instructions are not LMUL
specific. This forced the largest LMUL to have the worst case
behavior, even if that wasn't true for a subtarget.

Now that SchedWrites, SchedReads, WriteRes, and ReadAdvances
are created for (name, LMUL) pairs and (name, LMUL, SEW)
tuples, it becomes even less clear which pair should correspond
to the worst case behavior. Additionally, it no longer makes sense
for the UpperBound to belong to LMUL list and not to the SEW list.

Instead of creating a special UpperBound LMUL and an UpperBound
SEW, this patch renames UpperBound to WorstCaseBehavior, removes
it from the SchedMxList, and defines a WorstCaseBehavior SchedWrite,
SchedRead, WriteRes, and ReadAdvance for each name.

This gives subtargets the ability to describe the worst case behavior
of a record without forcing it to be the largest LMUL or the smallest
SEW.

Differential Revision: https://reviews.llvm.org/D146855
2023-03-27 06:46:14 -07:00
Michael Maitland
ad55f512e2 Revert "[RISCV] Remove UpperBound from SchedMxList and create WorstCaseBehavior records"
This reverts commit 74c0bd240499683078d4f15d31de690950da8231.
2023-03-27 06:26:51 -07:00
Michael Maitland
74c0bd2404 [RISCV] Remove UpperBound from SchedMxList and create WorstCaseBehavior records
Prior to this patch, UpperBound refered to the largest LMUL
supported. Instructions used UpperBound to assign the worst
case behaviour to records, since Instructions are not LMUL
specific. This forced the largest LMUL to have the worst case
behavior, even if that wasn't true for a subtarget.

Now that SchedWrites, SchedReads, WriteRes, and ReadAdvances
are created for (name, LMUL) pairs and (name, LMUL, SEW)
tuples, it becomes even less clear which pair should correspond
to the worst case behavior. Additionally, it no longer makes sense
for the UpperBound to belong to LMUL list and not to the SEW list.

Instead of creating a special UpperBound LMUL and an UpperBound
SEW, this patch renames UpperBound to WorstCaseBehavior, removes
it from the SchedMxList, and defines a WorstCaseBehavior SchedWrite,
SchedRead, WriteRes, and ReadAdvance for each name.

This gives subtargets the ability to describe the worst case behavior
of a record without forcing it to be the largest LMUL or the smallest
SEW.

Differential Revision: https://reviews.llvm.org/D146855
2023-03-27 06:06:55 -07:00
Nitin John Raj
7b39f16fb8 [RISCV] Made fsqrtv pseudoinstruction SEW-aware 2023-03-24 16:33:25 -07:00
Nitin John Raj
3cf7e35180 [RISCV] Made division pseudoinstructions SEW-aware 2023-03-24 16:33:24 -07:00
Nitin John Raj
5ab9ae12b7 [RISCV] Made vrgather.vv and vrgatherei16 pseudoinstructions SEW-aware 2023-03-24 16:33:24 -07:00
Nitin John Raj
a075ac05eb [RISCV] Made vcompress pseudoinstruction SEW-aware 2023-03-24 16:33:24 -07:00
Nitin John Raj
08be5e2537 [RISCV][NFC] Added possible SEWs associated with a given LMUL 2023-03-24 16:33:24 -07:00
Nitin John Raj
85e0d48a16 [RISCV][NFC] Broke ReadVRGatherVV into ReadVRGatherVV_data and ReadVRGatherVV_index to separate the reads for VRGatherVV
Differential Revision: https://reviews.llvm.org/D145406
2023-03-24 16:33:23 -07:00
Nitin John Raj
51e5846b56 [RISCV][NFC] Renamed [Read/Write]VGather* -> [Read/Write]VRGatherV*
Differential Revision: https://reviews.llvm.org/D145402
2023-03-24 16:33:23 -07:00
wangpc
3b1240ea76 [RISCV] Add classes to define SchedWrite list
SchedWrites are relevant to LMUL for most instructions, so we have
to enumerate all defined SchedWrites when defining ReadAdcance.
This patch adds some classes to simplify these definitions.

Reviewed By: michaelmaitland

Differential Revision: https://reviews.llvm.org/D145041
2023-03-07 17:54:05 +08:00
Philip Reames
04ed64e42f [RISCV][llvm-tblgen] Support conditional definitions using !exists clauses
The core part of this change is an extension to the tablegen language to allow conditional definition of records using if-statements based on !exists conditions.

The RISCV td file change is mostly to illustrate the potential use of conditional definitions. I am deliberately not maximally simplifying in this change to make merging with downstream code (or simply rebasing while this on review) easier.

Some background to make the change understandable.

TableGen does not have an if statement internally. It has if expressions - in the form of TernInitOp with IF opcode - and foreach statements. It implements an if-statement as a foreach which iterates either 0 or 1 times.

Foreach nodes are then evaluated via unrolling inside the parser. Specifically, they are evaluated, at latest, when the outermost multiclass or loop containing them reaches end of scope. The unrolled statements remain (potentially) unresolved after unrolling, but the number of iterations must be known at this point.

An !exists clause can only evaluate at final evaluation. (Specifically, forward references to definitions are allowed - up to the end of the containing scope at least.) The existing code did not set the final flag on the resolver, and thus would leave the !exists clause in an unresolved state. This would then cause an error since we don't know how many iterations on which to unroll the (synthetic) foreach loop.

I chose to only finally-evaluate the condition of the if-expression. This allows us to pick an arm at scope exit without inhibiting definitions in the arm from having self references.

Differential Revision: https://reviews.llvm.org/D145108
2023-03-03 11:29:47 -08:00
Philip Reames
27c3c6c4b0 [RISCV] Use !listremove for LMUL lists in V scheduling info [nfc]
Using listremove makes it easier to confirm that the code matches the comments.  The only in tree users of these lists are not order sensative.
2023-02-28 09:24:17 -08:00
Philip Reames
60f3703d1b [RISCV] Factor out multiclass definitions for V scheduling info [nfc]
Factoring out a shared multiclass imply makes it easier to see that all of these do the same thing, just on different lists. It also makes it easier to see differences - such as we don't define read related pieces for FWRed.

Differential Revision: https://reviews.llvm.org/D144899
2023-02-28 08:58:56 -08:00
Monk Chiang
781dedba30 [RISCV][CodeGen] Account for LMUL from VS2 for Vector Reduction Instructions
The Reduction instruction destination register LMUL is 1. But the source
register(vs2) has different LMUL(MF8 to M8). It's beneficial to know how
many registers are working on reduction instructions.
This patch creates separate SchedWrite for each relevant LMUL that from VS2.

Reviewed By: michaelmaitland

Differential Revision: https://reviews.llvm.org/D141565
2023-02-07 17:43:23 -08:00
Michael Maitland
7b36502854 [RISCV][CodeGen] Account for LMUL for Vector Integer load store instructions
It is likley that subtargets act differently for a vector load store instructions based on the LMUL.
This patch creates seperate SchedRead, SchedWrite, WriteRes, ReadAdvance for each relevant LMUL.

Differential Revision: https://reviews.llvm.org/D137429
2022-12-06 16:57:35 -08:00
Michael Maitland
1a43227ba5 [RISCV][CodeGen] Account for LMUL for Vector Permutation Instructions
It is likley that subtargets act differently for vector fixed-point arithmetic instructions
based on the LMUL. This patch creates seperate SchedRead, SchedWrite, WriteRes, ReadAdvance
for each relevant LMUL.

Differential Revision: https://reviews.llvm.org/D137428
2022-12-06 16:54:49 -08:00
Michael Maitland
e2b4425848 [RISCV][Codegen] Account for LMUL in Vector Mask instructions
It is likley that subtargets act differently for vector fixed-point arithmetic instructions based on the LMUL.
This patch creates seperate SchedRead, SchedWrite, WriteRes, ReadAdvance for each relevant LMUL.

Differential Revision: https://reviews.llvm.org/D137427
2022-12-06 06:48:42 -08:00
Michael Maitland
e9f2bac9a0 [RISCV][Codegen] Account for LMUL in Vector floating-point instructions
It is likley that subtargets act differently for vector floating-point instructions based on the LMUL.
This patch creates seperate SchedRead, SchedWrite, WriteRes, ReadAdvance for each relevant LMUL.

Differential Revision: https://reviews.llvm.org/D137426
2022-11-30 11:09:21 -08:00
wangpc
2b6910e12a [RISCV] Remove lmuls argument in Sched class
The original intention is adding a list of SchedWrites (which is a
default argument of ReadAdvance) to LMULReadAdvance, but it may not
be practical that there are two default arguments in one class. So
we add variants that are intended for widening and narrowing
instructions with postfix "W" and remove lmuls argument.

Reviewed By: michaelmaitland

Differential Revision: https://reviews.llvm.org/D138640
2022-11-30 16:16:22 +08:00
Michael Maitland
26e44d4aea [RISCV][CodeGen] Account for LMUL for Vector Fixed-Point Arithmetic Instructions
It is likley that subtargets act differently for vector fixed-point arithmetic instructions based on the LMUL.
This patch creates seperate SchedRead, SchedWrite, WriteRes, ReadAdvance for each relevant LMUL.

Differential Revision: https://reviews.llvm.org/D137342
2022-11-29 16:20:58 -08:00
Michael Maitland
184fbfd712 [RISCV][CodeGen] Chapter of vector instruction type corresponds with chapters in RISCV vector specification. NFC
The [vector spec](https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc) is organized in chapters
based on instruction type. The comments in the tablegen marked the incorrect chapters. This change
updates the comments with the correct chapter numbers.

Differential Revision: https://reviews.llvm.org/D138311
2022-11-18 10:30:08 -08:00
Michael Maitland
0eb2f663d2 [RISCV][CodeGen] Account for LMUL for Vector Integer Arithmetic Instructions
It is likley that subtargets act differently for a vector integer arithmetic instruction based on the LMUL.
This patch creates seperate SchedRead, SchedWrite, WriteRes, ReadAdvance for each relevant LMUL. It also
introduces the concept of an "UpperBound LMUL" which allows us to describe how an instruction should behave
when the LMUL is unknown. All base instructions use the UpperBound resources because they are not tied to
a specific LMUL. This gives subtargetes the flexibility to describe their own upper bounds on each vector
instruction.

I have a series of patches for the rest of the vector instruction set ready to go, but I would like to first
get feedback on the first one of the series (this one).

Differential Revision: https://reviews.llvm.org/D136730
2022-11-03 09:18:42 -07:00
Craig Topper
c66426f3a0 [RISCV] Remove EEW from some sched classes.
This removes the EEW from unit stride load/store and whole register
load, store, move.

It seems reasonable that implementations of these instructions wouldn't
usually be affected by element width.

We likely need to add LMUL information to our scheduling classes so
I thought it might be good to remove a few before they got multiplied
by LMUL.

Reviewed By: reames, michaelmaitland

Differential Revision: https://reviews.llvm.org/D135992
2022-10-20 08:23:22 -07:00
Craig Topper
1fab0ac559 [RISCV] Rename ReadVIALUCV->ReadVICALUV to match WriteVICALUV. NFC 2022-10-14 12:11:55 -07:00
Craig Topper
902c1b3c2f [RISCV] Remove unused SchedClass WriteVFCvtFToFV. NFC
This isn't bound to any instruction. From the section comment it
was for single-width F-to-F conversions, but those don't exist.
2022-10-11 16:26:06 -07:00
Michael Maitland
fbf8aa1b49 [RISCV][CodeGen] Add Scheduling for vset{i}vl{i} instruction
Differential Revision: https://reviews.llvm.org/D135188
2022-10-05 07:54:22 -07:00
Craig Topper
2e5c516a3d [RISCV] Add scheduler class to PseudoReadVLENB.
Reviewed By: monkchiang

Differential Revision: https://reviews.llvm.org/D130938
2022-08-02 09:38:32 -07:00
Monk Chiang
2b045324b2 [RISCV] Add scheduling resources for vector segment instructions.
Add scheduling resources for vector segment instructions

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D128886
2022-07-12 22:51:58 -07:00
Evandro Menezes
63a5ac4e0d [RISCV] Add scheduling resources for V
Add the scheduling resources for the V extension instructions.

Differential Revision: https://reviews.llvm.org/D98002
2021-08-03 15:47:51 -05:00