diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-17 18:58:56 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-17 18:58:56 -0600 |
commit | bdaf6dc251d98fc1c93165fa8579378204b395e1 (patch) | |
tree | ef961130983342c2615a0a84c8f754a017449312 | |
parent | 8ef3af85585446d897ae292476f433fb6db20c0c (diff) | |
download | chill-bdaf6dc251d98fc1c93165fa8579378204b395e1.tar.gz chill-bdaf6dc251d98fc1c93165fa8579378204b395e1.tar.bz2 chill-bdaf6dc251d98fc1c93165fa8579378204b395e1.zip |
chill doc
-rw-r--r-- | chill/include/chill_error.hh | 6 | ||||
-rw-r--r-- | chill/include/chilldebug.h | 6 | ||||
-rw-r--r-- | chill/include/chillmodule.hh | 15 | ||||
-rw-r--r-- | chill/include/dep.hh | 12 | ||||
-rw-r--r-- | chill/include/graph.hh | 7 | ||||
-rw-r--r-- | chill/include/ir_code.hh | 72 | ||||
-rw-r--r-- | chill/include/ir_rose.hh | 27 | ||||
-rw-r--r-- | chill/include/ir_rose_utils.hh | 6 | ||||
-rw-r--r-- | chill/include/irtools.hh | 13 | ||||
-rw-r--r-- | chill/include/loop.hh | 65 | ||||
-rw-r--r-- | chill/include/omegatools.hh | 103 | ||||
-rw-r--r-- | chill/src/chillmodule.cc | 4 | ||||
-rw-r--r-- | chill/src/ir_rose.cc | 551 | ||||
-rw-r--r-- | chill/src/loop.cc | 11 | ||||
-rw-r--r-- | chill/src/omegatools.cc | 1127 | ||||
-rw-r--r-- | omegalib/code_gen/src/CG_roseRepr.cc | 51 |
16 files changed, 163 insertions, 1913 deletions
diff --git a/chill/include/chill_error.hh b/chill/include/chill_error.hh index dc7432f..ca0936e 100644 --- a/chill/include/chill_error.hh +++ b/chill/include/chill_error.hh @@ -1,17 +1,17 @@ #ifndef CHILL_ERROR_HH #define CHILL_ERROR_HH -// for loop transformation problem +//! for loop transformation problem struct loop_error: public std::runtime_error { loop_error(const std::string &msg): std::runtime_error(msg){} }; -// for generic compiler intermediate code handling problem +//! for generic compiler intermediate code handling problem struct ir_error: public std::runtime_error { ir_error(const std::string &msg): std::runtime_error(msg){} }; -// specific for expression to preburger math translation problem +//! for specific for expression to preburger math translation problem struct ir_exp_error: public ir_error { ir_exp_error(const std::string &msg): ir_error(msg){} }; diff --git a/chill/include/chilldebug.h b/chill/include/chilldebug.h index 4abbb82..865f1f6 100644 --- a/chill/include/chilldebug.h +++ b/chill/include/chilldebug.h @@ -3,9 +3,13 @@ // enable the next line to get lots of output //#define DEBUGCHILL +#ifndef DEBUGCHILL_H +#define DEBUGCHILL_H #ifdef DEBUGCHILL #define DEBUG_PRINT(args...) fprintf(stderr, args ) #else -#define DEBUG_PRINT(args...) /* Don't do anything */ +#define DEBUG_PRINT(args...) do {} while(0) /* Don't do anything */ +#endif + #endif diff --git a/chill/include/chillmodule.hh b/chill/include/chillmodule.hh index 2cb6587..a99db0c 100644 --- a/chill/include/chillmodule.hh +++ b/chill/include/chillmodule.hh @@ -1,19 +1,12 @@ -#ifndef BASIC_CHILLMODULE_HH -#define BASIC_CHILLMODULE_HH -// TODO Python.h defines these and something else does too -#undef _POSIX_C_SOURCE -#undef _XOPEN_SOURCE +#ifndef CHILLMODULE_HH +#define CHILLMODULE_HH #include <Python.h> -// a C routine that will be called from python -//static PyObject * chill_print_code(PyObject *self, PyObject *args); - -//static PyMethodDef ChillMethods[] ; - void finalize_loop(int loop_num_start, int loop_num_end); int get_loop_num_start(); int get_loop_num_end(); -PyMODINIT_FUNC initchill() ; // pass C methods to python +//! pass C methods to python +PyMODINIT_FUNC initchill(); #endif diff --git a/chill/include/dep.hh b/chill/include/dep.hh index 1fa1280..f1cc864 100644 --- a/chill/include/dep.hh +++ b/chill/include/dep.hh @@ -14,9 +14,9 @@ typedef std::vector<DependenceVector> DependenceList; struct DependenceVector { DependenceType type; IR_Symbol *sym; - - bool is_reduction; // used to identify a class of flow dependence - // that can be broken + + bool is_reduction; //!< used to identify a class of flow dependence + //!< that can be broken std::vector<omega::coef_t> lbounds; std::vector<omega::coef_t> ubounds; @@ -29,7 +29,6 @@ struct DependenceVector { quasi = false; is_scalar_dependence = false; } - // DependenceVector(int size); DependenceVector(const DependenceVector &that); ~DependenceVector() {delete sym;} DependenceVector &operator=(const DependenceVector &that); @@ -40,7 +39,7 @@ struct DependenceVector { bool has_been_carried_at(int dim) const; bool has_been_carried_before(int dim) const; - // the following functions will be cleaned up or removed later + // TODO the following functions will be cleaned up or removed later bool isZero() const; bool isPositive() const; bool isNegative() const; @@ -55,7 +54,6 @@ struct DependenceVector { std::vector<DependenceVector> normalize() const; std::vector<DependenceVector> permute(const std::vector<int> &pi) const; DependenceVector reverse() const; - // std::vector<DependenceVector> matrix(const std::vector<std::vector<int> > &M) const; DependenceType getType() const; friend std::ostream& operator<<(std::ostream &os, const DependenceVector &d); }; @@ -72,10 +70,8 @@ public: DependenceGraph() { num_dim_ = 0; } ~DependenceGraph() {} int num_dim() const { return num_dim_; } -// DependenceGraph permute(const std::vector<int> &pi) const; DependenceGraph permute(const std::vector<int> &pi, const std::set<int> &active = std::set<int>()) const; - // DependenceGraph matrix(const std::vector<std::vector<int> > &M) const; DependenceGraph subspace(int dim) const; bool isPositive() const; bool hasPositive(int dim) const; diff --git a/chill/include/graph.hh b/chill/include/graph.hh index f8471df..b67183b 100644 --- a/chill/include/graph.hh +++ b/chill/include/graph.hh @@ -62,7 +62,11 @@ struct Graph { bool hasEdge(int v1, int v2) const; std::vector<EdgeType> getEdge(int v1, int v2) const; + //! Topological sort + /*! This topological sort does handle SCC in graph. */ std::vector<std::set<int> > topoSort() const; + //! Topological sort + /*! This topological sort does not handle SCC in graph. */ std::vector<std::set<int> > packed_topoSort() const; void dump() { @@ -76,7 +80,6 @@ template<typename VertexType, typename EdgeType> std::ostream& operator<<(std::ostream &os, const Graph<VertexType, EdgeType> &g) { for (int i = 0; i < g.vertex.size(); i++) for (typename Graph<VertexType,EdgeType>::EdgeList::const_iterator j = g.vertex[i].second.begin(); j != g.vertex[i].second.end(); j++) { - // os << i+1 << "->" << j->first+1 << ":"; os << "s" << i << "->" << "s" << j->first << ":"; for (typename std::vector<EdgeType>::const_iterator k = j->second.begin(); k != j->second.end(); k++) os << " " << *k; @@ -175,7 +178,6 @@ std::vector<EdgeType> Graph<VertexType,EdgeType>::getEdge(int v1, int v2) const return vertex[v1].second.find(v2)->second; } -// This topological sort does handle SCC in graph. template<typename VertexType, typename EdgeType> std::vector<std::set<int> > Graph<VertexType, EdgeType>::topoSort() const { const int n = vertex.size(); @@ -250,7 +252,6 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::topoSort() const { return result; } -// This topological sort does not handle SCC in graph. template<typename VertexType, typename EdgeType> std::vector<std::set<int> > Graph<VertexType, EdgeType>::packed_topoSort() const { const int n = vertex.size(); diff --git a/chill/include/ir_code.hh b/chill/include/ir_code.hh index 1f853fa..b6ebfcd 100644 --- a/chill/include/ir_code.hh +++ b/chill/include/ir_code.hh @@ -46,8 +46,8 @@ enum IR_ARRAY_LAYOUT_TYPE {IR_ARRAY_LAYOUT_ROW_MAJOR, class IR_Code; -// Base abstract class for scalar and array symbols. This is a place -// holder for related declaration in IR code. +//! Base abstract class for scalar and array symbols. +/*! This is a place holder for related declaration in IR code.*/ struct IR_Symbol { const IR_Code *ir_; @@ -75,8 +75,8 @@ struct IR_ArraySymbol: public IR_Symbol { }; -// Base abstract class for scalar and array references. This is a -// place holder for related code in IR code. +//! Base abstract class for scalar and array references. +/*! This is a place holder for related code in IR code. */ struct IR_Ref { const IR_Code *ir_; @@ -87,7 +87,8 @@ struct IR_Ref { virtual bool operator==(const IR_Ref &that) const = 0; virtual bool operator!=(const IR_Ref &that) const {return !(*this == that);} virtual omega::CG_outputRepr *convert() = 0; - virtual IR_Ref *clone() const = 0; /* shallow copy */ + //! shallow copy + virtual IR_Ref *clone() const = 0; }; @@ -155,20 +156,23 @@ struct IR_ArrayRef: public IR_Ref { struct IR_Block; -// Base abstract class for code structures. This is a place holder -// for the actual structure in the IR code. However, in cases that -// original source code may be transformed during loop initialization -// such as converting a while loop to a for loop or reconstructing the -// loop from low level IR code, the helper loop class (NOT -// IMPLEMENTED) must contain the transformed code that needs to be -// freed when out of service. +//! Base abstract class for code structures. +/*! + * This is a place holder for the actual structure in the IR code. + * However, in cases that original source code may be transformed during + * loop initialization such as converting a while loop to a for loop or + * reconstructing the loop from low level IR code, the helper loop class (NOT + * IMPLEMENTED) must contain the transformed code that needs to be + * freed when out of service. + */ struct IR_Control { const IR_Code *ir_; virtual ~IR_Control() {/* ir_ is not the responsibility of this object */} virtual IR_CONTROL_TYPE type() const = 0; virtual IR_Block *convert() = 0; - virtual IR_Control *clone() const = 0; /* shallow copy */ + //! shallow copy + virtual IR_Control *clone() const = 0; }; @@ -208,7 +212,7 @@ struct IR_While: public IR_Control { }; -// Abstract class for compiler IR. +//! Abstract class for compiler IR. class IR_Code { protected: omega::CG_outputBuilder *ocg_; @@ -217,10 +221,14 @@ protected: public: IR_Code() {ocg_ = NULL; init_code_ = cleanup_code_ = NULL;} - virtual ~IR_Code() { delete ocg_; delete init_code_; delete cleanup_code_; } /* the content of init and cleanup code have already been released in derived classes */ + virtual ~IR_Code() { delete ocg_; delete init_code_; delete cleanup_code_; } + /* the content of init and cleanup code have already been released in derived classes */ - // memory_type is for differentiating the location of where the new memory is allocated. - // this is useful for processors with heterogeneous memory hierarchy. + /*! + * \param memory_type is for differentiating the location of + * where the new memory is allocated. this is useful for + * processors with heterogeneous memory hierarchy. + */ virtual IR_ScalarSymbol *CreateScalarSymbol(const IR_Symbol *sym, int memory_type) = 0; virtual IR_ArraySymbol *CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outputRepr *> &size, int memory_type) = 0; @@ -228,19 +236,28 @@ public: virtual IR_ArrayRef *CreateArrayRef(const IR_ArraySymbol *sym, std::vector<omega::CG_outputRepr *> &index) = 0; virtual int ArrayIndexStartAt() {return 0;} - // Array references should be returned in their accessing order. - // e.g. s1: A[i] = A[i-1] - // s2: B[C[i]] = D[i] + E[i] - // return A[i-1], A[i], D[i], E[i], C[i], B[C[i]] in this order. + /*! + * Array references should be returned in their accessing order. + * + * ~~~ + * e.g. s1: A[i] = A[i-1] + * s2: B[C[i]] = D[i] + E[i] + * return A[i-1], A[i], D[i], E[i], C[i], B[C[i]] in this order. + * ~~~ + */ virtual std::vector<IR_ArrayRef *> FindArrayRef(const omega::CG_outputRepr *repr) const = 0; virtual std::vector<IR_ScalarRef *> FindScalarRef(const omega::CG_outputRepr *repr) const = 0; - // If there is no sub structure interesting inside the block, return empty, - // so we know when to stop looking inside. + /*! + * If there is no sub structure interesting inside the block, return empty, + * so we know when to stop looking inside. + */ virtual std::vector<IR_Control *> FindOneLevelControlStructure(const IR_Block *block) const = 0; - // All controls must be in the same block, at the same level and in - // contiguous lexical order as appeared in parameter vector. + /*! + * All controls must be in the same block, at the same level and in + * contiguous lexical order as appeared in parameter vector. + */ virtual IR_Block *MergeNeighboringControlStructures(const std::vector<IR_Control *> &controls) const = 0; virtual IR_Block *GetCode() const = 0; @@ -252,12 +269,9 @@ public: virtual std::vector<omega::CG_outputRepr *> QueryExpOperand(const omega::CG_outputRepr *repr) const = 0; virtual IR_Ref *Repr2Ref(const omega::CG_outputRepr *repr) const = 0; - //--------------------------------------------------------------------------- - // CC Omega code builder interface here - //--------------------------------------------------------------------------- + //! Codegen Omega code builder interface omega::CG_outputBuilder *builder() const {return ocg_;} }; #endif - diff --git a/chill/include/ir_rose.hh b/chill/include/ir_rose.hh index 0c0417a..9e94dea 100644 --- a/chill/include/ir_rose.hh +++ b/chill/include/ir_rose.hh @@ -236,28 +236,6 @@ public: std::map<SgVarRefExp*, IR_ScalarRef*> &read_scalars_1, std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1, std::set<std::string> &indices, std::vector<std::string> &index); - // std::set<std::string> &def_vars); - /*void findDefinitions(SgStatementPtrList &list_1, - std::set<VirtualCFG::CFGNode> &reaching_defs_1, - std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1, - std::set<std::string> &def_vars); - */ - /* void checkDependency(SgStatementPtrList &output_list_1, - std::vector<DependenceVector> &dvs1, - std::map<SgVarRefExp*, IR_ScalarRef*> &read_scalars_1, - std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1, - std::vector<std::string> &index, int i, int j); - void checkSelfDependency(SgStatementPtrList &output_list_1, - std::vector<DependenceVector> &dvs1, - std::map<SgVarRefExp*, IR_ScalarRef*> &read_scalars_1, - std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1, - std::vector<std::string> &index, int i, int j); - void checkWriteDependency(SgStatementPtrList &output_list_1, - std::vector<DependenceVector> &dvs1, - std::map<SgVarRefExp*, IR_ScalarRef*> &read_scalars_1, - std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1, - std::vector<std::string> &index, int i, int j); - */ std::vector<IR_ArrayRef *> FindArrayRef( const omega::CG_outputRepr *repr) const; std::vector<IR_ScalarRef *> FindScalarRef( @@ -276,11 +254,6 @@ public: std::vector<omega::CG_outputRepr *> QueryExpOperand( const omega::CG_outputRepr *repr) const; IR_Ref *Repr2Ref(const omega::CG_outputRepr *) const; - /* std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > - FindScalarDeps(const omega::CG_outputRepr *repr1, - const omega::CG_outputRepr *repr2, std::vector<std::string> index, - int i, int j); - */ void finalizeRose(); friend class IR_roseArraySymbol; friend class IR_roseArrayRef; diff --git a/chill/include/ir_rose_utils.hh b/chill/include/ir_rose_utils.hh index 9e98aee..d6749de 100644 --- a/chill/include/ir_rose_utils.hh +++ b/chill/include/ir_rose_utils.hh @@ -2,15 +2,11 @@ #define IR_ROSE_UTILS_HH #include <vector> #include <rose.h> -#include "sageBuilder.h" - - +#include <sageBuilder.h> std::vector<SgForStatement *> find_deepest_loops(SgNode *tnl); std::vector<SgForStatement *> find_loops(SgNode *tnl); - - SgNode* loop_body_at_level(SgNode* tnl, int level); SgNode* loop_body_at_level(SgForStatement* loop, int level); void swap_node_for_node_list(SgNode* tn, SgNode* new_tnl); diff --git a/chill/include/irtools.hh b/chill/include/irtools.hh index 8dc8e28..205efe1 100644 --- a/chill/include/irtools.hh +++ b/chill/include/irtools.hh @@ -7,15 +7,18 @@ #include "ir_code.hh" #include "dep.hh" -// IR tree is used to initialize a loop. For a loop node, payload is -// its mapped iteration space dimension. For a simple block node, -// payload is its mapped statement number. Normal if-else is splitted -// into two nodes where the one with odd payload represents then-part and -// the one with even payload represents else-part. +//! It is used to initialize a loop. struct ir_tree_node { IR_Control *content; ir_tree_node *parent; std::vector<ir_tree_node *> children; +/*! + * * For a loop node, payload is its mapped iteration space dimension. + * * For a simple block node, payload is its mapped statement number. + * * Normal if-else is splitted into two nodes + * * the one with odd payload represents then-part and + * * the one with even payload represents else-part. + */ int payload; ~ir_tree_node() { diff --git a/chill/include/loop.hh b/chill/include/loop.hh index f227bb5..2c50d6b 100644 --- a/chill/include/loop.hh +++ b/chill/include/loop.hh @@ -17,17 +17,21 @@ enum TilingMethodType { StridedTile, CountedTile }; enum LoopLevelType { LoopLevelOriginal, LoopLevelTile, LoopLevelUnknown }; -// Describes properties of each loop level of a statement. "payload" -// for LoopLevelOriginal means iteration space dimension, for -// LoopLevelTile means tiled loop level. Special value -1 for -// LoopLevelTile means purely derived loop. For dependence dimension -// payloads, the values must be in an increasing order. -// "parallel_level" will be used by code generation to support -// multi-level parallelization (default 0 means sequential loop under -// the current parallelization level). +//! Describes properties of each loop level of a statement. struct LoopLevel { LoopLevelType type; +/*! + * For LoopLevelOriginal means iteration space dimension + * For LoopLevelTile means tiled loop level. Special value -1 for + * LoopLevelTile means purely derived loop. For dependence dimension + * payloads, the values must be in an increasing order. + */ int payload; +/*! + * Used by code generation to support + * multi-level parallelization (default 0 means sequential loop under + * the current parallelization level). + */ int parallel_level; }; @@ -107,14 +111,16 @@ public: std::vector<std::set <int > > sort_by_same_loops(std::set<int > active, int level); // - // legacy unimodular transformations for perfectly nested loops - // e.g. M*(i,j)^T = (i',j')^T or M*(i,j,1)^T = (i',j')^T - // + //! legacy unimodular transformations for perfectly nested loops + /*! + * e.g. \f$M*(i,j)^T = (i',j')^T or M*(i,j,1)^T = (i',j')^T\f$ + */ bool nonsingular(const std::vector<std::vector<int> > &M); - // - // high-level loop transformations - // + /*! + * \defgroup hltrans High-level loop transformations + * @{ + */ void permute(const std::set<int> &active, const std::vector<int> &pi); void permute(int stmt_num, int level, const std::vector<int> &pi); void permute(const std::vector<int> &pi); @@ -129,8 +135,6 @@ public: bool datacopy_privatized(int stmt_num, int level, const std::string &array_name, const std::vector<int> &privatized_levels, bool allow_extra_read = false, int fastest_changing_dimension = -1, int padding_stride = 1, int padding_alignment = 1, int memory_type = 0); bool datacopy_privatized(const std::vector<std::pair<int, std::vector<int> > > &array_ref_nums, int level, const std::vector<int> &privatized_levels, bool allow_extra_read = false, int fastest_changing_dimension = -1, int padding_stride = 1, int padding_alignment = 1, int memory_type = 0); bool datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_ArrayRef *> > > &stmt_refs, int level, const std::vector<int> &privatized_levels, bool allow_extra_read, int fastest_changing_dimension, int padding_stride, int padding_alignment, int memory_type = 0); - //std::set<int> scalar_replacement_inner(int stmt_num); - Graph<std::set<int>, bool> construct_induced_graph_at_level(std::vector<std::set<int> > s, DependenceGraph dep, int dep_dim); @@ -142,26 +146,35 @@ public: void scale(const std::set<int> &stmt_nums, int level, int scale_amount); void reverse(const std::set<int> &stmt_nums, int level); void peel(int stmt_num, int level, int peel_amount = 1); - // - // more fancy loop transformations - // + /*! + * \defgroup hlfancy fancy loop transformations + * @{ + */ void modular_shift(int stmt_num, int level, int shift_amount) {} void diagonal_map(int stmt_num, const std::pair<int, int> &levels, int offset) {} void modular_partition(int stmt_num, int level, int stride) {} + /*! @} */ - // - // derived loop transformations - // + /*! + * \defgroup hlderived derived loop transformations + * @{ + */ + void shift_to(int stmt_num, int level, int absolute_position); std::set<int> unroll_extra(int stmt_num, int level, int unroll_amount, int cleanup_split_level = 0); bool is_dependence_valid_based_on_lex_order(int i, int j, const DependenceVector &dv, bool before); - // - // other public operations - // + /*! @} */ + + /*! + * \defgroup hlother other public operations + * @{ + */ void pragma(int stmt_num, int level, const std::string &pragmaText); void prefetch(int stmt_num, int level, const std::string &arrName, int hint); - //void prefetch(int stmt_num, int level, const std::string &arrName, const std::string &indexName, int offset, int hint); + /*! @} */ + + /*! @} */ }; diff --git a/chill/include/omegatools.hh b/chill/include/omegatools.hh index 206079c..f77a376 100644 --- a/chill/include/omegatools.hh +++ b/chill/include/omegatools.hh @@ -8,90 +8,81 @@ std::string tmp_e(); +//! Convert expression tree to omega relation. +/*! + * \param destroy shallow deallocation of "repr", not freeing the actual code inside. + */ void exp2formula(IR_Code *ir, omega::Relation &r, omega::F_And *f_root, std::vector<omega::Free_Var_Decl *> &freevars, omega::CG_outputRepr *repr, omega::Variable_ID lhs, char side, IR_CONDITION_TYPE rel, bool destroy); + +//! Build dependence relation for two array references. omega::Relation arrays2relation(IR_Code *ir, std::vector<omega::Free_Var_Decl*> &freevars, const IR_ArrayRef *ref_src, const omega::Relation &IS_w, const IR_ArrayRef *ref_dst, const omega::Relation &IS_r); +//! Convert array dependence relation into set of dependence vectors +/*! + * assuming ref_w is lexicographically before ref_r in the source code. + */ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relation2dependences( const IR_ArrayRef *ref_src, const IR_ArrayRef *ref_dst, const omega::Relation &r); +//! Convert a boolean expression to omega relation. +/*! + * \param destroy shallow deallocation of "repr", not freeing the actual code inside. + */ void exp2constraint(IR_Code *ir, omega::Relation &r, omega::F_And *f_root, std::vector<omega::Free_Var_Decl *> &freevars, omega::CG_outputRepr *repr, bool destroy); -// suif legacy code -// void suif2formula(Relation &r, F_And *f_root, -// std::vector<Free_Var_Decl*> &freevars, -// operand op, Variable_ID lhs, -// char side, char rel); -// void suif2formula(Relation &r, F_And *f_root, -// std::vector<Free_Var_Decl*> &freevars, -// instruction *ins, Variable_ID lhs, -// char side, char rel); -// void add_loop_stride_constraints(omega::Relation &r, omega::F_And *f_root, -// std::vector<omega::Free_Var_Decl*> &freevars, -// tree_for *tnf, char side); -// void add_loop_bound_constraints(IR_Code *ir, omega::Relation &r, omega::F_And *f_root, -// std::vector<omega::Free_Var_Decl*> &freevars, -// tree_for *tnf, -// char upper_or_lower, char side, IR_CONDITION_TYPE rel); -// Relation loop_iteration_space(std::vector<Free_Var_Decl*> &freevars, -// tree_node *tn, std::vector<tree_for*> &loops); - -// Relation arrays2relation(std::vector<Free_Var_Decl*> &freevars, -// in_array *ia_w, const Relation &IS1, -// in_array *ia_r, const Relation &IS2); -// std::vector<DependenceVector> relation2dependences(IR_Code *ir, in_array *ia_w, -// in_array *ia_r, const Relation &r); - -// end of suif legacy code - bool is_single_iteration(const omega::Relation &r, int dim); +//! Set/get the value of a variable which is know to be constant. void assign_const(omega::Relation &r, int dim, int val); + int get_const(const omega::Relation &r, int dim, omega::Var_Kind type); + +//! Find the position index variable in a Relation by name. omega::Variable_ID find_index(omega::Relation &r, const std::string &s, char side); + +//! Generate mapping relation for permuation. omega::Relation permute_relation(const std::vector<int> &pi); + omega::Relation get_loop_bound(const omega::Relation &r, int dim); + +//! Determine whether the loop (starting from 0) in the iteration space has only one iteration. bool is_single_loop_iteration(const omega::Relation &r, int level, const omega::Relation &known); +//! Get the bound for a specific loop. omega::Relation get_loop_bound(const omega::Relation &r, int level, const omega::Relation &known); omega::Relation get_max_loop_bound(const std::vector<omega::Relation> &r, int dim); omega::Relation get_min_loop_bound(const std::vector<omega::Relation> &r, int dim); + +//! Add strident to a loop. +/*! + * Issues: + * + * * Don't work with relations with multiple disjuncts. + * * Omega's dealing with max lower bound is awkward. + */ void add_loop_stride(omega::Relation &r, const omega::Relation &bound, int dim, int stride); bool is_inner_loop_depend_on_level(const omega::Relation &r, int level, const omega::Relation &known); -// void adjust_loop_bound(omega::Relation &r, int dim, int adjustment, std::vector<omega::Free_Var_Decl *> globals = std::vector<omega::Free_Var_Decl *>()); +/*! + * Suppose loop dim is i. Replace i with i+adjustment in loop bounds. + * + * ~~~ + * do i = 1, n + * do j = i, n + * ~~~ + * + * after call with dim = 0 and adjustment = 1: + * + * ~~~ + * do i = 1, n + * do j = i+1, n + * ~~~ + */ omega::Relation adjust_loop_bound(const omega::Relation &r, int level, int adjustment); -// void adjust_loop_bound(Relation &r, int dim, int adjustment); -// void adjust_loop_bound(Relation &r, int dim, Free_Var_Decl *global_var, int adjustment); -// boolean is_private_statement(const omega::Relation &r, int dim); - -// coef_t mod(const Relation &r, Variable_ID v, int dividend); - enum LexicalOrderType {LEX_MATCH, LEX_BEFORE, LEX_AFTER, LEX_UNKNOWN}; -// template <typename T> -// LexicalOrderType lexical_order(const std::vector<T> &a, const std::vector<T> &b) { -// int size = min(a.size(), b.size()); -// for (int i = 0; i < size; i++) { -// if (a[i] < b[i]) -// return LEX_BEFORE; -// else if (b[i] < a[i]) -// return LEX_AFTER; -// } -// if (a.size() < b.size()) -// return LEX_BEFORE; -// else if (b.size() < a.size()) -// return LEX_AFTER; -// else -// return LEX_MATCH; -// } - -// struct LoopException { -// std::string descr; -// LoopException(const std::string &s): descr(s) {}; -// }; - #endif diff --git a/chill/src/chillmodule.cc b/chill/src/chillmodule.cc index 36f810e..b7012cc 100644 --- a/chill/src/chillmodule.cc +++ b/chill/src/chillmodule.cc @@ -17,10 +17,6 @@ #include "chillmodule.hh" -#undef _POSIX_C_SOURCE -#undef _XOPEN_SOURCE -#include <Python.h> - using namespace omega; extern Loop *myloop; diff --git a/chill/src/ir_rose.cc b/chill/src/ir_rose.cc index dc11b4c..36e2db9 100644 --- a/chill/src/ir_rose.cc +++ b/chill/src/ir_rose.cc @@ -232,12 +232,6 @@ IR_Ref *IR_roseConstantRef::clone() const { // ---------------------------------------------------------------------------- bool IR_roseScalarRef::is_write() const { - /* if (ins_pos_ != NULL && op_pos_ == -1) - return true; - else - return false; - */ - if (is_write_ == 1) return true; @@ -270,11 +264,7 @@ omega::CG_outputRepr *IR_roseScalarRef::convert() { } IR_Ref * IR_roseScalarRef::clone() const { - //if (ins_pos_ == NULL) return new IR_roseScalarRef(ir_, vs_, this->is_write_); - //else - // return new IR_roseScalarRef(ir_, , op_pos_); - } // ---------------------------------------------------------------------------- @@ -684,12 +674,11 @@ omega::CG_outputRepr *IR_roseBlock::original() const { } } tnl = new omega::CG_roseRepr(bb); - //block = tnl->clone(); - + } else { + tnl = new omega::CG_roseRepr(tnl_); - - //block = tnl->clone(); + } return tnl; @@ -744,19 +733,6 @@ omega::CG_outputRepr *IR_roseIf::condition() const { SgExpression* exp = NULL; if (SgExprStatement* stmt = isSgExprStatement(tnl)) exp = stmt->get_expression(); - /* - SgExpression *op = iter(tnl); - if (iter.is_empty()) - throw ir_error("unrecognized if structure"); - tree_node *tn = iter.step(); - if (!iter.is_empty()) - throw ir_error("unrecognized if structure"); - if (!tn->is_instr()) - throw ir_error("unrecognized if structure"); - instruction *ins = static_cast<tree_instr *>(tn)->instr(); - if (!ins->opcode() == io_bfalse) - throw ir_error("unrecognized if structure"); - operand op = ins->src_op(0);*/ if (exp == NULL) return new omega::CG_roseRepr(tnl); else @@ -766,13 +742,8 @@ omega::CG_outputRepr *IR_roseIf::condition() const { IR_Block *IR_roseIf::then_body() const { SgNode *tnl = isSgNode(isSgIfStmt(ti_)->get_true_body()); - //tree_node_list *tnl = ti_->then_part(); if (tnl == NULL) return NULL; - /* - tree_node_list_iter iter(tnl); - if (iter.is_empty()) - return NULL; */ return new IR_roseBlock(ir_, tnl); } @@ -780,28 +751,14 @@ IR_Block *IR_roseIf::then_body() const { IR_Block *IR_roseIf::else_body() const { SgNode *tnl = isSgNode(isSgIfStmt(ti_)->get_false_body()); - //tree_node_list *tnl = ti_->else_part(); - if (tnl == NULL) return NULL; - /* - tree_node_list_iter iter(tnl); - if (iter.is_empty()) - return NULL;*/ return new IR_roseBlock(ir_, tnl); } IR_Block *IR_roseIf::convert() { const IR_Code *ir = ir_; - /* SgNode *tnl = ti_->get_parent(); - SgNode *start, *end; - start = end = ti_; - - //tree_node_list *tnl = ti_->parent(); - //tree_node_list_e *start, *end; - //start = end = ti_->list_e(); - */ delete this; return new IR_roseBlock(ir, ti_); } @@ -842,8 +799,6 @@ IR_roseCode::IR_roseCode(const char *filename, const char* proc_name) : strcpy(argv[1], filename); project = (IR_roseCode_Global_Init::Instance(argv))->project; - //main_ssa = new ssa_unfiltered_cfg::SSA_UnfilteredCfg(project); - //main_ssa->run(); firstScope = getFirstGlobalScope(project); SgFilePtrList& file_list = project->get_fileList(); @@ -855,12 +810,6 @@ IR_roseCode::IR_roseCode(const char *filename, const char* proc_name) : else is_fortran_ = false; - // Manu:: debug - // if (is_fortran_) - // std::cout << "Input is a fortran file\n"; - // else - // std::cout << "Input is a C file\n"; - root = file->get_globalScope(); if (!is_fortran_) { // Manu:: this macro should not be created if the input code is in fortran @@ -894,7 +843,6 @@ IR_roseCode::IR_roseCode(const char *filename, const char* proc_name) : symtab2_ = func->get_definition()->get_symbol_table(); symtab3_ = func->get_definition()->get_body()->get_symbol_table(); - // ocg_ = new omega::CG_roseBuilder(func->get_definition()->get_body()->get_symbol_table() , isSgNode(func->get_definition()->get_body())); // Manu:: added is_fortran_ parameter ocg_ = new omega::CG_roseBuilder(is_fortran_, root, firstScope, func->get_definition()->get_symbol_table(), @@ -912,14 +860,8 @@ IR_roseCode::~IR_roseCode() { } void IR_roseCode::finalizeRose() { - // Moved this out of the deconstructor - // ???? SgProject* project = (IR_roseCode_Global_Init::Instance(NULL))->project; - // -- Causes coredump. commented out for now -- // - // processes attributes left in Rose Ast - //postProcessRoseCodeInsertion(project); project->unparse(); - //backend((IR_roseCode_Global_Init::Instance(NULL))->project); } IR_ScalarSymbol *IR_roseCode::CreateScalarSymbol(const IR_Symbol *sym, int) { @@ -1088,16 +1030,7 @@ IR_ArrayRef *IR_roseCode::CreateArrayRef(const IR_ArraySymbol *sym, ia1 = buildPntrArrRefExp(ia1,exprLstExp); } else { for (int i = 0; i < index.size(); i++) { -/* - if (is_fortran_) - t = index.size() - i - 1; - else - t = i; -*/ - - // std::string y = - // isSgNode( - // static_cast<omega::CG_roseRepr *>(index[i])->GetExpression())->unparseToString(); + ia1 = buildPntrArrRefExp(ia1, static_cast<omega::CG_roseRepr *>(index[i])->GetExpression()); @@ -1105,7 +1038,6 @@ IR_ArrayRef *IR_roseCode::CreateArrayRef(const IR_ArraySymbol *sym, } SgPntrArrRefExp *ia = isSgPntrArrRefExp(ia1); - //std::string z = isSgNode(ia)->unparseToString(); return new IR_roseArrayRef(this, ia, -1); @@ -1188,14 +1120,6 @@ std::vector<IR_ScalarRef *> IR_roseCode::FindScalarRef( static_cast<const omega::CG_roseRepr *>(repr)->GetExpression(); if (isSgVarRefExp(op) && (!isSgArrayType(isSgVarRefExp(op)->get_type()))) { - /* if ((isSgAssignOp(isSgNode(op)->get_parent())) - && ((isSgAssignOp(isSgNode(op)->get_parent())->get_lhs_operand()) - == op)) - scalars.push_back( - new IR_roseScalarRef(this, - isSgAssignOp(isSgNode(op)->get_parent()), -1)); - else - */ if (SgBinaryOp* op_ = isSgBinaryOp( isSgVarRefExp(op)->get_parent())) { if (SgCompoundAssignOp *op__ = isSgCompoundAssignOp(op_)) { @@ -1359,30 +1283,6 @@ std::vector<IR_ArrayRef *> IR_roseCode::FindArrayRef( } } - /* base = isSgVarRefExp(op); - SgVariableSymbol *arrSymbol = (SgVariableSymbol*)(base->get_symbol()); - SgArrayType *arrType = isSgArrayType(arrSymbol->get_type()); - - SgExprListExp* dimList = arrType->get_dim_info(); - - if(dimList != NULL){ - SgExpressionPtrList::iterator it = dimList->get_expressions().begin(); - SgExpression *expr; - - - for (int i = 0; it != dimList->get_expressions().end(); it++, i++) - { - expr = *it; - - omega::CG_roseRepr *r = new omega::CG_roseRepr(expr); - std::vector<IR_ArrayRef *> a = FindArrayRef(r); - delete r; - std::copy(a.begin(), a.end(), back_inserter(arrays)); - } - - } - arrays.push_back(ref); - */ } else if (isSgAssignOp(op)) { omega::CG_roseRepr *r1 = new omega::CG_roseRepr( isSgAssignOp(op)->get_lhs_operand()); @@ -1416,54 +1316,6 @@ std::vector<IR_ArrayRef *> IR_roseCode::FindArrayRef( } return arrays; - - /* std::string x; - SgStatement* stmt = isSgStatement(tnl); - SGExprStatement* expr_statement = isSgExprStatement(stmt); - SgExpression* exp= NULL; - if(expr_statement == NULL){ - if(! (SgExpression* exp = isSgExpression(tnl)) - throw ir_error("FindArrayRef: Not a stmt nor an expression!!"); - - if( expr_statement != NULL){ - for(int i=0; i < tnl->get_numberOfTraversalSuccessors(); i++){ - - SgNode* tn = isSgStatement(tnl); - SgStatement* stmt = isSgStatement(tn); - if(stmt != NULL){ - SgExprStatement* expr_statement = isSgExprStatement(tn); - if(expr_statement != NULL) - x = isSgNode(expr_statement)->unparseToString(); - exp = expr_statement->get_expression(); - - } - else{ - - exp = isSgExpression(tn); - } - if(exp != NULL){ - x = isSgNode(exp)->unparseToString(); - - if(SgPntrArrRefExp* arrRef = isSgPntrArrRefExp(exp) ){ - if(arrRef == NULL) - throw ir_error("something wrong"); - IR_roseArrayRef *ref = new IR_roseArrayRef(this, arrRef); - arrays.push_back(ref); - } - - omega::CG_outputRepr *r = new omega::CG_roseRepr(isSgNode(exp->get_rhs_operand())); - std::vector<IR_ArrayRef *> a = FindArrayRef(r); - delete r; - std::copy(a.begin(), a.end(), back_inserter(arrays)); - - omega::CG_outputRepr *r1 = new omega::CG_roseRepr(isSgNode(exp->get_lhs_operand())); - std::vector<IR_ArrayRef *> a1 = FindArrayRef(r1); - delete r1; - std::copy(a1.begin(), a1.end(), back_inserter(arrays)); - - } - }*/ - } std::vector<IR_Control *> IR_roseCode::FindOneLevelControlStructure( @@ -1536,52 +1388,6 @@ std::vector<IR_Control *> IR_roseCode::FindOneLevelControlStructure( } -/*std::vector<IR_Control *> IR_roseCode::FindOneLevelControlStructure(const IR_Block *block) const { - - std::vector<IR_Control *> controls; - int i; - int j; - SgNode* tnl_ = ((static_cast<IR_roseBlock *>(const_cast<IR_Block *>(block)))->tnl_); - - - if(isSgForStatement(tnl_)) - controls.push_back(new IR_roseLoop(this,tnl_)); - - else if(isSgBasicBlock(tnl_)){ - - SgStatementPtrList& stmts = isSgBasicBlock(tnl_)->get_statements(); - - for(i =0; i < stmts.size(); i++){ - if(isSgNode(stmts[i]) == ((static_cast<IR_roseBlock *>(const_cast<IR_Block *>(block)))->start_)) - break; - } - - - SgNode* start= NULL; - SgNode* prev= NULL; - for(; i < stmts.size(); i++){ - if ( isSgForStatement(stmts[i]) || isSgFortranDo(stmts[i])){ - if(start != NULL){ - controls.push_back(new IR_roseBlock(this, (static_cast<IR_roseBlock *>(const_cast<IR_Block *>(block)))->tnl_ , start, prev)); - start = NULL; - } - controls.push_back(new IR_roseLoop(this, isSgNode(stmts[i]))); - } - else if( start == NULL ) - start = isSgNode(stmts[i]); - - prev = isSgNode(stmts[i]); - } - - if((start != NULL) && (start != isSgNode(stmts[0]))) - controls.push_back(new IR_roseBlock(this, (static_cast<IR_roseBlock *>(const_cast<IR_Block *>(block)))->tnl_, start, prev)); - } - - return controls; - - } - -*/ IR_Block *IR_roseCode::MergeNeighboringControlStructures( const std::vector<IR_Control *> &controls) const { if (controls.size() == 0) @@ -1781,61 +1587,6 @@ void IR_roseCode::ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr) { delete old; } -/*std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > IR_roseCode::FindScalarDeps( - const omega::CG_outputRepr *repr1, const omega::CG_outputRepr *repr2, - std::vector<std::string> index, int i, int j) { - - std::vector<DependenceVector> dvs1; - std::vector<DependenceVector> dvs2; - SgNode *tnl_1 = static_cast<const omega::CG_roseRepr *>(repr1)->GetCode(); - SgNode *tnl_2 = static_cast<const omega::CG_roseRepr *>(repr2)->GetCode(); - SgStatementPtrList* list_1 = - static_cast<const omega::CG_roseRepr *>(repr1)->GetList(); - SgStatementPtrList output_list_1; - - std::map<SgVarRefExp*, IR_ScalarRef*> read_scalars_1; - std::map<SgVarRefExp*, IR_ScalarRef*> write_scalars_1; - std::set<std::string> indices; - //std::set<VirtualCFG::CFGNode> reaching_defs_1; - std::set<std::string> def_vars_1; - - populateLists(tnl_1, list_1, output_list_1); - populateScalars(repr1, read_scalars_1, write_scalars_1, indices, index); - //def_vars_1); - //findDefinitions(output_list_1, reaching_defs_1, write_scalars_1); - //def_vars_1); - if (repr1 == repr2) - checkSelfDependency(output_list_1, dvs1, read_scalars_1, - write_scalars_1, index, i, j); - else { - SgStatementPtrList* list_2 = - static_cast<const omega::CG_roseRepr *>(repr2)->GetList(); - SgStatementPtrList output_list_2; - - std::map<SgVarRefExp*, IR_ScalarRef*> read_scalars_2; - std::map<SgVarRefExp*, IR_ScalarRef*> write_scalars_2; - //std::set<VirtualCFG::CFGNode> reaching_defs_2; - std::set<std::string> def_vars_2; - - populateLists(tnl_2, list_2, output_list_2); - populateScalars(repr2, read_scalars_2, write_scalars_2, indices, index); - //def_vars_2); - - checkDependency(output_list_2, dvs1, read_scalars_2, write_scalars_1, - index, i, j); - checkDependency(output_list_1, dvs1, read_scalars_1, write_scalars_2, - index, i, j); - checkWriteDependency(output_list_2, dvs1, write_scalars_2, - write_scalars_1, index, i, j); - checkWriteDependency(output_list_1, dvs1, write_scalars_1, - write_scalars_2, index, i, j); - } - - return std::make_pair(dvs1, dvs2); - //populateLists(tnl_2, list_2, list2); - - } -*/ IR_OPERATION_TYPE IR_roseCode::QueryExpOperation( const omega::CG_outputRepr *repr) const { SgExpression* op = @@ -1870,299 +1621,7 @@ IR_OPERATION_TYPE IR_roseCode::QueryExpOperation( else return IR_OP_UNKNOWN; } -/*void IR_roseCode::populateLists(SgNode* tnl_1, SgStatementPtrList* list_1, - SgStatementPtrList& output_list_1) { - if ((tnl_1 == NULL) && (list_1 != NULL)) { - output_list_1 = *list_1; - } else if (tnl_1 != NULL) { - - if (isSgForStatement(tnl_1)) { - SgStatement* check = isSgForStatement(tnl_1)->get_loop_body(); - if (isSgBasicBlock(check)) { - output_list_1 = isSgBasicBlock(check)->get_statements(); - - } else - output_list_1.push_back(check); - - } else if (isSgBasicBlock(tnl_1)) - output_list_1 = isSgBasicBlock(tnl_1)->get_statements(); - else if (isSgExprStatement(tnl_1)) - output_list_1.push_back(isSgExprStatement(tnl_1)); - else - //if (isSgIfStmt(tnl_1)) { - - throw ir_error( - "Statement type not handled, (probably IF statement)!!"); - - } - - } - - void IR_roseCode::populateScalars(const omega::CG_outputRepr *repr1, - std::map<SgVarRefExp*, IR_ScalarRef*> &read_scalars_1, - std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1, - std::set<std::string> &indices, std::vector<std::string> &index) { - - //std::set<std::string> &def_vars) { - std::vector<IR_ScalarRef *> scalars = FindScalarRef(repr1); - - for (int k = 0; k < index.size(); k++) - indices.insert(index[k]); - - for (int k = 0; k < scalars.size(); k++) - if (indices.find(scalars[k]->name()) == indices.end()) { - if (scalars[k]->is_write()) { - write_scalars_1.insert( - std::pair<SgVarRefExp*, IR_ScalarRef*>( - (isSgVarRefExp( - static_cast<const omega::CG_roseRepr *>(scalars[k]->convert())->GetExpression())), - scalars[k])); - - } else - - read_scalars_1.insert( - std::pair<SgVarRefExp*, IR_ScalarRef*>( - (isSgVarRefExp( - static_cast<const omega::CG_roseRepr *>(scalars[k]->convert())->GetExpression())), - scalars[k])); - } - - } - - - void IR_roseCode::checkWriteDependency(SgStatementPtrList &output_list_1, - std::vector<DependenceVector> &dvs1, - std::map<SgVarRefExp*, IR_ScalarRef*> &read_scalars_1, - std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1, - std::vector<std::string> &index, int i, int j) { - - for (std::map<SgVarRefExp*, IR_ScalarRef*>::iterator it = - read_scalars_1.begin(); it != read_scalars_1.end(); it++) { - SgVarRefExp* var__ = it->first; - - ssa_unfiltered_cfg::SSA_UnfilteredCfg::NodeReachingDefTable to_compare = - main_ssa->getReachingDefsBefore(isSgNode(var__)); - - for (ssa_unfiltered_cfg::SSA_UnfilteredCfg::NodeReachingDefTable::iterator it4 = - to_compare.begin(); it4 != to_compare.end(); it4++) { - ssa_unfiltered_cfg::SSA_UnfilteredCfg::VarName var_ = it4->first; - for (int j = 0; j < var_.size(); j++) { - int found = 0; - if (var_[j] == var__->get_symbol()->get_declaration()) { - - ssa_unfiltered_cfg::ReachingDef::ReachingDefPtr to_compare_2 = - it4->second; - - if (to_compare_2->isPhiFunction()) { - std::set<VirtualCFG::CFGNode> to_compare_set = - to_compare_2->getActualDefinitions(); - for (std::set<VirtualCFG::CFGNode>::iterator cfg_it = - to_compare_set.begin(); - cfg_it != to_compare_set.end(); cfg_it++) { - - if (isSgAssignOp(cfg_it->getNode()) - || isSgCompoundAssignOp(cfg_it->getNode())) - if (SgVarRefExp* variable = - isSgVarRefExp( - isSgBinaryOp(cfg_it->getNode())->get_lhs_operand())) { - - if (write_scalars_1.find(variable) - != write_scalars_1.end()) { - - - //end debug - found = 1; - DependenceVector dv1; - dv1.sym = it->second->symbol(); - dv1.is_scalar_dependence = true; - - int max = (j > i) ? j : i; - int start = index.size() - max; - - //1.lbounds.push_back(0); - //1.ubounds.push_back(0); - //dv2.sym = - // read_scalars_2.find(*di)->second->symbol(); - for (int k = 0; k < index.size(); k++) { - if (k >= max) { - dv1.lbounds.push_back( - negInfinity); - dv1.ubounds.push_back(-1); - } else { - dv1.lbounds.push_back(0); - dv1.ubounds.push_back(0); - - } - - } - dvs1.push_back(dv1); - break; - } - } - } - - } - - } - if (found == 1) - break; - } - } - } - } - void IR_roseCode::checkDependency(SgStatementPtrList &output_list_1, - std::vector<DependenceVector> &dvs1, - std::map<SgVarRefExp*, IR_ScalarRef*> &read_scalars_1, - std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1, - std::vector<std::string> &index, int i, int j) { - - for (SgStatementPtrList::iterator it2 = output_list_1.begin(); - it2 != output_list_1.end(); it2++) { - - std::set<SgVarRefExp*> vars_1 = main_ssa->getUsesAtNode( - isSgNode(isSgExprStatement(*it2)->get_expression())); - - std::set<SgVarRefExp*>::iterator di; - - for (di = vars_1.begin(); di != vars_1.end(); di++) { - int found = 0; - if (read_scalars_1.find(*di) != read_scalars_1.end()) { - - ssa_unfiltered_cfg::ReachingDef::ReachingDefPtr to_compare = - main_ssa->getDefinitionForUse(*di); - if (to_compare->isPhiFunction()) { - - std::set<VirtualCFG::CFGNode> to_compare_set = - to_compare->getActualDefinitions(); - - for (std::set<VirtualCFG::CFGNode>::iterator cfg_it = - to_compare_set.begin(); - cfg_it != to_compare_set.end(); cfg_it++) { - - - if (SgAssignOp* definition = isSgAssignOp( - cfg_it->getNode())) - if (SgVarRefExp* variable = isSgVarRefExp( - definition->get_lhs_operand())) { - - if (write_scalars_1.find(variable) - != write_scalars_1.end()) { - - found = 1; - DependenceVector dv1; - //DependenceVector dv2; - dv1.sym = - read_scalars_1.find(*di)->second->symbol(); - dv1.is_scalar_dependence = true; - - int max = (j > i) ? j : i; - int start = index.size() - max; - - //1.lbounds.push_back(0); - //1.ubounds.push_back(0); - //dv2.sym = - // read_scalars_2.find(*di)->second->symbol(); - for (int k = 0; k < index.size(); k++) { - if (k >= max) { - dv1.lbounds.push_back(negInfinity); - dv1.ubounds.push_back(-1); - } else { - dv1.lbounds.push_back(0); - dv1.ubounds.push_back(0); - - } - - } - dvs1.push_back(dv1); - break; - } - } - } - } - if (found == 1) - break; - } - } - } - - } - - void IR_roseCode::checkSelfDependency(SgStatementPtrList &output_list_1, - std::vector<DependenceVector> &dvs1, - std::map<SgVarRefExp*, IR_ScalarRef*> &read_scalars_1, - std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1, - std::vector<std::string> &index, int i, int j) { - - for (SgStatementPtrList::iterator it2 = output_list_1.begin(); - it2 != output_list_1.end(); it2++) { - - std::set<SgVarRefExp*> vars_1 = main_ssa->getUsesAtNode( - isSgNode(isSgExprStatement(*it2)->get_expression())); - - std::set<SgVarRefExp*>::iterator di; - - for (di = vars_1.begin(); di != vars_1.end(); di++) { - - if (read_scalars_1.find(*di) != read_scalars_1.end()) { - - ssa_unfiltered_cfg::ReachingDef::ReachingDefPtr to_compare = - main_ssa->getDefinitionForUse(*di); - if (to_compare->isPhiFunction()) { - - std::set<VirtualCFG::CFGNode> to_compare_set = - to_compare->getActualDefinitions(); - int found = 0; - for (std::set<VirtualCFG::CFGNode>::iterator cfg_it = - to_compare_set.begin(); - cfg_it != to_compare_set.end(); cfg_it++) { - - if (isSgAssignOp(cfg_it->getNode()) - || isSgCompoundAssignOp(cfg_it->getNode())) - if (SgVarRefExp* variable = - isSgVarRefExp( - isSgBinaryOp(cfg_it->getNode())->get_lhs_operand())) { - - if (write_scalars_1.find(variable) - == write_scalars_1.end()) { - - - found = 1; - DependenceVector dv1; - dv1.sym = - read_scalars_1.find(*di)->second->symbol(); - dv1.is_scalar_dependence = true; - - int max = (j > i) ? j : i; - int start = index.size() - max; - - //1.lbounds.push_back(0); - //1.ubounds.push_back(0); - //dv2.sym = - // read_scalars_2.find(*di)->second->symbol(); - for (int k = 0; k < index.size(); k++) { - if (k >= max) { - dv1.lbounds.push_back(negInfinity); - dv1.ubounds.push_back(-1); - } else { - dv1.lbounds.push_back(0); - dv1.ubounds.push_back(0); - - } - - } - dvs1.push_back(dv1); - break; - } - } - } - } - - } - } - } - - } -*/ + IR_CONDITION_TYPE IR_roseCode::QueryBooleanExpOperation( const omega::CG_outputRepr *repr) const { SgExpression* op2 = diff --git a/chill/src/loop.cc b/chill/src/loop.cc index f4cd844..f187a50 100644 --- a/chill/src/loop.cc +++ b/chill/src/loop.cc @@ -748,17 +748,6 @@ void Loop::pragma(int stmt_num, int level, const std::string &pragmaText) { CG_outputRepr *code = stmt[stmt_num].code; ocg->CreatePragmaAttribute(code, level, pragmaText); } -/* -void Loop::prefetch(int stmt_num, int level, const std::string &arrName, const std::string &indexName, int offset, int hint) { - // check sanity of parameters - if(stmt_num < 0) - throw std::invalid_argument("invalid statement " + to_string(stmt_num)); - - CG_outputBuilder *ocg = ir->builder(); - CG_outputRepr *code = stmt[stmt_num].code; - ocg->CreatePrefetchAttribute(code, level, arrName, indexName, int offset, hint); -} -*/ void Loop::prefetch(int stmt_num, int level, const std::string &arrName, int hint) { // check sanity of parameters diff --git a/chill/src/omegatools.cc b/chill/src/omegatools.cc index cab66d4..3aac404 100644 --- a/chill/src/omegatools.cc +++ b/chill/src/omegatools.cc @@ -14,7 +14,6 @@ *****************************************************************************/ #include <code_gen/codegen.h> -// #include <code_gen/output_repr.h> #include "omegatools.hh" #include "ir_code.hh" #include "chill_error.hh" @@ -42,18 +41,9 @@ std::string tmp_e() { return std::string("e")+to_string(counter++); } - - -//----------------------------------------------------------------------------- -// Convert expression tree to omega relation. "destroy" means shallow -// deallocation of "repr", not freeing the actual code inside. -// ----------------------------------------------------------------------------- void exp2formula(IR_Code *ir, Relation &r, F_And *f_root, std::vector<Free_Var_Decl*> &freevars, CG_outputRepr *repr, Variable_ID lhs, char side, IR_CONDITION_TYPE rel, bool destroy) { -// void exp2formula(IR_Code *ir, Relation &r, F_And *f_root, std::vector<Free_Var_Decl*> &freevars, -// CG_outputRepr *repr, Variable_ID lhs, char side, char rel, bool destroy) { - switch (ir->QueryExpOperation(repr)) { case IR_OP_CONSTANT: { @@ -509,10 +499,6 @@ void exp2formula(IR_Code *ir, Relation &r, F_And *f_root, std::vector<Free_Var_D } } - -//----------------------------------------------------------------------------- -// Build dependence relation for two array references. -// ----------------------------------------------------------------------------- Relation arrays2relation(IR_Code *ir, std::vector<Free_Var_Decl*> &freevars, const IR_ArrayRef *ref_src, const Relation &IS_w, const IR_ArrayRef *ref_dst, const Relation &IS_r) { @@ -583,11 +569,6 @@ Relation arrays2relation(IR_Code *ir, std::vector<Free_Var_Decl*> &freevars, return r; } - -//----------------------------------------------------------------------------- -// Convert array dependence relation into set of dependence vectors, assuming -// ref_w is lexicographically before ref_r in the source code. -// ----------------------------------------------------------------------------- std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relation2dependences (const IR_ArrayRef *ref_src, const IR_ArrayRef *ref_dst, const Relation &r) { assert(r.n_inp() == r.n_out()); @@ -815,11 +796,6 @@ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relatio return std::make_pair(dependences1, dependences2); } - -//----------------------------------------------------------------------------- -// Convert a boolean expression to omega relation. "destroy" means shallow -// deallocation of "repr", not freeing the actual code inside. -//----------------------------------------------------------------------------- void exp2constraint(IR_Code *ir, Relation &r, F_And *f_root, std::vector<Free_Var_Decl *> &freevars, CG_outputRepr *repr, bool destroy) { @@ -862,739 +838,6 @@ void exp2constraint(IR_Code *ir, Relation &r, F_And *f_root, } } - - - - -// inline void exp2formula(IR_Code *ir, Relation &r, F_And *f_root, -// std::vector<Free_Var_Decl*> &freevars, -// const CG_outputRepr *repr, Variable_ID lhs, char side, char rel) { -// exp2formula(ir, r, f_root, freevars, const_cast<CG_outputRepr *>(repr), lhs, side, rel, false); -// } - - - - - - - -//----------------------------------------------------------------------------- -// Convert suif expression tree to omega relation. -//----------------------------------------------------------------------------- - -// void suif2formula(Relation &r, F_And *f_root, -// std::vector<Free_Var_Decl*> &freevars, -// operand op, Variable_ID lhs, -// char side, char rel) { -// if (op.is_immed()) { -// immed im = op.immediate(); - -// if (im.is_integer()) { -// int c = im.integer(); - -// if (rel == '>') { -// GEQ_Handle h = f_root->add_GEQ(); -// h.update_coef(lhs, 1); -// h.update_const(-1*c); -// } -// else if (rel == '<') { -// GEQ_Handle h = f_root->add_GEQ(); -// h.update_coef(lhs, -1); -// h.update_const(c); -// } -// else { // '=' -// EQ_Handle h = f_root->add_EQ(); -// h.update_coef(lhs, 1); -// h.update_const(-1*c); -// } -// } -// else { -// return; //add Function in the future -// } -// } -// else if (op.is_symbol()) { -// String s = op.symbol()->name(); -// Variable_ID e = find_index(r, s, side); - -// if (e == NULL) { // must be free variable -// Free_Var_Decl *t = NULL; -// for (unsigned i = 0; i < freevars.size(); i++) { -// String ss = freevars[i]->base_name(); -// if (s == ss) { -// t = freevars[i]; -// break; -// } -// } - -// if (t == NULL) { -// t = new Free_Var_Decl(s); -// freevars.insert(freevars.end(), t); -// } - -// e = r.get_local(t); -// } - -// if (rel == '>') { -// GEQ_Handle h = f_root->add_GEQ(); -// h.update_coef(lhs, 1); -// h.update_coef(e, -1); -// } -// else if (rel == '<') { -// GEQ_Handle h = f_root->add_GEQ(); -// h.update_coef(lhs, -1); -// h.update_coef(e, 1); -// } -// else { // '=' -// EQ_Handle h = f_root->add_EQ(); -// h.update_coef(lhs, 1); -// h.update_coef(e, -1); -// } -// } -// else if (op.is_instr()) -// suif2formula(r, f_root, freevars, op.instr(), lhs, side, rel); -// } - - -// void suif2formula(Relation &r, F_And *f_root, -// std::vector<Free_Var_Decl*> &freevars, -// instruction *ins, Variable_ID lhs, -// char side, char rel) { -// if (ins->opcode() == io_cpy) { -// suif2formula(r, f_root, freevars, ins->src_op(0), lhs, side, rel); -// } -// else if (ins->opcode() == io_add || ins->opcode() == io_sub) { -// F_Exists *f_exists = f_root->add_exists(); -// Variable_ID e1 = f_exists->declare(tmp_e()); -// Variable_ID e2 = f_exists->declare(tmp_e()); -// F_And *f_and = f_exists->add_and(); - -// int add_or_sub = ins->opcode() == io_add ? 1 : -1; -// if (rel == '>') { -// GEQ_Handle h = f_and->add_GEQ(); -// h.update_coef(lhs, 1); -// h.update_coef(e1, -1); -// h.update_coef(e2, -1 * add_or_sub); -// } -// else if (rel == '<') { -// GEQ_Handle h = f_and->add_GEQ(); -// h.update_coef(lhs, -1); -// h.update_coef(e1, 1); -// h.update_coef(e2, 1 * add_or_sub); -// } -// else { // '=' -// EQ_Handle h = f_and->add_EQ(); -// h.update_coef(lhs, 1); -// h.update_coef(e1, -1); -// h.update_coef(e2, -1 * add_or_sub); -// } - -// suif2formula(r, f_and, freevars, ins->src_op(0), e1, side, '='); -// suif2formula(r, f_and, freevars, ins->src_op(1), e2, side, '='); -// } -// else if (ins->opcode() == io_mul) { -// operand op1 = ins->src_op(0); -// operand op2 = ins->src_op(1); - -// if (!op1.is_immed() && !op2.is_immed()) -// return; // add Function in the future -// else { -// operand op; -// immed im; -// if (op1.is_immed()) { -// im = op1.immediate(); -// op = op2; -// } -// else { -// im = op2.immediate(); -// op = op1; -// } - -// if (!im.is_integer()) -// return; //add Function in the future -// else { -// int c = im.integer(); - -// F_Exists *f_exists = f_root->add_exists(); -// Variable_ID e = f_exists->declare(tmp_e()); -// F_And *f_and = f_exists->add_and(); - -// if (rel == '>') { -// GEQ_Handle h = f_and->add_GEQ(); -// h.update_coef(lhs, 1); -// h.update_coef(e, -c); -// } -// else if (rel == '<') { -// GEQ_Handle h = f_and->add_GEQ(); -// h.update_coef(lhs, -1); -// h.update_coef(e, c); -// } -// else { -// EQ_Handle h = f_and->add_EQ(); -// h.update_coef(lhs, 1); -// h.update_coef(e, -c); -// } - -// suif2formula(r, f_and, freevars, op, e, side, '='); -// } -// } -// } -// else if (ins->opcode() == io_div) { -// operand op1 = ins->src_op(0); -// operand op2 = ins->src_op(1); - -// if (!op2.is_immed()) -// return; //add Function in the future -// else { -// immed im = op2.immediate(); - -// if (!im.is_integer()) -// return; //add Function in the future -// else { -// int c = im.integer(); - -// F_Exists *f_exists = f_root->add_exists(); -// Variable_ID e = f_exists->declare(tmp_e()); -// F_And *f_and = f_exists->add_and(); - -// if (rel == '>') { -// GEQ_Handle h = f_and->add_GEQ(); -// h.update_coef(lhs, c); -// h.update_coef(e, -1); -// } -// else if (rel == '<') { -// GEQ_Handle h = f_and->add_GEQ(); -// h.update_coef(lhs, -c); -// h.update_coef(e, 1); -// } -// else { -// EQ_Handle h = f_and->add_EQ(); -// h.update_coef(lhs, c); -// h.update_coef(e, -1); -// } - -// suif2formula(r, f_and, freevars, op1, e, side, '='); -// } -// } -// } -// else if (ins->opcode() == io_neg) { -// F_Exists *f_exists = f_root->add_exists(); -// Variable_ID e = f_exists->declare(tmp_e()); -// F_And *f_and = f_exists->add_and(); - -// if (rel == '>') { -// GEQ_Handle h = f_and->add_GEQ(); -// h.update_coef(lhs, 1); -// h.update_coef(e, 1); -// } -// else if (rel == '<') { -// GEQ_Handle h = f_and->add_GEQ(); -// h.update_coef(lhs, -1); -// h.update_coef(e, -1); -// } -// else { -// EQ_Handle h = f_and->add_EQ(); -// h.update_coef(lhs, 1); -// h.update_coef(e, 1); -// } - -// suif2formula(r, f_and, freevars, ins->src_op(0), e, side, '='); -// } -// else if (ins->opcode() == io_min) { -// operand op1 = ins->src_op(0); -// operand op2 = ins->src_op(1); - -// F_Exists *f_exists = f_root->add_exists(); -// Variable_ID e1 = f_exists->declare(tmp_e()); -// Variable_ID e2 = f_exists->declare(tmp_e()); -// F_And *f_and = f_exists->add_and(); - -// if (rel == '>') { -// F_Or *f_or = f_and->add_or(); -// F_And *f_and1 = f_or->add_and(); -// GEQ_Handle h1 = f_and1->add_GEQ(); -// h1.update_coef(lhs, 1); -// h1.update_coef(e1, -1); -// F_And *f_and2 = f_or->add_and(); -// GEQ_Handle h2 = f_and2->add_GEQ(); -// h2.update_coef(lhs, 1); -// h2.update_coef(e2, -1); -// } -// else if (rel == '<') { -// GEQ_Handle h1 = f_and->add_GEQ(); -// h1.update_coef(lhs, -1); -// h1.update_coef(e1, 1); -// GEQ_Handle h2 = f_and->add_GEQ(); -// h2.update_coef(lhs, -1); -// h2.update_coef(e2, 1); -// } -// else { -// F_Or *f_or = f_and->add_or(); -// F_And *f_and1 = f_or->add_and(); -// EQ_Handle h1 = f_and1->add_EQ(); -// h1.update_coef(lhs, 1); -// h1.update_coef(e1, -1); -// GEQ_Handle h2 = f_and1->add_GEQ(); -// h2.update_coef(e1, -1); -// h2.update_coef(e2, 1); -// F_And *f_and2 = f_or->add_and(); -// EQ_Handle h3 = f_and2->add_EQ(); -// h3.update_coef(lhs, 1); -// h3.update_coef(e2, -1); -// GEQ_Handle h4 = f_and2->add_GEQ(); -// h4.update_coef(e1, 1); -// h4.update_coef(e2, -1); -// } - -// suif2formula(r, f_and, freevars, op1, e1, side, '='); -// suif2formula(r, f_and, freevars, op2, e2, side, '='); -// } -// else if (ins->opcode() == io_max) { -// operand op1 = ins->src_op(0); -// operand op2 = ins->src_op(1); - -// F_Exists *f_exists = f_root->add_exists(); -// Variable_ID e1 = f_exists->declare(tmp_e()); -// Variable_ID e2 = f_exists->declare(tmp_e()); -// F_And *f_and = f_exists->add_and(); - -// if (rel == '>') { -// GEQ_Handle h1 = f_and->add_GEQ(); -// h1.update_coef(lhs, 1); -// h1.update_coef(e1, -1); -// GEQ_Handle h2 = f_and->add_GEQ(); -// h2.update_coef(lhs, 1); -// h2.update_coef(e2, -1); -// } -// else if (rel == '<') { -// F_Or *f_or = f_and->add_or(); -// F_And *f_and1 = f_or->add_and(); -// GEQ_Handle h1 = f_and1->add_GEQ(); -// h1.update_coef(lhs, -1); -// h1.update_coef(e1, 1); -// F_And *f_and2 = f_or->add_and(); -// GEQ_Handle h2 = f_and2->add_GEQ(); -// h2.update_coef(lhs, -1); -// h2.update_coef(e2, 1); -// } -// else { -// F_Or *f_or = f_and->add_or(); -// F_And *f_and1 = f_or->add_and(); -// EQ_Handle h1 = f_and1->add_EQ(); -// h1.update_coef(lhs, 1); -// h1.update_coef(e1, -1); -// GEQ_Handle h2 = f_and1->add_GEQ(); -// h2.update_coef(e1, 1); -// h2.update_coef(e2, -1); -// F_And *f_and2 = f_or->add_and(); -// EQ_Handle h3 = f_and2->add_EQ(); -// h3.update_coef(lhs, 1); -// h3.update_coef(e2, -1); -// GEQ_Handle h4 = f_and2->add_GEQ(); -// h4.update_coef(e1, -1); -// h4.update_coef(e2, 1); -// } - -// suif2formula(r, f_and, freevars, op1, e1, side, '='); -// suif2formula(r, f_and, freevars, op2, e2, side, '='); -// } -// } - -//----------------------------------------------------------------------------- -// Generate iteration space constraints -//----------------------------------------------------------------------------- - -// void add_loop_stride_constraints(Relation &r, F_And *f_root, -// std::vector<Free_Var_Decl*> &freevars, -// tree_for *tnf, char side) { - -// std::string name(tnf->index()->name()); -// int dim = 0; -// for (;dim < r.n_set(); dim++) -// if (r.set_var(dim+1)->name() == name) -// break; - -// Relation bound = get_loop_bound(r, dim); - -// operand op = tnf->step_op(); -// if (!op.is_null()) { -// if (op.is_immed()) { -// immed im = op.immediate(); -// if (im.is_integer()) { -// int c = im.integer(); - -// if (c != 1 && c != -1) -// add_loop_stride(r, bound, dim, c); -// } -// else -// assert(0); // messy stride -// } -// else -// assert(0); // messy stride -// } -// } - -// void add_loop_bound_constraints(IR_Code *ir, Relation &r, F_And *f_root, -// std::vector<Free_Var_Decl*> &freevars, -// tree_for *tnf, -// char upper_or_lower, char side, IR_CONDITION_TYPE rel) { -// Variable_ID v = find_index(r, tnf->index()->name(), side); - -// tree_node_list *tnl; - -// if (upper_or_lower == 'u') -// tnl = tnf->ub_list(); -// else -// tnl = tnf->lb_list(); - -// tree_node_list_iter iter(tnl); -// while (!iter.is_empty()) { -// tree_node *tn = iter.step(); -// if (tn->kind() != TREE_INSTR) -// break; // messy bounds - -// instruction *ins = static_cast<tree_instr *>(tn)->instr(); - - -// if (upper_or_lower == 'u' && (tnf->test() == FOR_SLT || tnf->test() == FOR_ULT)) { -// operand op1(ins->clone()); -// operand op2(new in_ldc(type_s32, operand(), immed(1))); -// instruction *t = new in_rrr(io_sub, op1.type(), operand(), op1, op2); - -// CG_suifRepr *repr = new CG_suifRepr(operand(t)); -// exp2formula(ir, r, f_root, freevars, repr, v, side, rel, true); -// delete t; -// } -// else if (tnf->test() == FOR_SLT || tnf->test() == FOR_SLTE || tnf->test() == FOR_ULT || tnf->test() == FOR_ULTE) { -// CG_suifRepr *repr = new CG_suifRepr(operand(ins)); -// exp2formula(ir, r, f_root, freevars, repr, v, side, rel, true); -// } -// else -// assert(0); -// } -// } - - -// Relation loop_iteration_space(std::vector<Free_Var_Decl*> &freevars, -// tree_node *tn, std::vector<tree_for*> &loops) { -// Relation r(loops.size()); -// for (unsigned i = 0; i < loops.size(); i++) { -// String s = loops[i]->index()->name(); -// r.name_set_var(i+1, s); -// } - -// F_And *f_root = r.add_and(); - -// std::vector<tree_for *> outer = find_outer_loops(tn); -// std::vector<LexicalOrderType> loops_lex(loops.size(), LEX_UNKNOWN); - -// for (unsigned i = 0; i < outer.size(); i++) { -// unsigned j; - -// for (j = 0; j < loops.size(); j++) { -// if (outer[i] == loops[j]) { -// loops_lex[j] = LEX_MATCH; -// break; -// } else if (outer[i]->index() == loops[j]->index()) { -// loops_lex[j] = lexical_order(outer[i],loops[j]); -// break; -// } -// } - -// if (j != loops.size()) { -// add_loop_bound_constraints(r, f_root, freevars, outer[i], 'l', 's', '>'); -// add_loop_bound_constraints(r, f_root, freevars, outer[i], 'u', 's', '<'); -// add_loop_stride_constraints(r,f_root, freevars, outer[i], 's'); -// } -// } - -// // Add degenerated constraints for non-enclosing loops for this -// // statement. We treat low-dim space as part of whole -// // iteration space. -// LexicalOrderType lex = LEX_MATCH; -// for (unsigned i = 0; i < loops.size(); i++) { -// if (loops_lex[i] != 0) { -// if (lex == LEX_MATCH) -// lex = loops_lex[i]; -// continue; -// } - -// if (lex == LEX_MATCH) { -// for (unsigned j = i+1; j < loops.size(); j++) { -// if (loops_lex[j] == LEX_BEFORE || loops_lex[j] == LEX_AFTER) { -// lex = loops_lex[j]; -// break; -// } -// } -// } - -// if (lex == LEX_MATCH) -// lex = lexical_order(tn, loops[i]); - -// if (lex == LEX_BEFORE) -// add_loop_bound_constraints(r, f_root, freevars, loops[i], 'l', 's', '='); -// else -// add_loop_bound_constraints(r, f_root, freevars, loops[i], 'u', 's', '='); -// } - -// return r; -// } - -// Relation arrays2relation(std::vector<Free_Var_Decl*> &freevars, -// in_array *ia_w, const Relation &IS1_, -// in_array *ia_r, const Relation &IS2_) { -// Relation &IS1 = const_cast<Relation &>(IS1_); -// Relation &IS2 = const_cast<Relation &>(IS2_); - -// Relation r(IS1.n_set(), IS2.n_set()); - -// for (int i = 1; i <= IS1.n_set(); i++) -// r.name_input_var(i, IS1.set_var(i)->name()); - -// for (int i = 1; i <= IS2.n_set(); i++) -// r.name_output_var(i, IS2.set_var(i)->name()+"'"); - -// if (get_sym_of_array(ia_w) != get_sym_of_array(ia_r)) { -// r.add_or(); // False Relation -// return r; -// } - -// F_And *f_root = r.add_and(); - -// for (unsigned i = 0; i < ia_w->dims(); i++) { -// F_Exists *f_exists = f_root->add_exists(); -// Variable_ID e = f_exists->declare(tmp_e()); -// F_And *f_and = f_exists->add_and(); - -// suif2formula(r, f_and, freevars, ia_w->index(i), e, 'w', '='); -// suif2formula(r, f_and, freevars, ia_r->index(i), e, 'r', '='); -// } - -// // add iteration space restriction -// r = Restrict_Domain(r, copy(IS1)); -// r = Restrict_Range(r, copy(IS2)); - -// // reset the output variable names lost in restriction -// for (int i = 1; i <= IS2.n_set(); i++) -// r.name_output_var(i, IS2.set_var(i)->name()+"'"); - -// return r; -// } - - -// std::vector<DependenceVector> relation2dependences (IR_Code *ir, in_array *ia_w, in_array *ia_r, const Relation &r) { -// assert(r.n_inp() == r.n_out()); - -// std::vector<DependenceVector> dependences; - -// std::stack<DependenceLevel> working; -// working.push(DependenceLevel(r, r.n_inp())); - -// while (!working.empty()) { -// DependenceLevel dep = working.top(); -// working.pop(); - -// // No dependence exists, move on. -// if (!dep.r.is_satisfiable()) -// continue; - -// if (dep.level == r.n_inp()) { -// DependenceVector dv; - -// // for loop independent dependence, use lexical order to -// // determine the correct source and destination -// if (dep.dir == 0) { -// LexicalOrderType order = lexical_order(ia_w->parent(), ia_r->parent()); - -// if (order == LEX_MATCH) -// continue; //trivial self zero-dependence -// else if (order == LEX_AFTER) { -// dv.src = new IR_suifArrayRef(ir, ia_r); -// dv.dst = new IR_suifArrayRef(ir, ia_w); -// } -// else { -// dv.src = new IR_suifArrayRef(ir, ia_w); -// dv.dst = new IR_suifArrayRef(ir,ia_r); -// } -// } -// else if (dep.dir == 1) { -// dv.src = new IR_suifArrayRef(ir, ia_w); -// dv.dst = new IR_suifArrayRef(ir, ia_r); -// } -// else { // dep.dir == -1 -// dv.src = new IR_suifArrayRef(ir, ia_r); -// dv.dst = new IR_suifArrayRef(ir, ia_w); -// } - -// dv.lbounds = dep.lbounds; -// dv.ubounds = dep.ubounds; - -// // // set the dependence type -// // if (is_lhs(dv.source) && is_lhs(dv.dest)) -// // dv.type = 'o'; -// // else if (!is_lhs(dv.source) && ! is_lhs(dv.dest)) -// // dv.type = 'i'; -// // else if (is_lhs(dv.source)) -// // dv.type = 'f'; -// // else -// // dv.type = 'a'; - -// dependences.push_back(dv); -// } -// else { -// // now work on the next dimension level -// int level = ++dep.level; - -// coef_t lbound, ubound; -// Relation delta = Deltas(copy(dep.r)); -// delta.query_variable_bounds(delta.set_var(level), lbound, ubound); - -// if (dep.dir == 0) { -// if (lbound > 0) { -// dep.dir = 1; -// dep.lbounds[level-1] = lbound; -// dep.ubounds[level-1] = ubound; - -// working.push(dep); -// } -// else if (ubound < 0) { -// dep.dir = -1; -// dep.lbounds[level-1] = -ubound; -// dep.ubounds[level-1] = -lbound; - -// working.push(dep); -// } -// else { -// // split the dependence vector into flow- and anti-dependence -// // for the first non-zero distance, also separate zero distance -// // at this level. -// { -// DependenceLevel dep2 = dep; - -// dep2.lbounds[level-1] = 0; -// dep2.ubounds[level-1] = 0; - -// F_And *f_root = dep2.r.and_with_and(); -// EQ_Handle h = f_root->add_EQ(); -// h.update_coef(dep2.r.input_var(level), 1); -// h.update_coef(dep2.r.output_var(level), -1); - -// working.push(dep2); -// } - -// if (lbound < 0 && ia_w != ia_r) { -// DependenceLevel dep2 = dep; - -// F_And *f_root = dep2.r.and_with_and(); -// GEQ_Handle h = f_root->add_GEQ(); -// h.update_coef(dep2.r.input_var(level), 1); -// h.update_coef(dep2.r.output_var(level), -1); -// h.update_const(-1); - -// // get tighter bounds under new constraints -// coef_t lbound, ubound; -// delta = Deltas(copy(dep2.r)); -// delta.query_variable_bounds(delta.set_var(level), -// lbound, ubound); - -// dep2.dir = -1; -// dep2.lbounds[level-1] = max(-ubound,static_cast<coef_t>(1)); // use max() to avoid Omega retardness -// dep2.ubounds[level-1] = -lbound; - -// working.push(dep2); -// } - -// if (ubound > 0) { -// DependenceLevel dep2 = dep; - -// F_And *f_root = dep2.r.and_with_and(); -// GEQ_Handle h = f_root->add_GEQ(); -// h.update_coef(dep2.r.input_var(level), -1); -// h.update_coef(dep2.r.output_var(level), 1); -// h.update_const(-1); - -// // get tighter bonds under new constraints -// coef_t lbound, ubound; -// delta = Deltas(copy(dep2.r)); -// delta.query_variable_bounds(delta.set_var(level), -// lbound, ubound); -// dep2.dir = 1; -// dep2.lbounds[level-1] = max(lbound,static_cast<coef_t>(1)); // use max() to avoid Omega retardness -// dep2.ubounds[level-1] = ubound; - -// working.push(dep2); -// } -// } -// } -// // now deal with dependence vector with known direction -// // determined at previous levels -// else { -// // For messy bounds, further test to see if the dependence distance -// // can be reduced to positive/negative. This is an omega hack. -// if (lbound == negInfinity && ubound == posInfinity) { -// { -// Relation t = dep.r; -// F_And *f_root = t.and_with_and(); -// GEQ_Handle h = f_root->add_GEQ(); -// h.update_coef(t.input_var(level), 1); -// h.update_coef(t.output_var(level), -1); -// h.update_const(-1); - -// if (!t.is_satisfiable()) { -// lbound = 0; -// } -// } -// { -// Relation t = dep.r; -// F_And *f_root = t.and_with_and(); -// GEQ_Handle h = f_root->add_GEQ(); -// h.update_coef(t.input_var(level), -1); -// h.update_coef(t.output_var(level), 1); -// h.update_const(-1); - -// if (!t.is_satisfiable()) { -// ubound = 0; -// } -// } -// } - -// // Same thing as above, test to see if zero dependence -// // distance possible. -// if (lbound == 0 || ubound == 0) { -// Relation t = dep.r; -// F_And *f_root = t.and_with_and(); -// EQ_Handle h = f_root->add_EQ(); -// h.update_coef(t.input_var(level), 1); -// h.update_coef(t.output_var(level), -1); - -// if (!t.is_satisfiable()) { -// if (lbound == 0) -// lbound = 1; -// if (ubound == 0) -// ubound = -1; -// } -// } - -// if (dep.dir == -1) { -// dep.lbounds[level-1] = -ubound; -// dep.ubounds[level-1] = -lbound; -// } -// else { // dep.dir == 1 -// dep.lbounds[level-1] = lbound; -// dep.ubounds[level-1] = ubound; -// } - -// working.push(dep); -// } -// } -// } - -// return dependences; -// } - -//----------------------------------------------------------------------------- -// Determine whether the loop (starting from 0) in the iteration space -// has only one iteration. -//----------------------------------------------------------------------------- bool is_single_loop_iteration(const Relation &r, int level, const Relation &known) { int n = r.n_set(); Relation r1 = Intersection(copy(r), Extend_Set(copy(known), n-known.n_set())); @@ -1626,8 +869,6 @@ bool is_single_loop_iteration(const Relation &r, int level, const Relation &know } - - bool is_single_iteration(const Relation &r, int dim) { assert(r.is_set()); const int n = r.n_set(); @@ -1637,11 +878,6 @@ bool is_single_iteration(const Relation &r, int dim) { Relation bound = get_loop_bound(r, dim); -// if (!bound.has_single_conjunct()) -// return false; - -// Conjunct *c = bound.query_DNF()->single_conjunct(); - for (DNF_Iterator di(bound.query_DNF()); di; di++) { bool is_single = false; for (EQ_Iterator ei((*di)->EQs()); ei; ei++) @@ -1655,78 +891,8 @@ bool is_single_iteration(const Relation &r, int dim) { } return true; - - - - -// Relation r = copy(r_); -// const int n = r.n_set(); - -// if (dim >= n) -// return true; - -// Relation bound = get_loop_bound(r, dim); -// bound = Approximate(bound); -// Conjunct *c = bound.query_DNF()->single_conjunct(); - -// return c->n_GEQs() == 0; - - - - - -// Relation r = copy(r_); -// r.simplify(); -// const int n = r.n_set(); - -// if (dim >= n) -// return true; - -// for (DNF_Iterator i(r.query_DNF()); i; i++) { -// std::vector<bool> is_single(n); -// for (int j = 0; j < dim; j++) -// is_single[j] = true; -// for (int j = dim; j < n; j++) -// is_single[j] = false; - -// bool found_new_single = true; -// while (found_new_single) { -// found_new_single = false; - -// for (EQ_Iterator j = (*i)->EQs(); j; j++) { -// int saved_pos = -1; -// for (Constr_Vars_Iter k(*j); k; k++) -// if ((*k).var->kind() == Set_Var || (*k).var->kind() == Input_Var) { -// int pos = (*k).var->get_position() - 1; -// if (!is_single[pos]) -// if (saved_pos == -1) -// saved_pos = pos; -// else { -// saved_pos = -1; -// break; -// } -// } - -// if (saved_pos != -1) { -// is_single[saved_pos] = true; -// found_new_single = true; -// } -// } - -// if (is_single[dim]) -// break; -// } - -// if (!is_single[dim]) -// return false; -// } - -// return true; } -//----------------------------------------------------------------------------- -// Set/get the value of a variable which is know to be constant. -//----------------------------------------------------------------------------- void assign_const(Relation &r, int dim, int val) { const int n = r.n_out(); @@ -1751,14 +917,10 @@ void assign_const(Relation &r, int dim, int val) { int get_const(const Relation &r, int dim, Var_Kind type) { -// Relation rr = copy(r); Relation &rr = const_cast<Relation &>(r); Variable_ID v; switch (type) { - // case Set_Var: - // v = rr.set_var(dim+1); - // break; case Input_Var: v = rr.input_var(dim+1); break; @@ -1777,19 +939,10 @@ int get_const(const Relation &r, int dim, Var_Kind type) { throw std::runtime_error("cannot get variable's constant value"); } - - - - - -//--------------------------------------------------------------------------- -// Get the bound for a specific loop. -//--------------------------------------------------------------------------- Relation get_loop_bound(const Relation &r, int dim) { assert(r.is_set()); const int n = r.n_set(); -// Relation r1 = project_onto_levels(copy(r), dim+1, true); Relation mapping(n,n); F_And *f_root = mapping.add_and(); for (int i = 1; i <= dim+1; i++) { @@ -1864,12 +1017,6 @@ Relation get_min_loop_bound(const std::vector<Relation> &r, int dim) { return res; } -//----------------------------------------------------------------------------- -// Add strident to a loop. -// Issues: -// - Don't work with relations with multiple disjuncts. -// - Omega's dealing with max lower bound is awkward. -//----------------------------------------------------------------------------- void add_loop_stride(Relation &r, const Relation &bound_, int dim, int stride) { F_And *f_root = r.and_with_and(); Relation &bound = const_cast<Relation &>(bound_); @@ -1953,15 +1100,6 @@ bool is_inner_loop_depend_on_level(const Relation &r, int level, const Relation return false; } - -//----------------------------------------------------------------------------- -// Suppose loop dim is i. Replace i with i+adjustment in loop bounds. -// e.g. do i = 1, n -// do j = i, n -// after call with dim = 0 and adjustment = 1: -// do i = 1, n -// do j = i+1, n -// ----------------------------------------------------------------------------- Relation adjust_loop_bound(const Relation &r, int level, int adjustment) { if (adjustment == 0) return copy(r); @@ -1998,236 +1136,6 @@ Relation adjust_loop_bound(const Relation &r, int level, int adjustment) { return r1; } - -// commented out on 07/14/2010 -// void adjust_loop_bound(Relation &r, int dim, int adjustment, std::vector<Free_Var_Decl *> globals) { -// assert(r.is_set()); - -// if (adjustment == 0) -// return; - -// const int n = r.n_set(); -// Tuple<std::string> name(n); -// for (int i = 1; i <= n; i++) -// name[i] = r.set_var(i)->name(); - -// Relation r1 = project_onto_levels(copy(r), dim+1, true); -// Relation r2 = Gist(copy(r), copy(r1)); - -// // remove old bogus global variable conditions since we are going to -// // update the value. -// if (globals.size() > 0) -// r1 = Gist(r1, project_onto_levels(copy(r), 0, true)); - -// Relation r4 = Relation::True(n); - -// for (DNF_Iterator di(r2.query_DNF()); di; di++) { -// for (EQ_Iterator ei = (*di)->EQs(); ei; ei++) { -// EQ_Handle h = r4.and_with_EQ(*ei); - -// Variable_ID v = r2.set_var(dim+1); -// coef_t c = (*ei).get_coef(v); -// if (c != 0) -// h.update_const(c*adjustment); - -// for (int i = 0; i < globals.size(); i++) { -// Variable_ID v = r2.get_local(globals[i]); -// coef_t c = (*ei).get_coef(v); -// if (c != 0) -// h.update_const(c*adjustment); -// } -// } - -// for (GEQ_Iterator gi = (*di)->GEQs(); gi; gi++) { -// GEQ_Handle h = r4.and_with_GEQ(*gi); - -// Variable_ID v = r2.set_var(dim+1); -// coef_t c = (*gi).get_coef(v); -// if (c != 0) -// h.update_const(c*adjustment); - -// for (int i = 0; i < globals.size(); i++) { -// Variable_ID v = r2.get_local(globals[i]); -// coef_t c = (*gi).get_coef(v); -// if (c != 0) -// h.update_const(c*adjustment); -// } -// } -// } -// r = Intersection(r1, r4); -// // } -// // else -// // r = Intersection(r1, r2); - -// for (int i = 1; i <= n; i++) -// r.name_set_var(i, name[i]); -// r.setup_names(); -// } - - -// void adjust_loop_bound(Relation &r, int dim, int adjustment) { -// assert(r.is_set()); -// const int n = r.n_set(); -// Tuple<String> name(n); -// for (int i = 1; i <= n; i++) -// name[i] = r.set_var(i)->name(); - -// Relation r1 = project_onto_levels(copy(r), dim+1, true); -// Relation r2 = Gist(r, copy(r1)); - -// Relation r3(n, n); -// F_And *f_root = r3.add_and(); -// for (int i = 0; i < n; i++) { -// EQ_Handle h = f_root->add_EQ(); -// h.update_coef(r3.output_var(i+1), 1); -// h.update_coef(r3.input_var(i+1), -1); -// if (i == dim) -// h.update_const(adjustment); -// } - -// r2 = Range(Restrict_Domain(r3, r2)); -// r = Intersection(r1, r2); - -// for (int i = 1; i <= n; i++) -// r.name_set_var(i, name[i]); -// r.setup_names(); -// } - -// void adjust_loop_bound(Relation &r, int dim, Free_Var_Decl *global_var, int adjustment) { -// assert(r.is_set()); -// const int n = r.n_set(); -// Tuple<String> name(n); -// for (int i = 1; i <= n; i++) -// name[i] = r.set_var(i)->name(); - -// Relation r1 = project_onto_levels(copy(r), dim+1, true); -// Relation r2 = Gist(r, copy(r1)); - -// Relation r3(n); -// Variable_ID v = r2.get_local(global_var); - -// for (DNF_Iterator di(r2.query_DNF()); di; di++) { -// for (EQ_Iterator ei = (*di)->EQs(); ei; ei++) { -// coef_t c = (*ei).get_coef(v); -// EQ_Handle h = r3.and_with_EQ(*ei); -// if (c != 0) -// h.update_const(c*adjustment); -// } -// for (GEQ_Iterator gi = (*di)->GEQs(); gi; gi++) { -// coef_t c = (*gi).get_coef(v); -// GEQ_Handle h = r3.and_with_GEQ(*gi); -// if (c != 0) -// h.update_const(c*adjustment); -// } -// } - -// r = Intersection(r1, r3); -// for (int i = 1; i <= n; i++) -// r.name_set_var(i, name[i]); -// r.setup_names(); -// } - - - -//------------------------------------------------------------------------------ -// If the dimension has value posInfinity, the statement should be privatized -// at this dimension. -//------------------------------------------------------------------------------ -// boolean is_private_statement(const Relation &r, int dim) { -// int n; -// if (r.is_set()) -// n = r.n_set(); -// else -// n = r.n_out(); - -// if (dim >= n) -// return false; - -// try { -// coef_t c; -// if (r.is_set()) -// c = get_const(r, dim, Set_Var); -// else -// c = get_const(r, dim, Output_Var); -// if (c == posInfinity) -// return true; -// else -// return false; -// } -// catch (loop_error e){ -// } - -// return false; -// } - - - -// // ---------------------------------------------------------------------------- -// // Calculate v mod dividend based on equations inside relation r. -// // Return posInfinity if it is not a constant. -// // ---------------------------------------------------------------------------- -// static coef_t mod_(const Relation &r_, Variable_ID v, int dividend, std::set<Variable_ID> &working_on) { -// assert(dividend > 0); -// if (v->kind() == Forall_Var || v->kind() == Exists_Var || v->kind() == Wildcard_Var) -// return posInfinity; - -// working_on.insert(v); - -// Relation &r = const_cast<Relation &>(r_); -// Conjunct *c = r.query_DNF()->single_conjunct(); - -// for (EQ_Iterator ei(c->EQs()); ei; ei++) { -// int coef = mod((*ei).get_coef(v), dividend); -// if (coef != 1 && coef != dividend - 1 ) -// continue; - -// coef_t result = 0; -// for (Constr_Vars_Iter cvi(*ei); cvi; cvi++) -// if ((*cvi).var != v) { -// int p = mod((*cvi).coef, dividend); - -// if (p == 0) -// continue; - -// if (working_on.find((*cvi).var) != working_on.end()) { -// result = posInfinity; -// break; -// } - -// coef_t q = mod_(r, (*cvi).var, dividend, working_on); -// if (q == posInfinity) { -// result = posInfinity; -// break; -// } -// result += p * q; -// } - -// if (result != posInfinity) { -// result += (*ei).get_const(); -// if (coef == 1) -// result = -result; -// working_on.erase(v); - -// return mod(result, dividend); -// } -// } - -// working_on.erase(v); -// return posInfinity; -// } - - -// coef_t mod(const Relation &r, Variable_ID v, int dividend) { -// std::set<Variable_ID> working_on = std::set<Variable_ID>(); - -// return mod_(r, v, dividend, working_on); -// } - - - -//----------------------------------------------------------------------------- -// Generate mapping relation for permuation. -//----------------------------------------------------------------------------- Relation permute_relation(const std::vector<int> &pi) { const int n = pi.size(); @@ -2243,11 +1151,6 @@ Relation permute_relation(const std::vector<int> &pi) { return r; } - - -//--------------------------------------------------------------------------- -// Find the position index variable in a Relation by name. -//--------------------------------------------------------------------------- Variable_ID find_index(Relation &r, const std::string &s, char side) { // Omega quirks: assure the names are propagated inside the relation r.setup_names(); @@ -2280,33 +1183,3 @@ Variable_ID find_index(Relation &r, const std::string &s, char side) { return NULL; } -// EQ_Handle get_eq(const Relation &r, int dim, Var_Kind type) { -// Variable_ID v; -// switch (type) { -// case Set_Var: -// v = r.set_var(dim+1); -// break; -// case Input_Var: -// v = r.input_var(dim+1); -// break; -// case Output_Var: -// v = r.output_var(dim+1); -// break; -// default: -// return NULL; -// } -// for (DNF_iterator di(r.query_DNF()); di; di++) -// for (EQ_Iterator ei = (*di)->EQs(); ei; ei++) -// if ((*ei).get_coef(v) != 0) -// return (*ei); - -// return NULL; -// } - - -// std::Pair<Relation, Relation> split_loop(const Relation &r, const Relation &cond) { -// Relation r1 = Intersection(copy(r), copy(cond)); -// Relation r2 = Intersection(copy(r), Complement(copy(cond))); - -// return std::Pair<Relation, Relation>(r1, r2); -// } diff --git a/omegalib/code_gen/src/CG_roseRepr.cc b/omegalib/code_gen/src/CG_roseRepr.cc index 99cf973..9265ab0 100644 --- a/omegalib/code_gen/src/CG_roseRepr.cc +++ b/omegalib/code_gen/src/CG_roseRepr.cc @@ -122,55 +122,4 @@ void CG_roseRepr::DumpFileHelper(SgNode* node, FILE *fp) const{ } } -/*void CG_roseRepr::DumpToFile(FILE *fp) const { -// std::string x; -SgNode* tnl = tnl_; -SgExpression* op = op_ ; - -if(tnl!= NULL){ - std::string x = tnl->unparseToString(); - fprintf(fp, "%s", x.c_str()); - -} -else if(op != NULL){ - std::string x = isSgNode(op)->unparseToString(); - fprintf(fp, "%s", x.c_str()); - - - -} -} -*/ -/* -SgNode* CG_roseRepr::copyAST ( SgNode* node ) -{ - -// This is a better implementation using a derived class from SgCopyHelp to control the -// copying process (skipping the copy of any function definition). This is a variable -// declaration with an explicitly declared class type. -class RestrictedCopyType : public SgCopyHelp - { - // DQ (9/26/2005): This class demonstrates the use of the copy mechanism - // within Sage III (originally designed and implemented by Qing Yi). - // One problem with it is that there is no context information permitted. - - public: - virtual SgNode *copyAst(const SgNode *n) - { - // This is the simpliest possible version of a deep copy SgCopyHelp::copyAst() member function. - SgNode *returnValue = n->copy(*this); - - return returnValue; - } - } restrictedCopyType; - - - - -// This triggers a bug with test2005_152.C (the unparsed code fails for g++ 4.1.2, but not 3.5.6) -SgNode* copyOfNode = node->copy(restrictedCopyType); -return copyOfNode; - -} -*/ } // namespace |