summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2016-09-22 15:12:54 -0600
committerTuowen Zhao <ztuowen@gmail.com>2016-09-22 15:12:54 -0600
commit1929ac1a60615ee86779790c46e04e53de75462f (patch)
tree35566b4f04184a9aed98fdc9dda74507075a7890
parentf27e01a039195c379fd6716c4870858789941365 (diff)
downloadchill-1929ac1a60615ee86779790c46e04e53de75462f.tar.gz
chill-1929ac1a60615ee86779790c46e04e53de75462f.tar.bz2
chill-1929ac1a60615ee86779790c46e04e53de75462f.zip
add CHILL_DEBUG_PRINT & CHILL_DEBUG_BEGIN & CHILL_DEBUG_END
-rw-r--r--CMakeLists.txt14
-rw-r--r--include/chillAST.h12
-rw-r--r--include/chillAST/chillAST_def.hh161
-rw-r--r--include/chillAST/chillAST_node.hh504
-rw-r--r--include/chillAST/chillASTs.hh (renamed from include/chill_ast.hh)711
-rw-r--r--include/chilldebug.h21
-rw-r--r--include/dep.hh4
-rwxr-xr-xinclude/ir_clang.hh11
-rw-r--r--include/ir_code.hh2
-rw-r--r--include/irtools.hh1
-rw-r--r--include/stencil.hh2
-rwxr-xr-xlib/chillcg/include/code_gen/CG_chillRepr.h2
-rw-r--r--src/chillASTs.cc (renamed from src/chill_ast.cc)39
-rwxr-xr-xsrc/ir_clang.cc168
-rw-r--r--src/irtools.cc78
-rw-r--r--src/omegatools.cc2
-rw-r--r--src/transformations/loop.cc (renamed from src/loop.cc)86
-rw-r--r--src/transformations/loop_basic.cc (renamed from src/loop_basic.cc)0
-rw-r--r--src/transformations/loop_datacopy.cc (renamed from src/loop_datacopy.cc)0
-rw-r--r--src/transformations/loop_extra.cc (renamed from src/loop_extra.cc)0
-rw-r--r--src/transformations/loop_tile.cc (renamed from src/loop_tile.cc)0
-rw-r--r--src/transformations/loop_unroll.cc (renamed from src/loop_unroll.cc)0
22 files changed, 897 insertions, 921 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2c6e2dd..c668668 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,18 +15,18 @@ set(CORE_LIBS
set(CORE_SRC
src/dep.cc
src/irtools.cc
- src/loop.cc
- src/loop_basic.cc
- src/loop_datacopy.cc
- src/loop_extra.cc
- src/loop_tile.cc
- src/loop_unroll.cc
+ src/transformations/loop.cc
+ src/transformations/loop_basic.cc
+ src/transformations/loop_datacopy.cc
+ src/transformations/loop_extra.cc
+ src/transformations/loop_tile.cc
+ src/transformations/loop_unroll.cc
src/omegatools.cc
)
set(IR_CHILL_SRC
src/ir_clang.cc
- src/chill_ast.cc
+ src/chillASTs.cc
)
set(PYTHON_SRC
diff --git a/include/chillAST.h b/include/chillAST.h
new file mode 100644
index 0000000..dba4ed2
--- /dev/null
+++ b/include/chillAST.h
@@ -0,0 +1,12 @@
+//
+// Created by ztuowen on 9/22/16.
+//
+
+#ifndef CHILL_CHILLAST_H
+#define CHILL_CHILLAST_H
+
+#include "chillAST/chillAST_def.hh"
+#include "chillAST/chillAST_node.hh"
+#include "chillAST/chillASTs.hh"
+
+#endif //CHILL_CHILLAST_H
diff --git a/include/chillAST/chillAST_def.hh b/include/chillAST/chillAST_def.hh
new file mode 100644
index 0000000..318b51b
--- /dev/null
+++ b/include/chillAST/chillAST_def.hh
@@ -0,0 +1,161 @@
+
+
+#ifndef _CHILLAST_DEF_H_
+#define _CHILLAST_DEF_H_
+
+
+#define CHILL_INDENT_AMOUNT 2
+
+#include <iostream>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <vector> // std::vector
+
+#include <ir_enums.hh> // for IR_CONDITION_*
+
+#define CHILLAST_NODETYPE_FORSTMT CHILLAST_NODETYPE_LOOP
+#define CHILLAST_NODETYPE_TRANSLATIONUNIT CHILLAST_NODETYPE_SOURCEFILE
+
+enum CHILL_ASTNODE_TYPE {
+ CHILLAST_NODETYPE_UNKNOWN=0,
+ CHILLAST_NODETYPE_SOURCEFILE,
+ CHILLAST_NODETYPE_TYPEDEFDECL,
+ CHILLAST_NODETYPE_VARDECL,
+ // CHILLAST_NODETYPE_PARMVARDECL, not used any more
+ CHILLAST_NODETYPE_FUNCTIONDECL,
+ CHILLAST_NODETYPE_RECORDDECL, // struct or union (or class)
+ CHILLAST_NODETYPE_MACRODEFINITION,
+ CHILLAST_NODETYPE_COMPOUNDSTMT,
+ CHILLAST_NODETYPE_LOOP, // AKA ForStmt
+ CHILLAST_NODETYPE_TERNARYOPERATOR,
+ CHILLAST_NODETYPE_BINARYOPERATOR,
+ CHILLAST_NODETYPE_UNARYOPERATOR,
+ CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR,
+ CHILLAST_NODETYPE_MEMBEREXPR, // structs/unions
+ CHILLAST_NODETYPE_DECLREFEXPR,
+ CHILLAST_NODETYPE_INTEGERLITERAL,
+ CHILLAST_NODETYPE_FLOATINGLITERAL,
+ CHILLAST_NODETYPE_IMPLICITCASTEXPR,
+ CHILLAST_NODETYPE_RETURNSTMT,
+ CHILLAST_NODETYPE_CALLEXPR,
+ CHILLAST_NODETYPE_DECLSTMT,
+ CHILLAST_NODETYPE_PARENEXPR,
+ CHILLAST_NODETYPE_CSTYLECASTEXPR,
+ CHILLAST_NODETYPE_CSTYLEADDRESSOF,
+ CHILLAST_NODETYPE_IFSTMT,
+ CHILLAST_NODETYPE_SIZEOF,
+ CHILLAST_NODETYPE_MALLOC,
+ CHILLAST_NODETYPE_FREE,
+ CHILLAST_NODETYPE_PREPROCESSING, // comments, #define, #include, whatever else works
+ CHILLAST_NODETYPE_NOOP, // NO OP
+ // CUDA specific
+ CHILLAST_NODETYPE_CUDAMALLOC,
+ CHILLAST_NODETYPE_CUDAFREE,
+ CHILLAST_NODETYPE_CUDAMEMCPY,
+ CHILLAST_NODETYPE_CUDAKERNELCALL,
+ CHILLAST_NODETYPE_CUDASYNCTHREADS,
+ CHILLAST_NODETYPE_NULL // explicit non-statement
+ // TODO
+
+} ;
+
+enum CHILL_FUNCTION_TYPE {
+ CHILL_FUNCTION_CPU = 0,
+ CHILL_FUNCTION_GPU
+};
+
+enum CHILL_MEMBER_EXP_TYPE {
+ CHILL_MEMBER_EXP_DOT = 0,
+ CHILL_MEMBER_EXP_ARROW
+};
+
+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,
+ CHILL_PREPROCESSING_LINEBEFORE, // previous line
+ CHILL_PREPROCESSING_LINEAFTER, // next line
+ CHILL_PREPROCESSING_TOTHERIGHT, // for this kind of comment, on same line
+ 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!
+
+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
+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_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
+
+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
+
+
+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_FunctionDecl *findFunctionDecl( chillAST_node *node, const char *procname);
+
+#endif
+
diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh
new file mode 100644
index 0000000..70660c5
--- /dev/null
+++ b/include/chillAST/chillAST_node.hh
@@ -0,0 +1,504 @@
+
+
+#ifndef _CHILLAST_NODE_H_
+#define _CHILLAST_NODE_H_
+
+#include "chillAST_def.hh"
+
+// an actual chill ast.
+// 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:
+
+ static int chill_scalar_counter; // for manufactured scalars
+ 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
+ virtual chillAST_SymbolTable *getSymbolTable() { return NULL; } // most nodes do NOT have a symbol table
+
+ virtual chillAST_VarDecl *findVariableNamed( 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;
+ 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; } ;
+
+ char *metacomment; // for compiler internals, formerly a comment
+ void setMetaComment( char *c ) { metacomment = strdup(c); };
+
+ std::vector<chillAST_Preprocessing*> preprocessinginfo;
+
+ virtual void addChild( chillAST_node* c) {
+ //if (c->isFunctionDecl()) fprintf(stderr, "addchild FunctionDecl\n");
+ c->parent = this;
+ // check to see if it's already there
+ for (int i=0; i<children.size(); i++) {
+ if (c == children[i]) {
+ //fprintf(stderr, "addchild ALREADY THERE\n");
+ return; // already there
+ }
+ }
+ children.push_back(c);
+ } ; // not usually useful
+
+ 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 );
+ };
+
+ virtual void removeChild(int i) {
+ children.erase( children.begin()+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) {
+ children[i] = newchild;
+ 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
+ };
+
+ 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 );
+ }
+ }
+
+ 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 const char* getUnderlyingType() {
+ fprintf(stderr,"(%s) forgot to implement getUnderlyingType()\n", Chill_AST_Node_Names[asttype]);
+ dump();
+ print();
+ fprintf(stderr, "\n\n");
+ segfault();
+ };
+
+ virtual chillAST_VarDecl* getUnderlyingVarDecl() {
+ fprintf(stderr,"(%s) forgot to implement getUnderlyingVarDecl()\n", Chill_AST_Node_Names[asttype]);
+ dump();
+ print();
+ fprintf(stderr, "\n\n");
+ segfault();
+ };
+
+
+ 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]);
+ dump();
+ print();
+ fprintf(stderr, "\n\n");
+ segfault();
+ };
+
+ virtual void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
+ fprintf(stderr,"(%s) forgot to implement gatherArrayRefs()\n" ,Chill_AST_Node_Names[asttype]);
+ dump();
+ print();
+ fprintf(stderr, "\n\n");
+ };
+
+ // 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]);
+ dump();
+ print();
+ fprintf(stderr, "\n\n");
+ };
+
+ 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
+
+ // 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);
+
+
+ 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 );
+ }
+
+
+ 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
+ if (!parent) return NULL;
+ 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
+ if (!parent) return NULL;
+ 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
+ }
+
+ // 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 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 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 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 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]);
+ }
+
+
+ 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;
+ }
+
+
+ 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* clone() { // makes a deep COPY (?)
+ fprintf(stderr,"(%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);
+ 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);
+ fprintf(fp, "\n");
+ 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
+ fflush(stdout);
+ // chillindent(indent, fp); TODO
+ fprintf(stderr,"(%s) forgot to implement stringRep()\n" ,Chill_AST_Node_Names[asttype]);
+ segfault();
+ }
+
+
+ virtual void printonly( int indent=0, FILE *fp = stderr ) { print( indent, fp); };
+
+ //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();
+ //fprintf(stderr, "get_top_level_loops of a %s with %d children\n", getTypeString(), n);
+ 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])) );
+ }
+ }
+ //fprintf(stderr, "found %d top level loops\n", loops.size());
+ }
+
+
+ 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;
+ }
+ }
+ }
+
+
+
+ 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++) {
+ //fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString());
+ 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();
+ //fprintf(stderr, "find_deepest_loops of a %s with %d children\n", getTypeString(), n);
+ 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()) {
+ deepest = subloops;
+ }
+ }
+
+ // append deepest we see at this level to loops
+ 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; } ;
+
+ 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);
+ if (parent != NULL) return parent->findDatatype(t); // most nodes do this
+ return NULL;
+ }
+
+
+ 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
+ }
+
+ 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;}
+
+ if (parent) parent->walk_parents();
+ else fprintf(stderr, "UHOH, %s has no parent??\n", getTypeString());
+ 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]);
+ exit(-1);
+ }
+ 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);
+ print();
+ 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);
+ print();
+ fprintf(stderr, "\n\n"); }
+
+ void printPreprocBEFORE( int indent, FILE *fp );
+ void printPreprocAFTER( int indent, FILE *fp );
+
+
+
+};
+
+
+#endif
+
diff --git a/include/chill_ast.hh b/include/chillAST/chillASTs.hh
index 43eb106..228cf3f 100644
--- a/include/chill_ast.hh
+++ b/include/chillAST/chillASTs.hh
@@ -1,664 +1,10 @@
-#ifndef _CHILL_AST_H_
-#define _CHILL_AST_H_
-
-
-#define CHILL_INDENT_AMOUNT 2
-
-#include <iostream>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <vector> // std::vector
-
-#include <ir_enums.hh> // for IR_CONDITION_*
-
-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!
-
-
-enum CHILL_ASTNODE_TYPE {
- CHILLAST_NODETYPE_UNKNOWN=0,
- CHILLAST_NODETYPE_SOURCEFILE,
- CHILLAST_NODETYPE_TYPEDEFDECL,
- CHILLAST_NODETYPE_VARDECL,
- // CHILLAST_NODETYPE_PARMVARDECL, not used any more
- CHILLAST_NODETYPE_FUNCTIONDECL,
- CHILLAST_NODETYPE_RECORDDECL, // struct or union (or class)
- CHILLAST_NODETYPE_MACRODEFINITION,
- CHILLAST_NODETYPE_COMPOUNDSTMT,
- CHILLAST_NODETYPE_LOOP, // AKA ForStmt
- CHILLAST_NODETYPE_TERNARYOPERATOR,
- CHILLAST_NODETYPE_BINARYOPERATOR,
- CHILLAST_NODETYPE_UNARYOPERATOR,
- CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR,
- CHILLAST_NODETYPE_MEMBEREXPR, // structs/unions
- CHILLAST_NODETYPE_DECLREFEXPR,
- CHILLAST_NODETYPE_INTEGERLITERAL,
- CHILLAST_NODETYPE_FLOATINGLITERAL,
- CHILLAST_NODETYPE_IMPLICITCASTEXPR,
- CHILLAST_NODETYPE_RETURNSTMT,
- CHILLAST_NODETYPE_CALLEXPR,
- CHILLAST_NODETYPE_DECLSTMT,
- CHILLAST_NODETYPE_PARENEXPR,
- CHILLAST_NODETYPE_CSTYLECASTEXPR,
- CHILLAST_NODETYPE_CSTYLEADDRESSOF,
- CHILLAST_NODETYPE_IFSTMT,
- CHILLAST_NODETYPE_SIZEOF,
- CHILLAST_NODETYPE_MALLOC,
- CHILLAST_NODETYPE_FREE,
- CHILLAST_NODETYPE_PREPROCESSING, // comments, #define, #include, whatever else works
- CHILLAST_NODETYPE_NOOP, // NO OP
- // CUDA specific
- CHILLAST_NODETYPE_CUDAMALLOC,
- CHILLAST_NODETYPE_CUDAFREE,
- CHILLAST_NODETYPE_CUDAMEMCPY,
- CHILLAST_NODETYPE_CUDAKERNELCALL,
- CHILLAST_NODETYPE_CUDASYNCTHREADS,
- CHILLAST_NODETYPE_NULL // explicit non-statement
- // TODO
-
-} ;
-
-#define CHILLAST_NODETYPE_FORSTMT CHILLAST_NODETYPE_LOOP
-#define CHILLAST_NODETYPE_TRANSLATIONUNIT CHILLAST_NODETYPE_SOURCEFILE
-
-enum CHILL_FUNCTION_TYPE {
- CHILL_FUNCTION_CPU = 0,
- CHILL_FUNCTION_GPU
-};
-
-enum CHILL_MEMBER_EXP_TYPE {
- CHILL_MEMBER_EXP_DOT = 0,
- CHILL_MEMBER_EXP_ARROW
-};
-
-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,
- CHILL_PREPROCESSING_LINEBEFORE, // previous line
- CHILL_PREPROCESSING_LINEAFTER, // next line
- CHILL_PREPROCESSING_TOTHERIGHT, // for this kind of comment, on same line
- CHILL_PREPROCESSING_IMMEDIATELYBEFORE // on same line
-};
-
-
-
-
-
-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
-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_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
-
-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
-
-
-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 *);
-
-
-
-
-
-
-// an actual chill ast.
-// 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:
-
- static int chill_scalar_counter; // for manufactured scalars
- 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
- virtual chillAST_SymbolTable *getSymbolTable() { return NULL; } // most nodes do NOT have a symbol table
-
- virtual chillAST_VarDecl *findVariableNamed( 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;
- 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; } ;
-
- char *metacomment; // for compiler internals, formerly a comment
- void setMetaComment( char *c ) { metacomment = strdup(c); };
-
- std::vector<chillAST_Preprocessing*> preprocessinginfo;
-
- virtual void addChild( chillAST_node* c) {
- //if (c->isFunctionDecl()) fprintf(stderr, "addchild FunctionDecl\n");
- c->parent = this;
- // check to see if it's already there
- for (int i=0; i<children.size(); i++) {
- if (c == children[i]) {
- //fprintf(stderr, "addchild ALREADY THERE\n");
- return; // already there
- }
- }
- children.push_back(c);
- } ; // not usually useful
-
- 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 );
- };
-
- virtual void removeChild(int i) {
- children.erase( children.begin()+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) {
- children[i] = newchild;
- 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
- };
-
- 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 );
- }
- }
-
- 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 const char* getUnderlyingType() {
- fprintf(stderr,"(%s) forgot to implement getUnderlyingType()\n", Chill_AST_Node_Names[asttype]);
- dump();
- print();
- fprintf(stderr, "\n\n");
- segfault();
- };
-
- virtual chillAST_VarDecl* getUnderlyingVarDecl() {
- fprintf(stderr,"(%s) forgot to implement getUnderlyingVarDecl()\n", Chill_AST_Node_Names[asttype]);
- dump();
- print();
- fprintf(stderr, "\n\n");
- segfault();
- };
+#ifndef _CHILLAST_ASTs_H_
+#define _CHILLAST_ASTs_H_
-
- 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]);
- dump();
- print();
- fprintf(stderr, "\n\n");
- segfault();
- };
-
- virtual void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
- fprintf(stderr,"(%s) forgot to implement gatherArrayRefs()\n" ,Chill_AST_Node_Names[asttype]);
- dump();
- print();
- fprintf(stderr, "\n\n");
- };
-
- // 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]);
- dump();
- print();
- fprintf(stderr, "\n\n");
- };
-
- 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
-
- // 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);
-
-
- 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 );
- }
-
-
- 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
- if (!parent) return NULL;
- 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
- if (!parent) return NULL;
- 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
- }
-
- // 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 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 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 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 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]);
- }
-
-
- 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;
- }
-
-
- 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* clone() { // makes a deep COPY (?)
- fprintf(stderr,"(%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);
- 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);
- fprintf(fp, "\n");
- 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
- fflush(stdout);
- // chillindent(indent, fp); TODO
- fprintf(stderr,"(%s) forgot to implement stringRep()\n" ,Chill_AST_Node_Names[asttype]);
- segfault();
- }
-
-
- virtual void printonly( int indent=0, FILE *fp = stderr ) { print( indent, fp); };
-
- //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();
- //fprintf(stderr, "get_top_level_loops of a %s with %d children\n", getTypeString(), n);
- 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])) );
- }
- }
- //fprintf(stderr, "found %d top level loops\n", loops.size());
- }
-
-
- 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;
- }
- }
- }
-
-
-
- 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++) {
- //fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString());
- 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();
- //fprintf(stderr, "find_deepest_loops of a %s with %d children\n", getTypeString(), n);
- 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()) {
- deepest = subloops;
- }
- }
-
- // append deepest we see at this level to loops
- 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; } ;
-
- 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);
- if (parent != NULL) return parent->findDatatype(t); // most nodes do this
- return NULL;
- }
-
-
- 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
- }
-
- 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;}
-
- if (parent) parent->walk_parents();
- else fprintf(stderr, "UHOH, %s has no parent??\n", getTypeString());
- 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]);
- exit(-1);
- }
- 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);
- print();
- 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);
- print();
- fprintf(stderr, "\n\n"); }
-
- void printPreprocBEFORE( int indent, FILE *fp );
- void printPreprocAFTER( int indent, FILE *fp );
-
-
-
-};
+#include "chillAST_def.hh"
+#include "chillAST_node.hh"
class chillAST_NULL: public chillAST_node { // NOOP?
public:
@@ -1223,46 +569,7 @@ public:
};
-
-/*
- class chillAST_VarDecl: public chillAST_node { // now a SINGLE DECL. multiples in
- public:
- int howmany; // usually 1 but sometimes multiple declarations in a decl;
- std::vector<class chillAST_SingleVarDecl*> decls;
-
- chillAST_VarDecl();
- chillAST_VarDecl( char *t, char *n, char *a);
- void addDecl( char *t, char *n, char *a);
-
- void dump( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr );
- };
-*/
-
-
-/*
-class chillAST_ParmVarDecl: public chillAST_node { // no longer used?
-public:
- char *vartype; // should probably be an enum
- char *varname;
- char *arraypart;
- int numdimensions; // TODO
- int *arraysizes; // TODO
- // hasDefaultArg
- // getDefaultArg
-
- chillAST_ParmVarDecl();
- chillAST_ParmVarDecl( const char *type, const char *name, const char *ap, chillAST_node *p );
-
- void dump( int indent=0, FILE *fp = stderr ) {
- fprintf(fp, "(2VarDecl'%s' '%s' '%s')", vartype, varname, arraypart); };
- void print( int indent=0, FILE *fp = stderr );
-};
-*/
-
-
-
-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;
@@ -1321,13 +628,8 @@ public:
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;
@@ -2357,7 +1659,6 @@ public:
-chillAST_FunctionDecl *findFunctionDecl( chillAST_node *node, const char *procname);
diff --git a/include/chilldebug.h b/include/chilldebug.h
index f187955..c09aa59 100644
--- a/include/chilldebug.h
+++ b/include/chilldebug.h
@@ -1,20 +1,31 @@
#ifndef DEBUGCHILL_H
#define DEBUGCHILL_H
+#include <libgen.h>
+#include <string.h>
+#include <stdlib.h>
+
#ifndef NDEBUG // means that CMAKE_BUILD_TYPE=Debug
#define DEBUGCHILL
#endif
+// This thing below potentially create leaks
+#define FILENAME basename(strdup(__FILE__))
#ifdef DEBUGCHILL
-#define CHILL_DEBUG_PRINT(format,args...) fprintf(stderr,"%s,%s,LN%d:\n\t" format,__FILE__,__FUNCTION__,__LINE__, ##args )
+#define CHILL_DEBUG_PRINT(format,args...) fprintf(stderr,"%s, %s, LN%d:\t" format,FILENAME,__FUNCTION__, \
+ __LINE__, ##args )
#define CHILL_DEBUG_BEGIN { \
- fprintf(stderr,"%s,%s,LN%d:\n",__FILE__,__FUNCTION__,__LINE__);
-#define CHILL_DEBUG_END }
+ fprintf(stderr,"=========\t%s, %s, LN%d\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 do {
-#define CHILL_DEBUG_END } while (0);
+#define CHILL_DEBUG_BEGIN while(0) {
+#define CHILL_DEBUG_END }
#endif
+// TODO below should be substituted by some error throwing? to be more consistent with cpp style
+#define CHILL_ERROR(format,args...) fprintf(stderr,"ERROR:\t%s, %s, LN%d:\t" format,FILENAME,__FUNCTION__, \
+ __LINE__, ##args )
+
#endif
diff --git a/include/dep.hh b/include/dep.hh
index ed5a83d..73c662c 100644
--- a/include/dep.hh
+++ b/include/dep.hh
@@ -34,7 +34,6 @@ struct DependenceVector {
quasi = false;
is_scalar_dependence = false;
}
- // DependenceVector(int size);
DependenceVector(const DependenceVector &that);
~DependenceVector() { delete sym; } // is this legal? TODO
DependenceVector &operator=(const DependenceVector &that);
@@ -60,7 +59,6 @@ struct DependenceVector {
std::vector<DependenceVector> normalize() const;
std::vector<DependenceVector> permute(const std::vector<int> &pi) const;
DependenceVector reverse() const;
- // std::vector<DependenceVector> matrix(const std::vector<std::vector<int> > &M) const;
DependenceType getType() const;
friend std::ostream& operator<<(std::ostream &os, const DependenceVector &d);
};
@@ -77,10 +75,8 @@ public:
DependenceGraph() { num_dim_ = 0; }
~DependenceGraph() {}
int num_dim() const { return num_dim_; }
-// DependenceGraph permute(const std::vector<int> &pi) const;
DependenceGraph permute(const std::vector<int> &pi,
const std::set<int> &active = std::set<int>()) const;
- // DependenceGraph matrix(const std::vector<std::vector<int> > &M) const;
DependenceGraph subspace(int dim) const;
bool isPositive() const;
bool hasPositive(int dim) const;
diff --git a/include/ir_clang.hh b/include/ir_clang.hh
index b283359..e637016 100755
--- a/include/ir_clang.hh
+++ b/include/ir_clang.hh
@@ -3,7 +3,6 @@
#include <omega.h>
#include "ir_code.hh"
-//#include <AstInterface_CLANG.h>
#include "chill_error.hh"
#define __STDC_CONSTANT_MACROS
@@ -29,7 +28,7 @@
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Basic/DiagnosticOptions.h"
-#include "chill_ast.hh"
+#include "chillAST.h"
extern std::vector<chillAST_VarDecl *> VariableDeclarations; // a global. TODO
@@ -282,14 +281,6 @@ public:
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_Code *ir, const StmtList& bDecl) : bDecl_(bDecl), cs_(NULL) {
- // fprintf(stderr, "MISTAKE IR_chillBlock bdecl\n"); exit(-1);
- // ir_ = ir;
- //}
- //IR_chillBlock(const IR_Code *ir, clang::CompoundStmt *cs) : cs_(cs) {
- // fprintf(stderr, "MISTAKE IR_chillBlock cs\n"); exit(-1);
- // ir_ = ir;
- //}
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] );
diff --git a/include/ir_code.hh b/include/ir_code.hh
index f52d147..e3fd8ea 100644
--- a/include/ir_code.hh
+++ b/include/ir_code.hh
@@ -24,7 +24,7 @@
#include <ir_enums.hh>
-#include <chill_ast.hh>
+#include <chillAST/chillASTs.hh>
#include <vector>
diff --git a/include/irtools.hh b/include/irtools.hh
index d85b76b..a743fa5 100644
--- a/include/irtools.hh
+++ b/include/irtools.hh
@@ -47,7 +47,6 @@ typedef std::map<int, std::pair<std::vector<DependenceVector>, std::vector<Depen
typedef std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > DVPair;
// Manu:: this function is required for reduction operation
-//omega::CG_outputRepr * from_same_statement(IR_Code *ir, IR_ArrayRef *a, IR_ArrayRef *b);
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);
diff --git a/include/stencil.hh b/include/stencil.hh
index 69eec42..799e3b9 100644
--- a/include/stencil.hh
+++ b/include/stencil.hh
@@ -2,7 +2,7 @@
#pragma once
#include "ir_clang.hh"
-#include "chill_ast.hh"
+#include "chillAST/chillASTs.hh"
//#include <omega.h>
#include <omegatools.hh>
diff --git a/lib/chillcg/include/code_gen/CG_chillRepr.h b/lib/chillcg/include/code_gen/CG_chillRepr.h
index 3d19de7..36b2fa4 100755
--- a/lib/chillcg/include/code_gen/CG_chillRepr.h
+++ b/lib/chillcg/include/code_gen/CG_chillRepr.h
@@ -12,7 +12,7 @@
#endif
-#include "chill_ast.hh"
+#include "chillAST/chillASTs.hh"
namespace omega {
diff --git a/src/chill_ast.cc b/src/chillASTs.cc
index 978e303..ebb811c 100644
--- a/src/chill_ast.cc
+++ b/src/chillASTs.cc
@@ -1,7 +1,8 @@
-#include "chill_ast.hh"
+#include <chilldebug.h>
+#include "chillAST.h"
using namespace std;
@@ -882,7 +883,7 @@ chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname,
chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *par, void *unique) {
- fprintf(stderr, "chillAST_FunctionDecl::chillAST_FunctionDecl with unique %p\n", unique);
+ CHILL_DEBUG_PRINT("chillAST_FunctionDecl::chillAST_FunctionDecl with unique %p\n", unique);
returnType = strdup(rt);
functionName = strdup(fname);
this->setFunctionCPU();
@@ -903,17 +904,17 @@ chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname,
void chillAST_FunctionDecl::addParameter( chillAST_VarDecl *p) {
- fprintf(stderr, "%s chillAST_FunctionDecl::addParameter( 0x%x param %s) total of %d parameters\n", functionName, p, p->varname, 1+parameters.size());
+ CHILL_DEBUG_PRINT("%s chillAST_FunctionDecl::addParameter( 0x%x param %s) total of %d parameters\n", functionName, p, p->varname, 1+parameters.size());
if (symbolTableHasVariableNamed( &parameters, p->varname)) { // NOT recursive. just in FunctionDecl
- fprintf(stderr, "chillAST_FunctionDecl::addParameter( %s ), parameter already exists?\n", p->varname);
+ CHILL_DEBUG_PRINT("chillAST_FunctionDecl::addParameter( %s ), parameter already exists?\n", p->varname);
// exit(-1); // ??
return; // error?
}
parameters.push_back(p);
//addSymbolToTable( parameters, p );
- fprintf(stderr, "setting %s isAParameter\n", p->varname);
+ CHILL_DEBUG_PRINT("setting %s isAParameter\n", p->varname);
p->isAParameter = true;
p->setParent( this ); // ?? unclear TODO
@@ -923,7 +924,7 @@ void chillAST_FunctionDecl::addParameter( chillAST_VarDecl *p) {
void chillAST_FunctionDecl::addDecl( chillAST_VarDecl *vd) { // to symbol table ONLY
- fprintf(stderr, "chillAST_FunctionDecl::addDecl( %s )\n", vd->varname);
+ CHILL_DEBUG_PRINT("chillAST_FunctionDecl::addDecl( %s )\n", vd->varname);
if (!body) {
//fprintf(stderr, "had no body\n");
body = new chillAST_CompoundStmt();
@@ -977,11 +978,11 @@ chillAST_VarDecl *chillAST_FunctionDecl::funcHasVariableNamed( const char *name
//fprintf(stderr, "comparing '%s' to '%s'\n", name, vd->varname);
if (!strcmp(name, vd->varname)) {
//fprintf(stderr, "yep, it's variable %d\n", i);
- fprintf(stderr, "%s was already defined in the function body\n", vd->varname);
+ CHILL_DEBUG_PRINT("%s was already defined in the function body\n", vd->varname);
return vd; // need to check type?
}
}
- fprintf(stderr, "not a parameter or variable named %s\n", name);
+ CHILL_DEBUG_PRINT("not a parameter or variable named %s\n", name);
return NULL;
}
@@ -1021,10 +1022,12 @@ void chillAST_FunctionDecl::insertChild(int i, chillAST_node* node) {
}
void chillAST_FunctionDecl::addChild(chillAST_node* node) {
- fprintf(stderr, "chillAST_FunctionDecl::addChild( ) "); node->print(0,stderr); fprintf(stderr, "\n\n");
+ CHILL_DEBUG_BEGIN
+ node->print(0,stderr); fprintf(stderr, "\n\n");
+ CHILL_DEBUG_END
if (node->isVarDecl()) {
chillAST_VarDecl *vd = ((chillAST_VarDecl *) node);
- fprintf(stderr, "functiondecl %s adding a VarDecl named %s\n", functionName, vd->varname);
+ CHILL_DEBUG_PRINT("functiondecl %s adding a VarDecl named %s\n", functionName, vd->varname);
}
body->addChild( node );
@@ -2138,7 +2141,7 @@ void chillAST_ForStmt::loseLoopWithLoopVar( char *var ) {
chillAST_BinaryOperator::chillAST_BinaryOperator() {
//fprintf(stderr, "chillAST_BinaryOperator::chillAST_BinaryOperator() %p no parent\n", this);
- fprintf(stderr, "chillAST_BinaryOperator::chillAST_BinaryOperator() no parent\n");
+ CHILL_DEBUG_PRINT("chillAST_BinaryOperator::chillAST_BinaryOperator() no parent\n");
lhs = rhs = NULL;
op = NULL;
asttype = CHILLAST_NODETYPE_BINARYOPERATOR;
@@ -2149,7 +2152,7 @@ chillAST_BinaryOperator::chillAST_BinaryOperator() {
chillAST_BinaryOperator::chillAST_BinaryOperator(chillAST_node *l, const char *oper, chillAST_node *r, chillAST_node *par) {
//fprintf(stderr, "chillAST_BinaryOperator::chillAST_BinaryOperator( l %p %s r %p, parent %p) this %p\n", l, oper, r, par, this);
- fprintf(stderr, "chillAST_BinaryOperator::chillAST_BinaryOperator( l %s r )\n", oper);
+ CHILL_DEBUG_PRINT("chillAST_BinaryOperator::chillAST_BinaryOperator( l %s r )\n", oper);
//if (l && r ) {
// fprintf(stderr, "("); l->print(0,stderr); fprintf(stderr, ") %s (", oper); r->print(0,stderr); fprintf(stderr, ")\n\n");
@@ -3872,10 +3875,7 @@ chillAST_node* chillAST_VarDecl::clone() {
void chillAST_VarDecl::splitarraypart() {
- fprintf(stderr, "chillAST_VarDecl::splitarraypart() ");
- //fprintf(stderr, "%p ", arraypart);
- if (arraypart) fprintf(stderr, "%s", arraypart);
- fprintf(stderr, "\n");
+ if (arraypart) CHILL_DEBUG_PRINT("%s\n", arraypart);
// split arraypart into (leading??) asterisks and known sizes [1][2][3]
if (!arraypart || // NULL
@@ -3895,7 +3895,7 @@ void chillAST_VarDecl::splitarraypart() {
for ( int i=0; i<strlen(arraypart); i++) {
if (arraypart[i] == '*') {
if (fixedcount) {
- fprintf(stderr, "illegal vardecl arraypart: '%s'\n", arraypart);
+ CHILL_ERROR("illegal vardecl arraypart: '%s'\n", arraypart);
segfault();
exit(-1);
}
@@ -5311,8 +5311,7 @@ chillAST_VarDecl::chillAST_VarDecl( chillAST_TypedefDecl *tdd, const char *n, c
chillAST_VarDecl::chillAST_VarDecl( const char *t, const char *n, const char *a, void *ptr, chillAST_node *par) {
- fprintf(stderr, "2chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart '%s' ) %p\n", t, n, a, this);
- //fprintf(stderr, "2chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart %s, ptr 0x%x, parent 0x%x )\n", t, n, a, ptr, par);
+ CHILL_DEBUG_PRINT("chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart '%s' ) %p\n", t, n, a, this);
vartype = strdup(t);
@@ -5453,7 +5452,7 @@ chillAST_VarDecl::chillAST_VarDecl( const char *t, const char *n, const char *a
isFromSourceFile = true; // default
filename = NULL;
- fprintf(stderr, "2chillAST_VarDecl::chillAST_VarDecl LEAVING\n");
+ CHILL_DEBUG_PRINT("LEAVING\n");
//parent->print(); fprintf(stderr, "\n\n");
diff --git a/src/ir_clang.cc b/src/ir_clang.cc
index 16deff3..0c56cf0 100755
--- a/src/ir_clang.cc
+++ b/src/ir_clang.cc
@@ -43,7 +43,7 @@ History:
#include <vector>
#include <chilldebug.h>
-#include "chill_ast.hh"
+#include "chillAST.h"
// TODO move to ir_clang.hh
// fwd declarations
@@ -833,7 +833,7 @@ chillAST_node * ConvertDeclStmt( DeclStmt *clangDS, chillAST_node *p ) {
// TODO
if (V->hasInit()) {
- fprintf(stderr, " ConvertDeclStmt() UNHANDLED initialization\n");
+ CHILL_ERROR(" ConvertDeclStmt() UNHANDLED initialization\n");
exit(-1);
}
}
@@ -886,13 +886,12 @@ chillAST_node * ConvertFunctionDecl( FunctionDecl *D, chillAST_node *p ) {
int numparams = D->getNumParams();
- //fprintf(stderr, "\nand %d parameters\n", numparams);
+ CHILL_DEBUG_PRINT( " %d parameters\n", numparams);
for (int i=0; i<numparams; i++) {
- if (i) fprintf(stderr, ", ");
VarDecl *clangvardecl = D->getParamDecl(i); // the ith parameter (CLANG)
ParmVarDecl *pvd = D->getParamDecl(i);
QualType T = pvd->getOriginalType();
- fprintf(stderr, "OTYPE %s\n", T.getAsString().c_str());
+ CHILL_DEBUG_PRINT("OTYPE %s\n", T.getAsString().c_str());
chillAST_VarDecl *chillPVD = (chillAST_VarDecl *)ConvertVarDecl( clangvardecl, chillFD ) ;
//chillPVD->print(); fflush(stdout);
@@ -901,14 +900,14 @@ chillAST_node * ConvertFunctionDecl( FunctionDecl *D, chillAST_node *p ) {
VariableDeclarations.push_back(chillPVD);
chillFD->addParameter(chillPVD);
- fprintf(stderr, "chillAST ParmVarDecl for %s from chill location 0x%x\n",chillPVD->varname, clangvardecl);
+ CHILL_DEBUG_PRINT("chillAST ParmVarDecl for %s from chill location 0x%x\n",chillPVD->varname, clangvardecl);
} // for each parameter
//fprintf(stderr, ")\n{\n"); // beginning of function body
//if (D->isExternC()) { chillFD->setExtern(); fprintf(stderr, "%s is extern\n", FuncName.c_str()); };
- if (D->getBuiltinID()) { chillFD->setExtern(); fprintf(stderr, "%s is builtin (extern)\n", FuncName.c_str()); };
+ if (D->getBuiltinID()) { chillFD->setExtern(); CHILL_DEBUG_PRINT("%s is builtin (extern)\n", FuncName.c_str()); };
Stmt *clangbody = D->getBody();
if (clangbody) { // may just be fwd decl or external, without an actual body
@@ -1670,12 +1669,14 @@ IR_Ref *IR_chillArrayRef::clone() const {
// ----------------------------------------------------------------------------
// Class: IR_chillLoop
// ----------------------------------------------------------------------------
-IR_chillLoop::IR_chillLoop(const IR_Code *ir, clang::ForStmt *tf) { fprintf(stderr, "IR_chillLoop::IR_chillLoop() you lose\n"); exit(-1); };
+IR_chillLoop::IR_chillLoop(const IR_Code *ir, clang::ForStmt *tf) { CHILL_ERROR("IR_chillLoop::IR_chillLoop() you lose\n"); exit(-1); };
-IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) {
- fprintf(stderr, "IR_xxxxLoop::IR_xxxxLoop()\n");
- fprintf(stderr, "loop is:\n");
- achillforstmt->print();
+IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) {
+ CHILL_DEBUG_BEGIN
+ fprintf(stderr, "IR_xxxxLoop::IR_xxxxLoop()\n");
+ fprintf(stderr, "loop is:\n");
+ achillforstmt->print();
+ CHILL_DEBUG_END
ir_ = ir;
chillforstmt = achillforstmt;
@@ -1684,7 +1685,7 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) {
chillAST_BinaryOperator *cond = (chillAST_BinaryOperator *)chillforstmt->getCond();
// check to be sure (assert)
if (!init->isAssignmentOp() || !cond->isComparisonOp() ) {
- fprintf(stderr, "ir_clang.cc, malformed loop init or cond:\n");
+ CHILL_ERROR("malformed loop init or cond:\n");
achillforstmt->print();
exit(-1);
}
@@ -1738,21 +1739,21 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) {
else beets = true;
if (beets) {
- fprintf(stderr, "malformed loop increment (or more likely unhandled case)\n");
- inc->print();
- exit(-1);
+ CHILL_ERROR("malformed loop increment (or more likely unhandled case)\n");
+ inc->print();
+ exit(-1);
}
} // binary operator
- else {
- fprintf(stderr, "IR_chillLoop constructor, unhandled loop increment\n");
- inc->print();
- exit(-1);
+ else {
+ CHILL_ERROR("IR_chillLoop constructor, unhandled loop increment\n");
+ inc->print();
+ exit(-1);
}
//inc->print(0, stderr);fprintf(stderr, "\n");
chillAST_DeclRefExpr *dre = (chillAST_DeclRefExpr *)init->getLHS();
if (!dre->isDeclRefExpr()) {
- fprintf(stderr, "malformed loop init.\n");
+ CHILL_DEBUG_PRINT("malformed loop init.\n");
init->print();
}
@@ -1767,22 +1768,22 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) {
chillbody = achillforstmt->getBody();
- fprintf(stderr, "IR_xxxxLoop::IR_xxxxLoop() DONE\n");
+ CHILL_DEBUG_PRINT("IR_xxxxLoop::IR_xxxxLoop() DONE\n");
}
omega::CG_outputRepr *IR_chillLoop::lower_bound() const {
- fprintf(stderr, "IR_xxxxLoop::lower_bound()\n");
+ CHILL_DEBUG_PRINT("IR_xxxxLoop::lower_bound()\n");
return new omega::CG_chillRepr(chilllowerbound);
}
omega::CG_outputRepr *IR_chillLoop::upper_bound() const {
- fprintf(stderr, "IR_xxxxLoop::upper_bound()\n");
+ CHILL_DEBUG_PRINT("IR_xxxxLoop::upper_bound()\n");
return new omega::CG_chillRepr(chillupperbound);
}
IR_Block *IR_chillLoop::body() const {
- fprintf(stderr, "IR_xxxxLoop::body()\n");
+ CHILL_DEBUG_PRINT("IR_xxxxLoop::body()\n");
//assert(isa<CompoundStmt>(tf_->getBody()));
//fprintf(stderr, "returning a clangBLOCK corresponding to the body of the loop\n");
//fprintf(stderr, "body type %s\n", chillbody->getTypeString());
@@ -1790,25 +1791,26 @@ IR_Block *IR_chillLoop::body() const {
}
IR_Control *IR_chillLoop::clone() const {
- fprintf(stderr, "IR_xxxxLoop::clone()\n");
+ CHILL_DEBUG_PRINT("IR_xxxxLoop::clone()\n");
//chillforstmt->print(); fflush(stdout);
return new IR_chillLoop(ir_, chillforstmt);
}
IR_CONDITION_TYPE IR_chillLoop::stop_cond() const {
chillAST_BinaryOperator *loopcondition = (chillAST_BinaryOperator*) chillupperbound;
- fprintf(stderr, "IR_xxxxLoop::stop_cond()\n");
+ CHILL_DEBUG_PRINT("IR_xxxxLoop::stop_cond()\n");
return conditionoperator;
}
IR_Block *IR_chillLoop::convert() { // convert the loop to a block
- fprintf(stderr, "IR_xxxxLoop::convert() maybe \n");
+ CHILL_DEBUG_PRINT("IR_xxxxLoop::convert() maybe \n");
return new IR_chillBlock( ir_, chillbody ); // ??
return NULL;
}
void IR_chillLoop::dump() const {
- fprintf(stderr, "TODO: IR_chillLoop::dump()\n"); exit(-1);
+ CHILL_ERROR("TODO: IR_chillLoop::dump()\n");
+ exit(-1);
}
@@ -1816,8 +1818,8 @@ void IR_chillLoop::dump() const {
// Class: IR_chillBlock
// ----------------------------------------------------------------------------
omega::CG_outputRepr *IR_chillBlock::original() const {
- fprintf(stderr, "IR_xxxxBlock::original() TODO \n");
- exit(-1);
+ CHILL_ERROR("IR_xxxxBlock::original() TODO \n");
+ exit(-1);
return NULL;
}
@@ -1851,7 +1853,7 @@ omega::CG_outputRepr *IR_chillBlock::extract() const {
}
IR_Control *IR_chillBlock::clone() const {
- fprintf(stderr, "IR_xxxxBlock::clone()\n");
+ CHILL_DEBUG_PRINT("IR_xxxxBlock::clone()\n");
//fprintf(stderr, "IR_xxxxBlock::clone() %d statements\n", statements.size());
return new IR_chillBlock( this ); // shallow copy ?
}
@@ -1945,15 +1947,12 @@ IR_clangCode_Global_Init *IR_clangCode_Global_Init::pinstance = 0;
IR_clangCode_Global_Init *IR_clangCode_Global_Init::Instance(char **argv) {
- fprintf(stderr, "in IR_clangCode_Global_Init::Instance(), ");
- if (pinstance == 0) {
- //fprintf(stderr, "\n\n*** making the one and only instance ***\n\n\n");
+ if (pinstance == 0) {
// this is the only way to create an IR_clangCode_Global_Init
pinstance = new IR_clangCode_Global_Init;
pinstance->ClangCompiler = new aClangCompiler( argv[1] );
}
- //fprintf(stderr, "leaving IR_clangCode_Global_Init::Instance()\n");
return pinstance;
}
@@ -2053,7 +2052,7 @@ aClangCompiler::aClangCompiler( char *filename ) {
NULLASTConsumer TheConsumer; // must pass a consumer in to ParseAST(). This one does nothing
//fprintf(stderr, "ready? Parse.\n");
- fprintf(stderr, "actually parsing file %s using clang\n", filename);
+ CHILL_DEBUG_PRINT("actually parsing file %s using clang\n", filename);
ParseAST( Clang->getPreprocessor(), &TheConsumer, Clang->getASTContext());
@@ -2062,7 +2061,7 @@ aClangCompiler::aClangCompiler( char *filename ) {
// TUD->dump(); // print it out
// create another AST, very similar to the clang AST but not written by idiots
- fprintf(stderr, "converting entire clang AST into chill AST (ir_clang.cc)\n");
+ CHILL_DEBUG_PRINT("converting entire clang AST into chill AST (ir_clang.cc)\n");
chillAST_node * wholefile = ConvertTranslationUnit( TUD, filename);
fflush(stdout);
@@ -2136,17 +2135,17 @@ chillAST_FunctionDecl* aClangCompiler::findprocedurebyname( char *procname ) {
//fprintf(stderr, "procs has %d members\n", procs.size());
if ( procs.size() == 0 ) {
- fprintf(stderr, "could not find function named '%s' in AST from file %s\n", procname, SourceFileName);
+ CHILL_ERROR("could not find function named '%s' in AST from file %s\n", procname, SourceFileName);
exit(-1);
}
if ( procs.size() > 1 ) {
- fprintf(stderr, "oddly, found %d functions named '%s' in AST from file %s\n", procs.size(), procname, SourceFileName);
- fprintf(stderr, "I am unsure what to do\n");
+ CHILL_ERROR("oddly, found %d functions named '%s' in AST from file %s\n", procs.size(), procname, SourceFileName);
+ CHILL_ERROR("I am unsure what to do\n");
exit(-1);
}
- fprintf(stderr, "found the procedure named %s\n", procname);
+ CHILL_DEBUG_PRINT("found the procedure named %s\n", procname);
return (chillAST_FunctionDecl *)procs[0];
}
@@ -2226,7 +2225,7 @@ IR_clangCode_Global_Init::~IR_clangCode_Global_Init()
// ----------------------------------------------------------------------------
IR_clangCode::IR_clangCode(const char *fname, const char *proc_name): IR_Code() {
- fprintf(stderr, "\nIR_xxxxCode::IR_xxxxCode()\n\n");
+ CHILL_DEBUG_PRINT("IR_xxxxCode::IR_xxxxCode()\n");
//fprintf(stderr, "IR_clangCode::IR_clangCode( filename %s, procedure %s )\n", filename, proc_name);
filename = strdup(fname); // filename is internal to IR_clangCode
@@ -2260,15 +2259,14 @@ IR_clangCode::IR_clangCode(const char *fname, const char *proc_name): IR_Code()
pInstance->setCurrentFunction( localFD );
chillAST_node *b = localFD->getBody(); // we do this just because it will get done next
- fprintf(stderr, "in IR_xxxxCode::IR_xxxxCode(), new CG_xxxxBuilder\n");
- fprintf(stderr, "ir_clang.cc calling new CG_chillBuilder() umwut?\n");
+ CHILL_DEBUG_PRINT("calling new CG_chillBuilder() umwut?\n");
ocg_ = new omega::CG_chillBuilder(); // ocg == omega code gen
chillfunc = localFD;
}
- fprintf(stderr, "IR_xxxxCode::IR_xxxxCode() returning after reading source file and finding function\n\n");
+ CHILL_DEBUG_PRINT("returning after reading source file and finding function\n\n");
//chillfunc->dump( 0, stderr);
@@ -2277,7 +2275,7 @@ IR_clangCode::IR_clangCode(const char *fname, const char *proc_name): IR_Code()
IR_clangCode::~IR_clangCode() {
//func_->print(llvm::outs(), 4); // printing as part of the destructor !!
- fprintf(stderr, "IR_xxxxCode::~IR_xxxxCode()\noutput happening as part of the destructor !!\n");
+ CHILL_DEBUG_PRINT("\n\toutput happening as part of the destructor !!\n");
//chillfunc->dump();
//chillfunc->print();
@@ -2578,7 +2576,7 @@ std::vector<IR_ArrayRef *> IR_clangCode::FindArrayRef(const omega::CG_outputRepr
std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Block *block) const {
- fprintf(stderr, "IR_xxxxCode::FindOneLevelControlStructure()\n");
+ CHILL_DEBUG_PRINT("IR_xxxxCode::FindOneLevelControlStructure()\n");
const IR_chillBlock *CB = (const IR_chillBlock *) block;
//fprintf(stderr, "block 0x%x\n", block);
@@ -2588,14 +2586,14 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
//fprintf(stderr, "blockast 0x%x\n", blockast);
if (blockast == NULL) {
int numstmts = CB->statements.size();
- fprintf(stderr, "%d statements\n", numstmts);
+ CHILL_DEBUG_PRINT("%d statements\n", numstmts);
if (numstmts == 0) return controls;
else if (numstmts == 1) blockast = CB->statements[0]; // a single statement
else {
- fprintf(stderr, "IR_xxxBlock is dumb, with multiple ways to hold statements\n");
+ CHILL_ERROR( "IR_xxxBlock is dumb, with multiple ways to hold statements\n");
exit(-1); // TODO FIX
}
}
@@ -2615,11 +2613,14 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
std::vector<chillAST_node *> children;
- if (blockast->asttype == CHILLAST_NODETYPE_FORSTMT) { fflush(stdout);
- fprintf(stderr, "found a top level For statement (Loop)\n");
- fprintf(stderr, "For Stmt (loop) is:\n");
- blockast->print();
- fprintf(stderr, "pushing the loop at TOP\n");
+ if (blockast->asttype == CHILLAST_NODETYPE_FORSTMT) {
+ CHILL_DEBUG_BEGIN
+ fflush(stdout);
+ fprintf(stderr, "found a top level For statement (Loop)\n");
+ fprintf(stderr, "For Stmt (loop) is:\n");
+ blockast->print();
+ fprintf(stderr, "pushing the loop at TOP\n");
+ CHILL_DEBUG_END
controls.push_back( new IR_chillLoop( this, (chillAST_ForStmt *)blockast));
}
@@ -2663,16 +2664,16 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
CHILL_ASTNODE_TYPE typ = children[i]->asttype;
if (typ == CHILLAST_NODETYPE_LOOP) {
if (numchildren == 1) {
- fprintf(stderr, "found a For statement (Loop)\n");
+ CHILL_DEBUG_PRINT("found a For statement (Loop)\n");
}
else {
- fprintf(stderr, "found a For statement (Loop) at %d within a Basic Block\n", i);
+ CHILL_DEBUG_PRINT("found a For statement (Loop) at %d within a Basic Block\n", i);
}
//children[i]->print(); printf("\n"); fflush(stdout);
ns = basicblock->numstatements();
if (ns) {
- fprintf(stderr, "pushing a run of statements %d to %d as a block\n", i-ns, i-1);
+ CHILL_DEBUG_PRINT("pushing a run of statements %d to %d as a block\n", i-ns, i-1);
controls.push_back( basicblock );
basicblock = new IR_chillBlock(this); // start a new one
}
@@ -2704,17 +2705,17 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
}
else {
- fprintf(stderr, "IR_clangCode::FindOneLevelControlStructure(), block is a %s???\n", blockast->getTypeString());
+ CHILL_ERROR("IR_clangCode::FindOneLevelControlStructure(), block is a %s???\n", blockast->getTypeString());
exit(-1);
}
- fprintf(stderr, "returning vector of %d controls\n", controls.size() );
+ CHILL_DEBUG_PRINT("returning vector of %d controls\n", controls.size() );
return controls;
}
IR_Block *IR_clangCode::MergeNeighboringControlStructures(const std::vector<IR_Control *> &controls) const {
- fprintf(stderr, "IR_xxxxCode::MergeNeighboringControlStructures %d controls\n", controls.size());
+ CHILL_DEBUG_PRINT("IR_xxxxCode::MergeNeighboringControlStructures %d controls\n", controls.size());
if (controls.size() == 0)
return NULL;
@@ -2726,7 +2727,7 @@ IR_Block *IR_clangCode::MergeNeighboringControlStructures(const std::vector<IR_C
for (int i = 0; i < controls.size(); i++) {
switch (controls[i]->type()) {
case IR_CONTROL_LOOP: {
- fprintf(stderr, "control %d is IR_CONTROL_LOOP\n", i);
+ CHILL_DEBUG_PRINT("control %d is IR_CONTROL_LOOP\n", i);
chillAST_ForStmt *loop = static_cast<IR_chillLoop *>(controls[i])->chillforstmt;
if (parent == NULL) {
parent = loop->parent;
@@ -2739,7 +2740,7 @@ IR_Block *IR_clangCode::MergeNeighboringControlStructures(const std::vector<IR_C
break;
}
case IR_CONTROL_BLOCK: {
- fprintf(stderr, "control %d is IR_CONTROL_BLOCK\n", i);
+ CHILL_DEBUG_PRINT("control %d is IR_CONTROL_BLOCK\n", i);
IR_chillBlock *CB = static_cast<IR_chillBlock*>(controls[i]);
std::vector<chillAST_node*> blockstmts = CB->statements;
if (statements.size() != 0) {
@@ -2758,8 +2759,7 @@ IR_Block *IR_clangCode::MergeNeighboringControlStructures(const std::vector<IR_C
else {
if (CB->chillAST) CBlock->addStatement(CBlock->chillAST); // if this is a block, add theblock's statements?
else { // should never happen
- fprintf(stderr, "WARNING: ir_clang.cc IR_clangCode::MergeNeighboringControlStructures");
- fprintf(stderr, " empty IR_CONTROL_BLOCK \n");
+ CHILL_DEBUG_PRINT("WARNING: empty IR_CONTROL_BLOCK \n");
}
}
break;
@@ -2923,9 +2923,8 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) {
}
break;
case IR_CONTROL_BLOCK:
- fprintf(stderr, "old is IR_CONTROL_BLOCK\n");
- fprintf(stderr, "IR_clangCode::ReplaceCode() stubbed out\n");
- exit(-1);
+ CHILL_ERROR("old is IR_CONTROL_BLOCK\n");
+ exit(-1);
//tf_old = static_cast<IR_chillBlock *>(old)->getStmtList()[0];
break;
default:
@@ -2935,17 +2934,18 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) {
fflush(stdout);
//fprintf(stderr, "\nafter inserting %d statements into the Clang IR,", numnew);
- fprintf(stderr, "\nnew parent2 is\n\n{\n");
- std::vector<chillAST_node*> newparentcode = par->getChildren();
- for (int i=0; i<newparentcode.size(); i++) {
- fflush(stdout);
- //fprintf(stderr, "%d ", i);
- newparentcode[i]->print(); printf(";\n"); fflush(stdout);
- }
-
+ CHILL_DEBUG_BEGIN
+ fprintf(stderr, "new parent2 is\n\n{\n");
+ std::vector<chillAST_node*> newparentcode = par->getChildren();
+ for (int i=0; i<newparentcode.size(); i++) {
+ fflush(stdout);
+ //fprintf(stderr, "%d ", i);
+ newparentcode[i]->print(); printf(";\n"); fflush(stdout);
+ }
+ fprintf(stderr, "}\n");
+ CHILL_DEBUG_END
- fprintf(stderr, "}\n");
}
@@ -3045,14 +3045,14 @@ IR_OPERATION_TYPE IR_clangCode::QueryExpOperation(const omega::CG_outputRepr *re
if (!strcmp(opstring, "/")) return IR_OP_DIVIDE;
if (!strcmp(opstring, "=")) return IR_OP_ASSIGNMENT;
- fprintf(stderr, "ir_clang.cc IR_clangCode::QueryExpOperation() UNHANDLED Binary(or Unary)Operator op type (%s)\n", opstring);
+ CHILL_ERROR("UNHANDLED Binary(or Unary)Operator op type (%s)\n", opstring);
exit(-1);
}
else if (node->isDeclRefExpr() ) return IR_OP_VARIABLE; // ??
//else if (node->is ) return something;
else {
- fprintf(stderr, "IR_clangCode::QueryExpOperation() UNHANDLED NODE TYPE %s\n", node->getTypeString());
- exit(-1);
+ CHILL_ERROR("IR_clangCode::QueryExpOperation() UNHANDLED NODE TYPE %s\n", node->getTypeString());
+ exit(-1);
}
/* CLANG
@@ -3123,7 +3123,7 @@ std::vector<omega::CG_outputRepr *> IR_clangCode::QueryExpOperand(const omega::C
v.push_back(new omega::CG_chillRepr( bop->rhs ));
}
else {
- fprintf(stderr, "ir_clang.cc IR_clangCode::QueryExpOperand() Binary Operator UNHANDLED op (%s)\n", op);
+ CHILL_ERROR("Binary Operator UNHANDLED op (%s)\n", op);
exit(-1);
}
} // BinaryOperator
@@ -3135,13 +3135,13 @@ std::vector<omega::CG_outputRepr *> IR_clangCode::QueryExpOperand(const omega::C
v.push_back( new omega::CG_chillRepr( uop->subexpr ));
}
else {
- fprintf(stderr, "ir_clang.cc IR_clangCode::QueryExpOperand() Unary Operator UNHANDLED op (%s)\n", op);
+ CHILL_ERROR("ir_clang.cc IR_clangCode::QueryExpOperand() Unary Operator UNHANDLED op (%s)\n", op);
exit(-1);
}
} // unaryoperator
else {
- fprintf(stderr, "ir_clang.cc IR_clangCode::QueryExpOperand() UNHANDLED node type %s\n", e->getTypeString());
- exit(-1);
+ CHILL_ERROR("UNHANDLED node type %s\n", e->getTypeString());
+ exit(-1);
}
diff --git a/src/irtools.cc b/src/irtools.cc
index 16c4f7c..d8d234f 100644
--- a/src/irtools.cc
+++ b/src/irtools.cc
@@ -13,6 +13,7 @@
#include <iostream>
#include <code_gen/CG_outputBuilder.h>
+#include <chilldebug.h>
#include "irtools.hh"
#include "omegatools.hh"
#include "chill_error.hh"
@@ -26,18 +27,18 @@ std::vector<ir_tree_node *> build_ir_tree(IR_Control *control,
ir_tree_node *parent) {
std::vector<ir_tree_node *> result;
- fprintf(stderr, "irtools.cc, build_ir_tree( control, parent) building a CHILL IR tree \n");
+ CHILL_DEBUG_PRINT("building a CHILL IR tree \n");
switch (control->type()) {
case IR_CONTROL_BLOCK: {
- fprintf(stderr, "irtools.cc L31 case IR_CONTROL_BLOCK\n");
+ CHILL_DEBUG_PRINT("case IR_CONTROL_BLOCK\n");
IR_Block *IRCB = static_cast<IR_Block *>(control);
std::vector<IR_Control *> controls = control->ir_->FindOneLevelControlStructure(IRCB);
- fprintf(stderr, "irtools.cc BACK FROM FindOneLevelControlStructure() %d controls\n", controls.size());
+ CHILL_DEBUG_PRINT( "BACK FROM FindOneLevelControlStructure() %d controls\n", controls.size());
if (controls.size() == 0) {
- fprintf(stderr, "controls.size() == 0\n");
+ CHILL_DEBUG_PRINT("controls.size() == 0\n");
ir_tree_node *node = new ir_tree_node;
node->content = control;
@@ -46,19 +47,19 @@ std::vector<ir_tree_node *> build_ir_tree(IR_Control *control,
result.push_back(node);
}
else {
- fprintf(stderr, "controls.size() == %d (NONZERO)\n", controls.size());
+ CHILL_DEBUG_PRINT("controls.size() == %d (NONZERO)\n", controls.size());
delete control;
for (int i = 0; i < controls.size(); i++)
switch (controls[i]->type()) {
case IR_CONTROL_BLOCK: {
- fprintf(stderr, "controls[%d] is IR_CONTROL_BLOCK\n", i);
+ CHILL_DEBUG_PRINT("controls[%d] is IR_CONTROL_BLOCK\n", i);
std::vector<ir_tree_node *> t = build_ir_tree(controls[i], parent);
result.insert(result.end(), t.begin(), t.end());
break;
}
case IR_CONTROL_LOOP: {
- fprintf(stderr, "controls[%d] is IR_CONTROL_LOOP\n", i);
+ CHILL_DEBUG_PRINT("controls[%d] is IR_CONTROL_LOOP\n", i);
ir_tree_node *node = new ir_tree_node;
node->content = controls[i];
node->parent = parent;
@@ -68,7 +69,7 @@ std::vector<ir_tree_node *> build_ir_tree(IR_Control *control,
break;
}
case IR_CONTROL_IF: {
- fprintf(stderr, "controls[%d] is IR_CONTROL_IF\n", i);
+ CHILL_DEBUG_PRINT("controls[%d] is IR_CONTROL_IF\n", i);
static int unique_if_identifier = 0;
IR_If* theif = static_cast<IR_If *>(controls[i]);
@@ -85,7 +86,7 @@ std::vector<ir_tree_node *> build_ir_tree(IR_Control *control,
block = theif->else_body();
if (block != NULL) {
- fprintf(stderr, "IF_CONTROL has an else\n");
+ CHILL_DEBUG_PRINT("IF_CONTROL has an else\n");
ir_tree_node *node = new ir_tree_node;
node->content = controls[i]->clone();
node->parent = parent;
@@ -108,16 +109,16 @@ std::vector<ir_tree_node *> build_ir_tree(IR_Control *control,
break;
}
case IR_CONTROL_LOOP: {
- fprintf(stderr, "case IR_CONTROL_LOOP\n");
+ CHILL_DEBUG_PRINT("case IR_CONTROL_LOOP\n");
ir_tree_node *node = new ir_tree_node;
node->content = control;
node->parent = parent;
- fprintf(stderr, "recursing. build_ir_tree() of CONTROL_LOOP creating children L122\n");
+ CHILL_DEBUG_PRINT("recursing. build_ir_tree() of CONTROL_LOOP creating children L122\n");
node->children = build_ir_tree(
static_cast<const IR_Loop *>(control)->body(), node);
node->payload = -1;
result.push_back(node);
- fprintf(stderr, "recursing. build_ir_tree() of CONTROL_LOOP creating children DONE\n");
+ CHILL_DEBUG_PRINT("recursing. build_ir_tree() of CONTROL_LOOP creating children DONE\n");
break;
}
default:
@@ -129,7 +130,7 @@ std::vector<ir_tree_node *> build_ir_tree(IR_Control *control,
break;
}
- fprintf(stderr, "build_ir_tree() vector result has %ld parts\n", result.size());
+ CHILL_DEBUG_PRINT("build_ir_tree() vector result has %ld parts\n", result.size());
return result;
}
@@ -138,18 +139,18 @@ std::vector<ir_tree_node *> build_ir_tree(IR_Control *control,
// lexical order in the source code.
std::vector<ir_tree_node *> extract_ir_stmts(const std::vector<ir_tree_node *> &ir_tree) {
- fprintf(stderr, "extract_ir_stmts() ir_tree.size() %d\n", ir_tree.size());
+ CHILL_DEBUG_PRINT("extract_ir_stmts() ir_tree.size() %d\n", ir_tree.size());
std::vector<ir_tree_node *> result;
for (int i = 0; i < ir_tree.size(); i++)
switch (ir_tree[i]->content->type()) {
case IR_CONTROL_BLOCK:
- fprintf(stderr, "IR_CONTROL_BLOCK\n");
+ CHILL_DEBUG_PRINT("IR_CONTROL_BLOCK\n");
result.push_back(ir_tree[i]);
break;
case IR_CONTROL_LOOP: {
- fprintf(stderr, "IR_CONTROL_LOOP( recursing )\n");
+ CHILL_DEBUG_PRINT("IR_CONTROL_LOOP( recursing )\n");
// clear loop payload from previous unsuccessful initialization process
ir_tree[i]->payload = -1;
@@ -159,7 +160,7 @@ std::vector<ir_tree_node *> extract_ir_stmts(const std::vector<ir_tree_node *> &
break;
}
case IR_CONTROL_IF: {
- fprintf(stderr, "IR_CONTROL_IF( recursing )\n");
+ CHILL_DEBUG_PRINT("IR_CONTROL_IF( recursing )\n");
std::vector<ir_tree_node *> t = extract_ir_stmts(ir_tree[i]->children);
result.insert(result.end(), t.begin(), t.end());
break;
@@ -176,7 +177,7 @@ std::string chill_ir_control_type_string( IR_CONTROL_TYPE type ) {
case IR_CONTROL_BLOCK: return std::string( "IR_CONTROL_BLOCK");
case IR_CONTROL_LOOP: return std::string( "IR_CONTROL_LOOP" );
case IR_CONTROL_IF: return std::string( "IR_CONTROL_IF" );
- case IR_CONTROL_WHILE: return std::string( "IR_CONTROL_WHLIE"); break;
+ case IR_CONTROL_WHILE: return std::string( "IR_CONTROL_WHLIE");
default: return std::string( "UNKNOWN_IR_NODE_TYPE" );
}
}
@@ -282,15 +283,15 @@ test_data_dependences(IR_Code *ir,
int nestLevelj,
std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols,
std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols_stringrepr) {
+ CHILL_DEBUG_BEGIN
+ fprintf(stderr, "\nirtools.cc test_data_dependences() %d freevars\n", freevar.size());
+ fprintf(stderr, "\nrepr1 %p ", repr1); repr1->dump(); fflush(stdout);
+ fprintf(stderr, "\nrepr2 %p ", repr2); repr2->dump(); fflush(stdout);
- fprintf(stderr, "\nirtools.cc test_data_dependences() %d freevars\n", freevar.size());
- fprintf(stderr, "\nrepr1 %p ", repr1); repr1->dump(); fflush(stdout);
- fprintf(stderr, "\nrepr2 %p ", repr2); repr2->dump(); fflush(stdout);
-
- for (int i=0; i<index.size(); i++) fprintf(stderr, "index %d %s\n", i, index[i].c_str());
- Relation *helper = new Relation(IS1); fprintf(stderr, "IS1 "); helper->print(); fflush(stdout);
- helper = new Relation(IS2); fprintf(stderr, "IS2 "); helper->print(); fflush(stdout);
-
+ for (int i=0; i<index.size(); i++) fprintf(stderr, "index %d %s\n", i, index[i].c_str());
+ Relation *helper = new Relation(IS1); fprintf(stderr, "IS1 "); helper->print(); fflush(stdout);
+ helper = new Relation(IS2); fprintf(stderr, "IS2 "); helper->print(); fflush(stdout);
+ CHILL_DEBUG_END
//for (int i=0; i<freevar.size(); i++) {
// std::string shit = (const std::string)(freevar[i]->base_name());
@@ -301,23 +302,25 @@ test_data_dependences(IR_Code *ir,
std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > result;
if (repr1 == repr2) {
- fprintf(stderr, "repr1 == repr2\nrepr1->dump()\n");
- repr1->dump();
+ CHILL_DEBUG_BEGIN
+ fprintf(stderr, "repr1 == repr2\nrepr1->dump()\n");
+ repr1->dump();
+ CHILL_DEBUG_END
fflush(stdout);
std::vector<IR_ArrayRef *> access = ir->FindArrayRef(repr1);
- fprintf(stderr, "access of size %d\n", access.size());
+ CHILL_DEBUG_PRINT("access of size %d\n", access.size());
for (int i = 0; i < access.size(); i++) {
IR_ArrayRef *a = access[i];
if (a->is_write()) {
- fprintf(stderr, "WRITE array access %d = %s\n", i, a->name().c_str());
+ CHILL_DEBUG_PRINT("WRITE array access %d = %s\n", i, a->name().c_str());
}
else {
- fprintf(stderr, " array access %d = %s\n", i, a->name().c_str());
+ CHILL_DEBUG_PRINT(" array access %d = %s\n", i, a->name().c_str());
}
}
- fprintf(stderr, "that was the list\n\n");
+ CHILL_DEBUG_PRINT("that was the list\n\n");
// Manu:: variables/structures added to identify dependence vectors related to reduction operation
tempResultMap trMap;
@@ -335,9 +338,9 @@ test_data_dependences(IR_Code *ir,
// Manu -- changes for identifying possible reduction operation
// The below loop nest is used to classify array references into different statements
- fprintf(stderr, "\nbefore mapRefstoStatements()\n");
+ CHILL_DEBUG_PRINT("\nbefore mapRefstoStatements()\n");
mapRefstoStatements(ir,access,ref2Stmt,rMap,tnrStmts,nrStmts);
- fprintf(stderr, "after mapRefstoStatements()\n\n");
+ CHILL_DEBUG_PRINT("after mapRefstoStatements()\n\n");
//-------------------------------------------------------------
omega::coef_t lbound[3], ubound[3]; // for each kind of dependence. We can potentially have reduction only if all
@@ -368,10 +371,11 @@ test_data_dependences(IR_Code *ir,
else fprintf(stderr, "%d b->is_NOT_write()\n", j);
if (*sym_a == *sym_b && (a->is_write() || b->is_write())) {
- fprintf(stderr, "\nirtools.cc ij %d %d SYMBOL A == SYMBOL B and one is a write\n", i, j);
Relation r = arrays2relation(ir, freevar, a, IS1, b, IS2,uninterpreted_symbols,uninterpreted_symbols_stringrepr);
- helper = new Relation(r); fprintf(stderr, "r "); helper->print(); fflush(stdout);
-
+ CHILL_DEBUG_BEGIN
+ fprintf(stderr, "\nirtools.cc ij %d %d SYMBOL A == SYMBOL B and one is a write\n", i, j);
+ Relation *helper = new Relation(r); fprintf(stderr, "r "); helper->print(); fflush(stdout);
+ CHILL_DEBUG_END
fprintf(stderr, "1\n");
std::pair<std::vector<DependenceVector>,
diff --git a/src/omegatools.cc b/src/omegatools.cc
index 0322182..7ebe726 100644
--- a/src/omegatools.cc
+++ b/src/omegatools.cc
@@ -19,7 +19,7 @@
#include "ir_code.hh"
#include "chill_error.hh"
-#include "chill_ast.hh"
+#include "chillAST/chillASTs.hh"
#include "code_gen/CG_chillRepr.h"
#include <code_gen/CG_utils.h>
diff --git a/src/loop.cc b/src/transformations/loop.cc
index 5f863f2..570bc90 100644
--- a/src/loop.cc
+++ b/src/transformations/loop.cc
@@ -37,6 +37,7 @@
#include "chill_error.hh"
#include <string.h>
#include <list>
+#include <chilldebug.h>
// TODO
#define _DEBUG_ true
@@ -51,19 +52,19 @@ const std::string Loop::overflow_var_name_prefix = std::string("over");
void echocontroltype( const IR_Control *control ) {
switch(control->type()) {
case IR_CONTROL_BLOCK: {
- fprintf(stderr, "IR_CONTROL_BLOCK\n");
+ CHILL_DEBUG_PRINT("IR_CONTROL_BLOCK\n");
break;
}
case IR_CONTROL_LOOP: {
- fprintf(stderr, "IR_CONTROL_LOOP\n");
+ CHILL_DEBUG_PRINT("IR_CONTROL_LOOP\n");
break;
}
case IR_CONTROL_IF: {
- fprintf(stderr, "IR_CONTROL_IF\n");
+ CHILL_DEBUG_PRINT("IR_CONTROL_IF\n");
break;
}
default:
- fprintf(stderr, "just a bunch of statements?\n");
+ CHILL_DEBUG_PRINT("just a bunch of statements?\n");
} // switch
}
@@ -107,10 +108,10 @@ void Loop::reduce(int stmt_num,
//ir->printStmt(stmt[stmt_num].code);
if (stmt[stmt_num].reduction != 1) {
- std::cout << "loop.cc Cannot reduce this statement\n";
+ CHILL_DEBUG_PRINT("Cannot reduce this statement\n");
return;
}
- fprintf(stderr, "loop.cc CAN reduce this statment?\n");
+ CHILL_DEBUG_PRINT("CAN reduce this statment?\n");
/*for (int i = 0; i < level.size(); i++)
if (stmt[stmt_num].loop_level[level[i] - 1].segreducible != true) {
@@ -303,19 +304,17 @@ bool Loop::isInitialized() const {
bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
std::vector<ir_tree_node *> &ir_stmt) {
- fprintf(stderr, "\n Loop::init_loop()\n");
-
- fprintf(stderr, "extract_ir_stmts()\n");
- fprintf(stderr, "ir_tree has %d statements\n", ir_tree.size());
+ CHILL_DEBUG_PRINT("extract_ir_stmts()\n");
+ CHILL_DEBUG_PRINT("ir_tree has %d statements\n", ir_tree.size());
ir_stmt = extract_ir_stmts(ir_tree);
- fprintf(stderr,"nesting level stmt size = %d\n", (int)ir_stmt.size());
+ CHILL_DEBUG_PRINT("nesting level stmt size = %d\n", (int)ir_stmt.size());
stmt_nesting_level_.resize(ir_stmt.size());
std::vector<int> stmt_nesting_level(ir_stmt.size());
- fprintf(stderr, "%d statements?\n", (int)ir_stmt.size());
+ CHILL_DEBUG_PRINT("%d statements?\n", (int)ir_stmt.size());
// find out how deeply nested each statement is. (how can these be different?)
for (int i = 0; i < ir_stmt.size(); i++) {
@@ -330,14 +329,14 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
}
stmt_nesting_level_[i] = t;
stmt_nesting_level[i] = t;
- fprintf(stderr, "stmt_nesting_level[%d] = %d\n", i, t);
+ CHILL_DEBUG_PRINT("stmt_nesting_level[%d] = %d\n", i, t);
}
if (actual_code.size() == 0)
actual_code = std::vector<CG_outputRepr*>(ir_stmt.size());
stmt = std::vector<Statement>(ir_stmt.size());
- fprintf(stderr, "in init_loop, made %d stmts\n", (int)ir_stmt.size());
+ CHILL_DEBUG_PRINT("in init_loop, made %d stmts\n", (int)ir_stmt.size());
uninterpreted_symbols = std::vector<std::map<std::string, std::vector<omega::CG_outputRepr * > > >(ir_stmt.size());
uninterpreted_symbols_stringrepr = std::vector<std::map<std::string, std::vector<omega::CG_outputRepr * > > >(ir_stmt.size());
@@ -357,34 +356,34 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
}
}
- fprintf(stderr, "max nesting level %d at location %d\n", max_nesting_level, loc);
+ CHILL_DEBUG_PRINT("max nesting level %d at location %d\n", max_nesting_level, loc);
// most deeply nested statement acting as a reference point
if (n_dim == -1) {
- fprintf(stderr, "loop.cc L356 n_dim now max_nesting_level %d\n", max_nesting_level);
+ CHILL_DEBUG_PRINT("n_dim now max_nesting_level %d\n", max_nesting_level);
n_dim = max_nesting_level;
max_loc = loc;
index = std::vector<std::string>(n_dim);
ir_tree_node *itn = ir_stmt[loc];
- fprintf(stderr, "itn = stmt[%d]\n", loc);
+ CHILL_DEBUG_PRINT("itn = stmt[%d]\n", loc);
int cur_dim = n_dim - 1;
while (itn->parent != NULL) {
- fprintf(stderr, "parent\n");
+ CHILL_DEBUG_PRINT("parent\n");
itn = itn->parent;
if (itn->content->type() == IR_CONTROL_LOOP) {
- fprintf(stderr, "IR_CONTROL_LOOP cur_dim %d\n", cur_dim);
+ CHILL_DEBUG_PRINT("IR_CONTROL_LOOP cur_dim %d\n", cur_dim);
IR_Loop *IRL = static_cast<IR_Loop *>(itn->content);
index[cur_dim] = IRL->index()->name();
- fprintf(stderr, "index[%d] = '%s'\n", cur_dim, index[cur_dim].c_str());
+ CHILL_DEBUG_PRINT("index[%d] = '%s'\n", cur_dim, index[cur_dim].c_str());
itn->payload = cur_dim--;
}
}
}
- fprintf(stderr, "align loops by names,\n");
+ CHILL_DEBUG_PRINT("align loops by names,\n");
// align loops by names, temporary solution
ir_tree_node *itn = ir_stmt[loc]; // defined outside loops??
int depth = stmt_nesting_level_[loc] - 1;
@@ -422,13 +421,13 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
}
}
- fprintf(stderr, "\nset relation variable names ****\n");
+ CHILL_DEBUG_PRINT("set relation variable names ****\n");
// set relation variable names
// this finds the loop variables for loops enclosing this statement and puts
// them in an Omega Relation (just their names, which could fail)
- fprintf(stderr, "Relation r(%d)\n", n_dim);
+ CHILL_DEBUG_PRINT("Relation r(%d)\n", n_dim);
Relation r(n_dim);
F_And *f_root = r.add_and();
itn = ir_stmt[loc];
@@ -828,18 +827,17 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
Loop::Loop(const IR_Control *control) {
- fprintf(stderr, "\nLoop::Loop(const IR_Control *control)\n");
- fprintf(stderr, "control type is %d ", control->type());
+ CHILL_DEBUG_PRINT("control type is %d ", control->type());
echocontroltype(control);
-
+
+ CHILL_DEBUG_PRINT("2set last_compute_cg_ = NULL; \n");
last_compute_cgr_ = NULL;
last_compute_cg_ = NULL;
- fprintf(stderr, "2set last_compute_cg_ = NULL; \n");
ir = const_cast<IR_Code *>(control->ir_); // point to the CHILL IR that this loop came from
if (ir == 0) {
- fprintf(stderr, "ir gotten from control = 0x%x\n", (long)ir);
- fprintf(stderr, "loop.cc GONNA DIE SOON *******************************\n\n");
+ CHILL_DEBUG_PRINT("ir gotten from control = 0x%x\n", (long)ir);
+ CHILL_DEBUG_PRINT("loop.cc GONNA DIE SOON *******************************\n\n");
}
init_code = NULL;
@@ -848,8 +846,8 @@ Loop::Loop(const IR_Control *control) {
overflow_var_name_counter = 1;
known = Relation::True(0);
- fprintf(stderr, "in Loop::Loop, calling build_ir_tree()\n");
- fprintf(stderr, "\nloop.cc, Loop::Loop() about to clone control\n");
+ CHILL_DEBUG_PRINT("calling build_ir_tree()\n");
+ CHILL_DEBUG_PRINT("about to clone control\n");
ir_tree = build_ir_tree(control->clone(), NULL);
//fprintf(stderr,"in Loop::Loop. ir_tree has %ld parts\n", ir_tree.size());
@@ -4008,11 +4006,11 @@ std::pair<Relation, Relation> construct_reduced_IS_And_XFORM(IR_Code *ir,
}
*/
- if (_DEBUG_) {
+ CHILL_DEBUG_BEGIN
std::cout << "relation debug" << std::endl;
IS.print();
- }
-
+ CHILL_DEBUG_END
+
F_And *f_root = XFORM.add_and();
count_ = 1;
@@ -4031,12 +4029,12 @@ std::pair<Relation, Relation> construct_reduced_IS_And_XFORM(IR_Code *ir,
omega::EQ_Handle h = f_root->add_EQ();
h.update_coef(XFORM.output_var((loops.size()) * 2 + 1), 1);
h.update_const(-lex_order[xform.n_out() - 1]);
-
- if (_DEBUG_) {
+
+ CHILL_DEBUG_BEGIN
std::cout << "relation debug" << std::endl;
IS.print();
XFORM.print();
- }
+ CHILL_DEBUG_END
return std::pair<Relation, Relation>(IS, XFORM);
@@ -4299,23 +4297,23 @@ std::map<std::string, std::vector<std::string> > recurse_on_exp_for_arrays(
std::vector<CG_outputRepr *> find_guards(IR_Code *ir, IR_Control *code) {
- fprintf(stderr, "find_guards()\n");
+ CHILL_DEBUG_PRINT("find_guards()\n");
std::vector<CG_outputRepr *> guards;
switch (code->type()) {
case IR_CONTROL_IF: {
- fprintf(stderr, "find_guards() it's an if\n");
+ CHILL_DEBUG_PRINT("find_guards() it's an if\n");
CG_outputRepr *cond = dynamic_cast<IR_If*>(code)->condition();
std::vector<CG_outputRepr *> then_body;
std::vector<CG_outputRepr *> else_body;
IR_Block *ORTB = dynamic_cast<IR_If*>(code)->then_body();
if (ORTB != NULL) {
- fprintf(stderr, "recursing on then\n");
+ CHILL_DEBUG_PRINT("recursing on then\n");
then_body = find_guards(ir, ORTB);
//dynamic_cast<IR_If*>(code)->then_body());
}
if (dynamic_cast<IR_If*>(code)->else_body() != NULL) {
- fprintf(stderr, "recursing on then\n");
+ CHILL_DEBUG_PRINT("recursing on then\n");
else_body = find_guards(ir,
dynamic_cast<IR_If*>(code)->else_body());
}
@@ -4330,9 +4328,9 @@ std::vector<CG_outputRepr *> find_guards(IR_Code *ir, IR_Control *code) {
break;
}
case IR_CONTROL_BLOCK: {
- fprintf(stderr, "find_guards() it's a control block\n");
+ CHILL_DEBUG_PRINT("it's a control block\n");
IR_Block* IRCB = dynamic_cast<IR_Block*>(code);
- fprintf(stderr, "find_guards() calling ir->FindOneLevelControlStructure(IRCB);\n");
+ CHILL_DEBUG_PRINT("calling ir->FindOneLevelControlStructure(IRCB);\n");
std::vector<IR_Control *> stmts = ir->FindOneLevelControlStructure(IRCB);
for (int i = 0; i < stmts.size(); i++) {
@@ -4343,7 +4341,7 @@ std::vector<CG_outputRepr *> find_guards(IR_Code *ir, IR_Control *code) {
break;
}
case IR_CONTROL_LOOP: {
- fprintf(stderr, "find_guards() it's a control loop\n");
+ CHILL_DEBUG_PRINT("it's a control loop\n");
std::vector<CG_outputRepr *> body = find_guards(ir,
dynamic_cast<IR_Loop*>(code)->body());
if (body.size() > 0)
diff --git a/src/loop_basic.cc b/src/transformations/loop_basic.cc
index a058598..a058598 100644
--- a/src/loop_basic.cc
+++ b/src/transformations/loop_basic.cc
diff --git a/src/loop_datacopy.cc b/src/transformations/loop_datacopy.cc
index 12d74fd..12d74fd 100644
--- a/src/loop_datacopy.cc
+++ b/src/transformations/loop_datacopy.cc
diff --git a/src/loop_extra.cc b/src/transformations/loop_extra.cc
index dac05bf..dac05bf 100644
--- a/src/loop_extra.cc
+++ b/src/transformations/loop_extra.cc
diff --git a/src/loop_tile.cc b/src/transformations/loop_tile.cc
index 41c3e7f..41c3e7f 100644
--- a/src/loop_tile.cc
+++ b/src/transformations/loop_tile.cc
diff --git a/src/loop_unroll.cc b/src/transformations/loop_unroll.cc
index 86ffd84..86ffd84 100644
--- a/src/loop_unroll.cc
+++ b/src/transformations/loop_unroll.cc