[Mlir-commits] [mlir] [mlir][EmitC] Expand the MemRefToEmitC pass - Lowering `CopyOp` (PR #151206)
Gil Rapaport
llvmlistbot at llvm.org
Thu Aug 7 12:11:41 PDT 2025
================
@@ -55,35 +65,33 @@ struct ConvertMemRefToEmitCPass
return signalPassFailure();
mlir::ModuleOp module = getOperation();
+ llvm::SmallVector<StringRef> requiredHeaders;
module.walk([&](mlir::emitc::CallOpaqueOp callOp) {
- if (callOp.getCallee() != alignedAllocFunctionName &&
- callOp.getCallee() != mallocFunctionName) {
+ StringRef expectedHeader;
+ if (callOp.getCallee() == alignedAllocFunctionName ||
+ callOp.getCallee() == mallocFunctionName)
+ expectedHeader = options.lowerToCpp ? cppStandardLibraryHeader
+ : cStandardLibraryHeader;
+ else if (callOp.getCallee() == memcpyFunctionName)
+ expectedHeader =
+ options.lowerToCpp ? cppStringLibraryHeader : cStringLibraryHeader;
+ else
return mlir::WalkResult::advance();
- }
+ requiredHeaders.push_back(expectedHeader);
+ return mlir::WalkResult::advance();
+ });
+ for (StringRef expectedHeader : requiredHeaders) {
+ bool headerFound = llvm::any_of(*module.getBody(), [&](Operation &op) {
----------------
aniragil wrote:
This scans all module-level ops for each expected header. Can instead scan once in advance to find all available headers, then when scanning `call_opaque`s can skip those whose requested header is already included.
https://github.com/llvm/llvm-project/pull/151206
More information about the Mlir-commits
mailing list