|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "circt/Dialect/RTG/IR/RTGOpInterfaces.h" |
| 10 | +#include "circt/Dialect/RTG/Transforms/RTGPasses.h" |
| 11 | +#include "mlir/IR/PatternMatch.h" |
| 12 | + |
| 13 | +namespace circt { |
| 14 | +namespace rtg { |
| 15 | +#define GEN_PASS_DEF_MATERIALIZECONSTRAINTSPASS |
| 16 | +#include "circt/Dialect/RTG/Transforms/RTGPasses.h.inc" |
| 17 | +} // namespace rtg |
| 18 | +} // namespace circt |
| 19 | + |
| 20 | +using namespace mlir; |
| 21 | +using namespace circt; |
| 22 | +using namespace circt::rtg; |
| 23 | + |
| 24 | +//===----------------------------------------------------------------------===// |
| 25 | +// Materialize Constraints Pass |
| 26 | +//===----------------------------------------------------------------------===// |
| 27 | + |
| 28 | +namespace { |
| 29 | +struct MaterializeConstraintsPass |
| 30 | + : public rtg::impl::MaterializeConstraintsPassBase< |
| 31 | + MaterializeConstraintsPass> { |
| 32 | + using Base::Base; |
| 33 | + void runOnOperation() override; |
| 34 | +}; |
| 35 | +} // namespace |
| 36 | + |
| 37 | +void MaterializeConstraintsPass::runOnOperation() { |
| 38 | + getOperation()->walk([&](ImplicitConstraintOpInterface op) { |
| 39 | + if (op.isConstraintMaterialized()) |
| 40 | + return; |
| 41 | + |
| 42 | + OpBuilder builder(op); |
| 43 | + builder.setInsertionPointAfter(op); |
| 44 | + auto *newOp = op.materializeConstraint(builder); |
| 45 | + if (newOp == op) |
| 46 | + return; |
| 47 | + if (newOp && op->getNumResults() > 0) |
| 48 | + op->replaceAllUsesWith(newOp); |
| 49 | + assert(newOp || |
| 50 | + op->getNumResults() == 0 && |
| 51 | + "cannot erase operation without result value replacements"); |
| 52 | + op->erase(); |
| 53 | + }); |
| 54 | +} |
0 commit comments