Commit Graph

629 Commits

Author SHA1 Message Date
Mark Lacey
088d7b5f20 IRGenModule users shouldn't need to know about clang::CodeGenerator.
Swift SVN r13179
2014-01-30 22:59:00 +00:00
Mark Lacey
d69b305200 Generate IR for inline functions from Clang modules.
Currently only inline functions referenced from Swift source files, or
from the REPL, will get IR generated for them. Inline functions
referenced by other inline functions will require additional effort to
generate properly.

With this change we use the clang::CodeGenerator-created llvm::Module
for all IR generation in Swift. This is perhaps undesirable, but
unavoidable given the interface the public Clang APIs expose, which do
not allow for building a ModuleBuilder that borrows an existing
llvm::Module.

Also unfortunate is the hack to generate a UsedAttr for each imported
inline function, but the public Clang APIs do not provide a way to only
emit deferred decls without emitting other things (e.g. module flags
that conflict with what the Swift IRGen emits). Note that we do not do
IRGen for every inline function in the module - only the ones that the
importer pulls in, which appears to be only those transitively
referenced from Swift code.

Swift SVN r13134
2014-01-30 02:33:37 +00:00
Mark Lacey
9fde7f17cc Add DisableFPElim to IRGenOptions.
Use this to initialize the llvm::TargetOptions for code generation.

Swift SVN r13130
2014-01-30 00:26:57 +00:00
Mark Lacey
5e40837b62 Always pass an llvm::Module* to performIRGeneration().
Previously it would create a new module if one was not passed in. There
are no uses where we do not or cannot provide a module, so it seems
reasonable to make the interface consistently require a module.

Swift SVN r13016
2014-01-27 23:48:49 +00:00
Connor Wakamo
38e1fd44af [frontend] Added support for -disable-llvm-arc-opts.
Adjusted how this option is handled: it is now set in IRGenOptions. If set,
this prevents the relevant passes from being added at all, instead of making
them no-ops.

Swift SVN r13005
2014-01-27 21:22:46 +00:00
Jordan Rose
be0a303c7d [DebugInfo] Only write an AST into the object file with the current compiler.
i.e. not the new driver/frontend. That one will insert it as part of linking.

Swift SVN r12923
2014-01-24 18:42:07 +00:00
Jordan Rose
11008f0ed1 Split diagnostics out into separate files.
Thanks to the way we've set up our diagnostics engine, there's not actually
a reason for /everything/ to get rebuilt when /one/ diagnostic changes.
I've split them up into five categories for now: Parse, Sema, SIL, IRGen,
and Frontend, plus a set of "Common" diagnostics that are used in multiple
areas of the compiler. We can massage this later.

No functionality change, but should speed up compile times!

Swift SVN r12438
2014-01-17 00:15:12 +00:00
Greg Parker
927613bcac [IRGen] Set iOS simulator bit in Objective-C metadata.
Swift SVN r12325
2014-01-15 08:13:40 +00:00
Chris Lattner
1d9a826420 more mainline API drift.
Swift SVN r12227
2014-01-13 15:15:58 +00:00
Chris Lattner
914591b332 adjust for mainline llvm changes.
Swift SVN r12219
2014-01-13 01:18:48 +00:00
Jordan Rose
f09cd93194 [autolinking] Hack: autolink any module containing external definitions.
We're still synthesizing external definitions too eagerly, and things
getting pulled in only through submodules aren't getting properly autolinked.
(That is, AppKit imports <QuartzCore/CIImage.h> but doesn't think that
QuartzCore is visible, because it isn't.)

The first right answer is to detect that a part of QuartzCore is visible even
though the whole thing isn't. The second right answer is to properly handle
Clang submodules as real modules---there are a lot of rough edges there.
<rdar://problem/13140302>. The third right answer is that we shouldn't even
emit references to these symbols until the /user/ needs them.

And what I'm doing now is just to attempt to link to every module that we've
synthesized thunks for.

<rdar://problem/15754311>

Swift SVN r12031
2014-01-08 01:52:24 +00:00
Doug Gregor
4c9bda853e llvm/Assembly/PrintModulePass.h moved to llvm/IR/PrintModulePass.h
Swift SVN r11991
2014-01-07 15:25:30 +00:00
Jordan Rose
b1b50a134e Autolinking: include all imported modules.
Although Cocoa.framework re-exports AppKit, Foundation, and CoreData, an
arbitrary library does not re-export most of its imports. Normally this
would be fine, but the Clang importer can pull in types too eagerly and
then generate thunks and wrappers for things we don't care about. At least
for now, return to the behavior of autolinking /anything/ that gets visibly
imported.

<rdar://problem/15705923>

Swift SVN r11844
2014-01-03 01:21:11 +00:00
Connor Wakamo
59f18f9fc0 Renamed irgen::Options and irgen::OutputKind to IRGenOptions and IRGenOutputKind, and move both out of the irgen namespace now that they're in swiftAST.
Swift SVN r11405
2013-12-18 01:17:09 +00:00
Connor Wakamo
3e81830385 Move "include/swift/IRGen/Options.h" to "include/swift/AST/IRGenOptions.h".
This commit only moves the header file; updating the class so that it is no longer in the irgen namespace will be handled separately.

Swift SVN r11404
2013-12-18 01:17:09 +00:00
Adrian Prantl
e01d25bcb7 [Sync with ToT LLVM] Output the new debug info metadata version.
Swift SVN r11266
2013-12-13 21:20:50 +00:00
Jordan Rose
417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00
Jordan Rose
8b8cc8ee62 Turn SerializedModule into SerializedASTFile.
Part of the FileUnit restructuring. A serialized module is now represented as
a TranslationUnit containing a single SerializedASTFile.

As part of this change, the FileUnit interface has been made virtual, rather
than switching on the Kind in every accessor. We think the operations
performed on files are sufficiently high-level that this shouldn't affect us.

A nice side effect of all this is that we now properly model the visibility
of modules imported into source files. Previously, we would always consider
the top-level imports of all files within a target, whether re-exported or
not.

We may still end up wanting to distinguish properties of a complete Swift
module file from a partial AST file, but we can do that within
SerializedModuleLoader.

Swift SVN r10832
2013-12-05 01:51:09 +00:00
Jordan Rose
eede5ec4f9 Begin refactoring for mixed file kinds within a single module.
The goal of this series of commits is to allow the main module to consist
of both source files and AST files, where the AST files represent files
that were already built and don't need to be rebuilt, or of Swift source
files and imported Clang headers that share a module (because they are in
the same target).

Currently modules are divided into different kinds, and that defines how
decls are looked up, how imports are managed, etc. In order to achieve the
goal above, that polymorphism should be pushed down to the individual units
within a module, so that instead of TranslationUnit, BuiltinModule,
SerializedModule, and ClangModule, we have SourceFile, BuiltinUnit,
SerializedFile, and ClangUnit. (Better names welcome.) At that point we can
hopefully collapse TranslationUnit into Module and make Module non-polymorphic.

This commit makes SourceFile the subclass of an abstract FileUnit, and
makes TranslationUnit hold an array of FileUnits instead of SourceFiles.
To demonstrate that this is actually working, the Builtin module has also
been converted to FileUnit: it is now a TranslationUnit containing a single
BuiltinUnit.

Swift SVN r10830
2013-12-05 01:51:03 +00:00
Joe Groff
72be5e8f59 IRGen: Always use PIC relocation model.
Fixes <rdar://problem/15358345>.

Swift SVN r10026
2013-11-07 18:42:53 +00:00
Jordan Rose
4a90ab0a4f [IRGen] Separate out SourceFile-specific processing from whole-module stuff.
We're going to want to emit multiple SourceFiles and one SILModule in one
IRGenModule.

Swift SVN r9670
2013-10-25 17:30:39 +00:00
Jordan Rose
28e01f3c3a Eliminate "MainSourceFile" from TranslationUnit in favor of an array.
Anywhere that assumes a single input file per TU now has to do so explicitly.
Parsing still puts all files in a single SourceFile instance; that's next on
the list.

There are a lot of issues still to go, but the design is now in place.

Swift SVN r9669
2013-10-25 17:30:37 +00:00
Jordan Rose
f7f253320a Re-add -l flag to Swift interim driver.
This is useful in -i and REPL modes, which do not have a separate linking
step. This version of the -l flag doesn't rely on TranslationUnit. I also
cleaned up the library-loading diagnostics.

Swift SVN r9488
2013-10-18 18:52:10 +00:00
Jordan Rose
5ed38c0b72 Clarify SourceFile vs. TranslationUnit interfaces for SILGen and IRGen.
Once we have multiple SourceFiles in a TranslationUnit, it no longer makes
sense to say "only SILGen decls starting from element N" without specifying
which source file you mean.

Also, clarify ownership by having performSILGeneration return a unique_ptr
instead of just a bare pointer.

Swift SVN r9112
2013-10-09 23:44:43 +00:00
Jordan Rose
49cd5b1680 Use SourceFile in IRGen.
The only real change here is that module-wide IR (autolinking and ObjC
runtime flags) have been pushed up from emitTranslationUnit (now
emitSourceFile) to its only caller, performIRGeneration.

Swift SVN r9075
2013-10-09 18:38:24 +00:00
Joe Groff
bea03d27f4 Bring back frame pointers.
The backend team needs them for performance analysis.

Swift SVN r8791
2013-09-30 20:29:18 +00:00
Michael Gottesman
4dc7cee606 Add in the option -disable-llvm-optzns to swift.
-disable-llvm-optzns in clang tells the frontend to do everything it would
normally do at lets say -O2, except run the actual LLVM IR passes on the
resulting IR. This is useful in the case where one wants to look at the result
of a non gauranteed SIL optimization pass at the IR level without llvm
optimizations applied.

Swift SVN r8594
2013-09-24 16:48:09 +00:00
Adrian Prantl
4829626f80 Pin the DWARF version to 3 until everyone has access to an updated
version of ld64. (echristo bumped the default for LLVM to 4 yesterday).

Swift SVN r7905
2013-09-04 17:55:33 +00:00
Jordan Rose
1e3b418f27 Remove hacks to speed up includes of "swift.swift", which doesn't exist now.
Swift SVN r7489
2013-08-22 23:20:25 +00:00
Jordan Rose
f1bc7801f4 Rework getReexportedModules to optionally find all imported modules.
...instead of just those that are re-exported. This will be used for
autolinking (and probably few other places).

As part of this, we get two name changes:
  (1) Module::getReexportedModules -> getImportedModules
  (2) TranslationUnit::getImportedModules -> getImports

The latter doesn't just get modules-plus-access-paths; it also includes
whether or not the import is re-exported. Mainly, though, it just didn't
seem like a good idea to overload this name when the two functions aren't
really related.

No tests yet, will come with autolinking.

Swift SVN r7487
2013-08-22 23:20:18 +00:00
Adrian Prantl
661315763a Debug Info: This patch implements the "emit modules when compiling -g"
proposal.
When compiling with debug info, build a swiftmodule that contains all the
type decls referenced by DWARF and emit it into a special __apple_swiftast
section in the .o file.

Swift SVN r7398
2013-08-21 01:07:30 +00:00
Joe Groff
8baa585bab IRGen: Add FixedTypeInfo methods for extra inhabitants/spare bits.
Dynamic forms of these methods will ultimately move to the fully general TypeInfo class, but for now I'm focusing on getting fixed-layout unions working. Set up methods on FixedTypeInfo for getting the fixed count of extra inhabitants and the spare bit mask for a type. Have the default implementation of extra inhabitants count use the spare bits. For now, only actually set spare bits for types with IR-level single scalar non-power-of-two integer representation (e.g., i1, or i21).

Swift SVN r7289
2013-08-16 20:56:28 +00:00
Jordan Rose
a35f7cbd4b Thread [exported] through TranslationUnit and the Serialization library.
This still doesn't do anything yet.

Swift SVN r7051
2013-08-08 19:09:21 +00:00
Chris Lattner
8956e856c6 remove the old AST capture analysis pass completely. The primary IR
gen pass has had it disabled for some time, so snip the last few uses
in the REPL and zap it.

Goodbye old friend, you were a very useful stopgap.


Swift SVN r6885
2013-08-05 14:14:17 +00:00
Adrian Prantl
adfdd7edc6 typo.
Swift SVN r6811
2013-08-01 18:47:40 +00:00
Chris Lattner
11f5b48a27 Fix a -Wdocumentation warning, and hack out NoFramePointerElimNonLeaf to
fix the build.  This isn't a proper fix (we should start putting out new attributes
on llvm::Function's, but getting the build working again seems important.


Swift SVN r6584
2013-07-25 03:41:57 +00:00
Jordan Rose
6547b9790a [serialization] Allow references to Clang-imported values.
This unfortunately duplicates the hack of directly referencing the Clang
module loader if a cross-reference points to the current module; ideally
we'd have some kind of module chain, but I'd settle for a refactoring of
the code to share with NameBinding.

Additionally, Clang nodes are not actually validated to be from the right
module, which could be problematic for extensions or any case of actual
name collision.

Swift SVN r6519
2013-07-23 23:10:05 +00:00
Jordan Rose
b17a23112e Revert "Update for LLVM change to raw_fd_ostream's option flags."
I'm not sure what I was thinking. Thanks for actually fixing this, Sean.

This reverts r6503.

Swift SVN r6307
2013-07-16 23:16:05 +00:00
Jordan Rose
0a6d9df178 Update for LLVM change to raw_fd_ostream's option flags.
Swift SVN r6305
2013-07-16 23:11:03 +00:00
Sean Callanan
213829f946 Adapted to a changed enum in llvm to make the build
work again.


Swift SVN r6300
2013-07-16 23:01:14 +00:00
Adrian Prantl
68e1df49f5 Fix a couple more glitches that were uncovered by assertions.
Swift SVN r5774
2013-06-23 03:35:28 +00:00
Chris Lattner
2144140168 really use SIL IRGen for all recursive compilations as well, this exposes a symbol
redefinition (or linkage type) bug that causes two tests to fail.  I filed 
rdar://13670581 to track this and am plowing forward, since they seem minor.


Swift SVN r4761
2013-04-17 03:46:40 +00:00
Joe Groff
24a092bc3a IRGen: Use 'generic' cpu target.
LLVM recently changed to autodetect host features by default. Change our default to use the "generic" CPU so that we emit binaries to a portable baseline (until some time in the future when we have proper -mtune and -mattr flags).

Swift SVN r4310
2013-03-06 23:59:18 +00:00
Joe Groff
c9d6a351f5 IRGen: SIL ClosureInsts (almost).
Implement lowering of SIL ClosureInsts by packing the partial arguments into a heap allocation and emitting a thunk to unpack them and apply the closure function, similar to curried entry points. The test doesn't work quite yet because nested FuncDecls don't get visited anymore. I need to replace my hacked SIL path with a proper walk of the SIL module to generate functions and the AST to generate types.

Swift SVN r3817
2013-01-20 19:50:10 +00:00
Joe Groff
9259c0d912 IRGen: Get "hello world" to compile through SIL.
Add a path through IRGenModule to optionally codegen FuncDecls using their corresponding SIL Functions when constructed with a SILModule. Jury-rig an IRGenSILFunction subclass of IRGenFunction that does the bare minimum necessary to compile "hello world" from SIL. There are some impedance mismatches between irgen and SIL that need to be smoothed out, particularly the AST-dependent way irgen currently handles function calls. Nonetheless, `swift -sil-i hello.swift` works!

Swift SVN r3759
2013-01-14 02:57:11 +00:00
Dave Zarzycki
ed5de91828 Fix build warnings
Swift SVN r3749
2013-01-11 18:58:44 +00:00
Joe Groff
aba47a6b90 Add a '-sil-emit-llvm' option to the driver.
It doesn't do anything but crash yet. Also add an entry point fo SILGen to Subsystems so that it can be invoked without dependency on SIL or SILGen.

Swift SVN r3738
2013-01-11 01:51:54 +00:00
Chris Lattner
47dbc4051c update for mainline LLVM header file moves.
Swift SVN r3634
2013-01-02 14:38:42 +00:00
Doug Gregor
83f2874ba1 Implement support for calling imported C functions from Swift.
There is no protection whatsoever if the Clang-to-Swift type
conversion produces something that Swift doesn't lower in an
ABI-compatible way. That will be dealt with later.


Swift SVN r3249
2012-11-27 00:34:48 +00:00
Eli Friedman
a9f685d94b Fix my crazy swift.swift inlining hack so it doesn't pull in llvm.global_ctors. <rdar://problem/12539597>.
Swift SVN r3032
2012-10-20 00:01:26 +00:00