2003-02-22 23:04:52 +00:00
|
|
|
//===- PromoteMemToReg.h - Promote Allocas to Scalars -----------*- C++ -*-===//
|
2005-04-21 20:59:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:59:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-02-22 23:04:52 +00:00
|
|
|
//
|
|
|
|
// This file exposes an interface to promote alloca instructions to SSA
|
|
|
|
// registers, by using the SSA construction algorithm.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_TRANSFORMS_UTILS_PROMOTEMEMTOREG_H
|
|
|
|
#define LLVM_TRANSFORMS_UTILS_PROMOTEMEMTOREG_H
|
2003-02-22 23:04:52 +00:00
|
|
|
|
2013-07-21 08:37:58 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2003-02-22 23:04:52 +00:00
|
|
|
class AllocaInst;
|
2007-06-07 21:57:03 +00:00
|
|
|
class DominatorTree;
|
2004-09-15 01:02:30 +00:00
|
|
|
class AliasSetTracker;
|
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
|
|
|
class AssumptionTracker;
|
2003-02-22 23:04:52 +00:00
|
|
|
|
2013-07-20 22:20:05 +00:00
|
|
|
/// \brief Return true if this alloca is legal for promotion.
|
2003-02-22 23:04:52 +00:00
|
|
|
///
|
2013-07-20 22:20:05 +00:00
|
|
|
/// This is true if there are only loads, stores, and lifetime markers
|
|
|
|
/// (transitively) using this alloca. This also enforces that there is only
|
|
|
|
/// ever one layer of bitcasts or GEPs between the alloca and the lifetime
|
|
|
|
/// markers.
|
2013-08-13 22:51:58 +00:00
|
|
|
bool isAllocaPromotable(const AllocaInst *AI);
|
2003-02-22 23:04:52 +00:00
|
|
|
|
2013-07-20 22:20:05 +00:00
|
|
|
/// \brief Promote the specified list of alloca instructions into scalar
|
|
|
|
/// registers, inserting PHI nodes as appropriate.
|
|
|
|
///
|
|
|
|
/// This function makes use of DominanceFrontier information. This function
|
|
|
|
/// does not modify the CFG of the function at all. All allocas must be from
|
|
|
|
/// the same function.
|
2003-02-22 23:04:52 +00:00
|
|
|
///
|
2004-09-15 01:02:30 +00:00
|
|
|
/// If AST is specified, the specified tracker is updated to reflect changes
|
|
|
|
/// made to the IR.
|
2013-07-21 08:37:58 +00:00
|
|
|
void PromoteMemToReg(ArrayRef<AllocaInst *> Allocas, DominatorTree &DT,
|
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
|
|
|
AliasSetTracker *AST = nullptr,
|
|
|
|
AssumptionTracker *AT = nullptr);
|
2003-02-22 23:04:52 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-02-22 23:04:52 +00:00
|
|
|
#endif
|