-
Notifications
You must be signed in to change notification settings - Fork 5.3k
JIT: remove anticipated demand for throw helpers #123781
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
Open
AndyAyersMS
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
AndyAyersMS:NoAcdDemands
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+116
−193
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3384,7 +3384,7 @@ Compiler::AddCodeDscMap* Compiler::fgGetAddCodeDscMap() | |
| } | ||
|
|
||
| //------------------------------------------------------------------------ | ||
| // fgAddCodeRef: Indicate that a particular throw helper block will | ||
| // fgCreateAddCodeDsc: Indicate that a particular throw helper block will | ||
| // be needed by the method. | ||
| // | ||
| // Arguments: | ||
|
|
@@ -3395,42 +3395,18 @@ Compiler::AddCodeDscMap* Compiler::fgGetAddCodeDscMap() | |
| // You can call this method after throw helpers have been created, | ||
| // but it will assert if this entails creation of a new helper. | ||
| // | ||
| void Compiler::fgAddCodeRef(BasicBlock* srcBlk, SpecialCodeKind kind) | ||
| Compiler::AddCodeDsc* Compiler::fgCreateAddCodeDsc(BasicBlock* srcBlk, SpecialCodeKind kind) | ||
| { | ||
| // Record that the code will call a THROW_HELPER | ||
| // so on Windows Amd64 we can allocate the 4 outgoing | ||
| // arg slots on the stack frame if there are no other calls. | ||
| // | ||
| compUsesThrowHelper = true; | ||
|
|
||
| if (!fgUseThrowHelperBlocks() && (kind != SCK_FAIL_FAST)) | ||
| { | ||
| // FailFast will still use a common throw helper, even in debuggable modes. | ||
| // | ||
| return; | ||
| } | ||
| assert(!fgRngChkThrowAdded); | ||
|
|
||
| // Fetch block data and designator | ||
| // | ||
| AcdKeyDesignator dsg = AcdKeyDesignator::KD_NONE; | ||
| unsigned const refData = (kind == SCK_FAIL_FAST) ? 0 : bbThrowIndex(srcBlk, &dsg); | ||
|
|
||
| // Look for an existing entry that matches what we're looking for | ||
| // | ||
| AddCodeDsc* add = fgFindExcptnTarget(kind, srcBlk); | ||
|
|
||
| if (add != nullptr) | ||
| { | ||
| JITDUMP(FMT_BB " requires throw helper block for %s, sharing ACD%u (data 0x%08x)\n", srcBlk->bbNum, | ||
| sckName(kind), add->acdNum, refData); | ||
| return; | ||
| } | ||
|
|
||
| assert(!fgRngChkThrowAdded); | ||
|
|
||
| // Allocate a new entry and prepend it to the list | ||
| // | ||
| add = new (this, CMK_Unknown) AddCodeDsc; | ||
| AddCodeDsc* add = new (this, CMK_BasicBlock) AddCodeDsc; | ||
| add->acdDstBlk = nullptr; | ||
| add->acdTryIndex = srcBlk->bbTryIndex; | ||
|
|
||
|
|
@@ -3467,25 +3443,26 @@ void Compiler::fgAddCodeRef(BasicBlock* srcBlk, SpecialCodeKind kind) | |
| assert(map->Lookup(key2, &add2)); | ||
| assert(add == add2); | ||
| #endif | ||
|
|
||
| return add; | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------ | ||
| // fgCreateThrowHelperBlocks: create the needed throw helpers | ||
| // fgCreateThrowHelperBlock: create a throw helper block | ||
| // | ||
| // Returns: | ||
| // Suitable phase status | ||
| // Arguments: | ||
| // add -- addCodeDesc describing the block to create | ||
| // | ||
| // Notes: | ||
| // Creates a new block if necessary, and sets the add->acdDstBlk to the new block. | ||
| // | ||
| PhaseStatus Compiler::fgCreateThrowHelperBlocks() | ||
| void Compiler::fgCreateThrowHelperBlock(AddCodeDsc* add) | ||
| { | ||
| if (fgAddCodeDscMap == nullptr) | ||
| if (add->acdDstBlk != nullptr) | ||
| { | ||
| return PhaseStatus::MODIFIED_NOTHING; | ||
| return; | ||
| } | ||
|
|
||
| // We should not have added throw helper blocks yet. | ||
| // | ||
| assert(!fgRngChkThrowAdded); | ||
|
|
||
| const static BBKinds jumpKinds[] = { | ||
| BBJ_ALWAYS, // SCK_NONE | ||
| BBJ_THROW, // SCK_RNGCHK_FAIL | ||
|
|
@@ -3499,89 +3476,82 @@ PhaseStatus Compiler::fgCreateThrowHelperBlocks() | |
|
|
||
| noway_assert(sizeof(jumpKinds) == SCK_COUNT); // sanity check | ||
|
|
||
| for (AddCodeDsc* const add : AddCodeDscMap::ValueIteration(fgAddCodeDscMap)) | ||
| { | ||
| // Create the target basic block in the region indicated by the acd info | ||
| // | ||
| assert(add->acdKind != SCK_NONE); | ||
| bool const putInFilter = (add->acdKeyDsg == AcdKeyDesignator::KD_FLT); | ||
| BasicBlock* const newBlk = fgNewBBinRegion(jumpKinds[add->acdKind], add->acdTryIndex, add->acdHndIndex, | ||
| /* nearBlk */ nullptr, putInFilter, | ||
| /* runRarely */ true, /* insertAtEnd */ true); | ||
| // Create the target basic block in the region indicated by the acd info | ||
| // | ||
| assert(add->acdKind != SCK_NONE); | ||
| bool const putInFilter = (add->acdKeyDsg == AcdKeyDesignator::KD_FLT); | ||
| BasicBlock* const newBlk = fgNewBBinRegion(jumpKinds[add->acdKind], add->acdTryIndex, add->acdHndIndex, | ||
| /* nearBlk */ nullptr, putInFilter, | ||
| /* runRarely */ true, /* insertAtEnd */ true); | ||
|
|
||
| // Update the descriptor so future lookups can find the block | ||
| // | ||
| add->acdDstBlk = newBlk; | ||
| // Update the descriptor so future lookups can find the block | ||
| // | ||
| add->acdDstBlk = newBlk; | ||
|
|
||
| #ifdef DEBUG | ||
| if (verbose) | ||
| if (verbose) | ||
| { | ||
| const char* msgWhere = ""; | ||
| switch (add->acdKeyDsg) | ||
| { | ||
| const char* msgWhere = ""; | ||
| switch (add->acdKeyDsg) | ||
| { | ||
| case AcdKeyDesignator::KD_NONE: | ||
| msgWhere = "non-EH region"; | ||
| break; | ||
|
|
||
| case AcdKeyDesignator::KD_HND: | ||
| msgWhere = "handler"; | ||
| break; | ||
| case AcdKeyDesignator::KD_NONE: | ||
| msgWhere = "non-EH region"; | ||
| break; | ||
|
|
||
| case AcdKeyDesignator::KD_TRY: | ||
| msgWhere = "try"; | ||
| break; | ||
| case AcdKeyDesignator::KD_HND: | ||
| msgWhere = "handler"; | ||
| break; | ||
|
|
||
| case AcdKeyDesignator::KD_FLT: | ||
| msgWhere = "filter"; | ||
| break; | ||
| case AcdKeyDesignator::KD_TRY: | ||
| msgWhere = "try"; | ||
| break; | ||
|
|
||
| default: | ||
| msgWhere = "? unexpected"; | ||
| } | ||
| case AcdKeyDesignator::KD_FLT: | ||
| msgWhere = "filter"; | ||
| break; | ||
|
|
||
| const char* msg; | ||
| switch (add->acdKind) | ||
| { | ||
| case SCK_RNGCHK_FAIL: | ||
| msg = " for RNGCHK_FAIL"; | ||
| break; | ||
| case SCK_DIV_BY_ZERO: | ||
| msg = " for DIV_BY_ZERO"; | ||
| break; | ||
| case SCK_OVERFLOW: | ||
| msg = " for OVERFLOW"; | ||
| break; | ||
| case SCK_ARG_EXCPN: | ||
| msg = " for ARG_EXCPN"; | ||
| break; | ||
| case SCK_ARG_RNG_EXCPN: | ||
| msg = " for ARG_RNG_EXCPN"; | ||
| break; | ||
| case SCK_FAIL_FAST: | ||
| msg = " for FAIL_FAST"; | ||
| break; | ||
| case SCK_NULL_CHECK: | ||
| msg = " for NULL_CHECK"; | ||
| break; | ||
| default: | ||
| msg = " for ??"; | ||
| break; | ||
| } | ||
| default: | ||
| msgWhere = "? unexpected"; | ||
| } | ||
|
|
||
| printf("\nAdding throw helper " FMT_BB " for ACD%u %s in %s%s\n", newBlk->bbNum, add->acdNum, | ||
| sckName(add->acdKind), msgWhere, msg); | ||
| const char* msg; | ||
| switch (add->acdKind) | ||
| { | ||
| case SCK_RNGCHK_FAIL: | ||
| msg = " for RNGCHK_FAIL"; | ||
| break; | ||
| case SCK_DIV_BY_ZERO: | ||
| msg = " for DIV_BY_ZERO"; | ||
| break; | ||
| case SCK_OVERFLOW: | ||
| msg = " for OVERFLOW"; | ||
| break; | ||
| case SCK_ARG_EXCPN: | ||
| msg = " for ARG_EXCPN"; | ||
| break; | ||
| case SCK_ARG_RNG_EXCPN: | ||
| msg = " for ARG_RNG_EXCPN"; | ||
| break; | ||
| case SCK_FAIL_FAST: | ||
| msg = " for FAIL_FAST"; | ||
| break; | ||
| case SCK_NULL_CHECK: | ||
| msg = " for NULL_CHECK"; | ||
| break; | ||
| default: | ||
| msg = " for ??"; | ||
| break; | ||
| } | ||
| #endif // DEBUG | ||
|
|
||
| // Mark the block as added by the compiler and not removable by future flow | ||
| // graph optimizations. Note that no target block points to these blocks. | ||
| // | ||
| newBlk->SetFlags(BBF_IMPORTED | BBF_DONT_REMOVE); | ||
| printf("\nAdding throw helper " FMT_BB " for ACD%u %s in %s%s\n", newBlk->bbNum, add->acdNum, | ||
| sckName(add->acdKind), msgWhere, msg); | ||
| } | ||
| #endif // DEBUG | ||
|
|
||
| fgRngChkThrowAdded = true; | ||
|
|
||
| return PhaseStatus::MODIFIED_EVERYTHING; | ||
| // Mark the block as added by the compiler and not removable by future flow | ||
| // graph optimizations. Note that no target block points to these blocks. | ||
| // | ||
| newBlk->SetFlags(BBF_IMPORTED | BBF_DONT_REMOVE); | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------ | ||
|
|
@@ -3627,6 +3597,10 @@ void Compiler::fgCreateThrowHelperBlockCode(AddCodeDsc* add) | |
| helper = CORINFO_HELP_FAIL_FAST; | ||
| break; | ||
|
|
||
| case SCK_NULL_CHECK: | ||
| helper = CORINFO_HELP_THROWNULLREF; | ||
| break; | ||
|
|
||
| default: | ||
| noway_assert(!"unexpected code addition kind"); | ||
| } | ||
|
|
@@ -3637,7 +3611,9 @@ void Compiler::fgCreateThrowHelperBlockCode(AddCodeDsc* add) | |
| // | ||
| GenTreeCall* tree = gtNewHelperCallNode(helper, TYP_VOID); | ||
|
|
||
| // There are no args here but fgMorphArgs has side effects | ||
| // For Wasm we may add an arg to the throw helper. | ||
| // | ||
| // Also fgMorphArgs has side effects | ||
| // such as setting the outgoing arg area (which is necessary | ||
| // on AMD if there are any calls). | ||
| // | ||
|
|
@@ -3651,8 +3627,8 @@ void Compiler::fgCreateThrowHelperBlockCode(AddCodeDsc* add) | |
| } | ||
| else | ||
| { | ||
| LIR::AsRange(block).InsertAtEnd(tree); | ||
| LIR::ReadOnlyRange range(tree, tree); | ||
| LIR::Range range = LIR::SeqTree(this, tree); | ||
| LIR::AsRange(block).InsertAtEnd(std::move(range)); | ||
| m_pLowering->LowerRange(block, range); | ||
| } | ||
| } | ||
|
|
@@ -3668,7 +3644,7 @@ void Compiler::fgCreateThrowHelperBlockCode(AddCodeDsc* add) | |
| // Code descriptor for the appropriate throw helper block, or nullptr if no such | ||
| // descriptor exists. | ||
| // | ||
| Compiler::AddCodeDsc* Compiler::fgFindExcptnTarget(SpecialCodeKind kind, BasicBlock* fromBlock) | ||
| Compiler::AddCodeDsc* Compiler::fgFindExcptnTarget(SpecialCodeKind kind, BasicBlock* fromBlock, bool createIfNeeded) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit]
|
||
| { | ||
| assert(fgUseThrowHelperBlocks() || (kind == SCK_FAIL_FAST)); | ||
| AddCodeDsc* add = nullptr; | ||
|
|
@@ -3678,20 +3654,14 @@ Compiler::AddCodeDsc* Compiler::fgFindExcptnTarget(SpecialCodeKind kind, BasicBl | |
|
|
||
| if (add == nullptr) | ||
| { | ||
| // We shouldn't be asking for these blocks late in compilation | ||
| // unless we know there are entries to be found. | ||
| if (fgRngChkThrowAdded) | ||
| { | ||
| JITDUMP(FMT_BB ": unexpected request for new throw helper: kind %d (%s), data 0x%08x\n", fromBlock->bbNum, | ||
| kind, sckName(kind), key.Data()); | ||
| add = fgCreateAddCodeDsc(fromBlock, kind); | ||
|
|
||
| if (kind == SCK_NULL_CHECK) | ||
| { | ||
| NYI_WASM("Missing null check demand"); | ||
| } | ||
| // Create the block... | ||
| // | ||
| if (createIfNeeded) | ||
| { | ||
| fgCreateThrowHelperBlock(add); | ||
| } | ||
|
|
||
| assert(!fgRngChkThrowAdded); | ||
| } | ||
|
|
||
| return add; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing // Returns (or is it Return Value) in the comment