Beaver. MLIR. IRMapping
(beaver v0.4.8)
Copy Markdown
An owned mapping between values, blocks, and operations in two pieces of IR.
Mappings are mutable native resources. Destroy them explicitly with
destroy/1, or use with_mapping/1 for scoped work. Mapped entities are
borrowed: a mapping must not be queried after either side of a mapping has
been destroyed.
clone/2 creates a detached, caller-owned operation. Insert that operation
into a block or destroy it. clone/3 inserts through a rewriter and updates
the mapping as part of the rewrite.
A mapping and a scoped insertion point can be combined in a rewrite callback without leaking native state or the rewriter's temporary position:
base = MLIR.PatternRewriter.as_base(rewriter)
old_result = MLIR.Operation.result(operation, 0)
MLIR.PatternRewriter.with_insertion_point(rewriter, {:before, operation}, fn ->
MLIR.IRMapping.with_mapping(fn mapping ->
replacement = build_replacement.(base)
mapping
|> MLIR.IRMapping.map(old_result, replacement)
|> MLIR.IRMapping.lookup(old_result)
|> then(&MLIR.RewriterBase.replace(base, old_result, &1))
end)
end)
Summary
Functions
Clears all mappings and returns mapping.
Clones operation as a detached caller-owned operation and updates mapping.
Clones and inserts operation through rewriter, updating mapping.
Returns whether a mapping exists for a value, block, or operation.
Creates an empty owned IR mapping.
Destroys an owned IR mapping.
Erases a value, block, or operation mapping and returns mapping.
Looks up a mapped entity, returning nil when no mapping exists.
Looks up a mapped entity, returning the input entity when absent.
Adds or replaces a value, block, or operation mapping.
Runs fun with a new mapping and always destroys it.
Types
@type entity() :: Beaver.MLIR.Value.t() | Beaver.MLIR.Block.t() | Beaver.MLIR.Operation.t()
@type rewriter() :: Beaver.MLIR.RewriterBase.t() | Beaver.MLIR.PatternRewriter.t()
@type t() :: %Beaver.MLIR.IRMapping{ref: term()}
Functions
Clears all mappings and returns mapping.
@spec clone(t(), Beaver.MLIR.Operation.t()) :: Beaver.MLIR.Operation.t()
Clones operation as a detached caller-owned operation and updates mapping.
@spec clone(t(), Beaver.MLIR.Operation.t(), rewriter()) :: Beaver.MLIR.Operation.t()
Clones and inserts operation through rewriter, updating mapping.
Returns whether a mapping exists for a value, block, or operation.
@spec create() :: t()
Creates an empty owned IR mapping.
@spec destroy(t()) :: :ok
Destroys an owned IR mapping.
Erases a value, block, or operation mapping and returns mapping.
Looks up a mapped entity, returning nil when no mapping exists.
Looks up a mapped entity, returning the input entity when absent.
Adds or replaces a value, block, or operation mapping.
@spec with_mapping((t() -> result)) :: result when result: var
Runs fun with a new mapping and always destroys it.