2013-05-20 20:46:30 +00:00
|
|
|
//===- llvm/Transforms/Utils/LoopUtils.h - Loop utilities -*- C++ -*-=========//
|
2013-05-20 16:47:07 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines some loop transformation utilities.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-05-20 20:46:30 +00:00
|
|
|
#ifndef LLVM_TRANSFORMS_UTILS_LOOPUTILS_H
|
|
|
|
#define LLVM_TRANSFORMS_UTILS_LOOPUTILS_H
|
2013-05-20 16:47:07 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2014-01-23 11:23:19 +00:00
|
|
|
class AliasAnalysis;
|
2015-01-04 12:03:27 +00:00
|
|
|
class AssumptionCache;
|
2014-01-23 11:23:19 +00:00
|
|
|
class BasicBlock;
|
2014-07-10 14:41:31 +00:00
|
|
|
class DataLayout;
|
2014-01-23 11:23:19 +00:00
|
|
|
class DominatorTree;
|
2013-05-20 16:47:07 +00:00
|
|
|
class Loop;
|
2014-01-23 11:23:19 +00:00
|
|
|
class LoopInfo;
|
2013-05-20 16:47:07 +00:00
|
|
|
class Pass;
|
2014-01-23 11:23:19 +00:00
|
|
|
class ScalarEvolution;
|
2013-05-20 16:47:07 +00:00
|
|
|
|
|
|
|
BasicBlock *InsertPreheaderForLoop(Loop *L, Pass *P);
|
|
|
|
|
2014-01-23 11:23:19 +00:00
|
|
|
/// \brief Simplify each loop in a loop nest recursively.
|
|
|
|
///
|
|
|
|
/// This takes a potentially un-simplified loop L (and its children) and turns
|
|
|
|
/// it into a simplified loop nest with preheaders and single backedges. It
|
|
|
|
/// will optionally update \c AliasAnalysis and \c ScalarEvolution analyses if
|
|
|
|
/// passed into it.
|
|
|
|
bool simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, Pass *PP,
|
2014-07-10 14:41:31 +00:00
|
|
|
AliasAnalysis *AA = nullptr, ScalarEvolution *SE = nullptr,
|
Make use of @llvm.assume in ValueTracking (computeKnownBits, etc.)
This change, which allows @llvm.assume to be used from within computeKnownBits
(and other associated functions in ValueTracking), adds some (optional)
parameters to computeKnownBits and friends. These functions now (optionally)
take a "context" instruction pointer, an AssumptionTracker pointer, and also a
DomTree pointer, and most of the changes are just to pass this new information
when it is easily available from InstSimplify, InstCombine, etc.
As explained below, the significant conceptual change is that known properties
of a value might depend on the control-flow location of the use (because we
care that the @llvm.assume dominates the use because assumptions have
control-flow dependencies). This means that, when we ask if bits are known in a
value, we might get different answers for different uses.
The significant changes are all in ValueTracking. Two main changes: First, as
with the rest of the code, new parameters need to be passed around. To make
this easier, I grouped them into a structure, and I made internal static
versions of the relevant functions that take this structure as a parameter. The
new code does as you might expect, it looks for @llvm.assume calls that make
use of the value we're trying to learn something about (often indirectly),
attempts to pattern match that expression, and uses the result if successful.
By making use of the AssumptionTracker, the process of finding @llvm.assume
calls is not expensive.
Part of the structure being passed around inside ValueTracking is a set of
already-considered @llvm.assume calls. This is to prevent a query using, for
example, the assume(a == b), to recurse on itself. The context and DT params
are used to find applicable assumptions. An assumption needs to dominate the
context instruction, or come after it deterministically. In this latter case we
only handle the specific case where both the assumption and the context
instruction are in the same block, and we need to exclude assumptions from
being used to simplify their own ephemeral values (those which contribute only
to the assumption) because otherwise the assumption would prove its feeding
comparison trivial and would be removed.
This commit adds the plumbing and the logic for a simple masked-bit propagation
(just enough to write a regression test). Future commits add more patterns
(and, correspondingly, more regression tests).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217342 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-07 18:57:58 +00:00
|
|
|
const DataLayout *DL = nullptr,
|
2015-01-04 12:03:27 +00:00
|
|
|
AssumptionCache *AC = nullptr);
|
2014-01-23 11:23:19 +00:00
|
|
|
|
2014-01-25 04:07:24 +00:00
|
|
|
/// \brief Put loop into LCSSA form.
|
|
|
|
///
|
|
|
|
/// Looks at all instructions in the loop which have uses outside of the
|
|
|
|
/// current loop. For each, an LCSSA PHI node is inserted and the uses outside
|
|
|
|
/// the loop are rewritten to use this node.
|
|
|
|
///
|
|
|
|
/// LoopInfo and DominatorTree are required and preserved.
|
|
|
|
///
|
|
|
|
/// If ScalarEvolution is passed in, it will be preserved.
|
|
|
|
///
|
|
|
|
/// Returns true if any modifications are made to the loop.
|
2014-12-22 22:35:46 +00:00
|
|
|
bool formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI,
|
|
|
|
ScalarEvolution *SE = nullptr);
|
2014-01-25 04:07:24 +00:00
|
|
|
|
2014-01-28 01:25:38 +00:00
|
|
|
/// \brief Put a loop nest into LCSSA form.
|
|
|
|
///
|
|
|
|
/// This recursively forms LCSSA for a loop nest.
|
|
|
|
///
|
|
|
|
/// LoopInfo and DominatorTree are required and preserved.
|
|
|
|
///
|
|
|
|
/// If ScalarEvolution is passed in, it will be preserved.
|
|
|
|
///
|
|
|
|
/// Returns true if any modifications are made to the loop.
|
2014-12-22 22:35:46 +00:00
|
|
|
bool formLCSSARecursively(Loop &L, DominatorTree &DT, LoopInfo *LI,
|
2014-04-25 05:29:35 +00:00
|
|
|
ScalarEvolution *SE = nullptr);
|
2013-05-20 16:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|