Skip to content

Commit 7eb899c

Browse files
committed
[OpenMP] Add more verbose remarks for runtime folding
We peform runtime folding, but do not currently emit remarks when it is performed. This is because it comes from the runtime library and is beyond the users control. However, people may still wish to view this and similar information easily, so we can enable this behaviour using a special flag to enable verbose remarks. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D109627
1 parent 8dae355 commit 7eb899c

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ static cl::opt<bool> AlwaysInlineDeviceFunctions(
102102
cl::desc("Inline all applicible functions on the device."), cl::Hidden,
103103
cl::init(false));
104104

105+
static cl::opt<bool>
106+
EnableVerboseRemarks("openmp-opt-verbose-remarks", cl::ZeroOrMore,
107+
cl::desc("Enables more verbose remarks."), cl::Hidden,
108+
cl::init(false));
109+
105110
STATISTIC(NumOpenMPRuntimeCallsDeduplicated,
106111
"Number of OpenMP runtime calls deduplicated");
107112
STATISTIC(NumOpenMPParallelRegionsDeleted,
@@ -4034,11 +4039,25 @@ struct AAFoldRuntimeCallCallSiteReturned : AAFoldRuntimeCall {
40344039
ChangeStatus Changed = ChangeStatus::UNCHANGED;
40354040

40364041
if (SimplifiedValue.hasValue() && SimplifiedValue.getValue()) {
4037-
Instruction &CB = *getCtxI();
4038-
A.changeValueAfterManifest(CB, **SimplifiedValue);
4039-
A.deleteAfterManifest(CB);
4042+
Instruction &I = *getCtxI();
4043+
A.changeValueAfterManifest(I, **SimplifiedValue);
4044+
A.deleteAfterManifest(I);
4045+
4046+
CallBase *CB = dyn_cast<CallBase>(&I);
4047+
auto Remark = [&](OptimizationRemark OR) {
4048+
if (auto *C = dyn_cast<ConstantInt>(*SimplifiedValue))
4049+
return OR << "Replacing OpenMP runtime call "
4050+
<< CB->getCalledFunction()->getName() << " with "
4051+
<< ore::NV("FoldedValue", C->getZExtValue()) << ".";
4052+
else
4053+
return OR << "Replacing OpenMP runtime call "
4054+
<< CB->getCalledFunction()->getName() << ".";
4055+
};
4056+
4057+
if (CB && EnableVerboseRemarks)
4058+
A.emitRemark<OptimizationRemark>(CB, "OMP180", Remark);
40404059

4041-
LLVM_DEBUG(dbgs() << TAG << "Folding runtime call: " << CB << " with "
4060+
LLVM_DEBUG(dbgs() << TAG << "Replacing runtime call: " << I << " with "
40424061
<< **SimplifiedValue << "\n");
40434062

40444063
Changed = ChangeStatus::CHANGED;

openmp/docs/remarks/OMP180.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. _omp180:
2+
3+
Replacing OpenMP runtime call <call> with <value>.
4+
====================================================================
5+
6+
This optimization remark indicates that analysis determined an OpenMP runtime
7+
calls can be replaced with a constant value. This can occur when an OpenMP
8+
runtime call that queried some internal state was found to always return a
9+
single value after analysis.
10+
11+
Example
12+
-------
13+
14+
This optimization will trigger for most target regions to simplify the runtime
15+
once certain constants are known. This will trigger for internal runtime
16+
functions so it requires enabling verbose remarks with
17+
`-openmp-opt-verbose-remarks`.
18+
19+
.. code-block:: c++
20+
21+
void foo() {
22+
#pragma omp target parallel
23+
{ }
24+
}
25+
26+
.. code-block:: console
27+
28+
$ clang test.c -fopenmp -fopenmp-targets=nvptx64 -O1 -Rpass=openmp-opt \
29+
-mllvm -openmp-opt-verbose-remarks
30+
remark: Replacing runtime call __kmpc_is_spmd_exec_mode with 1. [OMP180] [-Rpass=openmp-opt]
31+
remark: Replacing runtime call __kmpc_is_spmd_exec_mode with 1. [OMP180] [-Rpass=openmp-opt]
32+
remark: Replacing runtime call __kmpc_parallel_level with 1. [OMP180] [-Rpass=openmp-opt]
33+
remark: Replacing runtime call __kmpc_parallel_level with 1. [OMP180] [-Rpass=openmp-opt]
34+
35+
Diagnostic Scope
36+
----------------
37+
38+
OpenMP optimization remark.

openmp/docs/remarks/OptimizationRemarks.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ OpenMP Remarks
3939
OMP150
4040
OMP160
4141
OMP170
42+
OMP180
4243

4344
.. list-table::
4445
:widths: 15 15 70
@@ -107,3 +108,6 @@ OpenMP Remarks
107108
* - :ref:`OMP170 <omp170>`
108109
- Optimization
109110
- OpenMP runtime call <call> deduplicated.
111+
* - :ref:`OMP180 <omp180>`
112+
- Optimization
113+
- Replacing OpenMP runtime call <call> with <value>.

0 commit comments

Comments
 (0)