src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/backend/AllocatorTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/backend

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/backend/AllocatorTest.java

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.core.test.backend;
  24 
  25 import java.util.HashSet;
  26 
  27 import jdk.vm.ci.code.Register;
  28 import jdk.vm.ci.code.ValueUtil;
  29 import jdk.vm.ci.meta.Value;
  30 
  31 import org.junit.Assert;
  32 
  33 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
  34 import org.graalvm.compiler.debug.Debug;
  35 import org.graalvm.compiler.debug.Debug.Scope;
  36 import org.graalvm.compiler.lir.LIR;
  37 import org.graalvm.compiler.lir.LIRInstruction;
  38 import org.graalvm.compiler.lir.LIRValueUtil;
  39 import org.graalvm.compiler.lir.StandardOp.ValueMoveOp;
  40 import org.graalvm.compiler.lir.ValueProcedure;
  41 import org.graalvm.compiler.nodes.StructuredGraph;
  42 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;





  43 
  44 public class AllocatorTest extends BackendTest {
  45 
  46     @SuppressWarnings("try")
  47     protected void testAllocation(String snippet, final int expectedRegisters, final int expectedRegRegMoves, final int expectedSpillMoves) {
  48         final StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
  49         try (Scope s = Debug.scope("AllocatorTest", graph, graph.method(), getCodeCache())) {

  50             final RegisterStats stats = new RegisterStats(getLIRGenerationResult(graph).getLIR());
  51             try (Scope s2 = Debug.scope("Assertions", stats.lir)) {
  52                 Assert.assertEquals("register count", expectedRegisters, stats.registers.size());
  53                 Assert.assertEquals("reg-reg moves", expectedRegRegMoves, stats.regRegMoves);
  54                 Assert.assertEquals("spill moves", expectedSpillMoves, stats.spillMoves);
  55             } catch (Throwable e) {
  56                 throw Debug.handle(e);
  57             }
  58         } catch (Throwable e) {
  59             throw Debug.handle(e);
  60         }
  61     }
  62 
  63     private class RegisterStats {
  64 
  65         public final LIR lir;
  66         public HashSet<Register> registers = new HashSet<>();
  67         public int regRegMoves;
  68         public int spillMoves;
  69 
  70         RegisterStats(LIR lir) {
  71             this.lir = lir;
  72 
  73             for (AbstractBlockBase<?> block : lir.codeEmittingOrder()) {
  74                 if (block == null) {
  75                     continue;
  76                 }
  77                 for (LIRInstruction instr : lir.getLIRforBlock(block)) {
  78                     collectStats(instr);
  79                 }




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.core.test.backend;
  24 
  25 import java.util.HashSet;
  26 






  27 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
  28 import org.graalvm.compiler.debug.DebugContext;

  29 import org.graalvm.compiler.lir.LIR;
  30 import org.graalvm.compiler.lir.LIRInstruction;
  31 import org.graalvm.compiler.lir.LIRValueUtil;
  32 import org.graalvm.compiler.lir.StandardOp.ValueMoveOp;
  33 import org.graalvm.compiler.lir.ValueProcedure;
  34 import org.graalvm.compiler.nodes.StructuredGraph;
  35 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  36 import org.junit.Assert;
  37 
  38 import jdk.vm.ci.code.Register;
  39 import jdk.vm.ci.code.ValueUtil;
  40 import jdk.vm.ci.meta.Value;
  41 
  42 public class AllocatorTest extends BackendTest {
  43 
  44     @SuppressWarnings("try")
  45     protected void testAllocation(String snippet, final int expectedRegisters, final int expectedRegRegMoves, final int expectedSpillMoves) {
  46         final StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
  47         DebugContext debug = graph.getDebug();
  48         try (DebugContext.Scope s = debug.scope("AllocatorTest", graph, graph.method(), getCodeCache())) {
  49             final RegisterStats stats = new RegisterStats(getLIRGenerationResult(graph).getLIR());
  50             try (DebugContext.Scope s2 = debug.scope("Assertions", stats.lir)) {
  51                 Assert.assertEquals("register count", expectedRegisters, stats.registers.size());
  52                 Assert.assertEquals("reg-reg moves", expectedRegRegMoves, stats.regRegMoves);
  53                 Assert.assertEquals("spill moves", expectedSpillMoves, stats.spillMoves);
  54             } catch (Throwable e) {
  55                 throw debug.handle(e);
  56             }
  57         } catch (Throwable e) {
  58             throw debug.handle(e);
  59         }
  60     }
  61 
  62     private class RegisterStats {
  63 
  64         public final LIR lir;
  65         public HashSet<Register> registers = new HashSet<>();
  66         public int regRegMoves;
  67         public int spillMoves;
  68 
  69         RegisterStats(LIR lir) {
  70             this.lir = lir;
  71 
  72             for (AbstractBlockBase<?> block : lir.codeEmittingOrder()) {
  73                 if (block == null) {
  74                     continue;
  75                 }
  76                 for (LIRInstruction instr : lir.getLIRforBlock(block)) {
  77                     collectStats(instr);
  78                 }


src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/backend/AllocatorTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File