[Mlir-commits] [mlir] [mlir][emitc] Add op modelling C expressions (PR #71631)
Simon Camphausen
llvmlistbot at llvm.org
Thu Nov 9 06:21:44 PST 2023
================
@@ -505,22 +614,44 @@ static LogicalResult printOperation(CppEmitter &emitter, emitc::ForOp forOp) {
raw_indented_ostream &os = emitter.ostream();
+ // Utility function to determine whether a value is an expression that will be
+ // inlined, and as such should be wrapped in parentheses in order to guarantee
+ // its precedence and associativity.
+ auto requiresParentheses = [&](Value value) {
+ Operation *def = value.getDefiningOp();
+ if (!def)
+ return false;
+ auto expressionOp = dyn_cast<ExpressionOp>(def);
----------------
simon-camp wrote:
```suggestion
auto expressionOp = dyn_cast_if_present<ExpressionOp>(value.getDefiningOp());
```
https://github.com/llvm/llvm-project/pull/71631
More information about the Mlir-commits
mailing list