Skip to content

Commit aadac67

Browse files
Fix some issues with WebAssemblyCallLowering::lowerCall
1 parent 4118dfe commit aadac67

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

llvm/lib/Target/WebAssembly/GISel/WebAssemblyCallLowering.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,6 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
798798
auto PtrIntLLT = LLT::scalar(PtrSize);
799799

800800
IndirectIdx = MIRBuilder.buildPtrToInt(PtrIntLLT, IndirectIdx).getReg(0);
801-
if (PtrSize > 32) {
802-
IndirectIdx =
803-
MIRBuilder.buildTrunc(LLT::scalar(32), IndirectIdx).getReg(0);
804-
}
805801
} else if (CalleeType.getAddressSpace() ==
806802
WebAssembly::WASM_ADDRESS_SPACE_FUNCREF) {
807803
Table = WebAssembly::getOrCreateFuncrefCallTableSymbol(MF.getContext(),
@@ -833,8 +829,7 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
833829
if (Info.Callee.isGlobal()) {
834830
CallInst.addGlobalAddress(Info.Callee.getGlobal());
835831
} else if (Info.Callee.isSymbol()) {
836-
// TODO: figure out how to trigger/test this
837-
CallInst.addSym(Info.Callee.getMCSymbol());
832+
CallInst.addExternalSymbol(Info.Callee.getSymbolName());
838833
} else {
839834
llvm_unreachable("Trying to lower call with a callee other than reg, "
840835
"global, or a symbol.");
@@ -1078,8 +1073,24 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
10781073
for (auto SplitEVT : SplitEVTs) {
10791074
Register CurVReg = Info.OrigRet.Regs[i];
10801075
ArgInfo CurArgInfo = ArgInfo{CurVReg, SplitEVT.getTypeForEVT(Ctx), 0};
1081-
setArgFlags(CurArgInfo, AttributeList::ReturnIndex, DL, *Info.CB);
1082-
1076+
if (Info.CB) {
1077+
setArgFlags(CurArgInfo, AttributeList::ReturnIndex, DL, *Info.CB);
1078+
} else {
1079+
// we don't have a call base, so chances are we're looking at a libcall
1080+
// (external symbol).
1081+
1082+
// TODO: figure out how to get ALL the correct attributes
1083+
auto &Flags = CurArgInfo.Flags[0];
1084+
PointerType *PtrTy =
1085+
dyn_cast<PointerType>(CurArgInfo.Ty->getScalarType());
1086+
if (PtrTy) {
1087+
Flags.setPointer();
1088+
Flags.setPointerAddrSpace(PtrTy->getPointerAddressSpace());
1089+
}
1090+
Align MemAlign = DL.getABITypeAlign(CurArgInfo.Ty);
1091+
Flags.setMemAlign(MemAlign);
1092+
Flags.setOrigAlign(MemAlign);
1093+
}
10831094
splitToValueTypes(CurArgInfo, SplitReturns, DL, CallConv);
10841095
++i;
10851096
}

0 commit comments

Comments
 (0)