Path: blob/main/contrib/llvm-project/llvm/lib/Target/VE/VECustomDAG.h
35269 views
//===------------ VECustomDAG.h - VE Custom DAG Nodes -----------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines the helper functions that VE uses to lower LLVM code into a9// selection DAG. For example, hiding SDLoc, and easy to use SDNodeFlags.10//11//===----------------------------------------------------------------------===//1213#ifndef LLVM_LIB_TARGET_VE_VECUSTOMDAG_H14#define LLVM_LIB_TARGET_VE_VECUSTOMDAG_H1516#include "VE.h"17#include "VEISelLowering.h"18#include "llvm/CodeGen/SelectionDAG.h"19#include "llvm/CodeGen/TargetLowering.h"2021namespace llvm {2223std::optional<unsigned> getVVPOpcode(unsigned Opcode);2425bool isVVPUnaryOp(unsigned Opcode);26bool isVVPBinaryOp(unsigned Opcode);27bool isVVPReductionOp(unsigned Opcode);2829MVT splitVectorType(MVT VT);3031bool isPackedVectorType(EVT SomeVT);3233bool isMaskType(EVT SomeVT);3435bool isMaskArithmetic(SDValue Op);3637bool isVVPOrVEC(unsigned);3839bool supportsPackedMode(unsigned Opcode, EVT IdiomVT);4041bool isPackingSupportOpcode(unsigned Opc);4243bool maySafelyIgnoreMask(SDValue Op);4445/// The VE backend uses a two-staged process to lower and legalize vector46/// instructions:47//48/// 1. VP and standard vector SDNodes are lowered to SDNodes of the VVP_* layer.49//50// All VVP nodes have a mask and an Active Vector Length (AVL) parameter.51// The AVL parameters refers to the element position in the vector the VVP52// node operates on.53//54//55// 2. The VVP SDNodes are legalized. The AVL in a legal VVP node refers to56// chunks of 64bit. We track this by wrapping the AVL in a LEGALAVL node.57//58// The AVL mechanism in the VE architecture always refers to chunks of59// 64bit, regardless of the actual element type vector instructions are60// operating on. For vector types v256.32 or v256.64 nothing needs to be61// legalized since each element occupies a 64bit chunk - there is no62// difference between counting 64bit chunks or element positions. However,63// all vector types with > 256 elements store more than one logical element64// per 64bit chunk and need to be transformed.65// However legalization is performed, the resulting legal VVP SDNodes will66// have a LEGALAVL node as their AVL operand. The LEGALAVL nodes wraps67// around an AVL that refers to 64 bit chunks just as the architecture68// demands - that is, the wrapped AVL is the correct setting for the VL69// register for this VVP operation to get the desired behavior.70//71/// AVL Functions {72// The AVL operand position of this node.73std::optional<int> getAVLPos(unsigned);7475// Whether this is a LEGALAVL node.76bool isLegalAVL(SDValue AVL);7778// The AVL operand of this node.79SDValue getNodeAVL(SDValue);8081// Mask position of this node.82std::optional<int> getMaskPos(unsigned);8384SDValue getNodeMask(SDValue);8586// Return the AVL operand of this node. If it is a LEGALAVL node, unwrap it.87// Return with the boolean whether unwrapping happened.88std::pair<SDValue, bool> getAnnotatedNodeAVL(SDValue);8990/// } AVL Functions9192/// Node Properties {9394std::optional<EVT> getIdiomaticVectorType(SDNode *Op);9596SDValue getLoadStoreStride(SDValue Op, VECustomDAG &CDAG);9798SDValue getMemoryPtr(SDValue Op);99100SDValue getNodeChain(SDValue Op);101102SDValue getStoredValue(SDValue Op);103104SDValue getNodePassthru(SDValue Op);105106SDValue getGatherScatterIndex(SDValue Op);107108SDValue getGatherScatterScale(SDValue Op);109110unsigned getScalarReductionOpcode(unsigned VVPOC, bool IsMask);111112// Whether this VP_REDUCE_*/ VECREDUCE_*/VVP_REDUCE_* SDNode has a start113// parameter.114bool hasReductionStartParam(unsigned VVPOC);115116/// } Node Properties117118enum class Packing {119Normal = 0, // 256 element standard mode.120Dense = 1 // 512 element packed mode.121};122123// Get the vector or mask register type for this packing and element type.124MVT getLegalVectorType(Packing P, MVT ElemVT);125126// Whether this type belongs to a packed mask or vector register.127Packing getTypePacking(EVT);128129enum class PackElem : int8_t {130Lo = 0, // Integer (63, 32]131Hi = 1 // Float (32, 0]132};133134struct VETargetMasks {135SDValue Mask;136SDValue AVL;137VETargetMasks(SDValue Mask = SDValue(), SDValue AVL = SDValue())138: Mask(Mask), AVL(AVL) {}139};140141class VECustomDAG {142SelectionDAG &DAG;143SDLoc DL;144145public:146SelectionDAG *getDAG() const { return &DAG; }147148VECustomDAG(SelectionDAG &DAG, SDLoc DL) : DAG(DAG), DL(DL) {}149150VECustomDAG(SelectionDAG &DAG, SDValue WhereOp) : DAG(DAG), DL(WhereOp) {}151152VECustomDAG(SelectionDAG &DAG, const SDNode *WhereN) : DAG(DAG), DL(WhereN) {}153154/// getNode {155SDValue getNode(unsigned OC, SDVTList VTL, ArrayRef<SDValue> OpV,156std::optional<SDNodeFlags> Flags = std::nullopt) const {157auto N = DAG.getNode(OC, DL, VTL, OpV);158if (Flags)159N->setFlags(*Flags);160return N;161}162163SDValue getNode(unsigned OC, ArrayRef<EVT> ResVT, ArrayRef<SDValue> OpV,164std::optional<SDNodeFlags> Flags = std::nullopt) const {165auto N = DAG.getNode(OC, DL, ResVT, OpV);166if (Flags)167N->setFlags(*Flags);168return N;169}170171SDValue getNode(unsigned OC, EVT ResVT, ArrayRef<SDValue> OpV,172std::optional<SDNodeFlags> Flags = std::nullopt) const {173auto N = DAG.getNode(OC, DL, ResVT, OpV);174if (Flags)175N->setFlags(*Flags);176return N;177}178179SDValue getUNDEF(EVT VT) const { return DAG.getUNDEF(VT); }180/// } getNode181182/// Legalizing getNode {183SDValue getLegalReductionOpVVP(unsigned VVPOpcode, EVT ResVT, SDValue StartV,184SDValue VectorV, SDValue Mask, SDValue AVL,185SDNodeFlags Flags) const;186/// } Legalizing getNode187188/// Packing {189SDValue getUnpack(EVT DestVT, SDValue Vec, PackElem Part, SDValue AVL) const;190SDValue getPack(EVT DestVT, SDValue LoVec, SDValue HiVec, SDValue AVL) const;191/// } Packing192193SDValue getMergeValues(ArrayRef<SDValue> Values) const {194return DAG.getMergeValues(Values, DL);195}196197SDValue getConstant(uint64_t Val, EVT VT, bool IsTarget = false,198bool IsOpaque = false) const;199200SDValue getConstantMask(Packing Packing, bool AllTrue) const;201SDValue getMaskBroadcast(EVT ResultVT, SDValue Scalar, SDValue AVL) const;202SDValue getBroadcast(EVT ResultVT, SDValue Scalar, SDValue AVL) const;203204// Wrap AVL in a LEGALAVL node (unless it is one already).205SDValue annotateLegalAVL(SDValue AVL) const;206VETargetMasks getTargetSplitMask(SDValue RawMask, SDValue RawAVL,207PackElem Part) const;208209// Splitting support210SDValue getSplitPtrOffset(SDValue Ptr, SDValue ByteStride,211PackElem Part) const;212SDValue getSplitPtrStride(SDValue PackStride) const;213SDValue getGatherScatterAddress(SDValue BasePtr, SDValue Scale, SDValue Index,214SDValue Mask, SDValue AVL) const;215EVT getVectorVT(EVT ElemVT, unsigned NumElems) const {216return EVT::getVectorVT(*DAG.getContext(), ElemVT, NumElems);217}218};219220} // namespace llvm221222#endif // LLVM_LIB_TARGET_VE_VECUSTOMDAG_H223224225