PreviousUpNext

15.4.383  src/lib/compiler/back/low/sparc32/regor/instructions-rewrite-sparc32-g.pkg

## instructions-rewrite-sparc32-g.pkg

# Compiled by:
#     src/lib/compiler/back/low/sparc32/backend-sparc32.lib

# We are invoked from:
#
#     src/lib/compiler/back/low/main/sparc32/backend-lowhalf-sparc32.pkg
#     src/lib/compiler/back/low/sparc32/regor/spill-instructions-sparc32-g.pkg

stipulate
    package lem =  lowhalf_error_message;                                       # lowhalf_error_message         is from   src/lib/compiler/back/low/control/lowhalf-error-message.pkg
    package rkj =  registerkinds_junk;                                          # registerkinds_junk            is from   src/lib/compiler/back/low/code/registerkinds-junk.pkg
herein

    generic package   instructions_rewrite_sparc32_g   (
        #             ==============================
        #
        mcf: Machcode_Sparc32                                                   # Machcode_Sparc32              is from   src/lib/compiler/back/low/sparc32/code/machcode-sparc32.codemade.api
    )
    : (weak) Rewrite_Machine_Instructions                                       # Rewrite_Machine_Instructions  is from   src/lib/compiler/back/low/code/rewrite-machine-instructions.api
    {
        package mcf =  mcf;                                                     # "mcf" == "machcode_form" (abstract machine code).

        stipulate
            package rgk =  mcf::rgk;                                            # "rgk" == "registerkinds".
            package cls =  rkj::cls;                                            # "cls" == "codetemplists".
        herein

            fun error msg
                =
                lem::error ("instructions_rewrite_sparc32_g", msg);

            fun rewrite_use (instruction, rs, rt)
                =
                {   fun match r
                        =
                        rkj::codetemps_are_same_color (r, rs); 

                    fun rrr r
                        =
                        if (match r ) rt; else r;fi; 

                    fun ooo (i as mcf::REG r) => if (match r ) mcf::REG rt; else i;fi;
                        ooo i => i;
                    end;

                    fun ea' (THE (mcf::DISPLACE { base, disp, ramregion } ))
                            => 
                            THE (mcf::DISPLACE { base=>rrr base, disp, ramregion } );

                        ea' ea => ea;
                    end;

                    fun sparc_use (instruction)
                        = 
                        case instruction
                            #
                            mcf::LOAD { l, r, i, d, ramregion } => mcf::LOAD { l, r=>rrr r, i=>ooo i, d, ramregion };
                            mcf::STORE { s, d, r, i, ramregion } => mcf::STORE { s, d=>rrr d, r=>rrr r, i=>ooo i, ramregion };
                            mcf::FLOAD { l, r, i, d, ramregion } => mcf::FLOAD { l, r=>rrr r, i=>ooo i, d, ramregion };
                            mcf::FSTORE { s, d, r, i, ramregion } => mcf::FSTORE { s, d, r=>rrr r, i=>ooo i, ramregion };
                            mcf::ARITH { a, r, i, d } => mcf::ARITH { a, r=>rrr r, i=>ooo i, d };
                            mcf::SHIFT { s, r, i, d } => mcf::SHIFT { s, r=>rrr r, i=>ooo i, d };
                            mcf::BR { r, p, rcond, a, nop, label } =>
                                mcf::BR { r=>rrr r, p, rcond, a, nop, label };
                            mcf::MOVICC { b, i, d } => mcf::MOVICC { b, i=>ooo i, d=>rrr d };
                            mcf::MOVFCC { b, i, d } => mcf::MOVFCC { b, i=>ooo i, d=>rrr d };
                            mcf::MOVR { rcond, r, i, d } => mcf::MOVR { rcond, r=>rrr r, i=>ooo i, d=>rrr d };
                            mcf::JMP { r, i, labs, nop } => mcf::JMP { r=>rrr r, i=>ooo i, labs, nop };
                            mcf::JMPL { r, i, d, defs, uses, cuts_to, nop, ramregion } => 
                                mcf::JMPL { r=>rrr r, i=>ooo i, d, defs,
                                       uses=>cls::replace_this_by_that_in_codetemplists { this=>rs, that=>rt } uses,
                                       cuts_to, nop, ramregion };
                            mcf::CALL { defs, uses, label, cuts_to, nop, ramregion } => 
                                mcf::CALL { defs, uses=>cls::replace_this_by_that_in_codetemplists { this=>rs, that=>rt } uses,
                                       label, cuts_to, nop, ramregion };
                            mcf::SAVE { r, i, d } => mcf::SAVE { r=>rrr r, i=>ooo i, d };
                            mcf::RESTORE { r, i, d } => mcf::RESTORE { r=>rrr r, i=>ooo i, d };
                            mcf::WRY { r, i } => mcf::WRY { r=>rrr r, i=>ooo i };
                            mcf::TICC { t, cc, r, i } => mcf::TICC { t, cc, r=>rrr r, i=>ooo i };
                            _ => instruction;
                        esac;

                     case instruction
                         #
                         mcf::NOTE { op, ... }
                             =>
                             rewrite_use (op, rs, rt);

                         mcf::LIVE { regs, spilled }
                             =>
                             mcf::LIVE { regs=>rgk::add_codetemp_info_to_appropriate_kindlist (rt, rgk::drop_codetemp_info_from_codetemplists (rs, regs)),
                                                           spilled };
                         mcf::BASE_OP i
                             =>
                             mcf::BASE_OP (sparc_use i);

                         mcf::COPY { kind as rkj::INT_REGISTER, size_in_bits, src, dst, tmp }
                             => 
                             mcf::COPY { kind, size_in_bits, src=>map rrr src, dst, tmp=>ea' tmp };

                         _ => error "rewriteUse";
                     esac;
                };

            fun rewrite_def (instruction, rs, rt)
                =
                {   fun match r
                        =
                        rkj::codetemps_are_same_color (r, rs);

                    fun rrr r
                        =
                        if (match r ) rt; else r;fi; 

                    fun ea (THE (mcf::DIRECT r)) => THE (mcf::DIRECT (rrr r));
                        ea x => x;
                    end; 

                    fun sparc_def (instruction)
                        = 
                        case instruction 
                            #
                            mcf::LOAD { l, r, i, d, ramregion } => mcf::LOAD { l, r, i, d=>rrr d, ramregion };
                            mcf::ARITH { a, r, i, d }     => mcf::ARITH { a, r, i, d=>rrr d };
                            mcf::SHIFT { s, r, i, d }     => mcf::SHIFT { s, r, i, d=>rrr d };
                            mcf::SETHI { i, d }           => mcf::SETHI { i, d=>rrr d };
                            mcf::MOVICC { b, i, d }       => mcf::MOVICC { b, i, d=>rrr d };
                            mcf::MOVFCC { b, i, d }       => mcf::MOVFCC { b, i, d=>rrr d };
                            mcf::MOVR { rcond, r, i, d }  => mcf::MOVR { rcond, r, i, d=>rrr d };
                            mcf::SAVE { r, i, d }         => mcf::SAVE { r, i, d=>rrr d };
                            mcf::RESTORE { r, i, d }      => mcf::RESTORE { r, i, d=>rrr d };
                            mcf::RDY { d }                => mcf::RDY { d=>rrr d };

                            mcf::JMPL { r, i, d, defs, uses, cuts_to, nop, ramregion }
                                => 
                                mcf::JMPL { r, i, d=>rrr d, defs=>cls::replace_this_by_that_in_codetemplists { this=>rs, that=>rt } defs,
                                       uses, cuts_to, nop, ramregion };

                            mcf::CALL { defs, uses, label, cuts_to, nop, ramregion }
                                => 
                                mcf::CALL { defs=>cls::replace_this_by_that_in_codetemplists { this=>rs, that=>rt } defs,
                                       uses, label, cuts_to, nop, ramregion };

                            _ => instruction;
                        esac;


                    case  instruction
                        #
                        mcf::NOTE { op, ... }
                            =>
                            rewrite_def (op, rs, rt);

                        mcf::DEAD { regs, spilled }
                            => 
                            mcf::DEAD { regs=>rgk::add_codetemp_info_to_appropriate_kindlist (rt, rgk::drop_codetemp_info_from_codetemplists (rs, regs)), spilled };

                        mcf::BASE_OP i
                            =>
                            mcf::BASE_OP (sparc_def i);

                        mcf::COPY { kind as rkj::INT_REGISTER, size_in_bits,  src, dst, tmp }
                            => 
                            mcf::COPY { kind, size_in_bits, src, dst=>map rrr dst, tmp=>ea tmp };

                        _ => error "rewriteDef";
                    esac;
                };


            fun frewrite_use (instruction, rs, rt)
                =
                {   fun match r = rkj::codetemps_are_same_color (r, rs);
                    fun rrr r = if (match r ) rt; else r;fi; 

                    fun sparc_use (instruction)
                        = 
                        case instruction
                            #
                            mcf::FPOP1 { a, r, d }          =>   mcf::FPOP1   { a, r=>rrr r, d };
                            mcf::FPOP2 { a, r1, r2, d }     =>   mcf::FPOP2   { a, r1=>rrr r1, r2=>rrr r2, d };
                            mcf::FCMP { cmp, r1, r2, nop }  =>   mcf::FCMP    { cmp, r1=>rrr r1, r2=>rrr r2, nop };
                            mcf::FSTORE { s, r, i, d, ramregion } =>   mcf::FSTORE  { s, r, i, d=>rrr d, ramregion };
                            mcf::FMOVICC { size, b, r, d }    =>   mcf::FMOVICC { size, b, r=>rrr r, d=>rrr d };
                            mcf::FMOVFCC { size, b, r, d }    =>   mcf::FMOVFCC { size, b, r=>rrr r, d=>rrr d };

                            mcf::JMPL { r, i, d, defs, uses, cuts_to, nop, ramregion }
                                =>
                                mcf::JMPL { r, i, d, defs,
                                       uses=>cls::replace_this_by_that_in_codetemplists { this=>rs, that=>rt } uses,
                                       cuts_to, nop, ramregion };

                            mcf::CALL { defs, uses, label, cuts_to, nop, ramregion }
                                =>
                                mcf::CALL { defs, uses=>cls::replace_this_by_that_in_codetemplists { this=>rs, that=>rt } uses,
                                       label, cuts_to, nop, ramregion };
                            _ => instruction;
                        esac;

                    case instruction
                        #
                        mcf::NOTE { op, ... }
                            =>
                            frewrite_use (op, rs, rt);

                        mcf::BASE_OP i
                            =>
                            mcf::BASE_OP (sparc_use i);

                        mcf::LIVE { regs, spilled }
                            => 
                            mcf::LIVE { regs=>rgk::add_codetemp_info_to_appropriate_kindlist (rt, rgk::drop_codetemp_info_from_codetemplists (rs, regs)), spilled };

                        mcf::COPY { kind as rkj::FLOAT_REGISTER, size_in_bits, src, dst, tmp }
                            => 
                            mcf::COPY { kind, size_in_bits, src=>map rrr src, dst, tmp };

                        _ => error "frewriteUse";
                    esac;

              };


            fun frewrite_def (instruction, rs, rt)
                =
                {   fun match r
                        =
                        rkj::codetemps_are_same_color (r, rs);

                    fun rrr r
                        =
                        if (match r)   rt;
                        else           r;
                        fi; 

                    fun ea (THE (mcf::FDIRECT r)) => THE (mcf::FDIRECT (rrr r));
                        ea x => x;
                    end; 

                    fun sparc_def (instruction)
                        = 
                        case instruction
                            #                 
                            mcf::FPOP1   { a, r, d }               => mcf::FPOP1 { a, r, d=>rrr d };
                            mcf::FPOP2   { a, r1, r2, d }          => mcf::FPOP2 { a, r1, r2, d=>rrr d };
                            mcf::FLOAD   { l, r, i, d, ramregion } => mcf::FLOAD { l, r, i, d=>rrr d, ramregion };
                            mcf::FMOVICC { size, b, r, d }         => mcf::FMOVICC { size, b, r, d=>rrr d };
                            mcf::FMOVFCC { size, b, r, d }         => mcf::FMOVFCC { size, b, r, d=>rrr d };

                            mcf::JMPL { r, i, d, defs, uses, cuts_to, nop, ramregion }
                                =>
                                mcf::JMPL { r, i, d, uses, cuts_to, nop, ramregion,
                                           defs => cls::replace_this_by_that_in_codetemplists { this=>rs, that=>rt } defs
                                         };

                            mcf::CALL { defs, uses, label, cuts_to, nop, ramregion }
                                =>
                                mcf::CALL { uses, label, cuts_to, nop, ramregion,
                                           defs => cls::replace_this_by_that_in_codetemplists { this=>rs, that=>rt } defs
                                         };

                            _ => instruction;
                        esac;


                    case instruction
                        #                    
                        mcf::NOTE { op, ... }
                            =>
                            frewrite_def (op, rs, rt);

                        mcf::DEAD { regs, spilled }
                            => 
                            mcf::DEAD { regs=>rgk::add_codetemp_info_to_appropriate_kindlist (rt, rgk::drop_codetemp_info_from_codetemplists (rs, regs)), spilled };

                        mcf::BASE_OP i
                            =>
                            mcf::BASE_OP (sparc_def i);

                        mcf::COPY { kind as rkj::FLOAT_REGISTER, size_in_bits, src, dst, tmp }
                            => 
                            mcf::COPY { kind, size_in_bits, src, dst=>map rrr dst, tmp=>ea tmp };

                        _ => error "frewriteUse";
                    esac;

                };  
        end;
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext