platform/upstream/llvm.git
3 years agoRevert "[Coroutines] Set presplit attribute in Clang instead of CoroEarly pass"
Xun Li [Mon, 19 Apr 2021 00:20:02 +0000 (17:20 -0700)]
Revert "[Coroutines] Set presplit attribute in Clang instead of CoroEarly pass"

This reverts commit fa6b54c44ab1d5f579304eadb7ac8bd7e72d0e77.
The commited patch broke mlir tests. It seems that mlir tests depend on coroutine function properties set in CoroEarly pass.

3 years agoAdd a missing debug assertion in <list>.
Arthur O'Dwyer [Sun, 18 Apr 2021 17:55:54 +0000 (13:55 -0400)]
Add a missing debug assertion in <list>.

This came up in D100595.

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

3 years ago[TableGen] Pass SmallVector to union_modes instead of returning a std::vector.
Craig Topper [Sun, 18 Apr 2021 21:10:06 +0000 (14:10 -0700)]
[TableGen] Pass SmallVector to union_modes instead of returning a std::vector.

The number of modes is small so this should avoid a heap allocation.

Also replace std::set with SmallSet.

3 years ago[Coroutines] Set presplit attribute in Clang instead of CoroEarly pass
Xun Li [Sun, 18 Apr 2021 22:41:09 +0000 (15:41 -0700)]
[Coroutines] Set presplit attribute in Clang instead of CoroEarly pass

Presplit coroutines cannot be inlined. During AlwaysInliner we check if a function is a presplit coroutine, if so we skip inlining.
The presplit coroutine attributes are set in CoroEarly pass.
However in O0 pipeline, AlwaysInliner runs before CoroEarly, so the attribute isn't set yet and will still inline the coroutine.
This causes Clang to crash: https://bugs.llvm.org/show_bug.cgi?id=49920

To fix this, we set the attributes in the Clang front-end instead of in CoroEarly pass.

Reviewed By: rjmccall, ChuanqiXu

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

3 years agoRevert "[Coroutines] Move CoroEarly pass to before AlwaysInliner"
Xun Li [Sun, 18 Apr 2021 22:38:19 +0000 (15:38 -0700)]
Revert "[Coroutines] Move CoroEarly pass to before AlwaysInliner"

This reverts commit 2b50f5a4343f8fb06acaa5c36355bcf58092c9cd.
Forgot to update the description of the commit to sync with phabricator. Going to redo the commit.

3 years ago[Coroutines] Move CoroEarly pass to before AlwaysInliner
Xun Li [Mon, 12 Apr 2021 05:01:36 +0000 (22:01 -0700)]
[Coroutines] Move CoroEarly pass to before AlwaysInliner

Presplit coroutines cannot be inlined. During AlwaysInliner we check if a function is a presplit coroutine, if so we skip inlining.
The presplit coroutine attributes are set in CoroEarly pass.
However in O0 pipeline, AlwaysInliner runs before CoroEarly, so the attribute isn't set yet and will still inline the coroutine.
This causes Clang to crash: https://bugs.llvm.org/show_bug.cgi?id=49920

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

3 years ago[lit] Fix the return code for "not not" after evaluating "not" internally
Martin Storsjö [Sun, 18 Apr 2021 21:37:13 +0000 (00:37 +0300)]
[lit] Fix the return code for "not not" after evaluating "not" internally

This fixes cases where "not not <command>" is supposed to return
only the error codes 0 or 1, but after efee57925c3f46c74c6697,
it passed the original error code through.

This was visible on AIX in the shtest-output-printing.py testcase,
where 'wc' returns 2, while it returns 1 on other platforms, and the
test required "not not" to normalize it to 1.

3 years ago[TableGen] Use MachineValueTypeSet in place of SmallSet.
Craig Topper [Sun, 18 Apr 2021 20:35:11 +0000 (13:35 -0700)]
[TableGen] Use MachineValueTypeSet in place of SmallSet.

MachineValueTypeSet is effectively a std::bitset<256>. This allows
us quickly insert into the set and check if a type is in the set.

3 years ago[LoopDeletion] Add test for PR49967 (NFC)
Nikita Popov [Sun, 18 Apr 2021 20:07:49 +0000 (22:07 +0200)]
[LoopDeletion] Add test for PR49967 (NFC)

Test case for a SCEV invalidation bug caused by D100264, which
has since been reverted.

3 years ago[TableGen] Use range-based for loop. NFC
Craig Topper [Sun, 18 Apr 2021 04:49:45 +0000 (21:49 -0700)]
[TableGen] Use range-based for loop. NFC

3 years ago[Introspection] Dont emit json if unchanged.
Nathan James [Sun, 18 Apr 2021 19:22:08 +0000 (20:22 +0100)]
[Introspection] Dont emit json if unchanged.

Saves running the generate inc script in the, somewhat common, case where the json file doesn't need changing.

Reviewed By: steveire

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

3 years ago[sanitizer] Don't call __tls_get_addr on s390x after D98926
Fangrui Song [Sun, 18 Apr 2021 17:42:43 +0000 (10:42 -0700)]
[sanitizer] Don't call __tls_get_addr on s390x after D98926

glibc s390x doesn't define __tls_get_addr.

Fix PR50017

3 years ago[libc++] [CI] Fail if the headers contain cyclic dependencies.
Arthur O'Dwyer [Sat, 17 Apr 2021 13:56:34 +0000 (09:56 -0400)]
[libc++] [CI] Fail if the headers contain cyclic dependencies.

Since we have a tool to detect cycles now; and since we're entering
a phase where people can easily introduce cycles by accident (D100682)
or by request (D90999), I think it's increasingly important to shift
the burden of detecting these cycles onto the buildbot instead of
the poor human reviewer.

Also, grep for non-ASCII characters (such as U+200B and U+00AD)
and hard tabs; don't let those get checked in.

Differential Review: https://reviews.llvm.org/D100703

3 years agoRevert "[SCEV] Model `ashr exact x, C` as `(abs(x) EXACT/u (1<<C)) * signum(x)`"
Roman Lebedev [Sun, 18 Apr 2021 13:20:34 +0000 (16:20 +0300)]
Revert "[SCEV] Model `ashr exact x, C` as `(abs(x) EXACT/u (1<<C)) * signum(x)`"

As being discussed in https://reviews.llvm.org/D100721,
this modelling is lossy, we can't reconstruct `ash`/`ashr exact`
from it, which means that whenever we actually expand the IR,
we've just pessimized the code..

It would be good to model this pattern, after all it comes up every time
you want to compute a distance between two pointers, but not at this cost.

This reverts commit ec54867df5e7f20e12146e628af34f0384308bcb.

3 years ago[clang] Fix cross compiling clang for windows after 141945f950e2f3f
Martin Storsjö [Sun, 18 Apr 2021 12:53:48 +0000 (15:53 +0300)]
[clang] Fix cross compiling clang for windows after 141945f950e2f3f

Don't try to execute clang-ast-dump when cross compiling.

3 years ago[lldb] Remove a superfluous trailing semicolon, fixing warnings. NFC.
Martin Storsjö [Sun, 18 Apr 2021 12:53:04 +0000 (15:53 +0300)]
[lldb] Remove a superfluous trailing semicolon, fixing warnings. NFC.

3 years ago[Docs] Correct Boehm collector weblink in GarbageCollection.rst
xgupta [Sun, 18 Apr 2021 12:00:17 +0000 (17:30 +0530)]
[Docs] Correct Boehm collector weblink in GarbageCollection.rst

3 years ago[gn build] Port 01ace074fcb6
LLVM GN Syncbot [Sun, 18 Apr 2021 11:35:28 +0000 (11:35 +0000)]
[gn build] Port 01ace074fcb6

3 years ago[libc++] Implements ranges::enable_borrowed_range
Mark de Wever [Tue, 24 Nov 2020 17:08:02 +0000 (18:08 +0100)]
[libc++] Implements ranges::enable_borrowed_range

This is the initial patch to implement ranges in libc++.

Implements parts of:
- P0896R4 One Ranges Proposal
- P1870 forwarding-range is too subtle
- LWG3379 in several library names is misleading

Reviewed By: ldionne, #libc, cjdb, zoecarver, Quuxplusone

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

3 years ago[IndVarSimplify] Add test requiring ashr expansion.
Florian Hahn [Sun, 18 Apr 2021 11:09:59 +0000 (12:09 +0100)]
[IndVarSimplify] Add test requiring ashr expansion.

Add test cases showing large ashr expansion during IndVarSimplify
after ec54867df5e7.

3 years ago[AST][Introspection][NFC] Remove unnecessary temporary strings.
Nathan James [Sun, 18 Apr 2021 08:25:12 +0000 (09:25 +0100)]
[AST][Introspection][NFC] Remove unnecessary temporary strings.

3 years ago[NFC][X86][CostModel] Rewrite load_store.ll
Roman Lebedev [Sun, 18 Apr 2021 08:07:04 +0000 (11:07 +0300)]
[NFC][X86][CostModel] Rewrite load_store.ll

Test SSE41, since that added float/i64/i32/i8 inserts/extracts.
Don't forget to test vectors of pointers.
Do test byte-aligned loads/stores.
Fixup test coverage to be rather more exhaustive,
testing all reasonable element sizes vs element counts permutations
that fit up to witin ZMM.

3 years ago[NFC][LoopVectorize] Autogenerate check lines in X86/gather_scatter.ll test
Roman Lebedev [Sun, 18 Apr 2021 07:26:16 +0000 (10:26 +0300)]
[NFC][LoopVectorize] Autogenerate check lines in X86/gather_scatter.ll test

3 years agoUpdate InstCombine to use undef matcher instead
Juneyoung Lee [Sun, 18 Apr 2021 02:05:34 +0000 (11:05 +0900)]
Update InstCombine to use undef matcher instead

This is a patch to use m_Undef() matcher instead of isa<UndefValue>().

As suggested in D100122, this update is separately committed.

3 years agoUpdate m_Undef to match vectors/aggrs with undefs and poisons mixed
Juneyoung Lee [Sun, 18 Apr 2021 01:57:04 +0000 (10:57 +0900)]
Update m_Undef to match vectors/aggrs with undefs and poisons mixed

This fixes https://reviews.llvm.org/D93990#2666922
by teaching `m_Undef` to match vectors/aggrs with poison elements.

As suggested, fixes in InstCombine files to use the `m_Undef` matcher instead
of `isa<UndefValue>` will be followed.

Reviewed By: lebedev.ri

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

3 years ago[AST] Add TypeLoc support to node introspection
Stephen Kelly [Wed, 24 Mar 2021 02:29:30 +0000 (02:29 +0000)]
[AST] Add TypeLoc support to node introspection

Extend the matchers gathering API for types to record template
parameters.  The TypeLoc type hierarchy has some types which are
templates used in CRTP such as PointerLikeTypeLoc.  Record the inherited
template and template arguments of types inheriting those CRTP types in
the ClassInheritance map.  Because the name inherited from is now
computed, the value type in that map changes from StringRef to
std::string.  This also causes the toJSON override signature used to
serialize that map to change.

Remove the logic for skipping over empty ClassData instances.  Several
classes such as TypeOfExprTypeLoc inherit a CRTP class which provides
interesting locations though the derived class does not.  Record it as a
class to make the locations it inherits available.

Record the typeSourceInfo accessors too as they provide access to
TypeLocs in many classes.

The existing unit tests use UnorderedElementsAre to compare the
introspection result with the expected result.  Our current
implementation of google mock (in gmock-generated-matchers.h) is limited
to support for comparing a container of 10 elements.  As we are now
returning more than 10 results for one of the introspection tests,
change it to instead compare against an ordered vector of pairs.

Because a macro is used to generate API strings and API calls, disable
clang-format in blocks of expected results.  Otherwise clang-format
would insert whitespaces which would then be compared against the
introspected strings and fail the test.

Introduce a recursion guard in the generated code.  The TypeLoc class
has IgnoreParens() API which by default returns itself, so it would
otherwise recurse infinitely.

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

3 years ago[libc++] Remove hard tabs, U+00AD, and U+200B from all libc++ headers. NFCI.
Arthur O'Dwyer [Sat, 17 Apr 2021 21:03:20 +0000 (17:03 -0400)]
[libc++] Remove hard tabs, U+00AD, and U+200B from all libc++ headers. NFCI.

3 years ago[ADT] Update RPOT to work with specializations of different types.
Florian Hahn [Sat, 17 Apr 2021 17:16:07 +0000 (18:16 +0100)]
[ADT] Update RPOT to work with specializations of different types.

At the moment, ReversePostOrderTraversal performs a post-order walk on
the entry node of the passed in graph, rather than the graph type
itself.

If GT::NodeRef is the same as GraphT, everything works as expected and
this is the case for the current uses in-tree. But it does not work as
expected if GraphT != GT::NodeRef. In that case, we either fail to build
(if there is no GraphTrait specialization for GT:NodeRef) or we pick the
GraphTrait specialization for GT::NodeRef, instead of the specialization
of GraphT.

Both the depth-first and post-order iterators pick the expected
specalization and this patch updates ReversePostOrderTraversal to
delegate to po_begin & po_end to pick the right specialization, rather
than forcing using GraphTraits<GT::NodeRef>, by first getting the entry
node.

This makes `ReversePostOrderTraversal<Graph<6>> RPOT(G);` build and
work as expected in the test.

Reviewed By: dexonsmith

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

3 years ago[LoopUnroll] Regenerate test checks (NFC)
Nikita Popov [Sat, 17 Apr 2021 18:58:27 +0000 (20:58 +0200)]
[LoopUnroll] Regenerate test checks (NFC)

3 years ago[LoopUnroll] Make some tests more robust (NFC)
Nikita Popov [Sat, 17 Apr 2021 18:55:57 +0000 (20:55 +0200)]
[LoopUnroll] Make some tests more robust (NFC)

Replace branch on undef by branch on unknown condition.

3 years ago[JITLink] Add testcase that was accidentally left out of 19e402d2b34.
Lang Hames [Sat, 17 Apr 2021 18:55:14 +0000 (11:55 -0700)]
[JITLink] Add testcase that was accidentally left out of 19e402d2b34.

3 years ago[clang-scan-deps] Add support for clang-cl
Sylvain Audi [Sat, 17 Apr 2021 16:49:40 +0000 (12:49 -0400)]
[clang-scan-deps] Add support for clang-cl

clang-scan-deps contains some command line parsing and modifications.
This patch adds support for clang-cl command options.

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

3 years ago[clang-scan-deps] Support double-dashes in clang command lines
Sylvain Audi [Sat, 17 Apr 2021 01:45:42 +0000 (21:45 -0400)]
[clang-scan-deps] Support double-dashes in clang command lines

This fixes argument injection in clang command lines, by adding them before "--".

Previously, the arguments were injected at the end of the command line and could be added after "--", which would be wrongly interpreted as input file paths.

This fix is needed for a subsequent patch, see D92191.

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

3 years ago[Support] ThreadPool tests: silence warning unused variable 'It'
Alexandre Ganea [Sat, 17 Apr 2021 17:56:23 +0000 (13:56 -0400)]
[Support] ThreadPool tests: silence warning unused variable 'It'

3 years ago[AST] Enable AST node introspection on WIN32
Stephen Kelly [Sat, 17 Apr 2021 17:58:05 +0000 (18:58 +0100)]
[AST] Enable AST node introspection on WIN32

3 years ago[TableGen] Remove local SmallSet from TypeSetByHwMode::insert.
Craig Topper [Sat, 17 Apr 2021 17:47:04 +0000 (10:47 -0700)]
[TableGen] Remove local SmallSet from TypeSetByHwMode::insert.

This keeps track of which modes are in VVT so we can find out
if a mode is missing later. But we can just ask VVT whether it
has a particular mode.

3 years ago[NFC] Fixed Typos
Jennifer Chukwu [Sat, 17 Apr 2021 15:04:06 +0000 (20:34 +0530)]
[NFC] Fixed Typos

Reviewed By: xgupta

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

3 years ago[AST] Remove args from LocationCall
Stephen Kelly [Fri, 16 Apr 2021 21:29:06 +0000 (22:29 +0100)]
[AST] Remove args from LocationCall

This class initially had args to be generic to future needs. In
particular, I thought that source location introspection should show the
getBeginLoc of CallExpr args and the getArgLoc of
TemplateSpecializationLocInfo etc.  However, that is probably best left
out of source location introspection because it involves node traversal.

If something like this is needed in the future, it can be added in the
future.

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

3 years ago[ADT] Take graph as const & in some post-order iterators (NFC).
Florian Hahn [Sat, 17 Apr 2021 14:22:54 +0000 (15:22 +0100)]
[ADT] Take graph as const & in some post-order iterators (NFC).

This patch updates a couple of functions that unnecessarily took the
input graph by value, when it was not needed. They can take the graph by
const-reference instead, which does not require GraphT to provide a copy
constructor.

Split off from D100169.

3 years ago[libcxx][doc] Fixes typos.
Mark de Wever [Sat, 17 Apr 2021 16:01:32 +0000 (18:01 +0200)]
[libcxx][doc] Fixes typos.

3 years ago[HIP] Support hipRTC in header
Yaxun (Sam) Liu [Fri, 16 Apr 2021 14:40:17 +0000 (10:40 -0400)]
[HIP] Support hipRTC in header

hipRTC compiles HIP device code at run time. Since the system may not
have development tools installed, when a HIP program is compiled through
hipRTC, there is no standard C or C++ header available. As such, the HIP
headers should not depend on standard C or C++ headers when used
with hipRTC. Basically when hipRTC is used, HIP headers only provides
definitions of HIP device API functions. This is in line with what nvRTC does.

This patch adds support of hipRTC to HIP headers in clang. Basically hipRTC
defines a macro __HIPCC_RTC__ when compile HIP code at run time. When
this macro is defined, HIP headers do not include standard C/C++ headers.

Reviewed by: Artem Belevich

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

3 years ago[Pragma] Added support for GCC unroll/nounroll
Dávid Bolvanský [Sat, 17 Apr 2021 15:27:11 +0000 (17:27 +0200)]
[Pragma] Added support for GCC unroll/nounroll

GCC 8 introduced these new pragmas to control loop unrolling. We should support them for compatibility reasons and the implementation itself requires few lines of code, since everything needed is already implemented for #pragma unroll/nounroll.

3 years ago[CUDA][HIP] Mark device var used by host only
Yaxun (Sam) Liu [Wed, 17 Mar 2021 20:14:03 +0000 (16:14 -0400)]
[CUDA][HIP] Mark device var used by host only

Add device variables to llvm.compiler.used if they are
ODR-used by either host or device functions.

This is necessary to prevent them from being
eliminated by whole-program optimization
where the compiler has no way to know a device
variable is used by some host code.

Reviewed by: Artem Belevich

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

3 years ago[AMDGPU] Add GlobalDCE before internalization pass
Yaxun (Sam) Liu [Wed, 17 Mar 2021 14:31:06 +0000 (14:31 +0000)]
[AMDGPU] Add GlobalDCE before internalization pass

The internalization pass only internalizes global variables
with no users. If the global variable has some dead user,
the internalization pass will not internalize it.

To be able to internalize global variables with dead
users, a global dce pass is needed before the
internalization pass.

This patch adds that.

Reviewed by: Artem Belevich, Matt Arsenault

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

3 years ago[LICM] Add more tests for promotion and capture (NFC)
Nikita Popov [Sat, 17 Apr 2021 14:56:21 +0000 (16:56 +0200)]
[LICM] Add more tests for promotion and capture (NFC)

We could optimize the first case, as the pointer is captured only
after the loop.

3 years ago[SimplifyCFG] Skip dbg intrinsics when checking for branch-only BBs.
Florian Hahn [Sat, 17 Apr 2021 12:12:15 +0000 (13:12 +0100)]
[SimplifyCFG] Skip dbg intrinsics when checking for branch-only BBs.

Debug intrinsics are free to hoist and should be skipped when looking
for terminator-only blocks. As a consequence, we have to delegate to the
main hoisting loop to hoist any dbg intrinsics instead of jumping to the
terminator case directly.

This fixes PR49982.

Reviewed By: lebedev.ri

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

3 years ago[Inline] Don't add noalias metadata to inaccessiblememonly calls
Nikita Popov [Sat, 17 Apr 2021 12:51:29 +0000 (14:51 +0200)]
[Inline] Don't add noalias metadata to inaccessiblememonly calls

It will not do anything useful for them, as we already know that
they don't modref with any accessible memory.

In particular, this prevents noalias metadata from being placed
on noalias.scope.decl intrinsics. This reduces the amount of
metadata needed, and makes it more likely that unnecessary decls
can be eliminated.

3 years ago[Support] AbsoluteDifference - add brackets to appease static analyzer warning. NFCI.
Simon Pilgrim [Sat, 17 Apr 2021 11:00:38 +0000 (12:00 +0100)]
[Support] AbsoluteDifference - add brackets to appease static analyzer warning. NFCI.

3 years ago[Sanitizers] Fix build
David CARLIER [Sat, 17 Apr 2021 10:15:31 +0000 (11:15 +0100)]
[Sanitizers] Fix build

3 years ago[Sanitizers] DragonFlyBSD adding support for builtins
David Carlier [Sat, 17 Apr 2021 10:10:35 +0000 (11:10 +0100)]
[Sanitizers] DragonFlyBSD adding support for builtins
Reviewed By: vitalybuka

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

3 years ago[Sanitizers] Undefined Behavior Sanitizer support for DragonFlyBSD
David Carlier [Sat, 17 Apr 2021 10:08:00 +0000 (11:08 +0100)]
[Sanitizers] Undefined Behavior Sanitizer support for DragonFlyBSD
Reviewed By: vitalybuka

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

3 years ago[ELF] --wrap: don't clear sym->isUsedInRegularObj if real->isUsedInRegularObj; set...
Fangrui Song [Sat, 17 Apr 2021 07:29:51 +0000 (00:29 -0700)]
[ELF] --wrap: don't clear sym->isUsedInRegularObj if real->isUsedInRegularObj; set wrap's initial binding to sym's

Fix PR49897: if `__real_foo` has the isUsedInRegularObj bit set, we need to
retain `foo` in .symtab, even if `foo` is undefined. The new behavior will match
GNU ld.

Before the patch, we produced an R_X86_64_JUMP_SLOT relocation referencing the
index 0 undefined symbol, which would be erroed by glibc
(see f96ff3c0f8ebd941b3f6b345164c3d858b781484).

While here, fix another bug: if `__wrap_foo` does not exist, its initial binding
should be `foo`'s.

3 years agoNormalize interaction with boolean attributes
Serge Guelton [Wed, 24 Mar 2021 20:45:04 +0000 (16:45 -0400)]
Normalize interaction with boolean attributes

Such attributes can either be unset, or set to "true" or "false" (as string).
throughout the codebase, this led to inelegant checks ranging from

        if (Fn->getFnAttribute("no-jump-tables").getValueAsString() == "true")

to

        if (Fn->hasAttribute("no-jump-tables") && Fn->getFnAttribute("no-jump-tables").getValueAsString() == "true")

Introduce a getValueAsBool that normalize the check, with the following
behavior:

no attributes or attribute set to "false" => return false
attribute set to "true" => return true

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

3 years ago[libc][NFC] Use explicit conversion in aarch64 FEnv.
Siva Chandra [Sat, 17 Apr 2021 05:29:52 +0000 (22:29 -0700)]
[libc][NFC] Use explicit conversion in aarch64 FEnv.

3 years ago[libc]NFC] Use explicit conversion on frexpl_test and logbl_test.
Siva Chandra Reddy [Sat, 17 Apr 2021 05:49:23 +0000 (05:49 +0000)]
[libc]NFC] Use explicit conversion on frexpl_test and logbl_test.

3 years ago[libc][NFC] Use explicit conversion in modfl_test.
Siva Chandra Reddy [Sat, 17 Apr 2021 05:41:20 +0000 (05:41 +0000)]
[libc][NFC] Use explicit conversion in modfl_test.

3 years ago[libc][NFC] Make conversion from FPBits to the float point type explicit.
Siva Chandra Reddy [Wed, 14 Apr 2021 06:04:11 +0000 (06:04 +0000)]
[libc][NFC] Make conversion from FPBits to the float point type explicit.

This will help us catch errors like the ones fixed by the commit
31ed45d9cfd5da2bf4f1d7ddba54122df6fc91fa

3 years ago[libc][NFC] Add common template test class for sqrt, sqrtf and sqrtl.
Siva Chandra Reddy [Sat, 17 Apr 2021 05:06:13 +0000 (05:06 +0000)]
[libc][NFC] Add common template test class for sqrt, sqrtf and sqrtl.

3 years ago[ELF] Simplify R_386_TLS_GD computation. NFC
Fangrui Song [Sat, 17 Apr 2021 02:08:23 +0000 (19:08 -0700)]
[ELF] Simplify R_386_TLS_GD computation. NFC

3 years ago[TableGen] Replace two SmallDenseSets with SmallSets.
Craig Topper [Sat, 17 Apr 2021 00:45:40 +0000 (17:45 -0700)]
[TableGen] Replace two SmallDenseSets with SmallSets.

The key here is HwMode indices. They're going to be small numbers,
contiguous, and only a few different values. I don't think we need
to go through the SmallDenseSet hashing.

A BitVector would be even better, but we don't have the upper
bound here.

3 years ago[ASTReader] Only mark module out of date if not already compiled
Ben Barham [Sat, 17 Apr 2021 00:55:39 +0000 (17:55 -0700)]
[ASTReader] Only mark module out of date if not already compiled

If a module contains errors (ie. it was built with
-fallow-pcm-with-compiler-errors and had errors) and was from the module
cache, it is marked as out of date - see
a2c1054c303f20be006e9ef20739dbb88bd9ae02.

When a module is imported multiple times in the one compile, this caused
it to be recompiled each time - removing the existing buffer from the
module cache and replacing it. This results in various errors further
down the line.

Instead, only mark the module as out of date if it isn't already
finalized in the module cache.

Reviewed By: akyrtzi

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

3 years ago[PowerPC] Minor improvement for insert_vector_elt codegen
Nemanja Ivanovic [Fri, 16 Apr 2021 23:51:07 +0000 (18:51 -0500)]
[PowerPC] Minor improvement for insert_vector_elt codegen

For v2f64, all VSX subtargets can insert an element with a single
XXPERMDI.

3 years ago[clang][NFC] Fix a potential assert failure
Ben Shi [Fri, 16 Apr 2021 23:17:34 +0000 (07:17 +0800)]
[clang][NFC] Fix a potential assert failure

Reviewed By: MaskRay, craig.topper

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

3 years agoTarget::ReadMemory read from read-only binary file Section, not memory
Jason Molenda [Fri, 16 Apr 2021 23:10:16 +0000 (16:10 -0700)]
Target::ReadMemory read from read-only binary file Section, not memory

Commiting this patch for Augusto Noronha who is getting set
up still.

This patch changes Target::ReadMemory so the default behavior
when a read is in a Section that is read-only is to fetch the
data from the local binary image, instead of reading it from
memory.  Update all callers to use their old preferences
(the old prefer_file_cache bool) using the new API; we should
revisit these calls and see if they really intend to read
live memory, or if reading from a read-only Section would be
equivalent and important for performance-sensitive cases.

rdar://30634422

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

3 years ago[inferattrs] Don't infer lib func attributes for nobuiltin functions
Philip Reames [Fri, 16 Apr 2021 22:28:15 +0000 (15:28 -0700)]
[inferattrs] Don't infer lib func attributes for nobuiltin functions

If we have a nobuiltin function, we can't assume we know anything about the implementation.

I noticed this when tracing through a log from an in the wild miscompile (https://github.com/emscripten-core/emscripten/issues/9443) triggered after 8666463.  We were incorrectly assuming that a custom allocator could not free.  (It's not clear yet this is the only problem in said issue.)

I also noticed something similiar mentioned in the commit message of ab243e when scrolling back through history.  Through, from what I can tell, that commit fixed symptom not root cause.

The interface we have for library function detection is extremely error prone, but given the interaction between ``nobuiltin`` decls and ``builtin`` callsites, it's really hard to imagine something much cleaner.  I may iterate on that, but it'll be invasive enough I didn't want to hold an obvious functional fix on it.

3 years ago[gn build] (manually) port ca6751043d88 better
Nico Weber [Fri, 16 Apr 2021 22:16:14 +0000 (18:16 -0400)]
[gn build] (manually) port ca6751043d88 better

3 years ago[TableGen] Run GenerateVariants before ExpandHwModeBasedTypes.
Craig Topper [Fri, 16 Apr 2021 21:59:40 +0000 (14:59 -0700)]
[TableGen] Run GenerateVariants before ExpandHwModeBasedTypes.

A large portion of the patterns are duplicated for HwMode on RISCV.
If we expand HwMode first, we need to check nearly twice as many
patterns for variants. HwModes shouldn't affect whether a variant
is valid so we should be able to expand after.

This also reduces the RISCV isel table by 539 bytes due to factoring
working better on this pattern order. Unfortunately it increases
Hexagon table size by ~50 bytes. But I think this is a reasonable
trade.

3 years ago[gn build] (manually) port ca6751043d88
Nico Weber [Fri, 16 Apr 2021 22:03:44 +0000 (18:03 -0400)]
[gn build] (manually) port ca6751043d88

3 years ago[libc] Fix wrongly deduced type
Guillaume Chatelet [Fri, 16 Apr 2021 21:58:27 +0000 (21:58 +0000)]
[libc] Fix wrongly deduced type

3 years ago[OpenMP] Implement GOMP task reductions
Peyton, Jonathan L [Mon, 15 Mar 2021 19:02:34 +0000 (14:02 -0500)]
[OpenMP] Implement GOMP task reductions

Implement the remaining GOMP_* functions to support task reductions
in taskgroup, parallel, loop, and taskloop constructs.  The unused mem
argument to many of the work-sharing constructs has to do with the
scan() directive/ inscan() modifier.  If mem is set, each function
will call KMP_FATAL() and tell the user scan/inscan is unsupported.  The
GOMP reduction implementation is kept separate from our implementation
because of how GOMP presents reduction data and computes the reductions.
GOMP expects the privatized copies to be present even after a #pragma
omp parallel reduction(task:...) region has ended so the data is stored
inside GOMP's uintptr_t* data pseudo-structure.  This style is tightly
coupled with GCC compiler codegen.  There also isn't any init(),
combiner(), fini() functions in GOMP's codegen so the two
implementations were to disparate to try to wrap GOMP's around our own.

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

3 years ago[libc] Add endianness support
Guillaume Chatelet [Fri, 16 Apr 2021 21:34:49 +0000 (21:34 +0000)]
[libc] Add endianness support

Add endianness detection support. This will be useful to implement `memcmp`.

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

3 years ago[OpenMP] Allow affinity to re-detect for child processes
Peyton, Jonathan L [Tue, 23 Mar 2021 19:02:55 +0000 (14:02 -0500)]
[OpenMP] Allow affinity to re-detect for child processes

Current atfork() handler for child processes does not reset
the affinity masks array which prevents users from setting their own
affinity in child processes.

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

3 years ago[funcattrs] Add the maximal set of implied attributes to definitions
Philip Reames [Fri, 16 Apr 2021 21:03:36 +0000 (14:03 -0700)]
[funcattrs] Add the maximal set of implied attributes to definitions

Have funcattrs expand all implied attributes into the IR. This expands the infrastructure from D100400, but for definitions not declarations this time.

Somewhat subtly, this mostly isn't semantic. Because the accessors did the inference, any client which used the accessor was already getting the stronger result. Clients that directly checked presence of attributes (there are some), will see a stronger result now.

The old behavior can end up quite confusing for two reasons:
* Without this change, we have situations where function-attrs appears to fail when inferring an attribute (as seen by a human reading IR), but that consuming code will see that it should have been implied. As a human trying to sanity check test results and study IR for optimization possibilities, this is exceeding error prone and confusing. (I'll note that I wasted several hours recently because of this.)
* We can have transforms which trigger without the IR appearing (on inspection) to meet the preconditions. This change doesn't prevent this from happening (as the accessors still involve multiple checks), but it should make it less frequent.

I'd argue in favor of deleting the extra checks out of the accessors after this lands, but I want that in it's own review as a) it's purely stylistic, and b) I already know there's some disagreement.

Once this lands, I'm also going to do a cleanup change which will delete some now redundant duplicate predicates in the inference code, but again, that deserves to be a change of it's own.

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

3 years ago[libc] Extends the testing framework to support typed test
Guillaume Chatelet [Fri, 16 Apr 2021 09:18:03 +0000 (09:18 +0000)]
[libc] Extends the testing framework to support typed test

This patch provides `TYPED_TEST` and `TYPED_TEST_F` (similar in functionnality to gtest).
This is needed to extensively test building blocks for memory functions.

Example for `TYPED_TEST_F`:
```
template <typename T> class LlvmLibcMyTestFixture : public testing::Test {};

using Types = testing::TypeList<char, int, long>;

TYPED_TEST_F(LlvmLibcMyTestFixture, Simple, Types) {
  EXPECT_LE(sizeof(ParamType), 8UL);
}
```

Example for `TYPED_TEST`:
```
using Types = testing::TypeList<char, int, long>;

TYPED_TEST(LlvmLibcMyTest, Simple, Types) {
  EXPECT_LE(sizeof(ParamType), 8UL);
}
```

`ParamType` is displayed as fully qualified canonical type which can be difficult to read, the user can provide a more readable name by using the `REGISTER_TYPE_NAME` macro.

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

3 years ago[lld] Canonicalize HAVE_LIBXAR
Jez Ng [Fri, 16 Apr 2021 21:20:13 +0000 (17:20 -0400)]
[lld] Canonicalize HAVE_LIBXAR

I think this should unbreak the build after D100650...

3 years ago[sanitizer] GetTls: work around ppc64 with glibc<2.25(?) or GNU ld 2.30
Fangrui Song [Fri, 16 Apr 2021 21:03:28 +0000 (14:03 -0700)]
[sanitizer] GetTls: work around ppc64 with glibc<2.25(?) or GNU ld 2.30

GNU ld 2.26 and GNU ld 2.31 seem fine but GNU ld 2.30 has mysterious
segfaults linking msan tests.

3 years ago[lld-macho] Add separator to error message
Jez Ng [Fri, 16 Apr 2021 20:59:25 +0000 (16:59 -0400)]
[lld-macho] Add separator to error message

3 years ago[lldb] Set addressable bits from qHostInfo
Jonas Devlieghere [Fri, 16 Apr 2021 20:49:24 +0000 (13:49 -0700)]
[lldb] Set addressable bits from qHostInfo

Read the number of addressable bits from the qHostInfo packet and use it
to set the code and data address mask in the process. The data
(addressing_bits) is already present in the packet.

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

3 years ago[lldb] Implement ABI::Fix{Code,Data}Address for AArch64
Jonas Devlieghere [Fri, 16 Apr 2021 19:39:39 +0000 (12:39 -0700)]
[lldb] Implement ABI::Fix{Code,Data}Address for AArch64

Implement FixCodeAddress and FixDataAddress for ABIMacOSX_arm64 and
ABISysV_arm64 and add missing calls to RegisterContextUnwind. We need
this to unwind on Apple Silicon where libraries like libSystem are
arm64e even when the program being debugged is arm64.

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

3 years agoSimplify BitVector code
serge-sans-paille [Tue, 13 Apr 2021 14:14:32 +0000 (16:14 +0200)]
Simplify BitVector code

Instead of managing memory by hand, delegate it to std::vector. This makes the
code much simpler, and also avoids repeatedly computing the storage size.

According to valgrind --tool=callgrind, this also slightly decreases the
instruction count, but by a small margin.

This is a recommit of 82f0e3d3ea6bf927e3397b2fb423abbc5821a30f with one usage
fixed in llvm/lib/CodeGen/RegisterScavenging.cpp.

Not the slight API change: BitVector::clear() now has the same behavior as any
other container: it does not free memory, but indeed sets the size of the
BitVector to 0. It is thus incorrect to access its content right afterwards, a
scenario which wasn't enforced in previous implementation.

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

3 years ago[lld-macho] Initial groundwork for -bitcode_bundle
Jez Ng [Fri, 16 Apr 2021 20:46:45 +0000 (16:46 -0400)]
[lld-macho] Initial groundwork for -bitcode_bundle

This diff creates an empty XAR file and copies it into
`__LLVM,__bundle`. Follow-up work will actually populate the contents of
that XAR.

Reviewed By: #lld-macho, gkm

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

3 years ago[TableGen] Fix -Wparentheses
Fangrui Song [Fri, 16 Apr 2021 20:37:52 +0000 (13:37 -0700)]
[TableGen] Fix -Wparentheses

3 years ago[AMDGPU] Remove redundant field from DPP8 def
Joe Nash [Fri, 16 Apr 2021 17:22:23 +0000 (13:22 -0400)]
[AMDGPU] Remove redundant field from DPP8 def

These lines set the value to what it already was,
so they are redundant. NFC

Reviewed By: rampitec

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

Change-Id: Ibf6f27d50a7fa1f76c127f01b799821378bfd3b3

3 years ago[AMDGPU] NFC, Comment in disassembler for dpp8
Joe Nash [Fri, 16 Apr 2021 17:15:50 +0000 (13:15 -0400)]
[AMDGPU] NFC, Comment in disassembler for dpp8

Gives reasoning for convertDPP8.
Also corrects typo in Operand type comment.

Reviewed By: rampitec

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

Change-Id: I33ff269db8072d83e5e0ecdbfb731d6000fc26c4

3 years ago[TableGen] Predicate::operator== needs to compare the HwMode feature name in addition...
Craig Topper [Fri, 16 Apr 2021 20:16:47 +0000 (13:16 -0700)]
[TableGen] Predicate::operator== needs to compare the HwMode feature name in addition to the HwMode flag.

This was causing GenerateVariants to lose some variants since
HwMode is expanded first. We were mistakenly thinking the HwMode
predicate matched and finding the variant was isomorphic to a
pattern in another HwMode and discarding it.

Found while investigating it if would be better to generate
variants before expanding HwModes to improve RISCV build time.
I noticed an increase in the number of Opc_MorphNodeTo in the table
which indicated that the number of patterns had changed.

3 years ago[AMDGPU] Enforce that gfx802/803/805 do not support XNACK
Tony [Thu, 10 Dec 2020 04:07:04 +0000 (04:07 +0000)]
[AMDGPU] Enforce that gfx802/803/805 do not support XNACK

Reviewed By: kzhuravl

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

3 years ago[lldb] Add code and data address mask to Process
Jonas Devlieghere [Wed, 14 Apr 2021 23:34:04 +0000 (16:34 -0700)]
[lldb] Add code and data address mask to Process

Add a code and data address mask to Process with respective getters and
setters and a setting that allows the user to specify the mast as a
number of addressable bits. The masks will be used by FixCodeAddress and
FixDataAddress respectively in the ABI classes.

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

3 years ago[ELF] Default to -z start-stop-gc with a glibc "__libc_" special case
Fangrui Song [Fri, 16 Apr 2021 19:18:45 +0000 (12:18 -0700)]
[ELF] Default to -z start-stop-gc with a glibc "__libc_" special case

Change the default to facilitate GC for metadata section usage, so that they
don't need SHF_LINK_ORDER or SHF_GROUP just to drop the unhelpful rule (if they
want to be unconditionally retained, use SHF_GNU_RETAIN
(`__attribute__((retain))`) or linker script `KEEP`).

The dropped SHF_GROUP special case makes the behavior of -z start-stop-gc and -z
nostart-stop-gc closer to GNU ld>=2.37 (https://sourceware.org/PR27451).

However, we default to -z start-stop-gc (which actually matches more closely to
GNU ld before 2015-10 https://sourceware.org/PR19167), which is different from
modern GNU ld (which has the unhelpful rule to work around glibc). As a
compensation, we special case `__libc_` sections as a workaround for glibc<2.34
(https://sourceware.org/PR27492).

Since -z start-stop-gc as the default actually matches the traditional GNU ld
behavior, there isn't much to be aware of. There was a systemd usage which has
been fixed by https://github.com/systemd/systemd/pull/19144

3 years ago[WebAssembly] Remove saturating fp-to-int target intrinsics
Thomas Lively [Fri, 16 Apr 2021 19:11:20 +0000 (12:11 -0700)]
[WebAssembly] Remove saturating fp-to-int target intrinsics

Use the target-independent @llvm.fptosi and @llvm.fptoui intrinsics instead.
This includes removing the instrinsics for i32x4.trunc_sat_zero_f64x2_{s,u},
which are now represented in IR as a saturating truncation to a v2i32 followed by
a concatenation with a zero vector.

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

3 years agoDeclContext: Fix iterator category
Björn Schäpers [Thu, 15 Apr 2021 18:49:46 +0000 (20:49 +0200)]
DeclContext: Fix iterator category

This amends 0cb7e7ca0c864e052bf49978f3bcd667c9e16930.
The iterator category of lookup_iterator was changed, but here it stayed
hardcoded as random access. Found while trying to build Clazy.

Differential-Revision: https://reviews.llvm.org/D100590

3 years ago[tblgen] Fold loop into assert to avoid unused variable warnings. NFCI.
Benjamin Kramer [Fri, 16 Apr 2021 18:47:38 +0000 (20:47 +0200)]
[tblgen] Fold loop into assert to avoid unused variable warnings. NFCI.

3 years ago[nofree] Restrict semantics to memory visible to caller
Philip Reames [Fri, 16 Apr 2021 18:37:36 +0000 (11:37 -0700)]
[nofree] Restrict semantics to memory visible to caller

This patch clarifies the semantics of the nofree function attribute to make clear that it provides an "as if" semantic. That is, a nofree function is guaranteed not to free memory which existed before the call, but might allocate and then deallocate that same memory within the lifetime of the callee.

This is the result of the discussion on llvm-dev under the thread "Ambiguity in the nofree function attribute".

The most important part of this change is the LangRef wording. The rest is minor comment changes to emphasize the new semantics where code was accidentally consistent, and fix one place which wasn't consistent. That one place is currently narrowly used as it is primarily part of the ongoing (and not yet enabled) deref-at-point semantics work.

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

3 years ago[Builtins] Add memory allocation builtins (PR12543)
Dávid Bolvanský [Fri, 16 Apr 2021 18:34:03 +0000 (20:34 +0200)]
[Builtins] Add memory allocation builtins (PR12543)

3 years ago[CUDA, FDO] Filter out profiling options from GPU-side compilations.
Artem Belevich [Thu, 15 Apr 2021 20:48:28 +0000 (13:48 -0700)]
[CUDA, FDO] Filter out profiling options from GPU-side compilations.

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

3 years agoAddress D100645 comment
Vitaly Buka [Fri, 16 Apr 2021 18:28:41 +0000 (11:28 -0700)]
Address D100645 comment

3 years agoSanitizer built against glibc 2.34 doesn't work
Vitaly Buka [Fri, 16 Apr 2021 16:50:24 +0000 (09:50 -0700)]
Sanitizer built against glibc 2.34 doesn't work

As mentioned in https://gcc.gnu.org/PR100114 , glibc starting with the
https://sourceware.org/git/?p=glibc.git;a=commit;h=6c57d320484988e87e446e2e60ce42816bf51d53
change doesn't define SIGSTKSZ and MINSIGSTKSZ macros to constants, but to sysconf function call.
sanitizer_posix_libcdep.cpp has
static const uptr kAltStackSize = SIGSTKSZ * 4;  // SIGSTKSZ is not enough.
which is generally fine, just means that when SIGSTKSZ is not a compile time constant will be initialized later.
The problem is that kAltStackSize is used in SetAlternateSignalStack which is called very early, from .preinit_array
initialization, i.e. far before file scope variables are constructed, which means it is not initialized and
mmapping 0 will fail:
==145==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22)

Here is one possible fix, another one could be to make kAltStackSize a preprocessor macro if _SG_SIGSTKSZ is defined
(but perhaps with having an automatic const variable initialized to it so that sysconf isn't at least called twice
during SetAlternateSignalStack.

Reviewed By: vitalybuka

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

3 years ago[LLDB] Re-land: Use path relative to binary for finding .dwo files.
Caroline Tice [Fri, 16 Apr 2021 18:06:19 +0000 (11:06 -0700)]
[LLDB] Re-land: Use path relative to binary for finding .dwo files.

DWARF allows .dwo file paths to be relative rather than absolute. When
they are relative, DWARF uses DW_AT_comp_dir to find the .dwo
file. DW_AT_comp_dir can also be relative, making the entire search
patch for the .dwo file relative. In this case, LLDB currently
searches relative to its current working directory, i.e. the directory
from which the debugger was launched. This is not right, as the
compiler, which generated the relative paths, can have no idea where
the debugger will be launched. The correct thing is to search relative
to the location of the executable binary. That is what this patch
does.

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

3 years ago[M68k] Fix empty builtin va_list kind
Min-Yih Hsu [Fri, 16 Apr 2021 17:53:17 +0000 (10:53 -0700)]
[M68k] Fix empty builtin va_list kind

Clang _requires_ every target to provide a va_list kind so we shouldn't
put a llvm_unreachable there. Using `VoidPtrBuiltinVaList` because m68k
doesn't have any special ABI for variadic args.

3 years agoReland "[Support] Don't include <algorithm> in MathExtras.h"
Nico Weber [Fri, 16 Apr 2021 18:05:12 +0000 (14:05 -0400)]
Reland "[Support] Don't include <algorithm> in MathExtras.h"

This reverts commit af2a93fd6e9f9e037d2e2d67b879fe85d7e1cbed.
This time, add the include to APInt.h, which apparently relied
on getting this include transitively.

3 years ago[TableGen] CodeGenDAGPatterns - use const references on for-range loops to avoid...
Simon Pilgrim [Fri, 16 Apr 2021 17:54:35 +0000 (18:54 +0100)]
[TableGen] CodeGenDAGPatterns - use const references on for-range loops to avoid unnecessary copies. NFCI.