[Mlir-commits] [mlir] [MLIR][Intrinsics] Add new MLIR API to automatically resolve overload types (PR #168188)
Rajat Bajpai
llvmlistbot at llvm.org
Wed Nov 26 02:29:11 PST 2025
https://github.com/rajatbajpai updated https://github.com/llvm/llvm-project/pull/168188
>From 73dfc296cfdd6cc31ef885be666ce6d0375a84bc Mon Sep 17 00:00:00 2001
From: rbajpai <rbajpai at nvidia.com>
Date: Thu, 20 Nov 2025 23:13:27 +0530
Subject: [PATCH] [MLIR][Intrinsic] Add createIntrinsicCall with automatic
overload resolution
Add createIntrinsicCall overload that accepts return type and arguments,
automatically resolve overload types rather than requiring manual computation.
Simplifies NVVM_PrefetchOp by removing conditional overload logic.
---
mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td | 7 +------
mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h | 9 +++++++++
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 11 +++++++----
3 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
index 524b9f820f290..993a2648e46dc 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
@@ -3133,12 +3133,7 @@ def NVVM_PrefetchOp : NVVM_Op<"prefetch",
let llvmBuilder = [{
auto [id, args] = NVVM::PrefetchOp::getIntrinsicIDAndArgs(op,
moduleTranslation, builder);
-
- if(op.getTensormap())
- // Overloaded intrinsic
- createIntrinsicCall(builder, id, args, {args[0]->getType()});
- else
- createIntrinsicCall(builder, id, args);
+ createIntrinsicCall(builder, id, builder.getVoidTy(), args);
}];
}
diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
index eb7dfa7637e52..039ac8e2e1911 100644
--- a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
+++ b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
@@ -512,6 +512,15 @@ llvm::CallInst *createIntrinsicCall(llvm::IRBuilderBase &builder,
ArrayRef<llvm::Value *> args = {},
ArrayRef<llvm::Type *> tys = {});
+/// Creates a call to an LLVM IR intrinsic function with the given return type
+/// and arguments. If the intrinsic is overloaded, the function signature will
+/// be automatically resolved based on the provided return type and argument
+/// types.
+llvm::CallInst *createIntrinsicCall(llvm::IRBuilderBase &builder,
+ llvm::Intrinsic::ID intrinsic,
+ llvm::Type *retTy,
+ ArrayRef<llvm::Value *> args);
+
/// Creates a call to a LLVM IR intrinsic defined by LLVM_IntrOpBase. This
/// resolves the overloads, and maps mixed MLIR value and attribute arguments to
/// LLVM values.
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 4107e9c14507f..5ca6c82e06f3b 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -892,10 +892,13 @@ void mlir::LLVM::detail::connectPHINodes(Region ®ion,
llvm::CallInst *mlir::LLVM::detail::createIntrinsicCall(
llvm::IRBuilderBase &builder, llvm::Intrinsic::ID intrinsic,
ArrayRef<llvm::Value *> args, ArrayRef<llvm::Type *> tys) {
- llvm::Module *module = builder.GetInsertBlock()->getModule();
- llvm::Function *fn =
- llvm::Intrinsic::getOrInsertDeclaration(module, intrinsic, tys);
- return builder.CreateCall(fn, args);
+ return builder.CreateIntrinsic(intrinsic, tys, args);
+}
+
+llvm::CallInst *mlir::LLVM::detail::createIntrinsicCall(
+ llvm::IRBuilderBase &builder, llvm::Intrinsic::ID intrinsic,
+ llvm::Type *retTy, ArrayRef<llvm::Value *> args) {
+ return builder.CreateIntrinsic(retTy, intrinsic, args);
}
llvm::CallInst *mlir::LLVM::detail::createIntrinsicCall(
More information about the Mlir-commits
mailing list