[llvm] [SelectionDAG] Use uint8_t instead of unsigned char for isel MatcherTable. (PR #174014)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 30 11:56:15 PST 2025
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/174014
These are really the same type, but uint8_t is more accurate since we make assumptions that a table element is 8 bits when we emit VBRs.
>From f9f29f4898177ae0bb27808623c918f386a885c3 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 30 Dec 2025 00:26:47 -0800
Subject: [PATCH] [SelectionDAG] Use uint8_t instead of unsigned char for
MatcherTable.
---
llvm/include/llvm/CodeGen/SelectionDAGISel.h | 2 +-
.../CodeGen/SelectionDAG/SelectionDAGISel.cpp | 46 +++++++++----------
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp | 2 +-
3 files changed, 23 insertions(+), 27 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGISel.h b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
index 147e780dfc191..61c5fdc9ef2ba 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGISel.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
@@ -451,7 +451,7 @@ class SelectionDAGISel {
llvm_unreachable("Tblgen should generate this!");
}
- void SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
+ void SelectCodeCommon(SDNode *NodeToMatch, const uint8_t *MatcherTable,
unsigned TableSize);
/// Return true if complex patterns for this target can mutate the
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index f95273b4f1016..1c9e6bd5672be 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -2704,7 +2704,7 @@ void SelectionDAGISel::Select_PATCHPOINT(SDNode *N) {
/// GetVBR - decode a vbr encoding whose top bit is set.
LLVM_ATTRIBUTE_ALWAYS_INLINE static uint64_t
-GetVBR(uint64_t Val, const unsigned char *MatcherTable, unsigned &Idx) {
+GetVBR(uint64_t Val, const uint8_t *MatcherTable, unsigned &Idx) {
assert(Val >= 128 && "Not a VBR");
Val &= 127; // Remove first vbr bit.
@@ -2722,7 +2722,7 @@ GetVBR(uint64_t Val, const unsigned char *MatcherTable, unsigned &Idx) {
/// getSimpleVT - Decode a value in MatcherTable, if it's a VBR encoded value,
/// use GetVBR to decode it.
LLVM_ATTRIBUTE_ALWAYS_INLINE static MVT::SimpleValueType
-getSimpleVT(const unsigned char *MatcherTable, unsigned &MatcherIndex) {
+getSimpleVT(const uint8_t *MatcherTable, unsigned &MatcherIndex) {
unsigned SimpleVT = MatcherTable[MatcherIndex++];
if (SimpleVT & 128)
SimpleVT = GetVBR(SimpleVT, MatcherTable, MatcherIndex);
@@ -2926,7 +2926,7 @@ MorphNode(SDNode *Node, unsigned TargetOpc, SDVTList VTList,
/// CheckSame - Implements OP_CheckSame.
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
-CheckSame(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N,
+CheckSame(const uint8_t *MatcherTable, unsigned &MatcherIndex, SDValue N,
const SmallVectorImpl<std::pair<SDValue, SDNode *>> &RecordedNodes) {
// Accept if it is exactly the same as a previously recorded node.
unsigned RecNo = MatcherTable[MatcherIndex++];
@@ -2936,7 +2936,7 @@ CheckSame(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N,
/// CheckChildSame - Implements OP_CheckChildXSame.
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool CheckChildSame(
- const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N,
+ const uint8_t *MatcherTable, unsigned &MatcherIndex, SDValue N,
const SmallVectorImpl<std::pair<SDValue, SDNode *>> &RecordedNodes,
unsigned ChildNo) {
if (ChildNo >= N.getNumOperands())
@@ -2947,7 +2947,7 @@ LLVM_ATTRIBUTE_ALWAYS_INLINE static bool CheckChildSame(
/// CheckPatternPredicate - Implements OP_CheckPatternPredicate.
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
-CheckPatternPredicate(unsigned Opcode, const unsigned char *MatcherTable,
+CheckPatternPredicate(unsigned Opcode, const uint8_t *MatcherTable,
unsigned &MatcherIndex, const SelectionDAGISel &SDISel) {
bool TwoBytePredNo =
Opcode == SelectionDAGISel::OPC_CheckPatternPredicateTwoByte;
@@ -2962,7 +2962,7 @@ CheckPatternPredicate(unsigned Opcode, const unsigned char *MatcherTable,
/// CheckNodePredicate - Implements OP_CheckNodePredicate.
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
-CheckNodePredicate(unsigned Opcode, const unsigned char *MatcherTable,
+CheckNodePredicate(unsigned Opcode, const uint8_t *MatcherTable,
unsigned &MatcherIndex, const SelectionDAGISel &SDISel,
SDValue Op) {
unsigned PredNo = Opcode == SelectionDAGISel::OPC_CheckPredicate
@@ -2972,8 +2972,7 @@ CheckNodePredicate(unsigned Opcode, const unsigned char *MatcherTable,
}
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
-CheckOpcode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
- SDNode *N) {
+CheckOpcode(const uint8_t *MatcherTable, unsigned &MatcherIndex, SDNode *N) {
uint16_t Opc = MatcherTable[MatcherIndex++];
Opc |= static_cast<uint16_t>(MatcherTable[MatcherIndex++]) << 8;
return N->getOpcode() == Opc;
@@ -2999,14 +2998,13 @@ CheckChildType(MVT::SimpleValueType VT, SDValue N, const TargetLowering *TLI,
}
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
-CheckCondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
- SDValue N) {
+CheckCondCode(const uint8_t *MatcherTable, unsigned &MatcherIndex, SDValue N) {
return cast<CondCodeSDNode>(N)->get() ==
static_cast<ISD::CondCode>(MatcherTable[MatcherIndex++]);
}
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
-CheckChild2CondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
+CheckChild2CondCode(const uint8_t *MatcherTable, unsigned &MatcherIndex,
SDValue N) {
if (2 >= N.getNumOperands())
return false;
@@ -3014,8 +3012,8 @@ CheckChild2CondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
}
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
-CheckValueType(const unsigned char *MatcherTable, unsigned &MatcherIndex,
- SDValue N, const TargetLowering *TLI, const DataLayout &DL) {
+CheckValueType(const uint8_t *MatcherTable, unsigned &MatcherIndex, SDValue N,
+ const TargetLowering *TLI, const DataLayout &DL) {
MVT::SimpleValueType VT = getSimpleVT(MatcherTable, MatcherIndex);
if (cast<VTSDNode>(N)->getVT() == VT)
return true;
@@ -3036,8 +3034,7 @@ static uint64_t decodeSignRotatedValue(uint64_t V) {
}
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
-CheckInteger(const unsigned char *MatcherTable, unsigned &MatcherIndex,
- SDValue N) {
+CheckInteger(const uint8_t *MatcherTable, unsigned &MatcherIndex, SDValue N) {
int64_t Val = MatcherTable[MatcherIndex++];
if (Val & 128)
Val = GetVBR(Val, MatcherTable, MatcherIndex);
@@ -3049,7 +3046,7 @@ CheckInteger(const unsigned char *MatcherTable, unsigned &MatcherIndex,
}
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
-CheckChildInteger(const unsigned char *MatcherTable, unsigned &MatcherIndex,
+CheckChildInteger(const uint8_t *MatcherTable, unsigned &MatcherIndex,
SDValue N, unsigned ChildNo) {
if (ChildNo >= N.getNumOperands())
return false; // Match fails if out of range child #.
@@ -3057,8 +3054,8 @@ CheckChildInteger(const unsigned char *MatcherTable, unsigned &MatcherIndex,
}
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
-CheckAndImm(const unsigned char *MatcherTable, unsigned &MatcherIndex,
- SDValue N, const SelectionDAGISel &SDISel) {
+CheckAndImm(const uint8_t *MatcherTable, unsigned &MatcherIndex, SDValue N,
+ const SelectionDAGISel &SDISel) {
int64_t Val = MatcherTable[MatcherIndex++];
if (Val & 128)
Val = GetVBR(Val, MatcherTable, MatcherIndex);
@@ -3070,7 +3067,7 @@ CheckAndImm(const unsigned char *MatcherTable, unsigned &MatcherIndex,
}
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
-CheckOrImm(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N,
+CheckOrImm(const uint8_t *MatcherTable, unsigned &MatcherIndex, SDValue N,
const SelectionDAGISel &SDISel) {
int64_t Val = MatcherTable[MatcherIndex++];
if (Val & 128)
@@ -3088,11 +3085,10 @@ CheckOrImm(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N,
/// known to pass, set Result=false and return the MatcherIndex to continue
/// with. If the current predicate is unknown, set Result=false and return the
/// MatcherIndex to continue with.
-static unsigned IsPredicateKnownToFail(const unsigned char *Table,
- unsigned Index, SDValue N,
- bool &Result,
- const SelectionDAGISel &SDISel,
- SmallVectorImpl<std::pair<SDValue, SDNode*>> &RecordedNodes) {
+static unsigned IsPredicateKnownToFail(
+ const uint8_t *Table, unsigned Index, SDValue N, bool &Result,
+ const SelectionDAGISel &SDISel,
+ SmallVectorImpl<std::pair<SDValue, SDNode *>> &RecordedNodes) {
unsigned Opcode = Table[Index++];
switch (Opcode) {
default:
@@ -3297,7 +3293,7 @@ class MatchStateUpdater : public SelectionDAG::DAGUpdateListener
} // end anonymous namespace
void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
- const unsigned char *MatcherTable,
+ const uint8_t *MatcherTable,
unsigned TableSize) {
// FIXME: Should these even be selected? Handle these cases in the caller?
switch (NodeToMatch->getOpcode()) {
diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
index baedfc871e854..1c809db2986a6 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -1419,7 +1419,7 @@ void llvm::EmitMatcherTable(Matcher *TheMatcher, const CodeGenDAGPatterns &CGP,
OS << " #define TARGET_VAL(X) X & 255, unsigned(X) >> 8\n";
OS << " #define COVERAGE_IDX_VAL(X) X & 255, (unsigned(X) >> 8) & 255, ";
OS << "(unsigned(X) >> 16) & 255, (unsigned(X) >> 24) & 255\n";
- OS << " static const unsigned char MatcherTable[] = {\n";
+ OS << " static const uint8_t MatcherTable[] = {\n";
TotalSize = MatcherEmitter.EmitMatcherList(TheMatcher, 1, 0, OS);
OS << " 0\n }; // Total Array size is " << (TotalSize + 1)
<< " bytes\n\n";
More information about the llvm-commits
mailing list