2006-11-23 00:49:16 +01:00
|
|
|
//===-- PredicateSimplifier.cpp - Path Sensitive Simplifier ---------------===//
|
2006-08-29 00:44:55 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-08-29 00:44:55 +02:00
|
|
|
//
|
2006-11-23 00:49:16 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-08-29 00:44:55 +02:00
|
|
|
//
|
|
|
|
// Path-sensitive optimizer. In a branch where x == y, replace uses of
|
|
|
|
// x with y. Permits further optimization, such as the elimination of
|
|
|
|
// the unreachable call:
|
|
|
|
//
|
|
|
|
// void test(int *p, int *q)
|
|
|
|
// {
|
|
|
|
// if (p != q)
|
|
|
|
// return;
|
|
|
|
//
|
|
|
|
// if (*p != *q)
|
|
|
|
// foo(); // unreachable
|
|
|
|
// }
|
|
|
|
//
|
2006-11-23 00:49:16 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2006-08-29 00:44:55 +02:00
|
|
|
//
|
2007-03-16 03:37:39 +01:00
|
|
|
// The InequalityGraph focusses on four properties; equals, not equals,
|
|
|
|
// less-than and less-than-or-equals-to. The greater-than forms are also held
|
|
|
|
// just to allow walking from a lesser node to a greater one. These properties
|
2006-11-23 00:49:16 +01:00
|
|
|
// are stored in a lattice; LE can become LT or EQ, NE can become LT or GT.
|
2006-08-29 00:44:55 +02:00
|
|
|
//
|
2006-11-23 00:49:16 +01:00
|
|
|
// These relationships define a graph between values of the same type. Each
|
|
|
|
// Value is stored in a map table that retrieves the associated Node. This
|
2007-03-10 19:12:48 +01:00
|
|
|
// is how EQ relationships are stored; the map contains pointers from equal
|
|
|
|
// Value to the same node. The node contains a most canonical Value* form
|
|
|
|
// and the list of known relationships with other nodes.
|
2006-11-23 00:49:16 +01:00
|
|
|
//
|
|
|
|
// If two nodes are known to be inequal, then they will contain pointers to
|
|
|
|
// each other with an "NE" relationship. If node getNode(%x) is less than
|
|
|
|
// getNode(%y), then the %x node will contain <%y, GT> and %y will contain
|
|
|
|
// <%x, LT>. This allows us to tie nodes together into a graph like this:
|
|
|
|
//
|
|
|
|
// %a < %b < %c < %d
|
|
|
|
//
|
|
|
|
// with four nodes representing the properties. The InequalityGraph provides
|
2007-01-11 03:32:38 +01:00
|
|
|
// querying with "isRelatedBy" and mutators "addEquality" and "addInequality".
|
|
|
|
// To find a relationship, we start with one of the nodes any binary search
|
|
|
|
// through its list to find where the relationships with the second node start.
|
|
|
|
// Then we iterate through those to find the first relationship that dominates
|
|
|
|
// our context node.
|
2006-11-23 00:49:16 +01:00
|
|
|
//
|
|
|
|
// To create these properties, we wait until a branch or switch instruction
|
|
|
|
// implies that a particular value is true (or false). The VRPSolver is
|
|
|
|
// responsible for analyzing the variable and seeing what new inferences
|
|
|
|
// can be made from each property. For example:
|
|
|
|
//
|
2007-03-10 19:12:48 +01:00
|
|
|
// %P = icmp ne i32* %ptr, null
|
|
|
|
// %a = and i1 %P, %Q
|
|
|
|
// br i1 %a label %cond_true, label %cond_false
|
2006-11-23 00:49:16 +01:00
|
|
|
//
|
|
|
|
// For the true branch, the VRPSolver will start with %a EQ true and look at
|
|
|
|
// the definition of %a and find that it can infer that %P and %Q are both
|
|
|
|
// true. From %P being true, it can infer that %ptr NE null. For the false
|
2007-01-29 03:56:54 +01:00
|
|
|
// branch it can't infer anything from the "and" instruction.
|
2006-11-23 00:49:16 +01:00
|
|
|
//
|
|
|
|
// Besides branches, we can also infer properties from instruction that may
|
|
|
|
// have undefined behaviour in certain cases. For example, the dividend of
|
|
|
|
// a division may never be zero. After the division instruction, we may assume
|
|
|
|
// that the dividend is not equal to zero.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2007-03-16 03:37:39 +01:00
|
|
|
//
|
|
|
|
// The ValueRanges class stores the known integer bounds of a Value. When we
|
|
|
|
// encounter i8 %a u< %b, the ValueRanges stores that %a = [1, 255] and
|
2007-08-04 20:45:32 +02:00
|
|
|
// %b = [0, 254].
|
2007-03-16 03:37:39 +01:00
|
|
|
//
|
|
|
|
// It never stores an empty range, because that means that the code is
|
|
|
|
// unreachable. It never stores a single-element range since that's an equality
|
2007-04-07 05:16:12 +02:00
|
|
|
// relationship and better stored in the InequalityGraph, nor an empty range
|
|
|
|
// since that is better stored in UnreachableBlocks.
|
2007-03-16 03:37:39 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2006-08-29 00:44:55 +02:00
|
|
|
|
|
|
|
#define DEBUG_TYPE "predsimplify"
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
|
|
|
#include "llvm/Constants.h"
|
2006-10-22 21:53:27 +02:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2006-08-29 00:44:55 +02:00
|
|
|
#include "llvm/Instructions.h"
|
|
|
|
#include "llvm/Pass.h"
|
2007-01-11 03:32:38 +01:00
|
|
|
#include "llvm/ADT/DepthFirstIterator.h"
|
2006-11-23 00:49:16 +01:00
|
|
|
#include "llvm/ADT/SetOperations.h"
|
2007-02-04 01:40:42 +01:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
2006-08-29 00:44:55 +02:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/Analysis/Dominators.h"
|
2007-07-10 05:28:21 +02:00
|
|
|
#include "llvm/Assembly/Writer.h"
|
2006-08-29 00:44:55 +02:00
|
|
|
#include "llvm/Support/CFG.h"
|
2006-12-06 19:14:47 +01:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2007-03-10 19:12:48 +01:00
|
|
|
#include "llvm/Support/ConstantRange.h"
|
2006-08-29 00:44:55 +02:00
|
|
|
#include "llvm/Support/Debug.h"
|
2006-10-12 04:02:44 +02:00
|
|
|
#include "llvm/Support/InstVisitor.h"
|
2007-04-07 05:16:12 +02:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2006-11-23 00:49:16 +01:00
|
|
|
#include "llvm/Transforms/Utils/Local.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <deque>
|
2007-06-24 06:36:20 +02:00
|
|
|
#include <stack>
|
2006-08-29 00:44:55 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2006-12-19 22:49:03 +01:00
|
|
|
STATISTIC(NumVarsReplaced, "Number of argument substitutions");
|
|
|
|
STATISTIC(NumInstruction , "Number of instructions removed");
|
|
|
|
STATISTIC(NumSimple , "Number of simple replacements");
|
2007-01-11 03:32:38 +01:00
|
|
|
STATISTIC(NumBlocks , "Number of blocks marked unreachable");
|
2007-03-16 03:37:39 +01:00
|
|
|
STATISTIC(NumSnuggle , "Number of comparisons snuggled");
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2009-06-26 23:39:56 +02:00
|
|
|
static const ConstantRange empty(1, false);
|
|
|
|
|
2006-12-19 22:49:03 +01:00
|
|
|
namespace {
|
2007-06-24 06:36:20 +02:00
|
|
|
class DomTreeDFS {
|
|
|
|
public:
|
|
|
|
class Node {
|
|
|
|
friend class DomTreeDFS;
|
|
|
|
public:
|
|
|
|
typedef std::vector<Node *>::iterator iterator;
|
|
|
|
typedef std::vector<Node *>::const_iterator const_iterator;
|
|
|
|
|
|
|
|
unsigned getDFSNumIn() const { return DFSin; }
|
|
|
|
unsigned getDFSNumOut() const { return DFSout; }
|
|
|
|
|
|
|
|
BasicBlock *getBlock() const { return BB; }
|
|
|
|
|
|
|
|
iterator begin() { return Children.begin(); }
|
|
|
|
iterator end() { return Children.end(); }
|
|
|
|
|
|
|
|
const_iterator begin() const { return Children.begin(); }
|
|
|
|
const_iterator end() const { return Children.end(); }
|
|
|
|
|
|
|
|
bool dominates(const Node *N) const {
|
|
|
|
return DFSin <= N->DFSin && DFSout >= N->DFSout;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DominatedBy(const Node *N) const {
|
|
|
|
return N->dominates(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sorts by the number of descendants. With this, you can iterate
|
|
|
|
/// through a sorted list and the first matching entry is the most
|
|
|
|
/// specific match for your basic block. The order provided is stable;
|
|
|
|
/// DomTreeDFS::Nodes with the same number of descendants are sorted by
|
|
|
|
/// DFS in number.
|
|
|
|
bool operator<(const Node &N) const {
|
|
|
|
unsigned spread = DFSout - DFSin;
|
|
|
|
unsigned N_spread = N.DFSout - N.DFSin;
|
|
|
|
if (spread == N_spread) return DFSin < N.DFSin;
|
2007-07-05 05:15:00 +02:00
|
|
|
return spread < N_spread;
|
2007-06-24 06:36:20 +02:00
|
|
|
}
|
|
|
|
bool operator>(const Node &N) const { return N < *this; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned DFSin, DFSout;
|
|
|
|
BasicBlock *BB;
|
|
|
|
|
|
|
|
std::vector<Node *> Children;
|
|
|
|
};
|
|
|
|
|
|
|
|
// XXX: this may be slow. Instead of using "new" for each node, consider
|
|
|
|
// putting them in a vector to keep them contiguous.
|
|
|
|
explicit DomTreeDFS(DominatorTree *DT) {
|
|
|
|
std::stack<std::pair<Node *, DomTreeNode *> > S;
|
|
|
|
|
|
|
|
Entry = new Node;
|
|
|
|
Entry->BB = DT->getRootNode()->getBlock();
|
|
|
|
S.push(std::make_pair(Entry, DT->getRootNode()));
|
|
|
|
|
|
|
|
NodeMap[Entry->BB] = Entry;
|
|
|
|
|
|
|
|
while (!S.empty()) {
|
|
|
|
std::pair<Node *, DomTreeNode *> &Pair = S.top();
|
|
|
|
Node *N = Pair.first;
|
|
|
|
DomTreeNode *DTNode = Pair.second;
|
|
|
|
S.pop();
|
|
|
|
|
|
|
|
for (DomTreeNode::iterator I = DTNode->begin(), E = DTNode->end();
|
|
|
|
I != E; ++I) {
|
|
|
|
Node *NewNode = new Node;
|
|
|
|
NewNode->BB = (*I)->getBlock();
|
|
|
|
N->Children.push_back(NewNode);
|
|
|
|
S.push(std::make_pair(NewNode, *I));
|
|
|
|
|
|
|
|
NodeMap[NewNode->BB] = NewNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renumber();
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
DEBUG(dump());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
virtual
|
|
|
|
#endif
|
|
|
|
~DomTreeDFS() {
|
|
|
|
std::stack<Node *> S;
|
|
|
|
|
|
|
|
S.push(Entry);
|
|
|
|
while (!S.empty()) {
|
|
|
|
Node *N = S.top(); S.pop();
|
|
|
|
|
|
|
|
for (Node::iterator I = N->begin(), E = N->end(); I != E; ++I)
|
|
|
|
S.push(*I);
|
|
|
|
|
|
|
|
delete N;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-16 04:58:37 +02:00
|
|
|
/// getRootNode - This returns the entry node for the CFG of the function.
|
2007-06-24 06:36:20 +02:00
|
|
|
Node *getRootNode() const { return Entry; }
|
|
|
|
|
2007-07-16 04:58:37 +02:00
|
|
|
/// getNodeForBlock - return the node for the specified basic block.
|
2007-06-24 06:36:20 +02:00
|
|
|
Node *getNodeForBlock(BasicBlock *BB) const {
|
|
|
|
if (!NodeMap.count(BB)) return 0;
|
2007-07-05 05:15:00 +02:00
|
|
|
return const_cast<DomTreeDFS*>(this)->NodeMap[BB];
|
2007-06-24 06:36:20 +02:00
|
|
|
}
|
|
|
|
|
2007-07-16 04:58:37 +02:00
|
|
|
/// dominates - returns true if the basic block for I1 dominates that of
|
|
|
|
/// the basic block for I2. If the instructions belong to the same basic
|
|
|
|
/// block, the instruction first instruction sequentially in the block is
|
|
|
|
/// considered dominating.
|
2007-06-24 06:36:20 +02:00
|
|
|
bool dominates(Instruction *I1, Instruction *I2) {
|
|
|
|
BasicBlock *BB1 = I1->getParent(),
|
|
|
|
*BB2 = I2->getParent();
|
|
|
|
if (BB1 == BB2) {
|
|
|
|
if (isa<TerminatorInst>(I1)) return false;
|
|
|
|
if (isa<TerminatorInst>(I2)) return true;
|
|
|
|
if ( isa<PHINode>(I1) && !isa<PHINode>(I2)) return true;
|
|
|
|
if (!isa<PHINode>(I1) && isa<PHINode>(I2)) return false;
|
|
|
|
|
|
|
|
for (BasicBlock::const_iterator I = BB2->begin(), E = BB2->end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (&*I == I1) return true;
|
|
|
|
else if (&*I == I2) return false;
|
|
|
|
}
|
|
|
|
assert(!"Instructions not found in parent BasicBlock?");
|
|
|
|
} else {
|
2007-06-24 06:40:16 +02:00
|
|
|
Node *Node1 = getNodeForBlock(BB1),
|
2007-06-24 06:36:20 +02:00
|
|
|
*Node2 = getNodeForBlock(BB2);
|
2007-07-05 05:15:00 +02:00
|
|
|
return Node1 && Node2 && Node1->dominates(Node2);
|
2007-06-24 06:36:20 +02:00
|
|
|
}
|
2008-03-30 20:22:13 +02:00
|
|
|
return false; // Not reached
|
2007-06-24 06:36:20 +02:00
|
|
|
}
|
2007-07-16 04:58:37 +02:00
|
|
|
|
2007-06-24 06:36:20 +02:00
|
|
|
private:
|
2007-07-16 04:58:37 +02:00
|
|
|
/// renumber - calculates the depth first search numberings and applies
|
|
|
|
/// them onto the nodes.
|
2007-06-24 06:36:20 +02:00
|
|
|
void renumber() {
|
|
|
|
std::stack<std::pair<Node *, Node::iterator> > S;
|
|
|
|
unsigned n = 0;
|
|
|
|
|
|
|
|
Entry->DFSin = ++n;
|
|
|
|
S.push(std::make_pair(Entry, Entry->begin()));
|
|
|
|
|
|
|
|
while (!S.empty()) {
|
|
|
|
std::pair<Node *, Node::iterator> &Pair = S.top();
|
|
|
|
Node *N = Pair.first;
|
|
|
|
Node::iterator &I = Pair.second;
|
|
|
|
|
|
|
|
if (I == N->end()) {
|
|
|
|
N->DFSout = ++n;
|
|
|
|
S.pop();
|
|
|
|
} else {
|
|
|
|
Node *Next = *I++;
|
|
|
|
Next->DFSin = ++n;
|
|
|
|
S.push(std::make_pair(Next, Next->begin()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
virtual void dump() const {
|
|
|
|
dump(*cerr.stream());
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump(std::ostream &os) const {
|
|
|
|
os << "Predicate simplifier DomTreeDFS: \n";
|
|
|
|
dump(Entry, 0, os);
|
|
|
|
os << "\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump(Node *N, int depth, std::ostream &os) const {
|
|
|
|
++depth;
|
|
|
|
for (int i = 0; i < depth; ++i) { os << " "; }
|
|
|
|
os << "[" << depth << "] ";
|
|
|
|
|
|
|
|
os << N->getBlock()->getName() << " (" << N->getDFSNumIn()
|
|
|
|
<< ", " << N->getDFSNumOut() << ")\n";
|
|
|
|
|
|
|
|
for (Node::iterator I = N->begin(), E = N->end(); I != E; ++I)
|
|
|
|
dump(*I, depth, os);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Node *Entry;
|
|
|
|
std::map<BasicBlock *, Node *> NodeMap;
|
|
|
|
};
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
// SLT SGT ULT UGT EQ
|
|
|
|
// 0 1 0 1 0 -- GT 10
|
|
|
|
// 0 1 0 1 1 -- GE 11
|
|
|
|
// 0 1 1 0 0 -- SGTULT 12
|
|
|
|
// 0 1 1 0 1 -- SGEULE 13
|
2007-01-29 03:56:54 +01:00
|
|
|
// 0 1 1 1 0 -- SGT 14
|
|
|
|
// 0 1 1 1 1 -- SGE 15
|
2007-01-11 03:32:38 +01:00
|
|
|
// 1 0 0 1 0 -- SLTUGT 18
|
|
|
|
// 1 0 0 1 1 -- SLEUGE 19
|
|
|
|
// 1 0 1 0 0 -- LT 20
|
|
|
|
// 1 0 1 0 1 -- LE 21
|
2007-01-29 03:56:54 +01:00
|
|
|
// 1 0 1 1 0 -- SLT 22
|
|
|
|
// 1 0 1 1 1 -- SLE 23
|
|
|
|
// 1 1 0 1 0 -- UGT 26
|
|
|
|
// 1 1 0 1 1 -- UGE 27
|
|
|
|
// 1 1 1 0 0 -- ULT 28
|
|
|
|
// 1 1 1 0 1 -- ULE 29
|
2007-01-11 03:32:38 +01:00
|
|
|
// 1 1 1 1 0 -- NE 30
|
|
|
|
enum LatticeBits {
|
|
|
|
EQ_BIT = 1, UGT_BIT = 2, ULT_BIT = 4, SGT_BIT = 8, SLT_BIT = 16
|
|
|
|
};
|
|
|
|
enum LatticeVal {
|
|
|
|
GT = SGT_BIT | UGT_BIT,
|
|
|
|
GE = GT | EQ_BIT,
|
|
|
|
LT = SLT_BIT | ULT_BIT,
|
|
|
|
LE = LT | EQ_BIT,
|
|
|
|
NE = SLT_BIT | SGT_BIT | ULT_BIT | UGT_BIT,
|
|
|
|
SGTULT = SGT_BIT | ULT_BIT,
|
|
|
|
SGEULE = SGTULT | EQ_BIT,
|
|
|
|
SLTUGT = SLT_BIT | UGT_BIT,
|
|
|
|
SLEUGE = SLTUGT | EQ_BIT,
|
2007-01-29 03:56:54 +01:00
|
|
|
ULT = SLT_BIT | SGT_BIT | ULT_BIT,
|
|
|
|
UGT = SLT_BIT | SGT_BIT | UGT_BIT,
|
|
|
|
SLT = SLT_BIT | ULT_BIT | UGT_BIT,
|
|
|
|
SGT = SGT_BIT | ULT_BIT | UGT_BIT,
|
|
|
|
SLE = SLT | EQ_BIT,
|
|
|
|
SGE = SGT | EQ_BIT,
|
|
|
|
ULE = ULT | EQ_BIT,
|
|
|
|
UGE = UGT | EQ_BIT
|
2007-01-11 03:32:38 +01:00
|
|
|
};
|
|
|
|
|
2008-11-21 21:00:59 +01:00
|
|
|
#ifndef NDEBUG
|
2007-08-04 20:45:32 +02:00
|
|
|
/// validPredicate - determines whether a given value is actually a lattice
|
|
|
|
/// value. Only used in assertions or debugging.
|
2007-01-11 03:32:38 +01:00
|
|
|
static bool validPredicate(LatticeVal LV) {
|
|
|
|
switch (LV) {
|
2007-02-05 00:43:05 +01:00
|
|
|
case GT: case GE: case LT: case LE: case NE:
|
|
|
|
case SGTULT: case SGT: case SGEULE:
|
|
|
|
case SLTUGT: case SLT: case SLEUGE:
|
|
|
|
case ULT: case UGT:
|
|
|
|
case SLE: case SGE: case ULE: case UGE:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
|
|
|
}
|
2008-11-21 21:00:59 +01:00
|
|
|
#endif
|
2007-01-11 03:32:38 +01:00
|
|
|
|
|
|
|
/// reversePredicate - reverse the direction of the inequality
|
|
|
|
static LatticeVal reversePredicate(LatticeVal LV) {
|
|
|
|
unsigned reverse = LV ^ (SLT_BIT|SGT_BIT|ULT_BIT|UGT_BIT); //preserve EQ_BIT
|
2007-03-16 03:37:39 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
if ((reverse & (SLT_BIT|SGT_BIT)) == 0)
|
|
|
|
reverse |= (SLT_BIT|SGT_BIT);
|
|
|
|
|
|
|
|
if ((reverse & (ULT_BIT|UGT_BIT)) == 0)
|
|
|
|
reverse |= (ULT_BIT|UGT_BIT);
|
|
|
|
|
|
|
|
LatticeVal Rev = static_cast<LatticeVal>(reverse);
|
|
|
|
assert(validPredicate(Rev) && "Failed reversing predicate.");
|
|
|
|
return Rev;
|
|
|
|
}
|
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
/// ValueNumbering stores the scope-specific value numbers for a given Value.
|
|
|
|
class VISIBILITY_HIDDEN ValueNumbering {
|
2007-08-04 20:45:32 +02:00
|
|
|
|
|
|
|
/// VNPair is a tuple of {Value, index number, DomTreeDFS::Node}. It
|
|
|
|
/// includes the comparison operators necessary to allow you to store it
|
|
|
|
/// in a sorted vector.
|
2007-07-05 05:15:00 +02:00
|
|
|
class VISIBILITY_HIDDEN VNPair {
|
|
|
|
public:
|
|
|
|
Value *V;
|
|
|
|
unsigned index;
|
|
|
|
DomTreeDFS::Node *Subtree;
|
|
|
|
|
|
|
|
VNPair(Value *V, unsigned index, DomTreeDFS::Node *Subtree)
|
|
|
|
: V(V), index(index), Subtree(Subtree) {}
|
|
|
|
|
|
|
|
bool operator==(const VNPair &RHS) const {
|
|
|
|
return V == RHS.V && Subtree == RHS.Subtree;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const VNPair &RHS) const {
|
|
|
|
if (V != RHS.V) return V < RHS.V;
|
|
|
|
return *Subtree < *RHS.Subtree;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(Value *RHS) const {
|
|
|
|
return V < RHS;
|
|
|
|
}
|
2007-08-04 20:45:32 +02:00
|
|
|
|
|
|
|
bool operator>(Value *RHS) const {
|
|
|
|
return V > RHS;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator<(Value *RHS, const VNPair &pair) {
|
|
|
|
return pair.operator>(RHS);
|
|
|
|
}
|
2007-07-05 05:15:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<VNPair> VNMapType;
|
|
|
|
VNMapType VNMap;
|
|
|
|
|
2007-08-04 20:45:32 +02:00
|
|
|
/// The canonical choice for value number at index.
|
2007-07-05 05:15:00 +02:00
|
|
|
std::vector<Value *> Values;
|
|
|
|
|
|
|
|
DomTreeDFS *DTDFS;
|
|
|
|
|
|
|
|
public:
|
2007-07-10 05:28:21 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
virtual ~ValueNumbering() {}
|
|
|
|
virtual void dump() {
|
|
|
|
dump(*cerr.stream());
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump(std::ostream &os) {
|
|
|
|
for (unsigned i = 1; i <= Values.size(); ++i) {
|
|
|
|
os << i << " = ";
|
|
|
|
WriteAsOperand(os, Values[i-1]);
|
|
|
|
os << " {";
|
|
|
|
for (unsigned j = 0; j < VNMap.size(); ++j) {
|
|
|
|
if (VNMap[j].index == i) {
|
|
|
|
WriteAsOperand(os, VNMap[j].V);
|
|
|
|
os << " (" << VNMap[j].Subtree->getDFSNumIn() << ") ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << "}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
/// compare - returns true if V1 is a better canonical value than V2.
|
|
|
|
bool compare(Value *V1, Value *V2) const {
|
|
|
|
if (isa<Constant>(V1))
|
|
|
|
return !isa<Constant>(V2);
|
|
|
|
else if (isa<Constant>(V2))
|
|
|
|
return false;
|
|
|
|
else if (isa<Argument>(V1))
|
|
|
|
return !isa<Argument>(V2);
|
|
|
|
else if (isa<Argument>(V2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Instruction *I1 = dyn_cast<Instruction>(V1);
|
|
|
|
Instruction *I2 = dyn_cast<Instruction>(V2);
|
|
|
|
|
|
|
|
if (!I1 || !I2)
|
|
|
|
return V1->getNumUses() < V2->getNumUses();
|
|
|
|
|
|
|
|
return DTDFS->dominates(I1, I2);
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueNumbering(DomTreeDFS *DTDFS) : DTDFS(DTDFS) {}
|
|
|
|
|
|
|
|
/// valueNumber - finds the value number for V under the Subtree. If
|
|
|
|
/// there is no value number, returns zero.
|
|
|
|
unsigned valueNumber(Value *V, DomTreeDFS::Node *Subtree) {
|
2007-07-10 05:28:21 +02:00
|
|
|
if (!(isa<Constant>(V) || isa<Argument>(V) || isa<Instruction>(V))
|
|
|
|
|| V->getType() == Type::VoidTy) return 0;
|
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
VNMapType::iterator E = VNMap.end();
|
|
|
|
VNPair pair(V, 0, Subtree);
|
|
|
|
VNMapType::iterator I = std::lower_bound(VNMap.begin(), E, pair);
|
|
|
|
while (I != E && I->V == V) {
|
|
|
|
if (I->Subtree->dominates(Subtree))
|
|
|
|
return I->index;
|
|
|
|
++I;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
/// getOrInsertVN - always returns a value number, creating it if necessary.
|
|
|
|
unsigned getOrInsertVN(Value *V, DomTreeDFS::Node *Subtree) {
|
|
|
|
if (unsigned n = valueNumber(V, Subtree))
|
|
|
|
return n;
|
|
|
|
else
|
|
|
|
return newVN(V);
|
|
|
|
}
|
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
/// newVN - creates a new value number. Value V must not already have a
|
|
|
|
/// value number assigned.
|
|
|
|
unsigned newVN(Value *V) {
|
2007-07-10 05:28:21 +02:00
|
|
|
assert((isa<Constant>(V) || isa<Argument>(V) || isa<Instruction>(V)) &&
|
|
|
|
"Bad Value for value numbering.");
|
|
|
|
assert(V->getType() != Type::VoidTy && "Won't value number a void value");
|
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
Values.push_back(V);
|
|
|
|
|
|
|
|
VNPair pair = VNPair(V, Values.size(), DTDFS->getRootNode());
|
2007-07-10 05:28:21 +02:00
|
|
|
VNMapType::iterator I = std::lower_bound(VNMap.begin(), VNMap.end(), pair);
|
|
|
|
assert((I == VNMap.end() || value(I->index) != V) &&
|
2007-07-05 05:15:00 +02:00
|
|
|
"Attempt to create a duplicate value number.");
|
2007-07-10 05:28:21 +02:00
|
|
|
VNMap.insert(I, pair);
|
2007-07-05 05:15:00 +02:00
|
|
|
|
|
|
|
return Values.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// value - returns the Value associated with a value number.
|
|
|
|
Value *value(unsigned index) const {
|
|
|
|
assert(index != 0 && "Zero index is reserved for not found.");
|
|
|
|
assert(index <= Values.size() && "Index out of range.");
|
|
|
|
return Values[index-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// canonicalize - return a Value that is equal to V under Subtree.
|
|
|
|
Value *canonicalize(Value *V, DomTreeDFS::Node *Subtree) {
|
|
|
|
if (isa<Constant>(V)) return V;
|
|
|
|
|
|
|
|
if (unsigned n = valueNumber(V, Subtree))
|
|
|
|
return value(n);
|
|
|
|
else
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// addEquality - adds that value V belongs to the set of equivalent
|
|
|
|
/// values defined by value number n under Subtree.
|
|
|
|
void addEquality(unsigned n, Value *V, DomTreeDFS::Node *Subtree) {
|
|
|
|
assert(canonicalize(value(n), Subtree) == value(n) &&
|
|
|
|
"Node's 'canonical' choice isn't best within this subtree.");
|
|
|
|
|
|
|
|
// Suppose that we are given "%x -> node #1 (%y)". The problem is that
|
|
|
|
// we may already have "%z -> node #2 (%x)" somewhere above us in the
|
|
|
|
// graph. We need to find those edges and add "%z -> node #1 (%y)"
|
|
|
|
// to keep the lookups canonical.
|
|
|
|
|
|
|
|
std::vector<Value *> ToRepoint(1, V);
|
|
|
|
|
|
|
|
if (unsigned Conflict = valueNumber(V, Subtree)) {
|
|
|
|
for (VNMapType::iterator I = VNMap.begin(), E = VNMap.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (I->index == Conflict && I->Subtree->dominates(Subtree))
|
|
|
|
ToRepoint.push_back(I->V);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (std::vector<Value *>::iterator VI = ToRepoint.begin(),
|
|
|
|
VE = ToRepoint.end(); VI != VE; ++VI) {
|
|
|
|
Value *V = *VI;
|
|
|
|
|
|
|
|
VNPair pair(V, n, Subtree);
|
|
|
|
VNMapType::iterator B = VNMap.begin(), E = VNMap.end();
|
|
|
|
VNMapType::iterator I = std::lower_bound(B, E, pair);
|
|
|
|
if (I != E && I->V == V && I->Subtree == Subtree)
|
|
|
|
I->index = n; // Update best choice
|
2007-07-10 05:28:21 +02:00
|
|
|
else
|
2007-07-05 05:15:00 +02:00
|
|
|
VNMap.insert(I, pair); // New Value
|
|
|
|
|
|
|
|
// XXX: we currently don't have to worry about updating values with
|
|
|
|
// more specific Subtrees, but we will need to for PHI node support.
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
Value *V_n = value(n);
|
|
|
|
if (isa<Constant>(V) && isa<Constant>(V_n)) {
|
|
|
|
assert(V == V_n && "Constant equals different constant?");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// remove - removes all references to value V.
|
|
|
|
void remove(Value *V) {
|
2007-07-10 05:28:21 +02:00
|
|
|
VNMapType::iterator B = VNMap.begin(), E = VNMap.end();
|
2007-07-05 05:15:00 +02:00
|
|
|
VNPair pair(V, 0, DTDFS->getRootNode());
|
2007-07-10 05:28:21 +02:00
|
|
|
VNMapType::iterator J = std::upper_bound(B, E, pair);
|
2007-07-05 05:15:00 +02:00
|
|
|
VNMapType::iterator I = J;
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
while (I != B && (I == E || I->V == V)) --I;
|
2007-07-05 05:15:00 +02:00
|
|
|
|
|
|
|
VNMap.erase(I, J);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
/// The InequalityGraph stores the relationships between values.
|
|
|
|
/// Each Value in the graph is assigned to a Node. Nodes are pointer
|
|
|
|
/// comparable for equality. The caller is expected to maintain the logical
|
|
|
|
/// consistency of the system.
|
|
|
|
///
|
|
|
|
/// The InequalityGraph class may invalidate Node*s after any mutator call.
|
|
|
|
/// @brief The InequalityGraph stores the relationships between values.
|
|
|
|
class VISIBILITY_HIDDEN InequalityGraph {
|
2007-07-05 05:15:00 +02:00
|
|
|
ValueNumbering &VN;
|
2007-06-24 06:36:20 +02:00
|
|
|
DomTreeDFS::Node *TreeRoot;
|
2007-01-11 03:32:38 +01:00
|
|
|
|
|
|
|
InequalityGraph(); // DO NOT IMPLEMENT
|
|
|
|
InequalityGraph(InequalityGraph &); // DO NOT IMPLEMENT
|
2006-11-23 00:49:16 +01:00
|
|
|
public:
|
2007-07-05 05:15:00 +02:00
|
|
|
InequalityGraph(ValueNumbering &VN, DomTreeDFS::Node *TreeRoot)
|
|
|
|
: VN(VN), TreeRoot(TreeRoot) {}
|
2007-01-11 03:32:38 +01:00
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
class Node;
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
/// An Edge is contained inside a Node making one end of the edge implicit
|
|
|
|
/// and contains a pointer to the other end. The edge contains a lattice
|
2007-06-24 06:36:20 +02:00
|
|
|
/// value specifying the relationship and an DomTreeDFS::Node specifying
|
|
|
|
/// the root in the dominator tree to which this edge applies.
|
2007-01-11 03:32:38 +01:00
|
|
|
class VISIBILITY_HIDDEN Edge {
|
|
|
|
public:
|
2007-06-24 06:36:20 +02:00
|
|
|
Edge(unsigned T, LatticeVal V, DomTreeDFS::Node *ST)
|
2007-01-11 03:32:38 +01:00
|
|
|
: To(T), LV(V), Subtree(ST) {}
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
unsigned To;
|
|
|
|
LatticeVal LV;
|
2007-06-24 06:36:20 +02:00
|
|
|
DomTreeDFS::Node *Subtree;
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
bool operator<(const Edge &edge) const {
|
|
|
|
if (To != edge.To) return To < edge.To;
|
2007-07-05 05:15:00 +02:00
|
|
|
return *Subtree < *edge.Subtree;
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2007-06-24 06:36:20 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
bool operator<(unsigned to) const {
|
|
|
|
return To < to;
|
|
|
|
}
|
2007-06-24 06:36:20 +02:00
|
|
|
|
2007-06-05 01:52:59 +02:00
|
|
|
bool operator>(unsigned to) const {
|
|
|
|
return To > to;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator<(unsigned to, const Edge &edge) {
|
|
|
|
return edge.operator>(to);
|
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
};
|
2006-11-23 00:49:16 +01:00
|
|
|
|
|
|
|
/// A single node in the InequalityGraph. This stores the canonical Value
|
|
|
|
/// for the node, as well as the relationships with the neighbours.
|
|
|
|
///
|
|
|
|
/// @brief A single node in the InequalityGraph.
|
|
|
|
class VISIBILITY_HIDDEN Node {
|
|
|
|
friend class InequalityGraph;
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
typedef SmallVector<Edge, 4> RelationsType;
|
|
|
|
RelationsType Relations;
|
|
|
|
|
|
|
|
// TODO: can this idea improve performance?
|
|
|
|
//friend class std::vector<Node>;
|
|
|
|
//Node(Node &N) { RelationsType.swap(N.RelationsType); }
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
public:
|
|
|
|
typedef RelationsType::iterator iterator;
|
|
|
|
typedef RelationsType::const_iterator const_iterator;
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
#ifndef NDEBUG
|
2007-01-11 03:38:21 +01:00
|
|
|
virtual ~Node() {}
|
2007-01-11 03:32:38 +01:00
|
|
|
virtual void dump() const {
|
|
|
|
dump(*cerr.stream());
|
|
|
|
}
|
|
|
|
private:
|
2007-07-05 05:15:00 +02:00
|
|
|
void dump(std::ostream &os) const {
|
|
|
|
static const std::string names[32] =
|
|
|
|
{ "000000", "000001", "000002", "000003", "000004", "000005",
|
|
|
|
"000006", "000007", "000008", "000009", " >", " >=",
|
|
|
|
" s>u<", "s>=u<=", " s>", " s>=", "000016", "000017",
|
|
|
|
" s<u>", "s<=u>=", " <", " <=", " s<", " s<=",
|
|
|
|
"000024", "000025", " u>", " u>=", " u<", " u<=",
|
|
|
|
" !=", "000031" };
|
2007-01-11 03:32:38 +01:00
|
|
|
for (Node::const_iterator NI = begin(), NE = end(); NI != NE; ++NI) {
|
2007-07-05 05:15:00 +02:00
|
|
|
os << names[NI->LV] << " " << NI->To
|
2007-07-10 05:28:21 +02:00
|
|
|
<< " (" << NI->Subtree->getDFSNumIn() << "), ";
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
|
|
|
}
|
2007-07-05 05:15:00 +02:00
|
|
|
public:
|
2007-01-11 03:32:38 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
iterator begin() { return Relations.begin(); }
|
|
|
|
iterator end() { return Relations.end(); }
|
|
|
|
const_iterator begin() const { return Relations.begin(); }
|
|
|
|
const_iterator end() const { return Relations.end(); }
|
|
|
|
|
2007-06-24 06:36:20 +02:00
|
|
|
iterator find(unsigned n, DomTreeDFS::Node *Subtree) {
|
2007-01-11 03:32:38 +01:00
|
|
|
iterator E = end();
|
|
|
|
for (iterator I = std::lower_bound(begin(), E, n);
|
|
|
|
I != E && I->To == n; ++I) {
|
|
|
|
if (Subtree->DominatedBy(I->Subtree))
|
|
|
|
return I;
|
|
|
|
}
|
|
|
|
return E;
|
|
|
|
}
|
|
|
|
|
2007-06-24 06:36:20 +02:00
|
|
|
const_iterator find(unsigned n, DomTreeDFS::Node *Subtree) const {
|
2007-01-11 03:32:38 +01:00
|
|
|
const_iterator E = end();
|
|
|
|
for (const_iterator I = std::lower_bound(begin(), E, n);
|
|
|
|
I != E && I->To == n; ++I) {
|
|
|
|
if (Subtree->DominatedBy(I->Subtree))
|
|
|
|
return I;
|
|
|
|
}
|
|
|
|
return E;
|
|
|
|
}
|
|
|
|
|
2007-08-04 20:45:32 +02:00
|
|
|
/// update - updates the lattice value for a given node, creating a new
|
|
|
|
/// entry if one doesn't exist. The new lattice value must not be
|
|
|
|
/// inconsistent with any previously existing value.
|
2007-06-24 06:36:20 +02:00
|
|
|
void update(unsigned n, LatticeVal R, DomTreeDFS::Node *Subtree) {
|
2007-01-11 03:32:38 +01:00
|
|
|
assert(validPredicate(R) && "Invalid predicate.");
|
2007-01-15 15:30:07 +01:00
|
|
|
|
2007-08-04 20:45:32 +02:00
|
|
|
Edge edge(n, R, Subtree);
|
|
|
|
iterator B = begin(), E = end();
|
|
|
|
iterator I = std::lower_bound(B, E, edge);
|
|
|
|
|
|
|
|
iterator J = I;
|
|
|
|
while (J != E && J->To == n) {
|
|
|
|
if (Subtree->DominatedBy(J->Subtree))
|
|
|
|
break;
|
|
|
|
++J;
|
|
|
|
}
|
|
|
|
|
2007-08-19 01:18:03 +02:00
|
|
|
if (J != E && J->To == n) {
|
2007-08-04 20:45:32 +02:00
|
|
|
edge.LV = static_cast<LatticeVal>(J->LV & R);
|
|
|
|
assert(validPredicate(edge.LV) && "Invalid union of lattice values.");
|
|
|
|
|
2007-08-19 01:18:03 +02:00
|
|
|
if (edge.LV == J->LV)
|
|
|
|
return; // This update adds nothing new.
|
2008-02-26 11:53:30 +01:00
|
|
|
}
|
2007-08-19 01:18:03 +02:00
|
|
|
|
|
|
|
if (I != B) {
|
|
|
|
// We also have to tighten any edge beneath our update.
|
|
|
|
for (iterator K = I - 1; K->To == n; --K) {
|
|
|
|
if (K->Subtree->DominatedBy(Subtree)) {
|
|
|
|
LatticeVal LV = static_cast<LatticeVal>(K->LV & edge.LV);
|
|
|
|
assert(validPredicate(LV) && "Invalid union of lattice values");
|
|
|
|
K->LV = LV;
|
|
|
|
}
|
|
|
|
if (K == B) break;
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2008-02-26 11:53:30 +01:00
|
|
|
}
|
2007-08-04 20:45:32 +02:00
|
|
|
|
|
|
|
// Insert new edge at Subtree if it isn't already there.
|
|
|
|
if (I == E || I->To != n || Subtree != I->Subtree)
|
|
|
|
Relations.insert(I, edge);
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
};
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
private:
|
|
|
|
|
|
|
|
std::vector<Node> Nodes;
|
|
|
|
|
2006-09-10 04:27:07 +02:00
|
|
|
public:
|
2007-07-10 05:28:21 +02:00
|
|
|
/// node - returns the node object at a given value number. The pointer
|
|
|
|
/// returned may be invalidated on the next call to node().
|
2007-01-11 03:32:38 +01:00
|
|
|
Node *node(unsigned index) {
|
2007-07-10 05:28:21 +02:00
|
|
|
assert(VN.value(index)); // This triggers the necessary checks.
|
|
|
|
if (Nodes.size() < index) Nodes.resize(index);
|
2007-01-11 03:32:38 +01:00
|
|
|
return &Nodes[index-1];
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
/// isRelatedBy - true iff n1 op n2
|
2007-06-24 06:36:20 +02:00
|
|
|
bool isRelatedBy(unsigned n1, unsigned n2, DomTreeDFS::Node *Subtree,
|
|
|
|
LatticeVal LV) {
|
2007-01-11 03:32:38 +01:00
|
|
|
if (n1 == n2) return LV & EQ_BIT;
|
|
|
|
|
|
|
|
Node *N1 = node(n1);
|
|
|
|
Node::iterator I = N1->find(n2, Subtree), E = N1->end();
|
|
|
|
if (I != E) return (I->LV & LV) == I->LV;
|
|
|
|
|
|
|
|
return false;
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// The add* methods assume that your input is logically valid and may
|
|
|
|
// assertion-fail or infinitely loop if you attempt a contradiction.
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
/// addInequality - Sets n1 op n2.
|
|
|
|
/// It is also an error to call this on an inequality that is already true.
|
2007-06-24 06:36:20 +02:00
|
|
|
void addInequality(unsigned n1, unsigned n2, DomTreeDFS::Node *Subtree,
|
2007-01-11 03:32:38 +01:00
|
|
|
LatticeVal LV1) {
|
|
|
|
assert(n1 != n2 && "A node can't be inequal to itself.");
|
|
|
|
|
|
|
|
if (LV1 != NE)
|
|
|
|
assert(!isRelatedBy(n1, n2, Subtree, reversePredicate(LV1)) &&
|
|
|
|
"Contradictory inequality.");
|
|
|
|
|
|
|
|
// Suppose we're adding %n1 < %n2. Find all the %a < %n1 and
|
|
|
|
// add %a < %n2 too. This keeps the graph fully connected.
|
|
|
|
if (LV1 != NE) {
|
2007-04-07 05:36:51 +02:00
|
|
|
// Break up the relationship into signed and unsigned comparison parts.
|
|
|
|
// If the signed parts of %a op1 %n1 match that of %n1 op2 %n2, and
|
|
|
|
// op1 and op2 aren't NE, then add %a op3 %n2. The new relationship
|
|
|
|
// should have the EQ_BIT iff it's set for both op1 and op2.
|
2007-01-11 03:32:38 +01:00
|
|
|
|
|
|
|
unsigned LV1_s = LV1 & (SLT_BIT|SGT_BIT);
|
|
|
|
unsigned LV1_u = LV1 & (ULT_BIT|UGT_BIT);
|
2007-04-07 05:36:51 +02:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
for (Node::iterator I = node(n1)->begin(), E = node(n1)->end(); I != E; ++I) {
|
2007-01-11 03:32:38 +01:00
|
|
|
if (I->LV != NE && I->To != n2) {
|
2007-04-07 05:36:51 +02:00
|
|
|
|
2007-06-24 06:36:20 +02:00
|
|
|
DomTreeDFS::Node *Local_Subtree = NULL;
|
2007-01-11 03:32:38 +01:00
|
|
|
if (Subtree->DominatedBy(I->Subtree))
|
|
|
|
Local_Subtree = Subtree;
|
|
|
|
else if (I->Subtree->DominatedBy(Subtree))
|
|
|
|
Local_Subtree = I->Subtree;
|
|
|
|
|
|
|
|
if (Local_Subtree) {
|
|
|
|
unsigned new_relationship = 0;
|
|
|
|
LatticeVal ILV = reversePredicate(I->LV);
|
|
|
|
unsigned ILV_s = ILV & (SLT_BIT|SGT_BIT);
|
|
|
|
unsigned ILV_u = ILV & (ULT_BIT|UGT_BIT);
|
|
|
|
|
|
|
|
if (LV1_s != (SLT_BIT|SGT_BIT) && ILV_s == LV1_s)
|
|
|
|
new_relationship |= ILV_s;
|
|
|
|
if (LV1_u != (ULT_BIT|UGT_BIT) && ILV_u == LV1_u)
|
|
|
|
new_relationship |= ILV_u;
|
|
|
|
|
|
|
|
if (new_relationship) {
|
|
|
|
if ((new_relationship & (SLT_BIT|SGT_BIT)) == 0)
|
|
|
|
new_relationship |= (SLT_BIT|SGT_BIT);
|
|
|
|
if ((new_relationship & (ULT_BIT|UGT_BIT)) == 0)
|
|
|
|
new_relationship |= (ULT_BIT|UGT_BIT);
|
|
|
|
if ((LV1 & EQ_BIT) && (ILV & EQ_BIT))
|
|
|
|
new_relationship |= EQ_BIT;
|
|
|
|
|
|
|
|
LatticeVal NewLV = static_cast<LatticeVal>(new_relationship);
|
|
|
|
|
|
|
|
node(I->To)->update(n2, NewLV, Local_Subtree);
|
2007-07-10 05:28:21 +02:00
|
|
|
node(n2)->update(I->To, reversePredicate(NewLV), Local_Subtree);
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
for (Node::iterator I = node(n2)->begin(), E = node(n2)->end(); I != E; ++I) {
|
2007-01-11 03:32:38 +01:00
|
|
|
if (I->LV != NE && I->To != n1) {
|
2007-06-24 06:36:20 +02:00
|
|
|
DomTreeDFS::Node *Local_Subtree = NULL;
|
2007-01-11 03:32:38 +01:00
|
|
|
if (Subtree->DominatedBy(I->Subtree))
|
|
|
|
Local_Subtree = Subtree;
|
|
|
|
else if (I->Subtree->DominatedBy(Subtree))
|
|
|
|
Local_Subtree = I->Subtree;
|
|
|
|
|
|
|
|
if (Local_Subtree) {
|
|
|
|
unsigned new_relationship = 0;
|
|
|
|
unsigned ILV_s = I->LV & (SLT_BIT|SGT_BIT);
|
|
|
|
unsigned ILV_u = I->LV & (ULT_BIT|UGT_BIT);
|
|
|
|
|
|
|
|
if (LV1_s != (SLT_BIT|SGT_BIT) && ILV_s == LV1_s)
|
|
|
|
new_relationship |= ILV_s;
|
|
|
|
|
|
|
|
if (LV1_u != (ULT_BIT|UGT_BIT) && ILV_u == LV1_u)
|
|
|
|
new_relationship |= ILV_u;
|
|
|
|
|
|
|
|
if (new_relationship) {
|
|
|
|
if ((new_relationship & (SLT_BIT|SGT_BIT)) == 0)
|
|
|
|
new_relationship |= (SLT_BIT|SGT_BIT);
|
|
|
|
if ((new_relationship & (ULT_BIT|UGT_BIT)) == 0)
|
|
|
|
new_relationship |= (ULT_BIT|UGT_BIT);
|
|
|
|
if ((LV1 & EQ_BIT) && (I->LV & EQ_BIT))
|
|
|
|
new_relationship |= EQ_BIT;
|
|
|
|
|
|
|
|
LatticeVal NewLV = static_cast<LatticeVal>(new_relationship);
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
node(n1)->update(I->To, NewLV, Local_Subtree);
|
2007-01-11 03:32:38 +01:00
|
|
|
node(I->To)->update(n1, reversePredicate(NewLV), Local_Subtree);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
node(n1)->update(n2, LV1, Subtree);
|
|
|
|
node(n2)->update(n1, reversePredicate(LV1), Subtree);
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
/// remove - removes a node from the graph by removing all references to
|
|
|
|
/// and from it.
|
|
|
|
void remove(unsigned n) {
|
|
|
|
Node *N = node(n);
|
|
|
|
for (Node::iterator NI = N->begin(), NE = N->end(); NI != NE; ++NI) {
|
|
|
|
Node::iterator Iter = node(NI->To)->find(n, TreeRoot);
|
|
|
|
do {
|
|
|
|
node(NI->To)->Relations.erase(Iter);
|
|
|
|
Iter = node(NI->To)->find(n, TreeRoot);
|
|
|
|
} while (Iter != node(NI->To)->end());
|
|
|
|
}
|
|
|
|
N->Relations.clear();
|
2006-09-10 04:27:07 +02:00
|
|
|
}
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
#ifndef NDEBUG
|
2007-01-11 03:38:21 +01:00
|
|
|
virtual ~InequalityGraph() {}
|
2007-01-11 03:32:38 +01:00
|
|
|
virtual void dump() {
|
|
|
|
dump(*cerr.stream());
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump(std::ostream &os) {
|
2007-07-05 05:15:00 +02:00
|
|
|
for (unsigned i = 1; i <= Nodes.size(); ++i) {
|
|
|
|
os << i << " = {";
|
|
|
|
node(i)->dump(os);
|
|
|
|
os << "}\n";
|
2006-08-29 00:44:55 +02:00
|
|
|
}
|
|
|
|
}
|
2006-09-10 04:27:07 +02:00
|
|
|
#endif
|
2006-11-23 00:49:16 +01:00
|
|
|
};
|
2006-09-10 04:27:07 +02:00
|
|
|
|
2007-03-10 19:12:48 +01:00
|
|
|
class VRPSolver;
|
|
|
|
|
|
|
|
/// ValueRanges tracks the known integer ranges and anti-ranges of the nodes
|
|
|
|
/// in the InequalityGraph.
|
|
|
|
class VISIBILITY_HIDDEN ValueRanges {
|
2007-07-10 05:28:21 +02:00
|
|
|
ValueNumbering &VN;
|
|
|
|
TargetData *TD;
|
2009-07-16 20:04:31 +02:00
|
|
|
LLVMContext *Context;
|
2007-03-10 19:12:48 +01:00
|
|
|
|
|
|
|
class VISIBILITY_HIDDEN ScopedRange {
|
2007-07-10 05:28:21 +02:00
|
|
|
typedef std::vector<std::pair<DomTreeDFS::Node *, ConstantRange> >
|
|
|
|
RangeListType;
|
|
|
|
RangeListType RangeList;
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
static bool swo(const std::pair<DomTreeDFS::Node *, ConstantRange> &LHS,
|
|
|
|
const std::pair<DomTreeDFS::Node *, ConstantRange> &RHS) {
|
|
|
|
return *LHS.first < *RHS.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
#ifndef NDEBUG
|
|
|
|
virtual ~ScopedRange() {}
|
|
|
|
virtual void dump() const {
|
|
|
|
dump(*cerr.stream());
|
|
|
|
}
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
void dump(std::ostream &os) const {
|
|
|
|
os << "{";
|
|
|
|
for (const_iterator I = begin(), E = end(); I != E; ++I) {
|
2008-08-24 00:23:09 +02:00
|
|
|
os << &I->second << " (" << I->first->getDFSNumIn() << "), ";
|
2007-07-10 05:28:21 +02:00
|
|
|
}
|
|
|
|
os << "}";
|
2007-03-10 19:12:48 +01:00
|
|
|
}
|
2007-07-10 05:28:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef RangeListType::iterator iterator;
|
|
|
|
typedef RangeListType::const_iterator const_iterator;
|
|
|
|
|
|
|
|
iterator begin() { return RangeList.begin(); }
|
|
|
|
iterator end() { return RangeList.end(); }
|
|
|
|
const_iterator begin() const { return RangeList.begin(); }
|
|
|
|
const_iterator end() const { return RangeList.end(); }
|
|
|
|
|
|
|
|
iterator find(DomTreeDFS::Node *Subtree) {
|
|
|
|
iterator E = end();
|
|
|
|
iterator I = std::lower_bound(begin(), E,
|
|
|
|
std::make_pair(Subtree, empty), swo);
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
while (I != E && !I->first->dominates(Subtree)) ++I;
|
|
|
|
return I;
|
2007-03-10 19:12:48 +01:00
|
|
|
}
|
2007-06-05 01:52:59 +02:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
const_iterator find(DomTreeDFS::Node *Subtree) const {
|
|
|
|
const_iterator E = end();
|
|
|
|
const_iterator I = std::lower_bound(begin(), E,
|
|
|
|
std::make_pair(Subtree, empty), swo);
|
|
|
|
|
|
|
|
while (I != E && !I->first->dominates(Subtree)) ++I;
|
|
|
|
return I;
|
2007-06-05 01:52:59 +02:00
|
|
|
}
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
void update(const ConstantRange &CR, DomTreeDFS::Node *Subtree) {
|
|
|
|
assert(!CR.isEmptySet() && "Empty ConstantRange.");
|
2007-08-04 20:45:32 +02:00
|
|
|
assert(!CR.isSingleElement() && "Refusing to store single element.");
|
2007-07-10 05:28:21 +02:00
|
|
|
|
|
|
|
iterator E = end();
|
|
|
|
iterator I =
|
|
|
|
std::lower_bound(begin(), E, std::make_pair(Subtree, empty), swo);
|
|
|
|
|
|
|
|
if (I != end() && I->first == Subtree) {
|
2007-07-14 06:28:04 +02:00
|
|
|
ConstantRange CR2 = I->second.maximalIntersectWith(CR);
|
2007-07-10 05:28:21 +02:00
|
|
|
assert(!CR2.isEmptySet() && !CR2.isSingleElement() &&
|
|
|
|
"Invalid union of ranges.");
|
|
|
|
I->second = CR2;
|
|
|
|
} else
|
|
|
|
RangeList.insert(I, std::make_pair(Subtree, CR));
|
2007-06-05 01:52:59 +02:00
|
|
|
}
|
2007-03-10 19:12:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<ScopedRange> Ranges;
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
void update(unsigned n, const ConstantRange &CR, DomTreeDFS::Node *Subtree){
|
|
|
|
if (CR.isFullSet()) return;
|
|
|
|
if (Ranges.size() < n) Ranges.resize(n);
|
|
|
|
Ranges[n-1].update(CR, Subtree);
|
|
|
|
}
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
/// create - Creates a ConstantRange that matches the given LatticeVal
|
|
|
|
/// relation with a given integer.
|
|
|
|
ConstantRange create(LatticeVal LV, const ConstantRange &CR) {
|
|
|
|
assert(!CR.isEmptySet() && "Can't deal with empty set.");
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
if (LV == NE)
|
2009-07-11 08:15:39 +02:00
|
|
|
return ConstantRange::makeICmpRegion(ICmpInst::ICMP_NE, CR);
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
unsigned LV_s = LV & (SGT_BIT|SLT_BIT);
|
|
|
|
unsigned LV_u = LV & (UGT_BIT|ULT_BIT);
|
|
|
|
bool hasEQ = LV & EQ_BIT;
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
ConstantRange Range(CR.getBitWidth());
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
if (LV_s == SGT_BIT) {
|
2009-07-11 08:15:39 +02:00
|
|
|
Range = Range.maximalIntersectWith(ConstantRange::makeICmpRegion(
|
2007-07-10 05:28:21 +02:00
|
|
|
hasEQ ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_SGT, CR));
|
|
|
|
} else if (LV_s == SLT_BIT) {
|
2009-07-11 08:15:39 +02:00
|
|
|
Range = Range.maximalIntersectWith(ConstantRange::makeICmpRegion(
|
2007-07-10 05:28:21 +02:00
|
|
|
hasEQ ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_SLT, CR));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LV_u == UGT_BIT) {
|
2009-07-11 08:15:39 +02:00
|
|
|
Range = Range.maximalIntersectWith(ConstantRange::makeICmpRegion(
|
2007-07-10 05:28:21 +02:00
|
|
|
hasEQ ? ICmpInst::ICMP_UGE : ICmpInst::ICMP_UGT, CR));
|
|
|
|
} else if (LV_u == ULT_BIT) {
|
2009-07-11 08:15:39 +02:00
|
|
|
Range = Range.maximalIntersectWith(ConstantRange::makeICmpRegion(
|
2007-07-10 05:28:21 +02:00
|
|
|
hasEQ ? ICmpInst::ICMP_ULE : ICmpInst::ICMP_ULT, CR));
|
2007-03-10 19:12:48 +01:00
|
|
|
}
|
2007-07-10 05:28:21 +02:00
|
|
|
|
|
|
|
return Range;
|
2007-03-10 19:12:48 +01:00
|
|
|
}
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
bool isCanonical(Value *V, DomTreeDFS::Node *Subtree) {
|
|
|
|
return V == VN.canonicalize(V, Subtree);
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
public:
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2009-07-16 20:04:31 +02:00
|
|
|
ValueRanges(ValueNumbering &VN, TargetData *TD, LLVMContext *C) :
|
|
|
|
VN(VN), TD(TD), Context(C) {}
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
virtual ~ValueRanges() {}
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
virtual void dump() const {
|
|
|
|
dump(*cerr.stream());
|
|
|
|
}
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
void dump(std::ostream &os) const {
|
|
|
|
for (unsigned i = 0, e = Ranges.size(); i != e; ++i) {
|
|
|
|
os << (i+1) << " = ";
|
|
|
|
Ranges[i].dump(os);
|
|
|
|
os << "\n";
|
2007-03-10 19:12:48 +01:00
|
|
|
}
|
|
|
|
}
|
2007-04-07 17:48:32 +02:00
|
|
|
#endif
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
/// range - looks up the ConstantRange associated with a value number.
|
|
|
|
ConstantRange range(unsigned n, DomTreeDFS::Node *Subtree) {
|
|
|
|
assert(VN.value(n)); // performs range checks
|
2007-04-07 17:48:32 +02:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
if (n <= Ranges.size()) {
|
|
|
|
ScopedRange::iterator I = Ranges[n-1].find(Subtree);
|
|
|
|
if (I != Ranges[n-1].end()) return I->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *V = VN.value(n);
|
|
|
|
ConstantRange CR = range(V);
|
|
|
|
return CR;
|
|
|
|
}
|
2007-04-07 17:48:32 +02:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
/// range - determine a range from a Value without performing any lookups.
|
|
|
|
ConstantRange range(Value *V) const {
|
|
|
|
if (ConstantInt *C = dyn_cast<ConstantInt>(V))
|
2007-03-10 19:12:48 +01:00
|
|
|
return ConstantRange(C->getValue());
|
2007-07-10 05:28:21 +02:00
|
|
|
else if (isa<ConstantPointerNull>(V))
|
|
|
|
return ConstantRange(APInt::getNullValue(typeToWidth(V->getType())));
|
|
|
|
else
|
2008-02-20 17:44:09 +01:00
|
|
|
return ConstantRange(typeToWidth(V->getType()));
|
2007-03-10 19:12:48 +01:00
|
|
|
}
|
|
|
|
|
2007-04-07 05:16:12 +02:00
|
|
|
// typeToWidth - returns the number of bits necessary to store a value of
|
|
|
|
// this type, or zero if unknown.
|
|
|
|
uint32_t typeToWidth(const Type *Ty) const {
|
|
|
|
if (TD)
|
|
|
|
return TD->getTypeSizeInBits(Ty);
|
Executive summary: getTypeSize -> getTypeStoreSize / getABITypeSize.
The meaning of getTypeSize was not clear - clarifying it is important
now that we have x86 long double and arbitrary precision integers.
The issue with long double is that it requires 80 bits, and this is
not a multiple of its alignment. This gives a primitive type for
which getTypeSize differed from getABITypeSize. For arbitrary precision
integers it is even worse: there is the minimum number of bits needed to
hold the type (eg: 36 for an i36), the maximum number of bits that will
be overwriten when storing the type (40 bits for i36) and the ABI size
(i.e. the storage size rounded up to a multiple of the alignment; 64 bits
for i36).
This patch removes getTypeSize (not really - it is still there but
deprecated to allow for a gradual transition). Instead there is:
(1) getTypeSizeInBits - a number of bits that suffices to hold all
values of the type. For a primitive type, this is the minimum number
of bits. For an i36 this is 36 bits. For x86 long double it is 80.
This corresponds to gcc's TYPE_PRECISION.
(2) getTypeStoreSizeInBits - the maximum number of bits that is
written when storing the type (or read when reading it). For an
i36 this is 40 bits, for an x86 long double it is 80 bits. This
is the size alias analysis is interested in (getTypeStoreSize
returns the number of bytes). There doesn't seem to be anything
corresponding to this in gcc.
(3) getABITypeSizeInBits - this is getTypeStoreSizeInBits rounded
up to a multiple of the alignment. For an i36 this is 64, for an
x86 long double this is 96 or 128 depending on the OS. This is the
spacing between consecutive elements when you form an array out of
this type (getABITypeSize returns the number of bytes). This is
TYPE_SIZE in gcc.
Since successive elements in a SequentialType (arrays, pointers
and vectors) need to be aligned, the spacing between them will be
given by getABITypeSize. This means that the size of an array
is the length times the getABITypeSize. It also means that GEP
computations need to use getABITypeSize when computing offsets.
Furthermore, if an alloca allocates several elements at once then
these too need to be aligned, so the size of the alloca has to be
the number of elements multiplied by getABITypeSize. Logically
speaking this doesn't have to be the case when allocating just
one element, but it is simpler to also use getABITypeSize in this
case. So alloca's and mallocs should use getABITypeSize. Finally,
since gcc's only notion of size is that given by getABITypeSize, if
you want to output assembler etc the same as gcc then getABITypeSize
is the size you want.
Since a store will overwrite no more than getTypeStoreSize bytes,
and a read will read no more than that many bytes, this is the
notion of size appropriate for alias analysis calculations.
In this patch I have corrected all type size uses except some of
those in ScalarReplAggregates, lib/Codegen, lib/Target (the hard
cases). I will get around to auditing these too at some point,
but I could do with some help.
Finally, I made one change which I think wise but others might
consider pointless and suboptimal: in an unpacked struct the
amount of space allocated for a field is now given by the ABI
size rather than getTypeStoreSize. I did this because every
other place that reserves memory for a type (eg: alloca) now
uses getABITypeSize, and I didn't want to make an exception
for unpacked structs, i.e. I did it to make things more uniform.
This only effects structs containing long doubles and arbitrary
precision integers. If someone wants to pack these types more
tightly they can always use a packed struct.
llvm-svn: 43620
2007-11-01 21:53:16 +01:00
|
|
|
else
|
|
|
|
return Ty->getPrimitiveSizeInBits();
|
2007-03-10 19:12:48 +01:00
|
|
|
}
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
static bool isRelatedBy(const ConstantRange &CR1, const ConstantRange &CR2,
|
|
|
|
LatticeVal LV) {
|
2007-03-16 03:37:39 +01:00
|
|
|
switch (LV) {
|
2007-03-10 19:12:48 +01:00
|
|
|
default: assert(!"Impossible lattice value!");
|
|
|
|
case NE:
|
2007-07-14 06:28:04 +02:00
|
|
|
return CR1.maximalIntersectWith(CR2).isEmptySet();
|
2007-03-10 19:12:48 +01:00
|
|
|
case ULT:
|
|
|
|
return CR1.getUnsignedMax().ult(CR2.getUnsignedMin());
|
|
|
|
case ULE:
|
|
|
|
return CR1.getUnsignedMax().ule(CR2.getUnsignedMin());
|
|
|
|
case UGT:
|
|
|
|
return CR1.getUnsignedMin().ugt(CR2.getUnsignedMax());
|
|
|
|
case UGE:
|
|
|
|
return CR1.getUnsignedMin().uge(CR2.getUnsignedMax());
|
|
|
|
case SLT:
|
|
|
|
return CR1.getSignedMax().slt(CR2.getSignedMin());
|
|
|
|
case SLE:
|
|
|
|
return CR1.getSignedMax().sle(CR2.getSignedMin());
|
|
|
|
case SGT:
|
|
|
|
return CR1.getSignedMin().sgt(CR2.getSignedMax());
|
|
|
|
case SGE:
|
|
|
|
return CR1.getSignedMin().sge(CR2.getSignedMax());
|
|
|
|
case LT:
|
|
|
|
return CR1.getUnsignedMax().ult(CR2.getUnsignedMin()) &&
|
|
|
|
CR1.getSignedMax().slt(CR2.getUnsignedMin());
|
|
|
|
case LE:
|
|
|
|
return CR1.getUnsignedMax().ule(CR2.getUnsignedMin()) &&
|
|
|
|
CR1.getSignedMax().sle(CR2.getUnsignedMin());
|
|
|
|
case GT:
|
|
|
|
return CR1.getUnsignedMin().ugt(CR2.getUnsignedMax()) &&
|
|
|
|
CR1.getSignedMin().sgt(CR2.getSignedMax());
|
|
|
|
case GE:
|
|
|
|
return CR1.getUnsignedMin().uge(CR2.getUnsignedMax()) &&
|
|
|
|
CR1.getSignedMin().sge(CR2.getSignedMax());
|
|
|
|
case SLTUGT:
|
|
|
|
return CR1.getSignedMax().slt(CR2.getSignedMin()) &&
|
|
|
|
CR1.getUnsignedMin().ugt(CR2.getUnsignedMax());
|
|
|
|
case SLEUGE:
|
|
|
|
return CR1.getSignedMax().sle(CR2.getSignedMin()) &&
|
|
|
|
CR1.getUnsignedMin().uge(CR2.getUnsignedMax());
|
|
|
|
case SGTULT:
|
|
|
|
return CR1.getSignedMin().sgt(CR2.getSignedMax()) &&
|
|
|
|
CR1.getUnsignedMax().ult(CR2.getUnsignedMin());
|
|
|
|
case SGEULE:
|
|
|
|
return CR1.getSignedMin().sge(CR2.getSignedMax()) &&
|
|
|
|
CR1.getUnsignedMax().ule(CR2.getUnsignedMin());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
bool isRelatedBy(unsigned n1, unsigned n2, DomTreeDFS::Node *Subtree,
|
|
|
|
LatticeVal LV) {
|
|
|
|
ConstantRange CR1 = range(n1, Subtree);
|
|
|
|
ConstantRange CR2 = range(n2, Subtree);
|
|
|
|
|
|
|
|
// True iff all values in CR1 are LV to all values in CR2.
|
|
|
|
return isRelatedBy(CR1, CR2, LV);
|
|
|
|
}
|
|
|
|
|
2007-04-07 05:36:51 +02:00
|
|
|
void addToWorklist(Value *V, Constant *C, ICmpInst::Predicate Pred,
|
2007-03-10 19:12:48 +01:00
|
|
|
VRPSolver *VRP);
|
2007-04-07 17:48:32 +02:00
|
|
|
void markBlock(VRPSolver *VRP);
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
void mergeInto(Value **I, unsigned n, unsigned New,
|
2007-06-24 06:36:20 +02:00
|
|
|
DomTreeDFS::Node *Subtree, VRPSolver *VRP) {
|
2007-07-10 05:28:21 +02:00
|
|
|
ConstantRange CR_New = range(New, Subtree);
|
2007-03-18 02:09:32 +01:00
|
|
|
ConstantRange Merged = CR_New;
|
|
|
|
|
|
|
|
for (; n != 0; ++I, --n) {
|
2007-07-10 05:28:21 +02:00
|
|
|
unsigned i = VN.valueNumber(*I, Subtree);
|
|
|
|
ConstantRange CR_Kill = i ? range(i, Subtree) : range(*I);
|
2007-03-18 02:09:32 +01:00
|
|
|
if (CR_Kill.isFullSet()) continue;
|
2007-07-14 06:28:04 +02:00
|
|
|
Merged = Merged.maximalIntersectWith(CR_Kill);
|
2007-03-18 02:09:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Merged.isFullSet() || Merged == CR_New) return;
|
|
|
|
|
2007-04-07 05:36:51 +02:00
|
|
|
applyRange(New, Merged, Subtree, VRP);
|
|
|
|
}
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
void applyRange(unsigned n, const ConstantRange &CR,
|
2007-06-24 06:36:20 +02:00
|
|
|
DomTreeDFS::Node *Subtree, VRPSolver *VRP) {
|
2007-07-14 06:28:04 +02:00
|
|
|
ConstantRange Merged = CR.maximalIntersectWith(range(n, Subtree));
|
2007-07-10 05:28:21 +02:00
|
|
|
if (Merged.isEmptySet()) {
|
|
|
|
markBlock(VRP);
|
|
|
|
return;
|
|
|
|
}
|
2007-04-07 05:36:51 +02:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
if (const APInt *I = Merged.getSingleElement()) {
|
|
|
|
Value *V = VN.value(n); // XXX: redesign worklist.
|
2007-04-07 05:36:51 +02:00
|
|
|
const Type *Ty = V->getType();
|
|
|
|
if (Ty->isInteger()) {
|
2009-07-16 20:04:31 +02:00
|
|
|
addToWorklist(V, Context->getConstantInt(*I), ICmpInst::ICMP_EQ, VRP);
|
2007-04-07 05:36:51 +02:00
|
|
|
return;
|
|
|
|
} else if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
|
|
|
|
assert(*I == 0 && "Pointer is null but not zero?");
|
|
|
|
addToWorklist(V, ConstantPointerNull::get(PTy),
|
2007-07-10 05:28:21 +02:00
|
|
|
ICmpInst::ICMP_EQ, VRP);
|
2007-04-07 05:36:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
update(n, Merged, Subtree);
|
2007-03-18 02:09:32 +01:00
|
|
|
}
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
void addNotEquals(unsigned n1, unsigned n2, DomTreeDFS::Node *Subtree,
|
2007-06-24 06:36:20 +02:00
|
|
|
VRPSolver *VRP) {
|
2007-07-10 05:28:21 +02:00
|
|
|
ConstantRange CR1 = range(n1, Subtree);
|
|
|
|
ConstantRange CR2 = range(n2, Subtree);
|
2007-04-07 06:49:12 +02:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
uint32_t W = CR1.getBitWidth();
|
2007-04-07 06:49:12 +02:00
|
|
|
|
|
|
|
if (const APInt *I = CR1.getSingleElement()) {
|
|
|
|
if (CR2.isFullSet()) {
|
|
|
|
ConstantRange NewCR2(CR1.getUpper(), CR1.getLower());
|
2007-07-10 05:28:21 +02:00
|
|
|
applyRange(n2, NewCR2, Subtree, VRP);
|
2007-04-07 06:49:12 +02:00
|
|
|
} else if (*I == CR2.getLower()) {
|
2007-04-19 07:35:00 +02:00
|
|
|
APInt NewLower(CR2.getLower() + 1),
|
|
|
|
NewUpper(CR2.getUpper());
|
2007-04-07 06:49:12 +02:00
|
|
|
if (NewLower == NewUpper)
|
|
|
|
NewLower = NewUpper = APInt::getMinValue(W);
|
|
|
|
|
|
|
|
ConstantRange NewCR2(NewLower, NewUpper);
|
2007-07-10 05:28:21 +02:00
|
|
|
applyRange(n2, NewCR2, Subtree, VRP);
|
2007-04-07 06:49:12 +02:00
|
|
|
} else if (*I == CR2.getUpper() - 1) {
|
2007-04-19 07:35:00 +02:00
|
|
|
APInt NewLower(CR2.getLower()),
|
|
|
|
NewUpper(CR2.getUpper() - 1);
|
2007-04-07 06:49:12 +02:00
|
|
|
if (NewLower == NewUpper)
|
|
|
|
NewLower = NewUpper = APInt::getMinValue(W);
|
|
|
|
|
|
|
|
ConstantRange NewCR2(NewLower, NewUpper);
|
2007-07-10 05:28:21 +02:00
|
|
|
applyRange(n2, NewCR2, Subtree, VRP);
|
2007-04-07 06:49:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const APInt *I = CR2.getSingleElement()) {
|
|
|
|
if (CR1.isFullSet()) {
|
|
|
|
ConstantRange NewCR1(CR2.getUpper(), CR2.getLower());
|
2007-07-10 05:28:21 +02:00
|
|
|
applyRange(n1, NewCR1, Subtree, VRP);
|
2007-04-07 06:49:12 +02:00
|
|
|
} else if (*I == CR1.getLower()) {
|
2007-04-19 07:35:00 +02:00
|
|
|
APInt NewLower(CR1.getLower() + 1),
|
|
|
|
NewUpper(CR1.getUpper());
|
2007-04-07 06:49:12 +02:00
|
|
|
if (NewLower == NewUpper)
|
|
|
|
NewLower = NewUpper = APInt::getMinValue(W);
|
|
|
|
|
|
|
|
ConstantRange NewCR1(NewLower, NewUpper);
|
2007-07-10 05:28:21 +02:00
|
|
|
applyRange(n1, NewCR1, Subtree, VRP);
|
2007-04-07 06:49:12 +02:00
|
|
|
} else if (*I == CR1.getUpper() - 1) {
|
2007-04-19 07:35:00 +02:00
|
|
|
APInt NewLower(CR1.getLower()),
|
|
|
|
NewUpper(CR1.getUpper() - 1);
|
2007-04-07 06:49:12 +02:00
|
|
|
if (NewLower == NewUpper)
|
|
|
|
NewLower = NewUpper = APInt::getMinValue(W);
|
|
|
|
|
|
|
|
ConstantRange NewCR1(NewLower, NewUpper);
|
2007-07-10 05:28:21 +02:00
|
|
|
applyRange(n1, NewCR1, Subtree, VRP);
|
2007-04-07 06:49:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
void addInequality(unsigned n1, unsigned n2, DomTreeDFS::Node *Subtree,
|
2007-06-24 06:36:20 +02:00
|
|
|
LatticeVal LV, VRPSolver *VRP) {
|
2007-07-10 05:28:21 +02:00
|
|
|
assert(!isRelatedBy(n1, n2, Subtree, LV) && "Asked to do useless work.");
|
2007-03-18 02:09:32 +01:00
|
|
|
|
2007-04-07 06:49:12 +02:00
|
|
|
if (LV == NE) {
|
2007-07-10 05:28:21 +02:00
|
|
|
addNotEquals(n1, n2, Subtree, VRP);
|
2007-04-07 06:49:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
ConstantRange CR1 = range(n1, Subtree);
|
|
|
|
ConstantRange CR2 = range(n2, Subtree);
|
2007-03-10 19:12:48 +01:00
|
|
|
|
|
|
|
if (!CR1.isSingleElement()) {
|
2007-07-14 06:28:04 +02:00
|
|
|
ConstantRange NewCR1 = CR1.maximalIntersectWith(create(LV, CR2));
|
2007-04-07 05:36:51 +02:00
|
|
|
if (NewCR1 != CR1)
|
2007-07-10 05:28:21 +02:00
|
|
|
applyRange(n1, NewCR1, Subtree, VRP);
|
2007-03-10 19:12:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!CR2.isSingleElement()) {
|
2007-07-14 06:28:04 +02:00
|
|
|
ConstantRange NewCR2 = CR2.maximalIntersectWith(
|
|
|
|
create(reversePredicate(LV), CR1));
|
2007-04-07 05:36:51 +02:00
|
|
|
if (NewCR2 != CR2)
|
2007-07-10 05:28:21 +02:00
|
|
|
applyRange(n2, NewCR2, Subtree, VRP);
|
2007-03-10 19:12:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
/// UnreachableBlocks keeps tracks of blocks that are for one reason or
|
|
|
|
/// another discovered to be unreachable. This is used to cull the graph when
|
|
|
|
/// analyzing instructions, and to mark blocks with the "unreachable"
|
|
|
|
/// terminator instruction after the function has executed.
|
|
|
|
class VISIBILITY_HIDDEN UnreachableBlocks {
|
|
|
|
private:
|
|
|
|
std::vector<BasicBlock *> DeadBlocks;
|
2006-09-10 04:27:07 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
public:
|
|
|
|
/// mark - mark a block as dead
|
|
|
|
void mark(BasicBlock *BB) {
|
|
|
|
std::vector<BasicBlock *>::iterator E = DeadBlocks.end();
|
|
|
|
std::vector<BasicBlock *>::iterator I =
|
|
|
|
std::lower_bound(DeadBlocks.begin(), E, BB);
|
2006-09-10 04:27:07 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
if (I == E || *I != BB) DeadBlocks.insert(I, BB);
|
2006-09-10 04:27:07 +02:00
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
/// isDead - returns whether a block is known to be dead already
|
|
|
|
bool isDead(BasicBlock *BB) {
|
|
|
|
std::vector<BasicBlock *>::iterator E = DeadBlocks.end();
|
|
|
|
std::vector<BasicBlock *>::iterator I =
|
|
|
|
std::lower_bound(DeadBlocks.begin(), E, BB);
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
return I != E && *I == BB;
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
/// kill - replace the dead blocks' terminator with an UnreachableInst.
|
|
|
|
bool kill() {
|
|
|
|
bool modified = false;
|
|
|
|
for (std::vector<BasicBlock *>::iterator I = DeadBlocks.begin(),
|
|
|
|
E = DeadBlocks.end(); I != E; ++I) {
|
|
|
|
BasicBlock *BB = *I;
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
DOUT << "unreachable block: " << BB->getName() << "\n";
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB);
|
|
|
|
SI != SE; ++SI) {
|
|
|
|
BasicBlock *Succ = *SI;
|
|
|
|
Succ->removePredecessor(BB);
|
2006-09-20 19:04:01 +02:00
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
|
|
|
|
TerminatorInst *TI = BB->getTerminator();
|
|
|
|
TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
|
|
|
|
TI->eraseFromParent();
|
|
|
|
new UnreachableInst(BB);
|
|
|
|
++NumBlocks;
|
|
|
|
modified = true;
|
2006-09-20 19:04:01 +02:00
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
DeadBlocks.clear();
|
|
|
|
return modified;
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
};
|
2006-11-23 00:49:16 +01:00
|
|
|
|
|
|
|
/// VRPSolver keeps track of how changes to one variable affect other
|
|
|
|
/// variables, and forwards changes along to the InequalityGraph. It
|
|
|
|
/// also maintains the correct choice for "canonical" in the IG.
|
|
|
|
/// @brief VRPSolver calculates inferences from a new relationship.
|
|
|
|
class VISIBILITY_HIDDEN VRPSolver {
|
|
|
|
private:
|
2007-03-10 19:12:48 +01:00
|
|
|
friend class ValueRanges;
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
struct Operation {
|
|
|
|
Value *LHS, *RHS;
|
|
|
|
ICmpInst::Predicate Op;
|
|
|
|
|
2007-06-24 06:36:20 +02:00
|
|
|
BasicBlock *ContextBB; // XXX use a DomTreeDFS::Node instead
|
2007-01-13 03:05:28 +01:00
|
|
|
Instruction *ContextInst;
|
2007-01-11 03:32:38 +01:00
|
|
|
};
|
|
|
|
std::deque<Operation> WorkList;
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
ValueNumbering &VN;
|
2006-11-23 00:49:16 +01:00
|
|
|
InequalityGraph &IG;
|
2007-01-11 03:32:38 +01:00
|
|
|
UnreachableBlocks &UB;
|
2007-03-10 19:12:48 +01:00
|
|
|
ValueRanges &VR;
|
2007-06-24 06:36:20 +02:00
|
|
|
DomTreeDFS *DTDFS;
|
|
|
|
DomTreeDFS::Node *Top;
|
2007-01-11 03:32:38 +01:00
|
|
|
BasicBlock *TopBB;
|
|
|
|
Instruction *TopInst;
|
|
|
|
bool &modified;
|
2009-07-13 06:09:18 +02:00
|
|
|
LLVMContext *Context;
|
2006-11-23 00:49:16 +01:00
|
|
|
|
|
|
|
typedef InequalityGraph::Node Node;
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
// below - true if the Instruction is dominated by the current context
|
|
|
|
// block or instruction
|
|
|
|
bool below(Instruction *I) {
|
2007-06-24 06:36:20 +02:00
|
|
|
BasicBlock *BB = I->getParent();
|
|
|
|
if (TopInst && TopInst->getParent() == BB) {
|
|
|
|
if (isa<TerminatorInst>(TopInst)) return false;
|
|
|
|
if (isa<TerminatorInst>(I)) return true;
|
|
|
|
if ( isa<PHINode>(TopInst) && !isa<PHINode>(I)) return true;
|
|
|
|
if (!isa<PHINode>(TopInst) && isa<PHINode>(I)) return false;
|
|
|
|
|
|
|
|
for (BasicBlock::const_iterator Iter = BB->begin(), E = BB->end();
|
|
|
|
Iter != E; ++Iter) {
|
|
|
|
if (&*Iter == TopInst) return true;
|
|
|
|
else if (&*Iter == I) return false;
|
|
|
|
}
|
|
|
|
assert(!"Instructions not found in parent BasicBlock?");
|
|
|
|
} else {
|
2007-06-24 06:40:16 +02:00
|
|
|
DomTreeDFS::Node *Node = DTDFS->getNodeForBlock(BB);
|
2007-06-24 06:36:20 +02:00
|
|
|
if (!Node) return false;
|
|
|
|
return Top->dominates(Node);
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2008-03-30 20:22:13 +02:00
|
|
|
return false; // Not reached
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-06-24 06:36:20 +02:00
|
|
|
// aboveOrBelow - true if the Instruction either dominates or is dominated
|
|
|
|
// by the current context block or instruction
|
|
|
|
bool aboveOrBelow(Instruction *I) {
|
|
|
|
BasicBlock *BB = I->getParent();
|
|
|
|
DomTreeDFS::Node *Node = DTDFS->getNodeForBlock(BB);
|
|
|
|
if (!Node) return false;
|
|
|
|
|
|
|
|
return Top == Node || Top->dominates(Node) || Node->dominates(Top);
|
|
|
|
}
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
bool makeEqual(Value *V1, Value *V2) {
|
|
|
|
DOUT << "makeEqual(" << *V1 << ", " << *V2 << ")\n";
|
2007-06-24 06:36:20 +02:00
|
|
|
DOUT << "context is ";
|
|
|
|
if (TopInst) DOUT << "I: " << *TopInst << "\n";
|
|
|
|
else DOUT << "BB: " << TopBB->getName()
|
|
|
|
<< "(" << Top->getDFSNumIn() << ")\n";
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-04-07 05:16:12 +02:00
|
|
|
assert(V1->getType() == V2->getType() &&
|
|
|
|
"Can't make two values with different types equal.");
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
if (V1 == V2) return true;
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
if (isa<Constant>(V1) && isa<Constant>(V2))
|
|
|
|
return false;
|
2006-10-26 01:48:24 +02:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
unsigned n1 = VN.valueNumber(V1, Top), n2 = VN.valueNumber(V2, Top);
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
if (n1 && n2) {
|
|
|
|
if (n1 == n2) return true;
|
|
|
|
if (IG.isRelatedBy(n1, n2, Top, NE)) return false;
|
|
|
|
}
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
if (n1) assert(V1 == VN.value(n1) && "Value isn't canonical.");
|
|
|
|
if (n2) assert(V2 == VN.value(n2) && "Value isn't canonical.");
|
2006-09-02 21:40:38 +02:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
assert(!VN.compare(V2, V1) && "Please order parameters to makeEqual.");
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
assert(!isa<Constant>(V2) && "Tried to remove a constant.");
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
SetVector<unsigned> Remove;
|
|
|
|
if (n2) Remove.insert(n2);
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
if (n1 && n2) {
|
|
|
|
// Suppose we're being told that %x == %y, and %x <= %z and %y >= %z.
|
|
|
|
// We can't just merge %x and %y because the relationship with %z would
|
|
|
|
// be EQ and that's invalid. What we're doing is looking for any nodes
|
|
|
|
// %z such that %x <= %z and %y >= %z, and vice versa.
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
Node::iterator end = IG.node(n2)->end();
|
2007-01-15 15:30:07 +01:00
|
|
|
|
|
|
|
// Find the intersection between N1 and N2 which is dominated by
|
|
|
|
// Top. If we find %x where N1 <= %x <= N2 (or >=) then add %x to
|
|
|
|
// Remove.
|
2007-07-10 05:28:21 +02:00
|
|
|
for (Node::iterator I = IG.node(n1)->begin(), E = IG.node(n1)->end();
|
|
|
|
I != E; ++I) {
|
2007-01-15 15:30:07 +01:00
|
|
|
if (!(I->LV & EQ_BIT) || !Top->DominatedBy(I->Subtree)) continue;
|
|
|
|
|
|
|
|
unsigned ILV_s = I->LV & (SLT_BIT|SGT_BIT);
|
|
|
|
unsigned ILV_u = I->LV & (ULT_BIT|UGT_BIT);
|
2007-07-10 05:28:21 +02:00
|
|
|
Node::iterator NI = IG.node(n2)->find(I->To, Top);
|
2007-01-15 15:30:07 +01:00
|
|
|
if (NI != end) {
|
|
|
|
LatticeVal NILV = reversePredicate(NI->LV);
|
|
|
|
unsigned NILV_s = NILV & (SLT_BIT|SGT_BIT);
|
|
|
|
unsigned NILV_u = NILV & (ULT_BIT|UGT_BIT);
|
|
|
|
|
|
|
|
if ((ILV_s != (SLT_BIT|SGT_BIT) && ILV_s == NILV_s) ||
|
|
|
|
(ILV_u != (ULT_BIT|UGT_BIT) && ILV_u == NILV_u))
|
|
|
|
Remove.insert(I->To);
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
// See if one of the nodes about to be removed is actually a better
|
|
|
|
// canonical choice than n1.
|
|
|
|
unsigned orig_n1 = n1;
|
2007-01-17 03:23:37 +01:00
|
|
|
SetVector<unsigned>::iterator DontRemove = Remove.end();
|
|
|
|
for (SetVector<unsigned>::iterator I = Remove.begin()+1 /* skip n2 */,
|
2007-01-11 03:32:38 +01:00
|
|
|
E = Remove.end(); I != E; ++I) {
|
|
|
|
unsigned n = *I;
|
2007-07-05 05:15:00 +02:00
|
|
|
Value *V = VN.value(n);
|
|
|
|
if (VN.compare(V, V1)) {
|
2007-01-11 03:32:38 +01:00
|
|
|
V1 = V;
|
|
|
|
n1 = n;
|
|
|
|
DontRemove = I;
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
if (DontRemove != Remove.end()) {
|
|
|
|
unsigned n = *DontRemove;
|
|
|
|
Remove.remove(n);
|
|
|
|
Remove.insert(orig_n1);
|
|
|
|
}
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
// We'd like to allow makeEqual on two values to perform a simple
|
2008-05-27 00:49:36 +02:00
|
|
|
// substitution without creating nodes in the IG whenever possible.
|
2007-01-11 03:32:38 +01:00
|
|
|
//
|
|
|
|
// The first iteration through this loop operates on V2 before going
|
|
|
|
// through the Remove list and operating on those too. If all of the
|
|
|
|
// iterations performed simple replacements then we exit early.
|
2007-03-18 02:09:32 +01:00
|
|
|
bool mergeIGNode = false;
|
2007-01-11 03:32:38 +01:00
|
|
|
unsigned i = 0;
|
|
|
|
for (Value *R = V2; i == 0 || i < Remove.size(); ++i) {
|
2007-07-05 05:15:00 +02:00
|
|
|
if (i) R = VN.value(Remove[i]); // skip n2.
|
2007-01-11 03:32:38 +01:00
|
|
|
|
|
|
|
// Try to replace the whole instruction. If we can, we're done.
|
|
|
|
Instruction *I2 = dyn_cast<Instruction>(R);
|
|
|
|
if (I2 && below(I2)) {
|
|
|
|
std::vector<Instruction *> ToNotify;
|
2009-06-06 19:49:35 +02:00
|
|
|
for (Value::use_iterator UI = I2->use_begin(), UE = I2->use_end();
|
2007-01-11 03:32:38 +01:00
|
|
|
UI != UE;) {
|
|
|
|
Use &TheUse = UI.getUse();
|
|
|
|
++UI;
|
2009-06-06 19:49:35 +02:00
|
|
|
Instruction *I = cast<Instruction>(TheUse.getUser());
|
|
|
|
ToNotify.push_back(I);
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2006-10-26 01:48:24 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
DOUT << "Simply removing " << *I2
|
|
|
|
<< ", replacing with " << *V1 << "\n";
|
|
|
|
I2->replaceAllUsesWith(V1);
|
|
|
|
// leave it dead; it'll get erased later.
|
|
|
|
++NumInstruction;
|
|
|
|
modified = true;
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
for (std::vector<Instruction *>::iterator II = ToNotify.begin(),
|
|
|
|
IE = ToNotify.end(); II != IE; ++II) {
|
|
|
|
opsToDef(*II);
|
|
|
|
}
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
continue;
|
|
|
|
}
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
// Otherwise, replace all dominated uses.
|
|
|
|
for (Value::use_iterator UI = R->use_begin(), UE = R->use_end();
|
|
|
|
UI != UE;) {
|
|
|
|
Use &TheUse = UI.getUse();
|
|
|
|
++UI;
|
|
|
|
if (Instruction *I = dyn_cast<Instruction>(TheUse.getUser())) {
|
|
|
|
if (below(I)) {
|
|
|
|
TheUse.set(V1);
|
|
|
|
modified = true;
|
|
|
|
++NumVarsReplaced;
|
|
|
|
opsToDef(I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
// If that killed the instruction, stop here.
|
|
|
|
if (I2 && isInstructionTriviallyDead(I2)) {
|
|
|
|
DOUT << "Killed all uses of " << *I2
|
|
|
|
<< ", replacing with " << *V1 << "\n";
|
|
|
|
continue;
|
|
|
|
}
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
// If we make it to here, then we will need to create a node for N1.
|
|
|
|
// Otherwise, we can skip out early!
|
2007-03-18 02:09:32 +01:00
|
|
|
mergeIGNode = true;
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2006-09-13 21:24:01 +02:00
|
|
|
|
2007-03-18 02:09:32 +01:00
|
|
|
if (!isa<Constant>(V1)) {
|
|
|
|
if (Remove.empty()) {
|
2007-07-10 05:28:21 +02:00
|
|
|
VR.mergeInto(&V2, 1, VN.getOrInsertVN(V1, Top), Top, this);
|
2007-03-18 02:09:32 +01:00
|
|
|
} else {
|
|
|
|
std::vector<Value*> RemoveVals;
|
|
|
|
RemoveVals.reserve(Remove.size());
|
|
|
|
|
|
|
|
for (SetVector<unsigned>::iterator I = Remove.begin(),
|
|
|
|
E = Remove.end(); I != E; ++I) {
|
2007-07-05 05:15:00 +02:00
|
|
|
Value *V = VN.value(*I);
|
2007-03-18 02:09:32 +01:00
|
|
|
if (!V->use_empty())
|
|
|
|
RemoveVals.push_back(V);
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2007-07-10 05:28:21 +02:00
|
|
|
VR.mergeInto(&RemoveVals[0], RemoveVals.size(),
|
|
|
|
VN.getOrInsertVN(V1, Top), Top, this);
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-03-18 02:09:32 +01:00
|
|
|
if (mergeIGNode) {
|
|
|
|
// Create N1.
|
2007-07-10 05:28:21 +02:00
|
|
|
if (!n1) n1 = VN.getOrInsertVN(V1, Top);
|
2008-05-27 02:59:05 +02:00
|
|
|
IG.node(n1); // Ensure that IG.Nodes won't get resized
|
2007-03-18 02:09:32 +01:00
|
|
|
|
|
|
|
// Migrate relationships from removed nodes to N1.
|
|
|
|
for (SetVector<unsigned>::iterator I = Remove.begin(), E = Remove.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
unsigned n = *I;
|
2007-07-10 05:28:21 +02:00
|
|
|
for (Node::iterator NI = IG.node(n)->begin(), NE = IG.node(n)->end();
|
|
|
|
NI != NE; ++NI) {
|
2007-03-18 02:09:32 +01:00
|
|
|
if (NI->Subtree->DominatedBy(Top)) {
|
|
|
|
if (NI->To == n1) {
|
|
|
|
assert((NI->LV & EQ_BIT) && "Node inequal to itself.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Remove.count(NI->To))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
IG.node(NI->To)->update(n1, reversePredicate(NI->LV), Top);
|
2007-07-10 05:28:21 +02:00
|
|
|
IG.node(n1)->update(NI->To, NI->LV, Top);
|
2007-03-18 02:09:32 +01:00
|
|
|
}
|
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2006-09-13 21:24:01 +02:00
|
|
|
|
2007-03-18 02:09:32 +01:00
|
|
|
// Point V2 (and all items in Remove) to N1.
|
|
|
|
if (!n2)
|
2007-07-05 05:15:00 +02:00
|
|
|
VN.addEquality(n1, V2, Top);
|
2007-03-18 02:09:32 +01:00
|
|
|
else {
|
|
|
|
for (SetVector<unsigned>::iterator I = Remove.begin(),
|
|
|
|
E = Remove.end(); I != E; ++I) {
|
2007-07-05 05:15:00 +02:00
|
|
|
VN.addEquality(n1, VN.value(*I), Top);
|
2007-03-18 02:09:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If !Remove.empty() then V2 = Remove[0]->getValue().
|
|
|
|
// Even when Remove is empty, we still want to process V2.
|
|
|
|
i = 0;
|
|
|
|
for (Value *R = V2; i == 0 || i < Remove.size(); ++i) {
|
2007-07-05 05:15:00 +02:00
|
|
|
if (i) R = VN.value(Remove[i]); // skip n2.
|
2007-01-11 03:32:38 +01:00
|
|
|
|
2007-03-18 02:09:32 +01:00
|
|
|
if (Instruction *I2 = dyn_cast<Instruction>(R)) {
|
2007-06-24 06:36:20 +02:00
|
|
|
if (aboveOrBelow(I2))
|
2007-03-18 02:09:32 +01:00
|
|
|
defToOps(I2);
|
|
|
|
}
|
|
|
|
for (Value::use_iterator UI = V2->use_begin(), UE = V2->use_end();
|
|
|
|
UI != UE;) {
|
|
|
|
Use &TheUse = UI.getUse();
|
|
|
|
++UI;
|
|
|
|
if (Instruction *I = dyn_cast<Instruction>(TheUse.getUser())) {
|
2007-06-24 06:36:20 +02:00
|
|
|
if (aboveOrBelow(I))
|
2007-03-18 02:09:32 +01:00
|
|
|
opsToDef(I);
|
|
|
|
}
|
|
|
|
}
|
2007-01-15 15:30:07 +01:00
|
|
|
}
|
2007-03-18 02:09:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// re-opsToDef all dominated users of V1.
|
|
|
|
if (Instruction *I = dyn_cast<Instruction>(V1)) {
|
|
|
|
for (Value::use_iterator UI = I->use_begin(), UE = I->use_end();
|
2007-01-11 03:32:38 +01:00
|
|
|
UI != UE;) {
|
|
|
|
Use &TheUse = UI.getUse();
|
|
|
|
++UI;
|
2007-03-18 02:09:32 +01:00
|
|
|
Value *V = TheUse.getUser();
|
|
|
|
if (!V->use_empty()) {
|
2009-06-06 19:49:35 +02:00
|
|
|
Instruction *Inst = cast<Instruction>(V);
|
|
|
|
if (aboveOrBelow(Inst))
|
|
|
|
opsToDef(Inst);
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-09-13 21:24:01 +02:00
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
return true;
|
2006-08-29 00:44:55 +02:00
|
|
|
}
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
/// cmpInstToLattice - converts an CmpInst::Predicate to lattice value
|
|
|
|
/// Requires that the lattice value be valid; does not accept ICMP_EQ.
|
|
|
|
static LatticeVal cmpInstToLattice(ICmpInst::Predicate Pred) {
|
|
|
|
switch (Pred) {
|
|
|
|
case ICmpInst::ICMP_EQ:
|
|
|
|
assert(!"No matching lattice value.");
|
|
|
|
return static_cast<LatticeVal>(EQ_BIT);
|
|
|
|
default:
|
|
|
|
assert(!"Invalid 'icmp' predicate.");
|
|
|
|
case ICmpInst::ICMP_NE:
|
|
|
|
return NE;
|
|
|
|
case ICmpInst::ICMP_UGT:
|
2007-01-29 03:56:54 +01:00
|
|
|
return UGT;
|
2007-01-11 03:32:38 +01:00
|
|
|
case ICmpInst::ICMP_UGE:
|
2007-01-29 03:56:54 +01:00
|
|
|
return UGE;
|
2007-01-11 03:32:38 +01:00
|
|
|
case ICmpInst::ICMP_ULT:
|
2007-01-29 03:56:54 +01:00
|
|
|
return ULT;
|
2007-01-11 03:32:38 +01:00
|
|
|
case ICmpInst::ICMP_ULE:
|
2007-01-29 03:56:54 +01:00
|
|
|
return ULE;
|
2007-01-11 03:32:38 +01:00
|
|
|
case ICmpInst::ICMP_SGT:
|
2007-01-29 03:56:54 +01:00
|
|
|
return SGT;
|
2007-01-11 03:32:38 +01:00
|
|
|
case ICmpInst::ICMP_SGE:
|
2007-01-29 03:56:54 +01:00
|
|
|
return SGE;
|
2007-01-11 03:32:38 +01:00
|
|
|
case ICmpInst::ICMP_SLT:
|
2007-01-29 03:56:54 +01:00
|
|
|
return SLT;
|
2007-01-11 03:32:38 +01:00
|
|
|
case ICmpInst::ICMP_SLE:
|
2007-01-29 03:56:54 +01:00
|
|
|
return SLE;
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
public:
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver(ValueNumbering &VN, InequalityGraph &IG, UnreachableBlocks &UB,
|
|
|
|
ValueRanges &VR, DomTreeDFS *DTDFS, bool &modified,
|
|
|
|
BasicBlock *TopBB)
|
|
|
|
: VN(VN),
|
|
|
|
IG(IG),
|
2007-01-11 03:32:38 +01:00
|
|
|
UB(UB),
|
2007-03-10 19:12:48 +01:00
|
|
|
VR(VR),
|
2007-06-24 06:36:20 +02:00
|
|
|
DTDFS(DTDFS),
|
|
|
|
Top(DTDFS->getNodeForBlock(TopBB)),
|
2007-01-11 03:32:38 +01:00
|
|
|
TopBB(TopBB),
|
|
|
|
TopInst(NULL),
|
2009-07-13 06:09:18 +02:00
|
|
|
modified(modified),
|
|
|
|
Context(TopBB->getContext())
|
2007-06-24 06:36:20 +02:00
|
|
|
{
|
|
|
|
assert(Top && "VRPSolver created for unreachable basic block.");
|
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver(ValueNumbering &VN, InequalityGraph &IG, UnreachableBlocks &UB,
|
|
|
|
ValueRanges &VR, DomTreeDFS *DTDFS, bool &modified,
|
|
|
|
Instruction *TopInst)
|
|
|
|
: VN(VN),
|
|
|
|
IG(IG),
|
2007-01-11 03:32:38 +01:00
|
|
|
UB(UB),
|
2007-03-10 19:12:48 +01:00
|
|
|
VR(VR),
|
2007-06-24 06:36:20 +02:00
|
|
|
DTDFS(DTDFS),
|
|
|
|
Top(DTDFS->getNodeForBlock(TopInst->getParent())),
|
|
|
|
TopBB(TopInst->getParent()),
|
2007-01-11 03:32:38 +01:00
|
|
|
TopInst(TopInst),
|
2009-07-16 20:04:31 +02:00
|
|
|
modified(modified),
|
|
|
|
Context(TopInst->getParent()->getContext())
|
2007-01-11 03:32:38 +01:00
|
|
|
{
|
2007-06-24 06:36:20 +02:00
|
|
|
assert(Top && "VRPSolver created for unreachable basic block.");
|
|
|
|
assert(Top->getBlock() == TopInst->getParent() && "Context mismatch.");
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
bool isRelatedBy(Value *V1, Value *V2, ICmpInst::Predicate Pred) const {
|
|
|
|
if (Constant *C1 = dyn_cast<Constant>(V1))
|
|
|
|
if (Constant *C2 = dyn_cast<Constant>(V2))
|
|
|
|
return ConstantExpr::getCompare(Pred, C1, C2) ==
|
2007-01-11 13:24:14 +01:00
|
|
|
ConstantInt::getTrue();
|
2007-01-11 03:32:38 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
unsigned n1 = VN.valueNumber(V1, Top);
|
|
|
|
unsigned n2 = VN.valueNumber(V2, Top);
|
|
|
|
|
|
|
|
if (n1 && n2) {
|
|
|
|
if (n1 == n2) return Pred == ICmpInst::ICMP_EQ ||
|
|
|
|
Pred == ICmpInst::ICMP_ULE ||
|
|
|
|
Pred == ICmpInst::ICMP_UGE ||
|
|
|
|
Pred == ICmpInst::ICMP_SLE ||
|
|
|
|
Pred == ICmpInst::ICMP_SGE;
|
|
|
|
if (Pred == ICmpInst::ICMP_EQ) return false;
|
|
|
|
if (IG.isRelatedBy(n1, n2, Top, cmpInstToLattice(Pred))) return true;
|
|
|
|
if (VR.isRelatedBy(n1, n2, Top, cmpInstToLattice(Pred))) return true;
|
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
if ((n1 && !n2 && isa<Constant>(V2)) ||
|
|
|
|
(n2 && !n1 && isa<Constant>(V1))) {
|
|
|
|
ConstantRange CR1 = n1 ? VR.range(n1, Top) : VR.range(V1);
|
|
|
|
ConstantRange CR2 = n2 ? VR.range(n2, Top) : VR.range(V2);
|
|
|
|
|
|
|
|
if (Pred == ICmpInst::ICMP_EQ)
|
|
|
|
return CR1.isSingleElement() &&
|
|
|
|
CR1.getSingleElement() == CR2.getSingleElement();
|
|
|
|
|
|
|
|
return VR.isRelatedBy(CR1, CR2, cmpInstToLattice(Pred));
|
|
|
|
}
|
2007-03-10 19:12:48 +01:00
|
|
|
if (Pred == ICmpInst::ICMP_EQ) return V1 == V2;
|
2007-07-10 05:28:21 +02:00
|
|
|
return false;
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
/// add - adds a new property to the work queue
|
|
|
|
void add(Value *V1, Value *V2, ICmpInst::Predicate Pred,
|
|
|
|
Instruction *I = NULL) {
|
|
|
|
DOUT << "adding " << *V1 << " " << Pred << " " << *V2;
|
|
|
|
if (I) DOUT << " context: " << *I;
|
2007-06-24 06:36:20 +02:00
|
|
|
else DOUT << " default context (" << Top->getDFSNumIn() << ")";
|
2007-01-11 03:32:38 +01:00
|
|
|
DOUT << "\n";
|
|
|
|
|
2007-04-07 05:16:12 +02:00
|
|
|
assert(V1->getType() == V2->getType() &&
|
|
|
|
"Can't relate two values with different types.");
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
WorkList.push_back(Operation());
|
|
|
|
Operation &O = WorkList.back();
|
2007-01-13 03:05:28 +01:00
|
|
|
O.LHS = V1, O.RHS = V2, O.Op = Pred, O.ContextInst = I;
|
|
|
|
O.ContextBB = I ? I->getParent() : TopBB;
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
/// defToOps - Given an instruction definition that we've learned something
|
|
|
|
/// new about, find any new relationships between its operands.
|
|
|
|
void defToOps(Instruction *I) {
|
|
|
|
Instruction *NewContext = below(I) ? I : TopInst;
|
2007-07-05 05:15:00 +02:00
|
|
|
Value *Canonical = VN.canonicalize(I, Top);
|
2007-01-11 03:32:38 +01:00
|
|
|
|
|
|
|
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(I)) {
|
|
|
|
const Type *Ty = BO->getType();
|
|
|
|
assert(!Ty->isFPOrFPVector() && "Float in work queue!");
|
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
Value *Op0 = VN.canonicalize(BO->getOperand(0), Top);
|
|
|
|
Value *Op1 = VN.canonicalize(BO->getOperand(1), Top);
|
2007-01-11 03:32:38 +01:00
|
|
|
|
2007-03-10 19:12:48 +01:00
|
|
|
// TODO: "and i32 -1, %x" EQ %y then %x EQ %y.
|
2007-01-11 03:32:38 +01:00
|
|
|
|
|
|
|
switch (BO->getOpcode()) {
|
|
|
|
case Instruction::And: {
|
2007-03-16 03:37:39 +01:00
|
|
|
// "and i32 %a, %b" EQ -1 then %a EQ -1 and %b EQ -1
|
2009-07-13 22:58:05 +02:00
|
|
|
ConstantInt *CI = cast<ConstantInt>(Context->getAllOnesValue(Ty));
|
2007-01-11 03:32:38 +01:00
|
|
|
if (Canonical == CI) {
|
|
|
|
add(CI, Op0, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
add(CI, Op1, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case Instruction::Or: {
|
2007-03-10 19:12:48 +01:00
|
|
|
// "or i32 %a, %b" EQ 0 then %a EQ 0 and %b EQ 0
|
2009-07-13 06:09:18 +02:00
|
|
|
Constant *Zero = Context->getNullValue(Ty);
|
2007-01-11 03:32:38 +01:00
|
|
|
if (Canonical == Zero) {
|
|
|
|
add(Zero, Op0, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
add(Zero, Op1, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case Instruction::Xor: {
|
2007-03-10 19:12:48 +01:00
|
|
|
// "xor i32 %c, %a" EQ %b then %a EQ %c ^ %b
|
|
|
|
// "xor i32 %c, %a" EQ %c then %a EQ 0
|
|
|
|
// "xor i32 %c, %a" NE %c then %a NE 0
|
|
|
|
// Repeat the above, with order of operands reversed.
|
2007-01-11 03:32:38 +01:00
|
|
|
Value *LHS = Op0;
|
|
|
|
Value *RHS = Op1;
|
|
|
|
if (!isa<Constant>(LHS)) std::swap(LHS, RHS);
|
|
|
|
|
2007-01-12 01:02:12 +01:00
|
|
|
if (ConstantInt *CI = dyn_cast<ConstantInt>(Canonical)) {
|
|
|
|
if (ConstantInt *Arg = dyn_cast<ConstantInt>(LHS)) {
|
2009-07-16 20:04:31 +02:00
|
|
|
add(RHS,
|
|
|
|
Context->getConstantInt(CI->getValue() ^ Arg->getValue()),
|
2007-01-12 01:02:12 +01:00
|
|
|
ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
|
|
|
if (Canonical == LHS) {
|
2007-01-11 13:24:14 +01:00
|
|
|
if (isa<ConstantInt>(Canonical))
|
2009-07-13 06:09:18 +02:00
|
|
|
add(RHS, Context->getNullValue(Ty), ICmpInst::ICMP_EQ,
|
2007-01-11 03:32:38 +01:00
|
|
|
NewContext);
|
|
|
|
} else if (isRelatedBy(LHS, Canonical, ICmpInst::ICMP_NE)) {
|
2009-07-13 06:09:18 +02:00
|
|
|
add(RHS, Context->getNullValue(Ty), ICmpInst::ICMP_NE,
|
2007-01-11 03:32:38 +01:00
|
|
|
NewContext);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (ICmpInst *IC = dyn_cast<ICmpInst>(I)) {
|
2007-03-10 19:12:48 +01:00
|
|
|
// "icmp ult i32 %a, %y" EQ true then %a u< y
|
2007-01-11 03:32:38 +01:00
|
|
|
// etc.
|
|
|
|
|
2007-01-11 13:24:14 +01:00
|
|
|
if (Canonical == ConstantInt::getTrue()) {
|
2007-01-11 03:32:38 +01:00
|
|
|
add(IC->getOperand(0), IC->getOperand(1), IC->getPredicate(),
|
|
|
|
NewContext);
|
2007-01-11 13:24:14 +01:00
|
|
|
} else if (Canonical == ConstantInt::getFalse()) {
|
2007-01-11 03:32:38 +01:00
|
|
|
add(IC->getOperand(0), IC->getOperand(1),
|
|
|
|
ICmpInst::getInversePredicate(IC->getPredicate()), NewContext);
|
|
|
|
}
|
|
|
|
} else if (SelectInst *SI = dyn_cast<SelectInst>(I)) {
|
|
|
|
if (I->getType()->isFPOrFPVector()) return;
|
|
|
|
|
2007-03-10 19:12:48 +01:00
|
|
|
// Given: "%a = select i1 %x, i32 %b, i32 %c"
|
2007-01-11 03:32:38 +01:00
|
|
|
// %a EQ %b and %b NE %c then %x EQ true
|
|
|
|
// %a EQ %c and %b NE %c then %x EQ false
|
|
|
|
|
|
|
|
Value *True = SI->getTrueValue();
|
|
|
|
Value *False = SI->getFalseValue();
|
|
|
|
if (isRelatedBy(True, False, ICmpInst::ICMP_NE)) {
|
2007-07-05 05:15:00 +02:00
|
|
|
if (Canonical == VN.canonicalize(True, Top) ||
|
2007-01-11 03:32:38 +01:00
|
|
|
isRelatedBy(Canonical, False, ICmpInst::ICMP_NE))
|
2007-01-11 13:24:14 +01:00
|
|
|
add(SI->getCondition(), ConstantInt::getTrue(),
|
2007-01-11 03:32:38 +01:00
|
|
|
ICmpInst::ICMP_EQ, NewContext);
|
2007-07-05 05:15:00 +02:00
|
|
|
else if (Canonical == VN.canonicalize(False, Top) ||
|
2007-03-10 19:12:48 +01:00
|
|
|
isRelatedBy(Canonical, True, ICmpInst::ICMP_NE))
|
2007-01-11 13:24:14 +01:00
|
|
|
add(SI->getCondition(), ConstantInt::getFalse(),
|
2007-01-11 03:32:38 +01:00
|
|
|
ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
}
|
2007-03-22 03:02:51 +01:00
|
|
|
} else if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(I)) {
|
|
|
|
for (GetElementPtrInst::op_iterator OI = GEPI->idx_begin(),
|
|
|
|
OE = GEPI->idx_end(); OI != OE; ++OI) {
|
2007-07-05 05:15:00 +02:00
|
|
|
ConstantInt *Op = dyn_cast<ConstantInt>(VN.canonicalize(*OI, Top));
|
2007-03-22 03:02:51 +01:00
|
|
|
if (!Op || !Op->isZero()) return;
|
|
|
|
}
|
|
|
|
// TODO: The GEPI indices are all zero. Copy from definition to operand,
|
|
|
|
// jumping the type plane as needed.
|
2009-07-13 06:09:18 +02:00
|
|
|
if (isRelatedBy(GEPI, Context->getNullValue(GEPI->getType()),
|
2007-03-22 03:02:51 +01:00
|
|
|
ICmpInst::ICMP_NE)) {
|
|
|
|
Value *Ptr = GEPI->getPointerOperand();
|
2009-07-13 06:09:18 +02:00
|
|
|
add(Ptr, Context->getNullValue(Ptr->getType()), ICmpInst::ICMP_NE,
|
2007-03-22 03:02:51 +01:00
|
|
|
NewContext);
|
|
|
|
}
|
2007-04-07 17:48:32 +02:00
|
|
|
} else if (CastInst *CI = dyn_cast<CastInst>(I)) {
|
|
|
|
const Type *SrcTy = CI->getSrcTy();
|
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
unsigned ci = VN.getOrInsertVN(CI, Top);
|
2007-04-07 17:48:32 +02:00
|
|
|
uint32_t W = VR.typeToWidth(SrcTy);
|
|
|
|
if (!W) return;
|
2007-07-10 05:28:21 +02:00
|
|
|
ConstantRange CR = VR.range(ci, Top);
|
2007-04-07 17:48:32 +02:00
|
|
|
|
|
|
|
if (CR.isFullSet()) return;
|
|
|
|
|
|
|
|
switch (CI->getOpcode()) {
|
|
|
|
default: break;
|
|
|
|
case Instruction::ZExt:
|
|
|
|
case Instruction::SExt:
|
2007-07-10 05:28:21 +02:00
|
|
|
VR.applyRange(VN.getOrInsertVN(CI->getOperand(0), Top),
|
2007-04-07 17:48:32 +02:00
|
|
|
CR.truncate(W), Top, this);
|
|
|
|
break;
|
|
|
|
case Instruction::BitCast:
|
2007-07-10 05:28:21 +02:00
|
|
|
VR.applyRange(VN.getOrInsertVN(CI->getOperand(0), Top),
|
2007-04-07 17:48:32 +02:00
|
|
|
CR, Top, this);
|
|
|
|
break;
|
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
}
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
/// opsToDef - A new relationship was discovered involving one of this
|
|
|
|
/// instruction's operands. Find any new relationship involving the
|
2007-03-22 03:02:51 +01:00
|
|
|
/// definition, or another operand.
|
2007-01-11 03:32:38 +01:00
|
|
|
void opsToDef(Instruction *I) {
|
|
|
|
Instruction *NewContext = below(I) ? I : TopInst;
|
|
|
|
|
|
|
|
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(I)) {
|
2007-07-05 05:15:00 +02:00
|
|
|
Value *Op0 = VN.canonicalize(BO->getOperand(0), Top);
|
|
|
|
Value *Op1 = VN.canonicalize(BO->getOperand(1), Top);
|
2007-01-11 03:32:38 +01:00
|
|
|
|
2007-01-11 13:24:14 +01:00
|
|
|
if (ConstantInt *CI0 = dyn_cast<ConstantInt>(Op0))
|
|
|
|
if (ConstantInt *CI1 = dyn_cast<ConstantInt>(Op1)) {
|
2007-01-11 03:32:38 +01:00
|
|
|
add(BO, ConstantExpr::get(BO->getOpcode(), CI0, CI1),
|
|
|
|
ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
}
|
2006-09-10 04:27:07 +02:00
|
|
|
|
2007-03-18 02:09:32 +01:00
|
|
|
// "%y = and i1 true, %x" then %x EQ %y
|
|
|
|
// "%y = or i1 false, %x" then %x EQ %y
|
|
|
|
// "%x = add i32 %y, 0" then %x EQ %y
|
|
|
|
// "%x = mul i32 %y, 0" then %x EQ 0
|
|
|
|
|
|
|
|
Instruction::BinaryOps Opcode = BO->getOpcode();
|
2007-03-18 23:58:46 +01:00
|
|
|
const Type *Ty = BO->getType();
|
|
|
|
assert(!Ty->isFPOrFPVector() && "Float in work queue!");
|
|
|
|
|
2009-07-13 06:09:18 +02:00
|
|
|
Constant *Zero = Context->getNullValue(Ty);
|
2009-07-15 01:09:55 +02:00
|
|
|
Constant *One = Context->getConstantInt(Ty, 1);
|
2009-07-13 22:58:05 +02:00
|
|
|
ConstantInt *AllOnes = cast<ConstantInt>(Context->getAllOnesValue(Ty));
|
2007-03-18 02:09:32 +01:00
|
|
|
|
|
|
|
switch (Opcode) {
|
|
|
|
default: break;
|
2007-03-22 03:02:51 +01:00
|
|
|
case Instruction::LShr:
|
|
|
|
case Instruction::AShr:
|
|
|
|
case Instruction::Shl:
|
2008-10-24 06:00:26 +02:00
|
|
|
if (Op1 == Zero) {
|
|
|
|
add(BO, Op0, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-18 02:09:32 +01:00
|
|
|
case Instruction::Sub:
|
2007-03-18 23:58:46 +01:00
|
|
|
if (Op1 == Zero) {
|
|
|
|
add(BO, Op0, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
}
|
2008-10-24 06:00:26 +02:00
|
|
|
if (ConstantInt *CI0 = dyn_cast<ConstantInt>(Op0)) {
|
|
|
|
unsigned n_ci0 = VN.getOrInsertVN(Op1, Top);
|
|
|
|
ConstantRange CR = VR.range(n_ci0, Top);
|
|
|
|
if (!CR.isFullSet()) {
|
|
|
|
CR.subtract(CI0->getValue());
|
|
|
|
unsigned n_bo = VN.getOrInsertVN(BO, Top);
|
|
|
|
VR.applyRange(n_bo, CR, Top, this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ConstantInt *CI1 = dyn_cast<ConstantInt>(Op1)) {
|
|
|
|
unsigned n_ci1 = VN.getOrInsertVN(Op0, Top);
|
|
|
|
ConstantRange CR = VR.range(n_ci1, Top);
|
|
|
|
if (!CR.isFullSet()) {
|
|
|
|
CR.subtract(CI1->getValue());
|
|
|
|
unsigned n_bo = VN.getOrInsertVN(BO, Top);
|
|
|
|
VR.applyRange(n_bo, CR, Top, this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-03-18 23:58:46 +01:00
|
|
|
break;
|
|
|
|
case Instruction::Or:
|
|
|
|
if (Op0 == AllOnes || Op1 == AllOnes) {
|
|
|
|
add(BO, AllOnes, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
2008-10-24 06:00:26 +02:00
|
|
|
}
|
|
|
|
if (Op0 == Zero) {
|
|
|
|
add(BO, Op1, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
} else if (Op1 == Zero) {
|
|
|
|
add(BO, Op0, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-18 02:09:32 +01:00
|
|
|
case Instruction::Add:
|
2008-10-24 06:00:26 +02:00
|
|
|
if (ConstantInt *CI0 = dyn_cast<ConstantInt>(Op0)) {
|
|
|
|
unsigned n_ci0 = VN.getOrInsertVN(Op1, Top);
|
|
|
|
ConstantRange CR = VR.range(n_ci0, Top);
|
|
|
|
if (!CR.isFullSet()) {
|
|
|
|
CR.subtract(-CI0->getValue());
|
|
|
|
unsigned n_bo = VN.getOrInsertVN(BO, Top);
|
|
|
|
VR.applyRange(n_bo, CR, Top, this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ConstantInt *CI1 = dyn_cast<ConstantInt>(Op1)) {
|
|
|
|
unsigned n_ci1 = VN.getOrInsertVN(Op0, Top);
|
|
|
|
ConstantRange CR = VR.range(n_ci1, Top);
|
|
|
|
if (!CR.isFullSet()) {
|
|
|
|
CR.subtract(-CI1->getValue());
|
|
|
|
unsigned n_bo = VN.getOrInsertVN(BO, Top);
|
|
|
|
VR.applyRange(n_bo, CR, Top, this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fall-through
|
|
|
|
case Instruction::Xor:
|
2007-03-18 02:09:32 +01:00
|
|
|
if (Op0 == Zero) {
|
|
|
|
add(BO, Op1, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
} else if (Op1 == Zero) {
|
|
|
|
add(BO, Op0, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-18 23:58:46 +01:00
|
|
|
break;
|
|
|
|
case Instruction::And:
|
2007-03-18 02:09:32 +01:00
|
|
|
if (Op0 == AllOnes) {
|
|
|
|
add(BO, Op1, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
} else if (Op1 == AllOnes) {
|
|
|
|
add(BO, Op0, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
}
|
2008-10-24 06:00:26 +02:00
|
|
|
if (Op0 == Zero || Op1 == Zero) {
|
|
|
|
add(BO, Zero, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-18 23:58:46 +01:00
|
|
|
case Instruction::Mul:
|
|
|
|
if (Op0 == Zero || Op1 == Zero) {
|
2007-03-18 02:09:32 +01:00
|
|
|
add(BO, Zero, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
}
|
2008-10-24 06:00:26 +02:00
|
|
|
if (Op0 == One) {
|
|
|
|
add(BO, Op1, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
} else if (Op1 == One) {
|
|
|
|
add(BO, Op0, ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-18 23:58:46 +01:00
|
|
|
break;
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2006-09-10 04:27:07 +02:00
|
|
|
|
2007-03-10 19:12:48 +01:00
|
|
|
// "%x = add i32 %y, %z" and %x EQ %y then %z EQ 0
|
2007-03-22 03:02:51 +01:00
|
|
|
// "%x = add i32 %y, %z" and %x EQ %z then %y EQ 0
|
|
|
|
// "%x = shl i32 %y, %z" and %x EQ %y and %y NE 0 then %z EQ 0
|
2008-10-24 06:00:26 +02:00
|
|
|
// "%x = udiv i32 %y, %z" and %x EQ %y and %y NE 0 then %z EQ 1
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-03-22 03:02:51 +01:00
|
|
|
Value *Known = Op0, *Unknown = Op1,
|
2007-07-05 05:15:00 +02:00
|
|
|
*TheBO = VN.canonicalize(BO, Top);
|
2007-03-22 03:02:51 +01:00
|
|
|
if (Known != TheBO) std::swap(Known, Unknown);
|
|
|
|
if (Known == TheBO) {
|
2007-03-16 03:37:39 +01:00
|
|
|
switch (Opcode) {
|
2007-01-11 03:32:38 +01:00
|
|
|
default: break;
|
2007-03-22 03:02:51 +01:00
|
|
|
case Instruction::LShr:
|
|
|
|
case Instruction::AShr:
|
|
|
|
case Instruction::Shl:
|
|
|
|
if (!isRelatedBy(Known, Zero, ICmpInst::ICMP_NE)) break;
|
|
|
|
// otherwise, fall-through.
|
|
|
|
case Instruction::Sub:
|
2007-09-20 02:48:36 +02:00
|
|
|
if (Unknown == Op0) break;
|
2007-03-22 03:02:51 +01:00
|
|
|
// otherwise, fall-through.
|
2007-01-11 03:32:38 +01:00
|
|
|
case Instruction::Xor:
|
|
|
|
case Instruction::Add:
|
2007-03-18 23:58:46 +01:00
|
|
|
add(Unknown, Zero, ICmpInst::ICMP_EQ, NewContext);
|
2007-01-11 03:32:38 +01:00
|
|
|
break;
|
|
|
|
case Instruction::UDiv:
|
|
|
|
case Instruction::SDiv:
|
2007-03-22 03:02:51 +01:00
|
|
|
if (Unknown == Op1) break;
|
2008-10-24 06:00:26 +02:00
|
|
|
if (isRelatedBy(Known, Zero, ICmpInst::ICMP_NE))
|
2007-01-12 01:02:12 +01:00
|
|
|
add(Unknown, One, ICmpInst::ICMP_EQ, NewContext);
|
2007-01-11 03:32:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-03-10 19:12:48 +01:00
|
|
|
// TODO: "%a = add i32 %b, 1" and %b > %z then %a >= %z.
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
} else if (ICmpInst *IC = dyn_cast<ICmpInst>(I)) {
|
2007-03-16 03:37:39 +01:00
|
|
|
// "%a = icmp ult i32 %b, %c" and %b u< %c then %a EQ true
|
2007-03-10 19:12:48 +01:00
|
|
|
// "%a = icmp ult i32 %b, %c" and %b u>= %c then %a EQ false
|
2007-01-11 03:32:38 +01:00
|
|
|
// etc.
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
Value *Op0 = VN.canonicalize(IC->getOperand(0), Top);
|
|
|
|
Value *Op1 = VN.canonicalize(IC->getOperand(1), Top);
|
2007-01-11 03:32:38 +01:00
|
|
|
|
|
|
|
ICmpInst::Predicate Pred = IC->getPredicate();
|
2007-07-10 05:28:21 +02:00
|
|
|
if (isRelatedBy(Op0, Op1, Pred))
|
2007-01-11 13:24:14 +01:00
|
|
|
add(IC, ConstantInt::getTrue(), ICmpInst::ICMP_EQ, NewContext);
|
2007-07-10 05:28:21 +02:00
|
|
|
else if (isRelatedBy(Op0, Op1, ICmpInst::getInversePredicate(Pred)))
|
2007-01-11 13:24:14 +01:00
|
|
|
add(IC, ConstantInt::getFalse(), ICmpInst::ICMP_EQ, NewContext);
|
2007-01-11 03:32:38 +01:00
|
|
|
|
|
|
|
} else if (SelectInst *SI = dyn_cast<SelectInst>(I)) {
|
2007-03-22 03:02:51 +01:00
|
|
|
if (I->getType()->isFPOrFPVector()) return;
|
|
|
|
|
2007-03-16 03:37:39 +01:00
|
|
|
// Given: "%a = select i1 %x, i32 %b, i32 %c"
|
2007-01-11 03:32:38 +01:00
|
|
|
// %x EQ true then %a EQ %b
|
|
|
|
// %x EQ false then %a EQ %c
|
|
|
|
// %b EQ %c then %a EQ %b
|
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
Value *Canonical = VN.canonicalize(SI->getCondition(), Top);
|
2007-01-11 13:24:14 +01:00
|
|
|
if (Canonical == ConstantInt::getTrue()) {
|
2007-01-11 03:32:38 +01:00
|
|
|
add(SI, SI->getTrueValue(), ICmpInst::ICMP_EQ, NewContext);
|
2007-01-11 13:24:14 +01:00
|
|
|
} else if (Canonical == ConstantInt::getFalse()) {
|
2007-01-11 03:32:38 +01:00
|
|
|
add(SI, SI->getFalseValue(), ICmpInst::ICMP_EQ, NewContext);
|
2007-07-05 05:15:00 +02:00
|
|
|
} else if (VN.canonicalize(SI->getTrueValue(), Top) ==
|
|
|
|
VN.canonicalize(SI->getFalseValue(), Top)) {
|
2007-01-11 03:32:38 +01:00
|
|
|
add(SI, SI->getTrueValue(), ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
}
|
2007-01-12 02:23:53 +01:00
|
|
|
} else if (CastInst *CI = dyn_cast<CastInst>(I)) {
|
2007-04-07 17:48:32 +02:00
|
|
|
const Type *DestTy = CI->getDestTy();
|
|
|
|
if (DestTy->isFPOrFPVector()) return;
|
2007-01-12 02:23:53 +01:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
Value *Op = VN.canonicalize(CI->getOperand(0), Top);
|
2007-04-07 17:48:32 +02:00
|
|
|
Instruction::CastOps Opcode = CI->getOpcode();
|
|
|
|
|
|
|
|
if (Constant *C = dyn_cast<Constant>(Op)) {
|
|
|
|
add(CI, ConstantExpr::getCast(Opcode, C, DestTy),
|
2007-01-12 02:23:53 +01:00
|
|
|
ICmpInst::ICMP_EQ, NewContext);
|
|
|
|
}
|
|
|
|
|
2007-04-07 17:48:32 +02:00
|
|
|
uint32_t W = VR.typeToWidth(DestTy);
|
2007-07-10 05:28:21 +02:00
|
|
|
unsigned ci = VN.getOrInsertVN(CI, Top);
|
|
|
|
ConstantRange CR = VR.range(VN.getOrInsertVN(Op, Top), Top);
|
2007-04-07 17:48:32 +02:00
|
|
|
|
|
|
|
if (!CR.isFullSet()) {
|
|
|
|
switch (Opcode) {
|
|
|
|
default: break;
|
|
|
|
case Instruction::ZExt:
|
2007-07-10 05:28:21 +02:00
|
|
|
VR.applyRange(ci, CR.zeroExtend(W), Top, this);
|
2007-04-07 17:48:32 +02:00
|
|
|
break;
|
|
|
|
case Instruction::SExt:
|
2007-07-10 05:28:21 +02:00
|
|
|
VR.applyRange(ci, CR.signExtend(W), Top, this);
|
2007-04-07 17:48:32 +02:00
|
|
|
break;
|
|
|
|
case Instruction::Trunc: {
|
|
|
|
ConstantRange Result = CR.truncate(W);
|
|
|
|
if (!Result.isFullSet())
|
2007-07-10 05:28:21 +02:00
|
|
|
VR.applyRange(ci, Result, Top, this);
|
2007-04-07 17:48:32 +02:00
|
|
|
} break;
|
|
|
|
case Instruction::BitCast:
|
2007-07-10 05:28:21 +02:00
|
|
|
VR.applyRange(ci, CR, Top, this);
|
2007-04-07 17:48:32 +02:00
|
|
|
break;
|
|
|
|
// TODO: other casts?
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 03:02:51 +01:00
|
|
|
} else if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(I)) {
|
|
|
|
for (GetElementPtrInst::op_iterator OI = GEPI->idx_begin(),
|
|
|
|
OE = GEPI->idx_end(); OI != OE; ++OI) {
|
2007-07-05 05:15:00 +02:00
|
|
|
ConstantInt *Op = dyn_cast<ConstantInt>(VN.canonicalize(*OI, Top));
|
2007-03-22 03:02:51 +01:00
|
|
|
if (!Op || !Op->isZero()) return;
|
|
|
|
}
|
|
|
|
// TODO: The GEPI indices are all zero. Copy from operand to definition,
|
|
|
|
// jumping the type plane as needed.
|
|
|
|
Value *Ptr = GEPI->getPointerOperand();
|
2009-07-13 06:09:18 +02:00
|
|
|
if (isRelatedBy(Ptr, Context->getNullValue(Ptr->getType()),
|
2007-03-22 03:02:51 +01:00
|
|
|
ICmpInst::ICMP_NE)) {
|
2009-07-13 06:09:18 +02:00
|
|
|
add(GEPI, Context->getNullValue(GEPI->getType()), ICmpInst::ICMP_NE,
|
2007-03-22 03:02:51 +01:00
|
|
|
NewContext);
|
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2006-10-26 01:48:24 +02:00
|
|
|
}
|
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
/// solve - process the work queue
|
2006-11-23 00:49:16 +01:00
|
|
|
void solve() {
|
2007-01-11 03:32:38 +01:00
|
|
|
//DOUT << "WorkList entry, size: " << WorkList.size() << "\n";
|
2006-11-23 00:49:16 +01:00
|
|
|
while (!WorkList.empty()) {
|
2007-01-11 03:32:38 +01:00
|
|
|
//DOUT << "WorkList size: " << WorkList.size() << "\n";
|
2006-10-26 01:48:24 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
Operation &O = WorkList.front();
|
2007-01-13 03:05:28 +01:00
|
|
|
TopInst = O.ContextInst;
|
|
|
|
TopBB = O.ContextBB;
|
2007-06-24 06:36:20 +02:00
|
|
|
Top = DTDFS->getNodeForBlock(TopBB); // XXX move this into Context
|
2007-01-13 03:05:28 +01:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
O.LHS = VN.canonicalize(O.LHS, Top);
|
|
|
|
O.RHS = VN.canonicalize(O.RHS, Top);
|
2006-10-26 01:48:24 +02:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
assert(O.LHS == VN.canonicalize(O.LHS, Top) && "Canonicalize isn't.");
|
|
|
|
assert(O.RHS == VN.canonicalize(O.RHS, Top) && "Canonicalize isn't.");
|
2006-10-26 01:48:24 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
DOUT << "solving " << *O.LHS << " " << O.Op << " " << *O.RHS;
|
2007-01-13 03:05:28 +01:00
|
|
|
if (O.ContextInst) DOUT << " context inst: " << *O.ContextInst;
|
|
|
|
else DOUT << " context block: " << O.ContextBB->getName();
|
2007-01-11 03:32:38 +01:00
|
|
|
DOUT << "\n";
|
2006-10-26 01:48:24 +02:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
DEBUG(VN.dump());
|
2007-01-11 03:32:38 +01:00
|
|
|
DEBUG(IG.dump());
|
2007-07-10 05:28:21 +02:00
|
|
|
DEBUG(VR.dump());
|
2006-10-26 01:48:24 +02:00
|
|
|
|
2007-02-05 00:43:05 +01:00
|
|
|
// If they're both Constant, skip it. Check for contradiction and mark
|
|
|
|
// the BB as unreachable if so.
|
|
|
|
if (Constant *CI_L = dyn_cast<Constant>(O.LHS)) {
|
|
|
|
if (Constant *CI_R = dyn_cast<Constant>(O.RHS)) {
|
|
|
|
if (ConstantExpr::getCompare(O.Op, CI_L, CI_R) ==
|
|
|
|
ConstantInt::getFalse())
|
|
|
|
UB.mark(TopBB);
|
|
|
|
|
|
|
|
WorkList.pop_front();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
if (VN.compare(O.LHS, O.RHS)) {
|
2007-02-05 00:43:05 +01:00
|
|
|
std::swap(O.LHS, O.RHS);
|
|
|
|
O.Op = ICmpInst::getSwappedPredicate(O.Op);
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
2006-10-26 01:48:24 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
if (O.Op == ICmpInst::ICMP_EQ) {
|
2007-03-10 19:12:48 +01:00
|
|
|
if (!makeEqual(O.RHS, O.LHS))
|
2007-01-11 03:32:38 +01:00
|
|
|
UB.mark(TopBB);
|
|
|
|
} else {
|
|
|
|
LatticeVal LV = cmpInstToLattice(O.Op);
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
if ((LV & EQ_BIT) &&
|
|
|
|
isRelatedBy(O.LHS, O.RHS, ICmpInst::getSwappedPredicate(O.Op))) {
|
2007-03-10 19:12:48 +01:00
|
|
|
if (!makeEqual(O.RHS, O.LHS))
|
2007-01-11 03:32:38 +01:00
|
|
|
UB.mark(TopBB);
|
|
|
|
} else {
|
|
|
|
if (isRelatedBy(O.LHS, O.RHS, ICmpInst::getInversePredicate(O.Op))){
|
2007-02-05 00:43:05 +01:00
|
|
|
UB.mark(TopBB);
|
2007-01-11 03:32:38 +01:00
|
|
|
WorkList.pop_front();
|
|
|
|
continue;
|
2006-10-26 01:48:24 +02:00
|
|
|
}
|
2006-12-23 07:05:41 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
unsigned n1 = VN.getOrInsertVN(O.LHS, Top);
|
|
|
|
unsigned n2 = VN.getOrInsertVN(O.RHS, Top);
|
2006-12-23 07:05:41 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
if (n1 == n2) {
|
2007-01-11 03:32:38 +01:00
|
|
|
if (O.Op != ICmpInst::ICMP_UGE && O.Op != ICmpInst::ICMP_ULE &&
|
|
|
|
O.Op != ICmpInst::ICMP_SGE && O.Op != ICmpInst::ICMP_SLE)
|
|
|
|
UB.mark(TopBB);
|
2006-12-23 07:05:41 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
WorkList.pop_front();
|
|
|
|
continue;
|
|
|
|
}
|
2006-12-23 07:05:41 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
if (VR.isRelatedBy(n1, n2, Top, LV) ||
|
|
|
|
IG.isRelatedBy(n1, n2, Top, LV)) {
|
2007-01-11 03:32:38 +01:00
|
|
|
WorkList.pop_front();
|
|
|
|
continue;
|
|
|
|
}
|
2006-12-23 07:05:41 +01:00
|
|
|
|
2007-07-10 05:28:21 +02:00
|
|
|
VR.addInequality(n1, n2, Top, LV, this);
|
2007-03-10 19:12:48 +01:00
|
|
|
if ((!isa<ConstantInt>(O.RHS) && !isa<ConstantInt>(O.LHS)) ||
|
2007-07-10 05:28:21 +02:00
|
|
|
LV == NE)
|
2007-03-10 19:12:48 +01:00
|
|
|
IG.addInequality(n1, n2, Top, LV);
|
2007-02-05 00:43:05 +01:00
|
|
|
|
2007-01-15 15:30:07 +01:00
|
|
|
if (Instruction *I1 = dyn_cast<Instruction>(O.LHS)) {
|
2007-06-24 06:36:20 +02:00
|
|
|
if (aboveOrBelow(I1))
|
2007-01-15 15:30:07 +01:00
|
|
|
defToOps(I1);
|
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
if (isa<Instruction>(O.LHS) || isa<Argument>(O.LHS)) {
|
|
|
|
for (Value::use_iterator UI = O.LHS->use_begin(),
|
|
|
|
UE = O.LHS->use_end(); UI != UE;) {
|
|
|
|
Use &TheUse = UI.getUse();
|
|
|
|
++UI;
|
2009-06-06 19:49:35 +02:00
|
|
|
Instruction *I = cast<Instruction>(TheUse.getUser());
|
|
|
|
if (aboveOrBelow(I))
|
|
|
|
opsToDef(I);
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
|
|
|
}
|
2007-01-15 15:30:07 +01:00
|
|
|
if (Instruction *I2 = dyn_cast<Instruction>(O.RHS)) {
|
2007-06-24 06:36:20 +02:00
|
|
|
if (aboveOrBelow(I2))
|
2007-01-15 15:30:07 +01:00
|
|
|
defToOps(I2);
|
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
if (isa<Instruction>(O.RHS) || isa<Argument>(O.RHS)) {
|
|
|
|
for (Value::use_iterator UI = O.RHS->use_begin(),
|
|
|
|
UE = O.RHS->use_end(); UI != UE;) {
|
|
|
|
Use &TheUse = UI.getUse();
|
|
|
|
++UI;
|
2009-06-06 19:49:35 +02:00
|
|
|
Instruction *I = cast<Instruction>(TheUse.getUser());
|
|
|
|
if (aboveOrBelow(I))
|
|
|
|
opsToDef(I);
|
2007-01-11 03:32:38 +01:00
|
|
|
}
|
|
|
|
}
|
2006-12-23 07:05:41 +01:00
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
WorkList.pop_front();
|
2006-08-29 00:44:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-04-07 05:36:51 +02:00
|
|
|
void ValueRanges::addToWorklist(Value *V, Constant *C,
|
2007-03-10 19:12:48 +01:00
|
|
|
ICmpInst::Predicate Pred, VRPSolver *VRP) {
|
2007-04-07 05:36:51 +02:00
|
|
|
VRP->add(V, C, Pred, VRP->TopInst);
|
2007-03-10 19:12:48 +01:00
|
|
|
}
|
|
|
|
|
2007-04-07 17:48:32 +02:00
|
|
|
void ValueRanges::markBlock(VRPSolver *VRP) {
|
|
|
|
VRP->UB.mark(VRP->TopBB);
|
|
|
|
}
|
|
|
|
|
2006-08-29 00:44:55 +02:00
|
|
|
/// PredicateSimplifier - This class is a simplifier that replaces
|
|
|
|
/// one equivalent variable with another. It also tracks what
|
|
|
|
/// can't be equal and will solve setcc instructions when possible.
|
2006-11-23 00:49:16 +01:00
|
|
|
/// @brief Root of the predicate simplifier optimization.
|
|
|
|
class VISIBILITY_HIDDEN PredicateSimplifier : public FunctionPass {
|
2007-06-24 06:36:20 +02:00
|
|
|
DomTreeDFS *DTDFS;
|
2006-11-23 00:49:16 +01:00
|
|
|
bool modified;
|
2007-07-05 05:15:00 +02:00
|
|
|
ValueNumbering *VN;
|
2007-01-11 03:32:38 +01:00
|
|
|
InequalityGraph *IG;
|
|
|
|
UnreachableBlocks UB;
|
2007-03-10 19:12:48 +01:00
|
|
|
ValueRanges *VR;
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-06-24 06:36:20 +02:00
|
|
|
std::vector<DomTreeDFS::Node *> WorkList;
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2006-08-29 00:44:55 +02:00
|
|
|
public:
|
2007-05-06 15:37:16 +02:00
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2008-09-04 19:05:41 +02:00
|
|
|
PredicateSimplifier() : FunctionPass(&ID) {}
|
2007-05-01 23:15:47 +02:00
|
|
|
|
2006-08-29 00:44:55 +02:00
|
|
|
bool runOnFunction(Function &F);
|
2006-11-23 00:49:16 +01:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.addRequiredID(BreakCriticalEdgesID);
|
2007-04-25 06:18:54 +02:00
|
|
|
AU.addRequired<DominatorTree>();
|
2007-04-07 05:16:12 +02:00
|
|
|
AU.addRequired<TargetData>();
|
|
|
|
AU.addPreserved<TargetData>();
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
|
|
|
private:
|
2007-07-16 04:58:37 +02:00
|
|
|
/// Forwards - Adds new properties to VRPSolver and uses them to
|
2006-10-12 04:02:44 +02:00
|
|
|
/// simplify instructions. Because new properties sometimes apply to
|
|
|
|
/// a transition from one BasicBlock to another, this will use the
|
|
|
|
/// PredicateSimplifier::proceedToSuccessor(s) interface to enter the
|
2007-07-16 04:58:37 +02:00
|
|
|
/// basic block.
|
2006-11-23 00:49:16 +01:00
|
|
|
/// @brief Performs abstract execution of the program.
|
|
|
|
class VISIBILITY_HIDDEN Forwards : public InstVisitor<Forwards> {
|
2006-10-12 04:02:44 +02:00
|
|
|
friend class InstVisitor<Forwards>;
|
|
|
|
PredicateSimplifier *PS;
|
2007-06-24 06:36:20 +02:00
|
|
|
DomTreeDFS::Node *DTNode;
|
2006-10-12 04:02:44 +02:00
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
public:
|
2007-07-05 05:15:00 +02:00
|
|
|
ValueNumbering &VN;
|
2006-11-23 00:49:16 +01:00
|
|
|
InequalityGraph &IG;
|
2007-01-11 03:32:38 +01:00
|
|
|
UnreachableBlocks &UB;
|
2007-03-10 19:12:48 +01:00
|
|
|
ValueRanges &VR;
|
2006-10-12 04:02:44 +02:00
|
|
|
|
2007-06-24 06:36:20 +02:00
|
|
|
Forwards(PredicateSimplifier *PS, DomTreeDFS::Node *DTNode)
|
2007-07-05 05:15:00 +02:00
|
|
|
: PS(PS), DTNode(DTNode), VN(*PS->VN), IG(*PS->IG), UB(PS->UB),
|
|
|
|
VR(*PS->VR) {}
|
2006-10-12 04:02:44 +02:00
|
|
|
|
|
|
|
void visitTerminatorInst(TerminatorInst &TI);
|
|
|
|
void visitBranchInst(BranchInst &BI);
|
|
|
|
void visitSwitchInst(SwitchInst &SI);
|
|
|
|
|
2006-10-22 21:53:27 +02:00
|
|
|
void visitAllocaInst(AllocaInst &AI);
|
2006-10-12 04:02:44 +02:00
|
|
|
void visitLoadInst(LoadInst &LI);
|
|
|
|
void visitStoreInst(StoreInst &SI);
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-02-05 00:43:05 +01:00
|
|
|
void visitSExtInst(SExtInst &SI);
|
|
|
|
void visitZExtInst(ZExtInst &ZI);
|
|
|
|
|
2006-10-12 04:02:44 +02:00
|
|
|
void visitBinaryOperator(BinaryOperator &BO);
|
2007-03-16 03:37:39 +01:00
|
|
|
void visitICmpInst(ICmpInst &IC);
|
2006-10-12 04:02:44 +02:00
|
|
|
};
|
2007-03-10 19:12:48 +01:00
|
|
|
|
2006-08-29 00:44:55 +02:00
|
|
|
// Used by terminator instructions to proceed from the current basic
|
|
|
|
// block to the next. Verifies that "current" dominates "next",
|
|
|
|
// then calls visitBasicBlock.
|
2007-06-24 06:36:20 +02:00
|
|
|
void proceedToSuccessors(DomTreeDFS::Node *Current) {
|
|
|
|
for (DomTreeDFS::Node::iterator I = Current->begin(),
|
2007-04-25 06:18:54 +02:00
|
|
|
E = Current->end(); I != E; ++I) {
|
2007-01-11 03:32:38 +01:00
|
|
|
WorkList.push_back(*I);
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2006-09-20 19:04:01 +02:00
|
|
|
}
|
|
|
|
|
2007-06-24 06:36:20 +02:00
|
|
|
void proceedToSuccessor(DomTreeDFS::Node *Next) {
|
2007-01-11 03:32:38 +01:00
|
|
|
WorkList.push_back(Next);
|
2006-09-20 19:04:01 +02:00
|
|
|
}
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
// Visits each instruction in the basic block.
|
2007-06-24 06:36:20 +02:00
|
|
|
void visitBasicBlock(DomTreeDFS::Node *Node) {
|
2007-04-25 06:18:54 +02:00
|
|
|
BasicBlock *BB = Node->getBlock();
|
2007-01-15 15:30:07 +01:00
|
|
|
DOUT << "Entering Basic Block: " << BB->getName()
|
2007-06-24 06:36:20 +02:00
|
|
|
<< " (" << Node->getDFSNumIn() << ")\n";
|
2006-12-07 21:04:42 +01:00
|
|
|
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
|
2007-06-24 06:36:20 +02:00
|
|
|
visitInstruction(I++, Node);
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2006-09-20 19:04:01 +02:00
|
|
|
}
|
|
|
|
|
2007-07-16 04:58:37 +02:00
|
|
|
// Tries to simplify each Instruction and add new properties.
|
2007-06-24 06:36:20 +02:00
|
|
|
void visitInstruction(Instruction *I, DomTreeDFS::Node *DT) {
|
2006-12-07 21:04:42 +01:00
|
|
|
DOUT << "Considering instruction " << *I << "\n";
|
2007-07-10 05:28:21 +02:00
|
|
|
DEBUG(VN->dump());
|
2007-01-11 03:32:38 +01:00
|
|
|
DEBUG(IG->dump());
|
2007-07-10 05:28:21 +02:00
|
|
|
DEBUG(VR->dump());
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
// Sometimes instructions are killed in earlier analysis.
|
2006-11-23 00:49:16 +01:00
|
|
|
if (isInstructionTriviallyDead(I)) {
|
2007-01-11 03:32:38 +01:00
|
|
|
++NumSimple;
|
|
|
|
modified = true;
|
2007-07-05 05:15:00 +02:00
|
|
|
if (unsigned n = VN->valueNumber(I, DTDFS->getRootNode()))
|
|
|
|
if (VN->value(n) == I) IG->remove(n);
|
|
|
|
VN->remove(I);
|
2006-11-23 00:49:16 +01:00
|
|
|
I->eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
2006-09-20 19:04:01 +02:00
|
|
|
|
2007-01-13 03:05:28 +01:00
|
|
|
#ifndef NDEBUG
|
2006-11-23 00:49:16 +01:00
|
|
|
// Try to replace the whole instruction.
|
2007-07-05 05:15:00 +02:00
|
|
|
Value *V = VN->canonicalize(I, DT);
|
2007-01-11 03:32:38 +01:00
|
|
|
assert(V == I && "Late instruction canonicalization.");
|
2006-11-23 00:49:16 +01:00
|
|
|
if (V != I) {
|
|
|
|
modified = true;
|
|
|
|
++NumInstruction;
|
2006-12-07 21:04:42 +01:00
|
|
|
DOUT << "Removing " << *I << ", replacing with " << *V << "\n";
|
2007-07-05 05:15:00 +02:00
|
|
|
if (unsigned n = VN->valueNumber(I, DTDFS->getRootNode()))
|
|
|
|
if (VN->value(n) == I) IG->remove(n);
|
|
|
|
VN->remove(I);
|
2006-11-23 00:49:16 +01:00
|
|
|
I->replaceAllUsesWith(V);
|
|
|
|
I->eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
2006-09-20 19:04:01 +02:00
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
// Try to substitute operands.
|
|
|
|
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
|
|
|
|
Value *Oper = I->getOperand(i);
|
2007-07-05 05:15:00 +02:00
|
|
|
Value *V = VN->canonicalize(Oper, DT);
|
2007-01-11 03:32:38 +01:00
|
|
|
assert(V == Oper && "Late operand canonicalization.");
|
2006-11-23 00:49:16 +01:00
|
|
|
if (V != Oper) {
|
|
|
|
modified = true;
|
|
|
|
++NumVarsReplaced;
|
2006-12-07 21:04:42 +01:00
|
|
|
DOUT << "Resolving " << *I;
|
2006-11-23 00:49:16 +01:00
|
|
|
I->setOperand(i, V);
|
2006-12-07 21:04:42 +01:00
|
|
|
DOUT << " into " << *I;
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
|
|
|
}
|
2007-01-13 03:05:28 +01:00
|
|
|
#endif
|
2006-09-20 19:04:01 +02:00
|
|
|
|
2007-03-16 03:37:39 +01:00
|
|
|
std::string name = I->getParent()->getName();
|
|
|
|
DOUT << "push (%" << name << ")\n";
|
2007-04-25 06:18:54 +02:00
|
|
|
Forwards visit(this, DT);
|
2006-11-23 00:49:16 +01:00
|
|
|
visit.visit(*I);
|
2007-03-16 03:37:39 +01:00
|
|
|
DOUT << "pop (%" << name << ")\n";
|
2006-09-20 19:04:01 +02:00
|
|
|
}
|
2006-11-23 00:49:16 +01:00
|
|
|
};
|
2006-09-20 19:04:01 +02:00
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
bool PredicateSimplifier::runOnFunction(Function &F) {
|
2007-06-24 06:36:20 +02:00
|
|
|
DominatorTree *DT = &getAnalysis<DominatorTree>();
|
|
|
|
DTDFS = new DomTreeDFS(DT);
|
2007-04-07 05:16:12 +02:00
|
|
|
TargetData *TD = &getAnalysis<TargetData>();
|
|
|
|
|
2006-12-07 21:04:42 +01:00
|
|
|
DOUT << "Entering Function: " << F.getName() << "\n";
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
modified = false;
|
2007-06-24 06:36:20 +02:00
|
|
|
DomTreeDFS::Node *Root = DTDFS->getRootNode();
|
2007-07-05 05:15:00 +02:00
|
|
|
VN = new ValueNumbering(DTDFS);
|
|
|
|
IG = new InequalityGraph(*VN, Root);
|
2009-07-16 20:04:31 +02:00
|
|
|
VR = new ValueRanges(*VN, TD, Context);
|
2007-06-24 06:36:20 +02:00
|
|
|
WorkList.push_back(Root);
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
do {
|
2007-06-24 06:36:20 +02:00
|
|
|
DomTreeDFS::Node *DTNode = WorkList.back();
|
2006-11-23 00:49:16 +01:00
|
|
|
WorkList.pop_back();
|
2007-04-25 06:18:54 +02:00
|
|
|
if (!UB.isDead(DTNode->getBlock())) visitBasicBlock(DTNode);
|
2006-11-23 00:49:16 +01:00
|
|
|
} while (!WorkList.empty());
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-06-24 06:36:20 +02:00
|
|
|
delete DTDFS;
|
2007-03-10 19:12:48 +01:00
|
|
|
delete VR;
|
2007-01-11 03:32:38 +01:00
|
|
|
delete IG;
|
2008-11-09 13:45:23 +01:00
|
|
|
delete VN;
|
2007-01-11 03:32:38 +01:00
|
|
|
|
|
|
|
modified |= UB.kill();
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
return modified;
|
2006-09-02 21:40:38 +02:00
|
|
|
}
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
void PredicateSimplifier::Forwards::visitTerminatorInst(TerminatorInst &TI) {
|
2007-04-25 06:18:54 +02:00
|
|
|
PS->proceedToSuccessors(DTNode);
|
2006-08-29 00:44:55 +02:00
|
|
|
}
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
void PredicateSimplifier::Forwards::visitBranchInst(BranchInst &BI) {
|
|
|
|
if (BI.isUnconditional()) {
|
2007-04-25 06:18:54 +02:00
|
|
|
PS->proceedToSuccessors(DTNode);
|
2006-11-23 00:49:16 +01:00
|
|
|
return;
|
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
Value *Condition = BI.getCondition();
|
2007-01-11 03:32:38 +01:00
|
|
|
BasicBlock *TrueDest = BI.getSuccessor(0);
|
|
|
|
BasicBlock *FalseDest = BI.getSuccessor(1);
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
if (isa<Constant>(Condition) || TrueDest == FalseDest) {
|
2007-04-25 06:18:54 +02:00
|
|
|
PS->proceedToSuccessors(DTNode);
|
2006-11-23 00:49:16 +01:00
|
|
|
return;
|
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-06-24 06:36:20 +02:00
|
|
|
for (DomTreeDFS::Node::iterator I = DTNode->begin(), E = DTNode->end();
|
2007-04-25 06:18:54 +02:00
|
|
|
I != E; ++I) {
|
|
|
|
BasicBlock *Dest = (*I)->getBlock();
|
2007-01-11 03:32:38 +01:00
|
|
|
DOUT << "Branch thinking about %" << Dest->getName()
|
2007-06-24 06:36:20 +02:00
|
|
|
<< "(" << PS->DTDFS->getNodeForBlock(Dest)->getDFSNumIn() << ")\n";
|
2006-11-23 00:49:16 +01:00
|
|
|
|
|
|
|
if (Dest == TrueDest) {
|
2007-04-25 06:18:54 +02:00
|
|
|
DOUT << "(" << DTNode->getBlock()->getName() << ") true set:\n";
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, Dest);
|
2007-01-11 13:24:14 +01:00
|
|
|
VRP.add(ConstantInt::getTrue(), Condition, ICmpInst::ICMP_EQ);
|
2007-01-11 03:32:38 +01:00
|
|
|
VRP.solve();
|
2007-07-10 05:28:21 +02:00
|
|
|
DEBUG(VN.dump());
|
2007-01-11 03:32:38 +01:00
|
|
|
DEBUG(IG.dump());
|
2007-07-10 05:28:21 +02:00
|
|
|
DEBUG(VR.dump());
|
2006-11-23 00:49:16 +01:00
|
|
|
} else if (Dest == FalseDest) {
|
2007-04-25 06:18:54 +02:00
|
|
|
DOUT << "(" << DTNode->getBlock()->getName() << ") false set:\n";
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, Dest);
|
2007-01-11 13:24:14 +01:00
|
|
|
VRP.add(ConstantInt::getFalse(), Condition, ICmpInst::ICMP_EQ);
|
2007-01-11 03:32:38 +01:00
|
|
|
VRP.solve();
|
2007-07-10 05:28:21 +02:00
|
|
|
DEBUG(VN.dump());
|
2007-01-11 03:32:38 +01:00
|
|
|
DEBUG(IG.dump());
|
2007-07-10 05:28:21 +02:00
|
|
|
DEBUG(VR.dump());
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2006-09-18 23:09:35 +02:00
|
|
|
|
2007-01-11 03:32:38 +01:00
|
|
|
PS->proceedToSuccessor(*I);
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
}
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
void PredicateSimplifier::Forwards::visitSwitchInst(SwitchInst &SI) {
|
|
|
|
Value *Condition = SI.getCondition();
|
|
|
|
|
|
|
|
// Set the EQProperty in each of the cases BBs, and the NEProperties
|
|
|
|
// in the default BB.
|
2007-04-25 06:18:54 +02:00
|
|
|
|
2007-06-24 06:36:20 +02:00
|
|
|
for (DomTreeDFS::Node::iterator I = DTNode->begin(), E = DTNode->end();
|
2007-04-25 06:18:54 +02:00
|
|
|
I != E; ++I) {
|
|
|
|
BasicBlock *BB = (*I)->getBlock();
|
2007-01-11 03:32:38 +01:00
|
|
|
DOUT << "Switch thinking about BB %" << BB->getName()
|
2007-06-24 06:36:20 +02:00
|
|
|
<< "(" << PS->DTDFS->getNodeForBlock(BB)->getDFSNumIn() << ")\n";
|
2006-11-23 00:49:16 +01:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, BB);
|
2006-11-23 00:49:16 +01:00
|
|
|
if (BB == SI.getDefaultDest()) {
|
|
|
|
for (unsigned i = 1, e = SI.getNumCases(); i < e; ++i)
|
|
|
|
if (SI.getSuccessor(i) != BB)
|
2007-01-11 03:32:38 +01:00
|
|
|
VRP.add(Condition, SI.getCaseValue(i), ICmpInst::ICMP_NE);
|
|
|
|
VRP.solve();
|
2006-11-23 00:49:16 +01:00
|
|
|
} else if (ConstantInt *CI = SI.findCaseDest(BB)) {
|
2007-01-11 03:32:38 +01:00
|
|
|
VRP.add(Condition, CI, ICmpInst::ICMP_EQ);
|
|
|
|
VRP.solve();
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2007-01-11 03:32:38 +01:00
|
|
|
PS->proceedToSuccessor(*I);
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
2006-08-30 04:46:48 +02:00
|
|
|
}
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
void PredicateSimplifier::Forwards::visitAllocaInst(AllocaInst &AI) {
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &AI);
|
2009-07-13 06:09:18 +02:00
|
|
|
VRP.add(AI.getParent()->getContext()->getNullValue(AI.getType()),
|
|
|
|
&AI, ICmpInst::ICMP_NE);
|
2006-11-23 00:49:16 +01:00
|
|
|
VRP.solve();
|
2006-08-29 00:44:55 +02:00
|
|
|
}
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
void PredicateSimplifier::Forwards::visitLoadInst(LoadInst &LI) {
|
|
|
|
Value *Ptr = LI.getPointerOperand();
|
2008-10-24 06:00:26 +02:00
|
|
|
// avoid "load i8* null" -> null NE null.
|
2006-11-23 00:49:16 +01:00
|
|
|
if (isa<Constant>(Ptr)) return;
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &LI);
|
2009-07-13 06:09:18 +02:00
|
|
|
VRP.add(LI.getParent()->getContext()->getNullValue(Ptr->getType()),
|
|
|
|
Ptr, ICmpInst::ICMP_NE);
|
2006-11-23 00:49:16 +01:00
|
|
|
VRP.solve();
|
2006-08-29 00:44:55 +02:00
|
|
|
}
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
void PredicateSimplifier::Forwards::visitStoreInst(StoreInst &SI) {
|
|
|
|
Value *Ptr = SI.getPointerOperand();
|
|
|
|
if (isa<Constant>(Ptr)) return;
|
2006-10-22 21:53:27 +02:00
|
|
|
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &SI);
|
2009-07-13 06:09:18 +02:00
|
|
|
VRP.add(SI.getParent()->getContext()->getNullValue(Ptr->getType()),
|
|
|
|
Ptr, ICmpInst::ICMP_NE);
|
2006-11-23 00:49:16 +01:00
|
|
|
VRP.solve();
|
|
|
|
}
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2007-02-05 00:43:05 +01:00
|
|
|
void PredicateSimplifier::Forwards::visitSExtInst(SExtInst &SI) {
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &SI);
|
2009-07-16 20:04:31 +02:00
|
|
|
LLVMContext *Context = SI.getParent()->getContext();
|
2007-03-03 01:48:31 +01:00
|
|
|
uint32_t SrcBitWidth = cast<IntegerType>(SI.getSrcTy())->getBitWidth();
|
|
|
|
uint32_t DstBitWidth = cast<IntegerType>(SI.getDestTy())->getBitWidth();
|
2007-04-19 07:35:00 +02:00
|
|
|
APInt Min(APInt::getHighBitsSet(DstBitWidth, DstBitWidth-SrcBitWidth+1));
|
|
|
|
APInt Max(APInt::getLowBitsSet(DstBitWidth, SrcBitWidth-1));
|
2009-07-16 20:04:31 +02:00
|
|
|
VRP.add(Context->getConstantInt(Min), &SI, ICmpInst::ICMP_SLE);
|
|
|
|
VRP.add(Context->getConstantInt(Max), &SI, ICmpInst::ICMP_SGE);
|
2007-02-05 00:43:05 +01:00
|
|
|
VRP.solve();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PredicateSimplifier::Forwards::visitZExtInst(ZExtInst &ZI) {
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &ZI);
|
2009-07-16 20:04:31 +02:00
|
|
|
LLVMContext *Context = ZI.getParent()->getContext();
|
2007-03-03 01:48:31 +01:00
|
|
|
uint32_t SrcBitWidth = cast<IntegerType>(ZI.getSrcTy())->getBitWidth();
|
|
|
|
uint32_t DstBitWidth = cast<IntegerType>(ZI.getDestTy())->getBitWidth();
|
2007-04-19 07:35:00 +02:00
|
|
|
APInt Max(APInt::getLowBitsSet(DstBitWidth, SrcBitWidth));
|
2009-07-16 20:04:31 +02:00
|
|
|
VRP.add(Context->getConstantInt(Max), &ZI, ICmpInst::ICMP_UGE);
|
2007-02-05 00:43:05 +01:00
|
|
|
VRP.solve();
|
|
|
|
}
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
void PredicateSimplifier::Forwards::visitBinaryOperator(BinaryOperator &BO) {
|
|
|
|
Instruction::BinaryOps ops = BO.getOpcode();
|
2006-08-29 00:44:55 +02:00
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
switch (ops) {
|
2007-03-16 03:37:39 +01:00
|
|
|
default: break;
|
2007-02-05 00:43:05 +01:00
|
|
|
case Instruction::URem:
|
|
|
|
case Instruction::SRem:
|
|
|
|
case Instruction::UDiv:
|
|
|
|
case Instruction::SDiv: {
|
|
|
|
Value *Divisor = BO.getOperand(1);
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &BO);
|
2009-07-13 06:09:18 +02:00
|
|
|
VRP.add(BO.getParent()->getContext()->getNullValue(Divisor->getType()),
|
|
|
|
Divisor, ICmpInst::ICMP_NE);
|
2007-02-05 00:43:05 +01:00
|
|
|
VRP.solve();
|
|
|
|
break;
|
|
|
|
}
|
2007-03-16 03:37:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (ops) {
|
|
|
|
default: break;
|
|
|
|
case Instruction::Shl: {
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &BO);
|
2007-03-16 03:37:39 +01:00
|
|
|
VRP.add(&BO, BO.getOperand(0), ICmpInst::ICMP_UGE);
|
|
|
|
VRP.solve();
|
|
|
|
} break;
|
|
|
|
case Instruction::AShr: {
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &BO);
|
2007-03-16 03:37:39 +01:00
|
|
|
VRP.add(&BO, BO.getOperand(0), ICmpInst::ICMP_SLE);
|
|
|
|
VRP.solve();
|
|
|
|
} break;
|
|
|
|
case Instruction::LShr:
|
|
|
|
case Instruction::UDiv: {
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &BO);
|
2007-03-16 03:37:39 +01:00
|
|
|
VRP.add(&BO, BO.getOperand(0), ICmpInst::ICMP_ULE);
|
|
|
|
VRP.solve();
|
|
|
|
} break;
|
|
|
|
case Instruction::URem: {
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &BO);
|
2007-03-16 03:37:39 +01:00
|
|
|
VRP.add(&BO, BO.getOperand(1), ICmpInst::ICMP_ULE);
|
|
|
|
VRP.solve();
|
|
|
|
} break;
|
|
|
|
case Instruction::And: {
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &BO);
|
2007-03-16 03:37:39 +01:00
|
|
|
VRP.add(&BO, BO.getOperand(0), ICmpInst::ICMP_ULE);
|
|
|
|
VRP.add(&BO, BO.getOperand(1), ICmpInst::ICMP_ULE);
|
|
|
|
VRP.solve();
|
|
|
|
} break;
|
|
|
|
case Instruction::Or: {
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &BO);
|
2007-03-16 03:37:39 +01:00
|
|
|
VRP.add(&BO, BO.getOperand(0), ICmpInst::ICMP_UGE);
|
|
|
|
VRP.add(&BO, BO.getOperand(1), ICmpInst::ICMP_UGE);
|
|
|
|
VRP.solve();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PredicateSimplifier::Forwards::visitICmpInst(ICmpInst &IC) {
|
|
|
|
// If possible, squeeze the ICmp predicate into something simpler.
|
|
|
|
// Eg., if x = [0, 4) and we're being asked icmp uge %x, 3 then change
|
|
|
|
// the predicate to eq.
|
|
|
|
|
2007-04-07 04:30:14 +02:00
|
|
|
// XXX: once we do full PHI handling, modifying the instruction in the
|
|
|
|
// Forwards visitor will cause missed optimizations.
|
|
|
|
|
2007-03-16 03:37:39 +01:00
|
|
|
ICmpInst::Predicate Pred = IC.getPredicate();
|
|
|
|
|
2007-04-07 04:30:14 +02:00
|
|
|
switch (Pred) {
|
|
|
|
default: break;
|
|
|
|
case ICmpInst::ICMP_ULE: Pred = ICmpInst::ICMP_ULT; break;
|
|
|
|
case ICmpInst::ICMP_UGE: Pred = ICmpInst::ICMP_UGT; break;
|
|
|
|
case ICmpInst::ICMP_SLE: Pred = ICmpInst::ICMP_SLT; break;
|
|
|
|
case ICmpInst::ICMP_SGE: Pred = ICmpInst::ICMP_SGT; break;
|
|
|
|
}
|
|
|
|
if (Pred != IC.getPredicate()) {
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &IC);
|
2007-04-07 04:30:14 +02:00
|
|
|
if (VRP.isRelatedBy(IC.getOperand(1), IC.getOperand(0),
|
|
|
|
ICmpInst::ICMP_NE)) {
|
|
|
|
++NumSnuggle;
|
|
|
|
PS->modified = true;
|
|
|
|
IC.setPredicate(Pred);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Pred = IC.getPredicate();
|
|
|
|
|
2009-07-16 20:04:31 +02:00
|
|
|
LLVMContext *Context = IC.getParent()->getContext();
|
|
|
|
|
2007-03-16 03:37:39 +01:00
|
|
|
if (ConstantInt *Op1 = dyn_cast<ConstantInt>(IC.getOperand(1))) {
|
|
|
|
ConstantInt *NextVal = 0;
|
2007-04-07 04:30:14 +02:00
|
|
|
switch (Pred) {
|
2007-03-16 03:37:39 +01:00
|
|
|
default: break;
|
|
|
|
case ICmpInst::ICMP_SLT:
|
|
|
|
case ICmpInst::ICMP_ULT:
|
|
|
|
if (Op1->getValue() != 0)
|
2009-07-16 20:04:31 +02:00
|
|
|
NextVal = Context->getConstantInt(Op1->getValue()-1);
|
2007-03-16 03:37:39 +01:00
|
|
|
break;
|
|
|
|
case ICmpInst::ICMP_SGT:
|
|
|
|
case ICmpInst::ICMP_UGT:
|
|
|
|
if (!Op1->getValue().isAllOnesValue())
|
2009-07-16 20:04:31 +02:00
|
|
|
NextVal = Context->getConstantInt(Op1->getValue()+1);
|
2007-03-16 03:37:39 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-10-24 06:00:26 +02:00
|
|
|
|
2007-03-16 03:37:39 +01:00
|
|
|
if (NextVal) {
|
2007-07-05 05:15:00 +02:00
|
|
|
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &IC);
|
2007-03-16 03:37:39 +01:00
|
|
|
if (VRP.isRelatedBy(IC.getOperand(0), NextVal,
|
|
|
|
ICmpInst::getInversePredicate(Pred))) {
|
2009-07-10 01:48:35 +02:00
|
|
|
ICmpInst *NewIC = new ICmpInst(&IC, ICmpInst::ICMP_EQ,
|
|
|
|
IC.getOperand(0), NextVal, "");
|
2007-03-16 03:37:39 +01:00
|
|
|
NewIC->takeName(&IC);
|
|
|
|
IC.replaceAllUsesWith(NewIC);
|
2007-07-05 05:15:00 +02:00
|
|
|
|
|
|
|
// XXX: prove this isn't necessary
|
|
|
|
if (unsigned n = VN.valueNumber(&IC, PS->DTDFS->getRootNode()))
|
|
|
|
if (VN.value(n) == &IC) IG.remove(n);
|
|
|
|
VN.remove(&IC);
|
|
|
|
|
2007-03-16 03:37:39 +01:00
|
|
|
IC.eraseFromParent();
|
|
|
|
++NumSnuggle;
|
|
|
|
PS->modified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-30 04:46:48 +02:00
|
|
|
}
|
2006-11-23 00:49:16 +01:00
|
|
|
}
|
|
|
|
|
2008-05-13 02:00:25 +02:00
|
|
|
char PredicateSimplifier::ID = 0;
|
|
|
|
static RegisterPass<PredicateSimplifier>
|
|
|
|
X("predsimplify", "Predicate Simplifier");
|
|
|
|
|
2006-11-23 00:49:16 +01:00
|
|
|
FunctionPass *llvm::createPredicateSimplifierPass() {
|
|
|
|
return new PredicateSimplifier();
|
2006-08-29 00:44:55 +02:00
|
|
|
}
|