diff options
| author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-19 15:50:07 -0600 | 
|---|---|---|
| committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-19 15:50:07 -0600 | 
| commit | a9ed06bec80a2a975102195b5b7b4fe7fece3d38 (patch) | |
| tree | b7a92badcfa410c4b57870c78226429bd50d2bfe /lib/rosecg/include/code_gen | |
| parent | 210f77d2c32f14d2e99577fd3c9842bb19d47e50 (diff) | |
| download | chill-a9ed06bec80a2a975102195b5b7b4fe7fece3d38.tar.gz chill-a9ed06bec80a2a975102195b5b7b4fe7fece3d38.tar.bz2 chill-a9ed06bec80a2a975102195b5b7b4fe7fece3d38.zip  | |
change rosecg path & add install
Diffstat (limited to 'lib/rosecg/include/code_gen')
| -rw-r--r-- | lib/rosecg/include/code_gen/CG_roseBuilder.h | 108 | ||||
| -rw-r--r-- | lib/rosecg/include/code_gen/CG_roseRepr.h | 46 | ||||
| -rw-r--r-- | lib/rosecg/include/code_gen/rose_attributes.h | 91 | 
3 files changed, 245 insertions, 0 deletions
diff --git a/lib/rosecg/include/code_gen/CG_roseBuilder.h b/lib/rosecg/include/code_gen/CG_roseBuilder.h new file mode 100644 index 0000000..ca33f7e --- /dev/null +++ b/lib/rosecg/include/code_gen/CG_roseBuilder.h @@ -0,0 +1,108 @@ +#ifndef CG_roseBuilder_h +#define CG_roseBuilder_h + +#include <basic/Tuple.h> +#include "code_gen/rose_attributes.h" +#include <code_gen/CG_outputBuilder.h> +#include "code_gen/CG_roseRepr.h" +#include <string> + +namespace omega { + +class CG_roseBuilder : public CG_outputBuilder {  +public: +  CG_roseBuilder(int isFortran, SgGlobal* global, SgGlobal* global_scope, SgSymbolTable* symtab1, SgSymbolTable* symtab2,  SgNode* root); +  ~CG_roseBuilder(); +    +  //! 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 +   CG_outputRepr* CreateAssignment(int indent, CG_outputRepr* lhs, +                                          CG_outputRepr* rhs) const; + +  //! function invocation generation +    CG_outputRepr* CreateInvoke(const std::string &funcName, +    		std::vector<CG_outputRepr *> &argList) const; +   +  //! comment generation +   CG_outputRepr* CreateComment(int indent, const std::string &commentText) const; +  //! Attribute generation +    CG_outputRepr* CreateAttribute(CG_outputRepr  *control, +                                          const std::string &commentText) const; +  //! Pragma Attribute +  CG_outputRepr* CreatePragmaAttribute(CG_outputRepr *scopeStmt, int looplevel, +                                          const std::string &pragmaText) const; +   +  //! Prefetch Attribute +  CG_outputRepr* CreatePrefetchAttribute(CG_outputRepr *scopeStmt, int looplevel, +                                          const std::string &arrName, int hint) const; + +  //! 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 +   CG_outputRepr* CreateInductive(CG_outputRepr* index, +                                         CG_outputRepr* lower, +                                         CG_outputRepr* upper, +                                         CG_outputRepr* step) const; + +  //! loop stmt generation +   CG_outputRepr* CreateLoop(int indent, CG_outputRepr* control, +                                    CG_outputRepr* stmtList) const; + +   CG_outputRepr* CreateInt(int num ) const; +   bool isInteger(CG_outputRepr *op) const; +   CG_outputRepr* CreateIdent(const std::string &varName) const; + +   //! 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 +   CG_outputRepr* CreateAnd(CG_outputRepr* lop, CG_outputRepr* rop) const; + +  //--------------------------------------------------------------------------- +  // binary relational operations +  //--------------------------------------------------------------------------- +  // CG_outputRepr* CreateGE(CG_outputRepr*, CG_outputRepr*) const; +   CG_outputRepr* CreateLE(CG_outputRepr* lop, CG_outputRepr* rop) const; +   CG_outputRepr* CreateEQ(CG_outputRepr* lop, CG_outputRepr* rop) const; +      +  //--------------------------------------------------------------------------- +  // stmt list gen operations +  //--------------------------------------------------------------------------- +   CG_outputRepr* +    StmtListAppend(CG_outputRepr* list1, CG_outputRepr* list2) 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; + +private: +  SgSymbolTable *symtab_; +  SgSymbolTable *symtab2_; +  SgNode* root_; +  SgGlobal* global_; +  SgGlobal* global_scope; +  int isFortran; // Manu:: added for fortran support +}; + +extern char *k_ocg_comment; +std::vector<SgVarRefExp *>substitute(SgNode *tnl, const SgVariableSymbol *sym, SgExpression *expr,SgNode* root) ; + + + + +} // namespace + +#endif diff --git a/lib/rosecg/include/code_gen/CG_roseRepr.h b/lib/rosecg/include/code_gen/CG_roseRepr.h new file mode 100644 index 0000000..28553e7 --- /dev/null +++ b/lib/rosecg/include/code_gen/CG_roseRepr.h @@ -0,0 +1,46 @@ +#ifndef CG_roseRepr_h +#define CG_roseRepr_h + +#include <code_gen/CG_outputRepr.h> +#include "rose.h" + +namespace omega { + +class CG_roseRepr : public CG_outputRepr { +  friend class CG_roseBuilder; +public: +  CG_roseRepr(); +  CG_roseRepr(SgNode *tnl); +  CG_roseRepr(SgExpression *exp); +  CG_roseRepr(SgStatementPtrList* stmtlist); + +  ~CG_roseRepr(); +  CG_outputRepr *clone() const; +  void clear(); + +  SgNode* GetCode() const; +  SgStatementPtrList* GetList() const; +  SgExpression *GetExpression() const; + + + + +  //--------------------------------------------------------------------------- +  // Dump operations +  //--------------------------------------------------------------------------- +  void Dump() 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 +  SgNode  *tnl_; +  SgExpression  *op_; +  SgStatementPtrList *list_; +  void DumpFileHelper(SgNode* node, FILE* fp) const;  +  //operand op_; +}; + + + +} // namespace + +#endif diff --git a/lib/rosecg/include/code_gen/rose_attributes.h b/lib/rosecg/include/code_gen/rose_attributes.h new file mode 100644 index 0000000..9766f52 --- /dev/null +++ b/lib/rosecg/include/code_gen/rose_attributes.h @@ -0,0 +1,91 @@ +#ifndef ROSE_ATTRIBUTES_HH +#define ROSE_ATTRIBUTES_HH + +#include "rose.h" +#include <algorithm> +#include <string> +#include <vector> + +namespace omega { + +class CodeInsertion; + +typedef std::vector<CodeInsertion*> CodeInsertionPtrList; +typedef std::vector<CodeInsertion*>::iterator CodeInsertionPtrListItr; + +class CodeInsertion { +public: +	int loop_level; +	bool marked; +	CodeInsertion(int looplevel) { this->loop_level = looplevel; marked = false; } +	~CodeInsertion() {} +	virtual SgStatement* getStatement(SgScopeStatement* scopeStmt = NULL) = 0; +}; + +class PragmaInsertion : public CodeInsertion { +private: +	std::string name; +public: +	PragmaInsertion(int loop_level, const std::string &pragma) : CodeInsertion(loop_level) { this->name = std::string(pragma); } +	~PragmaInsertion() { } +	virtual SgStatement* getStatement(SgScopeStatement* scopeStmt = NULL); +}; + +class MMPrefetchInsertion : public CodeInsertion { +private: +	std::string arrName; +	std::vector<std::string*> indecies; +	std::vector<int> offsets; +	int indexCount; +	int cacheHint; +	void initialize(const std::string& arrName, int hint); +	void addDim(int offset); +	void addDim(int offset, const std::string& indexer); +	SgExpression* buildArrArg(SgScopeStatement* scopeStmt); +	SgExpression* makeIndexExp(int dim, SgScopeStatement* scopeStmt); +public: +	MMPrefetchInsertion(int loop_level, const std::string &arr, int hint) : CodeInsertion(loop_level) +		{ this->initialize(arr, hint); } +	~MMPrefetchInsertion() { } +	virtual SgStatement* getStatement(SgScopeStatement* scopeStmt = NULL); +}; + +class CodeInsertionAttribute : public AstAttribute { +private: +	std::vector<CodeInsertion*> code_insertions; +public: +	CodeInsertionAttribute() { code_insertions = std::vector<CodeInsertion*>(); } +	~CodeInsertionAttribute() {} +	 +	void add(CodeInsertion* ci) { code_insertions.push_back(ci); } +	CodeInsertionPtrListItr begin() { return code_insertions.begin(); } +	CodeInsertionPtrListItr end() { return code_insertions.end(); } +	void remove(CodeInsertion* ci) { std::remove(code_insertions.begin(), code_insertions.end(), ci); } +	int countCodeInsertions() { return code_insertions.size(); } +}; + +struct CodeInsertionMark { +public: +	SgStatement* stmt; +	CodeInsertion* ci; +}; + +class CodeInsertionVisitor : public AstPrePostProcessing { +private: +	int loop_level; +	std::vector<CodeInsertionMark*> ci_marks; +	void markStmt(SgStatement* stmt, CodeInsertion* ci); +public: +	void initialize(); +	virtual void preOrderVisit(SgNode* n); +	virtual void postOrderVisit(SgNode* n); +	void insertCode(); +}; + +void postProcessRoseCodeInsertion(SgProject* proj); +void copyAttributes(SgNode* s, SgNode* d); +CodeInsertionAttribute* getOrCreateCodeInsertionAttribute(SgNode* node); + +} + +#endif  | 
