├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── WORKSPACE ├── examples ├── .bazelrc ├── BUILD ├── WORKSPACE ├── clang │ ├── clang_empty_main.cc │ └── clang_list_methods.cc ├── generate_libcxx_bazelrc.py ├── llvm │ ├── function_argument_usage_pass.cc │ ├── llvm_bb_counter.cc │ ├── llvm_empty_main.cc │ ├── llvm_print_physical_registers.cc │ ├── llvm_print_supported_targets.cc │ └── target │ │ ├── custom_frame_lowering.cc │ │ ├── custom_frame_lowering.h │ │ ├── custom_mc_target_desc.cc │ │ ├── custom_register_class.td │ │ ├── custom_register_info.cc │ │ ├── custom_register_info.h │ │ └── custom_register_info.td └── mlir │ └── mlir_empty_main.cc └── llvm ├── BUILD ├── BUILD.tpl ├── llvm_config.bzl.tpl ├── llvm_configure.bzl └── llvm_tablegen.bzl.tpl /.gitignore: -------------------------------------------------------------------------------- 1 | bazel-* 2 | .clwb 3 | libcxx.bazelrc 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | This project adheres to No Code of Conduct. We are all adults. We accept anyone's contributions. Nothing else matters. 4 | 5 | For more information please visit the [No Code of Conduct](https://github.com/domgetter/NCoC) homepage. 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Due to the LLVM community's planes to add the Bazel build files in the project's monorepo 2 | [[1]](https://lists.llvm.org/pipermail/llvm-dev/2021-March/149220.html), I see no intent for 3 | the project.** 4 | 5 | # Bazel to the LLVM Compiler Infrastructure bridge 6 | 7 | [Bazel](https://docs.bazel.build/versions/master/bazel-overview.html) is an open-source 8 | build and test tool similar to Make, Maven, and Gradle. It uses a human-readable, 9 | high-level build language. Bazel supports projects in multiple languages and builds outputs 10 | for multiple platforms. For example, Tensorflow - end-to-end open-source platform for 11 | machine learning - uses Bazel as the build system. 12 | 13 | [LLVM](https://llvm.org/) is a collection of modular and reusable compiler and toolchain 14 | technologies. The LLVM Core libraries provide a modern source- and target-independent 15 | optimizer and code generator that makes it easy to invent a new programming language or 16 | port an existing compiler. Also LLVM provides its own native C/C++ compiler - Clang, 17 | debugger - LLDB, an implementation of the C++ Standard Library, and many other interesting 18 | things. The full list of LLVM's primary sub-projects is available on the official web-site. 19 | 20 | **bazel-llvm-bridge** provides a bridge that let you use static libraries from a local 21 | installation or kindly downloaded archive of LLVM in your projects when Bazel is used 22 | as a building tool. Each library from LLVM/Clang (including the special 'headers' library 23 | that provides LLVM's and Clang's headers) is available as a `@local_llvm//:llvm_` 24 | dependency (`@local_llvm//:llvm_headers` for the headers library), where `@local_llvm` is 25 | the name of the used `llvm_configure` 26 | [repository rule](https://docs.bazel.build/versions/master/skylark/repository_rules.html) 27 | while `llvm_`, `clang_` and `mlir_` are the default prefixes for LLVM, Clang and MLIR specific 28 | rules, all these parameters can be configured in your `WORKSPACE`. Notice that a library will 29 | bring also its dependencies exactly how the *CMake* build works. 30 | 31 | Platform-provided libraries such as "ncurses", "tinfo", "pthreads", "Z3" will be detected 32 | automatically using the `*.cmake` files generated by CMake during the LLVM build process. 33 | 34 | Notice: The minimum supported version of Bazel is 35 | [**0.25.0**](https://github.com/bazelbuild/bazel/releases/tag/0.25.0). 36 | 37 | 38 | ### How to leverage the bridge in your project 39 | 40 | In order to use any LLVM libraries in your targets, add the following to your 41 | `WORKSPACE` file: 42 | 43 | ```bzl 44 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 45 | 46 | http_archive( 47 | name = "bazel_llvm_bridge", 48 | sha256 = "0e0971ec02d5e061c2c472d185e390597a4d7842e3e457cfcda2f04c1839c05e", 49 | strip_prefix = "bazel-llvm-bridge-release-11-05", 50 | url = "https://github.com/samolisov/bazel-llvm-bridge/archive/release/11-05.zip", 51 | ) 52 | 53 | load("@bazel_llvm_bridge//llvm:llvm_configure.bzl", "llvm_configure") 54 | 55 | llvm_configure( 56 | name = "local_llvm", 57 | llvm_prefix = "llvm_", 58 | clang_prefix = "clang_", 59 | libcxx_prefix = "libcxx_", 60 | mlir_prefix = "mlir_", 61 | add_headers_to_deps = False, 62 | ) 63 | ``` 64 | 65 | Where `name` is whatever you want, default values for `llvm_prefix`, `clang_prefix`, 66 | `libcxx_prefix` and `mlir_prefix` may be omitted. By default, the header libraries will be 67 | automatically included as dependency to the generated targets (the LLVM header library to 68 | LLVM's, Clang's and other project's targets, the Clang header library to Clang's targets, etc.) 69 | If you would like to manually put the header libraries to dependencies, set up the 70 | `add_headers_to_deps` attribute of the reporitory rule to `False`. 71 | 72 | The LLVM libraries are fetched from a local installation so the `LLVM_INSTALL_PREFIX` 73 | environment variable **must** point to the local installation. 74 | 75 | The library's version number is matched to the version of LLVM and can be found in the 76 | `release/-` tag or `release/.x` branch. For example: 77 | 78 | ```bash 79 | $ git clone https://github.com/samolisov/bazel-llvm-bridge.git 80 | $ git checkout release/9.x 81 | $ git log --oneline -1 82 | ``` 83 | 84 | shows you the latest commit in the release branch. The commit can be used as a value of the `commit` 85 | attribute of the `git_repository` rule to checkout the compatible version of **bazel-llvm-bridge** for 86 | the used version of **LLVM**: 87 | 88 | ```bzl 89 | git_repository( 90 | name = "bazel_llvm_bridge", 91 | commit = "", 92 | remote = "https://github.com/samolisov/bazel-llvm-bridge.git", 93 | ) 94 | ``` 95 | 96 | Now the desired libraries can be added as dependencies (the `deps` attribute) to targets for 97 | your libraries and binaries (through the `@local_llvm` repository): 98 | 99 | ```bzl 100 | cc_binary( 101 | name = 'llvm_bb_counter', 102 | srcs = [ 103 | "llvm/llvm_bb_counter.cc", 104 | ], 105 | deps = [ 106 | "@local_llvm//:llvm_headers", 107 | "@local_llvm//:llvm_bit_reader", 108 | ] + if_cxx_linked([ 109 | "@local_llvm//:libcxx_shared", 110 | "@local_llvm//:libcxx_abi_shared", 111 | ]), 112 | visibility = ["//visibility:private"], 113 | ) 114 | ``` 115 | 116 | ### How to build the project 117 | 118 | To build your targets, do the following: 119 | 120 | 0. Build from sources or download from http://releases.llvm.org/download.html an 121 | archive with an LLVM package for your platform. The package must be unarchived 122 | into a local directory. 123 | 124 | 1. Set up the `LLVM_INSTALL_PREFIX` environment variable. The variable must 125 | contain a path to a local LLVM installation: 126 | 127 | ```bash 128 | $ export LLVM_INSTALL_PREFIX=~/dev/llvm_master 129 | ``` 130 | 131 | or, on Windows: 132 | 133 | ```bash 134 | $ set LLVM_INSTALL_PREFIX=C:\Dev\llvm_master 135 | ``` 136 | 137 | 2. Run the build: 138 | 139 | ```bash 140 | $ bazel build //:llvm_bb_counter 141 | ``` 142 | 143 | alternatively, the environment variables may be passed directly to the build 144 | command: 145 | 146 | ```bash 147 | $ bazel build --action_env LLVM_INSTALL_PREFIX=C:\Dev\llvm_master //:clang_list_methods 148 | ``` 149 | 150 | ### How to deal with targets 151 | 152 | The **bazel-llvm-bridge** supports all out-of-the-box provided LLVM targets: 153 | * AArch64 154 | * AMDGPU 155 | * ARM 156 | * AVR 157 | * BPF 158 | * Hexagon 159 | * Lanai 160 | * Mips 161 | * MSP430 162 | * NVPTX 163 | * PowerPC 164 | * RISCV 165 | * Sparc 166 | * SystemZ 167 | * WebAssembly 168 | * X86 169 | * XCore 170 | 171 | To link against a target, the user should to check whether the target is supported by the used 172 | local installation of LLVM. A set of `if_has_` functions are provided by 173 | `@local_llvm//:llvm_config.bzl` generated skylark file. Every function returns its first argument 174 | when the target `` is supported, otherwise it returns the second argument. The function 175 | is usable through the following way (see the `//:llvm_print_supported_targets` target in 176 | the `examples/BUILD` file): 177 | 178 | ```bzl 179 | load("@local_llvm//:llvm_config.bzl", 180 | "llvm_copts", 181 | "if_has_aarch64", 182 | ... 183 | "if_has_x86") 184 | 185 | cc_binary( 186 | name = "llvm_print_supported_targets", 187 | srcs = [ 188 | ... 189 | ], 190 | copts = llvm_copts() 191 | + if_has_aarch64(["-DLLVM_SUPPORTS_TARGET_AARCH64"]) 192 | ... 193 | + if_has_x86(["-DLLVM_SUPPORTS_TARGET_X86"]), 194 | deps = if_has_aarch64([ 195 | "@local_llvm//:llvm_aarch64_asm_parser", 196 | "@local_llvm//:llvm_aarch64_code_gen", 197 | "@local_llvm//:llvm_aarch64_disassembler", 198 | ]) + 199 | ... 200 | + if_has_x86([ 201 | "@local_llvm//:llvm_x86_asm_parser", 202 | "@local_llvm//:llvm_x86_code_gen", 203 | "@local_llvm//:llvm_x86_disassembler", 204 | ]) 205 | ) 206 | ``` 207 | 208 | ### How to deal with tablegen 209 | 210 | LLVM, Clang and MLIR are very intensive users of the [tablegen](https://llvm.org/docs/TableGen/) tool. 211 | For example, MLIR's Table-driven 212 | [Declarative Rewrite Rule](https://github.com/llvm/llvm-project/blob/master/mlir/docs/DeclarativeRewrites.md) 213 | is based upon tablegen. Fortunately, **bazel-llvm-bridge** provides a rule to run the tablegen 214 | tools for LLVM as well as for MLIR (`llvm-tblgen` and `mlir-tblgen` respectively). The rules are defined 215 | in the `llvm_tablegen.bzl` and `mlir_tablegen.bzl` files. 216 | 217 | To run the tablegen tool, the user should define one or more targets based on the `_tablegen` 218 | rule in a BUILD file. The targets can be used by any other `cc_` ones as dependencies and also 219 | can depend on any `cc_library` (the tablegen tool will use includes and headers provided by such 220 | libraries). For example: 221 | 222 | ```bzl 223 | load("@local_llvm//:llvm_tablegen.bzl", "tablegen") 224 | 225 | cc_binary( 226 | name = 'llvm_print_physical_registers', 227 | ... 228 | deps = [ 229 | ... 230 | ":tablegen_registers", 231 | ], 232 | visibility = ["//visibility:private"], 233 | ) 234 | 235 | tablegen( 236 | name = "tablegen_registers", 237 | srcs = [ 238 | "llvm/target/custom_register_class.td", 239 | ], 240 | src = "llvm/target/custom_register_info.td", 241 | out = "target/custom_register_info.inc", 242 | opts = ["-gen-register-info"], 243 | deps = ["@local_llvm//:headers"], 244 | visibility = ["//visibility:private"], 245 | ) 246 | ``` 247 | 248 | Notice: a target should be defined for every tablegen invocation. 249 | 250 | The `_tablegen` rule has the following attributes: 251 | * name - the target's name. 252 | * src - the tablegen (.td) file to be the input of the tablegen tool. 253 | * srcs - the tablegen and other files used by the 'src' file. This attribute may be 254 | required for sandboxing. 255 | * out - the generated file's name. Can be prefixed with any number of folders 256 | (for example, `toy/Ops.h.inc`). 257 | * opts - command line options for the tablegen tool. 258 | * deps - the list of libraries that provide includes for the .td file. 259 | * includes - the list of include dirs to be added to the command line. 260 | 261 | ### How to deal with Clang/LLVM/MLIR shared libraries 262 | 263 | Important note for users of the `libclang`, `libclang-cpp` and `LLVM-C` shared 264 | libraries. There are three rules to bring these libraries from the LLVM 265 | installation into the `bazel-bin`: `clang_copy_libclang`, `clang_copy_libclang_cpp` 266 | and `llvm_copy_c`. Just add the targets into the `data` attribute of a rule and 267 | they will appear in a `bazel-bin/external/` 268 | directory. Then the libraries can be copied into the `bazel-bin` (see genrules 269 | in the `examples/BUILD` file) and be used for running your applications. 270 | 271 | ### Linking against the libc++ standard library 272 | 273 | Archives hosted on the http://releases.llvm.org/download.html official website 274 | are usually built against the libc++ standard library. A configuration has been 275 | added to the `examples/.bazelrc` file to make Bazel link the targets against 276 | libc++. To enable the configuration, an `examples/libcxx.bazelrc` file must 277 | be generated, the file contains a set of `BAZEL_...` repository environment 278 | variable to let Bazel know where to look for libc++'s headers and the shared 279 | library file. 280 | 281 | To generate the file, a python script, `generate_libcxx_bazelrc.py`, was 282 | developed and placed into the `examples` directory. The script accepts two 283 | parameters: `-I` and 284 | `-L`. For example: 285 | 286 | ```bash 287 | $ python3 generate_libcxx_bazelrc.py -L/home/user/llvm/lib -I/home/user/llvm/include/c++/v1 288 | ``` 289 | 290 | Once a `libcxx.bazelrc` file has been generated, a build can be started with `--config=libc++` 291 | option: 292 | 293 | ```bash 294 | $ bazel build --repo_env LLVM_INSTALL_PREFIX=/home/user/llvm --config=libc++ //:clang_list_methods 295 | ``` 296 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | ## 2 | ## Workspace - using an external prebuilt llvm 3 | ## 4 | 5 | workspace(name = "bazel_llvm_bridge") 6 | -------------------------------------------------------------------------------- /examples/.bazelrc: -------------------------------------------------------------------------------- 1 | # configuration file for bazel-llvm-bridge examples. 2 | # This file groups build options for examples by systems, compilers 3 | # and system libraries. 4 | # 5 | # Linux options: 6 | # opt: Enables linux-compiler optimizations. 7 | # libc++: Enables the libc++ implementation of the standard C++ 8 | # library. The compiler-rt and unwind libraries will be 9 | # enabled if libc++ is configured to use them. 10 | # 11 | # macOS options: (have not been tested yet) 12 | # opt: Enables mac-compiler optimizations. 13 | # 14 | # Windows options: 15 | # clang-cl: Enables the clang-cl compiler on Windows 16 | # opt: Enables clang-cl specific optimizations. 17 | # opt-msvc: Enables MSVC-specific optimizations. 18 | # 19 | 20 | 21 | # Enable using platform specific build settings 22 | build --enable_platform_specific_config 23 | 24 | # Enable using toolchain resolution 25 | build --incompatible_enable_cc_toolchain_resolution 26 | 27 | # Enable common optimization for almost all compilers 28 | build:opt -c opt 29 | build:opt --copt=-march=native 30 | 31 | # Enable MSVC-specific optimizations 32 | build:opt-msvc -c opt 33 | build:opt-msvc --copt=/arch:AVX2 34 | 35 | # Enable clang-cl compiler 36 | build:clang-cl --extra_execution_platforms=//:x64_windows-clang-cl 37 | build:clang-cl --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl 38 | 39 | # Enable linking against the libc++ standard implementation 40 | try-import %workspace%/libcxx.bazelrc 41 | 42 | # Linux configs 43 | build:linux --copt=-Wall 44 | build:linux --copt=-Wextra 45 | build:linux --cxxopt=-std=c++17 46 | 47 | # macOS configs 48 | build:macos --copt=-Wall 49 | build:macos --copt=-Wextra 50 | build:macos --cxxopt=-std=c++17 51 | 52 | # Windows configs 53 | build:windows --copt=/W3 54 | build:windows --cxxopt=/std:c++17 55 | -------------------------------------------------------------------------------- /examples/BUILD: -------------------------------------------------------------------------------- 1 | ## 2 | ## Build - examples of using an external prebuilt llvm 3 | ## 4 | 5 | config_setting( 6 | name = "linux_x86_64", 7 | constraint_values = [ 8 | "@platforms//os:linux", 9 | "@platforms//cpu:x86_64", 10 | ], 11 | visibility = ["//visibility:public"], 12 | ) 13 | 14 | config_setting( 15 | name = "macos_x86_64", 16 | constraint_values = [ 17 | "@platforms//os:osx", 18 | "@platforms//cpu:x86_64", 19 | ], 20 | visibility = ["//visibility:public"], 21 | ) 22 | 23 | config_setting( 24 | name = "windows_x86_64", 25 | constraint_values = [ 26 | "@platforms//os:windows", 27 | "@platforms//cpu:x86_64", 28 | ], 29 | visibility = ["//visibility:public"], 30 | ) 31 | 32 | load("@local_llvm//:llvm_config.bzl", 33 | "llvm_nix_copts", 34 | "llvm_win_copts", 35 | "if_has_aarch64", 36 | "if_has_amdgpu", 37 | "if_has_arm", 38 | "if_has_avr", 39 | "if_has_bpf", 40 | "if_has_hexagon", 41 | "if_has_lanai", 42 | "if_has_mips", 43 | "if_has_msp430", 44 | "if_has_nvptx", 45 | "if_has_powerpc", 46 | "if_has_riscv", 47 | "if_has_sparc", 48 | "if_has_system_z", 49 | "if_has_web_assembly", 50 | "if_has_x86", 51 | "if_has_x_core") 52 | 53 | load("@local_llvm//:llvm_tablegen.bzl", "tablegen") 54 | 55 | llvm_copts = select({ 56 | ":linux_x86_64": llvm_nix_copts, 57 | ":macos_x86_64": llvm_nix_copts, 58 | ":windows_x86_64": llvm_win_copts, 59 | "//conditions:default": [], 60 | }) 61 | 62 | # Example: do nothing, just link a cc-file with all the LLVM libraries. 63 | # This example checks the dependency chain for each library. 64 | # Usage: llvm_check_dependencies 65 | cc_binary( 66 | name = 'llvm_check_dependencies', 67 | srcs = [ 68 | "llvm/llvm_empty_main.cc", 69 | ], 70 | copts = llvm_copts, 71 | deps = [ 72 | "@local_llvm//:config_headers", 73 | "@local_llvm//:headers", 74 | "@local_llvm//:aggressive_inst_combine", 75 | "@local_llvm//:analysis", 76 | "@local_llvm//:asm_parser", 77 | "@local_llvm//:asm_printer", 78 | "@local_llvm//:binary_format", 79 | "@local_llvm//:bit_reader", 80 | "@local_llvm//:bit_writer", 81 | "@local_llvm//:bitstream_reader", 82 | "@local_llvm//:cf_guard", 83 | "@local_llvm//:code_gen", 84 | "@local_llvm//:core", 85 | "@local_llvm//:coroutines", 86 | "@local_llvm//:coverage", 87 | "@local_llvm//:debug_info_code_view", 88 | "@local_llvm//:debug_info_dwarf", 89 | "@local_llvm//:debug_info_gsym", 90 | "@local_llvm//:debug_info_msf", 91 | "@local_llvm//:debug_info_pdb", 92 | "@local_llvm//:demangle", 93 | "@local_llvm//:dlltool_driver", 94 | "@local_llvm//:dwarf_linker", 95 | "@local_llvm//:execution_engine", 96 | "@local_llvm//:extensions", 97 | "@local_llvm//:file_check", 98 | "@local_llvm//:frontend_open_acc", 99 | "@local_llvm//:frontend_open_mp", 100 | "@local_llvm//:fuzz_mutate", 101 | "@local_llvm//:global_i_sel", 102 | "@local_llvm//:inst_combine", 103 | "@local_llvm//:instrumentation", 104 | "@local_llvm//:interface_stub", 105 | "@local_llvm//:interpreter", 106 | "@local_llvm//:ir_reader", 107 | "@local_llvm//:ipo", 108 | "@local_llvm//:jit_link", 109 | "@local_llvm//:lib_driver", 110 | "@local_llvm//:line_editor", 111 | "@local_llvm//:linker", 112 | "@local_llvm//:lto", 113 | "@local_llvm//:mc", 114 | "@local_llvm//:mca", 115 | "@local_llvm//:mc_disassembler", 116 | "@local_llvm//:mcjit", 117 | "@local_llvm//:mc_parser", 118 | "@local_llvm//:mir_parser", 119 | "@local_llvm//:objc_arc", 120 | "@local_llvm//:object", 121 | "@local_llvm//:object_yaml", 122 | "@local_llvm//:option", 123 | "@local_llvm//:orc_jit", 124 | "@local_llvm//:orc_shared", 125 | "@local_llvm//:orc_target_process", 126 | "@local_llvm//:passes", 127 | "@local_llvm//:profile_data", 128 | "@local_llvm//:remarks", 129 | "@local_llvm//:runtime_dyld", 130 | "@local_llvm//:scalar", 131 | "@local_llvm//:selection_dag", 132 | "@local_llvm//:support", 133 | "@local_llvm//:symbolize", 134 | "@local_llvm//:tablegen", 135 | "@local_llvm//:target", 136 | "@local_llvm//:text_api", 137 | "@local_llvm//:transform_utils", 138 | "@local_llvm//:vectorize", 139 | "@local_llvm//:windows_manifest", 140 | "@local_llvm//:x_ray", 141 | ] + if_has_aarch64([ 142 | "@local_llvm//:aarch64_asm_parser", 143 | "@local_llvm//:aarch64_code_gen", 144 | "@local_llvm//:aarch64_desc", 145 | "@local_llvm//:aarch64_disassembler", 146 | "@local_llvm//:aarch64_info", 147 | "@local_llvm//:aarch64_utils", 148 | ]) + if_has_amdgpu([ 149 | "@local_llvm//:amdgpu_asm_parser", 150 | "@local_llvm//:amdgpu_code_gen", 151 | "@local_llvm//:amdgpu_desc", 152 | "@local_llvm//:amdgpu_disassembler", 153 | "@local_llvm//:amdgpu_info", 154 | "@local_llvm//:amdgpu_utils", 155 | ]) + if_has_arm([ 156 | "@local_llvm//:arm_asm_parser", 157 | "@local_llvm//:arm_code_gen", 158 | "@local_llvm//:arm_desc", 159 | "@local_llvm//:arm_disassembler", 160 | "@local_llvm//:arm_info", 161 | "@local_llvm//:arm_utils", 162 | ]) + if_has_avr([ 163 | "@local_llvm//:avr_asm_parser", 164 | "@local_llvm//:avr_code_gen", 165 | "@local_llvm//:avr_desc", 166 | "@local_llvm//:avr_disassembler", 167 | "@local_llvm//:avr_info", 168 | ]) + if_has_bpf([ 169 | "@local_llvm//:bpf_asm_parser", 170 | "@local_llvm//:bpf_code_gen", 171 | "@local_llvm//:bpf_desc", 172 | "@local_llvm//:bpf_disassembler", 173 | "@local_llvm//:bpf_info", 174 | ]) + if_has_hexagon([ 175 | "@local_llvm//:hexagon_asm_parser", 176 | "@local_llvm//:hexagon_code_gen", 177 | "@local_llvm//:hexagon_desc", 178 | "@local_llvm//:hexagon_disassembler", 179 | "@local_llvm//:hexagon_info", 180 | ]) + if_has_lanai([ 181 | "@local_llvm//:lanai_asm_parser", 182 | "@local_llvm//:lanai_code_gen", 183 | "@local_llvm//:lanai_desc", 184 | "@local_llvm//:lanai_disassembler", 185 | "@local_llvm//:lanai_info", 186 | ]) + if_has_mips([ 187 | "@local_llvm//:mips_asm_parser", 188 | "@local_llvm//:mips_code_gen", 189 | "@local_llvm//:mips_desc", 190 | "@local_llvm//:mips_disassembler", 191 | "@local_llvm//:mips_info", 192 | ]) + if_has_msp430([ 193 | "@local_llvm//:msp430_asm_parser", 194 | "@local_llvm//:msp430_code_gen", 195 | "@local_llvm//:msp430_desc", 196 | "@local_llvm//:msp430_disassembler", 197 | "@local_llvm//:msp430_info", 198 | ]) + if_has_nvptx([ 199 | "@local_llvm//:nvptx_code_gen", 200 | "@local_llvm//:nvptx_desc", 201 | "@local_llvm//:nvptx_info", 202 | ]) + if_has_powerpc([ 203 | "@local_llvm//:powerpc_asm_parser", 204 | "@local_llvm//:powerpc_code_gen", 205 | "@local_llvm//:powerpc_desc", 206 | "@local_llvm//:powerpc_disassembler", 207 | "@local_llvm//:powerpc_info", 208 | ]) + if_has_riscv([ 209 | "@local_llvm//:riscv_asm_parser", 210 | "@local_llvm//:riscv_code_gen", 211 | "@local_llvm//:riscv_desc", 212 | "@local_llvm//:riscv_disassembler", 213 | "@local_llvm//:riscv_info", 214 | ]) + if_has_sparc([ 215 | "@local_llvm//:sparc_asm_parser", 216 | "@local_llvm//:sparc_code_gen", 217 | "@local_llvm//:sparc_desc", 218 | "@local_llvm//:sparc_disassembler", 219 | "@local_llvm//:sparc_info", 220 | ]) + if_has_system_z([ 221 | "@local_llvm//:system_z_asm_parser", 222 | "@local_llvm//:system_z_code_gen", 223 | "@local_llvm//:system_z_desc", 224 | "@local_llvm//:system_z_disassembler", 225 | "@local_llvm//:system_z_info", 226 | ]) + if_has_web_assembly([ 227 | "@local_llvm//:web_assembly_asm_parser", 228 | "@local_llvm//:web_assembly_code_gen", 229 | "@local_llvm//:web_assembly_desc", 230 | "@local_llvm//:web_assembly_disassembler", 231 | "@local_llvm//:web_assembly_info", 232 | ]) + if_has_x86([ 233 | "@local_llvm//:x86_asm_parser", 234 | "@local_llvm//:x86_code_gen", 235 | "@local_llvm//:x86_desc", 236 | "@local_llvm//:x86_disassembler", 237 | "@local_llvm//:x86_info", 238 | ]) + if_has_x_core([ 239 | "@local_llvm//:x_core_code_gen", 240 | "@local_llvm//:x_core_desc", 241 | "@local_llvm//:x_core_disassembler", 242 | "@local_llvm//:x_core_info", 243 | ]), 244 | visibility = ["//visibility:private"], 245 | ) 246 | 247 | # Example: taking the bit_reader library as well as LLVM's headers into 248 | # account. The 'llvm_bb_counter' application returns how many basic blocks 249 | # has every function in a bit code file. 250 | # Usage: llvm_bb_counter 251 | cc_binary( 252 | name = 'llvm_bb_counter', 253 | srcs = [ 254 | "llvm/llvm_bb_counter.cc", 255 | ], 256 | copts = llvm_copts, 257 | deps = [ 258 | "@local_llvm//:headers", 259 | "@local_llvm//:bit_reader", 260 | ], 261 | visibility = ["//visibility:private"], 262 | ) 263 | 264 | # Example: taking the core library as well as LLVM's headers into 265 | # account. Some custom IR passes are combined into a static library. 266 | # The 'alwayslink' flag is required to demonstrate how dependencies 267 | # are used. Without the flag, symbols not used by an application 268 | # linked against will just be ignored. 269 | cc_library( 270 | name = "llvm_exp_passes", 271 | srcs = [ 272 | "llvm/function_argument_usage_pass.cc", 273 | ], 274 | copts = llvm_copts, 275 | deps = [ 276 | "@local_llvm//:headers", 277 | "@local_llvm//:core", 278 | ], 279 | alwayslink = 1, # this is required to get a link error when 280 | # a dependency has been missed 281 | visibility = ["//visibility:public"], 282 | ) 283 | 284 | # Example: an application is just developed to be linked against the 285 | # 'llvm_exp_passes' static library. The application does nothing but 286 | # all dependencies must be satisfied to let the application be linked. 287 | # Usage: llvm_exp_passes_linked 288 | cc_binary( 289 | name = "llvm_exp_passes_linked", 290 | srcs = [ 291 | "llvm/llvm_empty_main.cc", 292 | ], 293 | copts = llvm_copts, 294 | deps = [ 295 | ":llvm_exp_passes", 296 | ], 297 | visibility = ["//visibility:private"], 298 | ) 299 | 300 | # Example: taking supported by the local installation of LLVM targets into 301 | # account. The example uses many provided 'if_has_' functions to 302 | # define required compiler flags and be linked against required target 303 | # libraries. 304 | # Usage: llvm_print_supported_targets 305 | cc_binary( 306 | name = "llvm_print_supported_targets", 307 | srcs = [ 308 | "llvm/llvm_print_supported_targets.cc", 309 | ], 310 | copts = llvm_copts, 311 | defines = if_has_aarch64(["LLVM_SUPPORTS_TARGET_AARCH64"]) 312 | + if_has_amdgpu(["LLVM_SUPPORTS_TARGET_AMDGPU"]) 313 | + if_has_arm(["LLVM_SUPPORTS_TARGET_ARM"]) 314 | + if_has_avr(["LLVM_SUPPORTS_TARGET_AVR"]) 315 | + if_has_bpf(["LLVM_SUPPORTS_TARGET_BPF"]) 316 | + if_has_hexagon(["LLVM_SUPPORTS_TARGET_HEXAGON"]) 317 | + if_has_lanai(["LLVM_SUPPORTS_TARGET_LANAI"]) 318 | + if_has_mips(["LLVM_SUPPORTS_TARGET_MIPS"]) 319 | + if_has_msp430(["LLVM_SUPPORTS_TARGET_MSP430"]) 320 | + if_has_nvptx(["LLVM_SUPPORTS_TARGET_NVPTX"]) 321 | + if_has_powerpc(["LLVM_SUPPORTS_TARGET_POWERPC"]) 322 | + if_has_riscv(["LLVM_SUPPORTS_TARGET_RISCV"]) 323 | + if_has_sparc(["LLVM_SUPPORTS_TARGET_SPARC"]) 324 | + if_has_system_z(["LLVM_SUPPORTS_TARGET_SYSTEMZ"]) 325 | + if_has_web_assembly(["LLVM_SUPPORTS_TARGET_WEBASSEMBLY"]) 326 | + if_has_x86(["LLVM_SUPPORTS_TARGET_X86"]) 327 | + if_has_x_core(["LLVM_SUPPORTS_TARGET_XCORE"]), 328 | deps = if_has_aarch64([ 329 | "@local_llvm//:aarch64_asm_parser", 330 | "@local_llvm//:aarch64_code_gen", 331 | "@local_llvm//:aarch64_disassembler", 332 | ]) + if_has_amdgpu([ 333 | "@local_llvm//:amdgpu_asm_parser", 334 | "@local_llvm//:amdgpu_code_gen", 335 | "@local_llvm//:amdgpu_disassembler", 336 | ]) + if_has_arm([ 337 | "@local_llvm//:arm_asm_parser", 338 | "@local_llvm//:arm_code_gen", 339 | "@local_llvm//:arm_disassembler", 340 | ]) + if_has_avr([ 341 | "@local_llvm//:avr_asm_parser", 342 | "@local_llvm//:avr_code_gen", 343 | "@local_llvm//:avr_disassembler", 344 | ]) + if_has_bpf([ 345 | "@local_llvm//:bpf_asm_parser", 346 | "@local_llvm//:bpf_code_gen", 347 | "@local_llvm//:bpf_disassembler", 348 | ]) + if_has_hexagon([ 349 | "@local_llvm//:hexagon_asm_parser", 350 | "@local_llvm//:hexagon_code_gen", 351 | "@local_llvm//:hexagon_disassembler", 352 | ]) + if_has_lanai([ 353 | "@local_llvm//:lanai_asm_parser", 354 | "@local_llvm//:lanai_code_gen", 355 | "@local_llvm//:lanai_disassembler", 356 | ]) + if_has_mips([ 357 | "@local_llvm//:mips_asm_parser", 358 | "@local_llvm//:mips_code_gen", 359 | "@local_llvm//:mips_disassembler", 360 | ]) + if_has_msp430([ 361 | "@local_llvm//:msp430_asm_parser", 362 | "@local_llvm//:msp430_code_gen", 363 | "@local_llvm//:msp430_disassembler", 364 | ]) + if_has_nvptx([ 365 | "@local_llvm//:nvptx_code_gen", 366 | ]) + if_has_powerpc([ 367 | "@local_llvm//:powerpc_asm_parser", 368 | "@local_llvm//:powerpc_code_gen", 369 | "@local_llvm//:powerpc_disassembler", 370 | ]) + if_has_riscv([ 371 | "@local_llvm//:riscv_asm_parser", 372 | "@local_llvm//:riscv_code_gen", 373 | "@local_llvm//:riscv_disassembler", 374 | ]) + if_has_sparc([ 375 | "@local_llvm//:sparc_asm_parser", 376 | "@local_llvm//:sparc_code_gen", 377 | "@local_llvm//:sparc_disassembler", 378 | ]) + if_has_system_z([ 379 | "@local_llvm//:system_z_asm_parser", 380 | "@local_llvm//:system_z_code_gen", 381 | "@local_llvm//:system_z_disassembler", 382 | ]) + if_has_web_assembly([ 383 | "@local_llvm//:web_assembly_asm_parser", 384 | "@local_llvm//:web_assembly_code_gen", 385 | "@local_llvm//:web_assembly_disassembler", 386 | ]) + if_has_x86([ 387 | "@local_llvm//:x86_asm_parser", 388 | "@local_llvm//:x86_code_gen", 389 | "@local_llvm//:x86_disassembler", 390 | ]) + if_has_x_core([ 391 | "@local_llvm//:x_core_code_gen", 392 | "@local_llvm//:x_core_disassembler", 393 | ]), 394 | ) 395 | 396 | # Example: print physical registers for an imaginary custom target. 397 | # This example demonstrates how to use llvm-tablegen as a dependency. 398 | # Usage: llvm_print_physical_registers 399 | cc_binary( 400 | name = 'llvm_print_physical_registers', 401 | srcs = [ 402 | "llvm/target/custom_frame_lowering.h", 403 | "llvm/target/custom_register_info.h", 404 | "llvm/target/custom_frame_lowering.cc", 405 | "llvm/target/custom_mc_target_desc.cc", 406 | "llvm/target/custom_register_info.cc", 407 | "llvm/llvm_print_physical_registers.cc", 408 | ], 409 | copts = llvm_copts, 410 | deps = [ 411 | "@local_llvm//:headers", 412 | "@local_llvm//:code_gen", 413 | "@local_llvm//:support", 414 | ":tablegen_registers", 415 | ], 416 | visibility = ["//visibility:private"], 417 | ) 418 | 419 | # Generates a custom_register_class.inc include using the llvm_tablegen 420 | # rule and llvm-tblgen tool. 421 | tablegen( 422 | name = "tablegen_registers", 423 | srcs = [ 424 | "llvm/target/custom_register_class.td", 425 | ], 426 | src = "llvm/target/custom_register_info.td", 427 | out = "target/custom_register_info.inc", 428 | opts = ["-gen-register-info"], 429 | deps = ["@local_llvm//:headers"], 430 | visibility = ["//visibility:private"], 431 | ) 432 | 433 | # Example: taking a platform specific libclang shared library 434 | # into account. The example uses automatically defined 435 | # 'copy_local_llvm_shared_' dependency to make a copy of the 436 | # libclang library in the 'bazel-bin' directory. On *nix platforms 437 | # the example linked so that to look for the library in the current directory. 438 | # The application reads function declaration and definition from a c/c++ code. 439 | # Usage: cd ./bazel-bin/ && ./clang_list_methods 440 | cc_binary( 441 | name = 'clang_list_methods', 442 | srcs = [ 443 | "clang/clang_list_methods.cc", 444 | ], 445 | copts = llvm_copts, 446 | data = select({ 447 | ":linux_x86_64": [ 448 | "copy_local_llvm_shared_lin", 449 | ], 450 | ":macos_x86_64": [ 451 | "copy_local_llvm_shared_mac", 452 | ], 453 | ":windows_x86_64": [ 454 | "copy_local_llvm_shared_win", 455 | ], 456 | "//conditions:default": [], 457 | }), 458 | deps = [ 459 | "@local_llvm//:cl_headers", 460 | "@local_llvm//:cl_libclang", 461 | "@local_llvm//:config_headers", 462 | "@local_llvm//:headers", 463 | "@local_llvm//:support", 464 | ], 465 | linkopts = select({ 466 | ":linux_x86_64": [ 467 | "-Wl,-R -Wl,." 468 | ], 469 | ":macos_x86_64": [ 470 | "-Wl,-R -Wl,." 471 | ], 472 | ":windows_x86_64": [ 473 | ], 474 | "//conditions:default": [], 475 | }), 476 | visibility = ["//visibility:private"], 477 | ) 478 | 479 | # Example: do nothing, just link a cc-file with all the Clang libraries. 480 | # This example checks the dependency chain for each library. 481 | # Usage: clang_check_dependencies 482 | cc_binary( 483 | name = 'clang_check_dependencies', 484 | srcs = [ 485 | "clang/clang_empty_main.cc", 486 | ], 487 | copts = llvm_copts, 488 | data = select({ 489 | ":linux_x86_64": [ 490 | "copy_local_llvm_shared_lin", 491 | ], 492 | ":macos_x86_64": [ 493 | "copy_local_llvm_shared_mac", 494 | ], 495 | ":windows_x86_64": [ 496 | "copy_local_llvm_shared_win", 497 | ], 498 | "//conditions:default": [], 499 | }), 500 | deps = [ 501 | "@local_llvm//:config_headers", 502 | "@local_llvm//:cl_headers", 503 | "@local_llvm//:cl_analysis", 504 | "@local_llvm//:cl_api_notes", 505 | "@local_llvm//:cl_arc_migrate", 506 | "@local_llvm//:cl_ast", 507 | "@local_llvm//:cl_ast_matchers", 508 | "@local_llvm//:cl_basic", 509 | "@local_llvm//:cl_code_gen", 510 | "@local_llvm//:cl_cross_tu", 511 | "@local_llvm//:cl_dependency_scanning", 512 | "@local_llvm//:cl_directory_watcher", 513 | "@local_llvm//:cl_driver", 514 | "@local_llvm//:cl_dynamic_ast_matchers", 515 | "@local_llvm//:cl_edit", 516 | "@local_llvm//:cl_format", 517 | "@local_llvm//:cl_frontend", 518 | "@local_llvm//:cl_frontend_tool", 519 | "@local_llvm//:cl_handle_cxx", 520 | "@local_llvm//:cl_handle_llvm", 521 | "@local_llvm//:cl_index", 522 | "@local_llvm//:cl_index_serialization", 523 | "@local_llvm//:cl_lex", 524 | "@local_llvm//:cl_libclang", 525 | "@local_llvm//:cl_parse", 526 | "@local_llvm//:cl_rewrite", 527 | "@local_llvm//:cl_rewrite_frontend", 528 | "@local_llvm//:cl_sema", 529 | "@local_llvm//:cl_serialization", 530 | "@local_llvm//:cl_static_analyzer_checkers", 531 | "@local_llvm//:cl_static_analyzer_core", 532 | "@local_llvm//:cl_static_analyzer_frontend", 533 | "@local_llvm//:cl_testing", 534 | "@local_llvm//:cl_tooling", 535 | "@local_llvm//:cl_tooling_ast_diff", 536 | "@local_llvm//:cl_tooling_core", 537 | "@local_llvm//:cl_tooling_inclusions", 538 | "@local_llvm//:cl_tooling_refactoring", 539 | "@local_llvm//:cl_tooling_syntax", 540 | "@local_llvm//:cl_transformer", 541 | ] + select({ 542 | ":linux_x86_64": ["@local_llvm//:cl_libclang_cpp"], 543 | ":macos_x86_64": ["@local_llvm//:cl_libclang_cpp"], 544 | "//conditions:default": [], 545 | }), 546 | linkopts = select({ 547 | ":linux_x86_64": [ 548 | "-Wl,-R -Wl,." 549 | ], 550 | ":macos_x86_64": [ 551 | "-Wl,-R -Wl,." 552 | ], 553 | ":windows_x86_64": [ 554 | ], 555 | "//conditions:default": [], 556 | }), 557 | visibility = ["//visibility:private"], 558 | ) 559 | 560 | # Example: do nothing, just link a cc-file with all the MLIR libraries. 561 | # This example checks the dependency chain for each library. 562 | # Usage: mlir_check_dependencies 563 | cc_binary( 564 | name = 'mlir_check_dependencies', 565 | srcs = [ 566 | "mlir/mlir_empty_main.cc", 567 | ], 568 | copts = llvm_copts, 569 | data = select({ 570 | ":linux_x86_64": [ 571 | "copy_mlir_runner_shared_lin", 572 | ], 573 | ":macos_x86_64": [ 574 | "copy_mlir_runner_shared_mac", 575 | ], 576 | ":windows_x86_64": [ 577 | "copy_mlir_runner_shared_win", 578 | ], 579 | "//conditions:default": [], 580 | }), 581 | deps = [ 582 | "@local_llvm//:headers", 583 | "@local_llvm//:ml_headers", 584 | "@local_llvm//:ml_affine", 585 | "@local_llvm//:ml_affine_edsc", 586 | "@local_llvm//:ml_affine_to_standard", 587 | "@local_llvm//:ml_affine_transforms", 588 | "@local_llvm//:ml_affine_utils", 589 | "@local_llvm//:ml_analysis", 590 | "@local_llvm//:ml_arm_neon", 591 | "@local_llvm//:ml_arm_sve", 592 | "@local_llvm//:ml_arm_neon_to_llvm", 593 | "@local_llvm//:ml_arm_sve_to_llvm", 594 | "@local_llvm//:ml_async", 595 | "@local_llvm//:ml_async_runtime", 596 | "@local_llvm//:ml_async_to_llvm", 597 | "@local_llvm//:ml_async_transforms", 598 | "@local_llvm//:ml_avx512", 599 | "@local_llvm//:ml_avx512_to_llvm", 600 | "@local_llvm//:ml_c_runner_utils", 601 | "@local_llvm//:ml_c_runner_utils_static", 602 | "@local_llvm//:ml_call_interfaces", 603 | "@local_llvm//:ml_capi_ir", 604 | "@local_llvm//:ml_capi_linalg", 605 | "@local_llvm//:ml_capi_registration", 606 | "@local_llvm//:ml_capi_scf", 607 | "@local_llvm//:ml_capi_shape", 608 | "@local_llvm//:ml_capi_standard", 609 | "@local_llvm//:ml_capi_tensor", 610 | "@local_llvm//:ml_capi_transforms", 611 | "@local_llvm//:ml_cast_interfaces", 612 | "@local_llvm//:ml_complex", 613 | "@local_llvm//:ml_complex_to_llvm", 614 | "@local_llvm//:ml_control_flow_interfaces", 615 | "@local_llvm//:ml_copy_op_interface", 616 | "@local_llvm//:ml_derived_attribute_op_interface", 617 | "@local_llvm//:ml_dialect", 618 | "@local_llvm//:ml_edsc", 619 | "@local_llvm//:ml_execution_engine", 620 | "@local_llvm//:ml_gpu", 621 | "@local_llvm//:ml_gpu_to_gpu_runtime_transforms", 622 | "@local_llvm//:ml_gpu_to_nvvm_transforms", 623 | "@local_llvm//:ml_gpu_to_rocdl_transforms", 624 | "@local_llvm//:ml_gpu_to_spirv", 625 | "@local_llvm//:ml_gpu_to_vulkan_transforms", 626 | "@local_llvm//:ml_infer_type_op_interface", 627 | "@local_llvm//:ml_ir", 628 | "@local_llvm//:ml_jit_runner", 629 | "@local_llvm//:ml_linalg", 630 | "@local_llvm//:ml_linalg_analysis", 631 | "@local_llvm//:ml_linalg_edsc", 632 | "@local_llvm//:ml_linalg_to_llvm", 633 | "@local_llvm//:ml_linalg_to_spirv", 634 | "@local_llvm//:ml_linalg_to_standard", 635 | "@local_llvm//:ml_linalg_transforms", 636 | "@local_llvm//:ml_linalg_utils", 637 | "@local_llvm//:ml_llvm_arm_neon", 638 | "@local_llvm//:ml_llvm_arm_sve", 639 | "@local_llvm//:ml_llvm_avx512", 640 | "@local_llvm//:ml_llvm_ir", 641 | "@local_llvm//:ml_llvm_ir_transforms", 642 | "@local_llvm//:ml_loop_analysis", 643 | "@local_llvm//:ml_loop_like_interface", 644 | "@local_llvm//:ml_mlir_opt_main", 645 | "@local_llvm//:ml_nvvm_ir", 646 | "@local_llvm//:ml_open_acc", 647 | "@local_llvm//:ml_open_mp", 648 | "@local_llvm//:ml_open_mp_to_llvm", 649 | "@local_llvm//:ml_opt_lib", 650 | "@local_llvm//:ml_parser", 651 | "@local_llvm//:ml_pass", 652 | "@local_llvm//:ml_pdl", 653 | "@local_llvm//:ml_pdl_interp", 654 | "@local_llvm//:ml_pdl_to_pdl_interp", 655 | "@local_llvm//:ml_presburger", 656 | "@local_llvm//:ml_public_api", 657 | "@local_llvm//:ml_quant", 658 | "@local_llvm//:ml_reduce", 659 | "@local_llvm//:ml_rewrite", 660 | "@local_llvm//:ml_rocdl_ir", 661 | "@local_llvm//:ml_runner_utils", 662 | "@local_llvm//:ml_scf", 663 | "@local_llvm//:ml_scf_to_gpu", 664 | "@local_llvm//:ml_scf_to_open_mp", 665 | "@local_llvm//:ml_scf_to_spirv", 666 | "@local_llvm//:ml_scf_to_standard", 667 | "@local_llvm//:ml_scf_transforms", 668 | "@local_llvm//:ml_sdbm", 669 | "@local_llvm//:ml_shape", 670 | "@local_llvm//:ml_shape_ops_transforms", 671 | "@local_llvm//:ml_shape_to_standard", 672 | "@local_llvm//:ml_side_effect_interfaces", 673 | "@local_llvm//:ml_spirv", 674 | "@local_llvm//:ml_spirv_binary_utils", 675 | "@local_llvm//:ml_spirv_conversion", 676 | "@local_llvm//:ml_spirv_deserialization", 677 | "@local_llvm//:ml_spirv_module_combiner", 678 | "@local_llvm//:ml_spirv_serialization", 679 | "@local_llvm//:ml_spirv_to_llvm", 680 | "@local_llvm//:ml_spirv_transforms", 681 | "@local_llvm//:ml_spirv_translate_registration", 682 | "@local_llvm//:ml_spirv_utils", 683 | "@local_llvm//:ml_standard", 684 | "@local_llvm//:ml_standard_ops_transforms", 685 | "@local_llvm//:ml_standard_to_llvm", 686 | "@local_llvm//:ml_standard_to_spirv", 687 | "@local_llvm//:ml_support", 688 | "@local_llvm//:ml_support_indented_ostream", 689 | "@local_llvm//:ml_tablegen", 690 | "@local_llvm//:ml_target_arm_neon", 691 | "@local_llvm//:ml_target_arm_sve", 692 | "@local_llvm//:ml_target_avx512", 693 | "@local_llvm//:ml_target_llvm_ir", 694 | "@local_llvm//:ml_target_llvm_ir_module_translation", 695 | "@local_llvm//:ml_target_nvvm_ir", 696 | "@local_llvm//:ml_target_rocdl_ir", 697 | "@local_llvm//:ml_tensor", 698 | "@local_llvm//:ml_tensor_transforms", 699 | "@local_llvm//:ml_tosa", 700 | "@local_llvm//:ml_tosa_to_linalg", 701 | "@local_llvm//:ml_tosa_transforms", 702 | "@local_llvm//:ml_transforms", 703 | "@local_llvm//:ml_transform_utils", 704 | "@local_llvm//:ml_translation", 705 | "@local_llvm//:ml_vector", 706 | "@local_llvm//:ml_vector_to_llvm", 707 | "@local_llvm//:ml_vector_to_rocdl", 708 | "@local_llvm//:ml_vector_to_scf", 709 | "@local_llvm//:ml_vector_to_spirv", 710 | "@local_llvm//:ml_vector_interfaces", 711 | "@local_llvm//:ml_view_like_interface", 712 | ], 713 | linkopts = select({ 714 | ":linux_x86_64": [ 715 | "-Wl,-R -Wl,." 716 | ], 717 | ":macos_x86_64": [ 718 | "-Wl,-R -Wl,." 719 | ], 720 | ":windows_x86_64": [ 721 | ], 722 | "//conditions:default": [], 723 | }), 724 | visibility = ["//visibility:private"], 725 | ) 726 | 727 | # Copies the libclang and libclang_cpp shared libraries to the 728 | # 'bazel-bin' directory on Linux. 729 | genrule( 730 | name = "copy_local_llvm_shared_lin", 731 | srcs = [ 732 | "@local_llvm//:cl_copy_libclang", 733 | "@local_llvm//:cl_copy_libclang_cpp", 734 | ], 735 | outs = [ 736 | "libclang.so.12git", 737 | "libclang-cpp.so.12git", 738 | ], 739 | cmd = """ 740 | cp -f $(location @local_llvm//:cl_copy_libclang) $(@D)/libclang.so.12git 741 | cp -f $(location @local_llvm//:cl_copy_libclang_cpp) $(@D)/libclang-cpp.so.12git 742 | """, 743 | output_to_bindir = 1, 744 | visibility = ["//visibility:private"], 745 | ) 746 | 747 | # Copies the libclang and libclang_cpp shared libraries to the 748 | # 'bazel-bin' directory on MacOS X. 749 | genrule( 750 | name = "copy_local_llvm_shared_mac", 751 | srcs = [ 752 | "@local_llvm//:cl_copy_libclang", 753 | "@local_llvm//:cl_copy_libclang_cpp", 754 | ], 755 | outs = [ 756 | "libclang.dylib", 757 | "libclang-cpp.dylib", 758 | ], 759 | cmd = """ 760 | cp -f $(location @local_llvm//:cl_copy_libclang) $(@D) 761 | cp -f $(location @local_llvm//:cl_copy_libclang_cpp) $(@D) 762 | """, 763 | output_to_bindir = 1, 764 | visibility = ["//visibility:private"], 765 | ) 766 | 767 | # Copies the libclang and llvm-c shared libraries to the 768 | # 'bazel-bin' directory on Windows. 769 | genrule( 770 | name = "copy_local_llvm_shared_win", 771 | srcs = [ 772 | "@local_llvm//:cl_copy_libclang", 773 | "@local_llvm//:copy_c", 774 | ], 775 | outs = [ 776 | "libclang.dll", 777 | "LLVM-C.dll", 778 | ], 779 | cmd = """ 780 | cp -f $(location @local_llvm//:cl_copy_libclang) $(@D) 781 | cp -f $(location @local_llvm//:copy_c) $(@D) 782 | """, 783 | output_to_bindir = 1, 784 | visibility = ["//visibility:private"], 785 | ) 786 | 787 | # Copies the mlir_runner_utils shared libraries to the 788 | # 'bazel-bin' directory on Linux. 789 | genrule( 790 | name = "copy_mlir_runner_shared_lin", 791 | srcs = [ 792 | "@local_llvm//:ml_copy_async_runtime", 793 | "@local_llvm//:ml_copy_runner_utils", 794 | "@local_llvm//:ml_copy_c_runner_utils", 795 | "@local_llvm//:ml_copy_public_api", 796 | ], 797 | outs = [ 798 | "libmlir_async_runtime.so.12git", 799 | "libmlir_runner_utils.so.12git", 800 | "libmlir_c_runner_utils.so.12git", 801 | "libMLIRPublicAPI.so.12git", 802 | ], 803 | cmd = """ 804 | cp -f $(location @local_llvm//:ml_copy_async_runtime) $(@D)/libmlir_async_runtime.so.12git 805 | cp -f $(location @local_llvm//:ml_copy_runner_utils) $(@D)/libmlir_runner_utils.so.12git 806 | cp -f $(location @local_llvm//:ml_copy_c_runner_utils) $(@D)/libmlir_c_runner_utils.so.12git 807 | cp -f $(location @local_llvm//:ml_copy_public_api) $(@D)/libMLIRPublicAPI.so.12git 808 | """, 809 | output_to_bindir = 1, 810 | visibility = ["//visibility:private"], 811 | ) 812 | 813 | # Copies the mlir_runner_utils shared libraries to the 814 | # 'bazel-bin' directory on MacOS X. 815 | genrule( 816 | name = "copy_mlir_runner_shared_mac", 817 | srcs = [ 818 | "@local_llvm//:ml_copy_async_runtime", 819 | "@local_llvm//:ml_copy_runner_utils", 820 | "@local_llvm//:ml_copy_c_runner_utils", 821 | "@local_llvm//:ml_copy_public_api", 822 | ], 823 | outs = [ 824 | "libmlir_async_runtime.dylib", 825 | "libmlir_runner_utils.dylib", 826 | "libmlir_c_runner_utils.dylib", 827 | "libMLIRPublicAPI.dylib", 828 | ], 829 | cmd = """ 830 | cp -f $(location @local_llvm//:ml_copy_async_runtime) $(@D) 831 | cp -f $(location @local_llvm//:ml_copy_runner_utils) $(@D) 832 | cp -f $(location @local_llvm//:ml_copy_c_runner_utils) $(@D) 833 | cp -f $(location @local_llvm//:ml_copy_public_api) $(@D) 834 | """, 835 | output_to_bindir = 1, 836 | visibility = ["//visibility:private"], 837 | ) 838 | 839 | # Copies the mlir_runner_utils shared libraries to the 840 | # 'bazel-bin' directory on Windows. 841 | genrule( 842 | name = "copy_mlir_runner_shared_win", 843 | srcs = [ 844 | "@local_llvm//:ml_copy_async_runtime", 845 | "@local_llvm//:ml_copy_runner_utils", 846 | "@local_llvm//:ml_copy_c_runner_utils", 847 | "@local_llvm//:ml_copy_public_api", 848 | ], 849 | outs = [ 850 | "mlir_async_runtime.dll", 851 | "mlir_runner_utils.dll", 852 | "mlir_c_runner_utils.dll", 853 | "MLIRPublicAPI.dll", 854 | ], 855 | cmd = """ 856 | cp -f $(location @local_llvm//:ml_copy_async_runtime) $(@D) 857 | cp -f $(location @local_llvm//:ml_copy_runner_utils) $(@D) 858 | cp -f $(location @local_llvm//:ml_copy_c_runner_utils) $(@D) 859 | cp -f $(location @local_llvm//:ml_copy_public_api) $(@D) 860 | """, 861 | output_to_bindir = 1, 862 | visibility = ["//visibility:private"], 863 | ) 864 | 865 | # Platform to enable the clang-cl compiler on Windows 866 | platform( 867 | name = "x64_windows-clang-cl", 868 | constraint_values = [ 869 | "@platforms//cpu:x86_64", 870 | "@platforms//os:windows", 871 | "@bazel_tools//tools/cpp:clang-cl", 872 | ], 873 | ) 874 | -------------------------------------------------------------------------------- /examples/WORKSPACE: -------------------------------------------------------------------------------- 1 | ## 2 | ## Workspace - examples of using an external prebuilt llvm 3 | ## 4 | 5 | workspace(name = "bazel_llvm_bridge_examples") 6 | 7 | local_repository( 8 | name = "bazel_llvm_bridge", 9 | path = "..", 10 | ) 11 | 12 | load("@bazel_llvm_bridge//llvm:llvm_configure.bzl", "llvm_configure") 13 | 14 | llvm_configure( 15 | name = "local_llvm", 16 | llvm_prefix = "", # default value: llvm_ 17 | clang_prefix = "cl_", # default value: clang_ 18 | libcxx_prefix = "cxx_", # default value: libcxx_ 19 | mlir_prefix = "ml_", # default value: mlir_ 20 | add_headers_to_deps = False, # default value: True 21 | 22 | # Either the LLVM_INSTALL_PREFIX environment variable must point to 23 | # a local llvm/clang installation or the 'urls', 'sha256' and, optionaly, 24 | # 'strip_prefix' must be specified. 25 | 26 | # If a build_file (and optionaly config_file) are specified, 27 | # the repository rule will generate no BUILD file, the specified one will 28 | # be taken into account instead. 29 | ) 30 | -------------------------------------------------------------------------------- /examples/clang/clang_empty_main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char** argv) { 4 | std::cout << "Hello, Clang" << std::endl; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /examples/clang/clang_list_methods.cc: -------------------------------------------------------------------------------- 1 | #include "llvm_config.h" 2 | 3 | extern "C" { 4 | #include "clang-c/Index.h" 5 | } 6 | 7 | #include "llvm/Support/CommandLine.h" 8 | #include 9 | #include 10 | #include 11 | 12 | #define ENDLINE "\n" 13 | #define EMPTY "" 14 | #define SPACE " " 15 | #define DEFINITION_MARKER "{}" 16 | 17 | namespace llvmdemo { 18 | // Demo class just to show how method declaration works if the source file is assigned as an argument of the program. 19 | class A { 20 | public: 21 | A(); 22 | A(const int &); 23 | void dome(const A& self, int i, long long j); 24 | private: 25 | ~A() {}; // We don't intend to inherit from A 26 | }; 27 | } 28 | 29 | std::string justAFunction(); 30 | 31 | using namespace llvm; 32 | 33 | static cl::opt 34 | FileName(cl::Positional, cl::desc("Input file"), cl::Required); 35 | 36 | std::string str(const CXString& s) { 37 | std::string result = clang_getCString(s); 38 | clang_disposeString(s); 39 | return result; 40 | } 41 | 42 | std::string isDefinition(const CXCursor& cursor) { 43 | return clang_isCursorDefinition(cursor) ? DEFINITION_MARKER : EMPTY; 44 | } 45 | 46 | std::string getFullQualifiedName(const CXCursor& cursor) { 47 | std::string qualifiedName = str(clang_getCursorSpelling(cursor)); 48 | auto semanticParent = clang_getCursorSemanticParent(cursor); 49 | if (clang_getCursorKind(semanticParent) == CXCursor_TranslationUnit) { 50 | return qualifiedName; 51 | } else { 52 | return getFullQualifiedName(semanticParent) + "::" + qualifiedName; 53 | } 54 | } 55 | 56 | std::string getFunctionPrototype(const CXCursor& cursor) { 57 | std::ostringstream resultstream; 58 | 59 | auto type = clang_getCursorType(cursor); 60 | auto result_type = str(clang_getTypeSpelling(clang_getResultType(type))); 61 | auto function_name = getFullQualifiedName(cursor); 62 | 63 | resultstream << result_type.c_str() << SPACE << function_name.c_str() << '('; 64 | 65 | int num_args = clang_Cursor_getNumArguments(cursor); 66 | for (int i = 0; i < num_args; ++i) { 67 | auto arg_cursor = clang_Cursor_getArgument(cursor, i); 68 | auto arg_name = str(clang_getCursorSpelling(arg_cursor)); 69 | if (arg_name.empty()) { 70 | arg_name = "no type"; 71 | } 72 | auto arg_data_type = str(clang_getTypeSpelling(clang_getArgType(type, i))); 73 | 74 | resultstream << arg_data_type.c_str() << SPACE << arg_name.c_str(); 75 | if (i < num_args - 1) { 76 | resultstream << ',' << SPACE; 77 | } 78 | } 79 | resultstream << ')' << SPACE << isDefinition(cursor).c_str() << ENDLINE; 80 | 81 | return resultstream.str(); 82 | } 83 | 84 | std::string getFunctionLocation(const CXCursor& cursor) { 85 | std::ostringstream resultstream; 86 | auto location = clang_getCursorLocation(cursor); 87 | CXString fName; 88 | unsigned line = 0, col = 0; 89 | clang_getPresumedLocation(location, &fName, &line, &col); 90 | resultstream << str(fName).c_str() << ":" << line << ":" << col << "\n"; 91 | return resultstream.str(); 92 | } 93 | 94 | enum CXChildVisitResult visitFunction(CXCursor cursor, CXCursor parent, CXClientData client_data) { 95 | if (clang_Location_isFromMainFile(clang_getCursorLocation(cursor)) == 0) 96 | return CXChildVisit_Continue; 97 | 98 | CXCursorKind kind = clang_getCursorKind(cursor); 99 | if (kind == CXCursor_CXXMethod || 100 | kind == CXCursor_FunctionDecl || 101 | kind == CXCursor_Constructor || 102 | kind == CXCursor_Destructor || 103 | kind == CXCursor_FunctionTemplate) 104 | { 105 | std::cout << getFunctionLocation(cursor) << getFunctionPrototype(cursor) << "\n"; 106 | return CXChildVisit_Continue; 107 | } 108 | return CXChildVisit_Recurse; 109 | } 110 | 111 | int main(int argc, char** argv) { 112 | cl::ParseCommandLineOptions(argc, argv, "AST Traversal Example"); 113 | CXIndex index = clang_createIndex(0, 0); 114 | const char *args[] = { 115 | CLANG_LIB_INCLUDE_COMMAND_ARG, 116 | LLVM_INCLUDE_COMMAND_ARG, 117 | "-I./include" 118 | }; 119 | 120 | CXTranslationUnit translationUnit = clang_parseTranslationUnit(index, FileName.c_str(), args, 3, 121 | NULL, 0, CXTranslationUnit_None); // CXTranslationUnit_SkipFunctionBodies doesn't parse bodies and we 122 | // won't able to recognize if a function is a definition. 123 | CXCursor cursor = clang_getTranslationUnitCursor(translationUnit); 124 | clang_visitChildren(cursor, visitFunction, NULL); 125 | clang_disposeTranslationUnit(translationUnit); 126 | clang_disposeIndex(index); 127 | 128 | // TODO: get all functions without definitions using clang_getCursorDefinition(CXCursor) 129 | return 0; 130 | } 131 | -------------------------------------------------------------------------------- /examples/generate_libcxx_bazelrc.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | FILE = "libcxx.bazelrc" 4 | 5 | def main(): 6 | lib, include = parse_command_line() 7 | if not lib or not include: 8 | print_usage() 9 | exit(1) 10 | with open(FILE, "w") as f: 11 | f.write("build:libc++ --repo_env BAZEL_CXXOPTS=\"--stdlib=libc++:-isystem%s\"\n" % include) 12 | f.write("build:libc++ --repo_env BAZEL_LINKOPTS=\"--stdlib=libc++\"\n") 13 | f.write("build:libc++ --repo_env BAZEL_LINKLIBS=\"-L%s:-Wl,-rpath,%s:-lc++\"\n" % (lib, lib)) 14 | 15 | def print_usage(): 16 | print("This script generates a libcxx.bazelrc file in the current directory") 17 | print("Usage: python[3] generate_libcxx_bazelrc.py -L -I") 18 | 19 | def parse_command_line(): 20 | 21 | def is_lib_param(arg): 22 | return len(arg) > 2 and arg.startswith("-L") 23 | 24 | def is_include_param(arg): 25 | return len(arg) > 2 and arg.startswith("-I") 26 | 27 | def parse_param(arg): 28 | return arg[2:].strip() 29 | 30 | args = sys.argv 31 | if len(args) >= 3 and ((is_lib_param(args[1]) and is_include_param(args[2])) 32 | or (is_include_param(args[1]) and is_lib_param(args[2]))): 33 | lib = parse_param(args[1] if is_lib_param(args[1]) else args[2]) 34 | include = parse_param(args[1] if is_include_param(args[1]) else args[2]) 35 | return (lib, include) 36 | 37 | return (None, None) 38 | 39 | if __name__ == "__main__": 40 | main() 41 | -------------------------------------------------------------------------------- /examples/llvm/function_argument_usage_pass.cc: -------------------------------------------------------------------------------- 1 | #include "llvm/ADT/SmallVector.h" 2 | #include "llvm/ADT/Statistic.h" 3 | #include "llvm/Pass.h" 4 | #include "llvm/IR/Argument.h" 5 | #include "llvm/IR/Function.h" 6 | #include "llvm/IR/Instructions.h" 7 | #include "llvm/IR/Module.h" 8 | #include "llvm/IR/Type.h" 9 | #include "llvm/Support/Debug.h" 10 | #include "llvm/Support/raw_ostream.h" 11 | 12 | #define DEBUG_TYPE "ArgUsage" 13 | STATISTIC(NumOfMismatches, "Number of type mismatches are found"); 14 | 15 | using namespace llvm; 16 | 17 | namespace llvm { 18 | void initializeFunctionArgumentUsagePassPass(PassRegistry&); 19 | } 20 | 21 | namespace { 22 | class FunctionArgumentUsagePass 23 | : public FunctionPass { 24 | public: 25 | struct TypeMismatchRecord { 26 | const StringRef functionName; 27 | const unsigned line; 28 | const bool hasLine; 29 | const unsigned argNo; 30 | const Type* expectedType; 31 | const Type* actualType; 32 | 33 | TypeMismatchRecord(const StringRef functionName, 34 | const unsigned line, 35 | const bool hasLine, 36 | const unsigned argNo, 37 | const Type* expectedType, 38 | const Type* actualType) 39 | : functionName(functionName), 40 | line(line), 41 | hasLine(hasLine), 42 | argNo(argNo), 43 | expectedType(expectedType), 44 | actualType(actualType) 45 | {} 46 | }; 47 | using TypeMismatch = struct TypeMismatchRecord; 48 | 49 | private: 50 | using TypeMismatchVector = SmallVector; 51 | TypeMismatchVector typeMismatches; 52 | 53 | template 54 | void analyzeFunctionUsages(Function &F, CallInst *call); 55 | public: 56 | using const_iterator = TypeMismatchVector::const_iterator; 57 | static char ID; 58 | FunctionArgumentUsagePass() : 59 | FunctionPass(ID) { 60 | } 61 | 62 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { 63 | AU.setPreservesAll(); 64 | } 65 | 66 | virtual const_iterator begin() const { 67 | return typeMismatches.begin(); 68 | } 69 | 70 | virtual const_iterator end() const { 71 | return typeMismatches.end(); 72 | } 73 | 74 | virtual bool runOnFunction(Function &F); 75 | 76 | virtual void print(llvm::raw_ostream &O, const Module *M) const; 77 | 78 | virtual void releaseMemory(); 79 | }; 80 | } 81 | 82 | char FunctionArgumentUsagePass::ID = 0; 83 | 84 | INITIALIZE_PASS(FunctionArgumentUsagePass, "fnargusage", "Function Argument Usage Pass", 85 | false /* Only looks at CFG */, 86 | false /* Analysis Pass */); 87 | 88 | static void dumpFunctionArgs(const Function &F) { 89 | dbgs() << "function '"; 90 | dbgs().write_escaped(F.getName()); 91 | dbgs() << "' takes " << F.arg_size() << " parameters:\n"; 92 | for (auto a = F.arg_begin(), e = F.arg_end(); a != e; ++a) { 93 | if (a->hasName()) { 94 | dbgs() << '\t' << a->getName(); 95 | } else { 96 | dbgs() << "\tanonymous"; 97 | } 98 | dbgs() << ": " << *a->getType() << '\n'; 99 | } 100 | } 101 | 102 | template 103 | void FunctionArgumentUsagePass::analyzeFunctionUsages(Function &F, CallInst *call) { 104 | bool hasLine = false; 105 | unsigned line = 0; 106 | LLVM_DEBUG({ 107 | dbgs() << "and is used in the '"; 108 | dbgs().write_escaped(call->getParent()->getParent()->getName()); 109 | dbgs() << "' function"; 110 | if (auto &debugLoc = call->getDebugLoc()) { 111 | line = call->getDebugLoc().getLine(); 112 | hasLine = true; 113 | dbgs() << " (on line: " << line << ')'; 114 | } 115 | dbgs() << ":\n"; 116 | }); 117 | // check on argument type mismatch 118 | // fa - a function's formal argument (an argument from 119 | // the signature of the function). 120 | // pha - a physical argument, an argument the function 121 | // is exactly executed with. 122 | auto fa = F.arg_begin(), fe = F.arg_end(); 123 | for (auto pha = call->arg_begin(), phe = call->arg_end(); 124 | (fa != fe && pha != phe); ++pha,++fa) { 125 | const Type *ftypeptr = fa->getType(); 126 | const Type *phtypeptr = pha->get()->getType(); 127 | 128 | LLVM_DEBUG({ 129 | dbgs() << "\targ #" << fa->getArgNo(); 130 | if (pha->get()->hasName()) { 131 | dbgs() << '(' << pha->get()->getName() << ')'; 132 | } 133 | dbgs() << ": " << *phtypeptr << '\n'; 134 | }); 135 | if (ftypeptr->getTypeID() != phtypeptr->getTypeID()) { 136 | // type mismatch is here 137 | // ... register it: 138 | NumOfMismatches++; 139 | typeMismatches.emplace_back(F.getName(), line, hasLine, 140 | fa->getArgNo(), ftypeptr, phtypeptr); 141 | LLVM_DEBUG({ 142 | // ... and debug: 143 | dbgs() << "\ttype mismatch: expected '"; 144 | dbgs() << *ftypeptr <<"' but argument is of type '"; 145 | dbgs() << *phtypeptr << "'\n"; 146 | }); 147 | } 148 | } 149 | } 150 | 151 | bool FunctionArgumentUsagePass::runOnFunction(Function &F) { 152 | LLVM_DEBUG(dumpFunctionArgs(F)); 153 | 154 | for (auto use = F.use_begin(), e = F.use_end(); use != e; ++use) { 155 | if (CallInst *call = dyn_cast(use->getUser())) { 156 | analyzeFunctionUsages(F, call); 157 | } else if (InvokeInst *call = dyn_cast(use->getUser())) { 158 | analyzeFunctionUsages(F, call); 159 | } 160 | } 161 | return false; 162 | } 163 | 164 | void FunctionArgumentUsagePass::print(llvm::raw_ostream &O, const Module *M) const { 165 | for (auto& mismatch : typeMismatches) { 166 | O << "Function '"; 167 | O.write_escaped(mismatch.functionName); 168 | O << "'"; 169 | if (mismatch.hasLine) { 170 | O << " call on line '" << mismatch.line << '\''; 171 | } 172 | O << ": argument type mismatch. "; 173 | O << "Argument #" << mismatch.argNo << ' '; 174 | O << "Expected '" << *mismatch.expectedType << "' "; 175 | O << "but argument is of type '" << *mismatch.actualType << "'\n"; 176 | } 177 | } 178 | 179 | void FunctionArgumentUsagePass::releaseMemory() { 180 | LLVM_DEBUG(dbgs() << "Release memory" << '\n'); 181 | // TODO reclaim memory, different functions have different number of users 182 | typeMismatches.clear(); 183 | } 184 | -------------------------------------------------------------------------------- /examples/llvm/llvm_bb_counter.cc: -------------------------------------------------------------------------------- 1 | #include "llvm/Bitcode/BitcodeReader.h" 2 | #include "llvm/Support/CommandLine.h" 3 | 4 | using namespace llvm; 5 | 6 | static cl::opt FileName(cl::Positional, cl::desc("Bitcode file"), cl::Required); 7 | 8 | int main(int argc, char** argv) { 9 | cl::ParseCommandLineOptions(argc, argv, "LLVM BB Counter\n"); 10 | LLVMContext context; 11 | 12 | ErrorOr> mb = MemoryBuffer::getFile(FileName); 13 | if (std::error_code ec = mb.getError()) { 14 | errs() << ec.message(); 15 | return -1; 16 | } 17 | 18 | Expected> m = parseBitcodeFile((*mb)->getMemBufferRef(), context); 19 | if (std::error_code ec = errorToErrorCode(m.takeError())) { 20 | errs() << "Error reading bitcode: " << ec.message() << "\n"; 21 | return -1; 22 | } 23 | 24 | for (Module::const_iterator I = (*m)->getFunctionList().begin(), 25 | E = (*m)->getFunctionList().end(); I != E; ++I) { 26 | if (!I->isDeclaration()) { 27 | outs() << I->getName() << " has " << I->size() << " basic block(s).\n"; 28 | } 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /examples/llvm/llvm_empty_main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char** argv) { 4 | std::cout << "Hello, LLVM" << std::endl; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /examples/llvm/llvm_print_physical_registers.cc: -------------------------------------------------------------------------------- 1 | #include "target/custom_register_info.h" 2 | 3 | #include "llvm/ADT/Triple.h" 4 | #include "llvm/Support/raw_os_ostream.h" 5 | 6 | using namespace llvm; 7 | 8 | int main(int argc, char** argv) { 9 | Triple TheTriple("custom-linux"); 10 | CustomRegisterInfo TRI{TheTriple}; 11 | 12 | for (auto rcit = TRI.regclass_begin(), rcite = TRI.regclass_end(); 13 | rcit != rcite; ++rcit) { 14 | errs() << "Register Class #" << (*rcit)->getID() << " " 15 | << TRI.getRegClassName(*rcit) 16 | << " (" << (*rcit)->getNumRegs() << " regs" 17 | << ((*rcit)->isAllocatable() ? ", allocatable": "") 18 | << ") " << TRI.getRegSizeInBits(**rcit) << " bits:" 19 | << "\n"; 20 | for (auto&& reg : **rcit) { 21 | errs() << TRI.getName(reg) 22 | << (Register::isPhysicalRegister(reg) ? 23 | " (physical)\n" : "\n"); 24 | } 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /examples/llvm/llvm_print_supported_targets.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char** argv) { 4 | std::cout << "Installed LLVM supports the following targets:" << std::endl; 5 | #ifdef LLVM_SUPPORTS_TARGET_AARCH64 6 | std::cout << " - AArch64" << std::endl; 7 | #endif 8 | #ifdef LLVM_SUPPORTS_TARGET_AMDGPU 9 | std::cout << " - AMDGPU" << std::endl; 10 | #endif 11 | #ifdef LLVM_SUPPORTS_TARGET_ARM 12 | std::cout << " - ARM" << std::endl; 13 | #endif 14 | #ifdef LLVM_SUPPORTS_TARGET_AVR 15 | std::cout << " - AVR" << std::endl; 16 | #endif 17 | #ifdef LLVM_SUPPORTS_TARGET_BPF 18 | std::cout << " - BPF" << std::endl; 19 | #endif 20 | #ifdef LLVM_SUPPORTS_TARGET_HEXAGON 21 | std::cout << " - Hexagon" << std::endl; 22 | #endif 23 | #ifdef LLVM_SUPPORTS_TARGET_LANAI 24 | std::cout << " - Lanai" << std::endl; 25 | #endif 26 | #ifdef LLVM_SUPPORTS_TARGET_MIPS 27 | std::cout << " - Mips" << std::endl; 28 | #endif 29 | #ifdef LLVM_SUPPORTS_TARGET_MSP430 30 | std::cout << " - MSP430" << std::endl; 31 | #endif 32 | #ifdef LLVM_SUPPORTS_TARGET_NVPTX 33 | std::cout << " - NVPTX" << std::endl; 34 | #endif 35 | #ifdef LLVM_SUPPORTS_TARGET_POWERPC 36 | std::cout << " - PowerPC" << std::endl; 37 | #endif 38 | #ifdef LLVM_SUPPORTS_TARGET_RISCV 39 | std::cout << " - RISCV" << std::endl; 40 | #endif 41 | #ifdef LLVM_SUPPORTS_TARGET_SPARC 42 | std::cout << " - Sparc" << std::endl; 43 | #endif 44 | #ifdef LLVM_SUPPORTS_TARGET_SYSTEMZ 45 | std::cout << " - SystemZ" << std::endl; 46 | #endif 47 | #ifdef LLVM_SUPPORTS_TARGET_WEBASSEMBLY 48 | std::cout << " - WebAssembly" << std::endl; 49 | #endif 50 | #ifdef LLVM_SUPPORTS_TARGET_X86 51 | std::cout << " - X86" << std::endl; 52 | #endif 53 | #ifdef LLVM_SUPPORTS_TARGET_XCORE 54 | std::cout << " - XCore" << std::endl; 55 | #endif 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /examples/llvm/target/custom_frame_lowering.cc: -------------------------------------------------------------------------------- 1 | #include "custom_frame_lowering.h" 2 | 3 | namespace llvm { 4 | class Triple; 5 | } // namespace llvm 6 | 7 | using namespace llvm; 8 | 9 | bool CustomFrameLowering::hasFP(const MachineFunction &MF) const { 10 | llvm_unreachable("Method hasFP is not implemented for custom"); 11 | return false; 12 | } 13 | 14 | void CustomFrameLowering::emitPrologue(MachineFunction &MF, 15 | MachineBasicBlock &MBB) const { 16 | llvm_unreachable("Method emitPrologue is not implemented for custom"); 17 | } 18 | 19 | void CustomFrameLowering::emitEpilogue(MachineFunction &MF, 20 | MachineBasicBlock &MBB) const { 21 | llvm_unreachable("Method emitEpilogue is not implemented for custom"); 22 | } 23 | -------------------------------------------------------------------------------- /examples/llvm/target/custom_frame_lowering.h: -------------------------------------------------------------------------------- 1 | #ifndef LLVM_TARGET_CUSTOMFRAMELOWERING_H 2 | #define LLVM_TARGET_CUSTOMFRAMELOWERING_H 3 | 4 | #include "llvm/CodeGen/TargetFrameLowering.h" 5 | 6 | namespace llvm { 7 | 8 | class CustomFrameLowering final : public TargetFrameLowering { 9 | bool hasFP(const MachineFunction &MF) const override; 10 | 11 | void emitPrologue(MachineFunction &MF, 12 | MachineBasicBlock &MBB) const override; 13 | 14 | void emitEpilogue(MachineFunction &MF, 15 | MachineBasicBlock &MBB) const override; 16 | }; 17 | 18 | } // End llvm namespace 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /examples/llvm/target/custom_mc_target_desc.cc: -------------------------------------------------------------------------------- 1 | #include "llvm/MC/MCRegisterInfo.h" 2 | 3 | #define GET_REGINFO_ENUM 4 | #define GET_REGINFO_MC_DESC 5 | #include "custom_register_info.inc" 6 | 7 | -------------------------------------------------------------------------------- /examples/llvm/target/custom_register_class.td: -------------------------------------------------------------------------------- 1 | //===- custom_register_class.td - Describe the Custom Register Classes --*- tablegen -*-==// 2 | 3 | // General Purpose Registers 4 | def GR8 : RegisterClass<"custom", [i8], 8, 5 | (add R1, R2, R3, R4, R1H, R2H, R3H, R4H)> { 6 | let AltOrders = [(sub GR8, R1H, R2H, R3H, R4H)]; 7 | } 8 | 9 | def GR16 : RegisterClass<"custom", [i16], 16, 10 | (add RX, RY, RZ, RA)>; 11 | 12 | let isAllocatable = 0 in 13 | def GRH16 : RegisterClass<"custom", [i16], 16, 14 | (add HRX, HRY, HRZ, HRA)>; 15 | 16 | def GR32 : RegisterClass<"custom", [i32], 32, 17 | (add WRX, WRY, WRZ, WRA)>; 18 | 19 | def GR64 : RegisterClass<"custom", [i64], 64, 20 | (add SRX, SRY, SRZ, SRA)>; 21 | 22 | def GR128 : RegisterClass<"custom", [i128], 128, 23 | (add ZRX, ZRY, ZRZ, ZRA)>; 24 | -------------------------------------------------------------------------------- /examples/llvm/target/custom_register_info.cc: -------------------------------------------------------------------------------- 1 | #include "custom_register_info.h" 2 | #include "custom_frame_lowering.h" 3 | 4 | #include "llvm/ADT/BitVector.h" 5 | #include "llvm/CodeGen/MachineFunction.h" 6 | #include "llvm/CodeGen/TargetSubtargetInfo.h" 7 | 8 | namespace llvm { 9 | class Triple; 10 | } // namespace llvm 11 | 12 | using namespace llvm; 13 | 14 | #define GET_REGINFO_TARGET_DESC 15 | #include "custom_register_info.inc" 16 | 17 | CustomRegisterInfo::CustomRegisterInfo(const Triple &TT) 18 | : CustomGenRegisterInfo(custom::WRA) {} 19 | 20 | const MCPhysReg * 21 | CustomRegisterInfo::getCalleeSavedRegs(const MachineFunction* MF) const { 22 | llvm_unreachable("Method getCalleeSavedRegs is not implemented for custom"); 23 | return nullptr; 24 | } 25 | 26 | BitVector 27 | CustomRegisterInfo::getReservedRegs(const MachineFunction &MF) const { 28 | llvm_unreachable("Method getReservedRegs is not implemented for custom"); 29 | return BitVector(getNumRegs()); 30 | } 31 | 32 | void 33 | CustomRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator MI, 34 | int SPAdj, unsigned FIOperandNum, 35 | RegScavenger *RS) const { 36 | llvm_unreachable("Method eliminateFrameIndex is not implemented for custom"); 37 | } 38 | 39 | Register 40 | CustomRegisterInfo::getFrameRegister(const MachineFunction &MF) const { 41 | llvm_unreachable("Method getFrameRegister is not implemented for custom"); 42 | return custom::WRA; 43 | } 44 | -------------------------------------------------------------------------------- /examples/llvm/target/custom_register_info.h: -------------------------------------------------------------------------------- 1 | #ifndef LLVM_TARGET_CUSTOMREGISTERINFO_H 2 | #define LLVM_TARGET_CUSTOMREGISTERINFO_H 3 | 4 | #include "llvm/CodeGen/TargetRegisterInfo.h" 5 | 6 | #define GET_REGINFO_ENUM 7 | #define GET_REGINFO_HEADER 8 | #include "custom_register_info.inc" 9 | 10 | namespace llvm { 11 | 12 | class Triple; 13 | 14 | class CustomRegisterInfo final : public CustomGenRegisterInfo { 15 | public: 16 | explicit CustomRegisterInfo(const Triple &TT); 17 | 18 | // Must be implemented to not be abstract 19 | const MCPhysReg * 20 | getCalleeSavedRegs(const MachineFunction* MF) const override; 21 | 22 | BitVector getReservedRegs(const MachineFunction &MF) const override; 23 | 24 | void eliminateFrameIndex(MachineBasicBlock::iterator MI, 25 | int SPAdj, unsigned FIOperandNum, 26 | RegScavenger *RS = nullptr) const override; 27 | 28 | Register getFrameRegister(const MachineFunction &MF) const override; 29 | }; 30 | 31 | } // End llvm namespace 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /examples/llvm/target/custom_register_info.td: -------------------------------------------------------------------------------- 1 | //===- custom_register_info.td - Describe the Custom Register File --*- tablegen -*-==// 2 | 3 | include "llvm/Target/Target.td" 4 | 5 | def CustomInstrInfo : InstrInfo; 6 | 7 | def Custom : Target { 8 | // Information about the instructions... 9 | let InstructionSet = CustomInstrInfo; 10 | let AllowRegisterRenaming = 1; 11 | } 12 | 13 | class CustomReg Enc, list subregs = []> : Register { 14 | let Namespace = "custom"; 15 | let HWEncoding = Enc; 16 | let SubRegs = subregs; 17 | } 18 | 19 | let Namespace = "custom" in { 20 | def sub_8bit : SubRegIndex<8>; 21 | def sub_8bit_hi : SubRegIndex<8, 8>; 22 | def sub_16bit : SubRegIndex<16>; 23 | def sub_16bit_hi : SubRegIndex<16, 16>; 24 | def sub_32bit : SubRegIndex<32>; 25 | def sub_64bit : SubRegIndex<64>; 26 | } 27 | 28 | // 8-bit registers 29 | // Low registers 30 | def R1 : CustomReg<"r1", 0>; 31 | def R2 : CustomReg<"r2", 1>; 32 | def R3 : CustomReg<"r3", 2>; 33 | def R4 : CustomReg<"r4", 3>; 34 | 35 | // High registers. 36 | def R1H : CustomReg<"r1h", 4>; 37 | def R2H : CustomReg<"r2h", 5>; 38 | def R3H : CustomReg<"r3h", 6>; 39 | def R4H : CustomReg<"r4h", 7>; 40 | 41 | // 16-bit registers 42 | let SubRegIndices = [sub_8bit, sub_8bit_hi], CoveredBySubRegs = 1 in { 43 | def RX : CustomReg<"rx", 0, [R1,R1H]>; 44 | def RY : CustomReg<"ry", 1, [R2,R2H]>; 45 | def RZ : CustomReg<"rz", 2, [R3,R3H]>; 46 | def RA : CustomReg<"ra", 3, [R4,R4H]>; 47 | } 48 | def IP : CustomReg<"ip", 0>; 49 | 50 | let isArtificial = 1 in { 51 | // High word of the low 32 bits of the super-register: 52 | def HRX : CustomReg<"", -1>; 53 | def HRY : CustomReg<"", -1>; 54 | def HRZ : CustomReg<"", -1>; 55 | def HRA : CustomReg<"", -1>; 56 | } 57 | 58 | // 32-bit registers 59 | let SubRegIndices = [sub_16bit, sub_16bit_hi], CoveredBySubRegs = 1 in { 60 | def WRX : CustomReg<"wrx", 0, [RX, HRX]>; 61 | def WRY : CustomReg<"wry", 1, [RY, HRY]>; 62 | def WRZ : CustomReg<"wrz", 2, [RZ, HRZ]>; 63 | def WRA : CustomReg<"wra", 3, [RA, HRA]>; 64 | } 65 | 66 | // 64-bit registers 67 | let SubRegIndices = [sub_32bit] in { 68 | def SRX : CustomReg<"srx", 0, [WRX]>; 69 | def SRY : CustomReg<"sry", 1, [WRY]>; 70 | def SRZ : CustomReg<"srz", 2, [WRZ]>; 71 | def SRA : CustomReg<"sra", 3, [WRA]>; 72 | } 73 | 74 | // 128-bit registers 75 | let SubRegIndices = [sub_64bit] in { 76 | def ZRX : CustomReg<"zrz", 0, [SRX]>; 77 | def ZRY : CustomReg<"zry", 1, [SRY]>; 78 | def ZRZ : CustomReg<"zrz", 2, [SRZ]>; 79 | def ZRA : CustomReg<"zra", 3, [SRA]>; 80 | } 81 | 82 | include "custom_register_class.td" 83 | -------------------------------------------------------------------------------- /examples/mlir/mlir_empty_main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char** argv) { 4 | std::cout << "Hello, MLIR" << std::endl; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /llvm/BUILD: -------------------------------------------------------------------------------- 1 | # Needed to make this a package. 2 | -------------------------------------------------------------------------------- /llvm/BUILD.tpl: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//visibility:public"]) 2 | 3 | exports_files(["LICENSE.TXT"]) 4 | 5 | %{CLANG_HEADERS_LIB} 6 | %{CLANG_ANALYSIS_LIB} 7 | %{CLANG_APINOTES_LIB} 8 | %{CLANG_ARCMIGRATE_LIB} 9 | %{CLANG_AST_LIB} 10 | %{CLANG_ASTMATCHERS_LIB} 11 | %{CLANG_BASIC_LIB} 12 | %{CLANG_CODEGEN_LIB} 13 | %{CLANG_CROSSTU_LIB} 14 | %{CLANG_DEPENDENCYSCANNING_LIB} 15 | %{CLANG_DIRECTORYWATCHER_LIB} 16 | %{CLANG_DRIVER_LIB} 17 | %{CLANG_DYNAMICASTMATCHERS_LIB} 18 | %{CLANG_EDIT_LIB} 19 | %{CLANG_FORMAT_LIB} 20 | %{CLANG_FRONTEND_LIB} 21 | %{CLANG_FRONTENDTOOL_LIB} 22 | %{CLANG_HANDLECXX_LIB} 23 | %{CLANG_HANDLELLVM_LIB} 24 | %{CLANG_INDEX_LIB} 25 | %{CLANG_INDEXSERIALIZATION_LIB} 26 | %{CLANG_LEX_LIB} 27 | %{CLANG_LIBCLANG_LIB} 28 | %{CLANG_LIBCLANG_COPY_GENRULE} 29 | %{CLANG_LIBCLANGCPP_LIB} 30 | %{CLANG_LIBCLANGCPP_COPY_GENRULE} 31 | %{CLANG_PARSE_LIB} 32 | %{CLANG_REWRITE_LIB} 33 | %{CLANG_REWRITEFRONTEND_LIB} 34 | %{CLANG_SEMA_LIB} 35 | %{CLANG_SERIALIZATION_LIB} 36 | %{CLANG_STATICANALYZERCHECKERS_LIB} 37 | %{CLANG_STATICANALYZERCORE_LIB} 38 | %{CLANG_STATICANALYZERFRONTEND_LIB} 39 | %{CLANG_TESTING_LIB} 40 | %{CLANG_TOOLING_LIB} 41 | %{CLANG_TOOLINGASTDIFF_LIB} 42 | %{CLANG_TOOLINGCORE_LIB} 43 | %{CLANG_TOOLINGINCLUSIONS_LIB} 44 | %{CLANG_TOOLINGREFACTORING_LIB} 45 | %{CLANG_TOOLINGSYNTAX_LIB} 46 | %{CLANG_TRANSFORMER_LIB} 47 | 48 | %{LLVM_HEADERS_LIB} 49 | %{LLVM_AGGRESSIVEINSTCOMBINE_LIB} 50 | %{LLVM_ANALYSIS_LIB} 51 | %{LLVM_ASMPRARSER_LIB} 52 | %{LLVM_ASMPRINTER_LIB} 53 | %{LLVM_BINARYFORMAT_LIB} 54 | %{LLVM_BITREADER_LIB} 55 | %{LLVM_BITWRITER_LIB} 56 | %{LLVM_BITSTREAMREADER_LIB} 57 | %{LLVM_C_LIB} 58 | %{LLVM_C_COPY_GENRULE} 59 | %{LLVM_CFGUARD_LIB} 60 | %{LLVM_CODEGEN_LIB} 61 | %{LLVM_CORE_LIB} 62 | %{LLVM_COROUTINES_LIB} 63 | %{LLVM_COVERAGE_LIB} 64 | %{LLVM_DEBUGINFOCODEVIEW_LIB} 65 | %{LLVM_DEBUGINFODWARF_LIB} 66 | %{LLVM_DEBUGINFOGSYM_LIB} 67 | %{LLVM_DEBUGINFOMSF_LIB} 68 | %{LLVM_DEBUGINFOPDB_LIB} 69 | %{LLVM_DEMANGLE_LIB} 70 | %{LLVM_DLLTOOLDRIVER_LIB} 71 | %{LLVM_DWARFLINKER_LIB} 72 | %{LLVM_EXECUTION_ENGINE_LIB} 73 | %{LLVM_EXTENSIONS} 74 | %{LLVM_FILECHECK_LIB} 75 | %{LLVM_FRONTEND_OPENACC_LIB} 76 | %{LLVM_FRONTEND_OPENMP_LIB} 77 | %{LLVM_FUZZMUTATE_LIB} 78 | %{LLVM_GLOBALISEL_LIB} 79 | %{LLVM_INSTCOMBINE_LIB} 80 | %{LLVM_INSTRUMENTATION_LIB} 81 | %{LLVM_INTERFACESTUB_LIB} 82 | %{LLVM_INTERPRETER_LIB} 83 | %{LLVM_IRREADER_LIB} 84 | %{LLVM_IPO_LIB} 85 | %{LLVM_JITLINK_LIB} 86 | %{LLVM_LIBDRIVER_LIB} 87 | %{LLVM_LINEEDITOR_LIB} 88 | %{LLVM_LINKER_LIB} 89 | %{LLVM_LTO_LIB} 90 | %{LLVM_MC_LIB} 91 | %{LLVM_MCA_LIB} 92 | %{LLVM_MCDISASSEMBLER_LIB} 93 | %{LLVM_MCJIT_LIB} 94 | %{LLVM_MCPARSER_LIB} 95 | %{LLVM_MIRPARSER_LIB} 96 | %{LLVM_OBJCARC_LIB} 97 | %{LLVM_OBJECT_LIB} 98 | %{LLVM_OBJECTYAML_LIB} 99 | %{LLVM_OPTION_LIB} 100 | %{LLVM_ORCJIT_LIB} 101 | %{LLVM_ORCSHARED_LIB} 102 | %{LLVM_ORCTARGETPROCESS_LIB} 103 | %{LLVM_PASSES_LIB} 104 | %{LLVM_PROFILEDATA_LIB} 105 | %{LLVM_REMARKS_LIB} 106 | %{LLVM_RUNTIMEDYLD_LIB} 107 | %{LLVM_SCALAR_LIB} 108 | %{LLVM_SELECTIONDAG_LIB} 109 | %{LLVM_SUPPORT_LIB} 110 | %{LLVM_SYMBOLIZE_LIB} 111 | %{LLVM_TABLEGEN_LIB} 112 | %{LLVM_TABLEGEN_TOOL} 113 | %{LLVM_TARGET_LIB} 114 | %{LLVM_TEXTAPI_LIB} 115 | %{LLVM_TRANSFORMUTILS_LIB} 116 | %{LLVM_VECTORIZE_LIB} 117 | %{LLVM_WINDOWS_MANIFEST_LIB} 118 | %{LLVM_XRAY_LIB} 119 | %{LLVM_AARCH64_ASMPARSER_LIB} 120 | %{LLVM_AARCH64_CODEGEN_LIB} 121 | %{LLVM_AARCH64_DESC_LIB} 122 | %{LLVM_AARCH64_DISASSEMBLER_LIB} 123 | %{LLVM_AARCH64_INFO_LIB} 124 | %{LLVM_AARCH64_UTILS_LIB} 125 | %{LLVM_AMDGPU_ASMPARSER_LIB} 126 | %{LLVM_AMDGPU_CODEGEN_LIB} 127 | %{LLVM_AMDGPU_DESC_LIB} 128 | %{LLVM_AMDGPU_DISASSEMBLER_LIB} 129 | %{LLVM_AMDGPU_INFO_LIB} 130 | %{LLVM_AMDGPU_UTILS_LIB} 131 | %{LLVM_ARM_ASMPARSER_LIB} 132 | %{LLVM_ARM_CODEGEN_LIB} 133 | %{LLVM_ARM_DESC_LIB} 134 | %{LLVM_ARM_DISASSEMBLER_LIB} 135 | %{LLVM_ARM_INFO_LIB} 136 | %{LLVM_ARM_UTILS_LIB} 137 | %{LLVM_AVR_ASMPARSER_LIB} 138 | %{LLVM_AVR_CODEGEN_LIB} 139 | %{LLVM_AVR_DESC_LIB} 140 | %{LLVM_AVR_DISASSEMBLER_LIB} 141 | %{LLVM_AVR_INFO_LIB} 142 | %{LLVM_BPF_ASMPARSER_LIB} 143 | %{LLVM_BPF_CODEGEN_LIB} 144 | %{LLVM_BPF_DESC_LIB} 145 | %{LLVM_BPF_DISASSEMBLER_LIB} 146 | %{LLVM_BPF_INFO_LIB} 147 | %{LLVM_HEXAGON_ASMPARSER_LIB} 148 | %{LLVM_HEXAGON_CODEGEN_LIB} 149 | %{LLVM_HEXAGON_DESC_LIB} 150 | %{LLVM_HEXAGON_DISASSEMBLER_LIB} 151 | %{LLVM_HEXAGON_INFO_LIB} 152 | %{LLVM_LANAI_ASMPARSER_LIB} 153 | %{LLVM_LANAI_CODEGEN_LIB} 154 | %{LLVM_LANAI_DESC_LIB} 155 | %{LLVM_LANAI_DISASSEMBLER_LIB} 156 | %{LLVM_LANAI_INFO_LIB} 157 | %{LLVM_MIPS_ASMPARSER_LIB} 158 | %{LLVM_MIPS_CODEGEN_LIB} 159 | %{LLVM_MIPS_DESC_LIB} 160 | %{LLVM_MIPS_DISASSEMBLER_LIB} 161 | %{LLVM_MIPS_INFO_LIB} 162 | %{LLVM_MSP430_ASMPARSER_LIB} 163 | %{LLVM_MSP430_CODEGEN_LIB} 164 | %{LLVM_MSP430_DESC_LIB} 165 | %{LLVM_MSP430_DISASSEMBLER_LIB} 166 | %{LLVM_MSP430_INFO_LIB} 167 | %{LLVM_NVPTX_CODEGEN_LIB} 168 | %{LLVM_NVPTX_DESC_LIB} 169 | %{LLVM_NVPTX_INFO_LIB} 170 | %{LLVM_POWERPC_ASMPARSER_LIB} 171 | %{LLVM_POWERPC_CODEGEN_LIB} 172 | %{LLVM_POWERPC_DESC_LIB} 173 | %{LLVM_POWERPC_DISASSEMBLER_LIB} 174 | %{LLVM_POWERPC_INFO_LIB} 175 | %{LLVM_RISCV_ASMPARSER_LIB} 176 | %{LLVM_RISCV_CODEGEN_LIB} 177 | %{LLVM_RISCV_DESC_LIB} 178 | %{LLVM_RISCV_DISASSEMBLER_LIB} 179 | %{LLVM_RISCV_INFO_LIB} 180 | %{LLVM_SPARC_ASMPARSER_LIB} 181 | %{LLVM_SPARC_CODEGEN_LIB} 182 | %{LLVM_SPARC_DESC_LIB} 183 | %{LLVM_SPARC_DISASSEMBLER_LIB} 184 | %{LLVM_SPARC_INFO_LIB} 185 | %{LLVM_SYSTEMZ_ASMPARSER_LIB} 186 | %{LLVM_SYSTEMZ_CODEGEN_LIB} 187 | %{LLVM_SYSTEMZ_DESC_LIB} 188 | %{LLVM_SYSTEMZ_DISASSEMBLER_LIB} 189 | %{LLVM_SYSTEMZ_INFO_LIB} 190 | %{LLVM_WEBASSEMBLY_ASMPARSER_LIB} 191 | %{LLVM_WEBASSEMBLY_CODEGEN_LIB} 192 | %{LLVM_WEBASSEMBLY_DESC_LIB} 193 | %{LLVM_WEBASSEMBLY_DISASSEMBLER_LIB} 194 | %{LLVM_WEBASSEMBLY_INFO_LIB} 195 | %{LLVM_X86_ASMPARSER_LIB} 196 | %{LLVM_X86_CODEGEN_LIB} 197 | %{LLVM_X86_DESC_LIB} 198 | %{LLVM_X86_DISASSEMBLER_LIB} 199 | %{LLVM_X86_INFO_LIB} 200 | %{LLVM_XCORE_CODEGEN_LIB} 201 | %{LLVM_XCORE_DESC_LIB} 202 | %{LLVM_XCORE_DISASSEMBLER_LIB} 203 | %{LLVM_XCORE_INFO_LIB} 204 | %{LLVM_CONFIG_GENRULE} 205 | %{LLVM_CONFIG_LIB} 206 | 207 | %{MLIR_HEADERS_LIB} 208 | %{MLIR_AFFINE_LIB} 209 | %{MLIR_AFFINEEDSC_LIB} 210 | %{MLIR_AFFINETOSTANDARD_LIB} 211 | %{MLIR_AFFINETRANSFORMS_LIB} 212 | %{MLIR_AFFINEUTILS_LIB} 213 | %{MLIR_ANALYSIS_LIB} 214 | %{MLIR_ARMNEON_LIB} 215 | %{MLIR_ARMNEONTOLLVM_LIB} 216 | %{MLIR_ARMSVE_LIB} 217 | %{MLIR_ARMSVETOLLVM_LIB} 218 | %{MLIR_ASYNC_LIB} 219 | %{MLIR_ASYNCRUNTIME_LIB} 220 | %{MLIR_ASYNCRUNTIME_COPY_GENRULE} 221 | %{MLIR_ASYNCTOLLVM_LIB} 222 | %{MLIR_ASYNCTRANSFORMS_LIB} 223 | %{MLIR_AVX512_LIB} 224 | %{MLIR_AVX512TOLLVM_LIB} 225 | %{MLIR_C_RUNNERUTILS_LIB} 226 | %{MLIR_C_RUNNERUTILS_COPY_GENRULE} 227 | %{MLIR_C_RUNNERUTILS_STATIC_LIB} 228 | %{MLIR_CALLINTERFACES_LIB} 229 | %{MLIR_CAPIIR_LIB} 230 | %{MLIR_CAPILINALG_LIB} 231 | %{MLIR_CAPIREGISTRATION_LIB} 232 | %{MLIR_CAPISCF_LIB} 233 | %{MLIR_CAPISHAPE_LIB} 234 | %{MLIR_CAPISTANDARD_LIB} 235 | %{MLIR_CAPITENSOR_LIB} 236 | %{MLIR_CAPITRANSFORMS_LIB} 237 | %{MLIR_CASTINTERFACES_LIB} 238 | %{MLIR_COMPLEX_LIB} 239 | %{MLIR_COMPLEXTOLLVM_LIB} 240 | %{MLIR_CONTROLFLOWINTERFACES_LIB} 241 | %{MLIR_COPYOPINTERFACE_LIB} 242 | %{MLIR_DERIVEDATTRIBUTEOPINTERFACE_LIB} 243 | %{MLIR_DIALECT_LIB} 244 | %{MLIR_EDSC_LIB} 245 | %{MLIR_EXECUTIONENGINE_LIB} 246 | %{MLIR_GPU_LIB} 247 | %{MLIR_GPUTOGPURUNTIMETRANSFORMS_LIB} 248 | %{MLIR_GPUTONVVMTRANSFORMS_LIB} 249 | %{MLIR_GPUTOROCDLTRANSFORMS_LIB} 250 | %{MLIR_GPUTOSPIRV_LIB} 251 | %{MLIR_GPUTOVULKANTRANSFORMS_LIB} 252 | %{MLIR_INFERTYPEOPINTERFACE_LIB} 253 | %{MLIR_IR_LIB} 254 | %{MLIR_JITRUNNER_LIB} 255 | %{MLIR_LINALG_LIB} 256 | %{MLIR_LINALGANALYSIS_LIB} 257 | %{MLIR_LINALGEDSC_LIB} 258 | %{MLIR_LINALGTOLLVM_LIB} 259 | %{MLIR_LINALGTOSPIRV_LIB} 260 | %{MLIR_LINALGTOSTANDARD_LIB} 261 | %{MLIR_LINALGTRANSFORMS_LIB} 262 | %{MLIR_LINALGUTILS_LIB} 263 | %{MLIR_LLVMARMNEON_LIB} 264 | %{MLIR_LLVMARMSVE_LIB} 265 | %{MLIR_LLVMAVX512_LIB} 266 | %{MLIR_LLVMIR_LIB} 267 | %{MLIR_LLVMIRTRANSFORMS_LIB} 268 | %{MLIR_LOOPANALYSIS_LIB} 269 | %{MLIR_LOOPLIKEINTERFACE_LIB} 270 | %{MLIR_MLIROPTMAIN_LIB} 271 | %{MLIR_NVVMIR_LIB} 272 | %{MLIR_OPENACC_LIB} 273 | %{MLIR_OPENMP_LIB} 274 | %{MLIR_OPENMPTOLLVM_LIB} 275 | %{MLIR_OPTLIB_LIB} 276 | %{MLIR_PARSER_LIB} 277 | %{MLIR_PASS_LIB} 278 | %{MLIR_PDL_LIB} 279 | %{MLIR_PDLINTERP_LIB} 280 | %{MLIR_PDLTOPDLINTERP_LIB} 281 | %{MLIR_PRESBURGER_LIB} 282 | %{MLIR_PUBLICAPI_LIB} 283 | %{MLIR_PUBLICAPI_COPY_GENRULE} 284 | %{MLIR_QUANT_LIB} 285 | %{MLIR_REDUCE_LIB} 286 | %{MLIR_REWRITE_LIB} 287 | %{MLIR_ROCDLIR_LIB} 288 | %{MLIR_RUNNERUTILS_LIB} 289 | %{MLIR_RUNNERUTILS_COPY_GENRULE} 290 | %{MLIR_SCF_LIB} 291 | %{MLIR_SCFTOGPU_LIB} 292 | %{MLIR_SCFTOOPENMP_LIB} 293 | %{MLIR_SCFTOSPIRV_LIB} 294 | %{MLIR_SCFTOSTANDARD_LIB} 295 | %{MLIR_SCFTRANSFORMS_LIB} 296 | %{MLIR_SDBM_LIB} 297 | %{MLIR_SHAPE_LIB} 298 | %{MLIR_SHAPEOPSTRANSFORMS_LIB} 299 | %{MLIR_SHAPETOSTANDARD_LIB} 300 | %{MLIR_SIDEEFFECTINTERFACES_LIB} 301 | %{MLIR_SPIRV_LIB} 302 | %{MLIR_SPIRVBINARYUTILS_LIB} 303 | %{MLIR_SPIRVCONVERSION_LIB} 304 | %{MLIR_SPIRVDESERIALIZATION_LIB} 305 | %{MLIR_SPIRVMODULECOMBINER_LIB} 306 | %{MLIR_SPIRVSERIALIZATION_LIB} 307 | %{MLIR_SPIRVTOLLVM_LIB} 308 | %{MLIR_SPIRVTRANSFORMS_LIB} 309 | %{MLIR_SPIRVTRANSLATEREGISTRATION_LIB} 310 | %{MLIR_SPIRVUTILS_LIB} 311 | %{MLIR_STANDARD_LIB} 312 | %{MLIR_STANDARDOPSTRANSFORMS_LIB} 313 | %{MLIR_STANDARDTOLLVM_LIB} 314 | %{MLIR_STANDARDTOSPIRV_LIB} 315 | %{MLIR_SUPPORT_LIB} 316 | %{MLIR_SUPPORTINDENTEDOSTREAM_LIB} 317 | %{MLIR_TABLEGEN_LIB} 318 | %{MLIR_TABLEGEN_TOOL} 319 | %{MLIR_TARGETARMNEON_LIB} 320 | %{MLIR_TARGETARMSVE_LIB} 321 | %{MLIR_TARGETAVX512_LIB} 322 | %{MLIR_TARGETLLVMIR_LIB} 323 | %{MLIR_TARGETLLVMIRMODULETRANSLATION_LIB} 324 | %{MLIR_TARGETNVVMIR_LIB} 325 | %{MLIR_TARGETROCDLIR_LIB} 326 | %{MLIR_TENSOR_LIB} 327 | %{MLIR_TENSORTRANSFORMS_LIB} 328 | %{MLIR_TOSA_LIB} 329 | %{MLIR_TOSATOLINALG_LIB} 330 | %{MLIR_TOSATRANSFORMS_LIB} 331 | %{MLIR_TRANSFORMS_LIB} 332 | %{MLIR_TRANSFORMUTILS_LIB} 333 | %{MLIR_TRANSLATION_LIB} 334 | %{MLIR_VECTOR_LIB} 335 | %{MLIR_VECTORTOLLVM_LIB} 336 | %{MLIR_VECTORTOROCDL_LIB} 337 | %{MLIR_VECTORTOSCF_LIB} 338 | %{MLIR_VECTORTOSPIRV_LIB} 339 | %{MLIR_VECTORINTERFACES_LIB} 340 | %{MLIR_VIEWLIKEINTERFACE_LIB} 341 | 342 | %{DEBUG_DEP_LIBS} 343 | %{DEP_LIBS} 344 | 345 | %{LIBCXX_HEADERS_LIB} 346 | %{LIBCXX_STATIC_LIB} 347 | %{LIBCXX_SHARED_LIB} 348 | %{LIBCXX_SHARED_COPY_GENRULE} 349 | %{LIBCXX_ABI_STATIC_LIB} 350 | %{LIBCXX_ABI_SHARED_LIB} 351 | %{LIBCXX_ABI_SHARED_COPY_GENRULE} 352 | -------------------------------------------------------------------------------- /llvm/llvm_config.bzl.tpl: -------------------------------------------------------------------------------- 1 | # -*- Python -*- 2 | """Skylark macros for bazel-llvm-bridge. 3 | 4 | llvm_enables_eh is a flag that displays if LLVM is built with exception 5 | support. 6 | 7 | if_llvm_enables_eh is a condition to check if the LLVM installation 8 | is built with enabled exception support. If so, the first argument will 9 | be returned, otherwise the second one. 10 | 11 | llvm_enables_rtti is a flag that displays if LLVM is built with enabled 12 | RTTI. 13 | 14 | if_llvm_enables_rtti is a condition to check if the LLVM installation 15 | is built with enabled RTTI. If so, the first argument will be returned, 16 | otherwise the second one. 17 | 18 | llvm_nix_copts is a convenient set of platform-dependent compiler options 19 | to enable the building process of LLVM-dependent targets for *Nix platforms. 20 | It can disable RTTI and enable the right level of C++. 21 | 22 | llvm_win_copts is a convenient set of platform-dependent compiler options 23 | to enable the building process of LLVM-dependent targets for Windows platform. 24 | It can disable RTTI and enable the right level of C++. 25 | 26 | llvm_has_cxx is a flag that displays if the local installation of LLVM 27 | contains the "libc++" standard library. 28 | 29 | if_has_cxx is a condition to check if the LLVM installation 30 | contains the "libc++" standard library. If so, the first argument 31 | will be returned, otherwise the second one. 32 | 33 | llvm_targets is a list of supported targets ("AArch64", "ARM", "X86", etc.) 34 | 35 | if_has_ is a condition to check if we are building with the target 36 | . If the target is supported, the first argument will be returned, 37 | otherwise the second one. 38 | """ 39 | 40 | llvm_enables_eh = %{LLVM_ENABLE_EH} 41 | 42 | def if_llvm_enables_eh(if_true, if_false = []): 43 | return if_true if llvm_enables_eh else if_false 44 | 45 | llvm_enables_rtti = %{LLVM_ENABLE_RTTI} 46 | 47 | def if_llvm_enables_rtti(if_true, if_false = []): 48 | return if_true if llvm_enables_rtti else if_false 49 | 50 | llvm_nix_copts = [ 51 | "-Wno-unused-member-function", 52 | "-Wno-unused-parameter", 53 | "-Wno-unused-private-field", 54 | "-Wno-unused-variable", 55 | "-Wno-used-but-marked-unused", 56 | ] + if_llvm_enables_rtti(["-frtti"], ["-fno-rtti"] 57 | ) + if_llvm_enables_eh(["-fexceptions"], ["-fno-exceptions"]) 58 | 59 | llvm_win_copts = [ 60 | "/bigobj", 61 | "-wd4141", 62 | "-wd4146", 63 | "-wd4244", 64 | "-wd4267", 65 | "-wd4624", 66 | "-w14062", 67 | "-we4238", 68 | ] + if_llvm_enables_rtti(["/GR"], ["/GR-"]) 69 | # Bazel currently pass /EHsc to enable exception by default. 70 | # We cannot disable exceptions: a lot of warnings D9025 will be generated. 71 | #+ if_llvm_enables_eh( 72 | # ["/EHsc"], 73 | # ["/EHs-c-", "/D_HAS_EXCEPTIONS=0"]) 74 | 75 | llvm_has_cxx = %{LLVM_HAS_CXX} 76 | 77 | llvm_targets = [ 78 | %{LLVM_TARGETS} 79 | ] 80 | 81 | def if_has_cxx(if_true, if_false = []): 82 | return if_true if llvm_has_cxx else if_false 83 | 84 | def if_has_aarch64(if_true, if_false = []): 85 | return if_true if "AArch64" in llvm_targets else if_false 86 | 87 | def if_has_amdgpu(if_true, if_false = []): 88 | return if_true if "AMDGPU" in llvm_targets else if_false 89 | 90 | def if_has_arm(if_true, if_false = []): 91 | return if_true if "ARM" in llvm_targets else if_false 92 | 93 | def if_has_avr(if_true, if_false = []): 94 | return if_true if "AVR" in llvm_targets else if_false 95 | 96 | def if_has_bpf(if_true, if_false = []): 97 | return if_true if "BPF" in llvm_targets else if_false 98 | 99 | def if_has_hexagon(if_true, if_false = []): 100 | return if_true if "Hexagon" in llvm_targets else if_false 101 | 102 | def if_has_lanai(if_true, if_false = []): 103 | return if_true if "Lanai" in llvm_targets else if_false 104 | 105 | def if_has_mips(if_true, if_false = []): 106 | return if_true if "Mips" in llvm_targets else if_false 107 | 108 | def if_has_msp430(if_true, if_false = []): 109 | return if_true if "MSP430" in llvm_targets else if_false 110 | 111 | def if_has_nvptx(if_true, if_false = []): 112 | return if_true if "NVPTX" in llvm_targets else if_false 113 | 114 | def if_has_powerpc(if_true, if_false = []): 115 | return if_true if "PowerPC" in llvm_targets else if_false 116 | 117 | def if_has_riscv(if_true, if_false = []): 118 | return if_true if "RISCV" in llvm_targets else if_false 119 | 120 | def if_has_sparc(if_true, if_false = []): 121 | return if_true if "Sparc" in llvm_targets else if_false 122 | 123 | def if_has_system_z(if_true, if_false = []): 124 | return if_true if "SystemZ" in llvm_targets else if_false 125 | 126 | def if_has_web_assembly(if_true, if_false = []): 127 | return if_true if "WebAssembly" in llvm_targets else if_false 128 | 129 | def if_has_x86(if_true, if_false = []): 130 | return if_true if "X86" in llvm_targets else if_false 131 | 132 | def if_has_x_core(if_true, if_false = []): 133 | return if_true if "XCore" in llvm_targets else if_false 134 | -------------------------------------------------------------------------------- /llvm/llvm_tablegen.bzl.tpl: -------------------------------------------------------------------------------- 1 | # -*- Python -*- 2 | """Skylark rule for running %{NAME} Tablegen. 3 | 4 | Example: 5 | %{PREFIX}tablegen( 6 | name = "mlir_toyc_td_decl", 7 | src = "mlir/toy/include/toy/Ops.td", 8 | out = "toy/Ops.h.inc", 9 | opts = ["-gen-op-decls"], 10 | deps = ["@local_llvm//:ml_headers"], 11 | visibility = ["//visibility:private"], 12 | ) 13 | """ 14 | 15 | def _get_transitive_hdrs(srcs, deps): 16 | """Obtain the source files for a target and header files for its 17 | transitive dependencies. 18 | 19 | Args: 20 | srcs: a list of source files 21 | deps: a list of targets that are direct dependencies 22 | Returns: 23 | a collection of the sources and transitive headers 24 | """ 25 | return depset( 26 | srcs, 27 | transitive = [dep[CcInfo].compilation_context.headers for dep in deps], 28 | ) 29 | 30 | def _get_transitive_includes(srcs, includes, deps): 31 | """Obtain the list of include directories for a target 32 | and its transitive dependencies. 33 | 34 | Args: 35 | srcs: a list of source files 36 | includes: a list of include directories 37 | deps: a list of targets that are direct dependencies 38 | Returns: 39 | a list of transitive include directories for a target 40 | """ 41 | return depset( 42 | [src.dirname for src in srcs] + includes, 43 | transitive 44 | = depset( 45 | [dep[CcInfo].compilation_context.system_includes for dep in deps], 46 | transitive 47 | = [dep[CcInfo].compilation_context.includes for dep in deps]) 48 | .to_list()) 49 | 50 | def _tablegen_impl(ctx): 51 | # Collect the list of srcs (required for a sandboxed build) 52 | srcs = ctx.files.srcs + ctx.files.src 53 | sources_list = _get_transitive_hdrs(srcs, ctx.attr.deps).to_list() 54 | 55 | # Collect the list of includes 56 | includes = ["-I" + i for i in _get_transitive_includes(srcs, 57 | ctx.attr.includes, ctx.attr.deps).to_list()] 58 | 59 | # Combine the arguments together 60 | args = ctx.attr.opts + includes + ["-o", ctx.outputs.out.path] 61 | args += [s.path for s in ctx.files.src] 62 | 63 | # Action to call the tablegen 64 | ctx.actions.run( 65 | inputs = sources_list, 66 | outputs = [ctx.outputs.out], 67 | arguments = args, 68 | progress_message = "%{NAME} Tablegen for %s" % ctx.files.src[0].short_path, 69 | executable = ctx.executable._tablegen, 70 | ) 71 | 72 | return [ 73 | CcInfo( 74 | compilation_context = cc_common.create_compilation_context( 75 | includes = depset([ctx.outputs.out.dirname]), 76 | headers = depset([ctx.outputs.out]) 77 | ) 78 | ) 79 | ] 80 | 81 | %{PREFIX}tablegen = rule( 82 | implementation = _tablegen_impl, 83 | attrs = { 84 | "srcs": attr.label_list(allow_files = True), 85 | "src": attr.label(mandatory = True, allow_files = True), 86 | "out": attr.output(mandatory = True), 87 | "opts": attr.string_list(mandatory = True), 88 | "includes": attr.string_list(), 89 | "deps": attr.label_list(), 90 | "_tablegen": attr.label( 91 | executable = True, 92 | cfg = "host", 93 | allow_files = True, 94 | default = Label("//:%{PREFIX}tablegen_tool"), 95 | ) 96 | } 97 | ) 98 | --------------------------------------------------------------------------------