summaryrefslogtreecommitdiffstats
path: root/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
diff options
context:
space:
mode:
authorDaniel Sanders <daniel_l_sanders@apple.com>2017-11-13 22:26:13 +0000
committerDaniel Sanders <daniel_l_sanders@apple.com>2017-11-13 22:26:13 +0000
commit87d196ca48b38f2f4503238b7d8aadebbc873571 (patch)
tree3a4b52349dde187ff7de70dc717afe55f6a58796 /llvm/utils/TableGen/CodeGenDAGPatterns.cpp
parent1bfefc1c725792108a37f4e2678eb23fb06bb92f (diff)
downloadbcm5719-llvm-87d196ca48b38f2f4503238b7d8aadebbc873571.tar.gz
bcm5719-llvm-87d196ca48b38f2f4503238b7d8aadebbc873571.zip
[tablegen] Handle atomic predicates for memory type inside tablegen. NFC.
Similar to r315841, GlobalISel and SelectionDAG require different code for the common atomic predicates due to differences in the representation. Even without that, differences in the IR (SDNode vs MachineInstr) require differences in the C++ predicate. This patch moves the implementation of the common atomic predicates related to memory type into tablegen so that it can handle these differences. It's NFC for SelectionDAG since it emits equivalent code and it's NFC for GlobalISel since the rules involving the relevant predicates are still rejected by the importer. llvm-svn: 318095
Diffstat (limited to 'llvm/utils/TableGen/CodeGenDAGPatterns.cpp')
-rw-r--r--llvm/utils/TableGen/CodeGenDAGPatterns.cpp43
1 files changed, 31 insertions, 12 deletions
diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
index c07a7267bbe..b8ba5db6ef4 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -818,32 +818,36 @@ TreePredicateFn::TreePredicateFn(TreePattern *N) : PatFragRec(N) {
}
bool TreePredicateFn::hasPredCode() const {
- return isLoad() || isStore() ||
+ return isLoad() || isStore() || isAtomic() ||
!PatFragRec->getRecord()->getValueAsString("PredicateCode").empty();
}
std::string TreePredicateFn::getPredCode() const {
std::string Code = "";
+ if (!isLoad() && !isStore() && !isAtomic()) {
+ Record *MemoryVT = getMemoryVT();
+
+ if (MemoryVT)
+ PrintFatalError(getOrigPatFragRecord()->getRecord()->getLoc(),
+ "MemoryVT requires IsLoad or IsStore");
+ }
+
if (!isLoad() && !isStore()) {
if (isUnindexed())
PrintFatalError(getOrigPatFragRecord()->getRecord()->getLoc(),
"IsUnindexed requires IsLoad or IsStore");
- Record *MemoryVT = getMemoryVT();
Record *ScalarMemoryVT = getScalarMemoryVT();
- if (MemoryVT)
- PrintFatalError(getOrigPatFragRecord()->getRecord()->getLoc(),
- "MemoryVT requires IsLoad or IsStore");
if (ScalarMemoryVT)
PrintFatalError(getOrigPatFragRecord()->getRecord()->getLoc(),
"ScalarMemoryVT requires IsLoad or IsStore");
}
- if (isLoad() && isStore())
+ if (isLoad() + isStore() + isAtomic() > 1)
PrintFatalError(getOrigPatFragRecord()->getRecord()->getLoc(),
- "IsLoad and IsStore are mutually exclusive");
+ "IsLoad, IsStore, and IsAtomic are mutually exclusive");
if (isLoad()) {
if (!isUnindexed() && !isNonExtLoad() && !isAnyExtLoad() &&
@@ -880,6 +884,23 @@ std::string TreePredicateFn::getPredCode() const {
"IsTruncStore requires IsStore");
}
+ if (isAtomic()) {
+ if (getMemoryVT() == nullptr)
+ PrintFatalError(getOrigPatFragRecord()->getRecord()->getLoc(),
+ "IsAtomic cannot be used by itself");
+ }
+ if (isLoad() || isStore() || isAtomic()) {
+ StringRef SDNodeName =
+ isLoad() ? "LoadSDNode" : isStore() ? "StoreSDNode" : "AtomicSDNode";
+
+ Record *MemoryVT = getMemoryVT();
+
+ if (MemoryVT)
+ Code += ("if (cast<" + SDNodeName + ">(N)->getMemoryVT() != MVT::" +
+ MemoryVT->getName() + ") return false;\n")
+ .str();
+ }
+
if (isLoad() || isStore()) {
StringRef SDNodeName = isLoad() ? "LoadSDNode" : "StoreSDNode";
@@ -920,13 +941,8 @@ std::string TreePredicateFn::getPredCode() const {
" if (!cast<StoreSDNode>(N)->isTruncatingStore()) return false;\n";
}
- Record *MemoryVT = getMemoryVT();
Record *ScalarMemoryVT = getScalarMemoryVT();
- if (MemoryVT)
- Code += ("if (cast<" + SDNodeName + ">(N)->getMemoryVT() != MVT::" +
- MemoryVT->getName() + ") return false;\n")
- .str();
if (ScalarMemoryVT)
Code += ("if (cast<" + SDNodeName +
">(N)->getMemoryVT().getScalarType() != MVT::" +
@@ -978,6 +994,9 @@ bool TreePredicateFn::isLoad() const {
bool TreePredicateFn::isStore() const {
return isPredefinedPredicateEqualTo("IsStore", true);
}
+bool TreePredicateFn::isAtomic() const {
+ return isPredefinedPredicateEqualTo("IsAtomic", true);
+}
bool TreePredicateFn::isUnindexed() const {
return isPredefinedPredicateEqualTo("IsUnindexed", true);
}
OpenPOWER on IntegriCloud