@@ -38,7 +38,7 @@ mlir::getReassociationIndicesForCollapse(ArrayRef<int64_t> sourceShape,
3838 SmallVector<ReassociationIndices, 4 > reassociationMap;
3939 reassociationMap.reserve (numTargetDims);
4040
41- unsigned sourceDim = 0 , targetDim = 0 ;
41+ unsigned sourceDimIdx = 0 , targetDimIdx = 0 ;
4242 // Source dimensions iteration logic for static target dimensions.
4343 // FIXME: Instead of lambda-capturing this function's source shape index "in
4444 // place", consider refactoring this into a separate function.
@@ -48,12 +48,12 @@ mlir::getReassociationIndicesForCollapse(ArrayRef<int64_t> sourceShape,
4848 ReassociationIndices resultIndices;
4949 int64_t prodOfCollapsedDims = 1 ;
5050 bool reachedTargetDimSize = false ;
51- for (; sourceDim < numSourceDims; ++sourceDim ) {
51+ for (; sourceDimIdx < numSourceDims; ++sourceDimIdx ) {
5252 // Source shape cannot be dynamic if the target dim is static.
53- if (sourceShape[sourceDim ] == ShapedType::kDynamic )
53+ if (sourceShape[sourceDimIdx ] == ShapedType::kDynamic )
5454 return failure ();
55- prodOfCollapsedDims *= sourceShape[sourceDim ];
56- resultIndices.push_back (sourceDim );
55+ prodOfCollapsedDims *= sourceShape[sourceDimIdx ];
56+ resultIndices.push_back (sourceDimIdx );
5757 if (prodOfCollapsedDims > targetShape && !mayHaveOffset)
5858 return failure ();
5959 while (prodOfCollapsedDims > targetShape) {
@@ -64,7 +64,7 @@ mlir::getReassociationIndicesForCollapse(ArrayRef<int64_t> sourceShape,
6464 }
6565 if (prodOfCollapsedDims == targetShape) {
6666 reachedTargetDimSize = true ;
67- ++sourceDim ;
67+ ++sourceDimIdx ;
6868 break ;
6969 }
7070 }
@@ -80,29 +80,29 @@ mlir::getReassociationIndicesForCollapse(ArrayRef<int64_t> sourceShape,
8080 bool mapConsecutiveDynDims) -> FailureOr<ReassociationIndices> {
8181 ReassociationIndices resultIndices;
8282 bool foundFirstDynamic = false ;
83- while (sourceDim < numSourceDims) {
84- if (sourceShape[sourceDim ] == ShapedType::kDynamic ) {
83+ while (sourceDimIdx < numSourceDims) {
84+ if (sourceShape[sourceDimIdx ] == ShapedType::kDynamic ) {
8585 if (foundFirstDynamic && !mapConsecutiveDynDims)
8686 break ;
8787 foundFirstDynamic |= true ;
8888 } else {
8989 if (foundFirstDynamic)
9090 break ;
91- else if (sourceShape[sourceDim ] > 1 && !allowStaticNonOnes)
91+ else if (sourceShape[sourceDimIdx ] > 1 && !allowStaticNonOnes)
9292 return failure ();
9393 }
94- resultIndices.push_back (sourceDim ++);
94+ resultIndices.push_back (sourceDimIdx ++);
9595 }
9696 if (!foundFirstDynamic)
9797 return failure ();
9898 return resultIndices;
9999 };
100100 // Iterate over target shape.
101101 bool wasLastDimDynamic = false ;
102- for (; targetDim < numTargetDims; ++targetDim ) {
103- int64_t currTargetShape = targetShape[targetDim ];
102+ for (; targetDimIdx < numTargetDims; ++targetDimIdx ) {
103+ int64_t currTargetShape = targetShape[targetDimIdx ];
104104 if (currTargetShape != ShapedType::kDynamic ) {
105- unsigned sourceDimAtStart = sourceDim ;
105+ unsigned sourceDimAtStart = sourceDimIdx ;
106106 auto indices = collectSourceIndicesForStaticTargetDim (
107107 currTargetShape, /* mayHaveOffset=*/ wasLastDimDynamic);
108108 if (failed (indices))
@@ -118,8 +118,9 @@ mlir::getReassociationIndicesForCollapse(ArrayRef<int64_t> sourceShape,
118118 continue ;
119119 }
120120
121- bool isNextDimDynamic = targetDim + 1 < numTargetDims &&
122- targetShape[targetDim + 1 ] == ShapedType::kDynamic ;
121+ bool isNextDimDynamic =
122+ targetDimIdx + 1 < numTargetDims &&
123+ targetShape[targetDimIdx + 1 ] == ShapedType::kDynamic ;
123124 auto indices = collectSourceIndicesForDynamicTargetDim (
124125 /* allowStaticNonOnes=*/ !wasLastDimDynamic,
125126 /* mapConsecutiveDynDims=*/ !wasLastDimDynamic && !isNextDimDynamic);
@@ -130,9 +131,9 @@ mlir::getReassociationIndicesForCollapse(ArrayRef<int64_t> sourceShape,
130131 }
131132 // Now that we've mapped all the target dimensions, process any remaining
132133 // entries in the source shape explicitly.
133- for (; sourceDim < numSourceDims; sourceDim ++) {
134- const bool isOne = sourceShape[sourceDim ] == 1 ,
135- isDynamic = sourceShape[sourceDim ] == ShapedType::kDynamic ;
134+ for (; sourceDimIdx < numSourceDims; sourceDimIdx ++) {
135+ const bool isOne = sourceShape[sourceDimIdx ] == 1 ,
136+ isDynamic = sourceShape[sourceDimIdx ] == ShapedType::kDynamic ;
136137 if (targetShape.empty ()) {
137138 if (!isOne && !isDynamic)
138139 return std::nullopt ;
@@ -145,7 +146,7 @@ mlir::getReassociationIndicesForCollapse(ArrayRef<int64_t> sourceShape,
145146 if (!wasLastDimDynamic && !isOne)
146147 return std::nullopt ;
147148 assert (!reassociationMap.empty ());
148- reassociationMap.back ().push_back (sourceDim );
149+ reassociationMap.back ().push_back (sourceDimIdx );
149150 }
150151 return reassociationMap;
151152}
0 commit comments