[mlir][llvm] Use tablegen to import shufflevector from LLVM IR.
authorTobias Gysi <tobias.gysi@nextsilicon.com>
Fri, 14 Oct 2022 11:45:32 +0000 (14:45 +0300)
committerTobias Gysi <tobias.gysi@nextsilicon.com>
Fri, 14 Oct 2022 11:46:05 +0000 (14:46 +0300)
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
mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
mlir/test/Target/LLVMIR/Import/basic.ll
mlir/test/Target/LLVMIR/Import/instructions.ll

index c87be7c..68d59cb 100644 (file)
@@ -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<llvm::ShuffleVectorInst>(inst);
+    SmallVector<int32_t> mask(svInst->getShuffleMask());
+    $res = $_builder.create<LLVM::ShuffleVectorOp>(
+      $_location, $v1, $v2, mask);
+  }];
 }
 
 // Misc operations.
index 3f95afb..163281e 100644 (file)
@@ -993,16 +993,6 @@ LogicalResult Importer::processInstruction(llvm::Instruction *inst) {
     mapValue(inst, res);
     return success();
   }
-  if (inst->getOpcode() == llvm::Instruction::ShuffleVector) {
-    auto *svInst = cast<llvm::ShuffleVectorInst>(inst);
-    Value vec1 = processValue(svInst->getOperand(0));
-    Value vec2 = processValue(svInst->getOperand(1));
-
-    SmallVector<int32_t> mask(svInst->getShuffleMask());
-    Value res = b.create<ShuffleVectorOp>(loc, vec1, vec2, mask);
-    mapValue(inst, res);
-    return success();
-  }
 
   return emitError(loc) << "unknown instruction: " << diag(*inst);
 }
index 6751e41..65c5210 100644 (file)
@@ -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<vector<4xf16>>
-  %val0 = load <4 x half>, <4 x half>* %arg0
-  ; CHECK: %[[V1:.+]] = llvm.load %{{.+}} : !llvm.ptr<vector<4xf16>>
-  %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> <i32 2, i32 3, i32 undef, i32 undef>
-  ret <4 x half> %shuffle
-}
-
 ; Varadic function definition
 %struct.va_list = type { i8* }
 
index b127586..1836f88 100644 (file)
@@ -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> <i32 2, i32 3, i32 undef, i32 undef>
+  ret <4 x half> %1
+}
+
+; // -----
+
 ; CHECK-LABEL: @alloca
 ; CHECK-SAME:  %[[SIZE:[a-zA-Z0-9]+]]
 define double* @alloca(i64 %size) {