|
32 | 32 | #include "llvm/ADT/APInt.h"
|
33 | 33 | #include "llvm/IR/Constant.h"
|
34 | 34 | #include "llvm/IR/Constants.h"
|
| 35 | +#include "llvm/IR/DataLayout.h" |
35 | 36 | #include "llvm/IR/InstrTypes.h"
|
36 | 37 | #include "llvm/IR/Instruction.h"
|
37 | 38 | #include "llvm/IR/Instructions.h"
|
@@ -2002,6 +2003,42 @@ inline ExtractValue_match<Ind, Val_t> m_ExtractValue(const Val_t &V) {
|
2002 | 2003 | return ExtractValue_match<Ind, Val_t>(V);
|
2003 | 2004 | }
|
2004 | 2005 |
|
| 2006 | +/// Matches patterns for `vscale`. This can either be a call to `llvm.vscale` or |
| 2007 | +/// the constant expression |
| 2008 | +/// `ptrtoint(gep <vscale x 1 x i8>, <vscale x 1 x i8>* null, i32 1>` |
| 2009 | +/// under the right conditions determined by DataLayout. |
| 2010 | +struct VScaleVal_match { |
| 2011 | +private: |
| 2012 | + template <typename Base, typename Offset> |
| 2013 | + inline BinaryOp_match<Base, Offset, Instruction::GetElementPtr> |
| 2014 | + m_OffsetGep(const Base &B, const Offset &O) { |
| 2015 | + return BinaryOp_match<Base, Offset, Instruction::GetElementPtr>(B, O); |
| 2016 | + } |
| 2017 | + |
| 2018 | +public: |
| 2019 | + const DataLayout &DL; |
| 2020 | + VScaleVal_match(const DataLayout &DL) : DL(DL) {} |
| 2021 | + |
| 2022 | + template <typename ITy> bool match(ITy *V) { |
| 2023 | + if (m_Intrinsic<Intrinsic::vscale>().match(V)) |
| 2024 | + return true; |
| 2025 | + |
| 2026 | + if (m_PtrToInt(m_OffsetGep(m_Zero(), m_SpecificInt(1))).match(V)) { |
| 2027 | + Type *PtrTy = cast<Operator>(V)->getOperand(0)->getType(); |
| 2028 | + Type *DerefTy = PtrTy->getPointerElementType(); |
| 2029 | + if (DerefTy->isVectorTy() && DerefTy->getVectorIsScalable() && |
| 2030 | + DL.getTypeAllocSizeInBits(DerefTy).getKnownMinSize() == 8) |
| 2031 | + return true; |
| 2032 | + } |
| 2033 | + |
| 2034 | + return false; |
| 2035 | + } |
| 2036 | +}; |
| 2037 | + |
| 2038 | +inline VScaleVal_match m_VScale(const DataLayout &DL) { |
| 2039 | + return VScaleVal_match(DL); |
| 2040 | +} |
| 2041 | + |
2005 | 2042 | } // end namespace PatternMatch
|
2006 | 2043 | } // end namespace llvm
|
2007 | 2044 |
|
|
0 commit comments