[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp SelectionDAG.cpp SelectionDAGISel.cpp
Andrew Lenharth
alenhar2 at cs.uiuc.edu
Tue May 3 10:19:56 PDT 2005
Changes in directory llvm/lib/CodeGen/SelectionDAG:
LegalizeDAG.cpp updated: 1.93 -> 1.94
SelectionDAG.cpp updated: 1.97 -> 1.98
SelectionDAGISel.cpp updated: 1.45 -> 1.46
---
Log message:
Implement count leading zeros (ctlz), count trailing zeros (cttz), and count
population (ctpop). Generic lowering is implemented, however only promotion
is implemented for SelectionDAG at the moment.
More coming soon.
---
Diffs of the changes: (+66 -3)
LegalizeDAG.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++
SelectionDAG.cpp | 9 ++++++---
SelectionDAGISel.cpp | 15 +++++++++++++++
3 files changed, 66 insertions(+), 3 deletions(-)
Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.93 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.94
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.93 Fri Apr 29 23:43:14 2005
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Tue May 3 12:19:29 2005
@@ -987,6 +987,51 @@
}
break;
+ case ISD::CTPOP:
+ case ISD::CTTZ:
+ case ISD::CTLZ:
+ Tmp1 = LegalizeOp(Node->getOperand(0)); // Op
+ switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
+ case TargetLowering::Legal:
+ if (Tmp1 != Node->getOperand(0))
+ Result = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1);
+ break;
+ case TargetLowering::Promote: {
+ MVT::ValueType OVT = Tmp1.getValueType();
+ MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT);
+ //Zero extend the argument
+ Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1);
+ // Perform the larger operation, then subtract if needed.
+ Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1);
+ switch(Node->getOpcode())
+ {
+ case ISD::CTPOP:
+ Result = Tmp1;
+ break;
+ case ISD::CTTZ:
+ //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT)
+ Tmp2 = DAG.getSetCC(ISD::SETEQ, MVT::i1, Tmp1,
+ DAG.getConstant(getSizeInBits(NVT), NVT));
+ Result = DAG.getNode(ISD::SELECT, NVT, Tmp2,
+ DAG.getConstant(getSizeInBits(OVT),NVT), Tmp1);
+ break;
+ case ISD::CTLZ:
+ //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT))
+ Result = DAG.getNode(ISD::SUB, NVT, Tmp1,
+ DAG.getConstant(getSizeInBits(NVT) -
+ getSizeInBits(OVT), NVT));
+ break;
+ }
+ break;
+ }
+ case TargetLowering::Custom:
+ assert(0 && "Cannot custom handle this yet!");
+ case TargetLowering::Expand:
+ assert(0 && "Cannot expand this yet!");
+ break;
+ }
+ break;
+
// Unary operators
case ISD::FABS:
case ISD::FNEG:
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.97 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.98
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.97 Thu Apr 28 16:44:03 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Tue May 3 12:19:29 2005
@@ -1328,10 +1328,13 @@
return SDOperand(N, 0);
}
-SDOperand SelectionDAG::getSrcValue(const Value* v) {
- SDNode *N = new SrcValueSDNode(v);
+SDOperand SelectionDAG::getSrcValue(const Value* v, int offset) {
+ if (v && ValueNodes[std::make_pair(v,offset)])
+ return SDOperand(ValueNodes[std::make_pair(v,offset)], 0);
+ SDNode *N = new SrcValueSDNode(v, offset);
N->setValueTypes(MVT::Other);
- // FIXME: memoize NODES
+ if (v) //only track non-null values
+ ValueNodes[std::make_pair(v,offset)] = N;
AllNodes.push_back(N);
return SDOperand(N, 0);
}
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.45 llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.46
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.45 Fri Apr 29 23:43:14 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Tue May 3 12:19:29 2005
@@ -707,6 +707,21 @@
DAG.setRoot(DAG.getNode(ISD::PCMARKER, MVT::Other, getRoot(), Num));
return;
}
+ case Intrinsic::cttz:
+ setValue(&I, DAG.getNode(ISD::CTTZ,
+ getValue(I.getOperand(1)).getValueType(),
+ getValue(I.getOperand(1))));
+ return;
+ case Intrinsic::ctlz:
+ setValue(&I, DAG.getNode(ISD::CTLZ,
+ getValue(I.getOperand(1)).getValueType(),
+ getValue(I.getOperand(1))));
+ return;
+ case Intrinsic::ctpop:
+ setValue(&I, DAG.getNode(ISD::CTPOP,
+ getValue(I.getOperand(1)).getValueType(),
+ getValue(I.getOperand(1))));
+ return;
}
SDOperand Callee;
More information about the llvm-commits
mailing list