-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
[MLIR][EmitC] Emit private functions as static #78336
Conversation
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-emitc Author: AlexDenisov (AlexDenisov) ChangesFull diff: https://github.com/llvm/llvm-project/pull/78336.diff 2 Files Affected:
diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index c32cb03caf9db69..e0baa24f143d8b5 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -745,6 +745,9 @@ static LogicalResult printOperation(CppEmitter &emitter,
CppEmitter::Scope scope(emitter);
raw_indented_ostream &os = emitter.ostream();
+ if (functionOp.isPrivate()) {
+ os << "static ";
+ }
if (failed(emitter.emitTypes(functionOp.getLoc(),
functionOp.getFunctionType().getResults())))
return failure();
diff --git a/mlir/test/Target/Cpp/call.mlir b/mlir/test/Target/Cpp/call.mlir
index 2bcdc87205184fb..09dd7642bb680aa 100644
--- a/mlir/test/Target/Cpp/call.mlir
+++ b/mlir/test/Target/Cpp/call.mlir
@@ -1,16 +1,16 @@
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s -check-prefix=CPP-DEFAULT
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck %s -check-prefix=CPP-DECLTOP
-func.func @emitc_call_opaque() {
+func.func private @emitc_call_opaque() {
%0 = emitc.call_opaque "func_a" () : () -> i32
%1 = emitc.call_opaque "func_b" () : () -> i32
return
}
-// CPP-DEFAULT: void emitc_call_opaque() {
+// CPP-DEFAULT: static void emitc_call_opaque() {
// CPP-DEFAULT-NEXT: int32_t [[V0:[^ ]*]] = func_a();
// CPP-DEFAULT-NEXT: int32_t [[V1:[^ ]*]] = func_b();
-// CPP-DECLTOP: void emitc_call_opaque() {
+// CPP-DECLTOP: static void emitc_call_opaque() {
// CPP-DECLTOP-NEXT: int32_t [[V0:[^ ]*]];
// CPP-DECLTOP-NEXT: int32_t [[V1:[^ ]*]];
// CPP-DECLTOP-NEXT: [[V0:]] = func_a();
@@ -22,12 +22,15 @@ func.func @emitc_call_opaque_two_results() {
%1:2 = emitc.call_opaque "two_results" () : () -> (i32, i32)
return
}
+
+// CPP-DEFAULT-NOT: static
// CPP-DEFAULT: void emitc_call_opaque_two_results() {
// CPP-DEFAULT-NEXT: size_t [[V1:[^ ]*]] = 0;
// CPP-DEFAULT-NEXT: int32_t [[V2:[^ ]*]];
// CPP-DEFAULT-NEXT: int32_t [[V3:[^ ]*]];
// CPP-DEFAULT-NEXT: std::tie([[V2]], [[V3]]) = two_results();
+// CPP-DECLTOP-NOT: static
// CPP-DECLTOP: void emitc_call_opaque_two_results() {
// CPP-DECLTOP-NEXT: size_t [[V1:[^ ]*]];
// CPP-DECLTOP-NEXT: int32_t [[V2:[^ ]*]];
|
Thanks for the pull-request @AlexDenisov. I am not sure if the concept of an |
I agree that it doesn't map directly, OTOH I'm seeing CPP target as an approximation. Would it also make sense to get this functionality in and then migrate to |
Why isn't private mapping to static for functions? |
I guess the mapping is not one-to-one: |
Yeah, that is what I had in mind. I think adding an
I already restarted my work on an
After several discussions there seemed to be kind of conses that one should rather extend the dialect and do what is necessary within conversions instead of extending support in the emitter for non-EmitC functions. Extending |
Totally fine with me, no pressure 🙌
Are these happening in the public space somewhere? I have some questions/suggestions about function prototypes, but would like to discuss them before submitting any patches as the implementation is a bit more involved. |
Some of these were in person at last year's C4ML and EuroLLVM, others via email, discord or discourse and even in pull requests. However, I'd love to move the entire discussion to discourse! So please feel free to open new topics with your questions and suggestions at https://discourse.llvm.org/c/mlir/31 and give me and my colleague @simon-camp a ping. If the questions/suggestions are not directly related to upstream, https://github.com/iml130/mlir-emitc/issues can be an alternative place. |
Implemented here UPD: fixed link |
No description provided.