aboutsummaryrefslogtreecommitdiff
path: root/utils/TableGen/CodeGenDAGPatterns.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-04-17 22:05:17 +0000
committerChris Lattner <sabre@nondot.org>2011-04-17 22:05:17 +0000
commit7ed1391ff66012e4963081cfb20b6166e8784f50 (patch)
tree5daca144fdadefe1c48e3479be81a0a96b35659b /utils/TableGen/CodeGenDAGPatterns.cpp
parent543790673c747ab2793fc657e239ce5f78419dc0 (diff)
now that predicates have a decent abstraction layer on them, introduce a new
kind of predicate: one that is specific to imm nodes. The predicate function specified here just checks an int64_t directly instead of messing around with SDNode's. The virtue of this is that it means that fastisel and other things can reason about these predicates. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129675 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/CodeGenDAGPatterns.cpp')
-rw-r--r--utils/TableGen/CodeGenDAGPatterns.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/utils/TableGen/CodeGenDAGPatterns.cpp b/utils/TableGen/CodeGenDAGPatterns.cpp
index b74144ebfd..13ac6b15ba 100644
--- a/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -621,14 +621,24 @@ static void DumpDepVars(MultipleUseVarSet &DepVars) {
// TreePredicateFn Implementation
//===----------------------------------------------------------------------===//
+/// TreePredicateFn constructor. Here 'N' is a subclass of PatFrag.
+TreePredicateFn::TreePredicateFn(TreePattern *N) : PatFragRec(N) {
+ assert((getPredCode().empty() || getImmCode().empty()) &&
+ ".td file corrupt: can't have a node predicate *and* an imm predicate");
+}
+
std::string TreePredicateFn::getPredCode() const {
return PatFragRec->getRecord()->getValueAsCode("PredicateCode");
}
+std::string TreePredicateFn::getImmCode() const {
+ return PatFragRec->getRecord()->getValueAsCode("ImmediateCode");
+}
+
/// isAlwaysTrue - Return true if this is a noop predicate.
bool TreePredicateFn::isAlwaysTrue() const {
- return getPredCode().empty();
+ return getPredCode().empty() && getImmCode().empty();
}
/// Return the name to use in the generated code to reference this, this is
@@ -642,6 +652,18 @@ std::string TreePredicateFn::getFnName() const {
/// not N. This handles casting and conversion to a concrete node type as
/// appropriate.
std::string TreePredicateFn::getCodeToRunOnSDNode() const {
+ // Handle immediate predicates first.
+ std::string ImmCode = getImmCode();
+ if (!ImmCode.empty()) {
+ std::string Result =
+ " int64_t Imm = cast<ConstantSDNode>(Node)->getSExtValue();\n";
+ if (ImmCode.find("VT") != std::string::npos)
+ Result += " MVT VT = Node->getValueType(0).getSimpleVT();\n";
+ return Result + ImmCode;
+ }
+
+ // Handle arbitrary node predicates.
+ assert(!getPredCode().empty() && "Don't have any predicate code!");
std::string ClassName;
if (PatFragRec->getOnlyTree()->isLeaf())
ClassName = "SDNode";