[llvm] [TableGen] Simplify insertBits (NFC) (PR #137538)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 27 11:15:28 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/137538
We can use "constexpr if" to combine the two variants of functions.
>From d745eb89d8e8059ebb75f1e7a47f3b3fee9c6103 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 27 Apr 2025 10:52:42 -0700
Subject: [PATCH] [TableGen] Simplify insertBits (NFC)
We can use "constexpr if" to combine the two variants of functions.
---
llvm/utils/TableGen/DecoderEmitter.cpp | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 415fe13f87547..f0f07dfce4abb 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -2145,16 +2145,14 @@ static void emitInsertBits(formatted_raw_ostream &OS) {
// Helper function for inserting bits extracted from an encoded instruction into
// a field.
template <typename InsnType>
-static std::enable_if_t<std::is_integral<InsnType>::value>
-insertBits(InsnType &field, InsnType bits, unsigned startBit, unsigned numBits) {
- assert(startBit + numBits <= sizeof field * 8);
- field |= (InsnType)bits << startBit;
-}
-
-template <typename InsnType>
-static std::enable_if_t<!std::is_integral<InsnType>::value>
-insertBits(InsnType &field, uint64_t bits, unsigned startBit, unsigned numBits) {
- field.insertBits(bits, startBit, numBits);
+static void insertBits(InsnType &field, InsnType bits, unsigned startBit,
+ unsigned numBits) {
+ if constexpr (std::is_integral<InsnType>::value) {
+ assert(startBit + numBits <= sizeof field * 8);
+ field |= (InsnType)bits << startBit;
+ } else {
+ field.insertBits(bits, startBit, numBits);
+ }
}
)";
}
More information about the llvm-commits
mailing list