Skip to content

Commit 73dfc29

Browse files
committed
[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.
1 parent cc5185b commit 73dfc29

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3133,12 +3133,7 @@ def NVVM_PrefetchOp : NVVM_Op<"prefetch",
31333133
let llvmBuilder = [{
31343134
auto [id, args] = NVVM::PrefetchOp::getIntrinsicIDAndArgs(op,
31353135
moduleTranslation, builder);
3136-
3137-
if(op.getTensormap())
3138-
// Overloaded intrinsic
3139-
createIntrinsicCall(builder, id, args, {args[0]->getType()});
3140-
else
3141-
createIntrinsicCall(builder, id, args);
3136+
createIntrinsicCall(builder, id, builder.getVoidTy(), args);
31423137
}];
31433138
}
31443139

mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,15 @@ llvm::CallInst *createIntrinsicCall(llvm::IRBuilderBase &builder,
512512
ArrayRef<llvm::Value *> args = {},
513513
ArrayRef<llvm::Type *> tys = {});
514514

515+
/// Creates a call to an LLVM IR intrinsic function with the given return type
516+
/// and arguments. If the intrinsic is overloaded, the function signature will
517+
/// be automatically resolved based on the provided return type and argument
518+
/// types.
519+
llvm::CallInst *createIntrinsicCall(llvm::IRBuilderBase &builder,
520+
llvm::Intrinsic::ID intrinsic,
521+
llvm::Type *retTy,
522+
ArrayRef<llvm::Value *> args);
523+
515524
/// Creates a call to a LLVM IR intrinsic defined by LLVM_IntrOpBase. This
516525
/// resolves the overloads, and maps mixed MLIR value and attribute arguments to
517526
/// LLVM values.

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,10 +892,13 @@ void mlir::LLVM::detail::connectPHINodes(Region &region,
892892
llvm::CallInst *mlir::LLVM::detail::createIntrinsicCall(
893893
llvm::IRBuilderBase &builder, llvm::Intrinsic::ID intrinsic,
894894
ArrayRef<llvm::Value *> args, ArrayRef<llvm::Type *> tys) {
895-
llvm::Module *module = builder.GetInsertBlock()->getModule();
896-
llvm::Function *fn =
897-
llvm::Intrinsic::getOrInsertDeclaration(module, intrinsic, tys);
898-
return builder.CreateCall(fn, args);
895+
return builder.CreateIntrinsic(intrinsic, tys, args);
896+
}
897+
898+
llvm::CallInst *mlir::LLVM::detail::createIntrinsicCall(
899+
llvm::IRBuilderBase &builder, llvm::Intrinsic::ID intrinsic,
900+
llvm::Type *retTy, ArrayRef<llvm::Value *> args) {
901+
return builder.CreateIntrinsic(retTy, intrinsic, args);
899902
}
900903

901904
llvm::CallInst *mlir::LLVM::detail::createIntrinsicCall(

0 commit comments

Comments
 (0)