Commit Graph

385769 Commits

Author SHA1 Message Date
Yaxun (Sam) Liu d5c0f00e21 [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
2021-04-17 11:25:25 -04:00
Yaxun (Sam) Liu 3597f02fd5 [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
2021-04-17 11:25:25 -04:00
Nikita Popov ae2da68da6 [LICM] Add more tests for promotion and capture (NFC)
We could optimize the first case, as the pointer is captured only
after the loop.
2021-04-17 16:57:15 +02:00
Florian Hahn af523514c4
[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
2021-04-17 15:17:50 +01:00
Nikita Popov e68b12c99e [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.
2021-04-17 14:56:13 +02:00
Simon Pilgrim 595394321d [Support] AbsoluteDifference - add brackets to appease static analyzer warning. NFCI. 2021-04-17 13:47:02 +01:00
David CARLIER 61fc02dc03 [Sanitizers] Fix build 2021-04-17 11:15:31 +01:00
David Carlier 0df0d6acea [Sanitizers] DragonFlyBSD adding support for builtins
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D89653
2021-04-17 11:10:35 +01:00
David Carlier 4583759414 [Sanitizers] Undefined Behavior Sanitizer support for DragonFlyBSD
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D89631
2021-04-17 11:08:00 +01:00
Fangrui Song 7c74ce3c68 [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 f96ff3c0f8).

While here, fix another bug: if `__wrap_foo` does not exist, its initial binding
should be `foo`'s.
2021-04-17 00:29:51 -07:00
Serge Guelton d6de1e1a71 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
2021-04-17 08:17:33 +02:00
Siva Chandra bbba69425c [libc][NFC] Use explicit conversion in aarch64 FEnv. 2021-04-16 22:53:12 -07:00
Siva Chandra Reddy 7db1102a10 [libc]NFC] Use explicit conversion on frexpl_test and logbl_test. 2021-04-17 05:50:00 +00:00
Siva Chandra Reddy bb8aa2ad1a [libc][NFC] Use explicit conversion in modfl_test. 2021-04-17 05:42:17 +00:00
Siva Chandra Reddy fb706e086c [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
31ed45d9cf
2021-04-17 05:22:20 +00:00
Siva Chandra Reddy fb69b92c7b [libc][NFC] Add common template test class for sqrt, sqrtf and sqrtl. 2021-04-17 05:13:27 +00:00
Fangrui Song b2a3d31eed [ELF] Simplify R_386_TLS_GD computation. NFC 2021-04-16 19:08:23 -07:00
Craig Topper a623051dc3 [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.
2021-04-16 17:57:53 -07:00
Ben Barham 1206b95e07 [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
a2c1054c30.

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
2021-04-16 17:57:03 -07:00
Nemanja Ivanovic ff769dd111 [PowerPC] Minor improvement for insert_vector_elt codegen
For v2f64, all VSX subtargets can insert an element with a single
XXPERMDI.
2021-04-16 18:52:37 -05:00
Ben Shi 06995fe256 [clang][NFC] Fix a potential assert failure
Reviewed By: MaskRay, craig.topper

Differential Revision: https://reviews.llvm.org/D100616
2021-04-17 07:17:34 +08:00
Jason Molenda e9fe788d32 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
2021-04-16 16:13:07 -07:00
Philip Reames 11707435cc [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.
2021-04-16 15:36:15 -07:00
Nico Weber bc636c1c2c [gn build] (manually) port ca6751043d better 2021-04-16 18:16:29 -04:00
Craig Topper be0ffbb21f [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.
2021-04-16 15:05:33 -07:00
Nico Weber 48cc5b0d35 [gn build] (manually) port ca6751043d 2021-04-16 18:03:44 -04:00
Guillaume Chatelet 2bfe15810d [libc] Fix wrongly deduced type 2021-04-16 21:59:25 +00:00
Peyton, Jonathan L 4457565757 [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
2021-04-16 16:36:31 -05:00
Guillaume Chatelet 7e075ad0b2 [libc] Add endianness support
Add endianness detection support. This will be useful to implement `memcmp`.

Differential Revision: https://reviews.llvm.org/D100571
2021-04-16 21:35:08 +00:00
Peyton, Jonathan L 5ebbb366c4 [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
2021-04-16 16:34:02 -05:00
Philip Reames f549176ad9 [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
2021-04-16 14:22:19 -07:00
Guillaume Chatelet 7c02dc22e4 [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
2021-04-16 21:21:35 +00:00
Jez Ng 3e1045ec04 [lld] Canonicalize HAVE_LIBXAR
I think this should unbreak the build after D100650...
2021-04-16 17:21:06 -04:00
Fangrui Song 08843a0c3f [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.
2021-04-16 14:03:28 -07:00
Jez Ng bb0e1ae7c4 [lld-macho] Add separator to error message 2021-04-16 17:01:14 -04:00
Jonas Devlieghere db2da0c8f9 [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
2021-04-16 13:49:38 -07:00
Jonas Devlieghere 8770b4ecca [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
2021-04-16 13:49:38 -07:00
serge-sans-paille 550ed575cb 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 82f0e3d3ea 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
2021-04-16 22:48:33 +02:00
Jez Ng ca6751043d [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
2021-04-16 16:47:14 -04:00
Fangrui Song 657b325416 [TableGen] Fix -Wparentheses 2021-04-16 13:37:52 -07:00
Joe Nash a0ed70abde [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
2021-04-16 16:23:52 -04:00
Joe Nash 919236e608 [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
2021-04-16 16:21:47 -04:00
Craig Topper 6b446310be [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.
2021-04-16 13:22:28 -07:00
Tony 13875aab4e [AMDGPU] Enforce that gfx802/803/805 do not support XNACK
Reviewed By: kzhuravl

Differential Revision: https://reviews.llvm.org/D100679
2021-04-16 19:34:30 +00:00
Jonas Devlieghere fdbb5a7a91 [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
2021-04-16 12:30:54 -07:00
Fangrui Song 6d2d3bd0a6 [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
2021-04-16 12:18:46 -07:00
Thomas Lively 5c729750a6 [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
2021-04-16 12:11:20 -07:00
Björn Schäpers 4696857733 DeclContext: Fix iterator category
This amends 0cb7e7ca0c.
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
2021-04-16 20:59:36 +02:00
Benjamin Kramer 7946cc404f [tblgen] Fold loop into assert to avoid unused variable warnings. NFCI. 2021-04-16 20:47:38 +02:00
Philip Reames ff55d01a8e [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
2021-04-16 11:38:55 -07:00