Commit Graph

166 Commits

Author SHA1 Message Date
Stephen Canon
3aa7b592b6 Implement Builtin.select binding llvm select instruction (#81598)
Not used (yet), but needed to implement SIMD.replacing(with:where:) idiomatically, and probably useful otherwise.
2025-05-20 13:30:59 -04:00
Anthony Latsis
0e6f3a8d54 Merge pull request #81375 from AnthonyLatsis/nocapture-both-ways
[test] Match `nocapture` to succeed both on main and rebranch
2025-05-09 14:37:32 +01:00
Anthony Latsis
55e5618eab [test] Match nocapture to succeed both on main and rebranch
Both the syntax and relative order of the LLVM `nocapture` parameter
attribute changed upstream in 29441e4f5fa5f5c7709f7cf180815ba97f611297.
To reduce conflicts with rebranch, adjust FileCheck patterns to expect
both syntaxes and orders anywhere the presence of the attribute is not
critical to the test. These changes are temporary and will be cleaned
up once rebranch is merged into main.
2025-05-08 23:52:43 +01:00
Dario Rexin
058638ee90 Merge pull request #81339 from drexin/wip-150722907
[IRGen] Emit llvm fneg operation for Builtin.fneg_*
2025-05-08 13:48:43 -07:00
Dario Rexin
877a98f8ef [IRGen] Emit llvm fneg operation for Builtin.fneg_*
rdar://150722907

The original handling was a workaround before LLVM added the fneg operation. Now that it has it, we should use it.
2025-05-06 10:27:30 -07:00
Anthony Latsis
17fc00f8a7 [test] IRGen: Adjust FileCheck patterns for new nuw attribute in upstream LLVM
This attribute was introduced in
7eca38ce76d5d1915f4ab7e665964062c0b37697 (llvm-project).

Match it using a wildcard regex, since it is not relevant to these
tests.

This is intended to reduce future conflicts with rebranch.
2025-05-04 03:28:56 +01:00
Erik Eckstein
af5ac6d283 Re-instate the allocVector builtin
Although it's not used anymore we still have to support it to be able to read old Swift.interface files which still contain the builtin.

rdar://144781646
2025-02-13 17:55:27 +01:00
Meghana Gupta
b7c4ef44e0 Update some test configs where stdlib is loaded later 2024-11-12 12:05:19 -08:00
Alejandro Alonso
48ec9c6360 Optimize Builtin.destroyArray when count is 1 statically 2024-03-27 14:00:22 -07:00
Alejandro Alonso
49b0a23561 Add getEnumTag and injectEnumTag builtins 2023-12-11 10:58:29 -08:00
Alex Lorenz
4858cb6225 [IRGen][interop] do not add 'nocapture' to not bitwise takable types
The use of 'nocapture' for parameters and return values is incorrect for C++ types, as they can actually capture a pointer into its own value (e.g. std::string in libstdc++)

rdar://115062687
2023-09-25 17:43:34 -07:00
Andrew Trick
da52e752c0 Update IRGen test for opaque pointers 2023-06-23 06:57:38 -07:00
Arnold Schwaighofer
c1a93e0bde Move tests over to use the %use_no_opaque_pointers option 2023-06-14 10:49:48 -07:00
Erik Eckstein
f5a0519289 fix Builtin.sizeof et al for metatypes
Those builtins always need to assume a thick metatype which is a pointer.
In other words the builtins need to use the maximally abstracted type.

rdar://108308786
2023-04-21 21:08:49 +02:00
Arnold Schwaighofer
d810b0f7e4 IRGen: Pass the elementType of pointers through to operations
In preparation for moving to llvm's opaque pointer representation
replace getPointerElementType and CreateCall/CreateLoad/Store uses that
dependent on the address operand's pointer element type.

This means an `Address` carries the element type and we use
`FunctionPointer` in more places or read the function type off the
`llvm::Function`.
2022-10-03 15:27:12 -07:00
Michael Gottesman
3e52007562 [builtin] Remove "unsafeGuaranteed" and related code since Unmanaged now has an Ownership SSA based implementation that works completely in SILGen.
This isn't used in the stdlib anymore as well.
2022-08-21 01:22:36 -07:00
Kuba (Brecka) Mracek
5d1ddbf33c Fix the signature of Builtin.Once() to take callback with an argument, to match swift_once() (#41353) 2022-02-12 11:18:11 -08:00
Andrew Trick
370a4eaee2 SILGen Builtin.loadRaw with alignment=1
This adds compiler support for misaligned raw pointer access. A Swift
Evolution proposal is required before users can take advantage of
this.
2021-11-30 12:23:46 -08:00
Min-Yih Hsu
e1023bc323 [DebugInfo] PATCH 2/3: Duplicate logics regarding debug_value_addr
This patch replace all in-memory objects of DebugValueAddrInst with
DebugValueInst + op_deref, and duplicates logics that handles
DebugValueAddrInst with the latter. All related check in the tests
have been updated as well.

Note that this patch neither remove the DebugValueAddrInst class nor
remove `debug_value_addr` syntax in the test inputs.
2021-08-31 11:57:56 -07:00
Alastair Houghton
abec55f432 [Runtime] Add ObjC support to isKnownUniquelyReferenced.
Add code to support detecting uniquely referenced Objective-C and Core
Foundation objects.

rdar://47902425
rdar://66805490
2021-07-29 16:29:48 +01:00
Stephen Canon
511b50e511 Implement shufflevector builtin. (#36650)
This isn't _terribly_ useful as-is, because the only constant mask you can get at from Swift at present is the zeroinitializer, but even that is quite useful for optimizing the repeating: intializer on SIMD. At some future point we should wire up generating constant masks for the .even, .odd, .high and .low properties (and also eventually make shufflevector take non-constant masks in LLVM). But this is enough to be useful, so let's get it in.
2021-04-04 23:23:53 -04:00
Stephen Canon
9ddbd56d32 Simd random mask benchmark (#36579)
* Add benchmark for SIMDMask.random generation.

* Add bitcast for IntN -> VecNxInt1
2021-03-25 08:54:40 -04:00
Mike Ash
bd62fdb2db [Concurrency] Make Job/AsyncTask minimally compatible with dispatch object layout
Create a TargetDispatchClassMetadata for Swift metadata that also has a dispatch-compatible vtable. Dispatch leaves room for ObjC class metadata so the two regions don't overlap. (The vtable currently consists of a single dummy entry; this will be filled out later.)

Rearrange the Job and AsyncTask hierarchy so that AsyncTask inherits only from Job, which in turn inherits from HeapObject. This gives all Job instances a dispatch-compatible isa field. It also gives them a refcount word, which is wasted on instances that aren't AsyncTask instances. Maybe we can find some use for that space in the future.

rdar://75227953
2021-03-10 10:04:30 -05:00
Stephen Canon
8b34d8bfb8 Allow Builtin.bitcast to do VecNxInt1 -> IntN (#36252)
This is necessary to support the idiom for movmsk operations on x86.
2021-03-03 16:02:09 -05:00
Stephen Canon
cd9887e24a Implement decodeImmediate for VecElementArguments (#36243)
This simply hadn't been wired up yet, which prevented us from being able to use certain intrinsics from the Builtin module (like vector_reduce_smin and friends).
2021-03-03 11:13:25 -05:00
John McCall
b22407ef0c Add a builtin to convert a Task* to a Job*. 2020-12-10 17:06:14 -05:00
Augusto Noronha
89fab1b06b Allow the creation of a shadow variable when the type is a refcounted pointer (#34835) 2020-11-30 09:07:23 -08:00
Arnold Schwaighofer
9b29ec6b98 IRGen: Store scalars as bytes to avoid undefined bits
Don't tempt llvm to misbehave on partially initialized bytes -- it will.

rdar:///66701259
2020-08-14 11:44:04 -07:00
Erik Eckstein
8f2632939a Builtins to support copy-on-write SIL instructions
* Builtin.COWBufferForReading -> ref_element_addr [immutable] / ref_tail_addr [immutable]
* Builtin.beginCOWmutation -> begin_cow_mutation
* Builtin.endCOWmutation -> end_cow_mutation
2020-05-14 08:39:54 +02:00
Xi Ge
64c0680686 Merge remote-tracking branch 'apple/master' into master-next 2019-10-28 10:19:36 -07:00
Joe Groff
4d5bf2770b IRGen: Hint condfail branches.
Mark the condfail condition as expected-false, and arrange the generated code so that the trap
basic block is emitted out-of-line, and the happy path falls through.
2019-10-16 10:21:22 -07:00
Harlan Haskins
d4247942c4 Merge remote-tracking branch 'upstream/master' into master-next 2019-09-26 20:19:25 -07:00
Harlan Haskins
e349b7b123 Merge branch 'master' into master-rebranch 2019-09-26 20:16:05 -07:00
Jordan Rose
a6dd630ca3 Eliminate Builtin.UnknownObject as an AST type (#27378)
This removes it from the AST and largely replaces it with AnyObject
at the SIL and IRGen layers. Some notes:

- Reflection still uses the notion of "unknown object" to mean an
  object with unknown refcounting. There's no real reason to make
  this different from AnyObject (an existential containing a
  single object with unknown refcounting), but this way nothing
  changes for clients of Reflection, and it's consistent with how
  native objects are represented.

- The value witness table and reflection descriptor for AnyObject
  use the mangling "BO" instead of "yXl".

- The demangler and remangler continue to support "BO" because it's
  still in use as a type encoding, even if it's not an AST-level
  Type anymore.

- Type-based alias analysis for Builtin.UnknownObject was incorrect,
  so it's a good thing we weren't using it.

- Same with enum layout. (This one assumed UnknownObject never
  referred to an Objective-C tagged pointer. That certainly wasn't how
  we were using it!)
2019-09-26 17:48:04 -07:00
Arnold Schwaighofer
9ee12db2a9 Fix tests for LLVM change that added anonymous parameter labeling
Fix for r367755.
2019-08-15 14:57:24 -07:00
Brent Royal-Gordon
fb20b503ba Merge branch 'master' into master-rebranch
# Conflicts:
#	lib/ClangImporter/ClangImporter.cpp
#	test/IRGen/builtins.swift
#	test/IRGen/enum.sil
#	tools/driver/autolink_extract_main.cpp
#	utils/build-presets.ini
2019-08-08 17:07:59 -07:00
Joe Groff
c0a9fef3cf Merge remote-tracking branch 'origin/master' into master-next 2019-08-05 10:38:17 -07:00
Joe Groff
f0e5e1911d IRGen: Access concrete type metadata by mangled name.
When we generate code that asks for complete metadata for a fully concrete specific type that
doesn't have trivial metadata access, like `(Int, String)` or `[String: [Any]]`,
generate a cache variable that points to a mangled name, and use a common accessor function
that turns that cache variable into a pointer to the instantiated metadata. This saves a bunch
of code size, and should have minimal runtime impact, since the demangling of any string only
has to happen once.

This mostly just works, though it exposed a couple of issues:

- Mangling a type ref including objc protocols didn't cause the objc protocol record to get
  instantiated. Fixed as part of this patch.
- The runtime type demangler doesn't correctly handle retroactive conformances. If there are
  multiple retroactive conformances in a process at runtime, then even though the mangled string
  refers to a specific conformance, the runtime still just picks one without listening to the
  mangler. This is left to fix later, rdar://problem/53828345.

There is some more follow-up work that we can do to further improve the gains:

- We could improve the runtime-provided entry points, adding versions that don't require size
  to be cached, and which can handle arbitrary metadata requests. This would allow for mangled
  names to also be used for incomplete metadata accesses and improve code size of some generic
  type accessors. However, we'd only be able to take advantage of the new entry points in
  OSes that ship a new runtime.
- We could choose to always symbolic reference all type references, which would generally reduce
  the size of mangled strings, as well as make runtime demangling more efficient, since it wouldn't
  need to hit the runtime caches. This would however require that we be able to handle symbolic
  references across files in the MetadataReader in order to avoid regressing remote mirror
  functionality.
2019-08-02 14:28:53 -07:00
Joe Groff
d38a72c4ad Merge branch 'master' into master-next 2019-07-18 13:14:39 -07:00
Erik Eckstein
117b1dafe6 Rename the two-parameter Builtin.condfail(c, message) to Builtin.condfail_message(c, message)
This is necessary to also support the old single paramter Builtin.condfail(c)
2019-07-17 17:41:59 +02:00
Erik Eckstein
b40ce6b34f SIL: add a failure message operand to Builtin.condfail
The SIL generation for this builtin also changes: instead of generating the cond_fail instructions upfront, let the optimizer generate it, if the operand is a static string literal.
In worst case, if the second operand is not a static string literal, the Builtin.condfail is lowered at the end of the optimization pipeline with a default message: "unknown program error".
2019-07-16 14:44:09 +02:00
Brent Royal-Gordon
d5a2912a26 Revert "Better runtime failure messages (not yet enabled by default)" 2019-07-15 13:42:40 -07:00
Erik Eckstein
3fd7eea96c SIL: add a failure message operand to Builtin.condfail
The SIL generation for this builtin also changes: instead of generating the cond_fail instructions upfront, let the optimizer generate it, if the operand is a static string literal.
In worst case, if the second operand is not a static string literal, the Builtin.condfail is lowered at the end of the optimization pipeline with a default message: "unknown program error".
2019-07-12 14:03:13 +02:00
swift-ci
f1cdb876a4 Merge remote-tracking branch 'origin/master' into master-next 2019-07-03 19:49:53 -07:00
Ravi Kandhadai
7a3c6d58f5 [stdlib][oslog] Create an SPI _globalStringTablePointer that exposes
the builtin.globalStringTablePointer to the new OSLog overlay.

Modify the new OSLog implementation to use this SPI instead of
`withCString` to pass the (compiler-generated) format string to
the C os_log_impl ABI.

Move the OSLogOptimization pass before constant propagation in
the pass pipeline so that the SPI and the builtin it uses can be
folded to a string_literal instruction.

Update OSLogTests to work with the changes in the implementation.
2019-07-03 17:25:37 -07:00
Ravi Kandhadai
5430aa0b17 [Builtin][SILGen][IRGen] Create a new builtin "globalStringTablePointer":
String -> Builtin.RawPointer that given a string constructed from a
literal, returns the address of the string literal in the global string
table of the compiled binary as a pointer.
2019-07-03 16:47:34 -07:00
Bob Wilson
e4cc933f70 master-next: adjust test output for change in LLVM block syntax
LLVM r356789 changed the format of textual IR to print nameless
blocks with labels instead of comments with "; <label>". Adjust Swift
tests to match. I also updated the utils/viewcfg script to match.
2019-03-29 18:19:26 -07:00
Michael Gottesman
fd4828e40a Eliminate -assume-parsing-unqualified-ownership-sil from tests.
I am doing this separately from the actual change to eliminate the option to
make it easier to review.
2018-12-19 12:54:13 -08:00
John McCall
2ba7090fe8 Remove the extra-inhabitant value witness functions.
This is essentially a long-belated follow-up to Arnold's #12606.
The key observation here is that the enum-tag-single-payload witnesses
are strictly more powerful than the XI witnesses: you can simulate
the XI witnesses by using an extra case count that's <= the XI count.
Of course the result is less efficient than the XI witnesses, but
that's less important than overall code size, and we can work on
fast-paths for that.

The extra inhabitant count is stored in a 32-bit field (always present)
following the ValueWitnessFlags, which now occupy a fixed 32 bits.
This inflates non-XI VWTs on 32-bit targets by a word, but the net effect
on XI VWTs is to shrink them by two words, which is likely to be the
more important change.  Also, being able to access the XI count directly
should be a nice win.
2018-12-11 22:18:44 -05:00
Arnold Schwaighofer
0463ba3f88 Add the Swift equivalent of the llvm.assume intrinsic
rdar://44947459
2018-10-04 13:08:26 -07:00