how to support goto function in XLS

23 views
Skip to first unread message

ray ic

unread,
Feb 25, 2024, 10:08:56 AMFeb 25
to xls...@googlegroups.com
Hi,
 I am a Newbie for xls. I have try an interesting flow : llvm2c and xls to verilog. I find that goto function is not supported in xls while it is used widely in llvm IR. So how to support goto function in XLS?
Thanks a lot

Eric Astor

unread,
Feb 26, 2024, 9:41:10 AMFeb 26
to ray ic, xls...@googlegroups.com
Hi Ray,

Software languages that support a GOTO function generally rely on the fact that their execution uses an instruction pointer to identify which instruction is operating at each point in time. On the other hand, XLS aims to compile down to hardware - and there's no way to directly "jump" to a different branch of execution in hardware, since that would involve dynamically changing how the wires connect. You can emulate this - which is what a CPU does! - but a GOTO function isn't really a natural fit for hardware itself, it's more of a fit for languages that execute on general-purpose hardware.

Hardware does have a more natural concept of branching logic that can be used, though! In XLS, we implement branching logic via selects, which use one value (the selector) to choose from between multiple possible output values (the cases). Any frontend that aims to convert LLVM IR (a control-flow-oriented language) into XLS (a data-flow-oriented language) would probably need to convert between these paradigms, translating the logic of how the data is transformed by the LLVM IR, rather than directly converting the LLVM IR itself. This sort of thing might be possible, but is likely to be quite tricky!

Since you mention you're using LLVM2C, I assume you've been experimenting with XLS[cc]! This is a contributed (which is why it lives in the "contrib" folder) semi-experimental frontend that converts a subset of C++ (sometimes called synthesizable C++) to XLS IR. It does exactly what I mentioned in the previous paragraph, converting the control flow of synthesizable C++ into the data flow of XLS IR; however, it isn't capable of doing everything. In fact, GOTOs can be used in so many different ways, expressing so many different kinds of data flow, that it would likely be pretty difficult to support them in this model.

Sorry I can't offer an easy solution, but I hope this information helps!

Best,
- Eric



--
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/CAOpLr9wmEmwObFYgpE6x%3DMkEjtgvpdYj9EzrFUYauutm8YxmfA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

ray ic

unread,
Feb 27, 2024, 5:41:39 AMFeb 27
to Eric Astor, xls...@googlegroups.com
Eric,
Thanks a lot for your reply! The xlscc(cc frontend parser) flow is good. My rough idea is we can use LLVM frontend to parse any language code to LLVM and translate to cc. Then I can use xls to generate hardware. Seems this flow can not work.  Previously I found another HLS tool(Legup)
could  handle goto function. It can auto partition hardware and software. It would generate an opensource mpu core(mips core or arm core). Maybe currently the customized mpu core generation can be used in xls flow to handle such scenario?
Another pure asic implementation flow for goto function can be: add some new global monitors which behave like watchdogs. If goto happen, then hw irq would trigger the global state switching. This may involve the glitches in ASIC implementation but may can be tolerated in FPGA implementation. 

More discussions are appreciated.


To unsubscribe from this group and stop receiving emails from it, send an email to xls-dev+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages