brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · cf5cc41 Raw
89 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file implements the WebAssemblySelectionDAGInfo class.11///12//===----------------------------------------------------------------------===//13 14#include "WebAssemblySelectionDAGInfo.h"15#include "WebAssemblyTargetMachine.h"16 17#define GET_SDNODE_DESC18#include "WebAssemblyGenSDNodeInfo.inc"19 20using namespace llvm;21 22#define DEBUG_TYPE "wasm-selectiondag-info"23 24WebAssemblySelectionDAGInfo::WebAssemblySelectionDAGInfo()25    : SelectionDAGGenTargetInfo(WebAssemblyGenSDNodeInfo) {}26 27WebAssemblySelectionDAGInfo::~WebAssemblySelectionDAGInfo() = default; // anchor28 29const char *30WebAssemblySelectionDAGInfo::getTargetNodeName(unsigned Opcode) const {31  switch (static_cast<WebAssemblyISD::NodeType>(Opcode)) {32  case WebAssemblyISD::CALL:33    return "WebAssemblyISD::CALL";34  case WebAssemblyISD::RET_CALL:35    return "WebAssemblyISD::RET_CALL";36  }37 38  return SelectionDAGGenTargetInfo::getTargetNodeName(Opcode);39}40 41SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemcpy(42    SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst, SDValue Src,43    SDValue Size, Align Alignment, bool IsVolatile, bool AlwaysInline,44    MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {45  auto &ST = DAG.getMachineFunction().getSubtarget<WebAssemblySubtarget>();46  if (!ST.hasBulkMemoryOpt())47    return SDValue();48 49  SDValue MemIdx = DAG.getConstant(0, DL, MVT::i32);50  auto LenMVT = ST.hasAddr64() ? MVT::i64 : MVT::i32;51 52  // Use `MEMCPY` here instead of `MEMORY_COPY` because `memory.copy` traps53  // if the pointers are invalid even if the length is zero. `MEMCPY` gets54  // extra code to handle this in the way that LLVM IR expects.55  return DAG.getNode(56      WebAssemblyISD::MEMCPY, DL, MVT::Other,57      {Chain, MemIdx, MemIdx, Dst, Src, DAG.getZExtOrTrunc(Size, DL, LenMVT)});58}59 60SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemmove(61    SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Op1, SDValue Op2,62    SDValue Op3, Align Alignment, bool IsVolatile,63    MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {64  return EmitTargetCodeForMemcpy(DAG, DL, Chain, Op1, Op2, Op3,65                                 Alignment, IsVolatile, false,66                                 DstPtrInfo, SrcPtrInfo);67}68 69SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemset(70    SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst, SDValue Val,71    SDValue Size, Align Alignment, bool IsVolatile, bool AlwaysInline,72    MachinePointerInfo DstPtrInfo) const {73  auto &ST = DAG.getMachineFunction().getSubtarget<WebAssemblySubtarget>();74  if (!ST.hasBulkMemoryOpt())75    return SDValue();76 77  SDValue MemIdx = DAG.getConstant(0, DL, MVT::i32);78  auto LenMVT = ST.hasAddr64() ? MVT::i64 : MVT::i32;79 80  // Use `MEMSET` here instead of `MEMORY_FILL` because `memory.fill` traps81  // if the pointers are invalid even if the length is zero. `MEMSET` gets82  // extra code to handle this in the way that LLVM IR expects.83  //84  // Only low byte matters for val argument, so anyext the i885  return DAG.getNode(WebAssemblyISD::MEMSET, DL, MVT::Other, Chain, MemIdx, Dst,86                     DAG.getAnyExtOrTrunc(Val, DL, MVT::i32),87                     DAG.getZExtOrTrunc(Size, DL, LenMVT));88}89