Commit Graph

655 Commits

Author SHA1 Message Date
Erik Eckstein
e4e5484ab4 LLVM-Passes: add pointer authentication to Swift's function merge pass.
If during merging a function pointer is passed as a parameter to the merged function, it needs to be signed on arm64e.

rdar://problem/66797689
2020-09-23 16:25:17 +02:00
swift_jenkins
75c4b09f51 Merge remote-tracking branch 'origin/master' into master-next 2020-09-15 15:41:58 -07:00
Hamish Knight
088a86eccb Introduce SymbolObjectCodeRequest
Add SymbolObjectCodeRequest, which emits object
code for a specific set of symbols by querying
TBDGen for the source of the symbols, and asking
SILGen (and eventually IRGen) to emit them.
2020-09-15 19:20:11 +01:00
Hamish Knight
44a8b56168 Rename getFiles to getFilesToEmit
Rename the member on ASTLoweringDescriptor and
IRGenDescriptor to make it more explicit it returns
the files that need emitting, rather than just the
files that happen to be present. This distinction
will become important once we start emitting code
only for a specific set of symbols.
2020-09-15 19:20:10 +01:00
Hamish Knight
add22194fd [SILGen] Allow lazy type-checking
Remove the type-checking call from
OptimizedIRRequest, and sink it down into SILGen
and IRGen when we come to emit the source files.
2020-09-15 19:20:10 +01:00
swift_jenkins
59f861034d Merge remote-tracking branch 'origin/master' into master-next 2020-09-11 05:35:11 -07:00
Erik Eckstein
56c857afa9 SIL: Check for leaked instructions in the SILVerifier and in the SILModule destructor. 2020-09-11 11:09:30 +02:00
David Zarzycki
00f4700496 Handle expanded enums in upstream LLVM (ZOS and GOFF) 2020-08-12 09:05:38 -04:00
Hamish Knight
9f47a284be Merge pull request #33159 from hamishknight/back-to-the-future
Introduce LoweredSILRequest
2020-07-28 21:30:42 -07:00
Hamish Knight
a99f8e9d9c Introduce LoweredSILRequest
Add a request that produces lowered SIL for a file
or module and use it in IRGenRequest if no
SILModule is provided.
2020-07-28 10:37:37 -07:00
Saleem Abdulrasool
8e86d0fbbd IRGen: always execute the coroutine lowering pass
Do not gate the coroutine extension points on the LLVM passes. Without
running this pass, the generated IR cannot be used by the LLVM tooling.
This allows generating the LLVM IR to debug issues in the LLVM backend.

I encountered this when trying to isolate a debug info generation bug
which seems to be caused by the SRoA pass in LLVM. By allowing to emit
the LLVM IR without the LLVM optimizations, it is possible to isolate
the LLVM pass operation via `opt` from LLVM.
2020-07-27 23:17:30 +00:00
Robert Widmann
638977454b Remove SharedTimer Infrastructure
Teach the UnifiedStatsReporter to directly construct
llvm::NamedRegionTimer for itself.
2020-07-16 17:35:50 -07:00
Hamish Knight
485d5e9bb4 [IRGen] Introduce OptimizedIRRequest
Introduce a request that wraps the entire compiler
pipeline and returns the optimized IR for a
whole-module or file.
2020-07-15 16:46:42 -07:00
Hamish Knight
d05bfa09d6 [IRGen] Lift call to performLLVM out of IRGenRequest
Remove the side-effecting call from IRGenRequest,
instead requiring callers to handle the optimization
and emission of the LLVM module.
2020-07-15 16:46:42 -07:00
Hamish Knight
408b6fcf3f [IRGen] Factor out compileAndWriteLLVM
Factor out the logic that deals with the LLVM
passes for compiling and emitting the module.
2020-07-15 16:46:42 -07:00
Hamish Knight
53ef0a2312 [IRGen] Move ObjCARCContractPass into performLLVMOptimizations
This seems like something we want to always do, not
just when emitting the LLVM module.
2020-07-15 16:46:41 -07:00
Hamish Knight
f9d70661dd [IRGen] Hash compiler version instead of lang version
The LLVM passes we apply don't depend on the language
version, only the compiler version.
2020-07-15 16:46:41 -07:00
Hamish Knight
45f11c8615 [IRGen] Allow IRGenDescriptor to hold a FileUnit
This will allow it to better interact with the
SILGen descriptor.
2020-07-15 16:46:41 -07:00
Hamish Knight
db7fea4665 Sink linker directive computation into IRGen
With an inverted pipeline, IRGen needs to be able
to compute the linker directives itself, so sink
it down such that it can be computed by the
`IRGenDescriptor`.
2020-07-13 20:42:54 -07:00
Hamish Knight
24dc744ca5 Have performParallelIRGeneration take an IRGenDescriptor 2020-07-13 20:42:53 -07:00
nate-chandler
69ff5be8ca Merge pull request #32791 from nate-chandler/generic-metadata-prespecialization-components/consider-conformances-ptrauth
[metadata prespecialization] Ptrauth for compared protocol conformances.
2020-07-09 16:10:02 -07:00
Nate Chandler
2701a0809b [metadata prespecialization] Ptrauth for compared protocol conformances.
Two protocol conformance descriptors are passed to
swift_compareProtocolConformanceDecriptors from generic metadata
accessors when there is a canonical prespecialization and one of the
generic arguments has a protocol requirement.

Previously, the descriptors were incorrectly being passed without
ptrauth processing: one from the witness table in the arguments that are
passed in to the accessor and one known statically.

Here, the descriptor in the witness table is authed using the
ProtocolConformanceDescriptor schema.  Then, both descriptors are signed
using the ProtocolConformanceDescriptorsAsArguments schema.  Finally, in
the runtime function, the descriptors are authed.
2020-07-09 11:45:16 -07:00
Yuta Saito
20bc0af42b [LTO] Support LLVM LTO for IRGen and frontend
This commit adds -lto flag for frontend to enable LTO at LLVM level.
When -lto=llvm given, compiler emits LLVM bitcode file instead of object
file and adds index summary for LTO.
In addition for ELF format, emit llvm.dependent-libraries section to
embed auto linking information
2020-07-01 23:30:58 +00:00
Hamish Knight
bf2f4af827 NFC: Move NumThreads from SILOptions to IRGenOptions
The option is only needed for IRGen.
2020-07-01 09:43:52 -07:00
Hamish Knight
c65246f74f Merge the IRGen requests
Similar to SILGen, merge `IRGenSourceFileRequest`
and `IRGenWholeModuleRequest` into a single
`IRGenRequest`.
2020-07-01 09:43:51 -07:00
Hamish Knight
fa715820a9 [IRGen] Assert the SourceFile has been type-checked 2020-07-01 09:43:51 -07:00
pi1024e
233ce8e034 Make numThreads variable unsigned and remove unneeded numThreads parameter 2020-06-24 17:35:59 -07:00
Adrian Prantl
f20d567633 Fix the hardcoded Swift AST section / segment name for Mach-O
to match the one specified in LLVM's Mach-O parser.
Otherwise LLDB could not possibly find it!

This name is used by the swift -modulewrap subcommand, which is currently unused
on Darwin, and primarily intended for use under Linux. However, it may be useful
to better support static archives (.a) files with Swift debug info in the
future. To fully support this, dsymutil and LLDB need to know to look for Swift
AST sections in Mach-O objects other than .dSYM bundled.

Implementation note: It would be nice to get the section name out of libObject,
but with the current architecture this needs a major refactoring that didn't
seem justified, given that there is an end-to-end test to prevent such a mishap
in the future.

<rdar://problem/63991514>
2020-06-12 18:01:24 -07:00
Saleem Abdulrasool
71309a8fa9 Revert "[LTO] Support LLVM level link time optimization on Darwin, Linux and Windows" 2020-06-07 11:25:48 -07:00
Saleem Abdulrasool
d0131ba6be Merge pull request #31146 from kateinoigakukun/katei/enable-lang-agnostic-lto
[LTO] Support LLVM level link time optimization on Darwin, Linux and Windows
2020-06-05 11:38:09 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Yuta Saito
915c4a6997 [LTO] Support LLVM level link time optimization
This commit adds -lto flag for driver to enable LTO at LLVM level.
When -lto=llvm given, compiler emits LLVM bitcode file instead of object
file and perform thin LTO using libLTO.dylib plugin.
When -lto=llvm-full given, perform full LTO instead of thin LTO.
2020-05-31 08:12:52 +09:00
Slava Pestov
8e35609df2 IRGen: Sign the class stub initialization callback pointer on arm64e
The Objective-C runtime expects a signed pointer here. The existing test
would have caught this, except it was always disabled because the
symbol name passed to the dlsym() check should not have had the leading
'_'.

Fixes <rdar://problem/57679510>.
2020-05-01 21:55:11 -04:00
Robert Widmann
bc0ccad160 [NFC] Dump DEBUG_VERIFY_GENERATED_CODE
rdar://54708850
2020-04-23 11:18:09 -07:00
Robert Widmann
db845eb6b3 Correct the ownership model for sil-opt
Destroying the SIL remark streamer after transferring ownership to LLVM
is frought. For one, the streamer holds the remark file's stream open.
Destroying it early doesn't accomodate sil-opt, which transfers control
to LLVM before running passes that emit remarks.

Instead, just take a reference to the context that the streamer gets
parented onto. If the remarks streamer infrastructure could just hold
the file stream open for us, we wouldn't have to do any of this.
2020-04-21 13:30:56 -07:00
Robert Widmann
90d05c10fa Lazily Associated a SILRemarkStreamer with an LLVMContext at IRGen time
Corrects a mistake introduced in #31106

I was under the impression that the LLVMContext for an instance of
llvm::remarks::RemarkStreamer was somehow just scratch-space. It turns
out the ASMPrinters don't gather remarks data from modules, they gather
it from the remark streamer associated with the module's context.

Thus, we cannot have the module's context be distinct from whatever
context the streamer is eventually associated with.

In order to bring these two systems back into harmony, introduce a simple
ownership contract to SILRemarkStreamer. That is, it starts owned by
a SILModule, in which case the SILRemarkStreamer holds onto the
underlying LLVM object as the optimizer emits remarks. When it comes
time to IRGen the module, then and only then do we install the streamer
on the module's context. This tranfers ownership of the underlying LLVM
streamer to LLVM itself, so it acts as a consuming operation. When we
are about to perform IR Generation, the SILModule will be expiring
anyways, so the streamer was already about to be destroyed.

We're just putting it to better use doing its job.
2020-04-20 17:55:20 -07:00
Dan Zheng
d28cf1cf55 [IRGen] Fix SynthesizedFileUnit. (#31082)
SynthesizedFileUnits are attached to a SourceFile.

Make IRGen consistent with TBDGen: when processing a SourceFile, only process
the attached SynthesizedFile. This avoids IRGen/TBDGen inconsistencies.

Use SourceFile name in SynthesizedFileUnit::getDiscriminatorForPrivateValue.

Resolves TF-1249.
2020-04-17 15:49:36 -07:00
Robert Widmann
de304b5bee [NFC] Introduce GeneratedModule
swift::GeneratedModule encapsulates an llvm::Module, llvm::LLVMContext
pair that must live and die together. It has  convenient accessors for
projecting the module and context components. The meat of this type is
the two conversion functions, which transfer ownership of either the
module component to the caller or the module and context to ORCJIT.

This is because ORC enforces an ownership contract that is distinct from
LLVM's rather wild ownership story for modules and their associated
contexts. See http://llvm.org/docs/ORCv2.html#how-to-use-threadsafemodule-and-threadsafecontext
2020-04-16 11:57:44 -07:00
Robert Widmann
6601c30646 [Gardening] Const-Qualify Some llvm::Module References 2020-04-16 11:57:44 -07:00
David Ungar
9dcd2b52b2 Allocate LLVMContext in IRGenModule. 2020-04-16 11:57:44 -07:00
Doug Gregor
548e28170a [Driver/Frontend] Thread the target SDK version through to the IR.
Teach the driver to pass the SDK version it computes (from the SDK
settings JSON in a Darwin-based platform's SDK) down into the frontend.
The frontend then sets that SDK version in the LLVM module, which
eventually makes its way into the Mach-O file.

Last part of rdar://problem/60332732.
2020-04-15 21:42:28 -07:00
Dan Zheng
f7a9eed4de [AutoDiff] Add generated implicit declarations to SynthesizedFileUnit.
Add implicit declarations generated by the differentiation transform to a
`SynthesizedFileUnit` instead of an ad-hoc pre-existing `SourceFile`.

Resolves TF-1232: type reconstruction for AutoDiff-generated declarations.

Previously, type reconstruction failed because retroactively adding declarations
to a `SourceFile` did not update name lookup caches.
2020-04-07 18:29:34 -07:00
Dan Zheng
c834696bfa Add SynthesizedFileUnit.
`SynthesizedFileUnit` is a container for synthesized declarations. Currently, it
only supports module-level declarations.

It is used by the SIL differentiation transform, which generates implicit struct
and enum declarations.
2020-04-07 18:29:26 -07:00
Nate Chandler
6c178c7c62 [prespecialized metadata] Require same file without wmo.
Without whole module optimization, the metadata accessors are emitted on
a per-file basis.  The result is that if the file containing a generic
type is processed before the file containing a usage of that type that
would result in that prespecialization, the metadata accessor would have
already been emitted by the time that the usage is noted, making it
impossible for the newly created prespecialization to be returned from
the already-emitted metadata accessor.

Here, require that either whole module optimization is enabled so that
the metadata accessors are all emitted at once at the end, or else that
the usage of the prespecialization is in the same file as the type is
declared.
2020-04-03 15:37:36 -07:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07:00
Robert Widmann
52f4aba784 IRGen Requests
Implement the IRGen Request infrastructure and provide the first
request: generating IR from a given SourceFile.
2020-03-16 18:00:33 -07:00
John McCall
2d25b6603e More descriptive names and comments; NFC. 2020-03-12 22:03:42 -04:00
Kuba (Brecka) Mracek
0d400ca310 Merge branch 'master' into mracek/arm64e 2020-03-04 09:36:25 -08:00
Hamish Knight
e9a7427712 [SILOptimizer] Add pipeline execution request (#29552)
[SILOptimizer] Add pipeline execution request
2020-03-03 20:24:28 -08:00
Kuba (Brecka) Mracek
5d918e5ee1 Merge branch 'master' into mracek/arm64e 2020-03-03 08:28:01 -08:00