def valid_kernel(node):
    """
    Whether the sub-tree that has `node` at its root is eligible to be
    enclosed within an OpenACC KERNELS directive.

    :param node: the node in the PSyIR to check.
    :type node: :py:class:`psyclone.psyGen.Node`

    :returns: True if the sub-tree can be enclosed in a KERNELS region.
    :rtype: bool

    """
    from psyclone.psyGen import CodeBlock, IfBlock
    from fparser.two.utils import walk_ast
    from fparser.two import Fortran2003
    excluded_node_types = CodeBlock, IfBlock
    if node.walk(excluded_node_types):
        return False
    if walk_ast([node.ast], [Fortran2003.Data_Ref]):
        return False
    return True
