diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp --- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp +++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp @@ -102,6 +102,11 @@ cl::desc("Inline all applicible functions on the device."), cl::Hidden, cl::init(false)); +static cl::opt + EnableVerboseRemarks("openmp-opt-verbose-remarks", cl::ZeroOrMore, + cl::desc("Enables more verbose remarks."), cl::Hidden, + cl::init(false)); + STATISTIC(NumOpenMPRuntimeCallsDeduplicated, "Number of OpenMP runtime calls deduplicated"); STATISTIC(NumOpenMPParallelRegionsDeleted, @@ -4034,11 +4039,25 @@ ChangeStatus Changed = ChangeStatus::UNCHANGED; if (SimplifiedValue.hasValue() && SimplifiedValue.getValue()) { - Instruction &CB = *getCtxI(); - A.changeValueAfterManifest(CB, **SimplifiedValue); - A.deleteAfterManifest(CB); + Instruction &I = *getCtxI(); + A.changeValueAfterManifest(I, **SimplifiedValue); + A.deleteAfterManifest(I); + + CallBase *CB = dyn_cast(&I); + auto Remark = [&](OptimizationRemark OR) { + if (auto *C = dyn_cast(*SimplifiedValue)) + return OR << "Replacing OpenMP runtime call " + << CB->getCalledFunction()->getName() << " with " + << ore::NV("FoldedValue", C->getZExtValue()) << "."; + else + return OR << "Replacing OpenMP runtime call " + << CB->getCalledFunction()->getName() << "."; + }; + + if (CB && EnableVerboseRemarks) + A.emitRemark(CB, "OMP180", Remark); - LLVM_DEBUG(dbgs() << TAG << "Folding runtime call: " << CB << " with " + LLVM_DEBUG(dbgs() << TAG << "Replacing runtime call: " << I << " with " << **SimplifiedValue << "\n"); Changed = ChangeStatus::CHANGED; diff --git a/openmp/docs/remarks/OMP180.rst b/openmp/docs/remarks/OMP180.rst new file mode 100644 --- /dev/null +++ b/openmp/docs/remarks/OMP180.rst @@ -0,0 +1,38 @@ +.. _omp180: + +Replacing OpenMP runtime call with . +==================================================================== + +This optimization remark indicates that analysis determined an OpenMP runtime +calls can be replaced with a constant value. This can occur when an OpenMP +runtime call that queried some internal state was found to always return a +single value after analysis. + +Example +------- + +This optimization will trigger for most target regions to simplify the runtime +once certain constants are known. This will trigger for internal runtime +functions so it requires enabling verbose remarks with +`-openmp-opt-verbose-remarks`. + +.. code-block:: c++ + + void foo() { + #pragma omp target parallel + { } + } + +.. code-block:: console + + $ clang test.c -fopenmp -fopenmp-targets=nvptx64 -O1 -Rpass=openmp-opt \ + -mllvm -openmp-opt-verbose-remarks + remark: Replacing runtime call __kmpc_is_spmd_exec_mode with 1. [OMP180] [-Rpass=openmp-opt] + remark: Replacing runtime call __kmpc_is_spmd_exec_mode with 1. [OMP180] [-Rpass=openmp-opt] + remark: Replacing runtime call __kmpc_parallel_level with 1. [OMP180] [-Rpass=openmp-opt] + remark: Replacing runtime call __kmpc_parallel_level with 1. [OMP180] [-Rpass=openmp-opt] + +Diagnostic Scope +---------------- + +OpenMP optimization remark. diff --git a/openmp/docs/remarks/OptimizationRemarks.rst b/openmp/docs/remarks/OptimizationRemarks.rst --- a/openmp/docs/remarks/OptimizationRemarks.rst +++ b/openmp/docs/remarks/OptimizationRemarks.rst @@ -39,6 +39,7 @@ OMP150 OMP160 OMP170 + OMP180 .. list-table:: :widths: 15 15 70 @@ -107,3 +108,6 @@ * - :ref:`OMP170 ` - Optimization - OpenMP runtime call deduplicated. + * - :ref:`OMP180 ` + - Optimization + - Replacing OpenMP runtime call with .