|
42 | 42 | from collections.abc import Iterator, Mapping, Sequence, Set |
43 | 43 |
|
44 | 44 | import islpy as isl |
45 | | - from pymbolic.typing import Expression |
| 45 | + from pymbolic.typing import ArithmeticExpression, Expression |
46 | 46 |
|
47 | 47 | from loopy.kernel import LoopKernel |
48 | 48 | from loopy.kernel.instruction import CallInstruction |
@@ -543,31 +543,48 @@ def generate_preambles(self, target: TargetBase) -> Iterator[str]: |
543 | 543 | """ |
544 | 544 | raise NotImplementedError() |
545 | 545 |
|
546 | | - # FIXME(pyright): these return types are not correct: see IndexOfCallable.emit_call |
547 | 546 | @abstractmethod |
548 | 547 | def emit_call(self, |
549 | 548 | expression_to_code_mapper: AbstractExpressionToCodeMapper, |
550 | 549 | expression: p.Call, |
551 | | - target: TargetBase) -> p.Call | p.CallWithKwargs: |
552 | | - ... |
| 550 | + target: TargetBase) -> ArithmeticExpression: |
| 551 | + """Generate a target-specific call expression by mapping its arguments |
| 552 | + to the appropriate data types. |
| 553 | +
|
| 554 | + :arg expression_to_code_mapper: an instance of |
| 555 | + ``loopy.symbolic.IdentityMapper`` |
| 556 | + responsible mapping the arguments (see |
| 557 | + :meth:`~loopy.target.c.codegen.expression.ExpressionToCExpressionMapper`). |
| 558 | + """ |
553 | 559 |
|
554 | 560 | @abstractmethod |
555 | 561 | def emit_call_insn(self, |
556 | 562 | insn: CallInstruction, |
557 | 563 | target: TargetBase, |
558 | 564 | expression_to_code_mapper: AbstractExpressionToCodeMapper, |
559 | | - ) -> tuple[p.Call | p.CallWithKwargs, bool]: |
| 565 | + ) -> tuple[ArithmeticExpression, bool]: |
560 | 566 | """ |
561 | 567 | Returns a tuple of ``(call, assignee_is_returned)`` which is the target |
562 | 568 | facing function call that would be seen in the generated code. ``call`` |
563 | | - is an instance of ``pymbolic.primitives.Call`` and ``assignee_is_returned`` |
564 | | - is a boolean flag used to indicate if the assignee is returned |
565 | | - by value of C-type targets. |
566 | | -
|
567 | | - *Example*: If ``assignee_is_returned=True``, then ``a, b = f(c, d)`` is |
568 | | - interpreted in the target as ``a = f(c, d, &b)``. If |
569 | | - ``assignee_is_returned=False``, then ``a, b = f(c, d)`` is interpreted |
570 | | - in the target as the statement ``f(c, d, &a, &b)``. |
| 569 | + is (usually) an instance of :class:`pymbolic.primitives.Call` and |
| 570 | + ``assignee_is_returned`` is a boolean flag used to indicate if the |
| 571 | + assignee is returned by value of C-type targets. |
| 572 | +
|
| 573 | + .. note:: |
| 574 | +
|
| 575 | + *Example*: If ``assignee_is_returned=True``, then ``a, b = f(c, |
| 576 | + d)`` is interpreted in the target as ``a = f(c, d, &b)``. If |
| 577 | + ``assignee_is_returned=False``, then ``a, b = f(c, d)`` is |
| 578 | + interpreted in the target as the statement ``f(c, d, &a, &b)``. |
| 579 | +
|
| 580 | + :arg expression_to_code_mapper: an instance of |
| 581 | + ``loopy.symbolic.IdentityMapper`` responsible for code mapping |
| 582 | + from :mod:`loopy` syntax to the *target syntax* (see |
| 583 | + :meth:`~loopy.target.c.codegen.expression.ExpressionToCExpressionMapper`). |
| 584 | +
|
| 585 | + :returns: a tuple of the call to be generated and an instance of |
| 586 | + :class:`bool` whether the first assignee is a part of the LHS in |
| 587 | + the assignment instruction |
571 | 588 | """ |
572 | 589 |
|
573 | 590 | @abstractmethod |
@@ -690,7 +707,7 @@ def is_ready_for_codegen(self) -> bool: |
690 | 707 | def emit_call(self, |
691 | 708 | expression_to_code_mapper: AbstractExpressionToCodeMapper, |
692 | 709 | expression: p.Call, |
693 | | - target: TargetBase) -> p.Call | p.CallWithKwargs: |
| 710 | + target: TargetBase) -> ArithmeticExpression: |
694 | 711 | assert self.is_ready_for_codegen() |
695 | 712 | assert self.arg_id_to_dtype is not None |
696 | 713 |
|
@@ -718,27 +735,7 @@ def emit_call_insn(self, |
718 | 735 | insn: CallInstruction, |
719 | 736 | target: TargetBase, |
720 | 737 | expression_to_code_mapper: AbstractExpressionToCodeMapper, |
721 | | - ) -> tuple[p.Call | p.CallWithKwargs, bool]: |
722 | | - """ |
723 | | - :arg insn: An instance of :class:`loopy.kernel.instructions.CallInstruction`. |
724 | | - :arg target: An instance of :class:`loopy.target.TargetBase`. |
725 | | - :arg expression_to_code_mapper: An instance of :class:`IdentityMapper` |
726 | | - responsible for code mapping from :mod:`loopy` syntax to the |
727 | | - **target syntax**. |
728 | | -
|
729 | | - :returns: A tuple of the call to be generated and an instance of |
730 | | - :class:`bool` whether the first assignee is a part of the LHS in |
731 | | - the assignment instruction. |
732 | | -
|
733 | | - .. note:: |
734 | | -
|
735 | | - The default implementation returns the first assignees and the |
736 | | - references of the rest of the assignees are appended to the |
737 | | - arguments of the call. |
738 | | -
|
739 | | - *Example:* ``c, d = f(a, b)`` is returned as ``c = f(a, b, &d)`` |
740 | | - """ |
741 | | - |
| 738 | + ) -> tuple[ArithmeticExpression, bool]: |
742 | 739 | from loopy.target.c import CFamilyTarget |
743 | 740 | if not isinstance(target, CFamilyTarget): |
744 | 741 | raise NotImplementedError( |
|
0 commit comments