This is an archive of the discontinued LLVM Phabricator instance.

WebAssembly: Implement call
ClosedPublic

Authored by jfb on Aug 20 2015, 3:44 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

jfb updated this revision to Diff 32762.Aug 20 2015, 3:44 PM
jfb retitled this revision from to WebAssembly: Implement call.
jfb updated this object.
jfb added a reviewer: sunfish.
jfb added a subscriber: llvm-commits.
jfb added a comment.Aug 20 2015, 3:48 PM

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!

jfb updated this revision to Diff 32763.Aug 20 2015, 3:51 PM
  • Fix comment.
sunfish edited edge metadata.Aug 20 2015, 5:44 PM

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.

jfb updated this revision to Diff 32848.Aug 21 2015, 11:22 AM
jfb marked 9 inline comments as done.
jfb edited edge metadata.
  • 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.
I'll factor it out into a toSymbol function.

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?

jfb marked an inline comment as done.Aug 21 2015, 11:23 AM
jfb added inline comments.
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.

jfb updated this revision to Diff 32851.Aug 21 2015, 11:26 AM
jfb marked an inline comment as done.
  • Use a multiclass.
sunfishcode accepted this revision.Aug 24 2015, 1:37 PM
sunfishcode added a reviewer: sunfishcode.
sunfishcode added a subscriber: sunfishcode.
sunfishcode added inline comments.
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.

This revision is now accepted and ready to land.Aug 24 2015, 1:37 PM
jfb updated this revision to Diff 33003.Aug 24 2015, 2:52 PM
jfb marked an inline comment as done.
jfb edited edge metadata.
  • 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.
jfb updated this revision to Diff 33004.Aug 24 2015, 2:56 PM

Merge.

This revision was automatically updated to reflect the committed changes.