tvm_tirx.ir.transform.PassContext#

class tvm_tirx.ir.transform.PassContext(opt_level=2, required_pass=None, disabled_pass=None, instruments=None, config=None)#

Bases: Object

Scope optimization levels, pass selection, instruments, and pass options.

Use a PassContext as a with block. Every pass that runs inside the block, called directly or by a Sequential, sees this context as PassContext.current() and receives it as the ctx argument of its callback. Outside any with block, a default context with opt_level=2 and no other options is active.

Parameters:
  • opt_level (Optional[int]) – Maximum optimization level enabled in sequential pipelines (default 2). A Sequential skips a child pass whose info.opt_level is higher. Calling a pass directly ignores this level.

  • required_pass (Optional[Union[List[str], Set[str], Tuple[str]]]) – Pass names to enable regardless of their optimization level.

  • disabled_pass (Optional[Union[List[str], Set[str], Tuple[str]]]) – Pass names to skip in sequential pipelines, even if required.

  • instruments (Optional[Sequence[PassInstrument]]) – The list of pass instrument implementations. They observe every pass that runs inside the context.

  • config (Optional[Dict[str, Object]]) – Additional configurations for specific passes. Keys must be registered option names, which list_configs() lists; an unknown key raises an error.

Examples

from tvm_tirx import tirx
from tvm_tirx.ir.transform import PassContext, Sequential

pipeline = Sequential([tirx.transform.StmtSimplify(), my_pass])
with PassContext(opt_level=3, disabled_pass=["tirx.StmtSimplify"]):
    assert PassContext.current().opt_level == 3
    after = pipeline(mod)  # runs only my_pass
override_instruments(instruments)#

Override instruments within this PassContext.

If there are existing instruments, their exit_pass_ctx callbacks are called. Then switching to new instruments and calling new enter_pass_ctx callbacks.

instrumentsSequence[PassInstrument]

The list of pass instrument implementations.

static current()#

Return the current pass context.

static list_configs()#

List all registered PassContext configuration names and metadata.

Returns:

configs (Dict[str, Dict[str, str]])

property config#
property disabled_pass#
property instruments#
property opt_level#
property required_pass#