commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1391604 - in /commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward: analysis/ instructions/
Date Fri, 28 Sep 2012 19:12:36 GMT
Author: luc
Date: Fri Sep 28 19:12:36 2012
New Revision: 1391604

URL: http://svn.apache.org/viewvc?rev=1391604&view=rev
Log:
Updated DCMPx bytecode transformation.

Added:
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer.java
  (with props)
Removed:
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer1.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer12.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer2.java
Modified:
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java?rev=1391604&r1=1391603&r2=1391604&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java
Fri Sep 28 19:12:36 2012
@@ -17,7 +17,6 @@
 package org.apache.commons.nabla.forward.analysis;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.IdentityHashMap;
 import java.util.Iterator;
@@ -38,9 +37,7 @@ import org.apache.commons.nabla.forward.
 import org.apache.commons.nabla.forward.instructions.DLoadTransformer;
 import org.apache.commons.nabla.forward.instructions.DReturnTransformer;
 import org.apache.commons.nabla.forward.instructions.DStoreTransformer;
-import org.apache.commons.nabla.forward.instructions.DcmpTransformer1;
-import org.apache.commons.nabla.forward.instructions.DcmpTransformer12;
-import org.apache.commons.nabla.forward.instructions.DcmpTransformer2;
+import org.apache.commons.nabla.forward.instructions.DcmpTransformer;
 import org.apache.commons.nabla.forward.instructions.Dup2Transformer;
 import org.apache.commons.nabla.forward.instructions.Dup2X1Transformer;
 import org.apache.commons.nabla.forward.instructions.Dup2X2Transformer;
@@ -58,7 +55,6 @@ import org.objectweb.asm.tree.FieldInsnN
 import org.objectweb.asm.tree.IincInsnNode;
 import org.objectweb.asm.tree.InsnList;
 import org.objectweb.asm.tree.InsnNode;
-import org.objectweb.asm.tree.LabelNode;
 import org.objectweb.asm.tree.LdcInsnNode;
 import org.objectweb.asm.tree.MethodInsnNode;
 import org.objectweb.asm.tree.MethodNode;
@@ -95,9 +91,6 @@ public class MethodDifferentiator {
     /** Instructions successors array. */
     private final Map<AbstractInsnNode, Set<AbstractInsnNode>> successors;
 
-    /** Cloned labels map. */
-    private final Map<LabelNode, LabelNode> clonedLabels;
-
     /** Build a differentiator for a method.
      * @param mathClasses math implementation classes
      * @param name name of the derived class
@@ -109,7 +102,6 @@ public class MethodDifferentiator {
         this.converted    = new HashSet<TrackingValue>();
         this.frames       = new IdentityHashMap<AbstractInsnNode, Frame<TrackingValue>>();
         this.successors   = new IdentityHashMap<AbstractInsnNode, Set<AbstractInsnNode>>();
-        this.clonedLabels = new HashMap<LabelNode, LabelNode>();
     }
 
     /** Get the index of the input {@link DerivativeStructure derivative structure} variable.
@@ -443,13 +435,7 @@ public class MethodDifferentiator {
             return new NarrowingTransformer().getReplacement(insn, this);
         case Opcodes.DCMPL :
         case Opcodes.DCMPG :
-            if (stack1Converted) {
-                if (stack0Converted) {
-                    return new DcmpTransformer12().getReplacement(insn, this);
-                }
-                return new DcmpTransformer1().getReplacement(insn, this);
-            }
-            return new DcmpTransformer2().getReplacement(insn, this);
+            return new DcmpTransformer(stack0Converted, stack1Converted).getReplacement(insn,
this);
         case Opcodes.DRETURN :
             // TODO the constructor parameter forced to true seems strange...
             return new DReturnTransformer(true).getReplacement(insn, this);
@@ -683,14 +669,6 @@ public class MethodDifferentiator {
         return max;
     }
 
-    /** Clone an instruction.
-     * @param insn instruction to clone
-     * @return cloned instruction
-     */
-    public AbstractInsnNode clone(final AbstractInsnNode insn) {
-        return insn.clone(clonedLabels);
-    }
-
     /** Analyzer preserving instructions successors information. */
     private class FlowAnalyzer extends Analyzer<TrackingValue> {
 

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer.java?rev=1391604&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer.java
(added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer.java
Fri Sep 28 19:12:36 2012
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.forward.instructions;
+
+import org.apache.commons.nabla.DifferentiationException;
+import org.apache.commons.nabla.forward.analysis.InstructionsTransformer;
+import org.apache.commons.nabla.forward.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for DCMPx instructions.
+ */
+public class DcmpTransformer implements InstructionsTransformer {
+
+    /** Indicator for top stack element conversion. */
+    private final boolean stack0Converted;
+
+    /** Indicator for next to top stack element conversion. */
+    private final boolean stack1Converted;
+
+    /** Simple constructor.
+     * @param stack0Converted if true, the top level stack element has already been converted
+     * @param stack1Converted if true, the next to top level stack element has already been
converted
+     */
+    public DcmpTransformer(final boolean stack0Converted, final boolean stack1Converted)
{
+        this.stack0Converted = stack0Converted;
+        this.stack1Converted = stack1Converted;
+    }
+
+    /** {@inheritDoc} */
+    public InsnList getReplacement(final AbstractInsnNode insn,
+                                   final MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException {
+        final InsnList list = new InsnList();
+
+        if (stack1Converted) {
+            if (stack0Converted) {
+                // operand stack initial state: ds_a, ds_b
+                list.add(new InsnNode(Opcodes.SWAP));                                   
          // => ds_b, ds_a
+                list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, DS_TYPE.getInternalName(),
+                                            "getValue",
+                                            Type.getMethodDescriptor(Type.DOUBLE_TYPE)));
         // => ds_b, a0
+                list.add(new InsnNode(Opcodes.DUP2_X2));                                
          // => a0, ds_b, a0
+                list.add(new InsnNode(Opcodes.POP2));                                   
          // => a0, ds_b
+                list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, DS_TYPE.getInternalName(),
+                                            "getValue",
+                                            Type.getMethodDescriptor(Type.DOUBLE_TYPE)));
         // => a0, b0
+            } else {
+                // operand stack initial state: ds_a, b0
+                list.add(new InsnNode(Opcodes.DUP2_X2));                                
          // => b0, ds_a, b0
+                list.add(new InsnNode(Opcodes.POP2));                                   
          // => b0, ds_a
+                list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, DS_TYPE.getInternalName(),
+                                            "getValue",
+                                            Type.getMethodDescriptor(Type.DOUBLE_TYPE)));
         // => b0, a0
+                list.add(new InsnNode(Opcodes.DUP2_X2));                                
          // => a0, b0, a0
+                list.add(new InsnNode(Opcodes.POP2));                                   
          // => a0, b0
+            }
+        } else {
+            // operand stack initial state: a, ds_b
+            list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, DS_TYPE.getInternalName(),
+                                        "getValue",
+                                        Type.getMethodDescriptor(Type.DOUBLE_TYPE)));   
          // => a0, b0
+        }
+
+        list.add(new InsnNode(insn.getOpcode()));                                       
          // => bool
+
+        return list;
+
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message