Commit Graph

177994 Commits

Author SHA1 Message Date
Nico Weber ecefdcd2b9 llvm-undname: Fix hex escapes in wchar_t, char16_t, char32_t strings
llvm-undname used to put '\x' in front of every pair of nibbles, but
u"\xD7\xFF" produces a string with 6 bytes: \xD7 \0 \xFF \0 (and \0\0). Correct
for a single character (plus terminating \0) is u\xD7FF instead.
Now, wchar_t, char16_t, and char32_t strings roundtrip from source to
clang-cl (and cl.exe) and then llvm-undname.

(...at least as long as it's not a string like L"\xD7FF" L"foo" which
gets demangled as L"\xD7FFfoo", where the compiler then considers the
"f" as part of the hex escape. That seems ok.)

Also add a comment saying that the "almost-valid" char32_t string I
added in my last commit is actually produced by compilers.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358857 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 17:19:27 +00:00
Nico Weber f6b23dfdd4 llvm-undname: Fix stack overflow on almost-valid
If a unsigned with all 4 bytes non-0 was passed to outputHex(), there
were two off-by-ones in it:

- Both MaxPos and Pos left space for the final \0, which left the buffer
  one byte to small. Set MaxPos to 16 instead of 15 to fix.

- The `assert(Pos >= 0);` was after a `Pos--`, move it up one line.

Since valid Unicode codepoints are <= 0x10ffff, this could never really
happen in practice.

Found by oss-fuzz.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358856 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 16:58:25 +00:00
Nikita Popov 66c5f5714a [ConstantRange] Add saturating add/sub methods
Add support for uadd_sat and friends to ConstantRange, so we can
handle uadd.sat and friends in LVI. The implementation is forwarding
to the corresponding APInt methods with appropriate bounds.

One thing worth pointing out here is that the handling of wrapping
ranges is not maximally accurate. A simple example is that adding 0
to a wrapped range will return a full range, rather than the original
wrapped range. The tests also only check that the non-wrapping
envelope is correct and minimal.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358855 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 15:23:05 +00:00
Nikita Popov bfce43af72 [ConstantRange] Add getNonEmpty() constructor
ConstantRanges have an annoying special case: If upper and lower are
the same, it can be either an empty or a full set. When constructing
constant ranges nearly always a full set is intended, but this still
requires an explicit check in many places.

This revision adds a getNonEmpty() constructor that disambiguates this
case: If upper and lower are the same, a full set is created.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358854 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 15:22:54 +00:00
Sanjay Patel e1f80841dd [AArch64] add tests with multiple binop+splat vals; NFC
See D60890 for context.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358853 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 15:01:19 +00:00
Nico Weber 2f10db760a llvm-undname: Fix stack overflow on invalid found by oss-fuzz
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358852 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 14:25:07 +00:00
Nico Weber a138d18baa gn build: Fix build after r358837
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358851 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 14:07:13 +00:00
David Green cc532a593e [ARM] Rewrite isLegalT2AddressImmediate
This does two main things, firstly adding some at least basic addressing modes
for i64 types, and secondly treats floats and doubles sensibly when there is no
fpu. The floating point change can help codesize in some cases, especially with
D60294.

Most backends seems to not consider the exact VT in isLegalAddressingMode,
instead switching on type size. That is now what this does when the target does
not have an fpu (as the float data will be loaded using LDR's). i64's currently
use the address range of an LDRD (even though they may be legalised and loaded
with an LDR). This is at least better than marking them all as illegal
addressing modes.

I have not attempted to do much with vectors yet. That will need changing once
MVE is added.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358845 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 09:54:29 +00:00
Craig Topper a83ee71394 [X86] Add the rounding control operand to the printing for some scalar FMA instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358844 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 07:12:56 +00:00
Fangrui Song 9f787399f0 [CachePruning] Simplify comparator
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358843 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 06:17:40 +00:00
Fangrui Song 5f1b9ac4cc [JITLink] Add dependency on MCParser to unit test after rL358818
This is required by -DBUILD_SHARED_LIBS=on builds for createMCAsmParser.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358842 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 06:12:00 +00:00
Craig Topper b098c5b8bb [X86] Don't form masked vfpclass instruction from and+vfpclass unless the fpclass only has a single use.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358841 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 05:18:04 +00:00
Lang Hames 66fbe58442 [JITLink] Remove an overly strict error check in JITLink's eh-frame parser.
The error check required FDEs to refer to the most recent CIE, but the eh-frame
spec allows them to refer to any previously seen CIE. This patch removes the
offending check.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358840 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 04:48:32 +00:00
Lang Hames 56839f1fbe [BinaryFormat] Fix bitfield-ordering of MachO::relocation_info on big-endian.
Hopefully this will fix the JITLink regression test failures on big-endian
testers (e.g.
http://lab.llvm.org:8011/builders/clang-s390x-linux-lnt/builds/12702)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358839 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 03:14:43 +00:00
Lang Hames 43a5825e0f [JITLink] Factor basic common GOT and stub creation code into its own class.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358838 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 03:14:42 +00:00
Petr Hosek deabfea0bc [gn] Move Features.inc to clangd, create a config for it
ClangdLSPServer and clangd unittests now include Features.inc so we
need to append the target_gen_dir that contains it to their
include_dirs. To do so, we use a public config that's applied to
any target that depends on the features one.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358837 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 01:09:15 +00:00
Lang Hames ca962926fe [JITLink] Add dependencies on MCDissassembler and Target to unit test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358836 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-21 00:35:58 +00:00
Nico Weber 594fc0d116 llvm-undname: Improve string literal demangling with embedded \0 chars
- Don't assert when a string looks like a u32 string to the heuristic
  but doesn't have a length that's 0 mod 4.  Instead, classify those
  as u16 with embedded \0 chars. Found by oss-fuzz.
- Print embedded nul bytes as \0 instead of \x00.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358835 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 23:59:06 +00:00
Nico Weber 772d6f05f1 ftime-trace: Trace the name of the currently active pass as well.
Differential Revision: https://reviews.llvm.org/D60782

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358834 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 23:22:45 +00:00
Lang Hames b9674336a4 [JITLink] Add yet more detail to MachO/x86-64 unsupported relocation errors.
Knowing the address/symbolnum field values makes it easier to identify the
unsupported relocation, and provides enough information for the full bit
pattern of the relocation to be reconstructed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358833 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 22:59:43 +00:00
Lang Hames e165e55ce1 [JITLink][ORC] Add JITLink to the list of dependencies for ORC.
The new ObjectLinkingLayer in ORC depends on JITLink.

This should fix the build error at
http://lab.llvm.org:8011/builders/clang-ppc64le-linux-multistage/builds/9621

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358832 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 22:15:57 +00:00
Lang Hames 5ad46871c1 [JITLink] Fix a bad formatv format string.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358831 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 22:06:12 +00:00
Lang Hames e232689821 [JITLink] Disable MachO/x86-64 regression test if the X86 target is not built.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358830 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 21:32:49 +00:00
Amara Emerson 6de3f3796c Revert r358800. Breaks Obsequi from the test suite.
The last attempt fixed gcc and consumer-typeset, but Obsequi seems to fail with
a different issue.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358829 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 21:25:00 +00:00
Lang Hames b2c9d41bb3 [JITLink] Add llvm-jitlink to the list of available tools in lit.
Should fix the 'llvm-jitlink command not found' errors that are appearing on
some builders.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358828 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 20:05:30 +00:00
Lang Hames fbdd3f379c [JITLink] Add BinaryFormat to JITLink's dependencies.
Hopefully this will fix the missing dependence on llvm::identify_magic that is
showing up on some PPC bots. E.g.

http://lab.llvm.org:8011/builders/clang-ppc64le-linux-multistage/builds/9617

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358827 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 19:48:45 +00:00
Lang Hames 9c95520160 [JITLink] Add more detail to MachO/x86-64 "unsupported relocation" errors.
The extra information here will be helpful in diagnosing errors, like the
ones currently occuring on the PPC big-endian bots. :)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358826 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 18:50:13 +00:00
Lang Hames 26be9b17bc [JITLink] Add check to JITLink unit test to bail out for unsupported targets.
This should prevent spurious JITLink unit test failures for builds that do not
support the target(s) required by the tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358825 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 18:30:17 +00:00
Lang Hames 3117779b94 [JITLink] Silence some MSVC implicit cast warnings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358824 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 18:30:16 +00:00
Lang Hames b9e1e5f631 [JITLink] Add llvm-jitlink subdirectory to tools/LLVMBuild.txt
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358823 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 17:58:29 +00:00
Lang Hames 1f07bff61e [JITLink] Use memset instead of bzero.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358822 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 17:49:58 +00:00
Lang Hames ff6a5905bb [JITLink] Silence a narrowing conversion warning.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358821 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 17:37:09 +00:00
Lang Hames 6c66c715b1 [JITLink] Update BuildingAJIT tutorials to account for API changes in r358818.
DynamicLibrarySearchGenerator::GetForCurrentProcess now takes a char (the global
prefix) rather than a DataLayout reference.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358820 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 17:35:28 +00:00
Lang Hames 4396216e12 [JITLink] Fix a missing header and bad prototype.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358819 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 17:29:57 +00:00
Lang Hames 91c3f35814 Initial implementation of JITLink - A replacement for RuntimeDyld.
Summary:

JITLink is a jit-linker that performs the same high-level task as RuntimeDyld:
it parses relocatable object files and makes their contents runnable in a target
process.

JITLink aims to improve on RuntimeDyld in several ways:

(1) A clear design intended to maximize code-sharing while minimizing coupling.

RuntimeDyld has been developed in an ad-hoc fashion for a number of years and
this had led to intermingling of code for multiple architectures (e.g. in
RuntimeDyldELF::processRelocationRef) in a way that makes the code more
difficult to read, reason about, extend. JITLink is designed to isolate
format and architecture specific code, while still sharing generic code.

(2) Support for native code models.

RuntimeDyld required the use of large code models (where calls to external
functions are made indirectly via registers) for many of platforms due to its
restrictive model for stub generation (one "stub" per symbol). JITLink allows
arbitrary mutation of the atom graph, allowing both GOT and PLT atoms to be
added naturally.

(3) Native support for asynchronous linking.

JITLink uses asynchronous calls for symbol resolution and finalization: these
callbacks are passed a continuation function that they must call to complete the
linker's work. This allows for cleaner interoperation with the new concurrent
ORC JIT APIs, while still being easily implementable in synchronous style if
asynchrony is not needed.

To maximise sharing, the design has a hierarchy of common code:

(1) Generic atom-graph data structure and algorithms (e.g. dead stripping and
 |  memory allocation) that are intended to be shared by all architectures.
 |
 + -- (2) Shared per-format code that utilizes (1), e.g. Generic MachO to
       |  atom-graph parsing.
       |
       + -- (3) Architecture specific code that uses (1) and (2). E.g.
                JITLinkerMachO_x86_64, which adds x86-64 specific relocation
                support to (2) to build and patch up the atom graph.

To support asynchronous symbol resolution and finalization, the callbacks for
these operations take continuations as arguments:

  using JITLinkAsyncLookupContinuation =
      std::function<void(Expected<AsyncLookupResult> LR)>;

  using JITLinkAsyncLookupFunction =
      std::function<void(const DenseSet<StringRef> &Symbols,
                         JITLinkAsyncLookupContinuation LookupContinuation)>;

  using FinalizeContinuation = std::function<void(Error)>;

  virtual void finalizeAsync(FinalizeContinuation OnFinalize);

In addition to its headline features, JITLink also makes other improvements:

  - Dead stripping support: symbols that are not used (e.g. redundant ODR
    definitions) are discarded, and take up no memory in the target process
    (In contrast, RuntimeDyld supported pointer equality for weak definitions,
    but the redundant definitions stayed resident in memory).

  - Improved exception handling support. JITLink provides a much more extensive
    eh-frame parser than RuntimeDyld, and is able to correctly fix up many
    eh-frame sections that RuntimeDyld currently (silently) fails on.

  - More extensive validation and error handling throughout.

This initial patch supports linking MachO/x86-64 only. Work on support for
other architectures and formats will happen in-tree.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358818 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 17:10:34 +00:00
Craig Topper a5ce03ca59 [X86] Disable argument copy elision for arguments passed via pointers
Summary:
If you pass two 1024 bit vectors in IR with AVX2 on Windows 64. Both vectors will be split in four 256 bit pieces. The four pieces of the first argument will be passed indirectly using 4 gprs. The second argument will get passed via pointers in memory.

The PartOffsets stored for the second argument are all in terms of its original 1024 bit size. So the PartOffsets for each piece are 32 bytes apart. So if we consider it for copy elision we'll only load an 8 byte pointer, but we'll move the address 32 bytes. The stack object size we create for the first part is probably wrong too.

This issue was encountered by ISPC. I'm working on getting a reduce test case, but wanted to go ahead and get feedback on the fix.

Reviewers: rnk

Reviewed By: rnk

Subscribers: dbabokin, llvm-commits, hiraditya

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358817 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 15:26:44 +00:00
Luqman Aden 6e5b564f91 [CorrelatedValuePropagation] Mark subs that we know not to wrap with nuw/nsw.
Summary:
Teach CorrelatedValuePropagation to also handle sub instructions in addition to add. Relatively simple since makeGuaranteedNoWrapRegion already understood sub instructions. Only subtle change is which range is passed as "Other" to that function, since sub isn't commutative.

Note that CorrelatedValuePropagation::processAddSub is still hidden behind a default-off flag as IndVarSimplify hasn't yet been fixed to strip the added nsw/nuw flags and causes a miscompile. (PR31181)

Reviewers: sanjoy, apilipenko, nikic

Reviewed By: nikic

Subscribers: hiraditya, jfb, jdoerfert, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358816 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 13:14:18 +00:00
Fangrui Song a1443772d6 [ExecutionDomainFix] Optimize a binary search insertion
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358815 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 13:00:50 +00:00
Fangrui Song a6744317c9 [llvm-symbolizer] Fix section index at the end of a section
This is very minor issue. The returned section index is only used by
DWARFDebugLine as an llvm::upper_bound input and the use case shouldn't
cause any behavioral change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358814 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 13:00:09 +00:00
Nikita Popov f925f4a471 [IndVarSimplify] Generate full checks for some LFTR tests; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358813 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 12:05:53 +00:00
Nikita Popov e886e07a6e [IndVarSimplify] Add tests for PR31181; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358812 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 12:05:43 +00:00
Sam McCall de61763a6d [ADT] Avoid warning in bsearch testcase
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358811 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 11:48:11 +00:00
Fangrui Song 8eaf2a6f00 [llvm-objdump] Fix End in disassemblyObject after rL358806
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358809 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 07:48:41 +00:00
Nikita Popov 9fc5e57dd8 [CVP] Add tests for sub nowrap inference; NFC
These are baseline tests for D60036.

Patch by Luqman Aden.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358808 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 07:43:15 +00:00
Nikita Popov 03d4298e86 [X86] Fix stack probing on x32 (PR41477)
Fix for https://bugs.llvm.org/show_bug.cgi?id=41477. On the x32 ABI
with stack probing a dynamic alloca will result in a WIN_ALLOCA_32
with a 32-bit size. The current implementation tries to copy it into
RAX, resulting in a physreg copy error. Fix this by copying to EAX
instead. Also fix incorrect opcodes or registers used in subs.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358807 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 07:25:46 +00:00
Fangrui Song b28f2143df [llvm-objdump] Don't disassemble symbols before SectionAddr
This was caught by UBSAN

tools/llvm-objdump/X86/macho-disassembly-g-dsym.test
tools/llvm-objdump/X86/hex-displacement.test

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358806 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 07:19:24 +00:00
Craig Topper 0428e2f205 [X86] Don't turn (and (shl X, C1), C2) into (shl (and X, (C1 >> C2), C2) if the original AND can represented by MOVZX.
The MOVZX doesn't require an immediate to be encoded at all. Though it does use
a 2 byte opcode so its the same size as a 1 byte immediate. But it has a
separate source and dest register so can help avoid copies.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358805 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 04:38:53 +00:00
Craig Topper 02d9cc1a8e [X86] Turn (and (anyextend (shl X, C1), C2)) into (shl (and (anyextend X), (C1 >> C2), C2) if the AND could match a movzx.
There's one slight regression in here because we don't check that the immediate
already allowed movzx before the shift. I'll fix that next.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358804 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 04:38:49 +00:00
Fangrui Song 10f82c578f [llvm-objdump] Simplify --{start,stop}-address
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358803 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 02:10:48 +00:00
Sam Clegg a1f46fe51c [WebAssembly] Object: Improve error messages on invalid section
Also add a test.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358801 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-20 00:11:46 +00:00