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();
59 void doPeepholeBuildPairF64SplitF64();
63 void RISCVDAGToDAGISel::PostprocessISelDAG() {
64 doPeepholeLoadStoreADDI();
65 doPeepholeBuildPairF64SplitF64();
70 MVT XLenVT = Subtarget->getXLenVT();
83 auto *ConstNode = cast<ConstantSDNode>(Node);
86 if (ConstNode->isNullValue()) {
87 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
SDLoc(Node),
89 ReplaceNode(Node, New.
getNode());
95 SDValue Imm = CurDAG->getTargetConstant(0, DL, XLenVT);
96 int FI = cast<FrameIndexSDNode>(Node)->getIndex();
98 SDValue TFI = CurDAG->getTargetFrameIndex(FI, VT);
99 ReplaceNode(Node, CurDAG->getMachineNode(RISCV::ADDI, DL, VT, TFI, Imm));
107 bool RISCVDAGToDAGISel::SelectInlineAsmMemoryOperand(
108 const SDValue &
Op,
unsigned ConstraintID, std::vector<SDValue> &OutOps) {
109 switch (ConstraintID) {
114 OutOps.push_back(Op);
124 if (
auto FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
125 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), Subtarget->getXLenVT());
134 void RISCVDAGToDAGISel::doPeepholeLoadStoreADDI() {
138 while (Position != CurDAG->allnodes_begin()) {
176 if (!isa<ConstantSDNode>(N->
getOperand(OffsetOpIdx)) ||
188 if (
auto Const = dyn_cast<ConstantSDNode>(ImmOperand)) {
189 ImmOperand = CurDAG->getTargetConstant(
191 }
else if (
auto GA = dyn_cast<GlobalAddressSDNode>(ImmOperand)) {
192 ImmOperand = CurDAG->getTargetGlobalAddress(
194 GA->getOffset(), GA->getTargetFlags());
199 LLVM_DEBUG(
dbgs() <<
"Folding add-immediate into mem-op:\nBase: ");
207 CurDAG->UpdateNodeOperands(N, Base.
getOperand(0), ImmOperand,
215 CurDAG->RemoveDeadNode(Base.
getNode());
224 void RISCVDAGToDAGISel::doPeepholeBuildPairF64SplitF64() {
228 while (Position != CurDAG->allnodes_begin()) {
241 dbgs() <<
"Removing redundant SplitF64Pseudo and replacing uses " 242 "with BuildPairF64Pseudo operands:\n");
250 CurDAG->ReplaceAllUsesOfValuesWith(From, To, 2);
253 CurDAG->RemoveDeadNodes();
259 return new RISCVDAGToDAGISel(TM);
EVT getValueType() const
Return the ValueType of the referenced return value.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
Compute iterated dominance frontiers using a linear time algorithm.
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
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...
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.
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.
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
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...