From 1baa78c6125f5495a9168b175c8ace8aa57c8eb5 Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Wed, 23 Oct 2024 15:14:55 +0100 Subject: [PATCH 1/3] #2717: Add Assignment.is_literal_assignment --- src/psyclone/psyir/nodes/assignment.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/psyclone/psyir/nodes/assignment.py b/src/psyclone/psyir/nodes/assignment.py index 3aca28e0b7..22c843b9f6 100644 --- a/src/psyclone/psyir/nodes/assignment.py +++ b/src/psyclone/psyir/nodes/assignment.py @@ -34,6 +34,7 @@ # Authors R. W. Ford, A. R. Porter, S. Siso and N. Nobre, STFC Daresbury Lab # I. Kavcic, Met Office # J. Henrichs, Bureau of Meteorology +# J. G. Wallwork, University of Cambridge # ----------------------------------------------------------------------------- ''' This module contains the Assignment node implementation.''' @@ -41,6 +42,7 @@ from psyclone.core import VariablesAccessInfo from psyclone.errors import InternalError from psyclone.f2pygen import PSyIRGen +from psyclone.psyir.nodes.literal import Literal from psyclone.psyir.nodes.array_reference import ArrayReference from psyclone.psyir.nodes.datanode import DataNode from psyclone.psyir.nodes.intrinsic_call import ( @@ -244,6 +246,16 @@ def is_array_assignment(self): return True return False + @property + def is_literal_assignment(self): + ''' + returns: True if the rhs of the assignment is a literal value and False + otherwise. + rtype: bool + + ''' + return isinstance(self.rhs, Literal) + def gen_code(self, parent): '''F2pygen code generation of an Assignment. From e14ab2a820e751cf98de36dc2df2571e9ce52d6b Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Wed, 23 Oct 2024 15:21:25 +0100 Subject: [PATCH 2/3] #2717: Use is_literal_assignment in tests --- src/psyclone/tests/psyir/nodes/assignment_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/psyclone/tests/psyir/nodes/assignment_test.py b/src/psyclone/tests/psyir/nodes/assignment_test.py index 3e2d13e4d5..b610fd3b43 100644 --- a/src/psyclone/tests/psyir/nodes/assignment_test.py +++ b/src/psyclone/tests/psyir/nodes/assignment_test.py @@ -34,6 +34,7 @@ # Authors R. W. Ford, A. R. Porter and S. Siso, STFC Daresbury Lab # I. Kavcic, Met Office # J. Henrichs, Bureau of Meteorology +# J. G. Wallwork, University of Cambridge # ----------------------------------------------------------------------------- ''' Performs py.test tests on the Assignment PSyIR node. ''' @@ -100,6 +101,7 @@ def test_assignment_create(): lhs = Reference(DataSymbol("tmp", REAL_SINGLE_TYPE)) rhs = Literal("0.0", REAL_SINGLE_TYPE) assignment = Assignment.create(lhs, rhs) + assert assignment.is_literal_assignment check_links(assignment, [lhs, rhs]) result = FortranWriter().assignment_node(assignment) assert result == "tmp = 0.0\n" @@ -150,6 +152,7 @@ def test_is_array_assignment(): array_ref = ArrayReference.create(symbol, [x_range, int_one.copy()]) assignment = Assignment.create(array_ref, one.copy()) assert assignment.is_array_assignment is True + assert assignment.is_literal_assignment # Check when lhs consists of various forms of structure access grid_type = StructureType.create([ @@ -349,8 +352,11 @@ def test_pointer_assignment(): assignment1 = Assignment(is_pointer=True) assignment1.addchild(lhs.copy()) assignment1.addchild(rhs.copy()) + assert not assignment1.is_literal_assignment assignment2 = Assignment.create(lhs, rhs, is_pointer=True) + assert not assignment2.is_literal_assignment not_pointer = Assignment.create(lhs.copy(), rhs.copy()) + assert not not_pointer.is_literal_assignment # Getters, equality and copy assert assignment1.is_pointer From b427b737ce0336cabc8b76723e6cc55169d173c6 Mon Sep 17 00:00:00 2001 From: Sergi Siso Date: Thu, 24 Oct 2024 09:28:15 +0100 Subject: [PATCH 3/3] #2752 Update changelog --- changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog b/changelog index 8c711bca1d..21666b17d3 100644 --- a/changelog +++ b/changelog @@ -250,6 +250,8 @@ 86) PR #2707 for #257. Fixes bugs in the loop-fusion transformation. + 87) PR #2752 towards #2717. Adds Assignment.is_literal_assignment property. + release 2.5.0 14th of February 2024 1) PR #2199 for #2189. Fix bugs with missing maps in enter data