Skip to content

Commit c919c39

Browse files
committed
[NFC][TableGen] Change DecoderEmitter insertBits to only use integer types
The `insertBits` templated function generated by DecoderEmitter is called with variable `tmp` of type `TmpType` which is: ``` using TmpType = std::conditional_t<std::is_integral<InsnType>::value, InsnType, uint64_t>; ``` That is, TmpType is always an integral type. Change the generated `insertBits` to be valid only for integer types, and eliminate the unused `insertBits` function from `DecoderUInt128` in AMDGPUDisassembler.h
1 parent 9293b65 commit c919c39

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ class DecoderUInt128 {
4343
DecoderUInt128() = default;
4444
DecoderUInt128(uint64_t Lo, uint64_t Hi = 0) : Lo(Lo), Hi(Hi) {}
4545
operator bool() const { return Lo || Hi; }
46-
void insertBits(uint64_t SubBits, unsigned BitPosition, unsigned NumBits) {
47-
assert(NumBits && NumBits <= 64);
48-
assert(SubBits >> 1 >> (NumBits - 1) == 0);
49-
assert(BitPosition < 128);
50-
if (BitPosition < 64) {
51-
Lo |= SubBits << BitPosition;
52-
Hi |= SubBits >> 1 >> (63 - BitPosition);
53-
} else {
54-
Hi |= SubBits << (BitPosition - 64);
55-
}
56-
}
5746
uint64_t extractBitsAsZExtValue(unsigned NumBits,
5847
unsigned BitPosition) const {
5948
assert(NumBits && NumBits <= 64);

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,8 +2184,6 @@ static void emitFieldFromInstruction(formatted_raw_ostream &OS) {
21842184
// Helper functions for extracting fields from encoded instructions.
21852185
// InsnType must either be integral or an APInt-like object that must:
21862186
// * be default-constructible and copy-constructible
2187-
// * be constructible from an APInt (this can be private)
2188-
// * Support insertBits(bits, startBit, numBits)
21892187
// * Support extractBitsAsZExtValue(numBits, startBit)
21902188
// * Support the ~, &, ==, and != operators with other objects of the same type
21912189
// * Support the != and bitwise & with uint64_t
@@ -2221,17 +2219,17 @@ fieldFromInstruction(const InsnType &insn, unsigned startBit,
22212219
static void emitInsertBits(formatted_raw_ostream &OS) {
22222220
OS << R"(
22232221
// Helper function for inserting bits extracted from an encoded instruction into
2224-
// a field.
2225-
template <typename InsnType>
2226-
static void insertBits(InsnType &field, InsnType bits, unsigned startBit,
2227-
unsigned numBits) {
2228-
if constexpr (std::is_integral<InsnType>::value) {
2229-
assert(startBit + numBits <= sizeof field * 8);
2230-
(void)numBits;
2231-
field |= (InsnType)bits << startBit;
2232-
} else {
2233-
field.insertBits(bits, startBit, numBits);
2234-
}
2222+
// an integer-typed field.
2223+
template <typename IntType>
2224+
static std::enable_if_t<std::is_integral_v<IntType>, void>
2225+
insertBits(IntType &field, IntType bits, unsigned startBit, unsigned numBits) {
2226+
// Check that no bit beyond numBits is set, so that a simple bitwise |
2227+
// is sufficient.
2228+
assert((~(((IntType)1 << numBits) - 1) & bits) == 0 &&
2229+
"bits has more than numBits bits set");
2230+
assert(startBit + numBits <= sizeof(IntType) * 8);
2231+
(void)numBits;
2232+
field |= bits << startBit;
22352233
}
22362234
)";
22372235
}

0 commit comments

Comments
 (0)