[Mlir-commits] [mlir] [MLIR][EmitC] Emit private functions as static (PR #78336)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jan 16 11:43:31 PST 2024


https://github.com/AlexDenisov created https://github.com/llvm/llvm-project/pull/78336

None

>From 19fa1100b7d5c33aec5800ad87d7e67ac2514c7e Mon Sep 17 00:00:00 2001
From: AlexDenisov <alex at lowlevelbits.org>
Date: Tue, 16 Jan 2024 20:37:44 +0100
Subject: [PATCH] [MLIR][EmitC] Emit private functions as static

---
 mlir/lib/Target/Cpp/TranslateToCpp.cpp | 3 +++
 mlir/test/Target/Cpp/call.mlir         | 9 ++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

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:[^ ]*]];



More information about the Mlir-commits mailing list