diff --git a/mlir/include/mlir/Dialect/Affine/Utils.h b/mlir/include/mlir/Dialect/Affine/Utils.h --- a/mlir/include/mlir/Dialect/Affine/Utils.h +++ b/mlir/include/mlir/Dialect/Affine/Utils.h @@ -319,6 +319,8 @@ Value linearIndex, ArrayRef basis); +template +bool hasNoInterveningEffect(Operation *start, T memOp); } // namespace mlir #endif // MLIR_DIALECT_AFFINE_UTILS_H diff --git a/mlir/lib/Dialect/Affine/Utils/Utils.cpp b/mlir/lib/Dialect/Affine/Utils/Utils.cpp --- a/mlir/lib/Dialect/Affine/Utils/Utils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/Utils.cpp @@ -658,7 +658,7 @@ /// will check if there is no write to the memory between `start` and `memOp` /// that would change the read within `memOp`. template -static bool hasNoInterveningEffect(Operation *start, T memOp) { +bool mlir::hasNoInterveningEffect(Operation *start, T memOp) { auto isLocallyAllocated = [](Value memref) { auto *defOp = memref.getDefiningOp(); return defOp && hasSingleEffect(defOp, memref); @@ -874,7 +874,7 @@ // 3. Ensure there is no intermediate operation which could replace the // value in memory. - if (!hasNoInterveningEffect(storeOp, loadOp)) + if (!mlir::hasNoInterveningEffect(storeOp, loadOp)) continue; // We now have a candidate for forwarding. @@ -901,6 +901,10 @@ return success(); } +template bool mlir::hasNoInterveningEffect( + mlir::Operation *, mlir::AffineReadOpInterface); + // This attempts to find stores which have no impact on the final result. // A writing op writeA will be eliminated if there exists an op writeB if // 1) writeA and writeB have mathematically equivalent affine access functions. @@ -937,7 +941,7 @@ // There cannot be an operation which reads from memory between // the two writes. - if (!hasNoInterveningEffect(writeA, writeB)) + if (!mlir::hasNoInterveningEffect(writeA, writeB)) continue; opsToErase.push_back(writeA); @@ -973,8 +977,8 @@ continue; // 3. There is no write between loadA and loadB. - if (!hasNoInterveningEffect(loadB.getOperation(), - loadA)) + if (!mlir::hasNoInterveningEffect( + loadB.getOperation(), loadA)) continue; // Check if two values have the same shape. This is needed for affine vector