aboutsummaryrefslogtreecommitdiffstats
path: root/utils/TableGen/CodeGenDAGPatterns.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/TableGen/CodeGenDAGPatterns.cpp')
-rw-r--r--utils/TableGen/CodeGenDAGPatterns.cpp106
1 files changed, 68 insertions, 38 deletions
diff --git a/utils/TableGen/CodeGenDAGPatterns.cpp b/utils/TableGen/CodeGenDAGPatterns.cpp
index 2602bbc..a750aa9 100644
--- a/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -771,7 +771,7 @@ static unsigned getPatternSize(const TreePatternNode *P,
/// Compute the complexity metric for the input pattern. This roughly
/// corresponds to the number of nodes that are covered.
-unsigned PatternToMatch::
+int PatternToMatch::
getPatternComplexity(const CodeGenDAGPatterns &CGP) const {
return getPatternSize(getSrcPattern(), CGP) + getAddedComplexity();
}
@@ -1387,7 +1387,7 @@ static EEVT::TypeSet getImplicitType(Record *R, unsigned ResNo,
if (R->isSubClassOf("SubRegIndex")) {
assert(ResNo == 0 && "SubRegisterIndices only produce one result!");
- return EEVT::TypeSet();
+ return EEVT::TypeSet(MVT::i32, TP);
}
if (R->isSubClassOf("ValueType")) {
@@ -1529,7 +1529,16 @@ TreePatternNode::isCommutativeIntrinsic(const CodeGenDAGPatterns &CDP) const {
return false;
}
+static bool isOperandClass(const TreePatternNode *N, StringRef Class) {
+ if (!N->isLeaf())
+ return N->getOperator()->isSubClassOf(Class);
+ DefInit *DI = dyn_cast<DefInit>(N->getLeafValue());
+ if (DI && DI->getDef()->isSubClassOf(Class))
+ return true;
+
+ return false;
+}
/// ApplyTypeConstraints - Apply all of the type constraints relevant to
/// this node and its children in the tree. This returns true if it makes a
/// change, false otherwise. If a type contradiction is found, flag an error.
@@ -1689,6 +1698,34 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
assert(getChild(0)->getNumTypes() == 1 && "FIXME: Unhandled");
MadeChange |= UpdateNodeType(0, getChild(0)->getExtType(0), TP);
MadeChange |= getChild(0)->UpdateNodeType(0, getExtType(0), TP);
+ } else if (getOperator()->getName() == "REG_SEQUENCE") {
+ // We need to do extra, custom typechecking for REG_SEQUENCE since it is
+ // variadic.
+
+ unsigned NChild = getNumChildren();
+ if (NChild < 3) {
+ TP.error("REG_SEQUENCE requires at least 3 operands!");
+ return false;
+ }
+
+ if (NChild % 2 == 0) {
+ TP.error("REG_SEQUENCE requires an odd number of operands!");
+ return false;
+ }
+
+ if (!isOperandClass(getChild(0), "RegisterClass")) {
+ TP.error("REG_SEQUENCE requires a RegisterClass for first operand!");
+ return false;
+ }
+
+ for (unsigned I = 1; I < NChild; I += 2) {
+ TreePatternNode *SubIdxChild = getChild(I + 1);
+ if (!isOperandClass(SubIdxChild, "SubRegIndex")) {
+ TP.error("REG_SEQUENCE requires a SubRegIndex for operand " +
+ itostr(I + 1) + "!");
+ return false;
+ }
+ }
}
unsigned ChildNo = 0;
@@ -1749,7 +1786,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
MadeChange |= Child->UpdateNodeTypeFromInst(ChildResNo, OperandNode, TP);
}
- if (ChildNo != getNumChildren()) {
+ if (!InstInfo.Operands.isVariadic && ChildNo != getNumChildren()) {
TP.error("Instruction '" + getOperator()->getName() +
"' was provided too many operands!");
return false;
@@ -1871,7 +1908,7 @@ TreePattern::TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
Trees.push_back(Pat);
}
-void TreePattern::error(const std::string &Msg) {
+void TreePattern::error(const Twine &Msg) {
if (HasError)
return;
dump();
@@ -2226,13 +2263,6 @@ CodeGenDAGPatterns::CodeGenDAGPatterns(RecordKeeper &R) :
VerifyInstructionFlags();
}
-CodeGenDAGPatterns::~CodeGenDAGPatterns() {
- for (pf_iterator I = PatternFragments.begin(),
- E = PatternFragments.end(); I != E; ++I)
- delete I->second;
-}
-
-
Record *CodeGenDAGPatterns::getSDNodeNamed(const std::string &Name) const {
Record *N = Records.getDef(Name);
if (!N || !N->isSubClassOf("SDNode")) {
@@ -2294,9 +2324,9 @@ void CodeGenDAGPatterns::ParsePatternFragments(bool OutFrags) {
DagInit *Tree = Fragments[i]->getValueAsDag("Fragment");
TreePattern *P =
- new TreePattern(Fragments[i], Tree,
- !Fragments[i]->isSubClassOf("OutPatFrag"), *this);
- PatternFragments[Fragments[i]] = P;
+ (PatternFragments[Fragments[i]] = llvm::make_unique<TreePattern>(
+ Fragments[i], Tree, !Fragments[i]->isSubClassOf("OutPatFrag"),
+ *this)).get();
// Validate the argument list, converting it to set, to discard duplicates.
std::vector<std::string> &Args = P->getArgList();
@@ -2354,16 +2384,16 @@ void CodeGenDAGPatterns::ParsePatternFragments(bool OutFrags) {
if (OutFrags != Fragments[i]->isSubClassOf("OutPatFrag"))
continue;
- TreePattern *ThePat = PatternFragments[Fragments[i]];
- ThePat->InlinePatternFragments();
+ TreePattern &ThePat = *PatternFragments[Fragments[i]];
+ 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.
- ThePat->InferAllTypes();
- ThePat->resetError();
+ ThePat.InferAllTypes();
+ ThePat.resetError();
// If debugging, print out the pattern fragment result.
- DEBUG(ThePat->dump());
+ DEBUG(ThePat.dump());
}
}
@@ -3274,14 +3304,14 @@ void CodeGenDAGPatterns::ParsePatterns() {
if (LI->getSize() == 0) continue; // no pattern.
// Parse the instruction.
- TreePattern *Result = new TreePattern(CurPattern, LI, false, *this);
+ TreePattern Result(CurPattern, LI, false, *this);
// Inline pattern fragments into it.
- Result->InlinePatternFragments();
+ Result.InlinePatternFragments();
- if (Result->getNumTrees() != 1)
- Result->error("Cannot handle instructions producing instructions "
- "with temporaries yet!");
+ if (Result.getNumTrees() != 1)
+ Result.error("Cannot handle instructions producing instructions "
+ "with temporaries yet!");
bool IterateInference;
bool InferredAllPatternTypes, InferredAllResultTypes;
@@ -3294,7 +3324,7 @@ void CodeGenDAGPatterns::ParsePatterns() {
// Infer as many types as possible. If we cannot infer all of them, we
// can never do anything with this pattern: report it to the user.
InferredAllResultTypes =
- Result->InferAllTypes(&Pattern->getNamedNodesMap());
+ Result.InferAllTypes(&Pattern->getNamedNodesMap());
IterateInference = false;
@@ -3302,13 +3332,13 @@ void CodeGenDAGPatterns::ParsePatterns() {
// resolve cases where the input type is known to be a pointer type (which
// is considered resolved), but the result knows it needs to be 32- or
// 64-bits. Infer the other way for good measure.
- for (unsigned i = 0, e = std::min(Result->getTree(0)->getNumTypes(),
+ for (unsigned i = 0, e = std::min(Result.getTree(0)->getNumTypes(),
Pattern->getTree(0)->getNumTypes());
i != e; ++i) {
- IterateInference = Pattern->getTree(0)->
- UpdateNodeType(i, Result->getTree(0)->getExtType(i), *Result);
- IterateInference |= Result->getTree(0)->
- UpdateNodeType(i, Pattern->getTree(0)->getExtType(i), *Result);
+ IterateInference = Pattern->getTree(0)->UpdateNodeType(
+ i, Result.getTree(0)->getExtType(i), Result);
+ IterateInference |= Result.getTree(0)->UpdateNodeType(
+ i, Pattern->getTree(0)->getExtType(i), Result);
}
// If our iteration has converged and the input pattern's types are fully
@@ -3322,8 +3352,8 @@ void CodeGenDAGPatterns::ParsePatterns() {
// arbitrary types to the result pattern's nodes.
if (!IterateInference && InferredAllPatternTypes &&
!InferredAllResultTypes)
- IterateInference = ForceArbitraryInstResultType(Result->getTree(0),
- *Result);
+ IterateInference =
+ ForceArbitraryInstResultType(Result.getTree(0), Result);
} while (IterateInference);
// Verify that we inferred enough types that we can do something with the
@@ -3332,7 +3362,7 @@ void CodeGenDAGPatterns::ParsePatterns() {
Pattern->error("Could not infer all types in pattern!");
if (!InferredAllResultTypes) {
Pattern->dump();
- Result->error("Could not infer all types in pattern result!");
+ Result.error("Could not infer all types in pattern result!");
}
// Validate that the input pattern is correct.
@@ -3345,7 +3375,7 @@ void CodeGenDAGPatterns::ParsePatterns() {
InstImpResults);
// Promote the xform function to be an explicit node if set.
- TreePatternNode *DstPattern = Result->getOnlyTree();
+ TreePatternNode *DstPattern = Result.getOnlyTree();
std::vector<TreePatternNode*> ResultNodeOperands;
for (unsigned ii = 0, ee = DstPattern->getNumChildren(); ii != ee; ++ii) {
TreePatternNode *OpNode = DstPattern->getChild(ii);
@@ -3357,16 +3387,16 @@ void CodeGenDAGPatterns::ParsePatterns() {
}
ResultNodeOperands.push_back(OpNode);
}
- DstPattern = Result->getOnlyTree();
+ DstPattern = Result.getOnlyTree();
if (!DstPattern->isLeaf())
DstPattern = new TreePatternNode(DstPattern->getOperator(),
ResultNodeOperands,
DstPattern->getNumTypes());
- for (unsigned i = 0, e = Result->getOnlyTree()->getNumTypes(); i != e; ++i)
- DstPattern->setType(i, Result->getOnlyTree()->getExtType(i));
+ for (unsigned i = 0, e = Result.getOnlyTree()->getNumTypes(); i != e; ++i)
+ DstPattern->setType(i, Result.getOnlyTree()->getExtType(i));
- TreePattern Temp(Result->getRecord(), DstPattern, false, *this);
+ TreePattern Temp(Result.getRecord(), DstPattern, false, *this);
Temp.InferAllTypes();