Skip to content

Commit 7e02345

Browse files
committed
Apply last round of reviews
1 parent 5ebd56a commit 7e02345

File tree

3 files changed

+45
-54
lines changed

3 files changed

+45
-54
lines changed

mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,6 @@ class LLVMImportDialectInterface
9898
/// efficient dispatch.
9999
class LLVMImportInterface
100100
: public DialectInterfaceCollection<LLVMImportDialectInterface> {
101-
private:
102-
/// Generate llvm.call_intrinsic when no supporting dialect available.
103-
LogicalResult
104-
convertUnregisteredIntrinsic(OpBuilder &builder, llvm::CallInst *inst,
105-
LLVM::ModuleImport &moduleImport) const;
106-
107101
public:
108102
using Base::Base;
109103

@@ -239,6 +233,11 @@ class LLVMImportInterface
239233
}
240234

241235
private:
236+
/// Generate llvm.call_intrinsic when no supporting dialect available.
237+
static LogicalResult
238+
convertUnregisteredIntrinsic(OpBuilder &builder, llvm::CallInst *inst,
239+
LLVM::ModuleImport &moduleImport);
240+
242241
DenseMap<unsigned, Dialect *> intrinsicToDialect;
243242
DenseMap<unsigned, const LLVMImportDialectInterface *> instructionToDialect;
244243
DenseMap<unsigned, SmallVector<Dialect *, 1>> metadataToDialect;

mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -80,48 +80,6 @@ static LogicalResult convertIntrinsicImpl(OpBuilder &odsBuilder,
8080
return failure();
8181
}
8282

83-
/// Converts the LLVM intrinsic to a generic LLVM intrinsic call using
84-
/// llvm.intrinsic_call. Returns failure otherwise.
85-
static LogicalResult
86-
convertUnregisteredIntrinsicImpl(OpBuilder &odsBuilder, llvm::CallInst *inst,
87-
LLVM::ModuleImport &moduleImport) {
88-
StringRef intrinName = inst->getCalledFunction()->getName();
89-
90-
SmallVector<llvm::Value *> args(inst->args());
91-
ArrayRef<llvm::Value *> llvmOperands(args);
92-
93-
SmallVector<llvm::OperandBundleUse> llvmOpBundles;
94-
llvmOpBundles.reserve(inst->getNumOperandBundles());
95-
for (unsigned i = 0; i < inst->getNumOperandBundles(); ++i)
96-
llvmOpBundles.push_back(inst->getOperandBundleAt(i));
97-
98-
SmallVector<Value> mlirOperands;
99-
SmallVector<NamedAttribute> mlirAttrs;
100-
if (failed(moduleImport.convertIntrinsicArguments(
101-
llvmOperands, llvmOpBundles, false, {}, {}, mlirOperands, mlirAttrs)))
102-
return failure();
103-
104-
Type results = moduleImport.convertType(inst->getType());
105-
auto op = odsBuilder.create<::mlir::LLVM::CallIntrinsicOp>(
106-
moduleImport.translateLoc(inst->getDebugLoc()), results,
107-
StringAttr::get(odsBuilder.getContext(), intrinName),
108-
ValueRange{mlirOperands}, FastmathFlagsAttr{});
109-
110-
moduleImport.setFastmathFlagsAttr(inst, op);
111-
112-
// Update importer tracking of results.
113-
unsigned numRes = op.getNumResults();
114-
if (numRes == 1)
115-
moduleImport.mapValue(inst) = op.getResult(0);
116-
else if (numRes == 0)
117-
moduleImport.mapNoResultOp(inst);
118-
else
119-
return op.emitError(
120-
"expected at most one result from target intrinsic call");
121-
122-
return success();
123-
}
124-
12583
/// Returns the list of LLVM IR metadata kinds that are convertible to MLIR LLVM
12684
/// dialect attributes.
12785
static ArrayRef<unsigned> getSupportedMetadataImpl(llvm::LLVMContext &context) {
@@ -411,8 +369,42 @@ static LogicalResult setIntelReqdSubGroupSizeAttr(Builder &builder,
411369

412370
LogicalResult mlir::LLVMImportInterface::convertUnregisteredIntrinsic(
413371
OpBuilder &builder, llvm::CallInst *inst,
414-
LLVM::ModuleImport &moduleImport) const {
415-
return convertUnregisteredIntrinsicImpl(builder, inst, moduleImport);
372+
LLVM::ModuleImport &moduleImport) {
373+
StringRef intrinName = inst->getCalledFunction()->getName();
374+
375+
SmallVector<llvm::Value *> args(inst->args());
376+
ArrayRef<llvm::Value *> llvmOperands(args);
377+
378+
SmallVector<llvm::OperandBundleUse> llvmOpBundles;
379+
llvmOpBundles.reserve(inst->getNumOperandBundles());
380+
for (unsigned i = 0; i < inst->getNumOperandBundles(); ++i)
381+
llvmOpBundles.push_back(inst->getOperandBundleAt(i));
382+
383+
SmallVector<Value> mlirOperands;
384+
SmallVector<NamedAttribute> mlirAttrs;
385+
if (failed(moduleImport.convertIntrinsicArguments(
386+
llvmOperands, llvmOpBundles, false, {}, {}, mlirOperands, mlirAttrs)))
387+
return failure();
388+
389+
Type results = moduleImport.convertType(inst->getType());
390+
auto op = builder.create<::mlir::LLVM::CallIntrinsicOp>(
391+
moduleImport.translateLoc(inst->getDebugLoc()), results,
392+
StringAttr::get(builder.getContext(), intrinName),
393+
ValueRange{mlirOperands}, FastmathFlagsAttr{});
394+
395+
moduleImport.setFastmathFlagsAttr(inst, op);
396+
397+
// Update importer tracking of results.
398+
unsigned numRes = op.getNumResults();
399+
if (numRes == 1)
400+
moduleImport.mapValue(inst) = op.getResult(0);
401+
else if (numRes == 0)
402+
moduleImport.mapNoResultOp(inst);
403+
else
404+
return op.emitError(
405+
"expected at most one result from target intrinsic call");
406+
407+
return success();
416408
}
417409
namespace {
418410

mlir/test/Target/LLVMIR/Import/intrinsic-unregistered.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ define dso_local void @t0(ptr %a) {
1313
; CHECK: llvm.return
1414
; CHECK: }
1515

16-
; -----
16+
; // -----
1717

1818
declare <8 x i8> @llvm.aarch64.neon.uabd.v8i8(<8 x i8>, <8 x i8>)
1919

@@ -27,7 +27,7 @@ define dso_local <8 x i8> @t1(<8 x i8> %lhs, <8 x i8> %rhs) {
2727
; CHECK: llvm.return %[[R]] : vector<8xi8>
2828
; CHECK: }
2929

30-
; -----
30+
; // -----
3131

3232
declare void @llvm.aarch64.neon.st2.v8i8.p0(<8 x i8>, <8 x i8>, ptr)
3333

@@ -41,7 +41,7 @@ define dso_local void @t2(<8 x i8> %lhs, <8 x i8> %rhs, ptr %a) {
4141
; CHECK: llvm.return
4242
; CHECK: }
4343

44-
; -----
44+
; // -----
4545

4646
declare void @llvm.gcroot(ptr %arg1, ptr %arg2)
4747
define void @gctest() gc "example" {
@@ -53,7 +53,7 @@ define void @gctest() gc "example" {
5353
; CHECK-LABEL: @gctest
5454
; CHECK: llvm.call_intrinsic "llvm.gcroot"({{.*}}, {{.*}}) : (!llvm.ptr, !llvm.ptr) -> !llvm.void
5555

56-
; -----
56+
; // -----
5757

5858
; Test we get the supported version, not the unregistered one.
5959

0 commit comments

Comments
 (0)