platform/upstream/llvm.git
4 years ago[LLDB] Fix LinuxPTraceDefines_arm64sve.h for AArch64 Linux host
Muhammad Omair Javaid [Tue, 21 Jul 2020 09:02:06 +0000 (14:02 +0500)]
[LLDB] Fix LinuxPTraceDefines_arm64sve.h for AArch64 Linux host

LinuxPTraceDefines_arm64sve.h defines essential macros for manipulating
AArch64 SVE core dump registers. Add guard for aarch64/Linux hosts where
newer versions of ptrace.h or sigcontext.h might already define SVE macros.

Differential Revision: https://reviews.llvm.org/D83541

4 years ago[clangd] Fix assertions for D83826
Kirill Bobyrev [Tue, 21 Jul 2020 09:16:43 +0000 (11:16 +0200)]
[clangd] Fix assertions for D83826

FuzzyFindRequest's toProtobuf is called on the client side (hence
LocalIndexRoot must be present) and fromProtobuf - on the server.

4 years agoRevert 502f0cc0e38 "[GWP-ASan] Split the unwinder into segv/non-segv."
Hans Wennborg [Tue, 21 Jul 2020 09:06:33 +0000 (11:06 +0200)]
Revert 502f0cc0e38 "[GWP-ASan] Split the unwinder into segv/non-segv."

It was causing tests to fail in -DCOMPILER_RT_BUILD_BUILTINS=OFF builds:

   GwpAsan-Unittest :: ./GwpAsan-x86_64-Test/BacktraceGuardedPoolAllocator.DoubleFree
   GwpAsan-Unittest :: ./GwpAsan-x86_64-Test/BacktraceGuardedPoolAllocator.UseAfterFree

see comment on the code review.

> Summary:
> Splits the unwinder into a non-segv (for allocation/deallocation traces) and a
> segv unwinder. This ensures that implementations can select an accurate, slower
> unwinder in the segv handler (if they choose to use the GWP-ASan provided one).
> This is important as fast frame-pointer unwinders (like the sanitizer unwinder)
> don't like unwinding through signal handlers.
>
> Reviewers: morehouse, cryptoad
>
> Reviewed By: morehouse, cryptoad
>
> Subscribers: cryptoad, mgorny, eugenis, pcc, #sanitizers
>
> Tags: #sanitizers
>
> Differential Revision: https://reviews.llvm.org/D83994

This reverts commit 502f0cc0e3889229e923e187f38dda91324ae139.

4 years ago[SCCP] Add range metadata to call sites with known return ranges.
Florian Hahn [Tue, 21 Jul 2020 09:01:42 +0000 (10:01 +0100)]
[SCCP] Add range metadata to call sites with known return ranges.

If we inferred a range for the function return value, we can add !range
at all call-sites of the function, if the range does not include undef.

Reviewers: efriedma, davide, nikic

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D83952

4 years ago[clangd] Don't send invalid messages from remote index
Kirill Bobyrev [Tue, 21 Jul 2020 09:04:53 +0000 (11:04 +0200)]
[clangd] Don't send invalid messages from remote index

Summary:
Remote server should not send messages that are invalid and will cause problems
on the client side. The client should not be affected by server's failures
whenever possible.

Also add more error messages and logs.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83826

4 years ago[ADT] use is_base_of inplace of is_same for random_access_iterator_tag checks
Nathan James [Tue, 21 Jul 2020 08:55:14 +0000 (09:55 +0100)]
[ADT] use is_base_of inplace of is_same for random_access_iterator_tag checks

Replace `std::is_same<X, std::random_access_iterator_tag>` with `std::is_base_of<std::random_access_iterator_tag, X>` in STLExtra algos.

This doesn't have too much impact on LLVM internally as no structs derive from it.
However external projects embedding LLVM may use `std::contiguous_iterator_tag` which should be considered by these algorithms.
As well as any other potential tags people want to define derived from `std::random_access_iterator_tag`

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D84141

4 years ago[LLDB] Fix Arm/AArch64 Linux broken build
Muhammad Omair Javaid [Tue, 21 Jul 2020 08:34:08 +0000 (13:34 +0500)]
[LLDB] Fix Arm/AArch64 Linux broken build

This patch fixes build breakage on LLDB Arm/AArch64 Linux buildbots.

http://lab.llvm.org:8011/builders/lldb-aarch64-ubuntu/builds/6649
http://lab.llvm.org:8011/builders/lldb-arm-ubuntu/builds/1919

This build breakage was introduces by commit: 001c8e1fd9f09d3de9ff6e64bdac4b8ca681dfb4

4 years ago[NFC] Use FileCheck for llvm-reduce interesness test
Alex Richardson [Tue, 21 Jul 2020 07:56:40 +0000 (08:56 +0100)]
[NFC] Use FileCheck for llvm-reduce interesness test

This makes the test added in 6187eeb683d8c639282d437e6af585e9b7f9c93e
easier to understand since you no longer have to look at another script
to see if it's doing the right thing.

4 years ago[libcxx][lit] Simplify parsing of trailing executor arguments
Alex Richardson [Tue, 21 Jul 2020 07:35:47 +0000 (08:35 +0100)]
[libcxx][lit] Simplify parsing of trailing executor arguments

Adding a positional argparse.ONE_OR_MORE arguments will correctly remove
the "--" separator after --env and parse only the command. This also has
the advantage that misspelled flags raise an argparse error rather than
silently being added to the command to be executed.

I discovered this while adding a new commandline option to ssh.py to allow
passing additional arguments to the scp/ssh commands since this is required
for our CHERI CI where we need to pass `-F <custom_config_file>` to each
ssh/scp command to set various arguments such as the localhost port, usage
of controlmaster, etc. to speed up connections to our emulated QEMU systems.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D84096

4 years ago[mlir] Fix undefined behavior in Linalg utils getViewSizes
Alex Zinenko [Tue, 21 Jul 2020 07:53:28 +0000 (09:53 +0200)]
[mlir] Fix undefined behavior in Linalg utils getViewSizes

The utility function getViewSizes in Linalg has been recently updated to
support a different form of Linalg operations. In doing so, the code looking
like `smallvector.push_back(smallvector[i])` was introduced. Unlike std
vectors, this can lead to undefined behavior if the vector must grow upon
insertion: `smallvector[i]` returns a reference to the element, `push_back`
takes a const reference to the element, and then grows the vector storage
before accessing the referenced value. After the resize, the reference may
become dangling, which leads to undefined behavior detected by ASAN as
use-after-free. Work around the issue by forcing the value to be copied by
putting it into a temporary variable.

4 years ago[MLIR][SPIRVToLLVM] Conversion of SPIR-V branch ops
George Mitenkov [Tue, 21 Jul 2020 07:25:32 +0000 (10:25 +0300)]
[MLIR][SPIRVToLLVM] Conversion of SPIR-V branch ops

This patch introduces conversion for `spv.Branch` and `spv.BranchConditional`
ops. Branch weigths for `spv.BranchConditional` are not supported at the
moment, and conversion in this case fails.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D83784

4 years ago[clang] Set the error-bit for ill-formed semantic InitListExpr.
Haojian Wu [Tue, 21 Jul 2020 07:39:44 +0000 (09:39 +0200)]
[clang] Set the error-bit for ill-formed semantic InitListExpr.

When a semantic checking fails on a syntactic InitListExpr, we will
get an ill-formed semantic InitListExpr (e.g. some inits are nullptr),
using this semantic InitListExpr in clang (without setting the err-bits) is crashy.

Differential Revision: https://reviews.llvm.org/D84140

4 years ago[AST][RecoveryExpr] Preserve the invalid "undef_var" initializer.
Haojian Wu [Tue, 21 Jul 2020 07:36:49 +0000 (09:36 +0200)]
[AST][RecoveryExpr] Preserve the invalid "undef_var" initializer.

And don't invalidate the VarDecl if the type is known.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D81395

4 years agoUse typedef to represent storage type in FPOption and FPOptionsOverride
Serge Pavlov [Mon, 20 Jul 2020 07:47:45 +0000 (14:47 +0700)]
Use typedef to represent storage type in FPOption and FPOptionsOverride

Size of FPOption is now 14 bit, which is closed to the current limit
of 16 bits. Adding new properties to FPOption would require change of
the types, which represent storage of FPOption and FPOptionsOverride.
To facilitate this change, the storage types were changed from standard
integer types to typedefs defined inside the proper classes. Checks for
size of these storage types were added.

No functional changes intended.

Differential Revision: https://reviews.llvm.org/D84147

4 years ago[jitlink] Updating test file for GOT relocations for elf x86
Jared Wyles [Tue, 21 Jul 2020 07:19:48 +0000 (17:19 +1000)]
[jitlink] Updating  test file for GOT relocations for elf x86

4 years ago[ARM] More unpredictable VCVT instructions.
David Green [Tue, 21 Jul 2020 05:49:04 +0000 (06:49 +0100)]
[ARM] More unpredictable VCVT instructions.

These extra vcvt instructions were missed from 74ca67c109 because they
live in a different Domain, but should be treated in the same way.

Differential Revision: https://reviews.llvm.org/D83204

4 years ago[lldb] Make TestOptionValueFileColonLine work on Windows
Jonas Devlieghere [Tue, 21 Jul 2020 06:13:01 +0000 (23:13 -0700)]
[lldb] Make TestOptionValueFileColonLine work on Windows

The colon in the file name is interpreted as a drive name and therefore
the path looks like foo:\\bar.c. Compare FileSpecs instead of their
string representation so we don't have to worry about that.

4 years ago[lldb] Fix redundant newline in AppendError calls.
Jonas Devlieghere [Tue, 21 Jul 2020 06:10:29 +0000 (23:10 -0700)]
[lldb] Fix redundant newline in AppendError calls.

AppendError always appends a newline to the given argument, while
AppendErrorWithFormat does not. I've updated the calls to remove the
extra newline.

4 years ago[clangd] Improve heuristic resolution of dependent types in TargetFinder
Nathan Ridge [Wed, 8 Jul 2020 06:51:34 +0000 (02:51 -0400)]
[clangd] Improve heuristic resolution of dependent types in TargetFinder

 * Try to apply heuristic resolution recursively to the base
   expression of a CXXDependentScopeMemberExpr.

 * Try to apply heuristic resolution recursively to the callee
   expression in a call expression.

Fixes https://github.com/clangd/clangd/issues/441

Subscribers: ilya-biryukov, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82739

4 years ago[lldb] Remove redundant WithFormat suffixes (NFC)
Jonas Devlieghere [Tue, 21 Jul 2020 05:57:06 +0000 (22:57 -0700)]
[lldb] Remove redundant WithFormat suffixes (NFC)

Replace calls to FooWithFormat() with calls to Foo() when only one
argument is provided and the given string doesn't need to be formatted.

4 years ago[ARM] Predicated MVE reduction tests. NFC
David Green [Mon, 20 Jul 2020 14:11:53 +0000 (15:11 +0100)]
[ARM] Predicated MVE reduction tests. NFC

4 years ago[clangd] Handle deduction guides in TargetFinder and ExplicitReferenceCollector
Nathan Ridge [Sun, 19 Jul 2020 06:26:49 +0000 (02:26 -0400)]
[clangd] Handle deduction guides in TargetFinder and ExplicitReferenceCollector

Summary: Fixes https://github.com/clangd/clangd/issues/463.

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84122

4 years ago[OpenMP] Use common interface to access GPU Grid Values
Saiyedul Islam [Tue, 21 Jul 2020 05:23:38 +0000 (05:23 +0000)]
[OpenMP] Use common interface to access GPU Grid Values

Use common interface for accessing target specific GPU grid values in NVPTX
OpenMP codegen as proposed in https://reviews.llvm.org/D80917

Originally authored by Greg Rodgers (@gregrodgers).

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D83492

4 years ago[NFC] Add another missing 'override'
Logan Smith [Tue, 21 Jul 2020 05:03:19 +0000 (22:03 -0700)]
[NFC] Add another missing 'override'

This should be the last one needed to appease the -Werror bots (knock on wood).

4 years ago[lldb] fix warnings in TestOptionValueFileColonLine.cpp
Jonas Devlieghere [Tue, 21 Jul 2020 04:43:17 +0000 (21:43 -0700)]
[lldb] fix warnings in TestOptionValueFileColonLine.cpp

4 years ago[lldb] Fix OptionValueFileColonLine to compile with MSVC
Jonas Devlieghere [Tue, 21 Jul 2020 04:25:32 +0000 (21:25 -0700)]
[lldb] Fix OptionValueFileColonLine to compile with MSVC

This should fix error C4716:
'lldb_private::OptionValueFileColonLine::Clear': must return a value

4 years ago[NFC] Add missing 'override's
Logan Smith [Tue, 21 Jul 2020 02:52:36 +0000 (19:52 -0700)]
[NFC] Add missing 'override's

4 years agoDebugInfo: Move getMD5AsBytes from DwarfUnit to DwarfDebug
David Blaikie [Tue, 21 Jul 2020 02:06:20 +0000 (19:06 -0700)]
DebugInfo: Move getMD5AsBytes from DwarfUnit to DwarfDebug

It wasn't using any state from DwarfUnit anyway.

4 years agoGlobalISel: Rewrite getLCMType
Matt Arsenault [Sat, 6 Jun 2020 23:37:43 +0000 (19:37 -0400)]
GlobalISel: Rewrite getLCMType

Try to make the behavior more consistent with getGCDType, and bias
towards returning something closer to the source type whenever there's
an ambiguity.

4 years agoGlobalISel: Handle more cases in getGCDType
Matt Arsenault [Sun, 7 Jun 2020 01:24:02 +0000 (21:24 -0400)]
GlobalISel: Handle more cases in getGCDType

Try harder to find a canonical unmerge type when trying to cover the
desired target type. Handle finding a compatible unmerge type for two
vectors with different element types. This will return the largest
multiple of the source vector element that will evenly divide the
target vector type.

Also make the handling mixing scalars and vectors, and prefer the
source element type as the unmerge target type.

4 years agoAMDGPU/GlobalISel: Remove unnecessary parameter
Matt Arsenault [Mon, 20 Jul 2020 23:40:15 +0000 (19:40 -0400)]
AMDGPU/GlobalISel: Remove unnecessary parameter

4 years ago[compiler-rt] Disable -Wsuggest-override for unittests
Logan Smith [Tue, 21 Jul 2020 00:39:14 +0000 (17:39 -0700)]
[compiler-rt] Disable -Wsuggest-override for unittests

This uses a special set of flags given to unittests to work around warnings raised by googletest and googlemock. This should bring the sanitizer bots back to green.

4 years agoAdd an option (-y) to "break set" and "source list" that uses the same
Jim Ingham [Thu, 16 Jul 2020 18:34:50 +0000 (11:34 -0700)]
Add an option (-y) to "break set" and "source list" that uses the same
file:line:column form that we use to print out locations.  Since we
print them this way it makes sense we also accept that form.

Differential Revision: https://reviews.llvm.org/D83975

4 years ago[lldb] Make sure we don't leak SBThreadPlan pointer (NFCI)
Jonas Devlieghere [Mon, 20 Jul 2020 23:57:40 +0000 (16:57 -0700)]
[lldb] Make sure we don't leak SBThreadPlan pointer (NFCI)

Make sure we don't accidentally leak the SBThreadPlan pointer when we
return before handing it off to Python to manage its lifetime.

4 years ago[lldb] Use weak_ptr to hold on to the underlying thread plan in SBThreadPlan
Jonas Devlieghere [Mon, 20 Jul 2020 23:50:59 +0000 (16:50 -0700)]
[lldb] Use weak_ptr to hold on to the underlying thread plan in SBThreadPlan

Use a weak pointer to hold on to the the underlying thread plan in
SBThreadPlan. When the process continues, all the popped ThreadPlans get
discarded, and you can’t reuse them, so you have to create them anew.
Therefore the SBThreadPlan doesn’t need to keep the ThreadPlan alive.

This fixes the cleanup error in TestThreadPlanCommands.py and
TestStepScripted.py caused by the thread plans never being deleted.

Differential revision: https://reviews.llvm.org/D84210

4 years ago[clang][NFC] Add missing 'override's
Logan Smith [Mon, 20 Jul 2020 23:40:03 +0000 (16:40 -0700)]
[clang][NFC] Add missing 'override's

4 years ago[MC,NVPTX] Add MCAsmPrinter support for unsigned-only data directives.
Artem Belevich [Wed, 8 Jul 2020 20:23:18 +0000 (13:23 -0700)]
[MC,NVPTX] Add MCAsmPrinter support for unsigned-only data directives.

PTX does not support negative values in .bNN data directives and we must
typecast such values to unsigned before printing them.

MCAsmInfo can now specify whether such casting is necessary for particular
target.

Differential Revision: https://reviews.llvm.org/D83423

4 years ago [Analyzer] Add checkRegionChanges for SmartPtrModeling
Nithin Vadukkumchery Rajendrakumar [Wed, 15 Jul 2020 00:54:44 +0000 (02:54 +0200)]
[Analyzer]   Add checkRegionChanges for SmartPtrModeling

    Summary:
    Implemented checkRegionChanges for SmartPtrModeling

    Reviewers: NoQ, Szelethus, vsavchenko, xazax.hun

    Reviewed By: NoQ, vsavchenko, xazax.hun

    Subscribers: martong, cfe-commits
    Tags: #clang

    Differential Revision: https://reviews.llvm.org/D83836

4 years agoFix how we handle bit-fields for Objective-C when creating an AST
shafik [Mon, 20 Jul 2020 23:09:18 +0000 (16:09 -0700)]
Fix how we handle bit-fields for Objective-C when creating an AST

Currently expressions dealing with bit-fields in Objective-C objects is pretty broken. When generating debug-info for Objective-C bit-fields DW_AT_data_bit_offset has a different meaning than it does to C and C++.
When we parse the DWARF we validate bit offsets for C and C++ correctly but not for ObjC. For ObjC in some cases we end up incorrectly flagging an error and we don't generate further bit-fields in the AST.
Later on when we do a name lookup we don't find the ObjCIvarDecl in the ObjCInterfaceDecl in some cases since we never added it and then we don't go to the runtime to obtain the offset.

This will fix how we handle bit-fields for the Objective-C case and add tests to verify this fix but also to documents areas that still don't work and will be addressed in follow-up PRs.

Note: we can never correctly calculate offsets statically because of how Objective-C deals with the fragile base class issue. Which means the runtime may need to shift fields over.

Differential Revision: https://reviews.llvm.org/D83433

4 years agoFix typo causing build failure
Logan Smith [Mon, 20 Jul 2020 22:13:22 +0000 (15:13 -0700)]
Fix typo causing build failure

(facepalm)

4 years ago[PlatformMacOSX] Remove unused variable. NFC.
Davide Italiano [Mon, 20 Jul 2020 21:50:36 +0000 (14:50 -0700)]
[PlatformMacOSX] Remove unused variable. NFC.

4 years ago[ExecutionEngine] Initialize near block hint in SectionMemoryManager.
Lang Hames [Mon, 20 Jul 2020 21:31:48 +0000 (14:31 -0700)]
[ExecutionEngine] Initialize near block hint in SectionMemoryManager.

When allocating a new memory block in SectionMemoryManager, initialize
the Near hint for the other memory groups if they have not been set
already.

Patch by Dana Koch. Thanks Dana!

4 years ago[NFC] Add missing 'override's
Logan Smith [Mon, 20 Jul 2020 21:38:10 +0000 (14:38 -0700)]
[NFC] Add missing 'override's

4 years ago[testsuite] Adapt lldb-server base test helper to run on arm64
Davide Italiano [Mon, 20 Jul 2020 21:11:58 +0000 (14:11 -0700)]
[testsuite] Adapt lldb-server base test helper to run on arm64

4 years agoRevert "[libTooling] In Clang Transformer, change `Metadata` field to deferred evalut...
Yitzhak Mandelbaum [Mon, 20 Jul 2020 21:24:58 +0000 (21:24 +0000)]
Revert "[libTooling] In Clang Transformer, change `Metadata` field to deferred evalutaion"

This reverts commit c0b8954ecba500e3d9609152295b74ccd7d89d62.

The commit has broken various builds. Reverting while I investigate the cause.

4 years ago[libTooling] In Clang Transformer, change `Metadata` field to deferred evalutaion
Yitzhak Mandelbaum [Mon, 20 Jul 2020 21:16:39 +0000 (21:16 +0000)]
[libTooling] In Clang Transformer, change `Metadata` field to deferred evalutaion

`Metadata` is being changed from an `llvm::Any` to a `MatchConsumer<llvm;:Any>`, so that it's evaluation can be be dependent on `MatchResult`s passed in.

Reviewed By: ymandel, gribozavr2

Differential Revision: https://reviews.llvm.org/D83820

4 years ago[OpenMP] libomp cleanup: add checks of bad memory access
AndreyChurbanov [Mon, 20 Jul 2020 21:12:46 +0000 (00:12 +0300)]
[OpenMP] libomp cleanup: add checks of bad memory access

Add check of frm to prevent array out-of-bound access;
add check of new_nproc to prevent access of unallocated hot_teams array;
add check of location info pointer to prevent NULL dereference;
add check of d_tn pointer to prevent NULL dereference in release build.
These checks make static analyzers happier.

This is second part of the patch from https://reviews.llvm.org/D84062.

4 years ago[PlatformDarwin] Add support for Apple Silicon.
Davide Italiano [Mon, 20 Jul 2020 21:10:35 +0000 (14:10 -0700)]
[PlatformDarwin] Add support for Apple Silicon.

Gets another large chunk of the testsuite to pass.

4 years ago[Reduce] Argument reduction: don't try to drop terminator instructions
Roman Lebedev [Mon, 20 Jul 2020 19:25:15 +0000 (22:25 +0300)]
[Reduce] Argument reduction: don't try to drop terminator instructions

Newly-added test previously crashed.

While it is up for debate whether or not instruction reduction
should be indiscriminate in instruction dropping (there you can
just ensure that the test case is still -verify'ies), here
if we drop terminator, CloneFunctionInto() will immediately crash.

So let's not do that :)

4 years agoDisable trivial weak_ptr test on ARM because it is not expected to work.
Vy Nguyen [Mon, 20 Jul 2020 20:59:46 +0000 (16:59 -0400)]
Disable trivial weak_ptr test on ARM because it is not expected to work.

Summary:
weak_ptr has two pointers (more than the 4 bytes limit), so it will not be returned in registers on ARM, even if it is trivial.
The test, therefore, will fail on ARM.

Reviewers: #libc!

Subscribers: kristof.beyls, danielkiss, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D84200

4 years ago[llvm][unittest] Add -Wno-suggest-override to more infrastructure that includes googl...
Logan Smith [Mon, 20 Jul 2020 20:59:34 +0000 (13:59 -0700)]
[llvm][unittest] Add -Wno-suggest-override to more infrastructure that includes googletest/googlemock headers

4 years ago[OpenMP] libomp cleanup: add check of input global tid parameter
AndreyChurbanov [Mon, 20 Jul 2020 20:49:58 +0000 (23:49 +0300)]
[OpenMP] libomp cleanup: add check of input global tid parameter

Add check of negative gtid before indexing __kmp_threads.
This makes static analyzers happier.
This is the first part of the patch split in two parts.

Differential Revision: https://reviews.llvm.org/D84062

4 years ago[analyzer][StdLibraryFunctionsChecker] Add POSIX networking functions
Gabor Marton [Tue, 7 Jul 2020 16:34:20 +0000 (18:34 +0200)]
[analyzer][StdLibraryFunctionsChecker] Add POSIX networking functions

Summary:
Adding networking functions from the POSIX standard (2017). This includes
functions that deal with sockets from socket.h, netdb.h.

In 'socket.h' of some libc implementations (e.g. glibc) with C99, sockaddr
parameter is a transparent union of the underlying sockaddr_ family of pointers
instead of being a pointer to struct sockaddr. In these cases, the standardized
signature will not match, thus we try to match with another signature that has
the joker Irrelevant type. In the case of transparent unions, we also not add
those constraints which require pointer types for the sockaddr param.

Interestingly, in 'netdb.h' sockaddr is not handled as a transparent union.

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83407

4 years ago[NFC] Use std::free instead of ::free
Louis Dionne [Mon, 20 Jul 2020 20:15:49 +0000 (16:15 -0400)]
[NFC] Use std::free instead of ::free

Since we include <cstdlib> instead of <stdlib.h>, it makes sense to
use std::free.

4 years ago[InstCombine] allow peeking through zext of shift amount to match rotate idioms ...
Sanjay Patel [Mon, 20 Jul 2020 19:49:01 +0000 (15:49 -0400)]
[InstCombine] allow peeking through zext of shift amount to match rotate idioms (PR45701)

We might want to also allow trunc of the shift amount, but that seems less likely?

  define i32 @src(i32 %x, i1 %y) {
  %0:
    %rem = and i1 %y, 1
    %cmp = icmp eq i1 %rem, 0
    %sh_prom = zext i1 %rem to i32
    %sub = sub nsw nuw i1 0, %rem
    %sh_prom1 = zext i1 %sub to i32
    %shr = lshr i32 %x, %sh_prom1
    %shl = shl i32 %x, %sh_prom
    %or = or i32 %shl, %shr
    %r = select i1 %cmp, i32 %x, i32 %or
    ret i32 %r
  }
  =>
  define i32 @tgt(i32 %x, i1 %y) {
  %0:
    %t = zext i1 %y to i32
    %r = fshl i32 %x, i32 %x, i32 %t
    ret i32 %r
  }

  Transformation seems to be correct!

https://alive2.llvm.org/ce/z/xgMvE3

http://bugs.llvm.org/PR45701

4 years ago[InstCombine] add tests for funnel shift/rotate with narrow shift amount; NFC
Sanjay Patel [Mon, 20 Jul 2020 19:31:24 +0000 (15:31 -0400)]
[InstCombine] add tests for funnel shift/rotate with narrow shift amount; NFC

4 years ago[Matrix] Use TileInfo to create tiled loop nest for matrix multiply.
Florian Hahn [Mon, 20 Jul 2020 19:50:49 +0000 (20:50 +0100)]
[Matrix] Use TileInfo to create tiled loop nest for matrix multiply.

This patch uses the TileInfo introduced in D77550 to generate a loop
nest for tiled matrix multiplication, instead of generating the
unrolled code for the whole multiplication. This makes code-generation
more scalable for larger matrixes.

Initially loops are only used if both the number of rows and columns are
divisible by the tile size. Other cases will be added as follow-up.

Reviewers: anemet, Gerolf, hfinkel, andrew.w.kaylor, LuoYuanke, nicolasvasilache

Reviewed By: anemet

Differential Revision: https://reviews.llvm.org/D81308

4 years ago[AArch64][SVE] Add support for trunc to <vscale x N x i1>.
Eli Friedman [Tue, 14 Jul 2020 20:02:58 +0000 (13:02 -0700)]
[AArch64][SVE] Add support for trunc to <vscale x N x i1>.

This isn't a natively supported operation, so convert it to a
mask+compare.

In addition to the operation itself, fix up some surrounding stuff to
make the testcase work: we need concat_vectors on i1 vectors, we need
legalization of i1 vector truncates, and we need to fix up all the
relevant uses of getVectorNumElements().

Differential Revision: https://reviews.llvm.org/D83811

4 years ago[LLDB] [COFF] Fix handling of symbols with more than one aux symbol
Martin Storsjö [Fri, 17 Jul 2020 20:35:45 +0000 (23:35 +0300)]
[LLDB] [COFF] Fix handling of symbols with more than one aux symbol

Differential Revision: https://reviews.llvm.org/D84070

4 years agoEnable -Wsuggest-override in the LLVM build
Logan Smith [Mon, 20 Jul 2020 17:06:11 +0000 (10:06 -0700)]
Enable -Wsuggest-override in the LLVM build

This patch adds Clang's new (and GCC's old) -Wsuggest-override to the warning flags for the LLVM build. The warning is a stronger form of -Winconsistent-missing-override which warns _everywhere_ that override is missing, not just in places where it's inconsistent within a class.

Some directories in the monorepo need the warning disabled for compatibility's, or sanity's, sake; in particular, libcxx/libcxxabi, and any code implementing or interoperating with googletest, googlemock, or google benchmark (which do not themselves use override). This patch adds -Wno-suggest-override to the relevant CMakeLists.txt's to accomplish this.

Differential Revision: https://reviews.llvm.org/D84126

4 years ago[PGO] Enable the extended value profile buckets for mem op sizes.
Hiroshi Yamauchi [Wed, 15 Jul 2020 18:56:06 +0000 (11:56 -0700)]
[PGO] Enable the extended value profile buckets for mem op sizes.

Following up D81682 and enable the new, extended value profile buckets for mem
op sizes.

Differential Revision: https://reviews.llvm.org/D83903

4 years ago[clangd] Remove TokenBuffer usage in TypeHierarchy
Aleksandr Platonov [Mon, 20 Jul 2020 11:46:09 +0000 (13:46 +0200)]
[clangd] Remove TokenBuffer usage in TypeHierarchy

Summary:
This patch mostly reverts D74850.
We could not use `AST.getTokens()` here, because it does not have tokens from the preamble.

Reviewers: sammccall, kadircet

Reviewed By: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, kbobyrev, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84144

4 years ago[clang-format] Add BitFieldColonSpacing option
Anders Waldenborg [Sat, 18 Jul 2020 10:35:01 +0000 (12:35 +0200)]
[clang-format] Add BitFieldColonSpacing option

This new option allows controlling if there should be spaces around
the ':' in a bitfield declaration.

BitFieldColonSpacing accepts four different values:

  // "Both" - default
  unsigned bitfield : 5
  unsigned bf2      : 5  // AlignConsecutiveBitFields=true

  // "None"
  unsigned bitfield:5
  unsigned bf2     :5

  // "Before"
  unsigned bitfield :5
  unsigned bf2      :5

  // "After"
  unsigned bitfield: 5
  unsigned bf2     : 5

Differential Revision: https://reviews.llvm.org/D84090

4 years ago[lldb/Reproducers] Always record the current working directory
Jonas Devlieghere [Mon, 20 Jul 2020 18:23:43 +0000 (11:23 -0700)]
[lldb/Reproducers] Always record the current working directory

Setting the current working directory in the VFS will fail if the given
path doesn't exist in the YAML mapping or on disk.

4 years ago[lldb] Fix method name to match LLDB code style (NFC)
Jonas Devlieghere [Mon, 20 Jul 2020 18:20:20 +0000 (11:20 -0700)]
[lldb] Fix method name to match LLDB code style (NFC)

recordInterestingDirectory -> RecordInterestingDirectory

4 years ago[PGO][PGSO] Remove a temporary flag used for gradual rollout.
Hiroshi Yamauchi [Fri, 17 Jul 2020 17:41:25 +0000 (10:41 -0700)]
[PGO][PGSO] Remove a temporary flag used for gradual rollout.

Remove the temporary flag PGSOIRPassOrTestOnly and the guard code which was used
for the staged rollout. This is a cleanup (NFC) as it's now false by default.

Differential Revision: https://reviews.llvm.org/D84057

4 years ago[llvm] Development-mode InlineAdvisor
Mircea Trofin [Thu, 9 Jul 2020 01:55:36 +0000 (18:55 -0700)]
[llvm] Development-mode InlineAdvisor

Summary:
This is the InlineAdvisor used in 'development' mode. It enables two
scenarios:

 - loading models via a command-line parameter, thus allowing for rapid
 training iteration, where models can be used for the next exploration
 phase without requiring recompiling the compiler. This trades off some
 compilation speed for the added flexibility.

 - collecting training logs, in the form of tensorflow.SequenceExample
 protobufs. We generate these as textual protobufs, which simplifies
 generation and testing. The protobufs may then be readily consumed by a
 tensorflow-based training algorithm.

To speed up training, training logs may also be collected from the
'default' training policy. In that case, this InlineAdvisor does not
use a model.

RFC: http://lists.llvm.org/pipermail/llvm-dev/2020-April/140763.html

Reviewers: jdoerfert, davidxl

Subscribers: mgorny, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83733

4 years ago[gn build] Port e1270b16c94
LLVM GN Syncbot [Mon, 20 Jul 2020 17:51:57 +0000 (17:51 +0000)]
[gn build] Port e1270b16c94

4 years ago[Matrix] Add TileInfo abstraction for tiled matrix code-gen.
Florian Hahn [Mon, 20 Jul 2020 17:31:04 +0000 (18:31 +0100)]
[Matrix] Add TileInfo abstraction for tiled matrix code-gen.

This patch adds a TileInfo abstraction and utilities to
create a 3-level loop nest for tiling.

Reviewers: anemet

Reviewed By: anemet

Differential Revision: https://reviews.llvm.org/D77550

4 years ago[PowerPC] Implement R_PPC64_REL24_NOTOC local calls, callee requires a TOC
Victor Huang [Mon, 20 Jul 2020 17:40:41 +0000 (17:40 +0000)]
[PowerPC] Implement R_PPC64_REL24_NOTOC local calls, callee requires a TOC

The PC Relative code now allows for calls that are marked with the relocation
R_PPC64_REL24_NOTOC. This indicates that the caller does not have a valid TOC
pointer in R2 and does not require R2 to be restored after the call.

This patch is added to support local calls to callees that require a TOC

Reviewed By: sfertile, MaskRay, nemanjai, stefanp

Differential Revision: https://reviews.llvm.org/D83504

4 years ago[LLD][COFF] Skip computation of the undefined symbols references that are not shown
Sylvain Audi [Thu, 9 Jul 2020 21:12:02 +0000 (17:12 -0400)]
[LLD][COFF] Skip computation of the undefined symbols references that are not shown

The "undefined symbol" error message from lld-link displays up to 3 references to that symbol, and the number of extra references not shown.

This patch removes the computation of the strings for those extra references.

It fixes a freeze of lld-link we accidentally encountered when activating asan on a large project, without linking with the asan library.
In that case, __asan_report_load8 was referenced more than 2 million times, causing the computation of that many display strings, of which only 3 were used.

Differential Revision: https://reviews.llvm.org/D83510

4 years ago[NFC] remove unused llvm::deleter
Yuanfang Chen [Sun, 19 Jul 2020 07:26:55 +0000 (00:26 -0700)]
[NFC] remove unused llvm::deleter

4 years ago[NFC] remove unused includes of SelectionDAGISel.h
Yuanfang Chen [Sat, 11 Jul 2020 02:47:12 +0000 (19:47 -0700)]
[NFC] remove unused includes of SelectionDAGISel.h

4 years ago[NFC] remove unneeded TargetLoweringObjectFile init after 85c30f3374d9
Yuanfang Chen [Tue, 7 Jul 2020 16:39:55 +0000 (09:39 -0700)]
[NFC] remove unneeded TargetLoweringObjectFile init after 85c30f3374d9

4 years ago[llc] (almost) remove `--print-machineinstrs`
Yuanfang Chen [Mon, 20 Jul 2020 17:09:41 +0000 (10:09 -0700)]
[llc] (almost) remove `--print-machineinstrs`

Its effect could be achieved by
`-stop-after`,`-print-after`,`-print-after-all`. But a few tests need to
print MIR after ISel which could not be done with
`-print-after`/`-stop-after` since isel pass does not have commandline name.
That's the reason `--print-machineinstrs` is downgraded to
`--print-after-isel` in this patch. `--print-after-isel` could be
removed after we switch to new pass manager since isel pass would have a
commandline text name to use `print-after` or equivalent switches.

The motivation of this patch is to reduce tests dependency on
would-be-deprecated feature.

Reviewed By: arsenm, dsanders

Differential Revision: https://reviews.llvm.org/D83275

4 years agoAMDGPU: Use MCRegister for preloaded arguments
Matt Arsenault [Mon, 20 Jul 2020 17:25:07 +0000 (13:25 -0400)]
AMDGPU: Use MCRegister for preloaded arguments

Attempt to fix build error with ancient GCC

4 years ago[llvm-readobj] clang-format DwarfCFIEHPrinter.h, NFC
Fangrui Song [Mon, 20 Jul 2020 17:25:16 +0000 (10:25 -0700)]
[llvm-readobj] clang-format DwarfCFIEHPrinter.h, NFC

Pre-commit header ordering changes (and other minor clean-ups) before landing D84106.

4 years ago[mlir] Added support for symbols inside linalg.generic and map concatenation
Jakub Lichman [Mon, 20 Jul 2020 16:30:10 +0000 (18:30 +0200)]
[mlir] Added support for symbols inside linalg.generic and map concatenation

This commit adds functionality needed for implementation of convolutions with
linalg.generic op. Since linalg.generic right now expects indexing maps to be
just permutations, offset indexing needed in convolutions is not possible.
Therefore in this commit we address the issue by adding support for symbols inside
indexing maps which enables more advanced indexing. The upcoming commit will
solve the problem of computing loop bounds from such maps.

Differential Revision: https://reviews.llvm.org/D83158

4 years ago[LLVMgold.so] -plugin-opt=save-temps: save combined module to .lto.o instead of .o
Fangrui Song [Mon, 20 Jul 2020 16:58:31 +0000 (09:58 -0700)]
[LLVMgold.so] -plugin-opt=save-temps: save combined module to .lto.o instead of .o

This matches LLD and fixes https://sourceware.org/bugzilla/show_bug.cgi?id=26262#c1

.o is a bad choice for save-temps output because it is easy to override the bitcode file (*.o)

```
 # Use bfd for the example, -fuse-ld=gold is similar.
clang -flto -c a.c  # generate bitcode file a.o
clang -fuse-ld=bfd -flto a.o -o a -Wl,-plugin-opt=save-temps  # override a.o

 # The user repeats the command but get surprised, because a.o is now a combined module.
clang -fuse-ld=bfd -flto a.o -o a -Wl,-plugin-opt=save-temps
```

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D84132

4 years ago[OPENMP50]Perform data mapping analysis only for explicitly mapped data.
Alexey Bataev [Tue, 7 Jul 2020 20:16:17 +0000 (16:16 -0400)]
[OPENMP50]Perform data mapping analysis only for explicitly mapped data.

Summary:
According to OpenMP 5.0, the restrictions for mapping of overlapped data
apply only for explicitly mapped data, there is no restriction for
implicitly mapped data just like in OpenMP 4.5.

Reviewers: jdoerfert

Subscribers: yaxunl, guansong, sstefan1, cfe-commits, caomhin

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83398

4 years ago[libcxx] Skip tests on GCC
Vy Nguyen [Mon, 20 Jul 2020 16:53:05 +0000 (12:53 -0400)]
[libcxx] Skip tests on GCC

Summary: These don't work with GCC

Reviewers: jyknight, #libc!

Subscribers: libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D84183

4 years ago[ThinLTO] parse flags and blockcount summaries
Nick Desaulniers [Mon, 20 Jul 2020 16:50:22 +0000 (09:50 -0700)]
[ThinLTO] parse flags and blockcount summaries

Forked from pr/46523, we were having a hard time running llvm-extract on
IR from a thinLTO build of the Linux kernel.

$ llvm-extract --func jeq_imm jit-42f488b63a04fdaa931315bdadecb6d23e20529a.ll
llvm-extract: jit-42f488b63a04fdaa931315bdadecb6d23e20529a.ll:47463:8:
error: Expected 'gv', 'module', or 'typeid' at the start of summary
entry
^209 = flags: 8
       ^

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D82917

4 years ago[Driver] Add --ld-path= and deprecate -fuse-ld=/abs/path and -fuse-ld=rel/path
Fangrui Song [Mon, 20 Jul 2020 16:34:39 +0000 (09:34 -0700)]
[Driver] Add --ld-path= and deprecate -fuse-ld=/abs/path and -fuse-ld=rel/path

Supersedes D80225. Add --ld-path= to avoid strange target specific
prefixes and make -fuse-ld= focus on its intended job: "linker flavor".
(-f* affects generated code or language features. --ld-path does not
affect codegen, so it is not named -f*)

The way --ld-path= works is similar to "Command Search and Execution" in POSIX.1-2017 2.9.1 Simple Commands.

If --ld-path= specifies

* an absolute path, the value specifies the linker.
* a relative path without a path component separator (/), the value is searched using the -B, COMPILER_PATH, then PATH.
* a relative path with a path component separator, the linker is found relative to the current working directory.

-fuse-ld= and --ld-path= can be composed, e.g. `-fuse-ld=lld --ld-path=/usr/bin/ld.lld`

The driver can base its linker option decision on the flavor -fuse-ld=, but it should not do fragile
flavor checking with --ld-path=.

Reviewed By: whitequark, keith

Differential Revision: https://reviews.llvm.org/D83015

4 years agoReland [libcxx]Put clang::trivial_abi on smart pointers
Vy Nguyen [Mon, 13 Jul 2020 16:34:37 +0000 (12:34 -0400)]
Reland [libcxx]Put clang::trivial_abi on smart pointers

    Reviewed By: ldionne,EricWF

    Tags: #libcxx

    Differential Revision: https://reviews.llvm.org/D82490

4 years agoRequire shell for lld/test/ELF/arm-exidx-range.s
Hans Wennborg [Mon, 20 Jul 2020 15:48:00 +0000 (17:48 +0200)]
Require shell for lld/test/ELF/arm-exidx-range.s

The test fails in 32-bit Windows builds for unclear reasons:

ld.lld: error: failed to open
C:\src\llvm_package_1100-rc1\build32_stage0\tools\lld\test\ELF\Output\arm-exidx-range.s.tmp:
The parameter is incorrect.

4 years agoFix issue in typo handling which could lead clang to hang
David Goldman [Fri, 17 Jul 2020 19:06:28 +0000 (15:06 -0400)]
Fix issue in typo handling which could lead clang to hang

Summary:
We need to detect when certain TypoExprs are not being transformed
due to invalid trees, otherwise we risk endlessly trying to fix it.

Reviewers: rsmith

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84067

4 years agoAMDGPU: Remove outdated fixme
Matt Arsenault [Mon, 20 Jul 2020 15:37:31 +0000 (11:37 -0400)]
AMDGPU: Remove outdated fixme

4 years agoAMDGPU: Fix not accounting for constantexpr uses of LDS globals
Matt Arsenault [Sat, 18 Jul 2020 00:21:28 +0000 (20:21 -0400)]
AMDGPU: Fix not accounting for constantexpr uses of LDS globals

This was failing to add the size of LDS globals that weren't directly
used by an instruction. They could be used by constant expressions
which are transitively used by the function. This requires a better
search, but just abort on this for now for correctness.

4 years ago[Sema] Promote SmallSet of enum to bitset
Benjamin Kramer [Mon, 20 Jul 2020 15:33:30 +0000 (17:33 +0200)]
[Sema] Promote SmallSet of enum to bitset

Even with 300 elements, this still consumes less stack space than the
SmallSet. NFCI.

4 years agoAMDGPU/GlobalISel: Initial Implementation of calls
Matt Arsenault [Fri, 3 Jul 2020 18:47:23 +0000 (14:47 -0400)]
AMDGPU/GlobalISel: Initial Implementation of calls

Return values, and tail calls are not yet handled.

4 years agoVerifier: Check byref address space for AMDGPU calling conventions
Matt Arsenault [Mon, 29 Jun 2020 14:37:15 +0000 (10:37 -0400)]
Verifier: Check byref address space for AMDGPU calling conventions

4 years agoIssue error on invalid arithemtic conversions in C ternary
Erich Keane [Mon, 20 Jul 2020 15:00:13 +0000 (08:00 -0700)]
Issue error on invalid arithemtic conversions in C ternary

As reported in PR46774, an invalid arithemetic conversion used in a C
ternary operator resulted in an assertion. This patch replaces that
assertion with a diagnostic stating that the conversion failed.

At the moment, I believe the only case of this happening is _ExtInt
types.

4 years agoVerifier: Disallow byval and similar for AMDGPU calling conventions
Matt Arsenault [Thu, 7 May 2020 18:58:05 +0000 (14:58 -0400)]
Verifier: Disallow byval and similar for AMDGPU calling conventions

These imply stack-like semantics, which doesn't make any sense for
entry points.

4 years ago[Driver] Promote SmallSet of enum to a bitset. NFCI.
Benjamin Kramer [Mon, 20 Jul 2020 14:50:00 +0000 (16:50 +0200)]
[Driver] Promote SmallSet of enum to a bitset. NFCI.

4 years agoUpgrade SmallSets of pointer-like types to SmallPtrSet
Benjamin Kramer [Mon, 20 Jul 2020 14:41:44 +0000 (16:41 +0200)]
Upgrade SmallSets of pointer-like types to SmallPtrSet

This is slightly more efficient. NFC.

4 years ago[MLIR][Shape] Allow `shape.rank` to accept extent tensors `tensor?xindex>`
Frederik Gossen [Mon, 20 Jul 2020 14:46:18 +0000 (14:46 +0000)]
[MLIR][Shape] Allow `shape.rank` to accept extent tensors `tensor?xindex>`

Differential Revision: https://reviews.llvm.org/D84156

4 years ago[MLIR][Shape] Allow `cstr_broadcastable` to accept extent tensors
Frederik Gossen [Mon, 20 Jul 2020 14:37:19 +0000 (14:37 +0000)]
[MLIR][Shape] Allow `cstr_broadcastable` to accept extent tensors

Differential Revision: https://reviews.llvm.org/D84155

4 years ago[DebugInfo] Support for DW_AT_associated and DW_AT_allocated.
Alok Kumar Sharma [Mon, 20 Jul 2020 14:20:37 +0000 (19:50 +0530)]
[DebugInfo] Support for DW_AT_associated and DW_AT_allocated.

Summary:
This support is needed for the Fortran array variables with pointer/allocatable
attribute. This support enables debugger to identify the status of variable
whether that is currently allocated/associated.

  for pointer array (before allocation/association)
  without DW_AT_associated

(gdb) pt ptr
type = integer (140737345375288:140737354129776)
(gdb) p ptr
value requires 35017956 bytes, which is more than max-value-size

  with DW_AT_associated

(gdb) pt ptr
type = integer (:)
(gdb) p ptr
$1 = <not associated>

  for allocatable array (before allocation)

  without DW_AT_allocated

(gdb) pt arr
type = integer (140737345375288:140737354129776)
(gdb) p arr
value requires 35017956 bytes, which is more than max-value-size

  with DW_AT_allocated

(gdb) pt arr
type = integer, allocatable (:)
(gdb) p arr
$1 = <not allocated>

    Testing
- unit test cases added
- check-llvm
- check-debuginfo

Reviewed By: aprantl

Differential Revision: https://reviews.llvm.org/D83544

4 years agoIR: Define byref parameter attribute
Matt Arsenault [Fri, 5 Jun 2020 20:58:47 +0000 (16:58 -0400)]
IR: Define byref parameter attribute

This allows tracking the in-memory type of a pointer argument to a
function for ABI purposes. This is essentially a stripped down version
of byval to remove some of the stack-copy implications in its
definition.

This includes the base IR changes, and some tests for places where it
should be treated similarly to byval. Codegen support will be in a
future patch.

My original attempt at solving some of these problems was to repurpose
byval with a different address space from the stack. However, it is
technically permitted for the callee to introduce a write to the
argument, although nothing does this in reality. There is also talk of
removing and replacing the byval attribute, so a new attribute would
need to take its place anyway.

This is intended avoid some optimization issues with the current
handling of aggregate arguments, as well as fixes inflexibilty in how
frontends can specify the kernel ABI. The most honest representation
of the amdgpu_kernel convention is to expose all kernel arguments as
loads from constant memory. Today, these are raw, SSA Argument values
and codegen is responsible for turning these into loads.

Background:

There currently isn't a satisfactory way to represent how arguments
for the amdgpu_kernel calling convention are passed. In reality,
arguments are passed in a single, flat, constant memory buffer
implicitly passed to the function. It is also illegal to call this
function in the IR, and this is only ever invoked by a driver of some
kind.

It does not make sense to have a stack passed parameter in this
context as is implied by byval. It is never valid to write to the
kernel arguments, as this would corrupt the inputs seen by other
dispatches of the kernel. These argumets are also not in the same
address space as the stack, so a copy is needed to an alloca. From a
source C-like language, the kernel parameters are invisible.
Semantically, a copy is always required from the constant argument
memory to a mutable variable.

The current clang calling convention lowering emits raw values,
including aggregates into the function argument list, since using
byval would not make sense. This has some unfortunate consequences for
the optimizer. In the aggregate case, we end up with an aggregate
store to alloca, which both SROA and instcombine turn into a store of
each aggregate field. The optimizer never pieces this back together to
see that this is really just a copy from constant memory, so we end up
stuck with expensive stack usage.

This also means the backend dictates the alignment of arguments, and
arbitrarily picks the LLVM IR ABI type alignment. By allowing an
explicit alignment, frontends can make better decisions. For example,
there's real no advantage to an aligment higher than 4, so a frontend
could choose to compact the argument layout. Similarly, there is a
high penalty to using an alignment lower than 4, so a frontend could
opt into more padding for small arguments.

Another design consideration is when it is appropriate to expose the
fact that these arguments are all really passed in adjacent
memory. Currently we have a late IR optimization pass in codegen to
rewrite the kernel argument values into explicit loads to enable
vectorization. In most programs, unrelated argument loads can be
merged together. However, exposing this property directly from the
frontend has some disadvantages. We still need a way to track the
original argument sizes and alignments to report to the driver. I find
using some side-channel, metadata mechanism to track this
unappealing. If the kernel arguments were exposed as a single buffer
to begin with, alias analysis would be unaware that the padding bits
betewen arguments are meaningless. Another family of problems is there
are still some gaps in replacing all of the available parameter
attributes with metadata equivalents once lowered to loads.

The immediate plan is to start using this new attribute to handle all
aggregate argumets for kernels. Long term, it makes sense to migrate
all kernel arguments, including scalars, to be passed indirectly in
the same manner.

Additional context is in D79744.

4 years agoMCFixup.h - remove unnecessary MCExpr.h include. NFCI.
Simon Pilgrim [Mon, 20 Jul 2020 14:17:04 +0000 (15:17 +0100)]
MCFixup.h - remove unnecessary MCExpr.h include. NFCI.

Move the include down to files that actually depend on MCExpr definitions.

Also exposes an implicit dependency on MCContext in AVRAsmBackend.h