
# Autogenerated by mlir-tblgen; don't manually edit.

from ._ods_common import _cext as _ods_cext
from ._ods_common import (
    equally_sized_accessor as _ods_equally_sized_accessor,
    get_default_loc_context as _ods_get_default_loc_context,
    get_op_results_or_values as _get_op_results_or_values,
    segmented_accessor as _ods_segmented_accessor,
)
_ods_ir = _ods_cext.ir
_ods_cext.globals.register_traceback_file_exclusion(__file__)

import builtins
from typing import Any as _Any, Sequence as _Sequence, Union as _Union, Optional as _Optional
import sys as _sys
if _sys.version_info >= (3, 12):
  from collections.abc import Buffer as _Buffer  # pytype: disable=not-supported-yet
else:
  try:
    from typing_extensions import Buffer as _Buffer
  except ImportError:
    _Buffer = _Any


@_ods_cext.register_dialect
class _Dialect(_ods_ir.Dialect):
  DIALECT_NAMESPACE = "ub"

@_ods_cext.register_operation(_Dialect)
class PoisonOp(_ods_ir.OpView):
  r"""
  The `poison` operation materializes a compile-time poisoned constant value
  to indicate deferred undefined behavior.
  `value` attribute is needed to indicate an optional additional poison
  semantics (e.g. partially poisoned vectors), default value indicates results
  is fully poisoned.
  
  Examples:
  
  ```
  // Short form
  %0 = ub.poison : i32
  // Long form
  %1 = ub.poison <#custom_poison_elements_attr> : vector<4xi64>
  ```
  """

  OPERATION_NAME = "ub.poison"

  _ODS_REGIONS = (0, True)

  def __init__(self, result: _ods_ir.Type, *, value: _Optional[_Union[_Any, _ods_ir.Attribute]] = None, loc: _Optional[_ods_ir.Location] = None, ip: _Optional[_ods_ir.InsertionPoint] = None):
    operands = []
    attributes = {}
    regions = None
    _ods_context = _ods_get_default_loc_context(loc)
    if value is not None: attributes["value"] = (value if (
        isinstance(value, _ods_ir.Attribute) or
        not _ods_ir.AttrBuilder.contains('PoisonAttrInterface')) else
          _ods_ir.AttrBuilder.get('PoisonAttrInterface')(value, context=_ods_context))
    results = []
    results.append(result)
    _ods_successors = None
    super().__init__(self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS, attributes=attributes, results=results, operands=operands, successors=_ods_successors, regions=regions, loc=loc, ip=ip)

  @builtins.property
  def value(self) -> _ods_ir.Attribute:
    return self.operation.attributes["value"]

  @value.setter
  def value(self, value: _ods_ir.Attribute):
    if value is None:
      raise ValueError("'None' not allowed as value for mandatory attributes")
    self.operation.attributes["value"] = value

  @builtins.property
  def result(self) -> _ods_ir.OpResult:
    return self.operation.results[0]

@_ods_cext.register_op_adaptor(PoisonOp)
class PoisonOpAdaptor(_ods_ir.OpAdaptor):
  OPERATION_NAME = "ub.poison"

  @builtins.property
  def value(self) -> _ods_ir.Attribute:
    return self.attributes["value"]

def poison(result: _ods_ir.Type, *, value: _Optional[_Union[_Any, _ods_ir.Attribute]] = None, loc: _Optional[_ods_ir.Location] = None, ip: _Optional[_ods_ir.InsertionPoint] = None) -> _ods_ir.OpResult:
  return PoisonOp(result=result, value=value, loc=loc, ip=ip).result

@_ods_cext.register_operation(_Dialect)
class UnreachableOp(_ods_ir.OpView):
  r"""
  The `unreachable` operation triggers immediate undefined behavior if
  executed.
  
  Example:
  
  ```
  ub.unreachable
  ```
  """

  OPERATION_NAME = "ub.unreachable"

  _ODS_REGIONS = (0, True)

  def __init__(self, *, loc: _Optional[_ods_ir.Location] = None, ip: _Optional[_ods_ir.InsertionPoint] = None):
    operands = []
    attributes = {}
    regions = None
    _ods_context = _ods_get_default_loc_context(loc)
    results = []
    _ods_successors = None
    super().__init__(self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS, attributes=attributes, results=results, operands=operands, successors=_ods_successors, regions=regions, loc=loc, ip=ip)

@_ods_cext.register_op_adaptor(UnreachableOp)
class UnreachableOpAdaptor(_ods_ir.OpAdaptor):
  OPERATION_NAME = "ub.unreachable"

def unreachable(*, loc: _Optional[_ods_ir.Location] = None, ip: _Optional[_ods_ir.InsertionPoint] = None) -> UnreachableOp:
  return UnreachableOp(loc=loc, ip=ip)
