Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def apply(self, node, options=None):
start_expr = "1"
psyir = fortran_reader.psyir_from_expression(
start_expr, node.symbol_table)
loop.children[0].replace_with(psyir)
loop.start_expr.replace_with(psyir)

# Set the upper bound
stop_expr = bounds["stop"].format(start='2', stop=stop)
Expand All @@ -262,4 +262,4 @@ def apply(self, node, options=None):
stop_expr = "1"
psyir = fortran_reader.psyir_from_expression(
stop_expr, node.symbol_table)
loop.children[1].replace_with(psyir)
loop.stop_expr.replace_with(psyir)
34 changes: 31 additions & 3 deletions src/psyclone/domain/lfric/lfric_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'''

from psyclone.configuration import Config
from psyclone.core import AccessType
from psyclone.core import AccessType, VariablesAccessMap, Signature
from psyclone.domain.common.psylayer import PSyLoop
from psyclone.domain.lfric import LFRicConstants
from psyclone.domain.lfric.lfric_kern import LFRicKern
Expand Down Expand Up @@ -116,6 +116,8 @@ def __init__(self, loop_type="", **kwargs):
self.variable = ischedule.symbol_table.find_or_create_tag(
tag, root_name=suggested_name, symbol_type=DataSymbol,
datatype=LFRicTypes("LFRicIntegerScalarDataType")())
else:
self.variable = DataSymbol("null", ScalarType.integer_type())

# The loop bounds names are given by the number of previous LFRic loops
# already present in the Schedule. Since this are inserted in order it
Expand Down Expand Up @@ -185,11 +187,11 @@ def lower_to_language_level(self):
child.lower_to_language_level()

# Finally create the new lowered Loop and replace the domain one
loop = Loop.create(self._variable, start, stop, step, [])
loop = Loop.create(self.variable, start, stop, step, [])
loop.preceding_comment = self.preceding_comment
loop.loop_body._symbol_table = \
self.loop_body.symbol_table.shallow_copy()
loop.children[3] = self.loop_body.copy()
loop.children[4] = self.loop_body.copy()
self.replace_with(loop)
lowered_node = loop
else:
Expand Down Expand Up @@ -1104,6 +1106,32 @@ def independent_iterations(self,
raise InternalError(f"independent_iterations: loop of type "
f"'{self.loop_type}' is not supported.")

def reference_accesses(self) -> VariablesAccessMap:
'''
:returns: a map of all the symbol accessed inside this node, the
keys are Signatures (unique identifiers to a symbol and its
structure accessors) and the values are AccessSequence
(a sequence of AccessTypes).

'''
var_accesses = VariablesAccessMap()

if self.variable.name != "null":
var_accesses.add_access(Signature(self.variable.name),
AccessType.WRITE, self)
# This re
Comment thread
LonelyCat124 marked this conversation as resolved.
Outdated
var_accesses.add_access(Signature(self.variable.name),
AccessType.READ, self)
var_accesses.update(self.start_expr.reference_accesses())
var_accesses.update(self.stop_expr.reference_accesses())
var_accesses.update(self.step_expr.reference_accesses())

# LFRic loops ignore the loop variable reference and loop bounds
# because it has placeholders until the DSL loop is lowered.
for child in self.loop_body.children:
var_accesses.update(child.reference_accesses())
return var_accesses


# ---------- Documentation utils -------------------------------------------- #
# The list of module members that we wish AutoAPI to generate
Expand Down
6 changes: 3 additions & 3 deletions src/psyclone/domain/lfric/lfric_loop_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def initialise(self, cursor: int) -> int:
assignment = Assignment.create(
lhs=Reference(lbound),
rhs=loop.lower_bound_psyir())
loop.children[0] = Reference(lbound)
loop.start_expr = Reference(lbound)
self._invoke.schedule.addchild(assignment, cursor)
cursor += 1
if first:
Expand All @@ -99,10 +99,10 @@ def initialise(self, cursor: int) -> int:
rhs=loop.upper_bound_psyir()
), cursor)
cursor += 1
loop.children[1] = Reference(ubound)
loop.stop_expr = Reference(ubound)
else:
# If it needs a color look-up, it has to be in-place
loop.children[1] = loop.upper_bound_psyir()
loop.stop_expr = loop.upper_bound_psyir()

return cursor

Expand Down
2 changes: 1 addition & 1 deletion src/psyclone/psyad/adjoint_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def loop_node(self, node):
new_node.step_expr = negate_expr(new_node.step_expr.copy())

# Determine the adjoint of the loop body
new_node.children[3] = self._visit(node.children[3])
new_node.children[4] = self._visit(node.loop_body)
return new_node

def ifblock_node(self, node):
Expand Down
7 changes: 6 additions & 1 deletion src/psyclone/psyir/nodes/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,17 @@ def create_data_movement_deep_copy_refs(self):
for sig in var_info.all_signatures:
vinfo = var_info[sig]
node = vinfo[0].node
sym = table.lookup(sig.var_name)

sym = table.lookup(sig.var_name, otherwise=None)

if not vinfo.has_data_access():
# Ignore references that don't correspond to data accesses.
continue

if not sym:
# Ignore signatures without a corresponding symbol
continue

if isinstance(sym.datatype, ScalarType):
# We ignore scalars as these are typically copied by value.
continue
Expand Down
2 changes: 1 addition & 1 deletion src/psyclone/psyir/nodes/dynamic_omp_task_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,7 @@ def _evaluate_loop(
# Finished handling the loop bounds now

# Recurse to the children
for child_node in node.children[3].children:
for child_node in node.loop_body.children:
self._evaluate_node(
child_node,
clause_lists
Expand Down
Loading
Loading