https://github.com/auyxs/llvm-optimizations
UNIMORE Compilers Course 2024/25 - collection of assignments
https://github.com/auyxs/llvm-optimizations
compilers llvm llvm-ir
Last synced: about 2 months ago
JSON representation
UNIMORE Compilers Course 2024/25 - collection of assignments
- Host: GitHub
- URL: https://github.com/auyxs/llvm-optimizations
- Owner: Auyxs
- License: mit
- Created: 2025-03-24T22:25:35.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-26T23:57:30.000Z (about 1 year ago)
- Last Synced: 2025-03-27T00:29:19.254Z (about 1 year ago)
- Topics: compilers, llvm, llvm-ir
- Language: C++
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LLVM Optimization Passes
[](https://llvm.org/)

Repository containing Compilers Course assignments at **Unimore (2024/2025)** - Implementation of **LLVM IR** optimization passes as plugins.
## 📂 First Assignment
1. **Algebraic Identity**
- `x + 0` → `x`
- `1 × 𝑥` → `x`
2. **Strength Reduction**
- `15 × 𝑥 = 𝑥 × 15` → `(𝑥 ≪ 4) – x`
- `y = x / 8` → `y = x >> 3`
3. **Multi-Instruction Optimization**
- `𝑎 = 𝑏 + 1, 𝑐 = 𝑎 − 1` → `𝑎 = 𝑏 + 1, 𝑐 = b`
### Usage
#### 🔧 Build
To build the LLVM plugin, follow these steps:
```bash
mkdir -p build
cd build
cmake -DLT_LLVM_INSTALL_DIR=$LLVM_DIR /path/to/assignment-01
make
```
The plugin (`libLocalOpts.so`) will be generated in the build directory.
> Note : Ensure that $LLVM_DIR is correctly set to your LLVM installation path.
> (e.g., /usr/lib/llvm-19/bin on Linux)
#### ▶️ Run Optimization Pass
Once the plugin is built, you can run the optimization script to test the implemented passes:
1. Place your `.cpp` test files in the `test/cpp` directory.
2. Before running the script, set the `OPT_PLUGIN_PATH` environment variable:
```bash
export OPT_PLUGIN_PATH=/path/to/libLocalOpts.so
```
3. Make the script executable and run it:
```bash
chmod +x run_opt.sh
./run_opt.sh
```
## 📂 Second Assignment - Dataflow Analysis
> Note: no code implementation required
1. **Very Busy Expressions**
2. **Dominator Analysis**
3. **Constant Propagation**
## Contributors
- Aurora Lin
- Eleonora Muzzi