Skip to content

Commit

Permalink
[X86] Use static_asserts instead of assert (NFC)
Browse files Browse the repository at this point in the history
Identified with misc-static-assert.
  • Loading branch information
kazutakahirata committed Apr 29, 2024
1 parent fa8fda8 commit 501cfd5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
21 changes: 11 additions & 10 deletions llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1168,33 +1168,34 @@ inline int getMemoryOperandNo(uint64_t TSFlags) {

/// \returns true if the register is a XMM.
inline bool isXMMReg(unsigned RegNo) {
assert(X86::XMM15 - X86::XMM0 == 15 &&
"XMM0-15 registers are not continuous");
assert(X86::XMM31 - X86::XMM16 == 15 &&
"XMM16-31 registers are not continuous");
static_assert(X86::XMM15 - X86::XMM0 == 15,
"XMM0-15 registers are not continuous");
static_assert(X86::XMM31 - X86::XMM16 == 15,
"XMM16-31 registers are not continuous");
return (RegNo >= X86::XMM0 && RegNo <= X86::XMM15) ||
(RegNo >= X86::XMM16 && RegNo <= X86::XMM31);
}

/// \returns true if the register is a YMM.
inline bool isYMMReg(unsigned RegNo) {
assert(X86::YMM15 - X86::YMM0 == 15 &&
"YMM0-15 registers are not continuous");
assert(X86::YMM31 - X86::YMM16 == 15 &&
"YMM16-31 registers are not continuous");
static_assert(X86::YMM15 - X86::YMM0 == 15,
"YMM0-15 registers are not continuous");
static_assert(X86::YMM31 - X86::YMM16 == 15,
"YMM16-31 registers are not continuous");
return (RegNo >= X86::YMM0 && RegNo <= X86::YMM15) ||
(RegNo >= X86::YMM16 && RegNo <= X86::YMM31);
}

/// \returns true if the register is a ZMM.
inline bool isZMMReg(unsigned RegNo) {
assert(X86::ZMM31 - X86::ZMM0 == 31 && "ZMM registers are not continuous");
static_assert(X86::ZMM31 - X86::ZMM0 == 31,
"ZMM registers are not continuous");
return RegNo >= X86::ZMM0 && RegNo <= X86::ZMM31;
}

/// \returns true if \p RegNo is an apx extended register.
inline bool isApxExtendedReg(unsigned RegNo) {
assert(X86::R31WH - X86::R16 == 95 && "EGPRs are not continuous");
static_assert(X86::R31WH - X86::R16 == 95, "EGPRs are not continuous");
return RegNo >= X86::R16 && RegNo <= X86::R31WH;
}

Expand Down
9 changes: 5 additions & 4 deletions llvm/lib/Target/X86/X86RegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,11 @@ unsigned X86RegisterInfo::getNumSupportedRegs(const MachineFunction &MF) const {
// APX registers (R16-R31)
//
// and try to return the minimum number of registers supported by the target.
assert((X86::R15WH + 1 == X86 ::YMM0) && (X86::YMM15 + 1 == X86::K0) &&
(X86::K6_K7 + 1 == X86::TMMCFG) && (X86::TMM7 + 1 == X86::R16) &&
(X86::R31WH + 1 == X86::NUM_TARGET_REGS) &&
"Register number may be incorrect");
static_assert((X86::R15WH + 1 == X86::YMM0) && (X86::YMM15 + 1 == X86::K0) &&
(X86::K6_K7 + 1 == X86::TMMCFG) &&
(X86::TMM7 + 1 == X86::R16) &&
(X86::R31WH + 1 == X86::NUM_TARGET_REGS),
"Register number may be incorrect");

const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
if (ST.hasEGPR())
Expand Down

0 comments on commit 501cfd5

Please sign in to comment.