[Mlir-commits] [mlir] [mlir] Fix conflict of user defined reserved functions with internal prototypes (PR #123378)
Christian Ulmann
llvmlistbot at llvm.org
Fri Jan 24 01:58:26 PST 2025
================
@@ -45,56 +45,91 @@ static constexpr llvm::StringRef kGenericFree = "_mlir_memref_to_llvm_free";
static constexpr llvm::StringRef kMemRefCopy = "memrefCopy";
/// Generic print function lookupOrCreate helper.
-LLVM::LLVMFuncOp mlir::LLVM::lookupOrCreateFn(Operation *moduleOp,
- StringRef name,
- ArrayRef<Type> paramTypes,
- Type resultType, bool isVarArg) {
+FailureOr<LLVM::LLVMFuncOp>
+mlir::LLVM::lookupOrCreateFn(Operation *moduleOp, StringRef name,
+ ArrayRef<Type> paramTypes, Type resultType,
+ bool isVarArg, bool isReserved) {
assert(moduleOp->hasTrait<OpTrait::SymbolTable>() &&
"expected SymbolTable operation");
auto func = llvm::dyn_cast_or_null<LLVM::LLVMFuncOp>(
SymbolTable::lookupSymbolIn(moduleOp, name));
- if (func)
+ auto funcT = LLVMFunctionType::get(resultType, paramTypes, isVarArg);
+ // Assert the signature of the found function is same as expected
+ if (func) {
+ if (funcT != func.getFunctionType()) {
+ if (isReserved) {
+ func.emitError("redefinition of reserved function '" + name +
+ "' of different type ")
+ .append(func.getFunctionType())
+ .append(" is prohibited");
+ } else {
+ func.emitError("redefinition of function '" + name +
+ "' of different type ")
+ .append(funcT)
+ .append(" is prohibited");
+ }
+ return failure();
+ }
return func;
+ }
OpBuilder b(moduleOp->getRegion(0));
return b.create<LLVM::LLVMFuncOp>(
moduleOp->getLoc(), name,
LLVM::LLVMFunctionType::get(resultType, paramTypes, isVarArg));
}
-LLVM::LLVMFuncOp mlir::LLVM::lookupOrCreatePrintI64Fn(Operation *moduleOp) {
- return lookupOrCreateFn(moduleOp, kPrintI64,
- IntegerType::get(moduleOp->getContext(), 64),
- LLVM::LLVMVoidType::get(moduleOp->getContext()));
+namespace {
+FailureOr<LLVM::LLVMFuncOp> lookupOrCreateReservedFn(Operation *moduleOp,
----------------
Dinistro wrote:
Nit: LLVM settled on using static functions for internal only functions instead of wrapping them into anonymous namespaces. The argument is that this is visible directly from the definition.
https://github.com/llvm/llvm-project/pull/123378
More information about the Mlir-commits
mailing list