Changeset 4e2b9710 for src/ResolvExpr


Ignore:
Timestamp:
Aug 25, 2016, 9:14:18 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
a839867
Parents:
c1c1112 (diff), 486341f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg2:software/cfa/cfa-cc

Location:
src/ResolvExpr
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rc1c1112 r4e2b9710  
    244244                for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
    245245                        if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) {
    246                                 alternatives.push_back( Alternative( new MemberExpr( dwt->clone(), expr->clone() ), env, newCost ) );
     246                                alternatives.push_back( Alternative( new MemberExpr( dwt, expr->clone() ), env, newCost ) );
    247247                                renameTypes( alternatives.back().expr );
    248248                        } else {
     
    418418        // /// Map of declaration uniqueIds (intended to be the assertions in an AssertionSet) to their parents and the number of times they've been included
    419419        //typedef std::unordered_map< UniqueId, std::unordered_map< UniqueId, unsigned > > AssertionParentSet;
    420        
     420
    421421        static const int recursionLimit = /*10*/ 4;  ///< Limit to depth of recursion satisfaction
    422422        //static const unsigned recursionParentLimit = 1;  ///< Limit to the number of times an assertion can recursively use itself
     
    429429                }
    430430        }
    431        
     431
    432432        template< typename ForwardIterator, typename OutputIterator >
    433         void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, /*const AssertionParentSet &needParents,*/ 
     433        void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, /*const AssertionParentSet &needParents,*/
    434434                                                 int level, const SymTab::Indexer &indexer, OutputIterator out ) {
    435435                if ( begin == end ) {
     
    469469                                std::cerr << std::endl;
    470470                        )
    471                        
     471
    472472                        AssertionSet newHave, newerNeed( newNeed );
    473473                        TypeEnvironment newEnv( newAlt.env );
     
    847847                for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
    848848                        if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) {
    849                                 alternatives.push_back( Alternative( new OffsetofExpr( aggInst->clone(), dwt->clone() ), env, Cost::zero ) );
     849                                alternatives.push_back( Alternative( new OffsetofExpr( aggInst->clone(), dwt ), env, Cost::zero ) );
    850850                                renameTypes( alternatives.back().expr );
    851851                        } else {
  • src/ResolvExpr/Resolver.cc

    rc1c1112 r4e2b9710  
    446446                } else if ( StructInstType * st = dynamic_cast< StructInstType * >( initContext ) ) {
    447447                        resolveAggrInit( st->get_baseStruct(), iter, end );
    448                 } else if ( UnionInstType *st = dynamic_cast< UnionInstType * >( initContext ) ) {
     448                } else if ( UnionInstType * st = dynamic_cast< UnionInstType * >( initContext ) ) {
    449449                        resolveAggrInit( st->get_baseUnion(), iter, end );
     450                } else if ( TypeInstType * tt = dynamic_cast< TypeInstType * >( initContext ) ) {
     451                        Type * base = tt->get_baseType()->get_base();
     452                        if ( base ) {
     453                                // know the implementation type, so try using that as the initContext
     454                                initContext = base;
     455                                visit( listInit );
     456                        } else {
     457                                // missing implementation type -- might be an unknown type variable, so try proceeding with the current init context
     458                                Visitor::visit( listInit );
     459                        }
    450460                } else {
     461                        assert( dynamic_cast< BasicType * >( initContext ) || dynamic_cast< PointerType * >( initContext ) );
    451462                        // basic types are handled here
    452463                        Visitor::visit( listInit );
     
    539550                }
    540551
    541                 // xxx - todo
    542                 // if ( InitTweak::isIntrinsicCallStmt( ctorInit->get_ctor() ) ) {
    543                 //      // can reduce the constructor down to a SingleInit using the
    544                 //      // second argument from the ctor call
    545                 // }
    546 
    547552                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_dtor() ) ) {
    548553                        delete ctorInit->get_dtor();
    549554                        ctorInit->set_dtor( NULL );
    550555                }
     556
     557                // xxx - todo -- what about arrays?
     558                // if ( dtor == NULL && InitTweak::isIntrinsicCallStmt( ctorInit->get_ctor() ) ) {
     559                //      // can reduce the constructor down to a SingleInit using the
     560                //      // second argument from the ctor call, since
     561                //      delete ctorInit->get_ctor();
     562                //      ctorInit->set_ctor( NULL );
     563
     564                //      Expression * arg =
     565                //      ctorInit->set_init( new SingleInit( arg ) );
     566                // }
    551567        }
    552568} // namespace ResolvExpr
  • src/ResolvExpr/TypeEnvironment.cc

    rc1c1112 r4e2b9710  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TypeEnvironment.cc -- 
     7// TypeEnvironment.cc --
    88//
    99// Author           : Richard C. Bilson
     
    2323
    2424namespace ResolvExpr {
     25        // adding this comparison operator significantly improves assertion resolution run time for
     26        // some cases. The current resolution algorithm's speed partially depends on the order of
     27        // assertions. Assertions which have fewer possible matches should appear before
     28        // assertions which have more possible matches. This seems to imply that this could
     29        // be further improved by providing an indexer as an additional argument and ordering based
     30        // on the number of matches of the same kind (object, function) for the names of the
     31        // declarations.
     32        //
     33        // I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this comparator.
     34        bool AssertCompare::operator()( DeclarationWithType * d1, DeclarationWithType * d2 ) {
     35                        // Objects are always less than functions
     36                        if ( ObjectDecl * objectDecl1 = dynamic_cast< ObjectDecl * >( d1 ) ) {
     37                                if ( ObjectDecl * objectDecl2 = dynamic_cast< ObjectDecl * >( d2 ) ) {
     38                                        // objects are ordered by name then type pointer, in that order
     39                                        int cmp = objectDecl1->get_name().compare( objectDecl2->get_name() );
     40                                        return cmp < 0 ||
     41                                                ( cmp == 0 && objectDecl1->get_type() < objectDecl2->get_type() );
     42                                } else {
     43                                        return true;
     44                                }
     45                        } else if ( FunctionDecl * funcDecl1 = dynamic_cast< FunctionDecl * >( d1 ) ) {
     46                                if ( FunctionDecl * funcDecl2 = dynamic_cast< FunctionDecl * >( d2 ) ) {
     47                                        // functions are ordered by name, # parameters, # returnVals, type pointer in that order
     48                                        FunctionType * ftype1 = funcDecl1->get_functionType();
     49                                        FunctionType * ftype2 = funcDecl2->get_functionType();
     50                                        int numThings1 = ftype1->get_parameters().size() + ftype1->get_returnVals().size();
     51                                        int numThings2 = ftype2->get_parameters().size() + ftype2->get_returnVals().size();
     52                                        if ( numThings1 < numThings2 ) return true;
     53                                        if ( numThings1 > numThings2 ) return false;
     54
     55                                        // if ( ftype1->get_parameters().size() < ftype2->get_parameters().size() ) return true;
     56                                        // else if ( ftype1->get_parameters().size() > ftype2->get_parameters().size() ) return false;
     57                                        // // same number of parameters
     58                                        // if ( ftype1->get_returnVals().size() < ftype2->get_returnVals().size() ) return true;
     59                                        // else if ( ftype1->get_returnVals().size() > ftype2->get_returnVals().size() ) return false;
     60                                        // same number of return vals
     61                                        // int cmp = funcDecl1->get_name().compare( funcDecl2->get_name() );
     62                                        // if ( cmp < 0 ) return true;
     63                                        // else if ( cmp > 0 ) return false;
     64                                        // // same name
     65                                        return ftype1 < ftype2;
     66                                } else {
     67                                        return false;
     68                                }
     69                        } else {
     70                                assert( false );
     71                        }
     72                }
     73
    2574        void printAssertionSet( const AssertionSet &assertions, std::ostream &os, int indent ) {
    2675                for ( AssertionSet::const_iterator i = assertions.begin(); i != assertions.end(); ++i ) {
  • src/ResolvExpr/TypeEnvironment.h

    rc1c1112 r4e2b9710  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // TypeEnvironment.h -- 
     7// TypeEnvironment.h --
    88//
    99// Author           : Richard C. Bilson
     
    2828
    2929namespace ResolvExpr {
    30         typedef std::map< DeclarationWithType*, bool > AssertionSet;
     30        struct AssertCompare {
     31                bool operator()( DeclarationWithType * d1, DeclarationWithType * d2 );
     32        };
     33        typedef std::map< DeclarationWithType*, bool, AssertCompare > AssertionSet;
    3134        typedef std::map< std::string, TypeDecl::Kind > OpenVarSet;
    3235
     
    3942                bool allowWidening;
    4043                TypeDecl::Kind kind;
    41  
     44
    4245                void initialize( const EqvClass &src, EqvClass &dest );
    4346                EqvClass();
     
    6265                void extractOpenVars( OpenVarSet &openVars ) const;
    6366                TypeEnvironment *clone() const { return new TypeEnvironment( *this ); }
    64  
     67
    6568                typedef std::list< EqvClass >::iterator iterator;
    6669                iterator begin() { return env.begin(); }
  • src/ResolvExpr/Unify.cc

    rc1c1112 r4e2b9710  
    484484                FunctionType *otherFunction = dynamic_cast< FunctionType* >( type2 );
    485485                if ( otherFunction && functionType->get_isVarArgs() == otherFunction->get_isVarArgs() ) {
    486 
    487                         if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
    488 
    489                                 if ( unifyDeclList( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), otherFunction->get_returnVals().begin(), otherFunction->get_returnVals().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
    490 
    491                                         markAssertions( haveAssertions, needAssertions, functionType );
    492                                         markAssertions( haveAssertions, needAssertions, otherFunction );
    493 
    494                                         result = true;
     486                        if ( functionType->get_parameters().size() == otherFunction->get_parameters().size() && functionType->get_returnVals().size() == otherFunction->get_returnVals().size() ) {
     487                                if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
     488                                        if ( unifyDeclList( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), otherFunction->get_returnVals().begin(), otherFunction->get_returnVals().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
     489
     490                                                markAssertions( haveAssertions, needAssertions, functionType );
     491                                                markAssertions( haveAssertions, needAssertions, otherFunction );
     492
     493                                                result = true;
     494                                        } // if
    495495                                } // if
    496496                        } // if
Note: See TracChangeset for help on using the changeset viewer.