blob: 280adb29fd02b9cf6a8f4dcc518f7c0d8e0a456f [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,
Ana Pazos2e4106b2018-07-26 17:49:43 +000028 URET_FLAG,
29 SRET_FLAG,
30 MRET_FLAG,
Alex Bradbury65385162017-11-21 07:51:32 +000031 CALL,
Alex Bradbury0b4175f2018-04-12 05:34:25 +000032 SELECT_CC,
33 BuildPairF64,
Mandeep Singh Grangddcb9562018-05-23 22:44:08 +000034 SplitF64,
35 TAIL
Alex Bradbury89718422017-10-19 21:37:38 +000036};
37}
38
39class RISCVTargetLowering : public TargetLowering {
40 const RISCVSubtarget &Subtarget;
41
42public:
43 explicit RISCVTargetLowering(const TargetMachine &TM,
44 const RISCVSubtarget &STI);
45
Alex Bradbury09926292018-04-26 12:13:48 +000046 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
47 unsigned AS,
48 Instruction *I = nullptr) const override;
Alex Bradburydcbff632018-04-26 13:15:17 +000049 bool isLegalICmpImmediate(int64_t Imm) const override;
Alex Bradbury5c41ece2018-04-26 13:00:37 +000050 bool isLegalAddImmediate(int64_t Imm) const override;
Alex Bradbury130b8b32018-04-26 13:37:00 +000051 bool isTruncateFree(Type *SrcTy, Type *DstTy) const override;
52 bool isTruncateFree(EVT SrcVT, EVT DstVT) const override;
Alex Bradbury15e894b2018-04-26 14:04:18 +000053 bool isZExtFree(SDValue Val, EVT VT2) const override;
Alex Bradbury09926292018-04-26 12:13:48 +000054
Alex Bradbury89718422017-10-19 21:37:38 +000055 // Provide custom lowering hooks for some operations.
56 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
57
58 // This method returns the name of a target specific DAG node.
59 const char *getTargetNodeName(unsigned Opcode) const override;
60
Alex Bradbury9330e642018-01-10 20:05:09 +000061 std::pair<unsigned, const TargetRegisterClass *>
62 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
63 StringRef Constraint, MVT VT) const override;
64
Alex Bradbury65385162017-11-21 07:51:32 +000065 MachineBasicBlock *
66 EmitInstrWithCustomInserter(MachineInstr &MI,
67 MachineBasicBlock *BB) const override;
68
Shiva Chenbbf4c5c2018-02-02 02:43:18 +000069 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
70 EVT VT) const override;
71
Alex Bradbury96f492d2018-06-13 12:04:51 +000072 bool shouldInsertFencesForAtomic(const Instruction *I) const override {
73 return isa<LoadInst>(I) || isa<StoreInst>(I);
74 }
75 Instruction *emitLeadingFence(IRBuilder<> &Builder, Instruction *Inst,
76 AtomicOrdering Ord) const override;
77 Instruction *emitTrailingFence(IRBuilder<> &Builder, Instruction *Inst,
78 AtomicOrdering Ord) const override;
79
Alex Bradbury89718422017-10-19 21:37:38 +000080private:
Alex Bradburydc31c612017-12-11 12:49:02 +000081 void analyzeInputArgs(MachineFunction &MF, CCState &CCInfo,
82 const SmallVectorImpl<ISD::InputArg> &Ins,
83 bool IsRet) const;
84 void analyzeOutputArgs(MachineFunction &MF, CCState &CCInfo,
85 const SmallVectorImpl<ISD::OutputArg> &Outs,
Alex Bradburyc85be0d2018-01-10 19:41:03 +000086 bool IsRet, CallLoweringInfo *CLI) const;
Alex Bradbury89718422017-10-19 21:37:38 +000087 // Lower incoming arguments, copy physregs into vregs
88 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
89 bool IsVarArg,
90 const SmallVectorImpl<ISD::InputArg> &Ins,
91 const SDLoc &DL, SelectionDAG &DAG,
92 SmallVectorImpl<SDValue> &InVals) const override;
Alex Bradburydc31c612017-12-11 12:49:02 +000093 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
94 bool IsVarArg,
95 const SmallVectorImpl<ISD::OutputArg> &Outs,
96 LLVMContext &Context) const override;
Alex Bradbury89718422017-10-19 21:37:38 +000097 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
98 const SmallVectorImpl<ISD::OutputArg> &Outs,
99 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
100 SelectionDAG &DAG) const override;
Alex Bradburya3376752017-11-08 13:41:21 +0000101 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
102 SmallVectorImpl<SDValue> &InVals) const override;
Alex Bradbury89718422017-10-19 21:37:38 +0000103 bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
104 Type *Ty) const override {
105 return true;
106 }
Alex Bradburyec8aa912017-11-08 13:24:21 +0000107 SDValue lowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
Alex Bradburyffc435e2017-11-21 08:11:03 +0000108 SDValue lowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
Alex Bradbury80c8eb72018-03-20 13:26:12 +0000109 SDValue lowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
Alex Bradburyffc435e2017-11-21 08:11:03 +0000110 SDValue lowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
Alex Bradbury65385162017-11-21 07:51:32 +0000111 SDValue lowerSELECT(SDValue Op, SelectionDAG &DAG) const;
Alex Bradburyc85be0d2018-01-10 19:41:03 +0000112 SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
Alex Bradbury70f137b2018-01-10 20:12:00 +0000113 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
114 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
Mandeep Singh Grangddcb9562018-05-23 22:44:08 +0000115
116 bool IsEligibleForTailCallOptimization(CCState &CCInfo,
117 CallLoweringInfo &CLI, MachineFunction &MF,
118 const SmallVector<CCValAssign, 16> &ArgLocs) const;
Alex Bradbury89718422017-10-19 21:37:38 +0000119};
120}
121
122#endif