Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

How to create IR nodes

43 views
Skip to first unread message

amykouf

unread,
Apr 12, 2023, 1:53:54 PM4/12/23
to xls-dev
Hello,

We are trying to develop a custom pass in which we will need to be able to create nodes in the IR. We have found MakeNode() in function_base.h. Were can we find the info on how to use it to create any possible node?

Any help would be greatly appreciated!
Thanks in advance

Leary, Chris

unread,
Apr 12, 2023, 2:08:26 PM4/12/23
to amykouf, xls-dev
See https://google.github.io/xls/adding_ir_operation/ and let us know if that's what you were looking for -- note we do not currently have a way to introduce arbitrary nodes in a /runtime pluggable/ way (similar to how we had a CustomCall operations in XLA, if by some chance you happen to be familiar with that), all operators are statically known, so you would need to fork/modify, as I imagine you're already intending to do in order to add the pass. Having runtime extension in a limited form that the compiler can still understand as a black-box operation (i.e. that would not be subject to internal optimizations) is part of the "FFI" (foreign function interface) work that is starting this quarter, which intends to let you instantiate external verilog modules directly into XLS designs and schedule them in pipeline generation -- you can see other threads in the xls-dev google group on the thinking / plan around how FFI would work, e.g. https://groups.google.com/g/xls-dev/c/SQJuX9yI1W0/m/QwUCiYj0BwAJ . If you're thinking this would be a new operation that you'd want to contribute to upstream XLS (vs keeping in an experimental fork) we should probably discuss. Note that we tend to be a little conservative about introducing new operators because in general introducing arbitrary nodes into a compiler suffers from the expression problem: https://en.wikipedia.org/wiki/Expression_problem due extension both in representation (fundamental IR node operations) and behaviors (passes that manipulate and reason about the IR nodes and associated costs), so keeping compiler internal surface area well known and understood has many benefits for the reasoning and evolution of a compiler, which is why we tend to extend the set judiciously, and only when there's not other more "desguaring the new operation to the existing set" oriented options available.

Cheers,

- Chris Leary

--
You received this message because you are subscribed to the Google Groups "xls-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xls-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xls-dev/9cf893f2-ca98-4991-b136-0a7caaf1bf8fn%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted
Message has been deleted

Leary, Chris

unread,
Apr 14, 2023, 7:34:19 PM4/14/23
to amykouf, xls-dev
You'd do something like:

Node* n = f->return_value();
XLS_ASSIGN_OR_RETURN(Node* new, f->MakeNode<BinOp>(n->loc(), n, whatever_other_node, Op::kXor));
f->set_return_value(n);


I will note, though, that we don't have a lot of "intro to hacking on the guts of the compiler" material, since it's an implementation detail for our end users, and it's common in the guts of code bases like these that "the source code is the documentation". Hopefully that's not too much of a let down. :-)

- Leary

On Fri, Apr 14, 2023 at 4:12 PM amykouf <amaliako...@gmail.com> wrote:
Thank you very much for your reply.

In fact we want to be able to create nodes (e.g. using MakeNode) with existing operations.

Our issue is that we are new to google XLS and we have an issue finding the documentation on how to create new nodes inside a pass.

For example, lets say we have a function and we want to create a pass which will add an IR node which will xor the output of the function with another operand.

We have found for instance the following code in one of the existing passes that creates a multiply instruction node:

XLS_ASSIGN_OR_RETURN(
          Node * multiply,
          fb->MakeNode<ArithOp>(
              loc, multiplicand_literal, dividend,
              multiplicand_literal->BitCountOrDie() + dividend->BitCountOrDie(),
              Op::kSMul));


We would like to know how we can understand this code and to be able to do the same with all the existing operations in XLS.

Best regards
Reply all
Reply to author
Forward
0 new messages