Loading [MathJax]/extensions/tex2jax.js
CIRCT 22.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LowerValidateToLabelsPass.cpp
Go to the documentation of this file.
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
12
13namespace circt {
14namespace rtg {
15#define GEN_PASS_DEF_LOWERVALIDATETOLABELSPASS
16#include "circt/Dialect/RTG/Transforms/RTGPasses.h.inc"
17} // namespace rtg
18} // namespace circt
19
20using namespace mlir;
21using namespace circt;
22
23//===----------------------------------------------------------------------===//
24// Lower Validate To Labels Pass
25//===----------------------------------------------------------------------===//
26
27namespace {
28struct LowerValidateToLabelsPass
29 : public rtg::impl::LowerValidateToLabelsPassBase<
30 LowerValidateToLabelsPass> {
31 void runOnOperation() override;
32};
33} // namespace
34
35void LowerValidateToLabelsPass::runOnOperation() {
36 auto *rootOp = getOperation();
37 UnusedOpPruner pruner;
38
39 auto result = rootOp->walk([&](rtg::ValidateOp validateOp) -> WalkResult {
40 Location loc = validateOp.getLoc();
41 auto regOp = validateOp.getRef().getDefiningOp<rtg::FixedRegisterOp>();
42 if (!regOp)
43 return validateOp->emitError("could not determine register");
44
45 if (!validateOp.getId().has_value())
46 return validateOp.emitError("expected ID to be set");
47
48 OpBuilder builder(validateOp);
49 auto intrinsicLabel = validateOp.getRef().getType().getIntrinsicLabel(
50 regOp.getReg(), validateOp.getId().value());
51 Value lbl = rtg::LabelDeclOp::create(
52 builder, loc, StringAttr::get(&getContext(), intrinsicLabel),
53 ValueRange());
54 rtg::LabelOp::create(builder, loc, rtg::LabelVisibility::global, lbl);
55 validateOp.getValue().replaceAllUsesWith(validateOp.getDefaultValue());
56 validateOp.getValues().replaceAllUsesWith(
57 validateOp.getDefaultUsedValues());
58
59 pruner.eraseNow(validateOp);
60 return WalkResult::advance();
61 });
62
63 if (result.wasInterrupted())
64 return signalPassFailure();
65
66 pruner.eraseNow();
67}
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition rtg.py:1
Utility that tracks operations that have potentially become unused and allows them to be cleaned up a...
void eraseNow(Operation *op)
Erase an operation immediately, and remove it from the set of ops to be removed later.