Commit Graph

1272 Commits

Author SHA1 Message Date
Ilia Diachkov 6c69427e88 [SPIR-V](3/6) Add MC layer, object file support, and InstPrinter
The patch adds SPIRV-specific MC layer implementation, SPIRV object
file support and SPIRVInstPrinter.

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

Authors: Aleksandr Bezzubikov, Lewis Crawford, Ilia Diachkov,
Michal Paszkowski, Andrey Tretyakov, Konrad Trifunovic

Co-authored-by: Aleksandr Bezzubikov <zuban32s@gmail.com>
Co-authored-by: Ilia Diachkov <iliya.diyachkov@intel.com>
Co-authored-by: Michal Paszkowski <michal.paszkowski@outlook.com>
Co-authored-by: Andrey Tretyakov <andrey1.tretyakov@intel.com>
Co-authored-by: Konrad Trifunovic <konrad.trifunovic@intel.com>
2022-04-20 01:10:25 +02:00
Antonio Frighetto 7c3d8c8977 Fix warnings when `-Wdeprecated-enum-enum-conversion` is enabled
clang may throw the following warning:
include/clang/AST/DeclarationName.h:210:52: error: arithmetic between
different enumeration types ('clang::DeclarationName::StoredNameKind'
and 'clang::detail::DeclarationNameExtra::ExtraKind') is deprecated
when flags -Werror,-Wdeprecated-enum-enum-conversion are on.

This adds the `addEnumValues()` helper function to STLExtras.h to hide
the details of adding enumeration values together from two different
enumerations.
2022-04-07 08:20:54 -04:00
Paul Robinson 077f90315b [PS5] Add PS5 as a legal triple component 2022-04-05 12:55:12 -07:00
Chris Bieneman 9130e471fe Add DXContainer
DXIL is wrapped in a container format defined by the DirectX 11
specification. Codebases differ in calling this format either DXBC or
DXILContainer.

Since eventually we want to add support for DXBC as a target
architecture and the format is used by DXBC and DXIL, I've termed it
DXContainer here.

Most of the changes in this patch are just adding cases to switch
statements to address warnings.

Reviewed By: pete

Differential Revision: https://reviews.llvm.org/D122062
2022-03-29 14:34:23 -05:00
Chris Bieneman b39f437757 [ADT] add initializer list specialization for is_contained
Adding an initializer list specialization for is_contained allows for
compile-time evaluation when called with a constant or runtime
evaluation for non-constant values.

This patch doesn't add any uses of this template, but that is coming in
a subsequent patch.

Reviewed By: pete

Differential Revision: https://reviews.llvm.org/D122079
2022-03-29 12:39:39 -05:00
Chris Bieneman 5b6207f3cd [ADT] Flesh out HLSL raytracing environments
Fleshing this out now allows me to rely on enum math to translate
values rather than having to translate the off cases.

I should have added this in the first pass, but wasn't thinking about
it.
2022-03-29 09:43:03 -05:00
Marek Kurdej df4da5f37d [ADT] Add drop_end.
This patch adds drop_end that is analogical to drop_begin.
It tries to fill the functional gap where one could drop first elements but not the last ones.
The need for it came in when refactoring clang-format.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D122009
2022-03-21 09:43:19 +01:00
Chris Bieneman 95871187bf Add DXIL triple
This patch adds triple support for:

* dxil architecture
* shadermodel OS (with version parsing)
* shader stages as environment

Reviewed By: MaskRay, pete

Differential Revision: https://reviews.llvm.org/D122031
2022-03-19 00:17:43 -05:00
Pavel Labath 161bddf3af [ADT] Make BitmaskEnum operations constant expressions
This avoids runtime initialization (a global constructor) whenever they appear
in the initializer.

The patch just adds the constexpr keyword to a couple of functions.

Differential Revision: https://reviews.llvm.org/D121281
2022-03-11 11:11:55 +01:00
Egor Zhdan 3a1cb36237 Add DriverKit support
This patch is the first in a series of patches to upstream the support for Apple's DriverKit. Once complete, it will allow targeting DriverKit platform with Clang similarly to AppleClang.

This code was originally authored by JF Bastien.

Differential Revision: https://reviews.llvm.org/D118046
2022-02-22 13:42:53 +00:00
Lu Weining 42fd2bfc90 [LoongArch 1/6] Add triples loongarch{32,64} for the upcoming LoongArch target
This is the first patch to incrementally add an MC layer for LoongArch to LLVM.
This patch also adds unit testcases for these new triples.

RFC for adding this new backend:
https://lists.llvm.org/pipermail/llvm-dev/2021-December/154371.html

Differential revision: https://reviews.llvm.org/D115857
2022-02-10 10:23:34 +00:00
Simon Pilgrim d1d7188b04 Fix signed/unsigned comparison warnings on ppc buildbots 2022-02-08 14:15:28 +00:00
Simon Pilgrim 58f944cf0b Fix signed/unsigned comparison warnings on ppc buildbots 2022-02-08 13:56:41 +00:00
Simon Pilgrim fd2bb51f1e [ADT] Add APInt/MathExtras isShiftedMask variant returning mask offset/length
In many cases, calls to isShiftedMask are immediately followed with checks to determine the size and position of the bitmask.

This patch adds variants of APInt::isShiftedMask, isShiftedMask_32 and isShiftedMask_64 that return these values as additional arguments.

I've updated a number of cases that were either performing seperate size/position calculations or had created their own local wrapper versions of these.

Differential Revision: https://reviews.llvm.org/D119019
2022-02-08 12:04:13 +00:00
Simon Pilgrim 675a557316 Remove redundant LLVM_HAS_RVALUE_REFERENCE_THIS and LLVM_LVALUE_FUNCTION defines
Now that VS2017 support has been dropped (D114639), the LLVM_HAS_RVALUE_REFERENCE_THIS define is always true and the LLVM_LVALUE_FUNCTION define is always enabled for ref-qualifiers.

This patch proposes we remove the defines and use the qualifiers directly.

Differential Revision: https://reviews.llvm.org/D118609
2022-02-02 16:56:26 +00:00
Aaron Ballman f489e86a24 Remove Waymarking.h as it is unused
This file was added in https://reviews.llvm.org/D74415. There was no
justification as to why it was added, and after about a year of being
in-tree, it's still unused, so this removes it.
2022-01-28 14:20:06 -05:00
Yuanfang Chen a41c8b8fd5 [ADT] support fixed-width output with `utohexstr`
Will use it to output a hash value that needs fixed-width.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D118427
2022-01-28 10:07:54 -08:00
Amilendra Kodithuwakku 1f08b08674 [clang][ARM] Emit warnings when PACBTI-M is used with unsupported architectures
Branch protection in M-class is supported by
 - Armv8.1-M.Main
 - Armv8-M.Main
 - Armv7-M

Attempting to enable this for other architectures, either by
command-line (e.g -mbranch-protection=bti) or by target attribute
in source code (e.g.  __attribute__((target("branch-protection=..."))) )
will generate a warning.

In both cases function attributes related to branch protection will not
be emitted. Regardless of the warning, module level attributes related to
branch protection will be emitted when it is enabled via the command-line.

The following people also contributed to this patch:
- Victor Campos

Reviewed By: chill

Differential Revision: https://reviews.llvm.org/D115501
2022-01-28 09:59:58 +00:00
Benjamin Kramer f15014ff54 Revert "Rename llvm::array_lengthof into llvm::size to match std::size from C++17"
This reverts commit ef82063207.

- It conflicts with the existing llvm::size in STLExtras, which will now
  never be called.
- Calling it without llvm:: breaks C++17 compat
2022-01-26 16:55:53 +01:00
serge-sans-paille ef82063207 Rename llvm::array_lengthof into llvm::size to match std::size from C++17
As a conquence move llvm::array_lengthof from STLExtras.h to
STLForwardCompat.h (which is included by STLExtras.h so no build
breakage expected).
2022-01-26 16:17:45 +01:00
serge-sans-paille 5f290c090a Move STLFunctionalExtras out of STLExtras
Only using that change in StringRef already decreases the number of
preoprocessed lines from 7837621 to 7776151 for LLVMSupport

Perhaps more interestingly, it shows that many files were relying on the
inclusion of StringRef.h to have the declaration from STLExtras.h. This
patch tries hard to patch relevant part of llvm-project impacted by this
hidden dependency removal.

Potential impact:
- "llvm/ADT/StringRef.h" no longer includes <memory>,
  "llvm/ADT/Optional.h" nor "llvm/ADT/STLExtras.h"

Related Discourse thread:
https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2022-01-24 14:13:21 +01:00
Chris Bieneman 9d3437fbf3 [ADT] [NFC] Add StringRef::detectEOL
This change moves EOL detection out of the clang::InclusionRewriter into
llvm::StringRef so that it can be easily reused elsewhere. It also adds
additional explicit test cases to verify the correct and expected return
results.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D117626
2022-01-21 09:47:02 -06:00
Jan Svoboda 622354a522 [llvm][ADT] Implement `BitVector::{pop_,}back`
LLVM Programmer’s Manual strongly discourages the use of `std::vector<bool>` and suggests `llvm::BitVector` as a possible replacement.

Currently, some users of `std::vector<bool>` cannot switch to `llvm::BitVector` because it doesn't implement the `pop_back()` and `back()` functions.

To enable easy transition of `std::vector<bool>` users, this patch implements `llvm::BitVector::pop_back()` and `llvm::BitVector::back()`.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D117115
2022-01-21 14:50:53 +01:00
Steven Wu 347d4d7323 [ADT] Fix Optional<> with llvm::is_trivially_move_constructible
Fix the compatibility of Optional<> with some GCC versions that it will fail
to compile when T is getting checked for `is_trivially_move_constructible`
as mentioned here: https://reviews.llvm.org/D93510#2538983

Fix the problem by using `llvm::is_trivially_move_constructible`.

Reviewed By: jplayer-nv, tatyana-krasnukha

Differential Revision: https://reviews.llvm.org/D117254
2022-01-18 08:37:43 -08:00
Kazu Hirata fc2b09a744 [ADT] Remove ImmutableSet::foreach and ImmutableMap::foreach (NFC)
These functions seem to be unused for at least 1 year.
2022-01-01 22:05:14 -08:00
Scott Linder 78a26c7daf [ADT] Add new type traits for type pack indexes
Similar versions of these already exist, this effectively just just
factors them out into STLExtras. I plan to use these in future patches.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D100672
2021-12-15 19:25:14 +00:00
Matthias Springer 7029a688c9 [adt] Fix compiler warning in test
Differential Revision: https://reviews.llvm.org/D115589
2021-12-15 16:13:24 +09:00
Duncan P. N. Exon Smith 9911589f5d ADT: Make StringRef::size() and StringRef::empty() constexpr
This unblocks using `StringLiteral::size()` for a SmallVector size in
another patch.

Differential Revision: https://reviews.llvm.org/D115395
2021-12-08 16:15:33 -08:00
Duncan P. N. Exon Smith ca451d3fa4 ADT: Add SmallVectorImpl::truncate() to replace uses of set_size()
Add `SmallVectorImpl::truncate()`, a variant of `resize()` that cannot
increase the size.

- Compared to `resize()`, this has no code path for growing the
  allocation and can be better optimized.
- Compared to `set_size()`, this formally calls destructors, and does
  not skip any constructors.
- Compared to `pop_back_n()`, this takes the new desired size, which in
  many contexts is more intuitive than the number of elements to remove.

The immediate motivation is to pair this with `resize_for_overwrite()`
to remove uses of `set_size()`, which can then be made private.

Differential Revision: https://reviews.llvm.org/D115383
2021-12-08 13:57:48 -08:00
James Farrell 219672b8dd Revert "Revert "Use VersionTuple for parsing versions in Triple, fixing issues that caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible.""
This reverts commit 63a6348cad.

Differential Revision: https://reviews.llvm.org/D115254
2021-12-07 23:15:21 +00:00
James Farrell 63a6348cad Revert "Use VersionTuple for parsing versions in Triple, fixing issues that caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible."
This reverts commit 5032467034.
2021-12-06 17:35:26 +00:00
James Farrell 5032467034 Use VersionTuple for parsing versions in Triple, fixing issues that caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible.
This reverts commit 40d5eeac6c.

Differential Revision: https://reviews.llvm.org/D114885
2021-12-06 14:57:47 +00:00
Schuyler Eldridge 63f417ef39
[ADT] Remove 0-width Asserts in APInt.getZExtValue
Remove assertion that disallows getting a zero-extended value from a
zero-width APInt.  This check is too restrictive and makes it difficult
to use APInt to model zero-width things, e.g., zero-width wires in the
CIRCT project.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>

Reviewed By: lattner, darthscsi, nikic

Differential Revision: https://reviews.llvm.org/D114768
2021-11-30 17:03:12 -05:00
Nikita Popov 40d5eeac6c Revert "Use VersionTuple for parsing versions in Triple. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible."
This reverts commit 1e82864670.

llvm/test/Transforms/LoopStrengthReduce/X86/2009-11-10-LSRCrash.ll fails
with assertion failure:

llc: /home/nikic/llvm-project/llvm/include/llvm/ADT/Optional.h:196: T& llvm::optional_detail::OptionalStorage<T, true>::getValue() & [with T = unsigned int]: Assertion `hasVal' failed.
...
 #8 0x00005633843af5cb llvm::MCStreamer::emitVersionForTarget(llvm::Triple const&, llvm::VersionTuple const&)
 #9 0x0000563383b47f14 llvm::AsmPrinter::doInitialization(llvm::Module&)
2021-11-30 18:36:32 +01:00
James Farrell 1e82864670 Use VersionTuple for parsing versions in Triple. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible.
See also https://github.com/android/ndk/issues/1455.

Differential Revision: https://reviews.llvm.org/D114163
2021-11-30 15:44:23 +00:00
Matthias Springer 068483978b [ADT] Add unit test for EquivalanceClasses comparator
This unit tests tests new functionality added by D112052.

Differential Revision: https://reviews.llvm.org/D113461
2021-11-17 08:07:53 +09:00
River Riddle 4c484f11d3 [llvm] Add a SFINAE template parameter to DenseMapInfo
This allows for using SFINAE partial specialization for DenseMapInfo.
In MLIR, this is particularly useful as it will allow for defining partial
specializations that support all Attribute, Op, and Type classes without
needing to specialize DenseMapInfo for each individual class.

Differential Revision: https://reviews.llvm.org/D113641
2021-11-16 18:54:14 +00:00
Duncan P. N. Exon Smith 6b9b86db9d ADT: Fix const-correctness of iterator facade
Fix the const-ness of `iterator_facade_base::operator->` and
`iterator_facade_base::operator[]`. This is a follow-up to
1b651be046, which fixed const-ness of
various iterator adaptors.

Iterators, like the pointers that they generalize, have two types of
`const`.

  - The `const` qualifier on members indicates whether the iterator
    itself can be changed. This is analagous to `int *const`.
  - The `const` qualifier on return values of `operator*()`,
    `operator[]()`, and `operator->()` controls whether the the
    pointed-to value can be changed. This is analogous to `const int*`.

If an iterator facade returns a handle to its own state, then T (and
PointerT and ReferenceT) should usually be const-qualified. Otherwise,
if clients are expected to modify the state itself, the field can be
declared mutable or a const_cast can be used.
2021-11-12 20:41:47 -08:00
Duncan P. N. Exon Smith c3edab8f78 ADT: Avoid repeating iterator adaptor/facade template params, NFC
Take advantage of class name injection to avoid redundantly specifying
template parameters of iterator adaptor/facade base classes.

No functionality change, although the private typedefs changed in a
couple of cases.

  - Added a private typedef HashTableIterator::BaseT, following the
    pattern from r207084 / 3478d4b164, to
    pre-emptively appease MSVC (maybe it's not necessary anymore but
    looks like we do this pretty consistently). Otherwise, I removed
    private
  - Removed private typedefs filter_iterator_impl::BaseT and
    FilterIteratorTest::InputIterator::BaseT since there was only one
    use of each and the definition was no longer interesting.
2021-11-12 14:00:08 -08:00
Duncan P. N. Exon Smith 1b651be046 ADT: Fix const-correctness of iterator adaptors
This fixes const-correctness of iterator adaptors, dropping non-`const`
overloads for `operator*()`.

Iterators, like the pointers that they generalize, have two types of
`const`.

The `const` qualifier on members indicates whether the iterator itself
can be changed. This is analagous to `int *const`.

The `const` qualifier on return values of `operator*()`, `operator[]()`,
and `operator->()` controls whether the the pointed-to value can be
changed. This is analogous to `const int *`.

Since `operator*()` does not (in principle) change the iterator, then
there should only be one definition, which is `const`-qualified. E.g.,
iterators wrapping `int*` should look like:
```
int *operator*() const; // always const-qualified, no overloads
```

ba7a6b314f changed `iterator_adaptor_base`
away from this to work around bugs in other iterator adaptors. That was
already reverted. This patch adds back its test, which combined
llvm::enumerate() and llvm::make_filter_range(), adds a test for
iterator_adaptor_base itself, and cleans up the `const`-ness of the
other iterator adaptors.

This also updates the documented requirements for
`iterator_facade_base`:
```
/// OLD:
///   - const T &operator*() const;
///   - T &operator*();

/// New:
///   - T &operator*() const;
```
In a future commit we might also clean up `iterator_facade`'s overloads
of `operator->()` and `operator[]()`. These already (correctly) return
non-`const` proxies regardless of the iterator's `const` qualifier.

Differential Revision: https://reviews.llvm.org/D113158
2021-11-12 11:24:17 -08:00
River Riddle 6de6131f02 [mlir] Optimize usage of llvm::mapped_iterator
mapped_iterator is a useful abstraction for applying a
map function over an existing iterator, but our current
usage ends up allocating storage/making indirect calls
even with the map function is a known function, which
is horribly inefficient. This commit refactors the usage
of mapped_iterator to avoid this, and allows for directly
referencing the map function when dereferencing.

Fixes PR52319

Differential Revision: https://reviews.llvm.org/D113511
2021-11-11 03:26:29 +00:00
Anastasia Stulova a10a69fe9c [SPIR-V] Add SPIR-V triple and clang target info.
Add new triple and target info for ‘spirv32’ and ‘spirv64’ and,
thus, enabling clang (LLVM IR) code emission to SPIR-V target.

The target for SPIR-V is mostly reused from SPIR by derivation
from a common base class since IR output for SPIR-V is mostly
the same as SPIR. Some refactoring are made accordingly.

Added and updated tests for parts that are different between
SPIR and SPIR-V.

Patch by linjamaki (Henry Linjamäki)!

Differential Revision: https://reviews.llvm.org/D109144
2021-11-08 13:34:10 +00:00
Roman Lebedev 7a98761d74
[NFC] Move CombinationGenerator from Exegesis to ADT
Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D113213
2021-11-05 16:53:46 +03:00
Geoffrey Martin-Noble c92de29f8d [NFC] Add size inference to to_vector
A default calculated size for SmallVector was added in
https://reviews.llvm.org/D92522 after discussion in
https://groups.google.com/g/llvm-dev/c/Z-VwNCTRGSg, but to_vector still
requires an explicit size. This patch adds the default size to to_vector
as well, so that this case doesn't unnecessarily force users to pick an
arbitrary size.

Reviewed By: silvas, dblaikie

Differential Revision: https://reviews.llvm.org/D112968
2021-11-04 09:24:02 -07:00
Ben Vanik 2fcffcd0e8 [ADT] Simplifying hex string parsing so it runs faster in debug modes.
This expands the lookup table statically and avoids routing through methods that
contain asserts (like StringRef/std::string element accessors and drop_front)
such that performance is more predictable across compilation environments. This
was primarily driven by slow debug mode performance but has a large benefit in
release builds as well.

```
ssd_mobilenet_v2_face_float (42MB .mlir)
  Debug/MSVC (old):  5.22s
  Debug/MSVC (new):  0.16s
Release/MSVC (old):  0.81s
Release/MSVC (new):  0.02s

huggingface_minilm (536MB .mlir)
  Debug/MSVC (old): 65.31s
  Debug/MSVC (new):  2.03s
Release/MSVC (old):  9.93s
Release/MSVC (new):  0.27s
```

Now in debug the time is split evenly between lexString, tryGetFromHex, and
element attrs hashing, with the next step to making it faster being to combine
the work (incremental hashing during conversion, etc) - but this is at least in
the right order of magnitude and retains the original API surface.

I have not profiled a build with clang but this is strictly less code and simpler
data structures so I'd expect improvements there as well.

This also fixes a bug where 0xFF bytes in the input would read out of bounds.

Reviewed By: dblaikie, stellaraccident

Differential Revision: https://reviews.llvm.org/D112105
2021-11-03 20:31:20 -07:00
Jakub Kuderski 3348b841d3 Make enum iteration with seq safe by default
By default `llvm::seq` would happily iterate over enums, which may be unsafe if the enum values are not continuous. This patch disable enum iteration with `llvm::seq` and `llvm::seq_inclusive` and adds two new functions: `enum_seq` and `enum_seq_inclusive`.

To make sure enum iteration is safe, we require users to declare their enum types as iterable by specializing `enum_iteration_traits<SomeEnum>`. Because it's not always possible to add these traits next to enum definition (e.g., for enums defined in external libraries), we provide an escape hatch to allow iteration on per-callsite basis by passing `force_iteration_on_noniterable_enum`.

The main benefit of this approach is that these global declarations via traits can appear just next to enum definitions, making easy to spot when enums are miss-labeled, e.g., after introducing new enum values, whereas `force_iteration_on_noniterable_enum` should stand out and be easy to grep for.

This emerged from a discussion with gchatelet@ about reusing llvm's `Sequence.h` in lieu of https://github.com/GPUOpen-Drivers/llpc/blob/dev/lgc/interface/lgc/EnumIterator.h.

Reviewed By: dblaikie, gchatelet, aaron.ballman

Differential Revision: https://reviews.llvm.org/D107378
2021-11-03 20:52:21 -04:00
Mehdi Amini 0986433401 Revert "Fix iterator_adaptor_base/enumerator_iter to allow composition of llvm::enumerate with llvm::make_filter_range"
This reverts commit ba7a6b314f.

Post-commit review showed that the fix implemented wasn't correct, and a
more principled fix is possible.
2021-11-04 00:14:12 +00:00
Mehdi Amini ba7a6b314f Fix iterator_adaptor_base/enumerator_iter to allow composition of llvm::enumerate with llvm::make_filter_range
* Properly specify reference type in enumerator_iter
* Fix constness of iterator_adaptor_base::operator*

Differential Revision: https://reviews.llvm.org/D112981
2021-11-02 22:49:43 +00:00
Michał Górny 66e06cc8cb [llvm] [ADT] Update llvm::Split() per Pavel Labath's suggestions
Optimize the iterator comparison logic to compare Current.data()
pointers.  Use std::tie for assignments from std::pair.  Replace
the custom class with a function returning iterator_range.

Differential Revision: https://reviews.llvm.org/D110535
2021-10-22 12:27:46 +02:00
YunQiang Su 302a165e18 [MIPS] Fix switching between 32/64-bit variants of r6 target triples
If clang driver gets 64-bit r6 target triple like `mipsisa64r6` and
additional option forces switching to generation of 32-bit code, it
loses r6 abi and generates 32-bit r2-r5 abi code.

```
$ clang -target mipsisa64r6-linux-gnu -mabi=32
```

This patch fixes the problem.

- Add optional `SubArchType` argument to the `Triple::setArch()` method.
- Implement generation of mips r6 target triples in the
  `Triple::getArchName()` method.

Differential Revision: https://reviews.llvm.org/D110514.diff
2021-10-21 15:04:07 +03:00