Skip to content

Remove unused Toy dialect files and clean up the example structure - #9

Merged
Alwaysproblem merged 1 commit into
mainfrom
mlir-tutorial-22
Mar 8, 2026
Merged

Remove unused Toy dialect files and clean up the example structure#9
Alwaysproblem merged 1 commit into
mainfrom
mlir-tutorial-22

Conversation

@Alwaysproblem

Copy link
Copy Markdown
Owner
  • Deleted obsolete ToyCombine.td, AST.cpp, struct-codegen.toy, and toyc.cpp files from the Ch8 example.
  • Updated README.md to remove references to the deleted files and examples.
  • Modified build_deps.sh and sync_deps.sh scripts to ensure proper dependency management.
  • Added explicit TypeID definitions in MyExtension classes across multiple transform examples.
  • Improved comments and formatting in MyExtension.td and MyExtensionTypes.td for clarity.
  • Updated debug logging in MyExtension.cpp to use the new logging macros.

- Deleted obsolete ToyCombine.td, AST.cpp, struct-codegen.toy, and toyc.cpp files from the Ch8 example.
- Updated README.md to remove references to the deleted files and examples.
- Modified build_deps.sh and sync_deps.sh scripts to ensure proper dependency management.
- Added explicit TypeID definitions in MyExtension classes across multiple transform examples.
- Improved comments and formatting in MyExtension.td and MyExtensionTypes.td for clarity.
- Updated debug logging in MyExtension.cpp to use the new logging macros.
@AlwaysproblemAlwaysproblem self-assigned this Mar 8, 2026
CopilotAI review requested due to automatic review settings March 8, 2026 12:52
@Alwaysproblem
Alwaysproblem merged commit 6d9ec43 into mainMar 8, 2026
2 of 5 checks passed

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR cleans up the MLIR Toy and Transform tutorial examples by removing the obsolete Chapter 8 Toy dialect implementation and modernizing several remaining chapters (Ch1–Ch7 + transform_Ch2–Ch4) to match newer MLIR/LLVM APIs and logging patterns.

Changes:

  • Removed the entire obsolete Ch8 example (sources, TableGen, build files, and sample inputs) and dropped it from the build + README.
  • Updated build/deps scripts to sync and build against a newer llvm-project revision.
  • Modernized several Ch1–Ch7 sources (API updates, pass argument names, debug logging, op creation patterns) and added explicit TypeID definitions for Transform extensions.

Reviewed changes

Copilot reviewed 78 out of 80 changed files in this pull request and generated 6 comments.

Show a summary per file
FileDescription
mlir/example/transform_Ch4/lib/MyExtension.cppSwitch debug output to DebugLog (LDBG) and add explicit extension TypeID.
mlir/example/transform_Ch3/lib/MyExtension.cppAdd explicit extension TypeID.
mlir/example/transform_Ch3/include/MyExtensionTypes.tdMinor comment formatting update (but introduces trailing whitespace).
mlir/example/transform_Ch3/include/MyExtension.tdUpdate op argument constraints / comment formatting (but introduces trailing whitespace).
mlir/example/transform_Ch2/lib/MyExtension.cppAdd explicit extension TypeID.
mlir/example/transform_Ch2/include/MyExtension.tdComment formatting update (but introduces trailing whitespace).
mlir/example/scripts/sync_deps.shUpdate llvm-project clone ref to a specific llvmorg-* tag.
mlir/example/scripts/build_deps.shAdjust workspace/path handling and update CMake configuration invocation.
mlir/example/README.mdRemove Ch8 usage documentation.
mlir/example/Ch8/toyc.cppDeleted obsolete Ch8 toy compiler entrypoint.
mlir/example/Ch8/struct-codegen.toyDeleted obsolete Ch8 sample.
mlir/example/Ch8/parser/AST.cppDeleted obsolete Ch8 AST dumper implementation.
mlir/example/Ch8/mlir/ToyCombine.tdDeleted obsolete Ch8 rewrite patterns (TableGen).
mlir/example/Ch8/mlir/ToyCombine.cppDeleted obsolete Ch8 canonicalization implementation.
mlir/example/Ch8/mlir/ShapeInferencePass.cppDeleted obsolete Ch8 pass implementation.
mlir/example/Ch8/mlir/MLIRGen.cppDeleted obsolete Ch8 MLIR generation implementation.
mlir/example/Ch8/mlir/LowerToLLVM.cppDeleted obsolete Ch8 lowering to LLVM implementation.
mlir/example/Ch8/mlir/LowerToAffineLoops.cppDeleted obsolete Ch8 lowering to affine implementation.
mlir/example/Ch8/matmul.toy.mlirDeleted obsolete Ch8 MLIR input sample.
mlir/example/Ch8/matmul.toyDeleted obsolete Ch8 source input sample.
mlir/example/Ch8/include/toy/ShapeInferenceInterface.tdDeleted obsolete Ch8 interface TableGen.
mlir/example/Ch8/include/toy/ShapeInferenceInterface.hDeleted obsolete Ch8 generated interface header.
mlir/example/Ch8/include/toy/Passes.hDeleted obsolete Ch8 pass declarations.
mlir/example/Ch8/include/toy/Parser.hDeleted obsolete Ch8 parser header.
mlir/example/Ch8/include/toy/Ops.tdDeleted obsolete Ch8 ops TableGen.
mlir/example/Ch8/include/toy/MLIRGen.hDeleted obsolete Ch8 MLIRGen header.
mlir/example/Ch8/include/toy/Lexer.hDeleted obsolete Ch8 lexer header.
mlir/example/Ch8/include/toy/Dialect.hDeleted obsolete Ch8 dialect header.
mlir/example/Ch8/include/toy/CMakeLists.txtDeleted obsolete Ch8 TableGen build definitions.
mlir/example/Ch8/include/toy/AST.hDeleted obsolete Ch8 AST header.
mlir/example/Ch8/include/CMakeLists.txtDeleted obsolete Ch8 include subdir build hook.
mlir/example/Ch8/CMakeLists.txtDeleted obsolete Ch8 executable build definition.
mlir/example/Ch7/toyc.cppUpdate includes/registry setup; make helpers static; register LLVM inliner interface.
mlir/example/Ch7/parser/AST.cppMake printLitHelperstatic.
mlir/example/Ch7/mlir/ShapeInferencePass.cppSwitch to DebugLog (LDBG) and add pass argument name.
mlir/example/Ch7/mlir/MLIRGen.cppUpdate op creation patterns to Op::create; minor API updates.
mlir/example/Ch7/mlir/LowerToLLVM.cppConvert patterns to OpConversionPattern; update builder calls; add pass argument.
mlir/example/Ch7/mlir/LowerToAffineLoops.cppConvert patterns to OpConversionPattern; refactor loop lowering helper; add pass argument.
mlir/example/Ch7/mlir/Dialect.cppUpdate builder usage to Op::create; adjust call interface setter cast.
mlir/example/Ch7/include/toy/Ops.tdUpdate comments/builders to reflect Op::create usage; update GenericCallOp signature fields.
mlir/example/Ch7/include/toy/Lexer.hAdd missing <cstdlib> include.
mlir/example/Ch6/toyc.cppSame modernizations as Ch7 (includes, static helpers, inliner interface registration).
mlir/example/Ch6/parser/AST.cppMake printLitHelperstatic.
mlir/example/Ch6/mlir/ShapeInferencePass.cppSwitch to DebugLog (LDBG) and add pass argument name.
mlir/example/Ch6/mlir/MLIRGen.cppUpdate op creation patterns to Op::create; minor API updates.
mlir/example/Ch6/mlir/LowerToLLVM.cppConvert patterns to OpConversionPattern; update builder calls; add pass argument.
mlir/example/Ch6/mlir/LowerToAffineLoops.cppConvert patterns to OpConversionPattern; refactor loop lowering helper; add pass argument.
mlir/example/Ch6/mlir/Dialect.cppUpdate builder usage to Op::create; adjust call interface setter cast.
mlir/example/Ch6/include/toy/Ops.tdUpdate comments/builders to reflect Op::create usage; update GenericCallOp signature fields.
mlir/example/Ch6/include/toy/Lexer.hAdd missing <cstdlib> include.
mlir/example/Ch5/toyc.cppUpdate includes and make helper functions static.
mlir/example/Ch5/parser/AST.cppMake printLitHelperstatic.
mlir/example/Ch5/mlir/ShapeInferencePass.cppSwitch to DebugLog (LDBG) and add pass argument name.
mlir/example/Ch5/mlir/MLIRGen.cppUpdate op creation patterns to Op::create; minor API updates.
mlir/example/Ch5/mlir/LowerToAffineLoops.cppConvert patterns to OpConversionPattern; refactor loop lowering helper; add pass argument.
mlir/example/Ch5/mlir/Dialect.cppUpdate builder usage to Op::create; adjust call interface setter cast.
mlir/example/Ch5/include/toy/Ops.tdUpdate comments/builders to reflect Op::create usage; update GenericCallOp signature fields.
mlir/example/Ch5/include/toy/Lexer.hAdd missing <cstdlib> include.
mlir/example/Ch4/toyc.cppMake helper functions static.
mlir/example/Ch4/parser/AST.cppMake printLitHelperstatic.
mlir/example/Ch4/mlir/ShapeInferencePass.cppSwitch to DebugLog (LDBG) and add pass argument name.
mlir/example/Ch4/mlir/MLIRGen.cppUpdate op creation patterns to Op::create; minor API updates.
mlir/example/Ch4/mlir/Dialect.cppUpdate builder usage to Op::create; adjust call interface setter cast.
mlir/example/Ch4/include/toy/Ops.tdUpdate comments/builders to reflect Op::create usage; update GenericCallOp signature fields.
mlir/example/Ch4/include/toy/Lexer.hAdd missing <cstdlib> include.
mlir/example/Ch3/toyc.cppMake helper functions static.
mlir/example/Ch3/parser/AST.cppMake printLitHelperstatic.
mlir/example/Ch3/mlir/MLIRGen.cppUpdate op creation patterns to Op::create; minor API updates.
mlir/example/Ch3/include/toy/Ops.tdUpdate comments/builders to reflect Op::create usage.
mlir/example/Ch3/include/toy/Lexer.hAdd missing <cstdlib> include.
mlir/example/Ch2/toyc.cppMake helper functions static.
mlir/example/Ch2/parser/AST.cppMake printLitHelperstatic.
mlir/example/Ch2/mlir/MLIRGen.cppUpdate op creation patterns to Op::create; minor API updates.
mlir/example/Ch2/include/toy/Ops.tdUpdate comments/builders to reflect Op::create usage.
mlir/example/Ch2/include/toy/Lexer.hAdd missing <cstdlib> include.
mlir/example/Ch1/toyc.cppMake helper function static.
mlir/example/Ch1/parser/AST.cppMake printLitHelperstatic.
mlir/example/Ch1/include/toy/Lexer.hAdd missing <cstdlib> include.
mlir/example/CMakeLists.txtRemove Ch8 from the build.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +24 to 33
// Define the new operation. By convention, prefix its name with the name of the dialect
// extension, "my.". The full operation name will be further prefixed with "transform.".
def ChangeCallTargetOp : Op<Transform_Dialect, "my.change_call_target",
// Indicate that the operation implements the required TransformOpInterface and
// MemoryEffectsOpInterface. Use the TransformEach trait to provide the
// MemoryEffectsOpInterface. Use the TransformEach trait to provide the
// implementation for TransformOpInterface.
[TransformOpInterface, TransformEachOpTrait,
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
// Provide a brief and a full description. It is recommended that the latter describes
// Provide a brief and a full description. It is recommended that the latter describes
// the effects on the operands and how the operation processes various failure modes.

CopilotAIMar 8, 2026

Copy link

Choose a reason for hiding this comment

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

Several comment lines in this hunk now end with trailing whitespace. The repo has a trailing-whitespace pre-commit hook enabled, so these will cause CI/local hooks to fail. Please strip the trailing spaces on these lines.

Copilot uses AI. Check for mistakes.
Comment on lines +22 to 30
// Define the new operation. By convention, prefix its name with the name of the dialect
// extension, "my.". The full operation name will be further prefixed with "transform.".
def ChangeCallTargetOp : Op<Transform_Dialect, "my.change_call_target",
// Indicate that the operation implements the required TransformOpInterface and
// MemoryEffectsOpInterface.
[DeclareOpInterfaceMethods<TransformOpInterface>,
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
// Provide a brief and a full description. It is recommended that the latter describes
// Provide a brief and a full description. It is recommended that the latter describes
// the effects on the operands and how the operation processes various failure modes.

CopilotAIMar 8, 2026

Copy link

Choose a reason for hiding this comment

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

Several comment lines in this hunk now end with trailing whitespace. The repo has a trailing-whitespace pre-commit hook enabled, so these will cause CI/local hooks to fail. Please strip the trailing spaces on these lines.

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +27
if [[ -f "/usr/bin/git" ]]; then
WORKSPACEROOT=$(git rev-parse --show-toplevel)/mlir/example || WORKSPACEROOT=`pwd`
fi

cd ${WORKSPACEROOT}

CopilotAIMar 8, 2026

Copy link

Choose a reason for hiding this comment

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

WORKSPACEROOT is only set when /usr/bin/git exists; on systems where git is installed elsewhere (or missing), WORKSPACEROOT remains unset and cd ${WORKSPACEROOT} will fail. Consider initializing WORKSPACEROOT unconditionally (e.g., derive it from the script location, and/or use command -v git), and quote it when cd-ing to handle spaces safely.

Copilot uses AI. Check for mistakes.
Comment on lines 53 to 56
cmake -GNinja \
"-H$LLVM_SRC_DIR/llvm" \
"-B$build_dir" \
"-Hllvm" \
"-B$build_dir" \
-DCMAKE_BUILD_TYPE=Debug \

CopilotAIMar 8, 2026

Copy link

Choose a reason for hiding this comment

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

The CMake invocation is passing "-H llvm" and "-B $build_dir" as single arguments that contain spaces. CMake expects -S/-B (or legacy -H/-B) to be separate tokens (e.g., -S llvm -B "$build_dir"), otherwise argument parsing can break and the build won’t configure.

Copilot uses AI. Check for mistakes.
Comment on lines +27 to 28
// The usual components of a type such as description, mnemonic and assembly format
// should be provided.

CopilotAIMar 8, 2026

Copy link

Choose a reason for hiding this comment

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

This line introduces trailing whitespace, which will fail the repo’s trailing-whitespace pre-commit hook. Please remove the extra space at the end of the comment line.

Copilot uses AI. Check for mistakes.
-DLLVM_ENABLE_LLD=OFF \
-DLLVM_ENABLE_BACKTRACES=OFF \
-DLLVM_INCLUDE_UTILS=ON \
-DCMAKE_INSTALL_PREFIX=${install_dir} \

CopilotAIMar 8, 2026

Copy link

Choose a reason for hiding this comment

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

install_dir is derived from script arguments or WORKSPACEROOT and is expanded unquoted in -DCMAKE_INSTALL_PREFIX=${install_dir}, which allows shell metacharacters in that value to break out of the cmake command. If this script is ever invoked with install_dir (e.g., the second CLI argument) influenced by untrusted input, an attacker could supply a value like /tmp/x; rm -rf / and cause arbitrary commands to execute with the script's privileges. Quote or otherwise sanitize install_dir (and other similar variables) before expanding them into shell commands so that characters like ;, &, and backticks cannot be interpreted by the shell.

Copilot uses AI. Check for mistakes.
Sign up for freeto 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.

2 participants

@Alwaysproblem