Skip to content

Commit 0cf16da

Browse files
committed
Add pre-commit
1 parent ccef74b commit 0cf16da

File tree

17 files changed

+186
-187
lines changed

17 files changed

+186
-187
lines changed

.clang-format

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
BasedOnStyle: LLVM
32
Cpp11BracedListStyle: false
43
AllowShortBlocksOnASingleLine: Never

.github/workflows/macos-ci.yml

+27-37
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,39 @@
11
name: macOS CI
2-
32
on:
43
push:
5-
branches: [ "main" ]
4+
branches: ["main"]
65
pull_request:
7-
branches: [ "main" ]
8-
6+
branches: ["main"]
97
jobs:
108
build:
119
runs-on: ${{ matrix.os }}
12-
1310
strategy:
1411
fail-fast: false
1512
matrix:
1613
os: [macos-latest]
1714
steps:
18-
- uses: actions/checkout@v4
19-
with:
20-
submodules: true
21-
22-
- name: Install LLVM@19
23-
run: brew install llvm@19 ninja
24-
25-
- name: Install Python dependencies
26-
run: pip install lit filecheck==0.0.24
27-
28-
- name: Set reusable strings
29-
id: strings
30-
shell: bash
31-
run: |
32-
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
33-
34-
- name: Configure CMake
35-
run: >
36-
cmake -G Ninja
37-
-B ${{ steps.strings.outputs.build-output-dir }}
38-
-DCMAKE_C_COMPILER=clang
39-
-DCMAKE_CXX_COMPILER=clang++
40-
-DCMAKE_PREFIX_PATH=/opt/homebrew/opt/llvm@19/
41-
-DCMAKE_BUILD_TYPE=Release
42-
-S ${{ github.workspace }}
43-
44-
- name: Build
45-
run: cmake --build ${{ steps.strings.outputs.build-output-dir }}
46-
47-
- name: Test
48-
working-directory: ${{ steps.strings.outputs.build-output-dir }}
49-
run: ninja run-integration-tests
15+
- uses: actions/checkout@v4
16+
with:
17+
submodules: true
18+
- name: Install LLVM@19
19+
run: brew install llvm@19 ninja
20+
- name: Install Python dependencies
21+
run: pip install lit filecheck==0.0.24
22+
- name: Set reusable strings
23+
id: strings
24+
shell: bash
25+
run: |
26+
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
27+
- name: Configure CMake
28+
run: |
29+
cmake -G Ninja \
30+
-B ${{ steps.strings.outputs.build-output-dir }} \
31+
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
32+
-DCMAKE_PREFIX_PATH=/opt/homebrew/opt/llvm@19/ \
33+
-DCMAKE_BUILD_TYPE=Release \
34+
-S ${{ github.workspace }}
35+
- name: Build
36+
run: cmake --build ${{ steps.strings.outputs.build-output-dir }}
37+
- name: Test
38+
working-directory: ${{ steps.strings.outputs.build-output-dir }}
39+
run: ninja run-integration-tests

.github/workflows/pre-commit.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: pre-commit
2+
on:
3+
pull_request:
4+
push:
5+
branches: [main]
6+
jobs:
7+
pre-commit:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: actions/setup-python@v3
12+
- uses: pre-commit/[email protected]

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
Output
2-
3-

.pre-commit-config.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v5.0.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
11+
- repo: https://github.com/google/yamlfmt
12+
rev: v0.14.0
13+
hooks:
14+
- id: yamlfmt
15+
- repo: https://github.com/cheshirekow/cmake-format-precommit
16+
rev: v0.6.13
17+
hooks:
18+
- id: cmake-format
19+
- repo: https://github.com/pre-commit/mirrors-clang-format
20+
rev: 'v19.1.4'
21+
hooks:
22+
- id: clang-format

cmake/lightstorm.cmake

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
function(add_lightstorm_executable ruby)
2-
set (in_ruby ${CMAKE_CURRENT_LIST_DIR}/${ruby})
3-
set (out_c ${CMAKE_CURRENT_BINARY_DIR}/${ruby}.c)
4-
set (target_name ${ruby}.exe)
5-
add_custom_command(OUTPUT ${out_c}
2+
set(in_ruby ${CMAKE_CURRENT_LIST_DIR}/${ruby})
3+
set(out_c ${CMAKE_CURRENT_BINARY_DIR}/${ruby}.c)
4+
set(target_name ${ruby}.exe)
5+
add_custom_command(
6+
OUTPUT ${out_c}
67
COMMAND $<TARGET_FILE:lightstorm> ${in_ruby} -o ${out_c}
7-
DEPENDS ${in_ruby} lightstorm
8-
)
8+
DEPENDS ${in_ruby} lightstorm)
99
add_executable(${target_name} ${out_c})
1010
target_compile_options(${target_name} PRIVATE ${LIGHTSTORM_CFLAGS})
1111
target_link_options(${target_name} PRIVATE ${LIGHTSTORM_CFLAGS})
12-
target_link_libraries(${target_name} PRIVATE mruby_static lightstorm_runtime_main)
13-
target_include_directories(${target_name} PRIVATE
14-
${CMAKE_SOURCE_DIR}
15-
${CMAKE_SOURCE_DIR}/third_party/mruby/include
16-
${CMAKE_SOURCE_DIR}/third_party/mruby/build/host/include
17-
)
12+
target_link_libraries(${target_name} PRIVATE mruby_static
13+
lightstorm_runtime_main)
14+
target_include_directories(
15+
${target_name}
16+
PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/third_party/mruby/include
17+
${CMAKE_SOURCE_DIR}/third_party/mruby/build/host/include)
1818
add_dependencies(${target_name} mruby_static)
1919
endfunction()

cmake/mruby.cmake

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
include(ExternalProject)
2-
set (MRUBY_DIR "${CMAKE_SOURCE_DIR}/third_party/mruby")
3-
set (MRUBY_BINARY "${MRUBY_DIR}/bin/mruby")
4-
set (MRBC_BINARY "${MRUBY_DIR}/bin/mrbc")
5-
set (MRUBY_STATIC "${MRUBY_DIR}/build/host/lib/libmruby.a")
2+
set(MRUBY_DIR "${CMAKE_SOURCE_DIR}/third_party/mruby")
3+
set(MRUBY_BINARY "${MRUBY_DIR}/bin/mruby")
4+
set(MRBC_BINARY "${MRUBY_DIR}/bin/mrbc")
5+
set(MRUBY_STATIC "${MRUBY_DIR}/build/host/lib/libmruby.a")
66

7-
ExternalProject_Add(mruby
7+
ExternalProject_Add(
8+
mruby
89
SOURCE_DIR ${MRUBY_DIR}
910
CONFIGURE_COMMAND ""
10-
BUILD_COMMAND ${CMAKE_COMMAND} -E env CFLAGS="${LIGHTSTORM_CFLAGS}" LDFLAGS="${LIGHTSTORM_CFLAGS}" rake all --verbose
11+
BUILD_COMMAND ${CMAKE_COMMAND} -E env CFLAGS="${LIGHTSTORM_CFLAGS}"
12+
LDFLAGS="${LIGHTSTORM_CFLAGS}" rake all --verbose
1113
BUILD_IN_SOURCE ON
1214
INSTALL_COMMAND ""
1315
BUILD_BYPRODUCTS ${MRUBY_STATIC} ${MRUBY_BINARY} ${MRBC_BINARY}
14-
BUILD_ALWAYS
15-
)
16+
BUILD_ALWAYS)
1617

1718
add_executable(mruby_binary IMPORTED GLOBAL)
1819
set_property(TARGET mruby_binary PROPERTY IMPORTED_LOCATION ${MRUBY_BINARY})

lib/compiler/CMakeLists.txt

+9-21
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
add_library(lightstorm_compiler STATIC
2-
compiler.cpp
3-
converter.cpp
4-
)
1+
add_library(lightstorm_compiler STATIC compiler.cpp converter.cpp)
52
target_include_directories(lightstorm_compiler
6-
PRIVATE
7-
${CMAKE_SOURCE_DIR}/include
8-
)
9-
target_include_directories(lightstorm_compiler
10-
PRIVATE SYSTEM
11-
${CMAKE_SOURCE_DIR}/third_party/mruby/include
12-
${LLVM_INCLUDE_DIRS}
13-
${MLIR_INCLUDE_DIRS}
14-
)
15-
target_link_libraries(lightstorm_compiler
16-
PRIVATE
17-
mruby_static
18-
rite_dialect
19-
MLIRFuncDialect
20-
MLIRIndexDialect
21-
MLIRTransforms
22-
)
3+
PRIVATE ${CMAKE_SOURCE_DIR}/include)
4+
target_include_directories(
5+
lightstorm_compiler
6+
PRIVATE SYSTEM ${CMAKE_SOURCE_DIR}/third_party/mruby/include
7+
${LLVM_INCLUDE_DIRS} ${MLIR_INCLUDE_DIRS})
8+
target_link_libraries(
9+
lightstorm_compiler PRIVATE mruby_static rite_dialect MLIRFuncDialect
10+
MLIRIndexDialect MLIRTransforms)
2311
target_compile_options(lightstorm_compiler PRIVATE -fno-rtti -fno-exceptions)
2412
add_dependencies(lightstorm_compiler mruby_static)

lib/conversion/CMakeLists.txt

+14-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
add_library(lightstorm_conversion STATIC
2-
c_conversion.cpp
3-
)
1+
add_library(lightstorm_conversion STATIC c_conversion.cpp)
42
target_include_directories(lightstorm_conversion
5-
PRIVATE
6-
${CMAKE_SOURCE_DIR}/include
7-
)
8-
target_include_directories(lightstorm_conversion
9-
PRIVATE SYSTEM
10-
${LLVM_INCLUDE_DIRS}
11-
${MLIR_INCLUDE_DIRS}
12-
)
13-
target_link_libraries(lightstorm_conversion
14-
PRIVATE
15-
rite_dialect
16-
MLIRTransforms
17-
MLIREmitCDialect
18-
MLIRFuncTransforms
19-
MLIRFuncToEmitC
20-
MLIRArithToEmitC
21-
MLIRTargetCpp
22-
)
3+
PRIVATE ${CMAKE_SOURCE_DIR}/include)
4+
target_include_directories(
5+
lightstorm_conversion PRIVATE SYSTEM ${LLVM_INCLUDE_DIRS}
6+
${MLIR_INCLUDE_DIRS})
7+
target_link_libraries(
8+
lightstorm_conversion
9+
PRIVATE rite_dialect
10+
MLIRTransforms
11+
MLIREmitCDialect
12+
MLIRFuncTransforms
13+
MLIRFuncToEmitC
14+
MLIRArithToEmitC
15+
MLIRTargetCpp)
2316
target_compile_options(lightstorm_conversion PRIVATE -fno-rtti -fno-exceptions)

lib/dialect/CMakeLists.txt

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
add_library(rite_dialect STATIC rite.cpp)
22
target_link_libraries(rite_dialect LLVMSupport MLIRDialect)
3-
target_include_directories(rite_dialect
4-
PUBLIC
5-
${CMAKE_CURRENT_BINARY_DIR}
6-
${CMAKE_SOURCE_DIR}/include
7-
)
8-
target_compile_options(rite_dialect PUBLIC -fno-rtti -fno-exceptions -fvisibility=hidden)
3+
target_include_directories(rite_dialect PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
4+
${CMAKE_SOURCE_DIR}/include)
5+
target_compile_options(rite_dialect PUBLIC -fno-rtti -fno-exceptions
6+
-fvisibility=hidden)
97
# Needed by mlir-tablegen
108
include_directories(SYSTEM ${MLIR_INCLUDE_DIRS})
119
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
1210

13-
set(LLVM_TARGET_DEFINITIONS ${CMAKE_SOURCE_DIR}/include/lightstorm/dialect/rite.td)
11+
set(LLVM_TARGET_DEFINITIONS
12+
${CMAKE_SOURCE_DIR}/include/lightstorm/dialect/rite.td)
1413
mlir_tablegen(RiteDialect.h.inc -gen-dialect-decls)
1514
mlir_tablegen(RiteDialect.cpp.inc -gen-dialect-defs)
1615
mlir_tablegen(RiteOps.h.inc -gen-op-decls)

lib/optimizations/CMakeLists.txt

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
add_library(lightstorm_optimizations STATIC
2-
optimizations.cpp
3-
)
1+
add_library(lightstorm_optimizations STATIC optimizations.cpp)
42
target_include_directories(lightstorm_optimizations
5-
PRIVATE
6-
${CMAKE_SOURCE_DIR}/include
7-
)
8-
target_include_directories(lightstorm_optimizations
9-
PRIVATE SYSTEM
10-
${LLVM_INCLUDE_DIRS}
11-
${MLIR_INCLUDE_DIRS}
12-
)
13-
target_link_libraries(lightstorm_optimizations
14-
PRIVATE
15-
rite_dialect
16-
)
17-
target_compile_options(lightstorm_optimizations PRIVATE -fno-rtti -fno-exceptions)
3+
PRIVATE ${CMAKE_SOURCE_DIR}/include)
4+
target_include_directories(
5+
lightstorm_optimizations PRIVATE SYSTEM ${LLVM_INCLUDE_DIRS}
6+
${MLIR_INCLUDE_DIRS})
7+
target_link_libraries(lightstorm_optimizations PRIVATE rite_dialect)
8+
target_compile_options(lightstorm_optimizations PRIVATE -fno-rtti
9+
-fno-exceptions)

lib/optimizations/optimizations.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ class EscapeAnalysisAtHome
4747
for (auto arith : function.getOps<rite::ArithOp>()) {
4848
// If all the uses of the ArithOp are another ArithOp, then this op can have an opportunity to
4949
// use stack-allocated slot instead of heap allocation
50-
auto is_arith = [](mlir::Operation *user) {
51-
return llvm::isa<rite::ArithOp>(user);
52-
};
50+
auto is_arith = [](mlir::Operation *user) { return llvm::isa<rite::ArithOp>(user); };
5351
if (std::all_of(arith->user_begin(), arith->user_end(), is_arith)) {
5452
worklist.push_back(arith);
5553
}
@@ -62,7 +60,13 @@ class EscapeAnalysisAtHome
6260
builder.setInsertionPointToStart(&entry);
6361
auto slot = builder.create<rite::StackAllocationOp>(arith.getLoc(), valueType, mrb);
6462
builder.setInsertionPointAfter(arith);
65-
auto no_escape = builder.create<rite::ArithNoEscapeOp>(arith->getLoc(), arith.getType(), arith.getMrb(), arith.getLhs(), arith.getRhs(), slot, arith.getKindAttr());
63+
auto no_escape = builder.create<rite::ArithNoEscapeOp>(arith->getLoc(),
64+
arith.getType(),
65+
arith.getMrb(),
66+
arith.getLhs(),
67+
arith.getRhs(),
68+
slot,
69+
arith.getKindAttr());
6670
arith->replaceAllUsesWith(no_escape);
6771
arith->erase();
6872
}

lib/runtime/CMakeLists.txt

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
add_library(lightstorm_runtime_main STATIC
2-
lightstorm_runtime_main.c
3-
)
4-
target_include_directories(lightstorm_runtime_main
5-
PUBLIC
6-
${CMAKE_SOURCE_DIR}/include
7-
${CMAKE_SOURCE_DIR}/third_party/mruby/include
8-
${CMAKE_SOURCE_DIR}/third_party/mruby/build/host/include
9-
)
1+
add_library(lightstorm_runtime_main STATIC lightstorm_runtime_main.c)
2+
target_include_directories(
3+
lightstorm_runtime_main
4+
PUBLIC ${CMAKE_SOURCE_DIR}/include
5+
${CMAKE_SOURCE_DIR}/third_party/mruby/include
6+
${CMAKE_SOURCE_DIR}/third_party/mruby/build/host/include)
107
target_compile_options(lightstorm_runtime_main PRIVATE ${LIGHTSTORM_CFLAGS})
118
target_link_options(lightstorm_runtime_main PRIVATE ${LIGHTSTORM_CFLAGS})
129
add_dependencies(lightstorm_runtime_main mruby_static)

tests/benchmarks/CMakeLists.txt

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
file(GLOB files RELATIVE ${CMAKE_CURRENT_LIST_DIR} "${CMAKE_CURRENT_LIST_DIR}/*.rb")
1+
file(
2+
GLOB files
3+
RELATIVE ${CMAKE_CURRENT_LIST_DIR}
4+
"${CMAKE_CURRENT_LIST_DIR}/*.rb")
25
foreach(file ${files})
36
add_lightstorm_executable(${file})
4-
set (bench_targets ${bench_targets} $<TARGET_FILE:${file}.exe> ${CMAKE_CURRENT_LIST_DIR}/${file})
5-
endforeach ()
6-
add_custom_target(run-benchmarks
7-
COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/bench.py $<TARGET_FILE:mruby_binary> ${bench_targets}
8-
)
7+
set(bench_targets ${bench_targets} $<TARGET_FILE:${file}.exe>
8+
${CMAKE_CURRENT_LIST_DIR}/${file})
9+
endforeach()
10+
add_custom_target(
11+
run-benchmarks COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/bench.py
12+
$<TARGET_FILE:mruby_binary> ${bench_targets})

0 commit comments

Comments
 (0)