Skip to content

Conversation

@chandraghale
Copy link
Contributor

Added codegen support for combined masked constructs masked taskloop simd.
Added implementation for EmitOMPMaskedTaskLoopSimdDirective.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. clang:openmp OpenMP related changes to Clang labels Jan 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 7, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: CHANDRA GHALE (chandraghale)

Changes

Added codegen support for combined masked constructs masked taskloop simd.
Added implementation for EmitOMPMaskedTaskLoopSimdDirective.


Full diff: https://github.com/llvm/llvm-project/pull/121916.diff

4 Files Affected:

  • (modified) clang/lib/CodeGen/CGStmt.cpp (+2-1)
  • (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+12)
  • (modified) clang/lib/CodeGen/CodeGenFunction.h (+2)
  • (added) clang/test/OpenMP/masked_taskloop_simd_codegen.c (+49)
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 3974739d2abb47..496a626f3be598 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -338,7 +338,8 @@ void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef<const Attr *> Attrs) {
         cast<OMPMasterTaskLoopSimdDirective>(*S));
     break;
   case Stmt::OMPMaskedTaskLoopSimdDirectiveClass:
-    llvm_unreachable("masked taskloop simd directive not supported yet.");
+    EmitOMPMaskedTaskLoopSimdDirective(
+        cast<OMPMaskedTaskLoopSimdDirective>(*S));
     break;
   case Stmt::OMPParallelMasterTaskLoopDirectiveClass:
     EmitOMPParallelMasterTaskLoopDirective(
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 6cb37b20b7aeee..fa3a82dad003b9 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -8006,6 +8006,18 @@ void CodeGenFunction::EmitOMPMasterTaskLoopSimdDirective(
   CGM.getOpenMPRuntime().emitMasterRegion(*this, CodeGen, S.getBeginLoc());
 }
 
+void CodeGenFunction::EmitOMPMaskedTaskLoopSimdDirective(
+    const OMPMaskedTaskLoopSimdDirective &S) {
+  auto &&CodeGen = [this, &S](CodeGenFunction &CGF, PrePostActionTy &Action) {
+    Action.Enter(CGF);
+    EmitOMPTaskLoopBasedDirective(S);
+  };
+  auto LPCRegion =
+      CGOpenMPRuntime::LastprivateConditionalRAII::disable(*this, S);
+  OMPLexicalScope Scope(*this, S);
+  CGM.getOpenMPRuntime().emitMaskedRegion(*this, CodeGen, S.getBeginLoc());
+}
+
 void CodeGenFunction::EmitOMPParallelMasterTaskLoopDirective(
     const OMPParallelMasterTaskLoopDirective &S) {
   auto &&CodeGen = [this, &S](CodeGenFunction &CGF, PrePostActionTy &Action) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 1a5c42f8f974d0..aa08985351f811 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -3865,6 +3865,8 @@ class CodeGenFunction : public CodeGenTypeCache {
   void EmitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective &S);
   void
   EmitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &S);
+  void
+  EmitOMPMaskedTaskLoopSimdDirective(const OMPMaskedTaskLoopSimdDirective &S);
   void EmitOMPParallelMasterTaskLoopDirective(
       const OMPParallelMasterTaskLoopDirective &S);
   void EmitOMPParallelMasterTaskLoopSimdDirective(
diff --git a/clang/test/OpenMP/masked_taskloop_simd_codegen.c b/clang/test/OpenMP/masked_taskloop_simd_codegen.c
new file mode 100644
index 00000000000000..f786bc582beb20
--- /dev/null
+++ b/clang/test/OpenMP/masked_taskloop_simd_codegen.c
@@ -0,0 +1,49 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --prefix-filecheck-ir-name _ --version 5
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -fopenmp-version=52 -x c -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+#define N 100
+void masked_taskloop_simd(){
+	#pragma omp masked taskloop simd
+	for( int i = 0; i < N; i++)
+	;
+
+}
+
+int main()
+{
+ masked_taskloop_simd();
+}
+// CHECK-LABEL: define dso_local void @masked_taskloop_simd(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:    [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], align 1
+// CHECK-NEXT:    [[TMP:%.*]] = alloca i32, align 4
+// CHECK-NEXT:    [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1:[0-9]+]])
+// CHECK-NEXT:    [[TMP1:%.*]] = call i32 @__kmpc_masked(ptr @[[GLOB1]], i32 [[TMP0]], i32 0)
+// CHECK-NEXT:    [[TMP2:%.*]] = icmp ne i32 [[TMP1]], 0
+// CHECK-NEXT:    br i1 [[TMP2]], label %[[OMP_IF_THEN:.*]], label %[[OMP_IF_END:.*]]
+// CHECK:       [[OMP_IF_THEN]]:
+// CHECK-NEXT:    call void @__kmpc_taskgroup(ptr @[[GLOB1]], i32 [[TMP0]])
+// CHECK-NEXT:    [[TMP3:%.*]] = call ptr @__kmpc_omp_task_alloc(ptr @[[GLOB1]], i32 [[TMP0]], i32 1, i64 80, i64 0, ptr @.omp_task_entry.)
+// CHECK-NEXT:    [[TMP4:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T_WITH_PRIVATES:%.*]], ptr [[TMP3]], i32 0, i32 0
+// CHECK-NEXT:    [[TMP5:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T:%.*]], ptr [[TMP4]], i32 0, i32 5
+// CHECK-NEXT:    store i64 0, ptr [[TMP5]], align 8
+// CHECK-NEXT:    [[TMP6:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T]], ptr [[TMP4]], i32 0, i32 6
+// CHECK-NEXT:    store i64 99, ptr [[TMP6]], align 8
+// CHECK-NEXT:    [[TMP7:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T]], ptr [[TMP4]], i32 0, i32 7
+// CHECK-NEXT:    store i64 1, ptr [[TMP7]], align 8
+// CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T]], ptr [[TMP4]], i32 0, i32 9
+// CHECK-NEXT:    call void @llvm.memset.p0.i64(ptr align 8 [[TMP8]], i8 0, i64 8, i1 false)
+// CHECK-NEXT:    [[TMP9:%.*]] = load i64, ptr [[TMP7]], align 8
+// CHECK-NEXT:    call void @__kmpc_taskloop(ptr @[[GLOB1]], i32 [[TMP0]], ptr [[TMP3]], i32 1, ptr [[TMP5]], ptr [[TMP6]], i64 [[TMP9]], i32 1, i32 0, i64 0, ptr null)
+// CHECK-NEXT:    call void @__kmpc_end_taskgroup(ptr @[[GLOB1]], i32 [[TMP0]])
+// CHECK-NEXT:    call void @__kmpc_end_masked(ptr @[[GLOB1]], i32 [[TMP0]])
+// CHECK-NEXT:    br label %[[OMP_IF_END]]
+// CHECK:       [[OMP_IF_END]]:
+// CHECK-NEXT:    ret void
+//
+// CHECK-LABEL: define dso_local i32 @main(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:    call void @masked_taskloop_simd()
+// CHECK-NEXT:    ret i32 0

@chandraghale
Copy link
Contributor Author

Note : OpenMPSupport.rst is updated in PR : #121741

@chandraghale
Copy link
Contributor Author

chandraghale commented Jan 10, 2025

@alexey-bataev Can you approve this and rest of splitted PRs 121914 and 121746 . This is the part of combined masked construct PR-121741 already merged. OpenMPSupport.rst and and rel note already updated.

Copy link
Member

@alexey-bataev alexey-bataev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@chandraghale chandraghale merged commit 1d2eea9 into llvm:main Jan 12, 2025
8 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jan 12, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-win running on sie-win-worker while building clang at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/46/builds/10325

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: ClangScanDeps/modules-full.cpp' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
rm -rf Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir
# executed command: rm -rf 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir'
# RUN: at line 2
rm -rf Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.cdb
# executed command: rm -rf 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.cdb'
# RUN: at line 3
mkdir -p Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir
# executed command: mkdir -p 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir'
# RUN: at line 4
cp Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps\modules-full.cpp Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/modules_cdb_input.cpp
# executed command: cp 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps\modules-full.cpp' 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/modules_cdb_input.cpp'
# RUN: at line 5
cp Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps\modules-full.cpp Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/modules_cdb_input2.cpp
# executed command: cp 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps\modules-full.cpp' 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/modules_cdb_input2.cpp'
# RUN: at line 6
mkdir Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs
# executed command: mkdir 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs'
# RUN: at line 7
cp Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/header.h Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs/header.h
# executed command: cp 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/header.h' 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs/header.h'
# RUN: at line 8
cp Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/header2.h Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs/header2.h
# executed command: cp 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/header2.h' 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs/header2.h'
# RUN: at line 9
cp Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/module.modulemap Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs/module.modulemap
# executed command: cp 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/module.modulemap' 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.dir/Inputs/module.modulemap'
# RUN: at line 10
sed -e "s|DIR|Z:/b/llvm-clang-x86_64-sie-win/build/tools/clang/test/ClangScanDeps/Output/modules-full.cpp.tmp.dir|g" Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/modules_cdb.json > Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.cdb
# executed command: sed -e 's|DIR|Z:/b/llvm-clang-x86_64-sie-win/build/tools/clang/test/ClangScanDeps/Output/modules-full.cpp.tmp.dir|g' 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/modules_cdb.json'
# RUN: at line 11
sed -e "s|DIR|Z:/b/llvm-clang-x86_64-sie-win/build/tools/clang/test/ClangScanDeps/Output/modules-full.cpp.tmp.dir|g" Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/modules_cdb_clangcl.json > Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp_clangcl.cdb
# executed command: sed -e 's|DIR|Z:/b/llvm-clang-x86_64-sie-win/build/tools/clang/test/ClangScanDeps/Output/modules-full.cpp.tmp.dir|g' 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\ClangScanDeps/Inputs/modules_cdb_clangcl.json'
# RUN: at line 13
z:\b\llvm-clang-x86_64-sie-win\build\bin\clang-scan-deps.exe -compilation-database Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.cdb -j 4 -format experimental-full    -mode preprocess-dependency-directives > Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.result
# executed command: 'z:\b\llvm-clang-x86_64-sie-win\build\bin\clang-scan-deps.exe' -compilation-database 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.cdb' -j 4 -format experimental-full -mode preprocess-dependency-directives
# .---redirected output from 'Z:\b\llvm-clang-x86_64-sie-win\build\tools\clang\test\ClangScanDeps\Output\modules-full.cpp.tmp.result'
# | {
# |   "modules": [
# |     {
# |       "clang-module-deps": [
# |         {
# |           "context-hash": "E230KSM589N6QXXX7H46XDD0P",
# |           "module-name": "header2"
# |         }
...

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jan 12, 2025

LLVM Buildbot has detected a new failure on builder clang-aarch64-sve-vls running on linaro-g3-01 while building clang at step 5 "cmake stage 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/143/builds/4710

Here is the relevant piece of the build log for the reference
Step 5 (cmake stage 1) failure: 'cmake -G ...' (failure)
...
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
  CMakeLists.txt:8 (include)


command timed out: 1200 seconds without output running [b'cmake', b'-G', b'Ninja', b'../llvm/llvm', b'-DCMAKE_BUILD_TYPE=Release', b'-DLLVM_ENABLE_ASSERTIONS=True', b"-DLLVM_LIT_ARGS='-v'", b'-DCMAKE_INSTALL_PREFIX=../stage1.install', b"-DCMAKE_C_FLAGS='-mcpu=neoverse-512tvb'", b"-DCMAKE_CXX_FLAGS='-mcpu=neoverse-512tvb'", b'-DLLVM_ENABLE_LLD=True', b'-DMLIR_INCLUDE_INTEGRATION_TESTS=True', b'-DMLIR_RUN_ARM_SVE_TESTS=True', b'-DLLVM_ENABLE_PROJECTS=clang-tools-extra;lld;mlir;llvm;clang;flang', b'-DLLVM_ENABLE_RUNTIMES=compiler-rt'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1200.237996

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants