From fadb5ea79f6c058b1c222f7898ff6d8b91ba24eb Mon Sep 17 00:00:00 2001 From: MaryXek Date: Wed, 26 Jun 2024 14:22:55 +0300 Subject: [PATCH] Minor refactoring to use pattern matching --- .../drivers/opencl/graal/lir/OCLKind.java | 52 +++++++------------ .../drivers/ptx/graal/lir/PTXKind.java | 26 ++++------ .../ptx/graal/nodes/FixedArrayCopyNode.java | 22 +++----- 3 files changed, 37 insertions(+), 63 deletions(-) diff --git a/tornado-drivers/opencl/src/main/java/uk/ac/manchester/tornado/drivers/opencl/graal/lir/OCLKind.java b/tornado-drivers/opencl/src/main/java/uk/ac/manchester/tornado/drivers/opencl/graal/lir/OCLKind.java index 770ea3ce78..b9c2d9a7ca 100644 --- a/tornado-drivers/opencl/src/main/java/uk/ac/manchester/tornado/drivers/opencl/graal/lir/OCLKind.java +++ b/tornado-drivers/opencl/src/main/java/uk/ac/manchester/tornado/drivers/opencl/graal/lir/OCLKind.java @@ -257,41 +257,29 @@ public static OCLAssembler.OCLBinaryTemplate resolvePrivateTemplateType(JavaKind } public static OCLAssembler.OCLBinaryTemplate resolvePrivatePointerTemplate(JavaKind type) { - if (type == JavaKind.Int) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_INT_ARRAY_PTR; - } else if (type == JavaKind.Double) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_DOUBLE_ARRAY_PTR; - } else if (type == JavaKind.Float) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_FLOAT_ARRAY_PTR; - } else if (type == JavaKind.Short) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_SHORT_ARRAY_PTR; - } else if (type == JavaKind.Long) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_LONG_ARRAY_PTR; - } else if (type == JavaKind.Char) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_CHAR_ARRAY_PTR; - } else if (type == JavaKind.Byte) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_BYTE_ARRAY_PTR; - } - return null; + return switch (type) { + case Int -> OCLAssembler.OCLBinaryTemplate.PRIVATE_INT_ARRAY_PTR; + case Double -> OCLAssembler.OCLBinaryTemplate.PRIVATE_DOUBLE_ARRAY_PTR; + case Float -> OCLAssembler.OCLBinaryTemplate.PRIVATE_FLOAT_ARRAY_PTR; + case Short -> OCLAssembler.OCLBinaryTemplate.PRIVATE_SHORT_ARRAY_PTR; + case Long -> OCLAssembler.OCLBinaryTemplate.PRIVATE_LONG_ARRAY_PTR; + case Char -> OCLAssembler.OCLBinaryTemplate.PRIVATE_CHAR_ARRAY_PTR; + case Byte -> OCLAssembler.OCLBinaryTemplate.PRIVATE_BYTE_ARRAY_PTR; + default -> null; + }; } public static OCLAssembler.OCLBinaryTemplate resolvePrivatePointerCopyTemplate(JavaKind type) { - if (type == JavaKind.Int) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_INT_ARRAY_PTR_COPY; - } else if (type == JavaKind.Double) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_DOUBLE_ARRAY_PTR_COPY; - } else if (type == JavaKind.Float) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_FLOAT_ARRAY_PTR_COPY; - } else if (type == JavaKind.Short) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_SHORT_ARRAY_PTR_COPY; - } else if (type == JavaKind.Long) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_LONG_ARRAY_PTR_COPY; - } else if (type == JavaKind.Char) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_CHAR_ARRAY_PTR_COPY; - } else if (type == JavaKind.Byte) { - return OCLAssembler.OCLBinaryTemplate.PRIVATE_BYTE_ARRAY_PTR_COPY; - } - return null; + return switch (type) { + case Int -> OCLAssembler.OCLBinaryTemplate.PRIVATE_INT_ARRAY_PTR_COPY; + case Double -> OCLAssembler.OCLBinaryTemplate.PRIVATE_DOUBLE_ARRAY_PTR_COPY; + case Float -> OCLAssembler.OCLBinaryTemplate.PRIVATE_FLOAT_ARRAY_PTR_COPY; + case Short -> OCLAssembler.OCLBinaryTemplate.PRIVATE_SHORT_ARRAY_PTR_COPY; + case Long -> OCLAssembler.OCLBinaryTemplate.PRIVATE_LONG_ARRAY_PTR_COPY; + case Char -> OCLAssembler.OCLBinaryTemplate.PRIVATE_CHAR_ARRAY_PTR_COPY; + case Byte -> OCLAssembler.OCLBinaryTemplate.PRIVATE_BYTE_ARRAY_PTR_COPY; + default -> null; + }; } public static OCLAssembler.OCLBinaryTemplate resolveTemplateType(JavaKind type) { diff --git a/tornado-drivers/ptx/src/main/java/uk/ac/manchester/tornado/drivers/ptx/graal/lir/PTXKind.java b/tornado-drivers/ptx/src/main/java/uk/ac/manchester/tornado/drivers/ptx/graal/lir/PTXKind.java index dd1d26ac08..414827af0d 100644 --- a/tornado-drivers/ptx/src/main/java/uk/ac/manchester/tornado/drivers/ptx/graal/lir/PTXKind.java +++ b/tornado-drivers/ptx/src/main/java/uk/ac/manchester/tornado/drivers/ptx/graal/lir/PTXKind.java @@ -255,22 +255,16 @@ public static PTXAssembler.PTXBinaryTemplate resolvePrivatePointerCopyTemplate(R } public static PTXAssembler.PTXBinaryTemplate resolvePrivatePointerCopyTemplate(JavaKind type) { - if (type == JavaKind.Int) { - return PTXAssembler.PTXBinaryTemplate.LOCAL_INT_ARRAY_PTR_COPY; - } else if (type == JavaKind.Double) { - return PTXAssembler.PTXBinaryTemplate.LOCAL_DOUBLE_ARRAY_PTR_COPY; - } else if (type == JavaKind.Float) { - return PTXAssembler.PTXBinaryTemplate.LOCAL_FLOAT_ARRAY_PTR_COPY; - } else if (type == JavaKind.Short) { - return PTXAssembler.PTXBinaryTemplate.LOCAL_SHORT_ARRAY_PTR_COPY; - } else if (type == JavaKind.Long) { - return PTXAssembler.PTXBinaryTemplate.LOCAL_LONG_ARRAY_PTR_COPY; - } else if (type == JavaKind.Char) { - return PTXAssembler.PTXBinaryTemplate.LOCAL_CHAR_ARRAY_PTR_COPY; - } else if (type == JavaKind.Byte) { - return PTXAssembler.PTXBinaryTemplate.LOCAL_BYTE_ARRAY_PTR_COPY; - } - return null; + return switch (type) { + case Int -> PTXAssembler.PTXBinaryTemplate.LOCAL_INT_ARRAY_PTR_COPY; + case Double -> PTXAssembler.PTXBinaryTemplate.LOCAL_DOUBLE_ARRAY_PTR_COPY; + case Float -> PTXAssembler.PTXBinaryTemplate.LOCAL_FLOAT_ARRAY_PTR_COPY; + case Short -> PTXAssembler.PTXBinaryTemplate.LOCAL_SHORT_ARRAY_PTR_COPY; + case Long -> PTXAssembler.PTXBinaryTemplate.LOCAL_LONG_ARRAY_PTR_COPY; + case Char -> PTXAssembler.PTXBinaryTemplate.LOCAL_CHAR_ARRAY_PTR_COPY; + case Byte -> PTXAssembler.PTXBinaryTemplate.LOCAL_BYTE_ARRAY_PTR_COPY; + default -> null; + }; } public static PTXKind resolveToVectorKind(ResolvedJavaType type) { diff --git a/tornado-drivers/ptx/src/main/java/uk/ac/manchester/tornado/drivers/ptx/graal/nodes/FixedArrayCopyNode.java b/tornado-drivers/ptx/src/main/java/uk/ac/manchester/tornado/drivers/ptx/graal/nodes/FixedArrayCopyNode.java index e0d85bee5d..54780d0e1e 100644 --- a/tornado-drivers/ptx/src/main/java/uk/ac/manchester/tornado/drivers/ptx/graal/nodes/FixedArrayCopyNode.java +++ b/tornado-drivers/ptx/src/main/java/uk/ac/manchester/tornado/drivers/ptx/graal/nodes/FixedArrayCopyNode.java @@ -75,21 +75,13 @@ public PTXArchitecture.PTXMemoryBase getMemoryRegister() { private int getOffset() { PTXKind kind = PTXKind.fromResolvedJavaType(elementType); - switch (kind) { - case F64: - case S64: - return 8; - case F32: - case S32: - return 4; - case S16: - return 2; - case U16: - case S8: - return 1; - default: - return -1; - } + return switch (kind) { + case F64, S64 -> 8; + case F32, S32 -> 4; + case S16 -> 2; + case U16, S8 -> 1; + default -> -1; + }; } @Override