Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 1 | //===-- WebAssemblySelectionDAGInfo.cpp - WebAssembly SelectionDAG Info ---===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 10 | /// This file implements the WebAssemblySelectionDAGInfo class. |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "WebAssemblyTargetMachine.h" |
| 15 | using namespace llvm; |
| 16 | |
| 17 | #define DEBUG_TYPE "wasm-selectiondag-info" |
| 18 | |
Heejin Ahn | 18c56a0 | 2019-02-04 19:13:39 +0000 | [diff] [blame] | 19 | WebAssemblySelectionDAGInfo::~WebAssemblySelectionDAGInfo() = default; // anchor |
Thomas Lively | d99af23 | 2019-02-05 00:49:55 +0000 | [diff] [blame] | 20 | |
| 21 | SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemcpy( |
Thomas Lively | de7a0a1 | 2019-02-13 22:11:16 +0000 | [diff] [blame] | 22 | SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst, SDValue Src, |
| 23 | SDValue Size, unsigned Align, bool IsVolatile, bool AlwaysInline, |
Thomas Lively | d99af23 | 2019-02-05 00:49:55 +0000 | [diff] [blame] | 24 | MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const { |
| 25 | if (!DAG.getMachineFunction() |
| 26 | .getSubtarget<WebAssemblySubtarget>() |
| 27 | .hasBulkMemory()) |
| 28 | return SDValue(); |
| 29 | |
Thomas Lively | de7a0a1 | 2019-02-13 22:11:16 +0000 | [diff] [blame] | 30 | SDValue MemIdx = DAG.getConstant(0, DL, MVT::i32); |
| 31 | return DAG.getNode(WebAssemblyISD::MEMORY_COPY, DL, MVT::Other, |
| 32 | {Chain, MemIdx, MemIdx, Dst, Src, |
| 33 | DAG.getZExtOrTrunc(Size, DL, MVT::i32)}); |
Thomas Lively | d99af23 | 2019-02-05 00:49:55 +0000 | [diff] [blame] | 34 | } |
Thomas Lively | 3150566 | 2019-02-05 20:57:40 +0000 | [diff] [blame] | 35 | |
| 36 | SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemmove( |
| 37 | SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Op1, SDValue Op2, |
| 38 | SDValue Op3, unsigned Align, bool IsVolatile, |
| 39 | MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const { |
| 40 | return EmitTargetCodeForMemcpy(DAG, DL, Chain, Op1, Op2, Op3, Align, |
| 41 | IsVolatile, false, DstPtrInfo, |
| 42 | SrcPtrInfo); |
| 43 | } |
Thomas Lively | bba3f06 | 2019-02-13 22:25:18 +0000 | [diff] [blame] | 44 | |
| 45 | SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemset( |
| 46 | SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst, SDValue Val, |
| 47 | SDValue Size, unsigned Align, bool IsVolatile, |
| 48 | MachinePointerInfo DstPtrInfo) const { |
| 49 | if (!DAG.getMachineFunction() |
| 50 | .getSubtarget<WebAssemblySubtarget>() |
| 51 | .hasBulkMemory()) |
| 52 | return SDValue(); |
| 53 | |
| 54 | SDValue MemIdx = DAG.getConstant(0, DL, MVT::i32); |
| 55 | // Only low byte matters for val argument, so anyext the i8 |
| 56 | return DAG.getNode(WebAssemblyISD::MEMORY_FILL, DL, MVT::Other, Chain, MemIdx, |
| 57 | Dst, DAG.getAnyExtOrTrunc(Val, DL, MVT::i32), |
| 58 | DAG.getZExtOrTrunc(Size, DL, MVT::i32)); |
| 59 | } |