let hasFolder = 1;
let hasVerifier = 1;
+ string llvmInstName = "ExtractValue";
string llvmBuilder = [{
$res = builder.CreateExtractValue($container, extractPosition($position));
}];
+ string mlirBuilder = [{
+ auto *evInst = cast<llvm::ExtractValueInst>(inst);
+ $res = $_builder.create<LLVM::ExtractValueOp>($_location,
+ $container, getPositionFromIndices(evInst->getIndices()));
+ }];
}
//===----------------------------------------------------------------------===//
let hasVerifier = 1;
+ string llvmInstName = "InsertValue";
string llvmBuilder = [{
$res = builder.CreateInsertValue($container, $value,
extractPosition($position));
}];
+ string mlirBuilder = [{
+ auto *ivInst = cast<llvm::InsertValueInst>(inst);
+ $res = $_builder.create<LLVM::InsertValueOp>($_location,
+ $container, $value, getPositionFromIndices(ivInst->getIndices()));
+ }];
}
//===----------------------------------------------------------------------===//
llvm_unreachable("incorrect sync scope identifier");
}
+/// Converts an array of unsigned indices to a signed integer position array.
+static SmallVector<int64_t> getPositionFromIndices(ArrayRef<unsigned> indices) {
+ SmallVector<int64_t> position;
+ llvm::append_range(position, indices);
+ return position;
+}
+
DataLayoutSpecInterface
mlir::translateDataLayout(const llvm::DataLayout &dataLayout,
MLIRContext *context) {
mapValue(inst, res);
return success();
}
- if (inst->getOpcode() == llvm::Instruction::InsertValue) {
- auto *ivInst = cast<llvm::InsertValueInst>(inst);
- Value inserted = processValue(ivInst->getInsertedValueOperand());
- Value aggOperand = processValue(ivInst->getAggregateOperand());
-
- SmallVector<int64_t> indices;
- llvm::append_range(indices, ivInst->getIndices());
- Value res = b.create<InsertValueOp>(loc, aggOperand, inserted, indices);
- mapValue(inst, res);
- return success();
- }
- if (inst->getOpcode() == llvm::Instruction::ExtractValue) {
- auto *evInst = cast<llvm::ExtractValueInst>(inst);
- Value aggOperand = processValue(evInst->getAggregateOperand());
-
- SmallVector<int64_t> indices;
- llvm::append_range(indices, evInst->getIndices());
- Value res = b.create<ExtractValueOp>(loc, aggOperand, indices);
- mapValue(inst, res);
- return success();
- }
if (inst->getOpcode() == llvm::Instruction::ShuffleVector) {
auto *svInst = cast<llvm::ShuffleVectorInst>(inst);
Value vec1 = processValue(svInst->getOperand(0));
ret void
}
-; Insert/ExtractValue
-; CHECK-LABEL: llvm.func @insert_extract_value_struct
-define float @insert_extract_value_struct({{i32},{float, double}}* %p) {
- ; CHECK: %[[C0:.+]] = llvm.mlir.constant(2.000000e+00 : f64)
- ; CHECK: %[[VT:.+]] = llvm.load %{{.+}}
- %t = load {{i32},{float, double}}, {{i32},{float, double}}* %p
- ; CHECK: %[[EV:.+]] = llvm.extractvalue %[[VT]][1, 0] :
- ; CHECK-SAME: !llvm.struct<(struct<(i32)>, struct<(f32, f64)>)>
- %s = extractvalue {{i32},{float, double}} %t, 1, 0
- ; CHECK: %[[IV:.+]] = llvm.insertvalue %[[C0]], %[[VT]][1, 1] :
- ; CHECK-SAME: !llvm.struct<(struct<(i32)>, struct<(f32, f64)>)>
- %r = insertvalue {{i32},{float, double}} %t, double 2.0, 1, 1
- ; CHECK: llvm.store %[[IV]], %{{.+}}
- store {{i32},{float, double}} %r, {{i32},{float, double}}* %p
- ; CHECK: llvm.return %[[EV]]
- ret float %s
-}
-
-; CHECK-LABEL: llvm.func @insert_extract_value_array
-define void @insert_extract_value_array([4 x [4 x i8]] %x1) {
- ; CHECK: %[[C0:.+]] = llvm.mlir.constant(0 : i8)
- ; CHECK: llvm.insertvalue %[[C0]], %{{.+}}[0, 0] : !llvm.array<4 x array<4 x i8>>
- %res1 = insertvalue [4 x [4 x i8 ]] %x1, i8 0, 0, 0
- ; CHECK: llvm.extractvalue %{{.+}}[1] : !llvm.array<4 x array<4 x i8>>
- %res2 = extractvalue [4 x [4 x i8 ]] %x1, 1
- ; CHECK: llvm.extractvalue %{{.+}}[0, 1] : !llvm.array<4 x array<4 x i8>>
- %res3 = extractvalue [4 x [4 x i8 ]] %x1, 0, 1
- ret void
-}
-
; Shufflevector
; CHECK-LABEL: llvm.func @shuffle_vec
define <4 x half> @shuffle_vec(<4 x half>* %arg0, <4 x half>* %arg1) {
; // -----
+; CHECK-LABEL: @insert_extract_value_struct
+; CHECK-SAME: %[[PTR:[a-zA-Z0-9]+]]
+define float @insert_extract_value_struct({{i32},{float, double}}* %ptr) {
+ ; CHECK: %[[C0:.+]] = llvm.mlir.constant(2.000000e+00 : f64)
+ ; CHECK: %[[VT:.+]] = llvm.load %[[PTR]]
+ %1 = load {{i32},{float, double}}, {{i32},{float, double}}* %ptr
+ ; CHECK: %[[EV:.+]] = llvm.extractvalue %[[VT]][1, 0] :
+ ; CHECK-SAME: !llvm.struct<(struct<(i32)>, struct<(f32, f64)>)>
+ %2 = extractvalue {{i32},{float, double}} %1, 1, 0
+ ; CHECK: %[[IV:.+]] = llvm.insertvalue %[[C0]], %[[VT]][1, 1] :
+ ; CHECK-SAME: !llvm.struct<(struct<(i32)>, struct<(f32, f64)>)>
+ %3 = insertvalue {{i32},{float, double}} %1, double 2.0, 1, 1
+ ; CHECK: llvm.store %[[IV]], %[[PTR]]
+ store {{i32},{float, double}} %3, {{i32},{float, double}}* %ptr
+ ; CHECK: llvm.return %[[EV]]
+ ret float %2
+}
+
+; // -----
+
+; CHECK-LABEL: @insert_extract_value_array
+; CHECK-SAME: %[[ARG1:[a-zA-Z0-9]+]]
+define void @insert_extract_value_array([4 x [4 x i8]] %arg1) {
+ ; CHECK: %[[C0:.+]] = llvm.mlir.constant(0 : i8)
+ ; CHECK: llvm.insertvalue %[[C0]], %[[ARG1]][0, 0] : !llvm.array<4 x array<4 x i8>>
+ %1 = insertvalue [4 x [4 x i8 ]] %arg1, i8 0, 0, 0
+ ; CHECK: llvm.extractvalue %[[ARG1]][1] : !llvm.array<4 x array<4 x i8>>
+ %2 = extractvalue [4 x [4 x i8 ]] %arg1, 1
+ ; CHECK: llvm.extractvalue %[[ARG1]][0, 1] : !llvm.array<4 x array<4 x i8>>
+ %3 = extractvalue [4 x [4 x i8 ]] %arg1, 0, 1
+ ret void
+}
+
+; // -----
+
; CHECK-LABEL: @select
; CHECK-SAME: %[[ARG1:[a-zA-Z0-9]+]]
; CHECK-SAME: %[[ARG2:[a-zA-Z0-9]+]]