Skip to content

Commit 5911f97

Browse files
committed
[skip-ci] Initial version of intrinsic call extension
1 parent 4c83001 commit 5911f97

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

src/psyclone/psyir/nodes/intrinsic_call.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def _get_first_argument_type(node) -> DataType:
8484
'''
8585
return node.arguments[0].datatype
8686

87+
8788
# Anyone using this?
8889
def _get_first_argument_type_with_optional_kind(node) -> DataType:
8990
'''Helper function for the common IntrinsicCall case where the
@@ -103,6 +104,7 @@ def _get_first_argument_type_with_optional_kind(node) -> DataType:
103104
return_type._precision = kind
104105
return return_type
105106

107+
106108
def _get_first_argument_logical_kind_with_optional_dim(node) -> DataType:
107109
'''Helper function for the common IntrinsicCall case where the
108110
return type is a Scalar logical with the kind of the first argument,
@@ -248,7 +250,7 @@ class Intrinsic(IAttr, Enum):
248250
ScalarType.Intrinsic.REAL,
249251
(node.arguments[node.argument_names.index("kind")]
250252
if "kind" not in node.argument_names else
251-
arguments[0].datatype.precision))
253+
node.arguments[0].datatype.precision))
252254
), None)
253255
ANY = IAttr(
254256
'ANY', True, False, False,
@@ -846,7 +848,8 @@ class Intrinsic(IAttr, Enum):
846848
ArgDesc(1, 1, DataNode), {}, None, None)
847849
PRODUCT = IAttr(
848850
'PRODUCT', True, False, False,
849-
ArgDesc(1, 1, DataNode), {"dim": DataNode, "mask": DataNode}, None, None)
851+
ArgDesc(1, 1, DataNode), {"dim": DataNode, "mask": DataNode},
852+
None, None)
850853
RADIX = IAttr(
851854
'RADIX', True, False, True,
852855
ArgDesc(1, 1, DataNode), {}, None, None)
@@ -872,13 +875,15 @@ class Intrinsic(IAttr, Enum):
872875
REDUCE = IAttr(
873876
'REDUCE', True, False, False,
874877
ArgDesc(2, 3, Reference),
875-
{"mask": DataNode, "identity": DataNode, "ordered": DataNode}, None, None)
878+
{"mask": DataNode, "identity": DataNode, "ordered": DataNode},
879+
None, None)
876880
REPEAT = IAttr(
877881
'REPEAT', True, False, False,
878882
ArgDesc(2, 2, Reference), {}, None, None)
879883
RESHAPE = IAttr(
880884
'RESHAPE', True, False, False,
881-
ArgDesc(2, 2, Reference), {"pad": DataNode, "order": DataNode}, None, None)
885+
ArgDesc(2, 2, Reference), {"pad": DataNode, "order": DataNode},
886+
None, None)
882887
RRSPACING = IAttr(
883888
'RRSPACING', True, True, False,
884889
ArgDesc(1, 1, Reference), {}, None, None)
@@ -890,7 +895,8 @@ class Intrinsic(IAttr, Enum):
890895
ArgDesc(2, 2, Reference), {}, None, None)
891896
SCAN = IAttr(
892897
'SCAN', True, True, False,
893-
ArgDesc(2, 2, Reference), {"back": DataNode, "kind": DataNode}, None, None)
898+
ArgDesc(2, 2, Reference), {"back": DataNode, "kind": DataNode},
899+
None, None)
894900
SELECTED_CHAR_KIND = IAttr(
895901
'SELECTED_CHAR_KIND', True, False, False,
896902
ArgDesc(1, 1, Reference), {}, None, None)
@@ -927,7 +933,8 @@ class Intrinsic(IAttr, Enum):
927933
ArgDesc(1, 1, DataNode), {}, None, None)
928934
SIZE = IAttr(
929935
'SIZE', True, False, True,
930-
ArgDesc(1, 1, DataNode), {"dim": DataNode, "kind": DataNode}, None, None)
936+
ArgDesc(1, 1, DataNode), {"dim": DataNode, "kind": DataNode},
937+
None, None)
931938
SPACING = IAttr(
932939
'SPACING', True, True, False,
933940
ArgDesc(1, 1, DataNode), {}, None, None)
@@ -939,17 +946,20 @@ class Intrinsic(IAttr, Enum):
939946
ArgDesc(1, 1, DataNode), {}, None, None)
940947
STOPPED_IMAGES = IAttr(
941948
'STOPPED_IMAGES', False, False, False,
942-
ArgDesc(0, 0, DataNode), {"team": DataNode, "kind": DataNode}, None, None)
949+
ArgDesc(0, 0, DataNode), {"team": DataNode, "kind": DataNode},
950+
None, None)
943951
STORAGE_SIZE = IAttr(
944952
'STORAGE_SIZE', True, False, True,
945953
ArgDesc(1, 1, DataNode), {"kind": DataNode}, None, None)
946954
SUM = IAttr(
947955
'SUM', True, False, False,
948-
ArgDesc(1, 1, DataNode), {"dim": DataNode, "mask": DataNode}, None, None)
956+
ArgDesc(1, 1, DataNode), {"dim": DataNode, "mask": DataNode},
957+
None, None)
949958
SYSTEM_CLOCK = IAttr(
950959
'SYSTEM_CLOCK', False, False, False,
951960
ArgDesc(0, 0, DataNode),
952-
{"count": DataNode, "count_rate": DataNode, "count_max": DataNode}, None, None)
961+
{"count": DataNode, "count_rate": DataNode, "count_max": DataNode},
962+
None, None)
953963
TAN = IAttr(
954964
'TAN', True, True, False,
955965
ArgDesc(1, 1, DataNode), {}, None, None)
@@ -962,7 +972,8 @@ class Intrinsic(IAttr, Enum):
962972
THIS_IMAGE = IAttr(
963973
'THIS_IMAGE', True, False, False,
964974
ArgDesc(0, 0, DataNode),
965-
{"coarray": DataNode, "team": DataNode, "dim": DataNode}, None, None)
975+
{"coarray": DataNode, "team": DataNode, "dim": DataNode},
976+
None, None)
966977
TINY = IAttr(
967978
'TINY', True, False, True,
968979
ArgDesc(1, 1, (Reference, Literal)), {}, None, None)
@@ -980,16 +991,19 @@ class Intrinsic(IAttr, Enum):
980991
ArgDesc(1, 1, DataNode), {}, None, None)
981992
UBOUND = IAttr(
982993
'UBOUND', True, False, True,
983-
ArgDesc(1, 1, DataNode), {"dim": DataNode, "kind": DataNode}, None, None)
994+
ArgDesc(1, 1, DataNode), {"dim": DataNode, "kind": DataNode},
995+
None, None)
984996
UCOBOUND = IAttr(
985997
'UCOBOUND', True, False, True,
986-
ArgDesc(1, 1, DataNode), {"dim": DataNode, "kind": DataNode}, None, None)
998+
ArgDesc(1, 1, DataNode), {"dim": DataNode, "kind": DataNode},
999+
None, None)
9871000
UNPACK = IAttr(
9881001
'UNPACK', True, False, False,
9891002
ArgDesc(3, 3, DataNode), {}, None, None)
9901003
VERIFY = IAttr(
9911004
'VERIFY', True, True, False,
992-
ArgDesc(2, 2, DataNode), {"back": DataNode, "kind": DataNode}, None, None)
1005+
ArgDesc(2, 2, DataNode), {"back": DataNode, "kind": DataNode},
1006+
None, None)
9931007

9941008
def __hash__(self):
9951009
return hash(self.name)

src/psyclone/tests/psyir/nodes/intrinsic_call_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def test_get_first_argument_logical_kind_with_optional_dim(fortran_reader):
629629
end subroutine x""",
630630
# AIMAG return type is UnresolvedType
631631
lambda res: isinstance(res, UnresolvedType)
632-
),
632+
),
633633
("""subroutine z
634634
real*4 :: x
635635
real :: y
@@ -638,7 +638,7 @@ def test_get_first_argument_logical_kind_with_optional_dim(fortran_reader):
638638
# AINT return type is that of x here.
639639
lambda res: (res.intrinsic == ScalarType.Intrinsic.REAL and
640640
res.precision == 4)
641-
),
641+
),
642642
("""subroutine z
643643
real*4 :: x
644644
real*8 :: y
@@ -648,7 +648,7 @@ def test_get_first_argument_logical_kind_with_optional_dim(fortran_reader):
648648
lambda res: (res.intrinsic == ScalarType.Intrinsic.REAL and
649649
isinstance(res.precision, Literal) and
650650
res.precision.value == "8")
651-
),
651+
),
652652
])
653653
def test_specific_return_types(fortran_reader, code, expected):
654654
''' Test the specific return types of each IntrinsicCall that has its own

0 commit comments

Comments
 (0)