Skip to content

Instantly share code, notes, and snippets.

@jackalcooper
Last active September 22, 2023 14:20
Show Gist options
  • Save jackalcooper/ffdd0cb06842fdfec582bc9c7904cddc to your computer and use it in GitHub Desktop.
Save jackalcooper/ffdd0cb06842fdfec582bc9c7904cddc to your computer and use it in GitHub Desktop.
first class dialect definition support in beaver
defmodule Cmath do
alias Beaver.MLIR.Type
use Beaver.Dialect, name: "cmath"
deftype complex(t = any_of(t, [Type.f32(), Type.f64()])) do
parameters(t)
end
defop norm do
operands(complex(any()))
results(any())
end
defop mul do
c = complex(any_of([Type.f32(), Type.f64()]))
operands([c, c])
results(c)
end
end
module {
irdl.dialect @cmath {
irdl.type @complex {
%0 = irdl.is f32
%1 = irdl.is f64
%2 = irdl.any_of(%0, %1)
irdl.parameters(%2)
}
irdl.operation @norm {
%0 = irdl.any
%1 = irdl.parametric @complex<%0>
irdl.operands(%1)
irdl.results(%0)
}
irdl.operation @mul {
%0 = irdl.is f32
%1 = irdl.is f64
%2 = irdl.any_of(%0, %1)
%3 = irdl.parametric @complex<%2>
irdl.operands(%3, %3)
irdl.results(%3)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment