2010-02-15 08:04:42 +00:00
|
|
|
//===- DAGISelMatcherEmitter.cpp - Matcher Emitter ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains code to generate C++ code a matcher.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DAGISelMatcher.h"
|
|
|
|
#include "CodeGenDAGPatterns.h"
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
#include "Record.h"
|
2010-02-17 00:31:50 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2010-02-15 08:04:42 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2010-02-16 07:21:10 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2010-02-15 08:04:42 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
enum {
|
2010-02-17 00:39:26 +00:00
|
|
|
CommentIndent = 30
|
2010-02-15 08:04:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ClassifyInt - Classify an integer by size, return '1','2','4','8' if this
|
|
|
|
/// fits in 1, 2, 4, or 8 sign extended bytes.
|
|
|
|
static char ClassifyInt(int64_t Val) {
|
|
|
|
if (Val == int8_t(Val)) return '1';
|
|
|
|
if (Val == int16_t(Val)) return '2';
|
|
|
|
if (Val == int32_t(Val)) return '4';
|
|
|
|
return '8';
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitInt - Emit the specified integer, returning the number of bytes emitted.
|
|
|
|
static unsigned EmitInt(int64_t Val, formatted_raw_ostream &OS) {
|
|
|
|
unsigned BytesEmitted = 1;
|
|
|
|
OS << (int)(unsigned char)Val << ", ";
|
|
|
|
if (Val == int8_t(Val)) {
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
OS << '\n';
|
2010-02-15 08:04:42 +00:00
|
|
|
return BytesEmitted;
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << (int)(unsigned char)(Val >> 8) << ", ";
|
|
|
|
++BytesEmitted;
|
|
|
|
|
|
|
|
if (Val != int16_t(Val)) {
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
OS << (int)(unsigned char)(Val >> 16) << ", "
|
|
|
|
<< (int)(unsigned char)(Val >> 24) << ", ";
|
2010-02-15 08:04:42 +00:00
|
|
|
BytesEmitted += 2;
|
|
|
|
|
|
|
|
if (Val != int32_t(Val)) {
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
OS << (int)(unsigned char)(Val >> 32) << ", "
|
|
|
|
<< (int)(unsigned char)(Val >> 40) << ", "
|
|
|
|
<< (int)(unsigned char)(Val >> 48) << ", "
|
|
|
|
<< (int)(unsigned char)(Val >> 56) << ", ";
|
2010-02-15 08:04:42 +00:00
|
|
|
BytesEmitted += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
OS.PadToColumn(CommentIndent) << "// " << Val << " aka 0x";
|
|
|
|
OS.write_hex(Val) << '\n';
|
2010-02-15 08:04:42 +00:00
|
|
|
return BytesEmitted;
|
|
|
|
}
|
|
|
|
|
2010-02-16 06:52:01 +00:00
|
|
|
namespace {
|
|
|
|
class MatcherTableEmitter {
|
2010-02-16 07:21:10 +00:00
|
|
|
StringMap<unsigned> NodePredicateMap, PatternPredicateMap;
|
|
|
|
std::vector<std::string> NodePredicates, PatternPredicates;
|
2010-02-17 00:31:50 +00:00
|
|
|
|
|
|
|
DenseMap<const ComplexPattern*, unsigned> ComplexPatternMap;
|
|
|
|
std::vector<const ComplexPattern*> ComplexPatterns;
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
DenseMap<Record*, unsigned> NodeXFormMap;
|
|
|
|
std::vector<const Record*> NodeXForms;
|
|
|
|
|
2010-02-16 06:52:01 +00:00
|
|
|
public:
|
2010-02-21 06:30:04 +00:00
|
|
|
MatcherTableEmitter() {}
|
2010-02-16 06:52:01 +00:00
|
|
|
|
2010-02-21 06:30:04 +00:00
|
|
|
unsigned EmitMatcherList(const MatcherNode *N, unsigned Indent,
|
2010-02-21 07:16:41 +00:00
|
|
|
unsigned StartIdx, formatted_raw_ostream &OS);
|
2010-02-16 07:21:10 +00:00
|
|
|
|
2010-02-21 06:30:04 +00:00
|
|
|
void EmitPredicateFunctions(formatted_raw_ostream &OS);
|
2010-02-16 06:52:01 +00:00
|
|
|
private:
|
2010-02-21 06:30:04 +00:00
|
|
|
unsigned EmitMatcher(const MatcherNode *N, unsigned Indent,
|
|
|
|
formatted_raw_ostream &OS);
|
2010-02-16 07:21:10 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2010-02-17 00:31:50 +00:00
|
|
|
|
|
|
|
unsigned getComplexPat(const ComplexPattern &P) {
|
|
|
|
unsigned &Entry = ComplexPatternMap[&P];
|
|
|
|
if (Entry == 0) {
|
|
|
|
ComplexPatterns.push_back(&P);
|
|
|
|
Entry = ComplexPatterns.size();
|
|
|
|
}
|
|
|
|
return Entry-1;
|
|
|
|
}
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
|
|
|
|
unsigned getNodeXFormID(Record *Rec) {
|
|
|
|
unsigned &Entry = NodeXFormMap[Rec];
|
|
|
|
if (Entry == 0) {
|
|
|
|
NodeXForms.push_back(Rec);
|
|
|
|
Entry = NodeXForms.size();
|
|
|
|
}
|
|
|
|
return Entry-1;
|
|
|
|
}
|
|
|
|
|
2010-02-16 06:52:01 +00:00
|
|
|
};
|
|
|
|
} // end anonymous namespace.
|
|
|
|
|
2010-02-15 08:04:42 +00:00
|
|
|
/// EmitMatcherOpcodes - Emit bytes for the specified matcher and return
|
|
|
|
/// the number of bytes emitted.
|
2010-02-16 06:52:01 +00:00
|
|
|
unsigned MatcherTableEmitter::
|
2010-02-21 06:30:04 +00:00
|
|
|
EmitMatcher(const MatcherNode *N, unsigned Indent, formatted_raw_ostream &OS) {
|
2010-02-15 08:04:42 +00:00
|
|
|
OS.PadToColumn(Indent*2);
|
|
|
|
|
|
|
|
switch (N->getKind()) {
|
|
|
|
case MatcherNode::Push: assert(0 && "Should be handled by caller");
|
2010-02-18 22:03:03 +00:00
|
|
|
case MatcherNode::RecordNode:
|
|
|
|
OS << "OPC_RecordNode,";
|
2010-02-17 01:03:09 +00:00
|
|
|
OS.PadToColumn(CommentIndent) << "// "
|
|
|
|
<< cast<RecordMatcherNode>(N)->getWhatFor() << '\n';
|
2010-02-15 08:04:42 +00:00
|
|
|
return 1;
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
|
|
|
|
case MatcherNode::RecordMemRef:
|
|
|
|
OS << "OPC_RecordMemRef,\n";
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case MatcherNode::CaptureFlagInput:
|
|
|
|
OS << "OPC_CaptureFlagInput,\n";
|
|
|
|
return 1;
|
|
|
|
|
2010-02-15 08:04:42 +00:00
|
|
|
case MatcherNode::MoveChild:
|
|
|
|
OS << "OPC_MoveChild, "
|
|
|
|
<< cast<MoveChildMatcherNode>(N)->getChildNo() << ",\n";
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
case MatcherNode::MoveParent:
|
|
|
|
OS << "OPC_MoveParent,\n";
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case MatcherNode::CheckSame:
|
|
|
|
OS << "OPC_CheckSame, "
|
|
|
|
<< cast<CheckSameMatcherNode>(N)->getMatchNumber() << ",\n";
|
|
|
|
return 2;
|
|
|
|
|
2010-02-16 07:21:10 +00:00
|
|
|
case MatcherNode::CheckPatternPredicate: {
|
|
|
|
StringRef Pred = cast<CheckPatternPredicateMatcherNode>(N)->getPredicate();
|
|
|
|
OS << "OPC_CheckPatternPredicate, " << getPatternPredicate(Pred) << ',';
|
|
|
|
OS.PadToColumn(CommentIndent) << "// " << Pred << '\n';
|
2010-02-15 08:04:42 +00:00
|
|
|
return 2;
|
2010-02-16 07:21:10 +00:00
|
|
|
}
|
|
|
|
case MatcherNode::CheckPredicate: {
|
|
|
|
StringRef Pred = cast<CheckPredicateMatcherNode>(N)->getPredicateName();
|
|
|
|
OS << "OPC_CheckPredicate, " << getNodePredicate(Pred) << ',';
|
|
|
|
OS.PadToColumn(CommentIndent) << "// " << Pred << '\n';
|
2010-02-15 08:04:42 +00:00
|
|
|
return 2;
|
2010-02-16 07:21:10 +00:00
|
|
|
}
|
|
|
|
|
2010-02-15 08:04:42 +00:00
|
|
|
case MatcherNode::CheckOpcode:
|
|
|
|
OS << "OPC_CheckOpcode, "
|
|
|
|
<< cast<CheckOpcodeMatcherNode>(N)->getOpcodeName() << ",\n";
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
case MatcherNode::CheckType:
|
|
|
|
OS << "OPC_CheckType, "
|
|
|
|
<< getEnumName(cast<CheckTypeMatcherNode>(N)->getType()) << ",\n";
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
case MatcherNode::CheckInteger: {
|
|
|
|
int64_t Val = cast<CheckIntegerMatcherNode>(N)->getValue();
|
|
|
|
OS << "OPC_CheckInteger" << ClassifyInt(Val) << ", ";
|
|
|
|
return EmitInt(Val, OS)+1;
|
|
|
|
}
|
|
|
|
case MatcherNode::CheckCondCode:
|
|
|
|
OS << "OPC_CheckCondCode, ISD::"
|
|
|
|
<< cast<CheckCondCodeMatcherNode>(N)->getCondCodeName() << ",\n";
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
case MatcherNode::CheckValueType:
|
|
|
|
OS << "OPC_CheckValueType, MVT::"
|
|
|
|
<< cast<CheckValueTypeMatcherNode>(N)->getTypeName() << ",\n";
|
|
|
|
return 2;
|
|
|
|
|
2010-02-17 00:39:26 +00:00
|
|
|
case MatcherNode::CheckComplexPat: {
|
|
|
|
const ComplexPattern &Pattern =
|
|
|
|
cast<CheckComplexPatMatcherNode>(N)->getPattern();
|
|
|
|
OS << "OPC_CheckComplexPat, " << getComplexPat(Pattern) << ',';
|
2010-02-17 06:47:35 +00:00
|
|
|
OS.PadToColumn(CommentIndent) << "// " << Pattern.getSelectFunc();
|
|
|
|
OS << ": " << Pattern.getNumOperands() << " operands";
|
|
|
|
if (Pattern.hasProperty(SDNPHasChain))
|
|
|
|
OS << " + chain result and input";
|
|
|
|
OS << '\n';
|
2010-02-15 08:04:42 +00:00
|
|
|
return 2;
|
2010-02-17 00:39:26 +00:00
|
|
|
}
|
2010-02-15 08:04:42 +00:00
|
|
|
|
|
|
|
case MatcherNode::CheckAndImm: {
|
|
|
|
int64_t Val = cast<CheckAndImmMatcherNode>(N)->getValue();
|
|
|
|
OS << "OPC_CheckAndImm" << ClassifyInt(Val) << ", ";
|
|
|
|
return EmitInt(Val, OS)+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MatcherNode::CheckOrImm: {
|
|
|
|
int64_t Val = cast<CheckOrImmMatcherNode>(N)->getValue();
|
|
|
|
OS << "OPC_CheckOrImm" << ClassifyInt(Val) << ", ";
|
|
|
|
return EmitInt(Val, OS)+1;
|
|
|
|
}
|
2010-02-16 19:15:55 +00:00
|
|
|
case MatcherNode::CheckFoldableChainNode:
|
|
|
|
OS << "OPC_CheckFoldableChainNode,\n";
|
2010-02-16 06:10:58 +00:00
|
|
|
return 1;
|
2010-02-17 06:23:39 +00:00
|
|
|
case MatcherNode::CheckChainCompatible:
|
|
|
|
OS << "OPC_CheckChainCompatible, "
|
|
|
|
<< cast<CheckChainCompatibleMatcherNode>(N)->getPreviousOp() << ",\n";
|
|
|
|
return 2;
|
2010-02-18 22:03:03 +00:00
|
|
|
|
2010-02-19 07:49:56 +00:00
|
|
|
case MatcherNode::EmitInteger: {
|
|
|
|
int64_t Val = cast<EmitIntegerMatcherNode>(N)->getValue();
|
|
|
|
OS << "OPC_EmitInteger" << ClassifyInt(Val) << ", "
|
|
|
|
<< getEnumName(cast<EmitIntegerMatcherNode>(N)->getVT()) << ", ";
|
|
|
|
return EmitInt(Val, OS)+2;
|
|
|
|
}
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
case MatcherNode::EmitStringInteger: {
|
|
|
|
const std::string &Val = cast<EmitStringIntegerMatcherNode>(N)->getValue();
|
|
|
|
// These should always fit into one byte.
|
|
|
|
OS << "OPC_EmitInteger1, "
|
|
|
|
<< getEnumName(cast<EmitStringIntegerMatcherNode>(N)->getVT()) << ", "
|
|
|
|
<< Val << ",\n";
|
|
|
|
return 3;
|
|
|
|
}
|
2010-02-19 07:49:56 +00:00
|
|
|
|
2010-02-18 22:03:03 +00:00
|
|
|
case MatcherNode::EmitRegister:
|
2010-02-19 07:49:56 +00:00
|
|
|
OS << "OPC_EmitRegister, "
|
|
|
|
<< getEnumName(cast<EmitRegisterMatcherNode>(N)->getVT()) << ", ";
|
|
|
|
if (Record *R = cast<EmitRegisterMatcherNode>(N)->getReg())
|
|
|
|
OS << getQualifiedName(R) << ",\n";
|
|
|
|
else
|
|
|
|
OS << "0 /*zero_reg*/,\n";
|
|
|
|
return 3;
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
|
|
|
|
case MatcherNode::EmitConvertToTarget:
|
|
|
|
OS << "OPC_EmitConvertToTarget, "
|
|
|
|
<< cast<EmitConvertToTargetMatcherNode>(N)->getSlot() << ",\n";
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
case MatcherNode::EmitMergeInputChains: {
|
|
|
|
const EmitMergeInputChainsMatcherNode *MN =
|
|
|
|
cast<EmitMergeInputChainsMatcherNode>(N);
|
|
|
|
OS << "OPC_EmitMergeInputChains, " << MN->getNumNodes() << ", ";
|
|
|
|
for (unsigned i = 0, e = MN->getNumNodes(); i != e; ++i)
|
|
|
|
OS << MN->getNode(i) << ", ";
|
|
|
|
OS << '\n';
|
|
|
|
return 2+MN->getNumNodes();
|
|
|
|
}
|
|
|
|
case MatcherNode::EmitCopyToReg:
|
|
|
|
OS << "OPC_EmitCopyToReg, "
|
|
|
|
<< cast<EmitCopyToRegMatcherNode>(N)->getSrcSlot() << ", "
|
|
|
|
<< getQualifiedName(cast<EmitCopyToRegMatcherNode>(N)->getDestPhysReg())
|
|
|
|
<< ",\n";
|
|
|
|
return 3;
|
|
|
|
case MatcherNode::EmitNodeXForm: {
|
|
|
|
const EmitNodeXFormMatcherNode *XF = cast<EmitNodeXFormMatcherNode>(N);
|
|
|
|
OS << "OPC_EmitNodeXForm, " << getNodeXFormID(XF->getNodeXForm()) << ", "
|
|
|
|
<< XF->getSlot() << ',';
|
|
|
|
OS.PadToColumn(CommentIndent) << "// "<<XF->getNodeXForm()->getName()<<'\n';
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MatcherNode::EmitNode: {
|
|
|
|
const EmitNodeMatcherNode *EN = cast<EmitNodeMatcherNode>(N);
|
|
|
|
OS << "OPC_EmitNode, TARGET_OPCODE(" << EN->getOpcodeName() << "), 0";
|
|
|
|
|
|
|
|
if (EN->hasChain()) OS << "|OPFL_Chain";
|
|
|
|
if (EN->hasFlag()) OS << "|OPFL_Flag";
|
|
|
|
if (EN->hasMemRefs()) OS << "|OPFL_MemRefs";
|
|
|
|
if (EN->getNumFixedArityOperands() != -1)
|
|
|
|
OS << "|OPFL_Variadic" << EN->getNumFixedArityOperands();
|
|
|
|
OS << ",\n";
|
|
|
|
|
|
|
|
OS.PadToColumn(Indent*2+4) << EN->getNumVTs() << "/*#VTs*/, ";
|
|
|
|
for (unsigned i = 0, e = EN->getNumVTs(); i != e; ++i)
|
|
|
|
OS << getEnumName(EN->getVT(i)) << ", ";
|
|
|
|
|
|
|
|
OS << EN->getNumOperands() << "/*#Ops*/, ";
|
|
|
|
for (unsigned i = 0, e = EN->getNumOperands(); i != e; ++i)
|
|
|
|
OS << EN->getOperand(i) << ", ";
|
|
|
|
OS << '\n';
|
2010-02-21 06:44:29 +00:00
|
|
|
return 6+EN->getNumVTs()+EN->getNumOperands();
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
}
|
2010-02-21 06:03:07 +00:00
|
|
|
case MatcherNode::CompleteMatch: {
|
|
|
|
const CompleteMatchMatcherNode *CM = cast<CompleteMatchMatcherNode>(N);
|
|
|
|
OS << "OPC_CompleteMatch, " << CM->getNumResults() << ", ";
|
|
|
|
for (unsigned i = 0, e = CM->getNumResults(); i != e; ++i)
|
|
|
|
OS << CM->getResult(i) << ", ";
|
|
|
|
OS << '\n';
|
|
|
|
OS.PadToColumn(Indent*2) << "// Src: "
|
|
|
|
<< *CM->getPattern().getSrcPattern() << '\n';
|
|
|
|
OS.PadToColumn(Indent*2) << "// Dst: "
|
|
|
|
<< *CM->getPattern().getDstPattern() << '\n';
|
2010-02-21 06:30:04 +00:00
|
|
|
return 2+CM->getNumResults();
|
2010-02-15 08:04:42 +00:00
|
|
|
}
|
2010-02-21 06:03:07 +00:00
|
|
|
}
|
2010-02-15 08:04:42 +00:00
|
|
|
assert(0 && "Unreachable");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-18 02:53:41 +00:00
|
|
|
/// EmitMatcherList - Emit the bytes for the specified matcher subtree.
|
2010-02-16 06:52:01 +00:00
|
|
|
unsigned MatcherTableEmitter::
|
2010-02-21 07:16:41 +00:00
|
|
|
EmitMatcherList(const MatcherNode *N, unsigned Indent, unsigned CurrentIdx,
|
2010-02-21 06:30:04 +00:00
|
|
|
formatted_raw_ostream &OS) {
|
2010-02-15 08:04:42 +00:00
|
|
|
unsigned Size = 0;
|
2010-02-18 02:49:24 +00:00
|
|
|
while (N) {
|
2010-02-15 08:04:42 +00:00
|
|
|
// Push is a special case since it is binary.
|
|
|
|
if (const PushMatcherNode *PMN = dyn_cast<PushMatcherNode>(N)) {
|
|
|
|
// We need to encode the child and the offset of the failure code before
|
|
|
|
// emitting either of them. Handle this by buffering the output into a
|
|
|
|
// string while we get the size.
|
|
|
|
SmallString<128> TmpBuf;
|
2010-02-18 02:53:41 +00:00
|
|
|
unsigned NextSize;
|
2010-02-15 08:04:42 +00:00
|
|
|
{
|
|
|
|
raw_svector_ostream OS(TmpBuf);
|
|
|
|
formatted_raw_ostream FOS(OS);
|
2010-02-18 02:53:41 +00:00
|
|
|
NextSize = EmitMatcherList(cast<PushMatcherNode>(N)->getNext(),
|
2010-02-21 07:16:41 +00:00
|
|
|
Indent+1, CurrentIdx+2, FOS);
|
2010-02-15 08:04:42 +00:00
|
|
|
}
|
|
|
|
|
2010-02-18 02:53:41 +00:00
|
|
|
if (NextSize > 255) {
|
2010-02-15 08:04:42 +00:00
|
|
|
errs() <<
|
|
|
|
"Tblgen internal error: can't handle predicate this complex yet\n";
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
// FIXME: exit(1);
|
2010-02-15 08:04:42 +00:00
|
|
|
}
|
|
|
|
|
2010-02-21 07:16:41 +00:00
|
|
|
OS << "/*" << CurrentIdx << "*/";
|
2010-02-15 08:04:42 +00:00
|
|
|
OS.PadToColumn(Indent*2);
|
2010-02-18 02:53:41 +00:00
|
|
|
OS << "OPC_Push, " << NextSize << ",\n";
|
2010-02-15 08:04:42 +00:00
|
|
|
OS << TmpBuf.str();
|
|
|
|
|
2010-02-21 07:16:41 +00:00
|
|
|
Size += 2+NextSize;
|
|
|
|
CurrentIdx += 2+NextSize;
|
2010-02-15 08:04:42 +00:00
|
|
|
N = PMN->getFailure();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-02-21 07:16:41 +00:00
|
|
|
OS << "/*" << CurrentIdx << "*/";
|
|
|
|
unsigned MatcherSize = EmitMatcher(N, Indent, OS);
|
|
|
|
Size += MatcherSize;
|
|
|
|
CurrentIdx += MatcherSize;
|
2010-02-15 08:04:42 +00:00
|
|
|
|
2010-02-18 02:53:41 +00:00
|
|
|
// If there are other nodes in this list, iterate to them, otherwise we're
|
2010-02-15 08:04:42 +00:00
|
|
|
// done.
|
2010-02-18 02:53:41 +00:00
|
|
|
N = N->getNext();
|
2010-02-15 08:04:42 +00:00
|
|
|
}
|
2010-02-18 02:49:24 +00:00
|
|
|
return Size;
|
2010-02-15 08:04:42 +00:00
|
|
|
}
|
|
|
|
|
2010-02-21 06:30:04 +00:00
|
|
|
void MatcherTableEmitter::EmitPredicateFunctions(formatted_raw_ostream &OS) {
|
2010-02-18 06:47:49 +00:00
|
|
|
// FIXME: Don't build off the DAGISelEmitter's predicates, emit them directly
|
|
|
|
// here into the case stmts.
|
|
|
|
|
2010-02-17 00:31:50 +00:00
|
|
|
// Emit pattern predicates.
|
2010-02-16 07:21:10 +00:00
|
|
|
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";
|
|
|
|
|
2010-02-17 00:31:50 +00:00
|
|
|
// Emit Node predicates.
|
2010-02-16 07:21:10 +00:00
|
|
|
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";
|
2010-02-17 00:31:50 +00:00
|
|
|
|
|
|
|
// Emit CompletePattern matchers.
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
// FIXME: This should be const.
|
2010-02-17 00:31:50 +00:00
|
|
|
OS << "bool CheckComplexPattern(SDNode *Root, SDValue N,\n";
|
|
|
|
OS << " unsigned PatternNo, SmallVectorImpl<SDValue> &Result) {\n";
|
|
|
|
OS << " switch (PatternNo) {\n";
|
|
|
|
OS << " default: assert(0 && \"Invalid pattern # in table?\");\n";
|
|
|
|
for (unsigned i = 0, e = ComplexPatterns.size(); i != e; ++i) {
|
|
|
|
const ComplexPattern &P = *ComplexPatterns[i];
|
|
|
|
unsigned NumOps = P.getNumOperands();
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
|
2010-02-17 00:31:50 +00:00
|
|
|
if (P.hasProperty(SDNPHasChain))
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
++NumOps; // Get the chained node too.
|
|
|
|
|
2010-02-17 00:31:50 +00:00
|
|
|
OS << " case " << i << ":\n";
|
|
|
|
OS << " Result.resize(Result.size()+" << NumOps << ");\n";
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
OS << " return " << P.getSelectFunc();
|
|
|
|
|
|
|
|
// FIXME: Temporary hack until old isel dies.
|
|
|
|
if (P.hasProperty(SDNPHasChain))
|
|
|
|
OS << "XXX";
|
|
|
|
|
|
|
|
OS << "(Root, N";
|
2010-02-17 00:31:50 +00:00
|
|
|
for (unsigned i = 0; i != NumOps; ++i)
|
|
|
|
OS << ", Result[Result.size()-" << (NumOps-i) << ']';
|
|
|
|
OS << ");\n";
|
|
|
|
}
|
|
|
|
OS << " }\n";
|
|
|
|
OS << "}\n\n";
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
|
|
|
|
// Emit SDNodeXForm handlers.
|
|
|
|
// FIXME: This should be const.
|
|
|
|
OS << "SDValue RunSDNodeXForm(SDValue V, unsigned XFormNo) {\n";
|
|
|
|
OS << " switch (XFormNo) {\n";
|
|
|
|
OS << " default: assert(0 && \"Invalid xform # in table?\");\n";
|
|
|
|
|
|
|
|
// FIXME: The node xform could take SDValue's instead of SDNode*'s.
|
|
|
|
for (unsigned i = 0, e = NodeXForms.size(); i != e; ++i)
|
|
|
|
OS << " case " << i << ": return Transform_" << NodeXForms[i]->getName()
|
|
|
|
<< "(V.getNode());\n";
|
|
|
|
OS << " }\n";
|
|
|
|
OS << "}\n\n";
|
2010-02-16 07:21:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-15 08:04:42 +00:00
|
|
|
void llvm::EmitMatcherTable(const MatcherNode *Matcher, raw_ostream &O) {
|
|
|
|
formatted_raw_ostream OS(O);
|
|
|
|
|
|
|
|
OS << "// The main instruction selector code.\n";
|
|
|
|
OS << "SDNode *SelectCode2(SDNode *N) {\n";
|
|
|
|
|
2010-02-21 06:30:04 +00:00
|
|
|
MatcherTableEmitter MatcherEmitter;
|
2010-02-16 06:52:01 +00:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
OS << " // Opcodes are emitted as 2 bytes, TARGET_OPCODE handles this.\n";
|
|
|
|
OS << " #define TARGET_OPCODE(X) X & 255, unsigned(X) >> 8\n";
|
2010-02-15 08:04:42 +00:00
|
|
|
OS << " static const unsigned char MatcherTable[] = {\n";
|
2010-02-21 07:16:41 +00:00
|
|
|
unsigned TotalSize = MatcherEmitter.EmitMatcherList(Matcher, 5, 0, OS);
|
2010-02-15 08:04:42 +00:00
|
|
|
OS << " 0\n }; // Total Array size is " << (TotalSize+1) << " bytes\n\n";
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 03:22:59 +00:00
|
|
|
OS << " #undef TARGET_OPCODE\n";
|
2010-02-16 06:52:01 +00:00
|
|
|
OS << " return SelectCodeCommon(N, MatcherTable,sizeof(MatcherTable));\n}\n";
|
2010-02-16 07:21:10 +00:00
|
|
|
OS << "\n";
|
|
|
|
|
|
|
|
// Next up, emit the function for node and pattern predicates:
|
2010-02-21 06:30:04 +00:00
|
|
|
MatcherEmitter.EmitPredicateFunctions(OS);
|
2010-02-15 08:04:42 +00:00
|
|
|
}
|