Skip to content

Revert "[MLIR][LLVMIR] Import unregistered intrinsics via llvm.intrinsic_call" #128973

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

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,9 @@ class LLVMImportInterface
LogicalResult convertIntrinsic(OpBuilder &builder, llvm::CallInst *inst,
LLVM::ModuleImport &moduleImport) const {
// Lookup the dialect interface for the given intrinsic.
// Verify the intrinsic identifier maps to an actual intrinsic.
llvm::Intrinsic::ID intrinId = inst->getIntrinsicID();
assert(intrinId != llvm::Intrinsic::not_intrinsic);

// First lookup the intrinsic across different dialects for known
// supported conversions, examples include arm-neon, nvm-sve, etc.
Dialect *dialect = intrinsicToDialect.lookup(intrinId);

// No specialized (supported) intrinsics, attempt to generate a generic
// version via llvm.call_intrinsic (if available).
Dialect *dialect = intrinsicToDialect.lookup(inst->getIntrinsicID());
if (!dialect)
return convertUnregisteredIntrinsic(builder, inst, moduleImport);
return failure();

// Dispatch the conversion to the dialect interface.
const LLVMImportDialectInterface *iface = getInterfaceFor(dialect);
Expand Down Expand Up @@ -233,11 +224,6 @@ class LLVMImportInterface
}

private:
/// Generate llvm.call_intrinsic when no supporting dialect available.
static LogicalResult
convertUnregisteredIntrinsic(OpBuilder &builder, llvm::CallInst *inst,
LLVM::ModuleImport &moduleImport);

DenseMap<unsigned, Dialect *> intrinsicToDialect;
DenseMap<unsigned, const LLVMImportDialectInterface *> instructionToDialect;
DenseMap<unsigned, SmallVector<Dialect *, 1>> metadataToDialect;
Expand Down
39 changes: 0 additions & 39 deletions mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,45 +367,6 @@ static LogicalResult setIntelReqdSubGroupSizeAttr(Builder &builder,
return success();
}

LogicalResult mlir::LLVMImportInterface::convertUnregisteredIntrinsic(
OpBuilder &builder, llvm::CallInst *inst,
LLVM::ModuleImport &moduleImport) {
StringRef intrinName = inst->getCalledFunction()->getName();

SmallVector<llvm::Value *> args(inst->args());
ArrayRef<llvm::Value *> llvmOperands(args);

SmallVector<llvm::OperandBundleUse> llvmOpBundles;
llvmOpBundles.reserve(inst->getNumOperandBundles());
for (unsigned i = 0; i < inst->getNumOperandBundles(); ++i)
llvmOpBundles.push_back(inst->getOperandBundleAt(i));

SmallVector<Value> mlirOperands;
SmallVector<NamedAttribute> mlirAttrs;
if (failed(moduleImport.convertIntrinsicArguments(
llvmOperands, llvmOpBundles, false, {}, {}, mlirOperands, mlirAttrs)))
return failure();

Type results = moduleImport.convertType(inst->getType());
auto op = builder.create<::mlir::LLVM::CallIntrinsicOp>(
moduleImport.translateLoc(inst->getDebugLoc()), results,
StringAttr::get(builder.getContext(), intrinName),
ValueRange{mlirOperands}, FastmathFlagsAttr{});

moduleImport.setFastmathFlagsAttr(inst, op);

// Update importer tracking of results.
unsigned numRes = op.getNumResults();
if (numRes == 1)
moduleImport.mapValue(inst) = op.getResult(0);
else if (numRes == 0)
moduleImport.mapNoResultOp(inst);
else
return op.emitError(
"expected at most one result from target intrinsic call");

return success();
}
namespace {

/// Implementation of the dialect interface that converts operations belonging
Expand Down
12 changes: 12 additions & 0 deletions mlir/test/Target/LLVMIR/Import/import-failure.ll
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ bb1:

; // -----

declare void @llvm.gcroot(ptr %arg1, ptr %arg2)

; CHECK: <unknown>
; CHECK-SAME: error: unhandled intrinsic: call void @llvm.gcroot(ptr %arg1, ptr null)
define void @unhandled_intrinsic() gc "example" {
%arg1 = alloca ptr
call void @llvm.gcroot(ptr %arg1, ptr null)
ret void
}

; // -----

; Check that debug intrinsics with an unsupported argument are dropped.

declare void @llvm.dbg.value(metadata, metadata, metadata)
Expand Down
68 changes: 0 additions & 68 deletions mlir/test/Target/LLVMIR/Import/intrinsic-unregistered.ll

This file was deleted.

Loading