1. [clangd] Check if macro is already in the IdentifierTable before loading it (details)
  2. [MLIR][GPU][NVVM] Add warp synchronous matrix-multiply accumulate ops (details)
  3. [OpenMP] Make sure classes work on the device as they do on the host (details)
  4. [OpenMP] Ensure the DefaultMapperId has a location (details)
  5. [OpenMP] Overhaul `declare target` handling (details)
Commit 16c7829784f071d9fd4ae9da4cc8b3786a58018e by kadircet
[clangd] Check if macro is already in the IdentifierTable before loading it

Having nested macros in the C code could cause clangd to fail an assert in clang::Preprocessor::setLoadedMacroDirective() and crash.

#1 0x00000000007ace30 PrintStackTraceSignalHandler(void*) /qdelacru/llvm-project/llvm/lib/Support/Unix/
#2 0x00000000007aaded llvm::sys::RunSignalHandlers() /qdelacru/llvm-project/llvm/lib/Support/Signals.cpp:76:20
#3 0x00000000007ac7c1 SignalHandler(int) /qdelacru/llvm-project/llvm/lib/Support/Unix/
#4 0x00007f096604db20 __restore_rt (/lib64/
#5 0x00007f0964b307ff raise (/lib64/
#6 0x00007f0964b1ac35 abort (/lib64/
#7 0x00007f0964b1ab09 _nl_load_domain.cold.0 (/lib64/
#8 0x00007f0964b28de6 (/lib64/
#9 0x0000000001004d1a clang::Preprocessor::setLoadedMacroDirective(clang::IdentifierInfo*, clang::MacroDirective*, clang::MacroDirective*) /qdelacru/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp:116:5

An example of the code that causes the assert failure:

During code completion in clangd, the macros will be loaded in loadMainFilePreambleMacros() by iterating over the macro names and calling PreambleIdentifiers->get(). Since these macro names are store in a StringSet (has StringMap underlying container), the order of the iterator is not guaranteed to be same as the order seen in the source code.

When clangd is trying to resolve nested macros it sometimes attempts to load them out of order which causes a macro to be stored twice. In the example above, ECHO2 macro gets resolved first, but since it uses another macro that has not been resolved it will try to resolve/store that as well. Now there are two MacroDirectives stored in the Preprocessor, ECHO and ECHO2. When clangd tries to load the next macro, ECHO, the preprocessor fails an assert in clang::Preprocessor::setLoadedMacroDirective() because there is already a MacroDirective stored for that macro name.

In this diff, I check if the macro is already inside the IdentifierTable and if it is skip it so that it is not resolved twice.

Reviewed By: kadircet

Differential Revision:
The file was modifiedclang-tools-extra/clangd/CodeComplete.cpp
The file was modifiedclang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Commit 875eb523c13249114507cb8facd797773e278d9e by uday
[MLIR][GPU][NVVM] Add warp synchronous matrix-multiply accumulate ops

Add warp synchronous matrix-multiply accumulate ops in GPU and NVVM
dialect. Add following three ops to GPU dialect :-
  1.) subgroup_mma_load_matrix
  2.) subgroup_mma_store_matrix
  3.) subgroup_mma_compute
Add following three ops to NVVM dialect :-
  1.) wmma.m16n16k16.load.[a,b,c].[f16,f32].row.stride

Reviewed By: bondhugula, ftynse, ThomasRaoux

Differential Revision:
The file was modifiedmlir/include/mlir/Dialect/LLVMIR/
The file was modifiedmlir/include/mlir/Dialect/GPU/
The file was modifiedmlir/lib/Dialect/GPU/IR/GPUDialect.cpp
The file was modifiedmlir/test/Target/LLVMIR/nvvmir.mlir
The file was modifiedmlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
The file was modifiedmlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
The file was modifiedmlir/test/Dialect/LLVMIR/invalid.mlir
The file was modifiedmlir/include/mlir/Dialect/GPU/GPUDialect.h
The file was modifiedmlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp
The file was modifiedmlir/lib/Target/LLVMIR/ModuleTranslation.cpp
The file was modifiedmlir/test/Dialect/GPU/ops.mlir
The file was modifiedmlir/test/Dialect/GPU/invalid.mlir
The file was modifiedmlir/include/mlir/Dialect/GPU/
Commit 5d8d994dfbe38fe86b1d883daa9fd8e47cdc1376 by johannes
[OpenMP] Make sure classes work on the device as they do on the host

We do provide `operator delete(void*)` in `<new>` but it should be
available by default. This is mostly boilerplate to test it and the
unconditional include of `<new>` in the header we always in include
on the device.

Reviewed By: JonChesterfield

Differential Revision:
The file was modifiedclang/lib/Headers/openmp_wrappers/new
The file was addedclang/test/Headers/Inputs/include/new
The file was modifiedclang/test/Headers/Inputs/include/stdlib.h
The file was addedclang/test/Headers/target_include_new.cpp
The file was modifiedclang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
Commit 3f14596700093bce436ae27178c307e842398b65 by johannes
[OpenMP] Ensure the DefaultMapperId has a location

A user reported an assertion (below) but without a reproducer. I failed to
create a test myself but from the assertion one can derive the problem.
I set the DefaultMapperId location now to make sure this doesn't cause

clang-13: .../DeclTemplate.h:1940:
void clang::ClassTemplateSpecializationDecl::setPointOfInstantiation(clang::SourceLocation):
Assertion `Loc.isValid() && "point of instantiation must be valid!"' failed.

Reviewed By: JonChesterfield

Differential Revision:
The file was modifiedclang/lib/Sema/SemaOpenMP.cpp
Commit df729e2b82b3cfc602a2295b95b7fa55ab423e88 by johannes
[OpenMP] Overhaul `declare target` handling

This patch fixes various issues with our prior `declare target` handling
and extends it to support `omp begin declare target` as well.

This started with PR49649 in mind, trying to provide a way for users to
avoid the "ref" global use introduced for globals with internal linkage.
From there it went down the rabbit hole, e.g., all variables, even
`nohost` ones, were emitted into the device code so it was impossible to
determine if "ref" was needed late in the game (based on the name only).
To make it really useful, `begin declare target` was needed as it can
carry the `device_type`. Not emitting variables eagerly had a ripple
effect. Finally, the precedence of the (explicit) declare target list
items needed to be taken into account, that meant we cannot just look
for any declare target attribute to make a decision. This caused the
handling of functions to require fixup as well.

I tried to clean up things while I was at it, e.g., we should not "parse
declarations and defintions" as part of OpenMP parsing, this will always
break at some point. Instead, we keep track what region we are in and
act on definitions and declarations instead, this is what we do for
declare variant and other begin/end directives already.

  - new diagnosis for restrictions specificed in the standard,
  - delayed emission of globals not mentioned in an explicit
    list of a declare target,
  - omission of `nohost` globals on the host and `host` globals on the
  - no explicit parsing of declarations in-between `omp [begin] declare
    variant` and the corresponding end anymore, regular parsing instead,
  - precedence for explicit mentions in `declare target` lists over
    implicit mentions in the declaration-definition-seq, and
  - `omp allocate` declarations will now replace an earlier emitted
    global, if necessary.



The patch is larger than I hoped but it turns out that most changes do
on their own lead to "inconsistent states", which seem less desirable

After working through this I feel the standard should remove the
explicit declare target forms as the delayed emission is horrible.
That said, while we delay things anyway, it seems to me we check too
often for the current status even though that is often not sufficient to
act upon. There seems to be a lot of duplication that can probably be
trimmed down. Eagerly emitting some things seems pretty weak as an
argument to keep so much logic around.


Reviewed By: ABataev

Differential Revision:
The file was modifiedclang/test/OpenMP/nvptx_target_codegen.cpp
The file was modifiedclang/test/utils/update_cc_test_checks/Inputs/
The file was modifiedclang/test/OpenMP/sections_firstprivate_codegen.cpp
The file was modifiedclang/test/OpenMP/declare_target_codegen_globalization.cpp
The file was modifiedclang/lib/CodeGen/CodeGenModule.h
The file was modifiedclang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected
The file was modifiedclang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
The file was modifiedclang/test/OpenMP/taskgroup_codegen.cpp
The file was modifiedclang/include/clang/Parse/Parser.h
The file was modifiedclang/test/OpenMP/for_firstprivate_codegen.cpp
The file was modifiedclang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
The file was modifiedclang/include/clang/Sema/Sema.h
The file was modifiedclang/test/OpenMP/irbuilder_for_unsigned.c
The file was modifiedclang/test/OpenMP/parallel_for_codegen.cpp
The file was modifiedclang/test/OpenMP/task_codegen.cpp
The file was modifiedclang/lib/Parse/ParseOpenMP.cpp
The file was modifiedclang/test/OpenMP/declare_target_messages.cpp
The file was modifiedclang/test/OpenMP/nvptx_declare_variant_name_mangling.cpp
The file was modifiedclang/lib/CodeGen/CGOpenMPRuntime.cpp
The file was removedclang/test/OpenMP/declare_target_device_only_compilation.cpp
The file was modifiedclang/test/OpenMP/threadprivate_codegen.cpp
The file was modifiedclang/test/OpenMP/irbuilder_for_rangefor.cpp
The file was modifiedclang/test/OpenMP/parallel_master_taskloop_simd_codegen.cpp
The file was modifiedclang/test/Headers/nvptx_device_math_complex.c
The file was modifiedllvm/include/llvm/Frontend/OpenMP/
The file was modifiedclang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
The file was modifiedclang/lib/Sema/SemaDecl.cpp
The file was modifiedclang/include/clang/Basic/
The file was modifiedclang/test/OpenMP/irbuilder_nested_parallel_for.c
The file was modifiedclang/test/OpenMP/parallel_master_taskloop_codegen.cpp
The file was modifiedclang/test/OpenMP/remarks_parallel_in_multiple_target_state_machines.c
The file was modifiedclang/test/OpenMP/single_codegen.cpp
The file was modifiedclang/test/OpenMP/remarks_parallel_in_target_state_machine.c
The file was modifiedclang/test/OpenMP/irbuilder_nested_openmp_parallel_empty.c
The file was modifiedclang/test/OpenMP/tile_codegen.cpp
The file was modifiedclang/include/clang/Basic/
The file was modifiedclang/lib/AST/AttrImpl.cpp
The file was modifiedclang/test/OpenMP/single_firstprivate_codegen.cpp
The file was modifiedclang/lib/CodeGen/CGDecl.cpp
The file was modifiedclang/lib/CodeGen/CodeGenModule.cpp
The file was addedclang/test/OpenMP/declare_target_only_one_side_compilation.cpp
The file was modifiedclang/test/OpenMP/irbuilder_for_iterator.cpp
The file was modifiedclang/lib/Sema/SemaOpenMP.cpp
The file was modifiedclang/include/clang/Basic/