llvm-6502/include/llvm
Chandler Carruth 713aa9431d Introduce a new SROA implementation.
This is essentially a ground up re-think of the SROA pass in LLVM. It
was initially inspired by a few problems with the existing pass:
- It is subject to the bane of my existence in optimizations: arbitrary
  thresholds.
- It is overly conservative about which constructs can be split and
  promoted.
- The vector value replacement aspect is separated from the splitting
  logic, missing many opportunities where splitting and vector value
  formation can work together.
- The splitting is entirely based around the underlying type of the
  alloca, despite this type often having little to do with the reality
  of how that memory is used. This is especially prevelant with unions
  and base classes where we tail-pack derived members.
- When splitting fails (often due to the thresholds), the vector value
  replacement (again because it is separate) can kick in for
  preposterous cases where we simply should have split the value. This
  results in forming i1024 and i2048 integer "bit vectors" that
  tremendously slow down subsequnet IR optimizations (due to large
  APInts) and impede the backend's lowering.

The new design takes an approach that fundamentally is not susceptible
to many of these problems. It is the result of a discusison between
myself and Duncan Sands over IRC about how to premptively avoid these
types of problems and how to do SROA in a more principled way. Since
then, it has evolved and grown, but this remains an important aspect: it
fixes real world problems with the SROA process today.

First, the transform of SROA actually has little to do with replacement.
It has more to do with splitting. The goal is to take an aggregate
alloca and form a composition of scalar allocas which can replace it and
will be most suitable to the eventual replacement by scalar SSA values.
The actual replacement is performed by mem2reg (and in the future
SSAUpdater).

The splitting is divided into four phases. The first phase is an
analysis of the uses of the alloca. This phase recursively walks uses,
building up a dense datastructure representing the ranges of the
alloca's memory actually used and checking for uses which inhibit any
aspects of the transform such as the escape of a pointer.

Once we have a mapping of the ranges of the alloca used by individual
operations, we compute a partitioning of the used ranges. Some uses are
inherently splittable (such as memcpy and memset), while scalar uses are
not splittable. The goal is to build a partitioning that has the minimum
number of splits while placing each unsplittable use in its own
partition. Overlapping unsplittable uses belong to the same partition.
This is the target split of the aggregate alloca, and it maximizes the
number of scalar accesses which become accesses to their own alloca and
candidates for promotion.

Third, we re-walk the uses of the alloca and assign each specific memory
access to all the partitions touched so that we have dense use-lists for
each partition.

Finally, we build a new, smaller alloca for each partition and rewrite
each use of that partition to use the new alloca. During this phase the
pass will also work very hard to transform uses of an alloca into a form
suitable for promotion, including forming vector operations, speculating
loads throguh PHI nodes and selects, etc.

After splitting is complete, each newly refined alloca that is
a candidate for promotion to a scalar SSA value is run through mem2reg.

There are lots of reasonably detailed comments in the source code about
the design and algorithms, and I'm going to be trying to improve them in
subsequent commits to ensure this is well documented, as the new pass is
in many ways more complex than the old one.

Some of this is still a WIP, but the current state is reasonbly stable.
It has passed bootstrap, the nightly test suite, and Duncan has run it
successfully through the ACATS and DragonEgg test suites. That said, it
remains behind a default-off flag until the last few pieces are in
place, and full testing can be done.

Specific areas I'm looking at next:
- Improved comments and some code cleanup from reviews.
- SSAUpdater and enabling this pass inside the CGSCC pass manager.
- Some datastructure tuning and compile-time measurements.
- More aggressive FCA splitting and vector formation.

Many thanks to Duncan Sands for the thorough final review, as well as
Benjamin Kramer for lots of review during the process of writing this
pass, and Daniel Berlin for reviewing the data structures and algorithms
and general theory of the pass. Also, several other people on IRC, over
lunch tables, etc for lots of feedback and advice.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163883 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-14 09:22:59 +00:00
..
ADT Fix Doxygen issues: 2012-09-13 12:34:29 +00:00
Analysis Remove unused typedefs gcc4.8 warns about. 2012-09-05 17:55:46 +00:00
Assembly Prune some includes and forward declarations. 2012-03-26 06:58:25 +00:00
Bitcode [ms-inline asm] Enumerate the InlineAsm dialects and rename the nsdialect to 2012-09-05 19:00:49 +00:00
CodeGen Fix PR11985 2012-09-12 21:43:09 +00:00
Config replace a couple of single-line comments with /* */ to fix the build of stuff depending on the C headers 2012-09-02 14:19:21 +00:00
DebugInfo Add support for fetching inlining context (stack of source code locations) 2012-09-04 08:12:33 +00:00
ExecutionEngine Better const handling for RuntimeDyld and MCJIT. 2012-09-13 21:50:06 +00:00
MC MachO: Correctly mark symbol-difference variables as N_ABS. 2012-09-13 23:11:25 +00:00
Object [Object] Extract Elf_Ehdr. Patch by Hemant Kulkarni! 2012-09-10 19:04:02 +00:00
Support Fix some code which is invalid in C++11: an expression of enumeration type 2012-09-13 21:18:18 +00:00
TableGen Fixing a type width warning with MSVC. 2012-09-09 20:34:25 +00:00
Target misched: Generic tablegen classes for the new machine model. 2012-09-14 06:18:55 +00:00
Transforms Introduce a new SROA implementation. 2012-09-14 09:22:59 +00:00
Argument.h
Attributes.h [ms-inline asm] Remove the Inline Asm Non-Standard Dialect attribute. This 2012-09-04 22:29:45 +00:00
AutoUpgrade.h
BasicBlock.h Add a constified getLandingPad() method. 2012-01-31 00:26:24 +00:00
CallGraphSCCPass.h
CallingConv.h
CMakeLists.txt llvm/include/llvm/CMakeLists.txt: Cut dependency to intrinsics_gen. 2012-07-06 15:55:39 +00:00
Constant.h getAllOnesValue also works for vectors of integers. 2012-06-04 07:18:12 +00:00
Constants.h When linearizing a multiplication, return at once if we see a factor of zero, 2012-06-13 09:42:13 +00:00
DebugInfo.h Recommit, with fixes: 2012-09-12 23:36:19 +00:00
DefaultPasses.h
DerivedTypes.h Cache the sized-ness of struct types, once we reach the steady state of 2012-03-07 02:33:09 +00:00
DIBuilder.h Recommit, with fixes: 2012-09-12 23:36:19 +00:00
Function.h Teach Function::hasAddressTaken that BlockAddress doesn't really take 2012-05-12 08:30:16 +00:00
GlobalAlias.h
GlobalValue.h Change the linker_private_weak_def_auto' linkage to linkonce_odr_auto_hide' to 2012-08-17 18:33:14 +00:00
GlobalVariable.h Clean-up after r159077. 2012-06-23 12:14:23 +00:00
GVMaterializer.h
InitializePasses.h Introduce a new SROA implementation. 2012-09-14 09:22:59 +00:00
InlineAsm.h Cleanup a few magic numbers. 2012-09-05 22:40:13 +00:00
InstrTypes.h Fix a bunch of -Wdocumentation warnings. 2012-08-23 16:54:08 +00:00
Instruction.def [unwind removal] Remove all of the code for the dead 'unwind' instruction. There 2012-02-06 21:44:22 +00:00
Instruction.h Refactor operation equivalence checking in BBVectorize by extending Instruction::isSameOperationAs. 2012-06-28 05:42:26 +00:00
Instructions.h Fix a couple of Doxygen comment issues pointed out by -Wdocumentation. 2012-09-12 16:59:47 +00:00
IntrinsicInst.h Remove the eh.exception and eh.selector intrinsics. Also remove a hack to copy 2012-01-31 01:46:13 +00:00
Intrinsics.h generalize this to allow any argument. 2012-05-27 19:17:16 +00:00
Intrinsics.td Add support for v16i32/v16i64 into the code generator. This is required for backends that use i32/i64 vectors for the getSetCCResultType function. 2012-07-26 21:22:00 +00:00
IntrinsicsARM.td
IntrinsicsCellSPU.td
IntrinsicsHexagon.td Test commit. 2012-08-17 06:36:26 +00:00
IntrinsicsMips.td Support MIPS DSP Rev2 intrinsics. 2012-08-27 12:29:01 +00:00
IntrinsicsNVVM.td Remove the PTX back-end and all of its artifacts (triple, etc.) 2012-05-24 21:38:21 +00:00
IntrinsicsPowerPC.td
IntrinsicsX86.td Mark avx2 maskstore has ReadWriteArgMem. Mark broadcast and maskload as ReadArgMem. 2012-08-26 22:01:42 +00:00
IntrinsicsXCore.td
IRBuilder.h Fix Doxygen issues: 2012-09-13 12:34:29 +00:00
LinkAllPasses.h Add a pass that renames everything with metasyntatic names. This works well after using bugpoint to reduce the confusion presented by the original names, which no longer mean what they used to. 2012-09-11 02:46:18 +00:00
LinkAllVMCore.h
Linker.h Prune some includes and forward declarations. 2012-03-26 06:58:25 +00:00
LLVMContext.h Define an official slot for the new !tbaa.struct metadata tag. 2012-09-13 17:56:17 +00:00
MDBuilder.h Update the header guard I missed when moving the header. 2012-07-15 23:45:20 +00:00
Metadata.h Move the Metadata merging methods from GVN and make them public in MDNode. 2012-06-16 20:33:37 +00:00
Module.h Move the "findUsedStructTypes" functionality outside of the Module class. 2012-08-03 00:30:35 +00:00
OperandTraits.h
Operator.h Remove support for the special 'fast' value for fpmath accuracy for the moment. 2012-04-16 19:39:33 +00:00
Pass.h Added TargetPassConfig::disablePass/substitutePass as a general mechanism to override specific passes. 2012-02-15 03:21:47 +00:00
PassAnalysisSupport.h
PassManager.h Add pass printer passes in the right place. 2012-02-01 07:16:20 +00:00
PassManagers.h Use ArrayRef instead of an explicit vector type. 2012-05-14 07:53:40 +00:00
PassRegistry.h
PassSupport.h
SymbolTableListTraits.h Remove unused typedefs gcc4.8 warns about. 2012-09-05 17:55:46 +00:00
Type.h add StructType helpers too. 2012-01-26 00:06:44 +00:00
TypeBuilder.h Move llvm/Support/TypeBuilder.h -> llvm/TypeBuilder.h. This completes 2012-07-15 23:45:24 +00:00
TypeFinder.h Move the "findUsedStructTypes" functionality outside of the Module class. 2012-08-03 00:30:35 +00:00
Use.h
User.h Grammar. 2012-05-16 22:08:58 +00:00
Value.h Fix Doxygen issues: 2012-09-13 12:34:29 +00:00
ValueSymbolTable.h