1#  Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2#  See https://llvm.org/LICENSE.txt for license information.
3#  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5try:
6  from ..ir import *
7  from ._ods_common import get_op_result_or_value as _get_op_result_or_value, get_op_results_or_values as _get_op_results_or_values
8except ImportError as e:
9  raise RuntimeError("Error loading imports from extension module") from e
10
11from typing import Optional, Sequence, Union
12
13
14class LoadOp:
15  """Specialization for the MemRef load operation."""
16
17  def __init__(self,
18               memref: Union[Operation, OpView, Value],
19               indices: Optional[Union[Operation, OpView,
20                                       Sequence[Value]]] = None,
21               *,
22               loc=None,
23               ip=None):
24    """Creates a memref load operation.
25
26    Args:
27      memref: the buffer to load from.
28      indices: the list of subscripts, may be empty for zero-dimensional
29        buffers.
30      loc: user-visible location of the operation.
31      ip: insertion point.
32    """
33    memref_resolved = _get_op_result_or_value(memref)
34    indices_resolved = [] if indices is None else _get_op_results_or_values(
35        indices)
36    return_type = MemRefType(memref_resolved.type).element_type
37    super().__init__(return_type, memref, indices_resolved, loc=loc, ip=ip)
38