Skip to content
Merged
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/jit/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,7 @@ inline PredBlockList::iterator& PredBlockList::iterator::operator++()
* emitter to convert a basic block to its corresponding emitter cookie.
*/

void* emitCodeGetCookie(BasicBlock* block);
void* emitCodeGetCookie(const BasicBlock* block);

// An enumerator of a block's all successors. In some cases (e.g. SsaBuilder::TopologicalSort)
// using iterators is not exactly efficient, at least because they contain an unnecessary
Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,9 @@ void CodeGen::genPrepForCompiler()
// 1. the target of jumps (fall-through flow doesn't require a label),
// 2. referenced labels such as for "switch" codegen,
// 3. needed to denote the range of EH regions to the VM.
// 4. needed to denote the range of code for alignment processing.
//
// No labels will be in the IR before now, but future codegen might annotate additional blocks
// with this flag, such as "switch" codegen, or codegen-created blocks from genCreateTempLabel().
// Also, the alignment processing code marks BBJ_COND fall-through labels elsewhere.
//
// To report exception handling information to the VM, we need the size of the exception
// handling regions. To compute that, we need to emit labels for the beginning block of
Expand Down Expand Up @@ -2588,7 +2586,6 @@ void CodeGen::genReportEH()
}
else
{
assert(bbLabel->bbEmitCookie != nullptr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to ehCodeOffset has the same assert, so it didn't seem necessary.

hndEnd = compiler->ehCodeOffset(bbLabel);
}

Expand Down
71 changes: 37 additions & 34 deletions src/coreclr/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,38 @@ void CodeGen::genCodeForBBlist()
}
#endif // TARGET_AMD64

#if FEATURE_LOOP_ALIGN
auto SetLoopAlignBackEdge = [=](const BasicBlock* block, const BasicBlock* target) {
// This is the last place where we operate on blocks and after this, we operate
// on IG. Hence, if we know that the destination of "block" is the first block
// of a loop and that loop needs alignment (it has BBF_LOOP_ALIGN), then "block"
// might represent the lexical end of the loop. Propagate that information on the
// IG through "igLoopBackEdge".
//
// During emitter, this information will be used to calculate the loop size.
// Depending on the loop size, the decision of whether to align a loop or not will be taken.
// (Loop size is calculated by walking the instruction groups; see emitter::getLoopSize()).
// If `igLoopBackEdge` is set, then mark the next BasicBlock as a label. This will cause
// the emitter to create a new IG for the next block. Otherwise, if the next block
// did not have a label, additional instructions might be added to the current IG. This
// would make the "back edge" IG larger, possibly causing the size of the loop computed
// by `getLoopSize()` to be larger than actual, which could push the loop size over the
// threshold of loop size that can be aligned.

if (target->isLoopAlign())
{
if (GetEmitter()->emitSetLoopBackEdge(target))
{
if (!block->IsLast())
{
JITDUMP("Mark " FMT_BB " as label: alignment end-of-loop\n", block->Next()->bbNum);
block->Next()->SetFlags(BBF_HAS_LABEL);
}
}
}
};
#endif // FEATURE_LOOP_ALIGN

/* Do we need to generate a jump or return? */

switch (block->GetKind())
Expand Down Expand Up @@ -746,45 +778,16 @@ void CodeGen::genCodeForBBlist()
}

#if FEATURE_LOOP_ALIGN
// This is the last place where we operate on blocks and after this, we operate
// on IG. Hence, if we know that the destination of "block" is the first block
// of a loop and needs alignment (it has BBF_LOOP_ALIGN), then "block" represents
// end of the loop. Propagate that information on the IG through "igLoopBackEdge".
//
// During emitter, this information will be used to calculate the loop size.
// Depending on the loop size, decision of whether to align a loop or not will be taken.
//
// In the emitter, we need to calculate the loop size from `block->bbTarget` through
// `block` (inclusive). Thus, we need to ensure there is a label on the lexical fall-through
// block, even if one is not otherwise needed, to be able to calculate the size of this
// loop (loop size is calculated by walking the instruction groups; see emitter::getLoopSize()).

if (block->GetTarget()->isLoopAlign())
{
GetEmitter()->emitSetLoopBackEdge(block->GetTarget());

if (!block->IsLast())
{
JITDUMP("Mark " FMT_BB " as label: alignment end-of-loop\n", block->Next()->bbNum);
block->Next()->SetFlags(BBF_HAS_LABEL);
}
}
SetLoopAlignBackEdge(block, block->GetTarget());
#endif // FEATURE_LOOP_ALIGN
break;

case BBJ_COND:

#if FEATURE_LOOP_ALIGN
if (block->GetTrueTarget()->isLoopAlign())
{
GetEmitter()->emitSetLoopBackEdge(block->GetTrueTarget());

if (!block->IsLast())
{
JITDUMP("Mark " FMT_BB " as label: alignment end-of-loop\n", block->Next()->bbNum);
block->Next()->SetFlags(BBF_HAS_LABEL);
}
}
// Either true or false target of BBJ_COND can induce a loop.
SetLoopAlignBackEdge(block, block->GetTrueTarget());
SetLoopAlignBackEdge(block, block->GetFalseTarget());
#endif // FEATURE_LOOP_ALIGN

break;
Expand Down Expand Up @@ -824,7 +827,7 @@ void CodeGen::genCodeForBBlist()
GetEmitter()->emitConnectAlignInstrWithCurIG();
}
}
#endif
#endif // FEATURE_LOOP_ALIGN

#ifdef DEBUG
if (compiler->verbose)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5318,8 +5318,8 @@ bool Compiler::shouldAlignLoop(FlowGraphNaturalLoop* loop, BasicBlock* top)

if (top->Prev()->isBBCallFinallyPairTail())
{
// If the previous block is the BBJ_ALWAYS of a
// BBJ_CALLFINALLY/BBJ_ALWAYS pair, then we can't add alignment
// If the previous block is the BBJ_CALLFINALLYRET of a
// BBJ_CALLFINALLY/BBJ_CALLFINALLYRET pair, then we can't add alignment
// because we can't add instructions in that block. In the
// FEATURE_EH_CALLFINALLY_THUNKS case, it would affect the
// reported EH, as above.
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3488,7 +3488,7 @@ inline void Compiler::compUpdateLife(VARSET_VALARG_TP newLife)
* the cookie associated with the given basic block.
*/

inline void* emitCodeGetCookie(BasicBlock* block)
inline void* emitCodeGetCookie(const BasicBlock* block)
{
assert(block);
return block->bbEmitCookie;
Expand Down
Loading