[Mlir-commits] [mlir] b4fa6d3 - Switch the CallbackOstream wrapper in the MLIR C API to an Unbuffered stream
Mehdi Amini
llvmlistbot at llvm.org
Tue Nov 3 22:37:11 PST 2020
Author: Mehdi Amini
Date: 2020-11-04T06:36:32Z
New Revision: b4fa6d3e13ef66baec8c2610c5ce39f3e470da12
URL: https://github.com/llvm/llvm-project/commit/b4fa6d3e13ef66baec8c2610c5ce39f3e470da12
DIFF: https://github.com/llvm/llvm-project/commit/b4fa6d3e13ef66baec8c2610c5ce39f3e470da12.diff
LOG: Switch the CallbackOstream wrapper in the MLIR C API to an Unbuffered stream
This delegate the control of the buffering to the user of the API. This
seems like a safer option as messages are immediately propagated to the
user, which may lead to less surprising behavior during debugging for
instance.
In terms of performance, a user can add a buffered stream on the other
side of the callback.
Differential Revision: https://reviews.llvm.org/D90726
Added:
Modified:
mlir/include/mlir/CAPI/Utils.h
mlir/lib/CAPI/IR/AffineExpr.cpp
mlir/lib/CAPI/IR/AffineMap.cpp
mlir/lib/CAPI/IR/Diagnostics.cpp
mlir/lib/CAPI/IR/IR.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/CAPI/Utils.h b/mlir/include/mlir/CAPI/Utils.h
index 022f09df6a5d..07bf4167a963 100644
--- a/mlir/include/mlir/CAPI/Utils.h
+++ b/mlir/include/mlir/CAPI/Utils.h
@@ -28,7 +28,8 @@ class CallbackOstream : public llvm::raw_ostream {
public:
CallbackOstream(std::function<void(const char *, intptr_t, void *)> callback,
void *opaqueData)
- : callback(callback), opaqueData(opaqueData), pos(0u) {}
+ : raw_ostream(/*unbuffered=*/true), callback(callback),
+ opaqueData(opaqueData), pos(0u) {}
void write_impl(const char *ptr, size_t size) override {
callback(ptr, size, opaqueData);
diff --git a/mlir/lib/CAPI/IR/AffineExpr.cpp b/mlir/lib/CAPI/IR/AffineExpr.cpp
index 53954b78a81e..a4dd6cc4ebf5 100644
--- a/mlir/lib/CAPI/IR/AffineExpr.cpp
+++ b/mlir/lib/CAPI/IR/AffineExpr.cpp
@@ -25,7 +25,6 @@ void mlirAffineExprPrint(MlirAffineExpr affineExpr, MlirStringCallback callback,
void *userData) {
mlir::detail::CallbackOstream stream(callback, userData);
unwrap(affineExpr).print(stream);
- stream.flush();
}
void mlirAffineExprDump(MlirAffineExpr affineExpr) {
diff --git a/mlir/lib/CAPI/IR/AffineMap.cpp b/mlir/lib/CAPI/IR/AffineMap.cpp
index 6a87c269a421..f8e78bcd46b2 100644
--- a/mlir/lib/CAPI/IR/AffineMap.cpp
+++ b/mlir/lib/CAPI/IR/AffineMap.cpp
@@ -29,7 +29,6 @@ void mlirAffineMapPrint(MlirAffineMap affineMap, MlirStringCallback callback,
void *userData) {
mlir::detail::CallbackOstream stream(callback, userData);
unwrap(affineMap).print(stream);
- stream.flush();
}
void mlirAffineMapDump(MlirAffineMap affineMap) { unwrap(affineMap).dump(); }
diff --git a/mlir/lib/CAPI/IR/Diagnostics.cpp b/mlir/lib/CAPI/IR/Diagnostics.cpp
index 9595446f9d5a..9cf422bb1b4f 100644
--- a/mlir/lib/CAPI/IR/Diagnostics.cpp
+++ b/mlir/lib/CAPI/IR/Diagnostics.cpp
@@ -19,7 +19,6 @@ void mlirDiagnosticPrint(MlirDiagnostic diagnostic, MlirStringCallback callback,
void *userData) {
detail::CallbackOstream stream(callback, userData);
unwrap(diagnostic).print(stream);
- stream.flush();
}
MlirLocation mlirDiagnosticGetLocation(MlirDiagnostic diagnostic) {
diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp
index 101e963159c9..ad240fc9d759 100644
--- a/mlir/lib/CAPI/IR/IR.cpp
+++ b/mlir/lib/CAPI/IR/IR.cpp
@@ -126,7 +126,6 @@ void mlirLocationPrint(MlirLocation location, MlirStringCallback callback,
void *userData) {
detail::CallbackOstream stream(callback, userData);
unwrap(location).print(stream);
- stream.flush();
}
/* ========================================================================== */
@@ -325,14 +324,12 @@ void mlirOperationPrint(MlirOperation op, MlirStringCallback callback,
void *userData) {
detail::CallbackOstream stream(callback, userData);
unwrap(op)->print(stream);
- stream.flush();
}
void mlirOperationPrintWithFlags(MlirOperation op, MlirOpPrintingFlags flags,
MlirStringCallback callback, void *userData) {
detail::CallbackOstream stream(callback, userData);
unwrap(op)->print(stream, *unwrap(flags));
- stream.flush();
}
void mlirOperationDump(MlirOperation op) { return unwrap(op)->dump(); }
@@ -476,7 +473,6 @@ void mlirBlockPrint(MlirBlock block, MlirStringCallback callback,
void *userData) {
detail::CallbackOstream stream(callback, userData);
unwrap(block)->print(stream);
- stream.flush();
}
/* ========================================================================== */
@@ -523,7 +519,6 @@ void mlirValuePrint(MlirValue value, MlirStringCallback callback,
void *userData) {
detail::CallbackOstream stream(callback, userData);
unwrap(value).print(stream);
- stream.flush();
}
/* ========================================================================== */
@@ -543,7 +538,6 @@ int mlirTypeEqual(MlirType t1, MlirType t2) { return unwrap(t1) == unwrap(t2); }
void mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData) {
detail::CallbackOstream stream(callback, userData);
unwrap(type).print(stream);
- stream.flush();
}
void mlirTypeDump(MlirType type) { unwrap(type).dump(); }
@@ -572,7 +566,6 @@ void mlirAttributePrint(MlirAttribute attr, MlirStringCallback callback,
void *userData) {
detail::CallbackOstream stream(callback, userData);
unwrap(attr).print(stream);
- stream.flush();
}
void mlirAttributeDump(MlirAttribute attr) { unwrap(attr).dump(); }
More information about the Mlir-commits
mailing list