Skip to content

Commit f4d3a0c

Browse files
[TableGen] Simplify insertBits (NFC) (#137538)
We can use "constexpr if" to combine the two variants of functions.
1 parent 3170599 commit f4d3a0c

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,16 +2145,14 @@ static void emitInsertBits(formatted_raw_ostream &OS) {
21452145
// Helper function for inserting bits extracted from an encoded instruction into
21462146
// a field.
21472147
template <typename InsnType>
2148-
static std::enable_if_t<std::is_integral<InsnType>::value>
2149-
insertBits(InsnType &field, InsnType bits, unsigned startBit, unsigned numBits) {
2150-
assert(startBit + numBits <= sizeof field * 8);
2151-
field |= (InsnType)bits << startBit;
2152-
}
2153-
2154-
template <typename InsnType>
2155-
static std::enable_if_t<!std::is_integral<InsnType>::value>
2156-
insertBits(InsnType &field, uint64_t bits, unsigned startBit, unsigned numBits) {
2157-
field.insertBits(bits, startBit, numBits);
2148+
static void insertBits(InsnType &field, InsnType bits, unsigned startBit,
2149+
unsigned numBits) {
2150+
if constexpr (std::is_integral<InsnType>::value) {
2151+
assert(startBit + numBits <= sizeof field * 8);
2152+
field |= (InsnType)bits << startBit;
2153+
} else {
2154+
field.insertBits(bits, startBit, numBits);
2155+
}
21582156
}
21592157
)";
21602158
}

0 commit comments

Comments
 (0)