Commit Graph

169 Commits

Author SHA1 Message Date
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
David Ungar
9dcd2b52b2 Allocate LLVMContext in IRGenModule. 2020-04-16 11:57:44 -07:00
Lang Hames
995c1c986f Merge remote-tracking branch 'upstream/master' into fix-imm-static-inits-merge 2020-03-13 18:36:32 -07:00
Lang Hames
2c083d8d2b [Immediate] Fix static constructor/destructor calls in RunImmediately.
Removes a redundant call to LLJIT::runConstructors and adds a call to
LLJIT::runDestructors.
2020-03-13 14:44:32 -07:00
Brent Royal-Gordon
8c2aeb387c Patch up runConstructors() change in Immediate.cpp 2020-03-06 13:51:15 -08:00
Lang Hames
17671672ce [Immediate] Switch the JIT codegen opt-level to Default.
This matches MCJIT's default, and may solve some of the linux test failures
seen in https://github.com/apple/swift/pull/29863.
2020-03-05 14:08:09 -08:00
Lang Hames
7a0754b127 [Immediate] Switch immediate mode from MCJIT to LLJIT.
LLJIT is a simple LLVM IR JIT. Its interface is similar to MCJIT, but its
implementation is based on LLVM's newer ORC APIs. This initial patch does not
make use of any of LLJIT/ORC's advanced features, but will provide better
diagnostics when JIT'd code fails to link. Once LLJIT has proven usable in
this basic configuration we can start experimenting with more advanced
features, including lazy compilation.
2020-02-14 17:59:23 -08:00
Robert Widmann
2af598fb52 [Gardening] Const-qualify Many Usages of CompilerInstance
For those operations that do not need to emit diagnostics or manipulate modules, there's no reason to mutate the passed instance.
2020-01-14 09:02:10 -08:00
Robert Widmann
8fe25f7530 [NFC] Remove CompilerInstance::setSILModule
The REPL was using the CompilerInstance to stash this parameter, then it would immediately move it into IRGen.  Drop the setter and pass this data directly.
2020-01-13 22:01:41 -08:00
Robert Widmann
bd57f14661 [NFC] Push const IRGenOptions and SILOptions everywhere 2020-01-13 22:01:41 -08:00
Robert Widmann
6407a4d36f [Gardening] Drop an unused parameter 2020-01-13 22:01:41 -08:00
Daniel Rodríguez Troitiño
50fd6eae97 [windows] Use unprefixed library name for immediate mode.
The library does not have the lib prefix in Windows, so the immediate
mode was not finding the file. This was making the new tests in
tests/Driver/options.swift fail on Windows. The tests pass after this
change.

Notice that it seems to load the host standard library, so restricting
the change to Windows seems to be OK and should not affect
cross-compilation. Windows was already hardcoding ".dll" as the library
extension, disregarding the target, anyway.
2019-07-03 19:16:35 -07:00
Mike Ash
9df513ae7c [Interpreter] Clean up the /usr/lib/swift fallback code.
- Check the target triple at runtime to decide whether to use the fallback.
- Change isInResourceDir to actually check the resource dir.
- Use ArrayRef<std::string> instead of std::vector<std::string>.
2019-07-01 13:08:04 -04:00
Mike Ash
3f774094b7 [Interpreter] Fall back to loading Swift dylibs from /usr/lib/swift on Apple platforms.
Continue to load the dylibs next to the compiler if they exist. If they don't, then use the OS's dylibs.

rdar://problem/47528005
2019-07-01 13:08:04 -04:00
Jordan Rose
56f7164f15 Remove support for -enable-source-import in JIT or REPL modes
This was full of cruft to begin with, and -enable-source-import has
plenty of other problems. Remove support for IRGen-ing those other
modules.
2018-09-22 13:47:16 -07:00
Bob Wilson
8e330ee344 NFC: Fix indentation around the newly renamed LLVM_DEBUG macro.
Jordan used a sed command to rename DEBUG to LLVM_DEBUG. That caused some
lines to wrap and messed up indentiation for multi-line arguments.
2018-07-21 00:56:18 -07:00
Jordan Rose
cefb0b62ba Replace old DEBUG macro with new LLVM_DEBUG
...using a sed command provided by Vedant:

$ find . -name \*.cpp -print -exec sed -i "" -E "s/ DEBUG\(/ LLVM_DEBUG(/g" {} \;
2018-07-20 14:37:26 -07:00
Michael Gottesman
a264b1ed9c [gardening] Use SmallPtrSetImpl instead of SmallPtr<N> in more function parameters/return values.
This is good practice like using SmallVectorImpl instead of SmallVector.
2018-05-07 10:35:51 -07:00
Slava Pestov
6d143726be Immediate: Use ModuleDecl::collectLinkLibraries() better 2018-04-26 23:37:16 -07:00
Slava Pestov
7e4da528a6 IRGen: Remove collectLinkLibrariesFromExternals()
It doesn't appear to do anything.
2018-04-24 20:30:17 -07:00
Doug Gregor
61e9cf8f1d [IRGen] Centralize the hack to collect autolink libraries from externals.
We had three copies of this code, each of which did a bit more work than
was actually necessary. Consolidate them and avoid calling
`collectLinkLibraries()` on a given module more than once within this
path.
2018-04-10 21:17:10 -07:00
Slava Pestov
cc586594d1 SIL: Remove unnecessary performSILLinking() calls from immediate mode and REPL 2018-04-09 13:27:07 -07:00
David Ungar
488db9fb9b Fix ReferencedNameTracker in preparation for batch mode. 2018-02-16 22:28:10 -07:00
David Ungar
fec411e9bc reformatted 2018-02-15 15:34:55 -07:00
David Ungar
1f9a4f3591 Pass around arguments for primary-specific filenames.
Get rid of IRGenOpts attributes that won’t work for batch mode and also remove fakeNamesStub.
2018-02-15 15:34:55 -07:00
Arnold Schwaighofer
2d58f08142 Use clang's effective llvm triple for IR generation
Instead of using the target that was passed to the driver. Use the target from
the clang importer that might have been changed by clang (i.e armv7 to thumbv7
on darwin)

rdar://32599805
2018-02-14 15:45:43 -08:00
Pavel Yaskevich
499fbdba77 [Immediate] Move to new diagnostic handler model when trying to link modules
These changes are trying to fix problem related to changes from upstream
LLVM which changes the way how diagnostics are handled in presence of linker
failures.

Resolves: rdar://problem/35458963
2017-11-09 22:06:58 -08:00
Arnold Schwaighofer
034241e440 Revert "Use clang's effective llvm triple for IR generation (#10211)"
This reverts commit 2e3522fafc because debugging
with thumb instructions is broken and being worked on.

rdar://32599805
2017-09-12 13:59:53 -07:00
Arnold Schwaighofer
2e3522fafc Use clang's effective llvm triple for IR generation (#10211)
* Use clang's effective llvm triple for IR generation

Instead of using the target that was passed to the driver. Use the target from
the clang importer that might have been changed by clang (i.e armv7 to thumbv7
on darwin)

rdar://32599805

* Address review comments

* Fix test case osx-targets.swift

* Fix pic.swift test case

* Fix test abi_v7k.swift

* Address review comment for test osx-targets.swift
2017-06-13 16:26:14 -07:00
Argyrios Kyrtzidis
ca906d1e99 Add '-Fsystem' framework search option to indicate path for frameworks that should be treated as 'system'
This has the effect of propagating the search path to the clang importer as '-iframework'.
It doesn't affect whether a swift module is treated as system or not, this can be done as follow-up enhancement.
2017-02-14 16:13:25 -08:00
Andrew Trick
855918c620 [Lowering] Add an AddressLowering pass. 2017-02-13 17:10:02 -08:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Hugh Bellamy
d80a2220bd Fix clang-cl error compiling Immediate.cpp on Windows 2016-12-08 13:17:22 +00:00
Hugh Bellamy
c417083e60 Port swift/Immediate to Windows (#5957) 2016-12-07 19:08:41 -08:00
Michael Gottesman
59c6a64f5a [gardening] 0 => nullptr. Fixed with clang-tidy. 2016-12-06 23:14:13 -08:00
Doug Gregor
51c2cee4d8 [Immediate] Remove a redundant, pessimizing std::move().
Silences a warning on newer Clang versions.
2016-12-01 10:37:28 -08:00
Roman Levenstein
409d146f17 Reduce memory usage by freeing memory occupied by SILModules after IRGen.
There is no need to keep SILModules around after IRGen has generated LLVM IR from them.
This reduces the compiler memory usage during LLVM code-generation and optimization phases roughly by 15%-20%.
2016-11-29 22:11:59 -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
Mark Lacey
1c00ac4c6d Merge remote-tracking branch 'origin/master' into master-next
Conflicts:
	lib/IRGen/IRGen.cpp
	test/DebugInfo/parent-scope.swift
2016-07-15 19:23:53 -07:00
Robert Widmann
dc88e51321 Nuke entry-point-based process args
Provides a new fallback for Process arguments for those instances where we do
not own main (e.g. Frameworks, Objective-C owns main.m or main.c, etc.). This
includes a number of platform-specific specializations of argument grabbing
logic and a new thread-safe interface to Process.unsafeArgv.

main()  | _NSGetArgc/_NSGetArgv    | /proc/self/cmdline     | __argc/__argv
--------|--------------------------|------------------------|---------------
Scripts | OS X, iOS, tvOS, watchOS | Linux, FreeBSD, Cygwin | Windows

For interpreted Swift where we must filter out the arguments we now do so by
loading the standard library and calling into new SPI to override the arguments
that would have been grabbed by the runtime. This implementation completely
subsumes the use of the entry point  '_stdlib_didEnterMain' and it will be
removed in a future commit.
2016-07-14 01:06:19 -07:00
Han Sangjin
cccfbf4d3c [swiftc/msvc] Compiling with MSVC (#1516)
Some modifications for the ms-extension option of the clang.exe in the Visual Studio 2015 development environment

This patch is only for swiftc.exe. I used the library set of Visual Studio 2015 Update 1 and recent version of swift-clang as the compiler. If you are using the real MSVC compiler, more patch might be required.
2016-07-08 19:06:10 -07:00
Michael Gottesman
0c1f6db23b [upstream-update] Add our own LLVM global context now that llvm::getGlobalContext() was removed upstream.
Swift relies on this for now. So create our own. This makes more sense
than trying to add back in the API (which is dead besides the c api) or
use the c api itself. We should probably consider not using a global
context like this.
2016-04-18 07:29:58 -07:00
Michael Gottesman
c182e692f4 [upstream-update] llvm::Linker::linkModules no longer needs a NoCtx diagnostic handler. It always gets it from the llvm context. 2016-02-06 11:22:26 -08:00
Michael Gottesman
99c6e2ce55 Pass in the actual unique_ptr of the submodule to llvm::Linker::linkModules to deal with an API that was updated upstream.
What is important to note is that the submodule needs to be forwarded via a move
constructor to make sure that we do not destroy the value early.
2016-02-06 11:22:26 -08:00
Michael Gottesman
5f55a47d93 llvm::DiagnosticInfo.h upstream now has its own header llvm/IR/DiagnosticInfo.h. Include it in Immediate.cpp. 2016-02-06 11:22:26 -08:00
Michael Gottesman
248ca3d657 Update for upstream linker changes.
llvm commits:
r254449.
r254777.
2016-02-06 11:22:26 -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
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00