2006-08-28 22:44:55 +00:00
|
|
|
//===-- PredicateSimplifier.cpp - Path Sensitive Simplifier -----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Nick Lewycky and is distributed under the
|
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This optimization works by substituting %q for %p when protected by a
|
2006-08-30 02:46:48 +00:00
|
|
|
// conditional that assures us of that fact. Properties are stored as
|
|
|
|
// relationships between two values.
|
2006-08-28 22:44:55 +00:00
|
|
|
//
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "predsimplify"
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
|
|
|
#include "llvm/Constants.h"
|
2006-10-22 19:53:27 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2006-08-28 22:44:55 +00:00
|
|
|
#include "llvm/Instructions.h"
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/Analysis/Dominators.h"
|
|
|
|
#include "llvm/Support/CFG.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2006-10-12 02:02:44 +00:00
|
|
|
#include "llvm/Support/InstVisitor.h"
|
2006-08-28 22:44:55 +00:00
|
|
|
#include <iostream>
|
2006-10-25 23:48:24 +00:00
|
|
|
#include <list>
|
2006-08-28 22:44:55 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2006-09-10 02:27:07 +00:00
|
|
|
typedef DominatorTree::Node DTNodeType;
|
|
|
|
|
2006-08-28 22:44:55 +00:00
|
|
|
namespace {
|
|
|
|
Statistic<>
|
|
|
|
NumVarsReplaced("predsimplify", "Number of argument substitutions");
|
|
|
|
Statistic<>
|
2006-08-30 02:46:48 +00:00
|
|
|
NumInstruction("predsimplify", "Number of instructions removed");
|
2006-08-28 22:44:55 +00:00
|
|
|
|
2006-09-20 17:04:01 +00:00
|
|
|
class PropertySet;
|
2006-09-10 02:27:07 +00:00
|
|
|
|
|
|
|
/// Similar to EquivalenceClasses, this stores the set of equivalent
|
2006-09-20 17:04:01 +00:00
|
|
|
/// types. Beyond EquivalenceClasses, it allows us to specify which
|
|
|
|
/// element will act as leader.
|
|
|
|
template<typename ElemTy>
|
2006-09-10 02:27:07 +00:00
|
|
|
class VISIBILITY_HIDDEN Synonyms {
|
|
|
|
std::map<ElemTy, unsigned> mapping;
|
|
|
|
std::vector<ElemTy> leaders;
|
2006-09-20 17:04:01 +00:00
|
|
|
PropertySet *PS;
|
2006-09-10 02:27:07 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef unsigned iterator;
|
|
|
|
typedef const unsigned const_iterator;
|
|
|
|
|
2006-09-20 17:04:01 +00:00
|
|
|
Synonyms(PropertySet *PS) : PS(PS) {}
|
|
|
|
|
2006-09-10 02:27:07 +00:00
|
|
|
// Inspection
|
|
|
|
|
|
|
|
bool empty() const {
|
|
|
|
return leaders.empty();
|
|
|
|
}
|
|
|
|
|
2006-10-25 23:48:24 +00:00
|
|
|
iterator findLeader(ElemTy &e) {
|
2006-09-10 02:27:07 +00:00
|
|
|
typename std::map<ElemTy, unsigned>::iterator MI = mapping.find(e);
|
|
|
|
if (MI == mapping.end()) return 0;
|
|
|
|
|
|
|
|
return MI->second;
|
|
|
|
}
|
|
|
|
|
2006-10-25 23:48:24 +00:00
|
|
|
const_iterator findLeader(ElemTy &e) const {
|
2006-09-10 02:27:07 +00:00
|
|
|
typename std::map<ElemTy, unsigned>::const_iterator MI =
|
|
|
|
mapping.find(e);
|
|
|
|
if (MI == mapping.end()) return 0;
|
|
|
|
|
|
|
|
return MI->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
ElemTy &getLeader(iterator I) {
|
2006-09-18 21:09:35 +00:00
|
|
|
assert(I && I <= leaders.size() && "Illegal leader to get.");
|
2006-09-10 02:27:07 +00:00
|
|
|
return leaders[I-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
const ElemTy &getLeader(const_iterator I) const {
|
2006-09-18 21:09:35 +00:00
|
|
|
assert(I && I <= leaders.size() && "Illegal leaders to get.");
|
2006-09-10 02:27:07 +00:00
|
|
|
return leaders[I-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void debug(std::ostream &os) const {
|
|
|
|
for (unsigned i = 1, e = leaders.size()+1; i != e; ++i) {
|
2006-09-13 19:32:53 +00:00
|
|
|
os << i << ". " << *getLeader(i) << ": [";
|
2006-09-10 02:27:07 +00:00
|
|
|
for (std::map<Value *, unsigned>::const_iterator
|
|
|
|
I = mapping.begin(), E = mapping.end(); I != E; ++I) {
|
|
|
|
if ((*I).second == i && (*I).first != leaders[i-1]) {
|
|
|
|
os << *(*I).first << " ";
|
2006-09-13 19:24:01 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-10 02:27:07 +00:00
|
|
|
os << "]\n";
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-10 02:27:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Mutators
|
|
|
|
|
2006-10-25 23:48:24 +00:00
|
|
|
void remove(ElemTy &e) {
|
|
|
|
ElemTy E = e; // The parameter to erase must not be a reference to
|
|
|
|
mapping.erase(E); // an element contained in the map.
|
|
|
|
}
|
|
|
|
|
2006-09-10 02:27:07 +00:00
|
|
|
/// Combine two sets referring to the same element, inserting the
|
|
|
|
/// elements as needed. Returns a valid iterator iff two already
|
|
|
|
/// existing disjoint synonym sets were combined. The iterator
|
2006-09-20 17:04:01 +00:00
|
|
|
/// points to the no longer existing element.
|
|
|
|
iterator unionSets(ElemTy E1, ElemTy E2);
|
2006-09-10 02:27:07 +00:00
|
|
|
|
|
|
|
/// Returns an iterator pointing to the synonym set containing
|
|
|
|
/// element e. If none exists, a new one is created and returned.
|
2006-10-25 23:48:24 +00:00
|
|
|
iterator findOrInsert(ElemTy &e) {
|
2006-09-10 02:27:07 +00:00
|
|
|
iterator I = findLeader(e);
|
|
|
|
if (I) return I;
|
|
|
|
|
|
|
|
leaders.push_back(e);
|
|
|
|
I = leaders.size();
|
|
|
|
mapping[e] = I;
|
|
|
|
return I;
|
|
|
|
}
|
|
|
|
};
|
2006-08-28 22:44:55 +00:00
|
|
|
|
|
|
|
/// Represents the set of equivalent Value*s and provides insertion
|
|
|
|
/// and fast lookup. Also stores the set of inequality relationships.
|
|
|
|
class PropertySet {
|
2006-09-23 15:13:08 +00:00
|
|
|
/// Returns true if V1 is a better choice than V2.
|
2006-09-20 17:04:01 +00:00
|
|
|
bool compare(Value *V1, Value *V2) const {
|
|
|
|
if (isa<Constant>(V1)) {
|
|
|
|
if (!isa<Constant>(V2)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (isa<Argument>(V1)) {
|
|
|
|
if (!isa<Constant>(V2) && !isa<Argument>(V2)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Instruction *I1 = dyn_cast<Instruction>(V1)) {
|
|
|
|
if (Instruction *I2 = dyn_cast<Instruction>(V2)) {
|
|
|
|
BasicBlock *BB1 = I1->getParent(),
|
|
|
|
*BB2 = I2->getParent();
|
|
|
|
if (BB1 == BB2) {
|
|
|
|
for (BasicBlock::const_iterator I = BB1->begin(), E = BB1->end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (&*I == I1) return true;
|
|
|
|
if (&*I == I2) return false;
|
|
|
|
}
|
|
|
|
assert(0 && "Instructions not found in parent BasicBlock?");
|
|
|
|
} else
|
|
|
|
return DT->getNode(BB1)->properlyDominates(DT->getNode(BB2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-08-28 22:44:55 +00:00
|
|
|
struct Property;
|
|
|
|
public:
|
2006-09-20 17:04:01 +00:00
|
|
|
/// Choose the canonical Value in a synonym set.
|
|
|
|
/// Leaves the more canonical choice in V1.
|
|
|
|
void order(Value *&V1, Value *&V2) const {
|
|
|
|
if (compare(V2, V1)) std::swap(V1, V2);
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertySet(DominatorTree *DT) : union_find(this), DT(DT) {}
|
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
Synonyms<Value *> union_find;
|
2006-09-10 02:27:07 +00:00
|
|
|
|
2006-08-28 22:44:55 +00:00
|
|
|
typedef std::vector<Property>::iterator PropertyIterator;
|
|
|
|
typedef std::vector<Property>::const_iterator ConstPropertyIterator;
|
2006-09-20 17:04:01 +00:00
|
|
|
typedef Synonyms<Value *>::iterator SynonymIterator;
|
2006-08-28 22:44:55 +00:00
|
|
|
|
|
|
|
enum Ops {
|
|
|
|
EQ,
|
|
|
|
NE
|
|
|
|
};
|
|
|
|
|
|
|
|
Value *canonicalize(Value *V) const {
|
|
|
|
Value *C = lookup(V);
|
|
|
|
return C ? C : V;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *lookup(Value *V) const {
|
2006-09-20 17:04:01 +00:00
|
|
|
SynonymIterator SI = union_find.findLeader(V);
|
2006-09-10 02:27:07 +00:00
|
|
|
if (!SI) return NULL;
|
|
|
|
return union_find.getLeader(SI);
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool empty() const {
|
2006-08-30 02:46:48 +00:00
|
|
|
return union_find.empty();
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
|
2006-10-25 23:48:24 +00:00
|
|
|
void remove(Value *V) {
|
|
|
|
SynonymIterator I = union_find.findLeader(V);
|
|
|
|
if (!I) return;
|
|
|
|
|
|
|
|
union_find.remove(V);
|
|
|
|
|
|
|
|
for (PropertyIterator PI = Properties.begin(), PE = Properties.end();
|
|
|
|
PI != PE;) {
|
|
|
|
Property &P = *PI++;
|
|
|
|
if (P.I1 == I || P.I2 == I) Properties.erase(PI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-28 22:44:55 +00:00
|
|
|
void addEqual(Value *V1, Value *V2) {
|
2006-09-02 19:40:38 +00:00
|
|
|
// If %x = 0. and %y = -0., seteq %x, %y is true, but
|
|
|
|
// copysign(%x) is not the same as copysign(%y).
|
2006-09-13 19:24:01 +00:00
|
|
|
if (V1->getType()->isFloatingPoint()) return;
|
2006-09-02 19:40:38 +00:00
|
|
|
|
2006-08-28 22:44:55 +00:00
|
|
|
order(V1, V2);
|
|
|
|
if (isa<Constant>(V2)) return; // refuse to set false == true.
|
|
|
|
|
2006-10-25 23:48:24 +00:00
|
|
|
if (union_find.findLeader(V1) &&
|
|
|
|
union_find.findLeader(V1) == union_find.findLeader(V2))
|
|
|
|
return; // no-op
|
|
|
|
|
2006-09-10 02:27:07 +00:00
|
|
|
SynonymIterator deleted = union_find.unionSets(V1, V2);
|
|
|
|
if (deleted) {
|
|
|
|
SynonymIterator replacement = union_find.findLeader(V1);
|
|
|
|
// Move Properties
|
|
|
|
for (PropertyIterator I = Properties.begin(), E = Properties.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (I->I1 == deleted) I->I1 = replacement;
|
|
|
|
else if (I->I1 > deleted) --I->I1;
|
|
|
|
if (I->I2 == deleted) I->I2 = replacement;
|
|
|
|
else if (I->I2 > deleted) --I->I2;
|
|
|
|
}
|
|
|
|
}
|
2006-08-28 22:44:55 +00:00
|
|
|
addImpliedProperties(EQ, V1, V2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addNotEqual(Value *V1, Value *V2) {
|
2006-09-02 19:40:38 +00:00
|
|
|
// If %x = NAN then seteq %x, %x is false.
|
2006-09-13 19:24:01 +00:00
|
|
|
if (V1->getType()->isFloatingPoint()) return;
|
|
|
|
|
|
|
|
// For example, %x = setne int 0, 0 causes "0 != 0".
|
|
|
|
if (isa<Constant>(V1) && isa<Constant>(V2)) return;
|
2006-09-02 19:40:38 +00:00
|
|
|
|
2006-08-31 00:39:16 +00:00
|
|
|
if (findProperty(NE, V1, V2) != Properties.end())
|
2006-10-25 23:48:24 +00:00
|
|
|
return; // no-op.
|
2006-08-28 22:44:55 +00:00
|
|
|
|
|
|
|
// Add the property.
|
2006-09-10 02:27:07 +00:00
|
|
|
SynonymIterator I1 = union_find.findOrInsert(V1),
|
|
|
|
I2 = union_find.findOrInsert(V2);
|
2006-09-13 19:24:01 +00:00
|
|
|
|
|
|
|
// Technically this means that the block is unreachable.
|
|
|
|
if (I1 == I2) return;
|
|
|
|
|
2006-09-10 02:27:07 +00:00
|
|
|
Properties.push_back(Property(NE, I1, I2));
|
2006-08-28 22:44:55 +00:00
|
|
|
addImpliedProperties(NE, V1, V2);
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyIterator findProperty(Ops Opcode, Value *V1, Value *V2) {
|
|
|
|
assert(Opcode != EQ && "Can't findProperty on EQ."
|
|
|
|
"Use the lookup method instead.");
|
|
|
|
|
2006-09-10 02:27:07 +00:00
|
|
|
SynonymIterator I1 = union_find.findLeader(V1),
|
|
|
|
I2 = union_find.findLeader(V2);
|
|
|
|
if (!I1 || !I2) return Properties.end();
|
2006-08-28 22:44:55 +00:00
|
|
|
|
2006-09-10 02:27:07 +00:00
|
|
|
return
|
|
|
|
find(Properties.begin(), Properties.end(), Property(Opcode, I1, I2));
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ConstPropertyIterator
|
|
|
|
findProperty(Ops Opcode, Value *V1, Value *V2) const {
|
|
|
|
assert(Opcode != EQ && "Can't findProperty on EQ."
|
|
|
|
"Use the lookup method instead.");
|
|
|
|
|
2006-09-10 02:27:07 +00:00
|
|
|
SynonymIterator I1 = union_find.findLeader(V1),
|
|
|
|
I2 = union_find.findLeader(V2);
|
|
|
|
if (!I1 || !I2) return Properties.end();
|
2006-08-28 22:44:55 +00:00
|
|
|
|
2006-09-10 02:27:07 +00:00
|
|
|
return
|
|
|
|
find(Properties.begin(), Properties.end(), Property(Opcode, I1, I2));
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Represents Head OP [Tail1, Tail2, ...]
|
|
|
|
// For example: %x != %a, %x != %b.
|
2006-09-10 02:27:07 +00:00
|
|
|
struct VISIBILITY_HIDDEN Property {
|
2006-09-20 17:04:01 +00:00
|
|
|
typedef SynonymIterator Iter;
|
2006-09-10 02:27:07 +00:00
|
|
|
|
|
|
|
Property(Ops opcode, Iter i1, Iter i2)
|
|
|
|
: Opcode(opcode), I1(i1), I2(i2)
|
2006-09-02 19:40:38 +00:00
|
|
|
{ assert(opcode != EQ && "Equality belongs in the synonym set, "
|
2006-09-10 02:27:07 +00:00
|
|
|
"not a property."); }
|
|
|
|
|
|
|
|
bool operator==(const Property &P) const {
|
|
|
|
return (Opcode == P.Opcode) &&
|
|
|
|
((I1 == P.I1 && I2 == P.I2) ||
|
|
|
|
(I1 == P.I2 && I2 == P.I1));
|
|
|
|
}
|
2006-08-28 22:44:55 +00:00
|
|
|
|
|
|
|
Ops Opcode;
|
2006-09-10 02:27:07 +00:00
|
|
|
Iter I1, I2;
|
2006-08-28 22:44:55 +00:00
|
|
|
};
|
|
|
|
|
2006-10-25 23:48:24 +00:00
|
|
|
void addToResolve(Value *V, std::list<Value *> &WorkList) {
|
|
|
|
if (!isa<Constant>(V) && !isa<BasicBlock>(V)) {
|
|
|
|
for (Value::use_iterator UI = V->use_begin(), UE = V->use_end();
|
|
|
|
UI != UE; ++UI) {
|
|
|
|
if (!isa<Constant>(*UI) && !isa<BasicBlock>(*UI)) {
|
|
|
|
WorkList.push_back(*UI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void resolve(std::list<Value *> &WorkList) {
|
|
|
|
if (WorkList.empty()) return;
|
|
|
|
|
|
|
|
Value *V = WorkList.front();
|
|
|
|
WorkList.pop_front();
|
|
|
|
|
|
|
|
if (empty()) return;
|
|
|
|
|
|
|
|
Instruction *I = dyn_cast<Instruction>(V);
|
|
|
|
if (!I) return;
|
|
|
|
|
|
|
|
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(I)) {
|
|
|
|
Value *lhs = canonicalize(BO->getOperand(0)),
|
|
|
|
*rhs = canonicalize(BO->getOperand(1));
|
|
|
|
|
|
|
|
ConstantIntegral *CI1 = dyn_cast<ConstantIntegral>(lhs),
|
|
|
|
*CI2 = dyn_cast<ConstantIntegral>(rhs);
|
|
|
|
|
|
|
|
if (CI1 && CI2) {
|
|
|
|
addToResolve(BO, WorkList);
|
|
|
|
addEqual(BO, ConstantExpr::get(BO->getOpcode(), CI1, CI2));
|
|
|
|
} else if (SetCondInst *SCI = dyn_cast<SetCondInst>(BO)) {
|
|
|
|
PropertySet::ConstPropertyIterator NE =
|
|
|
|
findProperty(PropertySet::NE, lhs, rhs);
|
|
|
|
|
|
|
|
if (NE != Properties.end()) {
|
|
|
|
switch (SCI->getOpcode()) {
|
|
|
|
case Instruction::SetEQ:
|
|
|
|
addToResolve(SCI, WorkList);
|
|
|
|
addEqual(SCI, ConstantBool::getFalse());
|
|
|
|
break;
|
|
|
|
case Instruction::SetNE:
|
|
|
|
addToResolve(SCI, WorkList);
|
|
|
|
addEqual(SCI, ConstantBool::getTrue());
|
|
|
|
break;
|
|
|
|
case Instruction::SetLE:
|
|
|
|
case Instruction::SetGE:
|
|
|
|
case Instruction::SetLT:
|
|
|
|
case Instruction::SetGT:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Unknown opcode in SetCondInst.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (SelectInst *SI = dyn_cast<SelectInst>(I)) {
|
|
|
|
Value *Condition = canonicalize(SI->getCondition());
|
|
|
|
if (ConstantBool *CB = dyn_cast<ConstantBool>(Condition)) {
|
|
|
|
addToResolve(SI, WorkList);
|
|
|
|
addEqual(SI, CB->getValue() ? SI->getTrueValue() : SI->getFalseValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!WorkList.empty()) resolve(WorkList);
|
|
|
|
}
|
|
|
|
|
2006-10-26 02:35:18 +00:00
|
|
|
void add(Ops Opcode, Value *V1, Value *V2, bool invert) {
|
|
|
|
switch (Opcode) {
|
|
|
|
case EQ:
|
|
|
|
if (invert) addNotEqual(V1, V2);
|
|
|
|
else addEqual(V1, V2);
|
|
|
|
break;
|
|
|
|
case NE:
|
|
|
|
if (invert) addEqual(V1, V2);
|
|
|
|
else addNotEqual(V1, V2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Unknown property opcode.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Finds the properties implied by an equivalence and adds them too.
|
|
|
|
/// Example: ("seteq %a, %b", true, EQ) --> (%a, %b, EQ)
|
|
|
|
/// ("seteq %a, %b", false, EQ) --> (%a, %b, NE)
|
2006-08-28 22:44:55 +00:00
|
|
|
void addImpliedProperties(Ops Opcode, Value *V1, Value *V2) {
|
|
|
|
order(V1, V2);
|
|
|
|
|
|
|
|
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(V2)) {
|
|
|
|
switch (BO->getOpcode()) {
|
|
|
|
case Instruction::SetEQ:
|
2006-10-26 02:35:18 +00:00
|
|
|
// "seteq int %a, %b" EQ true then %a EQ %b
|
|
|
|
// "seteq int %a, %b" EQ false then %a NE %b
|
|
|
|
// "seteq int %a, %b" NE true then %a NE %b
|
|
|
|
// "seteq int %a, %b" NE false then %a EQ %b
|
2006-09-28 23:35:22 +00:00
|
|
|
if (ConstantBool *V1CB = dyn_cast<ConstantBool>(V1))
|
|
|
|
add(Opcode, BO->getOperand(0), BO->getOperand(1),!V1CB->getValue());
|
2006-08-28 22:44:55 +00:00
|
|
|
break;
|
|
|
|
case Instruction::SetNE:
|
2006-10-26 02:35:18 +00:00
|
|
|
// "setne int %a, %b" EQ true then %a NE %b
|
|
|
|
// "setne int %a, %b" EQ false then %a EQ %b
|
|
|
|
// "setne int %a, %b" NE true then %a EQ %b
|
|
|
|
// "setne int %a, %b" NE false then %a NE %b
|
2006-09-28 23:35:22 +00:00
|
|
|
if (ConstantBool *V1CB = dyn_cast<ConstantBool>(V1))
|
|
|
|
add(Opcode, BO->getOperand(0), BO->getOperand(1), V1CB->getValue());
|
2006-08-28 22:44:55 +00:00
|
|
|
break;
|
|
|
|
case Instruction::SetLT:
|
|
|
|
case Instruction::SetGT:
|
2006-10-26 02:35:18 +00:00
|
|
|
// "setlt/gt int %a, %b" EQ true then %a NE %b
|
|
|
|
// "setlt/gt int %a, %b" NE false then %a NE %b
|
|
|
|
|
|
|
|
// "setlt int %a, %b" NE true then %a EQ %b
|
|
|
|
|
|
|
|
if (ConstantBool *CB = dyn_cast<ConstantBool>(V1)) {
|
|
|
|
if (CB->getValue() ^ Opcode==NE)
|
|
|
|
addNotEqual(BO->getOperand(0), BO->getOperand(1));
|
|
|
|
}
|
2006-08-28 22:44:55 +00:00
|
|
|
break;
|
|
|
|
case Instruction::SetLE:
|
|
|
|
case Instruction::SetGE:
|
2006-10-26 02:35:18 +00:00
|
|
|
// "setle/ge int %a, %b" EQ false then %a NE %b
|
|
|
|
// "setle/ge int %a, %b" NE true then %a NE %b
|
|
|
|
if (ConstantBool *CB = dyn_cast<ConstantBool>(V1)) {
|
|
|
|
if (CB->getValue() ^ Opcode==EQ)
|
|
|
|
addNotEqual(BO->getOperand(0), BO->getOperand(1));
|
|
|
|
}
|
2006-08-28 22:44:55 +00:00
|
|
|
break;
|
2006-10-25 23:48:24 +00:00
|
|
|
case Instruction::And: {
|
|
|
|
// "and int %a, %b" EQ 0xff then %a EQ 0xff and %b EQ 0xff
|
|
|
|
// "and bool %a, %b" EQ true then %a EQ true and %b EQ true
|
|
|
|
// "and bool %a, %b" NE false then %a EQ true and %b EQ true
|
|
|
|
if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(V1)) {
|
|
|
|
if (Opcode == EQ && CI->isAllOnesValue()) {
|
|
|
|
addEqual(CI, BO->getOperand(0));
|
|
|
|
addEqual(CI, BO->getOperand(1));
|
|
|
|
} else if (Opcode == NE && CI == ConstantBool::getFalse()) {
|
|
|
|
addEqual(ConstantBool::getTrue(), BO->getOperand(0));
|
|
|
|
addEqual(ConstantBool::getTrue(), BO->getOperand(1));
|
|
|
|
}
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
2006-10-25 23:48:24 +00:00
|
|
|
} break;
|
|
|
|
case Instruction::Or: {
|
|
|
|
// "or int %a, %b" EQ 0 then %a EQ 0 and %b EQ 0
|
|
|
|
// "or bool %a, %b" EQ false then %a EQ false and %b EQ false
|
|
|
|
// "or bool %a, %b" NE true then %a EQ false and %b EQ false
|
|
|
|
if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(V1)) {
|
|
|
|
if (Opcode == EQ && CI->isNullValue()) {
|
|
|
|
addEqual(CI, BO->getOperand(0));
|
|
|
|
addEqual(CI, BO->getOperand(1));
|
|
|
|
} else if (Opcode == NE && CI == ConstantBool::getTrue()) {
|
|
|
|
addEqual(ConstantBool::getFalse(), BO->getOperand(0));
|
|
|
|
addEqual(ConstantBool::getFalse(), BO->getOperand(1));
|
|
|
|
}
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
2006-10-25 23:48:24 +00:00
|
|
|
} break;
|
|
|
|
case Instruction::Xor: {
|
|
|
|
// "xor bool true, %a" EQ true then %a = false
|
|
|
|
// "xor bool true, %a" EQ false then %a = true
|
|
|
|
// "xor bool false, %a" EQ true then %a = true
|
|
|
|
// "xor bool false, %a" EQ false then %a = false
|
|
|
|
// 1. Repeat all of the above, with "NE false" in place of
|
|
|
|
// "EQ true" and "NE true" in place of "EQ false".
|
|
|
|
// "xor int %c, %a" EQ %c then %a = 0
|
|
|
|
// "xor int %c, %a" NE %c then %a != 0
|
2006-10-26 02:35:18 +00:00
|
|
|
// 2. Repeat all of the above, with order of operands reversed.
|
2006-10-25 23:48:24 +00:00
|
|
|
|
|
|
|
Value *LHS = BO->getOperand(0), *RHS = BO->getOperand(1);
|
|
|
|
if (!isa<Constant>(LHS)) std::swap(LHS, RHS);
|
|
|
|
|
|
|
|
if (ConstantBool *CB = dyn_cast<ConstantBool>(V1)) {
|
|
|
|
if (ConstantBool *A = dyn_cast<ConstantBool>(LHS)) {
|
2006-10-26 02:35:18 +00:00
|
|
|
addEqual(RHS, ConstantBool::get(A->getValue() ^ CB->getValue()
|
|
|
|
^ Opcode==NE));
|
2006-10-25 23:48:24 +00:00
|
|
|
}
|
2006-10-24 00:36:21 +00:00
|
|
|
}
|
2006-10-25 23:48:24 +00:00
|
|
|
else if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(V1)) {
|
|
|
|
if (ConstantIntegral *A = dyn_cast<ConstantIntegral>(LHS)) {
|
|
|
|
if (A == CI)
|
|
|
|
add(Opcode, RHS, Constant::getNullValue(A->getType()), false);
|
|
|
|
}
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
2006-10-25 23:48:24 +00:00
|
|
|
} break;
|
2006-08-28 22:44:55 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-09-02 19:40:38 +00:00
|
|
|
} else if (SelectInst *SI = dyn_cast<SelectInst>(V2)) {
|
2006-09-28 23:35:22 +00:00
|
|
|
ConstantBool *True = ConstantBool::get(Opcode==EQ),
|
|
|
|
*False = ConstantBool::get(Opcode!=EQ);
|
2006-09-02 19:40:38 +00:00
|
|
|
|
2006-10-26 02:35:18 +00:00
|
|
|
if (V1 == canonicalize(SI->getTrueValue()))
|
2006-09-02 19:40:38 +00:00
|
|
|
addEqual(SI->getCondition(), True);
|
2006-10-26 02:35:18 +00:00
|
|
|
else if (V1 == canonicalize(SI->getFalseValue()))
|
2006-09-02 19:40:38 +00:00
|
|
|
addEqual(SI->getCondition(), False);
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
2006-10-25 23:48:24 +00:00
|
|
|
|
|
|
|
std::list<Value *> WorkList;
|
|
|
|
addToResolve(V1, WorkList);
|
|
|
|
addToResolve(V2, WorkList);
|
|
|
|
resolve(WorkList);
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
|
2006-09-20 17:04:01 +00:00
|
|
|
DominatorTree *DT;
|
2006-08-28 22:44:55 +00:00
|
|
|
public:
|
2006-09-02 19:40:38 +00:00
|
|
|
#ifdef DEBUG
|
2006-08-28 22:44:55 +00:00
|
|
|
void debug(std::ostream &os) const {
|
2006-09-10 02:27:07 +00:00
|
|
|
static const char *OpcodeTable[] = { "EQ", "NE" };
|
|
|
|
|
|
|
|
union_find.debug(os);
|
|
|
|
for (std::vector<Property>::const_iterator I = Properties.begin(),
|
|
|
|
E = Properties.end(); I != E; ++I) {
|
|
|
|
os << (*I).I1 << " " << OpcodeTable[(*I).Opcode] << " "
|
|
|
|
<< (*I).I2 << "\n";
|
2006-08-31 00:39:16 +00:00
|
|
|
}
|
2006-09-10 02:27:07 +00:00
|
|
|
os << "\n";
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
2006-09-02 19:40:38 +00:00
|
|
|
#endif
|
2006-08-28 22:44:55 +00:00
|
|
|
|
|
|
|
std::vector<Property> Properties;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// 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-10-25 23:48:24 +00:00
|
|
|
class PredicateSimplifier : public FunctionPass {
|
2006-08-28 22:44:55 +00:00
|
|
|
public:
|
|
|
|
bool runOnFunction(Function &F);
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
|
|
|
|
|
|
|
private:
|
2006-10-12 02:02:44 +00:00
|
|
|
/// Forwards - Adds new properties into PropertySet and uses them to
|
|
|
|
/// 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
|
|
|
|
/// basic block with the new PropertySet.
|
|
|
|
class Forwards : public InstVisitor<Forwards> {
|
|
|
|
friend class InstVisitor<Forwards>;
|
|
|
|
PredicateSimplifier *PS;
|
|
|
|
public:
|
|
|
|
PropertySet &KP;
|
|
|
|
|
|
|
|
Forwards(PredicateSimplifier *PS, PropertySet &KP) : PS(PS), KP(KP) {}
|
|
|
|
|
|
|
|
// Tries to simplify each Instruction and add new properties to
|
|
|
|
// the PropertySet. Returns true if it erase the instruction.
|
|
|
|
//void visitInstruction(Instruction *I);
|
|
|
|
|
|
|
|
void visitTerminatorInst(TerminatorInst &TI);
|
|
|
|
void visitBranchInst(BranchInst &BI);
|
|
|
|
void visitSwitchInst(SwitchInst &SI);
|
|
|
|
|
2006-10-22 19:53:27 +00:00
|
|
|
void visitAllocaInst(AllocaInst &AI);
|
2006-10-12 02:02:44 +00:00
|
|
|
void visitLoadInst(LoadInst &LI);
|
|
|
|
void visitStoreInst(StoreInst &SI);
|
|
|
|
void visitBinaryOperator(BinaryOperator &BO);
|
|
|
|
};
|
2006-08-28 22:44:55 +00:00
|
|
|
|
|
|
|
// Used by terminator instructions to proceed from the current basic
|
|
|
|
// block to the next. Verifies that "current" dominates "next",
|
|
|
|
// then calls visitBasicBlock.
|
2006-09-18 21:09:35 +00:00
|
|
|
void proceedToSuccessors(PropertySet &CurrentPS, BasicBlock *Current);
|
2006-10-12 02:02:44 +00:00
|
|
|
void proceedToSuccessor(PropertySet &Properties, BasicBlock *Next);
|
2006-08-28 22:44:55 +00:00
|
|
|
|
|
|
|
// Visits each instruction in the basic block.
|
2006-09-18 21:09:35 +00:00
|
|
|
void visitBasicBlock(BasicBlock *Block, PropertySet &KnownProperties);
|
2006-08-28 22:44:55 +00:00
|
|
|
|
2006-09-10 02:27:07 +00:00
|
|
|
// Tries to simplify each Instruction and add new properties to
|
2006-10-12 02:02:44 +00:00
|
|
|
// the PropertySet.
|
2006-09-18 21:09:35 +00:00
|
|
|
void visitInstruction(Instruction *I, PropertySet &);
|
2006-08-28 22:44:55 +00:00
|
|
|
|
|
|
|
DominatorTree *DT;
|
|
|
|
bool modified;
|
|
|
|
};
|
|
|
|
|
|
|
|
RegisterPass<PredicateSimplifier> X("predsimplify",
|
|
|
|
"Predicate Simplifier");
|
2006-09-20 17:04:01 +00:00
|
|
|
|
|
|
|
template <typename ElemTy>
|
|
|
|
typename Synonyms<ElemTy>::iterator
|
|
|
|
Synonyms<ElemTy>::unionSets(ElemTy E1, ElemTy E2) {
|
|
|
|
PS->order(E1, E2);
|
|
|
|
|
|
|
|
iterator I1 = findLeader(E1),
|
|
|
|
I2 = findLeader(E2);
|
|
|
|
|
|
|
|
if (!I1 && !I2) { // neither entry is in yet
|
|
|
|
leaders.push_back(E1);
|
|
|
|
I1 = leaders.size();
|
|
|
|
mapping[E1] = I1;
|
|
|
|
mapping[E2] = I1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!I1 && I2) {
|
|
|
|
mapping[E1] = I2;
|
|
|
|
std::swap(getLeader(I2), E1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (I1 && !I2) {
|
|
|
|
mapping[E2] = I1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (I1 == I2) return 0;
|
|
|
|
|
|
|
|
// This is the case where we have two sets, [%a1, %a2, %a3] and
|
|
|
|
// [%p1, %p2, %p3] and someone says that %a2 == %p3. We need to
|
|
|
|
// combine the two synsets.
|
|
|
|
|
|
|
|
if (I1 > I2) --I1;
|
|
|
|
|
|
|
|
for (std::map<Value *, unsigned>::iterator I = mapping.begin(),
|
|
|
|
E = mapping.end(); I != E; ++I) {
|
|
|
|
if (I->second == I2) I->second = I1;
|
|
|
|
else if (I->second > I2) --I->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
leaders.erase(leaders.begin() + I2 - 1);
|
|
|
|
|
|
|
|
return I2;
|
|
|
|
}
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FunctionPass *llvm::createPredicateSimplifierPass() {
|
|
|
|
return new PredicateSimplifier();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PredicateSimplifier::runOnFunction(Function &F) {
|
|
|
|
DT = &getAnalysis<DominatorTree>();
|
|
|
|
|
|
|
|
modified = false;
|
2006-09-20 17:04:01 +00:00
|
|
|
PropertySet KnownProperties(DT);
|
2006-09-18 21:09:35 +00:00
|
|
|
visitBasicBlock(DT->getRootNode()->getBlock(), KnownProperties);
|
2006-08-28 22:44:55 +00:00
|
|
|
return modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PredicateSimplifier::getAnalysisUsage(AnalysisUsage &AU) const {
|
2006-10-03 14:52:23 +00:00
|
|
|
AU.addRequiredID(BreakCriticalEdgesID);
|
2006-08-28 22:44:55 +00:00
|
|
|
AU.addRequired<DominatorTree>();
|
2006-09-18 21:09:35 +00:00
|
|
|
AU.setPreservesCFG();
|
2006-10-03 14:52:23 +00:00
|
|
|
AU.addPreservedID(BreakCriticalEdgesID);
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
|
2006-09-18 21:09:35 +00:00
|
|
|
void PredicateSimplifier::visitBasicBlock(BasicBlock *BB,
|
2006-08-28 22:44:55 +00:00
|
|
|
PropertySet &KnownProperties) {
|
2006-09-13 18:55:37 +00:00
|
|
|
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
|
2006-09-18 21:09:35 +00:00
|
|
|
visitInstruction(I++, KnownProperties);
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-10 02:27:07 +00:00
|
|
|
void PredicateSimplifier::visitInstruction(Instruction *I,
|
|
|
|
PropertySet &KnownProperties) {
|
|
|
|
// Try to replace the whole instruction.
|
2006-10-25 23:48:24 +00:00
|
|
|
Value *V = KnownProperties.canonicalize(I);
|
2006-09-02 19:40:38 +00:00
|
|
|
if (V != I) {
|
|
|
|
modified = true;
|
|
|
|
++NumInstruction;
|
2006-09-20 17:04:01 +00:00
|
|
|
DEBUG(std::cerr << "Removing " << *I);
|
2006-10-25 23:48:24 +00:00
|
|
|
KnownProperties.remove(I);
|
2006-09-02 19:40:38 +00:00
|
|
|
I->replaceAllUsesWith(V);
|
2006-09-13 18:55:37 +00:00
|
|
|
I->eraseFromParent();
|
2006-09-02 19:40:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to substitute operands.
|
|
|
|
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
|
2006-08-28 22:44:55 +00:00
|
|
|
Value *Oper = I->getOperand(i);
|
2006-10-25 23:48:24 +00:00
|
|
|
Value *V = KnownProperties.canonicalize(Oper);
|
2006-08-28 22:44:55 +00:00
|
|
|
if (V != Oper) {
|
|
|
|
modified = true;
|
|
|
|
++NumVarsReplaced;
|
2006-09-23 15:13:08 +00:00
|
|
|
DEBUG(std::cerr << "Resolving " << *I);
|
2006-08-28 22:44:55 +00:00
|
|
|
I->setOperand(i, V);
|
|
|
|
DEBUG(std::cerr << "into " << *I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
Forwards visit(this, KnownProperties);
|
|
|
|
visit.visit(*I);
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
|
2006-09-18 21:09:35 +00:00
|
|
|
void PredicateSimplifier::proceedToSuccessors(PropertySet &KP,
|
|
|
|
BasicBlock *BBCurrent) {
|
|
|
|
DTNodeType *Current = DT->getNode(BBCurrent);
|
|
|
|
for (DTNodeType::iterator I = Current->begin(), E = Current->end();
|
|
|
|
I != E; ++I) {
|
|
|
|
PropertySet Copy(KP);
|
|
|
|
visitBasicBlock((*I)->getBlock(), Copy);
|
|
|
|
}
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
void PredicateSimplifier::proceedToSuccessor(PropertySet &KP, BasicBlock *BB) {
|
|
|
|
visitBasicBlock(BB, KP);
|
|
|
|
}
|
2006-08-28 22:44:55 +00:00
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
void PredicateSimplifier::Forwards::visitTerminatorInst(TerminatorInst &TI) {
|
|
|
|
PS->proceedToSuccessors(KP, TI.getParent());
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
void PredicateSimplifier::Forwards::visitBranchInst(BranchInst &BI) {
|
|
|
|
BasicBlock *BB = BI.getParent();
|
2006-09-18 21:09:35 +00:00
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
if (BI.isUnconditional()) {
|
|
|
|
PS->proceedToSuccessors(KP, BB);
|
2006-08-28 22:44:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
Value *Condition = BI.getCondition();
|
2006-08-28 22:44:55 +00:00
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
BasicBlock *TrueDest = BI.getSuccessor(0),
|
|
|
|
*FalseDest = BI.getSuccessor(1);
|
2006-08-30 02:46:48 +00:00
|
|
|
|
2006-10-03 17:36:01 +00:00
|
|
|
if (isa<ConstantBool>(Condition) || TrueDest == FalseDest) {
|
2006-10-12 02:02:44 +00:00
|
|
|
PS->proceedToSuccessors(KP, BB);
|
2006-08-30 02:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
DTNodeType *Node = PS->DT->getNode(BB);
|
2006-09-18 21:09:35 +00:00
|
|
|
for (DTNodeType::iterator I = Node->begin(), E = Node->end(); I != E; ++I) {
|
2006-10-03 17:36:01 +00:00
|
|
|
BasicBlock *Dest = (*I)->getBlock();
|
|
|
|
PropertySet DestProperties(KP);
|
2006-08-28 22:44:55 +00:00
|
|
|
|
2006-10-03 17:36:01 +00:00
|
|
|
if (Dest == TrueDest)
|
|
|
|
DestProperties.addEqual(ConstantBool::getTrue(), Condition);
|
|
|
|
else if (Dest == FalseDest)
|
|
|
|
DestProperties.addEqual(ConstantBool::getFalse(), Condition);
|
2006-09-18 21:09:35 +00:00
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
PS->proceedToSuccessor(DestProperties, Dest);
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
2006-09-18 21:09:35 +00:00
|
|
|
}
|
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
void PredicateSimplifier::Forwards::visitSwitchInst(SwitchInst &SI) {
|
|
|
|
Value *Condition = SI.getCondition();
|
2006-08-28 22:44:55 +00:00
|
|
|
|
|
|
|
// Set the EQProperty in each of the cases BBs,
|
|
|
|
// and the NEProperties in the default BB.
|
|
|
|
PropertySet DefaultProperties(KP);
|
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
DTNodeType *Node = PS->DT->getNode(SI.getParent());
|
2006-09-18 21:09:35 +00:00
|
|
|
for (DTNodeType::iterator I = Node->begin(), E = Node->end(); I != E; ++I) {
|
|
|
|
BasicBlock *BB = (*I)->getBlock();
|
2006-08-28 22:44:55 +00:00
|
|
|
|
2006-10-03 15:19:11 +00:00
|
|
|
PropertySet BBProperties(KP);
|
2006-10-12 02:02:44 +00:00
|
|
|
if (BB == SI.getDefaultDest()) {
|
|
|
|
for (unsigned i = 1, e = SI.getNumCases(); i < e; ++i)
|
|
|
|
if (SI.getSuccessor(i) != BB)
|
|
|
|
BBProperties.addNotEqual(Condition, SI.getCaseValue(i));
|
|
|
|
} else if (ConstantInt *CI = SI.findCaseDest(BB)) {
|
2006-10-03 15:19:11 +00:00
|
|
|
BBProperties.addEqual(Condition, CI);
|
|
|
|
}
|
2006-10-12 02:02:44 +00:00
|
|
|
PS->proceedToSuccessor(BBProperties, BB);
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-22 19:53:27 +00:00
|
|
|
void PredicateSimplifier::Forwards::visitAllocaInst(AllocaInst &AI) {
|
|
|
|
KP.addNotEqual(Constant::getNullValue(AI.getType()), &AI);
|
|
|
|
}
|
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
void PredicateSimplifier::Forwards::visitLoadInst(LoadInst &LI) {
|
|
|
|
Value *Ptr = LI.getPointerOperand();
|
2006-08-28 22:44:55 +00:00
|
|
|
KP.addNotEqual(Constant::getNullValue(Ptr->getType()), Ptr);
|
|
|
|
}
|
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
void PredicateSimplifier::Forwards::visitStoreInst(StoreInst &SI) {
|
|
|
|
Value *Ptr = SI.getPointerOperand();
|
2006-08-28 22:44:55 +00:00
|
|
|
KP.addNotEqual(Constant::getNullValue(Ptr->getType()), Ptr);
|
|
|
|
}
|
|
|
|
|
2006-10-12 02:02:44 +00:00
|
|
|
void PredicateSimplifier::Forwards::visitBinaryOperator(BinaryOperator &BO) {
|
|
|
|
Instruction::BinaryOps ops = BO.getOpcode();
|
2006-08-28 22:44:55 +00:00
|
|
|
|
2006-08-30 02:46:48 +00:00
|
|
|
switch (ops) {
|
2006-11-02 01:53:59 +00:00
|
|
|
case Instruction::URem:
|
|
|
|
case Instruction::SRem:
|
2006-10-26 06:15:43 +00:00
|
|
|
case Instruction::UDiv:
|
|
|
|
case Instruction::SDiv:
|
|
|
|
case Instruction::FDiv:
|
2006-11-02 01:53:59 +00:00
|
|
|
case Instruction::FRem: {
|
2006-10-12 02:02:44 +00:00
|
|
|
Value *Divisor = BO.getOperand(1);
|
2006-08-30 02:46:48 +00:00
|
|
|
KP.addNotEqual(Constant::getNullValue(Divisor->getType()), Divisor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-08-28 22:44:55 +00:00
|
|
|
}
|