Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor common compiler phases among different backends to drivers.common.compiler.phases package and restructure compiler utilities #304

Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
05a39f6
Refactor BoundCheckEliminationPhase to common module
mikepapadim Jan 8, 2024
80bc445
Add copyright notice to BoundCheckEliminationPhase.java
mikepapadim Jan 8, 2024
6ccce94
Refactor TornadoPartialLoopUnroll to common package
mikepapadim Jan 8, 2024
88f40c9
Refactor exception message and node checking in OCLFP64SupportPhase
mikepapadim Jan 8, 2024
8db59ed
Refactor InverseSquareRootPhase code for clarity
mikepapadim Jan 8, 2024
de1ccaa
Refactor TornadoPartialLoopUnroll class
mikepapadim Jan 8, 2024
1e3475d
Refactor PrimitiveSerialiser to use switch expression
mikepapadim Jan 8, 2024
55d92c2
Refactor instance type casting in TornadoFieldAccessFixup
mikepapadim Jan 8, 2024
15b11a3
Minor fixes in comments
mikepapadim Jan 8, 2024
d73c1bf
Refactor TornadoTaskSpecialisation with Java's pattern matching
mikepapadim Jan 9, 2024
60224db
Refactor TornadoNewArrayDevirtualizationReplacement to common location
mikepapadim Jan 9, 2024
a79c63b
Move compiler classes into 'phases' subpackage
mikepapadim Jan 10, 2024
2fb079d
Change module to open; add exports in common-exports
mikepapadim Jan 10, 2024
752b897
Refactor Tornado array replacement and type elimination
mikepapadim Jan 10, 2024
143caea
Reorder methods in TornadoPanamaPrivateMemory class
mikepapadim Jan 10, 2024
6e950ac
Refactor error handling and string formatting in TornadoSketcher class
mikepapadim Jan 10, 2024
31b9369
Refactor LoopCanonicalizer and TornadoCodeGenerator classes
mikepapadim Jan 10, 2024
ed5554a
Refactor object type casting in TornadoTaskSpecialisation
mikepapadim Jan 10, 2024
9da764d
Refactor package path for Tornado drivers
mikepapadim Jan 10, 2024
f3dd890
Relocate TornadoFieldAccessFixup and refactor its usage
mikepapadim Jan 11, 2024
2ba45ad
Relocate TornadoShapeAnalysis class to common compiler phases
mikepapadim Jan 11, 2024
887410c
Refactor TornadoOpenCLIntrinsicsReplacements for better readability a…
mikepapadim Jan 11, 2024
9f4c6be
Refactor all common compiler phases from runtime to driver.common and…
mikepapadim Jan 11, 2024
fcb5c0a
Refactor several compiler phases and update their usages
mikepapadim Jan 11, 2024
3d20bb0
Optimize several methods in TornadoApiReplacement
mikepapadim Jan 11, 2024
76fe75b
Refactor code and relocate classes in driver.common package
mikepapadim Jan 11, 2024
f1d33cb
Refactor code for setting dependencies in IntermediateTornadoGraph
mikepapadim Jan 11, 2024
70e9868
Refactor package name from 'sketch.tier' to 'sketcher'
mikepapadim Jan 11, 2024
af90555
Address PR comments and refactor switch-case statements to pattern ma…
mikepapadim Jan 11, 2024
90277ab
Refactor switch-cases to pattern matching in OCLWriteAtomicNode
mikepapadim Jan 11, 2024
86559de
Refactor switch statements in SPIRVFPBinaryIntrinsicNode.java
mikepapadim Jan 11, 2024
27aa7ec
Refactor switch-case statements to new switch expressions
mikepapadim Jan 11, 2024
07254d4
Update copyright years in various files
mikepapadim Jan 12, 2024
c45bfe8
Update copyright dates in Tornado runtime
mikepapadim Jan 12, 2024
d6fcfb7
Update copyright year in tornado runtime interfaces
mikepapadim Jan 12, 2024
d0ef84a
Fix string concatenation in TornadoSketcher
mikepapadim Jan 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@
jdk.internal.vm.compiler/org.graalvm.compiler.phases=tornado.runtime,tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.nodes.java=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.phases.tiers=tornado.runtime</arg>
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.phases.util=tornado.runtime</arg>
Expand All @@ -347,6 +350,9 @@
jdk.internal.vm.compiler/org.graalvm.compiler.core.common.spi=tornado.runtime,tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.nodes.loop=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.api.replacements=tornado.runtime
</arg>
<arg>--add-exports</arg>
Expand All @@ -363,6 +369,10 @@
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.nodes.extended=tornado.runtime</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.nodes.extended=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.nodes.loop=tornado.runtime</arg>
<arg>--add-exports</arg>
<arg>
Expand Down Expand Up @@ -399,6 +409,42 @@
jdk.internal.vm.compiler/org.graalvm.compiler.nodes.gc=tornado.runtime,tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.nodes=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.nodes.loop=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.nodes.calc=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.options=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.nodes.debug=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.nodes.util=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.nodes.virtual=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.loop.phases=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.core.common.util=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.nodes.memory.address=tornado.runtime,tornado.drivers.common
</arg>
Expand Down Expand Up @@ -501,6 +547,9 @@
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.phases.tiers=tornado.drivers.opencl
</arg>
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.phases.tiers=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.phases.util=tornado.drivers.opencl
</arg>
<arg>--add-exports</arg>
Expand All @@ -521,6 +570,10 @@
jdk.internal.vm.compiler/org.graalvm.compiler.phases.common=tornado.drivers.opencl
</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.phases.common=tornado.drivers.common
</arg>
<arg>--add-exports</arg>
<arg>
jdk.internal.vm.compiler/org.graalvm.compiler.core.common.spi=tornado.drivers.opencl
</arg>
Expand Down Expand Up @@ -1273,6 +1326,8 @@
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.options=tornado.drivers.opencl</arg>
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.options=tornado.drivers.common</arg>
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.phases=tornado.drivers.opencl</arg>
<arg>--add-exports</arg>
<arg>jdk.internal.vm.compiler/org.graalvm.compiler.phases.tiers=tornado.drivers.opencl
Expand Down
10 changes: 10 additions & 0 deletions tornado-assembly/src/etc/exportLists/common-exports
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.core.common.memory=tornado.drivers.common
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.graph=tornado.runtime,tornado.drivers.common
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.graph.iterators=tornado.drivers.common
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.nodes.java=tornado.drivers.common
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.nodes.extended=tornado.drivers.common
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.nodes.loop=tornado.drivers.common
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.nodes.calc=tornado.drivers.common
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.options=tornado.drivers.common
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.nodes.debug=tornado.drivers.common
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.nodes.util=tornado.drivers.common
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.nodes.virtual=tornado.drivers.common
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.loop.phases=tornado.drivers.common
--add-exports jdk.internal.vm.compiler/org.graalvm.compiler.core.common.util=tornado.drivers.common
13 changes: 9 additions & 4 deletions tornado-drivers/drivers-common/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
module tornado.drivers.common {
requires transitive jdk.internal.vm.compiler;
open module tornado.drivers.common {
requires transitive jdk.internal.vm.ci;
requires transitive jdk.internal.vm.compiler;
requires transitive tornado.runtime;

exports uk.ac.manchester.tornado.drivers.graal;
exports uk.ac.manchester.tornado.drivers.providers;
exports uk.ac.manchester.tornado.drivers.common;
exports uk.ac.manchester.tornado.drivers.common.architecture;
exports uk.ac.manchester.tornado.drivers.common.mm;
exports uk.ac.manchester.tornado.drivers.common.code;
exports uk.ac.manchester.tornado.drivers.common.graal.compiler;
exports uk.ac.manchester.tornado.drivers.common.logging;
exports uk.ac.manchester.tornado.drivers.common.compiler.phases.guards;
exports uk.ac.manchester.tornado.drivers.common.compiler.phases.memalloc;
exports uk.ac.manchester.tornado.drivers.common.compiler.phases.loops;
exports uk.ac.manchester.tornado.drivers.common.compiler.phases.utils;
exports uk.ac.manchester.tornado.drivers.common.compiler.phases.analysis;
exports uk.ac.manchester.tornado.drivers.common.utils;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* 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
* 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).
*
Expand All @@ -27,7 +27,7 @@
import java.util.HashMap;

import uk.ac.manchester.tornado.api.enums.TornadoVMBackendType;
import uk.ac.manchester.tornado.drivers.common.ColoursTerminal;
import uk.ac.manchester.tornado.drivers.common.utils.ColoursTerminal;
import uk.ac.manchester.tornado.runtime.TornadoAcceleratorDriver;
import uk.ac.manchester.tornado.runtime.TornadoCoreRuntime;
import uk.ac.manchester.tornado.runtime.common.TornadoOptions;
Expand All @@ -45,14 +45,6 @@
*/
public class TornadoDeviceQuery {

private static String formatSize(long v) {
if (v < 1024) {
return v + " B";
}
int z = (63 - Long.numberOfLeadingZeros(v)) / 10;
return String.format("%.1f %sB", (double) v / (1L << (z * 10)), " KMGTPE".charAt(z));
}

private static HashMap<TornadoVMBackendType, String> colourMapping;

static {
Expand All @@ -62,6 +54,14 @@ private static String formatSize(long v) {
colourMapping.put(TornadoVMBackendType.SPIRV, ColoursTerminal.PURPLE);
}

private static String formatSize(long v) {
if (v < 1024) {
return v + " B";
}
int z = (63 - Long.numberOfLeadingZeros(v)) / 10;
return String.format("%.1f %sB", (double) v / (1L << (z * 10)), " KMGTPE".charAt(z));
}

public static void main(String[] args) {

String verboseFlag = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* 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
* 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).
*
Expand All @@ -21,7 +21,7 @@
* Authors: Michalis Papadimitriou
*
*/
package uk.ac.manchester.tornado.runtime.graal.phases;
package uk.ac.manchester.tornado.drivers.common.compiler.phases.analysis;

import java.util.LinkedHashMap;
import java.util.Optional;
Expand Down Expand Up @@ -63,6 +63,14 @@

import jdk.vm.ci.meta.JavaKind;
import uk.ac.manchester.tornado.api.TornadoDeviceContext;
import uk.ac.manchester.tornado.runtime.graal.nodes.interfaces.MarkCastNode;
import uk.ac.manchester.tornado.runtime.graal.nodes.interfaces.MarkFloatingPointIntrinsicsNode;
import uk.ac.manchester.tornado.runtime.graal.nodes.interfaces.MarkGlobalThreadID;
import uk.ac.manchester.tornado.runtime.graal.nodes.interfaces.MarkIntIntrinsicNode;
import uk.ac.manchester.tornado.runtime.graal.nodes.interfaces.MarkLocalArray;
import uk.ac.manchester.tornado.runtime.graal.nodes.interfaces.MarkOCLWriteNode;
import uk.ac.manchester.tornado.runtime.graal.nodes.interfaces.MarkVectorLoad;
import uk.ac.manchester.tornado.runtime.graal.nodes.interfaces.MarkVectorValueNode;
import uk.ac.manchester.tornado.runtime.profiler.FeatureExtractionUtilities;
import uk.ac.manchester.tornado.runtime.profiler.ProfilerCodeFeatures;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
package uk.ac.manchester.tornado.runtime.graal.phases;
package uk.ac.manchester.tornado.drivers.common.compiler.phases.analysis;

import java.util.Collections;
import java.util.List;
Expand All @@ -41,6 +41,7 @@
import uk.ac.manchester.tornado.runtime.domain.IntDomain;
import uk.ac.manchester.tornado.runtime.graal.nodes.ParallelRangeNode;
import uk.ac.manchester.tornado.runtime.graal.nodes.TornadoLoopsData;
import uk.ac.manchester.tornado.runtime.graal.phases.TornadoHighTierContext;

/**
* It analyses the loop index space and determines the correct indices using
Expand Down Expand Up @@ -71,8 +72,7 @@ private int getMaxLevelNestedLoops(StructuredGraph graph) {

final List<LoopEx> loops = data.outerFirst();

for (int i = 0; i < loops.size(); i++) {
LoopEx loopEx = loops.get(i);
for (LoopEx loopEx : loops) {
LoopFragmentInside inside = loopEx.inside();
NodeBitMap nodes = inside.nodes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
package uk.ac.manchester.tornado.runtime.graal.phases;
package uk.ac.manchester.tornado.drivers.common.compiler.phases.analysis;

import static uk.ac.manchester.tornado.runtime.graal.compiler.TornadoCodeGenerator.debug;

Expand All @@ -37,6 +37,7 @@

import jdk.vm.ci.meta.ResolvedJavaField;
import uk.ac.manchester.tornado.api.internal.annotations.Vector;
import uk.ac.manchester.tornado.runtime.graal.phases.TornadoHighTierContext;

public class TornadoValueTypeReplacement extends BasePhase<TornadoHighTierContext> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, APT Group, Department of Computer Science,
* Copyright (c) 2020, 2023 APT Group, Department of Computer Science,
* School of Engineering, The University of Manchester. All rights reserved.
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
Expand All @@ -10,16 +10,15 @@
*
* 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
* 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.
*
* */
package uk.ac.manchester.tornado.drivers.opencl.graal.phases;
*/
package uk.ac.manchester.tornado.drivers.common.compiler.phases.guards;

import java.util.Optional;

Expand All @@ -36,7 +35,7 @@
* After canonicalization, we might end up with a Guard of type Bounds Check
* Exception without any array access. For those cases, we clean the graph and
* remove also the guard (deopt) node and avoid empty basic blocks before the
* OpenCL code generation.
* code generation.
*/
public class BoundCheckEliminationPhase extends Phase {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package uk.ac.manchester.tornado.runtime.graal.phases;
package uk.ac.manchester.tornado.drivers.common.compiler.phases.guards;

import java.util.Optional;

Expand All @@ -35,6 +35,8 @@
import org.graalvm.compiler.nodes.extended.GuardedNode;
import org.graalvm.compiler.phases.BasePhase;

import uk.ac.manchester.tornado.runtime.graal.phases.TornadoMidTierContext;

public class ExceptionCheckingElimination extends BasePhase<TornadoMidTierContext> {
@Override
public Optional<NotApplicable> notApplicableTo(GraphState graphState) {
Expand All @@ -47,10 +49,9 @@ public Optional<NotApplicable> notApplicableTo(GraphState graphState) {
@Override
protected void run(StructuredGraph graph, TornadoMidTierContext context) {

graph.getNodes().filter(n -> n instanceof GuardedNode).snapshot().forEach((node) -> {
graph.getNodes().filter(GuardedNode.class::isInstance).snapshot().forEach((node) -> {
GuardedNode guardedNode = (GuardedNode) node;
if (guardedNode.getGuard() instanceof GuardNode) {
GuardNode guard = (GuardNode) guardedNode.getGuard();
if (guardedNode.getGuard() instanceof GuardNode guard) {

LogicNode condition = guard.getCondition();

Expand All @@ -64,13 +65,10 @@ protected void run(StructuredGraph graph, TornadoMidTierContext context) {
}

} else if (condition instanceof IntegerBelowNode) {

ValueNode x = ((IntegerBelowNode) condition).getX();
condition.replaceFirstInput(x, graph.addOrUnique(ConstantNode.forInt(Integer.MAX_VALUE)));
}
}

});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
package uk.ac.manchester.tornado.runtime.graal.phases;
package uk.ac.manchester.tornado.drivers.common.compiler.phases.guards;

import java.util.HashSet;
import java.util.Optional;
Expand All @@ -33,6 +33,8 @@
import org.graalvm.compiler.nodes.extended.ValueAnchorNode;
import org.graalvm.compiler.phases.BasePhase;

import uk.ac.manchester.tornado.runtime.graal.phases.TornadoHighTierContext;

public class ExceptionSuppression extends BasePhase<TornadoHighTierContext> {
@Override
public Optional<NotApplicable> notApplicableTo(GraphState graphState) {
Expand All @@ -45,10 +47,9 @@ protected void run(StructuredGraph graph, TornadoHighTierContext context) {
Set<LogicNode> conditions = new HashSet<>();
Set<GuardNode> guards = new HashSet<>();

graph.getNodes().filter(n -> n instanceof GuardedNode).forEach((node) -> {
graph.getNodes().filter(GuardedNode.class::isInstance).forEach(node -> {
GuardedNode guardedNode = (GuardedNode) node;
if (guardedNode.getGuard() instanceof GuardNode) {
GuardNode guard = (GuardNode) guardedNode.getGuard();
if (guardedNode.getGuard() instanceof GuardNode guard) {
LogicNode condition = guard.getCondition();

conditions.add(condition);
Expand All @@ -59,8 +60,7 @@ protected void run(StructuredGraph graph, TornadoHighTierContext context) {
});

graph.getNodes().filter(ValueAnchorNode.class).forEach(anchor -> {
if (anchor.getAnchoredNode() instanceof GuardNode) {
final GuardNode guard = (GuardNode) anchor.getAnchoredNode();
if (anchor.getAnchoredNode() instanceof GuardNode guard) {
guards.add(guard);
conditions.add(guard.getCondition());
anchor.removeAnchoredNode();
Expand Down
Loading