[Mlir-commits] [mlir] [mlir][EmitC]Expand the MemRefToEmitC pass - Lowering `AllocOp` (PR #148257)

Gil Rapaport llvmlistbot at llvm.org
Wed Jul 23 03:53:11 PDT 2025


================
@@ -30,6 +30,16 @@ struct ConvertMemRefToEmitCPass
     : public impl::ConvertMemRefToEmitCBase<ConvertMemRefToEmitCPass> {
   void runOnOperation() override {
     TypeConverter converter;
+    mlir::ModuleOp module = getOperation();
+    module.walk([&](mlir::Operation *op) {
+      if (llvm::isa<mlir::memref::AllocOp, mlir::memref::CopyOp>(op)) {
+        OpBuilder builder(module.getBody(), module.getBody()->begin());
+        builder.create<emitc::IncludeOp>(module.getLoc(),
+                                         builder.getStringAttr("stdlib.h"));
----------------
aniragil wrote:

IIUC C-style `#include "stdlib.h"` works for C++, only difference is that functions are placed in the global namespace rather `std`.
I'm +1 on adding a flag, not sure it should be part of this commit as it should enforce unrelated C++ restrictions, e.g. multiple return values and tensor types. Can we leave a TODO here for when we have such a flag?

https://github.com/llvm/llvm-project/pull/148257


More information about the Mlir-commits mailing list