summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/chillAST/chillAST_def.hh90
-rw-r--r--include/chillAST/chillAST_node.hh665
-rw-r--r--include/chillAST/chillASTs.hh2174
-rw-r--r--include/chill_error.hh16
-rw-r--r--include/chilldebug.h6
-rw-r--r--include/chillmodule.hh2
-rw-r--r--include/dep.hh52
-rw-r--r--include/graph.hh103
-rwxr-xr-xinclude/ir_clang.hh299
-rw-r--r--include/ir_code.hh258
-rw-r--r--include/ir_enums.hh1
-rw-r--r--include/irtools.hh34
-rw-r--r--include/loop.hh4
-rw-r--r--include/omegatools.hh74
-rw-r--r--include/stencil.hh23
15 files changed, 2236 insertions, 1565 deletions
diff --git a/include/chillAST/chillAST_def.hh b/include/chillAST/chillAST_def.hh
index 318b51b..0e5832e 100644
--- a/include/chillAST/chillAST_def.hh
+++ b/include/chillAST/chillAST_def.hh
@@ -19,7 +19,7 @@
#define CHILLAST_NODETYPE_TRANSLATIONUNIT CHILLAST_NODETYPE_SOURCEFILE
enum CHILL_ASTNODE_TYPE {
- CHILLAST_NODETYPE_UNKNOWN=0,
+ CHILLAST_NODETYPE_UNKNOWN = 0,
CHILLAST_NODETYPE_SOURCEFILE,
CHILLAST_NODETYPE_TYPEDEFDECL,
CHILLAST_NODETYPE_VARDECL,
@@ -58,26 +58,26 @@ enum CHILL_ASTNODE_TYPE {
CHILLAST_NODETYPE_CUDASYNCTHREADS,
CHILLAST_NODETYPE_NULL // explicit non-statement
// TODO
-
-} ;
-enum CHILL_FUNCTION_TYPE {
+};
+
+enum CHILL_FUNCTION_TYPE {
CHILL_FUNCTION_CPU = 0,
CHILL_FUNCTION_GPU
};
-
-enum CHILL_MEMBER_EXP_TYPE {
+
+enum CHILL_MEMBER_EXP_TYPE {
CHILL_MEMBER_EXP_DOT = 0,
CHILL_MEMBER_EXP_ARROW
};
-
-enum CHILL_PREPROCESSING_TYPE {
+
+enum CHILL_PREPROCESSING_TYPE {
CHILL_PREPROCESSING_TYPEUNKNOWN = 0,
CHILL_PREPROCESSING_COMMENT,
CHILL_PREPROCESSING_POUNDDEFINE,
CHILL_PREPROCESSING_POUNDINCLUDE,
CHILL_PREPROCESSING_PRAGMA // unused so far
-};
+};
enum CHILL_PREPROCESSING_POSITION { // when tied to another statement
CHILL_PREPROCESSING_POSITIONUNKNOWN = 0,
@@ -87,14 +87,18 @@ enum CHILL_PREPROCESSING_POSITION { // when tied to another statement
CHILL_PREPROCESSING_IMMEDIATELYBEFORE // on same line
};
-char *parseUnderlyingType( char *sometype );
-char *parseArrayParts( char *sometype );
-bool isRestrict( const char *sometype );
-char *splitTypeInfo( char *underlyingtype );
-char *ulhack( char *brackets ); // change "1024UL" to "1024"
-char *restricthack( char *typeinfo ); // remove __restrict__ , MODIFIES the argument!
+char *parseUnderlyingType(char *sometype);
+
+char *parseArrayParts(char *sometype);
+
+bool isRestrict(const char *sometype);
+
+char *splitTypeInfo(char *underlyingtype);
+
+char *ulhack(char *brackets); // change "1024UL" to "1024"
+char *restricthack(char *typeinfo); // remove __restrict__ , MODIFIES the argument!
-extern const char* Chill_AST_Node_Names[]; // WARNING MUST BE KEPT IN SYNC WITH BELOW LIST
+extern const char *Chill_AST_Node_Names[]; // WARNING MUST BE KEPT IN SYNC WITH BELOW LIST
// fwd declarations
class chillAST_node; // the generic node. specific types derive from this
@@ -102,60 +106,88 @@ class chillAST_NULL; // empty
class chillAST_SourceFile; // ast for an entire source file (translationunit)
class chillAST_TypedefDecl;
+
class chillAST_VarDecl;
+
//class chillAST_ParmVarDecl;
class chillAST_FunctionDecl;
+
class chillAST_RecordDecl; // structs and unions (and classes?)
class chillAST_MacroDefinition;
+
class chillAST_CompoundStmt; // just a bunch of other statements
class chillAST_ForStmt; // AKA a LOOP
class chillAST_TernaryOperator;
+
class chillAST_BinaryOperator;
+
class chillAST_ArraySubscriptExpr;
+
class chillAST_MemberExpr;
+
class chillAST_DeclRefExpr;
+
class chillAST_IntegerLiteral;
+
class chillAST_FloatingLiteral;
+
class chillAST_UnaryOperator;
+
class chillAST_ImplicitCastExpr;
+
class chillAST_CStyleCastExpr;
+
class chillAST_CStyleAddressOf;
+
class chillAST_ReturnStmt;
+
class chillAST_CallExpr;
+
class chillAST_ParenExpr;
+
class chillAST_Sizeof;
+
class chillAST_Malloc;
+
class chillAST_Free;
+
class chillAST_NoOp;
+
class chillAST_CudaMalloc;
+
class chillAST_CudaFree;
+
class chillAST_CudaMemcpy;
+
class chillAST_CudaKernelCall;
+
class chillAST_CudaSyncthreads;
+
class chillAST_Preprocessing;
-typedef std::vector<chillAST_VarDecl *> chillAST_SymbolTable; // typedef
+typedef std::vector<chillAST_VarDecl *> chillAST_SymbolTable; // typedef
typedef std::vector<chillAST_TypedefDecl *> chillAST_TypedefTable; // typedef
-bool symbolTableHasVariableNamed( chillAST_SymbolTable *table, const char *name ); // fwd decl
-chillAST_VarDecl *symbolTableFindVariableNamed( chillAST_SymbolTable *table, const char *name ); // fwd decl TODO too many similar named functions
+bool symbolTableHasVariableNamed(chillAST_SymbolTable *table, const char *name); // fwd decl
+chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table,
+ const char *name); // fwd decl TODO too many similar named functions
-void printSymbolTable( chillAST_SymbolTable *st ); // fwd decl
-void printSymbolTableMoreInfo( chillAST_SymbolTable *st ); // fwd decl
+void printSymbolTable(chillAST_SymbolTable *st); // fwd decl
+void printSymbolTableMoreInfo(chillAST_SymbolTable *st); // fwd decl
-chillAST_node *lessthanmacro( chillAST_node *left, chillAST_node *right); // fwd declaration
-chillAST_SymbolTable *addSymbolToTable( chillAST_SymbolTable *st, chillAST_VarDecl *vd ); // fwd decl
-chillAST_TypedefTable *addTypedefToTable( chillAST_TypedefTable *tt, chillAST_TypedefDecl *td ); // fwd decl
+chillAST_node *lessthanmacro(chillAST_node *left, chillAST_node *right); // fwd declaration
+chillAST_SymbolTable *addSymbolToTable(chillAST_SymbolTable *st, chillAST_VarDecl *vd); // fwd decl
+chillAST_TypedefTable *addTypedefToTable(chillAST_TypedefTable *tt, chillAST_TypedefDecl *td); // fwd decl
-bool streq( const char *a, const char *b); // fwd decl
-void chillindent( int i, FILE *fp ); // fwd declaration
-void insertNewDeclAtLocationOfOldIfNeeded( chillAST_VarDecl *newdecl, chillAST_VarDecl *olddecl);
+bool streq(const char *a, const char *b); // fwd decl
+void chillindent(int i, FILE *fp); // fwd declaration
+void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_VarDecl *olddecl);
-chillAST_DeclRefExpr *buildDeclRefExpr( chillAST_VarDecl *);
+chillAST_DeclRefExpr *buildDeclRefExpr(chillAST_VarDecl *);
-chillAST_FunctionDecl *findFunctionDecl( chillAST_node *node, const char *procname);
+chillAST_FunctionDecl *findFunctionDecl(chillAST_node *node, const char *procname);
#endif
diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh
index 70660c5..bc3facb 100644
--- a/include/chillAST/chillAST_node.hh
+++ b/include/chillAST/chillAST_node.hh
@@ -9,363 +9,402 @@
// nodes based on clang AST which are in turn based on C++
class chillAST_node { // generic node. a tree of these is the AST. this is virtual (can't instantiate)
-public:
+public:
static int chill_scalar_counter; // for manufactured scalars
- static int chill_array_counter ; // for manufactured arrays
- static int chill_pointer_counter ; // for manufactured arrays
+ static int chill_array_counter; // for manufactured arrays
+ static int chill_pointer_counter; // for manufactured arrays
CHILL_ASTNODE_TYPE asttype;
-
- bool isSourceFile() { return (asttype == CHILLAST_NODETYPE_SOURCEFILE); };
- bool isTypeDefDecl() { return (asttype == CHILLAST_NODETYPE_TYPEDEFDECL); };
- bool isVarDecl() { return (asttype == CHILLAST_NODETYPE_VARDECL); };
- bool isFunctionDecl() { return (asttype == CHILLAST_NODETYPE_FUNCTIONDECL); };
- bool isRecordDecl() { return (asttype == CHILLAST_NODETYPE_RECORDDECL); };
- bool isMacroDefinition() { return (asttype == CHILLAST_NODETYPE_MACRODEFINITION); };
- bool isCompoundStmt() { return (asttype == CHILLAST_NODETYPE_COMPOUNDSTMT); };
- bool isLoop() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA ForStmt
- bool isForStmt() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA Loop
- bool isIfStmt() { return (asttype == CHILLAST_NODETYPE_IFSTMT); };
- bool isTernaryOperator() { return (asttype == CHILLAST_NODETYPE_TERNARYOPERATOR);};
- bool isBinaryOperator() { return (asttype == CHILLAST_NODETYPE_BINARYOPERATOR); };
- bool isUnaryOperator() { return (asttype == CHILLAST_NODETYPE_UNARYOPERATOR); };
- bool isArraySubscriptExpr() { return (asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR); };
- bool isMemberExpr() { return (asttype == CHILLAST_NODETYPE_MEMBEREXPR); };
- bool isDeclRefExpr() { return (asttype == CHILLAST_NODETYPE_DECLREFEXPR); };
- bool isIntegerLiteral() { return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL); };
- bool isFloatingLiteral() { return (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); };
- bool isImplicitCastExpr() { return (asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR); };
- bool isReturnStmt() { return (asttype == CHILLAST_NODETYPE_RETURNSTMT); };
- bool isCallExpr() { return (asttype == CHILLAST_NODETYPE_CALLEXPR); };
- bool isParenExpr() { return (asttype == CHILLAST_NODETYPE_PARENEXPR); };
- bool isSizeof() { return (asttype == CHILLAST_NODETYPE_SIZEOF); };
- bool isMalloc() { return (asttype == CHILLAST_NODETYPE_MALLOC); };
- bool isFree() { return (asttype == CHILLAST_NODETYPE_FREE); };
- bool isPreprocessing() { return (asttype == CHILLAST_NODETYPE_PREPROCESSING); };
- bool isNoOp() { return (asttype == CHILLAST_NODETYPE_NOOP); };
- bool isNull() { return (asttype == CHILLAST_NODETYPE_NULL); };
- bool isCStyleCastExpr() { return (asttype == CHILLAST_NODETYPE_CSTYLECASTEXPR); };
- bool isCStyleAddressOf() { return (asttype == CHILLAST_NODETYPE_CSTYLEADDRESSOF); };
- bool isCudaMalloc() { return (asttype == CHILLAST_NODETYPE_CUDAMALLOC); };
- bool isCudaFree() { return (asttype == CHILLAST_NODETYPE_CUDAFREE); };
- bool isCudaMemcpy() { return (asttype == CHILLAST_NODETYPE_CUDAMEMCPY); };
- bool isCudaKERNELCALL() { return (asttype == CHILLAST_NODETYPE_CUDAKERNELCALL); };
- bool isCudaSYNCTHREADS() { return (asttype == CHILLAST_NODETYPE_CUDASYNCTHREADS); };
-
- bool isDeclStmt() { return (asttype == CHILLAST_NODETYPE_DECLSTMT); }; // doesn't exist
-
- bool isConstant() { return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL) || (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); }
-
-
- virtual bool isAssignmentOp() { return false; };
- virtual bool isComparisonOp() { return false; };
- virtual bool isNotLeaf() { return false; };
- virtual bool isLeaf() { return true; };
- virtual bool isParmVarDecl() { return false; };
-
- virtual bool isPlusOp() { return false; };
- virtual bool isMinusOp() { return false; };
- virtual bool isPlusMinusOp() { return false; };
- virtual bool isMultDivOp() { return false; };
-
- virtual bool isAStruct() { return false; };
- virtual bool isAUnion() { return false; };
-
- virtual bool hasSymbolTable() { return false; } ; // most nodes do NOT have a symbol table
- virtual bool hasTypedefTable() { return false; } ; // most nodes do NOT have a typedef table
+
+ bool isSourceFile() { return (asttype == CHILLAST_NODETYPE_SOURCEFILE); };
+
+ bool isTypeDefDecl() { return (asttype == CHILLAST_NODETYPE_TYPEDEFDECL); };
+
+ bool isVarDecl() { return (asttype == CHILLAST_NODETYPE_VARDECL); };
+
+ bool isFunctionDecl() { return (asttype == CHILLAST_NODETYPE_FUNCTIONDECL); };
+
+ bool isRecordDecl() { return (asttype == CHILLAST_NODETYPE_RECORDDECL); };
+
+ bool isMacroDefinition() { return (asttype == CHILLAST_NODETYPE_MACRODEFINITION); };
+
+ bool isCompoundStmt() { return (asttype == CHILLAST_NODETYPE_COMPOUNDSTMT); };
+
+ bool isLoop() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA ForStmt
+ bool isForStmt() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA Loop
+ bool isIfStmt() { return (asttype == CHILLAST_NODETYPE_IFSTMT); };
+
+ bool isTernaryOperator() { return (asttype == CHILLAST_NODETYPE_TERNARYOPERATOR); };
+
+ bool isBinaryOperator() { return (asttype == CHILLAST_NODETYPE_BINARYOPERATOR); };
+
+ bool isUnaryOperator() { return (asttype == CHILLAST_NODETYPE_UNARYOPERATOR); };
+
+ bool isArraySubscriptExpr() { return (asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR); };
+
+ bool isMemberExpr() { return (asttype == CHILLAST_NODETYPE_MEMBEREXPR); };
+
+ bool isDeclRefExpr() { return (asttype == CHILLAST_NODETYPE_DECLREFEXPR); };
+
+ bool isIntegerLiteral() { return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL); };
+
+ bool isFloatingLiteral() { return (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); };
+
+ bool isImplicitCastExpr() { return (asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR); };
+
+ bool isReturnStmt() { return (asttype == CHILLAST_NODETYPE_RETURNSTMT); };
+
+ bool isCallExpr() { return (asttype == CHILLAST_NODETYPE_CALLEXPR); };
+
+ bool isParenExpr() { return (asttype == CHILLAST_NODETYPE_PARENEXPR); };
+
+ bool isSizeof() { return (asttype == CHILLAST_NODETYPE_SIZEOF); };
+
+ bool isMalloc() { return (asttype == CHILLAST_NODETYPE_MALLOC); };
+
+ bool isFree() { return (asttype == CHILLAST_NODETYPE_FREE); };
+
+ bool isPreprocessing() { return (asttype == CHILLAST_NODETYPE_PREPROCESSING); };
+
+ bool isNoOp() { return (asttype == CHILLAST_NODETYPE_NOOP); };
+
+ bool isNull() { return (asttype == CHILLAST_NODETYPE_NULL); };
+
+ bool isCStyleCastExpr() { return (asttype == CHILLAST_NODETYPE_CSTYLECASTEXPR); };
+
+ bool isCStyleAddressOf() { return (asttype == CHILLAST_NODETYPE_CSTYLEADDRESSOF); };
+
+ bool isCudaMalloc() { return (asttype == CHILLAST_NODETYPE_CUDAMALLOC); };
+
+ bool isCudaFree() { return (asttype == CHILLAST_NODETYPE_CUDAFREE); };
+
+ bool isCudaMemcpy() { return (asttype == CHILLAST_NODETYPE_CUDAMEMCPY); };
+
+ bool isCudaKERNELCALL() { return (asttype == CHILLAST_NODETYPE_CUDAKERNELCALL); };
+
+ bool isCudaSYNCTHREADS() { return (asttype == CHILLAST_NODETYPE_CUDASYNCTHREADS); };
+
+ bool isDeclStmt() { return (asttype == CHILLAST_NODETYPE_DECLSTMT); }; // doesn't exist
+
+ bool isConstant() {
+ return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL) || (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL);
+ }
+
+
+ virtual bool isAssignmentOp() { return false; };
+
+ virtual bool isComparisonOp() { return false; };
+
+ virtual bool isNotLeaf() { return false; };
+
+ virtual bool isLeaf() { return true; };
+
+ virtual bool isParmVarDecl() { return false; };
+
+ virtual bool isPlusOp() { return false; };
+
+ virtual bool isMinusOp() { return false; };
+
+ virtual bool isPlusMinusOp() { return false; };
+
+ virtual bool isMultDivOp() { return false; };
+
+ virtual bool isAStruct() { return false; };
+
+ virtual bool isAUnion() { return false; };
+
+ virtual bool hasSymbolTable() { return false; }; // most nodes do NOT have a symbol table
+ virtual bool hasTypedefTable() { return false; }; // most nodes do NOT have a typedef table
virtual chillAST_SymbolTable *getSymbolTable() { return NULL; } // most nodes do NOT have a symbol table
- virtual chillAST_VarDecl *findVariableNamed( const char *name ); // recursive
+ virtual chillAST_VarDecl *findVariableNamed(const char *name); // recursive
+
+ chillAST_RecordDecl *findRecordDeclNamed(const char *name); // recursive
- chillAST_RecordDecl *findRecordDeclNamed( const char *name ); // recursive
-
// void addDecl( chillAST_VarDecl *vd); // recursive, adds to first symbol table it can find
// TODO decide how to hide some data
- chillAST_node *parent;
+ chillAST_node *parent;
bool isFromSourceFile; // false = #included
char *filename; // file this node is from
- void segfault() { fprintf(stderr, "segfaulting on purpose\n"); int *i=0; int j = i[0]; }; // seg fault
- int getNumChildren() { return children.size(); };
- std::vector<chillAST_node*> children;
- std::vector<chillAST_node*> getChildren() { return children; } ; // not usually useful
- void setChildren( std::vector<chillAST_node*>&c ) { children = c; } ; // does not set parent. probably should
- chillAST_node *getChild( int which) { return children[which]; };
- void setChild( int which, chillAST_node *n ) { children[which] = n; children[which]->parent = this; } ;
-
+ int getNumChildren() { return children.size(); };
+ std::vector<chillAST_node *> children;
+
+ std::vector<chillAST_node *>& getChildren() { return children; }; // not usually useful
+ void setChildren(std::vector<chillAST_node *> &c) { children = c; }; // does not set parent. probably should
+ chillAST_node *getChild(int which) { return children[which]; };
+
+ void setChild(int which, chillAST_node *n) {
+ children[which] = n;
+ children[which]->parent = this;
+ };
+
char *metacomment; // for compiler internals, formerly a comment
- void setMetaComment( char *c ) { metacomment = strdup(c); };
+ void setMetaComment(const char *c) { metacomment = strdup(c); };
- std::vector<chillAST_Preprocessing*> preprocessinginfo;
+ std::vector<chillAST_Preprocessing *> preprocessinginfo;
- virtual void addChild( chillAST_node* c) {
- //if (c->isFunctionDecl()) fprintf(stderr, "addchild FunctionDecl\n");
+ virtual void addChild(chillAST_node *c) {
c->parent = this;
// check to see if it's already there
- for (int i=0; i<children.size(); i++) {
+ for (int i = 0; i < children.size(); i++) {
if (c == children[i]) {
- //fprintf(stderr, "addchild ALREADY THERE\n");
+ CHILL_ERROR("addchild ALREADY THERE\n");
return; // already there
}
}
children.push_back(c);
- } ; // not usually useful
+ }; // not usually useful
- virtual void insertChild(int i, chillAST_node* node) {
+ virtual void insertChild(int i, chillAST_node *node) {
//fprintf(stderr, "%s inserting child of type %s at location %d\n", getTypeString(), node->getTypeString(), i);
- node->parent = this;
- children.insert( children.begin()+i, node );
+ node->parent = this;
+ children.insert(children.begin() + i, node);
};
-
- virtual void removeChild(int i) {
- children.erase( children.begin()+i );
+
+ virtual void removeChild(int i) {
+ children.erase(children.begin() + i);
};
-
- int findChild( chillAST_node *c ) {
- for (int i=0; i<children.size(); i++) {
+
+ int findChild(chillAST_node *c) {
+ for (int i = 0; i < children.size(); i++) {
if (children[i] == c) return i;
}
return -1;
}
- virtual void replaceChild( chillAST_node *old, chillAST_node *newchild ) {
- fprintf(stderr,"(%s) forgot to implement replaceChild() ... using generic\n" ,Chill_AST_Node_Names[asttype]);
- fprintf(stderr, "%d children\n", children.size());
- for (int i=0; i<children.size(); i++) {
- if (children[i] == old) {
+ virtual void replaceChild(chillAST_node *old, chillAST_node *newchild) {
+ CHILL_DEBUG_PRINT("(%s) forgot to implement replaceChild() ... using generic\n", Chill_AST_Node_Names[asttype]);
+ CHILL_DEBUG_PRINT("%d children\n", children.size());
+ for (int i = 0; i < children.size(); i++) {
+ if (children[i] == old) {
children[i] = newchild;
- newchild->setParent( this );
- return;
+ newchild->setParent(this);
+ return;
}
}
- fprintf(stderr, "%s %p generic replaceChild called with oldchild that was not a child\n",
- getTypeString(), this) ;
- fprintf(stderr, "printing\n");
- print(); fprintf(stderr, "\nchild: ");
- if (!old) fprintf(stderr, "oldchild NULL!\n");
- old->print(); fprintf(stderr, "\nnew: ");
- newchild->print(); fprintf(stderr, "\n");
- segfault(); // make easier for gdb
+ CHILL_ERROR("%s %p generic replaceChild called with oldchild that was not a child\n",
+ getTypeString(), this);
+ CHILL_DEBUG_BEGIN
+ fprintf(stderr, "printing\n");
+ print();
+ fprintf(stderr, "\nchild: ");
+ if (!old) fprintf(stderr, "oldchild NULL!\n");
+ old->print();
+ fprintf(stderr, "\nnew: ");
+ newchild->print();
+ fprintf(stderr, "\n");
+ CHILL_DEBUG_END
+ exit(-1);
};
-
- virtual void loseLoopWithLoopVar( char *var ) {
- // walk tree. If a loop has this loop variable, replace the loop with the loop body,
- // removing the loop. The loop will be spread across a bunch of cores that will each
- // calculate their own loop variable.
-
- // things that can not have loops as substatements can have a null version of this method
- // things that have more complicated sets of "children" will have specialized versions
-
- // this is the generic version of the method. It just recurses among its children.
- // ForStmt is the only one that can actually remove itself. When it does, it will
- // potentially change the children vector, which is not the simple array it might appear.
- // so you have to make a copy of the vector to traverse
-
- std::vector<chillAST_node*> dupe = children; // simple enough?
- //fprintf(stderr, "node XXX has %d children\n", dupe.size());
- //fprintf(stderr, "generic node %s has %d children\n", getTypeString(), dupe.size());
- for (int i=0; i<dupe.size(); i++) { // recurse on all children
- dupe[i]->loseLoopWithLoopVar( var );
+
+ //! Spread the loop across a bunch of cores that will each calculate its own loop variable.
+ /*!
+ * If a loop has this loop variable, replace the loop with the loop body, calculate their own loop variable.
+ *
+ * things that can not have loops as substatements can have a null version of this method
+ * things that have more complicated sets of "children" will have specialized versions
+ *
+ * this is the generic version of the method. It just recurses among its children.
+ * ForStmt is the only one that can actually remove itself. When it does, it will
+ * potentially change the children vector, which is not the simple array it might appear.
+ * so you have to make a copy of the vector to traverse
+ *
+ * @param var
+ */
+ virtual void loseLoopWithLoopVar(char *var) {
+ std::vector<chillAST_node *> dupe = children; // simple enough?
+ for (int i = 0; i < dupe.size(); i++) { // recurse on all children
+ dupe[i]->loseLoopWithLoopVar(var);
}
}
- virtual int evalAsInt() {
- fprintf(stderr,"(%s) can't be evaluated as an integer??\n", Chill_AST_Node_Names[asttype]);
- print(); fprintf(stderr, "\n");
- segfault();
+ virtual int evalAsInt() {
+ CHILL_ERROR("(%s) can't be evaluated as an integer??\n", Chill_AST_Node_Names[asttype]);
+ print();
+ exit(-1);
}
- virtual const char* getUnderlyingType() {
- fprintf(stderr,"(%s) forgot to implement getUnderlyingType()\n", Chill_AST_Node_Names[asttype]);
+ virtual const char *getUnderlyingType() {
+ CHILL_ERROR("(%s) forgot to implement getUnderlyingType()\n", Chill_AST_Node_Names[asttype]);
dump();
print();
- fprintf(stderr, "\n\n");
- segfault();
- };
+ exit(-1);
+ };
- virtual chillAST_VarDecl* getUnderlyingVarDecl() {
- fprintf(stderr,"(%s) forgot to implement getUnderlyingVarDecl()\n", Chill_AST_Node_Names[asttype]);
+ virtual chillAST_VarDecl *getUnderlyingVarDecl() {
+ CHILL_ERROR("(%s) forgot to implement getUnderlyingVarDecl()\n", Chill_AST_Node_Names[asttype]);
dump();
print();
- fprintf(stderr, "\n\n");
- segfault();
- };
+ exit(-1);
+ };
- virtual chillAST_node *findref(){// find the SINGLE constant or data reference at this node or below
- fprintf(stderr,"(%s) forgot to implement findref()\n" ,Chill_AST_Node_Names[asttype]);
+ virtual chillAST_node *findref() {// find the SINGLE constant or data reference at this node or below
+ CHILL_ERROR("(%s) forgot to implement findref()\n", Chill_AST_Node_Names[asttype]);
dump();
print();
- fprintf(stderr, "\n\n");
- segfault();
+ exit(-1);
};
- virtual void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
- fprintf(stderr,"(%s) forgot to implement gatherArrayRefs()\n" ,Chill_AST_Node_Names[asttype]);
+ virtual void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {
+ CHILL_ERROR("(%s) forgot to implement gatherArrayRefs()\n", Chill_AST_Node_Names[asttype]);
dump();
print();
- fprintf(stderr, "\n\n");
+ exit(-1);
};
-
+
// TODO we MIGHT want the VarDecl // NOTHING IMPLEMENTS THIS? ???
- virtual void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- fprintf(stderr,"(%s) forgot to implement gatherScalarRefs()\n" ,Chill_AST_Node_Names[asttype]);
+ virtual void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ CHILL_ERROR("(%s) forgot to implement gatherScalarRefs()\n", Chill_AST_Node_Names[asttype]);
dump();
print();
- fprintf(stderr, "\n\n");
+ exit(-1);
};
-
- virtual void gatherLoopIndeces( std::vector<chillAST_VarDecl*> &indeces ) { // recursive walk parent links, looking for loops, and grabbing the declRefExpr in the loop init and cond.
- // you can quit when you get to certain nodes
- //fprintf(stderr, "%s::gatherLoopIndeces()\n", getTypeString());
-
- if (isSourceFile() || isFunctionDecl() ) return; // end of the line
+ //! recursive walk parent links, looking for loops, and grabbing the declRefExpr in the loop init and cond.
+ virtual void gatherLoopIndeces(
+ std::vector<chillAST_VarDecl *> &indeces) {
+ // you can quit when you get to certain nodes
- // just for debugging
- //if (parent) {
- // fprintf(stderr, "%s has parent of type %s\n", getTypeString(), parent->getTypeString());
- //}
- //else fprintf(stderr, "this %s %p has no parent???\n", getTypeString(), this);
+ CHILL_DEBUG_PRINT("%s::gatherLoopIndeces()\n", getTypeString());
+ if (isSourceFile() || isFunctionDecl()) return; // end of the line
if (!parent) return; // should not happen, but be careful
// for most nodes, this just recurses upwards
- //fprintf(stderr, "%s::gatherLoopIndeces() %p recursing up\n", this);
- parent->gatherLoopIndeces( indeces );
+ parent->gatherLoopIndeces(indeces);
}
-
- chillAST_ForStmt* findContainingLoop() { // recursive walk parent links, looking for loops
- //fprintf(stderr, "%s::findContainingLoop() ", getTypeString());
- //if (parent) fprintf(stderr, "parents is a %s\n", parent->getTypeString());
- //else fprintf(stderr, "no parent\n");
- // do not check SELF type, as we may want to find the loop containing a loop
+ //! recursive walk parent links, looking for loops
+ chillAST_ForStmt *findContainingLoop() {
+ CHILL_DEBUG_PRINT("%s::findContainingLoop() ", getTypeString());
if (!parent) return NULL;
- if (parent->isForStmt()) return (chillAST_ForStmt*)parent;
+ if (parent->isForStmt()) return (chillAST_ForStmt *) parent;
return parent->findContainingLoop(); // recurse upwards
}
- chillAST_node* findContainingNonLoop() { // recursive walk parent links, avoiding loops
- fprintf(stderr, "%s::findContainingNonLoop() ", getTypeString());
- //if (parent) fprintf(stderr, "parent is a %s\n", parent->getTypeString());
- //else fprintf(stderr, "no parent\n");
- // do not check SELF type, as we may want to find the loop containing a loop
+ //! recursive walk parent links, avoiding loops
+ chillAST_node *findContainingNonLoop() {
+ fprintf(stderr, "%s::findContainingNonLoop() ", getTypeString());
if (!parent) return NULL;
- if (parent->isCompoundStmt() && parent->getParent()->isForStmt()) return parent->getParent()->findContainingNonLoop(); // keep recursing
+ if (parent->isCompoundStmt() && parent->getParent()->isForStmt())
+ return parent->getParent()->findContainingNonLoop(); // keep recursing
if (parent->isForStmt()) return parent->findContainingNonLoop(); // keep recursing
- return (chillAST_node*)parent; // return non-loop
+ return (chillAST_node *) parent; // return non-loop
}
// TODO gather loop init and cond (and if cond) like gatherloopindeces
- virtual void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs ){ // both scalar and arrays
- fprintf(stderr,"(%s) forgot to implement gatherDeclRefExpr()\n" ,Chill_AST_Node_Names[asttype]);
+ virtual void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) { // both scalar and arrays
+ fprintf(stderr, "(%s) forgot to implement gatherDeclRefExpr()\n", Chill_AST_Node_Names[asttype]);
};
+ virtual void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {
+ fprintf(stderr, "(%s) forgot to implement gatherVarUsage()\n", Chill_AST_Node_Names[asttype]);
+ };
- virtual void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ) {
- fprintf(stderr,"(%s) forgot to implement gatherVarUsage()\n" ,Chill_AST_Node_Names[asttype]);
- };
-
- virtual void gatherVarLHSUsage( std::vector<chillAST_VarDecl*> &decls ) {
- fprintf(stderr,"(%s) forgot to implement gatherVarLHSUsage()\n" ,Chill_AST_Node_Names[asttype]);
- };
+ virtual void gatherVarLHSUsage(std::vector<chillAST_VarDecl *> &decls) {
+ fprintf(stderr, "(%s) forgot to implement gatherVarLHSUsage()\n", Chill_AST_Node_Names[asttype]);
+ };
+ //! ACTUAL Declaration
+ virtual void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {
+ fprintf(stderr, "(%s) forgot to implement gatherVarDecls()\n", Chill_AST_Node_Names[asttype]);
+ };
- virtual void gatherVarDecls( std::vector<chillAST_VarDecl*> &decls ) { // ACTUAL Declaration
- fprintf(stderr,"(%s) forgot to implement gatherVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
- };
-
- virtual void gatherVarDeclsMore( std::vector<chillAST_VarDecl*> &decls ) { // even if the decl itself is not in the ast.
- fprintf(stderr,"(%s) forgot to implement gatherVarDeclsMore()\n" ,Chill_AST_Node_Names[asttype]);
- };
+ virtual void
+ gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { // even if the decl itself is not in the ast.
+ fprintf(stderr, "(%s) forgot to implement gatherVarDeclsMore()\n", Chill_AST_Node_Names[asttype]);
+ };
- virtual void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls ) { // ACTUAL Declaration
- fprintf(stderr,"(%s) forgot to implement gatherScalarVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
- };
+ virtual void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) { // ACTUAL Declaration
+ fprintf(stderr, "(%s) forgot to implement gatherScalarVarDecls()\n", Chill_AST_Node_Names[asttype]);
+ };
- virtual void gatherArrayVarDecls( std::vector<chillAST_VarDecl*> &decls ) { // ACTUAL Declaration
- fprintf(stderr,"(%s) forgot to implement gatherArrayVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
- };
+ virtual void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) { // ACTUAL Declaration
+ fprintf(stderr, "(%s) forgot to implement gatherArrayVarDecls()\n", Chill_AST_Node_Names[asttype]);
+ };
- virtual chillAST_VarDecl *findArrayDecl( const char *name ) { // scoping TODO
- if (!hasSymbolTable()) return parent->findArrayDecl( name ); // most things
+ virtual chillAST_VarDecl *findArrayDecl(const char *name) { // scoping TODO
+ if (!hasSymbolTable()) return parent->findArrayDecl(name); // most things
else
- fprintf(stderr,"(%s) forgot to implement gatherArrayVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
+ fprintf(stderr, "(%s) forgot to implement gatherArrayVarDecls()\n", Chill_AST_Node_Names[asttype]);
}
- virtual void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
- fprintf(stderr,"(%s) forgot to implement replaceVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
- };
+ virtual void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ fprintf(stderr, "(%s) forgot to implement replaceVarDecls()\n", Chill_AST_Node_Names[asttype]);
+ };
- virtual bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ) {
- // this just looks for ForStmts with preferred index metacomment attached
- fprintf(stderr,"(%s) forgot to implement findLoopIndexesToReplace()\n" ,Chill_AST_Node_Names[asttype]);
- return false;
+ //! this just looks for ForStmts with preferred index metacomment attached
+ virtual bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) {
+ fprintf(stderr, "(%s) forgot to implement findLoopIndexesToReplace()\n", Chill_AST_Node_Names[asttype]);
+ return false;
}
-
- virtual chillAST_node* constantFold() { // hacky. TODO. make nice
- fprintf(stderr,"(%s) forgot to implement constantFold()\n" ,Chill_AST_Node_Names[asttype]);
- exit(-1); ;
+
+ virtual chillAST_node *constantFold() { // hacky. TODO. make nice
+ CHILL_ERROR("(%s) forgot to implement constantFold()\n", Chill_AST_Node_Names[asttype]);
+ exit(-1);;
};
- virtual chillAST_node* clone() { // makes a deep COPY (?)
- fprintf(stderr,"(%s) forgot to implement clone()\n" ,Chill_AST_Node_Names[asttype]);
- exit(-1); ;
+ virtual chillAST_node *clone() { // makes a deep COPY (?)
+ CHILL_ERROR("(%s) forgot to implement clone()\n", Chill_AST_Node_Names[asttype]);
+ exit(-1);;
};
- virtual void dump( int indent=0, FILE *fp = stderr ) {
- fflush(fp);
- fprintf(fp,"(%s) forgot to implement dump()\n" ,Chill_AST_Node_Names[asttype]); };// print ast
-
- virtual void print( int indent=0, FILE *fp = stderr ) {
- fflush(fp);
- //fprintf(stderr, "generic chillAST_node::print() called!\n");
- //fprintf(stderr, "asttype is %d\n", asttype);
+
+ //! Print AST
+ virtual void dump(int indent = 0, FILE *fp = stderr) {
+ fflush(fp);
+ CHILL_ERROR("(%s) forgot to implement dump()\n", Chill_AST_Node_Names[asttype]);
+ };// print ast
+
+ // TODO We might want to print the code a bit differently, This can be only a generic dump
+ //! Print CODE
+ virtual void print(int indent = 0, FILE *fp = stderr) {
+ fflush(fp);
fprintf(fp, "\n");
- chillindent(indent, fp);
- fprintf(fp,"(%s) forgot to implement print()\n" ,Chill_AST_Node_Names[asttype]);
- };// print CODE
-
- virtual void printName( int indent=0, FILE *fp = stderr ) {
- fflush(fp);
- //fprintf(stderr, "generic chillAST_node::printName() called!\n");
- //fprintf(stderr, "asttype is %d\n", asttype);
+ chillindent(indent, fp);
+ fprintf(fp, "(%s) forgot to implement print()\n", Chill_AST_Node_Names[asttype]);
+ };
+
+ virtual void printName(int indent = 0, FILE *fp = stderr) {
+ fflush(fp);
fprintf(fp, "\n");
- chillindent(indent, fp);
- fprintf(fp,"(%s) forgot to implement printName()\n" ,Chill_AST_Node_Names[asttype]);
+ chillindent(indent, fp);
+ fprintf(fp, "(%s) forgot to implement printName()\n", Chill_AST_Node_Names[asttype]);
};// print CODE
- virtual char *stringRep(int indent=0 ) { // the ast's print version
+ //! The AST's print version
+ virtual char *stringRep(int indent = 0) {
fflush(stdout);
- // chillindent(indent, fp); TODO
- fprintf(stderr,"(%s) forgot to implement stringRep()\n" ,Chill_AST_Node_Names[asttype]);
- segfault();
+ // TODO chillindent(indent, fp);
+ CHILL_ERROR("(%s) forgot to implement stringRep()\n", Chill_AST_Node_Names[asttype]);
+ exit(-1);
}
- virtual void printonly( int indent=0, FILE *fp = stderr ) { print( indent, fp); };
+ virtual void printonly(int indent = 0, FILE *fp = stderr) { print(indent, fp); };
- //virtual void printString( std::string &s ) {
+ //virtual void printString( std::string &s ) {
// fprintf(stderr,"(%s) forgot to implement printString()\n" ,Chill_AST_Node_Names[asttype]);
//}
- virtual void get_top_level_loops( std::vector<chillAST_ForStmt *> &loops) {
- int n = children.size();
+ virtual void get_top_level_loops(std::vector<chillAST_ForStmt *> &loops) {
+ int n = children.size();
//fprintf(stderr, "get_top_level_loops of a %s with %d children\n", getTypeString(), n);
- for (int i=0; i<n; i++) {
+ for (int i = 0; i < n; i++) {
//fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString());
if (children[i]->isForStmt()) {
- loops.push_back( ((chillAST_ForStmt *)(children[i])) );
+ loops.push_back(((chillAST_ForStmt *) (children[i])));
}
}
//fprintf(stderr, "found %d top level loops\n", loops.size());
@@ -373,128 +412,142 @@ public:
virtual void repairParentChild() { // for nodes where all subnodes are children
- int n = children.size();
- for (int i=0; i<n; i++) {
- if (children[i]->parent != this) {
- fprintf(stderr, "fixing child %s that didn't know its parent\n", children[i]->getTypeString());
- children[i]->parent = this;
+ int n = children.size();
+ for (int i = 0; i < n; i++) {
+ if (children[i]->parent != this) {
+ fprintf(stderr, "fixing child %s that didn't know its parent\n", children[i]->getTypeString());
+ children[i]->parent = this;
}
}
}
-
- virtual void get_deep_loops( std::vector<chillAST_ForStmt *> &loops) { // this is probably broken - returns ALL loops under it
- int n = children.size();
+ virtual void
+ get_deep_loops(std::vector<chillAST_ForStmt *> &loops) { // this is probably broken - returns ALL loops under it
+ int n = children.size();
//fprintf(stderr, "get_deep_loops of a %s with %d children\n", getTypeString(), n);
- for (int i=0; i<n; i++) {
+ for (int i = 0; i < n; i++) {
//fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString());
- children[i]->get_deep_loops( loops );
+ children[i]->get_deep_loops(loops);
}
//fprintf(stderr, "found %d deep loops\n", loops.size());
}
// generic for chillAST_node with children
- virtual void find_deepest_loops( std::vector<chillAST_ForStmt *> &loops) { // returns DEEPEST nesting of loops
- std::vector<chillAST_ForStmt *>deepest; // deepest below here
-
- int n = children.size();
+ virtual void find_deepest_loops(std::vector<chillAST_ForStmt *> &loops) { // returns DEEPEST nesting of loops
+ std::vector<chillAST_ForStmt *> deepest; // deepest below here
+
+ int n = children.size();
//fprintf(stderr, "find_deepest_loops of a %s with %d children\n", getTypeString(), n);
- for (int i=0; i<n; i++) {
+ for (int i = 0; i < n; i++) {
std::vector<chillAST_ForStmt *> subloops; // loops below here among a child of mine
-
+
//fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString());
- children[i]->find_deepest_loops( subloops );
-
- if (subloops.size() > deepest.size()) {
+ children[i]->find_deepest_loops(subloops);
+
+ if (subloops.size() > deepest.size()) {
deepest = subloops;
}
}
-
+
// append deepest we see at this level to loops
- for ( int i=0; i<deepest.size(); i++) {
- loops.push_back( deepest[i] );
+ for (int i = 0; i < deepest.size(); i++) {
+ loops.push_back(deepest[i]);
}
//fprintf(stderr, "found %d deep loops\n", loops.size());
-
+
}
+ const char *getTypeString() { return Chill_AST_Node_Names[asttype]; };
+
+ int getType() { return asttype; };
+
+ void setParent(chillAST_node *p) { parent = p; };
+ chillAST_node *getParent() { return parent; };
- const char *getTypeString() { return Chill_AST_Node_Names[asttype]; } ;
- int getType() { return asttype; };
- void setParent( chillAST_node *p) { parent = p; } ;
- chillAST_node *getParent() { return parent; } ;
-
- chillAST_SourceFile *getSourceFile() {
- if (isSourceFile()) return ((chillAST_SourceFile *)this);
- if (parent != NULL) return parent->getSourceFile();
- fprintf(stderr, "UHOH, getSourceFile() called on node %p %s that does not have a parent and is not a source file\n", this, this->getTypeString());
- this->print(); printf("\n\n"); fflush(stdout);
+ chillAST_SourceFile *getSourceFile() {
+ if (isSourceFile()) return ((chillAST_SourceFile *) this);
+ if (parent != NULL) return parent->getSourceFile();
+ fprintf(stderr, "UHOH, getSourceFile() called on node %p %s that does not have a parent and is not a source file\n",
+ this, this->getTypeString());
+ this->print();
+ printf("\n\n");
+ fflush(stdout);
exit(-1);
}
-
- virtual chillAST_node *findDatatype( char *t ) {
- fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
+
+ virtual chillAST_node *findDatatype(char *t) {
+ fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
if (parent != NULL) return parent->findDatatype(t); // most nodes do this
- return NULL;
+ return NULL;
}
- virtual chillAST_SymbolTable *addVariableToSymbolTable( chillAST_VarDecl *vd ) {
- if (!parent) {
- fprintf(stderr, "%s with no parent addVariableToSymbolTable()\n", getTypeString());
+ virtual chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) {
+ if (!parent) {
+ fprintf(stderr, "%s with no parent addVariableToSymbolTable()\n", getTypeString());
exit(-1);
}
//fprintf(stderr, "%s::addVariableToSymbolTable() (default) headed up\n", getTypeString());
- return parent->addVariableToSymbolTable( vd ); // default, defer to parent
+ return parent->addVariableToSymbolTable(vd); // default, defer to parent
}
- virtual void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) {
- parent->addTypedefToTypedefTable( tdd ); // default, defer to parent
+ virtual void addTypedefToTypedefTable(chillAST_TypedefDecl *tdd) {
+ parent->addTypedefToTypedefTable(tdd); // default, defer to parent
}
- void walk_parents() {
- fprintf(stderr, "wp: (%s) ", getTypeString());
- print(); printf("\n"); fflush(stdout);
- if (isSourceFile()) { fprintf(stderr, "(top sourcefile)\n\n"); return;}
+ void walk_parents() {
+ fprintf(stderr, "wp: (%s) ", getTypeString());
+ print();
+ printf("\n");
+ fflush(stdout);
+ if (isSourceFile()) {
+ fprintf(stderr, "(top sourcefile)\n\n");
+ return;
+ }
if (parent) parent->walk_parents();
else fprintf(stderr, "UHOH, %s has no parent??\n", getTypeString());
- return;
+ return;
}
- virtual chillAST_node *getEnclosingStatement( int level = 0 );
- virtual chillAST_VarDecl *multibase() {
- fprintf(stderr,"(%s) forgot to implement multibase()\n", Chill_AST_Node_Names[asttype]);
+ virtual chillAST_node *getEnclosingStatement(int level = 0);
+
+ virtual chillAST_VarDecl *multibase() {
+ fprintf(stderr, "(%s) forgot to implement multibase()\n", Chill_AST_Node_Names[asttype]);
exit(-1);
}
- virtual chillAST_node *multibase2() {
- fprintf(stderr,"(%s) forgot to implement multibase2()\n", Chill_AST_Node_Names[asttype]);
+
+ virtual chillAST_node *multibase2() {
+ fprintf(stderr, "(%s) forgot to implement multibase2()\n", Chill_AST_Node_Names[asttype]);
exit(-1);
}
-
- virtual void gatherStatements( std::vector<chillAST_node*> &statements ) {
- fprintf(stderr,"(%s) forgot to implement gatherStatements()\n" ,Chill_AST_Node_Names[asttype]);
- dump();fflush(stdout);
+
+ virtual void gatherStatements(std::vector<chillAST_node *> &statements) {
+ fprintf(stderr, "(%s) forgot to implement gatherStatements()\n", Chill_AST_Node_Names[asttype]);
+ dump();
+ fflush(stdout);
print();
- fprintf(stderr, "\n\n");
+ fprintf(stderr, "\n\n");
}
- virtual bool isSameAs( chillAST_node *other ){ // for tree comparison
- fprintf(stderr,"(%s) forgot to implement isSameAs()\n" ,Chill_AST_Node_Names[asttype]);
- dump(); fflush(stdout);
+ virtual bool isSameAs(chillAST_node *other) { // for tree comparison
+ fprintf(stderr, "(%s) forgot to implement isSameAs()\n", Chill_AST_Node_Names[asttype]);
+ dump();
+ fflush(stdout);
print();
- fprintf(stderr, "\n\n"); }
+ fprintf(stderr, "\n\n");
+ }
- void printPreprocBEFORE( int indent, FILE *fp );
- void printPreprocAFTER( int indent, FILE *fp );
+ void printPreprocBEFORE(int indent, FILE *fp);
+ void printPreprocAFTER(int indent, FILE *fp);
};
diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh
index 228cf3f..c7d13dd 100644
--- a/include/chillAST/chillASTs.hh
+++ b/include/chillAST/chillASTs.hh
@@ -6,22 +6,28 @@
#include "chillAST_def.hh"
#include "chillAST_node.hh"
-class chillAST_NULL: public chillAST_node { // NOOP?
+class chillAST_NULL : public chillAST_node { // NOOP?
public:
- chillAST_NULL(chillAST_node *p = NULL) { parent = p; asttype = CHILLAST_NODETYPE_NULL; };
- void print( int indent=0, FILE *fp = stderr ) {
- chillindent( indent, fp );
+ chillAST_NULL(chillAST_node *p = NULL) {
+ parent = p;
+ asttype = CHILLAST_NODETYPE_NULL;
+ };
+
+ void print(int indent = 0, FILE *fp = stderr) {
+ chillindent(indent, fp);
fprintf(fp, "/* (NULL statement); */ ");
fflush(fp);
}
- void dump( int indent=0, FILE *fp = stderr ) {
- chillindent( indent, fp );
- fprintf(fp, "(NULL statement) "); fflush(fp);
+
+ void dump(int indent = 0, FILE *fp = stderr) {
+ chillindent(indent, fp);
+ fprintf(fp, "(NULL statement) ");
+ fflush(fp);
}
};
-
-class chillAST_Preprocessing: public chillAST_node {
+
+class chillAST_Preprocessing : public chillAST_node {
public:
// variables that are special for this type of node
CHILL_PREPROCESSING_POSITION position;
@@ -30,18 +36,18 @@ public:
// constructors
chillAST_Preprocessing(); // not sure what this is good for
- chillAST_Preprocessing( CHILL_PREPROCESSING_POSITION pos, CHILL_PREPROCESSING_TYPE t, char *text );
-
+ chillAST_Preprocessing(CHILL_PREPROCESSING_POSITION pos, CHILL_PREPROCESSING_TYPE t, char *text);
+
// other methods particular to this type of node
-
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
//void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
-};
+};
//typedef is a keyword in the C and C++ programming languages. The purpose of typedef is to assign alternative names to existing types, most often those whose standard declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another.
-class chillAST_TypedefDecl: public chillAST_node {
+class chillAST_TypedefDecl : public chillAST_node {
private:
bool isStruct;
bool isUnion;
@@ -54,53 +60,72 @@ public:
chillAST_RecordDecl *rd; // if it's a struct, point to the recorddecl ??
// TODO what if "typedef int[10] tenints; " ??
- void setStructInfo( chillAST_RecordDecl *arrdee ) { rd = arrdee; };
- chillAST_RecordDecl * getStructDef();
+ void setStructInfo(chillAST_RecordDecl *arrdee) { rd = arrdee; };
+
+ chillAST_RecordDecl *getStructDef();
- bool isAStruct() { return isStruct; };
- bool isAUnion() { return isUnion; };
- void setStruct(bool tf) { isStruct = tf; fprintf(stderr, "%s isStruct %d\n", structname, isStruct); };
- void setUnion( bool tf) { isUnion = tf; };
- void setStructName( const char *newname) { structname = strdup(newname); };
- char *getStructName( ) { return structname; };
- bool nameis( const char *n ) { return !strcmp(n, structname); };
+ bool isAStruct() { return isStruct; };
+
+ bool isAUnion() { return isUnion; };
+
+ void setStruct(bool tf) {
+ isStruct = tf;
+ fprintf(stderr, "%s isStruct %d\n", structname, isStruct);
+ };
+
+ void setUnion(bool tf) { isUnion = tf; };
+
+ void setStructName(const char *newname) { structname = strdup(newname); };
+
+ char *getStructName() { return structname; };
+
+ bool nameis(const char *n) { return !strcmp(n, structname); };
// special for struct/unions rethink TODO
std::vector<chillAST_VarDecl *> subparts;
- chillAST_VarDecl *findSubpart( const char *name );
+
+ chillAST_VarDecl *findSubpart(const char *name);
//TODO hide data, set/get type and alias
chillAST_TypedefDecl();
+
chillAST_TypedefDecl(char *t, const char *nt, chillAST_node *p);
+
chillAST_TypedefDecl(char *t, const char *nt, char *a, chillAST_node *par);
-
- const char* getUnderlyingType() { fprintf(stderr, "TypedefDecl getUnderLyingType()\n"); return underlyingtype; };
+
+ const char *getUnderlyingType() {
+ fprintf(stderr, "TypedefDecl getUnderLyingType()\n");
+ return underlyingtype;
+ };
//virtual chillAST_VarDecl* getUnderlyingVarDecl() { return this; }; // ??
- void dump( int indent=0, FILE *fp = stderr ) {
- fprintf(fp, "(TypedefDecl %s %s %s)\n", underlyingtype, newtype, arraypart); };
- void print( int indent=0, FILE *fp = stderr ) ;
+ void dump(int indent = 0, FILE *fp = stderr) {
+ fprintf(fp, "(TypedefDecl %s %s %s)\n", underlyingtype, newtype, arraypart);
+ };
+
+ void print(int indent = 0, FILE *fp = stderr);
//void printString( std::string &s );
};
-class chillAST_VarDecl: public chillAST_node {
+class chillAST_VarDecl : public chillAST_node {
public:
char *vartype; // should probably be an enum, except it's used for unnamed structs too
- chillAST_RecordDecl *vardef;// the thing that says what the struct looks like
+ chillAST_RecordDecl *vardef;// the thing that says what the struct looks like
chillAST_TypedefDecl *typedefinition; // NULL for float, int, etc.
- chillAST_RecordDecl * getStructDef(); // TODO make vardef private?
+ chillAST_RecordDecl *getStructDef(); // TODO make vardef private?
//bool insideAStruct; // this variable is itself part of a struct
-
+
char *underlyingtype;
char *varname;
char *arraypart; // [ 12 ] [ 34 ] if that is how it was defined
char *arraypointerpart;
- char *arraysetpart;
+ char *arraysetpart;
+
void splitarraypart();
int numdimensions;
@@ -111,142 +136,188 @@ public:
bool isRestrict; // C++ __restrict__
bool isShared; // CUDA __shared__
bool isDevice; // CUDA __device__
- bool isStruct;
-
- int isAParameter;
+ bool isStruct;
+
+ int isAParameter;
bool byreference;
- void setByReference( bool tf ) { byreference = tf; fprintf(stderr, "byref %d\n", tf); };
+
+ void setByReference(bool tf) {
+ byreference = tf;
+ fprintf(stderr, "byref %d\n", tf);
+ };
bool isABuiltin; // if variable is builtin, we don't need to declare it
void *uniquePtr; // DO NOT REFERENCE THROUGH THIS! just used to differentiate declarations
- bool isArray() { return (numdimensions != 0); };
+ bool isArray() { return (numdimensions != 0); };
+
bool isAStruct() { return (isStruct || (typedefinition && typedefinition->isAStruct())); }
- void setStruct( bool b ) {isStruct = b;/*fprintf(stderr,"vardecl %s IS A STRUCT\n",varname);*/ };
- bool isPointer() { return isArray() && !knownArraySizes; } //
- bool knowAllDimensions() { return knownArraySizes; } ;
+ void setStruct(bool b) { isStruct = b;/*fprintf(stderr,"vardecl %s IS A STRUCT\n",varname);*/ };
+
+ bool isPointer() { return isArray() && !knownArraySizes; } //
+
+ bool knowAllDimensions() { return knownArraySizes; };
chillAST_node *init;
- void setInit( chillAST_node *i ) { init = i; i->setParent(this); };
+
+ void setInit(chillAST_node *i) {
+ init = i;
+ i->setParent(this);
+ };
+
bool hasInit() { return init != NULL; };
+
chillAST_node *getInit() { return init; };
-
+
chillAST_VarDecl();
- chillAST_VarDecl( const char *t, const char *n, const char *a, chillAST_node *p);
- chillAST_VarDecl( const char *t, const char *n, const char *a, void *ptr, chillAST_node *p);
- chillAST_VarDecl( chillAST_TypedefDecl *tdd, const char *n, const char *arraypart, chillAST_node *par);
- chillAST_VarDecl( chillAST_RecordDecl *astruct, const char *n, const char *arraypart, chillAST_node *par);
-
- void dump( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr );
- void printName( int indent=0, FILE *fp = stderr );
- bool isParmVarDecl() { return( isAParameter == 1 ); };
- bool isBuiltin() { return( isABuiltin == 1 ); }; // designate variable as a builtin
- void setLocation( void *ptr ) { uniquePtr = ptr; } ;
-
-
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
-
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs ) {}; // does nothing
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- const char* getUnderlyingType() { /* fprintf(stderr, "VarDecl getUnderLyingType()\n"); */return underlyingtype; };
- virtual chillAST_VarDecl* getUnderlyingVarDecl() { return this; };
-
- chillAST_node* constantFold();
- chillAST_node* clone();
+
+ chillAST_VarDecl(const char *t, const char *n, const char *a, chillAST_node *p);
+
+ chillAST_VarDecl(const char *t, const char *n, const char *a, void *ptr, chillAST_node *p);
+
+ chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, const char *arraypart, chillAST_node *par);
+
+ chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *n, const char *arraypart, chillAST_node *par);
+
+ void dump(int indent = 0, FILE *fp = stderr);
+
+ void print(int indent = 0, FILE *fp = stderr);
+
+ void printName(int indent = 0, FILE *fp = stderr);
+
+ bool isParmVarDecl() { return (isAParameter == 1); };
+
+ bool isBuiltin() { return (isABuiltin == 1); }; // designate variable as a builtin
+ void setLocation(void *ptr) { uniquePtr = ptr; };
+
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) {}; // does nothing
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ const char *getUnderlyingType() { /* fprintf(stderr, "VarDecl getUnderLyingType()\n"); */return underlyingtype; };
+
+ virtual chillAST_VarDecl *getUnderlyingVarDecl() { return this; };
+
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
};
-class chillAST_DeclRefExpr: public chillAST_node {
+class chillAST_DeclRefExpr : public chillAST_node {
public:
// variables that are special for this type of node
- char *declarationType;
- char *declarationName;
+ char *declarationType;
+ char *declarationName;
chillAST_node *decl; // the declaration of this variable or function ... uhoh
//char *functionparameters; // TODO probably should split this node into 2 types, one for variables, one for functions
// constructors
- chillAST_DeclRefExpr();
- chillAST_DeclRefExpr( const char *variablename, chillAST_node *p);
- chillAST_DeclRefExpr( const char *vartype, const char *variablename, chillAST_node *p);
- chillAST_DeclRefExpr( const char *vartype, const char *variablename, chillAST_node *dec, chillAST_node *p);
- chillAST_DeclRefExpr( chillAST_VarDecl *vd, chillAST_node *p=NULL);
- chillAST_DeclRefExpr( chillAST_FunctionDecl *fd, chillAST_node *p=NULL);
-
+ chillAST_DeclRefExpr();
+
+ chillAST_DeclRefExpr(const char *variablename, chillAST_node *p);
+
+ chillAST_DeclRefExpr(const char *vartype, const char *variablename, chillAST_node *p);
+
+ chillAST_DeclRefExpr(const char *vartype, const char *variablename, chillAST_node *dec, chillAST_node *p);
+
+ chillAST_DeclRefExpr(chillAST_VarDecl *vd, chillAST_node *p = NULL);
+
+ chillAST_DeclRefExpr(chillAST_FunctionDecl *fd, chillAST_node *p = NULL);
+
// other methods particular to this type of node
- bool operator!=( chillAST_DeclRefExpr &other ) { return decl != other.decl ; };
- bool operator==( chillAST_DeclRefExpr &other ) { return decl == other.decl ; }; // EXACT SAME VARECL BY ADDRESS
-
+ bool operator!=(chillAST_DeclRefExpr &other) { return decl != other.decl; };
+
+ bool operator==(chillAST_DeclRefExpr &other) { return decl == other.decl; }; // EXACT SAME VARECL BY ADDRESS
+
chillAST_node *getDecl() { return decl; };
- chillAST_VarDecl *getVarDecl() {
+ chillAST_VarDecl *getVarDecl() {
if (!decl) return NULL; // should never happen
- if (decl->isVarDecl()) return (chillAST_VarDecl *)decl;
- return NULL;
- };
-
- chillAST_FunctionDecl *getFunctionDecl() {
+ if (decl->isVarDecl()) return (chillAST_VarDecl *) decl;
+ return NULL;
+ };
+
+ chillAST_FunctionDecl *getFunctionDecl() {
if (!decl) return NULL; // should never happen
- if (decl->isFunctionDecl()) return (chillAST_FunctionDecl *)decl;
- return NULL;
- };
-
+ if (decl->isFunctionDecl()) return (chillAST_FunctionDecl *) decl;
+ return NULL;
+ };
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE
- void dump( int indent=0, FILE *fp = stderr ); // print ast
- char *stringRep(int indent=0 );
+ void print(int indent = 0, FILE *fp = stderr); // print CODE
+ void dump(int indent = 0, FILE *fp = stderr); // print ast
+ char *stringRep(int indent = 0);
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {}; // do nothing
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento );
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {}; // do nothing
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
// this is the AST node where these 2 differ
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing, to get the cvardecl using this method, the actual vardecl must be in the AST
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ); // returns the decl this declrefexpr references, even if the decl is not in the AST
+ void gatherVarDecls(
+ std::vector<chillAST_VarDecl *> &decls) {}; // does nothing, to get the cvardecl using this method, the actual vardecl must be in the AST
+ void gatherVarDeclsMore(
+ std::vector<chillAST_VarDecl *> &decls); // returns the decl this declrefexpr references, even if the decl is not in the AST
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- chillAST_node *findref(){return this;}// find the SINGLE constant or data reference at this node or below
-
- const char* getUnderlyingType() {fprintf(stderr, "DeclRefExpr getUnderLyingType()\n"); return decl->getUnderlyingType();};
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
- virtual chillAST_VarDecl* getUnderlyingVarDecl() { return decl->getUnderlyingVarDecl(); } // functions?? TODO
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
- chillAST_VarDecl* multibase();
- chillAST_node *multibase2() { return (chillAST_node *)multibase(); }
-};
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ chillAST_node *findref() { return this; }// find the SINGLE constant or data reference at this node or below
+ const char *getUnderlyingType() {
+ fprintf(stderr, "DeclRefExpr getUnderLyingType()\n");
+ return decl->getUnderlyingType();
+ };
+ virtual chillAST_VarDecl *getUnderlyingVarDecl() { return decl->getUnderlyingVarDecl(); } // functions?? TODO
-class chillAST_CompoundStmt: public chillAST_node {
+ chillAST_VarDecl *multibase();
+
+ chillAST_node *multibase2() { return (chillAST_node *) multibase(); }
+};
+
+
+class chillAST_CompoundStmt : public chillAST_node {
public:
// variables that are special for this type of node
- chillAST_SymbolTable *symbol_table; // symbols defined inside this compound statement
+ chillAST_SymbolTable *symbol_table; // symbols defined inside this compound statement
chillAST_TypedefTable *typedef_table;
- bool hasSymbolTable() { return true; } ;
- bool hasTypeDefTable() { return true; } ;
- chillAST_node *findDatatype( char *t ) {
- fprintf(stderr, "chillAST_CompoundStmt::findDatatype( %s )\n", t);
- if (typedef_table) {
- for (int i=0; i< typedef_table->size(); i++) {
+ bool hasSymbolTable() { return true; };
+
+ bool hasTypeDefTable() { return true; };
+
+ chillAST_node *findDatatype(char *t) {
+ fprintf(stderr, "chillAST_CompoundStmt::findDatatype( %s )\n", t);
+ if (typedef_table) {
+ for (int i = 0; i < typedef_table->size(); i++) {
chillAST_TypedefDecl *tdd = (*typedef_table)[i];
- if (tdd->nameis( t )) return tdd;
+ if (tdd->nameis(t)) return tdd;
}
}
if (parent) return parent->findDatatype(t);
@@ -255,106 +326,125 @@ public:
chillAST_SymbolTable *getSymbolTable() { return symbol_table; }
- chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_CompoundStmt method
+ chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_CompoundStmt method
//fprintf(stderr, "\nchillAST_CompoundStmt addVariableToSymbolTable( %s )\n", vd->varname);
- symbol_table = addSymbolToTable( symbol_table, vd );
+ symbol_table = addSymbolToTable(symbol_table, vd);
//printSymbolTable( symbol_table );
return symbol_table;
}
- void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) {
- typedef_table = addTypedefToTable( typedef_table, tdd );
+ void addTypedefToTypedefTable(chillAST_TypedefDecl *tdd) {
+ typedef_table = addTypedefToTable(typedef_table, tdd);
}
// constructors
chillAST_CompoundStmt(); // never has any args ???
-
+
// other methods particular to this type of node
-
-
+
+
// required methods
- void replaceChild( chillAST_node *old, chillAST_node *newchild );
- void dump( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr );
- chillAST_node* constantFold();
- chillAST_node* clone();
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void dump(int indent = 0, FILE *fp = stderr);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false );
- void loseLoopWithLoopVar( char *var ); // special case this for not for debugging
+ chillAST_node *constantFold();
- void gatherStatements( std::vector<chillAST_node*> &statements );
-};
+ chillAST_node *clone();
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
-class chillAST_RecordDecl: public chillAST_node { // declaration of the shape of a struct or union
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false);
+
+ void loseLoopWithLoopVar(char *var); // special case this for not for debugging
+
+ void gatherStatements(std::vector<chillAST_node *> &statements);
+};
+
+
+class chillAST_RecordDecl : public chillAST_node { // declaration of the shape of a struct or union
private:
char *name; // could be NULL? for unnamed structs?
- char *originalname;
+ char *originalname;
bool isStruct;
bool isUnion;
std::vector<chillAST_VarDecl *> subparts;
-
+
public:
chillAST_RecordDecl();
- chillAST_RecordDecl( const char *nam, chillAST_node *p );
- chillAST_RecordDecl( const char *nam, const char *orig, chillAST_node *p );
-
- void setName( const char *newname) { name = strdup(newname); };
- char *getName( ) { return name; };
-
- bool isAUnion() { return isUnion; };
- bool isAStruct() { return isStruct; };
+
+ chillAST_RecordDecl(const char *nam, chillAST_node *p);
+
+ chillAST_RecordDecl(const char *nam, const char *orig, chillAST_node *p);
+
+ void setName(const char *newname) { name = strdup(newname); };
+
+ char *getName() { return name; };
+
+ bool isAUnion() { return isUnion; };
+
+ bool isAStruct() { return isStruct; };
bool isUnnamed;
- void setUnnamed( bool b ) { isUnnamed = b; };
-
- void setStruct(bool tf) { isStruct = tf; };
+ void setUnnamed(bool b) { isUnnamed = b; };
+
+
+ void setStruct(bool tf) { isStruct = tf; };
+
//fprintf(stderr, "%s isStruct %d\n", structname, isStruct); };
- void setUnion( bool tf) { isUnion = tf; };
-
- chillAST_SymbolTable *addVariableToSymbolTable( chillAST_VarDecl *vd ); // RecordDecl does NOTHING
-
- int numSubparts() { return subparts.size(); };
- void addSubpart( chillAST_VarDecl *s ) { subparts.push_back(s); };
- chillAST_VarDecl *findSubpart( const char *name );
- chillAST_VarDecl *findSubpartByType( const char *typ );
-
- void dump( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr ) ;
- void printStructure( int indent=0, FILE *fp = stderr ) ;
-};
+ void setUnion(bool tf) { isUnion = tf; };
+ chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd); // RecordDecl does NOTHING
+ int numSubparts() { return subparts.size(); };
+
+ void addSubpart(chillAST_VarDecl *s) { subparts.push_back(s); };
+
+ chillAST_VarDecl *findSubpart(const char *name);
+
+ chillAST_VarDecl *findSubpartByType(const char *typ);
+
+ void dump(int indent = 0, FILE *fp = stderr);
+
+ void print(int indent = 0, FILE *fp = stderr);
+
+ void printStructure(int indent = 0, FILE *fp = stderr);
+};
-class chillAST_FunctionDecl: public chillAST_node {
+class chillAST_FunctionDecl : public chillAST_node {
private:
chillAST_CompoundStmt *body; // always a compound statement?
CHILL_FUNCTION_TYPE function_type; // CHILL_FUNCTION_CPU or CHILL_FUNCTION_GPU
bool externfunc; // function is external
bool builtin; // function is a builtin
- bool forwarddecl;
+ bool forwarddecl;
public:
char *returnType;
char *functionName;
// parameters
- int numParameters() { return parameters.size(); } ;
+ int numParameters() { return parameters.size(); };
chillAST_SymbolTable parameters;
// this is probably a mistake, but symbol_table here is pointing to BODY'S symbol table
@@ -363,201 +453,220 @@ public:
chillAST_TypedefTable *typedef_table; // function typedef table
- bool hasSymbolTable() { return true; } ; // COULD HAVE
- bool hasTypeDefTable(){ return true; } ; // COULD HAVE
+ bool hasSymbolTable() { return true; }; // COULD HAVE
+ bool hasTypeDefTable() { return true; }; // COULD HAVE
//char *parametertypes; // a single string??
- void printParameterTypes( FILE *fp );
- void setName( char *n ) { functionName = strdup(n); /* probable memory leak */ };
+ void printParameterTypes(FILE *fp);
- void setBuiltin() { builtin = true; } ; // designate function as a builtin
- bool isBuiltin() { return builtin; } ; // report whether is a builtin
+ void setName(char *n) { functionName = strdup(n); /* probable memory leak */ };
+
+ void setBuiltin() { builtin = true; }; // designate function as a builtin
+ bool isBuiltin() { return builtin; }; // report whether is a builtin
void setExtern() { externfunc = true; }; // designate function as external
- bool isExtern() { return externfunc; }; // report whether function is external
+ bool isExtern() { return externfunc; }; // report whether function is external
void setForward() { forwarddecl = true; }; // designate function as fwd declaration
- bool isForward() { return forwarddecl; }; // report whether function is external
+ bool isForward() { return forwarddecl; }; // report whether function is external
+
+ bool isFunctionCPU() { return (function_type == CHILL_FUNCTION_CPU); };
+
+ bool isFunctionGPU() { return (function_type == CHILL_FUNCTION_GPU); };
- bool isFunctionCPU() { return( function_type == CHILL_FUNCTION_CPU ); };
- bool isFunctionGPU() { return( function_type == CHILL_FUNCTION_GPU ); };
void setFunctionCPU() { function_type = CHILL_FUNCTION_CPU; };
+
void setFunctionGPU() { function_type = CHILL_FUNCTION_GPU; };
void *uniquePtr; // DO NOT REFERENCE THROUGH THIS! USED AS A UNIQUE ID
-
-
+
+
chillAST_FunctionDecl(); // { asttype = CHILLAST_NODETYPE_FUNCTIONDECL; numparameters = 0;};
- chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *p=NULL ) ;
- chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *p, void *unique ) ;
-
- void addParameter( chillAST_VarDecl *p);
- chillAST_VarDecl *hasParameterNamed( const char *name );
- chillAST_VarDecl *findParameterNamed( const char *name ) { return hasParameterNamed( name ); };
+ chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *p = NULL);
+
+ chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *p, void *unique);
- void addDecl( chillAST_VarDecl *vd); // just adds to symbol table?? TODO
+ void addParameter(chillAST_VarDecl *p);
- chillAST_VarDecl *funcHasVariableNamed( const char *name ); // functiondecl::hasVariableNamed
+ chillAST_VarDecl *hasParameterNamed(const char *name);
+
+ chillAST_VarDecl *findParameterNamed(const char *name) { return hasParameterNamed(name); };
+
+ void addDecl(chillAST_VarDecl *vd); // just adds to symbol table?? TODO
+
+ chillAST_VarDecl *funcHasVariableNamed(const char *name); // functiondecl::hasVariableNamed
//chillAST_VarDecl *findVariableNamed( const char *name ) { return hasVariableNamed( name ); };
- void addChild(chillAST_node* node); // special because inserts into BODY
- void insertChild(int i, chillAST_node* node); // special because inserts into BODY
+ void addChild(chillAST_node *node); // special because inserts into BODY
+ void insertChild(int i, chillAST_node *node); // special because inserts into BODY
+
+ void setBody(chillAST_node *bod);
+
+ chillAST_CompoundStmt *getBody() { return (body); }
+
+ void print(int indent = 0, FILE *fp = stderr); // in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // in chill_ast.cc
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void setBody( chillAST_node * bod );
- chillAST_CompoundStmt *getBody() { return( body); }
-
- void print( int indent=0, FILE *fp = stderr ); // in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // in chill_ast.cc
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- chillAST_VarDecl *findArrayDecl( const char *name );
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ chillAST_VarDecl *findArrayDecl(const char *name);
//void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
//void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento )
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void cleanUpVarDecls();
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void cleanUpVarDecls();
//void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false );
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false);
- chillAST_node* constantFold();
+ chillAST_node *constantFold();
- chillAST_node *findDatatype( char *t ) {
- fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
+ chillAST_node *findDatatype(char *t) {
+ fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
if (!typedef_table) { // not here
if (parent) return parent->findDatatype(t); // not here, check parents
else return NULL; // not defined here and no parent
}
-
+
//fprintf(stderr, "%d typedefs\n", typedef_table->size());
- for (int i=0; i< typedef_table->size(); i++) {
+ for (int i = 0; i < typedef_table->size(); i++) {
chillAST_TypedefDecl *tdd = (*typedef_table)[i];
- if ( tdd->nameis( t )) return tdd;
+ if (tdd->nameis(t)) return tdd;
}
if (parent) return parent->findDatatype(t);
return NULL; // should not happen
}
chillAST_SymbolTable *getParameterSymbolTable() { return &parameters; }
- chillAST_SymbolTable *getSymbolTable() { return body->getSymbolTable(); } //symbol_table; } //
- void setSymbolTable( chillAST_SymbolTable *tab ) {
+
+ chillAST_SymbolTable *getSymbolTable() { return body->getSymbolTable(); } //symbol_table; } //
+ void setSymbolTable(chillAST_SymbolTable *tab) {
// no longer keeping a local ?? symbol_table = tab;
if (!body) { // can never happen now
- body = new chillAST_CompoundStmt();
+ body = new chillAST_CompoundStmt();
} // only if func is empty!
- body->symbol_table = tab;
+ body->symbol_table = tab;
}
- chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_FunctionDecl method
+ chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_FunctionDecl method
//fprintf(stderr, "\nchillAST_FunctionDecl addVariableToSymbolTable( %s )\n", vd->varname);
-
+
// this is all dealing with the body's symbol table
// the function has a symbol table called "parameters" but that is a special case
- addSymbolToTable( getSymbolTable(), vd );
- if (!vd->parent) {
+ addSymbolToTable(getSymbolTable(), vd);
+ if (!vd->parent) {
//fprintf(stderr, "setting parent of vardecl to be the function whose symbol table it is going into\n"); // ??
- vd->setParent( this );
- insertChild(0,vd);
+ vd->setParent(this);
+ insertChild(0, vd);
}
//printSymbolTable( getSymbolTable() );
return getSymbolTable();
}
- void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) {
- typedef_table = addTypedefToTable( typedef_table, tdd );
+ void addTypedefToTypedefTable(chillAST_TypedefDecl *tdd) {
+ typedef_table = addTypedefToTable(typedef_table, tdd);
}
- void replaceChild( chillAST_node *old, chillAST_node *newchild ) {
- body->replaceChild( old, newchild );
+ void replaceChild(chillAST_node *old, chillAST_node *newchild) {
+ body->replaceChild(old, newchild);
}
}; // end FunctionDecl
-class chillAST_SourceFile: public chillAST_node {
+class chillAST_SourceFile : public chillAST_node {
public:
// constructors
chillAST_SourceFile(); // defined in chill_ast.cc
- chillAST_SourceFile(const char *filename ); // defined in chill_ast.cc
+ chillAST_SourceFile(const char *filename); // defined in chill_ast.cc
+
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printToFile(char *filename = NULL);
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printToFile( char *filename = NULL );
-
char *SourceFileName; // where this originated
- char *FileToWrite;
+ char *FileToWrite;
char *frontend;
- void setFileToWrite( char *f ) { FileToWrite = strdup( f ); };
-
- void setFrontend( const char *compiler ) { if (frontend) free(frontend); frontend = strdup(compiler); }
+ void setFileToWrite(char *f) { FileToWrite = strdup(f); };
+
+ void setFrontend(const char *compiler) {
+ if (frontend) free(frontend);
+ frontend = strdup(compiler);
+ }
// get, set filename ?
- chillAST_SymbolTable *global_symbol_table; // (global) symbols defined inside this source file
+ chillAST_SymbolTable *global_symbol_table; // (global) symbols defined inside this source file
chillAST_TypedefTable *global_typedef_table; // source file
- chillAST_VarDecl *findVariableNamed( const char *name ); // looks in global_symbol_table;
+ chillAST_VarDecl *findVariableNamed(const char *name); // looks in global_symbol_table;
- bool hasSymbolTable() { return true; } ; // "has" vs "can have" TODO
- bool hasTypeDefTable() { return true; } ;
+ bool hasSymbolTable() { return true; }; // "has" vs "can have" TODO
+ bool hasTypeDefTable() { return true; };
- chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_SourceFile method
+ chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_SourceFile method
fprintf(stderr, "\nchillAST_SourceFile addVariableToSymbolTable( %s )\n", vd->varname);
- global_symbol_table = addSymbolToTable( global_symbol_table, vd );
+ global_symbol_table = addSymbolToTable(global_symbol_table, vd);
//addChild( vd ); // ??
//printSymbolTable( global_symbol_table );
return global_symbol_table;
}
- void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) {
+ void addTypedefToTypedefTable(chillAST_TypedefDecl *tdd) {
//fprintf(stderr, "SOURCEFILE adding typedef %s to typedeftable\n", tdd->getStructName());
- global_typedef_table = addTypedefToTable( global_typedef_table, tdd );
+ global_typedef_table = addTypedefToTable(global_typedef_table, tdd);
//fprintf(stderr, "now global typedef table has %d entries\n", global_typedef_table->size());
}
- chillAST_node *findDatatype( char *t ) {
- fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
+ chillAST_node *findDatatype(char *t) {
+ fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
fprintf(stderr, "%d global typedefs\n", global_typedef_table->size());
- for (int i=0; i< global_typedef_table->size(); i++) {
-
+ for (int i = 0; i < global_typedef_table->size(); i++) {
+
chillAST_TypedefDecl *tdd = (*global_typedef_table)[i];
//fprintf(stderr, "comparing to %s\n", tdd->getStructName());
- if (tdd->nameis( t )) {
+ if (tdd->nameis(t)) {
//fprintf(stderr, "found it\n");
- return (chillAST_node *)tdd;
+ return (chillAST_node *) tdd;
}
}
return NULL;
}
- std::vector< chillAST_FunctionDecl *> functions; // at top level, or anywhere?
- std::vector< chillAST_MacroDefinition *> macrodefinitions;
+ std::vector<chillAST_FunctionDecl *> functions; // at top level, or anywhere?
+ std::vector<chillAST_MacroDefinition *> macrodefinitions;
- chillAST_MacroDefinition* findMacro( const char *name ); // TODO ignores arguments
- chillAST_FunctionDecl *findFunction( const char *name ); // TODO ignores arguments
- chillAST_node *findCall( const char *name );
- void addMacro(chillAST_MacroDefinition* md) {
+ chillAST_MacroDefinition *findMacro(const char *name); // TODO ignores arguments
+ chillAST_FunctionDecl *findFunction(const char *name); // TODO ignores arguments
+ chillAST_node *findCall(const char *name);
+
+ void addMacro(chillAST_MacroDefinition *md) {
macrodefinitions.push_back(md);
//fprintf(stderr, "addMacro(), now %d macros\n", macrodefinitions.size());
}
- void addFunc(chillAST_FunctionDecl* fd) {
+
+ void addFunc(chillAST_FunctionDecl *fd) {
//fprintf(stderr, "chillAST_SourceFile::addFunc( %s %p)\n", fd->functionName, fd);
- bool already = false;
- for (int i=0; i<functions.size(); i++) {
+ bool already = false;
+ for (int i = 0; i < functions.size(); i++) {
//fprintf(stderr, "function %d is %s %p\n", i, functions[i]->functionName, functions[i]);
- if (functions[i] == fd) {
+ if (functions[i] == fd) {
//fprintf(stderr, "function %s was already in source functions\n", fd->functionName);
already = true;
}
@@ -565,71 +674,88 @@ public:
if (!already) functions.push_back(fd);
// PROBABLY fd was created with sourcefile as its parent. Don't add it twice
- addChild( (chillAST_node *)fd); }
+ addChild((chillAST_node *) fd);
+ }
};
-class chillAST_MacroDefinition: public chillAST_node {
+class chillAST_MacroDefinition : public chillAST_node {
private:
chillAST_node *body; // rhs always a compound statement?
chillAST_SymbolTable *symbol_table;
public:
char *macroName;
- char *rhsString;
+ char *rhsString;
// parameters - these will be odd, in that they HAVE NO TYPE
- int numParameters() { return parameters.size(); } ;
- std::vector<chillAST_VarDecl *>parameters;
-
- void setName( char *n ) { macroName = strdup(n); /* probable memory leak */ };
- void setRhsString( char *n ) { rhsString = strdup(n); /* probable memory leak */ };
+ int numParameters() { return parameters.size(); };
+ std::vector<chillAST_VarDecl *> parameters;
+
+ void setName(char *n) { macroName = strdup(n); /* probable memory leak */ };
+
+ void setRhsString(char *n) { rhsString = strdup(n); /* probable memory leak */ };
+
char *getRhsString() { return rhsString; }
chillAST_MacroDefinition();
- chillAST_MacroDefinition( const char *name, chillAST_node *par);
- chillAST_MacroDefinition( const char *name, const char *rhs, chillAST_node *par);
-
- void addParameter( chillAST_VarDecl *p); // parameters have no TYPE ??
- chillAST_VarDecl *hasParameterNamed( const char *name );
- chillAST_VarDecl *findParameterNamed( const char *name ) { return hasParameterNamed( name ); };
- void addChild(chillAST_node* node); // special because inserts into BODY
- void insertChild(int i, chillAST_node* node); // special because inserts into BODY
-
- void setBody( chillAST_node * bod );
- chillAST_node *getBody() { return( body); }
-
- void print( int indent=0, FILE *fp = stderr ); // in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // in chill_ast.cc
-
- bool hasSymbolTable() { return true; } ;
+
+ chillAST_MacroDefinition(const char *name, chillAST_node *par);
+
+ chillAST_MacroDefinition(const char *name, const char *rhs, chillAST_node *par);
+
+ void addParameter(chillAST_VarDecl *p); // parameters have no TYPE ??
+ chillAST_VarDecl *hasParameterNamed(const char *name);
+
+ chillAST_VarDecl *findParameterNamed(const char *name) { return hasParameterNamed(name); };
+
+ void addChild(chillAST_node *node); // special because inserts into BODY
+ void insertChild(int i, chillAST_node *node); // special because inserts into BODY
+
+ void setBody(chillAST_node *bod);
+
+ chillAST_node *getBody() { return (body); }
+
+ void print(int indent = 0, FILE *fp = stderr); // in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // in chill_ast.cc
+
+ bool hasSymbolTable() { return true; };
//const std::vector<chillAST_VarDecl *> getSymbolTable() { return symbol_table; }
chillAST_SymbolTable *getSymbolTable() { return symbol_table; }
- chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_MacroDefinition method ??
+
+ chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_MacroDefinition method ??
//fprintf(stderr, "\nchillAST_MacroDefinition addVariableToSymbolTable( %s )\n", vd->varname);
- symbol_table = addSymbolToTable( symbol_table, vd );
+ symbol_table = addSymbolToTable(symbol_table, vd);
//printSymbolTable( symbol_table );
return symbol_table;
}
- chillAST_node* clone();
+ chillAST_node *clone();
// none of these make sense for macros
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls ){};
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
-
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls ){};
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls ){};
- chillAST_VarDecl *findArrayDecl( const char *name ){};
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ){};
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs ){};
- void cleanUpVarDecls();
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){};
- chillAST_node* constantFold(){};
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {};
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) {};
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) {};
+
+ chillAST_VarDecl *findArrayDecl(const char *name) {};
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {};
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) {};
+
+ void cleanUpVarDecls();
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) {};
+
+ chillAST_node *constantFold() {};
};
-class chillAST_ForStmt: public chillAST_node {
+class chillAST_ForStmt : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *init;
@@ -639,250 +765,320 @@ public:
IR_CONDITION_TYPE conditionoperator; // from ir_code.hh
chillAST_SymbolTable *symbol_table; // symbols defined inside this forstmt (in init but not body?) body is compound stmt
- bool hasSymbolTable() { return true; } ;
+ bool hasSymbolTable() { return true; };
// constructors
chillAST_ForStmt();
- chillAST_ForStmt( chillAST_node *ini, chillAST_node *con, chillAST_node *inc, chillAST_node *bod, chillAST_node *p);
-
+
+ chillAST_ForStmt(chillAST_node *ini, chillAST_node *con, chillAST_node *inc, chillAST_node *bod, chillAST_node *p);
+
// other methods particular to this type of node
void addSyncs();
- void removeSyncComment();
+
+ void removeSyncComment();
+
chillAST_node *getInit() { return init; };
+
chillAST_node *getCond() { return cond; };
- chillAST_node *getInc() { return incr; };
- chillAST_node *getBody() { //fprintf(stderr, "chillAST_ForStmt::getBody(), returning a chillAST_node of type %s\n", body->getTypeString());
- return body; };
- void setBody( chillAST_node *b ) { body = b; b->parent = this; };
-
- bool isNotLeaf() { return true; };
- bool isLeaf() { return false; };
-
-
+
+ chillAST_node *getInc() { return incr; };
+
+ chillAST_node *
+ getBody() { //fprintf(stderr, "chillAST_ForStmt::getBody(), returning a chillAST_node of type %s\n", body->getTypeString());
+ return body;
+ };
+
+ void setBody(chillAST_node *b) {
+ body = b;
+ b->parent = this;
+ };
+
+ bool isNotLeaf() { return true; };
+
+ bool isLeaf() { return false; };
+
+
// required methods that I can't seem to get to inherit
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printControl( int indent=0, FILE *fp = stderr ); // print just for ( ... ) but not body
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printControl(int indent = 0, FILE *fp = stderr); // print just for ( ... ) but not body
+
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- chillAST_node* constantFold();
- chillAST_node* clone();
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); // will get called on inner loops
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false );
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- void gatherLoopIndeces( std::vector<chillAST_VarDecl*> &indeces );
- void gatherLoopVars( std::vector<std::string> &loopvars ); // gather as strings ??
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
- void get_deep_loops( std::vector<chillAST_ForStmt *> &loops) { // chillAST_ForStmt version
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); // will get called on inner loops
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false);
+
+ void gatherLoopIndeces(std::vector<chillAST_VarDecl *> &indeces);
+
+ void gatherLoopVars(std::vector<std::string> &loopvars); // gather as strings ??
+
+ void get_deep_loops(std::vector<chillAST_ForStmt *> &loops) { // chillAST_ForStmt version
// ADD MYSELF!
- loops.push_back( this );
+ loops.push_back(this);
- int n = body->children.size();
+ int n = body->children.size();
//fprintf(stderr, "get_deep_loops of a %s with %d children\n", getTypeString(), n);
- for (int i=0; i<n; i++) {
+ for (int i = 0; i < n; i++) {
//fprintf(stderr, "child %d is a %s\n", i, body->children[i]->getTypeString());
- body->children[i]->get_deep_loops( loops );
+ body->children[i]->get_deep_loops(loops);
}
//fprintf(stderr, "found %d deep loops\n", loops.size());
}
- void find_deepest_loops( std::vector<chillAST_ForStmt *> &loops) {
+ void find_deepest_loops(std::vector<chillAST_ForStmt *> &loops) {
std::vector<chillAST_ForStmt *> b; // deepest loops below me
- int n = body->children.size();
- for (int i=0; i<n; i++) {
+ int n = body->children.size();
+ for (int i = 0; i < n; i++) {
std::vector<chillAST_ForStmt *> l; // deepest loops below one child
- body->children[i]->find_deepest_loops( l );
- if ( l.size() > b.size() ) { // a deeper nesting than we've seen
+ body->children[i]->find_deepest_loops(l);
+ if (l.size() > b.size()) { // a deeper nesting than we've seen
b = l;
}
}
- loops.push_back( this ); // add myself
- for (int i=0; i<b.size(); i++) loops.push_back(b[i]);
+ loops.push_back(this); // add myself
+ for (int i = 0; i < b.size(); i++) loops.push_back(b[i]);
}
- void loseLoopWithLoopVar( char *var ); // chillAST_ForStmt
- void replaceChild( chillAST_node *old, chillAST_node *newchild ) ;
+ void loseLoopWithLoopVar(char *var); // chillAST_ForStmt
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
- chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_ForStmt method
+ chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_ForStmt method
//fprintf(stderr, "\nchillAST_ForStmt addVariableToSymbolTable( %s )\n", vd->varname);
- symbol_table = addSymbolToTable( symbol_table, vd );
+ symbol_table = addSymbolToTable(symbol_table, vd);
//printSymbolTable( symbol_table );
return symbol_table;
}
- void gatherStatements( std::vector<chillAST_node*> &statements );
- bool lowerBound( int &l );
- bool upperBound( int &u );
+ void gatherStatements(std::vector<chillAST_node *> &statements);
-};
+ bool lowerBound(int &l);
+ bool upperBound(int &u);
+
+};
-class chillAST_TernaryOperator: public chillAST_node {
+class chillAST_TernaryOperator : public chillAST_node {
public:
// variables that are special for this type of node
char *op; // TODO need enum so far, only "?" conditional operator
chillAST_node *condition;
chillAST_node *lhs; // keep name from binary
chillAST_node *rhs;
-
-
+
+
// constructors
chillAST_TernaryOperator();
- chillAST_TernaryOperator(const char *op, chillAST_node *cond, chillAST_node *lhs, chillAST_node *rhs, chillAST_node *p=NULL);
-
+
+ chillAST_TernaryOperator(const char *op, chillAST_node *cond, chillAST_node *lhs, chillAST_node *rhs,
+ chillAST_node *p = NULL);
+
// other methods particular to this type of node
- bool isNotLeaf() { return true; };
- bool isLeaf() { return false; };
-
-
- char *getOp() { return op; }; // dangerous. could get changed!
- chillAST_node *getCond() { return condition; };
- chillAST_node *getRHS() { return rhs; };
+ bool isNotLeaf() { return true; };
+
+ bool isLeaf() { return false; };
+
+
+ char *getOp() { return op; }; // dangerous. could get changed!
+ chillAST_node *getCond() { return condition; };
+
+ chillAST_node *getRHS() { return rhs; };
+
chillAST_node *getLHS() { return lhs; };
- void setCond( chillAST_node *newc ) { condition = newc; newc->setParent( this ); }
- void setLHS( chillAST_node *newlhs ) { lhs = newlhs; newlhs->setParent( this ); }
- void setRHS( chillAST_node *newrhs ) { rhs = newrhs; newrhs->setParent( this ); }
+ void setCond(chillAST_node *newc) {
+ condition = newc;
+ newc->setParent(this);
+ }
+
+ void setLHS(chillAST_node *newlhs) {
+ lhs = newlhs;
+ newlhs->setParent(this);
+ }
+
+ void setRHS(chillAST_node *newrhs) {
+ rhs = newrhs;
+ newrhs->setParent(this);
+ }
+
-
-
-
// required methods that I can't seem to get to inherit
- void dump( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printonly( int indent=0, FILE *fp = stderr );
+ void dump(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printonly(int indent = 0, FILE *fp = stderr);
+
+ chillAST_node *constantFold();
- chillAST_node* constantFold();
- chillAST_node* clone();
- void replaceChild( chillAST_node *old, chillAST_node *newchild ) ;
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ chillAST_node *clone();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void gatherVarLHSUsage( std::vector<chillAST_VarDecl*> &decls );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- void loseLoopWithLoopVar( char *var ){}; // ternop can't have loop as child?
-};
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
-class chillAST_BinaryOperator: public chillAST_node {
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void gatherVarLHSUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ void loseLoopWithLoopVar(char *var) {}; // ternop can't have loop as child?
+};
+
+
+class chillAST_BinaryOperator : public chillAST_node {
public:
// variables that are special for this type of node
char *op; // TODO need enum
chillAST_node *lhs;
chillAST_node *rhs;
-
-
+
+
// constructors
chillAST_BinaryOperator();
- chillAST_BinaryOperator(chillAST_node *lhs, const char *op, chillAST_node *rhs, chillAST_node *p=NULL);
-
+
+ chillAST_BinaryOperator(chillAST_node *lhs, const char *op, chillAST_node *rhs, chillAST_node *p = NULL);
+
// other methods particular to this type of node
int evalAsInt();
- chillAST_IntegerLiteral *evalAsIntegerLiteral();
- bool isNotLeaf() { return true; };
- bool isLeaf() { return false; };
-
- chillAST_node *getRHS() { return rhs; };
+ chillAST_IntegerLiteral *evalAsIntegerLiteral();
+
+ bool isNotLeaf() { return true; };
+
+ bool isLeaf() { return false; };
+
+ chillAST_node *getRHS() { return rhs; };
+
chillAST_node *getLHS() { return lhs; };
- void setLHS( chillAST_node *newlhs ) { lhs = newlhs; newlhs->setParent( this ); }
- void setRHS( chillAST_node *newrhs ) { rhs = newrhs; newrhs->setParent( this ); }
-
- char *getOp() { return op; }; // dangerous. could get changed!
- bool isAugmentedAssignmentOp() {
- return
- (!strcmp(op, "*=")) || // BO_MulAssign,
- (!strcmp(op, "/=")) || // BO_DivAssign
- (!strcmp(op, "%=")) || // BO_RemAssign
- (!strcmp(op, "+=")) || // BO_AddAssign
- (!strcmp(op, "-=")) || // BO_SubAssign
-
- (!strcmp(op, "<<=")) || // BO_ShlAssign
- (!strcmp(op, ">>=")) || // BO_ShrAssign
- (!strcmp(op, "&&=")) || // BO_AndAssign
- (!strcmp(op, "||=")) || // BO_OrAssign
-
- (!strcmp(op, "^=")) // BO_XorAssign
- ;
+
+ void setLHS(chillAST_node *newlhs) {
+ lhs = newlhs;
+ newlhs->setParent(this);
+ }
+
+ void setRHS(chillAST_node *newrhs) {
+ rhs = newrhs;
+ newrhs->setParent(this);
+ }
+
+ char *getOp() { return op; }; // dangerous. could get changed!
+ bool isAugmentedAssignmentOp() {
+ return
+ (!strcmp(op, "*=")) || // BO_MulAssign,
+ (!strcmp(op, "/=")) || // BO_DivAssign
+ (!strcmp(op, "%=")) || // BO_RemAssign
+ (!strcmp(op, "+=")) || // BO_AddAssign
+ (!strcmp(op, "-=")) || // BO_SubAssign
+
+ (!strcmp(op, "<<=")) || // BO_ShlAssign
+ (!strcmp(op, ">>=")) || // BO_ShrAssign
+ (!strcmp(op, "&&=")) || // BO_AndAssign
+ (!strcmp(op, "||=")) || // BO_OrAssign
+
+ (!strcmp(op, "^=")) // BO_XorAssign
+ ;
}
- bool isAssignmentOp() {
- return( (!strcmp(op, "=")) || // BO_Assign,
- isAugmentedAssignmentOp() );
- };
- bool isComparisonOp() { return (!strcmp(op,"<")) || (!strcmp(op,">")) || (!strcmp(op,"<=")) || (!strcmp(op,">=")); };
-
- bool isPlusOp() { return (!strcmp(op,"+")); };
- bool isMinusOp() { return (!strcmp(op,"-")); };
- bool isPlusMinusOp() { return (!strcmp(op,"+")) || (!strcmp(op,"-")); };
- bool isMultDivOp() { return (!strcmp(op,"*")) || (!strcmp(op,"/")); };
-
- bool isStructOp() { return (!strcmp(op,".")) || (!strcmp(op,"->")); };
-
-
+
+ bool isAssignmentOp() {
+ return ((!strcmp(op, "=")) || // BO_Assign,
+ isAugmentedAssignmentOp());
+ };
+
+ bool isComparisonOp() {
+ return (!strcmp(op, "<")) || (!strcmp(op, ">")) || (!strcmp(op, "<=")) || (!strcmp(op, ">="));
+ };
+
+ bool isPlusOp() { return (!strcmp(op, "+")); };
+
+ bool isMinusOp() { return (!strcmp(op, "-")); };
+
+ bool isPlusMinusOp() { return (!strcmp(op, "+")) || (!strcmp(op, "-")); };
+
+ bool isMultDivOp() { return (!strcmp(op, "*")) || (!strcmp(op, "/")); };
+
+ bool isStructOp() { return (!strcmp(op, ".")) || (!strcmp(op, "->")); };
+
+
// required methods that I can't seem to get to inherit
- void dump( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printonly( int indent=0, FILE *fp = stderr );
- char *stringRep(int indent=0 );
+ void dump(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printonly(int indent = 0, FILE *fp = stderr);
+
+ char *stringRep(int indent = 0);
+
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
- chillAST_node* constantFold();
- chillAST_node* clone();
- void replaceChild( chillAST_node *old, chillAST_node *newchild ) ;
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ); // chillAST_BinaryOperator
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); // chillAST_BinaryOperator
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void gatherVarLHSUsage( std::vector<chillAST_VarDecl*> &decls );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- void loseLoopWithLoopVar( char *var ){}; // binop can't have loop as child?
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherStatements( std::vector<chillAST_node*> &statements ); //
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
- bool isSameAs( chillAST_node *other );
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
-};
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+ void gatherVarLHSUsage(std::vector<chillAST_VarDecl *> &decls);
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ void loseLoopWithLoopVar(char *var) {}; // binop can't have loop as child?
+ void gatherStatements(std::vector<chillAST_node *> &statements); //
+ bool isSameAs(chillAST_node *other);
+};
-class chillAST_ArraySubscriptExpr: public chillAST_node {
+class chillAST_ArraySubscriptExpr : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *base; // always a decl ref expr? No, for multidimensional array, is another ASE
@@ -891,472 +1087,559 @@ public:
bool imreadfrom; // WARNING: ONLY used when both writtento and readfrom are true x += 1 and so on
chillAST_VarDecl *basedecl; // the vardecl that this refers to
void *uniquePtr; // DO NOT REFERENCE THROUGH THIS!
-
+
// constructors
- chillAST_ArraySubscriptExpr();
- chillAST_ArraySubscriptExpr( chillAST_node *bas, chillAST_node *indx, chillAST_node *p, void *unique);
- chillAST_ArraySubscriptExpr( chillAST_node *bas, chillAST_node *indx, bool writtento, chillAST_node *p, void *unique);
-
- chillAST_ArraySubscriptExpr( chillAST_VarDecl *v, std::vector<chillAST_node *> indeces, chillAST_node *p);
-
+ chillAST_ArraySubscriptExpr();
+
+ chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, chillAST_node *p, void *unique);
+
+ chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, bool writtento, chillAST_node *p, void *unique);
+
+ chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, std::vector<chillAST_node *> indeces, chillAST_node *p);
+
// other methods particular to this type of node
- bool operator!=( const chillAST_ArraySubscriptExpr& ) ;
- bool operator==( const chillAST_ArraySubscriptExpr& ) ;
+ bool operator!=(const chillAST_ArraySubscriptExpr &);
+
+ bool operator==(const chillAST_ArraySubscriptExpr &);
+
chillAST_VarDecl *multibase(); // method for finding the basedecl
- chillAST_node *multibase2() { return base->multibase2(); }
+ chillAST_node *multibase2() { return base->multibase2(); }
chillAST_node *getIndex(int dim);
- void gatherIndeces( std::vector< chillAST_node * > &ind );
- void replaceChild( chillAST_node *old, chillAST_node *newchild ); // will examine index
+ void gatherIndeces(std::vector<chillAST_node *> &ind);
+
+ void replaceChild(chillAST_node *old, chillAST_node *newchild); // will examine index
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printonly( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr ) const; // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- char *stringRep(int indent=0 );
-
- chillAST_node* constantFold();
- chillAST_node* clone();
- chillAST_node *findref(){return this;}// find the SINGLE constant or data reference at this node or below
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
-
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
-
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
-
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
-
- const char* getUnderlyingType() {
- //fprintf(stderr, "ASE getUnderlyingType() base of type %s\n", base->getTypeString()); base->print(); printf("\n"); fflush(stderr);
- return base->getUnderlyingType(); };
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printonly(int indent = 0, FILE *fp = stderr);
+
+ void print(int indent = 0, FILE *fp = stderr) const; // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ char *stringRep(int indent = 0);
+
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ chillAST_node *findref() { return this; }// find the SINGLE constant or data reference at this node or below
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- virtual chillAST_VarDecl* getUnderlyingVarDecl() { return base->getUnderlyingVarDecl(); };
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
-};
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+ const char *getUnderlyingType() {
+ //fprintf(stderr, "ASE getUnderlyingType() base of type %s\n", base->getTypeString()); base->print(); printf("\n"); fflush(stderr);
+ return base->getUnderlyingType();
+ };
+ virtual chillAST_VarDecl *getUnderlyingVarDecl() { return base->getUnderlyingVarDecl(); };
-class chillAST_MemberExpr: public chillAST_node {
+};
+
+
+class chillAST_MemberExpr : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *base; // always a decl ref expr? No, can be Array Subscript Expr
- char *member;
- char *printstring;
+ char *member;
+ char *printstring;
chillAST_VarDecl *basedecl; // the vardecl that this refers to
void *uniquePtr; // DO NOT REFERENCE THROUGH THIS!
- CHILL_MEMBER_EXP_TYPE exptype;
-
+ CHILL_MEMBER_EXP_TYPE exptype;
+
// constructors
- chillAST_MemberExpr();
- chillAST_MemberExpr( chillAST_node *bas, const char *mem, chillAST_node *p, void *unique, CHILL_MEMBER_EXP_TYPE t=CHILL_MEMBER_EXP_DOT);
-
+ chillAST_MemberExpr();
+
+ chillAST_MemberExpr(chillAST_node *bas, const char *mem, chillAST_node *p, void *unique,
+ CHILL_MEMBER_EXP_TYPE t = CHILL_MEMBER_EXP_DOT);
+
// other methods particular to this type of node
- bool operator!=( const chillAST_MemberExpr& ) ;
- bool operator==( const chillAST_MemberExpr& ) ;
-
+ bool operator!=(const chillAST_MemberExpr &);
+
+ bool operator==(const chillAST_MemberExpr &);
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printonly( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr ) const; // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- char *stringRep( int indent = 0);
-
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printonly(int indent = 0, FILE *fp = stderr);
+
+ void print(int indent = 0, FILE *fp = stderr) const; // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ char *stringRep(int indent = 0);
+
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
- chillAST_VarDecl* getUnderlyingVarDecl();
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
- void replaceChild( chillAST_node *old, chillAST_node *newchild );
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
- void setType( CHILL_MEMBER_EXP_TYPE t ) { exptype = t; };
- CHILL_MEMBER_EXP_TYPE getType( CHILL_MEMBER_EXP_TYPE t ) { return exptype; };
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- chillAST_VarDecl* multibase(); // this one will return the member decl
- chillAST_node* multibase2(); // this one will return the member expression
-};
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ chillAST_VarDecl *getUnderlyingVarDecl();
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
+ void setType(CHILL_MEMBER_EXP_TYPE t) { exptype = t; };
-class chillAST_IntegerLiteral: public chillAST_node {
+ CHILL_MEMBER_EXP_TYPE getType(CHILL_MEMBER_EXP_TYPE t) { return exptype; };
+
+ chillAST_VarDecl *multibase(); // this one will return the member decl
+ chillAST_node *multibase2(); // this one will return the member expression
+};
+
+
+class chillAST_IntegerLiteral : public chillAST_node {
public:
// variables that are special for this type of node
int value;
-
+
// constructors
- chillAST_IntegerLiteral(int val, chillAST_node *p = NULL);
-
+ chillAST_IntegerLiteral(int val, chillAST_node *p = NULL);
+
// other methods particular to this type of node
- int evalAsInt() { return value; }
+ int evalAsInt() { return value; }
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ){}; // does nothing
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ){}; // does nothing
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls ){}; // does nothing
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls ){}; // does nothing
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls ){}; // does nothing
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {}; // does nothing
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {}; // does nothing
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs ) {}; // does nothing
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- chillAST_node *findref(){return this;}// find the SINGLE constant or data reference at this node or below
-};
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) {}; // does nothing
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
-class chillAST_FloatingLiteral: public chillAST_node {
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+ chillAST_node *findref() { return this; }// find the SINGLE constant or data reference at this node or below
+};
+
+
+class chillAST_FloatingLiteral : public chillAST_node {
public:
// variables that are special for this type of node
float value;
double doublevalue;
- int float0double1;
+ int float0double1;
char *allthedigits; // if not NULL, use this as printable representation
int precision; // float == 1, double == 2, ???
// constructors
- chillAST_FloatingLiteral( float val, chillAST_node *p);
- chillAST_FloatingLiteral( double val, chillAST_node *p);
- chillAST_FloatingLiteral( float val, int pre, chillAST_node *p);
- chillAST_FloatingLiteral( double val, int pre, chillAST_node *p);
- chillAST_FloatingLiteral( float val, const char *printable, chillAST_node *p);
- chillAST_FloatingLiteral( float val, int pre, const char *printable, chillAST_node *p);
- chillAST_FloatingLiteral( chillAST_FloatingLiteral *old );
-
+ chillAST_FloatingLiteral(float val, chillAST_node *p);
+
+ chillAST_FloatingLiteral(double val, chillAST_node *p);
+
+ chillAST_FloatingLiteral(float val, int pre, chillAST_node *p);
+
+ chillAST_FloatingLiteral(double val, int pre, chillAST_node *p);
+
+ chillAST_FloatingLiteral(float val, const char *printable, chillAST_node *p);
+
+ chillAST_FloatingLiteral(float val, int pre, const char *printable, chillAST_node *p);
+
+ chillAST_FloatingLiteral(chillAST_FloatingLiteral *old);
+
// other methods particular to this type of node
- void setPrecision( int precis ) { precision = precis; };
- int getPrecision() { return precision; }
-
+ void setPrecision(int precis) { precision = precis; };
+
+ int getPrecision() { return precision; }
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ){}; // does nothing
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ){}; // does nothing
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls ){}; // does nothing
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls ){}; // does nothing ;
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls ){}; // does nothing ;
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {}; // does nothing
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {}; // does nothing
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs ){}; // does nothing
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){};
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- chillAST_node *findref(){return this;};// find the SINGLE constant or data reference at this node or below
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- bool isSameAs( chillAST_node *other );
-};
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing ;
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing ;
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) {}; // does nothing
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ chillAST_node *findref() { return this; };// find the SINGLE constant or data reference at this node or below
+
+ bool isSameAs(chillAST_node *other);
+};
-class chillAST_UnaryOperator: public chillAST_node {
+class chillAST_UnaryOperator : public chillAST_node {
public:
// variables that are special for this type of node
char *op; // TODO enum
bool prefix; // or post
chillAST_node *subexpr;
-
+
// constructors
- chillAST_UnaryOperator( const char *oper, bool pre, chillAST_node *sub, chillAST_node *p );
-
+ chillAST_UnaryOperator(const char *oper, bool pre, chillAST_node *sub, chillAST_node *p);
+
// other methods particular to this type of node
- bool isAssignmentOp() {
- return( (!strcmp(op, "++")) ||
- (!strcmp(op, "--")) ); // are there more ??? TODO
+ bool isAssignmentOp() {
+ return ((!strcmp(op, "++")) ||
+ (!strcmp(op, "--"))); // are there more ??? TODO
}
-
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ); // chillAST_UnaryOperator
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarLHSUsage( std::vector<chillAST_VarDecl*> &decls );
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- int evalAsInt();
- bool isSameAs( chillAST_node *other );
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); // chillAST_UnaryOperator
+
+ void gatherVarLHSUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
-};
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+ //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+ int evalAsInt();
+
+ bool isSameAs(chillAST_node *other);
+};
-class chillAST_ImplicitCastExpr: public chillAST_node {
+class chillAST_ImplicitCastExpr : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *subexpr;
-
+
// constructors
- chillAST_ImplicitCastExpr(chillAST_node *sub, chillAST_node *p);
-
+ chillAST_ImplicitCastExpr(chillAST_node *sub, chillAST_node *p);
+
// other methods particular to this type of node
- bool isNotLeaf() { return true; };
- bool isLeaf() { return false; };
-
+ bool isNotLeaf() { return true; };
+
+ bool isLeaf() { return false; };
+
// required methods that I can't seem to get to inherit
- void replaceChild( chillAST_node *old, chillAST_node *newchild );
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printonly( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ) { print( indent, fp); }; // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
-
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
-
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
-
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
+
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printonly(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr) { print(indent, fp); }; // print ast in chill_ast.cc
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
//void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
chillAST_VarDecl *multibase(); // just recurse on subexpr
-};
-
+};
-class chillAST_CStyleCastExpr: public chillAST_node {
+class chillAST_CStyleCastExpr : public chillAST_node {
public:
// variables that are special for this type of node
- char * towhat;
+ char *towhat;
chillAST_node *subexpr;
+
// constructors
- chillAST_CStyleCastExpr(const char *to, chillAST_node *sub, chillAST_node *p=NULL);
-
+ chillAST_CStyleCastExpr(const char *to, chillAST_node *sub, chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void replaceChild( chillAST_node *old, chillAST_node *newchild );
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
+
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- chillAST_node *findref(){return subexpr;};// find the SINGLE constant or data reference at this node or below
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
-};
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
-class chillAST_CStyleAddressOf: public chillAST_node {
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ chillAST_node *findref() { return subexpr; };// find the SINGLE constant or data reference at this node or below
+
+};
+
+
+class chillAST_CStyleAddressOf : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *subexpr;
+
// constructors
- chillAST_CStyleAddressOf(chillAST_node *sub, chillAST_node *p=NULL);
-
+ chillAST_CStyleAddressOf(chillAST_node *sub, chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
//void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
-
-};
+
+};
-class chillAST_CudaMalloc:public chillAST_node {
+class chillAST_CudaMalloc : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *devPtr; // Pointer to allocated device memory
chillAST_node *sizeinbytes;
// constructors
- chillAST_CudaMalloc(chillAST_node *devmemptr, chillAST_node *size, chillAST_node *p=NULL);
-
+ chillAST_CudaMalloc(chillAST_node *devmemptr, chillAST_node *size, chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
//void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
//void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
-};
+};
-class chillAST_CudaFree:public chillAST_node {
+class chillAST_CudaFree : public chillAST_node {
public:
// variables that are special for this type of node
- chillAST_VarDecl *variable;
+ chillAST_VarDecl *variable;
// constructors
- chillAST_CudaFree(chillAST_VarDecl *var, chillAST_node *p=NULL);
-
+ chillAST_CudaFree(chillAST_VarDecl *var, chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- //void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
-};
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ //void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
+ //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
-class chillAST_Malloc:public chillAST_node { // malloc( sizeof(int) * 2048 );
+};
+
+
+class chillAST_Malloc : public chillAST_node { // malloc( sizeof(int) * 2048 );
public:
// variables that are special for this type of node
char *thing; // to void if this is null , sizeof(thing) if it is not
chillAST_node *sizeexpr; // bytes
// constructors
- chillAST_Malloc(chillAST_node *size, chillAST_node *p=NULL);
- chillAST_Malloc(char *thething, chillAST_node *numthings, chillAST_node *p=NULL); // malloc (sizeof(int) *1024)
+ chillAST_Malloc(chillAST_node *size, chillAST_node *p = NULL);
+
+ chillAST_Malloc(char *thething, chillAST_node *numthings, chillAST_node *p = NULL); // malloc (sizeof(int) *1024)
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- //void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
-};
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
-class chillAST_Free:public chillAST_node {
-public:
-
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ //void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
+ //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+};
-};
+class chillAST_Free : public chillAST_node {
+public:
+};
-class chillAST_CudaMemcpy:public chillAST_node {
+class chillAST_CudaMemcpy : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_VarDecl *dest; // Pointer to allocated device memory
@@ -1365,301 +1648,356 @@ public:
char *cudaMemcpyKind; // could use the actual enum
// constructors
- chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_node *size, char *kind, chillAST_node *p=NULL);
-
+ chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_node *size, char *kind,
+ chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
//void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
//void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
-};
+};
-class chillAST_CudaSyncthreads:public chillAST_node {
+class chillAST_CudaSyncthreads : public chillAST_node {
public:
// variables that are special for this type of node
// constructors
- chillAST_CudaSyncthreads(chillAST_node *p=NULL);
-
+ chillAST_CudaSyncthreads(chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
//chillAST_node* constantFold() {};
//chillAST_node* clone();
//void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ){};
//void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
//void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
//void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
//bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; };
-};
+};
-
-class chillAST_ReturnStmt: public chillAST_node {
+class chillAST_ReturnStmt : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *returnvalue;
-
+
// constructors
- chillAST_ReturnStmt( chillAST_node *retval, chillAST_node *p );
-
+ chillAST_ReturnStmt(chillAST_node *retval, chillAST_node *p);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
-};
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
-class chillAST_CallExpr: public chillAST_node { // a function call
+ //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+};
+
+
+class chillAST_CallExpr : public chillAST_node { // a function call
public:
// variables that are special for this type of node
chillAST_node *callee; // the function declaration (what about builtins?)
int numargs;
- std::vector<class chillAST_node*> args;
+ std::vector<class chillAST_node *> args;
chillAST_VarDecl *grid;
chillAST_VarDecl *block;
// constructors
- chillAST_CallExpr(chillAST_node *function, chillAST_node *p );
- void addArg( chillAST_node *newarg );
-
+ chillAST_CallExpr(chillAST_node *function, chillAST_node *p);
+
+ void addArg(chillAST_node *newarg);
+
// other methods particular to this type of node
// TODO get/set grid, block
-
+
// required methods that I can't seem to get to inherit
- chillAST_node* constantFold();
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ chillAST_node *constantFold();
+
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- chillAST_node* clone();
-};
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ chillAST_node *clone();
+};
-class chillAST_ParenExpr: public chillAST_node {
+
+class chillAST_ParenExpr : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *subexpr;
-
+
// constructors
- chillAST_ParenExpr( chillAST_node *sub, chillAST_node *p=NULL );
-
+ chillAST_ParenExpr(chillAST_node *sub, chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
-};
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
-class chillAST_Sizeof: public chillAST_node {
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+};
+
+
+class chillAST_Sizeof : public chillAST_node {
public:
// variables that are special for this type of node
- char *thing;
-
+ char *thing;
+
// constructors
- chillAST_Sizeof( char *t, chillAST_node *p = NULL );
-
+ chillAST_Sizeof(char *t, chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){};
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
-};
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
-class chillAST_NoOp: public chillAST_node {
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+};
+
+
+class chillAST_NoOp : public chillAST_node {
public:
- chillAST_NoOp( chillAST_node *p = NULL ); // { parent = p; };
+ chillAST_NoOp(chillAST_node *p = NULL); // { parent = p; };
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ) {}; // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ) {}; // print ast in chill_ast.cc
- chillAST_node* constantFold() {};
- chillAST_node* clone() { return new chillAST_NoOp( parent ); }; // ??
+ void print(int indent = 0, FILE *fp = stderr) {}; // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr) {}; // print ast in chill_ast.cc
+ chillAST_node *constantFold() {};
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {};
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {};
+ chillAST_node *clone() { return new chillAST_NoOp(parent); }; // ??
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls ){};
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {};
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls ){};
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls ){};
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {};
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ){};
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs ){};
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){};
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; };//no loops under here
-};
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {};
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) {};
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) {};
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {};
-class chillAST_IfStmt: public chillAST_node {
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) {};
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; };//no loops under here
+};
+
+
+class chillAST_IfStmt : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *cond;
chillAST_node *thenpart;
chillAST_node *elsepart;
IR_CONDITION_TYPE conditionoperator; // from ir_code.hh
-
+
// constructors
chillAST_IfStmt();
- chillAST_IfStmt( chillAST_node *c, chillAST_node *t, chillAST_node *e, chillAST_node *p);
-
+
+ chillAST_IfStmt(chillAST_node *c, chillAST_node *t, chillAST_node *e, chillAST_node *p);
+
// other methods particular to this type of node
chillAST_node *getCond() { return cond; };
+
chillAST_node *getThen() { return thenpart; };
+
chillAST_node *getElse() { return elsepart; };
- void setCond( chillAST_node *b ) { cond = b; if (cond) cond->parent = this; };
- void setThen( chillAST_node *b ) { thenpart = b; if (thenpart) thenpart->parent = this; };
- void setElse( chillAST_node *b ) { elsepart = b; if (elsepart) elsepart->parent = this; };
-
+ void setCond(chillAST_node *b) {
+ cond = b;
+ if (cond) cond->parent = this;
+ };
+
+ void setThen(chillAST_node *b) {
+ thenpart = b;
+ if (thenpart) thenpart->parent = this;
+ };
+
+ void setElse(chillAST_node *b) {
+ elsepart = b;
+ if (elsepart) elsepart->parent = this;
+ };
+
// required methods that I can't seem to get to inherit
- void dump( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr );
+ void dump(int indent = 0, FILE *fp = stderr);
- chillAST_node* constantFold();
- chillAST_node* clone();
+ void print(int indent = 0, FILE *fp = stderr);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *constantFold();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ chillAST_node *clone();
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false );
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherStatements( std::vector<chillAST_node*> &statements );
-
-};
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+ //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false);
+
+ void gatherStatements(std::vector<chillAST_node *> &statements);
+
+};
-class chillAST_something: public chillAST_node {
+
+class chillAST_something : public chillAST_node {
public:
// variables that are special for this type of node
-
+
// constructors
- chillAST_something();
-
+ chillAST_something();
+
// other methods particular to this type of node
-
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
//void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
-};
-
-
-
-
-
+};
#endif
diff --git a/include/chill_error.hh b/include/chill_error.hh
index c5601ae..7321e75 100644
--- a/include/chill_error.hh
+++ b/include/chill_error.hh
@@ -7,22 +7,22 @@
*/
//! for loop transformation problem
-struct loop_error: public std::runtime_error {
- loop_error(const std::string &msg): std::runtime_error(msg){}
+struct loop_error : public std::runtime_error {
+ loop_error(const std::string &msg) : std::runtime_error(msg) {}
};
//! for generic compiler intermediate code handling problem
-struct ir_error: public std::runtime_error {
- ir_error(const std::string &msg): std::runtime_error(msg){}
+struct ir_error : public std::runtime_error {
+ ir_error(const std::string &msg) : std::runtime_error(msg) {}
};
//! 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){}
+struct ir_exp_error : public ir_error {
+ ir_exp_error(const std::string &msg) : ir_error(msg) {}
};
-struct omega_error: public std::runtime_error {
- omega_error(const std::string &msg): std::runtime_error(msg){}
+struct omega_error : public std::runtime_error {
+ omega_error(const std::string &msg) : std::runtime_error(msg) {}
};
#endif
diff --git a/include/chilldebug.h b/include/chilldebug.h
index c09aa59..010687a 100644
--- a/include/chilldebug.h
+++ b/include/chilldebug.h
@@ -12,11 +12,11 @@
#define FILENAME basename(strdup(__FILE__))
#ifdef DEBUGCHILL
-#define CHILL_DEBUG_PRINT(format,args...) fprintf(stderr,"%s, %s, LN%d:\t" format,FILENAME,__FUNCTION__, \
+#define CHILL_DEBUG_PRINT(format,args...) fprintf(stderr,"%15s | %15s | LN%-4d:\t" format,FILENAME,__FUNCTION__, \
__LINE__, ##args )
#define CHILL_DEBUG_BEGIN { \
- fprintf(stderr,"=========\t%s, %s, LN%d\t=========\n",FILENAME,__FUNCTION__,__LINE__);
-#define CHILL_DEBUG_END fprintf(stderr,"===========================\n");}
+ fprintf(stderr,"=========\t%15s, %15s, LN%-4d\t=========\n",FILENAME,__FUNCTION__,__LINE__);
+#define CHILL_DEBUG_END fprintf(stderr,"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");}
#else
#define CHILL_DEBUG_PRINT(format,args...) do {} while(0) /* Don't do anything */
#define CHILL_DEBUG_BEGIN while(0) {
diff --git a/include/chillmodule.hh b/include/chillmodule.hh
index e83119f..896cc7c 100644
--- a/include/chillmodule.hh
+++ b/include/chillmodule.hh
@@ -9,7 +9,9 @@
#include <Python.h>
void finalize_loop(int loop_num_start, int loop_num_end);
+
int get_loop_num_start();
+
int get_loop_num_end();
//! pass C methods to python
PyMODINIT_FUNC initchill();
diff --git a/include/dep.hh b/include/dep.hh
index 73c662c..ffd2db5 100644
--- a/include/dep.hh
+++ b/include/dep.hh
@@ -6,25 +6,29 @@
#include "ir_code.hh"
#include "chill_error.hh"
-enum DependenceType { DEP_W2R, DEP_R2W, DEP_W2W, DEP_R2R, DEP_CONTROL, DEP_UNKNOWN };
+enum DependenceType {
+ DEP_W2R, DEP_R2W, DEP_W2W, DEP_R2R, DEP_CONTROL, DEP_UNKNOWN
+};
class DependenceVector;
+
typedef std::vector<DependenceVector> DependenceList;
struct DependenceVector {
DependenceType type;
IR_Symbol *sym;
-
+
bool from_same_stmt; // Manu
bool is_reduction_cand; // Manu
bool is_reduction; // used to identify a class of flow dependence
- // that can be broken
+ // that can be broken
std::vector<omega::coef_t> lbounds;
std::vector<omega::coef_t> ubounds;
-
+
bool quasi;
bool is_scalar_dependence;
+
DependenceVector() {
type = DEP_UNKNOWN;
sym = NULL;
@@ -34,52 +38,78 @@ struct DependenceVector {
quasi = false;
is_scalar_dependence = false;
}
+
DependenceVector(const DependenceVector &that);
+
~DependenceVector() { delete sym; } // is this legal? TODO
DependenceVector &operator=(const DependenceVector &that);
-
+
bool is_data_dependence() const;
+
bool is_control_dependence() const;
+
bool has_negative_been_carried_at(int dim) const;
+
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
bool isZero() const;
+
bool isPositive() const;
+
bool isNegative() const;
+
bool isAllPositive() const;
+
bool isAllNegative() const;
+
bool isZero(int dim) const;
+
bool hasPositive(int dim) const;
+
bool hasNegative(int dim) const;
+
bool isCarried(int dim, omega::coef_t distance = posInfinity) const;
+
bool canPermute(const std::vector<int> &pi) const;
-
+
std::vector<DependenceVector> normalize() const;
+
std::vector<DependenceVector> permute(const std::vector<int> &pi) const;
+
DependenceVector reverse() const;
+
DependenceType getType() const;
- friend std::ostream& operator<<(std::ostream &os, const DependenceVector &d);
+
+ friend std::ostream &operator<<(std::ostream &os, const DependenceVector &d);
};
+class DependenceGraph : public Graph<Empty, DependenceVector> {
-class DependenceGraph: public Graph<Empty, DependenceVector> {
-
protected:
int num_dim_;
-
+
public:
DependenceGraph(int n) { num_dim_ = n; }
+
DependenceGraph() { num_dim_ = 0; }
+
~DependenceGraph() {}
+
int num_dim() const { return num_dim_; }
+
DependenceGraph permute(const std::vector<int> &pi,
const std::set<int> &active = std::set<int>()) const;
+
DependenceGraph subspace(int dim) const;
+
bool isPositive() const;
+
bool hasPositive(int dim) const;
+
bool hasNegative(int dim) const;
};
diff --git a/include/graph.hh b/include/graph.hh
index 211444a..e5885ce 100644
--- a/include/graph.hh
+++ b/include/graph.hh
@@ -37,17 +37,25 @@
struct Empty {
Empty() {};
+
bool operator<(const Empty &) const { return true; };
+
bool operator==(const Empty &) const { return false; };
- friend std::ostream& operator<<(std::ostream &os, const Empty &) { return os; };
+
+ friend std::ostream &operator<<(std::ostream &os, const Empty &) { return os; };
};
namespace {
- enum GraphColorType {WHITE, GREY, BLACK};
+ enum GraphColorType {
+ WHITE, GREY, BLACK
+ };
}
-template<typename VertexType, typename EdgeType> struct Graph;
-template<typename VertexType, typename EdgeType> std::ostream& operator<<(std::ostream &os, const Graph<VertexType, EdgeType> &g);
+template<typename VertexType, typename EdgeType>
+struct Graph;
+
+template<typename VertexType, typename EdgeType>
+std::ostream &operator<<(std::ostream &os, const Graph<VertexType, EdgeType> &g);
template<typename VertexType = Empty, typename EdgeType = Empty>
struct Graph {
@@ -58,18 +66,27 @@ struct Graph {
bool directed;
Graph(bool directed = true);
-
+
int vertexCount() const;
+
int edgeCount() const;
+
bool isEmpty() const;
+
bool isDirected() const;
+
int insert(const VertexType &v = VertexType());
+
void connect(int v1, int v2, const EdgeType &e = EdgeType());
+
void connect(int v1, int v2, const std::vector<EdgeType> &e);
+
void disconnect(int v1, int v2);
+
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;
@@ -80,15 +97,16 @@ struct Graph {
void dump() {
std::cout << *this;
}
-
- friend std::ostream& operator<< <>(std::ostream &os, const Graph<VertexType, EdgeType> &g);
+
+ friend std::ostream &operator<<<>(std::ostream &os, const Graph<VertexType, EdgeType> &g);
};
template<typename VertexType, typename EdgeType>
-std::ostream& operator<<(std::ostream &os, const Graph<VertexType, EdgeType> &g) {
+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 << "s" << i << "->" << "s" << j->first << ":";
+ for (typename Graph<VertexType, EdgeType>::EdgeList::const_iterator j = g.vertex[i].second.begin();
+ j != g.vertex[i].second.end(); j++) {
+ os << "s" << i << "->" << "s" << j->first << ":";
for (typename std::vector<EdgeType>::const_iterator k = j->second.begin(); k != j->second.end(); k++)
os << " " << *k;
os << std::endl;
@@ -100,7 +118,7 @@ std::ostream& operator<<(std::ostream &os, const Graph<VertexType, EdgeType> &g)
template<typename VertexType, typename EdgeType>
Graph<VertexType, EdgeType>::Graph(bool directed_):
- directed(directed_) {
+ directed(directed_) {
}
template<typename VertexType, typename EdgeType>
@@ -117,8 +135,8 @@ int Graph<VertexType, EdgeType>::edgeCount() const {
result += j->second.size();
if (!directed)
- result = result/2;
-
+ result = result / 2;
+
return result;
}
@@ -133,7 +151,7 @@ bool Graph<VertexType, EdgeType>::isDirected() const {
}
template<typename VertexType, typename EdgeType>
-int Graph<VertexType, EdgeType>::insert(const VertexType & v) {
+int Graph<VertexType, EdgeType>::insert(const VertexType &v) {
for (int i = 0; i < vertex.size(); i++)
if (vertex[i].first == v)
return i;
@@ -141,10 +159,10 @@ int Graph<VertexType, EdgeType>::insert(const VertexType & v) {
vertex.push_back(std::make_pair(v, EdgeList()));
return vertex.size() - 1;
}
-
-
+
+
template<typename VertexType, typename EdgeType>
-void Graph<VertexType, EdgeType>::connect(int v1, int v2, const EdgeType &e) {
+void Graph<VertexType, EdgeType>::connect(int v1, int v2, const EdgeType &e) {
assert(v1 < vertex.size() && v2 < vertex.size());
vertex[v1].second[v2].push_back(e);;
@@ -153,19 +171,19 @@ void Graph<VertexType, EdgeType>::connect(int v1, int v2, const EdgeType &e) {
}
template<typename VertexType, typename EdgeType>
-void Graph<VertexType, EdgeType>::connect(int v1, int v2, const std::vector<EdgeType> &e) {
+void Graph<VertexType, EdgeType>::connect(int v1, int v2, const std::vector<EdgeType> &e) {
assert(v1 < vertex.size() && v2 < vertex.size());
if (e.size() == 0)
return;
-
+
copy(e.begin(), e.end(), back_inserter(vertex[v1].second[v2]));
if (!directed)
copy(e.begin(), e.end(), back_inserter(vertex[v2].second[v1]));
}
template<typename VertexType, typename EdgeType>
-void Graph<VertexType, EdgeType>::disconnect(int v1, int v2) {
+void Graph<VertexType, EdgeType>::disconnect(int v1, int v2) {
assert(v1 < vertex.size() && v2 < vertex.size());
vertex[v1].second.erase(v2);
@@ -174,12 +192,12 @@ void Graph<VertexType, EdgeType>::disconnect(int v1, int v2) {
}
template<typename VertexType, typename EdgeType>
-bool Graph<VertexType,EdgeType>::hasEdge(int v1, int v2) const {
+bool Graph<VertexType, EdgeType>::hasEdge(int v1, int v2) const {
return vertex[v1].second.find(v2) != vertex[v1].second.end();
}
template<typename VertexType, typename EdgeType>
-std::vector<EdgeType> Graph<VertexType,EdgeType>::getEdge(int v1, int v2) const {
+std::vector<EdgeType> Graph<VertexType, EdgeType>::getEdge(int v1, int v2) const {
if (!hasEdge(v1, v2))
return std::vector<EdgeType>();
@@ -194,9 +212,9 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::topoSort() const {
std::vector<int> order(n);
int c = n;
-
+
// first DFS
- for (int i = n-1; i >= 0; i--)
+ for (int i = n - 1; i >= 0; i--)
if (color[i] == WHITE) {
S.push(i);
while (!S.empty()) {
@@ -208,13 +226,11 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::topoSort() const {
S.push(j->first);
color[v] = GREY;
- }
- else if (color[v] == GREY) {
+ } else if (color[v] == GREY) {
color[v] = BLACK;
S.pop();
order[--c] = v;
- }
- else {
+ } else {
S.pop();
}
}
@@ -225,31 +241,29 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::topoSort() const {
for (int i = 0; i < n; i++)
for (typename EdgeList::const_iterator j = vertex[i].second.begin(); j != vertex[i].second.end(); j++)
edgeT[j->first].insert(i);
-
+
// second DFS in transposed graph starting from last finished vertex
fill(color.begin(), color.end(), WHITE);
std::vector<std::set<int> > result;
for (int i = 0; i < n; i++)
if (color[order[i]] == WHITE) {
std::set<int> s;
-
+
S.push(order[i]);
while (!S.empty()) {
int v = S.top();
-
- if(color[v] == WHITE) {
+
+ if (color[v] == WHITE) {
for (std::set<int>::const_iterator j = edgeT[v].begin(); j != edgeT[v].end(); j++)
if (color[*j] == WHITE)
S.push(*j);
color[v] = GREY;
- }
- else if (color[v] == GREY) {
+ } else if (color[v] == GREY) {
color[v] = BLACK;
S.pop();
s.insert(v);
- }
- else {
+ } else {
S.pop();
}
}
@@ -268,9 +282,9 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::packed_topoSort() const
std::vector<bool> is_root(n, false);
std::vector<std::set<int> > edges(n);
-
+
// first DFS
- for (int i = n-1; i >= 0; i--)
+ for (int i = n - 1; i >= 0; i--)
if (color[i] == WHITE) {
S.push(i);
is_root[i] = true;
@@ -282,8 +296,7 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::packed_topoSort() const
if (color[j->first] == WHITE) {
S.push(j->first);
edges[v].insert(j->first);
- }
- else if (color[j->first] == BLACK) {
+ } else if (color[j->first] == BLACK) {
if (is_root[j->first]) {
is_root[j->first] = false;
edges[v].insert(j->first);
@@ -291,12 +304,10 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::packed_topoSort() const
}
color[v] = GREY;
- }
- else if (color[v] == GREY) {
+ } else if (color[v] == GREY) {
color[v] = BLACK;
S.pop();
- }
- else {
+ } else {
S.pop();
}
}
@@ -313,7 +324,7 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::packed_topoSort() const
result.push_back(s);
while (true) {
std::set<int> s;
- for (std::set<int>::iterator i = result[result.size()-1].begin(); i != result[result.size()-1].end(); i++)
+ for (std::set<int>::iterator i = result[result.size() - 1].begin(); i != result[result.size() - 1].end(); i++)
s.insert(edges[*i].begin(), edges[*i].end());
if (s.size() != 0)
result.push_back(s);
diff --git a/include/ir_clang.hh b/include/ir_clang.hh
index e637016..9148eb3 100755
--- a/include/ir_clang.hh
+++ b/include/ir_clang.hh
@@ -6,6 +6,7 @@
#include "chill_error.hh"
#define __STDC_CONSTANT_MACROS
+
#include "clang/AST/Decl.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ParentMap.h"
@@ -34,37 +35,39 @@ extern std::vector<chillAST_VarDecl *> VariableDeclarations; // a global. TOD
typedef llvm::SmallVector<clang::Stmt *, 16> StmtList; // TODO delete
-struct IR_chillScalarSymbol: public IR_ScalarSymbol {
- chillAST_VarDecl *chillvd;
+struct IR_chillScalarSymbol : public IR_ScalarSymbol {
+ chillAST_VarDecl *chillvd;
IR_chillScalarSymbol(const IR_Code *ir, chillAST_VarDecl *vd) {
- fprintf(stderr, "making scalar symbol %s\n", vd->varname);
+ fprintf(stderr, "making scalar symbol %s\n", vd->varname);
ir_ = ir;
chillvd = vd;
}
-
+
std::string name() const;
+
int size() const;
+
bool operator==(const IR_Symbol &that) const;
+
IR_Symbol *clone() const;
};
-
-struct IR_chillArraySymbol: public IR_ArraySymbol {
+struct IR_chillArraySymbol : public IR_ArraySymbol {
//int indirect_; // what was this?
int offset_; // what is this?
- chillAST_VarDecl *chillvd;
+ chillAST_VarDecl *chillvd;
IR_chillArraySymbol(const IR_Code *ir, chillAST_VarDecl *vd, int offset = 0) {
//if ( vd == 0 )
//fprintf(stderr, "IR_chillArraySymbol::IR_chillArraySymbol (%s) vd 0x%x\n", vd->varname, vd);
ir_ = ir;
- chillvd = vd;
+ chillvd = vd;
//indirect_ = indirect;
offset_ = offset;
}
-
+
// No Fortran support!
IR_ARRAY_LAYOUT_TYPE layout_type() const {
@@ -72,104 +75,115 @@ struct IR_chillArraySymbol: public IR_ArraySymbol {
}
std::string name() const;
+
int elem_size() const;
+
int n_dim() const;
+
omega::CG_outputRepr *size(int dim) const;
+
bool operator!=(const IR_Symbol &that) const;
+
bool operator==(const IR_Symbol &that) const;
+
IR_Symbol *clone() const;
- // TODO Hack to pass build
+
+ // TODO Hack to pass build
IR_CONSTANT_TYPE elem_type() const {
- fprintf(stderr,"Not implemented elem_type in IR_chillArraySymbol");
- return IR_CONSTANT_UNKNOWN;};
-
-};
+ fprintf(stderr, "Not implemented elem_type in IR_chillArraySymbol");
+ return IR_CONSTANT_UNKNOWN;
+ };
+};
-struct IR_chillConstantRef: public IR_ConstantRef {
+struct IR_chillConstantRef : public IR_ConstantRef {
union {
omega::coef_t i_;
double f_;
};
-
+
IR_chillConstantRef(const IR_Code *ir, omega::coef_t i) {
ir_ = ir;
type_ = IR_CONSTANT_INT;
i_ = i;
}
+
IR_chillConstantRef(const IR_Code *ir, double f) {
ir_ = ir;
type_ = IR_CONSTANT_FLOAT;
f_ = f;
}
+
omega::coef_t integer() const {
assert(is_integer());
return i_;
}
+
bool operator==(const IR_Ref &that) const;
+
omega::CG_outputRepr *convert();
+
IR_Ref *clone() const;
-
+
};
-enum OP_POSITION { OP_DEST =-1, OP_UNKNOWN, OP_SRC };
+enum OP_POSITION {
+ OP_DEST = -1, OP_UNKNOWN, OP_SRC
+};
#define OP_LEFT OP_DEST
#define OP_RIGHT OP_SRC
-struct IR_chillScalarRef: public IR_ScalarRef {
+struct IR_chillScalarRef : public IR_ScalarRef {
OP_POSITION op_pos_; // -1 means destination operand, 0== unknown, 1 == source operand
//chillAST_BinaryOperator *bop; // binary op that contains this scalar?
- chillAST_DeclRefExpr *dre; // declrefexpr that uses this scalar ref, if that exists
- chillAST_VarDecl *chillvd; // the vardecl for this scalar
-
+ chillAST_DeclRefExpr *dre; // declrefexpr that uses this scalar ref, if that exists
+ chillAST_VarDecl *chillvd; // the vardecl for this scalar
+
IR_chillScalarRef(const IR_Code *ir, chillAST_BinaryOperator *ins, OP_POSITION pos) {
- fprintf(stderr, "\n***** new IR_xxxxScalarRef( ir, ins, pos ) *****\n\n");
- exit(-1);
+ fprintf(stderr, "\n***** new IR_xxxxScalarRef( ir, ins, pos ) *****\n\n");
+ exit(-1);
// this constructor takes a binary operation and an indicator of which side of the op to use,
// and finds the scalar in the lhs or rhs of the binary op.
ir_ = ir;
dre = NULL;
//bop = ins; // do we need this?
- if (pos == OP_LEFT) {
+ if (pos == OP_LEFT) {
chillAST_node *lhs = ins->lhs;
- if (lhs->isDeclRefExpr()) {
+ if (lhs->isDeclRefExpr()) {
chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) lhs;
- dre = DRE;
+ dre = DRE;
chillvd = DRE->getVarDecl();
+ } else if (lhs->isVarDecl()) {
+ chillvd = (chillAST_VarDecl *) lhs;
+ } else {
+ fprintf(stderr, "IR_chillScalarRef constructor, I'm confused\n");
+ exit(-1);
}
- else if (lhs->isVarDecl()) {
- chillvd = (chillAST_VarDecl *)lhs;
- }
- else {
- fprintf(stderr, "IR_chillScalarRef constructor, I'm confused\n"); exit(-1);
- }
- }
- else {
+ } else {
chillAST_node *rhs = ins->rhs;
- if (rhs->isDeclRefExpr()) {
+ if (rhs->isDeclRefExpr()) {
chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) rhs;
dre = DRE;
chillvd = DRE->getVarDecl();
- }
- else if (rhs->isVarDecl()) {
- chillvd = (chillAST_VarDecl *)rhs;
- }
- else {
- fprintf(stderr, "IR_chillScalarRef constructor, I'm confused\n"); exit(-1);
+ } else if (rhs->isVarDecl()) {
+ chillvd = (chillAST_VarDecl *) rhs;
+ } else {
+ fprintf(stderr, "IR_chillScalarRef constructor, I'm confused\n");
+ exit(-1);
}
}
op_pos_ = pos;
}
- IR_chillScalarRef(const IR_Code *ir, chillAST_DeclRefExpr *d) {
+ IR_chillScalarRef(const IR_Code *ir, chillAST_DeclRefExpr *d) {
// fprintf(stderr, "\n***** new IR_xxxxScalarRef( ir, REF EXPR sym %s ) *****\n\n", d->getVarDecl()->varname);
//fprintf(stderr, "new IR_chillScalarRef with a DECLREFEXPR (has dre) \n");
ir_ = ir;
dre = d;
//bop = NULL;
- chillvd = d->getVarDecl();
- op_pos_ = OP_UNKNOWN;
+ chillvd = d->getVarDecl();
+ op_pos_ = OP_UNKNOWN;
//fprintf(stderr, "\nScalarRef has:\n");
//fprintf(stderr, "assignment op DOESNT EXIST\n");
@@ -178,14 +192,16 @@ struct IR_chillScalarRef: public IR_ScalarRef {
//fprintf(stderr, "ref expr dre = 0x%x\n", dre);
}
- IR_chillScalarRef(const IR_Code *ir, chillAST_VarDecl *vardecl) {
- fprintf(stderr, "\n***** new IR_xxxxScalarRef( ir, sym 0x1234567 ) ***** THIS SHOULD NEVER HAPPEN\n\n");
- fprintf(stderr, "vardecl %s\n", vardecl->varname);
+ IR_chillScalarRef(const IR_Code *ir, chillAST_VarDecl *vardecl) {
+ fprintf(stderr,
+ "\n***** new IR_xxxxScalarRef( ir, sym 0x1234567 ) ***** THIS SHOULD NEVER HAPPEN\n\n");
+ fprintf(stderr, "vardecl %s\n", vardecl->varname);
ir_ = ir;
- dre = NULL; fprintf(stderr, "new IR_chillScalarRef with a vardecl but no dre\n");
+ dre = NULL;
+ fprintf(stderr, "new IR_chillScalarRef with a vardecl but no dre\n");
//bop = NULL;
- chillvd = vardecl;
- op_pos_ = OP_UNKNOWN;
+ chillvd = vardecl;
+ op_pos_ = OP_UNKNOWN;
//fprintf(stderr, "\nScalarRef has:\n");
//fprintf(stderr, "assignment op DOESNT EXIST\n");
@@ -194,21 +210,24 @@ struct IR_chillScalarRef: public IR_ScalarRef {
//fprintf(stderr, "ref expr dre = 0x%x\n", dre);
}
-
+
bool is_write() const;
+
IR_ScalarSymbol *symbol() const;
+
bool operator==(const IR_Ref &that) const;
+
omega::CG_outputRepr *convert();
+
IR_Ref *clone() const;
};
-
-struct IR_chillArrayRef: public IR_ArrayRef {
+struct IR_chillArrayRef : public IR_ArrayRef {
//DeclRefExpr *as_;
//chillAST_DeclRefExpr *chillDRE;
- chillAST_ArraySubscriptExpr* chillASE;
- int iswrite;
+ chillAST_ArraySubscriptExpr *chillASE;
+ int iswrite;
// IR_chillArrayRef(const IR_Code *ir, DeclRefExpr *as, ParentMap *pMap = NULL) {
@@ -216,102 +235,118 @@ struct IR_chillArrayRef: public IR_ArrayRef {
// fprintf(stderr, "new IR_chillArrayRef() CLANG ERROR\n"); exit(-1);
//}
- IR_chillArrayRef(const IR_Code *ir, chillAST_ArraySubscriptExpr *ase, int write ) {
+ IR_chillArrayRef(const IR_Code *ir, chillAST_ArraySubscriptExpr *ase, int write) {
//fprintf(stderr, "IR_chillArrayRef::IR_chillArrayRef() write %d\n", write);
ir_ = ir;
- chillASE = ase;
+ chillASE = ase;
iswrite = write; // ase->imwrittento;
}
bool is_write() const;
+
omega::CG_outputRepr *index(int dim) const;
+
IR_ArraySymbol *symbol() const;
+
bool operator!=(const IR_Ref &that) const;
+
bool operator==(const IR_Ref &that) const;
+
omega::CG_outputRepr *convert();
+
IR_Ref *clone() const;
+
virtual void Dump() const;
};
-
-struct IR_chillLoop: public IR_Loop {
+struct IR_chillLoop : public IR_Loop {
int step_size_;
chillAST_DeclRefExpr *chillindex; // the loop index variable (I) // was DeclRefExpr
- chillAST_ForStmt *chillforstmt;
- chillAST_node *chilllowerbound;
- chillAST_node *chillupperbound;
- chillAST_node *chillbody; // presumably a compound statement, but not guaranteeed
+ chillAST_ForStmt *chillforstmt;
+ chillAST_node *chilllowerbound;
+ chillAST_node *chillupperbound;
+ chillAST_node *chillbody; // presumably a compound statement, but not guaranteeed
IR_CONDITION_TYPE conditionoperator;
IR_chillLoop(const IR_Code *ir, clang::ForStmt *tf);
+
IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *forstmt);
~IR_chillLoop() {}
+
IR_ScalarSymbol *index() const { return new IR_chillScalarSymbol(ir_, chillindex->getVarDecl()); }
+
omega::CG_outputRepr *lower_bound() const;
+
omega::CG_outputRepr *upper_bound() const;
+
IR_CONDITION_TYPE stop_cond() const;
+
IR_Block *body() const;
-
+
// Handle following types of increment expressions:
-
+
// Unary increment/decrement
// i += K OR i -= K
// i = i + K OR i = i - K
// where K is positive
int step_size() const { return step_size_; } // K is always an integer ???
IR_Control *clone() const;
- IR_Block *convert() ;
- virtual void dump() const;
-};
+ IR_Block *convert();
+ virtual void dump() const;
+};
-struct IR_chillBlock: public IR_Block { // ONLY ONE OF bDecl or cs_ will be nonNULL ??
+struct IR_chillBlock : public IR_Block { // ONLY ONE OF bDecl or cs_ will be nonNULL ??
private:
//StmtList bDecl_; // declarations in the block??
//clang::CompoundStmt *cs_; // will a block always have a compound statement? (no)
//StmtList *stmts; // ??
public:
-
+
// Block is a basic block?? (no, just a chunk of code )
- std::vector<chillAST_node *>statements;
- chillAST_node *chillAST; // how about for now we say if there are statements, which is presumably the top level of statements from ... somewhere, otherwise the code is in chillAST
-
- IR_chillBlock( const IR_chillBlock *CB ) { // clone existing IR_chillBlock
+ std::vector<chillAST_node *> statements;
+
+ IR_chillBlock(const IR_chillBlock *CB) { // clone existing IR_chillBlock
ir_ = CB->ir_;
- for (int i=0; i<CB->statements.size(); i++) statements.push_back( CB->statements[i] );
- chillAST = CB->chillAST;
+ for (int i = 0; i < CB->statements.size(); i++) statements.push_back(CB->statements[i]);
}
- IR_chillBlock(const IR_Code *ir, chillAST_node *ast) {
+ IR_chillBlock(const IR_Code *ir, std::vector<chillAST_node *> ast) : statements(ast) {
ir_ = ir;
- chillAST = ast;
}
- IR_chillBlock(const IR_Code *ir) { // : cs_(NULL), bDecl_(NULL) {
- chillAST = NULL;
+ IR_chillBlock(const IR_Code *ir, chillAST_node *ast = NULL) { // : cs_(NULL), bDecl_(NULL) {
ir_ = ir;
+ if (ast != NULL)
+ statements.push_back(ast);
}
-
+
~IR_chillBlock() {}
+
omega::CG_outputRepr *extract() const;
+
omega::CG_outputRepr *original() const;
+
IR_Control *clone() const;
+
//StmtList getStmtList() const;
- std::vector<chillAST_node*> getStmtList() const;
- int numstatements() { return statements.size(); } ;
- void addStatement( chillAST_node* s );
+ std::vector<chillAST_node *> getStmtList() const;
- void dump() const;
+ int numstatements() { return statements.size(); };
+
+ void addStatement(chillAST_node *s);
+
+ void dump() const;
};
-#ifdef NOTYET
+#ifdef NOTYET
struct IR_clangIf: public IR_If {
SgNode *ti_;
@@ -327,20 +362,17 @@ struct IR_clangIf: public IR_If {
IR_Block *convert();
IR_Control *clone() const;
};
-#endif
-
-
-
+#endif
class aClangCompiler {
private:
//Chill_ASTConsumer *astConsumer_;
clang::ASTContext *astContext_;
-
+
clang::DiagnosticOptions *diagnosticOptions;
clang::TextDiagnosticPrinter *pTextDiagnosticPrinter;
- llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID ;
+ llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID;
clang::DiagnosticsEngine *diagnosticsEngine;
clang::CompilerInstance *Clang;
clang::Preprocessor *preprocessor;
@@ -365,15 +397,17 @@ private:
public:
- char *SourceFileName;
- chillAST_SourceFile * entire_file_AST; // TODO move out of public
+ char *SourceFileName;
+ chillAST_SourceFile *entire_file_AST; // TODO move out of public
+
+ aClangCompiler(char *filename); // constructor
+ chillAST_FunctionDecl *findprocedurebyname(char *name); // someday, return the chill AST
+ clang::FunctionDecl *FD;
- aClangCompiler( char *filename ); // constructor
- chillAST_FunctionDecl *findprocedurebyname( char *name ); // someday, return the chill AST
- clang::FunctionDecl *FD;
//Chill_ASTConsumer *getASTConsumer() { return astConsumer_; }
- clang::ASTContext *getASTContext() { return astContext_; }
- clang::SourceManager *getASTSourceManager() { return sourceManager; };
+ clang::ASTContext *getASTContext() { return astContext_; }
+
+ clang::SourceManager *getASTSourceManager() { return sourceManager; };
};
@@ -385,32 +419,37 @@ private:
// protecting the constructor is the SINGLETON PATTERN. a global by any other name
// IR_clangCode_Global_Init();
~IR_clangCode_Global_Init(); // is this hidden, too?
- chillAST_FunctionDecl * chillFD; // the original C code
+ chillAST_FunctionDecl *chillFD; // the original C code
- clang::ASTContext *astContext_;
+ clang::ASTContext *astContext_;
clang::SourceManager *sourceManager;
public:
clang::ASTContext *getASTContext() { return astContext_; }
- clang::SourceManager *getSourceManager() { return sourceManager; };
+
+ clang::SourceManager *getSourceManager() { return sourceManager; };
+
static IR_clangCode_Global_Init *Instance(char **argv);
- static IR_clangCode_Global_Init *Instance() { return pinstance; } ;
+
+ static IR_clangCode_Global_Init *Instance() { return pinstance; };
aClangCompiler *ClangCompiler; // this is the thing we really just want one of
- void setCurrentFunction( chillAST_node *F ) { chillFD = (chillAST_FunctionDecl *)F; } ;
- chillAST_FunctionDecl *getCurrentFunction( ) { return chillFD; } ;
+ void setCurrentFunction(chillAST_node *F) { chillFD = (chillAST_FunctionDecl *) F; };
+ chillAST_FunctionDecl *getCurrentFunction() { return chillFD; };
- void setCurrentASTContext( clang::ASTContext *A ) { astContext_ = A;};
- clang::ASTContext *getCurrentASTContext() { return astContext_; } ;
- void setCurrentASTSourceManager( clang::SourceManager *S ) { sourceManager = S; } ;
- clang::SourceManager *getCurrentASTSourceManager() { return sourceManager; } ;
-};
+ void setCurrentASTContext(clang::ASTContext *A) { astContext_ = A; };
+
+ clang::ASTContext *getCurrentASTContext() { return astContext_; };
+ void setCurrentASTSourceManager(clang::SourceManager *S) { sourceManager = S; };
+
+ clang::SourceManager *getCurrentASTSourceManager() { return sourceManager; };
+};
-class IR_clangCode: public IR_Code{ // for an entire file? A single function?
+class IR_clangCode : public IR_Code { // for an entire file? A single function?
protected:
//
@@ -419,12 +458,12 @@ protected:
chillAST_node *entire_file_AST;
- chillAST_FunctionDecl * chillfunc; // the function we're currenly modifying
+ chillAST_FunctionDecl *chillfunc; // the function we're currenly modifying
std::vector<chillAST_VarDecl> entire_file_symbol_table;
// loop symbol table?? for (int i=0; ... ) ??
-
-
+
+
clang::FunctionDecl *func_; // a clang construct the function we're currenly modifying
clang::ASTContext *astContext_;
@@ -436,32 +475,48 @@ protected:
//
public:
- clang::ASTContext *getASTContext() { return astContext_; } ;
- clang::SourceManager *getASTSourceManager() { return sourceManager; } ;
+ clang::ASTContext *getASTContext() { return astContext_; };
+
+ clang::SourceManager *getASTSourceManager() { return sourceManager; };
IR_clangCode(const char *filename, const char *proc_name);
+
~IR_clangCode();
IR_ScalarSymbol *CreateScalarSymbol(const IR_Symbol *sym, int i);
+
IR_ArraySymbol *CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outputRepr *> &size, int i);
+
IR_ScalarRef *CreateScalarRef(const IR_ScalarSymbol *sym);
+
IR_ArrayRef *CreateArrayRef(const IR_ArraySymbol *sym, std::vector<omega::CG_outputRepr *> &index);
- int ArrayIndexStartAt() { return 0;} // TODO FORTRAN
-
+
+ int ArrayIndexStartAt() { return 0; } // TODO FORTRAN
+
std::vector<IR_ScalarRef *> FindScalarRef(const omega::CG_outputRepr *repr) const;
+
std::vector<IR_ArrayRef *> FindArrayRef(const omega::CG_outputRepr *repr) const;
+
std::vector<IR_Control *> FindOneLevelControlStructure(const IR_Block *block) const;
+
IR_Block *MergeNeighboringControlStructures(const std::vector<IR_Control *> &controls) const;
+
IR_Block *GetCode() const;
+
void ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr);
+
void ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr);
-
- IR_CONDITION_TYPE QueryBooleanExpOperation(const omega::CG_outputRepr*) const;
+
+ IR_CONDITION_TYPE QueryBooleanExpOperation(const omega::CG_outputRepr *) const;
+
IR_OPERATION_TYPE QueryExpOperation(const omega::CG_outputRepr *repr) const;
+
std::vector<omega::CG_outputRepr *> QueryExpOperand(const omega::CG_outputRepr *repr) const;
+
IR_Ref *Repr2Ref(const omega::CG_outputRepr *) const;
-
+
friend class IR_chillArraySymbol;
+
friend class IR_chillArrayRef;
};
diff --git a/include/ir_code.hh b/include/ir_code.hh
index e3fd8ea..813fc0d 100644
--- a/include/ir_code.hh
+++ b/include/ir_code.hh
@@ -35,7 +35,6 @@
#include <code_gen/CG_outputBuilder.h>
-
class IR_Code; // forward declaration
@@ -45,14 +44,18 @@ struct IR_Symbol {
const IR_Code *ir_;
virtual ~IR_Symbol() {/* ir_ is not the responsibility of this object */}
+
virtual int n_dim() const = 0; // IR_Symbol
virtual std::string name() const = 0;
+
virtual bool operator==(const IR_Symbol &that) const = 0;
- virtual bool operator!=(const IR_Symbol &that) const {return !(*this == that);}
+
+ virtual bool operator!=(const IR_Symbol &that) const { return !(*this == that); }
+
virtual IR_Symbol *clone() const = 0; /* shallow copy */
- virtual bool isScalar() const { return false; } // default
- virtual bool isArray() const { return false; } // default
+ virtual bool isScalar() const { return false; } // default
+ virtual bool isArray() const { return false; } // default
virtual bool isPointer() const { return false; } // default
//IR_SYMBOL_TYPE symtype; // base type: int, float, double, struct, .... typedef'd something
@@ -60,29 +63,40 @@ struct IR_Symbol {
};
-struct IR_ScalarSymbol: public IR_Symbol {
+struct IR_ScalarSymbol : public IR_Symbol {
virtual ~IR_ScalarSymbol() {}
- int n_dim() const {return 0;} // IR_ScalarSymbol
+
+ int n_dim() const { return 0; } // IR_ScalarSymbol
virtual int size() const = 0;
+
bool isScalar() const { return true; }
};
-struct IR_ArraySymbol: public IR_Symbol {
+struct IR_ArraySymbol : public IR_Symbol {
virtual ~IR_ArraySymbol() {}
+
virtual int elem_size() const = 0;
+
virtual omega::CG_outputRepr *size(int dim) const = 0;
+
virtual IR_ARRAY_LAYOUT_TYPE layout_type() const = 0;
+
virtual IR_CONSTANT_TYPE elem_type() const = 0;
+
bool isArray() const { return true; }
};
-struct IR_PointerSymbol: public IR_Symbol {
+struct IR_PointerSymbol : public IR_Symbol {
virtual ~IR_PointerSymbol() {}
+
virtual omega::CG_outputRepr *size(int dim) const = 0;
- virtual void set_size(int dim, omega::CG_outputRepr*) = 0;
+
+ virtual void set_size(int dim, omega::CG_outputRepr *) = 0;
+
virtual IR_CONSTANT_TYPE elem_type() const = 0;
+
bool isPointer() const { return true; }
};
@@ -90,41 +104,58 @@ struct IR_PointerSymbol: public IR_Symbol {
// place holder for related code in IR code.
struct IR_Ref {
const IR_Code *ir_;
-
+
virtual ~IR_Ref() {/* ir_ is not the responsibility of this object */}
- virtual int n_dim() const = 0; // IR_Ref
+
+ virtual int n_dim() const = 0; // IR_Ref
virtual bool is_write() const = 0;
+
virtual std::string name() const = 0;
+
virtual bool operator==(const IR_Ref &that) const = 0;
- virtual bool operator!=(const IR_Ref &that) const {return !(*this == that);}
+
+ 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 */
- virtual void Dump() const { fprintf(stderr, "some IR_*Ref needs to implement Dump()\n"); int *i=0; int j=i[0]; };
+ virtual void Dump() const {
+ fprintf(stderr, "some IR_*Ref needs to implement Dump()\n");
+ int *i = 0;
+ int j = i[0];
+ };
};
-struct IR_ConstantRef: public IR_Ref {
+struct IR_ConstantRef : public IR_Ref {
IR_CONSTANT_TYPE type_;
virtual ~IR_ConstantRef() {}
- int n_dim() const {return 0;} // IR_ConstantRef
- bool is_write() const {return false;}
- std::string name() const {return std::string();}
- virtual bool is_integer() const {return type_ == IR_CONSTANT_INT;}
+
+ int n_dim() const { return 0; } // IR_ConstantRef
+ bool is_write() const { return false; }
+
+ std::string name() const { return std::string(); }
+
+ virtual bool is_integer() const { return type_ == IR_CONSTANT_INT; }
+
virtual omega::coef_t integer() const = 0;
};
-
-struct IR_ScalarRef: public IR_Ref {
+
+struct IR_ScalarRef : public IR_Ref {
virtual ~IR_ScalarRef() {}
- int n_dim() const {return 0;} // IR_ScalarRef
+
+ int n_dim() const { return 0; } // IR_ScalarRef
virtual IR_ScalarSymbol *symbol() const = 0;
+
std::string name() const {
IR_ScalarSymbol *sym = symbol(); // really inefficient. MAKE a symbol, just to get a name
std::string s = sym->name();
delete sym;
return s;
}
+
virtual int size() const {
IR_ScalarSymbol *sym = symbol();
int s = sym->size();
@@ -134,16 +165,20 @@ struct IR_ScalarRef: public IR_Ref {
};
-struct IR_ArrayRef: public IR_Ref {
+struct IR_ArrayRef : public IR_Ref {
virtual ~IR_ArrayRef() {}
- int n_dim() const { // IR_ArrayRef returns the size of the array
+
+ int n_dim() const { // IR_ArrayRef returns the size of the array
IR_ArraySymbol *sym = symbol();
int n = sym->n_dim();
// ?? delete sym;
return n;
}
+
virtual omega::CG_outputRepr *index(int dim) const = 0;
+
virtual IR_ArraySymbol *symbol() const = 0;
+
virtual std::string name() const {
// makes (constructs!) a symbol, just to copy a string!
IR_ArraySymbol *sym = symbol(); // TODO exceedingly wasteful
@@ -151,26 +186,30 @@ struct IR_ArrayRef: public IR_Ref {
// ?? delete sym; (goes out of scope, so deletes itself)
return s; // s ALSO goes out of scope but perhaps the info is copied at the other end
}
+
virtual int elem_size() const {
IR_ArraySymbol *sym = symbol();
int s = sym->elem_size();
// ?? delete sym;
return s;
}
+
virtual IR_ARRAY_LAYOUT_TYPE layout_type() const {
IR_ArraySymbol *sym = symbol();
IR_ARRAY_LAYOUT_TYPE t = sym->layout_type();
// ?? delete sym;
return t;
}
+
virtual void Dump() const { fprintf(stderr, "IR_ArrayRef needs to implement Dump()\n"); };
};
-struct IR_PointerArrayRef: public IR_Ref {
+struct IR_PointerArrayRef : public IR_Ref {
const IR_Code *ir_;
virtual ~IR_PointerArrayRef() {}
+
int n_dim() const { // IR_PointerArrayRef returns size of the ... symbol?
IR_PointerSymbol *sym = symbol();
int n = sym->n_dim();
@@ -178,8 +217,11 @@ struct IR_PointerArrayRef: public IR_Ref {
//delete sym;
return n;
}
+
virtual omega::CG_outputRepr *index(int dim) const = 0;
+
virtual IR_PointerSymbol *symbol() const = 0;
+
std::string name() const {
IR_PointerSymbol *sym = symbol();
std::string s = sym->name();
@@ -205,44 +247,61 @@ struct IR_Control {
const IR_Code *ir_; // hate this
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 */
};
-struct IR_Loop: public IR_Control {
+struct IR_Loop : public IR_Control {
virtual ~IR_Loop() {}
+
virtual IR_ScalarSymbol *index() const = 0;
+
virtual omega::CG_outputRepr *lower_bound() const = 0;
+
virtual omega::CG_outputRepr *upper_bound() const = 0;
+
virtual IR_CONDITION_TYPE stop_cond() const = 0;
+
virtual IR_Block *body() const = 0;
+
virtual int step_size() const = 0;
+
IR_CONTROL_TYPE type() const { return IR_CONTROL_LOOP; }
};
-struct IR_Block: public IR_Control {
+struct IR_Block : public IR_Control {
virtual ~IR_Block() {}
+
virtual omega::CG_outputRepr *extract() const = 0;
- IR_Block *convert() {return this;}
+
+ IR_Block *convert() { return this; }
+
IR_CONTROL_TYPE type() const { return IR_CONTROL_BLOCK; }
+
virtual omega::CG_outputRepr *original() const = 0;
};
-struct IR_If: public IR_Control {
+struct IR_If : public IR_Control {
virtual ~IR_If() {}
+
virtual omega::CG_outputRepr *condition() const = 0;
+
virtual IR_Block *then_body() const = 0;
+
virtual IR_Block *else_body() const = 0;
+
IR_CONTROL_TYPE type() const { return IR_CONTROL_IF; }
};
-
-struct IR_While: public IR_Control {
+struct IR_While : public IR_Control {
// NOT IMPLEMENTED
};
@@ -263,32 +322,52 @@ protected:
public:
int getPointerCounter() { return ir_pointer_counter; }
- int getArrayCounter() { return ir_array_counter; }
+
+ int getArrayCounter() { return ir_array_counter; }
// TODO can't get the initialize of counters to work !!
- int getAndIncrementPointerCounter() { if (ir_pointer_counter == 0) ir_pointer_counter= 1; ir_pointer_counter++; return ir_pointer_counter-1; }
- int getAndIncrementArrayCounter() { if (ir_array_counter == 0) ir_array_counter= 1; ir_array_counter += 1; return ir_array_counter-1; }
+ int getAndIncrementPointerCounter() {
+ if (ir_pointer_counter == 0) ir_pointer_counter = 1;
+ ir_pointer_counter++;
+ return ir_pointer_counter - 1;
+ }
+
+ int getAndIncrementArrayCounter() {
+ if (ir_array_counter == 0) ir_array_counter = 1;
+ ir_array_counter += 1;
+ return ir_array_counter - 1;
+ }
// if all flavors of ir_code use chillAST internally ...
- chillAST_FunctionDecl * func_defn; // the function we're modifying
- chillAST_FunctionDecl *GetChillFuncDefinition() { return func_defn; };
+ chillAST_FunctionDecl *func_defn; // the function we're modifying
+ chillAST_FunctionDecl *GetChillFuncDefinition() { return func_defn; };
- 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 */
-
- omega::CG_outputRepr* init_code(){ return init_code_; }
+ 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 */
+
+ omega::CG_outputRepr *init_code() { return init_code_; }
// 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_ScalarSymbol *CreateScalarSymbol(IR_CONSTANT_TYPE type, int memory_type, std::string name="" ) {
+
+ virtual IR_ScalarSymbol *CreateScalarSymbol(IR_CONSTANT_TYPE type, int memory_type, std::string name = "") {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual IR_ArraySymbol *CreateArraySymbol(const IR_Symbol *sym,
- std::vector<omega::CG_outputRepr *> &size,
+ virtual IR_ArraySymbol *CreateArraySymbol(const IR_Symbol *sym,
+ std::vector<omega::CG_outputRepr *> &size,
int memory_type) = 0;
+
virtual IR_ArraySymbol *CreateArraySymbol(omega::CG_outputRepr *type,
std::vector<omega::CG_outputRepr *> &size_repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
@@ -300,9 +379,10 @@ public:
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
+
virtual IR_PointerSymbol *CreatePointerSymbol(const IR_CONSTANT_TYPE type,
- std::vector<omega::CG_outputRepr *> &size_repr,
- std::string name="") {
+ std::vector<omega::CG_outputRepr *> &size_repr,
+ std::string name = "") {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
@@ -314,56 +394,68 @@ public:
}
virtual IR_ScalarRef *CreateScalarRef(const IR_ScalarSymbol *sym) = 0;
+
virtual IR_ArrayRef *CreateArrayRef(const IR_ArraySymbol *sym, std::vector<omega::CG_outputRepr *> &index) = 0;
- virtual omega::CG_outputRepr* CreateArrayRefRepr(const IR_ArraySymbol *sym,
- std::vector<omega::CG_outputRepr *> &index) {
+ virtual omega::CG_outputRepr *CreateArrayRefRepr(const IR_ArraySymbol *sym,
+ std::vector<omega::CG_outputRepr *> &index) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
- return NULL;
+ return NULL;
}
- virtual IR_PointerArrayRef *CreatePointerArrayRef( IR_PointerSymbol *sym,
- std::vector<omega::CG_outputRepr *> &index) {
+ virtual IR_PointerArrayRef *CreatePointerArrayRef(IR_PointerSymbol *sym,
+ std::vector<omega::CG_outputRepr *> &index) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual int ArrayIndexStartAt() {return 0;}
- virtual void CreateDefineMacro(std::string s,std::string args, omega::CG_outputRepr *repr) {
+ virtual int ArrayIndexStartAt() { return 0; }
+
+ virtual void CreateDefineMacro(std::string s, std::string args, omega::CG_outputRepr *repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
}
- virtual void CreateDefineMacro(std::string s,std::string args, std::string repr) {
+
+ virtual void CreateDefineMacro(std::string s, std::string args, std::string repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
}
- virtual void CreateDefineMacro(std::string s, std::vector<std::string> args,omega::CG_outputRepr *repr) {}; // TODO make pure virtual
- virtual omega::CG_outputRepr *CreateArrayType(IR_CONSTANT_TYPE type, omega::CG_outputRepr* size){
+ virtual void CreateDefineMacro(std::string s, std::vector<std::string> args,
+ omega::CG_outputRepr *repr) {}; // TODO make pure virtual
+
+ virtual omega::CG_outputRepr *CreateArrayType(IR_CONSTANT_TYPE type, omega::CG_outputRepr *size) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual omega::CG_outputRepr *CreatePointerType(IR_CONSTANT_TYPE type){
+
+ virtual omega::CG_outputRepr *CreatePointerType(IR_CONSTANT_TYPE type) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual omega::CG_outputRepr *CreatePointerType(omega::CG_outputRepr *type){
+
+ virtual omega::CG_outputRepr *CreatePointerType(omega::CG_outputRepr *type) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual omega::CG_outputRepr *CreateScalarType(IR_CONSTANT_TYPE type){
+
+ virtual omega::CG_outputRepr *CreateScalarType(IR_CONSTANT_TYPE type) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
+
// 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_PointerArrayRef *> FindPointerArrayRef(const omega::CG_outputRepr *repr) const{
+
+ virtual std::vector<IR_PointerArrayRef *> FindPointerArrayRef(const omega::CG_outputRepr *repr) const {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return std::vector<IR_PointerArrayRef *>();
}
+
virtual std::vector<IR_ScalarRef *> FindScalarRef(const omega::CG_outputRepr *repr) const = 0;
- virtual bool parent_is_array(IR_ArrayRef *a){
+
+ virtual bool parent_is_array(IR_ArrayRef *a) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return false;
}
@@ -375,70 +467,86 @@ public:
// 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;
+
virtual IR_Control *GetCode(omega::CG_outputRepr *code) const {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
+
virtual void ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) = 0;
+
virtual void ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr) = 0;
-
+
virtual IR_OPERATION_TYPE QueryExpOperation(const omega::CG_outputRepr *repr) const = 0;
+
virtual IR_CONDITION_TYPE QueryBooleanExpOperation(const omega::CG_outputRepr *repr) const = 0;
+
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;
// Manu:: Added functions required for reduction operation
- // virtual omega::CG_outputRepr * FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B) = 0;
- virtual bool FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B){
+ // virtual omega::CG_outputRepr * FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B) = 0;
+ virtual bool FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual void printStmt(const omega::CG_outputRepr *repr){
+
+ virtual void printStmt(const omega::CG_outputRepr *repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
}
- virtual int getStmtType(const omega::CG_outputRepr *repr){
+
+ virtual int getStmtType(const omega::CG_outputRepr *repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return 0;
}
- virtual IR_OPERATION_TYPE getReductionOp(const omega::CG_outputRepr *repr){
+
+ virtual IR_OPERATION_TYPE getReductionOp(const omega::CG_outputRepr *repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return IR_OP_MINUS;
}
- virtual IR_Control * FromForStmt(const omega::CG_outputRepr *repr){
+
+ virtual IR_Control *FromForStmt(const omega::CG_outputRepr *repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
// Manu:: Added functions for scalar expansion
- virtual IR_ArraySymbol *CreateArraySymbol(omega::CG_outputRepr *size, const IR_Symbol *sym){
+ virtual IR_ArraySymbol *CreateArraySymbol(omega::CG_outputRepr *size, const IR_Symbol *sym) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual bool ReplaceRHSExpression(omega::CG_outputRepr *code, IR_Ref *ref){
+
+ virtual bool ReplaceRHSExpression(omega::CG_outputRepr *code, IR_Ref *ref) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual omega::CG_outputRepr * GetRHSExpression(omega::CG_outputRepr *code){
+
+ virtual omega::CG_outputRepr *GetRHSExpression(omega::CG_outputRepr *code) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual omega::CG_outputRepr * GetLHSExpression(omega::CG_outputRepr *code){
+
+ virtual omega::CG_outputRepr *GetLHSExpression(omega::CG_outputRepr *code) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
+
virtual omega::CG_outputRepr *CreateMalloc(const IR_CONSTANT_TYPE type, std::string lhs,
- omega::CG_outputRepr * size_repr){
+ omega::CG_outputRepr *size_repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
+
virtual omega::CG_outputRepr *CreateMalloc(omega::CG_outputRepr *type, std::string variable,
- omega::CG_outputRepr * size_repr){
+ omega::CG_outputRepr *size_repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual omega::CG_outputRepr *CreateFree(omega::CG_outputRepr * exp){
+
+ virtual omega::CG_outputRepr *CreateFree(omega::CG_outputRepr *exp) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
@@ -448,7 +556,7 @@ public:
// CC Omega code builder interface here
//---------------------------------------------------------------------------
- omega::CG_outputBuilder *builder() const { return ocg_;}
+ omega::CG_outputBuilder *builder() const { return ocg_; }
};
diff --git a/include/ir_enums.hh b/include/ir_enums.hh
index 742dbe8..6c652e5 100644
--- a/include/ir_enums.hh
+++ b/include/ir_enums.hh
@@ -21,4 +21,5 @@ enum IR_CONDITION_TYPE {IR_COND_LT, IR_COND_LE,
enum IR_ARRAY_LAYOUT_TYPE {IR_ARRAY_LAYOUT_ROW_MAJOR,
IR_ARRAY_LAYOUT_COLUMN_MAJOR,
IR_ARRAY_LAYOUT_SPACE_FILLING};
+
#endif
diff --git a/include/irtools.hh b/include/irtools.hh
index a743fa5..c4a78ed 100644
--- a/include/irtools.hh
+++ b/include/irtools.hh
@@ -6,6 +6,7 @@
#include <code_gen/CG_outputRepr.h>
#include "ir_code.hh"
#include "dep.hh"
+
#define DEP_DEBUG 0
// IR tree is used to initialize a loop. For a loop node, payload is
@@ -18,7 +19,7 @@ struct ir_tree_node {
ir_tree_node *parent;
std::vector<ir_tree_node *> children;
int payload;
-
+
~ir_tree_node() {
for (int i = 0; i < children.size(); i++)
delete children[i];
@@ -28,19 +29,22 @@ struct ir_tree_node {
std::vector<ir_tree_node *> build_ir_tree(IR_Control *control,
ir_tree_node *parent = NULL);
+
std::vector<ir_tree_node *> extract_ir_stmts(
- const std::vector<ir_tree_node *> &ir_tree);
+ const std::vector<ir_tree_node *> &ir_tree);
+
bool is_dependence_valid(ir_tree_node *src_node, ir_tree_node *dst_node,
const DependenceVector &dv, bool before);
+
std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > test_data_dependences(
- IR_Code *ir, const omega::CG_outputRepr *repr1,
- const omega::Relation &IS1, const omega::CG_outputRepr *repr2,
- const omega::Relation &IS2, std::vector<omega::Free_Var_Decl*> &freevar,
- std::vector<std::string> index, int i, int j,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols_stringrepr);
+ IR_Code *ir, const omega::CG_outputRepr *repr1,
+ const omega::Relation &IS1, const omega::CG_outputRepr *repr2,
+ const omega::Relation &IS2, std::vector<omega::Free_Var_Decl *> &freevar,
+ std::vector<std::string> index, int i, int j,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr);
-std::vector<omega::CG_outputRepr *> collect_loop_inductive_and_conditionals(ir_tree_node * stmt_node);
+std::vector<omega::CG_outputRepr *> collect_loop_inductive_and_conditionals(ir_tree_node *stmt_node);
// Manu
typedef std::map<int, std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > > tempResultMap;
@@ -48,9 +52,17 @@ typedef std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> >
// Manu:: this function is required for reduction operation
bool from_same_statement(IR_Code *ir, IR_ArrayRef *a, IR_ArrayRef *b);
+
int stmtType(IR_Code *ir, const omega::CG_outputRepr *repr);
+
IR_OPERATION_TYPE getReductionOperator(IR_Code *ir, const omega::CG_outputRepr *repr);
-void mapRefstoStatements(IR_Code *ir,std::vector<IR_ArrayRef *> access, int ref2Stmt[], std::map<int,std::set<int> >& rMap, std::set<int>& tnrStmts, std::set<int>& nrStmts);
-void checkReductionDependence(int i, int j, int nestLeveli, omega::coef_t lbound[], omega::coef_t ubound[], int ref2Stmt[], std::map<int,std::set<int> >& rMap, DVPair& dv, tempResultMap& trMap, std::set<int> nrStmts );
+
+void
+mapRefstoStatements(IR_Code *ir, std::vector<IR_ArrayRef *> access, int ref2Stmt[], std::map<int, std::set<int> > &rMap,
+ std::set<int> &tnrStmts, std::set<int> &nrStmts);
+
+void
+checkReductionDependence(int i, int j, int nestLeveli, omega::coef_t lbound[], omega::coef_t ubound[], int ref2Stmt[],
+ std::map<int, std::set<int> > &rMap, DVPair &dv, tempResultMap &trMap, std::set<int> nrStmts);
#endif
diff --git a/include/loop.hh b/include/loop.hh
index 3909e6c..72295b6 100644
--- a/include/loop.hh
+++ b/include/loop.hh
@@ -117,8 +117,8 @@ public:
Loop(const IR_Control *control);
~Loop();
- omega::CG_outputRepr *getCode(int effort = 3) const; // TODO was 1
- //chillAST_node* LoopCuda::getCode(int effort, std::set<int> stmts) const;
+ omega::CG_outputRepr *getCode(int effort = 3) const; // TODO was 1
+ //chillAST_node* getCode(int effort, std::set<int> stmts) const;
void stencilASEPadded(int stmt_num);
diff --git a/include/omegatools.hh b/include/omegatools.hh
index 2f56971..8f06ebc 100644
--- a/include/omegatools.hh
+++ b/include/omegatools.hh
@@ -8,61 +8,87 @@
std::string tmp_e();
-void exp2formula(IR_Code *ir,
- omega::Relation &r,
+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,
+ omega::CG_outputRepr *repr,
+ omega::Variable_ID lhs,
char side,
- IR_CONDITION_TYPE rel,
- bool destroy,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols_stringrepr);
+ IR_CONDITION_TYPE rel,
+ bool destroy,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr);
-omega::Relation arrays2relation(IR_Code *ir, std::vector<omega::Free_Var_Decl*> &freevars,
+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,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols_stringrepr);
+ const IR_ArrayRef *ref_dst, const omega::Relation &IS_r,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr);
std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relation2dependences(
- const IR_ArrayRef *ref_src, const IR_ArrayRef *ref_dst, const omega::Relation &r);
+ const IR_ArrayRef *ref_src, const IR_ArrayRef *ref_dst, const omega::Relation &r);
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,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols_stringrepr);
+ omega::CG_outputRepr *repr, bool destroy,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr);
bool is_single_iteration(const omega::Relation &r, int dim);
+
void assign_const(omega::Relation &r, int dim, int val);
+
int get_const(const omega::Relation &r, int dim, omega::Var_Kind type);
+
omega::Variable_ID find_index(omega::Relation &r, const std::string &s, char side);
+
omega::Relation permute_relation(const std::vector<int> &pi);
+
omega::Relation get_loop_bound(const omega::Relation &r, int dim);
+
bool is_single_loop_iteration(const omega::Relation &r, int level, const omega::Relation &known);
+
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);
+
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 *>());
omega::Relation adjust_loop_bound(const omega::Relation &r, int level, int adjustment);
+
bool lowerBoundIsZero(const omega::Relation &bound, int dim);
+
omega::Relation and_with_relation_and_replace_var(const omega::Relation &R, omega::Variable_ID v1,
omega::Relation &g);
+
omega::Relation replicate_IS_and_add_at_pos(const omega::Relation &R, int level, omega::Relation &bound);
-omega::Relation replicate_IS_and_add_bound(const omega::Relation &R, int level, omega::Relation &bound) ;
-omega::CG_outputRepr * construct_int_floor(omega::CG_outputBuilder * ocg, const omega::Relation &R, const omega::GEQ_Handle &h, omega::Variable_ID v,const std::vector<std::pair<omega::CG_outputRepr *, int> > &assigned_on_the_fly,
- std::map<std::string, std::vector<omega::CG_outputRepr *> > unin);
+omega::Relation replicate_IS_and_add_bound(const omega::Relation &R, int level, omega::Relation &bound);
+
+omega::CG_outputRepr *
+construct_int_floor(omega::CG_outputBuilder *ocg, const omega::Relation &R, const omega::GEQ_Handle &h,
+ omega::Variable_ID v,
+ const std::vector<std::pair<omega::CG_outputRepr *, int> > &assigned_on_the_fly,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > unin);
+
//omega::CG_outputRepr * modified_output_subs_repr(omega::CG_outputBuilder * ocg, const omega::Relation &R, const omega::EQ_Handle &h, omega::Variable_ID v,const std::vector<std::pair<omega::CG_outputRepr *, int> > &assigned_on_the_fly,
// std::map<std::string, std::vector<omega::CG_outputRepr *> > unin);
-std::pair<omega::Relation, bool> replace_set_var_as_existential(const omega::Relation &R,int pos, std::vector<omega::Relation> &bound);
-omega::Relation replace_set_var_as_Global(const omega::Relation &R,int pos,std::vector<omega::Relation> &bound);
-omega::Relation replace_set_var_as_another_set_var(const omega::Relation &old_relation, const omega::Relation &new_relation, int old_pos, int new_pos);
+std::pair<omega::Relation, bool>
+replace_set_var_as_existential(const omega::Relation &R, int pos, std::vector<omega::Relation> &bound);
+
+omega::Relation replace_set_var_as_Global(const omega::Relation &R, int pos, std::vector<omega::Relation> &bound);
+
+omega::Relation
+replace_set_var_as_another_set_var(const omega::Relation &old_relation, const omega::Relation &new_relation,
+ int old_pos, int new_pos);
+
omega::Relation extract_upper_bound(const omega::Relation &R, omega::Variable_ID v1);
// void adjust_loop_bound(Relation &r, int dim, int adjustment);
@@ -72,7 +98,9 @@ omega::Relation extract_upper_bound(const omega::Relation &R, omega::Variable_ID
// coef_t mod(const Relation &r, Variable_ID v, int dividend);
-enum LexicalOrderType {LEX_MATCH, LEX_BEFORE, LEX_AFTER, LEX_UNKNOWN};
+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) {
diff --git a/include/stencil.hh b/include/stencil.hh
index 799e3b9..15bd94f 100644
--- a/include/stencil.hh
+++ b/include/stencil.hh
@@ -23,27 +23,28 @@ class stencilInfo {
public:
uint dimensions; // number of dimensions in the stencil
uint elements; // total number of elements in the stencil
- chillAST_VarDecl* srcArrayVariable; // the variable of the source array
- chillAST_VarDecl* dstArrayVariable; // the variable of the destination array
+ chillAST_VarDecl *srcArrayVariable; // the variable of the source array
+ chillAST_VarDecl *dstArrayVariable; // the variable of the destination array
int minOffset[3]; // the minimum offset for each dimension NOTE hardcoded to 3 dimensions TODO
int maxOffset[3]; // the maximum offset for each dimension
- chillAST_VarDecl* indexVariables[3]; // the variable used for indexing each dimension
+ chillAST_VarDecl *indexVariables[3]; // the variable used for indexing each dimension
- std::vector< std::vector< int > > offsets; // k+1, j-47, i+0 etc
+ std::vector<std::vector<int> > offsets; // k+1, j-47, i+0 etc
-
- std::vector< std::vector<chillAST_node*> > coefficients; // the coefficients of for each element, NOT IN ANY SET ORDER
- chillAST_node* find_coefficient( int i, int j, int k ) ; // hardcoded 3 dimensions TODO
+
+ std::vector<std::vector<chillAST_node *> > coefficients; // the coefficients of for each element, NOT IN ANY SET ORDER
+ chillAST_node *find_coefficient(int i, int j, int k); // hardcoded 3 dimensions TODO
// constructors
- stencilInfo();
- stencilInfo( chillAST_node *topstatement ) ;
+ stencilInfo();
+
+ stencilInfo(chillAST_node *topstatement);
- void walktree( chillAST_node *node, std::vector< chillAST_node * > &coeffstohere );
+ void walktree(chillAST_node *node, std::vector<chillAST_node *> &coeffstohere);
- void print( FILE *fp=stdout );
+ void print(FILE *fp = stdout);
int radius();