15#define GEN_PASS_DEF_LOWERVALIDATETOLABELSPASS
16#include "circt/Dialect/RTG/Transforms/RTGPasses.h.inc"
28struct LowerValidateToLabelsPass
29 :
public rtg::impl::LowerValidateToLabelsPassBase<
30 LowerValidateToLabelsPass> {
31 void runOnOperation()
override;
35void LowerValidateToLabelsPass::runOnOperation() {
36 auto *rootOp = getOperation();
39 auto result = rootOp->walk([&](rtg::ValidateOp validateOp) -> WalkResult {
40 Location loc = validateOp.getLoc();
41 auto regOp = validateOp.getRef().getDefiningOp<rtg::ConstantOp>();
43 return validateOp->emitError(
44 "could not determine register defining operation");
46 auto reg = dyn_cast<rtg::RegisterAttrInterface>(regOp.getValue());
48 return validateOp->emitError(
"could not determine register");
50 if (!validateOp.getId().has_value())
51 return validateOp.emitError(
"expected ID to be set");
53 OpBuilder builder(validateOp);
54 auto intrinsicLabel = validateOp.getRef().getType().getIntrinsicLabel(
55 reg, validateOp.getId().value());
56 Value lbl = rtg::LabelDeclOp::create(
57 builder, loc, StringAttr::get(&getContext(), intrinsicLabel),
59 rtg::LabelOp::create(builder, loc, rtg::LabelVisibility::global, lbl);
60 validateOp.getValue().replaceAllUsesWith(validateOp.getDefaultValue());
61 validateOp.getValues().replaceAllUsesWith(
62 validateOp.getDefaultUsedValues());
65 return WalkResult::advance();
68 if (result.wasInterrupted())
69 return signalPassFailure();
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
reg(value, clock, reset=None, reset_value=None, name=None, sym_name=None)
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.