summaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2020-07-26 19:36:28 +0000
committerDimitry Andric <dim@FreeBSD.org>2020-07-26 19:36:28 +0000
commitcfca06d7963fa0909f90483b42a6d7d194d01e08 (patch)
tree209fb2a2d68f8f277793fc8df46c753d31bc853b /llvm/utils/TableGen/CodeGenDAGPatterns.cpp
parent706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff)
Notes
Diffstat (limited to 'llvm/utils/TableGen/CodeGenDAGPatterns.cpp')
-rw-r--r--llvm/utils/TableGen/CodeGenDAGPatterns.cpp45
1 files changed, 30 insertions, 15 deletions
diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
index 7e0ba98da94aa..6fdc116721f33 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -277,7 +277,7 @@ bool TypeSetByHwMode::intersect(SetType &Out, const SetType &In) {
// Compute the intersection of scalars separately to account for only
// one set containing iPTR.
- // The itersection of iPTR with a set of integer scalar types that does not
+ // The intersection of iPTR with a set of integer scalar types that does not
// include iPTR will result in the most specific scalar type:
// - iPTR is more specific than any set with two elements or more
// - iPTR is less specific than any single integer scalar type.
@@ -999,9 +999,9 @@ std::string TreePredicateFn::getPredCode() const {
int64_t MinAlign = getMinAlignment();
if (MinAlign > 0) {
- Code += "if (cast<MemSDNode>(N)->getAlignment() < ";
+ Code += "if (cast<MemSDNode>(N)->getAlign() < Align(";
Code += utostr(MinAlign);
- Code += ")\nreturn false;\n";
+ Code += "))\nreturn false;\n";
}
Record *MemoryVT = getMemoryVT();
@@ -1091,7 +1091,8 @@ std::string TreePredicateFn::getPredCode() const {
.str();
}
- std::string PredicateCode = PatFragRec->getRecord()->getValueAsString("PredicateCode");
+ std::string PredicateCode =
+ std::string(PatFragRec->getRecord()->getValueAsString("PredicateCode"));
Code += PredicateCode;
@@ -1106,7 +1107,8 @@ bool TreePredicateFn::hasImmCode() const {
}
std::string TreePredicateFn::getImmCode() const {
- return PatFragRec->getRecord()->getValueAsString("ImmediateCode");
+ return std::string(
+ PatFragRec->getRecord()->getValueAsString("ImmediateCode"));
}
bool TreePredicateFn::immCodeUsesAPInt() const {
@@ -1223,7 +1225,8 @@ bool TreePredicateFn::hasGISelPredicateCode() const {
.empty();
}
std::string TreePredicateFn::getGISelPredicateCode() const {
- return PatFragRec->getRecord()->getValueAsString("GISelPredicateCode");
+ return std::string(
+ PatFragRec->getRecord()->getValueAsString("GISelPredicateCode"));
}
StringRef TreePredicateFn::getImmType() const {
@@ -2517,6 +2520,9 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
}
}
+ unsigned NumResults = Inst.getNumResults();
+ unsigned NumFixedOperands = InstInfo.Operands.size();
+
// If one or more operands with a default value appear at the end of the
// formal operand list for an instruction, we allow them to be overridden
// by optional operands provided in the pattern.
@@ -2525,14 +2531,15 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
// operand A with a default, then we don't allow A to be overridden,
// because there would be no way to specify whether the next operand in
// the pattern was intended to override A or skip it.
- unsigned NonOverridableOperands = Inst.getNumOperands();
- while (NonOverridableOperands > 0 &&
- CDP.operandHasDefault(Inst.getOperand(NonOverridableOperands-1)))
+ unsigned NonOverridableOperands = NumFixedOperands;
+ while (NonOverridableOperands > NumResults &&
+ CDP.operandHasDefault(InstInfo.Operands[NonOverridableOperands-1].Rec))
--NonOverridableOperands;
unsigned ChildNo = 0;
- for (unsigned i = 0, e = Inst.getNumOperands(); i != e; ++i) {
- Record *OperandNode = Inst.getOperand(i);
+ assert(NumResults <= NumFixedOperands);
+ for (unsigned i = NumResults, e = NumFixedOperands; i != e; ++i) {
+ Record *OperandNode = InstInfo.Operands[i].Rec;
// If the operand has a default value, do we use it? We must use the
// default if we've run out of children of the pattern DAG to consume,
@@ -2741,7 +2748,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(Init *TheInit,
if (R->getName() == "node" && !OpName.empty()) {
if (OpName.empty())
error("'node' argument requires a name to match with operand list");
- Args.push_back(OpName);
+ Args.push_back(std::string(OpName));
}
Res->setName(OpName);
@@ -2753,7 +2760,7 @@ TreePatternNodePtr TreePattern::ParseTreePattern(Init *TheInit,
if (OpName.empty())
error("'?' argument requires a name to match with operand list");
TreePatternNodePtr Res = std::make_shared<TreePatternNode>(TheInit, 1);
- Args.push_back(OpName);
+ Args.push_back(std::string(OpName));
Res->setName(OpName);
return Res;
}
@@ -2915,8 +2922,15 @@ static bool SimplifyTree(TreePatternNodePtr &N) {
// If we have a bitconvert with a resolved type and if the source and
// destination types are the same, then the bitconvert is useless, remove it.
+ //
+ // We make an exception if the types are completely empty. This can come up
+ // when the pattern being simplified is in the Fragments list of a PatFrags,
+ // so that the operand is just an untyped "node". In that situation we leave
+ // bitconverts unsimplified, and simplify them later once the fragment is
+ // expanded into its true context.
if (N->getOperator()->getName() == "bitconvert" &&
N->getExtType(0).isValueTypeByHwMode(false) &&
+ !N->getExtType(0).empty() &&
N->getExtType(0) == N->getChild(0)->getExtType(0) &&
N->getName().empty()) {
N = N->getChildShared(0);
@@ -3105,7 +3119,8 @@ void CodeGenDAGPatterns::ParseNodeTransforms() {
Record *XFormNode = Xforms.back();
Record *SDNode = XFormNode->getValueAsDef("Opcode");
StringRef Code = XFormNode->getValueAsString("XFormFunction");
- SDNodeXForms.insert(std::make_pair(XFormNode, NodeXForm(SDNode, Code)));
+ SDNodeXForms.insert(
+ std::make_pair(XFormNode, NodeXForm(SDNode, std::string(Code))));
Xforms.pop_back();
}
@@ -3173,7 +3188,7 @@ void CodeGenDAGPatterns::ParsePatternFragments(bool OutFrags) {
P->error("'" + ArgNameStr +
"' does not occur in pattern or was multiply specified!");
OperandsSet.erase(ArgNameStr);
- Args.push_back(ArgNameStr);
+ Args.push_back(std::string(ArgNameStr));
}
if (!OperandsSet.empty())