24 #define DEBUG_TYPE "riscv-isel" 37 return "RISCV DAG->DAG Pattern Instruction Selection";
45 void PostprocessISelDAG()
override;
49 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
unsigned ConstraintID,
50 std::vector<SDValue> &OutOps)
override;
55 #include "RISCVGenDAGISel.inc" 58 void doPeepholeLoadStoreADDI();
62 void RISCVDAGToDAGISel::PostprocessISelDAG() {
63 doPeepholeLoadStoreADDI();
75 if (Inst.Opc == RISCV::LUI)
78 Result = CurDAG->
getMachineNode(Inst.Opc, DL, XLenVT, SrcReg, SDImm);
92 Mask = cast<ConstantSDNode>(Node->
getOperand(1))->getZExtValue();
109 MVT XLenVT = Subtarget->getXLenVT();
115 auto ConstNode = cast<ConstantSDNode>(Node);
116 if (VT == XLenVT && ConstNode->isNullValue()) {
117 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
SDLoc(Node),
119 ReplaceNode(Node, New.
getNode());
122 int64_t Imm = ConstNode->getSExtValue();
130 SDValue Imm = CurDAG->getTargetConstant(0, DL, XLenVT);
131 int FI = cast<FrameIndexSDNode>(Node)->getIndex();
132 SDValue TFI = CurDAG->getTargetFrameIndex(FI, VT);
133 ReplaceNode(Node, CurDAG->getMachineNode(RISCV::ADDI, DL, VT, TFI, Imm));
137 if (!Subtarget->is64Bit())
148 uint64_t ShAmt = cast<ConstantSDNode>(Op1.
getNode())->getZExtValue();
150 if ((Mask | maskTrailingOnes<uint64_t>(ShAmt)) == 0xffffffff) {
152 CurDAG->getTargetConstant(ShAmt,
SDLoc(Node), XLenVT);
153 CurDAG->SelectNodeTo(Node, RISCV::SRLIW, XLenVT, Op0.
getOperand(0),
161 assert(!Subtarget->is64Bit() &&
"READ_CYCLE_WIDE is only used on riscv32");
163 ReplaceNode(Node, CurDAG->getMachineNode(RISCV::ReadCycleWide, DL,
MVT::i32,
173 bool RISCVDAGToDAGISel::SelectInlineAsmMemoryOperand(
174 const SDValue &
Op,
unsigned ConstraintID, std::vector<SDValue> &OutOps) {
175 switch (ConstraintID) {
179 OutOps.push_back(Op);
182 OutOps.push_back(Op);
192 if (
auto FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
193 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), Subtarget->getXLenVT());
202 void RISCVDAGToDAGISel::doPeepholeLoadStoreADDI() {
206 while (Position != CurDAG->allnodes_begin()) {
244 if (!isa<ConstantSDNode>(N->
getOperand(OffsetOpIdx)) ||
256 if (
auto Const = dyn_cast<ConstantSDNode>(ImmOperand)) {
257 ImmOperand = CurDAG->getTargetConstant(
259 }
else if (
auto GA = dyn_cast<GlobalAddressSDNode>(ImmOperand)) {
260 ImmOperand = CurDAG->getTargetGlobalAddress(
262 GA->getOffset(), GA->getTargetFlags());
267 LLVM_DEBUG(
dbgs() <<
"Folding add-immediate into mem-op:\nBase: ");
275 CurDAG->UpdateNodeOperands(N, Base.
getOperand(0), ImmOperand,
283 CurDAG->RemoveDeadNode(Base.
getNode());
290 return new RISCVDAGToDAGISel(TM);
static bool isConstantMask(SDNode *Node, uint64_t &Mask)
EVT getValueType() const
Return the ValueType of the referenced return value.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
This class represents lattice values for constants.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
void setNodeId(int Id)
Set unique node id.
SDNode * getNode() const
get the SDNode which holds the desired result
MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s), MachineInstr opcode, and operands.
Position
Position to insert a new instruction relative to an existing instruction.
FunctionPass * createRISCVISelDag(RISCVTargetMachine &TM)
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This instruction implements an extending load to FP stack slots.
bool isMachineOpcode() const
const SDValue & getOperand(unsigned Num) const
unsigned getMachineOpcode() const
FunctionPass class - This class is used to implement most global optimizations.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
bool use_empty() const
Return true if there are no uses of this node.
void dump() const
Dump this node, for debugging.
Iterator for intrusive lists based on ilist_node.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
static SDNode * selectImm(SelectionDAG *CurDAG, const SDLoc &DL, int64_t Imm, MVT XLenVT)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Bitwise operators - logical and, logical or, logical xor.
void generateInstSeq(int64_t Val, bool IsRV64, InstSeq &Res)
unsigned getOpcode() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
SDValue getRegister(unsigned Reg, EVT VT)
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
const SDValue & getOperand(unsigned i) const
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...