diff --git a/llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h b/llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h --- a/llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h +++ b/llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h @@ -14,7 +14,6 @@ #include "llvm/IR/PassManager.h" namespace llvm { -class TargetTransformInfo; /// Argument promotion pass. /// @@ -27,11 +26,6 @@ public: ArgumentPromotionPass(unsigned MaxElements = 2u) : MaxElements(MaxElements) {} - /// Checks if a type could have padding bytes. - // TODO the function aren't used in the ArgumentPromotionPass anymore and - // should be moved into AttributorAttributes.cpp as the single known user. - static bool isDenselyPacked(Type *Ty, const DataLayout &DL); - PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR); }; diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp --- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -698,44 +698,6 @@ return true; } -bool ArgumentPromotionPass::isDenselyPacked(Type *Ty, const DataLayout &DL) { - // There is no size information, so be conservative. - if (!Ty->isSized()) - return false; - - // If the alloc size is not equal to the storage size, then there are padding - // bytes. For x86_fp80 on x86-64, size: 80 alloc size: 128. - if (DL.getTypeSizeInBits(Ty) != DL.getTypeAllocSizeInBits(Ty)) - return false; - - // FIXME: This isn't the right way to check for padding in vectors with - // non-byte-size elements. - if (VectorType *SeqTy = dyn_cast(Ty)) - return isDenselyPacked(SeqTy->getElementType(), DL); - - // For array types, check for padding within members. - if (ArrayType *SeqTy = dyn_cast(Ty)) - return isDenselyPacked(SeqTy->getElementType(), DL); - - if (!isa(Ty)) - return true; - - // Check for padding within and between elements of a struct. - StructType *StructTy = cast(Ty); - const StructLayout *Layout = DL.getStructLayout(StructTy); - uint64_t StartPos = 0; - for (unsigned I = 0, E = StructTy->getNumElements(); I < E; ++I) { - Type *ElTy = StructTy->getElementType(I); - if (!isDenselyPacked(ElTy, DL)) - return false; - if (StartPos != Layout->getElementOffsetInBits(I)) - return false; - StartPos += DL.getTypeAllocSizeInBits(ElTy); - } - - return true; -} - /// Check if callers and callee agree on how promoted arguments would be /// passed. static bool areTypesABICompatible(ArrayRef Types, const Function &F, diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -36,6 +36,7 @@ #include "llvm/IR/Assumptions.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/GlobalValue.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instruction.h" @@ -51,7 +52,6 @@ #include "llvm/Support/GraphWriter.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/IPO/ArgumentPromotion.h" #include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/ValueMapper.h" #include @@ -180,6 +180,45 @@ } // namespace llvm +/// Checks if a type could have padding bytes. +static bool isDenselyPacked(Type *Ty, const DataLayout &DL) { + // There is no size information, so be conservative. + if (!Ty->isSized()) + return false; + + // If the alloc size is not equal to the storage size, then there are padding + // bytes. For x86_fp80 on x86-64, size: 80 alloc size: 128. + if (DL.getTypeSizeInBits(Ty) != DL.getTypeAllocSizeInBits(Ty)) + return false; + + // FIXME: This isn't the right way to check for padding in vectors with + // non-byte-size elements. + if (VectorType *SeqTy = dyn_cast(Ty)) + return isDenselyPacked(SeqTy->getElementType(), DL); + + // For array types, check for padding within members. + if (ArrayType *SeqTy = dyn_cast(Ty)) + return isDenselyPacked(SeqTy->getElementType(), DL); + + if (!isa(Ty)) + return true; + + // Check for padding within and between elements of a struct. + StructType *StructTy = cast(Ty); + const StructLayout *Layout = DL.getStructLayout(StructTy); + uint64_t StartPos = 0; + for (unsigned I = 0, E = StructTy->getNumElements(); I < E; ++I) { + Type *ElTy = StructTy->getElementType(I); + if (!isDenselyPacked(ElTy, DL)) + return false; + if (StartPos != Layout->getElementOffsetInBits(I)) + return false; + StartPos += DL.getTypeAllocSizeInBits(ElTy); + } + + return true; +} + /// Get pointer operand of memory accessing instruction. If \p I is /// not a memory accessing instruction, return nullptr. If \p AllowVolatile, /// is set to false and the instruction is volatile, return nullptr. @@ -6738,8 +6777,7 @@ // Avoid arguments with padding for now. if (!getIRPosition().hasAttr(Attribute::ByVal) && - !ArgumentPromotionPass::isDenselyPacked(*PrivatizableType, - A.getInfoCache().getDL())) { + !isDenselyPacked(*PrivatizableType, A.getInfoCache().getDL())) { LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] Padding detected\n"); return indicatePessimisticFixpoint(); }