blob: 101fd6e2f0af1e9a8b7320cfe6a22d2e503a40de [file] [log] [blame]
Alex Bradbury89718422017-10-19 21:37:38 +00001//===-- 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 Blaikieb3bde2e2017-11-17 01:07:10 +000020#include "llvm/CodeGen/TargetLowering.h"
Alex Bradbury89718422017-10-19 21:37:38 +000021
22namespace llvm {
23class RISCVSubtarget;
24namespace RISCVISD {
25enum NodeType : unsigned {
26 FIRST_NUMBER = ISD::BUILTIN_OP_END,
Alex Bradburya3376752017-11-08 13:41:21 +000027 RET_FLAG,
Alex Bradbury65385162017-11-21 07:51:32 +000028 CALL,
29 SELECT_CC
Alex Bradbury89718422017-10-19 21:37:38 +000030};
31}
32
33class RISCVTargetLowering : public TargetLowering {
34 const RISCVSubtarget &Subtarget;
35
36public:
37 explicit RISCVTargetLowering(const TargetMachine &TM,
38 const RISCVSubtarget &STI);
39
40 // Provide custom lowering hooks for some operations.
41 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
42
43 // This method returns the name of a target specific DAG node.
44 const char *getTargetNodeName(unsigned Opcode) const override;
45
Alex Bradbury9330e642018-01-10 20:05:09 +000046 std::pair<unsigned, const TargetRegisterClass *>
47 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
48 StringRef Constraint, MVT VT) const override;
49
Alex Bradbury65385162017-11-21 07:51:32 +000050 MachineBasicBlock *
51 EmitInstrWithCustomInserter(MachineInstr &MI,
52 MachineBasicBlock *BB) const override;
53
Shiva Chenbbf4c5c2018-02-02 02:43:18 +000054 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
55 EVT VT) const override;
56
Alex Bradbury89718422017-10-19 21:37:38 +000057private:
Alex Bradburydc31c612017-12-11 12:49:02 +000058 void analyzeInputArgs(MachineFunction &MF, CCState &CCInfo,
59 const SmallVectorImpl<ISD::InputArg> &Ins,
60 bool IsRet) const;
61 void analyzeOutputArgs(MachineFunction &MF, CCState &CCInfo,
62 const SmallVectorImpl<ISD::OutputArg> &Outs,
Alex Bradburyc85be0d2018-01-10 19:41:03 +000063 bool IsRet, CallLoweringInfo *CLI) const;
Alex Bradbury89718422017-10-19 21:37:38 +000064 // Lower incoming arguments, copy physregs into vregs
65 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
66 bool IsVarArg,
67 const SmallVectorImpl<ISD::InputArg> &Ins,
68 const SDLoc &DL, SelectionDAG &DAG,
69 SmallVectorImpl<SDValue> &InVals) const override;
Alex Bradburydc31c612017-12-11 12:49:02 +000070 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
71 bool IsVarArg,
72 const SmallVectorImpl<ISD::OutputArg> &Outs,
73 LLVMContext &Context) const override;
Alex Bradbury89718422017-10-19 21:37:38 +000074 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
75 const SmallVectorImpl<ISD::OutputArg> &Outs,
76 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
77 SelectionDAG &DAG) const override;
Alex Bradburya3376752017-11-08 13:41:21 +000078 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
79 SmallVectorImpl<SDValue> &InVals) const override;
Alex Bradbury89718422017-10-19 21:37:38 +000080 bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
81 Type *Ty) const override {
82 return true;
83 }
Alex Bradburyec8aa912017-11-08 13:24:21 +000084 SDValue lowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
Alex Bradburyffc435e2017-11-21 08:11:03 +000085 SDValue lowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
Alex Bradbury80c8eb72018-03-20 13:26:12 +000086 SDValue lowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
Alex Bradburyffc435e2017-11-21 08:11:03 +000087 SDValue lowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
Alex Bradbury65385162017-11-21 07:51:32 +000088 SDValue lowerSELECT(SDValue Op, SelectionDAG &DAG) const;
Alex Bradburyc85be0d2018-01-10 19:41:03 +000089 SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Alex Bradbury70f137b2018-01-10 20:12:00 +000090 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
91 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
Alex Bradbury89718422017-10-19 21:37:38 +000092};
93}
94
95#endif