Support function calls.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
This is still a work in progress, I need to figure out this void function problem, and add tests.
test/CodeGen/WebAssembly/call.ll | ||
---|---|---|
22 ↗ | (On Diff #32762) | I'm a bit confused: functions without a return type don't work at the moment. They get eliminated by initial selection DAG: === call_void_nullary === call_i32_nullary Initial selection DAG: BB#0 'call_void_nullary:' Initial selection DAG: BB#0 'call_i32_nullary:' SelectionDAG has 7 nodes: SelectionDAG has 7 nodes: 0x2e16db8: i32 = TargetConstant<0> 0x37d2ed8: i32 = TargetConstant<0> 0x2de2880: ch = EntryToken 0x379e9a0: ch = EntryToken 0x2e16db8: <multiple use> 0x2e16ee0: ch,glue = callseq_start 0x2de2880, 0x2e16db8 [ORD=2] 0x2e16ee0: <multiple use> 0x2e16c90: i32 = GlobalAddress<void ()* @void_nullary> 0 [ORD=2] 0x2e17008: ch = WebAssemblyISD::CALL 0x2e16ee0, 0x2e16c90 [ORD=2] 0x2e16ee0: <multiple use> 0x2e16db8: <multiple use> 0x37d2ed8: <multiple use> 0x37d3000: ch,glue = callseq_start 0x379e9a0, 0x37d2ed8 [ORD=2] 0x37d2db0: i32 = GlobalAddress<i32 ()* @i32_nullary> 0 [ORD=2] 0x37d3128: i32,ch = WebAssemblyISD::CALL 0x37d3000, 0x37d2db0 [ORD=2] 0x37d3128: <multiple use> 0x2e16db8: <multiple use> 0x37d2ed8: <multiple use> 0x2e17130: ch,glue = callseq_end 0x2e16ee0, 0x2e16db8, 0x2e16db8 [O 0x37d2ed8: <multiple use> RD=2] 0x37d3250: ch,glue = callseq_end 0x37d3128:1, 0x37d2ed8, 0x37d2ed8 [ORD=2] 0x37d3128: <multiple use> 0x2e17258: ch = WebAssemblyISD::RETURN 0x2e17130 [ORD=3] 0x37d3378: ch = WebAssemblyISD::RETURN 0x37d3250, 0x37d3128 [ORD=3] Combining: 0x2e17258: ch = WebAssemblyISD::RETURN 0x2e17130 [ORD=3] Combining: 0x37d3378: ch = WebAssemblyISD::RETURN 0x37d3250, 0x37d3128 [ORD=3] Combining: 0x2e17130: ch,glue = callseq_end 0x2e16ee0, 0x2e16db8, 0x2e1 Combining: 0x37d3250: ch,glue = callseq_end 0x37d3128:1, 0x37d2ed8, 0x3 6db8 [ORD=2] 7d2ed8 [ORD=2] Combining: 0x37d3128: i32,ch = WebAssemblyISD::CALL 0x37d3000, 0x37d2db 0 [ORD=2] Combining: 0x2e16ee0: ch,glue = callseq_start 0x2de2880, 0x2e16db8 [ORD Combining: 0x37d3000: ch,glue = callseq_start 0x379e9a0, 0x37d2ed8 [ORD =2] =2] Combining: 0x2e16db8: i32 = TargetConstant<0> Combining: 0x37d2ed8: i32 = TargetConstant<0> Combining: 0x37d2db0: i32 = GlobalAddress<i32 ()* @i32_nullary> 0 [ORD= 2] Combining: 0x2de2880: ch = EntryToken Combining: 0x379e9a0: ch = EntryToken I do set hasSideEffects = 1 on calls, so that's unexpected! |
Not done reviewing, but here are some comments so far.
lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp | ||
---|---|---|
136 ↗ | (On Diff #32763) | Is this a mismatched quote? |
lib/Target/WebAssembly/WebAssemblyISelLowering.cpp | ||
216 ↗ | (On Diff #32763) | This is likely why the call_void is getting deleted. It's necessary to hook up the Chain result even when there is no return value. |
321 ↗ | (On Diff #32763) | We should implement isOffsetFoldingLegal() to always return false, and then we can change this to assert that the offset is 0. |
323 ↗ | (On Diff #32763) | TargetFlags will only get set if the target sets them, and since we don't set them, this won't happen, so we can assert this too. |
lib/Target/WebAssembly/WebAssemblyISelLowering.h | ||
30 ↗ | (On Diff #32763) | Given the preprocessor magic, this comment should move to WebAssemblyISD.def. |
lib/Target/WebAssembly/WebAssemblyInstrCall.td | ||
22 ↗ | (On Diff #32763) | If we're going to use Pseudo instructions, should implement expandPostRAPseudo to expand them. |
24 ↗ | (On Diff #32763) | It looks like it's not necessary to set hasSideEffects on call instructions. |
lib/Target/WebAssembly/WebAssemblyInstrInfo.td | ||
50 ↗ | (On Diff #32763) | It looks like it's not necessary to set SDNPSideEffect here either. |
53 ↗ | (On Diff #32763) | Ditto about SDNPSideEffect. |
58 ↗ | (On Diff #32763) | For that matter, we shouldn't need it on WebAssemblyreturn either. |
- toSymbol
- Move NodeType comment to .def file.
- Fix chain. Remove CALL_VOID for now.
- Implement isOffsetFoldingLegal, assert on getOffset and getTargetFlags.
- Remove side-effect from call.
- Remove side-effect from return.
- Change symbol character from ` to $.
lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp | ||
---|---|---|
136 ↗ | (On Diff #32763) | Nah, just a marker for symbols. The discussion was still ongoing, but it looks like things settled on $ instead. |
lib/Target/WebAssembly/WebAssemblyInstrCall.td | ||
22 ↗ | (On Diff #32763) | BPF doesn't have it and aarch64 ignores callseq in expandPostRAPseudo, but both use pseudos. I'm not sure I understand what our current implementation would do beyond returning false, but then again I'm still pretty confused by selection DAG. Do you think this patch should have expandPostRAPseudo, and if so in what form? |
test/CodeGen/WebAssembly/call.ll | ||
---|---|---|
23 ↗ | (On Diff #32848) | This is resolved, but there's now an issue with void functions which I'll tackle in a separate patch. |
lib/Target/WebAssembly/WebAssemblyInstrCall.td | ||
---|---|---|
22 ↗ | (On Diff #32851) | If we don't need post-RA expansion, then these can just be regular instructions, rather than Pseudos. You can set 'isCodeGenOnly = 1' for them to indicate that they're just compiler magic. |
- Fix comment.
- toSymbol
- Move NodeType comment to .def file.
- Fix chain. Remove CALL_VOID for now.
- Implement isOffsetFoldingLegal, assert on getOffset and getTargetFlags.
- Remove side-effect from call.
- Remove side-effect from return.
- Change symbol character from ` to $.
- Use a multiclass.
- Make callseq an instruction instead of a pseudo.