2019-05-15 06:03:48 +08:00
|
|
|
//===- Pattern.cpp - Pattern wrapper class --------------------------------===//
|
2019-01-29 06:04:40 +08:00
|
|
|
//
|
|
|
|
// Copyright 2019 The MLIR Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
// =============================================================================
|
|
|
|
//
|
|
|
|
// Pattern wrapper class to simplify using TableGen Record defining a MLIR
|
|
|
|
// Pattern.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "mlir/TableGen/Pattern.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2019-04-09 06:14:59 +08:00
|
|
|
#include "llvm/Support/FormatVariadic.h"
|
[TableGen] Consolidate constraint related concepts
Previously we have multiple mechanisms to specify op definition and match constraints:
TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants
are not added because there are so many distinct cases we need to model; essentially,
they are all carrying a predicate. It's just an artifact of implementation.
It's quite confusing for users to grasp these variants and choose among them. Instead,
as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each
dialect has the flexibility to define its own aliases if wanted.
This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now
TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive
from TypeConstraint and AttrConstraint, respectively.
Comments are revised and examples are added to make it clear how to use constraints.
PiperOrigin-RevId: 240125076
2019-03-25 21:09:26 +08:00
|
|
|
#include "llvm/TableGen/Error.h"
|
2019-01-29 06:04:40 +08:00
|
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
using llvm::formatv;
|
2019-01-29 06:04:40 +08:00
|
|
|
using mlir::tblgen::Operator;
|
|
|
|
|
2019-02-02 07:40:22 +08:00
|
|
|
bool tblgen::DagLeaf::isUnspecified() const {
|
2019-04-01 23:58:53 +08:00
|
|
|
return dyn_cast_or_null<llvm::UnsetInit>(def);
|
2019-02-02 07:40:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool tblgen::DagLeaf::isOperandMatcher() const {
|
|
|
|
// Operand matchers specify a type constraint.
|
2019-04-01 23:58:53 +08:00
|
|
|
return isSubClassOf("TypeConstraint");
|
2019-02-02 07:40:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool tblgen::DagLeaf::isAttrMatcher() const {
|
2019-03-13 04:55:50 +08:00
|
|
|
// Attribute matchers specify an attribute constraint.
|
2019-04-01 23:58:53 +08:00
|
|
|
return isSubClassOf("AttrConstraint");
|
2019-02-02 07:40:22 +08:00
|
|
|
}
|
|
|
|
|
2019-04-23 05:13:45 +08:00
|
|
|
bool tblgen::DagLeaf::isNativeCodeCall() const {
|
|
|
|
return isSubClassOf("NativeCodeCall");
|
2019-02-02 07:40:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool tblgen::DagLeaf::isConstantAttr() const {
|
2019-04-01 23:58:53 +08:00
|
|
|
return isSubClassOf("ConstantAttr");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tblgen::DagLeaf::isEnumAttrCase() const {
|
2019-07-01 20:26:14 +08:00
|
|
|
return isSubClassOf("EnumAttrCaseInfo");
|
2019-02-02 07:40:22 +08:00
|
|
|
}
|
|
|
|
|
[TableGen] Consolidate constraint related concepts
Previously we have multiple mechanisms to specify op definition and match constraints:
TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants
are not added because there are so many distinct cases we need to model; essentially,
they are all carrying a predicate. It's just an artifact of implementation.
It's quite confusing for users to grasp these variants and choose among them. Instead,
as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each
dialect has the flexibility to define its own aliases if wanted.
This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now
TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive
from TypeConstraint and AttrConstraint, respectively.
Comments are revised and examples are added to make it clear how to use constraints.
PiperOrigin-RevId: 240125076
2019-03-25 21:09:26 +08:00
|
|
|
tblgen::Constraint tblgen::DagLeaf::getAsConstraint() const {
|
|
|
|
assert((isOperandMatcher() || isAttrMatcher()) &&
|
|
|
|
"the DAG leaf must be operand or attribute");
|
|
|
|
return Constraint(cast<llvm::DefInit>(def)->getDef());
|
2019-02-02 07:40:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tblgen::ConstantAttr tblgen::DagLeaf::getAsConstantAttr() const {
|
|
|
|
assert(isConstantAttr() && "the DAG leaf must be constant attribute");
|
|
|
|
return ConstantAttr(cast<llvm::DefInit>(def));
|
|
|
|
}
|
|
|
|
|
2019-04-01 23:58:53 +08:00
|
|
|
tblgen::EnumAttrCase tblgen::DagLeaf::getAsEnumAttrCase() const {
|
|
|
|
assert(isEnumAttrCase() && "the DAG leaf must be an enum attribute case");
|
|
|
|
return EnumAttrCase(cast<llvm::DefInit>(def));
|
|
|
|
}
|
|
|
|
|
2019-02-02 07:40:22 +08:00
|
|
|
std::string tblgen::DagLeaf::getConditionTemplate() const {
|
[TableGen] Consolidate constraint related concepts
Previously we have multiple mechanisms to specify op definition and match constraints:
TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants
are not added because there are so many distinct cases we need to model; essentially,
they are all carrying a predicate. It's just an artifact of implementation.
It's quite confusing for users to grasp these variants and choose among them. Instead,
as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each
dialect has the flexibility to define its own aliases if wanted.
This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now
TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive
from TypeConstraint and AttrConstraint, respectively.
Comments are revised and examples are added to make it clear how to use constraints.
PiperOrigin-RevId: 240125076
2019-03-25 21:09:26 +08:00
|
|
|
return getAsConstraint().getConditionTemplate();
|
2019-02-02 07:40:22 +08:00
|
|
|
}
|
|
|
|
|
2019-04-23 05:13:45 +08:00
|
|
|
llvm::StringRef tblgen::DagLeaf::getNativeCodeTemplate() const {
|
|
|
|
assert(isNativeCodeCall() && "the DAG leaf must be NativeCodeCall");
|
|
|
|
return cast<llvm::DefInit>(def)->getDef()->getValueAsString("expression");
|
2019-01-29 06:04:40 +08:00
|
|
|
}
|
|
|
|
|
2019-04-01 23:58:53 +08:00
|
|
|
bool tblgen::DagLeaf::isSubClassOf(StringRef superclass) const {
|
|
|
|
if (auto *defInit = dyn_cast_or_null<llvm::DefInit>(def))
|
|
|
|
return defInit->getDef()->isSubClassOf(superclass);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-23 05:13:45 +08:00
|
|
|
bool tblgen::DagNode::isNativeCodeCall() const {
|
|
|
|
if (auto *defInit = dyn_cast_or_null<llvm::DefInit>(node->getOperator()))
|
|
|
|
return defInit->getDef()->isSubClassOf("NativeCodeCall");
|
|
|
|
return false;
|
2019-03-13 04:55:50 +08:00
|
|
|
}
|
|
|
|
|
2019-05-25 10:35:23 +08:00
|
|
|
bool tblgen::DagNode::isOperation() const {
|
|
|
|
return !(isNativeCodeCall() || isVerifyUnusedValue() || isReplaceWithValue());
|
|
|
|
}
|
|
|
|
|
2019-04-23 05:13:45 +08:00
|
|
|
llvm::StringRef tblgen::DagNode::getNativeCodeTemplate() const {
|
|
|
|
assert(isNativeCodeCall() && "the DAG leaf must be NativeCodeCall");
|
2019-03-13 04:55:50 +08:00
|
|
|
return cast<llvm::DefInit>(node->getOperator())
|
|
|
|
->getDef()
|
2019-04-23 05:13:45 +08:00
|
|
|
->getValueAsString("expression");
|
2019-03-13 04:55:50 +08:00
|
|
|
}
|
|
|
|
|
2019-02-14 06:30:40 +08:00
|
|
|
llvm::StringRef tblgen::DagNode::getOpName() const {
|
|
|
|
return node->getNameStr();
|
|
|
|
}
|
|
|
|
|
2019-01-29 06:04:40 +08:00
|
|
|
Operator &tblgen::DagNode::getDialectOp(RecordOperatorMap *mapper) const {
|
|
|
|
llvm::Record *opDef = cast<llvm::DefInit>(node->getOperator())->getDef();
|
2019-04-13 00:52:11 +08:00
|
|
|
auto it = mapper->find(opDef);
|
|
|
|
if (it != mapper->end())
|
|
|
|
return *it->second;
|
|
|
|
return *mapper->try_emplace(opDef, llvm::make_unique<Operator>(opDef))
|
|
|
|
.first->second;
|
2019-01-29 06:04:40 +08:00
|
|
|
}
|
|
|
|
|
2019-05-04 10:48:57 +08:00
|
|
|
int tblgen::DagNode::getNumOps() const {
|
|
|
|
int count = isReplaceWithValue() ? 0 : 1;
|
|
|
|
for (int i = 0, e = getNumArgs(); i != e; ++i) {
|
2019-01-29 06:04:40 +08:00
|
|
|
if (auto child = getArgAsNestedDag(i))
|
|
|
|
count += child.getNumOps();
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2019-05-04 10:48:57 +08:00
|
|
|
int tblgen::DagNode::getNumArgs() const { return node->getNumArgs(); }
|
2019-01-29 06:04:40 +08:00
|
|
|
|
|
|
|
bool tblgen::DagNode::isNestedDagArg(unsigned index) const {
|
|
|
|
return isa<llvm::DagInit>(node->getArg(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
tblgen::DagNode tblgen::DagNode::getArgAsNestedDag(unsigned index) const {
|
|
|
|
return DagNode(dyn_cast_or_null<llvm::DagInit>(node->getArg(index)));
|
|
|
|
}
|
|
|
|
|
2019-02-02 07:40:22 +08:00
|
|
|
tblgen::DagLeaf tblgen::DagNode::getArgAsLeaf(unsigned index) const {
|
|
|
|
assert(!isNestedDagArg(index));
|
|
|
|
return DagLeaf(node->getArg(index));
|
2019-01-29 06:04:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StringRef tblgen::DagNode::getArgName(unsigned index) const {
|
|
|
|
return node->getArgNameStr(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tblgen::DagNode::isReplaceWithValue() const {
|
|
|
|
auto *dagOpDef = cast<llvm::DefInit>(node->getOperator())->getDef();
|
|
|
|
return dagOpDef->getName() == "replaceWithValue";
|
|
|
|
}
|
|
|
|
|
2019-03-09 05:56:53 +08:00
|
|
|
bool tblgen::DagNode::isVerifyUnusedValue() const {
|
|
|
|
auto *dagOpDef = cast<llvm::DefInit>(node->getOperator())->getDef();
|
|
|
|
return dagOpDef->getName() == "verifyUnusedValue";
|
|
|
|
}
|
|
|
|
|
2019-01-29 06:04:40 +08:00
|
|
|
tblgen::Pattern::Pattern(const llvm::Record *def, RecordOperatorMap *mapper)
|
|
|
|
: def(*def), recordOpMap(mapper) {
|
2019-04-09 06:14:59 +08:00
|
|
|
collectBoundArguments(getSourcePattern());
|
2019-01-29 06:04:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tblgen::DagNode tblgen::Pattern::getSourcePattern() const {
|
[TableGen] Consolidate constraint related concepts
Previously we have multiple mechanisms to specify op definition and match constraints:
TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants
are not added because there are so many distinct cases we need to model; essentially,
they are all carrying a predicate. It's just an artifact of implementation.
It's quite confusing for users to grasp these variants and choose among them. Instead,
as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each
dialect has the flexibility to define its own aliases if wanted.
This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now
TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive
from TypeConstraint and AttrConstraint, respectively.
Comments are revised and examples are added to make it clear how to use constraints.
PiperOrigin-RevId: 240125076
2019-03-25 21:09:26 +08:00
|
|
|
return tblgen::DagNode(def.getValueAsDag("sourcePattern"));
|
2019-01-29 06:04:40 +08:00
|
|
|
}
|
|
|
|
|
2019-05-04 10:48:57 +08:00
|
|
|
int tblgen::Pattern::getNumResults() const {
|
[TableGen] Consolidate constraint related concepts
Previously we have multiple mechanisms to specify op definition and match constraints:
TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants
are not added because there are so many distinct cases we need to model; essentially,
they are all carrying a predicate. It's just an artifact of implementation.
It's quite confusing for users to grasp these variants and choose among them. Instead,
as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each
dialect has the flexibility to define its own aliases if wanted.
This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now
TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive
from TypeConstraint and AttrConstraint, respectively.
Comments are revised and examples are added to make it clear how to use constraints.
PiperOrigin-RevId: 240125076
2019-03-25 21:09:26 +08:00
|
|
|
auto *results = def.getValueAsListInit("resultPatterns");
|
2019-01-29 06:04:40 +08:00
|
|
|
return results->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
tblgen::DagNode tblgen::Pattern::getResultPattern(unsigned index) const {
|
[TableGen] Consolidate constraint related concepts
Previously we have multiple mechanisms to specify op definition and match constraints:
TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants
are not added because there are so many distinct cases we need to model; essentially,
they are all carrying a predicate. It's just an artifact of implementation.
It's quite confusing for users to grasp these variants and choose among them. Instead,
as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each
dialect has the flexibility to define its own aliases if wanted.
This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now
TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive
from TypeConstraint and AttrConstraint, respectively.
Comments are revised and examples are added to make it clear how to use constraints.
PiperOrigin-RevId: 240125076
2019-03-25 21:09:26 +08:00
|
|
|
auto *results = def.getValueAsListInit("resultPatterns");
|
2019-01-29 06:04:40 +08:00
|
|
|
return tblgen::DagNode(cast<llvm::DagInit>(results->getElement(index)));
|
|
|
|
}
|
|
|
|
|
2019-04-23 04:40:30 +08:00
|
|
|
void tblgen::Pattern::ensureBoundInSourcePattern(llvm::StringRef name) const {
|
|
|
|
if (boundArguments.find(name) == boundArguments.end() &&
|
|
|
|
boundOps.find(name) == boundOps.end())
|
2019-01-29 06:04:40 +08:00
|
|
|
PrintFatalError(def.getLoc(),
|
|
|
|
Twine("referencing unbound variable '") + name + "'");
|
|
|
|
}
|
|
|
|
|
2019-02-02 07:40:22 +08:00
|
|
|
llvm::StringMap<tblgen::Argument> &
|
|
|
|
tblgen::Pattern::getSourcePatternBoundArgs() {
|
2019-01-29 06:04:40 +08:00
|
|
|
return boundArguments;
|
|
|
|
}
|
|
|
|
|
2019-04-23 04:40:30 +08:00
|
|
|
llvm::StringSet<> &tblgen::Pattern::getSourcePatternBoundOps() {
|
|
|
|
return boundOps;
|
2019-02-14 06:30:40 +08:00
|
|
|
}
|
|
|
|
|
2019-01-29 06:04:40 +08:00
|
|
|
const tblgen::Operator &tblgen::Pattern::getSourceRootOp() {
|
|
|
|
return getSourcePattern().getDialectOp(recordOpMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
tblgen::Operator &tblgen::Pattern::getDialectOp(DagNode node) {
|
|
|
|
return node.getDialectOp(recordOpMap);
|
|
|
|
}
|
2019-02-14 06:30:40 +08:00
|
|
|
|
[TableGen] Consolidate constraint related concepts
Previously we have multiple mechanisms to specify op definition and match constraints:
TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants
are not added because there are so many distinct cases we need to model; essentially,
they are all carrying a predicate. It's just an artifact of implementation.
It's quite confusing for users to grasp these variants and choose among them. Instead,
as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each
dialect has the flexibility to define its own aliases if wanted.
This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now
TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive
from TypeConstraint and AttrConstraint, respectively.
Comments are revised and examples are added to make it clear how to use constraints.
PiperOrigin-RevId: 240125076
2019-03-25 21:09:26 +08:00
|
|
|
std::vector<tblgen::AppliedConstraint> tblgen::Pattern::getConstraints() const {
|
2019-02-14 06:30:40 +08:00
|
|
|
auto *listInit = def.getValueAsListInit("constraints");
|
[TableGen] Consolidate constraint related concepts
Previously we have multiple mechanisms to specify op definition and match constraints:
TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants
are not added because there are so many distinct cases we need to model; essentially,
they are all carrying a predicate. It's just an artifact of implementation.
It's quite confusing for users to grasp these variants and choose among them. Instead,
as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each
dialect has the flexibility to define its own aliases if wanted.
This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now
TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive
from TypeConstraint and AttrConstraint, respectively.
Comments are revised and examples are added to make it clear how to use constraints.
PiperOrigin-RevId: 240125076
2019-03-25 21:09:26 +08:00
|
|
|
std::vector<tblgen::AppliedConstraint> ret;
|
2019-02-14 06:30:40 +08:00
|
|
|
ret.reserve(listInit->size());
|
[TableGen] Consolidate constraint related concepts
Previously we have multiple mechanisms to specify op definition and match constraints:
TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants
are not added because there are so many distinct cases we need to model; essentially,
they are all carrying a predicate. It's just an artifact of implementation.
It's quite confusing for users to grasp these variants and choose among them. Instead,
as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each
dialect has the flexibility to define its own aliases if wanted.
This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now
TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive
from TypeConstraint and AttrConstraint, respectively.
Comments are revised and examples are added to make it clear how to use constraints.
PiperOrigin-RevId: 240125076
2019-03-25 21:09:26 +08:00
|
|
|
|
2019-02-14 06:30:40 +08:00
|
|
|
for (auto it : *listInit) {
|
[TableGen] Consolidate constraint related concepts
Previously we have multiple mechanisms to specify op definition and match constraints:
TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants
are not added because there are so many distinct cases we need to model; essentially,
they are all carrying a predicate. It's just an artifact of implementation.
It's quite confusing for users to grasp these variants and choose among them. Instead,
as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each
dialect has the flexibility to define its own aliases if wanted.
This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now
TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive
from TypeConstraint and AttrConstraint, respectively.
Comments are revised and examples are added to make it clear how to use constraints.
PiperOrigin-RevId: 240125076
2019-03-25 21:09:26 +08:00
|
|
|
auto *dagInit = dyn_cast<llvm::DagInit>(it);
|
|
|
|
if (!dagInit)
|
|
|
|
PrintFatalError(def.getLoc(), "all elemements in Pattern multi-entity "
|
|
|
|
"constraints should be DAG nodes");
|
|
|
|
|
|
|
|
std::vector<std::string> entities;
|
|
|
|
entities.reserve(dagInit->arg_size());
|
|
|
|
for (auto *argName : dagInit->getArgNames())
|
|
|
|
entities.push_back(argName->getValue());
|
|
|
|
|
|
|
|
ret.emplace_back(cast<llvm::DefInit>(dagInit->getOperator())->getDef(),
|
|
|
|
std::move(entities));
|
2019-02-14 06:30:40 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2019-03-30 00:36:09 +08:00
|
|
|
|
|
|
|
int tblgen::Pattern::getBenefit() const {
|
2019-04-02 00:39:59 +08:00
|
|
|
// The initial benefit value is a heuristic with number of ops in the source
|
2019-03-30 00:36:09 +08:00
|
|
|
// pattern.
|
2019-04-02 00:39:59 +08:00
|
|
|
int initBenefit = getSourcePattern().getNumOps();
|
2019-03-30 00:36:09 +08:00
|
|
|
llvm::DagInit *delta = def.getValueAsDag("benefitDelta");
|
2019-04-02 00:39:59 +08:00
|
|
|
if (delta->getNumArgs() != 1 || !isa<llvm::IntInit>(delta->getArg(0))) {
|
|
|
|
PrintFatalError(def.getLoc(),
|
|
|
|
"The 'addBenefit' takes and only takes one integer value");
|
|
|
|
}
|
|
|
|
return initBenefit + dyn_cast<llvm::IntInit>(delta->getArg(0))->getValue();
|
2019-03-30 00:36:09 +08:00
|
|
|
}
|
2019-04-09 06:14:59 +08:00
|
|
|
|
2019-05-24 07:08:52 +08:00
|
|
|
std::vector<tblgen::Pattern::IdentifierLine>
|
|
|
|
tblgen::Pattern::getLocation() const {
|
|
|
|
std::vector<std::pair<StringRef, unsigned>> result;
|
|
|
|
result.reserve(def.getLoc().size());
|
|
|
|
for (auto loc : def.getLoc()) {
|
|
|
|
unsigned buf = llvm::SrcMgr.FindBufferContainingLoc(loc);
|
|
|
|
assert(buf && "invalid source location");
|
|
|
|
result.emplace_back(
|
|
|
|
llvm::SrcMgr.getBufferInfo(buf).Buffer->getBufferIdentifier(),
|
|
|
|
llvm::SrcMgr.getLineAndColumn(loc, buf).first);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-04-09 06:14:59 +08:00
|
|
|
void tblgen::Pattern::collectBoundArguments(DagNode tree) {
|
|
|
|
auto &op = getDialectOp(tree);
|
|
|
|
auto numOpArgs = op.getNumArgs();
|
|
|
|
auto numTreeArgs = tree.getNumArgs();
|
|
|
|
|
|
|
|
if (numOpArgs != numTreeArgs) {
|
|
|
|
PrintFatalError(def.getLoc(),
|
|
|
|
formatv("op '{0}' argument number mismatch: "
|
|
|
|
"{1} in pattern vs. {2} in definition",
|
|
|
|
op.getOperationName(), numTreeArgs, numOpArgs));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The name attached to the DAG node's operator is for representing the
|
|
|
|
// results generated from this op. It should be remembered as bound results.
|
|
|
|
auto treeName = tree.getOpName();
|
|
|
|
if (!treeName.empty())
|
2019-04-23 04:40:30 +08:00
|
|
|
boundOps.insert(treeName);
|
2019-04-09 06:14:59 +08:00
|
|
|
|
|
|
|
// TODO(jpienaar): Expand to multiple matches.
|
2019-05-04 10:48:57 +08:00
|
|
|
for (int i = 0; i != numTreeArgs; ++i) {
|
2019-04-09 06:14:59 +08:00
|
|
|
if (auto treeArg = tree.getArgAsNestedDag(i)) {
|
|
|
|
// This DAG node argument is a DAG node itself. Go inside recursively.
|
|
|
|
collectBoundArguments(treeArg);
|
|
|
|
} else {
|
|
|
|
auto treeArgName = tree.getArgName(i);
|
|
|
|
if (!treeArgName.empty())
|
|
|
|
boundArguments.try_emplace(treeArgName, op.getArg(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|