[Mono-dev] Patch for ilasm (ldc.i4 opt)

Thierry Lafage thierry.lafage at inria.fr
Mon Mar 22 04:25:26 EDT 2010


Hi Rodrigo,

I don't have an svn account, but I'll soon stop working on our gcc4cli 
project so I think, for the moment, it is not worth I have one (my 
successor may ask for one, when we've found him/her).
I simply would like to add this patch (+ another concerning local 
variable accesses), would you mind commiting it please?

Regards,

Thierry Lafage.



Rodrigo Kumpera a écrit :
> Patch looks good, do you have a SVN  account?
>
>
> On Wed, Mar 17, 2010 at 2:22 PM, Thierry Lafage 
> <thierry.lafage at inria.fr <mailto:thierry.lafage at inria.fr>> wrote:
>
>     Hi all,
>
>     Here is a small patch for ilasm which makes it replace ldc.i4 with
>     short forms when possible.
>     Note that I'm a C# and monodevelop newbie (but I tried to respect
>     the coding guidelines).
>     I suggest to add the "-opt:ldc" because I would like to add the
>     same kind of optimization for ldloc/stloc (use short forms when
>     possible). For this latter one, the command line option could be
>     "-opt:loc" (and we could add "-opt:all" to enable both at once).
>     I think the impact of such a patch is quite limited, but it's
>     important for us (the gcc4cli team) since we rely on ilasm to
>     assemble the CIL code produced by our compiler. And these
>     "optimizations" tasks are better suited to the assembler than to
>     the compiler itself.
>
>     Regards,
>     Thierry Lafage.
>
>
>     Index: ilasm/Driver.cs
>     ===================================================================
>     --- ilasm/Driver.cs     (revision 153715)
>     +++ ilasm/Driver.cs     (working copy)
>     @@ -20,6 +20,8 @@
>
>             public class Driver {
>
>     +                               internal static bool opt_ldc = false;
>     +
>                     enum Target {
>                             Dll,
>                             Exe
>     @@ -270,6 +272,10 @@
>                                                    else
>                                                            keyname =
>     command_arg;
>                                                    break;
>     +                                        case "opt":
>     +                                               if ("ldc" ==
>     command_arg)
>     +                                                      
>     Driver.opt_ldc = true;
>     +                                               break;
>                                             case "scan_only":
>                                                     scan_only = true;
>                                                     break;
>     @@ -344,6 +350,7 @@
>                                             "   /exe              
>     Compile to executable.\n" +
>                                             "   /dll              
>     Compile to library.\n" +
>                                             "   /debug            
>     Include debug information.\n" +
>     +                                        "   /opt:ldc          
>     Optimize ldc instructions (use shorter forms when possible).\n" +
>                                            "   /key:keyfile      
>     Strongname using the specified key file\n" +
>                                            "   /key:@container  
>      Strongname using the specified key container\n" +
>                                             "Options can be of the
>     form -option or /option\n");
>     Index: ilasm/codegen/IntInstr.cs
>     ===================================================================
>     --- ilasm/codegen/IntInstr.cs   (revision 153715)
>     +++ ilasm/codegen/IntInstr.cs   (working copy)
>     @@ -27,9 +27,35 @@
>                     public override void Emit (CodeGen code_gen,
>     MethodDef meth,
>                                               PEAPI.CILInstructions cil)
>                     {
>     -                        cil.IntInst (op, operand);
>     -                }
>     +                       if (Driver.opt_ldc && op ==
>     PEAPI.IntOp.ldc_i4) {
>     +                               if (operand >= -1 && operand <= 8)
>     +                                       cil.Inst (getOptLdcOp
>     (operand));
>     +                               else if (operand >= -128 &&
>     operand <= 127)
>     +                                       cil.IntInst
>     (PEAPI.IntOp.ldc_i4_s,
>     +                                               operand);
>     +                               else
>     +                                       cil.IntInst (op, operand);
>     +                       } else
>     +                               cil.IntInst (op, operand);
>     +               }
>
>     +               private PEAPI.Op getOptLdcOp (int operand)
>     +               {
>     +                       switch (operand) {
>     +                       case -1: return PEAPI.Op.ldc_i4_m1;
>     +                       case 0:  return PEAPI.Op.ldc_i4_0;
>     +                       case 1:  return PEAPI.Op.ldc_i4_1;
>     +                       case 2:  return PEAPI.Op.ldc_i4_2;
>     +                       case 3:  return PEAPI.Op.ldc_i4_3;
>     +                       case 4:  return PEAPI.Op.ldc_i4_4;
>     +                       case 5:  return PEAPI.Op.ldc_i4_5;
>     +                       case 6:  return PEAPI.Op.ldc_i4_6;
>     +                       case 7:  return PEAPI.Op.ldc_i4_7;
>     +                       case 8:  return PEAPI.Op.ldc_i4_8;
>     +                       default:
>     +                               throw new
>     ArgumentOutOfRangeException ("operand");
>     +                       }
>     +               }
>             }
>
>      }
>
>     _______________________________________________
>     Mono-devel-list mailing list
>     Mono-devel-list at lists.ximian.com
>     <mailto:Mono-devel-list at lists.ximian.com>
>     http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>


More information about the Mono-devel-list mailing list