Commit Graph

100 Commits

Author SHA1 Message Date
Chris Lattner
16522c3758 fix <rdar://problem/19623566> Obscure diagnostic for assigning negative numbers to unsigned
We now produce:
t.swift:1:15: error: negative integer '-9223372036854775808' overflows when stored into unsigned type 'UInt'
var x: UInt = -0x8000_0000_0000_0000
              ^



Swift SVN r27797
2015-04-27 01:18:47 +00:00
Chris Lattner
fa4f1d86ee Recommit r27756 with an update to diagnostic_constant_propagation_int.swift, which is iOS only.
Swift SVN r27761
2015-04-26 15:56:41 +00:00
Ted Kremenek
4a227f2661 Speculatively revert "fix <rdar://problem/18213320> enum with raw values that are too big are not diagnosed"
This looks like it caused test 'SILPasses/diagnostic_constant_propagation_int.swift' to fail.

Swift SVN r27757
2015-04-26 15:12:58 +00:00
Chris Lattner
d5ae69b276 fix <rdar://problem/18213320> enum with raw values that are too big are not diagnosed
On that testcase, we now generate:

t.swift:8:22: error: integer literal '123456' overflows when stored into 'UInt8'
  case tooFarByFar = 123456
                     ^
t.swift:7:8: error: integer literal '256' overflows when stored into 'UInt8'
  case twoHundredFiftySix
       ^

instead of spitting out some warnings with no source loc (which Xcode eats).


This patch:
 - Propagates source locations for literals when synthesizing code in various places,
   so we get the right diagnostic at the right spot.
 - Improves the constant folding SIL Pass to print the value overflowing, which is
   necessary for cases with an implicit value (like 256 above), and is general goodness
   for the QoI of the diagnostic anyway.



Swift SVN r27756
2015-04-26 06:21:23 +00:00
Roman Levenstein
77580edea5 Re-submit: Enable cast optimizations as a guaranteed optimization.
Fix a few places in diagnose unreachable, which were emitting false diagnostics after enabling this optimization.

This commit does not disable and remove the special-casing for bridging conversions in the CSApply yet. Let's wait a bit and see that everything works properly after my recent cast optimizations changes. If everything is OK, we can remove the code from CSApply.

This time it does not break the Alamofire external project (rdar://20579035).

rdar://20467603

Swift SVN r27513
2015-04-21 00:54:43 +00:00
Mark Lacey
6b3c364738 Revert "Enable cast optimizations as a guaranteed optimization."
This reverts commit r27379. It may have broken some of the external
projects we test.

Swift SVN r27425
2015-04-17 06:19:57 +00:00
Roman Levenstein
7675e614e3 Enable cast optimizations as a guaranteed optimization.
Fix a few places in diagnose unreachable, which were emitting false diagnostics after enabling this optimization.

This commit does not disable and remove the special-casing for bridging conversions in the CSApply yet. Let's wait a bit and see that everything works properly after my recent cast optimizations changes. If everything is OK, we can remove the code from CSApply.

Swift SVN r27379
2015-04-16 20:28:17 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +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
Michael Gottesman
719bbc5746 Remove dead return.
Swift SVN r25652
2015-03-01 04:54:33 +00:00
Michael Gottesman
669cdc537c Create an entrypoint tryToConcatenateStrings and hide the class StringConcatenationOptimizer in Local.cpp.
In every instance, we were just creating the StringConcatenationOptimizer and
then invoking optimize on it. This is a cleaner solution since the details of
how we perform the string concatenation are hidden in Local.cpp instead of being
in a header.

NFC.

Swift SVN r25341
2015-02-17 01:59:13 +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
Luqman Aden
040df3d400 Error out upon trying to shift by an amount larger than or equal to the
type's size.

Fixes <rdar://problem/19622546>

Swift SVN r24832
2015-01-29 23:09:51 +00:00
Luqman Aden
ffca6e8051 Add compile-time diagnostic for overflow on remainder.
Fixes <rdar://problem/19622097>

Swift SVN r24807
2015-01-28 22:41:14 +00:00
Erik Eckstein
4dd44833ea Refactor constant folding: extract constant folding to utility functions.
NFC

I need the constant folding functions for my upcoming changes in the inliner.



Swift SVN r24600
2015-01-21 11:11:36 +00:00
Roman Levenstein
233ed27fa1 [constant-propagation] Perform concatenation of string literals as a guaranteed optimization in constant-folding.
Note that it done in both constant-propagation and in sil-combine.  SILCombine catches cases that are exposed by inlining and other simplifications (which wouldn’t be guaranteed), but the constant prop case handles the guaranteed ones.

rdar://19125926

Swift SVN r23656
2014-12-03 21:46:29 +00:00
Erik Eckstein
54e1071da0 Add a builtin assumeNonNegative.
It returns the argument and specifies that the value is not negative.
It has only an effect if the argument is a load or call.

The effect of this builtin is that for the load/call argument a positive range metadata is created in llvm ir.

I also added a public function _assumeNonNegative(x: Int) -> Int in the stdlib.
To be on the save side, I prefixed it with an underscore. But maybe it makes sense to make it available for all users.



Swift SVN r23582
2014-11-26 09:53:14 +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
Chris Lattner
7081022e7d highlight the ranges of the LHS/RHS of binary expressions when they statically
overflow and diagnosed with an error, e.g.:

ov.swift:2:19: error: arithmetic operation '126 + 2' (on type 'Int8') results in an overflow
let v = Int8(126) + (1+1)
        ~~~~~~~~~ ^ ~~~~~



Swift SVN r22905
2014-10-24 04:04:28 +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
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Joe Groff
45eec9a2e9 Remove 'interface' from the method names of SILFunctionType.
SILFunctionTypes are always interface types now. NFC.

Swift SVN r19952
2014-07-14 22:03:46 +00:00
Pete Cooper
ffae044afe Typo
Swift SVN r18875
2014-06-13 18:29:01 +00:00
Michael Gottesman
617da22507 [constant-propagation] An indexing inst that indexes by 0 is a no-op. Teach constant propagation to simplify it.
rdar://16832529

Swift SVN r17649
2014-05-07 22:45:59 +00:00
Joe Groff
3b4a9d2ba5 Add a 'conditionallyUnreachable' builtin.
This builtin only becomes unreachable when assert_configuration calls have been folded, allowing library-level checks to become unreachable based on the assert level.

Swift SVN r17322
2014-05-03 19:41:40 +00:00
Chris Lattner
e06fbc4fca fix <rdar://problem/16763821> Integer overflow diagnostics refer to the 'Builtin.Blah' types rather than the user-visible types
this un-xfails two tests.


Swift SVN r17068
2014-04-30 04:14:06 +00:00
Arnold Schwaighofer
989d554a45 Add support for an assert_configuration builtin function
This patch adds support for a builtin function assert_configuration that is
replaced by constant progpagation by an appropriate value dependent on a compile
time setting. This replacement can also be disabled when serializing sil for a
library.

Using this mechanism we implement assertions that can  be disabled (or whose
behavior changes) depending on compile time build settings (Debug, Release,
DisableReplacement).

In the standard library we can now write one assert function that uses this
builtin function to provide different compile time selectable runtime behavior.

Example

Assert.swift:

@transparent
func assert<T : LogicValue>(
  condition: @auto_closure () -> T, message: StaticString = StaticString(),

  // Do not supply these parameters explicitly; they will be filled in
  // by the compiler and aren't even present when asserts are disabled
  file: StaticString = __FILE__, line: UWord = __LINE__
) {
  // Only in debug mode.
  if _isDebug() {
    assert(condition().getLogicValue(), message, file, line)
  }
}

AssertCommon.swift:

@transparent
func _isDebug() -> Bool {
  return Int32(Builtin.assert_configuration()) == 0;
}

rdar://16458612

Swift SVN r16472
2014-04-17 22:05:42 +00:00
Michael Gottesman
2feed65c65 [constant-propagation] Teach constant propagation how to fold expect of a constant.
Swift SVN r16389
2014-04-16 02:13:25 +00:00
Michael Gottesman
cffc3d372d [constant-propagation] Refactor constant propagation slightly to disable diagnostics so we can use it in the performance passes to help with branch simplification.
This commit also enables constant propagation in the performance
pipeline.

Since we are close to WWDC, this commit purposefully minimally touches
the pass (despite my hands wanted to refactor it so bad) just enough so
that we get the desired result with minimal in tree turmoil.

rdar://16604715

Swift SVN r16388
2014-04-16 01:49:16 +00:00
Michael Gottesman
78d7d2874e [constant-propagation] Remove from the delete list if we deleted them in recursivelyDeleteTriviallyDeadInstructions.
Also make the constant propagation test not dependent on the stdlib.

Swift SVN r16387
2014-04-16 01:19:26 +00:00
Michael Gottesman
e8f15df254 [constant-propagation] Delete all FoldedUsers in one call to recursivelyDeleteTriviallyDeadInstructions to ensure we don't delete one of those instructions and then attempt to delete them.
Swift SVN r16386
2014-04-16 01:19:25 +00:00
Chris Lattner
001c1890e5 put all the SIL*Transform classes in anonymous namespaces, there is
no need for their symbols to be exported out of their implementation
file.


Swift SVN r14714
2014-03-06 01:49:53 +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
0825258b80 SIL transforms should only invalidate when things change.
-sil-print-all shows a nice readable evolution now.

Oh yeah, and we don't unnecessarilly rerun passes.

Swift SVN r13677
2014-02-08 08:20:45 +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
27a1a63134 Remove unneeded empty virtual destructors.
Swift SVN r13599
2014-02-06 22:24:33 +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
0651b9bbd0 Add a new Dominance Analysis that wraps DomInfo and PDomInfo, and migrate the
passes that use them.



Swift SVN r13571
2014-02-06 07:52:16 +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
Nadav Rotem
a07aed9d1f Change errs() -> dbgs() in a few files.
Swift SVN r12572
2014-01-20 06:36:50 +00:00
Chris Lattner
2063e9b225 Enhance DCE to know that "condfail(false)" is dead.
Enhance constant propagation (a diagnostic pass) to invoke the DCE utility
when producing a condfail(false).

This fixes rdar://15729207.  Before we -emit-sil'd the testcase to:

sil @_TF1t1fFT_Si : $@thin () -> Int64 {
bb0:
  %0 = tuple ()
  %1 = integer_literal $Builtin.Int1, 0           // user: %2
  cond_fail %1 : $Builtin.Int1                    // id: %2
  %3 = integer_literal $Builtin.Int64, 8          // user: %5
  %4 = integer_literal $Builtin.Int1, 0           // user: %6
  %5 = struct $Int64 (%3 : $Builtin.Int64)        // user: %7
  cond_fail %4 : $Builtin.Int1                    // id: %6
  return %5 : $Int64                              // id: %7
}

and now we produce (if you ignore debug_value):

sil @_TF1t1fFT_Si : $@thin () -> Int64 {
bb0:
  %9 = integer_literal $Builtin.Int64, 8          // user: %10
  %10 = struct $Int64 (%9 : $Builtin.Int64)       // user: %11
  return %10 : $Int64                             // id: %11
}




Swift SVN r12490
2014-01-17 18:06:22 +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
Joe Groff
197a1653fd SIL: Start on a StripRuntimeChecks pass.
In the long term we want more detailed configurability of runtime checks, but for our short-term performance work we just want a blanket on/off switch. Add a StripRuntimeChecks SIL pass that, as a start, converts invocations of checked overflow builtins to the equivalent unchecked builtins and kills cond_fails. Expose it through the compiler with a -disable-all-runtime-checks switch.

NB: I haven't tested building the stdlib or running the tests with the switch thrown yet.

Swift SVN r12379
2014-01-16 02:35:16 +00:00
Joe Groff
b2f0b90ba2 SIL: Switch to SILFunctionType interface types in easy-to-reach places.
In nongeneric contexts, or contexts where we only care about the indirectness of parameters or have already substituted the generic parameters for a function, the interface types are interchangeable, so just switch over.

Swift SVN r12044
2014-01-08 04:48:29 +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
27a94b9309 add some helpers to SILBuilder, NFC.
Swift SVN r10699
2013-12-01 05:08:45 +00:00
Chris Lattner
a0fc29b5c3 strength reduce a few calls to get builtin info.
Swift SVN r10691
2013-11-30 00:57:08 +00:00