Example #1
0
 def __init__(self, mlir_context=None, emitter_registry=None):
     self.context = mlir_context if mlir_context else ir.MLIRContext()
     self.module = self.context.new_module()
     self.helper = Numpy.DialectHelper(self.context,
                                       ir.OpBuilder(self.context))
     self.emitters = (emitter_registry if emitter_registry else
                      EmitterRegistry.create_default())
Example #2
0
 def __init__(self, mlir_context=None, emitter_registry=None):
     self.context = mlir_context if mlir_context else ir.MLIRContext()
     # TODO: Instead of bootstrapping a large module, populate imports
     # dynamically.
     self.module = Numpy.load_builtin_module(self.context)
     self.helper = Numpy.DialectHelper(self.context)
     self.emitters = (emitter_registry if emitter_registry else
                      EmitterRegistry.create_default())
Example #3
0
 def __init__(self,
              *,
              config: Configuration,
              ir_context: ir.MLIRContext = None):
     super().__init__()
     self._ir_context = ir.MLIRContext() if not ir_context else ir_context
     self._ir_module = self._ir_context.new_module()
     self._ir_h = AllDialectHelper(self._ir_context,
                                   ir.OpBuilder(self._ir_context))
     self._config = config
Example #4
0
def load_builtin_module(context=None):
    """Loads a module populated with numpy built-ins.

  This is not a long-term solution but overcomes some bootstrapping
  issues.

    >>> m = load_builtin_module()
    >>> op = m.region(0).blocks.front.operations.front
    >>> op.is_registered
    True
    >>> op.name
    'numpy.builtin_ufunc'

  Args:
    context: The MLIRContext to use (None to create a new one).
  Returns:
    A ModuleOp.
  """
    if context is None: context = ir.MLIRContext()
    return context.parse_asm(_BUILTIN_MODULE_ASM)
Example #5
0
# RUN: %PYTHON %s | FileCheck %s --dump-input=fail

#  Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
#  See https://llvm.org/LICENSE.txt for license information.
#  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""Test for the MLIR IR Python bindings.

TODO: These tests were just for bootstrapping and are not authoritative at this
point.
"""

from _npcomp.mlir import ir

c = ir.MLIRContext()

# CHECK-LABEL: module @parseSuccess
m = c.parse_asm(r"""
module @parseSuccess {
  func @f() {
    return
  }
}
""")
# CHECK: func @f
print(m.to_asm())
# CHECK: OP NAME: module
print("OP NAME:", m.name)
# CHECK: NUM_REGIONS: 1
print("NUM_REGIONS:", m.num_regions)
region = m.region(0)
# CHECK: CONTAINED OP: func