Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove old const_cast around GetReturnTypeDesc.
  • Loading branch information
Sergey Andreenko committed May 14, 2020
commit 25b005bbcf23d6940b0f0512146484123ec22591
50 changes: 20 additions & 30 deletions src/coreclr/src/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,15 +622,12 @@ void GenTree::CopyReg(GenTree* from)
//
bool GenTree::gtHasReg() const
{
bool hasReg;
bool hasReg = false;

if (IsMultiRegCall())
{
// Have to cast away const-ness because GetReturnTypeDesc() is a non-const method
GenTree* tree = const_cast<GenTree*>(this);
GenTreeCall* call = tree->AsCall();
unsigned regCount = call->GetReturnTypeDesc()->GetReturnRegCount();
hasReg = false;
const GenTreeCall* call = AsCall();
const unsigned regCount = call->GetReturnTypeDesc()->GetReturnRegCount();

// A Multi-reg call node is said to have regs, if it has
// reg assigned to each of its result registers.
Expand All @@ -645,11 +642,9 @@ bool GenTree::gtHasReg() const
}
else if (IsCopyOrReloadOfMultiRegCall())
{
GenTree* tree = const_cast<GenTree*>(this);
GenTreeCopyOrReload* copyOrReload = tree->AsCopyOrReload();
GenTreeCall* call = copyOrReload->gtGetOp1()->AsCall();
unsigned regCount = call->GetReturnTypeDesc()->GetReturnRegCount();
hasReg = false;
const GenTreeCopyOrReload* copyOrReload = AsCopyOrReload();
const GenTreeCall* call = copyOrReload->gtGetOp1()->AsCall();
unsigned regCount = call->GetReturnTypeDesc()->GetReturnRegCount();

// A Multi-reg copy or reload node is said to have regs,
// if it has valid regs in any of the positions.
Expand Down Expand Up @@ -693,9 +688,7 @@ int GenTree::GetRegisterDstCount() const
}
else if (IsMultiRegCall())
{
// temporarily cast away const-ness as AsCall() method is not declared const
GenTree* temp = const_cast<GenTree*>(this);
return temp->AsCall()->GetReturnTypeDesc()->GetReturnRegCount();
return AsCall()->GetReturnTypeDesc()->GetReturnRegCount();
}
else if (IsCopyOrReload())
{
Expand Down Expand Up @@ -750,20 +743,18 @@ regMaskTP GenTree::gtGetRegMask() const
if (IsMultiRegCall())
{
// temporarily cast away const-ness as AsCall() method is not declared const
resultMask = genRegMask(GetRegNum());
GenTree* temp = const_cast<GenTree*>(this);
resultMask |= temp->AsCall()->GetOtherRegMask();
resultMask = genRegMask(GetRegNum());
resultMask |= AsCall()->GetOtherRegMask();
}
else if (IsCopyOrReloadOfMultiRegCall())
{
// A multi-reg copy or reload, will have valid regs for only those
// positions that need to be copied or reloaded. Hence we need
// to consider only those registers for computing reg mask.

GenTree* tree = const_cast<GenTree*>(this);
GenTreeCopyOrReload* copyOrReload = tree->AsCopyOrReload();
GenTreeCall* call = copyOrReload->gtGetOp1()->AsCall();
unsigned regCount = call->GetReturnTypeDesc()->GetReturnRegCount();
const GenTreeCopyOrReload* copyOrReload = AsCopyOrReload();
const GenTreeCall* call = copyOrReload->gtGetOp1()->AsCall();
const unsigned regCount = call->GetReturnTypeDesc()->GetReturnRegCount();

resultMask = RBM_NONE;
for (unsigned i = 0; i < regCount; ++i)
Expand All @@ -778,9 +769,8 @@ regMaskTP GenTree::gtGetRegMask() const
#if FEATURE_ARG_SPLIT
else if (OperIsPutArgSplit())
{
GenTree* tree = const_cast<GenTree*>(this);
GenTreePutArgSplit* splitArg = tree->AsPutArgSplit();
unsigned regCount = splitArg->gtNumRegs;
const GenTreePutArgSplit* splitArg = AsPutArgSplit();
const unsigned regCount = splitArg->gtNumRegs;

resultMask = RBM_NONE;
for (unsigned i = 0; i < regCount; ++i)
Expand Down Expand Up @@ -10217,18 +10207,18 @@ void Compiler::gtDispRegVal(GenTree* tree)
{
// 0th reg is GettRegNum(), which is already printed above.
// Print the remaining regs of a multi-reg call node.
GenTreeCall* call = tree->AsCall();
unsigned regCount = call->GetReturnTypeDesc()->TryGetReturnRegCount();
const GenTreeCall* call = tree->AsCall();
const unsigned regCount = call->GetReturnTypeDesc()->TryGetReturnRegCount();
for (unsigned i = 1; i < regCount; ++i)
{
printf(",%s", compRegVarName(call->GetRegNumByIdx(i)));
}
}
else if (tree->IsCopyOrReloadOfMultiRegCall())
{
GenTreeCopyOrReload* copyOrReload = tree->AsCopyOrReload();
GenTreeCall* call = tree->gtGetOp1()->AsCall();
unsigned regCount = call->GetReturnTypeDesc()->TryGetReturnRegCount();
const GenTreeCopyOrReload* copyOrReload = tree->AsCopyOrReload();
const GenTreeCall* call = tree->gtGetOp1()->AsCall();
const unsigned regCount = call->GetReturnTypeDesc()->TryGetReturnRegCount();
for (unsigned i = 1; i < regCount; ++i)
{
printf(",%s", compRegVarName(copyOrReload->GetRegNumByIdx(i)));
Expand Down Expand Up @@ -16529,7 +16519,7 @@ bool GenTree::isContained() const
else if (OperKind() & GTK_RELOP)
{
// We have to cast away const-ness since AsOp() method is non-const.
GenTree* childNode = const_cast<GenTree*>(this)->AsOp()->gtOp1;
const GenTree* childNode = AsOp()->gtGetOp1();
assert((isMarkedContained == false) || childNode->IsSIMDEqualityOrInequality());
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/jit/lsrabuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3272,7 +3272,7 @@ int LinearScan::BuildReturn(GenTree* tree)
noway_assert(op1->IsMultiRegCall());

const ReturnTypeDesc* retTypeDesc = op1->AsCall()->GetReturnTypeDesc();
int srcCount = retTypeDesc->GetReturnRegCount();
const int srcCount = retTypeDesc->GetReturnRegCount();
useCandidates = retTypeDesc->GetABIReturnRegs();
for (int i = 0; i < srcCount; i++)
{
Expand Down