LLVM  9.0.0svn
Go to the documentation of this file.
1 //===-- RISCVISelLowering.h - RISCV DAG Lowering Interface ------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the interfaces that RISCV uses to lower LLVM code into a
10 // selection DAG.
11 //
12 //===----------------------------------------------------------------------===//
17 #include "RISCV.h"
21 namespace llvm {
22 class RISCVSubtarget;
23 namespace RISCVISD {
24 enum NodeType : unsigned {
35  // RV64I shifts, directly matching the semantics of the named RISC-V
36  // instructions.
40  // 32-bit operations from RV64M that can't be simply matched with a pattern
41  // at instruction selection time.
45  // FPR32<->GPR transfer operations for RV64. Needed as an i32<->f32 bitcast
46  // is not legal on RV64. FMV_W_X_RV64 matches the semantics of the FMV.W.X.
47  // FMV_X_ANYEXTW_RV64 is similar to FMV.X.W but has an any-extended result.
48  // This is a more convenient semantic for producing dagcombines that remove
49  // unnecessary GPR->FPR->GPR moves.
52 };
53 }
56  const RISCVSubtarget &Subtarget;
58 public:
59  explicit RISCVTargetLowering(const TargetMachine &TM,
60  const RISCVSubtarget &STI);
62  bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
63  MachineFunction &MF,
64  unsigned Intrinsic) const override;
65  bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
66  unsigned AS,
67  Instruction *I = nullptr) const override;
68  bool isLegalICmpImmediate(int64_t Imm) const override;
69  bool isLegalAddImmediate(int64_t Imm) const override;
70  bool isTruncateFree(Type *SrcTy, Type *DstTy) const override;
71  bool isTruncateFree(EVT SrcVT, EVT DstVT) const override;
72  bool isZExtFree(SDValue Val, EVT VT2) const override;
73  bool isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT) const override;
75  // Provide custom lowering hooks for some operations.
76  SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
77  void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
78  SelectionDAG &DAG) const override;
80  SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
82  unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
83  const APInt &DemandedElts,
84  const SelectionDAG &DAG,
85  unsigned Depth) const override;
87  // This method returns the name of a target specific DAG node.
88  const char *getTargetNodeName(unsigned Opcode) const override;
90  std::pair<unsigned, const TargetRegisterClass *>
91  getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
92  StringRef Constraint, MVT VT) const override;
95  EmitInstrWithCustomInserter(MachineInstr &MI,
96  MachineBasicBlock *BB) const override;
98  EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
99  EVT VT) const override;
101  bool shouldInsertFencesForAtomic(const Instruction *I) const override {
102  return isa<LoadInst>(I) || isa<StoreInst>(I);
103  }
104  Instruction *emitLeadingFence(IRBuilder<> &Builder, Instruction *Inst,
105  AtomicOrdering Ord) const override;
106  Instruction *emitTrailingFence(IRBuilder<> &Builder, Instruction *Inst,
107  AtomicOrdering Ord) const override;
109 private:
110  void analyzeInputArgs(MachineFunction &MF, CCState &CCInfo,
112  bool IsRet) const;
113  void analyzeOutputArgs(MachineFunction &MF, CCState &CCInfo,
115  bool IsRet, CallLoweringInfo *CLI) const;
116  // Lower incoming arguments, copy physregs into vregs
117  SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
118  bool IsVarArg,
120  const SDLoc &DL, SelectionDAG &DAG,
121  SmallVectorImpl<SDValue> &InVals) const override;
122  bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
123  bool IsVarArg,
125  LLVMContext &Context) const override;
126  SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
128  const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
129  SelectionDAG &DAG) const override;
131  SmallVectorImpl<SDValue> &InVals) const override;
132  bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
133  Type *Ty) const override {
134  return true;
135  }
136  SDValue lowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
137  SDValue lowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
138  SDValue lowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
139  SDValue lowerSELECT(SDValue Op, SelectionDAG &DAG) const;
140  SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
141  SDValue lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
142  SDValue lowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
144  bool isEligibleForTailCallOptimization(
145  CCState &CCInfo, CallLoweringInfo &CLI, MachineFunction &MF,
146  const SmallVector<CCValAssign, 16> &ArgLocs) const;
149  shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;
150  virtual Value *emitMaskedAtomicRMWIntrinsic(
151  IRBuilder<> &Builder, AtomicRMWInst *AI, Value *AlignedAddr, Value *Incr,
152  Value *Mask, Value *ShiftAmt, AtomicOrdering Ord) const override;
154  shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *CI) const override;
155  virtual Value *
156  emitMaskedAtomicCmpXchgIntrinsic(IRBuilder<> &Builder, AtomicCmpXchgInst *CI,
157  Value *AlignedAddr, Value *CmpVal,
158  Value *NewVal, Value *Mask,
159  AtomicOrdering Ord) const override;
160 };
161 }
163 #endif
BUILTIN_OP_END - This must be the last enum value in this list.
Definition: ISDOpcodes.h:883
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:110
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:23
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:528
This class represents a function call, abstracting a target machine&#39;s calling convention.
Function Alias Analysis Results
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:691
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:41
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:742
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
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:20
Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
Extended Value Type.
Definition: ValueTypes.h:33
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:221
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:839
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:69
Representation of each machine instruction.
Definition: MachineInstr.h:63
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
LLVM Value Representation.
Definition: Value.h:72
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:80
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:58
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
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.