[clang] [CIR][OpenMP] Implement lowering for the 'if' clause for 'parallel' d… (PR #204999)

Pedro da Rosa Pinheiro via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 30 08:19:59 PDT 2026


================
@@ -93,6 +93,29 @@ bool OpenMPClauseEmitter::emitProcBind(
   return false;
 }
 
+bool OpenMPClauseEmitter::emitIf(mlir::omp::IfClauseOps &result) const {
+  for (const OMPClause *clause : clauses) {
+    const auto *ic = dyn_cast<OMPIfClause>(clause);
+    if (!ic)
+      continue;
+
+    Expr *ifCondition = ic->getCondition();
+    mlir::Value ifBoolValue = cgf.evaluateExprAsBool(ifCondition); // !cir.bool
+
+    mlir::Type uIntType = builder.getUIntNTy(1);
+    mlir::Value ifUIntValue =
+        builder.createBoolToInt(ifBoolValue, uIntType); // u1
----------------
pedropiin wrote:

Yes we do need to `u1` before `i1`.

The `cir.builtin_int_cast` needs an Integer-typed value as input, therefore we can't use `cir.bool` directly. And we can't use the `u1` directly as the value of the `if clause` needs to be a `mlir::IntegerType`. So, to my knowledge, the only way we can get a `mlir::IntegerType` from a boolean currently is through this 2-step conversion.  

https://github.com/llvm/llvm-project/pull/204999


More information about the cfe-commits mailing list