Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/coreclr/src/inc/opcode.def
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ OPDEF(CEE_INITOBJ, "initobj", PopI, Pu
OPDEF(CEE_CONSTRAINED, "constrained.", Pop0, Push0, InlineType, IPrefix, 2, 0xFE, 0x16, META)
OPDEF(CEE_CPBLK, "cpblk", PopI+PopI+PopI, Push0, InlineNone, IPrimitive, 2, 0xFE, 0x17, NEXT)
OPDEF(CEE_INITBLK, "initblk", PopI+PopI+PopI, Push0, InlineNone, IPrimitive, 2, 0xFE, 0x18, NEXT)
OPDEF(CEE_UNUSED69, "unused", Pop0, Push0, InlineNone, IPrimitive, 2, 0xFE, 0x19, NEXT)
OPDEF(CEE_NOCHECK, "no.", Pop0, Push0, ShortInlineI, IPrefix, 2, 0xFE, 0x19, META)
OPDEF(CEE_RETHROW, "rethrow", Pop0, Push0, InlineNone, IObjModel, 2, 0xFE, 0x1A, THROW)
OPDEF(CEE_UNUSED51, "unused", Pop0, Push0, InlineNone, IPrimitive, 2, 0xFE, 0x1B, NEXT)
OPDEF(CEE_SIZEOF, "sizeof", Pop0, PushI, InlineType, IPrimitive, 2, 0xFE, 0x1C, NEXT)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4702,6 +4702,7 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
case CEE_CONSTRAINED:
case CEE_READONLY:
case CEE_VOLATILE:
case CEE_NOCHECK:
case CEE_TAILCALL:
{
if (codeAddr >= codeEndp)
Expand Down Expand Up @@ -5607,6 +5608,7 @@ unsigned Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, F
case CEE_CONSTRAINED:
case CEE_VOLATILE:
case CEE_UNALIGNED:
case CEE_NOCHECK:
// fgFindJumpTargets should have ruled out this possibility
// (i.e. a prefix opcodes as last intruction in a block)
noway_assert(codeAddr < codeEndp);
Expand Down
82 changes: 75 additions & 7 deletions src/coreclr/src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7199,14 +7199,19 @@ bool Compiler::impTailCallRetTypeCompatible(var_types callerRetType,
// For prefixFlags
enum
{
PREFIX_TAILCALL_EXPLICIT = 0x00000001, // call has "tail" IL prefix
PREFIX_TAILCALL_EXPLICIT = 0x000000001, // call has "tail" IL prefix
PREFIX_TAILCALL_IMPLICIT =
0x00000010, // call is treated as having "tail" prefix even though there is no "tail" IL prefix
PREFIX_TAILCALL = (PREFIX_TAILCALL_EXPLICIT | PREFIX_TAILCALL_IMPLICIT),
PREFIX_VOLATILE = 0x00000100,
PREFIX_UNALIGNED = 0x00001000,
PREFIX_CONSTRAINED = 0x00010000,
PREFIX_READONLY = 0x00100000
0x000000002, // call is treated as having "tail" prefix even though there is no "tail" IL prefix
PREFIX_TAILCALL = (PREFIX_TAILCALL_EXPLICIT | PREFIX_TAILCALL_IMPLICIT),
PREFIX_VOLATILE = 0x000000004,
PREFIX_UNALIGNED = 0x000000008,
PREFIX_CONSTRAINED = 0x000000010,
PREFIX_READONLY = 0x000000020,
// DO NOT CHANGE THESE VALUES - impImportBlockCode (at case CEE_NOCHECK) relies on these being 6 bits left of the IL no. prefix flags
PREFIX_NO_TYPECHECK = 0x000000040,
PREFIX_NO_RANGECHECK = 0x000000080,
PREFIX_NO_NULLCHECK = 0x000000100,
PREFIX_NO_TYPERANGENULLCHECK = (PREFIX_NO_TYPECHECK | PREFIX_NO_RANGECHECK | PREFIX_NO_NULLCHECK)
};

/********************************************************************************
Expand Down Expand Up @@ -10005,6 +10010,7 @@ static OPCODE impGetNonPrefixOpcode(const BYTE* codeAddr, const BYTE* codeEndp)
case CEE_TAILCALL:
case CEE_CONSTRAINED:
case CEE_READONLY:
case CEE_NOCHECK:
break;
default:
return opcode;
Expand Down Expand Up @@ -10035,6 +10041,38 @@ static void impValidateMemoryAccessOpcode(const BYTE* codeAddr, const BYTE* code
}
}

/*****************************************************************************/
// Checks whether the opcode is a valid opcode for no. (check elision) prefix
static void impValidateCheckElisionOpcode(const BYTE* codeAddr, const BYTE* codeEndp, int flags)
{
OPCODE opcode = impGetNonPrefixOpcode(codeAddr, codeEndp);

if ((flags & PREFIX_NO_TYPECHECK) != 0)
{
if (!(opcode == CEE_CASTCLASS || opcode == CEE_UNBOX || opcode == CEE_LDELEMA
|| (opcode >= CEE_STELEM_I && opcode <= CEE_STELEM_REF) || opcode == CEE_STELEM))
{
BADCODE("Invalid opcode for no. prefix with typecheck flag");
}
}
if ((flags & PREFIX_NO_RANGECHECK) != 0)
{
// Covers LDELEMA, LDELEM_*, and STELEM_*
if (!(opcode >= CEE_LDELEMA && opcode <= CEE_STELEM))
{
BADCODE("Invalid opcode for no. prefix with rangecheck flag");
}
}
if ((flags & PREFIX_NO_NULLCHECK) != 0)
{
if (!(opcode == CEE_LDFLD || opcode == CEE_STFLD || opcode == CEE_CALLVIRT || opcode == CEE_LDVIRTFTN
|| (opcode >= CEE_LDELEMA && opcode <= CEE_STELEM)))
{
BADCODE("Invalid opcode for no. prefix with nullcheck flag");
}
}
}

/*****************************************************************************/

#ifdef DEBUG
Expand Down Expand Up @@ -13539,6 +13577,36 @@ void Compiler::impImportBlockCode(BasicBlock* block)
assert(sz == 0);
goto PREFIX;

case CEE_NOCHECK:
assert(sz == 1);
JITDUMP(" no.");
Verify(!(prefixFlags & PREFIX_NO_TYPERANGENULLCHECK), "Multiple no. prefixes");

{
int flags = getU1LittleEndian(codeAddr);

JITDUMP(" %u", flags);

++codeAddr;

// PREFIX_NO_TYPECHECK = 0x000000040 which is 0x1 (the value of typecheck flag) << 6
// The 2 subsequent flags are just left shift of 1, the same as the nullcheck/rangecheck IL flags, so we just have to
// left shift by 6 to transform
flags <<= 6;
if ((flags & (~PREFIX_NO_TYPERANGENULLCHECK)) != 0)
{
BADCODE("no. followed by invalid flags");
}

impValidateCheckElisionOpcode(codeAddr, codeEndp, flags);



prefixFlags |= flags;
}

goto PREFIX;

case CEE_TAILCALL:
JITDUMP(" tail.");

Expand Down