Re: Llvm Visual Studio Code

0 views
Skip to first unread message
Message has been deleted

Teodolinda Mattson

unread,
Jul 11, 2024, 11:36:44 PM7/11/24
to clearpounece

There are many different projects that compose LLVM. The first piece is theLLVM suite. This contains all of the tools, libraries, and header files neededto use LLVM. It contains an assembler, disassembler, bitcode analyzer andbitcode optimizer. It also contains basic regression tests that can be used totest the LLVM tools and the Clang front end.

llvm visual studio code


Descargar archivo https://tinurli.com/2yPGGN



The second piece is the Clang front end. Thiscomponent compiles C, C++, Objective C, and Objective C++ code into LLVMbitcode. Clang typically uses LLVM libraries to optimize the bitcode and emitmachine code. LLVM fully supports the COFF object file format, which iscompatible with all other existing Windows toolchains.

Any system that can adequately run Visual Studio 2019 is fine. The LLVMsource tree including the git index consumes approximately 3GB.Object files, libraries and executables consume approximately 5GB inRelease mode and much more in Debug mode. SSD drive and >16GB RAM arerecommended.

You will also need the CMake build system since itgenerates the project files you will use to build with. CMake is bundled withVisual Studio 2019 so separate installation is not required. If you do installCMake separately, Visual Studio 2022 will require CMake Version 3.21 or later.

If you would like to run the LLVM tests you will need Python. Version 3.8 and newer are known to work. You caninstall Python with Visual Studio 2019, from the Microsoft store or fromthe Python web site. We recommend the latter since itallows you to adjust installation options.

In the first install screen, select both Install launcher for all usersand Add Python to the PATH. This will allow installing psutil for allusers for the regression tests and make Python available from the commandline.

Instead of git clone you may download a compressed source distributionfrom the releases page.Select the last link: Source code (zip) and unpack the downloaded file usingWindows Explorer built-in zip support or any other unzip tool.

LLVM_ENABLE_PROJECTS specifies any additional LLVM projects you want tobuild while LLVM_TARGETS_TO_BUILD selects the compiler targets. IfLLVM_TARGETS_TO_BUILD is omitted by default all targets are builtslowing compilation and using more disk space.See the LLVM CMake guide for detailed information abouthow to configure the LLVM build.

Once CMake is installed then the simplest way is to just start theCMake GUI, select the directory where you have LLVM extracted to, andthe default options should all be fine. One option you may reallywant to change, regardless of anything else, might be theCMAKE_INSTALL_PREFIX setting to select a directory to INSTALL toonce compiling is complete, although installation is not mandatory forusing LLVM. Another important option is LLVM_TARGETS_TO_BUILD,which controls the LLVM target architectures that are included on thebuild.

By default, the Visual Studio project files generated by CMake use the32-bit toolset. If you are developing on a 64-bit version of Windows andwant to use the 64-bit toolset, pass the -Thost=x64 flag whengenerating the Visual Studio solution. This requires CMake 3.8.0 or later.

In the directory you created the project files will have an llvm.slnfile, just double-click on that to open Visual Studio. The default VisualStudio configuration is Debug which is slow and generates a huge amountof debug information on disk. For now, we recommend selecting Releaseconfiguration for the LLVM project which will build the fastest orRelWithDebInfo which is also several time larger than Release.Another technique is to build all of LLVM in Release mode and changecompiler flags, disabling optimization and enabling debug information, onlyfor specific libraries or source files you actually need to debug.

Instead of the steps above, to simplify the installation procedure you can useChocolatey as package manager.After the installation of Chocolatey,run these commands in an admin shell to install the required tools:

This example assumes that Python is in your PATH variable, which would beafter Add Python to the PATH was selected during Python installation.If you had opened a command window prior to Python installation, you wouldhave to close and reopen it to get the updated PATH.

The projects may still be built individually, but to build them all donot just select all of them in batch build (as some are meant asconfiguration projects), but rather select and build just theALL_BUILD project to build everything, or the INSTALL project,which first builds the ALL_BUILD project, then installs the LLVMheaders, libs, and other useful things to the directory set by theCMAKE_INSTALL_PREFIX setting when you first configured CMake.

You can use the source code from a standard checkout of the llvm-project(as described above) to do stand-alone builds, but you may also buildfrom a sparse checkout or from thetarballs available on the releasespage.

For stand-alone builds, you must have an llvm install that is configuredproperly to be consumable by stand-alone builds of the other projects.This could be a distro provided LLVM install, or you can build it yourself,like this:

Note that Debug builds require a lot of time and disk space. An LLVM-only buildwill need about 1-3 GB of space. A full build of LLVM and Clang will need around15-20 GB of disk space. The exact space requirements will vary by system. (Itis so large because of all the debugging information and the fact that thelibraries are statically linked into multiple tools).

The LLVM suite may compile on other platforms, but it is not guaranteed to doso. If compilation is successful, the LLVM utilities should be able toassemble, disassemble, analyze, and optimize LLVM bitcode. Code generationshould work as well, although the generated native code may not work on yourplatform.

LLVM is very demanding of the host C++ compiler, and as such tends to exposebugs in the compiler. We also attempt to follow improvements and developments inthe C++ language and library reasonably closely. As such, we require a modernhost C++ toolchain, both compiler and standard library, in order to build LLVM.

Anything older than these toolchains may work, but will require forcing thebuild system with a special option and is not really a supported host platform.Also note that older versions of these compilers have often crashed ormiscompiled LLVM.

GNU Binutils 2.19.1 Gold: This version of Gold contained a bug which causesintermittent failures when building LLVM with position independent code. Thesymptom is an error about cyclic dependencies. We recommend upgrading to anewer version of Gold.

However, some Linux distributions and some other or older BSDs sometimes haveextremely old versions of GCC. These steps attempt to help you upgrade youcompiler even on such a system. However, if at all possible, we encourage youto use a recent version of a distribution with a modern system compiler thatmeets these requirements. Note that it is tempting to install a priorversion of Clang and libc++ to be the host compiler, however libc++ was notwell tested or set up to build on Linux until relatively recently. Asa consequence, this guide suggests just using libstdc++ and a modern GCC as theinitial host in a bootstrap, and then using Clang (and potentially libc++).

Once you have a GCC toolchain, configure your build of LLVM to use the newtoolchain for your host compiler and C++ standard library. Because the newversion of libstdc++ is not on the system library search path, you need to passextra linker flags so that it can be found at link time (-L) and at runtime(-rpath). If you are using CMake, this invocation should produce workingbinaries:

The later sections of this guide describe the general layout of the LLVMsource tree, a simple example using the LLVM tool chain, and links to findmore information about LLVM or to get help via e-mail.

Throughout this manual, the following names are used to denote paths specific tothe local system and working environment. These are not environment variablesyou need to set but just strings used in the rest of this document below. Inany of the examples below, simply replace each of these names with theappropriate pathname on your local system. All these paths are absolute:

Once checked out repository, the LLVM suite source code must be configuredbefore being built. This process uses CMake. Unlinke the normal configurescript, CMake generates the build files in whatever format you request as wellas various *.inc files, and llvm/include/llvm/Config/config.h.cmake.

For these builds, the build system will compile the tools and librarieswith optimizations enabled and not generate debug info. CMakes defaultoptimization level is -O3. This can be configured by setting theCMAKE_CXX_FLAGS_RELEASE variable on the CMake command line.

These builds are useful when debugging. They generate optimized binaries withdebug information. CMakes default optimization level is -O2. This can beconfigured by setting the CMAKE_CXX_FLAGS_RELWITHDEBINFO variable on theCMake command line.

It is possible to cross-compile LLVM itself. That is, you can create LLVMexecutables and libraries to be hosted on a platform different from the platformwhere they are built (a Canadian Cross build). To generate build files forcross-compiling CMake provides a variable CMAKE_TOOLCHAIN_FILE which candefine compiler flags and variables used during the CMake test operations.

The result of such a build is executables that are not runnable on the buildhost but can be executed on the target. As an example the following CMakeinvocation can generate build files targeting iOS. This will work on macOSwith the latest Xcode:

The LLVM build system is capable of sharing a single LLVM source tree amongseveral LLVM builds. Hence, it is possible to build LLVM for several differentplatforms or configurations using the same source tree.

Kaleidoscope Tutorial: Kaleidoscope language tutorial run through theimplementation of a nice little compiler for a non-trivial languageincluding a hand-written lexer, parser, AST, as well as code generationsupport using LLVM- both static (ahead of time) and various approaches toJust In Time (JIT) compilation.Kaleidoscope Tutorial for complete beginner.

d3342ee215
Reply all
Reply to author
Forward
0 new messages