-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] do not inject malloc/free in to-LLVM translation #73224
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
Conversation
In the early days of MLIR-to-LLVM IR translation, it had to forcefully inject declarations of `malloc` and `free` functions as then-standard (now `memref`) dialect ops were unconditionally lowering to libc calls. This is no longer the case. Even when they do lower to libc calls, the signatures of those methods are injected at lowering since calls must target declared functions in valid IR. Don't inject those declarations anymore.
@llvm/pr-subscribers-mlir-llvm @llvm/pr-subscribers-mlir Author: Oleksandr "Alex" Zinenko (ftynse) ChangesIn the early days of MLIR-to-LLVM IR translation, it had to forcefully inject declarations of Full diff: https://github.com/llvm/llvm-project/pull/73224.diff 2 Files Affected:
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index ef1c8c21d54b08f..c5df0c7ec181a7c 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1320,14 +1320,6 @@ prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext,
m->getDiscardableAttr(LLVM::LLVMDialect::getTargetTripleAttrName()))
llvmModule->setTargetTriple(cast<StringAttr>(targetTripleAttr).getValue());
- // Inject declarations for `malloc` and `free` functions that can be used in
- // memref allocation/deallocation coming from standard ops lowering.
- llvm::IRBuilder<> builder(llvmContext);
- llvmModule->getOrInsertFunction("malloc", builder.getInt8PtrTy(),
- builder.getInt64Ty());
- llvmModule->getOrInsertFunction("free", builder.getVoidTy(),
- builder.getInt8PtrTy());
-
return llvmModule;
}
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index 73fcee0dd2e70bd..ab8506ff163efe6 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -179,7 +179,7 @@ llvm.mlir.global internal constant @sectionvar("teststring") {section = ".mysec
// CHECK: declare ptr @malloc(i64)
llvm.func @malloc(i64) -> !llvm.ptr
// CHECK: declare void @free(ptr)
-
+llvm.func @free(!llvm.ptr)
//
// Basic functionality: function and block conversion, function calls,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There seems to a failure in main now:
|
Looks like a clash with another change that added that test. |
In the early days of MLIR-to-LLVM IR translation, it had to forcefully inject declarations of
malloc
andfree
functions as then-standard (nowmemref
) dialect ops were unconditionally lowering to libc calls. This is no longer the case. Even when they do lower to libc calls, the signatures of those methods are injected at lowering since calls must target declared functions in valid IR. Don't inject those declarations anymore.