Commit Graph

136 Commits

Author SHA1 Message Date
Erik Eckstein
fc2ad09d4b Swift Bridging: use C++ instead of C bridging for BridgedSuccessor 2023-03-21 15:33:09 +01:00
Erik Eckstein
eecea088e7 Swift Bridging: use C++ instead of C bridging for BridgedOperand and BridgedValue 2023-03-21 15:33:09 +01:00
Erik Eckstein
318c30895f Swift Optimizer: eliminate ARC operations on types which are marked as immortal
A type (mostly classes) can be attributed with `@_semantics("arc.immortal")`.
ARC operations on values of such types are eliminated.

This is useful for the bridged SIL objects in the swift compiler sources.
2023-03-14 21:07:03 +01:00
Erik Eckstein
3fca8cd06e Swift SIL: speed up Operand.value
Instead of doing the type casts and/or conformance lookup on the swift side, do it on the C++ side.
It makes a significant performance difference because `Operand.value` is a time critical function
2023-03-14 21:07:03 +01:00
Erik Eckstein
40ed0fb388 Swift Optimizer: fix a crash when simplifying same-metatype comparisons of function types
The instance type of a metatype instruction is not necessarily a legal lowered SIL Type.
Lower the type before converting it to a SILType.

rdar://105502403
2023-02-15 21:14:32 +01:00
Erik Eckstein
cef6ef9a84 SIL: add a debug_step instruction
This instruction can be inserted by Onone optimizations as a replacement for deleted instructions to
ensure that it's possible to single step on its location.
2023-02-09 06:50:05 +01:00
Erik Eckstein
b1c6ae60cd Swift SIL: add metatype APIs to Type
* `var isMetatype: Bool`
* `var instanceTypeOfMetatype: Type`
2023-02-09 06:49:58 +01:00
Erik Eckstein
713f6c3946 Swift SIL: add Type.nominal and Type.isOrContainsObjectiveCClass APIs 2023-02-09 06:49:58 +01:00
John McCall
d25a8aec8b Add explicit lowering for value packs and pack expansions.
- SILPackType carries whether the elements are stored directly
  in the pack, which we're not currently using in the lowering,
  but it's probably something we'll want in the final ABI.
  Having this also makes it clear that we're doing the right
  thing with substitution and element lowering.  I also toyed
  with making this a scalar type, which made it necessary in
  various places, although eventually I pulled back to the
  design where we always use packs as addresses.

- Pack boundaries are a core ABI concept, so the lowering has
  to wrap parameter pack expansions up as packs.  There are huge
  unimplemented holes here where the abstraction pattern will
  need to tell us how many elements to gather into the pack,
  but a naive approach is good enough to get things off the
  ground.

- Pack conventions are related to the existing parameter and
  result conventions, but they're different on enough grounds
  that they deserve to be separated.
2023-01-29 03:29:06 -05:00
Erik Eckstein
d96ef3bedd Swift SIL: add some APIs to Location
* `var description`
* `func ==`
* `func hasSameSourceLocation(as:)`
2023-01-16 19:00:09 +01:00
Erik Eckstein
3f457eb1d4 Swift SIL: add IntegerLiteralInst.value 2023-01-16 19:00:09 +01:00
Erik Eckstein
221a16ba17 Swift SIL: add more arguments to Builder.createApply
add the `isNonThrowing` and `isNonAsync` flags and the `specializationInfo`
2023-01-16 19:00:09 +01:00
Erik Eckstein
cf8c68c6c4 Swift SIL: add Type.hasArchetype 2023-01-16 19:00:09 +01:00
Erik Eckstein
230c93df30 SIL Optimizer: add some SIL modification APIs
* `MutatingContext.notifyInvalidatedStackNesting` and `MutatingContext.needFixStackNesting`
* `MutatingContext.tryDeleteDeadClosure`
* `MutatingContext.erase(block:)`
* `Undef.get`
* `BasicBlock.moveAllInstructions`
* `BasicBlock.eraseAllArguments`
* `BasicBlock.moveAllArguments`
* `TermInst.replaceBranchTarget`
2023-01-16 19:00:09 +01:00
Erik Eckstein
a8ba48e71d Swift SIL: add Instruction.isDeleted API 2022-12-12 19:08:57 +01:00
Erik Eckstein
9e0b86ddbd Swift SIL: add Builder.createUnreachable() 2022-12-12 19:08:57 +01:00
Nate Chandler
8d8577e5b0 [SIL] Removed Indirect_In_Constant convention.
It is no different from @in.

Continue parse @in_constant in textual and serialized SIL, but just as
an alias for @in.
2022-12-09 21:54:00 -08:00
Egor Zhdan
a6372e955a Merge pull request #61618 from apple/egorzhdan/scs-reapply-enums
Revert "Revert "[cxx-interop][SwiftCompilerSources] Use C++ enums directly from Swift""
2022-10-20 15:46:17 +01:00
Erik Eckstein
173b698563 Swift SIL: add ApplySite.numIndirectResultArguments 2022-10-20 09:20:28 +02:00
Egor Zhdan
94ec683ba5 Revert "Revert "[cxx-interop][SwiftCompilerSources] Use C++ enums directly from Swift""
This reverts commit 69431f00
2022-10-18 18:55:57 +01:00
Nate Chandler
ca43d71769 [OpaqueValues] Fixed index of self argument.
Previously, SILFunction_getSelfArgumentIndex was directly using the
function type rather than interacting with the function convention.
Here, it is made to interact with the convention.
2022-10-14 17:11:01 -07:00
Erik Eckstein
4a60ea809b Add some Swift SIL infrastructure
* In `ApplySite`: `argumentOperands` and `isCalleeOperand`
* In `ArgumentConvention`: `isIndirect`, `isIndirectIn` and `isGuaranteed`
* In `Function`: `isDefinition`, `numParameterArguments`, `numArguments`, `getArgumentConvention`, `effectAttribute`
* In `Type`: `isFunction` and `isCalleeConsumedFunction`
* In `Instruction`: `hasUnspecifiedSideEffects`
* New bridged instructions: `EndApplyInst` and `AbortApplyInst`
* `LoadInst.ownership`
* `BeginAccessInst.isStatic`
* make the `Allocation` protocol a `SingleValueInstruction` (instead of `AnyObject`)
2022-10-05 07:37:41 +02:00
eeckstein
69431f00e8 Revert "[cxx-interop][SwiftCompilerSources] Use C++ enums directly from Swift" 2022-09-22 11:45:41 +02:00
Egor Zhdan
5f2a641513 [cxx-interop][SwiftCompilerSources] Use swift::SILWitnessTable::WitnessKind instead of `
SILWitnessTableEntryKind`

rdar://83361087
2022-09-20 12:03:48 +01:00
Egor Zhdan
3f1a30c52a [cxx-interop][SwiftCompilerSources] Use swift::SILAccessKind instead of BridgedAccessKind
rdar://83361087
2022-09-20 12:03:48 +01:00
Egor Zhdan
78cdf5eca6 [cxx-interop][SwiftCompilerSources] Use swift::BuiltinValueKind instead of BridgedBuiltinID
rdar://83361087
2022-09-20 12:03:48 +01:00
Egor Zhdan
710443ae6f [cxx-interop][SwiftCompilerSources] Use swift::SubstitutionMap instead of BridgedSubstitutionMap
rdar://83361087
2022-09-15 14:18:31 +01:00
Egor Zhdan
3dc584e948 [cxx-interop][SwiftCompilerSources] Use swift::SILDebugLocation instead of BridgedLocation
rdar://83361087
2022-09-15 11:36:29 +01:00
eeckstein
468b7b9486 Merge pull request #60994 from eeckstein/silnodes-def
SIL: no need for `BRIDGED_...` macros in SILNodes.def
2022-09-08 15:50:00 +02:00
Erik Eckstein
e790bf225c SIL: no need for BRIDGED_... macros in SILNodes.def
It's not needed to distinguish between bridged and not bridged node classes in SILNodes.def.
NFC.
2022-09-08 12:32:26 +02:00
Erik Eckstein
97b2354be6 SIL: add needsStackProtection flags for address_to_pointer and index_addr instructions.
Also add new "unprotected" variants of the `addressof` builtins:
* `Builtin.unprotectedAddressOf`
* `Builtin.unprotectedAddressOfBorrow`
2022-09-08 08:42:22 +02:00
Erik Eckstein
fdca208335 SIL: add the SILFunction.needsStackProtection flag
Indicates that stack protectors are inserted into this function to detect stack related buffer overflows.
2022-09-08 08:37:21 +02:00
Erik Eckstein
32af2dd5a4 Swift SIL: an autogenerated Location needs to keep the debug scope.
Therefore, instead of creating an autogenerated location with a null scope, make an existing location `autoGenerated`.
2022-09-02 08:56:38 +02:00
Erik Eckstein
082aec0990 Swift SIL: add var FunctionArgument.convention
Also:
* move the `ArgumentConvention` enum from Function.swift to Argument.swift.
* `FunctionArgument.isExclusiveIndirectParameter` -> `ArgumentConvention.isExclusiveIndirect`
* add `ArgumentConvention.isInout`
2022-09-02 07:11:49 +02:00
Erik Eckstein
f7aaa35092 Swift SIL: fix KeyPathInst.visitReferencedFunctions
It crashed for keypath instructions with zero components.
2022-08-26 18:00:11 +02:00
Erik Eckstein
f6e6b2ecf3 Swift SIL: add the possibility to pass a custom location to Builder initializers.
And add the static property `Location.autoGeneratedLocation`
2022-08-26 18:00:11 +02:00
Erik Eckstein
2745565a83 Swift SIL: correctly bridge "invalid" witness table entries.
Originally, I thought that couldn't appear in valid SIL, but there are "no_default" entries in default witness tables, which map to "invalid" entries.
2022-08-26 18:00:11 +02:00
Erik Eckstein
2fe1ee5533 Swift SIL: add a few Builder functions
* add `createAllocStack`
* add `createDeallocStack`
* add `createCopyAddr`
* add `@discardableResult` to the existing `createDeallocStackRef`
2022-08-24 17:55:02 +02:00
Erik Eckstein
bfb284f827 Swift SIL: add a few instructions and Instruction.visitReferencedFunctions
* add `DynamicFunctionRefInst` and `PreviousDynamicFunctionRefInst`
* add a common base class to all function-referencing instructions: `FunctionRefBaseInst`
* add `KeyPathInst`
* add `IndexAddrInst.base` and `IndexAddrInst.index` getters
* add `Instruction.visitReferencedFunctions` to visit all functions which are referenced by an instruction
2022-08-24 17:55:02 +02:00
Erik Eckstein
fbb694bcde Swift SIL: add bridging for witness and default witness tables 2022-08-24 17:55:02 +02:00
Erik Eckstein
7816513f0d Swift SIL: add bridging for vTables 2022-08-24 17:55:02 +02:00
Erik Eckstein
fe40707d5e Swift SIL: add Function.isPossiblyUsedExternally and Function.isAvailableExternally 2022-08-24 17:54:46 +02:00
Erik Eckstein
05d62293e6 Swift SIL: add NominalFieldsArray.getNameOfField(withIndex:) 2022-08-22 13:22:06 +02:00
Anxhelo Xhebraj
e748f01d90 Swift SIL: add constant checking for ref_element_addr field and global 2022-08-11 10:16:40 -07:00
Anxhelo Xhebraj
303ed781ff Swift SIL: add AccessKind to BeginAccess 2022-08-11 10:16:40 -07:00
Egor Zhdan
0e2d438c5b [cxx-interop][SwiftCompilerSources] Use llvm::StringRef instead of BridgedStringRef
rdar://83361000
2022-07-21 16:32:16 +01:00
Egor Zhdan
38edc7f377 [cxx-interop][SwiftCompilerSources] Remove getCopiedBridgedStringRef and freeBridgedStringRef
`std::string`s can now be passed directly between Swift and C++.

rdar://83361087
2022-07-06 12:57:50 +01:00
Erik Eckstein
a17ee435b6 Swift SIL: fix var ApplySite.arguments
In case of type-dependent operands, not all operands are part of the arguments
2022-06-08 22:51:57 +02:00
Erik Eckstein
f3adbd5c0e SIL: cache case indices in enum instructions.
As we do with field indices for struct instructions.
This avoids quadratic behavior in case of enums with lots of cases.
Also: cache field and enum case indices in the SILModule.
2022-05-16 09:33:14 -07:00
Erik Eckstein
a91d541a26 Swift SIL: add ApplySite.substitutionMap and ApplySite.getArgumentConvention() 2022-05-12 21:48:37 +02:00