[llvm] r269393 - SDAG: Implement Select instead of SelectImpl in MSP430DAGToDAGISel
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Thu May 12 23:10:50 PDT 2016
Author: bogner
Date: Fri May 13 01:10:50 2016
New Revision: 269393
URL: http://llvm.org/viewvc/llvm-project?rev=269393&view=rev
Log:
SDAG: Implement Select instead of SelectImpl in MSP430DAGToDAGISel
- Where we were returning a node before, call ReplaceNode instead.
- Where we would return null to fall back to another selector, rename
the method to try* and return a bool for success.
- Where we were calling SelectNodeTo, just return afterwards.
Part of llvm.org/pr26808.
Modified:
llvm/trunk/lib/Target/MSP430/MSP430ISelDAGToDAG.cpp
Modified: llvm/trunk/lib/Target/MSP430/MSP430ISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/MSP430ISelDAGToDAG.cpp?rev=269393&r1=269392&r2=269393&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MSP430/MSP430ISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/MSP430/MSP430ISelDAGToDAG.cpp Fri May 13 01:10:50 2016
@@ -110,10 +110,10 @@ namespace {
#include "MSP430GenDAGISel.inc"
private:
- SDNode *SelectImpl(SDNode *N) override;
- SDNode *SelectIndexedLoad(SDNode *Op);
- SDNode *SelectIndexedBinOp(SDNode *Op, SDValue N1, SDValue N2,
- unsigned Opc8, unsigned Opc16);
+ void Select(SDNode *N) override;
+ bool tryIndexedLoad(SDNode *Op);
+ bool tryIndexedBinOp(SDNode *Op, SDValue N1, SDValue N2, unsigned Opc8,
+ unsigned Opc16);
bool SelectAddr(SDValue Addr, SDValue &Base, SDValue &Disp);
};
@@ -323,10 +323,10 @@ static bool isValidIndexedLoad(const Loa
return true;
}
-SDNode *MSP430DAGToDAGISel::SelectIndexedLoad(SDNode *N) {
+bool MSP430DAGToDAGISel::tryIndexedLoad(SDNode *N) {
LoadSDNode *LD = cast<LoadSDNode>(N);
if (!isValidIndexedLoad(LD))
- return nullptr;
+ return false;
MVT VT = LD->getMemoryVT().getSimpleVT();
@@ -339,23 +339,23 @@ SDNode *MSP430DAGToDAGISel::SelectIndexe
Opcode = MSP430::MOV16rm_POST;
break;
default:
- return nullptr;
+ return false;
}
- return CurDAG->getMachineNode(Opcode, SDLoc(N),
- VT, MVT::i16, MVT::Other,
- LD->getBasePtr(), LD->getChain());
+ ReplaceNode(N,
+ CurDAG->getMachineNode(Opcode, SDLoc(N), VT, MVT::i16, MVT::Other,
+ LD->getBasePtr(), LD->getChain()));
+ return true;
}
-SDNode *MSP430DAGToDAGISel::SelectIndexedBinOp(SDNode *Op,
- SDValue N1, SDValue N2,
- unsigned Opc8, unsigned Opc16) {
+bool MSP430DAGToDAGISel::tryIndexedBinOp(SDNode *Op, SDValue N1, SDValue N2,
+ unsigned Opc8, unsigned Opc16) {
if (N1.getOpcode() == ISD::LOAD &&
N1.hasOneUse() &&
IsLegalToFold(N1, Op, Op, OptLevel)) {
LoadSDNode *LD = cast<LoadSDNode>(N1);
if (!isValidIndexedLoad(LD))
- return nullptr;
+ return false;
MVT VT = LD->getMemoryVT().getSimpleVT();
unsigned Opc = (VT == MVT::i16 ? Opc16 : Opc8);
@@ -369,14 +369,14 @@ SDNode *MSP430DAGToDAGISel::SelectIndexe
ReplaceUses(SDValue(N1.getNode(), 2), SDValue(ResNode, 2));
// Transfer writeback.
ReplaceUses(SDValue(N1.getNode(), 1), SDValue(ResNode, 1));
- return ResNode;
+ return true;
}
- return nullptr;
+ return false;
}
-SDNode *MSP430DAGToDAGISel::SelectImpl(SDNode *Node) {
+void MSP430DAGToDAGISel::Select(SDNode *Node) {
SDLoc dl(Node);
// Dump information about the Node being selected
@@ -390,7 +390,7 @@ SDNode *MSP430DAGToDAGISel::SelectImpl(S
Node->dump(CurDAG);
errs() << "\n");
Node->setNodeId(-1);
- return nullptr;
+ return;
}
// Few custom selection stuff.
@@ -400,89 +400,70 @@ SDNode *MSP430DAGToDAGISel::SelectImpl(S
assert(Node->getValueType(0) == MVT::i16);
int FI = cast<FrameIndexSDNode>(Node)->getIndex();
SDValue TFI = CurDAG->getTargetFrameIndex(FI, MVT::i16);
- if (Node->hasOneUse())
- return CurDAG->SelectNodeTo(Node, MSP430::ADD16ri, MVT::i16, TFI,
- CurDAG->getTargetConstant(0, dl, MVT::i16));
- return CurDAG->getMachineNode(MSP430::ADD16ri, dl, MVT::i16, TFI,
- CurDAG->getTargetConstant(0, dl, MVT::i16));
+ if (Node->hasOneUse()) {
+ CurDAG->SelectNodeTo(Node, MSP430::ADD16ri, MVT::i16, TFI,
+ CurDAG->getTargetConstant(0, dl, MVT::i16));
+ return;
+ }
+ ReplaceNode(Node, CurDAG->getMachineNode(
+ MSP430::ADD16ri, dl, MVT::i16, TFI,
+ CurDAG->getTargetConstant(0, dl, MVT::i16)));
+ return;
}
case ISD::LOAD:
- if (SDNode *ResNode = SelectIndexedLoad(Node))
- return ResNode;
+ if (tryIndexedLoad(Node))
+ return;
// Other cases are autogenerated.
break;
case ISD::ADD:
- if (SDNode *ResNode =
- SelectIndexedBinOp(Node,
- Node->getOperand(0), Node->getOperand(1),
- MSP430::ADD8rm_POST, MSP430::ADD16rm_POST))
- return ResNode;
- else if (SDNode *ResNode =
- SelectIndexedBinOp(Node, Node->getOperand(1), Node->getOperand(0),
- MSP430::ADD8rm_POST, MSP430::ADD16rm_POST))
- return ResNode;
+ if (tryIndexedBinOp(Node, Node->getOperand(0), Node->getOperand(1),
+ MSP430::ADD8rm_POST, MSP430::ADD16rm_POST))
+ return;
+ else if (tryIndexedBinOp(Node, Node->getOperand(1), Node->getOperand(0),
+ MSP430::ADD8rm_POST, MSP430::ADD16rm_POST))
+ return;
// Other cases are autogenerated.
break;
case ISD::SUB:
- if (SDNode *ResNode =
- SelectIndexedBinOp(Node,
- Node->getOperand(0), Node->getOperand(1),
- MSP430::SUB8rm_POST, MSP430::SUB16rm_POST))
- return ResNode;
+ if (tryIndexedBinOp(Node, Node->getOperand(0), Node->getOperand(1),
+ MSP430::SUB8rm_POST, MSP430::SUB16rm_POST))
+ return;
// Other cases are autogenerated.
break;
case ISD::AND:
- if (SDNode *ResNode =
- SelectIndexedBinOp(Node,
- Node->getOperand(0), Node->getOperand(1),
- MSP430::AND8rm_POST, MSP430::AND16rm_POST))
- return ResNode;
- else if (SDNode *ResNode =
- SelectIndexedBinOp(Node, Node->getOperand(1), Node->getOperand(0),
- MSP430::AND8rm_POST, MSP430::AND16rm_POST))
- return ResNode;
+ if (tryIndexedBinOp(Node, Node->getOperand(0), Node->getOperand(1),
+ MSP430::AND8rm_POST, MSP430::AND16rm_POST))
+ return;
+ else if (tryIndexedBinOp(Node, Node->getOperand(1), Node->getOperand(0),
+ MSP430::AND8rm_POST, MSP430::AND16rm_POST))
+ return;
// Other cases are autogenerated.
break;
case ISD::OR:
- if (SDNode *ResNode =
- SelectIndexedBinOp(Node,
- Node->getOperand(0), Node->getOperand(1),
- MSP430::OR8rm_POST, MSP430::OR16rm_POST))
- return ResNode;
- else if (SDNode *ResNode =
- SelectIndexedBinOp(Node, Node->getOperand(1), Node->getOperand(0),
- MSP430::OR8rm_POST, MSP430::OR16rm_POST))
- return ResNode;
+ if (tryIndexedBinOp(Node, Node->getOperand(0), Node->getOperand(1),
+ MSP430::OR8rm_POST, MSP430::OR16rm_POST))
+ return;
+ else if (tryIndexedBinOp(Node, Node->getOperand(1), Node->getOperand(0),
+ MSP430::OR8rm_POST, MSP430::OR16rm_POST))
+ return;
// Other cases are autogenerated.
break;
case ISD::XOR:
- if (SDNode *ResNode =
- SelectIndexedBinOp(Node,
- Node->getOperand(0), Node->getOperand(1),
- MSP430::XOR8rm_POST, MSP430::XOR16rm_POST))
- return ResNode;
- else if (SDNode *ResNode =
- SelectIndexedBinOp(Node, Node->getOperand(1), Node->getOperand(0),
- MSP430::XOR8rm_POST, MSP430::XOR16rm_POST))
- return ResNode;
+ if (tryIndexedBinOp(Node, Node->getOperand(0), Node->getOperand(1),
+ MSP430::XOR8rm_POST, MSP430::XOR16rm_POST))
+ return;
+ else if (tryIndexedBinOp(Node, Node->getOperand(1), Node->getOperand(0),
+ MSP430::XOR8rm_POST, MSP430::XOR16rm_POST))
+ return;
// Other cases are autogenerated.
break;
}
// Select the default instruction
- SDNode *ResNode = SelectCode(Node);
-
- DEBUG(errs() << "=> ");
- if (ResNode == nullptr || ResNode == Node)
- DEBUG(Node->dump(CurDAG));
- else
- DEBUG(ResNode->dump(CurDAG));
- DEBUG(errs() << "\n");
-
- return ResNode;
+ SelectCode(Node);
}
More information about the llvm-commits
mailing list