[clang] [CIR][OpenMP] Implement codegen for OpenMP `critical` directive in ClangIR (PR #240414)
Shrisha Kumar via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 12 23:00:21 PST 2026
Shrisha4real wrote:
> I think it'd be better if we can have the tests in the same files as classic codegen gated by `%if cir-enabled` in the `RUN` lines.
@skadewdl3 I did try this and this is what i found.. this gate should be used if both classic codegen and CIR give the same output, which isnt the case for this instance. The tests needed some modifications while porting from classic codegen .. for example
- if you take `critical_codegen.cpp:34-35` test case:
in classic code gen with -fopenmp-enable-irbuilder
```llvm
call void @__kmpc_critical(ptr @1, i32 %gtid, ptr @.gomp_critical_user_.var)
store i8 2, ptr %a, align 1
br label %entry.critical.after
```
cir does this
```llvm
call void @__kmpc_critical(ptr @1, i32 %gtid, ptr @.gomp_critical_user_.var)
%2 = alloca i8, align 1
br label %omp.critical.region
omp.critical.region:
store i8 2, ptr %2, align 1
br label %omp.region.cont
```
The behavior is the same in both : take the lock, store 2, release the lock. The jump to the new block is just an unconditional branch. Further optimizations should merge these blocks
- the above Sema handling mentioned in the PR note isnt clarified yet . As if now, lets say we use the clause `help(23)`, CIR hits this with NYI error , unlike classic codegen.
these are 2 examples i can state
---
but on the other hand, the IR for test case like `critical-dso-local.cpp` , the IR is identical for both front ends. As its just one test case that "passed" the condition, it made sense for me to keep all tests in the respective CIR test directory.
https://github.com/llvm/llvm-project/pull/240414
More information about the cfe-commits
mailing list