Skip to content

[CIR][Lowering] Core dialects: passthrough symbol visibility #1620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

felixdaas
Copy link

Fixes #1619
Fixes #1618

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for your first contributions. Can you please a testcase?

felixdaas added 3 commits May 21, 2025 15:48
… when convertion MLIR core module to LLVM MLIR module + added removal of unnecessary CIR Attr
…orrectly when a cir.func is lowered to a func.func in the indirect lowering (see: https: llvm#1618) 2. the cir.triple attr is converted to the llvm.triple attr correctly when compiling throughmlir (see: llvm#1619)
@felixdaas felixdaas force-pushed the convertCIRTargetTriple branch from adee41c to 280bb46 Compare May 21, 2025 14:15
@felixdaas
Copy link
Author

Hey, I’ve added two test cases that are very similar to the examples I mentioned in the issue description. As expected, the tests failed without the changes and passed with them. This is my first time writing tests with lit/FileCheck, so if you notice anything that could be improved, I’d appreciate your feedback — but they might already be fine as they are. I was also unsure about the naming, so if you have better suggestions, feel free to let me know.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

No problemo, here to help. Thanks for adding the tests - some nits but LGTM once fixed.

…onstraint to compilation test to fix execution on windows and mac
@felixdaas
Copy link
Author

Thanks for the feedback! I've implemented the requested changes. Additionally, I added the -triple x86_64-unknown-linux-gnu option to the %clang_cc1 invocation in the declaration.c test, following the pattern used in other ThroughMLIR tests. I also constrained the compilation test to run only on x86_64 Linux targets, so hopefully both will now pass on Windows and macOS as well.

I wasn't entirely sure which other targets to include. Based on CIRGenModule::getTargetCIRGenInfo(), it might make sense to relax the constraints in the future to support certain aarch64 targets (and possibly spirv64, nvptx, and amdgcn). But for now, I’ve conservatively limited the test to x86_64 Linux only.

@@ -25,6 +25,7 @@
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR_MACOS
// RUN: %clang -target arm64-apple-macosx12.0.0 -fclangir -S -emit-llvm %s -o %t3.ll
// RUN: FileCheck --input-file=%t3.ll %s -check-prefix=LLVM_MACOS
// RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fno-clangir-direct-lowering -c %s -o %t
Copy link
Member

Choose a reason for hiding this comment

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

This path is already tested up there in the other -fno-clangir-direct-lowering invocation, turns out you don't need this test.

Copy link
Author

@felixdaas felixdaas May 23, 2025

Choose a reason for hiding this comment

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

Maybe I'm missing something here but I don't see where this is already tested. I't looks to me like all the other tests using the indirect lowering "only" create the cir,core dialects or llvm ir and never actually compile to an object file (the error occurs when trying to compile the llvm ir to an object file since during the mlir core to llvm ir translation the cir.triple attribute is not converted to the llvm.triple attribute and is thus discarded). If I try to add this line to the driver.c test and run the test locally (on ubuntu) with the current code on llvm/clangir:main I get the error mentioned in issue #1619

error: unable to create target: 'No available targets are compatible with triple ""'

If I run the test locally with the update code of this PR the test passes, so it seems to me like it does add value.

Copy link
Member

Choose a reason for hiding this comment

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

True, thanks for clarifying! One last change, use -o %t.o

@bcardosolopes bcardosolopes changed the title Pass through cir.func attributes + convert cir.triple attribute when lowering throughMLIR [CIR][Lowering] Core dialects: passthrough symbol visibility May 23, 2025
@felixdaas
Copy link
Author

(and btw @bcardosolopes thanks for all the help and info on this PR and sorry about missing your suggestion about the space identation earlier)

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

Thanks for your patience, one last round of nits and LGTM!

int declaration(int x);
int declaration_test() {
return declaration(15);
}
Copy link
Member

Choose a reason for hiding this comment

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

One more nit: code style requires all files to terminate with a newline,

@@ -25,6 +25,7 @@
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR_MACOS
// RUN: %clang -target arm64-apple-macosx12.0.0 -fclangir -S -emit-llvm %s -o %t3.ll
// RUN: FileCheck --input-file=%t3.ll %s -check-prefix=LLVM_MACOS
// RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fno-clangir-direct-lowering -c %s -o %t
Copy link
Member

Choose a reason for hiding this comment

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

True, thanks for clarifying! One last change, use -o %t.o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants