llvm-6502/lib/Analysis
Chandler Carruth ed90ed077a Add a new visitor for walking the uses of a pointer value.
This visitor provides infrastructure for recursively traversing the
use-graph of a pointer-producing instruction like an alloca or a malloc.
It maintains a worklist of uses to visit, so it can handle very deep
recursions. It automatically looks through instructions which simply
translate one pointer to another (bitcasts and GEPs). It tracks the
offset relative to the original pointer as long as that offset remains
constant and exposes it during the visit as an APInt offset. Finally, it
performs conservative escape analysis.

However, currently it has some limitations that should be addressed
going forward:
1) It doesn't handle vectors of pointers.
2) It doesn't provide a cheaper visitor when the constant offset
   tracking isn't needed.
3) It doesn't support non-instruction pointer values.

The current functionality is exactly what is required to implement the
SROA pointer-use visitors in terms of this one, rather than in terms of
their own ad-hoc base visitor, which was always very poorly specified.
SROA has been converted to use this, and the code there deleted which
this utility now provides.

Technically speaking, using this new visitor allows SROA to handle a few
more cases than it previously did. It is now more aggressive in ignoring
chains of instructions which look like they would defeat SROA, but in
fact do not because they never result in a read or write of memory.
While this is "neat", it shouldn't be interesting for real programs as
any such chains should have been removed by others passes long before we
get to SROA. As a consequence, I've not added any tests for these
features -- it shouldn't be part of SROA's contract to perform such
heroics.

The goal is to extend the functionality of this visitor going forward,
and re-use it from passes like ASan that can benefit from doing
a detailed walk of the uses of a pointer.

Thanks to Ben Kramer for the code review rounds and lots of help
reviewing and debugging this patch.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169728 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-10 08:28:39 +00:00
..
IPA Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
AliasAnalysis.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
AliasAnalysisCounter.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
AliasAnalysisEvaluator.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
AliasDebugger.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
AliasSetTracker.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
Analysis.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
BasicAliasAnalysis.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
BlockFrequencyInfo.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
BranchProbabilityInfo.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
CaptureTracking.cpp Give CaptureTracker::shouldExplore a base implementation. Most users want to do 2012-10-08 22:12:48 +00:00
CFGPrinter.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
CMakeLists.txt Add a new visitor for walking the uses of a pointer value. 2012-12-10 08:28:39 +00:00
CodeMetrics.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ConstantFolding.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
CostModel.cpp constify the cost API 2012-12-03 22:47:12 +00:00
DbgInfoPrinter.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
DependenceAnalysis.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
DominanceFrontier.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
DomPrinter.cpp remove the blank line from previous ci. 2012-02-04 03:18:47 +00:00
InlineCost.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
InstCount.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
InstructionSimplify.cpp Reorganize FastMathFlags to be a wrapper around unsigned, and streamline some interfaces. 2012-12-09 21:12:04 +00:00
Interval.cpp Revert 'Fix a typo 'iff' => 'if''. iff is an abreviation of if and only if. See: http://en.wikipedia.org/wiki/If_and_only_if Commit 164767 2012-09-27 10:14:43 +00:00
IntervalPartition.cpp Now with fewer extraneous semicolons! 2010-10-07 22:25:06 +00:00
IVUsers.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
LazyValueInfo.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
LibCallAliasAnalysis.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
LibCallSemantics.cpp Thread const correctness through a bunch of AliasAnalysis interfaces and 2010-08-03 21:48:53 +00:00
Lint.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
LLVMBuild.txt LLVMBuild: Introduce a common section which currently has a list of the 2011-12-12 22:45:54 +00:00
Loads.cpp Move TargetData to DataLayout. 2012-10-08 16:38:25 +00:00
LoopInfo.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
LoopPass.cpp Enable the new LoopInfo algorithm by default. 2012-06-26 04:11:38 +00:00
Makefile make -fno-rtti the default unless a directory builds with REQUIRES_RTTI. 2010-01-24 20:43:08 +00:00
MemDepPrinter.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
MemoryBuiltins.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
MemoryDependenceAnalysis.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ModuleDebugInfoPrinter.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
NoAliasAnalysis.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
PathNumbering.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
PathProfileInfo.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
PathProfileVerifier.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
PHITransAddr.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
PostDominators.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ProfileDataLoader.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ProfileDataLoaderPass.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ProfileEstimatorPass.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ProfileInfo.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ProfileInfoLoader.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ProfileInfoLoaderPass.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ProfileVerifierPass.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
PtrUseVisitor.cpp Add a new visitor for walking the uses of a pointer value. 2012-12-10 08:28:39 +00:00
README.txt When checking whether the special handling for an addrec increment which 2010-04-26 21:46:36 +00:00
RegionInfo.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
RegionPass.cpp Remove the the block_node_iterator of Region, replace it by the block_iterator. 2012-08-27 13:49:24 +00:00
RegionPrinter.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ScalarEvolution.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ScalarEvolutionAliasAnalysis.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ScalarEvolutionExpander.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ScalarEvolutionNormalization.cpp More dead code removal (using -Wunreachable-code) 2012-01-20 21:51:11 +00:00
SparsePropagation.cpp Taken into account Duncan's comments for r149481 dated by 2nd Feb 2012: 2012-03-08 07:06:20 +00:00
Trace.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
TypeBasedAliasAnalysis.cpp Use the new script to sort the includes of every file under lib. 2012-12-03 16:50:05 +00:00
ValueTracking.cpp Add support to ValueTracking for determining that a pointer is non-null 2012-12-07 02:08:58 +00:00

Analysis Opportunities:

//===---------------------------------------------------------------------===//

In test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll, the
ScalarEvolution expression for %r is this:

  {1,+,3,+,2}<loop>

Outside the loop, this could be evaluated simply as (%n * %n), however
ScalarEvolution currently evaluates it as

  (-2 + (2 * (trunc i65 (((zext i64 (-2 + %n) to i65) * (zext i64 (-1 + %n) to i65)) /u 2) to i64)) + (3 * %n))

In addition to being much more complicated, it involves i65 arithmetic,
which is very inefficient when expanded into code.

//===---------------------------------------------------------------------===//

In formatValue in test/CodeGen/X86/lsr-delayed-fold.ll,

ScalarEvolution is forming this expression:

((trunc i64 (-1 * %arg5) to i32) + (trunc i64 %arg5 to i32) + (-1 * (trunc i64 undef to i32)))

This could be folded to

(-1 * (trunc i64 undef to i32))

//===---------------------------------------------------------------------===//