Skip to content

Commit 1e5b6dc

Browse files
committed
[Heavy] Replace ResolveOp with DiscardOp
1 parent 87b8d20 commit 1e5b6dc

File tree

3 files changed

+45
-29
lines changed

3 files changed

+45
-29
lines changed

heavy/include/nbdl_gen/Nbdl.td

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,6 @@ def Nbdl_GetOp : Nbdl_Op<"get", []> {
133133
let results = (outs Nbdl_Type:$result);
134134
}
135135

136-
def Nbdl_ResolveOp : Nbdl_Op<"resolve", [Terminator]> {
137-
let description = [{
138-
Finalize resolving stores by invoking the callback
139-
provided in the definition of a visit function.
140-
This is similar to nbdl.visit except it does not return
141-
a value and terminates the block.
142-
}];
143-
144-
let arguments = (ins Nbdl_Type:$fn, Variadic<Nbdl_Type>:$args);
145-
let results = (outs);
146-
}
147-
148136
def Nbdl_MatchOp : Nbdl_Op<"match", [Terminator, NoTerminator]> {
149137
let summary = "match";
150138
let description = [{
@@ -344,6 +332,21 @@ def Nbdl_UnitOp : Nbdl_Op<"unit", []> {
344332
let results = (outs Nbdl_Unit:$result);
345333
}
346334

335+
def Nbdl_DiscardOp : Nbdl_Op<"discard", [Terminator]> {
336+
let description = [{
337+
Discard the result of a nbdl.visit call.
338+
339+
Note:
340+
This is really only used to terminate the block
341+
and is the most command case for nbdl.visit.
342+
I don't know that we will ever want to "return"
343+
a value.
344+
}];
345+
346+
let arguments = (ins Nbdl_Type:$arg);
347+
let results = (outs);
348+
}
349+
347350
def Nbdl_VisitOp : Nbdl_Op<"visit", []> {
348351
let description = [{
349352
Call a function with resolved stores as arguments

heavy/lib/Nbdl/NbdlWriter.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ class FuncWriter : public NbdlWriter<FuncWriter> {
353353
else if (isa<OverloadOp>(Op)) return Visit(cast<OverloadOp>(Op));
354354
else if (isa<MemberNameOp>(Op)) return Visit(cast<MemberNameOp>(Op));
355355
else if (isa<GetOp>(Op)) return Visit(cast<GetOp>(Op));
356-
else if (isa<ResolveOp>(Op)) return Visit(cast<ResolveOp>(Op));
356+
else if (isa<DiscardOp>(Op)) return Visit(cast<DiscardOp>(Op));
357357
else if (isa<VisitOp>(Op)) return Visit(cast<VisitOp>(Op));
358358
else if (isa<NoOp>(Op)) return Visit(cast<NoOp>(Op));
359359
else if (isa<MatchIfOp>(Op)) return Visit(cast<MatchIfOp>(Op));
@@ -450,14 +450,8 @@ class FuncWriter : public NbdlWriter<FuncWriter> {
450450
OS << ");\n";
451451
}
452452

453-
void Visit(ResolveOp Op) {
454-
WriteExpr(Op.getFn());
455-
OS << '(';
456-
llvm::interleave(Op.getArgs(), OS,
457-
[&](mlir::Value V) {
458-
WriteExpr(V);
459-
}, ",\n");
460-
OS << ");\n";
453+
void Visit(DiscardOp Op) {
454+
// Do nothing.
461455
}
462456

463457
void Visit(ApplyActionOp Op) {

heavy/test/Nbdl/match_params.scm

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,24 @@
1010
(define !nbdl.store (type "!nbdl.store"))
1111
(define !nbdl.tag (type "!nbdl.tag"))
1212
(define !nbdl.symbol (type "!nbdl.symbol"))
13+
(define !nbdl.unit (type "!nbdl.unit"))
1314
(define i32 (type "i32"))
1415

16+
(define (resolve . args)
17+
(define Result
18+
(result
19+
(create-op "nbdl.visit"
20+
(loc: 0)
21+
(operands: args)
22+
(attributes:)
23+
(result-types: !nbdl.unit)
24+
)))
25+
(create-op "nbdl.discard"
26+
(loc: 0)
27+
(operands: Result)
28+
(attributes:)
29+
(result-types:)))
30+
1531
(%build-match-params
1632
'my_match_params
1733
1 ; num-params
@@ -62,7 +78,7 @@
6278
(at-block-begin (entry-block the-match-op))
6379
(%build-overload 'loc "::my::first_t const&"
6480
(lambda (my-first)
65-
(old-create-op "nbdl.resolve" (operands fn my-first))))
81+
(resolve fn my-first)))
6682
(%build-overload 'loc "uint32_t"
6783
(lambda (input)
6884
(define pred1 (result
@@ -77,12 +93,13 @@
7793
(result-types !nbdl.store))))
7894
(%build-match-if
7995
'loc input pred1
80-
(lambda() (old-create-op "nbdl.resolve" (operands fn input)))
96+
(lambda()
97+
(resolve fn input))
8198
(lambda()
8299
(%build-match-if
83100
'loc input pred2
84-
(lambda () (old-create-op "nbdl.resolve"
85-
(operands fn input)))
101+
(lambda()
102+
(resolve fn input))
86103
(lambda ()
87104
(define some-fn (result
88105
(old-create-op
@@ -91,12 +108,14 @@
91108
`("expr", (string-attr "::my::some_fn")))
92109
(result-types !nbdl.store))))
93110
(define some-fn-result
111+
; Intermediate visit call with result as operand
112+
; to "resolving" visit/discard.
94113
(result
95114
(old-create-op "nbdl.visit"
96-
(operands some-fn input)
97-
(result-types !nbdl.store))))
98-
(old-create-op "nbdl.resolve"
99-
(operands fn some-fn-result))))))))
115+
(operands some-fn input)
116+
(result-types !nbdl.store))))
117+
(resolve fn some-fn-result)
118+
))))))
100119
(%build-overload 'loc "")
101120
))))
102121

0 commit comments

Comments
 (0)