Commit Graph

5792 Commits

Author SHA1 Message Date
Michael Maitland
67beebfcb9 [TableGen][SubtargetEmitter] Refactor hasReadOfWrite to CodeGenProcModel (#92032)
SubtargetEmitter::GenSchedClassTables takes a CodeGenProcModel, but
calls hasReadOfWrite which loops over all ProcModels. We move
hasReadOfWrite to CodeGenProcModel and remove the loop over all
ProcModels. This leads to a 144% speedup on the RISC-V backend of our
downstream.
2024-05-14 17:15:19 -04:00
Alex Bradbury
4014e2e045 [TableGen][RISCV] Strip experimental- prefix in profile names in SupportedExperimentalProfiles
This matches what we do for extensions, and saves us having to do it in
RISCVISAInfo.

This is a minor tweak to what I added in #91993.
2024-05-14 07:30:28 +01:00
Tomas Matheson
12c0024d19 [AArch64][TargetParser] Move extension aliases into tablegen (#91970) 2024-05-14 07:04:29 +01:00
Alex Bradbury
e5a277b167 [TableGen][RISCV] Add initial support for marking profiles as experimental (#91993)
This is just the TableGen-side changes, split out as the minimal
testable unit. It doesn't yet transition RVA23 and friends to be
experimental (and add the necessary other changes for this to work).

Although choosing not to emit the SupportedExperimentalProfiles array if
no experimental profiles are present isn't consistent with what we do
for experimental extensions, we need to do this in order to avoid adding
a warning for the empty array when building LLVM for as long as we don't
have any experimental profiles defined.
2024-05-14 05:34:39 +01:00
Alex Bradbury
754ff0f54a [TableGen][RISCV] Use getAllDerivedDefinitionsIfDefined in RISCVTargetDefEmitter (#91941)
getAllDerivedDefinitions produces a fatal error if there are no
definitions. In practice this isn't much of a problem for
llvm/lib/Target/RISCV/*.td where it's hard to imagine not having at
least one of the required defitions. But it limits our ability to
structure and maintain tests (which is how I came across this issue).

This commit moves to using getAllDerivedDefinitionsIfDefined and aims to
skip emission of data structures that make no sense if no definitions
were found.
2024-05-13 17:05:28 +01:00
Tomas Matheson
639a740035 [AArch64] move extension information into tablgen (#90987)
Generate TargetParser extension information from tablegen. This includes FMV extension information. FMV only extensions are represented by a separate tablegen class.

Use MArchName/ArchKindEnumSpelling to avoid renamings.
Cases where there is simply a case difference are handled by
consistently uppercasing the AEK_ name in the emitted code.

Remove some Extensions which were not needed.
These had AEK entries but were never actually used for anything.
They are not present in Extensions[] data.
2024-05-09 21:54:48 +01:00
Kazu Hirata
bb6df0804b [llvm] Use StringRef::operator== instead of StringRef::equals (NFC) (#91441)
I'm planning to remove StringRef::equals in favor of
StringRef::operator==.

- StringRef::operator==/!= outnumber StringRef::equals by a factor of
  70 under llvm/ in terms of their usage.

- The elimination of StringRef::equals brings StringRef closer to
  std::string_view, which has operator== but not equals.

- S == "foo" is more readable than S.equals("foo"), especially for
  !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-08 10:33:53 -07:00
Fangrui Song
efad14954c [Support] Add end/error to decode[US]LEB128AndInc
Follow-up to #85739 to encourage error checking. We make `end` mandatory
and add decodeULEB128AndIncUnsafe to be used without `end`.

Pull Request: https://github.com/llvm/llvm-project/pull/90006
2024-05-08 09:22:30 -07:00
superZWT123
ffc9a30938 [TableGen] Use bitwise operations to access HwMode ID. (#88377)
1. Bitwise operations are used to access HwMode, allowing for the
coexistence of HwMode IDs for different features (such as RegInfo and
EncodingInfo). This will provide better scalability for HwMode.
Currently, most users utilize HwMode primarily for configuring
Register-related information, and few use it for configuring Encoding.
The limited scalability of HwMode has been a significant factor in this
usage pattern.
2. Sink the HwMode Encodings selection logic down to per instruction
level, this makes the logic for choosing encodings clearer and provides
better error messages.
3. Add some HwMode ID conflict detection to the getHwMode() interface.
2024-05-04 20:08:26 -05:00
Rin Dobrescu
385f59f9f5 [llvm-mca] Teach MCA constant registers do not create dependencies (#89387)
Constant registers like the zero registers XZR and WZR are treated as
any other register by LLVM-MCA. This can create non existent dependency
chains.
Currently there is no method in MCA to query if a register is constant.
This patch fixes the issue by adding a bool Constant
variable to MCRegisterDesc that is true for constant registers. Since
constant registers do not create dependencies, it makes sense to add
this check to MCA.
2024-05-03 10:30:22 +01:00
Pierre van Houtryve
ed299b3efd [GlobalISel] Optimize ULEB128 usage (#90565)
- Remove some cases where ULEB128 isn't needed
- Add a fastDecodeULEB128 tailored for GlobalISel which does unchecked
decoding optimized for the common case, which is 1 byte values. We
rarely have >1 byte Inst IDs, OpIdx, etc. and those are the most common
ULEB users by far.

This specific LEB128 decode function generates almost 2x less
instructions than the generic one.
2024-05-03 10:26:54 +02:00
Craig Topper
a7e0798854 [RISCV] Use binary search to look up supported profiles. (#90767)
As the list of profiles grow, this will be a more efficient lookup.

Because the profile name is a prefix of the Arch string, we use
upper_bound to find the first profile that definitely comes after the
Arch string. If that isn't the first supported profile, we move back 1
profile and see if that profile is a prefix of our Arch string.
2024-05-01 14:56:14 -07:00
Tomas Matheson
cfca977427 [AArch64][TargetParser] autogen ArchExtKind enum (#90314)
Re-land 61b2a0e333. Some Windows builds
were failing because AArch64TargetParserDef.inc is a generated header
which is included transitively into some clang components, but this
information is not available to the build system and therefore there is
a missing edge in the dependency graph. This patch incorporates the
fixes described in ac1ffd3caca12c254e0b8c847aa8ce8e51b6cfbf/D142403.

Thanks to ExtensionSet::toLLVMFeatureList, all values of ArchExtKind
should correspond to a particular -target-feature. The valid values of
-target-feature are in turn defined by SubtargetFeature defs.

Therefore we can generate ArchExtKind from the tablegen data. This is
done by adding an Extension class which derives from SubtargetFeature.

Because the Has* FieldNames do not always correspond to the AEK_
names ("extensions", as defined in TargetParser), and AEK_ names do
not always correspond to -march strings, some additional enum entries
have been added to remap the names. I have renamed these to make the
naming consistent, but split them into a separate PR to keep the diff
reasonable (#90320)
2024-05-01 15:14:44 +01:00
Tomas Matheson
35e6bae62c Revert "[AArch64][TargetParser] autogen ArchExtKind enum (#90314)"
This reverts commit 61b2a0e333.

Reason: AArch64TargetParserDef.inc not found while building clang
2024-04-30 14:42:08 +01:00
Tomas Matheson
61b2a0e333 [AArch64][TargetParser] autogen ArchExtKind enum (#90314)
Thanks to ExtensionSet::toLLVMFeatureList, all values of ArchExtKind
should correspond to a particular -target-feature. The valid values of
-target-feature are in turn defined by SubtargetFeature defs.

Therefore we can generate ArchExtKind from the tablegen data. This is
done by adding an Extension class which derives from SubtargetFeature.

Because the Has* FieldNames do not always correspond to the AEK_
names ("extensions", as defined in TargetParser), and AEK_ names do
not always correspond to -march strings, some additional enum entries
have been added to remap the names. I have renamed these to make the
naming consistent, but split them into a separate PR to keep the diff
reasonable (#90320)
2024-04-30 13:29:09 +01:00
Kai Nacke
413f6b95a4 [TableGen][GISel][NFC] clang-tidy GlobalISelEmitter.cpp (#90492)
Fixes a couple of style issues, such as:

- unused includes
- variable naming
- `else if` after `return`
2024-04-29 14:47:46 -04:00
Kai Nacke
1e174a7656 [TableGen][GISel] Handle frameindex/tframeindex (#90475)
Support patterns like

  Pat<(p0 frameindex:$fi), (ADD tframeindex:$fi, 0)>;

in the GlobalISel emitter in TableGen. Currently, using such a pattern
results in an error message.
2024-04-29 12:06:26 -04:00
Pengcheng Wang
c705c68476 [RISCV] Generate profiles from RISCVProfiles.td
So we can only mantain one place.

Reviewers: preames, yetingk, topperc

Reviewed By: topperc

Pull Request: https://github.com/llvm/llvm-project/pull/90187
2024-04-28 11:52:36 +08:00
Pengcheng Wang
7037878d2b [RISCV][TableGen] Get right experimental extension name
We should remove the `experimental-` prefix when printing march
string.

We didn't meet this problem because there is no processor containing
experimental extensions.

Reviewers: fpetrogalli, asb, topperc

Reviewed By: topperc, asb

Pull Request: https://github.com/llvm/llvm-project/pull/90185
2024-04-28 11:16:43 +08:00
Craig Topper
de375fbc71 [RISCV] Move OrderedExtensionMap typedef to RISCVISAUtils.h. NFC 2024-04-26 17:57:51 -07:00
Craig Topper
451e853e51 [RISCV] Flatten the ImpliedExts table in RISCVISAInfo.cpp (#89975)
Previously we had an individiaul global array of implied extensions for
each extension that needed it. This allowed each array to have a
different length. Then we had a sorted table that stored pointers and
size for the indivual arrays keyed by the extension name.

This patch changes the sorted table to use multiple rows if multiple
extensions are implied. We use equal_range instead of lower_bound to
find all the rows that apply to a given extension.

The CombineIntoExts array was also modified to store only the extension
name that need to be combined. This extension name is looked up in the
implied table to find all the extensions it depends on.
2024-04-26 10:32:21 -07:00
Jay Foad
ace3bd0580 Revert "[TableGen] Ignore inaccessible memory when checking pattern flags (#90061)"
This reverts commit 6578356a4e.

The patch had no effect due to a silly mistake and fixing the mistake
causes other problems.
2024-04-26 14:49:36 +01:00
Jay Foad
6578356a4e [TableGen] Ignore inaccessible memory when checking pattern flags (#90061)
In the AMDGPU backend we have some cases where we'd like to mark an
intrinsic as IntrInaccessibleMemOnly to model dependencies, but the
corresponding MachineInstrs use uses/defs of a special physical register
to express the same thing. In this case TableGen would complain:

  Pattern doesn't match mayLoad/mayStore = 0

but the error is not useful.
2024-04-26 10:28:52 +01:00
long.chen
2b2c66c00f [NFC][llvm] refine generated code format (#90172) 2024-04-26 15:44:55 +08:00
Fangrui Song
5a12f2867a LLVM_FALLTHROUGH => [[fallthrough]]. NFC 2024-04-25 17:50:59 -07:00
jofrn
eae7554d3f [TableGen] ShouldIgnore Pattern bit to disable DAG pattern imports during GISel (#88382)
Added GISelShouldIgnore property to class Pattern in TargetSelectionDAG.td; it's similar to FastISelShouldIgnore. This bit can be put on a record to avoid its pattern import within GlobalISelEmitter. This allows one to avoid the record's GISel .td implementation, .inc generation, and any skipped pattern warnings from -warn-on-skipped-patterns.
2024-04-25 16:42:48 -04:00
Craig Topper
80628ee0d5 [RISCV] Generate RISCVISAInfo table from RISCVFeatures.td. (#89955)
This generates the SupportedExtensions and ImpliedExts information from
the RISCVExtension records found in RISCVFeatures.td.

Some of the extensions listed in the individual `ImpliedExts*` arrays
may be in a different, but the order in those array doesn't matter. I
manually verified the all the extensions were still present in each
array.

I've added the new information to the existing RISCVTargetParserDef.inc
and RISCVTargetDefEmitter.cpp so we don't need to re-parse the entirety
of RISCV.td a second time for a new file.
2024-04-25 07:07:33 -07:00
Tomas Matheson
b8e97f0768 [ARM] Add ARMTargetDefEmitter to llvm-tblgen source
Missed from #88378, only showed up in the sanitizer builds.
2024-04-24 10:38:22 +01:00
Tomas Matheson
71c5964f5c [ARM][AArch64] autogenerate header file for TargetParser from Target tablegen files (#88378)
Introduce a mechanism to share data between the ARM and AArch64 backends and
TargetParser, to reduce duplication of code. This is similar to the current
RISC-V implementation.

The target tablegen file (in this case `ARM.td` or `AArch64.td`) is
processed during building of `TargetParser` to generate the following
files in the build tree:
 - `build/include/llvm/TargetParser/ARMTargetParserDef.inc`
 - `build/include/llvm/TargetParser/AArch64TargetParserDef.inc`

For now, the use of these generated files is limited to files _outside_
of `TargetParser`. The main reason for this is that the modifications to
`TargetParser` will require additional data added to the tablegen files,
which I want to split into separate PRs.
2024-04-24 09:18:36 +01:00
Pierre van Houtryve
9375962ac9 [TableGen][GlobalISel] Specialize more MatchTable Opcodes (#89736)
The vast majority of the following (very common) opcodes were always
called with identical arguments:

- `GIM_CheckType` for the root
- `GIM_CheckRegBankForClass` for the root
- `GIR_Copy` between the old and new root
- `GIR_ConstrainSelectedInstOperands` on the new root
- `GIR_BuildMI` to create the new root

I added overloaded version of each opcode specialized for the root
instructions. It always saves between 1 and 2 bytes per instance
depending on the number of arguments specialized into the opcode. Some
of these opcodes had between 5 and 15k occurences in the AArch64
GlobalISel Match Table.

Additionally, the following opcodes are almost always used in the same
sequence:

- `GIR_EraseFromParent 0` + `GIR_Done` 
- `GIR_EraseRootFromParent_Done` has been created to do both. Saves 2
bytes per occurence.
- `GIR_IsSafeToFold` was *always* called for each InsnID except 0.
- Changed the opcode to take the number of instructions to check after
`MI[0]`

The savings from these are pretty neat. For `AArch64GenGlobalISel.inc`:
- `AArch64InstructionSelector.cpp.o` goes down from 772kb to 704kb (-10%
code size)
- Self-reported MatchTable size goes from 420380 bytes to 352426 bytes
(~ -17%)

A smaller match table means a faster match table because we spend less
time iterating and decoding.
I don't have a solid measurement methodology for GlobalISel performance
so I don't have precise numbers but I saw a few % of improvements in a
simple testcase.
2024-04-24 09:19:18 +02:00
Craig Topper
733a87783c [RISCV] Split code that tablegen needs out of RISCVISAInfo. (#89684)
This introduces a new file, RISCVISAUtils.cpp and moves the rest of
RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using tablegen.
2024-04-23 15:12:36 -07:00
Martin Wehking
b817451211 Make default initialization explicit
Coverity (a static analysis tool) reported that the emitted 'Features'
variable inside emitComputeAvailableFeatures in TableGen might be
unitialized.
Silence this warning by adding brackets for the default initialization.
Adapt test cases to take additional brackets into account.
2024-04-23 12:26:34 +01:00
pvanhout
8a631d7898 [TableGen] Fix ReplaceRegAction RTTI Kind 2024-04-23 12:54:50 +02:00
Craig Topper
b64e483785 [RISCV][TableGen] Generate RISCVTargetParserDef.inc from the new RISCVExtension tblgen information. (#89335)
Instead of using RISCVISAInfo's extension information, use the extension
found in tblgen after #89326.
    
We still need to use RISCVISAInfo code to get the sorting rules for the
ISA string.
    
The ISA string we generate now is not quite the same extension we had
before. No implied extensions are included in the generate string unless
they are explicitly listed in RISCVProcessors.td. This primarily affects
Zicsr being implied by F, V implying Zve*, and Zvl*b implying a smaller
Zvl*b. All of these implication should be picked up when the string is
used by the frontend.
    
The benefit is that we get a more manageable ISA string for humans to
deal with.
    
This is a step towards generating RISCVISAInfo's extension list from
tblgen.
2024-04-22 20:37:11 -07:00
Krzysztof Parzyszek
14e6f63ee6 [Frontend][OpenMP] Add suggested brackets in array initialization
Fixes -Werror build after 40137ff0d8.
2024-04-22 15:54:28 -05:00
Krzysztof Parzyszek
40137ff0d8 [Frontend][OpenMP] Refactor getLeafConstructs, add getCompoundConstruct (#87247)
Emit a special leaf construct table in DirectiveEmitter.cpp, which will
allow both decomposition of a construct into leafs, and composition of
constituent constructs into a single compound construct (if possible).
The function `getLeafConstructs` is no longer auto-generated, but
implemented in OMP.cpp.

The table contains a row for each directive, and each row has the
following format
`dir_id, num_leafs, leaf1, leaf2, ..., leafN, -1, ...`
The rows are sorted lexicographically with respect to the leaf
constructs. This allows a binary search for the row corresponding to the
given list of leafs.

There is an auxiliary table that for each directive contains the index
of the row corresponding to that directive.

Looking up leaf constructs for a directive `dir_id` is of constant time,
and and consists of two lookups: `LeafTable[Auxiliary[dir_id]]`.
Finding a compound directive given the set of leafs is of time O(logn),
and is roughly represented by
`row = binary_search(LeafTable); return row[0]`.

The functions `getLeafConstructs` and `getCompoundConstruct` use these
lookup methods internally.
2024-04-22 14:41:11 -05:00
Craig Topper
f09f99ed32 [RISCV] Add RISCVTuneProcessorModel to 'generic' CPU. NFC
Remove hardcode GENERIC cpu from RISCVTargetDefEmitter.cpp.
2024-04-19 16:06:54 -07:00
Craig Topper
8e2060bf21 [X86][TableGen] Remove unnecessary use of formatted_raw_ostream. NFC (#89343)
This code used to use the PadToColumn feature of formatted_raw_ostream,
but no longer does. formatted_raw_ostream is slower than regular
raw_ostream because it has to keep track of the number of character
since the last new line character.
2024-04-19 12:39:54 -07:00
Simon Pilgrim
26a59bf6fc [TableGen] MacroFusionPredicatorEmitter - pass constant std::vector arguments by ArrayRef instead
Silence pass by value warnings

Fixes #89210
2024-04-19 16:57:18 +01:00
Freddy Ye
de3e4a9dfe [X86][APX] Remove KEYLOCKER and SHA promotions from EVEX MAP4. (#89173)
APX spec: https://cdrdv2.intel.com/v1/dl/getContent/784266
Change happended in version 4.0.
Removed instructions' Opcodes:
AESDEC128KL
AESDEC256KL
AESDECWIDE128KL
AESDECWIDE256KL
AESENC128KL
AESENC256KL
AESENCWIDE128KL
AESENCWIDE256KL
ENCODEKEY128
ENCODEKEY256
SHA1MSG1
SHA1MSG2
SHA1NEXTE
SHA1RNDS4
SHA256MSG1
SHA256MSG2
SHA256RNDS2
2024-04-19 10:56:59 +08:00
Michael Liao
62853a246e [TableGen][InstrInfoEmitter] Count sub-operands on def operands
- If a def operand includes multiple sub-operands, count them when
  generating instr info.
- Found issues in x86 and sparc backends, where memory operands of
  store or store-like instructions are wrongly placed in the output
  list.

Reviewers: jayfoad, arsenm, Pierre-vh

Reviewed By: arsenm

Pull Request: https://github.com/llvm/llvm-project/pull/88972
2024-04-16 20:34:20 -04:00
Craig Topper
9067070d91 [RISCV] Re-separate unaligned scalar and vector memory features in the backend. (#88954)
This is largely a revert of commit
e817966718.

As #88029 shows, there exists hardware that only supports unaligned
scalar.

I'm leaving how this gets exposed to the clang interface to a future
patch.
2024-04-16 15:40:32 -07:00
Freddy Ye
f4509cf284 [X86][MC] Support enc/dec for SETZUCC and promoted SETCC. (#86473)
apx-spec: https://cdrdv2.intel.com/v1/dl/getContent/784266
apx-syntax-recommendation:
https://cdrdv2.intel.com/v1/dl/getContent/817241
2024-04-11 10:18:29 +08:00
David Spickett
aff197ff21 Reland "[flang][clang] Add Visibility specific help text for options (#81869)"
This reverts commit 67d20412b4.

This includes fixes for clanginstallapi.
2024-04-05 08:27:59 +00:00
David Spickett
67d20412b4 Revert "[flang][clang] Add Visibility specific help text for options (#81869)"
This reverts commit 7e958f64ef.

Failing on multiple bots.
2024-04-05 08:15:35 +00:00
David Spickett
7e958f64ef [flang][clang] Add Visibility specific help text for options (#81869)
And use it to print the correct default OpenMP version for flang and
flang -fc1.

This change adds an optional `HelpTextsForVariants` to options. This
allows you to change the help text that gets shown in documentation and
`--help` based on the program its being generated for.

As `OptTable` needs to be constexpr compatible, I have used a std::array
of help text variants. Each entry is:
(list of visibilities) - > help text string

So for the OpenMP version we have (flang, fc1) -> "OpenMP version for
flang is...".

So you can have multiple visibilities use the same string. The number of
entries is currently set to 1, and the number of visibilities per entry
is 2, because that's the maximum we need for now. The code is written so
we can increase these numbers later, and the unused elements will be initialised.

I have not applied this to group descriptions just because I don't know
of one that needs changing. It could easily be enabled for those too if
needed. There are minor changes to them just to get it all to compile.

This approach of storing many help strings per option in the 1 driver
library seemed preferable to making a whole new library for Flang (even
if that would mostly be including stuff from Clang).
2024-04-05 09:03:16 +01:00
Shilei Tian
cfadf3f622 [TableGen] Fix a potential crash when operand doesn't appear in the instruction pattern (#87663)
We have a check of whether an operand is in the instruction pattern, and
emit an
error if it is not, but we simply continue execution, including directly
dereferencing a point-like object `InVal`, which will be just created
when
accessing the map. It contains a `nullptr` so dereferencing it causes
crash.
This is a very trivial fix.
2024-04-04 20:29:26 -04:00
Simon Pilgrim
ecb34599bd [X86] Add missing immediate qualifier to the (V)ROUND instructions (#87636)
Makes it easier to algorithmically recreate the instruction name in various analysis scripts I'm working on
2024-04-04 15:20:16 +01:00
Pengcheng Wang
b342d87f89 [TableGen][NFC] Add maybe_unused to MRI (#87044)
This suppresses warning `unused variable 'MRI' [-Wunused-variable]`
for those fusions that don't need `MRI`.
2024-04-01 18:04:28 +08:00
superZWT123
da1d3d8fb9 [TableGen] Introduce a less aggressive suppression for HwMode Decoder… (#86060)
1. Remove 'AllModes' and 'DefaultMode' suffixes for DecoderTables under
default HwMode.
2. Introduce a less aggressive suppression for HwMode DecoderTable, only
reduce necessary tables duplications. This allows encodings under
different HwModes to retain the original DecoderNamespace.
3. Change 'suppress-per-hwmode-duplicates' command option from bool type
to enum type, allowing users to choose what level of suppression to use.
2024-04-01 17:19:46 +08:00