Skip to content

Commit d144b7b

Browse files
committed
[WebAssembly] Use 64-bit table when targeting wasm64
See WebAssembly/memory64#51
1 parent 3ca428c commit d144b7b

File tree

5 files changed

+6
-31
lines changed

5 files changed

+6
-31
lines changed

lld/test/wasm/shared64.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ get_local_func_address:
154154
# CHECK-NEXT: Index: 0
155155
# CHECK-NEXT: ElemType: FUNCREF
156156
# CHECK-NEXT: Limits:
157+
# CHECK-NEXT: Flags: [ IS_64 ]
157158
# CHECK-NEXT: Minimum: 0x2
158159
# CHECK-NEXT: - Module: env
159160
# CHECK-NEXT: Field: __stack_pointer

lld/wasm/SyntheticSections.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,10 @@ void ElemSection::writeBody() {
584584
initExpr.Extended = false;
585585
if (ctx.isPic) {
586586
initExpr.Inst.Opcode = WASM_OPCODE_GLOBAL_GET;
587-
initExpr.Inst.Value.Global =
588-
(config->is64.value_or(false) ? WasmSym::tableBase32
589-
: WasmSym::tableBase)
590-
->getGlobalIndex();
587+
initExpr.Inst.Value.Global = WasmSym::tableBase->getGlobalIndex();
591588
} else {
592-
initExpr.Inst.Opcode = WASM_OPCODE_I32_CONST;
589+
bool is64 = config->is64.value_or(false);
590+
initExpr.Inst.Opcode = is64 ? WASM_OPCODE_I64_CONST : WASM_OPCODE_I32_CONST;
593591
initExpr.Inst.Value.Int32 = config->tableBase;
594592
}
595593
writeInitExpr(os, initExpr);

lld/wasm/Writer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,8 @@ static void finalizeIndirectFunctionTable() {
939939
limits.Flags |= WASM_LIMITS_FLAG_HAS_MAX;
940940
limits.Maximum = limits.Minimum;
941941
}
942+
if (config->is64.value_or(false))
943+
limits.Flags |= WASM_LIMITS_FLAG_IS_64;
942944
WasmSym::indirectFunctionTable->setLimits(limits);
943945
}
944946

llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -885,18 +885,6 @@ bool WebAssemblyFastISel::selectCall(const Instruction *I) {
885885
Table->setNoStrip();
886886
MIB.addImm(0);
887887
}
888-
// See if we must truncate the function pointer.
889-
// CALL_INDIRECT takes an i32, but in wasm64 we represent function pointers
890-
// as 64-bit for uniformity with other pointer types.
891-
// See also: WebAssemblyISelLowering.cpp: LowerCallResults
892-
if (Subtarget->hasAddr64()) {
893-
auto Wrap = BuildMI(*FuncInfo.MBB, std::prev(FuncInfo.InsertPt), MIMD,
894-
TII.get(WebAssembly::I32_WRAP_I64));
895-
Register Reg32 = createResultReg(&WebAssembly::I32RegClass);
896-
Wrap.addReg(Reg32, RegState::Define);
897-
Wrap.addReg(CalleeReg);
898-
CalleeReg = Reg32;
899-
}
900888
}
901889

902890
for (unsigned ArgReg : Args)

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -576,20 +576,6 @@ LowerCallResults(MachineInstr &CallResults, DebugLoc DL, MachineBasicBlock *BB,
576576
const MCInstrDesc &MCID = TII.get(CallOp);
577577
MachineInstrBuilder MIB(MF, MF.CreateMachineInstr(MCID, DL));
578578

579-
// See if we must truncate the function pointer.
580-
// CALL_INDIRECT takes an i32, but in wasm64 we represent function pointers
581-
// as 64-bit for uniformity with other pointer types.
582-
// See also: WebAssemblyFastISel::selectCall
583-
if (IsIndirect && MF.getSubtarget<WebAssemblySubtarget>().hasAddr64()) {
584-
Register Reg32 =
585-
MF.getRegInfo().createVirtualRegister(&WebAssembly::I32RegClass);
586-
auto &FnPtr = CallParams.getOperand(0);
587-
BuildMI(*BB, CallResults.getIterator(), DL,
588-
TII.get(WebAssembly::I32_WRAP_I64), Reg32)
589-
.addReg(FnPtr.getReg());
590-
FnPtr.setReg(Reg32);
591-
}
592-
593579
// Move the function pointer to the end of the arguments for indirect calls
594580
if (IsIndirect) {
595581
auto FnPtr = CallParams.getOperand(0);

0 commit comments

Comments
 (0)