Skip to content

Commit f0aaefb

Browse files
committed
[OpenMP] Implicit USM Clause Solution
This uses an implicitly added OpenMP USM Clause when initializing SEMA to enforce the use of USM.
1 parent 4d5a1f6 commit f0aaefb

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ LANGOPT(OpenMPTeamSubscription , 1, 0, "Assume distributed loops do not have mo
260260
LANGOPT(OpenMPNoThreadState , 1, 0, "Assume that no thread in a parallel region will modify an ICV.")
261261
LANGOPT(OpenMPNoNestedParallelism , 1, 0, "Assume that no thread in a parallel region will encounter a parallel region")
262262
LANGOPT(OpenMPOffloadMandatory , 1, 0, "Assert that offloading is mandatory and do not create a host fallback.")
263+
LANGOPT(OpenMPForceUSM , 1, 0, "Enable OpenMP unified shared memory mode via compiler.")
263264
LANGOPT(NoGPULib , 1, 0, "Indicate a build without the standard GPU libraries.")
264265
LANGOPT(RenderScript , 1, 0, "RenderScript")
265266

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,6 +3451,10 @@ def fopenmp_offload_mandatory : Flag<["-"], "fopenmp-offload-mandatory">, Group<
34513451
Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>,
34523452
HelpText<"Do not create a host fallback if offloading to the device fails.">,
34533453
MarshallingInfoFlag<LangOpts<"OpenMPOffloadMandatory">>;
3454+
def fopenmp_force_usm : Flag<["-"], "fopenmp-force-usm">, Group<f_Group>,
3455+
Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>,
3456+
HelpText<"Force behvaior as if the user specified pragma omp requires unified_shared_memory.">,
3457+
MarshallingInfoFlag<LangOpts<"OpenMPForceUSM">>;
34543458
def fopenmp_target_jit : Flag<["-"], "fopenmp-target-jit">, Group<f_Group>,
34553459
Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CLOption]>,
34563460
HelpText<"Emit code that can be JIT compiled for OpenMP offloading. Implies -foffload-lto=full">;

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,12 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM)
10441044
? CGM.getLangOpts().OMPHostIRFile
10451045
: StringRef{});
10461046
OMPBuilder.setConfig(Config);
1047+
1048+
// The user forces the compiler to behave as if omp requires unified_shared_memory was given.
1049+
if (CGM.getLangOpts().OpenMPForceUSM) {
1050+
HasRequiresUnifiedSharedMemory = true;
1051+
OMPBuilder.Config.setHasRequiresUnifiedSharedMemory(true);
1052+
}
10471053
}
10481054

10491055
void CGOpenMPRuntime::clear() {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6382,6 +6382,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
63826382
CmdArgs.push_back("-fopenmp-assume-no-nested-parallelism");
63836383
if (Args.hasArg(options::OPT_fopenmp_offload_mandatory))
63846384
CmdArgs.push_back("-fopenmp-offload-mandatory");
6385+
if (Args.hasArg(options::OPT_fopenmp_force_usm))
6386+
CmdArgs.push_back("-fopenmp-force-usm");
63856387
break;
63866388
default:
63876389
// By default, if Clang doesn't know how to generate useful OpenMP code

0 commit comments

Comments
 (0)