From acc87d50fe7314ab0b536d1e1b99056b0764537f Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 2 Oct 2021 22:39:36 +0200 Subject: [PATCH] Limit inline expansion depth --- oscar64/InterCode.cpp | 13 +++++++++++++ oscar64/InterCodeGenerator.cpp | 4 +++- oscar64/InterCodeGenerator.h | 4 ++-- oscar64/NativeCodeGenerator.cpp | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index eb3e494..1a5f44a 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -2786,6 +2786,19 @@ void InterCodeBasicBlock::PerformMachineSpecificValueUsageCheck(const GrowingIns if (mTrueJump) mTrueJump->PerformMachineSpecificValueUsageCheck(ltvalue, tvalid); if (mFalseJump) mFalseJump->PerformMachineSpecificValueUsageCheck(ltvalue, tvalid); + + if (mInstructions.Size() > 0 && mInstructions[mInstructions.Size() - 1]->mCode == IC_BRANCH && mInstructions[mInstructions.Size() - 1]->mSTemp[0] < 0) + { + mInstructions[mInstructions.Size() - 1]->mCode = IC_JUMP; + if (!mInstructions[mInstructions.Size() - 1]->mSIntConst[0]) + { + mTrueJump->mNumEntries--; + mTrueJump = mFalseJump; + } + else + mFalseJump->mNumEntries--; + mFalseJump = nullptr; + } } } diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index c62acde..9e34d27 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -1531,7 +1531,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* return ExValue(TheVoidTypeDeclaration); } - else if (exp->mLeft->mType == EX_CONSTANT && exp->mLeft->mDecValue->mType == DT_CONST_FUNCTION && (exp->mLeft->mDecValue->mFlags & DTF_INLINE)) + else if (exp->mLeft->mType == EX_CONSTANT && exp->mLeft->mDecValue->mType == DT_CONST_FUNCTION && (exp->mLeft->mDecValue->mFlags & DTF_INLINE) && !(inlineMapper && inlineMapper->mDepth > 3)) { Declaration* fdec = exp->mLeft->mDecValue; Expression* fexp = fdec->mValue; @@ -1539,6 +1539,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* InlineMapper nmapper; nmapper.mReturn = new InterCodeBasicBlock(); + if (inlineMapper) + nmapper.mDepth = inlineMapper->mDepth + 1; proc->Append(nmapper.mReturn); Declaration* pdec = ftype->mParams; diff --git a/oscar64/InterCodeGenerator.h b/oscar64/InterCodeGenerator.h index ee29279..30d46a0 100644 --- a/oscar64/InterCodeGenerator.h +++ b/oscar64/InterCodeGenerator.h @@ -34,10 +34,10 @@ protected: { GrowingArray mParams; InterCodeBasicBlock * mReturn; - int mResult; + int mResult, mDepth; InlineMapper(void) - : mParams(-1), mResult(-1) + : mParams(-1), mResult(-1), mDepth(0) {} }; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 404db81..43f611f 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -5844,6 +5844,7 @@ void NativeCodeBasicBlock::CallAssembler(InterCodeProcedure* proc, const InterIn if (ins->mCode == IC_ASSEMBLER && mNoFrame) ins->mLinkerObject->mFlags |= LOBJF_NO_FRAME; + assert(ins->mLinkerObject); mIns.Push(NativeCodeInstruction(ASMIT_JSR, ASMIM_ABSOLUTE, ins->mSIntConst[0], ins->mLinkerObject)); if (ins->mTTemp >= 0)