From a981cd8df0137e09172585abb4fb7eaae76a2fed Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Fri, 25 Jun 2021 10:22:01 -0500 Subject: [PATCH] [Hexagon] Convert getTypeAlignment to return Align Plus some minor related changes of the same nature. --- lib/Target/Hexagon/HexagonISelLowering.cpp | 26 +++++++++++----------- lib/Target/Hexagon/HexagonISelLowering.h | 4 ++-- lib/Target/Hexagon/HexagonSubtarget.h | 7 +++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/Target/Hexagon/HexagonISelLowering.cpp b/lib/Target/Hexagon/HexagonISelLowering.cpp index f156482cdcc..7126977a00f 100644 --- a/lib/Target/Hexagon/HexagonISelLowering.cpp +++ b/lib/Target/Hexagon/HexagonISelLowering.cpp @@ -1913,19 +1913,20 @@ const char* HexagonTargetLowering::getTargetNodeName(unsigned Opcode) const { } void -HexagonTargetLowering::validateConstPtrAlignment(SDValue Ptr, const SDLoc &dl, - unsigned NeedAlign) const { +HexagonTargetLowering::validateConstPtrAlignment(SDValue Ptr, Align NeedAlign, + const SDLoc &dl) const { auto *CA = dyn_cast(Ptr); if (!CA) return; unsigned Addr = CA->getZExtValue(); - unsigned HaveAlign = Addr != 0 ? 1u << countTrailingZeros(Addr) : NeedAlign; + Align HaveAlign = + Addr != 0 ? Align(1u << countTrailingZeros(Addr)) : NeedAlign; if (HaveAlign < NeedAlign) { std::string ErrMsg; raw_string_ostream O(ErrMsg); O << "Misaligned constant address: " << format_hex(Addr, 10) - << " has alignment " << HaveAlign - << ", but the memory access requires " << NeedAlign; + << " has alignment " << HaveAlign.value() + << ", but the memory access requires " << NeedAlign.value(); if (DebugLoc DL = dl.getDebugLoc()) DL.print(O << ", at "); report_fatal_error(O.str()); @@ -2900,8 +2901,8 @@ HexagonTargetLowering::LowerLoad(SDValue Op, SelectionDAG &DAG) const { LN = cast(NL.getNode()); } - unsigned ClaimAlign = LN->getAlignment(); - validateConstPtrAlignment(LN->getBasePtr(), dl, ClaimAlign); + Align ClaimAlign = LN->getAlign(); + validateConstPtrAlignment(LN->getBasePtr(), ClaimAlign, dl); // Call LowerUnalignedLoad for all loads, it recognizes loads that // don't need extra aligning. SDValue LU = LowerUnalignedLoad(SDValue(LN, 0), DAG); @@ -2932,12 +2933,11 @@ HexagonTargetLowering::LowerStore(SDValue Op, SelectionDAG &DAG) const { SN = cast(NS.getNode()); } - unsigned ClaimAlign = SN->getAlignment(); - SDValue Ptr = SN->getBasePtr(); - validateConstPtrAlignment(Ptr, dl, ClaimAlign); + Align ClaimAlign = SN->getAlign(); + validateConstPtrAlignment(SN->getBasePtr(), ClaimAlign, dl); MVT StoreTy = SN->getMemoryVT().getSimpleVT(); - unsigned NeedAlign = Subtarget.getTypeAlignment(StoreTy); + Align NeedAlign = Subtarget.getTypeAlignment(StoreTy); if (ClaimAlign < NeedAlign) return expandUnalignedStore(SN, DAG); return SDValue(SN, 0); @@ -2948,8 +2948,8 @@ HexagonTargetLowering::LowerUnalignedLoad(SDValue Op, SelectionDAG &DAG) const { LoadSDNode *LN = cast(Op.getNode()); MVT LoadTy = ty(Op); - unsigned NeedAlign = Subtarget.getTypeAlignment(LoadTy); - unsigned HaveAlign = LN->getAlignment(); + unsigned NeedAlign = Subtarget.getTypeAlignment(LoadTy).value(); + unsigned HaveAlign = LN->getAlign().value(); if (HaveAlign >= NeedAlign) return Op; diff --git a/lib/Target/Hexagon/HexagonISelLowering.h b/lib/Target/Hexagon/HexagonISelLowering.h index 84c4355927b..2e8d78d9185 100644 --- a/lib/Target/Hexagon/HexagonISelLowering.h +++ b/lib/Target/Hexagon/HexagonISelLowering.h @@ -341,8 +341,8 @@ private: void initializeHVXLowering(); unsigned getPreferredHvxVectorAction(MVT VecTy) const; - void validateConstPtrAlignment(SDValue Ptr, const SDLoc &dl, - unsigned NeedAlign) const; + void validateConstPtrAlignment(SDValue Ptr, Align NeedAlign, + const SDLoc &dl) const; std::pair getBaseAndOffset(SDValue Addr) const; diff --git a/lib/Target/Hexagon/HexagonSubtarget.h b/lib/Target/Hexagon/HexagonSubtarget.h index 5d5a3c48858..a4f2e159bf4 100644 --- a/lib/Target/Hexagon/HexagonSubtarget.h +++ b/lib/Target/Hexagon/HexagonSubtarget.h @@ -24,6 +24,7 @@ #include "llvm/CodeGen/ScheduleDAGMutation.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/MC/MCInstrItineraries.h" +#include "llvm/Support/Alignment.h" #include #include #include @@ -288,10 +289,10 @@ public: bool isHVXVectorType(MVT VecTy, bool IncludeBool = false) const; bool isTypeForHVX(Type *VecTy, bool IncludeBool = false) const; - unsigned getTypeAlignment(MVT Ty) const { + Align getTypeAlignment(MVT Ty) const { if (isHVXVectorType(Ty, true)) - return getVectorLength(); - return Ty.getSizeInBits() / 8; + return Align(getVectorLength()); + return Align(std::max(1, Ty.getSizeInBits() / 8)); } unsigned getL1CacheLineSize() const;