Passes/PredicateStateAnalysis/OneForAllTD.cpp
// state _between_ BB (inclusive) and Dom (non-inclusive), assuming Dom is either a dominator of BB or nullptr
state _between_ BB (inclusive) and Dom (non-inclusive), assuming Dom is either a dominator of BB or nullptr
state _between_ BB ( inclusive ) and Dom ( non - inclusive ) assuming Dom is either a dominator of BB or nullptr
PredicateState::Ptr OneForAllTD::stateBetween(const llvm::BasicBlock *BB, const llvm::BasicBlock* Dom) {
    auto&& s = betweens[std::make_pair(BB, Dom)];
    if(s) return s;
    ASSERTC(BB != nullptr);
    if(Dom == BB) return s = FN.State->Basic();
    auto res = PredicateStateBuilder(FN.State);
    res += basicPSFor(BB);
    const llvm::BasicBlock* idom = getIDom(BB);
    std::vector<PredicateState::Ptr> choices;
    for(const llvm::BasicBlock* succ: util::view(llvm::succ_begin(BB), llvm::succ_end(BB))) {
        auto succState = PredicateStateBuilder(FN.State);
        std::vector<Predicate::Ptr> phiBlock;
        std::vector<Predicate::Ptr> termBlock;
        auto termPr = TerminatorBranch(BB->getTerminator(), succ);
        for (auto* APA : PA) {
            auto&& map = APA->getTerminatorPredicateMap();
            if (borealis::util::containsKey(map, termPr)) {
                termBlock.push_back(map.at(termPr));
            }
        }
        for(auto&& I : *succ) if(auto* phi = llvm::dyn_cast<llvm::PHINode>(&I)) {
            auto br = PhiBranch(BB, phi);
            for (auto* APA : PA) {
                auto&& map = APA->getPhiPredicateMap();
                if (borealis::util::containsKey(map, br)) {
                    phiBlock.push_back(map.at(br));
                }
            }
        }
        succState += FN.State->Basic(termBlock);
        succState += FN.State->Basic(phiBlock);
        succState += stateBetween(succ, idom);
        choices.push_back(succState.apply());
    }
    switch(choices.size()) {
        case 0: break;
        case 1: res += choices.front(); break;
        default: res += FN.State->Choice(choices); break;
    }
    if(idom != Dom) {
        res  += stateBetween(idom, Dom);
    }
    return s = res.apply();
}
PredicateState :: Ptr OneForAllTD :: stateBetween ( const llvm :: BasicBlock * BB , const llvm :: BasicBlock * Dom ) { auto && s = betweens [ std :: make_pair ( BB , Dom ) ] ; if ( s ) return s ; ASSERTC ( BB != nullptr ) ; if ( Dom == BB ) return s = FN . State -> Basic ( ) ; auto res = PredicateStateBuilder ( FN . State ) ; res += basicPSFor ( BB ) ; const llvm :: BasicBlock * idom = getIDom ( BB ) ; std :: vector < PredicateState :: Ptr > choices ; for ( const llvm :: BasicBlock * succ : util :: view ( llvm :: succ_begin ( BB ) , llvm :: succ_end ( BB ) ) ) { auto succState = PredicateStateBuilder ( FN . State ) ; std :: vector < Predicate :: Ptr > phiBlock ; std :: vector < Predicate :: Ptr > termBlock ; auto termPr = TerminatorBranch ( BB -> getTerminator ( ) , succ ) ; for ( auto * APA : PA ) { auto && map = APA -> getTerminatorPredicateMap ( ) ; if ( borealis :: util :: containsKey ( map , termPr ) ) { termBlock . push_back ( map . at ( termPr ) ) ; } } for ( auto && I : * succ ) if ( auto * phi = llvm :: dyn_cast < llvm :: PHINode > ( & I ) ) { auto br = PhiBranch ( BB , phi ) ; for ( auto * APA : PA ) { auto && map = APA -> getPhiPredicateMap ( ) ; if ( borealis :: util :: containsKey ( map , br ) ) { phiBlock . push_back ( map . at ( br ) ) ; } } } succState += FN . State -> Basic ( termBlock ) ; succState += FN . State -> Basic ( phiBlock ) ; succState += stateBetween ( succ , idom ) ; choices . push_back ( succState . apply ( ) ) ; } switch ( choices . size ( ) ) { case 0 : break ; case 1 : res += choices . front ( ) ; break ; default : res += FN . State -> Choice ( choices ) ; break ; } if ( idom != Dom ) { res += stateBetween ( idom , Dom ) ; } return s = res . apply ( ) ; }
state _between_ BB (inclusive) and Dom (non-inclusive), assuming Dom is either a dominator of BB or nullptr
state _between_ BB ( inclusive ) and Dom ( non - inclusive ) assuming Dom is either a dominator of BB or nullptr