Skip to content

Commit

Permalink
Merge branch 'main' into teqdruid/pycde-publish
Browse files Browse the repository at this point in the history
  • Loading branch information
teqdruid committed May 18, 2024
2 parents f55a0c1 + f0bd31e commit 0862505
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 847 deletions.
9 changes: 9 additions & 0 deletions include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def AllOneConstantOp : Constraint<CPred<"$0.getDefiningOp<ConstantOp>() && $0.ge
def TypeWidthAdjust32 : NativeCodeCall<
"$_builder.getI32IntegerAttr(type_cast<FIRRTLBaseType>($0.getType()).getBitWidthOrSentinel() - type_cast<FIRRTLBaseType>($1.getType()).getBitWidthOrSentinel())">;

// Int 1 is one higher than int 2
def AdjInt : Constraint<CPred<"$0.getValue() + 1 == $1.getValue()">>;

/// Drop the writer to the first argument and passthrough the second
def DropWrite : NativeCodeCall<"dropWrite($_builder, $0, $1)">;

Expand Down Expand Up @@ -693,6 +696,12 @@ def CatCast : Pat <
(MoveNameHint $old, (CatPrimOp $x, $y)),
[(EqualSigns $x, $y)]>;

// cat(bits a:b x, bits b+1:c x) -> bits( a:c x)
def CatBitsBits : Pat <
(CatPrimOp:$old (BitsPrimOp $x, I32Attr:$hi, I32Attr:$mid), (BitsPrimOp $x, I32Attr:$mid2, I32Attr:$low)),
(MoveNameHint $old, (BitsPrimOp $x, $hi, $low)),
[(AdjInt $mid2, $mid)]>;

// regreset(clock, constant_zero, resetValue) -> reg(clock)
def RegResetWithZeroReset : Pat<
(RegResetOp $clock, $reset, $_, $name, $nameKind, $annotations, $inner_sym, $forceable),
Expand Down
4 changes: 2 additions & 2 deletions lib/Conversion/LoopScheduleToCalyx/LoopScheduleToCalyx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1630,9 +1630,9 @@ void LoopScheduleToCalyxPass::runOnOperation() {
return;
}

//===----------------------------------------------------------------------===//
//===--------------------------------------------------------------------===//
// Cleanup patterns
//===----------------------------------------------------------------------===//
//===--------------------------------------------------------------------===//
RewritePatternSet cleanupPatterns(&getContext());
cleanupPatterns.add<calyx::MultipleGroupDonePattern,
calyx::NonTerminatingGroupDonePattern>(&getContext());
Expand Down
4 changes: 2 additions & 2 deletions lib/Conversion/SCFToCalyx/SCFToCalyx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1831,9 +1831,9 @@ void SCFToCalyxPass::runOnOperation() {
return;
}

//===----------------------------------------------------------------------===//
//===--------------------------------------------------------------------===//
// Cleanup patterns
//===----------------------------------------------------------------------===//
//===--------------------------------------------------------------------===//
RewritePatternSet cleanupPatterns(&getContext());
cleanupPatterns.add<calyx::MultipleGroupDonePattern,
calyx::NonTerminatingGroupDonePattern>(&getContext());
Expand Down
41 changes: 6 additions & 35 deletions lib/Dialect/FIRRTL/FIRRTLFolds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,37 +1199,10 @@ void DShrPrimOp::getCanonicalizationPatterns(RewritePatternSet &results,
results.insert<patterns::DShrOfConstant>(context);
}

namespace {
// cat(bits(x, ...), bits(x, ...)) -> bits(x ...) when the two ...'s are
// consecutive in the input.
struct CatBitsBits : public mlir::RewritePattern {
CatBitsBits(MLIRContext *context)
: RewritePattern(CatPrimOp::getOperationName(), 0, context) {}
LogicalResult matchAndRewrite(Operation *op,
PatternRewriter &rewriter) const override {
auto cat = cast<CatPrimOp>(op);
if (auto lhsBits =
dyn_cast_or_null<BitsPrimOp>(cat.getLhs().getDefiningOp())) {
if (auto rhsBits =
dyn_cast_or_null<BitsPrimOp>(cat.getRhs().getDefiningOp())) {
if (lhsBits.getInput() == rhsBits.getInput() &&
lhsBits.getLo() - 1 == rhsBits.getHi()) {
replaceOpWithNewOpAndCopyName<BitsPrimOp>(
rewriter, cat, cat.getType(), lhsBits.getInput(), lhsBits.getHi(),
rhsBits.getLo());
return success();
}
}
}
return failure();
}
};
} // namespace

void CatPrimOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) {
results.insert<CatBitsBits, patterns::CatDoubleConst, patterns::CatCast>(
context);
results.insert<patterns::CatBitsBits, patterns::CatDoubleConst,
patterns::CatCast>(context);
}

OpFoldResult BitCastOp::fold(FoldAdaptor adaptor) {
Expand Down Expand Up @@ -1960,9 +1933,7 @@ struct NodeBypass : public mlir::RewritePattern {
if (node.getInnerSym() || !AnnotationSet(node).canBeDeleted() ||
node.use_empty() || node.isForceable())
return failure();
rewriter.startOpModification(node);
node.getResult().replaceAllUsesWith(node.getInput());
rewriter.finalizeOpModification(node);
rewriter.replaceAllUsesWith(node.getResult(), node.getInput());
return success();
}
};
Expand Down Expand Up @@ -2370,7 +2341,7 @@ static void erasePort(PatternRewriter &rewriter, Value port) {
if (!subfield) {
auto ty = port.getType();
auto reg = rewriter.create<RegOp>(port.getLoc(), ty, getClock());
port.replaceAllUsesWith(reg.getResult());
rewriter.replaceAllUsesWith(port, reg.getResult());
return;
}
}
Expand Down Expand Up @@ -2552,7 +2523,7 @@ struct FoldUnusedPorts : public mlir::RewritePattern {
if (deadPorts[i])
erasePort(rewriter, port);
else
port.replaceAllUsesWith(newOp.getResult(nextPort++));
rewriter.replaceAllUsesWith(port, newOp.getResult(nextPort++));
}

rewriter.eraseOp(op);
Expand Down Expand Up @@ -2644,7 +2615,7 @@ struct FoldReadWritePorts : public mlir::RewritePattern {
rewriter.replaceOpWithNewOp<WireOp>(wmodeField, wmodeField.getType());
}
} else {
result.replaceAllUsesWith(newResult);
rewriter.replaceAllUsesWith(result, newResult);
}
}
rewriter.eraseOp(op);
Expand Down
7 changes: 3 additions & 4 deletions lib/Dialect/FIRRTL/Import/FIRAnnotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ bool fromOMIRJSON(llvm::json::Value &value,
SmallVectorImpl<Attribute> &annotations,
llvm::json::Path path, MLIRContext *context);

/// Handle verif intent captured in printf + when's. Returns failure if any
/// encountered, otherwise bool indicates whether the printf was encoding verif
/// intent. Mutates the IR, and will delete the PrintFOp when returns true.
FailureOr<bool> foldWhenEncodedVerifOp(PrintFOp printOp);
/// Classifier for legacy verif intent captured in printf + when's. Returns
/// true if the printf encodes verif intent, false otherwise.
bool isRecognizedPrintfEncodedVerif(PrintFOp printOp);

} // namespace firrtl
} // namespace circt
Expand Down
38 changes: 15 additions & 23 deletions lib/Dialect/FIRRTL/Import/FIRParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5390,38 +5390,30 @@ FIRCircuitParser::parseModuleBody(const SymbolTable &circuitSymTbl,
if (failed(result))
return result;

// Convert print-encoded verifications after parsing.

// Scan for printf-encoded verif's to error on their use, no longer supported.
{
// Gather PrintFOps and then process to avoid walking while mutating.
SmallVector<PrintFOp> buffer;
deferredModule.moduleOp.walk(
[&buffer](PrintFOp printFOp) { buffer.push_back(printFOp); });

size_t numVerifPrintfs = 0;
std::optional<Location> printfLoc;
for (auto printFOp : buffer) {
auto loc = printFOp.getLoc();
auto result = circt::firrtl::foldWhenEncodedVerifOp(printFOp);
if (failed(result))
return failure();
if (*result) {
++numVerifPrintfs;
if (!printfLoc)
printfLoc = loc;
}
}

deferredModule.moduleOp.walk([&](PrintFOp printFOp) {
if (!circt::firrtl::isRecognizedPrintfEncodedVerif(printFOp))
return;
++numVerifPrintfs;
if (!printfLoc)
printfLoc = printFOp.getLoc();
});

if (numVerifPrintfs > 0) {
auto diag =
mlir::emitWarning(deferredModule.moduleOp.getLoc(),
"module contains ")
mlir::emitError(deferredModule.moduleOp.getLoc(), "module contains ")
<< numVerifPrintfs
<< " printf-encoded verification operation(s), which are deprecated "
"and will be removed in the future";
<< " printf-encoded verification operation(s), which are no longer "
"supported.";
diag.attachNote(*printfLoc)
<< "example printf here, will just be a printf in the future";
<< "example printf here, this is now just a printf and nothing more";
diag.attachNote() << "For more information, see "
"https://github.com/llvm/circt/issues/6970";
return diag;
}
}

Expand Down
Loading

0 comments on commit 0862505

Please sign in to comment.