[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xalan-cvs
Subject:    cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler Mode.java
From:       santiagopg () apache ! org
Date:       2004-06-11 17:41:21
Message-ID: 20040611174121.21348.qmail () minotaur ! apache ! org
[Download RAW message or body]

santiagopg    2004/06/11 10:41:21

  Modified:    java/src/org/apache/xalan/xsltc/compiler Mode.java
  Log:
  Fixed a problem with peephole optimization patterns. I don't know if something \
changed in BCEL since the code was written, but the pattern syntax was not correct. \
I've also added a new common peephole pattern which should reduce then inner loop's \
length in some Translets.  
  Revision  Changes    Path
  1.33      +62 -33    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Mode.java
  
  Index: Mode.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Mode.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Mode.java	26 May 2004 21:33:08 -0000	1.32
  +++ Mode.java	11 Jun 2004 17:41:21 -0000	1.33
  @@ -24,6 +24,7 @@
   import java.util.Iterator;
   import java.util.Vector;
   
  +import org.apache.bcel.generic.Instruction;
   import org.apache.bcel.generic.BranchHandle;
   import org.apache.bcel.generic.ConstantPoolGen;
   import org.apache.bcel.generic.DUP;
  @@ -1429,20 +1430,20 @@
       }
   
       /**
  -     * Peephole optimization: Remove sequences of [ALOAD, POP].
  -     */
  +      * Peephole optimization.
  +      */
       private void peepHoleOptimization(MethodGenerator methodGen) {
  -    InstructionList il = methodGen.getInstructionList();
  -    InstructionFinder find = new InstructionFinder(il);
  +        InstructionList il = methodGen.getInstructionList();
  +        InstructionFinder find = new InstructionFinder(il);
   	InstructionHandle ih;
   	String pattern;
   
  -	// Remove seqences of ALOAD, POP (GTM)
  -	pattern = "`aload'`pop'`instruction'";
  -	for(Iterator iter=find.search(pattern); iter.hasNext();){
  -	    InstructionHandle[] match = (InstructionHandle[])iter.next();
  +	// LoadInstruction, POP => (removed)
  +	pattern = "LoadInstruction POP";
  +	for (Iterator iter = find.search(pattern); iter.hasNext();) {
  +	    InstructionHandle[] match = (InstructionHandle[]) iter.next();
   	    try {
  -		if ((!match[0].hasTargeters()) && (!match[1].hasTargeters())) {
  +		if (!match[0].hasTargeters() && !match[1].hasTargeters()) {
                       il.delete(match[0], match[1]);
                   }
   	    }
  @@ -1450,45 +1451,73 @@
                   // TODO: move target down into the list
               }
   	}
  -	// Replace sequences of ILOAD_?, ALOAD_?, SWAP with ALOAD_?, ILOAD_?
  -	pattern = "`iload'`aload'`swap'`instruction'";
  -	for(Iterator iter=find.search(pattern); iter.hasNext();){
  +        
  +	// ILOAD_N, ILOAD_N, SWAP, ISTORE_N => ILOAD_N
  +	pattern = "ILOAD ILOAD SWAP ISTORE";
  +	for (Iterator iter = find.search(pattern); iter.hasNext();) {
  +            InstructionHandle[] match = (InstructionHandle[]) iter.next();
  +            try {              
  +                org.apache.bcel.generic.ILOAD iload1 = 
  +                    (org.apache.bcel.generic.ILOAD) match[0].getInstruction();
  +                org.apache.bcel.generic.ILOAD iload2 = 
  +                    (org.apache.bcel.generic.ILOAD) match[1].getInstruction();
  +                org.apache.bcel.generic.ISTORE istore = 
  +                    (org.apache.bcel.generic.ISTORE) match[3].getInstruction();
  +                
  +                if (!match[1].hasTargeters() &&
  +                    !match[2].hasTargeters() &&
  +                    !match[3].hasTargeters() &&
  +                    iload1.getIndex() == iload2.getIndex() &&
  +                    iload2.getIndex() == istore.getIndex())
  +                {
  +                    il.delete(match[1], match[3]);
  +                }
  +            }
  +            catch (TargetLostException e) {
  +                // TODO: move target down into the list
  +            }
  +        }
  +
  +        // LoadInstruction_N, LoadInstruction_M, SWAP => LoadInstruction_M, \
LoadInstruction_N  +	pattern = "LoadInstruction LoadInstruction SWAP";
  +	for (Iterator iter = find.search(pattern); iter.hasNext();) {
               InstructionHandle[] match = (InstructionHandle[])iter.next();
               try {
  -                org.apache.bcel.generic.Instruction iload;
  -                org.apache.bcel.generic.Instruction aload;
  -                if ((!match[0].hasTargeters()) &&
  -                    (!match[1].hasTargeters()) &&
  -                    (!match[2].hasTargeters())) {
  -                    iload = match[0].getInstruction();
  -                    aload = match[1].getInstruction();
  -                    il.insert(match[0], aload);
  -                    il.insert(match[0], iload);
  -                    il.delete(match[0], match[2]);
  +                if (!match[0].hasTargeters() &&
  +                    !match[1].hasTargeters() &&
  +                    !match[2].hasTargeters()) 
  +                {
  +                    Instruction load_m = match[1].getInstruction();
  +                    il.insert(match[0], load_m);
  +                    il.delete(match[1], match[2]);
                   }
               }
               catch (TargetLostException e) {
                   // TODO: move target down into the list
               }
           }
  -        
  -        // Replace sequences of ALOAD_1, ALOAD_1 with ALOAD_1, DUP 
  -	pattern = "`aload_1'`aload_1'`instruction'";
  -        for(Iterator iter=find.search(pattern); iter.hasNext();){
  +                
  +        // ALOAD_N ALOAD_N => ALOAD_N DUP
  +	pattern = "ALOAD ALOAD";
  +        for (Iterator iter = find.search(pattern); iter.hasNext();) {
               InstructionHandle[] match = (InstructionHandle[])iter.next();
               try {
  -	        org.apache.bcel.generic.Instruction iload;
  -                org.apache.bcel.generic.Instruction aload;
  -                if ((!match[0].hasTargeters()) && (!match[1].hasTargeters())) {
  -                    il.insert(match[1], new DUP());
  -                    il.delete(match[1]);
  +                if (!match[1].hasTargeters()) {
  +                    org.apache.bcel.generic.ALOAD aload1 = 
  +                        (org.apache.bcel.generic.ALOAD) match[0].getInstruction();
  +                    org.apache.bcel.generic.ALOAD aload2 = 
  +                        (org.apache.bcel.generic.ALOAD) match[1].getInstruction();
  +                    
  +                    if (aload1.getIndex() == aload2.getIndex()) {
  +                        il.insert(match[1], new DUP());
  +                        il.delete(match[1]);
  +                    }
                   }
               }
               catch (TargetLostException e) {
                   // TODO: move target down into the list
               }
           }
  -        
       }
   
       public InstructionHandle getTemplateInstructionHandle(Template template) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic