Commit Graph

66 Commits

Author SHA1 Message Date
Arnold Schwaighofer
48b6588bbb Teach DCE about ThrowInst and TryApplyInst
Part of rdar://20543286

Swift SVN r27302
2015-04-15 00:43:02 +00:00
John McCall
6d8fff9c06 Parsing and basic structure of try_apply. Not yet properly
threaded into IRGen; tests to follow when that's done.

I made a preliminary effort to make the inliner do the
right thing with try_apply, but otherwise tried to avoid
touching the optimizer any more than was required by the
removal of ApplyInstBase.

Swift SVN r26747
2015-03-31 02:41:03 +00:00
John McCall
1ffb87bb1f Implement a 'throw' instruction in SIL.
Swift SVN r26668
2015-03-28 02:00:20 +00:00
Nadav Rotem
240ff14db1 Split DominanceAnalysis into Dom and PDom using FunctionAnalysisBase.
This commit splits DominanceAnalysis into two analysis (Dom and PDom) that
can be cached and invalidates using the common FunctionAnalysisBase interface
independent of one another.

Swift SVN r26643
2015-03-27 20:54:28 +00:00
Nadav Rotem
ae75f152dc Teach DCE to invalidate branches and calls only if changes were made.
Swift SVN r26549
2015-03-25 19:47:28 +00:00
Nadav Rotem
d78b376d07 [passes] Replace the old invalidation lattice with a new invalidation scheme.
The old invalidation lattice was incorrect because changes to control flow could cause changes to the
call graph, so we've decided to change the way passes invalidate analysis.  In the new scheme, the lattice
is replaced with a list of traits that passes preserve or invalidate. The current traits are Calls and Branches.
Now, passes report which traits they preserve, which is the opposite of the previous implementation where
passes needed to report what they invalidate.

Node: I tried to limit the changes in this commit to mechanical changes to ease the review. I will cleanup some
of the code in a following commit.

Swift SVN r26449
2015-03-23 21:18:58 +00:00
Mark Lacey
fb56923ace Add a couple statistics to the DCE pass.
Swift SVN r26098
2015-03-13 08:34:54 +00:00
Arnold Schwaighofer
951dc2875a Nuke isSideEffectFree
We can now compute the same result with Inst.mayHaveSideEffects(). NFC.

Swift SVN r25742
2015-03-04 05:03:44 +00:00
Dmitri Hrybenko
61286f0260 Fix warnings produced by a newer version of Clang
Swift SVN r25257
2015-02-12 23:50:47 +00:00
Adrian Prantl
95eec5a155 Fix Test for: DCE is dropping debug intrinsics, Was: DebugInfo/closure-multivalue test is failing
In order to not completely loose testcoverage while rdar://problem/18709125
is under investiagtion, add a special flag for enabling debug value
liveness.

Patch by Michael Gottesman!

<rdar://problem/19267059>

Swift SVN r24416
2015-01-14 18:37:39 +00:00
Arnold Schwaighofer
aa2d900802 DeadCodeElimination: Invalidating the CFG invalidates Instructions
Swift SVN r24262
2015-01-08 03:12:52 +00:00
Arnold Schwaighofer
3dfe6b5a6a DeadCodeElimintation: call invalidateAnalysis(CFG) because we change the CFG
No test case. This was discovered by running a custom compilation pipeline (see
radar).

rdar://19321277

Swift SVN r24254
2015-01-08 00:52:40 +00:00
Roman Levenstein
c8d180e660 Generalize the switch_int instruction into switch_value instruction, which may switch on arguments of builtin integer types or function types. The later is required for implementing a more efficient speculative devirtualizaiton implementation. Implement lowering of switch_value into LLVM code. In case of integer operands, it reuses LLVM's switch optimizations. Support for switching on function types is not yet bullet-proof and will be refined in the subsequent patches.
rdar://18508812

Swift SVN r23042
2014-10-31 22:55:56 +00:00
Adrian Prantl
c41b30299f Audit all SILPasses to ensure that new instructions are never created
without a valid SILDebugScope. An assertion in IRGenSIL prevents future
optimizations from regressing in this regard.
Introducing SILBuilderWithScope and SILBuilderwithPostprocess to ease the
transition.

This patch is large, but mostly mechanical.
<rdar://problem/18494573> Swift: Debugger is not stopping at the set breakpoint

Swift SVN r22978
2014-10-28 01:49:11 +00:00
Joe Groff
e3f9a2035c SIL: Move SILGen and passes over to use "builtin" instead of "apply (builtin_function_ref)".
Swift SVN r22785
2014-10-15 23:37:22 +00:00
Roman Levenstein
78aee1aee7 [sil-dce] Fix a bug in DCE. Replace dead BB args of basic blocks with Undef.
rdar://18572960

Swift SVN r22660
2014-10-10 11:07:20 +00:00
Michael Gottesman
0f7053bd01 Remove SILBasicBlock::getBBArgIndex(SILArgument *) in favor of SILArgument::getIndex().
The index is a property of the argument. There is no reason from a modeling
perspective to go through the BB to get it.

Swift SVN r21338
2014-08-21 04:06:19 +00:00
John McCall
452b023e3f Properly analyze CheckedCastAddrBranch instructions in DCE.
In addition, metaprogram non-terminators instead of using
a default case.

Swift SVN r19074
2014-06-22 05:00:59 +00:00
Mark Lacey
8cbefaeef4 During DCE, eliminate branches to dead regions of code.
Enhances DCE to make unreachable those regions of code that have no
effect.

This allows loops like:
  for i in 0..n {
    // do nothing
  }
to be eliminated by first running DCE to make the loop unreachable, and
the CFG simplification to actually delete the blocks that make up the
loop (assuming we're talking -Ofast and cond_fails have been removed).

What's especially nice is that this can make unreachable several levels
of dead code, including deleting the code that produces the values used
to conditionally branch to other dead code, all in a single pass rather
than needing to iterate between DCE and CFG simplification to achieve
the same effect. For example, this:

  func f(b: Bool, c: Bool, d: Bool) {
    if (b && c) {
      // nothing useful here
      if (c && d) {
        // nothing useful here
        if (b && d) {
          // nothing useful here
        }
      }
    }
  }

is effectively reduced to:
  func f(b: Bool, c: Bool, d: Bool) {
    goto end      // pretend for a second we have goto
    if (b && c) {
      // nothing useful here
      if (c && d) {
        // nothing useful here
        if (b && d) {
          // nothing useful here
        }
      }
    }
    end:
  }
after a single pass, after which unreachable code elimination reduces
this to:
  func f(b: Bool, c: Bool, d: Bool) {
  }

Swift SVN r18664
2014-05-30 00:00:11 +00:00
Mark Lacey
8fe89071f5 Add some debug output for dead code elimination.
Swift SVN r18632
2014-05-26 06:18:22 +00:00
Mark Lacey
9917e62b0b Make a helper functions static.
Swift SVN r18631
2014-05-26 06:18:21 +00:00
Mark Lacey
77eeb6b6bb Coding style tweaks.
Swift SVN r18616
2014-05-24 07:28:51 +00:00
Mark Lacey
8156008cd8 Add a dead code elimination optimization pass.
In a loop like this:
  var j = 2
  for var i = 0; i < 100; ++i {
    j += 3
  }
it will completely eliminate j.

It does not yet support rewriting conditional branches as unconditional
branches in the cases where only empty blocks are control dependent on
an edge. Once this support is added, it will also completely eliminate
the loop itself.

Swift SVN r18615
2014-05-24 07:02:18 +00:00
Mark Lacey
79b727a22f Rename DeadCodeElimination.cpp to DiagnoseUnreachable.cpp.
Also rename dead_code_elimination.sil to diagnose_unreachable.sil.

This more accurately reflects what this file implements, and makes way
for adding a new DeadCodeElimination.cpp that does classic dead (as
opposed to unreachable) code elimination.

I will fix up the contents of the files as a separate step.

Swift SVN r18613
2014-05-24 07:02:14 +00:00
Mark Lacey
9c00cd72f2 Simplify if/else-return to if-return.
Small code clean-up. NFC.

Swift SVN r18504
2014-05-21 19:35:15 +00:00
Mark Lacey
67abd61547 Fix code comment to reflect what actually happens.
Swift SVN r18503
2014-05-21 19:35:15 +00:00
Mark Lacey
d3838dde1d Fix 80-column violation.
Swift SVN r18502
2014-05-21 19:35:14 +00:00
Arnold Schwaighofer
099c80bbd4 NoReturn folding: Set unreachable uses in different basic blocks to undef
The pass assumed that it is safe to delete instructions following a noreturn
call. If the instruction has an outside block user this would cause an failure
because we were deleting an instruction with uses.

Having control flow with uses from instructions after a noreturn call can happen
if we inline a transparent function after the noreturn call.

rdar://16852358

Swift SVN r17813
2014-05-09 23:29:56 +00:00
Joe Groff
79bbf17f42 Add Builtin.unreachable().
This will allow stdlib code to explicitly mark branches it knows to be unreachable. Make this work with SIL diagnostics by lowering the builtin to a normal builtin_function_ref/apply in SILGen, and special-case handling the builtin in DCE by removing the apply along with the following dead instructions when we recognize an unreachable block.

Swift SVN r16745
2014-04-24 05:00:00 +00:00
Mark Lacey
1452d24671 Small cleanup: Remove unnecessary calls to getDef(), mostly in dyn_cast<>(...).
Swift SVN r16235
2014-04-11 23:05:16 +00:00
Chris Lattner
8869767260 Implement the rest of rdar://16242700
Fix a phase ordering problem: SILGen of a noreturn function doesn't drop an unreachable after the function,
and doing so is problematic for various reasons (all expressions would have to handle their insertion point
vaporizing, and would have to emit unreachable code diagnostics).  Instead, run a simple pass that folds
noreturn calls and diagnoses unreachable code, and do it before DI.  This prevents DI from seeing false
paths, and rejecting what seems like invalid code.



Swift SVN r14711
2014-03-06 01:29:32 +00:00
Dmitri Hrybenko
ba6548b072 Track uptstream LLVM API change: llvm::tie() was removed, use std::tie() instead
Swift SVN r14573
2014-03-02 13:53:19 +00:00
Andrew Trick
731000b4cd Added -sil-print-all and -sil-verify-all options.
Swift SVN r13662
2014-02-07 23:07:11 +00:00
Nadav Rotem
1ef0d157ca PassManager: Inject the function/module into the Transformation.
Now the pass does not need to know about the pass manager. We also don't have
runOnFunction or runOnModule anymore because the trnasformation knows
which module it is processing. The Pass itself knows how to invalidate the
analysis, based on the injected pass manager that is internal to the
transformation.

Now our DCE transformation looks like this:

class DCE : public SILModuleTransform {
  void run() {
    performSILDeadCodeElimination(getModule());
    invalidateAnalysis(SILAnalysis::InvalidationKind::All);
  }
};





Swift SVN r13598
2014-02-06 22:11:21 +00:00
Nadav Rotem
99b075c32a Rename SILFunctionTrans -> SILFunctionTransform
Swift SVN r13536
2014-02-06 01:32:10 +00:00
Nadav Rotem
f8c7b54d28 Delete the unused performXXX() functions.
Swift SVN r13531
2014-02-06 00:57:28 +00:00
Michael Gottesman
631f9326ab [PM] Change enum => enum class everywhere in the PM code. Additionally fix some typos.
Swift SVN r13507
2014-02-05 21:25:15 +00:00
Nadav Rotem
1df8e93bbb Convert the diagnostic methods into passes.
Swift SVN r13503
2014-02-05 20:30:49 +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
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
Chris Lattner
b91d335c10 teach DCE's "isUserCode" predicate to ignore autogenerated code, like the
conditional destroy logic generated by DI.  This silences a bogus warning 
building the stdlib, in which DCE is proved that conditional destroy logic
wasn't needed.


Swift SVN r10735
2013-12-02 22:26:23 +00:00
Anna Zaks
76bfe8de6f [DCE] Add more stats.
Swift SVN r10652
2013-11-22 00:45:28 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Stephen Lin
8f53824a24 DeadCodeElimination: eliminate eraseAndCleanup and call recursivelyDeleteTriviallyDeadInstructions directly, which is also fixed to do reference dropping, checking for dead operands, and instruction erasures in the right order. No intended functionality change.
Swift SVN r10464
2013-11-14 19:46:51 +00:00
Chris Lattner
a0c5afa7ff re-commit r9816, allowing DI to delete allocations *in* transparent
functions.  Before it would only delete them once they got inlined,
which is a waste of compile time and serves no purpose.

This exposed a bug in mandatory inlining, which is now fixed.  It
strinks the stdlib by 4500 lines, almost 10%.



Swift SVN r9906
2013-11-03 18:07:39 +00:00
Dmitri Hrybenko
c2425d5afd Revert r9816. It causes three tests to enter an inf loop:
Interpreter/archetype_casts.swift
Interpreter/classes.swift
Interpreter/generic_casts.swift


Swift SVN r9829
2013-10-31 00:01:56 +00:00
Chris Lattner
a667e61fc3 Make the "delete store only stack allocations" logic delete all allocations
in transparent functions.  They will be deleted anyway when they get inlined
into callers, so there is no reason to do the work to carry them around and
inline them, only to delete them.

This shrinks the sil for the stdlib by about 5%: from 71672 lines to 67718 lines.



Swift SVN r9818
2013-10-30 22:07:44 +00:00
Anna Zaks
7d8c212083 Fix a bug in unreachable code diagnostic.
We only know if a block is unreachable after performing reachability analysis on the whole function.

Swift SVN r9807
2013-10-30 20:25:25 +00:00
Chris Lattner
ef93c81ffb Introduce a new SIL-level "undef" value, useful for SIL transformations.
IRGen support is missing, Joe volenteers to implement it.


Swift SVN r9776
2013-10-30 00:58:09 +00:00
Anna Zaks
c46c0ce58c [DCE] Refactor, use more explicit data structures/names.
Swift SVN r9766
2013-10-29 22:27:26 +00:00