Skip to content

Commit 4118dfe

Browse files
Fix formatting
1 parent 4edcd29 commit 4118dfe

File tree

1 file changed

+69
-59
lines changed

1 file changed

+69
-59
lines changed

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

Lines changed: 69 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,8 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
697697
LLVMContext &Ctx = MIRBuilder.getContext();
698698
const WebAssemblyTargetLowering &TLI = *getTLI<WebAssemblyTargetLowering>();
699699
MachineRegisterInfo &MRI = *MIRBuilder.getMRI();
700-
const WebAssemblySubtarget &Subtarget = MF.getSubtarget<WebAssemblySubtarget>();
700+
const WebAssemblySubtarget &Subtarget =
701+
MF.getSubtarget<WebAssemblySubtarget>();
701702

702703
CallingConv::ID CallConv = Info.CallConv;
703704
if (!callingConvSupported(CallConv)) {
@@ -716,7 +717,7 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
716717
*/
717718

718719
if (Info.IsTailCall) {
719-
Info.LoweredTailCall = true;
720+
Info.LoweredTailCall = true;
720721
auto NoTail = [&](const char *Msg) {
721722
if (Info.CB && Info.CB->isMustTailCall())
722723
fail(MIRBuilder, Msg);
@@ -773,65 +774,73 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
773774
Register IndirectIdx;
774775

775776
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);
810804
}
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+
}
811819

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+
}
821829
} 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+
}
832842
}
833843

834-
835844
SmallVector<ArgInfo, 8> SplitArgs;
836845

837846
bool HasSwiftErrorArg = false;
@@ -1028,8 +1037,9 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
10281037

10291038
Register DstPtr =
10301039
MIRBuilder
1031-
.buildPtrAdd(PtrLLT, VarArgStackPtr,
1032-
MIRBuilder.buildConstant(SizeLLT, Offset).getReg(0))
1040+
.buildPtrAdd(
1041+
PtrLLT, VarArgStackPtr,
1042+
MIRBuilder.buildConstant(SizeLLT, Offset).getReg(0))
10331043
.getReg(0);
10341044

10351045
MachineMemOperand *DstMMO = MF.getMachineMemOperand(
@@ -1053,7 +1063,7 @@ bool WebAssemblyCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
10531063
MIRBuilder.insertInstr(CallInst);
10541064

10551065
if (Info.LoweredTailCall) {
1056-
return true;
1066+
return true;
10571067
}
10581068

10591069
if (Info.CanLowerReturn && !Info.OrigRet.Ty->isVoidTy()) {

0 commit comments

Comments
 (0)