diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-18 15:16:52 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-18 15:16:52 -0600 |
commit | 18644419b50b2b14a24456e0fcdb210f231ee317 (patch) | |
tree | 3d2a57050ae93ee0ceb71df319b1533480a4001d /omegalib/codegen/include/code_gen | |
parent | 2fce43d484e4148ae858f410d51dcd9951d34374 (diff) | |
download | chill-18644419b50b2b14a24456e0fcdb210f231ee317.tar.gz chill-18644419b50b2b14a24456e0fcdb210f231ee317.tar.bz2 chill-18644419b50b2b14a24456e0fcdb210f231ee317.zip |
doc updated for code_gen
Diffstat (limited to 'omegalib/codegen/include/code_gen')
-rw-r--r-- | omegalib/codegen/include/code_gen/CG_outputBuilder.h | 116 | ||||
-rw-r--r-- | omegalib/codegen/include/code_gen/CG_outputRepr.h | 6 | ||||
-rw-r--r-- | omegalib/codegen/include/code_gen/CG_roseBuilder.h | 80 | ||||
-rw-r--r-- | omegalib/codegen/include/code_gen/CG_roseRepr.h | 1 | ||||
-rw-r--r-- | omegalib/codegen/include/code_gen/CG_suifBuilder.h | 88 | ||||
-rw-r--r-- | omegalib/codegen/include/code_gen/CG_suifRepr.h | 36 | ||||
-rwxr-xr-x | omegalib/codegen/include/code_gen/codegen.h | 12 |
7 files changed, 74 insertions, 265 deletions
diff --git a/omegalib/codegen/include/code_gen/CG_outputBuilder.h b/omegalib/codegen/include/code_gen/CG_outputBuilder.h index 2203235..19dc440 100644 --- a/omegalib/codegen/include/code_gen/CG_outputBuilder.h +++ b/omegalib/codegen/include/code_gen/CG_outputBuilder.h @@ -29,76 +29,57 @@ namespace omega { +//! abstract base class of comiler IR code builder class CG_outputBuilder { public: CG_outputBuilder() {} virtual ~CG_outputBuilder() {} - //--------------------------------------------------------------------------- - // substitute variables in stmt - //--------------------------------------------------------------------------- + //! substitute variables in stmt virtual CG_outputRepr *CreateSubstitutedStmt(int indent, CG_outputRepr *stmt, const std::vector<std::string> &vars, std::vector<CG_outputRepr *> &subs) const = 0; - //--------------------------------------------------------------------------- - // assignment stmt generation - //--------------------------------------------------------------------------- + //! assignment stmt generation virtual CG_outputRepr *CreateAssignment(int indent, CG_outputRepr *lhs, CG_outputRepr *rhs) const = 0; - //--------------------------------------------------------------------------- - // function invocation generation - //--------------------------------------------------------------------------- + //! function invocation generation virtual CG_outputRepr *CreateInvoke(const std::string &funcName, std::vector<CG_outputRepr *> &argList) const = 0; - //--------------------------------------------------------------------------- - // comment generation - //--------------------------------------------------------------------------- + //! comment generation virtual CG_outputRepr *CreateComment(int indent, const std::string &commentText) const = 0; - //--------------------------------------------------------------------------- - // Attribute generation - //--------------------------------------------------------------------------- + //! Attribute generation virtual CG_outputRepr* CreateAttribute(CG_outputRepr *control, const std::string &commentText) const = 0; - //--------------------------------------------------------------------------- - // Pragma Attribute - // -------------------------------------------------------------------------- + //! Pragma Attribute virtual CG_outputRepr* CreatePragmaAttribute(CG_outputRepr *scopeStmt, int looplevel, const std::string &pragmaText) const = 0; - //--------------------------------------------------------------------------- - // Prefetch Attribute - //--------------------------------------------------------------------------- + //! Prefetch Attribute virtual CG_outputRepr* CreatePrefetchAttribute(CG_outputRepr *scopeStmt, int looplevel, const std::string &arrName, int hint) const = 0; - //--------------------------------------------------------------------------- - // generate if stmt, true/false stmt can be NULL but not the condition - //--------------------------------------------------------------------------- + //! generate if stmt, true/false stmt can be NULL but not the condition virtual CG_outputRepr *CreateIf(int indent, CG_outputRepr *guardCondition, CG_outputRepr *true_stmtList, CG_outputRepr *false_stmtList) const = 0; - //--------------------------------------------------------------------------- - // generate loop inductive variable (loop control structure) - //--------------------------------------------------------------------------- + //! generate loop inductive variable (loop control structure) virtual CG_outputRepr *CreateInductive(CG_outputRepr *index, CG_outputRepr *lower, CG_outputRepr *upper, CG_outputRepr *step) const = 0; - //--------------------------------------------------------------------------- - // generate loop stmt from loop control and loop body, NULL parameter allowed - //--------------------------------------------------------------------------- + //! generate loop stmt from loop control and loop body, NULL parameter allowed virtual CG_outputRepr *CreateLoop(int indent, CG_outputRepr *control, CG_outputRepr *stmtList) const = 0; - //--------------------------------------------------------------------------- - // copy operation, NULL parameter allowed. this function makes pointer - // handling uniform regardless NULL status - //--------------------------------------------------------------------------- + //! copy operation, NULL parameter allowed. + /*! + * this function makes pointer handling uniform regardless NULL status + */ virtual CG_outputRepr *CreateCopy(CG_outputRepr *original) const { if (original == NULL) return NULL; @@ -106,69 +87,72 @@ public: return original->clone(); } - //--------------------------------------------------------------------------- - // basic integer number creation - //--------------------------------------------------------------------------- + //! basic integer number creation virtual CG_outputRepr *CreateInt(int num) const = 0; virtual bool isInteger(CG_outputRepr *op) const = 0; - //--------------------------------------------------------------------------- - // basic identity/variable creation - //--------------------------------------------------------------------------- + //! basic identity/variable creation virtual CG_outputRepr *CreateIdent(const std::string &varName) const = 0; - //--------------------------------------------------------------------------- - // binary arithmetic operations, NULL parameter means 0, - // Note: - // integer division truncation method undefined, only use when lop is known - // to be multiple of rop, otherwise use integer floor instead - //--------------------------------------------------------------------------- + //! Addition operations, NULL parameter means 0, virtual CG_outputRepr *CreatePlus(CG_outputRepr *lop, CG_outputRepr *rop) const = 0; + //! Subtraction operations, NULL parameter means 0, virtual CG_outputRepr *CreateMinus(CG_outputRepr *lop, CG_outputRepr *rop) const = 0; + //! Multiplication operations, NULL parameter means 0, virtual CG_outputRepr *CreateTimes(CG_outputRepr *lop, CG_outputRepr *rop) const = 0; + //! Division operations, NULL parameter means 0, + /*! + * integer division truncation method undefined, only use when lop is known + * to be multiple of rop, otherwise use integer floor instead + */ virtual CG_outputRepr *CreateDivide(CG_outputRepr *lop, CG_outputRepr *rop) const { return CreateIntegerFloor(lop, rop); } - //--------------------------------------------------------------------------- - // integer arithmetic functions, NULL parameter means 0, second parameter - // must be postive (i.e. b > 0 below), otherwise function undefined - // Note: - // ceil(a, b) = -floor(-a, b) or floor(a+b-1, b) or floor(a-1, b)+1 - // mod(a, b) = a-b*floor(a, b) - // where result must lie in range [0,b) - // floor(a, b) = a/b if a >= 0 - // (a-b+1)/b if a < 0 - // where native '/' operator behaves as 5/2 = 2, (-5)/2 = -2 - //--------------------------------------------------------------------------- + //! integer floor functions, NULL parameter means 0 + /*! + * second parameter must be postive (i.e. b > 0 below), otherwise function undefined + * + * floor(a, b) + * * = a/b if a >= 0 + * * = (a-b+1)/b if a < 0 + */ virtual CG_outputRepr *CreateIntegerFloor(CG_outputRepr *lop, CG_outputRepr *rop) const = 0; + //! integer mod functions, NULL parameter means 0 + /*! + * second parameter must be postive (i.e. b > 0 below), otherwise function undefined + * + * mod(a, b) = a-b*floor(a, b) where result must lie in range [0,b) + */ virtual CG_outputRepr *CreateIntegerMod(CG_outputRepr *lop, CG_outputRepr *rop) const { CG_outputRepr *lop2 = CreateCopy(lop); CG_outputRepr *rop2 = CreateCopy(rop); return CreateMinus(lop2, CreateTimes(rop2, CreateIntegerFloor(lop, rop))); } + //! integer ceil functions, NULL parameter means 0 + /*! + * second parameter must be postive (i.e. b > 0 below), otherwise function undefined + * + * ceil(a, b) = -floor(-a, b) or floor(a+b-1, b) or floor(a-1, b)+1 + */ virtual CG_outputRepr *CreateIntegerCeil(CG_outputRepr *lop, CG_outputRepr *rop) const { return CreateMinus(NULL, CreateIntegerFloor(CreateMinus(NULL, lop), rop)); } - //--------------------------------------------------------------------------- - // binary logical operation, NULL parameter means TRUE - //--------------------------------------------------------------------------- + //! binary logical operation, NULL parameter means TRUE virtual CG_outputRepr *CreateAnd(CG_outputRepr *lop, CG_outputRepr *rop) const = 0; - //--------------------------------------------------------------------------- - // binary condition operations - //--------------------------------------------------------------------------- + //! binary conditional Greater than or equal to virtual CG_outputRepr *CreateGE(CG_outputRepr *lop, CG_outputRepr *rop) const { return CreateLE(rop, lop); } + //! binary conditional Less than or equal to virtual CG_outputRepr *CreateLE(CG_outputRepr *lop, CG_outputRepr *rop) const = 0; + //! binary conditional equal to virtual CG_outputRepr *CreateEQ(CG_outputRepr *lop, CG_outputRepr *rop) const = 0; - //--------------------------------------------------------------------------- - // join stmts together, NULL parameter allowed - //--------------------------------------------------------------------------- + //! join stmts together, NULL parameter allowed virtual CG_outputRepr *StmtListAppend(CG_outputRepr *list1, CG_outputRepr *list2) const = 0; }; diff --git a/omegalib/codegen/include/code_gen/CG_outputRepr.h b/omegalib/codegen/include/code_gen/CG_outputRepr.h index 92f3d9f..0897007 100644 --- a/omegalib/codegen/include/code_gen/CG_outputRepr.h +++ b/omegalib/codegen/include/code_gen/CG_outputRepr.h @@ -20,9 +20,11 @@ namespace omega { class CG_outputRepr { public: CG_outputRepr() {} - virtual ~CG_outputRepr() { /* shallow delete */ } + //! shallow delete + virtual ~CG_outputRepr() { } virtual CG_outputRepr *clone() const = 0; - virtual void clear() { /* delete actual IR code wrapped inside */ } + //! delete actual IR code wrapped inside + virtual void clear() { } virtual void dump() const {} }; diff --git a/omegalib/codegen/include/code_gen/CG_roseBuilder.h b/omegalib/codegen/include/code_gen/CG_roseBuilder.h index 93b708e..5dad663 100644 --- a/omegalib/codegen/include/code_gen/CG_roseBuilder.h +++ b/omegalib/codegen/include/code_gen/CG_roseBuilder.h @@ -14,98 +14,60 @@ public: CG_roseBuilder(int isFortran, SgGlobal* global, SgGlobal* global_scope, SgSymbolTable* symtab1, SgSymbolTable* symtab2, SgNode* root); ~CG_roseBuilder(); - //--------------------------------------------------------------------------- - // place holder generation - //--------------------------------------------------------------------------- - // CG_outputRepr* CreatePlaceHolder(int indent, CG_outputRepr *stmt, - // Tuple<CG_outputRepr*> &funcList, - // Tuple<std::string> &loop_vars) const; - - - //--------------------------------------------------------------------------- - // substitute variables in stmt - //--------------------------------------------------------------------------- - - - + //! substitute variables in stmt CG_outputRepr *CreateSubstitutedStmt(int indent, CG_outputRepr *stmt, const std::vector<std::string> &vars, std::vector<CG_outputRepr *> &subs) const; - //--------------------------------------------------------------------------- - // assignment generation - //--------------------------------------------------------------------------- + //! assignment generation CG_outputRepr* CreateAssignment(int indent, CG_outputRepr* lhs, CG_outputRepr* rhs) const; - //--------------------------------------------------------------------------- - // function invocation generation - //--------------------------------------------------------------------------- + //! function invocation generation CG_outputRepr* CreateInvoke(const std::string &funcName, std::vector<CG_outputRepr *> &argList) const; - //--------------------------------------------------------------------------- - // comment generation - //--------------------------------------------------------------------------- + //! comment generation CG_outputRepr* CreateComment(int indent, const std::string &commentText) const; - //--------------------------------------------------------------------------- - // Attribute generation - //--------------------------------------------------------------------------- + //! Attribute generation CG_outputRepr* CreateAttribute(CG_outputRepr *control, const std::string &commentText) const; - //--------------------------------------------------------------------------- - // Pragma Attribute - //--------------------------------------------------------------------------- + //! Pragma Attribute CG_outputRepr* CreatePragmaAttribute(CG_outputRepr *scopeStmt, int looplevel, const std::string &pragmaText) const; - //--------------------------------------------------------------------------- - // Prefetch Attribute - //--------------------------------------------------------------------------- + //! Prefetch Attribute CG_outputRepr* CreatePrefetchAttribute(CG_outputRepr *scopeStmt, int looplevel, const std::string &arrName, int hint) const; - //--------------------------------------------------------------------------- - // if stmt gen operations - //--------------------------------------------------------------------------- + //! if stmt gen operations CG_outputRepr* CreateIf(int indent, CG_outputRepr* guardCondition, CG_outputRepr* true_stmtList, CG_outputRepr* false_stmtList) const; - //--------------------------------------------------------------------------- - // inductive variable generation, to be used in CreateLoop as control - //--------------------------------------------------------------------------- + //! inductive variable generation, to be used in CreateLoop as control CG_outputRepr* CreateInductive(CG_outputRepr* index, CG_outputRepr* lower, CG_outputRepr* upper, CG_outputRepr* step) const; - //--------------------------------------------------------------------------- - // loop stmt generation - //--------------------------------------------------------------------------- + //! loop stmt generation CG_outputRepr* CreateLoop(int indent, CG_outputRepr* control, CG_outputRepr* stmtList) const; - //--------------------------------------------------------------------------- - // basic operations - //--------------------------------------------------------------------------- CG_outputRepr* CreateInt(int num ) const; bool isInteger(CG_outputRepr *op) const; CG_outputRepr* CreateIdent(const std::string &varName) const; - //--------------------------------------------------------------------------- - // binary arithmetic operations - //--------------------------------------------------------------------------- + //! binary arithmetic operations CG_outputRepr* CreatePlus(CG_outputRepr* lop, CG_outputRepr* rop) const; CG_outputRepr* CreateMinus(CG_outputRepr* lop, CG_outputRepr* rop) const; CG_outputRepr* CreateTimes(CG_outputRepr* lop, CG_outputRepr* rop) const; CG_outputRepr* CreateIntegerFloor(CG_outputRepr* lop, CG_outputRepr* rop) const; CG_outputRepr* CreateIntegerMod(CG_outputRepr* lop, CG_outputRepr* rop) const; - //--------------------------------------------------------------------------- - // binary logical operations - //--------------------------------------------------------------------------- + //! binary logical operations CG_outputRepr* CreateAnd(CG_outputRepr* lop, CG_outputRepr* rop) const; //--------------------------------------------------------------------------- @@ -118,30 +80,14 @@ public: //--------------------------------------------------------------------------- // stmt list gen operations //--------------------------------------------------------------------------- - // CG_outputRepr* - // CreateStmtList(CG_outputRepr *singleton = NULL) const; - // CG_outputRepr* - // StmtListInsertLast(CG_outputRepr* list, CG_outputRepr* node) const; CG_outputRepr* StmtListAppend(CG_outputRepr* list1, CG_outputRepr* list2) const; - //CG_outputRepr* CreateDim3(const char* varName, int arg1, int arg2) const; CG_outputRepr* CreateDim3(const char* varName, CG_outputRepr* arg1, CG_outputRepr* arg2, CG_outputRepr* arg3 = NULL) const; // Manu:: added for fortran support bool isInputFortran() const; - //--------------------------------------------------------------------------- - // kernel generation - //--------------------------------------------------------------------------- - // CG_outputRepr* CreateKernel(immed_list* iml) const; - - //--------------------------------------------------------------------------- - // Add a modifier to a type (for things like __global__) - //--------------------------------------------------------------------------- - //type_node* ModifyType(type_node* base, const char* modifier) const; - - private: SgSymbolTable *symtab_; SgSymbolTable *symtab2_; @@ -152,8 +98,6 @@ private: }; extern char *k_ocg_comment; - //bool substitute(SgExpression *in, SgVariableSymbol *sym, SgExpression *expr, SgNode* root, SgExpression* parent); - //bool substitute(SgStatement *tn, SgVariableSymbol *sym, SgExpression* expr, SgNode* root, SgSymbolTable* symtab); std::vector<SgVarRefExp *>substitute(SgNode *tnl, const SgVariableSymbol *sym, SgExpression *expr,SgNode* root) ; diff --git a/omegalib/codegen/include/code_gen/CG_roseRepr.h b/omegalib/codegen/include/code_gen/CG_roseRepr.h index 4861db7..28553e7 100644 --- a/omegalib/codegen/include/code_gen/CG_roseRepr.h +++ b/omegalib/codegen/include/code_gen/CG_roseRepr.h @@ -29,7 +29,6 @@ public: // Dump operations //--------------------------------------------------------------------------- void Dump() const; - //void DumpToFile(FILE *fp = stderr) const; private: // only one of _tnl and _op would be active at any time, depending on // whether it is building a statement list or an expression tree diff --git a/omegalib/codegen/include/code_gen/CG_suifBuilder.h b/omegalib/codegen/include/code_gen/CG_suifBuilder.h deleted file mode 100644 index 9f57e3d..0000000 --- a/omegalib/codegen/include/code_gen/CG_suifBuilder.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef CG_suifBuilder_h -#define CG_suifBuilder_h - -#include <basic/Tuple.h> -#include <code_gen/CG_outputBuilder.h> -#include <code_gen/CG_suifRepr.h> -#include <string> - -namespace omega { - - -class CG_suifBuilder: public CG_outputBuilder { -public: - //CG_suifBuilder(proc_symtab *symtab) {symtab_ = symtab;} - CG_suifBuilder(proc_symtab *symtab); - //protonu--initializing code_gen stuff for cuda - //this looks like a flaw in my design - //end--protonu - ~CG_suifBuilder() {} - - CG_outputRepr* CreatePlaceHolder(int indent, CG_outputRepr *stmt, - Tuple<CG_outputRepr*> &funcList, - Tuple<std::string> &loop_vars) const; - CG_outputRepr* CreateAssignment(int indent, CG_outputRepr* lhs, - CG_outputRepr* rhs) const; - CG_outputRepr* CreateInvoke(const std::string &fname, - Tuple<CG_outputRepr*> &argList) const; - CG_outputRepr* CreateComment(int indent, const std::string &commentText) const; - CG_outputRepr* CreateAttribute(CG_outputRepr *control, - const std::string &commentText) const; - - CG_outputRepr* CreateIf(int indent, CG_outputRepr* guardCondition, - CG_outputRepr* true_stmtList, CG_outputRepr* false_stmtList) const; - CG_outputRepr* CreateInductive(CG_outputRepr* index, - CG_outputRepr* lower, - CG_outputRepr* upper, - CG_outputRepr* step) const; - CG_outputRepr* CreateLoop(int indent, CG_outputRepr* control, - CG_outputRepr* stmtList) const; - CG_outputRepr* CreateInt(int) const; - CG_outputRepr* CreateIdent(const std::string &idStr) const; - CG_outputRepr* CreatePlus(CG_outputRepr*, CG_outputRepr*) const; - CG_outputRepr* CreateMinus(CG_outputRepr*, CG_outputRepr*) const; - CG_outputRepr* CreateTimes(CG_outputRepr*, CG_outputRepr*) const; - CG_outputRepr* CreateIntegerDivide(CG_outputRepr*, CG_outputRepr*) const; - CG_outputRepr* CreateIntegerMod(CG_outputRepr*, CG_outputRepr*) const; - CG_outputRepr* CreateAnd(CG_outputRepr*, CG_outputRepr*) const; - CG_outputRepr* CreateGE(CG_outputRepr*, CG_outputRepr*) const; - CG_outputRepr* CreateLE(CG_outputRepr*, CG_outputRepr*) const; - CG_outputRepr* CreateEQ(CG_outputRepr*, CG_outputRepr*) const; - CG_outputRepr* StmtListAppend(CG_outputRepr* list1, CG_outputRepr* list2) const; - //--------------------------------------------------------------------------- - // pragma generation - //--------------------------------------------------------------------------- - virtual CG_outputRepr* CreatePragma(int indent, const std::string &pragmaText) const; - - //--------------------------------------------------------------------------- - // dim3 generation - //--------------------------------------------------------------------------- - virtual CG_outputRepr* CreateDim3(immed varName, immed arg1, immed arg2) const; - virtual CG_outputRepr* CreateDim3(immed varName, immed arg1, immed arg2, immed arg3) const; - - - //--------------------------------------------------------------------------- - // kernel generation - //--------------------------------------------------------------------------- - virtual CG_outputRepr* CreateKernel(immed_list* iml) const; - - //--------------------------------------------------------------------------- - // Add a modifier to a type (for things like __global__) - //--------------------------------------------------------------------------- - type_node* ModifyType(type_node* base, const char* modifier) const; -private: - proc_symtab *symtab_; -}; - -extern char *k_ocg_comment; - -bool substitute(instruction *in, var_sym *sym, operand expr, - base_symtab *st=NULL); -bool substitute(tree_node *tn, var_sym *sym, operand expr, - base_symtab *st=NULL); -bool substitute(tree_node_list *tnl, var_sym *sym, operand expr, - base_symtab *st = NULL); - -} - -#endif diff --git a/omegalib/codegen/include/code_gen/CG_suifRepr.h b/omegalib/codegen/include/code_gen/CG_suifRepr.h deleted file mode 100644 index ce7c6cd..0000000 --- a/omegalib/codegen/include/code_gen/CG_suifRepr.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef CG_suifRepr_h -#define CG_suifRepr_h - -#include <code_gen/CG_outputRepr.h> -#include <suif1.h> - -namespace omega { - -class CG_suifRepr : public CG_outputRepr { - friend class CG_suifBuilder; -public: - CG_suifRepr(); - CG_suifRepr(tree_node_list *tnl); - CG_suifRepr(operand op); - virtual ~CG_suifRepr(); - virtual CG_outputRepr *clone(); - virtual void clear(); - - tree_node_list* GetCode() const; - operand GetExpression() const; - - //--------------------------------------------------------------------------- - // Dump operations - //--------------------------------------------------------------------------- - virtual void Dump() const; - virtual void DumpToFile(FILE *fp = stderr) const; -private: - // only one of _tnl and _op would be active at any time, depending on - // whether it is building a statement list or an expression tree - tree_node_list *tnl_; - operand op_; -}; - -} // namespace - -#endif diff --git a/omegalib/codegen/include/code_gen/codegen.h b/omegalib/codegen/include/code_gen/codegen.h index 469653d..cb63bfd 100755 --- a/omegalib/codegen/include/code_gen/codegen.h +++ b/omegalib/codegen/include/code_gen/codegen.h @@ -15,10 +15,14 @@ public: static const int var_substitution_threshold; protected: - std::vector<std::vector<Relation> > projected_IS_; // projected_IS_[level-1][new stmt#] - std::vector<Relation> xforms_; // transformations[original stmt#] - Relation known_; // no need to generate code for constraints satisfied in known - std::vector<int> remap_; // map new stmt# to original stmt# + //! projected_IS_[level-1][new stmt#] + std::vector<std::vector<Relation> > projected_IS_; + //! transformations[original stmt#] + std::vector<Relation> xforms_; + //! no need to generate code for constraints satisfied in known + Relation known_; + //! map new stmt# to original stmt# + std::vector<int> remap_; public: CodeGen(const std::vector<Relation> &xforms, const std::vector<Relation> &IS, const Relation &known = Relation::Null(), |