### Example: Stand-alone Clang Build Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/llvm/docs/GettingStarted.rst A shell script demonstrating the process of building LLVM, installing it, and then building Clang as a stand-alone project. ```shell #!/bin/sh build_llvm=`pwd`/build-llvm build_clang=`pwd`/build-clang installprefix=`pwd`/install llvm=`pwd`/llvm-project mkdir -p $build_llvm mkdir -p $installprefix cmake -G Ninja -S $llvm/llvm -B $build_llvm \ -DLLVM_INSTALL_UTILS=ON \ -DCMAKE_INSTALL_PREFIX=$installprefix \ -DCMAKE_BUILD_TYPE=Release ninja -C $build_llvm install cmake -G Ninja -S $llvm/clang -B $build_clang \ -DLLVM_EXTERNAL_LIT=$build_llvm/utils/lit \ -DLLVM_ROOT=$installprefix ninja -C $build_clang ``` -------------------------------- ### Test Polly Installation Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/polly/www/get_started.html Runs the test suite for Polly after building. ```bash cmake --build . --target check-polly ``` -------------------------------- ### LLVM Installation for Stand-alone Builds Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/llvm/docs/GettingStarted.rst Installs LLVM with utility files, specifying the installation prefix, to be used for stand-alone builds of other projects. ```console cmake -G Ninja -S path/to/llvm-project/llvm -B $builddir \ -DLLVM_INSTALL_UTILS=ON \ -DCMAKE_INSTALL_PREFIX=/path/to/llvm/install/prefix \ < other options > ninja -C $builddir install ``` -------------------------------- ### Install LLVM Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/llvm/docs/GettingStarted.rst Installs LLVM header files, libraries, tools, and documentation to the path specified by CMAKE_INSTALL_PREFIX. ```console make install ``` -------------------------------- ### Install GCC from Source Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/llvm/docs/GettingStarted.rst Provides console commands to download, verify, build, and install a specific version of GCC from source. This is useful for systems with outdated default compilers. ```console %gcc_version=7.4.0 %wget https://ftp.gnu.org/gnu/gcc/gcc-${gcc_version}/gcc-${gcc_version}.tar.bz2 %wget https://ftp.gnu.org/gnu/gcc/gcc-${gcc_version}/gcc-${gcc_version}.tar.bz2.sig %wget https://ftp.gnu.org/gnu/gnu-keyring.gpg %signature_invalid=`gpg --verify --no-default-keyring --keyring ./gnu-keyring.gpg gcc-${gcc_version}.tar.bz2.sig` %if [ $signature_invalid ]; then echo "Invalid signature" ; exit 1 ; fi %tar -xvjf gcc-${gcc_version}.tar.bz2 %cd gcc-${gcc_version} %./contrib/download_prerequisites %cd .. %mkdir gcc-${gcc_version}-build %cd gcc-${gcc_version}-build %${PWD}/../gcc-${gcc_version}/configure --prefix=$HOME/toolchains --enable-languages=c,c++ %make -j$(nproc) %make install ``` -------------------------------- ### LLVM Installation Steps (Windows Batch) Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/llvm/docs/GettingStartedVS.rst This snippet outlines the command-line steps to set up the LLVM development environment on Windows. It includes changing directories, registering DLLs, installing Python packages, and cloning the LLVM source code repository. ```bat c: cd \ regsvr32 "%VSINSTALLDIR%\DIA SDK\bin\msdia140.dll" regsvr32 "%VSINSTALLDIR%\DIA SDK\bin\amd64\msdia140.dll" pip install psutil git clone https://github.com/llvm/llvm-project.git llvm ``` -------------------------------- ### Clang Preprocessing Example Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/clang/www/get_started.html Shows how to use the Clang driver to preprocess a C source file, displaying the output after the preprocessing stage. ```C typedef float V __attribute__((vector_size(16))); V foo(V a, V b) { return a+b*a; } ``` ```Shell clang ~/t.c -E ``` -------------------------------- ### Native Assembly to Executable Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/llvm/docs/GettingStarted.rst Provides commands for assembling native assembly language files into executable programs, with platform-specific examples for Solaris and other systems. ```console # On Solaris % /opt/SUNWspro/bin/cc -xarch=v9 hello.s -o hello.native ``` ```console # On others % gcc hello.s -o hello.native ``` -------------------------------- ### Clang CMake Configuration Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/clang/www/get_started.html Example CMake command to configure the build for LLVM and Clang, specifying projects, build type, and generator. ```cmake cmake -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../llvm ``` -------------------------------- ### Example jscop export output Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/polly/docs/HowToManuallyUseTheIndividualPiecesOfPolly.rst Shows example output from the jscop export process, indicating which SCoPs were written to .jscop files. ```text [...]Writing JScop '%for.cond1.preheader---%for.end19' in function 'init_array' to './init_array___%for.cond1.preheader---%for.end19.jscop'. Writing JScop '%for.cond1.preheader---%for.end30' in function 'main' to './main___%for.cond1.preheader---%for.end30.jscop'. ``` -------------------------------- ### Compile with Polly Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/polly/www/get_started.html Compiles a C program using the Polly-enabled clang compiler. ```bash bin/clang -O3 -mllvm -polly hello.c ``` -------------------------------- ### MLIR Operation Constant Folder Example Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/mlir/docs/Tutorials/QuickstartRewrites.md Provides a C++ example of a constant folder method for an MLIR operation, demonstrating how to handle folding logic. ```c++ OpFoldResult SpecificOp::fold(ArrayRef constOperands) { if (unable_to_fold) return {}; .... return val; } ``` -------------------------------- ### Clone LLVM Project Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/polly/www/get_started.html Clones the LLVM project repository, which includes Polly. Supports both full and shallow clones. ```bash git clone https://github.com/llvm/llvm-project.git ``` ```bash git clone --depth 1 https://github.com/llvm/llvm-project.git ``` -------------------------------- ### Polly Analysis Output Example Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/polly/docs/HowToManuallyUseTheIndividualPiecesOfPolly.rst Example output from Polly's analysis, detailing the structure of a detected SCoP in the 'init_array' function, including loop depth and context. ```text [...]Printing analysis 'Polly - Create polyhedral description of Scops' for region: 'for.cond1.preheader => for.end19' in function 'init_array': Function: init_array Region: %for.cond1.preheader---%for.end19 Max Loop Depth: 2 Invariant Accesses: { } Context: { : } Assumed Context: { : } ``` -------------------------------- ### MLIR Python Bindings Development Setup Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/mlir/docs/Bindings/Python.md Steps to set up a Python virtual environment and install MLIR Python dependencies. ```Shell # Make sure your 'python' is what you expect. Note that on multi-python # systems, this may have a version suffix, and on many Linuxes and MacOS where # python2 and python3 co-exist, you may also want to use `python3`. which python python -m venv ~/.venv/mlirdev source ~/.venv/mlirdev/bin/activate # Note that many LTS distros will bundle a version of pip itself that is too # old to download all of the latest binaries for certain platforms. # The pip version can be obtained with `python -m pip --version`, and for # Linux specifically, this should be cross checked with minimum versions # here: https://github.com/pypa/manylinux # It is recommended to upgrade pip: python -m pip install --upgrade pip # Now the `python` command will resolve to your virtual environment and # packages will be installed there. python -m pip install -r mlir/python/requirements.txt # Now run `cmake`, `ninja`, et al. ``` -------------------------------- ### Build Example Directory Setup Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/libc/examples/README.md Steps to set up the build directory for an example program. This involves navigating to the example's directory, creating a 'build' subdirectory, and changing into it. ```bash cd mkdir build cd build ``` -------------------------------- ### Install flang and create version file Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/flang/docs/GettingStarted.md Commands to install the built flang components and create a version marker file in the installation directory. ```bash ninja install echo "latest" > $INSTALLDIR/bin/versionrc ``` -------------------------------- ### Clang Build and Run Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/clang/www/get_started.html Instructions for building and running Clang on Unix-like systems, including checking out the LLVM project, configuring with CMake, building, and testing. ```bash git clone https://github.com/llvm/llvm-project.git ``` ```bash git clone --depth=1 https://github.com/llvm/llvm-project.git ``` ```bash cd llvm-project git fetch --unshallow ``` ```bash cd llvm-project mkdir build cd build ``` ```bash cmake -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../llvm ``` ```bash make ``` ```bash make check-clang ``` ```bash clang --help ``` ```bash clang file.c -fsyntax-only ``` ```bash clang file.c -S -emit-llvm -o - ``` ```bash clang file.c -S -emit-llvm -o - -O3 ``` ```bash clang file.c -S -O3 -o - ``` -------------------------------- ### Install LLVM Dependencies with Chocolatey Source: https://github.com/rocm/rocmlir/blob/develop/external/llvm-project/llvm/docs/GettingStartedVS.rst Installs Git, CMake, and Python 3 using Chocolatey, and installs the psutil library using pip. ```bat choco install -y git cmake python3 pip3 install psutil ```