Skip to content

Commit e029aaa

Browse files
authored
Make playground a separate CMake project (#4)
1 parent 473f913 commit e029aaa

26 files changed

Lines changed: 255 additions & 187 deletions

.github/workflows/ci.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,18 @@ jobs:
1919
source /root/emsdk/emsdk_env.sh
2020
npm --workspace=codemirror-lang-graphalg install
2121
npm --workspace=codemirror-lang-graphalg run prepare
22-
- name: Build compiler (native)
22+
- name: Build compiler
2323
shell: bash
2424
run: |
2525
./compiler/configure.sh
2626
cmake --build ./compiler/build
2727
cmake --build ./compiler/build --target check
28-
- name: Build compiler (wasm)
29-
shell: bash
30-
run: |
31-
source /root/emsdk/emsdk_env.sh
32-
./compiler/configure-wasm.sh
33-
cmake --build ./compiler/build-wasm
3428
- name: Build playground
3529
shell: bash
3630
run: |
3731
source /root/emsdk/emsdk_env.sh
32+
playground/cpp/configure-wasm.sh
33+
cmake --build playground/cpp/build-wasm --target graphalg-playground
3834
npm --workspace=playground install
3935
npm --workspace=playground run prepare
4036
- name: Build website

.github/workflows/pages.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,12 @@ jobs:
4040
source /root/emsdk/emsdk_env.sh
4141
npm --workspace=codemirror-lang-graphalg install
4242
npm --workspace=codemirror-lang-graphalg run prepare
43-
- name: Build compiler (wasm)
44-
shell: bash
45-
run: |
46-
source /root/emsdk/emsdk_env.sh
47-
./compiler/configure-wasm.sh
48-
cmake --build ./compiler/build-wasm
4943
- name: Build playground
5044
shell: bash
5145
run: |
5246
source /root/emsdk/emsdk_env.sh
47+
playground/cpp/configure-wasm.sh
48+
cmake --build playground/cpp/build-wasm --target graphalg-playground
5349
npm --workspace=playground install
5450
npm --workspace=playground run prepare
5551

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"mlir.tablegen_compilation_databases": [
3-
"compiler/build/tablegen_compile_commands.yml"
3+
"compiler/build/tablegen_compile_commands.yml",
44
],
5-
"mlir.server_path": "/workspaces/graphalg/compiler/build/graphalg-lsp-server",
5+
"mlir.server_path": "/workspaces/graphalg/compiler/build/tools/graphalg-lsp-server",
66
}

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ npm --workspace=codemirror-lang-graphalg run prepare
1616
cmake --build ./compiler/build
1717
cmake --build ./compiler/build --target check
1818

19-
./compiler/configure-wasm.sh
20-
cmake --build ./compiler/build-wasm
21-
2219
npm --workspace=playground install
20+
playground/cpp/configure-wasm.sh
21+
cmake --build playground/cpp/build-wasm --target graphalg-playground
2322
# Or npm --workspace=playground run watch to rebuild automatically upon edit.
2423
npm --workspace=playground run prepare
2524

compiler/CMakeLists.txt

Lines changed: 4 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ option(ENABLE_WASM "Enable wasm-only targets" OFF)
1818
# ================================= BEGIN LLVM =================================
1919

2020
find_package(LLVM REQUIRED CONFIG)
21-
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
22-
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
2321
include_directories(${LLVM_INCLUDE_DIRS})
2422
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
2523
add_definitions(${LLVM_DEFINITIONS_LIST})
@@ -41,8 +39,8 @@ list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
4139

4240
# Using a placeholder to set MLIR_TABLEGEN_EXE because find_package(MLIR)
4341
# overwrites the MLIR_TABLEGEN_EXE flag
44-
if(DEFINED SET_MLIR_TABLEGEN_PATH)
45-
set(MLIR_TABLEGEN_EXE "${SET_MLIR_TABLEGEN_PATH}")
42+
if(DEFINED GRAPHALG_OVERRIDE_MLIR_TABLEGEN_PATH)
43+
set(MLIR_TABLEGEN_EXE "${GRAPHALG_OVERRIDE_MLIR_TABLEGEN_PATH}")
4644
endif()
4745

4846
include(AddMLIR)
@@ -51,132 +49,6 @@ include(AddMLIR)
5149
# Directories with MLIR dialects
5250
add_subdirectory(include/graphalg)
5351

52+
add_subdirectory(src)
5453
add_subdirectory(test)
55-
56-
# graphalg_lib
57-
add_library(graphalg_lib STATIC
58-
src/graphalg/analysis/DenseAnalysis.cpp
59-
src/graphalg/GraphAlgAttr.cpp
60-
src/graphalg/GraphAlgAttr.cpp
61-
src/graphalg/GraphAlgCanonicalize.cpp
62-
src/graphalg/GraphAlgCast.cpp
63-
src/graphalg/GraphAlgDialect.cpp
64-
src/graphalg/GraphAlgExplicateSparsity.cpp
65-
src/graphalg/GraphAlgInterfaces.cpp
66-
src/graphalg/GraphAlgLoopAggregate.cpp
67-
src/graphalg/GraphAlgOps.cpp
68-
src/graphalg/GraphAlgPrepareInlinePass.cpp
69-
src/graphalg/GraphAlgScalarizeApply.cpp
70-
src/graphalg/GraphAlgSetDimensions.cpp
71-
src/graphalg/GraphAlgSplitAggregate.cpp
72-
src/graphalg/GraphAlgToCore.cpp
73-
src/graphalg/GraphAlgToCorePipeline.cpp
74-
src/graphalg/GraphAlgTypes.cpp
75-
src/graphalg/GraphAlgVerifyDimensions.cpp
76-
src/graphalg/SemiringTypes.cpp
77-
src/graphalg/evaluate/Evaluator.cpp
78-
)
79-
target_include_directories(graphalg_lib PUBLIC include)
80-
target_include_directories(graphalg_lib SYSTEM PUBLIC ${PROJECT_BINARY_DIR}/include)
81-
add_dependencies(graphalg_lib
82-
MLIRGraphAlgOpsIncGen
83-
MLIRGraphAlgPassesIncGen
84-
MLIRGraphAlgInterfacesIncGen
85-
)
86-
target_link_libraries(
87-
graphalg_lib
88-
PRIVATE
89-
MLIRAnalysis
90-
MLIRFuncDialect
91-
MLIRFuncInlinerExtension
92-
MLIRInferTypeOpInterface
93-
MLIRIR
94-
MLIRPass
95-
MLIRPass
96-
MLIRSupport
97-
MLIRTransforms
98-
)
99-
# Suppress -Wdangling-assignment-gsl for generated code from MLIR tablegen
100-
# The warning is triggered by template instantiations in GraphAlgOps.cpp.inc
101-
target_compile_options(graphalg_lib PRIVATE -Wno-dangling-assignment-gsl)
102-
if(NOT GRAPHALG_ENABLE_RTTI)
103-
target_compile_options(graphalg_lib PUBLIC -fno-rtti)
104-
endif()
105-
106-
add_library(graphalg_parse STATIC
107-
src/graphalg/parse/Lexer.cpp
108-
src/graphalg/parse/Parser.cpp
109-
)
110-
target_link_libraries(graphalg_parse PRIVATE graphalg_lib)
111-
112-
add_executable(graphalg-translate src/graphalg-translate.cpp)
113-
target_link_libraries(graphalg-translate PRIVATE
114-
${llvm_libs}
115-
graphalg_lib
116-
graphalg_parse
117-
MLIRTranslateLib
118-
)
119-
120-
add_executable(graphalg-opt src/graphalg-opt.cpp)
121-
target_link_libraries(graphalg-opt PRIVATE
122-
${llvm_libs}
123-
graphalg_lib
124-
MLIROptLib
125-
)
126-
127-
add_executable(graphalg-lsp-server src/graphalg-lsp-server.cpp)
128-
target_link_libraries(graphalg-lsp-server PRIVATE
129-
${llvm_libs}
130-
graphalg_lib
131-
MLIRLspServerLib
132-
)
133-
134-
add_executable(graphalg-exec src/graphalg-exec.cpp)
135-
target_link_libraries(graphalg-exec PRIVATE
136-
${llvm_libs}
137-
graphalg_lib
138-
MLIRParser
139-
)
140-
141-
add_executable(graphalg-playground src/graphalg-playground.cpp)
142-
target_link_libraries(graphalg-playground PRIVATE
143-
${llvm_libs}
144-
graphalg_lib
145-
graphalg_parse
146-
)
147-
148-
if(ENABLE_WASM)
149-
set(PLAYGROUND_EXPORTED_FUNCTIONS
150-
_ga_new
151-
_ga_free
152-
_ga_parse
153-
_ga_diag_count
154-
_ga_diag_line_start
155-
_ga_diag_line_end
156-
_ga_diag_col_start
157-
_ga_diag_col_end
158-
_ga_diag_msg
159-
_ga_desugar
160-
_ga_add_arg
161-
_ga_set_dims
162-
_ga_set_arg_bool
163-
_ga_set_arg_int
164-
_ga_set_arg_real
165-
_ga_evaluate
166-
_ga_get_res_ring
167-
_ga_get_res_rows
168-
_ga_get_res_cols
169-
_ga_get_res_bool
170-
_ga_get_res_int
171-
_ga_get_res_real
172-
_ga_get_res_inf
173-
)
174-
string (REPLACE ";" "," PLAYGROUND_EXPORTED_FUNCTIONS_STR "${PLAYGROUND_EXPORTED_FUNCTIONS}")
175-
176-
177-
target_link_options(graphalg-playground PRIVATE
178-
-sEXPORTED_FUNCTIONS=${PLAYGROUND_EXPORTED_FUNCTIONS_STR}
179-
-sEXPORTED_RUNTIME_METHODS=cwrap,UTF8ToString
180-
-sMODULARIZE
181-
-sEXPORT_ES6)
182-
endif()
54+
add_subdirectory(tools)

compiler/configure.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ cmake -S $WORKSPACE_ROOT -B $BUILD_DIR -G Ninja \
88
-DCMAKE_CXX_COMPILER=clang++-20 \
99
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
1010
-DCMAKE_LINKER_TYPE=MOLD \
11+
-DGRAPHALG_OVERRIDE_LLVM_TOOLS_BINARY_DIR="/usr/lib/llvm-20/bin" \
1112
-DLLVM_ROOT="/opt/llvm-debug" \
12-
-DSET_LLVM_TOOLS_BINARY_DIR="/usr/lib/llvm-20/bin"

compiler/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(graphalg)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
add_library(GraphAlgIR
2+
GraphAlgAttr.cpp
3+
GraphAlgCanonicalize.cpp
4+
GraphAlgCast.cpp
5+
GraphAlgDialect.cpp
6+
GraphAlgInterfaces.cpp
7+
GraphAlgOps.cpp
8+
GraphAlgInferDensity.cpp
9+
GraphAlgTypes.cpp
10+
SemiringTypes.cpp
11+
)
12+
target_include_directories(GraphAlgIR PUBLIC ../../include)
13+
target_include_directories(GraphAlgIR SYSTEM PUBLIC ${PROJECT_BINARY_DIR}/include)
14+
add_dependencies(GraphAlgIR
15+
MLIRGraphAlgOpsIncGen
16+
MLIRGraphAlgPassesIncGen
17+
MLIRGraphAlgInterfacesIncGen
18+
)
19+
target_link_libraries(
20+
GraphAlgIR
21+
PRIVATE
22+
MLIRFuncDialect
23+
MLIRFuncInlinerExtension
24+
MLIRInferTypeOpInterface
25+
MLIRIR
26+
MLIRSupport
27+
)
28+
# Suppress -Wdangling-assignment-gsl for generated code from MLIR tablegen
29+
# The warning is triggered by template instantiations in GraphAlgOps.cpp.inc
30+
target_compile_options(GraphAlgIR PRIVATE -Wno-dangling-assignment-gsl)
31+
if(NOT GRAPHALG_ENABLE_RTTI)
32+
target_compile_options(GraphAlgIR PUBLIC -fno-rtti)
33+
endif()
34+
35+
add_library(GraphAlgPasses
36+
GraphAlgExplicateSparsity.cpp
37+
GraphAlgLoopAggregate.cpp
38+
GraphAlgPrepareInlinePass.cpp
39+
GraphAlgScalarizeApply.cpp
40+
GraphAlgSetDimensions.cpp
41+
GraphAlgSplitAggregate.cpp
42+
GraphAlgToCore.cpp
43+
GraphAlgToCorePipeline.cpp
44+
GraphAlgVerifyDimensions.cpp
45+
)
46+
add_dependencies(GraphAlgPasses MLIRGraphAlgPassesIncGen)
47+
target_link_libraries(
48+
GraphAlgPasses
49+
PRIVATE
50+
GraphAlgAnalysis
51+
GraphAlgIR
52+
MLIRTransforms
53+
)
54+
55+
add_subdirectory(analysis)
56+
add_subdirectory(evaluate)
57+
add_subdirectory(parse)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "graphalg/GraphAlgOps.h"
2+
#include "graphalg/analysis/DenseAnalysis.h"
3+
4+
namespace graphalg {
5+
6+
// Used in DenseResult trait
7+
void markAllDense(llvm::ArrayRef<DensityLattice *> results,
8+
llvm::MutableArrayRef<mlir::ChangeResult> changedResults) {
9+
for (auto [i, r] : llvm::enumerate(results)) {
10+
changedResults[i] |= r->setDense(true);
11+
}
12+
}
13+
14+
static bool isDense(const DensityLattice *l) { return l->isDense(); }
15+
16+
// Used in PropagatesDense trait
17+
void markDenseIfAllInputsDense(
18+
llvm::ArrayRef<const DensityLattice *> operands,
19+
llvm::ArrayRef<DensityLattice *> results,
20+
llvm::MutableArrayRef<mlir::ChangeResult> changedResults) {
21+
auto allDense = llvm::all_of(operands, isDense);
22+
for (auto [i, r] : llvm::enumerate(results)) {
23+
changedResults[i] |= r->setDense(allDense);
24+
}
25+
}
26+
27+
void ElementWiseAddOp::inferDensity(
28+
llvm::ArrayRef<const DensityLattice *> operands,
29+
llvm::ArrayRef<DensityLattice *> results,
30+
llvm::MutableArrayRef<mlir::ChangeResult> changedResults) {
31+
auto anyDense = llvm::any_of(operands, isDense);
32+
changedResults[0] |= results[0]->setDense(anyDense);
33+
}
34+
35+
} // namespace graphalg
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
add_library(GraphAlgAnalysis
2+
DenseAnalysis.cpp
3+
)
4+
target_link_libraries(
5+
GraphAlgAnalysis
6+
PRIVATE
7+
GraphAlgIR
8+
MLIRAnalysis
9+
)

0 commit comments

Comments
 (0)