[all-commits] [llvm/llvm-project] 9ec501: [OpenMP] Refactor OMPScheduleType enum.

Michael Kruse via All-commits all-commits at lists.llvm.org
Mon Apr 18 12:04:38 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9ec501da76fc1559cadd6d6dac32766bf4376a3d
      https://github.com/llvm/llvm-project/commit/9ec501da76fc1559cadd6d6dac32766bf4376a3d
  Author: Michael Kruse <llvm-project at meinersbur.de>
  Date:   2022-04-18 (Mon, 18 Apr 2022)

  Changed paths:
    M clang/lib/CodeGen/CGStmtOpenMP.cpp
    M clang/test/OpenMP/irbuilder_for_unsigned_auto.c
    M clang/test/OpenMP/irbuilder_for_unsigned_dynamic.c
    M clang/test/OpenMP/irbuilder_for_unsigned_dynamic_chunked.c
    M clang/test/OpenMP/irbuilder_for_unsigned_runtime.c
    M llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
    M llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
    M llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
    M llvm/lib/Transforms/IPO/OpenMPOpt.cpp
    M llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
    M mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
    M mlir/test/Target/LLVMIR/openmp-llvm.mlir

  Log Message:
  -----------
  [OpenMP] Refactor OMPScheduleType enum.

The OMPScheduleType enum stores the constants from libomp's internal sched_type in kmp.h and are used by several kmp API functions. The enum values have an internal structure, namely each scheduling algorithm (e.g.) exists in four variants: unordered, orderend, normerge unordered, and nomerge ordered.

This patch (basically a followup to D114940) splits the "ordered" and "nomerge" bits into separate flags, as was already done for the "monotonic" and "nonmonotonic", so we can apply bit flags operations on them. It also now contains all possible combinations according to kmp's sched_type. Deriving of the OMPScheduleType enum from clause parameters has been moved form MLIR's OpenMPToLLVMIRTranslation.cpp to OpenMPIRBuilder to make available for clang as well. Since the primary purpose of the flag is the binary interface to libomp, it has been made more private to LLVMFrontend. The primary interface for generating worksharing-loop using OpenMPIRBuilder code becomes `applyWorkshareLoop` which derives the OMPScheduleType automatically and calls the appropriate emitter function.

While this is mostly a NFC refactor, it still applies the following functional changes:
 * The logic from OpenMPToLLVMIRTranslation to derive the OMPScheduleType also applies to clang. Most notably, it now applies the nonmonotonic flag for non-static schedules by default.
 * In OpenMPToLLVMIRTranslation, the nonmonotonic default flag was previously not applied if the simd modifier was used. I assume this was a bug, since the effect was due to `loop.schedule_modifier()` returning `mlir::omp::ScheduleModifier::none` instead of `llvm::Optional::None`.
 * In OpenMPToLLVMIRTranslation, the nonmonotonic default flag was set even if ordered was specified, in breach to what the comment before citing the OpenMP specification says. I assume this was an oversight.

The ordered flag with parameter was not considered in this patch. Changes will need to be made (e.g. adding/modifying function parameters) when support for it is added. The lengthy names of the enum values can be discussed, for the moment this is avoiding reusing previously existing enum value names such as `StaticChunked` to avoid confusion.

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D123403




More information about the All-commits mailing list