Skip to content

Commit d49e9d8

Browse files
authored
[SelectionDAG][NFC] Replace C-style casting with static_cast (#74060)
Fix comments in #73283.
1 parent 725656b commit d49e9d8

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,7 +2641,7 @@ MorphNode(SDNode *Node, unsigned TargetOpc, SDVTList VTList,
26412641
unsigned ResNumResults = Res->getNumValues();
26422642
// Move the glue if needed.
26432643
if ((EmitNodeInfo & OPFL_GlueOutput) && OldGlueResultNo != -1 &&
2644-
(unsigned)OldGlueResultNo != ResNumResults-1)
2644+
static_cast<unsigned>(OldGlueResultNo) != ResNumResults - 1)
26452645
ReplaceUses(SDValue(Node, OldGlueResultNo),
26462646
SDValue(Res, ResNumResults - 1));
26472647

@@ -2650,7 +2650,7 @@ MorphNode(SDNode *Node, unsigned TargetOpc, SDVTList VTList,
26502650

26512651
// Move the chain reference if needed.
26522652
if ((EmitNodeInfo & OPFL_Chain) && OldChainResultNo != -1 &&
2653-
(unsigned)OldChainResultNo != ResNumResults-1)
2653+
static_cast<unsigned>(OldChainResultNo) != ResNumResults - 1)
26542654
ReplaceUses(SDValue(Node, OldChainResultNo),
26552655
SDValue(Res, ResNumResults - 1));
26562656

@@ -2707,15 +2707,17 @@ LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
27072707
CheckOpcode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
27082708
SDNode *N) {
27092709
uint16_t Opc = MatcherTable[MatcherIndex++];
2710-
Opc |= (unsigned short)MatcherTable[MatcherIndex++] << 8;
2710+
Opc |= static_cast<uint16_t>(MatcherTable[MatcherIndex++]) << 8;
27112711
return N->getOpcode() == Opc;
27122712
}
27132713

27142714
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
27152715
CheckType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N,
27162716
const TargetLowering *TLI, const DataLayout &DL) {
2717-
MVT::SimpleValueType VT = (MVT::SimpleValueType)MatcherTable[MatcherIndex++];
2718-
if (N.getValueType() == VT) return true;
2717+
MVT::SimpleValueType VT =
2718+
static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
2719+
if (N.getValueType() == VT)
2720+
return true;
27192721

27202722
// Handle the case when VT is iPTR.
27212723
return VT == MVT::iPTR && N.getValueType() == TLI->getPointerTy(DL);
@@ -2735,7 +2737,7 @@ LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
27352737
CheckCondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
27362738
SDValue N) {
27372739
return cast<CondCodeSDNode>(N)->get() ==
2738-
(ISD::CondCode)MatcherTable[MatcherIndex++];
2740+
static_cast<ISD::CondCode>(MatcherTable[MatcherIndex++]);
27392741
}
27402742

27412743
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
@@ -2749,7 +2751,8 @@ CheckChild2CondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
27492751
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
27502752
CheckValueType(const unsigned char *MatcherTable, unsigned &MatcherIndex,
27512753
SDValue N, const TargetLowering *TLI, const DataLayout &DL) {
2752-
MVT::SimpleValueType VT = (MVT::SimpleValueType)MatcherTable[MatcherIndex++];
2754+
MVT::SimpleValueType VT =
2755+
static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
27532756
if (cast<VTSDNode>(N)->getVT() == VT)
27542757
return true;
27552758

@@ -3101,7 +3104,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
31013104

31023105
// Get the opcode, add the index to the table.
31033106
uint16_t Opc = MatcherTable[Idx++];
3104-
Opc |= (unsigned short)MatcherTable[Idx++] << 8;
3107+
Opc |= static_cast<uint16_t>(MatcherTable[Idx++]) << 8;
31053108
if (Opc >= OpcodeOffset.size())
31063109
OpcodeOffset.resize((Opc+1)*2);
31073110
OpcodeOffset[Opc] = Idx;
@@ -3118,7 +3121,8 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
31183121
#ifndef NDEBUG
31193122
unsigned CurrentOpcodeIndex = MatcherIndex;
31203123
#endif
3121-
BuiltinOpcodes Opcode = (BuiltinOpcodes)MatcherTable[MatcherIndex++];
3124+
BuiltinOpcodes Opcode =
3125+
static_cast<BuiltinOpcodes>(MatcherTable[MatcherIndex++]);
31223126
switch (Opcode) {
31233127
case OPC_Scope: {
31243128
// Okay, the semantics of this operation are that we should push a scope
@@ -3327,7 +3331,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
33273331
if (CaseSize == 0) break;
33283332

33293333
uint16_t Opc = MatcherTable[MatcherIndex++];
3330-
Opc |= (unsigned short)MatcherTable[MatcherIndex++] << 8;
3334+
Opc |= static_cast<uint16_t>(MatcherTable[MatcherIndex++]) << 8;
33313335

33323336
// If the opcode matches, then we will execute this case.
33333337
if (CurNodeOpcode == Opc)
@@ -3357,7 +3361,8 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
33573361
CaseSize = GetVBR(CaseSize, MatcherTable, MatcherIndex);
33583362
if (CaseSize == 0) break;
33593363

3360-
MVT CaseVT = (MVT::SimpleValueType)MatcherTable[MatcherIndex++];
3364+
MVT CaseVT =
3365+
static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
33613366
if (CaseVT == MVT::iPTR)
33623367
CaseVT = TLI->getPointerTy(CurDAG->getDataLayout());
33633368

@@ -3474,7 +3479,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
34743479
VT = MVT::i64;
34753480
break;
34763481
default:
3477-
VT = (MVT::SimpleValueType)MatcherTable[MatcherIndex++];
3482+
VT = static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
34783483
break;
34793484
}
34803485
int64_t Val = MatcherTable[MatcherIndex++];
@@ -3488,7 +3493,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
34883493
}
34893494
case OPC_EmitRegister: {
34903495
MVT::SimpleValueType VT =
3491-
(MVT::SimpleValueType)MatcherTable[MatcherIndex++];
3496+
static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
34923497
unsigned RegNo = MatcherTable[MatcherIndex++];
34933498
RecordedNodes.push_back(std::pair<SDValue, SDNode*>(
34943499
CurDAG->getRegister(RegNo, VT), nullptr));
@@ -3499,7 +3504,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
34993504
// values are stored in two bytes in the matcher table (just like
35003505
// opcodes).
35013506
MVT::SimpleValueType VT =
3502-
(MVT::SimpleValueType)MatcherTable[MatcherIndex++];
3507+
static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
35033508
unsigned RegNo = MatcherTable[MatcherIndex++];
35043509
RegNo |= MatcherTable[MatcherIndex++] << 8;
35053510
RecordedNodes.push_back(std::pair<SDValue, SDNode*>(
@@ -3645,7 +3650,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
36453650
case OPC_EmitNode0: case OPC_EmitNode1: case OPC_EmitNode2:
36463651
case OPC_MorphNodeTo0: case OPC_MorphNodeTo1: case OPC_MorphNodeTo2: {
36473652
uint16_t TargetOpc = MatcherTable[MatcherIndex++];
3648-
TargetOpc |= (unsigned short)MatcherTable[MatcherIndex++] << 8;
3653+
TargetOpc |= static_cast<uint16_t>(MatcherTable[MatcherIndex++]) << 8;
36493654
unsigned EmitNodeInfo = MatcherTable[MatcherIndex++];
36503655
// Get the result VT list.
36513656
unsigned NumVTs;
@@ -3660,7 +3665,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
36603665
SmallVector<EVT, 4> VTs;
36613666
for (unsigned i = 0; i != NumVTs; ++i) {
36623667
MVT::SimpleValueType VT =
3663-
(MVT::SimpleValueType)MatcherTable[MatcherIndex++];
3668+
static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
36643669
if (VT == MVT::iPTR)
36653670
VT = TLI->getPointerTy(CurDAG->getDataLayout()).SimpleTy;
36663671
VTs.push_back(VT);

0 commit comments

Comments
 (0)