diff options
| author | Tom Stellard <tstellar@redhat.com> | 2019-02-20 19:43:47 +0000 |
|---|---|---|
| committer | Tom Stellard <tstellar@redhat.com> | 2019-02-20 19:43:47 +0000 |
| commit | 9ad714f7d1a926c00b389a41a6d79969089da678 (patch) | |
| tree | 73160ab915d7e795194f0cec9618e329f318dbcf /llvm/utils/TableGen | |
| parent | 7feae0585825c9357f64242b63fd4bbb27ff020c (diff) | |
| download | bcm5719-llvm-9ad714f7d1a926c00b389a41a6d79969089da678.tar.gz bcm5719-llvm-9ad714f7d1a926c00b389a41a6d79969089da678.zip | |
Add support for pointer types in patterns
Summary:
This adds support for defining patterns for global isel using pointer
types, for example:
def : Pat<(load GPR32:$src),
(p1 (LOAD GPR32:$src))>;
DAGISelEmitter will ignore the pointer information and treat these
types as integers with the same bit-width as the pointer type.
Reviewers: dsanders, rtereshin, arsenm
Reviewed By: arsenm
Subscribers: Petar.Avramovic, wdng, rovka, kristof.beyls, jfb, volkan, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D57065
llvm-svn: 354510
Diffstat (limited to 'llvm/utils/TableGen')
| -rw-r--r-- | llvm/utils/TableGen/CodeGenDAGPatterns.cpp | 8 | ||||
| -rw-r--r-- | llvm/utils/TableGen/CodeGenDAGPatterns.h | 11 | ||||
| -rw-r--r-- | llvm/utils/TableGen/GlobalISelEmitter.cpp | 3 | ||||
| -rw-r--r-- | llvm/utils/TableGen/InfoByHwMode.cpp | 7 | ||||
| -rw-r--r-- | llvm/utils/TableGen/InfoByHwMode.h | 6 |
5 files changed, 33 insertions, 2 deletions
diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp index f231c3a4aa7..19a7874ee1f 100644 --- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp @@ -67,8 +67,10 @@ static bool berase_if(MachineValueTypeSet &S, Predicate P) { // inference will apply to each mode separately. TypeSetByHwMode::TypeSetByHwMode(ArrayRef<ValueTypeByHwMode> VTList) { - for (const ValueTypeByHwMode &VVT : VTList) + for (const ValueTypeByHwMode &VVT : VTList) { insert(VVT); + AddrSpaces.push_back(VVT.PtrAddrSpace); + } } bool TypeSetByHwMode::isValueTypeByHwMode(bool AllowEmpty) const { @@ -85,9 +87,13 @@ ValueTypeByHwMode TypeSetByHwMode::getValueTypeByHwMode() const { assert(isValueTypeByHwMode(true) && "The type set has multiple types for at least one HW mode"); ValueTypeByHwMode VVT; + auto ASI = AddrSpaces.begin(); + for (const auto &I : *this) { MVT T = I.second.empty() ? MVT::Other : *I.second.begin(); VVT.getOrCreateTypeForMode(I.first, T); + if (ASI != AddrSpaces.end()) + VVT.PtrAddrSpace = *ASI++; } return VVT; } diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.h b/llvm/utils/TableGen/CodeGenDAGPatterns.h index 24b58b1d949..81ee2d0204d 100644 --- a/llvm/utils/TableGen/CodeGenDAGPatterns.h +++ b/llvm/utils/TableGen/CodeGenDAGPatterns.h @@ -190,6 +190,7 @@ private: struct TypeSetByHwMode : public InfoByHwMode<MachineValueTypeSet> { using SetType = MachineValueTypeSet; + std::vector<unsigned> AddrSpaces; TypeSetByHwMode() = default; TypeSetByHwMode(const TypeSetByHwMode &VTS) = default; @@ -226,6 +227,15 @@ struct TypeSetByHwMode : public InfoByHwMode<MachineValueTypeSet> { return Map.size() == 1 && Map.begin()->first == DefaultMode; } + bool isPointer() const { + return getValueTypeByHwMode().isPointer(); + } + + unsigned getPtrAddrSpace() const { + assert(isPointer()); + return getValueTypeByHwMode().PtrAddrSpace; + } + bool insert(const ValueTypeByHwMode &VVT); bool constrain(const TypeSetByHwMode &VTS); template <typename Predicate> bool constrain(Predicate P); @@ -242,6 +252,7 @@ struct TypeSetByHwMode : public InfoByHwMode<MachineValueTypeSet> { bool validate() const; private: + unsigned PtrAddrSpace = std::numeric_limits<unsigned>::max(); /// Intersect two sets. Return true if anything has changed. bool intersect(SetType &Out, const SetType &In); }; diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp index 8079e2989b6..1e71d1317ed 100644 --- a/llvm/utils/TableGen/GlobalISelEmitter.cpp +++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp @@ -1513,6 +1513,9 @@ Error OperandMatcher::addTypeCheckPredicate(const TypeSetByHwMode &VTy, if (OperandIsAPointer) addPredicate<PointerToAnyOperandMatcher>(OpTyOrNone->get().getSizeInBits()); + else if (VTy.isPointer()) + addPredicate<LLTOperandMatcher>(LLT::pointer(VTy.getPtrAddrSpace(), + OpTyOrNone->get().getSizeInBits())); else addPredicate<LLTOperandMatcher>(*OpTyOrNone); return Error::success(); diff --git a/llvm/utils/TableGen/InfoByHwMode.cpp b/llvm/utils/TableGen/InfoByHwMode.cpp index ce1b78a8f17..d9662889a5d 100644 --- a/llvm/utils/TableGen/InfoByHwMode.cpp +++ b/llvm/utils/TableGen/InfoByHwMode.cpp @@ -38,6 +38,11 @@ ValueTypeByHwMode::ValueTypeByHwMode(Record *R, const CodeGenHwModes &CGH) { } } +ValueTypeByHwMode::ValueTypeByHwMode(Record *R, MVT T) : ValueTypeByHwMode(T) { + if (R->isSubClassOf("PtrValueType")) + PtrAddrSpace = R->getValueAsInt("AddrSpace"); +} + bool ValueTypeByHwMode::operator== (const ValueTypeByHwMode &T) const { assert(isValid() && T.isValid() && "Invalid type in assignment"); bool Simple = isSimple(); @@ -111,7 +116,7 @@ ValueTypeByHwMode llvm::getValueTypeByHwMode(Record *Rec, "Record must be derived from ValueType"); if (Rec->isSubClassOf("HwModeSelect")) return ValueTypeByHwMode(Rec, CGH); - return ValueTypeByHwMode(llvm::getValueType(Rec)); + return ValueTypeByHwMode(Rec, llvm::getValueType(Rec)); } RegSizeInfo::RegSizeInfo(Record *R, const CodeGenHwModes &CGH) { diff --git a/llvm/utils/TableGen/InfoByHwMode.h b/llvm/utils/TableGen/InfoByHwMode.h index 6871d61028c..9e5cc3d5f2a 100644 --- a/llvm/utils/TableGen/InfoByHwMode.h +++ b/llvm/utils/TableGen/InfoByHwMode.h @@ -119,6 +119,7 @@ struct InfoByHwMode { struct ValueTypeByHwMode : public InfoByHwMode<MVT> { ValueTypeByHwMode(Record *R, const CodeGenHwModes &CGH); + ValueTypeByHwMode(Record *R, MVT T); ValueTypeByHwMode(MVT T) { Map.insert({DefaultMode,T}); } ValueTypeByHwMode() = default; @@ -134,6 +135,11 @@ struct ValueTypeByHwMode : public InfoByHwMode<MVT> { static StringRef getMVTName(MVT T); void writeToStream(raw_ostream &OS) const; void dump() const; + + unsigned PtrAddrSpace = std::numeric_limits<unsigned>::max(); + bool isPointer() const { + return PtrAddrSpace != std::numeric_limits<unsigned>::max(); + } }; ValueTypeByHwMode getValueTypeByHwMode(Record *Rec, |

