Skip to content

Commit 1ae382a

Browse files
committed
[RTG] Add interleave_sequences op
1 parent a04610c commit 1ae382a

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

include/circt/Dialect/RTG/IR/RTGOps.td

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,27 @@ def EmbedSequenceOp : RTGOp<"embed_sequence", []> {
141141
let assemblyFormat = "$sequence attr-dict";
142142
}
143143

144+
def InterleaveSequencesOp : RTGOp<"interleave_sequences", [Pure]> {
145+
let summary = "interleave a list of sequences";
146+
let description = [{
147+
This operation takes a list of (at least one) fully randomized sequences and
148+
interleaves them by taking the next `batchSize` number of operations
149+
implementing the `InstructionOpInterface` of each sequence round-robin.
150+
151+
Therefore, if only one sequence is in the list, this operation is a NOP.
152+
}];
153+
154+
let arguments = (ins Variadic<RandomizedSequenceType>:$sequences,
155+
DefaultValuedAttr<I32Attr, "1">:$batchSize);
156+
157+
let results = (outs RandomizedSequenceType:$interleavedSequence);
158+
159+
let assemblyFormat = "$sequences (`batch` $batchSize^)? attr-dict";
160+
161+
let hasVerifier = 1;
162+
let hasFolder = 1;
163+
}
164+
144165
//===- Label Operations ---------------------------------------------------===//
145166

146167
class LabelDeclBase<string mnemonic,

lib/Dialect/RTG/IR/RTGOps.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,24 @@ void SubstituteSequenceOp::print(OpAsmPrinter &p) {
193193
p.printOptionalAttrDict((*this)->getAttrs(), {});
194194
}
195195

196+
//===----------------------------------------------------------------------===//
197+
// InterleaveSequencesOp
198+
//===----------------------------------------------------------------------===//
199+
200+
LogicalResult InterleaveSequencesOp::verify() {
201+
if (getSequences().empty())
202+
return emitOpError("must have at least one sequence in the list");
203+
204+
return success();
205+
}
206+
207+
OpFoldResult InterleaveSequencesOp::fold(FoldAdaptor adaptor) {
208+
if (getSequences().size() == 1)
209+
return getSequences()[0];
210+
211+
return {};
212+
}
213+
196214
//===----------------------------------------------------------------------===//
197215
// SetCreateOp
198216
//===----------------------------------------------------------------------===//

test/Dialect/RTG/IR/basic.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,11 @@ rtg.sequence @integerHandlingOps(%arg0: index, %arg1: index) {
134134
// CHECK: rtg.random_number_in_range [%arg0, %arg1)
135135
rtg.random_number_in_range [%arg0, %arg1)
136136
}
137+
138+
// CHECK-LABEL: rtg.test @interleaveSequences
139+
rtg.test @interleaveSequences(%seq0: !rtg.randomized_sequence, %seq1: !rtg.randomized_sequence) {
140+
// CHECK: rtg.interleave_sequences %seq0 {rtg.some_attr}
141+
rtg.interleave_sequences %seq0 {rtg.some_attr}
142+
// CHECK: rtg.interleave_sequences %seq0, %seq1 batch 4 {rtg.some_attr}
143+
rtg.interleave_sequences %seq0, %seq1 batch 4 {rtg.some_attr}
144+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: circt-opt --canonicalize %s | FileCheck %s
2+
3+
// CHECK-LABEL: @interleaveSequences
4+
rtg.test @interleaveSequences(%seq0: !rtg.randomized_sequence) {
5+
// CHECK-NEXT: rtg.embed_sequence %seq0
6+
%0 = rtg.interleave_sequences %seq0
7+
rtg.embed_sequence %0
8+
}

test/Dialect/RTG/IR/errors.mlir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,10 @@ rtg.target @target : !rtg.dict<> {
174174
// expected-error @below {{third sequence element type must be a fully substituted sequence}}
175175
rtg.context_switch #rtgtest.cpu<0> -> #rtgtest.cpu<1>, %0 : !rtg.sequence<!rtgtest.cpu, !rtgtest.cpu, !rtgtest.cpu>
176176
}
177+
178+
// -----
179+
180+
rtg.test @test() {
181+
// expected-error @below {{must have at least one sequence in the list}}
182+
%0 = rtg.interleave_sequences
183+
}

0 commit comments

Comments
 (0)