Skip to content

Commit 7de641f

Browse files
committed
Merge commit '83ddfa0d2247a9b6b512cfcedfa529b8bb573028' into llvmspirv_pulldown
2 parents 5301c8d + 83ddfa0 commit 7de641f

File tree

280 files changed

+29933
-1954
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+29933
-1954
lines changed

clang/docs/ClangCommandLineReference.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,11 @@ Emit OpenMP code only for SIMD-based constructs.
20392039

20402040
.. option:: -fopenmp-version=<arg>
20412041

2042+
.. option:: -fopenmp-extensions, -fno-openmp-extensions
2043+
2044+
Enable or disable all Clang extensions for OpenMP directives and clauses. By
2045+
default, they are enabled.
2046+
20422047
.. program:: clang1
20432048
.. option:: -fopenmp=<arg>
20442049
.. program:: clang

clang/docs/OpenMPSupport.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,20 @@ want to help with the implementation.
360360
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
361361
| task extension | nowait clause on taskwait | :none:`unclaimed` | |
362362
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
363+
364+
OpenMP Extensions
365+
=================
366+
367+
The following table provides a quick overview over various OpenMP
368+
extensions and their implementation status. These extensions are not
369+
currently defined by any standard, so links to associated LLVM
370+
documentation are provided. As these extensions mature, they will be
371+
considered for standardization. Please contact *openmp-dev* at
372+
*lists.llvm.org* to provide feedback.
373+
374+
+------------------------------+---------------------------------------------------------------------------+--------------------------+--------------------------------------------------------+
375+
|Category | Feature | Status | Reviews |
376+
+==============================+===========================================================================+==========================+========================================================+
377+
| device extension | `'ompx_hold' map type modifier | :good:`prototyped` | D106509, D106510 |
378+
| | <https://openmp.llvm.org/docs/openacc/OpenMPExtensions.html#ompx-hold>`_ | | |
379+
+------------------------------+---------------------------------------------------------------------------+--------------------------+--------------------------------------------------------+

clang/include/clang/AST/OpenMPClause.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5606,7 +5606,8 @@ class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
56065606
/// Map-type-modifiers for the 'map' clause.
56075607
OpenMPMapModifierKind MapTypeModifiers[NumberOfOMPMapClauseModifiers] = {
56085608
OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown,
5609-
OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown};
5609+
OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown,
5610+
OMPC_MAP_MODIFIER_unknown};
56105611

56115612
/// Location of map-type-modifiers for the 'map' clause.
56125613
SourceLocation MapTypeModifiersLoc[NumberOfOMPMapClauseModifiers];

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,8 +1303,8 @@ def err_omp_decl_in_declare_simd_variant : Error<
13031303
def err_omp_unknown_map_type : Error<
13041304
"incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'">;
13051305
def err_omp_unknown_map_type_modifier : Error<
1306-
"incorrect map type modifier, expected 'always', 'close', "
1307-
"%select{or 'mapper'|'mapper', or 'present'}0">;
1306+
"incorrect map type modifier, expected one of: 'always', 'close', 'mapper'"
1307+
"%select{|, 'present'}0%select{|, 'ompx_hold'}1">;
13081308
def err_omp_map_type_missing : Error<
13091309
"missing map type">;
13101310
def err_omp_map_type_modifier_missing : Error<

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10586,6 +10586,8 @@ def err_omp_map_shared_storage : Error<
1058610586
"variable already marked as mapped in current construct">;
1058710587
def err_omp_invalid_map_type_for_directive : Error<
1058810588
"%select{map type '%1' is not allowed|map type must be specified}0 for '#pragma omp %2'">;
10589+
def err_omp_invalid_map_type_modifier_for_directive : Error<
10590+
"map type modifier '%0' is not allowed for '#pragma omp %1'">;
1058910591
def err_omp_no_clause_for_directive : Error<
1059010592
"expected at least one %0 clause for '#pragma omp %1'">;
1059110593
def err_omp_threadprivate_in_clause : Error<

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")
231231
LANGOPT(CUDA , 1, 0, "CUDA")
232232
LANGOPT(HIP , 1, 0, "HIP")
233233
LANGOPT(OpenMP , 32, 0, "OpenMP support and version of OpenMP (31, 40 or 45)")
234+
LANGOPT(OpenMPExtensions , 1, 1, "Enable all Clang extensions for OpenMP directives and clauses")
234235
LANGOPT(OpenMPSimd , 1, 0, "Use SIMD only OpenMP support.")
235236
LANGOPT(OpenMPUseTLS , 1, 0, "Use TLS for threadprivates or runtime calls")
236237
LANGOPT(OpenMPIsDevice , 1, 0, "Generate code only for OpenMP target device")

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ OPENMP_MAP_MODIFIER_KIND(always)
123123
OPENMP_MAP_MODIFIER_KIND(close)
124124
OPENMP_MAP_MODIFIER_KIND(mapper)
125125
OPENMP_MAP_MODIFIER_KIND(present)
126+
// This is an OpenMP extension for the sake of OpenACC support.
127+
OPENMP_MAP_MODIFIER_KIND(ompx_hold)
126128

127129
// Modifiers for 'to' or 'from' clause.
128130
OPENMP_MOTION_MODIFIER_KIND(mapper)

clang/include/clang/Basic/OpenMPKinds.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_CLANG_BASIC_OPENMPKINDS_H
1515
#define LLVM_CLANG_BASIC_OPENMPKINDS_H
1616

17+
#include "clang/Basic/LangOptions.h"
1718
#include "llvm/ADT/StringRef.h"
1819
#include "llvm/Frontend/OpenMP/OMPConstants.h"
1920

@@ -167,7 +168,7 @@ enum OpenMPReductionClauseModifier {
167168
};
168169

169170
unsigned getOpenMPSimpleClauseType(OpenMPClauseKind Kind, llvm::StringRef Str,
170-
unsigned OpenMPVersion);
171+
const LangOptions &LangOpts);
171172
const char *getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type);
172173

173174
/// Checks if the specified directive is a directive with an associated

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,6 +2402,12 @@ def fopenmp : Flag<["-"], "fopenmp">, Group<f_Group>, Flags<[CC1Option, NoArgume
24022402
HelpText<"Parse OpenMP pragmas and generate parallel code.">;
24032403
def fno_openmp : Flag<["-"], "fno-openmp">, Group<f_Group>, Flags<[NoArgumentUnused]>;
24042404
def fopenmp_version_EQ : Joined<["-"], "fopenmp-version=">, Group<f_Group>, Flags<[CC1Option, NoArgumentUnused]>;
2405+
defm openmp_extensions: BoolFOption<"openmp-extensions",
2406+
LangOpts<"OpenMPExtensions">, DefaultTrue,
2407+
PosFlag<SetTrue, [CC1Option, NoArgumentUnused],
2408+
"Enable all Clang extensions for OpenMP directives and clauses">,
2409+
NegFlag<SetFalse, [CC1Option, NoArgumentUnused],
2410+
"Disable all Clang extensions for OpenMP directives and clauses">>;
24052411
def fopenmp_EQ : Joined<["-"], "fopenmp=">, Group<f_Group>;
24062412
def fopenmp_use_tls : Flag<["-"], "fopenmp-use-tls">, Group<f_Group>,
24072413
Flags<[NoArgumentUnused, HelpHidden]>;

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using namespace clang;
2121
using namespace llvm::omp;
2222

2323
unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
24-
unsigned OpenMPVersion) {
24+
const LangOptions &LangOpts) {
2525
switch (Kind) {
2626
case OMPC_default:
2727
return llvm::StringSwitch<unsigned>(Str)
@@ -59,7 +59,9 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
5959
.Case(#Name, static_cast<unsigned>(OMPC_MAP_MODIFIER_##Name))
6060
#include "clang/Basic/OpenMPKinds.def"
6161
.Default(OMPC_MAP_unknown);
62-
if (OpenMPVersion < 51 && Type == OMPC_MAP_MODIFIER_present)
62+
if (LangOpts.OpenMP < 51 && Type == OMPC_MAP_MODIFIER_present)
63+
return OMPC_MAP_MODIFIER_unknown;
64+
if (!LangOpts.OpenMPExtensions && Type == OMPC_MAP_MODIFIER_ompx_hold)
6365
return OMPC_MAP_MODIFIER_unknown;
6466
return Type;
6567
}
@@ -70,7 +72,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, StringRef Str,
7072
.Case(#Name, static_cast<unsigned>(OMPC_MOTION_MODIFIER_##Name))
7173
#include "clang/Basic/OpenMPKinds.def"
7274
.Default(OMPC_MOTION_MODIFIER_unknown);
73-
if (OpenMPVersion < 51 && Type == OMPC_MOTION_MODIFIER_present)
75+
if (LangOpts.OpenMP < 51 && Type == OMPC_MOTION_MODIFIER_present)
7476
return OMPC_MOTION_MODIFIER_unknown;
7577
return Type;
7678
}

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,8 @@ llvm::Value *CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction &CGF,
14481448
const char *FileName = PLoc.getFilename();
14491449
unsigned Line = PLoc.getLine();
14501450
unsigned Column = PLoc.getColumn();
1451-
SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FunctionName.c_str(), FileName,
1452-
Line, Column);
1451+
SrcLocStr =
1452+
OMPBuilder.getOrCreateSrcLocStr(FunctionName, FileName, Line, Column);
14531453
}
14541454
unsigned Reserved2Flags = getDefaultLocationReserved2Flags();
14551455
return OMPBuilder.getOrCreateIdent(SrcLocStr, llvm::omp::IdentFlag(Flags),
@@ -7269,6 +7269,14 @@ class MappableExprsHandler {
72697269
/// 0x800 is reserved for compatibility with XLC.
72707270
/// Produce a runtime error if the data is not already allocated.
72717271
OMP_MAP_PRESENT = 0x1000,
7272+
// Increment and decrement a separate reference counter so that the data
7273+
// cannot be unmapped within the associated region. Thus, this flag is
7274+
// intended to be used on 'target' and 'target data' directives because they
7275+
// are inherently structured. It is not intended to be used on 'target
7276+
// enter data' and 'target exit data' directives because they are inherently
7277+
// dynamic.
7278+
// This is an OpenMP extension for the sake of OpenACC support.
7279+
OMP_MAP_OMPX_HOLD = 0x2000,
72727280
/// Signal that the runtime library should use args as an array of
72737281
/// descriptor_dim pointers and use args_size as dims. Used when we have
72747282
/// non-contiguous list items in target update directive
@@ -7570,6 +7578,9 @@ class MappableExprsHandler {
75707578
llvm::find(MotionModifiers, OMPC_MOTION_MODIFIER_present) !=
75717579
MotionModifiers.end())
75727580
Bits |= OMP_MAP_PRESENT;
7581+
if (llvm::find(MapModifiers, OMPC_MAP_MODIFIER_ompx_hold) !=
7582+
MapModifiers.end())
7583+
Bits |= OMP_MAP_OMPX_HOLD;
75737584
if (IsNonContiguous)
75747585
Bits |= OMP_MAP_NON_CONTIG;
75757586
return Bits;
@@ -8923,6 +8934,20 @@ class MappableExprsHandler {
89238934
CombinedInfo.Types.back() |= OMP_MAP_PRESENT;
89248935
// Remove TARGET_PARAM flag from the first element
89258936
(*CurTypes.begin()) &= ~OMP_MAP_TARGET_PARAM;
8937+
// If any element has the ompx_hold modifier, then make sure the runtime
8938+
// uses the hold reference count for the struct as a whole so that it won't
8939+
// be unmapped by an extra dynamic reference count decrement. Add it to all
8940+
// elements as well so the runtime knows which reference count to check
8941+
// when determining whether it's time for device-to-host transfers of
8942+
// individual elements.
8943+
if (CurTypes.end() !=
8944+
llvm::find_if(CurTypes, [](OpenMPOffloadMappingFlags Type) {
8945+
return Type & OMP_MAP_OMPX_HOLD;
8946+
})) {
8947+
CombinedInfo.Types.back() |= OMP_MAP_OMPX_HOLD;
8948+
for (auto &M : CurTypes)
8949+
M |= OMP_MAP_OMPX_HOLD;
8950+
}
89268951

89278952
// All other current entries will be MEMBER_OF the combined entry
89288953
// (except for PTR_AND_OBJ entries which do not have a placeholder value

clang/lib/Driver/Compilation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ int Compilation::ExecuteCommand(const Command &C,
209209
!getDriver().CCPrintOptionsFilename.empty()) {
210210
std::error_code EC;
211211
OwnedStream.reset(new llvm::raw_fd_ostream(
212-
getDriver().CCPrintOptionsFilename.c_str(), EC,
212+
getDriver().CCPrintOptionsFilename, EC,
213213
llvm::sys::fs::OF_Append | llvm::sys::fs::OF_TextWithCRLF));
214214
if (EC) {
215215
getDriver().Diag(diag::err_drv_cc_print_options_failure)

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5988,7 +5988,7 @@ void Driver::BuildJobs(Compilation &C) const {
59885988
<< '\n';
59895989
Out.flush();
59905990
std::error_code EC;
5991-
llvm::raw_fd_ostream OS(CCPrintStatReportFilename.c_str(), EC,
5991+
llvm::raw_fd_ostream OS(CCPrintStatReportFilename, EC,
59925992
llvm::sys::fs::OF_Append |
59935993
llvm::sys::fs::OF_Text);
59945994
if (EC)

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ AMDGPUToolChain::detectSystemGPUs(const ArgList &Args,
754754

755755
std::string ErrorMessage;
756756
if (int Result = llvm::sys::ExecuteAndWait(
757-
Program.c_str(), {}, {}, Redirects, /* SecondsToWait */ 0,
757+
Program, {}, {}, Redirects, /* SecondsToWait */ 0,
758758
/*MemoryLimit*/ 0, &ErrorMessage)) {
759759
if (Result > 0) {
760760
ErrorMessage = "Exited with error code " + std::to_string(Result);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6215,6 +6215,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
62156215
options::OPT_fno_openmp_simd);
62166216
Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_enable_irbuilder);
62176217
Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
6218+
if (!Args.hasFlag(options::OPT_fopenmp_extensions,
6219+
options::OPT_fno_openmp_extensions, /*Default=*/true))
6220+
CmdArgs.push_back("-fno-openmp-extensions");
62186221
Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_cuda_number_of_sm_EQ);
62196222
Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_cuda_blocks_per_sm_EQ);
62206223
Args.AddAllArgs(CmdArgs,
@@ -6251,6 +6254,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
62516254
Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
62526255
options::OPT_fno_openmp_simd);
62536256
Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
6257+
if (!Args.hasFlag(options::OPT_fopenmp_extensions,
6258+
options::OPT_fno_openmp_extensions, /*Default=*/true))
6259+
CmdArgs.push_back("-fno-openmp-extensions");
62546260
}
62556261

62566262
const SanitizerArgs &Sanitize = TC.getSanitizerArgs();

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
669669
std::string CandidateRPath = TC.getArchSpecificLibPath();
670670
if (TC.getVFS().exists(CandidateRPath)) {
671671
CmdArgs.push_back("-rpath");
672-
CmdArgs.push_back(Args.MakeArgString(CandidateRPath.c_str()));
672+
CmdArgs.push_back(Args.MakeArgString(CandidateRPath));
673673
}
674674
}
675675

clang/lib/Driver/ToolChains/NetBSD.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
261261
const SanitizerArgs &SanArgs = ToolChain.getSanitizerArgs();
262262
if (SanArgs.needsSharedRt()) {
263263
CmdArgs.push_back("-rpath");
264-
CmdArgs.push_back(Args.MakeArgString(
265-
ToolChain.getCompilerRTPath().c_str()));
264+
CmdArgs.push_back(Args.MakeArgString(ToolChain.getCompilerRTPath()));
266265
}
267266

268267
unsigned Major, Minor, Micro;

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,8 +2131,7 @@ void CompilerInstance::createModuleFromSource(SourceLocation ImportLoc,
21312131
const FileEntry *ModuleMapFile = Other.getFileManager().getVirtualFile(
21322132
ModuleMapFileName, NullTerminatedSource.size(), 0);
21332133
Other.getSourceManager().overrideFileContents(
2134-
ModuleMapFile,
2135-
llvm::MemoryBuffer::getMemBuffer(NullTerminatedSource.c_str()));
2134+
ModuleMapFile, llvm::MemoryBuffer::getMemBuffer(NullTerminatedSource));
21362135

21372136
Other.BuiltModules = std::move(BuiltModules);
21382137
Other.DeleteBuiltModules = false;

0 commit comments

Comments
 (0)