body before the push.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96726
91177308-0d34-0410-b5e6-
96231b3b80d8
namespace {
class MatcherTableEmitter {
namespace {
class MatcherTableEmitter {
- formatted_raw_ostream &OS;
-
StringMap<unsigned> NodePredicateMap, PatternPredicateMap;
std::vector<std::string> NodePredicates, PatternPredicates;
StringMap<unsigned> NodePredicateMap, PatternPredicateMap;
std::vector<std::string> NodePredicates, PatternPredicates;
std::vector<const Record*> NodeXForms;
public:
std::vector<const Record*> NodeXForms;
public:
- MatcherTableEmitter(formatted_raw_ostream &os) : OS(os) {}
+ MatcherTableEmitter() {}
- unsigned EmitMatcherList(const MatcherNode *N, unsigned Indent);
+ unsigned EmitMatcherList(const MatcherNode *N, unsigned Indent,
+ formatted_raw_ostream &OS);
- void EmitPredicateFunctions();
+ void EmitPredicateFunctions(formatted_raw_ostream &OS);
- unsigned EmitMatcher(const MatcherNode *N, unsigned Indent);
+ unsigned EmitMatcher(const MatcherNode *N, unsigned Indent,
+ formatted_raw_ostream &OS);
unsigned getNodePredicate(StringRef PredName) {
unsigned &Entry = NodePredicateMap[PredName];
unsigned getNodePredicate(StringRef PredName) {
unsigned &Entry = NodePredicateMap[PredName];
/// EmitMatcherOpcodes - Emit bytes for the specified matcher and return
/// the number of bytes emitted.
unsigned MatcherTableEmitter::
/// EmitMatcherOpcodes - Emit bytes for the specified matcher and return
/// the number of bytes emitted.
unsigned MatcherTableEmitter::
-EmitMatcher(const MatcherNode *N, unsigned Indent) {
+EmitMatcher(const MatcherNode *N, unsigned Indent, formatted_raw_ostream &OS) {
OS.PadToColumn(Indent*2);
switch (N->getKind()) {
OS.PadToColumn(Indent*2);
switch (N->getKind()) {
<< *CM->getPattern().getSrcPattern() << '\n';
OS.PadToColumn(Indent*2) << "// Dst: "
<< *CM->getPattern().getDstPattern() << '\n';
<< *CM->getPattern().getSrcPattern() << '\n';
OS.PadToColumn(Indent*2) << "// Dst: "
<< *CM->getPattern().getDstPattern() << '\n';
+ return 2+CM->getNumResults();
}
}
assert(0 && "Unreachable");
}
}
assert(0 && "Unreachable");
/// EmitMatcherList - Emit the bytes for the specified matcher subtree.
unsigned MatcherTableEmitter::
/// EmitMatcherList - Emit the bytes for the specified matcher subtree.
unsigned MatcherTableEmitter::
-EmitMatcherList(const MatcherNode *N, unsigned Indent) {
+EmitMatcherList(const MatcherNode *N, unsigned Indent,
+ formatted_raw_ostream &OS) {
unsigned Size = 0;
while (N) {
// Push is a special case since it is binary.
unsigned Size = 0;
while (N) {
// Push is a special case since it is binary.
raw_svector_ostream OS(TmpBuf);
formatted_raw_ostream FOS(OS);
NextSize = EmitMatcherList(cast<PushMatcherNode>(N)->getNext(),
raw_svector_ostream OS(TmpBuf);
formatted_raw_ostream FOS(OS);
NextSize = EmitMatcherList(cast<PushMatcherNode>(N)->getNext(),
- Size += EmitMatcher(N, Indent);
+ Size += EmitMatcher(N, Indent, OS);
// If there are other nodes in this list, iterate to them, otherwise we're
// done.
// If there are other nodes in this list, iterate to them, otherwise we're
// done.
-void MatcherTableEmitter::EmitPredicateFunctions() {
+void MatcherTableEmitter::EmitPredicateFunctions(formatted_raw_ostream &OS) {
// FIXME: Don't build off the DAGISelEmitter's predicates, emit them directly
// here into the case stmts.
// FIXME: Don't build off the DAGISelEmitter's predicates, emit them directly
// here into the case stmts.
OS << "// The main instruction selector code.\n";
OS << "SDNode *SelectCode2(SDNode *N) {\n";
OS << "// The main instruction selector code.\n";
OS << "SDNode *SelectCode2(SDNode *N) {\n";
- MatcherTableEmitter MatcherEmitter(OS);
+ MatcherTableEmitter MatcherEmitter;
OS << " // Opcodes are emitted as 2 bytes, TARGET_OPCODE handles this.\n";
OS << " #define TARGET_OPCODE(X) X & 255, unsigned(X) >> 8\n";
OS << " static const unsigned char MatcherTable[] = {\n";
OS << " // Opcodes are emitted as 2 bytes, TARGET_OPCODE handles this.\n";
OS << " #define TARGET_OPCODE(X) X & 255, unsigned(X) >> 8\n";
OS << " static const unsigned char MatcherTable[] = {\n";
- unsigned TotalSize = MatcherEmitter.EmitMatcherList(Matcher, 2);
+ unsigned TotalSize = MatcherEmitter.EmitMatcherList(Matcher, 2, OS);
OS << " 0\n }; // Total Array size is " << (TotalSize+1) << " bytes\n\n";
OS << " #undef TARGET_OPCODE\n";
OS << " return SelectCodeCommon(N, MatcherTable,sizeof(MatcherTable));\n}\n";
OS << "\n";
// Next up, emit the function for node and pattern predicates:
OS << " 0\n }; // Total Array size is " << (TotalSize+1) << " bytes\n\n";
OS << " #undef TARGET_OPCODE\n";
OS << " return SelectCodeCommon(N, MatcherTable,sizeof(MatcherTable));\n}\n";
OS << "\n";
// Next up, emit the function for node and pattern predicates:
- MatcherEmitter.EmitPredicateFunctions();
+ MatcherEmitter.EmitPredicateFunctions(OS);