Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Delete IL verification failure helpers in importer #108996

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion src/coreclr/jit/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ void BasicBlock::dspFlags() const
{BBF_REMOVED, "del"},
{BBF_DONT_REMOVE, "keep"},
{BBF_INTERNAL, "internal"},
{BBF_FAILED_VERIFICATION, "failV"},
{BBF_HAS_SUPPRESSGC_CALL, "sup-gc"},
{BBF_LOOP_HEAD, "loophead"},
{BBF_HAS_LABEL, "label"},
Expand Down
71 changes: 35 additions & 36 deletions src/coreclr/jit/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,44 +424,43 @@ enum BasicBlockFlags : uint64_t
BBF_DONT_REMOVE = MAKE_BBFLAG( 3), // BB should not be removed during flow graph optimizations
BBF_IMPORTED = MAKE_BBFLAG( 4), // BB byte-code has been imported
BBF_INTERNAL = MAKE_BBFLAG( 5), // BB has been added by the compiler
BBF_FAILED_VERIFICATION = MAKE_BBFLAG( 6), // BB has verification exception
BBF_NEEDS_GCPOLL = MAKE_BBFLAG( 7), // BB may need a GC poll because it uses the slow tail call helper
BBF_FUNCLET_BEG = MAKE_BBFLAG( 8), // BB is the beginning of a funclet
BBF_CLONED_FINALLY_BEGIN = MAKE_BBFLAG( 9), // First block of a cloned finally region
BBF_CLONED_FINALLY_END = MAKE_BBFLAG(10), // Last block of a cloned finally region
BBF_HAS_NULLCHECK = MAKE_BBFLAG(11), // BB contains a null check
BBF_HAS_SUPPRESSGC_CALL = MAKE_BBFLAG(12), // BB contains a call to a method with SuppressGCTransitionAttribute
BBF_RUN_RARELY = MAKE_BBFLAG(13), // BB is rarely run (catch clauses, blocks with throws etc)
BBF_LOOP_HEAD = MAKE_BBFLAG(14), // BB is the head of a loop (can reach a predecessor)
BBF_HAS_LABEL = MAKE_BBFLAG(15), // BB needs a label
BBF_LOOP_ALIGN = MAKE_BBFLAG(16), // Block is lexically the first block in a loop we intend to align.
BBF_HAS_ALIGN = MAKE_BBFLAG(17), // BB ends with 'align' instruction
BBF_HAS_JMP = MAKE_BBFLAG(18), // BB executes a JMP instruction (instead of return)
BBF_GC_SAFE_POINT = MAKE_BBFLAG(19), // BB has a GC safe point (e.g. a call)
BBF_HAS_IDX_LEN = MAKE_BBFLAG(20), // BB contains simple index or length expressions on an SD array local var.
BBF_HAS_MD_IDX_LEN = MAKE_BBFLAG(21), // BB contains simple index, length, or lower bound expressions on an MD array local var.
BBF_HAS_MDARRAYREF = MAKE_BBFLAG(22), // Block has a multi-dimensional array reference
BBF_HAS_NEWOBJ = MAKE_BBFLAG(23), // BB contains 'new' of an object type.

BBF_RETLESS_CALL = MAKE_BBFLAG(24), // BBJ_CALLFINALLY that will never return (and therefore, won't need a paired
BBF_NEEDS_GCPOLL = MAKE_BBFLAG( 6), // BB may need a GC poll because it uses the slow tail call helper
BBF_FUNCLET_BEG = MAKE_BBFLAG( 7), // BB is the beginning of a funclet
BBF_CLONED_FINALLY_BEGIN = MAKE_BBFLAG( 8), // First block of a cloned finally region
BBF_CLONED_FINALLY_END = MAKE_BBFLAG( 9), // Last block of a cloned finally region
BBF_HAS_NULLCHECK = MAKE_BBFLAG(10), // BB contains a null check
BBF_HAS_SUPPRESSGC_CALL = MAKE_BBFLAG(11), // BB contains a call to a method with SuppressGCTransitionAttribute
BBF_RUN_RARELY = MAKE_BBFLAG(12), // BB is rarely run (catch clauses, blocks with throws etc)
BBF_LOOP_HEAD = MAKE_BBFLAG(13), // BB is the head of a loop (can reach a predecessor)
BBF_HAS_LABEL = MAKE_BBFLAG(14), // BB needs a label
BBF_LOOP_ALIGN = MAKE_BBFLAG(15), // Block is lexically the first block in a loop we intend to align.
BBF_HAS_ALIGN = MAKE_BBFLAG(16), // BB ends with 'align' instruction
BBF_HAS_JMP = MAKE_BBFLAG(17), // BB executes a JMP instruction (instead of return)
BBF_GC_SAFE_POINT = MAKE_BBFLAG(18), // BB has a GC safe point (e.g. a call)
BBF_HAS_IDX_LEN = MAKE_BBFLAG(19), // BB contains simple index or length expressions on an SD array local var.
BBF_HAS_MD_IDX_LEN = MAKE_BBFLAG(20), // BB contains simple index, length, or lower bound expressions on an MD array local var.
BBF_HAS_MDARRAYREF = MAKE_BBFLAG(21), // Block has a multi-dimensional array reference
BBF_HAS_NEWOBJ = MAKE_BBFLAG(22), // BB contains 'new' of an object type.

BBF_RETLESS_CALL = MAKE_BBFLAG(23), // BBJ_CALLFINALLY that will never return (and therefore, won't need a paired
// BBJ_CALLFINALLYRET); see isBBCallFinallyPair().
BBF_COLD = MAKE_BBFLAG(25), // BB is cold
BBF_PROF_WEIGHT = MAKE_BBFLAG(26), // BB weight is computed from profile data
BBF_KEEP_BBJ_ALWAYS = MAKE_BBFLAG(27), // A special BBJ_ALWAYS block, used by EH code generation. Keep the jump kind
BBF_COLD = MAKE_BBFLAG(24), // BB is cold
BBF_PROF_WEIGHT = MAKE_BBFLAG(25), // BB weight is computed from profile data
BBF_KEEP_BBJ_ALWAYS = MAKE_BBFLAG(26), // A special BBJ_ALWAYS block, used by EH code generation. Keep the jump kind
// as BBJ_ALWAYS. Used on x86 for the final step block out of a finally.
BBF_HAS_CALL = MAKE_BBFLAG(28), // BB contains a call
BBF_DOMINATED_BY_EXCEPTIONAL_ENTRY = MAKE_BBFLAG(29), // Block is dominated by exceptional entry.
BBF_BACKWARD_JUMP = MAKE_BBFLAG(30), // BB is surrounded by a backward jump/switch arc
BBF_BACKWARD_JUMP_SOURCE = MAKE_BBFLAG(31), // Block is a source of a backward jump
BBF_BACKWARD_JUMP_TARGET = MAKE_BBFLAG(32), // Block is a target of a backward jump
BBF_PATCHPOINT = MAKE_BBFLAG(33), // Block is a patchpoint
BBF_PARTIAL_COMPILATION_PATCHPOINT = MAKE_BBFLAG(34), // Block is a partial compilation patchpoint
BBF_HAS_HISTOGRAM_PROFILE = MAKE_BBFLAG(35), // BB contains a call needing a histogram profile
BBF_TAILCALL_SUCCESSOR = MAKE_BBFLAG(36), // BB has pred that has potential tail call
BBF_RECURSIVE_TAILCALL = MAKE_BBFLAG(37), // Block has recursive tailcall that may turn into a loop
BBF_NO_CSE_IN = MAKE_BBFLAG(38), // Block should kill off any incoming CSE
BBF_CAN_ADD_PRED = MAKE_BBFLAG(39), // Ok to add pred edge to this block, even when "safe" edge creation disabled
BBF_HAS_VALUE_PROFILE = MAKE_BBFLAG(40), // Block has a node that needs a value probing
BBF_HAS_CALL = MAKE_BBFLAG(27), // BB contains a call
BBF_DOMINATED_BY_EXCEPTIONAL_ENTRY = MAKE_BBFLAG(28), // Block is dominated by exceptional entry.
BBF_BACKWARD_JUMP = MAKE_BBFLAG(29), // BB is surrounded by a backward jump/switch arc
BBF_BACKWARD_JUMP_SOURCE = MAKE_BBFLAG(30), // Block is a source of a backward jump
BBF_BACKWARD_JUMP_TARGET = MAKE_BBFLAG(31), // Block is a target of a backward jump
BBF_PATCHPOINT = MAKE_BBFLAG(32), // Block is a patchpoint
BBF_PARTIAL_COMPILATION_PATCHPOINT = MAKE_BBFLAG(33), // Block is a partial compilation patchpoint
BBF_HAS_HISTOGRAM_PROFILE = MAKE_BBFLAG(34), // BB contains a call needing a histogram profile
BBF_TAILCALL_SUCCESSOR = MAKE_BBFLAG(35), // BB has pred that has potential tail call
BBF_RECURSIVE_TAILCALL = MAKE_BBFLAG(36), // Block has recursive tailcall that may turn into a loop
BBF_NO_CSE_IN = MAKE_BBFLAG(37), // Block should kill off any incoming CSE
BBF_CAN_ADD_PRED = MAKE_BBFLAG(38), // Ok to add pred edge to this block, even when "safe" edge creation disabled
BBF_HAS_VALUE_PROFILE = MAKE_BBFLAG(39), // Block has a node that needs a value probing

// The following are sets of flags.

Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11253,8 +11253,6 @@ class Compiler
void verInitCurrentState();
void verResetCurrentState(BasicBlock* block, EntryState* currentState);

void verConvertBBToThrowVerificationException(BasicBlock* block DEBUGARG(bool logMsg));
void verHandleVerificationFailure(BasicBlock* block DEBUGARG(bool logMsg));
typeInfo verMakeTypeInfoForLocal(unsigned lclNum);
typeInfo verMakeTypeInfo(CORINFO_CLASS_HANDLE clsHnd); // converts from jit type representation to typeInfo
typeInfo verMakeTypeInfo(CorInfoType ciType,
Expand Down
94 changes: 7 additions & 87 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2516,70 +2516,6 @@ GenTree* Compiler::impGetGenericTypeDefinition(GenTree* type)
return nullptr;
}

/*****************************************************************************
* 'logMsg' is true if a log message needs to be logged. false if the caller has
* already logged it (presumably in a more detailed fashion than done here)
*/

void Compiler::verConvertBBToThrowVerificationException(BasicBlock* block DEBUGARG(bool logMsg))
{
block->SetKindAndTargetEdge(BBJ_THROW);
block->SetFlags(BBF_FAILED_VERIFICATION);
block->RemoveFlags(BBF_IMPORTED);

impCurStmtOffsSet(block->bbCodeOffs);

// Clear the statement list as it exists so far; we're only going to have a verification exception.
impStmtList = impLastStmt = nullptr;

#ifdef DEBUG
if (logMsg)
{
JITLOG((LL_ERROR, "Verification failure: while compiling %s near IL offset %x..%xh \n", info.compFullName,
block->bbCodeOffs, block->bbCodeOffsEnd));
if (verbose)
{
printf("\n\nVerification failure: %s near IL %xh \n", info.compFullName, block->bbCodeOffs);
}
}

if (JitConfig.DebugBreakOnVerificationFailure())
{
DebugBreak();
}
#endif

impBeginTreeList();

// if the stack is non-empty evaluate all the side-effects
if (verCurrentState.esStackDepth > 0)
{
impEvalSideEffects();
}
assert(verCurrentState.esStackDepth == 0);

GenTree* op1 = gtNewHelperCallNode(CORINFO_HELP_VERIFICATION, TYP_VOID, gtNewIconNode(block->bbCodeOffs));
// verCurrentState.esStackDepth = 0;
impAppendTree(op1, CHECK_SPILL_NONE, impCurStmtDI);

// The inliner is not able to handle methods that require throw block, so
// make sure this methods never gets inlined.
info.compCompHnd->setMethodAttribs(info.compMethodHnd, CORINFO_FLG_BAD_INLINEE);
}

/*****************************************************************************
*
*/
void Compiler::verHandleVerificationFailure(BasicBlock* block DEBUGARG(bool logMsg))
{
verResetCurrentState(block, &verCurrentState);
verConvertBBToThrowVerificationException(block DEBUGARG(logMsg));

#ifdef DEBUG
impNoteLastILoffs(); // Remember at which BC offset the tree was finished
#endif // DEBUG
}

typeInfo Compiler::verMakeTypeInfoForLocal(unsigned lclNum)
{
LclVarDsc* varDsc = lvaGetDesc(lclNum);
Expand Down Expand Up @@ -11819,9 +11755,6 @@ void Compiler::impImportBlock(BasicBlock* block)
BADCODE("bad stack state");
}

// Oops. Something went wrong when spilling. Bad code.
verHandleVerificationFailure(block DEBUGARG(true));

goto SPILLSTACK;
}
}
Expand Down Expand Up @@ -11911,8 +11844,7 @@ void Compiler::impImportBlockPending(BasicBlock* block)
// Initialize bbEntryState just the first time we try to add this block to the pending list
// Just because bbEntryState is NULL, doesn't mean the pre-state wasn't previously set
// We use NULL to indicate the 'common' state to avoid memory allocation
if ((block->bbEntryState == nullptr) && !block->HasAnyFlag(BBF_IMPORTED | BBF_FAILED_VERIFICATION) &&
(impGetPendingBlockMember(block) == 0))
if ((block->bbEntryState == nullptr) && !block->HasFlag(BBF_IMPORTED) && (impGetPendingBlockMember(block) == 0))
{
verInitBBEntryState(block, &verCurrentState);
assert(block->bbStkDepth == 0);
Expand Down Expand Up @@ -12169,12 +12101,9 @@ void Compiler::ReimportSpillClique::Visit(SpillCliqueDir predOrSucc, BasicBlock*

if (!blk->HasFlag(BBF_IMPORTED) && (m_pComp->impGetPendingBlockMember(blk) == 0))
{
// If we haven't imported this block and we're not going to (because it isn't on
// the pending list) then just ignore it for now.

// This block has either never been imported (EntryState == NULL) or it failed
// verification. Neither state requires us to force it to be imported now.
assert((blk->bbEntryState == nullptr) || blk->HasFlag(BBF_FAILED_VERIFICATION));
// If we haven't imported this block (EntryState == NULL) and we're not going to
// (because it isn't on the pending list) then just ignore it for now.
assert(blk->bbEntryState == nullptr);
return;
}

Expand Down Expand Up @@ -12502,20 +12431,11 @@ void Compiler::impImport()
impPendingFree = dsc;

/* Now import the block */
impImportBlock(dsc->pdBB);

if (dsc->pdBB->HasFlag(BBF_FAILED_VERIFICATION))
{
verConvertBBToThrowVerificationException(dsc->pdBB DEBUGARG(true));
impEndTreeList(dsc->pdBB);
}
else
if (compDonotInline())
{
impImportBlock(dsc->pdBB);

if (compDonotInline())
{
return;
}
return;
}
}

Expand Down
Loading