Skip to content

Conversation

badumbatish
Copy link
Contributor

Part of #1912

This PR only fixes 1 file. Also added a CI file to see if it'd run correctly

Copy link
Collaborator

@xlauko xlauko left a comment

Choose a reason for hiding this comment

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

It would be better to split the PR, first setup an action and then add changes incrementally always checking it passes the new action.

The first one should have tag [Github][CIR]

-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
-DCLANG_ENABLE_CIR=ON

ninja -C build
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we build the project, the only needed thing are just generated tablegen files maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL compile_commands.json doesn't need the full build to be generated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'm not seeing a clean way to generate all the necessary tablegen files for MLIR, except for this hack right here for now

ninja -C build_pilot $(ninja -C build_pilot -t targets all | grep IncGen | sed 's/:.*//') clang-tablegen-targets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we're building 1k4 files with this approach so i'm not quite sure we need ccache or not here

Copy link
Member

Choose a reason for hiding this comment

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

We already have a job that builds and run ninja check-clang-cir, can't we run the clang-tidy after that and use the build artifacts from it? Not sure how easy is to connect these things, and it might not be the best to run it after we build (as opposed to faster bad formatting feedback), just dropping my 2 cents

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think i prefer keeping things separate as it's not adding on too much compile time (even w/o ccache) but I can't find any negatives about reusing artifacts except it's coupling CIs together more and slower formatting feedback.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with the direction you are proposing

@badumbatish badumbatish changed the title [CIR] [NFC] Fix formatting style in FrontendAction [1/N] [Github] [CIR] Add CI/CD for clang tidy [1/N] Sep 24, 2025
@badumbatish
Copy link
Contributor Author

badumbatish commented Sep 26, 2025

about the hacky ninja -C build_pilot $(ninja -C build_pilot -t targets all | grep IncGen | sed 's/:.*//') clang-tablegen-targets, the reason is that we don't make these IncGen's in CIR be dependencies on mlir-headers via add_dependencies(mlir-headers ...).

For example, in clang/include/clang/CIR/Dialect/IR/CMakeLists.txt, MLIRCIREnumsGen is not added to mlir-headers' dependencies so when we build the mlir-headers target, clang-tidy's reporting compiler error.

# This replicates part of the add_mlir_dialect cmake function from MLIR that
# cannot be used here. This happens because it expects to be run inside MLIR
# directory which is not the case for CIR (and also FIR, both have similar
# workarounds).

# Equivalent to add_mlir_dialect(CIROps cir)
set(LLVM_TARGET_DEFINITIONS CIROps.td)
mlir_tablegen(CIROps.h.inc -gen-op-decls)
mlir_tablegen(CIROps.cpp.inc -gen-op-defs)
mlir_tablegen(CIROpsTypes.h.inc -gen-typedef-decls)
mlir_tablegen(CIROpsTypes.cpp.inc -gen-typedef-defs)
mlir_tablegen(CIROpsDialect.h.inc -gen-dialect-decls)
mlir_tablegen(CIROpsDialect.cpp.inc -gen-dialect-defs)
add_public_tablegen_target(MLIRCIROpsIncGen)
add_dependencies(mlir-headers MLIRCIROpsIncGen)

# Equivalent to add_mlir_doc
add_clang_mlir_doc(CIROps CIROps Dialects/ -gen-op-doc)
add_clang_mlir_doc(CIRAttrs CIRAttrs Dialects/ -gen-attrdef-doc)
add_clang_mlir_doc(CIRTypes CIRTypes Dialects/ -gen-typedef-doc)

# Generate extra headers for custom enum and attrs.
mlir_tablegen(CIROpsEnums.h.inc -gen-enum-decls)
mlir_tablegen(CIROpsEnums.cpp.inc -gen-enum-defs)
mlir_tablegen(CIROpsStructs.h.inc -gen-attrdef-decls)
mlir_tablegen(CIROpsStructs.cpp.inc -gen-attrdef-defs)
mlir_tablegen(CIROpsAttributes.h.inc -gen-attrdef-decls)
mlir_tablegen(CIROpsAttributes.cpp.inc -gen-attrdef-defs)
add_public_tablegen_target(MLIRCIREnumsGen)

clang_tablegen(CIRBuiltinsLowering.inc -gen-cir-builtins-lowering
               SOURCE CIROps.td
               TARGET CIRBuiltinsLowering)

set(LLVM_TARGET_DEFINITIONS CIRTypeConstraints.td)
mlir_tablegen(CIRTypeConstraints.h.inc -gen-type-constraint-decls)
mlir_tablegen(CIRTypeConstraints.cpp.inc -gen-type-constraint-defs)
add_public_tablegen_target(MLIRCIRTypeConstraintsIncGen)
add_dependencies(mlir-headers MLIRCIRTypeConstraintsIncGen)

if we depend on the ninja check-clang-cir job it wouldn't be much of a problem, but if we're aiming for a separate CI/CD completely then we probably should make a few PR to address these, so that we don't end up with the hacky ninja build command

@bcardosolopes
Copy link
Member

the reason is that we don't make these IncGen's in CIR be dependencies on mlir-headers via add_dependencies(mlir-headers ...).

That was a great catch, fixing this dependency sounds like the way to go!

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.

3 participants