Commit Graph

74 Commits

Author SHA1 Message Date
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
Anna Zaks
60515e972f [CCP] Add folding of more binary operations (shifts, bitwise &|^, op on floats).
Among other benefits, addresses radar://15285629

Swift SVN r10646
2013-11-22 00:03:36 +00:00
Anna Zaks
ead8ede226 [CCP] refactor: rename + method extract
Swift SVN r10645
2013-11-22 00:03:35 +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
Anna Zaks
f4e6b746f5 Better handling of overflow diagnostics when user types are not available.
Currently, we use heuristics to determine if the conversion errors come from directly inlining the std integer types. However, if those operations are wrapped in another transparent function, we will not see the user-visible integer types anymore, so we fall back to Builtin types. Enhance the diagnostics in that case to specify if the sign-agnostic Builtin types are signed or unsigned.

This reverts r10484 and adds test cases.

Swift SVN r10512
2013-11-16 01:26:53 +00:00
Joe Groff
35df6b9c25 Snip unused variable.
Swift SVN r10484
2013-11-15 01:22:11 +00:00
Anna Zaks
f651e342c1 Add static checking for signed <-> unsigned int conversions (for same size ints).
Swift SVN r10477
2013-11-15 00:16:18 +00:00
Joe Groff
19457c12ea Give Builtin.Word an abstract size.
Instead of hardcoding Builtin.Word to be an alias for Builtin.Int64, make it its own type of abstract pointer width.

- Change BuiltinIntegerType's width representation to accommodate abstract widths.

- In the AST and in SIL, store values of the types as the greatest supported size for the abstract width (64 bits for a pointer).

- Add some type safety to the ([sz]ext|trunc)(OrBitCast)? builtins that they're used appropriately given the upper and lower bounds of the abstract sizes they're working with.

- Now that Builtin.Word is a distinct type, give it its own mangling.

- In IRGen, lower pointer-sized BuiltinIntegerType appropriately for the target, and truncate lowered SIL values if necessary.

Fixes <rdar://problem/15367913>.

Swift SVN r10467
2013-11-14 19:56:26 +00:00
Anna Zaks
34f5e43b09 [CCP] Diagnose truncation errors in int to int conversions.
Here we add compile time checks similar to the ones performed at runtime.

Swift SVN r10446
2013-11-14 01:35:22 +00:00
Anna Zaks
b687c3ce9c Add runtime integer truncation checking to the conversion constructors
Add new builtins(by generalizing, renaming, and extending the builtins used for compile time integer literal checking). These new builtins truncate integers and check for overflow/truncation errors at runtime. Use these for FixedPoint conversion constructors.

Fix a routine in stdlib's String implementation and a test that relied on bitwise behavior of the constructors (and triggered overflows).

TODO:
- Teach CCP about these to get static checking.
- Add special builtins for same size signed <-> unsigned conversions.

Swift SVN r10432
2013-11-13 21:54:34 +00:00
Anna Zaks
084bdfd05f Change the signature of the trunc builtins to return a tuple containing teh overflow bit as well as the result.
This is a first step in generalizing the builtin to handle non-constant int to int truncations.

Swift SVN r10341
2013-11-11 21:20:04 +00:00
Greg Parker
49e1856c13 Add Builtin.[trunc|zext|sext]OrBitCast() instead of hijacking the true casts.
Swift SVN r9985
2013-11-06 03:15:04 +00:00
Chris Lattner
beab485db3 enhance the constant folding pass a bit to be smarter about folding
tuple-producing results (like those produced by folding overflow builtins).

Before the pass would just RAUW the apply_inst with a tuple_inst, but this
would leave around a bunch of tuple extracts.  Now we seek and destroy them.

This unblocks other transformations and allows the stdlib to shrink by another
1700 LOC.


Swift SVN r9900
2013-11-03 06:01:13 +00:00
Chris Lattner
7403194b56 minor simplifications, no functionality change.
Swift SVN r9862
2013-11-01 00:07:10 +00:00
Chris Lattner
c118613de3 Fix SILValue use_iterators to type the user as a SILInstruction, not just a ValueBase.
There are no values other than instructions that can use other values.  BBArguments are
defs, not uses.  This eliminates a bunch of casts in clients that use getUser().


Swift SVN r9701
2013-10-27 23:32:14 +00:00
Anna Zaks
b2034f7a46 [CCP] Fold integer binary predicates.
Swift SVN r9642
2013-10-24 18:23:04 +00:00
Anna Zaks
594e2f5781 [CCP] Rework CCP to use an inverted algorithm.
Instead of adding all the instructions into the WorkList to begin with,
add only the constants and try to fold their users. Each time a user can
be folded, add it to the WorkList. This keeps the WorkList smaller.

The inverted algorithm also allows to simplify the handling of struct_extract
and tuple_extract.

(as suggested by Chris in comments on r9545)

Swift SVN r9598
2013-10-22 21:10:40 +00:00
Chris Lattner
91c7cea310 Remove the SILModule& argument from a few methods in SILInstruction.h.
Instructions know which module they came from, so there is no need to
pass it in.



Swift SVN r9584
2013-10-22 11:06:50 +00:00
Chris Lattner
c538feb61d some more minor tidying up: use StringRef instead of std::string in
one place, and use types already available instead of reconstructing
them (to simplify code).



Swift SVN r9583
2013-10-22 10:49:28 +00:00
Chris Lattner
0dd231ffff indentation: don't indent cases under switch statements. Even thought
Xcode insists on doing this, it is "wrong".


Swift SVN r9548
2013-10-21 18:23:44 +00:00
Chris Lattner
511931859e Some belated code review for the constant prop pass. Overall
the algorithm looks great, I made a number of minor stylistic
and comment changes, used some simpler APIs, and simplified
some things.  The only functionality change is a corner case
correctness bug where it looks like the struct/tuple extraction
folding logic in constantFoldInstruction could return the wrong
result in some corner case.


Swift SVN r9547
2013-10-21 18:21:27 +00:00
Anna Zaks
65a4766c29 Demote the integer literal overflow error into warning in some cases.
As a temporary workaround for radar://15236662.

Swift SVN r9395
2013-10-16 00:56:26 +00:00
Anna Zaks
38745bffa7 Add division by zero and integer division overflow diagnostics.
Addresses radar://15225468.

Swift SVN r9387
2013-10-15 23:13:13 +00:00
Anna Zaks
cf2ff89af5 Add type info to the constant expression overflow message
(As per Jordan's and Dmitry's code review for r9033.)

Swift SVN r9370
2013-10-15 20:22:29 +00:00
Anna Zaks
740fc0a9d9 Revert "Revert "Reimplement integer arithmetic overflow checking to use special, error on overflow builtins""
(This only fails under -DSWIFT_OPTIMIZED=NO; most likely due to an llvm bug.)

We've decided that it's best to specialize each arithmetic builtin that could overflow, instead of calling a separate generic "staticReport" builtin and passing it enough info to produce the message. The main advantage of this approach is that it would be possible for the compiler to customize the message and better link it to the builtin that overflows. For example, the constants that participated in the computation could be printed. In addition, less code will be generated and the compiler could, in the future, automatically emit the overflow diagnostics/trap at runtime.

This patch introduces new versions of op_with_overflow swift builtins. Which are lowered to llvm.op_with_overflow builtins in IRGen after the static diagnostics. If the last argument to the builtins evaluates to true, the overflow is unintentional. CCP uses the builtins to diagnose the overflow detectable at compile time. FixedPoint is changed to rely on these in implementation of primitive arithmetic operations.

Swift SVN r9328
2013-10-14 21:42:33 +00:00
Dmitri Hrybenko
158ed79f34 Adds overflow checking for floating point literals. The approach is the same
as for integer literals.


Swift SVN r9325
2013-10-14 19:47:38 +00:00
Dmitri Hrybenko
4a92814a67 Fix typo in comments
Swift SVN r9257
2013-10-12 11:26:16 +00:00