Path: blob/main/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYISelLowering.h
35266 views
//===-- CSKYISelLowering.cpp - CSKY DAG Lowering Implementation ----------===//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 CSKY uses to lower LLVM code into a9// selection DAG.10//11//===----------------------------------------------------------------------===//1213#ifndef LLVM_LIB_TARGET_CSKY_CSKYISELLOWERING_H14#define LLVM_LIB_TARGET_CSKY_CSKYISELLOWERING_H1516#include "MCTargetDesc/CSKYBaseInfo.h"17#include "llvm/CodeGen/CallingConvLower.h"18#include "llvm/CodeGen/TargetLowering.h"1920namespace llvm {21class CSKYSubtarget;2223namespace CSKYISD {24enum NodeType : unsigned {25FIRST_NUMBER = ISD::BUILTIN_OP_END,26NIE,27NIR,28RET,29CALL,30CALLReg,31TAIL,32TAILReg,33LOAD_ADDR,34// i32, i32 <-- f6435BITCAST_TO_LOHI,36// f64 < -- i32, i3237BITCAST_FROM_LOHI,38};39}4041class CSKYTargetLowering : public TargetLowering {42const CSKYSubtarget &Subtarget;4344public:45explicit CSKYTargetLowering(const TargetMachine &TM,46const CSKYSubtarget &STI);4748SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;4950EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,51EVT VT) const override;5253private:54SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,55bool IsVarArg,56const SmallVectorImpl<ISD::InputArg> &Ins,57const SDLoc &DL, SelectionDAG &DAG,58SmallVectorImpl<SDValue> &InVals) const override;5960bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,61bool IsVarArg,62const SmallVectorImpl<ISD::OutputArg> &Outs,63LLVMContext &Context) const override;6465SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,66const SmallVectorImpl<ISD::OutputArg> &Outs,67const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,68SelectionDAG &DAG) const override;6970SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,71SmallVectorImpl<SDValue> &InVals) const override;7273const char *getTargetNodeName(unsigned Opcode) const override;7475/// If a physical register, this returns the register that receives the76/// exception address on entry to an EH pad.77Register78getExceptionPointerRegister(const Constant *PersonalityFn) const override;7980/// If a physical register, this returns the register that receives the81/// exception typeid on entry to a landing pad.82Register83getExceptionSelectorRegister(const Constant *PersonalityFn) const override;8485bool isSelectSupported(SelectSupportKind Kind) const override {86// CSKY does not support scalar condition selects on vectors.87return (Kind != ScalarCondVectorVal);88}8990ConstraintType getConstraintType(StringRef Constraint) const override;9192std::pair<unsigned, const TargetRegisterClass *>93getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,94StringRef Constraint, MVT VT) const override;9596MachineBasicBlock *97EmitInstrWithCustomInserter(MachineInstr &MI,98MachineBasicBlock *BB) const override;99100SDValue getTargetNode(GlobalAddressSDNode *N, SDLoc DL, EVT Ty,101SelectionDAG &DAG, unsigned Flags) const;102103SDValue getTargetNode(ExternalSymbolSDNode *N, SDLoc DL, EVT Ty,104SelectionDAG &DAG, unsigned Flags) const;105106SDValue getTargetNode(JumpTableSDNode *N, SDLoc DL, EVT Ty, SelectionDAG &DAG,107unsigned Flags) const;108109SDValue getTargetNode(BlockAddressSDNode *N, SDLoc DL, EVT Ty,110SelectionDAG &DAG, unsigned Flags) const;111112SDValue getTargetNode(ConstantPoolSDNode *N, SDLoc DL, EVT Ty,113SelectionDAG &DAG, unsigned Flags) const;114115SDValue getTargetConstantPoolValue(GlobalAddressSDNode *N, EVT Ty,116SelectionDAG &DAG, unsigned Flags) const;117118SDValue getTargetConstantPoolValue(ExternalSymbolSDNode *N, EVT Ty,119SelectionDAG &DAG, unsigned Flags) const;120121SDValue getTargetConstantPoolValue(JumpTableSDNode *N, EVT Ty,122SelectionDAG &DAG, unsigned Flags) const;123124SDValue getTargetConstantPoolValue(BlockAddressSDNode *N, EVT Ty,125SelectionDAG &DAG, unsigned Flags) const;126127SDValue getTargetConstantPoolValue(ConstantPoolSDNode *N, EVT Ty,128SelectionDAG &DAG, unsigned Flags) const;129130template <class NodeTy, bool IsCall = false>131SDValue getAddr(NodeTy *N, SelectionDAG &DAG, bool IsLocal = true) const {132SDLoc DL(N);133EVT Ty = getPointerTy(DAG.getDataLayout());134135unsigned Flag = CSKYII::MO_None;136bool IsPIC = isPositionIndependent();137138if (IsPIC)139Flag = IsLocal ? CSKYII::MO_GOTOFF140: IsCall ? CSKYII::MO_PLT32141: CSKYII::MO_GOT32;142143SDValue TCPV = getTargetConstantPoolValue(N, Ty, DAG, Flag);144SDValue TV = getTargetNode(N, DL, Ty, DAG, Flag);145SDValue Addr = DAG.getNode(CSKYISD::LOAD_ADDR, DL, Ty, {TV, TCPV});146147if (!IsPIC)148return Addr;149150SDValue Result =151DAG.getNode(ISD::ADD, DL, Ty, {DAG.getGLOBAL_OFFSET_TABLE(Ty), Addr});152if (IsLocal)153return Result;154155return DAG.getLoad(Ty, DL, DAG.getEntryNode(), Result,156MachinePointerInfo::getGOT(DAG.getMachineFunction()));157}158159SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;160SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;161SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;162SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;163SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;164SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;165SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;166SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;167SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;168169SDValue getStaticTLSAddr(GlobalAddressSDNode *N, SelectionDAG &DAG,170bool UseGOT) const;171SDValue getDynamicTLSAddr(GlobalAddressSDNode *N, SelectionDAG &DAG) const;172173CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg) const;174CCAssignFn *CCAssignFnForReturn(CallingConv::ID CC, bool IsVarArg) const;175176bool decomposeMulByConstant(LLVMContext &Context, EVT VT,177SDValue C) const override;178bool isCheapToSpeculateCttz(Type *Ty) const override;179bool isCheapToSpeculateCtlz(Type *Ty) const override;180};181182} // namespace llvm183184#endif // LLVM_LIB_TARGET_CSKY_CSKYISELLOWERING_H185186187