[llvm-commits] [llvm] r96336 - in /llvm/trunk: include/llvm/CodeGen/DAGISelHeader.h include/llvm/CodeGen/SelectionDAGISel.h utils/TableGen/DAGISelMatcher.h utils/TableGen/DAGISelMatcherEmitter.cpp
Chris Lattner
sabre at nondot.org
Mon Feb 15 23:21:18 PST 2010
Author: lattner
Date: Tue Feb 16 01:21:10 2010
New Revision: 96336
URL: http://llvm.org/viewvc/llvm-project?rev=96336&view=rev
Log:
generate code for node and pattern predicates. Note that this won't
build if enabled, it will fail with constness issues. I'll resolve
these next.
Modified:
llvm/trunk/include/llvm/CodeGen/DAGISelHeader.h
llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h
llvm/trunk/utils/TableGen/DAGISelMatcher.h
llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp
Modified: llvm/trunk/include/llvm/CodeGen/DAGISelHeader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DAGISelHeader.h?rev=96336&r1=96335&r2=96336&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/DAGISelHeader.h (original)
+++ llvm/trunk/include/llvm/CodeGen/DAGISelHeader.h Tue Feb 16 01:21:10 2010
@@ -164,23 +164,29 @@
return true;
}
-static int8_t GetInt1(const unsigned char *MatcherTable, unsigned &Idx) {
+// These functions are marked always inline so that Idx doesn't get pinned to
+// the stack.
+ALWAYS_INLINE static int8_t
+GetInt1(const unsigned char *MatcherTable, unsigned &Idx) {
return MatcherTable[Idx++];
}
-static int16_t GetInt2(const unsigned char *MatcherTable, unsigned &Idx) {
+ALWAYS_INLINE static int16_t
+GetInt2(const unsigned char *MatcherTable, unsigned &Idx) {
int16_t Val = GetInt1(MatcherTable, Idx);
Val |= int16_t(GetInt1(MatcherTable, Idx)) << 8;
return Val;
}
-static int32_t GetInt4(const unsigned char *MatcherTable, unsigned &Idx) {
+ALWAYS_INLINE static int32_t
+GetInt4(const unsigned char *MatcherTable, unsigned &Idx) {
int32_t Val = GetInt2(MatcherTable, Idx);
Val |= int32_t(GetInt2(MatcherTable, Idx)) << 16;
return Val;
}
-static int64_t GetInt8(const unsigned char *MatcherTable, unsigned &Idx) {
+ALWAYS_INLINE static int64_t
+GetInt8(const unsigned char *MatcherTable, unsigned &Idx) {
int64_t Val = GetInt4(MatcherTable, Idx);
Val |= int64_t(GetInt4(MatcherTable, Idx)) << 32;
return Val;
@@ -308,18 +314,12 @@
if (N != RecordedNodes[RecNo]) break;
continue;
}
- case OPC_CheckPatternPredicate: {
- unsigned PredNo = MatcherTable[MatcherIndex++];
- (void)PredNo;
- // FIXME: CHECK IT.
+ case OPC_CheckPatternPredicate:
+ if (!CheckPatternPredicate(MatcherTable[MatcherIndex++])) break;
continue;
- }
- case OPC_CheckPredicate: {
- unsigned PredNo = MatcherTable[MatcherIndex++];
- (void)PredNo;
- // FIXME: CHECK IT.
+ case OPC_CheckPredicate:
+ if (!CheckNodePredicate(N.getNode(), MatcherTable[MatcherIndex++])) break;
continue;
- }
case OPC_CheckComplexPat: {
unsigned PatNo = MatcherTable[MatcherIndex++];
(void)PatNo;
Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h?rev=96336&r1=96335&r2=96336&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h Tue Feb 16 01:21:10 2010
@@ -112,6 +112,25 @@
bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS,
int64_t DesiredMaskS) const;
+
+ /// CheckPatternPredicate - This function is generated by tblgen in the
+ /// target. It runs the specified pattern predicate and returns true if it
+ /// succeeds or false if it fails. The number is a private implementation
+ /// detail to the code tblgen produces.
+ virtual bool CheckPatternPredicate(unsigned PredNo) const {
+ assert(0 && "Tblgen should generate the implementation of this!");
+ return 0;
+ }
+
+ /// CheckNodePredicate - This function is generated by tblgen in the
+ /// target. It runs node predicate #PredNo and returns true if it succeeds or
+ /// false if it fails. The number is a private implementation
+ /// detail to the code tblgen produces.
+ virtual bool CheckNodePredicate(SDNode *N, unsigned PredNo) const {
+ assert(0 && "Tblgen should generate the implementation of this!");
+ return 0;
+ }
+
// Calls to these functions are generated by tblgen.
SDNode *Select_INLINEASM(SDNode *N);
SDNode *Select_UNDEF(SDNode *N);
Modified: llvm/trunk/utils/TableGen/DAGISelMatcher.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelMatcher.h?rev=96336&r1=96335&r2=96336&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelMatcher.h (original)
+++ llvm/trunk/utils/TableGen/DAGISelMatcher.h Tue Feb 16 01:21:10 2010
@@ -10,9 +10,10 @@
#ifndef TBLGEN_DAGISELMATCHER_H
#define TBLGEN_DAGISELMATCHER_H
+#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/StringRef.h"
-#include "llvm/CodeGen/ValueTypes.h"
+#include "llvm/Support/Casting.h"
namespace llvm {
class CodeGenDAGPatterns;
Modified: llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp?rev=96336&r1=96335&r2=96336&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp Tue Feb 16 01:21:10 2010
@@ -14,7 +14,7 @@
#include "DAGISelMatcher.h"
#include "CodeGenDAGPatterns.h"
#include "llvm/ADT/SmallString.h"
-#include "llvm/Support/Casting.h"
+#include "llvm/ADT/StringMap.h"
#include "llvm/Support/FormattedStream.h"
using namespace llvm;
@@ -66,12 +66,35 @@
namespace {
class MatcherTableEmitter {
formatted_raw_ostream &OS;
+
+ StringMap<unsigned> NodePredicateMap, PatternPredicateMap;
+ std::vector<std::string> NodePredicates, PatternPredicates;
+
public:
MatcherTableEmitter(formatted_raw_ostream &os) : OS(os) {}
unsigned EmitMatcherAndChildren(const MatcherNode *N, unsigned Indent);
+
+ void EmitPredicateFunctions();
private:
unsigned EmitMatcher(const MatcherNode *N, unsigned Indent);
+
+ unsigned getNodePredicate(StringRef PredName) {
+ unsigned &Entry = NodePredicateMap[PredName];
+ if (Entry == 0) {
+ NodePredicates.push_back(PredName.str());
+ Entry = NodePredicates.size();
+ }
+ return Entry-1;
+ }
+ unsigned getPatternPredicate(StringRef PredName) {
+ unsigned &Entry = PatternPredicateMap[PredName];
+ if (Entry == 0) {
+ PatternPredicates.push_back(PredName.str());
+ Entry = PatternPredicates.size();
+ }
+ return Entry-1;
+ }
};
} // end anonymous namespace.
@@ -107,18 +130,19 @@
<< cast<CheckSameMatcherNode>(N)->getMatchNumber() << ",\n";
return 2;
- case MatcherNode::CheckPatternPredicate:
- OS << "OPC_CheckPatternPredicate, /*XXX*/0,";
- OS.PadToColumn(CommentIndent) << "// "
- << cast<CheckPatternPredicateMatcherNode>(N)->getPredicate() << '\n';
+ case MatcherNode::CheckPatternPredicate: {
+ StringRef Pred = cast<CheckPatternPredicateMatcherNode>(N)->getPredicate();
+ OS << "OPC_CheckPatternPredicate, " << getPatternPredicate(Pred) << ',';
+ OS.PadToColumn(CommentIndent) << "// " << Pred << '\n';
return 2;
-
- case MatcherNode::CheckPredicate:
- OS << "OPC_CheckPredicate, /*XXX*/0,";
- OS.PadToColumn(CommentIndent) << "// "
- << cast<CheckPredicateMatcherNode>(N)->getPredicateName() << '\n';
+ }
+ case MatcherNode::CheckPredicate: {
+ StringRef Pred = cast<CheckPredicateMatcherNode>(N)->getPredicateName();
+ OS << "OPC_CheckPredicate, " << getNodePredicate(Pred) << ',';
+ OS.PadToColumn(CommentIndent) << "// " << Pred << '\n';
return 2;
-
+ }
+
case MatcherNode::CheckOpcode:
OS << "OPC_CheckOpcode, "
<< cast<CheckOpcodeMatcherNode>(N)->getOpcodeName() << ",\n";
@@ -216,6 +240,25 @@
}
}
+void MatcherTableEmitter::EmitPredicateFunctions() {
+ OS << "bool CheckPatternPredicate(unsigned PredNo) const {\n";
+ OS << " switch (PredNo) {\n";
+ OS << " default: assert(0 && \"Invalid predicate in table?\");\n";
+ for (unsigned i = 0, e = PatternPredicates.size(); i != e; ++i)
+ OS << " case " << i << ": return " << PatternPredicates[i] << ";\n";
+ OS << " }\n";
+ OS << "}\n\n";
+
+ OS << "bool CheckNodePredicate(SDNode *N, unsigned PredNo) const {\n";
+ OS << " switch (PredNo) {\n";
+ OS << " default: assert(0 && \"Invalid predicate in table?\");\n";
+ for (unsigned i = 0, e = NodePredicates.size(); i != e; ++i)
+ OS << " case " << i << ": return " << NodePredicates[i] << "(N);\n";
+ OS << " }\n";
+ OS << "}\n\n";
+}
+
+
void llvm::EmitMatcherTable(const MatcherNode *Matcher, raw_ostream &O) {
formatted_raw_ostream OS(O);
@@ -228,4 +271,8 @@
unsigned TotalSize = MatcherEmitter.EmitMatcherAndChildren(Matcher, 2);
OS << " 0\n }; // Total Array size is " << (TotalSize+1) << " bytes\n\n";
OS << " return SelectCodeCommon(N, MatcherTable,sizeof(MatcherTable));\n}\n";
+ OS << "\n";
+
+ // Next up, emit the function for node and pattern predicates:
+ MatcherEmitter.EmitPredicateFunctions();
}
More information about the llvm-commits
mailing list