Commit Graph

76 Commits

Author SHA1 Message Date
Kavon Farvardin
885b758a52 IRGen: throws prediction for non-SIL calls
Some calls to throwing functions aren't represented with `try_apply` in
SIL, so we generate llvm.expect's when throw prediction is enabled.
2024-08-08 21:21:52 -04:00
Nate Chandler
9562312c83 [IRGen] Add dynamic size variant of CreateMemCpy.
Similar to the existing variant which takes a fixed size, the new
variant which takes a dynamic size digs the relevant address and
alignment values out of the Address struct and passes them along.
2023-12-01 06:58:36 -08:00
Alex Lorenz
7d8ecfc506 [interop] trap on uncaught C++ destructor exceptions 2023-02-22 10:59:47 -08:00
Alex Lorenz
1dc0f019bf [interop] add initial support for trapping on uncaught exceptions when making a foreign call 2023-02-21 13:30:18 -08:00
John McCall
27142e42f6 Add SIL instructions to get and set pack elements 2023-02-07 01:10:15 -05: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
Arnold Schwaighofer
b939a59a8b Re-introduce an IRBuilder optimization that LLVM removed 2022-05-12 13:06:51 -07:00
Ben Barham
04035b43b7 [next] Temporarily use getPointerElementType
`PointerType::getElementType` has been removed entirely as part of the
opaque pointers migration. Update to `getPointerElementType` for now
until we've also migrated.
2022-05-05 16:25:10 -07:00
Michael Gottesman
5a90f5c9d8 [irgen] Implement irgen::IRBuilder::SavedInsertionPointRAII.
This is ported from the SavedInsertionPointRAII at the SIL level. I thought that
I needed this to accomplish some of my recent work, but I was wrong. Still
seemed useful enough to upstream it.
2022-02-17 22:32:01 -08:00
Arnold Schwaighofer
8f159cfb88 Fix some deprecated uses of IRBuilder API
rdar://84034998
2021-10-11 11:01:22 -07:00
Arnold Schwaighofer
5372afeb98 Adjust to MaybeAlign -> Align change in llvm::StoreInst api 2020-05-18 06:16:38 -07:00
Arnold Schwaighofer
0792b12eed Make sure we get a valid llvm::Align value 2020-05-15 06:54:53 -07:00
Arnold Schwaighofer
803414cea7 Adjust to MaybeAlign -> Align change in LoadInst api 2020-05-15 06:40:37 -07:00
Michael Forster
8d1d9f1eb5 Remove calls to deprecated IRBuilder APIs
These APIs have been removed in upstream LLVM, breaking master-next.
2020-04-17 09:32:03 +02:00
Dan Zheng
1779632a6f [IRGen] NFC: silence llvm::MaybeAlign warnings.
Use `llvm::MaybeAlign` instead of `unsigned` to silence slew of warnings.
2020-02-20 08:49:28 +00:00
Jonas Devlieghere
4db7f40686 Update for upstream intrinsics change (NFC)
The Intrinsic ID is now an opaque typedef to facilitate splitting up
the enum into target-specific enums.
2020-01-03 10:53:22 -08:00
Raphael Isemann
6ae6447239 Adapt calls to CreateMemSet to LLVM API change
In 1b2842bf902a8b52acbef2425120533b63be5ae3 this API was changed.
It seems the right thing to do is turn this into the new alignment
type by doing MaybeAlign(alignment) which is what this patch does.
2019-12-11 18:28:51 +01:00
Shoaib Meenai
e1daf39bb6 [IRGen] Adjust for LLVM r373054
Use a MaybeAlign in one more spot.
2019-10-04 12:47:43 -07:00
Shoaib Meenai
a007f646fb [IRGen] Adjust for LLVM r373054
setAlignment now takes a MaybeAlign, so construct one where needed.
2019-09-30 12:04:32 -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
Erik Eckstein
ffd7f75de3 IRGen: debug info generation for cond_fail messages.
To display a failure message in the debugger, create a function in the debug info which has the name of the failure message.
The debug location of the trap/cond_fail is then wrapped into this function and the function is declared as "inlined".
In case the debugger stops at the trap instruction, it displays the inline function, which looks like the failure message.
For example:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000100000cbf a.out`testit3(_:) [inlined] Unexpectedly found nil while unwrapping an Optional value at test.swift:14:11 [opt]
   11
   12   @inline(never)
   13   func testit(_ a: Int?) -> Int {
-> 14     return a!
   15   }
   16

This change is currently not enabled by default, but can be enabled with the option "-Xllvm -enable-trap-debug-info".
Enabling this feature needs some changes in lldb. When the lldb part is done, this option can be removed and the feature enabled by default.
2019-07-16 14:51:18 +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
e915300e96 IRGen: debug info generation for cond_fail messages.
To display a failure message in the debugger, create a function in the debug info which has the name of the failure message.
The debug location of the trap/cond_fail is then wrapped into this function and the function is declared as "inlined".
In case the debugger stops at the trap instruction, it displays the inline function, which looks like the failure message.
For example:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000100000cbf a.out`testit3(_:) [inlined] Unexpectedly found nil while unwrapping an Optional value at test.swift:14:11 [opt]
   11
   12   @inline(never)
   13   func testit(_ a: Int?) -> Int {
-> 14     return a!
   15   }
   16

This change is currently not enabled by default, but can be enabled with the option "-Xllvm -enable-trap-debug-info".
Enabling this feature needs some changes in lldb. When the lldb part is done, this option can be removed and the feature enabled by default.
2019-07-12 14:03:13 +02:00
Slava Pestov
22cea6cf54 IRGen: Remove IRBuilder::StableIP 2019-05-13 23:12:48 -04:00
Saleem Abdulrasool
2c91da5d88 lib: update for LLVM API change
TerminatorInst has been removed and been made into a regular Instruction.  Use
the `isTerminator` function instead of the dyn_cast.
2019-02-07 17:54:59 -08:00
Bob Wilson
27efdcb8ee master-next: use separate memcpy/memmove src/dest alignment arguments
LLVM r323617 changed the IRBuilder's CreateMemCpy and CreateMemMove
functions to take separate arguments for the destination and source
alignments.
2018-03-28 22:19:16 -07:00
Sho Ikeda
08644c1d8f [gardening][IRGen] Replace typedef with using 2018-03-27 09:06:33 +09:00
John McCall
14c0c39be2 Basic plumbing to propagate metadata-generation results in IRGen. 2018-03-26 01:13:45 -04:00
swift-ci
9e94284246 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-02-26 14:00:10 -08:00
Vedant Kumar
f64d88591e [IRGen] Prevent mergeable traps from being created
PR #14729 made more calls to llvm.trap() non-mergeable. This follow-up
adds asserts to IRBuilder which make it harder to accidentally introduce
mergeable calls to llvm.trap() in the future.

The newly-added assertions exposed an issue in GenBuiltin while
compiling parts of the stdlib. This PR fixes the issue.

Suggested by Adrian Prantl!

rdar://32772768
2018-02-26 13:44:52 -08:00
Bob Wilson
1b55b85e2b Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-01-09 16:12:10 -08:00
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05:00
swift-ci
07902f91aa Merge remote-tracking branch 'origin/master' into master-next 2017-12-18 23:09:18 -08:00
John McCall
1f3f33e67d Clean up the internal APIs around dynamic allocas to structurally
discourage accidental use of them.  Relatedly, fix several bugs
where we were accidentally using dynamic allocas.
2017-12-19 00:29:43 -05:00
John McCall
a5d328690d PointerLikeTypeTraits is now a struct, not a class.
We compile with a pedantic warning that complains about these things,
and the massive flood of warnings is actually causing problems for the
build infrastructure.
2017-08-17 17:01:17 -04:00
John McCall
a0f20f673d Switch all of the indirect-call code in IRGen to FunctionPointer.
To make this stick, I've disallowed direct use of that overload of
CreateCall.  I've left the Constant overloads available, but eventually
we might want to consider fixing those, too, just to get all of this
code out of the business of manually remembering to pass around
attributes and calling conventions.

The test changes reflect the fact that we weren't really setting
attributes consistently at all, in this case on value witnesses.
2017-07-28 23:26:35 -04:00
John McCall
750d397909 Substantially rework how IRGen handles function pointers.
The goals here are four-fold:
  - provide cleaner internal abstractions
  - avoid IR bloat from extra bitcasts
  - avoid recomputing function-type lowering information
  - allow more information to be propagated from the function
    access site (e.g. class_method) to the call site

Use this framework immediately for class and protocol methods.
2017-07-20 14:33:18 -04:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Joe Shajrawi
ee5ed7bdc6 [IRGen] Code Size Reduction: Outline Copy/Consume (Loadable) Enum 2016-12-22 17:08:15 -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
Adrian Prantl
995f9f4c1c Silence warning when building without assertions. 2016-06-29 11:28:00 -07:00
Adrian Prantl
022a8b1345 Fix a bug that prevented setting a DebugLoc if the first SILInstruction
in the function is setup code for a closure and re-enable the assertions
that caught this on the bots.

rdar://problem/26955467
2016-06-29 10:47:11 -07:00
Adrian Prantl
885ddfbab1 Temporarily remove this assertion while investigating buildbot fallout. 2016-06-28 13:59:41 -07:00
Adrian Prantl
935b702a07 Add an assertion to IRBuilder to prevent function calls with no debug location
It is not valid LLVM IR to have a function call without a location to an
inlinable function inside a function with debug info — this makes it impossible
to construct inline information.

This patch adds an assertion and fixes up several places across IRGen where
such a situation could happen.

rdar://problem/26955467
2016-06-27 19:04:51 -07:00
John McCall
a02573e088 Implement CoerceAndExpand in Swift. NFC for now, since only swiftcall
uses this and there's no way to round-trip a SILFunctionType as a
foreign type using swiftcall.
2016-04-05 19:34:48 -07:00
Roman Levenstein
ec04b22145 Properly propagate the calling convention into LLVM's call instructions.
Each runtime function definition in RuntimeFunctions.def states which calling convention
should be used for this runtime function.  But IRGen and LLVMPasses were not always
properly propagating this declared calling convention all the way down to llvm's Call instructions.
In many cases, the standard C convention was set for the call irrespective of the actual calling
convention defined for a given runtime function. As a result, incorrect code was generated.

This commit tries to fix all those places, where such a mismatch was found. In many cases this is
achieved by defining a helper function CreateCall in such a way that makes sure that the call instruction
gets the same calling convention as the one used by its callee operand.
2016-02-25 05:30:59 -08:00
John McCall
ad217fb5de Borrow IRBuilder::CreateElementBitCast from Clang. 2016-01-17 20:05:45 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Joe Groff
0991b2c5d8 IRGen: Factor out IRBuilder helpers for CreateLifetimeStart/End. 2015-12-25 12:24:56 -08:00