Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/circt/Dialect/FIRRTL/AnnotationDetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ constexpr const char *traceNameAnnoClass =
constexpr const char *traceAnnoClass =
"chisel3.experimental.Trace$TraceAnnotation";

constexpr const char *omirTrackerAnnoClass =
"freechips.rocketchip.objectmodel.OMIRTracker";

constexpr const char *blackBoxInlineAnnoClass =
"firrtl.transforms.BlackBoxInlineAnno";
constexpr const char *blackBoxPathAnnoClass =
Expand Down
8 changes: 0 additions & 8 deletions include/circt/Dialect/FIRRTL/FIRRTLAnnotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ class Annotation {
void removeMember(StringAttr name);
void removeMember(StringRef name);

/// Returns true if this is an annotation which can be safely deleted without
/// consequence.
bool canBeDeleted();

using iterator = llvm::ArrayRef<NamedAttribute>::iterator;
iterator begin() const { return getDict().begin(); }
iterator end() const { return getDict().end(); }
Expand Down Expand Up @@ -247,10 +243,6 @@ class AnnotationSet {
static bool addDontTouch(Operation *op);
static bool removeDontTouch(Operation *op);

/// Check if every annotation can be deleted.
bool canBeDeleted() const;
static bool canBeDeleted(Operation *op);

bool operator==(const AnnotationSet &other) const {
return annotations == other.annotations;
}
Expand Down
22 changes: 0 additions & 22 deletions lib/Dialect/FIRRTL/FIRRTLAnnotations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,6 @@ bool AnnotationSet::removeDontTouch(Operation *op) {
return changed;
}

bool AnnotationSet::canBeDeleted() const {
return llvm::all_of(annotations, [](Attribute attr) {
return Annotation(attr).canBeDeleted();
});
}

bool AnnotationSet::canBeDeleted(Operation *op) {
return AnnotationSet(op).canBeDeleted();
}

/// Add more annotations to this AttributeSet.
void AnnotationSet::addAnnotations(ArrayRef<Annotation> newAnnotations) {
if (newAnnotations.empty())
Expand Down Expand Up @@ -438,18 +428,6 @@ void Annotation::removeMember(StringRef name) {
setDict(DictionaryAttr::getWithSorted(dict.getContext(), attributes));
}

bool Annotation::canBeDeleted() {

// The only annotations which can be deleted are OM-affiliated.
if (!isClass(omirTrackerAnnoClass))
return false;

auto tpe = getMember<StringAttr>("type");
return tpe &&
(tpe == "OMReferenceTarget" || tpe == "OMMemberReferenceTarget" ||
tpe == "OMMemberInstanceTarget");
}

void Annotation::dump() { attr.dump(); }

//===----------------------------------------------------------------------===//
Expand Down
12 changes: 5 additions & 7 deletions lib/Dialect/FIRRTL/FIRRTLFolds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1761,8 +1761,7 @@ static LogicalResult canonicalizeSingleSetConnect(MatchingConnectOp op,
// Only support wire and reg for now.
if (!isa<WireOp>(connectedDecl) && !isa<RegOp>(connectedDecl))
return failure();
if (hasDontTouch(connectedDecl) ||
!AnnotationSet(connectedDecl).canBeDeleted() ||
if (hasDontTouch(connectedDecl) || !AnnotationSet(connectedDecl).empty() ||
!hasDroppableName(connectedDecl) ||
cast<Forceable>(connectedDecl).isForceable())
return failure();
Expand Down Expand Up @@ -1940,7 +1939,7 @@ struct FoldNodeName : public mlir::RewritePattern {
auto node = cast<NodeOp>(op);
auto name = node.getNameAttr();
if (!node.hasDroppableName() || node.getInnerSym() ||
!AnnotationSet(node).canBeDeleted() || node.isForceable())
!AnnotationSet(node).empty() || node.isForceable())
return failure();
auto *newOp = node.getInput().getDefiningOp();
// Best effort, do not rename InstanceOp
Expand All @@ -1958,7 +1957,7 @@ struct NodeBypass : public mlir::RewritePattern {
LogicalResult matchAndRewrite(Operation *op,
PatternRewriter &rewriter) const override {
auto node = cast<NodeOp>(op);
if (node.getInnerSym() || !AnnotationSet(node).canBeDeleted() ||
if (node.getInnerSym() || !AnnotationSet(node).empty() ||
node.use_empty() || node.isForceable())
return failure();
rewriter.replaceAllUsesWith(node.getResult(), node.getInput());
Expand All @@ -1985,8 +1984,7 @@ LogicalResult NodeOp::fold(FoldAdaptor adaptor,
return failure();
if (hasDontTouch(getResult())) // handles inner symbols
return failure();
if (getAnnotationsAttr() &&
!AnnotationSet(getAnnotationsAttr()).canBeDeleted())
if (getAnnotationsAttr() && !AnnotationSet(getAnnotationsAttr()).empty())
return failure();
if (isForceable())
return failure();
Expand Down Expand Up @@ -2213,7 +2211,7 @@ struct FoldResetMux : public mlir::RewritePattern {
auto reset =
dyn_cast_or_null<ConstantOp>(reg.getResetValue().getDefiningOp());
if (!reset || hasDontTouch(reg.getOperation()) ||
!AnnotationSet(reg).canBeDeleted() || reg.isForceable())
!AnnotationSet(reg).empty() || reg.isForceable())
return failure();
// Find the one true connect, or bail
auto con = getSingleConnectUserOf(reg.getResult());
Expand Down
4 changes: 2 additions & 2 deletions lib/Dialect/FIRRTL/Transforms/AdvancedLayerSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class EffectInfo {

/// True if the given operation is NOT moveable due to some effect.
bool effectful(Operation *op) const {
if (!AnnotationSet(op).canBeDeleted() || hasDontTouch(op))
if (!AnnotationSet(op).empty() || hasDontTouch(op))
return true;
if (auto name = dyn_cast<FNamableOp>(op))
if (!name.hasDroppableName())
Expand Down Expand Up @@ -112,7 +112,7 @@ class EffectInfo {
}

void update(FModuleLike moduleOp) {
if (!AnnotationSet(moduleOp).canBeDeleted())
if (!AnnotationSet(moduleOp).empty())
return markEffectful(moduleOp);
auto *op = moduleOp.getOperation();
// Regular modules may be pure.
Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/FIRRTL/Transforms/IMConstProp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static bool isDeletableWireOrRegOrNode(Operation *op) {
return true;

// Otherwise, don't delete if has anything keeping it around or unknown.
return AnnotationSet(op).canBeDeleted() && !hasDontTouch(op) &&
return AnnotationSet(op).empty() && !hasDontTouch(op) &&
hasDroppableName(op) && !cast<Forceable>(op).isForceable();
}

Expand Down
11 changes: 2 additions & 9 deletions lib/Dialect/FIRRTL/Transforms/IMDeadCodeElim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static bool isDeletableDeclaration(Operation *op) {
if (auto name = dyn_cast<FNamableOp>(op))
if (!name.hasDroppableName())
return false;
return !hasDontTouch(op) && AnnotationSet(op).canBeDeleted();
return !hasDontTouch(op) && AnnotationSet(op).empty();
}

namespace {
Expand Down Expand Up @@ -403,11 +403,6 @@ void IMDeadCodeElimPass::runOnOperation() {
hierPathOp =
symbolTable->template lookup<hw::HierPathOp>(hierPathSym.getAttr());

if (anno.canBeDeleted()) {
if (hierPathOp && portId >= 0)
hierPathToElements[hierPathOp].insert(module.getArgument(portId));
return false;
}
if (hierPathOp)
markAlive(hierPathOp);
if (portId >= 0)
Expand Down Expand Up @@ -551,9 +546,7 @@ void IMDeadCodeElimPass::rewriteModuleBody(FModuleOp module) {

auto removeDeadNonLocalAnnotations = [&](int _, Annotation anno) -> bool {
auto hierPathSym = anno.getMember<FlatSymbolRefAttr>("circt.nonlocal");
// We only clean up non-local annotations here as local annotations will
// be deleted afterwards.
if (!anno.canBeDeleted() || !hierPathSym)
if (!hierPathSym)
return false;
auto hierPathOp =
symbolTable->template lookup<hw::HierPathOp>(hierPathSym.getAttr());
Expand Down
2 changes: 0 additions & 2 deletions lib/Dialect/FIRRTL/Transforms/LowerAnnotations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,6 @@ static llvm::StringMap<AnnoRecord> annotationRecords{{
{memTapSourceClass, {stdResolve, applyWithoutTarget<true>}},
{memTapPortClass, {stdResolve, applyWithoutTarget<true>}},
{memTapBlackboxClass, {stdResolve, applyWithoutTarget<true>}},
// OMIR Annotations
{omirTrackerAnnoClass, {stdResolve, applyWithoutTarget<true>}},
// Miscellaneous Annotations
{conventionAnnoClass, {stdResolve, applyConventionAnno}},
{dontTouchAnnoClass,
Expand Down
5 changes: 2 additions & 3 deletions lib/Dialect/FIRRTL/Transforms/RemoveUnusedPorts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ void RemoveUnusedPortsPass::removeUnusedModulePorts(
auto arg = module.getArgument(index);

// If the port is don't touch or has unprocessed annotations, we cannot
// remove the port. Maybe we can allow annotations though.
if ((hasDontTouch(arg) || !port.annotations.canBeDeleted()) &&
!ignoreDontTouch)
// remove the port.
if ((hasDontTouch(arg) || !port.annotations.empty()) && !ignoreDontTouch)
continue;

// TODO: Handle inout ports.
Expand Down
79 changes: 6 additions & 73 deletions test/Dialect/FIRRTL/canonicalization.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ firrtl.module @Orr(in %in0 : !firrtl.uint<0>, in %in2 : !firrtl.uint<2>,
out %a: !firrtl.uint<1>, out %b: !firrtl.uint<1>,
out %c: !firrtl.uint<1>, out %d: !firrtl.uint<1>,
out %e: !firrtl.uint<1>, out %f: !firrtl.uint<1>,
out %g: !firrtl.uint<1>, in %h : !firrtl.uint<64>,
out %g: !firrtl.uint<1>, in %h : !firrtl.uint<64>,
out %j : !firrtl.uint<1>) {
%invalid_ui2 = firrtl.invalidvalue : !firrtl.uint<2>
%c0_ui2 = firrtl.constant 0 : !firrtl.uint<2>
Expand Down Expand Up @@ -908,7 +908,7 @@ firrtl.module @Xorr(in %in0 : !firrtl.uint<0>, in %in2 : !firrtl.uint<2>,
out %a: !firrtl.uint<1>, out %b: !firrtl.uint<1>,
out %c: !firrtl.uint<1>, out %d: !firrtl.uint<1>,
out %e: !firrtl.uint<1>, out %f: !firrtl.uint<1>,
out %g: !firrtl.uint<1>, in %h : !firrtl.uint<64>,
out %g: !firrtl.uint<1>, in %h : !firrtl.uint<64>,
out %j : !firrtl.uint<1>) {
%invalid_ui2 = firrtl.invalidvalue : !firrtl.uint<2>
%c3_ui2 = firrtl.constant 3 : !firrtl.uint<2>
Expand Down Expand Up @@ -3490,73 +3490,6 @@ firrtl.module @HasBeenReset(in %clock: !firrtl.clock, in %reset1: !firrtl.uint<1
%constClockR1 = firrtl.node sym @constClockR1 %c5 : !firrtl.uint<1>
}

// OMIR annotations should not block removal.
// - See: https://github.com/llvm/circt/issues/6199
//
// CHECK-LABEL: firrtl.module @OMIRRemoval
firrtl.module @OMIRRemoval(in %source : !firrtl.uint<1>) {
// CHECK-NOT: %tmp_0
%tmp_0 = firrtl.wire {
annotations = [
{
class = "freechips.rocketchip.objectmodel.OMIRTracker",
id = 0 : i64,
type = "OMReferenceTarget"
}
]} : !firrtl.uint<1>
%a = firrtl.wire : !firrtl.uint<1>
firrtl.matchingconnect %tmp_0, %source : !firrtl.uint<1>
// CHECK: firrtl.matchingconnect %a, %source
firrtl.matchingconnect %a, %tmp_0 : !firrtl.uint<1>

// CHECK-NOT: %tmp_1
%tmp_1 = firrtl.wire {
annotations = [
{
class = "freechips.rocketchip.objectmodel.OMIRTracker",
id = 1 : i64,
type = "OMMemberReferenceTarget"
}
]} : !firrtl.uint<1>
%b = firrtl.wire : !firrtl.uint<1>
firrtl.matchingconnect %tmp_1, %source : !firrtl.uint<1>
// CHECK: firrtl.matchingconnect %b, %source
firrtl.matchingconnect %b, %tmp_1 : !firrtl.uint<1>

// CHECK-NOT: %tmp_2
%tmp_2 = firrtl.wire {
annotations = [
{
class = "freechips.rocketchip.objectmodel.OMIRTracker",
id = 2 : i64,
type = "OMMemberInstanceTarget"
}
]} : !firrtl.uint<1>
%c = firrtl.wire : !firrtl.uint<1>
firrtl.matchingconnect %tmp_2, %source : !firrtl.uint<1>
// CHECK: firrtl.matchingconnect %c, %source
firrtl.matchingconnect %c, %tmp_2 : !firrtl.uint<1>

// Adding one additional annotation will block removal.
//
// CHECK: %tmp_3
%tmp_3 = firrtl.wire {
annotations = [
{
class = "freechips.rocketchip.objectmodel.OMIRTracker",
id = 0 : i64,
type = "OMReferenceTarget"
},
{
class = "circt.test"
}
]} : !firrtl.uint<1>
%d = firrtl.wire : !firrtl.uint<1>
firrtl.matchingconnect %tmp_3, %source : !firrtl.uint<1>
// CHECK: firrtl.matchingconnect %d, %tmp_3
firrtl.matchingconnect %d, %tmp_3 : !firrtl.uint<1>
}

// CHECK-LABEL: firrtl.module @Whens
firrtl.module @Whens(in %clock: !firrtl.clock, in %a: !firrtl.uint<1>, in %reset: !firrtl.uint<1>) {
%true = firrtl.constant 1: !firrtl.uint<1>
Expand Down Expand Up @@ -3605,10 +3538,10 @@ firrtl.module @Probes(in %clock: !firrtl.clock) {
firrtl.module @sizeof(in %clock: !firrtl.clock,
in %vec: !firrtl.vector<uint<3>,3>,
in %bundle: !firrtl.bundle<a: uint<2>, b: uint<2>>) {
// CHECK: %c4_ui32 = firrtl.constant 4 : !firrtl.uint<32>
// CHECK: %c9_ui32 = firrtl.constant 9 : !firrtl.uint<32>
// CHECK: %c1_ui32 = firrtl.constant 1 : !firrtl.uint<32>
// CHECK: %n_c = firrtl.node interesting_name %c1_ui32
// CHECK: %c4_ui32 = firrtl.constant 4 : !firrtl.uint<32>
// CHECK: %c9_ui32 = firrtl.constant 9 : !firrtl.uint<32>
// CHECK: %c1_ui32 = firrtl.constant 1 : !firrtl.uint<32>
// CHECK: %n_c = firrtl.node interesting_name %c1_ui32
// CHECK: %n_vec = firrtl.node interesting_name %c9_ui32
// CHECK: %n_bundle = firrtl.node interesting_name %c4_ui32
%s_c = firrtl.int.sizeof %clock : (!firrtl.clock) -> !firrtl.uint<32>
Expand Down
71 changes: 0 additions & 71 deletions test/Dialect/FIRRTL/imconstprop.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -881,77 +881,6 @@ firrtl.circuit "RefSubOpPropagate" {
}
}

// -----

// OMIR annotation should not block removal.
// - See: https://github.com/llvm/circt/issues/6199
//
// CHECK-LABEL: firrtl.circuit "OMIRRemoval"
firrtl.circuit "OMIRRemoval" {
firrtl.module @OMIRRemoval(
out %a: !firrtl.uint<1>,
out %b: !firrtl.uint<2>,
out %c: !firrtl.uint<3>,
out %d: !firrtl.uint<4>
) {
%c1_ui1 = firrtl.constant 1 : !firrtl.uint<1>
%c3_ui2 = firrtl.constant 3 : !firrtl.uint<2>
%c7_ui3 = firrtl.constant 7 : !firrtl.uint<3>
%c15_ui4 = firrtl.constant 15 : !firrtl.uint<4>

// CHECK-NOT: %tmp_0
%tmp_0 = firrtl.node %c1_ui1 {
annotations = [
{
class = "freechips.rocketchip.objectmodel.OMIRTracker",
id = 0 : i64,
type = "OMReferenceTarget"
}
]} : !firrtl.uint<1>
firrtl.matchingconnect %a, %tmp_0 : !firrtl.uint<1>

// CHECK-NOT: %tmp_1
%tmp_1 = firrtl.node %c3_ui2 {
annotations = [
{
class = "freechips.rocketchip.objectmodel.OMIRTracker",
id = 1 : i64,
type = "OMMemberReferenceTarget"
}
]} : !firrtl.uint<2>
firrtl.matchingconnect %b, %tmp_1 : !firrtl.uint<2>

// CHECK-NOT: %tmp_2
%tmp_2 = firrtl.node %c7_ui3 {
annotations = [
{
class = "freechips.rocketchip.objectmodel.OMIRTracker",
id = 3 : i64,
type = "OMMemberInstanceTarget"
}
]} : !firrtl.uint<3>
firrtl.matchingconnect %c, %tmp_2 : !firrtl.uint<3>

// Adding one additional annotation will block removal.
//
// CHECK: %tmp_3
%tmp_3 = firrtl.node %c15_ui4 {
annotations = [
{
class = "freechips.rocketchip.objectmodel.OMIRTracker",
id = 4 : i64,
type = "OMReferenceTarget"
},
{
class = "circt.test"
}
]} : !firrtl.uint<4>
// CHECK-NEXT: firrtl.matchingconnect %d, %c15_ui4
firrtl.matchingconnect %d, %tmp_3 : !firrtl.uint<4>
}
}


// -----

firrtl.circuit "Layers" {
Expand Down
Loading