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::FixedRegisterOp>();
43 return validateOp->emitError(
"could not determine register");
45 if (!validateOp.getId().has_value())
46 return validateOp.emitError(
"expected ID to be set");
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),
54 rtg::LabelOp::create(builder, loc, rtg::LabelVisibility::global, lbl);
55 validateOp.getValue().replaceAllUsesWith(validateOp.getDefaultValue());
56 validateOp.getValues().replaceAllUsesWith(
57 validateOp.getDefaultUsedValues());
60 return WalkResult::advance();
63 if (result.wasInterrupted())
64 return signalPassFailure();
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
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.