Skip to content

Commit

Permalink
Add explicit error reporting to transform passes (#1976)
Browse files Browse the repository at this point in the history
Currently pass failures are silent (only written to `llvm::dbgs`) in
these passes Adding explicit error reporting will at least make it clear
what pass has failed.

Revert change to clang format script since it breaks when there are
multiple files, see:
https://github.com/openxla/stablehlo/actions/runs/7743835139

---------

Co-authored-by: mlevesquedion <[email protected]>
  • Loading branch information
GleasonK and mlevesquedion authored Feb 1, 2024
1 parent f5eadaa commit 39c4a00
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions build_tools/github_actions/lint_clang_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fi
echo "Running clang-format [mode=$FORMAT_MODE]..."
echo " Files: $CHANGED_FILES"
if [[ $FORMAT_MODE == 'fix' ]]; then
clang-format --style=google -i "$CHANGED_FILES"
clang-format --style=google -i $CHANGED_FILES
else
clang-format --style=google --dry-run --Werror "$CHANGED_FILES"
clang-format --style=google --dry-run --Werror $CHANGED_FILES
fi
7 changes: 5 additions & 2 deletions stablehlo/transforms/StablehloCanonicalizeDynamism.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,11 @@ struct StablehloCanonicalizeDynamismPass

RewritePatternSet patterns(&getContext());
populateStablehloCanonicalizeDynamismPatterns(&patterns, &getContext());
if (failed(applyPatternsAndFoldGreedily(getOperation(), std::move(patterns),
config))) {
auto func = getOperation();
if (failed(
applyPatternsAndFoldGreedily(func, std::move(patterns), config))) {
func.emitError("Failed to converge StablehloCanonicalizeDynamism in ")
<< config.maxIterations << " iterations";
return signalPassFailure();
}
}
Expand Down
3 changes: 3 additions & 0 deletions stablehlo/transforms/StablehloRefineShapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,9 +1082,12 @@ struct StablehloRefineShapesPass
config.strictMode = GreedyRewriteStrictness::AnyOp;

RewritePatternSet patterns(&getContext());

populateStablehloRefineShapesPatterns(&patterns, &getContext());
if (failed(
applyPatternsAndFoldGreedily(func, std::move(patterns), config))) {
func.emitError("Failed to converge StablehloRefineShapes in ")
<< config.maxIterations << " iterations";
return signalPassFailure();
}
}
Expand Down

0 comments on commit 39c4a00

Please sign in to comment.