aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-05-03[NFC] Rename `FixedLenDecoderEmitter` as `DecoderEmitter`Sheng1-2702/+0
Since now we are able to handle both fixed length & variable length instructions. Reviewed By: myhsu Differential Revision: https://reviews.llvm.org/D123451
2022-05-03[TableGen] Add support for variable length instruction in decoder generatorSheng1-257/+395
To support variable length instructions, I think of them as fixed length instructions with the "maximum length". For example, if there're three instructions with 2, 6 and 9 bytes, we can fit them into the algorithm by treating them all as 9 bytes. Also, since we can't know the length of the instruction in advance, there is a function object with type `void(APInt &, uint64_t)` added in the parameter list of `decodeInstruction` and `fieldFromInstruction`. We can use this to supply the additional bits the decoder needs after we know the opcode of the instruction. Finally, `InstrLenTable` is added to let the decoder know the length of the instructions. See D120960 for its usage. Reviewed By: myhsu Differential Revision: https://reviews.llvm.org/D120958
2022-05-03Revert "Fix a misuse of `cast`"Sheng1-1/+1
This reverts commit ba59ec2843f99f19d55d7cd9f9ac536fb038fdab.
2022-04-11Fix a misuse of `cast`Sheng1-1/+1
`cast` will assert instead of returning null pointer.
2022-03-25[Disassember][NFCI] Use strong type for instruction decoderMaksim Panchenko1-3/+4
All LLVM backends use MCDisassembler as a base class for their instruction decoders. Use "const MCDisassembler *" for the decoder instead of "const void *". Remove unnecessary static casts. Reviewed By: skan Differential Revision: https://reviews.llvm.org/D122245
2022-03-22[TableGen] Fix a misuse of getValueAsBitsInitSheng1-5/+6
`getValueAsBitsInit` will assert when the "SoftFail" isn't presented. But given the 'if' statement below, we should've allowed this situation. This patch fix this.
2022-02-09Prepare for LLVMMC headers cleanupserge-sans-paille1-0/+2
Be more explicit about which headers should be included in MC files generated by tblgen. See also: https://reviews.llvm.org/D119244
2021-05-07[TableGen] Use range-based for loops (NFC)Coelacanthus1-5/+5
Use range-based for loops in TableGen. Reviewed By: Paul-C-Anagnostopoulos Differential Revision: https://reviews.llvm.org/D101994
2021-03-17[TableGen] Fix excessive compile time issue in FixedLenDecoderEmitterJay Foad1-32/+50
This patch reduces the time taken for clang to compile the generated disassembler for an out-of-tree target with InsnType bigger than 64 bits from 4m30s to 48s. D67686 did a similar thing for CodeEmitterGen. The idea is to tweak the API of the APInt-like InsnType class so that we don't need so many temporary InsnTypes. This takes advantage of the rule stated in D52100 that currently "no string of bits extracted from the encoding may exceeed 64-bits", so we can use uint64_t for some temporaries. D52100 goes on to say that "fields are still permitted to exceed 64-bits so long as they aren't one contiguous string of bits". This patch breaks that by always using a "uint64_t tmp" in the generated decodeToMCInst, but it should be easy to fix in FilterChooser::emitBinaryParser by choosing to use a different type of tmp based on the known total field width. Differential Revision: https://reviews.llvm.org/D98046
2021-02-28[TableGen] Use ListSeparator (NFC)Kazu Hirata1-9/+2
2021-02-11[TableGen] Make the map in InfoByHwMode protected. NFCICraig Topper1-2/+2
Switch some for loops to just use the begin()/end() implementations in the InfoByHwMode struct. Add a method to insert into the map for the one case that was modifying the map directly.
2021-01-29[llvm] Use isa instead of dyn_cast (NFC)Kazu Hirata1-1/+1
2021-01-07[TableGen] Add field kind to the RecordVal class.Paul C. Anagnostopoulos1-1/+1
Differential Revision: https://reviews.llvm.org/D93969
2021-01-02[TableGen] Use llvm::append_range (NFC)Kazu Hirata1-4/+3
2021-01-01[llvm] Use isa instead of dyn_cast (NFC)Kazu Hirata1-1/+1
2020-12-14[TableGen] Fixed 64-bit filters being sliced to 32 bits in ↵Cameron Desrochers1-7/+8
FixedLenDecoderEmitter When using the FixedLenDecoderEmitter, llvm-tblgen emits tables with (OPC_ExtractField, OPC_ExtractFilterValue) opcode sequences to match the contiguous fixed bits of a given instruction's encoding. This encoding is represented in a 64-bit integer. However, the filter values were represented in a 32-bit integer. As such, instructions with fixed 64-bit encodings resulted in a table with an OPC_ExtractField for all 64 bits, followed by an OPC_ExtractFilterValue containing just the low 32 bits of their encoding, causing the filter never to match. The exact point at which the slicing occurred was during the map insertion at line 630. Differential Revision: https://reviews.llvm.org/D92423
2020-11-06[TableGen] Indentation and whitespace fixes in generated code. NFC.Jay Foad1-9/+9
Some of these were found by running clang-format over the generated code, although that complains about far more issues than I have fixed here. Differential Revision: https://reviews.llvm.org/D90937
2020-03-13[TableGen] Support combining AssemblerPredicates with ORsSimon Cook1-24/+40
For context, the proposed RISC-V bit manipulation extension has a subset of instructions which require one of two SubtargetFeatures to be enabled, 'zbb' or 'zbp', and there is no defined feature which both of these can imply to use as a constraint either (see comments in D65649). AssemblerPredicates allow multiple SubtargetFeatures to be declared in the "AssemblerCondString" field, separated by commas, and this means that the two features must both be enabled. There is no equivalent to say that _either_ feature X or feature Y must be enabled, short of creating a dummy SubtargetFeature for this purpose and having features X and Y imply the new feature. To solve the case where X or Y is needed without adding a new feature, and to better match a typical TableGen style, this replaces the existing "AssemblerCondString" with a dag "AssemblerCondDag" which represents the same information. Two operators are defined for use with AssemblerCondDag, "all_of", which matches the current behaviour, and "any_of", which adds the new proposed ORing features functionality. This was originally proposed in the RFC at http://lists.llvm.org/pipermail/llvm-dev/2020-February/139138.html Changes to all current backends are mechanical to support the replaced functionality, and are NFCI. At this stage, it is illegal to combine features with ands and ors in a single AssemblerCondDag. I suspect this case is sufficiently rare that adding more complex changes to support it are unnecessary. Differential Revision: https://reviews.llvm.org/D74338
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-16/+21
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2019-11-09Reduce scope of variable to silence cppcheck warning. NFCSimon Pilgrim1-2/+1
2019-09-19[TableGen] Support encoding per-HwModeJames Molloy1-9/+56
Much like ValueTypeByHwMode/RegInfoByHwMode, this patch allows targets to modify an instruction's encoding based on HwMode. When the EncodingInfos field is non-empty the Inst and Size fields of the Instruction are ignored and taken from EncodingInfos instead. As part of this promote getHwMode() from TargetSubtargetInfo to MCSubtargetInfo. This is NFC for all existing targets - new code is generated only if targets use EncodingByHwMode. llvm-svn: 372320
2019-08-25[TableGen] Correct comments for end of namespace. NFCBjorn Pettersson1-1/+1
Summary: Update end-of-namespace comments generated by tablegen emitters to fulfill the rules setup by clang-tidy's llvm-namespace-comment checker. Fixed a few end-of-namespace comments in the tablegen source code as well. Reviewers: craig.topper Reviewed By: craig.topper Subscribers: craig.topper, stoklund, dschuff, sbc100, jgravelle-google, aheejin, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66396 llvm-svn: 369865
2019-08-15[llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-2/+2
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013
2019-08-10[TableGen] Correct the shift to the proper bit width.Michael Liao1-1/+1
- Replace the previous 32-bit shift with 64-bit one matching `OpInit`. llvm-svn: 368513
2019-08-09[TableGen] Add "InitValue": Handle operands with set bit values in decoder ↵Daniel Sanders1-4/+18
methods Summary: The problem: When an operand had bits explicitly set to "1" (as in the InitValue.td test case attached), the decoder was ignoring those bits, and the DecoderMethod was receiving an input where the bits were still zero. The solution: We added an "InitValue" variable that stores the initial value of the operand based on what bits were explicitly initialized to 1 in TableGen code. The generated decoder code then uses that initial value to initialize the "tmp" variable, then calls fieldFromInstruction to read the values for the remaining bits that were left unknown in TableGen. This is mainly useful when there are variations of an instruction that differ based on what bits are set in the operands, since this change makes it possible to access those bits in a DecoderMethod. The DecoderMethod can use those bits to know how to handle the input. Patch by Nicolas Guillemot Reviewers: craig.topper, dsanders, fhahn Reviewed By: dsanders Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D63741 llvm-svn: 368458
2019-06-18Re-commit r363744: [tblgen][disasm] Allow multiple encodings to disassemble ↵Daniel Sanders1-45/+95
to the same instruction It seems macOS lets you have ArrayRef<const X> even though this is apparently forbidden by the language standard (Thanks MSVC++ for the clear error message). Removed the problematic const's to fix this. (It also seems I'm not receiving buildbot emails anymore and I'm trying to find out why. In the mean time I'll be polling lab.llvm.org to hopefully see if/when failures occur) llvm-svn: 363753
2019-06-18Revert [tblgen][disasm] Allow multiple encodings to disassemble to the same ↵Jordan Rupprecht1-98/+48
instruction This reverts r363744 (git commit 9b2252123d1e79d2b3594097a9d9cc60072b83d9) This breaks many buildbots, e.g. http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/203/steps/build%20stage%201/logs/stdio llvm-svn: 363747
2019-06-18[tblgen][disasm] Allow multiple encodings to disassemble to the same instructionDaniel Sanders1-48/+98
Summary: Add an AdditionalEncoding class which can be used to define additional encodings for a given instruction. This causes the disassembler to add an additional encoding to its matching tables that map to the specified instruction. Usage: def ADD1 : Instruction { bits<8> Reg; bits<32> Inst; let Size = 4; let Inst{0-7} = Reg; let Inst{8-14} = 0; let Inst{15} = 1; // Continuation bit let Inst{16-31} = 0; ... } def : AdditionalEncoding<ADD1> { bits<8> Reg; bits<16> Inst; // You can also have bits<32> and it will still be a 16-bit encoding let Size = 2; let Inst{0-3} = 0; let Inst{4-7} = Reg; let Inst{8-15} = 0; ... } with those definitions, llvm-mc will successfully disassemble both of these: 0x01 0x00 0x10 0x80 0x00 0x00 to: ADD1 r1 Depends on D52366 Reviewers: bogner, charukcs Reviewed By: bogner Subscribers: nlguillemot, nhaehnle, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D52369 llvm-svn: 363744
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2019-01-03[tblgen][disasm] Emit record names again when decoder conflicts occur.Daniel Sanders1-1/+1
And add a test for it. llvm-svn: 350277
2018-12-13Recommit r349041: [tblgen][disasm] Separate encodings from instructionsDaniel Sanders1-37/+51
Removed const from the ArrayRef<const EncodingAndInst> to avoid the std::vector<const EncodingAndInst> that G++ saw llvm-svn: 349055
2018-12-13Revert r349041: [tblgen][disasm] Separate encodings from instructionsDaniel Sanders1-51/+37
One of the GCC based bots is objecting to a vector of const EncodingAndInst's: In file included from /usr/include/c++/8/vector:64, from /export/users/atombot/llvm/clang-atom-d525-fedora-rel/llvm/utils/TableGen/CodeGenInstruction.h:22, from /export/users/atombot/llvm/clang-atom-d525-fedora-rel/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp:15: /usr/include/c++/8/bits/stl_vector.h: In instantiation of 'class std::vector<const {anonymous}::EncodingAndInst, std::allocator<const {anonymous}::EncodingAndInst> >': /export/users/atombot/llvm/clang-atom-d525-fedora-rel/llvm/utils/TableGen/FixedLenDecoderEmitter.cpp:375:32: required from here /usr/include/c++/8/bits/stl_vector.h:351:21: error: static assertion failed: std::vector must have a non-const, non-volatile value_type static_assert(is_same<typename remove_cv<_Tp>::type, _Tp>::value, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/8/bits/stl_vector.h:354:21: error: static assertion failed: std::vector must have the same value_type as its allocator static_assert(is_same<typename _Alloc::value_type, _Tp>::value, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ llvm-svn: 349046
2018-12-13[tblgen][disasm] Separate encodings from instructionsDaniel Sanders1-37/+51
Summary: Separate the concept of an encoding from an instruction. This will enable the definition of additional encodings for the same instruction which can be used to support variable length instruction sets in the disassembler (and potentially assembler but I'm not working towards that right now) without causing an explosion in the number of Instruction records that CodeGen then has to pick between. Reviewers: bogner, charukcs Reviewed By: bogner Subscribers: kparzysz, llvm-commits Differential Revision: https://reviews.llvm.org/D52366 llvm-svn: 349041
2018-10-23Fix MSVC build by correcting placement of declspec after r345056Daniel Sanders1-1/+1
Going by the MSVC toolchains at godbolt.org, declspec comes after the template<...>. llvm-svn: 345059
2018-10-23[tblgen] Allow FixedLenDecoderEmitter to use APInt-like objects as InsnTypeDaniel Sanders1-11/+49
Summary: Some targets have very long encodings and uint64_t isn't sufficient. uint128_t isn't portable so such targets need to use an object instead. There is one catch with this at the moment, no string of bits extracted from the encoding may exceeed 64-bits. Fields are still permitted to exceed 64-bits so long as they aren't one contiguous string of bits. If this proves to be a problem then we can modify the generation of fieldFromInstruction() calls to account for it but for now I've added an assertion for this. InsnType must either be integral or an APInt-like object that must: * Have a static const max_size_in_bits equal to the number of bits in the encoding. * be default-constructible and copy-constructible * be constructible from a uint64_t (this is the key area the interface deviates from APInt since this constructor does not take the bit width) * be constructible from an APInt (this can be private) * be convertible to uint64_t * Support the ~, &,, ==, !=, and |= operators with other objects of the same type * Support shift (<<, >>) with signed and unsigned integers on the RHS * Support put (<<) to raw_ostream& Reviewers: bogner, charukcs Subscribers: nhaehnle, llvm-commits Differential Revision: https://reviews.llvm.org/D52100 llvm-svn: 345056
2018-07-25[windows] Don't inline fieldFromInstruction on WindowsStella Stamenova1-1/+7
Summary: The VS compiler (on Windows) has a bug which results in fieldFromInstruction being optimized out in some circumstances. This only happens in *release no debug info* builds that have assertions *turned off* - in all other situations the function is not inlined, so the functionality is correct. All of the bots have assertions turned on, so this path is not regularly tested. The workaround is to not inline the function on Windows - if the bug is fixed in a later release of the VS compiler, the noinline specification can be removed. The test that consistently reproduces this is Lanai v11.txt test. Reviewers: asmith, labath, zturner Subscribers: dblaikie, stella.stamenova, aprantl, JDevlieghere, llvm-commits Differential Revision: https://reviews.llvm.org/D49753 llvm-svn: 337942
2018-07-05[TableGen] Increase the number of supported decoder fix-ups.Sander de Smalen1-18/+40
The vast number of added instructions for SVE causes TableGen to fail with an assertion: Assertion `Delta < 65536U && "disassembler decoding table too large!"' This patch increases the number of supported decoder fix-ups. Reviewers: dmgreen, stoklund, petpav01 Reviewed By: dmgreen Differential Revision: https://reviews.llvm.org/D48937 llvm-svn: 336334
2018-05-14Rename DEBUG macro to LLVM_DEBUG.Nicola Zaghen1-26/+46
The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM - Manual change to APInt - Manually chage DOCS as regex doesn't match it. In the transition period the DEBUG() macro is still present and aliased to the LLVM_DEBUG() one. Differential Revision: https://reviews.llvm.org/D43624 llvm-svn: 332240
2018-03-05TableGen: Use DefInit::getDef() instead of the type's getRecord()Nicolai Haehnle1-14/+11
The former simply makes more sense: we want to access the data here in the backend, not information about the type. More importantly, removing users of RecordRecTy::getRecord() allows us more freedom to refactor the frontend. Change-Id: Iee8905fd22cdb9b11c42ca03246c03d8fe4dd77f llvm-svn: 326699
2017-07-05[tablegen] Avoid creating temporary stringsAlexander Shaposhnikov1-3/+1
If a method / function returns a StringRef but the variable is of type const std::string& a temporary string is created (StringRef has a cast operator to std::string), which is a suboptimal behavior. Differential revision: https://reviews.llvm.org/D34994 Test plan: make check-all llvm-svn: 307195
2017-05-31[TableGen] Adapt more places to getValueAsString now returning a StringRef ↵Craig Topper1-8/+7
instead of a std::string. llvm-svn: 304347
2016-12-05TableGen: Use StringInit instead of std::string for DagInit arg namesMatthias Braun1-3/+5
llvm-svn: 288644
2016-12-04TableGen: Use StringRef instead of const std::string& in return vals.Matthias Braun1-3/+3
This will allow to switch to a different string storage in an upcoming commit. llvm-svn: 288612
2016-11-30Fix some Clang-tidy and Include What You Use warnings; other minor fixes (NFC).Eugene Zelenko1-47/+58
This preparation to remove SetVector.h dependency on SmallSet.h. llvm-svn: 288256
2016-10-21Switch SmallSetVector to use DenseSet when it overflows its inline space.Justin Lebar1-5/+6
Summary: SetVector already used DenseSet, but SmallSetVector used std::set. This leads to surprising performance differences. Moreover, it means that the set of key types accepted by SetVector and SmallSetVector are quite different! In order to make this change, we had to convert some callsites that used SmallSetVector<std::string, N> to use SmallSetVector<CachedHashString, N> instead. Reviewers: timshen Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25648 llvm-svn: 284887
2016-10-04Use StringRef in TableGen (NFC)Mehdi Amini1-1/+1
llvm-svn: 283273
2016-08-12Use the range variant of find/find_if instead of unpacking begin/endDavid Majnemer1-6/+2
If the result of the find is only used to compare against end(), just use is_contained instead. No functionality change is intended. llvm-svn: 278469
2016-07-18TableGen: Allow custom register operand decoder methodMatt Arsenault1-25/+33
This is for a situation where the encoding for a register may be different depending on the specific operand. For some instructions, we want to apply additional restrictions beyond the encoding's constraints. In AMDGPU some operands are VSrc_32, using the VS_32 pseudo register class which accept VGPRs, SGPRs, or immediates in the encoding. Some specific instructions with the same encoding operand do not want to allow immediates or SGPRs, but the encoding format is different in this case than a regular VGPR_32 operand. This allows specifying the encoding should be treated the same without introducing yet another dummy register class. llvm-svn: 275929
2016-07-04[TableGen] Remove dead code. NFCI.Davide Italiano1-28/+0
llvm-svn: 274515
2016-06-08Apply most suggestions of clang-tidy's performance-unnecessary-value-paramBenjamin Kramer1-6/+4
Avoids unnecessary copies. All changes audited & pass tests with asan. No functional change intended. llvm-svn: 272190