LLVM  8.0.1
RISCVISelLowering.h
Go to the documentation of this file.
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"
21 
22 namespace llvm {
23 class RISCVSubtarget;
24 namespace RISCVISD {
25 enum NodeType : unsigned {
36 };
37 }
38 
40  const RISCVSubtarget &Subtarget;
41 
42 public:
43  explicit RISCVTargetLowering(const TargetMachine &TM,
44  const RISCVSubtarget &STI);
45 
46  bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
47  MachineFunction &MF,
48  unsigned Intrinsic) const override;
49  bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
50  unsigned AS,
51  Instruction *I = nullptr) const override;
52  bool isLegalICmpImmediate(int64_t Imm) const override;
53  bool isLegalAddImmediate(int64_t Imm) const override;
54  bool isTruncateFree(Type *SrcTy, Type *DstTy) const override;
55  bool isTruncateFree(EVT SrcVT, EVT DstVT) const override;
56  bool isZExtFree(SDValue Val, EVT VT2) const override;
57  bool isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT) const override;
58 
59  // Provide custom lowering hooks for some operations.
60  SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
61 
62  SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
63 
64  // This method returns the name of a target specific DAG node.
65  const char *getTargetNodeName(unsigned Opcode) const override;
66 
67  std::pair<unsigned, const TargetRegisterClass *>
68  getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
69  StringRef Constraint, MVT VT) const override;
70 
72  EmitInstrWithCustomInserter(MachineInstr &MI,
73  MachineBasicBlock *BB) const override;
74 
75  EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
76  EVT VT) const override;
77 
78  bool shouldInsertFencesForAtomic(const Instruction *I) const override {
79  return isa<LoadInst>(I) || isa<StoreInst>(I);
80  }
81  Instruction *emitLeadingFence(IRBuilder<> &Builder, Instruction *Inst,
82  AtomicOrdering Ord) const override;
83  Instruction *emitTrailingFence(IRBuilder<> &Builder, Instruction *Inst,
84  AtomicOrdering Ord) const override;
85 
86 private:
87  void analyzeInputArgs(MachineFunction &MF, CCState &CCInfo,
89  bool IsRet) const;
90  void analyzeOutputArgs(MachineFunction &MF, CCState &CCInfo,
92  bool IsRet, CallLoweringInfo *CLI) const;
93  // Lower incoming arguments, copy physregs into vregs
94  SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
95  bool IsVarArg,
97  const SDLoc &DL, SelectionDAG &DAG,
98  SmallVectorImpl<SDValue> &InVals) const override;
99  bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
100  bool IsVarArg,
102  LLVMContext &Context) const override;
103  SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
105  const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
106  SelectionDAG &DAG) const override;
108  SmallVectorImpl<SDValue> &InVals) const override;
109  bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
110  Type *Ty) const override {
111  return true;
112  }
113  SDValue lowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
114  SDValue lowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
115  SDValue lowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
116  SDValue lowerSELECT(SDValue Op, SelectionDAG &DAG) const;
117  SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
118  SDValue lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
119  SDValue lowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
120 
121  bool IsEligibleForTailCallOptimization(CCState &CCInfo,
123  const SmallVector<CCValAssign, 16> &ArgLocs) const;
124 
126  shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;
127  virtual Value *emitMaskedAtomicRMWIntrinsic(
128  IRBuilder<> &Builder, AtomicRMWInst *AI, Value *AlignedAddr, Value *Incr,
129  Value *Mask, Value *ShiftAmt, AtomicOrdering Ord) const override;
131  shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *CI) const override;
132  virtual Value *
133  emitMaskedAtomicCmpXchgIntrinsic(IRBuilder<> &Builder, AtomicCmpXchgInst *CI,
134  Value *AlignedAddr, Value *CmpVal,
135  Value *NewVal, Value *Mask,
136  AtomicOrdering Ord) const override;
137 };
138 }
139 
140 #endif
BUILTIN_OP_END - This must be the last enum value in this list.
Definition: ISDOpcodes.h:877
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg If BaseGV is null...
LLVMContext & Context
This class represents lattice values for constants.
Definition: AllocatorList.h:24
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
Definition: Instructions.h:529
This class represents a function call, abstracting a target machine&#39;s calling convention.
unsigned const TargetRegisterInfo * TRI
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:692
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:743
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
AtomicOrdering
Atomic ordering for LLVM&#39;s memory model.
bool shouldInsertFencesForAtomic(const Instruction *I) const override
Whether AtomicExpandPass should automatically insert fences and reduce ordering for this atomic...
Analysis containing CSE Info
Definition: CSEInfo.cpp:21
Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
Extended Value Type.
Definition: ValueTypes.h:34
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This structure contains all information that is necessary for lowering calls.
CCState - This class holds information needed while lowering arguments and return values...
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:222
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
Class for arbitrary precision integers.
Definition: APInt.h:70
Representation of each machine instruction.
Definition: MachineInstr.h:64
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
LLVM Value Representation.
Definition: Value.h:73
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:81
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:59
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
This file describes how to lower LLVM code to machine code.