Path: blob/main/contrib/llvm-project/llvm/lib/Target/VE/VEISelLowering.h
35269 views
//===-- VEISelLowering.h - VE DAG Lowering Interface ------------*- 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 interfaces that VE uses to lower LLVM code into a9// selection DAG.10//11//===----------------------------------------------------------------------===//1213#ifndef LLVM_LIB_TARGET_VE_VEISELLOWERING_H14#define LLVM_LIB_TARGET_VE_VEISELLOWERING_H1516#include "VE.h"17#include "llvm/CodeGen/TargetLowering.h"1819namespace llvm {20class VESubtarget;2122namespace VEISD {23enum NodeType : unsigned {24FIRST_NUMBER = ISD::BUILTIN_OP_END,2526CMPI, // Compare between two signed integer values.27CMPU, // Compare between two unsigned integer values.28CMPF, // Compare between two floating-point values.29CMPQ, // Compare between two quad floating-point values.30CMOV, // Select between two values using the result of comparison.3132CALL, // A call instruction.33EH_SJLJ_LONGJMP, // SjLj exception handling longjmp.34EH_SJLJ_SETJMP, // SjLj exception handling setjmp.35EH_SJLJ_SETUP_DISPATCH, // SjLj exception handling setup_dispatch.36GETFUNPLT, // Load function address through %plt insturction.37GETTLSADDR, // Load address for TLS access.38GETSTACKTOP, // Retrieve address of stack top (first address of39// locals and temporaries).40GLOBAL_BASE_REG, // Global base reg for PIC.41Hi, // Hi/Lo operations, typically on a global address.42Lo, // Hi/Lo operations, typically on a global address.43RET_GLUE, // Return with a flag operand.44TS1AM, // A TS1AM instruction used for 1/2 bytes swap.45VEC_UNPACK_LO, // unpack the lo v256 slice of a packed v512 vector.46VEC_UNPACK_HI, // unpack the hi v256 slice of a packed v512 vector.47// 0: v512 vector, 1: AVL48VEC_PACK, // pack a lo and a hi vector into one v512 vector49// 0: v256 lo vector, 1: v256 hi vector, 2: AVL5051VEC_BROADCAST, // A vector broadcast instruction.52// 0: scalar value, 1: VL53REPL_I32,54REPL_F32, // Replicate subregister to other half.5556// Annotation as a wrapper. LEGALAVL(VL) means that VL refers to 64bit of57// data, whereas the raw EVL coming in from VP nodes always refers to number58// of elements, regardless of their size.59LEGALAVL,6061// VVP_* nodes.62#define ADD_VVP_OP(VVP_NAME, ...) VVP_NAME,63#include "VVPNodes.def"64};65}6667/// Convert a DAG integer condition code to a VE ICC condition.68inline static VECC::CondCode intCondCode2Icc(ISD::CondCode CC) {69switch (CC) {70default:71llvm_unreachable("Unknown integer condition code!");72case ISD::SETEQ:73return VECC::CC_IEQ;74case ISD::SETNE:75return VECC::CC_INE;76case ISD::SETLT:77return VECC::CC_IL;78case ISD::SETGT:79return VECC::CC_IG;80case ISD::SETLE:81return VECC::CC_ILE;82case ISD::SETGE:83return VECC::CC_IGE;84case ISD::SETULT:85return VECC::CC_IL;86case ISD::SETULE:87return VECC::CC_ILE;88case ISD::SETUGT:89return VECC::CC_IG;90case ISD::SETUGE:91return VECC::CC_IGE;92}93}9495/// Convert a DAG floating point condition code to a VE FCC condition.96inline static VECC::CondCode fpCondCode2Fcc(ISD::CondCode CC) {97switch (CC) {98default:99llvm_unreachable("Unknown fp condition code!");100case ISD::SETFALSE:101return VECC::CC_AF;102case ISD::SETEQ:103case ISD::SETOEQ:104return VECC::CC_EQ;105case ISD::SETNE:106case ISD::SETONE:107return VECC::CC_NE;108case ISD::SETLT:109case ISD::SETOLT:110return VECC::CC_L;111case ISD::SETGT:112case ISD::SETOGT:113return VECC::CC_G;114case ISD::SETLE:115case ISD::SETOLE:116return VECC::CC_LE;117case ISD::SETGE:118case ISD::SETOGE:119return VECC::CC_GE;120case ISD::SETO:121return VECC::CC_NUM;122case ISD::SETUO:123return VECC::CC_NAN;124case ISD::SETUEQ:125return VECC::CC_EQNAN;126case ISD::SETUNE:127return VECC::CC_NENAN;128case ISD::SETULT:129return VECC::CC_LNAN;130case ISD::SETUGT:131return VECC::CC_GNAN;132case ISD::SETULE:133return VECC::CC_LENAN;134case ISD::SETUGE:135return VECC::CC_GENAN;136case ISD::SETTRUE:137return VECC::CC_AT;138}139}140141/// getImmVal - get immediate representation of integer value142inline static uint64_t getImmVal(const ConstantSDNode *N) {143return N->getSExtValue();144}145146/// getFpImmVal - get immediate representation of floating point value147inline static uint64_t getFpImmVal(const ConstantFPSDNode *N) {148const APInt &Imm = N->getValueAPF().bitcastToAPInt();149uint64_t Val = Imm.getZExtValue();150if (Imm.getBitWidth() == 32) {151// Immediate value of float place places at higher bits on VE.152Val <<= 32;153}154return Val;155}156157class VECustomDAG;158159class VETargetLowering : public TargetLowering {160const VESubtarget *Subtarget;161162void initRegisterClasses();163void initSPUActions();164void initVPUActions();165166public:167VETargetLowering(const TargetMachine &TM, const VESubtarget &STI);168169const char *getTargetNodeName(unsigned Opcode) const override;170MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override {171return MVT::i32;172}173174Register getRegisterByName(const char *RegName, LLT VT,175const MachineFunction &MF) const override;176177/// getSetCCResultType - Return the ISD::SETCC ValueType178EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,179EVT VT) const override;180181SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,182bool isVarArg,183const SmallVectorImpl<ISD::InputArg> &Ins,184const SDLoc &dl, SelectionDAG &DAG,185SmallVectorImpl<SDValue> &InVals) const override;186187SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,188SmallVectorImpl<SDValue> &InVals) const override;189190bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,191bool isVarArg,192const SmallVectorImpl<ISD::OutputArg> &ArgsFlags,193LLVMContext &Context) const override;194SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,195const SmallVectorImpl<ISD::OutputArg> &Outs,196const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,197SelectionDAG &DAG) const override;198199/// Helper functions for atomic operations.200bool shouldInsertFencesForAtomic(const Instruction *I) const override {201// VE uses release consistency, so need fence for each atomics.202return true;203}204Instruction *emitLeadingFence(IRBuilderBase &Builder, Instruction *Inst,205AtomicOrdering Ord) const override;206Instruction *emitTrailingFence(IRBuilderBase &Builder, Instruction *Inst,207AtomicOrdering Ord) const override;208TargetLoweringBase::AtomicExpansionKind209shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;210ISD::NodeType getExtendForAtomicOps() const override {211return ISD::ANY_EXTEND;212}213214/// Custom Lower {215TargetLoweringBase::LegalizeAction216getCustomOperationAction(SDNode &) const override;217218SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;219unsigned getJumpTableEncoding() const override;220const MCExpr *LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI,221const MachineBasicBlock *MBB,222unsigned Uid,223MCContext &Ctx) const override;224SDValue getPICJumpTableRelocBase(SDValue Table,225SelectionDAG &DAG) const override;226// VE doesn't need getPICJumpTableRelocBaseExpr since it is used for only227// EK_LabelDifference32.228229SDValue lowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG) const;230SDValue lowerATOMIC_SWAP(SDValue Op, SelectionDAG &DAG) const;231SDValue lowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;232SDValue lowerConstantPool(SDValue Op, SelectionDAG &DAG) const;233SDValue lowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;234SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;235SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;236SDValue lowerEH_SJLJ_SETUP_DISPATCH(SDValue Op, SelectionDAG &DAG) const;237SDValue lowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;238SDValue lowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;239SDValue lowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;240SDValue lowerJumpTable(SDValue Op, SelectionDAG &DAG) const;241SDValue lowerLOAD(SDValue Op, SelectionDAG &DAG) const;242SDValue lowerSTORE(SDValue Op, SelectionDAG &DAG) const;243SDValue lowerToTLSGeneralDynamicModel(SDValue Op, SelectionDAG &DAG) const;244SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;245SDValue lowerVAARG(SDValue Op, SelectionDAG &DAG) const;246247SDValue lowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;248SDValue lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;249SDValue lowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;250/// } Custom Lower251252/// Replace the results of node with an illegal result253/// type with new values built out of custom code.254///255void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,256SelectionDAG &DAG) const override;257258/// Custom Inserter {259MachineBasicBlock *260EmitInstrWithCustomInserter(MachineInstr &MI,261MachineBasicBlock *MBB) const override;262MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr &MI,263MachineBasicBlock *MBB) const;264MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr &MI,265MachineBasicBlock *MBB) const;266MachineBasicBlock *emitSjLjDispatchBlock(MachineInstr &MI,267MachineBasicBlock *BB) const;268269void setupEntryBlockForSjLj(MachineInstr &MI, MachineBasicBlock *MBB,270MachineBasicBlock *DispatchBB, int FI,271int Offset) const;272// Setup basic block address.273Register prepareMBB(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,274MachineBasicBlock *TargetBB, const DebugLoc &DL) const;275// Prepare function/variable address.276Register prepareSymbol(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,277StringRef Symbol, const DebugLoc &DL, bool IsLocal,278bool IsCall) const;279/// } Custom Inserter280281/// VVP Lowering {282SDValue lowerToVVP(SDValue Op, SelectionDAG &DAG) const;283SDValue lowerVVP_LOAD_STORE(SDValue Op, VECustomDAG &) const;284SDValue lowerVVP_GATHER_SCATTER(SDValue Op, VECustomDAG &) const;285286SDValue legalizeInternalVectorOp(SDValue Op, SelectionDAG &DAG) const;287SDValue legalizeInternalLoadStoreOp(SDValue Op, VECustomDAG &CDAG) const;288SDValue splitVectorOp(SDValue Op, VECustomDAG &CDAG) const;289SDValue splitPackedLoadStore(SDValue Op, VECustomDAG &CDAG) const;290SDValue legalizePackedAVL(SDValue Op, VECustomDAG &CDAG) const;291SDValue splitMaskArithmetic(SDValue Op, SelectionDAG &DAG) const;292/// } VVPLowering293294/// Custom DAGCombine {295SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;296297SDValue combineSelect(SDNode *N, DAGCombinerInfo &DCI) const;298SDValue combineSelectCC(SDNode *N, DAGCombinerInfo &DCI) const;299SDValue combineTRUNCATE(SDNode *N, DAGCombinerInfo &DCI) const;300/// } Custom DAGCombine301302SDValue withTargetFlags(SDValue Op, unsigned TF, SelectionDAG &DAG) const;303SDValue makeHiLoPair(SDValue Op, unsigned HiTF, unsigned LoTF,304SelectionDAG &DAG) const;305SDValue makeAddress(SDValue Op, SelectionDAG &DAG) const;306307bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;308bool isFPImmLegal(const APFloat &Imm, EVT VT,309bool ForCodeSize) const override;310/// Returns true if the target allows unaligned memory accesses of the311/// specified type.312bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS, Align A,313MachineMemOperand::Flags Flags,314unsigned *Fast) const override;315316/// Inline Assembly {317318ConstraintType getConstraintType(StringRef Constraint) const override;319std::pair<unsigned, const TargetRegisterClass *>320getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,321StringRef Constraint, MVT VT) const override;322323/// } Inline Assembly324325/// Target Optimization {326327// Return lower limit for number of blocks in a jump table.328unsigned getMinimumJumpTableEntries() const override;329330// SX-Aurora VE's s/udiv is 5-9 times slower than multiply.331bool isIntDivCheap(EVT, AttributeList) const override { return false; }332// VE doesn't have rem.333bool hasStandaloneRem(EVT) const override { return false; }334// VE LDZ instruction returns 64 if the input is zero.335bool isCheapToSpeculateCtlz(Type *) const override { return true; }336// VE LDZ instruction is fast.337bool isCtlzFast() const override { return true; }338// VE has NND instruction.339bool hasAndNot(SDValue Y) const override;340341/// } Target Optimization342};343} // namespace llvm344345#endif // LLVM_LIB_TARGET_VE_VEISELLOWERING_H346347348