From f46ba096531c3ead97f4d48b07a278d23f905218 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Wed, 9 Sep 2020 06:49:15 -0700 Subject: [PATCH] Integrate LLVM at llvm/llvm-project@4964d75d7078 Updates LLVM usage to match [4964d75d7078](https://github.com/llvm/llvm-project/commit/4964d75d7078) PiperOrigin-RevId: 330713009 --- build_tools/llvm_version.txt | 2 +- .../Dialect/mhlo/transforms/rewriters.h | 4 +-- .../mhlo/transforms/hlo_legalize_to_lhlo.cc | 36 ++++++------------- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/build_tools/llvm_version.txt b/build_tools/llvm_version.txt index c950c9e..6e4961e 100644 --- a/build_tools/llvm_version.txt +++ b/build_tools/llvm_version.txt @@ -1,2 +1,2 @@ -8d9c13f37d2081c11186718ae8b5aef8b507d152 +4964d75d7078b932ac6b17c1990adaa6eada75c1 diff --git a/include/mlir-hlo/Dialect/mhlo/transforms/rewriters.h b/include/mlir-hlo/Dialect/mhlo/transforms/rewriters.h index 6e95152..3d0fc2a 100644 --- a/include/mlir-hlo/Dialect/mhlo/transforms/rewriters.h +++ b/include/mlir-hlo/Dialect/mhlo/transforms/rewriters.h @@ -51,9 +51,9 @@ void PopulateMhloToStdPatterns(OwningRewritePatternList *patterns, // Collection of rewrite patterns for lowering of HLO to LHLO dialect. void populateHLOToLHLOConversionPattern( - MLIRContext *context, BufferAssignmentPlacer *bufferAssignment, - BufferAssignmentTypeConverter *converter, + MLIRContext *context, BufferAssignmentTypeConverter *converter, OwningRewritePatternList *patterns); + // Collection of rewrite patterns for lowering of HLO to Linalg dialect. void populateHLOToLinalgConversionPattern(MLIRContext *context, OwningRewritePatternList *patterns); diff --git a/lib/Dialect/mhlo/transforms/hlo_legalize_to_lhlo.cc b/lib/Dialect/mhlo/transforms/hlo_legalize_to_lhlo.cc index 72af9b7..b3cb8bf 100644 --- a/lib/Dialect/mhlo/transforms/hlo_legalize_to_lhlo.cc +++ b/lib/Dialect/mhlo/transforms/hlo_legalize_to_lhlo.cc @@ -78,7 +78,6 @@ Value InsertDynamicAllocAndDealloc(Location loc, Value result, } Value InsertAlloc(Location loc, OpResult result, - BufferAssignmentPlacer* bufferAssignment, ConversionPatternRewriter* rewriter) { auto result_type = result.getType().dyn_cast(); if (!result_type || !result_type.hasStaticShape()) { @@ -88,8 +87,7 @@ Value InsertAlloc(Location loc, OpResult result, auto memref_type = MemRefType::get(result_type.getShape(), result_type.getElementType()); OpBuilder::InsertionGuard guard(*rewriter); - rewriter->restoreInsertionPoint( - bufferAssignment->computeAllocPosition(result)); + rewriter->setInsertionPoint(result.getDefiningOp()); auto alloc = rewriter->create(loc, memref_type); return alloc; } @@ -111,8 +109,8 @@ class HloToLhloOpConverter : public BaseOpConversion { return failure(); } if (resultType.hasStaticShape()) { - buffer_args.push_back(InsertAlloc(op->getLoc(), result.value(), - this->bufferAssignment, &rewriter)); + buffer_args.push_back( + InsertAlloc(op->getLoc(), result.value(), &rewriter)); } else { SmallVector results_shape; auto shape_type_op = dyn_cast(op); @@ -259,8 +257,7 @@ struct HloToLhloReduceOpConverter : public BaseOpConversion { const auto& original_results = op.getResults(); SmallVector buffer_args(operands.begin(), operands.end()); for (auto result : original_results) { - buffer_args.push_back( - InsertAlloc(loc, result, this->bufferAssignment, &rewriter)); + buffer_args.push_back(InsertAlloc(loc, result, &rewriter)); } auto new_op = rewriter.create(loc, llvm::None, buffer_args, op.getAttrs()); @@ -432,22 +429,12 @@ struct HloLegalizeToLhlo isMemRefType); }); - auto module = getOperation(); - WalkResult result = module.walk([&](FuncOp func) -> WalkResult { - BufferAssignmentPlacer bufferAssignment(func); - OwningRewritePatternList patterns; - populateHLOToLHLOConversionPattern(func.getContext(), &bufferAssignment, - &converter, &patterns); - // FIXME: we likely need to call converter.setResultConversionKind() to - // respect results_escape_function. - populateWithBufferAssignmentOpConversionPatterns< - mlir::ReturnOp, mlir::ReturnOp, lmhlo::CopyOp>( - &context, &bufferAssignment, &converter, &patterns); - return applyPartialConversion(func, target, patterns); - }); - if (result.wasInterrupted()) { + populateHLOToLHLOConversionPattern(&context, &converter, &patterns); + populateWithBufferAssignmentOpConversionPatterns< + mlir::ReturnOp, mlir::ReturnOp, lmhlo::CopyOp>(&context, &converter, + &patterns); + if (failed(applyPartialConversion(getOperation(), target, patterns))) signalPassFailure(); - } } private: @@ -460,8 +447,7 @@ struct HloLegalizeToLhlo } // namespace void populateHLOToLHLOConversionPattern( - MLIRContext* context, BufferAssignmentPlacer* bufferAssignment, - BufferAssignmentTypeConverter* converter, + MLIRContext* context, BufferAssignmentTypeConverter* converter, OwningRewritePatternList* patterns) { // clang-format off patterns->insert< @@ -506,7 +492,7 @@ void populateHLOToLHLOConversionPattern( HloToLhloReturnOpConverter, HloToLhloTensorLoadOpConverter, HloToLhloTensorStoreOpConverter - >(context, bufferAssignment, converter); + >(context, converter); // clang-format on }