Changeset ec79847


Ignore:
Timestamp:
May 9, 2016, 12:41:50 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
fb24492
Parents:
9e2c1f0
Message:

don't include global init/destroy functions if they're empty, remove all implicit single parameter intrinsic ctor/dtor calls

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixGlobalInit.cc

    r9e2c1f0 rec79847  
    1010// Created On       : Mon May 04 15:14:56 2016
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri May 06 16:14:13 2016
     12// Last Modified On : Mon May 09 11:44:29 2016
    1313// Update Count     : 2
    1414//
     
    9292                GlobalFixer fixer( name, inLibrary );
    9393                acceptAll( translationUnit, fixer );
    94                 translationUnit.push_back( fixer.initFunction );
    95                 translationUnit.push_back( fixer.destroyFunction );
     94                // don't need to include function if it's empty
     95                if ( fixer.initFunction->get_statements()->get_kids().empty() ) {
     96                        delete fixer.initFunction;
     97                } else {
     98                        translationUnit.push_back( fixer.initFunction );
     99                }
     100                if ( fixer.destroyFunction->get_statements()->get_kids().empty() ) {
     101                        delete fixer.destroyFunction;
     102                } else {
     103                        translationUnit.push_back( fixer.destroyFunction );
     104                }
    96105        }
    97106
  • src/InitTweak/FixInit.cc

    r9e2c1f0 rec79847  
    1010// Created On       : Wed Jan 13 16:29:30 2016
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed May 04 14:51:33 2016
     12// Last Modified On : Mon May 09 12:36:02 2016
    1313// Update Count     : 30
    1414//
     
    398398        }
    399399
    400         template<typename Iterator, typename OutputIterator>
    401         void insertDtors( Iterator begin, Iterator end, OutputIterator out ) {
    402                 for ( Iterator it = begin ; it != end ; ++it ) {
    403                         // remove if instrinsic destructor statement. Note that this is only called
    404                         // on lists of implicit dtors, so if the user manually calls an intrinsic
    405                         // dtor then the call will still be generated
    406                         if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( *it ) ) {
    407                                 ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( exprStmt->get_expr() );
    408                                 assert( appExpr );
    409                                 VariableExpr * function = dynamic_cast< VariableExpr * >( appExpr->get_function() );
    410                                 assert( function );
    411                                 // check for Intrinsic only - don't want to remove all overridable dtors because autogenerated dtor
    412                                 // will call all member dtors, and some members may have a user defined dtor.
    413                                 if ( function->get_var()->get_linkage() == LinkageSpec::Intrinsic ) {
    414                                         // don't need to call intrinsic dtor, because it does nothing
    415                                 } else {
     400        bool isInstrinsicSingleArgCallStmt( Statement * stmt ) {
     401                if ( stmt == NULL ) return false;
     402                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( stmt ) ) {
     403                        ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( exprStmt->get_expr() );
     404                        assert( appExpr );
     405                        VariableExpr * function = dynamic_cast< VariableExpr * >( appExpr->get_function() );
     406                        assert( function );
     407                        // check for Intrinsic only - don't want to remove all overridable ctor/dtors because autogenerated ctor/dtor
     408                        // will call all member dtors, and some members may have a user defined dtor.
     409                        FunctionType * funcType = GenPoly::getFunctionType( function->get_var()->get_type() );
     410                        assert( funcType );
     411                        return function->get_var()->get_linkage() == LinkageSpec::Intrinsic && funcType->get_parameters().size() == 1;
     412                } else if ( CompoundStmt * compoundStmt = dynamic_cast< CompoundStmt * >( stmt ) ) {
     413                        // could also be a compound statement with a loop, in the case of an array
     414                        assert( compoundStmt->get_kids().size() == 2 ); // loop variable and loop
     415                        ForStmt * forStmt = dynamic_cast< ForStmt * >( compoundStmt->get_kids().back() );
     416                        assert( forStmt && forStmt->get_body() );
     417                        return isInstrinsicSingleArgCallStmt( forStmt->get_body() );
     418                } else {
     419                        // should never get here
     420                        assert( false && "encountered unknown call statement" );
     421                }
     422        }
     423
     424        namespace {
     425                template<typename Iterator, typename OutputIterator>
     426                void insertDtors( Iterator begin, Iterator end, OutputIterator out ) {
     427                        for ( Iterator it = begin ; it != end ; ++it ) {
     428                                // remove if instrinsic destructor statement. Note that this is only called
     429                                // on lists of implicit dtors, so if the user manually calls an intrinsic
     430                                // dtor then the call will still be generated
     431                                if ( ! isInstrinsicSingleArgCallStmt( *it ) ) {
     432                                        // don't need to call intrinsic dtor, because it does nothing, but
    416433                                        // non-intrinsic dtors must be called
    417434                                        *out++ = (*it)->clone();
    418435                                }
    419                         } else {
    420                                 // could also be a compound statement with a loop, in the case of an array
    421                                 // xxx - write code to remove loop calling intrinsic dtor.
    422                                 *out++ = (*it)->clone();
    423436                        }
    424437                }
    425438        }
    426 
    427439
    428440        CompoundStmt * FixInit::mutate( CompoundStmt * compoundStmt ) {
  • src/InitTweak/FixInit.h

    r9e2c1f0 rec79847  
    1010// Created On       : Wed Jan 13 16:29:30 2016
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jan 13 16:31:13 2016
     12// Last Modified On : Mon May 09 12:08:11 2016
    1313// Update Count     : 5
    1414//
     
    2828  /// and unwrap basic C-style initializers
    2929        void fix( std::list< Declaration * > & translationUnit );
     30
     31  /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
     32  /// Intended to be used for default ctor/dtor calls, but might have use elsewhere.
     33  /// Currently has assertions that make it less than fully general.
     34  bool isInstrinsicSingleArgCallStmt( Statement * expr );
    3035} // namespace
    3136
  • src/ResolvExpr/Resolver.cc

    r9e2c1f0 rec79847  
    1010// Created On       : Sun May 17 12:17:01 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Apr 26 16:08:21 2016
     12// Last Modified On : Mon May 09 12:10:19 2016
    1313// Update Count     : 203
    1414//
     
    2525#include "SymTab/Indexer.h"
    2626#include "Common/utility.h"
     27#include "InitTweak/FixInit.h"
    2728
    2829#include <iostream>
     
    499500                delete ctorInit->get_init();
    500501                ctorInit->set_init( NULL );
     502
     503                // intrinsic single parameter constructors and destructors do nothing. Since this was
     504                // implicitly generated, there's no way for it to have side effects, so get rid of it
     505                // to clean up generated code.
     506                if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
     507                        delete ctorInit->get_ctor();
     508                        ctorInit->set_ctor( NULL );
     509                }
     510                if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
     511                        delete ctorInit->get_dtor();
     512                        ctorInit->set_dtor( NULL );
     513                }
    501514        }
    502515} // namespace ResolvExpr
Note: See TracChangeset for help on using the changeset viewer.