2017-10-20 05:37:38 +08:00
|
|
|
//===-- RISCVISelLowering.h - RISCV DAG Lowering Interface ------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-10-20 05:37:38 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the interfaces that RISCV uses to lower LLVM code into a
|
|
|
|
// selection DAG.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_TARGET_RISCV_RISCVISELLOWERING_H
|
|
|
|
#define LLVM_LIB_TARGET_RISCV_RISCVISELLOWERING_H
|
|
|
|
|
|
|
|
#include "RISCV.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetLowering.h"
|
2017-10-20 05:37:38 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class RISCVSubtarget;
|
|
|
|
namespace RISCVISD {
|
|
|
|
enum NodeType : unsigned {
|
|
|
|
FIRST_NUMBER = ISD::BUILTIN_OP_END,
|
2017-11-08 21:41:21 +08:00
|
|
|
RET_FLAG,
|
[RISCV] Add support for _interrupt attribute
- Save/restore only registers that are used.
This includes Callee saved registers and Caller saved registers
(arguments and temporaries) for integer and FP registers.
- If there is a call in the interrupt handler, save/restore all
Caller saved registers (arguments and temporaries) and all FP registers.
- Emit special return instructions depending on "interrupt"
attribute type.
Based on initial patch by Zhaoshi Zheng.
Reviewers: asb
Reviewed By: asb
Subscribers: rkruppe, the_o, MartinMosbeck, brucehoult, rbar, johnrusso, simoncook, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, rogfer01, llvm-commits
Differential Revision: https://reviews.llvm.org/D48411
llvm-svn: 338047
2018-07-27 01:49:43 +08:00
|
|
|
URET_FLAG,
|
|
|
|
SRET_FLAG,
|
|
|
|
MRET_FLAG,
|
2017-11-21 15:51:32 +08:00
|
|
|
CALL,
|
[RISCV] Optimize select_cc after fp compare expansion
Some FP compares expand to a sequence ending with (xor X, 1) to invert the result. If
the consumer is a select_cc we can likely get rid of this xor by fixing
up the select_cc condition.
This patch combines (select_cc (xor X, 1), 0, setne, trueV, falseV) -
(select_cc X, 0, seteq, trueV, falseV) if we can prove X is 0/1.
Reviewed By: lenary
Differential Revision: https://reviews.llvm.org/D94546
2021-01-15 05:41:35 +08:00
|
|
|
/// Select with condition operator - This selects between a true value and
|
|
|
|
/// a false value (ops #3 and #4) based on the boolean result of comparing
|
|
|
|
/// the lhs and rhs (ops #0 and #1) of a conditional expression with the
|
|
|
|
/// condition code in op #2, a XLenVT constant from the ISD::CondCode enum.
|
|
|
|
/// The lhs and rhs are XLenVT integers. The true and false values can be
|
|
|
|
/// integer or floating point.
|
2018-04-12 13:34:25 +08:00
|
|
|
SELECT_CC,
|
|
|
|
BuildPairF64,
|
2018-05-24 06:44:08 +08:00
|
|
|
SplitF64,
|
2019-01-25 13:04:00 +08:00
|
|
|
TAIL,
|
|
|
|
// RV64I shifts, directly matching the semantics of the named RISC-V
|
|
|
|
// instructions.
|
|
|
|
SLLW,
|
|
|
|
SRAW,
|
2019-01-25 13:11:34 +08:00
|
|
|
SRLW,
|
|
|
|
// 32-bit operations from RV64M that can't be simply matched with a pattern
|
2021-01-26 01:35:14 +08:00
|
|
|
// at instruction selection time. These have undefined behavior for division
|
|
|
|
// by 0 or overflow (divw) like their target independent counterparts.
|
2019-01-25 13:11:34 +08:00
|
|
|
DIVW,
|
|
|
|
DIVUW,
|
2019-02-01 06:48:38 +08:00
|
|
|
REMUW,
|
2020-11-21 02:11:34 +08:00
|
|
|
// RV64IB rotates, directly matching the semantics of the named RISC-V
|
|
|
|
// instructions.
|
|
|
|
ROLW,
|
|
|
|
RORW,
|
2021-02-01 09:37:44 +08:00
|
|
|
// RV64IB/RV32IB funnel shifts, with the semantics of the named RISC-V
|
|
|
|
// instructions, but the same operand order as fshl/fshr intrinsics.
|
|
|
|
FSR,
|
|
|
|
FSL,
|
2020-11-26 01:43:16 +08:00
|
|
|
// RV64IB funnel shifts, with the semantics of the named RISC-V instructions,
|
|
|
|
// but the same operand order as fshl/fshr intrinsics.
|
|
|
|
FSRW,
|
|
|
|
FSLW,
|
2020-07-03 22:57:59 +08:00
|
|
|
// FPR<->GPR transfer operations when the FPR is smaller than XLEN, needed as
|
|
|
|
// XLEN is the only legal integer width.
|
|
|
|
//
|
2020-12-04 02:29:10 +08:00
|
|
|
// FMV_H_X matches the semantics of the FMV.H.X.
|
|
|
|
// FMV_X_ANYEXTH is similar to FMV.X.H but has an any-extended result.
|
2020-07-03 22:57:59 +08:00
|
|
|
// FMV_W_X_RV64 matches the semantics of the FMV.W.X.
|
2019-02-01 06:48:38 +08:00
|
|
|
// FMV_X_ANYEXTW_RV64 is similar to FMV.X.W but has an any-extended result.
|
2020-07-03 22:57:59 +08:00
|
|
|
//
|
2019-02-01 06:48:38 +08:00
|
|
|
// This is a more convenient semantic for producing dagcombines that remove
|
|
|
|
// unnecessary GPR->FPR->GPR moves.
|
2020-12-04 02:29:10 +08:00
|
|
|
FMV_H_X,
|
|
|
|
FMV_X_ANYEXTH,
|
2019-02-01 06:48:38 +08:00
|
|
|
FMV_W_X_RV64,
|
[RISCV] Support @llvm.readcyclecounter() Intrinsic
On RISC-V, the `cycle` CSR holds a 64-bit count of the number of clock
cycles executed by the core, from an arbitrary point in the past. This
matches the intended semantics of `@llvm.readcyclecounter()`, which we
currently leave to the default lowering (to the constant 0).
With this patch, we will now correctly lower this intrinsic to the
intended semantics, using the user-space instruction `rdcycle`. On
64-bit targets, we can directly lower to this instruction.
On 32-bit targets, we need to do more, as `rdcycle` only returns the low
32-bits of the `cycle` CSR. In this case, we perform a custom lowering,
based on the PowerPC lowering, using `rdcycleh` to obtain the high
32-bits of the `cycle` CSR. This custom lowering inserts a new basic
block which detects overflow in the high 32-bits of the `cycle` CSR
during reading (because multiple instructions are required to read). The
emitted assembly matches the suggested assembly in the RISC-V
specification.
Differential Revision: https://reviews.llvm.org/D64125
llvm-svn: 365201
2019-07-05 20:35:21 +08:00
|
|
|
FMV_X_ANYEXTW_RV64,
|
|
|
|
// READ_CYCLE_WIDE - A read of the 64-bit cycle CSR on a 32-bit target
|
|
|
|
// (returns (Lo, Hi)). It takes a chain operand.
|
2020-11-11 21:41:55 +08:00
|
|
|
READ_CYCLE_WIDE,
|
|
|
|
// Generalized Reverse and Generalized Or-Combine - directly matching the
|
|
|
|
// semantics of the named RISC-V instructions. Lowered as custom nodes as
|
|
|
|
// TableGen chokes when faced with commutative permutations in deeply-nested
|
|
|
|
// DAGs. Each node takes an input operand and a TargetConstant immediate
|
|
|
|
// shift amount, and outputs a bit-manipulated version of input. All operands
|
|
|
|
// are of type XLenVT.
|
|
|
|
GREVI,
|
|
|
|
GREVIW,
|
|
|
|
GORCI,
|
|
|
|
GORCIW,
|
2020-12-19 01:50:23 +08:00
|
|
|
// Vector Extension
|
2021-02-09 02:59:38 +08:00
|
|
|
// VMV_V_X_VL matches the semantics of vmv.v.x but includes an extra operand
|
|
|
|
// for the VL value to be used for the operation.
|
|
|
|
VMV_V_X_VL,
|
|
|
|
// VFMV_V_F_VL matches the semantics of vfmv.v.f but includes an extra operand
|
|
|
|
// for the VL value to be used for the operation.
|
|
|
|
VFMV_V_F_VL,
|
2021-01-31 00:53:32 +08:00
|
|
|
// VMV_X_S matches the semantics of vmv.x.s. The result is always XLenVT sign
|
|
|
|
// extended from the vector element size.
|
2020-12-19 01:50:23 +08:00
|
|
|
VMV_X_S,
|
2020-12-15 21:05:32 +08:00
|
|
|
// Splats an i64 scalar to a vector type (with element type i64) where the
|
|
|
|
// scalar is a sign-extended i32.
|
|
|
|
SPLAT_VECTOR_I64,
|
2021-01-14 09:14:45 +08:00
|
|
|
// Read VLENB CSR
|
|
|
|
READ_VLENB,
|
2021-01-16 01:04:52 +08:00
|
|
|
// Truncates a RVV integer vector by one power-of-two.
|
|
|
|
TRUNCATE_VECTOR,
|
2021-01-22 09:08:41 +08:00
|
|
|
// Unit-stride fault-only-first load
|
|
|
|
VLEFF,
|
|
|
|
VLEFF_MASK,
|
2021-01-12 01:42:05 +08:00
|
|
|
// Matches the semantics of vslideup/vslidedown. The first operand is the
|
|
|
|
// pass-thru operand, the second is the source vector, and the third is the
|
|
|
|
// XLenVT index (either constant or non-constant).
|
|
|
|
VSLIDEUP,
|
|
|
|
VSLIDEDOWN,
|
2021-02-09 20:09:10 +08:00
|
|
|
// Matches the semantics of the vid.v instruction, with a mask and VL
|
|
|
|
// operand.
|
|
|
|
VID_VL,
|
2021-01-22 22:54:00 +08:00
|
|
|
// Matches the semantics of the vfcnvt.rod function (Convert double-width
|
|
|
|
// float to single-width float, rounding towards odd). Takes a double-width
|
|
|
|
// float vector and produces a single-width float vector.
|
|
|
|
VFNCVT_ROD,
|
2021-01-28 23:31:27 +08:00
|
|
|
// These nodes match the semantics of the corresponding RVV vector reduction
|
|
|
|
// instructions. They produce a vector result which is the reduction
|
|
|
|
// performed over the first vector operand plus the first element of the
|
|
|
|
// second vector operand. The first operand is an unconstrained vector type,
|
|
|
|
// and the result and second operand's types are expected to be the
|
|
|
|
// corresponding full-width LMUL=1 type for the first operand:
|
|
|
|
// nxv8i8 = vecreduce_add nxv32i8, nxv8i8
|
|
|
|
// nxv2i32 = vecreduce_add nxv8i32, nxv2i32
|
|
|
|
// The different in types does introduce extra vsetvli instructions but
|
|
|
|
// similarly it reduces the number of registers consumed per reduction.
|
|
|
|
VECREDUCE_ADD,
|
|
|
|
VECREDUCE_UMAX,
|
|
|
|
VECREDUCE_SMAX,
|
|
|
|
VECREDUCE_UMIN,
|
|
|
|
VECREDUCE_SMIN,
|
|
|
|
VECREDUCE_AND,
|
|
|
|
VECREDUCE_OR,
|
|
|
|
VECREDUCE_XOR,
|
2021-02-02 22:34:51 +08:00
|
|
|
VECREDUCE_FADD,
|
|
|
|
VECREDUCE_SEQ_FADD,
|
2021-02-09 02:32:32 +08:00
|
|
|
|
2021-02-13 01:20:54 +08:00
|
|
|
// Vector binary and unary ops with a mask as a third operand, and VL as a
|
|
|
|
// fourth operand.
|
2021-02-09 02:32:32 +08:00
|
|
|
// FIXME: Can we replace these with ISD::VP_*?
|
|
|
|
ADD_VL,
|
|
|
|
AND_VL,
|
|
|
|
MUL_VL,
|
|
|
|
OR_VL,
|
|
|
|
SDIV_VL,
|
|
|
|
SHL_VL,
|
|
|
|
SREM_VL,
|
|
|
|
SRA_VL,
|
|
|
|
SRL_VL,
|
|
|
|
SUB_VL,
|
|
|
|
UDIV_VL,
|
|
|
|
UREM_VL,
|
|
|
|
XOR_VL,
|
|
|
|
FADD_VL,
|
|
|
|
FSUB_VL,
|
|
|
|
FMUL_VL,
|
|
|
|
FDIV_VL,
|
|
|
|
FNEG_VL,
|
2021-02-13 07:10:18 +08:00
|
|
|
FSQRT_VL,
|
2021-02-09 02:45:45 +08:00
|
|
|
FMA_VL,
|
2021-02-11 20:45:38 +08:00
|
|
|
SMIN_VL,
|
|
|
|
SMAX_VL,
|
|
|
|
UMIN_VL,
|
|
|
|
UMAX_VL,
|
2021-02-09 02:32:32 +08:00
|
|
|
|
2021-02-13 01:20:54 +08:00
|
|
|
// Vector compare producing a mask. Fourth operand is input mask. Fifth
|
|
|
|
// operand is VL.
|
|
|
|
SETCC_VL,
|
|
|
|
|
2021-02-09 02:32:32 +08:00
|
|
|
// Set mask vector to all zeros or ones.
|
|
|
|
VMCLR_VL,
|
|
|
|
VMSET_VL,
|
|
|
|
|
2021-02-11 01:40:28 +08:00
|
|
|
// Matches the semantics of vrgather.vx with an extra operand for VL.
|
|
|
|
VRGATHER_VX_VL,
|
|
|
|
|
2021-02-09 02:32:32 +08:00
|
|
|
// Memory opcodes start here.
|
|
|
|
VLE_VL = ISD::FIRST_TARGET_MEMORY_OPCODE,
|
|
|
|
VSE_VL,
|
|
|
|
|
|
|
|
// WARNING: Do not add anything in the end unless you want the node to
|
|
|
|
// have memop! In fact, starting from FIRST_TARGET_MEMORY_OPCODE all
|
|
|
|
// opcodes will be thought as target memory ops!
|
2017-10-20 05:37:38 +08:00
|
|
|
};
|
2020-11-11 21:41:55 +08:00
|
|
|
} // namespace RISCVISD
|
2017-10-20 05:37:38 +08:00
|
|
|
|
|
|
|
class RISCVTargetLowering : public TargetLowering {
|
|
|
|
const RISCVSubtarget &Subtarget;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit RISCVTargetLowering(const TargetMachine &TM,
|
|
|
|
const RISCVSubtarget &STI);
|
|
|
|
|
2020-12-11 15:16:08 +08:00
|
|
|
const RISCVSubtarget &getSubtarget() const { return Subtarget; }
|
|
|
|
|
2018-09-19 18:54:22 +08:00
|
|
|
bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
|
|
|
|
MachineFunction &MF,
|
|
|
|
unsigned Intrinsic) const override;
|
2018-04-26 20:13:48 +08:00
|
|
|
bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
|
|
|
|
unsigned AS,
|
|
|
|
Instruction *I = nullptr) const override;
|
2018-04-26 21:15:17 +08:00
|
|
|
bool isLegalICmpImmediate(int64_t Imm) const override;
|
2018-04-26 21:00:37 +08:00
|
|
|
bool isLegalAddImmediate(int64_t Imm) const override;
|
2018-04-26 21:37:00 +08:00
|
|
|
bool isTruncateFree(Type *SrcTy, Type *DstTy) const override;
|
|
|
|
bool isTruncateFree(EVT SrcVT, EVT DstVT) const override;
|
2018-04-26 22:04:18 +08:00
|
|
|
bool isZExtFree(SDValue Val, EVT VT2) const override;
|
2018-11-30 17:56:54 +08:00
|
|
|
bool isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT) const override;
|
2020-11-10 02:05:51 +08:00
|
|
|
bool isCheapToSpeculateCttz() const override;
|
|
|
|
bool isCheapToSpeculateCtlz() const override;
|
2020-03-20 17:22:48 +08:00
|
|
|
bool isFPImmLegal(const APFloat &Imm, EVT VT,
|
|
|
|
bool ForCodeSize) const override;
|
[RISCV] Support Bit-Preserving FP in F/D Extensions
Summary:
This allows some integer bitwise operations to instead be performed by
hardware fp instructions. This is correct because the RISC-V spec
requires the F and D extensions to use the IEEE-754 standard
representation, and fp register loads and stores to be bit-preserving.
This is tested against the soft-float ABI, but with hardware float
extensions enabled, so that the tests also ensure the optimisation also
fires in this case.
Reviewers: asb, luismarques
Reviewed By: asb
Subscribers: hiraditya, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, kito-cheng, shiva0217, jrtc27, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, Jim, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D62900
llvm-svn: 362790
2019-06-07 20:20:14 +08:00
|
|
|
|
|
|
|
bool hasBitPreservingFPLogic(EVT VT) const override;
|
2018-04-26 20:13:48 +08:00
|
|
|
|
2017-10-20 05:37:38 +08:00
|
|
|
// Provide custom lowering hooks for some operations.
|
|
|
|
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
|
2019-01-25 13:04:00 +08:00
|
|
|
void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
|
|
|
|
SelectionDAG &DAG) const override;
|
2017-10-20 05:37:38 +08:00
|
|
|
|
2018-10-04 07:30:16 +08:00
|
|
|
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
|
|
|
|
|
2021-01-16 02:54:26 +08:00
|
|
|
bool targetShrinkDemandedConstant(SDValue Op, const APInt &DemandedBits,
|
|
|
|
const APInt &DemandedElts,
|
|
|
|
TargetLoweringOpt &TLO) const override;
|
|
|
|
|
2021-01-14 09:14:45 +08:00
|
|
|
void computeKnownBitsForTargetNode(const SDValue Op,
|
|
|
|
KnownBits &Known,
|
|
|
|
const APInt &DemandedElts,
|
|
|
|
const SelectionDAG &DAG,
|
|
|
|
unsigned Depth) const override;
|
2019-01-25 13:04:00 +08:00
|
|
|
unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
|
|
|
|
const APInt &DemandedElts,
|
|
|
|
const SelectionDAG &DAG,
|
|
|
|
unsigned Depth) const override;
|
|
|
|
|
2017-10-20 05:37:38 +08:00
|
|
|
// This method returns the name of a target specific DAG node.
|
|
|
|
const char *getTargetNodeName(unsigned Opcode) const override;
|
2018-01-11 04:05:09 +08:00
|
|
|
|
[RISCV] Support 'f' Inline Assembly Constraint
Summary:
This adds the 'f' inline assembly constraint, as supported by GCC. An
'f'-constrained operand is passed in a floating point register. Exactly
which kind of floating-point register (32-bit or 64-bit) is decided
based on the operand type and the available standard extensions (-f and
-d, respectively).
This patch adds support in both the clang frontend, and LLVM itself.
Reviewers: asb, lewis-revill
Reviewed By: asb
Subscribers: hiraditya, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, kito-cheng, shiva0217, jrtc27, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, Jim, s.egerton, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D65500
llvm-svn: 367403
2019-07-31 17:45:55 +08:00
|
|
|
ConstraintType getConstraintType(StringRef Constraint) const override;
|
2019-08-16 18:28:34 +08:00
|
|
|
|
|
|
|
unsigned getInlineAsmMemConstraint(StringRef ConstraintCode) const override;
|
|
|
|
|
2018-01-11 04:05:09 +08:00
|
|
|
std::pair<unsigned, const TargetRegisterClass *>
|
|
|
|
getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
|
|
|
|
StringRef Constraint, MVT VT) const override;
|
2017-10-20 05:37:38 +08:00
|
|
|
|
2019-06-11 20:42:13 +08:00
|
|
|
void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint,
|
|
|
|
std::vector<SDValue> &Ops,
|
|
|
|
SelectionDAG &DAG) const override;
|
|
|
|
|
2017-11-21 15:51:32 +08:00
|
|
|
MachineBasicBlock *
|
|
|
|
EmitInstrWithCustomInserter(MachineInstr &MI,
|
|
|
|
MachineBasicBlock *BB) const override;
|
2018-02-02 10:43:18 +08:00
|
|
|
|
|
|
|
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
|
|
|
|
EVT VT) const override;
|
2017-11-21 15:51:32 +08:00
|
|
|
|
2019-03-22 18:39:22 +08:00
|
|
|
bool convertSetCCLogicToBitwiseLogic(EVT VT) const override {
|
|
|
|
return VT.isScalarInteger();
|
|
|
|
}
|
2020-05-02 22:05:12 +08:00
|
|
|
bool convertSelectOfConstantsToMath(EVT VT) const override { return true; }
|
2019-03-22 18:39:22 +08:00
|
|
|
|
2018-06-13 20:04:51 +08:00
|
|
|
bool shouldInsertFencesForAtomic(const Instruction *I) const override {
|
|
|
|
return isa<LoadInst>(I) || isa<StoreInst>(I);
|
|
|
|
}
|
|
|
|
Instruction *emitLeadingFence(IRBuilder<> &Builder, Instruction *Inst,
|
|
|
|
AtomicOrdering Ord) const override;
|
|
|
|
Instruction *emitTrailingFence(IRBuilder<> &Builder, Instruction *Inst,
|
|
|
|
AtomicOrdering Ord) const override;
|
|
|
|
|
2020-11-26 07:07:34 +08:00
|
|
|
bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
|
|
|
|
EVT VT) const override;
|
|
|
|
|
2019-03-12 05:41:22 +08:00
|
|
|
ISD::NodeType getExtendForAtomicOps() const override {
|
[LegalizeTypes][RISCV] Correctly sign-extend comparison for ATOMIC_CMP_XCHG
Summary:
Currently, the comparison argument used for ATOMIC_CMP_XCHG is legalised
with GetPromotedInteger, which leaves the upper bits of the value
undefind. Since this is used for comparing in an LR/SC loop with a
full-width comparison, we must sign extend it. We introduce a new
getExtendForAtomicCmpSwapArg to complement getExtendForAtomicOps, since
many targets have compare-and-swap instructions (or pseudos) that
correctly handle an any-extend input, and the existing function
determines the extension of the result, whereas we are concerned with
the input.
This is related to https://reviews.llvm.org/D58829, which solved the
issue for ATOMIC_CMP_SWAP_WITH_SUCCESS, but not the simpler
ATOMIC_CMP_SWAP.
Reviewers: asb, lenary, efriedma
Reviewed By: asb
Subscribers: arichardson, hiraditya, rbar, johnrusso, simoncook, sabuasal, niosHD, kito-cheng, shiva0217, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, jfb, PkmX, jocewei, psnobl, benna, Jim, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, evandro, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74453
2020-04-01 22:50:47 +08:00
|
|
|
return ISD::SIGN_EXTEND;
|
|
|
|
}
|
|
|
|
|
|
|
|
ISD::NodeType getExtendForAtomicCmpSwapArg() const override {
|
2019-03-12 05:41:22 +08:00
|
|
|
return ISD::SIGN_EXTEND;
|
|
|
|
}
|
|
|
|
|
2019-04-16 22:38:32 +08:00
|
|
|
bool shouldExpandShift(SelectionDAG &DAG, SDNode *N) const override {
|
|
|
|
if (DAG.getMachineFunction().getFunction().hasMinSize())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
[RISCV] Prevent re-ordering some adds after shifts
Summary:
DAGCombine will normally turn a `(shl (add x, c1), c2)` into `(add (shl x, c2), c1 << c2)`, where `c1` and `c2` are constants. This can be prevented by a callback in TargetLowering.
On RISC-V, materialising the constant `c1 << c2` can be more expensive than materialising `c1`, because materialising the former may take more instructions, and may use a register, where materialising the latter would not.
This patch implements the hook in RISCVTargetLowering to prevent this transform, in the cases where:
- `c1` fits into the immediate field in an `addi` instruction.
- `c1` takes fewer instructions to materialise than `c1 << c2`.
In future, DAGCombine could do the check to see whether `c1` fits into an add immediate, which might simplify more targets hooks than just RISC-V.
Reviewers: asb, luismarques, efriedma
Reviewed By: asb
Subscribers: xbolva00, lebedev.ri, craig.topper, lewis-revill, Jim, hiraditya, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, kito-cheng, shiva0217, jrtc27, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D62857
llvm-svn: 363736
2019-06-19 04:38:08 +08:00
|
|
|
bool isDesirableToCommuteWithShift(const SDNode *N,
|
|
|
|
CombineLevel Level) const override;
|
2019-04-16 22:38:32 +08:00
|
|
|
|
2019-07-08 17:16:47 +08:00
|
|
|
/// If a physical register, this returns the register that receives the
|
|
|
|
/// exception address on entry to an EH pad.
|
2020-04-08 22:29:30 +08:00
|
|
|
Register
|
2019-07-08 17:16:47 +08:00
|
|
|
getExceptionPointerRegister(const Constant *PersonalityFn) const override;
|
|
|
|
|
|
|
|
/// If a physical register, this returns the register that receives the
|
|
|
|
/// exception typeid on entry to a landing pad.
|
2020-04-08 22:29:30 +08:00
|
|
|
Register
|
2019-07-08 17:16:47 +08:00
|
|
|
getExceptionSelectorRegister(const Constant *PersonalityFn) const override;
|
|
|
|
|
2019-08-29 07:40:37 +08:00
|
|
|
bool shouldExtendTypeInLibCall(EVT Type) const override;
|
2021-01-26 01:16:45 +08:00
|
|
|
bool shouldSignExtendTypeInLibCall(EVT Type, bool IsSigned) const override;
|
2019-08-29 07:40:37 +08:00
|
|
|
|
2019-11-04 19:21:51 +08:00
|
|
|
/// Returns the register with the specified architectural or ABI name. This
|
|
|
|
/// method is necessary to lower the llvm.read_register.* and
|
|
|
|
/// llvm.write_register.* intrinsics. Allocatable registers must be reserved
|
|
|
|
/// with the clang -ffixed-xX flag for access to be allowed.
|
2019-12-28 22:18:56 +08:00
|
|
|
Register getRegisterByName(const char *RegName, LLT VT,
|
2019-11-04 19:21:51 +08:00
|
|
|
const MachineFunction &MF) const override;
|
|
|
|
|
2017-10-20 05:37:38 +08:00
|
|
|
// Lower incoming arguments, copy physregs into vregs
|
|
|
|
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
|
|
|
|
bool IsVarArg,
|
|
|
|
const SmallVectorImpl<ISD::InputArg> &Ins,
|
|
|
|
const SDLoc &DL, SelectionDAG &DAG,
|
|
|
|
SmallVectorImpl<SDValue> &InVals) const override;
|
2020-05-12 18:49:17 +08:00
|
|
|
bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
|
|
|
|
bool IsVarArg,
|
|
|
|
const SmallVectorImpl<ISD::OutputArg> &Outs,
|
|
|
|
LLVMContext &Context) const override;
|
2017-10-20 05:37:38 +08:00
|
|
|
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
|
|
|
|
const SmallVectorImpl<ISD::OutputArg> &Outs,
|
|
|
|
const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
|
|
|
|
SelectionDAG &DAG) const override;
|
2017-11-08 21:41:21 +08:00
|
|
|
SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI,
|
|
|
|
SmallVectorImpl<SDValue> &InVals) const override;
|
2020-06-10 16:16:09 +08:00
|
|
|
|
2017-10-20 05:37:38 +08:00
|
|
|
bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
|
|
|
|
Type *Ty) const override {
|
|
|
|
return true;
|
|
|
|
}
|
2020-02-18 23:53:26 +08:00
|
|
|
bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
|
2020-06-10 16:16:09 +08:00
|
|
|
bool shouldConsiderGEPOffsetSplit() const override { return true; }
|
|
|
|
|
2020-07-08 09:48:46 +08:00
|
|
|
bool decomposeMulByConstant(LLVMContext &Context, EVT VT,
|
|
|
|
SDValue C) const override;
|
|
|
|
|
2020-06-10 16:16:09 +08:00
|
|
|
TargetLowering::AtomicExpansionKind
|
|
|
|
shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const override;
|
|
|
|
Value *emitMaskedAtomicRMWIntrinsic(IRBuilder<> &Builder, AtomicRMWInst *AI,
|
|
|
|
Value *AlignedAddr, Value *Incr,
|
|
|
|
Value *Mask, Value *ShiftAmt,
|
|
|
|
AtomicOrdering Ord) const override;
|
|
|
|
TargetLowering::AtomicExpansionKind
|
|
|
|
shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *CI) const override;
|
|
|
|
Value *emitMaskedAtomicCmpXchgIntrinsic(IRBuilder<> &Builder,
|
|
|
|
AtomicCmpXchgInst *CI,
|
|
|
|
Value *AlignedAddr, Value *CmpVal,
|
|
|
|
Value *NewVal, Value *Mask,
|
|
|
|
AtomicOrdering Ord) const override;
|
|
|
|
|
2021-01-27 15:00:46 +08:00
|
|
|
/// Returns true if the target allows unaligned memory accesses of the
|
|
|
|
/// specified type.
|
|
|
|
bool allowsMisalignedMemoryAccesses(
|
|
|
|
EVT VT, unsigned AddrSpace = 0, Align Alignment = Align(1),
|
|
|
|
MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
|
|
|
|
bool *Fast = nullptr) const override;
|
|
|
|
|
2020-06-10 16:16:09 +08:00
|
|
|
private:
|
|
|
|
void analyzeInputArgs(MachineFunction &MF, CCState &CCInfo,
|
|
|
|
const SmallVectorImpl<ISD::InputArg> &Ins,
|
|
|
|
bool IsRet) const;
|
|
|
|
void analyzeOutputArgs(MachineFunction &MF, CCState &CCInfo,
|
|
|
|
const SmallVectorImpl<ISD::OutputArg> &Outs,
|
|
|
|
bool IsRet, CallLoweringInfo *CLI) const;
|
2019-04-01 22:42:56 +08:00
|
|
|
|
|
|
|
template <class NodeTy>
|
2019-06-11 20:57:47 +08:00
|
|
|
SDValue getAddr(NodeTy *N, SelectionDAG &DAG, bool IsLocal = true) const;
|
2019-04-01 22:42:56 +08:00
|
|
|
|
2019-06-19 16:40:59 +08:00
|
|
|
SDValue getStaticTLSAddr(GlobalAddressSDNode *N, SelectionDAG &DAG,
|
|
|
|
bool UseGOT) const;
|
|
|
|
SDValue getDynamicTLSAddr(GlobalAddressSDNode *N, SelectionDAG &DAG) const;
|
|
|
|
|
2017-11-08 21:24:21 +08:00
|
|
|
SDValue lowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
|
[RISCV] Support and tests for a variety of additional LLVM IR constructs
Previous patches primarily ensured that codegen was possible for the standard
RISC-V instructions. However, there are a number of IR inputs that wouldn't be
appropriately lowered. This patch both adds test cases and supports lowering
for a number of these cases:
* Improved sext/zext/trunc support
* Support for setcc variants that don't map directly to RISC-V instructions
* Lowering mul, and hence support for external symbols
* addc, adde, subc, sube
* mulhs, srem, mulhu, urem, udiv, sdiv
* {srl,sra,shl}_parts
* brind
* br_jt
* bswap, ctlz, cttz, ctpop
* rotl, rotr
* BlockAddress operands
Differential Revision: https://reviews.llvm.org/D29938
llvm-svn: 318737
2017-11-21 16:11:03 +08:00
|
|
|
SDValue lowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
|
2018-03-20 21:26:12 +08:00
|
|
|
SDValue lowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
|
2020-11-25 22:01:19 +08:00
|
|
|
SDValue lowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
|
2019-06-19 16:40:59 +08:00
|
|
|
SDValue lowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
|
2017-11-21 15:51:32 +08:00
|
|
|
SDValue lowerSELECT(SDValue Op, SelectionDAG &DAG) const;
|
2018-01-11 03:41:03 +08:00
|
|
|
SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
|
2018-10-04 13:27:50 +08:00
|
|
|
SDValue lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue lowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
|
2019-04-16 22:38:32 +08:00
|
|
|
SDValue lowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue lowerShiftRightParts(SDValue Op, SelectionDAG &DAG, bool IsSRA) const;
|
2020-12-15 21:05:32 +08:00
|
|
|
SDValue lowerSPLATVECTOR(SDValue Op, SelectionDAG &DAG) const;
|
2021-01-13 20:27:05 +08:00
|
|
|
SDValue lowerVectorMaskExt(SDValue Op, SelectionDAG &DAG,
|
|
|
|
int64_t ExtTrueVal) const;
|
|
|
|
SDValue lowerVectorMaskTrunc(SDValue Op, SelectionDAG &DAG) const;
|
2021-01-12 01:42:05 +08:00
|
|
|
SDValue lowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
|
2020-03-28 08:27:00 +08:00
|
|
|
SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
|
2020-12-17 13:45:52 +08:00
|
|
|
SDValue LowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG) const;
|
2021-01-28 23:31:27 +08:00
|
|
|
SDValue lowerVECREDUCE(SDValue Op, SelectionDAG &DAG) const;
|
2021-02-02 22:34:51 +08:00
|
|
|
SDValue lowerFPVECREDUCE(SDValue Op, SelectionDAG &DAG) const;
|
2021-02-09 02:32:32 +08:00
|
|
|
SDValue lowerFixedLengthVectorLoadToRVV(SDValue Op, SelectionDAG &DAG) const;
|
|
|
|
SDValue lowerFixedLengthVectorStoreToRVV(SDValue Op, SelectionDAG &DAG) const;
|
2021-02-13 01:20:54 +08:00
|
|
|
SDValue lowerFixedLengthVectorSetccToRVV(SDValue Op, SelectionDAG &DAG) const;
|
2021-02-09 02:32:32 +08:00
|
|
|
SDValue lowerToScalableOp(SDValue Op, SelectionDAG &DAG,
|
|
|
|
unsigned NewOpc) const;
|
2018-05-24 06:44:08 +08:00
|
|
|
|
2019-02-21 22:31:41 +08:00
|
|
|
bool isEligibleForTailCallOptimization(
|
|
|
|
CCState &CCInfo, CallLoweringInfo &CLI, MachineFunction &MF,
|
|
|
|
const SmallVector<CCValAssign, 16> &ArgLocs) const;
|
2018-09-19 18:54:22 +08:00
|
|
|
|
2019-10-23 04:25:01 +08:00
|
|
|
/// Generate error diagnostics if any register used by CC has been marked
|
|
|
|
/// reserved.
|
|
|
|
void validateCCReservedRegs(
|
|
|
|
const SmallVectorImpl<std::pair<llvm::Register, llvm::SDValue>> &Regs,
|
|
|
|
MachineFunction &MF) const;
|
2021-02-09 02:32:32 +08:00
|
|
|
|
|
|
|
bool useRVVForFixedLengthVectorVT(MVT VT) const;
|
2017-10-20 05:37:38 +08:00
|
|
|
};
|
2020-12-11 15:16:08 +08:00
|
|
|
|
2021-01-27 15:00:46 +08:00
|
|
|
namespace RISCV {
|
|
|
|
// We use 64 bits as the known part in the scalable vector types.
|
|
|
|
static constexpr unsigned RVVBitsPerBlock = 64;
|
2021-02-11 03:20:07 +08:00
|
|
|
} // namespace RISCV
|
2021-01-27 15:00:46 +08:00
|
|
|
|
2020-12-11 15:16:08 +08:00
|
|
|
namespace RISCVVIntrinsicsTable {
|
|
|
|
|
|
|
|
struct RISCVVIntrinsicInfo {
|
2021-01-28 04:22:36 +08:00
|
|
|
unsigned IntrinsicID;
|
|
|
|
uint8_t ExtendedOperand;
|
2020-12-11 15:16:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
using namespace RISCV;
|
|
|
|
|
|
|
|
#define GET_RISCVVIntrinsicsTable_DECL
|
|
|
|
#include "RISCVGenSearchableTables.inc"
|
|
|
|
|
|
|
|
} // end namespace RISCVVIntrinsicsTable
|
[RISCV] Implement vlseg intrinsics.
For Zvlsseg, we need continuous vector registers for the values. We need
to define new register classes for the different combinations of (number
of fields and LMUL). For example,
when the number of fields(NF) = 3, LMUL = 2, the values will be assigned
to (V0M2, V2M2, V4M2), (V2M2, V4M2, V6M2), (V4M2, V6M2, V8M2), ...
We define the vlseg intrinsics with multiple outputs. There is no way to
describe the codegen patterns with multiple outputs in the tablegen
files. We do the codegen in RISCVISelDAGToDAG and use EXTRACT_SUBREG to
extract the values of output.
The multiple scalable vector values will be put into a struct. This
patch is depended on the support for scalable vector struct.
Differential Revision: https://reviews.llvm.org/D94229
2020-12-31 17:14:15 +08:00
|
|
|
|
|
|
|
namespace RISCVZvlssegTable {
|
|
|
|
|
|
|
|
struct RISCVZvlsseg {
|
2021-01-28 04:22:36 +08:00
|
|
|
unsigned IntrinsicID;
|
|
|
|
uint8_t SEW;
|
|
|
|
uint8_t LMUL;
|
|
|
|
uint8_t IndexLMUL;
|
|
|
|
uint16_t Pseudo;
|
[RISCV] Implement vlseg intrinsics.
For Zvlsseg, we need continuous vector registers for the values. We need
to define new register classes for the different combinations of (number
of fields and LMUL). For example,
when the number of fields(NF) = 3, LMUL = 2, the values will be assigned
to (V0M2, V2M2, V4M2), (V2M2, V4M2, V6M2), (V4M2, V6M2, V8M2), ...
We define the vlseg intrinsics with multiple outputs. There is no way to
describe the codegen patterns with multiple outputs in the tablegen
files. We do the codegen in RISCVISelDAGToDAG and use EXTRACT_SUBREG to
extract the values of output.
The multiple scalable vector values will be put into a struct. This
patch is depended on the support for scalable vector struct.
Differential Revision: https://reviews.llvm.org/D94229
2020-12-31 17:14:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
using namespace RISCV;
|
|
|
|
|
|
|
|
#define GET_RISCVZvlssegTable_DECL
|
|
|
|
#include "RISCVGenSearchableTables.inc"
|
|
|
|
|
|
|
|
} // namespace RISCVZvlssegTable
|
2017-10-20 05:37:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|