Skip to content

Commit 43edad5

Browse files
authored
JIT: Consistently use TypeIs/OperIs for type/oper checks (#116141)
- Add `LclVarDsc::TypeIs` - Switch type and oper checks to `TypeIs` and `OperIs` everywhere (replacements done with a series of regex)
1 parent fcd197c commit 43edad5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+916
-923
lines changed

src/coreclr/jit/assertionprop.cpp

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1, GenTree* op2, optAsser
11371137
op1 = op1->gtEffectiveVal();
11381138

11391139
ssize_t offset = 0;
1140-
while ((op1->gtOper == GT_ADD) && (op1->gtType == TYP_BYREF))
1140+
while (op1->OperIs(GT_ADD) && op1->TypeIs(TYP_BYREF))
11411141
{
11421142
if (op1->gtGetOp2()->IsCnsIntOrI())
11431143
{
@@ -1184,7 +1184,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1, GenTree* op2, optAsser
11841184

11851185
{
11861186
/* Skip over a GT_COMMA node(s), if necessary */
1187-
while (op2->gtOper == GT_COMMA)
1187+
while (op2->OperIs(GT_COMMA))
11881188
{
11891189
op2 = op2->AsOp()->gtOp2;
11901190
}
@@ -1229,7 +1229,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1, GenTree* op2, optAsser
12291229
assertion.op2.kind = op2Kind;
12301230
assertion.op2.vn = optConservativeNormalVN(op2);
12311231

1232-
if (op2->gtOper == GT_CNS_INT)
1232+
if (op2->OperIs(GT_CNS_INT))
12331233
{
12341234
ssize_t iconVal = op2->AsIntCon()->IconValue();
12351235
if (varTypeIsSmall(lclVar) && op1->OperIs(GT_STORE_LCL_VAR))
@@ -1245,7 +1245,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1, GenTree* op2, optAsser
12451245
}
12461246
else
12471247
{
1248-
noway_assert(op2->gtOper == GT_CNS_DBL);
1248+
noway_assert(op2->OperIs(GT_CNS_DBL));
12491249
/* If we have an NaN value then don't record it */
12501250
if (FloatingPointUtils::isNaN(op2->AsDblCon()->DconValue()))
12511251
{
@@ -1441,7 +1441,7 @@ bool Compiler::optIsTreeKnownIntValue(bool vnBased, GenTree* tree, ssize_t* pCon
14411441
// Is Local assertion prop?
14421442
if (!vnBased)
14431443
{
1444-
if (tree->OperGet() == GT_CNS_INT)
1444+
if (tree->OperIs(GT_CNS_INT))
14451445
{
14461446
*pConstant = tree->AsIntCon()->IconValue();
14471447
*pFlags = tree->GetIconHandleFlag();
@@ -2062,25 +2062,25 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree)
20622062
}
20632063

20642064
// Check for op1 or op2 to be lcl var and if so, keep it in op1.
2065-
if ((op1->gtOper != GT_LCL_VAR) && (op2->gtOper == GT_LCL_VAR))
2065+
if (!op1->OperIs(GT_LCL_VAR) && op2->OperIs(GT_LCL_VAR))
20662066
{
20672067
std::swap(op1, op2);
20682068
}
20692069

20702070
// If op1 is lcl and op2 is const or lcl, create assertion.
2071-
if ((op1->gtOper == GT_LCL_VAR) && (op2->OperIsConst() || (op2->gtOper == GT_LCL_VAR))) // Fix for Dev10 851483
2071+
if (op1->OperIs(GT_LCL_VAR) && (op2->OperIsConst() || op2->OperIs(GT_LCL_VAR))) // Fix for Dev10 851483
20722072
{
20732073
// Watch out for cases where long local(s) are implicitly truncated.
20742074
//
20752075
LclVarDsc* const lcl1Dsc = lvaGetDesc(op1->AsLclVarCommon());
2076-
if ((lcl1Dsc->TypeGet() == TYP_LONG) && (op1->TypeGet() != TYP_LONG))
2076+
if (lcl1Dsc->TypeIs(TYP_LONG) && !op1->TypeIs(TYP_LONG))
20772077
{
20782078
return NO_ASSERTION_INDEX;
20792079
}
20802080
if (op2->OperIs(GT_LCL_VAR))
20812081
{
20822082
LclVarDsc* const lcl2Dsc = lvaGetDesc(op2->AsLclVarCommon());
2083-
if ((lcl2Dsc->TypeGet() == TYP_LONG) && (op2->TypeGet() != TYP_LONG))
2083+
if (lcl2Dsc->TypeIs(TYP_LONG) && !op2->TypeIs(TYP_LONG))
20842084
{
20852085
return NO_ASSERTION_INDEX;
20862086
}
@@ -2101,19 +2101,19 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree)
21012101
}
21022102

21032103
// Check op1 and op2 for an indirection of a GT_LCL_VAR and keep it in op1.
2104-
if (((op1->gtOper != GT_IND) || (op1->AsOp()->gtOp1->gtOper != GT_LCL_VAR)) &&
2105-
((op2->gtOper == GT_IND) && (op2->AsOp()->gtOp1->gtOper == GT_LCL_VAR)))
2104+
if ((!op1->OperIs(GT_IND) || !op1->AsOp()->gtOp1->OperIs(GT_LCL_VAR)) &&
2105+
(op2->OperIs(GT_IND) && op2->AsOp()->gtOp1->OperIs(GT_LCL_VAR)))
21062106
{
21072107
std::swap(op1, op2);
21082108
}
21092109
// If op1 is ind, then extract op1's oper.
2110-
if ((op1->gtOper == GT_IND) && (op1->AsOp()->gtOp1->gtOper == GT_LCL_VAR))
2110+
if (op1->OperIs(GT_IND) && op1->AsOp()->gtOp1->OperIs(GT_LCL_VAR))
21112111
{
21122112
return optCreateJtrueAssertions(op1, op2, assertionKind);
21132113
}
21142114

21152115
// Look for a call to an IsInstanceOf helper compared to a nullptr
2116-
if ((op2->gtOper != GT_CNS_INT) && (op1->gtOper == GT_CNS_INT))
2116+
if (!op2->OperIs(GT_CNS_INT) && op1->OperIs(GT_CNS_INT))
21172117
{
21182118
std::swap(op1, op2);
21192119
}
@@ -2757,7 +2757,7 @@ GenTree* Compiler::optVNBasedFoldExpr(BasicBlock* block, GenTree* parent, GenTre
27572757
//
27582758
GenTree* Compiler::optVNBasedFoldConstExpr(BasicBlock* block, GenTree* parent, GenTree* tree)
27592759
{
2760-
if (tree->OperGet() == GT_JTRUE)
2760+
if (tree->OperIs(GT_JTRUE))
27612761
{
27622762
// Treat JTRUE separately to extract side effects into respective statements rather
27632763
// than using a COMMA separated op1.
@@ -2797,7 +2797,7 @@ GenTree* Compiler::optVNBasedFoldConstExpr(BasicBlock* block, GenTree* parent, G
27972797
{
27982798
float value = vnStore->ConstantValue<float>(vnCns);
27992799

2800-
if (tree->TypeGet() == TYP_INT)
2800+
if (tree->TypeIs(TYP_INT))
28012801
{
28022802
// Same sized reinterpretation of bits to integer
28032803
conValTree = gtNewIconNode(*(reinterpret_cast<int*>(&value)));
@@ -2815,7 +2815,7 @@ GenTree* Compiler::optVNBasedFoldConstExpr(BasicBlock* block, GenTree* parent, G
28152815
{
28162816
double value = vnStore->ConstantValue<double>(vnCns);
28172817

2818-
if (tree->TypeGet() == TYP_LONG)
2818+
if (tree->TypeIs(TYP_LONG))
28192819
{
28202820
conValTree = gtNewLconNode(*(reinterpret_cast<INT64*>(&value)));
28212821
}
@@ -2878,7 +2878,7 @@ GenTree* Compiler::optVNBasedFoldConstExpr(BasicBlock* block, GenTree* parent, G
28782878

28792879
case TYP_REF:
28802880
{
2881-
if (tree->TypeGet() == TYP_REF)
2881+
if (tree->TypeIs(TYP_REF))
28822882
{
28832883
const size_t value = vnStore->ConstantValue<size_t>(vnCns);
28842884
if (value == 0)
@@ -3724,7 +3724,7 @@ GenTree* Compiler::optAssertionProp_LocalStore(ASSERT_VALARG_TP assertions, GenT
37243724
// does not kill the zerobj assertion for s.
37253725
//
37263726
unsigned const dstLclNum = store->GetLclNum();
3727-
bool const dstLclIsStruct = lvaGetDesc(dstLclNum)->TypeGet() == TYP_STRUCT;
3727+
bool const dstLclIsStruct = lvaGetDesc(dstLclNum)->TypeIs(TYP_STRUCT);
37283728
AssertionIndex const dstIndex =
37293729
optLocalAssertionIsEqualOrNotEqual(O1K_LCLVAR, dstLclNum, dstLclIsStruct ? O2K_ZEROOBJ : O2K_CONST_INT, 0,
37303730
assertions);
@@ -4474,19 +4474,19 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
44744474
{
44754475
printf("%d\n", vnStore->ConstantValue<int>(vnCns));
44764476
}
4477-
else if (op1->TypeGet() == TYP_LONG)
4477+
else if (op1->TypeIs(TYP_LONG))
44784478
{
44794479
printf("%lld\n", vnStore->ConstantValue<INT64>(vnCns));
44804480
}
4481-
else if (op1->TypeGet() == TYP_DOUBLE)
4481+
else if (op1->TypeIs(TYP_DOUBLE))
44824482
{
44834483
printf("%f\n", vnStore->ConstantValue<double>(vnCns));
44844484
}
4485-
else if (op1->TypeGet() == TYP_FLOAT)
4485+
else if (op1->TypeIs(TYP_FLOAT))
44864486
{
44874487
printf("%f\n", vnStore->ConstantValue<float>(vnCns));
44884488
}
4489-
else if (op1->TypeGet() == TYP_REF)
4489+
else if (op1->TypeIs(TYP_REF))
44904490
{
44914491
// The only constant of TYP_REF that ValueNumbering supports is 'null'
44924492
if (vnStore->ConstantValue<size_t>(vnCns) == 0)
@@ -4498,7 +4498,7 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
44984498
printf("%d (gcref)\n", static_cast<target_ssize_t>(vnStore->ConstantValue<size_t>(vnCns)));
44994499
}
45004500
}
4501-
else if (op1->TypeGet() == TYP_BYREF)
4501+
else if (op1->TypeIs(TYP_BYREF))
45024502
{
45034503
printf("%d (byref)\n", static_cast<target_ssize_t>(vnStore->ConstantValue<size_t>(vnCns)));
45044504
}
@@ -4519,7 +4519,7 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
45194519
op1->gtFlags |= (vnStore->GetHandleFlags(vnCns) & GTF_ICON_HDL_MASK);
45204520
}
45214521
}
4522-
else if (op1->TypeGet() == TYP_LONG)
4522+
else if (op1->TypeIs(TYP_LONG))
45234523
{
45244524
op1->BashToConst(vnStore->ConstantValue<INT64>(vnCns));
45254525

@@ -4528,7 +4528,7 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
45284528
op1->gtFlags |= (vnStore->GetHandleFlags(vnCns) & GTF_ICON_HDL_MASK);
45294529
}
45304530
}
4531-
else if (op1->TypeGet() == TYP_DOUBLE)
4531+
else if (op1->TypeIs(TYP_DOUBLE))
45324532
{
45334533
double constant = vnStore->ConstantValue<double>(vnCns);
45344534
op1->BashToConst(constant);
@@ -4539,19 +4539,19 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
45394539
// assertion we have made.
45404540
allowReverse = !FloatingPointUtils::isNaN(constant);
45414541
}
4542-
else if (op1->TypeGet() == TYP_FLOAT)
4542+
else if (op1->TypeIs(TYP_FLOAT))
45434543
{
45444544
float constant = vnStore->ConstantValue<float>(vnCns);
45454545
op1->BashToConst(constant);
45464546

45474547
// See comments for TYP_DOUBLE.
45484548
allowReverse = !FloatingPointUtils::isNaN(constant);
45494549
}
4550-
else if (op1->TypeGet() == TYP_REF)
4550+
else if (op1->TypeIs(TYP_REF))
45514551
{
45524552
op1->BashToConst(static_cast<target_ssize_t>(vnStore->ConstantValue<size_t>(vnCns)), TYP_REF);
45534553
}
4554-
else if (op1->TypeGet() == TYP_BYREF)
4554+
else if (op1->TypeIs(TYP_BYREF))
45554555
{
45564556
op1->BashToConst(static_cast<target_ssize_t>(vnStore->ConstantValue<size_t>(vnCns)), TYP_BYREF);
45574557
}
@@ -4564,7 +4564,7 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
45644564

45654565
// set foldResult to either 0 or 1
45664566
bool foldResult = assertionKindIsEqual;
4567-
if (tree->gtOper == GT_NE)
4567+
if (tree->OperIs(GT_NE))
45684568
{
45694569
foldResult = !foldResult;
45704570
}
@@ -4644,19 +4644,19 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions,
46444644
*/
46454645
GenTree* Compiler::optAssertionPropLocal_RelOp(ASSERT_VALARG_TP assertions, GenTree* tree, Statement* stmt)
46464646
{
4647-
assert(tree->OperGet() == GT_EQ || tree->OperGet() == GT_NE);
4647+
assert(tree->OperIs(GT_EQ) || tree->OperIs(GT_NE));
46484648

46494649
GenTree* op1 = tree->AsOp()->gtOp1;
46504650
GenTree* op2 = tree->AsOp()->gtOp2;
46514651

46524652
// For Local AssertionProp we only can fold when op1 is a GT_LCL_VAR
4653-
if (op1->gtOper != GT_LCL_VAR)
4653+
if (!op1->OperIs(GT_LCL_VAR))
46544654
{
46554655
return nullptr;
46564656
}
46574657

46584658
// For Local AssertionProp we only can fold when op2 is a GT_CNS_INT
4659-
if (op2->gtOper != GT_CNS_INT)
4659+
if (!op2->OperIs(GT_CNS_INT))
46604660
{
46614661
return nullptr;
46624662
}
@@ -4716,7 +4716,7 @@ GenTree* Compiler::optAssertionPropLocal_RelOp(ASSERT_VALARG_TP assertions, GenT
47164716

47174717
// Return either CNS_INT 0 or CNS_INT 1.
47184718
bool foldResult = (constantIsEqual == assertionKindIsEqual);
4719-
if (tree->gtOper == GT_NE)
4719+
if (tree->OperIs(GT_NE))
47204720
{
47214721
foldResult = !foldResult;
47224722
}
@@ -6101,7 +6101,7 @@ ASSERT_TP* Compiler::optComputeAssertionGen()
61016101
{
61026102
for (GenTree* const tree : stmt->TreeList())
61036103
{
6104-
if (tree->gtOper == GT_JTRUE)
6104+
if (tree->OperIs(GT_JTRUE))
61056105
{
61066106
// A GT_TRUE is always the last node in a tree, so we can break here
61076107
assert((tree->gtNext == nullptr) && (stmt->GetNextStmt() == nullptr));
@@ -6324,7 +6324,7 @@ Compiler::fgWalkResult Compiler::optVNBasedFoldCurStmt(BasicBlock* block,
63246324

63256325
// Don't propagate floating-point constants into a TYP_STRUCT LclVar
63266326
// This can occur for HFA return values (see hfa_sf3E_r.exe)
6327-
if (tree->TypeGet() == TYP_STRUCT)
6327+
if (tree->TypeIs(TYP_STRUCT))
63286328
{
63296329
return WALK_CONTINUE;
63306330
}
@@ -6445,7 +6445,7 @@ void Compiler::optVnNonNullPropCurStmt(BasicBlock* block, Statement* stmt, GenTr
64456445
{
64466446
ASSERT_TP empty = BitVecOps::UninitVal();
64476447
GenTree* newTree = nullptr;
6448-
if (tree->OperGet() == GT_CALL)
6448+
if (tree->OperIs(GT_CALL))
64496449
{
64506450
newTree = optNonNullAssertionProp_Call(empty, tree->AsCall());
64516451
}

src/coreclr/jit/async.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ bool AsyncLiveness::IsLive(unsigned lclNum)
174174

175175
LclVarDsc* dsc = m_comp->lvaGetDesc(lclNum);
176176

177-
if (((dsc->TypeGet() == TYP_BYREF) && !dsc->IsImplicitByRef()) ||
178-
((dsc->TypeGet() == TYP_STRUCT) && dsc->GetLayout()->HasGCByRef()))
177+
if ((dsc->TypeIs(TYP_BYREF) && !dsc->IsImplicitByRef()) ||
178+
(dsc->TypeIs(TYP_STRUCT) && dsc->GetLayout()->HasGCByRef()))
179179
{
180180
// Even if these are address exposed we expect them to be dead at
181181
// suspension points. TODO: It would be good to somehow verify these
@@ -617,7 +617,7 @@ ContinuationLayout AsyncTransformation::LayOutContinuation(BasicBlock*
617617
{
618618
LclVarDsc* dsc = m_comp->lvaGetDesc(inf.LclNum);
619619

620-
if ((dsc->TypeGet() == TYP_STRUCT) || dsc->IsImplicitByRef())
620+
if (dsc->TypeIs(TYP_STRUCT) || dsc->IsImplicitByRef())
621621
{
622622
ClassLayout* layout = dsc->GetLayout();
623623
assert(!layout->HasGCByRef());
@@ -643,15 +643,15 @@ ContinuationLayout AsyncTransformation::LayOutContinuation(BasicBlock*
643643
inf.GCDataCount = layout->GetGCPtrCount();
644644
}
645645
}
646-
else if (dsc->TypeGet() == TYP_REF)
646+
else if (dsc->TypeIs(TYP_REF))
647647
{
648648
inf.Alignment = TARGET_POINTER_SIZE;
649649
inf.DataSize = 0;
650650
inf.GCDataCount = 1;
651651
}
652652
else
653653
{
654-
assert(dsc->TypeGet() != TYP_BYREF);
654+
assert(!dsc->TypeIs(TYP_BYREF));
655655

656656
inf.Alignment = genTypeAlignments[dsc->TypeGet()];
657657
inf.DataSize = genTypeSize(dsc);
@@ -1005,7 +1005,7 @@ void AsyncTransformation::FillInGCPointersOnSuspension(const jitstd::vector<Live
10051005
}
10061006

10071007
LclVarDsc* dsc = m_comp->lvaGetDesc(inf.LclNum);
1008-
if (dsc->TypeGet() == TYP_REF)
1008+
if (dsc->TypeIs(TYP_REF))
10091009
{
10101010
GenTree* value = m_comp->gtNewLclvNode(inf.LclNum, TYP_REF);
10111011
GenTree* objectArr = m_comp->gtNewLclvNode(objectArrLclNum, TYP_REF);
@@ -1016,7 +1016,7 @@ void AsyncTransformation::FillInGCPointersOnSuspension(const jitstd::vector<Live
10161016
}
10171017
else
10181018
{
1019-
assert((dsc->TypeGet() == TYP_STRUCT) || dsc->IsImplicitByRef());
1019+
assert(dsc->TypeIs(TYP_STRUCT) || dsc->IsImplicitByRef());
10201020
ClassLayout* layout = dsc->GetLayout();
10211021
unsigned numSlots = layout->GetSlotCount();
10221022
unsigned gcRefIndex = 0;
@@ -1132,7 +1132,7 @@ void AsyncTransformation::FillInDataOnSuspension(const jitstd::vector<LiveLocalI
11321132
}
11331133

11341134
GenTree* store;
1135-
if ((dsc->TypeGet() == TYP_STRUCT) || dsc->IsImplicitByRef())
1135+
if (dsc->TypeIs(TYP_STRUCT) || dsc->IsImplicitByRef())
11361136
{
11371137
GenTree* cns = m_comp->gtNewIconNode((ssize_t)offset, TYP_I_IMPL);
11381138
GenTree* addr = m_comp->gtNewOperNode(GT_ADD, TYP_BYREF, byteArr, cns);
@@ -1311,7 +1311,7 @@ void AsyncTransformation::RestoreFromDataOnResumption(unsigned
13111311
GenTree* addr = m_comp->gtNewOperNode(GT_ADD, TYP_BYREF, byteArr, cns);
13121312

13131313
GenTree* value;
1314-
if ((dsc->TypeGet() == TYP_STRUCT) || dsc->IsImplicitByRef())
1314+
if (dsc->TypeIs(TYP_STRUCT) || dsc->IsImplicitByRef())
13151315
{
13161316
value = m_comp->gtNewLoadValueNode(dsc->GetLayout(), addr, GTF_IND_NONFAULTING);
13171317
}
@@ -1358,7 +1358,7 @@ void AsyncTransformation::RestoreFromGCPointersOnResumption(unsigned
13581358
}
13591359

13601360
LclVarDsc* dsc = m_comp->lvaGetDesc(inf.LclNum);
1361-
if (dsc->TypeGet() == TYP_REF)
1361+
if (dsc->TypeIs(TYP_REF))
13621362
{
13631363
GenTree* objectArr = m_comp->gtNewLclvNode(resumeObjectArrLclNum, TYP_REF);
13641364
unsigned offset = OFFSETOF__CORINFO_Array__data + (inf.GCDataIndex * TARGET_POINTER_SIZE);
@@ -1369,7 +1369,7 @@ void AsyncTransformation::RestoreFromGCPointersOnResumption(unsigned
13691369
}
13701370
else
13711371
{
1372-
assert((dsc->TypeGet() == TYP_STRUCT) || dsc->IsImplicitByRef());
1372+
assert(dsc->TypeIs(TYP_STRUCT) || dsc->IsImplicitByRef());
13731373
ClassLayout* layout = dsc->GetLayout();
13741374
unsigned numSlots = layout->GetSlotCount();
13751375
unsigned gcRefIndex = 0;

0 commit comments

Comments
 (0)