Exemplo n.º 1
0
//! Propagate a data-flow set from caller to callee
OA_ptr<DataFlow::DataFlowSet> 
ManagerICFGDep::callerToCallee(ProcHandle caller,
   OA_ptr<DataFlow::DataFlowSet> dfset, CallHandle call, ProcHandle callee)
{

    
    // new DepDFSet for this stmt
    OA_ptr<DepDFSet> stmtDepDFSet;
    stmtDepDFSet = new DepDFSet;


    //! ===========================================
    //! Iterate over assignment pairs of statement
    //! ===========================================

    OA::OA_ptr<OA::AssignPairIterator> aPairIter;
    aPairIter = mIR->getAssignPairIterator(call);

    for( ; aPairIter->isValid(); ++(*aPairIter)) {

        //! ======== Get the LHS (Defs) of Assignment ========
        OA::MemRefHandle memref = aPairIter->currentTarget();

        //! ======== Get the RHS (Uses) of Assignment ========
        OA::ExprHandle expr = aPairIter->currentSource();


        //! ========
        //! Get Defs
        //! ========
        OA_ptr<Alias::AliasTagSet> aSet = mAlias->getAliasTags(memref);
        OA::OA_ptr<OA::Alias::AliasTagIterator> deftagSetIter;
        deftagSetIter = aSet->getIterator();



        //! ================ Def tagIter =============
        for( deftagSetIter->reset() ; deftagSetIter->isValid();
             ++(*deftagSetIter) ) {


                 //! ============
                 //! Get Uses
                 //! ============

                 //! ======== Get ExprTree for RHS =========
                 OA_ptr<ExprTree> eTree = mIR->getExprTree(expr);

                 CollectMREVisitor evalVisitor;
                 eTree->acceptVisitor(evalVisitor);

                 //! ======= Collect all MREs from ExprTree =========
                 OA::set<OA_ptr<MemRefExpr> > mSet;
                 mSet = evalVisitor.getMemRef();

                 OA::OA_ptr<std::set<OA_ptr<MemRefExpr> > > mSetPtr;
                 mSetPtr = new std::set<OA_ptr<MemRefExpr> >(mSet);

                 OA_ptr<MemRefExprIterator> mreIter;
                 mreIter = new OA::MemRefExprIterator(mSetPtr);



                 //! ============ Use MREIter ==============
                 for( ; mreIter->isValid(); ++(*mreIter) ) {

                     OA::OA_ptr<OA::MemRefExpr> mre;
                     mre = mreIter->current();

                     //! === ignore AddressOf because it is not a Use ===
                     if(mre->isaAddressOf()) {
                        continue;
                     }

                     OA::OA_ptr<OA::Alias::AliasTagSet> mretagSet;
                     OA::OA_ptr<OA::Alias::AliasTagIterator> mretagSetIter;
                     mretagSet = mAlias->getAliasTags(mreIter->current());
                     mretagSetIter = mretagSet->getIterator();

                     //! =============== Use tagIter ==============
                     for( ; mretagSetIter->isValid(); ++(*mretagSetIter)) {

                         //! =============================================
                         //! Create ICFGDep Pair
                         //! =============================================

                         stmtDepDFSet->insertDep(mretagSetIter->current(),
                                                 deftagSetIter->current());



                     } // end mreTagSetIter

                 } // end mreIter

        } // end deftagIter


    } // end aPairIter


    //! =========================================
    //! map stmtDepDFSet to stmt in depResults
    //! =========================================
    mDep->mapCallToDeps(call, stmtDepDFSet);


    return dfset;

}
Exemplo n.º 2
0
OA_ptr<DataFlow::DataFlowSet>
ManagerICFGDep::transfer(ProcHandle proc,
                         OA_ptr<DataFlow::DataFlowSet> in, OA::StmtHandle stmt)
{


    // new DepDFSet for this stmt
    OA_ptr<DepDFSet> stmtDepDFSet;
    stmtDepDFSet = new DepDFSet;


    //! ===========================================
    //! Iterate over assignment pairs of statement
    //! ===========================================

    OA::OA_ptr<OA::AssignPairIterator> aPairIter;
    aPairIter = mIR->getAssignPairIterator(stmt);

    for( ; aPairIter->isValid(); ++(*aPairIter)) {

        //! ======== Get the LHS (Defs) of Assignment ========
        OA::MemRefHandle memref = aPairIter->currentTarget();

        //! ======== Get the RHS (Uses) of Assignment ========
        OA::ExprHandle expr = aPairIter->currentSource();


        //! ========
        //! Get Defs
        //! ========
        OA_ptr<Alias::AliasTagSet> aSet = mAlias->getAliasTags(memref);
        OA::OA_ptr<OA::Alias::AliasTagIterator> deftagSetIter;
        deftagSetIter = aSet->getIterator();



        //! ================ Def tagIter =============
        for( deftagSetIter->reset() ; deftagSetIter->isValid();
             ++(*deftagSetIter) ) {

                 //! =====================================================
                 //! Store Must Defs
                 //!
                 //! Do it here, before going over Uses in RHS ExprHandle.
                 //! because we have pointer assignment statements p=>x
                 //! which is modelled as p=&x.  AddressOf is not a Use
                 //! and therefore we ignore &x for ICFGDep pairs but
                 //! def "p" is Must Def and we dont want to ignore it.
                 //! Thus, process MustDefs before accessing RHS.
                 //! =====================================================

                  if(aSet->isMust()) {
                     mDep->insertMustDefForStmt(stmt,deftagSetIter->current());
                     stmtDepDFSet->removeImplicitDep(deftagSetIter->current(),
                                                     deftagSetIter->current());
                  }

                 //! ============
                 //! Get Uses
                 //! ============

                 //! ======== Get ExprTree for RHS =========
                 OA_ptr<ExprTree> eTree = mIR->getExprTree(expr);

                 CollectMREVisitor evalVisitor;
                 eTree->acceptVisitor(evalVisitor);

                 //! ======= Collect all MREs from ExprTree =========
                 OA::set<OA_ptr<MemRefExpr> > mSet;
                 mSet = evalVisitor.getMemRef();

                 OA::OA_ptr<std::set<OA_ptr<MemRefExpr> > > mSetPtr;
                 mSetPtr = new std::set<OA_ptr<MemRefExpr> >(mSet);

                 OA_ptr<MemRefExprIterator> mreIter;
                 mreIter = new OA::MemRefExprIterator(mSetPtr);



                 //! ============ Use MREIter ==============
                 for( ; mreIter->isValid(); ++(*mreIter) ) {

                     OA::OA_ptr<OA::MemRefExpr> mre;
                     mre = mreIter->current();

                     //! === ignore AddressOf because it is not a Use ===
                     if(mre->isaAddressOf()) {
                        continue;
                     }


                     OA::OA_ptr<OA::Alias::AliasTagSet> mretagSet;
                     OA::OA_ptr<OA::Alias::AliasTagIterator> mretagSetIter;
                     mretagSet = mAlias->getAliasTags(mreIter->current());
                     mretagSetIter = mretagSet->getIterator();

                     //! =============== Use tagIter ==============
                     for( ; mretagSetIter->isValid(); ++(*mretagSetIter)) {

                         //! =============================================
                         //! Create ICFGDep Pair
                         //! =============================================

                         stmtDepDFSet->insertDep(mretagSetIter->current(),
                                                 deftagSetIter->current());

                     } // end mreTagSetIter

                 } // end mreIter

             } // end deftagIter

         } // end aPairIter


         //! =========================================
         //! map stmtDepDFSet to stmt in depResults
         //! =========================================
         mDep->mapStmtToDeps(stmt, stmtDepDFSet);


         return in;

}