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