diff options
author | Daniel Sanders <daniel_l_sanders@apple.com> | 2017-11-13 22:26:13 +0000 |
---|---|---|
committer | Daniel Sanders <daniel_l_sanders@apple.com> | 2017-11-13 22:26:13 +0000 |
commit | 438d60f1e77de43fcf75358a2ab8f9e661a48406 (patch) | |
tree | 04e3b028183d012123d2f42799747663c104576a /utils/TableGen | |
parent | ecb06411e6f18740f369c552501930d6757ca22f (diff) |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318095 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen')
-rw-r--r-- | utils/TableGen/CodeGenDAGPatterns.cpp | 43 | ||||
-rw-r--r-- | utils/TableGen/CodeGenDAGPatterns.h | 2 |
2 files changed, 33 insertions, 12 deletions
diff --git a/utils/TableGen/CodeGenDAGPatterns.cpp b/utils/TableGen/CodeGenDAGPatterns.cpp index c07a7267bbe..b8ba5db6ef4 100644 --- a/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/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); } diff --git a/utils/TableGen/CodeGenDAGPatterns.h b/utils/TableGen/CodeGenDAGPatterns.h index d3bb99a5a8f..3a76ab25ea7 100644 --- a/utils/TableGen/CodeGenDAGPatterns.h +++ b/utils/TableGen/CodeGenDAGPatterns.h @@ -486,6 +486,8 @@ public: bool isLoad() const; // Is the desired predefined predicate for a store? bool isStore() const; + // Is the desired predefined predicate for an atomic? + bool isAtomic() const; /// Is this predicate the predefined unindexed load predicate? /// Is this predicate the predefined unindexed store predicate? |