xref: /freebsd/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.cpp (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
10b57cec5SDimitry Andric //===-- WebAssemblySelectionDAGInfo.cpp - WebAssembly SelectionDAG Info ---===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric ///
90b57cec5SDimitry Andric /// \file
100b57cec5SDimitry Andric /// This file implements the WebAssemblySelectionDAGInfo class.
110b57cec5SDimitry Andric ///
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #include "WebAssemblyTargetMachine.h"
150b57cec5SDimitry Andric using namespace llvm;
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric #define DEBUG_TYPE "wasm-selectiondag-info"
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric WebAssemblySelectionDAGInfo::~WebAssemblySelectionDAGInfo() = default; // anchor
200b57cec5SDimitry Andric 
EmitTargetCodeForMemcpy(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Dst,SDValue Src,SDValue Size,Align Alignment,bool IsVolatile,bool AlwaysInline,MachinePointerInfo DstPtrInfo,MachinePointerInfo SrcPtrInfo) const210b57cec5SDimitry Andric SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemcpy(
220b57cec5SDimitry Andric     SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst, SDValue Src,
235ffd83dbSDimitry Andric     SDValue Size, Align Alignment, bool IsVolatile, bool AlwaysInline,
240b57cec5SDimitry Andric     MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
255ffd83dbSDimitry Andric   auto &ST = DAG.getMachineFunction().getSubtarget<WebAssemblySubtarget>();
265ffd83dbSDimitry Andric   if (!ST.hasBulkMemory())
270b57cec5SDimitry Andric     return SDValue();
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric   SDValue MemIdx = DAG.getConstant(0, DL, MVT::i32);
305ffd83dbSDimitry Andric   auto LenMVT = ST.hasAddr64() ? MVT::i64 : MVT::i32;
310b57cec5SDimitry Andric   return DAG.getNode(WebAssemblyISD::MEMORY_COPY, DL, MVT::Other,
320b57cec5SDimitry Andric                      {Chain, MemIdx, MemIdx, Dst, Src,
335ffd83dbSDimitry Andric                       DAG.getZExtOrTrunc(Size, DL, LenMVT)});
340b57cec5SDimitry Andric }
350b57cec5SDimitry Andric 
EmitTargetCodeForMemmove(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Op1,SDValue Op2,SDValue Op3,Align Alignment,bool IsVolatile,MachinePointerInfo DstPtrInfo,MachinePointerInfo SrcPtrInfo) const360b57cec5SDimitry Andric SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemmove(
370b57cec5SDimitry Andric     SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Op1, SDValue Op2,
385ffd83dbSDimitry Andric     SDValue Op3, Align Alignment, bool IsVolatile,
390b57cec5SDimitry Andric     MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
405ffd83dbSDimitry Andric   return EmitTargetCodeForMemcpy(DAG, DL, Chain, Op1, Op2, Op3,
415ffd83dbSDimitry Andric                                  Alignment, IsVolatile, false,
425ffd83dbSDimitry Andric                                  DstPtrInfo, SrcPtrInfo);
430b57cec5SDimitry Andric }
440b57cec5SDimitry Andric 
EmitTargetCodeForMemset(SelectionDAG & DAG,const SDLoc & DL,SDValue Chain,SDValue Dst,SDValue Val,SDValue Size,Align Alignment,bool IsVolatile,bool AlwaysInline,MachinePointerInfo DstPtrInfo) const450b57cec5SDimitry Andric SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemset(
460b57cec5SDimitry Andric     SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst, SDValue Val,
47*81ad6265SDimitry Andric     SDValue Size, Align Alignment, bool IsVolatile, bool AlwaysInline,
480b57cec5SDimitry Andric     MachinePointerInfo DstPtrInfo) const {
495ffd83dbSDimitry Andric   auto &ST = DAG.getMachineFunction().getSubtarget<WebAssemblySubtarget>();
505ffd83dbSDimitry Andric   if (!ST.hasBulkMemory())
510b57cec5SDimitry Andric     return SDValue();
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric   SDValue MemIdx = DAG.getConstant(0, DL, MVT::i32);
545ffd83dbSDimitry Andric   auto LenMVT = ST.hasAddr64() ? MVT::i64 : MVT::i32;
550b57cec5SDimitry Andric   // Only low byte matters for val argument, so anyext the i8
560b57cec5SDimitry Andric   return DAG.getNode(WebAssemblyISD::MEMORY_FILL, DL, MVT::Other, Chain, MemIdx,
570b57cec5SDimitry Andric                      Dst, DAG.getAnyExtOrTrunc(Val, DL, MVT::i32),
585ffd83dbSDimitry Andric                      DAG.getZExtOrTrunc(Size, DL, LenMVT));
590b57cec5SDimitry Andric }
60