Skip to content

Created infrastructure for compiler course #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 48 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
1e18b62
ci
Kuznetsov-Artyom Dec 27, 2024
47e8294
example ClangAST
Kuznetsov-Artyom Dec 27, 2024
9dae910
change test
Kuznetsov-Artyom Dec 28, 2024
9954db9
example LLVM-IR
Kuznetsov-Artyom Dec 28, 2024
f532d02
change CMakeLists.txt
Kuznetsov-Artyom Dec 28, 2024
66ec2c4
update ci
Kuznetsov-Artyom Dec 28, 2024
412da49
update ci
Kuznetsov-Artyom Dec 28, 2024
84f99c1
add mold linker for Linux / MacOS
Kuznetsov-Artyom Dec 28, 2024
e07485b
add upload artifacts and add scenario llvm_enable_assertions=off
Kuznetsov-Artyom Dec 28, 2024
6941e24
try artifacts
Kuznetsov-Artyom Dec 28, 2024
ac697e2
try enable artifacts
Kuznetsov-Artyom Dec 28, 2024
d66a4a2
add clang-tidy
Kuznetsov-Artyom Dec 29, 2024
197063f
update ci
Kuznetsov-Artyom Dec 29, 2024
37eca29
check ci
Kuznetsov-Artyom Dec 29, 2024
dbb72ce
upd ci
Kuznetsov-Artyom Dec 29, 2024
14dc3b2
upd
Kuznetsov-Artyom Dec 29, 2024
07d0ceb
change target build for macOS
Kuznetsov-Artyom Dec 29, 2024
fcea7a5
upd ci build
Kuznetsov-Artyom Dec 29, 2024
3ff08d1
upd ci
Kuznetsov-Artyom Dec 29, 2024
dced4fb
change check tests
Kuznetsov-Artyom Dec 29, 2024
ef3d405
fix yml build
Kuznetsov-Artyom Dec 29, 2024
8c7f1d7
check ci
Kuznetsov-Artyom Dec 29, 2024
1d87a8a
check ci
Kuznetsov-Artyom Dec 29, 2024
290f5fa
change version python
Kuznetsov-Artyom Dec 29, 2024
edc949a
remove unused cmake flags
Kuznetsov-Artyom Dec 29, 2024
85a7bea
upd
Kuznetsov-Artyom Dec 29, 2024
96aae3e
upd
Kuznetsov-Artyom Dec 29, 2024
81d70b9
fix parallel build
Kuznetsov-Artyom Dec 29, 2024
3164020
fix windows
Kuznetsov-Artyom Dec 29, 2024
85573d2
success fix
Kuznetsov-Artyom Dec 29, 2024
351889d
Update example.cpp for ClangAST lab
Kuznetsov-Artyom Dec 29, 2024
e5a237a
add lab mlir
Kuznetsov-Artyom Dec 30, 2024
619ebf3
add mangling for targets
Kuznetsov-Artyom Dec 30, 2024
f534549
add mlir build in CI
Kuznetsov-Artyom Dec 30, 2024
04d8f64
style
Kuznetsov-Artyom Dec 30, 2024
3fc3be9
add backend lab
Kuznetsov-Artyom Jan 1, 2025
c89846c
disable windows
Kuznetsov-Artyom Jan 1, 2025
bf6a7f9
change README.md
Kuznetsov-Artyom Jan 2, 2025
bc56c66
update CI
Kuznetsov-Artyom Jan 2, 2025
d2ded1e
fix CI
Kuznetsov-Artyom Jan 2, 2025
32f7994
test migrate backend lab from X86 directory
Kuznetsov-Artyom Jan 2, 2025
aff3174
remove backend lab from x86 dir
Kuznetsov-Artyom Jan 2, 2025
5764c1c
pre-review
Kuznetsov-Artyom Jan 3, 2025
d532380
add instruction for implementation labs
Kuznetsov-Artyom Jan 15, 2025
b53c76a
add links
Kuznetsov-Artyom Jan 15, 2025
01702fe
add labeler bot
Kuznetsov-Artyom Feb 7, 2025
0c1b956
delete unnecessary target
Kuznetsov-Artyom Feb 7, 2025
866697b
update
Kuznetsov-Artyom Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'lab:clang':
- "clang/compiler-course/**"
'lab:llvm ir':
- "llvm/compiler-course/llvm-ir/**"
'lab:backend':
- "llvm/compiler-course/backend/**"
'lab:mlir':
- "mlir/compiler-course/**"

tests:
- "clang/test/compiler-course/**"
- "llvm/test/compiler-course/**"
- "mlir/test/compiler-course/**"

ci:
- ".github/**"
117 changes: 117 additions & 0 deletions .github/workflows/compiler-course-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Build LLVM
on: [push, pull_request]

jobs:
ubuntu-gcc-build:
runs-on: ubuntu-latest
strategy:
matrix:
assertions: [ON, OFF]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup environment
run: |
sudo apt-get install -y \
build-essential \
ninja-build \
- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
max-size: 500M
key: ccache-${{ github.job }}
- name: Build
run: |
cmake -S llvm -B build \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;mlir" \
-DLLVM_ENABLE_ASSERTIONS=${{ matrix.assertions }} \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DLLVM_TARGETS_TO_BUILD="X86;AArch64" \
-G Ninja
cmake --build build --config Release -j $(nproc)
- name: Test
run: |
cmake --build build --config Release -t \
check-llvm-compiler-course \
check-clang-compiler-course \
check-mlir-compiler-course -j $(nproc)
macos-build:
runs-on: macOS-latest
strategy:
matrix:
assertions: [ON, OFF]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup environment
run: |
brew install \
ninja
- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
max-size: 500M
key: ccache-${{ github.job }}
- name: Build
run: |
cmake -S llvm -B build \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;mlir" \
-DLLVM_ENABLE_ASSERTIONS=${{ matrix.assertions }} \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DLLVM_TARGETS_TO_BUILD="X86;AArch64" \
-G Ninja
cmake --build build --config Release -j $(nproc)
- name: Test
run: |
cmake --build build --config Release -t \
check-llvm-compiler-course \
check-clang-compiler-course \
check-mlir-compiler-course -j $(nproc)
windows-build:
runs-on: windows-latest
strategy:
matrix:
assertions: [ON, OFF]
steps:
- name: Setup Windows
uses: llvm/actions/setup-windows@main
with:
arch: amd64
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python_version }}
- name: Install Ninja
uses: llvm/actions/install-ninja@main
- uses: actions/checkout@v4
with:
fetch-depth: 250
- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1
with:
max-size: 2G
variant: sccache
- name: Build
shell: bash
id: build-llvm
run: |
builddir="$(pwd)"/build
echo "llvm-builddir=$builddir" >> "$GITHUB_OUTPUT"
cmake -G Ninja \
-B "$builddir" \
-S llvm \
-DLLVM_ENABLE_PROJECTS="clang" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=${{ matrix.assertions }} \
-DLLDB_INCLUDE_TESTS=OFF \
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
-DLLVM_TARGETS_TO_BUILD="X86;AArch64" \
${{ inputs.extra_cmake_args }}
ninja -C "$builddir" all
43 changes: 43 additions & 0 deletions .github/workflows/compiler-course-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Static analysis
on: [pull_request]

jobs:
clang-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install clang-format
run: |
sudo apt-get install -y clang-format
- name: Run clang-format
run: |
git-clang-format --diff `git merge-base ${GITHUB_SHA} ${GITHUB_BASE_REF}`
clang-tidy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Update submodules
run: git submodule update --init --recursive
- name: ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ github.job }}
- uses: ZedThree/[email protected]
id: review
with:
build_dir: build
cmake_command: cmake -S llvm -B build
-DCMAKE_BUILD_TYPE=Release
-DLLVM_ENABLE_PROJECTS='clang;mlir'
-DLLVM_ENABLE_ASSERTIONS=ON
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-G Ninja
config_file: .clang-tidy
apt_packages: build-essential,ninja-build
split_workflow: true
env:
CC: clang-16
CXX: clang++-16
18 changes: 18 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Label bot"
on: [pull_request]

jobs:
label-bot:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Check out repository
uses: actions/[email protected]
- name: Add labels
uses: actions/labeler@v4
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: ".github/labeler.yml"
dot: true
130 changes: 108 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# The LLVM Compiler Infrastructure
# Compiler course 2025

[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/llvm/llvm-project/badge)](https://securityscorecards.dev/viewer/?uri=github.com/llvm/llvm-project)
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8273/badge)](https://www.bestpractices.dev/projects/8273)
[![libc++](https://github.com/llvm/llvm-project/actions/workflows/libcxx-build-and-test.yaml/badge.svg?branch=main&event=schedule)](https://github.com/llvm/llvm-project/actions/workflows/libcxx-build-and-test.yaml?query=event%3Aschedule)

Welcome to the LLVM project!
# What is LLVM?
LLLVM is a set of compiler and toolchain technologies that can be used to develop a frontend for any programming language and a backend for any instruction set architecture. LLVM is designed around a language-independent intermediate representation (IR) that serves as a portable, high-level assembly language that can be optimized with a variety of transformations over multiple passes. The name LLVM originally stood for Low Level Virtual Machine, though the project has expanded and the name is no longer officially an initialism.

This repository contains the source code for LLVM, a toolkit for the
construction of highly optimized compilers, optimizers, and run-time
Expand All @@ -16,29 +17,114 @@ 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](https://clang.llvm.org/) frontend. This
component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode
-- and from there into object files, using LLVM.
# 0. Intro
This course will consist of 4 laboratory work. As part of the laboratory works, you will study all stages of compilation, starting with the generation of the AST tree, ending with code generation.

Other components include:
the [libc++ C++ standard library](https://libcxx.llvm.org),
the [LLD linker](https://lld.llvm.org), and more.
## Note
Recommended OS - Linux (WSL).

## Getting the Source Code and Building LLVM
# 1. Clone repository
1. Create fork this repository
2. Clone local fork
```bash
git clone https://github.com/<your-github-name>/llvm.git
cd llvm/
git checkout -b <name-your-branch>
```

Consult the
[Getting Started with LLVM](https://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm)
page for information on building and running LLVM.
# 2. Setup environment
```bash
sudo apt-get update \
&& sudo apt-get install -q -y --no-install-recommends \
git \
cmake \
ccache \
mold \
clang \
build-essential \
ninja-build \
python3 \
python3-pip \
wget \
vim
```

For information on how to contribute to the LLVM project, please take a look at
the [Contributing to LLVM](https://llvm.org/docs/Contributing.html) guide.
# 3. Build project
```bash
cmake -G Ninja -S llvm -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang \
-DLLVM_USE_LINKER=mold \
-DLLVM_CCACHE_BUILD=ON \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_ENABLE_PROJECTS="clang;mlir" \
-DLLVM_TARGETS_TO_BUILD=X86 # specify your target architecture (X86, Aarch64)
cmake --build build --config Release -j 4
```
# 4. Where to implement laboratory work?
Each directory has an implementation example.

## Getting in touch
## ClangAST lab
```bash
cd clang/compiler-course/ # for labs
```
```bash
cd clang/test/compiler-course/ # for tests
```
## LLVM IR lab
```bash
cd llvm/compiler-course/llvm-ir/ # for labs
```
```bash
cd llvm/test/compiler-course/ # for tests
```
## Backend lab
```bash
cd llvm/compiler-course/backend/ # for labs
```
```bash
cd llvm/test/compiler-course/ # for tests
```
## MLIR lab
```bash MLIR
cd mlir/compiler-course/ # for labs
```
```bash MLIR
cd mlir/test/compiler-course/ # for tests
```
# 5. Run tests
For all tests
```bash
cmake --build build --config Release -t \
check-llvm-compiler-course \
check-clang-compiler-course \
check-mlir-compiler-course -j 4
```
For one test
```bash
./build/bin/llvm-lit -v /path/to/test_file
```
# 6. Resources
- [Telegram сhat][chat]
- [Telegram сhannel][channel]
- [Tasks and results][results]
- Materials
- [Lectures][lecture]
- [LLVM][llvm]
- [MLIR][mlir]
- [Clang][clang]
- [Official YouTube channel LLVM][youtube_llvm]

Join the [LLVM Discourse forums](https://discourse.llvm.org/), [Discord
chat](https://discord.gg/xS7Z362),
[LLVM Office Hours](https://llvm.org/docs/GettingInvolved.html#office-hours) or
[Regular sync-ups](https://llvm.org/docs/GettingInvolved.html#online-sync-ups).

The LLVM project has adopted a [code of conduct](https://llvm.org/docs/CodeOfConduct.html) for
participants to all modes of communication within the project.
<!-- LINKS -->
<!-- Tasks and results -->
[results]: https://docs.google.com/spreadsheets/d/1LiZ5FMd5t61yoGdnpANTFpzqtKD_ejtvLl1cHKZxvXQ/edit?usp=sharing
<!-- Contacts -->
[channel]: https://t.me/+TPntKPD8z0E3OWJi
[chat]: https://t.me/+JG3n1jeSAiIxZjMy
<!-- Materials -->
[lecture]: https://github.com/NN-complr-tech/Complr-course-lectures
[llvm]: https://llvm.org/
[mlir]: https://mlir.llvm.org/
[clang]: https://clang.llvm.org/
[youtube_llvm]: https://www.youtube.com/@LLVMPROJ
5 changes: 5 additions & 0 deletions clang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -940,3 +940,8 @@ set(CLANG_INSTALL_LIBDIR_BASENAME "lib${CLANG_LIBDIR_SUFFIX}")
configure_file(
${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
${CLANG_BINARY_DIR}/include/clang/Config/config.h)

# BEGIN COMPILER COURSE
include(${LLVM_COMMON_CMAKE_UTILS}/Modules/UtilsCompilerCourse.cmake)
add_subdirectory(compiler-course)
# END COMPILER COURSE
5 changes: 5 additions & 0 deletions clang/compiler-course/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (CLANG_PLUGIN_SUPPORT)
list_subdirs(subdirs ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirs(subdirs "COMPILER COURSE (ClangAST)")
set(CLANG_TEST_DEPS ${CLANG_TEST_DEPS} PARENT_SCOPE)
endif()
18 changes: 18 additions & 0 deletions clang/compiler-course/example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(Title "ExamplePlugin")
set(Student "Ivanov_Ivan")
set(Group "FIIT0")
set(TARGET_NAME "${Title}_${Student}_${Group}_ClangAST")

file(GLOB_RECURSE SOURCES *.cpp *.h *.hpp)
add_llvm_library(${TARGET_NAME} MODULE ${SOURCES} PLUGIN_TOOL clang)

if(WIN32 OR CYGWIN)
set(LLVM_LINK_COMPONENTS Support)
clang_target_link_libraries(${TARGET_NAME} PRIVATE
clangAST
clangBasic
clangFrontend
)
endif()

set(CLANG_TEST_DEPS "${TARGET_NAME}" ${CLANG_TEST_DEPS} PARENT_SCOPE)
Loading
Loading