Skip to content

Commit

Permalink
Add support for LLVM 16 and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
lsk567 committed Nov 21, 2024
1 parent 7a67345 commit 44dec17
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 27 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ test/**/*gt/*
**/__pycache__
/Dockerfile*
env
build
build
**/*.bc
**/*.ll
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,40 @@ cd gametime
git submodule update --init --recursive
```

### 2. Install LLVM and Clang (Version 13)
### 2. Install LLVM and Clang (Version 16)

Gametime requires LLVM and Clang version 13. The installation instructions differ slightly between Linux and macOS:
Gametime requires LLVM and Clang version 16. The installation instructions differ slightly between Linux and macOS:

#### On Linux (Ubuntu/Debian):
Update your package manager and install LLVM and Clang version 13:

```bash
sudo apt update
sudo apt install clang-13 llvm-13
sudo apt install clang-16 llvm-16
```

Ensure that version 13 is used by setting it as the default:

```bash
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-13 100
sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-13 100
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 100
sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-16 100
```

#### On macOS:
First, ensure that Homebrew is installed, then install LLVM version 13 using the following commands:
First, ensure that Homebrew is installed, then install LLVM version 16 using the following commands:

```bash
brew install llvm@13
brew install llvm@16
```

After installation, update your `PATH` to include LLVM version 13:

```bash
export PATH="/usr/local/opt/llvm@13/bin:$PATH"
export PATH="/usr/local/opt/llvm@16/bin:$PATH"
```

### 3. Install Extra Dependencies and Local Modules

Install the required Python packages and additional system libraries:

```bash
pip install -e .
pip install -r requirements.txt
```

#### On Linux (Ubuntu/Debian):
Install additional system libraries:

Expand All @@ -71,6 +64,15 @@ Install the additional libraries via Homebrew:
brew install graphviz
```

#### Install Python dependencies:

Install the required Python packages and additional system libraries:

```bash
pip install -e .
pip install -r requirements.txt
```

If you are having trouble installing pygraphviz on macOS try the following: [StackOverflow](https://stackoverflow.com/questions/69970147/how-do-i-resolve-the-pygraphviz-error-on-mac-os)

### 4. Install KLEE
Expand All @@ -89,7 +91,7 @@ Each test requires a YAML configuration file. Ensure that your YAML file is corr

### 2. Create a Test Class

Navigate to the `wcet.py` file and create a new test class based on one of the available backend configurations. Specify the path to your YAML configuration file in the `config_path` attribute.
Navigate to the `wcet_test.py` file and create a new test class based on one of the available backend configurations. Specify the path to your YAML configuration file in the `config_path` attribute.

#### Example:

Expand All @@ -100,7 +102,7 @@ class TestBinarysearchARM(TestARMBackend):

### 3. Add the Test Class to the Main Function

In the `main` function of `wcet.py`, add your newly created test class to the suite for execution.
In the `main` function of `wcet_test.py`, add your newly created test class to the suite for execution.

#### Example:

Expand All @@ -113,7 +115,7 @@ suite.addTests(loader.loadTestsFromTestCase(TestBinarysearchARM))
Run the test using the following command:

```bash
python wcet.py
python wcet_test.py
```

---
Expand Down
2 changes: 2 additions & 0 deletions src/clang_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def inline_functions(bc_filepath: str, output_file_folder: str, output_name: str
output_file: str = os.path.join(output_file_folder, f"{output_name}.bc")

commands: List[str] = ["opt",
"-enable-new-pm=0",
"-always-inline",
"-inline", "-inline-threshold=10000000",
"-S", bc_filepath,
Expand Down Expand Up @@ -242,6 +243,7 @@ def unroll_loops(bc_filepath: str, output_file_folder: str, output_name: str, pr
output_file: str = os.path.join(output_file_folder, f"{output_name}.bc")

commands: List[str] = ["opt",
"-enable-new-pm=0",
# "-mem2reg",
"-simplifycfg",
"-loops",
Expand Down
2 changes: 1 addition & 1 deletion src/inliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def assemble_bitcode(input_file, output_file):
run_command(f"llvm-as {input_file} -o {output_file}")

def inline_bitcode(input_file, output_file):
run_command(f"opt -always-inline -inline -inline-threshold=10000000 {input_file} -o {output_file}")
run_command(f"opt -enable-new-pm=0 -always-inline -inline -inline-threshold=10000000 {input_file} -o {output_file}")

def generate_cfg(input_file):
run_command(f"opt -dot-cfg {input_file}")
Expand Down
1 change: 1 addition & 0 deletions src/smt_solver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
modify_bitcode
2 changes: 1 addition & 1 deletion src/unroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def unroll_llvm_ir(input_ir, output_ir):
"""
Generate LLVM Intermediate Representation (.ll file) from LLVM bitcode.
"""
command = f"opt -loop-unroll -S {input_ir} -o {output_ir}"
command = f"opt -enable-new-pm=0 -loop-unroll -S {input_ir} -o {output_ir}"
run_command(command, f"Generating LLVM IR from {input_ir}")


Expand Down
2 changes: 1 addition & 1 deletion test/tacle_test/programs/ext_func/ext_lib_test/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def assemble_bitcode(input_file, output_file):
run_command(f"llvm-as {input_file} -o {output_file}")

def inline_functions(input_file, output_file):
run_command(f"opt -always-inline -inline -inline-threshold=10000000 {input_file} -o {output_file}")
run_command(f"opt -enable-new-pm=0 -always-inline -inline -inline-threshold=10000000 {input_file} -o {output_file}")

def generate_cfg(input_file):
run_command(f"opt -dot-cfg {input_file}")
Expand Down
1 change: 0 additions & 1 deletion test/tacle_test/programs/if_elif_else/helper.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "helper.h"
#include <stdio.h>

int abs(int x) {
Expand Down
3 changes: 2 additions & 1 deletion test/tacle_test/programs/if_elif_else/if_elif_else.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include </Users/abdallaeltayeb/Desktop/Gamtime_project/gametime/test/tacle_test/programs/if_elif_else/helper.h>

int abs(int x);

// int test (int x) {
// // if (x < 0 && b < 0) {
Expand Down
2 changes: 1 addition & 1 deletion test/tacle_test/programs/loops/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def unroll_llvm_ir(input_ir, output_ir):
"""
Generate LLVM Intermediate Representation (.ll file) from LLVM bitcode.
"""
command = f"opt -loop-unroll -S {input_ir} -o {output_ir}"
command = f"opt -enable-new-pm=0 -loop-unroll -S {input_ir} -o {output_ir}"
run_command(command, f"Generating LLVM IR from {input_ir}")


Expand Down
4 changes: 2 additions & 2 deletions test/tacle_test/wcet_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ class TestCountNegativeARM(TestARMBackend):
# suite.addTests(loader.loadTestsFromTestCase(TestPrimeFlexpret))
# suite.addTests(loader.loadTestsFromTestCase(TestIfElifElseX86))
# suite.addTests(loader.loadTestsFromTestCase(TestBinarysearchARM))
# suite.addTests(loader.loadTestsFromTestCase(TestIfElifElseARM))
suite.addTests(loader.loadTestsFromTestCase(TestIfElifElseARM))
# suite.addTests(loader.loadTestsFromTestCase(TestPrimeARM))
suite.addTests(loader.loadTestsFromTestCase(TestCountNegativeARM))
# suite.addTests(loader.loadTestsFromTestCase(TestCountNegativeARM))

runner = unittest.TextTestRunner()
runner.run(suite)

0 comments on commit 44dec17

Please sign in to comment.