Debian Codegraph @

utils/bazel/llvm-project-overlay/mlir/linalggen.bzl

raw
1 # This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5 """BUILD extensions for MLIR linalg generation."""
6
7 load("@rules_cc//cc:defs.bzl", "cc_library")
8
9 def genlinalg(name, linalggen, src, linalg_outs):
10 """genlinalg() generates code from a tc spec file.
11
12 Args:
13 name: The name of the build rule for use in dependencies.
14 linalggen: The binary used to produce the output.
15 src: The tc spec file.
16 linalg_outs: A list of tuples (opts, out), where each opts is a string of
17 options passed to linalggen, and the out is the corresponding output file
18 produced.
19 """
20
21 for (opts, out) in linalg_outs:
22 # All arguments to generate the output except output destination.
23 base_args = [
24 "$(location %s)" % linalggen,
25 "%s" % opts,
26 "$(location %s)" % src,
27 ]
28 rule_suffix = "_".join(opts.replace("-", "_").replace("=", "_").split(" "))
29
30 # Rule to generate code using generated shell script.
31 native.genrule(
32 name = "%s_%s_genrule" % (name, rule_suffix),
33 srcs = [src],
34 outs = [out],
35 tools = [linalggen],
36 output_to_bindir = 1,
37 cmd = (" ".join(base_args)),
38 )
39
40 hdrs = [f for (opts, f) in linalg_outs]
41 cc_library(
42 name = name,
43 hdrs = hdrs,
44 textual_hdrs = hdrs,
45 )