Przeglądaj źródła

Code Quality: use legalizePostRegAlloc flag on Func instead of passing bool to Legalizers

ARM and ARM64 legalizers behave differently before and after register allocation. We've had bugs in the past where, mainly through static helper functions similar to Lowerer::InsertMove where we've had the flag wrong. This commit adds a flag on Func to tell the legalizer if it should behave as if register allocation has happened or not, and removes the need to pass the flags. The flag was not used on x86 and x64

There were a couple of places where the flag passed did not agree with whether register allocation has finished, in particular LinearScan::InsertLea (passed the flag true) and ARM and ARM64 LowererMD::ChangeToAssign (always passed false). I've added an RAII auto-restore helper to change the flag on the Func while those calls are in progress . While not ideal, it does have the benefit of being mroe expressive.

I'm using a new flag instead of the existing (dbg only) isPostRegAlloc flag because the flag can be temporarily overriden.
Matt Gardner 7 lat temu
rodzic
commit
aa4bc74d2a

+ 7 - 22
lib/Backend/Func.cpp

@@ -72,6 +72,7 @@ Func::Func(JitArenaAllocator *alloc, JITTimeWorkItem * workItem,
     hasInstrNumber(false),
     maintainByteCodeOffset(true),
     frameSize(0),
+    topFunc(parentFunc ? parentFunc->topFunc : this),
     parentFunc(parentFunc),
     argObjSyms(nullptr),
     m_nonTempLocalVars(nullptr),
@@ -109,6 +110,7 @@ Func::Func(JitArenaAllocator *alloc, JITTimeWorkItem * workItem,
     isTJLoopBody(false),
     m_nativeCodeDataSym(nullptr),
     isFlowGraphValid(false),
+    legalizePostRegAlloc(false),
 #if DBG
     m_callSiteCount(0),
 #endif
@@ -1314,6 +1316,11 @@ Func::EndPhase(Js::Phase tag, bool dump)
     }
 #endif
 
+    if (tag == Js::RegAllocPhase)
+    {
+        this->legalizePostRegAlloc = true;
+    }
+
 #if DBG
     if (tag == Js::LowererPhase)
     {
@@ -1352,28 +1359,6 @@ Func::EndPhase(Js::Phase tag, bool dump)
 #endif
 }
 
-Func const *
-Func::GetTopFunc() const
-{
-    Func const * func = this;
-    while (!func->IsTopFunc())
-    {
-        func = func->parentFunc;
-    }
-    return func;
-}
-
-Func *
-Func::GetTopFunc()
-{
-    Func * func = this;
-    while (!func->IsTopFunc())
-    {
-        func = func->parentFunc;
-    }
-    return func;
-}
-
 StackSym *
 Func::EnsureLoopParamSym()
 {

+ 26 - 2
lib/Backend/Func.h

@@ -364,8 +364,8 @@ static const unsigned __int64 c_debugFillPattern8 = 0xcececececececece;
     }
     void NumberInstrs();
     bool IsTopFunc() const { return this->parentFunc == nullptr; }
-    Func const * GetTopFunc() const;
-    Func * GetTopFunc();
+    Func const * GetTopFunc() const { return this->topFunc; }
+    Func * GetTopFunc() { return this->topFunc; }
 
     void SetFirstArgOffset(IR::Instr* inlineeStart);
 
@@ -732,6 +732,7 @@ public:
     bool                hasTempObjectProducingInstr:1; // At least one instruction which can produce temp object
     bool                isTJLoopBody : 1;
     bool                isFlowGraphValid : 1;
+    bool                legalizePostRegAlloc : 1;
 #if DBG
     bool                hasCalledSetDoFastPaths:1;
     bool                isPostLower:1;
@@ -836,6 +837,8 @@ public:
                         }
     }
 
+    bool                ShouldLegalizePostRegAlloc() const { return topFunc->legalizePostRegAlloc; }
+
     bool                GetApplyTargetInliningRemovedArgumentsAccess() const { return this->applyTargetInliningRemovedArgumentsAccess;}
     void                SetApplyTargetInliningRemovedArgumentsAccess() { this->applyTargetInliningRemovedArgumentsAccess = true;}
 
@@ -1024,6 +1027,7 @@ private:
 #ifdef PROFILE_EXEC
     Js::ScriptContextProfiler *const m_codeGenProfiler;
 #endif
+    Func * const        topFunc;
     Func * const        parentFunc;
     StackSym *          m_inlineeFrameStartSym;
     uint                maxInlineeArgOutSize;
@@ -1106,6 +1110,26 @@ private:
     bool dump;
     bool isPhaseComplete;
 };
+
+class AutoRestoreLegalize
+{
+public:
+    AutoRestoreLegalize(Func * func, bool val) : 
+        m_func(func->GetTopFunc()), 
+        m_originalValue(m_func->legalizePostRegAlloc)
+    {
+        m_func->legalizePostRegAlloc = val;
+    }
+
+    ~AutoRestoreLegalize()
+    {
+        m_func->legalizePostRegAlloc = m_originalValue;
+    }
+private:
+    Func * m_func;
+    bool m_originalValue;
+};
+
 #define BEGIN_CODEGEN_PHASE(func, phase) { AutoCodeGenPhase __autoCodeGen(func, phase);
 #define END_CODEGEN_PHASE(func, phase) __autoCodeGen.EndPhase(func, phase, true, true); }
 #define END_CODEGEN_PHASE_NO_DUMP(func, phase) __autoCodeGen.EndPhase(func, phase, false, true); }

+ 2 - 1
lib/Backend/LinearScan.cpp

@@ -4797,7 +4797,8 @@ IR::Instr* LinearScan::InsertLea(IR::RegOpnd *dst, IR::Opnd *src, IR::Instr *con
 {
     IR::Instr *instrPrev = insertBeforeInstr->m_prev;
 
-    IR::Instr *instrRet = Lowerer::InsertLea(dst, src, insertBeforeInstr, true);
+    AutoRestoreLegalize restore(insertBeforeInstr->m_func, true);
+    IR::Instr *instrRet = Lowerer::InsertLea(dst, src, insertBeforeInstr);
 
     for (IR::Instr *instr = instrPrev->m_next; instr != insertBeforeInstr; instr = instr->m_next)
     {

+ 7 - 7
lib/Backend/Lower.cpp

@@ -15376,7 +15376,7 @@ IR::Instr *Lowerer::InsertSub(
     return instr;
 }
 
-IR::Instr *Lowerer::InsertLea(IR::RegOpnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, bool postRegAlloc)
+IR::Instr *Lowerer::InsertLea(IR::RegOpnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr)
 {
     Assert(dst);
     Assert(src);
@@ -15388,11 +15388,11 @@ IR::Instr *Lowerer::InsertLea(IR::RegOpnd *const dst, IR::Opnd *const src, IR::I
     IR::Instr *const instr = IR::Instr::New(LowererMD::MDLea, dst, src, func);
 
     insertBeforeInstr->InsertBefore(instr);
-    return ChangeToLea(instr, postRegAlloc);
+    return ChangeToLea(instr);
 }
 
 IR::Instr *
-Lowerer::ChangeToLea(IR::Instr * instr, bool postRegAlloc)
+Lowerer::ChangeToLea(IR::Instr * instr)
 {
     Assert(instr);
     Assert(instr->GetDst());
@@ -15402,7 +15402,7 @@ Lowerer::ChangeToLea(IR::Instr * instr, bool postRegAlloc)
     Assert(!instr->GetSrc2());
 
     instr->m_opcode = LowererMD::MDLea;
-    LowererMD::Legalize(instr, postRegAlloc);
+    LowererMD::Legalize(instr);
     return instr;
 }
 
@@ -27185,7 +27185,7 @@ Lowerer::SetHasBailedOut(IR::Instr * bailoutInstr)
     IR::SymOpnd * hasBailedOutOpnd = IR::SymOpnd::New(this->m_func->m_hasBailedOutSym, TyUint32, this->m_func);
     IR::Instr * setInstr = IR::Instr::New(LowererMD::GetStoreOp(TyUint32), hasBailedOutOpnd, IR::IntConstOpnd::New(1, TyUint32, this->m_func), this->m_func);
     bailoutInstr->InsertBefore(setInstr);
-    LowererMD::Legalize(setInstr, true);
+    LowererMD::Legalize(setInstr);
 }
 
 IR::Instr*
@@ -27236,7 +27236,7 @@ Lowerer::EmitSaveEHBailoutReturnValueAndJumpToRetThunk(IR::Instr * insertAfterIn
     IR::RegOpnd *eaxOpnd = IR::RegOpnd::New(NULL, LowererMD::GetRegReturn(TyMachReg), TyMachReg, this->m_func);
     IR::Instr * movInstr = IR::Instr::New(LowererMD::GetStoreOp(TyVar), bailoutReturnValueSymOpnd, eaxOpnd, this->m_func);
     insertAfterInstr->InsertAfter(movInstr);
-    LowererMD::Legalize(movInstr, true);
+    LowererMD::Legalize(movInstr);
 
     IR::BranchInstr * jumpInstr = IR::BranchInstr::New(LowererMD::MDUncondBranchOpcode, this->currentRegion->GetBailoutReturnThunkLabel(), this->m_func);
     movInstr->InsertAfter(jumpInstr);
@@ -27258,7 +27258,7 @@ Lowerer::EmitRestoreReturnValueFromEHBailout(IR::LabelInstr * restoreLabel, IR::
 
     epilogLabel->InsertBefore(restoreLabel);
     epilogLabel->InsertBefore(movInstr);
-    LowererMD::Legalize(movInstr, true);
+    LowererMD::Legalize(movInstr);
     restoreLabel->InsertBefore(IR::BranchInstr::New(LowererMD::MDUncondBranchOpcode, epilogLabel, this->m_func));
 }
 

+ 2 - 2
lib/Backend/Lower.h

@@ -397,8 +397,8 @@ public:
     static IR::BranchInstr *    InsertTestBranch(IR::Opnd *const testSrc1, IR::Opnd *const testSrc2, const Js::OpCode branchOpCode, const bool isUnsigned, IR::LabelInstr *const target, IR::Instr *const insertBeforeInstr);
     static IR::Instr *          InsertAdd(const bool needFlags, IR::Opnd *const dst, IR::Opnd *src1, IR::Opnd *src2, IR::Instr *const insertBeforeInstr);
     static IR::Instr *          InsertSub(const bool needFlags, IR::Opnd *const dst, IR::Opnd *src1, IR::Opnd *src2, IR::Instr *const insertBeforeInstr);
-    static IR::Instr *          InsertLea(IR::RegOpnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr, bool postRegAlloc = false);
-    static IR::Instr *          ChangeToLea(IR::Instr *const instr, bool postRegAlloc = false);
+    static IR::Instr *          InsertLea(IR::RegOpnd *const dst, IR::Opnd *const src, IR::Instr *const insertBeforeInstr);
+    static IR::Instr *          ChangeToLea(IR::Instr *const instr);
     static IR::Instr *          InsertXor(IR::Opnd *const dst, IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
     static IR::Instr *          InsertAnd(IR::Opnd *const dst, IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);
     static IR::Instr *          InsertOr(IR::Opnd *const dst, IR::Opnd *const src1, IR::Opnd *const src2, IR::Instr *const insertBeforeInstr);

+ 2 - 2
lib/Backend/arm/EncoderMD.cpp

@@ -2401,7 +2401,7 @@ bool EncoderMD::TryConstFold(IR::Instr *instr, IR::RegOpnd *regOpnd)
         }
 
         instr->ReplaceSrc(regOpnd, regOpnd->m_sym->GetConstOpnd());
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
 
         return true;
     }
@@ -2421,7 +2421,7 @@ bool EncoderMD::TryFold(IR::Instr *instr, IR::RegOpnd *regOpnd)
         }
         IR::SymOpnd *symOpnd = IR::SymOpnd::New(regOpnd->m_sym, regOpnd->GetType(), instr->m_func);
         instr->ReplaceSrc(regOpnd, symOpnd);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
 
         return true;
     }

+ 62 - 72
lib/Backend/arm/LegalizeMD.cpp

@@ -26,7 +26,12 @@ static LegalForms LegalSrcForms(IR::Instr * instr, uint opndNum)
     return _InstrForms[instr->m_opcode - (Js::OpCode::MDStart+1)].src[opndNum-1];
 }
 
-void LegalizeMD::LegalizeInstr(IR::Instr * instr, bool fPostRegAlloc)
+RegNum LegalizeMD::GetScratchReg(IR::Instr * instr)
+{
+    return instr->m_func->ShouldLegalizePostRegAlloc() ? SCRATCH_REG : RegNOREG;
+}
+
+void LegalizeMD::LegalizeInstr(IR::Instr * instr)
 {
     if (!instr->IsLowered())
     {
@@ -34,12 +39,12 @@ void LegalizeMD::LegalizeInstr(IR::Instr * instr, bool fPostRegAlloc)
         return;
     }
 
-    LegalizeDst(instr, fPostRegAlloc);
-    LegalizeSrc(instr, instr->GetSrc1(), 1, fPostRegAlloc);
-    LegalizeSrc(instr, instr->GetSrc2(), 2, fPostRegAlloc);
+    LegalizeDst(instr);
+    LegalizeSrc(instr, instr->GetSrc1(), 1);
+    LegalizeSrc(instr, instr->GetSrc2(), 2);
 }
 
-void LegalizeMD::LegalizeDst(IR::Instr * instr, bool fPostRegAlloc)
+void LegalizeMD::LegalizeDst(IR::Instr * instr)
 {
     LegalForms forms = LegalDstForms(instr);
 
@@ -74,15 +79,11 @@ void LegalizeMD::LegalizeDst(IR::Instr * instr, bool fPostRegAlloc)
         // So extract the location, load it to register, replace the MemRefOpnd with an IndirOpnd taking the
         // register as base, and fall through to legalize the IndirOpnd.
         intptr_t memLoc = opnd->AsMemRefOpnd()->GetMemLoc();
-        IR::RegOpnd *newReg = IR::RegOpnd::New(TyMachPtr, instr->m_func);
-        if (fPostRegAlloc)
-        {
-            newReg->SetReg(SCRATCH_REG);
-        }
+        IR::RegOpnd *newReg = IR::RegOpnd::New(GetScratchReg(instr), TyMachPtr, instr->m_func);
         IR::Instr *newInstr = IR::Instr::New(Js::OpCode::LDIMM, newReg,
             IR::AddrOpnd::New(memLoc, opnd->AsMemRefOpnd()->GetAddrKind(), instr->m_func, true), instr->m_func);
         instr->InsertBefore(newInstr);
-        LegalizeMD::LegalizeInstr(newInstr, fPostRegAlloc);
+        LegalizeMD::LegalizeInstr(newInstr);
         IR::IndirOpnd *indirOpnd = IR::IndirOpnd::New(newReg, 0, opnd->GetType(), instr->m_func);
         opnd = instr->ReplaceDst(indirOpnd);
     }
@@ -90,24 +91,24 @@ void LegalizeMD::LegalizeDst(IR::Instr * instr, bool fPostRegAlloc)
     case IR::OpndKindIndir:
         if (!(forms & L_IndirMask))
         {
-            instr = LegalizeStore(instr, forms, fPostRegAlloc);
+            instr = LegalizeStore(instr, forms);
             forms = LegalDstForms(instr);
         }
-        LegalizeIndirOffset(instr, opnd->AsIndirOpnd(), forms, fPostRegAlloc);
+        LegalizeIndirOffset(instr, opnd->AsIndirOpnd(), forms);
         break;
 
     case IR::OpndKindSym:
         if (!(forms & L_SymMask))
         {
-            instr = LegalizeStore(instr, forms, fPostRegAlloc);
+            instr = LegalizeStore(instr, forms);
             forms = LegalDstForms(instr);
         }
 
-        if (fPostRegAlloc)
+        if (instr->m_func->ShouldLegalizePostRegAlloc())
         {
             // In order to legalize SymOffset we need to know final argument area, which is only available after lowerer.
             // So, don't legalize sym offset here, but it will be done as part of register allocator.
-            LegalizeSymOffset(instr, opnd->AsSymOpnd(), forms, fPostRegAlloc);
+            LegalizeSymOffset(instr, opnd->AsSymOpnd(), forms);
         }
         break;
 
@@ -117,7 +118,7 @@ void LegalizeMD::LegalizeDst(IR::Instr * instr, bool fPostRegAlloc)
     }
 }
 
-IR::Instr * LegalizeMD::LegalizeStore(IR::Instr *instr, LegalForms forms, bool fPostRegAlloc)
+IR::Instr * LegalizeMD::LegalizeStore(IR::Instr *instr, LegalForms forms)
 {
     if (LowererMD::IsAssign(instr) && instr->GetSrc1()->IsRegOpnd())
     {
@@ -129,14 +130,14 @@ IR::Instr * LegalizeMD::LegalizeStore(IR::Instr *instr, LegalForms forms, bool f
         // Sink the mem opnd. The caller will verify the offset.
         // We don't expect to hit this point after register allocation, because we
         // can't guarantee that the instruction will be legal.
-        Assert(!fPostRegAlloc);
+        Assert(!instr->m_func->ShouldLegalizePostRegAlloc());
         instr = instr->SinkDst(LowererMD::GetStoreOp(instr->GetDst()->GetType()), RegNOREG);
     }
 
     return instr;
 }
 
-void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, bool fPostRegAlloc)
+void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum)
 {
     LegalForms forms = LegalSrcForms(instr, opndNum);
     if (opnd == NULL)
@@ -166,11 +167,11 @@ void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, b
     case IR::OpndKindAddr:
     case IR::OpndKindHelperCall:
     case IR::OpndKindIntConst:
-        LegalizeImmed(instr, opnd, opndNum, opnd->GetImmediateValueAsInt32(instr->m_func), forms, fPostRegAlloc);
+        LegalizeImmed(instr, opnd, opndNum, opnd->GetImmediateValueAsInt32(instr->m_func), forms);
         break;
 
     case IR::OpndKindLabel:
-        LegalizeLabelOpnd(instr, opnd, opndNum, fPostRegAlloc);
+        LegalizeLabelOpnd(instr, opnd, opndNum);
         break;
 
     case IR::OpndKindMemRef:
@@ -179,14 +180,10 @@ void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, b
         // So extract the location, load it to register, replace the MemRefOpnd with an IndirOpnd taking the
         // register as base, and fall through to legalize the IndirOpnd.
         intptr_t memLoc = opnd->AsMemRefOpnd()->GetMemLoc();
-        IR::RegOpnd *newReg = IR::RegOpnd::New(TyMachPtr, instr->m_func);
-        if (fPostRegAlloc)
-        {
-            newReg->SetReg(SCRATCH_REG);
-        }
+        IR::RegOpnd *newReg = IR::RegOpnd::New(GetScratchReg(instr), TyMachPtr, instr->m_func);
         IR::Instr *newInstr = IR::Instr::New(Js::OpCode::LDIMM, newReg, IR::AddrOpnd::New(memLoc, IR::AddrOpndKindDynamicMisc, instr->m_func), instr->m_func);
         instr->InsertBefore(newInstr);
-        LegalizeMD::LegalizeInstr(newInstr, fPostRegAlloc);
+        LegalizeMD::LegalizeInstr(newInstr);
         IR::IndirOpnd *indirOpnd = IR::IndirOpnd::New(newReg, 0, opnd->GetType(), instr->m_func);
         if (opndNum == 1)
         {
@@ -201,24 +198,24 @@ void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, b
     case IR::OpndKindIndir:
         if (!(forms & L_IndirMask))
         {
-            instr = LegalizeLoad(instr, opndNum, forms, fPostRegAlloc);
+            instr = LegalizeLoad(instr, opndNum, forms);
             forms = LegalSrcForms(instr, 1);
         }
-        LegalizeIndirOffset(instr, opnd->AsIndirOpnd(), forms, fPostRegAlloc);
+        LegalizeIndirOffset(instr, opnd->AsIndirOpnd(), forms);
         break;
 
     case IR::OpndKindSym:
         if (!(forms & L_SymMask))
         {
-            instr = LegalizeLoad(instr, opndNum, forms, fPostRegAlloc);
+            instr = LegalizeLoad(instr, opndNum, forms);
             forms = LegalSrcForms(instr, 1);
         }
 
-        if (fPostRegAlloc)
+        if (instr->m_func->ShouldLegalizePostRegAlloc())
         {
             // In order to legalize SymOffset we need to know final argument area, which is only available after lowerer.
             // So, don't legalize sym offset here, but it will be done as part of register allocator.
-            LegalizeSymOffset(instr, opnd->AsSymOpnd(), forms, fPostRegAlloc);
+            LegalizeSymOffset(instr, opnd->AsSymOpnd(), forms);
         }
         break;
 
@@ -228,7 +225,7 @@ void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, b
     }
 }
 
-IR::Instr * LegalizeMD::LegalizeLoad(IR::Instr *instr, uint opndNum, LegalForms forms, bool fPostRegAlloc)
+IR::Instr * LegalizeMD::LegalizeLoad(IR::Instr *instr, uint opndNum, LegalForms forms)
 {
     if (LowererMD::IsAssign(instr) && instr->GetDst()->IsRegOpnd())
     {
@@ -240,25 +237,25 @@ IR::Instr * LegalizeMD::LegalizeLoad(IR::Instr *instr, uint opndNum, LegalForms
         // Hoist the memory opnd. The caller will verify the offset.
         if (opndNum == 1)
         {
-            AssertMsg(!fPostRegAlloc || instr->GetSrc1()->GetType() == TyMachReg, "Post RegAlloc other types disallowed");
-            instr = instr->HoistSrc1(LowererMD::GetLoadOp(instr->GetSrc1()->GetType()), fPostRegAlloc ? SCRATCH_REG : RegNOREG);
+            AssertMsg(!instr->m_func->ShouldLegalizePostRegAlloc() || instr->GetSrc1()->GetType() == TyMachReg, "Post RegAlloc other types disallowed");
+            instr = instr->HoistSrc1(LowererMD::GetLoadOp(instr->GetSrc1()->GetType()), GetScratchReg(instr));
         }
         else
         {
-            AssertMsg(!fPostRegAlloc || instr->GetSrc2()->GetType() == TyMachReg, "Post RegAlloc other types disallowed");
-            instr = instr->HoistSrc2(LowererMD::GetLoadOp(instr->GetSrc2()->GetType()), fPostRegAlloc ? SCRATCH_REG : RegNOREG);
+            AssertMsg(!instr->m_func->ShouldLegalizePostRegAlloc() || instr->GetSrc2()->GetType() == TyMachReg, "Post RegAlloc other types disallowed");
+            instr = instr->HoistSrc2(LowererMD::GetLoadOp(instr->GetSrc2()->GetType()), GetScratchReg(instr));
         }
     }
 
     return instr;
 }
 
-void LegalizeMD::LegalizeIndirOffset(IR::Instr * instr, IR::IndirOpnd * indirOpnd, LegalForms forms, bool fPostRegAlloc)
+void LegalizeMD::LegalizeIndirOffset(IR::Instr * instr, IR::IndirOpnd * indirOpnd, LegalForms forms)
 {
     if (forms & (L_VIndirI11))
     {
         // Vfp doesn't support register indirect operation
-        LegalizeMD::LegalizeIndirOpndForVFP(instr, indirOpnd, fPostRegAlloc);
+        LegalizeMD::LegalizeIndirOpndForVFP(instr, indirOpnd);
         return;
     }
 
@@ -266,8 +263,8 @@ void LegalizeMD::LegalizeIndirOffset(IR::Instr * instr, IR::IndirOpnd * indirOpn
 
     if (indirOpnd->GetIndexOpnd() != NULL && offset != 0)
     {
-        IR::Instr *addInstr = Lowerer::HoistIndirOffset(instr, indirOpnd, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
-        LegalizeMD::LegalizeInstr(addInstr, fPostRegAlloc);
+        IR::Instr *addInstr = Lowerer::HoistIndirOffset(instr, indirOpnd, GetScratchReg(instr));
+        LegalizeMD::LegalizeInstr(addInstr);
         return;
     }
 
@@ -288,17 +285,13 @@ void LegalizeMD::LegalizeIndirOffset(IR::Instr * instr, IR::IndirOpnd * indirOpn
     }
 
     // Offset is too large, so hoist it and replace it with an index, only valid for Thumb & Thumb2
-    IR::Instr *addInstr = Lowerer::HoistIndirOffset(instr, indirOpnd, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
-    LegalizeMD::LegalizeInstr(addInstr, fPostRegAlloc);
+    IR::Instr *addInstr = Lowerer::HoistIndirOffset(instr, indirOpnd, GetScratchReg(instr));
+    LegalizeMD::LegalizeInstr(addInstr);
 }
 
-void LegalizeMD::LegalizeSymOffset(
-    IR::Instr * instr,
-    IR::SymOpnd * symOpnd,
-    LegalForms forms,
-    bool fPostRegAlloc)
+void LegalizeMD::LegalizeSymOffset(IR::Instr * instr, IR::SymOpnd * symOpnd, LegalForms forms)
 {
-    AssertMsg(fPostRegAlloc, "LegalizeMD::LegalizeSymOffset can (and will) be called as part of register allocation. Can't call it as part of lowerer, as final argument area is not available yet.");
+    AssertMsg(instr->m_func->ShouldLegalizePostRegAlloc(), "LegalizeMD::LegalizeSymOffset can (and will) be called as part of register allocation. Can't call it as part of lowerer, as final argument area is not available yet.");
 
     RegNum baseReg;
     int32 offset;
@@ -334,8 +327,8 @@ void LegalizeMD::LegalizeSymOffset(
         }
 
         IR::RegOpnd *baseOpnd = IR::RegOpnd::New(NULL, baseReg, TyMachPtr, instr->m_func);
-        IR::Instr* instrAdd = Lowerer::HoistSymOffsetAsAdd(instr, symOpnd, baseOpnd, offset, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
-        LegalizeMD::LegalizeInstr(instrAdd, fPostRegAlloc);
+        IR::Instr* instrAdd = Lowerer::HoistSymOffsetAsAdd(instr, symOpnd, baseOpnd, offset, GetScratchReg(instr));
+        LegalizeMD::LegalizeInstr(instrAdd);
         return;
     }
 
@@ -345,14 +338,14 @@ void LegalizeMD::LegalizeSymOffset(
         instr->m_opcode = Js::OpCode::ADD;
         instr->ReplaceSrc1(IR::RegOpnd::New(NULL, baseReg, TyMachPtr, instr->m_func));
         instr->SetSrc2(IR::IntConstOpnd::New(offset, TyMachReg, instr->m_func));
-        newInstr = instr->HoistSrc2(Js::OpCode::LDIMM, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
-        LegalizeMD::LegalizeInstr(newInstr, fPostRegAlloc);
-        LegalizeMD::LegalizeInstr(instr, fPostRegAlloc);
+        newInstr = instr->HoistSrc2(Js::OpCode::LDIMM, GetScratchReg(instr));
+        LegalizeMD::LegalizeInstr(newInstr);
+        LegalizeMD::LegalizeInstr(instr);
     }
     else
     {
-        newInstr = Lowerer::HoistSymOffset(instr, symOpnd, baseReg, offset, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
-        LegalizeMD::LegalizeInstr(newInstr, fPostRegAlloc);
+        newInstr = Lowerer::HoistSymOffset(instr, symOpnd, baseReg, offset, GetScratchReg(instr));
+        LegalizeMD::LegalizeInstr(newInstr);
     }
 }
 
@@ -361,8 +354,7 @@ void LegalizeMD::LegalizeImmed(
     IR::Opnd * opnd,
     uint opndNum,
     IntConstType immed,
-    LegalForms forms,
-    bool fPostRegAlloc)
+    LegalForms forms)
 {
     if (!(((forms & L_ImmModC12) && EncoderMD::CanEncodeModConst12(immed)) ||
           ((forms & L_ImmU5) && IS_CONST_UINT5(immed)) ||
@@ -371,27 +363,24 @@ void LegalizeMD::LegalizeImmed(
     {
         if (instr->m_opcode != Js::OpCode::LDIMM)
         {
-            instr = LegalizeMD::GenerateLDIMM(instr, opndNum, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
+            instr = LegalizeMD::GenerateLDIMM(instr, opndNum, GetScratchReg(instr));
         }
 
-        if (fPostRegAlloc)
+        if (instr->m_func->ShouldLegalizePostRegAlloc())
         {
             LegalizeMD::LegalizeLDIMM(instr, immed);
         }
     }
 }
 
-void LegalizeMD::LegalizeLabelOpnd(
-    IR::Instr * instr,
-    IR::Opnd * opnd,
-    uint opndNum,
-    bool fPostRegAlloc)
+void LegalizeMD::LegalizeLabelOpnd(IR::Instr * instr, IR::Opnd * opnd, uint opndNum)
 {
     if (instr->m_opcode != Js::OpCode::LDIMM)
     {
-        instr = LegalizeMD::GenerateLDIMM(instr, opndNum, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
+        instr = LegalizeMD::GenerateLDIMM(instr, opndNum, GetScratchReg(instr));
     }
-    if (fPostRegAlloc)
+
+    if (instr->m_func->ShouldLegalizePostRegAlloc())
     {
         LegalizeMD::LegalizeLdLabel(instr, opnd);
     }
@@ -428,6 +417,7 @@ void LegalizeMD::LegalizeLDIMM(IR::Instr * instr, IntConstType immed)
             instr->m_opcode = Js::OpCode::MOV;
             return;
         }
+
         bool fDontEncode = Security::DontEncode(instr->GetSrc1());
 
         IR::IntConstOpnd *src1 = IR::IntConstOpnd::New(immed & 0x0000FFFF, TyInt16, instr->m_func);
@@ -596,7 +586,7 @@ bool LegalizeMD::LegalizeDirectBranch(IR::BranchInstr *branchInstr, uint32 branc
     return true;
 }
 
-void LegalizeMD::LegalizeIndirOpndForVFP(IR::Instr* insertInstr, IR::IndirOpnd *indirOpnd, bool fPostRegAlloc)
+void LegalizeMD::LegalizeIndirOpndForVFP(IR::Instr* insertInstr, IR::IndirOpnd *indirOpnd)
 {
     IR::RegOpnd *baseOpnd = indirOpnd->GetBaseOpnd();
     int32 offset = indirOpnd->GetOffset();
@@ -621,16 +611,16 @@ void LegalizeMD::LegalizeIndirOpndForVFP(IR::Instr* insertInstr, IR::IndirOpnd *
             indexOpnd = newIndexOpnd;
         }
 
-        IR::Instr * instrAdd = Lowerer::HoistIndirIndexOpndAsAdd(insertInstr, indirOpnd, baseOpnd, indexOpnd, fPostRegAlloc? SCRATCH_REG : RegNOREG);
-        LegalizeMD::LegalizeInstr(instrAdd, fPostRegAlloc);
+        IR::Instr * instrAdd = Lowerer::HoistIndirIndexOpndAsAdd(insertInstr, indirOpnd, baseOpnd, indexOpnd, GetScratchReg(insertInstr));
+        LegalizeMD::LegalizeInstr(instrAdd);
     }
 
     if (IS_CONST_UINT10((offset < 0? -offset: offset)))
     {
         return;
     }
-    IR::Instr* instrAdd = Lowerer::HoistIndirOffsetAsAdd(insertInstr, indirOpnd, indirOpnd->GetBaseOpnd(), offset, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
-    LegalizeMD::LegalizeInstr(instrAdd, fPostRegAlloc);
+    IR::Instr* instrAdd = Lowerer::HoistIndirOffsetAsAdd(insertInstr, indirOpnd, indirOpnd->GetBaseOpnd(), offset, GetScratchReg(insertInstr));
+    LegalizeMD::LegalizeInstr(instrAdd);
 }
 
 

+ 12 - 10
lib/Backend/arm/LegalizeMD.h

@@ -70,21 +70,23 @@ struct LegalInstrForms
 class LegalizeMD
 {
 public:
-    static void LegalizeInstr(IR::Instr * instr, bool fPostRegAlloc);
-    static void LegalizeDst(IR::Instr * instr, bool fPostRegAlloc);
-    static void LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, bool fPostRegAlloc);
+    static void LegalizeInstr(IR::Instr * instr);
+    static void LegalizeDst(IR::Instr * instr);
+    static void LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum);
 
     static bool LegalizeDirectBranch(IR::BranchInstr *instr, uint32 branchOffset); // DirectBranch has no src & dst operands.
     //Returns IndexOpnd which is removed from VFP indirect operand
-    static void LegalizeIndirOpndForVFP(IR::Instr* insertInstr, IR::IndirOpnd *indirOpnd, bool fPostRegAlloc);
+    static void LegalizeIndirOpndForVFP(IR::Instr* insertInstr, IR::IndirOpnd *indirOpnd);
 
 private:
-    static IR::Instr *LegalizeStore(IR::Instr *instr, LegalForms forms, bool fPostRegAlloc);
-    static IR::Instr *LegalizeLoad(IR::Instr *instr, uint opndNum, LegalForms forms, bool fPostRegAlloc);
-    static void LegalizeIndirOffset(IR::Instr * instr, IR::IndirOpnd * indirOpnd, LegalForms forms, bool fPostRegAlloc);
-    static void LegalizeSymOffset(IR::Instr * instr, IR::SymOpnd * indirOpnd, LegalForms forms, bool fPostRegAlloc);
-    static void LegalizeImmed(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, IntConstType immed, LegalForms forms, bool fPostRegAlloc);
-    static void LegalizeLabelOpnd(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, bool fPostRegAlloc);
+    static RegNum GetScratchReg(IR::Instr * instr);
+
+    static IR::Instr *LegalizeStore(IR::Instr *instr, LegalForms forms);
+    static IR::Instr *LegalizeLoad(IR::Instr *instr, uint opndNum, LegalForms forms);
+    static void LegalizeIndirOffset(IR::Instr * instr, IR::IndirOpnd * indirOpnd, LegalForms forms);
+    static void LegalizeSymOffset(IR::Instr * instr, IR::SymOpnd * indirOpnd, LegalForms forms);
+    static void LegalizeImmed(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, IntConstType immed, LegalForms forms);
+    static void LegalizeLabelOpnd(IR::Instr * instr, IR::Opnd * opnd, uint opndNum);
 
     static void LegalizeLDIMM(IR::Instr * instr, IntConstType immed);
     static void LegalizeLdLabel(IR::Instr * instr, IR::Opnd * opnd);

+ 3 - 3
lib/Backend/arm/LinearScanMD.cpp

@@ -183,7 +183,7 @@ LinearScanMD::LegalizeDef(IR::Instr * instr)
 
     // Legalize opcodes, etc., but do not expand symbol/indirs with large offsets
     // because we can't safely do this until all loads and stores are in place.
-    LegalizeMD::LegalizeDst(instr, false);
+    LegalizeMD::LegalizeDst(instr);
 }
 
 void
@@ -201,11 +201,11 @@ LinearScanMD::LegalizeUse(IR::Instr * instr, IR::Opnd * opnd)
     // because we can't safely do this until all loads and stores are in place.
     if (opnd == instr->GetSrc1())
     {
-        LegalizeMD::LegalizeSrc(instr, opnd, 1, false);
+        LegalizeMD::LegalizeSrc(instr, opnd, 1);
     }
     else
     {
-        LegalizeMD::LegalizeSrc(instr, opnd, 2, false);
+        LegalizeMD::LegalizeSrc(instr, opnd, 2);
     }
 }
 

+ 70 - 68
lib/Backend/arm/LowerMD.cpp

@@ -363,7 +363,7 @@ LowererMD::LoadDynamicArgument(IR::Instr *instr, uint argNumber)
     IR::Opnd* dst = GetOpndForArgSlot((Js::ArgSlot) (argNumber - 1));
     instr->SetDst(dst);
     instr->m_opcode = Js::OpCode::MOV;
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     return instr;
 }
@@ -381,7 +381,7 @@ LowererMD::LoadDynamicArgumentUsingLength(IR::Instr *instr)
     IR::IndirOpnd *actualsLocation = IR::IndirOpnd::New(stackPointer, add->GetDst()->AsRegOpnd(), GetDefaultIndirScale(), TyMachReg, this->m_func);
     instr->SetDst(actualsLocation);
     instr->m_opcode = Js::OpCode::LDR;
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     return instr;
 }
@@ -980,7 +980,7 @@ LowererMD::GenerateStackDeallocation(IR::Instr *instr, uint32 allocSize)
         spOpnd,
         IR::IntConstOpnd::New(allocSize, TyMachReg, this->m_func, true), this->m_func);
     instr->InsertBefore(spAdjustInstr);
-    LegalizeMD::LegalizeInstr(spAdjustInstr, true);
+    LegalizeMD::LegalizeInstr(spAdjustInstr);
 }
 
 //------------------------------------------------------------------------------------------
@@ -2308,7 +2308,9 @@ LowererMD::ChangeToAssign(IR::Instr * instr, IRType type)
     {
         instr->m_opcode = LowererMD::GetMoveOp(type);
     }
-    LegalizeMD::LegalizeInstr(instr, false);
+
+    AutoRestoreLegalize restore(instr->m_func, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     return instr;
 }
@@ -2620,7 +2622,7 @@ LowererMD::LowerCondBranch(IR::Instr * instr)
                 instrPrev->SetSrc1(opndSrc1);
                 instrPrev->SetSrc2(opndSrc2);
                 instr->InsertBefore(instrPrev);
-                LegalizeMD::LegalizeInstr(instrPrev, false);
+                LegalizeMD::LegalizeInstr(instrPrev);
 
                 //Transfer the result to ARM status register control register.
                 instrPrev = IR::Instr::New(Js::OpCode::VMRS, this->m_func);
@@ -2637,7 +2639,7 @@ LowererMD::LowerCondBranch(IR::Instr * instr)
                 instrPrev->SetSrc2(opndSrc2);
                 instr->InsertBefore(instrPrev);
 
-                LegalizeMD::LegalizeInstr(instrPrev, false);
+                LegalizeMD::LegalizeInstr(instrPrev);
 
                 instr->m_opcode = MDBranchOpcode(instr->m_opcode);
             }
@@ -2746,7 +2748,7 @@ LowererMD::GenerateFastDivByPow2(IR::Instr *instrDiv)
     //// s1 =  AND  src1, 0x80000001 | ((src2Value - 1) << 1)
     //instr = IR::Instr::New(Js::OpCode::AND, s1, src1, IR::IntConstOpnd::New((0x80000001 | ((src2Value - 1) << 1)), TyInt32, m_func), m_func);
     //instrDiv->InsertBefore(instr);
-    //LegalizeMD::LegalizeInstr(instr, false);
+    //LegalizeMD::LegalizeInstr(instr);
 
     ////       CMP s1, 1
     //instr = IR::Instr::New(Js::OpCode::CMP, m_func);
@@ -2761,12 +2763,12 @@ LowererMD::GenerateFastDivByPow2(IR::Instr *instrDiv)
     //// s1  = ASR  src1, log2(src2Value)  -- do the equal divide
     //instr = IR::Instr::New(Js::OpCode::ASR, s1, src1, IR::IntConstOpnd::New(Math::Log2(src2Value), TyInt32, m_func), m_func);
     //instrDiv->InsertBefore(instr);
-    //LegalizeMD::LegalizeInstr(instr, false);
+    //LegalizeMD::LegalizeInstr(instr);
 
     //// dst = ORR   s1, 1                 -- restore tagged int bit
     //instr = IR::Instr::New(Js::OpCode::ORR, dst, s1, IR::IntConstOpnd::New(1, TyInt32, m_func), m_func);
     //instrDiv->InsertBefore(instr);
-    //LegalizeMD::LegalizeInstr(instr, false);
+    //LegalizeMD::LegalizeInstr(instr);
     //
     ////       B  $done
     //instr = IR::BranchInstr::New(Js::OpCode::B, done, m_func);
@@ -2791,7 +2793,7 @@ LowererMD::GenerateFastDivByPow2(IR::Instr *instrDiv)
     //// s1 =  ASR  src1, log2(src2Value) + 1 -- do the integer divide and also shift out the tagged int bit
     //instr = IR::Instr::New(Js::OpCode::ASR, s1, src1, IR::IntConstOpnd::New(Math::Log2(src2Value) + 1, TyInt32, m_func), m_func);
     //instrDiv->InsertBefore(instr);
-    //LegalizeMD::LegalizeInstr(instr, false);
+    //LegalizeMD::LegalizeInstr(instr);
 
     //// Arg2: scriptContext
     //IR::JnHelperMethod helperMethod;
@@ -2803,7 +2805,7 @@ LowererMD::GenerateFastDivByPow2(IR::Instr *instrDiv)
     //    StackSym * tempNumberSym = this->m_lowerer->GetTempNumberSym(dst, instr->dstIsTempNumberTransferred);
 
     //    instr = this->m_lowerer->InsertLoadStackAddress(tempNumberSym, instrDiv);
-    //    LegalizeMD::LegalizeInstr(instr, false);
+    //    LegalizeMD::LegalizeInstr(instr);
 
     //    this->LoadHelperArgument(instrDiv, instr->GetDst());
     //}
@@ -3021,7 +3023,7 @@ bool LowererMD::GenerateFastCmXxTaggedInt(IR::Instr *instr, bool isInHelper  /*
     instrCmp->SetSrc1(src1);
     instrCmp->SetSrc2(src2);
     instr->InsertBefore(instrCmp);
-    LegalizeMD::LegalizeInstr(instrCmp,false);
+    LegalizeMD::LegalizeInstr(instrCmp);
 
     instr->InsertBefore(IR::BranchInstr::New(opcode, fallthru, m_func));
     instr->InsertBefore(IR::Instr::New(Js::OpCode::LDIMM, dst, opndFalse, m_func));
@@ -3064,7 +3066,7 @@ IR::Instr * LowererMD::GenerateConvBool(IR::Instr *instr)
     instrTst->SetSrc1(src1);
     instrTst->SetSrc2(src1);
     instr->InsertBefore(instrTst);
-    LegalizeMD::LegalizeInstr(instrTst, false);
+    LegalizeMD::LegalizeInstr(instrTst);
 
     // BNE fallthrough
     instr->InsertBefore(IR::BranchInstr::New(Js::OpCode::BNE, fallthru, m_func));
@@ -3270,7 +3272,7 @@ LowererMD::GenerateFastSub(IR::Instr * instrSub)
     // dst = ADD s1, 1        -- restore the var tag on the result
     instr = IR::Instr::New(Js::OpCode::ADD, instrSub->GetDst(), opndReg, IR::IntConstOpnd::New(1, TyMachReg, this->m_func), this->m_func);
     instrSub->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     //      B $fallthru
     labelFallThru = IR::LabelInstr::New(Js::OpCode::Label, this->m_func);
@@ -3426,7 +3428,7 @@ LowererMD::GenerateFastMul(IR::Instr * instrMul)
     // dst= ORR s1, AtomTag   -- make sure var tag is set on the result
     instr = IR::Instr::New(Js::OpCode::ORR, instrMul->GetDst(), opndReg1, IR::IntConstOpnd::New(Js::AtomTag, TyVar, this->m_func), this->m_func);
     instrMul->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     //      B $fallthru
     instr = IR::BranchInstr::New(Js::OpCode::B, labelFallThru, this->m_func);
@@ -3506,7 +3508,7 @@ LowererMD::GenerateFastAnd(IR::Instr * instrAnd)
     // dstReg = AND src1, src2
     instr = IR::Instr::New(Js::OpCode::AND, dst, src1, src2, this->m_func);
     instrAnd->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     if (isInt)
     {
@@ -3620,7 +3622,7 @@ LowererMD::GenerateFastOr(IR::Instr * instrOr)
     // dst = OR src1, src2
     instr = IR::Instr::New(Js::OpCode::ORR, dst, src1, src2, this->m_func);
     instrOr->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     if (isInt)
     {
@@ -4447,7 +4449,7 @@ LowererMD::GenerateStFldFromLocalInlineCache(
         opndIndir = IR::IndirOpnd::New(opndBase, opndSlotIndex, LowererMD::GetDefaultIndirScale(), TyMachReg, instrStFld->m_func);
         instr = IR::Instr::New(Js::OpCode::STR, opndIndir, opndSrc, instrStFld->m_func);
         instrStFld->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
     }
     else
     {
@@ -4455,7 +4457,7 @@ LowererMD::GenerateStFldFromLocalInlineCache(
         opndIndir = IR::IndirOpnd::New(opndSlotArray, opndSlotIndex, LowererMD::GetDefaultIndirScale(), TyMachReg, instrStFld->m_func);
         instr = IR::Instr::New(Js::OpCode::STR, opndIndir, opndSrc, instrStFld->m_func);
         instrStFld->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
     }
 
     // B $done
@@ -4529,7 +4531,7 @@ LowererMD::GenerateUntagVar(IR::RegOpnd * opnd, IR::LabelInstr * instrFail, IR::
     IR::Instr *instr = IR::Instr::New(Js::OpCode::ASRS, int32Opnd, opnd,
         IR::IntConstOpnd::New(Js::VarTag_Shift, TyInt8, this->m_func), this->m_func);
     insertBeforeInstr->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     // No need to check if we already know that it is a tagged int.
     if (generateTagCheck)
@@ -4749,7 +4751,7 @@ bool LowererMD::TryGenerateFastMulAdd(IR::Instr * instrAdd, IR::Instr ** pInstrP
         //       BCC  $helper        -- if not tagged int, jmp to $helper
         instr = IR::Instr::New(Js::OpCode::ASRS, s2, mulSrc2, IR::IntConstOpnd::New(Js::VarTag_Shift, TyVar, this->m_func), m_func);
         instrAdd->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
         if (!mulSrc2->IsTaggedInt())    // If we already pre-know it's tagged int, no need to check.
         {
             instr = IR::BranchInstr::New(Js::OpCode::BCC, labelHelper, this->m_func);
@@ -4780,7 +4782,7 @@ bool LowererMD::TryGenerateFastMulAdd(IR::Instr * instrAdd, IR::Instr ** pInstrP
         // Copy the result into dst
         // dst = s3
         Lowerer::InsertMove(instrAdd->GetDst(), s3, instrAdd);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
 
         //       B $done
         instr = IR::BranchInstr::New(Js::OpCode::B, labelDone, this->m_func);
@@ -4862,7 +4864,7 @@ LowererMD::LoadCheckedFloat(
                                             IR::IntConstOpnd::New(Js::AtomTag, TyMachReg, this->m_func),
                                             this->m_func);
     instrInsert->InsertBefore(instrFirst);
-    LegalizeMD::LegalizeInstr(instrFirst, false);
+    LegalizeMD::LegalizeInstr(instrFirst);
 
     IR::LabelInstr * labelVar = IR::LabelInstr::New(Js::OpCode::Label, this->m_func);
     instr = IR::BranchInstr::New(Js::OpCode::BCC, labelVar, this->m_func);
@@ -4987,7 +4989,7 @@ LowererMD::EmitLoadFloatFromNumber(IR::Opnd *dst, IR::Opnd *src, IR::Instr *inse
         // VLDR dst, [pResult].f64
         instr = IR::Instr::New(Js::OpCode::VLDR, dst, tempSymOpnd, this->m_func);
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
     }
 }
 
@@ -5011,7 +5013,7 @@ LowererMD::EmitLoadFloatCommon(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertIn
         regFloatOpnd = IR::RegOpnd::New(TyFloat64, this->m_func);
         instr = IR::Instr::New(Js::OpCode::VLDR, regFloatOpnd, memRef, this->m_func);
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
         isFloatConst = true;
     }
     // Src is constant?
@@ -5039,7 +5041,7 @@ LowererMD::EmitLoadFloatCommon(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertIn
             instr = IR::Instr::New(Js::OpCode::VMOV, dst, regFloatOpnd, this->m_func);
             insertInstr->InsertBefore(instr);
         }
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
         return nullptr;
     }
     Assert(src->IsRegOpnd());
@@ -5078,7 +5080,7 @@ LowererMD::EmitLoadFloatCommon(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertIn
         instr = IR::Instr::New(Js::OpCode::VMOV, dst, reg2, this->m_func);
         insertInstr->InsertBefore(instr);
     }
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     // B $Done
     instr = IR::BranchInstr::New(Js::OpCode::B, labelDone, this->m_func);
@@ -5105,7 +5107,7 @@ LowererMD::EmitLoadFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertInstr, I
 
     if (dst->IsIndirOpnd())
     {
-        LegalizeMD::LegalizeIndirOpndForVFP(insertInstr, dst->AsIndirOpnd(), false);
+        LegalizeMD::LegalizeIndirOpndForVFP(insertInstr, dst->AsIndirOpnd());
     }
 
     labelDone = EmitLoadFloatCommon(dst, src, insertInstr, true);
@@ -5185,7 +5187,7 @@ LowererMD::EmitLoadFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertInstr, I
         Js::OpCode opcode = (dst->GetType() == TyFloat32)? Js::OpCode::VLDR32: Js::OpCode::VLDR;
         instr = IR::Instr::New(opcode, dst , memAddress, this->m_func);
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
     }
 
     // $Done
@@ -5224,7 +5226,7 @@ LowererMD::GenerateNumberAllocation(IR::RegOpnd * opndDst, IR::Instr * instrInse
     checkInstr->SetSrc1(nextMemBlockOpnd);
     checkInstr->SetSrc2(endAddressOpnd);
     instrInsert->InsertBefore(checkInstr);
-    LegalizeMD::LegalizeInstr(checkInstr, false);
+    LegalizeMD::LegalizeInstr(checkInstr);
 
     // BHI $helper
     IR::LabelInstr * helperLabel = IR::LabelInstr::New(Js::OpCode::Label, this->m_func, true);
@@ -5283,21 +5285,21 @@ LowererMD::GenerateFastRecyclerAlloc(size_t allocSize, IR::RegOpnd* newObjDst, I
     // LDR newObjDst, allocator->freeObjectList
     IR::Instr * loadMemBlockInstr = IR::Instr::New(Js::OpCode::LDR, newObjDst, freeObjectListOpnd, this->m_func);
     insertionPointInstr->InsertBefore(loadMemBlockInstr);
-    LegalizeMD::LegalizeInstr(loadMemBlockInstr, false);
+    LegalizeMD::LegalizeInstr(loadMemBlockInstr);
 
     // nextMemBlock = ADD newObjDst, allocSize
     IR::RegOpnd * nextMemBlockOpnd = IR::RegOpnd::New(TyMachPtr, this->m_func);
     IR::IntConstOpnd* allocSizeOpnd = IR::IntConstOpnd::New((int32)allocSize, TyInt32, this->m_func);
     IR::Instr * loadNextMemBlockInstr = IR::Instr::New(Js::OpCode::ADD, nextMemBlockOpnd, newObjDst, allocSizeOpnd, this->m_func);
     insertionPointInstr->InsertBefore(loadNextMemBlockInstr);
-    LegalizeMD::LegalizeInstr(loadNextMemBlockInstr, false);
+    LegalizeMD::LegalizeInstr(loadNextMemBlockInstr);
 
     // CMP nextMemBlock, allocator->endAddress
     IR::Instr * checkInstr = IR::Instr::New(Js::OpCode::CMP, this->m_func);
     checkInstr->SetSrc1(nextMemBlockOpnd);
     checkInstr->SetSrc2(endAddressOpnd);
     insertionPointInstr->InsertBefore(checkInstr);
-    LegalizeMD::LegalizeInstr(checkInstr, false);
+    LegalizeMD::LegalizeInstr(checkInstr);
 
     // BHI $allocHelper
     IR::BranchInstr * branchToAllocHelperInstr = IR::BranchInstr::New(Js::OpCode::BHI, allocHelperLabel, this->m_func);
@@ -5306,7 +5308,7 @@ LowererMD::GenerateFastRecyclerAlloc(size_t allocSize, IR::RegOpnd* newObjDst, I
     // LDR allocator->freeObjectList, nextMemBlock
     IR::Instr * setFreeObjectListInstr = IR::Instr::New(Js::OpCode::LDR, freeObjectListOpnd, nextMemBlockOpnd, this->m_func);
     insertionPointInstr->InsertBefore(setFreeObjectListInstr);
-    LegalizeMD::LegalizeInstr(setFreeObjectListInstr, false);
+    LegalizeMD::LegalizeInstr(setFreeObjectListInstr);
 
     // B $allocDone
     IR::BranchInstr * branchToAllocDoneInstr = IR::BranchInstr::New(Js::OpCode::B, allocDoneLabel, this->m_func);
@@ -5319,7 +5321,7 @@ LowererMD::GenerateClz(IR::Instr * instr)
     Assert(instr->GetSrc1()->IsInt32() || instr->GetSrc1()->IsUInt32());
     Assert(IRType_IsNativeInt(instr->GetDst()->GetType()));
     instr->m_opcode = Js::OpCode::CLZ;
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 }
 
 void
@@ -5340,7 +5342,7 @@ LowererMD::SaveDoubleToVar(IR::RegOpnd * dstOpnd, IR::RegOpnd *opndFloat, IR::In
         IR::SymOpnd * symTempSrc = IR::SymOpnd::New(tempNumberSym, TyMachPtr, this->m_func);
         newInstr = IR::Instr::New(Js::OpCode::LEA, dstOpnd, symTempSrc, this->m_func);
         instrInsert->InsertBefore(newInstr);
-        LegalizeMD::LegalizeInstr(newInstr, false);
+        LegalizeMD::LegalizeInstr(newInstr);
 
         symVTableDst = IR::SymOpnd::New(tempNumberSym, TyMachPtr, this->m_func);
         symDblDst = IR::SymOpnd::New(tempNumberSym, (uint32)Js::JavascriptNumber::GetValueOffset(), TyFloat64, this->m_func);
@@ -5374,19 +5376,19 @@ LowererMD::SaveDoubleToVar(IR::RegOpnd * dstOpnd, IR::RegOpnd *opndFloat, IR::In
         // STR dst->vtable, JavascriptNumber::vtable
         newInstr = IR::Instr::New(Js::OpCode::STR, symVTableDst, jsNumberVTable, this->m_func);
         numberInitInsertInstr->InsertBefore(newInstr);
-        LegalizeMD::LegalizeInstr(newInstr, false);
+        LegalizeMD::LegalizeInstr(newInstr);
 
         // STR dst->type, JavascriptNumber_type
         IR::Opnd *typeOpnd = m_lowerer->LoadLibraryValueOpnd(numberInitInsertInstr, LibraryValue::ValueNumberTypeStatic);
         newInstr = IR::Instr::New(Js::OpCode::STR, symTypeDst, typeOpnd, this->m_func);
         numberInitInsertInstr->InsertBefore(newInstr);
-        LegalizeMD::LegalizeInstr(newInstr, false);
+        LegalizeMD::LegalizeInstr(newInstr);
     }
 
     // VSTR dst->value, opndFloat   ; copy the float result to the temp JavascriptNumber
     newInstr = IR::Instr::New(Js::OpCode::VSTR, symDblDst, opndFloat, this->m_func);
     instrInsert->InsertBefore(newInstr);
-    LegalizeMD::LegalizeInstr(newInstr, false);
+    LegalizeMD::LegalizeInstr(newInstr);
 
 
 }
@@ -5450,7 +5452,7 @@ LowererMD::GenerateFastAbs(IR::Opnd *dst, IR::Opnd *src, IR::Instr *callInstr, I
         IR::RegOpnd *regOpnd = IR::RegOpnd::New(TyVar, this->m_func);
         instr = IR::Instr::New(Js::OpCode::MOV, regOpnd, src, this->m_func);
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
         src = regOpnd;
     }
 
@@ -5508,7 +5510,7 @@ LowererMD::GenerateFastAbs(IR::Opnd *dst, IR::Opnd *src, IR::Instr *callInstr, I
         instr = IR::Instr::New(
             Js::OpCode::ADD, dst, dst32, IR::IntConstOpnd::New(Js::AtomTag, TyMachReg, this->m_func), this->m_func);
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
     }
 
     if (labelFloat)
@@ -5529,7 +5531,7 @@ LowererMD::GenerateFastAbs(IR::Opnd *dst, IR::Opnd *src, IR::Instr *callInstr, I
         instr->SetSrc1(opnd);
         instr->SetSrc2(m_lowerer->LoadVTableValueOpnd(insertInstr, VTableValue::VtableJavascriptNumber));
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
 
         // BNE $helper
         instr = IR::BranchInstr::New(Js::OpCode::BNE, labelHelper, this->m_func);
@@ -5687,7 +5689,7 @@ br2_Common:
         break;
     }
 
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 }
 
 void
@@ -5876,7 +5878,7 @@ LowererMD::LowerInt4MulWithBailOut(
         insertInstr->SetSrc1(src1);
         insertInstr->SetSrc2(src2);
         bailOutLabel->InsertBefore(insertInstr);
-        LegalizeMD::LegalizeInstr(insertInstr, false);
+        LegalizeMD::LegalizeInstr(insertInstr);
         bailOutLabel->InsertBefore(IR::BranchInstr::New(Js::OpCode::BPL, skipBailOutLabel, instr->m_func));
 
         // Fall through to bailOutLabel
@@ -6036,7 +6038,7 @@ LowererMD::EmitLoadVar(IR::Instr *instrLoad, bool isFromUint32, bool isHelper)
                 instr->SetSrc1(opnd32src1);
                 instr->SetSrc2(IR::IntConstOpnd::New((int32)0x80000000 >> Js::VarTag_Shift, TyInt32, this->m_func));
                 instrLoad->InsertBefore(instr);
-                LegalizeMD::LegalizeInstr(instr, false);
+                LegalizeMD::LegalizeInstr(instr);
 
                 //     BNE $helper
                 instr = IR::BranchInstr::New(Js::OpCode::BNE, labelToVar, this->m_func);
@@ -6340,7 +6342,7 @@ void LowererMD::GenerateFastInlineBuiltInCall(IR::Instr* instr, IR::JnHelperMeth
         Assert(helperMethod == (IR::JnHelperMethod)0);
         Assert(instr->GetSrc2() == nullptr);
         instr->m_opcode = Js::OpCode::VSQRT;
-        LegalizeMD::LegalizeInstr(instr, /* fPostRegAlloc = */ false);
+        LegalizeMD::LegalizeInstr(instr);
         break;
 
     case Js::OpCode::InlineMathAbs:
@@ -6597,7 +6599,7 @@ LowererMD::GenerateFastInlineBuiltInMathFloor(IR::Instr* instr)
     instrCmp->SetSrc1(floatOpnd);
     instrCmp->SetSrc2(floatOpnd);
     instr->InsertBefore(instrCmp);
-    LegalizeMD::LegalizeInstr(instrCmp, false);
+    LegalizeMD::LegalizeInstr(instrCmp);
 
     // VMRS APSR, FPSCR
     // BVS  $bailoutLabel
@@ -6695,7 +6697,7 @@ LowererMD::GenerateFastInlineBuiltInMathCeil(IR::Instr* instr)
     instrCmp->SetSrc1(floatOpnd);
     instrCmp->SetSrc2(floatOpnd);
     instr->InsertBefore(instrCmp);
-    LegalizeMD::LegalizeInstr(instrCmp, false);
+    LegalizeMD::LegalizeInstr(instrCmp);
 
     // VMRS APSR, FPSCR
     // BVS  $bailoutLabel
@@ -6798,7 +6800,7 @@ LowererMD::GenerateFastInlineBuiltInMathRound(IR::Instr* instr)
     instrCmp->SetSrc1(floatOpnd);
     instrCmp->SetSrc2(floatOpnd);
     instr->InsertBefore(instrCmp);
-    LegalizeMD::LegalizeInstr(instrCmp, false);
+    LegalizeMD::LegalizeInstr(instrCmp);
 
     // VMRS APSR, FPSCR
     // BVS  $bailoutLabel
@@ -6942,7 +6944,7 @@ LowererMD::LowerToFloat(IR::Instr *instr)
         Assume(UNREACHED);
     }
 
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
     return instr;
 }
 
@@ -6961,7 +6963,7 @@ LowererMD::LowerFloatCondBranch(IR::BranchInstr *instrBranch, bool ignoreNaN)
     instrCmp->SetSrc1(src1);
     instrCmp->SetSrc2(src2);
     instrBranch->InsertBefore(instrCmp);
-    LegalizeMD::LegalizeInstr(instrCmp, false);
+    LegalizeMD::LegalizeInstr(instrCmp);
 
     instrBranch->InsertBefore(IR::Instr::New(Js::OpCode::VMRS, func));
 
@@ -7113,7 +7115,7 @@ LowererMD::CheckOverflowOnFloatToInt32(IR::Instr* instrInsert, IR::Opnd* intOpnd
     instr->SetSrc1(intOpnd);
     instr->SetSrc2(IR::IntConstOpnd::New(0x80000000, TyInt32, this->m_func, true));
     instrInsert->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     // BEQ $helper
     instr = IR::BranchInstr::New(Js::OpCode::BEQ, labelHelper, this->m_func);
@@ -7128,13 +7130,13 @@ LowererMD::CheckOverflowOnFloatToInt32(IR::Instr* instrInsert, IR::Opnd* intOpnd
         IR::IntConstOpnd::New(0x80000000, TyInt32, this->m_func, true),
         this->m_func);
     instrInsert->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     instr = IR::Instr::New(Js::OpCode::CMP, this->m_func);
     instr->SetSrc1(intOpnd);
     instr->SetSrc2(regOpnd);
     instrInsert->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     // BNE $done
     instr = IR::BranchInstr::New(Js::OpCode::BNE, labelDone, this->m_func);
@@ -7310,7 +7312,7 @@ LowererMD::LoadFloatValue(IR::Opnd * opndDst, double value, IR::Instr * instrIns
     }
     IR::Instr * instr = IR::Instr::New(Js::OpCode::VLDR, opndDst, opnd, instrInsert->m_func);
     instrInsert->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr,false);
+    LegalizeMD::LegalizeInstr(instr);
     return instr;
 }
 
@@ -7344,7 +7346,7 @@ void LowererMD::GenerateFloatTest(IR::RegOpnd * opndSrc, IR::Instr * insertInstr
     instr->SetSrc1(vt);
     instr->SetSrc2(m_lowerer->LoadVTableValueOpnd(insertInstr, VTableValue::VtableJavascriptNumber));
     insertInstr->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr,false);
+    LegalizeMD::LegalizeInstr(instr);
 
     // BNE $helper
     instr = IR::BranchInstr::New(Js::OpCode::BNE, labelHelper, this->m_func);
@@ -7367,7 +7369,7 @@ void LowererMD::LoadFloatValue(IR::RegOpnd * javascriptNumber, IR::RegOpnd * opn
 
 template <bool verify>
 void
-LowererMD::Legalize(IR::Instr *const instr, bool fPostRegAlloc)
+LowererMD::Legalize(IR::Instr *const instr)
 {
     Func *const func = instr->m_func;
 
@@ -7384,7 +7386,7 @@ LowererMD::Legalize(IR::Instr *const instr, bool fPostRegAlloc)
         const IR::AutoReuseOpnd autoReuseFloat32Reg(float32Reg, func);
         IR::Instr *const newInstr = IR::Instr::New(Js::OpCode::VCVTS32F64, float32Reg, instr->GetSrc1(), func);
         instr->InsertBefore(newInstr);
-        LegalizeMD::LegalizeInstr(newInstr, false);
+        LegalizeMD::LegalizeInstr(newInstr);
         instr->m_opcode = Js::OpCode::VMOVARMVFP;
         instr->ReplaceSrc1(float32Reg);
     }
@@ -7394,12 +7396,12 @@ LowererMD::Legalize(IR::Instr *const instr, bool fPostRegAlloc)
         // NYI for the rest of legalization
         return;
     }
-    LegalizeMD::LegalizeInstr(instr, fPostRegAlloc);
+    LegalizeMD::LegalizeInstr(instr);
 }
 
-template void LowererMD::Legalize<false>(IR::Instr *const instr, bool fPostRegalloc);
+template void LowererMD::Legalize<false>(IR::Instr *const instr);
 #if DBG
-template void LowererMD::Legalize<true>(IR::Instr *const instr, bool fPostRegalloc);
+template void LowererMD::Legalize<true>(IR::Instr *const instr);
 #endif
 
 void
@@ -7501,7 +7503,7 @@ LowererMD::FinalLowerAssign(IR::Instr * instr)
 {
     if (instr->m_opcode == Js::OpCode::LDIMM)
     {
-        LegalizeMD::LegalizeInstr(instr, true);
+        LegalizeMD::LegalizeInstr(instr);
 
         // LDIMM can expand into MOV/MOVT when the immediate is more than 16 bytes,
         // it can also expand into multiple different no-op (normally MOV) instrs when we obfuscate it, which is randomly.
@@ -7512,7 +7514,7 @@ LowererMD::FinalLowerAssign(IR::Instr * instr)
         Assert(instr->GetDst()->IsRegOpnd());
         if (!instr->GetSrc1()->IsRegOpnd())
         {
-            LegalizeMD::LegalizeSrc(instr, instr->GetSrc1(), 1, true);
+            LegalizeMD::LegalizeSrc(instr, instr->GetSrc1(), 1);
             return true;
         }
         instr->m_opcode = (instr->GetSrc1()->GetType() == TyMachDouble) ? Js::OpCode::VMOV : Js::OpCode::MOV;
@@ -7522,7 +7524,7 @@ LowererMD::FinalLowerAssign(IR::Instr * instr)
         Assert(instr->GetSrc1()->IsRegOpnd());
         if (!instr->GetDst()->IsRegOpnd())
         {
-            LegalizeMD::LegalizeDst(instr, true);
+            LegalizeMD::LegalizeDst(instr);
             return true;
         }
         instr->m_opcode = (instr->GetDst()->GetType() == TyMachDouble) ? Js::OpCode::VMOV : Js::OpCode::MOV;
@@ -7538,7 +7540,7 @@ LowererMD::FinalLowerAssign(IR::Instr * instr)
         uint32 argOutSize = UInt32Math::Mul(this->m_func->m_argSlotsForFunctionsCalled, MachRegInt, Js::Throw::OutOfMemory);
         instr->SetSrc1(IR::IntConstOpnd::New(argOutSize, TyMachReg, this->m_func));
         instr->m_opcode = Js::OpCode::LDIMM;
-        LegalizeMD::LegalizeInstr(instr, true);
+        LegalizeMD::LegalizeInstr(instr);
         return true;
     }
     else if (instr->m_opcode == Js::OpCode::REM)
@@ -7586,8 +7588,8 @@ LowererMD::LowerDivI4AndBailOnReminder(IR::Instr * instr, IR::LabelInstr * bailO
 
     // delay assigning to the final dst.
     IR::Instr * sinkedInstr = instr->SinkDst(Js::OpCode::MOV);
-    LegalizeMD::LegalizeInstr(instr, false);
-    LegalizeMD::LegalizeInstr(sinkedInstr, false);
+    LegalizeMD::LegalizeInstr(instr);
+    LegalizeMD::LegalizeInstr(sinkedInstr);
 
     IR::Opnd * resultOpnd = instr->GetDst();
     IR::Opnd * numerator = instr->GetSrc1();
@@ -7600,7 +7602,7 @@ LowererMD::LowerDivI4AndBailOnReminder(IR::Instr * instr, IR::LabelInstr * bailO
     IR::RegOpnd * mulResult = IR::RegOpnd::New(TyInt32, m_func);
     IR::Instr * mulInstr = IR::Instr::New(Js::OpCode::MUL, mulResult, resultOpnd, denominatorOpnd, m_func);
     insertBeforeInstr->InsertBefore(mulInstr);
-    LegalizeMD::LegalizeInstr(mulInstr, false);
+    LegalizeMD::LegalizeInstr(mulInstr);
 
     this->m_lowerer->InsertCompareBranch(mulResult, numerator, Js::OpCode::BrNeq_A, bailOutLabel, insertBeforeInstr);
     return insertBeforeInstr;

+ 1 - 1
lib/Backend/arm/LowerMD.h

@@ -210,7 +210,7 @@ public:
             IR::Opnd*           GenerateArgOutForStackArgs(IR::Instr* callInstr, IR::Instr* stackArgsInstr);
 
             template <bool verify = false>
-            static void         Legalize(IR::Instr *const instr, bool fPostRegAlloc = false);
+            static void         Legalize(IR::Instr *const instr);
 
             void                GenerateFastInlineBuiltInMathAbs(IR::Instr *callInstr);
             void                GenerateFastInlineBuiltInMathFloor(IR::Instr *callInstr);

+ 2 - 2
lib/Backend/arm64/EncoderMD.cpp

@@ -1635,7 +1635,7 @@ bool EncoderMD::TryConstFold(IR::Instr *instr, IR::RegOpnd *regOpnd)
         }
 
         instr->ReplaceSrc(regOpnd, constOpnd);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
 
         return true;
     }
@@ -1655,7 +1655,7 @@ bool EncoderMD::TryFold(IR::Instr *instr, IR::RegOpnd *regOpnd)
         }
         IR::SymOpnd *symOpnd = IR::SymOpnd::New(regOpnd->m_sym, regOpnd->GetType(), instr->m_func);
         instr->ReplaceSrc(regOpnd, symOpnd);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
 
         return true;
     }

+ 64 - 57
lib/Backend/arm64/LegalizeMD.cpp

@@ -41,7 +41,12 @@ static LegalForms LegalSrcForms(IR::Instr * instr, uint opndNum)
     return _InstrForms[instr->m_opcode - (Js::OpCode::MDStart+1)].src[opndNum-1];
 }
 
-void LegalizeMD::LegalizeInstr(IR::Instr * instr, bool fPostRegAlloc)
+RegNum LegalizeMD::GetScratchReg(IR::Instr * instr)
+{
+    return instr->m_func->ShouldLegalizePostRegAlloc() ? SCRATCH_REG : RegNOREG;
+}
+
+void LegalizeMD::LegalizeInstr(IR::Instr * instr)
 {
     if (!instr->IsLowered())
     {
@@ -68,9 +73,9 @@ void LegalizeMD::LegalizeInstr(IR::Instr * instr, bool fPostRegAlloc)
         break;
     }
 
-    LegalizeDst(instr, fPostRegAlloc);
-    LegalizeSrc(instr, instr->GetSrc1(), 1, fPostRegAlloc);
-    LegalizeSrc(instr, instr->GetSrc2(), 2, fPostRegAlloc);
+    LegalizeDst(instr);
+    LegalizeSrc(instr, instr->GetSrc1(), 1);
+    LegalizeSrc(instr, instr->GetSrc2(), 2);
 }
 
 void LegalizeMD::LegalizeRegOpnd(IR::Instr* instr, IR::Opnd* opnd)
@@ -99,8 +104,10 @@ void LegalizeMD::LegalizeRegOpnd(IR::Instr* instr, IR::Opnd* opnd)
     }
 }
 
-void LegalizeMD::LegalizeDst(IR::Instr * instr, bool fPostRegAlloc)
+void LegalizeMD::LegalizeDst(IR::Instr * instr)
 {
+    const bool fPostRegAlloc = instr->m_func->ShouldLegalizePostRegAlloc();
+
     LegalForms forms = LegalDstForms(instr);
 
     IR::Opnd * opnd = instr->GetDst();
@@ -134,15 +141,11 @@ void LegalizeMD::LegalizeDst(IR::Instr * instr, bool fPostRegAlloc)
         // So extract the location, load it to register, replace the MemRefOpnd with an IndirOpnd taking the
         // register as base, and fall through to legalize the IndirOpnd.
         intptr_t memLoc = opnd->AsMemRefOpnd()->GetMemLoc();
-        IR::RegOpnd *newReg = IR::RegOpnd::New(TyMachPtr, instr->m_func);
-        if (fPostRegAlloc)
-        {
-            newReg->SetReg(SCRATCH_REG);
-        }
+        IR::RegOpnd *newReg = IR::RegOpnd::New(GetScratchReg(instr), TyMachPtr, instr->m_func);
         IR::Instr *newInstr = IR::Instr::New(Js::OpCode::LDIMM, newReg,
             IR::AddrOpnd::New(memLoc, opnd->AsMemRefOpnd()->GetAddrKind(), instr->m_func, true), instr->m_func);
         instr->InsertBefore(newInstr);
-        LegalizeMD::LegalizeInstr(newInstr, fPostRegAlloc);
+        LegalizeMD::LegalizeInstr(newInstr);
         IR::IndirOpnd *indirOpnd = IR::IndirOpnd::New(newReg, 0, opnd->GetType(), instr->m_func);
         opnd = instr->ReplaceDst(indirOpnd);
     }
@@ -150,16 +153,16 @@ void LegalizeMD::LegalizeDst(IR::Instr * instr, bool fPostRegAlloc)
     case IR::OpndKindIndir:
         if (!(forms & L_IndirMask))
         {
-            instr = LegalizeStore(instr, forms, fPostRegAlloc);
+            instr = LegalizeStore(instr, forms);
             forms = LegalDstForms(instr);
         }
-        LegalizeIndirOffset(instr, opnd->AsIndirOpnd(), forms, fPostRegAlloc);
+        LegalizeIndirOffset(instr, opnd->AsIndirOpnd(), forms);
         break;
 
     case IR::OpndKindSym:
         if (!(forms & L_SymMask))
         {
-            instr = LegalizeStore(instr, forms, fPostRegAlloc);
+            instr = LegalizeStore(instr, forms);
             forms = LegalDstForms(instr);
         }
 
@@ -167,7 +170,7 @@ void LegalizeMD::LegalizeDst(IR::Instr * instr, bool fPostRegAlloc)
         {
             // In order to legalize SymOffset we need to know final argument area, which is only available after lowerer.
             // So, don't legalize sym offset here, but it will be done as part of register allocator.
-            LegalizeSymOffset(instr, opnd->AsSymOpnd(), forms, fPostRegAlloc);
+            LegalizeSymOffset(instr, opnd->AsSymOpnd(), forms);
         }
         break;
 
@@ -177,8 +180,10 @@ void LegalizeMD::LegalizeDst(IR::Instr * instr, bool fPostRegAlloc)
     }
 }
 
-IR::Instr * LegalizeMD::LegalizeStore(IR::Instr *instr, LegalForms forms, bool fPostRegAlloc)
+IR::Instr * LegalizeMD::LegalizeStore(IR::Instr *instr, LegalForms forms)
 {
+    const bool fPostRegAlloc = instr->m_func->ShouldLegalizePostRegAlloc();
+
     if (LowererMD::IsAssign(instr) && instr->GetSrc1()->IsRegOpnd())
     {
         // We can just change this to a store in place.
@@ -198,8 +203,10 @@ IR::Instr * LegalizeMD::LegalizeStore(IR::Instr *instr, LegalForms forms, bool f
     return instr;
 }
 
-void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, bool fPostRegAlloc)
+void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum)
 {
+    const bool fPostRegAlloc = instr->m_func->ShouldLegalizePostRegAlloc();
+
     LegalForms forms = LegalSrcForms(instr, opndNum);
     if (opnd == NULL)
     {
@@ -228,11 +235,11 @@ void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, b
     case IR::OpndKindAddr:
     case IR::OpndKindHelperCall:
     case IR::OpndKindIntConst:
-        LegalizeImmed(instr, opnd, opndNum, opnd->GetImmediateValue(instr->m_func), forms, fPostRegAlloc);
+        LegalizeImmed(instr, opnd, opndNum, opnd->GetImmediateValue(instr->m_func), forms);
         break;
 
     case IR::OpndKindLabel:
-        LegalizeLabelOpnd(instr, opnd, opndNum, fPostRegAlloc);
+        LegalizeLabelOpnd(instr, opnd, opndNum);
         break;
 
     case IR::OpndKindMemRef:
@@ -241,14 +248,10 @@ void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, b
         // So extract the location, load it to register, replace the MemRefOpnd with an IndirOpnd taking the
         // register as base, and fall through to legalize the IndirOpnd.
         intptr_t memLoc = opnd->AsMemRefOpnd()->GetMemLoc();
-        IR::RegOpnd *newReg = IR::RegOpnd::New(TyMachPtr, instr->m_func);
-        if (fPostRegAlloc)
-        {
-            newReg->SetReg(SCRATCH_REG);
-        }
+        IR::RegOpnd *newReg = IR::RegOpnd::New(GetScratchReg(instr), TyMachPtr, instr->m_func);
         IR::Instr *newInstr = IR::Instr::New(Js::OpCode::LDIMM, newReg, IR::AddrOpnd::New(memLoc, IR::AddrOpndKindDynamicMisc, instr->m_func), instr->m_func);
         instr->InsertBefore(newInstr);
-        LegalizeMD::LegalizeInstr(newInstr, fPostRegAlloc);
+        LegalizeMD::LegalizeInstr(newInstr);
         IR::IndirOpnd *indirOpnd = IR::IndirOpnd::New(newReg, 0, opnd->GetType(), instr->m_func);
         if (opndNum == 1)
         {
@@ -263,16 +266,16 @@ void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, b
     case IR::OpndKindIndir:
         if (!(forms & L_IndirMask))
         {
-            instr = LegalizeLoad(instr, opndNum, forms, fPostRegAlloc);
+            instr = LegalizeLoad(instr, opndNum, forms);
             forms = LegalSrcForms(instr, 1);
         }
-        LegalizeIndirOffset(instr, opnd->AsIndirOpnd(), forms, fPostRegAlloc);
+        LegalizeIndirOffset(instr, opnd->AsIndirOpnd(), forms);
         break;
 
     case IR::OpndKindSym:
         if (!(forms & L_SymMask))
         {
-            instr = LegalizeLoad(instr, opndNum, forms, fPostRegAlloc);
+            instr = LegalizeLoad(instr, opndNum, forms);
             forms = LegalSrcForms(instr, 1);
         }
 
@@ -280,7 +283,7 @@ void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, b
         {
             // In order to legalize SymOffset we need to know final argument area, which is only available after lowerer.
             // So, don't legalize sym offset here, but it will be done as part of register allocator.
-            LegalizeSymOffset(instr, opnd->AsSymOpnd(), forms, fPostRegAlloc);
+            LegalizeSymOffset(instr, opnd->AsSymOpnd(), forms);
         }
         break;
 
@@ -290,8 +293,10 @@ void LegalizeMD::LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, b
     }
 }
 
-IR::Instr * LegalizeMD::LegalizeLoad(IR::Instr *instr, uint opndNum, LegalForms forms, bool fPostRegAlloc)
+IR::Instr * LegalizeMD::LegalizeLoad(IR::Instr *instr, uint opndNum, LegalForms forms)
 {
+    const bool fPostRegAlloc = instr->m_func->ShouldLegalizePostRegAlloc();
+
     if (LowererMD::IsAssign(instr) && instr->GetDst()->IsRegOpnd())
     {
         // We can just change this to a load in place.
@@ -302,7 +307,7 @@ IR::Instr * LegalizeMD::LegalizeLoad(IR::Instr *instr, uint opndNum, LegalForms
         // Hoist the memory opnd. The caller will verify the offset.
         IR::Opnd* src = (opndNum == 1) ? instr->GetSrc1() : instr->GetSrc2();
         AssertMsg(!fPostRegAlloc || src->GetType() == TyMachReg, "Post RegAlloc other types disallowed");
-        instr = GenerateHoistSrc(instr, opndNum, LowererMD::GetLoadOp(src->GetType()), fPostRegAlloc ? SCRATCH_REG : RegNOREG, fPostRegAlloc);
+        instr = GenerateHoistSrc(instr, opndNum, LowererMD::GetLoadOp(src->GetType()), GetScratchReg(instr));
     }
 
     if (instr->m_opcode == Js::OpCode::LDR && instr->GetSrc1()->IsSigned())
@@ -313,8 +318,10 @@ IR::Instr * LegalizeMD::LegalizeLoad(IR::Instr *instr, uint opndNum, LegalForms
     return instr;
 }
 
-void LegalizeMD::LegalizeIndirOffset(IR::Instr * instr, IR::IndirOpnd * indirOpnd, LegalForms forms, bool fPostRegAlloc)
+void LegalizeMD::LegalizeIndirOffset(IR::Instr * instr, IR::IndirOpnd * indirOpnd, LegalForms forms)
 {
+    const bool fPostRegAlloc = instr->m_func->ShouldLegalizePostRegAlloc();
+
     // For LEA, we have special handling of indiropnds
     auto correctSize = [](IR::Instr* instr, IR::IndirOpnd* indirOpnd)
     {
@@ -373,15 +380,15 @@ void LegalizeMD::LegalizeIndirOffset(IR::Instr * instr, IR::IndirOpnd * indirOpn
                 indexOpnd = newIndexOpnd;
             }
 
-            IR::Instr * instrAdd = Lowerer::HoistIndirIndexOpndAsAdd(instr, indirOpnd, baseOpnd, indexOpnd, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
-            LegalizeMD::LegalizeInstr(instrAdd, fPostRegAlloc);
+            IR::Instr * instrAdd = Lowerer::HoistIndirIndexOpndAsAdd(instr, indirOpnd, baseOpnd, indexOpnd, GetScratchReg(instr));
+            LegalizeMD::LegalizeInstr(instrAdd);
         }
     }
     else if (indirOpnd->GetIndexOpnd() != nullptr && offset != 0)
     {
         // Can't have both offset and index, so hoist the offset and try again.
-        IR::Instr *addInstr = Lowerer::HoistIndirOffset(instr, indirOpnd, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
-        LegalizeMD::LegalizeInstr(addInstr, fPostRegAlloc);
+        IR::Instr *addInstr = Lowerer::HoistIndirOffset(instr, indirOpnd, GetScratchReg(instr));
+        LegalizeMD::LegalizeInstr(addInstr);
         if (instr->m_opcode == Js::OpCode::LEA)
         {
             AssertOrFailFastMsg(indirOpnd->GetBaseOpnd() != nullptr && indirOpnd->GetBaseOpnd()->GetSize() == TySize[TyMachPtr], "Base operand of LEA must have pointer-width!");
@@ -440,16 +447,14 @@ void LegalizeMD::LegalizeIndirOffset(IR::Instr * instr, IR::IndirOpnd * indirOpn
     }
 
     // Offset is too large, so hoist it and replace it with an index
-    IR::Instr *addInstr = Lowerer::HoistIndirOffset(instr, indirOpnd, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
-    LegalizeMD::LegalizeInstr(addInstr, fPostRegAlloc);
+    IR::Instr *addInstr = Lowerer::HoistIndirOffset(instr, indirOpnd, GetScratchReg(instr));
+    LegalizeMD::LegalizeInstr(addInstr);
 }
 
-void LegalizeMD::LegalizeSymOffset(
-    IR::Instr * instr,
-    IR::SymOpnd * symOpnd,
-    LegalForms forms,
-    bool fPostRegAlloc)
+void LegalizeMD::LegalizeSymOffset(IR::Instr * instr, IR::SymOpnd * symOpnd, LegalForms forms)
 {
+    const bool fPostRegAlloc = instr->m_func->ShouldLegalizePostRegAlloc();
+
     AssertMsg(fPostRegAlloc, "LegalizeMD::LegalizeSymOffset can (and will) be called as part of register allocation. Can't call it as part of lowerer, as final argument area is not available yet.");
 
     RegNum baseReg;
@@ -520,14 +525,14 @@ void LegalizeMD::LegalizeSymOffset(
         instr->m_opcode = Js::OpCode::ADD;
         instr->ReplaceSrc1(IR::RegOpnd::New(NULL, baseReg, TyMachPtr, instr->m_func));
         instr->SetSrc2(IR::IntConstOpnd::New(offset, TyMachReg, instr->m_func));
-        newInstr = instr->HoistSrc2(Js::OpCode::LDIMM, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
-        LegalizeMD::LegalizeInstr(newInstr, fPostRegAlloc);
-        LegalizeMD::LegalizeInstr(instr, fPostRegAlloc);
+        newInstr = instr->HoistSrc2(Js::OpCode::LDIMM, GetScratchReg(instr));
+        LegalizeMD::LegalizeInstr(newInstr);
+        LegalizeMD::LegalizeInstr(instr);
     }
     else
     {
-        newInstr = Lowerer::HoistSymOffset(instr, symOpnd, baseReg, offset, fPostRegAlloc ? SCRATCH_REG : RegNOREG);
-        LegalizeMD::LegalizeInstr(newInstr, fPostRegAlloc);
+        newInstr = Lowerer::HoistSymOffset(instr, symOpnd, baseReg, offset, GetScratchReg(instr));
+        LegalizeMD::LegalizeInstr(newInstr);
     }
 }
 
@@ -536,9 +541,10 @@ void LegalizeMD::LegalizeImmed(
     IR::Opnd * opnd,
     uint opndNum,
     IntConstType immed,
-    LegalForms forms,
-    bool fPostRegAlloc)
+    LegalForms forms)
 {
+    const bool fPostRegAlloc = instr->m_func->ShouldLegalizePostRegAlloc();
+
     int size = instr->GetDst()->GetSize();
     if (!(((forms & L_ImmLog12) && EncoderMD::CanEncodeLogicalConst(immed, size)) ||
          ((forms & L_ImmU12) && IS_CONST_UINT12(immed)) ||
@@ -549,7 +555,7 @@ void LegalizeMD::LegalizeImmed(
     {
         if (instr->m_opcode != Js::OpCode::LDIMM)
         {
-            instr = LegalizeMD::GenerateLDIMM(instr, opndNum, fPostRegAlloc ? SCRATCH_REG : RegNOREG, fPostRegAlloc);
+            instr = LegalizeMD::GenerateLDIMM(instr, opndNum, GetScratchReg(instr));
         }
 
         if (fPostRegAlloc)
@@ -562,12 +568,13 @@ void LegalizeMD::LegalizeImmed(
 void LegalizeMD::LegalizeLabelOpnd(
     IR::Instr * instr,
     IR::Opnd * opnd,
-    uint opndNum,
-    bool fPostRegAlloc)
+    uint opndNum)
 {
+    const bool fPostRegAlloc = instr->m_func->ShouldLegalizePostRegAlloc();
+
     if (instr->m_opcode != Js::OpCode::LDIMM)
     {
-        instr = LegalizeMD::GenerateLDIMM(instr, opndNum, fPostRegAlloc ? SCRATCH_REG : RegNOREG, fPostRegAlloc);
+        instr = LegalizeMD::GenerateLDIMM(instr, opndNum, GetScratchReg(instr));
     }
     if (fPostRegAlloc)
     {
@@ -575,7 +582,7 @@ void LegalizeMD::LegalizeLabelOpnd(
     }
 }
 
-IR::Instr * LegalizeMD::GenerateHoistSrc(IR::Instr * instr, uint opndNum, Js::OpCode op, RegNum scratchReg, bool fPostRegAlloc)
+IR::Instr * LegalizeMD::GenerateHoistSrc(IR::Instr * instr, uint opndNum, Js::OpCode op, RegNum scratchReg)
 {
     IR::Instr * newInstr;
     if (opndNum == 1)
@@ -591,7 +598,7 @@ IR::Instr * LegalizeMD::GenerateHoistSrc(IR::Instr * instr, uint opndNum, Js::Op
     return newInstr;
 }
 
-IR::Instr * LegalizeMD::GenerateLDIMM(IR::Instr * instr, uint opndNum, RegNum scratchReg, bool fPostRegAlloc)
+IR::Instr * LegalizeMD::GenerateLDIMM(IR::Instr * instr, uint opndNum, RegNum scratchReg)
 {
     if (LowererMD::IsAssign(instr) && instr->GetDst()->IsRegOpnd())
     {
@@ -599,7 +606,7 @@ IR::Instr * LegalizeMD::GenerateLDIMM(IR::Instr * instr, uint opndNum, RegNum sc
     }
     else
     {
-        instr = GenerateHoistSrc(instr, opndNum, Js::OpCode::LDIMM, scratchReg, fPostRegAlloc);
+        instr = GenerateHoistSrc(instr, opndNum, Js::OpCode::LDIMM, scratchReg);
     }
 
     return instr;

+ 12 - 11
lib/Backend/arm64/LegalizeMD.h

@@ -75,22 +75,23 @@ struct LegalInstrForms
 class LegalizeMD
 {
 public:
-    static void LegalizeInstr(IR::Instr * instr, bool fPostRegAlloc);
-    static void LegalizeDst(IR::Instr * instr, bool fPostRegAlloc);
-    static void LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, bool fPostRegAlloc);
+    static void LegalizeInstr(IR::Instr * instr);
+    static void LegalizeDst(IR::Instr * instr);
+    static void LegalizeSrc(IR::Instr * instr, IR::Opnd * opnd, uint opndNum);
 
     static bool LegalizeDirectBranch(IR::BranchInstr *instr, uintptr_t branchOffset);
     static bool LegalizeAdrOffset(IR::Instr *instr, uintptr_t instrOffset);
     static bool LegalizeDataAdr(IR::Instr *instr, uintptr_t dataOffset);
 
 private:
+    static RegNum GetScratchReg(IR::Instr * instr);
     static void LegalizeRegOpnd(IR::Instr* instr, IR::Opnd* opnd);
-    static IR::Instr *LegalizeStore(IR::Instr *instr, LegalForms forms, bool fPostRegAlloc);
-    static IR::Instr *LegalizeLoad(IR::Instr *instr, uint opndNum, LegalForms forms, bool fPostRegAlloc);
-    static void LegalizeIndirOffset(IR::Instr * instr, IR::IndirOpnd * indirOpnd, LegalForms forms, bool fPostRegAlloc);
-    static void LegalizeSymOffset(IR::Instr * instr, IR::SymOpnd * indirOpnd, LegalForms forms, bool fPostRegAlloc);
-    static void LegalizeImmed(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, IntConstType immed, LegalForms forms, bool fPostRegAlloc);
-    static void LegalizeLabelOpnd(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, bool fPostRegAlloc);
+    static IR::Instr *LegalizeStore(IR::Instr *instr, LegalForms forms);
+    static IR::Instr *LegalizeLoad(IR::Instr *instr, uint opndNum, LegalForms forms);
+    static void LegalizeIndirOffset(IR::Instr * instr, IR::IndirOpnd * indirOpnd, LegalForms forms);
+    static void LegalizeSymOffset(IR::Instr * instr, IR::SymOpnd * indirOpnd, LegalForms forms);
+    static void LegalizeImmed(IR::Instr * instr, IR::Opnd * opnd, uint opndNum, IntConstType immed, LegalForms forms);
+    static void LegalizeLabelOpnd(IR::Instr * instr, IR::Opnd * opnd, uint opndNum);
 
     static inline uint32 ShiftTo16(UIntConstType* immed)
     {
@@ -106,9 +107,9 @@ private:
 
     static void LegalizeLDIMM(IR::Instr * instr, IntConstType immed);
     static void LegalizeLdLabel(IR::Instr * instr, IR::Opnd * opnd);
-    static IR::Instr * GenerateLDIMM(IR::Instr * instr, uint opndNum, RegNum scratchReg, bool fPostRegAlloc);
+    static IR::Instr * GenerateLDIMM(IR::Instr * instr, uint opndNum, RegNum scratchReg);
 
-    static IR::Instr * GenerateHoistSrc(IR::Instr * instr, uint opndNum, Js::OpCode op, RegNum scratchReg, bool fPostRegAlloc);
+    static IR::Instr * GenerateHoistSrc(IR::Instr * instr, uint opndNum, Js::OpCode op, RegNum scratchReg);
 
     static void ObfuscateLDIMM(IR::Instr * instrMov, IR::Instr * instrMovt);
     static void EmitRandomNopBefore(IR::Instr * instrMov, UINT_PTR rand, RegNum targetReg);

+ 3 - 3
lib/Backend/arm64/LinearScanMD.cpp

@@ -183,7 +183,7 @@ LinearScanMD::LegalizeDef(IR::Instr * instr)
 
     // Legalize opcodes, etc., but do not expand symbol/indirs with large offsets
     // because we can't safely do this until all loads and stores are in place.
-    LegalizeMD::LegalizeDst(instr, false);
+    LegalizeMD::LegalizeDst(instr);
 }
 
 void
@@ -201,11 +201,11 @@ LinearScanMD::LegalizeUse(IR::Instr * instr, IR::Opnd * opnd)
     // because we can't safely do this until all loads and stores are in place.
     if (opnd == instr->GetSrc1())
     {
-        LegalizeMD::LegalizeSrc(instr, opnd, 1, false);
+        LegalizeMD::LegalizeSrc(instr, opnd, 1);
     }
     else
     {
-        LegalizeMD::LegalizeSrc(instr, opnd, 2, false);
+        LegalizeMD::LegalizeSrc(instr, opnd, 2);
     }
 }
 

+ 57 - 55
lib/Backend/arm64/LowerMD.cpp

@@ -390,7 +390,7 @@ LowererMD::LoadDynamicArgument(IR::Instr *instr, uint argNumber)
     IR::Opnd* dst = GetOpndForArgSlot((Js::ArgSlot) (argNumber - 1));
     instr->SetDst(dst);
     instr->m_opcode = Js::OpCode::MOV;
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     return instr;
 }
@@ -404,13 +404,13 @@ LowererMD::LoadDynamicArgumentUsingLength(IR::Instr *instr)
     // We register store the first INT_ARG_REG_COUNT - 3 parameters, since the first 3 register parameters are taken by function object, callinfo, and this pointer
     IR::Instr *add = IR::Instr::New(Js::OpCode::SUB, IR::RegOpnd::New(src2->GetType(), this->m_func), src2, IR::IntConstOpnd::New(INT_ARG_REG_COUNT - 3, TyInt8, this->m_func), this->m_func);
     instr->InsertBefore(add);
-    LegalizeMD::LegalizeInstr(add, false);
+    LegalizeMD::LegalizeInstr(add);
     //We need store nth actuals, so stack location is after function object, callinfo & this pointer
     IR::RegOpnd *stackPointer   = IR::RegOpnd::New(nullptr, GetRegStackPointer(), TyMachReg, this->m_func);
     IR::IndirOpnd *actualsLocation = IR::IndirOpnd::New(stackPointer, add->GetDst()->AsRegOpnd(), GetDefaultIndirScale(), TyMachReg, this->m_func);
     instr->SetDst(actualsLocation);
     instr->m_opcode = Js::OpCode::LDR;
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     return instr;
 }
@@ -891,7 +891,7 @@ LowererMD::GenerateStackProbe(IR::Instr *insertInstr, bool afterProlog)
         instr->SetSrc1(IR::RegOpnd::New(nullptr, GetRegStackPointer(), TyMachReg, this->m_func));
         instr->SetSrc2(scratchOpnd);
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
 
         // BHI done
         instr = IR::BranchInstr::New(Js::OpCode::BHI, doneLabelInstr, this->m_func);
@@ -988,7 +988,7 @@ LowererMD::GenerateStackDeallocation(IR::Instr *instr, uint32 allocSize)
         spOpnd,
         IR::IntConstOpnd::New(allocSize, TyMachReg, this->m_func, true), this->m_func);
     instr->InsertBefore(spAdjustInstr);
-    LegalizeMD::LegalizeInstr(spAdjustInstr, true);
+    LegalizeMD::LegalizeInstr(spAdjustInstr);
 }
 
 
@@ -2111,7 +2111,9 @@ LowererMD::ChangeToAssign(IR::Instr * instr, IRType destType)
     {
         instr->m_opcode = IRType_IsFloat(destType) ? Js::OpCode::FMOV : Js::OpCode::MOV;
     }
-    LegalizeMD::LegalizeInstr(instr, false);
+
+    AutoRestoreLegalize restore(instr->m_func, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     return instr;
 }
@@ -2393,7 +2395,7 @@ LowererMD::LowerCondBranch(IR::Instr * instr)
             instrPrev->SetSrc1(opndSrc1);
             instrPrev->SetSrc2(IR::IntConstOpnd::New(0, TyInt32, m_func));
             instr->InsertBefore(instrPrev);
-            LegalizeMD::LegalizeInstr(instrPrev, false);
+            LegalizeMD::LegalizeInstr(instrPrev);
 
             instr->m_opcode = Js::OpCode::BNE;
 
@@ -2407,7 +2409,7 @@ LowererMD::LowerCondBranch(IR::Instr * instr)
             instrPrev->SetSrc1(opndSrc1);
             instrPrev->SetSrc2(IR::IntConstOpnd::New(0, TyInt32, m_func));
             instr->InsertBefore(instrPrev);
-            LegalizeMD::LegalizeInstr(instrPrev, false);
+            LegalizeMD::LegalizeInstr(instrPrev);
 
             instr->m_opcode = Js::OpCode::BEQ;
 
@@ -2427,7 +2429,7 @@ LowererMD::LowerCondBranch(IR::Instr * instr)
                 instrPrev->SetSrc1(opndSrc1);
                 instrPrev->SetSrc2(opndSrc2);
                 instr->InsertBefore(instrPrev);
-                LegalizeMD::LegalizeInstr(instrPrev, false);
+                LegalizeMD::LegalizeInstr(instrPrev);
 
                 instr->m_opcode = LowererMD::MDBranchOpcode(instr->m_opcode);
             }
@@ -2440,7 +2442,7 @@ LowererMD::LowerCondBranch(IR::Instr * instr)
                 instrPrev->SetSrc2(opndSrc2);
                 instr->InsertBefore(instrPrev);
 
-                LegalizeMD::LegalizeInstr(instrPrev, false);
+                LegalizeMD::LegalizeInstr(instrPrev);
 
                 instr->m_opcode = MDBranchOpcode(instr->m_opcode);
             }
@@ -2553,7 +2555,7 @@ LowererMD::GenerateFastDivByPow2(IR::Instr *instrDiv)
     //// s1 =  AND  src1, 0x80000001 | ((src2Value - 1) << 1)
     //instr = IR::Instr::New(Js::OpCode::AND, s1, src1, IR::IntConstOpnd::New((0x80000001 | ((src2Value - 1) << 1)), TyInt32, m_func), m_func);
     //instrDiv->InsertBefore(instr);
-    //LegalizeMD::LegalizeInstr(instr, false);
+    //LegalizeMD::LegalizeInstr(instr);
 
     ////       CMP s1, 1
     //instr = IR::Instr::New(Js::OpCode::CMP, m_func);
@@ -2568,12 +2570,12 @@ LowererMD::GenerateFastDivByPow2(IR::Instr *instrDiv)
     //// s1  = ASR  src1, log2(src2Value)  -- do the equal divide
     //instr = IR::Instr::New(Js::OpCode::ASR, s1, src1, IR::IntConstOpnd::New(Math::Log2(src2Value), TyInt32, m_func), m_func);
     //instrDiv->InsertBefore(instr);
-    //LegalizeMD::LegalizeInstr(instr, false);
+    //LegalizeMD::LegalizeInstr(instr);
 
     //// dst = ORR   s1, 1                 -- restore tagged int bit
     //instr = IR::Instr::New(Js::OpCode::ORR, dst, s1, IR::IntConstOpnd::New(1, TyInt32, m_func), m_func);
     //instrDiv->InsertBefore(instr);
-    //LegalizeMD::LegalizeInstr(instr, false);
+    //LegalizeMD::LegalizeInstr(instr);
     //
     ////       B  $done
     //instr = IR::BranchInstr::New(Js::OpCode::B, done, m_func);
@@ -2598,7 +2600,7 @@ LowererMD::GenerateFastDivByPow2(IR::Instr *instrDiv)
     //// s1 =  ASR  src1, log2(src2Value) + 1 -- do the integer divide and also shift out the tagged int bit
     //instr = IR::Instr::New(Js::OpCode::ASR, s1, src1, IR::IntConstOpnd::New(Math::Log2(src2Value) + 1, TyInt32, m_func), m_func);
     //instrDiv->InsertBefore(instr);
-    //LegalizeMD::LegalizeInstr(instr, false);
+    //LegalizeMD::LegalizeInstr(instr);
 
     //// Arg2: scriptContext
     //IR::JnHelperMethod helperMethod;
@@ -2610,7 +2612,7 @@ LowererMD::GenerateFastDivByPow2(IR::Instr *instrDiv)
     //    StackSym * tempNumberSym = this->m_lowerer->GetTempNumberSym(dst, instr->dstIsTempNumberTransferred);
 
     //    instr = this->m_lowerer->InsertLoadStackAddress(tempNumberSym, instrDiv);
-    //    LegalizeMD::LegalizeInstr(instr, false);
+    //    LegalizeMD::LegalizeInstr(instr);
 
     //    this->LoadHelperArgument(instrDiv, instr->GetDst());
     //}
@@ -2831,7 +2833,7 @@ bool LowererMD::GenerateFastCmXxTaggedInt(IR::Instr *instr, bool isInHelper  /*
     instrCmp->SetSrc1(src1);
     instrCmp->SetSrc2(src2);
     instr->InsertBefore(instrCmp);
-    LegalizeMD::LegalizeInstr(instrCmp,false);
+    LegalizeMD::LegalizeInstr(instrCmp);
 
     instr->InsertBefore(IR::BranchInstr::New(opcode, fallthru, m_func));
     instr->InsertBefore(IR::Instr::New(Js::OpCode::LDIMM, dst, opndFalse, m_func));
@@ -2874,7 +2876,7 @@ IR::Instr * LowererMD::GenerateConvBool(IR::Instr *instr)
     instrTst->SetSrc1(src1);
     instrTst->SetSrc2(src1);
     instr->InsertBefore(instrTst);
-    LegalizeMD::LegalizeInstr(instrTst, false);
+    LegalizeMD::LegalizeInstr(instrTst);
 
     // BNE fallthrough
     instr->InsertBefore(IR::BranchInstr::New(Js::OpCode::BNE, fallthru, m_func));
@@ -3405,7 +3407,7 @@ LowererMD::GenerateTaggedZeroTest( IR::Opnd * opndSrc, IR::Instr * insertInstr,
         instr->SetSrc1(opndSrc);
         instr->SetSrc2(opndSrc);
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
     }
 }
 
@@ -4001,7 +4003,7 @@ LowererMD::GenerateFastScopedFld(IR::Instr * instrScopedFld, bool isLoad)
     instr->SetSrc1(opndReg1);
     instr->SetSrc2(IR::IntConstOpnd::New(0x1, TyInt8, this->m_func));
     instrScopedFld->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     // BNE $helper
     instr = IR::BranchInstr::New(Js::OpCode::BNE, labelHelper, this->m_func);
@@ -4156,7 +4158,7 @@ LowererMD::GenerateStFldFromLocalInlineCache(
         opndIndir = IR::IndirOpnd::New(opndBase, opndSlotIndex, LowererMD::GetDefaultIndirScale(), TyMachReg, instrStFld->m_func);
         instr = IR::Instr::New(Js::OpCode::STR, opndIndir, opndSrc, instrStFld->m_func);
         instrStFld->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
     }
     else
     {
@@ -4164,7 +4166,7 @@ LowererMD::GenerateStFldFromLocalInlineCache(
         opndIndir = IR::IndirOpnd::New(opndSlotArray, opndSlotIndex, LowererMD::GetDefaultIndirScale(), TyMachReg, instrStFld->m_func);
         instr = IR::Instr::New(Js::OpCode::STR, opndIndir, opndSrc, instrStFld->m_func);
         instrStFld->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
     }
 
     // B $done
@@ -4569,7 +4571,7 @@ LowererMD::EmitLoadFloatFromNumber(IR::Opnd *dst, IR::Opnd *src, IR::Instr *inse
         instr->SetSrc1(regBoolResult);
         instr->SetSrc2(regBoolResult);
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
 
         // BNE $noBailOut
         labelNoBailOut = IR::LabelInstr::New(Js::OpCode::Label, this->m_func, true);
@@ -4595,7 +4597,7 @@ LowererMD::EmitLoadFloatFromNumber(IR::Opnd *dst, IR::Opnd *src, IR::Instr *inse
         // VLDR dst, [pResult].f64
         instr = IR::Instr::New(Js::OpCode::FLDR, dst, tempSymOpnd, this->m_func);
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
     }
 }
 
@@ -4619,7 +4621,7 @@ LowererMD::EmitLoadFloatCommon(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertIn
         regFloatOpnd = IR::RegOpnd::New(TyFloat64, this->m_func);
         instr = IR::Instr::New(Js::OpCode::FLDR, regFloatOpnd, memRef, this->m_func);
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
         isFloatConst = true;
     }
     // Src is constant?
@@ -4647,7 +4649,7 @@ LowererMD::EmitLoadFloatCommon(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertIn
             instr = IR::Instr::New(Js::OpCode::FMOV, dst, regFloatOpnd, this->m_func);
             insertInstr->InsertBefore(instr);
         }
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
         return nullptr;
     }
     Assert(src->IsRegOpnd());
@@ -4686,7 +4688,7 @@ LowererMD::EmitLoadFloatCommon(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertIn
         instr = IR::Instr::New(Js::OpCode::FMOV, dst, reg2, this->m_func);
         insertInstr->InsertBefore(instr);
     }
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     // B $Done
     instr = IR::BranchInstr::New(Js::OpCode::B, labelDone, this->m_func);
@@ -4786,7 +4788,7 @@ LowererMD::EmitLoadFloat(IR::Opnd *dst, IR::Opnd *src, IR::Instr *insertInstr, I
     {
         instr = IR::Instr::New(Js::OpCode::FLDR, dst , memAddress, this->m_func);
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
     }
 
     // $Done
@@ -4820,21 +4822,21 @@ LowererMD::GenerateFastRecyclerAlloc(size_t allocSize, IR::RegOpnd* newObjDst, I
     // LDR newObjDst, allocator->freeObjectList
     IR::Instr * loadMemBlockInstr = IR::Instr::New(Js::OpCode::LDR, newObjDst, freeObjectListOpnd, this->m_func);
     insertionPointInstr->InsertBefore(loadMemBlockInstr);
-    LegalizeMD::LegalizeInstr(loadMemBlockInstr, false);
+    LegalizeMD::LegalizeInstr(loadMemBlockInstr);
 
     // nextMemBlock = ADD newObjDst, allocSize
     IR::RegOpnd * nextMemBlockOpnd = IR::RegOpnd::New(TyMachPtr, this->m_func);
     IR::IntConstOpnd* allocSizeOpnd = IR::IntConstOpnd::New((int32)allocSize, TyInt32, this->m_func);
     IR::Instr * loadNextMemBlockInstr = IR::Instr::New(Js::OpCode::ADD, nextMemBlockOpnd, newObjDst, allocSizeOpnd, this->m_func);
     insertionPointInstr->InsertBefore(loadNextMemBlockInstr);
-    LegalizeMD::LegalizeInstr(loadNextMemBlockInstr, false);
+    LegalizeMD::LegalizeInstr(loadNextMemBlockInstr);
 
     // CMP nextMemBlock, allocator->endAddress
     IR::Instr * checkInstr = IR::Instr::New(Js::OpCode::CMP, this->m_func);
     checkInstr->SetSrc1(nextMemBlockOpnd);
     checkInstr->SetSrc2(endAddressOpnd);
     insertionPointInstr->InsertBefore(checkInstr);
-    LegalizeMD::LegalizeInstr(checkInstr, false);
+    LegalizeMD::LegalizeInstr(checkInstr);
 
     // BHI $allocHelper
     IR::BranchInstr * branchToAllocHelperInstr = IR::BranchInstr::New(Js::OpCode::BHI, allocHelperLabel, this->m_func);
@@ -4843,7 +4845,7 @@ LowererMD::GenerateFastRecyclerAlloc(size_t allocSize, IR::RegOpnd* newObjDst, I
     // LDR allocator->freeObjectList, nextMemBlock
     IR::Instr * setFreeObjectListInstr = IR::Instr::New(Js::OpCode::LDR, freeObjectListOpnd, nextMemBlockOpnd, this->m_func);
     insertionPointInstr->InsertBefore(setFreeObjectListInstr);
-    LegalizeMD::LegalizeInstr(setFreeObjectListInstr, false);
+    LegalizeMD::LegalizeInstr(setFreeObjectListInstr);
 
     // B $allocDone
     IR::BranchInstr * branchToAllocDoneInstr = IR::BranchInstr::New(Js::OpCode::B, allocDoneLabel, this->m_func);
@@ -4856,7 +4858,7 @@ LowererMD::GenerateClz(IR::Instr * instr)
     Assert(instr->GetSrc1()->IsIntegral32());
     Assert(IRType_IsNativeInt(instr->GetDst()->GetType()));
     instr->m_opcode = Js::OpCode::CLZ;
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 }
 
 void
@@ -5191,7 +5193,7 @@ br2_Common:
         break;
     }
 
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 }
 
 void
@@ -5354,7 +5356,7 @@ LowererMD::LowerInt4MulWithBailOut(
     IR::Opnd* s3 = IR::RegOpnd::New(TyInt64, instr->m_func);
     insertInstr = IR::Instr::New(Js::OpCode::SMULL, s3, src1, src2, instr->m_func);
     instr->InsertBefore(insertInstr);
-    LegalizeMD::LegalizeInstr(insertInstr, false);
+    LegalizeMD::LegalizeInstr(insertInstr);
 
     // dst = MOV_TRUNC s3
     instr->m_opcode = Js::OpCode::MOV_TRUNC;
@@ -5388,7 +5390,7 @@ LowererMD::LowerInt4MulWithBailOut(
         insertInstr->SetSrc1(src1);
         insertInstr->SetSrc2(src2);
         bailOutLabel->InsertBefore(insertInstr);
-        LegalizeMD::LegalizeInstr(insertInstr, false);
+        LegalizeMD::LegalizeInstr(insertInstr);
         bailOutLabel->InsertBefore(IR::BranchInstr::New(Js::OpCode::BPL, skipBailOutLabel, instr->m_func));
 
         // Fall through to bailOutLabel
@@ -5417,7 +5419,7 @@ LowererMD::LowerInt4MulWithBailOut(
         insertInstr->SetSrc1(dst);
         insertInstr->SetSrc2(dst);
         insertBeforeInstr->InsertBefore(insertInstr);
-        LegalizeMD::LegalizeInstr(insertInstr, false);
+        LegalizeMD::LegalizeInstr(insertInstr);
 
         insertBeforeInstr->InsertBefore(IR::BranchInstr::New(Js::OpCode::BEQ, checkForNegativeZeroLabel, instr->m_func));
     }
@@ -5471,7 +5473,7 @@ LowererMD::LowerInt4RemWithBailOut(
         insertInstr->SetSrc1(dst);
         insertInstr->SetSrc2(dst);
         bailOutLabel->InsertBefore(insertInstr);
-        LegalizeMD::LegalizeInstr(insertInstr, false);
+        LegalizeMD::LegalizeInstr(insertInstr);
 
         IR::Instr *branchInstr = IR::BranchInstr::New(Js::OpCode::BNE, skipBailOutLabel, instr->m_func);
         bailOutLabel->InsertBefore(branchInstr);
@@ -5480,7 +5482,7 @@ LowererMD::LowerInt4RemWithBailOut(
         insertInstr->SetSrc1(src1);
         insertInstr->SetSrc2(src1);
         bailOutLabel->InsertBefore(insertInstr);
-        LegalizeMD::LegalizeInstr(insertInstr, false);
+        LegalizeMD::LegalizeInstr(insertInstr);
 
         branchInstr = IR::BranchInstr::New(Js::OpCode::BPL, skipBailOutLabel, instr->m_func);
         bailOutLabel->InsertBefore(branchInstr);
@@ -5850,7 +5852,7 @@ void LowererMD::GenerateFastInlineBuiltInCall(IR::Instr* instr, IR::JnHelperMeth
         Assert(helperMethod == (IR::JnHelperMethod)0);
         Assert(instr->GetSrc2() == nullptr);
         instr->m_opcode = Js::OpCode::FSQRT;
-        LegalizeMD::LegalizeInstr(instr, /* fPostRegAlloc = */ false);
+        LegalizeMD::LegalizeInstr(instr);
         break;
 
     case Js::OpCode::InlineMathAbs:
@@ -5979,7 +5981,7 @@ LowererMD::GenerateFastInlineMathFround(IR::Instr* instr)
         {
             Assert(dstType == TyFloat64);
             instr->m_opcode = Js::OpCode::FCVT;
-            LegalizeMD::LegalizeInstr(instr, false);
+            LegalizeMD::LegalizeInstr(instr);
         }
     }
     else
@@ -5988,7 +5990,7 @@ LowererMD::GenerateFastInlineMathFround(IR::Instr* instr)
         if (dstType == TyFloat32)
         {
             instr->m_opcode = Js::OpCode::FCVT;
-            LegalizeMD::LegalizeInstr(instr, false);
+            LegalizeMD::LegalizeInstr(instr);
         }
         else
         {
@@ -5998,7 +6000,7 @@ LowererMD::GenerateFastInlineMathFround(IR::Instr* instr)
             instr->InsertBefore(shortener);
             instr->SetSrc1(tempOpnd);
             instr->m_opcode = Js::OpCode::FCVT;
-            LegalizeMD::LegalizeInstr(instr, false);
+            LegalizeMD::LegalizeInstr(instr);
         }
     }
 }
@@ -6255,7 +6257,7 @@ LowererMD::LowerToFloat(IR::Instr *instr)
         Assume(UNREACHED);
     }
 
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
     return instr;
 }
 
@@ -6274,7 +6276,7 @@ LowererMD::LowerFloatCondBranch(IR::BranchInstr *instrBranch, bool ignoreNaN)
     instrCmp->SetSrc1(src1);
     instrCmp->SetSrc2(src2);
     instrBranch->InsertBefore(instrCmp);
-    LegalizeMD::LegalizeInstr(instrCmp, false);
+    LegalizeMD::LegalizeInstr(instrCmp);
 
     switch (instrBranch->m_opcode)
     {
@@ -6566,7 +6568,7 @@ LowererMD::LoadFloatValue(IR::Opnd * opndDst, double value, IR::Instr * instrIns
     }
     IR::Instr * instr = IR::Instr::New(Js::OpCode::FLDR, opndDst, opnd, instrInsert->m_func);
     instrInsert->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr,false);
+    LegalizeMD::LegalizeInstr(instr);
     return instr;
 }
 
@@ -6583,7 +6585,7 @@ void LowererMD::GenerateFloatTest(IR::RegOpnd * opndSrc, IR::Instr * insertInstr
     instr->SetSrc1(opndSrc);
     instr->SetSrc2(floatTag);
     insertInstr->InsertBefore(instr);
-    LegalizeMD::LegalizeInstr(instr, false);
+    LegalizeMD::LegalizeInstr(instr);
 
     // BZ $helper
     instr = IR::BranchInstr::New(Js::OpCode::BEQ /* BZ */, labelHelper, this->m_func);
@@ -6602,7 +6604,7 @@ IR::RegOpnd* LowererMD::CheckFloatAndUntag(IR::RegOpnd * opndSrc, IR::Instr * in
         instr->SetSrc1(opndSrc);
         instr->SetSrc2(floatTag);
         insertInstr->InsertBefore(instr);
-        LegalizeMD::LegalizeInstr(instr, false);
+        LegalizeMD::LegalizeInstr(instr);
 
         // BZ $helper
         instr = IR::BranchInstr::New(Js::OpCode::BEQ /* BZ */, labelHelper, this->m_func);
@@ -6628,7 +6630,7 @@ LowererMD::Legalize(IR::Instr *const instr, bool fPostRegAlloc)
         // NYI for the rest of legalization
         return;
     }
-    LegalizeMD::LegalizeInstr(instr, fPostRegAlloc);
+    LegalizeMD::LegalizeInstr(instr);
 }
 
 template void LowererMD::Legalize<false>(IR::Instr *const instr, bool fPostRegalloc);
@@ -6813,7 +6815,7 @@ LowererMD::FinalLowerAssign(IR::Instr * instr)
 {
     if (instr->m_opcode == Js::OpCode::LDIMM)
     {
-        LegalizeMD::LegalizeInstr(instr, true);
+        LegalizeMD::LegalizeInstr(instr);
 
         // LDIMM can expand into up to 4 instructions when the immediate is more than 16 bytes,
         // it can also expand into multiple different no-op (normally MOV) instrs when we obfuscate it, which is randomly.
@@ -6824,7 +6826,7 @@ LowererMD::FinalLowerAssign(IR::Instr * instr)
         Assert(instr->GetDst()->IsRegOpnd());
         if (!instr->GetSrc1()->IsRegOpnd())
         {
-            LegalizeMD::LegalizeSrc(instr, instr->GetSrc1(), 1, true);
+            LegalizeMD::LegalizeSrc(instr, instr->GetSrc1(), 1);
             return true;
         }
         instr->m_opcode = instr->GetSrc1()->IsFloat() ? Js::OpCode::FMOV : Js::OpCode::MOV;
@@ -6834,7 +6836,7 @@ LowererMD::FinalLowerAssign(IR::Instr * instr)
         Assert(instr->GetSrc1()->IsRegOpnd());
         if (!instr->GetDst()->IsRegOpnd())
         {
-            LegalizeMD::LegalizeDst(instr, true);
+            LegalizeMD::LegalizeDst(instr);
             return true;
         }
         instr->m_opcode = instr->GetDst()->IsFloat() ? Js::OpCode::FMOV : Js::OpCode::MOV;
@@ -6850,7 +6852,7 @@ LowererMD::FinalLowerAssign(IR::Instr * instr)
         uint32 argOutSize = UInt32Math::Mul(this->m_func->m_argSlotsForFunctionsCalled, MachRegInt, Js::Throw::OutOfMemory);
         instr->SetSrc1(IR::IntConstOpnd::New(argOutSize, TyMachReg, this->m_func));
         instr->m_opcode = Js::OpCode::LDIMM;
-        LegalizeMD::LegalizeInstr(instr, true);
+        LegalizeMD::LegalizeInstr(instr);
         return true;
     }
     else if (instr->m_opcode == Js::OpCode::REM)
@@ -6919,8 +6921,8 @@ LowererMD::LowerDivI4AndBailOnReminder(IR::Instr * instr, IR::LabelInstr * bailO
 
     // delay assigning to the final dst.
     IR::Instr * sinkedInstr = instr->SinkDst(Js::OpCode::MOV);
-    LegalizeMD::LegalizeInstr(instr, false);
-    LegalizeMD::LegalizeInstr(sinkedInstr, false);
+    LegalizeMD::LegalizeInstr(instr);
+    LegalizeMD::LegalizeInstr(sinkedInstr);
 
     IR::Opnd * resultOpnd = instr->GetDst();
     IR::Opnd * numerator = instr->GetSrc1();
@@ -6933,7 +6935,7 @@ LowererMD::LowerDivI4AndBailOnReminder(IR::Instr * instr, IR::LabelInstr * bailO
     IR::RegOpnd * mulResult = IR::RegOpnd::New(TyInt32, m_func);
     IR::Instr * mulInstr = IR::Instr::New(Js::OpCode::MUL, mulResult, resultOpnd, denominatorOpnd, m_func);
     insertBeforeInstr->InsertBefore(mulInstr);
-    LegalizeMD::LegalizeInstr(mulInstr, false);
+    LegalizeMD::LegalizeInstr(mulInstr);
 
     this->m_lowerer->InsertCompareBranch(mulResult, numerator, Js::OpCode::BrNeq_A, bailOutLabel, insertBeforeInstr);
     return insertBeforeInstr;