@@ -697,7 +697,8 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
697
697
LLVMContext &Ctx = MIRBuilder.getContext ();
698
698
const WebAssemblyTargetLowering &TLI = *getTLI<WebAssemblyTargetLowering>();
699
699
MachineRegisterInfo &MRI = *MIRBuilder.getMRI ();
700
- const WebAssemblySubtarget &Subtarget = MF.getSubtarget <WebAssemblySubtarget>();
700
+ const WebAssemblySubtarget &Subtarget =
701
+ MF.getSubtarget <WebAssemblySubtarget>();
701
702
702
703
CallingConv::ID CallConv = Info.CallConv ;
703
704
if (!callingConvSupported (CallConv)) {
@@ -716,7 +717,7 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
716
717
*/
717
718
718
719
if (Info.IsTailCall ) {
719
- Info.LoweredTailCall = true ;
720
+ Info.LoweredTailCall = true ;
720
721
auto NoTail = [&](const char *Msg) {
721
722
if (Info.CB && Info.CB ->isMustTailCall ())
722
723
fail (MIRBuilder, Msg);
@@ -773,65 +774,73 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
773
774
Register IndirectIdx;
774
775
775
776
if (Info.Callee .isReg ()) {
776
- LLT CalleeType = MRI.getType (Info.Callee .getReg ());
777
- assert (CalleeType.isPointer () && " Trying to lower a call with a Callee other than a pointer???" );
778
-
779
- IsIndirect = true ;
780
- CallInst = MIRBuilder.buildInstrNoInsert (Info.LoweredTailCall ? WebAssembly::RET_CALL_INDIRECT : WebAssembly::CALL_INDIRECT);
781
-
782
- // Placeholder for the type index.
783
- // This gets replaced with the correct value in WebAssemblyMCInstLower.cpp
784
- CallInst.addImm (0 );
785
-
786
- MCSymbolWasm *Table;
787
- if (CalleeType.getAddressSpace () == WebAssembly::WASM_ADDRESS_SPACE_DEFAULT) {
788
- Table = WebAssembly::getOrCreateFunctionTableSymbol (
789
- MF.getContext (), &Subtarget);
790
- IndirectIdx = Info.Callee .getReg ();
791
-
792
- auto PtrSize = CalleeType.getSizeInBits ();
793
- auto PtrIntLLT = LLT::scalar (PtrSize);
794
-
795
- IndirectIdx = MIRBuilder.buildPtrToInt (PtrIntLLT, IndirectIdx).getReg (0 );
796
- if (PtrSize > 32 ) {
797
- IndirectIdx = MIRBuilder.buildTrunc (LLT::scalar (32 ), IndirectIdx).getReg (0 );
798
- }
799
- } else if (CalleeType.getAddressSpace () == WebAssembly::WASM_ADDRESS_SPACE_FUNCREF) {
800
- Table = WebAssembly::getOrCreateFuncrefCallTableSymbol (
801
- MF.getContext (), &Subtarget);
802
-
803
- auto TableSetInstr = MIRBuilder.buildInstr (WebAssembly::TABLE_SET_FUNCREF);
804
- TableSetInstr.addSym (Table);
805
- TableSetInstr.addUse (Info.Callee .getReg ());
806
- IndirectIdx = MIRBuilder.buildConstant (LLT::scalar (32 ), 0 ).getReg (0 );
807
- } else {
808
- fail (MIRBuilder, " Invalid address space for indirect call" );
809
- return false ;
777
+ LLT CalleeType = MRI.getType (Info.Callee .getReg ());
778
+ assert (CalleeType.isPointer () &&
779
+ " Trying to lower a call with a Callee other than a pointer???" );
780
+
781
+ IsIndirect = true ;
782
+ CallInst = MIRBuilder.buildInstrNoInsert (
783
+ Info.LoweredTailCall ? WebAssembly::RET_CALL_INDIRECT
784
+ : WebAssembly::CALL_INDIRECT);
785
+
786
+ // Placeholder for the type index.
787
+ // This gets replaced with the correct value in WebAssemblyMCInstLower.cpp
788
+ CallInst.addImm (0 );
789
+
790
+ MCSymbolWasm *Table;
791
+ if (CalleeType.getAddressSpace () ==
792
+ WebAssembly::WASM_ADDRESS_SPACE_DEFAULT) {
793
+ Table = WebAssembly::getOrCreateFunctionTableSymbol (MF.getContext (),
794
+ &Subtarget);
795
+ IndirectIdx = Info.Callee .getReg ();
796
+
797
+ auto PtrSize = CalleeType.getSizeInBits ();
798
+ auto PtrIntLLT = LLT::scalar (PtrSize);
799
+
800
+ IndirectIdx = MIRBuilder.buildPtrToInt (PtrIntLLT, IndirectIdx).getReg (0 );
801
+ if (PtrSize > 32 ) {
802
+ IndirectIdx =
803
+ MIRBuilder.buildTrunc (LLT::scalar (32 ), IndirectIdx).getReg (0 );
810
804
}
805
+ } else if (CalleeType.getAddressSpace () ==
806
+ WebAssembly::WASM_ADDRESS_SPACE_FUNCREF) {
807
+ Table = WebAssembly::getOrCreateFuncrefCallTableSymbol (MF.getContext (),
808
+ &Subtarget);
809
+
810
+ auto TableSetInstr =
811
+ MIRBuilder.buildInstr (WebAssembly::TABLE_SET_FUNCREF);
812
+ TableSetInstr.addSym (Table);
813
+ TableSetInstr.addUse (Info.Callee .getReg ());
814
+ IndirectIdx = MIRBuilder.buildConstant (LLT::scalar (32 ), 0 ).getReg (0 );
815
+ } else {
816
+ fail (MIRBuilder, " Invalid address space for indirect call" );
817
+ return false ;
818
+ }
811
819
812
- if (Subtarget.hasCallIndirectOverlong ()) {
813
- CallInst.addSym (Table);
814
- } else {
815
- // For the MVP there is at most one table whose number is 0, but we can't
816
- // write a table symbol or issue relocations. Instead we just ensure the
817
- // table is live and write a zero.
818
- Table->setNoStrip ();
819
- CallInst.addImm (0 );
820
- }
820
+ if (Subtarget.hasCallIndirectOverlong ()) {
821
+ CallInst.addSym (Table);
822
+ } else {
823
+ // For the MVP there is at most one table whose number is 0, but we can't
824
+ // write a table symbol or issue relocations. Instead we just ensure the
825
+ // table is live and write a zero.
826
+ Table->setNoStrip ();
827
+ CallInst.addImm (0 );
828
+ }
821
829
} else {
822
- CallInst = MIRBuilder.buildInstrNoInsert (Info.LoweredTailCall ? WebAssembly::RET_CALL : WebAssembly::CALL);
823
-
824
- if (Info.Callee .isGlobal ()) {
825
- CallInst.addGlobalAddress (Info.Callee .getGlobal ());
826
- } else if (Info.Callee .isSymbol ()) {
827
- // TODO: figure out how to trigger/test this
828
- CallInst.addSym (Info.Callee .getMCSymbol ());
829
- } else {
830
- llvm_unreachable (" Trying to lower call with a callee other than reg, global, or a symbol." );
831
- }
830
+ CallInst = MIRBuilder.buildInstrNoInsert (
831
+ Info.LoweredTailCall ? WebAssembly::RET_CALL : WebAssembly::CALL);
832
+
833
+ if (Info.Callee .isGlobal ()) {
834
+ CallInst.addGlobalAddress (Info.Callee .getGlobal ());
835
+ } else if (Info.Callee .isSymbol ()) {
836
+ // TODO: figure out how to trigger/test this
837
+ CallInst.addSym (Info.Callee .getMCSymbol ());
838
+ } else {
839
+ llvm_unreachable (" Trying to lower call with a callee other than reg, "
840
+ " global, or a symbol." );
841
+ }
832
842
}
833
843
834
-
835
844
SmallVector<ArgInfo, 8 > SplitArgs;
836
845
837
846
bool HasSwiftErrorArg = false ;
@@ -1028,8 +1037,9 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
1028
1037
1029
1038
Register DstPtr =
1030
1039
MIRBuilder
1031
- .buildPtrAdd (PtrLLT, VarArgStackPtr,
1032
- MIRBuilder.buildConstant (SizeLLT, Offset).getReg (0 ))
1040
+ .buildPtrAdd (
1041
+ PtrLLT, VarArgStackPtr,
1042
+ MIRBuilder.buildConstant (SizeLLT, Offset).getReg (0 ))
1033
1043
.getReg (0 );
1034
1044
1035
1045
MachineMemOperand *DstMMO = MF.getMachineMemOperand (
@@ -1053,7 +1063,7 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
1053
1063
MIRBuilder.insertInstr (CallInst);
1054
1064
1055
1065
if (Info.LoweredTailCall ) {
1056
- return true ;
1066
+ return true ;
1057
1067
}
1058
1068
1059
1069
if (Info.CanLowerReturn && !Info.OrigRet .Ty ->isVoidTy ()) {
0 commit comments