Updates LLVM usage to match
[91e7a1713332](https://github.com/llvm/llvm-project/commit/91e7a1713332)

PiperOrigin-RevId: 355702100
This commit is contained in:
A. Unique TensorFlower 2021-02-04 13:41:18 -08:00 committed by TensorFlow MLIR Team
parent 60e1b6882c
commit 99bc05f2e4
6 changed files with 51 additions and 60 deletions

View File

@ -15,9 +15,9 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
LLVM_COMMIT = "56fcd4ea8dafecbd71ff6eda7db6407d66505c93" LLVM_COMMIT = "91e7a17133324ac4beaf6ed45c170436c2d91c98"
LLVM_SHA256 = "71537fa919251e225c34a820bd7ef3d0a295db58c5c5f07032323d45f4b318e7" LLVM_SHA256 = "07ef834c47337dc7b38c765693a3b5a1835aac2f716fd9a06c374a71722c20de"
LLVM_BAZEL_TAG = "llvm-project-{commit}".format(commit = LLVM_COMMIT) LLVM_BAZEL_TAG = "llvm-project-{commit}".format(commit = LLVM_COMMIT)

View File

@ -1,2 +1,2 @@
56fcd4ea8dafecbd71ff6eda7db6407d66505c93 91e7a17133324ac4beaf6ed45c170436c2d91c98

View File

@ -1051,19 +1051,18 @@ class SliceConverter : public OpConversionPattern<lmhlo::SliceOp> {
return failure(); return failure();
} }
SmallVector<Value, 3> ranges; SmallVector<OpFoldResult, 3> offsets, sizes, strides;
for (int i = 0, e = arg_type.getRank(); i < e; ++i) { for (int i = 0, e = arg_type.getRank(); i < e; ++i) {
Value start_index = rewriter.create<ConstantIndexOp>( offsets.push_back(rewriter.getI64IntegerAttr(
loc, slice_op.start_indices().getValue<int64_t>(i)); slice_op.start_indices().getValue<int64_t>(i)));
Value limit_index = rewriter.create<ConstantIndexOp>( sizes.push_back(rewriter.getI64IntegerAttr(
loc, slice_op.limit_indices().getValue<int64_t>(i)); slice_op.limit_indices().getValue<int64_t>(i) -
Value stride = rewriter.create<ConstantIndexOp>( slice_op.start_indices().getValue<int64_t>(i)));
loc, slice_op.strides().getValue<int64_t>(i)); strides.push_back(
ranges.push_back(rewriter.create<linalg::RangeOp>(loc, start_index, rewriter.getI64IntegerAttr(slice_op.strides().getValue<int64_t>(i)));
limit_index, stride));
} }
auto linalg_slice = auto linalg_slice = rewriter.create<SubViewOp>(loc, slice_op.getOperand(0),
rewriter.create<linalg::SliceOp>(loc, slice_op.getOperand(0), ranges); offsets, sizes, strides);
rewriter.create<linalg::CopyOp>(loc, linalg_slice, slice_op.getOperand(1)); rewriter.create<linalg::CopyOp>(loc, linalg_slice, slice_op.getOperand(1));
rewriter.eraseOp(slice_op); rewriter.eraseOp(slice_op);
return success(); return success();

View File

@ -119,32 +119,32 @@ class LhloReduceToGPULaunchConverter : public OpConversionPattern<ReduceOp> {
// Compute memrefs for the value to reduce. This makes it easier to just // Compute memrefs for the value to reduce. This makes it easier to just
// inline the body. // inline the body.
auto output = *reduce_op.out().begin(); auto output = *reduce_op.out().begin();
// TODO(herhut) Move this to the SliceOp builder.
auto resType = MemRefType::get( auto resType = MemRefType::get(
llvm::None, output.getType().cast<MemRefType>().getElementType(), llvm::None, getElementTypeOrSelf(output.getType()),
makeStridedLinearLayoutMap(llvm::None, makeStridedLinearLayoutMap(llvm::None,
MemRefType::getDynamicStrideOrOffset(), MemRefType::getDynamicStrideOrOffset(),
rewriter.getContext())); rewriter.getContext()));
auto accumulator = rewriter.create<mlir::linalg::SliceOp>( OpFoldResult offset = launch_op.getThreadIds().x;
loc, resType, output, ArrayRef<Value>{launch_op.getThreadIds().x}); auto oneAttr = rewriter.getI64IntegerAttr(1);
OpFoldResult size = oneAttr;
OpFoldResult stride = oneAttr;
auto accumulator = rewriter.create<SubViewOp>(loc, resType, output,
offset, size, stride);
llvm::SmallVector<Value, 4> indexings; llvm::SmallVector<Value, 4> indexings;
auto input_buffer = *reduce_op.operands().begin(); auto input_buffer = *reduce_op.operands().begin();
auto input_type = input_buffer.getType().cast<MemRefType>(); auto input_type_rank =
for (int64_t dim = 0; dim < input_type.getRank(); ++dim) { input_buffer.getType().cast<MemRefType>().getRank();
indexings.push_back(dim == reducing_dimension
? loop.getInductionVar() Value input = *reduce_op.operand_begin();
: launch_op.getThreadIds().x); SmallVector<OpFoldResult> offsets = llvm::to_vector<4>(llvm::map_range(
} llvm::seq<int>(0, input_type_rank), [&](int dim) -> OpFoldResult {
// TODO(herhut) Move this to the SliceOp builder. return dim == reducing_dimension ? loop.getInductionVar()
auto input = *reduce_op.operand_begin(); : launch_op.getThreadIds().x;
auto rhs = rewriter.create<mlir::linalg::SliceOp>( }));
loc, SmallVector<OpFoldResult> sizes(input_type_rank, oneAttr);
MemRefType::get( SmallVector<OpFoldResult> strides(input_type_rank, oneAttr);
llvm::None, input_type.getElementType(), auto rhs = rewriter.create<SubViewOp>(loc, accumulator.getType(), input,
makeStridedLinearLayoutMap(llvm::None, offsets, sizes, strides);
MemRefType::getDynamicStrideOrOffset(),
rewriter.getContext())),
input, indexings);
// Now copy over the actual body of the reduction, leaving out the // Now copy over the actual body of the reduction, leaving out the
// terminator. // terminator.

View File

@ -13,6 +13,8 @@ func @reduce(%arg: memref<100x10xf32>,
return return
} }
// CHECK-DAG: #[[$MAP:.*]] = affine_map<()[s0] -> (s0)>
// CHECK: func @reduce(%[[ARG0:.*]]: memref<100x10xf32>, %[[ARG1:.*]]: memref<f32>, %[[ARG2:.*]]: memref<100xf32>) { // CHECK: func @reduce(%[[ARG0:.*]]: memref<100x10xf32>, %[[ARG1:.*]]: memref<f32>, %[[ARG2:.*]]: memref<100xf32>) {
// CHECK-DAG: %[[C100:.*]] = constant 100 : index // CHECK-DAG: %[[C100:.*]] = constant 100 : index
// CHECK-DAG: %[[C1:.*]] = constant 1 : index // CHECK-DAG: %[[C1:.*]] = constant 1 : index
@ -23,12 +25,10 @@ func @reduce(%arg: memref<100x10xf32>,
// CHECK-DAG: %[[UB:.*]] = constant 10 : index // CHECK-DAG: %[[UB:.*]] = constant 10 : index
// CHECK-DAG: %[[STEP:.*]] = constant 1 : index // CHECK-DAG: %[[STEP:.*]] = constant 1 : index
// CHECK: scf.for %[[IDX1:.*]] = %[[LB]] to %[[UB]] step %[[STEP]] { // CHECK: scf.for %[[IDX1:.*]] = %[[LB]] to %[[UB]] step %[[STEP]] {
// CHECK: %[[LHS:.*]] = linalg.slice %[[ARG2]][%[[IDX]]] : memref<100xf32>, index, memref<f32, #map> // CHECK: %[[LHS:.*]] = subview %[[ARG2]][%[[IDX]]] [1] [1] : memref<100xf32> to memref<f32, #[[$MAP]]>
// CHECK: %[[RHS:.*]] = linalg.slice %[[ARG0]][%[[IDX]], %[[IDX1]]] : memref<100x10xf32>, index, index, memref<f32, #map> // CHECK: %[[RHS:.*]] = subview %[[ARG0]][%[[IDX]], %[[IDX1]]] [1, 1] [1, 1] : memref<100x10xf32> to memref<f32, #[[$MAP]]>
// CHECK: "lmhlo.add"(%[[LHS]], %[[RHS]], %[[LHS]]) : (memref<f32, {{.*}}>, memref<f32, {{.*}}>, memref<f32, {{.*}}>) -> () // CHECK: "lmhlo.add"(%[[LHS]], %[[RHS]], %[[LHS]]) : (memref<f32, {{.*}}>, memref<f32, {{.*}}>, memref<f32, {{.*}}>) -> ()
// CHECK: } // CHECK: }
// CHECK: gpu.terminator // CHECK: gpu.terminator
// CHECK: } // CHECK: }
// CHECK: return // CHECK: return
// CHECK: }
// CHECK: }

View File

@ -745,15 +745,7 @@ func @slice(%operand: memref<?x?xf32>, %result: memref<?x?xf32>) {
} : (memref<?x?xf32>, memref<?x?xf32>) -> () } : (memref<?x?xf32>, memref<?x?xf32>) -> ()
return return
} }
// CHECK: %[[L0:.*]] = constant 0 : index // CHECK: %[[RESULT:.*]] = subview %[[IN]][0, 1] [2, 2] [1, 1] : memref<?x?xf32> to memref<2x2xf32, #{{.*}}>
// CHECK: %[[L2:.*]] = constant 2 : index
// CHECK: %[[L1:.*]] = constant 1 : index
// CHECK: %[[LHS:.*]] = linalg.range %[[L0]] : %[[L2]] : %[[L1]]
// CHECK: %[[R0:.*]] = constant 1 : index
// CHECK: %[[R2:.*]] = constant 3 : index
// CHECK: %[[R1:.*]] = constant 1 : index
// CHECK: %[[RHS:.*]] = linalg.range %[[R0]] : %[[R2]] : %[[R1]]
// CHECK: %[[RESULT:.*]] = linalg.slice %[[IN]][%[[LHS]], %[[RHS]]]
// CHECK: linalg.copy(%[[RESULT]], %[[OUT]]) // CHECK: linalg.copy(%[[RESULT]], %[[OUT]])
// ----- // -----