Home | History | Annotate | Download | only in Utils

Lines Matching refs:SI

105   bool SimplifySwitch(SwitchInst *SI, IRBuilder<> &Builder);
448 if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
449 Cond = dyn_cast<Instruction>(SI->getCondition());
465 if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
468 if (SI->getNumSuccessors()*std::distance(pred_begin(SI->getParent()),
469 pred_end(SI->getParent())) <= 128)
470 CV = SI->getCondition();
490 if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
491 Cases.reserve(SI->getNumCases());
492 for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end(); i != e; ++i)
495 return SI->getDefaultDest();
608 SwitchInst *SI = cast<SwitchInst>(TI);
619 MDNode* MD = SI->getMetadata(LLVMContext::MD_prof);
620 bool HasWeight = MD && (MD->getNumOperands() == 2 + SI->getNumCases());
628 for (SwitchInst::CaseIt i = SI->case_end(), e = SI->case_begin(); i != e;) {
636 SI->removeCase(i);
640 SI->setMetadata(LLVMContext::MD_prof,
641 MDBuilder(SI->getParent()->getContext()).
674 for (succ_iterator SI = succ_begin(TIBB), e = succ_end(TIBB); SI != e; ++SI)
675 if (*SI != CheckEdge)
676 (*SI)->removePredecessor(TIBB);
782 // Figure out which 'cases' to copy from SI to PSI.
874 // in SI that occur in PSI with a destination of BB will be
979 for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
981 for (BasicBlock::iterator BBI = SI->begin();
1061 for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
1063 for (BasicBlock::iterator BBI = SI->begin();
1092 for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
1094 for (BasicBlock::iterator BBI = SI->begin();
1102 SelectInst *&SI = InsertedSelects[std::make_pair(BB1V, BB2V)];
1103 if (SI == 0)
1104 SI = cast<SelectInst>
1111 PN->setIncomingValue(i, SI);
1116 for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI)
1117 AddPredecessorToBlock(*SI, BIParent, BB1);
1340 StoreInst *SI = dyn_cast<StoreInst>(CurI);
1342 if (SI && SI->getPointerOperand() == StorePtr)
1344 return SI->getValueOperand();
1345 else if (SI)
2531 static bool SimplifySwitchOnSelect(SwitchInst *SI, SelectInst *Select) {
2540 BasicBlock *TrueBB = SI->findCaseValue(TrueVal).getCaseSuccessor();
2541 BasicBlock *FalseBB = SI->findCaseValue(FalseVal).getCaseSuccessor();
2546 bool HasWeights = HasBranchWeights(SI);
2548 GetBranchWeights(SI, Weights);
2549 if (Weights.size() == 1 + SI->getNumCases()) {
2550 TrueWeight = (uint32_t)Weights[SI->findCaseValue(TrueVal).
2552 FalseWeight = (uint32_t)Weights[SI->findCaseValue(FalseVal).
2558 return SimplifyTerminatorOnSelect(SI, Condition, TrueBB, FalseBB,
2567 static bool SimplifyIndirectBrOnSelect(IndirectBrInst *IBI, SelectInst *SI) {
2569 BlockAddress *TBA = dyn_cast<BlockAddress>(SI->getTrueValue());
2570 BlockAddress *FBA = dyn_cast<BlockAddress>(SI->getFalseValue());
2579 return SimplifyTerminatorOnSelect(IBI, SI->getCondition(), TrueBB, FalseBB,
2618 SwitchInst *SI = cast<SwitchInst>(Pred->getTerminator());
2619 if (SI->getCondition() != V)
2625 if (SI->getDefaultDest() != BB) {
2626 ConstantInt *VVal = SI->findCaseDest(BB);
2641 if (SI->findCaseValue(Cst) != SI->case_default()) {
2680 bool HasWeights = HasBranchWeights(SI);
2682 GetBranchWeights(SI, Weights);
2683 if (Weights.size() == 1 + SI->getNumCases()) {
2689 SI->setMetadata(LLVMContext::MD_prof,
2690 MDBuilder(SI->getContext()).
2694 SI->addCase(Cst, NewBB);
2698 Builder.SetCurrentDebugLocation(SI->getDebugLoc());
2945 if (StoreInst *SI = dyn_cast<StoreInst>(BBI)) {
2946 if (SI->isVolatile())
2999 } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
3000 for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end();
3003 BB->removePredecessor(SI->getParent());
3004 SI->removeCase(i);
3010 if (SI->getDefaultDest() == BB) {
3012 for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end();
3040 SI->setDefaultDest(MaxBlock);
3047 MaxBlock->removePredecessor(SI->getParent());
3049 for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end();
3052 SI->removeCase(i);
3092 static bool TurnSwitchRangeIntoICmp(SwitchInst *SI, IRBuilder<> &Builder) {
3093 assert(SI->getNumCases() > 1 && "Degenerate switch?");
3097 SwitchInst::CaseIt I = SI->case_begin();
3100 for (SwitchInst::CaseIt E = SI->case_end(); I != E; PrevI = I++) {
3105 assert(Cases.size() == SI->getNumCases() && "Not all cases gathered");
3115 Constant *NumCases = ConstantInt::get(Offset->getType(), SI->getNumCases());
3117 Value *Sub = SI->getCondition();
3122 if (NumCases->isNullValue() && SI->getNumCases() != 0)
3123 Cmp = ConstantInt::getTrue(SI->getContext());
3127 Cmp, SI->case_begin().getCaseSuccessor(), SI->getDefaultDest());
3131 bool HasWeights = HasBranchWeights(SI);
3133 GetBranchWeights(SI, Weights);
3134 if (Weights.size() == 1 + SI->getNumCases()) {
3142 MDBuilder(SI->getContext()).
3149 for (BasicBlock::iterator BBI = SI->case_begin().getCaseSuccessor()->begin();
3151 for (unsigned I = 0, E = SI->getNumCases()-1; I != E; ++I)
3152 cast<PHINode>(BBI)->removeIncomingValue(SI->getParent());
3154 SI->eraseFromParent();
3161 static bool EliminateDeadSwitchCases(SwitchInst *SI) {
3162 Value *Cond = SI->getCondition();
3169 for (SwitchInst::CaseIt I = SI->case_begin(), E = SI->case_end(); I != E; ++I) {
3179 bool HasWeight = HasBranchWeights(SI);
3181 GetBranchWeights(SI, Weights);
3182 HasWeight = (Weights.size() == 1 + SI->getNumCases());
3187 SwitchInst::CaseIt Case = SI->findCaseValue(DeadCases[I]);
3188 assert(Case != SI->case_default() &&
3196 Case.getCaseSuccessor()->removePredecessor(SI->getParent());
3197 SI->removeCase(Case);
3201 SI->setMetadata(LLVMContext::MD_prof,
3202 MDBuilder(SI->getParent()->getContext()).
3247 static bool ForwardSwitchConditionToPHI(SwitchInst *SI) {
3251 for (SwitchInst::CaseIt I = SI->case_begin(), E = SI->case_end(); I != E; ++I) {
3273 Phi->setIncomingValue(Indexes[I], SI->getCondition());
3352 /// case), of a switch instruction SI.
3354 GetCaseResults(SwitchInst *SI,
3360 BasicBlock *Pred = SI->getParent();
3365 ConstantPool.insert(std::make_pair(SI->getCondition(), CaseVal));
3607 static bool ShouldBuildLookupTable(SwitchInst *SI,
3612 if (SI->getNumCases() > TableSize || TableSize >= UINT64_MAX / 10)
3646 return SI->getNumCases() * 10 >= TableSize * 4;
3652 static bool SwitchToLookupTable(SwitchInst *SI,
3656 assert(SI->getNumCases() > 1 && "Degenerate switch?");
3673 if (SI->getNumCases() < 4)
3678 assert(SI->case_begin() != SI->case_end());
3679 SwitchInst::CaseIt CI = SI->case_begin();
3690 for (SwitchInst::CaseIt E = SI->case_end(); CI != E; ++CI) {
3700 if (!GetCaseResults(SI, CaseVal, CI.getCaseSuccessor(), &CommonDest,
3714 if (!GetCaseResults(SI, 0, SI->getDefaultDest(), &CommonDest,
3726 if (!ShouldBuildLookupTable(SI, TableSize, TTI, TD, ResultTypes))
3738 Builder.SetInsertPoint(SI);
3739 Value *TableIndex = Builder.CreateSub(SI->getCondition(), MinCaseVal,
3743 Builder.CreateCondBr(Cmp, LookupBB, SI->getDefaultDest());
3772 for (unsigned i = 0; i < SI->getNumSuccessors(); ++i) {
3773 BasicBlock *Succ = SI->getSuccessor(i);
3774 if (Succ == SI->getDefaultDest()) continue;
3775 Succ->removePredecessor(SI->getParent());
3777 SI->eraseFromParent();
3783 bool SimplifyCFGOpt::SimplifySwitch(SwitchInst *SI, IRBuilder<> &Builder) {
3784 BasicBlock *BB = SI->getParent();
3786 if (isValueEqualityComparison(SI)) {
3790 if (SimplifyEqualityComparisonWithOnlyPredecessor(SI, OnlyPred, Builder))
3793 Value *Cond = SI->getCondition();
3795 if (SimplifySwitchOnSelect(SI, Select))
3804 if (SI == &*BBI)
3805 if (FoldValueComparisonIntoPredecessors(SI, Builder))
3810 if (TurnSwitchRangeIntoICmp(SI, Builder))
3814 if (EliminateDeadSwitchCases(SI))
3817 if (ForwardSwitchConditionToPHI(SI))
3820 if (SwitchToLookupTable(SI, Builder, TTI, TD))
3856 if (SelectInst *SI = dyn_cast<SelectInst>(IBI->getAddress())) {
3857 if (SimplifyIndirectBrOnSelect(IBI, SI))
4015 if (StoreInst *SI = dyn_cast<StoreInst>(Use))
4016 if (!SI->isVolatile())
4017 return SI->getPointerAddressSpace() == 0 && SI->getPointerOperand() == I;
4101 } else if (SwitchInst *SI = dyn_cast<SwitchInst>(BB->getTerminator())) {
4102 if (SimplifySwitch(SI, Builder)) return true;