Commit Graph

242 Commits

Author SHA1 Message Date
Erik Eckstein
3ba935605e SimplifyCFG: fix try_apply -> apply transformation for indirect error results
Indirect error results must not be included in the final apply arguments which they are not present in the callee.
2023-11-27 08:51:12 +01:00
Slava Pestov
05ccd9734c SIL: Introduce ThrowAddrInst 2023-10-31 16:58:54 -04:00
Tony Allevato
5f5b24f96e [C++20] Make operator{==,!=}s const.
In C++20, the compiler will synthesize a version of the operator
with its arguments reversed to ease commutativity. This reversed
version is ambiguous with the hand-written operator when the
argument is const but `this` isn't.
2023-10-03 17:10:57 -04:00
Meghana Gupta
9311e948a5 Avoid unnecessary block arguments in SimplifyCFG::threadEdge and SimplifyCFG::simplifyThreadedTerminators 2023-08-17 10:33:22 -07:00
Meghana Gupta
bbd6a87e2b Fix simplifyArguments for a few edges cases in OSSA 2023-08-16 23:14:36 -07:00
Meghana Gupta
93d6f93435 Fixes to SimplifyCFG::threadEdge for OSSA 2023-08-14 11:36:05 -07:00
Meghana Gupta
05c7d64511 We don't consider it profitable to jump thread when we could optimize arc in OSSA.
Copy propagation should be able to handle such cases without jump threading.
2023-08-14 11:36:04 -07:00
Meghana Gupta
e3a98e88f3 Add new flags to enable specific SimplifyCFG operations 2023-08-14 11:36:04 -07:00
Meghana Gupta
a303bb4519 Disable SimplifyCFG::tailDuplicateObjCMethodCallSuccessorBlocks in OSSA
Support for this needs to be added
2023-08-14 11:36:04 -07:00
Meghana Gupta
bf68e3ff39 Disable ArgumentSplitter for non trivial types in ossa 2023-08-14 11:36:04 -07:00
Evan Wilde
83b044f5fb Migrating LLVM API usage on main
This patch migrates the compiler off of the deprecated LLVM APIs where I
can.

 - APInt::getAllOnesValue -> APInt::getAllOnes
 - APInt::getNullValue -> APInt::getZero
 - APInt::isNullValue -> APInt::isZero
 - APInt::getMinSignedBits -> APInt::getSignificantBits
 - clang::Module::submodule_{begin,end} -> clang::Module::submodules
2023-07-13 11:22:35 -07:00
Nate Chandler
b9b286eff2 [Test] Ensourced simplify-cfg-try-jump-threading.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
f1d61afdfb [Test] Ensourced simplify-cfg-simplify....
-term-with-identical-dest-blocks.  Moved the test next to the code it
calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
736b1afb4d [Test] Ensourced simplify-cfg-simplify-switch....
-enum-unreachable-blocks.  Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
d57b1e5fee [Test] Ensourced simplify-cfg-simplify-switch....
-enum-on-objc-class-optional.  Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
49bc5a66d4 [Test] Ensourced simplify-cfg-simplify-switch....
-enum-block.  Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
bf229c357e [Test] Ensourced simplify-cfg-canonicalize....
-switch-enum.  Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
df02726e7b [Test] Ensourced simplify-cfg-simplify-block-args.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
bc909e5b28 [Test] Ensourced simplify-cfg-simplify-argument.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Meghana Gupta
16c300c2af Remove OwnershipForwardingConversionInst, ConversionInst.
Add new ConversionOperation abstraction, use this in place of ConversionInst
2023-06-15 10:53:28 -07:00
Meghana Gupta
5d401fb70a Remove select_value SIL instruction 2023-06-13 14:13:43 -07:00
Meghana Gupta
1dc713e2f7 Add new flags "reborrow" and "escaping" to SILArgument.
"reborrow" flag on the SILArgument avoids transitive walk over the phi operandsi
to determine if it is a reborrow in multiple utilities.
SIL transforms must keep the flag up-to-date by calling SILArgument::setReborrow.
SILVerifier checks to ensure the flag is not invalidated.

Currently "escaping" is not used anywhere.
2023-05-11 12:31:37 -07:00
Erik Eckstein
edce513580 SIL: simplify replaceBranchTarget
Instead of re-creating all kind of terminator instructions, just re-assign the terminator's successor.
2023-01-16 18:55:35 +01:00
Meghana Gupta
dac6c0303f Add tests for simple jump threading 2023-01-08 00:15:17 -08:00
Meghana Gupta
5d2967ca75 Fix SimplifyCFG::simplifySwitchEnumOnObjcClassOptional for OSSA 2023-01-08 00:15:17 -08:00
Meghana Gupta
cdbd0f4743 Fix SimplifyCFG::simplifyArgs for OSSA 2023-01-08 00:15:12 -08:00
Meghana Gupta
3660a1e6a9 Remove borrow scope adjustment for @guaranteed phi args 2023-01-06 23:50:07 -08:00
Meghana Gupta
900d8c3f63 Add ossa unit tests for SimplifyCFG::simplifyTermWithIdenticalDestBlocks 2023-01-06 23:50:07 -08:00
Meghana Gupta
73cd7a9dc1 Add ossa unit tests for SimplifyCFG::simplifySwitchEnumUnreachableBlocks 2023-01-06 23:50:07 -08:00
Meghana Gupta
1fc0d0aba1 SimplifyCFG: Modify DestBB before replacing branch target 2023-01-06 23:50:07 -08:00
Meghana Gupta
94f8841374 Fix SimplifyCFG::simplifySwitchEnumBlock for OSSA 2023-01-06 23:50:07 -08:00
Meghana Gupta
ff4ab7de11 Enable SimplifyCFG::canonicalizeSwitchEnums and add unit tests 2022-10-21 23:08:43 -07:00
Meghana Gupta
97013100dc [NFC] Move SimplifyCFG class to its own header so that it can be accessed by the unit test infra 2022-10-21 16:48:28 -07:00
Erik Eckstein
ecbcacdecf SIL Analysis: Rename InvalidationKind::FunctionData to InvalidationKind::Effects
This invalidation kind is used when a compute-effects pass changes function effects.
Also, let optimization passes which don't change effects only invalidate the `FunctionBody` and not `Everything`.
2022-10-20 09:20:28 +02:00
Andrew Trick
8f34d9cc2f Add a comment regarding an optimizer rule for self-loops. 2022-10-04 13:27:48 -07:00
Josh Soref
730b16c569 Spelling siloptimizer
* access
* accessed
* accesses
* accessor
* acquiring
* across
* activated
* additive
* address
* addresses'
* aggregated
* analysis
* and
* appropriately
* archetype
* argument
* associated
* availability
* barriers
* because
* been
* beginning
* belongs
* beneficial
* blocks
* borrow
* builtin
* cannot
* canonical
* canonicalize
* clazz
* cleanup
* coalesceable
* coalesced
* comparisons
* completely
* component
* computed
* concrete
* conjunction
* conservatively
* constituent
* construct
* consuming
* containing
* covered
* creates
* critical
* dataflow
* declaration
* defined
* defining
* definition
* deinitialization
* deliberately
* dependencies
* dependent
* deserialized
* destroy
* deterministic
* deterministically
* devirtualizes
* diagnostic
* diagnostics
* differentiation
* disable
* discipline
* dominate
* dominates
* don't
* element
* eliminate
* eliminating
* elimination
* embedded
* encounter
* epilogue
* epsilon
* escape
* escaping
* essential
* evaluating
* evaluation
* evaluator
* executing
* existential
* existentials
* explicit
* expression
* extended
* extension
* extract
* for
* from
* function
* generic
* guarantee
* guaranteed
* happened
* heuristic
* however
* identifiable
* immediately
* implementation
* improper
* include
* infinite
* initialize
* initialized
* initializer
* inside
* instruction
* interference
* interferes
* interleaved
* internal
* intersection
* intractable
* intrinsic
* invalidates
* irreducible
* irrelevant
* language
* lifetime
* literal
* looks
* materialize
* meaning
* mergeable
* might
* mimics
* modification
* modifies
* multiple
* mutating
* necessarily
* necessary
* needsmultiplecopies
* nonetheless
* nothing
* occurred
* occurs
* optimization
* optimizing
* original
* outside
* overflow
* overlapping
* overridden
* owned
* ownership
* parallel
* parameter
* paths
* patterns
* pipeline
* plottable
* possible
* potentially
* practically
* preamble
* precede
* preceding
* predecessor
* preferable
* preparation
* probably
* projection
* properties
* property
* protocol
* reabstraction
* reachable
* recognized
* recursive
* recursively
* redundant
* reentrancy
* referenced
* registry
* reinitialization
* reload
* represent
* requires
* response
* responsible
* retrieving
* returned
* returning
* returns
* rewriting
* rewritten
* sample
* scenarios
* scope
* should
* sideeffects
* similar
* simplify
* simplifycfg
* somewhat
* spaghetti
* specialization
* specializations
* specialized
* specially
* statistically
* substitute
* substitution
* succeeds
* successful
* successfully
* successor
* superfluous
* surprisingly
* suspension
* swift
* targeted
* that
* that our
* the
* therefore
* this
* those
* threshold
* through
* transform
* transformation
* truncated
* ultimate
* unchecked
* uninitialized
* unlikely
* unmanaged
* unoptimized key
* updataflow
* usefulness
* utilities
* villain
* whenever
* writes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-10-03 18:31:33 -04:00
Erik Eckstein
653b6ecc33 fix a crash/hang in SimplifyCFG.
Jump threading in an unreachable CFG region can lead to a crash (in an assert compiler) or hang (in an no-assert compiler) in `ValueBase::replaceAllUsesWith`.

Unfortunately I couldn't come up with an isolated SIL test case.

rdar://92267349
2022-04-25 16:48:59 +02:00
Andrew Trick
2fd4de411e [SIL-opaque] Removed [Unconditional]CheckedCastValue 2022-03-22 17:04:13 -07:00
Andrew Trick
83b01d8ebe Improve the SILPhiArgument API
This subclass of SILArgument should be eliminated--it's not always a
phi, and whether it is a "phi argument" has nothing whatsoever to do
with the opcode. That is a property of a value's uses, not a property of the
value.

Until then, provide a logical and useful API within the type. This
often avoids the need to explicitly cast to a SILPhiArgument type and
avoids a lot of boilerplate in code that deals with phis.

Note: PhiOperand and PhiValue are improved abstractions on top of this
API. But the SILArgument-level API is still an important bridge
between SILArgument and other phi abstractions.
2022-02-15 13:28:46 -08:00
Erik Eckstein
8fe36eedd8 SILPassManager: improve bisecting for debugging the optimizer
* Add the possibility to bisect the individual transforms of SILCombine and SimplifyCFG.
   To do so, the `-sil-opt-pass-count` option now accepts the format `<n>.<m>`, where `m` is the sub-pass number.
   The sub-pass number limits the number of individual transforms in SILCombine or SimplifyCFG.

* Add an option `-sil-print-last` to print the SIL of the currently optimized function before and after the last pass, which is specified with `-sil-opt-pass-count`.
2022-02-09 13:25:30 +01:00
Andrew Trick
55e0523b95 Prepare replaceAllUses[AndErase]() API support for terminators
Setup the API for use with SimplifyCFG first, so the OSSA RAUW utility
can be redesigned around it. The functionality is disabled because it
won't be testable until that's all in place.
2021-10-13 10:57:15 -07:00
Andrew Trick
a5b1b5c3f8 SILOptimizer OSSA support for switch_enum & checked_cast_br
To create OSSA terminator results, use:
- OwnershipForwardingTermInst::createResult(SILType ValueOwnershipKind)
- SwitchEnumInst::createDefaultResult()

Add support for passing trivial values to nontrivial forwarding
ownership. This effectively converts None to Guaranteed ownership.

This is essential for handling ".none" enums as trivial values while
extracting a nontrivial payload with switch_enum. This converts None
to Guaranteed ownership. Generates a copy if needed to convert back to
Owned ownership.
2021-09-07 22:50:46 -07:00
Meghana Gupta
5b3c687bf1 Fix an edge case in OSSA RLE for loops
In OSSA RLE for loops, in certain cases SSAUpdater will not create a new
SILPhiArgument to be used as the forwarding value. Based on dominator info
it may return the newly copied available value as the forwarding value.
This newly copied available value in the dominating predecessor
will have destroy values at leaking blocks.

Rename makeNewValueAvailable to makeValueAvailable and handle users so that only
additional required destroy_values are inserted.
2021-08-31 09:47:42 -07:00
Andrew Trick
19007a63b1 SimplifyCFG add tracing 2021-07-17 19:37:12 -07:00
Andrew Trick
ca1c46b09a OSSA: SimplifyCFG. Add DeadEndBlocks and pass it to jump-threading. 2021-07-17 18:31:25 -07:00
Andrew Trick
e6ec4e4691 SimplifyCFG OSSA support for trivial switch_enum. 2021-07-17 18:31:25 -07:00
Meghana Gupta
54933624f1 Add IsInfiniteJumpThreadingBudget for testing 2021-07-17 18:31:25 -07:00
Andrew Trick
74e928b39e Add -enable-ossa-simplifycfg and -enable-ossa-jumpthread-simplifycfg
as temporary flags to gradually stage in OSSA tests.
2021-07-17 18:31:25 -07:00
Meghana Gupta
c46acc0f9c OSSA: SimplifyCFG. Only jump thread for trivial dest block args.
Support for non-trivial args will be added separately.
2021-07-17 18:31:25 -07:00
Andrew Trick
8a45b5fa2c OSSA: Support SimplifyCFG tryJumpThreading for testing.
This will be gated by a testing flag while tests are staged in.
2021-07-17 18:31:25 -07:00