5345 Commits

Author SHA1 Message Date
Kazu Hirata
b595eb83e5 [llvm] Use *{Set,Map}::contains (NFC) 2023-03-14 18:56:07 -07:00
NAKAMURA Takumi
59fe64ae47 Let IntrinsicEmitter free from CodeGenTarget.h
For now, I have introduced `llvm::tmp::getValueType(Rec)` as a copy from
`CodeGenTarget.cpp`. This will be removed in the near future, when
IntrinsicEmitter will not depend on MVT.

Differential Revision: https://reviews.llvm.org/D143844
2023-03-15 08:09:44 +09:00
NAKAMURA Takumi
fe7b38cb6b llvm-tblgen: Split out CodeGenIntrinsics.cpp from CodeGenTarget.cpp
Differential Revision: https://reviews.llvm.org/D143844
2023-03-15 08:09:35 +09:00
Craig Topper
81a150656b [TableGen][RISCV][Hexagon][LoongArch] Add a list of Predicates to HwMode.
Use the predicate condition instead of checkFeatures in *GenDAGISel.inc.

This makes the code similar to isel pattern predicates.

checkFeatures is still used by code created by SubtargetEmitter so
we can't remove the string. Backends need to be careful to keep
the string and predicates in sync, but I don't think that's a big issue.

I haven't measured it, but this should be a compile time improvement
for isel since we don't have to do any of the string processing that's
inside checkFeatures.

Reviewed By: kparzysz

Differential Revision: https://reviews.llvm.org/D146012
2023-03-14 13:00:38 -07:00
Jakub Kuderski
b9db89fbcf [ADT][NFCI] Do not use non-const lvalue-refs with enumerate in llvm/
Replace references to `enumerate` results with either const lvalue
rerences or structured bindings. I did not use structured bindings
everywhere as it wasn't clear to me it would improve readability.

This is in preparation to the switch to `zip` semantics which won't
support non-const lvalue reference to elements:
https://reviews.llvm.org/D144503.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D145987
2023-03-13 20:59:06 -04:00
David Spickett
78d91e4452 [llvm][TableGen][Jupyter] Correct notebook name in example command 2023-03-09 09:14:13 +00:00
James Y Knight
b87dc35669 [TableGen] Delete support for deprecated positional matching.
After the work in a538d1f13a13 5351878ba196 372240dfe3d5, and
subsequently cleanup of all the in-tree targets, we can now delete the
support for positional operand matching!

This removes three options which could previously be set in a
Target's "InstrInfo" tablegen definition:
- useDeprecatedPositionallyEncodedOperands
- decodePositionallyEncodedOperands
- noNamedPositionallyEncodedOperands

(Also announced at https://discourse.llvm.org/t/tablegen-deleting-deprecated-positional-instruction-operand-matching-support/68524)

Differential Revision: https://reviews.llvm.org/D144210
2023-03-07 15:04:09 -05:00
Sander de Smalen
170e7a0ec2 [AArch64][SME2] Add CodeGen support for target("aarch64.svcount").
This patch adds AArch64 CodeGen support such that the type can be passed
and returned to/from functions, and also adds support to use this type in
load/store operations and PHI nodes.

Reviewed By: paulwalker-arm

Differential Revision: https://reviews.llvm.org/D136862
2023-03-02 12:07:41 +00:00
Craig Topper
f69baa419a [TableGen] Minor tweak to AssemblerCondDag evaluation to be more consistent with other dags. NFC
Instead of using getAsString on the dag operator, check if the operator
is a DefInit and then get the name of the Def.
2023-02-28 21:26:57 -08:00
Craig Topper
17c31fba5b [TableGen] Replace a StringMap keyed by Record name with a DenseMap.
We can use the Record* to uniquely identify the Record without using
its name.
2023-02-27 22:54:03 -08:00
Craig Topper
0a341a1eda [TableGen] Use raw_svector_ostream and ListSeparator to simplify some code. NFC 2023-02-26 19:36:34 -08:00
Craig Topper
8869f301c5 [TableGen] Remove duplicate call to getPredicateCheck. NFC 2023-02-26 16:32:25 -08:00
Michael Liao
e80d2cad34 [TableGen] Emit static const globals in getOperandType
- That saves the overhead of operand type querying.
2023-02-22 03:56:55 -05:00
NAKAMURA Takumi
c1bd1eed8e Rework "llvm-tblgen: Anonymize some functions.", llvmorg-17-init-2668-gc45e90cf152d
Anonymous namespace should be applied only to class definitions.
2023-02-20 23:20:43 +09:00
Kazu Hirata
f8f3db2756 Use APInt::count{l,r}_{zero,one} (NFC) 2023-02-19 22:04:47 -08:00
Kai Luo
fd766ba2b1 [GISelEmitter][NFC] Correct path of GISel's td file in the comment.
`include/llvm/CodeGen/TargetGlobalISel.td` no longer exists.
2023-02-20 10:08:01 +08:00
Kazu Hirata
cbde2124f1 Use APInt::popcount instead of APInt::countPopulation (NFC)
This is for consistency with the C++20-style bit manipulation
functions in <bit>.
2023-02-19 11:29:12 -08:00
NAKAMURA Takumi
c45e90cf15 llvm-tblgen: Anonymize some functions. 2023-02-19 14:44:56 +09:00
NAKAMURA Takumi
aeafcbcd75 llvm-tblgen: Add "TableGenBackends.h" to each emitter.
"TableGenBackends.h" has declarations of emitters.
2023-02-19 03:06:32 +09:00
NAKAMURA Takumi
b3405ace95 llvm-tblgen: Add missing includes 2023-02-19 03:06:31 +09:00
NAKAMURA Takumi
655f4cb0e4 llvm-tblgen: Reformat 2023-02-19 03:06:31 +09:00
NAKAMURA Takumi
afde3f549d llvm-tblgen: Apply IWYU partially 2023-02-17 00:32:46 +09:00
Kazu Hirata
7e6e636fb6 Use llvm::has_single_bit<uint32_t> (NFC)
This patch replaces isPowerOf2_32 with llvm::has_single_bit<uint32_t>
where the argument is wider than uint32_t.
2023-02-15 22:17:27 -08:00
David Spickett
fdd18e866b [llvm][TableGen][Jupyter] Show llvm-tblgen not found error in notebook
Previously this message was only shown on the command line,
which is not much help if you can't see that.
(you've full screened the browser or you aren't running Jupyter
on the same machine)

Instead return the error as stderr which will get printed in
the notebook just like stderr from llvm-tblgen would.

I've refactored the message sending along the way. Note that
even when we do not send a stream, we still need to send the
status reply. The send_... methods will do that for you.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D142531
2023-02-13 09:26:48 +00:00
NAKAMURA Takumi
bb5f79158b llvm-tblgen: Apply IWYU in some files 2023-02-12 20:49:08 +09:00
NAKAMURA Takumi
2d570bab4f CodeGenTarget.cpp: Reformat. 2023-02-12 20:49:07 +09:00
NAKAMURA Takumi
f00d101b8e llvm/utils/TableGen/CodeGenIntrinsics.h: Fix a comment line (since 2006!) 2023-02-12 03:33:56 +09:00
NAKAMURA Takumi
2e08e431cc LLVMTableGenGlobalISel: Provide INTERFACE_INCLUDE_DIRECTORIES
Its user may include its headers as `GlobalISel/*.h`
2023-02-12 03:06:00 +09:00
Pierre van Houtryve
70924673af [RFC][GISel] Add a way to ignore COPY instructions in InstructionSelector
RFC to add a way to ignore COPY instructions when pattern-matching MIR in GISel.
    - Add a new "GISelFlags" class to TableGen. Both `Pattern`  and `PatFrags` defs can use it to alter matching behaviour.
    - Flags start at zero and are scoped: the setter returns a `SaveAndRestore` object so that when the current scope ends, the flags are restored to their previous values. This allows child patterns to modify the flags without affecting the parent pattern.
    - Child patterns always reuse the parent's pattern, but they can override its values. For more examples, see `GlobalISelEmitterFlags.td` tests.
    - [AMDGPU] Use the IgnoreCopies flag in BFI patterns, which are known to be bothered by cross-regbank copies.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D136234
2023-02-10 08:37:42 +01:00
Remi Segard
cfba328183 [GlobalISel] Enable patterns with multiple output operands for the GlobalISelEmitter
This enables writing patterns with mutliple output operands in the input pattern for GlobalISel
2023-02-04 10:08:32 -04:00
Sergei Barannikov
a7fbca4080 [NFC] Extract CodeGenInstAlias into its own *.h/*.cpp
Differential Revision: https://reviews.llvm.org/D142968
2023-02-01 05:23:43 +03:00
David Spickett
6bc9b15e69 [llvm][TableGen][Jupyter] Add notebook links to README
This folder contains the kernel and notebooks
so let's make that obvious and list them in the
readme.
2023-01-26 13:57:05 +00:00
David Spickett
232a27b1bf [LLVM][TableGen] Notebook describing how to write a Python backend
This tutorial uses the dump json option to write a backend for
SQL queries.

It is based on the work of Min-Yih Hsu:
* https://github.com/mshockwave/SQLGen
* https://www.youtube.com/watch?v=UP-LBRbvI_U

I hope that having the same concepts in 3 forms will allow people
to choose the style that fits them.

The main drawback here being that it's in Python. C++ can be used
in a notebook (https://github.com/jupyter-xeus/xeus-cling) but I
decided against it for a few reasons:

* Python is the default for Jupyter, no extra installs needed.
* Having the code in a second language may help people who
  know one or the other.
* There is no upstream example of a JSON powered backend.
  (and although we would be unlikely to accept one upstream,
  I think it's a great option for quick development before
  translating into C++)

Reviewed By: myhsu

Differential Revision: https://reviews.llvm.org/D142364
2023-01-26 12:29:53 +00:00
Jay Foad
0572db093d [TableGen] Speed up computeUberSets. NFC.
Differential Revision: https://reviews.llvm.org/D142472
2023-01-25 13:43:00 +00:00
Min-Yih Hsu
36c19eae27 [TableGen] Support custom decoders for variable length instructions
Just like the encoder directive for variable-length instructions, this
patch adds a new decoder directive to allow custom decoder function on
an operand.

Right now, due to the design of DecoderEmitter each operand can only
have a single custom decoder in a given instruction.

Differential Revision: https://reviews.llvm.org/D142079
2023-01-24 21:59:24 -08:00
Jay Foad
96f49905de [MC] Store target Insts table in reverse order. NFC.
This will allow an entry in the table to access data that is stored
immediately after the end of the table, by adding its opcode value
to its address.

Differential Revision: https://reviews.llvm.org/D142217
2023-01-24 21:42:13 +00:00
Jay Foad
d8ce50e3c2 [MC] Store number of implicit operands in MCInstrDesc. NFC.
Combine the implicit uses and defs lists into a single list of uses
followed by defs. Instead of 0-terminating the list, store the number
of uses and defs. This avoids having to scan the whole list to find the
length and removes one pointer from MCInstrDesc (although it does not
get any smaller due to alignment issues).

Remove the old accessor methods getImplicitUses, getNumImplicitUses,
getImplicitDefs and getNumImplicitDefs as all clients are using the new
implicit_uses and implicit_defs.

Differential Revision: https://reviews.llvm.org/D142216
2023-01-24 21:23:27 +00:00
Kazu Hirata
b3af04f880 [llvm] Use llvm::countr_zero instead of findFirstSet (NFC)
At each call to findFirstSet in this patch, the argument is known to
be nonzero, so we can safely switch to llvm::countr_zero, which will
become std::countr_zero once C++20 is available.
2023-01-23 23:07:41 -08:00
Jay Foad
2eef875915 [TableGen] Avoid repeated lookups of Uses and Defs records. NFC. 2023-01-23 18:46:32 +00:00
David Spickett
cef9e872ed [llvm][tablegen][jupyter] Fixup README
Make the first line a title and relative link
to the Markdown of the demo notebook.
2023-01-23 14:49:02 +00:00
David Spickett
92787e3e34 [LLVM][TableGen] Support combined cells in jupyter kernel
This changes the default mode to cache the code blocks we're
asked to compile until we see the new `%reset` magic to clear that cache.

This means that if you run several cells in sequence, at the end you're
compiling the code from all the cells at once.

This emulates what the ipython kernel does where it uses a persistent
interpreter state by default.

`%reset` will only be acted on when it's in the cell we're asked to run
(the newest code).

`%args` we will use the most recent value we have cached.

The example notebook has been updated to explain that.

Depends on D132378

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D132646
2023-01-23 14:19:36 +00:00
David Spickett
210a383e18 [LLVM][TableGen] Add jupyter kernel for llvm-tblgen
This is based on the MLIR opt kernel:
https://github.com/llvm/llvm-project/tree/main/mlir/utils/jupyter

The inent of this is to enable experimentation and the creation
of interactive tutorials for the basics of tablegen.

Noteable changes from that:
* Removed the codemirror mode settings since those won't exist
  for tablegen.
* Added "%args" "magic" to control arguments sent to llvm-tblgen.

(magics are directives, see
https://ipython.readthedocs.io/en/stable/interactive/magics.html)

For example the following:
```
%args --print-detailed-records
class Stuff {}

def water_bottle : Stuff {}
```
Produces:
```
DETAILED RECORDS for file -

-------------------- Global Variables (0) --------------------

-------------------- Classes (1) --------------------

Stuff  |<stdin>:1|
  Template args: (none)
  Superclasses: (none)
  Fields: (none)

-------------------- Records (1) --------------------

water_bottle  |<stdin>:3|
  Superclasses: Stuff
  Fields: (none)
```

Reviewed By: jpienaar, awarzynski

Differential Revision: https://reviews.llvm.org/D132378
2023-01-23 14:15:55 +00:00
Kazu Hirata
ca7e849720 [llvm] Use llvm::bit_floor (NFC)
In all these cases, the arguments to Log2_32 are known to be nonzero,
so we don't have to worry about "1 << -1".
2023-01-22 13:41:23 -08:00
Kazu Hirata
caa99a01f5 Use llvm::popcount instead of llvm::countPopulation(NFC) 2023-01-22 12:48:51 -08:00
Craig Topper
d80b7fde92 Recommit "[RISCV][TableGen] Move XLen detection into getMArch in RISCVTargetDefEmitter. NFC"
Using the correct feature name to detect 64bit this time. Previously,
I mistakenly compared the expected record name against a string inside
the record.
2023-01-20 12:20:58 -08:00
Craig Topper
8d25c73e39 Revert "[RISCV][TableGen] Move XLen detection into getMArch in RISCVTargetDefEmitter. NFC"
This reverts commit e58010f712ccac83194852fa95ed70ef76ba6a33.

Seems this is failing on the build bots.
2023-01-20 10:45:13 -08:00
Craig Topper
e58010f712 [RISCV][TableGen] Move XLen detection into getMArch in RISCVTargetDefEmitter. NFC
We no longer need the XLen in two places. Fold it into the code
that determines the default march.
2023-01-20 10:16:28 -08:00
Craig Topper
0ccbf91166 [RISCV] Remove Features from CPUInfo in RISCVTargetParser.
Instead of having separate feature bits, get information from march.
Invalid is now implied by empty march.
64-bit is now implied by march starting with "rv64".

Reviewed By: fpetrogalli

Differential Revision: https://reviews.llvm.org/D142230
2023-01-20 10:03:37 -08:00
Craig Topper
e62ffd3fd6 [RISCV][TableGen] Use getAllDerivedDefinitions in RISCVTargetDefEmitter to simplify the code. NFC 2023-01-20 00:34:05 -08:00
wangpc
fcc2e5aa39 [TableGen][NFC] Add postfix for validators of CompressPat
So that we won't get redefinition errors if we use compressInst
and uncompressInst in the same file.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D141896
2023-01-18 14:34:06 +08:00