[clang] [llvm] [OpenMP] Diagnostic check for imperfect loop collapse (PR #96087)
Meinersbur wrote: I agree with @kparzysz that the examples you are using are generally unsafe. E.g. with ```c #pragma omp parallel for collapse(2) for (int i = 0; i < N; i++) { arr[i][i] = ...; for (int j = 0; j < N; j++) { arr[i][j] = ...; } } ``` there shouldn't be an expectation on which thread `arr[i][i]` is executed relative to all `a[i][j]`. The use case the non-perfectly nested loop are intended for is to to a precomputation that only depends on i, not on j: ```c #pragma omp parallel for collapse(2) for (int i = 0; i < N; i++) { double e = exp(2*PI*i); for (int j = 0; j < N; j++) { arr[i][j] = ... e ...; } } ``` A compiler could optimize this by computing `exp(2*PI*i)` at most once per thread that is scheduled at least one chunk that uses `i`, but computing it for any inner loop iteration is just as correct. I agree with @alexey-bataev that this should be something handled as a diagnostic in the frontend, like [`Sema::checkOpenMPLoop`](https://github.com/llvm/llvm-project/blob/d6d8243dcd4ea768549904036ed31b8e59e14c73/clang/lib/Sema/SemaOpenMP.cpp#L9620). Pass analysis messages are intended for optimization hints, and are unreliable for correctness warnings (they change depending on optimization levels and previous optimizations, e.g. some code may have been optimized away because of undefined behavior (like ... race conditions), but still would want to warn about it). Point-to analysis would be out-of-scope at this level. I would recommend to only emit the warning if some non-private memory is being written to. If being more sophisticated maybe instead whether `i` is not used to access the global or the same pointer/array variable used used somewhere else in the body. That includes the in-between code as well since it is sunk into the inner loop. Note that the Clang community is very conservative about adding new warnings. Generally, they don't want to add new warnings that are not enabled by default, must not have a legitimate use-case ([adding a warning for calling a virtual method in a constructor was turned down because of this](https://discourse.llvm.org/t/warning-when-calling-virtual-functions-from-constructor-desctructor/50589)), and false-positives must have a form that tells the compiler that this is intended such as `if ((x = 5))`. Everything beyond this should go into clang-tidy or the static analyzer. https://github.com/llvm/llvm-project/pull/96087 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Add emitAtomicCompareExchangeBuiltin helper function (PR #101966)
Meinersbur wrote: `TargetLibraryInfoImpl` is not contained in the backends, but implemented entirely in [`TargetLibraryInfo.cpp`](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Analysis/TargetLibraryInfo.cpp). `TargetLowering` is implemented in the backend, but is also optional. If not provided, the max size of atomic operations is assumed to be 16. I think that frontends having to resolve the ABI information independently would be worse. https://github.com/llvm/llvm-project/pull/101966 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][Driver] Introduce -fopenmp-targets offloading option (PR #100152)
Meinersbur wrote: I reproduced this locally. The output is: ``` $ /home/meinersbur/build/llvm-project/release/bin/flang-new -S -### /c/Users/meinersbur/src/llvm-project/flang/test/Driver/omp-driver-offload-amdgpu.f90 -o /home/meinersbur/build/llvm-project/release/tools/flang/test/Driver/Output/omp-driver-offload-amdgpu.f90.tmp 2>&1 -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa --target=x86_64-unknown-linux-gnu flang-new version 20.0.0git (/home/meinersbur/src/llvm-project/clang f2ec205140a214accd161919c40a966d5695c536) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/meinersbur/build/llvm-project/release/bin Build config: +assertions flang-new: error: cannot determine amdgcn architecture: /home/meinersbur/build/llvm-project/release/bin/amdgpu-arch: ; consider passing it via '-march' "/home/meinersbur/build/llvm-project/release/bin/flang-new" "-fc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc" "-fcolor-diagnostics" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "x86-64" "-fopenmp" "-resource-dir" "/home/meinersbur/build/llvm-project/release/lib/clang/20" "-fopenmp-targets=amdgcn-amd-amdhsa" "-mframe-pointer=all" "-o" "/tmp/meinersbur/omp-driver-offload-amdgpu-e54e29.bc" "-x" "f95-cpp-input" "/c/Users/meinersbur/src/llvm-project/flang/test/Driver/omp-driver-offload-amdgpu.f90" "/home/meinersbur/build/llvm-project/release/bin/flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa" "-emit-llvm-bc" "-fcolor-diagnostics" "-mrelocation-model" "pic" "-pic-level" "2" "-target-cpu" "gfx906" "-fopenmp" "-res urce-dir" "/home/meinersbur/build/llvm-project/release/lib/clang/20" "-fopenmp-host-ir-file-path" "/tmp/meinersbur/omp-driver-offload-amdgpu-e54e29.bc" "-fopenmp-is-target-device" "-mframe-pointer=all" "-o" "/tmp/meinersbur/omp-driver-offload-amdgpu-479864.bc" "-x" "f95-cpp-input" "/c/Users/meinersbur/src/llvm-project/flang/test/Driver/omp-driver-offload-amdgpu.f90" "/home/meinersbur/build/llvm-project/release/bin/clang-offload-packager" "-o" "/tmp/meinersbur/omp-driver-offload-amdgpu-7a81eb.out" "--image=file=/tmp/meinersbur/omp-driver-offload-amdgpu-479864.bc,triple=amdgcn-amd-amdhsa,arch=gfx906,kind=openmp" "/home/meinersbur/build/llvm-project/release/bin/flang-new" "-fc1" "-triple" "x86_64-unknown-linux-gnu" "-S" "-fcolor-diagnostics" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "x86-64" "-fopenmp" "-resource-dir" "/home/meinersbur/build/llvm-project/release/lib/clang/20" "-fembed-offload-object=/tmp/meinersbur/omp-driver-offload-amdgpu-7a81eb.out" "-fopenmp-targets=amdgcn-amd-amdhsa" "-mframe-pointer=all" "-o" "/home/meinersbur/build/llvm-project/release/tools/flang/test/Driver/Output/omp-driver-offload-amdgpu.f90.tmp" "-x" "ir" "/tmp/meinersbur/omp-driver-offload-amdgpu-e54e29.bc" ``` amdgpu-arch fails with: ``` $ bin/amdgpu-arch Failed to 'dlopen' libhsa-runtime64.so Failed to load libamdhip64.so: libamdhip64.so: cannot open shared object file: No such file or directory ``` https://github.com/llvm/llvm-project/pull/100152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][Driver] Introduce -fopenmp-targets offloading option (PR #100152)
@@ -492,6 +493,18 @@ void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs, if (Args.hasArg(options::OPT_nogpulib)) CmdArgs.push_back("-nogpulib"); } + + // For all the host OpenMP offloading compile jobs we need to pass the targets + // information using -fopenmp-targets= option. + if (JA.isHostOffloading(Action::OFK_OpenMP)) { +SmallString<128> Targets("-fopenmp-targets="); Meinersbur wrote: ```suggestion StringRef Targets("-fopenmp-targets="); ``` This is never modified, `SmallString` would be beneficial when using `append`. https://github.com/llvm/llvm-project/pull/100152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][Driver] Introduce -fopenmp-targets offloading option (PR #100152)
https://github.com/Meinersbur approved this pull request. Some nits, but otherwise LGTM. https://github.com/llvm/llvm-project/pull/100152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][Driver] Introduce -fopenmp-targets offloading option (PR #100152)
@@ -492,6 +493,18 @@ void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs, if (Args.hasArg(options::OPT_nogpulib)) CmdArgs.push_back("-nogpulib"); } + + // For all the host OpenMP offloading compile jobs we need to pass the targets + // information using -fopenmp-targets= option. + if (JA.isHostOffloading(Action::OFK_OpenMP)) { +SmallString<128> Targets("-fopenmp-targets="); + +SmallVector Triples; +auto TCRange = C.getOffloadToolChains(); +std::transform(TCRange.first, TCRange.second, std::back_inserter(Triples), + [](auto TC) { return TC.second->getTripleString(); }); Meinersbur wrote: I was going to suggest `llvm::append_range` and `llvm::map` here, but it seems `TCRange` is a weird type. https://github.com/llvm/llvm-project/pull/100152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][Driver] Introduce -fopenmp-targets offloading option (PR #100152)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/100152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][Driver] Introduce -fopenmp-targets offloading option (PR #100152)
@@ -492,6 +493,18 @@ void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs, if (Args.hasArg(options::OPT_nogpulib)) CmdArgs.push_back("-nogpulib"); } + + // For all the host OpenMP offloading compile jobs we need to pass the targets + // information using -fopenmp-targets= option. + if (JA.isHostOffloading(Action::OFK_OpenMP)) { +SmallString<128> Targets("-fopenmp-targets="); + +SmallVector Triples; Meinersbur wrote: ```suggestion SmallVector Triples; ``` Unless there is a motivation for the magic number "4". https://github.com/llvm/llvm-project/pull/100152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][Driver] Introduce -fopenmp-targets offloading option (PR #100152)
@@ -492,6 +493,18 @@ void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs, if (Args.hasArg(options::OPT_nogpulib)) CmdArgs.push_back("-nogpulib"); } + + // For all the host OpenMP offloading compile jobs we need to pass the targets + // information using -fopenmp-targets= option. + if (JA.isHostOffloading(Action::OFK_OpenMP)) { +SmallString<128> Targets("-fopenmp-targets="); + +SmallVector Triples; +auto TCRange = C.getOffloadToolChains(); +std::transform(TCRange.first, TCRange.second, std::back_inserter(Triples), + [](auto TC) { return TC.second->getTripleString(); }); +CmdArgs.push_back(Args.MakeArgString(Targets + llvm::join(Triples, ","))); Meinersbur wrote: ```suggestion CmdArgs.push_back(Args.MakeArgString(Twine(Targets) + llvm::join(Triples, ","))); ``` To make it work with StringRef (`MakeArgString` takes a `Twine` and uses `SmallString` internally). That is, just do ```suggestion CmdArgs.push_back(Args.MakeArgString(Twine("-fopenmp-targets") + llvm::join(Triples, ","))); ``` https://github.com/llvm/llvm-project/pull/100152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
https://github.com/Meinersbur approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -5229,13 +5362,288 @@ static void emitTargetOutlinedFunction( OMPBuilder.emitTargetRegionFunction(EntryInfo, GenerateOutlinedFunction, true, OutlinedFn, OutlinedFnID); } +OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetTask( +Function *OutlinedFn, Value *OutlinedFnID, +EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args, +Value *DeviceID, Value *RTLoc, OpenMPIRBuilder::InsertPointTy AllocaIP, +SmallVector &Dependencies, +bool HasNoWait) { + + // When we arrive at this function, the target region itself has been + // outlined into the function OutlinedFn. + // So at ths point, for + // -- + // void user_code_that_offloads(...) { + // omp target depend(..) map(from:a) map(to:b, c) + //a = b + c + // } + // + // -- + // + // we have + // + // -- + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // ;; target region has been outlined and now we need to + // ;; offload to it via a target task. + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + // We have to now do the following + // (i) Make an offloading call to outlined_device_function using the OpenMP + // RTL. See 'kernel_launch_function' in the pseudo code below. This is + // emitted by emitKernelLaunch + // (ii) Create a task entry point function that calls kernel_launch_function + // and is the entry point for the target task. See + // '@.omp_target_task_proxy_func in the pseudocode below. + // (iii) Create a task with the task entry point created in (ii) + // + // That is we create the following + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // + // %structArg = alloca { ptr, ptr, ptr }, align 8 + // %strucArg[0] = %.offload_baseptrs + // %strucArg[1] = %.offload_ptrs + // %strucArg[2] = %.offload_mappers + // proxy_target_task = @__kmpc_omp_task_alloc(..., + // @.omp_target_task_proxy_func) + // memcpy(proxy_target_task->shareds, %structArg, sizeof(structArg)) + // dependencies_array = ... + // ;; if nowait not present + // call @__kmpc_omp_wait_deps(..., dependencies_array) + // call @__kmpc_omp_task_begin_if0(...) + // call @ @.omp_target_task_proxy_func(i32 thread_id, ptr + // %proxy_target_task) call @__kmpc_omp_task_complete_if0(...) + // } + // + // define internal void @.omp_target_task_proxy_func(i32 %thread.id, + // ptr %task) { + // %structArg = alloca {ptr, ptr, ptr} + // %shared_data = load (getelementptr %task, 0, 0) + // mempcy(%structArg, %shared_data, sizeof(structArg)) + // kernel_launch_function(%thread.id, %structArg) + // } + // + // We need the proxy function because the signature of the task entry point + // expected by kmpc_omp_task is always the same and will be different from + // that of the kernel_launch function. + // + // kernel_launch_function is generated by emitKernelLaunch and has the + // always_inline attribute. void kernel_launch_function(thread_id, + //structArg) + //alwaysinline { + // %kernel_args = alloca %struct.__tgt_kernel_arguments, align 8 + // offload_baseptrs = load(getelementptr structArg, 0, 0) + // offload_ptrs = load(getelementptr structArg, 0, 1) + // offload_mappers = load(getelementptr structArg, 0, 2) + // ; setup kernel_args using offload_baseptrs, offload_ptrs and + // ; offload_mappers + // call i32 @__tgt_target_kernel(..., + // outlined_device_function, + // ptr %kernel_args) + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + BasicBlock *TargetTaskBodyBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.body"); + BasicBlock *TargetTaskAllocaBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.alloca"); + + InsertPointTy TargetTaskAllocaIP = + InsertPointTy(TargetTaskAllocaBB, TargetTaskAllocaBB->begin()); + InsertPointTy TargetTaskBodyIP = + InsertPointTy(TargetTaskBodyBB, TargetTaskBodyBB->begin()); + + OutlineInfo OI; + OI.En
[clang] [llvm] [openmp] [Clang][OpenMP] Add interchange directive (PR #93022)
https://github.com/Meinersbur closed https://github.com/llvm/llvm-project/pull/93022 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Clang][OpenMP] Add interchange directive (PR #93022)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93022 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Clang][OpenMP] Add interchange directive (PR #93022)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93022 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Clang][OpenMP] Add interchange directive (PR #93022)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93022 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Clang][OpenMP] Add interchange directive (PR #93022)
@@ -14853,6 +14861,158 @@ StmtResult SemaOpenMP::ActOnOpenMPReverseDirective(Stmt *AStmt, buildPreInits(Context, PreInits)); } +StmtResult SemaOpenMP::ActOnOpenMPInterchangeDirective( +ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, +SourceLocation EndLoc) { + ASTContext &Context = getASTContext(); + DeclContext *CurContext = SemaRef.CurContext; + Scope *CurScope = SemaRef.getCurScope(); + + // Empty statement should only be possible if there already was an error. + if (!AStmt) +return StmtError(); + + // interchange without permutation clause swaps two loops. + constexpr size_t NumLoops = 2; + + // Verify and diagnose loop nest. + SmallVector LoopHelpers(NumLoops); + Stmt *Body = nullptr; + SmallVector, 2> OriginalInits; + if (!checkTransformableLoopNest(OMPD_interchange, AStmt, NumLoops, + LoopHelpers, Body, OriginalInits)) +return StmtError(); + + // Delay interchange to when template is completely instantiated. + if (CurContext->isDependentContext()) +return OMPInterchangeDirective::Create(Context, StartLoc, EndLoc, Clauses, + NumLoops, AStmt, nullptr, nullptr); + + assert(LoopHelpers.size() == NumLoops && + "Expecting loop iteration space dimensionaly to match number of " + "affected loops"); + assert(OriginalInits.size() == NumLoops && + "Expecting loop iteration space dimensionaly to match number of " + "affected loops"); + + // Decode the permutation clause. + constexpr uint64_t Permutation[] = {1, 0}; + + // Find the affected loops. + SmallVector LoopStmts(NumLoops, nullptr); + collectLoopStmts(AStmt, LoopStmts); + + // Collect pre-init statements on the order before the permuation. + SmallVector PreInits; + for (auto I : llvm::seq(NumLoops)) { +OMPLoopBasedDirective::HelperExprs &LoopHelper = LoopHelpers[I]; + +assert(LoopHelper.Counters.size() == 1 && + "Single-dimensional loop iteration space expected"); +auto *OrigCntVar = cast(LoopHelper.Counters.front()); + +std::string OrigVarName = OrigCntVar->getNameInfo().getAsString(); Meinersbur wrote: I don't get this. `getAsString` returns an `std::string` r-value. Assigning it to a `SmallString` will unpack that `std::string` and copy it over to `SmallString`'s buffer, compared to RVO where no additional copy happens. Furthermore, contemporary implementations of `std::string` are [already using a small-size buffer](https://devblogs.microsoft.com/oldnewthing/20240510-00/?p=109742). I guess I could call `OrigCntVar->getNameInfo().operator<<`, and pass a `raw_svector_ostream` instantiated using a `SmallString`. This would enable us to choose a larger small buffer size ourselves. Is that what you are asking for? If so, what should the small buffer size be? https://github.com/llvm/llvm-project/pull/93022 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Revise IDE folder structure (PR #89746)
https://github.com/Meinersbur closed https://github.com/llvm/llvm-project/pull/89746 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Revise IDE folder structure (PR #89746)
Meinersbur wrote: @frasercrmck I intended to follow the target name, which is "prepare" in this case. I changed it in the most recent push. I may not have noticed myself because it is not used by default (llvm-spirv must have been found). Here is what it looks like (dark mode, Aliases kept collapsed because to many items): ![image](https://github.com/user-attachments/assets/1686ff79-5afe-4602-8992-c1156428ef4b) https://github.com/llvm/llvm-project/pull/89746 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Revise IDE folder structure (PR #89746)
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/89746 >From 6f39beb9ee58d7c377dce6ba8ce69e71da5b8e09 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Tue, 23 Apr 2024 12:55:15 +0200 Subject: [PATCH 1/8] [llvm] Revise IDE folder structure --- llvm/CMakeLists.txt | 12 ++- llvm/cmake/modules/AddLLVM.cmake | 83 ++- llvm/cmake/modules/AddOCaml.cmake | 5 +- llvm/cmake/modules/AddSphinxTarget.cmake | 3 + llvm/cmake/modules/CrossCompile.cmake | 4 + .../modules/LLVMDistributionSupport.cmake | 8 ++ .../modules/LLVMExternalProjectUtils.cmake| 25 +- llvm/cmake/modules/TableGen.cmake | 7 +- llvm/docs/CMakeLists.txt | 1 + llvm/examples/Kaleidoscope/CMakeLists.txt | 2 +- llvm/include/llvm/Support/CMakeLists.txt | 2 +- llvm/lib/Support/BLAKE3/CMakeLists.txt| 1 + llvm/runtimes/CMakeLists.txt | 23 + llvm/test/CMakeLists.txt | 6 +- llvm/tools/opt-viewer/CMakeLists.txt | 1 + .../InlineAdvisorPlugin/CMakeLists.txt| 3 +- .../Analysis/InlineOrderPlugin/CMakeLists.txt | 2 +- llvm/unittests/CMakeLists.txt | 2 +- llvm/unittests/DebugInfo/BTF/CMakeLists.txt | 2 - .../DebugInfo/CodeView/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/DWARF/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/GSYM/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/MSF/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/PDB/CMakeLists.txt | 2 - llvm/unittests/ExecutionEngine/CMakeLists.txt | 2 - .../ExecutionEngine/JITLink/CMakeLists.txt| 2 - .../ExecutionEngine/MCJIT/CMakeLists.txt | 2 - .../ExecutionEngine/Orc/CMakeLists.txt| 2 - .../Support/CommandLineInit/CMakeLists.txt| 4 - .../Support/DynamicLibrary/CMakeLists.txt | 4 +- llvm/unittests/Target/AArch64/CMakeLists.txt | 2 - llvm/unittests/Target/AMDGPU/CMakeLists.txt | 2 - llvm/unittests/Target/ARM/CMakeLists.txt | 2 - llvm/unittests/Target/CMakeLists.txt | 3 - .../unittests/Target/LoongArch/CMakeLists.txt | 2 - llvm/unittests/Target/PowerPC/CMakeLists.txt | 2 - llvm/unittests/Target/RISCV/CMakeLists.txt| 2 - .../Target/WebAssembly/CMakeLists.txt | 2 - llvm/unittests/Target/X86/CMakeLists.txt | 2 - .../Transforms/Coroutines/CMakeLists.txt | 2 - llvm/unittests/Transforms/IPO/CMakeLists.txt | 2 - .../Transforms/Scalar/CMakeLists.txt | 2 - .../unittests/Transforms/Utils/CMakeLists.txt | 2 - .../Transforms/Vectorize/CMakeLists.txt | 2 - .../tools/llvm-cfi-verify/CMakeLists.txt | 2 - .../tools/llvm-exegesis/CMakeLists.txt| 2 - llvm/unittests/tools/llvm-mca/CMakeLists.txt | 2 - .../tools/llvm-profdata/CMakeLists.txt| 2 - .../tools/llvm-profgen/CMakeLists.txt | 2 - llvm/utils/LLVMVisualizers/CMakeLists.txt | 2 +- llvm/utils/TableGen/Basic/CMakeLists.txt | 1 - llvm/utils/TableGen/CMakeLists.txt| 2 - llvm/utils/TableGen/Common/CMakeLists.txt | 1 - llvm/utils/lit/CMakeLists.txt | 4 +- llvm/utils/llvm-locstats/CMakeLists.txt | 2 +- llvm/utils/mlgo-utils/CMakeLists.txt | 2 +- 56 files changed, 159 insertions(+), 112 deletions(-) diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 43181af3bc195..48a6ab7d21f48 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -1124,7 +1124,7 @@ configure_file( add_custom_target(srpm COMMAND cpack -G TGZ --config CPackSourceConfig.cmake -B ${LLVM_SRPM_DIR}/SOURCES COMMAND rpmbuild -bs --define '_topdir ${LLVM_SRPM_DIR}' ${LLVM_SRPM_BINARY_SPECFILE}) -set_target_properties(srpm PROPERTIES FOLDER "Misc") +set_target_properties(srpm PROPERTIES FOLDER "LLVM/Misc") if(APPLE AND DARWIN_LTO_LIBRARY) set(CMAKE_EXE_LINKER_FLAGS @@ -1222,7 +1222,9 @@ if( LLVM_INCLUDE_UTILS ) add_subdirectory(utils/split-file) add_subdirectory(utils/mlgo-utils) if( LLVM_INCLUDE_TESTS ) +set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test") add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest) +set(LLVM_SUBPROJECT_TITLE) endif() else() if ( LLVM_INCLUDE_TESTS ) @@ -1286,7 +1288,7 @@ if( LLVM_INCLUDE_TESTS ) if(LLVM_ALL_LIT_DEPENDS OR LLVM_ALL_ADDITIONAL_TEST_DEPENDS) add_dependencies(test-depends ${LLVM_ALL_LIT_DEPENDS} ${LLVM_ALL_ADDITIONAL_TEST_DEPENDS}) endif() - set_target_properties(test-depends PROPERTIES FOLDER "Tests") + set_target_properties(test-depends PROPERTIES FOLDER "LLVM/Tests") add_dependencies(check-all test-depends) endif() @@ -1343,7 +1345,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) # Installing the headers needs to depend on generating any public # tablegen'd headers. add_custom_target(llvm-headers DEPENDS intrinsics_gen omp_gen) - s
[libclc] [llvm] [libclc] Revise IDE folder structure (PR #89746)
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/89746 >From 6f39beb9ee58d7c377dce6ba8ce69e71da5b8e09 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Tue, 23 Apr 2024 12:55:15 +0200 Subject: [PATCH 1/7] [llvm] Revise IDE folder structure --- llvm/CMakeLists.txt | 12 ++- llvm/cmake/modules/AddLLVM.cmake | 83 ++- llvm/cmake/modules/AddOCaml.cmake | 5 +- llvm/cmake/modules/AddSphinxTarget.cmake | 3 + llvm/cmake/modules/CrossCompile.cmake | 4 + .../modules/LLVMDistributionSupport.cmake | 8 ++ .../modules/LLVMExternalProjectUtils.cmake| 25 +- llvm/cmake/modules/TableGen.cmake | 7 +- llvm/docs/CMakeLists.txt | 1 + llvm/examples/Kaleidoscope/CMakeLists.txt | 2 +- llvm/include/llvm/Support/CMakeLists.txt | 2 +- llvm/lib/Support/BLAKE3/CMakeLists.txt| 1 + llvm/runtimes/CMakeLists.txt | 23 + llvm/test/CMakeLists.txt | 6 +- llvm/tools/opt-viewer/CMakeLists.txt | 1 + .../InlineAdvisorPlugin/CMakeLists.txt| 3 +- .../Analysis/InlineOrderPlugin/CMakeLists.txt | 2 +- llvm/unittests/CMakeLists.txt | 2 +- llvm/unittests/DebugInfo/BTF/CMakeLists.txt | 2 - .../DebugInfo/CodeView/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/DWARF/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/GSYM/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/MSF/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/PDB/CMakeLists.txt | 2 - llvm/unittests/ExecutionEngine/CMakeLists.txt | 2 - .../ExecutionEngine/JITLink/CMakeLists.txt| 2 - .../ExecutionEngine/MCJIT/CMakeLists.txt | 2 - .../ExecutionEngine/Orc/CMakeLists.txt| 2 - .../Support/CommandLineInit/CMakeLists.txt| 4 - .../Support/DynamicLibrary/CMakeLists.txt | 4 +- llvm/unittests/Target/AArch64/CMakeLists.txt | 2 - llvm/unittests/Target/AMDGPU/CMakeLists.txt | 2 - llvm/unittests/Target/ARM/CMakeLists.txt | 2 - llvm/unittests/Target/CMakeLists.txt | 3 - .../unittests/Target/LoongArch/CMakeLists.txt | 2 - llvm/unittests/Target/PowerPC/CMakeLists.txt | 2 - llvm/unittests/Target/RISCV/CMakeLists.txt| 2 - .../Target/WebAssembly/CMakeLists.txt | 2 - llvm/unittests/Target/X86/CMakeLists.txt | 2 - .../Transforms/Coroutines/CMakeLists.txt | 2 - llvm/unittests/Transforms/IPO/CMakeLists.txt | 2 - .../Transforms/Scalar/CMakeLists.txt | 2 - .../unittests/Transforms/Utils/CMakeLists.txt | 2 - .../Transforms/Vectorize/CMakeLists.txt | 2 - .../tools/llvm-cfi-verify/CMakeLists.txt | 2 - .../tools/llvm-exegesis/CMakeLists.txt| 2 - llvm/unittests/tools/llvm-mca/CMakeLists.txt | 2 - .../tools/llvm-profdata/CMakeLists.txt| 2 - .../tools/llvm-profgen/CMakeLists.txt | 2 - llvm/utils/LLVMVisualizers/CMakeLists.txt | 2 +- llvm/utils/TableGen/Basic/CMakeLists.txt | 1 - llvm/utils/TableGen/CMakeLists.txt| 2 - llvm/utils/TableGen/Common/CMakeLists.txt | 1 - llvm/utils/lit/CMakeLists.txt | 4 +- llvm/utils/llvm-locstats/CMakeLists.txt | 2 +- llvm/utils/mlgo-utils/CMakeLists.txt | 2 +- 56 files changed, 159 insertions(+), 112 deletions(-) diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 43181af3bc195..48a6ab7d21f48 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -1124,7 +1124,7 @@ configure_file( add_custom_target(srpm COMMAND cpack -G TGZ --config CPackSourceConfig.cmake -B ${LLVM_SRPM_DIR}/SOURCES COMMAND rpmbuild -bs --define '_topdir ${LLVM_SRPM_DIR}' ${LLVM_SRPM_BINARY_SPECFILE}) -set_target_properties(srpm PROPERTIES FOLDER "Misc") +set_target_properties(srpm PROPERTIES FOLDER "LLVM/Misc") if(APPLE AND DARWIN_LTO_LIBRARY) set(CMAKE_EXE_LINKER_FLAGS @@ -1222,7 +1222,9 @@ if( LLVM_INCLUDE_UTILS ) add_subdirectory(utils/split-file) add_subdirectory(utils/mlgo-utils) if( LLVM_INCLUDE_TESTS ) +set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test") add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest) +set(LLVM_SUBPROJECT_TITLE) endif() else() if ( LLVM_INCLUDE_TESTS ) @@ -1286,7 +1288,7 @@ if( LLVM_INCLUDE_TESTS ) if(LLVM_ALL_LIT_DEPENDS OR LLVM_ALL_ADDITIONAL_TEST_DEPENDS) add_dependencies(test-depends ${LLVM_ALL_LIT_DEPENDS} ${LLVM_ALL_ADDITIONAL_TEST_DEPENDS}) endif() - set_target_properties(test-depends PROPERTIES FOLDER "Tests") + set_target_properties(test-depends PROPERTIES FOLDER "LLVM/Tests") add_dependencies(check-all test-depends) endif() @@ -1343,7 +1345,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) # Installing the headers needs to depend on generating any public # tablegen'd headers. add_custom_target(llvm-headers DEPENDS intrinsics_gen omp_gen) - s
[clang] [llvm] [openmp] [Clang][OpenMP] Add reverse directive (PR #92916)
@@ -15749,6 +15757,186 @@ StmtResult SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef Clauses, buildPreInits(Context, PreInits)); } +StmtResult SemaOpenMP::ActOnOpenMPReverseDirective(Stmt *AStmt, + SourceLocation StartLoc, + SourceLocation EndLoc) { + ASTContext &Context = getASTContext(); + Scope *CurScope = SemaRef.getCurScope(); + + // Empty statement should only be possible if there already was an error. + if (!AStmt) +return StmtError(); + + constexpr unsigned NumLoops = 1; + Stmt *Body = nullptr; + SmallVector LoopHelpers( + NumLoops); + SmallVector, NumLoops + 1> OriginalInits; + if (!checkTransformableLoopNest(OMPD_reverse, AStmt, NumLoops, LoopHelpers, + Body, OriginalInits)) +return StmtError(); + + // Delay applying the transformation to when template is completely + // instantiated. + if (SemaRef.CurContext->isDependentContext()) +return OMPReverseDirective::Create(Context, StartLoc, EndLoc, AStmt, + nullptr, nullptr); + + assert(LoopHelpers.size() == NumLoops && + "Expecting a single-dimensional loop iteration space"); + assert(OriginalInits.size() == NumLoops && + "Expecting a single-dimensional loop iteration space"); + OMPLoopBasedDirective::HelperExprs &LoopHelper = LoopHelpers.front(); + + // Find the loop statement. + Stmt *LoopStmt = nullptr; + collectLoopStmts(AStmt, {LoopStmt}); + + // Determine the PreInit declarations. + SmallVector PreInits; + addLoopPreInits(Context, LoopHelper, LoopStmt, OriginalInits[0], PreInits); + + auto *IterationVarRef = cast(LoopHelper.IterationVarRef); + QualType IVTy = IterationVarRef->getType(); + uint64_t IVWidth = Context.getTypeSize(IVTy); + auto *OrigVar = cast(LoopHelper.Counters.front()); + + // Iteration variable SourceLocations. + SourceLocation OrigVarLoc = OrigVar->getExprLoc(); + SourceLocation OrigVarLocBegin = OrigVar->getBeginLoc(); + SourceLocation OrigVarLocEnd = OrigVar->getEndLoc(); + + // Locations pointing to the transformation. + SourceLocation TransformLoc = StartLoc; + SourceLocation TransformLocBegin = StartLoc; + SourceLocation TransformLocEnd = EndLoc; + + // Internal variable names. + std::string OrigVarName = OrigVar->getNameInfo().getAsString(); + std::string TripCountName = (Twine(".tripcount.") + OrigVarName).str(); + std::string ForwardIVName = (Twine(".forward.iv.") + OrigVarName).str(); + std::string ReversedIVName = (Twine(".reversed.iv.") + OrigVarName).str(); Meinersbur wrote: SmallString works, but requires a separate `append` statement. Applied. https://github.com/llvm/llvm-project/pull/92916 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Clang][OpenMP] Add reverse directive (PR #92916)
@@ -15749,6 +15757,186 @@ StmtResult SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef Clauses, buildPreInits(Context, PreInits)); } +StmtResult SemaOpenMP::ActOnOpenMPReverseDirective(Stmt *AStmt, + SourceLocation StartLoc, + SourceLocation EndLoc) { + ASTContext &Context = getASTContext(); + Scope *CurScope = SemaRef.getCurScope(); + + // Empty statement should only be possible if there already was an error. + if (!AStmt) +return StmtError(); + + constexpr unsigned NumLoops = 1; + Stmt *Body = nullptr; + SmallVector LoopHelpers( + NumLoops); + SmallVector, NumLoops + 1> OriginalInits; + if (!checkTransformableLoopNest(OMPD_reverse, AStmt, NumLoops, LoopHelpers, + Body, OriginalInits)) +return StmtError(); + + // Delay applying the transformation to when template is completely + // instantiated. + if (SemaRef.CurContext->isDependentContext()) +return OMPReverseDirective::Create(Context, StartLoc, EndLoc, AStmt, + nullptr, nullptr); + + assert(LoopHelpers.size() == NumLoops && + "Expecting a single-dimensional loop iteration space"); + assert(OriginalInits.size() == NumLoops && + "Expecting a single-dimensional loop iteration space"); + OMPLoopBasedDirective::HelperExprs &LoopHelper = LoopHelpers.front(); + + // Find the loop statement. + Stmt *LoopStmt = nullptr; + collectLoopStmts(AStmt, {LoopStmt}); + + // Determine the PreInit declarations. + SmallVector PreInits; + addLoopPreInits(Context, LoopHelper, LoopStmt, OriginalInits[0], PreInits); + + auto *IterationVarRef = cast(LoopHelper.IterationVarRef); + QualType IVTy = IterationVarRef->getType(); + uint64_t IVWidth = Context.getTypeSize(IVTy); + auto *OrigVar = cast(LoopHelper.Counters.front()); + + // Iteration variable SourceLocations. + SourceLocation OrigVarLoc = OrigVar->getExprLoc(); + SourceLocation OrigVarLocBegin = OrigVar->getBeginLoc(); + SourceLocation OrigVarLocEnd = OrigVar->getEndLoc(); + + // Locations pointing to the transformation. + SourceLocation TransformLoc = StartLoc; + SourceLocation TransformLocBegin = StartLoc; + SourceLocation TransformLocEnd = EndLoc; + + // Internal variable names. + std::string OrigVarName = OrigVar->getNameInfo().getAsString(); + std::string TripCountName = (Twine(".tripcount.") + OrigVarName).str(); + std::string ForwardIVName = (Twine(".forward.iv.") + OrigVarName).str(); + std::string ReversedIVName = (Twine(".reversed.iv.") + OrigVarName).str(); + + // LoopHelper.Updates will read the logical iteration number from + // LoopHelper.IterationVarRef, compute the value of the user loop counter of + // that logical iteration from it, then assign it to the user loop counter + // variable. We cannot directly use LoopHelper.IterationVarRef as the + // induction variable of the generated loop because it may cause an underflow: + // \code + // for (unsigned i = 0; i < n; ++i) + // body(i); + // \endcode + // + // Naive reversal: + // \code + // for (unsigned i = n-1; i >= 0; --i) + // body(i); + // \endcode + // + // Instead, we introduce a new iteration variable representing the logical + // iteration counter of the original loop, convert it to the logical iteration + // number of the reversed loop, then let LoopHelper.Updates compute the user's + // loop iteration variable from it. + // \code + // for (auto .forward.iv = 0; .forward.iv < n; ++.forward.iv) { + // auto .reversed.iv = n - .forward.iv - 1; + // i = (.reversed.iv + 0) * 1;// LoopHelper.Updates + // body(i); // Body + // } + // \endcode + + // Subexpressions with more than one use. One of the constraints of an AST is + // that every node object must appear at most once, hence we define a lambda + // that creates a new AST node at every use. + CaptureVars CopyTransformer(SemaRef); + auto MakeNumIterations = [&CopyTransformer, &LoopHelper]() -> Expr * { +return AssertSuccess( +CopyTransformer.TransformExpr(LoopHelper.NumIterations)); + }; + + // Create the iteration variable for the forward loop (from 0 to n-1). + VarDecl *ForwardIVDecl = + buildVarDecl(SemaRef, {}, IVTy, ForwardIVName, nullptr, OrigVar); + auto MakeForwardRef = [&SemaRef = this->SemaRef, ForwardIVDecl, IVTy, + OrigVarLoc]() { +return buildDeclRefExpr(SemaRef, ForwardIVDecl, IVTy, OrigVarLoc); + }; + + // Iteration variable for the reversed induction variable (from n-1 downto 0): + // Reuse the iteration variable created by checkOpenMPLoop. + auto *ReversedIVDecl = cast(IterationVarRef->getDecl()); + ReversedIVDecl->setDeclName( + &SemaRef.PP.getIdentifierTable().get(ReversedIVName)); + + // For init-statement: + // \co
[clang] [llvm] [openmp] [Clang][OpenMP] Add reverse directive (PR #92916)
@@ -15749,6 +15757,186 @@ StmtResult SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef Clauses, buildPreInits(Context, PreInits)); } +StmtResult SemaOpenMP::ActOnOpenMPReverseDirective(Stmt *AStmt, + SourceLocation StartLoc, + SourceLocation EndLoc) { + ASTContext &Context = getASTContext(); + Scope *CurScope = SemaRef.getCurScope(); + + // Empty statement should only be possible if there already was an error. + if (!AStmt) +return StmtError(); + + constexpr unsigned NumLoops = 1; + Stmt *Body = nullptr; + SmallVector LoopHelpers( + NumLoops); + SmallVector, NumLoops + 1> OriginalInits; + if (!checkTransformableLoopNest(OMPD_reverse, AStmt, NumLoops, LoopHelpers, + Body, OriginalInits)) +return StmtError(); + + // Delay applying the transformation to when template is completely + // instantiated. + if (SemaRef.CurContext->isDependentContext()) +return OMPReverseDirective::Create(Context, StartLoc, EndLoc, AStmt, + nullptr, nullptr); + + assert(LoopHelpers.size() == NumLoops && + "Expecting a single-dimensional loop iteration space"); + assert(OriginalInits.size() == NumLoops && + "Expecting a single-dimensional loop iteration space"); + OMPLoopBasedDirective::HelperExprs &LoopHelper = LoopHelpers.front(); + + // Find the loop statement. + Stmt *LoopStmt = nullptr; + collectLoopStmts(AStmt, {LoopStmt}); + + // Determine the PreInit declarations. + SmallVector PreInits; + addLoopPreInits(Context, LoopHelper, LoopStmt, OriginalInits[0], PreInits); + + auto *IterationVarRef = cast(LoopHelper.IterationVarRef); + QualType IVTy = IterationVarRef->getType(); + uint64_t IVWidth = Context.getTypeSize(IVTy); + auto *OrigVar = cast(LoopHelper.Counters.front()); + + // Iteration variable SourceLocations. + SourceLocation OrigVarLoc = OrigVar->getExprLoc(); + SourceLocation OrigVarLocBegin = OrigVar->getBeginLoc(); + SourceLocation OrigVarLocEnd = OrigVar->getEndLoc(); + + // Locations pointing to the transformation. + SourceLocation TransformLoc = StartLoc; + SourceLocation TransformLocBegin = StartLoc; + SourceLocation TransformLocEnd = EndLoc; + + // Internal variable names. + std::string OrigVarName = OrigVar->getNameInfo().getAsString(); + std::string TripCountName = (Twine(".tripcount.") + OrigVarName).str(); + std::string ForwardIVName = (Twine(".forward.iv.") + OrigVarName).str(); + std::string ReversedIVName = (Twine(".reversed.iv.") + OrigVarName).str(); + + // LoopHelper.Updates will read the logical iteration number from + // LoopHelper.IterationVarRef, compute the value of the user loop counter of + // that logical iteration from it, then assign it to the user loop counter + // variable. We cannot directly use LoopHelper.IterationVarRef as the + // induction variable of the generated loop because it may cause an underflow: + // \code + // for (unsigned i = 0; i < n; ++i) + // body(i); + // \endcode + // + // Naive reversal: + // \code + // for (unsigned i = n-1; i >= 0; --i) + // body(i); + // \endcode + // + // Instead, we introduce a new iteration variable representing the logical + // iteration counter of the original loop, convert it to the logical iteration + // number of the reversed loop, then let LoopHelper.Updates compute the user's + // loop iteration variable from it. + // \code + // for (auto .forward.iv = 0; .forward.iv < n; ++.forward.iv) { + // auto .reversed.iv = n - .forward.iv - 1; + // i = (.reversed.iv + 0) * 1;// LoopHelper.Updates + // body(i); // Body + // } + // \endcode + + // Subexpressions with more than one use. One of the constraints of an AST is + // that every node object must appear at most once, hence we define a lambda + // that creates a new AST node at every use. + CaptureVars CopyTransformer(SemaRef); + auto MakeNumIterations = [&CopyTransformer, &LoopHelper]() -> Expr * { +return AssertSuccess( +CopyTransformer.TransformExpr(LoopHelper.NumIterations)); + }; + + // Create the iteration variable for the forward loop (from 0 to n-1). + VarDecl *ForwardIVDecl = + buildVarDecl(SemaRef, {}, IVTy, ForwardIVName, nullptr, OrigVar); + auto MakeForwardRef = [&SemaRef = this->SemaRef, ForwardIVDecl, IVTy, + OrigVarLoc]() { +return buildDeclRefExpr(SemaRef, ForwardIVDecl, IVTy, OrigVarLoc); + }; + + // Iteration variable for the reversed induction variable (from n-1 downto 0): + // Reuse the iteration variable created by checkOpenMPLoop. + auto *ReversedIVDecl = cast(IterationVarRef->getDecl()); + ReversedIVDecl->setDeclName( + &SemaRef.PP.getIdentifierTable().get(ReversedIVName)); + + // For init-statement: + // \co
[clang] [llvm] [openmp] [Clang][OpenMP] Add reverse directive (PR #92916)
@@ -15749,6 +15757,186 @@ StmtResult SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef Clauses, buildPreInits(Context, PreInits)); } +StmtResult SemaOpenMP::ActOnOpenMPReverseDirective(Stmt *AStmt, + SourceLocation StartLoc, + SourceLocation EndLoc) { + ASTContext &Context = getASTContext(); + Scope *CurScope = SemaRef.getCurScope(); + + // Empty statement should only be possible if there already was an error. + if (!AStmt) +return StmtError(); + + constexpr unsigned NumLoops = 1; + Stmt *Body = nullptr; + SmallVector LoopHelpers( + NumLoops); + SmallVector, NumLoops + 1> OriginalInits; + if (!checkTransformableLoopNest(OMPD_reverse, AStmt, NumLoops, LoopHelpers, + Body, OriginalInits)) +return StmtError(); + + // Delay applying the transformation to when template is completely + // instantiated. + if (SemaRef.CurContext->isDependentContext()) +return OMPReverseDirective::Create(Context, StartLoc, EndLoc, AStmt, + nullptr, nullptr); + + assert(LoopHelpers.size() == NumLoops && + "Expecting a single-dimensional loop iteration space"); + assert(OriginalInits.size() == NumLoops && + "Expecting a single-dimensional loop iteration space"); + OMPLoopBasedDirective::HelperExprs &LoopHelper = LoopHelpers.front(); + + // Find the loop statement. + Stmt *LoopStmt = nullptr; + collectLoopStmts(AStmt, {LoopStmt}); + + // Determine the PreInit declarations. + SmallVector PreInits; + addLoopPreInits(Context, LoopHelper, LoopStmt, OriginalInits[0], PreInits); + + auto *IterationVarRef = cast(LoopHelper.IterationVarRef); + QualType IVTy = IterationVarRef->getType(); + uint64_t IVWidth = Context.getTypeSize(IVTy); + auto *OrigVar = cast(LoopHelper.Counters.front()); + + // Iteration variable SourceLocations. + SourceLocation OrigVarLoc = OrigVar->getExprLoc(); + SourceLocation OrigVarLocBegin = OrigVar->getBeginLoc(); + SourceLocation OrigVarLocEnd = OrigVar->getEndLoc(); + + // Locations pointing to the transformation. + SourceLocation TransformLoc = StartLoc; + SourceLocation TransformLocBegin = StartLoc; + SourceLocation TransformLocEnd = EndLoc; + + // Internal variable names. + std::string OrigVarName = OrigVar->getNameInfo().getAsString(); + std::string TripCountName = (Twine(".tripcount.") + OrigVarName).str(); + std::string ForwardIVName = (Twine(".forward.iv.") + OrigVarName).str(); + std::string ReversedIVName = (Twine(".reversed.iv.") + OrigVarName).str(); Meinersbur wrote: `Twine` stores a non-owning reference to its argument, here `OrigVarName`. If that string goes out of scope or is changed, that becomes a dangling reference. `Twine` was designed to be valid within a statement only; at the end of that statement temporaries may be released. From `Twine.h`: ``` /// A Twine is not intended for use directly and should not be stored, its /// implementation relies on the ability to store pointers to temporary stack /// objects which may be deallocated at the end of a statement. Twines should /// only be used as const references in arguments, when an API wishes /// to accept possibly-concatenated strings. ``` In this case only two strings are concatenated, so there are no temporary strings that `Twine` could help avoiding. I may still have used `Twine` here because either I originally also appended a suffix, or expected `Twine` to benefit from being able to precompute the target string length. If that's the case, `std::string::operator+` should be able to do the same. Let me remove `Twine` here completely. https://github.com/llvm/llvm-project/pull/92916 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [OpenMPIRBuilder] Emit __atomic_load and __atomic_compare_exchange libcalls for complex types in atomic update (PR #92364)
@@ -6033,6 +6034,52 @@ std::pair OpenMPIRBuilder::emitAtomicUpdate( Res.second = Res.first; else Res.second = emitRMWOpAsInstruction(Res.first, Expr, RMWOp); + } else if (RMWOp == llvm::AtomicRMWInst::BinOp::BAD_BINOP) { Meinersbur wrote: `BAD_BINOP`? Doesn't this implement `BinOp::Xchg`? https://github.com/llvm/llvm-project/pull/92364 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [OpenMPIRBuilder] Emit __atomic_load and __atomic_compare_exchange libcalls for complex types in atomic update (PR #92364)
@@ -6033,6 +6034,52 @@ std::pair OpenMPIRBuilder::emitAtomicUpdate( Res.second = Res.first; else Res.second = emitRMWOpAsInstruction(Res.first, Expr, RMWOp); + } else if (RMWOp == llvm::AtomicRMWInst::BinOp::BAD_BINOP) { +LoadInst *OldVal = +Builder.CreateLoad(XElemTy, X, X->getName() + ".atomic.load"); +OldVal->setAtomic(AO); +const DataLayout &LoadDL = OldVal->getModule()->getDataLayout(); +unsigned LoadSize = +LoadDL.getTypeStoreSize(OldVal->getPointerOperand()->getType()); +OpenMPIRBuilder::AtomicInfo atomicInfo(&Builder, XElemTy, LoadSize * 8, + LoadSize * 8, OldVal->getAlign(), + OldVal->getAlign(), true, X); +auto AtomicLoadRes = atomicInfo.EmitAtomicLoadLibcall(AO); +BasicBlock *CurBB = Builder.GetInsertBlock(); +Instruction *CurBBTI = CurBB->getTerminator(); +CurBBTI = CurBBTI ? CurBBTI : Builder.CreateUnreachable(); +BasicBlock *ExitBB = +CurBB->splitBasicBlock(CurBBTI, X->getName() + ".atomic.exit"); +BasicBlock *ContBB = CurBB->splitBasicBlock(CurBB->getTerminator(), +X->getName() + ".atomic.cont"); +ContBB->getTerminator()->eraseFromParent(); +Builder.restoreIP(AllocaIP); +AllocaInst *NewAtomicAddr = Builder.CreateAlloca(XElemTy); +NewAtomicAddr->setName(X->getName() + "x.new.val"); +Builder.SetInsertPoint(ContBB); +llvm::PHINode *PHI = Builder.CreatePHI(OldVal->getType(), 2); +PHI->addIncoming(AtomicLoadRes.first, CurBB); +Value *OldExprVal = PHI; +Value *Upd = UpdateOp(OldExprVal, Builder); +Builder.CreateStore(Upd, NewAtomicAddr); +AtomicOrdering Failure = +llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(AO); +auto Result = atomicInfo.EmitAtomicCompareExchangeLibcall( +AtomicLoadRes.second, NewAtomicAddr, AO, Failure); +LoadInst *PHILoad = Builder.CreateLoad(XElemTy, Result.first); +PHI->addIncoming(PHILoad, Builder.GetInsertBlock()); +Builder.CreateCondBr(Result.second, ExitBB, ContBB); +OldVal->eraseFromParent(); +Res.first = OldExprVal; +Res.second = Upd; + +if (UnreachableInst *ExitTI = +dyn_cast(ExitBB->getTerminator())) { + CurBBTI->eraseFromParent(); + Builder.SetInsertPoint(ExitBB); +} else { + Builder.SetInsertPoint(ExitTI); Meinersbur wrote: Could you add some comment explaining the code+control flow that is generated here? https://github.com/llvm/llvm-project/pull/92364 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [OpenMPIRBuilder] Emit __atomic_load and __atomic_compare_exchange libcalls for complex types in atomic update (PR #92364)
@@ -6033,6 +6034,52 @@ std::pair OpenMPIRBuilder::emitAtomicUpdate( Res.second = Res.first; else Res.second = emitRMWOpAsInstruction(Res.first, Expr, RMWOp); + } else if (RMWOp == llvm::AtomicRMWInst::BinOp::BAD_BINOP) { +LoadInst *OldVal = +Builder.CreateLoad(XElemTy, X, X->getName() + ".atomic.load"); +OldVal->setAtomic(AO); +const DataLayout &LoadDL = OldVal->getModule()->getDataLayout(); +unsigned LoadSize = +LoadDL.getTypeStoreSize(OldVal->getPointerOperand()->getType()); +OpenMPIRBuilder::AtomicInfo atomicInfo(&Builder, XElemTy, LoadSize * 8, + LoadSize * 8, OldVal->getAlign(), + OldVal->getAlign(), true, X); +auto AtomicLoadRes = atomicInfo.EmitAtomicLoadLibcall(AO); +BasicBlock *CurBB = Builder.GetInsertBlock(); +Instruction *CurBBTI = CurBB->getTerminator(); +CurBBTI = CurBBTI ? CurBBTI : Builder.CreateUnreachable(); +BasicBlock *ExitBB = +CurBB->splitBasicBlock(CurBBTI, X->getName() + ".atomic.exit"); +BasicBlock *ContBB = CurBB->splitBasicBlock(CurBB->getTerminator(), +X->getName() + ".atomic.cont"); +ContBB->getTerminator()->eraseFromParent(); +Builder.restoreIP(AllocaIP); +AllocaInst *NewAtomicAddr = Builder.CreateAlloca(XElemTy); +NewAtomicAddr->setName(X->getName() + "x.new.val"); +Builder.SetInsertPoint(ContBB); +llvm::PHINode *PHI = Builder.CreatePHI(OldVal->getType(), 2); +PHI->addIncoming(AtomicLoadRes.first, CurBB); +Value *OldExprVal = PHI; +Value *Upd = UpdateOp(OldExprVal, Builder); +Builder.CreateStore(Upd, NewAtomicAddr); +AtomicOrdering Failure = +llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(AO); +auto Result = atomicInfo.EmitAtomicCompareExchangeLibcall( Meinersbur wrote: ```suggestion auto Result = atomicInfo.EmitAtomicCompareExchange( ``` The decision of whether to to use libcall should be made by AtomicInfo itself. https://github.com/llvm/llvm-project/pull/92364 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [OpenMPIRBuilder] Emit __atomic_load and __atomic_compare_exchange libcalls for complex types in atomic update (PR #92364)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/92364 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [OpenMPIRBuilder] Emit __atomic_load and __atomic_compare_exchange libcalls for complex types in atomic update (PR #92364)
https://github.com/Meinersbur commented: I see you squashed in my proposed refactoring of AtomicInfo. I think it should be its own PR. It also was just a sketch and needs to be completed (`check-clang` is failing) and needs some cleanup (`auto` -> type, `emitAtomicLibcalls2`). Ideally, it would be NFC for clang. I was hoping you would continue with my sketch, but I could work on it as well. https://github.com/llvm/llvm-project/pull/92364 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] Avoid object libraries in the VS IDE (PR #93519)
Meinersbur wrote: @dpalermo I added fix as PR #98072 https://github.com/llvm/llvm-project/pull/93519 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)
Meinersbur wrote: Using git bisect, I tracked down Flang not working anymore on Windows to this PR: ``` > flang-new hello.f90 -o hello flang-new version 19.0.0git Target: x86_64-pc-windows-msvc Thread model: posix InstalledDir: C:\Users\meinersbur\build\llvm-project\release\bin Build config: +assertions "C:\\Users\\meinersbur\\build\\llvm-project\\release\\bin\\flang-new" -fc1 -triple x86_64-pc-windows-msvc19.40.33811 -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -target-cpu x86-64 --dependent-lib=clang_rt.builtins-x86_64.lib -D_MT --dependent-lib=libcmt --dependent-lib=Fortran_main.static.lib --dependent-lib=FortranRuntime.static.lib --dependent-lib=FortranDecimal.static.lib -D_MSC_VER=1940 -D_MSC_FULL_VER=194033811 -D_WIN32 -D_M_X64=100 -mframe-pointer=none -o "C:\\Users\\MEINER~1\\AppData\\Local\\Temp\\hello-2ee671.o" -x f95-cpp-input hello.f90 "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.40.33807\\bin\\Hostx64\\x64\\link.exe" -out:hello "-libpath:C:\\Users\\meinersbur\\build\\llvm-project\\release\\lib" /WHOLEARCHIVE:Fortran_main.static.lib /subsystem:console "-libpath:C:\\Users\\meinersbur\\build\\llvm-project\\release\\lib\\clang\\19\\lib\\windows" -nologo "C:\\Users\\MEINER~1\\AppData\\Local\\Temp\\hello-2ee671.o" LINK : fatal error LNK1104: cannot open file 'clang_rt.builtins.lib' flang-new: error: linker command failed with exit code 1104 (use -v to see invocation) ``` Before this commit, `/DEFAULTLIB:clang_rt.builtins-x86_64.lib` the linking directive, now it is `/DEFAULTLIB:clang_rt.builtins-x86_64.lib`. Turns out, `clang_rt.builtins-x86_64.lib` is actually shipped with the MSVC compiler (`C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\\lib\x64`, possibly for Sanitizer support in MSVC), which makes the former work, but not the latter. With `-DLLVM_ENABLE_PROJECTS=compiler-rt`, the resource-dir `build\llvm-project\release\lib\clang\19\lib\windows` is filled with `clang_rt.builtins-x86_64.lib` et.al., but also changes it back to `/DEFAULTLIB:clang_rt.builtins-x86_64.lib`, and it works again. https://github.com/llvm/llvm-project/pull/87866 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Clang][OpenMP] Add reverse directive (PR #92916)
Meinersbur wrote: #92916 has been accepted, but waiting for this PR. https://github.com/llvm/llvm-project/pull/92916 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] Avoid object libraries in the VS IDE (PR #93519)
https://github.com/Meinersbur closed https://github.com/llvm/llvm-project/pull/93519 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -5229,13 +5362,288 @@ static void emitTargetOutlinedFunction( OMPBuilder.emitTargetRegionFunction(EntryInfo, GenerateOutlinedFunction, true, OutlinedFn, OutlinedFnID); } +OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetTask( +Function *OutlinedFn, Value *OutlinedFnID, +EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args, +Value *DeviceID, Value *RTLoc, OpenMPIRBuilder::InsertPointTy AllocaIP, +SmallVector &Dependencies, +bool HasNoWait) { + + // When we arrive at this function, the target region itself has been + // outlined into the function OutlinedFn. + // So at ths point, for + // -- + // void user_code_that_offloads(...) { + // omp target depend(..) map(from:a) map(to:b, c) + //a = b + c + // } + // + // -- + // + // we have + // + // -- + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // ;; target region has been outlined and now we need to + // ;; offload to it via a target task. + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + // We have to now do the following + // (i) Make an offloading call to outlined_device_function using the OpenMP + // RTL. See 'kernel_launch_function' in the pseudo code below. This is + // emitted by emitKernelLaunch + // (ii) Create a task entry point function that calls kernel_launch_function + // and is the entry point for the target task. See + // '@.omp_target_task_proxy_func in the pseudocode below. + // (iii) Create a task with the task entry point created in (ii) + // + // That is we create the following + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // + // %structArg = alloca { ptr, ptr, ptr }, align 8 + // %strucArg[0] = %.offload_baseptrs + // %strucArg[1] = %.offload_ptrs + // %strucArg[2] = %.offload_mappers + // proxy_target_task = @__kmpc_omp_task_alloc(..., + // @.omp_target_task_proxy_func) + // memcpy(proxy_target_task->shareds, %structArg, sizeof(structArg)) + // dependencies_array = ... + // ;; if nowait not present + // call @__kmpc_omp_wait_deps(..., dependencies_array) + // call @__kmpc_omp_task_begin_if0(...) + // call @ @.omp_target_task_proxy_func(i32 thread_id, ptr + // %proxy_target_task) call @__kmpc_omp_task_complete_if0(...) + // } + // + // define internal void @.omp_target_task_proxy_func(i32 %thread.id, + // ptr %task) { + // %structArg = alloca {ptr, ptr, ptr} + // %shared_data = load (getelementptr %task, 0, 0) + // mempcy(%structArg, %shared_data, sizeof(structArg)) + // kernel_launch_function(%thread.id, %structArg) + // } + // + // We need the proxy function because the signature of the task entry point + // expected by kmpc_omp_task is always the same and will be different from + // that of the kernel_launch function. + // + // kernel_launch_function is generated by emitKernelLaunch and has the + // always_inline attribute. void kernel_launch_function(thread_id, + //structArg) + //alwaysinline { + // %kernel_args = alloca %struct.__tgt_kernel_arguments, align 8 + // offload_baseptrs = load(getelementptr structArg, 0, 0) + // offload_ptrs = load(getelementptr structArg, 0, 1) + // offload_mappers = load(getelementptr structArg, 0, 2) + // ; setup kernel_args using offload_baseptrs, offload_ptrs and + // ; offload_mappers + // call i32 @__tgt_target_kernel(..., + // outlined_device_function, + // ptr %kernel_args) + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + BasicBlock *TargetTaskBodyBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.body"); + BasicBlock *TargetTaskAllocaBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.alloca"); + + InsertPointTy TargetTaskAllocaIP = + InsertPointTy(TargetTaskAllocaBB, TargetTaskAllocaBB->begin()); + InsertPointTy TargetTaskBodyIP = + InsertPointTy(TargetTaskBodyBB, TargetTaskBodyBB->begin()); + + OutlineInfo OI; + OI.En
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -681,7 +681,30 @@ convertOmpTeams(omp::TeamsOp op, llvm::IRBuilderBase &builder, ompLoc, bodyCB, numTeamsLower, numTeamsUpper, threadLimit, ifExpr)); return bodyGenStatus; } - +static void +buildDependData(std::optional depends, OperandRange dependVars, +LLVM::ModuleTranslation &moduleTranslation, +SmallVector &dds) { Meinersbur wrote: ```suggestion SmallVectorImpl &dds) { ``` https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -5229,13 +5362,288 @@ static void emitTargetOutlinedFunction( OMPBuilder.emitTargetRegionFunction(EntryInfo, GenerateOutlinedFunction, true, OutlinedFn, OutlinedFnID); } +OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetTask( +Function *OutlinedFn, Value *OutlinedFnID, +EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args, +Value *DeviceID, Value *RTLoc, OpenMPIRBuilder::InsertPointTy AllocaIP, +SmallVector &Dependencies, +bool HasNoWait) { + + // When we arrive at this function, the target region itself has been + // outlined into the function OutlinedFn. + // So at ths point, for + // -- + // void user_code_that_offloads(...) { + // omp target depend(..) map(from:a) map(to:b, c) + //a = b + c + // } + // + // -- + // + // we have + // + // -- + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // ;; target region has been outlined and now we need to + // ;; offload to it via a target task. + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + // We have to now do the following + // (i) Make an offloading call to outlined_device_function using the OpenMP + // RTL. See 'kernel_launch_function' in the pseudo code below. This is + // emitted by emitKernelLaunch + // (ii) Create a task entry point function that calls kernel_launch_function + // and is the entry point for the target task. See + // '@.omp_target_task_proxy_func in the pseudocode below. + // (iii) Create a task with the task entry point created in (ii) + // + // That is we create the following + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // + // %structArg = alloca { ptr, ptr, ptr }, align 8 + // %strucArg[0] = %.offload_baseptrs + // %strucArg[1] = %.offload_ptrs + // %strucArg[2] = %.offload_mappers + // proxy_target_task = @__kmpc_omp_task_alloc(..., + // @.omp_target_task_proxy_func) + // memcpy(proxy_target_task->shareds, %structArg, sizeof(structArg)) + // dependencies_array = ... + // ;; if nowait not present + // call @__kmpc_omp_wait_deps(..., dependencies_array) + // call @__kmpc_omp_task_begin_if0(...) + // call @ @.omp_target_task_proxy_func(i32 thread_id, ptr + // %proxy_target_task) call @__kmpc_omp_task_complete_if0(...) + // } + // + // define internal void @.omp_target_task_proxy_func(i32 %thread.id, + // ptr %task) { + // %structArg = alloca {ptr, ptr, ptr} + // %shared_data = load (getelementptr %task, 0, 0) + // mempcy(%structArg, %shared_data, sizeof(structArg)) + // kernel_launch_function(%thread.id, %structArg) + // } + // + // We need the proxy function because the signature of the task entry point + // expected by kmpc_omp_task is always the same and will be different from + // that of the kernel_launch function. + // + // kernel_launch_function is generated by emitKernelLaunch and has the + // always_inline attribute. void kernel_launch_function(thread_id, + //structArg) + //alwaysinline { + // %kernel_args = alloca %struct.__tgt_kernel_arguments, align 8 + // offload_baseptrs = load(getelementptr structArg, 0, 0) + // offload_ptrs = load(getelementptr structArg, 0, 1) + // offload_mappers = load(getelementptr structArg, 0, 2) + // ; setup kernel_args using offload_baseptrs, offload_ptrs and + // ; offload_mappers + // call i32 @__tgt_target_kernel(..., + // outlined_device_function, + // ptr %kernel_args) + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + BasicBlock *TargetTaskBodyBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.body"); + BasicBlock *TargetTaskAllocaBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.alloca"); + + InsertPointTy TargetTaskAllocaIP = + InsertPointTy(TargetTaskAllocaBB, TargetTaskAllocaBB->begin()); + InsertPointTy TargetTaskBodyIP = + InsertPointTy(TargetTaskBodyBB, TargetTaskBodyBB->begin()); + + OutlineInfo OI; + OI.En
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -5229,13 +5362,288 @@ static void emitTargetOutlinedFunction( OMPBuilder.emitTargetRegionFunction(EntryInfo, GenerateOutlinedFunction, true, OutlinedFn, OutlinedFnID); } +OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetTask( +Function *OutlinedFn, Value *OutlinedFnID, +EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args, +Value *DeviceID, Value *RTLoc, OpenMPIRBuilder::InsertPointTy AllocaIP, +SmallVector &Dependencies, +bool HasNoWait) { + + // When we arrive at this function, the target region itself has been + // outlined into the function OutlinedFn. + // So at ths point, for + // -- + // void user_code_that_offloads(...) { + // omp target depend(..) map(from:a) map(to:b, c) + //a = b + c + // } + // + // -- + // + // we have + // + // -- + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // ;; target region has been outlined and now we need to + // ;; offload to it via a target task. + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + // We have to now do the following + // (i) Make an offloading call to outlined_device_function using the OpenMP + // RTL. See 'kernel_launch_function' in the pseudo code below. This is + // emitted by emitKernelLaunch + // (ii) Create a task entry point function that calls kernel_launch_function + // and is the entry point for the target task. See + // '@.omp_target_task_proxy_func in the pseudocode below. + // (iii) Create a task with the task entry point created in (ii) + // + // That is we create the following + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // + // %structArg = alloca { ptr, ptr, ptr }, align 8 + // %strucArg[0] = %.offload_baseptrs + // %strucArg[1] = %.offload_ptrs + // %strucArg[2] = %.offload_mappers + // proxy_target_task = @__kmpc_omp_task_alloc(..., + // @.omp_target_task_proxy_func) + // memcpy(proxy_target_task->shareds, %structArg, sizeof(structArg)) + // dependencies_array = ... + // ;; if nowait not present + // call @__kmpc_omp_wait_deps(..., dependencies_array) + // call @__kmpc_omp_task_begin_if0(...) + // call @ @.omp_target_task_proxy_func(i32 thread_id, ptr + // %proxy_target_task) call @__kmpc_omp_task_complete_if0(...) + // } + // + // define internal void @.omp_target_task_proxy_func(i32 %thread.id, + // ptr %task) { + // %structArg = alloca {ptr, ptr, ptr} + // %shared_data = load (getelementptr %task, 0, 0) + // mempcy(%structArg, %shared_data, sizeof(structArg)) + // kernel_launch_function(%thread.id, %structArg) + // } + // + // We need the proxy function because the signature of the task entry point + // expected by kmpc_omp_task is always the same and will be different from + // that of the kernel_launch function. + // + // kernel_launch_function is generated by emitKernelLaunch and has the + // always_inline attribute. void kernel_launch_function(thread_id, + //structArg) + //alwaysinline { + // %kernel_args = alloca %struct.__tgt_kernel_arguments, align 8 + // offload_baseptrs = load(getelementptr structArg, 0, 0) + // offload_ptrs = load(getelementptr structArg, 0, 1) + // offload_mappers = load(getelementptr structArg, 0, 2) + // ; setup kernel_args using offload_baseptrs, offload_ptrs and + // ; offload_mappers + // call i32 @__tgt_target_kernel(..., + // outlined_device_function, + // ptr %kernel_args) + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + BasicBlock *TargetTaskBodyBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.body"); + BasicBlock *TargetTaskAllocaBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.alloca"); + + InsertPointTy TargetTaskAllocaIP = + InsertPointTy(TargetTaskAllocaBB, TargetTaskAllocaBB->begin()); + InsertPointTy TargetTaskBodyIP = + InsertPointTy(TargetTaskBodyBB, TargetTaskBodyBB->begin()); Meinersbur w
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -5229,13 +5362,288 @@ static void emitTargetOutlinedFunction( OMPBuilder.emitTargetRegionFunction(EntryInfo, GenerateOutlinedFunction, true, OutlinedFn, OutlinedFnID); } +OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetTask( +Function *OutlinedFn, Value *OutlinedFnID, +EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args, +Value *DeviceID, Value *RTLoc, OpenMPIRBuilder::InsertPointTy AllocaIP, +SmallVector &Dependencies, +bool HasNoWait) { + + // When we arrive at this function, the target region itself has been + // outlined into the function OutlinedFn. + // So at ths point, for + // -- + // void user_code_that_offloads(...) { + // omp target depend(..) map(from:a) map(to:b, c) + //a = b + c + // } + // + // -- + // + // we have + // + // -- + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // ;; target region has been outlined and now we need to + // ;; offload to it via a target task. + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + // We have to now do the following + // (i) Make an offloading call to outlined_device_function using the OpenMP + // RTL. See 'kernel_launch_function' in the pseudo code below. This is + // emitted by emitKernelLaunch + // (ii) Create a task entry point function that calls kernel_launch_function + // and is the entry point for the target task. See + // '@.omp_target_task_proxy_func in the pseudocode below. + // (iii) Create a task with the task entry point created in (ii) + // + // That is we create the following + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // + // %structArg = alloca { ptr, ptr, ptr }, align 8 + // %strucArg[0] = %.offload_baseptrs + // %strucArg[1] = %.offload_ptrs + // %strucArg[2] = %.offload_mappers + // proxy_target_task = @__kmpc_omp_task_alloc(..., + // @.omp_target_task_proxy_func) + // memcpy(proxy_target_task->shareds, %structArg, sizeof(structArg)) + // dependencies_array = ... + // ;; if nowait not present + // call @__kmpc_omp_wait_deps(..., dependencies_array) + // call @__kmpc_omp_task_begin_if0(...) + // call @ @.omp_target_task_proxy_func(i32 thread_id, ptr + // %proxy_target_task) call @__kmpc_omp_task_complete_if0(...) + // } + // + // define internal void @.omp_target_task_proxy_func(i32 %thread.id, + // ptr %task) { + // %structArg = alloca {ptr, ptr, ptr} + // %shared_data = load (getelementptr %task, 0, 0) + // mempcy(%structArg, %shared_data, sizeof(structArg)) + // kernel_launch_function(%thread.id, %structArg) + // } + // + // We need the proxy function because the signature of the task entry point + // expected by kmpc_omp_task is always the same and will be different from + // that of the kernel_launch function. + // + // kernel_launch_function is generated by emitKernelLaunch and has the + // always_inline attribute. void kernel_launch_function(thread_id, + //structArg) + //alwaysinline { + // %kernel_args = alloca %struct.__tgt_kernel_arguments, align 8 + // offload_baseptrs = load(getelementptr structArg, 0, 0) + // offload_ptrs = load(getelementptr structArg, 0, 1) + // offload_mappers = load(getelementptr structArg, 0, 2) + // ; setup kernel_args using offload_baseptrs, offload_ptrs and + // ; offload_mappers + // call i32 @__tgt_target_kernel(..., + // outlined_device_function, + // ptr %kernel_args) + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + BasicBlock *TargetTaskBodyBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.body"); + BasicBlock *TargetTaskAllocaBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.alloca"); + + InsertPointTy TargetTaskAllocaIP = + InsertPointTy(TargetTaskAllocaBB, TargetTaskAllocaBB->begin()); + InsertPointTy TargetTaskBodyIP = + InsertPointTy(TargetTaskBodyBB, TargetTaskBodyBB->begin()); + + OutlineInfo OI; + OI.En
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -5229,13 +5362,288 @@ static void emitTargetOutlinedFunction( OMPBuilder.emitTargetRegionFunction(EntryInfo, GenerateOutlinedFunction, true, OutlinedFn, OutlinedFnID); } +OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetTask( +Function *OutlinedFn, Value *OutlinedFnID, +EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args, +Value *DeviceID, Value *RTLoc, OpenMPIRBuilder::InsertPointTy AllocaIP, +SmallVector &Dependencies, +bool HasNoWait) { + + // When we arrive at this function, the target region itself has been + // outlined into the function OutlinedFn. + // So at ths point, for + // -- + // void user_code_that_offloads(...) { + // omp target depend(..) map(from:a) map(to:b, c) + //a = b + c + // } + // + // -- + // + // we have + // + // -- + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // ;; target region has been outlined and now we need to + // ;; offload to it via a target task. + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + // We have to now do the following + // (i) Make an offloading call to outlined_device_function using the OpenMP + // RTL. See 'kernel_launch_function' in the pseudo code below. This is + // emitted by emitKernelLaunch + // (ii) Create a task entry point function that calls kernel_launch_function + // and is the entry point for the target task. See + // '@.omp_target_task_proxy_func in the pseudocode below. + // (iii) Create a task with the task entry point created in (ii) + // + // That is we create the following + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // + // %structArg = alloca { ptr, ptr, ptr }, align 8 + // %strucArg[0] = %.offload_baseptrs + // %strucArg[1] = %.offload_ptrs + // %strucArg[2] = %.offload_mappers + // proxy_target_task = @__kmpc_omp_task_alloc(..., + // @.omp_target_task_proxy_func) + // memcpy(proxy_target_task->shareds, %structArg, sizeof(structArg)) + // dependencies_array = ... + // ;; if nowait not present + // call @__kmpc_omp_wait_deps(..., dependencies_array) + // call @__kmpc_omp_task_begin_if0(...) + // call @ @.omp_target_task_proxy_func(i32 thread_id, ptr + // %proxy_target_task) call @__kmpc_omp_task_complete_if0(...) + // } + // + // define internal void @.omp_target_task_proxy_func(i32 %thread.id, + // ptr %task) { + // %structArg = alloca {ptr, ptr, ptr} + // %shared_data = load (getelementptr %task, 0, 0) + // mempcy(%structArg, %shared_data, sizeof(structArg)) + // kernel_launch_function(%thread.id, %structArg) + // } + // + // We need the proxy function because the signature of the task entry point + // expected by kmpc_omp_task is always the same and will be different from + // that of the kernel_launch function. + // + // kernel_launch_function is generated by emitKernelLaunch and has the + // always_inline attribute. void kernel_launch_function(thread_id, + //structArg) + //alwaysinline { + // %kernel_args = alloca %struct.__tgt_kernel_arguments, align 8 + // offload_baseptrs = load(getelementptr structArg, 0, 0) + // offload_ptrs = load(getelementptr structArg, 0, 1) + // offload_mappers = load(getelementptr structArg, 0, 2) + // ; setup kernel_args using offload_baseptrs, offload_ptrs and + // ; offload_mappers + // call i32 @__tgt_target_kernel(..., + // outlined_device_function, + // ptr %kernel_args) + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + BasicBlock *TargetTaskBodyBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.body"); + BasicBlock *TargetTaskAllocaBB = + splitBB(Builder, /*CreateBranch=*/true, "target.task.alloca"); + + InsertPointTy TargetTaskAllocaIP = + InsertPointTy(TargetTaskAllocaBB, TargetTaskAllocaBB->begin()); + InsertPointTy TargetTaskBodyIP = + InsertPointTy(TargetTaskBodyBB, TargetTaskBodyBB->begin()); + + OutlineInfo OI; + OI.En
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -681,7 +681,30 @@ convertOmpTeams(omp::TeamsOp op, llvm::IRBuilderBase &builder, ompLoc, bodyCB, numTeamsLower, numTeamsUpper, threadLimit, ifExpr)); return bodyGenStatus; } - +static void Meinersbur wrote: [nit] ```suggestion static void ``` https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -5212,6 +5273,78 @@ static Function *createOutlinedFunction( return Func; } +// Create an entry point for a target task with the following. +// It'll have the following signature +// void @.omp_target_task_proxy_func(i32 %thread.id, ptr %task) +// This function is called from emitTargetTask once the +// code to launch the target kernel has been outlined already. +static Function *emitProxyTaskFunction(OpenMPIRBuilder &OMPBuilder, + IRBuilderBase &Builder, + CallInst *StaleCI) { + Module &M = OMPBuilder.M; + // CalledFunction is the target launch function, i.e. + // the function that sets up kernel arguments and calls + // __tgt_target_kernel to launch the kernel on the device. + Function *CalledFunction = StaleCI->getCalledFunction(); + OpenMPIRBuilder::InsertPointTy IP(StaleCI->getParent(), +StaleCI->getIterator()); + LLVMContext &Ctx = StaleCI->getParent()->getContext(); + Type *ThreadIDTy = Type::getInt32Ty(Ctx); + Type *TaskPtrTy = OMPBuilder.TaskPtr; + Type *TaskTy = OMPBuilder.Task; + auto ProxyFnTy = + FunctionType::get(Builder.getVoidTy(), {ThreadIDTy, TaskPtrTy}, +/* isVarArg */ false); + auto ProxyFn = Function::Create(ProxyFnTy, GlobalValue::InternalLinkage, + ".omp_target_task_proxy_func", + Builder.GetInsertBlock()->getModule()); + + BasicBlock *EntryBB = + BasicBlock::Create(Builder.getContext(), "entry", ProxyFn); + Builder.SetInsertPoint(EntryBB); + + bool HasShareds = StaleCI->arg_size() > 1; + // TODO: This is a temporary assert to prove to ourselves that + // the outlined target launch function is always going to have + // atmost two arguments if there is any data shared between + // host and device. + assert((!HasShareds || (StaleCI->arg_size() == 2)) && + "StaleCI with shareds should have exactly two arguments."); + if (HasShareds) { +AllocaInst *ArgStructAlloca = +dyn_cast(StaleCI->getArgOperand(1)); Meinersbur wrote: ```suggestion auto *ArgStructAlloca = dyn_cast(StaleCI->getArgOperand(1)); ``` https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -5212,6 +5273,78 @@ static Function *createOutlinedFunction( return Func; } +// Create an entry point for a target task with the following. +// It'll have the following signature +// void @.omp_target_task_proxy_func(i32 %thread.id, ptr %task) +// This function is called from emitTargetTask once the +// code to launch the target kernel has been outlined already. Meinersbur wrote: Could be a Doxygen comment ```suggestion /// Create an entry point for a target task with the following. /// It'll have the following signature /// void @.omp_target_task_proxy_func(i32 %thread.id, ptr %task) /// This function is called from emitTargetTask once the /// code to launch the target kernel has been outlined already. ``` https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -5212,6 +5273,78 @@ static Function *createOutlinedFunction( return Func; } +// Create an entry point for a target task with the following. +// It'll have the following signature +// void @.omp_target_task_proxy_func(i32 %thread.id, ptr %task) +// This function is called from emitTargetTask once the +// code to launch the target kernel has been outlined already. +static Function *emitProxyTaskFunction(OpenMPIRBuilder &OMPBuilder, + IRBuilderBase &Builder, + CallInst *StaleCI) { + Module &M = OMPBuilder.M; + // CalledFunction is the target launch function, i.e. + // the function that sets up kernel arguments and calls + // __tgt_target_kernel to launch the kernel on the device. + Function *CalledFunction = StaleCI->getCalledFunction(); + OpenMPIRBuilder::InsertPointTy IP(StaleCI->getParent(), +StaleCI->getIterator()); + LLVMContext &Ctx = StaleCI->getParent()->getContext(); + Type *ThreadIDTy = Type::getInt32Ty(Ctx); + Type *TaskPtrTy = OMPBuilder.TaskPtr; + Type *TaskTy = OMPBuilder.Task; + auto ProxyFnTy = + FunctionType::get(Builder.getVoidTy(), {ThreadIDTy, TaskPtrTy}, +/* isVarArg */ false); + auto ProxyFn = Function::Create(ProxyFnTy, GlobalValue::InternalLinkage, + ".omp_target_task_proxy_func", + Builder.GetInsertBlock()->getModule()); + + BasicBlock *EntryBB = + BasicBlock::Create(Builder.getContext(), "entry", ProxyFn); + Builder.SetInsertPoint(EntryBB); + + bool HasShareds = StaleCI->arg_size() > 1; + // TODO: This is a temporary assert to prove to ourselves that + // the outlined target launch function is always going to have + // atmost two arguments if there is any data shared between + // host and device. + assert((!HasShareds || (StaleCI->arg_size() == 2)) && + "StaleCI with shareds should have exactly two arguments."); + if (HasShareds) { +AllocaInst *ArgStructAlloca = +dyn_cast(StaleCI->getArgOperand(1)); +assert(ArgStructAlloca && + "Unable to find the alloca instruction corresponding to arguments " + "for extracted function"); +StructType *ArgStructType = +dyn_cast(ArgStructAlloca->getAllocatedType()); +LLVM_DEBUG(dbgs() << "ArgStructType = " << *ArgStructType << "\n"); + +AllocaInst *NewArgStructAlloca = +Builder.CreateAlloca(ArgStructType, nullptr, "structArg"); +Value *TaskT = ProxyFn->getArg(1); +Value *ThreadId = ProxyFn->getArg(0); +LLVM_DEBUG(dbgs() << "TaskT = " << *TaskT << "\n"); +Value *SharedsSize = +Builder.getInt64(M.getDataLayout().getTypeStoreSize(ArgStructType)); + +Value *Shareds = Builder.CreateStructGEP(TaskTy, TaskT, 0); +LoadInst *LoadShared = +Builder.CreateLoad(PointerType::getUnqual(Ctx), Shareds); + +// TODO: Are these alignment values correct? Meinersbur wrote: I think `NewArgStructAlloca->getAlign()` shold be sufficient. If the alloca/load doesn't have the align set explicitly, `memcpy` should apply pointer alignment itself. https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -5212,6 +5273,78 @@ static Function *createOutlinedFunction( return Func; } +// Create an entry point for a target task with the following. +// It'll have the following signature +// void @.omp_target_task_proxy_func(i32 %thread.id, ptr %task) +// This function is called from emitTargetTask once the +// code to launch the target kernel has been outlined already. +static Function *emitProxyTaskFunction(OpenMPIRBuilder &OMPBuilder, + IRBuilderBase &Builder, + CallInst *StaleCI) { + Module &M = OMPBuilder.M; + // CalledFunction is the target launch function, i.e. + // the function that sets up kernel arguments and calls + // __tgt_target_kernel to launch the kernel on the device. + Function *CalledFunction = StaleCI->getCalledFunction(); + OpenMPIRBuilder::InsertPointTy IP(StaleCI->getParent(), +StaleCI->getIterator()); + LLVMContext &Ctx = StaleCI->getParent()->getContext(); + Type *ThreadIDTy = Type::getInt32Ty(Ctx); + Type *TaskPtrTy = OMPBuilder.TaskPtr; + Type *TaskTy = OMPBuilder.Task; + auto ProxyFnTy = + FunctionType::get(Builder.getVoidTy(), {ThreadIDTy, TaskPtrTy}, +/* isVarArg */ false); + auto ProxyFn = Function::Create(ProxyFnTy, GlobalValue::InternalLinkage, + ".omp_target_task_proxy_func", + Builder.GetInsertBlock()->getModule()); + + BasicBlock *EntryBB = + BasicBlock::Create(Builder.getContext(), "entry", ProxyFn); + Builder.SetInsertPoint(EntryBB); + + bool HasShareds = StaleCI->arg_size() > 1; Meinersbur wrote: What is "Shareds"? https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
https://github.com/Meinersbur commented: Conceptually, looks quite good. Just some style comments. https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -5229,13 +5362,288 @@ static void emitTargetOutlinedFunction( OMPBuilder.emitTargetRegionFunction(EntryInfo, GenerateOutlinedFunction, true, OutlinedFn, OutlinedFnID); } +OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetTask( +Function *OutlinedFn, Value *OutlinedFnID, +EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args, +Value *DeviceID, Value *RTLoc, OpenMPIRBuilder::InsertPointTy AllocaIP, +SmallVector &Dependencies, +bool HasNoWait) { + + // When we arrive at this function, the target region itself has been + // outlined into the function OutlinedFn. + // So at ths point, for + // -- + // void user_code_that_offloads(...) { + // omp target depend(..) map(from:a) map(to:b, c) + //a = b + c + // } + // + // -- + // + // we have + // + // -- + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // ;; target region has been outlined and now we need to + // ;; offload to it via a target task. + // } + // void outlined_device_function(ptr a, ptr b, ptr c) { + // *a = *b + *c + // } + // + // We have to now do the following + // (i) Make an offloading call to outlined_device_function using the OpenMP + // RTL. See 'kernel_launch_function' in the pseudo code below. This is + // emitted by emitKernelLaunch + // (ii) Create a task entry point function that calls kernel_launch_function + // and is the entry point for the target task. See + // '@.omp_target_task_proxy_func in the pseudocode below. + // (iii) Create a task with the task entry point created in (ii) + // + // That is we create the following + // + // void user_code_that_offloads(...) { + // %.offload_baseptrs = alloca [3 x ptr], align 8 + // %.offload_ptrs = alloca [3 x ptr], align 8 + // %.offload_mappers = alloca [3 x ptr], align 8 + // + // %structArg = alloca { ptr, ptr, ptr }, align 8 + // %strucArg[0] = %.offload_baseptrs + // %strucArg[1] = %.offload_ptrs + // %strucArg[2] = %.offload_mappers + // proxy_target_task = @__kmpc_omp_task_alloc(..., + // @.omp_target_task_proxy_func) + // memcpy(proxy_target_task->shareds, %structArg, sizeof(structArg)) + // dependencies_array = ... + // ;; if nowait not present + // call @__kmpc_omp_wait_deps(..., dependencies_array) + // call @__kmpc_omp_task_begin_if0(...) + // call @ @.omp_target_task_proxy_func(i32 thread_id, ptr + // %proxy_target_task) call @__kmpc_omp_task_complete_if0(...) + // } + // + // define internal void @.omp_target_task_proxy_func(i32 %thread.id, + // ptr %task) { + // %structArg = alloca {ptr, ptr, ptr} + // %shared_data = load (getelementptr %task, 0, 0) + // mempcy(%structArg, %shared_data, sizeof(structArg)) + // kernel_launch_function(%thread.id, %structArg) + // } + // + // We need the proxy function because the signature of the task entry point + // expected by kmpc_omp_task is always the same and will be different from + // that of the kernel_launch function. + // + // kernel_launch_function is generated by emitKernelLaunch and has the + // always_inline attribute. void kernel_launch_function(thread_id, Meinersbur wrote: [nit] line break https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -1762,6 +1762,26 @@ class OpenMPIRBuilder { EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args, Value *DeviceID, Value *RTLoc, InsertPointTy AllocaIP); + /// Generate a target-task for the target construct + /// + /// \param OutlinedFn The outlined device/target kernel function. + /// \param OutlinedFnID The ooulined function ID. + /// \param EmitTargetCallFallbackCB Call back function to generate host + ///fallback code. + /// \param Args Data structure holding information about the kernel arguments. + /// \param DeviceID Identifier for the device via the 'device' clause. + /// \param RTLoc Source location identifier + /// \param AllocaIP The insertion point to be used for alloca instructions. + /// \param Dependencies Vector of DependData objects holding information of + ///dependencies as specified by the 'depend' clause. + /// \param HasNoWait True if the target construct had 'nowait' on it, false + ///otherwise + InsertPointTy emitTargetTask( + Function *OutlinedFn, Value *OutlinedFnID, + EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args, + Value *DeviceID, Value *RTLoc, InsertPointTy AllocaIP, + SmallVector &Dependencies, bool HasNoWait); Meinersbur wrote: ```suggestion ArrayRef Dependencies, bool HasNoWait); ``` https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -1698,6 +1701,64 @@ void OpenMPIRBuilder::createTaskyield(const LocationDescription &Loc) { emitTaskyieldImpl(Loc); } +// Processes the dependencies in Dependencies and does the following +// - Allocates space on the stack of an array of DependInfo objects +// - Populates each DependInfo object with relevant information of +// the corresponding dependence. +// - All code is inserted in the entry block of the current function. +static Value * +emitDepArray(OpenMPIRBuilder &OMPBuilder, + SmallVector &Dependencies) { + // Early return if we have no dependencies to process + if (!Dependencies.size()) +return nullptr; + + IRBuilderBase &Builder = OMPBuilder.Builder; + Type *DependInfo = OMPBuilder.DependInfo; + Module &M = OMPBuilder.M; + + Value *DepArray = nullptr; + if (Dependencies.size()) { +OpenMPIRBuilder::InsertPointTy OldIP = Builder.saveIP(); +Builder.SetInsertPoint( +&OldIP.getBlock()->getParent()->getEntryBlock().back()); Meinersbur wrote: ```suggestion Builder.SetInsertPoint( &OldIP.getBlock()->getParent()->getEntryBlock().getTerminator()); ``` just makes it more explicit. Did you consider explicitly passing the AllocaIP, could be needed with combined constructs. https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -1698,6 +1701,64 @@ void OpenMPIRBuilder::createTaskyield(const LocationDescription &Loc) { emitTaskyieldImpl(Loc); } +// Processes the dependencies in Dependencies and does the following +// - Allocates space on the stack of an array of DependInfo objects +// - Populates each DependInfo object with relevant information of +// the corresponding dependence. +// - All code is inserted in the entry block of the current function. +static Value * +emitDepArray(OpenMPIRBuilder &OMPBuilder, + SmallVector &Dependencies) { + // Early return if we have no dependencies to process + if (!Dependencies.size()) +return nullptr; + + IRBuilderBase &Builder = OMPBuilder.Builder; + Type *DependInfo = OMPBuilder.DependInfo; + Module &M = OMPBuilder.M; + + Value *DepArray = nullptr; + if (Dependencies.size()) { +OpenMPIRBuilder::InsertPointTy OldIP = Builder.saveIP(); +Builder.SetInsertPoint( +&OldIP.getBlock()->getParent()->getEntryBlock().back()); + +Type *DepArrayTy = ArrayType::get(DependInfo, Dependencies.size()); +DepArray = Builder.CreateAlloca(DepArrayTy, nullptr, ".dep.arr.addr"); + +unsigned P = 0; +for (const OpenMPIRBuilder::DependData &Dep : Dependencies) { + Value *Base = + Builder.CreateConstInBoundsGEP2_64(DepArrayTy, DepArray, 0, P); + // Store the pointer to the variable + Value *Addr = Builder.CreateStructGEP( + DependInfo, Base, + static_cast(RTLDependInfoFields::BaseAddr)); + Value *DepValPtr = + Builder.CreatePtrToInt(Dep.DepVal, Builder.getInt64Ty()); + Builder.CreateStore(DepValPtr, Addr); + // Store the size of the variable + Value *Size = Builder.CreateStructGEP( + DependInfo, Base, + static_cast(RTLDependInfoFields::Len)); + Builder.CreateStore(Builder.getInt64(M.getDataLayout().getTypeStoreSize( + Dep.DepValueType)), + Size); + // Store the dependency kind + Value *Flags = Builder.CreateStructGEP( + DependInfo, Base, + static_cast(RTLDependInfoFields::Flags)); + Builder.CreateStore( + ConstantInt::get(Builder.getInt8Ty(), + static_cast(Dep.DepKind)), + Flags); Meinersbur wrote: Consider adding a comment with a mock source of what is generate here: ``` DepArray[P].BaseAddre = ... ``` https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -2253,7 +2275,8 @@ class OpenMPIRBuilder { SmallVectorImpl &Inputs, GenMapInfoCallbackTy GenMapInfoCB, TargetBodyGenCallbackTy BodyGenCB, - TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB); + TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB, + SmallVector Dependencies = {}); Meinersbur wrote: ```suggestion ArrayRef Dependencies = {}); ``` https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
@@ -1698,6 +1701,64 @@ void OpenMPIRBuilder::createTaskyield(const LocationDescription &Loc) { emitTaskyieldImpl(Loc); } +// Processes the dependencies in Dependencies and does the following +// - Allocates space on the stack of an array of DependInfo objects +// - Populates each DependInfo object with relevant information of +// the corresponding dependence. +// - All code is inserted in the entry block of the current function. +static Value * +emitDepArray(OpenMPIRBuilder &OMPBuilder, + SmallVector &Dependencies) { + // Early return if we have no dependencies to process + if (!Dependencies.size()) Meinersbur wrote: ```suggestion if (Dependencies.empty()) ``` https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)
https://github.com/Meinersbur commented: Not a full a review, but the first notes that I started with https://github.com/llvm/llvm-project/pull/93977 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] Avoid object libraries in the VS IDE (PR #93519)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93519 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] Avoid object libraries in the VS IDE (PR #93519)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93519 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] Avoid object libraries in the VS IDE (PR #93519)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93519 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] Avoid object libraries in the VS IDE (PR #93519)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93519 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][OpenMP] Add -fopenmp-force-usm option to flang (PR #94359)
@@ -172,13 +174,17 @@ struct OffloadModuleOpts { module.getOperation())) { offloadMod.setIsTargetDevice(Opts.OpenMPIsTargetDevice); offloadMod.setIsGPU(Opts.OpenMPIsGPU); +if (Opts.OpenMPForceUSM) { + offloadMod.setRequires(mlir::omp::ClauseRequires::unified_shared_memory); +} if (Opts.OpenMPIsTargetDevice) { offloadMod.setFlags(Opts.OpenMPTargetDebug, Opts.OpenMPTeamSubscription, Opts.OpenMPThreadSubscription, Opts.OpenMPNoThreadState, Opts.OpenMPNoNestedParallelism, Opts.OpenMPVersion, Opts.NoGPULib); - if (!Opts.OMPHostIRFile.empty()) + if (!Opts.OMPHostIRFile.empty()) { Meinersbur wrote: [nit] unrelated change https://github.com/llvm/llvm-project/pull/94359 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][OpenMP] Add -fopenmp-force-usm option to flang (PR #94359)
@@ -766,6 +766,8 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ); // FIXME: Clang supports a whole bunch more flags here. Meinersbur wrote: The FIXME should stay behind all handled options https://github.com/llvm/llvm-project/pull/94359 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][OpenMP] Add -fopenmp-force-usm option to flang (PR #94359)
https://github.com/Meinersbur approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/94359 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][OpenMP] Add -fopenmp-force-usm option to flang (PR #94359)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/94359 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Clang][OpenMP] Add reverse directive (PR #92916)
Meinersbur wrote: @alexey-bataev ping https://github.com/llvm/llvm-project/pull/92916 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] Avoid object libraries in the VS IDE (PR #93519)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93519 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] Avoid object libraries in the VS IDE (PR #93519)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/93519 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] Avoid object libraries in the VS IDE (PR #93519)
https://github.com/Meinersbur ready_for_review https://github.com/llvm/llvm-project/pull/93519 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] Avoid object libraries in the VS IDE (PR #93519)
https://github.com/Meinersbur created https://github.com/llvm/llvm-project/pull/93519 As discussed in #89743, when using the Visual Studio solution generators, object library projects are displayed as a collection of non-editable *.obj files. To look for the corresponding source files, one has to browse (or search) to the library's obj.libname project. This patch tries to avoid this as much as possible. For Clang, there is already an exception for XCode. We handle MSVC_IDE the same way. For MLIR, this is more complicated. There are explicit references to the obj.libname target that only work when there is an object library. This patch cleans up the reasons for why an object library is needed: 1. The obj.libname is modified in the calling CMakeLists.txt. Note that with use-only references, `add_library( ALIAS )` could have been used. 2. An libMLIR.so (mlir-shlib) is also created. This works by adding linking the object libraries' object file into libMLIR.so (in addition to the library's own .so/.a). XCode is handled using the `-force_load` linker option instead. Windows is not even supported. This mechanism is different from LLVM's llvm-shlib that is created by linking static libraries with `-Wl,--whole-archive` (and `-Wl,-all_load` on MacOS). 3. The library might be added to an aggregate library. In-tree, the seems to be only libMLIR-C.so and the standalone example. It uses the object library and `-force_load` mechanism as above. Again, this is different from libLLVM-C.so. 4. Build an object library whenever it was before this patch, except when generating a Visual Studio solution. This condition could be removed, but I am trying to avoid build breakages of whatever configurations others use. This seem to not have worked with XCode because of the explicit references to obj.libname. I don't have access to XCode, but I tried to preserve the current working. IMHO there should be a common mechanism to build aggregate libraries for all LLVM projects instead of the 4 that we have now. As far as I can see, this means for LLVM there are the following changes on whether object libraries are created: 1. An object library is created even in XCode if FORCE_OBJECT_LIBRARY is set. I do not know how XCode handles it, but I also know CMake will abort otherwise. 2. An object library is created even for explicitly SHARED libraries for building libMLIR.so. Again, mlir-shlib does not work otherwise. libMLIR.so itself is created using SHARED so this is marking it as EXCLUDE_FROM_LIBMLIR. 3. For the second condition, it is now sensitive to whether the mlir-shlib is built at all (LLVM_BUILD_LLVM_DYLIB). However, an object library is still built using the fourth condition unless using the MSVC solution generator. That is, except with MSVC_IDE, when an object library was built before, it will also be an object library now. >From a08815e3b5e204c4f7eccbfbfcdb04d00ab7f895 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Tue, 28 May 2024 09:50:21 +0200 Subject: [PATCH] Avoid object libraries in the VS IDE --- clang/cmake/modules/AddClang.cmake | 6 ++- clang/lib/Support/CMakeLists.txt | 2 +- flang/cmake/modules/AddFlang.cmake | 21 +++--- mlir/cmake/modules/AddMLIR.cmake | 62 +++- mlir/lib/Dialect/GPU/CMakeLists.txt | 2 + mlir/lib/Target/LLVM/CMakeLists.txt | 4 ++ mlir/tools/mlir-shlib/CMakeLists.txt | 1 + 7 files changed, 70 insertions(+), 28 deletions(-) diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake index a5ef639187d9d..9d09be1936847 100644 --- a/clang/cmake/modules/AddClang.cmake +++ b/clang/cmake/modules/AddClang.cmake @@ -96,8 +96,12 @@ macro(add_clang_library name) else() set(LIBTYPE STATIC) endif() -if(NOT XCODE) +if(NOT XCODE AND NOT MSVC_IDE) # The Xcode generator doesn't handle object libraries correctly. + # The Visual Studio CMake generator does handle object libraries + # correctly, but it is preferable to list the libraries with their + # source files (instead of the object files and the source files in + # a separate target in the "Object Libraries" folder) list(APPEND LIBTYPE OBJECT) endif() set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name}) diff --git a/clang/lib/Support/CMakeLists.txt b/clang/lib/Support/CMakeLists.txt index 8ea5620052ed8..de06271e914ae 100644 --- a/clang/lib/Support/CMakeLists.txt +++ b/clang/lib/Support/CMakeLists.txt @@ -15,7 +15,7 @@ set(clangSupport_sources add_clang_library(clangSupport ${clangSupport_sources}) -if (NOT XCODE) +if (TARGET obj.clangSupport) add_library(clangSupport_tablegen ALIAS obj.clangSupport) elseif (NOT LLVM_LINK_LLVM_DYLIB) add_library(clangSupport_tablegen ALIAS clangSupport) diff --git a/flang/cmake/modules/AddFlang.cmake b/flang/cmake/modules/AddFlang.cmake index 3a5119b83831f..aeb4d862cf780 100644 --- a/flang/cmake/modules/AddFlang.cma
[clang-tools-extra] 5fb3830 - [clang-tools-extra] Remove redundant FOLDER property. NFC.
Author: Michael Kruse Date: 2024-05-27T17:42:32+02:00 New Revision: 5fb38307f372555cd22fd09ace86c3b1ccd2abb9 URL: https://github.com/llvm/llvm-project/commit/5fb38307f372555cd22fd09ace86c3b1ccd2abb9 DIFF: https://github.com/llvm/llvm-project/commit/5fb38307f372555cd22fd09ace86c3b1ccd2abb9.diff LOG: [clang-tools-extra] Remove redundant FOLDER property. NFC. This should have been removed from #89744 to address a review comment. Added: Modified: clang-tools-extra/clang-tidy/misc/CMakeLists.txt Removed: diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt index 0583671910526..35e29b9a7d136 100644 --- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt @@ -52,7 +52,6 @@ add_clang_library(clangTidyMiscModule genconfusable ClangDriverOptions ) -set_target_properties(clangTidyMiscModule PROPERTIES FOLDER "Clang Tools Extra/Libraries") clang_target_link_libraries(clangTidyMiscModule PRIVATE ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang-tools-extra] Revise IDE folder structure (PR #89744)
Meinersbur wrote: > This is basically names passed as FOLDER property are very generic. They are a little more specific than before (especially when considering Compiler-RT which put everything into "Compiler-RT/Misc"). Being more contextual would also require more maintenance, e.g. adding the right folder name for new artifacts. Only users of CMake's XCode or Visual Studio generators even see then, other would not even know something is off when this is not done. Hence the goal was to reduce maintenance, i.e. `add_clang_library` selects the folder name itself. It only has the type of the target available (here: library), so that's what it is restricted to. > Then this change is +- fine. Thank you https://github.com/llvm/llvm-project/pull/89744 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang-tools-extra] Revise IDE folder structure (PR #89744)
https://github.com/Meinersbur closed https://github.com/llvm/llvm-project/pull/89744 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang-tools-extra] Revise IDE folder structure (PR #89744)
Meinersbur wrote: > For me this entire change doesn't make sense. Could you elaborate on why? https://github.com/llvm/llvm-project/pull/89744 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang-tools-extra] Revise IDE folder structure (PR #89744)
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/89744 >From 6f39beb9ee58d7c377dce6ba8ce69e71da5b8e09 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Tue, 23 Apr 2024 12:55:15 +0200 Subject: [PATCH 1/6] [llvm] Revise IDE folder structure --- llvm/CMakeLists.txt | 12 ++- llvm/cmake/modules/AddLLVM.cmake | 83 ++- llvm/cmake/modules/AddOCaml.cmake | 5 +- llvm/cmake/modules/AddSphinxTarget.cmake | 3 + llvm/cmake/modules/CrossCompile.cmake | 4 + .../modules/LLVMDistributionSupport.cmake | 8 ++ .../modules/LLVMExternalProjectUtils.cmake| 25 +- llvm/cmake/modules/TableGen.cmake | 7 +- llvm/docs/CMakeLists.txt | 1 + llvm/examples/Kaleidoscope/CMakeLists.txt | 2 +- llvm/include/llvm/Support/CMakeLists.txt | 2 +- llvm/lib/Support/BLAKE3/CMakeLists.txt| 1 + llvm/runtimes/CMakeLists.txt | 23 + llvm/test/CMakeLists.txt | 6 +- llvm/tools/opt-viewer/CMakeLists.txt | 1 + .../InlineAdvisorPlugin/CMakeLists.txt| 3 +- .../Analysis/InlineOrderPlugin/CMakeLists.txt | 2 +- llvm/unittests/CMakeLists.txt | 2 +- llvm/unittests/DebugInfo/BTF/CMakeLists.txt | 2 - .../DebugInfo/CodeView/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/DWARF/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/GSYM/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/MSF/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/PDB/CMakeLists.txt | 2 - llvm/unittests/ExecutionEngine/CMakeLists.txt | 2 - .../ExecutionEngine/JITLink/CMakeLists.txt| 2 - .../ExecutionEngine/MCJIT/CMakeLists.txt | 2 - .../ExecutionEngine/Orc/CMakeLists.txt| 2 - .../Support/CommandLineInit/CMakeLists.txt| 4 - .../Support/DynamicLibrary/CMakeLists.txt | 4 +- llvm/unittests/Target/AArch64/CMakeLists.txt | 2 - llvm/unittests/Target/AMDGPU/CMakeLists.txt | 2 - llvm/unittests/Target/ARM/CMakeLists.txt | 2 - llvm/unittests/Target/CMakeLists.txt | 3 - .../unittests/Target/LoongArch/CMakeLists.txt | 2 - llvm/unittests/Target/PowerPC/CMakeLists.txt | 2 - llvm/unittests/Target/RISCV/CMakeLists.txt| 2 - .../Target/WebAssembly/CMakeLists.txt | 2 - llvm/unittests/Target/X86/CMakeLists.txt | 2 - .../Transforms/Coroutines/CMakeLists.txt | 2 - llvm/unittests/Transforms/IPO/CMakeLists.txt | 2 - .../Transforms/Scalar/CMakeLists.txt | 2 - .../unittests/Transforms/Utils/CMakeLists.txt | 2 - .../Transforms/Vectorize/CMakeLists.txt | 2 - .../tools/llvm-cfi-verify/CMakeLists.txt | 2 - .../tools/llvm-exegesis/CMakeLists.txt| 2 - llvm/unittests/tools/llvm-mca/CMakeLists.txt | 2 - .../tools/llvm-profdata/CMakeLists.txt| 2 - .../tools/llvm-profgen/CMakeLists.txt | 2 - llvm/utils/LLVMVisualizers/CMakeLists.txt | 2 +- llvm/utils/TableGen/Basic/CMakeLists.txt | 1 - llvm/utils/TableGen/CMakeLists.txt| 2 - llvm/utils/TableGen/Common/CMakeLists.txt | 1 - llvm/utils/lit/CMakeLists.txt | 4 +- llvm/utils/llvm-locstats/CMakeLists.txt | 2 +- llvm/utils/mlgo-utils/CMakeLists.txt | 2 +- 56 files changed, 159 insertions(+), 112 deletions(-) diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 43181af3bc195..48a6ab7d21f48 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -1124,7 +1124,7 @@ configure_file( add_custom_target(srpm COMMAND cpack -G TGZ --config CPackSourceConfig.cmake -B ${LLVM_SRPM_DIR}/SOURCES COMMAND rpmbuild -bs --define '_topdir ${LLVM_SRPM_DIR}' ${LLVM_SRPM_BINARY_SPECFILE}) -set_target_properties(srpm PROPERTIES FOLDER "Misc") +set_target_properties(srpm PROPERTIES FOLDER "LLVM/Misc") if(APPLE AND DARWIN_LTO_LIBRARY) set(CMAKE_EXE_LINKER_FLAGS @@ -1222,7 +1222,9 @@ if( LLVM_INCLUDE_UTILS ) add_subdirectory(utils/split-file) add_subdirectory(utils/mlgo-utils) if( LLVM_INCLUDE_TESTS ) +set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test") add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest) +set(LLVM_SUBPROJECT_TITLE) endif() else() if ( LLVM_INCLUDE_TESTS ) @@ -1286,7 +1288,7 @@ if( LLVM_INCLUDE_TESTS ) if(LLVM_ALL_LIT_DEPENDS OR LLVM_ALL_ADDITIONAL_TEST_DEPENDS) add_dependencies(test-depends ${LLVM_ALL_LIT_DEPENDS} ${LLVM_ALL_ADDITIONAL_TEST_DEPENDS}) endif() - set_target_properties(test-depends PROPERTIES FOLDER "Tests") + set_target_properties(test-depends PROPERTIES FOLDER "LLVM/Tests") add_dependencies(check-all test-depends) endif() @@ -1343,7 +1345,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) # Installing the headers needs to depend on generating any public # tablegen'd headers. add_custom_target(llvm-headers DEPENDS intrinsics_gen omp_gen) - s
[clang-tools-extra] [llvm] [clang-tools-extra] Revise IDE folder structure (PR #89744)
@@ -51,6 +52,7 @@ add_clang_library(clangTidyMiscModule genconfusable ClangDriverOptions ) +set_target_properties(clangTidyMiscModule PROPERTIES FOLDER "Clang Tools Extra/Libraries") Meinersbur wrote: This `set_target_properties` is redundant here, the same folder is already set by `add_clang_library` in #89741. This must be a leftover from cleaning up when I changed `add_clang_library` to set the folder instead of each of them individually. Thanks for noticing. https://github.com/llvm/llvm-project/pull/89744 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [libclc] [libcxx] [libcxxabi] [libunwind] [lld] [lldb] [llvm] [mlir] [openmp] [polly] [pstl] Update IDE Folders (PR #89153)
https://github.com/Meinersbur closed https://github.com/llvm/llvm-project/pull/89153 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libc] [libcxx] [libcxxabi] [libunwind] [llvm] [pstl] Revise IDE folder structure (PR #89755)
https://github.com/Meinersbur closed https://github.com/llvm/llvm-project/pull/89755 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libc] [libcxx] [libcxxabi] [libunwind] [llvm] [pstl] Revise IDE folder structure (PR #89755)
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/89755 >From 6f39beb9ee58d7c377dce6ba8ce69e71da5b8e09 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Tue, 23 Apr 2024 12:55:15 +0200 Subject: [PATCH 1/6] [llvm] Revise IDE folder structure --- llvm/CMakeLists.txt | 12 ++- llvm/cmake/modules/AddLLVM.cmake | 83 ++- llvm/cmake/modules/AddOCaml.cmake | 5 +- llvm/cmake/modules/AddSphinxTarget.cmake | 3 + llvm/cmake/modules/CrossCompile.cmake | 4 + .../modules/LLVMDistributionSupport.cmake | 8 ++ .../modules/LLVMExternalProjectUtils.cmake| 25 +- llvm/cmake/modules/TableGen.cmake | 7 +- llvm/docs/CMakeLists.txt | 1 + llvm/examples/Kaleidoscope/CMakeLists.txt | 2 +- llvm/include/llvm/Support/CMakeLists.txt | 2 +- llvm/lib/Support/BLAKE3/CMakeLists.txt| 1 + llvm/runtimes/CMakeLists.txt | 23 + llvm/test/CMakeLists.txt | 6 +- llvm/tools/opt-viewer/CMakeLists.txt | 1 + .../InlineAdvisorPlugin/CMakeLists.txt| 3 +- .../Analysis/InlineOrderPlugin/CMakeLists.txt | 2 +- llvm/unittests/CMakeLists.txt | 2 +- llvm/unittests/DebugInfo/BTF/CMakeLists.txt | 2 - .../DebugInfo/CodeView/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/DWARF/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/GSYM/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/MSF/CMakeLists.txt | 2 - llvm/unittests/DebugInfo/PDB/CMakeLists.txt | 2 - llvm/unittests/ExecutionEngine/CMakeLists.txt | 2 - .../ExecutionEngine/JITLink/CMakeLists.txt| 2 - .../ExecutionEngine/MCJIT/CMakeLists.txt | 2 - .../ExecutionEngine/Orc/CMakeLists.txt| 2 - .../Support/CommandLineInit/CMakeLists.txt| 4 - .../Support/DynamicLibrary/CMakeLists.txt | 4 +- llvm/unittests/Target/AArch64/CMakeLists.txt | 2 - llvm/unittests/Target/AMDGPU/CMakeLists.txt | 2 - llvm/unittests/Target/ARM/CMakeLists.txt | 2 - llvm/unittests/Target/CMakeLists.txt | 3 - .../unittests/Target/LoongArch/CMakeLists.txt | 2 - llvm/unittests/Target/PowerPC/CMakeLists.txt | 2 - llvm/unittests/Target/RISCV/CMakeLists.txt| 2 - .../Target/WebAssembly/CMakeLists.txt | 2 - llvm/unittests/Target/X86/CMakeLists.txt | 2 - .../Transforms/Coroutines/CMakeLists.txt | 2 - llvm/unittests/Transforms/IPO/CMakeLists.txt | 2 - .../Transforms/Scalar/CMakeLists.txt | 2 - .../unittests/Transforms/Utils/CMakeLists.txt | 2 - .../Transforms/Vectorize/CMakeLists.txt | 2 - .../tools/llvm-cfi-verify/CMakeLists.txt | 2 - .../tools/llvm-exegesis/CMakeLists.txt| 2 - llvm/unittests/tools/llvm-mca/CMakeLists.txt | 2 - .../tools/llvm-profdata/CMakeLists.txt| 2 - .../tools/llvm-profgen/CMakeLists.txt | 2 - llvm/utils/LLVMVisualizers/CMakeLists.txt | 2 +- llvm/utils/TableGen/Basic/CMakeLists.txt | 1 - llvm/utils/TableGen/CMakeLists.txt| 2 - llvm/utils/TableGen/Common/CMakeLists.txt | 1 - llvm/utils/lit/CMakeLists.txt | 4 +- llvm/utils/llvm-locstats/CMakeLists.txt | 2 +- llvm/utils/mlgo-utils/CMakeLists.txt | 2 +- 56 files changed, 159 insertions(+), 112 deletions(-) diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 43181af3bc195..48a6ab7d21f48 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -1124,7 +1124,7 @@ configure_file( add_custom_target(srpm COMMAND cpack -G TGZ --config CPackSourceConfig.cmake -B ${LLVM_SRPM_DIR}/SOURCES COMMAND rpmbuild -bs --define '_topdir ${LLVM_SRPM_DIR}' ${LLVM_SRPM_BINARY_SPECFILE}) -set_target_properties(srpm PROPERTIES FOLDER "Misc") +set_target_properties(srpm PROPERTIES FOLDER "LLVM/Misc") if(APPLE AND DARWIN_LTO_LIBRARY) set(CMAKE_EXE_LINKER_FLAGS @@ -1222,7 +1222,9 @@ if( LLVM_INCLUDE_UTILS ) add_subdirectory(utils/split-file) add_subdirectory(utils/mlgo-utils) if( LLVM_INCLUDE_TESTS ) +set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test") add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest) +set(LLVM_SUBPROJECT_TITLE) endif() else() if ( LLVM_INCLUDE_TESTS ) @@ -1286,7 +1288,7 @@ if( LLVM_INCLUDE_TESTS ) if(LLVM_ALL_LIT_DEPENDS OR LLVM_ALL_ADDITIONAL_TEST_DEPENDS) add_dependencies(test-depends ${LLVM_ALL_LIT_DEPENDS} ${LLVM_ALL_ADDITIONAL_TEST_DEPENDS}) endif() - set_target_properties(test-depends PROPERTIES FOLDER "Tests") + set_target_properties(test-depends PROPERTIES FOLDER "LLVM/Tests") add_dependencies(check-all test-depends) endif() @@ -1343,7 +1345,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) # Installing the headers needs to depend on generating any public # tablegen'd headers. add_custom_target(llvm-headers DEPENDS intrinsics_gen omp_gen) - s
[libc] [libcxx] [libcxxabi] [libunwind] [llvm] [pstl] Revise IDE folder structure (PR #89755)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/89755 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Revise IDE folder structure (PR #89746)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/89746 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Revise IDE folder structure (PR #89743)
Meinersbur wrote: Sorry for the notification noise. For some reason, when committing the parent PR, it closed this one. https://github.com/llvm/llvm-project/pull/89743 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Revise IDE folder structure (PR #89743)
https://github.com/Meinersbur closed https://github.com/llvm/llvm-project/pull/89743 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [llvm] [clang-tools-extra] Revise IDE folder structure (PR #89744)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/89744 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Revise IDE folder structure (PR #89743)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/89743 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [Clang][OpenMP] Add reverse directive (PR #92916)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/92916 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)
https://github.com/Meinersbur closed https://github.com/llvm/llvm-project/pull/91459 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/91459 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/91459 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/91459 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)
@@ -156,9 +156,9 @@ extern "C" void body(...) {} // IR-EMPTY: // IR-NEXT: [[FOR_INC]]: // IR-NEXT:%[[TMP34:.+]] = load i32, ptr %[[DOTTILE_0_IV_I]], align 4 -// IR-NEXT:%[[INC:.+]] = add nsw i32 %[[TMP34]], 1 +// IR-NEXT:%[[INC:.+]] = add i32 %[[TMP34]], 1 Meinersbur wrote: `nuw` would be an idea for a Clang extension in the footsteps of [vector extensions](https://releases.llvm.org/18.1.1/tools/clang/docs/LanguageExtensions.html#vectors-and-extended-vectors) or [`_ExtInt`](http://blog.llvm.org/2020/04/the-new-clang-extint-feature-provides.html) which also exposed a feature that LLVM always supported. E.g. ``` typedef unsigned nowrap_unsigned_t __attribute__((ext_no_wrap)); for (nowrap_unsigned_t i = 0; i < n; ++i) ``` or ``` int [[clang::]] ``` However, the language consequences are immense. https://github.com/llvm/llvm-project/pull/91459 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)
@@ -156,9 +156,9 @@ extern "C" void body(...) {} // IR-EMPTY: // IR-NEXT: [[FOR_INC]]: // IR-NEXT:%[[TMP34:.+]] = load i32, ptr %[[DOTTILE_0_IV_I]], align 4 -// IR-NEXT:%[[INC:.+]] = add nsw i32 %[[TMP34]], 1 +// IR-NEXT:%[[INC:.+]] = add i32 %[[TMP34]], 1 Meinersbur wrote: This is due to the change of using the type of `LoopHelper.NumIterations` (an unsigned integer) as the new loop's induction variable (instead of the original loop's iteration variable type). In iterator-based loops that type would be incompatible with `LoopHelper.NumIterations` which remains an integer. Even if the original loop variable is a signed integer (it could be a (`std::iota_view`)[https://en.cppreference.com/w/cpp/ranges/iota_view] over the same range), using and unsigned type is more correct as long as we start counting at 0. For instance, the loop ``` #pragma omp tile sizes(2) for (int i = INT_MIN; i < INT_MAX; ++i) ``` would overflow the `nsw` flag. The "most correct" fix would be to add the `nuw` flag. Unfortunately there is no AST expression we could create that would make CodeGen generate one. Alternatively, I could make generated loops start counting at `INT_MIN`. https://github.com/llvm/llvm-project/pull/91459 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)
@@ -182,17 +182,34 @@ class OMPLoopScope : public CodeGenFunction::RunCleanupsScope { } return false; }); - PreInits = cast_or_null(LD->getPreInits()); + PreInits = LD->getPreInits(); } else if (const auto *Tile = dyn_cast(&S)) { - PreInits = cast_or_null(Tile->getPreInits()); + PreInits = Tile->getPreInits(); } else if (const auto *Unroll = dyn_cast(&S)) { - PreInits = cast_or_null(Unroll->getPreInits()); + PreInits = Unroll->getPreInits(); } else { llvm_unreachable("Unknown loop-based directive kind."); } if (PreInits) { - for (const auto *I : PreInits->decls()) -CGF.EmitVarDecl(cast(*I)); + // CompoundStmts and DeclStmts are used as lists of PreInit statements and + // declarations. Since declarations must be visible in the the following + // that they initialize, unpack the ComboundStmt they are nested in. + SmallVector PreInitStmts; + if (auto *PreInitCompound = dyn_cast(PreInits)) +llvm::append_range(PreInitStmts, PreInitCompound->body()); + else +PreInitStmts.push_back(PreInits); + + for (const Stmt *S : PreInitStmts) { +// EmitStmt skips any OMPCapturedExprDecls, but needs to be emitted +// here. +if (auto *PreInitDecl = dyn_cast(S)) { Meinersbur wrote: Everything else is emitted in `CGF.EmitStmt(S);` at line 211. `CGF.EmitStmt(S)` does itself call `CGF.EmitVarDecl(S)` if passed a DeclStmts, so this special handling should not be necessary. It includes, however, an exception for `OMPCapturedExprDecl` (subclass of `VarDecl`) that are NOT emitted so we need to do this explicitly here. Otherwise, lines 203-212 would be just a single `CGF.EmitStmt(S)`. https://github.com/llvm/llvm-project/blob/a15b685c2d868eaf408d05baa50baa3c9f5cc740/clang/lib/CodeGen/CGDecl.cpp#L129 https://github.com/llvm/llvm-project/pull/91459 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)
@@ -182,17 +182,34 @@ class OMPLoopScope : public CodeGenFunction::RunCleanupsScope { } return false; }); - PreInits = cast_or_null(LD->getPreInits()); + PreInits = LD->getPreInits(); } else if (const auto *Tile = dyn_cast(&S)) { - PreInits = cast_or_null(Tile->getPreInits()); + PreInits = Tile->getPreInits(); } else if (const auto *Unroll = dyn_cast(&S)) { - PreInits = cast_or_null(Unroll->getPreInits()); + PreInits = Unroll->getPreInits(); } else { llvm_unreachable("Unknown loop-based directive kind."); } if (PreInits) { - for (const auto *I : PreInits->decls()) -CGF.EmitVarDecl(cast(*I)); + // CompoundStmts and DeclStmts are used as lists of PreInit statements and + // declarations. Since declarations must be visible in the the following + // that they initialize, unpack the ComboundStmt they are nested in. + SmallVector PreInitStmts; + if (auto *PreInitCompound = dyn_cast(PreInits)) Meinersbur wrote: This is explained in the summary. In essence, the init-statement for a C++20 foreach-loop does not need to be a DeclStmt, but can be an arbitrary Stmt. https://github.com/llvm/llvm-project/pull/91459 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [driver] Do not warn about unused plugin flags. (PR #88948)
Meinersbur wrote: @jakeegan Sorry, didn't see you comment over an extended weekend. https://github.com/llvm/llvm-project/pull/88948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)
https://github.com/Meinersbur closed https://github.com/llvm/llvm-project/pull/91345 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [Clang][OpenMP] Fix tile/unroll on iterator- and foreach-loops. (PR #91459)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/91459 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [Clang][OpenMP][Tile] Allow non-constant tile sizes. (PR #91345)
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/91345 >From 855a84814eb8d263427bce7837af61e67eb2db95 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Tue, 7 May 2024 14:47:45 +0200 Subject: [PATCH 1/6] Make unique instances --- clang/lib/Sema/SemaOpenMP.cpp | 75 +++ 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index cf5447f223d45..fff4c7350f0f7 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -15109,6 +15109,8 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef Clauses, SourceLocation StartLoc, SourceLocation EndLoc) { ASTContext &Context = getASTContext(); + Scope *CurScope = SemaRef.getCurScope(); + auto SizesClauses = OMPExecutableDirective::getClausesOfKind(Clauses); if (SizesClauses.empty()) { @@ -15137,6 +15139,7 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef Clauses, NumLoops, AStmt, nullptr, nullptr); SmallVector PreInits; + CaptureVars CopyTransformer(SemaRef); // Create iteration variables for the generated loops. SmallVector FloorIndVars; @@ -15200,19 +15203,30 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef Clauses, Expr *NumIterations = LoopHelper.NumIterations; auto *OrigCntVar = cast(LoopHelper.Counters[0]); QualType CntTy = OrigCntVar->getType(); -Expr *DimTileSize = SizesClause->getSizesRefs()[I]; -Scope *CurScope = SemaRef.getCurScope(); -// Commonly used variables. -DeclRefExpr *TileIV = buildDeclRefExpr(SemaRef, TileIndVars[I], CntTy, - OrigCntVar->getExprLoc()); -DeclRefExpr *FloorIV = buildDeclRefExpr(SemaRef, FloorIndVars[I], CntTy, -OrigCntVar->getExprLoc()); +// Commonly used variables. One of the constraints of an AST is that every +// node object must appear at most once, hence we define lamdas that create +// a new AST node at every use. +auto MakeDimTileSize = [&SemaRef = this->SemaRef, &CopyTransformer, I, +SizesClause]() -> Expr * { + Expr *DimTileSize = SizesClause->getSizesRefs()[I]; + return AssertSuccess(CopyTransformer.TransformExpr(DimTileSize)); +}; +auto MakeTileIVRef = [&SemaRef = this->SemaRef, &TileIndVars, I, CntTy, + OrigCntVar]() { + return buildDeclRefExpr(SemaRef, TileIndVars[I], CntTy, + OrigCntVar->getExprLoc()); +}; +auto MakeFloorIVRef = [&SemaRef = this->SemaRef, &FloorIndVars, I, CntTy, + OrigCntVar]() { + return buildDeclRefExpr(SemaRef, FloorIndVars[I], CntTy, + OrigCntVar->getExprLoc()); +}; // For init-statement: auto .tile.iv = .floor.iv -SemaRef.AddInitializerToDecl(TileIndVars[I], - SemaRef.DefaultLvalueConversion(FloorIV).get(), - /*DirectInit=*/false); +SemaRef.AddInitializerToDecl( +TileIndVars[I], SemaRef.DefaultLvalueConversion(MakeFloorIVRef()).get(), +/*DirectInit=*/false); Decl *CounterDecl = TileIndVars[I]; StmtResult InitStmt = new (Context) DeclStmt(DeclGroupRef::Create(Context, &CounterDecl, 1), @@ -15220,10 +15234,11 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef Clauses, if (!InitStmt.isUsable()) return StmtError(); -// For cond-expression: .tile.iv < min(.floor.iv + DimTileSize, -// NumIterations) -ExprResult EndOfTile = SemaRef.BuildBinOp( -CurScope, LoopHelper.Cond->getExprLoc(), BO_Add, FloorIV, DimTileSize); +// For cond-expression: +// .tile.iv < min(.floor.iv + DimTileSize, NumIterations) +ExprResult EndOfTile = +SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_Add, + MakeFloorIVRef(), MakeDimTileSize()); if (!EndOfTile.isUsable()) return StmtError(); ExprResult IsPartialTile = @@ -15238,25 +15253,28 @@ StmtResult SemaOpenMP::ActOnOpenMPTileDirective(ArrayRef Clauses, return StmtError(); ExprResult CondExpr = SemaRef.BuildBinOp(CurScope, LoopHelper.Cond->getExprLoc(), BO_LT, - TileIV, MinTileAndIterSpace.get()); + MakeTileIVRef(), MinTileAndIterSpace.get()); if (!CondExpr.isUsable()) return StmtError(); // For incr-statement: ++.tile.iv ExprResult IncrStmt = SemaRef.BuildUnaryOp( -CurScope, LoopHelper.Inc->getExprLoc(), UO_PreInc, TileIV); +CurScope, LoopHelper.Inc->getExprLoc(), UO_PreInc, MakeTileIVRef()); if (!IncrStmt.isUsable()) return StmtError(); // Statements