Skip to content

Conversation

@ashjeong
Copy link
Contributor

@ashjeong ashjeong commented Jun 18, 2025

Replaces ConstantOp with ConstantIntOp where applicable to reduce code clutter of creating extraneous IntegerAttr.

Relies on
llvm/llvm-project#144636 & llvm/llvm-project#144638

Note that ConstantIntOp does not support a single TypedAttr argument or arguments of container types and values – continue to use ConstantOp for these cases.

Please merge with respective PR in ZKX!
ONLY merge when the CI works properly

This PR was mistakenly merged with #61 to main, while CI was still not finishing successfully. See #62 for the fix.

@ashjeong ashjeong requested review from batzor, chokobole and quanxi1 June 18, 2025 02:26
@ashjeong ashjeong marked this pull request as draft June 18, 2025 04:30
@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch from 1b164dd to 0bf058a Compare June 18, 2025 06:02
@chokobole
Copy link
Collaborator

Closing this PR for now, as it's not a priority at the moment. We'll reopen it when the time is right

@chokobole chokobole closed this Aug 1, 2025
@ashjeong ashjeong reopened this Aug 11, 2025
@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch from 0bf058a to 4a62cfa Compare August 11, 2025 09:04
@ashjeong ashjeong marked this pull request as ready for review August 11, 2025 09:05
@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch from 4a62cfa to a209db1 Compare August 11, 2025 09:36
@chokobole
Copy link
Collaborator

@chokobole
Copy link
Collaborator

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request primarily refactors the codebase to align with upstream MLIR API changes, namely replacing arith::ConstantOp with the more direct arith::ConstantIntOp and renaming bufferization::ToMemrefOp to bufferization::ToBufferOp. The changes are applied consistently across the codebase, including tests and patch files for dependencies. A notable improvement is the more precise verification logic for the elliptic_curve.msm operation, which is now correctly documented. Overall, the refactoring is clean and well-executed. I've added a couple of suggestions to improve robustness by replacing assert(false, ...) with llvm_unreachable.

@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch from a209db1 to 5c76cc2 Compare August 12, 2025 05:47
Note that `ToMemref` has been changed to `ToBuffer`

LLVM commit used contains the PRs
- llvm/llvm-project#144636
- llvm/llvm-project#144638
which were committed in order to apply changes from `ConstantOp` to `ConstantIntOp`
Patch done to llvm-project:
- Switches int/type ordering of `ConstantIntOp`to standardize with `ConstantOp` argument
   ordering
- Adds constructor for `APInt` types

Note that a `TypedAttr` input still requires `ConstantOp` to be used
patches/ is not a real folder and our patch files are all included in
third-party/llvm-project/
@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch from 5c76cc2 to e2ac967 Compare August 12, 2025 05:50
@ashjeong ashjeong requested a review from chokobole August 12, 2025 05:52
Without this move, pre-commit may need to be run twice
@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch from e2ac967 to b3adf94 Compare August 12, 2025 05:54
Copy link
Collaborator

@chokobole chokobole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chokobole
Copy link
Collaborator

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a significant refactoring effort to align with upstream MLIR/LLVM API changes. The primary changes involve replacing arith::ConstantOp with arith::ConstantIntOp and bufferization::ToMemrefOp with bufferization::ToBufferOp. These changes have been applied consistently across the codebase. Additionally, there are several good practice improvements, such as replacing assert with llvm_unreachable and enhancing operator verification logic. The configuration for clang-tidy has also been updated to use a shell script, which is a good approach for managing platform-specific arguments. I've found one issue in this new script that needs to be addressed. Overall, the changes are well-executed and improve the codebase.


# Get the path to the directory containing this script.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PROJECT_ROOT=$(dirname "$SCRIPT_DIR")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The PROJECT_ROOT variable appears to be defined incorrectly. SCRIPT_DIR will resolve to the project's root directory, and dirname "$SCRIPT_DIR" will then point to the parent directory of the project. This will likely cause clang-tidy to fail to find compile_commands.json, which is expected to be at the project root.

Suggested change
PROJECT_ROOT=$(dirname "$SCRIPT_DIR")
PROJECT_ROOT="$SCRIPT_DIR"

Copy link
Contributor

@batzor batzor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch from b3adf94 to 2fdd49b Compare August 12, 2025 08:23
@ashjeong
Copy link
Contributor Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a large refactoring that primarily replaces arith::ConstantOp with the more specific arith::ConstantIntOp where applicable. This helps reduce code clutter by avoiding the creation of extraneous IntegerAttr. The changes also include replacing bufferization::ToMemrefOp with bufferization::ToBufferOp to align with upstream MLIR changes.

Beyond the main refactoring, the PR introduces a new script for clang-tidy in pre-commit hooks, updates LLVM dependencies, and improves code quality by replacing assert with llvm_unreachable for better compiler optimizations.

The changes are extensive but look correct and consistent with the stated goals. I've added a couple of suggestions to make the new run_clang_tidy.sh script more robust.

ashjeong added a commit to fractalyze/zkx that referenced this pull request Aug 12, 2025
@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch 5 times, most recently from 6e14d69 to bf7d6e0 Compare August 13, 2025 04:07
Copy link
Contributor

@quanxi1 quanxi1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

ashjeong added a commit to fractalyze/zkx that referenced this pull request Aug 13, 2025
ashjeong added a commit to fractalyze/zkx that referenced this pull request Aug 13, 2025
ashjeong added a commit to fractalyze/zkx that referenced this pull request Aug 13, 2025
@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch 10 times, most recently from 2a246d9 to a598ee9 Compare August 13, 2025 07:18
@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch from a598ee9 to e71eef0 Compare August 13, 2025 07:19
@ashjeong ashjeong changed the title refac: change arith constant op refac: change arith constant op (merged with #41) Aug 14, 2025
@ashjeong ashjeong closed this Aug 14, 2025
@ashjeong ashjeong changed the title refac: change arith constant op (merged with #41) refac: change arith constant op (merged with #61) Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants