ScopInfo: Make getDimensionSize better reflect which dimensions carry sizes

In polly the first dimensions of an array as well as all scalars do not carry
any size information. This commit makes this explicit in the interface of
getDimensionSize. Before this commit getDimensionSize(0) returned the size of
the first dimension that carried a size. After this commit getDimensionSize(i)
will either return the size of dimension 'i' or assert in case 'i' does not
carry a size or does not exist at all.

This very same behaviour was already present in getDimensionSizePw(). This
commit also adds assertions that ensure getDimensionSizePw() is called
appropriately.

llvm-svn: 252607
This commit is contained in:
Tobias Grosser 2015-11-10 14:24:21 +00:00
parent 9d55f19cfa
commit 262538435f
3 changed files with 25 additions and 12 deletions

View File

@ -127,15 +127,25 @@ public:
unsigned getNumberOfDimensions() const { return DimensionSizes.size(); }
/// @brief Return the size of dimension @p dim as SCEV*.
const SCEV *getDimensionSize(unsigned dim) const {
assert(dim < getNumberOfDimensions() && "Invalid dimension");
return DimensionSizes[dim];
//
// Scalars do not have array dimensions and the first dimension of
// a (possibly multi-dimensional) array also does not carry any size
// information.
const SCEV *getDimensionSize(unsigned Dim) const {
assert(Dim > 0 && "Only dimensions larger than zero are sized.");
assert(Dim < getNumberOfDimensions() && "Invalid dimension");
return DimensionSizes[Dim - 1];
}
/// @brief Return the size of dimension @p dim as isl_pw_aff.
__isl_give isl_pw_aff *getDimensionSizePw(unsigned dim) const {
assert(dim < getNumberOfDimensions() && "Invalid dimension");
return isl_pw_aff_copy(DimensionSizesPw[dim - 1]);
//
// Scalars do not have array dimensions and the first dimension of
// a (possibly multi-dimensional) array also does not carry any size
// information.
__isl_give isl_pw_aff *getDimensionSizePw(unsigned Dim) const {
assert(Dim > 0 && "Only dimensions larger than zero are sized.");
assert(Dim < getNumberOfDimensions() && "Invalid dimension");
return isl_pw_aff_copy(DimensionSizesPw[Dim - 1]);
}
/// @brief Get the type of the elements stored in this array.

View File

@ -217,13 +217,16 @@ void ScopArrayInfo::print(raw_ostream &OS, bool SizeAsPwAff) const {
OS.indent(8) << *getElementType() << " " << getName();
if (getNumberOfDimensions() > 0)
OS << "[*]";
for (unsigned u = 0; u + 1 < getNumberOfDimensions(); u++) {
for (unsigned u = 1; u < getNumberOfDimensions(); u++) {
OS << "[";
if (SizeAsPwAff)
OS << " " << DimensionSizesPw[u] << " ";
else
OS << *DimensionSizes[u];
if (SizeAsPwAff) {
auto Size = getDimensionSizePw(u);
OS << " " << Size << " ";
isl_pw_aff_free(Size);
} else {
OS << *getDimensionSize(u);
}
OS << "]";
}

View File

@ -151,7 +151,7 @@ Value *IslExprBuilder::createAccessAddress(isl_ast_expr *Expr) {
if (u + 1 >= e)
break;
const SCEV *DimSCEV = SAI->getDimensionSize(u - 1);
const SCEV *DimSCEV = SAI->getDimensionSize(u);
llvm::ValueToValueMap Map(GlobalMap.begin(), GlobalMap.end());
DimSCEV = SCEVParameterRewriter::rewrite(DimSCEV, SE, Map);