From b26a2755dc107b2608bc9c6c3f8e952613760b46 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Mon, 2 Nov 2020 13:57:42 -0600 Subject: [PATCH] [Hexagon] Move isTypeForHVX from Hexagon TTI to HexagonSubtarget, NFC It's useful outside of Hexagon TTI, and with how TTI is implemented, it is not accessible outside of TTI. --- llvm/lib/Target/Hexagon/HexagonSubtarget.cpp | 53 ++++++++++++++++++++++ llvm/lib/Target/Hexagon/HexagonSubtarget.h | 39 ++-------------- .../Target/Hexagon/HexagonTargetTransformInfo.cpp | 21 ++------- .../Target/Hexagon/HexagonTargetTransformInfo.h | 1 - 4 files changed, 59 insertions(+), 55 deletions(-) diff --git a/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp b/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp index 6079292..fe1582a 100644 --- a/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp +++ b/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp @@ -125,6 +125,59 @@ HexagonSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) { return *this; } +bool HexagonSubtarget::isHVXElementType(MVT Ty, bool IncludeBool) const { + if (!useHVXOps()) + return false; + if (Ty.isVector()) + Ty = Ty.getVectorElementType(); + if (IncludeBool && Ty == MVT::i1) + return true; + ArrayRef ElemTypes = getHVXElementTypes(); + return llvm::find(ElemTypes, Ty) != ElemTypes.end(); +} + +bool HexagonSubtarget::isHVXVectorType(MVT VecTy, bool IncludeBool) const { + if (!VecTy.isVector() || !useHVXOps() || VecTy.isScalableVector()) + return false; + MVT ElemTy = VecTy.getVectorElementType(); + if (!IncludeBool && ElemTy == MVT::i1) + return false; + + unsigned HwLen = getVectorLength(); + unsigned NumElems = VecTy.getVectorNumElements(); + ArrayRef ElemTypes = getHVXElementTypes(); + + if (IncludeBool && ElemTy == MVT::i1) { + // Boolean HVX vector types are formed from regular HVX vector types + // by replacing the element type with i1. + for (MVT T : ElemTypes) + if (NumElems * T.getSizeInBits() == 8 * HwLen) + return true; + return false; + } + + unsigned VecWidth = VecTy.getSizeInBits(); + if (VecWidth != 8 * HwLen && VecWidth != 16 * HwLen) + return false; + return llvm::find(ElemTypes, ElemTy) != ElemTypes.end(); +} + +bool HexagonSubtarget::isTypeForHVX(Type *VecTy, bool IncludeBool) const { + if (!VecTy->isVectorTy() || isa(VecTy)) + return false; + // Avoid types like <2 x i32*>. + if (!cast(VecTy)->getElementType()->isIntegerTy()) + return false; + EVT Ty = EVT::getEVT(VecTy, /*HandleUnknown*/false); + if (!Ty.isSimple() || Ty.getSizeInBits() <= 64) + return false; + if (isHVXVectorType(Ty.getSimpleVT(), IncludeBool)) + return true; + auto Action = + getTargetLowering()->getPreferredVectorAction(Ty.getSimpleVT()); + return Action == TargetLoweringBase::TypeWidenVector; +} + void HexagonSubtarget::UsrOverflowMutation::apply(ScheduleDAGInstrs *DAG) { for (SUnit &SU : DAG->SUnits) { if (!SU.isInstr()) diff --git a/llvm/lib/Target/Hexagon/HexagonSubtarget.h b/llvm/lib/Target/Hexagon/HexagonSubtarget.h index 5b71784..7b7fb8d 100644 --- a/llvm/lib/Target/Hexagon/HexagonSubtarget.h +++ b/llvm/lib/Target/Hexagon/HexagonSubtarget.h @@ -275,42 +275,9 @@ public: return makeArrayRef(Types); } - bool isHVXElementType(MVT Ty, bool IncludeBool = false) const { - if (!useHVXOps()) - return false; - if (Ty.isVector()) - Ty = Ty.getVectorElementType(); - if (IncludeBool && Ty == MVT::i1) - return true; - ArrayRef ElemTypes = getHVXElementTypes(); - return llvm::find(ElemTypes, Ty) != ElemTypes.end(); - } - - bool isHVXVectorType(MVT VecTy, bool IncludeBool = false) const { - if (!VecTy.isVector() || !useHVXOps() || VecTy.isScalableVector()) - return false; - MVT ElemTy = VecTy.getVectorElementType(); - if (!IncludeBool && ElemTy == MVT::i1) - return false; - - unsigned HwLen = getVectorLength(); - unsigned NumElems = VecTy.getVectorNumElements(); - ArrayRef ElemTypes = getHVXElementTypes(); - - if (IncludeBool && ElemTy == MVT::i1) { - // Boolean HVX vector types are formed from regular HVX vector types - // by replacing the element type with i1. - for (MVT T : ElemTypes) - if (NumElems * T.getSizeInBits() == 8*HwLen) - return true; - return false; - } - - unsigned VecWidth = VecTy.getSizeInBits(); - if (VecWidth != 8*HwLen && VecWidth != 16*HwLen) - return false; - return llvm::find(ElemTypes, ElemTy) != ElemTypes.end(); - } + bool isHVXElementType(MVT Ty, bool IncludeBool = false) const; + bool isHVXVectorType(MVT VecTy, bool IncludeBool = false) const; + bool isTypeForHVX(Type *VecTy, bool IncludeBool = false) const; unsigned getTypeAlignment(MVT Ty) const { if (isHVXVectorType(Ty, true)) diff --git a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp index 045e59a..3c00b2c 100644 --- a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp +++ b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp @@ -47,21 +47,6 @@ bool HexagonTTIImpl::useHVX() const { return ST.useHVXOps() && HexagonAutoHVX; } -bool HexagonTTIImpl::isTypeForHVX(Type *VecTy) const { - if (!VecTy->isVectorTy() || isa(VecTy)) - return false; - // Avoid types like <2 x i32*>. - if (!cast(VecTy)->getElementType()->isIntegerTy()) - return false; - EVT VecVT = EVT::getEVT(VecTy); - if (!VecVT.isSimple() || VecVT.getSizeInBits() <= 64) - return false; - if (ST.isHVXVectorType(VecVT.getSimpleVT())) - return true; - auto Action = TLI.getPreferredVectorAction(VecVT.getSimpleVT()); - return Action == TargetLoweringBase::TypeWidenVector; -} - unsigned HexagonTTIImpl::getTypeNumElements(Type *Ty) const { if (auto *VTy = dyn_cast(Ty)) return VTy->getNumElements(); @@ -171,7 +156,7 @@ unsigned HexagonTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src, if (Src->isVectorTy()) { VectorType *VecTy = cast(Src); unsigned VecWidth = VecTy->getPrimitiveSizeInBits().getFixedSize(); - if (useHVX() && isTypeForHVX(VecTy)) { + if (useHVX() && ST.isTypeForHVX(VecTy)) { unsigned RegWidth = getRegisterBitWidth(true); assert(RegWidth && "Non-zero vector register width expected"); // Cost of HVX loads. @@ -314,11 +299,11 @@ unsigned HexagonTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, } bool HexagonTTIImpl::isLegalMaskedStore(Type *DataType, Align /*Alignment*/) { - return HexagonMaskedVMem && isTypeForHVX(DataType); + return HexagonMaskedVMem && ST.isTypeForHVX(DataType); } bool HexagonTTIImpl::isLegalMaskedLoad(Type *DataType, Align /*Alignment*/) { - return HexagonMaskedVMem && isTypeForHVX(DataType); + return HexagonMaskedVMem && ST.isTypeForHVX(DataType); } /// --- Vector TTI end --- diff --git a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h index 5a5a5f7..835358d 100644 --- a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h +++ b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h @@ -43,7 +43,6 @@ class HexagonTTIImpl : public BasicTTIImplBase { const HexagonTargetLowering *getTLI() const { return &TLI; } bool useHVX() const; - bool isTypeForHVX(Type *VecTy) const; // Returns the number of vector elements of Ty, if Ty is a vector type, // or 1 if Ty is a scalar type. It is incorrect to call this function -- 2.7.4