Skip to content

Commit

Permalink
Merge branch 'main' into christos/dialects/math/custom-format
Browse files Browse the repository at this point in the history
  • Loading branch information
compor committed Jan 24, 2025
2 parents e4fa1f5 + bac3115 commit 61fa401
Show file tree
Hide file tree
Showing 12 changed files with 427 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Generating executables through MLIR

As mentioned previously, xDSL can interoperate with MLIR as its backend. As this
xDSL can interoperate with MLIR as its backend. As this
requires an installation, and therefore a compilation, of a lot of the LLVM
project and MLIR, this functonality is not distributed with xDSL by default. To
actually leverage from this functionality, first clone and build MLIR. Please
Expand Down
41 changes: 34 additions & 7 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,41 @@ site_name: xDSL

theme:
name: "material"
features:
- navigation.instant
- navigation.tracking
- navigation.tabs
- navigation.sections
- navigation.expand

plugins:
- search
- mkdocstrings
- gen-files:
scripts:
- scripts/gen_ref_pages.py
- mkdocstrings:
handlers:
python:
options:
docstring_style: google
members_order: source
show_root_heading: true
show_root_full_path: false
show_signature_annotations: true


# nav:
# - xDSL: index.md
# - API Reference:
# - API Reference: api/index.md
# - Core IR Data Structures: api/ir/index.md
nav:
- xDSL: index.md
- API Reference:
- API Reference: api/index.md
- Core IR Data Structures:
- Core IR Data Structures: api/ir/index.md
- Attribute: api/ir/attribute.md
- SSAValue: api/ir/ssa_value.md
- IRNode: api/ir/ir_node.md
- Operation: api/ir/operation.md
- Block: api/ir/block.md
- Region: api/ir/region.md
- Dialect: api/ir/dialect.md
- Code Reference: reference/index.md
- Guides:
- MLIR Interoperation: guides/mlir_interoperation.md
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ dev = [
"filecheck==1.0.1",
"lit<19.0.0",
"marimo==0.10.14",
"pre-commit==4.0.1",
"ruff==0.9.2",
"pre-commit==4.1.0",
"ruff==0.9.3",
"asv<0.7",
"nbconvert>=7.7.2,<8.0.0",
"textual-dev==1.7.0",
"pytest-asyncio==0.25.2",
"pyright==1.1.392.post0",
]
docs = [
"mkdocs>=1.6.1",
"mkdocs-gen-files>=0.5.0",
"mkdocs-material>=9.5.49",
"mkdocs>=1.6.1",
"mkdocstrings[python]>=0.27.0",
]
gui = ["textual==1.0.0", "pyclip==0.7"]
Expand Down
49 changes: 49 additions & 0 deletions scripts/gen_ref_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Generate the code reference pages and navigation."""

from pathlib import Path

import mkdocs_gen_files
from mkdocs_gen_files.nav import Nav

nav = Nav()

root = Path(__file__).parent.parent
src = root / "xdsl"

for path in sorted(src.rglob("*.py")):
module_path = path.relative_to(src).with_suffix("")
doc_path = path.relative_to(src).with_suffix(".md")
full_doc_path = Path("reference", doc_path)

parts = tuple(module_path.parts)

if parts[-1] == "__init__":
parts = parts[:-1]
doc_path = doc_path.with_name("index.md")
full_doc_path = full_doc_path.with_name("index.md")
elif parts[-1] == "__main__":
continue
elif parts[-1].startswith("_"):
continue
if not parts:
continue

if "ir" == parts[0]:
# IR is documented separately
continue

ident = ".".join(parts)

if ident in ("irdl.error",):
# TODO: rename error function, treated as circular reference
continue

nav[parts] = doc_path.as_posix()

with mkdocs_gen_files.open(full_doc_path, "w") as fd:
fd.write(f"::: xdsl.{ident}")

mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(root))

with mkdocs_gen_files.open("reference/index.md", "w") as nav_file:
nav_file.writelines(nav.build_literate_nav())
6 changes: 6 additions & 0 deletions tests/filecheck/dialects/llvm/example.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ builtin.module {
// CHECK-NEXT: func.return
// CHECK-NEXT: }

%val = "test.op"() : () -> i32

%fval = llvm.bitcast %val : i32 to f32

// CHECK: %val = "test.op"() : () -> i32
// CHECK-NEXT: %fval = llvm.bitcast %val : i32 to f32
}
92 changes: 92 additions & 0 deletions tests/irdl/test_declarative_assembly_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
FloatAttr,
IndexType,
IntegerAttr,
IntegerType,
MemRefType,
ModuleOp,
UnitAttr,
Expand All @@ -31,12 +32,14 @@
from xdsl.irdl import (
AllOf,
AnyAttr,
AnyInt,
AttrSizedOperandSegments,
AttrSizedRegionSegments,
AttrSizedResultSegments,
BaseAttr,
EqAttrConstraint,
GenericAttrConstraint,
IntVarConstraint,
IRDLOperation,
ParamAttrConstraint,
ParameterDef,
Expand All @@ -48,6 +51,7 @@
VarOperand,
VarOpResult,
attr_def,
eq,
irdl_attr_definition,
irdl_op_definition,
operand_def,
Expand Down Expand Up @@ -2466,6 +2470,32 @@ class RangeVarOp(IRDLOperation): # pyright: ignore[reportUnusedClass]
assert isinstance(my_op, RangeVarOp)


def test_int_var_inference():
@irdl_op_definition
class IntVarOp(IRDLOperation):
name = "test.int_var"
T: ClassVar = IntVarConstraint("T", AnyInt())
ins = var_operand_def(RangeOf(eq(IndexType()), length=T))
outs = var_result_def(RangeOf(eq(IntegerType(64)), length=T))

assembly_format = "$ins attr-dict"

ctx = MLContext()
ctx.load_op(IntVarOp)
ctx.load_dialect(Test)
program = textwrap.dedent("""\
%in0, %in1 = "test.op"() : () -> (index, index)
%out0, %out1 = test.int_var %in0, %in1
""")

parser = Parser(ctx, program)
test_op = parser.parse_optional_operation()
assert isinstance(test_op, test.Operation)
my_op = parser.parse_optional_operation()
assert isinstance(my_op, IntVarOp)
assert my_op.result_types == (IntegerType(64), IntegerType(64))


################################################################################
# Declarative Format Verification #
################################################################################
Expand Down Expand Up @@ -2965,6 +2995,68 @@ class DefaultConstantOp(IRDLOperation):
check_equivalence(program, generic, ctx)


@pytest.mark.parametrize(
"program, generic",
[
(
"test.default_attr_dict",
'"test.default_attr_dict"() <{prop = false}> {attr = false} : () -> ()',
),
(
"test.default_attr_dict {attr = true, prop = true}",
'"test.default_attr_dict"() <{prop = true}> {attr = true} : () -> ()',
),
],
)
def test_default_property_in_attr_dict(program: str, generic: str):
@irdl_op_definition
class DefaultAttrDictOp(IRDLOperation):
name = "test.default_attr_dict"

prop = prop_def(BoolAttr, default_value=BoolAttr.from_bool(False))

attr = attr_def(BoolAttr, default_value=BoolAttr.from_bool(False))

irdl_options = [ParsePropInAttrDict()]

assembly_format = "attr-dict"

ctx = MLContext()
ctx.load_op(DefaultAttrDictOp)

check_roundtrip(program, ctx)
check_equivalence(program, generic, ctx)


@pytest.mark.parametrize(
"program, generic",
[
(
"test.default_attr_dict",
'"test.default_attr_dict"() {attr = false} : () -> ()',
),
(
"test.default_attr_dict {attr = true}",
'"test.default_attr_dict"() {attr = true} : () -> ()',
),
],
)
def test_default_attr_in_attr_dict(program: str, generic: str):
@irdl_op_definition
class DefaultAttrDictOp(IRDLOperation):
name = "test.default_attr_dict"

attr = attr_def(BoolAttr, default_value=BoolAttr.from_bool(False))

assembly_format = "attr-dict"

ctx = MLContext()
ctx.load_op(DefaultAttrDictOp)

check_roundtrip(program, ctx)
check_equivalence(program, generic, ctx)


################################################################################
# Extractors #
################################################################################
Expand Down
Loading

0 comments on commit 61fa401

Please sign in to comment.