-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tf-frontend] remove shape.split_at, shape.cstr_broadcastable, mhlo.c…
…str_reshapable
- Loading branch information
1 parent
1b6a971
commit 435a78b
Showing
10 changed files
with
199 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
frontends/tf-frontend/tf_mlir_ext/transforms/remove_cstr_reshapable.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//===- remove_cstr_reshapable.cc ------------------------------*--- C++ -*-===// | ||
// | ||
// Copyright 2022 ByteDance Ltd. and/or its affiliates. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "mhlo/IR/hlo_ops.h" | ||
#include "mlir/Dialect/Func/IR/FuncOps.h" | ||
#include "mlir/Dialect/Shape/IR/Shape.h" | ||
#include "mlir/Pass/PassManager.h" | ||
#include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
#include "mlir/Transforms/Passes.h" | ||
#include "mlir/include/mlir/IR/IRMapping.h" | ||
#include "llvm/Support/Debug.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
||
#include "tf_mlir_ext/transforms/passes_detail.h" | ||
#include "tf_mlir_ext/transforms/remove_cstr_reshapable.h" | ||
|
||
using namespace mlir; | ||
using namespace llvm; | ||
|
||
#define DEBUG_TYPE "remove_cstr_reshapable" | ||
|
||
namespace { | ||
/// Removal patterns. | ||
class RemoveCstrReshapableOp : public OpRewritePattern<mhlo::CstrReshapableOp> { | ||
public: | ||
using OpRewritePattern::OpRewritePattern; | ||
|
||
LogicalResult matchAndRewrite(mhlo::CstrReshapableOp op, | ||
PatternRewriter &rewriter) const override { | ||
rewriter.replaceOpWithNewOp<shape::ConstWitnessOp>(op.getOperation(), true); | ||
return success(); | ||
} | ||
}; | ||
|
||
/// Removal pass. | ||
class RemoveCstrReshapablePass | ||
: public RemoveCstrReshapableBase<RemoveCstrReshapablePass> { | ||
|
||
void runOnOperation() override { | ||
MLIRContext &ctx = getContext(); | ||
|
||
RewritePatternSet patterns(&ctx); | ||
patterns.add<RemoveCstrReshapableOp>(patterns.getContext()); | ||
|
||
(void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)); | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<OperationPass<func::FuncOp>> | ||
mlir::tfext::createRemoveCstrReshapablePass() { | ||
return std::make_unique<RemoveCstrReshapablePass>(); | ||
} |
37 changes: 37 additions & 0 deletions
37
frontends/tf-frontend/tf_mlir_ext/transforms/remove_cstr_reshapable.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===- remove_cstr_reshapable.h -------------------------------*--- C++ -*-===// | ||
// | ||
// Copyright 2022 ByteDance Ltd. and/or its affiliates. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef TFEXT_TRANSFORMS_REMOVE_CSTR_RESHAPABLE | ||
#define TFEXT_TRANSFORMS_REMOVE_CSTR_RESHAPABLE | ||
|
||
#include <memory> | ||
|
||
#include "mlir/IR/MLIRContext.h" // from @llvm-project | ||
#include "mlir/IR/PatternMatch.h" // from @llvm-project | ||
#include "mlir/Pass/Pass.h" // from @llvm-project | ||
#include "tensorflow/compiler/mlir/tensorflow/ir/tf_executor.h" | ||
|
||
namespace mlir { | ||
namespace tfext { | ||
|
||
// ------------------------------------------- | ||
std::unique_ptr<OperationPass<func::FuncOp>> createRemoveCstrReshapablePass(); | ||
|
||
} // namespace tfext | ||
} // namespace mlir | ||
|
||
#endif // TFEXT_TRANSFORMS_REMOVE_CSTR_RESHAPABLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters