Commit Graph

8 Commits

Author SHA1 Message Date
Erik Eckstein
d73686a5b5 SILCombine: limit the worklist size for instruction canonicalization
To be precise: don't add instruction uses to the worklist if it already has more than 10000 elements.
This avoids quadratic behavior for very large functions.

rdar://problem/56268570
2020-04-10 20:10:24 +02:00
Andrew Trick
bddc69c8a6 Organize SILOptimizer/Utils headers. Remove Local.h.
The XXOptUtils.h convention is already established and parallels
the SIL/XXUtils convention.

New:
- InstOptUtils.h
- CFGOptUtils.h
- BasicBlockOptUtils.h
- ValueLifetime.h

Removed:
- Local.h
- Two conflicting CFG.h files

This reorganization is helpful before I introduce more
utilities for block cloning similar to SinkAddressProjections.

Move the control flow utilies out of Local.h, which was an
unreadable, unprincipled mess. Rename it to InstOptUtils.h, and
confine it to small APIs for working with individual instructions.
These are the optimizer's additions to /SIL/InstUtils.h.

Rename CFG.h to CFGOptUtils.h and remove the one in /Analysis. Now
there is only SIL/CFG.h, resolving the naming conflict within the
swift project (this has always been a problem for source tools). Limit
this header to low-level APIs for working with branches and CFG edges.

Add BasicBlockOptUtils.h for block level transforms (it makes me sad
that I can't use BBOptUtils.h, but SIL already has
BasicBlockUtils.h). These are larger APIs for cloning or removing
whole blocks.
2019-10-02 11:34:54 -07:00
Stephen Canon
16b9ead9f5 Fix typo NDNEBUG -> NDEBUG to unbreak release builds (#27086) 2019-09-08 23:01:40 -04:00
Nate Chandler
20ee77fb6e [Gardening] Style tweaks to SILInstructionWorklist.
Noted reliance on LTO and eliminated an else following a return.
2019-09-06 13:13:00 -07:00
Nate Chandler
0dce4da603 [SIL] Tweaked worklist instruction methods' style.
Adjusted some variable names.
2019-09-06 11:54:34 -07:00
Nate Chandler
bf8f2666a6 [SIL] Extracted instruction methods from SILCombiner.
SILCombiner has a number of conveniences for inserting, replacing, and
removing instructions that involve modifying a worklist as part of their
behavior.  Here, that functionality is added to the
SILInstructionWorklist; in a subsequent commit it will be removed from
SILCombiner which will then call through to SILInstructionWorklist.
2019-09-06 11:50:54 -07:00
Nate Chandler
d2270b9e85 [SIL] Updated instruction worklist.
- Replaced usage of raw map and vector with the type that wraps the
  combination (BlotSetVector); that provided a significant deduplication
  since a sizeable portion of the worklist's implementation was in
  vector and map management now provided by the BlotSetVector.
- Templated over the type of map and vector used by the blot set vector.
- Added SmallSILInstructionWorklist where the map and vector are
  specified to be SmallDenseMap and SmallVector respectively.
- Replaced usages of bare ValueBase with usages of SILValue.
- Renamed zap to resetChecked.

Added a bit of functionality to BlotSetVector, specifically to support
SILInstructionWorklist:

- Made insert return not just the index that the potentially-inserted
  item is at on return but additionally whether an insertion occurred,
  matching the behavior of llvm::DenseMap::insert.
- Added a method to reserve capacity in the backing vector and map:
  BlotSetVector::reserve.
- Added a method to free extra storage used by the backing vector and
  map: BlotSetVector::clear.
- Modified SmallBlotSetVector's template parameters so that only a value
  and size can be specified--that type will always use SmallVector and
  SmallDenseMap for its superclass' VectorT and MapT template
  parameters.
- Updated variable names.
2019-09-06 09:10:26 -07:00
Nate Chandler
4968dcc80e [SIL] Took SILInstructionWorklist from SILCombine.
SILCombine had a dedicated worklist type that is generally useful.  Here
that type is extracted into SIL as SILInstructionWorklist so that it can
be reused.  Minor style changes were made as well.
2019-09-04 11:24:27 -07:00