{"id":21529234,"url":"https://github.com/everx-labs/tvm-compiler","last_synced_at":"2025-04-09T23:51:46.665Z","repository":{"id":35508901,"uuid":"216748315","full_name":"everx-labs/TVM-Compiler","owner":"everx-labs","description":"Clang compiler for TVM","archived":false,"fork":false,"pushed_at":"2023-09-25T13:54:48.000Z","size":647928,"stargazers_count":62,"open_issues_count":15,"forks_count":16,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-09T23:51:07.600Z","etag":null,"topics":["blockchain","clang","everscale","llvm"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/everx-labs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-10-22T07:19:20.000Z","updated_at":"2025-03-23T16:06:00.000Z","dependencies_parsed_at":"2024-04-03T19:09:36.504Z","dependency_job_id":null,"html_url":"https://github.com/everx-labs/TVM-Compiler","commit_stats":null,"previous_names":["tonlabs/tvm-compiler","everx-labs/tvm-compiler"],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everx-labs%2FTVM-Compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everx-labs%2FTVM-Compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everx-labs%2FTVM-Compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/everx-labs%2FTVM-Compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/everx-labs","download_url":"https://codeload.github.com/everx-labs/TVM-Compiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131454,"owners_count":21052819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","clang","everscale","llvm"],"created_at":"2024-11-24T01:56:27.359Z","updated_at":"2025-04-09T23:51:41.649Z","avatar_url":"https://github.com/everx-labs.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C and C++ compiler for TVM\n\n`Getting C++ toolchain in binary form`\nThis README is mostly about building C++ for TVM which is the most appropriate way to get the compiler and the library for contributors. If your intent is only to use the compiler, we provide binary package you can simply download:\n- [For Ubuntu](http://sdkbinaries-ws.tonlabs.io/clang-for-tvm/clang-for-tvm.tar.gz)\n- [For Mac OS X](https://sdkbinaries.tonlabs.io/clang-for-tvm/clang-for-tvm-darwin.zip)\n\nThe binaries are updated on every commit in master, so they are always up to date.\n\n`Clang for TVM based on LLVM 7.0.0`.\nThis repository contain\n* Clang for TVM C and C++ compiler\n* [C++ runtime and SDK headers-only library](https://github.com/tonlabs/TON-Compiler/tree/master/llvm/projects/ton-compiler)\n* [C runtime and SDK library](https://github.com/tonlabs/TON-Compiler/tree/master/llvm/projects/ton-compiler)\nThe following guide is about building the compilers and installing them, to find a user guide and example contracts, please refer to [the samples repository](https://github.com/tonlabs/samples).\n\n## Prerequisites\nTo build the toolchain, you need a recent C++ toolchain supporting C++17:\n- MSVC 2017 or newer\n- Clang 6.0.0 or newer\n- GCC 7.3.0 or newer\n- Rust 1.47.0 or newer\n- Cargo\n\nStable operation of older toolchains is not guaranteed.\nYou also need zlib 1.2.3.4 or newer. Python 2.7 is required to run tests. Optionally, you can use ninja-build.\nFor more info about LLVM software requirements visit: [https://llvm.org/docs/GettingStarted.html](https://llvm.org/docs/GettingStarted.html).\n\n## Supported operation systems\nWe expect the project to build successfully on\n- Ubuntu 16.04, 18.04\n- Mac OS Mojave 10.14.3 or higher\n- Windows 10\n\n## Building and installing\nTo build and to install the compiler use the following script:\n```\n$ git clone git@github.com:tonlabs/TON-Compiler.git \u0026\u0026 cd TON-Compiler\n$ mkdir build\n$ cd build\n$ cmake -DCMAKE_INSTALL_PREFIX=/path/to/install -C /path/to/TON-Compiler/cmake/Cache/ton-compiler.cmake ../llvm\n$ cmake --build . --target install-distribution\n```\nNotes:\n* `/path/to/install` must be complete path to the installation folder, otherwise Clang might be unable to find all the libraries, headers and tools by default.\n* We strongly recommend to use the installed version of the compiler, otherwise it might be unable to find the required headers and tools by itself, so they have to be specified by hands.\n* A complete C and C++ toolchain require [tvm_linker](https://github.com/tonlabs/TVM-linker/) to be built. We recommend to put the liker binary to `/path/to/install/bin` directory. Otherwise you might need to use `-fuse-ld` option to spicify full name of the linker.\n* `install-distribution` installs only required minimum of tools, while `install` target copies all the LLVM tools to the installation folder. These additional tools doesn't necessary work with TVM target properly.\n\nFor Windows / Microsoft Visual Studio 2017/2020 (clang Compiler without linker \u0026 other external tools)\n```\n\u003e git clone git@github.com:tonlabs/TON-Compiler.git \u0026\u0026 cd TON-Compiler\n\u003e mkdir build\n\u003e cd build\n\u003e cmake -G \"Visual Studio 15\" -DLLVM_TARGETS_TO_BUILD=\"TVM\" -C /path/to/TON-Compiler/cmake/Cache/ton-compiler-alone.cmake ../llvm\n```\n\nThen open generated solution file LLVM.sln with Visual Studio\n\n### Troubleshooting and speeding up the build\nBuilding Clang takes quite a bit of time, below we list some options to speed it up:\n* Use faster build system via `-GXXX` option. We recommend to choose `ninja-build` (you might need to install it first) using `-GNinja`.\n* Use a faster linker via `-DCMAKE_LINKER=\u003clinker name\u003e`. It's known that `lld` is faster than `gold`, and gold is faster than `ld`. On Linux, however, `lld` might not be a part of the default toolchain, so you might have to install it first.\n* Use a faster compiler via `-DCMAKE_C_COMPILER=\u003ccompiler\u003e` and `-DCMAKE_CXX_COMPILER=\u003ccompiler\u003e`. Clang might be slightly faster than GCC.\n* Build dynamically linked version of Clang via `-DBUILD_SHARED_LIB=On`.\nNote that building Clang also require a tens of gigabytes of disk space (especially for a static build) and several gigabytes of RAM to be build. In case, you run out of memory `-DLLVM_PARALLEL_LINK_JOBS=N` might be of help. This option limits the number of link jobs running in parallel does the footpring. There is also a separate option `-DLLVM_PARALLEL_COMPILE_JOBS=N` to limit number of compilation jobs running in parallel.\nTo learn more about possible configurations of LLVM build, please refer to [LLVM documentation](https://llvm.org/docs/CMake.html). In case you are experiencing problems with build, we would appreciete raising an issue in this repository.\n\n## Running tests\nTo run tests for TVM, execute\n```\n$ cmake --build . --target check-llvm-codegen-tvm\n```\n\nTo run tests for other platforms (to ensure that LLVM itself is not broken), you have to create a separate build without using `/path/to/TON-Compiler/cmake/Cache/ton-compiler.cmake` config and run\n```\n$ cmake --build . --target check all\n```\n\nFor more details see [testing.md](https://github.com/tonlabs/TON-Compiler/blob/readme/testing.md).\n\n## Example of usage\nYou can learn more about C++ for TVM and find examples of usage of C++ toolchain [here](https://github.com/tonlabs/samples/tree/master/cpp). C toolchain is mostly for geeks who want to follow TVM assembly closely, but doesn't want to work with stack. C examples might be found [here](https://github.com/tonlabs/samples/tree/master/c).\n\n## Getting support\nC and C++ for TVM, being similar to conventional C and C++, has their own extensions and limitations, so if you are getting started with programming for TVM, we recommend to first refer to [the examples repository](https://github.com/tonlabs/samples).\nTexts, videos and samples illustrating how to use the compiler will soon appear at https://ton.dev/ and https://www.youtube.com/channel/UC9kJ6DKaxSxk6T3lEGdq-Gg. Stay tuned.\nYou can also get support in [TON Dev Telegram channel](https://t.me/tondev_en).\nIn case you found a bug, raise an issue in the repository. Please attach the source file, the command to reproduce the failure and your machine description.\n\n## Contribution policy\nThe project strives to follow LLVM coding standards and policies as well as C++ Core Guidelines, so before contributing, we recommend you to familiarize with the following documents:\n- [LLVM Developer Policy](https://llvm.org/docs/DeveloperPolicy.html)\n- [LLVM Coding Standards](https://llvm.org/docs/CodingStandards.html)\n- [LLVM Programmer’s Manual](http://llvm.org/docs/ProgrammersManual.html)\n- [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md)\n\nNote: Since TVM backend uses C++17 which is not yet fully supported in LLVM, the guidelines could be reasonably adjusted for cases of C++17 usages. C++17 data structures are preferred over LLVM counterparts, for instance, `std::optional\u003cT\u003e` is better to use w.r.t. `llvm::Optional\u003cT\u003e`.\n\nAll changes in LLVM (excluding `lib/Target/TVM` subdirectory) must be marked as local changes in the following way:\n```\n// TVM local begin\n\u003cchanged LLVM code\u003e\n// TVM local end\n```\nThe reason is to help resolving merge conflicts when updating LLVM to a new version.\n\nAll removals from LLVM must be commented out instead:\n```\n#if 0\n\u003cremoved LLVM code\u003e\n#endif\n```\nThe reason is to minimize number of merge conflicts when updating LLVM to a new version.\nTo learn more about development a downstream LLVM project, refer to [https://llvm.org/devmtg/2015-10/slides/RobinsonEdwards-LivingDownstreamWithoutDrowning.pdf](https://llvm.org/devmtg/2015-10/slides/RobinsonEdwards-LivingDownstreamWithoutDrowning.pdf).\n\n## Upstreaming\nWe believe that LLVM community would benefit from getting TVM backend upstream. It's a very distinct architecture, that break several assumptions. For instance, Clang front-end and the optimizer relies on 8-bit bytes byte which is not true for TVM as well as for some non-mainstream processors. Furthermore, target independent code generator is designed for a register machine, so stack machine support is benefitial at least for WebAssembly. So, with some constraints removed, LLVM will be better placed to downstream development and we believe it is feasible without damaging existing targets.\nWe would like to implement, upstream and maintain the following features:\n* Byte size specified in data layout, removing magical number 8 from the optimizer.\n* memset, memcopy, memmove configured with the byte size.\n* DAG scheduler for a stack machine.\n* Generic analysis and transformation passes to optimize for stack machine on MIR level.\nThe current version of Clang for TVM is based on LLVM 7.0.0, it's planned update LLVM, remove hardcoded byte size and adopt opaque types insted of types we introduced to LLVM.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feverx-labs%2Ftvm-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feverx-labs%2Ftvm-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feverx-labs%2Ftvm-compiler/lists"}