Skip to content

Make EntryPointInfo::callsCount usable by redeferral heuristic. #1757

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

Closed
wants to merge 1 commit into from
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
10 changes: 3 additions & 7 deletions lib/Backend/BailOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ void BailOutRecord::ScheduleFunctionCodeGen(Js::ScriptFunction * function, Js::S
bailOutRecordNotConst->bailOutCount++;

Js::FunctionEntryPointInfo *entryPointInfo = function->GetFunctionEntryPointInfo();
uint8 callsCount = entryPointInfo->callsCount;
uint32 callsCount = entryPointInfo->callsCount;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can just change this to:
uint32 callsCount = MIN(entryPointInfo->callsCount, 255);
to retain the previous bailout behavior we had with saturation.

RejitReason rejitReason = RejitReason::None;
bool reThunk = false;

Expand Down Expand Up @@ -2312,11 +2312,7 @@ void BailOutRecord::ScheduleLoopBodyCodeGen(Js::ScriptFunction * function, Js::S

entryPointInfo->totalJittedLoopIterations += entryPointInfo->jittedLoopIterationsSinceLastBailout;
entryPointInfo->jittedLoopIterationsSinceLastBailout = 0;
if (entryPointInfo->totalJittedLoopIterations > UINT8_MAX)
{
entryPointInfo->totalJittedLoopIterations = UINT8_MAX;
}
uint8 totalJittedLoopIterations = (uint8)entryPointInfo->totalJittedLoopIterations;
uint32 totalJittedLoopIterations = entryPointInfo->totalJittedLoopIterations;
Copy link
Contributor

Choose a reason for hiding this comment

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

uint32 totalJittedLoopIterations = entryPointInfo->totalJittedLoopIterations; [](start = 4, length = 77)

In keeping with @LouisLaf 's suggestion in ScheduleFunctionCodeGen, we should retain the existing code here.

totalJittedLoopIterations = totalJittedLoopIterations <= Js::LoopEntryPointInfo::GetDecrLoopCountPerBailout() ? 0 : totalJittedLoopIterations - Js::LoopEntryPointInfo::GetDecrLoopCountPerBailout();

CheckPreemptiveRejit(executeFunction, bailOutKind, bailOutRecordNotConst, totalJittedLoopIterations, interpreterFrame->GetCurrentLoopNum());
Expand Down Expand Up @@ -2598,7 +2594,7 @@ void BailOutRecord::ScheduleLoopBodyCodeGen(Js::ScriptFunction * function, Js::S
}
}

void BailOutRecord::CheckPreemptiveRejit(Js::FunctionBody* executeFunction, IR::BailOutKind bailOutKind, BailOutRecord* bailoutRecord, uint8& callsOrIterationsCount, int loopNumber)
void BailOutRecord::CheckPreemptiveRejit(Js::FunctionBody* executeFunction, IR::BailOutKind bailOutKind, BailOutRecord* bailoutRecord, uint32& callsOrIterationsCount, int loopNumber)
{
if (bailOutKind == IR::BailOutOnNoProfile && executeFunction->IncrementBailOnMisingProfileCount() > CONFIG_FLAG(BailOnNoProfileLimit))
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Backend/BailOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class BailOutRecord

static void ScheduleFunctionCodeGen(Js::ScriptFunction * function, Js::ScriptFunction * innerMostInlinee, BailOutRecord const * bailOutRecord, IR::BailOutKind bailOutKind, Js::ImplicitCallFlags savedImplicitCallFlags, void * returnAddress);
static void ScheduleLoopBodyCodeGen(Js::ScriptFunction * function, Js::ScriptFunction * innerMostInlinee, BailOutRecord const * bailOutRecord, IR::BailOutKind bailOutKind);
static void CheckPreemptiveRejit(Js::FunctionBody* executeFunction, IR::BailOutKind bailOutKind, BailOutRecord* bailoutRecord, uint8& callsOrIterationsCount, int loopNumber);
static void CheckPreemptiveRejit(Js::FunctionBody* executeFunction, IR::BailOutKind bailOutKind, BailOutRecord* bailoutRecord, uint32& callsOrIterationsCount, int loopNumber);
void RestoreValues(IR::BailOutKind bailOutKind, Js::JavascriptCallStackLayout * layout, Js::InterpreterStackFrame * newInstance, Js::ScriptContext * scriptContext,
bool fromLoopBody, Js::Var * registerSaves, BailOutReturnValue * returnValue, Js::Var* pArgumentsObject, Js::Var branchValue = nullptr, void* returnAddress = nullptr, bool useStartCall = true, void * argoutRestoreAddress = nullptr) const;
void RestoreValues(IR::BailOutKind bailOutKind, Js::JavascriptCallStackLayout * layout, uint count, __in_ecount_opt(count) int * offsets, int argOutSlotId,
Expand Down
71 changes: 56 additions & 15 deletions lib/Backend/Lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14506,22 +14506,65 @@ IR::Instr *Lowerer::InsertConvertFloat64ToFloat32(
return instr;
}

void Lowerer::InsertIncUInt8PreventOverflow(
void Lowerer::InsertDecUInt32PreventOverflow(
IR::Opnd *const dst,
IR::Opnd *const src,
IR::Instr *const insertBeforeInstr,
IR::Instr * *const onOverflowInsertBeforeInstrRef)
{
LowererMD::InsertIncUInt8PreventOverflow(dst, src, insertBeforeInstr, onOverflowInsertBeforeInstrRef);
}
Assert(dst);
Assert(dst->GetType() == TyUint32);
Assert(src);
Assert(src->GetType() == TyUint32);
Assert(insertBeforeInstr);

void Lowerer::InsertDecUInt8PreventOverflow(
IR::Opnd *const dst,
IR::Opnd *const src,
IR::Instr *const insertBeforeInstr,
IR::Instr * *const onOverflowInsertBeforeInstrRef)
{
LowererMD::InsertDecUInt8PreventOverflow(dst, src, insertBeforeInstr, onOverflowInsertBeforeInstrRef);
Func *const func = insertBeforeInstr->m_func;

// Generate:
// subs temp, src, 1
// bcs $overflow
// mov dst, temp
// b $continue
// $overflow:
// mov dst, 0
// $continue:

IR::LabelInstr *const overflowLabel = Lowerer::InsertLabel(false, insertBeforeInstr);

// subs temp, src, 1
IR::RegOpnd *const tempOpnd = IR::RegOpnd::New(StackSym::New(TyUint32, func), TyUint8, func);
const IR::AutoReuseOpnd autoReuseTempOpnd(tempOpnd, func);
Lowerer::InsertSub(true, tempOpnd, src, IR::IntConstOpnd::New(1, TyUint32, func, true), overflowLabel);

// bcs $overflow
Lowerer::InsertBranch(Js::OpCode::BrLt_A, true, overflowLabel, overflowLabel);

Copy link
Collaborator

Choose a reason for hiding this comment

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

With int32, I think we don't even care about the overflow. Plus, with saturation, it doesn't fix the retiring problem, it just delays it.

// mov dst, temp
Lowerer::InsertMove(dst, tempOpnd, overflowLabel);

const bool dstEqualsSrc = dst->IsEqual(src);
if(!dstEqualsSrc || onOverflowInsertBeforeInstrRef)
{
// b $continue
// $overflow:
// mov dst, 0
// $continue:
IR::LabelInstr *const continueLabel = Lowerer::InsertLabel(false, insertBeforeInstr);
Lowerer::InsertBranch(Js::OpCode::Br, continueLabel, overflowLabel);
if(!dstEqualsSrc)
{
Lowerer::InsertMove(dst, IR::IntConstOpnd::New(0, TyUint32, func, true), continueLabel);
}

if(onOverflowInsertBeforeInstrRef)
{
*onOverflowInsertBeforeInstrRef = continueLabel;
}
}
else
{
// $overflow:
}
}

void Lowerer::InsertFloatCheckForZeroOrNanBranch(
Expand Down Expand Up @@ -21850,18 +21893,16 @@ void Lowerer::LowerFunctionBodyCallCountChange(IR::Instr *const insertBeforeInst
IR::AddrOpnd::New((Js::Var)func->GetWorkItem()->GetCallsCountAddress(), IR::AddrOpndKindDynamicMisc, func, true),
insertBeforeInstr);

IR::IndirOpnd *const countOpnd = IR::IndirOpnd::New(countAddressOpnd, 0, TyUint8, func);
IR::IndirOpnd *const countOpnd = IR::IndirOpnd::New(countAddressOpnd, 0, TyUint32, func);
const IR::AutoReuseOpnd autoReuseCountOpnd(countOpnd, func);
if(!isSimpleJit)
{
// InsertIncUint8PreventOverflow [countAddress]
InsertIncUInt8PreventOverflow(countOpnd, countOpnd, insertBeforeInstr);
Lowerer::InsertAdd(false, countOpnd, countOpnd, IR::IntConstOpnd::New(1, TyUint32, func, true), insertBeforeInstr);
return;
}

// InsertDecUint8PreventOverflow [countAddress]
IR::Instr *onOverflowInsertBeforeInstr;
InsertDecUInt8PreventOverflow(
InsertDecUInt32PreventOverflow(
countOpnd,
countOpnd,
insertBeforeInstr,
Expand Down
3 changes: 1 addition & 2 deletions lib/Backend/Lower.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ class Lowerer
static IR::Instr * InsertConvertFloat64ToFloat32(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr);

public:
static void InsertIncUInt8PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr);
static void InsertDecUInt8PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr);
static void InsertDecUInt32PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr);
void InsertFloatCheckForZeroOrNanBranch(IR::Opnd *const src, const bool branchOnZeroOrNan, IR::LabelInstr *const target, IR::LabelInstr *const fallthroughLabel, IR::Instr *const insertBeforeInstr);

public:
Expand Down
78 changes: 0 additions & 78 deletions lib/Backend/LowerMDShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4713,84 +4713,6 @@ LowererMD::GenerateStFldFromLocalInlineCache(
instrStFld->InsertBefore(instr);
}

void LowererMD::InsertIncUInt8PreventOverflow(
IR::Opnd *const dst,
IR::Opnd *const src,
IR::Instr *const insertBeforeInstr,
IR::Instr * *const onOverflowInsertBeforeInstrRef)
{
Assert(dst);
Assert(dst->GetType() == TyUint8);
Assert(src);
Assert(src->GetType() == TyUint8);
Assert(insertBeforeInstr);

Func *const func = insertBeforeInstr->m_func;

// Generate:
// cmp src, static_cast<uint8>(-1)
// jeq $done
// dst = add src, 1
// $noOverflow:

IR::LabelInstr *const noOverflowLabel = Lowerer::InsertLabel(false, insertBeforeInstr);

Lowerer::InsertCompareBranch(src, IR::IntConstOpnd::New(static_cast<uint8>(-1), TyUint8, func, true),
Js::OpCode::BrEq_A, noOverflowLabel, noOverflowLabel);

// inc dst, src
Lowerer::InsertAdd(true, dst, src, IR::IntConstOpnd::New(1, TyUint8, func, true), noOverflowLabel);


// $done:

if(onOverflowInsertBeforeInstrRef)
{
*onOverflowInsertBeforeInstrRef = noOverflowLabel;
}
}

void LowererMD::InsertDecUInt8PreventOverflow(
IR::Opnd *const dst,
IR::Opnd *const src,
IR::Instr *const insertBeforeInstr,
IR::Instr * *const onOverflowInsertBeforeInstrRef)
{
Assert(dst);
Assert(dst->GetType() == TyUint8);
Assert(src);
Assert(src->GetType() == TyUint8);
Assert(insertBeforeInstr);

Func *const func = insertBeforeInstr->m_func;

// Generate:
// sub dst, src, 1
// jnc $noOverflow
// mov dst, 0
// $noOverflow:

IR::LabelInstr *const noOverflowLabel = Lowerer::InsertLabel(false, insertBeforeInstr);

// sub dst, src, 1
IR::Instr *const instr = IR::Instr::New(Js::OpCode::SUB, dst, src, IR::IntConstOpnd::New(1, TyUint8, func, true), func);
noOverflowLabel->InsertBefore(instr);
MakeDstEquSrc1(instr);

// jnc $noOverflow
Lowerer::InsertBranch(Js::OpCode::BrGe_A, true, noOverflowLabel, noOverflowLabel);

// mov dst, 0
Lowerer::InsertMove(dst, IR::IntConstOpnd::New(0, TyUint8, func, true), noOverflowLabel);

// $noOverflow:

if(onOverflowInsertBeforeInstrRef)
{
*onOverflowInsertBeforeInstrRef = noOverflowLabel;
}
}

//----------------------------------------------------------------------------
//
// LowererMD::GenerateFastScopedLdFld
Expand Down
2 changes: 0 additions & 2 deletions lib/Backend/LowerMDShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ class LowererMD
}

public:
static void InsertIncUInt8PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr);
static void InsertDecUInt8PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr);

#ifdef ENABLE_SIMDJS
void Simd128InitOpcodeMap();
Expand Down
129 changes: 0 additions & 129 deletions lib/Backend/arm/LowerMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,135 +452,6 @@ LowererMD::GenerateFunctionObjectTest(IR::Instr * callInstr, IR::RegOpnd *funct
}
}

void LowererMD::InsertIncUInt8PreventOverflow(
IR::Opnd *const dst,
IR::Opnd *const src,
IR::Instr *const insertBeforeInstr,
IR::Instr * *const onOverflowInsertBeforeInstrRef)
{
Assert(dst);
Assert(dst->GetType() == TyUint8);
Assert(src);
Assert(src->GetType() == TyUint8);
Assert(insertBeforeInstr);

Func *const func = insertBeforeInstr->m_func;

// Generate:
// add temp, src, 1
// tst temp, static_cast<uint8>(-1)
// beq $overflow
// mov dst, temp
// b $continue
// $overflow:
// mov dst, static_cast<uint8>(-1)
// $continue:

IR::LabelInstr *const overflowLabel = Lowerer::InsertLabel(false, insertBeforeInstr);

// add temp, src, 1
IR::RegOpnd *const tempOpnd = IR::RegOpnd::New(StackSym::New(TyUint8, func), TyUint8, func);
const IR::AutoReuseOpnd autoReuseTempOpnd(tempOpnd, func);
Lowerer::InsertAdd(false, tempOpnd, src, IR::IntConstOpnd::New(1, TyUint8, func, true), overflowLabel);

// tst temp, 0xff
// beq $overflow
Lowerer::InsertTestBranch(
tempOpnd,
IR::IntConstOpnd::New(static_cast<uint8>(-1), TyUint8, func, true),
Js::OpCode::BrEq_A,
overflowLabel,
overflowLabel);

// mov dst, temp
Lowerer::InsertMove(dst, tempOpnd, overflowLabel);

const bool dstEqualsSrc = dst->IsEqual(src);
if(!dstEqualsSrc || onOverflowInsertBeforeInstrRef)
{
// b $continue
// $overflow:
// mov dst, static_cast<uint8>(-1)
// $continue:
IR::LabelInstr *const continueLabel = Lowerer::InsertLabel(false, insertBeforeInstr);
Lowerer::InsertBranch(Js::OpCode::Br, continueLabel, overflowLabel);
if(!dstEqualsSrc)
{
Lowerer::InsertMove(dst, IR::IntConstOpnd::New(static_cast<uint8>(-1), TyUint8, func, true), continueLabel);
}

if(onOverflowInsertBeforeInstrRef)
{
*onOverflowInsertBeforeInstrRef = continueLabel;
}
}
else
{
// $overflow:
}
}

void LowererMD::InsertDecUInt8PreventOverflow(
IR::Opnd *const dst,
IR::Opnd *const src,
IR::Instr *const insertBeforeInstr,
IR::Instr * *const onOverflowInsertBeforeInstrRef)
{
Assert(dst);
Assert(dst->GetType() == TyUint8);
Assert(src);
Assert(src->GetType() == TyUint8);
Assert(insertBeforeInstr);

Func *const func = insertBeforeInstr->m_func;

// Generate:
// subs temp, src, 1
// bcs $overflow
// mov dst, temp
// b $continue
// $overflow:
// mov dst, 0
// $continue:

IR::LabelInstr *const overflowLabel = Lowerer::InsertLabel(false, insertBeforeInstr);

// subs temp, src, 1
IR::RegOpnd *const tempOpnd = IR::RegOpnd::New(StackSym::New(TyUint8, func), TyUint8, func);
const IR::AutoReuseOpnd autoReuseTempOpnd(tempOpnd, func);
Lowerer::InsertSub(true, tempOpnd, src, IR::IntConstOpnd::New(1, TyUint8, func, true), overflowLabel);

// bcs $overflow
Lowerer::InsertBranch(Js::OpCode::BrLt_A, true, overflowLabel, overflowLabel);

// mov dst, temp
Lowerer::InsertMove(dst, tempOpnd, overflowLabel);

const bool dstEqualsSrc = dst->IsEqual(src);
if(!dstEqualsSrc || onOverflowInsertBeforeInstrRef)
{
// b $continue
// $overflow:
// mov dst, 0
// $continue:
IR::LabelInstr *const continueLabel = Lowerer::InsertLabel(false, insertBeforeInstr);
Lowerer::InsertBranch(Js::OpCode::Br, continueLabel, overflowLabel);
if(!dstEqualsSrc)
{
Lowerer::InsertMove(dst, IR::IntConstOpnd::New(0, TyUint8, func, true), continueLabel);
}

if(onOverflowInsertBeforeInstrRef)
{
*onOverflowInsertBeforeInstrRef = continueLabel;
}
}
else
{
// $overflow:
}
}

IR::Instr*
LowererMD::GeneratePreCall(IR::Instr * callInstr, IR::Opnd *functionObjOpnd)
{
Expand Down
4 changes: 0 additions & 4 deletions lib/Backend/arm/LowerMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,6 @@ class LowererMD

void LowerInlineSpreadArgOutLoop(IR::Instr *callInstr, IR::RegOpnd *indexOpnd, IR::RegOpnd *arrayElementsStartOpnd);

public:
static void InsertIncUInt8PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr);
static void InsertDecUInt8PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr);

private:
void GenerateFlagInlineCacheCheckForGetterSetter(
IR::Instr * insertBeforeInstr,
Expand Down
4 changes: 0 additions & 4 deletions lib/Backend/arm64/LowerMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,4 @@ class LowererMD
void ResetHelperArgsCount() { __debugbreak(); }

void LowerInlineSpreadArgOutLoop(IR::Instr *callInstr, IR::RegOpnd *indexOpnd, IR::RegOpnd *arrayElementsStartOpnd) { __debugbreak(); }

public:
static void InsertIncUInt8PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr) { __debugbreak(); }
static void InsertDecUInt8PreventOverflow(IR::Opnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, IR::Instr * *const onOverflowInsertBeforeInstrRef = nullptr) { __debugbreak(); }
};
Loading