Skip to content

Commit

Permalink
refactor linting
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed Sep 8, 2023
1 parent dc353ba commit 73b7093
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 138 deletions.
157 changes: 33 additions & 124 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
# By latest GitHub means actually latest LTS only
runs-on: ubuntu-latest

permissions:
pull-requests: write

strategy:
# Run all the test even if there are some which fail
fail-fast: false
Expand Down Expand Up @@ -110,7 +113,7 @@ jobs:
- name: Install git
run: |
apt-get update
apt-get install -y git
apt-get install -y git sudo
# Clone the repo and its submodules. Do shallow clone to save clone
# time.
Expand Down Expand Up @@ -164,8 +167,8 @@ jobs:
- name: Build and test (Assert)
if: matrix.build_type == 'Assert'
run: |
mkdir build_assert
cd build_assert
mkdir build
cd build
cmake .. \
-GNinja \
-DCMAKE_BUILD_TYPE=Debug \
Expand All @@ -191,8 +194,8 @@ jobs:
- name: Build and test (Release)
if: matrix.build_type == 'Release'
run: |
mkdir build_release
cd build_release
mkdir build
cd build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DAIE_COMPILER=NONE \
Expand All @@ -206,132 +209,38 @@ jobs:
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_COMPILE_WARNING_AS_ERROR=ON \
-DLLVM_EXTERNAL_LIT=`pwd`/../llvm/build/bin/llvm-lit
-DLLVM_EXTERNAL_LIT=`pwd`/../llvm/build/bin/llvm-lit \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
make -j$(nproc)
make check-aie
make check-tutorials
make check-reference-designs
lint-repo:
name: Check code format
runs-on: ubuntu-latest
steps:
# We'll be running clang-tidy later in this flow.
- name: Install clang-tidy
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy-12
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy \
/usr/bin/clang-tidy-12 100
# Clone the repo and its submodules. Do shallow clone to save clone
# time.
- name: Get repo
uses: actions/checkout@v3
with:
fetch-depth: 2
submodules: "true"

# --------
# Lint the code.
# -------

# Choose the git commit to diff against for the purposes of linting.
# Since this workflow is triggered on both pushes and pull requests, we
# have to determine if the pull request target branch is set (which it
# will only be on the PR triggered flow). If it's not, then compare
# against the last commit.
- name: choose-commit
if: always()
- uses: cpp-linter/cpp-linter-action@v2
id: linter
env:
# Base ref is the target branch, in text form (not hash)
PR_BASE: ${{ github.base_ref }}
run: |
# Run clang-format
if [[ -z "$PR_BASE" ]]; then
DIFF_COMMIT_NAME="HEAD^"
else
DIFF_COMMIT_NAME="$PR_BASE"
fi
echo "DIFF_COMMIT_NAME=$DIFF_COMMIT_NAME" >> $GITHUB_ENV
# Since we did a shallow fetch for this repo, we must fetch the commit
# upon which we be diff'ing. The last step set the ref name in the
# $DIFF_COMMIT_NAME environment variable. When running the fetch, resolve
# it to the commit hash and pass that hash along to subsequent steps.
- name: git fetch base commit
continue-on-error: true
run: |
if [[ ! "$DIFF_COMMIT_NAME" == *"HEAD"* ]]; then
git fetch --recurse-submodules=no origin $DIFF_COMMIT_NAME
DIFF_COMMIT_SHA=$( git rev-parse origin/$DIFF_COMMIT_NAME )
else
DIFF_COMMIT_SHA=$( git rev-parse $DIFF_COMMIT_NAME )
fi
echo "DIFF_COMMIT=$DIFF_COMMIT_SHA" >> $GITHUB_ENV
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
style: file
database: build

# Run 'git clang-format', comparing against the target commit hash. If
# clang-format fixed anything, fail and output a patch.
- name: clang-format
if: always()
run: |
# Run clang-format
git clang-format-12 $DIFF_COMMIT
git diff --ignore-submodules > clang-format.patch
if [ -s clang-format.patch ]; then
echo "Clang-format found formatting problems in the following " \
"files. See diff in the clang-format.patch artifact."
git diff --ignore-submodules --name-only
git checkout .
exit 1
fi
echo "Clang-format found no formatting problems"
exit 0
- name: Check for cpp-linter fails
if: steps.linter.outputs.checks-failed > 0
run: exit 1

# Run clang-tidy against only the changes. The 'clang-tidy-diff' script
# does this if supplied with the diff.
- name: clang-tidy
if: always()
run: |
git diff -U0 $DIFF_COMMIT | \
clang-tidy-diff-12.py -path build_assert -p1 -fix
git diff --ignore-submodules > clang-tidy.patch
if [ -s clang-tidy.patch ]; then
echo "Clang-tidy problems in the following files. " \
"See diff in the clang-tidy.patch artifact."
git diff --ignore-submodules --name-only
git checkout .
exit 1
fi
echo "Clang-tidy found no problems"
exit 0
format-python:
name: Check Python code format
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v3

# Upload the format and tidy patches to an artifact (zip'd) associated
# with the workflow run. Only run this on a failure.
- name: Upload format and tidy patches
uses: actions/upload-artifact@v3
continue-on-error: true
if: failure()
- uses: reviewdog/action-black@v3
with:
name: clang-format-tidy-patches
path: clang-*.patch

# Unfortunately, artifact uploads are always zips so display the diff as
# well to provide feedback at a glance.
- name: clang format and tidy patches display
if: failure()
continue-on-error: true
run: |
# Display patches
if [ ! -z clang-format.patch ]; then
echo "Clang-format patch"
echo "================"
cat clang-format.patch
echo "================"
fi
if [ ! -z clang-tidy.patch ]; then
echo "Clang-tidy patch"
echo "================"
cat clang-tidy.patch
echo "================"
fi
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-check
level: error
filter_mode: file
verbose: true
fail_on_error: true
2 changes: 1 addition & 1 deletion lib/CAPI/Dialects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(AIE, aie, xilinx::AIE::AIEDialect)
//===---------------------------------------------------------------------===//

bool aieTypeIsObjectFifoType(MlirType type) {

Check warning on line 19 in lib/CAPI/Dialects.cpp

View workflow job for this annotation

GitHub Actions / Build and Test (Assert, 20.04)

/lib/CAPI/Dialects.cpp:19:6 [modernize-use-trailing-return-type]

use a trailing return type for this function

Check warning on line 19 in lib/CAPI/Dialects.cpp

View workflow job for this annotation

GitHub Actions / Build and Test (Assert, 22.04)

/lib/CAPI/Dialects.cpp:19:6 [modernize-use-trailing-return-type]

use a trailing return type for this function

Check warning on line 19 in lib/CAPI/Dialects.cpp

View workflow job for this annotation

GitHub Actions / Build and Test (Release, 20.04)

/lib/CAPI/Dialects.cpp:19:6 [modernize-use-trailing-return-type]

use a trailing return type for this function

Check warning on line 19 in lib/CAPI/Dialects.cpp

View workflow job for this annotation

GitHub Actions / Build and Test (Release, 22.04)

/lib/CAPI/Dialects.cpp:19:6 [modernize-use-trailing-return-type]

use a trailing return type for this function
return unwrap(type).isa<xilinx::AIE::AIEObjectFifoType>();
return unwrap(type).isa<xilinx::AIE::AIEObjectFifoType>();
}

MlirType aieObjectFifoTypeGet(MlirType type) {

Check warning on line 23 in lib/CAPI/Dialects.cpp

View workflow job for this annotation

GitHub Actions / Build and Test (Assert, 20.04)

/lib/CAPI/Dialects.cpp:23:10 [modernize-use-trailing-return-type]

use a trailing return type for this function

Check warning on line 23 in lib/CAPI/Dialects.cpp

View workflow job for this annotation

GitHub Actions / Build and Test (Assert, 22.04)

/lib/CAPI/Dialects.cpp:23:10 [modernize-use-trailing-return-type]

use a trailing return type for this function

Check warning on line 23 in lib/CAPI/Dialects.cpp

View workflow job for this annotation

GitHub Actions / Build and Test (Release, 20.04)

/lib/CAPI/Dialects.cpp:23:10 [modernize-use-trailing-return-type]

use a trailing return type for this function

Check warning on line 23 in lib/CAPI/Dialects.cpp

View workflow job for this annotation

GitHub Actions / Build and Test (Release, 22.04)

/lib/CAPI/Dialects.cpp:23:10 [modernize-use-trailing-return-type]

use a trailing return type for this function
Expand Down
26 changes: 13 additions & 13 deletions python/aie/compiler/aiecc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
import rich.progress as progress

aie_opt_passes = [
"--aie-normalize-address-spaces",
"--canonicalize",
"--cse",
"--convert-vector-to-llvm",
"--expand-strided-metadata",
"--lower-affine",
"--convert-math-to-llvm",
"--convert-arith-to-llvm",
"--convert-memref-to-llvm",
"--convert-func-to-llvm=use-bare-ptr-memref-call-conv",
"--convert-cf-to-llvm",
"--canonicalize",
"--cse",
"--aie-normalize-address-spaces",
"--canonicalize",
"--cse",
"--convert-vector-to-llvm",
"--expand-strided-metadata",
"--lower-affine",
"--convert-math-to-llvm",
"--convert-arith-to-llvm",
"--convert-memref-to-llvm",
"--convert-func-to-llvm=use-bare-ptr-memref-call-conv",
"--convert-cf-to-llvm",
"--canonicalize",
"--cse",
]


Expand Down

0 comments on commit 73b7093

Please sign in to comment.