Commit Graph

82 Commits

Author SHA1 Message Date
Rahul Joshi
743f839a88 [NFC][LLVM][TableGen] Change RecordKeeper::getClass to return const pointer (#112261)
Change `RecordKeeper::getClass` to return const record pointer. This is
a part of effort to have better const correctness in TableGen backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-23 11:32:05 -07:00
Rahul Joshi
62e2c7fb2d [LLVM][TableGen] Change all Init pointers to const (#112705)
This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-18 07:50:22 -07:00
Rahul Joshi
667815ccf4 [NFC][TableGen] Change RecordKeeper::getDef() to return const pointer (#110992)
This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-03 08:18:43 -07:00
Rahul Joshi
65e69f7436 [NFC][TableGen] Change Record::getSuperClasses to use const Record* (#110845)
Change `Record::getSuperClasses` to return a const pointer to the
superclass records.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-02 13:24:46 -07:00
Rahul Joshi
d256b9e88b [TableGen] Change DefInit::Def to a const Record pointer (#110747)
This change undoes a const_cast<> introduced in an earlier change to
help transition to const pointers. It is a part of effort to have better
const correctness in TableGen backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-02 09:48:26 -07:00
Matt Arsenault
37e717ec13 TableGen/GlobalISel: Fix using wrong type for instruction flags
09515f2c20 increased the size of the
MachineInstr flags from uint16_t to uint32_t, so change TableGen
to match.
2024-10-02 12:37:41 +04:00
Rahul Joshi
a140931be5 [TableGen] Change getValueAsListOfDefs to return const pointer vector (#110713)
Change `getValueAsListOfDefs` to return a vector of const Record
pointer, and remove `getValueAsListOfConstDefs` that was added as a
transition aid.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-01 14:30:38 -07:00
Rahul Joshi
9d95e2614e [TableGen] Change all type pointers to const (#110602)
This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-10-01 06:54:17 -07:00
Stephen Chou
ec61311e77 [LLVM][TableGen] Support type casts of nodes with multiple results (#109728)
Currently, type casts can only be used to pattern match for intrinsics
with a single overloaded return value. For instance:
```
def int_foo : Intrinsic<[llvm_anyint_ty], []>;
def : Pat<(i32 (int_foo)), ...>;
```

This patch extends type casts to support matching intrinsics with
multiple overloaded return values. As an example, the following defines
a pattern that matches only if the overloaded intrinsic call returns an
`i16` for the first result and an `i32` for the second result:
```
def int_bar : Intrinsic<[llvm_anyint_ty, llvm_anyint_ty], []>;
def : Pat<([i16, i32] (int_bar)), ...>;
```
2024-10-01 11:17:00 +04:00
Rahul Joshi
bfa8519bbb [LLVM][TableGen] Change GlobalISelEmitter to use const RecordKeeper (#110109)
Change GlobalISelEmitter to use const RecordKeeper.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-30 06:37:36 -07:00
Rahul Joshi
c92137e474 [NFC][TableGen] Adopt scaled indent in PredicateExpander (#109801)
Adopt scaled indent in PredicateExpander.
Added pre/post inc/dec operators to `indent` and related unit tests.
Verified by comparing *.inc files generated by LLVM build with/without
the change.
2024-09-24 22:05:51 -07:00
Rahul Joshi
3138eb500c [LLVM][TableGen] Use const record pointers in TableGen/Common files (#109467)
Use const record pointers in TableGen/Common files.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-23 13:07:31 -07:00
Craig Topper
eb8d865c44 [TableGen] Change getReg() == 0 to !getReg().isValid() in expandCheckInvalidRegOperand. NFC 2024-09-21 22:37:28 -07:00
Rahul Joshi
708567ab0b [LLVM][TableGen] Adopt indent for indentation (#109275)
Adopt `indent` for indentation DAGISelMatcher and DecoderEmitter.
2024-09-20 04:28:01 -07:00
Rahul Joshi
2b01452c20 [LLVM][TableGen] Use const Record pointers in PredicateExpander (#109365)
Use const Record pointers in PredicateExpander.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-20 04:23:52 -07:00
Rahul Joshi
d109636c2e [LLVM][TableGen] Change GISelCombinerEmitter to use const RecordKeeper (#109187)
Change GISelCombinerEmitter to use const RecordKeeper.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-20 04:23:11 -07:00
Rahul Joshi
3e24dd42dd [NFC] Rename variables to conform to LLVM coding standards (#109166)
Rename `indent` to `Indent` and `o` to `OS`.
Rename `Indentation` to `Indent`.
Remove unused argument from `emitPredicateMatch`.
Change `Indent` argument to `emitBinaryParser` to by value.
2024-09-19 04:49:12 -07:00
Rahul Joshi
23123aa4ec [LLVM][TableGen] Change InstrInfoEmitter to use const RecordKeeper (#109189)
Change InstrInfoEmitter to use const RecordKeeper.

This is a part of effort to have better const correctness in TableGen backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-18 22:27:26 -07:00
Rahul Joshi
c29dfb3346 [LLVM][TableGen] Change CodeGenSchedule to use const Record pointers (#108782)
Change CodeGenSchedule to use const Record pointers.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-18 04:45:49 -07:00
Rahul Joshi
100b34bbc1 [LLVM][TableGen] Change VarLenCodeEmitterGen to use const RecordKeeper (#108960)
Change VarLenCodeEmitterGen to use const RecordKeeper.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-17 09:01:04 -07:00
Rahul Joshi
8e00afcfdd [LLVM][TableGen] Change SubtargetEmitter to use const RecordKeeper (#108763)
Change SubtargetEmitter to use const RecordKeeper.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-15 10:26:27 -07:00
Rahul Joshi
87e8b53009 [LLVM][TableGen] Change CodeGenDAGPatterns to use const RecordKeeper (#108762)
Change CodeGenDAGPatterns to use const RecordKeeper.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-15 10:26:03 -07:00
Rahul Joshi
43f044ba7e [LLVM][TableGen] Change CodeGenTarget to use const RecordKeeper (#108752)
Change CodeGenTarget to use const RecordKeeper.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-15 07:33:48 -07:00
Rahul Joshi
8783bd5faa [LLVM][TableGen] Change CodeGenInstAlias to use const Record pointers (#108753)
Change CodeGenInstAlias to use const Record pointers.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-15 07:27:41 -07:00
Rahul Joshi
3ae71d154e [LLVM][TableGen] Change CodeGenSchedule to use const RecordKeeper (#108617)
Change CodeGenSchedule to use const RecordKeeper.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-15 04:55:29 -07:00
Rahul Joshi
d3cdf0f222 [LLVM][Option] Refactor option name comparison (#108219)
Move common functions shared by TableGen Option Emitter
and Options library to Support:
- Move `StrCmpOptionName` and base it on the existing version
  in OptTable.cpp, with an additional mode to control fall back to
  case insensitive comparison.
- Add `StrCmpOptionPrefixes` to compare prefixes and use zip() to
  iterate through lists of prefixes.
- Rename `CompareOptionRecords` to less ambiguous name 
  `IsOptionRecordLess`.
- Merge 2 back-to-back ifs with same condition in
  `IsOptionRecordLess`.

Fixes https://github.com/llvm/llvm-project/issues/107723
2024-09-13 17:30:19 -07:00
Rahul Joshi
7c6592f5a3 [TableGen] Change CodeGenRegister to use const Record pointer (#108027)
Change CodeGenRegister to use const Record pointer.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-11 08:53:47 -07:00
Rahul Joshi
2b452b455e [TableGen] Change SubtargetFeatureInfo to use const Record pointers (#108013)
Change SubtargetFeatureInfo to use const Record pointers.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-11 08:53:21 -07:00
Rahul Joshi
3786568196 [TableGen] Change CodeGenInstruction record members to const (#107921)
Change CodeGenInstruction::{TheDef, InfereredFrom} to const pointers.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-11 08:52:26 -07:00
Rahul Joshi
ccc4fa1842 [TableGen] Fix MacOS failure in Option Emitter. (#108225)
Handle the case of same pointer used as both inputs to the
`CompareOptionRecords`, to avoid emitting errors for equivalent options.

Follow-up to #107696.
2024-09-11 09:57:31 -04:00
Rahul Joshi
5f25b89513 [TableGen] Migrate Option Emitters to const RecordKeeper (#107696)
Migrate Opt/OptRST Emitters to const RecordKeeper.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-11 05:57:50 -07:00
Rahul Joshi
bdf02249e7 [TableGen] Change CGIOperandList::OperandInfo::Rec to const pointer (#107858)
Change CGIOperandList::OperandInfo::Rec and CGIOperandList::TheDef to
const pointer.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-09 14:33:21 -07:00
Rahul Joshi
985600dcd3 [TableGen] Migrate CodeGenHWModes to use const RecordKeeper (#107851)
Migrate CodeGenHWModes to use const RecordKeeper and const Record
pointers.

This is a part of effort to have better const correctness in TableGen
backends:


https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
2024-09-09 13:09:53 -07:00
Rahul Joshi
1651014960 [TableGen] Change SetTheory set/vec to use const Record * (#107692)
Change SetTheory::RecSet/RecVec to use const Record pointers.
2024-09-09 08:47:42 -07:00
Rahul Joshi
ce3c58e104 [NFC][TableGen] Replace DefInit::get() with Record::getDefInit() (#107762)
Eliminate DefInit::get() as its a duplicate of Record::getDefInit(). 
Use early return in `VarDefInit::instantiate`.
2024-09-08 12:18:53 -07:00
Rahul Joshi
c1e3b990a9 [TableGen] Eliminate static CodeGenIntrinsicMap in PatternParser (#107339)
Instead, move it to CodeGenTarget class, and use it in both
PatternParser and SearchableTableEmitter.
2024-09-07 15:11:34 -07:00
Rahul Joshi
0ceffd362b [TableGen] Add PrintError family overload that take a print function (#107333)
Add PrintError and family overload that accepts a print function. This
avoids constructing potentially long strings for passing into these
print functions.
2024-09-07 05:13:54 -07:00
Thomas Fransham
59f8796aaa Initial changes for llvm shared library build using explicit visibility annotations
These are my initial build and code changes to supporting building llvm
as shared library/DLL on windows(without force exporting all symbols)
and making symbol visibility hidden by default on Linux which adding
explicit symbol visibility macros to the whole llvm codebase.

Updated cmake code to allow building llvm-shlib on windows by appending
/WHOLEARCHIVE:lib to the linker options.
Remove the hardcoded CMake error from using LLVM_BUILD_LLVM_DYLIB on
windows.
Updated CMake to define new macros to control conditional export macros
in llvm/Support/Compiler.h
Use /Zc:dllexportInlines- when compiling with clang-cl on windows with a
opt out CMake option to disable using it.
Replace some use of LLVM_EXTERNAL_VISIBILITY with new export macros.

Some of the cmake and code changes are based on @tstellar's earlier PR
https://github.com/llvm/llvm-project/pull/67502.

I have Windows building using clang-cl, while for MSVC its at-least able
to build libllvm, but some tests can't build because llvm iterator
template metaprogramming that doesn't work well with dllexport. Linux
should build without issue. My full branch is here
https://github.com/fsfod/llvm-project/tree/llvm-export-api-20.0 and
including all the auto generated export macros from clang tooling based
system.
2024-09-06 10:51:44 -07:00
Rahul Joshi
16df489fda [TableGen] Add const variants of accessors for backend (#106658)
Split RecordKeeper `getAllDerivedDefinitions` family of functions into
two variants:
  (a) non-const ones that return vectors of `Record *` and 
  (b) const ones, that return vector/ArrayRef of `const Record *`.

This will help gradual migration of TableGen backends to use 
`const RecordKeeper` and by implication change code to work 
with const pointers and better const correctness.

Existing backends are not yet compatible with the const family of
functions, so change them to use a non-constant `RecordKeeper` 
reference, till they are migrated.
2024-09-05 18:35:55 -07:00
Rahul Joshi
660cc98647 [TableGen] Add CodeGenIntrinsicsMap for on-demand intrinsic creation (#107100)
- Add class `CodeGenIntrinsicMap` for on-demand creation of  
  `CodeGenIntrinsic`.
- Add class `CodeGenIntrinsicContext` to capture global information
  required to build `CodeGenIntrinsic` objects.
- Adopt GlobalISel PatternParser and SearchableTableEmitter to use it.
2024-09-04 14:58:01 -07:00
Brandon Wu
dc03ee3cbb [llvm][RISCV] Add RISCV vector tuple type to value types(MVT) (#97993)
Summary:
This patch handles the types(MVT) in `selectionDAG` for RISCV vector
tuples.
As described in previous patch handling llvm types, the MVTs also have
32 variants:
```
riscv_nxv1i8x2, riscv_nxv1i8x3, riscv_nxv1i8x4, riscv_nxv1i8x5, riscv_nxv1i8x6, riscv_nxv1i8x7, riscv_nxv1i8x8,
riscv_nxv2i8x2, riscv_nxv2i8x3, riscv_nxv2i8x4, riscv_nxv2i8x5, riscv_nxv2i8x6, riscv_nxv2i8x7, riscv_nxv2i8x8,
riscv_nxv4i8x2, riscv_nxv4i8x3, riscv_nxv4i8x4, riscv_nxv4i8x5, riscv_nxv4i8x6, riscv_nxv4i8x7, riscv_nxv4i8x8,
riscv_nxv8i8x2, riscv_nxv8i8x3, riscv_nxv8i8x4, riscv_nxv8i8x5, riscv_nxv8i8x6, riscv_nxv8i8x7, riscv_nxv8i8x8,
riscv_nxv16i8x2, riscv_nxv16i8x3, riscv_nxv16i8x4,
riscv_nxv32i8x2.
```

Detail:
An intuitive way to model vector tuple type is using nested scalable
vector, e.g. `nElts=NF, EltTy=nxv2i32`. However it's not compatible to
what we've done to handle scalable vector in TargetLowering, so it would
need more effort to change the code to handle this concept.
Another approach is encoding the `MinNumElts` info in `sz` of `MVT`,
e.g.
`nElts=NF, sz=(NF*MinNumElts*8)`, this makes it much easier to handle
and
changes less code.

This patch adopts the latter approach.

Stacked on https://github.com/llvm/llvm-project/pull/97992
2024-08-31 19:01:29 +08:00
Rahul Joshi
d7da79f2cd [NFC][SetTheory] Refactor to use const pointers and range loops (#105544)
- Refactor SetTheory code to use const pointers when possible.
- Use auto for variables initialized using dyn_cast<>.
- Use range based for loops and early continue.
2024-08-22 05:47:31 -07:00
Rahul Joshi
ddda37a6c7 [TableGen] Refactor Intrinsic handling in TableGen (#103980)
CodeGenIntrinsic changes:
  - Use `const` Record pointers, and `StringRef` when possible.
  - Default initialize several fields with their definition instead of in
 the constructor.
- Simplify various string checks in the constructor using StringRef
starts_with()/ends_with() functions.
- Eliminate first argument to `setDefaultProperties` and use `TheDef`
class member instead.

IntrinsicEmitter changes:
  - Emit `namespace llvm::Intrinsic` instead of nested namespaces.
  - End generated comments with a .
  - Use range based for loops, and early continue within loops.
  - Emit `static constexpr` instead of `static const` for arrays.
- Change `compareFnAttributes` to use std::tie() to compare intrinsic
attributes and return a default value when all attributes are equal.

STLExtras:
  - Add std::replace wrapper which takes a range.
2024-08-16 09:26:57 -07:00
Craig Topper
ce88ca928a [TableGen] Sign extend constants based on size for EmitIntegerMatcher. (#104550)
I'm planning to add a getSignedConstant to SelectionDAG and use it for
EmitInteger in SelectionDAGISel which already uses int64_t.
getSignedConstant will assert that the constant has the correct number
of significant bits for the VT.

This patch ensures that tablegen emits constants in this form.
2024-08-16 08:43:54 -07:00
Rahul Joshi
8a61bfcf8f [NFC] Fix TableGen include guards to match paths (#102746)
- Fix include guards for headers under utils/TableGen to match their
paths.
2024-08-10 17:35:03 +03:00
Kazu Hirata
e9a47a664a [llvm] Construct SmallVector with ArrayRef (NFC) (#102712)
Without this patch, the constructor arguments come from
SmallVectorImpl, not ArrayRef.  This patch switches them to ArrayRef
so that we can construct SmallVector with a single argument.

Note that LLVM Programmer’s Manual prefers ArrayRef to SmallVectorImpl
for flexibility.
2024-08-09 21:39:13 -07:00
Rahul Joshi
8ce5a32f02 [TableGen] Rework error reporting for duplicate Feature/Processor (#102257)
- Extract code for sorting and checking duplicate Records into a helper
  function and update `collectProcModels` to use the helper.
- Update `FeatureKeyValues` to:
  (a) Remove code for duplicate checks and use the helper.
  (b) Trim features with empty name explicitly to be able to use
      the helper.
- Make the sorting deterministic by using record name as a secondary
  key for sorting, and re-enable SubtargetFeatureUniqueNames.td test
  that was disabled due to the non-determinism of the error messages.
- Change wording of error message when duplicate records are found to
  be source code position agnostic, since `First` may not be before
  `Second` lexically.
2024-08-08 02:00:36 +03:00
Simon Pilgrim
8b522992a9 Fix gcc Wparentheses warning. NFC. 2024-08-07 16:28:06 +01:00
Kazu Hirata
2e9d2f183f [TableGen] Construct SmallVector with ArrayRef (NFC) (#101870) 2024-08-04 08:54:07 -07:00
Craig Topper
358593ba87 [TableGen] Use std::move. NFC
Fixes #101408.
2024-08-01 21:42:44 -07:00