[Mlir-commits] [mlir] [mlir][EmitC] Refactor MLIR Translate To Cpp (PR #84973)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Mar 12 12:03:11 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 2a3068455716a1a37da9155d4d96107901bba4a8 192078cde4a203ff7a52f4c5b2aa1a1ecff8c6b3 -- mlir/include/mlir/Target/Cpp/CppTranslationInterface.h mlir/include/mlir/Target/Cpp/CppTranslationUtils.h mlir/include/mlir/Target/Cpp/Dialect/All.h mlir/include/mlir/Target/Cpp/Dialect/Builtin/BuiltinToCppTranslation.h mlir/include/mlir/Target/Cpp/Dialect/ControlFlow/ControlFlowToCppTranslation.h mlir/include/mlir/Target/Cpp/Dialect/EmitC/EmitCToCppTranslation.h mlir/include/mlir/Target/Cpp/Dialect/Func/FuncToCppTranslation.h mlir/include/mlir/Target/Cpp/TranslateToCpp.h mlir/lib/Target/Cpp/CppTranslationUtils.cpp mlir/lib/Target/Cpp/Dialect/Builtin/BuiltinToCppTranslation.cpp mlir/lib/Target/Cpp/Dialect/ControlFlow/ControlFlowToCppTranslation.cpp mlir/lib/Target/Cpp/Dialect/EmitC/EmitCToCppTranslation.cpp mlir/lib/Target/Cpp/Dialect/Func/FuncToCppTranslation.cpp mlir/include/mlir/Target/Cpp/CppEmitter.h mlir/lib/Target/Cpp/TranslateRegistration.cpp mlir/lib/Target/Cpp/TranslateToCpp.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/mlir/include/mlir/Target/Cpp/CppTranslationUtils.h b/mlir/include/mlir/Target/Cpp/CppTranslationUtils.h
index 4ca777fa90..be41a4e651 100644
--- a/mlir/include/mlir/Target/Cpp/CppTranslationUtils.h
+++ b/mlir/include/mlir/Target/Cpp/CppTranslationUtils.h
@@ -54,7 +54,6 @@ inline LogicalResult interleaveCommaWithError(const Container &c,
return interleaveWithError(c.begin(), c.end(), eachFn, [&]() { os << ", "; });
}
-
/// Determine whether expression \p expressionOp should be emitted inline, i.e.
/// as part of its user. This function recommends inlining of any expressions
/// that can be inlined unless it is used by another expression, under the
diff --git a/mlir/lib/Target/Cpp/CppTranslationUtils.cpp b/mlir/lib/Target/Cpp/CppTranslationUtils.cpp
index b455f5e9f7..25a4f236e5 100644
--- a/mlir/lib/Target/Cpp/CppTranslationUtils.cpp
+++ b/mlir/lib/Target/Cpp/CppTranslationUtils.cpp
@@ -42,7 +42,7 @@ bool shouldBeInlined(emitc::ExpressionOp expressionOp) {
// ! constant, binary and unart op are currently only used by emitc translation
LogicalResult printConstantOp(CppEmitter &emitter, Operation *operation,
- Attribute value) {
+ Attribute value) {
OpResult result = operation->getResult(0);
// Only emit an assignment as the variable was already declared when printing
@@ -73,9 +73,8 @@ LogicalResult printConstantOp(CppEmitter &emitter, Operation *operation,
return emitter.emitAttribute(operation->getLoc(), value);
}
-LogicalResult printBinaryOperation(CppEmitter &emitter,
- Operation *operation,
- StringRef binaryOperator) {
+LogicalResult printBinaryOperation(CppEmitter &emitter, Operation *operation,
+ StringRef binaryOperator) {
raw_ostream &os = emitter.ostream();
if (failed(emitter.emitAssignPrefix(*operation)))
@@ -92,9 +91,8 @@ LogicalResult printBinaryOperation(CppEmitter &emitter,
return success();
}
-LogicalResult printUnaryOperation(CppEmitter &emitter,
- Operation *operation,
- StringRef unaryOperator) {
+LogicalResult printUnaryOperation(CppEmitter &emitter, Operation *operation,
+ StringRef unaryOperator) {
raw_ostream &os = emitter.ostream();
if (failed(emitter.emitAssignPrefix(*operation)))
@@ -109,7 +107,7 @@ LogicalResult printUnaryOperation(CppEmitter &emitter,
}
LogicalResult printCallOperation(CppEmitter &emitter, Operation *callOp,
- StringRef callee) {
+ StringRef callee) {
if (failed(emitter.emitAssignPrefix(*callOp)))
return failure();
@@ -121,9 +119,8 @@ LogicalResult printCallOperation(CppEmitter &emitter, Operation *callOp,
return success();
}
-LogicalResult printFunctionArgs(CppEmitter &emitter,
- Operation *functionOp,
- ArrayRef<Type> arguments) {
+LogicalResult printFunctionArgs(CppEmitter &emitter, Operation *functionOp,
+ ArrayRef<Type> arguments) {
raw_indented_ostream &os = emitter.ostream();
return (
@@ -132,9 +129,8 @@ LogicalResult printFunctionArgs(CppEmitter &emitter,
}));
}
-LogicalResult printFunctionArgs(CppEmitter &emitter,
- Operation *functionOp,
- Region::BlockArgListType arguments) {
+LogicalResult printFunctionArgs(CppEmitter &emitter, Operation *functionOp,
+ Region::BlockArgListType arguments) {
raw_indented_ostream &os = emitter.ostream();
return (interleaveCommaWithError(
@@ -144,9 +140,8 @@ LogicalResult printFunctionArgs(CppEmitter &emitter,
}));
}
-LogicalResult printFunctionBody(CppEmitter &emitter,
- Operation *functionOp,
- Region::BlockListType &blocks) {
+LogicalResult printFunctionBody(CppEmitter &emitter, Operation *functionOp,
+ Region::BlockListType &blocks) {
raw_indented_ostream &os = emitter.ostream();
os.indent();
@@ -221,5 +216,4 @@ LogicalResult printFunctionBody(CppEmitter &emitter,
return success();
}
-
#endif // MLIR_TARGET_CPP_CPPTRANSLATIONUTILS_CPP
diff --git a/mlir/lib/Target/Cpp/Dialect/EmitC/EmitCToCppTranslation.cpp b/mlir/lib/Target/Cpp/Dialect/EmitC/EmitCToCppTranslation.cpp
index 1c1e2a03b3..fa27d42b58 100644
--- a/mlir/lib/Target/Cpp/Dialect/EmitC/EmitCToCppTranslation.cpp
+++ b/mlir/lib/Target/Cpp/Dialect/EmitC/EmitCToCppTranslation.cpp
@@ -444,7 +444,6 @@ static LogicalResult printOperation(CppEmitter &emitter,
return success();
}
-
static LogicalResult printOperation(CppEmitter &emitter,
emitc::DeclareFuncOp declareFuncOp) {
CppEmitter::Scope scope(emitter);
@@ -487,19 +486,20 @@ public:
bool trailingSemicolon) const final {
LogicalResult status =
llvm::TypeSwitch<Operation *, LogicalResult>(op)
- // EmitC ops.
- .Case<emitc::AddOp, emitc::ApplyOp, emitc::AssignOp,
- emitc::BitwiseAndOp, emitc::BitwiseLeftShiftOp,
- emitc::BitwiseNotOp, emitc::BitwiseOrOp,
- emitc::BitwiseRightShiftOp, emitc::BitwiseXorOp, emitc::CallOp,
- emitc::CallOpaqueOp, emitc::CastOp, emitc::CmpOp,
- emitc::ConstantOp, emitc::DeclareFuncOp, emitc::DivOp,
- emitc::ExpressionOp, emitc::ForOp, emitc::FuncOp, emitc::IfOp,
- emitc::IncludeOp, emitc::LogicalAndOp, emitc::LogicalNotOp,
- emitc::LogicalOrOp, emitc::MulOp, emitc::RemOp, emitc::ReturnOp,
- emitc::SubOp, emitc::UnaryMinusOp, emitc::UnaryPlusOp,
- emitc::VariableOp, emitc::VerbatimOp>(
- [&](auto op) { return printOperation(cppEmitter, op); })
+ // EmitC ops.
+ .Case<emitc::AddOp, emitc::ApplyOp, emitc::AssignOp,
+ emitc::BitwiseAndOp, emitc::BitwiseLeftShiftOp,
+ emitc::BitwiseNotOp, emitc::BitwiseOrOp,
+ emitc::BitwiseRightShiftOp, emitc::BitwiseXorOp,
+ emitc::CallOp, emitc::CallOpaqueOp, emitc::CastOp,
+ emitc::CmpOp, emitc::ConstantOp, emitc::DeclareFuncOp,
+ emitc::DivOp, emitc::ExpressionOp, emitc::ForOp,
+ emitc::FuncOp, emitc::IfOp, emitc::IncludeOp,
+ emitc::LogicalAndOp, emitc::LogicalNotOp, emitc::LogicalOrOp,
+ emitc::MulOp, emitc::RemOp, emitc::ReturnOp, emitc::SubOp,
+ emitc::UnaryMinusOp, emitc::UnaryPlusOp, emitc::VariableOp,
+ emitc::VerbatimOp>(
+ [&](auto op) { return printOperation(cppEmitter, op); })
.Case<emitc::LiteralOp>([&](auto op) { return success(); })
.Default([&](Operation *) {
return op->emitOpError("unable to find printer for op")
diff --git a/mlir/lib/Target/Cpp/TranslateRegistration.cpp b/mlir/lib/Target/Cpp/TranslateRegistration.cpp
index 91385c38ea..e8af37292b 100644
--- a/mlir/lib/Target/Cpp/TranslateRegistration.cpp
+++ b/mlir/lib/Target/Cpp/TranslateRegistration.cpp
@@ -32,9 +32,8 @@ void registerToCppTranslation() {
TranslateFromMLIRRegistration reg(
"mlir-to-cpp", "translate from mlir to cpp",
[](Operation *op, raw_ostream &output) {
- return translateToCpp(
- op, output,
- /*declareVariablesAtTop=*/declareVariablesAtTop);
+ return translateToCpp(op, output,
+ /*declareVariablesAtTop=*/declareVariablesAtTop);
},
[](DialectRegistry ®istry) {
// clang-format off
diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index de4d546811..5a090741ce 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -73,7 +73,7 @@ static FailureOr<int> getOperatorPrecedence(Operation *operation) {
CppEmitter::CppEmitter(raw_ostream &os, Operation *module,
bool declareVariablesAtTop)
- : os(os), module(module), declareVariablesAtTop(declareVariablesAtTop),
+ : os(os), module(module), declareVariablesAtTop(declareVariablesAtTop),
iface(module->getContext()) {
valueInScopeCount.push(0);
labelInScopeCount.push(0);
@@ -508,7 +508,7 @@ LogicalResult CppEmitter::emitTupleType(Location loc, ArrayRef<Type> types) {
}
LogicalResult mlir::translateToCpp(Operation *op, raw_ostream &os,
- bool declareVariablesAtTop) {
+ bool declareVariablesAtTop) {
CppEmitter emitter(os, op, declareVariablesAtTop);
return emitter.emitOperation(*op, /*trailingSemicolon=*/false);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/84973
More information about the Mlir-commits
mailing list