53 if (
CastInst *CI = dyn_cast<CastInst>(U))
54 if (CI->getOpcode() == Op) {
64 CI->replaceAllUsesWith(Ret);
82 rememberInstruction(Ret);
91 assert((Op == Instruction::BitCast ||
92 Op == Instruction::PtrToInt ||
93 Op == Instruction::IntToPtr) &&
94 "InsertNoopCastOfTo cannot perform non-noop casts!");
96 "InsertNoopCastOfTo cannot change sizes!");
99 if (Op == Instruction::BitCast) {
102 if (
CastInst *CI = dyn_cast<CastInst>(V)) {
103 if (CI->getOperand(0)->getType() == Ty)
104 return CI->getOperand(0);
108 if ((Op == Instruction::PtrToInt || Op == Instruction::IntToPtr) &&
110 if (
CastInst *CI = dyn_cast<CastInst>(V))
111 if ((CI->getOpcode() == Instruction::PtrToInt ||
112 CI->getOpcode() == Instruction::IntToPtr) &&
115 return CI->getOperand(0);
117 if ((CE->getOpcode() == Instruction::PtrToInt ||
118 CE->getOpcode() == Instruction::IntToPtr) &&
121 return CE->getOperand(0);
130 if (
Argument *
A = dyn_cast<Argument>(V)) {
132 while ((isa<BitCastInst>(IP) &&
133 isa<Argument>(cast<BitCastInst>(IP)->getOperand(0)) &&
134 cast<BitCastInst>(IP)->getOperand(0) !=
A) ||
135 isa<DbgInfoIntrinsic>(IP) ||
136 isa<LandingPadInst>(IP))
138 return ReuseOrCreateCast(
A, Ty, Op, IP);
145 IP = II->getNormalDest()->begin();
146 while (isa<PHINode>(IP) || isa<LandingPadInst>(IP))
148 return ReuseOrCreateCast(I, Ty, Op, IP);
156 if (
Constant *CLHS = dyn_cast<Constant>(LHS))
157 if (
Constant *CRHS = dyn_cast<Constant>(RHS))
161 unsigned ScanLimit = 6;
165 if (IP != BlockBegin) {
167 for (; ScanLimit; --IP, --ScanLimit) {
170 if (isa<DbgInfoIntrinsic>(IP))
172 if (IP->getOpcode() == (
unsigned)Opcode && IP->getOperand(0) == LHS &&
173 IP->getOperand(1) == RHS)
175 if (IP == BlockBegin)
break;
181 BuilderType::InsertPointGuard Guard(Builder);
185 if (!L->isLoopInvariant(LHS) || !L->isLoopInvariant(RHS))
break;
186 BasicBlock *Preheader = L->getLoopPreheader();
187 if (!Preheader)
break;
196 rememberInstruction(BO);
209 const SCEV *&Remainder,
232 C->getValue()->getValue().sdiv(
233 FC->getValue()->getValue()));
243 FC->getValue()->getValue())));
251 if (
const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(S)) {
257 if (
const SCEVConstant *
C = dyn_cast<SCEVConstant>(M->getOperand(0)))
269 for (
unsigned i = 0, e = M->getNumOperands(); i != e; ++i) {
270 const SCEV *SOp = M->getOperand(i);
285 const SCEV *Step =
A->getStepRecurrence(SE);
291 const SCEV *Start =
A->getStart();
309 unsigned NumAddRecs = 0;
310 for (
unsigned i = Ops.
size(); i > 0 && isa<SCEVAddRecExpr>(Ops[i-1]); --i)
316 const SCEV *Sum = NoAddRecs.empty() ?
322 if (
const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Sum))
323 Ops.
append(Add->op_begin(), Add->op_end());
324 else if (!Sum->isZero())
327 Ops.
append(AddRecs.begin(), AddRecs.end());
340 for (
unsigned i = 0, e = Ops.
size(); i != e; ++i)
342 const SCEV *Start =
A->getStart();
343 if (Start->
isZero())
break;
346 A->getStepRecurrence(SE),
349 if (
const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Start)) {
351 Ops.
append(Add->op_begin(), Add->op_end());
352 e += Add->getNumOperands();
357 if (!AddRecs.
empty()) {
392 Value *SCEVExpander::expandAddToGEP(
const SCEV *
const *op_begin,
393 const SCEV *
const *op_end,
400 bool AnyNonZeroIndices =
false;
406 Type *IntPtrTy = SE.TD
423 for (
unsigned i = 0, e = Ops.size(); i != e; ++i) {
424 const SCEV *Op = Ops[i];
431 AnyNonZeroIndices =
true;
439 if (!ScaledOps.
empty()) {
456 while (
StructType *STy = dyn_cast<StructType>(ElTy)) {
457 bool FoundFieldNo =
false;
459 if (STy->getNumElements() == 0)
break;
463 if (Ops.empty())
break;
467 uint64_t FullOffset =
C->getValue()->getZExtValue();
472 ElTy = STy->getTypeAtIndex(ElIdx);
475 AnyNonZeroIndices =
true;
482 for (
unsigned i = 0, e = Ops.size(); i != e; ++i)
483 if (
const SCEVUnknown *U = dyn_cast<SCEVUnknown>(Ops[i])) {
486 if (U->isOffsetOf(CTy, FieldNo) && CTy == STy) {
489 STy->getTypeAtIndex(cast<ConstantInt>(FieldNo)->getZExtValue());
491 AnyNonZeroIndices =
true;
501 ElTy = STy->getTypeAtIndex(0u);
507 if (
ArrayType *ATy = dyn_cast<ArrayType>(ElTy))
508 ElTy = ATy->getElementType();
516 if (!AnyNonZeroIndices) {
518 V = InsertNoopCastOfTo(V,
521 assert(!isa<Instruction>(V) ||
528 if (
Constant *CLHS = dyn_cast<Constant>(V))
529 if (
Constant *CRHS = dyn_cast<Constant>(Idx))
533 unsigned ScanLimit = 6;
537 if (IP != BlockBegin) {
539 for (; ScanLimit; --IP, --ScanLimit) {
542 if (isa<DbgInfoIntrinsic>(IP))
544 if (IP->getOpcode() == Instruction::GetElementPtr &&
545 IP->getOperand(0) == V && IP->getOperand(1) == Idx)
547 if (IP == BlockBegin)
break;
552 BuilderType::InsertPointGuard Guard(Builder);
556 if (!L->isLoopInvariant(V) || !L->isLoopInvariant(Idx))
break;
557 BasicBlock *Preheader = L->getLoopPreheader();
558 if (!Preheader)
break;
566 rememberInstruction(GEP);
572 BuilderType::InsertPoint SaveInsertPt = Builder.
saveIP();
576 if (!L->isLoopInvariant(V))
break;
578 bool AnyIndexNotLoopInvariant =
false;
580 E = GepIndices.
end(); I != E; ++
I)
581 if (!L->isLoopInvariant(*I)) {
582 AnyIndexNotLoopInvariant =
true;
585 if (AnyIndexNotLoopInvariant)
588 BasicBlock *Preheader = L->getLoopPreheader();
589 if (!Preheader)
break;
600 Casted = InsertNoopCastOfTo(Casted, PTy);
605 rememberInstruction(GEP);
629 const Loop *SCEVExpander::getRelevantLoop(
const SCEV *S) {
631 std::pair<DenseMap<const SCEV *, const Loop *>::iterator,
bool> Pair =
632 RelevantLoops.insert(std::make_pair(S, static_cast<const Loop *>(0)));
634 return Pair.first->second;
636 if (isa<SCEVConstant>(S))
639 if (
const SCEVUnknown *U = dyn_cast<SCEVUnknown>(S)) {
640 if (
const Instruction *I = dyn_cast<Instruction>(U->getValue()))
652 return RelevantLoops[
N] = L;
655 const Loop *Result = getRelevantLoop(
C->getOperand());
656 return RelevantLoops[
C] = Result;
658 if (
const SCEVUDivExpr *D = dyn_cast<SCEVUDivExpr>(S)) {
661 getRelevantLoop(D->getRHS()),
663 return RelevantLoops[D] = Result;
676 bool operator()(std::pair<const Loop *, const SCEV *> LHS,
677 std::pair<const Loop *, const SCEV *> RHS)
const {
679 if (LHS.second->getType()->isPointerTy() !=
680 RHS.second->getType()->isPointerTy())
681 return LHS.second->getType()->isPointerTy();
684 if (LHS.first != RHS.first)
690 if (LHS.second->isNonConstantNegative()) {
691 if (!RHS.second->isNonConstantNegative())
693 }
else if (RHS.second->isNonConstantNegative())
711 for (std::reverse_iterator<SCEVAddExpr::op_iterator>
I(S->
op_end()),
713 OpsAndLoops.
push_back(std::make_pair(getRelevantLoop(*I), *I));
717 std::stable_sort(OpsAndLoops.
begin(), OpsAndLoops.
end(), LoopCompare(*SE.DT));
723 I = OpsAndLoops.
begin(), E = OpsAndLoops.
end(); I != E; ) {
724 const Loop *CurLoop = I->first;
725 const SCEV *Op = I->second;
730 }
else if (
PointerType *PTy = dyn_cast<PointerType>(Sum->getType())) {
734 for (; I != E && I->first == CurLoop; ++
I) {
737 const SCEV *
X = I->second;
738 if (
const SCEVUnknown *U = dyn_cast<SCEVUnknown>(X))
739 if (!isa<Instruction>(U->getValue()))
743 Sum = expandAddToGEP(NewOps.
begin(), NewOps.
end(), PTy, Ty, Sum);
751 for (++I; I != E && I->first == CurLoop; ++
I)
753 Sum = expandAddToGEP(NewOps.
begin(), NewOps.
end(), PTy, Ty, expand(Op));
757 Sum = InsertNoopCastOfTo(Sum, Ty);
758 Sum = InsertBinop(Instruction::Sub, Sum, W);
763 Sum = InsertNoopCastOfTo(Sum, Ty);
765 if (isa<Constant>(Sum))
std::swap(Sum, W);
766 Sum = InsertBinop(Instruction::Add, Sum, W);
780 for (std::reverse_iterator<SCEVMulExpr::op_iterator>
I(S->
op_end()),
782 OpsAndLoops.
push_back(std::make_pair(getRelevantLoop(*I), *I));
785 std::stable_sort(OpsAndLoops.
begin(), OpsAndLoops.
end(), LoopCompare(*SE.DT));
791 I = OpsAndLoops.
begin(), E = OpsAndLoops.
end(); I != E; ) {
792 const SCEV *Op = I->second;
799 Prod = InsertNoopCastOfTo(Prod, Ty);
805 Prod = InsertNoopCastOfTo(Prod, Ty);
807 if (isa<Constant>(Prod))
std::swap(Prod, W);
808 Prod = InsertBinop(Instruction::Mul, Prod, W);
821 const APInt &RHS =
SC->getValue()->getValue();
823 return InsertBinop(Instruction::LShr, LHS,
828 return InsertBinop(Instruction::UDiv, LHS, RHS);
837 Base =
A->getStart();
840 A->getStepRecurrence(SE),
844 if (
const SCEVAddExpr *
A = dyn_cast<SCEVAddExpr>(Base)) {
845 Base =
A->getOperand(
A->getNumOperands()-1);
847 NewAddOps.
back() = Rest;
858 (isa<CastInst>(IncV) && !isa<BitCastInst>(IncV)))
863 if (L == IVIncInsertLoop) {
865 OE = IncV->
op_end(); OI != OE; ++OI)
866 if (
Instruction *OInst = dyn_cast<Instruction>(OI))
867 if (!SE.DT->
dominates(OInst, IVIncInsertPos))
881 return isNormalAddRecExprPHI(PN, IncV, L);
896 if (IncV == InsertPos)
903 case Instruction::Add:
904 case Instruction::Sub: {
906 if (!OInst || SE.DT->
dominates(OInst, InsertPos))
907 return dyn_cast<Instruction>(IncV->
getOperand(0));
910 case Instruction::BitCast:
912 case Instruction::GetElementPtr:
915 if (isa<Constant>(*I))
917 if (
Instruction *OInst = dyn_cast<Instruction>(*I)) {
931 unsigned AS = cast<PointerType>(IncV->
getType())->getAddressSpace();
950 if (isa<PHINode>(InsertPos)
967 E = IVIncs.
rend(); I != E; ++
I) {
998 PointerType *GEPPtrTy = cast<PointerType>(ExpandTy);
1001 if (!isa<ConstantInt>(StepV))
1004 const SCEV *
const StepArray[1] = { SE.
getSCEV(StepV) };
1005 IncV = expandAddToGEP(StepArray, StepArray+1, GEPPtrTy, IntTy, PN);
1008 rememberInstruction(IncV);
1011 IncV = useSubtract ?
1014 rememberInstruction(IncV);
1023 SCEVExpander::getAddRecExprPHILiterally(
const SCEVAddRecExpr *Normalized,
1027 assert((!IVIncInsertLoop||IVIncInsertPos) &&
"Uninitialized insert position");
1044 if (!isExpandedAddRecExprPHI(PN, IncV, L))
1046 if (L == IVIncInsertLoop && !
hoistIVInc(IncV, IVIncInsertPos))
1050 if (!isNormalAddRecExprPHI(PN, IncV, L))
1052 if (L == IVIncInsertLoop)
1054 if (SE.DT->
dominates(IncV, IVIncInsertPos))
1059 IVIncInsertPos = IncV;
1060 IncV = cast<Instruction>(IncV->
getOperand(0));
1061 }
while (IncV != PN);
1065 InsertedValues.insert(PN);
1067 rememberInstruction(IncV);
1073 BuilderType::InsertPointGuard Guard(Builder);
1083 PostIncLoops.
clear();
1090 assert(!isa<Instruction>(StartV) ||
1111 Twine(IVName) +
".iv");
1112 rememberInstruction(PN);
1130 Value *IncV = expandIVInc(PN, StepV, L, ExpandTy, IntTy, useSubtract);
1131 if (isa<OverflowingBinaryOperator>(IncV)) {
1133 cast<BinaryOperator>(IncV)->setHasNoUnsignedWrap();
1135 cast<BinaryOperator>(IncV)->setHasNoSignedWrap();
1142 PostIncLoops = SavedPostIncLoops;
1145 InsertedValues.insert(PN);
1158 if (PostIncLoops.
count(L)) {
1163 Loops, SE, *SE.DT));
1168 const SCEV *PostLoopOffset = 0;
1170 PostLoopOffset = Start;
1172 Normalized = cast<SCEVAddRecExpr>(
1180 const SCEV *PostLoopScale = 0;
1182 PostLoopScale = Step;
1186 Start, Step, Normalized->
getLoop(),
1192 Type *ExpandTy = PostLoopScale ? IntTy : STy;
1193 PHINode *PN = getAddRecExprPHILiterally(Normalized, L, ExpandTy, IntTy);
1197 if (!PostIncLoops.
count(L))
1202 assert(LatchBlock &&
"PostInc mode requires a unique loop latch!");
1208 if (isa<Instruction>(Result)
1209 && !SE.DT->
dominates(cast<Instruction>(Result),
1227 BuilderType::InsertPointGuard Guard(Builder);
1230 Result = expandIVInc(PN, StepV, L, ExpandTy, IntTy, useSubtract);
1235 if (PostLoopScale) {
1236 assert(S->
isAffine() &&
"Can't linearly scale non-affine recurrences.");
1237 Result = InsertNoopCastOfTo(Result, IntTy);
1240 rememberInstruction(Result);
1244 if (PostLoopOffset) {
1245 if (
PointerType *PTy = dyn_cast<PointerType>(ExpandTy)) {
1246 const SCEV *
const OffsetArray[1] = { PostLoopOffset };
1247 Result = expandAddToGEP(OffsetArray, OffsetArray+1, PTy, IntTy, Result);
1249 Result = InsertNoopCastOfTo(Result, IntTy);
1252 rememberInstruction(Result);
1260 if (!CanonicalMode)
return expandAddRecExprLiterally(S);
1283 BuilderType::InsertPointGuard Guard(Builder);
1284 while (isa<PHINode>(NewInsertPt) || isa<DbgInfoIntrinsic>(NewInsertPt) ||
1285 isa<LandingPadInst>(NewInsertPt))
1302 const SCEV *RestArray[1] = { Rest };
1310 if (!isa<SCEVMulExpr>(Base) && !isa<SCEVUDivExpr>(Base)) {
1311 Value *StartV = expand(Base);
1312 assert(StartV->
getType() == PTy &&
"Pointer type mismatch for GEP!");
1313 return expandAddToGEP(RestArray, RestArray+1, PTy, Ty, StartV);
1330 rememberInstruction(CanonicalIV);
1336 if (!PredSeen.
insert(HP))
1342 Instruction *Add = BinaryOperator::CreateAdd(CanonicalIV, One,
1346 rememberInstruction(Add);
1357 "IVs with types different from the canonical IV should "
1358 "already have been handled!");
1380 const SCEV *NewS = S;
1382 if (isa<SCEVAddRecExpr>(Ext))
1385 const SCEV *V = cast<SCEVAddRecExpr>(NewS)->evaluateAtIteration(IH, SE);
1398 rememberInstruction(I);
1407 rememberInstruction(I);
1416 rememberInstruction(I);
1428 LHS = InsertNoopCastOfTo(LHS, Ty);
1432 rememberInstruction(ICmp);
1434 rememberInstruction(Sel);
1440 LHS = InsertNoopCastOfTo(LHS, S->
getType());
1452 LHS = InsertNoopCastOfTo(LHS, Ty);
1456 rememberInstruction(ICmp);
1458 rememberInstruction(Sel);
1464 LHS = InsertNoopCastOfTo(LHS, S->
getType());
1476 Value *V = expand(SH);
1479 "non-trivial casts should be done with the SCEVs directly!");
1480 V = InsertNoopCastOfTo(V, Ty);
1485 Value *SCEVExpander::expand(
const SCEV *S) {
1499 InsertPt = L->
getHeader()->getFirstInsertionPt();
1506 InsertPt = L->
getHeader()->getFirstInsertionPt();
1509 || isa<DbgInfoIntrinsic>(InsertPt))) {
1517 I = InsertedExpressions.find(std::make_pair(S, InsertPt));
1518 if (I != InsertedExpressions.end())
1521 BuilderType::InsertPointGuard Guard(Builder);
1533 InsertedExpressions[std::make_pair(S, InsertPt)] = V;
1537 void SCEVExpander::rememberInstruction(
Value *I) {
1538 if (!PostIncLoops.
empty())
1539 InsertedPostIncValues.insert(I);
1541 InsertedValues.insert(I);
1551 assert(Ty->
isIntegerTy() &&
"Can only insert integer induction variables!");
1592 unsigned NumElim = 0;
1597 PEnd = Phis.
end(); PIter != PEnd; ++PIter) {
1607 <<
"INDVARS: Eliminated constant iv: " << *Phi <<
'\n');
1621 const SCEV *TruncExpr =
1623 ExprToIVMap[TruncExpr] = Phi;
1643 && !(ChainedPhis.count(Phi)
1644 || isExpandedAddRecExprPHI(OrigPhiRef, OrigInc, L))
1645 && (ChainedPhis.count(Phi)
1646 || isExpandedAddRecExprPHI(Phi, IsomorphicInc, L))) {
1658 if (OrigInc != IsomorphicInc
1659 && TruncExpr == SE.
getSCEV(IsomorphicInc)
1660 && ((isa<PHINode>(OrigInc) && isa<PHINode>(IsomorphicInc))
1663 <<
"INDVARS: Eliminated congruent iv.inc: "
1664 << *IsomorphicInc <<
'\n');
1665 Value *NewInc = OrigInc;
1666 if (OrigInc->
getType() != IsomorphicInc->getType()) {
1673 CreateTruncOrBitCast(OrigInc, IsomorphicInc->
getType(), IVName);
1675 IsomorphicInc->replaceAllUsesWith(NewInc);
1680 <<
"INDVARS: Eliminated congruent iv: " << *Phi <<
'\n');
1682 Value *NewIV = OrigPhiRef;
1715 struct SCEVFindUnsafe {
1721 bool follow(
const SCEV *S) {
1722 if (
const SCEVUDivExpr *D = dyn_cast<SCEVUDivExpr>(S)) {
1730 const SCEV *Step = AR->getStepRecurrence(SE);
1731 if (!AR->isAffine() && !SE.dominates(Step, AR->getLoop()->getHeader())) {
1738 bool isDone()
const {
return IsUnsafe; }
1744 SCEVFindUnsafe Search(SE);
1746 return !Search.IsUnsafe;
NoWrapFlags getNoWrapFlags(NoWrapFlags Mask=NoWrapMask) const
const SCEV * getTruncateOrNoop(const SCEV *V, Type *Ty)
Value * CreateGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
std::reverse_iterator< iterator > reverse_iterator
void push_back(const T &Elt)
bool hoistIVInc(Instruction *IncV, Instruction *InsertPos)
hoistIVInc - Utility for hoisting an IV increment.
static IntegerType * getInt1Ty(LLVMContext &C)
BasicBlock::iterator GetInsertPoint() const
void addIncoming(Value *V, BasicBlock *BB)
LLVM Argument representation.
const SCEV * TransformForPostIncUse(TransformKind Kind, const SCEV *S, Instruction *User, Value *OperandValToReplace, PostIncLoopSet &Loops, ScalarEvolution &SE, DominatorTree &DT)
void SetCurrentDebugLocation(const DebugLoc &L)
Set location information used by debugging information.
const SCEV * getConstant(ConstantInt *V)
LLVMContext & getContext() const
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getNumOperands() const
static Constant * getGetElementPtr(Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false)
static bool FactorOutConstant(const SCEV *&S, const SCEV *&Remainder, const SCEV *Factor, ScalarEvolution &SE, const DataLayout *TD)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
bool mayHaveSideEffects() const
bool properlyDominates(const SCEV *S, const BasicBlock *BB)
bool properlyDominates(const DomTreeNode *A, const DomTreeNode *B) const
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
bool isLoopInvariant(const SCEV *S, const Loop *L)
LoopT * getParentLoop() const
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static IntegerType * getInt64Ty(LLVMContext &C)
Value * visit(const SCEV *S)
void setDebugLoc(const DebugLoc &Loc)
setDebugLoc - Set the debug location information for this instruction.
BlockT * getHeader() const
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
const SCEV * getStart() const
static Constant * getNullValue(Type *Ty)
StringRef getName() const
BlockT * getLoopLatch() const
#define DEBUG_WITH_TYPE(TYPE, X)
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
static const Loop * PickMostRelevantLoop(const Loop *A, const Loop *B, DominatorTree &DT)
const StructLayout * getStructLayout(StructType *Ty) const
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0)
Base class of casting instructions.
NodeTy * getNextNode()
Get the next node, or 0 for the list tail.
const APInt & getValue() const
Return the constant's value.
static bool width_descending(Value *lhs, Value *rhs)
Sort values by integer width for replaceCongruentIVs.
#define llvm_unreachable(msg)
const SCEV *const * op_iterator
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
uint64_t getTypeSizeInBits(Type *Ty) const
op_iterator op_begin() const
Value * CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name="")
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
InsertPoint saveIP() const
Returns the current insert point.
const SCEV * getSizeOfExpr(Type *IntTy, Type *AllocTy)
Loop * getLoopFor(const BasicBlock *BB) const
void replaceAllUsesWith(Value *V)
Type * getEffectiveSCEVType(Type *Ty) const
Type * getElementType() const
const SCEV * getAddRecExpr(const SCEV *Start, const SCEV *Step, const Loop *L, SCEV::NoWrapFlags Flags)
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
size_t getNumOperands() const
uint64_t getElementOffset(unsigned Idx) const
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=0)
Construct any of the CastInst subclasses.
void restoreIP(InsertPoint IP)
Sets the current insert point to a previously-saved location.
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="")
bool isSCEVable(Type *Ty) const
BlockT * getLoopPreheader() const
LLVM Basic Block Representation.
Value * hasConstantValue() const
static void SplitAddRecs(SmallVectorImpl< const SCEV * > &Ops, Type *Ty, ScalarEvolution &SE)
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
LLVM Constant Representation.
const SCEV * getOperand(unsigned i) const
Normalize - Normalize according to the given loops.
Interval::pred_iterator pred_begin(Interval *I)
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=0)
ItTy next(ItTy it, Dist n)
bool contains(const LoopT *L) const
Value * expandCodeFor(const SCEV *SH, Type *Ty, Instruction *I)
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
const SCEV * getLHS() const
static void SimplifyAddOperands(SmallVectorImpl< const SCEV * > &Ops, Type *Ty, ScalarEvolution &SE)
bool dominates(const DomTreeNode *A, const DomTreeNode *B) const
void append(in_iter in_start, in_iter in_end)
static UndefValue * get(Type *T)
bool isNonConstantNegative() const
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
const SCEV * getRHS() const
unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT, SmallVectorImpl< WeakVH > &DeadInsts, const TargetTransformInfo *TTI=NULL)
static void ExposePointerBase(const SCEV *&Base, const SCEV *&Rest, ScalarEvolution &SE)
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
static PointerType * getInt1PtrTy(LLVMContext &C, unsigned AS=0)
Class for constant integers.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
const SCEV * getTruncateExpr(const SCEV *Op, Type *Ty)
unsigned logBase2() const
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
PHINode * getOrInsertCanonicalInductionVariable(const Loop *L, Type *Ty)
bool isAllOnesValue() const
uint64_t getSizeInBytes() const
BasicBlock * GetInsertBlock() const
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
PHINode * getCanonicalInductionVariable() const
unsigned getElementContainingOffset(uint64_t Offset) const
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
ConstantInt * getValue() const
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.
Class for arbitrary precision integers.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="")
const SCEV * getAddExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
void visitAll(const SCEV *Root, SV &Visitor)
Use SCEVTraversal to visit all nodes in the givien expression tree.
Value * CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name="")
static IntegerType * getInt32Ty(LLVMContext &C)
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
static Instruction::CastOps getCastOpcode(const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
Infer the opcode for cast operand and type.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Instruction * getIVIncOperand(Instruction *IncV, Instruction *InsertPos, bool allowScale)
getIVIncOperand - Return the induction variable increment's IV operand.
unsigned getPrimitiveSizeInBits() const
const Loop * getLoop() const
reverse_iterator rbegin()
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
LLVM Value Representation.
const SCEV * getSCEV(Value *V)
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
void moveBefore(Instruction *MovePos)
bool isInsertedInstruction(Instruction *I) const
const SCEV * getUnknown(Value *V)
bool dominates(const SCEV *S, const BasicBlock *BB)
op_iterator op_end() const
const SCEV * getNegativeSCEV(const SCEV *V)
bool hasComputableLoopEvolution(const SCEV *S, const Loop *L)
const SCEV * getNoopOrAnyExtend(const SCEV *V, Type *Ty)
bool isSafeToExpand(const SCEV *S, ScalarEvolution &SE)
Value * CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name="")
const SCEV * getOperand() const
static Constant * getCast(unsigned ops, Constant *C, Type *Ty)
const SCEV * getMulExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
const BasicBlock * getParent() const
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
const SCEV * getAnyExtendExpr(const SCEV *Op, Type *Ty)