1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #include "mlir/Conversion/SCFToStandard/SCFToStandard.h" // from @llvm-project 17 #include "mlir/Dialect/SCF/SCF.h" // from @llvm-project 18 #include "tensorflow/compiler/mlir/hlo/include/mlir-hlo/Dialect/mhlo/transforms/rewriters.h" 19 #include "tensorflow/compiler/mlir/tools/kernel_gen/transforms/passes.h" 20 21 namespace mlir { 22 namespace kernel_gen { 23 namespace transforms { 24 namespace { 25 26 #define GEN_PASS_CLASSES 27 #include "tensorflow/compiler/mlir/tools/kernel_gen/transforms/kernel_gen_passes.h.inc" 28 29 struct ParallelLoopsToSequentialPass 30 : public ParallelLoopsToSequentialBase<ParallelLoopsToSequentialPass> { runOnFunctionmlir::kernel_gen::transforms::__anonf4e700190111::ParallelLoopsToSequentialPass31 void runOnFunction() override { 32 mlir::OwningRewritePatternList patterns; 33 mlir::populateLoopToStdConversionPatterns(patterns, &getContext()); 34 35 mlir::ConversionTarget target(getContext()); 36 target.addIllegalOp<mlir::scf::ParallelOp>(); 37 target.addLegalOp<mlir::scf::ForOp, mlir::scf::IfOp>(); 38 target.markUnknownOpDynamicallyLegal([](mlir::Operation*) { return true; }); 39 if (failed(applyPartialConversion(getOperation(), target, 40 std::move(patterns)))) 41 signalPassFailure(); 42 } 43 }; 44 45 } // namespace 46 CreateParallelLoopsToSequential()47std::unique_ptr<mlir::FunctionPass> CreateParallelLoopsToSequential() { 48 return std::make_unique<ParallelLoopsToSequentialPass>(); 49 } 50 51 } // namespace transforms 52 } // namespace kernel_gen 53 } // namespace mlir 54