1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00
Commit Graph

3365 Commits

Author SHA1 Message Date
Vladislav Vinogradov
3d786653b8 [ADT][Support] Fix C4146 error from MSVC
Unary minus operator applied to unsigned type, result still unsigned.

Use `~0U` instead of `-1U` and `1 + ~VAL` instead of `-VAL`.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D94417
2021-01-15 14:34:14 -08:00
Duncan P. N. Exon Smith
d845ab560b Revert "Revert "ADT: Fix reference invalidation in SmallVector...""
This reverts commit 33be50daa9ce1074c3b423a4ab27c70c0722113a,
effectively reapplying:

- 260a856c2abcef49c7cb3bdcd999701db3e2af38
- 3043e5a5c33c4c871f4a1dfd621a8839f9a1f0b3
- 49142991a685bd427d7e877c29c77371dfb7634c

... with a fix to skip a call to `SmallVector::isReferenceToStorage()`
when we know the parameter had been taken by value for small, POD-like
`T`. See https://reviews.llvm.org/D93779 for the discussion on the
revert.

At a high-level, these commits fix reference invalidation in
SmallVector's push_back, append, insert (one or N), and resize
operations. For more details, please see the original commit messages.

This commit fixes a bug that crept into
`SmallVectorTemplateCommon::reserveForAndGetAddress()` during the review
process after performance analysis was done. That function is now called
`reserveForParamAndGetAddress()`, clarifying that it only works for
parameter values. It uses that knowledge to bypass
`SmallVector::isReferenceToStorage()` when `TakesParamByValue`. This is
`constexpr` and avoids adding overhead for "small enough", trivially
copyable `T`.

Performance could potentially be tuned further by increasing the
threshold for `TakesParamByValue`, which is currently defined as:
```
bool TakesParamByValue = sizeof(T) <= 2 * sizeof(void *);
```
in the POD-like version of SmallVectorTemplateBase (else, `false`).

Differential Revision: https://reviews.llvm.org/D94800
2021-01-15 14:27:48 -08:00
Nikita Popov
886badc15d Revert "Reapply "ADT: Fix reference invalidation in SmallVector::push_back and single-element insert""
This reverts commit 260a856c2abcef49c7cb3bdcd999701db3e2af38.
This reverts commit 3043e5a5c33c4c871f4a1dfd621a8839f9a1f0b3.
This reverts commit 49142991a685bd427d7e877c29c77371dfb7634c.

This change had a larger than anticipated compile-time impact,
possibly because the small value optimization is not working as
intended. See D93779.
2021-01-15 09:28:42 +01:00
Alexandre Ganea
358e11b98e Revert "Fix llvm::Optional build breaks in MSVC using std::is_trivially_copyable"
This reverts commit 854f0984f0b7ab9a9a541a4bcda7ea173e4113d3.

This breaks compilation with clang-cl on Windows, while in a MSVC 16.8 cmd.exe.
This also breaks PPC: http://lab.llvm.org:8011/#/builders/93/builds/1435
And: https://reviews.llvm.org/D93510#2497737
2021-01-14 08:35:38 -05:00
Duncan P. N. Exon Smith
03b8526e35 ADT: Reduce code duplication in SmallVector by calling reserve and clear, NFC 2021-01-13 21:10:31 -08:00
Duncan P. N. Exon Smith
a94b40b819 ADT: Reduce code duplication in SmallVector by reusing reserve, NFC 2021-01-13 20:52:57 -08:00
Duncan P. N. Exon Smith
1f680ae2d9 ADT: Reduce code duplication in SmallVector::resize by using pop_back_n, NFC 2021-01-13 20:50:00 -08:00
Duncan P. N. Exon Smith
48a93fb6cc ADT: Fix reference invalidation in SmallVector::resize
For small enough, trivially copyable `T`, take the parameter by-value in
`SmallVector::resize`.  Otherwise, when growing, update the arugment
appropriately.

Differential Revision: https://reviews.llvm.org/D93781
2021-01-13 20:48:08 -08:00
Duncan P. N. Exon Smith
f269bb04a5 ADT: Fix reference invalidation in N-element SmallVector::append and insert
For small enough, trivially copyable `T`, take the parameter by-value in
`SmallVector::append` and `SmallVector::insert`.  Otherwise, when
growing, update the arugment appropriately.

Differential Revision: https://reviews.llvm.org/D93780
2021-01-13 20:00:44 -08:00
Duncan P. N. Exon Smith
9e6be04b5b Reapply "ADT: Fix reference invalidation in SmallVector::push_back and single-element insert"
This reverts commit 56d1ffb927d03958a7a31442596df749264a7792, reapplying
9abac60309006db00eca0af406c2e16bef26807c, removing insert_one_maybe_copy
and using a helper called forward_value_param instead. This avoids use
of `std::is_same` (or any SFINAE), so I'm hoping it's more portable and
MSVC will be happier.

Original commit message follows:

For small enough, trivially copyable `T`, take the argument by value in
`SmallVector::push_back` and copy it when forwarding to
`SmallVector::insert_one_impl`. Otherwise, when growing, update the
argument appropriately.

Differential Revision: https://reviews.llvm.org/D93779
2021-01-13 19:45:39 -08:00
Kazu Hirata
d84950767c [llvm] Use *Set::contains (NFC) 2021-01-13 19:14:41 -08:00
Duncan P. N. Exon Smith
a3e1d2d498 Revert "ADT: Fix reference invalidation in SmallVector::push_back and single-element insert"
This reverts commit 9abac60309006db00eca0af406c2e16bef26807c since there
are some bot errors on Windows:
http://lab.llvm.org:8011/#/builders/127/builds/4489

```
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/IntervalMap.cpp.obj
C:\PROGRA~2\MIB055~1\2017\PROFES~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\cl.exe  /nologo /TP -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib\Support -IC:\b\slave\sanitizer-windows\llvm-project\llvm\lib\Support -Iinclude -IC:\b\slave\sanitizer-windows\llvm-project\llvm\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:__cplusplus /Zi /Zc:strictStrings /Oi /Zc:rvalueCast /bigobj /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd4324 -w14062 -we4238 /Gw /MD /O2 /Ob2 -UNDEBUG -std:c++14  /EHs-c- /GR- /showIncludes /Folib\Support\CMakeFiles\LLVMSupport.dir\IntervalMap.cpp.obj /Fdlib\Support\CMakeFiles\LLVMSupport.dir\LLVMSupport.pdb /FS -c C:\b\slave\sanitizer-windows\llvm-project\llvm\lib\Support\IntervalMap.cpp
C:\b\slave\sanitizer-windows\llvm-project\llvm\include\llvm/ADT/SmallVector.h(746): error C2672: 'llvm::SmallVectorImpl<T>::insert_one_maybe_copy': no matching overloaded function found
        with
        [
            T=llvm::IntervalMapImpl::Path::Entry
        ]
C:\b\slave\sanitizer-windows\llvm-project\llvm\include\llvm/ADT/SmallVector.h(745): note: while compiling class template member function 'llvm::IntervalMapImpl::Path::Entry *llvm::SmallVectorImpl<T>::insert(llvm::IntervalMapImpl::Path::Entry *,T &&)'
        with
        [
            T=llvm::IntervalMapImpl::Path::Entry
        ]
C:\b\slave\sanitizer-windows\llvm-project\llvm\lib\Support\IntervalMap.cpp(22): note: see reference to function template instantiation 'llvm::IntervalMapImpl::Path::Entry *llvm::SmallVectorImpl<T>::insert(llvm::IntervalMapImpl::Path::Entry *,T &&)' being compiled
        with
        [
            T=llvm::IntervalMapImpl::Path::Entry
        ]
C:\b\slave\sanitizer-windows\llvm-project\llvm\include\llvm/ADT/SmallVector.h(1136): note: see reference to class template instantiation 'llvm::SmallVectorImpl<T>' being compiled
        with
        [
            T=llvm::IntervalMapImpl::Path::Entry
        ]
C:\b\slave\sanitizer-windows\llvm-project\llvm\include\llvm/ADT/IntervalMap.h(790): note: see reference to class template instantiation 'llvm::SmallVector<llvm::IntervalMapImpl::Path::Entry,4>' being compiled
C:\b\slave\sanitizer-windows\llvm-project\llvm\include\llvm/ADT/SmallVector.h(746): error C2783: 'llvm::IntervalMapImpl::Path::Entry *llvm::SmallVectorImpl<T>::insert_one_maybe_copy(llvm::IntervalMapImpl::Path::Entry *,ArgType &&)': could not deduce template argument for '__formal'
        with
        [
            T=llvm::IntervalMapImpl::Path::Entry
        ]
C:\b\slave\sanitizer-windows\llvm-project\llvm\include\llvm/ADT/SmallVector.h(727): note: see declaration of 'llvm::SmallVectorImpl<T>::insert_one_maybe_copy'
        with
        [
            T=llvm::IntervalMapImpl::Path::Entry
        ]
```
2021-01-13 19:04:20 -08:00
Duncan P. N. Exon Smith
c96fe02b9c ADT: Fix reference invalidation in SmallVector::push_back and single-element insert
For small enough, trivially copyable `T`, take the argument by value in
`SmallVector::push_back` and copy it when forwarding to
`SmallVector::insert_one_impl`. Otherwise, when growing, update the
argument appropriately.

Differential Revision: https://reviews.llvm.org/D93779
2021-01-13 18:58:24 -08:00
James Player
6397bc6461 Fix llvm::Optional build breaks in MSVC using std::is_trivially_copyable
Current code breaks this version of MSVC due to a mismatch between `std::is_trivially_copyable` and `llvm::is_trivially_copyable` for `std::pair` instantiations.  Hence I was attempting to use `std::is_trivially_copyable` to set `llvm::is_trivially_copyable<T>::value`.

I spent some time root causing an `llvm::Optional` build error on MSVC 16.8.3 related to the change described above:

```
62>C:\src\ocg_llvm\llvm-project\llvm\include\llvm/ADT/BreadthFirstIterator.h(96,12): error C2280: 'llvm::Optional<std::pair<std::pair<unsigned int,llvm::Graph<4>::NodeSubset> *,llvm::Optional<llvm::Graph<4>::ChildIterator>>> &llvm::Optional<std::pair<std::pair<unsigned int,llvm::Graph<4>::NodeSubset> *,llvm::Optional<llvm::Graph<4>::ChildIterator>>>::operator =(const llvm::Optional<std::pair<std::pair<unsigned int,llvm::Graph<4>::NodeSubset> *,llvm::Optional<llvm::Graph<4>::ChildIterator>>> &)': attempting to reference a deleted function (compiling source file C:\src\ocg_llvm\llvm-project\llvm\unittests\ADT\BreadthFirstIteratorTest.cpp)
...
```
The "trivial" specialization of `optional_detail::OptionalStorage` assumes that the value type is trivially copy constructible and trivially copy assignable. The specialization is invoked based on a check of `is_trivially_copyable` alone, which does not imply both `is_trivially_copy_assignable` and `is_trivially_copy_constructible` are true.

[[ https://en.cppreference.com/w/cpp/named_req/TriviallyCopyable | According to the spec ]], a deleted assignment operator does not make `is_trivially_copyable` false. So I think all these properties need to be checked explicitly in order to specialize `OptionalStorage` to the "trivial" version:
```
/// Storage for any type.
template <typename T, bool = std::is_trivially_copy_constructible<T>::value
                          && std::is_trivially_copy_assignable<T>::value>
class OptionalStorage {
```
Above fixed my build break in MSVC, but I think we need to explicitly check `is_trivially_copy_constructible` too since it might be possible the copy constructor is deleted.  Also would be ideal to move over to `std::is_trivially_copyable` instead of the `llvm` namespace verson.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D93510
2021-01-13 15:23:48 -08:00
Nathan James
9a01228ffe Fix build errors after ceb9379a9
For some reason some builds dont like the arrow operator access. using the deref then access should fix the issue.

/home/buildbots/ppc64le-flang-mlir-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include/llvm/ADT/iterator.h:171:34: error: taking the address of a temporary object of type 'llvm::StringRef' [-Waddress-of-temporary]
  PointerT operator->() { return &static_cast<DerivedT *>(this)->operator*(); }
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/buildbots/ppc64le-flang-mlir-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include/llvm/ADT/StringExtras.h:387:13: note: in instantiation of member function 'llvm::iterator_facade_base<llvm::mapped_iterator<mlir::tblgen::TypeParameter *, (lambda at /home/buildbots/ppc64le-flang-mlir-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/mlir/tools/mlir-tblgen/TypeDefGen.cpp:414:19), llvm::StringRef>, std::random_access_iterator_tag, llvm::StringRef, long, llvm::StringRef *, llvm::StringRef &>::operator->' requested here
    Len += I->size();
2021-01-13 12:19:53 +00:00
Nathan James
1a9d376e87 [ADT] Fix join_impl using the wrong size when calculating total length
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D83305
2021-01-13 11:36:49 +00:00
Duncan P. N. Exon Smith
0557f33853 ADT: Fix pointer comparison UB in SmallVector
The standard requires comparisons of pointers to unrelated storage to
use `std::less`. Split out some helpers that do that and update all the
code that was comparing using `<` and friends (mostly assertions).

Differential Revision: https://reviews.llvm.org/D93777
2021-01-11 15:31:04 -08:00
Nathan James
5ed102c708 [ADT] Add makeIntrusiveRefCnt helper function
Works like std::make_unique but for IntrusiveRefCntPtr objects.
See https://lists.llvm.org/pipermail/llvm-dev/2021-January/147729.html

Reviewed By: dblaikie, MaskRay

Differential Revision: https://reviews.llvm.org/D94440
2021-01-11 20:12:53 +00:00
Kazu Hirata
6a844d8634 [StringExtras] Add a helper class for comma-separated lists
This patch introduces a helper class SubsequentDelim to simplify loops
that generate a comma-separated lists.

For example, consider the following loop, taken from
llvm/lib/CodeGen/MachineBasicBlock.cpp:

    for (auto I = pred_begin(), E = pred_end(); I != E; ++I) {
      if (I != pred_begin())
        OS << ", ";
      OS << printMBBReference(**I);
    }

The new class allows us to rewrite the loop as:

    SubsequentDelim SD;
    for (auto I = pred_begin(), E = pred_end(); I != E; ++I)
      OS << SD << printMBBReference(**I);

where SD evaluates to the empty string for the first time and ", " for
subsequent iterations.

Unlike interleaveComma, defined in llvm/include/llvm/ADT/STLExtras.h,
SubsequentDelim can accommodate a wider variety of loops, including:

- those that conditionally skip certain items,
- those that need iterators to call getSuccProbability(I), and
- those that iterate over integer ranges.

As an example, this patch cleans up MachineBasicBlock::print.

Differential Revision: https://reviews.llvm.org/D94377
2021-01-10 14:32:02 -08:00
Florian Hahn
867bd6d8b8 [STLExtras] Use return type from operator* of the wrapped iter.
Currently make_early_inc_range cannot be used with iterators with
operator* implementations that do not return a reference.

Most notably in the LLVM codebase, this means the User iterator ranges
cannot be used with make_early_inc_range, which slightly simplifies
iterating over ranges while elements are removed.

Instead of directly using BaseT::reference as return type of operator*,
this patch uses decltype to get the actual return type of the operator*
implementation in WrappedIteratorT.

This patch also updates a few places to use make use of
make_early_inc_range.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D93992
2021-01-10 14:41:13 +00:00
Kazu Hirata
3109d596ee [llvm] Use llvm::append_range (NFC) 2021-01-06 18:27:33 -08:00
Brandon Bergren
3adc8af0ca [PowerPC] Add the LLVM triple for powerpcle [1/5]
Add a triple for powerpcle-*-*.

This is a little-endian encoding of the 32-bit PowerPC ABI, useful in certain niche situations:

1) A loader such as the FreeBSD loader which will be loading a little endian kernel. This is required for PowerPC64LE to load properly in pseries VMs.
Such a loader is implemented as a freestanding ELF32 LSB binary.

2) Userspace emulation of a 32-bit LE architecture such as x86 on 64-bit hosts such as PowerPC64LE with tools like box86 requires having a 32-bit LE toolchain and library set, as they operate by translating only the main binary and switching to native code when making library calls.

3) The Void Linux for PowerPC project is experimenting with running an entire powerpcle userland.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D93918
2021-01-02 12:17:22 -06:00
Nathan James
b6e73d2ad1 [ADT] Add resize_for_overwrite method to SmallVector.
Analagous to the std::make_(unqiue|shared)_for_overwrite added in c++20.
If T is POD, and the container gets larger, any new values added wont be initialized.
This is useful when using SmallVector as a buffer where its planned to overwrite any potential new values added.
If T is not POD, `new (Storage) T` functions identically to `new (Storage) T()` so this will function identically to `resize(size_type)`.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93532
2020-12-22 17:18:59 +00:00
Lucas Prates
c7222c149c [ARM] Adding v8.7-A command-line support for the ARM target
This extends the command-line support for the 'armv8.7-a' architecture
name to the ARM target.

Based on a patch written by Momchil Velikov.

Reviewed By: ostannard

Differential Revision: https://reviews.llvm.org/D93231
2020-12-17 13:48:54 +00:00
Barry Revzin
2fc9f32ca3 Make LLVM build in C++20 mode
Part of the <=> changes in C++20 make certain patterns of writing equality
operators ambiguous with themselves (sorry!).
This patch goes through and adjusts all the comparison operators such that
they should work in both C++17 and C++20 modes. It also makes two other small
C++20-specific changes (adding a constructor to a type that cases to be an
aggregate, and adding casts from u8 literals which no longer have type
const char*).

There were four categories of errors that this review fixes.
Here are canonical examples of them, ordered from most to least common:

// 1) Missing const
namespace missing_const {
    struct A {
    #ifndef FIXED
        bool operator==(A const&);
    #else
        bool operator==(A const&) const;
    #endif
    };

    bool a = A{} == A{}; // error
}

// 2) Type mismatch on CRTP
namespace crtp_mismatch {
    template <typename Derived>
    struct Base {
    #ifndef FIXED
        bool operator==(Derived const&) const;
    #else
        // in one case changed to taking Base const&
        friend bool operator==(Derived const&, Derived const&);
    #endif
    };

    struct D : Base<D> { };

    bool b = D{} == D{}; // error
}

// 3) iterator/const_iterator with only mixed comparison
namespace iter_const_iter {
    template <bool Const>
    struct iterator {
        using const_iterator = iterator<true>;

        iterator();

        template <bool B, std::enable_if_t<(Const && !B), int> = 0>
        iterator(iterator<B> const&);

    #ifndef FIXED
        bool operator==(const_iterator const&) const;
    #else
        friend bool operator==(iterator const&, iterator const&);
    #endif
    };

    bool c = iterator<false>{} == iterator<false>{} // error
          || iterator<false>{} == iterator<true>{}
          || iterator<true>{} == iterator<false>{}
          || iterator<true>{} == iterator<true>{};
}

// 4) Same-type comparison but only have mixed-type operator
namespace ambiguous_choice {
    enum Color { Red };

    struct C {
        C();
        C(Color);
        operator Color() const;
        bool operator==(Color) const;
        friend bool operator==(C, C);
    };

    bool c = C{} == C{}; // error
    bool d = C{} == Red;
}

Differential revision: https://reviews.llvm.org/D78938
2020-12-17 10:44:10 +00:00
River Riddle
28caccdfb8 [mlir][Inliner] Refactor the inliner to use nested pass pipelines instead of just canonicalization
Now that passes have support for running nested pipelines, the inliner can now allow for users to provide proper nested pipelines to use for optimization during inlining. This revision also changes the behavior of optimization during inlining to optimize before attempting to inline, which should lead to a more accurate cost model and prevents the need for users to schedule additional duplicate cleanup passes before/after the inliner that would already be run during inlining.

Differential Revision: https://reviews.llvm.org/D91211
2020-12-14 18:09:47 -08:00
Reid Kleckner
b945e1014a Revert "ADT: Migrate users of AlignedCharArrayUnion to std::aligned_union_t, NFC"
We determined that the MSVC implementation of std::aligned* isn't suited
to our needs. It doesn't support 16 byte alignment or higher, and it
doesn't really guarantee 8 byte alignment. See
https://github.com/microsoft/STL/issues/1533

Also reverts "ADT: Change AlignedCharArrayUnion to an alias of std::aligned_union_t, NFC"

Also reverts "ADT: Remove AlignedCharArrayUnion, NFC" to bring back
AlignedCharArrayUnion.

This reverts commit 4d8bf870a82765eb0d4fe53c82f796b957c05954.

This reverts commit d10f9863a5ac1cb681af07719650c44b48f289ce.

This reverts commit 4b5dc150b9862271720b3d56a3e723a55dd81838.
2020-12-14 17:04:06 -08:00
Scott Linder
d0f7c7f0f0 [SmallVector][NFC] Link to ProgrammersManual from SmallVector docs
Add a "see also" link from the condensed doxygen description of
`SmallVector` to the more complete description in the ProgrammersManual.
2020-12-11 19:34:10 +00:00
Scott Linder
789653fed0 [SmallVector] Copy new docs into Doxygen comment
Copy the `ProgrammersManual.rst` changes from D92522 to the Doxygen
comment for `SmallVector`, to hopefully encourage new uses migrating to
the no-explicit-`N` form.

Differential Revision: https://reviews.llvm.org/D93069
2020-12-10 22:20:37 +00:00
Duncan P. N. Exon Smith
7308ff63ab ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC
Allow a `std::unique_ptr` to be moved into the an `IntrusiveRefCntPtr`,
and remove a couple of now-unnecessary `release()` calls.

Differential Revision: https://reviews.llvm.org/D92888
2020-12-08 17:33:19 -08:00
Duncan P. N. Exon Smith
0282c36f00 ADT: Add hash_value overload for Optional
Add a `hash_value` for Optional so that other data structures with
optional fields can easily hash them. I have a use for this in an
upcoming patch.

Differential Revision: https://reviews.llvm.org/D92676
2020-12-08 15:25:03 -08:00
Nuno Lopes
558b019bb5 DenseMap: fix build with clang in C++20 mode
clang was complaing about this code:
llvm/include/llvm/IR/PassManager.h:715:17: error: ISO C++20 considers use of overloaded operator '!=' to be ambiguous despite there being a unique best viable function with non-reversed arguments [-Werror,-Wambiguous-reversed-operator]
      if (IMapI != IsResultInvalidated.end())
          ~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~
llvm/include/llvm/ADT/DenseMap.h:1253:8: note: candidate function with non-reversed arguments
  bool operator!=(const ConstIterator &RHS) const {
       ^
llvm/include/llvm/ADT/DenseMap.h:1246:8: note: ambiguous candidate function with reversed arguments
  bool operator==(const ConstIterator &RHS) const {
       ^

The warning is triggered when the DenseMapIterator (lhs) is not const and so
the == operator is applied to different types on lhs/rhs.
Using a template allows the function to be available for both const/non-const
iterator types and gets rid of the warning
2020-12-08 18:39:31 +00:00
Nathan James
28b9fcb9d6 [llvm][NFC] Made RefCountBase constructors protected
Matches ThreadSafeRefCountBase and forces the class to be inherited.
2020-12-07 20:23:11 +00:00
Nathan James
d6790a9df8 [llvm] Add asserts in (ThreadSafe)?RefCountedBase destructors
Added a trivial destructor in release mode and in debug mode a destructor that asserts RefCount is indeed zero.
This ensure people aren't manually (maybe accidentally) destroying these objects like in this contrived example.
```lang=c++
{
  std::unique_ptr<SomethingRefCounted> Object;
  holdIntrusiveOwnership(Object.get());
  // Object Destructor called here will assert.
}
```

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D92480
2020-12-07 20:20:08 +00:00
Duncan P. N. Exon Smith
ea15c01596 ADT: Migrate users of AlignedCharArrayUnion to std::aligned_union_t, NFC
Prepare to delete `AlignedCharArrayUnion` by migrating its users over to
`std::aligned_union_t`.

I will delete `AlignedCharArrayUnion` and its tests in a follow-up
commit so that it's easier to revert in isolation in case some
downstream wants to keep using it.

Differential Revision: https://reviews.llvm.org/D92516
2020-12-04 12:34:49 -08:00
Duncan P. N. Exon Smith
f1e94c82c9 ADT: Stop peeking inside AlignedCharArrayUnion, NFC
Update all the users of `AlignedCharArrayUnion` to stop peeking inside
(to look at `buffer`) so that a follow-up patch can replace it with an
alias to `std::aligned_union_t`.

This was reviewed as part of https://reviews.llvm.org/D92512, but I'm
splitting this bit out to commit first to reduce churn in case the
change to `AlignedCharArrayUnion` needs to be reverted for some
unexpected reason.
2020-12-04 11:07:42 -08:00
David Blaikie
4518389307 IntrusiveRefCntPtr: Ensure RefCount is initialized during ThreadSafeRefCountedBase copy construction
Post commit feedback on 2e83ccc2ee33 from Nathan James!
2020-12-03 18:43:01 -08:00
David Blaikie
88c4002891 ADT: Support copying of IntrusiveRefCntPtr objects
This was partially supported but untested for RefCountedBase (the
implicit copy assignment would've been problematic - so delete that) and
unsupported (would not have compiled, because std::atomic is
non-copyable) for ThreadSafeRefCountedBase (implement similar support
to RefCountedBase)

Fix the test that had a copy ctor for the derived object but called
RefCountBase's default ctor from that copy ctor - which meant it wasn't
actually testing RefCountBase's copy semantics.
2020-12-03 17:42:32 -08:00
Sean Silva
bc224c8fad [SmallVector] Allow SmallVector<T>
This patch adds a capability to SmallVector to decide a number of
inlined elements automatically. The policy is:

- A minimum of 1 inlined elements, with more as long as
sizeof(SmallVector<T>) <= 64.
- If sizeof(T) is "too big", then trigger a static_assert: this dodges
the more pathological cases

This is expected to systematically improve SmallVector use in the
LLVM codebase, which has historically been plagued by semi-arbitrary /
cargo culted N parameters, often leading to bad outcomes due to
excessive sizeof(SmallVector<T, N>). This default also makes
programming more convenient by avoiding edit/rebuild cycles due to
forgetting to type the N parameter.

Differential Revision: https://reviews.llvm.org/D92522
2020-12-03 17:21:44 -08:00
Mehdi Amini
91270b1460 Revert "Switch to std::is_trivially_move_constructible and std::is_trivially_copy_constructible"
This reverts commit c8d406c93c5bb01599990201f78d8428dd29d289.

Builds are broken with some versions of GCC.
2020-12-03 19:58:06 +00:00
Fangrui Song
f6492fea1c Switch to std::is_trivially_move_constructible and std::is_trivially_copy_constructible
Differential Revision: https://reviews.llvm.org/D92543
2020-12-03 09:15:40 -08:00
Ahmed Bougacha
fe6a3c2668 [Triple][MachO] Define "arm64e", an AArch64 subarch for Pointer Auth.
This also teaches MachO writers/readers about the MachO cpu subtype,
beyond the minimal subtype reader support present at the moment.

This also defines a preprocessor macro to allow users to distinguish
__arm64__ from __arm64e__.

arm64e defaults to an "apple-a12" CPU, which supports v8.3a, allowing
pointer-authentication codegen.
It also currently defaults to ios14 and macos11.

Differential Revision: https://reviews.llvm.org/D87095
2020-12-03 07:53:59 -08:00
Tim Northover
a8373fee73 arm64: count Triple::aarch64_32 as an aarch64 target and enable leaf frame pointers 2020-12-03 11:09:44 +00:00
Fangrui Song
649f05aa24 Switch from llvm::is_trivially_copyable to std::is_trivially_copyable
GCC<5 did not support std::is_trivially_copyable. Now LLVM builds require 5.1
we can migrate to std::is_trivially_copyable.

The Optional.h change made MSVC choke
(https://buildkite.com/llvm-project/premerge-checks/builds/18587#cd1bb616-ffdc-4581-9795-b42c284196de)
so I leave it out for now.

Differential Revision: https://reviews.llvm.org/D92514
2020-12-02 22:02:48 -08:00
Duncan P. N. Exon Smith
402de92d98 ADT: Remove redundant alignas from IntervalMap, NFC
`AlignedArrayCharUnion` is now using `alignas`, which is properly
supported now by all the host toolchains we support. As a result, the
extra `alignas` on `IntervalMap` isn't needed anymore.

This is effectively a revert of 379daa29744cd96b0a87ed0d4a010fa4bc47ce73.

Differential Revision: https://reviews.llvm.org/D92509
2020-12-02 14:33:20 -08:00
Reid Kleckner
7c87aeebfe Revert "Use std::is_trivially_copyable", breaks MSVC build
Revert "Delete llvm::is_trivially_copyable and CMake variable HAVE_STD_IS_TRIVIALLY_COPYABLE"

This reverts commit 4d4bd40b578d77b8c5bc349ded405fb58c333c78.

This reverts commit 557b00e0afb2dc1776f50948094ca8cc62d97be4.
2020-12-02 14:30:46 -08:00
Fangrui Song
3effbaa68f Delete llvm::is_trivially_copyable and CMake variable HAVE_STD_IS_TRIVIALLY_COPYABLE
GCC<5 did not support std::is_trivially_copyable. Now LLVM builds
require 5.1 we can delete llvm::is_trivially_copyable after the users
have been migrated to std::is_trivially_copyable.
2020-12-02 09:58:08 -08:00
Fangrui Song
dffdc25f75 Use std::is_trivially_copyable
GCC<5 did not support std::is_trivially_copyable. Now LLVM builds require 5.1
we can migrate to std::is_trivially_copyable.
2020-12-02 09:58:07 -08:00
Arthur O'Dwyer
c383fe5b05 s/instantate/instantiate/ throughout. NFCI.
The static_assert in "libcxx/include/memory" was the main offender here,
but then I figured I might as well `git grep -i instantat` and fix all
the instances I found. One was in user-facing HTML documentation;
the rest were in comments or tests.
2020-12-01 22:13:40 -05:00
Jameson Nash
1c1949a4cb fix some Wundef warnings in public headers
Differential Revision: https://reviews.llvm.org/D91094
2020-11-23 20:17:46 -05:00
Jay Foad
1ac4a188a1 Fix speling in comments. NFC. 2020-11-23 14:43:24 +00:00
Kerry McLaughlin
1a23665577 [APInt] Add the truncOrSelf resizing operator to APInt
Truncates the APInt if the bit width is greater than the width specified,
otherwise do nothing

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D91445
2020-11-23 11:27:30 +00:00
Duncan P. N. Exon Smith
7668c9150a ADT: Split out isSafeToReferenceAfterResize helper to use early returns, NFC
The assertion logic in SmallVector::assertSafeToReferenceAfterResize is
hard to follow; split out SmallVector::isSafeToReferenceAfterResize and
add early returns and comments. No functionality change here.
2020-11-19 17:55:04 -08:00
Duncan P. N. Exon Smith
82e253383a ADT: Use early returns in SmallVector::resize, NFC
Just a simple cleanup, no functionality change here.
2020-11-19 17:28:57 -08:00
Duncan P. N. Exon Smith
8605039d2b ADT: Weaken SmallVector::resize assertion from 5abf76fbe37380874a88cc9aa02164800e4e10f3
There's no need to check for reference invalidation when
`SmallVector::resize` is shrinking; the parameter isn't accessed.

Differential Revision: https://reviews.llvm.org/D91832
2020-11-19 17:25:36 -08:00
Duncan P. N. Exon Smith
b6b630c8ab ADT: Add assertions to SmallVector::insert, etc., for reference invalidation
2c196bbc6bd897b3dcc1d87a3baac28e1e88df41 asserted that
`SmallVector::push_back` doesn't invalidate the parameter when it needs
to grow. Do the same for `resize`, `append`, `assign`, `insert`, and
`emplace_back`.

Differential Revision: https://reviews.llvm.org/D91744
2020-11-18 17:36:28 -08:00
Moritz Sichert
0fadcfd431 Added GDB pretty printer for StringMap
Reviewed By: csigg, dblaikie

Differential Revision: https://reviews.llvm.org/D91183
2020-11-18 16:33:34 -08:00
Duncan P. N. Exon Smith
d59bc177d6 ADT: Share an implementation for single-element insert in SmallVector, NFC
Factor out `SmallVectorImple::insert_one_impl`, a common implementation
for `insert(iterator, T&&)` and `insert(iterator, T const&)`. This is
just a clean up and has no functionality change.

Differential Revision: https://reviews.llvm.org/D91674
2020-11-17 21:20:51 -08:00
Mehdi Amini
738b5c2c48 Add an assertion in SmallVector::push_back()
This assertion ensures the input value isn't part of the vector when
growing is required. In such cases the vector will grow and the input
value is invalidated before being read from.

This found 14 failed Tests.

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D84293
2020-11-14 00:55:34 +00:00
Nathan James
0430707986 [clangd] Handle duplicate enum constants in PopulateSwitch tweak
If an enum has different names for the same constant, make sure only the first one declared gets added into the switch. Failing to do so results in a compiler error as 2 case labels can't represent the same value.

```
lang=c
enum Numbers{
One,
Un = One,
Two,
Deux = Two,
Three,
Trois = Three
};

// Old behaviour
switch (<Number>) {
  case One:
  case Un:
  case Two:
  case Duex:
  case Three:
  case Trois: break;
}

// New behaviour
switch (<Number>) {
  case One:
  case Two:
  case Three: break;
}
```

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90555
2020-11-09 12:14:53 +00:00
Sean Silva
7b66e6757c [STLExtras] Add append_range helper.
This is convenient in a lot of cases, such as when the thing you want
to append is `someReallyLongFunctionName()` that you'd rather not
write twice or assign to a variable for the paired begin/end calls.

Differential Revision: https://reviews.llvm.org/D90894
2020-11-05 16:20:02 -08:00
Nathan James
b80fbad013 [ADT] Add SmallVector::pop_back_n
Adds a method called pop_back_n to SmallVector.
This is more readable and less error prone than the alternatives of using
```lang=c++
Vector.resize(Vector.size() - N);
Vector.erase(Vector.end() - N, Vector.end());
for (unsigned I = 0;I<N;++I) Vector.pop_back();
```

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D90576
2020-11-03 14:57:10 +00:00
Ben Dunbobbin
1b5bdf4e65 [PS4] Support dllimport/export attributes
For PS4 development we support dllimport/export annotations in
source code. This patch enables the dllimport/export attributes
on PS4 by adding a new function to query the triple for whether
dllimport/export are used and using that function to decide
whether these attributes are supported. This replaces the current
method of checking if the target is Windows.

This means we can drop the use of "TargetArch" in the .td file
(which is an improvement as dllimport/export support isn't really
a function of the architecture).

I have included a simple codgen test to show that the attributes
are accepted and have an effect on codegen for PS4. I have also
enabled the DLLExportStaticLocal and DLLImportStaticLocal
attributes, which we support downstream. However, I am unable to
write a test for these attributes until other patches for PS4
dllimport/export handling land upstream. Whilst writing this
patch I noticed that, as these attributes are internal, they do
not need to be target specific (when these attributes are added
internally in Clang the target specific checks have already been
run); however, I think leaving them target specific is fine
because it isn't harmful and they "really are" target specific
even if that has no functional impact.

Differential Revision: https://reviews.llvm.org/D90442
2020-11-02 14:25:34 +00:00
Nathan James
fe6ca64874 [ADT][NFC] Silence some misc-unconventional-assign-operator warnings 2020-10-30 10:57:25 +00:00
Nathan James
21052ba8d6 [ADT] Add methods to SmallString for efficient concatenation
A common pattern when using SmallString is to repeatedly call append to build a larger string.
The issue here is the optimizer can't see through this and often has to check there is enough space in the storage for each string you try to append.
This results in lots of conditional branches and potentially multiple calls to grow needing to be emitted if the buffer wasn't large enough.
By taking an initializer_list of StringRefs, SmallString can preallocate the storage it needs for all of the StringRefs which only need to grow one time at most, then use a fast path of copying all the strings into its storage knowing there is guaranteed to be enough capacity.
By using StringRefs, this also means you can append different string like types in one go as they will all be implicitly converted to a StringRef.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D90386
2020-10-30 10:07:40 +00:00
Adam Balogh
46939502b8 [ADT] Fix for ImmutableMapRef
The `Root` member of `ImmutableMapRef` was changed recently from a plain
pointer to `IntrusiveRefCntPtr`. However, the `Profile` member function
was not adjusted. This results in comilation error whenever the
`Profile` method is used on an `ImmutableMapRef`. This patch fixes this
issue and also adds unit tests for `ImmutableMapRef`.

Differential Revision: https://reviews.llvm.org/D89486
2020-10-29 13:19:51 +01:00
River Riddle
d248b6cfb7 [llvm][StringExtras] Use a lookup table for hexDigitValue
This method is at the core of the conversion from hex to binary, and using a lookup table great improves the compile time of hex conversions.

Context: In MLIR we use hex strings to represent very large constants in the textual format of the IR. These changes lead to a large decrease in compile time when parsing these constants (>1 second -> 350 miliseconds).

Differential Revision: https://reviews.llvm.org/D90320
2020-10-28 16:58:06 -07:00
River Riddle
9da2a4f5d7 [llvm][StringExtras] Add a fail-able version of fromHex
This revision adds a fail-able/checked version of `fromHex` that fails when the input string contains a non-hex character. This removes the need for users to have a separate check for if the string contains all hex digits. This becomes very costly for large hex strings given that checking if a string contains only hex digits is effectively the same as just converting it in the first place.

Context: In MLIR we use hex strings to represent very large constants in the textual format of the IR. These changes lead to a large decrease in compile time when parsing these constants (2 seconds -> 1 second).

Differential Revision: https://reviews.llvm.org/D90265
2020-10-28 16:58:06 -07:00
Mitch Phillips
12ea6caf44 Revert "[ADT] Fix for ImmutableMapRef"
This reverts commit a6336eab0c507b665dda63fa9db1292a2cdee409.

This commit broke check-llvm under ASan:

See http://lab.llvm.org:8011/#/builders/5/builds/446 for more details.
2020-10-27 20:50:46 -07:00
Alex Lorenz
ce5134f423 [driver][arm64] Set target CPU to A12 for compiler invocations that
target Apple Silicon macOS machines

Differential Revision: https://reviews.llvm.org/D82699
2020-10-21 23:35:27 -07:00
Adam Balogh
a4200b92ce [ADT] Fix for ImmutableMapRef
The `Root` member of `ImmutableMapRef` was changed recently from a plain
pointer to `IntrusiveRefCntPtr`. However, the `Profile` member function
was not adjusted. This results in comilation error whenever the
`Profile` method is used on an `ImmutableMapRef`. This patch fixes this
issue and also adds unit tests for `ImmutableMapRef`.

Differential Revision: https://reviews.llvm.org/D89486
2020-10-21 12:13:20 +02:00
Sam McCall
75a854e0a6 [ADT] Avoid use of result_of_t in function_ref
It has bugs on some old libc++ versions and we don't need the power.
See https://reviews.llvm.org/D88977
2020-10-19 14:59:45 +02:00
Reid Kleckner
4b5ed96964 [ADT] Use alignas + sizeof for inline storage, NFC
AlignedCharArrayUnion is really only needed to handle the "union" case
when we need memory of suitable size and alignment for multiple types.
SmallVector only needs storage for one type, so use that directly.
2020-10-14 16:16:02 -07:00
jasonliu
d77cbcb130 [AIX] Turn -fdata-sections on by default in Clang
Summary:

This patch does the following:
1. Make InitTargetOptionsFromCodeGenFlags() accepts Triple as a
 parameter, because some options' default value is triple dependant.
2. DataSections is turned on by default on AIX for llc.
3. Test cases change accordingly because of the default behaviour change.
4. Clang Driver passes in -fdata-sections by default on AIX.

Reviewed By: MaskRay, DiggerLin

Differential Revision: https://reviews.llvm.org/D88737
2020-10-14 15:58:31 +00:00
Bevin Hansson
ad6d96ea4f [Fixed Point] Add floating point methods to APFixedPoint.
This adds methods to APFixedPoint for converting to and from
floating point values.

Differential Revision: https://reviews.llvm.org/D85961
2020-10-09 10:27:42 +02:00
Sam McCall
a23b9aed3d Reapply [ADT] function_ref's constructor is unavailable if the argument is not callable.
This reverts commit 281703e67ffaee8e26efef86e0df3e145477f4cb.

GCC 5.4 bugs are worked around by avoiding use of variable templates.

Differential Revision: https://reviews.llvm.org/D88977
2020-10-07 18:31:12 +02:00
Sam McCall
dc3a1be2c9 Revert "[ADT] function_ref's constructor is unavailable if the argument is not callable."
This reverts commit 4cae6228d129d4c4dfb156c043977bb6b5690031.

Breaks GCC build:
http://lab.llvm.org:8011/#/builders/8/builds/33/steps/6/logs/stdio
2020-10-07 16:37:13 +02:00
Sam McCall
360a9fdce4 [ADT] function_ref's constructor is unavailable if the argument is not callable.
This allows overload sets containing function_ref arguments to work correctly
Otherwise they're ambiguous as anything "could be" converted to a function_ref.

This matches proposed std::function_ref, absl::function_ref, etc.

Differential Revision: https://reviews.llvm.org/D88901
2020-10-07 16:31:09 +02:00
Roman Lebedev
8b5ad85b2f [NFC][APInt] Refactor getMinSignedBits() in terms of getNumSignBits()
This is fully identical to the old implementation, just easier to read.
2020-09-22 21:37:29 +03:00
Simon Pilgrim
ce833bfec3 Revert rGf835779160ec303 "[APFloat] multiplySignificand - always pass IEEEFloat as const reference. NFCI."
This reverts commit f835779160ec30340676918915526615a07e826e while I investigate some buildbot failures
2020-09-22 12:15:23 +01:00
Simon Pilgrim
5c56e1aa26 [APFloat] multiplySignificand - always pass IEEEFloat as const reference. NFCI.
We do this in all other cases.
2020-09-22 11:29:29 +01:00
Serge Pavlov
35714dfbb7 [FPEnv] Use typed accessors in FPOptions
Previously methods `FPOptions::get*` returned unsigned value even if the
corresponding property was represented by specific enumeration type. With
this change such methods return actual type of the property. It also
allows printing value of a property as text rather than integer code.

Differential Revision: https://reviews.llvm.org/D87812
2020-09-18 14:16:43 +07:00
Simon Pilgrim
558faf7f34 APInt.h - return directly from clearUnusedBits in single word cases. NFCI.
Consistently use the same pattern of returning *this from the clearUnusedBits() call to allow us to early out from the isSingleWord() path and avoid an else statement.
2020-09-09 13:22:57 +01:00
Simon Pilgrim
095c0be790 [APFloat] Fix uninitialized variable in IEEEFloat constructors
Some constructors of IEEEFloat do not initialize member variable exponent.
Fix it by initializing exponent with the following values:

For NaNs, the `exponent` is `maxExponent+1`.
For Infinities, the `exponent` is `maxExponent+1`.
For Zeroes, the `exponent` is `maxExponent-1`.

Patch by: @nullptr.cpp (Yang Fan)

Differential Revision: https://reviews.llvm.org/D86997
2020-09-09 11:38:30 +01:00
Benjamin Kramer
c3337b0542 [SmallVector] Move error handling out of line
This reduces duplication and avoids emitting ice cold code into every
instance of grow().
2020-09-06 18:06:44 +02:00
Fangrui Song
7b5b3c5b86 [SmallVector] Include stdexcept if LLVM_ENABLE_EXCEPTIONS
std::length_error needs stdexcept.
2020-09-03 18:06:08 -07:00
Dimitry Andric
79876868be Eliminate the sizing template parameter N from CoalescingBitVector
Since the parameter is not used anywhere, and the default size of 16
apparently causes PR47359, remove it. This ensures that IntervalMap will
automatically determine the optimal size, using its NodeSizer struct.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D87044
2020-09-03 18:15:41 +02:00
Geoffrey Martin-Noble
60cb217dc7 Improve error handling for SmallVector programming errors
This patch changes errors in `SmallVector::grow` that are independent of
memory capacity to be reported using report_fatal_error or
std::length_error instead of report_bad_alloc_error, which falsely signals
an OOM.

It also cleans up a few related things:
- makes report_bad_alloc_error to print the failure reason passed
  to it.
- fixes the documentation to indicate that report_bad_alloc_error
  calls `abort()` not "an assertion"
- uses a consistent name for the size/capacity argument to `grow`
  and `grow_pod`

Reviewed By: mehdi_amini, MaskRay

Differential Revision: https://reviews.llvm.org/D86892
2020-09-02 15:00:26 -07:00
Jay Foad
53df1fb508 [APInt] New member function setBitVal
Differential Revision: https://reviews.llvm.org/D87033
2020-09-02 21:40:31 +01:00
Zi Xuan Wu
ed26c15759 [RFC][Target] Add a new triple called Triple::csky
Before upstream a new target called CSKY, make a new triple of that called Triple::csky.
For now, it's a 32-bit little endian target and the detail can be referred at D86269.

This is the split part of D86269, which add a new target called CSKY.

Differential Revision: https://reviews.llvm.org/D86505
2020-09-02 12:46:09 +08:00
Varun Gandhi
99d53ed697 [ADT] Make Optional a literal type.
This allows returning Optional values from constexpr contexts.

Reviewed By: fhahn, dblaikie, rjmccall

Differential Revision: https://reviews.llvm.org/D86354
2020-09-01 16:13:40 -07:00
Roman Lebedev
5d89fa42b3 [NFC][STLExtras] Add make_first_range(), similar to existing make_second_range()
Having just one of the two seens weird.
I wanted to use it a few times, but it wasn't there.
2020-08-29 09:58:07 +03:00
Yevgeny Rouban
ae25ecf12b [ADT] Allow IsSizeLessThanThresholdT for incomplete types. NFC
If the type T is incomplete then sizeof(T) results in C++ compilation error at line:
  static constexpr bool value = sizeof(T) <= (2 * sizeof(void *));

This patch allows incomplete types in parameters of function. Example:
  using SomeFunc = void(SomeIncompleteType &);
  llvm::unique_function<SomeFuncType> SomeFunc;

Reviewers: DaniilSuchkov, vvereschaka

Differential Revision: https://reviews.llvm.org/D81554
2020-08-21 11:01:57 +07:00
Vitaly Buka
8be4d9ede0 [APInt] Allow self-assignment with libstdc++
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-ubuntu/builds/8256/steps/test-check-all/logs/FAIL%3A%20LLVM%3A%3Athinlto-function-summary-paramaccess.ll

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D86053
2020-08-20 04:14:40 -07:00
Bevin Hansson
9531c6209d [ADT] Move FixedPoint.h from Clang to LLVM.
This patch moves FixedPointSemantics and APFixedPoint
from Clang to LLVM ADT.

This will make it easier to use the fixed-point
classes in LLVM for constructing an IR builder for
fixed-point and for reusing the APFixedPoint class
for constant evaluation purposes.

RFC: http://lists.llvm.org/pipermail/llvm-dev/2020-August/144025.html

Reviewed By: leonardchan, rjmccall

Differential Revision: https://reviews.llvm.org/D85312
2020-08-20 10:29:45 +02:00
Kai Nacke
b0aab57571 [SystemZ/ZOS] Add binary format goff and operating system zos to the triple
Adds the binary format goff and the operating system zos to the triple
class. goff is selected as default binary format if zos is choosen as
operating system. No further functionality is added.

Reviewers: efriedma, tahonermann, hubert.reinterpertcast, MaskRay

Reviewed By: efriedma, tahonermann, hubert.reinterpertcast

Differential Revision: https://reviews.llvm.org/D82081
2020-08-11 05:26:26 -04:00
Shinji Okumura
4e0af248b2 [NFC][APInt][DenseMapInfo] Move DenseMapAPIntKeyInfo into DenseMap.h as DenseMapInfo<APInt>
`DenseMapAPIntKeyInfo` is now located in `lib/IR/LLVMContextImpl.h`.
Moved it into `include/ADT/DenseMapInfo.h` to use it.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D85131
2020-08-03 23:31:13 +09:00
Shinji Okumura
7c6b247bf7 Revert "[Attributor] AAPotentialValues Interface"
The commit cause build failure.
2020-08-02 22:49:52 +09:00
Shinji Okumura
5dd3ff33f5 [Attributor] AAPotentialValues Interface
This is a split patch of D80991.
This patch introduces AAPotentialValues and its interface only.
For more detail of AAPotentialValues abstract attribute, see the original patch.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D83283
2020-08-02 19:12:17 +09:00
Stefanos Baziotis
9255f8a1f0 [ADT][BitVector][NFC] Merge find_first_in() / find_first_unset_in()
We can implement find_first_unset_in() in the same function
if every BitWord we use is first flipped.

Differential Revision: https://reviews.llvm.org/D84717
2020-07-29 04:51:22 +03:00
Jinsong Ji
a3d207d6bc Re-land "[PowerPC] Remove QPX/A2Q BGQ/BGP CNK support"
This reverts commit bf544fa1c3cb80f24d85e84559fb11193846259f.

Fixed the typo in PPCInstrInfo.cpp.
2020-07-28 14:00:11 +00:00
Alina Sbirlea
f4701f9f4b [CFGDiff] Refactor Succ/Pred maps.
Summary:
Refactor Succ/Pred maps to have a single map lookup when constructing
children. The preivous desing made sense when used by GraphTraits.
This more closely matches the previous approach in DomTree.

Reviewers: dblaikie

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D84567
2020-07-27 18:02:52 -07:00
Jinsong Ji
89408b2ab3 Revert "[PowerPC] Remove QPX/A2Q BGQ/BGP CNK support"
This reverts commit adffce71538e219aab4eeb024819baa7687262ff.

This is breaking test-suite, revert while investigation.
2020-07-27 21:07:00 +00:00
Jinsong Ji
2d65e976a4 [PowerPC] Remove QPX/A2Q BGQ/BGP CNK support
Per RFC http://lists.llvm.org/pipermail/llvm-dev/2020-April/141295.html
no one is making use of QPX/A2Q/BGQ/BGP CNK anymore.

This patch remove the support of QPX/A2Q in llvm, BGQ/BGP in clang,
CNK support in openmp/polly.

Reviewed By: hfinkel

Differential Revision: https://reviews.llvm.org/D83915
2020-07-27 19:24:39 +00:00
Nathan James
8b5de07c6a [ADT] Add a range-based version of std::move
Adds a range-based version of `std::move`, the version that moves a range, not the one that creates r-value references.

Reviewed By: dblaikie, gamesh411

Differential Revision: https://reviews.llvm.org/D83902
2020-07-25 10:37:34 +01:00
Fangrui Song
b4f9e0d70d [ADT] Delete unused llvm::pointer_union_detail::AssignableFrom
Noticed by Zhiwei Chen
2020-07-22 09:24:36 -07:00
Nathan James
6fc76c37f5 [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
2020-07-21 09:55:16 +01:00
Yuanfang Chen
8dacd8c600 [NFC] remove unused llvm::deleter 2020-07-20 10:43:29 -07:00
David Blaikie
8ab112dbf4 [llvm] Add contains(KeyType) -> bool methods to StringSet
Matches C++20 API addition.

Differential Revision: https://reviews.llvm.org/D83449
2020-07-17 11:26:27 -07:00
David Blaikie
479337797c [llvm] Add contains(KeyType) -> bool methods to SparseSet
Matches C++20 API addition.

Differential Revision: https://reviews.llvm.org/D83449
2020-07-17 11:26:27 -07:00
David Blaikie
294e3ec1ba [llvm] Add contains(KeyType) -> bool methods to SmallSet
Matches C++20 API addition.

Differential Revision: https://reviews.llvm.org/D83449
2020-07-17 11:26:27 -07:00
David Blaikie
fe6846924a [llvm] Add contains(KeyType) -> bool methods to SmallPtrSet
Matches C++20 API addition.

Differential Revision: https://reviews.llvm.org/D83449
2020-07-17 11:26:27 -07:00
David Blaikie
3cfbc95ca8 [llvm] Add contains(KeyType) -> bool methods to SetVector
Matches C++20 API addition.

Differential Revision: https://reviews.llvm.org/D83449
2020-07-17 11:26:27 -07:00
David Blaikie
f4752de569 [llvm] Add contains(KeyType) -> bool methods to DenseSet
Matches C++20 API addition.

Differential Revision: https://reviews.llvm.org/D83449
2020-07-17 11:26:26 -07:00
Michael Forster
070c7b821a Add hashing support for std::tuple
Summary:
All tuple values are passed directly to hash_combine. This is inspired by the implementation used for Swift:

4a1b4edbe1
845f3829b9

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83887
2020-07-16 19:01:25 +02:00
Rahul Joshi
b39d7177a6 [NFC] Use appropriate names for for_each and transform template parameters
Differential Revision: https://reviews.llvm.org/D83848
2020-07-16 09:35:16 -07:00
Nikita Popov
addd3a654c [ADT] Specialize std::swap() for SetVector
This is intended to address a compile-time regression from
1eddce4177cfddc86d4696b758904443b0b4f193. A SmallPtrSet was
replaced with a SetVector there, which had an unexpected large
compile-time impact. It turns out that this structure is getting
swapped a lot, and previously this used an optimized std::swap()
specialization for SmallPtrSet. Now it ends up using the default,
triple-move based implementation, which is much more expensive.

This patch (partly) addresses the issue by specializing std::swap()
for SetVector.

Differential Revision: https://reviews.llvm.org/D82230
2020-07-13 23:14:04 +02:00
Pavel Labath
af4f8a5640 [ADT] Make Load(AP)IntFromMemory pointer argument const
The function does not modify this memory.
2020-07-13 17:32:54 +02:00
sstefan1
50ffa1ab38 Reland "[OpenMPOpt] ICV Tracking"
This reverts commit 1d542f0ca83fa1411d6501a8d088450d83abd5b8.

`recollectUses()` is added to prevent looking at dead uses after
Attributor run.

This is the first and most basic ICV Tracking implementation. For this
first version, we only support deduplication within the same BB.

Reviewers: jdoerfert, JonChesterfield, hamax97, jhuber6, uenoku,
baziotis, lebedev.ri

Differential Revision: https://reviews.llvm.org/D81788
2020-07-11 02:25:57 +02:00
David Blaikie
5518644f63 Remove unnecessary/erroneous "static" from function templates in headers
This risks ODR violations in inline functions that call these functions
(if they remain static) & otherwise just causes some object size
increase, potentially, by these functions not being deduplicated by the
linker.
2020-07-10 16:23:33 -07:00
Guillaume Chatelet
a3a41cd01b [Bitfields][NFC] Make sure bitfields are contiguous
Differential Revision: https://reviews.llvm.org/D83202
2020-07-07 14:35:13 +00:00
Bruno Ricci
127992925a [Support][NFC] Fix Wdocumentation warning in ADT/Bitfields.h
\tparam is used for template parameters instead of \param.
2020-07-06 22:41:40 +01:00
Guillaume Chatelet
6e9457fc4d Fix off by one error in Bitfields
Differential Revision: https://reviews.llvm.org/D83192
2020-07-06 08:47:58 +00:00
River Riddle
986143ca63 Add front/back accessors to indexed_accessor_range.
These map to the similar accessors on ArrayRef and other random access containers.

This fixes a compilation error on MLIR ODS for variadic operands/results, which relied on the availability of front in certain situations.
2020-06-29 22:41:15 -07:00
Sam McCall
8554b66076 [ADT] Use more explicit from to initialize member. Appease MSVC?
Or at least get a clearer error message:
http://lab.llvm.org:8011/builders/mlir-windows/builds/3958/steps/build-unified-tree/logs/stdio
2020-06-29 22:22:12 +02:00
Sam McCall
b7a1205c71 Reland [ADT] Support const-qualified unique_functions
This reverts commit 09b6dffb8ed19d624fddc7a57ce886f8be3c45b2.

Now compiles with GCC!
2020-06-29 21:40:16 +02:00
Alex Lorenz
7a66c0870c [darwin][driver] isMacosxVersionLT should check against the minimum supported OS version
This change ensures that the Darwin driver doesn't add unsupported libraries to the link
invocation when linking the Apple Silicon macOS slice.

rdar://61011136

Differential Revision: https://reviews.llvm.org/D82696
2020-06-29 12:21:54 -07:00
Nikita Popov
9640f394fa Revert "[ADT] Support const-qualified unique_functions"
This reverts commit 01bf8cdf5fa9bc71869e15e5e351b2b68c39feb6.

Breaks the build:

llvm/include/llvm/ADT/FunctionExtras.h:223:7: error: explicit template argument list not allowed
  223 |       Callbacks<CallableT, CalledAs, EnableIfTrivial<CallableT>>;
2020-06-29 20:28:10 +02:00
Sam McCall
8618b3d880 [ADT] Support const-qualified unique_functions
Summary:
This technique should extend to rvalue-qualified etc, but I didn't add any.
I removed "volatile" from the future plans, which seems... speculative at best.

While here I moved the callbacks object out of the constructor into a
variable template, which I believe addresses the fixme there about unused
objects.

(I'm not a template guru, so it's always possible the old version was designed
for compile-time performance in a way I'm missing)

Reviewers: kadircet

Subscribers: dexonsmith, llvm-commits, chandlerc

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82581
2020-06-29 20:13:42 +02:00
Simon Pilgrim
4bf9737876 Fix MSVC truncation of constant value warning. 2020-06-29 16:03:00 +01:00
Guillaume Chatelet
e127592414 [NFC] Fix typos 2020-06-29 13:00:37 +00:00
Guillaume Chatelet
9871a892f8 [ADT] Add Bitfield utilities
Context:
--------
There are places in LLVM where we need to pack typed fields into opaque values.
For instance, the `XXXInst` classes in `llvm/include/llvm/IR/Instructions.h` that extract informations from `Value::SubclassData` via `getSubclassDataFromInstruction()`.
The bit twiddling is done manually: this impairs readability and prevent consistent handling of out of range values (e.g. 435b458ad0/llvm/include/llvm/IR/Instructions.h (L564))
More importantly, the bit pattern is scattered throughout the implementation making it hard to pack additionnal fields or check for overlapping bits.

Design decisions:
-----------------
The Bitfield structs are to be declared together so it is clear which bits are used or not.
The code is designed with simplicity in mind, hence a few limitations:
 - Storage is limited to a single integer,
 - Enum values have to be `unsigned`,
 - Storage type has to be `unsigned`,
 - There are no automatic detection of overlapping fields (packed bitfield declaration should help though),
 - The interface is C like so `storage` needs to be passed in everytime (code is simpler and lifetime considerations more obvious)

RFC: http://lists.llvm.org/pipermail/llvm-dev/2020-June/142196.html

Differential Revision: https://reviews.llvm.org/D81580
2020-06-29 12:48:44 +00:00
Simon Pilgrim
f5fa275b44 Revert rGf0bab7875e78e01c149d12302dcc4b6d4c43e25c - "Triple.h - reduce Twine.h include to forward declarations. NFC."
This causes ICEs on the clang-ppc64be buildbots and I've limited ability to triage the problem.
2020-06-26 14:46:40 +01:00
Simon Pilgrim
efd7ae7bbc Triple.h - reduce Twine.h include to forward declarations. NFC.
Move include down to a number of other files that had an implicit dependency on the Twine class.
2020-06-26 13:06:57 +01:00
Alex Lorenz
a32e5e9698 [Triple] support macOS 11 os version number
macOS goes to 11! This commit adds support for the new version number by ensuring
that existing version comparison routines, and the 'darwin' OS identifier
understands the new numbering scheme. It also adds a new utility method
'getCanonicalVersionForOS', which lets users translate some uses of
macOS 10.16 into macOS 11. This utility method will be used in upcoming
clang and swift commits.

Differential Revision: https://reviews.llvm.org/D82337
2020-06-22 23:03:47 -07:00
Rahul Joshi
099582bd9c - Add hasNItemsOrLess and container variants of hasNItems, hasNItemsOrMore, and hasNItemsOrLess
- Fixed a bug in hasNItems()
- Extend the STLExtras unit test to test hasSingleElement() and hasNItems() and friends.

Differential Revision: https://reviews.llvm.org/D82232
2020-06-22 15:07:36 -07:00
Daniel
ec554713c8 [clang-tidy] remove duplicate fixes of alias checkers
when both a check and its alias are enabled, we should only take the fixes of one of them and not both.
This patch fixes bug 45577
https://bugs.llvm.org/show_bug.cgi?id=45577

Reviewed By: aaron.ballman, njames93

Differential Revision: https://reviews.llvm.org/D80753
2020-06-19 20:40:59 +01:00
Thomas Preud'homme
b66c895a2d [ADT] Fix itostr handling of min int64_t value
Summary:
UBSan buildbot caught an undefined behavior in itostr with INT64_MIN.
The negation cannot be represented in the promoted operand (long long).
Negation is well defined on unsigned value though so this commit does
the negation after the static cast.

Reviewers: jhenderson, chandlerc, lattner

Reviewed By: lattner

Subscribers: dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82200
2020-06-19 18:38:43 +01:00
Chen Zheng
0256ae72a3 [APInt] set all bits for getBitsSetWithWrap if loBit == hiBit
differentiate getBitsSetWithWrap & getBitsSet when loBit == hiBit
getBitsSetWithWrap sets all bits;
getBitsSet does nothing.

Reviewed By: lkail, RKSimon, lebedev.ri

Differential Revision: https://reviews.llvm.org/D81325
2020-06-08 22:55:24 -04:00
Jonas Paulsson
27037aea90 [SystemZ] Implement -fstack-clash-protection
Probing of allocated stack space is now done when this option is passed. The
purpose is to protect against the stack clash attack (see
https://www.qualys.com/2017/06/19/stack-clash/stack-clash.txt).

Review: Ulrich Weigand

Differential Revision: https://reviews.llvm.org/D78717
2020-06-06 18:38:36 +02:00
Vedant Kumar
6f84fd7763 [LiveDebugValues] Speed up removeEntryValue, NFC
Summary:
Instead of iterating over all VarLoc IDs in removeEntryValue(), just
iterate over the interval reserved for entry value VarLocs. This changes
the iteration order, hence the test update -- otherwise this is NFC.

This appears to give an ~8.5x wall time speed-up for LiveDebugValues when
compiling sqlite3.c 3.30.1 with a Release clang (on my machine):

```
          ---User Time---   --System Time--   --User+System--   ---Wall Time--- --- Name ---
  Before: 2.5402 ( 18.8%)   0.0050 (  0.4%)   2.5452 ( 17.3%)   2.5452 ( 17.3%) Live DEBUG_VALUE analysis
   After: 0.2364 (  2.1%)   0.0034 (  0.3%)   0.2399 (  2.0%)   0.2398 (  2.0%) Live DEBUG_VALUE analysis
```

The change in removeEntryValue() is the only one that appears to affect
wall time, but for consistency (and to resolve a pending TODO), I made
the analogous changes for iterating over SpillLocKind VarLocs.

Reviewers: nikic, aprantl, jmorse, djtodoro

Subscribers: hiraditya, dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80684
2020-06-01 11:02:36 -07:00
serge-sans-paille
ffa794c4cb Improve SmallPtrSetImpl::count implementation
Relying on the find method implies a roundtrip to the iterator world, which is
not costless because iterator creation involves a few check to ensure the
iterator is in a valid position (through the SmallPtrSetIteratorImpl::AdvanceIfNotValid
method). It turns out that the result of SmallPtrSetImpl::find_imp is either
valid or the EndPointer, so there's no need to go through that abstraction,
and the compiler cannot guess it.

Differential Revision: https://reviews.llvm.org/D80708
2020-06-01 07:49:19 +02:00
Saiyedul Islam
1696d5f270 [OpenMP][AMDGCN] Support OpenMP offloading for AMDGCN architecture - Part 1
Summary:
Allow AMDGCN as a GPU offloading target for OpenMP during compiler
invocation and allow setting CUDAMode for it.

Originally authored by Greg Rodgers (@gregrodgers).

Reviewers: ronlieb, yaxunl, b-sumner, scchan, JonChesterfield, jdoerfert, sameerds, msearles, hliao, arsenm

Reviewed By: sameerds

Subscribers: sstefan1, jvesely, wdng, arsenm, guansong, dexonsmith, cfe-commits, llvm-commits, gregrodgers

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D79754
2020-05-27 07:51:27 +00:00
Benjamin Kramer
86b9f45429 [ImmutableSet] Use IntrusiveRefCntPtr to eliminate some manual refcounting
Still not ideal as the refcounting leaks to users, but better than
before. NFCI.
2020-05-21 19:10:22 +02:00
Jean-Michel Gorius
e77d83d2b0 [ADT][Analysis] NFC: Fix some more typos 2020-05-21 18:53:43 +02:00
Jean-Michel Gorius
bd64a1c8db [ADT] NFC: Fix typos in header comments 2020-05-21 17:43:00 +02:00
Ties Stuij
745a9668d4 [IR][BFloat] Add BFloat IR type
Summary:
The BFloat IR type is introduced to provide support for, initially, the BFloat16
datatype introduced with the Armv8.6 architecture (optional from Armv8.2
onwards). It has an 8-bit exponent and a 7-bit mantissa and behaves like an IEEE
754 floating point IR type.

This is part of a patch series upstreaming Armv8.6 features. Subsequent patches
will upstream intrinsics support and C-lang support for BFloat.

Reviewers: SjoerdMeijer, rjmccall, rsmith, liutianle, RKSimon, craig.topper, jfb, LukeGeeson, sdesmalen, deadalnix, ctetreau

Subscribers: hiraditya, llvm-commits, danielkiss, arphaman, kristof.beyls, dexonsmith

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78190
2020-05-15 14:43:43 +01:00
Benjamin Kramer
168515468c [StringSet] Simplify code a bit. NFC. 2020-05-14 20:56:49 +02:00
River Riddle
ef34a4ddd4 [mlir] Add support for merging identical blocks during canonicalization
This revision adds support for merging identical blocks, or those with the same operations that branch to the same successors. Operands that mismatch between the different blocks are replaced with new block arguments added to the merged block.

Differential Revision: https://reviews.llvm.org/D79134
2020-05-04 19:56:46 -07:00
Benjamin Kramer
cc00bd7349 [SmallVector] Weaken the predicate for the memcpy optimization
We don't require the type to be trivially assignable. While the standard
says that only is_trivially_copyable types may be memcpy'd, this seems
overly strict. We never assign the type, so there's no way for the type
to observe that the copy/move construction got elided. This is important
for std::pair<POD, POD>, which is not trivially assignable and probably
never will be because changing that would break ABI.

As a side-effect this no longer allows types with deleted copy/move
constructors in SmallVector. That's an unintended side-effect of
is_trivially_copyable anyways.

Shrinks Release+Asserts clang by 20k.
2020-05-02 19:40:42 +02:00