1//===-- WebAssemblySelectionDAGInfo.cpp - WebAssembly SelectionDAG Info ---===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements the WebAssemblySelectionDAGInfo class.
11///
12//===----------------------------------------------------------------------===//
13
14#include "WebAssemblyTargetMachine.h"
15using namespace llvm;
16
17#define DEBUG_TYPE "wasm-selectiondag-info"
18
19WebAssemblySelectionDAGInfo::~WebAssemblySelectionDAGInfo() = default; // anchor
20
21SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemcpy(
22 SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst, SDValue Src,
23 SDValue Size, Align Alignment, bool IsVolatile, bool AlwaysInline,
24 MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
25 auto &ST = DAG.getMachineFunction().getSubtarget<WebAssemblySubtarget>();
26 if (!ST.hasBulkMemory())
27 return SDValue();
28
29 SDValue MemIdx = DAG.getConstant(Val: 0, DL, VT: MVT::i32);
30 auto LenMVT = ST.hasAddr64() ? MVT::i64 : MVT::i32;
31 return DAG.getNode(Opcode: WebAssemblyISD::MEMORY_COPY, DL, VT: MVT::Other,
32 Ops: {Chain, MemIdx, MemIdx, Dst, Src,
33 DAG.getZExtOrTrunc(Op: Size, DL, VT: LenMVT)});
34}
35
36SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemmove(
37 SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Op1, SDValue Op2,
38 SDValue Op3, Align Alignment, bool IsVolatile,
39 MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
40 return EmitTargetCodeForMemcpy(DAG, DL, Chain, Dst: Op1, Src: Op2, Size: Op3,
41 Alignment, IsVolatile, AlwaysInline: false,
42 DstPtrInfo, SrcPtrInfo);
43}
44
45SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemset(
46 SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst, SDValue Val,
47 SDValue Size, Align Alignment, bool IsVolatile, bool AlwaysInline,
48 MachinePointerInfo DstPtrInfo) const {
49 auto &ST = DAG.getMachineFunction().getSubtarget<WebAssemblySubtarget>();
50 if (!ST.hasBulkMemory())
51 return SDValue();
52
53 SDValue MemIdx = DAG.getConstant(Val: 0, DL, VT: MVT::i32);
54 auto LenMVT = ST.hasAddr64() ? MVT::i64 : MVT::i32;
55 // Only low byte matters for val argument, so anyext the i8
56 return DAG.getNode(Opcode: WebAssemblyISD::MEMORY_FILL, DL, VT: MVT::Other, N1: Chain, N2: MemIdx,
57 N3: Dst, N4: DAG.getAnyExtOrTrunc(Op: Val, DL, VT: MVT::i32),
58 N5: DAG.getZExtOrTrunc(Op: Size, DL, VT: LenMVT));
59}
60