Skip to content

[mlir] Clean up prints with llvm::interleaved. NFC. #136468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions mlir/lib/Analysis/FlatLinearValueConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/InterleavedRange.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>

Expand Down Expand Up @@ -1106,9 +1107,9 @@ IntegerSet FlatLinearConstraints::getAsIntegerSet(MLIRContext *context) const {
}
if (!noLocalRepVars.empty()) {
LLVM_DEBUG({
llvm::dbgs() << "local variables at position(s) ";
llvm::interleaveComma(noLocalRepVars, llvm::dbgs());
llvm::dbgs() << " do not have an explicit representation in:\n";
llvm::dbgs() << "local variables at position(s) "
<< llvm::interleaved(noLocalRepVars)
<< " do not have an explicit representation in:\n";
this->dump();
});
return IntegerSet();
Expand Down
9 changes: 4 additions & 5 deletions mlir/lib/Debug/Observers/ActionLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "mlir/Debug/Observers/ActionLogging.h"
#include "mlir/Debug/BreakpointManager.h"
#include "mlir/IR/Action.h"
#include "llvm/Support/InterleavedRange.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/raw_ostream.h"

Expand Down Expand Up @@ -55,11 +56,9 @@ void ActionLogger::beforeExecute(const ActionActiveStack *action,
action->getAction().print(os);
else
os << action->getAction().getTag();
if (printIRUnits) {
os << " (";
interleaveComma(action->getAction().getContextIRUnits(), os);
os << ")";
}
if (printIRUnits)
os << " (" << llvm::interleaved(action->getAction().getContextIRUnits())
<< ")";
os << "`\n";
}

Expand Down
46 changes: 18 additions & 28 deletions mlir/lib/Dialect/Linalg/TransformOps/GPUHeuristics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/InterleavedRange.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <cmath>
Expand Down Expand Up @@ -44,8 +45,8 @@ transform::gpu::CopyMappingInfo::CopyMappingInfo(MLIRContext *ctx,
"only 1,2,3-D copies are supported for now");

LDBG("START CopyMappingInfo, favorPredication: " << favorPredication);
LLVM_DEBUG(llvm::interleaveComma(copySizes, DBGS() << "--copy shape: ");
llvm::dbgs() << "\n";);
LLVM_DEBUG(DBGS() << "--copy shape: " << llvm::interleaved(copySizes)
<< "\n");

// Greedily find the largest vector size that can be used to copy the most
// minor dimension: we are in the business of filling kMaxVectorLoadBitWidth
Expand All @@ -63,11 +64,10 @@ transform::gpu::CopyMappingInfo::CopyMappingInfo(MLIRContext *ctx,
if (status == Status::Invalid)
return;

LLVM_DEBUG(llvm::interleaveComma(copySizes, DBGS() << "--copy: ");
llvm::dbgs() << "\n"; llvm::interleaveComma(
this->numThreads, DBGS() << "--numThreads: ");
llvm::dbgs() << "\n";);
LDBG("--vectorSize: " << this->vectorSize);
LLVM_DEBUG(DBGS() << "--copy: " << llvm::interleaved(copySizes) << "\n"
<< "--numThreads: " << llvm::interleaved(this->numThreads)
<< "\n"
<< "--vectorSize: " << this->vectorSize << "\n");
assert(this->numThreads.size() == copySizes.size() &&
"compute copy mapping expected same number of threads and copy sizes");

Expand Down Expand Up @@ -158,10 +158,8 @@ static SmallVector<int64_t> maximizeNumThreads(ArrayRef<int64_t> sizes,
int64_t localBest = factor * product(nestedThreadsPerDim);
if (localBest > best && localBest <= maxNumThreads) {
LDBG(indent << "new localBest: " << localBest);
LLVM_DEBUG(
llvm::interleaveComma(nestedThreadsPerDim,
DBGS() << indent << "nestedThreadsPerDim: ");
llvm::dbgs() << "\n";);
LDBG(indent << "nestedThreadsPerDim: "
<< llvm::interleaved(nestedThreadsPerDim));
localThreadsPerDim.clear();
localThreadsPerDim.push_back(factor);
llvm::append_range(localThreadsPerDim, nestedThreadsPerDim);
Expand All @@ -170,10 +168,7 @@ static SmallVector<int64_t> maximizeNumThreads(ArrayRef<int64_t> sizes,
}

LDBG(indent << "found globalBest: " << best);
LLVM_DEBUG(llvm::interleaveComma(localThreadsPerDim,
DBGS() << indent << "numThreads: ");
llvm::dbgs() << "\n";);

LDBG(indent << "numThreads: " << llvm::interleaved(localThreadsPerDim));
return localThreadsPerDim;
}

Expand Down Expand Up @@ -231,10 +226,8 @@ transform::gpu::CopyMappingInfo::inferNumThreadsImpl(
SmallVector<int64_t> inferredNumThreads =
maximizeNumThreads(scaledSizes, 0, totalNumThreads);

LLVM_DEBUG(llvm::interleaveComma(inferredNumThreads,
DBGS() << "inferred numThreads: ");
llvm::dbgs() << "\n";
LDBG("computed actualVectorSize: " << desiredVectorSize););
LDBG("inferred numThreads: " << llvm::interleaved(inferredNumThreads));
LDBG("computed actualVectorSize: " << desiredVectorSize);

// Corner case: we cannot use more threads than available. If the dimension of
// the copy is so bad it is because higher-level tiling did not do its job, we
Expand All @@ -255,13 +248,10 @@ transform::gpu::CopyMappingInfo::inferNumThreadsImpl(
}

void transform::gpu::CopyMappingInfo::print(llvm::raw_ostream &os) const {
os << "MappingInfo{";
os << "CopyMappingInfo: ";
os << "valid: " << (status != Status::Invalid) << ", ";
os << "vectorSize: " << vectorSize << ", ";
llvm::interleaveComma(numThreads, os << ", numThreads: {");
llvm::interleaveComma(smallestBoundingTileSizes,
os << "}, smallestBoundingTileSizes: {");
llvm::interleaveComma(threadMapping, os << "}, threadMapping: {");
os << "}}";
os << "MappingInfo{"
<< "CopyMappingInfo: " << "valid: " << (status != Status::Invalid) << ", "
<< "vectorSize: " << vectorSize << ", numThreads: {"
<< llvm::interleaved(numThreads) << "}, smallestBoundingTileSizes: {"
<< llvm::interleaved(smallestBoundingTileSizes) << "}, threadMapping: {"
<< llvm::interleaved(threadMapping) << "}}";
}
14 changes: 6 additions & 8 deletions mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "mlir/Interfaces/FunctionImplementation.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/InterleavedRange.h"

using namespace mlir;

Expand Down Expand Up @@ -219,14 +220,11 @@ LogicalResult transform::MatchStructuredBodyOp::verify() {
getElementwise() + getContraction().has_value();

if (numOptions > 1) {
std::string attributeNames;
llvm::raw_string_ostream os(attributeNames);
llvm::interleaveComma(ArrayRef<StringAttr>{getReductionPositionAttrName(),
getPassthroughAttrName(),
getElementwiseAttrName(),
getContractionAttrName()},
os);
return emitOpError() << "only one of {" << attributeNames << "} is allowed";
StringAttr attributeNames[] = {
getReductionPositionAttrName(), getPassthroughAttrName(),
getElementwiseAttrName(), getContractionAttrName()};
return emitOpError() << "only one of {" << llvm::interleaved(attributeNames)
<< "} is allowed";
}

if (std::optional<ArrayAttr> contractionAttr = getContraction()) {
Expand Down
3 changes: 2 additions & 1 deletion mlir/lib/Dialect/Linalg/TransformOps/Syntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "mlir/Dialect/Linalg/TransformOps/Syntax.h"
#include "mlir/IR/OpImplementation.h"
#include "llvm/Support/InterleavedRange.h"

using namespace mlir;

Expand Down Expand Up @@ -67,7 +68,7 @@ void mlir::printSemiFunctionType(OpAsmPrinter &printer, Operation *op,

if (resultType.size() > 1)
printer << "(";
llvm::interleaveComma(resultType, printer.getStream());
printer << llvm::interleaved(resultType);
if (resultType.size() > 1)
printer << ")";
}
Expand Down
5 changes: 2 additions & 3 deletions mlir/lib/IR/ExtensibleDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/OperationSupport.h"
#include "mlir/IR/StorageUniquerSupport.h"
#include "llvm/Support/InterleavedRange.h"

using namespace mlir;

Expand Down Expand Up @@ -47,9 +48,7 @@ static void typeOrAttrPrinter(AsmPrinter &printer, ArrayRef<Attribute> params) {
if (params.empty())
return;

printer << "<";
interleaveComma(params, printer.getStream());
printer << ">";
printer << "<" << llvm::interleaved(params) << ">";
}

//===----------------------------------------------------------------------===//
Expand Down
5 changes: 3 additions & 2 deletions mlir/lib/IR/PDL/PDLPatternMatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "mlir/IR/Iterators.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/RegionKindInterface.h"
#include "llvm/Support/InterleavedRange.h"

using namespace mlir;

Expand All @@ -34,13 +35,13 @@ void PDLValue::print(raw_ostream &os) const {
os << cast<Type>();
break;
case Kind::TypeRange:
llvm::interleaveComma(cast<TypeRange>(), os);
os << llvm::interleaved(cast<TypeRange>());
break;
case Kind::Value:
os << cast<Value>();
break;
case Kind::ValueRange:
llvm::interleaveComma(cast<ValueRange>(), os);
os << llvm::interleaved(cast<ValueRange>());
break;
}
}
Expand Down
19 changes: 9 additions & 10 deletions mlir/lib/Interfaces/InferTypeOpInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Matchers.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/InterleavedRange.h"

using namespace mlir;

Expand Down Expand Up @@ -176,9 +177,8 @@ void ShapeAdaptor::dump() const {
return "?";
return llvm::formatv("{0}", dim).str();
});
llvm::errs() << "rank = " << getRank() << " dims = [";
llvm::interleave(mapped, llvm::errs(), "x");
llvm::errs() << "]\n";
llvm::errs() << "rank = " << getRank()
<< " dims = " << llvm::interleaved_array(mapped, "x") << "\n";
}

ShapeAdaptor ValueShapeRange::getValueAsShape(int index) {
Expand Down Expand Up @@ -243,13 +243,12 @@ LogicalResult mlir::detail::verifyInferredResultTypes(Operation *op) {
void mlir::detail::reportFatalInferReturnTypesError(OperationState &state) {
std::string buffer;
llvm::raw_string_ostream os(buffer);
os << "Failed to infer result type(s):\n";
os << "\"" << state.name << "\"(...) ";
os << state.attributes.getDictionary(state.location.getContext());
os << " : (";
llvm::interleaveComma(state.operands, os,
[&](Value val) { os << val.getType(); });
os << ") -> ( ??? )";
os << "Failed to infer result type(s):\n"
<< "\"" << state.name << "\"(...) "
<< state.attributes.getDictionary(state.location.getContext()) << " : ("
<< llvm::interleaved(llvm::map_range(
state.operands, [](Value val) { return val.getType(); }))
<< ") -> ( ??? )";
emitRemark(state.location, "location of op");
llvm::report_fatal_error(llvm::StringRef(buffer));
}
Loading