Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 1 | //===-- RISCVISelLowering.h - RISCV DAG Lowering Interface ------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the interfaces that RISCV uses to lower LLVM code into a |
| 11 | // selection DAG. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_LIB_TARGET_RISCV_RISCVISELLOWERING_H |
| 16 | #define LLVM_LIB_TARGET_RISCV_RISCVISELLOWERING_H |
| 17 | |
| 18 | #include "RISCV.h" |
| 19 | #include "llvm/CodeGen/SelectionDAG.h" |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/TargetLowering.h" |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
| 23 | class RISCVSubtarget; |
| 24 | namespace RISCVISD { |
| 25 | enum NodeType : unsigned { |
| 26 | FIRST_NUMBER = ISD::BUILTIN_OP_END, |
Alex Bradbury | a337675 | 2017-11-08 13:41:21 +0000 | [diff] [blame] | 27 | RET_FLAG, |
Alex Bradbury | 6538516 | 2017-11-21 07:51:32 +0000 | [diff] [blame] | 28 | CALL, |
Alex Bradbury | 0b4175f | 2018-04-12 05:34:25 +0000 | [diff] [blame] | 29 | SELECT_CC, |
| 30 | BuildPairF64, |
| 31 | SplitF64 |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 32 | }; |
| 33 | } |
| 34 | |
| 35 | class RISCVTargetLowering : public TargetLowering { |
| 36 | const RISCVSubtarget &Subtarget; |
| 37 | |
| 38 | public: |
| 39 | explicit RISCVTargetLowering(const TargetMachine &TM, |
| 40 | const RISCVSubtarget &STI); |
| 41 | |
Alex Bradbury | 0992629 | 2018-04-26 12:13:48 +0000 | [diff] [blame] | 42 | bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, |
| 43 | unsigned AS, |
| 44 | Instruction *I = nullptr) const override; |
Alex Bradbury | 5c41ece | 2018-04-26 13:00:37 +0000 | [diff] [blame^] | 45 | bool isLegalAddImmediate(int64_t Imm) const override; |
Alex Bradbury | 0992629 | 2018-04-26 12:13:48 +0000 | [diff] [blame] | 46 | |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 47 | // Provide custom lowering hooks for some operations. |
| 48 | SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; |
| 49 | |
| 50 | // This method returns the name of a target specific DAG node. |
| 51 | const char *getTargetNodeName(unsigned Opcode) const override; |
| 52 | |
Alex Bradbury | 9330e64 | 2018-01-10 20:05:09 +0000 | [diff] [blame] | 53 | std::pair<unsigned, const TargetRegisterClass *> |
| 54 | getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, |
| 55 | StringRef Constraint, MVT VT) const override; |
| 56 | |
Alex Bradbury | 6538516 | 2017-11-21 07:51:32 +0000 | [diff] [blame] | 57 | MachineBasicBlock * |
| 58 | EmitInstrWithCustomInserter(MachineInstr &MI, |
| 59 | MachineBasicBlock *BB) const override; |
| 60 | |
Shiva Chen | bbf4c5c | 2018-02-02 02:43:18 +0000 | [diff] [blame] | 61 | EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, |
| 62 | EVT VT) const override; |
| 63 | |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 64 | private: |
Alex Bradbury | dc31c61 | 2017-12-11 12:49:02 +0000 | [diff] [blame] | 65 | void analyzeInputArgs(MachineFunction &MF, CCState &CCInfo, |
| 66 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 67 | bool IsRet) const; |
| 68 | void analyzeOutputArgs(MachineFunction &MF, CCState &CCInfo, |
| 69 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Alex Bradbury | c85be0d | 2018-01-10 19:41:03 +0000 | [diff] [blame] | 70 | bool IsRet, CallLoweringInfo *CLI) const; |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 71 | // Lower incoming arguments, copy physregs into vregs |
| 72 | SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, |
| 73 | bool IsVarArg, |
| 74 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 75 | const SDLoc &DL, SelectionDAG &DAG, |
| 76 | SmallVectorImpl<SDValue> &InVals) const override; |
Alex Bradbury | dc31c61 | 2017-12-11 12:49:02 +0000 | [diff] [blame] | 77 | bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, |
| 78 | bool IsVarArg, |
| 79 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 80 | LLVMContext &Context) const override; |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 81 | SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg, |
| 82 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 83 | const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL, |
| 84 | SelectionDAG &DAG) const override; |
Alex Bradbury | a337675 | 2017-11-08 13:41:21 +0000 | [diff] [blame] | 85 | SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI, |
| 86 | SmallVectorImpl<SDValue> &InVals) const override; |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 87 | bool shouldConvertConstantLoadToIntImm(const APInt &Imm, |
| 88 | Type *Ty) const override { |
| 89 | return true; |
| 90 | } |
Alex Bradbury | ec8aa91 | 2017-11-08 13:24:21 +0000 | [diff] [blame] | 91 | SDValue lowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const; |
Alex Bradbury | ffc435e | 2017-11-21 08:11:03 +0000 | [diff] [blame] | 92 | SDValue lowerBlockAddress(SDValue Op, SelectionDAG &DAG) const; |
Alex Bradbury | 80c8eb7 | 2018-03-20 13:26:12 +0000 | [diff] [blame] | 93 | SDValue lowerConstantPool(SDValue Op, SelectionDAG &DAG) const; |
Alex Bradbury | ffc435e | 2017-11-21 08:11:03 +0000 | [diff] [blame] | 94 | SDValue lowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const; |
Alex Bradbury | 6538516 | 2017-11-21 07:51:32 +0000 | [diff] [blame] | 95 | SDValue lowerSELECT(SDValue Op, SelectionDAG &DAG) const; |
Alex Bradbury | c85be0d | 2018-01-10 19:41:03 +0000 | [diff] [blame] | 96 | SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const; |
Alex Bradbury | 70f137b | 2018-01-10 20:12:00 +0000 | [diff] [blame] | 97 | SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const; |
| 98 | SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const; |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 99 | }; |
| 100 | } |
| 101 | |
| 102 | #endif |