Esempio n. 1
0
def PhaseFinalizeStackAndLocalRegAlloc(fun: ir.Fun, _opt_stats: Dict[str, int],
                                       fout):
    """Finalizing the stack implies performing all transformations that
    could increase register usage.

    """
    # print("@@@@@@\n", "\n".join(serialize.FunRenderToAsm(fun)), file=fout)

    # hack: some of the code expansion templates need a scratch reg
    # we do not want to reserve registers for this globally, so instead
    # we inject some nop instructions that reserve a register that we
    # use as a scratch for the instruction immediately following the nop
    #
    # This still has a potential bug: if the next instruction has one of its
    # inputs spilled, it will like use the scratch reg provided by the nop1
    # which will cause incorrect code.
    # TODO: add a checker so we at least detect this
    # Alternatives: reserve reg (maybe only for functions that need it)
    # TODO: make sure that nop1 regs never get spilled
    isel_tab.FunAddNop1ForCodeSel(fun)
    regs.FunLocalRegAlloc(fun)
    fun.FinalizeStackSlots()
    # if fun.name == "fibonacci": DumpFun("after local alloc", fun)
    # DumpFun("after local alloc", fun)
    # cleanup
    _FunMoveEliminationCpu(fun)
Esempio n. 2
0
def PhaseFinalizeStackAndLocalRegAlloc(fun: ir.Fun, _opt_stats: Dict[str, int],
                                       fout):
    """Finalizing the stack implies performing all transformations that
    could increase register usage.

    """
    regs.FunLocalRegAlloc(fun)
    fun.FinalizeStackSlots()
    # cleanup
    FunMoveEliminationCpu(fun)
Esempio n. 3
0
def PhaseFinalizeStackAndLocalRegAlloc(fun: ir.Fun, _opt_stats: Dict[str, int],
                                       fout):
    """Finalizing the stack implies performing all transformations that
    could increase register usage.

    """
    if False:
        to_be_spillled = [reg for reg in fun.regs if not reg.HasCpuReg()]
        to_be_spillled.sort()
        reg_alloc.FunSpillRegs(fun, o.DK.U32, to_be_spillled)

    fun.FinalizeStackSlots()
    # DumpFun("@@@ aaa", fun)
    # Special flavor out-of-bound immediate rewriter that is stack aware
    # In rare cases this could introduce the need for another gpr reg
    _FunRewriteOutOfBoundsOffsetsStk(fun)
    # DumpFun("@@@@ before reg-alloc", fun)
    # Assign regs to local var

    regs.FunLocalRegAlloc(fun)
    fun.flags &= ~ir.FUN_FLAG.STACK_FINALIZED
    fun.FinalizeStackSlots()
    # cleanup
    FunMoveEliminationCpu(fun)