llvm with tablegen backend for capstone disassembler
Go to file
max 92233062c1 [mlir][python bindings] generate all the enums
This PR implements python enum bindings for *all* the enums - this includes `I*Attrs` (including positional/bit) and `Dialect/EnumAttr`.

There are a few parts to this:

1. CMake: a small addition to `declare_mlir_dialect_python_bindings` and `declare_mlir_dialect_extension_python_bindings` to generate the enum, a boolean arg `GEN_ENUM_BINDINGS` to make it opt-in (even though it works for basically all of the dialects), and an optional `GEN_ENUM_BINDINGS_TD_FILE` for handling corner cases.
2. EnumPythonBindingGen.cpp: there are two weedy aspects here that took investigation:
    1. If an enum attribute is not a `Dialect/EnumAttr` then the `EnumAttrInfo` record is canonical, as far as both the cases of the enum **and the `AttrDefName`**. On the otherhand, if an enum is a `Dialect/EnumAttr` then the `EnumAttr` record has the correct `AttrDefName` ("load bearing", i.e., populates `ods.ir.AttributeBuilder('<NAME>')`) but its `enum` field contains the cases, which is an instance of `EnumAttrInfo`. The solution is to generate an one enum class for both `Dialect/EnumAttr` and "independent" `EnumAttrInfo` but to make that class interopable with two builder registrations that both do the right thing (see next sub-bullet).
    2. Because we don't have a good connection to cpp `EnumAttr`, i.e., only the `enum class` getters are exposed (like `DimensionAttr::get(Dimension value)`), we have to resort to parsing e.g., `Attribute.parse(f'#gpu<dim {x}>')`. This means that the set of supported `assemblyFormat`s (for the enum) is fixed at compile of MLIR (currently 2, the only 2 I saw). There might be some things that could be done here but they would require quite a bit more C API work to support generically (e.g., casting ints to enum cases and binding all the getters or going generically through the `symbolize*` methods, like `symbolizeDimension(uint32_t)` or `symbolizeDimension(StringRef)`).

A few small changes:

1. In addition, since this patch registers default builders for attributes where people might've had their own builders already written, I added a `replace` param to `AttributeBuilder.insert` (`False` by default).
2. `makePythonEnumCaseName` can't handle all the different ways in which people write their enum cases, e.g., `llvm.CConv.Intel_OCL_BI`, which gets turned into `INTEL_O_C_L_B_I` (because `llvm::convertToSnakeFromCamelCase` doesn't look for runs of caps). So I dropped it. On the otherhand regularization does need to done because some enums have `None` as a case (and others might have other python keywords).
3. I turned on `llvm` dialect generation here in order to test `nvvm.WGMMAScaleIn`, which is an enum with [[ d7e26b5620/mlir/include/mlir/IR/EnumAttr.td (L22-L25) | no explicit discriminator ]] for the `neg` case.

Note, dialects that didn't get a `GEN_ENUM_BINDINGS` don't have any enums to generate.

Let me know if I should add more tests (the three trivial ones I added exercise both the supported `assemblyFormat`s and `replace=True`).

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D157934
2023-08-23 15:03:55 -05:00
.ci [ci] Make libc++ and Clang CI scripts independent 2023-07-12 14:01:38 -04:00
.github/workflows workflows: Disable repo-lockdown for llvm/utils/git 2023-08-23 07:51:29 -07:00
bolt [BOLT] Implement createRelocation for AArch64 2023-08-23 00:53:32 +08:00
clang [AMDGPU] Prepend --no-undefined option for linker instead of append 2023-08-23 12:25:01 -07:00
clang-tools-extra [clang-tidy] Fix test to not depend on D153156, which was reverted 2023-08-22 18:39:19 -07:00
cmake [CMake] Switch the CMP0091 policy (MSVC_RUNTIME_LIBRARY) to the new behaviour 2023-07-17 09:59:05 +03:00
compiler-rt [builtins] Avoid undefined behavior when calculating absolute value in floatsidf.c and floatsisf.c 2023-08-23 08:57:18 +02:00
cross-project-tests Revert "[Dexter] Remove builder from Dexter" 2023-08-21 18:06:27 +01:00
flang [flang][openacc] Restrict number of device_type values on the set directive 2023-08-23 11:59:49 -07:00
libc [libc] Remove MAX_LANE_SIZE definition from the RPC server 2023-08-23 12:09:30 -05:00
libclc Reland "[CMake] Bumps minimum version to 3.20.0. 2023-05-27 12:51:21 +02:00
libcxx [libcxx][NFC] Update status documentation for stride range view 2023-08-23 19:28:37 +02:00
libcxxabi [libc++] Fix a few incorrect CMake configuration options 2023-08-17 09:43:09 -04:00
libunwind MIPS: unwind, don't save/restore hi/lo for R6 2023-08-19 00:35:25 -04:00
lld [lld] Do not include StringSwitch.h (NFC) 2023-08-23 09:20:14 -07:00
lldb [lldb/test] Fix Crashlog/no-args.test on ASAN builds (NFC) 2023-08-23 07:32:35 -07:00
llvm [AMDGPU] Emit .actual_access metadata 2023-08-23 12:57:29 -07:00
llvm-libgcc [llvm-libgcc] Don't export __{,de}register_frame_info* and __register_frame_table 2023-08-23 13:00:36 -07:00
mlir [mlir][python bindings] generate all the enums 2023-08-23 15:03:55 -05:00
openmp [OpenMP] Force the parallel abstraction to be inlined 2023-08-23 11:48:18 -07:00
polly Headers for basic blocks in CFG dot graphs 2023-08-17 07:55:23 -07:00
pstl Clear release notes for 18.x 2023-07-25 13:58:49 +02:00
runtimes Reland "[CMake] Bumps minimum version to 3.20.0. 2023-05-27 12:51:21 +02:00
third-party [unittest] teach gTest to print entries of DenseMap as pairs 2023-06-28 11:29:52 +02:00
utils [bazel] keep args one-per-line 2023-08-23 08:44:13 +00:00
.arcconfig
.arclint
.clang-format
.clang-tidy Add -misc-use-anonymous-namespace to .clang-tidy 2023-05-06 02:33:20 +03:00
.git-blame-ignore-revs Revert "[mlir][spirv] Add D155747 to .git-blame-ignore-revs" 2023-07-21 10:59:16 -04:00
.gitignore [llvm] Ignore .rej files in .gitignore 2022-04-28 08:44:51 -07:00
.mailmap Add entry to mailmap 2023-04-25 23:15:07 -07:00
CONTRIBUTING.md Added instruction to join the llvm discourse and discord group. 2023-03-27 17:02:07 -07:00
LICENSE.TXT [docs] Add LICENSE.txt to the root of the mono-repo 2022-08-24 09:35:00 +02:00
README.md [docs] Update README and GettingStarted 2023-03-08 12:55:59 -08:00
SECURITY.md

The LLVM Compiler Infrastructure

Welcome to the LLVM project!

This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.

The LLVM project has multiple components. The core of the project is itself called "LLVM". This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.

C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.

Other components include: the libc++ C++ standard library, the LLD linker, and more.

Getting the Source Code and Building LLVM

Consult the Getting Started with LLVM page for information on building and running LLVM.

For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.

Getting in touch

Join the LLVM Discourse forums, Discord chat, or #llvm IRC channel on OFTC.

The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.