summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp')
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp54
1 files changed, 36 insertions, 18 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
index 82b032267d55..171d59ae4c6b 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
@@ -16,11 +16,11 @@
//===----------------------------------------------------------------------===//
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
+#include "Utils/WebAssemblyUtilities.h"
#include "WebAssembly.h"
#include "WebAssemblyMachineFunctionInfo.h"
#include "WebAssemblySubtarget.h"
#include "WebAssemblyTargetMachine.h"
-#include "WebAssemblyUtilities.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/CodeGen/FastISel.h"
#include "llvm/CodeGen/FunctionLoweringInfo.h"
@@ -130,21 +130,21 @@ private:
case MVT::i64:
case MVT::f32:
case MVT::f64:
+ return VT;
case MVT::funcref:
case MVT::externref:
- return VT;
+ if (Subtarget->hasReferenceTypes())
+ return VT;
+ break;
case MVT::f16:
return MVT::f32;
case MVT::v16i8:
case MVT::v8i16:
case MVT::v4i32:
case MVT::v4f32:
- if (Subtarget->hasSIMD128())
- return VT;
- break;
case MVT::v2i64:
case MVT::v2f64:
- if (Subtarget->hasUnimplementedSIMD128())
+ if (Subtarget->hasSIMD128())
return VT;
break;
default:
@@ -869,18 +869,32 @@ bool WebAssemblyFastISel::selectCall(const Instruction *I) {
if (IsDirect) {
MIB.addGlobalAddress(Func);
} else {
- // Add placeholders for the type index and immediate flags
- MIB.addImm(0);
+ // Placeholder for the type index.
MIB.addImm(0);
-
- // Ensure that the object file has a __indirect_function_table import, as we
- // call_indirect against it.
- MCSymbolWasm *Sym = WebAssembly::getOrCreateFunctionTableSymbol(
- MF->getMMI().getContext(), "__indirect_function_table");
- // Until call_indirect emits TABLE_NUMBER relocs against this symbol, mark
- // it as NO_STRIP so as to ensure that the indirect function table makes it
- // to linked output.
- Sym->setNoStrip();
+ // The table into which this call_indirect indexes.
+ MCSymbolWasm *Table = WebAssembly::getOrCreateFunctionTableSymbol(
+ MF->getMMI().getContext(), Subtarget);
+ if (Subtarget->hasReferenceTypes()) {
+ MIB.addSym(Table);
+ } else {
+ // Otherwise for the MVP there is at most one table whose number is 0, but
+ // we can't write a table symbol or issue relocations. Instead we just
+ // ensure the table is live.
+ Table->setNoStrip();
+ MIB.addImm(0);
+ }
+ // See if we must truncate the function pointer.
+ // CALL_INDIRECT takes an i32, but in wasm64 we represent function pointers
+ // as 64-bit for uniformity with other pointer types.
+ // See also: WebAssemblyISelLowering.cpp: LowerCallResults
+ if (Subtarget->hasAddr64()) {
+ auto Wrap = BuildMI(*FuncInfo.MBB, std::prev(FuncInfo.InsertPt), DbgLoc,
+ TII.get(WebAssembly::I32_WRAP_I64));
+ unsigned Reg32 = createResultReg(&WebAssembly::I32RegClass);
+ Wrap.addReg(Reg32, RegState::Define);
+ Wrap.addReg(CalleeReg);
+ CalleeReg = Reg32;
+ }
}
for (unsigned ArgReg : Args)
@@ -1156,7 +1170,7 @@ bool WebAssemblyFastISel::selectBitCast(const Instruction *I) {
}
Register Reg = fastEmit_ISD_BITCAST_r(VT.getSimpleVT(), RetVT.getSimpleVT(),
- In, I->getOperand(0)->hasOneUse());
+ In);
if (!Reg)
return false;
MachineBasicBlock::iterator Iter = FuncInfo.InsertPt;
@@ -1171,6 +1185,8 @@ bool WebAssemblyFastISel::selectLoad(const Instruction *I) {
const auto *Load = cast<LoadInst>(I);
if (Load->isAtomic())
return false;
+ if (!WebAssembly::isDefaultAddressSpace(Load->getPointerAddressSpace()))
+ return false;
if (!Subtarget->hasSIMD128() && Load->getType()->isVectorTy())
return false;
@@ -1229,6 +1245,8 @@ bool WebAssemblyFastISel::selectStore(const Instruction *I) {
const auto *Store = cast<StoreInst>(I);
if (Store->isAtomic())
return false;
+ if (!WebAssembly::isDefaultAddressSpace(Store->getPointerAddressSpace()))
+ return false;
if (!Subtarget->hasSIMD128() &&
Store->getValueOperand()->getType()->isVectorTy())
return false;