Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RTG] Add get_size ops for sets and bags #7920

Open
wants to merge 1 commit into
base: maerhart-rtg-bag-union
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions include/circt/Dialect/RTG/IR/RTGOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ def SetUnionOp : RTGOp<"set_union", [
}];
}

def SetGetSizeOp : RTGOp<"set_get_size", [Pure]> {
let summary = "returns the number of elements in the set";

let arguments = (ins SetType:$set);
let results = (outs Index:$result);

let assemblyFormat = [{
$set `:` qualified(type($set)) attr-dict
}];
}

//===- Bag Operations ------------------------------------------------------===//

def BagCreateOp : RTGOp<"bag_create", [Pure, SameVariadicOperandSize]> {
Expand Down Expand Up @@ -241,6 +252,21 @@ def BagUnionOp : RTGOp<"bag_union", [
}];
}

def BagGetSizeOp : RTGOp<"bag_get_size", [Pure]> {
let summary = "returns the number of unique elements in the bag";
let description = [{
This operation returns the number of unique elements in the bag, i.e., for
the bag `{a, a, b, c, c}` it returns 3.
}];

let arguments = (ins BagType:$bag);
let results = (outs Index:$result);

let assemblyFormat = [{
$bag `:` qualified(type($bag)) attr-dict
}];
}

//===- Test Specification Operations --------------------------------------===//

def TestOp : RTGOp<"test", [
Expand Down
9 changes: 6 additions & 3 deletions include/circt/Dialect/RTG/IR/RTGVisitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class RTGOpVisitor {
auto *thisCast = static_cast<ConcreteType *>(this);
return TypeSwitch<Operation *, ResultType>(op)
.template Case<SequenceOp, SequenceClosureOp, SetCreateOp,
SetSelectRandomOp, SetDifferenceOp, SetUnionOp, TestOp,
InvokeSequenceOp, BagCreateOp, BagSelectRandomOp,
BagDifferenceOp, BagUnionOp, TargetOp, YieldOp>(
SetSelectRandomOp, SetDifferenceOp, SetUnionOp,
SetGetSizeOp, TestOp, InvokeSequenceOp, BagCreateOp,
BagSelectRandomOp, BagDifferenceOp, BagUnionOp,
BagGetSizeOp, TargetOp, YieldOp>(
[&](auto expr) -> ResultType {
return thisCast->visitOp(expr, args...);
})
Expand Down Expand Up @@ -90,10 +91,12 @@ class RTGOpVisitor {
HANDLE(SetSelectRandomOp, Unhandled);
HANDLE(SetDifferenceOp, Unhandled);
HANDLE(SetUnionOp, Unhandled);
HANDLE(SetGetSizeOp, Unhandled);
HANDLE(BagCreateOp, Unhandled);
HANDLE(BagSelectRandomOp, Unhandled);
HANDLE(BagDifferenceOp, Unhandled);
HANDLE(BagUnionOp, Unhandled);
HANDLE(BagGetSizeOp, Unhandled);
HANDLE(TestOp, Unhandled);
HANDLE(TargetOp, Unhandled);
HANDLE(YieldOp, Unhandled);
Expand Down
4 changes: 4 additions & 0 deletions test/Dialect/RTG/IR/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ func.func @sets(%arg0: i32, %arg1: i32) {
// CHECK: [[EMPTY:%.+]] = rtg.set_create : i32
// CHECK: [[DIFF:%.+]] = rtg.set_difference [[SET]], [[EMPTY]] : !rtg.set<i32>
// CHECK: rtg.set_union [[SET]], [[DIFF]] : !rtg.set<i32>
// CHECK: rtg.set_get_size [[SET]] : !rtg.set<i32>
%set = rtg.set_create %arg0, %arg1 : i32
%r = rtg.set_select_random %set : !rtg.set<i32>
%empty = rtg.set_create : i32
%diff = rtg.set_difference %set, %empty : !rtg.set<i32>
%union = rtg.set_union %set, %diff : !rtg.set<i32>
%size = rtg.set_get_size %set : !rtg.set<i32>

return
}
Expand All @@ -50,12 +52,14 @@ rtg.sequence @bags {
// CHECK: [[DIFF:%.+]] = rtg.bag_difference [[BAG]], [[EMPTY]] : !rtg.bag<i32>
// CHECK: rtg.bag_difference [[BAG]], [[EMPTY]] inf : !rtg.bag<i32>
// CHECK: rtg.bag_union [[BAG]], [[EMPTY]], [[DIFF]] : !rtg.bag<i32>
// CHECK: rtg.bag_get_size [[BAG]] : !rtg.bag<i32>
%bag = rtg.bag_create (%arg2 x %arg0, %arg2 x %arg1) : i32
%r = rtg.bag_select_random %bag : !rtg.bag<i32>
%empty = rtg.bag_create : i32
%diff = rtg.bag_difference %bag, %empty : !rtg.bag<i32>
%diff2 = rtg.bag_difference %bag, %empty inf : !rtg.bag<i32>
%union = rtg.bag_union %bag, %empty, %diff : !rtg.bag<i32>
%size = rtg.bag_get_size %bag : !rtg.bag<i32>
}

// CHECK-LABEL: rtg.target @empty_target : !rtg.dict<> {
Expand Down