ml_switcheroo.compiler.frontends.rdna.nodes =========================================== .. py:module:: ml_switcheroo.compiler.frontends.rdna.nodes .. autoapi-nested-parse:: RDNA AST Nodes. Defines the data structures for the AMD RDNA / GCN syntax tree. Each node corresponds to a syntactic element in RDNA assembly and implements `__str__` to emit valid assembly code. Classes ------- .. autoapisummary:: ml_switcheroo.compiler.frontends.rdna.nodes.RdnaNode ml_switcheroo.compiler.frontends.rdna.nodes.Operand ml_switcheroo.compiler.frontends.rdna.nodes.LabelRef ml_switcheroo.compiler.frontends.rdna.nodes.SGPR ml_switcheroo.compiler.frontends.rdna.nodes.VGPR ml_switcheroo.compiler.frontends.rdna.nodes.Immediate ml_switcheroo.compiler.frontends.rdna.nodes.Modifier ml_switcheroo.compiler.frontends.rdna.nodes.Memory ml_switcheroo.compiler.frontends.rdna.nodes.Instruction ml_switcheroo.compiler.frontends.rdna.nodes.Label ml_switcheroo.compiler.frontends.rdna.nodes.Directive ml_switcheroo.compiler.frontends.rdna.nodes.Comment Functions --------- .. autoapisummary:: ml_switcheroo.compiler.frontends.rdna.nodes.c_SGPR ml_switcheroo.compiler.frontends.rdna.nodes.c_VGPR Module Contents --------------- .. py:class:: RdnaNode Bases: :py:obj:`abc.ABC` Abstract base class for all RDNA AST nodes. .. py:method:: __str__() -> str :abstractmethod: Returns the valid RDNA string representation of the node. .. py:class:: Operand Bases: :py:obj:`RdnaNode` Base class for instruction operands (Registers, Immediates, etc.). .. py:method:: __str__() -> str Returns the valid RDNA string representation of the node. .. py:class:: LabelRef Bases: :py:obj:`Operand` Represents a reference to a label (e.g. as a jump target) or generic identifier operand. .. attribute:: name The label identifier. :type: str .. py:attribute:: name :type: str .. py:method:: __str__() -> str Returns the valid RDNA string representation of the node. .. py:class:: SGPR Bases: :py:obj:`Operand` Represents a Scalar General Purpose Register (e.g., s0, s10). .. attribute:: index The register index. :type: int .. attribute:: count If > 1, represents a range/multi-register (e.g., s[0:3]). :type: int .. py:attribute:: index :type: int .. py:attribute:: count :type: int :value: 1 .. py:method:: __str__() -> str Returns the valid RDNA string representation of the node. .. py:class:: VGPR Bases: :py:obj:`Operand` Represents a Vector General Purpose Register (e.g., v0, v255). .. attribute:: index The register index. :type: int .. attribute:: count If > 1, represents a range/multi-register (e.g., v[0:3]). :type: int .. py:attribute:: index :type: int .. py:attribute:: count :type: int :value: 1 .. py:method:: __str__() -> str Returns the valid RDNA string representation of the node. .. py:function:: c_SGPR(idx: int) -> SGPR Helper to create a single SGPR. .. py:function:: c_VGPR(idx: int) -> VGPR Helper to create a single VGPR. .. py:class:: Immediate Bases: :py:obj:`Operand` Represents a literal constant value. .. attribute:: value The numeric value. :type: Union[int, float] .. attribute:: is_hex If True, renders as hex string (e.g., 0xff). :type: bool .. py:attribute:: value :type: Union[int, float] .. py:attribute:: is_hex :type: bool :value: False .. py:method:: __str__() -> str Returns the valid RDNA string representation of the node. .. py:class:: Modifier Bases: :py:obj:`Operand` Represents an instruction modifier or attribute. e.g., `glc`, `slc`, `off`. .. attribute:: name The modifier string. :type: str .. py:attribute:: name :type: str .. py:method:: __str__() -> str Returns the valid RDNA string representation of the node. .. py:class:: Memory Bases: :py:obj:`Operand` Represents a memory address operand, typically used in generic loads/stores. RDNA often passes the address as a register or register pair, but explicit offset syntax exists. Format: `method[base + offset]` or simply register references depending on op. This node models the bracketed syntax `global_load_dword v0, v[1:2], off`. Usually, RDNA just uses registers as operands, but sometimes specific addressing notation is used. Here we treat it as an explicit container if needed, primarily for offsets. .. attribute:: base The base register. :type: Union[SGPR, VGPR] .. attribute:: offset Immediate byte offset. :type: Optional[int] .. py:attribute:: base :type: Union[SGPR, VGPR] .. py:attribute:: offset :type: Optional[int] :value: None .. py:method:: __str__() -> str Returns the valid RDNA string representation of the node. .. py:class:: Instruction Bases: :py:obj:`RdnaNode` Represents a single RDNA operation line. Format: `{opcode} {operands}` Modifiers are treated as operands in the list for flexible placement. .. attribute:: opcode The instruction mnemonic (e.g., "v_add_f32", "s_mov_b32"). :type: str .. attribute:: operands List of operand nodes. :type: List[Operand] .. py:attribute:: opcode :type: str .. py:attribute:: operands :type: List[Operand] :value: [] .. py:method:: __str__() -> str Returns the valid RDNA string representation of the node. .. py:class:: Label Bases: :py:obj:`RdnaNode` Represents a jump target label. Format: `{name}:` .. attribute:: name The label identifier. :type: str .. py:attribute:: name :type: str .. py:method:: __str__() -> str Returns the valid RDNA string representation of the node. .. py:class:: Directive Bases: :py:obj:`RdnaNode` Represents an assembler directive. Format: `.{name} {params}` .. attribute:: name The directive name (e.g., "global_base"). :type: str .. attribute:: params List of string parameters. :type: List[str] .. py:attribute:: name :type: str .. py:attribute:: params :type: List[str] :value: [] .. py:method:: __str__() -> str Returns the valid RDNA string representation of the node. .. py:class:: Comment Bases: :py:obj:`RdnaNode` Represents a line comment. RDNA assembly uses `;` for comments. Format: `; {text}` .. attribute:: text The comment content. :type: str .. py:attribute:: text :type: str .. py:method:: __str__() -> str Returns the valid RDNA string representation of the node.