completely eliminate TreePattern::PatternType

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23335 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2005-09-13 21:20:49 +00:00
parent 7b738342f0
commit ee9f0c3c2e
2 changed files with 42 additions and 80 deletions

View File

@ -329,66 +329,15 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP) {
// TreePattern implementation
//
TreePattern::TreePattern(PatternType pty, Record *TheRec,
const std::vector<DagInit *> &RawPat,
DAGISelEmitter &ise)
: PTy(pty), TheRecord(TheRec), ISE(ise) {
TreePattern::TreePattern(Record *TheRec, const std::vector<DagInit *> &RawPat,
DAGISelEmitter &ise) : TheRecord(TheRec), ISE(ise) {
for (unsigned i = 0, e = RawPat.size(); i != e; ++i)
Trees.push_back(ParseTreePattern(RawPat[i]));
// Sanity checks and cleanup.
switch (PTy) {
case PatFrag: {
assert(Trees.size() == 1 && "How can we have more than one pattern here?");
// Validate arguments list, convert it to map, to discard duplicates.
std::set<std::string> OperandsMap(Args.begin(), Args.end());
if (OperandsMap.count(""))
error("Cannot have unnamed 'node' values in pattern fragment!");
// Parse the operands list.
DagInit *OpsList = TheRec->getValueAsDag("Operands");
if (OpsList->getNodeType()->getName() != "ops")
error("Operands list should start with '(ops ... '!");
// Copy over the arguments.
Args.clear();
for (unsigned i = 0, e = OpsList->getNumArgs(); i != e; ++i) {
if (!dynamic_cast<DefInit*>(OpsList->getArg(i)) ||
static_cast<DefInit*>(OpsList->getArg(i))->
getDef()->getName() != "node")
error("Operands list should all be 'node' values.");
if (OpsList->getArgName(i).empty())
error("Operands list should have names for each operand!");
if (!OperandsMap.count(OpsList->getArgName(i)))
error("'" + OpsList->getArgName(i) +
"' does not occur in pattern or was multiply specified!");
OperandsMap.erase(OpsList->getArgName(i));
Args.push_back(OpsList->getArgName(i));
}
if (!OperandsMap.empty())
error("Operands list does not contain an entry for operand '" +
*OperandsMap.begin() + "'!");
break;
}
default:
if (!Args.empty())
error("Only pattern fragments can have operands (use 'node' values)!");
break;
}
}
void TreePattern::error(const std::string &Msg) const {
std::string M = "In ";
switch (PTy) {
case PatFrag: M += "patfrag "; break;
case Instruction: M += "instruction "; break;
}
throw M + TheRecord->getName() + ": " + Msg;
throw "In " + TheRecord->getName() + ": " + Msg;
}
/// getIntrinsicType - Check to see if the specified record has an intrinsic
@ -507,11 +456,6 @@ bool TreePattern::InferAllTypes() {
}
void TreePattern::print(std::ostream &OS) const {
switch (getPatternType()) {
case TreePattern::PatFrag: OS << "PatFrag pattern "; break;
case TreePattern::Instruction: OS << "Inst pattern "; break;
}
OS << getRecord()->getName();
if (!Args.empty()) {
OS << "(" << Args[0];
@ -565,9 +509,40 @@ void DAGISelEmitter::ParseAndResolvePatternFragments(std::ostream &OS) {
for (unsigned i = 0, e = Fragments.size(); i != e; ++i) {
std::vector<DagInit*> Trees;
Trees.push_back(Fragments[i]->getValueAsDag("Fragment"));
TreePattern *P = new TreePattern(TreePattern::PatFrag, Fragments[i],
Trees, *this);
TreePattern *P = new TreePattern(Fragments[i], Trees, *this);
PatternFragments[Fragments[i]] = P;
// Validate the argument list, converting it to map, to discard duplicates.
std::vector<std::string> &Args = P->getArgList();
std::set<std::string> OperandsMap(Args.begin(), Args.end());
if (OperandsMap.count(""))
P->error("Cannot have unnamed 'node' values in pattern fragment!");
// Parse the operands list.
DagInit *OpsList = Fragments[i]->getValueAsDag("Operands");
if (OpsList->getNodeType()->getName() != "ops")
P->error("Operands list should start with '(ops ... '!");
// Copy over the arguments.
Args.clear();
for (unsigned j = 0, e = OpsList->getNumArgs(); j != e; ++j) {
if (!dynamic_cast<DefInit*>(OpsList->getArg(j)) ||
static_cast<DefInit*>(OpsList->getArg(j))->
getDef()->getName() != "node")
P->error("Operands list should all be 'node' values.");
if (OpsList->getArgName(j).empty())
P->error("Operands list should have names for each operand!");
if (!OperandsMap.count(OpsList->getArgName(j)))
P->error("'" + OpsList->getArgName(j) +
"' does not occur in pattern or was multiply specified!");
OperandsMap.erase(OpsList->getArgName(j));
Args.push_back(OpsList->getArgName(j));
}
if (!OperandsMap.empty())
P->error("Operands list does not contain an entry for operand '" +
*OperandsMap.begin() + "'!");
// If there is a code init for this fragment, emit the predicate code and
// keep track of the fact that this fragment uses it.
@ -596,7 +571,7 @@ void DAGISelEmitter::ParseAndResolvePatternFragments(std::ostream &OS) {
E = PatternFragments.end(); I != E; ++I) {
TreePattern *ThePat = I->second;
ThePat->InlinePatternFragments();
// Infer as many types as possible. Don't worry about it if we don't infer
// all of them, some may depend on the inputs of the pattern.
try {
@ -631,8 +606,7 @@ void DAGISelEmitter::ParseAndResolveInstructions() {
Trees.push_back((DagInit*)LI->getElement(j));
// Parse the instruction.
TreePattern *I = new TreePattern(TreePattern::Instruction, Instrs[i],
Trees, *this);
TreePattern *I = new TreePattern(Instrs[i], Trees, *this);
// Inline pattern fragments into it.
I->InlinePatternFragments();

View File

@ -190,19 +190,10 @@ namespace llvm {
};
/// TreePattern - Represent a pattern of one form or another. Currently, two
/// types of patterns are possible: Instructions and PatFrags.
/// TreePattern - Represent a pattern, used for instructions, pattern
/// fragments, etc.
///
class TreePattern {
public:
enum PatternType {
PatFrag, Instruction
};
private:
/// PTy - The type of pattern this is.
///
PatternType PTy;
/// Trees - The list of pattern trees which corresponds to this pattern.
/// Note that PatFrag's only have a single tree.
///
@ -223,13 +214,9 @@ namespace llvm {
/// TreePattern constructor - Parse the specified DagInits into the
/// current record.
TreePattern(PatternType pty, Record *TheRec,
TreePattern(Record *TheRec,
const std::vector<DagInit *> &RawPat, DAGISelEmitter &ise);
/// getPatternType - Return what flavor of Record this pattern originated from
///
PatternType getPatternType() const { return PTy; }
/// getTrees - Return the tree patterns which corresponds to this pattern.
///
const std::vector<TreePatternNode*> &getTrees() const { return Trees; }
@ -250,6 +237,7 @@ namespace llvm {
assert(i < Args.size() && "Argument reference out of range!");
return Args[i];
}
std::vector<std::string> &getArgList() { return Args; }
DAGISelEmitter &getDAGISelEmitter() const { return ISE; }