Commit Graph

238 Commits

Author SHA1 Message Date
Michael Gottesman
b6f8bd9a55 Initial simple cost based performance inliner.
This is a very initial version mostly to get machinery in place before we start
considering more interesting things.

Specifically we do not:

1. Inline functions with any substitutions.
2. Inline functions that are not thin.
3. Inline functions in any recursive manner (i.e. we just follow the call tree
and inline until we run out of cost).
4. Remove functions that we have completely inlined as a good citizen should.

Additionally the cost model is purposely simplistic and assumes that every SIL
instruction is one to one with an LLVM instruction (when many do not become any
LLVM instruction and others become 2). The idea is simply to put a cost on the
total increase in code size we allow due to inlining in a specific function.
Thus we just continually inline until we run out our inlining budget.

Even with the current limitations we inline 1248 apply inst in the stdlib when
setting a cost threshold of 225.

Swift SVN r11596
2013-12-23 06:00:57 +00:00
Nadav Rotem
d0c96e4eeb Implement a very very basic SIL Mem2Reg pass that promotes write-only and single-basicblock allocas.
This pass removes 1/4 of the allocas in the standard library.



Swift SVN r11189
2013-12-12 17:42:50 +00:00
Jordan Rose
b4e4b551bd Rename CompilerInstance::doIt to performParse.
'doIt' is semantically meaningless, and doesn't mention the fact that nothing
has actually been compiled yet (to SIL, to IR, or to machine code).
'performParse' matches the compiler flag -parse, which stops after
type-checking.

No functionality change.

Swift SVN r10951
2013-12-07 00:13:58 +00:00
Nadav Rotem
ccf3a127f2 Add a simple generic specialization pass.
Swift SVN r10885
2013-12-05 22:20:05 +00:00
Michael Gottesman
4379283013 Remove inclusion of SILPasses/Passes.h into Subsystems.h and update all relevant files.
Swift SVN r10880
2013-12-05 19:58:21 +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
Michael Gottesman
f2b8c0991d [cse] Initial implementation of EarlyCSE Port.
This patch contains an initial implementation of CSE for SIL ported from LLVM's
earlycse pass. It follows the overall general structure using
ScopedHashTables/DominatorTrees to perform the computation.

Currently it only handles integer literals to ease with the initial review. Once
this gets in I will be spending some time extending the pass to handle other
instructions.

Even with just handling integers this reduces the size of the stdlib in SIL by
~300 lines.

Swift SVN r10794
2013-12-04 21:49:37 +00:00
Chris Lattner
dadc9fc6d1 split predictable memory optimization (load promotion + alloc deletion) out to
its own SIL pass.  The bulk of this patch is updating the DI testcase to detangle
DI tests from load promotion tests.



Swift SVN r10721
2013-12-02 01:33:29 +00:00
Joe Groff
003709d51f SIL: Add a backreference from SILModule to its originating Swift Module.
Ideally this wouldn't be necessary, but the type substitution APIs required by generic specialization and SIL verification currently require a Module* pointer, and it's obnoxious to have to pass it down separately everywhere it's needed. Longer-term the reliance on Modules for type substitution might be able to go away.

Swift SVN r9866
2013-11-01 00:46:21 +00:00
Chris Lattner
b3d07ad9c6 fix sil-opt to call llvm_shutdown when its done, allowing it to work with -stats.
Swift SVN r9791
2013-10-30 16:01:10 +00:00
Chris Lattner
d5fd6a67e0 Sketch out a trivial start at a simplify-cfg pass with one optimization to delete
dead blocks (which happens to be incorrect).

Unlike the LLVM SimplifyCFG pass, this one will be worklist-based instead of 
iterative, avoiding needless iteration over the entire function when a small
local changes are being made.


Swift SVN r9756
2013-10-29 04:37:27 +00:00
Jordan Rose
d870f60edd Don't print statistics twice under -print-stats.
llvm::EnableStatistics() already causes statistics to be printed on exit.

Swift SVN r9549
2013-10-21 18:36:44 +00:00
Michael Gottesman
bdf7cbe178 [sil-combine] Initial SILCombine implementation.
This pass is a port of InstCombine from LLVM to SIL. Thus if you are familiar
with the code from InstCombine you will feel right at home.

Keep in mind that in order to help with review, this is just a skeleton with no
optimizations in it besides a simple DCE based off of isInstructionTriviallyDead
(which this patch exposes in Local.h like LLVM does) to ensure that trivial
testing of the pass can be accomplished since otherwise it would do nothing
implying that no tests could be written at all.

I additionally modified one test which no longer passed due to SILCombine
removing 1x unused metatype instruction from the standard library.

Swift SVN r9404
2013-10-16 03:10:14 +00:00
Stephen Lin
d500349527 SILOpt: remove accidental fall-through from capture promotion to next case
Swift SVN r9374
2013-10-15 20:44:01 +00:00
Stephen Lin
94dbad4666 Add (but do not enable by default) a pass for closure capture promotion (rdar://problem/14757727).
Swift SVN r9362
2013-10-15 19:11:54 +00:00
Jordan Rose
09787207fc Push TUKind into SourceFile (as InputKind).
Different SourceFiles in the same module will eventually have different
input kinds (at the very least Main vs. Library).

Swift SVN r9076
2013-10-09 18:38:25 +00:00
Chris Lattner
73ad4dbb6a Completely remove the stacktossa pass, it is dead now.
Swift SVN r8996
2013-10-07 22:11:32 +00:00
Chris Lattner
d6b01a42ad add a new (skeleton) pass for deshadowing inout variables.
Swift SVN r8954
2013-10-07 15:53:40 +00:00
Anna Zaks
a19d7569cc Introduce Builtin.staticReport, which allows compiler diagnostic reporting.
- Introduces the Builtin
- If the first parameter evaluates to '1', the dataflow diagnostics pass produces a diagnostic.
- The Builtin gets cleaned up before IRGen, but not before SIL serialization.

This patch also removes the current, overflow warning and XFAILs one of the tests. The other test is switched to use Builtin.staticReport.

TODO:
 - Utilize the other parameters to the builtin - the Message and IsError flag.
 - Use this Builtin within the stdlib.

Swift SVN r8939
2013-10-05 00:12:23 +00:00
Chris Lattner
767da738bb Change the command line option to sil-opt for the definite initialization
pass to be -definite-init instead of -memory-promotion, rename the
entrypoint for the pass to match, and tidy various and sundry comments.


Swift SVN r8927
2013-10-04 18:45:09 +00:00
Joe Groff
82a18333ed SIL: Purge SpecializeInst.
Make ApplyInst and PartialApplyInst directly take substitutions for generic functions instead of trying to stage out substitutions separately. The legacy reasons for doing this are gone.

Swift SVN r8747
2013-09-28 00:15:45 +00:00
Anna Zaks
992e95ee0c Add -emit-verbose-sil argument to sil-opt.
Swift SVN r8107
2013-09-11 20:54:28 +00:00
Stephen Lin
a0f44d50b2 Update remaining references to [force_inline] to [transparent]
Swift SVN r7627
2013-08-27 18:46:03 +00:00
Chris Lattner
e1855fd3a5 move SIL verification logic to SIL/Verifier.cpp and change
sil-opt to run the verifier after every sil pass it runs.


Swift SVN r7477
2013-08-22 21:27:19 +00:00
Stephen Lin
12e9086893 Initial implementation of mandatory inlining pass; non-recursive inlining, single basic blocks, no diagnosis of circular inlining
Swift SVN r7241
2013-08-14 22:30:20 +00:00
Anna Zaks
342dff1c80 [SIL CCP] Add the early constant propagation pass skeleton.
The pass folds a single operation: int_sadd_with_overflow and issues an
error on detectable overflow.

Swift SVN r7204
2013-08-13 17:36:35 +00:00
Chris Lattner
1d05280a2a Fix -verify mode in sil-opt to not capture diagnostics produced while
*parsing* the .sil file.  If any errors happen while parsing the sil
file, report them immediately and return with an error.



Swift SVN r7005
2013-08-07 21:51:14 +00:00
Chris Lattner
8b56b861b5 give sil-opt a -verify mode. Not particularly useful yet, since all source
locations for sil instructions have no location.


Swift SVN r6987
2013-08-07 18:20:31 +00:00
Chris Lattner
b3fadfc31b Add the outline of a new SIL memory promotion pass. This is what will handle
definite initialization, promoting boxes to stack, building ssa, and doing definite
initialization.

I'll build this in place, then kill off the other two passes when this subsumes them.


Swift SVN r6903
2013-08-05 16:39:26 +00:00
Chris Lattner
ad2d69b8dc fix sil-opt to stop running if it sees a parse error.
Swift SVN r6876
2013-08-03 04:26:15 +00:00
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
Argyrios Kyrtzidis
5536e61e59 [Frontend] Keep a list of input files in CompilerInvocation and create input buffer IDs as part of CompilerInstance::setup().
Swift SVN r6497
2013-07-23 14:49:31 +00:00
Argyrios Kyrtzidis
200e64d8c2 [Frontend] Refactor CompilerInvocation to be a pure settings object.
This mainly removes the extraneous DiagnosticEngine and SourceMgr from CompilerInvocation.
Instances of these can be found via the CompilerInstance object.

Swift SVN r6496
2013-07-23 14:49:29 +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
ef75f4f4e1 tidy this up.
Swift SVN r6471
2013-07-22 21:19:08 +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
e0f19cfb4e Feedback from Dmitri
Swift SVN r6466
2013-07-22 20:42:11 +00:00
Chris Lattner
988e3b1842 Add a new sil-opt tool, which will be the SIL analog to the LLVM 'opt' tool.
Swift SVN r6463
2013-07-22 19:56:03 +00:00