From ea9cae03d780de4cc84d4777445ad8de89ebf361 Mon Sep 17 00:00:00 2001 From: Tobias Gysi Date: Fri, 14 Oct 2022 14:45:32 +0300 Subject: [PATCH] [mlir][llvm] Use tablegen to import shufflevector from LLVM IR. The revision imports the shuffle vector operation using tablegen generated builders. Additionally, it moves its test to the instructions.ll test file. Depends on D135874 Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D135880 --- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 7 +++++++ mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp | 10 ---------- mlir/test/Target/LLVMIR/Import/basic.ll | 12 ------------ mlir/test/Target/LLVMIR/Import/instructions.ll | 11 +++++++++++ 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index c87be7c..68d59cb 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -914,9 +914,16 @@ def LLVM_ShuffleVectorOp : LLVM_Op<"shufflevector", let hasVerifier = 1; + string llvmInstName = "ShuffleVector"; string llvmBuilder = [{ $res = builder.CreateShuffleVector($v1, $v2, $mask); }]; + string mlirBuilder = [{ + auto *svInst = cast(inst); + SmallVector mask(svInst->getShuffleMask()); + $res = $_builder.create( + $_location, $v1, $v2, mask); + }]; } // Misc operations. diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp index 3f95afb..163281e 100644 --- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -993,16 +993,6 @@ LogicalResult Importer::processInstruction(llvm::Instruction *inst) { mapValue(inst, res); return success(); } - if (inst->getOpcode() == llvm::Instruction::ShuffleVector) { - auto *svInst = cast(inst); - Value vec1 = processValue(svInst->getOperand(0)); - Value vec2 = processValue(svInst->getOperand(1)); - - SmallVector mask(svInst->getShuffleMask()); - Value res = b.create(loc, vec1, vec2, mask); - mapValue(inst, res); - return success(); - } return emitError(loc) << "unknown instruction: " << diag(*inst); } diff --git a/mlir/test/Target/LLVMIR/Import/basic.ll b/mlir/test/Target/LLVMIR/Import/basic.ll index 6751e41..65c5210 100644 --- a/mlir/test/Target/LLVMIR/Import/basic.ll +++ b/mlir/test/Target/LLVMIR/Import/basic.ll @@ -448,18 +448,6 @@ def: ; pred: bb3, bbs ret void } -; Shufflevector -; CHECK-LABEL: llvm.func @shuffle_vec -define <4 x half> @shuffle_vec(<4 x half>* %arg0, <4 x half>* %arg1) { - ; CHECK: %[[V0:.+]] = llvm.load %{{.+}} : !llvm.ptr> - %val0 = load <4 x half>, <4 x half>* %arg0 - ; CHECK: %[[V1:.+]] = llvm.load %{{.+}} : !llvm.ptr> - %val1 = load <4 x half>, <4 x half>* %arg1 - ; CHECK: llvm.shufflevector %[[V0]], %[[V1]] [2, 3, -1, -1] : vector<4xf16> - %shuffle = shufflevector <4 x half> %val0, <4 x half> %val1, <4 x i32> - ret <4 x half> %shuffle -} - ; Varadic function definition %struct.va_list = type { i8* } diff --git a/mlir/test/Target/LLVMIR/Import/instructions.ll b/mlir/test/Target/LLVMIR/Import/instructions.ll index b127586..1836f88 100644 --- a/mlir/test/Target/LLVMIR/Import/instructions.ll +++ b/mlir/test/Target/LLVMIR/Import/instructions.ll @@ -323,6 +323,17 @@ define void @select(i32 %arg0, i32 %arg1, i1 %cond) { ; // ----- +; CHECK-LABEL: func @shuffle_vec +; CHECK-SAME: %[[ARG1:[a-zA-Z0-9]+]] +; CHECK-SAME: %[[ARG2:[a-zA-Z0-9]+]] +define <4 x half> @shuffle_vec(<4 x half> %arg1, <4 x half> %arg2) { + ; CHECK: llvm.shufflevector %[[ARG1]], %[[ARG2]] [2, 3, -1, -1] : vector<4xf16> + %1 = shufflevector <4 x half> %arg1, <4 x half> %arg2, <4 x i32> + ret <4 x half> %1 +} + +; // ----- + ; CHECK-LABEL: @alloca ; CHECK-SAME: %[[SIZE:[a-zA-Z0-9]+]] define double* @alloca(i64 %size) { -- 2.7.4