Commit Graph

62 Commits

Author SHA1 Message Date
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Evan Wilde
26a974e772 [NFC] Headers headers headers!
Including headers that were being transitively included from LLVM
before. Also pointing them at the new locations for some of them.
2023-07-17 10:55:55 -07:00
Evan Wilde
8ce6ee8dd1 Updating API usages
LLVM deprecated, renamed, and removed a bunch of APIs. This patch
contains a lot of the changes needed to deal with that.

The SetVector type changed the template parameters.

APInt updated multiple names, countPopulation became popcount,
getAllOnesValue became getAllOnes, getNullValue became getZero, etc...

Clang type nullability check stopped taking a clang AST context.

The LLVM IRGen Function type stopped exposing basic block list directly,
but gained enough API surface that the translation isn't too bad.
(GenControl.cpp, LLVMMergeFunctions.cpp)

llvm::Optional had a transform function. That was being used in a couple
of places, so I've added a new implementation under STLExtras that
transforms valid optionals, otherwise it returns nullopt.
2023-07-17 10:53:42 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Erik Eckstein
2ed2cea2b6 Use std::invoke_result instead of the deprecated std::result_of 2022-11-15 17:23:08 +01:00
John McCall
63db5457ce [NFC] Add a utility to add the elements of a pack to a vector
When we adopt C++17, we'll be able to do this with a fold expression,
but this will be useful in the meantime.
2022-03-27 14:11:20 -04:00
Robert Widmann
fe6dfbf458 Add an Implementation of std::erase_if for std::unordered_set. 2020-12-10 18:31:04 -08:00
John McCall
c02c2bc112 [NFC] Add an iterator template for walking singly-linked lists. 2020-10-01 02:34:53 -04:00
swift_jenkins
4af022eb5c Merge remote-tracking branch 'origin/master' into master-next 2020-05-18 14:19:30 -07:00
Saleem Abdulrasool
f0413f6170 build: remove last llvm:: reference in stdlib
This removes the last reference to the `llvm::` namespace in the
standard library.  All uses of the LLVMSupport library now are
namespaced into the `__swift::__runtime` namespace.  This allows us to
incrementally vend the LLVMSupport library and make the separation
explicit.
2020-05-18 11:41:57 -07:00
Saleem Abdulrasool
3fa1d1fe3f runtime: ingest LLVMSupport into the runtime
This adds a new copy of LLVMSupport into the runtime.  This is the final
step before changing the inline namespace for the runtime support.  This
will allow us to avoid the ODR violations from the header definitions of
LLVMSupport.

LLVMSupport forked at: 22492eead218ec91d349c8c50439880fbeacf2b7
Changes made to LLVMSupport from that revision:
  process.inc forward declares `_beginthreadex` due to compilation issues due to custom flag handling

API changes required that we alter the `Deallocate` routine to account
for the alignment.

This is a temporary state, meant to simplify the process.  We do not use
the entire LLVMSupport library and there is no value in keeping the
entire library.  Subsequent commits will prune the library to the needs
for the runtime.
2020-05-15 09:55:36 -07:00
Michael Forster
7b345931d5 Remove Swift's copy of llvm::interleave
This is only needed on the master branch, which doesn't have LLVM's
copy, yet.
2020-04-20 11:46:27 +02:00
Michael Forster
fae87c96d7 Move interleave(...) to the llvm namespace
This simplifies fixing the master-next build. Upstream LLVM already
has a copy of this function, so on master-next we only need to delete
the Swift copy, reducing the potential for merge conflicts.
2020-04-17 11:20:50 +02:00
Michael Gottesman
6759d82dad Revert "Revert "[pmo] Fix load [copy] like I fixed load_borrow.""
This reverts commit 2b8e266694.

That reapplies 7623367208.
2019-11-17 03:48:00 -08:00
Brent Royal-Gordon
2b8e266694 Revert "[pmo] Fix load [copy] like I fixed load_borrow." 2019-11-16 15:54:12 -08:00
Michael Gottesman
b8a1ecdb3f [stlextras] Add overloads for binary_search that take containers. 2019-11-15 15:16:58 -08:00
Michael Gottesman
d0219b6f7a [stlextras] Add overloads for binary_search that take containers. 2019-11-15 12:57:39 -08:00
Jordan Rose
7b0d081965 Remove IteratorRange in favor of llvm::iterator_range
Now that llvm::iterator_range has 'empty', there's not enough reason to
keep our own version of it in the Swift repo.

No functionality change.
2019-10-08 11:23:28 -07:00
Jordan Rose
262f6864c2 Remove unused swift::FilterIterator and swift::FilterRange
No functionality change ("unused")
2019-10-02 10:23:19 -07:00
Jordan Rose
8b8c88e258 Improve swift::TransformRange enough to delete TransformArrayRef
We have a lot of "transform a range" types already:
llvm::mapped_iterator, swift::TransformRange and
swift::TransformIterator, and swift::ArrayRefView for static
transformations. This gets rid of one more layer without losing
any real functionality.
2019-10-02 10:23:05 -07:00
Michael Gottesman
7b2fc076f7 [sil] Add new API ValueBase:getUsersOfType<T>().
For some time now we have had the API ValueBase::getSingleUserOfType<T>() but we
never implemented getUsersOfType<T>() using transform/filter iterators.

Since there wasn't a specific API, several incarnations of this API have been
created for BeginBorrow, LoadBorrow, BeginAccess.

In this commit, I introduce the API and use it to excise the redundant code in
those above mentioned 3 instructions.
2019-09-06 16:40:51 -07:00
Michael Gottesman
69f6000921 [opt-transform-range] Do not assume that Range::iterator exists.
The reason not to do this is that some important range
adapters (e.x. llvm::iterator_range) do not have such a typedef. Rather than
changing upstream this commit just fixes the problem by inferring the iterator
type from the result of Range::begin().

TLDR: This makes OptionalTransformRange work with llvm::iterator_range.
2019-09-05 19:52:20 -07:00
Michael Gottesman
9c58e4b0a3 [patternmatch] Add InstructionOperand_match to support for matching against instructions with misc number of operands.
NOTE:

1. To test this I changed UnaryOp_match to use this under the hood.

2. These types of m_##ID##Inst matchers now will only accept compound types and
I added a static assert to verify that this mistake doesn't happen. We
previously had matchers that would take an int or the like to match tuple
extract patterns. I converted those to use TupleExtractOperation that also
properly handles destructures.
2019-08-05 17:26:02 -07:00
Jordan Rose
844ae38722 Remove some Swift STLExtras that LLVM now provides (#26443)
No functionality change.
2019-07-31 18:34:52 -07:00
David Ungar
663760e3b7 ASTOOScope ontology 2019-05-28 10:48:22 -07:00
Jordan Rose
f6c7973911 Teach -verify-apply-fixes to handle overlapping fix-its (#23970)
...by coalescing duplicates and dropping conflicts. Both cases can
happen with "expected-error 2 {{...}}": we might get multiple fix-its
providing the same new message, or one message might have diverged
into two, giving us incompatible changes.
2019-04-12 13:19:54 -07:00
Jordan Rose
4bfe4eff6d [ParseableInterfaces] Add -prebuilt-module-cache-path to the frontend
When trying to load a swiftinterface, search this directory before
doing all the work of building a swiftmodule.
2018-12-17 18:23:28 -08:00
Sho Ikeda
9c3e4848bf [gardening][Basic] Replace typedef with using 2018-03-28 21:27:26 +09:00
Michael Gottesman
a05f4f6666 [stl-extras] Add a range version of std::accumulate. 2017-10-09 13:36:18 -07:00
Jordan Rose
9a04bee421 [ClangImporter] Turn ImportNameVersion into a struct.
...so that we don't have to keep coming back to update it every major
release. And also so we can actually put methods on it instead of
using free functions.

No intended behavior change (yet).
2017-09-15 14:30:24 -07:00
Michael Gottesman
7248221d40 [stl-extras] Provide next_or_default and prev_or_default helpers for iterators.
These work like next_or_end or prev_or_begin, except that instead of forcing the
default value to be the compared against the value, you can specify the value
used upon going out of range.

i.e., instead of:

(x, y) -> (x == y) ? y : std::next(x)

We have:

(x, y, z) -> (x == y) ? z : std::next(x)

This is a strict generalization of next_or_end and prev_or_begin so I
re-implemented both routines in terms of the new routines, so no source needed
to be updated.
2017-09-09 16:23:12 -07:00
Bob Wilson
b87f9d0d4e master-next: Change TransformIterator to work with bidirectional iterators.
The custom DFS implementation for dominators in LLVM r307727 uses a reverse
iterator and so fails to build if SILBasicBlocks do not support that.
2017-07-14 10:40:15 -07:00
Michael Gottesman
e11daa8ddf [upstream-update] Do not use succ_iterator in GraphTraits. Use succblock_iterator instead.
rdar://31790907
2017-04-26 16:50:57 -07:00
Michael Gottesman
aa76c2a5e6 [silgen] (mark_uninitialized (project_box (alloc_box))) -> (project_box (mark_uninitialized (alloc_box)))
I put in a simple fixup pass (MarkUninitializedFixup) for staging purposes. I
don't expect it to be in tree long. I just did not feel comfortable fixing up in
1 commit all of the passes up to DI.

rdar://31521023
2017-04-17 17:45:54 -07:00
Michael Gottesman
e34bbdf2fb [semantic-sil] Create a new higher level API for accessing the ownership checker. It is meant to be used by passes.
rdar://29870610
2017-04-05 14:34:21 -07:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.

Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.

Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
2017-01-26 15:35:48 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Michael Gottesman
6f3c1ee658 Add a new ArrayRefView like structure called TransformArrayRef.
The difference is that TransformArrayRef stores its function as an std::function
instead of using a template parameter. This is useful in situations where one
wants to define such a type in a header on forward declared pointers. If one had
to define the function to be used as a template parameter, one would have to
define the function or provide a forward declared version
2016-12-18 01:11:14 -08:00
Michael Gottesman
0bfda96ace [sil-func-extractor] Teach sil-extract to extract a list of functions and the inverse of a list of functions. Also rename to sil-func-extractor to make it clearer what it is doing.
This will allow for modules to be split from the command line using a script.

The one thing that is missing from this still is that it does not handle shared
functions in IMO a satisfactory way. Given that we are splitting a module, my
feeling that the correct way to do this is to create a public shim for the
shared function in the module that the shared function gets put in and let all
other users use that entry point.

But I need to think about this a bit more.
2016-12-08 18:29:33 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
practicalswift
566bfc0d56 [gardening] Fix typos. 2016-10-13 22:19:08 +02:00
Francis Ricci
66dcad0d34 SIL: Avoid dereferencing sentinel nodes in ilist_iterators
The behaviour of ilist has changed in LLVM.  It is no longer permissible to
dereference the `end()` value.  Add a check to ensure that we do not
accidentally dereference the iterator.
2016-10-12 11:46:31 -07:00
Dan Raviv
29d76f3b68 Canonize swift header files headers and footers
- Added missing ifdef guard in PointerIntEnum header
- Consistent naming convention for ifdef guards
- Consistent 'end namespace swift'
- Consistent single EOL at end of header files
2016-03-23 09:04:12 +02:00
Michael Gottesman
6434e5b032 Some small fixes suggested by Jordan to ImmutablePointerSet.
The larger changes are coming in a subsequent commit.
2016-02-16 02:13:55 -08:00
Michael Gottesman
f09749791a [arc] Move some code that is STL like from ImmutablePointerSet.h -> STLExtras.h
Specifically:

1. set_union_for_each. This is like std::for_each, but it visits its inputs
(which are assumed to be sorted/uniqued sets) in set_union order.
2. is_uniqued_and_sorted.

I also fixed several nits from Jordan.
2016-02-15 14:16:05 -08:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
Michael Gottesman
389238e801 Add support for multiple @_semantics attributes at the SIL level.
This is something that we have wanted for a long time and will enable us to
remove some hacks from the compiler (i.e. how we determine in the ARC optimizer
that we have "fatalError" like function) and also express new things like
"noarc".
2016-01-02 04:17:07 -06:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
fa0b339a21 Fix typos. 2015-12-26 17:51:59 +01:00