Commit Graph

9332 Commits

Author SHA1 Message Date
Anna Zaks
64693183da [DCE] Add a very primitive dead code elimination pass
DCE is added as a separate SIL pass with it's own entry point.

For now, detect and simplify the branch instructions with constant
conditions and delete unreachable basic blocks (for now, we do not even
pay any regards to the basic block arguments).

Swift SVN r6713
2013-07-29 21:55:05 +00:00
Anna Zaks
0acc4d5f13 [SIL] Pass type instead of String to the diagnostic machinery
As per Doug’s code review of r6151.

Swift SVN r6711
2013-07-29 21:55:03 +00:00
Jordan Rose
d9b7c8ad5a Move ClangModule into the ClangImporter library.
This makes it very clear who is depending on special behavior at the
module level. Doing isa<ClangModule> now requires a header import; anything
more requires actually linking against the ClangImporter library.

If the current source file really can't import ClangModule.h, it can
still fall back to checking against the DeclContext's getContextKind()
(and indeed AST currently does in a few places).

Swift SVN r6695
2013-07-29 18:56:35 +00:00
Enrico Granata
c75fe924a1 Moving the Swift demangler from libSIL to libBasic
Plus, a couple of minor cosmetic changes that I had held off for a couple days now



Swift SVN r6691
2013-07-29 17:42:57 +00:00
Joe Groff
50bd6cb630 SILPrinter: Handle bound generic types as SILConstant context.
Fixes <rdar://problem/14503782>.

Swift SVN r6688
2013-07-29 15:55:42 +00:00
Doug Gregor
0842fb5cf8 Rename "base class" to "superclass" and "derived class" to "subclass".
Standardize on the more-common "superclass" and "subclass" terminology
throughout the compiler, rather than the odd mix of base/derived and
super/sub. 

Also, have ClassDecl only store the Type of the superclass. Location
information will be part of the inheritance clause for parsed classes.




Swift SVN r6687
2013-07-29 15:48:34 +00:00
Joe Groff
3c03a8cb21 SIL: Patch up float_literal bit handling.
Add a getBits() method to FloatLiteralInst so we don't need to round trip APInt -> APFloat -> APInt to print the bits in the printer. Use allocateLiteralInstWithBitSize instead of -WithTextSize to avoid wasting space.

Swift SVN r6680
2013-07-28 17:39:51 +00:00
Joe Groff
d46bdbe25d SIL: Reorder float_literal printing to be a bit clearer.
Swift SVN r6679
2013-07-27 17:10:39 +00:00
Joe Groff
24dc1cfad7 SIL: Remove the redundant associated_metatype instruction.
Its behavior was exactly the same in IRGen as 'metatype' on the associated type. Managing type metadata should be IRGen's job.

Swift SVN r6677
2013-07-27 04:13:59 +00:00
Joe Groff
1300efb8fb SIL: Represent float_literal values with bitwise representations.
This way we don't need to deal with the inaccuracy of decimal float literals. While we're here, modify the in-memory representation of IntegerLiteralInst and FloatLiteralInst to save the word array of the APInt instead of round-tripping through plain text.

Swift SVN r6676
2013-07-27 03:57:14 +00:00
John McCall
a75e26600c Don't store element offsets in individual RValues.
Swift SVN r6670
2013-07-27 00:42:30 +00:00
Anna Zaks
e5c3a7ea80 [SIL] Make sure SILBasicBlock destructor gets called.
This also ensures that the instructions indie the basic block
get destructed.

Swift SVN r6667
2013-07-27 00:25:03 +00:00
Joe Groff
11ce744de1 SILPrinter: Comment sil decls and function_refs with demangled names.
Swift SVN r6658
2013-07-26 22:39:00 +00:00
Doug Gregor
532dd646dc Use "witness" rather than "value witness" to mean a non-type witness in the AST/type checker.
The term "value witness" has a very specific meaning in IR generation,
causing unnecessary confusion.


Swift SVN r6650
2013-07-26 18:34:06 +00:00
Doug Gregor
d0f60ab755 Introduce some encapsulation into ProtocolConformance.
Swift SVN r6648
2013-07-26 18:12:17 +00:00
Anna Zaks
b5ebb34982 Emit an error on returning from a 'noreturn' function.
Swift SVN r6628
2013-07-26 00:32:22 +00:00
Enrico Granata
3d1f75fe87 Changing enum names to have an uppercase initial
Adding a comment to describe the purpose of SubstitutionWithProtocol

Swift SVN r6612
2013-07-25 21:06:57 +00:00
Dmitri Hrybenko
6a6f1f66fe Demangler: clean up includes and extra llvm:: prefixes
Swift SVN r6608
2013-07-25 20:45:07 +00:00
Joe Groff
de1f926349 SILGen: Propagate function thin-ness through specializations.
Now that we actually support generic protocol methods, we can end up specializing non-thin function values (because the protocol_method/archetype_method value carries the This metadata as payload), so the thin-ness of the specialized function type needs to be constrained by the input type's thinness. Relax the verifier to allow a specialize inst to produce a thick value if its input is thick.

Swift SVN r6598
2013-07-25 15:57:17 +00:00
Doug Gregor
740f8b8354 SIL verifier: protocol and archetype method instructions can refer to polymorphic functions.
Swift SVN r6589
2013-07-25 06:37:23 +00:00
Peter O'Gorman
ce79d725e4 Fix build on case sensitive fs
Swift SVN r6587
2013-07-25 04:20:27 +00:00
Enrico Granata
e3241cf6e8 One space is enough: _TMdC3foo3bar should read "direct type metadata for foo.bar" instead of "direct type"...
Swift SVN r6581
2013-07-25 01:41:54 +00:00
Enrico Granata
144ecb0b06 The previous implementation of the demangler treated allocating vs. initializing constructors in a way that is highly inconvenient from a debugger perspective.
The user-specified constructor() and destructor() were marked with an extra attribute (initializing and destroying) for classes, vs. the allocating and deallocating destructors which had no extra cruft
(but hardly anyone would care about them since they are system-provided)

This checkin (discussed with Joe Groff changes) the behavior of the demangler such that the user's constructors and destructors now demangle as one would expect:
; CHECK: _TC3foo3barcfMS0_FT_S0_ ---> foo.bar.constructor : (foo.bar.metatype)() -> foo.bar
; CHECK: _TC3foo3bard ---> foo.bar.destructor

and the system-provided allocator/deallocator demangles with a clearly distinguishable name:
; CHECK: _TC3foo3barCfMS0_FT_S0_ ---> foo.bar.__allocating_constructor : (foo.bar.metatype)() -> foo.bar
; CHECK: _TC3foo3barD ---> foo.bar.__deallocating_destructor



Swift SVN r6573
2013-07-24 23:37:47 +00:00
Joe Groff
6b779cc642 SIL: Spell all non-SILFunction Swift decl references with '#'.
Reserve '@' as the SILFunction introducer, and use '#' when referencing Swift decls (like with SILConstants).

Swift SVN r6563
2013-07-24 22:10:52 +00:00
Joe Groff
398cbba5be Rename SILConstant to SILDeclRef.
"SILConstant" doesn't really describe its role in SIL anymore, which is to provide a reference to a Swift declaration in a SIL instruction, such as a method or nominal type field.

Swift SVN r6559
2013-07-24 21:21:31 +00:00
Enrico Granata
efcd17f604 This commit implements the Demangler API in C++ and de facto deprecates the existing Demangle.swift
The new demangler is in the "swift/SIL/Demangle.{h|cpp}" files, and in the swift::Demangle namespace, which has two public entry points:

std::string demangleSymbol(llvm::StringRef mangled);
std::string demangleType(llvm::StringRef mangled);

This was necessary to support the need for LLDB to demangle Swift symbol (and type) names

Test case is included



Swift SVN r6547
2013-07-24 17:52:27 +00:00
John McCall
325b86b82a Prepare SIL type lowering to create more expressive type-infos.
Swift SVN r6545
2013-07-24 04:58:49 +00:00
John McCall
4df7c9d33f Adjust the mechanics of type lowering to avoid double-caching.
Swift SVN r6531
2013-07-23 23:51:13 +00:00
John McCall
fd9b983b40 Micro-optimize SILType::isAddressOnly.
Swift SVN r6504
2013-07-23 17:23:58 +00:00
John McCall
3e9fa26587 Extract some helper functions for l-values.
Swift SVN r6501
2013-07-23 16:44:34 +00:00
John McCall
8d92add99b Don't needlessly materialize logical l-values before loading them.
Swift SVN r6495
2013-07-23 06:28:55 +00:00
John McCall
84420609fa Remove unnecessary SGFContext parameter from Decl/Stmt visitation.
Swift SVN r6494
2013-07-23 06:28:54 +00:00
John McCall
7b193e1fae Make SILGenFunction's Expr visitation private; there are multiple
meaningful ways to visit Exprs.

Swift SVN r6493
2013-07-23 06:28:53 +00:00
John McCall
e668ff914f Add parsing and IR-gen for weak_retain and weak_release.
Swift SVN r6492
2013-07-23 06:28:51 +00:00
Chris Lattner
1a75f7c5a3 more renaming to make things consistent-er
Swift SVN r6481
2013-07-22 21:42:25 +00:00
Chris Lattner
e9f9636206 rename AllocBoxPromotion -> AllocBoxToStack.cpp to be more similar in name to the StackToSSA.cpp pass.
Swift SVN r6474
2013-07-22 21:37:41 +00:00
Chris Lattner
e0dbcc40de split memorypromotion into two different passes, split its testcases
in half, and switch them to use sil-opt to test with.


Swift SVN r6469
2013-07-22 20:59:28 +00:00
Chris Lattner
446fb1f016 rename MemoryPromotion.cpp -> AllocBoxPromotion.cpp
Swift SVN r6467
2013-07-22 20:44:35 +00:00
Chris Lattner
df967027ec Implement a first hack at (limited) alloc_stack to register
promotion.  This pass is destined to be somewhat different than
LLVM's mem2reg pass:
 - Because we can't break debug information, this won't remove
   alloc_stack (and the stores to it) for allocations with location info.
 - Because this gates other dataflow diagnostics, we don't want a value
   being pinned to the stack to prevent promotion.  Instead, we promote
   all loads that we can, even if some end up being blocked by a [byref]
   "may" store.

Lots of caveats herein:
 - This doesn't do cross block promotion yet.
 - This doesn't remove the allocation even when it is allowed to.
 - This causes a few IRGen test failures, including an irgen crash.
 - This should be split out to its own file, its own pass, and its own
   testcase.

Because of these caveats, this is disabled by default right now. Pass -enable-stack-promotion to get it.


Swift SVN r6454
2013-07-22 16:38:32 +00:00
Chris Lattner
e4708b1f3a build on Joe's new "emitDestroyAddress" helper to emit a "load + release" pair instead
of destroy_address when possible.


Swift SVN r6437
2013-07-22 00:57:17 +00:00
Chris Lattner
63d2d16bea Building on Joe's refactoring of TypeLoweringInfo, teach memorypromotion to
not insert destroy_addr instructions when a type is trivial.  This also works
around its other limitation (not handling multiple final releases), allowing it
to promote 73 more boxes.


Swift SVN r6436
2013-07-22 00:52:32 +00:00
Chris Lattner
dbd820c6e5 teach memorypromotion about ProjectExistentialInst. Mention ARC optimization in SIL.rst.
Swift SVN r6435
2013-07-22 00:46:00 +00:00
Chris Lattner
0d6f684442 tuple_element_addr doesn't cause a pointer to escape unless the result of
the tuple_element_addr escapes.  This allows the pass to promote 50 more
alloc_box's in the stdlib.



Swift SVN r6434
2013-07-22 00:09:11 +00:00
Chris Lattner
c1e6a4c273 the indirect return result of an apply doesn't capture a pointer.
Swift SVN r6433
2013-07-21 23:21:38 +00:00
Chris Lattner
b70073588f byref arguments to apply and partial_apply do not capture their result,
so allow alloc_box to be promoted to alloc_stack in such cases.


Swift SVN r6432
2013-07-21 20:36:36 +00:00
Joe Groff
8ac1bda817 SIL: Move retain/release/destroy helpers onto SILBuilder.
Add a convenience SILModule::getTypeLoweringInfo forwarder, and move the emitRetainRValue and emitReleaseRValue helpers from SILGenFunction to SILBuilder so they're more readily available to non-SILGen passes. Add an emitDestroyAddress helper that emits nothing, destroy_addr, or load + release based on the value semantics of the referenced type.

Swift SVN r6431
2013-07-21 18:39:56 +00:00
Joe Groff
1984cf41e0 SIL: Rename SILFunction::getMangledName to SILFunction::getName.
Swift SVN r6430
2013-07-21 18:39:51 +00:00
Joe Groff
59c7fa881c SIL: Refactor TypeLoweringInfo to be keyed on SILType.
SIL passes need to have the value semantics information in TypeLoweringInfo available by SILType. Refactor getTypeLoweringInfo into separate "derive the SILType from a Swift type" and "determine the value semantics for a SILType" stages, and index the resulting TypeLoweringInfo by both (CanType, uncurryLevel) and SILType.

Swift SVN r6429
2013-07-21 18:39:47 +00:00
Chris Lattner
099f0cf451 simplify the construction of SILFunctionTypeInfo, inlining some singly-called helper functions.
Swift SVN r6427
2013-07-21 15:42:25 +00:00
Chris Lattner
b79c5aab94 Move SILFunctionTypeInfo logic into SILType.cpp out of SILModule.cpp,
no functionality change.


Swift SVN r6426
2013-07-21 15:32:58 +00:00