13
13
14
14
#include "WebAssemblyISelLowering.h"
15
15
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
16
- #include "Utils/WebAssemblyTypeUtilities.h"
17
16
#include "Utils/WebAssemblyUtilities.h"
18
17
#include "WebAssemblyMachineFunctionInfo.h"
19
18
#include "WebAssemblySubtarget.h"
@@ -67,10 +66,6 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
67
66
addRegisterClass(MVT::v2i64, &WebAssembly::V128RegClass);
68
67
addRegisterClass(MVT::v2f64, &WebAssembly::V128RegClass);
69
68
}
70
- if (Subtarget->hasReferenceTypes()) {
71
- addRegisterClass(MVT::externref, &WebAssembly::EXTERNREFRegClass);
72
- addRegisterClass(MVT::funcref, &WebAssembly::FUNCREFRegClass);
73
- }
74
69
// Compute derived properties from the register classes.
75
70
computeRegisterProperties(Subtarget->getRegisterInfo());
76
71
@@ -87,12 +82,6 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
87
82
setOperationAction(ISD::STORE, T, Custom);
88
83
}
89
84
}
90
- if (Subtarget->hasReferenceTypes()) {
91
- for (auto T : {MVT::externref, MVT::funcref}) {
92
- setOperationAction(ISD::LOAD, T, Custom);
93
- setOperationAction(ISD::STORE, T, Custom);
94
- }
95
- }
96
85
97
86
setOperationAction(ISD::GlobalAddress, MVTPtr, Custom);
98
87
setOperationAction(ISD::GlobalTLSAddress, MVTPtr, Custom);
@@ -479,16 +468,6 @@ LowerCallResults(MachineInstr &CallResults, DebugLoc DL, MachineBasicBlock *BB,
479
468
bool IsIndirect = CallParams.getOperand(0).isReg();
480
469
bool IsRetCall = CallResults.getOpcode() == WebAssembly::RET_CALL_RESULTS;
481
470
482
- bool IsFuncrefCall = false;
483
- if (IsIndirect) {
484
- Register Reg = CallParams.getOperand(0).getReg();
485
- const MachineFunction *MF = BB->getParent();
486
- const MachineRegisterInfo &MRI = MF->getRegInfo();
487
- const TargetRegisterClass *TRC = MRI.getRegClass(Reg);
488
- IsFuncrefCall = (TRC == &WebAssembly::FUNCREFRegClass);
489
- assert(!IsFuncrefCall || Subtarget->hasReferenceTypes());
490
- }
491
-
492
471
unsigned CallOp;
493
472
if (IsIndirect && IsRetCall) {
494
473
CallOp = WebAssembly::RET_CALL_INDIRECT;
@@ -532,11 +511,8 @@ LowerCallResults(MachineInstr &CallResults, DebugLoc DL, MachineBasicBlock *BB,
532
511
// Placeholder for the type index.
533
512
MIB.addImm(0);
534
513
// The table into which this call_indirect indexes.
535
- MCSymbolWasm *Table = IsFuncrefCall
536
- ? WebAssembly::getOrCreateFuncrefCallTableSymbol(
537
- MF.getContext(), Subtarget)
538
- : WebAssembly::getOrCreateFunctionTableSymbol(
539
- MF.getContext(), Subtarget);
514
+ MCSymbolWasm *Table =
515
+ WebAssembly::getOrCreateFunctionTableSymbol(MF.getContext(), Subtarget);
540
516
if (Subtarget->hasReferenceTypes()) {
541
517
MIB.addSym(Table);
542
518
} else {
@@ -555,39 +531,6 @@ LowerCallResults(MachineInstr &CallResults, DebugLoc DL, MachineBasicBlock *BB,
555
531
CallParams.eraseFromParent();
556
532
CallResults.eraseFromParent();
557
533
558
- // If this is a funcref call, to avoid hidden GC roots, we need to clear the
559
- // table slot with ref.null upon call_indirect return.
560
- //
561
- // This generates the following code, which comes right after a call_indirect
562
- // of a funcref:
563
- //
564
- // i32.const 0
565
- // ref.null func
566
- // table.set __funcref_call_table
567
- if (IsIndirect && IsFuncrefCall) {
568
- MCSymbolWasm *Table = WebAssembly::getOrCreateFuncrefCallTableSymbol(
569
- MF.getContext(), Subtarget);
570
- Register RegZero =
571
- MF.getRegInfo().createVirtualRegister(&WebAssembly::I32RegClass);
572
- MachineInstr *Const0 =
573
- BuildMI(MF, DL, TII.get(WebAssembly::CONST_I32), RegZero).addImm(0);
574
- BB->insertAfter(MIB.getInstr()->getIterator(), Const0);
575
-
576
- Register RegFuncref =
577
- MF.getRegInfo().createVirtualRegister(&WebAssembly::FUNCREFRegClass);
578
- MachineInstr *RefNull =
579
- BuildMI(MF, DL, TII.get(WebAssembly::REF_NULL_FUNCREF), RegFuncref)
580
- .addImm(static_cast<int32_t>(WebAssembly::HeapType::Funcref));
581
- BB->insertAfter(Const0->getIterator(), RefNull);
582
-
583
- MachineInstr *TableSet =
584
- BuildMI(MF, DL, TII.get(WebAssembly::TABLE_SET_FUNCREF))
585
- .addSym(Table)
586
- .addReg(RegZero)
587
- .addReg(RegFuncref);
588
- BB->insertAfter(RefNull->getIterator(), TableSet);
589
- }
590
-
591
534
return BB;
592
535
}
593
536
@@ -1111,33 +1054,6 @@ WebAssemblyTargetLowering::LowerCall(CallLoweringInfo &CLI,
1111
1054
InTys.push_back(In.VT);
1112
1055
}
1113
1056
1114
- // Lastly, if this is a call to a funcref we need to add an instruction
1115
- // table.set to the chain and transform the call.
1116
- if (CLI.CB && isFuncref(CLI.CB->getCalledOperand())) {
1117
- // In the absence of function references proposal where a funcref call is
1118
- // lowered to call_ref, using reference types we generate a table.set to set
1119
- // the funcref to a special table used solely for this purpose, followed by
1120
- // a call_indirect. Here we just generate the table set, and return the
1121
- // SDValue of the table.set so that LowerCall can finalize the lowering by
1122
- // generating the call_indirect.
1123
- SDValue Chain = Ops[0];
1124
-
1125
- MCSymbolWasm *Table = WebAssembly::getOrCreateFuncrefCallTableSymbol(
1126
- MF.getContext(), Subtarget);
1127
- SDValue Sym = DAG.getMCSymbol(Table, PtrVT);
1128
- SDValue TableSlot = DAG.getConstant(0, DL, MVT::i32);
1129
- SDValue TableSetOps[] = {Chain, Sym, TableSlot, Callee};
1130
- SDValue TableSet = DAG.getMemIntrinsicNode(
1131
- WebAssemblyISD::TABLE_SET, DL, DAG.getVTList(MVT::Other), TableSetOps,
1132
- MVT::funcref,
1133
- // Machine Mem Operand args
1134
- MachinePointerInfo(WasmAddressSpace::FUNCREF),
1135
- CLI.CB->getCalledOperand()->getPointerAlignment(DAG.getDataLayout()),
1136
- MachineMemOperand::MOStore);
1137
-
1138
- Ops[0] = TableSet; // The new chain is the TableSet itself
1139
- }
1140
-
1141
1057
if (CLI.IsTailCall) {
1142
1058
// ret_calls do not return values to the current frame
1143
1059
SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
@@ -1369,13 +1285,6 @@ static Optional<unsigned> IsWebAssemblyLocal(SDValue Op, SelectionDAG &DAG) {
1369
1285
return WebAssemblyFrameLowering::getLocalForStackObject(MF, FI->getIndex());
1370
1286
}
1371
1287
1372
- bool WebAssemblyTargetLowering::isFuncref(const Value *Op) const {
1373
- const Type *Ty = Op->getType();
1374
-
1375
- return isa<PointerType>(Ty) &&
1376
- Ty->getPointerAddressSpace() == WasmAddressSpace::FUNCREF;
1377
- }
1378
-
1379
1288
SDValue WebAssemblyTargetLowering::LowerStore(SDValue Op,
1380
1289
SelectionDAG &DAG) const {
1381
1290
SDLoc DL(Op);
0 commit comments