Split ScopArrayInfo::updateSizes into two functions

The former ScopArrayInfo::updateSizes was implicitly divided into an
  updateElementType and an updateSizes. Now this partitioning is
  explicit.

llvm-svn: 260860
This commit is contained in:
Johannes Doerfert 2016-02-14 22:31:39 +00:00
parent 965edde695
commit 3ff2221cfc
2 changed files with 29 additions and 19 deletions

View File

@ -234,6 +234,16 @@ public:
ArrayRef<const SCEV *> DimensionSizes, enum MemoryKind Kind,
const DataLayout &DL, Scop *S);
/// @brief Update the element type of the ScopArrayInfo object.
///
/// Memory accesses referencing this ScopArrayInfo object may use
/// different element sizes. This function ensures the canonical element type
/// stored is small enough to model accesses to the current element type as
/// well as to @p NewElementType.
///
/// @param NewElementType An element type that is used to access this array.
void updateElementType(Type *NewElementType);
/// @brief Update the sizes of the ScopArrayInfo object.
///
/// A ScopArrayInfo object may be created without all outer dimensions being
@ -241,15 +251,10 @@ public:
/// this ScopArrayInfo object. It verifies that sizes are compatible and adds
/// additional outer array dimensions, if needed.
///
/// Similarly, memory accesses referencing this ScopArrayInfo object may use
/// different element sizes. This function ensures the canonical element type
/// stored is small enough to model all memory accesses.
///
/// @param Sizes A vector of array sizes where the rightmost array
/// sizes need to match the innermost array sizes already
/// defined in SAI.
/// @param ElementType The element type of this memory access.
bool updateSizes(ArrayRef<const SCEV *> Sizes, Type *ElementType);
bool updateSizes(ArrayRef<const SCEV *> Sizes);
/// @brief Destructor to free the isl id of the base pointer.
~ScopArrayInfo();

View File

@ -182,7 +182,7 @@ ScopArrayInfo::ScopArrayInfo(Value *BasePtr, Type *ElementType, isl_ctx *Ctx,
getIslCompatibleName("MemRef_", BasePtr, Kind == MK_PHI ? "__phi" : "");
Id = isl_id_alloc(Ctx, BasePtrName.c_str(), this);
updateSizes(Sizes, ElementType);
updateSizes(Sizes);
BasePtrOriginSAI = identifyBasePtrOriginSAI(S, BasePtr);
if (BasePtrOriginSAI)
const_cast<ScopArrayInfo *>(BasePtrOriginSAI)->addDerivedSAI(this);
@ -195,21 +195,25 @@ __isl_give isl_space *ScopArrayInfo::getSpace() const {
return Space;
}
bool ScopArrayInfo::updateSizes(ArrayRef<const SCEV *> NewSizes,
Type *NewElementType) {
void ScopArrayInfo::updateElementType(Type *NewElementType) {
if (NewElementType == ElementType)
return;
auto OldElementSize = DL.getTypeAllocSizeInBits(ElementType);
auto NewElementSize = DL.getTypeAllocSizeInBits(NewElementType);
if (NewElementSize != OldElementSize) {
if (NewElementSize % OldElementSize == 0 &&
NewElementSize < OldElementSize) {
ElementType = NewElementType;
} else {
auto GCD = GreatestCommonDivisor64(NewElementSize, OldElementSize);
ElementType = IntegerType::get(ElementType->getContext(), GCD);
}
}
if (NewElementSize == OldElementSize)
return;
if (NewElementSize % OldElementSize == 0 && NewElementSize < OldElementSize) {
ElementType = NewElementType;
} else {
auto GCD = GreatestCommonDivisor64(NewElementSize, OldElementSize);
ElementType = IntegerType::get(ElementType->getContext(), GCD);
}
}
bool ScopArrayInfo::updateSizes(ArrayRef<const SCEV *> NewSizes) {
int SharedDims = std::min(NewSizes.size(), DimensionSizes.size());
int ExtraDimsNew = NewSizes.size() - SharedDims;
int ExtraDimsOld = DimensionSizes.size() - SharedDims;
@ -3055,9 +3059,10 @@ Scop::getOrCreateScopArrayInfo(Value *BasePtr, Type *ElementType,
SAI.reset(new ScopArrayInfo(BasePtr, ElementType, getIslCtx(), Sizes, Kind,
DL, this));
} else {
SAI->updateElementType(ElementType);
// In case of mismatching array sizes, we bail out by setting the run-time
// context to false.
if (!SAI->updateSizes(Sizes, ElementType))
if (!SAI->updateSizes(Sizes))
invalidate(DELINEARIZATION, DebugLoc());
}
return SAI.get();