[llvm-commits] [llvm] r96636 - /llvm/trunk/utils/TableGen/DAGISelMatcherGen.cpp
Chris Lattner
sabre at nondot.org
Thu Feb 18 16:27:40 PST 2010
Author: lattner
Date: Thu Feb 18 18:27:40 2010
New Revision: 96636
URL: http://llvm.org/viewvc/llvm-project?rev=96636&view=rev
Log:
introduce a new ResultVal and start keeping track of temporary values.
Modified:
llvm/trunk/utils/TableGen/DAGISelMatcherGen.cpp
Modified: llvm/trunk/utils/TableGen/DAGISelMatcherGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelMatcherGen.cpp?rev=96636&r1=96635&r2=96636&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelMatcherGen.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelMatcherGen.cpp Thu Feb 18 18:27:40 2010
@@ -15,6 +15,46 @@
using namespace llvm;
namespace {
+ /// ResultVal - When generating new nodes for the result of a pattern match,
+ /// this value is used to represent an input to the node. Result values can
+ /// either be an input that is 'recorded' in the RecordedNodes array by the
+ /// matcher or it can be a temporary value created by the emitter for things
+ /// like constants.
+ class ResultVal {
+ unsigned Number : 30;
+ enum {
+ Recorded, Temporary
+ } Kind : 2; // True if temporary, false if recorded.
+ public:
+ static ResultVal getRecorded(unsigned N) {
+ ResultVal R;
+ R.Number = N;
+ R.Kind = Recorded;
+ return R;
+ }
+
+ static ResultVal getTemp(unsigned N) {
+ ResultVal R;
+ R.Number = N;
+ R.Kind = Temporary;
+ return R;
+ }
+
+ bool isTemp() const { return Kind == Temporary; }
+ bool isRecorded() const { return Kind == Recorded; }
+
+ unsigned getTempNo() const {
+ assert(isTemp());
+ return Number;
+ }
+
+ unsigned getRecordedNo() const {
+ assert(isRecorded());
+ return Number;
+ }
+ };
+
+
class MatcherGen {
const PatternToMatch &Pattern;
const CodeGenDAGPatterns &CGP;
@@ -28,8 +68,16 @@
/// number that they were captured as. These are biased by 1 to make
/// insertion easier.
StringMap<unsigned> VariableMap;
+
+ /// NextRecordedOperandNo - As we emit opcodes to record matched values in
+ /// the RecordedNodes array, this keeps track of which slot will be next to
+ /// record into.
unsigned NextRecordedOperandNo;
+ /// NextTemporary - As we generate code, this indicates the next temporary
+ /// ID that will be generated.
+ unsigned NextTemporary;
+
/// InputChains - This maintains the position in the recorded nodes array of
/// all of the recorded input chains.
SmallVector<unsigned, 2> InputChains;
@@ -64,18 +112,18 @@
// Result Code Generation.
void EmitResultOperand(const TreePatternNode *N,
- SmallVectorImpl<unsigned> &ResultOps);
+ SmallVectorImpl<ResultVal> &ResultOps);
void EmitResultLeafAsOperand(const TreePatternNode *N,
- SmallVectorImpl<unsigned> &ResultOps);
+ SmallVectorImpl<ResultVal> &ResultOps);
void EmitResultInstructionAsOperand(const TreePatternNode *N,
- SmallVectorImpl<unsigned> &ResultOps);
+ SmallVectorImpl<ResultVal> &ResultOps);
};
} // end anon namespace.
MatcherGen::MatcherGen(const PatternToMatch &pattern,
const CodeGenDAGPatterns &cgp)
-: Pattern(pattern), CGP(cgp), NextRecordedOperandNo(0),
+: Pattern(pattern), CGP(cgp), NextRecordedOperandNo(0), NextTemporary(0),
Matcher(0), CurPredicate(0) {
// We need to produce the matcher tree for the patterns source pattern. To do
// this we need to match the structure as well as the types. To do the type
@@ -396,12 +444,12 @@
//===----------------------------------------------------------------------===//
void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode *N,
- SmallVectorImpl<unsigned> &ResultOps) {
+ SmallVectorImpl<ResultVal> &ResultOps){
assert(N->isLeaf() && "Must be a leaf");
if (IntInit *II = dynamic_cast<IntInit*>(N->getLeafValue())) {
AddMatcherNode(new EmitIntegerMatcherNode(II->getValue(),N->getTypeNum(0)));
- //ResultOps.push_back(TmpNode(TmpNo++));
+ ResultOps.push_back(ResultVal::getTemp(NextTemporary++));
return;
}
@@ -410,13 +458,13 @@
if (DI->getDef()->isSubClassOf("Register")) {
AddMatcherNode(new EmitRegisterMatcherNode(DI->getDef(),
N->getTypeNum(0)));
- //ResultOps.push_back(TmpNode(TmpNo++));
+ ResultOps.push_back(ResultVal::getTemp(NextTemporary++));
return;
}
if (DI->getDef()->getName() == "zero_reg") {
AddMatcherNode(new EmitRegisterMatcherNode(0, N->getTypeNum(0)));
- //ResultOps.push_back(TmpNode(TmpNo++));
+ ResultOps.push_back(ResultVal::getTemp(NextTemporary++));
return;
}
@@ -434,7 +482,7 @@
}
void MatcherGen::EmitResultInstructionAsOperand(const TreePatternNode *N,
- SmallVectorImpl<unsigned> &ResultOps) {
+ SmallVectorImpl<ResultVal> &ResultOps){
Record *Op = N->getOperator();
const CodeGenTarget &CGT = CGP.getTargetInfo();
CodeGenInstruction &II = CGT.getInstruction(Op->getName());
@@ -456,7 +504,7 @@
// where there are predicate operands for an instruction, we need to fill
// in the 'execute always' values. Match up the node operands to the
// instruction operands to do this.
- SmallVector<unsigned, 8> Ops;
+ SmallVector<ResultVal, 8> Ops;
for (unsigned ChildNo = 0, InstOpNo = NumResults, e = II.OperandList.size();
InstOpNo != e; ++InstOpNo) {
@@ -489,7 +537,7 @@
}
void MatcherGen::EmitResultOperand(const TreePatternNode *N,
- SmallVectorImpl<unsigned> &ResultOps) {
+ SmallVectorImpl<ResultVal> &ResultOps) {
// This is something selected from the pattern we matched.
if (!N->getName().empty()) {
//errs() << "unhandled named node: \n";
@@ -514,7 +562,7 @@
// FIXME: Handle Ops.
// FIXME: Ops should be vector of "ResultValue> which is either an index into
// the results vector is is a temp result.
- SmallVector<unsigned, 8> Ops;
+ SmallVector<ResultVal, 8> Ops;
EmitResultOperand(Pattern.getDstPattern(), Ops);
//AddMatcherNode(new EmitNodeMatcherNode(Pattern));
}
More information about the llvm-commits
mailing list