Home | History | Annotate | Download | only in Utils

Lines Matching refs:SI

100   bool SimplifySwitch(SwitchInst *SI, IRBuilder<> &Builder);
506 if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
507 Cond = dyn_cast<Instruction>(SI->getCondition());
523 if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
526 if (SI->getNumSuccessors()*std::distance(pred_begin(SI->getParent()),
527 pred_end(SI->getParent())) <= 128)
528 CV = SI->getCondition();
550 if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
551 Cases.reserve(SI->getNumCases());
552 for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end(); i != e; ++i)
555 return SI->getDefaultDest();
668 SwitchInst *SI = cast<SwitchInst>(TI);
679 MDNode* MD = SI->getMetadata(LLVMContext::MD_prof);
680 bool HasWeight = MD && (MD->getNumOperands() == 2 + SI->getNumCases());
688 for (SwitchInst::CaseIt i = SI->case_end(), e = SI->case_begin(); i != e;) {
696 SI->removeCase(i);
700 SI->setMetadata(LLVMContext::MD_prof,
701 MDBuilder(SI->getParent()->getContext()).
734 for (succ_iterator SI = succ_begin(TIBB), e = succ_end(TIBB); SI != e; ++SI)
735 if (*SI != CheckEdge)
736 (*SI)->removePredecessor(TIBB);
842 // Figure out which 'cases' to copy from SI to PSI.
934 // in SI that occur in PSI with a destination of BB will be
1039 for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
1041 for (BasicBlock::iterator BBI = SI->begin();
1135 for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
1137 for (BasicBlock::iterator BBI = SI->begin();
1145 SelectInst *&SI = InsertedSelects[std::make_pair(BB1V, BB2V)];
1146 if (SI == 0)
1147 SI = cast<SelectInst>
1154 PN->setIncomingValue(i, SI);
1159 for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI)
1160 AddPredecessorToBlock(*SI, BIParent, BB1);
2487 static bool SimplifySwitchOnSelect(SwitchInst *SI, SelectInst *Select) {
2496 BasicBlock *TrueBB = SI->findCaseValue(TrueVal).getCaseSuccessor();
2497 BasicBlock *FalseBB = SI->findCaseValue(FalseVal).getCaseSuccessor();
2502 bool HasWeights = HasBranchWeights(SI);
2504 GetBranchWeights(SI, Weights);
2505 if (Weights.size() == 1 + SI->getNumCases()) {
2506 TrueWeight = (uint32_t)Weights[SI->findCaseValue(TrueVal).
2508 FalseWeight = (uint32_t)Weights[SI->findCaseValue(FalseVal).
2514 return SimplifyTerminatorOnSelect(SI, Condition, TrueBB, FalseBB,
2523 static bool SimplifyIndirectBrOnSelect(IndirectBrInst *IBI, SelectInst *SI) {
2525 BlockAddress *TBA = dyn_cast<BlockAddress>(SI->getTrueValue());
2526 BlockAddress *FBA = dyn_cast<BlockAddress>(SI->getFalseValue());
2535 return SimplifyTerminatorOnSelect(IBI, SI->getCondition(), TrueBB, FalseBB,
2574 SwitchInst *SI = cast<SwitchInst>(Pred->getTerminator());
2575 if (SI->getCondition() != V)
2581 if (SI->getDefaultDest() != BB) {
2582 ConstantInt *VVal = SI->findCaseDest(BB);
2597 if (SI->findCaseValue(Cst) != SI->case_default()) {
2636 bool HasWeights = HasBranchWeights(SI);
2638 GetBranchWeights(SI, Weights);
2639 if (Weights.size() == 1 + SI->getNumCases()) {
2645 SI->setMetadata(LLVMContext::MD_prof,
2646 MDBuilder(SI->getContext()).
2650 SI->addCase(Cst, NewBB);
2654 Builder.SetCurrentDebugLocation(SI->getDebugLoc());
2901 if (StoreInst *SI = dyn_cast<StoreInst>(BBI)) {
2902 if (SI->isVolatile())
2955 } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
2956 for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end();
2959 BB->removePredecessor(SI->getParent());
2960 SI->removeCase(i);
2966 if (SI->getDefaultDest() == BB) {
2968 for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end();
2996 SI->setDefaultDest(MaxBlock);
3003 MaxBlock->removePredecessor(SI->getParent());
3005 for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end();
3008 SI->removeCase(i);
3048 static bool TurnSwitchRangeIntoICmp(SwitchInst *SI, IRBuilder<> &Builder) {
3049 assert(SI->getNumCases() > 1 && "Degenerate switch?");
3053 SwitchInst::CaseIt I = SI->case_begin();
3056 for (SwitchInst::CaseIt E = SI->case_end(); I != E; PrevI = I++) {
3061 assert(Cases.size() == SI->getNumCases() && "Not all cases gathered");
3071 Constant *NumCases = ConstantInt::get(Offset->getType(), SI->getNumCases());
3073 Value *Sub = SI->getCondition();
3078 Cmp, SI->case_begin().getCaseSuccessor(), SI->getDefaultDest());
3082 bool HasWeights = HasBranchWeights(SI);
3084 GetBranchWeights(SI, Weights);
3085 if (Weights.size() == 1 + SI->getNumCases()) {
3093 MDBuilder(SI->getContext()).
3100 for (BasicBlock::iterator BBI = SI->case_begin().getCaseSuccessor()->begin();
3102 for (unsigned I = 0, E = SI->getNumCases()-1; I != E; ++I)
3103 cast<PHINode>(BBI)->removeIncomingValue(SI->getParent());
3105 SI->eraseFromParent();
3112 static bool EliminateDeadSwitchCases(SwitchInst *SI) {
3113 Value *Cond = SI->getCondition();
3120 for (SwitchInst::CaseIt I = SI->case_begin(), E = SI->case_end(); I != E; ++I) {
3130 bool HasWeight = HasBranchWeights(SI);
3132 GetBranchWeights(SI, Weights);
3133 HasWeight = (Weights.size() == 1 + SI->getNumCases());
3138 SwitchInst::CaseIt Case = SI->findCaseValue(DeadCases[I]);
3139 assert(Case != SI->case_default() &&
3147 Case.getCaseSuccessor()->removePredecessor(SI->getParent());
3148 SI->removeCase(Case);
3152 SI->setMetadata(LLVMContext::MD_prof,
3153 MDBuilder(SI->getParent()->getContext()).
3198 static bool ForwardSwitchConditionToPHI(SwitchInst *SI) {
3202 for (SwitchInst::CaseIt I = SI->case_begin(), E = SI->case_end(); I != E; ++I) {
3224 Phi->setIncomingValue(Indexes[I], SI->getCondition());
3303 /// case), of a switch instruction SI.
3304 static bool GetCaseResults(SwitchInst *SI,
3310 BasicBlock *Pred = SI
3315 ConstantPool.insert(std::make_pair(SI->getCondition(), CaseVal));
3557 static bool ShouldBuildLookupTable(SwitchInst *SI,
3562 if (SI->getNumCases() > TableSize || TableSize >= UINT64_MAX / 10)
3596 return SI->getNumCases() * 10 >= TableSize * 4;
3602 static bool SwitchToLookupTable(SwitchInst *SI,
3606 assert(SI->getNumCases() > 1 && "Degenerate switch?");
3623 if (SI->getNumCases() < 4)
3628 assert(SI->case_begin() != SI->case_end());
3629 SwitchInst::CaseIt CI = SI->case_begin();
3640 for (SwitchInst::CaseIt E = SI->case_end(); CI != E; ++CI) {
3650 if (!GetCaseResults(SI, CaseVal, CI.getCaseSuccessor(), &CommonDest,
3664 if (!GetCaseResults(SI, 0, SI->getDefaultDest(), &CommonDest,
3676 if (!ShouldBuildLookupTable(SI, TableSize, TTI, TD, ResultTypes))
3688 Builder.SetInsertPoint(SI);
3689 Value *TableIndex = Builder.CreateSub(SI->getCondition(), MinCaseVal,
3693 Builder.CreateCondBr(Cmp, LookupBB, SI->getDefaultDest());
3722 for (unsigned i = 0; i < SI->getNumSuccessors(); ++i) {
3723 BasicBlock *Succ = SI->getSuccessor(i);
3724 if (Succ == SI->getDefaultDest()) continue;
3725 Succ->removePredecessor(SI->getParent());
3727 SI->eraseFromParent();
3733 bool SimplifyCFGOpt::SimplifySwitch(SwitchInst *SI, IRBuilder<> &Builder) {
3734 BasicBlock *BB = SI->getParent();
3736 if (isValueEqualityComparison(SI)) {
3740 if (SimplifyEqualityComparisonWithOnlyPredecessor(SI, OnlyPred, Builder))
3743 Value *Cond = SI->getCondition();
3745 if (SimplifySwitchOnSelect(SI, Select))
3754 if (SI == &*BBI)
3755 if (FoldValueComparisonIntoPredecessors(SI, Builder))
3760 if (TurnSwitchRangeIntoICmp(SI, Builder))
3764 if (EliminateDeadSwitchCases(SI))
3767 if (ForwardSwitchConditionToPHI(SI))
3770 if (SwitchToLookupTable(SI, Builder, TTI, TD))
3806 if (SelectInst *SI = dyn_cast<SelectInst>(IBI->getAddress())) {
3807 if (SimplifyIndirectBrOnSelect(IBI, SI))
3965 if (StoreInst *SI = dyn_cast<StoreInst>(Use))
3966 if (!SI->isVolatile())
3967 return SI->getPointerAddressSpace() == 0 && SI->getPointerOperand() == I;
4051 } else if (SwitchInst *SI = dyn_cast<SwitchInst>(BB->getTerminator())) {
4052 if (SimplifySwitch(SI, Builder)) return true;