diff --git a/HowToLoopChainIR/src/ShiftTransformationHowTo.cpp b/HowToLoopChainIR/src/ShiftTransformationHowTo.cpp index e8c2d20..a953381 100644 --- a/HowToLoopChainIR/src/ShiftTransformationHowTo.cpp +++ b/HowToLoopChainIR/src/ShiftTransformationHowTo.cpp @@ -190,16 +190,11 @@ int main(){ */ vector extents; extents.push_back("10"); - extents.push_back("K"); + extents.push_back("5"); extents.push_back("0"); - // Because we have a symbolic, we also need to create a symbolics vector. - vector symbols; - symbols.push_back("K"); - - // Create the transformation - ShiftTransformation transformation(1, extents, symbols); + ShiftTransformation transformation(1, extents ); transformations.push_back( &transformation ); // Apply the transformations @@ -260,33 +255,16 @@ int main(){ // Lets create a dummy transformation that won't be applied to a schedule. vector extents; extents.push_back("11"); - extents.push_back("1+K*K"); - - vector symbols; - symbols.push_back("K"); + extents.push_back("12"); // Create the transformation - ShiftTransformation transformation(1, extents, symbols); + ShiftTransformation transformation(1, extents ); // We can get the id of the loop we will be transforming using getLoopId() cout << "Loop id: " << transformation.getLoopId() << endl; // We can get the extents as a vector using getExtents() - vector gotExtents = transformation.getExtents(); - - cout << "Extents: "; - for( vector::iterator it = gotExtents.begin(); it != gotExtents.end(); it++ ){ - cout << "(" << *it << ") "; - } - cout << endl; - - // We can get the symbols as a vector using getSymbols() - vector gotSymbols = transformation.getSymbols(); - - cout << "Symbols: "; - for( vector::iterator it = gotSymbols.begin(); it != gotSymbols.end(); it++ ){ - cout << "\"" << *it << "\" "; - } - cout << endl; + Tuple gotExtents = transformation.getExtents(); + cout << "Extents: " << gotExtents << endl; } diff --git a/include/LoopChainIR/Subspace.hpp b/include/LoopChainIR/Subspace.hpp index b8ec493..85d8e29 100644 --- a/include/LoopChainIR/Subspace.hpp +++ b/include/LoopChainIR/Subspace.hpp @@ -98,13 +98,13 @@ namespace LoopChainIR { /*! \brief Returns the stage assigned to this Subspace. */ timestamp_t get_stage() const; /*! \brief Returns a string of the iterators at or before the specified stage, with option to use aliases. */ - std::string get_iterators( timestamp_t stage, bool use_aliases ); + std::string get_iterators( timestamp_t stage, bool use_aliases ) const; /*! \brief Returns the index'th iterator, with option to use aliases. */ - std::string get( size_type index, bool use_aliases ); + std::string get( size_type index, bool use_aliases ) const; /*! \brief Returns the index'th iterator, respecting alias state. */ - std::string operator[]( size_type index ); + std::string operator[]( size_type index ) const; /*! \brief Returns true if the subspaces have the same iterators. Aliasing and stage not considered. */ bool operator==( const Subspace that ) const; /*! \brief Returns true if the subspaces do not have the same iterators. Aliasing and stage not considered. */ @@ -159,6 +159,7 @@ namespace LoopChainIR { public: typedef std::vector Container; typedef Container::iterator iterator; + typedef Container::const_iterator const_iterator; protected: typedef std::insert_iterator insert_iterator; @@ -179,43 +180,62 @@ namespace LoopChainIR { iterator begin(); /*! \brief Returns an iterator to the end of the Subspaces. */ iterator end(); + + /*! \brief Returns an iterator to the first Subspace, with option to use aliases. */ + const_iterator begin( bool use_aliases ) const; + /*! \brief Returns an iterator to the first Subspace, respecting alias state of Subspaces */ + const_iterator begin() const; + /*! \brief Returns an iterator to the end of the Subspaces. */ + const_iterator end() const; + /*! \brief Returns an itreator referencing the loops Subspace (typically [loops_c]). */ - iterator get_iterator_to_loops() + iterator get_iterator_to_loops(); /*! \brief Returns an itreator referencing the nests Subspace (typically [i_0,i_1,...m,i_c]). */; iterator get_iterator_to_nest(); /*! \brief Given a pointer to a Subspace this SubspaceManager manages, returns an iterator to it. */ - iterator get_iterator_to_subspace( Subspace* subspace ); + iterator get_iterator_to_subspace( const Subspace* subspace ); /*! \brief Returns a pointer to the loops Subspace. */ Subspace* get_loops(); /*! \brief Returns a pointer to the nests Subspace. */ Subspace* get_nest(); + /*! \brief Returns an itreator referencing the loops Subspace (typically [loops_c]). */ + const_iterator get_iterator_to_loops() const; + /*! \brief Returns an itreator referencing the nests Subspace (typically [i_0,i_1,...m,i_c]). */; + const_iterator get_iterator_to_nest() const; + /*! \brief Given a pointer to a Subspace this SubspaceManager manages, returns an iterator to it. */ + const_iterator get_iterator_to_subspace( const Subspace* subspace ) const; + /*! \brief Returns a pointer to the loops Subspace. */ + const Subspace* get_loops() const; + /*! \brief Returns a pointer to the nests Subspace. */ + const Subspace* get_nest() const; + std::string get_safe_prefix( std::string basic ); iterator insert_left( Subspace* subpsace, iterator cursor ); iterator insert_right( Subspace* subpsace, iterator cursor ); - Subspace::size_type size(); + Subspace::size_type size() const; /*! \brief Returns the current stage. */ - timestamp_t get_current_stage(); + timestamp_t get_current_stage() const; /*! \brief Returns the stage that forms the input iteration space of a function created at this stage. */ - timestamp_t get_input_stage(); + timestamp_t get_input_stage() const; /*! \brief Returns the stage that forms the output iteration space of a function created at this stage. */ - timestamp_t get_output_stage(); + timestamp_t get_output_stage() const; /*! \brief Advances the curent stage forward by one. */ timestamp_t advance_stage(); /*! \brief Advances stage, and unsets alias for all managed subspaces. */ timestamp_t next_stage(); /*! \brief Returns string of iterators for this stage, with option to use aliases. */ - std::string get_iterators( timestamp_t stage, bool use_aliases ); + std::string get_iterators( timestamp_t stage, bool use_aliases ) const; /*! \brief Returns string of iterators for the current stage, respecting all Subspaces alias state. */ - std::string get_iterators( ); + std::string get_iterators( ) const; /*! \brief Returns string of iterators that forms the input iteration space of a function created at this stage, not respecting any Subspaces alias state. */ - std::string get_input_iterators(); + std::string get_input_iterators() const; /*! \brief Returns string of iterators that forms the output iteration space of a function created at this stage, respecting all Subspaces alias state. */ - std::string get_output_iterators(); + std::string get_output_iterators() const; }; } #endif diff --git a/src/Schedule.cpp b/src/Schedule.cpp index 347cab3..c200bb3 100644 --- a/src/Schedule.cpp +++ b/src/Schedule.cpp @@ -207,15 +207,16 @@ IslAstRoot* Schedule::codegenToIslAst(){ isl_ast_build* build = isl_ast_build_alloc(ctx); build = isl_ast_build_set_options( build, separate_map ); - // Create iterator names by the thousands - int dims = 100; - isl_id_list* names = isl_id_list_alloc( ctx, dims ); - for( int d = 0; d < dims; ++d ){ - isl_id* id = isl_id_alloc( ctx, (this->getIteratorPrefix() + to_string(d)).c_str(), NULL ); - names = isl_id_list_add( names, id ); + // Create hundreds of iterator names + { + int dims = 100; + isl_id_list* names = isl_id_list_alloc( ctx, dims ); + for( int d = 0; d < dims; ++d ){ + isl_id* id = isl_id_alloc( ctx, (this->getIteratorPrefix() + to_string(d)).c_str(), NULL ); + names = isl_id_list_add( names, id ); + } + build = isl_ast_build_set_iterators( build, names ); } - build = isl_ast_build_set_iterators( build, names ); - isl_ast_node* tree = isl_ast_build_node_from_schedule_map( build, schedule_map ); @@ -312,7 +313,9 @@ std::string Schedule::codegenToISCC( ) const { for( int i = 1; i < stmt_count; i += 1 ){ os << ((i>1)?"+":"") << "S" << i; } - os << ") );"; + const Subspace* nest = manager.get_nest();; + os << ") ) using { [" << manager.get_input_iterators() << "] -> " + << "separate[" << nest->get( nest->size() , false ) << "] };"; return std::string( os.str() ); } diff --git a/src/Subspace.cpp b/src/Subspace.cpp index 240d0b6..79c0bdf 100644 --- a/src/Subspace.cpp +++ b/src/Subspace.cpp @@ -103,12 +103,12 @@ timestamp_t Subspace::get_stage() const { return this->stage; } -std::string Subspace::get_iterators( timestamp_t stage, bool use_aliases ){ +std::string Subspace::get_iterators( timestamp_t stage, bool use_aliases ) const { ostringstream stream; if( this->get_stage() <= stage ){ bool not_first = false; - for( Subspace::iterator iter = this->begin( use_aliases ); iter != this->end(); ++iter ){ + for( Subspace::const_iterator iter = this->begin( use_aliases ); iter != this->end(); ++iter ){ stream << (not_first?",":"") << *iter ; not_first = true; } @@ -117,7 +117,7 @@ std::string Subspace::get_iterators( timestamp_t stage, bool use_aliases ){ return stream.str(); } -std::string Subspace::get( Subspace::size_type index, bool use_aliases ){ +std::string Subspace::get( Subspace::size_type index, bool use_aliases ) const { if( this->is_aliased() && use_aliases ){ return SSTR( alias_prefix << this->all_iterators[index] ); } else { @@ -126,7 +126,7 @@ std::string Subspace::get( Subspace::size_type index, bool use_aliases ){ } -std::string Subspace::operator[]( size_type index ){ +std::string Subspace::operator[]( size_type index ) const { return this->get( index, this->is_aliased() ); } @@ -241,7 +241,15 @@ SubspaceManager::iterator SubspaceManager::end(){ return this->subspaces.end(); } -SubspaceManager::iterator SubspaceManager::get_iterator_to_subspace( Subspace* subspace ){ +SubspaceManager::const_iterator SubspaceManager::begin() const { + return this->subspaces.begin(); +} + +SubspaceManager::const_iterator SubspaceManager::end() const { + return this->subspaces.end(); +} + +SubspaceManager::iterator SubspaceManager::get_iterator_to_subspace( const Subspace* subspace ){ SubspaceManager::iterator iter = this->subspaces.begin(); while( iter != this->subspaces.end() && *iter != subspace ){ ++iter; @@ -265,6 +273,32 @@ Subspace* SubspaceManager::get_nest(){ return *( this->get_iterator_to_nest() ); } + +SubspaceManager::const_iterator SubspaceManager::get_iterator_to_subspace( const Subspace* subspace ) const { + SubspaceManager::const_iterator iter = this->subspaces.begin(); + while( iter != this->subspaces.end() && *iter != subspace ){ + ++iter; + } + return iter; +} + +SubspaceManager::const_iterator SubspaceManager::get_iterator_to_loops() const { + return this->get_iterator_to_subspace( this->loop ); +} + +SubspaceManager::const_iterator SubspaceManager::get_iterator_to_nest() const { + return this->get_iterator_to_subspace( this->nest ); +} + +const Subspace* SubspaceManager::get_loops() const { + return *( this->get_iterator_to_loops() ); +} + +const Subspace* SubspaceManager::get_nest() const { + return *( this->get_iterator_to_nest() ); +} + + std::string SubspaceManager::get_safe_prefix( std::string base ){ if( this->safe_prefixes.count( base ) == 0 ){ this->safe_prefixes[base] = 1; @@ -289,23 +323,23 @@ SubspaceManager::iterator SubspaceManager::insert_right( Subspace* subspace, Sub return this->insert_left( subspace, std::next(cursor) ); } -Subspace::size_type SubspaceManager::size(){ +Subspace::size_type SubspaceManager::size() const { Subspace::size_type size = 0; - for( Subspace* subspace : *this ){ - size += subspace->complete_size(); + for( SubspaceManager::const_iterator it = this->begin(); it != this->end(); ++it ){ + size += (*it)->complete_size(); } return size; } -timestamp_t SubspaceManager::get_current_stage(){ +timestamp_t SubspaceManager::get_current_stage() const { return this->stage; } -timestamp_t SubspaceManager::get_input_stage(){ +timestamp_t SubspaceManager::get_input_stage() const { return this->get_current_stage(); } -timestamp_t SubspaceManager::get_output_stage() { +timestamp_t SubspaceManager::get_output_stage() const { return this->get_input_stage() + 1; } @@ -321,12 +355,13 @@ timestamp_t SubspaceManager::next_stage(){ return this->advance_stage(); } -std::string SubspaceManager::get_iterators( timestamp_t stage, bool use_aliases ){ +std::string SubspaceManager::get_iterators( timestamp_t stage, bool use_aliases ) const { ostringstream stream; bool not_first = false; - for( Subspace* subspace : *this ){ - std::string subspace_str = subspace->get_iterators( stage, use_aliases ); + for( SubspaceManager::const_iterator it = this->begin(); it != this->end(); ++it ){ + const Subspace* subspace = *it; + std::string subspace_str = subspace->get_iterators( stage, use_aliases ); if( subspace_str != "" ){ stream << (not_first? "," : "") << subspace_str; @@ -338,14 +373,14 @@ std::string SubspaceManager::get_iterators( timestamp_t stage, bool use_aliases return stream.str(); } -std::string SubspaceManager::get_iterators( ){ +std::string SubspaceManager::get_iterators( ) const { return this->get_iterators( this->get_current_stage(), true ); } -std::string SubspaceManager::get_input_iterators(){ +std::string SubspaceManager::get_input_iterators() const { return this->get_iterators( this->get_input_stage(), false ); } -std::string SubspaceManager::get_output_iterators(){ +std::string SubspaceManager::get_output_iterators() const { return this->get_iterators( this->get_output_stage(), true ); }