Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a59052d
Replace polygeist with llvm-project
Jiahui17 Nov 6, 2025
7d1ea23
Replace all changed calls to MLIR APIs
Jiahui17 Nov 6, 2025
fce6f40
CfToHandshake: DynamaticPass -> Pass
Jiahui17 Nov 7, 2025
1316452
WIP: fixing the inlining block
Jiahui17 Nov 7, 2025
a585fe3
fix handshake folder pattern
Jiahui17 Nov 10, 2025
0111b15
fix deprecated create statements
Jiahui17 Nov 10, 2025
1ba0c62
Fix calling replaceUsesWith1 multiple times
Jiahui17 Nov 20, 2025
78ce392
Handle a chain of GEPs in translate-llvm-to-std
Jiahui17 Nov 20, 2025
1279c07
suppress the no-verify-fixpoint warning
Jiahui17 Nov 21, 2025
c25a45d
flatten the MD array in llvm to std conversion
Jiahui17 Nov 21, 2025
963ad1b
Fix load and store to constant zero index
Jiahui17 Nov 21, 2025
aa123e7
disable unroll
Jiahui17 Nov 21, 2025
70c99f0
Also flatten the constant value attribute into 1d
Jiahui17 Nov 21, 2025
ed571c1
Implicit trunc when converting profiler input string into APInt
Jiahui17 Nov 21, 2025
6c70c4b
typo in the type conversion
Jiahui17 Nov 21, 2025
decb7a9
[StdProfiler] Handling signness and truncation when coverting to integer
Jiahui17 Nov 21, 2025
d906d4e
disable test_bitint test (waiting for a bugfix in llvm)
Jiahui17 Nov 21, 2025
32f7973
InstCombine is no longer strictly necessary
Jiahui17 Nov 21, 2025
52b5f2b
Copy comments from FlattenMemRefRowMajor to GEP conversion
Jiahui17 Nov 21, 2025
03a6dc6
Remove deprecated statements
Jiahui17 Nov 21, 2025
41f7eff
fix some compiler warnings
Jiahui17 Nov 22, 2025
99a9426
Revert "fix some compiler warnings"
Jiahui17 Nov 22, 2025
33fc551
No more lit test
Jiahui17 Nov 22, 2025
7b93116
Disable verbose debug output
Jiahui17 Nov 22, 2025
2ab4d43
Upload also the err message
Jiahui17 Nov 22, 2025
ead24a4
Fix reversed
Jiahui17 Nov 22, 2025
f4b41d4
Fix APInt cast of SExt's input
Jiahui17 Nov 27, 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
15 changes: 8 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ jobs:
- name: build
run: ./build.sh --release --force

- name: check-dynamatic
if: steps.build.outputs.exit_code == 0
run: ninja -C build check-dynamatic

- name: check-dynamatic-experimental
if: steps.build.outputs.exit_code == 0
run: ninja -C build check-dynamatic-experimental
# - name: check-dynamatic
# if: steps.build.outputs.exit_code == 0
# run: ninja -C build check-dynamatic
#
# - name: check-dynamatic-experimental
# if: steps.build.outputs.exit_code == 0
# run: ninja -C build check-dynamatic-experimental

- name: integration-test
if: steps.build.outputs.exit_code == 0
Expand Down Expand Up @@ -126,4 +126,5 @@ jobs:
integration-test/*/out*/comp
integration-test/*/out*/sim/report.txt
integration-test/*/out/dynamatic_out.txt
integration-test/*/out/dynamatic_err.txt

11 changes: 5 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[submodule "polygeist"]
path = polygeist
url = https://github.com/EPFL-LAP/Polygeist.git
branch = main
shallow = true

[submodule "visual-dataflow/godot-cpp"]
path = visual-dataflow/godot-cpp
url = https://github.com/godotengine/godot-cpp
Expand All @@ -12,3 +6,8 @@
[submodule "data/aig"]
path = data/aig
url = https://github.com/ETHZ-DYNAMO/dataflow-aig-library
[submodule "llvm-project"]
path = llvm-project
url = https://github.com/llvm/llvm-project.git
branch = main
shallow = true
81 changes: 27 additions & 54 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ print_help_and_exit () {

List of options:
--release | -r : build in \"Release\" mode (default is \"Debug\")
--skip-polygeist <polygeist-path> : skip building POLYGEIST
--skip-llvm <llvm-path> : skip building LLVM
--visual-dataflow | -v : build visual-dataflow's C++ library
--export-godot | -e <godot-path> : export the Godot project (requires engine)
--force | -f : force cmake reconfiguration in each (sub)project
Expand Down Expand Up @@ -126,7 +126,6 @@ run_ninja() {

CMAKE_COMPILERS="-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++"
CMAKE_LLVM_BUILD_OPTIMIZATIONS="-DLLVM_CCACHE_BUILD=ON -DLLVM_USE_LINKER=lld"
CMAKE_POLYGEIST_BUILD_OPTIMIZATIONS="-DPOLYGEIST_USE_LINKER=lld"
CMAKE_DYNAMATIC_BUILD_OPTIMIZATIONS="-DDYNAMATIC_CCACHE_BUILD=ON -DLLVM_USE_LINKER=lld"
CMAKE_DYNAMATIC_ENABLE_XLS=""
CMAKE_DYNAMATIC_ENABLE_LEQ_BINARIES=""
Expand All @@ -138,8 +137,8 @@ BUILD_TYPE="Debug"
BUILD_VISUAL_DATAFLOW=0
GODOT_PATH=""
ENABLE_XLS_INTEGRATION=0
SKIP_POLYGEIST=0
POLYGEIST_DIR="$PWD/polygeist"
SKIP_LLVM=0
LLVM_DIR="$PWD/llvm-project"

# Loop over command line arguments and update script variables
PARSE_ARG=""
Expand All @@ -156,8 +155,8 @@ do
GODOT_PATH="../$GODOT_PATH"
fi
PARSE_ARG=""
elif [[ $PARSE_ARG == "polygeist-path" ]]; then
POLYGEIST_DIR="$arg"
elif [[ $PARSE_ARG == "llvm-path" ]]; then
LLVM_DIR="$arg"
PARSE_ARG=""
elif [[ $PARSE_ARG == "llvm-parallel-link-jobs" ]]; then
LLVM_PARALLEL_LINK_JOBS="$arg"
Expand All @@ -167,7 +166,6 @@ do
"--disable-build-opt" | "-o")
CMAKE_COMPILERS=""
CMAKE_LLVM_BUILD_OPTIMIZATIONS=""
CMAKE_POLYGEIST_BUILD_OPTIMIZATIONS=""
CMAKE_DYNAMATIC_BUILD_OPTIMIZATIONS=""
;;
"--force" | "-f")
Expand All @@ -191,9 +189,9 @@ do
"--export-godot" | "-e")
PARSE_ARG="godot-path"
;;
"--skip-polygeist")
SKIP_POLYGEIST=1
PARSE_ARG="polygeist-path"
"--skip-llvm")
SKIP_LLVM=1
PARSE_ARG="llvm-path"
;;
"--experimental-enable-xls")
ENABLE_XLS_INTEGRATION=1
Expand Down Expand Up @@ -225,11 +223,11 @@ echo "##########################################################################
echo "############# DYNAMATIC - DHLS COMPILER INFRASTRUCTURE - EPFL/LAP ##############"
echo "################################################################################"

if [[ $SKIP_POLYGEIST -eq 0 ]]; then
if [[ $SKIP_LLVM -eq 0 ]]; then

#### Polygeist ####
#### LLVM ####

prepare_to_build_project "LLVM" "polygeist/llvm-project/build"
prepare_to_build_project "LLVM" "llvm-project/build"

# CMake
if should_run_cmake ; then
Expand All @@ -241,44 +239,21 @@ if [[ $SKIP_POLYGEIST -eq 0 ]]; then
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DLLVM_PARALLEL_LINK_JOBS=$LLVM_PARALLEL_LINK_JOBS \
$CMAKE_COMPILERS $CMAKE_LLVM_BUILD_OPTIMIZATIONS
exit_on_fail "Failed to cmake polygeist/llvm-project"
exit_on_fail "Failed to cmake llvm-project"
fi

# Build
run_ninja
exit_on_fail "Failed to build polygeist/llvm-project"
exit_on_fail "Failed to build llvm-project"
if [[ ENABLE_TESTS -eq 1 ]]; then
ninja check-mlir
exit_on_fail "Tests for polygeist/llvm-project failed"
fi

prepare_to_build_project "Polygeist" "polygeist/build"

# CMake
if should_run_cmake ; then
cmake -G Ninja .. \
-DMLIR_DIR=$PWD/../llvm-project/build/lib/cmake/mlir \
-DCLANG_DIR=$PWD/../llvm-project/build/lib/cmake/clang \
-DLLVM_TARGETS_TO_BUILD="host" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
$CMAKE_COMPILERS $CMAKE_POLYGEIST_BUILD_OPTIMIZATIONS
exit_on_fail "Failed to cmake polygeist"
fi

# Build
run_ninja
exit_on_fail "Failed to build polygeist"
if [[ ENABLE_TESTS -eq 1 ]]; then
ninja check-polygeist-opt
exit_on_fail "Tests for polygeist failed"
ninja check-cgeist
exit_on_fail "Tests for polygeist failed"
exit_on_fail "Tests for llvm-project failed"
fi

else
echo "Skipping POLYGEIST/LLVM build. IMPORTANT: Verify that the path of polygeist in the script tools/dynamatic/scripts/compile.sh is the same"
if [[ ! -d $POLYGEIST_DIR ]]; then
echo "POLYGEIST directory not found: $POLYGEIST_DIR"
echo "Skipping LLVM build. IMPORTANT: Verify that the path of llvm in the script tools/dynamatic/scripts/compile.sh is the same"
if [[ ! -d $LLVM_DIR ]]; then
echo "LLVM directory not found: $LLVM_DIR"
exit 1
fi
fi
Expand Down Expand Up @@ -336,10 +311,10 @@ prepare_to_build_project "Dynamatic" "build"
# CMake
if should_run_cmake ; then
cmake -G Ninja .. \
-DMLIR_DIR="$POLYGEIST_DIR"/llvm-project/build/lib/cmake/mlir \
-DLLVM_DIR="$POLYGEIST_DIR"/llvm-project/build/lib/cmake/llvm \
-DCLANG_DIR="$POLYGEIST_DIR"/llvm-project/build/lib/cmake/clang \
-DPolly_DIR="$POLYGEIST_DIR"/llvm-project/build/tools/polly/lib/cmake/polly \
-DMLIR_DIR="$LLVM_DIR/build/lib/cmake/mlir" \
-DLLVM_DIR="$LLVM_DIR/build/lib/cmake/llvm" \
-DCLANG_DIR="$LLVM_DIR/build/lib/cmake/clang" \
-DPolly_DIR="$LLVM_DIR/build/tools/polly/lib/cmake/polly" \
-DLLVM_TARGETS_TO_BUILD="host" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_EXPORT_COMPILE_COMMANDS="ON" \
Expand Down Expand Up @@ -374,8 +349,8 @@ if [[ BUILD_VISUAL_DATAFLOW -ne 0 ]]; then
# CMake
if should_run_cmake ; then
cmake -G Ninja .. \
-DMLIR_DIR="$POLYGEIST_DIR"/llvm-project/build/lib/cmake/mlir \
-DLLVM_DIR="$POLYGEIST_DIR"/llvm-project/build/lib/cmake/llvm \
-DMLIR_DIR="$LLVM_DIR/llvm-project/build/lib/cmake/mlir" \
-DLLVM_DIR="$LLVM_DIR/llvm-project/build/lib/cmake/llvm" \
-DLLVM_TARGETS_TO_BUILD="host" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_EXPORT_COMPILE_COMMANDS="ON" \
Expand Down Expand Up @@ -411,11 +386,9 @@ cd "$SCRIPT_CWD" && mkdir -p bin/generators

# Create symbolic links to all binaries we use from subfolders

create_symlink "$POLYGEIST_DIR"/build/bin/cgeist
create_symlink "$POLYGEIST_DIR"/build/bin/polygeist-opt
create_symlink "$POLYGEIST_DIR"/llvm-project/build/bin/clang++
create_symlink "$POLYGEIST_DIR"/llvm-project/build/bin/opt
create_symlink "$POLYGEIST_DIR"/llvm-project/build/bin/clang
create_symlink "$LLVM_DIR/build/bin/opt"
create_symlink "$LLVM_DIR/build/bin/clang++"
create_symlink "$LLVM_DIR/build/bin/clang"
create_symlink ../build/bin/dynamatic
create_symlink ../build/bin/dynamatic-mlir-lsp-server
create_symlink ../build/bin/dynamatic-opt
Expand All @@ -435,7 +408,7 @@ create_generator_symlink build/bin/exp-sharing-wrapper-generator
create_generator_symlink "$LSQ_GEN_PATH/$LSQ_GEN_JAR"

# Create symbolic links to polygeist headers (standard c library for clang)
create_include_symlink "$POLYGEIST_DIR"/llvm-project/clang/lib/Headers
create_include_symlink "$LLVM_DIR/clang/lib/Headers"


if [[ $GODOT_PATH != "" ]]; then
Expand Down
10 changes: 3 additions & 7 deletions docs/DeveloperGuide/CompilerIntrinsics/Frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The output of Dynamatic's C frontend is an MLIR IR written in standard MLIR dial

Notable optimizations that we need from the LLVM project:
- `mem2reg`: Suppressing allocas (allocate memory on the heap) into regs.
- `instcombine`: Performing local DAG-to-DAG rewriting. Notably, this canonicalizes a chain of `getelementptr` instructions (GEPs).
- `instcombine`: Performing local DAG-to-DAG rewriting.
- `loop-rotate`: Transforming loops to do-while loops as much as possible.
- `simplifycfg`, `loopsimplify`: reducing the number of BBs (fewer branches).
- `consthoist`: Moving constants around.
Expand All @@ -55,7 +55,7 @@ The translation between LLVM IR and the standard dialects (especially the subset
> - LLVM uses void ptrs for array inputs (both for fixed-size arrays `int arr[10][20]` and arrays with unbounded length `int * arr`). While in standard dialect, we use MemRef types `memref<10 * 20 * i32>` for referencing an array.
> - LLVM does not represent constants as operations, while in MILR, constants must be "materialized" as explicit constant operations.
> - LLVM has explicit SSA Phi nodes. MLIR replaces the Phis by block arguments.
> - The MemRef dialect does not have a special GEP operation for the array index calculation (e.g., `a[0][1]`); instead, it has a high-level syntax like `%result = memref.load [%memrefValue] %dim0, %dim1`. Therefore, GEPs are replaced by a direct connection between indices to the loads/stores.
> - The MemRef dialect does not have a special GEP operation for the array index calculation (e.g., `a[0][1]`); instead, it has a high-level syntax like `%result = memref.load [%memrefValue] %dim0, %dim1`. We directly flatten the arrays into 1D and replace GEPs with multiplications and additions.
> - In LLVM, global values can be referenced by GEPs, but in MLIR MemRef dialect, global values can only be referenced via `get_global` op via the `sym_name` symbol attached to the global op.

### Type Conversion for Function Arguments
Expand All @@ -80,15 +80,11 @@ For each LLVM function, Dynamatic performs the following translation:
1. **Constant materialization**. Create a corresponding `arith::ConstantOp` for each constant input of each `llvm::Instruction *` in LLVM IR.
2. **Block conversion**. Create an MLIR block for every basic block in LLVM. Remember the BB mappings (see the list above). For every Phi output in LLVM, it creates the corresponding block argument in MLIR (for each array function argument, the original C code is used to recover the correct MemRef type). Remember the value mappings (see the list above).
3. **Global conversion**. Create a MemRef global operation for each global variable in LLVM.
4. **Instruction translation**. Create an operation in MLIR for each LLVM operation from the input values (retrieved from the value mapping). Exception: GEP are removed and the indices are directly connected to the loads and stores.
4. **Instruction translation**. Create an operation in MLIR for each LLVM operation from the input values (retrieved from the value mapping).

> [!NOTE]
> The syntax of the GEP instruction in LLVM is often simplified/shortened. This requires a sophisticated conversion rule for GEP. Check out the LLVM documentation on [caveats of GEP syntax](https://llvm.org/docs/GetElementPtr.html) for more details.

> [!IMPORTANT]
> The `instcombine` pass must be applied before the conversion to eliminate a
> chain of GEPs.

## Memory Dependency Analysis

TODO
17 changes: 9 additions & 8 deletions experimental/include/experimental/Conversion/FtdCfToHandshake.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
#include "dynamatic/Support/LLVM.h"
#include "experimental/Analysis/GSAAnalysis.h"

namespace dynamatic {
namespace experimental {
#define GEN_PASS_DECL_FTDCFTOHANDSHAKE
#include "experimental/Conversion/Passes.h.inc"
} // namespace experimental
} // namespace dynamatic

namespace dynamatic {
namespace experimental {
namespace ftd {
Expand All @@ -35,14 +42,14 @@ class FtdLowerFuncToHandshake : public LowerFuncToHandshake {
NameAnalysis &namer, MLIRContext *ctx,
mlir::PatternBenefit benefit = 1)
: LowerFuncToHandshake(namer, ctx, benefit), cdAnalysis(cda),
gsaAnalysis(gsa){};
gsaAnalysis(gsa) {};

FtdLowerFuncToHandshake(ControlDependenceAnalysis &cda, gsa::GSAAnalysis &gsa,
NameAnalysis &namer,
const TypeConverter &typeConverter, MLIRContext *ctx,
mlir::PatternBenefit benefit = 1)
: LowerFuncToHandshake(namer, typeConverter, ctx, benefit),
cdAnalysis(cda), gsaAnalysis(gsa){};
cdAnalysis(cda), gsaAnalysis(gsa) {};

LogicalResult
matchAndRewrite(mlir::func::FuncOp funcOp, OpAdaptor adaptor,
Expand Down Expand Up @@ -85,12 +92,6 @@ struct FtdConvertIndexCast : public ConvertIndexCast<CastOp, ExtOp> {
ConversionPatternRewriter &rewriter) const override;
};

#define GEN_PASS_DECL_FTDCFTOHANDSHAKE
#define GEN_PASS_DEF_FTDCFTOHANDSHAKE
#include "experimental/Conversion/Passes.h.inc"

std::unique_ptr<dynamatic::DynamaticPass> createFtdCfToHandshake();

} // namespace ftd
} // namespace experimental
} // namespace dynamatic
Expand Down
3 changes: 1 addition & 2 deletions experimental/include/experimental/Conversion/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ include "dynamatic/Support/Passes.td"
// FtdCfToHandshake
//===----------------------------------------------------------------------===//

def FtdCfToHandshake : DynamaticPass<"ftd-lower-cf-to-handshake"> {
def FtdCfToHandshake : Pass<"ftd-lower-cf-to-handshake"> {
let summary = "Lowers func and cf dialects to handshake with fast token delivery";
let description = [{
The fast token delivery (FTD) methodology was described by
Expand All @@ -33,7 +33,6 @@ def FtdCfToHandshake : DynamaticPass<"ftd-lower-cf-to-handshake"> {
As the algorithm does not require any parameter, no input is necessary. This pass can
be used through the flag "--fast-token-delivery" at compile tile in dynamatic.
}];
let constructor = "dynamatic::experimental::ftd::createFtdCfToHandshake()";
}

#endif // EXPERIMENTAL_CONVERSION_PASSES_TD
Expand Down
1 change: 1 addition & 0 deletions experimental/include/experimental/Support/CFGAnnotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "dynamatic/Analysis/NameAnalysis.h"
#include "dynamatic/Dialect/Handshake/HandshakeOps.h"
#include <variant>

namespace dynamatic {
namespace experimental {
Expand Down
Loading
Loading