aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/IntrinsicEmitter.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-01-03[llvm-(min-)tblgen] Avoid redundant source compilation (#114494)Michael Kruse1-867/+0
All the sources of `llvm-min-tblgen` are also used for `llvm-tblgen`, with identical compilation flags. Reuse the object files of `llvm-min-tblgen` for `llvm-tblgen` by applying the usual source structure of an executable: One file per executable which named after the executable name containing the (in this case trivial) main function, which just calls the tblgen_main in TableGen.cpp. This should also clear up any confusion (including mine) of where each executable's main function is. While this slightly reduces build time, the main motivation is ccache. Using the hard_link option, building the object files for `llvm-tblgen` will result in a hard link to the same object file already used for `llvm-min-tblgen`. To signal the build system that the file is new, ccache will update the file's time stamp. Unfortunately, time stamps are shared between all hard-linked files s.t. this will indirectly also update the time stamps for the object files used for `llvm-tblgen`. At the next run, Ninja will recognize this time stamp discrepancy to the expected stamp recorded in `.ninja_log` and rebuild those object files for `llvm-min-tblgen`, which again will also update the stamp for the `llvm-tblgen`... . This is especially annoying for tablegen because it means Ninja will re-run all tablegenning in every build. I am using the hard_link option because it reduces the cost of having multiple build-trees of the LLVM sources and reduces the wear to the SSD they are stored on.
2025-01-02Revert "[llvm-(min-)tblgen] Avoid redundant source compilation (#114494)"Michael Kruse1-0/+867
This reverts commit f6cb56902c6dcafede21eb6662910b6ff661fc0f. Buildbot failures such as https://lab.llvm.org/buildbot/#/builders/89/builds/13541: ``` /usr/bin/ld: utils/TableGen/Basic/CMakeFiles/obj.LLVMTableGenBasic.dir/ARMTargetDefEmitter.cpp.o: undefined reference to symbol '_ZN4llvm23EnableABIBreakingChecksE' /usr/bin/ld: /home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/./lib/libLLVMSupport.so.20.0git: error adding symbols: DSO missing from command line ``` Going to investigate.
2025-01-02[llvm-(min-)tblgen] Avoid redundant source compilation (#114494)Michael Kruse1-867/+0
All the sources of `llvm-min-tblgen` are also used for `llvm-tblgen`, with identical compilation flags. Reuse the object files of `llvm-min-tblgen` for `llvm-tblgen` by applying the usual source structure of an executable: One file per executable which named after the executable name containing the (in this case trivial) main function, which just calls the tblgen_main in TableGen.cpp. This should also clear up any confusion (including mine) of where each executable's main function is. While this slightly reduces build time, the main motivation is ccache. Using the hard_link option, building the object files for `llvm-tblgen` will result in a hard link to the same object file already used for `llvm-min-tblgen`. To signal the build system that the file is new, ccache will update the file's time stamp. Unfortunately, time stamps are shared between all hard-linked files s.t. this will indirectly also update the time stamps for the object files used for `llvm-tblgen`. At the next run, Ninja will recognize this time stamp discrepancy to the expected stamp recorded in `.ninja_log` and rebuild those object files for `llvm-min-tblgen`, which again will also update the stamp for the `llvm-tblgen`... . This is especially annoying for tablegen because it means Ninja will re-run all tablegenning in every build. I am using the hard_link option because it reduces the cost of having multiple build-trees of the LLVM sources and reduces the wear to the SSD they are stored on.
2024-12-07Switch the intrinsic names to a string table (#118929)Chandler Carruth1-2/+26
This avoids the need to dynamically relocate each pointer in the table. To make this work, this PR also moves the binary search of intrinsic names to an internal function with an adjusted signature, and switches the unittesting to test against actual intrinsics.
2024-10-28[TableGen] [NFC] Remove unused includes in TableGen BE (#113725)Jerry Sun1-1/+0
split PR as requested from https://github.com/llvm/llvm-project/pull/113318. Removes unused imports in TableGen BE
2024-10-15[LLVM][TableGen] Check overloaded intrinsic mangling suffix conflicts (#110324)Rahul Joshi1-1/+1
Check name conflicts between intrinsics caused by mangling suffix. If the base name of an overloaded intrinsic is a proper prefix of another intrinsic, check if the other intrinsic name suffix after the proper prefix can match a mangled type and issue an error if it can.
2024-10-05[NFC][TableGen] Change `CodeGenIntrinsics` to use const references (#111219)Rahul Joshi1-3/+3
Change `CodeGenIntrinsics` classes to vend out const references to `CodeGenIntrinsic` or `TargetSet` objects.
2024-10-01[LLVM][TableGen] Decrease code size of `Intrinsic::getAttributes` (#110573)Rahul Joshi1-70/+80
Decrease code size of `Intrinsic::getAttributes` function by uniquing the function and argument attributes separately and using the `IntrinsicsToAttributesMap` to store argument attribute ID in low 8 bits and function attribute ID in upper 8 bits. This reduces the number of cases to handle in the generated switch from 368 to 131, which is ~2.8x reduction in the number of switch cases. Also eliminate the fixed size array `AS` and `NumAttrs` variable, and instead call `AttributeList::get` directly from each case, with an inline array of the <index, AttribueSet> pairs.
2024-09-25[LLVM][TableGen] Adopt !listflatten for Intrinsic type signature (#109884)Rahul Joshi1-5/+3
Intrinisc type signature is a `list<list<int>>` that hold IIT encoding for each param/ret type (outer list) where the IIT encoding for each type itself can be 0 or more integers (the inner list). Intrinsic emitter flatten this list into generate the type signature in `ComputeTypeSignature`. Use the new !listflatten() operator to instead flatten the list in the TableGen definition and eliminate flattening in the emitter code. Verified that `-gen-intrinsic-impl` output for Intrinsics.td is identical with and without the change.
2024-09-17[NFC][TableGen] Adopt formatv() automatic index in IntrinsicEmitter (#108954)Rahul Joshi1-30/+30
Adopt the use of formatv() automatic index assignment feature in IntrinsicEmitter.
2024-09-07[TableGen] Add PrintError family overload that take a print function (#107333)Rahul Joshi1-9/+11
Add PrintError and family overload that accepts a print function. This avoids constructing potentially long strings for passing into these print functions.
2024-09-04[TableGen] Refactor Intrinsics record (#106986)Rahul Joshi1-5/+6
Eliminate unused `isTarget` field in Intrinsic record. Eliminate `isOverloaded`, `Types` and `TypeSig` fields from the record, as they are already available through the `TypeInfo` field. Change intrinsic emitter code to look for this info using fields of the `TypeInfo` record attached to the `Intrinsic` record. Fix several intrinsic related unit tests to source the `Intrinsic` class def from Intrinsics.td as opposed to defining a skeleton in the test. This eliminates some duplication of information in the Intrinsic class, as well as reduces the memory allocated for record fields, resulting in ~2% reduction (though that's not the main goal).
2024-09-04[TableGen] Optimize intrinsic info type signature encoding (#106809)Rahul Joshi1-32/+48
Change the "fixed encoding" table used for encoding intrinsic type signature to use 16-bit encoding as opposed to 32-bit. This results in both space and time improvements. For space, the total static storage size (in bytes) of this info reduces by 50%: - Current = 14193*4 (Fixed table) + 16058 + 3 (Long Table) = 72833 - New size = 14193*2 (Fixed table) + 19879 + 3 (Long Table) = 48268. - Reduction = 50.9% For time, with the added benchmark, we see a 7.3% speedup in `GetIntrinsicInfoTableEntries` benchmark. Actual output of the benchmark in included in the GitHub MR.
2024-09-02[NFC][TableGen] Refactor `getIntrinsicFnAttributeSet` (#106587)Rahul Joshi1-59/+77
Fix intrinsic function attributes to not generate attribute sets that are empty in `getIntrinsicFnAttributeSet`. Refactor the code to use helper functions to get effective memory effects for an intrinsic and to check if it has non-default attributes. This eliminates one case statement in `getIntrinsicFnAttributeSet` that we generate today for the case when intrinsic attributes are default ones. Also rename `Intrinsic` to `Int` to follow the naming convention used in this file and adjust emission code to not emit unnecessary empty line between cases generated.
2024-08-29Fix MSVC "not all control paths return a value" warning. NFC.Simon Pilgrim1-0/+1
2024-08-29[NFC][TableGen] Refactor IntrinsicEmitter code (#106479)Rahul Joshi1-190/+203
- Use formatv() and raw string literals to simplify emission code. - Use range based for loops and structured bindings to simplify loops. - Use const Pointers to Records. - Rename `ComputeFixedEncoding` to `ComputeTypeSignature` to reflect what the function actually does, cnd change it to return a vector. - Use reverse() and range based for loop to pack 8 nibbles into 32-bits. - Rename some variables to follow LLVM coding standards. - For function memory effects, print human readable effects in comment.
2024-08-28[NFC] Fix formatv() usage in preparation of validation (#106454)Rahul Joshi1-2/+2
Fix several uses of formatv() that would be flagged as invalid by an upcoming change that will add additional validation to formatv().
2024-08-26[TableGen] Allow emitter callbacks to use `const RecordKeeper &` (#104716)Rahul Joshi1-12/+12
- Refactor TableGen backend options to allow specifying a callback function that takes either a const reference or a non-const reference to `RecordKeeper`. This will enable gradual migration of code to use const references and pointers to `RecordKeeper` and `Record` in the TableGen backends. - Refactor handling of the callback command line options. Move variable for the command line option from the header to the CPP file, and add a function `ApplyCallback` to apply the selected callback. - Change callbacks in TableGen.cpp to take const reference. They use the `Opt` class to register their callbacks. - Change IntrinsicEmitter to use the `OptClass` to define its callbacks. It already uses a const reference in the implementation.
2024-08-22[NFC][TableGen] Emit more readable builtin string table (#105445)Rahul Joshi1-3/+1
- Add `EmitStringLiteralDef` to StringToOffsetTable class to emit more readable string table. - Use that in `EmitIntrinsicToBuiltinMap`.
2024-08-20[TableGen] Rework `EmitIntrinsicToBuiltinMap` (#104681)Rahul Joshi1-65/+156
Rework `IntrinsicEmitter::EmitIntrinsicToBuiltinMap` for improved peformance as well as refactor the code. Performance: - Current generated code does a linear search on the TargetPrefix, followed by a binary search on the builtin names for that target's builtins. - Improve the performance of this code in 2 ways: (a) Use binary search on the target prefix to lookup the builtin table for the target. (b) Improve the (common) case of when all builtins for a target share a common prefix. Check this common prefix first, and then do the binary search in the builtin table using the builtin name with the common prefix removed. This should help both data size (by creating a smaller static string table) and runtime (by reducing the cost of binary search on smaller strings). Refactor: - Use range based for loops for iterating over maps. - Use formatv() and C++ raw string literals to simplify the emission code. - Change the generated `getIntrinsicForClangBuiltin` and `getIntrinsicForMSBuiltin` to take a `StringRef` instead of `const char *` for the prefix.
2024-08-16[TableGen] Refactor Intrinsic handling in TableGen (#103980)Rahul Joshi1-91/+63
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-03-25[RFC][TableGen] Restructure TableGen Source (#80847)Pierre van Houtryve1-2/+2
Refactor of the llvm-tblgen source into: - a "Basic" library, which contains the bare minimum utilities to build `llvm-min-tablegen` - a "Common" library which contains all of the helpers for TableGen backends. Such helpers can be shared by more than one backend, and even unit tested (e.g. CodeExpander is, maybe we can add more over time) Fixes #80647
2024-02-14[TableGen] Stop using make_pair and make_tuple. NFC. (#81730)Jay Foad1-1/+1
These are unnecessary since C++17.
2024-02-09[NFC] clang-format utils/TableGen (#80973)Pierre van Houtryve1-21/+21
``` find llvm/utils/TableGen -iname "*.h" -o -iname "*.cpp" | xargs clang-format-16 -i ``` Split from #80847
2023-12-07[TableGen] Remove unnecessary includes (NFC)Kazu Hirata1-1/+0
Identified with clangd.
2023-09-27[NFC] Use const references to avoid copying objects in for-loopsGregory Alfonso1-1/+1
Differential Revision: https://reviews.llvm.org/D139487
2023-07-12[FPEnv][TableGen] Add strictfp attribute to constrained intrinsics by default.Kevin P. Neal1-1/+7
In D146869 @arsenm pointed out that the constrained intrinsics aren't getting the strictfp attribute by default. They should be since they are required to have it anyway. TableGen did not know about this attribute until now. This patch adds strictfp to TableGen, and it uses it on all of the constrained intrinsics. Differential Revision: https://reviews.llvm.org/D154991
2023-06-21Intrinsics: Allow tablegen to mark parameters with dereferenceableMatt Arsenault1-0/+4
2023-04-26TableGen: Replace `IntrinsicEmitter::ComputeFixedEncoding()` and cleanupNAKAMURA Takumi1-333/+0
Depends on D146915 Differential Revision: https://reviews.llvm.org/D145937
2023-04-26TableGen: Implement TypeSig generator in `Intrinsics.td`NAKAMURA Takumi1-0/+22
This commit doesn't replace `IntrinsicEmitter::ComputeFixedEncoding()`, but compares outputs to it, to make sure implementation correct. Depends on D145871, D145872, D145874, and D146914 Differential Revision: https://reviews.llvm.org/D146915
2023-04-26ReformatNAKAMURA Takumi1-9/+7
2023-04-25Migrate `IIT_Info` into `Intrinsics.td`NAKAMURA Takumi1-0/+26
- Define `IIT_Info` in `Intrinsics.td` - Implement `EmitIITInfo` in `IntrinsicEmitter.cpp` - Use generated `IIT_Info` in `Function.cpp` Depends on D145873 and D146179 Differential Revision: https://reviews.llvm.org/D146914
2023-03-31Move definitions of ArgKind from Intrinsics.h to Intrinsics.tdNAKAMURA Takumi1-0/+18
Values of ArgKind are used (as naked constants) also in IntrinsicEmitter. They can be dissolved to move their logic to Intrinsics.td. Differential Revision: https://reviews.llvm.org/D145873
2023-03-31Let IntrinsicEnums.inc conditional by GET_INTRINSIC_ENUM_VALUESNAKAMURA Takumi1-1/+4
Part of https://reviews.llvm.org/D145873
2023-03-21llvm-tblgen: Rewrite emitters to use `TableGen::Emitter`NAKAMURA Takumi1-3/+8
Each emitter became self-contained since it has the registration of option. Differential Revision: https://reviews.llvm.org/D144351
2023-03-15Let IntrinsicEmitter free from CodeGenTarget.hNAKAMURA Takumi1-1/+1
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-02-12llvm-tblgen: Apply IWYU in some filesNAKAMURA Takumi1-0/+15
2023-01-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille1-1/+1
Use deduction guides instead of helper functions. The only non-automatic changes have been: 1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*)) 2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase. 3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated. 4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that). Per reviewers' comment, some useless makeArrayRef have been removed in the process. This is a follow-up to https://reviews.llvm.org/D140896 that introduced the deduction guides. Differential Revision: https://reviews.llvm.org/D140955
2022-12-06[llvm] Don't include Optional.h (NFC)Kazu Hirata1-1/+0
These source files no longer use Optional<T>, so they do not need to include Optional.h. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-06[TableGen] llvm::Optional => std::optionalFangrui Song1-3/+3
2022-12-02[utils] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+1
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-14[TableGen] Use MemoryEffects to represent intrinsic memory effects (NFCI)Nikita Popov1-56/+9
The TableGen implementation was using a homegrown implementation of FunctionModRefInfo. This switches it to use MemoryEffects instead. This makes the code simpler, and will allow exposing the full representational power of MemoryEffects in the future. Among other things, this will allow us to map IntrHasSideEffects to an inaccessiblemem readwrite, rather than just ignoring it entirely in most cases. To avoid layering issues, this moves the ModRef.h header from IR to Support, so that it can be included in the TableGen layer. Differential Revision: https://reviews.llvm.org/D137641
2022-11-04[IR] Switch everything to use memory attributeNikita Popov1-21/+25
This switches everything to use the memory attribute proposed in https://discourse.llvm.org/t/rfc-unify-memory-effect-attributes/65579. The old argmemonly, inaccessiblememonly and inaccessiblemem_or_argmemonly attributes are dropped. The readnone, readonly and writeonly attributes are restricted to parameters only. The old attributes are auto-upgraded both in bitcode and IR. The bitcode upgrade is a policy requirement that has to be retained indefinitely. The IR upgrade is mainly there so it's not necessary to update all tests using memory attributes in this patch, which is already large enough. We could drop that part after migrating tests, or retain it longer term, to make it easier to import IR from older LLVM versions. High-level Function/CallBase APIs like doesNotAccessMemory() or setDoesNotAccessMemory() are mapped transparently to the memory attribute. Code that directly manipulates attributes (e.g. via AttributeList) on the other hand needs to switch to working with the memory attribute instead. Differential Revision: https://reviews.llvm.org/D135780
2022-10-12[Attributes] Make intrinsic attribute generation more flexible (NFC)Nikita Popov1-185/+211
Currently attributes for intrinsics are emitted using the ArrayRef<AttrKind> based constructor for AttributeLists. This works out fine for simple enum attributes, but doesn't really generalize to attributes that accept values. We're already doing something awkward for alignment attributes, and I'd like to have a cleaner solution to this with https://discourse.llvm.org/t/rfc-unify-memory-effect-attributes/65579 in mind. The new generation approach is to instead directly construct Attributes, giving us access to the full generality of that interface. To avoid significantly increasing the size of the generated code, we now also deduplicate the attribute sets. The code generated per unique AttributeList looks like this: case 204: { AS[0] = {1, getIntrinsicArgAttributeSet(C, 5)}; AS[1] = {AttributeList::FunctionIndex, getIntrinsicFnAttributeSet(C, 10)}; NumAttrs = 2; break; } and then the helper functions contain something like case 5: return AttributeSet::get(C, { Attribute::get(C, Attribute::NoCapture), }); and case 10: return AttributeSet::get(C, { Attribute::get(C, Attribute::NoUnwind), Attribute::get(C, Attribute::ArgMemOnly), }); A casualty of this change is the intrin-properties.td test, as I don't think that FileCheck allows matching this kind of output. Differential Revision: https://reviews.llvm.org/D135679
2022-10-11[TableGen] Change representation of ArgumentAttributes (NFC)Nikita Popov1-67/+65
Instead of a flat list that includes the argument index, use a nested vector, where each inner vector is the attribute set for a single argument. This is more obvious and makes followup changes simpler.
2022-08-16[Intrinsics] Add initial support for NonNull attributeAlexander Shaposhnikov1-2/+8
Add initial support for NonNull attribute. (https://github.com/llvm/llvm-project/issues/57113) Test plan: verify that for __thread int x; int main() { int* y = &x; return *y; } (with this patch) clang -O -fsanitize=null -S -emit-llvm -o - doesn't emit a null-pointer check Differential revision: https://reviews.llvm.org/D131872
2022-08-08[llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song1-8/+8
With C++17 there is no Clang pedantic warning or MSVC C5051.
2022-06-22Rename GCCBuiltin into ClangBuiltinGuillaume Gomez1-5/+6
This patch is needed because developers expect "GCCBuiltin" items to be the GCC intrinsics equivalent and not the Clang internals. Reviewed By: #libc_abi, RKSimon, xbolva00 Differential Revision: https://reviews.llvm.org/D127460
2022-06-02[ValueTypes] Define MVTs for v128i2/v64i4 as well as i2 and i4.Hendrik Greving1-19/+25
Adds MVT::v128i2, MVT::v64i4, and implied MVT::i2, MVT::i4. Keeps MVT::i2, MVT::i4 lowering actions as expand, which should be removed once targets set this explicitly. Adjusts 11 lit tests to reflect slightly different behavior during DAG combine. Differential Revision: https://reviews.llvm.org/D125247
2022-06-01Revert "[ValueTypes] Define MVTs for v128i2/v64i4 as well as i2 and i4."Hendrik Greving1-25/+19
This reverts commit 430ac5c3029c52e391e584c6d4447e6e361fae99. Due to failures in Clang tests. Differential Revision: https://reviews.llvm.org/D125247