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
5 """BUILD extensions for MLIR linalg generation."""
7 def genlinalg(name, linalggen, src, linalg_outs):
8 """genlinalg() generates code from a tc spec file.
11 name: The name of the build rule for use in dependencies.
12 linalggen: The binary used to produce the output.
13 src: The tc spec file.
14 linalg_outs: A list of tuples (opts, out), where each opts is a string of
15 options passed to linalggen, and the out is the corresponding output file
19 for (opts, out) in linalg_outs:
20 # All arguments to generate the output except output destination.
22 "$(location %s)" % linalggen,
24 "$(location %s)" % src,
26 rule_suffix = "_".join(opts.replace("-", "_").replace("=", "_").split(" "))
28 # Rule to generate code using generated shell script.
30 name = "%s_%s_genrule" % (name, rule_suffix),
34 cmd = (" ".join(base_args)),
37 hdrs = [f for (opts, f) in linalg_outs]