23 #define DEBUG_TYPE "reassociate"
46 STATISTIC(NumChanged,
"Number of insts reassociated");
47 STATISTIC(NumAnnihil,
"Number of expr tree annihilated");
48 STATISTIC(NumFactor ,
"Number of multiplies factored");
54 ValueEntry(
unsigned R,
Value *O) : Rank(R), Op(O) {}
56 inline bool operator<(
const ValueEntry &LHS,
const ValueEntry &RHS) {
57 return LHS.Rank > RHS.Rank;
67 << *Ops[0].Op->getType() <<
'\t';
68 for (
unsigned i = 0, e = Ops.
size(); i != e; ++i) {
71 dbgs() <<
", #" << Ops[i].Rank <<
"] ";
83 Factor(
Value *Base,
unsigned Power) : Base(Base), Power(Power) {}
87 bool operator()(
const Factor &LHS,
const Factor &RHS) {
88 return LHS.Base < RHS.Base;
94 bool operator()(
const Factor &LHS,
const Factor &RHS) {
95 return LHS.Base == RHS.Base;
100 struct PowerDescendingSorter {
101 bool operator()(
const Factor &LHS,
const Factor &RHS) {
102 return LHS.Power > RHS.Power;
108 bool operator()(
const Factor &LHS,
const Factor &RHS) {
109 return LHS.Power == RHS.Power;
126 bool isInvalid()
const {
return SymbolicPart == 0; }
127 bool isOrExpr()
const {
return isOr; }
128 Value *getValue()
const {
return OrigVal; }
129 Value *getSymbolicPart()
const {
return SymbolicPart; }
130 unsigned getSymbolicRank()
const {
return SymbolicRank; }
131 const APInt &getConstPart()
const {
return ConstPart; }
133 void Invalidate() { SymbolicPart = OrigVal = 0; }
134 void setSymbolicRank(
unsigned R) { SymbolicRank = R; }
145 struct PtrSortFunctor {
146 bool operator()(XorOpnd *
const &LHS, XorOpnd *
const &RHS) {
147 return LHS->getSymbolicRank() < RHS->getSymbolicRank();
154 unsigned SymbolicRank;
178 unsigned getRank(
Value *V);
187 bool CombineXorOpnd(
Instruction *
I, XorOpnd *Opnd1, XorOpnd *Opnd2,
200 XorOpnd::XorOpnd(
Value *V) {
201 assert(!isa<ConstantInt>(V) &&
"No ConstantInt");
210 if (isa<ConstantInt>(V0))
214 ConstPart =
C->getValue();
229 "Reassociate expressions",
false,
false)
237 if (V->
hasOneUse() && isa<Instruction>(V) &&
238 cast<Instruction>(V)->getOpcode() == Opcode)
239 return cast<BinaryOperator>(V);
246 case Instruction::LandingPad:
247 case Instruction::Alloca:
249 case Instruction::Invoke:
250 case Instruction::UDiv:
251 case Instruction::SDiv:
252 case Instruction::FDiv:
253 case Instruction::URem:
254 case Instruction::SRem:
255 case Instruction::FRem:
258 return !isa<DbgInfoIntrinsic>(
I);
264 void Reassociate::BuildRankMap(
Function &
F) {
269 ValueRankMap[&*I] = ++i;
273 E = RPOT.end(); I != E; ++
I) {
275 unsigned BBRank = RankMap[BB] = ++i << 16;
282 ValueRankMap[&*I] = ++BBRank;
286 unsigned Reassociate::getRank(
Value *V) {
289 if (isa<Argument>(V))
return ValueRankMap[V];
293 if (
unsigned Rank = ValueRankMap[I])
300 unsigned Rank = 0, MaxRank = RankMap[I->getParent()];
301 for (
unsigned i = 0, e = I->getNumOperands();
302 i != e && Rank != MaxRank; ++i)
303 Rank = std::max(Rank, getRank(I->getOperand(i)));
307 if (!I->getType()->isIntegerTy() ||
314 return ValueRankMap[
I] = Rank;
323 BinaryOperator::CreateMul(Neg->
getOperand(1), Cst,
"",Neg);
371 assert(LHS == 1 && RHS == 1 &&
"Weights not reduced!");
376 assert(LHS == 1 && RHS == 1 &&
"Weights not reduced!");
380 if (Opcode == Instruction::Add) {
386 assert(Opcode == Instruction::Mul &&
"Unknown associative operation!");
402 assert(LHS.
ult(Threshold) && RHS.
ult(Threshold) &&
"Weights not reduced!");
405 while (LHS.uge(Threshold))
413 "Weights not reduced!");
415 while (Total >= Threshold)
499 DEBUG(
dbgs() <<
"LINEARIZE: " << *I <<
'\n');
504 "Expected an associative and commutative operation!");
518 bool MadeChange =
false;
542 while (!Worklist.
empty()) {
543 std::pair<BinaryOperator*, APInt>
P = Worklist.
pop_back_val();
546 for (
unsigned OpIdx = 0; OpIdx < 2; ++OpIdx) {
548 APInt Weight = P.second;
549 DEBUG(
dbgs() <<
"OPERAND: " << *Op <<
" (" << Weight <<
")\n");
550 assert(!Op->
use_empty() &&
"No uses, so how did we get to it?!");
555 assert(Visited.
insert(Op) &&
"Not first visit!");
556 DEBUG(
dbgs() <<
"DIRECT ADD: " << *Op <<
" (" << Weight <<
")\n");
557 Worklist.
push_back(std::make_pair(BO, Weight));
562 LeafMap::iterator It = Leaves.find(Op);
563 if (It == Leaves.end()) {
565 assert(Visited.
insert(Op) &&
"Not first visit!");
569 DEBUG(
dbgs() <<
"ADD USES LEAF: " << *Op <<
" (" << Weight <<
")\n");
575 }
else if (It != Leaves.end()) {
577 assert(Visited.
count(Op) &&
"In leaf map but not visited!");
582 #if 0 // TODO: Re-enable once PR13021 is fixed.
585 assert(!Op->
hasOneUse() &&
"Only one use, but we got here twice!");
594 DEBUG(
dbgs() <<
"UNLEAF: " << *Op <<
" (" << It->second <<
")\n");
595 Worklist.
push_back(std::make_pair(BO, It->second));
615 assert((!isa<Instruction>(Op) ||
616 cast<Instruction>(Op)->getOpcode() != Opcode) &&
617 "Should have been handled above!");
618 assert(Op->
hasOneUse() &&
"Has uses outside the expression tree!");
624 DEBUG(
dbgs() <<
"MORPH LEAF: " << *Op <<
" (" << Weight <<
") TO ");
627 Worklist.
push_back(std::make_pair(BO, Weight));
634 DEBUG(
dbgs() <<
"ADD LEAF: " << *Op <<
" (" << Weight <<
")\n");
643 for (
unsigned i = 0, e = LeafOrder.
size(); i != e; ++i) {
644 Value *V = LeafOrder[i];
645 LeafMap::iterator It = Leaves.find(V);
646 if (It == Leaves.end())
650 APInt Weight = It->second;
656 Ops.
push_back(std::make_pair(V, Weight));
664 assert(Identity &&
"Associative operation without identity!");
675 assert(Ops.
size() > 1 &&
"Single values should be used directly!");
703 for (
unsigned i = 0, e = Ops.
size(); i != e; ++i)
704 NotRewritable.
insert(Ops[i].Op);
710 for (
unsigned i = 0; ; ++i) {
714 if (i+2 == Ops.
size()) {
715 Value *NewLHS = Ops[i].Op;
716 Value *NewRHS = Ops[i+1].Op;
720 if (NewLHS == OldLHS && NewRHS == OldRHS)
724 if (NewLHS == OldRHS && NewRHS == OldLHS) {
737 if (NewLHS != OldLHS) {
739 if (BO && !NotRewritable.
count(BO))
740 NodesToRewrite.push_back(BO);
743 if (NewRHS != OldRHS) {
745 if (BO && !NotRewritable.
count(BO))
746 NodesToRewrite.push_back(BO);
751 ExpressionChanged = Op;
760 Value *NewRHS = Ops[i].Op;
770 if (BO && !NotRewritable.
count(BO))
771 NodesToRewrite.push_back(BO);
773 ExpressionChanged = Op;
784 if (BO && !NotRewritable.
count(BO)) {
797 if (NodesToRewrite.empty()) {
800 Undef, Undef,
"", I);
802 NewOp = NodesToRewrite.pop_back_val();
808 ExpressionChanged = Op;
818 if (ExpressionChanged)
821 if (ExpressionChanged == I)
824 ExpressionChanged = cast<BinaryOperator>(*ExpressionChanged->
use_begin());
828 for (
unsigned i = 0, e = NodesToRewrite.size(); i != e; ++i)
829 RedoInsts.insert(NodesToRewrite[i]);
881 if (
Instruction *InstInput = dyn_cast<Instruction>(V)) {
882 if (
InvokeInst *II = dyn_cast<InvokeInst>(InstInput)) {
883 InsertPt = II->getNormalDest()->begin();
885 InsertPt = InstInput;
888 while (isa<PHINode>(InsertPt)) ++InsertPt;
936 BinaryOperator::CreateAdd(Sub->
getOperand(0), NegVal,
"", Sub);
945 DEBUG(
dbgs() <<
"Negated: " << *New <<
'\n');
957 BinaryOperator::CreateMul(Shl->
getOperand(0), MulCst,
"", Shl);
971 unsigned XRank = Ops[i].Rank;
972 unsigned e = Ops.
size();
973 for (
unsigned j = i+1; j != e && Ops[j].Rank == XRank; ++j)
977 for (
unsigned j = i-1; j != ~0U && Ops[j].Rank == XRank; --j)
987 if (Ops.
size() == 1)
return Ops.
back();
992 return BinaryOperator::CreateAdd(V2, V1,
"tmp", I);
998 Value *Reassociate::RemoveFactorFromExpression(
Value *V,
Value *Factor) {
1006 for (
unsigned i = 0, e = Tree.
size(); i != e; ++i) {
1008 Factors.
append(E.second.getZExtValue(),
1009 ValueEntry(getRank(E.first), E.first));
1012 bool FoundFactor =
false;
1013 bool NeedsNegate =
false;
1014 for (
unsigned i = 0, e = Factors.
size(); i != e; ++i) {
1015 if (Factors[i].Op == Factor) {
1022 if (
ConstantInt *FC1 = dyn_cast<ConstantInt>(Factor))
1023 if (
ConstantInt *FC2 = dyn_cast<ConstantInt>(Factors[i].Op))
1024 if (FC1->getValue() == -FC2->getValue()) {
1025 FoundFactor = NeedsNegate =
true;
1033 RewriteExprTree(BO, Factors);
1041 if (Factors.
size() == 1) {
1042 RedoInsts.insert(BO);
1045 RewriteExprTree(BO, Factors);
1081 for (
unsigned i = 0, e = Ops.
size(); i != e; ++i) {
1083 assert(i < Ops.
size());
1098 assert(i < Ops.
size());
1099 if (i+1 != Ops.
size() && Ops[i+1].Op == Ops[i].Op) {
1128 const APInt &ConstOpnd) {
1129 if (ConstOpnd != 0) {
1134 "and.ra", InsertBefore);
1150 bool Reassociate::CombineXorOpnd(
Instruction *I, XorOpnd *Opnd1,
1156 if (Opnd1->isOrExpr() && Opnd1->getConstPart() != 0) {
1157 if (!Opnd1->getValue()->hasOneUse())
1160 const APInt &C1 = Opnd1->getConstPart();
1161 if (C1 != ConstOpnd)
1164 Value *
X = Opnd1->getSymbolicPart();
1169 if (
Instruction *
T = dyn_cast<Instruction>(Opnd1->getValue()))
1170 RedoInsts.insert(
T);
1185 bool Reassociate::CombineXorOpnd(
Instruction *I, XorOpnd *Opnd1, XorOpnd *Opnd2,
1187 Value *X = Opnd1->getSymbolicPart();
1188 if (X != Opnd2->getSymbolicPart())
1192 int DeadInstNum = 1;
1193 if (Opnd1->getValue()->hasOneUse())
1195 if (Opnd2->getValue()->hasOneUse())
1204 if (Opnd1->isOrExpr() != Opnd2->isOrExpr()) {
1205 if (Opnd2->isOrExpr())
1208 const APInt &C1 = Opnd1->getConstPart();
1209 const APInt &C2 = Opnd2->getConstPart();
1210 APInt C3((~C1) ^ C2);
1213 if (C3 != 0 && !C3.isAllOnesValue()) {
1214 int NewInstNum = ConstOpnd != 0 ? 1 : 2;
1215 if (NewInstNum > DeadInstNum)
1222 }
else if (Opnd1->isOrExpr()) {
1225 const APInt &C1 = Opnd1->getConstPart();
1226 const APInt &C2 = Opnd2->getConstPart();
1231 int NewInstNum = ConstOpnd != 0 ? 1 : 2;
1232 if (NewInstNum > DeadInstNum)
1241 const APInt &C1 = Opnd1->getConstPart();
1242 const APInt &C2 = Opnd2->getConstPart();
1249 if (
Instruction *
T = dyn_cast<Instruction>(Opnd1->getValue()))
1250 RedoInsts.insert(
T);
1251 if (
Instruction *
T = dyn_cast<Instruction>(Opnd2->getValue()))
1252 RedoInsts.insert(
T);
1265 if (Ops.
size() == 1)
1270 Type *Ty = Ops[0].Op->getType();
1274 for (
unsigned i = 0, e = Ops.
size(); i != e; ++i) {
1275 Value *V = Ops[i].Op;
1276 if (!isa<ConstantInt>(V)) {
1278 O.setSymbolicRank(getRank(O.getSymbolicPart()));
1281 ConstOpnd ^= cast<ConstantInt>(V)->getValue();
1289 for (
unsigned i = 0, e = Opnds.
size(); i != e; ++i)
1296 std::sort(OpndPtrs.
begin(), OpndPtrs.
end(), XorOpnd::PtrSortFunctor());
1299 XorOpnd *PrevOpnd = 0;
1300 bool Changed =
false;
1301 for (
unsigned i = 0, e = Opnds.
size(); i < e; i++) {
1302 XorOpnd *CurrOpnd = OpndPtrs[i];
1307 if (ConstOpnd != 0 && CombineXorOpnd(I, CurrOpnd, ConstOpnd, CV)) {
1310 *CurrOpnd = XorOpnd(CV);
1312 CurrOpnd->Invalidate();
1317 if (!PrevOpnd || CurrOpnd->getSymbolicPart() != PrevOpnd->getSymbolicPart()) {
1318 PrevOpnd = CurrOpnd;
1325 if (CombineXorOpnd(I, CurrOpnd, PrevOpnd, ConstOpnd, CV)) {
1327 PrevOpnd->Invalidate();
1329 *CurrOpnd = XorOpnd(CV);
1330 PrevOpnd = CurrOpnd;
1332 CurrOpnd->Invalidate();
1342 for (
unsigned int i = 0, e = Opnds.
size(); i < e; i++) {
1343 XorOpnd &O = Opnds[i];
1346 ValueEntry VE(getRank(O.getValue()), O.getValue());
1349 if (ConstOpnd != 0) {
1351 ValueEntry VE(getRank(C), C);
1354 int Sz = Ops.
size();
1356 return Ops.
back().Op;
1358 assert(ConstOpnd == 0);
1377 for (
unsigned i = 0, e = Ops.
size(); i != e; ++i) {
1378 Value *TheOp = Ops[i].Op;
1382 if (i+1 != Ops.
size() && Ops[i+1].Op == TheOp) {
1384 unsigned NumFound = 0;
1388 }
while (i != Ops.
size() && Ops[i].Op == TheOp);
1390 DEBUG(
errs() <<
"\nFACTORING [" << NumFound <<
"]: " << *TheOp <<
'\n');
1395 Mul = BinaryOperator::CreateMul(TheOp, Mul,
"factor", I);
1400 RedoInsts.insert(cast<Instruction>(Mul));
1409 Ops.
insert(Ops.
begin(), ValueEntry(getRank(Mul), Mul));
1426 if (Ops.
size() == 2)
1449 unsigned MaxOcc = 0;
1450 Value *MaxOccVal = 0;
1451 for (
unsigned i = 0, e = Ops.
size(); i != e; ++i) {
1459 assert(Factors.
size() > 1 &&
"Bad linearize!");
1463 for (
unsigned i = 0, e = Factors.
size(); i != e; ++i) {
1464 Value *Factor = Factors[i];
1465 if (!Duplicates.insert(Factor))
continue;
1467 unsigned Occ = ++FactorOccurrences[Factor];
1468 if (Occ > MaxOcc) { MaxOcc = Occ; MaxOccVal = Factor; }
1473 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Factor))
1474 if (CI->isNegative() && !CI->isMinValue(
true)) {
1476 assert(!Duplicates.count(Factor) &&
1477 "Shouldn't have two constant factors, missed a canonicalize");
1479 unsigned Occ = ++FactorOccurrences[Factor];
1480 if (Occ > MaxOcc) { MaxOcc = Occ; MaxOccVal = Factor; }
1487 DEBUG(
errs() <<
"\nFACTORING [" << MaxOcc <<
"]: " << *MaxOccVal <<
'\n');
1494 Instruction *DummyInst = BinaryOperator::CreateAdd(MaxOccVal, MaxOccVal);
1496 for (
unsigned i = 0; i != Ops.
size(); ++i) {
1502 if (
Value *V = RemoveFactorFromExpression(Ops[i].Op, MaxOccVal)) {
1505 for (
unsigned j = Ops.
size(); j != i;) {
1507 if (Ops[j].Op == Ops[i].Op) {
1519 unsigned NumAddedValues = NewMulOps.
size();
1525 assert(NumAddedValues > 1 &&
"Each occurrence should contribute a value");
1526 (void)NumAddedValues;
1528 RedoInsts.insert(VI);
1531 Instruction *
V2 = BinaryOperator::CreateMul(V, MaxOccVal,
"tmp", I);
1535 RedoInsts.insert(V2);
1545 Ops.
insert(Ops.
begin(), ValueEntry(getRank(V2), V2));
1553 struct IsValueInMap {
1558 bool operator()(
const ValueEntry &Entry) {
1559 return Map.
find(Entry.Op) != Map.end();
1579 unsigned FactorPowerSum = 0;
1580 for (
unsigned Idx = 1, Size = Ops.
size(); Idx < Size; ++Idx) {
1581 Value *Op = Ops[Idx-1].Op;
1585 for (; Idx < Size && Ops[Idx].Op == Op; ++Idx)
1589 FactorPowerSum += Count;
1596 if (FactorPowerSum < 4)
1601 for (
unsigned Idx = 1; Idx < Ops.
size(); ++Idx) {
1602 Value *Op = Ops[Idx-1].Op;
1606 for (; Idx < Ops.
size() && Ops[Idx].Op == Op; ++Idx)
1613 FactorPowerSum += Count;
1620 assert(FactorPowerSum >= 4);
1622 std::sort(Factors.
begin(), Factors.
end(), Factor::PowerDescendingSorter());
1629 if (Ops.
size() == 1)
1635 }
while (!Ops.
empty());
1648 assert(Factors[0].Power);
1650 for (
unsigned LastIdx = 0, Idx = 1, Size = Factors.
size();
1651 Idx < Size && Factors[Idx].Power > 0; ++Idx) {
1652 if (Factors[Idx].Power != Factors[LastIdx].Power) {
1661 InnerProduct.
push_back(Factors[LastIdx].Base);
1663 InnerProduct.
push_back(Factors[Idx].Base);
1665 }
while (Idx < Size && Factors[Idx].Power == Factors[LastIdx].Power);
1671 RedoInsts.insert(
MI);
1678 Factor::PowerEqual()),
1684 for (
unsigned Idx = 0, Size = Factors.
size(); Idx != Size; ++Idx) {
1685 if (Factors[Idx].Power & 1)
1686 OuterProduct.
push_back(Factors[Idx].Base);
1687 Factors[Idx].Power >>= 1;
1689 if (Factors[0].Power) {
1690 Value *SquareRoot = buildMinimalMultiplyDAG(Builder, Factors);
1694 if (OuterProduct.
size() == 1)
1695 return OuterProduct.
front();
1712 if (!collectMultiplyFactors(Ops, Factors))
1716 Value *V = buildMinimalMultiplyDAG(Builder, Factors);
1720 ValueEntry NewEntry = ValueEntry(getRank(V), V);
1721 Ops.
insert(std::lower_bound(Ops.
begin(), Ops.
end(), NewEntry), NewEntry);
1731 while (!Ops.
empty() && isa<Constant>(Ops.
back().Op)) {
1748 if (Ops.
size() == 1)
return Ops[0].Op;
1752 unsigned NumOps = Ops.
size();
1762 if (
Value *Result = OptimizeXor(I, Ops))
1766 case Instruction::Add:
1767 if (
Value *Result = OptimizeAdd(I, Ops))
1771 case Instruction::Mul:
1772 if (
Value *Result = OptimizeMul(I, Ops))
1777 if (Ops.
size() != NumOps)
1778 return OptimizeExpression(I, Ops);
1788 ValueRankMap.
erase(I);
1789 RedoInsts.remove(I);
1793 for (
unsigned i = 0, e = Ops.
size(); i != e; ++i)
1794 if (
Instruction *Op = dyn_cast<Instruction>(Ops[i])) {
1797 unsigned Opcode = Op->getOpcode();
1801 RedoInsts.insert(Op);
1809 if (!isa<BinaryOperator>(I))
1812 if (I->
getOpcode() == Instruction::Shl &&
1821 RedoInsts.insert(I);
1832 if (I->
getOpcode() != Instruction::FMul &&
1838 unsigned LHSRank = getRank(LHS);
1839 unsigned RHSRank = getRank(RHS);
1842 if (RHSRank < LHSRank) {
1861 if (I->
getOpcode() == Instruction::Sub) {
1864 RedoInsts.insert(I);
1874 RedoInsts.insert(I);
1894 cast<Instruction>(BO->
use_back())->getOpcode() == Instruction::Sub)
1897 ReassociateExpression(BO);
1908 for (
unsigned i = 0, e = Tree.
size(); i != e; ++i) {
1910 Ops.
append(E.second.getZExtValue(),
1911 ValueEntry(getRank(E.first), E.first));
1922 std::stable_sort(Ops.
begin(), Ops.
end());
1926 if (
Value *V = OptimizeExpression(I, Ops)) {
1932 DEBUG(
dbgs() <<
"Reassoc to scalar: " << *V <<
'\n');
1936 RedoInsts.insert(I);
1946 cast<Instruction>(I->
use_back())->getOpcode() == Instruction::Add &&
1947 isa<ConstantInt>(Ops.
back().Op) &&
1948 cast<ConstantInt>(Ops.
back().Op)->isAllOnesValue()) {
1955 if (Ops.
size() == 1) {
1963 if (
Instruction *OI = dyn_cast<Instruction>(Ops[0].Op))
1965 RedoInsts.insert(I);
1971 RewriteExprTree(I, Ops);
1974 bool Reassociate::runOnFunction(
Function &F) {
1986 assert(II->getParent() == BI &&
"Moved to a different block!");
1991 while (!RedoInsts.empty()) {
2002 ValueRankMap.clear();
void push_back(const T &Elt)
STATISTIC(NumChanged,"Number of insts reassociated")
static PassRegistry * getPassRegistry()
uint64_t getZExtValue() const
Get zero extended value.
static BinaryOperator * LowerNegateToMultiply(Instruction *Neg)
The main container class for the LLVM Intermediate Representation.
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static Constant * getBinOpIdentity(unsigned Opcode, Type *Ty)
void operator<(const Optional< T > &X, const Optional< U > &Y)
Poison comparison between two Optional objects. Clients needs to explicitly compare the underlying va...
iterator insert(iterator I, const T &Elt)
const Function * getParent() const
Return the enclosing method, or null if none.
void setDebugLoc(const DebugLoc &Loc)
setDebugLoc - Set the debug location information for this instruction.
static void FindSingleUseMultiplyFactors(Value *V, SmallVectorImpl< Value * > &Factors, const SmallVectorImpl< ValueEntry > &Ops)
static Constant * getNullValue(Type *Ty)
StringRef getName() const
void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy=true, const Module *Context=0)
static const Value * getNegArgument(const Value *BinOp)
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0)
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
static bool isUnmovableInstruction(Instruction *I)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
FunctionPass * createReassociatePass()
void setName(const Twine &Name)
ID
LLVM Calling Convention Representation.
static Value * OptimizeAndOrXor(unsigned Opcode, SmallVectorImpl< ValueEntry > &Ops)
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
bool count(PtrType Ptr) const
count - Return true if the specified pointer is in the set.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
std::pair< Value *, APInt > RepeatedValue
bool isAssociative() const
static Value * createAndInstr(Instruction *InsertBefore, Value *Opnd, const APInt &ConstOpnd)
bool isFloatingPointTy() const
void replaceAllUsesWith(Value *V)
const char * getOpcodeName() const
static const Value * getNotArgument(const Value *BinOp)
bool ult(const APInt &RHS) const
Unsigned less than comparison.
static Value * buildMultiplyTree(IRBuilder<> &Builder, SmallVectorImpl< Value * > &Ops)
Build a tree of multiplies, computing the product of Ops.
INITIALIZE_PASS(Reassociate,"reassociate","Reassociate expressions", false, false) FunctionPass *llvm
LLVM Basic Block Representation.
LLVM Constant Representation.
static Value * NegateValue(Value *V, Instruction *BI)
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=0)
static Value * EmitAddTreeOfValues(Instruction *I, SmallVectorImpl< WeakVH > &Ops)
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
unsigned getBitWidth() const
Return the number of bits in the APInt.
NUW NUW NUW NUW Exact static Exact BinaryOperator * CreateNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=0)
Value * getOperand(unsigned i) const
bool isCommutative() const
static bool isNot(const Value *V)
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
void append(in_iter in_start, in_iter in_end)
static UndefValue * get(Type *T)
iterator erase(iterator I)
static unsigned CarmichaelShift(unsigned Bitwidth)
std::vector< NodeType * >::reverse_iterator rpo_iterator
BinaryOps getOpcode() const
unsigned getIntegerBitWidth() const
Class for constant integers.
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
const BasicBlock & getEntryBlock() const
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
void initializeReassociatePass(PassRegistry &)
static bool isNeg(const Value *V)
Class for arbitrary precision integers.
bool isMinValue() const
Determine if this is the smallest unsigned value.
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
bool isAllOnesValue() const
Determine if all bits are set.
static BinaryOperator * BreakUpSubtract(Instruction *Sub)
bool isIdempotent() const
static void PrintOps(Instruction *I, const SmallVectorImpl< ValueEntry > &Ops)
static void IncorporateWeight(APInt &LHS, const APInt &RHS, unsigned Opcode)
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
const Type * getScalarType() const
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=0)
unsigned getPrimitiveSizeInBits() const
static int const Threshold
static BinaryOperator * ConvertShiftToMul(Instruction *Shl)
LLVM Value Representation.
static unsigned FindInOperandList(SmallVectorImpl< ValueEntry > &Ops, unsigned i, Value *X)
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
A vector that has set insertion semantics.
void clearSubclassOptionalData()
void moveBefore(Instruction *MovePos)
static BinaryOperator * isReassociableOp(Value *V, unsigned Opcode)
static bool ShouldBreakUpSubtract(Instruction *Sub)
static APInt getNullValue(unsigned numBits)
Get the '0' value.
iterator find(const KeyT &Val)
static Constant * getBinOpAbsorber(unsigned Opcode, Type *Ty)
static bool LinearizeExprTree(BinaryOperator *I, SmallVectorImpl< RepeatedValue > &Ops)
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
const BasicBlock * getParent() const