changeset 13225:f83540edfcd4

removed PTXTargetMethodAssembler
author Doug Simon <doug.simon@oracle.com>
date Tue, 03 Dec 2013 10:06:09 +0100
parents 7086a2fe7370
children 0b4d38339708
files graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTestBase.java graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXTargetMethodAssembler.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/TargetMethodAssembler.java
diffstat 5 files changed, 33 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTestBase.java	Tue Dec 03 09:48:22 2013 +0100
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTestBase.java	Tue Dec 03 10:06:09 2013 +0100
@@ -29,11 +29,13 @@
 
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.code.CallingConvention.Type;
+import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.*;
-import com.oracle.graal.compiler.ptx.*;
 import com.oracle.graal.compiler.target.*;
 import com.oracle.graal.compiler.test.*;
 import com.oracle.graal.debug.*;
+import com.oracle.graal.hotspot.*;
+import com.oracle.graal.hotspot.bridge.*;
 import com.oracle.graal.hotspot.meta.*;
 import com.oracle.graal.hotspot.ptx.*;
 import com.oracle.graal.java.*;
@@ -57,6 +59,12 @@
         super(PTX.class);
     }
 
+    private static CompilerToGPU toGPU = HotSpotGraalRuntime.runtime().getCompilerToGPU();
+
+    private static boolean validDevice = toGPU.deviceInit();
+
+    private static final int totalProcessors = (validDevice ? toGPU.availableProcessors() : 0);
+
     protected CompilationResult compile(String test) {
         if (getBackend() instanceof PTXHotSpotBackend) {
             StructuredGraph graph = parse(test);
@@ -80,8 +88,20 @@
              * GPU fallback to CPU in cases of ECC failure on kernel invocation.
              */
             Suites suites = Suites.createDefaultSuites();
-            CompilationResult result = GraalCompiler.compileGraph(graph, cc, graph.method(), getProviders(), ptxBackend, target, null, phasePlan, OptimisticOptimizations.NONE, new SpeculationLog(),
-                            suites, new ExternalCompilationResult());
+            ExternalCompilationResult result = GraalCompiler.compileGraph(graph, cc, graph.method(), getProviders(), ptxBackend, target, null, phasePlan, OptimisticOptimizations.NONE,
+                            new SpeculationLog(), suites, new ExternalCompilationResult());
+
+            ResolvedJavaMethod method = graph.method();
+
+            try {
+                if ((validDevice) && (result.getTargetCode() != null)) {
+                    long kernel = toGPU.generateKernel(result.getTargetCode(), method.getName());
+                    result.setEntryPoint(kernel);
+                }
+            } catch (Throwable th) {
+                th.printStackTrace();
+            }
+
             return result;
         } else {
             return null;
@@ -143,7 +163,7 @@
                  * for now assert that the warp array block is no larger than the number of physical
                  * gpu cores.
                  */
-                assert dimensionX * dimensionY * dimensionZ < PTXTargetMethodAssembler.getAvailableProcessors();
+                assert dimensionX * dimensionY * dimensionZ < totalProcessors;
 
                 r = ((HotSpotNmethod) installedCode).executeParallel(dimensionX, dimensionY, dimensionZ, executeArgs);
             } else {
--- a/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXTargetMethodAssembler.java	Tue Dec 03 09:48:22 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.compiler.ptx;
-
-import com.oracle.graal.api.code.*;
-import com.oracle.graal.api.meta.*;
-import com.oracle.graal.asm.*;
-import com.oracle.graal.hotspot.*;
-import com.oracle.graal.hotspot.bridge.*;
-import com.oracle.graal.lir.*;
-import com.oracle.graal.lir.asm.*;
-import com.oracle.graal.nodes.*;
-
-public class PTXTargetMethodAssembler extends TargetMethodAssembler {
-
-    private static CompilerToGPU toGPU = HotSpotGraalRuntime.runtime().getCompilerToGPU();
-
-    private static boolean validDevice = toGPU.deviceInit();
-
-    private static final int totalProcessors = (validDevice ? toGPU.availableProcessors() : 0);
-
-    public static int getAvailableProcessors() {
-        return totalProcessors;
-    }
-
-    // detach ??
-
-    public PTXTargetMethodAssembler(CodeCacheProvider codeCache, ForeignCallsProvider foreignCalls, FrameMap frameMap, AbstractAssembler asm, FrameContext frameContext,
-                    ExternalCompilationResult compilationResult) {
-        super(codeCache, foreignCalls, frameMap, asm, frameContext, compilationResult);
-    }
-
-    @Override
-    public void finalize(StructuredGraph graph) {
-        ResolvedJavaMethod method = graph.method();
-        assert method != null : graph + " is not associated wth a method";
-        super.finalize(graph);
-        ExternalCompilationResult result = (ExternalCompilationResult) compilationResult;
-
-        try {
-            if ((validDevice) && (result.getTargetCode() != null)) {
-                long kernel = toGPU.generateKernel(result.getTargetCode(), method.getName());
-                result.setEntryPoint(kernel);
-            }
-        } catch (Throwable th) {
-            th.printStackTrace();
-        }
-    }
-}
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java	Tue Dec 03 09:48:22 2013 +0100
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java	Tue Dec 03 10:06:09 2013 +0100
@@ -282,7 +282,7 @@
     public static void emitCode(Backend backend, long[] leafGraphIds, Assumptions assumptions, LIRGenerator lirGen, CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner) {
         TargetMethodAssembler tasm = backend.newAssembler(lirGen, compilationResult);
         backend.emitCode(tasm, lirGen, installedCodeOwner);
-        tasm.finalize(lirGen.getGraph());
+        tasm.finish();
         if (!assumptions.isEmpty()) {
             compilationResult.setAssumptions(assumptions);
         }
--- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java	Tue Dec 03 09:48:22 2013 +0100
+++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java	Tue Dec 03 10:06:09 2013 +0100
@@ -176,7 +176,7 @@
         FrameMap frameMap = lirGen.frameMap;
         AbstractAssembler masm = createAssembler(frameMap);
         PTXFrameContext frameContext = new PTXFrameContext();
-        TargetMethodAssembler tasm = new PTXTargetMethodAssembler(getCodeCache(), getForeignCalls(), frameMap, masm, frameContext, (ExternalCompilationResult) compilationResult);
+        TargetMethodAssembler tasm = new TargetMethodAssembler(getCodeCache(), getForeignCalls(), frameMap, masm, frameContext, compilationResult);
         tasm.setFrameSize(0);
         return tasm;
     }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/TargetMethodAssembler.java	Tue Dec 03 09:48:22 2013 +0100
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/TargetMethodAssembler.java	Tue Dec 03 10:06:09 2013 +0100
@@ -27,13 +27,12 @@
 import java.util.*;
 
 import com.oracle.graal.api.code.*;
-import com.oracle.graal.api.code.CompilationResult.*;
+import com.oracle.graal.api.code.CompilationResult.DataPatch;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.asm.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.lir.*;
-import com.oracle.graal.nodes.*;
 
 public class TargetMethodAssembler {
 
@@ -92,7 +91,12 @@
         compilationResult.addAnnotation(new CompilationResult.CodeComment(asm.codeBuffer.position(), s));
     }
 
-    public void finalize(StructuredGraph graph) {
+    /**
+     * Sets the {@linkplain CompilationResult#setTargetCode(byte[], int) code} and
+     * {@linkplain CompilationResult#recordExceptionHandler(int, int) exception handler} fields of
+     * the compilation result.
+     */
+    public void finish() {
         // Install code, data and frame size
         compilationResult.setTargetCode(asm.codeBuffer.close(false), asm.codeBuffer.position());
 
@@ -126,7 +130,6 @@
             Debug.metric("DataPatches").add(ldp.size());
             Debug.metric("ExceptionHandlersEmitted").add(compilationResult.getExceptionHandlers().size());
         }
-        Debug.log("Finished compiling %s", graph);
     }
 
     public void recordExceptionHandlers(int pcOffset, LIRFrameState info) {