summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2016-09-23 10:59:54 -0600
committerTuowen Zhao <ztuowen@gmail.com>2016-09-23 10:59:54 -0600
commit699861922d5349ffa98b518f34016b2be2ca368d (patch)
treeb1172a41c89b382487772ef05c8a5ce70c068fa0
parent16f097d5548e9b31ab4b0dc343afeb680b361e28 (diff)
downloadchill-699861922d5349ffa98b518f34016b2be2ca368d.tar.gz
chill-699861922d5349ffa98b518f34016b2be2ca368d.tar.bz2
chill-699861922d5349ffa98b518f34016b2be2ca368d.zip
more changes
-rw-r--r--include/chillAST/chillAST_def.hh90
-rw-r--r--include/chillAST/chillAST_node.hh665
-rw-r--r--include/chillAST/chillASTs.hh2174
-rw-r--r--include/chill_error.hh16
-rw-r--r--include/chilldebug.h6
-rw-r--r--include/chillmodule.hh2
-rw-r--r--include/dep.hh52
-rw-r--r--include/graph.hh103
-rwxr-xr-xinclude/ir_clang.hh299
-rw-r--r--include/ir_code.hh258
-rw-r--r--include/ir_enums.hh1
-rw-r--r--include/irtools.hh34
-rw-r--r--include/loop.hh4
-rw-r--r--include/omegatools.hh74
-rw-r--r--include/stencil.hh23
-rwxr-xr-xlib/chillcg/include/code_gen/CG_chillRepr.h107
-rw-r--r--src/chill.cc19
-rw-r--r--src/chillASTs.cc6539
-rw-r--r--src/chillmodule.cc392
-rw-r--r--src/dep.cc197
-rwxr-xr-xsrc/ir_clang.cc2289
-rw-r--r--src/irtools.cc624
-rw-r--r--src/omegatools.cc1766
-rw-r--r--src/transformations/loop.cc2791
-rw-r--r--src/transformations/loop_basic.cc858
-rw-r--r--src/transformations/loop_datacopy.cc811
-rw-r--r--src/transformations/loop_extra.cc124
-rw-r--r--src/transformations/loop_tile.cc420
-rw-r--r--src/transformations/loop_unroll.cc642
29 files changed, 10923 insertions, 10457 deletions
diff --git a/include/chillAST/chillAST_def.hh b/include/chillAST/chillAST_def.hh
index 318b51b..0e5832e 100644
--- a/include/chillAST/chillAST_def.hh
+++ b/include/chillAST/chillAST_def.hh
@@ -19,7 +19,7 @@
#define CHILLAST_NODETYPE_TRANSLATIONUNIT CHILLAST_NODETYPE_SOURCEFILE
enum CHILL_ASTNODE_TYPE {
- CHILLAST_NODETYPE_UNKNOWN=0,
+ CHILLAST_NODETYPE_UNKNOWN = 0,
CHILLAST_NODETYPE_SOURCEFILE,
CHILLAST_NODETYPE_TYPEDEFDECL,
CHILLAST_NODETYPE_VARDECL,
@@ -58,26 +58,26 @@ enum CHILL_ASTNODE_TYPE {
CHILLAST_NODETYPE_CUDASYNCTHREADS,
CHILLAST_NODETYPE_NULL // explicit non-statement
// TODO
-
-} ;
-enum CHILL_FUNCTION_TYPE {
+};
+
+enum CHILL_FUNCTION_TYPE {
CHILL_FUNCTION_CPU = 0,
CHILL_FUNCTION_GPU
};
-
-enum CHILL_MEMBER_EXP_TYPE {
+
+enum CHILL_MEMBER_EXP_TYPE {
CHILL_MEMBER_EXP_DOT = 0,
CHILL_MEMBER_EXP_ARROW
};
-
-enum CHILL_PREPROCESSING_TYPE {
+
+enum CHILL_PREPROCESSING_TYPE {
CHILL_PREPROCESSING_TYPEUNKNOWN = 0,
CHILL_PREPROCESSING_COMMENT,
CHILL_PREPROCESSING_POUNDDEFINE,
CHILL_PREPROCESSING_POUNDINCLUDE,
CHILL_PREPROCESSING_PRAGMA // unused so far
-};
+};
enum CHILL_PREPROCESSING_POSITION { // when tied to another statement
CHILL_PREPROCESSING_POSITIONUNKNOWN = 0,
@@ -87,14 +87,18 @@ enum CHILL_PREPROCESSING_POSITION { // when tied to another statement
CHILL_PREPROCESSING_IMMEDIATELYBEFORE // on same line
};
-char *parseUnderlyingType( char *sometype );
-char *parseArrayParts( char *sometype );
-bool isRestrict( const char *sometype );
-char *splitTypeInfo( char *underlyingtype );
-char *ulhack( char *brackets ); // change "1024UL" to "1024"
-char *restricthack( char *typeinfo ); // remove __restrict__ , MODIFIES the argument!
+char *parseUnderlyingType(char *sometype);
+
+char *parseArrayParts(char *sometype);
+
+bool isRestrict(const char *sometype);
+
+char *splitTypeInfo(char *underlyingtype);
+
+char *ulhack(char *brackets); // change "1024UL" to "1024"
+char *restricthack(char *typeinfo); // remove __restrict__ , MODIFIES the argument!
-extern const char* Chill_AST_Node_Names[]; // WARNING MUST BE KEPT IN SYNC WITH BELOW LIST
+extern const char *Chill_AST_Node_Names[]; // WARNING MUST BE KEPT IN SYNC WITH BELOW LIST
// fwd declarations
class chillAST_node; // the generic node. specific types derive from this
@@ -102,60 +106,88 @@ class chillAST_NULL; // empty
class chillAST_SourceFile; // ast for an entire source file (translationunit)
class chillAST_TypedefDecl;
+
class chillAST_VarDecl;
+
//class chillAST_ParmVarDecl;
class chillAST_FunctionDecl;
+
class chillAST_RecordDecl; // structs and unions (and classes?)
class chillAST_MacroDefinition;
+
class chillAST_CompoundStmt; // just a bunch of other statements
class chillAST_ForStmt; // AKA a LOOP
class chillAST_TernaryOperator;
+
class chillAST_BinaryOperator;
+
class chillAST_ArraySubscriptExpr;
+
class chillAST_MemberExpr;
+
class chillAST_DeclRefExpr;
+
class chillAST_IntegerLiteral;
+
class chillAST_FloatingLiteral;
+
class chillAST_UnaryOperator;
+
class chillAST_ImplicitCastExpr;
+
class chillAST_CStyleCastExpr;
+
class chillAST_CStyleAddressOf;
+
class chillAST_ReturnStmt;
+
class chillAST_CallExpr;
+
class chillAST_ParenExpr;
+
class chillAST_Sizeof;
+
class chillAST_Malloc;
+
class chillAST_Free;
+
class chillAST_NoOp;
+
class chillAST_CudaMalloc;
+
class chillAST_CudaFree;
+
class chillAST_CudaMemcpy;
+
class chillAST_CudaKernelCall;
+
class chillAST_CudaSyncthreads;
+
class chillAST_Preprocessing;
-typedef std::vector<chillAST_VarDecl *> chillAST_SymbolTable; // typedef
+typedef std::vector<chillAST_VarDecl *> chillAST_SymbolTable; // typedef
typedef std::vector<chillAST_TypedefDecl *> chillAST_TypedefTable; // typedef
-bool symbolTableHasVariableNamed( chillAST_SymbolTable *table, const char *name ); // fwd decl
-chillAST_VarDecl *symbolTableFindVariableNamed( chillAST_SymbolTable *table, const char *name ); // fwd decl TODO too many similar named functions
+bool symbolTableHasVariableNamed(chillAST_SymbolTable *table, const char *name); // fwd decl
+chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table,
+ const char *name); // fwd decl TODO too many similar named functions
-void printSymbolTable( chillAST_SymbolTable *st ); // fwd decl
-void printSymbolTableMoreInfo( chillAST_SymbolTable *st ); // fwd decl
+void printSymbolTable(chillAST_SymbolTable *st); // fwd decl
+void printSymbolTableMoreInfo(chillAST_SymbolTable *st); // fwd decl
-chillAST_node *lessthanmacro( chillAST_node *left, chillAST_node *right); // fwd declaration
-chillAST_SymbolTable *addSymbolToTable( chillAST_SymbolTable *st, chillAST_VarDecl *vd ); // fwd decl
-chillAST_TypedefTable *addTypedefToTable( chillAST_TypedefTable *tt, chillAST_TypedefDecl *td ); // fwd decl
+chillAST_node *lessthanmacro(chillAST_node *left, chillAST_node *right); // fwd declaration
+chillAST_SymbolTable *addSymbolToTable(chillAST_SymbolTable *st, chillAST_VarDecl *vd); // fwd decl
+chillAST_TypedefTable *addTypedefToTable(chillAST_TypedefTable *tt, chillAST_TypedefDecl *td); // fwd decl
-bool streq( const char *a, const char *b); // fwd decl
-void chillindent( int i, FILE *fp ); // fwd declaration
-void insertNewDeclAtLocationOfOldIfNeeded( chillAST_VarDecl *newdecl, chillAST_VarDecl *olddecl);
+bool streq(const char *a, const char *b); // fwd decl
+void chillindent(int i, FILE *fp); // fwd declaration
+void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_VarDecl *olddecl);
-chillAST_DeclRefExpr *buildDeclRefExpr( chillAST_VarDecl *);
+chillAST_DeclRefExpr *buildDeclRefExpr(chillAST_VarDecl *);
-chillAST_FunctionDecl *findFunctionDecl( chillAST_node *node, const char *procname);
+chillAST_FunctionDecl *findFunctionDecl(chillAST_node *node, const char *procname);
#endif
diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh
index 70660c5..bc3facb 100644
--- a/include/chillAST/chillAST_node.hh
+++ b/include/chillAST/chillAST_node.hh
@@ -9,363 +9,402 @@
// nodes based on clang AST which are in turn based on C++
class chillAST_node { // generic node. a tree of these is the AST. this is virtual (can't instantiate)
-public:
+public:
static int chill_scalar_counter; // for manufactured scalars
- static int chill_array_counter ; // for manufactured arrays
- static int chill_pointer_counter ; // for manufactured arrays
+ static int chill_array_counter; // for manufactured arrays
+ static int chill_pointer_counter; // for manufactured arrays
CHILL_ASTNODE_TYPE asttype;
-
- bool isSourceFile() { return (asttype == CHILLAST_NODETYPE_SOURCEFILE); };
- bool isTypeDefDecl() { return (asttype == CHILLAST_NODETYPE_TYPEDEFDECL); };
- bool isVarDecl() { return (asttype == CHILLAST_NODETYPE_VARDECL); };
- bool isFunctionDecl() { return (asttype == CHILLAST_NODETYPE_FUNCTIONDECL); };
- bool isRecordDecl() { return (asttype == CHILLAST_NODETYPE_RECORDDECL); };
- bool isMacroDefinition() { return (asttype == CHILLAST_NODETYPE_MACRODEFINITION); };
- bool isCompoundStmt() { return (asttype == CHILLAST_NODETYPE_COMPOUNDSTMT); };
- bool isLoop() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA ForStmt
- bool isForStmt() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA Loop
- bool isIfStmt() { return (asttype == CHILLAST_NODETYPE_IFSTMT); };
- bool isTernaryOperator() { return (asttype == CHILLAST_NODETYPE_TERNARYOPERATOR);};
- bool isBinaryOperator() { return (asttype == CHILLAST_NODETYPE_BINARYOPERATOR); };
- bool isUnaryOperator() { return (asttype == CHILLAST_NODETYPE_UNARYOPERATOR); };
- bool isArraySubscriptExpr() { return (asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR); };
- bool isMemberExpr() { return (asttype == CHILLAST_NODETYPE_MEMBEREXPR); };
- bool isDeclRefExpr() { return (asttype == CHILLAST_NODETYPE_DECLREFEXPR); };
- bool isIntegerLiteral() { return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL); };
- bool isFloatingLiteral() { return (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); };
- bool isImplicitCastExpr() { return (asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR); };
- bool isReturnStmt() { return (asttype == CHILLAST_NODETYPE_RETURNSTMT); };
- bool isCallExpr() { return (asttype == CHILLAST_NODETYPE_CALLEXPR); };
- bool isParenExpr() { return (asttype == CHILLAST_NODETYPE_PARENEXPR); };
- bool isSizeof() { return (asttype == CHILLAST_NODETYPE_SIZEOF); };
- bool isMalloc() { return (asttype == CHILLAST_NODETYPE_MALLOC); };
- bool isFree() { return (asttype == CHILLAST_NODETYPE_FREE); };
- bool isPreprocessing() { return (asttype == CHILLAST_NODETYPE_PREPROCESSING); };
- bool isNoOp() { return (asttype == CHILLAST_NODETYPE_NOOP); };
- bool isNull() { return (asttype == CHILLAST_NODETYPE_NULL); };
- bool isCStyleCastExpr() { return (asttype == CHILLAST_NODETYPE_CSTYLECASTEXPR); };
- bool isCStyleAddressOf() { return (asttype == CHILLAST_NODETYPE_CSTYLEADDRESSOF); };
- bool isCudaMalloc() { return (asttype == CHILLAST_NODETYPE_CUDAMALLOC); };
- bool isCudaFree() { return (asttype == CHILLAST_NODETYPE_CUDAFREE); };
- bool isCudaMemcpy() { return (asttype == CHILLAST_NODETYPE_CUDAMEMCPY); };
- bool isCudaKERNELCALL() { return (asttype == CHILLAST_NODETYPE_CUDAKERNELCALL); };
- bool isCudaSYNCTHREADS() { return (asttype == CHILLAST_NODETYPE_CUDASYNCTHREADS); };
-
- bool isDeclStmt() { return (asttype == CHILLAST_NODETYPE_DECLSTMT); }; // doesn't exist
-
- bool isConstant() { return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL) || (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); }
-
-
- virtual bool isAssignmentOp() { return false; };
- virtual bool isComparisonOp() { return false; };
- virtual bool isNotLeaf() { return false; };
- virtual bool isLeaf() { return true; };
- virtual bool isParmVarDecl() { return false; };
-
- virtual bool isPlusOp() { return false; };
- virtual bool isMinusOp() { return false; };
- virtual bool isPlusMinusOp() { return false; };
- virtual bool isMultDivOp() { return false; };
-
- virtual bool isAStruct() { return false; };
- virtual bool isAUnion() { return false; };
-
- virtual bool hasSymbolTable() { return false; } ; // most nodes do NOT have a symbol table
- virtual bool hasTypedefTable() { return false; } ; // most nodes do NOT have a typedef table
+
+ bool isSourceFile() { return (asttype == CHILLAST_NODETYPE_SOURCEFILE); };
+
+ bool isTypeDefDecl() { return (asttype == CHILLAST_NODETYPE_TYPEDEFDECL); };
+
+ bool isVarDecl() { return (asttype == CHILLAST_NODETYPE_VARDECL); };
+
+ bool isFunctionDecl() { return (asttype == CHILLAST_NODETYPE_FUNCTIONDECL); };
+
+ bool isRecordDecl() { return (asttype == CHILLAST_NODETYPE_RECORDDECL); };
+
+ bool isMacroDefinition() { return (asttype == CHILLAST_NODETYPE_MACRODEFINITION); };
+
+ bool isCompoundStmt() { return (asttype == CHILLAST_NODETYPE_COMPOUNDSTMT); };
+
+ bool isLoop() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA ForStmt
+ bool isForStmt() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA Loop
+ bool isIfStmt() { return (asttype == CHILLAST_NODETYPE_IFSTMT); };
+
+ bool isTernaryOperator() { return (asttype == CHILLAST_NODETYPE_TERNARYOPERATOR); };
+
+ bool isBinaryOperator() { return (asttype == CHILLAST_NODETYPE_BINARYOPERATOR); };
+
+ bool isUnaryOperator() { return (asttype == CHILLAST_NODETYPE_UNARYOPERATOR); };
+
+ bool isArraySubscriptExpr() { return (asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR); };
+
+ bool isMemberExpr() { return (asttype == CHILLAST_NODETYPE_MEMBEREXPR); };
+
+ bool isDeclRefExpr() { return (asttype == CHILLAST_NODETYPE_DECLREFEXPR); };
+
+ bool isIntegerLiteral() { return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL); };
+
+ bool isFloatingLiteral() { return (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); };
+
+ bool isImplicitCastExpr() { return (asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR); };
+
+ bool isReturnStmt() { return (asttype == CHILLAST_NODETYPE_RETURNSTMT); };
+
+ bool isCallExpr() { return (asttype == CHILLAST_NODETYPE_CALLEXPR); };
+
+ bool isParenExpr() { return (asttype == CHILLAST_NODETYPE_PARENEXPR); };
+
+ bool isSizeof() { return (asttype == CHILLAST_NODETYPE_SIZEOF); };
+
+ bool isMalloc() { return (asttype == CHILLAST_NODETYPE_MALLOC); };
+
+ bool isFree() { return (asttype == CHILLAST_NODETYPE_FREE); };
+
+ bool isPreprocessing() { return (asttype == CHILLAST_NODETYPE_PREPROCESSING); };
+
+ bool isNoOp() { return (asttype == CHILLAST_NODETYPE_NOOP); };
+
+ bool isNull() { return (asttype == CHILLAST_NODETYPE_NULL); };
+
+ bool isCStyleCastExpr() { return (asttype == CHILLAST_NODETYPE_CSTYLECASTEXPR); };
+
+ bool isCStyleAddressOf() { return (asttype == CHILLAST_NODETYPE_CSTYLEADDRESSOF); };
+
+ bool isCudaMalloc() { return (asttype == CHILLAST_NODETYPE_CUDAMALLOC); };
+
+ bool isCudaFree() { return (asttype == CHILLAST_NODETYPE_CUDAFREE); };
+
+ bool isCudaMemcpy() { return (asttype == CHILLAST_NODETYPE_CUDAMEMCPY); };
+
+ bool isCudaKERNELCALL() { return (asttype == CHILLAST_NODETYPE_CUDAKERNELCALL); };
+
+ bool isCudaSYNCTHREADS() { return (asttype == CHILLAST_NODETYPE_CUDASYNCTHREADS); };
+
+ bool isDeclStmt() { return (asttype == CHILLAST_NODETYPE_DECLSTMT); }; // doesn't exist
+
+ bool isConstant() {
+ return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL) || (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL);
+ }
+
+
+ virtual bool isAssignmentOp() { return false; };
+
+ virtual bool isComparisonOp() { return false; };
+
+ virtual bool isNotLeaf() { return false; };
+
+ virtual bool isLeaf() { return true; };
+
+ virtual bool isParmVarDecl() { return false; };
+
+ virtual bool isPlusOp() { return false; };
+
+ virtual bool isMinusOp() { return false; };
+
+ virtual bool isPlusMinusOp() { return false; };
+
+ virtual bool isMultDivOp() { return false; };
+
+ virtual bool isAStruct() { return false; };
+
+ virtual bool isAUnion() { return false; };
+
+ virtual bool hasSymbolTable() { return false; }; // most nodes do NOT have a symbol table
+ virtual bool hasTypedefTable() { return false; }; // most nodes do NOT have a typedef table
virtual chillAST_SymbolTable *getSymbolTable() { return NULL; } // most nodes do NOT have a symbol table
- virtual chillAST_VarDecl *findVariableNamed( const char *name ); // recursive
+ virtual chillAST_VarDecl *findVariableNamed(const char *name); // recursive
+
+ chillAST_RecordDecl *findRecordDeclNamed(const char *name); // recursive
- chillAST_RecordDecl *findRecordDeclNamed( const char *name ); // recursive
-
// void addDecl( chillAST_VarDecl *vd); // recursive, adds to first symbol table it can find
// TODO decide how to hide some data
- chillAST_node *parent;
+ chillAST_node *parent;
bool isFromSourceFile; // false = #included
char *filename; // file this node is from
- void segfault() { fprintf(stderr, "segfaulting on purpose\n"); int *i=0; int j = i[0]; }; // seg fault
- int getNumChildren() { return children.size(); };
- std::vector<chillAST_node*> children;
- std::vector<chillAST_node*> getChildren() { return children; } ; // not usually useful
- void setChildren( std::vector<chillAST_node*>&c ) { children = c; } ; // does not set parent. probably should
- chillAST_node *getChild( int which) { return children[which]; };
- void setChild( int which, chillAST_node *n ) { children[which] = n; children[which]->parent = this; } ;
-
+ int getNumChildren() { return children.size(); };
+ std::vector<chillAST_node *> children;
+
+ std::vector<chillAST_node *>& getChildren() { return children; }; // not usually useful
+ void setChildren(std::vector<chillAST_node *> &c) { children = c; }; // does not set parent. probably should
+ chillAST_node *getChild(int which) { return children[which]; };
+
+ void setChild(int which, chillAST_node *n) {
+ children[which] = n;
+ children[which]->parent = this;
+ };
+
char *metacomment; // for compiler internals, formerly a comment
- void setMetaComment( char *c ) { metacomment = strdup(c); };
+ void setMetaComment(const char *c) { metacomment = strdup(c); };
- std::vector<chillAST_Preprocessing*> preprocessinginfo;
+ std::vector<chillAST_Preprocessing *> preprocessinginfo;
- virtual void addChild( chillAST_node* c) {
- //if (c->isFunctionDecl()) fprintf(stderr, "addchild FunctionDecl\n");
+ virtual void addChild(chillAST_node *c) {
c->parent = this;
// check to see if it's already there
- for (int i=0; i<children.size(); i++) {
+ for (int i = 0; i < children.size(); i++) {
if (c == children[i]) {
- //fprintf(stderr, "addchild ALREADY THERE\n");
+ CHILL_ERROR("addchild ALREADY THERE\n");
return; // already there
}
}
children.push_back(c);
- } ; // not usually useful
+ }; // not usually useful
- virtual void insertChild(int i, chillAST_node* node) {
+ virtual void insertChild(int i, chillAST_node *node) {
//fprintf(stderr, "%s inserting child of type %s at location %d\n", getTypeString(), node->getTypeString(), i);
- node->parent = this;
- children.insert( children.begin()+i, node );
+ node->parent = this;
+ children.insert(children.begin() + i, node);
};
-
- virtual void removeChild(int i) {
- children.erase( children.begin()+i );
+
+ virtual void removeChild(int i) {
+ children.erase(children.begin() + i);
};
-
- int findChild( chillAST_node *c ) {
- for (int i=0; i<children.size(); i++) {
+
+ int findChild(chillAST_node *c) {
+ for (int i = 0; i < children.size(); i++) {
if (children[i] == c) return i;
}
return -1;
}
- virtual void replaceChild( chillAST_node *old, chillAST_node *newchild ) {
- fprintf(stderr,"(%s) forgot to implement replaceChild() ... using generic\n" ,Chill_AST_Node_Names[asttype]);
- fprintf(stderr, "%d children\n", children.size());
- for (int i=0; i<children.size(); i++) {
- if (children[i] == old) {
+ virtual void replaceChild(chillAST_node *old, chillAST_node *newchild) {
+ CHILL_DEBUG_PRINT("(%s) forgot to implement replaceChild() ... using generic\n", Chill_AST_Node_Names[asttype]);
+ CHILL_DEBUG_PRINT("%d children\n", children.size());
+ for (int i = 0; i < children.size(); i++) {
+ if (children[i] == old) {
children[i] = newchild;
- newchild->setParent( this );
- return;
+ newchild->setParent(this);
+ return;
}
}
- fprintf(stderr, "%s %p generic replaceChild called with oldchild that was not a child\n",
- getTypeString(), this) ;
- fprintf(stderr, "printing\n");
- print(); fprintf(stderr, "\nchild: ");
- if (!old) fprintf(stderr, "oldchild NULL!\n");
- old->print(); fprintf(stderr, "\nnew: ");
- newchild->print(); fprintf(stderr, "\n");
- segfault(); // make easier for gdb
+ CHILL_ERROR("%s %p generic replaceChild called with oldchild that was not a child\n",
+ getTypeString(), this);
+ CHILL_DEBUG_BEGIN
+ fprintf(stderr, "printing\n");
+ print();
+ fprintf(stderr, "\nchild: ");
+ if (!old) fprintf(stderr, "oldchild NULL!\n");
+ old->print();
+ fprintf(stderr, "\nnew: ");
+ newchild->print();
+ fprintf(stderr, "\n");
+ CHILL_DEBUG_END
+ exit(-1);
};
-
- virtual void loseLoopWithLoopVar( char *var ) {
- // walk tree. If a loop has this loop variable, replace the loop with the loop body,
- // removing the loop. The loop will be spread across a bunch of cores that will each
- // calculate their own loop variable.
-
- // things that can not have loops as substatements can have a null version of this method
- // things that have more complicated sets of "children" will have specialized versions
-
- // this is the generic version of the method. It just recurses among its children.
- // ForStmt is the only one that can actually remove itself. When it does, it will
- // potentially change the children vector, which is not the simple array it might appear.
- // so you have to make a copy of the vector to traverse
-
- std::vector<chillAST_node*> dupe = children; // simple enough?
- //fprintf(stderr, "node XXX has %d children\n", dupe.size());
- //fprintf(stderr, "generic node %s has %d children\n", getTypeString(), dupe.size());
- for (int i=0; i<dupe.size(); i++) { // recurse on all children
- dupe[i]->loseLoopWithLoopVar( var );
+
+ //! Spread the loop across a bunch of cores that will each calculate its own loop variable.
+ /*!
+ * If a loop has this loop variable, replace the loop with the loop body, calculate their own loop variable.
+ *
+ * things that can not have loops as substatements can have a null version of this method
+ * things that have more complicated sets of "children" will have specialized versions
+ *
+ * this is the generic version of the method. It just recurses among its children.
+ * ForStmt is the only one that can actually remove itself. When it does, it will
+ * potentially change the children vector, which is not the simple array it might appear.
+ * so you have to make a copy of the vector to traverse
+ *
+ * @param var
+ */
+ virtual void loseLoopWithLoopVar(char *var) {
+ std::vector<chillAST_node *> dupe = children; // simple enough?
+ for (int i = 0; i < dupe.size(); i++) { // recurse on all children
+ dupe[i]->loseLoopWithLoopVar(var);
}
}
- virtual int evalAsInt() {
- fprintf(stderr,"(%s) can't be evaluated as an integer??\n", Chill_AST_Node_Names[asttype]);
- print(); fprintf(stderr, "\n");
- segfault();
+ virtual int evalAsInt() {
+ CHILL_ERROR("(%s) can't be evaluated as an integer??\n", Chill_AST_Node_Names[asttype]);
+ print();
+ exit(-1);
}
- virtual const char* getUnderlyingType() {
- fprintf(stderr,"(%s) forgot to implement getUnderlyingType()\n", Chill_AST_Node_Names[asttype]);
+ virtual const char *getUnderlyingType() {
+ CHILL_ERROR("(%s) forgot to implement getUnderlyingType()\n", Chill_AST_Node_Names[asttype]);
dump();
print();
- fprintf(stderr, "\n\n");
- segfault();
- };
+ exit(-1);
+ };
- virtual chillAST_VarDecl* getUnderlyingVarDecl() {
- fprintf(stderr,"(%s) forgot to implement getUnderlyingVarDecl()\n", Chill_AST_Node_Names[asttype]);
+ virtual chillAST_VarDecl *getUnderlyingVarDecl() {
+ CHILL_ERROR("(%s) forgot to implement getUnderlyingVarDecl()\n", Chill_AST_Node_Names[asttype]);
dump();
print();
- fprintf(stderr, "\n\n");
- segfault();
- };
+ exit(-1);
+ };
- virtual chillAST_node *findref(){// find the SINGLE constant or data reference at this node or below
- fprintf(stderr,"(%s) forgot to implement findref()\n" ,Chill_AST_Node_Names[asttype]);
+ virtual chillAST_node *findref() {// find the SINGLE constant or data reference at this node or below
+ CHILL_ERROR("(%s) forgot to implement findref()\n", Chill_AST_Node_Names[asttype]);
dump();
print();
- fprintf(stderr, "\n\n");
- segfault();
+ exit(-1);
};
- virtual void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
- fprintf(stderr,"(%s) forgot to implement gatherArrayRefs()\n" ,Chill_AST_Node_Names[asttype]);
+ virtual void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {
+ CHILL_ERROR("(%s) forgot to implement gatherArrayRefs()\n", Chill_AST_Node_Names[asttype]);
dump();
print();
- fprintf(stderr, "\n\n");
+ exit(-1);
};
-
+
// TODO we MIGHT want the VarDecl // NOTHING IMPLEMENTS THIS? ???
- virtual void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- fprintf(stderr,"(%s) forgot to implement gatherScalarRefs()\n" ,Chill_AST_Node_Names[asttype]);
+ virtual void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ CHILL_ERROR("(%s) forgot to implement gatherScalarRefs()\n", Chill_AST_Node_Names[asttype]);
dump();
print();
- fprintf(stderr, "\n\n");
+ exit(-1);
};
-
- virtual void gatherLoopIndeces( std::vector<chillAST_VarDecl*> &indeces ) { // recursive walk parent links, looking for loops, and grabbing the declRefExpr in the loop init and cond.
- // you can quit when you get to certain nodes
- //fprintf(stderr, "%s::gatherLoopIndeces()\n", getTypeString());
-
- if (isSourceFile() || isFunctionDecl() ) return; // end of the line
+ //! recursive walk parent links, looking for loops, and grabbing the declRefExpr in the loop init and cond.
+ virtual void gatherLoopIndeces(
+ std::vector<chillAST_VarDecl *> &indeces) {
+ // you can quit when you get to certain nodes
- // just for debugging
- //if (parent) {
- // fprintf(stderr, "%s has parent of type %s\n", getTypeString(), parent->getTypeString());
- //}
- //else fprintf(stderr, "this %s %p has no parent???\n", getTypeString(), this);
+ CHILL_DEBUG_PRINT("%s::gatherLoopIndeces()\n", getTypeString());
+ if (isSourceFile() || isFunctionDecl()) return; // end of the line
if (!parent) return; // should not happen, but be careful
// for most nodes, this just recurses upwards
- //fprintf(stderr, "%s::gatherLoopIndeces() %p recursing up\n", this);
- parent->gatherLoopIndeces( indeces );
+ parent->gatherLoopIndeces(indeces);
}
-
- chillAST_ForStmt* findContainingLoop() { // recursive walk parent links, looking for loops
- //fprintf(stderr, "%s::findContainingLoop() ", getTypeString());
- //if (parent) fprintf(stderr, "parents is a %s\n", parent->getTypeString());
- //else fprintf(stderr, "no parent\n");
- // do not check SELF type, as we may want to find the loop containing a loop
+ //! recursive walk parent links, looking for loops
+ chillAST_ForStmt *findContainingLoop() {
+ CHILL_DEBUG_PRINT("%s::findContainingLoop() ", getTypeString());
if (!parent) return NULL;
- if (parent->isForStmt()) return (chillAST_ForStmt*)parent;
+ if (parent->isForStmt()) return (chillAST_ForStmt *) parent;
return parent->findContainingLoop(); // recurse upwards
}
- chillAST_node* findContainingNonLoop() { // recursive walk parent links, avoiding loops
- fprintf(stderr, "%s::findContainingNonLoop() ", getTypeString());
- //if (parent) fprintf(stderr, "parent is a %s\n", parent->getTypeString());
- //else fprintf(stderr, "no parent\n");
- // do not check SELF type, as we may want to find the loop containing a loop
+ //! recursive walk parent links, avoiding loops
+ chillAST_node *findContainingNonLoop() {
+ fprintf(stderr, "%s::findContainingNonLoop() ", getTypeString());
if (!parent) return NULL;
- if (parent->isCompoundStmt() && parent->getParent()->isForStmt()) return parent->getParent()->findContainingNonLoop(); // keep recursing
+ if (parent->isCompoundStmt() && parent->getParent()->isForStmt())
+ return parent->getParent()->findContainingNonLoop(); // keep recursing
if (parent->isForStmt()) return parent->findContainingNonLoop(); // keep recursing
- return (chillAST_node*)parent; // return non-loop
+ return (chillAST_node *) parent; // return non-loop
}
// TODO gather loop init and cond (and if cond) like gatherloopindeces
- virtual void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs ){ // both scalar and arrays
- fprintf(stderr,"(%s) forgot to implement gatherDeclRefExpr()\n" ,Chill_AST_Node_Names[asttype]);
+ virtual void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) { // both scalar and arrays
+ fprintf(stderr, "(%s) forgot to implement gatherDeclRefExpr()\n", Chill_AST_Node_Names[asttype]);
};
+ virtual void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {
+ fprintf(stderr, "(%s) forgot to implement gatherVarUsage()\n", Chill_AST_Node_Names[asttype]);
+ };
- virtual void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ) {
- fprintf(stderr,"(%s) forgot to implement gatherVarUsage()\n" ,Chill_AST_Node_Names[asttype]);
- };
-
- virtual void gatherVarLHSUsage( std::vector<chillAST_VarDecl*> &decls ) {
- fprintf(stderr,"(%s) forgot to implement gatherVarLHSUsage()\n" ,Chill_AST_Node_Names[asttype]);
- };
+ virtual void gatherVarLHSUsage(std::vector<chillAST_VarDecl *> &decls) {
+ fprintf(stderr, "(%s) forgot to implement gatherVarLHSUsage()\n", Chill_AST_Node_Names[asttype]);
+ };
+ //! ACTUAL Declaration
+ virtual void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {
+ fprintf(stderr, "(%s) forgot to implement gatherVarDecls()\n", Chill_AST_Node_Names[asttype]);
+ };
- virtual void gatherVarDecls( std::vector<chillAST_VarDecl*> &decls ) { // ACTUAL Declaration
- fprintf(stderr,"(%s) forgot to implement gatherVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
- };
-
- virtual void gatherVarDeclsMore( std::vector<chillAST_VarDecl*> &decls ) { // even if the decl itself is not in the ast.
- fprintf(stderr,"(%s) forgot to implement gatherVarDeclsMore()\n" ,Chill_AST_Node_Names[asttype]);
- };
+ virtual void
+ gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { // even if the decl itself is not in the ast.
+ fprintf(stderr, "(%s) forgot to implement gatherVarDeclsMore()\n", Chill_AST_Node_Names[asttype]);
+ };
- virtual void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls ) { // ACTUAL Declaration
- fprintf(stderr,"(%s) forgot to implement gatherScalarVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
- };
+ virtual void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) { // ACTUAL Declaration
+ fprintf(stderr, "(%s) forgot to implement gatherScalarVarDecls()\n", Chill_AST_Node_Names[asttype]);
+ };
- virtual void gatherArrayVarDecls( std::vector<chillAST_VarDecl*> &decls ) { // ACTUAL Declaration
- fprintf(stderr,"(%s) forgot to implement gatherArrayVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
- };
+ virtual void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) { // ACTUAL Declaration
+ fprintf(stderr, "(%s) forgot to implement gatherArrayVarDecls()\n", Chill_AST_Node_Names[asttype]);
+ };
- virtual chillAST_VarDecl *findArrayDecl( const char *name ) { // scoping TODO
- if (!hasSymbolTable()) return parent->findArrayDecl( name ); // most things
+ virtual chillAST_VarDecl *findArrayDecl(const char *name) { // scoping TODO
+ if (!hasSymbolTable()) return parent->findArrayDecl(name); // most things
else
- fprintf(stderr,"(%s) forgot to implement gatherArrayVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
+ fprintf(stderr, "(%s) forgot to implement gatherArrayVarDecls()\n", Chill_AST_Node_Names[asttype]);
}
- virtual void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
- fprintf(stderr,"(%s) forgot to implement replaceVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
- };
+ virtual void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ fprintf(stderr, "(%s) forgot to implement replaceVarDecls()\n", Chill_AST_Node_Names[asttype]);
+ };
- virtual bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ) {
- // this just looks for ForStmts with preferred index metacomment attached
- fprintf(stderr,"(%s) forgot to implement findLoopIndexesToReplace()\n" ,Chill_AST_Node_Names[asttype]);
- return false;
+ //! this just looks for ForStmts with preferred index metacomment attached
+ virtual bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) {
+ fprintf(stderr, "(%s) forgot to implement findLoopIndexesToReplace()\n", Chill_AST_Node_Names[asttype]);
+ return false;
}
-
- virtual chillAST_node* constantFold() { // hacky. TODO. make nice
- fprintf(stderr,"(%s) forgot to implement constantFold()\n" ,Chill_AST_Node_Names[asttype]);
- exit(-1); ;
+
+ virtual chillAST_node *constantFold() { // hacky. TODO. make nice
+ CHILL_ERROR("(%s) forgot to implement constantFold()\n", Chill_AST_Node_Names[asttype]);
+ exit(-1);;
};
- virtual chillAST_node* clone() { // makes a deep COPY (?)
- fprintf(stderr,"(%s) forgot to implement clone()\n" ,Chill_AST_Node_Names[asttype]);
- exit(-1); ;
+ virtual chillAST_node *clone() { // makes a deep COPY (?)
+ CHILL_ERROR("(%s) forgot to implement clone()\n", Chill_AST_Node_Names[asttype]);
+ exit(-1);;
};
- virtual void dump( int indent=0, FILE *fp = stderr ) {
- fflush(fp);
- fprintf(fp,"(%s) forgot to implement dump()\n" ,Chill_AST_Node_Names[asttype]); };// print ast
-
- virtual void print( int indent=0, FILE *fp = stderr ) {
- fflush(fp);
- //fprintf(stderr, "generic chillAST_node::print() called!\n");
- //fprintf(stderr, "asttype is %d\n", asttype);
+
+ //! Print AST
+ virtual void dump(int indent = 0, FILE *fp = stderr) {
+ fflush(fp);
+ CHILL_ERROR("(%s) forgot to implement dump()\n", Chill_AST_Node_Names[asttype]);
+ };// print ast
+
+ // TODO We might want to print the code a bit differently, This can be only a generic dump
+ //! Print CODE
+ virtual void print(int indent = 0, FILE *fp = stderr) {
+ fflush(fp);
fprintf(fp, "\n");
- chillindent(indent, fp);
- fprintf(fp,"(%s) forgot to implement print()\n" ,Chill_AST_Node_Names[asttype]);
- };// print CODE
-
- virtual void printName( int indent=0, FILE *fp = stderr ) {
- fflush(fp);
- //fprintf(stderr, "generic chillAST_node::printName() called!\n");
- //fprintf(stderr, "asttype is %d\n", asttype);
+ chillindent(indent, fp);
+ fprintf(fp, "(%s) forgot to implement print()\n", Chill_AST_Node_Names[asttype]);
+ };
+
+ virtual void printName(int indent = 0, FILE *fp = stderr) {
+ fflush(fp);
fprintf(fp, "\n");
- chillindent(indent, fp);
- fprintf(fp,"(%s) forgot to implement printName()\n" ,Chill_AST_Node_Names[asttype]);
+ chillindent(indent, fp);
+ fprintf(fp, "(%s) forgot to implement printName()\n", Chill_AST_Node_Names[asttype]);
};// print CODE
- virtual char *stringRep(int indent=0 ) { // the ast's print version
+ //! The AST's print version
+ virtual char *stringRep(int indent = 0) {
fflush(stdout);
- // chillindent(indent, fp); TODO
- fprintf(stderr,"(%s) forgot to implement stringRep()\n" ,Chill_AST_Node_Names[asttype]);
- segfault();
+ // TODO chillindent(indent, fp);
+ CHILL_ERROR("(%s) forgot to implement stringRep()\n", Chill_AST_Node_Names[asttype]);
+ exit(-1);
}
- virtual void printonly( int indent=0, FILE *fp = stderr ) { print( indent, fp); };
+ virtual void printonly(int indent = 0, FILE *fp = stderr) { print(indent, fp); };
- //virtual void printString( std::string &s ) {
+ //virtual void printString( std::string &s ) {
// fprintf(stderr,"(%s) forgot to implement printString()\n" ,Chill_AST_Node_Names[asttype]);
//}
- virtual void get_top_level_loops( std::vector<chillAST_ForStmt *> &loops) {
- int n = children.size();
+ virtual void get_top_level_loops(std::vector<chillAST_ForStmt *> &loops) {
+ int n = children.size();
//fprintf(stderr, "get_top_level_loops of a %s with %d children\n", getTypeString(), n);
- for (int i=0; i<n; i++) {
+ for (int i = 0; i < n; i++) {
//fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString());
if (children[i]->isForStmt()) {
- loops.push_back( ((chillAST_ForStmt *)(children[i])) );
+ loops.push_back(((chillAST_ForStmt *) (children[i])));
}
}
//fprintf(stderr, "found %d top level loops\n", loops.size());
@@ -373,128 +412,142 @@ public:
virtual void repairParentChild() { // for nodes where all subnodes are children
- int n = children.size();
- for (int i=0; i<n; i++) {
- if (children[i]->parent != this) {
- fprintf(stderr, "fixing child %s that didn't know its parent\n", children[i]->getTypeString());
- children[i]->parent = this;
+ int n = children.size();
+ for (int i = 0; i < n; i++) {
+ if (children[i]->parent != this) {
+ fprintf(stderr, "fixing child %s that didn't know its parent\n", children[i]->getTypeString());
+ children[i]->parent = this;
}
}
}
-
- virtual void get_deep_loops( std::vector<chillAST_ForStmt *> &loops) { // this is probably broken - returns ALL loops under it
- int n = children.size();
+ virtual void
+ get_deep_loops(std::vector<chillAST_ForStmt *> &loops) { // this is probably broken - returns ALL loops under it
+ int n = children.size();
//fprintf(stderr, "get_deep_loops of a %s with %d children\n", getTypeString(), n);
- for (int i=0; i<n; i++) {
+ for (int i = 0; i < n; i++) {
//fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString());
- children[i]->get_deep_loops( loops );
+ children[i]->get_deep_loops(loops);
}
//fprintf(stderr, "found %d deep loops\n", loops.size());
}
// generic for chillAST_node with children
- virtual void find_deepest_loops( std::vector<chillAST_ForStmt *> &loops) { // returns DEEPEST nesting of loops
- std::vector<chillAST_ForStmt *>deepest; // deepest below here
-
- int n = children.size();
+ virtual void find_deepest_loops(std::vector<chillAST_ForStmt *> &loops) { // returns DEEPEST nesting of loops
+ std::vector<chillAST_ForStmt *> deepest; // deepest below here
+
+ int n = children.size();
//fprintf(stderr, "find_deepest_loops of a %s with %d children\n", getTypeString(), n);
- for (int i=0; i<n; i++) {
+ for (int i = 0; i < n; i++) {
std::vector<chillAST_ForStmt *> subloops; // loops below here among a child of mine
-
+
//fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString());
- children[i]->find_deepest_loops( subloops );
-
- if (subloops.size() > deepest.size()) {
+ children[i]->find_deepest_loops(subloops);
+
+ if (subloops.size() > deepest.size()) {
deepest = subloops;
}
}
-
+
// append deepest we see at this level to loops
- for ( int i=0; i<deepest.size(); i++) {
- loops.push_back( deepest[i] );
+ for (int i = 0; i < deepest.size(); i++) {
+ loops.push_back(deepest[i]);
}
//fprintf(stderr, "found %d deep loops\n", loops.size());
-
+
}
+ const char *getTypeString() { return Chill_AST_Node_Names[asttype]; };
+
+ int getType() { return asttype; };
+
+ void setParent(chillAST_node *p) { parent = p; };
+ chillAST_node *getParent() { return parent; };
- const char *getTypeString() { return Chill_AST_Node_Names[asttype]; } ;
- int getType() { return asttype; };
- void setParent( chillAST_node *p) { parent = p; } ;
- chillAST_node *getParent() { return parent; } ;
-
- chillAST_SourceFile *getSourceFile() {
- if (isSourceFile()) return ((chillAST_SourceFile *)this);
- if (parent != NULL) return parent->getSourceFile();
- fprintf(stderr, "UHOH, getSourceFile() called on node %p %s that does not have a parent and is not a source file\n", this, this->getTypeString());
- this->print(); printf("\n\n"); fflush(stdout);
+ chillAST_SourceFile *getSourceFile() {
+ if (isSourceFile()) return ((chillAST_SourceFile *) this);
+ if (parent != NULL) return parent->getSourceFile();
+ fprintf(stderr, "UHOH, getSourceFile() called on node %p %s that does not have a parent and is not a source file\n",
+ this, this->getTypeString());
+ this->print();
+ printf("\n\n");
+ fflush(stdout);
exit(-1);
}
-
- virtual chillAST_node *findDatatype( char *t ) {
- fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
+
+ virtual chillAST_node *findDatatype(char *t) {
+ fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
if (parent != NULL) return parent->findDatatype(t); // most nodes do this
- return NULL;
+ return NULL;
}
- virtual chillAST_SymbolTable *addVariableToSymbolTable( chillAST_VarDecl *vd ) {
- if (!parent) {
- fprintf(stderr, "%s with no parent addVariableToSymbolTable()\n", getTypeString());
+ virtual chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) {
+ if (!parent) {
+ fprintf(stderr, "%s with no parent addVariableToSymbolTable()\n", getTypeString());
exit(-1);
}
//fprintf(stderr, "%s::addVariableToSymbolTable() (default) headed up\n", getTypeString());
- return parent->addVariableToSymbolTable( vd ); // default, defer to parent
+ return parent->addVariableToSymbolTable(vd); // default, defer to parent
}
- virtual void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) {
- parent->addTypedefToTypedefTable( tdd ); // default, defer to parent
+ virtual void addTypedefToTypedefTable(chillAST_TypedefDecl *tdd) {
+ parent->addTypedefToTypedefTable(tdd); // default, defer to parent
}
- void walk_parents() {
- fprintf(stderr, "wp: (%s) ", getTypeString());
- print(); printf("\n"); fflush(stdout);
- if (isSourceFile()) { fprintf(stderr, "(top sourcefile)\n\n"); return;}
+ void walk_parents() {
+ fprintf(stderr, "wp: (%s) ", getTypeString());
+ print();
+ printf("\n");
+ fflush(stdout);
+ if (isSourceFile()) {
+ fprintf(stderr, "(top sourcefile)\n\n");
+ return;
+ }
if (parent) parent->walk_parents();
else fprintf(stderr, "UHOH, %s has no parent??\n", getTypeString());
- return;
+ return;
}
- virtual chillAST_node *getEnclosingStatement( int level = 0 );
- virtual chillAST_VarDecl *multibase() {
- fprintf(stderr,"(%s) forgot to implement multibase()\n", Chill_AST_Node_Names[asttype]);
+ virtual chillAST_node *getEnclosingStatement(int level = 0);
+
+ virtual chillAST_VarDecl *multibase() {
+ fprintf(stderr, "(%s) forgot to implement multibase()\n", Chill_AST_Node_Names[asttype]);
exit(-1);
}
- virtual chillAST_node *multibase2() {
- fprintf(stderr,"(%s) forgot to implement multibase2()\n", Chill_AST_Node_Names[asttype]);
+
+ virtual chillAST_node *multibase2() {
+ fprintf(stderr, "(%s) forgot to implement multibase2()\n", Chill_AST_Node_Names[asttype]);
exit(-1);
}
-
- virtual void gatherStatements( std::vector<chillAST_node*> &statements ) {
- fprintf(stderr,"(%s) forgot to implement gatherStatements()\n" ,Chill_AST_Node_Names[asttype]);
- dump();fflush(stdout);
+
+ virtual void gatherStatements(std::vector<chillAST_node *> &statements) {
+ fprintf(stderr, "(%s) forgot to implement gatherStatements()\n", Chill_AST_Node_Names[asttype]);
+ dump();
+ fflush(stdout);
print();
- fprintf(stderr, "\n\n");
+ fprintf(stderr, "\n\n");
}
- virtual bool isSameAs( chillAST_node *other ){ // for tree comparison
- fprintf(stderr,"(%s) forgot to implement isSameAs()\n" ,Chill_AST_Node_Names[asttype]);
- dump(); fflush(stdout);
+ virtual bool isSameAs(chillAST_node *other) { // for tree comparison
+ fprintf(stderr, "(%s) forgot to implement isSameAs()\n", Chill_AST_Node_Names[asttype]);
+ dump();
+ fflush(stdout);
print();
- fprintf(stderr, "\n\n"); }
+ fprintf(stderr, "\n\n");
+ }
- void printPreprocBEFORE( int indent, FILE *fp );
- void printPreprocAFTER( int indent, FILE *fp );
+ void printPreprocBEFORE(int indent, FILE *fp);
+ void printPreprocAFTER(int indent, FILE *fp);
};
diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh
index 228cf3f..c7d13dd 100644
--- a/include/chillAST/chillASTs.hh
+++ b/include/chillAST/chillASTs.hh
@@ -6,22 +6,28 @@
#include "chillAST_def.hh"
#include "chillAST_node.hh"
-class chillAST_NULL: public chillAST_node { // NOOP?
+class chillAST_NULL : public chillAST_node { // NOOP?
public:
- chillAST_NULL(chillAST_node *p = NULL) { parent = p; asttype = CHILLAST_NODETYPE_NULL; };
- void print( int indent=0, FILE *fp = stderr ) {
- chillindent( indent, fp );
+ chillAST_NULL(chillAST_node *p = NULL) {
+ parent = p;
+ asttype = CHILLAST_NODETYPE_NULL;
+ };
+
+ void print(int indent = 0, FILE *fp = stderr) {
+ chillindent(indent, fp);
fprintf(fp, "/* (NULL statement); */ ");
fflush(fp);
}
- void dump( int indent=0, FILE *fp = stderr ) {
- chillindent( indent, fp );
- fprintf(fp, "(NULL statement) "); fflush(fp);
+
+ void dump(int indent = 0, FILE *fp = stderr) {
+ chillindent(indent, fp);
+ fprintf(fp, "(NULL statement) ");
+ fflush(fp);
}
};
-
-class chillAST_Preprocessing: public chillAST_node {
+
+class chillAST_Preprocessing : public chillAST_node {
public:
// variables that are special for this type of node
CHILL_PREPROCESSING_POSITION position;
@@ -30,18 +36,18 @@ public:
// constructors
chillAST_Preprocessing(); // not sure what this is good for
- chillAST_Preprocessing( CHILL_PREPROCESSING_POSITION pos, CHILL_PREPROCESSING_TYPE t, char *text );
-
+ chillAST_Preprocessing(CHILL_PREPROCESSING_POSITION pos, CHILL_PREPROCESSING_TYPE t, char *text);
+
// other methods particular to this type of node
-
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
//void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
-};
+};
//typedef is a keyword in the C and C++ programming languages. The purpose of typedef is to assign alternative names to existing types, most often those whose standard declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another.
-class chillAST_TypedefDecl: public chillAST_node {
+class chillAST_TypedefDecl : public chillAST_node {
private:
bool isStruct;
bool isUnion;
@@ -54,53 +60,72 @@ public:
chillAST_RecordDecl *rd; // if it's a struct, point to the recorddecl ??
// TODO what if "typedef int[10] tenints; " ??
- void setStructInfo( chillAST_RecordDecl *arrdee ) { rd = arrdee; };
- chillAST_RecordDecl * getStructDef();
+ void setStructInfo(chillAST_RecordDecl *arrdee) { rd = arrdee; };
+
+ chillAST_RecordDecl *getStructDef();
- bool isAStruct() { return isStruct; };
- bool isAUnion() { return isUnion; };
- void setStruct(bool tf) { isStruct = tf; fprintf(stderr, "%s isStruct %d\n", structname, isStruct); };
- void setUnion( bool tf) { isUnion = tf; };
- void setStructName( const char *newname) { structname = strdup(newname); };
- char *getStructName( ) { return structname; };
- bool nameis( const char *n ) { return !strcmp(n, structname); };
+ bool isAStruct() { return isStruct; };
+
+ bool isAUnion() { return isUnion; };
+
+ void setStruct(bool tf) {
+ isStruct = tf;
+ fprintf(stderr, "%s isStruct %d\n", structname, isStruct);
+ };
+
+ void setUnion(bool tf) { isUnion = tf; };
+
+ void setStructName(const char *newname) { structname = strdup(newname); };
+
+ char *getStructName() { return structname; };
+
+ bool nameis(const char *n) { return !strcmp(n, structname); };
// special for struct/unions rethink TODO
std::vector<chillAST_VarDecl *> subparts;
- chillAST_VarDecl *findSubpart( const char *name );
+
+ chillAST_VarDecl *findSubpart(const char *name);
//TODO hide data, set/get type and alias
chillAST_TypedefDecl();
+
chillAST_TypedefDecl(char *t, const char *nt, chillAST_node *p);
+
chillAST_TypedefDecl(char *t, const char *nt, char *a, chillAST_node *par);
-
- const char* getUnderlyingType() { fprintf(stderr, "TypedefDecl getUnderLyingType()\n"); return underlyingtype; };
+
+ const char *getUnderlyingType() {
+ fprintf(stderr, "TypedefDecl getUnderLyingType()\n");
+ return underlyingtype;
+ };
//virtual chillAST_VarDecl* getUnderlyingVarDecl() { return this; }; // ??
- void dump( int indent=0, FILE *fp = stderr ) {
- fprintf(fp, "(TypedefDecl %s %s %s)\n", underlyingtype, newtype, arraypart); };
- void print( int indent=0, FILE *fp = stderr ) ;
+ void dump(int indent = 0, FILE *fp = stderr) {
+ fprintf(fp, "(TypedefDecl %s %s %s)\n", underlyingtype, newtype, arraypart);
+ };
+
+ void print(int indent = 0, FILE *fp = stderr);
//void printString( std::string &s );
};
-class chillAST_VarDecl: public chillAST_node {
+class chillAST_VarDecl : public chillAST_node {
public:
char *vartype; // should probably be an enum, except it's used for unnamed structs too
- chillAST_RecordDecl *vardef;// the thing that says what the struct looks like
+ chillAST_RecordDecl *vardef;// the thing that says what the struct looks like
chillAST_TypedefDecl *typedefinition; // NULL for float, int, etc.
- chillAST_RecordDecl * getStructDef(); // TODO make vardef private?
+ chillAST_RecordDecl *getStructDef(); // TODO make vardef private?
//bool insideAStruct; // this variable is itself part of a struct
-
+
char *underlyingtype;
char *varname;
char *arraypart; // [ 12 ] [ 34 ] if that is how it was defined
char *arraypointerpart;
- char *arraysetpart;
+ char *arraysetpart;
+
void splitarraypart();
int numdimensions;
@@ -111,142 +136,188 @@ public:
bool isRestrict; // C++ __restrict__
bool isShared; // CUDA __shared__
bool isDevice; // CUDA __device__
- bool isStruct;
-
- int isAParameter;
+ bool isStruct;
+
+ int isAParameter;
bool byreference;
- void setByReference( bool tf ) { byreference = tf; fprintf(stderr, "byref %d\n", tf); };
+
+ void setByReference(bool tf) {
+ byreference = tf;
+ fprintf(stderr, "byref %d\n", tf);
+ };
bool isABuiltin; // if variable is builtin, we don't need to declare it
void *uniquePtr; // DO NOT REFERENCE THROUGH THIS! just used to differentiate declarations
- bool isArray() { return (numdimensions != 0); };
+ bool isArray() { return (numdimensions != 0); };
+
bool isAStruct() { return (isStruct || (typedefinition && typedefinition->isAStruct())); }
- void setStruct( bool b ) {isStruct = b;/*fprintf(stderr,"vardecl %s IS A STRUCT\n",varname);*/ };
- bool isPointer() { return isArray() && !knownArraySizes; } //
- bool knowAllDimensions() { return knownArraySizes; } ;
+ void setStruct(bool b) { isStruct = b;/*fprintf(stderr,"vardecl %s IS A STRUCT\n",varname);*/ };
+
+ bool isPointer() { return isArray() && !knownArraySizes; } //
+
+ bool knowAllDimensions() { return knownArraySizes; };
chillAST_node *init;
- void setInit( chillAST_node *i ) { init = i; i->setParent(this); };
+
+ void setInit(chillAST_node *i) {
+ init = i;
+ i->setParent(this);
+ };
+
bool hasInit() { return init != NULL; };
+
chillAST_node *getInit() { return init; };
-
+
chillAST_VarDecl();
- chillAST_VarDecl( const char *t, const char *n, const char *a, chillAST_node *p);
- chillAST_VarDecl( const char *t, const char *n, const char *a, void *ptr, chillAST_node *p);
- chillAST_VarDecl( chillAST_TypedefDecl *tdd, const char *n, const char *arraypart, chillAST_node *par);
- chillAST_VarDecl( chillAST_RecordDecl *astruct, const char *n, const char *arraypart, chillAST_node *par);
-
- void dump( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr );
- void printName( int indent=0, FILE *fp = stderr );
- bool isParmVarDecl() { return( isAParameter == 1 ); };
- bool isBuiltin() { return( isABuiltin == 1 ); }; // designate variable as a builtin
- void setLocation( void *ptr ) { uniquePtr = ptr; } ;
-
-
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
-
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs ) {}; // does nothing
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- const char* getUnderlyingType() { /* fprintf(stderr, "VarDecl getUnderLyingType()\n"); */return underlyingtype; };
- virtual chillAST_VarDecl* getUnderlyingVarDecl() { return this; };
-
- chillAST_node* constantFold();
- chillAST_node* clone();
+
+ chillAST_VarDecl(const char *t, const char *n, const char *a, chillAST_node *p);
+
+ chillAST_VarDecl(const char *t, const char *n, const char *a, void *ptr, chillAST_node *p);
+
+ chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, const char *arraypart, chillAST_node *par);
+
+ chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *n, const char *arraypart, chillAST_node *par);
+
+ void dump(int indent = 0, FILE *fp = stderr);
+
+ void print(int indent = 0, FILE *fp = stderr);
+
+ void printName(int indent = 0, FILE *fp = stderr);
+
+ bool isParmVarDecl() { return (isAParameter == 1); };
+
+ bool isBuiltin() { return (isABuiltin == 1); }; // designate variable as a builtin
+ void setLocation(void *ptr) { uniquePtr = ptr; };
+
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) {}; // does nothing
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ const char *getUnderlyingType() { /* fprintf(stderr, "VarDecl getUnderLyingType()\n"); */return underlyingtype; };
+
+ virtual chillAST_VarDecl *getUnderlyingVarDecl() { return this; };
+
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
};
-class chillAST_DeclRefExpr: public chillAST_node {
+class chillAST_DeclRefExpr : public chillAST_node {
public:
// variables that are special for this type of node
- char *declarationType;
- char *declarationName;
+ char *declarationType;
+ char *declarationName;
chillAST_node *decl; // the declaration of this variable or function ... uhoh
//char *functionparameters; // TODO probably should split this node into 2 types, one for variables, one for functions
// constructors
- chillAST_DeclRefExpr();
- chillAST_DeclRefExpr( const char *variablename, chillAST_node *p);
- chillAST_DeclRefExpr( const char *vartype, const char *variablename, chillAST_node *p);
- chillAST_DeclRefExpr( const char *vartype, const char *variablename, chillAST_node *dec, chillAST_node *p);
- chillAST_DeclRefExpr( chillAST_VarDecl *vd, chillAST_node *p=NULL);
- chillAST_DeclRefExpr( chillAST_FunctionDecl *fd, chillAST_node *p=NULL);
-
+ chillAST_DeclRefExpr();
+
+ chillAST_DeclRefExpr(const char *variablename, chillAST_node *p);
+
+ chillAST_DeclRefExpr(const char *vartype, const char *variablename, chillAST_node *p);
+
+ chillAST_DeclRefExpr(const char *vartype, const char *variablename, chillAST_node *dec, chillAST_node *p);
+
+ chillAST_DeclRefExpr(chillAST_VarDecl *vd, chillAST_node *p = NULL);
+
+ chillAST_DeclRefExpr(chillAST_FunctionDecl *fd, chillAST_node *p = NULL);
+
// other methods particular to this type of node
- bool operator!=( chillAST_DeclRefExpr &other ) { return decl != other.decl ; };
- bool operator==( chillAST_DeclRefExpr &other ) { return decl == other.decl ; }; // EXACT SAME VARECL BY ADDRESS
-
+ bool operator!=(chillAST_DeclRefExpr &other) { return decl != other.decl; };
+
+ bool operator==(chillAST_DeclRefExpr &other) { return decl == other.decl; }; // EXACT SAME VARECL BY ADDRESS
+
chillAST_node *getDecl() { return decl; };
- chillAST_VarDecl *getVarDecl() {
+ chillAST_VarDecl *getVarDecl() {
if (!decl) return NULL; // should never happen
- if (decl->isVarDecl()) return (chillAST_VarDecl *)decl;
- return NULL;
- };
-
- chillAST_FunctionDecl *getFunctionDecl() {
+ if (decl->isVarDecl()) return (chillAST_VarDecl *) decl;
+ return NULL;
+ };
+
+ chillAST_FunctionDecl *getFunctionDecl() {
if (!decl) return NULL; // should never happen
- if (decl->isFunctionDecl()) return (chillAST_FunctionDecl *)decl;
- return NULL;
- };
-
+ if (decl->isFunctionDecl()) return (chillAST_FunctionDecl *) decl;
+ return NULL;
+ };
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE
- void dump( int indent=0, FILE *fp = stderr ); // print ast
- char *stringRep(int indent=0 );
+ void print(int indent = 0, FILE *fp = stderr); // print CODE
+ void dump(int indent = 0, FILE *fp = stderr); // print ast
+ char *stringRep(int indent = 0);
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {}; // do nothing
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento );
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {}; // do nothing
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
// this is the AST node where these 2 differ
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing, to get the cvardecl using this method, the actual vardecl must be in the AST
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ); // returns the decl this declrefexpr references, even if the decl is not in the AST
+ void gatherVarDecls(
+ std::vector<chillAST_VarDecl *> &decls) {}; // does nothing, to get the cvardecl using this method, the actual vardecl must be in the AST
+ void gatherVarDeclsMore(
+ std::vector<chillAST_VarDecl *> &decls); // returns the decl this declrefexpr references, even if the decl is not in the AST
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- chillAST_node *findref(){return this;}// find the SINGLE constant or data reference at this node or below
-
- const char* getUnderlyingType() {fprintf(stderr, "DeclRefExpr getUnderLyingType()\n"); return decl->getUnderlyingType();};
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
- virtual chillAST_VarDecl* getUnderlyingVarDecl() { return decl->getUnderlyingVarDecl(); } // functions?? TODO
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
- chillAST_VarDecl* multibase();
- chillAST_node *multibase2() { return (chillAST_node *)multibase(); }
-};
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ chillAST_node *findref() { return this; }// find the SINGLE constant or data reference at this node or below
+ const char *getUnderlyingType() {
+ fprintf(stderr, "DeclRefExpr getUnderLyingType()\n");
+ return decl->getUnderlyingType();
+ };
+ virtual chillAST_VarDecl *getUnderlyingVarDecl() { return decl->getUnderlyingVarDecl(); } // functions?? TODO
-class chillAST_CompoundStmt: public chillAST_node {
+ chillAST_VarDecl *multibase();
+
+ chillAST_node *multibase2() { return (chillAST_node *) multibase(); }
+};
+
+
+class chillAST_CompoundStmt : public chillAST_node {
public:
// variables that are special for this type of node
- chillAST_SymbolTable *symbol_table; // symbols defined inside this compound statement
+ chillAST_SymbolTable *symbol_table; // symbols defined inside this compound statement
chillAST_TypedefTable *typedef_table;
- bool hasSymbolTable() { return true; } ;
- bool hasTypeDefTable() { return true; } ;
- chillAST_node *findDatatype( char *t ) {
- fprintf(stderr, "chillAST_CompoundStmt::findDatatype( %s )\n", t);
- if (typedef_table) {
- for (int i=0; i< typedef_table->size(); i++) {
+ bool hasSymbolTable() { return true; };
+
+ bool hasTypeDefTable() { return true; };
+
+ chillAST_node *findDatatype(char *t) {
+ fprintf(stderr, "chillAST_CompoundStmt::findDatatype( %s )\n", t);
+ if (typedef_table) {
+ for (int i = 0; i < typedef_table->size(); i++) {
chillAST_TypedefDecl *tdd = (*typedef_table)[i];
- if (tdd->nameis( t )) return tdd;
+ if (tdd->nameis(t)) return tdd;
}
}
if (parent) return parent->findDatatype(t);
@@ -255,106 +326,125 @@ public:
chillAST_SymbolTable *getSymbolTable() { return symbol_table; }
- chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_CompoundStmt method
+ chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_CompoundStmt method
//fprintf(stderr, "\nchillAST_CompoundStmt addVariableToSymbolTable( %s )\n", vd->varname);
- symbol_table = addSymbolToTable( symbol_table, vd );
+ symbol_table = addSymbolToTable(symbol_table, vd);
//printSymbolTable( symbol_table );
return symbol_table;
}
- void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) {
- typedef_table = addTypedefToTable( typedef_table, tdd );
+ void addTypedefToTypedefTable(chillAST_TypedefDecl *tdd) {
+ typedef_table = addTypedefToTable(typedef_table, tdd);
}
// constructors
chillAST_CompoundStmt(); // never has any args ???
-
+
// other methods particular to this type of node
-
-
+
+
// required methods
- void replaceChild( chillAST_node *old, chillAST_node *newchild );
- void dump( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr );
- chillAST_node* constantFold();
- chillAST_node* clone();
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void dump(int indent = 0, FILE *fp = stderr);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false );
- void loseLoopWithLoopVar( char *var ); // special case this for not for debugging
+ chillAST_node *constantFold();
- void gatherStatements( std::vector<chillAST_node*> &statements );
-};
+ chillAST_node *clone();
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
-class chillAST_RecordDecl: public chillAST_node { // declaration of the shape of a struct or union
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false);
+
+ void loseLoopWithLoopVar(char *var); // special case this for not for debugging
+
+ void gatherStatements(std::vector<chillAST_node *> &statements);
+};
+
+
+class chillAST_RecordDecl : public chillAST_node { // declaration of the shape of a struct or union
private:
char *name; // could be NULL? for unnamed structs?
- char *originalname;
+ char *originalname;
bool isStruct;
bool isUnion;
std::vector<chillAST_VarDecl *> subparts;
-
+
public:
chillAST_RecordDecl();
- chillAST_RecordDecl( const char *nam, chillAST_node *p );
- chillAST_RecordDecl( const char *nam, const char *orig, chillAST_node *p );
-
- void setName( const char *newname) { name = strdup(newname); };
- char *getName( ) { return name; };
-
- bool isAUnion() { return isUnion; };
- bool isAStruct() { return isStruct; };
+
+ chillAST_RecordDecl(const char *nam, chillAST_node *p);
+
+ chillAST_RecordDecl(const char *nam, const char *orig, chillAST_node *p);
+
+ void setName(const char *newname) { name = strdup(newname); };
+
+ char *getName() { return name; };
+
+ bool isAUnion() { return isUnion; };
+
+ bool isAStruct() { return isStruct; };
bool isUnnamed;
- void setUnnamed( bool b ) { isUnnamed = b; };
-
- void setStruct(bool tf) { isStruct = tf; };
+ void setUnnamed(bool b) { isUnnamed = b; };
+
+
+ void setStruct(bool tf) { isStruct = tf; };
+
//fprintf(stderr, "%s isStruct %d\n", structname, isStruct); };
- void setUnion( bool tf) { isUnion = tf; };
-
- chillAST_SymbolTable *addVariableToSymbolTable( chillAST_VarDecl *vd ); // RecordDecl does NOTHING
-
- int numSubparts() { return subparts.size(); };
- void addSubpart( chillAST_VarDecl *s ) { subparts.push_back(s); };
- chillAST_VarDecl *findSubpart( const char *name );
- chillAST_VarDecl *findSubpartByType( const char *typ );
-
- void dump( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr ) ;
- void printStructure( int indent=0, FILE *fp = stderr ) ;
-};
+ void setUnion(bool tf) { isUnion = tf; };
+ chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd); // RecordDecl does NOTHING
+ int numSubparts() { return subparts.size(); };
+
+ void addSubpart(chillAST_VarDecl *s) { subparts.push_back(s); };
+
+ chillAST_VarDecl *findSubpart(const char *name);
+
+ chillAST_VarDecl *findSubpartByType(const char *typ);
+
+ void dump(int indent = 0, FILE *fp = stderr);
+
+ void print(int indent = 0, FILE *fp = stderr);
+
+ void printStructure(int indent = 0, FILE *fp = stderr);
+};
-class chillAST_FunctionDecl: public chillAST_node {
+class chillAST_FunctionDecl : public chillAST_node {
private:
chillAST_CompoundStmt *body; // always a compound statement?
CHILL_FUNCTION_TYPE function_type; // CHILL_FUNCTION_CPU or CHILL_FUNCTION_GPU
bool externfunc; // function is external
bool builtin; // function is a builtin
- bool forwarddecl;
+ bool forwarddecl;
public:
char *returnType;
char *functionName;
// parameters
- int numParameters() { return parameters.size(); } ;
+ int numParameters() { return parameters.size(); };
chillAST_SymbolTable parameters;
// this is probably a mistake, but symbol_table here is pointing to BODY'S symbol table
@@ -363,201 +453,220 @@ public:
chillAST_TypedefTable *typedef_table; // function typedef table
- bool hasSymbolTable() { return true; } ; // COULD HAVE
- bool hasTypeDefTable(){ return true; } ; // COULD HAVE
+ bool hasSymbolTable() { return true; }; // COULD HAVE
+ bool hasTypeDefTable() { return true; }; // COULD HAVE
//char *parametertypes; // a single string??
- void printParameterTypes( FILE *fp );
- void setName( char *n ) { functionName = strdup(n); /* probable memory leak */ };
+ void printParameterTypes(FILE *fp);
- void setBuiltin() { builtin = true; } ; // designate function as a builtin
- bool isBuiltin() { return builtin; } ; // report whether is a builtin
+ void setName(char *n) { functionName = strdup(n); /* probable memory leak */ };
+
+ void setBuiltin() { builtin = true; }; // designate function as a builtin
+ bool isBuiltin() { return builtin; }; // report whether is a builtin
void setExtern() { externfunc = true; }; // designate function as external
- bool isExtern() { return externfunc; }; // report whether function is external
+ bool isExtern() { return externfunc; }; // report whether function is external
void setForward() { forwarddecl = true; }; // designate function as fwd declaration
- bool isForward() { return forwarddecl; }; // report whether function is external
+ bool isForward() { return forwarddecl; }; // report whether function is external
+
+ bool isFunctionCPU() { return (function_type == CHILL_FUNCTION_CPU); };
+
+ bool isFunctionGPU() { return (function_type == CHILL_FUNCTION_GPU); };
- bool isFunctionCPU() { return( function_type == CHILL_FUNCTION_CPU ); };
- bool isFunctionGPU() { return( function_type == CHILL_FUNCTION_GPU ); };
void setFunctionCPU() { function_type = CHILL_FUNCTION_CPU; };
+
void setFunctionGPU() { function_type = CHILL_FUNCTION_GPU; };
void *uniquePtr; // DO NOT REFERENCE THROUGH THIS! USED AS A UNIQUE ID
-
-
+
+
chillAST_FunctionDecl(); // { asttype = CHILLAST_NODETYPE_FUNCTIONDECL; numparameters = 0;};
- chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *p=NULL ) ;
- chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *p, void *unique ) ;
-
- void addParameter( chillAST_VarDecl *p);
- chillAST_VarDecl *hasParameterNamed( const char *name );
- chillAST_VarDecl *findParameterNamed( const char *name ) { return hasParameterNamed( name ); };
+ chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *p = NULL);
+
+ chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *p, void *unique);
- void addDecl( chillAST_VarDecl *vd); // just adds to symbol table?? TODO
+ void addParameter(chillAST_VarDecl *p);
- chillAST_VarDecl *funcHasVariableNamed( const char *name ); // functiondecl::hasVariableNamed
+ chillAST_VarDecl *hasParameterNamed(const char *name);
+
+ chillAST_VarDecl *findParameterNamed(const char *name) { return hasParameterNamed(name); };
+
+ void addDecl(chillAST_VarDecl *vd); // just adds to symbol table?? TODO
+
+ chillAST_VarDecl *funcHasVariableNamed(const char *name); // functiondecl::hasVariableNamed
//chillAST_VarDecl *findVariableNamed( const char *name ) { return hasVariableNamed( name ); };
- void addChild(chillAST_node* node); // special because inserts into BODY
- void insertChild(int i, chillAST_node* node); // special because inserts into BODY
+ void addChild(chillAST_node *node); // special because inserts into BODY
+ void insertChild(int i, chillAST_node *node); // special because inserts into BODY
+
+ void setBody(chillAST_node *bod);
+
+ chillAST_CompoundStmt *getBody() { return (body); }
+
+ void print(int indent = 0, FILE *fp = stderr); // in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // in chill_ast.cc
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void setBody( chillAST_node * bod );
- chillAST_CompoundStmt *getBody() { return( body); }
-
- void print( int indent=0, FILE *fp = stderr ); // in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // in chill_ast.cc
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- chillAST_VarDecl *findArrayDecl( const char *name );
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ chillAST_VarDecl *findArrayDecl(const char *name);
//void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
//void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento )
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void cleanUpVarDecls();
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void cleanUpVarDecls();
//void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false );
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false);
- chillAST_node* constantFold();
+ chillAST_node *constantFold();
- chillAST_node *findDatatype( char *t ) {
- fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
+ chillAST_node *findDatatype(char *t) {
+ fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
if (!typedef_table) { // not here
if (parent) return parent->findDatatype(t); // not here, check parents
else return NULL; // not defined here and no parent
}
-
+
//fprintf(stderr, "%d typedefs\n", typedef_table->size());
- for (int i=0; i< typedef_table->size(); i++) {
+ for (int i = 0; i < typedef_table->size(); i++) {
chillAST_TypedefDecl *tdd = (*typedef_table)[i];
- if ( tdd->nameis( t )) return tdd;
+ if (tdd->nameis(t)) return tdd;
}
if (parent) return parent->findDatatype(t);
return NULL; // should not happen
}
chillAST_SymbolTable *getParameterSymbolTable() { return &parameters; }
- chillAST_SymbolTable *getSymbolTable() { return body->getSymbolTable(); } //symbol_table; } //
- void setSymbolTable( chillAST_SymbolTable *tab ) {
+
+ chillAST_SymbolTable *getSymbolTable() { return body->getSymbolTable(); } //symbol_table; } //
+ void setSymbolTable(chillAST_SymbolTable *tab) {
// no longer keeping a local ?? symbol_table = tab;
if (!body) { // can never happen now
- body = new chillAST_CompoundStmt();
+ body = new chillAST_CompoundStmt();
} // only if func is empty!
- body->symbol_table = tab;
+ body->symbol_table = tab;
}
- chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_FunctionDecl method
+ chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_FunctionDecl method
//fprintf(stderr, "\nchillAST_FunctionDecl addVariableToSymbolTable( %s )\n", vd->varname);
-
+
// this is all dealing with the body's symbol table
// the function has a symbol table called "parameters" but that is a special case
- addSymbolToTable( getSymbolTable(), vd );
- if (!vd->parent) {
+ addSymbolToTable(getSymbolTable(), vd);
+ if (!vd->parent) {
//fprintf(stderr, "setting parent of vardecl to be the function whose symbol table it is going into\n"); // ??
- vd->setParent( this );
- insertChild(0,vd);
+ vd->setParent(this);
+ insertChild(0, vd);
}
//printSymbolTable( getSymbolTable() );
return getSymbolTable();
}
- void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) {
- typedef_table = addTypedefToTable( typedef_table, tdd );
+ void addTypedefToTypedefTable(chillAST_TypedefDecl *tdd) {
+ typedef_table = addTypedefToTable(typedef_table, tdd);
}
- void replaceChild( chillAST_node *old, chillAST_node *newchild ) {
- body->replaceChild( old, newchild );
+ void replaceChild(chillAST_node *old, chillAST_node *newchild) {
+ body->replaceChild(old, newchild);
}
}; // end FunctionDecl
-class chillAST_SourceFile: public chillAST_node {
+class chillAST_SourceFile : public chillAST_node {
public:
// constructors
chillAST_SourceFile(); // defined in chill_ast.cc
- chillAST_SourceFile(const char *filename ); // defined in chill_ast.cc
+ chillAST_SourceFile(const char *filename); // defined in chill_ast.cc
+
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printToFile(char *filename = NULL);
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printToFile( char *filename = NULL );
-
char *SourceFileName; // where this originated
- char *FileToWrite;
+ char *FileToWrite;
char *frontend;
- void setFileToWrite( char *f ) { FileToWrite = strdup( f ); };
-
- void setFrontend( const char *compiler ) { if (frontend) free(frontend); frontend = strdup(compiler); }
+ void setFileToWrite(char *f) { FileToWrite = strdup(f); };
+
+ void setFrontend(const char *compiler) {
+ if (frontend) free(frontend);
+ frontend = strdup(compiler);
+ }
// get, set filename ?
- chillAST_SymbolTable *global_symbol_table; // (global) symbols defined inside this source file
+ chillAST_SymbolTable *global_symbol_table; // (global) symbols defined inside this source file
chillAST_TypedefTable *global_typedef_table; // source file
- chillAST_VarDecl *findVariableNamed( const char *name ); // looks in global_symbol_table;
+ chillAST_VarDecl *findVariableNamed(const char *name); // looks in global_symbol_table;
- bool hasSymbolTable() { return true; } ; // "has" vs "can have" TODO
- bool hasTypeDefTable() { return true; } ;
+ bool hasSymbolTable() { return true; }; // "has" vs "can have" TODO
+ bool hasTypeDefTable() { return true; };
- chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_SourceFile method
+ chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_SourceFile method
fprintf(stderr, "\nchillAST_SourceFile addVariableToSymbolTable( %s )\n", vd->varname);
- global_symbol_table = addSymbolToTable( global_symbol_table, vd );
+ global_symbol_table = addSymbolToTable(global_symbol_table, vd);
//addChild( vd ); // ??
//printSymbolTable( global_symbol_table );
return global_symbol_table;
}
- void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) {
+ void addTypedefToTypedefTable(chillAST_TypedefDecl *tdd) {
//fprintf(stderr, "SOURCEFILE adding typedef %s to typedeftable\n", tdd->getStructName());
- global_typedef_table = addTypedefToTable( global_typedef_table, tdd );
+ global_typedef_table = addTypedefToTable(global_typedef_table, tdd);
//fprintf(stderr, "now global typedef table has %d entries\n", global_typedef_table->size());
}
- chillAST_node *findDatatype( char *t ) {
- fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
+ chillAST_node *findDatatype(char *t) {
+ fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
fprintf(stderr, "%d global typedefs\n", global_typedef_table->size());
- for (int i=0; i< global_typedef_table->size(); i++) {
-
+ for (int i = 0; i < global_typedef_table->size(); i++) {
+
chillAST_TypedefDecl *tdd = (*global_typedef_table)[i];
//fprintf(stderr, "comparing to %s\n", tdd->getStructName());
- if (tdd->nameis( t )) {
+ if (tdd->nameis(t)) {
//fprintf(stderr, "found it\n");
- return (chillAST_node *)tdd;
+ return (chillAST_node *) tdd;
}
}
return NULL;
}
- std::vector< chillAST_FunctionDecl *> functions; // at top level, or anywhere?
- std::vector< chillAST_MacroDefinition *> macrodefinitions;
+ std::vector<chillAST_FunctionDecl *> functions; // at top level, or anywhere?
+ std::vector<chillAST_MacroDefinition *> macrodefinitions;
- chillAST_MacroDefinition* findMacro( const char *name ); // TODO ignores arguments
- chillAST_FunctionDecl *findFunction( const char *name ); // TODO ignores arguments
- chillAST_node *findCall( const char *name );
- void addMacro(chillAST_MacroDefinition* md) {
+ chillAST_MacroDefinition *findMacro(const char *name); // TODO ignores arguments
+ chillAST_FunctionDecl *findFunction(const char *name); // TODO ignores arguments
+ chillAST_node *findCall(const char *name);
+
+ void addMacro(chillAST_MacroDefinition *md) {
macrodefinitions.push_back(md);
//fprintf(stderr, "addMacro(), now %d macros\n", macrodefinitions.size());
}
- void addFunc(chillAST_FunctionDecl* fd) {
+
+ void addFunc(chillAST_FunctionDecl *fd) {
//fprintf(stderr, "chillAST_SourceFile::addFunc( %s %p)\n", fd->functionName, fd);
- bool already = false;
- for (int i=0; i<functions.size(); i++) {
+ bool already = false;
+ for (int i = 0; i < functions.size(); i++) {
//fprintf(stderr, "function %d is %s %p\n", i, functions[i]->functionName, functions[i]);
- if (functions[i] == fd) {
+ if (functions[i] == fd) {
//fprintf(stderr, "function %s was already in source functions\n", fd->functionName);
already = true;
}
@@ -565,71 +674,88 @@ public:
if (!already) functions.push_back(fd);
// PROBABLY fd was created with sourcefile as its parent. Don't add it twice
- addChild( (chillAST_node *)fd); }
+ addChild((chillAST_node *) fd);
+ }
};
-class chillAST_MacroDefinition: public chillAST_node {
+class chillAST_MacroDefinition : public chillAST_node {
private:
chillAST_node *body; // rhs always a compound statement?
chillAST_SymbolTable *symbol_table;
public:
char *macroName;
- char *rhsString;
+ char *rhsString;
// parameters - these will be odd, in that they HAVE NO TYPE
- int numParameters() { return parameters.size(); } ;
- std::vector<chillAST_VarDecl *>parameters;
-
- void setName( char *n ) { macroName = strdup(n); /* probable memory leak */ };
- void setRhsString( char *n ) { rhsString = strdup(n); /* probable memory leak */ };
+ int numParameters() { return parameters.size(); };
+ std::vector<chillAST_VarDecl *> parameters;
+
+ void setName(char *n) { macroName = strdup(n); /* probable memory leak */ };
+
+ void setRhsString(char *n) { rhsString = strdup(n); /* probable memory leak */ };
+
char *getRhsString() { return rhsString; }
chillAST_MacroDefinition();
- chillAST_MacroDefinition( const char *name, chillAST_node *par);
- chillAST_MacroDefinition( const char *name, const char *rhs, chillAST_node *par);
-
- void addParameter( chillAST_VarDecl *p); // parameters have no TYPE ??
- chillAST_VarDecl *hasParameterNamed( const char *name );
- chillAST_VarDecl *findParameterNamed( const char *name ) { return hasParameterNamed( name ); };
- void addChild(chillAST_node* node); // special because inserts into BODY
- void insertChild(int i, chillAST_node* node); // special because inserts into BODY
-
- void setBody( chillAST_node * bod );
- chillAST_node *getBody() { return( body); }
-
- void print( int indent=0, FILE *fp = stderr ); // in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // in chill_ast.cc
-
- bool hasSymbolTable() { return true; } ;
+
+ chillAST_MacroDefinition(const char *name, chillAST_node *par);
+
+ chillAST_MacroDefinition(const char *name, const char *rhs, chillAST_node *par);
+
+ void addParameter(chillAST_VarDecl *p); // parameters have no TYPE ??
+ chillAST_VarDecl *hasParameterNamed(const char *name);
+
+ chillAST_VarDecl *findParameterNamed(const char *name) { return hasParameterNamed(name); };
+
+ void addChild(chillAST_node *node); // special because inserts into BODY
+ void insertChild(int i, chillAST_node *node); // special because inserts into BODY
+
+ void setBody(chillAST_node *bod);
+
+ chillAST_node *getBody() { return (body); }
+
+ void print(int indent = 0, FILE *fp = stderr); // in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // in chill_ast.cc
+
+ bool hasSymbolTable() { return true; };
//const std::vector<chillAST_VarDecl *> getSymbolTable() { return symbol_table; }
chillAST_SymbolTable *getSymbolTable() { return symbol_table; }
- chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_MacroDefinition method ??
+
+ chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_MacroDefinition method ??
//fprintf(stderr, "\nchillAST_MacroDefinition addVariableToSymbolTable( %s )\n", vd->varname);
- symbol_table = addSymbolToTable( symbol_table, vd );
+ symbol_table = addSymbolToTable(symbol_table, vd);
//printSymbolTable( symbol_table );
return symbol_table;
}
- chillAST_node* clone();
+ chillAST_node *clone();
// none of these make sense for macros
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls ){};
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
-
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls ){};
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls ){};
- chillAST_VarDecl *findArrayDecl( const char *name ){};
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ){};
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs ){};
- void cleanUpVarDecls();
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){};
- chillAST_node* constantFold(){};
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {};
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) {};
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) {};
+
+ chillAST_VarDecl *findArrayDecl(const char *name) {};
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {};
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) {};
+
+ void cleanUpVarDecls();
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) {};
+
+ chillAST_node *constantFold() {};
};
-class chillAST_ForStmt: public chillAST_node {
+class chillAST_ForStmt : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *init;
@@ -639,250 +765,320 @@ public:
IR_CONDITION_TYPE conditionoperator; // from ir_code.hh
chillAST_SymbolTable *symbol_table; // symbols defined inside this forstmt (in init but not body?) body is compound stmt
- bool hasSymbolTable() { return true; } ;
+ bool hasSymbolTable() { return true; };
// constructors
chillAST_ForStmt();
- chillAST_ForStmt( chillAST_node *ini, chillAST_node *con, chillAST_node *inc, chillAST_node *bod, chillAST_node *p);
-
+
+ chillAST_ForStmt(chillAST_node *ini, chillAST_node *con, chillAST_node *inc, chillAST_node *bod, chillAST_node *p);
+
// other methods particular to this type of node
void addSyncs();
- void removeSyncComment();
+
+ void removeSyncComment();
+
chillAST_node *getInit() { return init; };
+
chillAST_node *getCond() { return cond; };
- chillAST_node *getInc() { return incr; };
- chillAST_node *getBody() { //fprintf(stderr, "chillAST_ForStmt::getBody(), returning a chillAST_node of type %s\n", body->getTypeString());
- return body; };
- void setBody( chillAST_node *b ) { body = b; b->parent = this; };
-
- bool isNotLeaf() { return true; };
- bool isLeaf() { return false; };
-
-
+
+ chillAST_node *getInc() { return incr; };
+
+ chillAST_node *
+ getBody() { //fprintf(stderr, "chillAST_ForStmt::getBody(), returning a chillAST_node of type %s\n", body->getTypeString());
+ return body;
+ };
+
+ void setBody(chillAST_node *b) {
+ body = b;
+ b->parent = this;
+ };
+
+ bool isNotLeaf() { return true; };
+
+ bool isLeaf() { return false; };
+
+
// required methods that I can't seem to get to inherit
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printControl( int indent=0, FILE *fp = stderr ); // print just for ( ... ) but not body
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printControl(int indent = 0, FILE *fp = stderr); // print just for ( ... ) but not body
+
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- chillAST_node* constantFold();
- chillAST_node* clone();
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); // will get called on inner loops
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false );
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- void gatherLoopIndeces( std::vector<chillAST_VarDecl*> &indeces );
- void gatherLoopVars( std::vector<std::string> &loopvars ); // gather as strings ??
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
- void get_deep_loops( std::vector<chillAST_ForStmt *> &loops) { // chillAST_ForStmt version
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); // will get called on inner loops
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false);
+
+ void gatherLoopIndeces(std::vector<chillAST_VarDecl *> &indeces);
+
+ void gatherLoopVars(std::vector<std::string> &loopvars); // gather as strings ??
+
+ void get_deep_loops(std::vector<chillAST_ForStmt *> &loops) { // chillAST_ForStmt version
// ADD MYSELF!
- loops.push_back( this );
+ loops.push_back(this);
- int n = body->children.size();
+ int n = body->children.size();
//fprintf(stderr, "get_deep_loops of a %s with %d children\n", getTypeString(), n);
- for (int i=0; i<n; i++) {
+ for (int i = 0; i < n; i++) {
//fprintf(stderr, "child %d is a %s\n", i, body->children[i]->getTypeString());
- body->children[i]->get_deep_loops( loops );
+ body->children[i]->get_deep_loops(loops);
}
//fprintf(stderr, "found %d deep loops\n", loops.size());
}
- void find_deepest_loops( std::vector<chillAST_ForStmt *> &loops) {
+ void find_deepest_loops(std::vector<chillAST_ForStmt *> &loops) {
std::vector<chillAST_ForStmt *> b; // deepest loops below me
- int n = body->children.size();
- for (int i=0; i<n; i++) {
+ int n = body->children.size();
+ for (int i = 0; i < n; i++) {
std::vector<chillAST_ForStmt *> l; // deepest loops below one child
- body->children[i]->find_deepest_loops( l );
- if ( l.size() > b.size() ) { // a deeper nesting than we've seen
+ body->children[i]->find_deepest_loops(l);
+ if (l.size() > b.size()) { // a deeper nesting than we've seen
b = l;
}
}
- loops.push_back( this ); // add myself
- for (int i=0; i<b.size(); i++) loops.push_back(b[i]);
+ loops.push_back(this); // add myself
+ for (int i = 0; i < b.size(); i++) loops.push_back(b[i]);
}
- void loseLoopWithLoopVar( char *var ); // chillAST_ForStmt
- void replaceChild( chillAST_node *old, chillAST_node *newchild ) ;
+ void loseLoopWithLoopVar(char *var); // chillAST_ForStmt
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
- chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_ForStmt method
+ chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_ForStmt method
//fprintf(stderr, "\nchillAST_ForStmt addVariableToSymbolTable( %s )\n", vd->varname);
- symbol_table = addSymbolToTable( symbol_table, vd );
+ symbol_table = addSymbolToTable(symbol_table, vd);
//printSymbolTable( symbol_table );
return symbol_table;
}
- void gatherStatements( std::vector<chillAST_node*> &statements );
- bool lowerBound( int &l );
- bool upperBound( int &u );
+ void gatherStatements(std::vector<chillAST_node *> &statements);
-};
+ bool lowerBound(int &l);
+ bool upperBound(int &u);
+
+};
-class chillAST_TernaryOperator: public chillAST_node {
+class chillAST_TernaryOperator : public chillAST_node {
public:
// variables that are special for this type of node
char *op; // TODO need enum so far, only "?" conditional operator
chillAST_node *condition;
chillAST_node *lhs; // keep name from binary
chillAST_node *rhs;
-
-
+
+
// constructors
chillAST_TernaryOperator();
- chillAST_TernaryOperator(const char *op, chillAST_node *cond, chillAST_node *lhs, chillAST_node *rhs, chillAST_node *p=NULL);
-
+
+ chillAST_TernaryOperator(const char *op, chillAST_node *cond, chillAST_node *lhs, chillAST_node *rhs,
+ chillAST_node *p = NULL);
+
// other methods particular to this type of node
- bool isNotLeaf() { return true; };
- bool isLeaf() { return false; };
-
-
- char *getOp() { return op; }; // dangerous. could get changed!
- chillAST_node *getCond() { return condition; };
- chillAST_node *getRHS() { return rhs; };
+ bool isNotLeaf() { return true; };
+
+ bool isLeaf() { return false; };
+
+
+ char *getOp() { return op; }; // dangerous. could get changed!
+ chillAST_node *getCond() { return condition; };
+
+ chillAST_node *getRHS() { return rhs; };
+
chillAST_node *getLHS() { return lhs; };
- void setCond( chillAST_node *newc ) { condition = newc; newc->setParent( this ); }
- void setLHS( chillAST_node *newlhs ) { lhs = newlhs; newlhs->setParent( this ); }
- void setRHS( chillAST_node *newrhs ) { rhs = newrhs; newrhs->setParent( this ); }
+ void setCond(chillAST_node *newc) {
+ condition = newc;
+ newc->setParent(this);
+ }
+
+ void setLHS(chillAST_node *newlhs) {
+ lhs = newlhs;
+ newlhs->setParent(this);
+ }
+
+ void setRHS(chillAST_node *newrhs) {
+ rhs = newrhs;
+ newrhs->setParent(this);
+ }
+
-
-
-
// required methods that I can't seem to get to inherit
- void dump( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printonly( int indent=0, FILE *fp = stderr );
+ void dump(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printonly(int indent = 0, FILE *fp = stderr);
+
+ chillAST_node *constantFold();
- chillAST_node* constantFold();
- chillAST_node* clone();
- void replaceChild( chillAST_node *old, chillAST_node *newchild ) ;
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ chillAST_node *clone();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void gatherVarLHSUsage( std::vector<chillAST_VarDecl*> &decls );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- void loseLoopWithLoopVar( char *var ){}; // ternop can't have loop as child?
-};
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
-class chillAST_BinaryOperator: public chillAST_node {
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void gatherVarLHSUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ void loseLoopWithLoopVar(char *var) {}; // ternop can't have loop as child?
+};
+
+
+class chillAST_BinaryOperator : public chillAST_node {
public:
// variables that are special for this type of node
char *op; // TODO need enum
chillAST_node *lhs;
chillAST_node *rhs;
-
-
+
+
// constructors
chillAST_BinaryOperator();
- chillAST_BinaryOperator(chillAST_node *lhs, const char *op, chillAST_node *rhs, chillAST_node *p=NULL);
-
+
+ chillAST_BinaryOperator(chillAST_node *lhs, const char *op, chillAST_node *rhs, chillAST_node *p = NULL);
+
// other methods particular to this type of node
int evalAsInt();
- chillAST_IntegerLiteral *evalAsIntegerLiteral();
- bool isNotLeaf() { return true; };
- bool isLeaf() { return false; };
-
- chillAST_node *getRHS() { return rhs; };
+ chillAST_IntegerLiteral *evalAsIntegerLiteral();
+
+ bool isNotLeaf() { return true; };
+
+ bool isLeaf() { return false; };
+
+ chillAST_node *getRHS() { return rhs; };
+
chillAST_node *getLHS() { return lhs; };
- void setLHS( chillAST_node *newlhs ) { lhs = newlhs; newlhs->setParent( this ); }
- void setRHS( chillAST_node *newrhs ) { rhs = newrhs; newrhs->setParent( this ); }
-
- char *getOp() { return op; }; // dangerous. could get changed!
- bool isAugmentedAssignmentOp() {
- return
- (!strcmp(op, "*=")) || // BO_MulAssign,
- (!strcmp(op, "/=")) || // BO_DivAssign
- (!strcmp(op, "%=")) || // BO_RemAssign
- (!strcmp(op, "+=")) || // BO_AddAssign
- (!strcmp(op, "-=")) || // BO_SubAssign
-
- (!strcmp(op, "<<=")) || // BO_ShlAssign
- (!strcmp(op, ">>=")) || // BO_ShrAssign
- (!strcmp(op, "&&=")) || // BO_AndAssign
- (!strcmp(op, "||=")) || // BO_OrAssign
-
- (!strcmp(op, "^=")) // BO_XorAssign
- ;
+
+ void setLHS(chillAST_node *newlhs) {
+ lhs = newlhs;
+ newlhs->setParent(this);
+ }
+
+ void setRHS(chillAST_node *newrhs) {
+ rhs = newrhs;
+ newrhs->setParent(this);
+ }
+
+ char *getOp() { return op; }; // dangerous. could get changed!
+ bool isAugmentedAssignmentOp() {
+ return
+ (!strcmp(op, "*=")) || // BO_MulAssign,
+ (!strcmp(op, "/=")) || // BO_DivAssign
+ (!strcmp(op, "%=")) || // BO_RemAssign
+ (!strcmp(op, "+=")) || // BO_AddAssign
+ (!strcmp(op, "-=")) || // BO_SubAssign
+
+ (!strcmp(op, "<<=")) || // BO_ShlAssign
+ (!strcmp(op, ">>=")) || // BO_ShrAssign
+ (!strcmp(op, "&&=")) || // BO_AndAssign
+ (!strcmp(op, "||=")) || // BO_OrAssign
+
+ (!strcmp(op, "^=")) // BO_XorAssign
+ ;
}
- bool isAssignmentOp() {
- return( (!strcmp(op, "=")) || // BO_Assign,
- isAugmentedAssignmentOp() );
- };
- bool isComparisonOp() { return (!strcmp(op,"<")) || (!strcmp(op,">")) || (!strcmp(op,"<=")) || (!strcmp(op,">=")); };
-
- bool isPlusOp() { return (!strcmp(op,"+")); };
- bool isMinusOp() { return (!strcmp(op,"-")); };
- bool isPlusMinusOp() { return (!strcmp(op,"+")) || (!strcmp(op,"-")); };
- bool isMultDivOp() { return (!strcmp(op,"*")) || (!strcmp(op,"/")); };
-
- bool isStructOp() { return (!strcmp(op,".")) || (!strcmp(op,"->")); };
-
-
+
+ bool isAssignmentOp() {
+ return ((!strcmp(op, "=")) || // BO_Assign,
+ isAugmentedAssignmentOp());
+ };
+
+ bool isComparisonOp() {
+ return (!strcmp(op, "<")) || (!strcmp(op, ">")) || (!strcmp(op, "<=")) || (!strcmp(op, ">="));
+ };
+
+ bool isPlusOp() { return (!strcmp(op, "+")); };
+
+ bool isMinusOp() { return (!strcmp(op, "-")); };
+
+ bool isPlusMinusOp() { return (!strcmp(op, "+")) || (!strcmp(op, "-")); };
+
+ bool isMultDivOp() { return (!strcmp(op, "*")) || (!strcmp(op, "/")); };
+
+ bool isStructOp() { return (!strcmp(op, ".")) || (!strcmp(op, "->")); };
+
+
// required methods that I can't seem to get to inherit
- void dump( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printonly( int indent=0, FILE *fp = stderr );
- char *stringRep(int indent=0 );
+ void dump(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printonly(int indent = 0, FILE *fp = stderr);
+
+ char *stringRep(int indent = 0);
+
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
- chillAST_node* constantFold();
- chillAST_node* clone();
- void replaceChild( chillAST_node *old, chillAST_node *newchild ) ;
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ); // chillAST_BinaryOperator
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); // chillAST_BinaryOperator
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void gatherVarLHSUsage( std::vector<chillAST_VarDecl*> &decls );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- void loseLoopWithLoopVar( char *var ){}; // binop can't have loop as child?
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherStatements( std::vector<chillAST_node*> &statements ); //
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
- bool isSameAs( chillAST_node *other );
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
-};
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+ void gatherVarLHSUsage(std::vector<chillAST_VarDecl *> &decls);
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ void loseLoopWithLoopVar(char *var) {}; // binop can't have loop as child?
+ void gatherStatements(std::vector<chillAST_node *> &statements); //
+ bool isSameAs(chillAST_node *other);
+};
-class chillAST_ArraySubscriptExpr: public chillAST_node {
+class chillAST_ArraySubscriptExpr : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *base; // always a decl ref expr? No, for multidimensional array, is another ASE
@@ -891,472 +1087,559 @@ public:
bool imreadfrom; // WARNING: ONLY used when both writtento and readfrom are true x += 1 and so on
chillAST_VarDecl *basedecl; // the vardecl that this refers to
void *uniquePtr; // DO NOT REFERENCE THROUGH THIS!
-
+
// constructors
- chillAST_ArraySubscriptExpr();
- chillAST_ArraySubscriptExpr( chillAST_node *bas, chillAST_node *indx, chillAST_node *p, void *unique);
- chillAST_ArraySubscriptExpr( chillAST_node *bas, chillAST_node *indx, bool writtento, chillAST_node *p, void *unique);
-
- chillAST_ArraySubscriptExpr( chillAST_VarDecl *v, std::vector<chillAST_node *> indeces, chillAST_node *p);
-
+ chillAST_ArraySubscriptExpr();
+
+ chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, chillAST_node *p, void *unique);
+
+ chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, bool writtento, chillAST_node *p, void *unique);
+
+ chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, std::vector<chillAST_node *> indeces, chillAST_node *p);
+
// other methods particular to this type of node
- bool operator!=( const chillAST_ArraySubscriptExpr& ) ;
- bool operator==( const chillAST_ArraySubscriptExpr& ) ;
+ bool operator!=(const chillAST_ArraySubscriptExpr &);
+
+ bool operator==(const chillAST_ArraySubscriptExpr &);
+
chillAST_VarDecl *multibase(); // method for finding the basedecl
- chillAST_node *multibase2() { return base->multibase2(); }
+ chillAST_node *multibase2() { return base->multibase2(); }
chillAST_node *getIndex(int dim);
- void gatherIndeces( std::vector< chillAST_node * > &ind );
- void replaceChild( chillAST_node *old, chillAST_node *newchild ); // will examine index
+ void gatherIndeces(std::vector<chillAST_node *> &ind);
+
+ void replaceChild(chillAST_node *old, chillAST_node *newchild); // will examine index
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printonly( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr ) const; // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- char *stringRep(int indent=0 );
-
- chillAST_node* constantFold();
- chillAST_node* clone();
- chillAST_node *findref(){return this;}// find the SINGLE constant or data reference at this node or below
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
-
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
-
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
-
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
-
- const char* getUnderlyingType() {
- //fprintf(stderr, "ASE getUnderlyingType() base of type %s\n", base->getTypeString()); base->print(); printf("\n"); fflush(stderr);
- return base->getUnderlyingType(); };
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printonly(int indent = 0, FILE *fp = stderr);
+
+ void print(int indent = 0, FILE *fp = stderr) const; // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ char *stringRep(int indent = 0);
+
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ chillAST_node *findref() { return this; }// find the SINGLE constant or data reference at this node or below
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- virtual chillAST_VarDecl* getUnderlyingVarDecl() { return base->getUnderlyingVarDecl(); };
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
-};
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+ const char *getUnderlyingType() {
+ //fprintf(stderr, "ASE getUnderlyingType() base of type %s\n", base->getTypeString()); base->print(); printf("\n"); fflush(stderr);
+ return base->getUnderlyingType();
+ };
+ virtual chillAST_VarDecl *getUnderlyingVarDecl() { return base->getUnderlyingVarDecl(); };
-class chillAST_MemberExpr: public chillAST_node {
+};
+
+
+class chillAST_MemberExpr : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *base; // always a decl ref expr? No, can be Array Subscript Expr
- char *member;
- char *printstring;
+ char *member;
+ char *printstring;
chillAST_VarDecl *basedecl; // the vardecl that this refers to
void *uniquePtr; // DO NOT REFERENCE THROUGH THIS!
- CHILL_MEMBER_EXP_TYPE exptype;
-
+ CHILL_MEMBER_EXP_TYPE exptype;
+
// constructors
- chillAST_MemberExpr();
- chillAST_MemberExpr( chillAST_node *bas, const char *mem, chillAST_node *p, void *unique, CHILL_MEMBER_EXP_TYPE t=CHILL_MEMBER_EXP_DOT);
-
+ chillAST_MemberExpr();
+
+ chillAST_MemberExpr(chillAST_node *bas, const char *mem, chillAST_node *p, void *unique,
+ CHILL_MEMBER_EXP_TYPE t = CHILL_MEMBER_EXP_DOT);
+
// other methods particular to this type of node
- bool operator!=( const chillAST_MemberExpr& ) ;
- bool operator==( const chillAST_MemberExpr& ) ;
-
+ bool operator!=(const chillAST_MemberExpr &);
+
+ bool operator==(const chillAST_MemberExpr &);
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printonly( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr ) const; // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- char *stringRep( int indent = 0);
-
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printonly(int indent = 0, FILE *fp = stderr);
+
+ void print(int indent = 0, FILE *fp = stderr) const; // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ char *stringRep(int indent = 0);
+
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
- chillAST_VarDecl* getUnderlyingVarDecl();
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
- void replaceChild( chillAST_node *old, chillAST_node *newchild );
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
- void setType( CHILL_MEMBER_EXP_TYPE t ) { exptype = t; };
- CHILL_MEMBER_EXP_TYPE getType( CHILL_MEMBER_EXP_TYPE t ) { return exptype; };
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- chillAST_VarDecl* multibase(); // this one will return the member decl
- chillAST_node* multibase2(); // this one will return the member expression
-};
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ chillAST_VarDecl *getUnderlyingVarDecl();
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
+ void setType(CHILL_MEMBER_EXP_TYPE t) { exptype = t; };
-class chillAST_IntegerLiteral: public chillAST_node {
+ CHILL_MEMBER_EXP_TYPE getType(CHILL_MEMBER_EXP_TYPE t) { return exptype; };
+
+ chillAST_VarDecl *multibase(); // this one will return the member decl
+ chillAST_node *multibase2(); // this one will return the member expression
+};
+
+
+class chillAST_IntegerLiteral : public chillAST_node {
public:
// variables that are special for this type of node
int value;
-
+
// constructors
- chillAST_IntegerLiteral(int val, chillAST_node *p = NULL);
-
+ chillAST_IntegerLiteral(int val, chillAST_node *p = NULL);
+
// other methods particular to this type of node
- int evalAsInt() { return value; }
+ int evalAsInt() { return value; }
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ){}; // does nothing
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ){}; // does nothing
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls ){}; // does nothing
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls ){}; // does nothing
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls ){}; // does nothing
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {}; // does nothing
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {}; // does nothing
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs ) {}; // does nothing
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- chillAST_node *findref(){return this;}// find the SINGLE constant or data reference at this node or below
-};
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) {}; // does nothing
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
-class chillAST_FloatingLiteral: public chillAST_node {
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+ chillAST_node *findref() { return this; }// find the SINGLE constant or data reference at this node or below
+};
+
+
+class chillAST_FloatingLiteral : public chillAST_node {
public:
// variables that are special for this type of node
float value;
double doublevalue;
- int float0double1;
+ int float0double1;
char *allthedigits; // if not NULL, use this as printable representation
int precision; // float == 1, double == 2, ???
// constructors
- chillAST_FloatingLiteral( float val, chillAST_node *p);
- chillAST_FloatingLiteral( double val, chillAST_node *p);
- chillAST_FloatingLiteral( float val, int pre, chillAST_node *p);
- chillAST_FloatingLiteral( double val, int pre, chillAST_node *p);
- chillAST_FloatingLiteral( float val, const char *printable, chillAST_node *p);
- chillAST_FloatingLiteral( float val, int pre, const char *printable, chillAST_node *p);
- chillAST_FloatingLiteral( chillAST_FloatingLiteral *old );
-
+ chillAST_FloatingLiteral(float val, chillAST_node *p);
+
+ chillAST_FloatingLiteral(double val, chillAST_node *p);
+
+ chillAST_FloatingLiteral(float val, int pre, chillAST_node *p);
+
+ chillAST_FloatingLiteral(double val, int pre, chillAST_node *p);
+
+ chillAST_FloatingLiteral(float val, const char *printable, chillAST_node *p);
+
+ chillAST_FloatingLiteral(float val, int pre, const char *printable, chillAST_node *p);
+
+ chillAST_FloatingLiteral(chillAST_FloatingLiteral *old);
+
// other methods particular to this type of node
- void setPrecision( int precis ) { precision = precis; };
- int getPrecision() { return precision; }
-
+ void setPrecision(int precis) { precision = precis; };
+
+ int getPrecision() { return precision; }
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ){}; // does nothing
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ){}; // does nothing
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls ){}; // does nothing
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls ){}; // does nothing ;
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls ){}; // does nothing ;
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {}; // does nothing
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {}; // does nothing
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs ){}; // does nothing
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){};
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- chillAST_node *findref(){return this;};// find the SINGLE constant or data reference at this node or below
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- bool isSameAs( chillAST_node *other );
-};
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing ;
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing ;
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) {}; // does nothing
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ chillAST_node *findref() { return this; };// find the SINGLE constant or data reference at this node or below
+
+ bool isSameAs(chillAST_node *other);
+};
-class chillAST_UnaryOperator: public chillAST_node {
+class chillAST_UnaryOperator : public chillAST_node {
public:
// variables that are special for this type of node
char *op; // TODO enum
bool prefix; // or post
chillAST_node *subexpr;
-
+
// constructors
- chillAST_UnaryOperator( const char *oper, bool pre, chillAST_node *sub, chillAST_node *p );
-
+ chillAST_UnaryOperator(const char *oper, bool pre, chillAST_node *sub, chillAST_node *p);
+
// other methods particular to this type of node
- bool isAssignmentOp() {
- return( (!strcmp(op, "++")) ||
- (!strcmp(op, "--")) ); // are there more ??? TODO
+ bool isAssignmentOp() {
+ return ((!strcmp(op, "++")) ||
+ (!strcmp(op, "--"))); // are there more ??? TODO
}
-
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ); // chillAST_UnaryOperator
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarLHSUsage( std::vector<chillAST_VarDecl*> &decls );
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- int evalAsInt();
- bool isSameAs( chillAST_node *other );
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); // chillAST_UnaryOperator
+
+ void gatherVarLHSUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
-};
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+ //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+ int evalAsInt();
+
+ bool isSameAs(chillAST_node *other);
+};
-class chillAST_ImplicitCastExpr: public chillAST_node {
+class chillAST_ImplicitCastExpr : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *subexpr;
-
+
// constructors
- chillAST_ImplicitCastExpr(chillAST_node *sub, chillAST_node *p);
-
+ chillAST_ImplicitCastExpr(chillAST_node *sub, chillAST_node *p);
+
// other methods particular to this type of node
- bool isNotLeaf() { return true; };
- bool isLeaf() { return false; };
-
+ bool isNotLeaf() { return true; };
+
+ bool isLeaf() { return false; };
+
// required methods that I can't seem to get to inherit
- void replaceChild( chillAST_node *old, chillAST_node *newchild );
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void printonly( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ) { print( indent, fp); }; // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
-
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
-
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
-
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
+
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void printonly(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr) { print(indent, fp); }; // print ast in chill_ast.cc
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
//void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
chillAST_VarDecl *multibase(); // just recurse on subexpr
-};
-
+};
-class chillAST_CStyleCastExpr: public chillAST_node {
+class chillAST_CStyleCastExpr : public chillAST_node {
public:
// variables that are special for this type of node
- char * towhat;
+ char *towhat;
chillAST_node *subexpr;
+
// constructors
- chillAST_CStyleCastExpr(const char *to, chillAST_node *sub, chillAST_node *p=NULL);
-
+ chillAST_CStyleCastExpr(const char *to, chillAST_node *sub, chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void replaceChild( chillAST_node *old, chillAST_node *newchild );
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void replaceChild(chillAST_node *old, chillAST_node *newchild);
+
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- chillAST_node *findref(){return subexpr;};// find the SINGLE constant or data reference at this node or below
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
-};
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
-class chillAST_CStyleAddressOf: public chillAST_node {
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ chillAST_node *findref() { return subexpr; };// find the SINGLE constant or data reference at this node or below
+
+};
+
+
+class chillAST_CStyleAddressOf : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *subexpr;
+
// constructors
- chillAST_CStyleAddressOf(chillAST_node *sub, chillAST_node *p=NULL);
-
+ chillAST_CStyleAddressOf(chillAST_node *sub, chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
//void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
-
-};
+
+};
-class chillAST_CudaMalloc:public chillAST_node {
+class chillAST_CudaMalloc : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *devPtr; // Pointer to allocated device memory
chillAST_node *sizeinbytes;
// constructors
- chillAST_CudaMalloc(chillAST_node *devmemptr, chillAST_node *size, chillAST_node *p=NULL);
-
+ chillAST_CudaMalloc(chillAST_node *devmemptr, chillAST_node *size, chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
//void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
//void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
-};
+};
-class chillAST_CudaFree:public chillAST_node {
+class chillAST_CudaFree : public chillAST_node {
public:
// variables that are special for this type of node
- chillAST_VarDecl *variable;
+ chillAST_VarDecl *variable;
// constructors
- chillAST_CudaFree(chillAST_VarDecl *var, chillAST_node *p=NULL);
-
+ chillAST_CudaFree(chillAST_VarDecl *var, chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- //void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
-};
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ //void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
+ //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
-class chillAST_Malloc:public chillAST_node { // malloc( sizeof(int) * 2048 );
+};
+
+
+class chillAST_Malloc : public chillAST_node { // malloc( sizeof(int) * 2048 );
public:
// variables that are special for this type of node
char *thing; // to void if this is null , sizeof(thing) if it is not
chillAST_node *sizeexpr; // bytes
// constructors
- chillAST_Malloc(chillAST_node *size, chillAST_node *p=NULL);
- chillAST_Malloc(char *thething, chillAST_node *numthings, chillAST_node *p=NULL); // malloc (sizeof(int) *1024)
+ chillAST_Malloc(chillAST_node *size, chillAST_node *p = NULL);
+
+ chillAST_Malloc(char *thething, chillAST_node *numthings, chillAST_node *p = NULL); // malloc (sizeof(int) *1024)
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- //void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
-};
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
-class chillAST_Free:public chillAST_node {
-public:
-
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ //void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
+ //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+};
-};
+class chillAST_Free : public chillAST_node {
+public:
+};
-class chillAST_CudaMemcpy:public chillAST_node {
+class chillAST_CudaMemcpy : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_VarDecl *dest; // Pointer to allocated device memory
@@ -1365,301 +1648,356 @@ public:
char *cudaMemcpyKind; // could use the actual enum
// constructors
- chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_node *size, char *kind, chillAST_node *p=NULL);
-
+ chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_node *size, char *kind,
+ chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
//void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
//void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
-};
+};
-class chillAST_CudaSyncthreads:public chillAST_node {
+class chillAST_CudaSyncthreads : public chillAST_node {
public:
// variables that are special for this type of node
// constructors
- chillAST_CudaSyncthreads(chillAST_node *p=NULL);
-
+ chillAST_CudaSyncthreads(chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
//chillAST_node* constantFold() {};
//chillAST_node* clone();
//void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ){};
//void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ) {}; // does nothing
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {}; // does nothing
//void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
//void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
//bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; };
-};
+};
-
-class chillAST_ReturnStmt: public chillAST_node {
+class chillAST_ReturnStmt : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *returnvalue;
-
+
// constructors
- chillAST_ReturnStmt( chillAST_node *retval, chillAST_node *p );
-
+ chillAST_ReturnStmt(chillAST_node *retval, chillAST_node *p);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *clone();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
-};
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
-class chillAST_CallExpr: public chillAST_node { // a function call
+ //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+};
+
+
+class chillAST_CallExpr : public chillAST_node { // a function call
public:
// variables that are special for this type of node
chillAST_node *callee; // the function declaration (what about builtins?)
int numargs;
- std::vector<class chillAST_node*> args;
+ std::vector<class chillAST_node *> args;
chillAST_VarDecl *grid;
chillAST_VarDecl *block;
// constructors
- chillAST_CallExpr(chillAST_node *function, chillAST_node *p );
- void addArg( chillAST_node *newarg );
-
+ chillAST_CallExpr(chillAST_node *function, chillAST_node *p);
+
+ void addArg(chillAST_node *newarg);
+
// other methods particular to this type of node
// TODO get/set grid, block
-
+
// required methods that I can't seem to get to inherit
- chillAST_node* constantFold();
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ chillAST_node *constantFold();
+
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
- chillAST_node* clone();
-};
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+ chillAST_node *clone();
+};
-class chillAST_ParenExpr: public chillAST_node {
+
+class chillAST_ParenExpr : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *subexpr;
-
+
// constructors
- chillAST_ParenExpr( chillAST_node *sub, chillAST_node *p=NULL );
-
+ chillAST_ParenExpr(chillAST_node *sub, chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
-};
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
-class chillAST_Sizeof: public chillAST_node {
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+};
+
+
+class chillAST_Sizeof : public chillAST_node {
public:
// variables that are special for this type of node
- char *thing;
-
+ char *thing;
+
// constructors
- chillAST_Sizeof( char *t, chillAST_node *p = NULL );
-
+ chillAST_Sizeof(char *t, chillAST_node *p = NULL);
+
// other methods particular to this type of node
-
-
+
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
- chillAST_node* constantFold();
- chillAST_node* clone();
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
+ chillAST_node *constantFold();
+
+ chillAST_node *clone();
+
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){};
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
-};
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
-class chillAST_NoOp: public chillAST_node {
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; }; // no loops under here
+
+};
+
+
+class chillAST_NoOp : public chillAST_node {
public:
- chillAST_NoOp( chillAST_node *p = NULL ); // { parent = p; };
+ chillAST_NoOp(chillAST_node *p = NULL); // { parent = p; };
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ) {}; // print CODE in chill_ast.cc
- void dump( int indent=0, FILE *fp = stderr ) {}; // print ast in chill_ast.cc
- chillAST_node* constantFold() {};
- chillAST_node* clone() { return new chillAST_NoOp( parent ); }; // ??
+ void print(int indent = 0, FILE *fp = stderr) {}; // print CODE in chill_ast.cc
+ void dump(int indent = 0, FILE *fp = stderr) {}; // print ast in chill_ast.cc
+ chillAST_node *constantFold() {};
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {};
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {};
+ chillAST_node *clone() { return new chillAST_NoOp(parent); }; // ??
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls ){};
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {};
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls ){};
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls ){};
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {};
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls ){};
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs ){};
- void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){};
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; };//no loops under here
-};
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {};
+
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) {};
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) {};
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) {};
-class chillAST_IfStmt: public chillAST_node {
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) {};
+
+ void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
+
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
+ bool forcesync = false) { return false; };//no loops under here
+};
+
+
+class chillAST_IfStmt : public chillAST_node {
public:
// variables that are special for this type of node
chillAST_node *cond;
chillAST_node *thenpart;
chillAST_node *elsepart;
IR_CONDITION_TYPE conditionoperator; // from ir_code.hh
-
+
// constructors
chillAST_IfStmt();
- chillAST_IfStmt( chillAST_node *c, chillAST_node *t, chillAST_node *e, chillAST_node *p);
-
+
+ chillAST_IfStmt(chillAST_node *c, chillAST_node *t, chillAST_node *e, chillAST_node *p);
+
// other methods particular to this type of node
chillAST_node *getCond() { return cond; };
+
chillAST_node *getThen() { return thenpart; };
+
chillAST_node *getElse() { return elsepart; };
- void setCond( chillAST_node *b ) { cond = b; if (cond) cond->parent = this; };
- void setThen( chillAST_node *b ) { thenpart = b; if (thenpart) thenpart->parent = this; };
- void setElse( chillAST_node *b ) { elsepart = b; if (elsepart) elsepart->parent = this; };
-
+ void setCond(chillAST_node *b) {
+ cond = b;
+ if (cond) cond->parent = this;
+ };
+
+ void setThen(chillAST_node *b) {
+ thenpart = b;
+ if (thenpart) thenpart->parent = this;
+ };
+
+ void setElse(chillAST_node *b) {
+ elsepart = b;
+ if (elsepart) elsepart->parent = this;
+ };
+
// required methods that I can't seem to get to inherit
- void dump( int indent=0, FILE *fp = stderr );
- void print( int indent=0, FILE *fp = stderr );
+ void dump(int indent = 0, FILE *fp = stderr);
- chillAST_node* constantFold();
- chillAST_node* clone();
+ void print(int indent = 0, FILE *fp = stderr);
- void gatherVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherVarDeclsMore ( std::vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
+ chillAST_node *constantFold();
- void gatherScalarVarDecls( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayVarDecls ( std::vector<chillAST_VarDecl*> &decls );
- void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
- void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
+ chillAST_node *clone();
- void gatherVarUsage( std::vector<chillAST_VarDecl*> &decls );
- void gatherDeclRefExprs( std::vector<chillAST_DeclRefExpr *>&refs );
- //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
- bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false );
+ void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
- void gatherStatements( std::vector<chillAST_node*> &statements );
-
-};
+ void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
+ void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
+ void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
+ void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
+ void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
+ void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
+ //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
+ bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false);
+
+ void gatherStatements(std::vector<chillAST_node *> &statements);
+
+};
-class chillAST_something: public chillAST_node {
+
+class chillAST_something : public chillAST_node {
public:
// variables that are special for this type of node
-
+
// constructors
- chillAST_something();
-
+ chillAST_something();
+
// other methods particular to this type of node
-
+
// required methods that I can't seem to get to inherit
- void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
+ void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
//void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
-};
-
-
-
-
-
+};
#endif
diff --git a/include/chill_error.hh b/include/chill_error.hh
index c5601ae..7321e75 100644
--- a/include/chill_error.hh
+++ b/include/chill_error.hh
@@ -7,22 +7,22 @@
*/
//! for loop transformation problem
-struct loop_error: public std::runtime_error {
- loop_error(const std::string &msg): std::runtime_error(msg){}
+struct loop_error : public std::runtime_error {
+ loop_error(const std::string &msg) : std::runtime_error(msg) {}
};
//! for generic compiler intermediate code handling problem
-struct ir_error: public std::runtime_error {
- ir_error(const std::string &msg): std::runtime_error(msg){}
+struct ir_error : public std::runtime_error {
+ ir_error(const std::string &msg) : std::runtime_error(msg) {}
};
//! for specific for expression to preburger math translation problem
-struct ir_exp_error: public ir_error {
- ir_exp_error(const std::string &msg): ir_error(msg){}
+struct ir_exp_error : public ir_error {
+ ir_exp_error(const std::string &msg) : ir_error(msg) {}
};
-struct omega_error: public std::runtime_error {
- omega_error(const std::string &msg): std::runtime_error(msg){}
+struct omega_error : public std::runtime_error {
+ omega_error(const std::string &msg) : std::runtime_error(msg) {}
};
#endif
diff --git a/include/chilldebug.h b/include/chilldebug.h
index c09aa59..010687a 100644
--- a/include/chilldebug.h
+++ b/include/chilldebug.h
@@ -12,11 +12,11 @@
#define FILENAME basename(strdup(__FILE__))
#ifdef DEBUGCHILL
-#define CHILL_DEBUG_PRINT(format,args...) fprintf(stderr,"%s, %s, LN%d:\t" format,FILENAME,__FUNCTION__, \
+#define CHILL_DEBUG_PRINT(format,args...) fprintf(stderr,"%15s | %15s | LN%-4d:\t" format,FILENAME,__FUNCTION__, \
__LINE__, ##args )
#define CHILL_DEBUG_BEGIN { \
- fprintf(stderr,"=========\t%s, %s, LN%d\t=========\n",FILENAME,__FUNCTION__,__LINE__);
-#define CHILL_DEBUG_END fprintf(stderr,"===========================\n");}
+ fprintf(stderr,"=========\t%15s, %15s, LN%-4d\t=========\n",FILENAME,__FUNCTION__,__LINE__);
+#define CHILL_DEBUG_END fprintf(stderr,"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");}
#else
#define CHILL_DEBUG_PRINT(format,args...) do {} while(0) /* Don't do anything */
#define CHILL_DEBUG_BEGIN while(0) {
diff --git a/include/chillmodule.hh b/include/chillmodule.hh
index e83119f..896cc7c 100644
--- a/include/chillmodule.hh
+++ b/include/chillmodule.hh
@@ -9,7 +9,9 @@
#include <Python.h>
void finalize_loop(int loop_num_start, int loop_num_end);
+
int get_loop_num_start();
+
int get_loop_num_end();
//! pass C methods to python
PyMODINIT_FUNC initchill();
diff --git a/include/dep.hh b/include/dep.hh
index 73c662c..ffd2db5 100644
--- a/include/dep.hh
+++ b/include/dep.hh
@@ -6,25 +6,29 @@
#include "ir_code.hh"
#include "chill_error.hh"
-enum DependenceType { DEP_W2R, DEP_R2W, DEP_W2W, DEP_R2R, DEP_CONTROL, DEP_UNKNOWN };
+enum DependenceType {
+ DEP_W2R, DEP_R2W, DEP_W2W, DEP_R2R, DEP_CONTROL, DEP_UNKNOWN
+};
class DependenceVector;
+
typedef std::vector<DependenceVector> DependenceList;
struct DependenceVector {
DependenceType type;
IR_Symbol *sym;
-
+
bool from_same_stmt; // Manu
bool is_reduction_cand; // Manu
bool is_reduction; // used to identify a class of flow dependence
- // that can be broken
+ // that can be broken
std::vector<omega::coef_t> lbounds;
std::vector<omega::coef_t> ubounds;
-
+
bool quasi;
bool is_scalar_dependence;
+
DependenceVector() {
type = DEP_UNKNOWN;
sym = NULL;
@@ -34,52 +38,78 @@ struct DependenceVector {
quasi = false;
is_scalar_dependence = false;
}
+
DependenceVector(const DependenceVector &that);
+
~DependenceVector() { delete sym; } // is this legal? TODO
DependenceVector &operator=(const DependenceVector &that);
-
+
bool is_data_dependence() const;
+
bool is_control_dependence() const;
+
bool has_negative_been_carried_at(int dim) const;
+
bool has_been_carried_at(int dim) const;
+
bool has_been_carried_before(int dim) const;
-
+
// the following functions will be cleaned up or removed later
bool isZero() const;
+
bool isPositive() const;
+
bool isNegative() const;
+
bool isAllPositive() const;
+
bool isAllNegative() const;
+
bool isZero(int dim) const;
+
bool hasPositive(int dim) const;
+
bool hasNegative(int dim) const;
+
bool isCarried(int dim, omega::coef_t distance = posInfinity) const;
+
bool canPermute(const std::vector<int> &pi) const;
-
+
std::vector<DependenceVector> normalize() const;
+
std::vector<DependenceVector> permute(const std::vector<int> &pi) const;
+
DependenceVector reverse() const;
+
DependenceType getType() const;
- friend std::ostream& operator<<(std::ostream &os, const DependenceVector &d);
+
+ friend std::ostream &operator<<(std::ostream &os, const DependenceVector &d);
};
+class DependenceGraph : public Graph<Empty, DependenceVector> {
-class DependenceGraph: public Graph<Empty, DependenceVector> {
-
protected:
int num_dim_;
-
+
public:
DependenceGraph(int n) { num_dim_ = n; }
+
DependenceGraph() { num_dim_ = 0; }
+
~DependenceGraph() {}
+
int num_dim() const { return num_dim_; }
+
DependenceGraph permute(const std::vector<int> &pi,
const std::set<int> &active = std::set<int>()) const;
+
DependenceGraph subspace(int dim) const;
+
bool isPositive() const;
+
bool hasPositive(int dim) const;
+
bool hasNegative(int dim) const;
};
diff --git a/include/graph.hh b/include/graph.hh
index 211444a..e5885ce 100644
--- a/include/graph.hh
+++ b/include/graph.hh
@@ -37,17 +37,25 @@
struct Empty {
Empty() {};
+
bool operator<(const Empty &) const { return true; };
+
bool operator==(const Empty &) const { return false; };
- friend std::ostream& operator<<(std::ostream &os, const Empty &) { return os; };
+
+ friend std::ostream &operator<<(std::ostream &os, const Empty &) { return os; };
};
namespace {
- enum GraphColorType {WHITE, GREY, BLACK};
+ enum GraphColorType {
+ WHITE, GREY, BLACK
+ };
}
-template<typename VertexType, typename EdgeType> struct Graph;
-template<typename VertexType, typename EdgeType> std::ostream& operator<<(std::ostream &os, const Graph<VertexType, EdgeType> &g);
+template<typename VertexType, typename EdgeType>
+struct Graph;
+
+template<typename VertexType, typename EdgeType>
+std::ostream &operator<<(std::ostream &os, const Graph<VertexType, EdgeType> &g);
template<typename VertexType = Empty, typename EdgeType = Empty>
struct Graph {
@@ -58,18 +66,27 @@ struct Graph {
bool directed;
Graph(bool directed = true);
-
+
int vertexCount() const;
+
int edgeCount() const;
+
bool isEmpty() const;
+
bool isDirected() const;
+
int insert(const VertexType &v = VertexType());
+
void connect(int v1, int v2, const EdgeType &e = EdgeType());
+
void connect(int v1, int v2, const std::vector<EdgeType> &e);
+
void disconnect(int v1, int v2);
+
bool hasEdge(int v1, int v2) const;
+
std::vector<EdgeType> getEdge(int v1, int v2) const;
-
+
//! Topological sort
/*! This topological sort does handle SCC in graph. */
std::vector<std::set<int> > topoSort() const;
@@ -80,15 +97,16 @@ struct Graph {
void dump() {
std::cout << *this;
}
-
- friend std::ostream& operator<< <>(std::ostream &os, const Graph<VertexType, EdgeType> &g);
+
+ friend std::ostream &operator<<<>(std::ostream &os, const Graph<VertexType, EdgeType> &g);
};
template<typename VertexType, typename EdgeType>
-std::ostream& operator<<(std::ostream &os, const Graph<VertexType, EdgeType> &g) {
+std::ostream &operator<<(std::ostream &os, const Graph<VertexType, EdgeType> &g) {
for (int i = 0; i < g.vertex.size(); i++)
- for (typename Graph<VertexType,EdgeType>::EdgeList::const_iterator j = g.vertex[i].second.begin(); j != g.vertex[i].second.end(); j++) {
- os << "s" << i << "->" << "s" << j->first << ":";
+ for (typename Graph<VertexType, EdgeType>::EdgeList::const_iterator j = g.vertex[i].second.begin();
+ j != g.vertex[i].second.end(); j++) {
+ os << "s" << i << "->" << "s" << j->first << ":";
for (typename std::vector<EdgeType>::const_iterator k = j->second.begin(); k != j->second.end(); k++)
os << " " << *k;
os << std::endl;
@@ -100,7 +118,7 @@ std::ostream& operator<<(std::ostream &os, const Graph<VertexType, EdgeType> &g)
template<typename VertexType, typename EdgeType>
Graph<VertexType, EdgeType>::Graph(bool directed_):
- directed(directed_) {
+ directed(directed_) {
}
template<typename VertexType, typename EdgeType>
@@ -117,8 +135,8 @@ int Graph<VertexType, EdgeType>::edgeCount() const {
result += j->second.size();
if (!directed)
- result = result/2;
-
+ result = result / 2;
+
return result;
}
@@ -133,7 +151,7 @@ bool Graph<VertexType, EdgeType>::isDirected() const {
}
template<typename VertexType, typename EdgeType>
-int Graph<VertexType, EdgeType>::insert(const VertexType & v) {
+int Graph<VertexType, EdgeType>::insert(const VertexType &v) {
for (int i = 0; i < vertex.size(); i++)
if (vertex[i].first == v)
return i;
@@ -141,10 +159,10 @@ int Graph<VertexType, EdgeType>::insert(const VertexType & v) {
vertex.push_back(std::make_pair(v, EdgeList()));
return vertex.size() - 1;
}
-
-
+
+
template<typename VertexType, typename EdgeType>
-void Graph<VertexType, EdgeType>::connect(int v1, int v2, const EdgeType &e) {
+void Graph<VertexType, EdgeType>::connect(int v1, int v2, const EdgeType &e) {
assert(v1 < vertex.size() && v2 < vertex.size());
vertex[v1].second[v2].push_back(e);;
@@ -153,19 +171,19 @@ void Graph<VertexType, EdgeType>::connect(int v1, int v2, const EdgeType &e) {
}
template<typename VertexType, typename EdgeType>
-void Graph<VertexType, EdgeType>::connect(int v1, int v2, const std::vector<EdgeType> &e) {
+void Graph<VertexType, EdgeType>::connect(int v1, int v2, const std::vector<EdgeType> &e) {
assert(v1 < vertex.size() && v2 < vertex.size());
if (e.size() == 0)
return;
-
+
copy(e.begin(), e.end(), back_inserter(vertex[v1].second[v2]));
if (!directed)
copy(e.begin(), e.end(), back_inserter(vertex[v2].second[v1]));
}
template<typename VertexType, typename EdgeType>
-void Graph<VertexType, EdgeType>::disconnect(int v1, int v2) {
+void Graph<VertexType, EdgeType>::disconnect(int v1, int v2) {
assert(v1 < vertex.size() && v2 < vertex.size());
vertex[v1].second.erase(v2);
@@ -174,12 +192,12 @@ void Graph<VertexType, EdgeType>::disconnect(int v1, int v2) {
}
template<typename VertexType, typename EdgeType>
-bool Graph<VertexType,EdgeType>::hasEdge(int v1, int v2) const {
+bool Graph<VertexType, EdgeType>::hasEdge(int v1, int v2) const {
return vertex[v1].second.find(v2) != vertex[v1].second.end();
}
template<typename VertexType, typename EdgeType>
-std::vector<EdgeType> Graph<VertexType,EdgeType>::getEdge(int v1, int v2) const {
+std::vector<EdgeType> Graph<VertexType, EdgeType>::getEdge(int v1, int v2) const {
if (!hasEdge(v1, v2))
return std::vector<EdgeType>();
@@ -194,9 +212,9 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::topoSort() const {
std::vector<int> order(n);
int c = n;
-
+
// first DFS
- for (int i = n-1; i >= 0; i--)
+ for (int i = n - 1; i >= 0; i--)
if (color[i] == WHITE) {
S.push(i);
while (!S.empty()) {
@@ -208,13 +226,11 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::topoSort() const {
S.push(j->first);
color[v] = GREY;
- }
- else if (color[v] == GREY) {
+ } else if (color[v] == GREY) {
color[v] = BLACK;
S.pop();
order[--c] = v;
- }
- else {
+ } else {
S.pop();
}
}
@@ -225,31 +241,29 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::topoSort() const {
for (int i = 0; i < n; i++)
for (typename EdgeList::const_iterator j = vertex[i].second.begin(); j != vertex[i].second.end(); j++)
edgeT[j->first].insert(i);
-
+
// second DFS in transposed graph starting from last finished vertex
fill(color.begin(), color.end(), WHITE);
std::vector<std::set<int> > result;
for (int i = 0; i < n; i++)
if (color[order[i]] == WHITE) {
std::set<int> s;
-
+
S.push(order[i]);
while (!S.empty()) {
int v = S.top();
-
- if(color[v] == WHITE) {
+
+ if (color[v] == WHITE) {
for (std::set<int>::const_iterator j = edgeT[v].begin(); j != edgeT[v].end(); j++)
if (color[*j] == WHITE)
S.push(*j);
color[v] = GREY;
- }
- else if (color[v] == GREY) {
+ } else if (color[v] == GREY) {
color[v] = BLACK;
S.pop();
s.insert(v);
- }
- else {
+ } else {
S.pop();
}
}
@@ -268,9 +282,9 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::packed_topoSort() const
std::vector<bool> is_root(n, false);
std::vector<std::set<int> > edges(n);
-
+
// first DFS
- for (int i = n-1; i >= 0; i--)
+ for (int i = n - 1; i >= 0; i--)
if (color[i] == WHITE) {
S.push(i);
is_root[i] = true;
@@ -282,8 +296,7 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::packed_topoSort() const
if (color[j->first] == WHITE) {
S.push(j->first);
edges[v].insert(j->first);
- }
- else if (color[j->first] == BLACK) {
+ } else if (color[j->first] == BLACK) {
if (is_root[j->first]) {
is_root[j->first] = false;
edges[v].insert(j->first);
@@ -291,12 +304,10 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::packed_topoSort() const
}
color[v] = GREY;
- }
- else if (color[v] == GREY) {
+ } else if (color[v] == GREY) {
color[v] = BLACK;
S.pop();
- }
- else {
+ } else {
S.pop();
}
}
@@ -313,7 +324,7 @@ std::vector<std::set<int> > Graph<VertexType, EdgeType>::packed_topoSort() const
result.push_back(s);
while (true) {
std::set<int> s;
- for (std::set<int>::iterator i = result[result.size()-1].begin(); i != result[result.size()-1].end(); i++)
+ for (std::set<int>::iterator i = result[result.size() - 1].begin(); i != result[result.size() - 1].end(); i++)
s.insert(edges[*i].begin(), edges[*i].end());
if (s.size() != 0)
result.push_back(s);
diff --git a/include/ir_clang.hh b/include/ir_clang.hh
index e637016..9148eb3 100755
--- a/include/ir_clang.hh
+++ b/include/ir_clang.hh
@@ -6,6 +6,7 @@
#include "chill_error.hh"
#define __STDC_CONSTANT_MACROS
+
#include "clang/AST/Decl.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ParentMap.h"
@@ -34,37 +35,39 @@ extern std::vector<chillAST_VarDecl *> VariableDeclarations; // a global. TOD
typedef llvm::SmallVector<clang::Stmt *, 16> StmtList; // TODO delete
-struct IR_chillScalarSymbol: public IR_ScalarSymbol {
- chillAST_VarDecl *chillvd;
+struct IR_chillScalarSymbol : public IR_ScalarSymbol {
+ chillAST_VarDecl *chillvd;
IR_chillScalarSymbol(const IR_Code *ir, chillAST_VarDecl *vd) {
- fprintf(stderr, "making scalar symbol %s\n", vd->varname);
+ fprintf(stderr, "making scalar symbol %s\n", vd->varname);
ir_ = ir;
chillvd = vd;
}
-
+
std::string name() const;
+
int size() const;
+
bool operator==(const IR_Symbol &that) const;
+
IR_Symbol *clone() const;
};
-
-struct IR_chillArraySymbol: public IR_ArraySymbol {
+struct IR_chillArraySymbol : public IR_ArraySymbol {
//int indirect_; // what was this?
int offset_; // what is this?
- chillAST_VarDecl *chillvd;
+ chillAST_VarDecl *chillvd;
IR_chillArraySymbol(const IR_Code *ir, chillAST_VarDecl *vd, int offset = 0) {
//if ( vd == 0 )
//fprintf(stderr, "IR_chillArraySymbol::IR_chillArraySymbol (%s) vd 0x%x\n", vd->varname, vd);
ir_ = ir;
- chillvd = vd;
+ chillvd = vd;
//indirect_ = indirect;
offset_ = offset;
}
-
+
// No Fortran support!
IR_ARRAY_LAYOUT_TYPE layout_type() const {
@@ -72,104 +75,115 @@ struct IR_chillArraySymbol: public IR_ArraySymbol {
}
std::string name() const;
+
int elem_size() const;
+
int n_dim() const;
+
omega::CG_outputRepr *size(int dim) const;
+
bool operator!=(const IR_Symbol &that) const;
+
bool operator==(const IR_Symbol &that) const;
+
IR_Symbol *clone() const;
- // TODO Hack to pass build
+
+ // TODO Hack to pass build
IR_CONSTANT_TYPE elem_type() const {
- fprintf(stderr,"Not implemented elem_type in IR_chillArraySymbol");
- return IR_CONSTANT_UNKNOWN;};
-
-};
+ fprintf(stderr, "Not implemented elem_type in IR_chillArraySymbol");
+ return IR_CONSTANT_UNKNOWN;
+ };
+};
-struct IR_chillConstantRef: public IR_ConstantRef {
+struct IR_chillConstantRef : public IR_ConstantRef {
union {
omega::coef_t i_;
double f_;
};
-
+
IR_chillConstantRef(const IR_Code *ir, omega::coef_t i) {
ir_ = ir;
type_ = IR_CONSTANT_INT;
i_ = i;
}
+
IR_chillConstantRef(const IR_Code *ir, double f) {
ir_ = ir;
type_ = IR_CONSTANT_FLOAT;
f_ = f;
}
+
omega::coef_t integer() const {
assert(is_integer());
return i_;
}
+
bool operator==(const IR_Ref &that) const;
+
omega::CG_outputRepr *convert();
+
IR_Ref *clone() const;
-
+
};
-enum OP_POSITION { OP_DEST =-1, OP_UNKNOWN, OP_SRC };
+enum OP_POSITION {
+ OP_DEST = -1, OP_UNKNOWN, OP_SRC
+};
#define OP_LEFT OP_DEST
#define OP_RIGHT OP_SRC
-struct IR_chillScalarRef: public IR_ScalarRef {
+struct IR_chillScalarRef : public IR_ScalarRef {
OP_POSITION op_pos_; // -1 means destination operand, 0== unknown, 1 == source operand
//chillAST_BinaryOperator *bop; // binary op that contains this scalar?
- chillAST_DeclRefExpr *dre; // declrefexpr that uses this scalar ref, if that exists
- chillAST_VarDecl *chillvd; // the vardecl for this scalar
-
+ chillAST_DeclRefExpr *dre; // declrefexpr that uses this scalar ref, if that exists
+ chillAST_VarDecl *chillvd; // the vardecl for this scalar
+
IR_chillScalarRef(const IR_Code *ir, chillAST_BinaryOperator *ins, OP_POSITION pos) {
- fprintf(stderr, "\n***** new IR_xxxxScalarRef( ir, ins, pos ) *****\n\n");
- exit(-1);
+ fprintf(stderr, "\n***** new IR_xxxxScalarRef( ir, ins, pos ) *****\n\n");
+ exit(-1);
// this constructor takes a binary operation and an indicator of which side of the op to use,
// and finds the scalar in the lhs or rhs of the binary op.
ir_ = ir;
dre = NULL;
//bop = ins; // do we need this?
- if (pos == OP_LEFT) {
+ if (pos == OP_LEFT) {
chillAST_node *lhs = ins->lhs;
- if (lhs->isDeclRefExpr()) {
+ if (lhs->isDeclRefExpr()) {
chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) lhs;
- dre = DRE;
+ dre = DRE;
chillvd = DRE->getVarDecl();
+ } else if (lhs->isVarDecl()) {
+ chillvd = (chillAST_VarDecl *) lhs;
+ } else {
+ fprintf(stderr, "IR_chillScalarRef constructor, I'm confused\n");
+ exit(-1);
}
- else if (lhs->isVarDecl()) {
- chillvd = (chillAST_VarDecl *)lhs;
- }
- else {
- fprintf(stderr, "IR_chillScalarRef constructor, I'm confused\n"); exit(-1);
- }
- }
- else {
+ } else {
chillAST_node *rhs = ins->rhs;
- if (rhs->isDeclRefExpr()) {
+ if (rhs->isDeclRefExpr()) {
chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) rhs;
dre = DRE;
chillvd = DRE->getVarDecl();
- }
- else if (rhs->isVarDecl()) {
- chillvd = (chillAST_VarDecl *)rhs;
- }
- else {
- fprintf(stderr, "IR_chillScalarRef constructor, I'm confused\n"); exit(-1);
+ } else if (rhs->isVarDecl()) {
+ chillvd = (chillAST_VarDecl *) rhs;
+ } else {
+ fprintf(stderr, "IR_chillScalarRef constructor, I'm confused\n");
+ exit(-1);
}
}
op_pos_ = pos;
}
- IR_chillScalarRef(const IR_Code *ir, chillAST_DeclRefExpr *d) {
+ IR_chillScalarRef(const IR_Code *ir, chillAST_DeclRefExpr *d) {
// fprintf(stderr, "\n***** new IR_xxxxScalarRef( ir, REF EXPR sym %s ) *****\n\n", d->getVarDecl()->varname);
//fprintf(stderr, "new IR_chillScalarRef with a DECLREFEXPR (has dre) \n");
ir_ = ir;
dre = d;
//bop = NULL;
- chillvd = d->getVarDecl();
- op_pos_ = OP_UNKNOWN;
+ chillvd = d->getVarDecl();
+ op_pos_ = OP_UNKNOWN;
//fprintf(stderr, "\nScalarRef has:\n");
//fprintf(stderr, "assignment op DOESNT EXIST\n");
@@ -178,14 +192,16 @@ struct IR_chillScalarRef: public IR_ScalarRef {
//fprintf(stderr, "ref expr dre = 0x%x\n", dre);
}
- IR_chillScalarRef(const IR_Code *ir, chillAST_VarDecl *vardecl) {
- fprintf(stderr, "\n***** new IR_xxxxScalarRef( ir, sym 0x1234567 ) ***** THIS SHOULD NEVER HAPPEN\n\n");
- fprintf(stderr, "vardecl %s\n", vardecl->varname);
+ IR_chillScalarRef(const IR_Code *ir, chillAST_VarDecl *vardecl) {
+ fprintf(stderr,
+ "\n***** new IR_xxxxScalarRef( ir, sym 0x1234567 ) ***** THIS SHOULD NEVER HAPPEN\n\n");
+ fprintf(stderr, "vardecl %s\n", vardecl->varname);
ir_ = ir;
- dre = NULL; fprintf(stderr, "new IR_chillScalarRef with a vardecl but no dre\n");
+ dre = NULL;
+ fprintf(stderr, "new IR_chillScalarRef with a vardecl but no dre\n");
//bop = NULL;
- chillvd = vardecl;
- op_pos_ = OP_UNKNOWN;
+ chillvd = vardecl;
+ op_pos_ = OP_UNKNOWN;
//fprintf(stderr, "\nScalarRef has:\n");
//fprintf(stderr, "assignment op DOESNT EXIST\n");
@@ -194,21 +210,24 @@ struct IR_chillScalarRef: public IR_ScalarRef {
//fprintf(stderr, "ref expr dre = 0x%x\n", dre);
}
-
+
bool is_write() const;
+
IR_ScalarSymbol *symbol() const;
+
bool operator==(const IR_Ref &that) const;
+
omega::CG_outputRepr *convert();
+
IR_Ref *clone() const;
};
-
-struct IR_chillArrayRef: public IR_ArrayRef {
+struct IR_chillArrayRef : public IR_ArrayRef {
//DeclRefExpr *as_;
//chillAST_DeclRefExpr *chillDRE;
- chillAST_ArraySubscriptExpr* chillASE;
- int iswrite;
+ chillAST_ArraySubscriptExpr *chillASE;
+ int iswrite;
// IR_chillArrayRef(const IR_Code *ir, DeclRefExpr *as, ParentMap *pMap = NULL) {
@@ -216,102 +235,118 @@ struct IR_chillArrayRef: public IR_ArrayRef {
// fprintf(stderr, "new IR_chillArrayRef() CLANG ERROR\n"); exit(-1);
//}
- IR_chillArrayRef(const IR_Code *ir, chillAST_ArraySubscriptExpr *ase, int write ) {
+ IR_chillArrayRef(const IR_Code *ir, chillAST_ArraySubscriptExpr *ase, int write) {
//fprintf(stderr, "IR_chillArrayRef::IR_chillArrayRef() write %d\n", write);
ir_ = ir;
- chillASE = ase;
+ chillASE = ase;
iswrite = write; // ase->imwrittento;
}
bool is_write() const;
+
omega::CG_outputRepr *index(int dim) const;
+
IR_ArraySymbol *symbol() const;
+
bool operator!=(const IR_Ref &that) const;
+
bool operator==(const IR_Ref &that) const;
+
omega::CG_outputRepr *convert();
+
IR_Ref *clone() const;
+
virtual void Dump() const;
};
-
-struct IR_chillLoop: public IR_Loop {
+struct IR_chillLoop : public IR_Loop {
int step_size_;
chillAST_DeclRefExpr *chillindex; // the loop index variable (I) // was DeclRefExpr
- chillAST_ForStmt *chillforstmt;
- chillAST_node *chilllowerbound;
- chillAST_node *chillupperbound;
- chillAST_node *chillbody; // presumably a compound statement, but not guaranteeed
+ chillAST_ForStmt *chillforstmt;
+ chillAST_node *chilllowerbound;
+ chillAST_node *chillupperbound;
+ chillAST_node *chillbody; // presumably a compound statement, but not guaranteeed
IR_CONDITION_TYPE conditionoperator;
IR_chillLoop(const IR_Code *ir, clang::ForStmt *tf);
+
IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *forstmt);
~IR_chillLoop() {}
+
IR_ScalarSymbol *index() const { return new IR_chillScalarSymbol(ir_, chillindex->getVarDecl()); }
+
omega::CG_outputRepr *lower_bound() const;
+
omega::CG_outputRepr *upper_bound() const;
+
IR_CONDITION_TYPE stop_cond() const;
+
IR_Block *body() const;
-
+
// Handle following types of increment expressions:
-
+
// Unary increment/decrement
// i += K OR i -= K
// i = i + K OR i = i - K
// where K is positive
int step_size() const { return step_size_; } // K is always an integer ???
IR_Control *clone() const;
- IR_Block *convert() ;
- virtual void dump() const;
-};
+ IR_Block *convert();
+ virtual void dump() const;
+};
-struct IR_chillBlock: public IR_Block { // ONLY ONE OF bDecl or cs_ will be nonNULL ??
+struct IR_chillBlock : public IR_Block { // ONLY ONE OF bDecl or cs_ will be nonNULL ??
private:
//StmtList bDecl_; // declarations in the block??
//clang::CompoundStmt *cs_; // will a block always have a compound statement? (no)
//StmtList *stmts; // ??
public:
-
+
// Block is a basic block?? (no, just a chunk of code )
- std::vector<chillAST_node *>statements;
- chillAST_node *chillAST; // how about for now we say if there are statements, which is presumably the top level of statements from ... somewhere, otherwise the code is in chillAST
-
- IR_chillBlock( const IR_chillBlock *CB ) { // clone existing IR_chillBlock
+ std::vector<chillAST_node *> statements;
+
+ IR_chillBlock(const IR_chillBlock *CB) { // clone existing IR_chillBlock
ir_ = CB->ir_;
- for (int i=0; i<CB->statements.size(); i++) statements.push_back( CB->statements[i] );
- chillAST = CB->chillAST;
+ for (int i = 0; i < CB->statements.size(); i++) statements.push_back(CB->statements[i]);
}
- IR_chillBlock(const IR_Code *ir, chillAST_node *ast) {
+ IR_chillBlock(const IR_Code *ir, std::vector<chillAST_node *> ast) : statements(ast) {
ir_ = ir;
- chillAST = ast;
}
- IR_chillBlock(const IR_Code *ir) { // : cs_(NULL), bDecl_(NULL) {
- chillAST = NULL;
+ IR_chillBlock(const IR_Code *ir, chillAST_node *ast = NULL) { // : cs_(NULL), bDecl_(NULL) {
ir_ = ir;
+ if (ast != NULL)
+ statements.push_back(ast);
}
-
+
~IR_chillBlock() {}
+
omega::CG_outputRepr *extract() const;
+
omega::CG_outputRepr *original() const;
+
IR_Control *clone() const;
+
//StmtList getStmtList() const;
- std::vector<chillAST_node*> getStmtList() const;
- int numstatements() { return statements.size(); } ;
- void addStatement( chillAST_node* s );
+ std::vector<chillAST_node *> getStmtList() const;
- void dump() const;
+ int numstatements() { return statements.size(); };
+
+ void addStatement(chillAST_node *s);
+
+ void dump() const;
};
-#ifdef NOTYET
+#ifdef NOTYET
struct IR_clangIf: public IR_If {
SgNode *ti_;
@@ -327,20 +362,17 @@ struct IR_clangIf: public IR_If {
IR_Block *convert();
IR_Control *clone() const;
};
-#endif
-
-
-
+#endif
class aClangCompiler {
private:
//Chill_ASTConsumer *astConsumer_;
clang::ASTContext *astContext_;
-
+
clang::DiagnosticOptions *diagnosticOptions;
clang::TextDiagnosticPrinter *pTextDiagnosticPrinter;
- llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID ;
+ llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID;
clang::DiagnosticsEngine *diagnosticsEngine;
clang::CompilerInstance *Clang;
clang::Preprocessor *preprocessor;
@@ -365,15 +397,17 @@ private:
public:
- char *SourceFileName;
- chillAST_SourceFile * entire_file_AST; // TODO move out of public
+ char *SourceFileName;
+ chillAST_SourceFile *entire_file_AST; // TODO move out of public
+
+ aClangCompiler(char *filename); // constructor
+ chillAST_FunctionDecl *findprocedurebyname(char *name); // someday, return the chill AST
+ clang::FunctionDecl *FD;
- aClangCompiler( char *filename ); // constructor
- chillAST_FunctionDecl *findprocedurebyname( char *name ); // someday, return the chill AST
- clang::FunctionDecl *FD;
//Chill_ASTConsumer *getASTConsumer() { return astConsumer_; }
- clang::ASTContext *getASTContext() { return astContext_; }
- clang::SourceManager *getASTSourceManager() { return sourceManager; };
+ clang::ASTContext *getASTContext() { return astContext_; }
+
+ clang::SourceManager *getASTSourceManager() { return sourceManager; };
};
@@ -385,32 +419,37 @@ private:
// protecting the constructor is the SINGLETON PATTERN. a global by any other name
// IR_clangCode_Global_Init();
~IR_clangCode_Global_Init(); // is this hidden, too?
- chillAST_FunctionDecl * chillFD; // the original C code
+ chillAST_FunctionDecl *chillFD; // the original C code
- clang::ASTContext *astContext_;
+ clang::ASTContext *astContext_;
clang::SourceManager *sourceManager;
public:
clang::ASTContext *getASTContext() { return astContext_; }
- clang::SourceManager *getSourceManager() { return sourceManager; };
+
+ clang::SourceManager *getSourceManager() { return sourceManager; };
+
static IR_clangCode_Global_Init *Instance(char **argv);
- static IR_clangCode_Global_Init *Instance() { return pinstance; } ;
+
+ static IR_clangCode_Global_Init *Instance() { return pinstance; };
aClangCompiler *ClangCompiler; // this is the thing we really just want one of
- void setCurrentFunction( chillAST_node *F ) { chillFD = (chillAST_FunctionDecl *)F; } ;
- chillAST_FunctionDecl *getCurrentFunction( ) { return chillFD; } ;
+ void setCurrentFunction(chillAST_node *F) { chillFD = (chillAST_FunctionDecl *) F; };
+ chillAST_FunctionDecl *getCurrentFunction() { return chillFD; };
- void setCurrentASTContext( clang::ASTContext *A ) { astContext_ = A;};
- clang::ASTContext *getCurrentASTContext() { return astContext_; } ;
- void setCurrentASTSourceManager( clang::SourceManager *S ) { sourceManager = S; } ;
- clang::SourceManager *getCurrentASTSourceManager() { return sourceManager; } ;
-};
+ void setCurrentASTContext(clang::ASTContext *A) { astContext_ = A; };
+
+ clang::ASTContext *getCurrentASTContext() { return astContext_; };
+ void setCurrentASTSourceManager(clang::SourceManager *S) { sourceManager = S; };
+
+ clang::SourceManager *getCurrentASTSourceManager() { return sourceManager; };
+};
-class IR_clangCode: public IR_Code{ // for an entire file? A single function?
+class IR_clangCode : public IR_Code { // for an entire file? A single function?
protected:
//
@@ -419,12 +458,12 @@ protected:
chillAST_node *entire_file_AST;
- chillAST_FunctionDecl * chillfunc; // the function we're currenly modifying
+ chillAST_FunctionDecl *chillfunc; // the function we're currenly modifying
std::vector<chillAST_VarDecl> entire_file_symbol_table;
// loop symbol table?? for (int i=0; ... ) ??
-
-
+
+
clang::FunctionDecl *func_; // a clang construct the function we're currenly modifying
clang::ASTContext *astContext_;
@@ -436,32 +475,48 @@ protected:
//
public:
- clang::ASTContext *getASTContext() { return astContext_; } ;
- clang::SourceManager *getASTSourceManager() { return sourceManager; } ;
+ clang::ASTContext *getASTContext() { return astContext_; };
+
+ clang::SourceManager *getASTSourceManager() { return sourceManager; };
IR_clangCode(const char *filename, const char *proc_name);
+
~IR_clangCode();
IR_ScalarSymbol *CreateScalarSymbol(const IR_Symbol *sym, int i);
+
IR_ArraySymbol *CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outputRepr *> &size, int i);
+
IR_ScalarRef *CreateScalarRef(const IR_ScalarSymbol *sym);
+
IR_ArrayRef *CreateArrayRef(const IR_ArraySymbol *sym, std::vector<omega::CG_outputRepr *> &index);
- int ArrayIndexStartAt() { return 0;} // TODO FORTRAN
-
+
+ int ArrayIndexStartAt() { return 0; } // TODO FORTRAN
+
std::vector<IR_ScalarRef *> FindScalarRef(const omega::CG_outputRepr *repr) const;
+
std::vector<IR_ArrayRef *> FindArrayRef(const omega::CG_outputRepr *repr) const;
+
std::vector<IR_Control *> FindOneLevelControlStructure(const IR_Block *block) const;
+
IR_Block *MergeNeighboringControlStructures(const std::vector<IR_Control *> &controls) const;
+
IR_Block *GetCode() const;
+
void ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr);
+
void ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr);
-
- IR_CONDITION_TYPE QueryBooleanExpOperation(const omega::CG_outputRepr*) const;
+
+ IR_CONDITION_TYPE QueryBooleanExpOperation(const omega::CG_outputRepr *) const;
+
IR_OPERATION_TYPE QueryExpOperation(const omega::CG_outputRepr *repr) const;
+
std::vector<omega::CG_outputRepr *> QueryExpOperand(const omega::CG_outputRepr *repr) const;
+
IR_Ref *Repr2Ref(const omega::CG_outputRepr *) const;
-
+
friend class IR_chillArraySymbol;
+
friend class IR_chillArrayRef;
};
diff --git a/include/ir_code.hh b/include/ir_code.hh
index e3fd8ea..813fc0d 100644
--- a/include/ir_code.hh
+++ b/include/ir_code.hh
@@ -35,7 +35,6 @@
#include <code_gen/CG_outputBuilder.h>
-
class IR_Code; // forward declaration
@@ -45,14 +44,18 @@ struct IR_Symbol {
const IR_Code *ir_;
virtual ~IR_Symbol() {/* ir_ is not the responsibility of this object */}
+
virtual int n_dim() const = 0; // IR_Symbol
virtual std::string name() const = 0;
+
virtual bool operator==(const IR_Symbol &that) const = 0;
- virtual bool operator!=(const IR_Symbol &that) const {return !(*this == that);}
+
+ virtual bool operator!=(const IR_Symbol &that) const { return !(*this == that); }
+
virtual IR_Symbol *clone() const = 0; /* shallow copy */
- virtual bool isScalar() const { return false; } // default
- virtual bool isArray() const { return false; } // default
+ virtual bool isScalar() const { return false; } // default
+ virtual bool isArray() const { return false; } // default
virtual bool isPointer() const { return false; } // default
//IR_SYMBOL_TYPE symtype; // base type: int, float, double, struct, .... typedef'd something
@@ -60,29 +63,40 @@ struct IR_Symbol {
};
-struct IR_ScalarSymbol: public IR_Symbol {
+struct IR_ScalarSymbol : public IR_Symbol {
virtual ~IR_ScalarSymbol() {}
- int n_dim() const {return 0;} // IR_ScalarSymbol
+
+ int n_dim() const { return 0; } // IR_ScalarSymbol
virtual int size() const = 0;
+
bool isScalar() const { return true; }
};
-struct IR_ArraySymbol: public IR_Symbol {
+struct IR_ArraySymbol : public IR_Symbol {
virtual ~IR_ArraySymbol() {}
+
virtual int elem_size() const = 0;
+
virtual omega::CG_outputRepr *size(int dim) const = 0;
+
virtual IR_ARRAY_LAYOUT_TYPE layout_type() const = 0;
+
virtual IR_CONSTANT_TYPE elem_type() const = 0;
+
bool isArray() const { return true; }
};
-struct IR_PointerSymbol: public IR_Symbol {
+struct IR_PointerSymbol : public IR_Symbol {
virtual ~IR_PointerSymbol() {}
+
virtual omega::CG_outputRepr *size(int dim) const = 0;
- virtual void set_size(int dim, omega::CG_outputRepr*) = 0;
+
+ virtual void set_size(int dim, omega::CG_outputRepr *) = 0;
+
virtual IR_CONSTANT_TYPE elem_type() const = 0;
+
bool isPointer() const { return true; }
};
@@ -90,41 +104,58 @@ struct IR_PointerSymbol: public IR_Symbol {
// place holder for related code in IR code.
struct IR_Ref {
const IR_Code *ir_;
-
+
virtual ~IR_Ref() {/* ir_ is not the responsibility of this object */}
- virtual int n_dim() const = 0; // IR_Ref
+
+ virtual int n_dim() const = 0; // IR_Ref
virtual bool is_write() const = 0;
+
virtual std::string name() const = 0;
+
virtual bool operator==(const IR_Ref &that) const = 0;
- virtual bool operator!=(const IR_Ref &that) const {return !(*this == that);}
+
+ virtual bool operator!=(const IR_Ref &that) const { return !(*this == that); }
+
virtual omega::CG_outputRepr *convert() = 0;
+
virtual IR_Ref *clone() const = 0; /* shallow copy */
- virtual void Dump() const { fprintf(stderr, "some IR_*Ref needs to implement Dump()\n"); int *i=0; int j=i[0]; };
+ virtual void Dump() const {
+ fprintf(stderr, "some IR_*Ref needs to implement Dump()\n");
+ int *i = 0;
+ int j = i[0];
+ };
};
-struct IR_ConstantRef: public IR_Ref {
+struct IR_ConstantRef : public IR_Ref {
IR_CONSTANT_TYPE type_;
virtual ~IR_ConstantRef() {}
- int n_dim() const {return 0;} // IR_ConstantRef
- bool is_write() const {return false;}
- std::string name() const {return std::string();}
- virtual bool is_integer() const {return type_ == IR_CONSTANT_INT;}
+
+ int n_dim() const { return 0; } // IR_ConstantRef
+ bool is_write() const { return false; }
+
+ std::string name() const { return std::string(); }
+
+ virtual bool is_integer() const { return type_ == IR_CONSTANT_INT; }
+
virtual omega::coef_t integer() const = 0;
};
-
-struct IR_ScalarRef: public IR_Ref {
+
+struct IR_ScalarRef : public IR_Ref {
virtual ~IR_ScalarRef() {}
- int n_dim() const {return 0;} // IR_ScalarRef
+
+ int n_dim() const { return 0; } // IR_ScalarRef
virtual IR_ScalarSymbol *symbol() const = 0;
+
std::string name() const {
IR_ScalarSymbol *sym = symbol(); // really inefficient. MAKE a symbol, just to get a name
std::string s = sym->name();
delete sym;
return s;
}
+
virtual int size() const {
IR_ScalarSymbol *sym = symbol();
int s = sym->size();
@@ -134,16 +165,20 @@ struct IR_ScalarRef: public IR_Ref {
};
-struct IR_ArrayRef: public IR_Ref {
+struct IR_ArrayRef : public IR_Ref {
virtual ~IR_ArrayRef() {}
- int n_dim() const { // IR_ArrayRef returns the size of the array
+
+ int n_dim() const { // IR_ArrayRef returns the size of the array
IR_ArraySymbol *sym = symbol();
int n = sym->n_dim();
// ?? delete sym;
return n;
}
+
virtual omega::CG_outputRepr *index(int dim) const = 0;
+
virtual IR_ArraySymbol *symbol() const = 0;
+
virtual std::string name() const {
// makes (constructs!) a symbol, just to copy a string!
IR_ArraySymbol *sym = symbol(); // TODO exceedingly wasteful
@@ -151,26 +186,30 @@ struct IR_ArrayRef: public IR_Ref {
// ?? delete sym; (goes out of scope, so deletes itself)
return s; // s ALSO goes out of scope but perhaps the info is copied at the other end
}
+
virtual int elem_size() const {
IR_ArraySymbol *sym = symbol();
int s = sym->elem_size();
// ?? delete sym;
return s;
}
+
virtual IR_ARRAY_LAYOUT_TYPE layout_type() const {
IR_ArraySymbol *sym = symbol();
IR_ARRAY_LAYOUT_TYPE t = sym->layout_type();
// ?? delete sym;
return t;
}
+
virtual void Dump() const { fprintf(stderr, "IR_ArrayRef needs to implement Dump()\n"); };
};
-struct IR_PointerArrayRef: public IR_Ref {
+struct IR_PointerArrayRef : public IR_Ref {
const IR_Code *ir_;
virtual ~IR_PointerArrayRef() {}
+
int n_dim() const { // IR_PointerArrayRef returns size of the ... symbol?
IR_PointerSymbol *sym = symbol();
int n = sym->n_dim();
@@ -178,8 +217,11 @@ struct IR_PointerArrayRef: public IR_Ref {
//delete sym;
return n;
}
+
virtual omega::CG_outputRepr *index(int dim) const = 0;
+
virtual IR_PointerSymbol *symbol() const = 0;
+
std::string name() const {
IR_PointerSymbol *sym = symbol();
std::string s = sym->name();
@@ -205,44 +247,61 @@ struct IR_Control {
const IR_Code *ir_; // hate this
virtual ~IR_Control() {/* ir_ is not the responsibility of this object */}
+
virtual IR_CONTROL_TYPE type() const = 0;
+
virtual IR_Block *convert() = 0;
+
virtual IR_Control *clone() const = 0; /* shallow copy */
};
-struct IR_Loop: public IR_Control {
+struct IR_Loop : public IR_Control {
virtual ~IR_Loop() {}
+
virtual IR_ScalarSymbol *index() const = 0;
+
virtual omega::CG_outputRepr *lower_bound() const = 0;
+
virtual omega::CG_outputRepr *upper_bound() const = 0;
+
virtual IR_CONDITION_TYPE stop_cond() const = 0;
+
virtual IR_Block *body() const = 0;
+
virtual int step_size() const = 0;
+
IR_CONTROL_TYPE type() const { return IR_CONTROL_LOOP; }
};
-struct IR_Block: public IR_Control {
+struct IR_Block : public IR_Control {
virtual ~IR_Block() {}
+
virtual omega::CG_outputRepr *extract() const = 0;
- IR_Block *convert() {return this;}
+
+ IR_Block *convert() { return this; }
+
IR_CONTROL_TYPE type() const { return IR_CONTROL_BLOCK; }
+
virtual omega::CG_outputRepr *original() const = 0;
};
-struct IR_If: public IR_Control {
+struct IR_If : public IR_Control {
virtual ~IR_If() {}
+
virtual omega::CG_outputRepr *condition() const = 0;
+
virtual IR_Block *then_body() const = 0;
+
virtual IR_Block *else_body() const = 0;
+
IR_CONTROL_TYPE type() const { return IR_CONTROL_IF; }
};
-
-struct IR_While: public IR_Control {
+struct IR_While : public IR_Control {
// NOT IMPLEMENTED
};
@@ -263,32 +322,52 @@ protected:
public:
int getPointerCounter() { return ir_pointer_counter; }
- int getArrayCounter() { return ir_array_counter; }
+
+ int getArrayCounter() { return ir_array_counter; }
// TODO can't get the initialize of counters to work !!
- int getAndIncrementPointerCounter() { if (ir_pointer_counter == 0) ir_pointer_counter= 1; ir_pointer_counter++; return ir_pointer_counter-1; }
- int getAndIncrementArrayCounter() { if (ir_array_counter == 0) ir_array_counter= 1; ir_array_counter += 1; return ir_array_counter-1; }
+ int getAndIncrementPointerCounter() {
+ if (ir_pointer_counter == 0) ir_pointer_counter = 1;
+ ir_pointer_counter++;
+ return ir_pointer_counter - 1;
+ }
+
+ int getAndIncrementArrayCounter() {
+ if (ir_array_counter == 0) ir_array_counter = 1;
+ ir_array_counter += 1;
+ return ir_array_counter - 1;
+ }
// if all flavors of ir_code use chillAST internally ...
- chillAST_FunctionDecl * func_defn; // the function we're modifying
- chillAST_FunctionDecl *GetChillFuncDefinition() { return func_defn; };
+ chillAST_FunctionDecl *func_defn; // the function we're modifying
+ chillAST_FunctionDecl *GetChillFuncDefinition() { return func_defn; };
- IR_Code() {ocg_ = NULL; init_code_ = cleanup_code_ = NULL;}
- virtual ~IR_Code() { delete ocg_; delete init_code_; delete cleanup_code_; } /* the content of init and cleanup code have already been released in derived classes */
-
- omega::CG_outputRepr* init_code(){ return init_code_; }
+ IR_Code() {
+ ocg_ = NULL;
+ init_code_ = cleanup_code_ = NULL;
+ }
+
+ virtual ~IR_Code() {
+ delete ocg_;
+ delete init_code_;
+ delete cleanup_code_;
+ } /* the content of init and cleanup code have already been released in derived classes */
+
+ omega::CG_outputRepr *init_code() { return init_code_; }
// memory_type is for differentiating the location of where the new memory is allocated.
// this is useful for processors with heterogeneous memory hierarchy.
virtual IR_ScalarSymbol *CreateScalarSymbol(const IR_Symbol *sym, int memory_type) = 0;
- virtual IR_ScalarSymbol *CreateScalarSymbol(IR_CONSTANT_TYPE type, int memory_type, std::string name="" ) {
+
+ virtual IR_ScalarSymbol *CreateScalarSymbol(IR_CONSTANT_TYPE type, int memory_type, std::string name = "") {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual IR_ArraySymbol *CreateArraySymbol(const IR_Symbol *sym,
- std::vector<omega::CG_outputRepr *> &size,
+ virtual IR_ArraySymbol *CreateArraySymbol(const IR_Symbol *sym,
+ std::vector<omega::CG_outputRepr *> &size,
int memory_type) = 0;
+
virtual IR_ArraySymbol *CreateArraySymbol(omega::CG_outputRepr *type,
std::vector<omega::CG_outputRepr *> &size_repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
@@ -300,9 +379,10 @@ public:
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
+
virtual IR_PointerSymbol *CreatePointerSymbol(const IR_CONSTANT_TYPE type,
- std::vector<omega::CG_outputRepr *> &size_repr,
- std::string name="") {
+ std::vector<omega::CG_outputRepr *> &size_repr,
+ std::string name = "") {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
@@ -314,56 +394,68 @@ public:
}
virtual IR_ScalarRef *CreateScalarRef(const IR_ScalarSymbol *sym) = 0;
+
virtual IR_ArrayRef *CreateArrayRef(const IR_ArraySymbol *sym, std::vector<omega::CG_outputRepr *> &index) = 0;
- virtual omega::CG_outputRepr* CreateArrayRefRepr(const IR_ArraySymbol *sym,
- std::vector<omega::CG_outputRepr *> &index) {
+ virtual omega::CG_outputRepr *CreateArrayRefRepr(const IR_ArraySymbol *sym,
+ std::vector<omega::CG_outputRepr *> &index) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
- return NULL;
+ return NULL;
}
- virtual IR_PointerArrayRef *CreatePointerArrayRef( IR_PointerSymbol *sym,
- std::vector<omega::CG_outputRepr *> &index) {
+ virtual IR_PointerArrayRef *CreatePointerArrayRef(IR_PointerSymbol *sym,
+ std::vector<omega::CG_outputRepr *> &index) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual int ArrayIndexStartAt() {return 0;}
- virtual void CreateDefineMacro(std::string s,std::string args, omega::CG_outputRepr *repr) {
+ virtual int ArrayIndexStartAt() { return 0; }
+
+ virtual void CreateDefineMacro(std::string s, std::string args, omega::CG_outputRepr *repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
}
- virtual void CreateDefineMacro(std::string s,std::string args, std::string repr) {
+
+ virtual void CreateDefineMacro(std::string s, std::string args, std::string repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
}
- virtual void CreateDefineMacro(std::string s, std::vector<std::string> args,omega::CG_outputRepr *repr) {}; // TODO make pure virtual
- virtual omega::CG_outputRepr *CreateArrayType(IR_CONSTANT_TYPE type, omega::CG_outputRepr* size){
+ virtual void CreateDefineMacro(std::string s, std::vector<std::string> args,
+ omega::CG_outputRepr *repr) {}; // TODO make pure virtual
+
+ virtual omega::CG_outputRepr *CreateArrayType(IR_CONSTANT_TYPE type, omega::CG_outputRepr *size) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual omega::CG_outputRepr *CreatePointerType(IR_CONSTANT_TYPE type){
+
+ virtual omega::CG_outputRepr *CreatePointerType(IR_CONSTANT_TYPE type) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual omega::CG_outputRepr *CreatePointerType(omega::CG_outputRepr *type){
+
+ virtual omega::CG_outputRepr *CreatePointerType(omega::CG_outputRepr *type) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual omega::CG_outputRepr *CreateScalarType(IR_CONSTANT_TYPE type){
+
+ virtual omega::CG_outputRepr *CreateScalarType(IR_CONSTANT_TYPE type) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
+
// Array references should be returned in their accessing order.
// e.g. s1: A[i] = A[i-1]
// s2: B[C[i]] = D[i] + E[i]
// return A[i-1], A[i], D[i], E[i], C[i], B[C[i]] in this order.
virtual std::vector<IR_ArrayRef *> FindArrayRef(const omega::CG_outputRepr *repr) const = 0;
- virtual std::vector<IR_PointerArrayRef *> FindPointerArrayRef(const omega::CG_outputRepr *repr) const{
+
+ virtual std::vector<IR_PointerArrayRef *> FindPointerArrayRef(const omega::CG_outputRepr *repr) const {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return std::vector<IR_PointerArrayRef *>();
}
+
virtual std::vector<IR_ScalarRef *> FindScalarRef(const omega::CG_outputRepr *repr) const = 0;
- virtual bool parent_is_array(IR_ArrayRef *a){
+
+ virtual bool parent_is_array(IR_ArrayRef *a) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return false;
}
@@ -375,70 +467,86 @@ public:
// All controls must be in the same block, at the same level and in
// contiguous lexical order as appeared in parameter vector.
virtual IR_Block *MergeNeighboringControlStructures(const std::vector<IR_Control *> &controls) const = 0;
-
+
virtual IR_Block *GetCode() const = 0;
+
virtual IR_Control *GetCode(omega::CG_outputRepr *code) const {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
+
virtual void ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) = 0;
+
virtual void ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr) = 0;
-
+
virtual IR_OPERATION_TYPE QueryExpOperation(const omega::CG_outputRepr *repr) const = 0;
+
virtual IR_CONDITION_TYPE QueryBooleanExpOperation(const omega::CG_outputRepr *repr) const = 0;
+
virtual std::vector<omega::CG_outputRepr *> QueryExpOperand(const omega::CG_outputRepr *repr) const = 0;
+
virtual IR_Ref *Repr2Ref(const omega::CG_outputRepr *repr) const = 0;
// Manu:: Added functions required for reduction operation
- // virtual omega::CG_outputRepr * FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B) = 0;
- virtual bool FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B){
+ // virtual omega::CG_outputRepr * FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B) = 0;
+ virtual bool FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual void printStmt(const omega::CG_outputRepr *repr){
+
+ virtual void printStmt(const omega::CG_outputRepr *repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
}
- virtual int getStmtType(const omega::CG_outputRepr *repr){
+
+ virtual int getStmtType(const omega::CG_outputRepr *repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return 0;
}
- virtual IR_OPERATION_TYPE getReductionOp(const omega::CG_outputRepr *repr){
+
+ virtual IR_OPERATION_TYPE getReductionOp(const omega::CG_outputRepr *repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return IR_OP_MINUS;
}
- virtual IR_Control * FromForStmt(const omega::CG_outputRepr *repr){
+
+ virtual IR_Control *FromForStmt(const omega::CG_outputRepr *repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
// Manu:: Added functions for scalar expansion
- virtual IR_ArraySymbol *CreateArraySymbol(omega::CG_outputRepr *size, const IR_Symbol *sym){
+ virtual IR_ArraySymbol *CreateArraySymbol(omega::CG_outputRepr *size, const IR_Symbol *sym) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual bool ReplaceRHSExpression(omega::CG_outputRepr *code, IR_Ref *ref){
+
+ virtual bool ReplaceRHSExpression(omega::CG_outputRepr *code, IR_Ref *ref) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual omega::CG_outputRepr * GetRHSExpression(omega::CG_outputRepr *code){
+
+ virtual omega::CG_outputRepr *GetRHSExpression(omega::CG_outputRepr *code) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual omega::CG_outputRepr * GetLHSExpression(omega::CG_outputRepr *code){
+
+ virtual omega::CG_outputRepr *GetLHSExpression(omega::CG_outputRepr *code) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
+
virtual omega::CG_outputRepr *CreateMalloc(const IR_CONSTANT_TYPE type, std::string lhs,
- omega::CG_outputRepr * size_repr){
+ omega::CG_outputRepr *size_repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
+
virtual omega::CG_outputRepr *CreateMalloc(omega::CG_outputRepr *type, std::string variable,
- omega::CG_outputRepr * size_repr){
+ omega::CG_outputRepr *size_repr) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
- virtual omega::CG_outputRepr *CreateFree(omega::CG_outputRepr * exp){
+
+ virtual omega::CG_outputRepr *CreateFree(omega::CG_outputRepr *exp) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
return NULL;
}
@@ -448,7 +556,7 @@ public:
// CC Omega code builder interface here
//---------------------------------------------------------------------------
- omega::CG_outputBuilder *builder() const { return ocg_;}
+ omega::CG_outputBuilder *builder() const { return ocg_; }
};
diff --git a/include/ir_enums.hh b/include/ir_enums.hh
index 742dbe8..6c652e5 100644
--- a/include/ir_enums.hh
+++ b/include/ir_enums.hh
@@ -21,4 +21,5 @@ enum IR_CONDITION_TYPE {IR_COND_LT, IR_COND_LE,
enum IR_ARRAY_LAYOUT_TYPE {IR_ARRAY_LAYOUT_ROW_MAJOR,
IR_ARRAY_LAYOUT_COLUMN_MAJOR,
IR_ARRAY_LAYOUT_SPACE_FILLING};
+
#endif
diff --git a/include/irtools.hh b/include/irtools.hh
index a743fa5..c4a78ed 100644
--- a/include/irtools.hh
+++ b/include/irtools.hh
@@ -6,6 +6,7 @@
#include <code_gen/CG_outputRepr.h>
#include "ir_code.hh"
#include "dep.hh"
+
#define DEP_DEBUG 0
// IR tree is used to initialize a loop. For a loop node, payload is
@@ -18,7 +19,7 @@ struct ir_tree_node {
ir_tree_node *parent;
std::vector<ir_tree_node *> children;
int payload;
-
+
~ir_tree_node() {
for (int i = 0; i < children.size(); i++)
delete children[i];
@@ -28,19 +29,22 @@ struct ir_tree_node {
std::vector<ir_tree_node *> build_ir_tree(IR_Control *control,
ir_tree_node *parent = NULL);
+
std::vector<ir_tree_node *> extract_ir_stmts(
- const std::vector<ir_tree_node *> &ir_tree);
+ const std::vector<ir_tree_node *> &ir_tree);
+
bool is_dependence_valid(ir_tree_node *src_node, ir_tree_node *dst_node,
const DependenceVector &dv, bool before);
+
std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > test_data_dependences(
- IR_Code *ir, const omega::CG_outputRepr *repr1,
- const omega::Relation &IS1, const omega::CG_outputRepr *repr2,
- const omega::Relation &IS2, std::vector<omega::Free_Var_Decl*> &freevar,
- std::vector<std::string> index, int i, int j,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols_stringrepr);
+ IR_Code *ir, const omega::CG_outputRepr *repr1,
+ const omega::Relation &IS1, const omega::CG_outputRepr *repr2,
+ const omega::Relation &IS2, std::vector<omega::Free_Var_Decl *> &freevar,
+ std::vector<std::string> index, int i, int j,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr);
-std::vector<omega::CG_outputRepr *> collect_loop_inductive_and_conditionals(ir_tree_node * stmt_node);
+std::vector<omega::CG_outputRepr *> collect_loop_inductive_and_conditionals(ir_tree_node *stmt_node);
// Manu
typedef std::map<int, std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > > tempResultMap;
@@ -48,9 +52,17 @@ typedef std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> >
// Manu:: this function is required for reduction operation
bool from_same_statement(IR_Code *ir, IR_ArrayRef *a, IR_ArrayRef *b);
+
int stmtType(IR_Code *ir, const omega::CG_outputRepr *repr);
+
IR_OPERATION_TYPE getReductionOperator(IR_Code *ir, const omega::CG_outputRepr *repr);
-void mapRefstoStatements(IR_Code *ir,std::vector<IR_ArrayRef *> access, int ref2Stmt[], std::map<int,std::set<int> >& rMap, std::set<int>& tnrStmts, std::set<int>& nrStmts);
-void checkReductionDependence(int i, int j, int nestLeveli, omega::coef_t lbound[], omega::coef_t ubound[], int ref2Stmt[], std::map<int,std::set<int> >& rMap, DVPair& dv, tempResultMap& trMap, std::set<int> nrStmts );
+
+void
+mapRefstoStatements(IR_Code *ir, std::vector<IR_ArrayRef *> access, int ref2Stmt[], std::map<int, std::set<int> > &rMap,
+ std::set<int> &tnrStmts, std::set<int> &nrStmts);
+
+void
+checkReductionDependence(int i, int j, int nestLeveli, omega::coef_t lbound[], omega::coef_t ubound[], int ref2Stmt[],
+ std::map<int, std::set<int> > &rMap, DVPair &dv, tempResultMap &trMap, std::set<int> nrStmts);
#endif
diff --git a/include/loop.hh b/include/loop.hh
index 3909e6c..72295b6 100644
--- a/include/loop.hh
+++ b/include/loop.hh
@@ -117,8 +117,8 @@ public:
Loop(const IR_Control *control);
~Loop();
- omega::CG_outputRepr *getCode(int effort = 3) const; // TODO was 1
- //chillAST_node* LoopCuda::getCode(int effort, std::set<int> stmts) const;
+ omega::CG_outputRepr *getCode(int effort = 3) const; // TODO was 1
+ //chillAST_node* getCode(int effort, std::set<int> stmts) const;
void stencilASEPadded(int stmt_num);
diff --git a/include/omegatools.hh b/include/omegatools.hh
index 2f56971..8f06ebc 100644
--- a/include/omegatools.hh
+++ b/include/omegatools.hh
@@ -8,61 +8,87 @@
std::string tmp_e();
-void exp2formula(IR_Code *ir,
- omega::Relation &r,
+void exp2formula(IR_Code *ir,
+ omega::Relation &r,
omega::F_And *f_root,
std::vector<omega::Free_Var_Decl *> &freevars,
- omega::CG_outputRepr *repr,
- omega::Variable_ID lhs,
+ omega::CG_outputRepr *repr,
+ omega::Variable_ID lhs,
char side,
- IR_CONDITION_TYPE rel,
- bool destroy,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols_stringrepr);
+ IR_CONDITION_TYPE rel,
+ bool destroy,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr);
-omega::Relation arrays2relation(IR_Code *ir, std::vector<omega::Free_Var_Decl*> &freevars,
+omega::Relation arrays2relation(IR_Code *ir, std::vector<omega::Free_Var_Decl *> &freevars,
const IR_ArrayRef *ref_src, const omega::Relation &IS_w,
- const IR_ArrayRef *ref_dst, const omega::Relation &IS_r,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols_stringrepr);
+ const IR_ArrayRef *ref_dst, const omega::Relation &IS_r,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr);
std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relation2dependences(
- const IR_ArrayRef *ref_src, const IR_ArrayRef *ref_dst, const omega::Relation &r);
+ const IR_ArrayRef *ref_src, const IR_ArrayRef *ref_dst, const omega::Relation &r);
void exp2constraint(IR_Code *ir, omega::Relation &r, omega::F_And *f_root,
std::vector<omega::Free_Var_Decl *> &freevars,
- omega::CG_outputRepr *repr, bool destroy,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols,
- std::map<std::string, std::vector<omega::CG_outputRepr * > > &uninterpreted_symbols_stringrepr);
+ omega::CG_outputRepr *repr, bool destroy,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr);
bool is_single_iteration(const omega::Relation &r, int dim);
+
void assign_const(omega::Relation &r, int dim, int val);
+
int get_const(const omega::Relation &r, int dim, omega::Var_Kind type);
+
omega::Variable_ID find_index(omega::Relation &r, const std::string &s, char side);
+
omega::Relation permute_relation(const std::vector<int> &pi);
+
omega::Relation get_loop_bound(const omega::Relation &r, int dim);
+
bool is_single_loop_iteration(const omega::Relation &r, int level, const omega::Relation &known);
+
omega::Relation get_loop_bound(const omega::Relation &r, int level, const omega::Relation &known);
+
omega::Relation get_max_loop_bound(const std::vector<omega::Relation> &r, int dim);
+
omega::Relation get_min_loop_bound(const std::vector<omega::Relation> &r, int dim);
+
void add_loop_stride(omega::Relation &r, const omega::Relation &bound, int dim, int stride);
+
bool is_inner_loop_depend_on_level(const omega::Relation &r, int level, const omega::Relation &known);
+
// void adjust_loop_bound(omega::Relation &r, int dim, int adjustment, std::vector<omega::Free_Var_Decl *> globals = std::vector<omega::Free_Var_Decl *>());
omega::Relation adjust_loop_bound(const omega::Relation &r, int level, int adjustment);
+
bool lowerBoundIsZero(const omega::Relation &bound, int dim);
+
omega::Relation and_with_relation_and_replace_var(const omega::Relation &R, omega::Variable_ID v1,
omega::Relation &g);
+
omega::Relation replicate_IS_and_add_at_pos(const omega::Relation &R, int level, omega::Relation &bound);
-omega::Relation replicate_IS_and_add_bound(const omega::Relation &R, int level, omega::Relation &bound) ;
-omega::CG_outputRepr * construct_int_floor(omega::CG_outputBuilder * ocg, const omega::Relation &R, const omega::GEQ_Handle &h, omega::Variable_ID v,const std::vector<std::pair<omega::CG_outputRepr *, int> > &assigned_on_the_fly,
- std::map<std::string, std::vector<omega::CG_outputRepr *> > unin);
+omega::Relation replicate_IS_and_add_bound(const omega::Relation &R, int level, omega::Relation &bound);
+
+omega::CG_outputRepr *
+construct_int_floor(omega::CG_outputBuilder *ocg, const omega::Relation &R, const omega::GEQ_Handle &h,
+ omega::Variable_ID v,
+ const std::vector<std::pair<omega::CG_outputRepr *, int> > &assigned_on_the_fly,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > unin);
+
//omega::CG_outputRepr * modified_output_subs_repr(omega::CG_outputBuilder * ocg, const omega::Relation &R, const omega::EQ_Handle &h, omega::Variable_ID v,const std::vector<std::pair<omega::CG_outputRepr *, int> > &assigned_on_the_fly,
// std::map<std::string, std::vector<omega::CG_outputRepr *> > unin);
-std::pair<omega::Relation, bool> replace_set_var_as_existential(const omega::Relation &R,int pos, std::vector<omega::Relation> &bound);
-omega::Relation replace_set_var_as_Global(const omega::Relation &R,int pos,std::vector<omega::Relation> &bound);
-omega::Relation replace_set_var_as_another_set_var(const omega::Relation &old_relation, const omega::Relation &new_relation, int old_pos, int new_pos);
+std::pair<omega::Relation, bool>
+replace_set_var_as_existential(const omega::Relation &R, int pos, std::vector<omega::Relation> &bound);
+
+omega::Relation replace_set_var_as_Global(const omega::Relation &R, int pos, std::vector<omega::Relation> &bound);
+
+omega::Relation
+replace_set_var_as_another_set_var(const omega::Relation &old_relation, const omega::Relation &new_relation,
+ int old_pos, int new_pos);
+
omega::Relation extract_upper_bound(const omega::Relation &R, omega::Variable_ID v1);
// void adjust_loop_bound(Relation &r, int dim, int adjustment);
@@ -72,7 +98,9 @@ omega::Relation extract_upper_bound(const omega::Relation &R, omega::Variable_ID
// coef_t mod(const Relation &r, Variable_ID v, int dividend);
-enum LexicalOrderType {LEX_MATCH, LEX_BEFORE, LEX_AFTER, LEX_UNKNOWN};
+enum LexicalOrderType {
+ LEX_MATCH, LEX_BEFORE, LEX_AFTER, LEX_UNKNOWN
+};
// template <typename T>
// LexicalOrderType lexical_order(const std::vector<T> &a, const std::vector<T> &b) {
diff --git a/include/stencil.hh b/include/stencil.hh
index 799e3b9..15bd94f 100644
--- a/include/stencil.hh
+++ b/include/stencil.hh
@@ -23,27 +23,28 @@ class stencilInfo {
public:
uint dimensions; // number of dimensions in the stencil
uint elements; // total number of elements in the stencil
- chillAST_VarDecl* srcArrayVariable; // the variable of the source array
- chillAST_VarDecl* dstArrayVariable; // the variable of the destination array
+ chillAST_VarDecl *srcArrayVariable; // the variable of the source array
+ chillAST_VarDecl *dstArrayVariable; // the variable of the destination array
int minOffset[3]; // the minimum offset for each dimension NOTE hardcoded to 3 dimensions TODO
int maxOffset[3]; // the maximum offset for each dimension
- chillAST_VarDecl* indexVariables[3]; // the variable used for indexing each dimension
+ chillAST_VarDecl *indexVariables[3]; // the variable used for indexing each dimension
- std::vector< std::vector< int > > offsets; // k+1, j-47, i+0 etc
+ std::vector<std::vector<int> > offsets; // k+1, j-47, i+0 etc
-
- std::vector< std::vector<chillAST_node*> > coefficients; // the coefficients of for each element, NOT IN ANY SET ORDER
- chillAST_node* find_coefficient( int i, int j, int k ) ; // hardcoded 3 dimensions TODO
+
+ std::vector<std::vector<chillAST_node *> > coefficients; // the coefficients of for each element, NOT IN ANY SET ORDER
+ chillAST_node *find_coefficient(int i, int j, int k); // hardcoded 3 dimensions TODO
// constructors
- stencilInfo();
- stencilInfo( chillAST_node *topstatement ) ;
+ stencilInfo();
+
+ stencilInfo(chillAST_node *topstatement);
- void walktree( chillAST_node *node, std::vector< chillAST_node * > &coeffstohere );
+ void walktree(chillAST_node *node, std::vector<chillAST_node *> &coeffstohere);
- void print( FILE *fp=stdout );
+ void print(FILE *fp = stdout);
int radius();
diff --git a/lib/chillcg/include/code_gen/CG_chillRepr.h b/lib/chillcg/include/code_gen/CG_chillRepr.h
index 36b2fa4..4a0510f 100755
--- a/lib/chillcg/include/code_gen/CG_chillRepr.h
+++ b/lib/chillcg/include/code_gen/CG_chillRepr.h
@@ -7,7 +7,7 @@
#include <string.h>
#include <code_gen/CG_outputRepr.h>
-#ifndef __STDC_CONSTANT_MACROS
+#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
@@ -17,69 +17,70 @@
namespace omega {
-class CG_chillRepr : public CG_outputRepr {
- friend class CG_chillBuilder;
-public:
- CG_chillRepr() { stmtclassname = strdup("NOTHING"); }
-
-
- char *type() const { return strdup("chill"); };
- //
- std::vector<chillAST_node*> chillnodes; // TODO make private
- void printChillNodes() const {
- for (int i=0; i<chillnodes.size(); i++) {
- chillnodes[i]->print(); printf("\n"); }
- fflush(stdout);
- };
-
- CG_chillRepr( std::vector<chillAST_node*> cnodes ) {
- chillnodes = cnodes;
- }
-
- CG_chillRepr( chillAST_node *chillast ) {
- stmtclassname = strdup(chillast->getTypeString());
- //fprintf(stderr, "made new chillRepr of class %s\n", stmtclassname);
- if (chillast->asttype == CHILLAST_NODETYPE_COMPOUNDSTMT) {
- std::vector<chillAST_node*> children = chillast->getChildren();
- int numchildren = children.size();
- for (int i=0; i<numchildren; i++) {
- chillnodes.push_back( children[i] );
- //fprintf(stderr, "adding a statement from a CompoundStmt\n");
+ class CG_chillRepr : public CG_outputRepr {
+ friend class CG_chillBuilder;
+
+ public:
+ CG_chillRepr() { stmtclassname = strdup("NOTHING"); }
+
+
+ char *type() const { return strdup("chill"); };
+ //
+ std::vector<chillAST_node *> chillnodes; // TODO make private
+ void printChillNodes() const {
+ for (int i = 0; i < chillnodes.size(); i++) {
+ chillnodes[i]->print();
+ printf("\n");
}
+ fflush(stdout);
+ };
+
+ CG_chillRepr(std::vector<chillAST_node *> cnodes) {
+ chillnodes = cnodes;
}
- else { // for now, assume it's a single statement
- chillnodes.push_back( chillast ); // ??
+
+ CG_chillRepr(chillAST_node *chillast) {
+ stmtclassname = strdup(chillast->getTypeString());
+ //fprintf(stderr, "made new chillRepr of class %s\n", stmtclassname);
+ if (chillast->asttype == CHILLAST_NODETYPE_COMPOUNDSTMT) {
+ std::vector<chillAST_node *> children = chillast->getChildren();
+ int numchildren = children.size();
+ for (int i = 0; i < numchildren; i++) {
+ chillnodes.push_back(children[i]);
+ //fprintf(stderr, "adding a statement from a CompoundStmt\n");
+ }
+ } else { // for now, assume it's a single statement
+ chillnodes.push_back(chillast); // ??
+ }
}
- }
- void addStatement( chillAST_node *s ) { chillnodes.push_back( s ); } ;
-
- std::vector<chillAST_node*> getChillCode() const { return chillnodes; };
- chillAST_node *GetCode() ;
-
-
- ~CG_chillRepr();
- CG_outputRepr *clone() const;
- void clear();
+ void addStatement(chillAST_node *s) { chillnodes.push_back(s); };
+
+ std::vector<chillAST_node *> getChillCode() const { return chillnodes; };
+
+ chillAST_node *GetCode();
+
+
+ ~CG_chillRepr();
+
+ CG_outputRepr *clone() const;
-
-
+ void clear();
+ //---------------------------------------------------------------------------
+ // Dump operations
+ //---------------------------------------------------------------------------
+ void dump() const { printChillNodes(); };
- //---------------------------------------------------------------------------
- // Dump operations
- //---------------------------------------------------------------------------
- void dump() const { printChillNodes(); };
- void Dump() const;
- //void DumpToFile(FILE *fp = stderr) const;
-private:
+ void Dump() const;
+ //void DumpToFile(FILE *fp = stderr) const;
+ private:
- char *stmtclassname; // chill
-
-};
+ char *stmtclassname; // chill
+ };
} // namespace
diff --git a/src/chill.cc b/src/chill.cc
index a3ad57f..f69f3bf 100644
--- a/src/chill.cc
+++ b/src/chill.cc
@@ -26,27 +26,26 @@ std::vector<int> loops;
// CHiLL program main
// Initialize state and run script or interactive mode
//---
-int main( int argc, char* argv[] )
-{
+int main(int argc, char *argv[]) {
CHILL_DEBUG_PRINT("%s main()\n", argv[0]);
if (argc > 2) {
fprintf(stderr, "Usage: %s [script_file]\n", argv[0]);
exit(-1);
}
-
+
// Create PYTHON interpreter
/* Pass argv[0] to the Python interpreter */
Py_SetProgramName(argv[0]);
-
+
/* Initialize the Python interpreter. Required. */
Py_Initialize();
-
+
/* Add a static module */
initchill();
-
+
if (argc == 2) {
- FILE* f = fopen(argv[1], "r");
- if(!f){
+ FILE *f = fopen(argv[1], "r");
+ if (!f) {
printf("can't open script file \"%s\"\n", argv[1]);
exit(-1);
}
@@ -61,8 +60,8 @@ int main( int argc, char* argv[] )
printf("Copyright (C) 2008 University of Southern California\n");
printf("Copyright (C) 2009-2012 University of Utah\n");
fflush(stdout);
- is_interactive=true;
- PyRun_InteractiveLoop(stdin,"-");
+ is_interactive = true;
+ PyRun_InteractiveLoop(stdin, "-");
printf("CHiLL ending...\n");
fflush(stdout);
}
diff --git a/src/chillASTs.cc b/src/chillASTs.cc
index 2564c63..c73eb98 100644
--- a/src/chillASTs.cc
+++ b/src/chillASTs.cc
@@ -7,322 +7,314 @@
using namespace std;
int chillAST_node::chill_scalar_counter = 0;
-int chillAST_node::chill_array_counter = 1;
-
-
-const char* Chill_AST_Node_Names[] = {
- "Unknown AST node type",
- "SourceFile",
- "TypedefDecl",
- "VarDecl",
- // "ParmVarDecl", not used any more
- "FunctionDecl",
- "RecordDecl",
- "MacroDefinition",
- "CompoundStmt",
- "ForStmt",
- "TernaryOperator",
- "BinaryOperator",
- "UnaryOperator",
- "ArraySubscriptExpr",
- "MemberExpr",
- "DeclRefExpr",
- "IntegerLiteral",
- "FloatingLiteral",
- "ImplicitCastExpr", // not sure we need this
- "ReturnStmt",
- "CallExpr",
- "DeclStmt",
- "ParenExpr",
- "CStyleCastExpr",
- "CStyleAddressOf",
- "IfStmt",
- "SizeOf",
- "Malloc",
- "Free",
- "NoOp",
-// CUDA specific
- "CudaMalloc",
- "CudaFree",
- "CudaMemcpy",
- "CudaKernelCall",
- "CudaSyncthreads",
- "fake1",
- "fake2",
- "fake3"
+int chillAST_node::chill_array_counter = 1;
+
+
+const char *Chill_AST_Node_Names[] = {
+ "Unknown AST node type",
+ "SourceFile",
+ "TypedefDecl",
+ "VarDecl",
+ // "ParmVarDecl", not used any more
+ "FunctionDecl",
+ "RecordDecl",
+ "MacroDefinition",
+ "CompoundStmt",
+ "ForStmt",
+ "TernaryOperator",
+ "BinaryOperator",
+ "UnaryOperator",
+ "ArraySubscriptExpr",
+ "MemberExpr",
+ "DeclRefExpr",
+ "IntegerLiteral",
+ "FloatingLiteral",
+ "ImplicitCastExpr", // not sure we need this
+ "ReturnStmt",
+ "CallExpr",
+ "DeclStmt",
+ "ParenExpr",
+ "CStyleCastExpr",
+ "CStyleAddressOf",
+ "IfStmt",
+ "SizeOf",
+ "Malloc",
+ "Free",
+ "NoOp",
+// CUDA specific
+ "CudaMalloc",
+ "CudaFree",
+ "CudaMemcpy",
+ "CudaKernelCall",
+ "CudaSyncthreads",
+ "fake1",
+ "fake2",
+ "fake3"
};
-char *parseUnderlyingType( char *sometype ) {
+char *parseUnderlyingType(char *sometype) {
int len = strlen(sometype);
- //fprintf(stderr, "parseUnderlyingType( %s )\n", sometype);
- char *underlying = strdup(sometype);
+ //fprintf(stderr, "parseUnderlyingType( %s )\n", sometype);
+ char *underlying = strdup(sometype);
char *p;
char *start = underlying;
// ugly. we want to turn "float *" into "float" but "struct abc *" into struct abc.
- // there are probably many more cases. have an approved list? TODO
+ // there are probably many more cases. have an approved list? TODO
if (strstr(underlying, "struct ")) start += 7; // (length("struct "))
- //fprintf(stderr, "sometype '%s' start '%s'\n", sometype, start);
+ //fprintf(stderr, "sometype '%s' start '%s'\n", sometype, start);
if (p = index(start, ' ')) *p = '\0'; // end at first space leak
if (p = index(start, '[')) *p = '\0'; // leak
if (p = index(start, '*')) *p = '\0'; // leak
-
- return underlying;
+
+ return underlying;
}
-void printSymbolTable( chillAST_SymbolTable *st ) {
- //printf("%d entries\n", st->size());
+void printSymbolTable(chillAST_SymbolTable *st) {
+ //printf("%d entries\n", st->size());
if (!st) return;
- for (int i=0; i<st->size(); i++) { printf("%d ", i ); (*st)[i]->printName(); printf("\n"); }
- if (st->size() )printf("\n");
- fflush(stdout);
+ for (int i = 0; i < st->size(); i++) {
+ printf("%d ", i);
+ (*st)[i]->printName();
+ printf("\n");
+ }
+ if (st->size())printf("\n");
+ fflush(stdout);
}
-void printSymbolTableMoreInfo( chillAST_SymbolTable *st ) {
- //printf("%d entries\n", st->size());
+void printSymbolTableMoreInfo(chillAST_SymbolTable *st) {
+ //printf("%d entries\n", st->size());
if (!st) return;
- for (int i=0; i<st->size(); i++) { printf("%d ", i ); (*st)[i]->print(); printf("\n"); }
- if (st->size() )printf("\n");
- fflush(stdout);
+ for (int i = 0; i < st->size(); i++) {
+ printf("%d ", i);
+ (*st)[i]->print();
+ printf("\n");
+ }
+ if (st->size())printf("\n");
+ fflush(stdout);
}
-bool symbolTableHasVariableNamed( chillAST_SymbolTable *table, const char *name ) {
- if (!table) return false; // ??
+bool symbolTableHasVariableNamed(chillAST_SymbolTable *table, const char *name) {
+ if (!table) return false; // ??
int numvars = table->size();
- for (int i=0; i<numvars; i++) {
+ for (int i = 0; i < numvars; i++) {
chillAST_VarDecl *vd = (*table)[i];
- if (!strcmp(name, vd->varname)) return true; // need to check type?
+ if (!strcmp(name, vd->varname)) return true; // need to check type?
}
return false;
}
-
-chillAST_VarDecl *symbolTableFindVariableNamed( chillAST_SymbolTable *table, const char *name ){ // fwd decl TODO too many similar named functions
- if (!table) return NULL; // ??
+chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table,
+ const char *name) { // fwd decl TODO too many similar named functions
+ if (!table) return NULL; // ??
// see if name has a dot or arrow (->) indicating that it is a structure/class
- const char *cdot = strstr( name, "." );
+ const char *cdot = strstr(name, ".");
const char *carrow = strstr(name, "->"); // initial 'c' for const - can't change those
char *varname;
char *subpart = NULL;
- if (cdot || carrow) {
- fprintf(stderr, "symbolTableFindVariableNamed(), name '%s' looks like a struct\n", name);
+ if (cdot || carrow) {
+ fprintf(stderr, "symbolTableFindVariableNamed(), name '%s' looks like a struct\n", name);
// so, look for the first part in the symbol table.
// warning, this could be looking for a->b.c.d->e.f->g
- varname = strdup( name );
+ varname = strdup(name);
- char *dot = strstr(varname, "." );
- char *arrow = strstr( varname, "->" );
- if (dot != NULL && arrow != NULL ) { // dot AND arrow,
+ char *dot = strstr(varname, ".");
+ char *arrow = strstr(varname, "->");
+ if (dot != NULL && arrow != NULL) { // dot AND arrow,
fprintf(stderr, "chillast.cc symbolTableFindVariableNamed(), name '%s' has both dot and arrow? TODO\n");
- exit(-1);
- }
- else if (dot != NULL && !arrow) { // just dot(s). dot points to the first one
+ exit(-1);
+ } else if (dot != NULL && !arrow) { // just dot(s). dot points to the first one
//fprintf(stderr, "name '%s' has dot(s)\n", varname);
*dot = '\0'; // end string at the dot
subpart = &(dot[1]);
fprintf(stderr, "will now look for a struct/class named %s that has member %s\n", varname, subpart);
- }
- else if (arrow != NULL && !dot) { // just arrow(s) arrow points to the first one
+ } else if (arrow != NULL && !dot) { // just arrow(s) arrow points to the first one
//fprintf(stderr, "name '%s' has arrow(s)\n", varname);
*arrow = '\0'; // end string at the arrow
- subpart = &(arrow[2]);
+ subpart = &(arrow[2]);
fprintf(stderr, "will now look for a struct/class named %s that has member %s\n", varname, subpart);
+ } else { // impossible
+ fprintf(stderr,
+ "chillast.cc symbolTableFindVariableNamed(), varname '%s', looks like a struct, but I can't figure it out\n",
+ varname);
+ exit(-1);
}
- else { // impossible
- fprintf(stderr, "chillast.cc symbolTableFindVariableNamed(), varname '%s', looks like a struct, but I can't figure it out\n", varname);
- exit(-1);
- }
- }
- else {
- varname = strdup(name);
+ } else {
+ varname = strdup(name);
}
int numvars = table->size();
- for (int i=0; i<numvars; i++) {
+ for (int i = 0; i < numvars; i++) {
chillAST_VarDecl *vd = (*table)[i];
- if (!strcmp(varname, vd->varname)) {
+ if (!strcmp(varname, vd->varname)) {
fprintf(stderr, "found variable named %s\n", varname);
- if (!subpart) return vd; // need to check type?
+ if (!subpart) return vd; // need to check type?
// OK, we have a variable, which looks like a struct/class, and a subpart that is some member names
- //fprintf(stderr, "but I don't know how to check if it has member %s\n", subpart);
-
- char *dot = strstr(subpart, "." );
- char *arrow = strstr(subpart, "->" );
-
+ //fprintf(stderr, "but I don't know how to check if it has member %s\n", subpart);
+
+ char *dot = strstr(subpart, ".");
+ char *arrow = strstr(subpart, "->");
+
if (!dot && !arrow) { // whew, only one level of struct
- //fprintf(stderr, "whew, only one level of struct\n");
-
+ //fprintf(stderr, "whew, only one level of struct\n");
+
// make sure this variable definition is a struct
- if (vd->isAStruct()) {
- //fprintf(stderr, "%s is a struct of type %s\n", varname, vd->getTypeString());
- if (vd->isVarDecl()) {
- chillAST_RecordDecl *rd = vd->getStructDef();
- if (rd) {
- //fprintf(stderr, "has a recordDecl\n");
-
- chillAST_VarDecl *sp = rd->findSubpart( subpart );
+ if (vd->isAStruct()) {
+ //fprintf(stderr, "%s is a struct of type %s\n", varname, vd->getTypeString());
+ if (vd->isVarDecl()) {
+ chillAST_RecordDecl *rd = vd->getStructDef();
+ if (rd) {
+ //fprintf(stderr, "has a recordDecl\n");
+
+ chillAST_VarDecl *sp = rd->findSubpart(subpart);
if (sp) fprintf(stderr, "found a struct member named %s\n", subpart);
else fprintf(stderr, "DIDN'T FIND a struct member named %s\n", subpart);
- return sp; // return the subpart??
- }
- else {
- fprintf(stderr, "no recordDecl\n");
- exit(-1);
+ return sp; // return the subpart??
+ } else {
+ fprintf(stderr, "no recordDecl\n");
+ exit(-1);
}
- }
- else {
+ } else {
fprintf(stderr, "NOT a VarDecl???\n"); // impossible
}
- }
- else {
- fprintf(stderr, "false alarm. %s is a variable, but doesn't have subparts\n", varname);
- return NULL; // false alarm. a variable of the correct name exists, but is not a struct
+ } else {
+ fprintf(stderr, "false alarm. %s is a variable, but doesn't have subparts\n", varname);
+ return NULL; // false alarm. a variable of the correct name exists, but is not a struct
}
}
-
- fprintf(stderr, "chillast.cc symbolTableFindVariableNamed(), name '%s' can't figure out multiple levels of struct yet!\n");
- exit(-1);
+ fprintf(stderr,
+ "chillast.cc symbolTableFindVariableNamed(), name '%s' can't figure out multiple levels of struct yet!\n");
+
+ exit(-1);
}
}
return NULL;
}
-
-char *ulhack( char *brackets ) // remove UL from numbers, MODIFIES the argument!
+char *ulhack(char *brackets) // remove UL from numbers, MODIFIES the argument!
{
- //fprintf(stderr, "ulhack( \"%s\" -> ", brackets);
- // another hack. remove "UL" from integers
+ //fprintf(stderr, "ulhack( \"%s\" -> ", brackets);
+ // another hack. remove "UL" from integers
int len = strlen(brackets);
- for (int i=0; i< len-2; i++) {
+ for (int i = 0; i < len - 2; i++) {
if (isdigit(brackets[i])) {
- if (brackets[i+1] == 'U' && brackets[i+2] == 'L') {
- // remove
- for (int j=i+3; j<len; j++) brackets[j-2] = brackets[j];
- len -=2;
+ if (brackets[i + 1] == 'U' && brackets[i + 2] == 'L') {
+ // remove
+ for (int j = i + 3; j < len; j++) brackets[j - 2] = brackets[j];
+ len -= 2;
brackets[len] = '\0';
}
}
}
- //fprintf(stderr, "\"%s\" )\n", brackets);
+ //fprintf(stderr, "\"%s\" )\n", brackets);
return brackets;
}
-char *restricthack( char *typeinfo ) // remove __restrict__ , MODIFIES the argument!
+char *restricthack(char *typeinfo) // remove __restrict__ , MODIFIES the argument!
{
//if (!isRestrict( typeinfo )) return typeinfo;
// there is a "__restrict__ " somewhere embedded. remove it.
- // duplicate work
- std::string r( "__restrict__" );
- std::string t( typeinfo );
- size_t index = t.find( r );
+ // duplicate work
+ std::string r("__restrict__");
+ std::string t(typeinfo);
+ size_t index = t.find(r);
- if (index == std::string::npos) return typeinfo;
+ if (index == std::string::npos) return typeinfo;
- char *c = &( typeinfo[index] );
+ char *c = &(typeinfo[index]);
char *after = c + 12;
if (*after == ' ') after++;
- //fprintf(stderr, "after = '%s'\n", after);
+ //fprintf(stderr, "after = '%s'\n", after);
- while (*after != '\0') *c++ = *after++;
+ while (*after != '\0') *c++ = *after++;
*c = '\0';
- return typeinfo;
+ return typeinfo;
}
-
-
-
-char *parseArrayParts( char *sometype ) {
+char *parseArrayParts(char *sometype) {
int len = strlen(sometype);
- char *arraypart = (char *)calloc(1 + strlen(sometype), sizeof(char));// leak
+ char *arraypart = (char *) calloc(1 + strlen(sometype), sizeof(char));// leak
int c = 0;
- for (int i=0; i<strlen(sometype); ) {
- if ( sometype[i] == '*') arraypart[c++] = '*';
- if ( sometype[i] == '[') {
+ for (int i = 0; i < strlen(sometype);) {
+ if (sometype[i] == '*') arraypart[c++] = '*';
+ if (sometype[i] == '[') {
while (sometype[i] != ']') {
arraypart[c++] = sometype[i++];
}
- arraypart[c++] = ']';
+ arraypart[c++] = ']';
}
i += 1;
}
ulhack(arraypart);
- restricthack( arraypart );
+ restricthack(arraypart);
- //fprintf(stderr, "parseArrayParts( %s ) => %s\n", sometype, arraypart);
+ //fprintf(stderr, "parseArrayParts( %s ) => %s\n", sometype, arraypart);
return arraypart;
}
+char *splitTypeInfo(char *underlyingtype) { // return the bracketed part of a type
+ char *ap = ulhack(parseArrayParts(underlyingtype)); // return this
-
-
-
-
-char *splitTypeInfo( char *underlyingtype ) { // return the bracketed part of a type
- char *ap = ulhack(parseArrayParts( underlyingtype )); // return this
-
- // now need to remove all that from the underlyingtype to get
+ // now need to remove all that from the underlyingtype to get
char *arraypart = strdup(""); // leak
if (index(underlyingtype, '[')) {
- // looks like an array
+ // looks like an array
free(arraypart);
char *start = index(underlyingtype, '['); // wrong. can have int *buh[32]
- arraypart = strdup( start );
- if (*(start-1) == ' ') start--; // hack
+ arraypart = strdup(start);
+ if (*(start - 1) == ' ') start--; // hack
*start = '\0';
- // ugly. very leaky
- strcpy( underlyingtype, parseUnderlyingType( underlyingtype ));
-
- // ulhack( arraypart );
+ // ugly. very leaky
+ strcpy(underlyingtype, parseUnderlyingType(underlyingtype));
+
+ // ulhack( arraypart );
}
- return ap; // leak unless caller frees this
+ return ap; // leak unless caller frees this
}
-
-bool isRestrict( const char *sometype ) { // does not modify sometype
- string r( "__restrict__" );
- string t( sometype );
- return (std::string::npos != t.find( r ) );
+bool isRestrict(const char *sometype) { // does not modify sometype
+ string r("__restrict__");
+ string t(sometype);
+ return (std::string::npos != t.find(r));
}
+bool streq(const char *a, const char *b) { return !strcmp(a, b); }; // slightly less ugly // TODO enums
-bool streq( const char *a, const char *b) { return !strcmp(a,b); }; // slightly less ugly // TODO enums
+void chillindent(int howfar, FILE *fp) { for (int i = 0; i < howfar; i++) fprintf(fp, " "); }
-void chillindent( int howfar, FILE *fp ) { for (int i=0; i<howfar; i++) fprintf(fp, " "); }
-
-
-chillAST_VarDecl * chillAST_node::findVariableNamed( const char *name ) { // generic, recursive
- fprintf(stderr, "nodetype %s findVariableNamed( %s )\n", getTypeString(), name );
+chillAST_VarDecl *chillAST_node::findVariableNamed(const char *name) { // generic, recursive
+ fprintf(stderr, "nodetype %s findVariableNamed( %s )\n", getTypeString(), name);
if (hasSymbolTable()) { // look in my symbol table if I have one
- fprintf(stderr, "%s has a symbol table\n", getTypeString());
- chillAST_VarDecl *vd = symbolTableFindVariableNamed( getSymbolTable(), name);
+ fprintf(stderr, "%s has a symbol table\n", getTypeString());
+ chillAST_VarDecl *vd = symbolTableFindVariableNamed(getSymbolTable(), name);
if (vd) {
- fprintf(stderr, "found it\n");
+ fprintf(stderr, "found it\n");
return vd; // found locally
}
- fprintf(stderr, "%s has a symbol table but couldn't find %s\n", getTypeString(), name );
+ fprintf(stderr, "%s has a symbol table but couldn't find %s\n", getTypeString(), name);
}
if (!parent) {
fprintf(stderr, "%s has no parent\n", getTypeString());
@@ -331,62 +323,62 @@ chillAST_VarDecl * chillAST_node::findVariableNamed( const char *name ) { // gen
// recurse upwards
//fprintf(stderr, "recursing from %s up to parent %p\n", getTypeString(), parent);
fprintf(stderr, "recursing from %s up to parent\n", getTypeString());
- return parent->findVariableNamed( name );
+ return parent->findVariableNamed(name);
}
-chillAST_RecordDecl * chillAST_node::findRecordDeclNamed( const char *name ) { // recursive
- fprintf(stderr, "%s::findRecordDeclNamed( %s )\n", getTypeString(), name);
+chillAST_RecordDecl *chillAST_node::findRecordDeclNamed(const char *name) { // recursive
+ fprintf(stderr, "%s::findRecordDeclNamed( %s )\n", getTypeString(), name);
// look in children
int numchildren = children.size();
- fprintf(stderr, "%d children\n", numchildren);
- for (int i=0; i<numchildren; i++) {
+ fprintf(stderr, "%d children\n", numchildren);
+ for (int i = 0; i < numchildren; i++) {
fprintf(stderr, "child %d %s\n", i, children[i]->getTypeString());
if (children[i]->isRecordDecl()) {
- chillAST_RecordDecl *RD = (chillAST_RecordDecl *)children[i];
- fprintf(stderr, "it is a recordDecl named '%s' vs '%s'\n", RD->getName(), name);
- if (!strcmp( RD->getName(), name )) {
- fprintf(stderr, "FOUND IT\n");
+ chillAST_RecordDecl *RD = (chillAST_RecordDecl *) children[i];
+ fprintf(stderr, "it is a recordDecl named '%s' vs '%s'\n", RD->getName(), name);
+ if (!strcmp(RD->getName(), name)) {
+ fprintf(stderr, "FOUND IT\n");
return RD;
}
}
- }
-
+ }
+
if (!parent) return NULL; // no more recursion available
// recurse upwards
- return parent->findRecordDeclNamed( name );
+ return parent->findRecordDeclNamed(name);
}
-void chillAST_node::printPreprocBEFORE( int indent, FILE *fp ) {
- int numstmts = preprocessinginfo.size();
- //if (0 != numstmts) {
- // fprintf(fp, "chillAST_node::printPreprocBEFORE() %d statements\n", numstmts);
- //}
-
-
- for (int i=0; i< numstmts; i++) {
- //fprintf(fp, "stmt %d %d\n", i, preprocessinginfo[i]->position);
- if (preprocessinginfo[i]->position == CHILL_PREPROCESSING_LINEBEFORE ||
+void chillAST_node::printPreprocBEFORE(int indent, FILE *fp) {
+ int numstmts = preprocessinginfo.size();
+ //if (0 != numstmts) {
+ // fprintf(fp, "chillAST_node::printPreprocBEFORE() %d statements\n", numstmts);
+ //}
+
+
+ for (int i = 0; i < numstmts; i++) {
+ //fprintf(fp, "stmt %d %d\n", i, preprocessinginfo[i]->position);
+ if (preprocessinginfo[i]->position == CHILL_PREPROCESSING_LINEBEFORE ||
preprocessinginfo[i]->position == CHILL_PREPROCESSING_IMMEDIATELYBEFORE) {
- //fprintf(stderr, "before %d\n", preprocessinginfo[i]->position);
- preprocessinginfo[i]->print(indent, fp);
+ //fprintf(stderr, "before %d\n", preprocessinginfo[i]->position);
+ preprocessinginfo[i]->print(indent, fp);
}
}
}
-void chillAST_node::printPreprocAFTER( int indent, FILE *fp ) {
- for (int i=0; i< preprocessinginfo.size(); i++) {
- if (preprocessinginfo[i]->position == CHILL_PREPROCESSING_LINEAFTER ||
- preprocessinginfo[i]->position == CHILL_PREPROCESSING_TOTHERIGHT) {
- //fprintf(stderr, "after %d\n", preprocessinginfo[i]->position);
- preprocessinginfo[i]->print(indent, fp);
+void chillAST_node::printPreprocAFTER(int indent, FILE *fp) {
+ for (int i = 0; i < preprocessinginfo.size(); i++) {
+ if (preprocessinginfo[i]->position == CHILL_PREPROCESSING_LINEAFTER ||
+ preprocessinginfo[i]->position == CHILL_PREPROCESSING_TOTHERIGHT) {
+ //fprintf(stderr, "after %d\n", preprocessinginfo[i]->position);
+ preprocessinginfo[i]->print(indent, fp);
}
}
}
-chillAST_SourceFile::chillAST_SourceFile::chillAST_SourceFile() {
+chillAST_SourceFile::chillAST_SourceFile::chillAST_SourceFile() {
SourceFileName = strdup("No Source File");
asttype = CHILLAST_NODETYPE_SOURCEFILE;
parent = NULL; // top node
@@ -394,30 +386,31 @@ chillAST_SourceFile::chillAST_SourceFile::chillAST_SourceFile() {
global_symbol_table = NULL;
global_typedef_table = NULL;
FileToWrite = NULL;
- frontend = strdup("unknown");
+ frontend = strdup("unknown");
isFromSourceFile = true;
- filename = NULL;
+ filename = NULL;
};
-chillAST_SourceFile::chillAST_SourceFile(const char *filename ) {
- SourceFileName = strdup(filename);
- asttype = CHILLAST_NODETYPE_SOURCEFILE;
+chillAST_SourceFile::chillAST_SourceFile(const char *filename) {
+ SourceFileName = strdup(filename);
+ asttype = CHILLAST_NODETYPE_SOURCEFILE;
parent = NULL; // top node
metacomment = NULL;
global_symbol_table = NULL;
global_typedef_table = NULL;
- FileToWrite = NULL;
- frontend = strdup("unknown");
+ FileToWrite = NULL;
+ frontend = strdup("unknown");
isFromSourceFile = true;
- filename = NULL;
+ filename = NULL;
};
-void chillAST_SourceFile::print( int indent, FILE *fp ) {
- //fprintf(stderr, "chillAST_SourceFile::print()\n");
+void chillAST_SourceFile::print(int indent, FILE *fp) {
+ //fprintf(stderr, "chillAST_SourceFile::print()\n");
fflush(fp);
- fprintf(fp, "\n// this source derived from CHILL AST originally from file '%s' as parsed by frontend compiler %s\n\n", SourceFileName, frontend);
- std::vector< char * > includedfiles;
- int sofar = 0;
+ fprintf(fp, "\n// this source derived from CHILL AST originally from file '%s' as parsed by frontend compiler %s\n\n",
+ SourceFileName, frontend);
+ std::vector<char *> includedfiles;
+ int sofar = 0;
//fprintf(fp, "#define __rose_lt(x,y) ((x)<(y)?(x):(y))\n#define __rose_gt(x,y) ((x)>(y)?(x):(y))\n"); // help diff figure out what's going on
@@ -426,156 +419,150 @@ void chillAST_SourceFile::print( int indent, FILE *fp ) {
//fprintf(stderr, "they are\n");
//for (int i=0; i<numchildren; i++) {
// fprintf(stderr, "%s ", children[i]->getTypeString());
- // if (children[i]->isFunctionDecl()) {
+ // if (children[i]->isFunctionDecl()) {
// fprintf(stderr, "%s ", ((chillAST_FunctionDecl *)children[i])->functionName);
// }
- // fprintf(stderr, "\n");
- //}
+ // fprintf(stderr, "\n");
+ //}
- for (int i=0; i<numchildren; i++) {
+ for (int i = 0; i < numchildren; i++) {
//fprintf(fp, "\n// child %d of type %s:\n", i, children[i]->getTypeString());
- if (children[i]->isFromSourceFile) {
- if (children[i]->isFunctionDecl()) {
- fprintf(stderr, "\nchild %d function %s\n",i,((chillAST_FunctionDecl *)children[i])->functionName);
- }
- //fprintf(stderr, "child %d IS from source file\n", i);
+ if (children[i]->isFromSourceFile) {
+ if (children[i]->isFunctionDecl()) {
+ fprintf(stderr, "\nchild %d function %s\n", i, ((chillAST_FunctionDecl *) children[i])->functionName);
+ }
+ //fprintf(stderr, "child %d IS from source file\n", i);
//if (children[i]->isMacroDefinition()) fprintf(fp, "\n"); fflush(fp);
- children[i]->print( indent, fp );
- if (children[i]->isVarDecl()) fprintf(fp, ";\n"); fflush(fp); // top level vardecl\n");
- }
- else {
- //fprintf(stderr, "child %d is not from source file\n", i);
- // this should all go away
-
-#ifdef NOPE
- if (children[i]->filename // not null and not empty string
+ children[i]->print(indent, fp);
+ if (children[i]->isVarDecl()) fprintf(fp, ";\n");
+ fflush(fp); // top level vardecl\n");
+ } else {
+ //fprintf(stderr, "child %d is not from source file\n", i);
+ // this should all go away
+
+#ifdef NOPE
+ if (children[i]->filename // not null and not empty string
//&& 0 != strlen(children[i]->filename)
- ) { // should not be necessary
- //fprintf(fp, "// need an include for %s\n", children[i]->filename);
+ ) { // should not be necessary
+ //fprintf(fp, "// need an include for %s\n", children[i]->filename);
bool rddid = false;
- sofar = includedfiles.size();
-
+ sofar = includedfiles.size();
+
for (int j=0; j<sofar; j++) {
- //fprintf(stderr, "comparing %s and %s\n", includedfiles[j], children[i]->filename );
+ //fprintf(stderr, "comparing %s and %s\n", includedfiles[j], children[i]->filename );
if (!strcmp( includedfiles[j], children[i]->filename) ) { // this file has already been included
rddid = true;
- //fprintf(stderr, "already did that one\n");
+ //fprintf(stderr, "already did that one\n");
}
}
-
+
if (false == rddid) { // we need to include it now
fprintf(fp, "#include \"%s\"\n", children[i]->filename);
includedfiles.push_back(strdup( children[i]->filename ));
}
- //else {
- // fprintf(fp, "already did\n");
- //}
+ //else {
+ // fprintf(fp, "already did\n");
+ //}
}
-#endif // NOPE
+#endif // NOPE
}
- }
+ }
- fflush(fp);
+ fflush(fp);
- //fprintf(fp, "\n\n// functions??\n");
- //for (int i=0; i<functions.size(); i++) {
- // fprintf(fp, "\n\n"); functions[i]->print(0,fp); fflush(fp);
- //}
+ //fprintf(fp, "\n\n// functions??\n");
+ //for (int i=0; i<functions.size(); i++) {
+ // fprintf(fp, "\n\n"); functions[i]->print(0,fp); fflush(fp);
+ //}
};
-
-
-void chillAST_SourceFile::printToFile( char *filename ) {
+void chillAST_SourceFile::printToFile(char *filename) {
char fn[1024];
- if (NULL == filename) { // build up a filename using original name and frontend if known
- if (FileToWrite) {
- strcpy( fn, FileToWrite );
- }
- else {
+ if (NULL == filename) { // build up a filename using original name and frontend if known
+ if (FileToWrite) {
+ strcpy(fn, FileToWrite);
+ } else {
// input name with name of frontend compiler prepended
if (frontend) sprintf(fn, "%s_%s\0", frontend, SourceFileName);
else sprintf(fn, "UNKNOWNFRONTEND_%s\0", SourceFileName); // should never happen
}
- }
- else strcpy( fn, filename );
+ } else strcpy(fn, filename);
FILE *fp = fopen(fn, "w");
- if (!fp) {
+ if (!fp) {
fprintf(stderr, "can't open file '%s' for writing\n", fn);
exit(-1);
}
-
+
//fprintf(fp, "\n\n");
- //dump(0, fp);
+ //dump(0, fp);
fprintf(fp, "\n\n");
print(0, fp);
-
-}
+}
-void chillAST_SourceFile::dump( int indent, FILE *fp ) {
- fflush(fp);
- fprintf(fp, "\n//CHILL AST originally from file '%s'\n", SourceFileName);
+void chillAST_SourceFile::dump(int indent, FILE *fp) {
+ fflush(fp);
+ fprintf(fp, "\n//CHILL AST originally from file '%s'\n", SourceFileName);
int numchildren = children.size();
- for (int i=0; i<numchildren; i++) {
- children[i]->dump( indent, fp );
+ for (int i = 0; i < numchildren; i++) {
+ children[i]->dump(indent, fp);
}
- fflush(fp);
+ fflush(fp);
};
-
-chillAST_MacroDefinition * chillAST_SourceFile::findMacro( const char *name ) {
+chillAST_MacroDefinition *chillAST_SourceFile::findMacro(const char *name) {
//fprintf(stderr, "chillAST_SourceFile::findMacro( %s )\n", name );
-
+
int numMacros = macrodefinitions.size();
- for (int i=0; i<numMacros; i++) {
- if (!strcmp( macrodefinitions[i]->macroName, name )) return macrodefinitions[i];
+ for (int i = 0; i < numMacros; i++) {
+ if (!strcmp(macrodefinitions[i]->macroName, name)) return macrodefinitions[i];
}
return NULL; // not found
}
-chillAST_FunctionDecl * chillAST_SourceFile::findFunction( const char *name ) {
+chillAST_FunctionDecl *chillAST_SourceFile::findFunction(const char *name) {
//fprintf(stderr, "chillAST_SourceFile::findMacro( %s )\n", name );
-
+
int numFuncs = functions.size();
- for (int i=0; i<numFuncs; i++) {
- if ( !strcmp( functions[i]->functionName, name )) return functions[i];
+ for (int i = 0; i < numFuncs; i++) {
+ if (!strcmp(functions[i]->functionName, name)) return functions[i];
}
return NULL;
}
-chillAST_node *chillAST_SourceFile::findCall( const char *name ) {
- chillAST_MacroDefinition *macro = findMacro( name );
- if (macro) return (chillAST_node *)macro;
- chillAST_FunctionDecl *func =findFunction( name );
+chillAST_node *chillAST_SourceFile::findCall(const char *name) {
+ chillAST_MacroDefinition *macro = findMacro(name);
+ if (macro) return (chillAST_node *) macro;
+ chillAST_FunctionDecl *func = findFunction(name);
return func;
}
-chillAST_VarDecl * chillAST_SourceFile::findVariableNamed( const char *name ) {
- fprintf(stderr, "SOURCEFILE SPECIAL %s findVariableNamed( %s )\n", getTypeString(), name );
+chillAST_VarDecl *chillAST_SourceFile::findVariableNamed(const char *name) {
+ fprintf(stderr, "SOURCEFILE SPECIAL %s findVariableNamed( %s )\n", getTypeString(), name);
if (hasSymbolTable()) { // look in my symbol table if I have one
- fprintf(stderr, "%s has a symbol table\n", getTypeString());
- chillAST_VarDecl *vd = symbolTableFindVariableNamed( getSymbolTable(), name);
+ fprintf(stderr, "%s has a symbol table\n", getTypeString());
+ chillAST_VarDecl *vd = symbolTableFindVariableNamed(getSymbolTable(), name);
if (vd) {
- fprintf(stderr, "found it\n");
+ fprintf(stderr, "found it\n");
return vd; // found locally
}
- fprintf(stderr, "%s has a symbol table but couldn't find %s\n", getTypeString(), name );
+ fprintf(stderr, "%s has a symbol table but couldn't find %s\n", getTypeString(), name);
}
fprintf(stderr, "looking for %s in SourceFile global_symbol_table\n", name);
- chillAST_VarDecl *vd = symbolTableFindVariableNamed( global_symbol_table, name );
+ chillAST_VarDecl *vd = symbolTableFindVariableNamed(global_symbol_table, name);
if (vd) {
- fprintf(stderr, "found it\n");
+ fprintf(stderr, "found it\n");
return vd; // found locally
}
@@ -586,299 +573,296 @@ chillAST_VarDecl * chillAST_SourceFile::findVariableNamed( const char *name ) {
// recurse upwards
//fprintf(stderr, "recursing from %s up to parent %p\n", getTypeString(), parent);
fprintf(stderr, "recursing from %s up to parent\n", getTypeString());
- return parent->findVariableNamed( name );
+ return parent->findVariableNamed(name);
}
-
-chillAST_TypedefDecl::chillAST_TypedefDecl() {
- underlyingtype = newtype = arraypart = NULL;
- asttype = CHILLAST_NODETYPE_TYPEDEFDECL;
+chillAST_TypedefDecl::chillAST_TypedefDecl() {
+ underlyingtype = newtype = arraypart = NULL;
+ asttype = CHILLAST_NODETYPE_TYPEDEFDECL;
parent = NULL;
metacomment = NULL;
isStruct = isUnion = false;
- structname = NULL;
- rd = NULL;
- isFromSourceFile = true; // default
- filename = NULL;
+ structname = NULL;
+ rd = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
};
chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *nt, chillAST_node *par) {
- //fprintf(stderr, "chillAST_TypedefDecl::chillAST_TypedefDecl( underlying type %s, newtype %s )\n", t, nt);
- underlyingtype = strdup(t);
+ //fprintf(stderr, "chillAST_TypedefDecl::chillAST_TypedefDecl( underlying type %s, newtype %s )\n", t, nt);
+ underlyingtype = strdup(t);
newtype = strdup(nt);
- arraypart = NULL;
+ arraypart = NULL;
asttype = CHILLAST_NODETYPE_TYPEDEFDECL;
- parent = NULL;
+ parent = NULL;
metacomment = NULL;
isStruct = isUnion = false;
- structname = NULL;
- rd = NULL;
- isFromSourceFile = true; // default
- filename = NULL;
+ structname = NULL;
+ rd = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
};
chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *a, char *p, chillAST_node *par) {
- underlyingtype = strdup(t);
- //fprintf(stderr, "chillAST_TypedefDecl::chillAST_TypedefDecl( underlying type %s )\n", underlyingtype);
+ underlyingtype = strdup(t);
+ //fprintf(stderr, "chillAST_TypedefDecl::chillAST_TypedefDecl( underlying type %s )\n", underlyingtype);
newtype = strdup(a); // the new named type ??
- arraypart = strdup(p); // array (p)art?
- // splitarraypart(); // TODO
+ arraypart = strdup(p); // array (p)art?
+ // splitarraypart(); // TODO
- asttype = CHILLAST_NODETYPE_TYPEDEFDECL;
+ asttype = CHILLAST_NODETYPE_TYPEDEFDECL;
parent = par;
metacomment = NULL;
isStruct = isUnion = false;
- structname = NULL;
- rd = NULL;
- isFromSourceFile = true; // default
- filename = NULL;
+ structname = NULL;
+ rd = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
};
+void chillAST_TypedefDecl::print(int indent, FILE *fp) {
+ //fprintf(fp, "typedefdecl->print()\n");
+ printPreprocBEFORE(indent, fp);
-void chillAST_TypedefDecl::print( int indent, FILE *fp ) {
- //fprintf(fp, "typedefdecl->print()\n");
-
- printPreprocBEFORE(indent, fp);
-
- if (isStruct) {
- fprintf(fp, "\n/* A typedef STRUCT */\n"); chillindent(indent, fp);
+ if (isStruct) {
+ fprintf(fp, "\n/* A typedef STRUCT */\n");
+ chillindent(indent, fp);
}
chillindent(indent, fp);
- fprintf(fp, "typedef "); fflush(fp);
-
- if (rd) {
- rd->print(indent, fp); // needs to not print the ending semicolon ??
- }
-
- else if (isStruct) {
- fprintf(stderr, "/* no rd */\n");
-
+ fprintf(fp, "typedef ");
+ fflush(fp);
+
+ if (rd) {
+ rd->print(indent, fp); // needs to not print the ending semicolon ??
+ } else if (isStruct) {
+ fprintf(stderr, "/* no rd */\n");
+
//fprintf(fp, "struct %s\n", structname);
chillindent(indent, fp);
fprintf(fp, "{\n");
- for (int i=0; i<subparts.size(); i++) {
- //fprintf(fp, "a %s\n", subparts[i]->getTypeString());
- subparts[i]->print(indent+1, fp);
+ for (int i = 0; i < subparts.size(); i++) {
+ //fprintf(fp, "a %s\n", subparts[i]->getTypeString());
+ subparts[i]->print(indent + 1, fp);
fprintf(fp, ";\n");
}
fprintf(fp, "};\n");
+ } else {
+ fprintf(fp, "/* NOT A STRUCT */ typedef %s %s%s;\n", underlyingtype, newtype, arraypart);
+ dump();
+ printf("\n\n");
+ fflush(stdout);
}
- else {
- fprintf(fp, "/* NOT A STRUCT */ typedef %s %s%s;\n", underlyingtype, newtype, arraypart );
- dump(); printf("\n\n"); fflush(stdout);
- }
-
- // then the newname
- fprintf(fp, "%s;\n", newtype);
- fflush(fp);
- printPreprocAFTER(indent, fp);
+
+ // then the newname
+ fprintf(fp, "%s;\n", newtype);
+ fflush(fp);
+ printPreprocAFTER(indent, fp);
return;
}
-chillAST_VarDecl *chillAST_TypedefDecl::findSubpart( const char *name ) {
+chillAST_VarDecl *chillAST_TypedefDecl::findSubpart(const char *name) {
//fprintf(stderr, "chillAST_TypedefDecl::findSubpart( %s )\n", name);
- //fprintf(stderr, "typedef %s %s\n", structname, newtype);
+ //fprintf(stderr, "typedef %s %s\n", structname, newtype);
if (rd) { // we have a record decl look there
- chillAST_VarDecl *sub = rd->findSubpart( name );
- //fprintf(stderr, "rd found subpart %p\n", sub);
- return sub;
+ chillAST_VarDecl *sub = rd->findSubpart(name);
+ //fprintf(stderr, "rd found subpart %p\n", sub);
+ return sub;
}
- // can this ever happen now ???
+ // can this ever happen now ???
int nsub = subparts.size();
- //fprintf(stderr, "%d subparts\n", nsub);
- for (int i=0; i<nsub; i++) {
- if ( !strcmp( name, subparts[i]->varname )) return subparts[i];
+ //fprintf(stderr, "%d subparts\n", nsub);
+ for (int i = 0; i < nsub; i++) {
+ if (!strcmp(name, subparts[i]->varname)) return subparts[i];
}
- //fprintf(stderr, "subpart not found\n");
+ //fprintf(stderr, "subpart not found\n");
+
-
- return NULL;
+ return NULL;
}
-chillAST_RecordDecl * chillAST_TypedefDecl::getStructDef() {
+chillAST_RecordDecl *chillAST_TypedefDecl::getStructDef() {
if (rd) return rd;
- return NULL;
+ return NULL;
}
-
-chillAST_RecordDecl::chillAST_RecordDecl() {
+chillAST_RecordDecl::chillAST_RecordDecl() {
asttype = CHILLAST_NODETYPE_RECORDDECL;
- name = strdup("unknown"); // ??
- originalname = NULL; // ??
+ name = strdup("unknown"); // ??
+ originalname = NULL; // ??
isStruct = isUnion = false;
- parent = NULL;
- isFromSourceFile = true; // default
- filename = NULL;
+ parent = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
}
-chillAST_RecordDecl::chillAST_RecordDecl( const char *nam, chillAST_node *p ) {
+chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, chillAST_node *p) {
//fprintf(stderr, "chillAST_RecordDecl::chillAST_RecordDecl()\n");
asttype = CHILLAST_NODETYPE_RECORDDECL;
- parent = p;
+ parent = p;
if (nam) name = strdup(nam);
- else name = strdup("unknown"); // ??
+ else name = strdup("unknown"); // ??
originalname = NULL; // ?? // make them do it manually?
isStruct = isUnion = false;
- isFromSourceFile = true; // default
- filename = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
}
-chillAST_RecordDecl::chillAST_RecordDecl( const char *nam, const char *orig, chillAST_node *p ) {
- fprintf(stderr, "chillAST_RecordDecl::chillAST_RecordDecl( %s, ( AKA %s ) )\n", nam, orig);
+chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, const char *orig, chillAST_node *p) {
+ fprintf(stderr, "chillAST_RecordDecl::chillAST_RecordDecl( %s, ( AKA %s ) )\n", nam, orig);
asttype = CHILLAST_NODETYPE_RECORDDECL;
- parent = p;
- if (p) p->addChild( this );
-
+ parent = p;
+ if (p) p->addChild(this);
+
if (nam) name = strdup(nam);
- else name = strdup("unknown"); // ??
-
- originalname = NULL;
+ else name = strdup("unknown"); // ??
+
+ originalname = NULL;
if (orig) originalname = strdup(orig);
-
+
isStruct = isUnion = false;
- isFromSourceFile = true; // default
- filename = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
}
-
-chillAST_VarDecl * chillAST_RecordDecl::findSubpart( const char *nam ){
+chillAST_VarDecl *chillAST_RecordDecl::findSubpart(const char *nam) {
//fprintf(stderr, "chillAST_RecordDecl::findSubpart( %s )\n", nam);
int nsub = subparts.size();
//fprintf(stderr, "%d subparts\n", nsub);
- for (int i=0; i<nsub; i++) {
+ for (int i = 0; i < nsub; i++) {
//fprintf(stderr, "comparing to '%s' to '%s'\n", nam, subparts[i]->varname);
- if ( !strcmp( nam, subparts[i]->varname )) return subparts[i];
+ if (!strcmp(nam, subparts[i]->varname)) return subparts[i];
}
- fprintf(stderr, "chillAST_RecordDecl::findSubpart() couldn't find member NAMED %s in ", nam); print(); printf("\n\n"); fflush(stdout);
+ fprintf(stderr, "chillAST_RecordDecl::findSubpart() couldn't find member NAMED %s in ", nam);
+ print();
+ printf("\n\n");
+ fflush(stdout);
- return NULL;
+ return NULL;
}
-chillAST_VarDecl * chillAST_RecordDecl::findSubpartByType( const char *typ ){
+chillAST_VarDecl *chillAST_RecordDecl::findSubpartByType(const char *typ) {
//fprintf(stderr, "chillAST_RecordDecl::findSubpart( %s )\n", nam);
int nsub = subparts.size();
//fprintf(stderr, "%d subparts\n", nsub);
- for (int i=0; i<nsub; i++) {
+ for (int i = 0; i < nsub; i++) {
//fprintf(stderr, "comparing '%s' to '%s'\n", typ, subparts[i]->vartype);
- if ( !strcmp( typ, subparts[i]->vartype )) return subparts[i];
+ if (!strcmp(typ, subparts[i]->vartype)) return subparts[i];
}
- //fprintf(stderr, "chillAST_RecordDecl::findSubpart() couldn't find member of TYPE %s in ", typ); print(); printf("\n\n"); fflush(stdout);
+ //fprintf(stderr, "chillAST_RecordDecl::findSubpart() couldn't find member of TYPE %s in ", typ); print(); printf("\n\n"); fflush(stdout);
- return NULL;
+ return NULL;
}
-void chillAST_RecordDecl::print( int indent, FILE *fp ) {
+void chillAST_RecordDecl::print(int indent, FILE *fp) {
//fprintf(fp, "chillAST_RecordDecl::print()\n");
- if (isUnnamed) return;
-
- printPreprocBEFORE(indent, fp);
+ if (isUnnamed) return;
+
+ printPreprocBEFORE(indent, fp);
- chillindent(indent, fp);
- if (isStruct) {
+ chillindent(indent, fp);
+ if (isStruct) {
//fprintf(fp, "\n/* A Record Decl STRUCT */\n"); chillindent(indent, fp);
fprintf(fp, "struct ");
- if ( strncmp( "unnamed", name, 7) ) fprintf(fp, "%s\n", name);
-
+ if (strncmp("unnamed", name, 7)) fprintf(fp, "%s\n", name);
+
chillindent(indent, fp);
fprintf(fp, "{\n");
- for (int i=0; i<subparts.size(); i++) {
- //fprintf(fp, "a %s\n", subparts[i]->getTypeString());
- subparts[i]->print(indent+1, fp);
+ for (int i = 0; i < subparts.size(); i++) {
+ //fprintf(fp, "a %s\n", subparts[i]->getTypeString());
+ subparts[i]->print(indent + 1, fp);
fprintf(fp, ";\n");
}
fprintf(fp, "} ");
- fprintf(fp, "\n"); // TODO need semicolon when defining struct. can't have it when part of a typedef. One of the following lines is correct in each case.
+ fprintf(fp,
+ "\n"); // TODO need semicolon when defining struct. can't have it when part of a typedef. One of the following lines is correct in each case.
//fprintf(fp, ";\n");
- }
- else {
+ } else {
fprintf(fp, "/* UNKNOWN RECORDDECL print() */ ");
exit(-1);
}
- printPreprocAFTER(indent, fp);
- fflush(fp);
+ printPreprocAFTER(indent, fp);
+ fflush(fp);
}
-chillAST_SymbolTable * chillAST_RecordDecl::addVariableToSymbolTable( chillAST_VarDecl *vd ){
+chillAST_SymbolTable *chillAST_RecordDecl::addVariableToSymbolTable(chillAST_VarDecl *vd) {
// for now, just bail. or do we want the struct to have an actual symbol table?
- //fprintf(stderr, "chillAST_RecordDecl::addVariableToSymbolTable() ignoring struct member %s vardecl\n", vd->varname);
- return NULL; // damn, I hope nothing uses this!
+ //fprintf(stderr, "chillAST_RecordDecl::addVariableToSymbolTable() ignoring struct member %s vardecl\n", vd->varname);
+ return NULL; // damn, I hope nothing uses this!
}
-void chillAST_RecordDecl::printStructure( int indent, FILE *fp ) {
- //fprintf(stderr, "chillAST_RecordDecl::printStructure()\n");
- chillindent(indent, fp);
- if (isStruct) {
+void chillAST_RecordDecl::printStructure(int indent, FILE *fp) {
+ //fprintf(stderr, "chillAST_RecordDecl::printStructure()\n");
+ chillindent(indent, fp);
+ if (isStruct) {
fprintf(fp, "struct { ", name);
- for (int i=0; i<subparts.size(); i++) {
- subparts[i]->print( 0, fp); // ?? TODO indent level
+ for (int i = 0; i < subparts.size(); i++) {
+ subparts[i]->print(0, fp); // ?? TODO indent level
fprintf(fp, "; ");
}
fprintf(fp, "} ");
- }
- else {
+ } else {
fprintf(fp, "/* UNKNOWN RECORDDECL printStructure() */ ");
exit(-1);
}
- fflush(fp);
+ fflush(fp);
}
+void chillAST_RecordDecl::dump(int indent, FILE *fp) {
+ chillindent(indent, fp);
-void chillAST_RecordDecl::dump( int indent, FILE *fp ) {
- chillindent(indent, fp);
-
}
-chillAST_FunctionDecl::chillAST_FunctionDecl() {
- functionName = strdup("YouScrewedUp");
- asttype = CHILLAST_NODETYPE_FUNCTIONDECL;
- forwarddecl = externfunc = builtin = false;
+chillAST_FunctionDecl::chillAST_FunctionDecl() {
+ functionName = strdup("YouScrewedUp");
+ asttype = CHILLAST_NODETYPE_FUNCTIONDECL;
+ forwarddecl = externfunc = builtin = false;
uniquePtr = (void *) NULL;
- this->setFunctionCPU();
+ this->setFunctionCPU();
parent = NULL;
metacomment = NULL;
//symbol_table = NULL; // eventually, pointing to body's symbol table
typedef_table = NULL;
body = new chillAST_CompoundStmt();
- isFromSourceFile = true; // default
- filename = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
};
-chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *par) {
+chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *par) {
returnType = strdup(rt);
functionName = strdup(fname);
- this->setFunctionCPU();
- //fprintf(stderr, "functionName %s\n", functionName);
- forwarddecl = externfunc = builtin = false;
+ this->setFunctionCPU();
+ //fprintf(stderr, "functionName %s\n", functionName);
+ forwarddecl = externfunc = builtin = false;
- asttype = CHILLAST_NODETYPE_FUNCTIONDECL;
+ asttype = CHILLAST_NODETYPE_FUNCTIONDECL;
parent = par;
metacomment = NULL;
- if (par) par->getSourceFile()->addFunc( this );
+ if (par) par->getSourceFile()->addFunc(this);
// symbol_table = NULL; //use body's instead
typedef_table = NULL;
body = new chillAST_CompoundStmt();
- isFromSourceFile = true; // default
- filename = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
};
@@ -886,161 +870,161 @@ chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname,
CHILL_DEBUG_PRINT("chillAST_FunctionDecl::chillAST_FunctionDecl with unique %p\n", unique);
returnType = strdup(rt);
functionName = strdup(fname);
- this->setFunctionCPU();
- //fprintf(stderr, "functionName %s\n", functionName);
- forwarddecl = externfunc = builtin = false;
+ this->setFunctionCPU();
+ //fprintf(stderr, "functionName %s\n", functionName);
+ forwarddecl = externfunc = builtin = false;
body = new chillAST_CompoundStmt();
- asttype = CHILLAST_NODETYPE_FUNCTIONDECL;
- uniquePtr = unique; // a quick way to check equivalence. DO NOT ACCESS THROUGH THIS
+ asttype = CHILLAST_NODETYPE_FUNCTIONDECL;
+ uniquePtr = unique; // a quick way to check equivalence. DO NOT ACCESS THROUGH THIS
parent = par;
metacomment = NULL;
- if (par) par->getSourceFile()->addFunc( this );
- //symbol_table = NULL; // use body's
+ if (par) par->getSourceFile()->addFunc(this);
+ //symbol_table = NULL; // use body's
typedef_table = NULL;
- isFromSourceFile = true; // default
- filename = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
};
-void chillAST_FunctionDecl::addParameter( chillAST_VarDecl *p) {
- CHILL_DEBUG_PRINT("%s chillAST_FunctionDecl::addParameter( 0x%x param %s) total of %d parameters\n", functionName, p, p->varname, 1+parameters.size());
+void chillAST_FunctionDecl::addParameter(chillAST_VarDecl *p) {
+ 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
+ if (symbolTableHasVariableNamed(&parameters, p->varname)) { // NOT recursive. just in FunctionDecl
CHILL_DEBUG_PRINT("chillAST_FunctionDecl::addParameter( %s ), parameter already exists?\n", p->varname);
- // exit(-1); // ??
- return; // error?
+ // exit(-1); // ??
+ return; // error?
}
parameters.push_back(p);
//addSymbolToTable( parameters, p );
CHILL_DEBUG_PRINT("setting %s isAParameter\n", p->varname);
- p->isAParameter = true;
-
- p->setParent( this ); // ?? unclear TODO
- //p->dump(); printf("\naddparameter done\n\n"); fflush(stdout);
-}
+ p->isAParameter = true;
+ p->setParent(this); // ?? unclear TODO
+ //p->dump(); printf("\naddparameter done\n\n"); fflush(stdout);
+}
-void chillAST_FunctionDecl::addDecl( chillAST_VarDecl *vd) { // to symbol table ONLY
+void chillAST_FunctionDecl::addDecl(chillAST_VarDecl *vd) { // to symbol table ONLY
CHILL_DEBUG_PRINT("chillAST_FunctionDecl::addDecl( %s )\n", vd->varname);
- if (!body) {
- //fprintf(stderr, "had no body\n");
+ if (!body) {
+ //fprintf(stderr, "had no body\n");
body = new chillAST_CompoundStmt();
-
+
//body->symbol_table = symbol_table; // probably wrong if this ever does something
}
- //fprintf(stderr, "before body->addvar(), func symbol table had %d entries\n", symbol_table->size());
- //fprintf(stderr, "before body->addvar(), body symbol table was %p\n", body->symbol_table);
- //fprintf(stderr, "before body->addvar(), body symbol table had %d entries\n", body->symbol_table->size());
+ //fprintf(stderr, "before body->addvar(), func symbol table had %d entries\n", symbol_table->size());
+ //fprintf(stderr, "before body->addvar(), body symbol table was %p\n", body->symbol_table);
+ //fprintf(stderr, "before body->addvar(), body symbol table had %d entries\n", body->symbol_table->size());
//adds to body symbol table, and makes sure function has a copy. probably dumb
- body->symbol_table = body->addVariableToSymbolTable( vd );
- //fprintf(stderr, "after body->addvar(), func symbol table had %d entries\n", symbol_table->size());
+ body->symbol_table = body->addVariableToSymbolTable(vd);
+ //fprintf(stderr, "after body->addvar(), func symbol table had %d entries\n", symbol_table->size());
}
-chillAST_VarDecl *chillAST_FunctionDecl::hasParameterNamed( const char *name ) {
+chillAST_VarDecl *chillAST_FunctionDecl::hasParameterNamed(const char *name) {
int numparams = parameters.size();
- for (int i=0; i<numparams; i++) {
- if (!strcmp(name, parameters[i]->varname)) return parameters[i]; // need to check type?
+ for (int i = 0; i < numparams; i++) {
+ if (!strcmp(name, parameters[i]->varname)) return parameters[i]; // need to check type?
}
- return NULL;
+ return NULL;
}
// similar to symbolTableHasVariableNamed() but returns the variable definition
-chillAST_VarDecl *chillAST_FunctionDecl::funcHasVariableNamed( const char *name ) { // NOT recursive
+chillAST_VarDecl *chillAST_FunctionDecl::funcHasVariableNamed(const char *name) { // NOT recursive
//fprintf(stderr, "chillAST_FunctionDecl::funcHasVariableNamed( %s )\n", name );
// first check the parameters
int numparams = parameters.size();
- for (int i=0; i<numparams; i++) {
+ for (int i = 0; i < numparams; i++) {
chillAST_VarDecl *vd = parameters[i];
- if (!strcmp(name, vd->varname)) {
- //fprintf(stderr, "yep, it's parameter %d\n", i);
- return vd; // need to check type?
+ if (!strcmp(name, vd->varname)) {
+ //fprintf(stderr, "yep, it's parameter %d\n", i);
+ return vd; // need to check type?
}
}
- //fprintf(stderr, "no parameter named %s\n", name);
+ //fprintf(stderr, "no parameter named %s\n", name);
- chillAST_SymbolTable *st = getSymbolTable();
+ chillAST_SymbolTable *st = getSymbolTable();
if (!st) {
- fprintf(stderr,"and no symbol_table, so no variable named %s\n", name);
- return NULL; // no symbol table so no variable by that name
+ fprintf(stderr, "and no symbol_table, so no variable named %s\n", name);
+ return NULL; // no symbol table so no variable by that name
}
-
- int numvars = st->size();
- //fprintf(stderr, "checking against %d variables\n", numvars);
- for (int i=0; i<numvars; i++) {
+
+ int numvars = st->size();
+ //fprintf(stderr, "checking against %d variables\n", numvars);
+ for (int i = 0; i < numvars; i++) {
chillAST_VarDecl *vd = (*st)[i];
- //fprintf(stderr, "comparing '%s' to '%s'\n", name, vd->varname);
+ //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, "yep, it's variable %d\n", i);
CHILL_DEBUG_PRINT("%s was already defined in the function body\n", vd->varname);
- return vd; // need to check type?
+ return vd; // need to check type?
}
}
CHILL_DEBUG_PRINT("not a parameter or variable named %s\n", name);
- return NULL;
+ return NULL;
}
-
-
-void chillAST_FunctionDecl::setBody( chillAST_node * bod ) {
- //fprintf(stderr, "%s chillAST_FunctionDecl::setBody( 0x%x ) total of %d children\n", functionName, bod, 1+children.size());
- if (bod->isCompoundStmt()) body = (chillAST_CompoundStmt *)bod;
- else {
+void chillAST_FunctionDecl::setBody(chillAST_node *bod) {
+ //fprintf(stderr, "%s chillAST_FunctionDecl::setBody( 0x%x ) total of %d children\n", functionName, bod, 1+children.size());
+ if (bod->isCompoundStmt()) body = (chillAST_CompoundStmt *) bod;
+ else {
body = new chillAST_CompoundStmt();
- body->addChild( bod );
+ body->addChild(bod);
}
- //symbol_table = body->getSymbolTable();
+ //symbol_table = body->getSymbolTable();
//addChild(bod);
- bod->setParent( this ); // well, ...
+ bod->setParent(this); // well, ...
}
-void chillAST_FunctionDecl::insertChild(int i, chillAST_node* node) {
- fprintf(stderr, "chillAST_FunctionDecl::insertChild() "); node->print(0,stderr); fprintf(stderr, "\n\n");
- body->insertChild( i, node );
+void chillAST_FunctionDecl::insertChild(int i, chillAST_node *node) {
+ fprintf(stderr, "chillAST_FunctionDecl::insertChild() ");
+ node->print(0, stderr);
+ fprintf(stderr, "\n\n");
+ body->insertChild(i, node);
- if (node->isVarDecl()) {
+ if (node->isVarDecl()) {
chillAST_VarDecl *vd = ((chillAST_VarDecl *) node);
fprintf(stderr, "functiondecl %s inserting a VarDecl named %s\n", functionName, vd->varname);
chillAST_SymbolTable *st = getSymbolTable();
- if (!st) {
- fprintf(stderr, "symbol table is NULL!\n");
- }
- else {
- fprintf(stderr, "%d entries in the symbol table\n", st->size());
- printSymbolTable( getSymbolTable() );
+ if (!st) {
+ fprintf(stderr, "symbol table is NULL!\n");
+ } else {
+ fprintf(stderr, "%d entries in the symbol table\n", st->size());
+ printSymbolTable(getSymbolTable());
}
- fprintf(stderr, "\n\n");
+ fprintf(stderr, "\n\n");
}
}
-void chillAST_FunctionDecl::addChild(chillAST_node* node) {
+void chillAST_FunctionDecl::addChild(chillAST_node *node) {
CHILL_DEBUG_BEGIN
- node->print(0,stderr); fprintf(stderr, "\n\n");
+ node->print(0, stderr);
+ fprintf(stderr, "\n\n");
CHILL_DEBUG_END
- if (node->isVarDecl()) {
+ if (node->isVarDecl()) {
chillAST_VarDecl *vd = ((chillAST_VarDecl *) node);
CHILL_DEBUG_PRINT("functiondecl %s adding a VarDecl named %s\n", functionName, vd->varname);
}
- body->addChild( node );
- node->parent = this; // this, or body??
+ body->addChild(node);
+ node->parent = this; // this, or body??
}
-void chillAST_FunctionDecl::printParameterTypes( FILE *fp ) { // also prints names
- //fprintf(stderr, "\n\n%s chillAST_FunctionDecl::printParameterTypes()\n", functionName);
- fprintf(fp, "( ");
- int numparameters = parameters.size();
- for (int i=0; i<numparameters; i++) {
- if (i!=0) fprintf(fp, ", ");
+void chillAST_FunctionDecl::printParameterTypes(FILE *fp) { // also prints names
+ //fprintf(stderr, "\n\n%s chillAST_FunctionDecl::printParameterTypes()\n", functionName);
+ fprintf(fp, "( ");
+ int numparameters = parameters.size();
+ for (int i = 0; i < numparameters; i++) {
+ if (i != 0) fprintf(fp, ", ");
chillAST_VarDecl *p = parameters[i];
p->print(0, fp); // note: no indent, as this is in the function parens
}
@@ -1049,403 +1033,392 @@ void chillAST_FunctionDecl::printParameterTypes( FILE *fp ) { // also prints n
}
-
-
-void chillAST_FunctionDecl::print( int indent, FILE *fp ) {
- //fprintf(fp, "\n// functiondecl %p \n", this);
- //chillindent(indent, fp);
+void chillAST_FunctionDecl::print(int indent, FILE *fp) {
+ //fprintf(fp, "\n// functiondecl %p \n", this);
+ //chillindent(indent, fp);
//fprintf(fp, "//(functiondecl) %d parameters\n", numparameters);
- printPreprocBEFORE(indent, fp);
+ printPreprocBEFORE(indent, fp);
fprintf(fp, "\n");
- chillindent(indent, fp);
+ chillindent(indent, fp);
+
+ if (externfunc) fprintf(fp, "extern ");
- if (externfunc) fprintf(fp, "extern ");
+ if (function_type == CHILL_FUNCTION_GPU) fprintf(fp, "__global__ ");
+ fprintf(fp, "%s %s", returnType, functionName);
+ printParameterTypes(fp);
- if (function_type == CHILL_FUNCTION_GPU) fprintf(fp, "__global__ ");
- fprintf(fp, "%s %s", returnType, functionName );
- printParameterTypes(fp);
-
- // non-parameter variables (now must have explicit vardecl in the body)
+ // non-parameter variables (now must have explicit vardecl in the body)
//int numvars = symbol_table.size();
- //for (int i=0; i<numvars; i++) {
+ //for (int i=0; i<numvars; i++) {
// symbol_table[i]->print(1,fp);
- // fprintf(fp, ";\n");
- //}
-
- // now the body
- if (!(externfunc || forwarddecl)) {
- if (body) {
- fprintf(fp, "\n{\n");
- //chillindent(indent+1, fp); fprintf(fp, "//body\n"); fflush(fp);
- body->print( indent+1, fp);
- fprintf(fp, "\n");
- //chillindent(indent+1, fp); fprintf(fp, "//END body\n"); fflush(fp);
-
+ // fprintf(fp, ";\n");
+ //}
+
+ // now the body
+ if (!(externfunc || forwarddecl)) {
+ if (body) {
+ fprintf(fp, "\n{\n");
+ //chillindent(indent+1, fp); fprintf(fp, "//body\n"); fflush(fp);
+ body->print(indent + 1, fp);
+ fprintf(fp, "\n");
+ //chillindent(indent+1, fp); fprintf(fp, "//END body\n"); fflush(fp);
+
// tidy up
- chillindent(indent, fp);
+ chillindent(indent, fp);
fprintf(fp, "}\n");
- } // if body
- else {
- fprintf(fp, "{}\n"); // should never happen, but not external and no body
+ } // if body
+ else {
+ fprintf(fp, "{}\n"); // should never happen, but not external and no body
}
- }
- else { // extern func or forward decl. just end forward declaration
+ } else { // extern func or forward decl. just end forward declaration
fprintf(fp, "; // fwd decl\n");
}
-
- printPreprocAFTER(indent, fp);
- fflush(fp);
+ printPreprocAFTER(indent, fp);
+
+ fflush(fp);
}
-
-void chillAST_FunctionDecl::dump( int indent, FILE *fp ) {
- fprintf(fp, "\n");
+void chillAST_FunctionDecl::dump(int indent, FILE *fp) {
+ fprintf(fp, "\n");
fprintf(fp, "// isFromSourceFile ");
- if (filename) fprintf(fp, "%s ", filename);
- if (isFromSourceFile) fprintf(fp, "true\n");
- else fprintf(fp, "false\n");
- chillindent(indent, fp);
- fprintf(fp, "(FunctionDecl %s %s(", returnType, functionName );
-
- int numparameters = parameters.size();
- for (int i=0; i<numparameters; i++) {
- if (i!=0) fprintf(fp, ", ");
+ if (filename) fprintf(fp, "%s ", filename);
+ if (isFromSourceFile) fprintf(fp, "true\n");
+ else fprintf(fp, "false\n");
+ chillindent(indent, fp);
+ fprintf(fp, "(FunctionDecl %s %s(", returnType, functionName);
+
+ int numparameters = parameters.size();
+ for (int i = 0; i < numparameters; i++) {
+ if (i != 0) fprintf(fp, ", ");
chillAST_VarDecl *p = parameters[i];
- //fprintf(stderr, "param type %s vartype %s\n", p->getTypeString(), p->vartype);
+ //fprintf(stderr, "param type %s vartype %s\n", p->getTypeString(), p->vartype);
p->print(0, fp); // note: no indent, as this is in the function parens, ALSO print, not dump
}
fprintf(fp, ")\n"); // end of input parameters
-
- // now the body -
- if (body) body->dump( indent+1 , fp);
+
+ // now the body -
+ if (body) body->dump(indent + 1, fp);
// tidy up
- chillindent(indent, fp);
+ chillindent(indent, fp);
fprintf(fp, ")\n");
- fflush(fp);
+ fflush(fp);
}
-
-
-
-
-void chillAST_FunctionDecl::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_FunctionDecl::gatherVarDecls()\n");
- //if (0 < children.size()) fprintf(stderr, "functiondecl has %d children\n", children.size());
+void chillAST_FunctionDecl::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_FunctionDecl::gatherVarDecls()\n");
+ //if (0 < children.size()) fprintf(stderr, "functiondecl has %d children\n", children.size());
//fprintf(stderr, "functiondecl has %d parameters\n", numParameters());
- for (int i=0; i<numParameters(); i++) parameters[i]->gatherVarDecls( decls );
- //fprintf(stderr, "after parms, %d decls\n", decls.size());
- for (int i=0; i<children.size(); i++) children[i]->gatherVarDecls( decls );
- //fprintf(stderr, "after children, %d decls\n", decls.size());
- body->gatherVarDecls( decls ); // todo, figure out if functiondecl has actual children
- //fprintf(stderr, "after body, %d decls\n", decls.size());
+ for (int i = 0; i < numParameters(); i++) parameters[i]->gatherVarDecls(decls);
+ //fprintf(stderr, "after parms, %d decls\n", decls.size());
+ for (int i = 0; i < children.size(); i++) children[i]->gatherVarDecls(decls);
+ //fprintf(stderr, "after children, %d decls\n", decls.size());
+ body->gatherVarDecls(decls); // todo, figure out if functiondecl has actual children
+ //fprintf(stderr, "after body, %d decls\n", decls.size());
//for (int d=0; d<decls.size(); d++) {
- // decls[d]->print(0,stderr); fprintf(stderr, "\n");
- //}
+ // decls[d]->print(0,stderr); fprintf(stderr, "\n");
+ //}
}
-void chillAST_FunctionDecl::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //if (0 < children.size()) fprintf(stderr, "functiondecl has %d children\n", children.size());
-
- for (int i=0; i<numParameters(); i++) parameters[i]->gatherScalarVarDecls( decls );
- for (int i=0; i<children.size(); i++) children[i]->gatherScalarVarDecls( decls );
- body->gatherScalarVarDecls( decls ); // todo, figure out if functiondecl has actual children
+void chillAST_FunctionDecl::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //if (0 < children.size()) fprintf(stderr, "functiondecl has %d children\n", children.size());
+
+ for (int i = 0; i < numParameters(); i++) parameters[i]->gatherScalarVarDecls(decls);
+ for (int i = 0; i < children.size(); i++) children[i]->gatherScalarVarDecls(decls);
+ body->gatherScalarVarDecls(decls); // todo, figure out if functiondecl has actual children
}
-void chillAST_FunctionDecl::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //if (0 < children.size()) fprintf(stderr, "functiondecl has %d children\n", children.size());
-
- for (int i=0; i<numParameters(); i++) parameters[i]->gatherArrayVarDecls( decls );
- for (int i=0; i<children.size(); i++) children[i]->gatherArrayVarDecls( decls );
- body->gatherArrayVarDecls( decls ); // todo, figure out if functiondecl has actual children
+void chillAST_FunctionDecl::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //if (0 < children.size()) fprintf(stderr, "functiondecl has %d children\n", children.size());
+
+ for (int i = 0; i < numParameters(); i++) parameters[i]->gatherArrayVarDecls(decls);
+ for (int i = 0; i < children.size(); i++) children[i]->gatherArrayVarDecls(decls);
+ body->gatherArrayVarDecls(decls); // todo, figure out if functiondecl has actual children
}
-chillAST_VarDecl *chillAST_FunctionDecl::findArrayDecl( const char *name ) {
+chillAST_VarDecl *chillAST_FunctionDecl::findArrayDecl(const char *name) {
//fprintf(stderr, "chillAST_FunctionDecl::findArrayDecl( %s )\n", name );
- chillAST_VarDecl *p = hasParameterNamed( name );
+ chillAST_VarDecl *p = hasParameterNamed(name);
//if (p) fprintf(stderr, "function %s has parameter named %s\n", functionName, name );
if (p && p->isArray()) return p;
- chillAST_VarDecl *v = funcHasVariableNamed ( name );
+ chillAST_VarDecl *v = funcHasVariableNamed(name);
//if (v) fprintf(stderr, "function %s has symbol table variable named %s\n", functionName, name );
if (v && v->isArray()) return v;
// declared variables that may not be in symbol table but probably should be
- vector<chillAST_VarDecl*> decls ;
- gatherArrayVarDecls( decls );
- for (int i=0; i<decls.size(); i++) {
- chillAST_VarDecl *vd = decls[i];
- if (0 == strcmp(vd->varname, name ) && vd->isArray()) return vd;
+ vector<chillAST_VarDecl *> decls;
+ gatherArrayVarDecls(decls);
+ for (int i = 0; i < decls.size(); i++) {
+ chillAST_VarDecl *vd = decls[i];
+ if (0 == strcmp(vd->varname, name) && vd->isArray()) return vd;
}
- //fprintf(stderr, "can't find array named %s in function %s \n", name, functionName);
- return NULL;
+ //fprintf(stderr, "can't find array named %s in function %s \n", name, functionName);
+ return NULL;
}
-void chillAST_FunctionDecl::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- for (int i=0; i<children.size(); i++) children[i]->gatherVarUsage( decls );
- body->gatherVarUsage( decls ); // todo, figure out if functiondecl has actual children
+void chillAST_FunctionDecl::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ for (int i = 0; i < children.size(); i++) children[i]->gatherVarUsage(decls);
+ body->gatherVarUsage(decls); // todo, figure out if functiondecl has actual children
}
-void chillAST_FunctionDecl::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- for (int i=0; i<children.size(); i++) children[i]->gatherDeclRefExprs( refs );
- body->gatherDeclRefExprs( refs ); // todo, figure out if functiondecl has actual children
+void chillAST_FunctionDecl::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ for (int i = 0; i < children.size(); i++) children[i]->gatherDeclRefExprs(refs);
+ body->gatherDeclRefExprs(refs); // todo, figure out if functiondecl has actual children
}
+void chillAST_FunctionDecl::cleanUpVarDecls() {
+ //fprintf(stderr, "\ncleanUpVarDecls() for function %s\n", functionName);
+ vector<chillAST_VarDecl *> used;
+ vector<chillAST_VarDecl *> defined;
+ vector<chillAST_VarDecl *> deletethese;
-void chillAST_FunctionDecl::cleanUpVarDecls() {
- //fprintf(stderr, "\ncleanUpVarDecls() for function %s\n", functionName);
- vector<chillAST_VarDecl*> used;
- vector<chillAST_VarDecl*> defined;
- vector<chillAST_VarDecl*> deletethese;
-
- gatherVarUsage( used );
- gatherVarDecls( defined );
+ gatherVarUsage(used);
+ gatherVarDecls(defined);
- //fprintf(stderr, "\nvars used: \n");
- //for ( int i=0; i< used.size(); i++) {
- //used[i]->print(0, stderr); fprintf(stderr, "\n");
- //}
- //fprintf(stderr, "\n");
- //fprintf(stderr, "\nvars defined: \n");
- //for ( int i=0; i< defined.size(); i++) {
- // defined[i]->print(0, stderr); fprintf(stderr, "\n");
- //}
- //fprintf(stderr, "\n");
+ //fprintf(stderr, "\nvars used: \n");
+ //for ( int i=0; i< used.size(); i++) {
+ //used[i]->print(0, stderr); fprintf(stderr, "\n");
+ //}
+ //fprintf(stderr, "\n");
+ //fprintf(stderr, "\nvars defined: \n");
+ //for ( int i=0; i< defined.size(); i++) {
+ // defined[i]->print(0, stderr); fprintf(stderr, "\n");
+ //}
+ //fprintf(stderr, "\n");
- for ( int j=0; j < defined.size(); j++) {
- //fprintf(stderr, "j %d defined %s\n", j, defined[j]->varname);
+ for (int j = 0; j < defined.size(); j++) {
+ //fprintf(stderr, "j %d defined %s\n", j, defined[j]->varname);
bool definedandused = false;
- for ( int i=0; i < used.size(); i++) {
- if (used[i] == defined[j]) {
- //fprintf(stderr, "i %d used %s\n", i, used[i]->varname);
+ for (int i = 0; i < used.size(); i++) {
+ if (used[i] == defined[j]) {
+ //fprintf(stderr, "i %d used %s\n", i, used[i]->varname);
//fprintf(stderr, "\n");
definedandused = true;
break;
}
}
- if (!definedandused) {
- if ( defined[j]->isParmVarDecl() ) {
- //fprintf(stderr, "we'd remove %s except that it's a parameter. Maybe someday\n", defined[j]->varname);
- }
- else {
- //fprintf(stderr, "we can probably remove the definition of %s\n", defined[j]->varname);
- deletethese.push_back( defined[j] );
+ if (!definedandused) {
+ if (defined[j]->isParmVarDecl()) {
+ //fprintf(stderr, "we'd remove %s except that it's a parameter. Maybe someday\n", defined[j]->varname);
+ } else {
+ //fprintf(stderr, "we can probably remove the definition of %s\n", defined[j]->varname);
+ deletethese.push_back(defined[j]);
}
}
}
- //fprintf(stderr, "deleting %d vardecls\n", deletethese.size());
- for (int i=0; i<deletethese.size(); i++) {
- //fprintf(stderr, "deleting varDecl %s\n", deletethese[i]->varname);
- chillAST_node *par = deletethese[i]->parent;
- par->removeChild( par->findChild( deletethese[i] ));
+ //fprintf(stderr, "deleting %d vardecls\n", deletethese.size());
+ for (int i = 0; i < deletethese.size(); i++) {
+ //fprintf(stderr, "deleting varDecl %s\n", deletethese[i]->varname);
+ chillAST_node *par = deletethese[i]->parent;
+ par->removeChild(par->findChild(deletethese[i]));
}
- //fprintf(stderr, "\n\nnow check for vars used but not defined\n");
+ //fprintf(stderr, "\n\nnow check for vars used but not defined\n");
// now check for vars used but not defined?
- for ( int j=0; j < used.size(); j++) {
- //fprintf(stderr, "%s is used\n", used[j]->varname);
+ for (int j = 0; j < used.size(); j++) {
+ //fprintf(stderr, "%s is used\n", used[j]->varname);
bool definedandused = false;
- for ( int i=0; i < defined.size(); i++) {
- if (used[j] == defined[i]) {
- //fprintf(stderr, "%s is defined\n", defined[i]->varname);
+ for (int i = 0; i < defined.size(); i++) {
+ if (used[j] == defined[i]) {
+ //fprintf(stderr, "%s is defined\n", defined[i]->varname);
definedandused = true;
break;
}
}
- if (!definedandused) {
- //fprintf(stderr, "%s is used but not defined?\n", used[j]->varname);
+ if (!definedandused) {
+ //fprintf(stderr, "%s is used but not defined?\n", used[j]->varname);
// add it to the beginning of the function
- insertChild(0, used[j]);
+ insertChild(0, used[j]);
}
}
-
+
}
//void chillAST_FunctionDecl::replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl ) {
-// for (int i=0; i<children.size(); i++) children[i]->replaceVarDecls( olddecl, newdecl );
-//}
+// for (int i=0; i<children.size(); i++) children[i]->replaceVarDecls( olddecl, newdecl );
+//}
-bool chillAST_FunctionDecl::findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync ) {
- if (body) body->findLoopIndexesToReplace( symtab, false );
+bool chillAST_FunctionDecl::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync) {
+ if (body) body->findLoopIndexesToReplace(symtab, false);
return false;
}
-
- chillAST_node *chillAST_FunctionDecl::constantFold() {
- //fprintf(stderr, "chillAST_FunctionDecl::constantFold()\n");
- // parameters can't have constants?
- int numparameters = parameters.size();
- for (int i=0; i<numparameters; i++) {
- parameters[i]->constantFold();
- }
- if (body) body = (chillAST_CompoundStmt *)body->constantFold();
- return this;
- }
+chillAST_node *chillAST_FunctionDecl::constantFold() {
+ //fprintf(stderr, "chillAST_FunctionDecl::constantFold()\n");
+ // parameters can't have constants?
+ int numparameters = parameters.size();
+ for (int i = 0; i < numparameters; i++) {
+ parameters[i]->constantFold();
+ }
+ if (body) body = (chillAST_CompoundStmt *) body->constantFold();
+ return this;
+}
-chillAST_MacroDefinition::chillAST_MacroDefinition() {
+chillAST_MacroDefinition::chillAST_MacroDefinition() {
macroName = strdup("UNDEFINEDMACRO");
rhsString = NULL;
- asttype = CHILLAST_NODETYPE_MACRODEFINITION;
- parent = NULL;
+ asttype = CHILLAST_NODETYPE_MACRODEFINITION;
+ parent = NULL;
metacomment = NULL;
symbol_table = NULL;
//rhsideString = NULL;
- isFromSourceFile = true; // default
- filename = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
};
-chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, chillAST_node *par) {
+chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, chillAST_node *par) {
macroName = strdup(mname);
rhsString = NULL;
- asttype = CHILLAST_NODETYPE_MACRODEFINITION;
+ asttype = CHILLAST_NODETYPE_MACRODEFINITION;
parent = par;
metacomment = NULL;
symbol_table = NULL;
//rhsideString = NULL;
- if (par) par->getSourceFile()->addMacro( this );
+ if (par) par->getSourceFile()->addMacro(this);
- //fprintf(stderr, "chillAST_MacroDefinition::chillAST_MacroDefinition( %s, ", mname);
+ //fprintf(stderr, "chillAST_MacroDefinition::chillAST_MacroDefinition( %s, ", mname);
//if (par) fprintf(stderr, " parent NOT NULL);\n");
//else fprintf(stderr, " parent NULL);\n");
- isFromSourceFile = true; // default
- filename = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
};
-chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, const char *rhs, chillAST_node *par) {
+chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, const char *rhs, chillAST_node *par) {
macroName = strdup(mname);
rhsString = strdup(rhs);
- asttype = CHILLAST_NODETYPE_MACRODEFINITION;
+ asttype = CHILLAST_NODETYPE_MACRODEFINITION;
parent = par;
metacomment = NULL;
symbol_table = NULL;
- if (par) par->getSourceFile()->addMacro( this );
+ if (par) par->getSourceFile()->addMacro(this);
- //fprintf(stderr, "chillAST_MacroDefinition::chillAST_MacroDefinition( %s, ", mname);
+ //fprintf(stderr, "chillAST_MacroDefinition::chillAST_MacroDefinition( %s, ", mname);
//if (par) fprintf(stderr, " parent NOT NULL);\n");
//else fprintf(stderr, " parent NULL);\n");
- isFromSourceFile = true; // default
- filename = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
};
-chillAST_node* chillAST_MacroDefinition::clone() {
+chillAST_node *chillAST_MacroDefinition::clone() {
// TODO ?? cloning a macro makes no sense
return this;
-#ifdef CONFUSED
+#ifdef CONFUSED
- //fprintf(stderr, "chillAST_MacroDefinition::clone() for %s\n", macroName);
- chillAST_MacroDefinition *clo = new chillAST_MacroDefinition( macroName, parent);
+ //fprintf(stderr, "chillAST_MacroDefinition::clone() for %s\n", macroName);
+ chillAST_MacroDefinition *clo = new chillAST_MacroDefinition( macroName, parent);
for (int i=0; i<parameters.size(); i++) clo->addParameter( parameters[i] );
clo->setBody( body->clone() );
- return clo;
-#endif
+ return clo;
+#endif
}
-void chillAST_MacroDefinition::setBody( chillAST_node * bod ) {
- fprintf(stderr, "%s chillAST_MacroDefinition::setBody( 0x%x )\n", macroName, bod);
+void chillAST_MacroDefinition::setBody(chillAST_node *bod) {
+ fprintf(stderr, "%s chillAST_MacroDefinition::setBody( 0x%x )\n", macroName, bod);
body = bod;
- fprintf(stderr, "body is:\n"); body->print(0,stderr); fprintf(stderr, "\n\n");
- rhsString = body->stringRep();
- bod->setParent( this ); // well, ...
+ fprintf(stderr, "body is:\n");
+ body->print(0, stderr);
+ fprintf(stderr, "\n\n");
+ rhsString = body->stringRep();
+ bod->setParent(this); // well, ...
}
-void chillAST_MacroDefinition::addParameter( chillAST_VarDecl *p) {
- //fprintf(stderr, "%s chillAST_MacroDefinition::addParameter( 0x%x ) total of %d children\n", functionName, p, 1+children.size());
+void chillAST_MacroDefinition::addParameter(chillAST_VarDecl *p) {
+ //fprintf(stderr, "%s chillAST_MacroDefinition::addParameter( 0x%x ) total of %d children\n", functionName, p, 1+children.size());
parameters.push_back(p);
- fprintf(stderr, "macro setting %s isAParameter\n", p->varname);
- p->isAParameter = true;
- p->setParent( this );
+ fprintf(stderr, "macro setting %s isAParameter\n", p->varname);
+ p->isAParameter = true;
+ p->setParent(this);
- addVariableToSymbolTable( p );
+ addVariableToSymbolTable(p);
}
-chillAST_VarDecl *chillAST_MacroDefinition::hasParameterNamed( const char *name ) {
+chillAST_VarDecl *chillAST_MacroDefinition::hasParameterNamed(const char *name) {
int numparams = parameters.size();
- for (int i=0; i<numparams; i++) {
- if (!strcmp(name, parameters[i]->varname)) return parameters[i]; // need to check type?
+ for (int i = 0; i < numparams; i++) {
+ if (!strcmp(name, parameters[i]->varname)) return parameters[i]; // need to check type?
}
- return NULL;
+ return NULL;
}
-void chillAST_MacroDefinition::insertChild(int i, chillAST_node* node) {
- body->insertChild( i, node );
+void chillAST_MacroDefinition::insertChild(int i, chillAST_node *node) {
+ body->insertChild(i, node);
}
-void chillAST_MacroDefinition::addChild(chillAST_node* node) {
- body->addChild( node );
- node->parent = this; // this, or body??
+void chillAST_MacroDefinition::addChild(chillAST_node *node) {
+ body->addChild(node);
+ node->parent = this; // this, or body??
}
-void chillAST_MacroDefinition::dump( int indent, FILE *fp ) {
- fprintf(fp, "\n");
- chillindent(indent, fp);
+void chillAST_MacroDefinition::dump(int indent, FILE *fp) {
+ fprintf(fp, "\n");
+ chillindent(indent, fp);
fprintf(fp, "(MacroDefinition %s(", macroName);
- for (int i=0; i<numParameters(); i++) {
+ for (int i = 0; i < numParameters(); i++) {
fprintf(fp, "\n");
- chillindent(indent+1, fp);
- fprintf(fp, "(%s)", parameters[i]->varname);
+ chillindent(indent + 1, fp);
+ fprintf(fp, "(%s)", parameters[i]->varname);
}
- fprintf(fp, ")\n");
- body->dump( indent+1, fp);
- if (rhsString) fprintf(fp, " (aka %s)");
- fprintf(fp, "\n");
+ fprintf(fp, ")\n");
+ body->dump(indent + 1, fp);
+ if (rhsString) fprintf(fp, " (aka %s)");
+ fprintf(fp, "\n");
fflush(fp);
}
-void chillAST_MacroDefinition::print( int indent, FILE *fp ) { // UHOH TODO
+void chillAST_MacroDefinition::print(int indent, FILE *fp) { // UHOH TODO
//fprintf(fp, "\n"); // ignore indentation
- //fprintf(stderr, "macro has %d parameters\n", numParameters());
+ //fprintf(stderr, "macro has %d parameters\n", numParameters());
- printPreprocBEFORE(indent, fp);
+ printPreprocBEFORE(indent, fp);
fprintf(fp, "#define %s", macroName);
- if (0 != numParameters()) {
+ if (0 != numParameters()) {
fprintf(fp, "(");
- for (int i=0; i<numParameters(); i++) {
+ for (int i = 0; i < numParameters(); i++) {
if (i) fprintf(fp, ",");
- fprintf(fp, "%s", parameters[i]->varname);
+ fprintf(fp, "%s", parameters[i]->varname);
}
fprintf(fp, ") ");
}
- if (body) body->print(0, fp); // TODO should force newlines out of multiline macros
- fprintf(fp, "\n");
-}
-
-
+ if (body) body->print(0, fp); // TODO should force newlines out of multiline macros
+ fprintf(fp, "\n");
+}
chillAST_ForStmt::chillAST_ForStmt() {
@@ -1457,133 +1430,130 @@ chillAST_ForStmt::chillAST_ForStmt() {
parent = NULL;
metacomment = NULL;
symbol_table = NULL;
- isFromSourceFile = true; // default
- filename = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
}
-chillAST_ForStmt::chillAST_ForStmt( chillAST_node *ini, chillAST_node *con, chillAST_node *inc, chillAST_node *bod, chillAST_node *par) {
- parent = par;
+chillAST_ForStmt::chillAST_ForStmt(chillAST_node *ini, chillAST_node *con, chillAST_node *inc, chillAST_node *bod,
+ chillAST_node *par) {
+ parent = par;
metacomment = NULL;
init = ini;
cond = con;
incr = inc;
body = bod;
- init->setParent( this );
- cond->setParent( this );
- incr->setParent( this );
-
- //fprintf(stderr, "chillAST_ForStmt::chillAST_ForStmt() bod %p\n", bod);
+ init->setParent(this);
+ cond->setParent(this);
+ incr->setParent(this);
+
+ //fprintf(stderr, "chillAST_ForStmt::chillAST_ForStmt() bod %p\n", bod);
+
+ if (body) body->setParent(this); // not sure this should be legal
- if (body) body->setParent( this ); // not sure this should be legal
-
- asttype = CHILLAST_NODETYPE_LOOP; // breaking with tradition, this was CHILL_AST_FORSTMT
+ asttype = CHILLAST_NODETYPE_LOOP; // breaking with tradition, this was CHILL_AST_FORSTMT
- if (!cond->isBinaryOperator()) {
+ if (!cond->isBinaryOperator()) {
fprintf(stderr, "ForStmt conditional is of type %s. Expecting a BinaryOperator\n", cond->getTypeString());
- exit(-1);
+ exit(-1);
}
- chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *)cond;
- char *condstring = bo->op;
- if (!strcmp(condstring, "<")) conditionoperator = IR_COND_LT;
+ chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *) cond;
+ char *condstring = bo->op;
+ if (!strcmp(condstring, "<")) conditionoperator = IR_COND_LT;
else if (!strcmp(condstring, "<=")) conditionoperator = IR_COND_LE;
- else if (!strcmp(condstring, ">")) conditionoperator = IR_COND_GT;
+ else if (!strcmp(condstring, ">")) conditionoperator = IR_COND_GT;
else if (!strcmp(condstring, ">=")) conditionoperator = IR_COND_GE;
- else {
+ else {
fprintf(stderr, "ForStmt, illegal/unhandled end condition \"%s\"\n", condstring);
fprintf(stderr, "currently can only handle <, >, <=, >=\n");
exit(1);
}
- isFromSourceFile = true; // default
- filename = NULL;
+ isFromSourceFile = true; // default
+ filename = NULL;
}
-bool chillAST_ForStmt::lowerBound( int &l ) { // l is an output (passed as reference)
-
- // above, cond must be a binaryoperator ... ???
- if (conditionoperator == IR_COND_LT ||
- conditionoperator == IR_COND_LE ) {
-
- // lower bound is rhs of init
- if (!init->isBinaryOperator()) {
+bool chillAST_ForStmt::lowerBound(int &l) { // l is an output (passed as reference)
+
+ // above, cond must be a binaryoperator ... ???
+ if (conditionoperator == IR_COND_LT ||
+ conditionoperator == IR_COND_LE) {
+
+ // lower bound is rhs of init
+ if (!init->isBinaryOperator()) {
fprintf(stderr, "chillAST_ForStmt::lowerBound() init is not a chillAST_BinaryOperator\n");
exit(-1);
}
-
- chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *)init;
- if (!init->isAssignmentOp()) {
+
+ chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *) init;
+ if (!init->isAssignmentOp()) {
fprintf(stderr, "chillAST_ForStmt::lowerBound() init is not an assignment chillAST_BinaryOperator\n");
exit(-1);
}
-
- //fprintf(stderr, "rhs "); bo->rhs->print(0,stderr); fprintf(stderr, " ");
+
+ //fprintf(stderr, "rhs "); bo->rhs->print(0,stderr); fprintf(stderr, " ");
l = bo->rhs->evalAsInt(); // float could be legal I suppose
- //fprintf(stderr, " %d\n", l);
- return true;
- }
- else if (conditionoperator == IR_COND_GT ||
- conditionoperator == IR_COND_GE ) { // decrementing
+ //fprintf(stderr, " %d\n", l);
+ return true;
+ } else if (conditionoperator == IR_COND_GT ||
+ conditionoperator == IR_COND_GE) { // decrementing
// lower bound is rhs of cond (not init)
- chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *)cond;
+ chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *) cond;
l = bo->rhs->evalAsInt(); // float could be legal I suppose
- return true;
+ return true;
}
-
- // some case we don't handle ??
- fprintf(stderr, "chillAST_ForStmt::lowerBound() can't find lower bound of ");
- print(0,stderr);
- fprintf(stderr, "\n\n");
+
+ // some case we don't handle ??
+ fprintf(stderr, "chillAST_ForStmt::lowerBound() can't find lower bound of ");
+ print(0, stderr);
+ fprintf(stderr, "\n\n");
return false; // or exit ???
}
-bool chillAST_ForStmt::upperBound( int &u ) { // u is an output (passed as reference)
-
- // above, cond must be a binaryoperator ... ???
- if (conditionoperator == IR_COND_GT ||
- conditionoperator == IR_COND_GE ) { // decrementing
+bool chillAST_ForStmt::upperBound(int &u) { // u is an output (passed as reference)
+
+ // above, cond must be a binaryoperator ... ???
+ if (conditionoperator == IR_COND_GT ||
+ conditionoperator == IR_COND_GE) { // decrementing
- // upper bound is rhs of init
- if (!init->isBinaryOperator()) {
+ // upper bound is rhs of init
+ if (!init->isBinaryOperator()) {
fprintf(stderr, "chillAST_ForStmt::upperBound() init is not a chillAST_BinaryOperator\n");
exit(-1);
}
- chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *)init;
- if (!init->isAssignmentOp()) {
+ chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *) init;
+ if (!init->isAssignmentOp()) {
fprintf(stderr, "chillAST_ForStmt::upperBound() init is not an assignment chillAST_BinaryOperator\n");
exit(-1);
}
u = bo->rhs->evalAsInt(); // float could be legal I suppose
- return true;
- }
- else if (conditionoperator == IR_COND_LT ||
- conditionoperator == IR_COND_LE ) {
+ return true;
+ } else if (conditionoperator == IR_COND_LT ||
+ conditionoperator == IR_COND_LE) {
//fprintf(stderr, "upper bound is rhs of cond ");
// upper bound is rhs of cond (not init)
- chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *)cond;
+ chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *) cond;
//bo->rhs->print(0,stderr);
u = bo->rhs->evalAsInt(); // float could be legal I suppose
- if (conditionoperator == IR_COND_LT) u -= 1;
+ if (conditionoperator == IR_COND_LT) u -= 1;
//fprintf(stderr, " %d\n", u);
- return true;
+ return true;
}
- // some case we don't handle ??
- fprintf(stderr, "chillAST_ForStmt::upperBound() can't find upper bound of ");
- print(0,stderr);
- fprintf(stderr, "\n\n");
+ // some case we don't handle ??
+ fprintf(stderr, "chillAST_ForStmt::upperBound() can't find upper bound of ");
+ print(0, stderr);
+ fprintf(stderr, "\n\n");
return false; // or exit ???
}
-
-
-void chillAST_ForStmt::printControl( int in, FILE *fp ) {
+void chillAST_ForStmt::printControl(int in, FILE *fp) {
chillindent(in, fp);
fprintf(fp, "for (");
init->print(0, fp);
@@ -1592,175 +1562,173 @@ void chillAST_ForStmt::printControl( int in, FILE *fp ) {
fprintf(fp, "; ");
incr->print(0, fp);
fprintf(fp, ")");
- fflush(fp);
+ fflush(fp);
}
-void chillAST_ForStmt::print( int indent, FILE *fp ) {
- printPreprocBEFORE(indent, fp);
- //fprintf(fp, "chillAST_ForStmt::print()\n");
- if (metacomment) {
+void chillAST_ForStmt::print(int indent, FILE *fp) {
+ printPreprocBEFORE(indent, fp);
+ //fprintf(fp, "chillAST_ForStmt::print()\n");
+ if (metacomment) {
chillindent(indent, fp);
- //for(int i=0; i<indent; i++) fprintf(fp, "..");
+ //for(int i=0; i<indent; i++) fprintf(fp, "..");
fprintf(fp, "// %s\n", metacomment);
}
- printControl(indent, fp); // does not do a newline or bracket
- fprintf(fp, " {\n");
+ printControl(indent, fp); // does not do a newline or bracket
+ fprintf(fp, " {\n");
- // I have no idea what made me do this next bit.
- // A forstmt with compounds inside compounds ???
- // this should probably all go away
+ // I have no idea what made me do this next bit.
+ // A forstmt with compounds inside compounds ???
+ // this should probably all go away
chillAST_node *b = body;
- //fprintf(fp, "b children %d\n", b->getNumChildren());
- //fprintf(fp, "body child 0 of type %s\n", b->children[0]->getTypeString());
- //fprintf(stderr, "forstmt body type %s\n", Chill_AST_Node_Names[b->asttype] );
+ //fprintf(fp, "b children %d\n", b->getNumChildren());
+ //fprintf(fp, "body child 0 of type %s\n", b->children[0]->getTypeString());
+ //fprintf(stderr, "forstmt body type %s\n", Chill_AST_Node_Names[b->asttype] );
// deal with a tree of compound statements, in an ugly way. leave the ugliness
- while (1 == b->getNumChildren() && b->children[0]->isCompoundStmt()) {
- b = b->children[0];
+ while (1 == b->getNumChildren() && b->children[0]->isCompoundStmt()) {
+ b = b->children[0];
}
// this was to sometimes not enclose in a bracket. stupid. always enclose in a bracket.
//if (1 == b->getNumChildren() && b->children[0]->isForStmt()) fprintf(fp, ") {\n" );
//else if (1 == b->getNumChildren() ) fprintf(fp, ") { ?? \n" ); // to allow for() for( ) to not have open bracket?
- //else {
- //fprintf(fp, ")\n");
- //chillindent(in, fp);
- //fprintf(fp, "{\n" );
+ //else {
+ //fprintf(fp, ")\n");
+ //chillindent(in, fp);
+ //fprintf(fp, "{\n" );
- //fprintf(fp, ")");
+ //fprintf(fp, ")");
//}
- b->print(indent+1, fp );
+ b->print(indent + 1, fp);
- // I think this can't happen any more. body is always a compound statement
- if (b->asttype == CHILLAST_NODETYPE_BINARYOPERATOR) { // a single assignment statement
- fprintf(fp, ";\n");
+ // I think this can't happen any more. body is always a compound statement
+ if (b->asttype == CHILLAST_NODETYPE_BINARYOPERATOR) { // a single assignment statement
+ fprintf(fp, ";\n");
}
- // always print brackets
+ // always print brackets
- //if ((1 == b->getNumChildren() && b->children[0]->isForStmt()) ||
+ //if ((1 == b->getNumChildren() && b->children[0]->isForStmt()) ||
// (1 != b->getNumChildren() )) {
chillindent(indent, fp);
- fprintf(fp, "}\n" );
+ fprintf(fp, "}\n");
//}
- printPreprocAFTER(indent, fp);
+ printPreprocAFTER(indent, fp);
fflush(fp); //
}
-void chillAST_ForStmt::dump( int indent, FILE *fp ) {
+void chillAST_ForStmt::dump(int indent, FILE *fp) {
chillindent(indent, fp);
fprintf(fp, "(ForStmt \n");
- init->dump(indent+1, fp);
- cond->dump(indent+1, fp);
- incr->dump(indent+1, fp);
- body->dump(indent+1, fp);
+ init->dump(indent + 1, fp);
+ cond->dump(indent + 1, fp);
+ incr->dump(indent + 1, fp);
+ body->dump(indent + 1, fp);
chillindent(indent, fp);
fprintf(fp, ")\n");
}
-
-chillAST_node *chillAST_ForStmt::constantFold() {
- init = init->constantFold();
- cond = cond->constantFold();
- incr = incr->constantFold();
- body = body->constantFold();
- return this;
- }
+
+chillAST_node *chillAST_ForStmt::constantFold() {
+ init = init->constantFold();
+ cond = cond->constantFold();
+ incr = incr->constantFold();
+ body = body->constantFold();
+ return this;
+}
- chillAST_node *chillAST_ForStmt::clone() {
- chillAST_ForStmt *fs = new chillAST_ForStmt( init->clone(), cond->clone(), incr->clone(), body->clone(), parent);
+chillAST_node *chillAST_ForStmt::clone() {
+ chillAST_ForStmt *fs = new chillAST_ForStmt(init->clone(), cond->clone(), incr->clone(), body->clone(), parent);
fs->isFromSourceFile = isFromSourceFile;
if (filename) fs->filename = strdup(filename);
return fs;
- }
+}
-void chillAST_ForStmt::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_ForStmt::gatherVarDecls()\n");
+void chillAST_ForStmt::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_ForStmt::gatherVarDecls()\n");
//fprintf(stderr, "chillAST_ForStmt::gatherVarDecls() before %d\n", decls.size());
- // TODO clear a loop_var_decls variable and then walk it ?
- init->gatherVarDecls( decls );
- cond->gatherVarDecls( decls );
- incr->gatherVarDecls( decls );
- body->gatherVarDecls( decls );
- //fprintf(stderr, "after %d\n", decls.size());
+ // TODO clear a loop_var_decls variable and then walk it ?
+ init->gatherVarDecls(decls);
+ cond->gatherVarDecls(decls);
+ incr->gatherVarDecls(decls);
+ body->gatherVarDecls(decls);
+ //fprintf(stderr, "after %d\n", decls.size());
}
-void chillAST_ForStmt::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
+void chillAST_ForStmt::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
//fprintf(stderr, "chillAST_ForStmt::gatherScalarVarDecls() before %d\n", decls.size());
- init->gatherScalarVarDecls( decls );
- cond->gatherScalarVarDecls( decls );
- incr->gatherScalarVarDecls( decls );
- body->gatherScalarVarDecls( decls );
+ init->gatherScalarVarDecls(decls);
+ cond->gatherScalarVarDecls(decls);
+ incr->gatherScalarVarDecls(decls);
+ body->gatherScalarVarDecls(decls);
}
-void chillAST_ForStmt::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
+void chillAST_ForStmt::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
//fprintf(stderr, "chillAST_ForStmt::gatherArrayVarDecls() before %d\n", decls.size());
- init->gatherArrayVarDecls( decls );
- cond->gatherArrayVarDecls( decls );
- incr->gatherArrayVarDecls( decls );
- body->gatherArrayVarDecls( decls );
+ init->gatherArrayVarDecls(decls);
+ cond->gatherArrayVarDecls(decls);
+ incr->gatherArrayVarDecls(decls);
+ body->gatherArrayVarDecls(decls);
}
-void chillAST_ForStmt::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
- init->gatherArrayRefs( refs, 0 ); // 0 ??
- cond->gatherArrayRefs( refs, 0 ); // 0 ??
- incr->gatherArrayRefs( refs, 0 ); // 0 ??
- body->gatherArrayRefs( refs, 0 ); // 0 ??
+void chillAST_ForStmt::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {
+ init->gatherArrayRefs(refs, 0); // 0 ??
+ cond->gatherArrayRefs(refs, 0); // 0 ??
+ incr->gatherArrayRefs(refs, 0); // 0 ??
+ body->gatherArrayRefs(refs, 0); // 0 ??
}
-void chillAST_ForStmt::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- init->gatherScalarRefs( refs, 0 ); // 0 ??
- cond->gatherScalarRefs( refs, 0 ); // 0 ??
- incr->gatherScalarRefs( refs, 0 ); // 0 ??
- body->gatherScalarRefs( refs, 0 ); // 0 ??
-}
-
-void chillAST_ForStmt::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- init->gatherDeclRefExprs( refs );
- cond->gatherDeclRefExprs( refs );
- incr->gatherDeclRefExprs( refs );
- body->gatherDeclRefExprs( refs );
+void chillAST_ForStmt::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ init->gatherScalarRefs(refs, 0); // 0 ??
+ cond->gatherScalarRefs(refs, 0); // 0 ??
+ incr->gatherScalarRefs(refs, 0); // 0 ??
+ body->gatherScalarRefs(refs, 0); // 0 ??
}
+void chillAST_ForStmt::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ init->gatherDeclRefExprs(refs);
+ cond->gatherDeclRefExprs(refs);
+ incr->gatherDeclRefExprs(refs);
+ body->gatherDeclRefExprs(refs);
+}
-void chillAST_ForStmt::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- init->gatherVarUsage( decls );
- cond->gatherVarUsage( decls );
- incr->gatherVarUsage( decls );
- body->gatherVarUsage( decls );
+void chillAST_ForStmt::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ init->gatherVarUsage(decls);
+ cond->gatherVarUsage(decls);
+ incr->gatherVarUsage(decls);
+ body->gatherVarUsage(decls);
}
-void chillAST_ForStmt::gatherStatements(std::vector<chillAST_node*> &statements ){
-
+void chillAST_ForStmt::gatherStatements(std::vector<chillAST_node *> &statements) {
+
// for completeness, should do all 4. Maybe someday
- //init->gatherStatements( statements );
- //cond->gatherStatements( statements );
- //incr->gatherStatements( statements );
- body->gatherStatements( statements );
+ //init->gatherStatements( statements );
+ //cond->gatherStatements( statements );
+ //incr->gatherStatements( statements );
+ body->gatherStatements(statements);
}
-
void chillAST_ForStmt::addSyncs() {
- //fprintf(stderr, "\nchillAST_ForStmt::addSyncs() ");
+ //fprintf(stderr, "\nchillAST_ForStmt::addSyncs() ");
//fprintf(stderr, "for (");
//init->print(0, stderr);
//fprintf(stderr, "; ");
//cond->print(0, stderr);
//fprintf(stderr, "; ");
//incr->print(0, stderr);
- //fprintf(stderr, ")\n");
-
- if (!parent) {
+ //fprintf(stderr, ")\n");
+
+ if (!parent) {
fprintf(stderr, "uhoh, chillAST_ForStmt::addSyncs() ForStmt has no parent!\n");
fprintf(stderr, "for (");
init->print(0, stderr);
@@ -1768,86 +1736,83 @@ void chillAST_ForStmt::addSyncs() {
cond->print(0, stderr);
fprintf(stderr, "; ");
incr->print(0, stderr);
- fprintf(stderr, ")\n");
+ fprintf(stderr, ")\n");
- return; // exit?
+ return; // exit?
}
- if (parent->isCompoundStmt()) {
+ if (parent->isCompoundStmt()) {
//fprintf(stderr, "ForStmt parent is CompoundStmt 0x%x\n", parent);
- vector<chillAST_node*> chillin = parent->getChildren();
+ vector<chillAST_node *> chillin = parent->getChildren();
int numc = chillin.size();
//fprintf(stderr, "ForStmt parent is CompoundStmt 0x%x with %d children\n", parent, numc);
- for (int i=0; i<numc; i++) {
- if (this == parent->getChild(i)) {
- //fprintf(stderr, "forstmt 0x%x is child %d of %d\n", this, i, numc);
+ for (int i = 0; i < numc; i++) {
+ if (this == parent->getChild(i)) {
+ //fprintf(stderr, "forstmt 0x%x is child %d of %d\n", this, i, numc);
chillAST_CudaSyncthreads *ST = new chillAST_CudaSyncthreads();
- parent->insertChild(i+1, ST); // corrupts something ...
- //fprintf(stderr, "Create a call to __syncthreads() 2\n");
- //parent->addChild(ST); // wrong, but safer still kills
+ parent->insertChild(i + 1, ST); // corrupts something ...
+ //fprintf(stderr, "Create a call to __syncthreads() 2\n");
+ //parent->addChild(ST); // wrong, but safer still kills
}
}
chillin = parent->getChildren();
int nowc = chillin.size();
- //fprintf(stderr, "old, new number of children = %d %d\n", numc, nowc);
-
- }
- else {
- fprintf(stderr, "chillAST_ForStmt::addSyncs() unhandled parent type %s\n", parent->getTypeString());
- exit(-1);
+ //fprintf(stderr, "old, new number of children = %d %d\n", numc, nowc);
+
+ } else {
+ fprintf(stderr, "chillAST_ForStmt::addSyncs() unhandled parent type %s\n", parent->getTypeString());
+ exit(-1);
}
- //fprintf(stderr, "leaving addSyncs()\n");
+ //fprintf(stderr, "leaving addSyncs()\n");
}
-
-
-void chillAST_ForStmt::removeSyncComment() {
- //fprintf(stderr, "chillAST_ForStmt::removeSyncComment()\n");
- if (metacomment && strstr(metacomment, "~cuda~") && strstr(metacomment, "preferredIdx: ")) {
- char *ptr = strlen( "preferredIdx: " ) + strstr(metacomment, "preferredIdx: ");
- *ptr = '\0';
+void chillAST_ForStmt::removeSyncComment() {
+ //fprintf(stderr, "chillAST_ForStmt::removeSyncComment()\n");
+ if (metacomment && strstr(metacomment, "~cuda~") && strstr(metacomment, "preferredIdx: ")) {
+ char *ptr = strlen("preferredIdx: ") + strstr(metacomment, "preferredIdx: ");
+ *ptr = '\0';
}
}
-bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync ) {
- fprintf(stderr, "\nchillAST_ForStmt::findLoopIndexesToReplace( force = %d )\n", forcesync);
- //if (metacomment) fprintf(stderr, "metacomment '%s'\n", metacomment);
+bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync) {
+ fprintf(stderr, "\nchillAST_ForStmt::findLoopIndexesToReplace( force = %d )\n", forcesync);
+ //if (metacomment) fprintf(stderr, "metacomment '%s'\n", metacomment);
bool force = forcesync;
bool didasync = false;
- if (forcesync) {
- //fprintf(stderr, "calling addSyncs() because PREVIOUS ForStmt in a block had preferredIdx\n");
+ if (forcesync) {
+ //fprintf(stderr, "calling addSyncs() because PREVIOUS ForStmt in a block had preferredIdx\n");
addSyncs();
- didasync = true;
- }
-
- //fprintf(stderr, "chillAST_ForStmt::findLoopIndexesToReplace()\n");
- if (metacomment && strstr(metacomment, "~cuda~") && strstr(metacomment, "preferredIdx: ")) {
- //fprintf(stderr, "metacomment '%s'\n", metacomment);
-
- char *copy = strdup(metacomment);
- char *ptr = strstr(copy, "preferredIdx: ");
- char *vname = ptr + strlen( "preferredIdx: " );
+ didasync = true;
+ }
+
+ //fprintf(stderr, "chillAST_ForStmt::findLoopIndexesToReplace()\n");
+ if (metacomment && strstr(metacomment, "~cuda~") && strstr(metacomment, "preferredIdx: ")) {
+ //fprintf(stderr, "metacomment '%s'\n", metacomment);
+
+ char *copy = strdup(metacomment);
+ char *ptr = strstr(copy, "preferredIdx: ");
+ char *vname = ptr + strlen("preferredIdx: ");
char *space = strstr(vname, " "); // TODO index()
- if (space) {
- //fprintf(stderr, "vname = '%s'\n", vname);
- force = true;
+ if (space) {
+ //fprintf(stderr, "vname = '%s'\n", vname);
+ force = true;
}
- if ((!didasync) && force ) {
- //fprintf(stderr, "calling addSyncs() because ForStmt metacomment had preferredIdx '%s'\n", vname);
+ if ((!didasync) && force) {
+ //fprintf(stderr, "calling addSyncs() because ForStmt metacomment had preferredIdx '%s'\n", vname);
addSyncs();
- removeSyncComment();
- didasync = true;
+ removeSyncComment();
+ didasync = true;
}
- if (space) *space = '\0'; // if this is multiple words, grab the first one
- //fprintf(stderr, "vname = '%s'\n", vname);
-
+ if (space) *space = '\0'; // if this is multiple words, grab the first one
+ //fprintf(stderr, "vname = '%s'\n", vname);
+
//fprintf(stderr, "\nfor (");
//init->print(0, stderr);
//fprintf(stderr, "; ");
@@ -1856,74 +1821,75 @@ bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bo
//incr->print(0, stderr);
//fprintf(stderr, ") %s\n", metacomment );
//fprintf(stderr, "prefer '%s'\n", vname );
-
- vector<chillAST_VarDecl*> decls;
- init->gatherVarLHSUsage( decls );
- //cond->gatherVarUsage( decls );
- //incr->gatherVarUsage( decls );
- //fprintf(stderr, "forstmt has %d vardecls in init, cond, inc\n", decls.size());
-
- if ( 1 != decls.size()) {
+
+ vector<chillAST_VarDecl *> decls;
+ init->gatherVarLHSUsage(decls);
+ //cond->gatherVarUsage( decls );
+ //incr->gatherVarUsage( decls );
+ //fprintf(stderr, "forstmt has %d vardecls in init, cond, inc\n", decls.size());
+
+ if (1 != decls.size()) {
fprintf(stderr, "uhoh, preferred index in for statement, but multiple variables used\n");
- print(0,stderr);
- fprintf(stderr, "\nvariables are:\n");
- for (int i=0; i<decls.size(); i++) {
- decls[i]->print(0,stderr); fprintf(stderr, "\n");
+ print(0, stderr);
+ fprintf(stderr, "\nvariables are:\n");
+ for (int i = 0; i < decls.size(); i++) {
+ decls[i]->print(0, stderr);
+ fprintf(stderr, "\n");
}
- exit(0);
+ exit(0);
}
- chillAST_VarDecl* olddecl = decls[0];
+ chillAST_VarDecl *olddecl = decls[0];
- // RIGHT NOW, change all the references that this loop wants swapped out
+ // RIGHT NOW, change all the references that this loop wants swapped out
// find vardecl for named preferred index. it has to already exist
- fprintf(stderr, "RIGHT NOW, change all the references that this loop wants swapped out \n");
+ fprintf(stderr, "RIGHT NOW, change all the references that this loop wants swapped out \n");
- chillAST_VarDecl *newguy = findVariableNamed( vname ); // recursive
- if (!newguy) {
+ chillAST_VarDecl *newguy = findVariableNamed(vname); // recursive
+ if (!newguy) {
fprintf(stderr, "there was no variable named %s anywhere I could find\n", vname);
}
- // wrong - this only looks at variables defined in the forstmt, not
+ // wrong - this only looks at variables defined in the forstmt, not
// in parents of the forstmt
- //int numsym = symtab->size();
+ //int numsym = symtab->size();
//fprintf(stderr, "%d symbols\n", numsym);
- //for (int i=0; i<numsym; i++) {
+ //for (int i=0; i<numsym; i++) {
// fprintf(stderr, "sym %d is '%s'\n", i, (*symtab)[i]->varname);
- // if (!strcmp(vname, (*symtab)[i]->varname)) {
+ // if (!strcmp(vname, (*symtab)[i]->varname)) {
// newguy = (*symtab)[i];
// }
//}
- if (!newguy) {
- fprintf(stderr, "chillAST_ForStmt::findLoopIndexesToReplace() there is no defined variable %s\n", vname);
+ if (!newguy) {
+ fprintf(stderr, "chillAST_ForStmt::findLoopIndexesToReplace() there is no defined variable %s\n", vname);
- // make one ?? seems like this should never happen
- newguy = new chillAST_VarDecl( olddecl->vartype, vname, ""/*?*/, NULL );
+ // make one ?? seems like this should never happen
+ newguy = new chillAST_VarDecl(olddecl->vartype, vname, ""/*?*/, NULL);
// insert actual declaration in code location? how?
// find parent of the ForStmt?
// find parent^n of the ForStmt that is not a Forstmt?
// find parent^n of the Forstmt that is a FunctionDecl?
chillAST_node *contain = findContainingNonLoop();
- if (contain == NULL) {
+ if (contain == NULL) {
fprintf(stderr, "nothing but loops all the way up?\n");
exit(0);
}
- fprintf(stderr, "containing non-loop is a %s\n", contain->getTypeString());
-
- contain->print(0,stderr);
- contain->insertChild( 0, newguy ); // ugly order TODO
- contain->addVariableToSymbolTable( newguy ); // adds to first enclosing symbolTable
-
- if (! symbolTableHasVariableNamed( contain->getSymbolTable(), vname )) {
- fprintf(stderr, "container doesn't have a var names %s afterwards???\n", vname);
- exit(-1);
+ fprintf(stderr, "containing non-loop is a %s\n", contain->getTypeString());
+
+ contain->print(0, stderr);
+ contain->insertChild(0, newguy); // ugly order TODO
+ contain->addVariableToSymbolTable(newguy); // adds to first enclosing symbolTable
+
+ if (!symbolTableHasVariableNamed(contain->getSymbolTable(), vname)) {
+ fprintf(stderr, "container doesn't have a var names %s afterwards???\n", vname);
+ exit(-1);
}
}
- // swap out old for new in init, cond, incr, body
- if (newguy) {
- fprintf(stderr, "\nwill replace %s with %s in init, cond, incr\n", olddecl->varname, newguy->varname);
+ // swap out old for new in init, cond, incr, body
+ if (newguy) {
+ fprintf(stderr, "\nwill replace %s with %s in init, cond, incr\n", olddecl->varname, newguy->varname);
fprintf(stderr, "was: for (");
init->print(0, stderr);
fprintf(stderr, "; ");
@@ -1931,11 +1897,11 @@ bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bo
fprintf(stderr, "; ");
incr->print(0, stderr);
fprintf(stderr, ")\n");
-
-
- init->replaceVarDecls( olddecl, newguy );
- cond->replaceVarDecls( olddecl, newguy );
- incr->replaceVarDecls( olddecl, newguy );
+
+
+ init->replaceVarDecls(olddecl, newguy);
+ cond->replaceVarDecls(olddecl, newguy);
+ incr->replaceVarDecls(olddecl, newguy);
fprintf(stderr, " is: for (");
init->print(0, stderr);
@@ -1945,74 +1911,74 @@ bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bo
incr->print(0, stderr);
fprintf(stderr, ")\n\n");
- fprintf(stderr,"recursing to ForStmt body of type %s\n", body->getTypeString());
- body->replaceVarDecls( olddecl, newguy );
+ fprintf(stderr, "recursing to ForStmt body of type %s\n", body->getTypeString());
+ body->replaceVarDecls(olddecl, newguy);
fprintf(stderr, "\nafter recursing to body, this loop is (there should be no %s)\n", olddecl->varname);
- print(0, stderr); fprintf(stderr, "\n");
-
+ print(0, stderr);
+ fprintf(stderr, "\n");
+
}
-
+
//if (!space) // there was only one preferred
- //fprintf(stderr, "removing metacomment\n");
+ //fprintf(stderr, "removing metacomment\n");
metacomment = NULL; // memleak
}
// check for more loops. We may have already swapped variables out in body (right above here)
- body->findLoopIndexesToReplace( symtab, false ) ;
+ body->findLoopIndexesToReplace(symtab, false);
- return force;
+ return force;
}
-void chillAST_ForStmt::replaceChild( chillAST_node *old, chillAST_node *newchild ){
- //fprintf(stderr, "chillAST_ForStmt::replaceChild() REALLY CALLING BODY->ReplaceCHILD\n");
- body->replaceChild( old, newchild );
+void chillAST_ForStmt::replaceChild(chillAST_node *old, chillAST_node *newchild) {
+ //fprintf(stderr, "chillAST_ForStmt::replaceChild() REALLY CALLING BODY->ReplaceCHILD\n");
+ body->replaceChild(old, newchild);
}
-
-void chillAST_ForStmt::replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){
- // logic problem if my loop var is olddecl!
+void chillAST_ForStmt::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ // logic problem if my loop var is olddecl!
//fprintf(stderr, "chillAST_ForStmt::replaceVarDecls( old %s, new %s )\n", olddecl->varname, newdecl->varname);
// this is called for inner loops!
- init->replaceVarDecls( olddecl, newdecl );
- cond->replaceVarDecls( olddecl, newdecl );
- incr->replaceVarDecls( olddecl, newdecl );
- body->replaceVarDecls( olddecl, newdecl );
+ init->replaceVarDecls(olddecl, newdecl);
+ cond->replaceVarDecls(olddecl, newdecl);
+ incr->replaceVarDecls(olddecl, newdecl);
+ body->replaceVarDecls(olddecl, newdecl);
}
-void chillAST_ForStmt::gatherLoopIndeces( std::vector<chillAST_VarDecl*> &indeces ) {
- //fprintf(stderr, "chillAST_ForStmt::gatherLoopIndeces()\nloop is:\n"); print(0,stderr);
+void chillAST_ForStmt::gatherLoopIndeces(std::vector<chillAST_VarDecl *> &indeces) {
+ //fprintf(stderr, "chillAST_ForStmt::gatherLoopIndeces()\nloop is:\n"); print(0,stderr);
- vector<chillAST_VarDecl*> decls;
- init->gatherVarLHSUsage( decls );
- cond->gatherVarLHSUsage( decls );
- incr->gatherVarLHSUsage( decls );
+ vector<chillAST_VarDecl *> decls;
+ init->gatherVarLHSUsage(decls);
+ cond->gatherVarLHSUsage(decls);
+ incr->gatherVarLHSUsage(decls);
// note: NOT GOING INTO BODY OF THE LOOP
- int numdecls = decls.size();
+ int numdecls = decls.size();
//fprintf(stderr, "gatherLoopIndeces(), %d lhs vardecls for this ForStmt\n", numdecls);
- for (int i=0; i<decls.size(); i++) {
+ for (int i = 0; i < decls.size(); i++) {
//fprintf(stderr, "%s %p\n", decls[i]->varname, decls[i] );
- indeces.push_back( decls[i] );
+ indeces.push_back(decls[i]);
}
-
+
// Don't forget to keep heading upwards!
if (parent) {
- //fprintf(stderr, "loop %p has parent of type %s\n", this, parent->getTypeString());
- parent->gatherLoopIndeces( indeces );
+ //fprintf(stderr, "loop %p has parent of type %s\n", this, parent->getTypeString());
+ parent->gatherLoopIndeces(indeces);
}
//else fprintf(stderr, "this loop has no parent???\n");
}
-void chillAST_ForStmt::gatherLoopVars( std::vector<std::string> &loopvars ) {
+void chillAST_ForStmt::gatherLoopVars(std::vector<std::string> &loopvars) {
//fprintf(stderr, "gathering loop vars for loop for (");
//init->print(0, stderr);
//fprintf(stderr, "; ");
@@ -2021,29 +1987,29 @@ void chillAST_ForStmt::gatherLoopVars( std::vector<std::string> &loopvars ) {
//incr->print(0, stderr);
//fprintf(stderr, ")\n" );
- //init->dump(0, stderr);
+ //init->dump(0, stderr);
- vector<chillAST_VarDecl*> decls;
- init->gatherVarLHSUsage( decls );
- cond->gatherVarLHSUsage( decls );
- incr->gatherVarLHSUsage( decls );
+ vector<chillAST_VarDecl *> decls;
+ init->gatherVarLHSUsage(decls);
+ cond->gatherVarLHSUsage(decls);
+ incr->gatherVarLHSUsage(decls);
// note: NOT GOING INTO BODY OF THE LOOP
-
- for (int i=0; i<decls.size(); i++) loopvars.push_back( strdup( decls[i]->varname ));
+
+ for (int i = 0; i < decls.size(); i++) loopvars.push_back(strdup(decls[i]->varname));
}
-void chillAST_ForStmt::loseLoopWithLoopVar( char *var ) {
+void chillAST_ForStmt::loseLoopWithLoopVar(char *var) {
- //fprintf(stderr, "\nchillAST_ForStmt::loseLoopWithLoopVar( %s )\n", var );
+ //fprintf(stderr, "\nchillAST_ForStmt::loseLoopWithLoopVar( %s )\n", var );
- // now recurse (could do first, I suppose)
+ // now recurse (could do first, I suppose)
// if you DON'T do this first, you may have already replaced yourself with this loop body
// the body will no longer have this forstmt as parent, it will have the forstmt's parent as its parent
- //fprintf(stderr, "forstmt 0x%x, recursing loseLoop to body 0x%x of type %s with parent 0x%x of type %s\n", this, body, body->getTypeString(), body->parent, body->parent->getTypeString());
- body->loseLoopWithLoopVar( var ) ;
+ //fprintf(stderr, "forstmt 0x%x, recursing loseLoop to body 0x%x of type %s with parent 0x%x of type %s\n", this, body, body->getTypeString(), body->parent, body->parent->getTypeString());
+ body->loseLoopWithLoopVar(var);
@@ -2051,306 +2017,309 @@ void chillAST_ForStmt::loseLoopWithLoopVar( char *var ) {
// if *I* am a loop to be replaced, tell my parent to replace me with my loop body
std::vector<std::string> loopvars;
- gatherLoopVars( loopvars );
-
- if (loopvars.size() != 1) {
+ gatherLoopVars(loopvars);
+
+ if (loopvars.size() != 1) {
fprintf(stderr, "uhoh, loop has more than a single loop var and trying to loseLoopWithLoopVar()\n");
- print(0,stderr);
- fprintf(stderr, "\nvariables are:\n");
- for (int i=0; i<loopvars.size(); i++) {
- fprintf(stderr, "%s\n", loopvars[i].c_str());
+ print(0, stderr);
+ fprintf(stderr, "\nvariables are:\n");
+ for (int i = 0; i < loopvars.size(); i++) {
+ fprintf(stderr, "%s\n", loopvars[i].c_str());
}
-
- exit(-1);
+
+ exit(-1);
}
-
+
//fprintf(stderr, "my loop var %s, looking for %s\n", loopvars[0].c_str(), var );
- if (!strcmp(var, loopvars[0].c_str())) {
+ if (!strcmp(var, loopvars[0].c_str())) {
//fprintf(stderr, "OK, trying to lose myself! for (");
//init->print(0, stderr);
//fprintf(stderr, "; ");
//cond->print(0, stderr);
//fprintf(stderr, "; ");
//incr->print(0, stderr);
- //fprintf(stderr, ")\n" );
+ //fprintf(stderr, ")\n" );
- if (!parent) {
+ if (!parent) {
fprintf(stderr, "chillAST_ForStmt::loseLoopWithLoopVar() I have no parent!\n");
exit(-1);
}
- vector<chillAST_VarDecl*> decls;
- init->gatherVarLHSUsage( decls ); // this can fail if init is outside the loop
- cond->gatherVarLHSUsage( decls );
- incr->gatherVarLHSUsage( decls );
- if (decls.size() > 1) {
+ vector<chillAST_VarDecl *> decls;
+ init->gatherVarLHSUsage(decls); // this can fail if init is outside the loop
+ cond->gatherVarLHSUsage(decls);
+ incr->gatherVarLHSUsage(decls);
+ if (decls.size() > 1) {
fprintf(stderr, "chill_ast.cc multiple loop variables confuses me\n");
- exit(-1);
+ exit(-1);
}
- chillAST_node *newstmt = body;
+ chillAST_node *newstmt = body;
// ACTUALLY, if I am being replaced, and my loop conditional is a min (Ternary), then wrap my loop body in an if statement
if (cond->isBinaryOperator()) { // what else could it be?
chillAST_BinaryOperator *BO = (chillAST_BinaryOperator *) cond;
- if (BO->rhs->isTernaryOperator()) {
+ if (BO->rhs->isTernaryOperator()) {
+
+ chillAST_TernaryOperator *TO = (chillAST_TernaryOperator *) BO->rhs;
+ chillAST_BinaryOperator *C = (chillAST_BinaryOperator *) TO->condition;
- chillAST_TernaryOperator *TO = (chillAST_TernaryOperator *)BO->rhs;
- chillAST_BinaryOperator *C = (chillAST_BinaryOperator *)TO->condition;
-
//fprintf(stderr, "loop condition RHS is ternary\nCondition RHS");
- C->print(); printf("\n"); fflush(stdout);
+ C->print();
+ printf("\n");
+ fflush(stdout);
chillAST_node *l = C->lhs;
- if (l->isParenExpr()) l = ((chillAST_ParenExpr *)l)->subexpr;
+ if (l->isParenExpr()) l = ((chillAST_ParenExpr *) l)->subexpr;
chillAST_node *r = C->rhs;
- if (r->isParenExpr()) r = ((chillAST_ParenExpr *)r)->subexpr;
+ if (r->isParenExpr()) r = ((chillAST_ParenExpr *) r)->subexpr;
- //fprintf(stderr, "lhs is %s rhs is %s\n", l->getTypeString(), r->getTypeString());
-
- chillAST_node *ifcondrhs = NULL;
+ //fprintf(stderr, "lhs is %s rhs is %s\n", l->getTypeString(), r->getTypeString());
+
+ chillAST_node *ifcondrhs = NULL;
if (!(l->isConstant())) ifcondrhs = l;
else if (!(r->isConstant())) ifcondrhs = r;
- else {
+ else {
// should never happen. 2 constants. infinite loop
- fprintf(stderr, "chill_ast.cc INIFNITE LOOP?\n");
- this->print(0,stderr); fprintf(stderr, "\n\n");
+ fprintf(stderr, "chill_ast.cc INIFNITE LOOP?\n");
+ this->print(0, stderr);
+ fprintf(stderr, "\n\n");
exit(-1);
}
-
+
// wrap the loop body in an if
- chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr( decls[0] );
- chillAST_BinaryOperator *ifcond = new chillAST_BinaryOperator( DRE, "<=", ifcondrhs );
- chillAST_IfStmt *ifstmt = new chillAST_IfStmt( ifcond, body, NULL, NULL );
-
- newstmt = ifstmt;
+ chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr(decls[0]);
+ chillAST_BinaryOperator *ifcond = new chillAST_BinaryOperator(DRE, "<=", ifcondrhs);
+ chillAST_IfStmt *ifstmt = new chillAST_IfStmt(ifcond, body, NULL, NULL);
+
+ newstmt = ifstmt;
}
}
- //fprintf(stderr, "forstmt 0x%x has parent 0x%x of type %s\n", this, parent, parent->getTypeString());
+ //fprintf(stderr, "forstmt 0x%x has parent 0x%x of type %s\n", this, parent, parent->getTypeString());
//fprintf(stderr, "forstmt will be replaced by\n");
- //newstmt->print(0,stderr); fprintf(stderr, "\n\n");
+ //newstmt->print(0,stderr); fprintf(stderr, "\n\n");
- parent->replaceChild( this, newstmt );
+ parent->replaceChild(this, newstmt);
}
}
-
-
-
chillAST_BinaryOperator::chillAST_BinaryOperator() {
//fprintf(stderr, "chillAST_BinaryOperator::chillAST_BinaryOperator() %p no parent\n", this);
CHILL_DEBUG_PRINT("no parent\n");
lhs = rhs = NULL;
op = NULL;
- asttype = CHILLAST_NODETYPE_BINARYOPERATOR;
- isFromSourceFile = true; // default
+ asttype = CHILLAST_NODETYPE_BINARYOPERATOR;
+ isFromSourceFile = true; // default
filename = NULL;
}
-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);
+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);
CHILL_DEBUG_PRINT("( 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");
- //}
+ //if (l && r ) {
+ // fprintf(stderr, "("); l->print(0,stderr); fprintf(stderr, ") %s (", oper); r->print(0,stderr); fprintf(stderr, ")\n\n");
+ //}
lhs = l;
rhs = r;
parent = par;
-
- if (lhs) lhs->setParent( this );
- if (rhs) rhs->setParent( this ); // may only have part of the lhs and rhs when binop is created
+
+ if (lhs) lhs->setParent(this);
+ if (rhs) rhs->setParent(this); // may only have part of the lhs and rhs when binop is created
op = strdup(oper);
- asttype = CHILLAST_NODETYPE_BINARYOPERATOR;
+ asttype = CHILLAST_NODETYPE_BINARYOPERATOR;
// if this writes to lhs and lhs type has an 'imwrittento' concept, set that up
- if (isAssignmentOp()) {
+ if (isAssignmentOp()) {
if (lhs && lhs->isArraySubscriptExpr()) {
- ((chillAST_ArraySubscriptExpr*)lhs)->imwrittento = true;
- //fprintf(stderr, "chillAST_BinaryOperator, op '=', lhs is an array reference LVALUE\n");
+ ((chillAST_ArraySubscriptExpr *) lhs)->imwrittento = true;
+ //fprintf(stderr, "chillAST_BinaryOperator, op '=', lhs is an array reference LVALUE\n");
}
}
- if (isAugmentedAssignmentOp()) { // += etc
- //fprintf(stderr, "isAugmentedAssignmentOp() "); print(); fflush(stdout);
- if (lhs && lhs->isArraySubscriptExpr()) {
- //fprintf(stderr, "lhs is also read from "); lhs->print(); fflush(stdout);
- ((chillAST_ArraySubscriptExpr*)lhs)->imreadfrom = true; // note will ALSO have imwrittento true
+ if (isAugmentedAssignmentOp()) { // += etc
+ //fprintf(stderr, "isAugmentedAssignmentOp() "); print(); fflush(stdout);
+ if (lhs && lhs->isArraySubscriptExpr()) {
+ //fprintf(stderr, "lhs is also read from "); lhs->print(); fflush(stdout);
+ ((chillAST_ArraySubscriptExpr *) lhs)->imreadfrom = true; // note will ALSO have imwrittento true
}
}
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-int chillAST_BinaryOperator::evalAsInt() {
+int chillAST_BinaryOperator::evalAsInt() {
// very limited. allow +-*/ and integer literals ...
- if (isAssignmentOp()) return rhs->evalAsInt(); // ?? ignores/loses lhs info
+ if (isAssignmentOp()) return rhs->evalAsInt(); // ?? ignores/loses lhs info
- if (!strcmp("+", op)) {
- //fprintf(stderr, "chillAST_BinaryOperator::evalAsInt() %d + %d\n", lhs->evalAsInt(), rhs->evalAsInt());
- return lhs->evalAsInt() + rhs->evalAsInt();
+ if (!strcmp("+", op)) {
+ //fprintf(stderr, "chillAST_BinaryOperator::evalAsInt() %d + %d\n", lhs->evalAsInt(), rhs->evalAsInt());
+ return lhs->evalAsInt() + rhs->evalAsInt();
}
- if (!strcmp("-", op)) return lhs->evalAsInt() - rhs->evalAsInt();
- if (!strcmp("*", op)) return lhs->evalAsInt() * rhs->evalAsInt();
- if (!strcmp("/", op)) return lhs->evalAsInt() / rhs->evalAsInt();
-
- fprintf(stderr, "chillAST_BinaryOperator::evalAsInt() unhandled op '%s'\n", op);
- segfault();
+ if (!strcmp("-", op)) return lhs->evalAsInt() - rhs->evalAsInt();
+ if (!strcmp("*", op)) return lhs->evalAsInt() * rhs->evalAsInt();
+ if (!strcmp("/", op)) return lhs->evalAsInt() / rhs->evalAsInt();
+
+ fprintf(stderr, "chillAST_BinaryOperator::evalAsInt() unhandled op '%s'\n", op);
+ exit(-1);
}
-chillAST_IntegerLiteral *chillAST_BinaryOperator::evalAsIntegerLiteral() {
- return new chillAST_IntegerLiteral( evalAsInt() ); // ??
+chillAST_IntegerLiteral *chillAST_BinaryOperator::evalAsIntegerLiteral() {
+ return new chillAST_IntegerLiteral(evalAsInt()); // ??
}
-void chillAST_BinaryOperator::dump( int indent, FILE *fp ) {
- chillindent(indent, fp);
+void chillAST_BinaryOperator::dump(int indent, FILE *fp) {
+ chillindent(indent, fp);
fprintf(fp, "(BinaryOperator '%s'\n", op);
- if (lhs) lhs->dump(indent+1, fp); // lhs could be null
- else { chillindent(indent+1, fp); fprintf(fp, "(NULL)\n"); }
- fflush(fp);
+ if (lhs) lhs->dump(indent + 1, fp); // lhs could be null
+ else {
+ chillindent(indent + 1, fp);
+ fprintf(fp, "(NULL)\n");
+ }
+ fflush(fp);
- if (rhs) rhs->dump(indent+1, fp); // rhs could be null
- else { chillindent(indent+1, fp); fprintf(fp, "(NULL)\n"); }
- fflush(fp);
+ if (rhs) rhs->dump(indent + 1, fp); // rhs could be null
+ else {
+ chillindent(indent + 1, fp);
+ fprintf(fp, "(NULL)\n");
+ }
+ fflush(fp);
- chillindent(indent, fp);
+ chillindent(indent, fp);
fprintf(fp, ")\n");
- fflush(fp);
+ fflush(fp);
}
-void chillAST_BinaryOperator::print( int indent, FILE *fp ) { // TODO this needparens logic is wrong
- printPreprocBEFORE(indent, fp);
+void chillAST_BinaryOperator::print(int indent, FILE *fp) { // TODO this needparens logic is wrong
+ printPreprocBEFORE(indent, fp);
- chillindent( indent, fp );
+ chillindent(indent, fp);
bool needparens = false;
- if (lhs) {
- if (lhs->isImplicitCastExpr()) {
+ if (lhs) {
+ if (lhs->isImplicitCastExpr()) {
// fprintf(stderr, "\nlhs 0x%x isImplicitCastExpr()\n", lhs);
// fprintf(stderr, "lhs subexpr 0x%x\n", ((chillAST_ImplicitCastExpr*)lhs)->subexpr);
// fprintf(stderr, "lhs subexpr type %s\n", ((chillAST_ImplicitCastExpr*)lhs)->subexpr->getTypeString());
- //
- if (((chillAST_ImplicitCastExpr*)lhs)->subexpr->isNotLeaf()) needparens = true;
- }
- else if (lhs->isNotLeaf()) {
- if (isMinusOp() && lhs->isPlusOp()) needparens = false;
- else if (isPlusMinusOp() && lhs->isMultDivOp()) needparens = false;
+ //
+ if (((chillAST_ImplicitCastExpr *) lhs)->subexpr->isNotLeaf()) needparens = true;
+ } else if (lhs->isNotLeaf()) {
+ if (isMinusOp() && lhs->isPlusOp()) needparens = false;
+ else if (isPlusMinusOp() && lhs->isMultDivOp()) needparens = false;
else needparens = true;
}
}
- //fprintf(stderr, "\n\nbinop ");
- //lhs->printonly(0,stderr);
- //fprintf(stderr," %s ",op);
- //rhs->printonly(0,stderr);
- //fprintf(stderr,"\n");
+ //fprintf(stderr, "\n\nbinop ");
+ //lhs->printonly(0,stderr);
+ //fprintf(stderr," %s ",op);
+ //rhs->printonly(0,stderr);
+ //fprintf(stderr,"\n");
//fprintf(stderr, "op is %s lhs %s rhs %s\n", op, lhs->getTypeString(), rhs->getTypeString());
- //fprintf(stderr, "lhs "); lhs->printonly(0, stderr); fprintf(stderr, " ");
- //fprintf(stderr, "lhs needparens = %d\n", needparens);
+ //fprintf(stderr, "lhs "); lhs->printonly(0, stderr); fprintf(stderr, " ");
+ //fprintf(stderr, "lhs needparens = %d\n", needparens);
if (needparens) fprintf(fp, "(");
- if (lhs) lhs->print( 0, fp );
- else fprintf(fp, "(NULL)");
- if (needparens) fprintf(fp, ")");
+ if (lhs) lhs->print(0, fp);
+ else fprintf(fp, "(NULL)");
+ if (needparens) fprintf(fp, ")");
- fprintf( fp, " %s ", op);
+ fprintf(fp, " %s ", op);
needparens = false;
- //fprintf(stderr, "binop rhs is of type %s\n", rhs->getTypeString());
- if (rhs) {
- if (rhs->isImplicitCastExpr()) {
- if (((chillAST_ImplicitCastExpr*)rhs)->subexpr->isNotLeaf()) needparens = true;
- }
- //else if (rhs->isNotLeaf()) needparens = true; // too many parens. test too simple
- else if (rhs->isNotLeaf()) {
+ //fprintf(stderr, "binop rhs is of type %s\n", rhs->getTypeString());
+ if (rhs) {
+ if (rhs->isImplicitCastExpr()) {
+ if (((chillAST_ImplicitCastExpr *) rhs)->subexpr->isNotLeaf()) needparens = true;
+ }
+ //else if (rhs->isNotLeaf()) needparens = true; // too many parens. test too simple
+ else if (rhs->isNotLeaf()) {
// really need the precedence ordering, and check relative of op and rhs op
- if (isMinusOp() ) needparens = true; // safer. perhaps complicated thing on rhs of a minus
- else if (isPlusMinusOp() && rhs->isMultDivOp()) needparens = false;
+ if (isMinusOp()) needparens = true; // safer. perhaps complicated thing on rhs of a minus
+ else if (isPlusMinusOp() && rhs->isMultDivOp()) needparens = false;
else needparens = true;
}
}
- //fprintf(stderr, "rhs "); rhs->printonly(0, stderr); fprintf(stderr, " ");
- //fprintf(stderr, "rhs needparens = %d\n\n", needparens);
- //if (!needparens) fprintf(stderr, "rhs isNotLeaf() = %d\n", rhs->isNotLeaf());
+ //fprintf(stderr, "rhs "); rhs->printonly(0, stderr); fprintf(stderr, " ");
+ //fprintf(stderr, "rhs needparens = %d\n\n", needparens);
+ //if (!needparens) fprintf(stderr, "rhs isNotLeaf() = %d\n", rhs->isNotLeaf());
if (needparens) fprintf(fp, "(");
- if (rhs) rhs->print( 0, fp );
- else fprintf(fp, "(NULL)");
- if (needparens) fprintf(fp, ")");
- fflush(fp);
- printPreprocAFTER(indent, fp);
+ if (rhs) rhs->print(0, fp);
+ else fprintf(fp, "(NULL)");
+ if (needparens) fprintf(fp, ")");
+ fflush(fp);
+ printPreprocAFTER(indent, fp);
}
-char *chillAST_BinaryOperator::stringRep(int indent ) {
- std::string s = string( lhs->stringRep() ) + " " + op + " " + string(lhs->stringRep() );
- return strdup( s.c_str() );
+char *chillAST_BinaryOperator::stringRep(int indent) {
+ std::string s = string(lhs->stringRep()) + " " + op + " " + string(lhs->stringRep());
+ return strdup(s.c_str());
}
+void chillAST_BinaryOperator::printonly(int indent, FILE *fp) {
-void chillAST_BinaryOperator::printonly( int indent, FILE *fp ) {
-
- lhs->printonly( indent, fp );
- fprintf( fp, " %s ", op);
- rhs->printonly( 0, fp );
- fflush(fp);
-
+ lhs->printonly(indent, fp);
+ fprintf(fp, " %s ", op);
+ rhs->printonly(0, fp);
+ fflush(fp);
}
-class chillAST_node* chillAST_BinaryOperator::constantFold() {
+class chillAST_node *chillAST_BinaryOperator::constantFold() {
//fprintf(stderr, "\nchillAST_BinaryOperator::constantFold() ");
//print(0,stderr); fprintf(stderr, "\n");
lhs = lhs->constantFold();
rhs = rhs->constantFold();
-
+
chillAST_node *returnval = this;
- if (lhs->isConstant() && rhs->isConstant() ) {
+ if (lhs->isConstant() && rhs->isConstant()) {
//fprintf(stderr, "binop folding constants\n"); print(0,stderr); fprintf(stderr, "\n");
- if (streq(op, "+") || streq(op, "-") || streq(op, "*")) {
+ if (streq(op, "+") || streq(op, "-") || streq(op, "*")) {
if (lhs->isIntegerLiteral() && rhs->isIntegerLiteral()) {
- chillAST_IntegerLiteral *l = (chillAST_IntegerLiteral *)lhs;
- chillAST_IntegerLiteral *r = (chillAST_IntegerLiteral *)rhs;
+ chillAST_IntegerLiteral *l = (chillAST_IntegerLiteral *) lhs;
+ chillAST_IntegerLiteral *r = (chillAST_IntegerLiteral *) rhs;
chillAST_IntegerLiteral *I;
-
- if (streq(op, "+")) I = new chillAST_IntegerLiteral(l->value+r->value, parent);
- if (streq(op, "-")) I = new chillAST_IntegerLiteral(l->value-r->value, parent);
- if (streq(op, "*")) I = new chillAST_IntegerLiteral(l->value*r->value, parent);
+
+ if (streq(op, "+")) I = new chillAST_IntegerLiteral(l->value + r->value, parent);
+ if (streq(op, "-")) I = new chillAST_IntegerLiteral(l->value - r->value, parent);
+ if (streq(op, "*")) I = new chillAST_IntegerLiteral(l->value * r->value, parent);
returnval = I;
//fprintf(stderr, "%d %s %d becomes %d\n", l->value,op, r->value, I->value);
- }
- else { // at least one is a float
+ } else { // at least one is a float
// usually don't want to do this for floats or doubles
- // could probably check for special cases like 0.0/30.0 or X/X or X/1.0
+ // could probably check for special cases like 0.0/30.0 or X/X or X/1.0
#ifdef FOLDFLOATS
- float lval, rval;
- if (lhs->isIntegerLiteral()) {
- lval = (float) ((chillAST_IntegerLiteral *)lhs)->value;
+ float lval, rval;
+ if (lhs->isIntegerLiteral()) {
+ lval = (float) ((chillAST_IntegerLiteral *)lhs)->value;
}
- else {
- lval = ((chillAST_FloatingLiteral *)lhs)->value;
+ else {
+ lval = ((chillAST_FloatingLiteral *)lhs)->value;
}
- if (rhs->isIntegerLiteral()) {
- rval = (float) ((chillAST_IntegerLiteral *)rhs)->value;
+ if (rhs->isIntegerLiteral()) {
+ rval = (float) ((chillAST_IntegerLiteral *)rhs)->value;
}
- else {
- rval = ((chillAST_FloatingLiteral *)rhs)->value;
+ else {
+ rval = ((chillAST_FloatingLiteral *)rhs)->value;
}
chillAST_FloatingLiteral *F;
@@ -2363,301 +2332,297 @@ class chillAST_node* chillAST_BinaryOperator::constantFold() {
}
}
- //else fprintf(stderr, "can't fold op '%s' yet\n", op);
+ //else fprintf(stderr, "can't fold op '%s' yet\n", op);
}
- //fprintf(stderr, "returning "); returnval->print(0,stderr); fprintf(stderr, "\n");
+ //fprintf(stderr, "returning "); returnval->print(0,stderr); fprintf(stderr, "\n");
return returnval;
}
-class chillAST_node* chillAST_BinaryOperator::clone() {
- //fprintf(stderr, "chillAST_BinaryOperator::clone() "); print(); printf("\n"); fflush(stdout);
+class chillAST_node *chillAST_BinaryOperator::clone() {
+ //fprintf(stderr, "chillAST_BinaryOperator::clone() "); print(); printf("\n"); fflush(stdout);
- chillAST_node* l = lhs->clone();
- chillAST_node* r = rhs->clone();
- chillAST_BinaryOperator *bo = new chillAST_BinaryOperator( l, op, r, parent );
- l->setParent( bo );
- r->setParent( bo );
+ chillAST_node *l = lhs->clone();
+ chillAST_node *r = rhs->clone();
+ chillAST_BinaryOperator *bo = new chillAST_BinaryOperator(l, op, r, parent);
+ l->setParent(bo);
+ r->setParent(bo);
bo->isFromSourceFile = isFromSourceFile;
- if (filename) bo->filename = strdup(filename);
+ if (filename) bo->filename = strdup(filename);
return bo;
}
-void chillAST_BinaryOperator::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ) {
- //fprintf(stderr, "chillAST_BinaryOperator::gatherArrayRefs()\n");
- //print(); fflush(stdout); fprintf(stderr, "\n");
- //if (isAugmentedAssignmentOp()) {
+void chillAST_BinaryOperator::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {
+ //fprintf(stderr, "chillAST_BinaryOperator::gatherArrayRefs()\n");
+ //print(); fflush(stdout); fprintf(stderr, "\n");
+ //if (isAugmentedAssignmentOp()) {
// fprintf(stderr, "%s is augmented assignment\n", op);
//}
- //if (isAssignmentOp()) {
+ //if (isAssignmentOp()) {
// fprintf(stderr, "%s is assignment\n", op);
//}
//if (isAugmentedAssignmentOp()) { // lhs is ALSO on the RHS, NOT as a write
// if (lhs->isArraySubscriptExpr()) { // probably some case where this fails
- // ((chillAST_ArraySubscriptExpr *) lhs)->imreadfrom = true;
+ // ((chillAST_ArraySubscriptExpr *) lhs)->imreadfrom = true;
// //lhs->&gatherArrayRefs( refs, 0 );
// }
- //}
+ //}
- //fprintf(stderr, "in chillAST_BinaryOperator::gatherArrayRefs(), %d &arrayrefs before\n", refs.size());
- lhs->gatherArrayRefs( refs, isAssignmentOp() );
- //fprintf(stderr, "in chillAST_BinaryOperator::gatherArrayRefs(), %d &arrayrefs after lhs\n", refs.size());
- rhs->gatherArrayRefs( refs, 0 );
- //fprintf(stderr, "in chillAST_BinaryOperator::gatherArrayRefs(), %d &refs\n", refs.size());
-
- //for (int i=0; i<refs.size(); i++) {
- // fprintf(stderr, "%s\n", (*refs)[i]->basedecl->varname);
- //}
+ //fprintf(stderr, "in chillAST_BinaryOperator::gatherArrayRefs(), %d &arrayrefs before\n", refs.size());
+ lhs->gatherArrayRefs(refs, isAssignmentOp());
+ //fprintf(stderr, "in chillAST_BinaryOperator::gatherArrayRefs(), %d &arrayrefs after lhs\n", refs.size());
+ rhs->gatherArrayRefs(refs, 0);
+ //fprintf(stderr, "in chillAST_BinaryOperator::gatherArrayRefs(), %d &refs\n", refs.size());
+
+ //for (int i=0; i<refs.size(); i++) {
+ // fprintf(stderr, "%s\n", (*refs)[i]->basedecl->varname);
+ //}
}
-void chillAST_BinaryOperator::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- lhs->gatherScalarRefs( refs, isAssignmentOp() );
- rhs->gatherScalarRefs( refs, 0 );
-}
+void chillAST_BinaryOperator::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ lhs->gatherScalarRefs(refs, isAssignmentOp());
+ rhs->gatherScalarRefs(refs, 0);
+}
-void chillAST_BinaryOperator::replaceChild( chillAST_node *old, chillAST_node *newchild ) {
+void chillAST_BinaryOperator::replaceChild(chillAST_node *old, chillAST_node *newchild) {
//fprintf(stderr, "\nbinop::replaceChild( old 0x%x, new ) lhs 0x%x rhd 0x%x\n", old, lhs, rhs);
// will pointers match??
- if (lhs == old) setLHS( newchild );
- else if (rhs == old) setRHS( newchild );
-
- // silently ignore?
- //else {
+ if (lhs == old) setLHS(newchild);
+ else if (rhs == old) setRHS(newchild);
+
+ // silently ignore?
+ //else {
// fprintf(stderr, "\nERROR chillAST_BinaryOperator::replaceChild( old 0x%x, new ) lhs 0x%x rhd 0x%x\n", old, lhs, rhs);
// fprintf(stderr, "old is not a child of this BinaryOperator\n");
// print();
// dump();
- // exit(-1);
- //}
+ // exit(-1);
+ //}
}
+void chillAST_BinaryOperator::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_BinaryOperator::gatherVarDecls()\n");
-void chillAST_BinaryOperator::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_BinaryOperator::gatherVarDecls()\n");
-
- //fprintf(stderr, "chillAST_BinaryOperator::gatherVarDecls() before %d\n", decls.size());
- //print(0,stderr); fprintf(stderr, "\n");
- //fprintf(stderr, "lhs is %s\n", lhs->getTypeString());
- if (lhs) lhs->gatherVarDecls( decls ); // 'if' to deal with partially formed
- if (rhs) rhs->gatherVarDecls( decls );
- //fprintf(stderr, "after %d\n", decls.size());
+ //fprintf(stderr, "chillAST_BinaryOperator::gatherVarDecls() before %d\n", decls.size());
+ //print(0,stderr); fprintf(stderr, "\n");
+ //fprintf(stderr, "lhs is %s\n", lhs->getTypeString());
+ if (lhs) lhs->gatherVarDecls(decls); // 'if' to deal with partially formed
+ if (rhs) rhs->gatherVarDecls(decls);
+ //fprintf(stderr, "after %d\n", decls.size());
}
-void chillAST_BinaryOperator::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_BinaryOperator::gatherScalarVarDecls() before %d\n", decls.size());
- //fprintf(stderr, "lhs is %s\n", lhs->getTypeString());
- lhs->gatherScalarVarDecls( decls );
- rhs->gatherScalarVarDecls( decls );
- //fprintf(stderr, "after %d\n", decls.size());
+void chillAST_BinaryOperator::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_BinaryOperator::gatherScalarVarDecls() before %d\n", decls.size());
+ //fprintf(stderr, "lhs is %s\n", lhs->getTypeString());
+ lhs->gatherScalarVarDecls(decls);
+ rhs->gatherScalarVarDecls(decls);
+ //fprintf(stderr, "after %d\n", decls.size());
}
-void chillAST_BinaryOperator::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_BinaryOperator::gatherArrayVarDecls() before %d\n", decls.size());
- //fprintf(stderr, "lhs is %s\n", lhs->getTypeString());
- lhs->gatherArrayVarDecls( decls );
- rhs->gatherArrayVarDecls( decls );
- //fprintf(stderr, "after %d\n", decls.size());
+void chillAST_BinaryOperator::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_BinaryOperator::gatherArrayVarDecls() before %d\n", decls.size());
+ //fprintf(stderr, "lhs is %s\n", lhs->getTypeString());
+ lhs->gatherArrayVarDecls(decls);
+ rhs->gatherArrayVarDecls(decls);
+ //fprintf(stderr, "after %d\n", decls.size());
}
-
-void chillAST_BinaryOperator::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- lhs->gatherDeclRefExprs( refs );
- rhs->gatherDeclRefExprs( refs );
+void chillAST_BinaryOperator::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ lhs->gatherDeclRefExprs(refs);
+ rhs->gatherDeclRefExprs(refs);
}
-void chillAST_BinaryOperator::gatherStatements(std::vector<chillAST_node*> &statements ){
-
+void chillAST_BinaryOperator::gatherStatements(std::vector<chillAST_node *> &statements) {
+
// what's legit?
- if (isAssignmentOp()) {
- statements.push_back( this );
+ if (isAssignmentOp()) {
+ statements.push_back(this);
}
}
-
-
-void chillAST_BinaryOperator::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- lhs->gatherVarUsage( decls );
- rhs->gatherVarUsage( decls );
+void chillAST_BinaryOperator::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ lhs->gatherVarUsage(decls);
+ rhs->gatherVarUsage(decls);
}
-void chillAST_BinaryOperator::gatherVarLHSUsage( vector<chillAST_VarDecl*> &decls ) {
- lhs->gatherVarUsage( decls );
+void chillAST_BinaryOperator::gatherVarLHSUsage(vector<chillAST_VarDecl *> &decls) {
+ lhs->gatherVarUsage(decls);
}
- void chillAST_BinaryOperator::replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
- //if (!strcmp(op, "<=")) {
- // fprintf(stderr, "chillAST_BinaryOperator::replaceVarDecls( old %s, new %s)\n", olddecl->varname, newdecl->varname );
- // print(); printf("\n"); fflush(stdout);
- // fprintf(stderr, "binaryoperator, lhs is of type %s\n", lhs->getTypeString());
- // fprintf(stderr, "binaryoperator, rhs is of type %s\n", rhs->getTypeString());
- //}
- lhs->replaceVarDecls( olddecl, newdecl );
- rhs->replaceVarDecls( olddecl, newdecl );
- //if (!strcmp(op, "<=")) {
- // print(); printf("\n\n"); fflush(stdout);
- //}
- }
+void chillAST_BinaryOperator::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ //if (!strcmp(op, "<=")) {
+ // fprintf(stderr, "chillAST_BinaryOperator::replaceVarDecls( old %s, new %s)\n", olddecl->varname, newdecl->varname );
+ // print(); printf("\n"); fflush(stdout);
+ // fprintf(stderr, "binaryoperator, lhs is of type %s\n", lhs->getTypeString());
+ // fprintf(stderr, "binaryoperator, rhs is of type %s\n", rhs->getTypeString());
+ //}
+ lhs->replaceVarDecls(olddecl, newdecl);
+ rhs->replaceVarDecls(olddecl, newdecl);
+ //if (!strcmp(op, "<=")) {
+ // print(); printf("\n\n"); fflush(stdout);
+ //}
+}
-bool chillAST_BinaryOperator::isSameAs( chillAST_node *other ){
+bool chillAST_BinaryOperator::isSameAs(chillAST_node *other) {
if (!other->isBinaryOperator()) return false;
- chillAST_BinaryOperator *o = (chillAST_BinaryOperator *)other;
- if (strcmp(op, o->op)) return false; // different operators
- return lhs->isSameAs( o->lhs ) && rhs->isSameAs( o->rhs ); // recurse
+ chillAST_BinaryOperator *o = (chillAST_BinaryOperator *) other;
+ if (strcmp(op, o->op)) return false; // different operators
+ return lhs->isSameAs(o->lhs) && rhs->isSameAs(o->rhs); // recurse
}
-
-
chillAST_TernaryOperator::chillAST_TernaryOperator() {
op = strdup("?"); // the only one so far
condition = lhs = rhs = NULL;
- asttype = CHILLAST_NODETYPE_TERNARYOPERATOR;
- isFromSourceFile = true; // default
+ asttype = CHILLAST_NODETYPE_TERNARYOPERATOR;
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_TernaryOperator::chillAST_TernaryOperator(const char *oper, chillAST_node *c, chillAST_node *l, chillAST_node *r, chillAST_node *par) {
-
+chillAST_TernaryOperator::chillAST_TernaryOperator(const char *oper, chillAST_node *c, chillAST_node *l,
+ chillAST_node *r, chillAST_node *par) {
+
op = strdup(oper);
- condition = c; condition->setParent( this );
- lhs = l; lhs->setParent( this );
- rhs = r; rhs->setParent( this );
- asttype = CHILLAST_NODETYPE_TERNARYOPERATOR;
- isFromSourceFile = true; // default
+ condition = c;
+ condition->setParent(this);
+ lhs = l;
+ lhs->setParent(this);
+ rhs = r;
+ rhs->setParent(this);
+ asttype = CHILLAST_NODETYPE_TERNARYOPERATOR;
+ isFromSourceFile = true; // default
filename = NULL;
}
-void chillAST_TernaryOperator::dump( int indent, FILE *fp ) {
- chillindent(indent, fp);
+void chillAST_TernaryOperator::dump(int indent, FILE *fp) {
+ chillindent(indent, fp);
fprintf(fp, "(TernaryOperator '%s'\n", op);
- condition->dump(indent+1, fp);
- lhs->dump(indent+1, fp);
- rhs->dump(indent+1, fp);
- chillindent(indent, fp);
+ condition->dump(indent + 1, fp);
+ lhs->dump(indent + 1, fp);
+ rhs->dump(indent + 1, fp);
+ chillindent(indent, fp);
fprintf(fp, ")\n");
fflush(fp);
}
-void chillAST_TernaryOperator::print( int indent, FILE *fp ) {
- printPreprocBEFORE(indent, fp);
+void chillAST_TernaryOperator::print(int indent, FILE *fp) {
+ printPreprocBEFORE(indent, fp);
chillindent(indent, fp);
fprintf(fp, "(");
- condition->print(0,fp);
- fprintf(fp, "%s", op);
- lhs->print(0,fp);
+ condition->print(0, fp);
+ fprintf(fp, "%s", op);
+ lhs->print(0, fp);
fprintf(fp, ":");
- rhs->print(0,fp);
+ rhs->print(0, fp);
fprintf(fp, ")");
fflush(fp);
}
-void chillAST_TernaryOperator::replaceChild( chillAST_node *old, chillAST_node *newchild ) {
+void chillAST_TernaryOperator::replaceChild(chillAST_node *old, chillAST_node *newchild) {
//fprintf(stderr, "\nbinop::replaceChild( old 0x%x, new ) lhs 0x%x rhd 0x%x\n", old, lhs, rhs);
// will pointers match??
- if (lhs == old) setLHS( newchild );
- else if (rhs == old) setRHS( newchild );
- else if (condition == old) setCond( newchild );
+ if (lhs == old) setLHS(newchild);
+ else if (rhs == old) setRHS(newchild);
+ else if (condition == old) setCond(newchild);
- // silently ignore?
- //else {
+ // silently ignore?
+ //else {
//}
}
-void chillAST_TernaryOperator::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- condition->gatherVarDecls( decls );
- lhs->gatherVarDecls( decls );
- rhs->gatherVarDecls( decls );
+void chillAST_TernaryOperator::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ condition->gatherVarDecls(decls);
+ lhs->gatherVarDecls(decls);
+ rhs->gatherVarDecls(decls);
}
-void chillAST_TernaryOperator::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- condition->gatherScalarVarDecls( decls );
- lhs->gatherScalarVarDecls( decls );
- rhs->gatherScalarVarDecls( decls );
+void chillAST_TernaryOperator::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ condition->gatherScalarVarDecls(decls);
+ lhs->gatherScalarVarDecls(decls);
+ rhs->gatherScalarVarDecls(decls);
}
-void chillAST_TernaryOperator::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- condition->gatherArrayVarDecls( decls );
- lhs->gatherArrayVarDecls( decls );
- rhs->gatherArrayVarDecls( decls );
+void chillAST_TernaryOperator::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ condition->gatherArrayVarDecls(decls);
+ lhs->gatherArrayVarDecls(decls);
+ rhs->gatherArrayVarDecls(decls);
}
-
-void chillAST_TernaryOperator::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- condition->gatherDeclRefExprs( refs );
- lhs->gatherDeclRefExprs( refs );
- rhs->gatherDeclRefExprs( refs );
+void chillAST_TernaryOperator::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ condition->gatherDeclRefExprs(refs);
+ lhs->gatherDeclRefExprs(refs);
+ rhs->gatherDeclRefExprs(refs);
}
-
-void chillAST_TernaryOperator::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- condition->gatherVarUsage( decls );
- lhs->gatherVarUsage( decls );
- rhs->gatherVarUsage( decls );
+void chillAST_TernaryOperator::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ condition->gatherVarUsage(decls);
+ lhs->gatherVarUsage(decls);
+ rhs->gatherVarUsage(decls);
}
-void chillAST_TernaryOperator::gatherVarLHSUsage( vector<chillAST_VarDecl*> &decls ) {
- // this makes no sense for ternary ??
+void chillAST_TernaryOperator::gatherVarLHSUsage(vector<chillAST_VarDecl *> &decls) {
+ // this makes no sense for ternary ??
}
-void chillAST_TernaryOperator::replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
- condition->replaceVarDecls( olddecl, newdecl );
- lhs->replaceVarDecls( olddecl, newdecl );
- rhs->replaceVarDecls( olddecl, newdecl );
+void chillAST_TernaryOperator::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ condition->replaceVarDecls(olddecl, newdecl);
+ lhs->replaceVarDecls(olddecl, newdecl);
+ rhs->replaceVarDecls(olddecl, newdecl);
}
-void chillAST_TernaryOperator::printonly( int indent, FILE *fp ) {
+void chillAST_TernaryOperator::printonly(int indent, FILE *fp) {
fprintf(fp, "(");
- condition->printonly(0,fp);
- fprintf(fp, "%s", op);
- lhs->printonly(0,fp);
+ condition->printonly(0, fp);
+ fprintf(fp, "%s", op);
+ lhs->printonly(0, fp);
fprintf(fp, ":");
- rhs->printonly(0,fp);
+ rhs->printonly(0, fp);
fprintf(fp, ")");
fflush(fp);
}
-class chillAST_node* chillAST_TernaryOperator::constantFold() {
+class chillAST_node *chillAST_TernaryOperator::constantFold() {
condition = condition->constantFold();
lhs = lhs->constantFold();
rhs = rhs->constantFold();
-
+
chillAST_node *returnval = this;
- if (condition->isConstant()) {
+ if (condition->isConstant()) {
//fprintf(stderr, "ternop folding constants\n");
//print(0,stderr);
//fprintf(stderr, "\n");
// assume op is "?"
- // TODO
- /*
-
- if (streq(op, "+") || streq(op, "-") || streq(op, "*")) {
+ // TODO
+ /*
+
+ if (streq(op, "+") || streq(op, "-") || streq(op, "*")) {
if (lhs->isIntegerLiteral() && rhs->isIntegerLiteral()) {
chillAST_IntegerLiteral *l = (chillAST_IntegerLiteral *)lhs;
chillAST_IntegerLiteral *r = (chillAST_IntegerLiteral *)rhs;
chillAST_IntegerLiteral *I;
-
+
if (streq(op, "+")) I = new chillAST_IntegerLiteral(l->value+r->value, parent);
if (streq(op, "-")) I = new chillAST_IntegerLiteral(l->value-r->value, parent);
if (streq(op, "*")) I = new chillAST_IntegerLiteral(l->value*r->value, parent);
@@ -2667,17 +2632,17 @@ class chillAST_node* chillAST_TernaryOperator::constantFold() {
}
else { // at least one is a float
float lval, rval;
- if (lhs->isIntegerLiteral()) {
- lval = (float) ((chillAST_IntegerLiteral *)lhs)->value;
+ if (lhs->isIntegerLiteral()) {
+ lval = (float) ((chillAST_IntegerLiteral *)lhs)->value;
}
- else {
- lval = ((chillAST_FloatingLiteral *)lhs)->value;
+ else {
+ lval = ((chillAST_FloatingLiteral *)lhs)->value;
}
- if (rhs->isIntegerLiteral()) {
- rval = (float) ((chillAST_IntegerLiteral *)rhs)->value;
+ if (rhs->isIntegerLiteral()) {
+ rval = (float) ((chillAST_IntegerLiteral *)rhs)->value;
}
- else {
- rval = ((chillAST_FloatingLiteral *)rhs)->value;
+ else {
+ rval = ((chillAST_FloatingLiteral *)rhs)->value;
}
chillAST_FloatingLiteral *F;
@@ -2688,238 +2653,232 @@ class chillAST_node* chillAST_TernaryOperator::constantFold() {
returnval = F;
}
}
- else fprintf(stderr, "can't fold op '%s' yet\n", op);
+ else fprintf(stderr, "can't fold op '%s' yet\n", op);
*/
}
return returnval;
}
-class chillAST_node* chillAST_TernaryOperator::clone() {
- chillAST_node* c = condition->clone();
- chillAST_node* l = lhs->clone();
- chillAST_node* r = rhs->clone();
- chillAST_TernaryOperator *to = new chillAST_TernaryOperator( op, l, r, parent );
- c->setParent( to );
- l->setParent( to );
- r->setParent( to );
+class chillAST_node *chillAST_TernaryOperator::clone() {
+ chillAST_node *c = condition->clone();
+ chillAST_node *l = lhs->clone();
+ chillAST_node *r = rhs->clone();
+ chillAST_TernaryOperator *to = new chillAST_TernaryOperator(op, l, r, parent);
+ c->setParent(to);
+ l->setParent(to);
+ r->setParent(to);
to->isFromSourceFile = isFromSourceFile;
filename = NULL;
return to;
}
-void chillAST_TernaryOperator::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ) {
- condition->gatherArrayRefs( refs, isAssignmentOp() );
- lhs->gatherArrayRefs( refs, isAssignmentOp() );
- rhs->gatherArrayRefs( refs, 0 );
+void chillAST_TernaryOperator::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {
+ condition->gatherArrayRefs(refs, isAssignmentOp());
+ lhs->gatherArrayRefs(refs, isAssignmentOp());
+ rhs->gatherArrayRefs(refs, 0);
}
-void chillAST_TernaryOperator::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- condition->gatherScalarRefs( refs, isAssignmentOp() );
- lhs->gatherScalarRefs( refs, isAssignmentOp() );
- rhs->gatherScalarRefs( refs, 0 );
-}
-
-
-
-
-
+void chillAST_TernaryOperator::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ condition->gatherScalarRefs(refs, isAssignmentOp());
+ lhs->gatherScalarRefs(refs, isAssignmentOp());
+ rhs->gatherScalarRefs(refs, 0);
+}
-chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() {
- //fprintf(stderr, "\n%p chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 0\n", this);
- asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR;
+chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() {
+ //fprintf(stderr, "\n%p chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 0\n", this);
+ asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR;
base = index = NULL;
- basedecl = NULL; //fprintf(stderr, "setting basedecl NULL for ASE %p\n", this);
- imwrittento = false; // ??
- imreadfrom = false; // ??
+ basedecl = NULL; //fprintf(stderr, "setting basedecl NULL for ASE %p\n", this);
+ imwrittento = false; // ??
+ imreadfrom = false; // ??
parent = NULL;
metacomment = NULL;
//fprintf(stderr, "chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() NEED TO FAKE A LOCATION\n");
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
- //fprintf(stderr, "\nASE %p is empty\n", this);
+ //fprintf(stderr, "\nASE %p is empty\n", this);
}
-
-chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr( chillAST_node *bas, chillAST_node *indx, chillAST_node *par, void *unique ) {
+chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, chillAST_node *par,
+ void *unique) {
//fprintf(stderr, "\nchillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 1\n");
- //fprintf(stderr, "ASE index %p ", indx); indx->print(0,stderr); fprintf(stderr, "\n");
- asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR;
- bas->setParent( this );
- if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr*)bas)->subexpr; // probably wrong
- else base = bas;
- if (indx->isImplicitCastExpr()) index = ((chillAST_ImplicitCastExpr*)indx)->subexpr; // probably wrong
+ //fprintf(stderr, "ASE index %p ", indx); indx->print(0,stderr); fprintf(stderr, "\n");
+ asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR;
+ bas->setParent(this);
+ if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr *) bas)->subexpr; // probably wrong
+ else base = bas;
+ if (indx->isImplicitCastExpr()) index = ((chillAST_ImplicitCastExpr *) indx)->subexpr; // probably wrong
else index = indx;
- base->setParent( this );
- index->setParent( this );
+ base->setParent(this);
+ index->setParent(this);
- imwrittento = false; // ??
- imreadfrom = false; // ??
+ imwrittento = false; // ??
+ imreadfrom = false; // ??
uniquePtr = (void *) unique;
- //fprintf(stderr,"chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() original = 0x%x\n", uniquePtr);
- //fprintf(stderr, "chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 1 calling multibase()\n");
- basedecl = multibase();//fprintf(stderr, "%p ASE 1 basedecl = %p\n",this,basedecl);
+ //fprintf(stderr,"chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() original = 0x%x\n", uniquePtr);
+ //fprintf(stderr, "chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 1 calling multibase()\n");
+ basedecl = multibase();//fprintf(stderr, "%p ASE 1 basedecl = %p\n",this,basedecl);
//basedecl->print(); printf("\n");
- //basedecl->dump(); printf("\n"); fflush(stdout);
- //fprintf(stderr, "basedecl varname %s\n", basedecl->varname);
- isFromSourceFile = true; // default
+ //basedecl->dump(); printf("\n"); fflush(stdout);
+ //fprintf(stderr, "basedecl varname %s\n", basedecl->varname);
+ isFromSourceFile = true; // default
filename = NULL;
- //fprintf(stderr, "\nASE %p parent %p ", this, parent); print(0,stderr); fprintf(stderr, "\n\n");
+ //fprintf(stderr, "\nASE %p parent %p ", this, parent); print(0,stderr); fprintf(stderr, "\n\n");
}
+chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, bool writtento,
+ chillAST_node *par, void *unique) {
+ //fprintf(stderr, "\nchillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 2 parent %p\n", par );
+ //fprintf(stderr, "ASE %p index %p ", this, indx); indx->print(0,stderr); fprintf(stderr, "\n");
-chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr( chillAST_node *bas, chillAST_node *indx, bool writtento, chillAST_node *par, void *unique ) {
- //fprintf(stderr, "\nchillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 2 parent %p\n", par );
- //fprintf(stderr, "ASE %p index %p ", this, indx); indx->print(0,stderr); fprintf(stderr, "\n");
-
- asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR;
- bas->setParent( this );
- if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr*)bas)->subexpr; // probably wrong
+ asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR;
+ bas->setParent(this);
+ if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr *) bas)->subexpr; // probably wrong
else base = bas;
- if (indx->isImplicitCastExpr()) index = ((chillAST_ImplicitCastExpr*)indx)->subexpr; // probably wrong
+ if (indx->isImplicitCastExpr()) index = ((chillAST_ImplicitCastExpr *) indx)->subexpr; // probably wrong
else index = indx;
-
+
//fprintf(stderr, "setting parent of base %p to %p\n", base, this);
//fprintf(stderr, "setting parent of index %p to %p\n", index, this);
- base->setParent( this );
- index->setParent( this );
-
- imwrittento = writtento; // ??
+ base->setParent(this);
+ index->setParent(this);
+
+ imwrittento = writtento; // ??
//fprintf(stderr, "ASE %p imwrittento %d\n", this, imwrittento);
- imreadfrom = false; // ??
+ imreadfrom = false; // ??
uniquePtr = (void *) unique;
- //fprintf(stderr,"chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() original = 0x%x\n", uniquePtr);
+ //fprintf(stderr,"chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() original = 0x%x\n", uniquePtr);
- basedecl = multibase();
+ basedecl = multibase();
- //fprintf(stderr, "%p ASE 2 basedecl = %p\n", this, basedecl);
- //printf("basedecl is "); fflush(stdout); basedecl->print(); printf("\n"); fflush(stdout);
+ //fprintf(stderr, "%p ASE 2 basedecl = %p\n", this, basedecl);
+ //printf("basedecl is "); fflush(stdout); basedecl->print(); printf("\n"); fflush(stdout);
//basedecl->dump(); printf("\n"); fflush(stdout);
- //fprintf(stderr, "basedecl varname %s\n", basedecl->varname);
- isFromSourceFile = true; // default
+ //fprintf(stderr, "basedecl varname %s\n", basedecl->varname);
+ isFromSourceFile = true; // default
filename = NULL;
//fprintf(stderr, "chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 2 DONE\n");
- //print(0,stderr); fprintf(stderr, "\n\n");
- //fprintf(stderr, "\nASE %p parent %p ", this, parent); print(0,stderr); fprintf(stderr, "\n\n");
- }
-
+ //print(0,stderr); fprintf(stderr, "\n\n");
+ //fprintf(stderr, "\nASE %p parent %p ", this, parent); print(0,stderr); fprintf(stderr, "\n\n");
+}
-chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr( chillAST_VarDecl *v, std::vector<chillAST_node *> indeces, chillAST_node *par) {
- //fprintf(stderr, "\nchillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 4\n");
+chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, std::vector<chillAST_node *> indeces,
+ chillAST_node *par) {
+ //fprintf(stderr, "\nchillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 4\n");
//fprintf(stderr,"chillAST_ArraySubscriptExpr( chillAST_VarDecl *v, std::vector<int> indeces)\n");
- asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR;
+ asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR;
parent = par;
- //if (parent == NULL) {
- // fprintf(stderr, "dammit. ASE %p has no parent\n", this);
- //}
+ //if (parent == NULL) {
+ // fprintf(stderr, "dammit. ASE %p has no parent\n", this);
+ //}
int numindeces = indeces.size();
- for (int i=0; i<numindeces; i++) {
- fprintf(stderr, "ASE index %d ", i); indeces[i]->print(0,stderr); fprintf(stderr, "\n");
- // printf("[");
- // indeces[i]->print();
- // printf("]");
- }
- //fflush(stdout);
+ for (int i = 0; i < numindeces; i++) {
+ fprintf(stderr, "ASE index %d ", i);
+ indeces[i]->print(0, stderr);
+ fprintf(stderr, "\n");
+ // printf("[");
+ // indeces[i]->print();
+ // printf("]");
+ }
+ //fflush(stdout);
//fprintf(stderr, "\n");
-
- chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr( v->vartype, v->varname, v, NULL);
- basedecl = v; // ??
- //fprintf(stderr, "%p ASE 3 basedecl = %p ", this, basedecl);
- //fprintf(stderr, "of type %s\n", basedecl->getTypeString());
+
+ chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr(v->vartype, v->varname, v, NULL);
+ basedecl = v; // ??
+ //fprintf(stderr, "%p ASE 3 basedecl = %p ", this, basedecl);
+ //fprintf(stderr, "of type %s\n", basedecl->getTypeString());
//basedecl->print(); printf("\n");
- //basedecl->dump(); printf("\n"); fflush(stdout);
- //fprintf(stderr, "basedecl varname %s\n", basedecl->varname);
-
+ //basedecl->dump(); printf("\n"); fflush(stdout);
+ //fprintf(stderr, "basedecl varname %s\n", basedecl->varname);
+
chillAST_ArraySubscriptExpr *rent = this; // parent for subnodes
-
- // these are on the top level ASE that we're creating here
+
+ // these are on the top level ASE that we're creating here
base = (chillAST_node *) DRE;
- index = indeces[ numindeces-1];
+ index = indeces[numindeces - 1];
+
+ base->setParent(this);
+ index->setParent(this);
- base->setParent( this );
- index->setParent(this);
+ for (int i = numindeces - 2; i >= 0; i--) {
- for (int i=numindeces-2; i>=0; i--) {
-
- chillAST_ArraySubscriptExpr *ASE = new chillAST_ArraySubscriptExpr( DRE, indeces[i], rent, 0);
- rent->base = ASE; //
+ chillAST_ArraySubscriptExpr *ASE = new chillAST_ArraySubscriptExpr(DRE, indeces[i], rent, 0);
+ rent->base = ASE; //
rent = ASE;
}
-
+
imwrittento = false;
- imreadfrom = false;
- //fprintf(stderr, "ASE is "); print(); printf("\n\n"); fflush(stdout);
- isFromSourceFile = true; // default
+ imreadfrom = false;
+ //fprintf(stderr, "ASE is "); print(); printf("\n\n"); fflush(stdout);
+ isFromSourceFile = true; // default
filename = NULL;
- //fprintf(stderr, "\nASE %p parent %p ", this, parent); print(0,stderr); fprintf(stderr, "\n\n");
+ //fprintf(stderr, "\nASE %p parent %p ", this, parent); print(0,stderr); fprintf(stderr, "\n\n");
}
-
-chillAST_node *chillAST_node::getEnclosingStatement( int level ) { // TODO do for subclasses?
+chillAST_node *chillAST_node::getEnclosingStatement(int level) { // TODO do for subclasses?
//fprintf(stderr, "chillAST_node::getEnclosingStatement( level %d ) node type %s\n", level, getTypeString());
//print(); printf("\n"); fflush(stdout);
// so far, user will ONLY call this directly on an array subscript expression
- if (isArraySubscriptExpr()) return parent->getEnclosingStatement( level+1);
+ if (isArraySubscriptExpr()) return parent->getEnclosingStatement(level + 1);
- if (level != 0) {
- if (isBinaryOperator() ||
- isUnaryOperator() ||
- isTernaryOperator() ||
- isReturnStmt() ||
+ if (level != 0) {
+ if (isBinaryOperator() ||
+ isUnaryOperator() ||
+ isTernaryOperator() ||
+ isReturnStmt() ||
isCallExpr()
- ) return this;
-
-
- // things that are not endpoints. recurse through parent
- if (isMemberExpr()) return parent->getEnclosingStatement( level+1 );
- if (isImplicitCastExpr()) return parent->getEnclosingStatement( level+1 );
- if (isSizeof()) return parent->getEnclosingStatement( level+1 );
- if (isCStyleCastExpr()) return parent->getEnclosingStatement( level+1 );
+ )
+ return this;
+
+
+ // things that are not endpoints. recurse through parent
+ if (isMemberExpr()) return parent->getEnclosingStatement(level + 1);
+ if (isImplicitCastExpr()) return parent->getEnclosingStatement(level + 1);
+ if (isSizeof()) return parent->getEnclosingStatement(level + 1);
+ if (isCStyleCastExpr()) return parent->getEnclosingStatement(level + 1);
return NULL;
}
- fprintf(stderr, "getEnclosingStatement() level %d type %s, returning NULL\n", level, getTypeString());
- segfault();
+ fprintf(stderr, "getEnclosingStatement() level %d type %s, returning NULL\n", level, getTypeString());
+ exit(-1);
return NULL;
}
-
-void chillAST_ArraySubscriptExpr::gatherIndeces(std::vector<chillAST_node*>&ind) {
- if (base->isArraySubscriptExpr()) ((chillAST_ArraySubscriptExpr *)base)->gatherIndeces( ind );
- ind.push_back( index );
+void chillAST_ArraySubscriptExpr::gatherIndeces(std::vector<chillAST_node *> &ind) {
+ if (base->isArraySubscriptExpr()) ((chillAST_ArraySubscriptExpr *) base)->gatherIndeces(ind);
+ ind.push_back(index);
}
-
-void chillAST_ArraySubscriptExpr::dump( int indent, FILE *fp ) {
+void chillAST_ArraySubscriptExpr::dump(int indent, FILE *fp) {
// fprintf(stderr, "\n%p chillAST_ArraySubscriptExpr::dump() basedecl %p\n", basedecl);
-
+
char *local;
if (basedecl && basedecl->vartype) {
- local = strdup( basedecl->vartype );
- }
- else {
- fprintf(stderr, "%p chillAST_ArraySubscriptExpr::dump(), no basedecl ???\n",this);
+ local = strdup(basedecl->vartype);
+ } else {
+ fprintf(stderr, "%p chillAST_ArraySubscriptExpr::dump(), no basedecl ???\n", this);
local = strdup("");
- //fprintf(stderr, "base is "); base->dump(); printf("\n"); base->print(); printf("\n"); fflush(stdout);
+ //fprintf(stderr, "base is "); base->dump(); printf("\n"); base->print(); printf("\n"); fflush(stdout);
//print(); printf("\n"); fflush(stdout);
}
@@ -2929,811 +2888,819 @@ void chillAST_ArraySubscriptExpr::dump( int indent, FILE *fp ) {
chillindent(indent, fp);
//fprintf(fp, "(ArraySubscriptExpr '%s' ", local);
- if (basedecl) {
- //fprintf(stderr, " chillAST_ArraySubscriptExpr::dump() basedecl is of type %s\n", basedecl->getTypeString());
- fprintf(fp, "(ArraySubscriptExpr (%s) '%s' ", basedecl->varname, local);
- }
- else fprintf(stderr, " chillAST_ArraySubscriptExpr::dump() has no basedecl\n");
+ if (basedecl) {
+ //fprintf(stderr, " chillAST_ArraySubscriptExpr::dump() basedecl is of type %s\n", basedecl->getTypeString());
+ fprintf(fp, "(ArraySubscriptExpr (%s) '%s' ", basedecl->varname, local);
+ } else fprintf(stderr, " chillAST_ArraySubscriptExpr::dump() has no basedecl\n");
free(local);
- if (imwrittento) {
- if (imreadfrom) fprintf(fp, "lvalue AND rvalue\n");
- else fprintf(fp, "lvalue\n");
- }
- else fprintf(fp, "rvalue\n");
- base->dump( indent+1, fp );
- index->dump(indent+1, fp);
+ if (imwrittento) {
+ if (imreadfrom) fprintf(fp, "lvalue AND rvalue\n");
+ else fprintf(fp, "lvalue\n");
+ } else fprintf(fp, "rvalue\n");
+ base->dump(indent + 1, fp);
+ index->dump(indent + 1, fp);
chillindent(indent, fp);
fprintf(fp, ")\n");
- fflush(fp);
+ fflush(fp);
}
-
-void chillAST_ArraySubscriptExpr::print( int indent, FILE *fp ) {
- base->print( indent, fp );
+void chillAST_ArraySubscriptExpr::print(int indent, FILE *fp) {
+ base->print(indent, fp);
fprintf(fp, "[");
- index->print(0, fp);
+ index->print(0, fp);
fprintf(fp, "]");
- fflush(fp);
+ fflush(fp);
}
-char *chillAST_ArraySubscriptExpr::stringRep(int indent ) {
- fprintf(stderr, "chillAST_ArraySubscriptExpr::stringRep\n");
+char *chillAST_ArraySubscriptExpr::stringRep(int indent) {
+ fprintf(stderr, "chillAST_ArraySubscriptExpr::stringRep\n");
char *blurb;
- char *b = base->stringRep(0);
- char *i = index->stringRep(0);
+ char *b = base->stringRep(0);
+ char *i = index->stringRep(0);
// combine. shoudl be using strings. much cleaner TODO
std::string s = string(b) + "[" + string(i) + "]";
- fprintf(stderr, "ASE stringrep %s\n", s.c_str());
- return strdup( s.c_str());
-
+ fprintf(stderr, "ASE stringrep %s\n", s.c_str());
+ return strdup(s.c_str());
+
}
-void chillAST_ArraySubscriptExpr::printonly( int indent, FILE *fp ) {
- base->printonly( indent, fp );
+void chillAST_ArraySubscriptExpr::printonly(int indent, FILE *fp) {
+ base->printonly(indent, fp);
fprintf(fp, "[");
- index->printonly(0, fp);
+ index->printonly(0, fp);
fprintf(fp, "]");
- fflush(fp);
+ fflush(fp);
}
-void chillAST_ArraySubscriptExpr::print( int indent, FILE *fp ) const {
- base->print( indent, fp );
+void chillAST_ArraySubscriptExpr::print(int indent, FILE *fp) const {
+ base->print(indent, fp);
fprintf(fp, "[");
- index->print(0, fp);
+ index->print(0, fp);
fprintf(fp, "]");
- fflush(fp);
+ fflush(fp);
};
-chillAST_VarDecl *chillAST_ArraySubscriptExpr::multibase() {
+chillAST_VarDecl *chillAST_ArraySubscriptExpr::multibase() {
// return the VARDECL of the thing the subscript is an index into
//this should probably be a chillAST_node function instead of having all these ifs
- //print(); printf("\n"); fflush(stdout);
- //base->print(); printf("\n"); fflush(stdout);
- //fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase() base of type %s\n", base->getTypeString());
-
- return base->multibase();
+ //print(); printf("\n"); fflush(stdout);
+ //base->print(); printf("\n"); fflush(stdout);
+ //fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase() base of type %s\n", base->getTypeString());
+
+ return base->multibase();
// this will be used to SET basedecl
//basedecl = NULL; // do this so we don't confuse ourselves looking at uninitialized basedecl
- chillAST_node *b = base;
+ chillAST_node *b = base;
//fprintf(stderr, "base is of type %s\n", b->getTypeString());
if (!b) return NULL; // just in case ??
if (base->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) { // bad coding
- b = ((chillAST_ImplicitCastExpr*)b)->subexpr;
+ b = ((chillAST_ImplicitCastExpr *) b)->subexpr;
}
if (b->asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR) { // multidimensional array!
// recurse
- return ((chillAST_ArraySubscriptExpr *)b)->multibase();
+ return ((chillAST_ArraySubscriptExpr *) b)->multibase();
}
- if (b->asttype == CHILLAST_NODETYPE_DECLREFEXPR) return(((chillAST_DeclRefExpr*)b)->getVarDecl());
+ if (b->asttype == CHILLAST_NODETYPE_DECLREFEXPR) return (((chillAST_DeclRefExpr *) b)->getVarDecl());
-
- if (b->isBinaryOperator()) {
+
+ if (b->isBinaryOperator()) {
// presumably a dot or pointer ref that resolves to an array
chillAST_BinaryOperator *BO = (chillAST_BinaryOperator *) b;
- if ( strcmp(BO->op, ".") ) {
+ if (strcmp(BO->op, ".")) {
fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase(), UNHANDLED case:\n");
- fprintf(stderr, "base is binary operator, of type %s\n", BO->op);
+ fprintf(stderr, "base is binary operator, of type %s\n", BO->op);
exit(-1);
}
chillAST_node *l = BO->lhs;
chillAST_node *r = BO->rhs;
- printf("L %s\nR %s\n", l->getTypeString(), r->getTypeString());
- exit(-1);
+ printf("L %s\nR %s\n", l->getTypeString(), r->getTypeString());
+ exit(-1);
return NULL; // TODO do checks?
}
- if (b->isMemberExpr()) {
+ if (b->isMemberExpr()) {
//c.i[c.count] we want i member of inspector
chillAST_MemberExpr *ME = (chillAST_MemberExpr *) b;
- //fprintf(stderr, "multibase() Member Expression "); ME->print(); printf("\n"); fflush(stdout);
+ //fprintf(stderr, "multibase() Member Expression "); ME->print(); printf("\n"); fflush(stdout);
chillAST_node *n = ME->base; // WRONG want the MEMBER
//fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase() Member Expression base of type %s\n", n->getTypeString());
- //fprintf(stderr, "base is "); ME->base->dump();
+ //fprintf(stderr, "base is "); ME->base->dump();
// NEED to be able to get lowest level recorddecl or typedef from this base
- fprintf(stderr, "chillast.cc, L2315, bailing??\n");
- exit(0);
+ fprintf(stderr, "chillast.cc, L2315, bailing??\n");
+ exit(0);
- if (!n->isDeclRefExpr()) {
+ if (!n->isDeclRefExpr()) {
fprintf(stderr, "MemberExpr member is not chillAST_DeclRefExpr\n");
exit(-1);
}
- chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *)n;
+ chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) n;
n = DRE->decl;
- //fprintf(stderr, "DRE decl is of type %s\n", n->getTypeString());
- assert( n->isVarDecl() );
+ //fprintf(stderr, "DRE decl is of type %s\n", n->getTypeString());
+ assert(n->isVarDecl());
chillAST_VarDecl *vd = (chillAST_VarDecl *) n;
- vd->print(); printf("\n"); fflush(stdout);
+ vd->print();
+ printf("\n");
+ fflush(stdout);
+
+ chillAST_TypedefDecl *tdd = vd->typedefinition;
+ chillAST_RecordDecl *rd = vd->vardef;
+ //fprintf(stderr, "tdd %p rd %p\n", tdd, rd);
- chillAST_TypedefDecl *tdd = vd->typedefinition;
- chillAST_RecordDecl *rd = vd->vardef;
- //fprintf(stderr, "tdd %p rd %p\n", tdd, rd);
-
- print(); printf("\n");
- dump(); printf("\n"); fflush(stdout);
+ print();
+ printf("\n");
+ dump();
+ printf("\n");
+ fflush(stdout);
+
+ assert(tdd != NULL || rd != NULL);
- assert( tdd != NULL || rd != NULL );
-
chillAST_VarDecl *sub;
- if (tdd) sub = tdd->findSubpart( ME->member );
- if (rd) sub = rd->findSubpart( ME->member );
+ if (tdd) sub = tdd->findSubpart(ME->member);
+ if (rd) sub = rd->findSubpart(ME->member);
+
+ //fprintf(stderr, "subpart is "); sub->print(); printf("\n"); fflush(stdout);
- //fprintf(stderr, "subpart is "); sub->print(); printf("\n"); fflush(stdout);
-
- return sub; // what if the sub is an array ?? TODO
+ return sub; // what if the sub is an array ?? TODO
}
- fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase(), UNHANDLED case %s\n",
- b->getTypeString());
- print(); printf("\n"); fflush(stdout);
- fprintf(stderr, "base is: "); b->print(); printf("\n"); fflush(stdout);
- segfault();
+ fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase(), UNHANDLED case %s\n",
+ b->getTypeString());
+ print();
+ printf("\n");
+ fflush(stdout);
+ fprintf(stderr, "base is: ");
+ b->print();
+ printf("\n");
+ fflush(stdout);
+ exit(-1);
}
chillAST_node *chillAST_ArraySubscriptExpr::getIndex(int dim) {
- //fprintf(stderr, "chillAST_ArraySubscriptExpr::getIndex( %d )\n", dim);
+ //fprintf(stderr, "chillAST_ArraySubscriptExpr::getIndex( %d )\n", dim);
- chillAST_node *b = base;
+ chillAST_node *b = base;
int depth = 0;
- std::vector<chillAST_node*> ind;
+ std::vector<chillAST_node *> ind;
chillAST_node *curindex = index;
- for (;;) {
- if (b->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) b = ((chillAST_ImplicitCastExpr*)b)->subexpr;
+ for (;;) {
+ if (b->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) b = ((chillAST_ImplicitCastExpr *) b)->subexpr;
else if (b->asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR) {
- //fprintf(stderr, "base "); b->print(); fprintf(stderr, "\n");
- //fprintf(stderr, "index "); curindex->print(); fprintf(stderr, "\n");
+ //fprintf(stderr, "base "); b->print(); fprintf(stderr, "\n");
+ //fprintf(stderr, "index "); curindex->print(); fprintf(stderr, "\n");
ind.push_back(curindex);
- curindex = ((chillAST_ArraySubscriptExpr*)b)->index;
- b = ((chillAST_ArraySubscriptExpr*)b)->base;
+ curindex = ((chillAST_ArraySubscriptExpr *) b)->index;
+ b = ((chillAST_ArraySubscriptExpr *) b)->base;
depth++;
- }
- else {
- //fprintf(stderr, "base "); b->print(); fprintf(stderr, "\n");
- //fprintf(stderr, "index "); curindex->print(); fprintf(stderr, "\n");
+ } else {
+ //fprintf(stderr, "base "); b->print(); fprintf(stderr, "\n");
+ //fprintf(stderr, "index "); curindex->print(); fprintf(stderr, "\n");
//fprintf(stderr, "stopping at base type %s\n", b->getTypeString());
ind.push_back(curindex);
- break;
+ break;
}
}
//fprintf(stderr, "depth %d\n", depth );
- //for (int i=0; i<ind.size(); i++) { ind[i]->print(); fprintf(stderr, "\n"); }
-
- return ind[ depth - dim ];
- /*
- if (dim == 0) return index; // single dimension
- fprintf(stderr, "DIM NOT 0\n");
- // multidimension
- chillAST_node *b = base;
+ //for (int i=0; i<ind.size(); i++) { ind[i]->print(); fprintf(stderr, "\n"); }
+
+ return ind[depth - dim];
+ /*
+ if (dim == 0) return index; // single dimension
+ fprintf(stderr, "DIM NOT 0\n");
+ // multidimension
+ chillAST_node *b = base;
if (base->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) { // bad coding
b = ((chillAST_ImplicitCastExpr*)b)->subexpr;
}
if (b->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) { // bad coding
b = ((chillAST_ImplicitCastExpr*)b)->subexpr;
}
-
+
b->print(); printf("\n"); fflush(stdout);
if (b->asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR) {
return ((chillAST_ArraySubscriptExpr *)b)->getIndex(dim-1);
}
fprintf(stderr, "chillAST_ArraySubscriptExpr::getIndex() failed\n");
- */
- exit(-1);
+ */
+ exit(-1);
}
-
-
-class chillAST_node* chillAST_ArraySubscriptExpr::constantFold() {
- //fprintf(stderr, "chillAST_ArraySubscriptExpr::constantFold()\n");
- base = base->constantFold();
+class chillAST_node *chillAST_ArraySubscriptExpr::constantFold() {
+ //fprintf(stderr, "chillAST_ArraySubscriptExpr::constantFold()\n");
+ base = base->constantFold();
index = index->constantFold();
return this;
}
-class chillAST_node* chillAST_ArraySubscriptExpr::clone() {
+class chillAST_node *chillAST_ArraySubscriptExpr::clone() {
//fprintf(stderr,"chillAST_ArraySubscriptExpr::clone() old imwrittento %d\n", imwrittento);
//fprintf(stderr, "cloning ASE %p ", this); print(0,stderr); printf(" with parent %p\n", parent); fflush(stdout);
- //fprintf(stderr, "base %p base->parent %p index %p index->parent %p\n", base, base->parent, index, index->parent);
+ //fprintf(stderr, "base %p base->parent %p index %p index->parent %p\n", base, base->parent, index, index->parent);
//fprintf(stderr, "old base "); base->print(); printf("\n"); fflush(stdout);
//fprintf(stderr, "old base "); base->dump(); printf("\n"); fflush(stdout);
- if (base->isDeclRefExpr()) {
- chillAST_VarDecl *vd = (chillAST_VarDecl *)(((chillAST_DeclRefExpr *)base)->decl);
+ if (base->isDeclRefExpr()) {
+ chillAST_VarDecl *vd = (chillAST_VarDecl *) (((chillAST_DeclRefExpr *) base)->decl);
//fprintf(stderr, "old decl "); vd->print(); printf("\n");fflush(stdout);
//fprintf(stderr, "old decl "); vd->dump(); printf("\n");fflush(stdout);
}
- chillAST_node *b = base->clone();
+ chillAST_node *b = base->clone();
//fprintf(stderr, "new base "); b->print(); printf("\n"); fflush(stdout);
//fprintf(stderr, "new base "); b->dump(); printf("\n"); fflush(stdout);
chillAST_node *i = index->clone();
//fprintf(stderr, "new index "); i->print(); printf("\n"); fflush(stdout);
-
- //if (!index->parent) {
+
+ //if (!index->parent) {
// fprintf(stderr, "ASE %p SOURCE OF CLONE INDEX %p of type %s HAS NO PARENT\n", this, index, index->getTypeString());
// fprintf(stderr, "ASE SOURCE IS "); print(0,stderr); fprintf(stderr, "\n\n");
- //}
- //fprintf(stderr, "cloning AST %p, after cloning base and index, creating a new ASE\n", this);
- chillAST_ArraySubscriptExpr *ASE = new chillAST_ArraySubscriptExpr( b, i, imwrittento, parent, uniquePtr /* ?? */ );
- //fprintf(stderr, "cloned AST will be %p with parent %p and base %p index %p\n", ASE, parent, b, i);
+ //}
+ //fprintf(stderr, "cloning AST %p, after cloning base and index, creating a new ASE\n", this);
+ chillAST_ArraySubscriptExpr *ASE = new chillAST_ArraySubscriptExpr(b, i, imwrittento, parent, uniquePtr /* ?? */ );
+ //fprintf(stderr, "cloned AST will be %p with parent %p and base %p index %p\n", ASE, parent, b, i);
ASE->imreadfrom = false; // don't know this yet
- //ASE->imreadfrom = imreadfrom; // ??
- //if (ASE->imreadfrom) {
+ //ASE->imreadfrom = imreadfrom; // ??
+ //if (ASE->imreadfrom) {
// fprintf(stderr, "in chillAST_ArraySubscriptExpr::clone(), imreadfrom is being set. \n");
- // ASE->print(); fflush(stdout); fprintf(stderr, "\n");
- //}
+ // ASE->print(); fflush(stdout); fprintf(stderr, "\n");
+ //}
//fprintf(stderr, "cloned result "); ASE->print(); printf("\n\n\n"); fflush(stdout);
- //fprintf(stderr, "ASE clone() this 0x%x clone 0x%x\n", this, ASE);
+ //fprintf(stderr, "ASE clone() this 0x%x clone 0x%x\n", this, ASE);
ASE->isFromSourceFile = isFromSourceFile;
- if (filename) ASE->filename = strdup(filename);
+ if (filename) ASE->filename = strdup(filename);
return ASE;
}
-void chillAST_ArraySubscriptExpr::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
- //fprintf(stderr, "chillAST_ArraySubscriptExpr::gatherArrayRefs setting imwrittento %d for ", writtento);
-//fprintf(stderr, "%s ", base->getTypeString());
-//base->print(); printf("\n"); fflush(stdout);
+void chillAST_ArraySubscriptExpr::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {
+ //fprintf(stderr, "chillAST_ArraySubscriptExpr::gatherArrayRefs setting imwrittento %d for ", writtento);
+//fprintf(stderr, "%s ", base->getTypeString());
+//base->print(); printf("\n"); fflush(stdout);
//fprintf(stderr, "found an array subscript. &refs 0x%x ", refs);
- if (!imwrittento) imwrittento = writtento; // may be both written and not for +=
- fflush(stdout);
+ if (!imwrittento) imwrittento = writtento; // may be both written and not for +=
+ fflush(stdout);
//fprintf(stderr, "recursing on index "); index->print(0,stderr); fprintf(stderr, "\n");
- index->gatherArrayRefs( refs, 0 ); // recurse first
- //fprintf(stderr, "adding this "); print(0,stderr); fprintf(stderr, "\n");
- //fprintf(stderr, "refs[%d] = 0x%x = ", refs.size(), this); print(); fflush(stdout);
- refs.push_back( this );
+ index->gatherArrayRefs(refs, 0); // recurse first
+ //fprintf(stderr, "adding this "); print(0,stderr); fprintf(stderr, "\n");
+ //fprintf(stderr, "refs[%d] = 0x%x = ", refs.size(), this); print(); fflush(stdout);
+ refs.push_back(this);
- //fprintf(stderr, " size now %d\n", refs.size());
+ //fprintf(stderr, " size now %d\n", refs.size());
}
-void chillAST_ArraySubscriptExpr::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- index->gatherScalarRefs( refs, 0 );
-}
+void chillAST_ArraySubscriptExpr::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ index->gatherScalarRefs(refs, 0);
+}
-void chillAST_ArraySubscriptExpr::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_ArraySubscriptExpr::gatherVarDecls()\n");
+void chillAST_ArraySubscriptExpr::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_ArraySubscriptExpr::gatherVarDecls()\n");
- base->gatherVarDecls( decls );
- index->gatherVarDecls( decls );
+ base->gatherVarDecls(decls);
+ index->gatherVarDecls(decls);
}
-void chillAST_ArraySubscriptExpr::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
+void chillAST_ArraySubscriptExpr::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
//fprintf(stderr, "chillAST_ArraySubscriptExpr::gatherScalarVarDecls()\n");
- //fprintf(stderr, "base %s index %s\n", base->getTypeString(), index->getTypeString());
- base->gatherScalarVarDecls( decls );
- index->gatherScalarVarDecls( decls );
+ //fprintf(stderr, "base %s index %s\n", base->getTypeString(), index->getTypeString());
+ base->gatherScalarVarDecls(decls);
+ index->gatherScalarVarDecls(decls);
}
-void chillAST_ArraySubscriptExpr::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
+void chillAST_ArraySubscriptExpr::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
//fprintf(stderr, "chillAST_ArraySubscriptExpr::gatherArrayVarDecls()\n");
- //fprintf(stderr, "base %s index %s\n", base->getTypeString(), index->getTypeString());
- base->gatherArrayVarDecls( decls );
- index->gatherArrayVarDecls( decls );
+ //fprintf(stderr, "base %s index %s\n", base->getTypeString(), index->getTypeString());
+ base->gatherArrayVarDecls(decls);
+ index->gatherArrayVarDecls(decls);
}
-void chillAST_ArraySubscriptExpr::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- base->gatherDeclRefExprs( refs );
- index->gatherDeclRefExprs( refs );
+void chillAST_ArraySubscriptExpr::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ base->gatherDeclRefExprs(refs);
+ index->gatherDeclRefExprs(refs);
}
-void chillAST_ArraySubscriptExpr::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- base->gatherVarUsage( decls );
- index->gatherVarUsage( decls );
+void chillAST_ArraySubscriptExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ base->gatherVarUsage(decls);
+ index->gatherVarUsage(decls);
}
-void chillAST_ArraySubscriptExpr::replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){
- base->replaceVarDecls( olddecl, newdecl );
- index->replaceVarDecls( olddecl, newdecl );
+void chillAST_ArraySubscriptExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ base->replaceVarDecls(olddecl, newdecl);
+ index->replaceVarDecls(olddecl, newdecl);
}
-void chillAST_ArraySubscriptExpr::replaceChild( chillAST_node *old, chillAST_node *newchild ) {
- //fprintf(stderr,"chillAST_ArraySubscriptExpr::replaceChild()\n");
+void chillAST_ArraySubscriptExpr::replaceChild(chillAST_node *old, chillAST_node *newchild) {
+ //fprintf(stderr,"chillAST_ArraySubscriptExpr::replaceChild()\n");
// arraysubscriptexpression doesn t really have children (should it?)
// try index ???
- if (old == index) {
+ if (old == index) {
//fprintf(stderr, "old is index\n");
index = newchild;
index->parent = this;
return;
}
-
- // try base ??? unclear if this makes sense TODO
- if (old == base) {
+
+ // try base ??? unclear if this makes sense TODO
+ if (old == base) {
//fprintf(stderr, "old is base\n");
base = newchild;
base->parent = this;
return;
}
-
- fprintf(stderr, "chillAST_ArraySubscriptExpr::replaceChild() old is not base or index\n");
- print(0,stderr); fprintf(stderr, "\nchild: ");
+
+ fprintf(stderr, "chillAST_ArraySubscriptExpr::replaceChild() old is not base or index\n");
+ print(0, stderr);
+ fprintf(stderr, "\nchild: ");
if (!old) fprintf(stderr, "oldchild NULL!\n");
- old->print(0,stderr); fprintf(stderr, "\nnew: ");
- newchild->print(0,stderr); fprintf(stderr, "\n");
- segfault(); // make easier for gdb
+ old->print(0, stderr);
+ fprintf(stderr, "\nnew: ");
+ newchild->print(0, stderr);
+ fprintf(stderr, "\n");
+ exit(-1); // make easier for gdb
};
-bool chillAST_ArraySubscriptExpr::operator!=( const chillAST_ArraySubscriptExpr &other) {
+bool chillAST_ArraySubscriptExpr::operator!=(const chillAST_ArraySubscriptExpr &other) {
bool opposite = *this == other;
return !opposite;
}
-
-bool chillAST_ArraySubscriptExpr::operator==( const chillAST_ArraySubscriptExpr &other) {
+bool chillAST_ArraySubscriptExpr::operator==(const chillAST_ArraySubscriptExpr &other) {
//fprintf(stderr, "chillAST_ArraySubscriptExpr::operator==\n");
//fprintf(stderr, "this->basedecl 0x%x other.basedecl 0x%x\n", this->basedecl, other.basedecl);
//this->basedecl->print(); printf("\n\n");
//other.basedecl->print(); printf("\n"); fflush(stdout);
- //this->print(); printf(" 0x%x == 0x%x ",this->uniquePtr, other.uniquePtr ); other.print(); printf(" ?? "); fflush(stdout);
- //if ( this->uniquePtr == other.uniquePtr) fprintf(stderr, "t\n");
- //else fprintf(stderr, "f\n");
- return this->uniquePtr == other.uniquePtr;
+ //this->print(); printf(" 0x%x == 0x%x ",this->uniquePtr, other.uniquePtr ); other.print(); printf(" ?? "); fflush(stdout);
+ //if ( this->uniquePtr == other.uniquePtr) fprintf(stderr, "t\n");
+ //else fprintf(stderr, "f\n");
+ return this->uniquePtr == other.uniquePtr;
}
-
-
-
-chillAST_MemberExpr::chillAST_MemberExpr() {
- asttype = CHILLAST_NODETYPE_MEMBEREXPR;
+chillAST_MemberExpr::chillAST_MemberExpr() {
+ asttype = CHILLAST_NODETYPE_MEMBEREXPR;
base = NULL;
member = NULL;
parent = NULL;
metacomment = NULL;
- exptype = CHILL_MEMBER_EXP_DOT;
- isFromSourceFile = true; // default
+ exptype = CHILL_MEMBER_EXP_DOT;
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_MemberExpr::chillAST_MemberExpr( chillAST_node *bas, const char *mem, chillAST_node *p, void *unique, CHILL_MEMBER_EXP_TYPE t ) {
- asttype = CHILLAST_NODETYPE_MEMBEREXPR;
+chillAST_MemberExpr::chillAST_MemberExpr(chillAST_node *bas, const char *mem, chillAST_node *p, void *unique,
+ CHILL_MEMBER_EXP_TYPE t) {
+ asttype = CHILLAST_NODETYPE_MEMBEREXPR;
base = bas;
- if (base) base->setParent( this );
- if (mem) member = strdup( mem );
+ if (base) base->setParent(this);
+ if (mem) member = strdup(mem);
parent = p;
metacomment = NULL;
uniquePtr = unique;
exptype = t;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
- return; // ignore tests below ?? TODO ??
+ return; // ignore tests below ?? TODO ??
// base needs to RESOLVE to a decl ref expr but may not BE one
// A.b . c lhs is a binop or memberexpr
- if (bas->isBinaryOperator()) {
+ if (bas->isBinaryOperator()) {
//fprintf(stderr, "checking binop to see if it resolved to a declrefexpr\n");
// cheat for now or just remove the check below
- return;
+ return;
}
- if (! ( bas->isDeclRefExpr() || bas->isArraySubscriptExpr() )) {
+ if (!(bas->isDeclRefExpr() || bas->isArraySubscriptExpr())) {
fprintf(stderr, "chillAST_MemberExpr::chillAST_MemberExpr(), base is of type %s\n", bas->getTypeString());
fprintf(stderr, "chillAST_MemberExpr::chillAST_MemberExpr(), base is not DeclRefExpr\n");
-
- base->print(); printf(".%s\n", mem); fflush(stdout);
- segfault();
+
+ base->print();
+ printf(".%s\n", mem);
+ fflush(stdout);
+ exit(-1);
}
}
-void chillAST_MemberExpr::dump( int indent, FILE *fp ) {
+void chillAST_MemberExpr::dump(int indent, FILE *fp) {
chillindent(indent, fp);
- fprintf(fp, "(MemberExpr \n");
+ fprintf(fp, "(MemberExpr \n");
- base->dump( indent+1, fp );
- chillindent(indent+1, fp);
+ base->dump(indent + 1, fp);
+ chillindent(indent + 1, fp);
if (exptype == CHILL_MEMBER_EXP_ARROW) fprintf(fp, "->");
- else fprintf(fp, ".");
-
- fprintf(fp, "%s\n", member);
+ else fprintf(fp, ".");
+
+ fprintf(fp, "%s\n", member);
chillindent(indent, fp);
fprintf(fp, ")\n");
}
-void chillAST_MemberExpr::print( int indent, FILE *fp ) {
- if (base) base->print( indent, fp );
+void chillAST_MemberExpr::print(int indent, FILE *fp) {
+ if (base) base->print(indent, fp);
else {
- chillindent( indent, fp );
- fprintf(fp, "(NULL)");
+ chillindent(indent, fp);
+ fprintf(fp, "(NULL)");
}
if (exptype == CHILL_MEMBER_EXP_ARROW) fprintf(fp, "->");
- else fprintf(fp, ".");
+ else fprintf(fp, ".");
if (member) fprintf(fp, "%s", member);
- else fprintf(fp, "(NULL)");
- fflush(fp);
+ else fprintf(fp, "(NULL)");
+ fflush(fp);
}
-void chillAST_MemberExpr::printonly( int indent, FILE *fp ) {
- base->print( indent, fp );
+void chillAST_MemberExpr::printonly(int indent, FILE *fp) {
+ base->print(indent, fp);
if (exptype == CHILL_MEMBER_EXP_ARROW) fprintf(fp, "->");
- else fprintf(fp, ".");
+ else fprintf(fp, ".");
fprintf(fp, "%s", member);
- fflush(fp);
+ fflush(fp);
}
-char *chillAST_MemberExpr::stringRep( int indent ) { // char pointer to what we'd print
- fprintf(stderr, "*chillAST_MemberExpr::stringRep()\n");
- if (base->isDeclRefExpr()) { //
- chillAST_VarDecl *vd = (chillAST_VarDecl *) ((chillAST_DeclRefExpr *)base)->decl;
- char *leak = (char *)malloc(128);
+char *chillAST_MemberExpr::stringRep(int indent) { // char pointer to what we'd print
+ fprintf(stderr, "*chillAST_MemberExpr::stringRep()\n");
+ if (base->isDeclRefExpr()) { //
+ chillAST_VarDecl *vd = (chillAST_VarDecl *) ((chillAST_DeclRefExpr *) base)->decl;
+ char *leak = (char *) malloc(128);
if (exptype == CHILL_MEMBER_EXP_ARROW) sprintf(leak, "%s->%s", vd->varname, member);
else sprintf(leak, "%s.%s", vd->varname, member);
- printstring = leak;
+ printstring = leak;
return leak;
}
- // else
- // TODO
- return strdup("chillAST_MemberExpr::getStringRep()hadanerror");
+ // else
+ // TODO
+ return strdup("chillAST_MemberExpr::getStringRep()hadanerror");
}
-class chillAST_node* chillAST_MemberExpr::constantFold() {
- base = base->constantFold();
+class chillAST_node *chillAST_MemberExpr::constantFold() {
+ base = base->constantFold();
//member = member->constantFold();
return this;
}
-class chillAST_node* chillAST_MemberExpr::clone() {
- chillAST_node *b = base->clone();
- char *m = strdup( member ); // ??
- chillAST_MemberExpr *ME = new chillAST_MemberExpr( b, m, parent, uniquePtr /* ?? */ );
+class chillAST_node *chillAST_MemberExpr::clone() {
+ chillAST_node *b = base->clone();
+ char *m = strdup(member); // ??
+ chillAST_MemberExpr *ME = new chillAST_MemberExpr(b, m, parent, uniquePtr /* ?? */ );
ME->isFromSourceFile = isFromSourceFile;
- if (filename) ME->filename = strdup(filename);
+ if (filename) ME->filename = strdup(filename);
return ME;
}
-void chillAST_MemberExpr::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
- fprintf(stderr, "chillAST_MemberExpr::gatherArrayRefs() "); print(0,stderr); fprintf(stderr, "\n");
- fprintf(stderr, "base of of type %s\n", base->getTypeString());
- base->gatherArrayRefs( refs, writtento ); //
-
+void chillAST_MemberExpr::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {
+ fprintf(stderr, "chillAST_MemberExpr::gatherArrayRefs() ");
+ print(0, stderr);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "base of of type %s\n", base->getTypeString());
+ base->gatherArrayRefs(refs, writtento); //
+
}
-void chillAST_MemberExpr::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- base->gatherScalarRefs( refs, writtento );
-}
+void chillAST_MemberExpr::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ base->gatherScalarRefs(refs, writtento);
+}
-void chillAST_MemberExpr::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- base->gatherVarDecls( decls );
+void chillAST_MemberExpr::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ base->gatherVarDecls(decls);
}
-void chillAST_MemberExpr::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- base->gatherScalarVarDecls( decls );
+void chillAST_MemberExpr::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ base->gatherScalarVarDecls(decls);
}
-void chillAST_MemberExpr::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- base->gatherArrayVarDecls( decls );
+void chillAST_MemberExpr::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ base->gatherArrayVarDecls(decls);
}
-void chillAST_MemberExpr::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- base->gatherDeclRefExprs( refs );
+void chillAST_MemberExpr::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ base->gatherDeclRefExprs(refs);
}
-void chillAST_MemberExpr::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- base->gatherVarUsage( decls );
+void chillAST_MemberExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ base->gatherVarUsage(decls);
}
-void chillAST_MemberExpr::replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){
- base->replaceVarDecls( olddecl, newdecl );
+void chillAST_MemberExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ base->replaceVarDecls(olddecl, newdecl);
}
-bool chillAST_MemberExpr::operator!=( const chillAST_MemberExpr &other) {
+bool chillAST_MemberExpr::operator!=(const chillAST_MemberExpr &other) {
bool opposite = *this == other;
return !opposite;
}
-bool chillAST_MemberExpr::operator==( const chillAST_MemberExpr &other) {
- return this->uniquePtr == other.uniquePtr;
+bool chillAST_MemberExpr::operator==(const chillAST_MemberExpr &other) {
+ return this->uniquePtr == other.uniquePtr;
}
-void chillAST_MemberExpr::replaceChild( chillAST_node *old, chillAST_node *newchild ) {
+void chillAST_MemberExpr::replaceChild(chillAST_node *old, chillAST_node *newchild) {
//printf("\nMemberExpr::replaceChild( )\n");
- //printf("old: ");
- //old->print();
- //printf("\nnew: ");
- //newchild->print();
- //printf("\n"); fflush(stdout);
+ //printf("old: ");
+ //old->print();
+ //printf("\nnew: ");
+ //newchild->print();
+ //printf("\n"); fflush(stdout);
// will pointers match??
- if (base == old) {
- //fprintf(stderr, "old matches base of MemberExpr\n");
- base = newchild;
- }
- else {
- base->replaceChild( old, newchild );
+ if (base == old) {
+ //fprintf(stderr, "old matches base of MemberExpr\n");
+ base = newchild;
+ } else {
+ base->replaceChild(old, newchild);
}
-}
+}
-chillAST_node *chillAST_MemberExpr::multibase2() { /*fprintf(stderr, "ME MB2\n" );*/ return (chillAST_node *)this; }
+chillAST_node *chillAST_MemberExpr::multibase2() { /*fprintf(stderr, "ME MB2\n" );*/ return (chillAST_node *) this; }
-chillAST_VarDecl* chillAST_MemberExpr::getUnderlyingVarDecl() {
+chillAST_VarDecl *chillAST_MemberExpr::getUnderlyingVarDecl() {
fprintf(stderr, "chillAST_MemberExpr:getUnderlyingVarDecl()\n");
- print(); printf("\n"); fflush(stdout);
- exit(-1);
+ print();
+ printf("\n");
+ fflush(stdout);
+ exit(-1);
// find the member with the correct name
-
-}
-
+}
chillAST_VarDecl *chillAST_MemberExpr::multibase() {
- //c.i[c.count] we want i member of c
- //fprintf(stderr, "ME MB\n" );
+ //c.i[c.count] we want i member of c
+ //fprintf(stderr, "ME MB\n" );
//fprintf(stderr, "chillAST_MemberExpr::multibase()\n");
//print(); printf("\n"); fflush(stdout);
//fprintf(stderr, "MemberExpr base is type %s, member %s\n", base->getTypeString(), member);
-
- //chillAST_VarDecl *vd = base->getUnderlyingVarDecl(); // this is the only thing that ever calls this ???
- chillAST_VarDecl *vd = base->multibase(); // ??
+
+ //chillAST_VarDecl *vd = base->getUnderlyingVarDecl(); // this is the only thing that ever calls this ???
+ chillAST_VarDecl *vd = base->multibase(); // ??
//fprintf(stderr, "vd "); vd->print(); printf("\n"); fflush(stdout);
-
+
chillAST_RecordDecl *rd = vd->getStructDef();
- if (!rd) {
+ if (!rd) {
fprintf(stderr, "chillAST_MemberExpr::multibase() vardecl is not a struct??\n");
- fprintf(stderr, "vd "); vd->print(); printf("\n"); fflush(stdout);
- fprintf(stderr, "vd "); vd->dump(); printf("\n"); fflush(stdout);
+ fprintf(stderr, "vd ");
+ vd->print();
+ printf("\n");
+ fflush(stdout);
+ fprintf(stderr, "vd ");
+ vd->dump();
+ printf("\n");
+ fflush(stdout);
exit(-1);
}
// OK, we have the recorddecl that defines the structure
// now find the member with the correct name
- chillAST_VarDecl *sub = rd->findSubpart( member );
+ chillAST_VarDecl *sub = rd->findSubpart(member);
//fprintf(stderr, "sub %s:\n", member);
- if (!sub) {
+ if (!sub) {
fprintf(stderr, "can't find member %s in \n", member);
- rd->print();
+ rd->print();
}
//sub->print(); printf("\n"); fflush(stdout);
//sub->dump() ; printf("\n"); fflush(stdout);
- return sub;
+ return sub;
//find vardecl of member in def of base
-
-}
-
+}
-chillAST_DeclRefExpr::chillAST_DeclRefExpr() {
- asttype = CHILLAST_NODETYPE_DECLREFEXPR;
- declarationType = strdup("UNKNOWN");
+chillAST_DeclRefExpr::chillAST_DeclRefExpr() {
+ asttype = CHILLAST_NODETYPE_DECLREFEXPR;
+ declarationType = strdup("UNKNOWN");
declarationName = strdup("NONE");
- decl = NULL;
+ decl = NULL;
parent = NULL;
metacomment = NULL;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_DeclRefExpr::chillAST_DeclRefExpr( const char *varname, chillAST_node *par ) {
- asttype = CHILLAST_NODETYPE_DECLREFEXPR;
- declarationType = strdup("UNKNOWN");
- declarationName = strdup(varname);
- decl = NULL;
- parent = par;
- isFromSourceFile = true; // default
+chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *varname, chillAST_node *par) {
+ asttype = CHILLAST_NODETYPE_DECLREFEXPR;
+ declarationType = strdup("UNKNOWN");
+ declarationName = strdup(varname);
+ decl = NULL;
+ parent = par;
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_DeclRefExpr::chillAST_DeclRefExpr( const char *vartype, const char *varname, chillAST_node *par) {
- //fprintf(stderr, "DRE::DRE 0x%x %s %s\n", this, vartype, varname );
- asttype = CHILLAST_NODETYPE_DECLREFEXPR;
- declarationType = strdup(vartype);
- declarationName = strdup(varname);
- decl = NULL;
- parent = par;
- isFromSourceFile = true; // default
+chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varname, chillAST_node *par) {
+ //fprintf(stderr, "DRE::DRE 0x%x %s %s\n", this, vartype, varname );
+ asttype = CHILLAST_NODETYPE_DECLREFEXPR;
+ declarationType = strdup(vartype);
+ declarationName = strdup(varname);
+ decl = NULL;
+ parent = par;
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_DeclRefExpr::chillAST_DeclRefExpr( const char *vartype, const char *varname, chillAST_node *d, chillAST_node *par ) {
- //fprintf(stderr, "DRE::DRE2 0x%x %s %s 0x%x\n", this, vartype, varname, d );
- asttype = CHILLAST_NODETYPE_DECLREFEXPR;
- declarationType = strdup(vartype);
- declarationName = strdup(varname);
- decl = d;
- parent = par;
- isFromSourceFile = true; // default
+chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varname, chillAST_node *d,
+ chillAST_node *par) {
+ //fprintf(stderr, "DRE::DRE2 0x%x %s %s 0x%x\n", this, vartype, varname, d );
+ asttype = CHILLAST_NODETYPE_DECLREFEXPR;
+ declarationType = strdup(vartype);
+ declarationName = strdup(varname);
+ decl = d;
+ parent = par;
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_DeclRefExpr::chillAST_DeclRefExpr( chillAST_VarDecl *vd, chillAST_node *par ){ // variable def
- //fprintf(stderr, "DRE::DRE3 (VD) 0x%x %s %s 0x%x\n", this, vd->vartype, vd->varname, vd );
-
- asttype = CHILLAST_NODETYPE_DECLREFEXPR;
- declarationType = strdup(vd->vartype);
- declarationName = strdup(vd->varname);
- decl = vd;
+chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_VarDecl *vd, chillAST_node *par) { // variable def
+ //fprintf(stderr, "DRE::DRE3 (VD) 0x%x %s %s 0x%x\n", this, vd->vartype, vd->varname, vd );
+
+ asttype = CHILLAST_NODETYPE_DECLREFEXPR;
+ declarationType = strdup(vd->vartype);
+ declarationName = strdup(vd->varname);
+ decl = vd;
parent = par;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_DeclRefExpr::chillAST_DeclRefExpr( chillAST_FunctionDecl *fd, chillAST_node *par ){ // function def
- asttype = CHILLAST_NODETYPE_DECLREFEXPR;
- declarationType = strdup(fd->returnType);
- declarationName = strdup(fd->functionName);
- decl = fd;
+chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_FunctionDecl *fd, chillAST_node *par) { // function def
+ asttype = CHILLAST_NODETYPE_DECLREFEXPR;
+ declarationType = strdup(fd->returnType);
+ declarationName = strdup(fd->functionName);
+ decl = fd;
parent = par;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
+chillAST_DeclRefExpr *buildDeclRefExpr(chillAST_VarDecl *vd) {
+ chillAST_DeclRefExpr *dre = new chillAST_DeclRefExpr(vd, NULL);
-chillAST_DeclRefExpr *buildDeclRefExpr( chillAST_VarDecl *vd) {
- chillAST_DeclRefExpr *dre = new chillAST_DeclRefExpr( vd, NULL );
-
}
-void chillAST_DeclRefExpr::print( int indent, FILE *fp) {
+void chillAST_DeclRefExpr::print(int indent, FILE *fp) {
chillindent(indent, fp);
- //fprintf(fp, "%s %s", declarationType, declarationName); // this is printing float *A
- fprintf(fp, "%s", declarationName); // this is printing A
- fflush(fp);
+ //fprintf(fp, "%s %s", declarationType, declarationName); // this is printing float *A
+ fprintf(fp, "%s", declarationName); // this is printing A
+ fflush(fp);
}
-char *chillAST_DeclRefExpr::stringRep( int indent ) {
- return strdup( declarationName );
+char *chillAST_DeclRefExpr::stringRep(int indent) {
+ return strdup(declarationName);
}
-void chillAST_DeclRefExpr::dump( int indent, FILE *fp) {
+void chillAST_DeclRefExpr::dump(int indent, FILE *fp) {
chillindent(indent, fp);
- fprintf(fp, "(DeclRefExpr '%s' ", declarationType);
+ fprintf(fp, "(DeclRefExpr '%s' ", declarationType);
chillAST_VarDecl *vd = getVarDecl();
- if (vd) {
+ if (vd) {
if (vd->isAParameter) fprintf(fp, "ParmVar ");
else fprintf(fp, "Var ");
}
- fprintf(fp, "'%s' ", declarationName); // variable or function name
+ fprintf(fp, "'%s' ", declarationName); // variable or function name
- if (chillAST_FunctionDecl *fd = getFunctionDecl()) {
- // print parameter types for functions
- fd->printParameterTypes( fp );
+ if (chillAST_FunctionDecl *fd = getFunctionDecl()) {
+ // print parameter types for functions
+ fd->printParameterTypes(fp);
}
-
- fprintf(fp, ")\n");
- fflush(fp);
+
+ fprintf(fp, ")\n");
+ fflush(fp);
}
-class chillAST_node* chillAST_DeclRefExpr::constantFold() { // can never do anything?
+class chillAST_node *chillAST_DeclRefExpr::constantFold() { // can never do anything?
return this;
}
-class chillAST_node* chillAST_DeclRefExpr::clone() {
- //fprintf(stderr, "chillAST_DeclRefExpr::clone()\n");
- chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr( declarationType, declarationName, decl, parent );
+class chillAST_node *chillAST_DeclRefExpr::clone() {
+ //fprintf(stderr, "chillAST_DeclRefExpr::clone()\n");
+ chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr(declarationType, declarationName, decl, parent);
DRE->isFromSourceFile = isFromSourceFile;
- if (filename) DRE->filename = strdup(filename);
+ if (filename) DRE->filename = strdup(filename);
return DRE;
}
-void chillAST_DeclRefExpr::gatherVarDeclsMore( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_DeclRefExpr::gatherVarDeclsMore()\n");
- decl->gatherVarDeclsMore( decls );
+void chillAST_DeclRefExpr::gatherVarDeclsMore(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_DeclRefExpr::gatherVarDeclsMore()\n");
+ decl->gatherVarDeclsMore(decls);
}
-void chillAST_DeclRefExpr::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_DeclRefExpr::gatherScalarVarDecls()\n");
- decl->gatherScalarVarDecls(decls);
- //fprintf(stderr, "now %d scalar vardecls\n", decls.size());
+void chillAST_DeclRefExpr::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_DeclRefExpr::gatherScalarVarDecls()\n");
+ decl->gatherScalarVarDecls(decls);
+ //fprintf(stderr, "now %d scalar vardecls\n", decls.size());
}
-void chillAST_DeclRefExpr::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_DeclRefExpr::gatherArrayVarDecls()\n");
- decl->gatherArrayVarDecls(decls);
- //fprintf(stderr, "now %d Array vardecls\n", decls.size());
+void chillAST_DeclRefExpr::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_DeclRefExpr::gatherArrayVarDecls()\n");
+ decl->gatherArrayVarDecls(decls);
+ //fprintf(stderr, "now %d Array vardecls\n", decls.size());
}
-void chillAST_DeclRefExpr::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- refs.push_back(this);
+void chillAST_DeclRefExpr::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ refs.push_back(this);
}
-void chillAST_DeclRefExpr::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- refs.push_back(this);
-}
+void chillAST_DeclRefExpr::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ refs.push_back(this);
+}
-void chillAST_DeclRefExpr::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_DeclRefExpr::gatherVarUsage()\n");
- for (int i=0; i<decls.size(); i++) {
- if (decls[i] == decl) {
+void chillAST_DeclRefExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_DeclRefExpr::gatherVarUsage()\n");
+ for (int i = 0; i < decls.size(); i++) {
+ if (decls[i] == decl) {
//fprintf(stderr, "decl was already there\n");
return;
}
- if (streq(declarationName, decls[i]->varname)) {
- if (streq(declarationType, decls[i]->vartype)) {
+ if (streq(declarationName, decls[i]->varname)) {
+ if (streq(declarationType, decls[i]->vartype)) {
//fprintf(stderr, "decl was already there\n");
return;
}
}
}
chillAST_VarDecl *vd = getVarDecl(); // null for functiondecl
- if (vd) decls.push_back( vd );
+ if (vd) decls.push_back(vd);
}
-
-
-void chillAST_DeclRefExpr::replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){
- //fprintf(stderr, "chillAST_DeclRefExpr::replaceVarDecls()\n");
- if (decl == olddecl) {
+void chillAST_DeclRefExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ //fprintf(stderr, "chillAST_DeclRefExpr::replaceVarDecls()\n");
+ if (decl == olddecl) {
//fprintf(stderr, "replacing old %s with %s\n", olddecl->varname, newdecl->varname);
- //fprintf(stderr, "DRE was "); print();
- decl = newdecl;
- declarationType = strdup(newdecl->vartype);
- declarationName = strdup(newdecl->varname);
- //fprintf(stderr, "\nDRE is "); print(); fprintf(stderr, "\n\n");
- }
- else {
- if (!strcmp(olddecl->varname, declarationName)) {
- //fprintf(stderr, "uhoh, chillAST_DeclRefExpr::replaceVarDecls()\n");
- decl = newdecl;
- declarationType = strdup(newdecl->vartype);
- declarationName = strdup(newdecl->varname);
+ //fprintf(stderr, "DRE was "); print();
+ decl = newdecl;
+ declarationType = strdup(newdecl->vartype);
+ declarationName = strdup(newdecl->varname);
+ //fprintf(stderr, "\nDRE is "); print(); fprintf(stderr, "\n\n");
+ } else {
+ if (!strcmp(olddecl->varname, declarationName)) {
+ //fprintf(stderr, "uhoh, chillAST_DeclRefExpr::replaceVarDecls()\n");
+ decl = newdecl;
+ declarationType = strdup(newdecl->vartype);
+ declarationName = strdup(newdecl->varname);
}
}
}
@@ -3749,797 +3716,771 @@ chillAST_VarDecl *chillAST_DeclRefExpr::multibase() {
}
-
-
-
-
-
-
-
-void chillAST_VarDecl::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_VarDecl::gatherVarDecls()\n");
- for (int i=0; i<decls.size(); i++) {
- if (decls[i] == this) {
+void chillAST_VarDecl::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_VarDecl::gatherVarDecls()\n");
+ for (int i = 0; i < decls.size(); i++) {
+ if (decls[i] == this) {
//fprintf(stderr, "decl was already there\n");
return;
}
- if (streq(decls[i]->varname, varname)) {
- if (streq(decls[i]->vartype, vartype)) {
+ if (streq(decls[i]->varname, varname)) {
+ if (streq(decls[i]->vartype, vartype)) {
//fprintf(stderr, "VarDecl (direct) decl was already there\n");
return;
}
}
}
- decls.push_back( this );
+ decls.push_back(this);
}
-void chillAST_VarDecl::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_VarDecl::gatherScalarVarDecls(), %s numdimensions %d\n", varname, numdimensions);
+void chillAST_VarDecl::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_VarDecl::gatherScalarVarDecls(), %s numdimensions %d\n", varname, numdimensions);
if (numdimensions != 0) return; // not a scalar
-
- for (int i=0; i<decls.size(); i++) {
- if (decls[i] == this) {
+
+ for (int i = 0; i < decls.size(); i++) {
+ if (decls[i] == this) {
//fprintf(stderr, "decl was already there\n");
return;
}
if (streq(decls[i]->varname, varname)) { // wrong. scoping. TODO
- if (streq(decls[i]->vartype, vartype)) {
+ if (streq(decls[i]->vartype, vartype)) {
//fprintf(stderr, "VarDecl (direct) decl was already there\n");
return;
}
}
}
- //fprintf(stderr, "adding vardecl for %s to decls\n", varname);
- decls.push_back( this );
+ //fprintf(stderr, "adding vardecl for %s to decls\n", varname);
+ decls.push_back(this);
}
-void chillAST_VarDecl::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_VarDecl::gatherScalarVarDecls(), %s numdimensions %d\n", varname, numdimensions);
+void chillAST_VarDecl::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_VarDecl::gatherScalarVarDecls(), %s numdimensions %d\n", varname, numdimensions);
if (numdimensions == 0) return; // not an array
-
- for (int i=0; i<decls.size(); i++) {
- if (decls[i] == this) {
+
+ for (int i = 0; i < decls.size(); i++) {
+ if (decls[i] == this) {
//fprintf(stderr, "decl was already there\n");
return;
}
if (streq(decls[i]->varname, varname)) { // wrong. scoping. TODO
- if (streq(decls[i]->vartype, vartype)) {
+ if (streq(decls[i]->vartype, vartype)) {
//fprintf(stderr, "VarDecl (direct) decl was already there\n");
return;
}
}
}
- //fprintf(stderr, "adding vardecl for %s to decls\n", varname);
- decls.push_back( this );
+ //fprintf(stderr, "adding vardecl for %s to decls\n", varname);
+ decls.push_back(this);
}
+chillAST_node *chillAST_VarDecl::constantFold() { return this; }
-chillAST_node *chillAST_VarDecl::constantFold() { return this; }
-
-chillAST_node* chillAST_VarDecl::clone() {
- fprintf(stderr, "\nchillAST_VarDecl::clone() cloning vardecl for %s\n", varname);
+chillAST_node *chillAST_VarDecl::clone() {
+ fprintf(stderr, "\nchillAST_VarDecl::clone() cloning vardecl for %s\n", varname);
if (isAParameter) fprintf(stderr, "old vardecl IS a parameter\n");
//else fprintf(stderr, "old vardecl IS NOT a parameter\n");
- chillAST_VarDecl *vd = new chillAST_VarDecl( vartype, strdup(varname), arraypart, NULL); // NULL so we don't add the variable AGAIN to the (presumably) function
-
+ chillAST_VarDecl *vd = new chillAST_VarDecl(vartype, strdup(varname), arraypart,
+ NULL); // NULL so we don't add the variable AGAIN to the (presumably) function
+
vd->typedefinition = typedefinition;
- vd->vardef = vardef; // perhaps should not do this TODO
+ vd->vardef = vardef; // perhaps should not do this TODO
//vd->isStruct = (vardef != NULL); // ??
-
- vd->underlyingtype = strdup(underlyingtype);
+
+ vd->underlyingtype = strdup(underlyingtype);
vd->arraysizes = NULL;
- vd->knownArraySizes = knownArraySizes;
+ vd->knownArraySizes = knownArraySizes;
vd->numdimensions = numdimensions;
vd->arraypointerpart = NULL;
- if (arraypart != NULL && NULL!=arraysizes) { // !strcmp(arraypart, "")) {
+ if (arraypart != NULL && NULL != arraysizes) { // !strcmp(arraypart, "")) {
//fprintf(stderr, "in chillAST_VarDecl::clone(), cloning the array info\n");
//fprintf(stderr, "numdimensions %d arraysizes 0x%x\n", numdimensions, arraysizes) ;
vd->numdimensions = numdimensions;
- if (arraysizes) {
- vd->arraysizes = (int *)malloc( sizeof(int *) * numdimensions );
- for (int i=0; i< numdimensions; i++) {
- //fprintf(stderr, "i %d\n", i);
- vd->arraysizes[i] = arraysizes[i];
+ if (arraysizes) {
+ vd->arraysizes = (int *) malloc(sizeof(int *) * numdimensions);
+ for (int i = 0; i < numdimensions; i++) {
+ //fprintf(stderr, "i %d\n", i);
+ vd->arraysizes[i] = arraysizes[i];
}
}
}
- if ( arraypointerpart ) {
- //fprintf(stderr, "copying arraypointerpart\n");
- vd->arraypointerpart = strdup( arraypointerpart);
+ if (arraypointerpart) {
+ //fprintf(stderr, "copying arraypointerpart\n");
+ vd->arraypointerpart = strdup(arraypointerpart);
}
- vd->isStruct = this->isStruct;
- //vd->insideAStruct = this->insideAStruct;
+ vd->isStruct = this->isStruct;
+ //vd->insideAStruct = this->insideAStruct;
- //if (vd->isStruct) fprintf(stderr, "vardecl::clone() %s is a struct\n", varname);
- //else fprintf(stderr, "vardecl::clone() %s is NOT a struct\n", varname);
+ //if (vd->isStruct) fprintf(stderr, "vardecl::clone() %s is a struct\n", varname);
+ //else fprintf(stderr, "vardecl::clone() %s is NOT a struct\n", varname);
- vd->knownArraySizes = this->knownArraySizes;
+ vd->knownArraySizes = this->knownArraySizes;
vd->isFromSourceFile = isFromSourceFile;
- if (filename) vd->filename = strdup(filename);
+ if (filename) vd->filename = strdup(filename);
return vd;
}
-void chillAST_VarDecl::splitarraypart() {
+void chillAST_VarDecl::splitarraypart() {
if (arraypart) CHILL_DEBUG_PRINT("%s\n", arraypart);
// split arraypart into (leading??) asterisks and known sizes [1][2][3]
- if (!arraypart || // NULL
+ if (!arraypart || // NULL
(arraypart && (*arraypart == '\0'))) { // or empty string
// parts are both empty string
if (arraypointerpart) free(arraypointerpart);
arraypointerpart = strdup("");
if (arraysetpart) free(arraysetpart);
- arraysetpart = strdup("");
+ arraysetpart = strdup("");
return;
}
// arraypart exists and is not empty
int asteriskcount = 0;
int fixedcount = 0;
- for ( int i=0; i<strlen(arraypart); i++) {
- if (arraypart[i] == '*') {
+ for (int i = 0; i < strlen(arraypart); i++) {
+ if (arraypart[i] == '*') {
if (fixedcount) {
CHILL_ERROR("illegal vardecl arraypart: '%s'\n", arraypart);
- segfault();
+ exit(-1);
exit(-1);
}
asteriskcount++;
- }
- else { // remainder is fixed?
- fixedcount++;
+ } else { // remainder is fixed?
+ fixedcount++;
// check for brackets and digits only? TODO
}
}
- arraypointerpart = (char *) calloc( asteriskcount+1, sizeof(char));
- arraysetpart = (char *) calloc( fixedcount+1, sizeof(char));
+ arraypointerpart = (char *) calloc(asteriskcount + 1, sizeof(char));
+ arraysetpart = (char *) calloc(fixedcount + 1, sizeof(char));
char *ptr = arraypart;
- for ( int i=0; i<asteriskcount; i++) arraypointerpart[i] = *ptr++;
- for ( int i=0; i<fixedcount; i++) arraysetpart[i] = *ptr++;
+ for (int i = 0; i < asteriskcount; i++) arraypointerpart[i] = *ptr++;
+ for (int i = 0; i < fixedcount; i++) arraysetpart[i] = *ptr++;
- //fprintf(stderr, "%s = %s + %s\n", arraypart, arraypointerpart, arraysetpart);
+ //fprintf(stderr, "%s = %s + %s\n", arraypart, arraypointerpart, arraysetpart);
}
-
-
-
-
-chillAST_IntegerLiteral::chillAST_IntegerLiteral(int val, chillAST_node *par){
- value = val;
+chillAST_IntegerLiteral::chillAST_IntegerLiteral(int val, chillAST_node *par) {
+ value = val;
asttype = CHILLAST_NODETYPE_INTEGERLITERAL;
parent = par;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-void chillAST_IntegerLiteral::print( int indent, FILE *fp) {
+void chillAST_IntegerLiteral::print(int indent, FILE *fp) {
chillindent(indent, fp);
fprintf(fp, "%d", value);
- fflush(fp);
+ fflush(fp);
}
-void chillAST_IntegerLiteral::dump( int indent, FILE *fp) {
+void chillAST_IntegerLiteral::dump(int indent, FILE *fp) {
chillindent(indent, fp);
fprintf(fp, "(IntegerLiteral 'int' %d)\n", value);
- fflush(fp);
+ fflush(fp);
}
+class chillAST_node *chillAST_IntegerLiteral::constantFold() { return this; } // can never do anything
-class chillAST_node* chillAST_IntegerLiteral::constantFold() { return this; } // can never do anything
+class chillAST_node *chillAST_IntegerLiteral::clone() {
-class chillAST_node* chillAST_IntegerLiteral::clone() {
-
- chillAST_IntegerLiteral *IL = new chillAST_IntegerLiteral( value, parent );
- IL->isFromSourceFile = isFromSourceFile;
- if (filename) IL->filename = strdup(filename);
- return IL;
+ chillAST_IntegerLiteral *IL = new chillAST_IntegerLiteral(value, parent);
+ IL->isFromSourceFile = isFromSourceFile;
+ if (filename) IL->filename = strdup(filename);
+ return IL;
}
-
-chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, chillAST_node *par){
- value = val;
+
+chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, chillAST_node *par) {
+ value = val;
precision = 1;
- float0double1 = 0; // which is live!
- allthedigits = NULL;
+ float0double1 = 0; // which is live!
+ allthedigits = NULL;
asttype = CHILLAST_NODETYPE_FLOATINGLITERAL;
parent = par;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, chillAST_node *par){
- doublevalue = val;
+chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, chillAST_node *par) {
+ doublevalue = val;
precision = 2;
- float0double1 = 1; // which is live!
- allthedigits = NULL;
+ float0double1 = 1; // which is live!
+ allthedigits = NULL;
asttype = CHILLAST_NODETYPE_FLOATINGLITERAL;
parent = par;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, chillAST_node *par){
- value = val;
+chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, chillAST_node *par) {
+ value = val;
precision = 1;
- float0double1 = 0; // which is live!
- precision = precis; //
- allthedigits = NULL;
+ float0double1 = 0; // which is live!
+ precision = precis; //
+ allthedigits = NULL;
asttype = CHILLAST_NODETYPE_FLOATINGLITERAL;
parent = par;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, int precis, chillAST_node *par){
- doublevalue = val;
- float0double1 = 1; // which is live!
- precision = precis; //
- allthedigits = NULL;
+chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, int precis, chillAST_node *par) {
+ doublevalue = val;
+ float0double1 = 1; // which is live!
+ precision = precis; //
+ allthedigits = NULL;
asttype = CHILLAST_NODETYPE_FLOATINGLITERAL;
parent = par;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, const char *printthis, chillAST_node *par){
- value = val;
- float0double1 = 0; // which is live!
+chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, const char *printthis, chillAST_node *par) {
+ value = val;
+ float0double1 = 0; // which is live!
precision = 1;
allthedigits = NULL;
- if (printthis) allthedigits = strdup( printthis );
- //fprintf(stderr, "\nfloatingliteral allthedigits = '%s'\n", allthedigits);
+ if (printthis) allthedigits = strdup(printthis);
+ //fprintf(stderr, "\nfloatingliteral allthedigits = '%s'\n", allthedigits);
asttype = CHILLAST_NODETYPE_FLOATINGLITERAL;
parent = par;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, const char *printthis, chillAST_node *par){
- value = val;
- float0double1 = 0; // which is live!
- precision = precis; // but value is a float?? TODO
+chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, const char *printthis, chillAST_node *par) {
+ value = val;
+ float0double1 = 0; // which is live!
+ precision = precis; // but value is a float?? TODO
allthedigits = NULL;
- if (printthis) {
- //fprintf(stderr, "\nchillAST_FloatingLiteral constructor, printthis ");
- //fprintf(stderr, "%p\n", printthis);
- allthedigits = strdup( printthis );
+ if (printthis) {
+ //fprintf(stderr, "\nchillAST_FloatingLiteral constructor, printthis ");
+ //fprintf(stderr, "%p\n", printthis);
+ allthedigits = strdup(printthis);
}
- //fprintf(stderr, "\nfloatingliteral allthedigits = '%s'\n", allthedigits);
+ //fprintf(stderr, "\nfloatingliteral allthedigits = '%s'\n", allthedigits);
asttype = CHILLAST_NODETYPE_FLOATINGLITERAL;
parent = par;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_FloatingLiteral::chillAST_FloatingLiteral( chillAST_FloatingLiteral *old ) {
- //fprintf(stderr, "chillAST_FloatingLiteral::chillAST_FloatingLiteral( old ) allthedigits %p\n", old->allthedigits);
+chillAST_FloatingLiteral::chillAST_FloatingLiteral(chillAST_FloatingLiteral *old) {
+ //fprintf(stderr, "chillAST_FloatingLiteral::chillAST_FloatingLiteral( old ) allthedigits %p\n", old->allthedigits);
asttype = CHILLAST_NODETYPE_FLOATINGLITERAL;
- value = old->value;
- doublevalue = old->doublevalue;
- float0double1 = old->float0double1;
+ value = old->value;
+ doublevalue = old->doublevalue;
+ float0double1 = old->float0double1;
allthedigits = NULL;
- if (old->allthedigits) allthedigits = strdup(old->allthedigits);
- precision = old->precision;
- isFromSourceFile = true; // default
+ if (old->allthedigits) allthedigits = strdup(old->allthedigits);
+ precision = old->precision;
+ isFromSourceFile = true; // default
filename = NULL;
}
-
-void chillAST_FloatingLiteral::print( int indent, FILE *fp) {
+void chillAST_FloatingLiteral::print(int indent, FILE *fp) {
chillindent(indent, fp);
//fprintf(fp, "%f", value);
// attempt to be more like rose output
- char output[1024]; // warning, hardcoded
+ char output[1024]; // warning, hardcoded
if (allthedigits != NULL) {
- strcpy(output, allthedigits ); // if they have specified 100 digits of pi, give 'em 100 digits
- //fprintf(stderr, "floatingliteral allthedigits = '%s'\n", allthedigits);
- }
- else {
- if (float0double1 == 0) sprintf(output, "%f", value);
+ strcpy(output, allthedigits); // if they have specified 100 digits of pi, give 'em 100 digits
+ //fprintf(stderr, "floatingliteral allthedigits = '%s'\n", allthedigits);
+ } else {
+ if (float0double1 == 0) sprintf(output, "%f", value);
else sprintf(output, "%f", doublevalue);
-
+
// next part to avoid printing 123.4560000000000000000000000000
char *dot = index(output, '.');
- if (dot) {
+ if (dot) {
char *end = output + strlen(output);
char *onechar;
char *lastnonzero = dot;
- for (onechar = output; onechar < end; onechar ++) {
+ for (onechar = output; onechar < end; onechar++) {
if (*onechar != '0') lastnonzero = onechar;
}
-
- if (lastnonzero == dot)
+
+ if (lastnonzero == dot)
lastnonzero[2] = '\0'; // may be after end of string, but that should be OK
else lastnonzero[1] = '\0'; // may be after end of string, but that should be OK
}
}
- if (precision == 1) {
+ if (precision == 1) {
int len = strlen(output);
output[len] = 'f'; // explicit single precision
- output[len+1] = '\0';
+ output[len + 1] = '\0';
}
- fprintf(fp, "%s", output);
- fflush(fp);
+ fprintf(fp, "%s", output);
+ fflush(fp);
}
-void chillAST_FloatingLiteral::dump( int indent, FILE *fp) {
+void chillAST_FloatingLiteral::dump(int indent, FILE *fp) {
chillindent(indent, fp);
// 2x2 cases ???
- if (precision == 1)
- fprintf(fp, "(FloatingLiteral 'float' ");
- else fprintf(fp, "(FloatingLiteral 'double' ");
+ if (precision == 1)
+ fprintf(fp, "(FloatingLiteral 'float' ");
+ else fprintf(fp, "(FloatingLiteral 'double' ");
- if (float0double1 == 0) fprintf(fp, "%f)\n", value); // %f gives enough digits
- else fprintf(fp, "%f)\n", doublevalue); // %f gives enough digits
- fflush(fp);
+ if (float0double1 == 0) fprintf(fp, "%f)\n", value); // %f gives enough digits
+ else fprintf(fp, "%f)\n", doublevalue); // %f gives enough digits
+ fflush(fp);
}
-chillAST_node* chillAST_FloatingLiteral::constantFold() { return this; }; // NOOP
+chillAST_node *chillAST_FloatingLiteral::constantFold() { return this; }; // NOOP
-chillAST_node* chillAST_FloatingLiteral::clone() {
- //fprintf(stderr, "chillAST_FloatingLiteral::clone() ");
- //fprintf(stderr, "allthedigits %p \n", allthedigits);
- chillAST_FloatingLiteral *newone = new chillAST_FloatingLiteral( this );
+chillAST_node *chillAST_FloatingLiteral::clone() {
+ //fprintf(stderr, "chillAST_FloatingLiteral::clone() ");
+ //fprintf(stderr, "allthedigits %p \n", allthedigits);
+ chillAST_FloatingLiteral *newone = new chillAST_FloatingLiteral(this);
- newone->isFromSourceFile = isFromSourceFile;
- if (filename) newone->filename = strdup(filename);
- //print(); printf(" "); newone->print(); printf("\n"); fflush(stdout);
+ newone->isFromSourceFile = isFromSourceFile;
+ if (filename) newone->filename = strdup(filename);
+ //print(); printf(" "); newone->print(); printf("\n"); fflush(stdout);
return newone;
}
-
-bool chillAST_FloatingLiteral::isSameAs( chillAST_node *other ){
+
+bool chillAST_FloatingLiteral::isSameAs(chillAST_node *other) {
if (!other->isFloatingLiteral()) return false;
- chillAST_FloatingLiteral *o = (chillAST_FloatingLiteral *)other;
+ chillAST_FloatingLiteral *o = (chillAST_FloatingLiteral *) other;
// should we care about single vs double precision?
if (float0double1 != o->float0double1) return false;
- if (float0double1 == 0) {
+ if (float0double1 == 0) {
return value == o->value; // WARNING, comparing floats with ==
}
return doublevalue == o->doublevalue; // WARNING, comparing doubless with ==
-}
-
-
-
+}
-chillAST_UnaryOperator::chillAST_UnaryOperator( const char *oper, bool pre, chillAST_node *sub, chillAST_node *par ) {
+chillAST_UnaryOperator::chillAST_UnaryOperator(const char *oper, bool pre, chillAST_node *sub, chillAST_node *par) {
op = strdup(oper);
prefix = pre;
- subexpr = sub;
- subexpr->setParent( this );
- asttype = CHILLAST_NODETYPE_UNARYOPERATOR;
- parent = par;
- isFromSourceFile = true; // default
+ subexpr = sub;
+ subexpr->setParent(this);
+ asttype = CHILLAST_NODETYPE_UNARYOPERATOR;
+ parent = par;
+ isFromSourceFile = true; // default
filename = NULL;
}
-void chillAST_UnaryOperator::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ) {
- subexpr->gatherArrayRefs( refs, isAssignmentOp()); //
+void chillAST_UnaryOperator::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {
+ subexpr->gatherArrayRefs(refs, isAssignmentOp()); //
}
-
-void chillAST_UnaryOperator::print( int indent, FILE *fp) {
+void chillAST_UnaryOperator::print(int indent, FILE *fp) {
bool needparens = false;
if (subexpr->isNotLeaf()) needparens = true; // may get more complicated
- chillindent( indent, fp); // will this ever be invoked?
- if (prefix) fprintf(fp, "%s", op);
+ chillindent(indent, fp); // will this ever be invoked?
+ if (prefix) fprintf(fp, "%s", op);
if (needparens) fprintf(fp, "(");
- subexpr->print( 0, fp );
- if (needparens) fprintf(fp, ")");
- if (!prefix) fprintf(fp, "%s", op);
- fflush(fp);
+ subexpr->print(0, fp);
+ if (needparens) fprintf(fp, ")");
+ if (!prefix) fprintf(fp, "%s", op);
+ fflush(fp);
}
-void chillAST_UnaryOperator::dump( int indent, FILE *fp) {
- chillindent( indent, fp);
+void chillAST_UnaryOperator::dump(int indent, FILE *fp) {
+ chillindent(indent, fp);
fprintf(fp, "(UnaryOperator ");
- if (prefix) fprintf(fp, "prefix ");
+ if (prefix) fprintf(fp, "prefix ");
else fprintf(fp, "postfix ");
fprintf(fp, "%s\n", op);
- subexpr->dump(indent+1, fp);
+ subexpr->dump(indent + 1, fp);
- chillindent( indent, fp);
+ chillindent(indent, fp);
fprintf(fp, ")\n");
}
-void chillAST_UnaryOperator::gatherVarLHSUsage( vector<chillAST_VarDecl*> &decls ) {
+void chillAST_UnaryOperator::gatherVarLHSUsage(vector<chillAST_VarDecl *> &decls) {
if ((!strcmp("++", op)) || (!strcmp("--", op))) {
- subexpr->gatherVarUsage( decls ); // do all unary modify the subexpr? (no, - )
+ subexpr->gatherVarUsage(decls); // do all unary modify the subexpr? (no, - )
}
}
-
-chillAST_node* chillAST_UnaryOperator::constantFold() {
+chillAST_node *chillAST_UnaryOperator::constantFold() {
//fprintf(stderr, "chillAST_UnaryOperator::constantFold() ");
- //print(); fprintf(stderr, "\n");
+ //print(); fprintf(stderr, "\n");
subexpr = subexpr->constantFold();
chillAST_node *returnval = this;
if (subexpr->isConstant()) {
//fprintf(stderr, "unary op folding constants\n");
//print(0,stderr); fprintf(stderr, "\n");
-
- if (streq(op, "-")) {
+
+ if (streq(op, "-")) {
if (subexpr->isIntegerLiteral()) {
- int intval = ((chillAST_IntegerLiteral*)subexpr)->value;
- chillAST_IntegerLiteral *I = new chillAST_IntegerLiteral( -intval, parent);
+ int intval = ((chillAST_IntegerLiteral *) subexpr)->value;
+ chillAST_IntegerLiteral *I = new chillAST_IntegerLiteral(-intval, parent);
returnval = I;
//fprintf(stderr, "integer -%d becomes %d\n", intval, I->value);
- }
- else {
- chillAST_FloatingLiteral *FL = (chillAST_FloatingLiteral*)subexpr;
- chillAST_FloatingLiteral *F = new chillAST_FloatingLiteral( FL ); // clone
+ } else {
+ chillAST_FloatingLiteral *FL = (chillAST_FloatingLiteral *) subexpr;
+ chillAST_FloatingLiteral *F = new chillAST_FloatingLiteral(FL); // clone
F->parent = FL->parent;
F->value = -F->value;
F->doublevalue = -F->doublevalue;
-
- F->print(); fprintf(stderr, "\n");
-
+
+ F->print();
+ fprintf(stderr, "\n");
+
returnval = F;
}
- }
- else fprintf(stderr, "can't fold op '%s' yet\n", op);
- }
+ } else fprintf(stderr, "can't fold op '%s' yet\n", op);
+ }
return returnval;
}
-class chillAST_node* chillAST_UnaryOperator::clone() {
- chillAST_UnaryOperator *UO = new chillAST_UnaryOperator( op, prefix, subexpr->clone(), parent );
- UO->isFromSourceFile = isFromSourceFile;
- if (filename) UO->filename = strdup(filename);
- return UO;
+class chillAST_node *chillAST_UnaryOperator::clone() {
+ chillAST_UnaryOperator *UO = new chillAST_UnaryOperator(op, prefix, subexpr->clone(), parent);
+ UO->isFromSourceFile = isFromSourceFile;
+ if (filename) UO->filename = strdup(filename);
+ return UO;
}
-void chillAST_UnaryOperator::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherVarDecls( decls );
+void chillAST_UnaryOperator::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherVarDecls(decls);
}
-void chillAST_UnaryOperator::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherScalarVarDecls( decls );
+void chillAST_UnaryOperator::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherScalarVarDecls(decls);
}
-void chillAST_UnaryOperator::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherArrayVarDecls( decls );
+void chillAST_UnaryOperator::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherArrayVarDecls(decls);
}
-void chillAST_UnaryOperator::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- subexpr->gatherDeclRefExprs( refs );
+void chillAST_UnaryOperator::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ subexpr->gatherDeclRefExprs(refs);
}
-void chillAST_UnaryOperator::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherVarUsage( decls );
+void chillAST_UnaryOperator::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherVarUsage(decls);
}
- void chillAST_UnaryOperator::replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
- subexpr->replaceVarDecls( olddecl, newdecl );
- }
+void chillAST_UnaryOperator::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ subexpr->replaceVarDecls(olddecl, newdecl);
+}
-int chillAST_UnaryOperator::evalAsInt() {
+int chillAST_UnaryOperator::evalAsInt() {
if (!strcmp("+", op)) return subexpr->evalAsInt();
if (!strcmp("-", op)) return -subexpr->evalAsInt();
if (!strcmp("++", op)) return 1 + subexpr->evalAsInt();
if (!strcmp("--", op)) return subexpr->evalAsInt() - 1;
- fprintf(stderr, "chillAST_UnaryOperator::evalAsInt() unhandled op '%s'\n", op);
- segfault();
+ fprintf(stderr, "chillAST_UnaryOperator::evalAsInt() unhandled op '%s'\n", op);
+ exit(-1);
}
-bool chillAST_UnaryOperator::isSameAs( chillAST_node *other ){
+bool chillAST_UnaryOperator::isSameAs(chillAST_node *other) {
if (!other->isUnaryOperator()) return false;
- chillAST_UnaryOperator *o = (chillAST_UnaryOperator *)other;
- if (strcmp(op, o->op)) return false; // different operators
- return subexpr->isSameAs( o->subexpr ); // recurse
+ chillAST_UnaryOperator *o = (chillAST_UnaryOperator *) other;
+ if (strcmp(op, o->op)) return false; // different operators
+ return subexpr->isSameAs(o->subexpr); // recurse
}
-chillAST_ImplicitCastExpr::chillAST_ImplicitCastExpr( chillAST_node *sub, chillAST_node *par ) {
+chillAST_ImplicitCastExpr::chillAST_ImplicitCastExpr(chillAST_node *sub, chillAST_node *par) {
subexpr = sub;
- subexpr->setParent( this );
- asttype = CHILLAST_NODETYPE_IMPLICITCASTEXPR;
- parent = par;
+ subexpr->setParent(this);
+ asttype = CHILLAST_NODETYPE_IMPLICITCASTEXPR;
+ parent = par;
//fprintf(stderr, "ImplicitCastExpr 0x%x has subexpr 0x%x", this, subexpr);
- //fprintf(stderr, " of type %s\n", subexpr->getTypeString());
- isFromSourceFile = true; // default
+ //fprintf(stderr, " of type %s\n", subexpr->getTypeString());
+ isFromSourceFile = true; // default
filename = NULL;
}
-void chillAST_ImplicitCastExpr::print( int indent, FILE *fp) {
+void chillAST_ImplicitCastExpr::print(int indent, FILE *fp) {
// No need to print anything, simply forward to the sub expression.
- subexpr->print( indent, fp );
- fflush(fp);
+ subexpr->print(indent, fp);
+ fflush(fp);
};
-void chillAST_ImplicitCastExpr::printonly( int indent, FILE *fp) {
+void chillAST_ImplicitCastExpr::printonly(int indent, FILE *fp) {
// No need to print anything, simply forward to the sub expression.
- subexpr->printonly( indent, fp );
- fflush(fp);
+ subexpr->printonly(indent, fp);
+ fflush(fp);
};
-void chillAST_ImplicitCastExpr::replaceChild( chillAST_node *old, chillAST_node *newchild ){
+void chillAST_ImplicitCastExpr::replaceChild(chillAST_node *old, chillAST_node *newchild) {
if (subexpr == old) { // should be the case for this to get called
subexpr = newchild;
- subexpr->setParent( this );
+ subexpr->setParent(this);
//old->parent = NULL;
return;
}
fprintf(stderr, "chillAST_ImplicitCastExpr::replaceChild() called with bad 'old'\n");
- exit(-1); // ??
+ exit(-1); // ??
}
-class chillAST_node* chillAST_ImplicitCastExpr::constantFold() {
+class chillAST_node *chillAST_ImplicitCastExpr::constantFold() {
chillAST_node *child = subexpr->constantFold();
- child->setParent( parent ) ; // remove myself !! probably a bad idea. TODO
- return child;
+ child->setParent(parent); // remove myself !! probably a bad idea. TODO
+ return child;
}
-class chillAST_node* chillAST_ImplicitCastExpr::clone() {
- chillAST_ImplicitCastExpr *ICE = new chillAST_ImplicitCastExpr( subexpr->clone(), parent);
- ICE->isFromSourceFile = isFromSourceFile;
- if (filename) ICE->filename = strdup(filename);
- return ICE;
+class chillAST_node *chillAST_ImplicitCastExpr::clone() {
+ chillAST_ImplicitCastExpr *ICE = new chillAST_ImplicitCastExpr(subexpr->clone(), parent);
+ ICE->isFromSourceFile = isFromSourceFile;
+ if (filename) ICE->filename = strdup(filename);
+ return ICE;
}
-void chillAST_ImplicitCastExpr::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ) {
- subexpr->gatherArrayRefs( refs, w );
+void chillAST_ImplicitCastExpr::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {
+ subexpr->gatherArrayRefs(refs, w);
}
-void chillAST_ImplicitCastExpr::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- subexpr->gatherScalarRefs( refs, writtento );
-}
+void chillAST_ImplicitCastExpr::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ subexpr->gatherScalarRefs(refs, writtento);
+}
-void chillAST_ImplicitCastExpr::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherVarDecls( decls );
+void chillAST_ImplicitCastExpr::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherVarDecls(decls);
}
-void chillAST_ImplicitCastExpr::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherScalarVarDecls( decls );
+void chillAST_ImplicitCastExpr::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherScalarVarDecls(decls);
}
-void chillAST_ImplicitCastExpr::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherArrayVarDecls( decls );
+void chillAST_ImplicitCastExpr::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherArrayVarDecls(decls);
}
-void chillAST_ImplicitCastExpr::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- subexpr->gatherDeclRefExprs( refs );
+void chillAST_ImplicitCastExpr::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ subexpr->gatherDeclRefExprs(refs);
}
-void chillAST_ImplicitCastExpr::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherVarUsage( decls );
+void chillAST_ImplicitCastExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherVarUsage(decls);
}
+chillAST_CStyleCastExpr::chillAST_CStyleCastExpr(const char *to, chillAST_node *sub, chillAST_node *par) {
-chillAST_CStyleCastExpr::chillAST_CStyleCastExpr( const char *to, chillAST_node *sub, chillAST_node *par ) {
-
- //fprintf(stderr, "chillAST_CStyleCastExpr::chillAST_CStyleCastExpr( %s, ...)\n", to);
+ //fprintf(stderr, "chillAST_CStyleCastExpr::chillAST_CStyleCastExpr( %s, ...)\n", to);
towhat = strdup(to);
subexpr = sub;
- if (subexpr) subexpr->setParent( this );
- asttype = CHILLAST_NODETYPE_CSTYLECASTEXPR;
- parent = par;
- //fprintf(stderr, "chillAST_CStyleCastExpr (%s) sub 0x%x\n", towhat, sub );
- isFromSourceFile = true; // default
+ if (subexpr) subexpr->setParent(this);
+ asttype = CHILLAST_NODETYPE_CSTYLECASTEXPR;
+ parent = par;
+ //fprintf(stderr, "chillAST_CStyleCastExpr (%s) sub 0x%x\n", towhat, sub );
+ isFromSourceFile = true; // default
filename = NULL;
}
-void chillAST_CStyleCastExpr::replaceChild( chillAST_node *old, chillAST_node *newchild ){
+void chillAST_CStyleCastExpr::replaceChild(chillAST_node *old, chillAST_node *newchild) {
if (subexpr == old) { // should be the case for this to get called
subexpr = newchild;
- subexpr->setParent( this );
+ subexpr->setParent(this);
//old->parent = NULL;
return;
}
fprintf(stderr, "chillAST_CStyleCastExpr::replaceChild() called with bad 'old'\n");
- exit(-1); // ??
+ exit(-1); // ??
}
- void chillAST_CStyleCastExpr::replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
- subexpr->replaceVarDecls( olddecl, newdecl);
- }
+void chillAST_CStyleCastExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ subexpr->replaceVarDecls(olddecl, newdecl);
+}
-void chillAST_CStyleCastExpr::print( int indent, FILE *fp) {
- //fprintf(stderr, "CStyleCastExpr::print()\n");
- chillindent(indent, fp);
+void chillAST_CStyleCastExpr::print(int indent, FILE *fp) {
+ //fprintf(stderr, "CStyleCastExpr::print()\n");
+ chillindent(indent, fp);
// special cases? should probably walk the AST and change the literal itself
- if ( !strcmp("float", towhat) && subexpr->isIntegerLiteral()) { // (float) 3 => 3.0f
- subexpr->print( 0, fp ); fprintf(fp, ".0f");
- }
- else if ( !strcmp("double", towhat) && subexpr->isIntegerLiteral()) { // (double) 3 => 3.0
- subexpr->print( 0, fp ); fprintf(fp, ".0");
- }
- else if ( !strcmp("float", towhat) && subexpr->isFloatingLiteral()) { // (float) 3.0 => 3.0f
- subexpr->print( 0, fp ); fprintf(fp, "f");
- }
- else { // general case
- fprintf(fp, "((%s) ", towhat);
- //fprintf(fp, "\ntowhat '%s'\n", towhat );
-
- if (subexpr->isVarDecl()) fprintf(fp, "%s", ((chillAST_VarDecl *)subexpr)->varname);
- else subexpr->print( indent, fp );
- //fprintf(fp, "subexpr '%s' ", subexpr->getTypeString());
- fprintf(fp, ")");
+ if (!strcmp("float", towhat) && subexpr->isIntegerLiteral()) { // (float) 3 => 3.0f
+ subexpr->print(0, fp);
+ fprintf(fp, ".0f");
+ } else if (!strcmp("double", towhat) && subexpr->isIntegerLiteral()) { // (double) 3 => 3.0
+ subexpr->print(0, fp);
+ fprintf(fp, ".0");
+ } else if (!strcmp("float", towhat) && subexpr->isFloatingLiteral()) { // (float) 3.0 => 3.0f
+ subexpr->print(0, fp);
+ fprintf(fp, "f");
+ } else { // general case
+ fprintf(fp, "((%s) ", towhat);
+ //fprintf(fp, "\ntowhat '%s'\n", towhat );
+
+ if (subexpr->isVarDecl()) fprintf(fp, "%s", ((chillAST_VarDecl *) subexpr)->varname);
+ else subexpr->print(indent, fp);
+ //fprintf(fp, "subexpr '%s' ", subexpr->getTypeString());
+ fprintf(fp, ")");
}
- fflush(fp);
+ fflush(fp);
};
-void chillAST_CStyleCastExpr::dump( int indent, FILE *fp) {
+void chillAST_CStyleCastExpr::dump(int indent, FILE *fp) {
chillindent(indent, fp);
fprintf(fp, "(CStyleCastExpr (%s) \n", towhat);
- subexpr->dump( indent+1, fp );
+ subexpr->dump(indent + 1, fp);
chillindent(indent, fp);
fprintf(fp, ")\n");
- fflush(fp);
+ fflush(fp);
}
-class chillAST_node* chillAST_CStyleCastExpr::constantFold() {
+class chillAST_node *chillAST_CStyleCastExpr::constantFold() {
subexpr = subexpr->constantFold();
- return this;
+ return this;
}
-class chillAST_node* chillAST_CStyleCastExpr::clone() {
- chillAST_CStyleCastExpr *CSCE = new chillAST_CStyleCastExpr( towhat, subexpr->clone(), parent );
- CSCE->isFromSourceFile = isFromSourceFile;
- if (filename) CSCE->filename = strdup(filename);
+class chillAST_node *chillAST_CStyleCastExpr::clone() {
+ chillAST_CStyleCastExpr *CSCE = new chillAST_CStyleCastExpr(towhat, subexpr->clone(), parent);
+ CSCE->isFromSourceFile = isFromSourceFile;
+ if (filename) CSCE->filename = strdup(filename);
return CSCE;
}
-void chillAST_CStyleCastExpr::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ) {
- subexpr->gatherArrayRefs( refs, w );
+void chillAST_CStyleCastExpr::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {
+ subexpr->gatherArrayRefs(refs, w);
}
-void chillAST_CStyleCastExpr::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- subexpr->gatherScalarRefs( refs, writtento );
-}
-
-
-void chillAST_CStyleCastExpr::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherVarDecls( decls );
+void chillAST_CStyleCastExpr::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ subexpr->gatherScalarRefs(refs, writtento);
}
-void chillAST_CStyleCastExpr::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherScalarVarDecls( decls );
+void chillAST_CStyleCastExpr::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherVarDecls(decls);
}
-void chillAST_CStyleCastExpr::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherArrayVarDecls( decls );
+void chillAST_CStyleCastExpr::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherScalarVarDecls(decls);
}
-void chillAST_CStyleCastExpr::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- subexpr->gatherDeclRefExprs( refs );
+void chillAST_CStyleCastExpr::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherArrayVarDecls(decls);
}
-void chillAST_CStyleCastExpr::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherVarUsage( decls );
+void chillAST_CStyleCastExpr::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ subexpr->gatherDeclRefExprs(refs);
}
+void chillAST_CStyleCastExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherVarUsage(decls);
+}
-chillAST_CStyleAddressOf::chillAST_CStyleAddressOf( chillAST_node *sub, chillAST_node *par ) {
+chillAST_CStyleAddressOf::chillAST_CStyleAddressOf(chillAST_node *sub, chillAST_node *par) {
subexpr = sub;
- subexpr->setParent( this );
- asttype = CHILLAST_NODETYPE_CSTYLEADDRESSOF;
- parent = par;
- //fprintf(stderr, "chillAST_CStyleCastExpr (%s) sub 0x%x\n", towhat, sub );
- isFromSourceFile = true; // default
+ subexpr->setParent(this);
+ asttype = CHILLAST_NODETYPE_CSTYLEADDRESSOF;
+ parent = par;
+ //fprintf(stderr, "chillAST_CStyleCastExpr (%s) sub 0x%x\n", towhat, sub );
+ isFromSourceFile = true; // default
filename = NULL;
}
-void chillAST_CStyleAddressOf::print( int indent, FILE *fp) {
- //fprintf(stderr, "CStyleAddressOf::print()\n");
- chillindent(indent, fp);
- fprintf(fp, "(&");
- subexpr->print( 0, fp );
- fprintf(fp, ")");
- fflush(fp);
+void chillAST_CStyleAddressOf::print(int indent, FILE *fp) {
+ //fprintf(stderr, "CStyleAddressOf::print()\n");
+ chillindent(indent, fp);
+ fprintf(fp, "(&");
+ subexpr->print(0, fp);
+ fprintf(fp, ")");
+ fflush(fp);
};
-void chillAST_CStyleAddressOf::dump( int indent, FILE *fp) {
+void chillAST_CStyleAddressOf::dump(int indent, FILE *fp) {
chillindent(indent, fp);
fprintf(fp, "(CStyleAddressOf \n");
- subexpr->print( indent+1, fp );
+ subexpr->print(indent + 1, fp);
chillindent(indent, fp);
fprintf(fp, ")\n");
- fflush(fp);
+ fflush(fp);
}
-class chillAST_node* chillAST_CStyleAddressOf::constantFold() {
+class chillAST_node *chillAST_CStyleAddressOf::constantFold() {
subexpr = subexpr->constantFold();
- return this;
+ return this;
}
-class chillAST_node* chillAST_CStyleAddressOf::clone() {
- chillAST_CStyleAddressOf *CSAO = new chillAST_CStyleAddressOf( subexpr->clone(), parent );
- CSAO->isFromSourceFile = isFromSourceFile;
- if (filename) CSAO->filename = strdup(filename);
+class chillAST_node *chillAST_CStyleAddressOf::clone() {
+ chillAST_CStyleAddressOf *CSAO = new chillAST_CStyleAddressOf(subexpr->clone(), parent);
+ CSAO->isFromSourceFile = isFromSourceFile;
+ if (filename) CSAO->filename = strdup(filename);
return CSAO;
}
-void chillAST_CStyleAddressOf::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ) {
- subexpr->gatherArrayRefs( refs, w );
+void chillAST_CStyleAddressOf::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {
+ subexpr->gatherArrayRefs(refs, w);
}
-void chillAST_CStyleAddressOf::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- subexpr->gatherScalarRefs( refs, writtento );
-}
-
-void chillAST_CStyleAddressOf::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherVarDecls( decls );
+void chillAST_CStyleAddressOf::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ subexpr->gatherScalarRefs(refs, writtento);
}
-void chillAST_CStyleAddressOf::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherScalarVarDecls( decls );
+void chillAST_CStyleAddressOf::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherVarDecls(decls);
}
-
-void chillAST_CStyleAddressOf::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherArrayVarDecls( decls );
+void chillAST_CStyleAddressOf::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherScalarVarDecls(decls);
}
-void chillAST_CStyleAddressOf::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- subexpr->gatherDeclRefExprs( refs );
+void chillAST_CStyleAddressOf::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherArrayVarDecls(decls);
}
-void chillAST_CStyleAddressOf::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherVarUsage( decls );
+void chillAST_CStyleAddressOf::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ subexpr->gatherDeclRefExprs(refs);
}
+void chillAST_CStyleAddressOf::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherVarUsage(decls);
+}
chillAST_Malloc::chillAST_Malloc(chillAST_node *size, chillAST_node *p) {
@@ -4547,810 +4488,793 @@ chillAST_Malloc::chillAST_Malloc(chillAST_node *size, chillAST_node *p) {
sizeexpr = size; // probably a multiply like sizeof(int) * 1024
asttype = CHILLAST_NODETYPE_MALLOC;
parent = p;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
-};
+};
chillAST_Malloc::chillAST_Malloc(char *thething, chillAST_node *numthings, chillAST_node *p) {
thing = strdup(thething); // "int" or "float" or "struct widget"
- sizeexpr = numthings;
+ sizeexpr = numthings;
asttype = CHILLAST_NODETYPE_MALLOC;
parent = p;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
-};
+};
-chillAST_node* chillAST_Malloc::constantFold() {
- sizeexpr->constantFold();
+chillAST_node *chillAST_Malloc::constantFold() {
+ sizeexpr->constantFold();
}
-chillAST_node* chillAST_Malloc::clone() {
- chillAST_Malloc *M = new chillAST_Malloc( thing, sizeexpr, parent); // the general version
- M->isFromSourceFile = isFromSourceFile;
- if (filename) M->filename = strdup(filename);
+chillAST_node *chillAST_Malloc::clone() {
+ chillAST_Malloc *M = new chillAST_Malloc(thing, sizeexpr, parent); // the general version
+ M->isFromSourceFile = isFromSourceFile;
+ if (filename) M->filename = strdup(filename);
return M;
-};
+};
-void chillAST_Malloc::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
- sizeexpr->gatherArrayRefs( refs, writtento );
+void chillAST_Malloc::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {
+ sizeexpr->gatherArrayRefs(refs, writtento);
};
-void chillAST_Malloc::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- sizeexpr->gatherScalarRefs( refs, writtento );
+void chillAST_Malloc::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ sizeexpr->gatherScalarRefs(refs, writtento);
};
-void chillAST_Malloc::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- sizeexpr->gatherVarDecls(decls);
+void chillAST_Malloc::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ sizeexpr->gatherVarDecls(decls);
};
-void chillAST_Malloc::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ){
- sizeexpr->gatherScalarVarDecls(decls);
+void chillAST_Malloc::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ sizeexpr->gatherScalarVarDecls(decls);
};
-void chillAST_Malloc::gatherArrayVarDecls ( vector<chillAST_VarDecl*> &decls ) {
- sizeexpr->gatherArrayVarDecls(decls);
+void chillAST_Malloc::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ sizeexpr->gatherArrayVarDecls(decls);
};
-void chillAST_Malloc::gatherVarUsage( vector<chillAST_VarDecl*> &decls ){
- sizeexpr->gatherVarUsage(decls);
+void chillAST_Malloc::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ sizeexpr->gatherVarUsage(decls);
};
+void chillAST_Malloc::print(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "malloc(");
-void chillAST_Malloc::print( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "malloc(");
-
if (thing) {
- fprintf(fp, " sizeof(%s) * ", thing );
+ fprintf(fp, " sizeof(%s) * ", thing);
}
- sizeexpr->print(0,fp);
+ sizeexpr->print(0, fp);
fprintf(fp, ")");
- fflush(fp);
-};
+ fflush(fp);
+};
-void chillAST_Malloc::dump( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "(Malloc \n");
- sizeexpr->dump( indent+1, fp );
- chillindent(indent, fp);
+void chillAST_Malloc::dump(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "(Malloc \n");
+ sizeexpr->dump(indent + 1, fp);
+ chillindent(indent, fp);
fprintf(fp, ")\n");
- fflush(fp);
+ fflush(fp);
};
-
chillAST_CudaMalloc::chillAST_CudaMalloc(chillAST_node *devmemptr, chillAST_node *size, chillAST_node *p) {
- devPtr = devmemptr;
+ devPtr = devmemptr;
sizeinbytes = size; // probably a multiply like sizeof(int) * 1024
asttype = CHILLAST_NODETYPE_CUDAMALLOC;
parent = p;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
-};
+};
-void chillAST_CudaMalloc::print( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "cudaMalloc(");
- devPtr->print( 0, fp );
+void chillAST_CudaMalloc::print(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "cudaMalloc(");
+ devPtr->print(0, fp);
fprintf(fp, ",");
- sizeinbytes->print( 0, fp );
+ sizeinbytes->print(0, fp);
fprintf(fp, ")");
- fflush(fp);
+ fflush(fp);
};
-void chillAST_CudaMalloc::dump( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "(CudaMalloc \n");
- devPtr->dump( indent+1, fp );
+void chillAST_CudaMalloc::dump(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "(CudaMalloc \n");
+ devPtr->dump(indent + 1, fp);
fprintf(fp, "\n");
- sizeinbytes->dump( indent+1, fp );
+ sizeinbytes->dump(indent + 1, fp);
fprintf(fp, ")\n");
- fflush(fp);
+ fflush(fp);
};
-class chillAST_node* chillAST_CudaMalloc::constantFold() {
+class chillAST_node *chillAST_CudaMalloc::constantFold() {
devPtr = devPtr->constantFold();
- return this;
+ return this;
}
-class chillAST_node* chillAST_CudaMalloc::clone() {
- chillAST_CudaMalloc *CM = new chillAST_CudaMalloc( devPtr->clone(), sizeinbytes->clone(), parent );
- CM->isFromSourceFile = isFromSourceFile;
- if (filename) CM->filename = strdup(filename);
- return CM;
+class chillAST_node *chillAST_CudaMalloc::clone() {
+ chillAST_CudaMalloc *CM = new chillAST_CudaMalloc(devPtr->clone(), sizeinbytes->clone(), parent);
+ CM->isFromSourceFile = isFromSourceFile;
+ if (filename) CM->filename = strdup(filename);
+ return CM;
}
-void chillAST_CudaMalloc::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ) {
- devPtr->gatherArrayRefs( refs, false );
- sizeinbytes->gatherArrayRefs( refs, false );
+void chillAST_CudaMalloc::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {
+ devPtr->gatherArrayRefs(refs, false);
+ sizeinbytes->gatherArrayRefs(refs, false);
}
-void chillAST_CudaMalloc::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- devPtr->gatherScalarRefs( refs, false );
- sizeinbytes->gatherScalarRefs( refs, false );
+void chillAST_CudaMalloc::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ devPtr->gatherScalarRefs(refs, false);
+ sizeinbytes->gatherScalarRefs(refs, false);
}
-void chillAST_CudaMalloc::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- devPtr->gatherVarDecls( decls );
- sizeinbytes->gatherVarDecls( decls );
+void chillAST_CudaMalloc::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ devPtr->gatherVarDecls(decls);
+ sizeinbytes->gatherVarDecls(decls);
}
-void chillAST_CudaMalloc::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- devPtr->gatherScalarVarDecls( decls );
- sizeinbytes->gatherScalarVarDecls( decls );
+void chillAST_CudaMalloc::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ devPtr->gatherScalarVarDecls(decls);
+ sizeinbytes->gatherScalarVarDecls(decls);
}
-
-void chillAST_CudaMalloc::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- devPtr->gatherArrayVarDecls( decls );
- sizeinbytes->gatherArrayVarDecls( decls );
+void chillAST_CudaMalloc::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ devPtr->gatherArrayVarDecls(decls);
+ sizeinbytes->gatherArrayVarDecls(decls);
}
-
-void chillAST_CudaMalloc::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- devPtr->gatherVarUsage( decls );
- sizeinbytes->gatherVarUsage( decls );
+void chillAST_CudaMalloc::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ devPtr->gatherVarUsage(decls);
+ sizeinbytes->gatherVarUsage(decls);
}
-
chillAST_CudaFree::chillAST_CudaFree(chillAST_VarDecl *var, chillAST_node *p) {
- variable = var;
+ variable = var;
parent = p;
asttype = CHILLAST_NODETYPE_CUDAFREE;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
-};
+};
-void chillAST_CudaFree::print( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "cudaFree(%s)", variable->varname);
- fflush(fp);
+void chillAST_CudaFree::print(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "cudaFree(%s)", variable->varname);
+ fflush(fp);
};
-void chillAST_CudaFree::dump( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "(CudaFree %s )\n", variable->varname);
- fflush(fp);
+void chillAST_CudaFree::dump(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "(CudaFree %s )\n", variable->varname);
+ fflush(fp);
};
-class chillAST_node* chillAST_CudaFree::constantFold() {
- return this;
+class chillAST_node *chillAST_CudaFree::constantFold() {
+ return this;
}
-class chillAST_node* chillAST_CudaFree::clone() {
- chillAST_CudaFree *CF = new chillAST_CudaFree( variable, parent );
- CF->isFromSourceFile = isFromSourceFile;
- if (filename) CF->filename = strdup(filename);
- return CF;
+class chillAST_node *chillAST_CudaFree::clone() {
+ chillAST_CudaFree *CF = new chillAST_CudaFree(variable, parent);
+ CF->isFromSourceFile = isFromSourceFile;
+ if (filename) CF->filename = strdup(filename);
+ return CF;
}
-void chillAST_CudaFree::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ) {}
-void chillAST_CudaFree::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {}
-
-void chillAST_CudaFree::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- variable->gatherVarDecls( decls );
-}
+void chillAST_CudaFree::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {}
+void chillAST_CudaFree::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {}
-void chillAST_CudaFree::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- variable->gatherScalarVarDecls( decls );
+void chillAST_CudaFree::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ variable->gatherVarDecls(decls);
}
-void chillAST_CudaFree::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- variable->gatherArrayVarDecls( decls );
+void chillAST_CudaFree::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ variable->gatherScalarVarDecls(decls);
}
-
-void chillAST_CudaFree::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- variable->gatherVarUsage( decls );
+void chillAST_CudaFree::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ variable->gatherArrayVarDecls(decls);
}
+void chillAST_CudaFree::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ variable->gatherVarUsage(decls);
+}
-
-
-
-
-
-chillAST_CudaMemcpy::chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_node *siz, char *kind, chillAST_node *par) {
+chillAST_CudaMemcpy::chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_node *siz, char *kind,
+ chillAST_node *par) {
dest = d;
src = s;
- //fprintf(stderr, "chillAST_CudaMemcpy::chillAST_CudaMemcpy( dest %s, src %s, ...)\n", d->varname, s->varname );
+ //fprintf(stderr, "chillAST_CudaMemcpy::chillAST_CudaMemcpy( dest %s, src %s, ...)\n", d->varname, s->varname );
size = siz;
cudaMemcpyKind = kind;
asttype = CHILLAST_NODETYPE_CUDAMEMCPY;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
parent = par;
-};
+};
-void chillAST_CudaMemcpy::print( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "cudaMemcpy(%s,%s,", dest->varname, src->varname);
+void chillAST_CudaMemcpy::print(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "cudaMemcpy(%s,%s,", dest->varname, src->varname);
//dest->print( 0, fp );
//fprintf(fp, ",");
- // src->print( 0, fp ); just want the src NAME, not name and array info
+ // src->print( 0, fp ); just want the src NAME, not name and array info
//fprintf(fp, ",");
- size->print( 0, fp );
+ size->print(0, fp);
fprintf(fp, ",%s)", cudaMemcpyKind);
- fflush(fp);
+ fflush(fp);
};
-void chillAST_CudaMemcpy::dump( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "(CudaMemcpy \n");
- dest->dump( indent+1, fp );
- src->dump( indent+1, fp );
- size->dump( indent+1, fp );
- chillindent(indent+1, fp);
+void chillAST_CudaMemcpy::dump(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "(CudaMemcpy \n");
+ dest->dump(indent + 1, fp);
+ src->dump(indent + 1, fp);
+ size->dump(indent + 1, fp);
+ chillindent(indent + 1, fp);
fprintf(fp, ",%s\n", cudaMemcpyKind);
- fflush(fp);
+ fflush(fp);
};
-class chillAST_node* chillAST_CudaMemcpy::constantFold() {
- dest = (chillAST_VarDecl *)dest->constantFold();
- src = (chillAST_VarDecl *)src->constantFold();
+class chillAST_node *chillAST_CudaMemcpy::constantFold() {
+ dest = (chillAST_VarDecl *) dest->constantFold();
+ src = (chillAST_VarDecl *) src->constantFold();
size = size->constantFold();
- return this;
+ return this;
}
-class chillAST_node* chillAST_CudaMemcpy::clone() {
- chillAST_CudaMemcpy *CMCPY = new chillAST_CudaMemcpy((chillAST_VarDecl *)(dest->clone()),(chillAST_VarDecl *)(src->clone()), size->clone(), strdup(cudaMemcpyKind), parent );
- CMCPY->isFromSourceFile = isFromSourceFile;
- if (filename) CMCPY->filename = strdup(filename);
+class chillAST_node *chillAST_CudaMemcpy::clone() {
+ chillAST_CudaMemcpy *CMCPY = new chillAST_CudaMemcpy((chillAST_VarDecl *) (dest->clone()),
+ (chillAST_VarDecl *) (src->clone()), size->clone(),
+ strdup(cudaMemcpyKind), parent);
+ CMCPY->isFromSourceFile = isFromSourceFile;
+ if (filename) CMCPY->filename = strdup(filename);
return CMCPY;
}
-void chillAST_CudaMemcpy::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool w ) {
- dest->gatherArrayRefs( refs, false );
- src ->gatherArrayRefs( refs, false );
- size->gatherArrayRefs( refs, false );
+void chillAST_CudaMemcpy::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {
+ dest->gatherArrayRefs(refs, false);
+ src->gatherArrayRefs(refs, false);
+ size->gatherArrayRefs(refs, false);
}
-void chillAST_CudaMemcpy::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- dest->gatherScalarRefs( refs, false );
- src ->gatherScalarRefs( refs, false );
- size->gatherScalarRefs( refs, false );
-}
+void chillAST_CudaMemcpy::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ dest->gatherScalarRefs(refs, false);
+ src->gatherScalarRefs(refs, false);
+ size->gatherScalarRefs(refs, false);
+}
-void chillAST_CudaMemcpy::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- dest->gatherVarDecls( decls );
- src ->gatherVarDecls( decls );
- size->gatherVarDecls( decls );
+void chillAST_CudaMemcpy::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ dest->gatherVarDecls(decls);
+ src->gatherVarDecls(decls);
+ size->gatherVarDecls(decls);
}
-void chillAST_CudaMemcpy::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- dest->gatherScalarVarDecls( decls );
- src ->gatherScalarVarDecls( decls );
- size->gatherScalarVarDecls( decls );
+void chillAST_CudaMemcpy::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ dest->gatherScalarVarDecls(decls);
+ src->gatherScalarVarDecls(decls);
+ size->gatherScalarVarDecls(decls);
}
-void chillAST_CudaMemcpy::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- dest->gatherArrayVarDecls( decls );
- src ->gatherArrayVarDecls( decls );
- size->gatherArrayVarDecls( decls );
+void chillAST_CudaMemcpy::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ dest->gatherArrayVarDecls(decls);
+ src->gatherArrayVarDecls(decls);
+ size->gatherArrayVarDecls(decls);
}
-void chillAST_CudaMemcpy::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- dest->gatherVarUsage( decls );
- src ->gatherVarUsage( decls );
- size->gatherVarUsage( decls );
+void chillAST_CudaMemcpy::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ dest->gatherVarUsage(decls);
+ src->gatherVarUsage(decls);
+ size->gatherVarUsage(decls);
}
-
-chillAST_CudaSyncthreads::chillAST_CudaSyncthreads( chillAST_node *par) {
+chillAST_CudaSyncthreads::chillAST_CudaSyncthreads(chillAST_node *par) {
asttype = CHILLAST_NODETYPE_CUDASYNCTHREADS;
parent = par;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
-}
-
- void chillAST_CudaSyncthreads::print( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "__syncthreads()");
- fflush(fp);
- }
-
- void chillAST_CudaSyncthreads::dump( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "(syncthreads)\n");
- fflush(fp);
- }
-
-
-
-
-
-
+}
+void chillAST_CudaSyncthreads::print(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "__syncthreads()");
+ fflush(fp);
+}
+void chillAST_CudaSyncthreads::dump(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "(syncthreads)\n");
+ fflush(fp);
+}
-chillAST_ReturnStmt::chillAST_ReturnStmt( chillAST_node *retval, chillAST_node *par ) {
- asttype = CHILLAST_NODETYPE_RETURNSTMT;
+chillAST_ReturnStmt::chillAST_ReturnStmt(chillAST_node *retval, chillAST_node *par) {
+ asttype = CHILLAST_NODETYPE_RETURNSTMT;
returnvalue = retval;
- if (returnvalue) returnvalue->setParent( this );
- parent = par;
- isFromSourceFile = true; // default
+ if (returnvalue) returnvalue->setParent(this);
+ parent = par;
+ isFromSourceFile = true; // default
filename = NULL;
}
-void chillAST_ReturnStmt::print( int indent, FILE *fp) {
- printPreprocBEFORE(indent, fp);
+void chillAST_ReturnStmt::print(int indent, FILE *fp) {
+ printPreprocBEFORE(indent, fp);
chillindent(indent, fp);
if (returnvalue != NULL) {
fprintf(fp, "return(");
- returnvalue->print( 0, fp );
- fprintf(fp, ")" ); // parent will add ";\n" ??
- }
- else {
+ returnvalue->print(0, fp);
+ fprintf(fp, ")"); // parent will add ";\n" ??
+ } else {
fprintf(fp, "return");
}
- fflush(fp);
+ fflush(fp);
}
-void chillAST_ReturnStmt::dump( int indent, FILE *fp) {
+void chillAST_ReturnStmt::dump(int indent, FILE *fp) {
chillindent(indent, fp);
fprintf(fp, "(ReturnStmt");
if (returnvalue) {
fprintf(fp, "\n");
- returnvalue->dump(indent+1,fp);
+ returnvalue->dump(indent + 1, fp);
chillindent(indent, fp);
}
- fprintf(fp, ")\n");
+ fprintf(fp, ")\n");
}
-class chillAST_node* chillAST_ReturnStmt::constantFold() {
- if (returnvalue) returnvalue = returnvalue->constantFold();
+class chillAST_node *chillAST_ReturnStmt::constantFold() {
+ if (returnvalue) returnvalue = returnvalue->constantFold();
return this;
}
-
-class chillAST_node* chillAST_ReturnStmt::clone() {
- chillAST_node *val = NULL;
- if ( returnvalue ) val = returnvalue->clone();
- chillAST_ReturnStmt *RS = new chillAST_ReturnStmt( val, parent );
- RS->isFromSourceFile = isFromSourceFile;
- if (filename) RS->filename = strdup(filename);
+class chillAST_node *chillAST_ReturnStmt::clone() {
+ chillAST_node *val = NULL;
+ if (returnvalue) val = returnvalue->clone();
+ chillAST_ReturnStmt *RS = new chillAST_ReturnStmt(val, parent);
+ RS->isFromSourceFile = isFromSourceFile;
+ if (filename) RS->filename = strdup(filename);
return RS;
}
-void chillAST_ReturnStmt::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- if (returnvalue) returnvalue->gatherVarDecls( decls );
+void chillAST_ReturnStmt::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ if (returnvalue) returnvalue->gatherVarDecls(decls);
}
-void chillAST_ReturnStmt::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- if (returnvalue) returnvalue->gatherScalarVarDecls( decls );
+void chillAST_ReturnStmt::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ if (returnvalue) returnvalue->gatherScalarVarDecls(decls);
}
-void chillAST_ReturnStmt::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- if (returnvalue) returnvalue->gatherArrayVarDecls( decls );
+void chillAST_ReturnStmt::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ if (returnvalue) returnvalue->gatherArrayVarDecls(decls);
}
-
-void chillAST_ReturnStmt::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- if (returnvalue) returnvalue->gatherDeclRefExprs( refs );
+void chillAST_ReturnStmt::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ if (returnvalue) returnvalue->gatherDeclRefExprs(refs);
}
-
-void chillAST_ReturnStmt::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- if (returnvalue) returnvalue->gatherVarUsage( decls );
+void chillAST_ReturnStmt::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ if (returnvalue) returnvalue->gatherVarUsage(decls);
}
+chillAST_CallExpr::chillAST_CallExpr(chillAST_node *c,
+ chillAST_node *par) { //, int numofargs, chillAST_node **theargs ) {
-
-chillAST_CallExpr::chillAST_CallExpr(chillAST_node *c, chillAST_node *par) { //, int numofargs, chillAST_node **theargs ) {
-
- //fprintf(stderr, "chillAST_CallExpr::chillAST_CallExpr callee type %s\n", c->getTypeString());
+ //fprintf(stderr, "chillAST_CallExpr::chillAST_CallExpr callee type %s\n", c->getTypeString());
asttype = CHILLAST_NODETYPE_CALLEXPR;
callee = c;
- //callee->setParent( this ); // ??
+ //callee->setParent( this ); // ??
numargs = 0;
- parent = par;
+ parent = par;
grid = block = NULL;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-void chillAST_CallExpr::addArg( chillAST_node *a ) {
- args.push_back( a );
- a->setParent( this );
+void chillAST_CallExpr::addArg(chillAST_node *a) {
+ args.push_back(a);
+ a->setParent(this);
numargs += 1;
}
-void chillAST_CallExpr::print( int indent, FILE *fp) {
- printPreprocBEFORE(indent, fp);
+void chillAST_CallExpr::print(int indent, FILE *fp) {
+ printPreprocBEFORE(indent, fp);
chillindent(indent, fp);
chillAST_FunctionDecl *FD = NULL;
chillAST_MacroDefinition *MD = NULL;
- if (callee->isDeclRefExpr()) {
- chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) callee;
- //fprintf(stderr, "DRE decl is 0x%x\n", DRE->decl);
- if (!DRE->decl) {
- // a macro?
- fprintf(fp, "%s ", DRE->declarationName);
- return; // ??
+ if (callee->isDeclRefExpr()) {
+ chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) callee;
+ //fprintf(stderr, "DRE decl is 0x%x\n", DRE->decl);
+ if (!DRE->decl) {
+ // a macro?
+ fprintf(fp, "%s ", DRE->declarationName);
+ return; // ??
}
- //fprintf(stderr, "DRE decl of type %s\n", DRE->decl->getTypeString());
- if ( (DRE->decl)->isFunctionDecl()) FD = (chillAST_FunctionDecl *)DRE->decl;
- else {
- fprintf(stderr, "chillAST_CallExpr::print() DRE decl of type %s\n", DRE->decl->getTypeString());
+ //fprintf(stderr, "DRE decl of type %s\n", DRE->decl->getTypeString());
+ if ((DRE->decl)->isFunctionDecl()) FD = (chillAST_FunctionDecl *) DRE->decl;
+ else {
+ fprintf(stderr, "chillAST_CallExpr::print() DRE decl of type %s\n", DRE->decl->getTypeString());
exit(-1);
}
- }
- else if (callee->isFunctionDecl()) FD = (chillAST_FunctionDecl *) callee;
- else if (callee->isMacroDefinition()) {
+ } else if (callee->isFunctionDecl()) FD = (chillAST_FunctionDecl *) callee;
+ else if (callee->isMacroDefinition()) {
MD = (chillAST_MacroDefinition *) callee;
- fprintf(fp, "%s(", MD->macroName);
- }
- else {
- fprintf(stderr, "\nchillAST_CallExpr::print() callee of unhandled type %s\n", callee->getTypeString());
+ fprintf(fp, "%s(", MD->macroName);
+ } else {
+ fprintf(stderr, "\nchillAST_CallExpr::print() callee of unhandled type %s\n", callee->getTypeString());
callee->dump();
- exit(-1);
+ exit(-1);
}
-
- if (FD) {
- fprintf(fp, "%s", FD->functionName ); fflush(fp);
+
+ if (FD) {
+ fprintf(fp, "%s", FD->functionName);
+ fflush(fp);
if (grid && block) {
fprintf(fp, "<<<%s,%s>>>(", grid->varname, block->varname); // a
- }
- else fprintf(fp, "(");
+ } else fprintf(fp, "(");
}
//callee->print( indent, fp);
- for (int i=0; i<args.size(); i++) {
- if (i!=0) fprintf(fp, ", ");
- args[i]->print(0, fp);
+ for (int i = 0; i < args.size(); i++) {
+ if (i != 0) fprintf(fp, ", ");
+ args[i]->print(0, fp);
}
fprintf(fp, ")"); //a
- fflush(fp);
+ fflush(fp);
}
-void chillAST_CallExpr::dump( int indent, FILE *fp) {
+void chillAST_CallExpr::dump(int indent, FILE *fp) {
chillindent(indent, fp);
fprintf(fp, "(CallExpr ");
- //fprintf(stderr, "callee type %s\n", callee->getTypeString());
+ //fprintf(stderr, "callee type %s\n", callee->getTypeString());
chillAST_FunctionDecl *fd = NULL;
if (callee->isDeclRefExpr()) { // always?
- chillAST_DeclRefExpr *dre = (chillAST_DeclRefExpr *)callee;
+ chillAST_DeclRefExpr *dre = (chillAST_DeclRefExpr *) callee;
fd = dre->getFunctionDecl(); // if NULL, we've got a Vardecl instead
if (fd) {
- //fd->print();
+ //fd->print();
fprintf(fp, "%s\n", fd->returnType);
}
- callee->dump(indent+1, fp);
- if (fd) {
+ callee->dump(indent + 1, fp);
+ if (fd) {
int numparams = fd->parameters.size();
- for (int i=0; i<numparams; i++) fd->parameters[i]->dump(indent+1, fp);
+ for (int i = 0; i < numparams; i++) fd->parameters[i]->dump(indent + 1, fp);
}
}
chillindent(indent, fp);
fprintf(fp, ")\n");
}
-void chillAST_CallExpr::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
- for (int i=0; i<args.size(); i++) {
- args[i]->gatherArrayRefs( refs, writtento );
+void chillAST_CallExpr::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {
+ for (int i = 0; i < args.size(); i++) {
+ args[i]->gatherArrayRefs(refs, writtento);
}
}
-void chillAST_CallExpr::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- for (int i=0; i<args.size(); i++) {
- args[i]->gatherScalarRefs( refs, writtento );
+
+void chillAST_CallExpr::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ for (int i = 0; i < args.size(); i++) {
+ args[i]->gatherScalarRefs(refs, writtento);
}
-}
+}
-void chillAST_CallExpr::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- for (int i=0; i<args.size(); i++) {
- args[i]->gatherVarDecls( decls );
+void chillAST_CallExpr::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ for (int i = 0; i < args.size(); i++) {
+ args[i]->gatherVarDecls(decls);
}
}
-void chillAST_CallExpr::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- for (int i=0; i<args.size(); i++) {
- args[i]->gatherScalarVarDecls( decls );
+void chillAST_CallExpr::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ for (int i = 0; i < args.size(); i++) {
+ args[i]->gatherScalarVarDecls(decls);
}
}
-void chillAST_CallExpr::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- for (int i=0; i<args.size(); i++) {
- args[i]->gatherArrayVarDecls( decls );
+void chillAST_CallExpr::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ for (int i = 0; i < args.size(); i++) {
+ args[i]->gatherArrayVarDecls(decls);
}
}
-void chillAST_CallExpr::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- for (int i=0; i<args.size(); i++) {
- args[i]->gatherDeclRefExprs( refs );
+void chillAST_CallExpr::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ for (int i = 0; i < args.size(); i++) {
+ args[i]->gatherDeclRefExprs(refs);
}
}
-void chillAST_CallExpr::replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){
- for (int i=0; i<args.size(); i++) args[i]->replaceVarDecls( olddecl, newdecl );
+void chillAST_CallExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ for (int i = 0; i < args.size(); i++) args[i]->replaceVarDecls(olddecl, newdecl);
}
-void chillAST_CallExpr::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- for (int i=0; i<args.size(); i++) {
- args[i]->gatherVarUsage( decls );
+void chillAST_CallExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ for (int i = 0; i < args.size(); i++) {
+ args[i]->gatherVarUsage(decls);
}
}
-chillAST_node* chillAST_CallExpr::constantFold() {
- numargs = args.size(); // wrong place for this
- for (int i=0; i<numargs; i++) {
- args[i] = args[i]->constantFold();
+chillAST_node *chillAST_CallExpr::constantFold() {
+ numargs = args.size(); // wrong place for this
+ for (int i = 0; i < numargs; i++) {
+ args[i] = args[i]->constantFold();
}
- return this;
+ return this;
}
-chillAST_node* chillAST_CallExpr::clone() {
+chillAST_node *chillAST_CallExpr::clone() {
//fprintf(stderr, "chillAST_CallExpr::clone()\n");
- //print(0, stderr); fprintf(stderr, "\n");
+ //print(0, stderr); fprintf(stderr, "\n");
- chillAST_CallExpr *CE = new chillAST_CallExpr( callee->clone(), NULL );
- for (int i=0; i<args.size(); i++) CE->addArg( args[i]->clone() );
- CE->isFromSourceFile = isFromSourceFile;
- if (filename) CE->filename = strdup(filename);
- return CE;
+ chillAST_CallExpr *CE = new chillAST_CallExpr(callee->clone(), NULL);
+ for (int i = 0; i < args.size(); i++) CE->addArg(args[i]->clone());
+ CE->isFromSourceFile = isFromSourceFile;
+ if (filename) CE->filename = strdup(filename);
+ return CE;
}
-
-
-chillAST_VarDecl::chillAST_VarDecl() {
- //fprintf(stderr, "0chillAST_VarDecl::chillAST_VarDecl() %p\n", this);
- fprintf(stderr, "0chillAST_VarDecl::chillAST_VarDecl()\n");
+chillAST_VarDecl::chillAST_VarDecl() {
+ //fprintf(stderr, "0chillAST_VarDecl::chillAST_VarDecl() %p\n", this);
+ fprintf(stderr, "0chillAST_VarDecl::chillAST_VarDecl()\n");
vartype = underlyingtype = varname = arraypart = arraypointerpart = arraysetpart = NULL;
- typedefinition = NULL;
+ typedefinition = NULL;
- //fprintf(stderr, "setting underlying type NULL\n" );
+ //fprintf(stderr, "setting underlying type NULL\n" );
init = NULL;
- numdimensions=0; arraysizes = NULL;
- asttype = CHILLAST_NODETYPE_VARDECL; //
+ numdimensions = 0;
+ arraysizes = NULL;
+ asttype = CHILLAST_NODETYPE_VARDECL; //
parent = NULL;
metacomment = NULL;
- vardef = NULL;
+ vardef = NULL;
isStruct = false;
-
- //insideAStruct = false;
- isAParameter = false;
+
+ //insideAStruct = false;
+ isAParameter = false;
byreference = false;
- isABuiltin = false;
- isRestrict = isDevice = isShared = false; // fprintf(stderr, "RDS = false\n");
+ isABuiltin = false;
+ isRestrict = isDevice = isShared = false; // fprintf(stderr, "RDS = false\n");
knownArraySizes = false;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
-};
-
+};
-chillAST_VarDecl::chillAST_VarDecl( const char *t, const char *n, const char *a, chillAST_node *par) {
- //fprintf(stderr, "1chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart %s, parent %p) %p\n", t, n, a, par, this);
- fprintf(stderr, "1chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart %s)\n", t, n, a);
- vartype = strdup(t);
+chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, chillAST_node *par) {
+ //fprintf(stderr, "1chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart %s, parent %p) %p\n", t, n, a, par, this);
+ fprintf(stderr, "1chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart %s)\n", t, n, a);
+ vartype = strdup(t);
typedefinition = NULL;
- underlyingtype = parseUnderlyingType( vartype );
- //fprintf(stderr, "setting underlying type %s from %s\n", underlyingtype, vartype );
- varname = strdup(n);
+ underlyingtype = parseUnderlyingType(vartype);
+ //fprintf(stderr, "setting underlying type %s from %s\n", underlyingtype, vartype );
+ varname = strdup(n);
arraypointerpart = arraysetpart = NULL;
if (a) arraypart = strdup(a);
- else arraypart = strdup("");
+ else arraypart = strdup("");
splitarraypart();
init = NULL;
- numdimensions=0; arraysizes = NULL;
+ numdimensions = 0;
+ arraysizes = NULL;
uniquePtr = NULL;
asttype = CHILLAST_NODETYPE_VARDECL;
parent = par;
-
- knownArraySizes = false;
- //fprintf(stderr, "arraypart len %d\n", strlen(a));
- for (int i=0; i<strlen(a); i++) {
- if (a[i] == '[') { numdimensions++; knownArraySizes = true; }
+ knownArraySizes = false;
+ //fprintf(stderr, "arraypart len %d\n", strlen(a));
+ for (int i = 0; i < strlen(a); i++) {
+ if (a[i] == '[') {
+ numdimensions++;
+ knownArraySizes = true;
+ }
if (!knownArraySizes && a[i] == '*') numdimensions++;
}
-
- vardef = NULL;
+
+ vardef = NULL;
isStruct = false;
-
- //insideAStruct = false;
- isAParameter = false;
+
+ //insideAStruct = false;
+ isAParameter = false;
byreference = false;
- isABuiltin = false;
- isRestrict = isDevice = isShared = false; // fprintf(stderr, "RDS = false\n");
+ isABuiltin = false;
+ isRestrict = isDevice = isShared = false; // fprintf(stderr, "RDS = false\n");
+
+ if (parent) {
+ //fprintf(stderr, "chillAST_VarDecl::chillAST_VarDecl( %s ), adding to symbol table???\n", varname);
+ parent->addVariableToSymbolTable(this); // should percolate up until something has a symbol table
- if (parent) {
- //fprintf(stderr, "chillAST_VarDecl::chillAST_VarDecl( %s ), adding to symbol table???\n", varname);
- parent->addVariableToSymbolTable( this ); // should percolate up until something has a symbol table
-
}
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
-};
-
+};
-chillAST_VarDecl::chillAST_VarDecl( chillAST_RecordDecl *astruct, const char *nam, const char *array, chillAST_node *par) {
+chillAST_VarDecl::chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *nam, const char *array,
+ chillAST_node *par) {
// define a variable whose type is a struct!
-
- fprintf(stderr, "3chillAST_VarDecl::chillAST_VarDecl( %s %p struct ", nam, this );
- const char *type = astruct->getName();
- fprintf (stderr, "%s, name %s, arraypart %s parent ) %p\n", type, nam, array, this); // , par);
+
+ fprintf(stderr, "3chillAST_VarDecl::chillAST_VarDecl( %s %p struct ", nam, this);
+ const char *type = astruct->getName();
+ fprintf(stderr, "%s, name %s, arraypart %s parent ) %p\n", type, nam, array, this); // , par);
vartype = strdup(type);
- // these always go together ??
- vardef = astruct;// pointer to the thing that says what is inside the struct
- isStruct = true; // ?? wrong if it's a union ?? TODO
-
- //insideAStruct = false;
- //fprintf(stderr, "setting vardef of %s to %p\n", nam, vardef);
-
- underlyingtype = parseUnderlyingType( vartype );
- //fprintf(stderr, "setting underlying type %s from %s\n", underlyingtype, vartype );
- varname = strdup(nam);
+ // these always go together ??
+ vardef = astruct;// pointer to the thing that says what is inside the struct
+ isStruct = true; // ?? wrong if it's a union ?? TODO
+
+ //insideAStruct = false;
+ //fprintf(stderr, "setting vardef of %s to %p\n", nam, vardef);
+
+ underlyingtype = parseUnderlyingType(vartype);
+ //fprintf(stderr, "setting underlying type %s from %s\n", underlyingtype, vartype );
+ varname = strdup(nam);
arraypart = strdup(array);
arraypointerpart = arraysetpart = NULL;
- splitarraypart();
+ splitarraypart();
init = NULL;
- numdimensions=0; arraysizes = NULL;
+ numdimensions = 0;
+ arraysizes = NULL;
uniquePtr = NULL;
asttype = CHILLAST_NODETYPE_VARDECL;
parent = par;
- knownArraySizes = false;
- //fprintf(stderr, "arraypart len %d\n", strlen(a));
- for (int i=0; i<strlen(array); i++) {
- if (array[i] == '[') { numdimensions++; knownArraySizes = true; }
+ knownArraySizes = false;
+ //fprintf(stderr, "arraypart len %d\n", strlen(a));
+ for (int i = 0; i < strlen(array); i++) {
+ if (array[i] == '[') {
+ numdimensions++;
+ knownArraySizes = true;
+ }
if (!knownArraySizes && array[i] == '*') numdimensions++;
}
-
+
isAParameter = false;
- fprintf(stderr, "%s is NOT a parameter\n", nam);
+ fprintf(stderr, "%s is NOT a parameter\n", nam);
byreference = false;
- isABuiltin = false;
- isRestrict = isDevice = isShared = false; // fprintf(stderr, "RDS = false\n");
+ isABuiltin = false;
+ isRestrict = isDevice = isShared = false; // fprintf(stderr, "RDS = false\n");
typedefinition = NULL;
- //fprintf(stderr, "chillAST_VarDecl::chillAST_VarDecl( chillAST_RecordDecl *astruct, ...) MIGHT add struct to some symbol table\n");
- //if (parent) fprintf(stderr, "yep, adding it\n");
+ //fprintf(stderr, "chillAST_VarDecl::chillAST_VarDecl( chillAST_RecordDecl *astruct, ...) MIGHT add struct to some symbol table\n");
+ //if (parent) fprintf(stderr, "yep, adding it\n");
- if (parent) parent->addVariableToSymbolTable( this ); // should percolate up until something has a symbol table
+ if (parent) parent->addVariableToSymbolTable(this); // should percolate up until something has a symbol table
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
-};
-
-
-
+};
-chillAST_VarDecl::chillAST_VarDecl( chillAST_TypedefDecl *tdd, const char *n, const char *a, chillAST_node *par) {
+chillAST_VarDecl::chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, const char *a, chillAST_node *par) {
fprintf(stderr, "4chillAST_VarDecl::chillAST_VarDecl( %s typedef ", n);
const char *type = tdd->getStructName();
//fprintf (stderr, "%s, name %s, arraypart %s parent ) %p\n", type, n, a,this); // , par);
typedefinition = tdd;
- vartype = strdup(type);
- underlyingtype = parseUnderlyingType( vartype );
- //fprintf(stderr, "setting underlying type %s from %s\n", underlyingtype, vartype );
- varname = strdup(n);
+ vartype = strdup(type);
+ underlyingtype = parseUnderlyingType(vartype);
+ //fprintf(stderr, "setting underlying type %s from %s\n", underlyingtype, vartype );
+ varname = strdup(n);
arraypart = strdup(a);
arraypointerpart = arraysetpart = NULL;
- splitarraypart();
+ splitarraypart();
init = NULL;
- numdimensions=0; arraysizes = NULL;
+ numdimensions = 0;
+ arraysizes = NULL;
uniquePtr = NULL;
asttype = CHILLAST_NODETYPE_VARDECL;
parent = par;
- knownArraySizes = false;
- //fprintf(stderr, "arraypart len %d\n", strlen(a));
- for (int i=0; i<strlen(a); i++) {
- if (a[i] == '[') { numdimensions++; knownArraySizes = true; }
+ knownArraySizes = false;
+ //fprintf(stderr, "arraypart len %d\n", strlen(a));
+ for (int i = 0; i < strlen(a); i++) {
+ if (a[i] == '[') {
+ numdimensions++;
+ knownArraySizes = true;
+ }
if (!knownArraySizes && a[i] == '*') numdimensions++;
}
isStruct = tdd->isAStruct();
-
- //insideAStruct = false;
-
- vardef = NULL;
+ //insideAStruct = false;
- isAParameter = false;
- byreference = false;
- isABuiltin = false;
- isRestrict = isDevice = isShared = false; // //fprintf(stderr, "RDS = false\n");
- if (parent) parent->addVariableToSymbolTable( this ); // should percolate up until something has a symbol table
- isFromSourceFile = true; // default
- filename = NULL;
-};
-
+ vardef = NULL;
+ isAParameter = false;
+ byreference = false;
+ isABuiltin = false;
+ isRestrict = isDevice = isShared = false; // //fprintf(stderr, "RDS = false\n");
+ if (parent) parent->addVariableToSymbolTable(this); // should percolate up until something has a symbol table
+ isFromSourceFile = true; // default
+ filename = NULL;
+};
-chillAST_VarDecl::chillAST_VarDecl( const char *t, const char *n, const char *a, void *ptr, chillAST_node *par) {
+chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, void *ptr, chillAST_node *par) {
CHILL_DEBUG_PRINT("chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart '%s' ) %p\n", t, n, a, this);
- vartype = strdup(t);
+ vartype = strdup(t);
typedefinition = NULL;
- underlyingtype = parseUnderlyingType( vartype );
- //fprintf(stderr, "setting underlying type %s from %s\n", underlyingtype, vartype );
- varname = strdup(n);
+ underlyingtype = parseUnderlyingType(vartype);
+ //fprintf(stderr, "setting underlying type %s from %s\n", underlyingtype, vartype );
+ varname = strdup(n);
vardef = NULL; // not a struct
isStruct = false;
- isAParameter = false;
-
+ isAParameter = false;
+
if (a) arraypart = strdup(a);
else arraypart = strdup(""); // should catch this earlier
arraypointerpart = arraysetpart = NULL;
- splitarraypart();
+ splitarraypart();
init = NULL;
- numdimensions=0; arraysizes = NULL;
+ numdimensions = 0;
+ arraysizes = NULL;
uniquePtr = ptr;
asttype = CHILLAST_NODETYPE_VARDECL;
parent = par;
- knownArraySizes = false;
+ knownArraySizes = false;
if (par) par->addChild(this); // ??
-
- //fprintf(stderr, "name arraypart len %d\n", strlen(a));
- //fprintf(stderr, "arraypart '%s'\n", arraypart);
- for (int i=0; i<strlen(a); i++) {
- if (a[i] == '[') { numdimensions++; knownArraySizes = true; }
- if (!knownArraySizes && a[i] == '*') numdimensions++; // fails for a[4000 * 4]
- }
- //if (0 == strlen(a) && numdimensions == 0) {
- // for (int i=0; i<strlen(t); i++) { // handle float * x
+
+ //fprintf(stderr, "name arraypart len %d\n", strlen(a));
+ //fprintf(stderr, "arraypart '%s'\n", arraypart);
+ for (int i = 0; i < strlen(a); i++) {
+ if (a[i] == '[') {
+ numdimensions++;
+ knownArraySizes = true;
+ }
+ if (!knownArraySizes && a[i] == '*') numdimensions++; // fails for a[4000 * 4]
+ }
+ //if (0 == strlen(a) && numdimensions == 0) {
+ // for (int i=0; i<strlen(t); i++) { // handle float * x
// if (t[i] == '[') numdimensions++;
// if (t[i] == '*') numdimensions++;
- // }
- //}
- //fprintf(stderr, "2name %s numdimensions %d\n", n, numdimensions);
+ // }
+ //}
+ //fprintf(stderr, "2name %s numdimensions %d\n", n, numdimensions);
@@ -5360,674 +5284,655 @@ chillAST_VarDecl::chillAST_VarDecl( const char *t, const char *n, const char *a
//knownArraySizes = true;
//if (index(vartype, '*')) knownArraySizes = false; // float *a; for example
//if (index(arraypart, '*')) knownArraySizes = false;
-
+
// note: vartype here, arraypart in next code.. is that right?
- if (index(vartype, '*')) {
- for (int i = 0; i<strlen(vartype); i++) if (vartype[i] == '*') numdim++;
+ if (index(vartype, '*')) {
+ for (int i = 0; i < strlen(vartype); i++) if (vartype[i] == '*') numdim++;
//fprintf(stderr, "numd %d\n", numd);
- numdimensions = numdim;
+ numdimensions = numdim;
}
-
+
if (index(arraypart, '[')) { // JUST [12][34][56] no asterisks
char *dupe = strdup(arraypart);
int len = strlen(arraypart);
- for (int i=0; i<len; i++) if (dupe[i] == '[') numdim++;
-
+ for (int i = 0; i < len; i++) if (dupe[i] == '[') numdim++;
+
//fprintf(stderr, "numdim %d\n", numdim);
-
- numdimensions = numdim;
- int *as = (int *)malloc(sizeof(int *) * numdim );
- if (!as) {
+
+ numdimensions = numdim;
+ int *as = (int *) malloc(sizeof(int *) * numdim);
+ if (!as) {
fprintf(stderr, "can't malloc array sizes in ConvertVarDecl()\n");
exit(-1);
}
arraysizes = as; // 'as' changed later!
-
-
+
+
char *ptr = dupe;
//fprintf(stderr, "dupe '%s'\n", ptr);
while (ptr = index(ptr, '[')) { // this fails for float a[4000*4]
ptr++;
char *leak = strdup(ptr);
char *close = index(leak, ']');
- if (close) *close = '\0';
+ if (close) *close = '\0';
int l = strlen(leak);
bool justdigits = true;
bool justmath = true;
- for (int i=0; i<l; i++) {
- char c = leak[i];
+ for (int i = 0; i < l; i++) {
+ char c = leak[i];
if (!isdigit(c)) justdigits = false;
- if (!( isdigit(c) ||
- isblank(c) ||
- ((c == '+') || (c == '*') || (c == '*') || (c == '*')) || // math
- ((c == '(') || (c == ')')))
- ) {
- //fprintf(stderr, " not justmath because '%c'\n", c);
- justmath = false;
+ if (!(isdigit(c) ||
+ isblank(c) ||
+ ((c == '+') || (c == '*') || (c == '*') || (c == '*')) || // math
+ ((c == '(') || (c == ')')))
+ ) {
+ //fprintf(stderr, " not justmath because '%c'\n", c);
+ justmath = false;
}
-
+
}
//fprintf(stderr, "tmp '%s'\n", leak);
- if (justdigits) {
+ if (justdigits) {
int dim;
sscanf(ptr, "%d", &dim);
//fprintf(stderr, "dim %d\n", dim);
- *as++ = dim;
- }
- else {
+ *as++ = dim;
+ } else {
if (justmath) fprintf(stderr, "JUST MATH\n");
- fprintf(stderr, "need to evaluate %s, faking with hardcoded 16000\n", leak);
- *as++ = 16000; // temp TODO DFL
+ fprintf(stderr, "need to evaluate %s, faking with hardcoded 16000\n", leak);
+ *as++ = 16000; // temp TODO DFL
}
- free (leak);
+ free(leak);
- ptr = index(ptr, ']');
- //fprintf(stderr, "bottom of loop, ptr = '%s'\n", ptr);
+ ptr = index(ptr, ']');
+ //fprintf(stderr, "bottom of loop, ptr = '%s'\n", ptr);
}
free(dupe);
- //for (int i=0; i<numdim; i++) {
- // fprintf(stderr, "dimension %d = %d\n", i, arraysizes[i]);
- //}
-
+ //for (int i=0; i<numdim; i++) {
+ // fprintf(stderr, "dimension %d = %d\n", i, arraysizes[i]);
+ //}
+
//fprintf(stderr, "need to handle [] array to determine num dimensions\n");
- //exit(-1);
+ //exit(-1);
}
-
-
- //insideAStruct = false;
+
+
+ //insideAStruct = false;
byreference = false;
- isABuiltin = false;
- isRestrict = isDevice = isShared = false; // fprintf(stderr, "RDS = false\n");
-
- //print(); printf("\n"); fflush(stdout);
+ isABuiltin = false;
+ isRestrict = isDevice = isShared = false; // fprintf(stderr, "RDS = false\n");
- // currently this is bad, because a struct does not have a symbol table, so the
- // members of a struct are passed up to the func or sourcefile.
- if (parent) parent->addVariableToSymbolTable( this ); // should percolate up until something has a symbol table
+ //print(); printf("\n"); fflush(stdout);
+ // currently this is bad, because a struct does not have a symbol table, so the
+ // members of a struct are passed up to the func or sourcefile.
+ if (parent) parent->addVariableToSymbolTable(this); // should percolate up until something has a symbol table
- isFromSourceFile = true; // default
+
+ isFromSourceFile = true; // default
filename = NULL;
CHILL_DEBUG_PRINT("LEAVING\n");
//parent->print(); fprintf(stderr, "\n\n");
-};
+};
-void chillAST_VarDecl::print( int indent, FILE *fp ) {
+void chillAST_VarDecl::print(int indent, FILE *fp) {
//fprintf(fp, "chillAST_VarDecl::print()\n");
-
- printPreprocBEFORE(indent, fp);
- //fprintf(fp, "VarDecl vartype '%s' varname %s ", vartype, varname);
+ printPreprocBEFORE(indent, fp);
+
+ //fprintf(fp, "VarDecl vartype '%s' varname %s ", vartype, varname);
//if (isAStruct()) fprintf(fp, "isAStruct()\n");
//else fprintf(fp, "NOT A Struct\n");
// fprintf(fp, "\n"); fflush(fp); dump(0,fp); fflush(fp); // debug
chillindent(indent, fp);
- //fprintf(fp, "vardecl->print vartype '%s'\n", vartype);
- if (isDevice) fprintf(fp, "__device__ ");
- if (isShared) fprintf(fp, "__shared__ ");
-
+ //fprintf(fp, "vardecl->print vartype '%s'\n", vartype);
+ if (isDevice) fprintf(fp, "__device__ ");
+ if (isShared) fprintf(fp, "__shared__ ");
+
//if (isAStruct()) fprintf(fp, "/* isAStruct() */ ");
//else fprintf(fp, "/* NOT A Struct() */ ");
- //if (vardef) fprintf(fp, "/* vardef */ ");
- //else fprintf(fp, "/* NOT vardef */ ");
+ //if (vardef) fprintf(fp, "/* vardef */ ");
+ //else fprintf(fp, "/* NOT vardef */ ");
- //fprintf(stderr, "chillAST_VarDecl::print() %s\n", varname );
- //if (isParmVarDecl()) fprintf(stderr, "%s is a parameter\n", varname);
- //if (isAStruct()) fprintf(stderr, "%s is a struct\n", varname);
- //else fprintf(stderr, "%s is NOT a struct\n", varname);
+ //fprintf(stderr, "chillAST_VarDecl::print() %s\n", varname );
+ //if (isParmVarDecl()) fprintf(stderr, "%s is a parameter\n", varname);
+ //if (isAStruct()) fprintf(stderr, "%s is a struct\n", varname);
+ //else fprintf(stderr, "%s is NOT a struct\n", varname);
//if (!parent) fprintf(stderr, "VARDECL HAS NO PARENT\n");
- //else fprintf(stderr, "parent of %s is type %s\n", varname, parent->getTypeString());
+ //else fprintf(stderr, "parent of %s is type %s\n", varname, parent->getTypeString());
// this logic is probably wrong (what about pointer to struct? )
//fprintf(stderr, "checking for unnamed only used here\n");
if ((!isAParameter) && isAStruct() && vardef) { // an unnamed struct used only here ??
-
+
//fprintf(fp, "i%s sAStruct() && vardef ?? vardecl of type UNNAMED ONLY USED HERE \n", varname );
- // print the internals of the struct and then the name
- vardef->printStructure( 0, fp );
- fprintf(fp, "%s", varname );
-
+ // print the internals of the struct and then the name
+ vardef->printStructure(0, fp);
+ fprintf(fp, "%s", varname);
+
return;
}
-
- //fprintf(fp, "ugly logic\n");
+
+ //fprintf(fp, "ugly logic\n");
// ugly logic TODO
-
- if (typedefinition && typedefinition->isAStruct()) fprintf(fp, "struct ");
+
+ if (typedefinition && typedefinition->isAStruct()) fprintf(fp, "struct ");
if (isAParameter) {
- //fprintf(fp, "%s isaparameter\n", varname);
- //if (isAStruct()) fprintf(fp, "struct ");
- //fprintf(fp, "(param) nd %d", numdimensions );
- //dump();
+ //fprintf(fp, "%s isaparameter\n", varname);
+ //if (isAStruct()) fprintf(fp, "struct ");
+ //fprintf(fp, "(param) nd %d", numdimensions );
+ //dump();
if (numdimensions > 0) {
- if (knownArraySizes) { // just [12][34][56]
+ if (knownArraySizes) { // just [12][34][56]
fprintf(fp, "%s ", vartype);
if (byreference) fprintf(fp, "&");
fprintf(fp, "%s", varname);
- for (int n=0; n< (numdimensions); n++) fprintf(fp, "[%d]", arraysizes[n]);
- }
- else { // some unknown array part float *a; or float **a; or float (*)a[1234]
+ for (int n = 0; n < (numdimensions); n++) fprintf(fp, "[%d]", arraysizes[n]);
+ } else { // some unknown array part float *a; or float **a; or float (*)a[1234]
//fprintf(fp, "\nsome unknown\n");
//fprintf(fp, "arraypointerpart '%s'\n", arraypointerpart);
//fprintf(fp, "arraysetpart '%s'\n", arraysetpart);
-
- if (numdimensions == 1) {
- //fprintf(fp, "\nnd1, vartype %s\n", vartype);
-
+
+ if (numdimensions == 1) {
+ //fprintf(fp, "\nnd1, vartype %s\n", vartype);
+
// TODO this if means I have probably made a mistake somewhere
- if (!index(vartype, '*')) fprintf(fp, "%s *%s", vartype, varname ); // float *x
+ if (!index(vartype, '*')) fprintf(fp, "%s *%s", vartype, varname); // float *x
else fprintf(fp, "%s%s", vartype, varname); // float *a;
-
- }
- else { // more than one dimension
- if ( !strcmp("", arraysetpart) ) { // no known dimensions float ***a;
- fprintf(fp, "%s %s%s", vartype, arraypointerpart, varname);
- }
- else if ( !strcmp("", arraypointerpart)) { // ALL known float a[2][7];
- fprintf(fp, "%s %s", vartype, varname);
- for (int n=0; n< numdimensions; n++) fprintf(fp, "[%d]", arraysizes[n]);
- }
- else { // float (*)a[1234]
- // this seems really wrong
- // float (*)a[1234]
- fprintf(fp, "%s (", vartype);
- for (int n=0; n< (numdimensions-1); n++) fprintf(fp, "*");
+ } else { // more than one dimension
+
+ if (!strcmp("", arraysetpart)) { // no known dimensions float ***a;
+ fprintf(fp, "%s %s%s", vartype, arraypointerpart, varname);
+ } else if (!strcmp("", arraypointerpart)) { // ALL known float a[2][7];
+ fprintf(fp, "%s %s", vartype, varname);
+ for (int n = 0; n < numdimensions; n++) fprintf(fp, "[%d]", arraysizes[n]);
+ } else { // float (*)a[1234]
+ // this seems really wrong
+ // float (*)a[1234]
+ fprintf(fp, "%s (", vartype);
+ for (int n = 0; n < (numdimensions - 1); n++) fprintf(fp, "*");
fprintf(fp, "%s)", varname);
- fprintf(fp, "[%d]", arraysizes[numdimensions-1]);
+ fprintf(fp, "[%d]", arraysizes[numdimensions - 1]);
}
-
+
}
}
} // if numdimensions > 0
else { // parameter float x
- fprintf(fp, "%s ", vartype);
- if (byreference) fprintf(fp, "&");
- fprintf(fp, "%s", varname);
+ fprintf(fp, "%s ", vartype);
+ if (byreference) fprintf(fp, "&");
+ fprintf(fp, "%s", varname);
}
- } // end parameter
+ } // end parameter
else { // NOT A PARAMETER
- //fprintf(fp, "NOT A PARAM ... vartype '%s'\n", vartype);
+ //fprintf(fp, "NOT A PARAM ... vartype '%s'\n", vartype);
//if (isArray()) fprintf(stderr, "an array, numdimensions %d\n", numdimensions);
//fprintf(stderr, "arraysizes %p\n", arraysizes);
-
-
-
- //if (isArray() && arraysizes == NULL) {
+
+
+
+ //if (isArray() && arraysizes == NULL) {
// // we just know the number of dimensions but no sizes
// // int ***something
// fprintf(fp, "%s ", vartype); // "int "
// for (int i=0; i<numdimensions; i++) fprintf(fp, "*"); // ***
- // fprintf(fp, "%s", varname); // variable name
+ // fprintf(fp, "%s", varname); // variable name
// }
- // else
-
- fprintf(fp, "%s %s", vartype, arraypointerpart);
+ // else
+
+ fprintf(fp, "%s %s", vartype, arraypointerpart);
if (isRestrict) fprintf(fp, " __restrict__ "); // wrong place
- fprintf(fp, "%s%s", varname, arraysetpart );
- if (init) {
- fprintf(fp, " = "); fflush(fp);
+ fprintf(fp, "%s%s", varname, arraysetpart);
+ if (init) {
+ fprintf(fp, " = ");
+ fflush(fp);
init->print(0, fp);
}
}
- fflush(fp);
- //fprintf(stderr, "numdimensions %d arraysizes address 0x%x\n", numdimensions, arraysizes);
- //if (!isAParameter) fprintf(fp, ";\n", vartype, varname, arraypart );
+ fflush(fp);
+ //fprintf(stderr, "numdimensions %d arraysizes address 0x%x\n", numdimensions, arraysizes);
+ //if (!isAParameter) fprintf(fp, ";\n", vartype, varname, arraypart );
};
-
-
-void chillAST_VarDecl::printName( int in, FILE *fp ) {
+void chillAST_VarDecl::printName(int in, FILE *fp) {
chillindent(in, fp);
fprintf(fp, "%s", varname);
};
-
-
-void chillAST_VarDecl::dump( int indent, FILE *fp ) {
+void chillAST_VarDecl::dump(int indent, FILE *fp) {
chillindent(indent, fp);
- fprintf(fp, "(VarDecl \"'%s' '%s' '%s'\" n_dim %d ) ", vartype, varname, arraypart, numdimensions);
-
+ fprintf(fp, "(VarDecl \"'%s' '%s' '%s'\" n_dim %d ) ", vartype, varname, arraypart, numdimensions);
+
//fprintf(fp, "vardef %p\n", vardef);
- //if (vardef) fprintf(fp, "(typedef or struct!)\n");
+ //if (vardef) fprintf(fp, "(typedef or struct!)\n");
//fprintf(fp, "typedefinition %p\n", typedefinition);
- //if (isStruct) fprintf(fp, "isStruct\n");
-
+ //if (isStruct) fprintf(fp, "isStruct\n");
+
//if (isAParameter) fprintf(fp, "PARAMETER\n");
//else fprintf(fp, "NOT PARAMETER\n");
- fflush(fp);
+ fflush(fp);
- //segfault(); // see what called this
+ //exit(-1); // see what called this
};
-chillAST_RecordDecl * chillAST_VarDecl::getStructDef() {
+chillAST_RecordDecl *chillAST_VarDecl::getStructDef() {
if (vardef) return vardef;
if (typedefinition) return typedefinition->getStructDef();
- return NULL;
+ return NULL;
}
-
-
-
chillAST_CompoundStmt::chillAST_CompoundStmt() {
- //fprintf(stderr, "chillAST_CompoundStmt::chillAST_CompoundStmt() %p\n", this);
- asttype = CHILLAST_NODETYPE_COMPOUNDSTMT;
- parent = NULL;
+ //fprintf(stderr, "chillAST_CompoundStmt::chillAST_CompoundStmt() %p\n", this);
+ asttype = CHILLAST_NODETYPE_COMPOUNDSTMT;
+ parent = NULL;
symbol_table = new chillAST_SymbolTable;
typedef_table = NULL;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
-};
+};
-void chillAST_CompoundStmt::print( int indent, FILE *fp ) {
- printPreprocBEFORE(indent, fp);
+void chillAST_CompoundStmt::print(int indent, FILE *fp) {
+ printPreprocBEFORE(indent, fp);
int numchildren = children.size();
- //fprintf(stderr, "NUMCHILDREN %d\n", numchildren); sleep(1);
- for (int i=0; i<numchildren; i++) {
+ //fprintf(stderr, "NUMCHILDREN %d\n", numchildren); sleep(1);
+ for (int i = 0; i < numchildren; i++) {
children[i]->print(indent, fp);
- if (children[i]->asttype != CHILLAST_NODETYPE_FORSTMT
+ if (children[i]->asttype != CHILLAST_NODETYPE_FORSTMT
&& children[i]->asttype != CHILLAST_NODETYPE_IFSTMT
&& children[i]->asttype != CHILLAST_NODETYPE_COMPOUNDSTMT
- //&& children[i]->asttype != CHILLAST_NODETYPE_VARDECL // vardecl does its own ";\n"
- )
- {
- fprintf(fp, ";\n"); // probably wrong
- }
+ //&& children[i]->asttype != CHILLAST_NODETYPE_VARDECL // vardecl does its own ";\n"
+ ) {
+ fprintf(fp, ";\n"); // probably wrong
+ }
}
- fflush(fp);
+ fflush(fp);
}
-void chillAST_CompoundStmt::replaceChild( chillAST_node *old, chillAST_node *newchild ){
- //fprintf(stderr, "chillAST_CompoundStmt::replaceChild( old %s, new %s)\n", old->getTypeString(), newchild->getTypeString() );
- vector<chillAST_node*> dupe = children;
- int numdupe = dupe.size();
- int any = 0;
-
- for (int i=0; i<numdupe; i++) {
+void chillAST_CompoundStmt::replaceChild(chillAST_node *old, chillAST_node *newchild) {
+ //fprintf(stderr, "chillAST_CompoundStmt::replaceChild( old %s, new %s)\n", old->getTypeString(), newchild->getTypeString() );
+ vector<chillAST_node *> dupe = children;
+ int numdupe = dupe.size();
+ int any = 0;
+
+ for (int i = 0; i < numdupe; i++) {
- //fprintf(stderr, "\ni %d\n",i);
- //for (int j=0; j<numdupe; j++) {
- // fprintf(stderr, "this 0x%x children[%d/%d] = 0x%x type %s\n", this, j, children.size(), children[j], children[j]->getTypeString());
+ //fprintf(stderr, "\ni %d\n",i);
+ //for (int j=0; j<numdupe; j++) {
+ // fprintf(stderr, "this 0x%x children[%d/%d] = 0x%x type %s\n", this, j, children.size(), children[j], children[j]->getTypeString());
//}
- if (dupe[i] == old) {
- //fprintf(stderr, "replacing child %d of %d\n", i, numdupe);
+ if (dupe[i] == old) {
+ //fprintf(stderr, "replacing child %d of %d\n", i, numdupe);
//fprintf(stderr, "was \n"); print();
children[i] = newchild;
- newchild->setParent( this );
- //fprintf(stderr, "is \n"); print(); fprintf(stderr, "\n\n");
- // old->parent = NULL;
+ newchild->setParent(this);
+ //fprintf(stderr, "is \n"); print(); fprintf(stderr, "\n\n");
+ // old->parent = NULL;
any = 1;
}
}
- if (!any) {
+ if (!any) {
fprintf(stderr, "chillAST_CompoundStmt::replaceChild(), could not find old\n");
- exit(-1);
+ exit(-1);
}
}
-void chillAST_CompoundStmt::loseLoopWithLoopVar( char *var ) {
- //fprintf(stderr, "chillAST_CompoundStmt::loseLoopWithLoopVar( %s )\n", var);
+void chillAST_CompoundStmt::loseLoopWithLoopVar(char *var) {
+ //fprintf(stderr, "chillAST_CompoundStmt::loseLoopWithLoopVar( %s )\n", var);
//fprintf(stderr, "CompoundStmt 0x%x has parent 0x%x ", this, this->parent);
- //fprintf(stderr, "%s\n", parent->getTypeString());
+ //fprintf(stderr, "%s\n", parent->getTypeString());
-
- //fprintf(stderr, "CompoundStmt node has %d children\n", children.size());
- //fprintf(stderr, "before doing a damned thing, \n");
+
+ //fprintf(stderr, "CompoundStmt node has %d children\n", children.size());
+ //fprintf(stderr, "before doing a damned thing, \n");
//print();
//dump(); fflush(stdout);
- //fprintf(stderr, "\n\n");
+ //fprintf(stderr, "\n\n");
#ifdef DAMNED
- for (int j=0; j<children.size(); j++) {
- fprintf(stderr, "j %d/%d ", j, children.size());
+ for (int j=0; j<children.size(); j++) {
+ fprintf(stderr, "j %d/%d ", j, children.size());
fprintf(stderr, "subnode %d 0x%x ", j, children[j] );
- fprintf(stderr, "asttype %d ", children[j]->asttype);
+ fprintf(stderr, "asttype %d ", children[j]->asttype);
fprintf(stderr, "%s ", children[j]->getTypeString());
- if (children[j]->isForStmt()) {
- chillAST_ForStmt *FS = ((chillAST_ForStmt *) children[j]);
+ if (children[j]->isForStmt()) {
+ chillAST_ForStmt *FS = ((chillAST_ForStmt *) children[j]);
fprintf(stderr, "for (");
FS->init->print(0, stderr);
fprintf(stderr, "; ");
FS->cond->print(0, stderr);
fprintf(stderr, "; ");
FS->incr->print(0, stderr);
- fprintf(stderr, ") with %d statements in body 0x%x\n", FS->body->getNumChildren(), FS->body );
+ fprintf(stderr, ") with %d statements in body 0x%x\n", FS->body->getNumChildren(), FS->body );
}
- else fprintf(stderr, "\n");
+ else fprintf(stderr, "\n");
}
#endif
- vector<chillAST_node*> dupe = children; // simple enough?
- for (int i=0; i<dupe.size(); i++) {
- //for (int j=0; j<dupe.size(); j++) {
- // fprintf(stderr, "j %d/%d\n", j, dupe.size());
+ vector<chillAST_node *> dupe = children; // simple enough?
+ for (int i = 0; i < dupe.size(); i++) {
+ //for (int j=0; j<dupe.size(); j++) {
+ // fprintf(stderr, "j %d/%d\n", j, dupe.size());
// fprintf(stderr, "subnode %d %s ", j, children[j]->getTypeString());
- // if (children[j]->isForStmt()) {
- // chillAST_ForStmt *FS = ((chillAST_ForStmt *) children[j]);
+ // if (children[j]->isForStmt()) {
+ // chillAST_ForStmt *FS = ((chillAST_ForStmt *) children[j]);
// fprintf(stderr, "for (");
// FS->init->print(0, stderr);
// fprintf(stderr, "; ");
// FS->cond->print(0, stderr);
// fprintf(stderr, "; ");
// FS->incr->print(0, stderr);
- // fprintf(stderr, ") with %d statements in body 0x%x\n", FS->body->getNumChildren(), FS->body );
- //}
- //else fprintf(stderr, "\n");
+ // fprintf(stderr, ") with %d statements in body 0x%x\n", FS->body->getNumChildren(), FS->body );
+ //}
+ //else fprintf(stderr, "\n");
//}
-
- //fprintf(stderr, "CompoundStmt 0x%x recursing to child %d/%d\n", this, i, dupe.size());
- dupe[i]->loseLoopWithLoopVar( var );
+
+ //fprintf(stderr, "CompoundStmt 0x%x recursing to child %d/%d\n", this, i, dupe.size());
+ dupe[i]->loseLoopWithLoopVar(var);
}
- //fprintf(stderr, "CompoundStmt node 0x%x done recursing\n", this );
+ //fprintf(stderr, "CompoundStmt node 0x%x done recursing\n", this );
}
-
-void chillAST_CompoundStmt::dump( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "(CompoundStmt \n" );
+void chillAST_CompoundStmt::dump(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "(CompoundStmt \n");
int numchildren = children.size();
- //for (int i=0; i<numchildren; i++) {
- // fprintf(fp, "%d %s 0x%x\n", i, children[i]->getTypeString(), children[i]);
- //}
- //fprintf(fp, "\n");
+ //for (int i=0; i<numchildren; i++) {
+ // fprintf(fp, "%d %s 0x%x\n", i, children[i]->getTypeString(), children[i]);
+ //}
+ //fprintf(fp, "\n");
- for (int i=0; i<numchildren; i++) {
- children[i]->dump(indent+1, fp);
+ for (int i = 0; i < numchildren; i++) {
+ children[i]->dump(indent + 1, fp);
fprintf(fp, "\n"); // ???
fflush(fp);
}
- chillindent(indent, fp);
- fprintf(fp, ")\n");
+ chillindent(indent, fp);
+ fprintf(fp, ")\n");
};
-
-chillAST_node* chillAST_CompoundStmt::constantFold(){
- //fprintf(stderr, "chillAST_CompoundStmt::constantFold()\n");
- for (int i=0; i<children.size(); i++) children[i] = children[i]->constantFold();
+chillAST_node *chillAST_CompoundStmt::constantFold() {
+ //fprintf(stderr, "chillAST_CompoundStmt::constantFold()\n");
+ for (int i = 0; i < children.size(); i++) children[i] = children[i]->constantFold();
return this;
}
-chillAST_node* chillAST_CompoundStmt::clone(){
+chillAST_node *chillAST_CompoundStmt::clone() {
chillAST_CompoundStmt *cs = new chillAST_CompoundStmt();
- for (int i=0; i<children.size(); i++) cs->addChild( children[i]->clone() );
- cs->setParent( parent );
- cs->isFromSourceFile = isFromSourceFile;
- if (filename) cs->filename = strdup(filename);
+ for (int i = 0; i < children.size(); i++) cs->addChild(children[i]->clone());
+ cs->setParent(parent);
+ cs->isFromSourceFile = isFromSourceFile;
+ if (filename) cs->filename = strdup(filename);
return cs;
}
-void chillAST_CompoundStmt::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- //fprintf(stderr, "chillAST_CompoundStmt::gatherVarDecls()\n");
- for (int i=0; i<children.size(); i++) children[i]->gatherVarDecls( decls );
+void chillAST_CompoundStmt::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ //fprintf(stderr, "chillAST_CompoundStmt::gatherVarDecls()\n");
+ for (int i = 0; i < children.size(); i++) children[i]->gatherVarDecls(decls);
}
-void chillAST_CompoundStmt::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- for (int i=0; i<children.size(); i++) children[i]->gatherScalarVarDecls( decls );
+void chillAST_CompoundStmt::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ for (int i = 0; i < children.size(); i++) children[i]->gatherScalarVarDecls(decls);
}
-void chillAST_CompoundStmt::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- for (int i=0; i<children.size(); i++) children[i]->gatherArrayVarDecls( decls );
+void chillAST_CompoundStmt::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ for (int i = 0; i < children.size(); i++) children[i]->gatherArrayVarDecls(decls);
}
-void chillAST_CompoundStmt::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- for (int i=0; i<children.size(); i++) children[i]->gatherDeclRefExprs( refs );
+void chillAST_CompoundStmt::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ for (int i = 0; i < children.size(); i++) children[i]->gatherDeclRefExprs(refs);
}
-void chillAST_CompoundStmt::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- for (int i=0; i<children.size(); i++) children[i]->gatherVarUsage( decls );
+void chillAST_CompoundStmt::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ for (int i = 0; i < children.size(); i++) children[i]->gatherVarUsage(decls);
}
-void chillAST_CompoundStmt::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
- for (int i=0; i<children.size(); i++) children[i]->gatherArrayRefs( refs, 0);
+void chillAST_CompoundStmt::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {
+ for (int i = 0; i < children.size(); i++) children[i]->gatherArrayRefs(refs, 0);
+}
+
+void chillAST_CompoundStmt::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ for (int i = 0; i < children.size(); i++) children[i]->gatherScalarRefs(refs, 0);
}
-void chillAST_CompoundStmt::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- for (int i=0; i<children.size(); i++) children[i]->gatherScalarRefs( refs, 0);
-}
-
-void chillAST_CompoundStmt::gatherStatements(std::vector<chillAST_node*> &statements ){
- for (int i=0; i<children.size(); i++) children[i]->gatherStatements( statements );
-}
-
+void chillAST_CompoundStmt::gatherStatements(std::vector<chillAST_node *> &statements) {
+ for (int i = 0; i < children.size(); i++) children[i]->gatherStatements(statements);
+}
-void chillAST_CompoundStmt::replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){
- for (int i=0; i<children.size(); i++) children[i]->replaceVarDecls( olddecl, newdecl );
+void chillAST_CompoundStmt::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ for (int i = 0; i < children.size(); i++) children[i]->replaceVarDecls(olddecl, newdecl);
}
-bool chillAST_CompoundStmt::findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync ) {
+bool chillAST_CompoundStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync) {
// see how many elements we currently have
- int sofar = children.size();
+ int sofar = children.size();
// make big enough to add a sync after each statement. wasteful. TODO
- // this prevents inserts happening at the forstmt::addSync() from causing a
- // reallocation, which screwsup the loop below here
- children.reserve( 2 * sofar );
- //fprintf(stderr, "sofar %d reserved %d\n", sofar, 2*sofar);
+ // this prevents inserts happening at the forstmt::addSync() from causing a
+ // reallocation, which screwsup the loop below here
+ children.reserve(2 * sofar);
+ //fprintf(stderr, "sofar %d reserved %d\n", sofar, 2*sofar);
bool force = false;
- for (int i=0; i<children.size(); i++) { // children.size() to see it gain each time
- if (children.size() > sofar ) {
- //fprintf(stderr, "HEY! CompoundStmt::findLoopIndexesToReplace() noticed that children increased from %d to %d\n", sofar, children.size());
- sofar = children.size();
+ for (int i = 0; i < children.size(); i++) { // children.size() to see it gain each time
+ if (children.size() > sofar) {
+ //fprintf(stderr, "HEY! CompoundStmt::findLoopIndexesToReplace() noticed that children increased from %d to %d\n", sofar, children.size());
+ sofar = children.size();
}
- //fprintf(stderr, "compound child %d of type %s force %d\n", i, children[i]->getTypeString(), force );
- bool thisforces = children[i]->findLoopIndexesToReplace( symtab, force );
+ //fprintf(stderr, "compound child %d of type %s force %d\n", i, children[i]->getTypeString(), force );
+ bool thisforces = children[i]->findLoopIndexesToReplace(symtab, force);
force = force || thisforces; // once set, always
}
- return false;
+ return false;
-/*
+/*
vector<chillAST_node*> childrencopy;
- for (int i=0; i<children.size(); i++) childrencopy.push_back( children[i] );
+ for (int i=0; i<children.size(); i++) childrencopy.push_back( children[i] );
bool force = false;
-
- char *origtypes[64];
- int origsize = children.size();
- for (int i=0; i<children.size(); i++) {
- fprintf(stderr, "ORIGINAL compound child %d of type %s\n", i, children[i]->getTypeString() );
- origtypes[i] = strdup( children[i]->getTypeString() );
- fprintf(stderr, "ORIGINAL compound child %d of type %s\n", i, children[i]->getTypeString() );
- }
-
- for (int i=0; i<childrencopy.size(); i++) {
- fprintf(stderr, "compound child %d of type %s force %d\n", i, childrencopy[i]->getTypeString(), force );
+
+ char *origtypes[64];
+ int origsize = children.size();
+ for (int i=0; i<children.size(); i++) {
+ fprintf(stderr, "ORIGINAL compound child %d of type %s\n", i, children[i]->getTypeString() );
+ origtypes[i] = strdup( children[i]->getTypeString() );
+ fprintf(stderr, "ORIGINAL compound child %d of type %s\n", i, children[i]->getTypeString() );
+ }
+
+ for (int i=0; i<childrencopy.size(); i++) {
+ fprintf(stderr, "compound child %d of type %s force %d\n", i, childrencopy[i]->getTypeString(), force );
force = force || childrencopy[i]->findLoopIndexesToReplace( symtab, force ); // once set, always
}
- fprintf(stderr, "\n");
- for (int i=0; i<origsize; i++) {
- fprintf(stderr, "BEFORE compound child %d/%d of type %s\n", i, origsize, origtypes[i]);
+ fprintf(stderr, "\n");
+ for (int i=0; i<origsize; i++) {
+ fprintf(stderr, "BEFORE compound child %d/%d of type %s\n", i, origsize, origtypes[i]);
}
- for (int i=0; i<children.size(); i++) {
- fprintf(stderr, "AFTER compound child %d/%d of type %s\n", i, children.size(), children[i]->getTypeString() );
+ for (int i=0; i<children.size(); i++) {
+ fprintf(stderr, "AFTER compound child %d/%d of type %s\n", i, children.size(), children[i]->getTypeString() );
}
return false;
-*/
+*/
}
-
-
-
-chillAST_ParenExpr::chillAST_ParenExpr( chillAST_node *sub, chillAST_node *par ){
+chillAST_ParenExpr::chillAST_ParenExpr(chillAST_node *sub, chillAST_node *par) {
subexpr = sub;
- subexpr->setParent( this );
- asttype = CHILLAST_NODETYPE_PARENEXPR;
+ subexpr->setParent(this);
+ asttype = CHILLAST_NODETYPE_PARENEXPR;
parent = par;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-void chillAST_ParenExpr::print( int indent, FILE *fp ) {
- //fprintf(stderr, "chillAST_ParenExpr::print()\n");
+void chillAST_ParenExpr::print(int indent, FILE *fp) {
+ //fprintf(stderr, "chillAST_ParenExpr::print()\n");
chillindent(indent, fp); // hard to believe this will ever do anything
- fprintf(fp, "(" );
- subexpr->print( 0, fp );
- fprintf(fp, ")" );
- fflush(fp);
+ fprintf(fp, "(");
+ subexpr->print(0, fp);
+ fprintf(fp, ")");
+ fflush(fp);
}
-void chillAST_ParenExpr::dump( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "(ParenExpr \n");
- subexpr->dump( indent+1, fp );
- chillindent(indent, fp);
- fprintf(fp, ")\n");
+void chillAST_ParenExpr::dump(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "(ParenExpr \n");
+ subexpr->dump(indent + 1, fp);
+ chillindent(indent, fp);
+ fprintf(fp, ")\n");
}
-void chillAST_ParenExpr::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
- subexpr->gatherArrayRefs( refs, writtento );
+void chillAST_ParenExpr::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {
+ subexpr->gatherArrayRefs(refs, writtento);
}
-void chillAST_ParenExpr::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- subexpr->gatherScalarRefs( refs, writtento );
-}
-
+void chillAST_ParenExpr::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ subexpr->gatherScalarRefs(refs, writtento);
+}
-chillAST_node* chillAST_ParenExpr::constantFold() {
+chillAST_node *chillAST_ParenExpr::constantFold() {
subexpr = subexpr->constantFold();
- return this;
+ return this;
}
-chillAST_node* chillAST_ParenExpr::clone() {
- chillAST_ParenExpr *PE = new chillAST_ParenExpr( subexpr->clone(), NULL );
- PE->isFromSourceFile = isFromSourceFile;
- if (filename) PE->filename = strdup(filename);
- return PE;
+chillAST_node *chillAST_ParenExpr::clone() {
+ chillAST_ParenExpr *PE = new chillAST_ParenExpr(subexpr->clone(), NULL);
+ PE->isFromSourceFile = isFromSourceFile;
+ if (filename) PE->filename = strdup(filename);
+ return PE;
}
-void chillAST_ParenExpr::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherVarDecls( decls );
+void chillAST_ParenExpr::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherVarDecls(decls);
}
-void chillAST_ParenExpr::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherScalarVarDecls( decls );
+void chillAST_ParenExpr::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherScalarVarDecls(decls);
}
-void chillAST_ParenExpr::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherArrayVarDecls( decls );
+void chillAST_ParenExpr::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherArrayVarDecls(decls);
}
-void chillAST_ParenExpr::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- subexpr->gatherDeclRefExprs( refs );
+void chillAST_ParenExpr::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ subexpr->gatherDeclRefExprs(refs);
}
-void chillAST_ParenExpr::replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){
- subexpr->replaceVarDecls( olddecl, newdecl );
+void chillAST_ParenExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
+ subexpr->replaceVarDecls(olddecl, newdecl);
}
-void chillAST_ParenExpr::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- subexpr->gatherVarUsage( decls );
+void chillAST_ParenExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ subexpr->gatherVarUsage(decls);
}
-
-chillAST_Sizeof::chillAST_Sizeof( char *athing, chillAST_node *par ){
- thing = strdup( athing ); // memory leak
+chillAST_Sizeof::chillAST_Sizeof(char *athing, chillAST_node *par) {
+ thing = strdup(athing); // memory leak
parent = par;
- isFromSourceFile = true; // default
+ isFromSourceFile = true; // default
filename = NULL;
}
-void chillAST_Sizeof::print( int indent, FILE *fp ) {
- //fprintf(stderr, "chillAST_Sizeof::print()\n");
+void chillAST_Sizeof::print(int indent, FILE *fp) {
+ //fprintf(stderr, "chillAST_Sizeof::print()\n");
chillindent(indent, fp); // hard to believe this will ever do anything
- fprintf(fp, "sizeof(" );
- fprintf(fp, "%s)", thing );
- fflush(fp);
+ fprintf(fp, "sizeof(");
+ fprintf(fp, "%s)", thing);
+ fflush(fp);
}
-void chillAST_Sizeof::dump( int indent, FILE *fp ) {
- chillindent(indent, fp);
- fprintf(fp, "(Sizeof %s )\n", thing);
+void chillAST_Sizeof::dump(int indent, FILE *fp) {
+ chillindent(indent, fp);
+ fprintf(fp, "(Sizeof %s )\n", thing);
}
-void chillAST_Sizeof::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {}
-void chillAST_Sizeof::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {}
+void chillAST_Sizeof::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {}
-chillAST_node* chillAST_Sizeof::constantFold() {
- return this;
+void chillAST_Sizeof::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {}
+
+chillAST_node *chillAST_Sizeof::constantFold() {
+ return this;
}
-chillAST_node* chillAST_Sizeof::clone() {
- chillAST_Sizeof *SO = new chillAST_Sizeof( thing, NULL );
- SO->isFromSourceFile = isFromSourceFile;
- if (filename) SO->filename = strdup(filename);
- return SO;
+chillAST_node *chillAST_Sizeof::clone() {
+ chillAST_Sizeof *SO = new chillAST_Sizeof(thing, NULL);
+ SO->isFromSourceFile = isFromSourceFile;
+ if (filename) SO->filename = strdup(filename);
+ return SO;
}
-void chillAST_Sizeof::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) { // TODO
+void chillAST_Sizeof::gatherVarDecls(vector<chillAST_VarDecl *> &decls) { // TODO
}
-void chillAST_Sizeof::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) { // TODO
+void chillAST_Sizeof::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) { // TODO
}
-void chillAST_Sizeof::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) { // TODO
+void chillAST_Sizeof::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { // TODO
}
-void chillAST_Sizeof::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- // TODO
+void chillAST_Sizeof::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ // TODO
}
-void chillAST_Sizeof::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
+void chillAST_Sizeof::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
}
-void insertNewDeclAtLocationOfOldIfNeeded( chillAST_VarDecl *newdecl, chillAST_VarDecl *olddecl) {
+void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_VarDecl *olddecl) {
//fprintf(stderr, "insertNewDeclAtLocationOfOldIfNeeded( new 0x%x old 0x%x\n", newdecl, olddecl );
if (newdecl == NULL || olddecl == NULL) {
@@ -6041,196 +5946,195 @@ void insertNewDeclAtLocationOfOldIfNeeded( chillAST_VarDecl *newdecl, chillAST_V
chillAST_node *newparent = newdecl->parent;
chillAST_node *oldparent = olddecl->parent;
- //fprintf(stderr, "newparent 0x%x oldparent 0x%x\n", newparent, oldparent );
+ //fprintf(stderr, "newparent 0x%x oldparent 0x%x\n", newparent, oldparent );
if (newparent == oldparent) return;
- if (newparent != NULL)
+ if (newparent != NULL)
//fprintf(stderr, "chill_ast.cc insertNewDeclAtLocationOfOldIfNeeded() new decl already has parent?? probably wrong\n");
- newdecl->parent = oldparent; // will be true soon
+ newdecl->parent = oldparent; // will be true soon
// find actual location of old decl and insert new one there
//fprintf(stderr, "oldparent is of type %s\n", oldparent->getTypeString()); // better be compoundstmt ??
- vector<chillAST_node*> children = oldparent->getChildren();
-
- int numchildren = children.size();
- //fprintf(stderr, "oldparent has %d children\n", numchildren);
-
+ vector<chillAST_node *> children = oldparent->getChildren();
+
+ int numchildren = children.size();
+ //fprintf(stderr, "oldparent has %d children\n", numchildren);
+
if (numchildren == 0) {
- fprintf(stderr, "chill_ast.cc insertNewDeclAtLocationOfOldIfNeeded() impossible number of oldparent children (%d)\n", numchildren);
+ fprintf(stderr,
+ "chill_ast.cc insertNewDeclAtLocationOfOldIfNeeded() impossible number of oldparent children (%d)\n",
+ numchildren);
exit(-1);
}
bool newalreadythere = false;
int index = -1;
- //fprintf(stderr, "olddecl is 0x%x\n", olddecl);
+ //fprintf(stderr, "olddecl is 0x%x\n", olddecl);
//fprintf(stderr, "I know of %d variables\n", numchildren);
- for (int i=0; i<numchildren; i++) {
- chillAST_node *child = oldparent->getChild(i);
- //fprintf(stderr, "child %d @ 0x%x is of type %s\n", i, child, child->getTypeString());
- if (children[i] == olddecl) {
+ for (int i = 0; i < numchildren; i++) {
+ chillAST_node *child = oldparent->getChild(i);
+ //fprintf(stderr, "child %d @ 0x%x is of type %s\n", i, child, child->getTypeString());
+ if (children[i] == olddecl) {
index = i;
- //fprintf(stderr, "found old decl at index %d\n", index);
+ //fprintf(stderr, "found old decl at index %d\n", index);
}
- if (children[i] == newdecl) {
- newalreadythere = true;
- //fprintf(stderr, "new already there @ index %d\n", i);
+ if (children[i] == newdecl) {
+ newalreadythere = true;
+ //fprintf(stderr, "new already there @ index %d\n", i);
}
}
- if (index == -1) {
- fprintf(stderr, "chill_ast.cc insertNewDeclAtLocationOfOldIfNeeded() can't find old decl for %s\n", olddecl->varname);
+ if (index == -1) {
+ fprintf(stderr, "chill_ast.cc insertNewDeclAtLocationOfOldIfNeeded() can't find old decl for %s\n",
+ olddecl->varname);
exit(-1);
}
- if (!newalreadythere) oldparent->insertChild( index, newdecl );
+ if (!newalreadythere) oldparent->insertChild(index, newdecl);
}
-void gatherVarDecls( vector<chillAST_node*> &code, vector<chillAST_VarDecl*> &decls) {
+void gatherVarDecls(vector<chillAST_node *> &code, vector<chillAST_VarDecl *> &decls) {
//fprintf(stderr, "gatherVarDecls()\n");
int numcode = code.size();
//fprintf(stderr, "%d top level statements\n", numcode);
- for (int i=0; i<numcode; i++) {
+ for (int i = 0; i < numcode; i++) {
chillAST_node *statement = code[i];
- statement->gatherVarDecls( decls );
+ statement->gatherVarDecls(decls);
}
}
-void gatherVarUsage( vector<chillAST_node*> &code, vector<chillAST_VarDecl*> &decls) {
+void gatherVarUsage(vector<chillAST_node *> &code, vector<chillAST_VarDecl *> &decls) {
//fprintf(stderr, "gatherVarUsage()\n");
int numcode = code.size();
//fprintf(stderr, "%d top level statements\n", numcode);
- for (int i=0; i<numcode; i++) {
+ for (int i = 0; i < numcode; i++) {
chillAST_node *statement = code[i];
- statement->gatherVarUsage( decls );
+ statement->gatherVarUsage(decls);
}
}
-
-
-chillAST_IfStmt::chillAST_IfStmt() {
- cond = thenpart = elsepart = NULL;
- asttype = CHILLAST_NODETYPE_IFSTMT;
- isFromSourceFile = true; // default
+chillAST_IfStmt::chillAST_IfStmt() {
+ cond = thenpart = elsepart = NULL;
+ asttype = CHILLAST_NODETYPE_IFSTMT;
+ isFromSourceFile = true; // default
filename = NULL;
}
-chillAST_IfStmt::chillAST_IfStmt(chillAST_node *c, chillAST_node *t, chillAST_node *e, chillAST_node *p){
+chillAST_IfStmt::chillAST_IfStmt(chillAST_node *c, chillAST_node *t, chillAST_node *e, chillAST_node *p) {
cond = c;
- if (cond) cond->setParent( this );
+ if (cond) cond->setParent(this);
thenpart = t;
- if (thenpart) thenpart->setParent( this );
+ if (thenpart) thenpart->setParent(this);
elsepart = e;
- if (elsepart) elsepart->setParent( this );
+ if (elsepart) elsepart->setParent(this);
parent = p;
- asttype = CHILLAST_NODETYPE_IFSTMT;
- isFromSourceFile = true; // default
+ asttype = CHILLAST_NODETYPE_IFSTMT;
+ isFromSourceFile = true; // default
filename = NULL;
}
-void chillAST_IfStmt::gatherVarDecls( vector<chillAST_VarDecl*> &decls ) {
- if (cond) cond->gatherVarDecls( decls );
- if (thenpart) thenpart->gatherVarDecls( decls );
- if (elsepart) elsepart->gatherVarDecls( decls );
+void chillAST_IfStmt::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
+ if (cond) cond->gatherVarDecls(decls);
+ if (thenpart) thenpart->gatherVarDecls(decls);
+ if (elsepart) elsepart->gatherVarDecls(decls);
}
-void chillAST_IfStmt::gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) {
- if (cond) cond->gatherScalarVarDecls( decls );
- if (thenpart) thenpart->gatherScalarVarDecls( decls );
- if (elsepart) elsepart->gatherScalarVarDecls( decls );
+void chillAST_IfStmt::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ if (cond) cond->gatherScalarVarDecls(decls);
+ if (thenpart) thenpart->gatherScalarVarDecls(decls);
+ if (elsepart) elsepart->gatherScalarVarDecls(decls);
}
-void chillAST_IfStmt::gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) {
- if (cond) cond->gatherArrayVarDecls( decls );
- if (thenpart) thenpart->gatherArrayVarDecls( decls );
- if (elsepart) elsepart->gatherArrayVarDecls( decls );
+void chillAST_IfStmt::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
+ if (cond) cond->gatherArrayVarDecls(decls);
+ if (thenpart) thenpart->gatherArrayVarDecls(decls);
+ if (elsepart) elsepart->gatherArrayVarDecls(decls);
}
-void chillAST_IfStmt::gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {
- if (cond) cond->gatherDeclRefExprs( refs );
- if (thenpart) thenpart->gatherDeclRefExprs( refs );
- if (elsepart) elsepart->gatherDeclRefExprs( refs );
+void chillAST_IfStmt::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
+ if (cond) cond->gatherDeclRefExprs(refs);
+ if (thenpart) thenpart->gatherDeclRefExprs(refs);
+ if (elsepart) elsepart->gatherDeclRefExprs(refs);
}
-void chillAST_IfStmt::gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
- if (cond) cond->gatherVarUsage( decls );
- if (thenpart) thenpart->gatherVarUsage( decls );
- if (elsepart) elsepart->gatherVarUsage( decls );
+void chillAST_IfStmt::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
+ if (cond) cond->gatherVarUsage(decls);
+ if (thenpart) thenpart->gatherVarUsage(decls);
+ if (elsepart) elsepart->gatherVarUsage(decls);
}
-void chillAST_IfStmt::gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
- cond->gatherArrayRefs( refs, 0 ); // 0 ??
- thenpart->gatherArrayRefs( refs, 0 ); // 0 ??
- if (elsepart) elsepart->gatherArrayRefs( refs, 0 ); // 0 ??
+void chillAST_IfStmt::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {
+ cond->gatherArrayRefs(refs, 0); // 0 ??
+ thenpart->gatherArrayRefs(refs, 0); // 0 ??
+ if (elsepart) elsepart->gatherArrayRefs(refs, 0); // 0 ??
}
-void chillAST_IfStmt::gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
- cond->gatherScalarRefs( refs, 0 ); // 0 ??
- thenpart->gatherScalarRefs( refs, 0 ); // 0 ??
- if (elsepart) elsepart->gatherScalarRefs( refs, 0 ); // 0 ??
-}
+void chillAST_IfStmt::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
+ cond->gatherScalarRefs(refs, 0); // 0 ??
+ thenpart->gatherScalarRefs(refs, 0); // 0 ??
+ if (elsepart) elsepart->gatherScalarRefs(refs, 0); // 0 ??
+}
-chillAST_node *chillAST_IfStmt::constantFold() {
+chillAST_node *chillAST_IfStmt::constantFold() {
if (cond) cond = cond->constantFold();
if (thenpart) thenpart = thenpart->constantFold();
if (elsepart) elsepart = elsepart->constantFold();
- return this;
+ return this;
}
-void chillAST_IfStmt::gatherStatements(std::vector<chillAST_node*> &statements ){
+void chillAST_IfStmt::gatherStatements(std::vector<chillAST_node *> &statements) {
- //print(); printf("\n"); fflush(stdout);
- thenpart->gatherStatements( statements );
- //fprintf(stderr, "ifstmt, after then, %d statements\n", statements.size());
- if (elsepart){
- //fprintf(stderr, "there is an elsepart of type %s\n", elsepart->getTypeString());
- elsepart->gatherStatements( statements );
+ //print(); printf("\n"); fflush(stdout);
+ thenpart->gatherStatements(statements);
+ //fprintf(stderr, "ifstmt, after then, %d statements\n", statements.size());
+ if (elsepart) {
+ //fprintf(stderr, "there is an elsepart of type %s\n", elsepart->getTypeString());
+ elsepart->gatherStatements(statements);
}
- //fprintf(stderr, "ifstmt, after else, %d statements\n", statements.size());
+ //fprintf(stderr, "ifstmt, after else, %d statements\n", statements.size());
}
-
-chillAST_node *chillAST_IfStmt::clone() {
- chillAST_node *c, *t, *e;
- c = t = e = NULL;
- if (cond) c = cond->clone(); // has to be one, right?
+chillAST_node *chillAST_IfStmt::clone() {
+ chillAST_node *c, *t, *e;
+ c = t = e = NULL;
+ if (cond) c = cond->clone(); // has to be one, right?
if (thenpart) t = thenpart->clone();
if (elsepart) e = elsepart->clone();
- chillAST_IfStmt *IS = new chillAST_IfStmt( c, t, e, parent);
+ chillAST_IfStmt *IS = new chillAST_IfStmt(c, t, e, parent);
IS->isFromSourceFile = isFromSourceFile;
- if (filename) IS->filename = strdup(filename);
+ if (filename) IS->filename = strdup(filename);
return IS;
-}
-
+}
-void chillAST_IfStmt::dump( int indent, FILE *fp ) {
+void chillAST_IfStmt::dump(int indent, FILE *fp) {
chillindent(indent, fp);
fprintf(fp, "(if ");
fprintf(fp, "\n");
- cond->dump(indent+1, fp);
+ cond->dump(indent + 1, fp);
fprintf(fp, "\n");
- thenpart->dump(indent+1, fp);
- fprintf(fp, "\n");
+ thenpart->dump(indent + 1, fp);
+ fprintf(fp, "\n");
- if (elsepart) {
- elsepart->dump(indent+1, fp);
+ if (elsepart) {
+ elsepart->dump(indent + 1, fp);
fprintf(fp, "\n");
}
chillindent(indent, fp);
@@ -6238,255 +6142,246 @@ void chillAST_IfStmt::dump( int indent, FILE *fp ) {
}
-
-void chillAST_IfStmt::print(int indent, FILE *fp ) {
- printPreprocBEFORE(indent, fp);
+void chillAST_IfStmt::print(int indent, FILE *fp) {
+ printPreprocBEFORE(indent, fp);
chillindent(indent, fp);
- fprintf(fp, "if (");
+ fprintf(fp, "if (");
if (cond) cond->print(0, fp);
- else fprintf(fp, "(NULL cond)");
+ else fprintf(fp, "(NULL cond)");
- bool needbracket = true;
- if (thenpart) {
+ bool needbracket = true;
+ if (thenpart) {
if (thenpart->isBinaryOperator()) needbracket = false;
if (thenpart->isCompoundStmt()) { // almost always true
- chillAST_CompoundStmt *CS = (chillAST_CompoundStmt*) thenpart;
- if (CS->children.size() == 1 && CS->children[0]->isBinaryOperator()) needbracket = false;
- }
-
- if(needbracket) fprintf(fp, ") {\n");
- else fprintf(fp, ")\n");
-
- thenpart->print(indent+1, fp); // end of line
-
- if(needbracket) {
- //fprintf(fp, "\n");
+ chillAST_CompoundStmt *CS = (chillAST_CompoundStmt *) thenpart;
+ if (CS->children.size() == 1 && CS->children[0]->isBinaryOperator()) needbracket = false;
+ }
+
+ if (needbracket) fprintf(fp, ") {\n");
+ else fprintf(fp, ")\n");
+
+ thenpart->print(indent + 1, fp); // end of line
+
+ if (needbracket) {
+ //fprintf(fp, "\n");
chillindent(indent, fp);
- fprintf(fp, "}\n");
+ fprintf(fp, "}\n");
}
- }
- else fprintf(fp, "(NULL thenpart)");
+ } else fprintf(fp, "(NULL thenpart)");
+
-
needbracket = true;
- if (elsepart) {
+ if (elsepart) {
if (elsepart->isBinaryOperator()) needbracket = false;
if (elsepart->isCompoundStmt()) { // almost always true
- chillAST_CompoundStmt *CS = (chillAST_CompoundStmt*) elsepart;
-
- if (CS->children.size() == 1 && CS->children[0]->isBinaryOperator()) needbracket = false;
-
- }
-
- fprintf(fp, "\n");
+ chillAST_CompoundStmt *CS = (chillAST_CompoundStmt *) elsepart;
+
+ if (CS->children.size() == 1 && CS->children[0]->isBinaryOperator()) needbracket = false;
+
+ }
+
+ fprintf(fp, "\n");
chillindent(indent, fp);
-
- if (needbracket) fprintf(fp, "else {\n");
- else fprintf(fp, "else\n");
-
- elsepart->print(indent+1, fp);
-
- if(needbracket) {
- fprintf(fp, "\n");
+
+ if (needbracket) fprintf(fp, "else {\n");
+ else fprintf(fp, "else\n");
+
+ elsepart->print(indent + 1, fp);
+
+ if (needbracket) {
+ fprintf(fp, "\n");
chillindent(indent, fp);
- fprintf(fp, "}\n");
+ fprintf(fp, "}\n");
}
}
- //else fprintf(fp, "else { /* NOTHING */ }");
+ //else fprintf(fp, "else { /* NOTHING */ }");
}
-
-bool chillAST_IfStmt::findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync ) {
- thenpart->findLoopIndexesToReplace( symtab );
- elsepart->findLoopIndexesToReplace( symtab );
- return false; // ??
+bool chillAST_IfStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync) {
+ thenpart->findLoopIndexesToReplace(symtab);
+ elsepart->findLoopIndexesToReplace(symtab);
+ return false; // ??
}
-
-chillAST_node *lessthanmacro( chillAST_node *left, chillAST_node *right) {
+chillAST_node *lessthanmacro(chillAST_node *left, chillAST_node *right) {
- chillAST_ParenExpr *lp1 = new chillAST_ParenExpr( left );
- chillAST_ParenExpr *rp1 = new chillAST_ParenExpr( right );
- chillAST_BinaryOperator *cond = new chillAST_BinaryOperator( lp1, "<", rp1 );
+ chillAST_ParenExpr *lp1 = new chillAST_ParenExpr(left);
+ chillAST_ParenExpr *rp1 = new chillAST_ParenExpr(right);
+ chillAST_BinaryOperator *cond = new chillAST_BinaryOperator(lp1, "<", rp1);
- chillAST_ParenExpr *lp2 = new chillAST_ParenExpr( left );
- chillAST_ParenExpr *rp2 = new chillAST_ParenExpr( right );
-
- chillAST_TernaryOperator *t = new chillAST_TernaryOperator("?", cond, lp2, rp2);
-
- return t;
-}
+ chillAST_ParenExpr *lp2 = new chillAST_ParenExpr(left);
+ chillAST_ParenExpr *rp2 = new chillAST_ParenExpr(right);
+ chillAST_TernaryOperator *t = new chillAST_TernaryOperator("?", cond, lp2, rp2);
+ return t;
+}
// look for function declaration with a given name, in the tree with root "node"
-void findFunctionDeclRecursive( chillAST_node *node, const char *procname, vector<chillAST_FunctionDecl*>& funcs )
-{
- //fprintf(stderr, "findmanually() CHILL AST node of type %s\n", node->getTypeString());
-
- if (node->isFunctionDecl()) {
+void findFunctionDeclRecursive(chillAST_node *node, const char *procname, vector<chillAST_FunctionDecl *> &funcs) {
+ //fprintf(stderr, "findmanually() CHILL AST node of type %s\n", node->getTypeString());
+
+ if (node->isFunctionDecl()) {
char *name = ((chillAST_FunctionDecl *) node)->functionName; // compare name with desired name
//fprintf(stderr, "node name 0x%x ", name);
- //fprintf(stderr, "%s procname ", name);
+ //fprintf(stderr, "%s procname ", name);
//fprintf(stderr, "0x%x ", procname);
- //fprintf(stderr, "%s\n", procname);
- if (!strcmp( name, procname)) {
- //fprintf(stderr, "found procedure %s\n", procname );
- funcs.push_back( (chillAST_FunctionDecl*) node ); // this is it
+ //fprintf(stderr, "%s\n", procname);
+ if (!strcmp(name, procname)) {
+ //fprintf(stderr, "found procedure %s\n", procname );
+ funcs.push_back((chillAST_FunctionDecl *) node); // this is it
// quit recursing. probably not correct in some horrible case
- return;
+ return;
}
- //else fprintf(stderr, "this is not the function we're looking for\n");
+ //else fprintf(stderr, "this is not the function we're looking for\n");
}
- // this is where the children can be used effectively.
+ // this is where the children can be used effectively.
// we don't really care what kind of node we're at. We just check the node itself
- // and then its children is needed.
+ // and then its children is needed.
- int numc = node->children.size();
+ int numc = node->children.size();
fprintf(stderr, "(top)node has %d children\n", numc);
- for (int i=0; i<numc; i++) {
- if (node->isSourceFile()) {
- fprintf(stderr, "node of type %s is recursing to child %d of type %s\n", node->getTypeString(), i, node->children[i]->getTypeString());
- if (node->children[i]->isFunctionDecl()) {
- chillAST_FunctionDecl *fd = (chillAST_FunctionDecl*) node->children[i];
- fprintf(stderr, "child %d is functiondecl %s\n", i, fd->functionName);
+ for (int i = 0; i < numc; i++) {
+ if (node->isSourceFile()) {
+ fprintf(stderr, "node of type %s is recursing to child %d of type %s\n", node->getTypeString(), i,
+ node->children[i]->getTypeString());
+ if (node->children[i]->isFunctionDecl()) {
+ chillAST_FunctionDecl *fd = (chillAST_FunctionDecl *) node->children[i];
+ fprintf(stderr, "child %d is functiondecl %s\n", i, fd->functionName);
}
}
- findFunctionDeclRecursive( node->children[i], procname, funcs );
-
+ findFunctionDeclRecursive(node->children[i], procname, funcs);
+
}
- return;
+ return;
}
-chillAST_FunctionDecl *findFunctionDecl( chillAST_node *node, const char *procname)
-{
- vector<chillAST_FunctionDecl*> functions;
- findFunctionDeclRecursive( node, procname, functions );
+chillAST_FunctionDecl *findFunctionDecl(chillAST_node *node, const char *procname) {
+ vector<chillAST_FunctionDecl *> functions;
+ findFunctionDeclRecursive(node, procname, functions);
- if ( functions.size() == 0 ) {
+ if (functions.size() == 0) {
fprintf(stderr, "could not find function named '%s'\n", procname);
exit(-1);
}
-
- if ( functions.size() > 1 ) {
+
+ if (functions.size() > 1) {
fprintf(stderr, "oddly, found %d functions named '%s'\n", functions.size(), procname);
- fprintf(stderr, "I am unsure what to do\n");
+ fprintf(stderr, "I am unsure what to do\n");
- for (int f = 0; f < functions.size(); f++) {
- fprintf(stderr, "function %d %p %s\n", f, functions[f], functions[f]->functionName);
+ for (int f = 0; f < functions.size(); f++) {
+ fprintf(stderr, "function %d %p %s\n", f, functions[f], functions[f]->functionName);
}
exit(-1);
}
-
- //fprintf(stderr, "found the procedure named %s\n", procname);
+
+ //fprintf(stderr, "found the procedure named %s\n", procname);
return functions[0];
}
-chillAST_SymbolTable *addSymbolToTable( chillAST_SymbolTable *st, chillAST_VarDecl *vd ) // definition
+chillAST_SymbolTable *addSymbolToTable(chillAST_SymbolTable *st, chillAST_VarDecl *vd) // definition
{
chillAST_SymbolTable *s = st;
- if (!s) s = new chillAST_SymbolTable;
-
+ if (!s) s = new chillAST_SymbolTable;
+
int tablesize = s->size();
-
- for (int i=0; i<tablesize; i++) {
- if ((*s)[i] == vd) {
- //fprintf(stderr, "the exact same symbol, not just the same name, was already there\n");
- return s; // already there
+
+ for (int i = 0; i < tablesize; i++) {
+ if ((*s)[i] == vd) {
+ //fprintf(stderr, "the exact same symbol, not just the same name, was already there\n");
+ return s; // already there
}
}
- for (int i=0; i<tablesize; i++) {
- //fprintf(stderr, "name %s vs name %s\n", (*s)[i]->varname, vd->varname);
- if (!strcmp( (*s)[i]->varname, vd->varname)) {
- //fprintf(stderr, "symbol with the same name was already there\n");
- return s; // already there
+ for (int i = 0; i < tablesize; i++) {
+ //fprintf(stderr, "name %s vs name %s\n", (*s)[i]->varname, vd->varname);
+ if (!strcmp((*s)[i]->varname, vd->varname)) {
+ //fprintf(stderr, "symbol with the same name was already there\n");
+ return s; // already there
}
}
- //fprintf(stderr, "adding %s %s to a symbol table that didn't already have it\n", vd->vartype, vd->varname);
+ //fprintf(stderr, "adding %s %s to a symbol table that didn't already have it\n", vd->vartype, vd->varname);
- //printf("before:\n");
- //printSymbolTable( s ); fflush(stdout);
+ //printf("before:\n");
+ //printSymbolTable( s ); fflush(stdout);
- s->push_back(vd); // add it
+ s->push_back(vd); // add it
- //printf("after:\n");
- //printSymbolTable( s ); fflush(stdout);
+ //printf("after:\n");
+ //printSymbolTable( s ); fflush(stdout);
return s;
}
-chillAST_TypedefTable *addTypedefToTable( chillAST_TypedefTable *tdt, chillAST_TypedefDecl *td )
-{
+chillAST_TypedefTable *addTypedefToTable(chillAST_TypedefTable *tdt, chillAST_TypedefDecl *td) {
chillAST_TypedefTable *t = tdt;
if (!t) t = new chillAST_TypedefTable;
int tablesize = t->size();
-
- for (int i=0; i<tablesize; i++) {
- if ((*t)[i] == td) return t; // already there
+
+ for (int i = 0; i < tablesize; i++) {
+ if ((*t)[i] == td) return t; // already there
}
- t->push_back(td); // add it
+ t->push_back(td); // add it
return t;
}
-chillAST_NoOp::chillAST_NoOp( chillAST_node *p ) {
- parent = p;
- isFromSourceFile = true; // default
+chillAST_NoOp::chillAST_NoOp(chillAST_node *p) {
+ parent = p;
+ isFromSourceFile = true; // default
filename = NULL;
}; // so we have SOMETHING for NoOp in the cc file ???
-chillAST_Preprocessing::chillAST_Preprocessing() {
+chillAST_Preprocessing::chillAST_Preprocessing() {
position = CHILL_PREPROCESSING_POSITIONUNKNOWN;
- pptype = CHILL_PREPROCESSING_TYPEUNKNOWN;
+ pptype = CHILL_PREPROCESSING_TYPEUNKNOWN;
blurb = strdup(""); // never use null. ignore the leak ??
}
- chillAST_Preprocessing::chillAST_Preprocessing(CHILL_PREPROCESSING_POSITION pos,
- CHILL_PREPROCESSING_TYPE t,
- char *text )
- {
- position = pos;
- pptype = t;
- blurb = strdup( text );
- }
-
-void chillAST_Preprocessing::print( int indent, FILE *fp ) { // probably very wrong
- if (position == CHILL_PREPROCESSING_LINEAFTER ) {
- fprintf(fp, "\n");
- chillindent(indent, fp);
- }
- if (position == CHILL_PREPROCESSING_LINEBEFORE) { // ???
- //fprintf(fp, "\n");
- chillindent(indent, fp);
- }
-
- fprintf(fp, "%s", blurb);
-
- if (position == CHILL_PREPROCESSING_TOTHERIGHT) {
- fprintf(fp, "\n");
- }
+chillAST_Preprocessing::chillAST_Preprocessing(CHILL_PREPROCESSING_POSITION pos,
+ CHILL_PREPROCESSING_TYPE t,
+ char *text) {
+ position = pos;
+ pptype = t;
+ blurb = strdup(text);
+}
+
+void chillAST_Preprocessing::print(int indent, FILE *fp) { // probably very wrong
+ if (position == CHILL_PREPROCESSING_LINEAFTER) {
+ fprintf(fp, "\n");
+ chillindent(indent, fp);
+ }
+ if (position == CHILL_PREPROCESSING_LINEBEFORE) { // ???
+ //fprintf(fp, "\n");
+ chillindent(indent, fp);
+ }
+ fprintf(fp, "%s", blurb);
- if (position == CHILL_PREPROCESSING_LINEBEFORE) {
- //fprintf(fp, "\n"); // comment seems to have \n at the end already
- //chillindent(indent, fp);
- }
+ if (position == CHILL_PREPROCESSING_TOTHERIGHT) {
+ fprintf(fp, "\n");
+ }
- //if (pptype != CHILL_PREPROCESSING_IMMEDIATELYBEFORE && pptype != CHILL_PREPROCESSING_UNKNOWN) fprint(fp, "\n");
-
- }
+ if (position == CHILL_PREPROCESSING_LINEBEFORE) {
+ //fprintf(fp, "\n"); // comment seems to have \n at the end already
+ //chillindent(indent, fp);
+ }
+
+
+ //if (pptype != CHILL_PREPROCESSING_IMMEDIATELYBEFORE && pptype != CHILL_PREPROCESSING_UNKNOWN) fprint(fp, "\n");
+
+}
diff --git a/src/chillmodule.cc b/src/chillmodule.cc
index 5a7d575..5e78be3 100644
--- a/src/chillmodule.cc
+++ b/src/chillmodule.cc
@@ -53,8 +53,7 @@ void finalize_loop(int loop_num_start, int loop_num_end) {
if (loop_num_start == loop_num_end) {
ir_code->ReplaceCode(ir_controls[loops[loop_num_start]], myloop->getCode());
ir_controls[loops[loop_num_start]] = NULL;
- }
- else {
+ } else {
std::vector<IR_Control *> parm;
for (int i = loops[loop_num_start]; i <= loops[loop_num_end]; i++)
parm.push_back(ir_controls[i]);
@@ -67,20 +66,21 @@ void finalize_loop(int loop_num_start, int loop_num_end) {
}
delete myloop;
}
+
void finalize_loop() {
int loop_num_start = get_loop_num_start();
int loop_num_end = get_loop_num_end();
finalize_loop(loop_num_start, loop_num_end);
}
+
static void init_loop(int loop_num_start, int loop_num_end) {
if (source_filename.empty()) {
- fprintf(stderr, "source file not set when initializing the loop");
+ CHILL_ERROR("source file not set when initializing the loop");
if (!is_interactive)
exit(2);
- }
- else {
+ } else {
if (ir_code == NULL) {
- ir_code = new IR_clangCode(source_filename.c_str(),procedure_name.c_str());
+ ir_code = new IR_clangCode(source_filename.c_str(), procedure_name.c_str());
IR_Block *block = ir_code->GetCode();
ir_controls = ir_code->FindOneLevelControlStructure(block);
for (int i = 0; i < ir_controls.size(); i++) {
@@ -90,25 +90,25 @@ static void init_loop(int loop_num_start, int loop_num_end) {
delete block;
}
if (myloop != NULL && myloop->isInitialized()) {
- finalize_loop();
+ finalize_loop();
}
}
set_loop_num_start(loop_num_start);
set_loop_num_end(loop_num_end);
if (loop_num_end < loop_num_start) {
- fprintf(stderr, "the last loop must be after the start loop");
+ CHILL_ERROR("the last loop must be after the start loop");
if (!is_interactive)
exit(2);
- }
+ }
if (loop_num_end >= loops.size()) {
- fprintf(stderr, "loop %d does not exist", loop_num_end);
+ CHILL_ERROR("loop %d does not exist", loop_num_end);
if (!is_interactive)
exit(2);
}
std::vector<IR_Control *> parm;
for (int i = loops[loop_num_start]; i <= loops[loop_num_end]; i++) {
if (ir_controls[i] == NULL) {
- fprintf(stderr, "loop has already been processed");
+ CHILL_ERROR("loop has already been processed");
if (!is_interactive)
exit(2);
}
@@ -116,7 +116,7 @@ static void init_loop(int loop_num_start, int loop_num_end) {
}
IR_Block *block = ir_code->MergeNeighboringControlStructures(parm);
myloop = new Loop(block);
- delete block;
+ delete block;
}
// ----------------------- //
@@ -124,11 +124,11 @@ static void init_loop(int loop_num_start, int loop_num_end) {
// ----------------------- //
// -- CHiLL support -- //
-static void strict_arg_num(PyObject* args, int arg_num, const char* fname = NULL) {
+static void strict_arg_num(PyObject *args, int arg_num, const char *fname = NULL) {
int arg_given = PyTuple_Size(args);
char msg[128];
- if(arg_num != arg_given) {
- if(fname)
+ if (arg_num != arg_given) {
+ if (fname)
sprintf(msg, "%s: expected %i arguments, was given %i.", fname, arg_num, arg_given);
else
sprintf(msg, "Expected %i argumets, was given %i.", arg_num, arg_given);
@@ -136,11 +136,11 @@ static void strict_arg_num(PyObject* args, int arg_num, const char* fname = NULL
}
}
-static int strict_arg_range(PyObject* args, int arg_min, int arg_max, const char* fname = NULL) {
+static int strict_arg_range(PyObject *args, int arg_min, int arg_max, const char *fname = NULL) {
int arg_given = PyTuple_Size(args);
char msg[128];
- if(arg_given < arg_min || arg_given > arg_max) {
- if(fname)
+ if (arg_given < arg_min || arg_given > arg_max) {
+ if (fname)
sprintf(msg, "%s: expected %i to %i arguments, was given %i.", fname, arg_min, arg_max, arg_given);
else
sprintf(msg, "Expected %i to %i, argumets, was given %i.", arg_min, arg_max, arg_given);
@@ -149,58 +149,58 @@ static int strict_arg_range(PyObject* args, int arg_min, int arg_max, const char
return arg_given;
}
-static int intArg(PyObject* args, int index, int dval = 0) {
- if(PyTuple_Size(args) <= index)
- return dval;
+static int intArg(PyObject *args, int index, int dval = 0) {
+ if (PyTuple_Size(args) <= index)
+ return dval;
int ival;
- PyObject *item = PyTuple_GetItem(args, index);
+ PyObject *item = PyTuple_GetItem(args, index);
Py_INCREF(item);
if (PyInt_Check(item)) ival = PyInt_AsLong(item);
else {
- fprintf(stderr, "argument at index %i is not an int\n", index);
+ CHILL_ERROR("argument at index %i is not an int\n", index);
exit(-1);
}
return ival;
}
-static std::string strArg(PyObject* args, int index, const char* dval = NULL) {
- if(PyTuple_Size(args) <= index)
+static std::string strArg(PyObject *args, int index, const char *dval = NULL) {
+ if (PyTuple_Size(args) <= index)
return dval;
std::string strval;
- PyObject *item = PyTuple_GetItem(args, index);
+ PyObject *item = PyTuple_GetItem(args, index);
Py_INCREF(item);
if (PyString_Check(item)) strval = strdup(PyString_AsString(item));
else {
- fprintf(stderr, "argument at index %i is not an string\n", index);
+ CHILL_ERROR("argument at index %i is not an string\n", index);
exit(-1);
}
return strval;
}
-static bool boolArg(PyObject* args, int index, bool dval = false) {
- if(PyTuple_Size(args) <= index)
+static bool boolArg(PyObject *args, int index, bool dval = false) {
+ if (PyTuple_Size(args) <= index)
return dval;
bool bval;
- PyObject* item = PyTuple_GetItem(args, index);
+ PyObject *item = PyTuple_GetItem(args, index);
Py_INCREF(item);
- return (bool)PyObject_IsTrue(item);
+ return (bool) PyObject_IsTrue(item);
}
-static bool tostringintmapvector(PyObject* args, int index, std::vector<std::map<std::string,int> >& vec) {
- if(PyTuple_Size(args) <= index)
+static bool tostringintmapvector(PyObject *args, int index, std::vector<std::map<std::string, int> > &vec) {
+ if (PyTuple_Size(args) <= index)
return false;
- PyObject* seq = PyTuple_GetItem(args, index);
+ PyObject *seq = PyTuple_GetItem(args, index);
//TODO: Typecheck
int seq_len = PyList_Size(seq);
- for(int i = 0; i < seq_len; i++) {
- std::map<std::string,int> map;
- PyObject* dict = PyList_GetItem(seq, i);
- PyObject* keys = PyDict_Keys(dict);
+ for (int i = 0; i < seq_len; i++) {
+ std::map<std::string, int> map;
+ PyObject *dict = PyList_GetItem(seq, i);
+ PyObject *keys = PyDict_Keys(dict);
//TODO: Typecheck
int dict_len = PyList_Size(keys);
- for(int j = 0; j < dict_len; j++) {
- PyObject* key = PyList_GetItem(keys, j);
- PyObject* value = PyDict_GetItem(dict, key);
+ for (int j = 0; j < dict_len; j++) {
+ PyObject *key = PyList_GetItem(keys, j);
+ PyObject *value = PyDict_GetItem(dict, key);
std::string str_key = strdup(PyString_AsString(key));
int int_value = PyInt_AsLong(value);
map[str_key] = int_value;
@@ -210,46 +210,47 @@ static bool tostringintmapvector(PyObject* args, int index, std::vector<std::map
return true;
}
-static bool tointvector(PyObject* seq, std::vector<int>& vec) {
+static bool tointvector(PyObject *seq, std::vector<int> &vec) {
//TODO: Typecheck
int seq_len = PyList_Size(seq);
- for(int i = 0; i < seq_len; i++) {
- PyObject* item = PyList_GetItem(seq, i);
+ for (int i = 0; i < seq_len; i++) {
+ PyObject *item = PyList_GetItem(seq, i);
vec.push_back(PyInt_AsLong(item));
}
return true;
}
-static bool tointvector(PyObject* args, int index, std::vector<int>& vec) {
- if(PyTuple_Size(args) <= index)
+static bool tointvector(PyObject *args, int index, std::vector<int> &vec) {
+ if (PyTuple_Size(args) <= index)
return false;
- PyObject* seq = PyTuple_GetItem(args, index);
+ PyObject *seq = PyTuple_GetItem(args, index);
return tointvector(seq, vec);
}
-static bool tointset(PyObject* args, int index, std::set<int>& set) {
- if(PyTuple_Size(args) <= index)
+static bool tointset(PyObject *args, int index, std::set<int> &set) {
+ if (PyTuple_Size(args) <= index)
return false;
- PyObject* seq = PyTuple_GetItem(args, index);
+ PyObject *seq = PyTuple_GetItem(args, index);
//TODO: Typecheck
int seq_len = PyList_Size(seq);
- for(int i = 0; i < seq_len; i++) {
- PyObject* item = PyList_GetItem(seq, i);
+ for (int i = 0; i < seq_len; i++) {
+ PyObject *item = PyList_GetItem(seq, i);
set.insert(PyInt_AsLong(item));
}
return true;
}
-static bool tointmatrix(PyObject* args, int index, std::vector<std::vector<int> >& mat) {
- if(PyTuple_Size(args) <= index)
+
+static bool tointmatrix(PyObject *args, int index, std::vector<std::vector<int> > &mat) {
+ if (PyTuple_Size(args) <= index)
return false;
- PyObject* seq_one = PyTuple_GetItem(args, index);
+ PyObject *seq_one = PyTuple_GetItem(args, index);
int seq_one_len = PyList_Size(seq_one);
- for(int i = 0; i < seq_one_len; i++) {
+ for (int i = 0; i < seq_one_len; i++) {
std::vector<int> vec;
- PyObject* seq_two = PyList_GetItem(seq_one, i);
+ PyObject *seq_two = PyList_GetItem(seq_one, i);
int seq_two_len = PyList_Size(seq_two);
- for(int j = 0; j < seq_two_len; j++) {
- PyObject* item = PyList_GetItem(seq_two, j);
+ for (int j = 0; j < seq_two_len; j++) {
+ PyObject *item = PyList_GetItem(seq_two, j);
vec.push_back(PyInt_AsLong(item));
}
mat.push_back(vec);
@@ -261,40 +262,38 @@ static bool tointmatrix(PyObject* args, int index, std::vector<std::vector<int>
// CHiLL interface functions //
// ------------------------- //
-static PyObject* chill_source(PyObject* self, PyObject* args) {
+static PyObject *chill_source(PyObject *self, PyObject *args) {
strict_arg_num(args, 1, "source");
source_filename = strArg(args, 0);
Py_RETURN_NONE;
}
-static PyObject* chill_procedure(PyObject* self, PyObject* args) {
- if(!procedure_name.empty()) {
- fprintf(stderr, "only one procedure can be handled in a script");
- if(!is_interactive)
+static PyObject *chill_procedure(PyObject *self, PyObject *args) {
+ if (!procedure_name.empty()) {
+ CHILL_ERROR("only one procedure can be handled in a script");
+ if (!is_interactive)
exit(2);
}
procedure_name = strArg(args, 0);
Py_RETURN_NONE;
}
-static PyObject* chill_loop(PyObject* self, PyObject* args) {
+static PyObject *chill_loop(PyObject *self, PyObject *args) {
// loop (n)
// loop (n:m)
-
+
int nargs = PyTuple_Size(args);
int start_num;
int end_num;
- if(nargs == 1) {
+ if (nargs == 1) {
start_num = intArg(args, 0);
end_num = start_num;
- }
- else if(nargs == 2) {
+ } else if (nargs == 2) {
start_num = intArg(args, 0);
end_num = intArg(args, 1);
- }
- else {
- fprintf(stderr, "loop takes one or two arguments");
- if(!is_interactive)
+ } else {
+ CHILL_ERROR("loop takes one or two arguments");
+ if (!is_interactive)
exit(2);
}
set_loop_num_start(start_num);
@@ -303,20 +302,20 @@ static PyObject* chill_loop(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}
-static PyObject* chill_print_code(PyObject* self, PyObject* args) {
+static PyObject *chill_print_code(PyObject *self, PyObject *args) {
strict_arg_num(args, 0, "print_code");
myloop->printCode();
printf("\n");
Py_RETURN_NONE;
}
-static PyObject* chill_print_dep(PyObject* self, PyObject* args) {
+static PyObject *chill_print_dep(PyObject *self, PyObject *args) {
strict_arg_num(args, 0, "print_dep");
myloop->printDependenceGraph();
Py_RETURN_NONE;
}
-static PyObject* chill_print_space(PyObject* self, PyObject* args) {
+static PyObject *chill_print_space(PyObject *self, PyObject *args) {
strict_arg_num(args, 0, "print_space");
myloop->printIterationSpace();
Py_RETURN_NONE;
@@ -324,9 +323,9 @@ static PyObject* chill_print_space(PyObject* self, PyObject* args) {
static void add_known(std::string cond_expr) {
int num_dim = myloop->known.n_set();
- std::vector<std::map<std::string, int> >* cond;
+ std::vector<std::map<std::string, int> > *cond;
cond = parse_relation_vector(cond_expr.c_str());
-
+
Relation rel(num_dim);
F_And *f_root = rel.add_and();
for (int j = 0; j < cond->size(); j++) {
@@ -358,21 +357,20 @@ static void add_known(std::string cond_expr) {
myloop->addKnown(rel);
}
-static PyObject* chill_known(PyObject* self, PyObject* args) {
+static PyObject *chill_known(PyObject *self, PyObject *args) {
strict_arg_num(args, 1, "known");
if (PyList_Check(PyTuple_GetItem(args, 0))) {
- PyObject* list = PyTuple_GetItem(args, 0);
+ PyObject *list = PyTuple_GetItem(args, 0);
for (int i = 0; i < PyList_Size(list); i++) {
add_known(std::string(PyString_AsString(PyList_GetItem(list, i))));
}
- }
- else {
+ } else {
add_known(strArg(args, 0));
}
Py_RETURN_NONE;
}
-static PyObject* chill_remove_dep(PyObject* self, PyObject* args) {
+static PyObject *chill_remove_dep(PyObject *self, PyObject *args) {
strict_arg_num(args, 0, "remove_dep");
int from = intArg(args, 0);
int to = intArg(args, 1);
@@ -380,45 +378,43 @@ static PyObject* chill_remove_dep(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}
-static PyObject* chill_original(PyObject* self, PyObject* args) {
+static PyObject *chill_original(PyObject *self, PyObject *args) {
strict_arg_num(args, 0, "original");
myloop->original();
Py_RETURN_NONE;
}
-static PyObject* chill_permute(PyObject* self, PyObject* args) {
+static PyObject *chill_permute(PyObject *self, PyObject *args) {
int nargs = strict_arg_range(args, 1, 3, "permute");
- if((nargs < 1) || (nargs > 3))
+ if ((nargs < 1) || (nargs > 3))
throw std::runtime_error("incorrect number of arguments in permute");
- if(nargs == 1) {
+ if (nargs == 1) {
// premute ( vector )
- std::vector<int> pi;
- if(!tointvector(args, 0, pi))
+ std::vector<int> pi;
+ if (!tointvector(args, 0, pi))
throw std::runtime_error("first arg in permute(pi) must be an int vector");
myloop->permute(pi);
- }
- else if (nargs == 2) {
+ } else if (nargs == 2) {
// permute ( set, vector )
std::set<int> active;
std::vector<int> pi;
- if(!tointset(args, 0, active))
+ if (!tointset(args, 0, active))
throw std::runtime_error("the first argument in permute(active, pi) must be an int set");
- if(!tointvector(args, 1, pi))
+ if (!tointvector(args, 1, pi))
throw std::runtime_error("the second argument in permute(active, pi) must be an int vector");
- myloop->permute(active, pi);
- }
- else if (nargs == 3) {
+ myloop->permute(active, pi);
+ } else if (nargs == 3) {
int stmt_num = intArg(args, 1);
int level = intArg(args, 2);
std::vector<int> pi;
- if(!tointvector(args, 3, pi))
+ if (!tointvector(args, 3, pi))
throw std::runtime_error("the third argument in permute(stmt_num, level, pi) must be an int vector");
myloop->permute(stmt_num, level, pi);
}
Py_RETURN_NONE;
}
-static PyObject* chill_pragma(PyObject* self, PyObject* args) {
+static PyObject *chill_pragma(PyObject *self, PyObject *args) {
strict_arg_num(args, 3, "pragma");
int stmt_num = intArg(args, 1);
int level = intArg(args, 1);
@@ -427,7 +423,7 @@ static PyObject* chill_pragma(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}
-static PyObject* chill_prefetch(PyObject* self, PyObject* args) {
+static PyObject *chill_prefetch(PyObject *self, PyObject *args) {
strict_arg_num(args, 3, "prefetch");
int stmt_num = intArg(args, 0);
int level = intArg(args, 1);
@@ -437,17 +433,16 @@ static PyObject* chill_prefetch(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}
-static PyObject* chill_tile(PyObject* self, PyObject* args) {
+static PyObject *chill_tile(PyObject *self, PyObject *args) {
int nargs = strict_arg_range(args, 3, 7, "tile");
int stmt_num = intArg(args, 0);
int level = intArg(args, 1);
int tile_size = intArg(args, 2);
- if(nargs == 3) {
+ if (nargs == 3) {
myloop->tile(stmt_num, level, tile_size);
- }
- else if(nargs >= 4) {
+ } else if (nargs >= 4) {
int outer_level = intArg(args, 3);
- if(nargs >= 5) {
+ if (nargs >= 5) {
TilingMethodType method = StridedTile;
int imethod = intArg(args, 4, 2); //< don't know if a default value is needed
// check method input against expected values
@@ -457,25 +452,25 @@ static PyObject* chill_tile(PyObject* self, PyObject* args) {
method = CountedTile;
else
throw std::runtime_error("5th argument must be either strided or counted");
- if(nargs >= 6) {
+ if (nargs >= 6) {
int alignment_offset = intArg(args, 5);
- if(nargs == 7) {
+ if (nargs == 7) {
int alignment_multiple = intArg(args, 6, 1);
myloop->tile(stmt_num, level, tile_size, outer_level, method, alignment_offset, alignment_multiple);
}
- if(nargs == 6)
+ if (nargs == 6)
myloop->tile(stmt_num, level, tile_size, outer_level, method, alignment_offset);
}
- if(nargs == 5)
+ if (nargs == 5)
myloop->tile(stmt_num, level, tile_size, outer_level, method);
}
- if(nargs == 4)
- myloop->tile(stmt_num, level, tile_size, outer_level);
+ if (nargs == 4)
+ myloop->tile(stmt_num, level, tile_size, outer_level);
}
Py_RETURN_NONE;
}
-static void chill_datacopy_vec(PyObject* args) {
+static void chill_datacopy_vec(PyObject *args) {
// Overload 1: bool datacopy(
// const std::vector<std::pair<int, std::vector<int> > > &array_ref_nums,
// int level,
@@ -487,28 +482,26 @@ static void chill_datacopy_vec(PyObject* args) {
std::vector<std::pair<int, std::vector<int> > > array_ref_nums;
// expect list(tuple(int,list(int)))
// or dict(int,list(int))
- if(PyList_CheckExact(PyTuple_GetItem(args, 0))) {
- PyObject* list = PyTuple_GetItem(args, 0);
- for(int i = 0; i < PyList_Size(list); i ++) {
- PyObject* tup = PyList_GetItem(list, i);
+ if (PyList_CheckExact(PyTuple_GetItem(args, 0))) {
+ PyObject *list = PyTuple_GetItem(args, 0);
+ for (int i = 0; i < PyList_Size(list); i++) {
+ PyObject *tup = PyList_GetItem(list, i);
int index = PyLong_AsLong(PyTuple_GetItem(tup, 0));
std::vector<int> vec;
tointvector(PyTuple_GetItem(tup, 1), vec);
array_ref_nums.push_back(std::pair<int, std::vector<int> >(index, vec));
}
- }
- else if(PyList_CheckExact(PyTuple_GetItem(args, 0))) {
- PyObject* dict = PyTuple_GetItem(args, 0);
- PyObject* klist = PyDict_Keys(dict);
- for(int ki = 0; ki < PyList_Size(klist); ki++) {
- PyObject* index = PyList_GetItem(klist, ki);
+ } else if (PyList_CheckExact(PyTuple_GetItem(args, 0))) {
+ PyObject *dict = PyTuple_GetItem(args, 0);
+ PyObject *klist = PyDict_Keys(dict);
+ for (int ki = 0; ki < PyList_Size(klist); ki++) {
+ PyObject *index = PyList_GetItem(klist, ki);
std::vector<int> vec;
- tointvector(PyDict_GetItem(dict,index), vec);
+ tointvector(PyDict_GetItem(dict, index), vec);
array_ref_nums.push_back(std::pair<int, std::vector<int> >(PyLong_AsLong(index), vec));
}
Py_DECREF(klist);
- }
- else {
+ } else {
//TODO: this should never happen
}
int level = intArg(args, 1);
@@ -517,34 +510,35 @@ static void chill_datacopy_vec(PyObject* args) {
int padding_stride = intArg(args, 4, 1);
int padding_alignment = intArg(args, 5, 4);
int memory_type = intArg(args, 6, 0);
- myloop->datacopy(array_ref_nums, level, allow_extra_read, fastest_changing_dimension, padding_stride, padding_alignment, memory_type);
+ myloop->datacopy(array_ref_nums, level, allow_extra_read, fastest_changing_dimension, padding_stride,
+ padding_alignment, memory_type);
}
-static void chill_datacopy_int(PyObject* args) {
+static void chill_datacopy_int(PyObject *args) {
int stmt_num = intArg(args, 0);
int level = intArg(args, 1);
- std::string array_name = strArg(args,2,0);
- bool allow_extra_read = boolArg(args,3,false);
+ std::string array_name = strArg(args, 2, 0);
+ bool allow_extra_read = boolArg(args, 3, false);
int fastest_changing_dimension = intArg(args, 4, -1);
int padding_stride = intArg(args, 5, 1);
int padding_alignment = intArg(args, 6, 4);
int memory_type = intArg(args, 7, 0);
- myloop->datacopy(stmt_num, level, array_name, allow_extra_read, fastest_changing_dimension, padding_stride, padding_alignment, memory_type);
+ myloop->datacopy(stmt_num, level, array_name, allow_extra_read, fastest_changing_dimension, padding_stride,
+ padding_alignment, memory_type);
}
-static PyObject* chill_datacopy(PyObject* self, PyObject* args) {
+static PyObject *chill_datacopy(PyObject *self, PyObject *args) {
// Overload 2: bool datacopy(int stmt_num, int level, const std::string &array_name, bool allow_extra_read = false, int fastest_changing_dimension = -1, int padding_stride = 1, int padding_alignment = 4, int memory_type = 0);
int nargs = strict_arg_range(args, 3, 7, "datacopy");
- if(PyList_CheckExact(PyTuple_GetItem(args,0)) || PyDict_CheckExact(PyTuple_GetItem(args, 0))) {
+ if (PyList_CheckExact(PyTuple_GetItem(args, 0)) || PyDict_CheckExact(PyTuple_GetItem(args, 0))) {
chill_datacopy_vec(args);
- }
- else {
+ } else {
chill_datacopy_int(args);
}
Py_RETURN_NONE;
}
-static PyObject* chill_datacopy_privatized(PyObject* self, PyObject* args) {
+static PyObject *chill_datacopy_privatized(PyObject *self, PyObject *args) {
// bool datacopy_privatized(int stmt_num, int level, const std::string &array_name, const std::vector<int> &privatized_levels, bool allow_extra_read = false, int fastest_changing_dimension = -1, int padding_stride = 1, int padding_alignment = 1, int memory_type = 0);
int nargs = strict_arg_range(args, 4, 9, "datacopy_privatized");
int stmt_num = intArg(args, 0);
@@ -557,43 +551,44 @@ static PyObject* chill_datacopy_privatized(PyObject* self, PyObject* args) {
int padding_stride = intArg(args, 6, 1);
int padding_alignment = intArg(args, 7, 1);
int memory_type = intArg(args, 8);
- myloop->datacopy_privatized(stmt_num, level, array_name, privatized_levels, allow_extra_read, fastest_changing_dimension, padding_stride, padding_alignment, memory_type);
+ myloop->datacopy_privatized(stmt_num, level, array_name, privatized_levels, allow_extra_read,
+ fastest_changing_dimension, padding_stride, padding_alignment, memory_type);
Py_RETURN_NONE;
}
-static PyObject* chill_unroll(PyObject* self, PyObject* args) {
+static PyObject *chill_unroll(PyObject *self, PyObject *args) {
int nargs = strict_arg_range(args, 3, 4, "unroll");
//std::set<int> unroll(int stmt_num, int level, int unroll_amount, std::vector< std::vector<std::string> >idxNames= std::vector< std::vector<std::string> >(), int cleanup_split_level = 0);
int stmt_num = intArg(args, 0);
int level = intArg(args, 1);
int unroll_amount = intArg(args, 2);
- std::vector< std::vector<std::string> > idxNames = std::vector< std::vector<std::string> >();
+ std::vector<std::vector<std::string> > idxNames = std::vector<std::vector<std::string> >();
int cleanup_split_level = intArg(args, 3);
myloop->unroll(stmt_num, level, unroll_amount, idxNames, cleanup_split_level);
Py_RETURN_NONE;
}
-
-static PyObject* chill_unroll_extra(PyObject* self, PyObject* args) {
+
+static PyObject *chill_unroll_extra(PyObject *self, PyObject *args) {
int nargs = strict_arg_range(args, 3, 4, "unroll_extra");
int stmt_num = intArg(args, 0);
int level = intArg(args, 1);
int unroll_amount = intArg(args, 2);
int cleanup_split_level = intArg(args, 3, 0);
- myloop->unroll_extra(stmt_num, level, unroll_amount, cleanup_split_level);
+ myloop->unroll_extra(stmt_num, level, unroll_amount, cleanup_split_level);
Py_RETURN_NONE;
}
-
-static PyObject* chill_split(PyObject* self, PyObject* args) {
+
+static PyObject *chill_split(PyObject *self, PyObject *args) {
strict_arg_num(args, 3, "split");
int stmt_num = intArg(args, 0);
int level = intArg(args, 1);
int num_dim = myloop->stmt[stmt_num].xform.n_out();
-
- std::vector<std::map<std::string, int> >* cond;
+
+ std::vector<std::map<std::string, int> > *cond;
std::string cond_expr = strArg(args, 2);
cond = parse_relation_vector(cond_expr.c_str());
-
- Relation rel((num_dim-1)/2);
+
+ Relation rel((num_dim - 1) / 2);
F_And *f_root = rel.add_and();
for (int j = 0; j < cond->size(); j++) {
GEQ_Handle h = f_root->add_GEQ();
@@ -603,7 +598,7 @@ static PyObject* chill_split(PyObject* self, PyObject* args) {
if (dim == 0)
h.update_const(it->second);
else {
- if (dim > (num_dim-1)/2)
+ if (dim > (num_dim - 1) / 2)
throw std::invalid_argument("invalid loop level " + to_string(dim) + " in split condition");
h.update_coef(rel.set_var(dim), it->second);
}
@@ -623,18 +618,18 @@ static PyObject* chill_split(PyObject* self, PyObject* args) {
}
}
}
- myloop->split(stmt_num,level,rel);
+ myloop->split(stmt_num, level, rel);
Py_RETURN_NONE;
}
-static PyObject* chill_nonsingular(PyObject* self, PyObject* args) {
- std::vector< std::vector<int> > mat;
+static PyObject *chill_nonsingular(PyObject *self, PyObject *args) {
+ std::vector<std::vector<int> > mat;
tointmatrix(args, 0, mat);
myloop->nonsingular(mat);
Py_RETURN_NONE;
}
-static PyObject* chill_skew(PyObject* self, PyObject* args) {
+static PyObject *chill_skew(PyObject *self, PyObject *args) {
std::set<int> stmt_nums;
std::vector<int> skew_amounts;
int level = intArg(args, 1);
@@ -644,7 +639,7 @@ static PyObject* chill_skew(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}
-static PyObject* chill_scale(PyObject* self, PyObject* args) {
+static PyObject *chill_scale(PyObject *self, PyObject *args) {
strict_arg_num(args, 3);
std::set<int> stmt_nums;
int level = intArg(args, 1);
@@ -654,7 +649,7 @@ static PyObject* chill_scale(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}
-static PyObject* chill_reverse(PyObject* self, PyObject* args) {
+static PyObject *chill_reverse(PyObject *self, PyObject *args) {
strict_arg_num(args, 2);
std::set<int> stmt_nums;
int level = intArg(args, 1);
@@ -663,7 +658,7 @@ static PyObject* chill_reverse(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}
-static PyObject* chill_shift(PyObject* self, PyObject* args) {
+static PyObject *chill_shift(PyObject *self, PyObject *args) {
strict_arg_num(args, 3);
std::set<int> stmt_nums;
int level = intArg(args, 1);
@@ -673,7 +668,7 @@ static PyObject* chill_shift(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}
-static PyObject* chill_shift_to(PyObject* self, PyObject* args) {
+static PyObject *chill_shift_to(PyObject *self, PyObject *args) {
strict_arg_num(args, 3);
int stmt_num = intArg(args, 0);
int level = intArg(args, 1);
@@ -682,7 +677,7 @@ static PyObject* chill_shift_to(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}
-static PyObject* chill_peel(PyObject* self, PyObject* args) {
+static PyObject *chill_peel(PyObject *self, PyObject *args) {
strict_arg_range(args, 2, 3);
int stmt_num = intArg(args, 0);
int level = intArg(args, 1);
@@ -691,7 +686,7 @@ static PyObject* chill_peel(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}
-static PyObject* chill_fuse(PyObject* self, PyObject* args) {
+static PyObject *chill_fuse(PyObject *self, PyObject *args) {
strict_arg_num(args, 2);
std::set<int> stmt_nums;
int level = intArg(args, 1);
@@ -700,7 +695,7 @@ static PyObject* chill_fuse(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}
-static PyObject* chill_distribute(PyObject* self, PyObject* args) {
+static PyObject *chill_distribute(PyObject *self, PyObject *args) {
strict_arg_num(args, 2);
std::set<int> stmts;
int level = intArg(args, 1);
@@ -710,49 +705,48 @@ static PyObject* chill_distribute(PyObject* self, PyObject* args) {
}
static PyObject *
-chill_num_statements(PyObject *self, PyObject *args)
-{
+chill_num_statements(PyObject *self, PyObject *args) {
//DEBUG_PRINT("\nC chill_num_statements() called from python\n");
int num = myloop->stmt.size();
//DEBUG_PRINT("C num_statement() = %d\n", num);
- return Py_BuildValue( "i", num ); // BEWARE "d" is DOUBLE, not int
-}
-
-static PyMethodDef ChillMethods[] = {
-
- //python name C routine parameter passing comment
- {"source", chill_source, METH_VARARGS, "set source file for chill script"},
- {"procedure", chill_procedure, METH_VARARGS, "set the name of the procedure"},
- {"loop", chill_loop, METH_VARARGS, "indicate which loop to optimize"},
- {"print_code", chill_print_code, METH_VARARGS, "print generated code"},
- {"print_dep", chill_print_dep, METH_VARARGS, "print the dependencies graph"},
- {"print_space", chill_print_space, METH_VARARGS, "print space"},
- {"known", chill_known, METH_VARARGS, "knwon"},
- {"remove_dep", chill_remove_dep, METH_VARARGS, "remove dependency i suppose"},
- {"original", chill_original, METH_VARARGS, "original"},
- {"permute", chill_permute, METH_VARARGS, "permute"},
- {"pragma", chill_pragma, METH_VARARGS, "pragma"},
- {"prefetch", chill_prefetch, METH_VARARGS, "prefetch"},
- {"tile", chill_tile, METH_VARARGS, "tile"},
- {"datacopy", chill_datacopy, METH_VARARGS, "datacopy"},
- {"datacopy_privitized", chill_datacopy_privatized, METH_VARARGS, "datacopy_privatized"},
- {"unroll", chill_unroll, METH_VARARGS, "unroll"},
- {"unroll_extra", chill_unroll_extra, METH_VARARGS, "unroll_extra"},
- {"split", chill_split, METH_VARARGS, "split"},
- {"nonsingular", chill_nonsingular, METH_VARARGS, "nonsingular"},
- {"skew", chill_skew, METH_VARARGS, "skew"},
- {"scale", chill_scale, METH_VARARGS, "scale"},
- {"reverse", chill_reverse, METH_VARARGS, "reverse"},
- {"shift", chill_shift, METH_VARARGS, "shift"},
- {"shift_to", chill_shift_to, METH_VARARGS, "shift_to"},
- {"peel", chill_peel, METH_VARARGS, "peel"},
- {"fuse", chill_fuse, METH_VARARGS, "fuse"},
- {"distribute", chill_distribute, METH_VARARGS, "distribute"},
- {"num_statements", chill_num_statements, METH_VARARGS, "number of statements in the current loop"},
- {NULL, NULL, 0, NULL}
+ return Py_BuildValue("i", num); // BEWARE "d" is DOUBLE, not int
+}
+
+static PyMethodDef ChillMethods[] = {
+
+ //python name C routine parameter passing comment
+ {"source", chill_source, METH_VARARGS, "set source file for chill script"},
+ {"procedure", chill_procedure, METH_VARARGS, "set the name of the procedure"},
+ {"loop", chill_loop, METH_VARARGS, "indicate which loop to optimize"},
+ {"print_code", chill_print_code, METH_VARARGS, "print generated code"},
+ {"print_dep", chill_print_dep, METH_VARARGS, "print the dependencies graph"},
+ {"print_space", chill_print_space, METH_VARARGS, "print space"},
+ {"known", chill_known, METH_VARARGS, "knwon"},
+ {"remove_dep", chill_remove_dep, METH_VARARGS, "remove dependency i suppose"},
+ {"original", chill_original, METH_VARARGS, "original"},
+ {"permute", chill_permute, METH_VARARGS, "permute"},
+ {"pragma", chill_pragma, METH_VARARGS, "pragma"},
+ {"prefetch", chill_prefetch, METH_VARARGS, "prefetch"},
+ {"tile", chill_tile, METH_VARARGS, "tile"},
+ {"datacopy", chill_datacopy, METH_VARARGS, "datacopy"},
+ {"datacopy_privitized", chill_datacopy_privatized, METH_VARARGS, "datacopy_privatized"},
+ {"unroll", chill_unroll, METH_VARARGS, "unroll"},
+ {"unroll_extra", chill_unroll_extra, METH_VARARGS, "unroll_extra"},
+ {"split", chill_split, METH_VARARGS, "split"},
+ {"nonsingular", chill_nonsingular, METH_VARARGS, "nonsingular"},
+ {"skew", chill_skew, METH_VARARGS, "skew"},
+ {"scale", chill_scale, METH_VARARGS, "scale"},
+ {"reverse", chill_reverse, METH_VARARGS, "reverse"},
+ {"shift", chill_shift, METH_VARARGS, "shift"},
+ {"shift_to", chill_shift_to, METH_VARARGS, "shift_to"},
+ {"peel", chill_peel, METH_VARARGS, "peel"},
+ {"fuse", chill_fuse, METH_VARARGS, "fuse"},
+ {"distribute", chill_distribute, METH_VARARGS, "distribute"},
+ {"num_statements", chill_num_statements, METH_VARARGS, "number of statements in the current loop"},
+ {NULL, NULL, 0, NULL}
};
-static void register_globals(PyObject* m) {
+static void register_globals(PyObject *m) {
// Preset globals
PyModule_AddStringConstant(m, "VERSION", CHILL_BUILD_VERSION);
PyModule_AddStringConstant(m, "dest", "C");
@@ -766,12 +760,12 @@ static void register_globals(PyObject* m) {
PyModule_AddIntConstant(m, "textured", 2);
// Bool flags
PyModule_AddIntConstant(m, "sync", 1);
-}
+}
PyMODINIT_FUNC
initchill(void) // pass C methods to python
{
- CHILL_DEBUG_PRINT("in C, initchill() to set up C methods to be called from python\n");
- PyObject* m = Py_InitModule("chill", ChillMethods);
+ CHILL_DEBUG_PRINT("set up C methods to be called from python\n");
+ PyObject *m = Py_InitModule("chill", ChillMethods);
register_globals(m);
}
diff --git a/src/dep.cc b/src/dep.cc
index e47d7aa..7439dd2 100644
--- a/src/dep.cc
+++ b/src/dep.cc
@@ -26,51 +26,51 @@
// Class: DependeceVector
//-----------------------------------------------------------------------------
-std::ostream& operator<<(std::ostream &os, const DependenceVector &d) {
+std::ostream &operator<<(std::ostream &os, const DependenceVector &d) {
if (d.sym != NULL) {
os << d.sym->name();
os << ':';
if (d.quasi)
os << "_quasi";
-
+
}
-
+
switch (d.type) {
- case DEP_W2R:
- os << "flow";
- // Check for reduction implemetation correctness
- if (d.is_reduction)
- os << "_reduction";
- break;
- case DEP_R2W:
- os << "anti";
- // TODO: Remove Check for reduction implemetation correctness
- if (d.is_reduction)
- os << "_reduction";
- break;
- case DEP_W2W:
- os << "output";
- // TODO: Remove Check for reduction implemetation correctness
- if (d.is_reduction)
- os << "_reduction";
- break;
- case DEP_R2R:
- os << "input";
- break;
- case DEP_CONTROL:
- os << "control";
- break;
- default:
- os << "unknown";
- break;
+ case DEP_W2R:
+ os << "flow";
+ // Check for reduction implemetation correctness
+ if (d.is_reduction)
+ os << "_reduction";
+ break;
+ case DEP_R2W:
+ os << "anti";
+ // TODO: Remove Check for reduction implemetation correctness
+ if (d.is_reduction)
+ os << "_reduction";
+ break;
+ case DEP_W2W:
+ os << "output";
+ // TODO: Remove Check for reduction implemetation correctness
+ if (d.is_reduction)
+ os << "_reduction";
+ break;
+ case DEP_R2R:
+ os << "input";
+ break;
+ case DEP_CONTROL:
+ os << "control";
+ break;
+ default:
+ os << "unknown";
+ break;
}
-
+
os << '(';
-
+
for (int i = 0; i < d.lbounds.size(); i++) {
omega::coef_t lbound = d.lbounds[i];
omega::coef_t ubound = d.ubounds[i];
-
+
if (lbound == ubound)
os << lbound;
else {
@@ -91,13 +91,13 @@ std::ostream& operator<<(std::ostream &os, const DependenceVector &d) {
} else
os << lbound << '~' << ubound;
}
-
+
if (i < d.lbounds.size() - 1)
os << ", ";
}
-
+
os << ')';
-
+
return os;
}
@@ -139,6 +139,7 @@ DependenceVector &DependenceVector::operator=(const DependenceVector &that) {
}
return *this;
}
+
DependenceType DependenceVector::getType() const {
return type;
}
@@ -161,14 +162,14 @@ bool DependenceVector::is_control_dependence() const {
bool DependenceVector::has_negative_been_carried_at(int dim) const {
if (!is_data_dependence())
throw std::invalid_argument("only works for data dependences");
-
+
if (dim < 0 || dim >= lbounds.size())
return false;
-
+
for (int i = 0; i < dim; i++)
if (lbounds[i] > 0 || ubounds[i] < 0)
return false;
-
+
if (lbounds[dim] < 0)
return true;
else
@@ -179,36 +180,36 @@ bool DependenceVector::has_negative_been_carried_at(int dim) const {
bool DependenceVector::has_been_carried_at(int dim) const {
if (!is_data_dependence())
throw std::invalid_argument("only works for data dependences");
-
+
if (dim < 0 || dim >= lbounds.size())
return false;
-
+
for (int i = 0; i < dim; i++)
if (lbounds[i] > 0 || ubounds[i] < 0)
return false;
-
- if ((lbounds[dim] != 0) || (ubounds[dim] !=0))
+
+ if ((lbounds[dim] != 0) || (ubounds[dim] != 0))
return true;
-
+
return false;
}
bool DependenceVector::has_been_carried_before(int dim) const {
if (!is_data_dependence())
throw std::invalid_argument("only works for data dependences");
-
+
if (dim < 0)
return false;
if (dim > lbounds.size())
dim = lbounds.size();
-
+
for (int i = 0; i < dim; i++) {
if (lbounds[i] > 0)
return true;
if (ubounds[i] < 0)
return true;
}
-
+
return false;
}
@@ -219,11 +220,11 @@ bool DependenceVector::isZero() const {
bool DependenceVector::isZero(int dim) const {
if (dim >= lbounds.size())
throw std::invalid_argument("invalid dependence dimension");
-
+
for (int i = 0; i <= dim; i++)
if (lbounds[i] != 0 || ubounds[i] != 0)
return false;
-
+
return true;
}
@@ -235,7 +236,7 @@ bool DependenceVector::isPositive() const {
else if (lbounds[i] > 0)
return true;
}
-
+
return false;
}
@@ -247,7 +248,7 @@ bool DependenceVector::isNegative() const {
else if (ubounds[i] < 0)
return true;
}
-
+
return false;
}
@@ -255,7 +256,7 @@ bool DependenceVector::isAllPositive() const {
for (int i = 0; i < lbounds.size(); i++)
if (lbounds[i] < 0)
return false;
-
+
return true;
}
@@ -263,14 +264,14 @@ bool DependenceVector::isAllNegative() const {
for (int i = 0; i < ubounds.size(); i++)
if (ubounds[i] > 0)
return false;
-
+
return true;
}
bool DependenceVector::hasPositive(int dim) const {
if (dim >= lbounds.size())
throw std::invalid_argument("invalid dependence dimension");
-
+
if (lbounds[dim] > 0)
//av: changed from ubounds to lbounds may have side effects
return true;
@@ -281,7 +282,7 @@ bool DependenceVector::hasPositive(int dim) const {
bool DependenceVector::hasNegative(int dim) const {
if (dim >= lbounds.size())
throw std::invalid_argument("invalid dependence dimension");
-
+
if (ubounds[dim] < 0)
//av: changed from lbounds to ubounds may have side effects
return true;
@@ -292,45 +293,45 @@ bool DependenceVector::hasNegative(int dim) const {
bool DependenceVector::isCarried(int dim, omega::coef_t distance) const {
if (distance <= 0)
throw std::invalid_argument("invalid dependence distance size");
-
+
if (dim > lbounds.size())
dim = lbounds.size();
-
+
for (int i = 0; i < dim; i++)
if (lbounds[i] > 0)
return false;
else if (ubounds[i] < 0)
return false;
-
+
if (dim >= lbounds.size())
return true;
-
+
if (lbounds[dim] > distance)
return false;
else if (ubounds[dim] < -distance)
return false;
-
+
return true;
}
bool DependenceVector::canPermute(const std::vector<int> &pi) const {
if (pi.size() != lbounds.size())
throw std::invalid_argument(
- "permute dimensionality do not match dependence space");
-
+ "permute dimensionality do not match dependence space");
+
for (int i = 0; i < pi.size(); i++) {
if (lbounds[pi[i]] > 0)
return true;
else if (lbounds[pi[i]] < 0)
return false;
}
-
+
return true;
}
std::vector<DependenceVector> DependenceVector::normalize() const {
std::vector<DependenceVector> result;
-
+
DependenceVector dv(*this);
for (int i = 0; i < dv.lbounds.size(); i++) {
if (dv.lbounds[i] < 0 && dv.ubounds[i] >= 0) {
@@ -351,63 +352,63 @@ std::vector<DependenceVector> DependenceVector::normalize() const {
else
break;
}
-
+
result.push_back(dv);
return result;
}
std::vector<DependenceVector> DependenceVector::permute(
- const std::vector<int> &pi) const {
+ const std::vector<int> &pi) const {
if (pi.size() != lbounds.size())
throw std::invalid_argument(
- "permute dimensionality do not match dependence space");
-
+ "permute dimensionality do not match dependence space");
+
const int n = lbounds.size();
-
+
DependenceVector dv(*this);
for (int i = 0; i < n; i++) {
dv.lbounds[i] = lbounds[pi[i]];
dv.ubounds[i] = ubounds[pi[i]];
}
-
+
int violated = 0;
-
+
for (int i = 0; i < n; i++) {
if (dv.lbounds[i] > 0)
break;
else if (dv.lbounds[i] < 0)
violated = 1;
}
-
+
if (((violated == 1) && !quasi) && !is_scalar_dependence) {
throw ir_error("dependence violation");
-
+
}
-
+
return dv.normalize();
}
DependenceVector DependenceVector::reverse() const {
const int n = lbounds.size();
-
+
DependenceVector dv(*this);
switch (type) {
- case DEP_W2R:
- dv.type = DEP_R2W;
- break;
- case DEP_R2W:
- dv.type = DEP_W2R;
- break;
- default:
- dv.type = type;
+ case DEP_W2R:
+ dv.type = DEP_R2W;
+ break;
+ case DEP_R2W:
+ dv.type = DEP_W2R;
+ break;
+ default:
+ dv.type = type;
}
-
+
for (int i = 0; i < n; i++) {
dv.lbounds[i] = -ubounds[i];
dv.ubounds[i] = -lbounds[i];
}
dv.quasi = true;
-
+
return dv;
}
@@ -473,10 +474,10 @@ DependenceVector DependenceVector::reverse() const {
DependenceGraph DependenceGraph::permute(const std::vector<int> &pi,
const std::set<int> &active) const {
DependenceGraph g;
-
+
for (int i = 0; i < vertex.size(); i++)
g.insert(vertex[i].first);
-
+
for (int i = 0; i < vertex.size(); i++)
for (EdgeList::const_iterator j = vertex[i].second.begin();
j != vertex[i].second.end(); j++) {
@@ -502,7 +503,7 @@ DependenceGraph DependenceGraph::permute(const std::vector<int> &pi,
g.connect(i, j->first, dv);
}
}
-
+
return g;
}
@@ -522,23 +523,23 @@ DependenceGraph DependenceGraph::permute(const std::vector<int> &pi,
DependenceGraph DependenceGraph::subspace(int dim) const {
DependenceGraph g;
-
+
for (int i = 0; i < vertex.size(); i++)
g.insert(vertex[i].first);
-
+
for (int i = 0; i < vertex.size(); i++)
for (EdgeList::const_iterator j = vertex[i].second.begin();
j != vertex[i].second.end(); j++)
-
+
for (int k = 0; k < j->second.size(); k++) {
- if(j->second[k].type != DEP_CONTROL){
+ if (j->second[k].type != DEP_CONTROL) {
if (j->second[k].isCarried(dim))
g.connect(i, j->first, j->second[k]);
- }else
+ } else
g.connect(i, j->first, j->second[k]);
-
+
}
-
+
return g;
}
@@ -549,7 +550,7 @@ bool DependenceGraph::isPositive() const {
for (int k = 0; k < j->second.size(); k++)
if (!j->second[k].isPositive())
return false;
-
+
return true;
}
@@ -560,7 +561,7 @@ bool DependenceGraph::hasPositive(int dim) const {
for (int k = 0; k < j->second.size(); k++)
if (!j->second[k].hasPositive(dim))
return false;
-
+
return true;
}
@@ -571,6 +572,6 @@ bool DependenceGraph::hasNegative(int dim) const {
for (int k = 0; k < j->second.size(); k++)
if (!j->second[k].hasNegative(dim))
return false;
-
+
return true;
}
diff --git a/src/ir_clang.cc b/src/ir_clang.cc
index 0c56cf0..c8a0c12 100755
--- a/src/ir_clang.cc
+++ b/src/ir_clang.cc
@@ -21,7 +21,7 @@ History:
#include "loop.hh"
#include "chill_error.hh"
-#define DUMPFUNC(x, y) std::cerr << "In function " << x << "\n"; y->dump();
+#define DUMPFUNC(x, y) std::cerr << "In function " << x << "\n"; y->dump();
#include "clang/Frontend/FrontendActions.h"
#include <clang/CodeGen/CodeGenAction.h>
@@ -47,29 +47,48 @@ History:
// TODO move to ir_clang.hh
// fwd declarations
-chillAST_node * ConvertVarDecl( clang::VarDecl *D, chillAST_node * );
-chillAST_node * ConvertTypeDefDecl( clang::TypedefDecl *TDD, chillAST_node * );
-chillAST_node * ConvertRecordDecl( clang::RecordDecl *D, chillAST_node * );
-chillAST_node * ConvertDeclStmt( clang::DeclStmt *clangDS, chillAST_node * );
-chillAST_node * ConvertCompoundStmt( clang::CompoundStmt *clangCS, chillAST_node * );
-chillAST_node * ConvertFunctionDecl( clang::FunctionDecl *D , chillAST_node *);
-chillAST_node * ConvertForStmt( clang::ForStmt *clangFS, chillAST_node * );
-chillAST_node * ConvertUnaryOperator( clang::UnaryOperator * clangU, chillAST_node *O );
-chillAST_node * ConvertBinaryOperator( clang::BinaryOperator * clangBO, chillAST_node *B );
-chillAST_node * ConvertArraySubscriptExpr( clang::ArraySubscriptExpr *clangASE, chillAST_node * );
-chillAST_node * ConvertDeclRefExpr( clang::DeclRefExpr * clangDRE, chillAST_node * );
-chillAST_node * ConvertIntegerLiteral( clang::IntegerLiteral *clangIL, chillAST_node * );
-chillAST_node * ConvertFloatingLiteral( clang::FloatingLiteral *clangFL, chillAST_node * );
-chillAST_node * ConvertImplicitCastExpr( clang::ImplicitCastExpr *clangICE, chillAST_node * );
-chillAST_node * ConvertCStyleCastExpr( clang::CStyleCastExpr *clangICE, chillAST_node * );
-chillAST_node * ConvertReturnStmt( clang::ReturnStmt *clangRS, chillAST_node * );
-chillAST_node * ConvertCallExpr( clang::CallExpr *clangCE , chillAST_node *);
-chillAST_node * ConvertIfStmt( clang::IfStmt *clangIS , chillAST_node *);
-chillAST_node * ConvertMemberExpr( clang::MemberExpr *clangME , chillAST_node *);
-
-
-chillAST_node * ConvertTranslationUnit( clang::TranslationUnitDecl *TUD, char *filename );
-chillAST_node * ConvertGenericClangAST( clang::Stmt *s, chillAST_node * );
+chillAST_node *ConvertVarDecl(clang::VarDecl *D, chillAST_node *);
+
+chillAST_node *ConvertTypeDefDecl(clang::TypedefDecl *TDD, chillAST_node *);
+
+chillAST_node *ConvertRecordDecl(clang::RecordDecl *D, chillAST_node *);
+
+chillAST_node *ConvertDeclStmt(clang::DeclStmt *clangDS, chillAST_node *);
+
+chillAST_node *ConvertCompoundStmt(clang::CompoundStmt *clangCS, chillAST_node *);
+
+chillAST_node *ConvertFunctionDecl(clang::FunctionDecl *D, chillAST_node *);
+
+chillAST_node *ConvertForStmt(clang::ForStmt *clangFS, chillAST_node *);
+
+chillAST_node *ConvertUnaryOperator(clang::UnaryOperator *clangU, chillAST_node *O);
+
+chillAST_node *ConvertBinaryOperator(clang::BinaryOperator *clangBO, chillAST_node *B);
+
+chillAST_node *ConvertArraySubscriptExpr(clang::ArraySubscriptExpr *clangASE, chillAST_node *);
+
+chillAST_node *ConvertDeclRefExpr(clang::DeclRefExpr *clangDRE, chillAST_node *);
+
+chillAST_node *ConvertIntegerLiteral(clang::IntegerLiteral *clangIL, chillAST_node *);
+
+chillAST_node *ConvertFloatingLiteral(clang::FloatingLiteral *clangFL, chillAST_node *);
+
+chillAST_node *ConvertImplicitCastExpr(clang::ImplicitCastExpr *clangICE, chillAST_node *);
+
+chillAST_node *ConvertCStyleCastExpr(clang::CStyleCastExpr *clangICE, chillAST_node *);
+
+chillAST_node *ConvertReturnStmt(clang::ReturnStmt *clangRS, chillAST_node *);
+
+chillAST_node *ConvertCallExpr(clang::CallExpr *clangCE, chillAST_node *);
+
+chillAST_node *ConvertIfStmt(clang::IfStmt *clangIS, chillAST_node *);
+
+chillAST_node *ConvertMemberExpr(clang::MemberExpr *clangME, chillAST_node *);
+
+
+chillAST_node *ConvertTranslationUnit(clang::TranslationUnitDecl *TUD, char *filename);
+
+chillAST_node *ConvertGenericClangAST(clang::Stmt *s, chillAST_node *);
std::vector<chillAST_VarDecl *> VariableDeclarations;
@@ -82,89 +101,99 @@ using namespace std;
static string binops[] = {
- " ", " ", // BO_PtrMemD, BO_PtrMemI, // [C++ 5.5] Pointer-to-member operators.
- "*", "/", "%", // BO_Mul, BO_Div, BO_Rem, // [C99 6.5.5] Multiplicative operators.
- "+", "-", // BO_Add, BO_Sub, // [C99 6.5.6] Additive operators.
- "<<", ">>", // BO_Shl, BO_Shr, // [C99 6.5.7] Bitwise shift operators.
- "<", ">", "<=", ">=", // BO_LT, BO_GT, BO_LE, BO_GE, // [C99 6.5.8] Relational operators.
- "==", "!=", // BO_EQ, BO_NE, // [C99 6.5.9] Equality operators.
- "&", // BO_And, // [C99 6.5.10] Bitwise AND operator.
- "??", // BO_Xor, // [C99 6.5.11] Bitwise XOR operator.
- "|", // BO_Or, // [C99 6.5.12] Bitwise OR operator.
- "&&", // BO_LAnd, // [C99 6.5.13] Logical AND operator.
- "||", // BO_LOr, // [C99 6.5.14] Logical OR operator.
- "=", "*=", // BO_Assign, BO_MulAssign, // [C99 6.5.16] Assignment operators.
- "/=", "%=", // BO_DivAssign, BO_RemAssign,
- "+=", "-=", // BO_AddAssign, BO_SubAssign,
- "???", "???", // BO_ShlAssign, BO_ShrAssign,
- "&&=", "???", // BO_AndAssign, BO_XorAssign,
- "||=", // BO_OrAssign,
- ","}; // BO_Comma // [C99 6.5.17] Comma operator.
+ " ", " ", // BO_PtrMemD, BO_PtrMemI, // [C++ 5.5] Pointer-to-member operators.
+ "*", "/", "%", // BO_Mul, BO_Div, BO_Rem, // [C99 6.5.5] Multiplicative operators.
+ "+", "-", // BO_Add, BO_Sub, // [C99 6.5.6] Additive operators.
+ "<<", ">>", // BO_Shl, BO_Shr, // [C99 6.5.7] Bitwise shift operators.
+ "<", ">", "<=", ">=", // BO_LT, BO_GT, BO_LE, BO_GE, // [C99 6.5.8] Relational operators.
+ "==", "!=", // BO_EQ, BO_NE, // [C99 6.5.9] Equality operators.
+ "&", // BO_And, // [C99 6.5.10] Bitwise AND operator.
+ "??", // BO_Xor, // [C99 6.5.11] Bitwise XOR operator.
+ "|", // BO_Or, // [C99 6.5.12] Bitwise OR operator.
+ "&&", // BO_LAnd, // [C99 6.5.13] Logical AND operator.
+ "||", // BO_LOr, // [C99 6.5.14] Logical OR operator.
+ "=", "*=", // BO_Assign, BO_MulAssign, // [C99 6.5.16] Assignment operators.
+ "/=", "%=", // BO_DivAssign, BO_RemAssign,
+ "+=", "-=", // BO_AddAssign, BO_SubAssign,
+ "???", "???", // BO_ShlAssign, BO_ShrAssign,
+ "&&=", "???", // BO_AndAssign, BO_XorAssign,
+ "||=", // BO_OrAssign,
+ ","}; // BO_Comma // [C99 6.5.17] Comma operator.
static string unops[] = {
- "++", "--", // [C99 6.5.2.4] Postfix increment and decrement
- "++", "--", // [C99 6.5.3.1] Prefix increment and decrement
- "@", "*", // [C99 6.5.3.2] Address and indirection
- "+", "-", // [C99 6.5.3.3] Unary arithmetic
- "~", "!", // [C99 6.5.3.3] Unary arithmetic
- "__real", "__imag", // "__real expr"/"__imag expr" Extension.
- "__extension" // __extension__ marker.
+ "++", "--", // [C99 6.5.2.4] Postfix increment and decrement
+ "++", "--", // [C99 6.5.3.1] Prefix increment and decrement
+ "@", "*", // [C99 6.5.3.2] Address and indirection
+ "+", "-", // [C99 6.5.3.3] Unary arithmetic
+ "~", "!", // [C99 6.5.3.3] Unary arithmetic
+ "__real", "__imag", // "__real expr"/"__imag expr" Extension.
+ "__extension" // __extension__ marker.
};
// forward defs
-SourceManager * globalSRCMAN; // ugly. shame.
+SourceManager *globalSRCMAN; // ugly. shame.
+
+char *splitTypeInfo(char *underlyingtype);
+
+void printsourceline(const char *filename, int line);
+
+void printlines(SourceLocation &S, SourceLocation &E, SourceManager *SRCMAN);
+
+void PrintBinaryOperator(Stmt *s, SourceManager *SRCMAN, int level);
+
+void PrintDeclStmt(Stmt *s, SourceManager *SRCMAN, int level);
+
+void PrintALoop(Stmt *L, SourceManager *SRCMAN, int level);
-char *splitTypeInfo( char *underlyingtype );
-void printsourceline( const char *filename, int line );
-void printlines( SourceLocation &S, SourceLocation &E, SourceManager *SRCMAN );
+void PrintAUnaryOperator(Stmt *s, SourceManager *SRCMAN, int level);
-void PrintBinaryOperator( Stmt *s, SourceManager *SRCMAN, int level );
-void PrintDeclStmt( Stmt *s, SourceManager *SRCMAN, int level );
-void PrintALoop( Stmt *L, SourceManager *SRCMAN, int level );
-void PrintAUnaryOperator( Stmt *s, SourceManager *SRCMAN, int level );
-void PrintAnIfStmt( Stmt *s, SourceManager *SRCMAN, int level );
-void PrintCompoundStmt( Stmt *s, SourceManager *SRCMAN, int level );
-void PrintDeclRefExpr( Stmt *s, SourceManager *SRCMAN, int level );
-void PrintImplicitCastExpr( Stmt *s, SourceManager *SRCMAN, int level );
-void PrintReturnStmt( Stmt *s, SourceManager *SRCMAN, int level );
-void PrintStmt( Stmt *s, SourceManager *SRCMAN, int level );
+void PrintAnIfStmt(Stmt *s, SourceManager *SRCMAN, int level);
-void PrintAnIntegerLiteral( Stmt *I );
-void PrintAFloatingLiteral( Stmt *s );
+void PrintCompoundStmt(Stmt *s, SourceManager *SRCMAN, int level);
-void PrintFunctionDecl( FunctionDecl *D, SourceManager *SRCMAN, int level );
-void PrintTypeDefDecl( TypedefDecl *D, SourceManager *SRCMAN, int level );
-void PrintVarDecl( VarDecl *D, SourceManager *SRCMAN, int level );
+void PrintDeclRefExpr(Stmt *s, SourceManager *SRCMAN, int level);
+void PrintImplicitCastExpr(Stmt *s, SourceManager *SRCMAN, int level);
+void PrintReturnStmt(Stmt *s, SourceManager *SRCMAN, int level);
+void PrintStmt(Stmt *s, SourceManager *SRCMAN, int level);
+void PrintAnIntegerLiteral(Stmt *I);
-void printlines( SourceLocation &S, SourceLocation &E, SourceManager *SRCMAN ) {
- unsigned int startlineno = SRCMAN->getPresumedLineNumber( S );
- unsigned int endlineno = SRCMAN->getPresumedLineNumber( E );
- const char *filename = SRCMAN->getBufferName( S );
+void PrintAFloatingLiteral(Stmt *s);
+
+void PrintFunctionDecl(FunctionDecl *D, SourceManager *SRCMAN, int level);
+
+void PrintTypeDefDecl(TypedefDecl *D, SourceManager *SRCMAN, int level);
+
+void PrintVarDecl(VarDecl *D, SourceManager *SRCMAN, int level);
+
+
+void printlines(SourceLocation &S, SourceLocation &E, SourceManager *SRCMAN) {
+ unsigned int startlineno = SRCMAN->getPresumedLineNumber(S);
+ unsigned int endlineno = SRCMAN->getPresumedLineNumber(E);
+ const char *filename = SRCMAN->getBufferName(S);
fprintf(stderr, "\n");
- for (int l=startlineno; l<= endlineno; l++) printsourceline( filename, l);
+ for (int l = startlineno; l <= endlineno; l++) printsourceline(filename, l);
}
-void Indent( int level ) {
- for (int i=0; i<level; i++) fprintf(stderr, " ");
+void Indent(int level) {
+ for (int i = 0; i < level; i++) fprintf(stderr, " ");
}
// really slow and bad. but I'm debugging
-void printsourceline( const char *filename, int line )
-{
- FILE *fp = fopen (filename, "r");
+void printsourceline(const char *filename, int line) {
+ FILE *fp = fopen(filename, "r");
// Now read lines up to and including the line we want.
char buf[10240];
int l = 0;
while (l < line) {
- if (fgets (buf, sizeof(buf), fp))
+ if (fgets(buf, sizeof(buf), fp))
++l;
else
break;
@@ -175,8 +204,7 @@ void printsourceline( const char *filename, int line )
}
-
-void PrintBinaryOperator( Stmt *s, SourceManager *SRCMAN, int level ) { // SOMETIMES SHOULD HAVE ; + return
+void PrintBinaryOperator(Stmt *s, SourceManager *SRCMAN, int level) { // SOMETIMES SHOULD HAVE ; + return
//rintf(stderr, "\nBinaryOperator(%d) ", level);
BinaryOperator *b = cast<BinaryOperator>(s);
@@ -187,91 +215,83 @@ void PrintBinaryOperator( Stmt *s, SourceManager *SRCMAN, int level ) { // SOME
//fprintf(stderr, "binaryoperator lhs has type %s\n", lhs->getStmtClassName());
//fprintf(stderr, "binaryoperator rhs has type %s\n\n", rhs->getStmtClassName());
- PrintStmt( lhs, SRCMAN, level+1 );
- fprintf(stderr, " %s ", binops[op].c_str());
- PrintStmt( rhs, SRCMAN, level+1);
+ PrintStmt(lhs, SRCMAN, level + 1);
+ fprintf(stderr, " %s ", binops[op].c_str());
+ PrintStmt(rhs, SRCMAN, level + 1);
if (level == 1) fprintf(stderr, ";\n");
}
-
-void PrintDeclStmt( Stmt *s, SourceManager *SRCMAN, int level ) {
- fprintf(stderr, "\nDeclaration Statement(%d)", level);
+void PrintDeclStmt(Stmt *s, SourceManager *SRCMAN, int level) {
+ fprintf(stderr, "\nDeclaration Statement(%d)", level);
DeclStmt *D = cast<DeclStmt>(s);
- //QualType QT = D->getType();
- //string TypeStr = QT.getAsString();
- //fprintf(stderr, "type %s\n", TypeStr,c_str());
+ //QualType QT = D->getType();
+ //string TypeStr = QT.getAsString();
+ //fprintf(stderr, "type %s\n", TypeStr,c_str());
+
+ //SourceLocation S = D->getStartLoc();
+ //SourceLocation E = D->getEndLoc();
+ //printlines(S, E, SRCMAN);
+
+ if (D->isSingleDecl()) {
+ fprintf(stderr, "this is a single definition\n");
+ Decl *d = D->getSingleDecl();
+ } else {
+ fprintf(stderr, "this is NOT a single definition\n");
+ DeclGroupRef dg = D->getDeclGroup();
+ }
+
+ for (DeclStmt::decl_iterator DI = D->decl_begin(), DE = D->decl_end(); DI != DE; ++DI) {
+ //fprintf(stderr, "a def\n");
+ Decl *d = *DI;
+ //fprintf(stderr, "\nstatement of type %s\n", d->getStmtClassName());
+ //std::cout << (void *) d << "?";
+ if (ValueDecl *VD = dyn_cast<ValueDecl>(d)) {
+ if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
+ if (V->getStorageClass() != SC_None) {
+ fprintf(stderr, "%s ", VarDecl::getStorageClassSpecifierString(V->getStorageClass()));
+ }
+ // else fprintf(stderr, "no storage class? ");
+
+ QualType T = V->getType();
+ string TypeStr = T.getAsString();
+ std::string Name = VD->getNameAsString();
+ //VD->getType().getAsStringInternal(Name,
+ // PrintingPolicy(VD->getASTContext().getLangOpts()));
+ fprintf(stderr, "%s %s ", TypeStr.c_str(), Name.c_str());
+ // If this is a vardecl with an initializer, emit it.
+ if (Expr *E = V->getInit()) {
+ fprintf(stderr, " = ");
+
+ Stmt *s = dyn_cast<Stmt>(E);
+ PrintStmt(s, SRCMAN, level + 1);
+ //fprintf(stderr, ";\n");
- //SourceLocation S = D->getStartLoc();
- //SourceLocation E = D->getEndLoc();
- //printlines(S, E, SRCMAN);
+ }
- if (D->isSingleDecl()) {
- fprintf(stderr, "this is a single definition\n");
- Decl *d = D->getSingleDecl();
- }
- else {
- fprintf(stderr, "this is NOT a single definition\n");
- DeclGroupRef dg = D->getDeclGroup();
}
- for (DeclStmt::decl_iterator DI = D->decl_begin(), DE = D->decl_end(); DI != DE; ++DI) {
- //fprintf(stderr, "a def\n");
- Decl *d = *DI;
- //fprintf(stderr, "\nstatement of type %s\n", d->getStmtClassName());
- //std::cout << (void *) d << "?";
- if (ValueDecl *VD = dyn_cast<ValueDecl>(d)) {
- if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
- if (V->getStorageClass() != SC_None) {
- fprintf(stderr, "%s ", VarDecl::getStorageClassSpecifierString(V->getStorageClass()));
- }
- // else fprintf(stderr, "no storage class? ");
-
- QualType T = V->getType();
- string TypeStr = T.getAsString();
- std::string Name = VD->getNameAsString();
- //VD->getType().getAsStringInternal(Name,
- // PrintingPolicy(VD->getASTContext().getLangOpts()));
- fprintf(stderr,"%s %s ", TypeStr.c_str(), Name.c_str());
- // If this is a vardecl with an initializer, emit it.
- if (Expr *E = V->getInit()) {
- fprintf(stderr, " = ");
-
- Stmt *s = dyn_cast<Stmt>(E);
- PrintStmt(s, SRCMAN, level+1);
- //fprintf(stderr, ";\n");
-
- }
-
- }
-
- }
- if (level <= 1) fprintf(stderr, ";\n"); // TODO wrong
+ }
+ if (level <= 1) fprintf(stderr, ";\n"); // TODO wrong
- } // for each actual declaration
+ } // for each actual declaration
}
-
-
-
-
-void PrintAFloatingLiteral( Stmt *s ) {
+void PrintAFloatingLiteral(Stmt *s) {
FloatingLiteral *F = dyn_cast<FloatingLiteral>(s);
fprintf(stderr, "%f", F->getValueAsApproximateDouble()); // TODO approximate?
}
-
-
-void PrintALoop( Stmt *L, SourceManager *SRCMAN, int level ) {
+void PrintALoop(Stmt *L, SourceManager *SRCMAN, int level) {
//fprintf(stderr, "\nA LOOP L=0x%x SRCMAN 0x%x", L, &SRCMAN);
ForStmt *ForStatement = cast<ForStmt>(L);
SourceLocation srcloc = ForStatement->getForLoc();
- unsigned int lineno = SRCMAN->getPresumedLineNumber( srcloc );
- const char *filename = SRCMAN->getBufferName( srcloc );
+ unsigned int lineno = SRCMAN->getPresumedLineNumber(srcloc);
+ const char *filename = SRCMAN->getBufferName(srcloc);
//fprintf(stderr, " in file %s at line %d ", filename, lineno);
//printsourceline( filename, lineno);
@@ -287,34 +307,33 @@ void PrintALoop( Stmt *L, SourceManager *SRCMAN, int level ) {
fprintf(stderr, "; ");
PrintStmt(incr, SRCMAN, 0);
fprintf(stderr, " )\n");
- Indent(level);
+ Indent(level);
fprintf(stderr, "{\n");
- PrintStmt(body, SRCMAN, level+1);
+ PrintStmt(body, SRCMAN, level + 1);
fprintf(stderr, "}\n\n");
}
-void PrintAUnaryOperator( Stmt *s, SourceManager *SRCMAN, int level ) {
+void PrintAUnaryOperator(Stmt *s, SourceManager *SRCMAN, int level) {
//fprintf(stderr, "UnaryOperator ");
UnaryOperator *u = cast<UnaryOperator>(s);
const char *op = unops[u->getOpcode()].c_str();
if (u->isPrefix()) {
- fprintf(stderr, "%s", op );
+ fprintf(stderr, "%s", op);
}
- PrintStmt( u->getSubExpr(), SRCMAN, level+1 );
+ PrintStmt(u->getSubExpr(), SRCMAN, level + 1);
if (u->isPostfix()) {
- fprintf(stderr, "%s", op );
+ fprintf(stderr, "%s", op);
}
}
-
-void PrintAnIfStmt( Stmt *s, SourceManager *SRCMAN, int level ) {
+void PrintAnIfStmt(Stmt *s, SourceManager *SRCMAN, int level) {
//fprintf(stderr, "an IF statement\n");
// SourceLocation S = s->getLocStart();
// SourceLocation E = s->getLocEnd();
@@ -327,95 +346,89 @@ void PrintAnIfStmt( Stmt *s, SourceManager *SRCMAN, int level ) {
Stmt *Else = IfStatement->getElse();
fprintf(stderr, "if (");
- PrintStmt(Cond, SRCMAN, level+1);
+ PrintStmt(Cond, SRCMAN, level + 1);
fprintf(stderr, ") {\n");
- PrintStmt(Then, SRCMAN, level+1);
+ PrintStmt(Then, SRCMAN, level + 1);
fprintf(stderr, "\n}\nelse\n{\n");
- PrintStmt(Else, SRCMAN, level+1);
+ PrintStmt(Else, SRCMAN, level + 1);
fprintf(stderr, "\n}\n\n");
}
-
-void PrintAnIntegerLiteral( Stmt *s ) {
+void PrintAnIntegerLiteral(Stmt *s) {
IntegerLiteral *I = dyn_cast<IntegerLiteral>(s);
bool isSigned = I->getType()->isSignedIntegerType();
fprintf(stderr, "%s", I->getValue().toString(10, isSigned).c_str());
}
-
-void PrintArraySubscriptExpr( Stmt *s, SourceManager *SRCMAN, int level ) {
+void PrintArraySubscriptExpr(Stmt *s, SourceManager *SRCMAN, int level) {
ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(s);
Expr *Base = ASE->getBase();
Expr *Index = ASE->getIdx();
- PrintStmt(Base, SRCMAN, level+1);
+ PrintStmt(Base, SRCMAN, level + 1);
fprintf(stderr, "[");
- PrintStmt(Index, SRCMAN, level+1);
+ PrintStmt(Index, SRCMAN, level + 1);
fprintf(stderr, "]");
}
-void PrintCompoundStmt( Stmt *s, SourceManager *SRCMAN, int level ) {
+void PrintCompoundStmt(Stmt *s, SourceManager *SRCMAN, int level) {
//fprintf(stderr, "\nCompoundStmt(%d)", level);
CompoundStmt *cs = dyn_cast<CompoundStmt>(s);
- int numchildren=cs->size();
- //fprintf(stderr, "CompoundStmt has %d children\n", numchildren);
-
-
-#ifdef DEBUGGING
-BUH
- for (Stmt::child_range I = cs->children(); I; ++I) {
- const char *classname = I->getStmtClassName();
- if (!strcmp(classname, "BinaryOperator")) {
- BinaryOperator *b = cast<BinaryOperator>(*I);
- BinaryOperator::Opcode op = b->getOpcode();
- if (op == BO_Assign) {
- fprintf(stderr, "compound statement has child of type ASSIGNMENT STATEMENT ");
- SourceLocation S = I->getLocStart();
- SourceLocation E = I->getLocEnd();
- unsigned int startlineno = SRCMAN->getPresumedLineNumber( S );
- unsigned int endlineno = SRCMAN->getPresumedLineNumber( E );
- fprintf(stderr, "(%d-%d)\n", startlineno, endlineno );
+ int numchildren = cs->size();
+ //fprintf(stderr, "CompoundStmt has %d children\n", numchildren);
+
+
+#ifdef DEBUGGING
+ BUH
+ for (Stmt::child_range I = cs->children(); I; ++I) {
+ const char *classname = I->getStmtClassName();
+ if (!strcmp(classname, "BinaryOperator")) {
+ BinaryOperator *b = cast<BinaryOperator>(*I);
+ BinaryOperator::Opcode op = b->getOpcode();
+ if (op == BO_Assign) {
+ fprintf(stderr, "compound statement has child of type ASSIGNMENT STATEMENT ");
+ SourceLocation S = I->getLocStart();
+ SourceLocation E = I->getLocEnd();
+ unsigned int startlineno = SRCMAN->getPresumedLineNumber( S );
+ unsigned int endlineno = SRCMAN->getPresumedLineNumber( E );
+ fprintf(stderr, "(%d-%d)\n", startlineno, endlineno );
+ }
+ else
+ fprintf(stderr, "compound statement has child of type %s\n", I->getStmtClassName());
}
else
fprintf(stderr, "compound statement has child of type %s\n", I->getStmtClassName());
}
- else
- fprintf(stderr, "compound statement has child of type %s\n", I->getStmtClassName());
- }
#endif // debugging
+ for (auto I = cs->child_begin(); I != cs->child_end(); ++I) {
+ Stmt *child = *I;
+ PrintStmt(child, SRCMAN, level); // NOTE not level + 1
- for (auto I = cs->child_begin(); I!=cs->child_end(); ++I) {
- Stmt *child = *I;
- PrintStmt( child, SRCMAN, level ); // NOTE not level + 1
-
- fprintf(stderr, "\n"); // ***\n\n");
- }
-
-}
-
+ fprintf(stderr, "\n"); // ***\n\n");
+ }
+}
-void PrintDeclRefExpr( Stmt *s, SourceManager *SRCMAN, int level ) {
+void PrintDeclRefExpr(Stmt *s, SourceManager *SRCMAN, int level) {
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(s);
//if (NestedNameSpecifier *Qualifier = DRE->getQualifier())
// Qualifier->print( raw_ostream nonstandard of course );
DeclarationNameInfo DNI = DRE->getNameInfo();
DeclarationName DN = DNI.getName();
- fprintf(stderr, "%s", DN.getAsString().c_str());
+ fprintf(stderr, "%s", DN.getAsString().c_str());
}
-
-void PrintFunctionDecl( FunctionDecl *D, SourceManager *SRCMAN, int level ) {
+void PrintFunctionDecl(FunctionDecl *D, SourceManager *SRCMAN, int level) {
//rintf(stderr, "\nFunctionDecl(%d) %s\n", level, D->getNameInfo().getAsString().c_str());
// Type name as string
QualType QT = D->getReturnType();
@@ -427,11 +440,11 @@ void PrintFunctionDecl( FunctionDecl *D, SourceManager *SRCMAN, int level ) {
//fprintf(stderr, "function %s has type %s ", FuncName.c_str(), TypeStr.c_str());
- fprintf(stderr, "\n%s %s(",TypeStr.c_str(), FuncName.c_str());
+ fprintf(stderr, "\n%s %s(", TypeStr.c_str(), FuncName.c_str());
int numparams = D->getNumParams();
//fprintf(stderr, "and %d parameters\n", numparams);
- for (int i=0; i<numparams; i++) {
+ for (int i = 0; i < numparams; i++) {
if (i) fprintf(stderr, ", ");
ParmVarDecl *clangVardecl = D->getParamDecl(i);
@@ -439,16 +452,16 @@ void PrintFunctionDecl( FunctionDecl *D, SourceManager *SRCMAN, int level ) {
StorageClass SCAsWritten = clangVardecl->getStorageClass();
if (SCAsWritten != SC_None) {
fprintf(stderr, "%s ", VarDecl::getStorageClassSpecifierString(SCAsWritten));
- }
+ }
//else fprintf(stderr, "(no storage class?) ");
QualType T = clangVardecl->getType();
if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(clangVardecl))
T = Parm->getOriginalType();
- string Name = clangVardecl->getName();
+ string Name = clangVardecl->getName();
char *td = strdup(T.getAsString().c_str());
- fprintf(stderr, "td = '%s'\n", td);
+ fprintf(stderr, "td = '%s'\n", td);
char *arraypart = splitTypeInfo(td);
fprintf(stderr, "%s %s%s ", td, Name.c_str(), arraypart);
@@ -457,31 +470,30 @@ void PrintFunctionDecl( FunctionDecl *D, SourceManager *SRCMAN, int level ) {
fprintf(stderr, ")\n{\n"); // beginning of function body
Stmt *body = D->getBody();
- PrintStmt( body, SRCMAN, level+1);
+ PrintStmt(body, SRCMAN, level + 1);
fprintf(stderr, "}\n\n"); // end of function body
}
-void PrintImplicitCastExpr( Stmt *s, SourceManager *SRCMAN, int level ) {
+void PrintImplicitCastExpr(Stmt *s, SourceManager *SRCMAN, int level) {
ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(s);
- PrintStmt( ICE->getSubExpr(), SRCMAN, level+1);
+ PrintStmt(ICE->getSubExpr(), SRCMAN, level + 1);
}
-
-void PrintReturnStmt( Stmt *s, SourceManager *SRCMAN, int level ) {
+void PrintReturnStmt(Stmt *s, SourceManager *SRCMAN, int level) {
ReturnStmt *r = dyn_cast<ReturnStmt>(s);
fprintf(stderr, "return");
if (r->getRetValue()) {
fprintf(stderr, " ");
- PrintStmt( r->getRetValue(), SRCMAN, level+1);
+ PrintStmt(r->getRetValue(), SRCMAN, level + 1);
}
fprintf(stderr, ";\n");
}
-void PrintStmt( Stmt *s, SourceManager *SRCMAN, int level ) {
+void PrintStmt(Stmt *s, SourceManager *SRCMAN, int level) {
//fprintf(stderr, "\nprint statement 0x%x of type %s\n", s, s->getStmtClassName());
@@ -491,21 +503,33 @@ void PrintStmt( Stmt *s, SourceManager *SRCMAN, int level ) {
//const char *filename = SRCMAN->getBufferName( srcloc );
//StmtClass getStmtClass()
- if (isa<DeclStmt>(s)) { PrintDeclStmt(s, SRCMAN, level);
- } else if (isa<FloatingLiteral>(s)) { PrintAFloatingLiteral(s );
- } else if (isa<IntegerLiteral>(s)) { PrintAnIntegerLiteral(s );
- } else if (isa<UnaryOperator>(s)) { PrintAUnaryOperator(s, SRCMAN, level);
- } else if (isa<BinaryOperator>(s)) { PrintBinaryOperator(s, SRCMAN, level);
- } else if (isa<ForStmt>(s)) { PrintALoop(s, SRCMAN, level);
- } else if (isa<IfStmt>(s)) { PrintAnIfStmt(s, SRCMAN, level);
- } else if (isa<CompoundStmt>(s)) { PrintCompoundStmt(s, SRCMAN, level);
- } else if (isa<ImplicitCastExpr>(s)) { PrintImplicitCastExpr(s, SRCMAN, level);
- } else if (isa<DeclRefExpr>(s)) { PrintDeclRefExpr(s, SRCMAN, level);
- } else if (isa<ArraySubscriptExpr>(s)) {PrintArraySubscriptExpr(s, SRCMAN, level);
- } else if (isa<ReturnStmt>(s)) { PrintReturnStmt(s, SRCMAN, level);
- } else {
+ if (isa<DeclStmt>(s)) {
+ PrintDeclStmt(s, SRCMAN, level);
+ } else if (isa<FloatingLiteral>(s)) {
+ PrintAFloatingLiteral(s);
+ } else if (isa<IntegerLiteral>(s)) {
+ PrintAnIntegerLiteral(s);
+ } else if (isa<UnaryOperator>(s)) {
+ PrintAUnaryOperator(s, SRCMAN, level);
+ } else if (isa<BinaryOperator>(s)) {
+ PrintBinaryOperator(s, SRCMAN, level);
+ } else if (isa<ForStmt>(s)) {
+ PrintALoop(s, SRCMAN, level);
+ } else if (isa<IfStmt>(s)) {
+ PrintAnIfStmt(s, SRCMAN, level);
+ } else if (isa<CompoundStmt>(s)) {
+ PrintCompoundStmt(s, SRCMAN, level);
+ } else if (isa<ImplicitCastExpr>(s)) {
+ PrintImplicitCastExpr(s, SRCMAN, level);
+ } else if (isa<DeclRefExpr>(s)) {
+ PrintDeclRefExpr(s, SRCMAN, level);
+ } else if (isa<ArraySubscriptExpr>(s)) {
+ PrintArraySubscriptExpr(s, SRCMAN, level);
+ } else if (isa<ReturnStmt>(s)) {
+ PrintReturnStmt(s, SRCMAN, level);
+ } else {
fprintf(stderr, "\nPrintStmt() UNHANDLED statement of type %s\n", s->getStmtClassName());
- exit(-1);
+ exit(-1);
}
//int numchildren=0;
//for (Stmt::child_range I = s->children(); I; ++I, numchildren++) ;
@@ -516,36 +540,34 @@ void PrintStmt( Stmt *s, SourceManager *SRCMAN, int level ) {
}
-void PrintTranslationUnit( TranslationUnitDecl *TUD, ASTContext &CTX ) {
+void PrintTranslationUnit(TranslationUnitDecl *TUD, ASTContext &CTX) {
// TUD derived from Decl and DeclContext
- static DeclContext *DC = TUD->castToDeclContext( TUD );
+ static DeclContext *DC = TUD->castToDeclContext(TUD);
//SourceManager SM = CTX.getSourceManager();
for (DeclContext::decl_iterator DI = DC->decls_begin(), DE = DC->decls_end(); DI != DE; ++DI) {
Decl *D = *DI;
- if (isa<FunctionDecl>(D)) { //fprintf(stderr, "FunctionDecl\n");
- PrintFunctionDecl( dyn_cast<FunctionDecl>(D), &CTX.getSourceManager(), 0);
- }
- else if (isa<VarDecl>(D)) { //fprintf(stderr, "VarDecl\n");
- PrintVarDecl( dyn_cast<VarDecl>(D), &CTX.getSourceManager(), 0 );
- }
- else if (isa<TypedefDecl>(D)) { //fprintf(stderr, "TypedefDecl\n");
- PrintTypeDefDecl( dyn_cast<TypedefDecl>(D), &CTX.getSourceManager(), 0 );
- }
- else if (isa<TypeAliasDecl>(D)) { fprintf(stderr, "TypeAliasDecl\n");
- }
- else {
- fprintf(stderr, "\na declaration of type %s (%d) which I have no idea how to handle\n", D->getDeclKindName(), D->getKind());
+ if (isa<FunctionDecl>(D)) { //fprintf(stderr, "FunctionDecl\n");
+ PrintFunctionDecl(dyn_cast<FunctionDecl>(D), &CTX.getSourceManager(), 0);
+ } else if (isa<VarDecl>(D)) { //fprintf(stderr, "VarDecl\n");
+ PrintVarDecl(dyn_cast<VarDecl>(D), &CTX.getSourceManager(), 0);
+ } else if (isa<TypedefDecl>(D)) { //fprintf(stderr, "TypedefDecl\n");
+ PrintTypeDefDecl(dyn_cast<TypedefDecl>(D), &CTX.getSourceManager(), 0);
+ } else if (isa<TypeAliasDecl>(D)) {
+ fprintf(stderr, "TypeAliasDecl\n");
+ } else {
+ fprintf(stderr, "\na declaration of type %s (%d) which I have no idea how to handle\n", D->getDeclKindName(),
+ D->getKind());
exit(-1);
}
-
+
//else if (isa<TypedefNameDecl>(D)) { fprintf(stderr, "TypedefNameDecl\n");}
}
}
-void PrintTypeDefDecl( TypedefDecl *D, SourceManager *SRCMAN, int level ) {
+void PrintTypeDefDecl(TypedefDecl *D, SourceManager *SRCMAN, int level) {
/* internal typedefs do not have a source file and this will die!
SourceLocation S = D->getLocStart(); // NOT getStartLoc(), that's class DeclStmt
@@ -558,7 +580,7 @@ void PrintTypeDefDecl( TypedefDecl *D, SourceManager *SRCMAN, int level ) {
*/
// arrays suck
- char *td = strdup( D->getUnderlyingType().getAsString().c_str());
+ char *td = strdup(D->getUnderlyingType().getAsString().c_str());
//fprintf(stderr, "td = '%s'\n", td);
char *arraypart = splitTypeInfo(td);
fprintf(stderr, "typedef %s %s%s;\n", td, D->getName().str().c_str(), arraypart);
@@ -568,18 +590,17 @@ void PrintTypeDefDecl( TypedefDecl *D, SourceManager *SRCMAN, int level ) {
}
-
-void PrintVarDecl( VarDecl *D, SourceManager *SRCMAN, int level ) {
+void PrintVarDecl(VarDecl *D, SourceManager *SRCMAN, int level) {
// arrays suck
- char *td = strdup( D->getType().getAsString().c_str()); // leak
+ char *td = strdup(D->getType().getAsString().c_str()); // leak
//fprintf(stderr, "td = '%s'\n", td);
char *arraypart = splitTypeInfo(td);
- fprintf(stderr, "%s %s%s", td, D->getName().str().c_str(), arraypart);
+ fprintf(stderr, "%s %s%s", td, D->getName().str().c_str(), arraypart);
Expr *Init = D->getInit();
if (Init) {
//fprintf(stderr," = (TODO)");
- PrintStmt( Init, SRCMAN, level+1);
+ PrintStmt(Init, SRCMAN, level + 1);
}
fprintf(stderr, ";\n");
@@ -594,33 +615,33 @@ void PrintVarDecl( VarDecl *D, SourceManager *SRCMAN, int level ) {
-chillAST_node * ConvertVarDecl( VarDecl *D, chillAST_node *p ) {
+chillAST_node *ConvertVarDecl(VarDecl *D, chillAST_node *p) {
//fprintf(stderr, "\nConvertVarDecl()\n");
//fprintf(stderr, "Decl has type %s\n", D->getDeclKindName());
//PrintVarDecl( D, globalSRCMAN, 0 );
- bool isParm = false;
+ bool isParm = false;
- QualType T0 = D->getType();
- QualType T = T0;
- if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) { // My GOD clang stinks
- T = Parm->getOriginalType();
- isParm = true;
- }
+ QualType T0 = D->getType();
+ QualType T = T0;
+ if (ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) { // My GOD clang stinks
+ T = Parm->getOriginalType();
+ isParm = true;
+ }
// arrays suck
- char *vartype = strdup( T.getAsString().c_str());
+ char *vartype = strdup(T.getAsString().c_str());
//fprintf(stderr, "vartype = '%s' T0 '%s\n", vartype, T0.getAsString().c_str() );
char *arraypart = splitTypeInfo(vartype);
//fprintf(stderr, "arraypart = '%s'\n", arraypart);
- char *varname = strdup(D->getName().str().c_str());
+ char *varname = strdup(D->getName().str().c_str());
//fprintf(stderr, "VarDecl (clang 0x%x) for %s %s%s\n", D, vartype, varname, arraypart);
-
- chillAST_VarDecl * chillVD = new chillAST_VarDecl( vartype, varname, arraypart, (void *)D, p /* , initializer */ );
- chillVD->isAParameter = isParm;
+ chillAST_VarDecl *chillVD = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, p /* , initializer */ );
+
+ chillVD->isAParameter = isParm;
//fprintf(stderr, "\nthis is the vardecl\n");
//chillVD->print(); printf("\n\n"); fflush(stdout);
@@ -643,68 +664,69 @@ chillAST_node * ConvertVarDecl( VarDecl *D, chillAST_node *p ) {
int numdim = 0;
- chillVD-> knownArraySizes = true;
+ chillVD->knownArraySizes = true;
if (index(vartype, '*')) chillVD->knownArraySizes = false; // float *a; for example
- if (index(arraypart, '*')) chillVD->knownArraySizes = false;
-
+ if (index(arraypart, '*')) chillVD->knownArraySizes = false;
+
// note: vartype here, arraypart in next code.. is that right?
- if (index(vartype, '*')) {
- for (int i = 0; i<strlen(vartype); i++) if (vartype[i] == '*') numdim++;
+ if (index(vartype, '*')) {
+ for (int i = 0; i < strlen(vartype); i++) if (vartype[i] == '*') numdim++;
//fprintf(stderr, "numd %d\n", numd);
- chillVD->numdimensions = numdim;
+ chillVD->numdimensions = numdim;
}
if (index(arraypart, '[')) { // JUST [12][34][56] no asterisks
char *dupe = strdup(arraypart);
int len = strlen(arraypart);
- for (int i=0; i<len; i++) if (dupe[i] == '[') numdim++;
+ for (int i = 0; i < len; i++) if (dupe[i] == '[') numdim++;
//fprintf(stderr, "numdim %d\n", numdim);
- chillVD->numdimensions = numdim;
- int *as = (int *)malloc(sizeof(int *) * numdim );
- if (!as) {
+ chillVD->numdimensions = numdim;
+ int *as = (int *) malloc(sizeof(int *) * numdim);
+ if (!as) {
fprintf(stderr, "can't malloc array sizes in ConvertVarDecl()\n");
exit(-1);
}
chillVD->arraysizes = as; // 'as' changed later!
-
+
char *ptr = dupe;
//fprintf(stderr, "dupe '%s'\n", ptr);
- while (ptr = index(ptr, '[')) {
+ while (ptr = index(ptr, '[')) {
ptr++;
//fprintf(stderr, "tmp '%s'\n", ptr);
int dim;
sscanf(ptr, "%d", &dim);
//fprintf(stderr, "dim %d\n", dim);
- *as++ = dim;
-
- ptr = index(ptr, ']');
+ *as++ = dim;
+
+ ptr = index(ptr, ']');
//fprintf(stderr, "bottom of loop, ptr = '%s'\n", ptr);
}
free(dupe);
//for (int i=0; i<numdim; i++) {
// fprintf(stderr, "dimension %d = %d\n", i, chillVD->arraysizes[i]);
//}
-
+
//fprintf(stderr, "need to handle [] array to determine num dimensions\n");
//exit(-1);
}
-
+
Expr *Init = D->getInit();
if (Init) {
- fprintf(stderr," = VARDECL HAS INIT. (TODO) (RIGHT NOW)"); exit(-1);
+ fprintf(stderr, " = VARDECL HAS INIT. (TODO) (RIGHT NOW)");
+ exit(-1);
}
//fprintf(stderr, ";\n");
-
+
//fprintf(stderr, "calling chillVD->print()\n");
//chillVD->print(); // debugging only
- free (vartype);
- free (varname);
+ free(vartype);
+ free(varname);
// store this away for declrefexpr that references it!
VariableDeclarations.push_back(chillVD);
@@ -712,65 +734,61 @@ chillAST_node * ConvertVarDecl( VarDecl *D, chillAST_node *p ) {
}
-
-chillAST_node * ConvertRecordDecl( clang::RecordDecl *RD, chillAST_node *p ) { // for structs and unions
+chillAST_node *ConvertRecordDecl(clang::RecordDecl *RD, chillAST_node *p) { // for structs and unions
//fprintf(stderr, "ConvertRecordDecl( )\n\nclang sees\n");
//RD->dump();
//fflush(stdout);
//fprintf(stderr, "\n");
-
+
//fprintf(stderr, "%s with name %s\n", ((clang::Decl *)RD)->getDeclKindName(), RD->getNameAsString().c_str());
//const clang::ASTRecordLayout RL = RD->getASTContext().getASTRecordLayout( RD );
//RD->getASTContext().DumpRecordLayout( RD , cout );
int count = 0;
- for (clang::RecordDecl::field_iterator fi = RD->field_begin(); fi != RD->field_end(); fi++) count++;
+ for (clang::RecordDecl::field_iterator fi = RD->field_begin(); fi != RD->field_end(); fi++) count++;
//fprintf(stderr, "%d fields in this struct/union\n", count);
char blurb[128];
- sprintf(blurb, "struct %s", RD->getNameAsString().c_str());
- fprintf(stderr, "blurb is '%s'\n", blurb);
+ sprintf(blurb, "struct %s", RD->getNameAsString().c_str());
+ fprintf(stderr, "blurb is '%s'\n", blurb);
- chillAST_TypedefDecl *astruct = new chillAST_TypedefDecl( blurb, "", p);
- astruct->setStruct( true );
- astruct->setStructName( RD->getNameAsString().c_str() );
+ chillAST_TypedefDecl *astruct = new chillAST_TypedefDecl(blurb, "", p);
+ astruct->setStruct(true);
+ astruct->setStructName(RD->getNameAsString().c_str());
- for (clang::RecordDecl::field_iterator fi = RD->field_begin(); fi != RD->field_end(); fi++) {
+ for (clang::RecordDecl::field_iterator fi = RD->field_begin(); fi != RD->field_end(); fi++) {
clang::FieldDecl *FD = (*fi);
- FD->dump(); printf(";\n"); fflush(stdout);
- string TypeStr = FD->getType().getAsString();
+ FD->dump();
+ printf(";\n");
+ fflush(stdout);
+ string TypeStr = FD->getType().getAsString();
- const char *typ = TypeStr.c_str();
+ const char *typ = TypeStr.c_str();
const char *name = FD->getNameAsString().c_str();
fprintf(stderr, "(typ) %s (name) %s\n", typ, name);
chillAST_VarDecl *VD = NULL;
// very clunky and incomplete
- VD = new chillAST_VarDecl( typ, name, "", astruct ); // can't handle arrays yet
-
- astruct->subparts.push_back(VD);
+ VD = new chillAST_VarDecl(typ, name, "", astruct); // can't handle arrays yet
+
+ astruct->subparts.push_back(VD);
}
- fprintf(stderr, "I just defined a struct\n");
- astruct->print(0, stderr);
+ fprintf(stderr, "I just defined a struct\n");
+ astruct->print(0, stderr);
- return astruct;
+ return astruct;
}
-
-
-
-
-
-chillAST_node * ConvertTypeDefDecl( TypedefDecl *TDD, chillAST_node *p ) {
+chillAST_node *ConvertTypeDefDecl(TypedefDecl *TDD, chillAST_node *p) {
//fprintf(stderr, "ConvertTypedefDecl( ) \n");
//fprintf(stderr, "TDD has type %s\n", TDD->getDeclKindName());
//TDD->dump(); fprintf(stderr, "\n");
- char *under = strdup( TDD->getUnderlyingType().getAsString().c_str());
+ char *under = strdup(TDD->getUnderlyingType().getAsString().c_str());
//fprintf(stderr, "under = '%s'\n", under);
char *arraypart = splitTypeInfo(under);
//fprintf(stderr, "typedef %s %s%s;\n", under, TDD->getName().str().c_str(), arraypart);
@@ -778,99 +796,95 @@ chillAST_node * ConvertTypeDefDecl( TypedefDecl *TDD, chillAST_node *p ) {
char *alias = strdup(TDD->getName().str().c_str());
//fprintf(stderr, "underlying type %s arraypart '%s' name %s\n", under, arraypart, TDD->getName().str().c_str() );
- chillAST_TypedefDecl *CTDD = new chillAST_TypedefDecl( under, alias, arraypart, p );
+ chillAST_TypedefDecl *CTDD = new chillAST_TypedefDecl(under, alias, arraypart, p);
- free(under);
- free(arraypart);
+ free(under);
+ free(arraypart);
- return CTDD;
+ return CTDD;
}
-
-chillAST_node * ConvertDeclStmt( DeclStmt *clangDS, chillAST_node *p ) {
+chillAST_node *ConvertDeclStmt(DeclStmt *clangDS, chillAST_node *p) {
//fprintf(stderr, "ConvertDeclStmt()\n");
chillAST_VarDecl *chillvardecl; // the thing we'll return if this is a single declaration
-
+
bool multiples = !clangDS->isSingleDecl();
- if ( multiples) {
+ if (multiples) {
//fprintf(stderr, "ir_clang.cc multiple declarations in a single CLANG DeclStmt not really handled! (??)\n");
// for now, try to make the multiple decls into a compoundstmt with them inside.
// if we don't get scoping problems, this might work
}
-
+
DeclGroupRef dgr = clangDS->getDeclGroup();
clang::DeclGroupRef::iterator DI = dgr.begin();
clang::DeclGroupRef::iterator DE = dgr.end();
-
- for ( ; DI != DE; ++DI) {
+
+ for (; DI != DE; ++DI) {
Decl *D = *DI;
- const char *declty = D->getDeclKindName();
+ const char *declty = D->getDeclKindName();
//fprintf(stderr, "a decl of type %s\n", D->getDeclKindName());
-
+
if (!strcmp("Var", declty)) {
VarDecl *V = dyn_cast<VarDecl>(D);
// ValueDecl *VD = dyn_cast<ValueDecl>(D); // not needed?
std::string Name = V->getNameAsString();
- char *varname = strdup( Name.c_str());
-
+ char *varname = strdup(Name.c_str());
+
//fprintf(stderr, "variable named %s\n", Name.c_str());
QualType T = V->getType();
string TypeStr = T.getAsString();
- char *vartype = strdup( TypeStr.c_str());
-
+ char *vartype = strdup(TypeStr.c_str());
+
//fprintf(stderr, "%s %s\n", td, varname);
- char *arraypart = splitTypeInfo( vartype );
-
- chillvardecl = new chillAST_VarDecl(vartype, varname, arraypart, (void *)D, p );
+ char *arraypart = splitTypeInfo(vartype);
+
+ chillvardecl = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, p);
//fprintf(stderr, "DeclStmt (clang 0x%x) for %s %s%s\n", D, vartype, varname, arraypart);
// store this away for declrefexpr that references it!
VariableDeclarations.push_back(chillvardecl);
-
- if (multiples) p->addChild( chillvardecl );
+
+ if (multiples) p->addChild(chillvardecl);
// TODO
- if (V->hasInit()) {
+ if (V->hasInit()) {
CHILL_ERROR(" ConvertDeclStmt() UNHANDLED initialization\n");
- exit(-1);
+ exit(-1);
}
}
} // for each of possibly multiple decls
-
+
if (multiples) return NULL; // multiple decls added themselves already
return chillvardecl; // OR a single decl
}
-
-chillAST_node * ConvertCompoundStmt( CompoundStmt *clangCS, chillAST_node *p ) {
+chillAST_node *ConvertCompoundStmt(CompoundStmt *clangCS, chillAST_node *p) {
//fprintf(stderr, "ConvertCompoundStmt( )\n");
- int numchildren= clangCS->size();
+ int numchildren = clangCS->size();
//fprintf(stderr, "clang CompoundStmt has %d children\n", numchildren);
// make an empty CHILL compound statement
- chillAST_CompoundStmt *chillCS = new chillAST_CompoundStmt;
- chillCS->setParent( p );
+ chillAST_CompoundStmt *chillCS = new chillAST_CompoundStmt;
+ chillCS->setParent(p);
// for each clang child
- for (auto I = clangCS->child_begin(); I!=clangCS->child_end(); ++I) { // ?? loop looks WRONG
+ for (auto I = clangCS->child_begin(); I != clangCS->child_end(); ++I) { // ?? loop looks WRONG
// create the chill ast for each child
Stmt *child = *I;
- chillAST_node *n = ConvertGenericClangAST( child, chillCS );
+ chillAST_node *n = ConvertGenericClangAST(child, chillCS);
// usually n will be a statement. We just add it as a child.
// SOME DeclStmts have multiple declarations. They will add themselves and return NULL
- if (n) chillCS->addChild( n );
+ if (n) chillCS->addChild(n);
}
-
+
return chillCS;
}
-
-
-chillAST_node * ConvertFunctionDecl( FunctionDecl *D, chillAST_node *p ) {
+chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) {
//fprintf(stderr, "\nConvertFunctionDecl( )\n");
QualType QT = D->getReturnType();
string ReturnTypeStr = QT.getAsString();
@@ -881,108 +895,110 @@ chillAST_node * ConvertFunctionDecl( FunctionDecl *D, chillAST_node *p ) {
//fprintf(stderr, "function %s has type %s ", FuncName.c_str(), ReturnTypeStr.c_str());
//fprintf(stderr, "\n%s %s()\n", ReturnTypeStr.c_str(), FuncName.c_str());
- chillAST_FunctionDecl *chillFD = new chillAST_FunctionDecl( ReturnTypeStr.c_str(), FuncName.c_str(), p, D);
-
+ chillAST_FunctionDecl *chillFD = new chillAST_FunctionDecl(ReturnTypeStr.c_str(), FuncName.c_str(), p, D);
+
int numparams = D->getNumParams();
- CHILL_DEBUG_PRINT( " %d parameters\n", numparams);
- for (int i=0; i<numparams; i++) {
+ CHILL_DEBUG_PRINT(" %d parameters\n", numparams);
+ for (int i = 0; i < numparams; i++) {
VarDecl *clangvardecl = D->getParamDecl(i); // the ith parameter (CLANG)
- ParmVarDecl *pvd = D->getParamDecl(i);
+ ParmVarDecl *pvd = D->getParamDecl(i);
QualType T = pvd->getOriginalType();
CHILL_DEBUG_PRINT("OTYPE %s\n", T.getAsString().c_str());
- chillAST_VarDecl *chillPVD = (chillAST_VarDecl *)ConvertVarDecl( clangvardecl, chillFD ) ;
+ chillAST_VarDecl *chillPVD = (chillAST_VarDecl *) ConvertVarDecl(clangvardecl, chillFD);
//chillPVD->print(); fflush(stdout);
//chillPVD->isAParameter = 1;
- VariableDeclarations.push_back(chillPVD);
-
- chillFD->addParameter(chillPVD);
- CHILL_DEBUG_PRINT("chillAST ParmVarDecl for %s from chill location 0x%x\n",chillPVD->varname, clangvardecl);
+ VariableDeclarations.push_back(chillPVD);
+
+ chillFD->addParameter(chillPVD);
+ 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(); CHILL_DEBUG_PRINT("%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
//fprintf(stderr, "body of type %s\n", clangbody->getStmtClassName());
//chillAST_node *CB = ConvertCompoundStmt( dyn_cast<CompoundStmt>(clangbody) ); // always a compound statement?
- chillAST_node *CB = ConvertGenericClangAST( clangbody, chillFD );
+ chillAST_node *CB = ConvertGenericClangAST(clangbody, chillFD);
//fprintf(stderr, "FunctionDecl body = 0x%x of type %s\n", CB, CB->getTypeString());
- chillFD->setBody ( CB );
+ chillFD->setBody(CB);
}
//fprintf(stderr, "adding function %s 0x%x to FunctionDeclarations\n", chillFD->functionName, chillFD);
- FunctionDeclarations.push_back(chillFD);
- return chillFD;
+ FunctionDeclarations.push_back(chillFD);
+ return chillFD;
}
-chillAST_node * ConvertForStmt( ForStmt *clangFS, chillAST_node *p ) {
+chillAST_node *ConvertForStmt(ForStmt *clangFS, chillAST_node *p) {
Stmt *init = clangFS->getInit();
Expr *cond = clangFS->getCond();
Expr *incr = clangFS->getInc();
Stmt *body = clangFS->getBody();
- chillAST_node *ini = ConvertGenericClangAST( init, NULL );
- chillAST_node *con = ConvertGenericClangAST( cond, NULL);
- chillAST_node *inc = ConvertGenericClangAST( incr, NULL);
- chillAST_node *bod = ConvertGenericClangAST( body, NULL);
- if (bod->asttype != CHILLAST_NODETYPE_COMPOUNDSTMT) {
+ chillAST_node *ini = ConvertGenericClangAST(init, NULL);
+ chillAST_node *con = ConvertGenericClangAST(cond, NULL);
+ chillAST_node *inc = ConvertGenericClangAST(incr, NULL);
+ chillAST_node *bod = ConvertGenericClangAST(body, NULL);
+ if (bod->asttype != CHILLAST_NODETYPE_COMPOUNDSTMT) {
//fprintf(stderr, "ForStmt body of type %s\n", bod->getTypeString());
// make single statement loop bodies loop like other loops
- chillAST_CompoundStmt *cs = new chillAST_CompoundStmt( );
- cs->addChild( bod );
+ chillAST_CompoundStmt *cs = new chillAST_CompoundStmt();
+ cs->addChild(bod);
bod = cs;
}
- chillAST_ForStmt *chill_loop = new chillAST_ForStmt( ini, con, inc, bod, p );
- ini->setParent( chill_loop );
- con->setParent( chill_loop );
- inc->setParent( chill_loop );
- bod->setParent( chill_loop );
+ chillAST_ForStmt *chill_loop = new chillAST_ForStmt(ini, con, inc, bod, p);
+ ini->setParent(chill_loop);
+ con->setParent(chill_loop);
+ inc->setParent(chill_loop);
+ bod->setParent(chill_loop);
- return chill_loop;
+ return chill_loop;
}
-chillAST_node * ConvertIfStmt( IfStmt *clangIS, chillAST_node *p ) {
+chillAST_node *ConvertIfStmt(IfStmt *clangIS, chillAST_node *p) {
Expr *cond = clangIS->getCond();
Stmt *thenpart = clangIS->getThen();
Stmt *elsepart = clangIS->getElse();
-
- chillAST_node *con = ConvertGenericClangAST( cond, NULL);
+
+ chillAST_node *con = ConvertGenericClangAST(cond, NULL);
chillAST_node *thn = NULL;
- if (thenpart) thn = ConvertGenericClangAST( thenpart, NULL);
+ if (thenpart) thn = ConvertGenericClangAST(thenpart, NULL);
chillAST_node *els = NULL;
- if (elsepart) els = ConvertGenericClangAST( elsepart, NULL);
-
- chillAST_IfStmt *ifstmt = new chillAST_IfStmt( con, thn, els, NULL);
- return ifstmt;
-}
+ if (elsepart) els = ConvertGenericClangAST(elsepart, NULL);
+ chillAST_IfStmt *ifstmt = new chillAST_IfStmt(con, thn, els, NULL);
+ return ifstmt;
+}
-chillAST_node * ConvertUnaryOperator( UnaryOperator * clangUO, chillAST_node *p ) {
+chillAST_node *ConvertUnaryOperator(UnaryOperator *clangUO, chillAST_node *p) {
const char *op = unops[clangUO->getOpcode()].c_str();
bool pre = clangUO->isPrefix();
- chillAST_node *sub = ConvertGenericClangAST( clangUO->getSubExpr(), NULL );
+ chillAST_node *sub = ConvertGenericClangAST(clangUO->getSubExpr(), NULL);
- chillAST_UnaryOperator *chillUO = new chillAST_UnaryOperator( op, pre, sub, p );
- sub->setParent( chillUO );
- return chillUO;
+ chillAST_UnaryOperator *chillUO = new chillAST_UnaryOperator(op, pre, sub, p);
+ sub->setParent(chillUO);
+ return chillUO;
}
-chillAST_node * ConvertBinaryOperator( BinaryOperator * clangBO, chillAST_node *p ) {
+chillAST_node *ConvertBinaryOperator(BinaryOperator *clangBO, chillAST_node *p) {
// get the clang parts
Expr *lhs = clangBO->getLHS();
@@ -991,40 +1007,37 @@ chillAST_node * ConvertBinaryOperator( BinaryOperator * clangBO, chillAST_node *
// convert to chill equivalents
- chillAST_node *l = ConvertGenericClangAST( lhs, NULL );
+ chillAST_node *l = ConvertGenericClangAST(lhs, NULL);
const char *opstring = binops[op].c_str();
- chillAST_node *r = ConvertGenericClangAST( rhs, NULL );
+ chillAST_node *r = ConvertGenericClangAST(rhs, NULL);
// TODO chill equivalent for numeric op.
// build up the chill Binary Op AST node
- chillAST_BinaryOperator * binop = new chillAST_BinaryOperator( l, opstring, r, p );
- l->setParent( binop );
- r->setParent( binop );
+ chillAST_BinaryOperator *binop = new chillAST_BinaryOperator(l, opstring, r, p);
+ l->setParent(binop);
+ r->setParent(binop);
- return binop;
+ return binop;
}
+chillAST_node *ConvertArraySubscriptExpr(ArraySubscriptExpr *clangASE, chillAST_node *p) {
-
-chillAST_node * ConvertArraySubscriptExpr( ArraySubscriptExpr *clangASE, chillAST_node *p ) {
-
- Expr *clangbase = clangASE->getBase();
+ Expr *clangbase = clangASE->getBase();
Expr *clangindex = clangASE->getIdx();
//fprintf(stderr, "clang base: "); clangbase->dump(); fprintf(stderr, "\n");
- chillAST_node *bas = ConvertGenericClangAST( clangbase, NULL );
- chillAST_node *indx = ConvertGenericClangAST( clangindex, NULL );
-
- chillAST_ArraySubscriptExpr * chillASE = new chillAST_ArraySubscriptExpr( bas, indx, p, clangASE);
- bas->setParent( chillASE );
- indx->setParent( chillASE );
- return chillASE;
-}
+ chillAST_node *bas = ConvertGenericClangAST(clangbase, NULL);
+ chillAST_node *indx = ConvertGenericClangAST(clangindex, NULL);
+ chillAST_ArraySubscriptExpr *chillASE = new chillAST_ArraySubscriptExpr(bas, indx, p, clangASE);
+ bas->setParent(chillASE);
+ indx->setParent(chillASE);
+ return chillASE;
+}
-chillAST_node * ConvertDeclRefExpr( DeclRefExpr * clangDRE, chillAST_node *p ) {
+chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) {
DeclarationNameInfo DNI = clangDRE->getNameInfo();
ValueDecl *vd = static_cast<ValueDecl *>(clangDRE->getDecl()); // ValueDecl ?? VarDecl ??
@@ -1035,232 +1048,232 @@ chillAST_node * ConvertDeclRefExpr( DeclRefExpr * clangDRE, chillAST_node *p ) {
//fprintf(stderr, "kind %s\n", vd->getDeclKindName());
DeclarationName DN = DNI.getName();
- const char *varname = DN.getAsString().c_str() ;
- chillAST_DeclRefExpr * chillDRE = new chillAST_DeclRefExpr(TypeStr.c_str(), varname, p );
+ const char *varname = DN.getAsString().c_str();
+ chillAST_DeclRefExpr *chillDRE = new chillAST_DeclRefExpr(TypeStr.c_str(), varname, p);
//fprintf(stderr, "clang DeclRefExpr refers to declaration of %s @ 0x%x\n", varname, vd);
//fprintf(stderr, "clang DeclRefExpr refers to declaration of %s of kind %s\n", varname, vd->getDeclKindName());
-
+
// find the definition (we hope)
- if ( (!strcmp("Var", vd->getDeclKindName())) || (!strcmp("ParmVar", vd->getDeclKindName()))) {
+ if ((!strcmp("Var", vd->getDeclKindName())) || (!strcmp("ParmVar", vd->getDeclKindName()))) {
// it's a variable reference
int numvars = VariableDeclarations.size();
chillAST_VarDecl *chillvd = NULL;
- for (int i=0; i<numvars; i++) {
+ for (int i = 0; i < numvars; i++) {
if (VariableDeclarations[i]->uniquePtr == vd) {
chillvd = VariableDeclarations[i];
//fprintf(stderr, "found it at variabledeclaration %d of %d\n", i, numvars);
}
}
- if (!chillvd) {
- fprintf(stderr, "\nWARNING, ir_clang.cc clang DeclRefExpr %s refers to a declaration I can't find! at ox%x\n", varname, vd);
+ if (!chillvd) {
+ fprintf(stderr, "\nWARNING, ir_clang.cc clang DeclRefExpr %s refers to a declaration I can't find! at ox%x\n",
+ varname, vd);
fprintf(stderr, "variables I know of are:\n");
- for (int i=0; i<numvars; i++) {
+ for (int i = 0; i < numvars; i++) {
chillAST_VarDecl *adecl = VariableDeclarations[i];
if (adecl->isParmVarDecl()) fprintf(stderr, "(parameter) ");
- fprintf(stderr, "%s %s at location 0x%x\n", adecl->vartype, adecl->varname, adecl->uniquePtr);
- }
- fprintf(stderr, "\n");
+ fprintf(stderr, "%s %s at location 0x%x\n", adecl->vartype, adecl->varname, adecl->uniquePtr);
+ }
+ fprintf(stderr, "\n");
}
-
- if (chillvd == NULL) { fprintf(stderr, "chillDRE->decl = 0x%x\n", chillvd); exit(-1); }
- chillDRE->decl = (chillAST_node *)chillvd; // start of spaghetti pointers ...
- }
- else if (!strcmp("Function", vd->getDeclKindName())) {
+ if (chillvd == NULL) {
+ fprintf(stderr, "chillDRE->decl = 0x%x\n", chillvd);
+ exit(-1);
+ }
+
+ chillDRE->decl = (chillAST_node *) chillvd; // start of spaghetti pointers ...
+ } else if (!strcmp("Function", vd->getDeclKindName())) {
//fprintf(stderr, "declrefexpr of type Function\n");
int numfuncs = FunctionDeclarations.size();
chillAST_FunctionDecl *chillfd = NULL;
- for (int i=0; i<numfuncs; i++) {
+ for (int i = 0; i < numfuncs; i++) {
if (FunctionDeclarations[i]->uniquePtr == vd) {
chillfd = FunctionDeclarations[i];
//fprintf(stderr, "found it at functiondeclaration %d of %d\n", i, numfuncs);
}
}
- if (chillfd == NULL) { fprintf(stderr, "chillDRE->decl = 0x%x\n", chillfd); exit(-1); }
+ if (chillfd == NULL) {
+ fprintf(stderr, "chillDRE->decl = 0x%x\n", chillfd);
+ exit(-1);
+ }
- chillDRE->decl = (chillAST_node *)chillfd; // start of spaghetti pointers ...
-
- }
- else {
- fprintf(stderr, "clang DeclRefExpr refers to declaration of %s of kind %s\n", varname, vd->getDeclKindName());
- fprintf(stderr, "chillDRE->decl = UNDEFINED\n");
- exit(-1);
+ chillDRE->decl = (chillAST_node *) chillfd; // start of spaghetti pointers ...
+
+ } else {
+ fprintf(stderr, "clang DeclRefExpr refers to declaration of %s of kind %s\n", varname, vd->getDeclKindName());
+ fprintf(stderr, "chillDRE->decl = UNDEFINED\n");
+ exit(-1);
}
//fprintf(stderr, "%s\n", DN.getAsString().c_str());
- return chillDRE;
+ return chillDRE;
}
-
-chillAST_node * ConvertIntegerLiteral( IntegerLiteral *clangIL, chillAST_node *p ) {
+chillAST_node *ConvertIntegerLiteral(IntegerLiteral *clangIL, chillAST_node *p) {
bool isSigned = clangIL->getType()->isSignedIntegerType();
//int val = clangIL->getIntValue();
- const char *printable = clangIL->getValue().toString(10, isSigned).c_str();
- int val = atoi( printable );
+ const char *printable = clangIL->getValue().toString(10, isSigned).c_str();
+ int val = atoi(printable);
//fprintf(stderr, "int value %s (%d)\n", printable, val);
- chillAST_IntegerLiteral *chillIL = new chillAST_IntegerLiteral( val, p );
- return chillIL;
+ chillAST_IntegerLiteral *chillIL = new chillAST_IntegerLiteral(val, p);
+ return chillIL;
}
-chillAST_node * ConvertFloatingLiteral( FloatingLiteral *clangFL, chillAST_node *p ) {
+chillAST_node *ConvertFloatingLiteral(FloatingLiteral *clangFL, chillAST_node *p) {
//fprintf(stderr, "\nConvertFloatingLiteral()\n");
float val = clangFL->getValueAsApproximateDouble(); // TODO approx is a bad idea!
- string WHAT;
+ string WHAT;
SmallString<16> Str;
- clangFL->getValue().toString( Str );
- const char *printable = Str.c_str();
+ clangFL->getValue().toString(Str);
+ const char *printable = Str.c_str();
//fprintf(stderr, "literal %s\n", printable);
SourceLocation sloc = clangFL->getLocStart();
SourceLocation eloc = clangFL->getLocEnd();
- std::string start = sloc.printToString( *globalSRCMAN );
- std::string end = eloc.printToString( *globalSRCMAN );
+ std::string start = sloc.printToString(*globalSRCMAN);
+ std::string end = eloc.printToString(*globalSRCMAN);
//fprintf(stderr, "literal try2 start %s end %s\n", start.c_str(), end.c_str());
//printlines( sloc, eloc, globalSRCMAN );
- unsigned int startlineno = globalSRCMAN->getPresumedLineNumber( sloc );
- unsigned int endlineno = globalSRCMAN->getPresumedLineNumber( eloc ); ;
- const char *filename = globalSRCMAN->getBufferName( sloc );
+ unsigned int startlineno = globalSRCMAN->getPresumedLineNumber(sloc);
+ unsigned int endlineno = globalSRCMAN->getPresumedLineNumber(eloc);;
+ const char *filename = globalSRCMAN->getBufferName(sloc);
- std::string fname = globalSRCMAN->getFilename( sloc );
+ std::string fname = globalSRCMAN->getFilename(sloc);
//fprintf(stderr, "fname %s\n", fname.c_str());
if (filename && strlen(filename) > 0) {} // fprintf(stderr, "literal file '%s'\n", filename);
- else {
- fprintf(stderr, "\nConvertFloatingLiteral() filename is NULL?\n");
+ else {
+ fprintf(stderr, "\nConvertFloatingLiteral() filename is NULL?\n");
//sloc = globalSRCMAN->getFileLoc( sloc ); // should get spelling loc?
- sloc = globalSRCMAN->getSpellingLoc( sloc ); // should get spelling loc?
+ sloc = globalSRCMAN->getSpellingLoc(sloc); // should get spelling loc?
//eloc = globalSRCMAN->getFileLoc( eloc );
- start = sloc.printToString( *globalSRCMAN );
+ start = sloc.printToString(*globalSRCMAN);
//end = eloc.printToString( *globalSRCMAN );
//fprintf(stderr, "literal try3 start %s end %s\n", start.c_str(), end.c_str());
-
- startlineno = globalSRCMAN->getPresumedLineNumber( sloc );
+
+ startlineno = globalSRCMAN->getPresumedLineNumber(sloc);
//endlineno = globalSRCMAN->getPresumedLineNumber( eloc ); ;
//fprintf(stderr, "start, end line numbers %d %d\n", startlineno, endlineno);
-
- filename = globalSRCMAN->getBufferName( sloc );
+
+ filename = globalSRCMAN->getBufferName(sloc);
//if (globalSRCMAN->isMacroBodyExpansion( sloc )) {
// fprintf(stderr, "IS MACRO\n");
//}
}
-
- unsigned int offset = globalSRCMAN->getFileOffset( sloc );
+
+ unsigned int offset = globalSRCMAN->getFileOffset(sloc);
//fprintf(stderr, "literal file offset %d\n", offset);
- FILE *fp = fopen (filename, "r");
+ FILE *fp = fopen(filename, "r");
fseek(fp, offset, SEEK_SET); // go to the part of the file where the float is defined
-
+
char buf[10240];
- fgets (buf, sizeof(buf), fp); // read a line starting where the float starts
+ fgets(buf, sizeof(buf), fp); // read a line starting where the float starts
fclose(fp);
// buf has the line we want grab the float constant out of it
//fprintf(stderr, "\nbuf '%s'\n", buf);
char *ptr = buf;
if (*ptr == '-') ptr++; // ignore possible minus sign
- int len = strspn(ptr, ".-0123456789f");
+ int len = strspn(ptr, ".-0123456789f");
buf[len] = '\0';
//fprintf(stderr, "'%s'\n", buf);
- chillAST_FloatingLiteral *chillFL = new chillAST_FloatingLiteral( val, buf, p );
-
+ chillAST_FloatingLiteral *chillFL = new chillAST_FloatingLiteral(val, buf, p);
+
//chillFL->print(); printf("\n"); fflush(stdout);
- return chillFL;
+ return chillFL;
}
-chillAST_node * ConvertImplicitCastExpr( ImplicitCastExpr *clangICE, chillAST_node *p ) {
+chillAST_node *ConvertImplicitCastExpr(ImplicitCastExpr *clangICE, chillAST_node *p) {
//fprintf(stderr, "ConvertImplicitCastExpr()\n");
CastExpr *CE = dyn_cast<ImplicitCastExpr>(clangICE);
//fprintf(stderr, "implicit cast of type %s\n", CE->getCastKindName());
- chillAST_node * sub = ConvertGenericClangAST( clangICE->getSubExpr(), p );
- chillAST_ImplicitCastExpr *chillICE = new chillAST_ImplicitCastExpr( sub, p );
-
+ chillAST_node *sub = ConvertGenericClangAST(clangICE->getSubExpr(), p);
+ chillAST_ImplicitCastExpr *chillICE = new chillAST_ImplicitCastExpr(sub, p);
+
//sub->setParent( chillICE ); // these 2 lines work
//return chillICE;
//sub->setParent(p); // ignore the ImplicitCastExpr !! TODO (probably a bad idea)
- return sub;
+ return sub;
}
-
-
-chillAST_node * ConvertCStyleCastExpr( CStyleCastExpr *clangCSCE, chillAST_node *p ) {
+chillAST_node *ConvertCStyleCastExpr(CStyleCastExpr *clangCSCE, chillAST_node *p) {
//fprintf(stderr, "ConvertCStyleCastExpr()\n");
//fprintf(stderr, "C Style cast of kind ");
CastExpr *CE = dyn_cast<CastExpr>(clangCSCE);
//fprintf(stderr, "%s\n", CE->getCastKindName());
-
+
//clangCSCE->getTypeAsWritten().getAsString(Policy)
- const char * towhat = strdup( clangCSCE->getTypeAsWritten().getAsString().c_str() );
+ const char *towhat = strdup(clangCSCE->getTypeAsWritten().getAsString().c_str());
//fprintf(stderr, "before sub towhat (%s)\n", towhat);
- chillAST_node * sub = ConvertGenericClangAST( clangCSCE->getSubExprAsWritten(), NULL );
+ chillAST_node *sub = ConvertGenericClangAST(clangCSCE->getSubExprAsWritten(), NULL);
//fprintf(stderr, "after sub towhat (%s)\n", towhat);
- chillAST_CStyleCastExpr *chillCSCE = new chillAST_CStyleCastExpr( towhat, sub, p );
+ chillAST_CStyleCastExpr *chillCSCE = new chillAST_CStyleCastExpr(towhat, sub, p);
//fprintf(stderr, "after CSCE towhat (%s)\n", towhat);
- sub->setParent( chillCSCE );
- return chillCSCE;
+ sub->setParent(chillCSCE);
+ return chillCSCE;
}
-
-
-chillAST_node * ConvertReturnStmt( ReturnStmt *clangRS, chillAST_node *p ) {
- chillAST_node * retval = ConvertGenericClangAST( clangRS->getRetValue(), NULL ); // NULL is handled
+chillAST_node *ConvertReturnStmt(ReturnStmt *clangRS, chillAST_node *p) {
+ chillAST_node *retval = ConvertGenericClangAST(clangRS->getRetValue(), NULL); // NULL is handled
//if (retval == NULL) fprintf(stderr, "return stmt returns nothing\n");
- chillAST_ReturnStmt * chillRS = new chillAST_ReturnStmt( retval, p );
- if (retval) retval->setParent( chillRS );
- return chillRS;
+ chillAST_ReturnStmt *chillRS = new chillAST_ReturnStmt(retval, p);
+ if (retval) retval->setParent(chillRS);
+ return chillRS;
}
-chillAST_node * ConvertCallExpr( CallExpr *clangCE, chillAST_node *p ) {
+chillAST_node *ConvertCallExpr(CallExpr *clangCE, chillAST_node *p) {
//fprintf(stderr, "ConvertCallExpr()\n");
- chillAST_node *callee = ConvertGenericClangAST( clangCE->getCallee(), NULL );
+ chillAST_node *callee = ConvertGenericClangAST(clangCE->getCallee(), NULL);
//fprintf(stderr, "callee is of type %s\n", callee->getTypeString());
//chillAST_node *next = ((chillAST_ImplicitCastExpr *)callee)->subexpr;
//fprintf(stderr, "callee is of type %s\n", next->getTypeString());
- chillAST_CallExpr *chillCE = new chillAST_CallExpr( callee, p );
- callee->setParent( chillCE );
+ chillAST_CallExpr *chillCE = new chillAST_CallExpr(callee, p);
+ callee->setParent(chillCE);
int numargs = clangCE->getNumArgs();
//fprintf(stderr, "CallExpr has %d args\n", numargs);
- Expr **clangargs = clangCE->getArgs();
- for (int i=0; i<numargs; i++) {
- chillCE->addArg( ConvertGenericClangAST( clangargs[i], chillCE ) );
+ Expr **clangargs = clangCE->getArgs();
+ for (int i = 0; i < numargs; i++) {
+ chillCE->addArg(ConvertGenericClangAST(clangargs[i], chillCE));
}
-
- return chillCE;
+
+ return chillCE;
}
-chillAST_node * ConvertParenExpr( ParenExpr *clangPE, chillAST_node *p ) {
- chillAST_node *sub = ConvertGenericClangAST( clangPE->getSubExpr(), NULL);
- chillAST_ParenExpr *chillPE = new chillAST_ParenExpr( sub, p);
- sub->setParent( chillPE );
+chillAST_node *ConvertParenExpr(ParenExpr *clangPE, chillAST_node *p) {
+ chillAST_node *sub = ConvertGenericClangAST(clangPE->getSubExpr(), NULL);
+ chillAST_ParenExpr *chillPE = new chillAST_ParenExpr(sub, p);
+ sub->setParent(chillPE);
- return chillPE;
+ return chillPE;
}
-chillAST_node * ConvertTranslationUnit( TranslationUnitDecl *TUD, char *filename ) {
+chillAST_node *ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename) {
//fprintf(stderr, "ConvertTranslationUnit( filename %s )\n\n", filename);
// TUD derived from Decl and DeclContext
- static DeclContext *DC = TUD->castToDeclContext( TUD );
+ static DeclContext *DC = TUD->castToDeclContext(TUD);
// TODO this was to get the filename without having to pass it in
@@ -1271,35 +1284,33 @@ chillAST_node * ConvertTranslationUnit( TranslationUnitDecl *TUD, char *filenam
//const char *filename = SRCMAN->getBufferName( srcloc );
- chillAST_SourceFile * topnode = new chillAST_SourceFile( filename );
- topnode->setFrontend("clang");
- topnode->chill_array_counter = 1;
+ chillAST_SourceFile *topnode = new chillAST_SourceFile(filename);
+ topnode->setFrontend("clang");
+ topnode->chill_array_counter = 1;
topnode->chill_scalar_counter = 0;
// now recursively build clang AST from the children of TUD
//for (DeclContext::decl_iterator DI = DC->decls_begin(), DE = DC->decls_end(); DI != DE; ++DI)
DeclContext::decl_iterator start = DC->decls_begin();
- DeclContext::decl_iterator end = DC->decls_end();
- for (DeclContext::decl_iterator DI=start; DI != end; ++DI) {
+ DeclContext::decl_iterator end = DC->decls_end();
+ for (DeclContext::decl_iterator DI = start; DI != end; ++DI) {
Decl *D = *DI;
-
- if (isa<FunctionDecl>(D)) { //fprintf(stderr, "\nTUD FunctionDecl\n");
- topnode->addChild( ConvertFunctionDecl( dyn_cast<FunctionDecl>(D), topnode ));
- }
- else if (isa<VarDecl>(D)) { //fprintf(stderr, "\nTUD VarDecl\n");
- topnode->addChild( ConvertVarDecl( dyn_cast<VarDecl>(D), topnode ));
+
+ if (isa<FunctionDecl>(D)) { //fprintf(stderr, "\nTUD FunctionDecl\n");
+ topnode->addChild(ConvertFunctionDecl(dyn_cast<FunctionDecl>(D), topnode));
+ } else if (isa<VarDecl>(D)) { //fprintf(stderr, "\nTUD VarDecl\n");
+ topnode->addChild(ConvertVarDecl(dyn_cast<VarDecl>(D), topnode));
//fflush(stdout); fprintf(stderr, "\nTUD VarDecl DONE\n");
- }
- else if (isa<TypedefDecl>(D)) { //fprintf(stderr, "\nTUD TypedefDecl\n");
- topnode->addChild( ConvertTypeDefDecl( dyn_cast<TypedefDecl>(D), topnode ));
- }
- else if (isa<RecordDecl>(D)) { fprintf(stderr, "\nTUD RecordDecl\n");
- topnode->addChild( ConvertRecordDecl( dyn_cast<RecordDecl>(D), topnode ));
- }
- else if (isa<TypeAliasDecl>(D)) { fprintf(stderr, "TUD TypeAliasDecl TODO \n"); exit(-1);
- }
- else {
- fprintf(stderr, "\nTUD a declaration of type %s (%d) which I can't handle\n", D->getDeclKindName(), D->getKind());
+ } else if (isa<TypedefDecl>(D)) { //fprintf(stderr, "\nTUD TypedefDecl\n");
+ topnode->addChild(ConvertTypeDefDecl(dyn_cast<TypedefDecl>(D), topnode));
+ } else if (isa<RecordDecl>(D)) {
+ fprintf(stderr, "\nTUD RecordDecl\n");
+ topnode->addChild(ConvertRecordDecl(dyn_cast<RecordDecl>(D), topnode));
+ } else if (isa<TypeAliasDecl>(D)) {
+ fprintf(stderr, "TUD TypeAliasDecl TODO \n");
+ exit(-1);
+ } else {
+ fprintf(stderr, "\nTUD a declaration of type %s (%d) which I can't handle\n", D->getDeclKindName(), D->getKind());
exit(-1);
}
}
@@ -1307,63 +1318,78 @@ chillAST_node * ConvertTranslationUnit( TranslationUnitDecl *TUD, char *filenam
//fprintf(stderr, "in ConvertTranslationUnit(), dumping the file\n");
//topnode->dump();
- return ( chillAST_node *) topnode;
+ return (chillAST_node *) topnode;
}
+chillAST_node *ConvertGenericClangAST(Stmt *s, chillAST_node *p) {
- chillAST_node * ConvertGenericClangAST( Stmt *s, chillAST_node *p ) {
-
- if (s == NULL) return NULL;
- //fprintf(stderr, "\nConvertGenericClangAST() Stmt of type %d (%s)\n", s->getStmtClass(),s->getStmtClassName());
- Decl *D = (Decl *) s;
- //if (isa<Decl>(D)) fprintf(stderr, "Decl of kind %d (%s)\n", D->getKind(),D->getDeclKindName() );
-
+ if (s == NULL) return NULL;
+ //fprintf(stderr, "\nConvertGenericClangAST() Stmt of type %d (%s)\n", s->getStmtClass(),s->getStmtClassName());
+ Decl *D = (Decl *) s;
+ //if (isa<Decl>(D)) fprintf(stderr, "Decl of kind %d (%s)\n", D->getKind(),D->getDeclKindName() );
- chillAST_node *ret = NULL;
- if (isa<CompoundStmt>(s)) {ret = ConvertCompoundStmt( dyn_cast<CompoundStmt>(s),p);
- } else if (isa<DeclStmt>(s)) {ret = ConvertDeclStmt(dyn_cast<DeclStmt>(s),p);
- } else if (isa<ForStmt>(s)) {ret = ConvertForStmt(dyn_cast<ForStmt>(s),p);
- } else if (isa<BinaryOperator>(s)) {ret = ConvertBinaryOperator(dyn_cast<BinaryOperator>(s),p);
- } else if (isa<ArraySubscriptExpr>(s)) {ret = ConvertArraySubscriptExpr(dyn_cast<ArraySubscriptExpr>(s),p);
- } else if (isa<DeclRefExpr>(s)) {ret = ConvertDeclRefExpr(dyn_cast<DeclRefExpr>(s),p);
- } else if (isa<FloatingLiteral>(s)) {ret = ConvertFloatingLiteral(dyn_cast<FloatingLiteral>(s),p);
- } else if (isa<IntegerLiteral>(s)) {ret = ConvertIntegerLiteral(dyn_cast<IntegerLiteral>(s),p);
- } else if (isa<UnaryOperator>(s)) {ret = ConvertUnaryOperator(dyn_cast<UnaryOperator>(s),p);
- } else if (isa<ImplicitCastExpr>(s)) {ret = ConvertImplicitCastExpr(dyn_cast<ImplicitCastExpr>(s),p);
- } else if (isa<CStyleCastExpr>(s)) {ret = ConvertCStyleCastExpr(dyn_cast<CStyleCastExpr>(s),p);
- } else if (isa<ReturnStmt>(s)) {ret = ConvertReturnStmt(dyn_cast<ReturnStmt>(s),p);
- } else if (isa<CallExpr>(s)) {ret = ConvertCallExpr(dyn_cast<CallExpr>(s),p);
- } else if (isa<ParenExpr>(s)) {ret = ConvertParenExpr(dyn_cast<ParenExpr>(s),p);
- } else if (isa<IfStmt>(s)) {ret = ConvertIfStmt(dyn_cast<IfStmt>(s),p);
- } else if (isa<MemberExpr>(s)) {ret = ConvertMemberExpr(dyn_cast<MemberExpr>(s),p);
+ chillAST_node *ret = NULL;
+ if (isa<CompoundStmt>(s)) {
+ ret = ConvertCompoundStmt(dyn_cast<CompoundStmt>(s), p);
+ } else if (isa<DeclStmt>(s)) {
+ ret = ConvertDeclStmt(dyn_cast<DeclStmt>(s), p);
+ } else if (isa<ForStmt>(s)) {
+ ret = ConvertForStmt(dyn_cast<ForStmt>(s), p);
+ } else if (isa<BinaryOperator>(s)) {
+ ret = ConvertBinaryOperator(dyn_cast<BinaryOperator>(s), p);
+ } else if (isa<ArraySubscriptExpr>(s)) {
+ ret = ConvertArraySubscriptExpr(dyn_cast<ArraySubscriptExpr>(s), p);
+ } else if (isa<DeclRefExpr>(s)) {
+ ret = ConvertDeclRefExpr(dyn_cast<DeclRefExpr>(s), p);
+ } else if (isa<FloatingLiteral>(s)) {
+ ret = ConvertFloatingLiteral(dyn_cast<FloatingLiteral>(s), p);
+ } else if (isa<IntegerLiteral>(s)) {
+ ret = ConvertIntegerLiteral(dyn_cast<IntegerLiteral>(s), p);
+ } else if (isa<UnaryOperator>(s)) {
+ ret = ConvertUnaryOperator(dyn_cast<UnaryOperator>(s), p);
+ } else if (isa<ImplicitCastExpr>(s)) {
+ ret = ConvertImplicitCastExpr(dyn_cast<ImplicitCastExpr>(s), p);
+ } else if (isa<CStyleCastExpr>(s)) {
+ ret = ConvertCStyleCastExpr(dyn_cast<CStyleCastExpr>(s), p);
+ } else if (isa<ReturnStmt>(s)) {
+ ret = ConvertReturnStmt(dyn_cast<ReturnStmt>(s), p);
+ } else if (isa<CallExpr>(s)) {
+ ret = ConvertCallExpr(dyn_cast<CallExpr>(s), p);
+ } else if (isa<ParenExpr>(s)) {
+ ret = ConvertParenExpr(dyn_cast<ParenExpr>(s), p);
+ } else if (isa<IfStmt>(s)) {
+ ret = ConvertIfStmt(dyn_cast<IfStmt>(s), p);
+ } else if (isa<MemberExpr>(s)) {
+ ret = ConvertMemberExpr(dyn_cast<MemberExpr>(s), p);
- // these can only happen at the top level?
- // } else if (isa<FunctionDecl>(D)) { ret = ConvertFunctionDecl( dyn_cast<FunctionDecl>(D));
- //} else if (isa<VarDecl>(D)) { ret = ConvertVarDecl( dyn_cast<VarDecl>(D) );
- //} else if (isa<TypedefDecl>(D)) { ret = ConvertTypeDefDecl( dyn_cast<TypedefDecl>(D));
- // else if (isa<TranslationUnitDecl>(s)) // need filename
+ // these can only happen at the top level?
+ // } else if (isa<FunctionDecl>(D)) { ret = ConvertFunctionDecl( dyn_cast<FunctionDecl>(D));
+ //} else if (isa<VarDecl>(D)) { ret = ConvertVarDecl( dyn_cast<VarDecl>(D) );
+ //} else if (isa<TypedefDecl>(D)) { ret = ConvertTypeDefDecl( dyn_cast<TypedefDecl>(D));
+ // else if (isa<TranslationUnitDecl>(s)) // need filename
- // } else if (isa<>(s)) { Convert ( dyn_cast<>(s));
- /*
- */
+ // } else if (isa<>(s)) { Convert ( dyn_cast<>(s));
- } else {
- // more work to do
- fprintf(stderr, "ir_clang.cc ConvertGenericClangAST() UNHANDLED ");
- //if (isa<Decl>(D)) fprintf(stderr, "Decl of kind %s\n", D->getDeclKindName() );
- if (isa<Stmt>(s))fprintf(stderr, "Stmt of type %s\n", s->getStmtClassName());
- exit(-1);
- }
-
- return ret;
- }
+ /*
+ */
+
+ } else {
+ // more work to do
+ fprintf(stderr, "ir_clang.cc ConvertGenericClangAST() UNHANDLED ");
+ //if (isa<Decl>(D)) fprintf(stderr, "Decl of kind %s\n", D->getDeclKindName() );
+ if (isa<Stmt>(s))fprintf(stderr, "Stmt of type %s\n", s->getStmtClassName());
+ exit(-1);
+ }
+
+ return ret;
+}
@@ -1377,18 +1403,18 @@ chillAST_node * ConvertTranslationUnit( TranslationUnitDecl *TUD, char *filenam
// ----------------------------------------------------------------------------
// Class: IR_chillScalarSymbol
// ----------------------------------------------------------------------------
-
+
std::string IR_chillScalarSymbol::name() const {
//return vd_->getNameAsString(); CLANG
//fprintf(stderr, "IR_chillScalarSymbol::name() %s\n", chillvd->varname);
return std::string(chillvd->varname); // CHILL
}
-
+
// Return size in bytes
int IR_chillScalarSymbol::size() const {
//return (vd_->getASTContext().getTypeSize(vd_->getType())) / 8; // ??
- fprintf(stderr, "IR_chillScalarSymbol::size() probably WRONG\n");
+ fprintf(stderr, "IR_chillScalarSymbol::size() probably WRONG\n");
return (8); // bytes??
}
@@ -1397,13 +1423,13 @@ bool IR_chillScalarSymbol::operator==(const IR_Symbol &that) const {
//fprintf(stderr, "IR_xxxxScalarSymbol::operator== probably WRONG\n");
if (typeid(*this) != typeid(that))
return false;
-
+
const IR_chillScalarSymbol *l_that = static_cast<const IR_chillScalarSymbol *>(&that);
return this->chillvd == l_that->chillvd;
}
IR_Symbol *IR_chillScalarSymbol::clone() const {
- return new IR_chillScalarSymbol(ir_, chillvd ); // clone
+ return new IR_chillScalarSymbol(ir_, chillvd); // clone
}
// ----------------------------------------------------------------------------
@@ -1411,12 +1437,13 @@ IR_Symbol *IR_chillScalarSymbol::clone() const {
// ----------------------------------------------------------------------------
std::string IR_chillArraySymbol::name() const {
- return std::string( strdup( chillvd ->varname));
+ return std::string(strdup(chillvd->varname));
}
int IR_chillArraySymbol::elem_size() const {
- fprintf(stderr, "IR_chillArraySymbol::elem_size() TODO\n"); exit(-1);
+ fprintf(stderr, "IR_chillArraySymbol::elem_size() TODO\n");
+ exit(-1);
return 8; // TODO
//const ArrayType *at = dyn_cast<ArrayType>(vd_->getType());
//if(at) {
@@ -1432,13 +1459,14 @@ int IR_chillArraySymbol::n_dim() const {
//fprintf(stderr, "variable %s %s %s\n", chillvd->vartype, chillvd->varname, chillvd->arraypart);
//fprintf(stderr, "IR_chillArraySymbol::n_dim() %d\n", chillvd->numdimensions);
//fprintf(stderr, "IR_chillArraySymbol::n_dim() TODO \n"); exit(-1);
- return chillvd->numdimensions;
+ return chillvd->numdimensions;
}
// TODO
omega::CG_outputRepr *IR_chillArraySymbol::size(int dim) const {
- fprintf(stderr, "IR_chillArraySymbol::n_size() TODO \n"); exit(-1);
+ fprintf(stderr, "IR_chillArraySymbol::n_size() TODO \n");
+ exit(-1);
return NULL;
}
@@ -1446,13 +1474,13 @@ omega::CG_outputRepr *IR_chillArraySymbol::size(int dim) const {
bool IR_chillArraySymbol::operator!=(const IR_Symbol &that) const {
//fprintf(stderr, "IR_xxxxArraySymbol::operator!= NOT EQUAL\n");
//chillAST_VarDecl *chillvd;
- return chillvd != ((IR_chillArraySymbol*)&that)->chillvd ;
+ return chillvd != ((IR_chillArraySymbol *) &that)->chillvd;
}
bool IR_chillArraySymbol::operator==(const IR_Symbol &that) const {
//fprintf(stderr, "IR_xxxxArraySymbol::operator== EQUAL\n");
//chillAST_VarDecl *chillvd;
- return chillvd == ((IR_chillArraySymbol*)&that)->chillvd ;
+ return chillvd == ((IR_chillArraySymbol *) &that)->chillvd;
/*
if (typeid(*this) != typeid(that))
return false;
@@ -1474,12 +1502,12 @@ IR_Symbol *IR_chillArraySymbol::clone() const {
bool IR_chillConstantRef::operator==(const IR_Ref &that) const {
if (typeid(*this) != typeid(that))
return false;
-
+
const IR_chillConstantRef *l_that = static_cast<const IR_chillConstantRef *>(&that);
-
+
if (this->type_ != l_that->type_)
return false;
-
+
if (this->type_ == IR_CONSTANT_INT)
return this->i_ == l_that->i_;
else
@@ -1491,8 +1519,9 @@ omega::CG_outputRepr *IR_chillConstantRef::convert() {
//assert(astContext_ != NULL);
if (type_ == IR_CONSTANT_INT) {
- fprintf(stderr, "IR_chillConstantRef::convert() unimplemented\n"); exit(-1);
-
+ fprintf(stderr, "IR_chillConstantRef::convert() unimplemented\n");
+ exit(-1);
+
// TODO
/*
BuiltinType *bint = new BuiltinType(BuiltinType::Int);
@@ -1501,8 +1530,7 @@ omega::CG_outputRepr *IR_chillConstantRef::convert() {
delete this;
return result;
*/
- }
- else
+ } else
throw ir_error("constant type not supported");
}
@@ -1521,7 +1549,7 @@ IR_Ref *IR_chillConstantRef::clone() const {
// ----------------------------------------------------------------------------
bool IR_chillScalarRef::is_write() const {
- return op_pos_ == OP_DEST; // 2 other alternatives: OP_UNKNOWN, OP_SRC
+ return op_pos_ == OP_DEST; // 2 other alternatives: OP_UNKNOWN, OP_SRC
}
@@ -1529,7 +1557,7 @@ IR_ScalarSymbol *IR_chillScalarRef::symbol() const {
//VarDecl *vd = static_cast<VarDecl *>(vs_->getDecl());
//fprintf(stderr, "ir_clang.cc IR_chillScalarRef::symbol()\n"); //exit(-1);
chillAST_VarDecl *vd = NULL;
- if (chillvd) vd = chillvd;
+ if (chillvd) vd = chillvd;
return new IR_chillScalarSymbol(ir_, vd); // IR_chillScalarRef::symbol()
}
@@ -1537,22 +1565,22 @@ IR_ScalarSymbol *IR_chillScalarRef::symbol() const {
bool IR_chillScalarRef::operator==(const IR_Ref &that) const {
if (typeid(*this) != typeid(that))
return false;
-
+
const IR_chillScalarRef *l_that = static_cast<const IR_chillScalarRef *>(&that);
-
+
return this->chillvd == l_that->chillvd;
}
omega::CG_outputRepr *IR_chillScalarRef::convert() {
//fprintf(stderr, "IR_chillScalarRef::convert() unimplemented\n"); exit(-1);
- if (!dre) fprintf(stderr, "IR_chillScalarRef::convert() CLANG SCALAR REF has no dre\n");
+ if (!dre) fprintf(stderr, "IR_chillScalarRef::convert() CLANG SCALAR REF has no dre\n");
omega::CG_chillRepr *result = new omega::CG_chillRepr(dre);
delete this;
return result;
}
-IR_Ref * IR_chillScalarRef::clone() const {
+IR_Ref *IR_chillScalarRef::clone() const {
if (dre) return new IR_chillScalarRef(ir_, dre); // use declrefexpr if it exists
return new IR_chillScalarRef(ir_, chillvd); // uses vardecl
}
@@ -1563,17 +1591,17 @@ IR_Ref * IR_chillScalarRef::clone() const {
// ----------------------------------------------------------------------------
bool IR_chillArrayRef::is_write() const {
-
+
return (iswrite); // TODO
}
// TODO
omega::CG_outputRepr *IR_chillArrayRef::index(int dim) const {
- fprintf(stderr, "IR_xxxxArrayRef::index( %d ) \n", dim);
+ fprintf(stderr, "IR_xxxxArrayRef::index( %d ) \n", dim);
//chillASE->print(); printf("\n"); fflush(stdout);
//chillASE->getIndex(dim)->print(); printf("\n"); fflush(stdout);
- return new omega::CG_chillRepr( chillASE->getIndex(dim) );
+ return new omega::CG_chillRepr(chillASE->getIndex(dim));
}
@@ -1582,16 +1610,16 @@ IR_ArraySymbol *IR_chillArrayRef::symbol() const {
//chillASE->print(); printf("\n"); fflush(stdout);
//fprintf(stderr, "base: "); chillASE->base->print(); printf("\n"); fflush(stdout);
-
- chillAST_node *mb = chillASE->multibase();
- chillAST_VarDecl *vd = (chillAST_VarDecl*)mb;
+
+ chillAST_node *mb = chillASE->multibase();
+ chillAST_VarDecl *vd = (chillAST_VarDecl *) mb;
//fprintf(stderr, "symbol: '%s'\n", vd->varname);
//fprintf(stderr, "IR_chillArrayRef symbol: '%s%s'\n", vd->varname, vd->arraypart);
//fprintf(stderr, "numdimensions %d\n", vd->numdimensions);
- IR_ArraySymbol *AS = new IR_chillArraySymbol(ir_, vd);
+ IR_ArraySymbol *AS = new IR_chillArraySymbol(ir_, vd);
//fprintf(stderr, "ir_clang.cc returning IR_chillArraySymbol 0x%x\n", AS);
- return AS;
+ return AS;
/*
chillAST_node *b = chillASE->base;
fprintf(stderr, "base of type %s\n", b->getTypeString());
@@ -1624,10 +1652,12 @@ bool IR_chillArrayRef::operator!=(const IR_Ref &that) const {
bool op = (*this) == that; // opposite
return !op;
}
-
-void IR_chillArrayRef::Dump() const {
+
+void IR_chillArrayRef::Dump() const {
//fprintf(stderr, "IR_chillArrayRef::Dump() this 0x%x chillASE 0x%x\n", this, chillASE);
- chillASE->print(); printf("\n");fflush(stdout);
+ chillASE->print();
+ printf("\n");
+ fflush(stdout);
}
@@ -1635,7 +1665,7 @@ bool IR_chillArrayRef::operator==(const IR_Ref &that) const {
//fprintf(stderr, "IR_xxxxArrayRef::operator==\n");
//printf("I am\n"); chillASE->print(); printf("\n");
const IR_chillArrayRef *l_that = static_cast<const IR_chillArrayRef *>(&that);
- const chillAST_ArraySubscriptExpr* thatASE = l_that->chillASE;
+ const chillAST_ArraySubscriptExpr *thatASE = l_that->chillASE;
//printf("other is:\n"); thatASE->print(); printf("\n"); fflush(stdout);
//fprintf(stderr, "addresses are 0x%x 0x%x\n", chillASE, thatASE );
return (*chillASE) == (*thatASE);
@@ -1653,7 +1683,7 @@ bool IR_chillArrayRef::operator==(const IR_Ref &that) const {
omega::CG_outputRepr *IR_chillArrayRef::convert() {
//fprintf(stderr, "IR_chillArrayRef::convert()\n");
- CG_chillRepr *result = new CG_chillRepr( chillASE->clone() );
+ CG_chillRepr *result = new CG_chillRepr(chillASE->clone());
// omega::CG_chillRepr *temp = new omega::CG_chillRepr(static_cast<Expr*>(this->as_));
// omega::CG_outputRepr *result = temp->clone();
delete this;
@@ -1669,74 +1699,70 @@ IR_Ref *IR_chillArrayRef::clone() const {
// ----------------------------------------------------------------------------
// Class: IR_chillLoop
// ----------------------------------------------------------------------------
-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, clang::ForStmt *tf) {
+ CHILL_ERROR("you lose\n");
+ exit(-1);
+};
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;
+ ir_ = ir;
chillforstmt = achillforstmt;
- chillAST_BinaryOperator *init = (chillAST_BinaryOperator *)chillforstmt->getInit();
- chillAST_BinaryOperator *cond = (chillAST_BinaryOperator *)chillforstmt->getCond();
+ chillAST_BinaryOperator *init = (chillAST_BinaryOperator *) chillforstmt->getInit();
+ chillAST_BinaryOperator *cond = (chillAST_BinaryOperator *) chillforstmt->getCond();
// check to be sure (assert)
- if (!init->isAssignmentOp() || !cond->isComparisonOp() ) {
+ if (!init->isAssignmentOp() || !cond->isComparisonOp()) {
CHILL_ERROR("malformed loop init or cond:\n");
- achillforstmt->print();
- exit(-1);
+ achillforstmt->print();
+ exit(-1);
}
chilllowerbound = init->getRHS();
chillupperbound = cond->getRHS();
- conditionoperator = achillforstmt->conditionoperator;
-
- chillAST_node *inc = chillforstmt->getInc();
+ conditionoperator = achillforstmt->conditionoperator;
+
+ chillAST_node *inc = chillforstmt->getInc();
// check the increment
//fprintf(stderr, "increment is of type %s\n", inc->getTypeString());
//inc->print(); printf("\n"); fflush(stdout);
- if (inc->asttype == CHILLAST_NODETYPE_UNARYOPERATOR) {
+ if (inc->asttype == CHILLAST_NODETYPE_UNARYOPERATOR) {
if (!strcmp(((chillAST_UnaryOperator *) inc)->op, "++")) step_size_ = 1;
- else step_size_ = -1;
- }
- else if (inc->asttype == CHILLAST_NODETYPE_BINARYOPERATOR) {
+ else step_size_ = -1;
+ } else if (inc->asttype == CHILLAST_NODETYPE_BINARYOPERATOR) {
int beets = false; // slang
chillAST_BinaryOperator *bop = (chillAST_BinaryOperator *) inc;
if (bop->isAssignmentOp()) { // I=I+1 or similar
chillAST_node *rhs = bop->getRHS(); // (I+1)
// TODO looks like this will fail for I=1+I or I=J+1 etc. do more checking
-
- char *assop = bop->getOp();
+
+ char *assop = bop->getOp();
//fprintf(stderr, "'%s' is an assignment op\n", bop->getOp());
if (streq(assop, "+=") || streq(assop, "-=")) {
chillAST_node *stride = rhs;
//fprintf(stderr, "stride is of type %s\n", stride->getTypeString());
- if (stride->isIntegerLiteral()) {
- int val = ((chillAST_IntegerLiteral *)stride)->value;
- if (streq( assop, "+=")) step_size_ = val;
- else if (streq( assop, "-=")) step_size_ = -val;
- else beets = true;
- }
- else beets = true; // += or -= but not constant stride
- }
- else if (rhs->isBinaryOperator()) {
- chillAST_BinaryOperator *binoprhs = (chillAST_BinaryOperator *)rhs;
- chillAST_node *intlit = binoprhs->getRHS();
+ if (stride->isIntegerLiteral()) {
+ int val = ((chillAST_IntegerLiteral *) stride)->value;
+ if (streq(assop, "+=")) step_size_ = val;
+ else if (streq(assop, "-=")) step_size_ = -val;
+ else beets = true;
+ } else beets = true; // += or -= but not constant stride
+ } else if (rhs->isBinaryOperator()) {
+ chillAST_BinaryOperator *binoprhs = (chillAST_BinaryOperator *) rhs;
+ chillAST_node *intlit = binoprhs->getRHS();
if (intlit->isIntegerLiteral()) {
- int val = ((chillAST_IntegerLiteral *)intlit)->value;
- if (!strcmp( binoprhs->getOp(), "+")) step_size_ = val;
- else if (!strcmp( binoprhs->getOp(), "-")) step_size_ = -val;
- else beets = true;
- }
- else beets = true;
- }
- else beets = true;
- }
- else beets = true;
+ int val = ((chillAST_IntegerLiteral *) intlit)->value;
+ if (!strcmp(binoprhs->getOp(), "+")) step_size_ = val;
+ else if (!strcmp(binoprhs->getOp(), "-")) step_size_ = -val;
+ else beets = true;
+ } else beets = true;
+ } else beets = true;
+ } else beets = true;
if (beets) {
CHILL_ERROR("malformed loop increment (or more likely unhandled case)\n");
@@ -1751,10 +1777,10 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) {
}
//inc->print(0, stderr);fprintf(stderr, "\n");
- chillAST_DeclRefExpr *dre = (chillAST_DeclRefExpr *)init->getLHS();
- if (!dre->isDeclRefExpr()) {
+ chillAST_DeclRefExpr *dre = (chillAST_DeclRefExpr *) init->getLHS();
+ if (!dre->isDeclRefExpr()) {
CHILL_DEBUG_PRINT("malformed loop init.\n");
- init->print();
+ init->print();
}
chillindex = dre; // the loop index variable
@@ -1766,7 +1792,7 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) {
//chillupperbound->print(0, stderr); fprintf(stderr, "\n");
//fprintf(stderr, "step size is %d\n\n", step_size_) ;
- chillbody = achillforstmt->getBody();
+ chillbody = achillforstmt->getBody();
CHILL_DEBUG_PRINT("IR_xxxxLoop::IR_xxxxLoop() DONE\n");
}
@@ -1787,7 +1813,7 @@ IR_Block *IR_chillLoop::body() const {
//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());
- return new IR_chillBlock(ir_, chillbody ) ; // static_cast<CompoundStmt *>(tf_->getBody()));
+ return new IR_chillBlock(ir_, chillbody); // static_cast<CompoundStmt *>(tf_->getBody()));
}
IR_Control *IR_chillLoop::clone() const {
@@ -1797,18 +1823,18 @@ IR_Control *IR_chillLoop::clone() const {
}
IR_CONDITION_TYPE IR_chillLoop::stop_cond() const {
- chillAST_BinaryOperator *loopcondition = (chillAST_BinaryOperator*) chillupperbound;
+ chillAST_BinaryOperator *loopcondition = (chillAST_BinaryOperator *) chillupperbound;
CHILL_DEBUG_PRINT("IR_xxxxLoop::stop_cond()\n");
- return conditionoperator;
+ return conditionoperator;
}
IR_Block *IR_chillLoop::convert() { // convert the loop to a block
CHILL_DEBUG_PRINT("IR_xxxxLoop::convert() maybe \n");
- return new IR_chillBlock( ir_, chillbody ); // ??
+ return new IR_chillBlock(ir_, chillbody); // ??
return NULL;
}
-void IR_chillLoop::dump() const {
+void IR_chillLoop::dump() const {
CHILL_ERROR("TODO: IR_chillLoop::dump()\n");
exit(-1);
}
@@ -1824,102 +1850,91 @@ omega::CG_outputRepr *IR_chillBlock::original() const {
}
-
omega::CG_outputRepr *IR_chillBlock::extract() const {
- fflush(stdout);
- fprintf(stderr, "IR_xxxxBlock::extract()\n");
+ fflush(stdout);
+ fprintf(stderr, "IR_xxxxBlock::extract()\n");
//omega::CG_chillRepr *tnl = new omega::CG_chillRepr(getStmtList());
// if the block refers to a compound statement, return the next level
// of statements ; otherwise just return a repr of the statements
- chillAST_node *code = chillAST;
- //if (chillAST != NULL) fprintf(stderr, "block has chillAST of type %s\n",code->getTypeString());
+ //if (chillAST != NULL) fprintf(stderr, "block has chillAST of type %s\n",code->getTypeString());
//fprintf(stderr, "block has %d exploded statements\n", statements.size());
- omega::CG_chillRepr *OR;
- if (0 == statements.size()) {
- OR = new omega::CG_chillRepr(code); // presumably a compound statement ??
- }
- else {
- fprintf(stderr, "adding a statement from IR_chillBlock::extract()\n");
- OR = new omega::CG_chillRepr(); // empty of statements
- for (int i=0; i<statements.size(); i++) OR->addStatement( statements[i] );
- }
-
- fflush(stdout);
- fprintf(stderr, "IR_xxxxBlock::extract() LEAVING\n");
+ omega::CG_chillRepr *OR;
+ CHILL_DEBUG_PRINT("adding a statement from IR_chillBlock::extract()\n");
+ OR = new omega::CG_chillRepr(); // empty of statements
+ for (int i = 0; i < statements.size(); i++) OR->addStatement(statements[i]);
+ CHILL_DEBUG_PRINT("IR_xxxxBlock::extract() LEAVING\n");
return OR;
}
IR_Control *IR_chillBlock::clone() const {
CHILL_DEBUG_PRINT("IR_xxxxBlock::clone()\n");
//fprintf(stderr, "IR_xxxxBlock::clone() %d statements\n", statements.size());
- return new IR_chillBlock( this ); // shallow copy ?
+ return new IR_chillBlock(this); // shallow copy ?
}
-void IR_chillBlock::dump() const {
- fprintf(stderr, "IR_chillBlock::dump() TODO\n"); return;
+void IR_chillBlock::dump() const {
+ fprintf(stderr, "IR_chillBlock::dump() TODO\n");
+ return;
}
//StmtList
-vector<chillAST_node*> IR_chillBlock::getStmtList() const {
+vector<chillAST_node *> IR_chillBlock::getStmtList() const {
fprintf(stderr, "IR_xxxxBlock::getStmtList()\n");
return statements; // ??
}
-void IR_chillBlock::addStatement( chillAST_node* s ) {
- statements.push_back( s );
+void IR_chillBlock::addStatement(chillAST_node *s) {
+ statements.push_back(s);
}
-
-void PrintTranslationUnit( TranslationUnitDecl *TUD) { // , ASTContext &CTX ) {
- fprintf(stderr, "MY PrintTranslationUnit()\n");
+void PrintTranslationUnit(TranslationUnitDecl *TUD) { // , ASTContext &CTX ) {
+ fprintf(stderr, "MY PrintTranslationUnit()\n");
// TUD derived from Decl and DeclContext
- static DeclContext *DC = TUD->castToDeclContext( TUD );
+ static DeclContext *DC = TUD->castToDeclContext(TUD);
//SourceManager SM = CTX.getSourceManager();
for (DeclContext::decl_iterator DI = DC->decls_begin(), DE = DC->decls_end(); DI != DE; ++DI) {
Decl *D = *DI;
- fprintf(stderr, "D\n");
- if (isa<FunctionDecl>(D)) { fprintf(stderr, "FunctionDecl\n");
+ fprintf(stderr, "D\n");
+ if (isa<FunctionDecl>(D)) {
+ fprintf(stderr, "FunctionDecl\n");
//PrintFunctionDecl( dyn_cast<FunctionDecl>(D), CTX.getSourceManager(), 0);
- }
- else if (isa<VarDecl>(D)) { fprintf(stderr, "VarDecl\n");
+ } else if (isa<VarDecl>(D)) {
+ fprintf(stderr, "VarDecl\n");
//PrintVarDecl( dyn_cast<VarDecl>(D), CTX.getSourceManager(), 0 );
- }
- else if (isa<TypedefDecl>(D)) { fprintf(stderr, "TypedefDecl\n");
+ } else if (isa<TypedefDecl>(D)) {
+ fprintf(stderr, "TypedefDecl\n");
//PrintTypeDefDecl( dyn_cast<TypedefDecl>(D), CTX.getSourceManager(), 0 );
- }
- else if (isa<TypeAliasDecl>(D)) { fprintf(stderr, "TypeAliasDecl\n");
- }
- else fprintf(stderr, "\na declaration of type %s (%d)\n", D->getDeclKindName(), D->getKind());
+ } else if (isa<TypeAliasDecl>(D)) {
+ fprintf(stderr, "TypeAliasDecl\n");
+ } else fprintf(stderr, "\na declaration of type %s (%d)\n", D->getDeclKindName(), D->getKind());
//else if (isa<TypedefNameDecl>(D)) { fprintf(stderr, "TypedefNameDecl\n");}
}
}
-class NULLASTConsumer : public ASTConsumer
-{
+class NULLASTConsumer : public ASTConsumer {
};
-
-void findmanually( chillAST_node *node, char *procname, std::vector<chillAST_node*>& procs ) {
+void findmanually(chillAST_node *node, char *procname, std::vector<chillAST_node *> &procs) {
//fprintf(stderr, "findmanually() CHILL AST node of type %s\n", node->getTypeString());
-
- if (node->asttype == CHILLAST_NODETYPE_FUNCTIONDECL ) {
+
+ if (node->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) {
char *name = ((chillAST_FunctionDecl *) node)->functionName;
//fprintf(stderr, "node name 0x%x ", name);
//fprintf(stderr, "%s procname ", name);
//fprintf(stderr, "0x%x ", procname);
//fprintf(stderr, "%s\n", procname);
- if (!strcmp( name, procname)) {
+ if (!strcmp(name, procname)) {
//fprintf(stderr, "found procedure %s\n", procname );
- procs.push_back( node );
+ procs.push_back(node);
// quit recursing. probably not correct in some horrible case
- return;
+ return;
}
//else fprintf(stderr, "this is not the function we're looking for\n");
}
@@ -1929,14 +1944,14 @@ void findmanually( chillAST_node *node, char *procname, std::vector<chillAST_nod
// we don't really care what kind of node we're at. We just check the node itself
// and then its children is needed.
- int numc = node->children.size();
+ int numc = node->children.size();
//fprintf(stderr, "%d children\n", numc);
- for (int i=0; i<numc; i++) {
+ for (int i = 0; i < numc; i++) {
//fprintf(stderr, "node of type %s is recursing to child %d\n", node->getTypeString(), i);
- findmanually( node->children[i], procname, procs );
+ findmanually(node->children[i], procname, procs);
}
- return;
+ return;
}
// ----------------------------------------------------------------------------
@@ -1949,34 +1964,35 @@ IR_clangCode_Global_Init *IR_clangCode_Global_Init::pinstance = 0;
IR_clangCode_Global_Init *IR_clangCode_Global_Init::Instance(char **argv) {
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] );
+ pinstance = new IR_clangCode_Global_Init;
+ pinstance->ClangCompiler = new aClangCompiler(argv[1]);
}
return pinstance;
}
-aClangCompiler::aClangCompiler( char *filename ) {
-
+aClangCompiler::aClangCompiler(char *filename) {
+
//fprintf(stderr, "making a clang compiler for file %s\n", filename);
- SourceFileName = strdup( filename );
+ SourceFileName = strdup(filename);
// Arguments to pass to the clang frontend
std::vector<const char *> args;
- args.push_back(strdup(filename));
-
+ args.push_back(strdup(filename));
+
// The compiler invocation needs a DiagnosticsEngine so it can report problems
//IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); // temp
- diagnosticOptions = new DiagnosticOptions(); // private member of aClangCompiler
-
- pTextDiagnosticPrinter = new clang::TextDiagnosticPrinter(llvm::errs(), diagnosticOptions); // private member of aClangCompiler
-
+ diagnosticOptions = new DiagnosticOptions(); // private member of aClangCompiler
+
+ pTextDiagnosticPrinter = new clang::TextDiagnosticPrinter(llvm::errs(),
+ diagnosticOptions); // private member of aClangCompiler
+
//llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID(new clang::DiagnosticIDs());
//clang::DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
diagnosticsEngine = new clang::DiagnosticsEngine(diagID, diagnosticOptions, pTextDiagnosticPrinter);
-
+
// Create the compiler invocation
// This class is designed to represent an abstract "invocation" of the compiler,
// including data such as the include paths, the code generation options,
@@ -1985,7 +2001,7 @@ aClangCompiler::aClangCompiler( char *filename ) {
//CI = new clang::CompilerInvocation;
clang::CompilerInvocation::CreateFromArgs(*CI, &args[0], &args[0] + args.size(), *diagnosticsEngine);
-
+
// Create the compiler instance
Clang = new clang::CompilerInstance(); // TODO should have a better name ClangCompilerInstance
@@ -1993,10 +2009,10 @@ aClangCompiler::aClangCompiler( char *filename ) {
// Get ready to report problems
Clang->createDiagnostics(nullptr, true);
//Clang.createDiagnostics(0, 0);
-
-
+
+
//#ifdef KIDDINGME
- //fprintf(stderr, "target\n");
+ //fprintf(stderr, "target\n");
// Initialize target info with the default triple for our platform.
//TargetOptions TO;
//TO.Triple = llvm::sys::getDefaultTargetTriple();
@@ -2006,24 +2022,24 @@ aClangCompiler::aClangCompiler( char *filename ) {
targetOptions = std::make_shared<clang::TargetOptions>();
targetOptions->Triple = llvm::sys::getDefaultTargetTriple();
- TargetInfo *pti = TargetInfo::CreateTargetInfo(Clang->getDiagnostics(),targetOptions);
+ TargetInfo *pti = TargetInfo::CreateTargetInfo(Clang->getDiagnostics(), targetOptions);
Clang->setTarget(pti);
-
+
//#endif
-
+
// ??
//fprintf(stderr, "filemgr\n");
Clang->createFileManager();
FileManager &FileMgr = Clang->getFileManager();
fileManager = &FileMgr;
-
+
//fprintf(stderr, "sourcemgr\n");
Clang->createSourceManager(FileMgr);
SourceManager &SourceMgr = Clang->getSourceManager();
sourceManager = &SourceMgr; // ?? aclangcompiler copy
- globalSRCMAN = &SourceMgr; // TODO global bad
+ globalSRCMAN = &SourceMgr; // TODO global bad
Clang->setInvocation(CI.get()); // Replace the current invocation
@@ -2039,14 +2055,14 @@ aClangCompiler::aClangCompiler( char *filename ) {
//fprintf(stderr, "CONTEXT\n");
Clang->createASTContext(); // needs preprocessor
- astContext_ = &Clang->getASTContext();
-
+ astContext_ = &Clang->getASTContext();
+
//fprintf(stderr, "filein\n");
const FileEntry *FileIn = FileMgr.getFile(filename); // needs preprocessor
- SourceMgr.setMainFileID(SourceMgr.createFileID(FileIn,clang::SourceLocation(),clang::SrcMgr::C_User));
+ SourceMgr.setMainFileID(SourceMgr.createFileID(FileIn, clang::SourceLocation(), clang::SrcMgr::C_User));
//DiagnosticConsumer DiagConsumer = Clang->getDiagnosticClient();
- Clang->getDiagnosticClient().BeginSourceFile( Clang->getLangOpts(), &Clang->getPreprocessor());
+ Clang->getDiagnosticClient().BeginSourceFile(Clang->getLangOpts(), &Clang->getPreprocessor());
NULLASTConsumer TheConsumer; // must pass a consumer in to ParseAST(). This one does nothing
@@ -2054,15 +2070,15 @@ aClangCompiler::aClangCompiler( char *filename ) {
//fprintf(stderr, "ready? Parse.\n");
CHILL_DEBUG_PRINT("actually parsing file %s using clang\n", filename);
- ParseAST( Clang->getPreprocessor(), &TheConsumer, Clang->getASTContext());
+ ParseAST(Clang->getPreprocessor(), &TheConsumer, Clang->getASTContext());
// Translation Unit is contents of a file
- TranslationUnitDecl* TUD = astContext_->getTranslationUnitDecl();
+ TranslationUnitDecl *TUD = astContext_->getTranslationUnitDecl();
// TUD->dump(); // print it out
// create another AST, very similar to the clang AST but not written by idiots
CHILL_DEBUG_PRINT("converting entire clang AST into chill AST (ir_clang.cc)\n");
- chillAST_node * wholefile = ConvertTranslationUnit( TUD, filename);
+ chillAST_node *wholefile = ConvertTranslationUnit(TUD, filename);
fflush(stdout);
//fprintf(stderr, "printing whole file\n");
@@ -2071,14 +2087,14 @@ aClangCompiler::aClangCompiler( char *filename ) {
//wholefile->dump();
//fflush(stdout);
- entire_file_AST = (chillAST_SourceFile *)wholefile;
+ entire_file_AST = (chillAST_SourceFile *) wholefile;
- astContext_ = &Clang->getASTContext();
+ astContext_ = &Clang->getASTContext();
//#define DOUBLE
#ifdef DOUBLE
- fprintf(stderr, "DOUBLE\n");
+ fprintf(stderr, "DOUBLE\n");
fprintf(stderr, "\n\nCLANG dump of the file I parsed:\n");
llvm::OwningPtr<clang::FrontendAction> Act2(new clang::ASTDumpAction());
@@ -2087,21 +2103,18 @@ aClangCompiler::aClangCompiler( char *filename ) {
exit(3);
}
#endif
- fflush(stdout); fflush(stderr);
- fflush(stdout); fflush(stderr);
- fflush(stdout); fflush(stderr);
- fflush(stdout); fflush(stderr);
-
-
-
-
-
-
+ fflush(stdout);
+ fflush(stderr);
+ fflush(stdout);
+ fflush(stderr);
+ fflush(stdout);
+ fflush(stderr);
+ fflush(stdout);
+ fflush(stderr);
+#ifdef DONTDOTHIS
-#ifdef DONTDOTHIS
-
// calling this Action seems to overwrite the astcontext and the AST. (!)
// don't ever do this, or you lose contact with the original AST (?)
@@ -2117,43 +2130,40 @@ aClangCompiler::aClangCompiler( char *filename ) {
fflush(stdout);
#endif
-
+
//fprintf(stderr, "leaving aClangCompiler::aClangCompiler( filename )\n");
}
-
-
-chillAST_FunctionDecl* aClangCompiler::findprocedurebyname( char *procname ) {
+chillAST_FunctionDecl *aClangCompiler::findprocedurebyname(char *procname) {
//fprintf(stderr, "searching through files in the clang AST\n\n");
//fprintf(stderr, "astContext_ 0x%x\n", astContext_);
- std::vector<chillAST_node*> procs;
- findmanually( entire_file_AST, procname, procs );
+ std::vector<chillAST_node *> procs;
+ findmanually(entire_file_AST, procname, procs);
//fprintf(stderr, "procs has %d members\n", procs.size());
- if ( procs.size() == 0 ) {
+ if (procs.size() == 0) {
CHILL_ERROR("could not find function named '%s' in AST from file %s\n", procname, SourceFileName);
exit(-1);
}
-
- if ( procs.size() > 1 ) {
+
+ if (procs.size() > 1) {
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);
}
CHILL_DEBUG_PRINT("found the procedure named %s\n", procname);
- return (chillAST_FunctionDecl *)procs[0];
+ return (chillAST_FunctionDecl *) procs[0];
}
-
-#ifdef NOPE
-IR_clangCode_Global_Init::IR_clangCode_Global_Init(char *filename , clang::FileSystemOptions fso ) :
+#ifdef NOPE
+IR_clangCode_Global_Init::IR_clangCode_Global_Init(char *filename , clang::FileSystemOptions fso ) :
fileManager(fso) // , headerSearch( headerSearchOptions, fileManager, diagengine, languageOptions, pTargetInfo )
{
/* CLANG Initialization */
@@ -2201,11 +2211,10 @@ IR_clangCode_Global_Init::IR_clangCode_Global_Init(char *filename , clang::File
sema.Initialize();
clang::ParseAST(*preprocessor, astConsumer_, *astContext_);
}
-#endif
+#endif
-IR_clangCode_Global_Init::~IR_clangCode_Global_Init()
-{
+IR_clangCode_Global_Init::~IR_clangCode_Global_Init() {
/*
delete pTextDiagnosticPrinter;
delete diagnostic;
@@ -2224,10 +2233,10 @@ IR_clangCode_Global_Init::~IR_clangCode_Global_Init()
// Class: IR_clangCode
// ----------------------------------------------------------------------------
-IR_clangCode::IR_clangCode(const char *fname, const char *proc_name): IR_Code() {
+IR_clangCode::IR_clangCode(const char *fname, const char *proc_name) : IR_Code() {
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
procedurename = strdup(proc_name);
@@ -2235,34 +2244,34 @@ IR_clangCode::IR_clangCode(const char *fname, const char *proc_name): IR_Code()
char *argv[2];
argv[0] = strdup("chill");
argv[1] = strdup(filename);
-
+
// use clang to parse the input file ? (or is that already done?)
//fprintf(stderr, "IR_clangCode::IR_clangCode(), parsing input file %s\n", argv[1]);
-
+
// this causes opening and parsing of the file.
// this is the only call to Instance that has an argument list or file name
IR_clangCode_Global_Init *pInstance = IR_clangCode_Global_Init::Instance(argv);
-
- if(pInstance) {
-
+
+ if (pInstance) {
+
aClangCompiler *Clang = pInstance->ClangCompiler;
//fprintf(stderr, "Clang is 0x%x\n", Clang);
//fprintf(stderr, "want to get pointer to clang ast for procedure %s\n", proc_name);
- pInstance->setCurrentFunction( NULL ); // we have no function AST yet
+ pInstance->setCurrentFunction(NULL); // we have no function AST yet
entire_file_AST = Clang->entire_file_AST; // ugly that same name, different classes
- chillAST_FunctionDecl *localFD = Clang->findprocedurebyname( strdup(proc_name) ); // stored locally
+ chillAST_FunctionDecl *localFD = Clang->findprocedurebyname(strdup(proc_name)); // stored locally
//fprintf(stderr, "back from findprocedurebyname( %s )\n", proc_name );
//localFD->print();
- pInstance->setCurrentFunction( localFD );
+ pInstance->setCurrentFunction(localFD);
- chillAST_node *b = localFD->getBody(); // we do this just because it will get done next
+ chillAST_node *b = localFD->getBody(); // we do this just because it will get done next
CHILL_DEBUG_PRINT("calling new CG_chillBuilder() umwut?\n");
ocg_ = new omega::CG_chillBuilder(); // ocg == omega code gen
- chillfunc = localFD;
+ chillfunc = localFD;
}
@@ -2281,121 +2290,122 @@ IR_clangCode::~IR_clangCode() {
//fprintf(stderr, "Constant Folding before\n");
//chillfunc->print();
- chillfunc->constantFold();
+ chillfunc->constantFold();
//fprintf(stderr, "\nConstant Folding after\n");
//chillfunc->print();
- chillfunc->cleanUpVarDecls();
+ chillfunc->cleanUpVarDecls();
//chillfunc->dump();
// TODO should output the entire file, not just the function we're working on
- chillAST_SourceFile *src = chillfunc->getSourceFile();
+ chillAST_SourceFile *src = chillfunc->getSourceFile();
//chillAST_node *p = chillfunc->parent; // should be translationDeclUnit
- if (src) {
+ if (src) {
//src->print(); // tmp
- if (src->isSourceFile()) src->printToFile( );
+ if (src->isSourceFile()) src->printToFile();
}
}
-
-
-
//TODO
IR_ScalarSymbol *IR_clangCode::CreateScalarSymbol(const IR_Symbol *sym, int i) {
//fprintf(stderr, "IR_clangCode::CreateScalarSymbol()\n");
- if (typeid(*sym) == typeid( IR_chillScalarSymbol ) ) { // should be the case ???
- fprintf(stderr, "IR_xxxxCode::CreateScalarSymbol() from a scalar symbol\n");
+ if (typeid(*sym) == typeid(IR_chillScalarSymbol)) { // should be the case ???
+ fprintf(stderr, "IR_xxxxCode::CreateScalarSymbol() from a scalar symbol\n");
//fprintf(stderr, "(typeid(*sym) == typeid( IR_chillScalarSymbol )\n");
- const IR_chillScalarSymbol *CSS = (IR_chillScalarSymbol*) sym;
+ const IR_chillScalarSymbol *CSS = (IR_chillScalarSymbol *) sym;
chillAST_VarDecl *vd = CSS->chillvd;
-
+
// do we have to check to see if it's already there?
- VariableDeclarations.push_back(vd);
- chillAST_node *bod = chillfunc->getBody(); // always a compoundStmt ??
- bod->insertChild(0, vd);
- fprintf(stderr, "returning ... really\n");
- return new IR_chillScalarSymbol( this, CSS->chillvd); // CSS->clone();
+ VariableDeclarations.push_back(vd);
+ chillAST_node *bod = chillfunc->getBody(); // always a compoundStmt ??
+ bod->insertChild(0, vd);
+ fprintf(stderr, "returning ... really\n");
+ return new IR_chillScalarSymbol(this, CSS->chillvd); // CSS->clone();
}
// ??
- if (typeid(*sym) == typeid( IR_chillArraySymbol ) ) {
- fprintf(stderr, "IR_xxxxCode::CreateScalarSymbol() from an array symbol?\n");
- const IR_chillArraySymbol *CAS = (IR_chillArraySymbol*) sym;
+ if (typeid(*sym) == typeid(IR_chillArraySymbol)) {
+ fprintf(stderr, "IR_xxxxCode::CreateScalarSymbol() from an array symbol?\n");
+ const IR_chillArraySymbol *CAS = (IR_chillArraySymbol *) sym;
//fprintf(stderr, "CAS 0x%x chillvd = 0x%x\n", CAS, CAS->chillvd);
//fprintf(stderr, "\nthis is the SYMBOL?: \n");
//CAS->print();
//CAS->dump();
- chillAST_VarDecl *vd = CAS->chillvd;
+ chillAST_VarDecl *vd = CAS->chillvd;
//fprintf(stderr, "\nthis is the var decl?: ");
//vd->print(); printf("\n");
//vd->dump(); printf("\n\n");
- fflush(stdout);
-
+ fflush(stdout);
+
// figure out the base type (probably float) of the array
char *basetype = vd->underlyingtype;
- fprintf(stderr, "scalar will be of type SgType%s\n", basetype);
+ fprintf(stderr, "scalar will be of type SgType%s\n", basetype);
char tmpname[128];
- sprintf(tmpname, "newVariable%i\0", vd->chill_scalar_counter++);
- chillAST_VarDecl * scalarvd = new chillAST_VarDecl( basetype, tmpname, "", NULL); // TODO parent
- scalarvd->print(); printf("\n"); fflush(stdout);
+ sprintf(tmpname, "newVariable%i\0", vd->chill_scalar_counter++);
+ chillAST_VarDecl *scalarvd = new chillAST_VarDecl(basetype, tmpname, "", NULL); // TODO parent
+ scalarvd->print();
+ printf("\n");
+ fflush(stdout);
- fprintf(stderr, "VarDecl has parent that is a NULL\n");
+ fprintf(stderr, "VarDecl has parent that is a NULL\n");
- return (IR_ScalarSymbol *) (new IR_chillScalarSymbol( this, scalarvd)); // CSS->clone();
+ return (IR_ScalarSymbol *) (new IR_chillScalarSymbol(this, scalarvd)); // CSS->clone();
}
-
- fprintf(stderr, "IR_clangCode::CreateScalarSymbol(), passed a sym that is not a clang scalar symbol OR an array symbol???\n");
+
+ fprintf(stderr,
+ "IR_clangCode::CreateScalarSymbol(), passed a sym that is not a clang scalar symbol OR an array symbol???\n");
int *n = NULL;
n[0] = 1;
- exit(-1);
+ exit(-1);
return NULL;
}
-IR_ArraySymbol *IR_clangCode::CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outputRepr *> &size, int i) {
- fprintf(stderr, "IR_xxxxCode::CreateArraySymbol()\n");
+IR_ArraySymbol *
+IR_clangCode::CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outputRepr *> &size, int i) {
+ fprintf(stderr, "IR_xxxxCode::CreateArraySymbol()\n");
// build a new array name
char namestring[128];
sprintf(namestring, "_P%d\0", entire_file_AST->chill_array_counter++);
- fprintf(stderr, "creating Array %s\n", namestring);
-
+ fprintf(stderr, "creating Array %s\n", namestring);
+
char arraypart[100];
char *s = &arraypart[0];
- for (int i=0; i<size.size(); i++) {
+ for (int i = 0; i < size.size(); i++) {
omega::CG_outputRepr *OR = size[i];
- CG_chillRepr * CR = (CG_chillRepr * ) OR;
+ CG_chillRepr *CR = (CG_chillRepr *) OR;
//fprintf(stderr, "%d chillnodes\n", CR->chillnodes.size());
-
+
// this SHOULD be 1 chillnode of type IntegerLiteral (per dimension)
int numnodes = CR->chillnodes.size();
- if (1 != numnodes) {
- fprintf(stderr,
- "IR_clangCode::CreateArraySymbol() array dimension %d has %d chillnodes\n",
- i, numnodes );
+ if (1 != numnodes) {
+ fprintf(stderr,
+ "IR_clangCode::CreateArraySymbol() array dimension %d has %d chillnodes\n",
+ i, numnodes);
exit(-1);
}
chillAST_node *nodezero = CR->chillnodes[0];
- if (!nodezero->isIntegerLiteral()) {
+ if (!nodezero->isIntegerLiteral()) {
fprintf(stderr, "IR_clangCode::CreateArraySymbol() array dimension %d not an IntegerLiteral\n", i);
exit(-1);
}
- chillAST_IntegerLiteral *IL = (chillAST_IntegerLiteral *)nodezero;
+ chillAST_IntegerLiteral *IL = (chillAST_IntegerLiteral *) nodezero;
int val = IL->value;
- sprintf(s, "[%d]\0", val);
- s = &arraypart[ strlen(arraypart) ];
+ sprintf(s, "[%d]\0", val);
+ s = &arraypart[strlen(arraypart)];
}
//fprintf(stderr, "arraypart '%s'\n", arraypart);
- chillAST_VarDecl *vd = new chillAST_VarDecl( "float", namestring, arraypart, NULL); // todo type from sym
+ chillAST_VarDecl *vd = new chillAST_VarDecl("float", namestring, arraypart, NULL); // todo type from sym
// put decl in some symbol table
VariableDeclarations.push_back(vd);
@@ -2403,37 +2413,37 @@ IR_ArraySymbol *IR_clangCode::CreateArraySymbol(const IR_Symbol *sym, std::vecto
chillAST_node *bod = chillfunc->getBody(); // always a compoundStmt ??
bod->insertChild(0, vd);
- return new IR_chillArraySymbol( this, vd);
+ return new IR_chillArraySymbol(this, vd);
}
// TODO
std::vector<IR_ScalarRef *> IR_clangCode::FindScalarRef(const omega::CG_outputRepr *repr) const {
std::vector<IR_ScalarRef *> scalars;
- fprintf(stderr, "IR_clangCode::FindScalarRef() DIE\n"); exit(-1);
+ fprintf(stderr, "IR_clangCode::FindScalarRef() DIE\n");
+ exit(-1);
return scalars;
}
-
IR_ScalarRef *IR_clangCode::CreateScalarRef(const IR_ScalarSymbol *sym) {
//fprintf(stderr, "\n***** ir_clang.cc IR_clangCode::CreateScalarRef( sym %s )\n", sym->name().c_str());
//DeclRefExpr *de = new (vd->getASTContext())DeclRefExpr(static_cast<ValueDecl*>(vd), vd->getType(), SourceLocation());
//fprintf(stderr, "sym 0x%x\n", sym);
- IR_chillScalarRef *sr = new IR_chillScalarRef(this, buildDeclRefExpr(((IR_chillScalarSymbol*)sym)->chillvd)); // uses VarDecl to mak a declrefexpr
+ IR_chillScalarRef *sr = new IR_chillScalarRef(this, buildDeclRefExpr(
+ ((IR_chillScalarSymbol *) sym)->chillvd)); // uses VarDecl to mak a declrefexpr
//fprintf(stderr, "returning ScalarRef with dre 0x%x\n", sr->dre);
- return sr;
+ return sr;
//return (IR_ScalarRef *)NULL;
}
-
IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector<omega::CG_outputRepr *> &index) {
- fprintf(stderr, "IR_clangCode::CreateArrayRef() ir_clang.cc\n");
- fprintf(stderr, "sym->n_dim() %d index.size() %d\n", sym->n_dim(), index.size());
+ fprintf(stderr, "IR_clangCode::CreateArrayRef() ir_clang.cc\n");
+ fprintf(stderr, "sym->n_dim() %d index.size() %d\n", sym->n_dim(), index.size());
int t;
- if(sym->n_dim() != index.size()) {
+ if (sym->n_dim() != index.size()) {
throw std::invalid_argument("incorrect array symbol dimensionality dim != size ir_clang.cc L2359");
}
@@ -2442,18 +2452,18 @@ IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector
std::vector<chillAST_node *> inds;
//fprintf(stderr, "%d array indeces\n", sym->n_dim());
- for (int i=0; i< index.size(); i++) {
- CG_chillRepr *CR = (CG_chillRepr *)index[i];
-
+ for (int i = 0; i < index.size(); i++) {
+ CG_chillRepr *CR = (CG_chillRepr *) index[i];
+
int numnodes = CR->chillnodes.size();
- if (1 != numnodes) {
- fprintf(stderr,
- "IR_clangCode::CreateArrayRef() array dimension %d has %d chillnodes\n",
- i, numnodes );
+ if (1 != numnodes) {
+ fprintf(stderr,
+ "IR_clangCode::CreateArrayRef() array dimension %d has %d chillnodes\n",
+ i, numnodes);
exit(-1);
}
- inds.push_back( CR->chillnodes[0] );
+ inds.push_back(CR->chillnodes[0]);
/*
chillAST_node *nodezero = CR->chillnodes[0];
@@ -2473,9 +2483,9 @@ IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector
// now we've got the vardecl AND the indeces to make a chillAST that represents the array reference
// TODO Passing NULL for chillAST node?
CHILL_DEBUG_PRINT("Passed NULL as chillAST node");
- chillAST_ArraySubscriptExpr *ASE = new chillAST_ArraySubscriptExpr( vd, inds, NULL);
+ chillAST_ArraySubscriptExpr *ASE = new chillAST_ArraySubscriptExpr(vd, inds, NULL);
- auto ref = new IR_chillArrayRef( this, ASE, 0 );
+ auto ref = new IR_chillArrayRef(this, ASE, 0);
return ref;
}
@@ -2484,23 +2494,23 @@ IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector
std::vector<IR_ArrayRef *> IR_clangCode::FindArrayRef(const omega::CG_outputRepr *repr) const {
//fprintf(stderr, "FindArrayRef()\n");
std::vector<IR_ArrayRef *> arrays;
- const omega::CG_chillRepr *crepr = static_cast<const omega::CG_chillRepr *>(repr);
- std::vector<chillAST_node*> chillstmts = crepr->getChillCode();
+ const omega::CG_chillRepr *crepr = static_cast<const omega::CG_chillRepr *>(repr);
+ std::vector<chillAST_node *> chillstmts = crepr->getChillCode();
//fprintf(stderr, "there are %d chill statements in this repr\n", chillstmts.size());
- std::vector<chillAST_ArraySubscriptExpr*> refs;
- for (int i=0; i<chillstmts.size(); i++) {
+ std::vector<chillAST_ArraySubscriptExpr *> refs;
+ for (int i = 0; i < chillstmts.size(); i++) {
//fprintf(stderr, "\nchillstatement %d = ", i); chillstmts[i]->print(0, stderr); fprintf(stderr, "\n");
- chillstmts[i]->gatherArrayRefs( refs, false );
+ chillstmts[i]->gatherArrayRefs(refs, false);
}
//fprintf(stderr, "%d total refs\n", refs.size());
- for (int i=0; i<refs.size(); i++) {
- if (refs[i]->imreadfrom) {
+ for (int i = 0; i < refs.size(); i++) {
+ if (refs[i]->imreadfrom) {
//fprintf(stderr, "ref[%d] going to be put in TWICE, as both read and write\n", i);
- arrays.push_back( new IR_chillArrayRef( this, refs[i], 0 ) ); // UGLY TODO dual usage of a ref in "+="
+ arrays.push_back(new IR_chillArrayRef(this, refs[i], 0)); // UGLY TODO dual usage of a ref in "+="
}
- arrays.push_back( new IR_chillArrayRef( this, refs[i], refs[i]->imwrittento ) ); // this is wrong
+ arrays.push_back(new IR_chillArrayRef(this, refs[i], refs[i]->imwrittento)); // this is wrong
// we need to know whether this reference will be written, etc.
}
@@ -2576,32 +2586,29 @@ std::vector<IR_ArrayRef *> IR_clangCode::FindArrayRef(const omega::CG_outputRepr
std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Block *block) const {
- CHILL_DEBUG_PRINT("IR_xxxxCode::FindOneLevelControlStructure()\n");
- const IR_chillBlock *CB = (const IR_chillBlock *) block;
+ const IR_chillBlock *CB = (const IR_chillBlock *) block;
//fprintf(stderr, "block 0x%x\n", block);
std::vector<IR_Control *> controls;
- chillAST_node *blockast = CB->chillAST;
- //fprintf(stderr, "blockast 0x%x\n", blockast);
- if (blockast == NULL) {
- int numstmts = CB->statements.size();
- CHILL_DEBUG_PRINT("%d statements\n", numstmts);
+ chillAST_node *blockast = NULL;
+ int numstmts = CB->statements.size();
+ CHILL_DEBUG_PRINT("%d statements\n", numstmts);
- if (numstmts == 0) return controls;
+ if (numstmts == 0) return controls;
- else if (numstmts == 1) blockast = CB->statements[0]; // a single statement
+ else if (numstmts == 1) blockast = CB->statements[0]; // a single statement
- else {
- CHILL_ERROR( "IR_xxxBlock is dumb, with multiple ways to hold statements\n");
- exit(-1); // TODO FIX
+ CHILL_DEBUG_BEGIN
+ for (int i = 0; i < CB->statements.size(); ++i) {
+ fprintf(stderr, "block's AST is of type %s\n", CB->statements[i]->getTypeString());
+ CB->statements[i]->print();
+ printf("\n");
+ fflush(stdout);
}
- }
+ CHILL_DEBUG_END
- //fprintf(stderr, "block's AST is of type %s\n", blockast->getTypeString());
- //blockast->print(); printf("\n\n"); fflush(stdout);
-
//vector<chillAST_node *> funcchildren = chillfunc->getChildren();
//fprintf(stderr, "%d children of clangcode\n", funcchildren.size()); // includes parameters
@@ -2612,7 +2619,7 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
std::vector<chillAST_node *> children;
-
+
if (blockast->asttype == CHILLAST_NODETYPE_FORSTMT) {
CHILL_DEBUG_BEGIN
fflush(stdout);
@@ -2622,154 +2629,147 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
fprintf(stderr, "pushing the loop at TOP\n");
CHILL_DEBUG_END
- controls.push_back( new IR_chillLoop( this, (chillAST_ForStmt *)blockast));
+ controls.push_back(new IR_chillLoop(this, (chillAST_ForStmt *) blockast));
}
- //else if (blockast->asttype == CHILLAST_NODETYPE_IFSTMT) {
- // controls.push_back( new IR_clangIf( this, (chillAST_IfStmt *)blockast));
- //}
- else if (blockast->asttype == CHILLAST_NODETYPE_COMPOUNDSTMT ||
- blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) {
+ //else if (blockast->asttype == CHILLAST_NODETYPE_IFSTMT) {
+ // controls.push_back( new IR_clangIf( this, (chillAST_IfStmt *)blockast));
+ //}
+ else if (blockast->asttype == CHILLAST_NODETYPE_COMPOUNDSTMT ||
+ blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) {
- if (blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) {
+ if (blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) {
//fprintf(stderr, "ir_clanc.cc blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL\n");
- chillAST_FunctionDecl *FD = (chillAST_FunctionDecl *)blockast;
- chillAST_node *bod = FD->getBody();
+ chillAST_FunctionDecl *FD = (chillAST_FunctionDecl *) blockast;
+ chillAST_node *bod = FD->getBody();
//fprintf(stderr, "bod 0x%x\n", bod);
- children = bod->getChildren();
+ children = bod->getChildren();
//fprintf(stderr, "FunctionDecl body is of type %s\n", bod->getTypeString());
//fprintf(stderr, "found a top level FunctionDecl (Basic Block)\n");
//fprintf(stderr, "basic block has %d statements\n", children.size() );
//fprintf(stderr, "basic block is:\n");
//bod->print();
- }
- else /* CompoundStmt */ {
+ } else /* CompoundStmt */ {
//fprintf(stderr, "found a top level Basic Block\n");
children = blockast->getChildren();
}
-
- int numchildren = children.size();
+
+ int numchildren = children.size();
//fprintf(stderr, "basic block has %d statements\n", numchildren);
//fprintf(stderr, "basic block is:\n");
//fprintf(stderr, "{\n");
//blockast->print();
//fprintf(stderr, "}\n");
-
- int ns;
+
+ int ns;
IR_chillBlock *basicblock = new IR_chillBlock(this); // no statements
- for (int i=0; i<numchildren; i++) {
+ for (int i = 0; i < numchildren; i++) {
//fprintf(stderr, "child %d is of type %s\n", i, children[i]->getTypeString());
CHILL_ASTNODE_TYPE typ = children[i]->asttype;
if (typ == CHILLAST_NODETYPE_LOOP) {
- if (numchildren == 1) {
+ if (numchildren == 1) {
CHILL_DEBUG_PRINT("found a For statement (Loop)\n");
- }
- else {
+ } else {
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) {
- CHILL_DEBUG_PRINT("pushing a run of statements %d to %d as a block\n", i-ns, i-1);
- controls.push_back( basicblock );
+ CHILL_DEBUG_PRINT("pushing a run of statements as a block\n");
+ controls.push_back(basicblock);
basicblock = new IR_chillBlock(this); // start a new one
}
-
- //fprintf(stderr, "pushing the loop at %d\n", i);
- controls.push_back( new IR_chillLoop(this, (chillAST_ForStmt *)children[i] ));
-
+
+ CHILL_DEBUG_PRINT("pushing the loop at %d\n", i);
+ controls.push_back(new IR_chillLoop(this, (chillAST_ForStmt *) children[i]));
+
}
- //else if (typ == CHILLAST_NODETYPE_IFSTMT ) // TODO
+ //else if (typ == CHILLAST_NODETYPE_IFSTMT ) // TODO
else { // straight line code
- //fprintf(stderr, "straight line code\n");
- basicblock->addStatement( children[i] );
- //fprintf(stderr, "child %d = \n", i); children[i]->print(); printf("\n"); fflush(stdout);
- //fprintf(stderr, "child %d is part of a basic block\n", i);
+ basicblock->addStatement(children[i]);
+ CHILL_DEBUG_BEGIN
+ fprintf(stderr, "straight line code\n");
+ fprintf(stderr, "child %d = \n", i);
+ children[i]->print();
+ printf("\n");
+ fflush(stdout);
+ fprintf(stderr, "child %d is part of a basic block\n", i);
+ CHILL_DEBUG_END
}
} // for each child
ns = basicblock->numstatements();
//fprintf(stderr, "ns %d\n", ns);
- if (ns != 0 ) {
+ if (ns != 0) {
if (ns != numchildren) {
//fprintf(stderr, "end of body ends the run of %d statements in the Basic Block\n", ns);
- controls.push_back( basicblock );
- }
- else {
+ controls.push_back(basicblock);
+ } else {
//fprintf(stderr, "NOT sending straightline run of statements, because it would be the entire block. There are no control statements in the block\n");
}
}
//else fprintf(stderr, "NOT sending the last run of %d statements\n", ns);
-
- }
- else {
- CHILL_ERROR("IR_clangCode::FindOneLevelControlStructure(), block is a %s???\n", blockast->getTypeString());
+
+ } else {
+ CHILL_ERROR("block is a %s???\n", blockast->getTypeString());
exit(-1);
}
-
- CHILL_DEBUG_PRINT("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 {
- CHILL_DEBUG_PRINT("IR_xxxxCode::MergeNeighboringControlStructures %d controls\n", controls.size());
+ CHILL_DEBUG_PRINT("%d controls\n", controls.size());
if (controls.size() == 0)
return NULL;
-
- IR_chillBlock *CBlock = new IR_chillBlock(controls[0]->ir_); // the thing we're building
- std::vector<chillAST_node*> statements;
- chillAST_node *parent = NULL;
- for (int i = 0; i < controls.size(); i++) {
+ IR_chillBlock *CBlock = new IR_chillBlock(controls[0]->ir_); // the thing we're building
+
+ std::vector<chillAST_node *> statements;
+ chillAST_node *parent = NULL;
+ for (int i = 0; i < controls.size(); i++) {
switch (controls[i]->type()) {
- case IR_CONTROL_LOOP: {
- 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;
- } else {
- if (parent != loop->parent) {
- throw ir_error("controls to merge not at the same level");
+ case IR_CONTROL_LOOP: {
+ 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;
+ } else {
+ if (parent != loop->parent) {
+ throw ir_error("controls to merge not at the same level");
+ }
}
+ CBlock->addStatement(loop);
+ break;
}
- CBlock->addStatement( loop );
- break;
- }
- case IR_CONTROL_BLOCK: {
- 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) {
- for (int j=0; j< blockstmts.size(); j++) {
+ case IR_CONTROL_BLOCK: {
+ 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;
+ for (int j = 0; j < blockstmts.size(); j++) {
if (parent == NULL) {
parent = blockstmts[j]->parent;
- }
- else {
- if (parent != blockstmts[j]->parent) {
- throw ir_error("ir_clang.cc IR_clangCode::MergeNeighboringControlStructures controls to merge not at the same level");
+ } else {
+ if (parent != blockstmts[j]->parent) {
+ throw ir_error(
+ "ir_clang.cc IR_clangCode::MergeNeighboringControlStructures controls to merge not at the same level");
}
}
- CBlock->addStatement( blockstmts[j] );
+ CBlock->addStatement(blockstmts[j]);
}
+ break;
}
- else {
- if (CB->chillAST) CBlock->addStatement(CBlock->chillAST); // if this is a block, add theblock's statements?
- else { // should never happen
- CHILL_DEBUG_PRINT("WARNING: empty IR_CONTROL_BLOCK \n");
- }
- }
- break;
+ default:
+ throw ir_error("unrecognized control to merge");
}
- default:
- throw ir_error("unrecognized control to merge");
- }
- } // for each control
+ } // for each control
- return CBlock;
+ return CBlock;
}
@@ -2783,16 +2783,16 @@ IR_Block *IR_clangCode::GetCode() const { // return IR_Block corresponding to
//fprintf(stderr, "sourceManager 0x%x\n", sourceManager);
//bod->print();
- return new IR_chillBlock(this, chillfunc ) ;
+ return new IR_chillBlock(this, chillfunc);
}
void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) {
- fflush(stdout);
- fprintf(stderr, "IR_xxxxCode::ReplaceCode( old, *repr)\n");
+ fflush(stdout);
+ fprintf(stderr, "IR_xxxxCode::ReplaceCode( old, *repr)\n");
CG_chillRepr *chillrepr = (CG_chillRepr *) repr;
- std::vector<chillAST_node*> newcode = chillrepr->getChillCode();
+ std::vector<chillAST_node *> newcode = chillrepr->getChillCode();
int numnew = newcode.size();
//fprintf(stderr, "new code (%d) is\n", numnew);
@@ -2801,10 +2801,10 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) {
// fprintf(stderr, "\n");
//}
- struct IR_chillLoop* cloop;
+ struct IR_chillLoop *cloop;
- std::vector<chillAST_VarDecl*> olddecls;
- chillfunc->gatherVarDecls( olddecls );
+ std::vector<chillAST_VarDecl *> olddecls;
+ chillfunc->gatherVarDecls(olddecls);
//fprintf(stderr, "\n%d old decls they are:\n", olddecls.size());
//for (int i=0; i<olddecls.size(); i++) {
// fprintf(stderr, "olddecl[%d] ox%x ",i, olddecls[i]);
@@ -2814,11 +2814,11 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) {
//fprintf(stderr, "num new stmts %d\n", numnew);
//fprintf(stderr, "new code we're look for decls in:\n");
- std::vector<chillAST_VarDecl*> decls;
- for (int i=0; i<numnew; i++) {
+ std::vector<chillAST_VarDecl *> decls;
+ for (int i = 0; i < numnew; i++) {
//newcode[i]->print(0,stderr);
//fprintf(stderr, "\n");
- newcode[i]->gatherVarUsage( decls );
+ newcode[i]->gatherVarUsage(decls);
}
//fprintf(stderr, "\n%d new vars used they are:\n", decls.size());
@@ -2828,21 +2828,21 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) {
//}
- for (int i=0; i<decls.size(); i++) {
+ for (int i = 0; i < decls.size(); i++) {
//fprintf(stderr, "\nchecking "); decls[i]->print(); printf("\n"); fflush(stdout);
- int inthere = 0;
- for (int j=0; j<VariableDeclarations.size(); j++) {
- if (VariableDeclarations[j] == decls[i]) {
+ int inthere = 0;
+ for (int j = 0; j < VariableDeclarations.size(); j++) {
+ if (VariableDeclarations[j] == decls[i]) {
//fprintf(stderr, "it's in the Variable Declarations()\n");
}
}
- for (int j=0; j<olddecls.size(); j++) {
- if (decls[i] == olddecls[j]) {
+ for (int j = 0; j < olddecls.size(); j++) {
+ if (decls[i] == olddecls[j]) {
//fprintf(stderr, "it's in the olddecls (exactly)\n");
inthere = 1;
}
- if (streq(decls[i]->varname, olddecls[j]->varname)) {
- if (streq(decls[i]->arraypart, olddecls[j]->arraypart)) {
+ if (streq(decls[i]->varname, olddecls[j]->varname)) {
+ if (streq(decls[i]->arraypart, olddecls[j]->arraypart)) {
//fprintf(stderr, "it's in the olddecls (INEXACTLY)\n");
inthere = 1;
}
@@ -2850,50 +2850,52 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) {
}
if (!inthere) {
//fprintf(stderr, "inserting decl[%d] for ",i); decls[i]->print(); printf("\n");fflush(stdout);
- chillfunc->getBody()->insertChild(0, decls[i]);
- olddecls.push_back( decls[i] );
+ chillfunc->getBody()->insertChild(0, decls[i]);
+ olddecls.push_back(decls[i]);
}
}
-
+
chillAST_node *par;
switch (old->type()) {
- case IR_CONTROL_LOOP:
- {
+ case IR_CONTROL_LOOP: {
//fprintf(stderr, "old is IR_CONTROL_LOOP\n");
- cloop = (struct IR_chillLoop* )old;
+ cloop = (struct IR_chillLoop *) old;
chillAST_ForStmt *forstmt = cloop->chillforstmt;
fprintf(stderr, "old was\n");
- forstmt->print(); printf("\n"); fflush(stdout);
+ forstmt->print();
+ printf("\n");
+ fflush(stdout);
//fprintf(stderr, "\nnew code is\n");
//for (int i=0; i<numnew; i++) { newcode[i]->print(); printf("\n"); }
//fflush(stdout);
-
+
par = forstmt->parent;
if (!par) {
- fprintf(stderr, "old parent was NULL\n");
+ fprintf(stderr, "old parent was NULL\n");
fprintf(stderr, "ir_clang.cc that will not work very well.\n");
- exit(-1);
+ exit(-1);
}
-
- fprintf(stderr, "\nold parent was\n\n{\n");
- par->print(); printf("\n"); fflush(stdout);
- fprintf(stderr, "\n}\n");
+ fprintf(stderr, "\nold parent was\n\n{\n");
+ par->print();
+ printf("\n");
+ fflush(stdout);
+ fprintf(stderr, "\n}\n");
- std::vector<chillAST_node*> oldparentcode = par->getChildren(); // probably only works for compoundstmts
+ std::vector<chillAST_node *> oldparentcode = par->getChildren(); // probably only works for compoundstmts
//fprintf(stderr, "ir_clang.cc oldparentcode\n");
// find loop in the parent
int index = -1;
int numstatements = oldparentcode.size();
- for (int i=0; i<numstatements; i++) if (oldparentcode[i] == forstmt) { index = i; }
- if (index == -1) {
- fprintf(stderr, "ir_clang.cc can't find the loop in its parent\n");
- exit(-1);
+ for (int i = 0; i < numstatements; i++) if (oldparentcode[i] == forstmt) { index = i; }
+ if (index == -1) {
+ fprintf(stderr, "ir_clang.cc can't find the loop in its parent\n");
+ exit(-1);
}
//fprintf(stderr, "loop is index %d\n", index);
@@ -2901,96 +2903,105 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) {
par->setChild(index, newcode[0]); // overwrite old stmt
//fprintf(stderr, "inserting %s 0x%x as index %d of 0x%x\n", newcode[0]->getTypeString(), newcode[0], index, par);
// do we need to update the IR_cloop?
- cloop->chillforstmt = (chillAST_ForStmt*) newcode[0]; // ?? DFL
+ cloop->chillforstmt = (chillAST_ForStmt *) newcode[0]; // ?? DFL
//printf("inserting "); newcode[0]->print(); printf("\n");
- if (numnew > 1){
+ if (numnew > 1) {
//oldparentcode.insert( oldparentcode.begin()+index+1, numnew-1, NULL); // allocate in bulk
-
+
// add the rest of the new statements
- for (int i=1; i<numnew; i++) {
- printf("inserting "); newcode[i]->print(); printf("\n");
- par->insertChild( index+i, newcode[i] ); // sets parent
+ for (int i = 1; i < numnew; i++) {
+ printf("inserting ");
+ newcode[i]->print();
+ printf("\n");
+ par->insertChild(index + i, newcode[i]); // sets parent
}
}
// TODO add in (insert) variable declarations that go with the new loops
-
- fflush(stdout);
+
+ fflush(stdout);
}
- break;
- case IR_CONTROL_BLOCK:
- CHILL_ERROR("old is IR_CONTROL_BLOCK\n");
- exit(-1);
- //tf_old = static_cast<IR_chillBlock *>(old)->getStmtList()[0];
- break;
- default:
- throw ir_error("control structure to be replaced not supported");
- break;
+ break;
+ case IR_CONTROL_BLOCK:
+ CHILL_ERROR("old is IR_CONTROL_BLOCK\n");
+ exit(-1);
+ //tf_old = static_cast<IR_chillBlock *>(old)->getStmtList()[0];
+ break;
+ default:
+ throw ir_error("control structure to be replaced not supported");
+ break;
}
-
- fflush(stdout);
+
+ fflush(stdout);
//fprintf(stderr, "\nafter inserting %d statements into the Clang IR,", numnew);
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++) {
+ 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);
+ newparentcode[i]->print();
+ printf(";\n");
+ fflush(stdout);
}
fprintf(stderr, "}\n");
CHILL_DEBUG_END
-
}
-
-
void IR_clangCode::ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr) {
fprintf(stderr, "IR_xxxxCode::ReplaceExpression()\n");
if (typeid(*old) == typeid(IR_chillArrayRef)) {
//fprintf(stderr, "expressions is IR_chillArrayRef\n");
- IR_chillArrayRef *CAR = (IR_chillArrayRef *)old;
- chillAST_ArraySubscriptExpr* CASE = CAR->chillASE;
- printf("\nreplacing old "); CASE->print(); printf("\n"); fflush(stdout);
-
- omega::CG_chillRepr *crepr = (omega::CG_chillRepr *)repr;
- if (crepr->chillnodes.size() != 1) {
- fprintf(stderr, "IR_clangCode::ReplaceExpression(), replacing with %d chillnodes???\n");
+ IR_chillArrayRef *CAR = (IR_chillArrayRef *) old;
+ chillAST_ArraySubscriptExpr *CASE = CAR->chillASE;
+ printf("\nreplacing old ");
+ CASE->print();
+ printf("\n");
+ fflush(stdout);
+
+ omega::CG_chillRepr *crepr = (omega::CG_chillRepr *) repr;
+ if (crepr->chillnodes.size() != 1) {
+ fprintf(stderr, "IR_clangCode::ReplaceExpression(), replacing with %d chillnodes???\n");
//exit(-1);
}
-
- chillAST_node *newthing = crepr->chillnodes[0];
- fprintf(stderr, "with new "); newthing->print(); printf("\n\n"); fflush(stdout);
- if (!CASE->parent) {
- fprintf(stderr, "IR_clangCode::ReplaceExpression() old has no parent ??\n");
- exit(-1);
+ chillAST_node *newthing = crepr->chillnodes[0];
+ fprintf(stderr, "with new ");
+ newthing->print();
+ printf("\n\n");
+ fflush(stdout);
+
+ if (!CASE->parent) {
+ fprintf(stderr, "IR_clangCode::ReplaceExpression() old has no parent ??\n");
+ exit(-1);
}
fprintf(stderr, "OLD parent = "); // of type %s\n", CASE->parent->getTypeString());
- if (CASE->parent->isImplicitCastExpr()) CASE->parent->parent->print();
- else CASE->parent->print();
- printf("\n"); fflush(stdout);
+ if (CASE->parent->isImplicitCastExpr()) CASE->parent->parent->print();
+ else CASE->parent->print();
+ printf("\n");
+ fflush(stdout);
//CASE->parent->print(); printf("\n"); fflush(stdout);
//CASE->parent->parent->print(); printf("\n"); fflush(stdout);
//CASE->parent->parent->print(); printf("\n"); fflush(stdout);
//CASE->parent->parent->parent->print(); printf("\n"); fflush(stdout);
- CASE->parent->replaceChild( CASE, newthing );
+ CASE->parent->replaceChild(CASE, newthing);
fprintf(stderr, "after replace parent is "); // of type %s\n", CASE->parent->getTypeString());
- if (CASE->parent->isImplicitCastExpr()) CASE->parent->parent->print();
- else CASE->parent->print();
- printf("\n\n"); fflush(stdout);
+ if (CASE->parent->isImplicitCastExpr()) CASE->parent->parent->print();
+ else CASE->parent->print();
+ printf("\n\n");
+ fflush(stdout);
@@ -3000,12 +3011,11 @@ void IR_clangCode::ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr) {
//CASE->parent->parent->parent->print(); printf("\n"); fflush(stdout);
- }
- else if (typeid(*old) == typeid(IR_chillScalarRef)) {
- fprintf(stderr, "IR_clangCode::ReplaceExpression() IR_chillScalarRef unhandled\n");
- }
- else {
- fprintf(stderr, "UNKNOWN KIND OF REF\n"); exit(-1);
+ } else if (typeid(*old) == typeid(IR_chillScalarRef)) {
+ fprintf(stderr, "IR_clangCode::ReplaceExpression() IR_chillScalarRef unhandled\n");
+ } else {
+ fprintf(stderr, "UNKNOWN KIND OF REF\n");
+ exit(-1);
}
delete old;
@@ -3018,27 +3028,26 @@ IR_CONDITION_TYPE IR_clangCode::QueryBooleanExpOperation(const omega::CG_outputR
}
-
IR_OPERATION_TYPE IR_clangCode::QueryExpOperation(const omega::CG_outputRepr *repr) const {
//fprintf(stderr, "IR_clangCode::QueryExpOperation()\n");
- CG_chillRepr *crepr = (CG_chillRepr *) repr;
+ CG_chillRepr *crepr = (CG_chillRepr *) repr;
chillAST_node *node = crepr->chillnodes[0];
//fprintf(stderr, "chillAST node type %s\n", node->getTypeString());
// really need to be more rigorous than this hack // TODO
- if (node->isImplicitCastExpr()) node = ((chillAST_ImplicitCastExpr*)node)->subexpr;
- if (node->isCStyleCastExpr()) node = ((chillAST_CStyleCastExpr*) node)->subexpr;
- if (node->isParenExpr()) node = ((chillAST_ParenExpr*) node)->subexpr;
+ if (node->isImplicitCastExpr()) node = ((chillAST_ImplicitCastExpr *) node)->subexpr;
+ if (node->isCStyleCastExpr()) node = ((chillAST_CStyleCastExpr *) node)->subexpr;
+ if (node->isParenExpr()) node = ((chillAST_ParenExpr *) node)->subexpr;
- if (node->isIntegerLiteral() || node->isFloatingLiteral()) return IR_OP_CONSTANT;
+ if (node->isIntegerLiteral() || node->isFloatingLiteral()) return IR_OP_CONSTANT;
else if (node->isBinaryOperator() || node->isUnaryOperator()) {
char *opstring;
- if (node->isBinaryOperator())
- opstring= ((chillAST_BinaryOperator*)node)->op; // TODO enum
+ if (node->isBinaryOperator())
+ opstring = ((chillAST_BinaryOperator *) node)->op; // TODO enum
else
- opstring= ((chillAST_UnaryOperator*)node)->op; // TODO enum
-
+ opstring = ((chillAST_UnaryOperator *) node)->op; // TODO enum
+
if (!strcmp(opstring, "+")) return IR_OP_PLUS;
if (!strcmp(opstring, "-")) return IR_OP_MINUS;
if (!strcmp(opstring, "*")) return IR_OP_MULTIPLY;
@@ -3047,10 +3056,9 @@ IR_OPERATION_TYPE IR_clangCode::QueryExpOperation(const omega::CG_outputRepr *re
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 {
+ } else if (node->isDeclRefExpr()) return IR_OP_VARIABLE; // ??
+ //else if (node->is ) return something;
+ else {
CHILL_ERROR("IR_clangCode::QueryExpOperation() UNHANDLED NODE TYPE %s\n", node->getTypeString());
exit(-1);
}
@@ -3090,151 +3098,148 @@ IR_OPERATION_TYPE IR_clangCode::QueryExpOperation(const omega::CG_outputRepr *re
}
-std::vector<omega::CG_outputRepr *> IR_clangCode::QueryExpOperand(const omega::CG_outputRepr *repr) const {
+std::vector<omega::CG_outputRepr *> IR_clangCode::QueryExpOperand(const omega::CG_outputRepr *repr) const {
//fprintf(stderr, "IR_clangCode::QueryExpOperand()\n");
std::vector<omega::CG_outputRepr *> v;
-
- CG_chillRepr *crepr = (CG_chillRepr *) repr;
+
+ CG_chillRepr *crepr = (CG_chillRepr *) repr;
//Expr *e = static_cast<const omega::CG_chillRepr *>(repr)->GetExpression(); wrong.. CLANG
chillAST_node *e = crepr->chillnodes[0]; // ??
//e->print(); printf("\n"); fflush(stdout);
// really need to be more rigorous than this hack // TODO
- if (e->isImplicitCastExpr()) e = ((chillAST_ImplicitCastExpr*)e)->subexpr;
- if (e->isCStyleCastExpr()) e = ((chillAST_CStyleCastExpr*) e)->subexpr;
- if (e->isParenExpr()) e = ((chillAST_ParenExpr*) e)->subexpr;
+ if (e->isImplicitCastExpr()) e = ((chillAST_ImplicitCastExpr *) e)->subexpr;
+ if (e->isCStyleCastExpr()) e = ((chillAST_CStyleCastExpr *) e)->subexpr;
+ if (e->isParenExpr()) e = ((chillAST_ParenExpr *) e)->subexpr;
//if(isa<IntegerLiteral>(e) || isa<FloatingLiteral>(e) || isa<DeclRefExpr>(e)) {
- if (e->isIntegerLiteral() || e->isFloatingLiteral() || e->isDeclRefExpr() ) {
+ if (e->isIntegerLiteral() || e->isFloatingLiteral() || e->isDeclRefExpr()) {
//fprintf(stderr, "it's a constant\n");
omega::CG_chillRepr *repr = new omega::CG_chillRepr(e);
v.push_back(repr);
//} else if(BinaryOperator *bop = dyn_cast<BinaryOperator>(e)) {
- } else if (e->isBinaryOperator()) {
+ } else if (e->isBinaryOperator()) {
//fprintf(stderr, "ir_clang.cc BOP TODO\n"); exit(-1); //
- chillAST_BinaryOperator *bop = (chillAST_BinaryOperator*)e;
+ chillAST_BinaryOperator *bop = (chillAST_BinaryOperator *) e;
char *op = bop->op; // TODO enum for operator types
- if (streq(op, "=")) {
- v.push_back(new omega::CG_chillRepr( bop->rhs )); // for assign, return RHS
- }
- else if (streq(op, "+") || streq(op, "-") || streq(op, "*") || streq(op, "/") ) {
- v.push_back(new omega::CG_chillRepr( bop->lhs )); // for +*-/ return both lhs and rhs
- v.push_back(new omega::CG_chillRepr( bop->rhs ));
- }
- else {
+ if (streq(op, "=")) {
+ v.push_back(new omega::CG_chillRepr(bop->rhs)); // for assign, return RHS
+ } else if (streq(op, "+") || streq(op, "-") || streq(op, "*") || streq(op, "/")) {
+ v.push_back(new omega::CG_chillRepr(bop->lhs)); // for +*-/ return both lhs and rhs
+ v.push_back(new omega::CG_chillRepr(bop->rhs));
+ } else {
CHILL_ERROR("Binary Operator UNHANDLED op (%s)\n", op);
exit(-1);
}
} // BinaryOperator
- else if (e->isUnaryOperator()) {
+ else if (e->isUnaryOperator()) {
omega::CG_chillRepr *repr;
- chillAST_UnaryOperator *uop = (chillAST_UnaryOperator*)e;
+ chillAST_UnaryOperator *uop = (chillAST_UnaryOperator *) e;
char *op = uop->op; // TODO enum
if (streq(op, "+") || streq(op, "-")) {
- v.push_back( new omega::CG_chillRepr( uop->subexpr ));
- }
- else {
+ v.push_back(new omega::CG_chillRepr(uop->subexpr));
+ } else {
CHILL_ERROR("ir_clang.cc IR_clangCode::QueryExpOperand() Unary Operator UNHANDLED op (%s)\n", op);
exit(-1);
}
} // unaryoperator
- else {
+ else {
CHILL_ERROR("UNHANDLED node type %s\n", e->getTypeString());
exit(-1);
}
-
- /*
- Expr *op1, *op2;
- switch(bop->getOpcode()) {
- case BO_Assign:
- op2 = bop->getRHS();
- repr = new omega::CG_chillRepr(op2);
- v.push_back(repr);
- break;
- case BO_Add:
- case BO_Sub:
- case BO_Mul:
- case BO_Div:
- op1 = bop->getLHS();
- repr = new omega::CG_chillRepr(op1);
- v.push_back(repr);
- op2 = bop->getRHS();
- repr = new omega::CG_chillRepr(op2);
- v.push_back(repr);
- break;
- default:
- throw ir_error("operation not supported");
- }
- */
- //} else if(UnaryOperator *uop = dyn_cast<UnaryOperator>(e)) {
- //} else if(e->isUnaryOperator()) {
- /*
- omega::CG_chillRepr *repr;
-
- switch(uop->getOpcode()) {
- case UO_Minus:
- case UO_Plus:
- op1 = uop->getSubExpr();
- repr = new omega::CG_chillRepr(op1);
- v.push_back(repr);
- break;
- default:
- throw ir_error("operation not supported");
- }
- */
- //} else if(ConditionalOperator *cop = dyn_cast<ConditionalOperator>(e)) {
- //omega::CG_chillRepr *repr;
-
- // TODO: Handle conditional operator here
- //} else throw ir_error("operand type UNsupported");
-
+
+ /*
+Expr *op1, *op2;
+ switch(bop->getOpcode()) {
+ case BO_Assign:
+ op2 = bop->getRHS();
+ repr = new omega::CG_chillRepr(op2);
+ v.push_back(repr);
+ break;
+ case BO_Add:
+ case BO_Sub:
+ case BO_Mul:
+ case BO_Div:
+ op1 = bop->getLHS();
+ repr = new omega::CG_chillRepr(op1);
+ v.push_back(repr);
+ op2 = bop->getRHS();
+ repr = new omega::CG_chillRepr(op2);
+ v.push_back(repr);
+ break;
+ default:
+ throw ir_error("operation not supported");
+ }
+ */
+ //} else if(UnaryOperator *uop = dyn_cast<UnaryOperator>(e)) {
+ //} else if(e->isUnaryOperator()) {
+ /*
+ omega::CG_chillRepr *repr;
+
+ switch(uop->getOpcode()) {
+ case UO_Minus:
+ case UO_Plus:
+ op1 = uop->getSubExpr();
+ repr = new omega::CG_chillRepr(op1);
+ v.push_back(repr);
+ break;
+ default:
+ throw ir_error("operation not supported");
+ }
+ */
+ //} else if(ConditionalOperator *cop = dyn_cast<ConditionalOperator>(e)) {
+ //omega::CG_chillRepr *repr;
+
+ // TODO: Handle conditional operator here
+ //} else throw ir_error("operand type UNsupported");
+
return v;
}
IR_Ref *IR_clangCode::Repr2Ref(const omega::CG_outputRepr *repr) const {
- CG_chillRepr *crepr = (CG_chillRepr *) repr;
- chillAST_node *node = crepr->chillnodes[0];
-
+ CG_chillRepr *crepr = (CG_chillRepr *) repr;
+ chillAST_node *node = crepr->chillnodes[0];
+
//Expr *e = static_cast<const omega::CG_chillRep *>(repr)->GetExpression();
- if(node->isIntegerLiteral()) {
+ if (node->isIntegerLiteral()) {
// FIXME: Not sure if it'll work in all cases (long?)
- int val = ((chillAST_IntegerLiteral*)node)->value;
- return new IR_chillConstantRef(this, static_cast<omega::coef_t>(val) );
- } else if(node->isFloatingLiteral()) {
- float val = ((chillAST_FloatingLiteral*)node)->value;
- return new IR_chillConstantRef(this, val );
- } else if(node->isDeclRefExpr()) {
+ int val = ((chillAST_IntegerLiteral *) node)->value;
+ return new IR_chillConstantRef(this, static_cast<omega::coef_t>(val));
+ } else if (node->isFloatingLiteral()) {
+ float val = ((chillAST_FloatingLiteral *) node)->value;
+ return new IR_chillConstantRef(this, val);
+ } else if (node->isDeclRefExpr()) {
//fprintf(stderr, "ir_clang.cc IR_clangCode::Repr2Ref() declrefexpr TODO\n"); exit(-1);
- return new IR_chillScalarRef(this, (chillAST_DeclRefExpr*)node); // uses DRE
- } else {
- fprintf(stderr, "ir_clang.cc IR_clangCode::Repr2Ref() UNHANDLED node type %s\n", node->getTypeString());
- exit(-1);
+ return new IR_chillScalarRef(this, (chillAST_DeclRefExpr *) node); // uses DRE
+ } else {
+ fprintf(stderr, "ir_clang.cc IR_clangCode::Repr2Ref() UNHANDLED node type %s\n", node->getTypeString());
+ exit(-1);
//assert(0);
}
}
-chillAST_node * ConvertMemberExpr( clang::MemberExpr *clangME , chillAST_node *) {
- fprintf(stderr, "ConvertMemberExpr()\n");
-
- clang::Expr *E = clangME->getBase();
+chillAST_node *ConvertMemberExpr(clang::MemberExpr *clangME, chillAST_node *) {
+ fprintf(stderr, "ConvertMemberExpr()\n");
+
+ clang::Expr *E = clangME->getBase();
E->dump();
- chillAST_node *base = ConvertGenericClangAST( clangME->getBase(), NULL );
+ chillAST_node *base = ConvertGenericClangAST(clangME->getBase(), NULL);
- DeclarationNameInfo memnameinfo = clangME->getMemberNameInfo();
+ DeclarationNameInfo memnameinfo = clangME->getMemberNameInfo();
DeclarationName DN = memnameinfo.getName();
const char *member = DN.getAsString().c_str();
//fprintf(stderr, "%s\n", DN.getAsString().c_str());
- chillAST_MemberExpr *ME = new chillAST_MemberExpr( base, member, NULL, clangME );
+ chillAST_MemberExpr *ME = new chillAST_MemberExpr(base, member, NULL, clangME);
- fprintf(stderr, "this is the Member Expresion\n");
- ME->print();
- fprintf(stderr, "\n");
+ fprintf(stderr, "this is the Member Expresion\n");
+ ME->print();
+ fprintf(stderr, "\n");
+
+ return ME;
- return ME;
-
}
diff --git a/src/irtools.cc b/src/irtools.cc
index d8d234f..68c9eac 100644
--- a/src/irtools.cc
+++ b/src/irtools.cc
@@ -23,113 +23,113 @@ using namespace omega;
// Build Chill IR tree from the source code (from the front end compiler's AST).
// Block type node can only be a leaf, i.e., there are no further structures
// inside a block allowed.
-std::vector<ir_tree_node *> build_ir_tree(IR_Control *control,
+std::vector<ir_tree_node *> build_ir_tree(IR_Control *control,
ir_tree_node *parent) {
std::vector<ir_tree_node *> result;
-
+
CHILL_DEBUG_PRINT("building a CHILL IR tree \n");
switch (control->type()) {
- case IR_CONTROL_BLOCK: {
- 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);
+ case IR_CONTROL_BLOCK: {
+ 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);
+
+
+ CHILL_DEBUG_PRINT("BACK FROM FindOneLevelControlStructure() %d controls\n", controls.size());
+
+ if (controls.size() == 0) {
+ CHILL_DEBUG_PRINT("controls.size() == 0\n");
- CHILL_DEBUG_PRINT( "BACK FROM FindOneLevelControlStructure() %d controls\n", controls.size());
+ ir_tree_node *node = new ir_tree_node;
+ node->content = control;
+ node->parent = parent;
+ node->payload = -1;
+ result.push_back(node);
+ } else {
+ 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: {
+ 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: {
+ 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;
+ node->children = build_ir_tree(static_cast<IR_Loop *>(controls[i])->body(), node); // recurse
+ node->payload = -1;
+ result.push_back(node);
+ break;
+ }
+ case IR_CONTROL_IF: {
+ 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]);
+ IR_Block *block = theif->then_body();
+ if (block != NULL) {
+ ir_tree_node *node = new ir_tree_node;
+ node->content = controls[i];
+ node->parent = parent;
+ node->children = build_ir_tree(block, node); // recurse
+ node->payload = unique_if_identifier + 1;
+ result.push_back(node);
+ }
- if (controls.size() == 0) {
- CHILL_DEBUG_PRINT("controls.size() == 0\n");
+ block = theif->else_body();
+ if (block != NULL) {
+ 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;
+ node->children = build_ir_tree(block, node); // recurse
+ node->payload = unique_if_identifier;
+ result.push_back(node);
+ }
+ unique_if_identifier += 2;
+ break;
+ }
+ default:
+ ir_tree_node *node = new ir_tree_node;
+ node->content = controls[i];
+ node->parent = parent;
+ node->payload = -1;
+ result.push_back(node);
+ break;
+ }
+ }
+ break;
+ }
+ case IR_CONTROL_LOOP: {
+ CHILL_DEBUG_PRINT("case IR_CONTROL_LOOP\n");
ir_tree_node *node = new ir_tree_node;
- node->content = control;
- node->parent = parent;
+ node->content = control;
+ node->parent = parent;
+ 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);
+ CHILL_DEBUG_PRINT("recursing. build_ir_tree() of CONTROL_LOOP creating children DONE\n");
+ break;
}
- else {
- 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: {
- 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: {
- 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;
- node->children = build_ir_tree(static_cast<IR_Loop *>(controls[i])->body(), node); // recurse
- node->payload = -1;
- result.push_back(node);
- break;
- }
- case IR_CONTROL_IF: {
- 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]);
- IR_Block *block = theif->then_body();
- if (block != NULL) {
- ir_tree_node *node = new ir_tree_node;
- node->content = controls[i];
- node->parent = parent;
- node->children = build_ir_tree(block, node); // recurse
- node->payload = unique_if_identifier+1;
- result.push_back(node);
- }
-
-
- block = theif->else_body();
- if (block != NULL) {
- 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;
- node->children = build_ir_tree(block, node); // recurse
- node->payload = unique_if_identifier;
- result.push_back(node);
- }
- unique_if_identifier += 2;
- break;
- }
- default:
- ir_tree_node *node = new ir_tree_node;
- node->content = controls[i];
- node->parent = parent;
- node->payload = -1;
- result.push_back(node);
- break;
- }
- }
- break;
- }
- case IR_CONTROL_LOOP: {
- CHILL_DEBUG_PRINT("case IR_CONTROL_LOOP\n");
- ir_tree_node *node = new ir_tree_node;
- node->content = control;
- node->parent = parent;
- 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);
- CHILL_DEBUG_PRINT("recursing. build_ir_tree() of CONTROL_LOOP creating children DONE\n");
- break;
- }
- default:
- ir_tree_node *node = new ir_tree_node;
- node->content = control;
- node->parent = parent;
- node->payload = -1;
- result.push_back(node);
- break;
+ default:
+ ir_tree_node *node = new ir_tree_node;
+ node->content = control;
+ node->parent = parent;
+ node->payload = -1;
+ result.push_back(node);
+ break;
}
-
+
CHILL_DEBUG_PRINT("build_ir_tree() vector result has %ld parts\n", result.size());
return result;
}
@@ -144,46 +144,51 @@ std::vector<ir_tree_node *> extract_ir_stmts(const std::vector<ir_tree_node *> &
for (int i = 0; i < ir_tree.size(); i++)
switch (ir_tree[i]->content->type()) {
- case IR_CONTROL_BLOCK:
- CHILL_DEBUG_PRINT("IR_CONTROL_BLOCK\n");
- result.push_back(ir_tree[i]);
- break;
+ case IR_CONTROL_BLOCK:
+ CHILL_DEBUG_PRINT("IR_CONTROL_BLOCK\n");
+ result.push_back(ir_tree[i]);
+ break;
- case IR_CONTROL_LOOP: {
- CHILL_DEBUG_PRINT("IR_CONTROL_LOOP( recursing )\n");
- // clear loop payload from previous unsuccessful initialization process
- ir_tree[i]->payload = -1;
-
- std::vector<ir_tree_node *> t = extract_ir_stmts(ir_tree[i]->children);
-
- result.insert(result.end(), t.begin(), t.end());
- break;
- }
- case IR_CONTROL_IF: {
- 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;
- }
- default:
- throw std::invalid_argument("invalid ir tree");
+ case IR_CONTROL_LOOP: {
+ CHILL_DEBUG_PRINT("IR_CONTROL_LOOP( recursing )\n");
+ // clear loop payload from previous unsuccessful initialization process
+ ir_tree[i]->payload = -1;
+
+ std::vector<ir_tree_node *> t = extract_ir_stmts(ir_tree[i]->children);
+
+ result.insert(result.end(), t.begin(), t.end());
+ break;
+ }
+ case IR_CONTROL_IF: {
+ 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;
+ }
+ default:
+ throw std::invalid_argument("invalid ir tree");
}
-
+
return result;
}
-std::string chill_ir_control_type_string( IR_CONTROL_TYPE type ) {
- switch(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");
- default: return std::string( "UNKNOWN_IR_NODE_TYPE" );
+std::string chill_ir_control_type_string(IR_CONTROL_TYPE type) {
+ switch (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");
+ default:
+ return std::string("UNKNOWN_IR_NODE_TYPE");
}
}
-std::string chill_ir_node_type_string( ir_tree_node *node ) {
- return chill_ir_control_type_string( node->content->type() );
+std::string chill_ir_node_type_string(ir_tree_node *node) {
+ return chill_ir_control_type_string(node->content->type());
}
@@ -191,14 +196,14 @@ bool is_dependence_valid(ir_tree_node *src_node, ir_tree_node *dst_node,
const DependenceVector &dv, bool before) {
std::set<ir_tree_node *> loop_nodes;
ir_tree_node *itn = src_node;
-
+
if (!dv.is_scalar_dependence) {
while (itn->parent != NULL) {
itn = itn->parent;
if (itn->content->type() == IR_CONTROL_LOOP)
loop_nodes.insert(itn);
}
-
+
int last_dim = -1;
itn = dst_node;
while (itn->parent != NULL) {
@@ -208,25 +213,25 @@ bool is_dependence_valid(ir_tree_node *src_node, ir_tree_node *dst_node,
&& itn->payload > last_dim)
last_dim = itn->payload;
}
-
+
if (last_dim == -1)
return true;
-
+
for (int i = 0; i <= last_dim; i++) {
if (dv.lbounds[i] > 0)
return true;
else if (dv.lbounds[i] < 0)
return false;
}
-
+
if (before)
return true;
else
return false;
}
-
+
return true;
-
+
}
@@ -234,31 +239,31 @@ bool is_dependence_valid(ir_tree_node *src_node, ir_tree_node *dst_node,
//enclosing a statement
std::vector<omega::CG_outputRepr *> collect_loop_inductive_and_conditionals(
- ir_tree_node * stmt_node) {
-
+ ir_tree_node *stmt_node) {
+
std::vector<omega::CG_outputRepr *> to_return;
ir_tree_node *itn = stmt_node;
-
+
while (itn->parent != NULL) {
itn = itn->parent;
-
+
switch (itn->content->type()) {
- case IR_CONTROL_LOOP: {
- IR_Loop *lp = static_cast<IR_Loop *>(itn->content);
- to_return.push_back(lp->lower_bound());
- to_return.push_back(lp->upper_bound());
-
- break;
- }
- case IR_CONTROL_IF: {
- CG_outputRepr *cond =
- static_cast<IR_If *>(itn->content)->condition();
-
- to_return.push_back(cond);
- break;
- }
- default:
- throw std::invalid_argument("invalid ir tree");
+ case IR_CONTROL_LOOP: {
+ IR_Loop *lp = static_cast<IR_Loop *>(itn->content);
+ to_return.push_back(lp->lower_bound());
+ to_return.push_back(lp->upper_bound());
+
+ break;
+ }
+ case IR_CONTROL_IF: {
+ CG_outputRepr *cond =
+ static_cast<IR_If *>(itn->content)->condition();
+
+ to_return.push_back(cond);
+ break;
+ }
+ default:
+ throw std::invalid_argument("invalid ir tree");
}
}
return to_return;
@@ -271,36 +276,46 @@ std::vector<omega::CG_outputRepr *> collect_loop_inductive_and_conditionals(
// positive. The first vector in returned pair is dependences from the
// first statement to the second statement and the second vector in
// returned pair is in reverse order.
-std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> >
-test_data_dependences(IR_Code *ir,
- const CG_outputRepr *repr1,
+std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> >
+test_data_dependences(IR_Code *ir,
+ const CG_outputRepr *repr1,
const Relation &IS1,
- const CG_outputRepr *repr2,
+ const CG_outputRepr *repr2,
const Relation &IS2,
- std::vector<Free_Var_Decl*> &freevar,
+ std::vector<Free_Var_Decl *> &freevar,
std::vector<std::string> index,
- int nestLeveli,
- 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) {
+ int nestLeveli,
+ 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, "\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());
-
+
// fprintf(stderr, "freevar %d %s\n", i, shit.c_str());
//}
-
+
std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > result;
-
+
if (repr1 == repr2) {
CHILL_DEBUG_BEGIN
fprintf(stderr, "repr1 == repr2\nrepr1->dump()\n");
@@ -312,14 +327,13 @@ test_data_dependences(IR_Code *ir,
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()) {
+
+ if (a->is_write()) {
CHILL_DEBUG_PRINT("WRITE array access %d = %s\n", i, a->name().c_str());
- }
- else {
+ } else {
CHILL_DEBUG_PRINT(" array access %d = %s\n", i, a->name().c_str());
- }
- }
+ }
+ }
CHILL_DEBUG_PRINT("that was the list\n\n");
// Manu:: variables/structures added to identify dependence vectors related to reduction operation
@@ -330,16 +344,16 @@ test_data_dependences(IR_Code *ir,
std::set<int> tnrStmts;
int stmtId = 1;
int tempStmtId = 1;
- std::map<int,std::set<int> > rMap; // This maps statement number to a set of dependences
+ std::map<int, std::set<int> > rMap; // This maps statement number to a set of dependences
std::map<int, std::set<int> >::iterator itMap;
for (int i = 0; i < access.size(); i++) {
ref2Stmt[i] = -1;
}
-
+
// Manu -- changes for identifying possible reduction operation
// The below loop nest is used to classify array references into different statements
CHILL_DEBUG_PRINT("\nbefore mapRefstoStatements()\n");
- mapRefstoStatements(ir,access,ref2Stmt,rMap,tnrStmts,nrStmts);
+ mapRefstoStatements(ir, access, ref2Stmt, rMap, tnrStmts, nrStmts);
CHILL_DEBUG_PRINT("after mapRefstoStatements()\n\n");
//-------------------------------------------------------------
@@ -348,92 +362,98 @@ test_data_dependences(IR_Code *ir,
lbound[0] = lbound[1] = lbound[2] = LLONG_MAX;
ubound[0] = ubound[1] = ubound[2] = LLONG_MIN;
//-------------------------------------------------------------
-
+
for (int i = 0; i < access.size(); i++) {
- fprintf(stderr, "i %d\n", i);
+ fprintf(stderr, "i %d\n", i);
IR_ArrayRef *a = access[i];
IR_ArraySymbol *sym_a = a->symbol();
- fprintf(stderr, "sym_a = %s\n", a->name().c_str());
+ fprintf(stderr, "sym_a = %s\n", a->name().c_str());
for (int j = i; j < access.size(); j++) {
- fprintf(stderr, "irtools.cc j %d\n", j);
+ fprintf(stderr, "irtools.cc j %d\n", j);
IR_ArrayRef *b = access[j];
IR_ArraySymbol *sym_b = b->symbol();
- fprintf(stderr, "sym_b = %s\n", b->name().c_str());
-
- fprintf(stderr, "irtools.cc ij %d %d\n", i, j);
-
- if (*sym_a == *sym_b) fprintf(stderr, "*sym_a == *sym_b\n");
+ fprintf(stderr, "sym_b = %s\n", b->name().c_str());
+
+ fprintf(stderr, "irtools.cc ij %d %d\n", i, j);
+
+ if (*sym_a == *sym_b) fprintf(stderr, "*sym_a == *sym_b\n");
else fprintf(stderr, "*sym_a NOT == *sym_b\n");
- if ( a->is_write()) fprintf(stderr, "%d a->is_write()\n", i);
- else fprintf(stderr, "%d a->is_NOT_write()\n", i);
- if ( b->is_write()) fprintf(stderr, "%d b->is_write()\n", j);
- else fprintf(stderr, "%d b->is_NOT_write()\n", j);
+ if (a->is_write()) fprintf(stderr, "%d a->is_write()\n", i);
+ else fprintf(stderr, "%d a->is_NOT_write()\n", i);
+ if (b->is_write()) fprintf(stderr, "%d b->is_write()\n", j);
+ else fprintf(stderr, "%d b->is_NOT_write()\n", j);
if (*sym_a == *sym_b && (a->is_write() || b->is_write())) {
- Relation r = arrays2relation(ir, freevar, a, IS1, b, IS2,uninterpreted_symbols,uninterpreted_symbols_stringrepr);
+ Relation r = arrays2relation(ir, freevar, a, IS1, b, IS2, uninterpreted_symbols,
+ uninterpreted_symbols_stringrepr);
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);
+ 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");
+ fprintf(stderr, "1\n");
std::pair<std::vector<DependenceVector>,
- std::vector<DependenceVector> > dv =
- relation2dependences(a, b, r);
- fprintf(stderr, "\nirtools.cc ij %d %d dv.first %d dv.second %d\n", i, j, dv.first.size(), dv.second.size());
- fprintf(stderr, "2");
- result.first.insert(result.first.end(), dv.first.begin(),
+ std::vector<DependenceVector> > dv =
+ relation2dependences(a, b, r);
+ fprintf(stderr, "\nirtools.cc ij %d %d dv.first %d dv.second %d\n", i, j, dv.first.size(),
+ dv.second.size());
+ fprintf(stderr, "2");
+ result.first.insert(result.first.end(), dv.first.begin(),
dv.first.end());
- fprintf(stderr, "3");
+ fprintf(stderr, "3");
result.second.insert(result.second.end(), dv.second.begin(),
dv.second.end());
- fprintf(stderr, "4");
+ fprintf(stderr, "4");
// Manu:: check if the array references belong to the same statement
// If yes, set the flag in the dependence vector
//----------------------------------------------
- if(DEP_DEBUG){
+ if (DEP_DEBUG) {
std::cout << "Size of the dependence vector '" << a->name().c_str() << "' -- " << dv.first.size() << "\n";
std::cout << "------------ Printing dependence vector START ---------------\n";
-
- for (std::vector<DependenceVector>::iterator itd = dv.first.begin(); itd != dv.first.end(); itd++){
+
+ for (std::vector<DependenceVector>::iterator itd = dv.first.begin(); itd != dv.first.end(); itd++) {
if (itd->type == DEP_R2W)
- std::cout<<"WAR\n";
+ std::cout << "WAR\n";
else if (itd->type == DEP_W2R)
- std::cout<<"RAW\n";
+ std::cout << "RAW\n";
else if (itd->type == DEP_W2W)
- std::cout<<"WAW\n";
-
+ std::cout << "WAW\n";
+
std::vector<omega::coef_t>::iterator itu = itd->ubounds.begin();
- for (std::vector<omega::coef_t>::iterator itl = itd->lbounds.begin(); itl != itd->lbounds.end(); itl++){
+ for (std::vector<omega::coef_t>::iterator itl = itd->lbounds.begin(); itl != itd->lbounds.end(); itl++) {
std::cout << "(" << *itl << ", " << *itu << ")\n";
itu++;
}
}
std::cout << "--------\n";
- for (std::vector<DependenceVector>::iterator itd = dv.second.begin(); itd != dv.second.end(); itd++){
+ for (std::vector<DependenceVector>::iterator itd = dv.second.begin(); itd != dv.second.end(); itd++) {
if (itd->type == DEP_R2W)
- std::cout<<"WAR\n";
+ std::cout << "WAR\n";
else if (itd->type == DEP_W2R)
- std::cout<<"RAW\n";
+ std::cout << "RAW\n";
else if (itd->type == DEP_W2W)
- std::cout<<"WAW\n";
-
+ std::cout << "WAW\n";
+
std::vector<omega::coef_t>::iterator itu = itd->ubounds.begin();
- for (std::vector<omega::coef_t>::iterator itl = itd->lbounds.begin(); itl != itd->lbounds.end(); itl++){
+ for (std::vector<omega::coef_t>::iterator itl = itd->lbounds.begin(); itl != itd->lbounds.end(); itl++) {
std::cout << "(" << *itl << ", " << *itu << ")\n";
itu++;
}
}
std::cout << "------------ Printing dependence vector END---------------\n";
}
- checkReductionDependence(i,j,nestLeveli,lbound,ubound,ref2Stmt,rMap,dv,trMap,nrStmts);
+ checkReductionDependence(i, j, nestLeveli, lbound, ubound, ref2Stmt, rMap, dv, trMap, nrStmts);
//----------------------------------------------
-
+
// // Manu:: original code without the condition
if (((rMap.find(ref2Stmt[i])->second).size() != 3) || (lbound[0] != lbound[1]) || (lbound[1] != lbound[2]) ||
- (lbound[0] != lbound[2]) || (ubound[0] != ubound[1]) || (ubound[1] != ubound[2]) || (ubound[0] != ubound[2])) { // Manu:: original code without the condition
+ (lbound[0] != lbound[2]) || (ubound[0] != ubound[1]) || (ubound[1] != ubound[2]) ||
+ (ubound[0] != ubound[2])) { // Manu:: original code without the condition
result.first.insert(result.first.end(),
dv.first.begin(), dv.first.end());
result.second.insert(result.second.end(),
@@ -446,7 +466,7 @@ test_data_dependences(IR_Code *ir,
}
delete sym_a;
}
-
+
// Manu
for (ittrMap = trMap.begin(); ittrMap != trMap.end(); ittrMap++) {
DVPair tdv = ittrMap->second;
@@ -455,29 +475,30 @@ test_data_dependences(IR_Code *ir,
result.second.insert(result.second.end(), tdv.second.begin(),
tdv.second.end());
}
-
+
for (int i = 0; i < access.size(); i++)
delete access[i];
} else {
- fprintf(stderr, "\nrepr1 != repr2\n");
+ fprintf(stderr, "\nrepr1 != repr2\n");
std::vector<IR_ArrayRef *> access1 = ir->FindArrayRef(repr1);
std::vector<IR_ArrayRef *> access2 = ir->FindArrayRef(repr2);
-
+
for (int i = 0; i < access1.size(); i++) {
- fprintf(stderr, "i %d\n", i);
+ fprintf(stderr, "i %d\n", i);
IR_ArrayRef *a = access1[i];
IR_ArraySymbol *sym_a = a->symbol();
-
+
for (int j = 0; j < access2.size(); j++) {
IR_ArrayRef *b = access2[j];
IR_ArraySymbol *sym_b = b->symbol();
if (*sym_a == *sym_b && (a->is_write() || b->is_write())) {
- Relation r = arrays2relation(ir, freevar, a, IS1, b, IS2, uninterpreted_symbols,uninterpreted_symbols_stringrepr);
+ Relation r = arrays2relation(ir, freevar, a, IS1, b, IS2, uninterpreted_symbols,
+ uninterpreted_symbols_stringrepr);
std::pair<std::vector<DependenceVector>,
- std::vector<DependenceVector> > dv =
- relation2dependences(a, b, r);
-
+ std::vector<DependenceVector> > dv =
+ relation2dependences(a, b, r);
+
result.first.insert(result.first.end(), dv.first.begin(),
dv.first.end());
result.second.insert(result.second.end(), dv.second.begin(),
@@ -487,7 +508,7 @@ test_data_dependences(IR_Code *ir,
}
delete sym_a;
}
-
+
for (int i = 0; i < access1.size(); i++)
delete access1[i];
for (int i = 0; i < access2.size(); i++)
@@ -507,8 +528,9 @@ test_data_dependences(IR_Code *ir,
result.second.insert(result.second.end(), dv.second.begin(),
dv.second.end());
*/
-
- fprintf(stderr, "LEAVING test_data_dependences() first size %d second size %d\n\n", result.first.size(), result.second.size());
+
+ fprintf(stderr, "LEAVING test_data_dependences() first size %d second size %d\n\n", result.first.size(),
+ result.second.size());
return result;
}
@@ -516,13 +538,13 @@ test_data_dependences(IR_Code *ir,
//Manu:: This function tests if two references are from the same statement
//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) {
- return ir->FromSameStmt(a,b);
+ return ir->FromSameStmt(a, b);
}
// Manu
int stmtType(IR_Code *ir, const CG_outputRepr *repr) {
- fprintf(stderr, "stmtType() DIE \n");
- exit(-1);
+ fprintf(stderr, "stmtType() DIE \n");
+ exit(-1);
return (ir->getStmtType(repr)); /// AIEEE returns a meaningless number encoding rose internals.
}
@@ -532,8 +554,10 @@ IR_OPERATION_TYPE getReductionOperator(IR_Code *ir, const CG_outputRepr *repr) {
}
// Manu:: map references to its corresponding statements
-void mapRefstoStatements(IR_Code *ir, std::vector<IR_ArrayRef *> access, int ref2Stmt[], std::map<int,std::set<int> >& rMap, std::set<int>& tnrStmts, std::set<int>& nrStmts) {
-
+void
+mapRefstoStatements(IR_Code *ir, std::vector<IR_ArrayRef *> access, int ref2Stmt[], std::map<int, std::set<int> > &rMap,
+ std::set<int> &tnrStmts, std::set<int> &nrStmts) {
+
int stmtId = 1;
for (int i = 0; i < access.size(); i++) {
IR_ArrayRef *a = access[i];
@@ -542,7 +566,7 @@ void mapRefstoStatements(IR_Code *ir, std::vector<IR_ArrayRef *> access, int ref
IR_ArrayRef *b = access[j];
IR_ArraySymbol *sym_b = b->symbol();
bool inSameStmt;
- if (from_same_statement(ir,access[i],access[j])) {
+ if (from_same_statement(ir, access[i], access[j])) {
inSameStmt = true;
// std::cout << "Manu:: inSameStmt " << a->name().c_str() << ", " << b->name().c_str() << "\n";
} else {
@@ -553,7 +577,7 @@ void mapRefstoStatements(IR_Code *ir, std::vector<IR_ArrayRef *> access, int ref
if (ref2Stmt[i] == -1)
ref2Stmt[i] = stmtId++;
ref2Stmt[j] = ref2Stmt[i];
- rMap.insert(std::pair<int,std::set<int> >(ref2Stmt[i],std::set<int>()));
+ rMap.insert(std::pair<int, std::set<int> >(ref2Stmt[i], std::set<int>()));
} else {
if (ref2Stmt[i] == -1)
ref2Stmt[i] = stmtId++;
@@ -564,26 +588,28 @@ void mapRefstoStatements(IR_Code *ir, std::vector<IR_ArrayRef *> access, int ref
tnrStmts.insert(j);
}
}
-
+
}
}
std::set<int>::iterator itS;
for (itS = tnrStmts.begin(); itS != tnrStmts.end(); itS++) {
nrStmts.insert(ref2Stmt[*itS]);
}
-
+
}
// Manu:: This function tests reduction dependence and updates corresponding data structures
-void checkReductionDependence(int i, int j, int nestLeveli, omega::coef_t lbound[], omega::coef_t ubound[], int ref2Stmt[], std::map<int,std::set<int> >& rMap, DVPair& dv, tempResultMap& trMap, std::set<int> nrStmts ) {
-
+void
+checkReductionDependence(int i, int j, int nestLeveli, omega::coef_t lbound[], omega::coef_t ubound[], int ref2Stmt[],
+ std::map<int, std::set<int> > &rMap, DVPair &dv, tempResultMap &trMap, std::set<int> nrStmts) {
+
std::map<int, std::set<int> >::iterator itMap;
tempResultMap::iterator ittrMap;
- bool raw,war,waw, flg;
+ bool raw, war, waw, flg;
raw = war = waw = flg = false;
- if ((ref2Stmt[i] == ref2Stmt[j]) && (nrStmts.find(ref2Stmt[i])== nrStmts.end())) {
+ if ((ref2Stmt[i] == ref2Stmt[j]) && (nrStmts.find(ref2Stmt[i]) == nrStmts.end())) {
for (int k = 0; k < dv.first.size(); k++) {
- if ((dv.first[k].lbounds[nestLeveli-1] == 0) && (dv.first[k].ubounds[nestLeveli-1] == 0))
+ if ((dv.first[k].lbounds[nestLeveli - 1] == 0) && (dv.first[k].ubounds[nestLeveli - 1] == 0))
continue;
itMap = rMap.find(ref2Stmt[i]);
if (dv.first[k].type == DEP_R2W) {
@@ -591,15 +617,15 @@ void checkReductionDependence(int i, int j, int nestLeveli, omega::coef_t lbound
std::set<int> s = itMap->second;
s.insert(1); // war == 1
rMap.erase(itMap);
- rMap.insert(std::pair<int,std::set<int> >(ref2Stmt[i],s));
- if (lbound[0] > dv.first[k].lbounds[nestLeveli-1])
- lbound[0] = dv.first[k].lbounds[nestLeveli-1];
- if(ubound[0] < dv.first[k].ubounds[nestLeveli-1])
- ubound[0] = dv.first[k].ubounds[nestLeveli-1];
+ rMap.insert(std::pair<int, std::set<int> >(ref2Stmt[i], s));
+ if (lbound[0] > dv.first[k].lbounds[nestLeveli - 1])
+ lbound[0] = dv.first[k].lbounds[nestLeveli - 1];
+ if (ubound[0] < dv.first[k].ubounds[nestLeveli - 1])
+ ubound[0] = dv.first[k].ubounds[nestLeveli - 1];
} else if (dv.first[k].type == DEP_W2R) {
// for (int k1 = 0; k1 < dv.first[k].lbounds.size(); k1++) {
// omega::coef_t lbound = dv.first[k].lbounds[k1];
- omega::coef_t lbound1 = dv.first[k].lbounds[nestLeveli-1];
+ omega::coef_t lbound1 = dv.first[k].lbounds[nestLeveli - 1];
if (lbound1 > 0) {
flg = true;
// break;
@@ -610,28 +636,28 @@ void checkReductionDependence(int i, int j, int nestLeveli, omega::coef_t lbound
std::set<int> s = itMap->second;
s.insert(2); // raw == 2
rMap.erase(itMap);
- rMap.insert(std::pair<int,std::set<int> >(ref2Stmt[i],s));
- if (lbound[1] > dv.first[k].lbounds[nestLeveli-1])
- lbound[1] = dv.first[k].lbounds[nestLeveli-1];
- if(ubound[1] < dv.first[k].ubounds[nestLeveli-1])
- ubound[1] = dv.first[k].ubounds[nestLeveli-1];
+ rMap.insert(std::pair<int, std::set<int> >(ref2Stmt[i], s));
+ if (lbound[1] > dv.first[k].lbounds[nestLeveli - 1])
+ lbound[1] = dv.first[k].lbounds[nestLeveli - 1];
+ if (ubound[1] < dv.first[k].ubounds[nestLeveli - 1])
+ ubound[1] = dv.first[k].ubounds[nestLeveli - 1];
}
} else if (dv.first[k].type == DEP_W2W) {
waw = true;
std::set<int> s = itMap->second;
s.insert(3); // waw == 3
rMap.erase(itMap);
- rMap.insert(std::pair<int,std::set<int> >(ref2Stmt[i],s));
- if (lbound[2] > dv.first[k].lbounds[nestLeveli-1])
- lbound[2] = dv.first[k].lbounds[nestLeveli-1];
- if(ubound[2] < dv.first[k].ubounds[nestLeveli-1])
- ubound[2] = dv.first[k].ubounds[nestLeveli-1];
+ rMap.insert(std::pair<int, std::set<int> >(ref2Stmt[i], s));
+ if (lbound[2] > dv.first[k].lbounds[nestLeveli - 1])
+ lbound[2] = dv.first[k].lbounds[nestLeveli - 1];
+ if (ubound[2] < dv.first[k].ubounds[nestLeveli - 1])
+ ubound[2] = dv.first[k].ubounds[nestLeveli - 1];
}
// std::cout<< "Manu:: Flags:: " << "raw " << raw << ", war " << war << ", waw " << waw << "\n";
}
flg = false;
for (int k = 0; k < dv.second.size(); k++) {
- if ((dv.second[k].lbounds[nestLeveli-1] == 0) && (dv.second[k].ubounds[nestLeveli-1] == 0))
+ if ((dv.second[k].lbounds[nestLeveli - 1] == 0) && (dv.second[k].ubounds[nestLeveli - 1] == 0))
continue;
itMap = rMap.find(ref2Stmt[i]);
if (dv.second[k].type == DEP_R2W) {
@@ -639,16 +665,16 @@ void checkReductionDependence(int i, int j, int nestLeveli, omega::coef_t lbound
std::set<int> s = itMap->second;
s.insert(1); // war == 1
rMap.erase(itMap);
- rMap.insert(std::pair<int,std::set<int> >(ref2Stmt[i],s));
- if (lbound[0] > dv.second[k].lbounds[nestLeveli-1])
- lbound[0] = dv.second[k].lbounds[nestLeveli-1];
- if (ubound[0] < dv.second[k].ubounds[nestLeveli-1])
- ubound[0] = dv.second[k].ubounds[nestLeveli-1];
-
+ rMap.insert(std::pair<int, std::set<int> >(ref2Stmt[i], s));
+ if (lbound[0] > dv.second[k].lbounds[nestLeveli - 1])
+ lbound[0] = dv.second[k].lbounds[nestLeveli - 1];
+ if (ubound[0] < dv.second[k].ubounds[nestLeveli - 1])
+ ubound[0] = dv.second[k].ubounds[nestLeveli - 1];
+
} else if (dv.second[k].type == DEP_W2R) {
// for (int k1 = 0; k1 < dv.second[k].lbounds.size(); k1++) {
//omega::coef_t lbound = dv.second[k].lbounds[k1];
- omega::coef_t lbound1 = dv.second[k].lbounds[nestLeveli-1];
+ omega::coef_t lbound1 = dv.second[k].lbounds[nestLeveli - 1];
if (lbound1 > 0) {
flg = true;
// break;
@@ -659,33 +685,33 @@ void checkReductionDependence(int i, int j, int nestLeveli, omega::coef_t lbound
std::set<int> s = itMap->second;
s.insert(2); // raw == 2
rMap.erase(itMap);
- rMap.insert(std::pair<int,std::set<int> >(ref2Stmt[i],s));
- if (lbound[1] > dv.second[k].lbounds[nestLeveli-1])
- lbound[1] = dv.second[k].lbounds[nestLeveli-1];
- if (ubound[1] < dv.second[k].ubounds[nestLeveli-1])
- ubound[1] = dv.second[k].ubounds[nestLeveli-1];
-
+ rMap.insert(std::pair<int, std::set<int> >(ref2Stmt[i], s));
+ if (lbound[1] > dv.second[k].lbounds[nestLeveli - 1])
+ lbound[1] = dv.second[k].lbounds[nestLeveli - 1];
+ if (ubound[1] < dv.second[k].ubounds[nestLeveli - 1])
+ ubound[1] = dv.second[k].ubounds[nestLeveli - 1];
+
}
-
+
} else if (dv.second[k].type == DEP_W2W) {
waw = true;
std::set<int> s = itMap->second;
s.insert(3); // waw == 3
rMap.erase(itMap);
- rMap.insert(std::pair<int,std::set<int> >(ref2Stmt[i],s));
- if (lbound[2] > dv.second[k].lbounds[nestLeveli-1])
- lbound[2] = dv.second[k].lbounds[nestLeveli-1];
- if (ubound[2] < dv.second[k].ubounds[nestLeveli-1])
- ubound[2] = dv.second[k].ubounds[nestLeveli-1];
-
+ rMap.insert(std::pair<int, std::set<int> >(ref2Stmt[i], s));
+ if (lbound[2] > dv.second[k].lbounds[nestLeveli - 1])
+ lbound[2] = dv.second[k].lbounds[nestLeveli - 1];
+ if (ubound[2] < dv.second[k].ubounds[nestLeveli - 1])
+ ubound[2] = dv.second[k].ubounds[nestLeveli - 1];
+
}
// std::cout<< "Manu:: Flags:: " << "raw " << raw << ", war " << war << ", waw " << waw << "\n";
}
-
+
// if ((rMap.find(ref2Stmt[i])->second).size() == 3) {
- if(DEP_DEBUG){
- std::cout << "lbounds: " << lbound[0] << ", " << lbound[1] << ", " <<lbound[2] << "\n";
- std::cout << "ubounds: " << ubound[0] << ", " << ubound[1] << ", " <<ubound[2] << "\n";
+ if (DEP_DEBUG) {
+ std::cout << "lbounds: " << lbound[0] << ", " << lbound[1] << ", " << lbound[2] << "\n";
+ std::cout << "ubounds: " << ubound[0] << ", " << ubound[1] << ", " << ubound[2] << "\n";
}
if (((rMap.find(ref2Stmt[i])->second).size() == 3) && (lbound[0] == lbound[1]) && (lbound[1] == lbound[2])
&& (ubound[0] == ubound[1]) && (ubound[1] == ubound[2])) {
@@ -694,7 +720,7 @@ void checkReductionDependence(int i, int j, int nestLeveli, omega::coef_t lbound
dv.second[k].is_reduction_cand = true;
for (int k = 0; k < dv.first.size(); k++)
dv.first[k].is_reduction_cand = true;
- trMap.insert(std::pair<int,DVPair>(ref2Stmt[i],DVPair(dv.first,dv.second)));
+ trMap.insert(std::pair<int, DVPair>(ref2Stmt[i], DVPair(dv.first, dv.second)));
}
} else {
// tempArrayRefId[i] = tempArrayRefId[j] = 0;
@@ -711,24 +737,24 @@ void checkReductionDependence(int i, int j, int nestLeveli, omega::coef_t lbound
for (int k = 0; k < (tdv.second).size(); k++)
tdv.second[k].is_reduction_cand = false;
trMap.erase(ittrMap);
- trMap.insert(std::pair<int,DVPair>(ref2Stmt[i],DVPair(tdv.first,tdv.second)));
+ trMap.insert(std::pair<int, DVPair>(ref2Stmt[i], DVPair(tdv.first, tdv.second)));
}
}
-
-}
+}
-void print_control( IR_Control *con ) {
+void print_control(IR_Control *con) {
IR_CONTROL_TYPE type = con->type();
- fprintf(stderr, "this is IR_Control of type %s\n", chill_ir_control_type_string( type ).c_str());
+ fprintf(stderr, "this is IR_Control of type %s\n", chill_ir_control_type_string(type).c_str());
switch (type) {
- case IR_CONTROL_BLOCK:
- case IR_CONTROL_LOOP:
- case IR_CONTROL_IF:
- case IR_CONTROL_WHILE:
- default: return;
+ case IR_CONTROL_BLOCK:
+ case IR_CONTROL_LOOP:
+ case IR_CONTROL_IF:
+ case IR_CONTROL_WHILE:
+ default:
+ return;
}
}
diff --git a/src/omegatools.cc b/src/omegatools.cc
index 7ebe726..c7233c8 100644
--- a/src/omegatools.cc
+++ b/src/omegatools.cc
@@ -33,58 +33,56 @@ namespace {
// -1:negative, 0: undetermined, 1: postive
std::vector<coef_t> lbounds;
std::vector<coef_t> ubounds;
- DependenceLevel(const Relation &_r, int _dims):
- r(_r), level(0), dir(0), lbounds(_dims), ubounds(_dims) {}
+
+ DependenceLevel(const Relation &_r, int _dims) :
+ r(_r), level(0), dir(0), lbounds(_dims), ubounds(_dims) {}
};
}
-
-
std::string tmp_e() {
static int counter = 1;
- return std::string("e")+to_string(counter++);
+ return std::string("e") + to_string(counter++);
}
-
//-----------------------------------------------------------------------------
// Convert expression tree to omega relation. "destroy" means shallow
// deallocation of "repr", not freeing the actual code inside.
// -----------------------------------------------------------------------------
-void exp2formula(IR_Code *ir,
- Relation &r,
- F_And *f_root,
- std::vector<Free_Var_Decl*> &freevars,
- CG_outputRepr *repr,
- Variable_ID lhs,
- char side,
- IR_CONDITION_TYPE rel,
+void exp2formula(IR_Code *ir,
+ Relation &r,
+ F_And *f_root,
+ std::vector<Free_Var_Decl *> &freevars,
+ CG_outputRepr *repr,
+ Variable_ID lhs,
+ char side,
+ IR_CONDITION_TYPE rel,
bool destroy,
std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols,
std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr
- ) {
-
+) {
+
fprintf(stderr, "\n*** exp2formula()\n");
//repr->dump(); /* printf("\n"); */fflush(stdout);
- fprintf(stderr, "repr "); r.print(); printf("\n"); fflush(stdout);
-
-
+ fprintf(stderr, "repr ");
+ r.print();
+ printf("\n");
+ fflush(stdout);
+
+
IR_OPERATION_TYPE optype = ir->QueryExpOperation(repr);
-
+
switch (optype) {
-
-
-
-
- case IR_OP_CONSTANT:
- {
+
+
+ case IR_OP_CONSTANT: {
fprintf(stderr, "IR_OP_CONSTANT\n");
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
IR_ConstantRef *ref = static_cast<IR_ConstantRef *>(ir->Repr2Ref(v[0]));
if (!ref->is_integer())
throw ir_exp_error("non-integer constant coefficient");
-
+
coef_t c = ref->integer();
if (rel == IR_COND_GE || rel == IR_COND_GT) {
GEQ_Handle h = f_root->add_GEQ();
@@ -92,46 +90,42 @@ void exp2formula(IR_Code *ir,
if (rel == IR_COND_GE)
h.update_const(-c);
else
- h.update_const(-c-1);
- }
- else if (rel == IR_COND_LE || rel == IR_COND_LT) {
+ h.update_const(-c - 1);
+ } else if (rel == IR_COND_LE || rel == IR_COND_LT) {
GEQ_Handle h = f_root->add_GEQ();
h.update_coef(lhs, -1);
if (rel == IR_COND_LE)
h.update_const(c);
else
- h.update_const(c-1);
- }
- else if (rel == IR_COND_EQ) {
+ h.update_const(c - 1);
+ } else if (rel == IR_COND_EQ) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(lhs, 1);
h.update_const(-c);
- }
- else
+ } else
throw std::invalid_argument("unsupported condition type");
-
+
delete v[0];
delete ref;
if (destroy)
delete repr;
-
+
break;
}
-
- case IR_OP_VARIABLE:
- {
+
+ case IR_OP_VARIABLE: {
fprintf(stderr, "IR_OP_VARIABLE\n");
//fprintf(stderr, "repr "); repr->dump(); fflush(stdout);
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
//fprintf(stderr, "v "); v[0]->dump(); fflush(stdout);
IR_ScalarRef *ref = static_cast<IR_ScalarRef *>(ir->Repr2Ref(v[0]));
-
+
//fprintf(stderr, "omegatools.cc calling ref->name()\n");
std::string s = ref->name();
Variable_ID e = find_index(r, s, side);
//fprintf(stderr, "s %s\n", s.c_str());
-
-
+
+
if (e == NULL) { // must be free variable
Free_Var_Decl *t = NULL;
for (unsigned i = 0; i < freevars.size(); i++) {
@@ -141,37 +135,34 @@ void exp2formula(IR_Code *ir,
break;
}
}
-
+
if (t == NULL) {
t = new Free_Var_Decl(s);
freevars.insert(freevars.end(), t);
}
-
+
e = r.get_local(t);
}
-
+
if (rel == IR_COND_GE || rel == IR_COND_GT) {
GEQ_Handle h = f_root->add_GEQ();
h.update_coef(lhs, 1);
h.update_coef(e, -1);
if (rel == IR_COND_GT)
h.update_const(-1);
- }
- else if (rel == IR_COND_LE || rel == IR_COND_LT) {
+ } else if (rel == IR_COND_LE || rel == IR_COND_LT) {
GEQ_Handle h = f_root->add_GEQ();
h.update_coef(lhs, -1);
h.update_coef(e, 1);
if (rel == IR_COND_LT)
h.update_const(-1);
- }
- else if (rel == IR_COND_EQ) {
+ } else if (rel == IR_COND_EQ) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(lhs, 1);
h.update_coef(e, -1);
- }
- else
+ } else
throw std::invalid_argument("unsupported condition type");
-
+
// delete v[0];
delete ref;
if (destroy)
@@ -179,8 +170,7 @@ void exp2formula(IR_Code *ir,
break;
}
- case IR_OP_ASSIGNMENT:
- {
+ case IR_OP_ASSIGNMENT: {
fprintf(stderr, "IR_OP_ASSIGNMENT\n");
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
exp2formula(ir, r, f_root, freevars, v[0], lhs, side, rel, true,
@@ -189,15 +179,14 @@ void exp2formula(IR_Code *ir,
delete repr;
break;
}
-
- case IR_OP_PLUS:
- {
+
+ case IR_OP_PLUS: {
fprintf(stderr, "IR_OP_PLUS\n");
F_Exists *f_exists = f_root->add_exists();
Variable_ID e1 = f_exists->declare(tmp_e());
Variable_ID e2 = f_exists->declare(tmp_e());
F_And *f_and = f_exists->add_and();
-
+
if (rel == IR_COND_GE || rel == IR_COND_GT) {
GEQ_Handle h = f_and->add_GEQ();
h.update_coef(lhs, 1);
@@ -205,24 +194,21 @@ void exp2formula(IR_Code *ir,
h.update_coef(e2, -1);
if (rel == IR_COND_GT)
h.update_const(-1);
- }
- else if (rel == IR_COND_LE || rel == IR_COND_LT) {
+ } else if (rel == IR_COND_LE || rel == IR_COND_LT) {
GEQ_Handle h = f_and->add_GEQ();
h.update_coef(lhs, -1);
h.update_coef(e1, 1);
h.update_coef(e2, 1);
if (rel == IR_COND_LT)
h.update_const(-1);
- }
- else if (rel == IR_COND_EQ) {
+ } else if (rel == IR_COND_EQ) {
EQ_Handle h = f_and->add_EQ();
h.update_coef(lhs, 1);
h.update_coef(e1, -1);
h.update_coef(e2, -1);
- }
- else
+ } else
throw std::invalid_argument("unsupported condition type");
-
+
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
exp2formula(ir, r, f_and, freevars, v[0], e1, side, IR_COND_EQ, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
@@ -232,14 +218,13 @@ void exp2formula(IR_Code *ir,
delete repr;
break;
}
- case IR_OP_MINUS:
- {
+ case IR_OP_MINUS: {
fprintf(stderr, "IR_OP_MINUS\n");
F_Exists *f_exists = f_root->add_exists();
Variable_ID e1 = f_exists->declare(tmp_e());
Variable_ID e2 = f_exists->declare(tmp_e());
F_And *f_and = f_exists->add_and();
-
+
if (rel == IR_COND_GE || rel == IR_COND_GT) {
GEQ_Handle h = f_and->add_GEQ();
h.update_coef(lhs, 1);
@@ -247,48 +232,44 @@ void exp2formula(IR_Code *ir,
h.update_coef(e2, 1);
if (rel == IR_COND_GT)
h.update_const(-1);
- }
- else if (rel == IR_COND_LE || rel == IR_COND_LT) {
+ } else if (rel == IR_COND_LE || rel == IR_COND_LT) {
GEQ_Handle h = f_and->add_GEQ();
h.update_coef(lhs, -1);
h.update_coef(e1, 1);
h.update_coef(e2, -1);
if (rel == IR_COND_LT)
h.update_const(-1);
- }
- else if (rel == IR_COND_EQ) {
+ } else if (rel == IR_COND_EQ) {
EQ_Handle h = f_and->add_EQ();
h.update_coef(lhs, 1);
h.update_coef(e1, -1);
h.update_coef(e2, 1);
- }
- else
+ } else
throw std::invalid_argument("unsupported condition type");
-
+
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
- fprintf(stderr, "IR_OP_MINUS v has %d parts\n", (int)v.size());
- fprintf(stderr, "IR_OP_MINUS recursing 1\n");
+ fprintf(stderr, "IR_OP_MINUS v has %d parts\n", (int) v.size());
+ fprintf(stderr, "IR_OP_MINUS recursing 1\n");
exp2formula(ir, r, f_and, freevars, v[0], e1, side, IR_COND_EQ, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
-
- if (v.size() > 1) {
+
+ if (v.size() > 1) {
fprintf(stderr, "IR_OP_MINUS recursing 2\n"); // dies here because it's unary minus?
exp2formula(ir, r, f_and, freevars, v[1], e2, side, IR_COND_EQ, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
- }
-
-
+ }
+
+
if (destroy)
delete repr;
break;
}
- case IR_OP_MULTIPLY:
- {
+ case IR_OP_MULTIPLY: {
fprintf(stderr, "IR_OP_MULTIPLY\n");
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
-
+
coef_t coef;
CG_outputRepr *term;
if (ir->QueryExpOperation(v[0]) == IR_OP_CONSTANT) {
@@ -297,43 +278,38 @@ void exp2formula(IR_Code *ir,
delete v[0];
delete ref;
term = v[1];
- }
- else if (ir->QueryExpOperation(v[1]) == IR_OP_CONSTANT) {
+ } else if (ir->QueryExpOperation(v[1]) == IR_OP_CONSTANT) {
IR_ConstantRef *ref = static_cast<IR_ConstantRef *>(ir->Repr2Ref(v[1]));
coef = ref->integer();
delete v[1];
delete ref;
term = v[0];
- }
- else
+ } else
throw ir_exp_error("not presburger expression");
-
+
F_Exists *f_exists = f_root->add_exists();
Variable_ID e = f_exists->declare(tmp_e());
F_And *f_and = f_exists->add_and();
-
+
if (rel == IR_COND_GE || rel == IR_COND_GT) {
GEQ_Handle h = f_and->add_GEQ();
h.update_coef(lhs, 1);
h.update_coef(e, -coef);
if (rel == IR_COND_GT)
h.update_const(-1);
- }
- else if (rel == IR_COND_LE || rel == IR_COND_LT) {
+ } else if (rel == IR_COND_LE || rel == IR_COND_LT) {
GEQ_Handle h = f_and->add_GEQ();
h.update_coef(lhs, -1);
h.update_coef(e, coef);
if (rel == IR_COND_LT)
h.update_const(-1);
- }
- else if (rel == IR_COND_EQ) {
+ } else if (rel == IR_COND_EQ) {
EQ_Handle h = f_and->add_EQ();
h.update_coef(lhs, 1);
h.update_coef(e, -coef);
- }
- else
+ } else
throw std::invalid_argument("unsupported condition type");
-
+
exp2formula(ir, r, f_and, freevars, term, e, side, IR_COND_EQ, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
if (destroy)
@@ -341,155 +317,140 @@ void exp2formula(IR_Code *ir,
break;
}
- case IR_OP_DIVIDE:
- {
+ case IR_OP_DIVIDE: {
fprintf(stderr, "IR_OP_DIVIDE\n");
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
-
+
assert(ir->QueryExpOperation(v[1]) == IR_OP_CONSTANT);
IR_ConstantRef *ref = static_cast<IR_ConstantRef *>(ir->Repr2Ref(v[1]));
coef_t coef = ref->integer();
delete v[1];
delete ref;
-
+
F_Exists *f_exists = f_root->add_exists();
Variable_ID e = f_exists->declare(tmp_e());
F_And *f_and = f_exists->add_and();
-
+
if (rel == IR_COND_GE || rel == IR_COND_GT) {
GEQ_Handle h = f_and->add_GEQ();
h.update_coef(lhs, coef);
h.update_coef(e, -1);
if (rel == IR_COND_GT)
h.update_const(-1);
- }
- else if (rel == IR_COND_LE || rel == IR_COND_LT) {
+ } else if (rel == IR_COND_LE || rel == IR_COND_LT) {
GEQ_Handle h = f_and->add_GEQ();
h.update_coef(lhs, -coef);
h.update_coef(e, 1);
if (rel == IR_COND_LT)
h.update_const(-1);
- }
- else if (rel == IR_COND_EQ) {
+ } else if (rel == IR_COND_EQ) {
EQ_Handle h = f_and->add_EQ();
h.update_coef(lhs, coef);
h.update_coef(e, -1);
- }
- else
+ } else
throw std::invalid_argument("unsupported condition type");
-
+
exp2formula(ir, r, f_and, freevars, v[0], e, side, IR_COND_EQ, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
if (destroy)
delete repr;
break;
}
-
- case IR_OP_MOD:
- {
+
+ case IR_OP_MOD: {
fprintf(stderr, "IR_OP_MOD\n");
/* the left hand of a mod can be a var but the right must be a const */
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
-
+
assert(ir->QueryExpOperation(v[1]) == IR_OP_CONSTANT);
IR_ConstantRef *ref = static_cast<IR_ConstantRef *>(ir->Repr2Ref(v[1]));
coef_t coef = ref->integer();
delete v[1];
delete ref;
-
+
F_Exists *f_exists = f_root->add_exists();
Variable_ID e = f_exists->declare(tmp_e());
Variable_ID b = f_exists->declare(tmp_e());
F_And *f_and = f_exists->add_and();
-
-
- if (rel == IR_COND_EQ)
- {
- EQ_Handle h = f_and->add_EQ();
- h.update_coef(lhs, 1);
- h.update_coef(b, coef);
- h.update_coef(e, -1);
- }
-
- else if (rel == IR_COND_GE || rel == IR_COND_GT) {
+
+
+ if (rel == IR_COND_EQ) {
+ EQ_Handle h = f_and->add_EQ();
+ h.update_coef(lhs, 1);
+ h.update_coef(b, coef);
+ h.update_coef(e, -1);
+ } else if (rel == IR_COND_GE || rel == IR_COND_GT) {
//i = CONST alpha + beta && beta >= const ( handled higher up ) && beta < CONST
EQ_Handle h = f_and->add_EQ();
h.update_coef(lhs, 1);
h.update_coef(b, coef);
h.update_coef(e, -1);
-
+
GEQ_Handle k = f_and->add_GEQ();
- k.update_coef(lhs, -1 );
- k.update_const(coef-1);
-
- }
-
- else if (rel == IR_COND_LE || rel == IR_COND_LT) {
+ k.update_coef(lhs, -1);
+ k.update_const(coef - 1);
+
+ } else if (rel == IR_COND_LE || rel == IR_COND_LT) {
//i = CONST alpha + beta && beta <= const ( handled higher up ) && beta >= 0
EQ_Handle h = f_and->add_EQ();
h.update_coef(lhs, 1);
h.update_coef(b, coef);
h.update_coef(e, -1);
-
+
GEQ_Handle k = f_and->add_GEQ();
- k.update_coef(lhs, 1 );
-
+ k.update_coef(lhs, 1);
+
}
-
- exp2formula(ir, r, f_and, freevars, v[0], e, side, IR_COND_EQ, true,
+
+ exp2formula(ir, r, f_and, freevars, v[0], e, side, IR_COND_EQ, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
if (destroy)
delete repr;
-
+
break;
}
-
-
- case IR_OP_POSITIVE:
- {
+
+
+ case IR_OP_POSITIVE: {
fprintf(stderr, "IR_OP_POSITIVE\n");
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
-
+
exp2formula(ir, r, f_root, freevars, v[0], lhs, side, rel, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
-
+
if (destroy)
delete repr;
break;
- }
-
-
- case IR_OP_NEGATIVE:
- {
+ }
+
+
+ case IR_OP_NEGATIVE: {
fprintf(stderr, "IR_OP_NEGATIVE\n");
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
-
+
F_Exists *f_exists = f_root->add_exists();
Variable_ID e = f_exists->declare(tmp_e());
F_And *f_and = f_exists->add_and();
-
+
if (rel == IR_COND_GE || rel == IR_COND_GT) {
GEQ_Handle h = f_and->add_GEQ();
h.update_coef(lhs, 1);
h.update_coef(e, 1);
if (rel == IR_COND_GT)
h.update_const(-1);
- }
- else if (rel == IR_COND_LE || rel == IR_COND_LT) {
+ } else if (rel == IR_COND_LE || rel == IR_COND_LT) {
GEQ_Handle h = f_and->add_GEQ();
h.update_coef(lhs, -1);
h.update_coef(e, -1);
if (rel == IR_COND_LT)
h.update_const(-1);
- }
- else if (rel == IR_COND_EQ) {
+ } else if (rel == IR_COND_EQ) {
EQ_Handle h = f_and->add_EQ();
h.update_coef(lhs, 1);
h.update_coef(e, 1);
- }
- else
+ } else
throw std::invalid_argument("unsupported condition type");
-
+
exp2formula(ir, r, f_and, freevars, v[0], e, side, IR_COND_EQ, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
if (destroy)
@@ -498,13 +459,12 @@ void exp2formula(IR_Code *ir,
}
- case IR_OP_MIN:
- {
+ case IR_OP_MIN: {
fprintf(stderr, "IR_OP_MIN\n");
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
-
+
F_Exists *f_exists = f_root->add_exists();
-
+
if (rel == IR_COND_GE || rel == IR_COND_GT) {
F_Or *f_or = f_exists->add_and()->add_or();
for (int i = 0; i < v.size(); i++) {
@@ -515,69 +475,65 @@ void exp2formula(IR_Code *ir,
h.update_coef(e, -1);
if (rel == IR_COND_GT)
h.update_const(-1);
-
+
exp2formula(ir, r, f_and, freevars, v[i], e, side, IR_COND_EQ, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
}
- }
- else if (rel == IR_COND_LE || rel == IR_COND_LT) {
+ } else if (rel == IR_COND_LE || rel == IR_COND_LT) {
F_And *f_and = f_exists->add_and();
for (int i = 0; i < v.size(); i++) {
- Variable_ID e = f_exists->declare(tmp_e());
+ Variable_ID e = f_exists->declare(tmp_e());
GEQ_Handle h = f_and->add_GEQ();
h.update_coef(lhs, -1);
h.update_coef(e, 1);
if (rel == IR_COND_LT)
h.update_const(-1);
-
+
exp2formula(ir, r, f_and, freevars, v[i], e, side, IR_COND_EQ, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
}
- }
- else if (rel == IR_COND_EQ) {
+ } else if (rel == IR_COND_EQ) {
F_Or *f_or = f_exists->add_and()->add_or();
for (int i = 0; i < v.size(); i++) {
Variable_ID e = f_exists->declare(tmp_e());
F_And *f_and = f_or->add_and();
-
+
EQ_Handle h = f_and->add_EQ();
h.update_coef(lhs, 1);
h.update_coef(e, -1);
-
+
exp2formula(ir, r, f_and, freevars, v[i], e, side, IR_COND_EQ, false,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
-
+
for (int j = 0; j < v.size(); j++)
if (j != i) {
Variable_ID e2 = f_exists->declare(tmp_e());
GEQ_Handle h2 = f_and->add_GEQ();
h2.update_coef(e, -1);
h2.update_coef(e2, 1);
-
- exp2formula(ir, r, f_and, freevars, v[j], e2, side,
+
+ exp2formula(ir, r, f_and, freevars, v[j], e2, side,
IR_COND_EQ, false,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
}
}
-
+
for (int i = 0; i < v.size(); i++)
delete v[i];
- }
- else
+ } else
throw std::invalid_argument("unsupported condition type");
-
+
if (destroy)
delete repr;
break;
}
- case IR_OP_MAX:
- {
+ case IR_OP_MAX: {
fprintf(stderr, "IR_OP_MAX\n");
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
-
+
F_Exists *f_exists = f_root->add_exists();
-
+
if (rel == IR_COND_LE || rel == IR_COND_LT) {
F_Or *f_or = f_exists->add_and()->add_or();
for (int i = 0; i < v.size(); i++) {
@@ -588,336 +544,331 @@ void exp2formula(IR_Code *ir,
h.update_coef(e, 1);
if (rel == IR_COND_LT)
h.update_const(-1);
-
+
exp2formula(ir, r, f_and, freevars, v[i], e, side, IR_COND_EQ, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
}
- }
- else if (rel == IR_COND_GE || rel == IR_COND_GT) {
+ } else if (rel == IR_COND_GE || rel == IR_COND_GT) {
F_And *f_and = f_exists->add_and();
for (int i = 0; i < v.size(); i++) {
- Variable_ID e = f_exists->declare(tmp_e());
+ Variable_ID e = f_exists->declare(tmp_e());
GEQ_Handle h = f_and->add_GEQ();
h.update_coef(lhs, 1);
h.update_coef(e, -1);
if (rel == IR_COND_GT)
h.update_const(-1);
-
+
exp2formula(ir, r, f_and, freevars, v[i], e, side, IR_COND_EQ, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
-
+
}
- }
- else if (rel == IR_COND_EQ) {
+ } else if (rel == IR_COND_EQ) {
F_Or *f_or = f_exists->add_and()->add_or();
for (int i = 0; i < v.size(); i++) {
Variable_ID e = f_exists->declare(tmp_e());
F_And *f_and = f_or->add_and();
-
+
EQ_Handle h = f_and->add_EQ();
h.update_coef(lhs, 1);
h.update_coef(e, -1);
-
+
exp2formula(ir, r, f_and, freevars, v[i], e, side, IR_COND_EQ, false,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
-
+
for (int j = 0; j < v.size(); j++)
if (j != i) {
Variable_ID e2 = f_exists->declare(tmp_e());
GEQ_Handle h2 = f_and->add_GEQ();
h2.update_coef(e, 1);
h2.update_coef(e2, -1);
-
+
exp2formula(ir, r, f_and, freevars, v[j], e2, side, IR_COND_EQ, false,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
}
}
-
+
for (int i = 0; i < v.size(); i++)
delete v[i];
- }
- else
+ } else
throw std::invalid_argument("unsupported condition type");
-
+
if (destroy)
delete repr;
break;
}
-
- case IR_OP_ARRAY_VARIABLE: { // *****
- fprintf(stderr, "\nomegatools.cc IR_OP_ARRAY_VARIABLE ARRAY! \n");
-
- // temp for printing
- //CG_chillRepr *CR = (CG_chillRepr *)repr;
- //fprintf(stderr, "repr "); CR->dump(); fflush(stdout);
-
- //fprintf(stderr, "repr "); repr->dump(); /* printf("\n"); */fflush(stdout);
-
- std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
- IR_Ref *ref = static_cast<IR_ScalarRef *>(ir->Repr2Ref(v[0]));
-
-
- CG_chillRepr *CR = (CG_chillRepr *)v[0]; // cheat for now. we should not know this is a chillRepr
- //fprintf(stderr, "v "); CR->dump(); fflush(stdout);
- //fprintf(stderr, "v "); v[0]->dump(); /* printf("\n"); */ fflush(stdout);
- chillAST_node* node = CR->GetCode();
-
-
- //fprintf(stderr, "\n**** walking parents!\n");
- //std::vector<chillAST_VarDecl*> loopvars;
- //node->gatherLoopIndeces( loopvars );
- //fprintf(stderr, "in omegatools, %d loop vars\n", (int)loopvars.size());
-
-
- std::string s = ref->name();
- //fprintf(stderr, "array variable s is %s\n", s.c_str());
-
- int max_dim = 0;
- bool need_new_fsymbol = false;
- std::set<std::string> vars;
- //fprintf(stderr, "ref->n_dim %d\n", ref->n_dim());
- for (int i = 0; i < ref->n_dim(); i++) {
- //fprintf(stderr, "dimension %d\n", i);
- Relation temp(r.n_inp());
-
- // r is enclosing relation, we build another that will include this
- r.setup_names();
- if (r.is_set())
- for (int j = 1; j <= r.n_set(); j++) {
- temp.name_set_var(j, r.set_var(j)->name());
- }
- else
- for (int j = 1; j <= r.n_inp(); j++) {
- temp.name_input_var(j, r.input_var(j)->name());
- }
-
- F_And *temp_root = temp.add_and();
-
- CG_outputRepr* repr;
- if(dynamic_cast<IR_PointerArrayRef *>(ref) != NULL)
- repr = dynamic_cast<IR_PointerArrayRef *>(ref)->index(i); // i or i+1
- else if(dynamic_cast<IR_ArrayRef *>(ref) != NULL)
- repr = dynamic_cast<IR_ArrayRef *>(ref)->index(i);
-
- std::vector<Free_Var_Decl*> freevars;
- Free_Var_Decl *t = new Free_Var_Decl(s);
- Variable_ID e = temp.get_local(t);
- freevars.insert(freevars.end(), t);
-
- fprintf(stderr, "exp2formula recursing? \n");
- exp2formula(ir, temp, temp_root, freevars, repr, e, side,
- IR_COND_EQ, false, uninterpreted_symbols,
- uninterpreted_symbols_stringrepr);
- fprintf(stderr, "BACK FROM exp2formula recursing? \n");
-
- // temp is relation for the index of the array ??
- for (DNF_Iterator di(temp.query_DNF()); di; di++) {
- for (EQ_Iterator ei = (*di)->EQs(); ei; ei++) {
-
- if ((*ei).get_const() != 0)
- need_new_fsymbol = true;
- for (Constr_Vars_Iter cvi(*ei); cvi; cvi++)
- if ((*cvi).var->kind() == Input_Var) {
- if ((*cvi).var->get_position() > max_dim)
- max_dim = (*cvi).var->get_position();
- vars.insert(
- r.input_var((*cvi).var->get_position())->name());
-
- }
+
+ case IR_OP_ARRAY_VARIABLE: { // *****
+ fprintf(stderr, "\nomegatools.cc IR_OP_ARRAY_VARIABLE ARRAY! \n");
+
+ // temp for printing
+ //CG_chillRepr *CR = (CG_chillRepr *)repr;
+ //fprintf(stderr, "repr "); CR->dump(); fflush(stdout);
+
+ //fprintf(stderr, "repr "); repr->dump(); /* printf("\n"); */fflush(stdout);
+
+ std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr);
+ IR_Ref *ref = static_cast<IR_ScalarRef *>(ir->Repr2Ref(v[0]));
+
+
+ CG_chillRepr *CR = (CG_chillRepr *) v[0]; // cheat for now. we should not know this is a chillRepr
+ //fprintf(stderr, "v "); CR->dump(); fflush(stdout);
+ //fprintf(stderr, "v "); v[0]->dump(); /* printf("\n"); */ fflush(stdout);
+ chillAST_node *node = CR->GetCode();
+
+
+ //fprintf(stderr, "\n**** walking parents!\n");
+ //std::vector<chillAST_VarDecl*> loopvars;
+ //node->gatherLoopIndeces( loopvars );
+ //fprintf(stderr, "in omegatools, %d loop vars\n", (int)loopvars.size());
+
+
+ std::string s = ref->name();
+ //fprintf(stderr, "array variable s is %s\n", s.c_str());
+
+ int max_dim = 0;
+ bool need_new_fsymbol = false;
+ std::set<std::string> vars;
+ //fprintf(stderr, "ref->n_dim %d\n", ref->n_dim());
+ for (int i = 0; i < ref->n_dim(); i++) {
+ //fprintf(stderr, "dimension %d\n", i);
+ Relation temp(r.n_inp());
+
+ // r is enclosing relation, we build another that will include this
+ r.setup_names();
+ if (r.is_set())
+ for (int j = 1; j <= r.n_set(); j++) {
+ temp.name_set_var(j, r.set_var(j)->name());
+ }
+ else
+ for (int j = 1; j <= r.n_inp(); j++) {
+ temp.name_input_var(j, r.input_var(j)->name());
+ }
+
+ F_And *temp_root = temp.add_and();
+
+ CG_outputRepr *repr;
+ if (dynamic_cast<IR_PointerArrayRef *>(ref) != NULL)
+ repr = dynamic_cast<IR_PointerArrayRef *>(ref)->index(i); // i or i+1
+ else if (dynamic_cast<IR_ArrayRef *>(ref) != NULL)
+ repr = dynamic_cast<IR_ArrayRef *>(ref)->index(i);
+
+ std::vector<Free_Var_Decl *> freevars;
+ Free_Var_Decl *t = new Free_Var_Decl(s);
+ Variable_ID e = temp.get_local(t);
+ freevars.insert(freevars.end(), t);
+
+ fprintf(stderr, "exp2formula recursing? \n");
+ exp2formula(ir, temp, temp_root, freevars, repr, e, side,
+ IR_COND_EQ, false, uninterpreted_symbols,
+ uninterpreted_symbols_stringrepr);
+ fprintf(stderr, "BACK FROM exp2formula recursing? \n");
+
+ // temp is relation for the index of the array ??
+ for (DNF_Iterator di(temp.query_DNF()); di; di++) {
+ for (EQ_Iterator ei = (*di)->EQs(); ei; ei++) {
+
+ if ((*ei).get_const() != 0)
+ need_new_fsymbol = true;
+ for (Constr_Vars_Iter cvi(*ei); cvi; cvi++)
+ if ((*cvi).var->kind() == Input_Var) {
+ if ((*cvi).var->get_position() > max_dim)
+ max_dim = (*cvi).var->get_position();
+ vars.insert(
+ r.input_var((*cvi).var->get_position())->name());
+
+ }
+ }
+
}
-
+
+ if (max_dim != ref->n_dim())
+ need_new_fsymbol = true;
}
-
- if (max_dim != ref->n_dim())
- need_new_fsymbol = true;
- }
-
- //fprintf(stderr, "%d vars: ", (int)vars.size());
- //for (int i=0; i<vars.size(); i++) fprintf(stderr, "%s", vars[i].c_str());
- //for (std::set<std::string>::iterator it = vars.begin(); it != vars.end(); it++) {
- // fprintf(stderr, "%s ", (*it).c_str());
- //}
- //fprintf(stderr, "\n");
-
- // r is enclosing relation, we build another that will include
- Variable_ID e = find_index(r, s, side); // s is the array named "index"
-
- std::vector<chillAST_node*> internals = ((CG_chillRepr *)v[0])->getChillCode();
- int numnodes = internals.size(); // always 1?
- std::vector<chillAST_DeclRefExpr *>dres;
- std::vector<chillAST_VarDecl*> decls;
- std::vector<chillAST_VarDecl*> sdecls;
- for (int i=0; i<numnodes; i++) {
- internals[i]->gatherScalarVarDecls(sdecls); // vardecls for scalars
- }
-
- //fprintf(stderr, "%d scalar var decls()\n", sdecls.size());
- //for (int i=0; i<sdecls.size(); i++) {
- // fprintf(stderr, "vardecl %2d: ", i);
- // sdecls[i]->print(); printf("\n"); fflush(stdout);
- //}
-
-
- //fprintf(stderr, "omegatools.cc, exp2formula() NOW WHAT\n");
- //exit(0);
-
- if (e == NULL) { // s must be a free variable
- //fprintf(stderr, "'%s' must be free variable\n\n", s.c_str());
- //fprintf(stderr, "SO WE WILL CREATE A MACRO ???\n");
-
- Free_Var_Decl *t = NULL;
-
- // keep adding underscores until we have created a unique name based on the original
- do {
- s += "_";
- t = NULL;
- for (unsigned i = 0; i < freevars.size(); i++) {
- std::string ss = freevars[i]->base_name();
-
- if (s == ss) {
- t = freevars[i];
- break;
+
+ //fprintf(stderr, "%d vars: ", (int)vars.size());
+ //for (int i=0; i<vars.size(); i++) fprintf(stderr, "%s", vars[i].c_str());
+ //for (std::set<std::string>::iterator it = vars.begin(); it != vars.end(); it++) {
+ // fprintf(stderr, "%s ", (*it).c_str());
+ //}
+ //fprintf(stderr, "\n");
+
+ // r is enclosing relation, we build another that will include
+ Variable_ID e = find_index(r, s, side); // s is the array named "index"
+
+ std::vector<chillAST_node *> internals = ((CG_chillRepr *) v[0])->getChillCode();
+ int numnodes = internals.size(); // always 1?
+ std::vector<chillAST_DeclRefExpr *> dres;
+ std::vector<chillAST_VarDecl *> decls;
+ std::vector<chillAST_VarDecl *> sdecls;
+ for (int i = 0; i < numnodes; i++) {
+ internals[i]->gatherScalarVarDecls(sdecls); // vardecls for scalars
+ }
+
+ //fprintf(stderr, "%d scalar var decls()\n", sdecls.size());
+ //for (int i=0; i<sdecls.size(); i++) {
+ // fprintf(stderr, "vardecl %2d: ", i);
+ // sdecls[i]->print(); printf("\n"); fflush(stdout);
+ //}
+
+
+ //fprintf(stderr, "omegatools.cc, exp2formula() NOW WHAT\n");
+ //exit(0);
+
+ if (e == NULL) { // s must be a free variable
+ //fprintf(stderr, "'%s' must be free variable\n\n", s.c_str());
+ //fprintf(stderr, "SO WE WILL CREATE A MACRO ???\n");
+
+ Free_Var_Decl *t = NULL;
+
+ // keep adding underscores until we have created a unique name based on the original
+ do {
+ s += "_";
+ t = NULL;
+ for (unsigned i = 0; i < freevars.size(); i++) {
+ std::string ss = freevars[i]->base_name();
+
+ if (s == ss) {
+ t = freevars[i];
+ break;
+ }
}
+ } while (t != NULL);
+
+ if (!need_new_fsymbol)
+ t = new Free_Var_Decl(s, ref->n_dim());
+ else
+ t = new Free_Var_Decl(s, max_dim);
+ freevars.insert(freevars.end(), t); // add index_____ to freevars
+
+
+ std::vector<std::string> Vargs; // vector of args
+ std::string args;
+ std::vector<omega::CG_outputRepr *> reprs;
+ std::vector<omega::CG_outputRepr *> reprs2;
+ for (std::set<std::string>::iterator it = vars.begin();
+ it != vars.end(); it++) {
+ if (it == vars.begin())
+ args += "(";
+ else
+ args += ",";
+ args += *it;
+ //fprintf(stderr, "an argument to the macro: %s\n", it->c_str());
+ Vargs.push_back((*it));
+ reprs.push_back(ir->builder()->CreateIdent(*it));
+ reprs2.push_back(ir->builder()->CreateIdent(*it));
}
- } while (t != NULL);
-
- if (!need_new_fsymbol)
- t = new Free_Var_Decl(s, ref->n_dim());
- else
- t = new Free_Var_Decl(s, max_dim);
- freevars.insert(freevars.end(), t); // add index_____ to freevars
-
-
- std::vector< std::string > Vargs; // vector of args
- std::string args;
- std::vector<omega::CG_outputRepr *> reprs;
- std::vector<omega::CG_outputRepr *> reprs2;
- for (std::set<std::string>::iterator it = vars.begin();
- it != vars.end(); it++) {
- if (it == vars.begin())
- args += "(";
- else
- args += ",";
- args += *it;
- //fprintf(stderr, "an argument to the macro: %s\n", it->c_str());
- Vargs.push_back( (*it) );
- reprs.push_back(ir->builder()->CreateIdent(*it));
- reprs2.push_back(ir->builder()->CreateIdent(*it));
+ args += ")";
+
+ //fprintf(stderr, "args '%s'\n", args.c_str());
+ //fprintf(stderr, "Vargs ");
+ //for (int i=0; i<Vargs.size(); i++) fprintf(stderr, "%s ",Vargs[i].c_str());
+ //fprintf(stderr, "\n");
+
+ //fprintf(stderr, "omegatools.cc ir->CreateDefineMacro( s (%s), args(%s), repr)\n", s.c_str(), args.c_str());
+
+ // TODO repr, the rhs of the macro, needs to NOT refer to an actual variable ???
+
+
+ ir->CreateDefineMacro(s, Vargs, repr);
+
+
+
+ // index_(i) uses i outputrepr
+ //fprintf(stderr,"omegatools.cc making uninterpreted symbol %s\n",s.c_str());
+ uninterpreted_symbols.insert( // adding to uninterpreted_symbols
+ std::pair<std::string, std::vector<omega::CG_outputRepr *> >(
+ s, reprs));
+ uninterpreted_symbols_stringrepr.insert( // adding to uninterpreted_symbols_stringrepr
+ std::pair<std::string, std::vector<omega::CG_outputRepr *> >(s, reprs2));
+
+
+ e = r.get_local(t, Input_Tuple);
+
+ if (rel == IR_COND_GE || rel == IR_COND_GT) {
+ GEQ_Handle h = f_root->add_GEQ();
+ h.update_coef(lhs, 1);
+ h.update_coef(e, -1);
+ if (rel == IR_COND_GT)
+ h.update_const(-1);
+ } else if (rel == IR_COND_LE || rel == IR_COND_LT) {
+ GEQ_Handle h = f_root->add_GEQ();
+ h.update_coef(lhs, -1);
+ h.update_coef(e, 1);
+ if (rel == IR_COND_LT)
+ h.update_const(-1);
+ } else if (rel == IR_COND_EQ) {
+ EQ_Handle h = f_root->add_EQ();
+ h.update_coef(lhs, 1);
+ h.update_coef(e, -1);
+ } else
+ throw std::invalid_argument("unsupported condition type");
}
- args += ")";
-
- //fprintf(stderr, "args '%s'\n", args.c_str());
- //fprintf(stderr, "Vargs ");
- //for (int i=0; i<Vargs.size(); i++) fprintf(stderr, "%s ",Vargs[i].c_str());
- //fprintf(stderr, "\n");
-
- //fprintf(stderr, "omegatools.cc ir->CreateDefineMacro( s (%s), args(%s), repr)\n", s.c_str(), args.c_str());
-
- // TODO repr, the rhs of the macro, needs to NOT refer to an actual variable ???
-
-
- ir->CreateDefineMacro(s, Vargs, repr);
-
-
-
- // index_(i) uses i outputrepr
- //fprintf(stderr,"omegatools.cc making uninterpreted symbol %s\n",s.c_str());
- uninterpreted_symbols.insert( // adding to uninterpreted_symbols
- std::pair<std::string, std::vector<omega::CG_outputRepr *> >(
- s, reprs));
- uninterpreted_symbols_stringrepr.insert( // adding to uninterpreted_symbols_stringrepr
- std::pair<std::string, std::vector<omega::CG_outputRepr *> >(s, reprs2));
-
-
- e = r.get_local(t, Input_Tuple);
-
- if (rel == IR_COND_GE || rel == IR_COND_GT) {
- GEQ_Handle h = f_root->add_GEQ();
- h.update_coef(lhs, 1);
- h.update_coef(e, -1);
- if (rel == IR_COND_GT)
- h.update_const(-1);
- } else if (rel == IR_COND_LE || rel == IR_COND_LT) {
- GEQ_Handle h = f_root->add_GEQ();
- h.update_coef(lhs, -1);
- h.update_coef(e, 1);
- if (rel == IR_COND_LT)
- h.update_const(-1);
- } else if (rel == IR_COND_EQ) {
- EQ_Handle h = f_root->add_EQ();
- h.update_coef(lhs, 1);
- h.update_coef(e, -1);
- } else
- throw std::invalid_argument("unsupported condition type");
- }
- // delete v[0];
- delete ref;
- if (destroy) delete repr;
-
- //fprintf(stderr, "FINALLY DONE with IR_OP_ARRAY_VARIABLE\n\n");
- break;
- }
+ // delete v[0];
+ delete ref;
+ if (destroy) delete repr;
+
+ //fprintf(stderr, "FINALLY DONE with IR_OP_ARRAY_VARIABLE\n\n");
+ break;
+ }
- case IR_OP_NULL:
- fprintf(stderr, "IR_OP_NULL\n");
- break;
+ case IR_OP_NULL:
+ fprintf(stderr, "IR_OP_NULL\n");
+ break;
- default:
- throw ir_exp_error("unsupported operand type");
+ default:
+ throw ir_exp_error("unsupported operand type");
}
}
-
-
//-----------------------------------------------------------------------------
// Build dependence relation for two array references.
// -----------------------------------------------------------------------------
-Relation arrays2relation(IR_Code *ir, std::vector<Free_Var_Decl*> &freevars,
+Relation arrays2relation(IR_Code *ir, std::vector<Free_Var_Decl *> &freevars,
const IR_ArrayRef *ref_src, const Relation &IS_w,
const IR_ArrayRef *ref_dst, const Relation &IS_r,
std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols,
std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr) {
-
+
//fprintf(stderr, "arrays2relation()\n");
//fprintf(stderr, "%d freevars\n", freevars.size());
//for (int i=0; i<freevars.size(); i++) fprintf(stderr, "freevar %d %s\n", i, (const char *)(freevars[i]->base_name()));
-
-
+
+
Relation &IS1 = const_cast<Relation &>(IS_w);
Relation &IS2 = const_cast<Relation &>(IS_r);
-
+
//Relation *helper;
//helper = new Relation(IS1); fprintf(stderr, "IS1 "); helper->print(); fflush(stdout);
//helper = new Relation(IS2); fprintf(stderr, "IS2 "); helper->print(); fflush(stdout);
-
+
Relation r(IS1.n_set(), IS2.n_set());
//helper = new Relation(r); fprintf(stderr, "r "); helper->print(); fflush(stdout);
-
+
for (int i = 1; i <= IS1.n_set(); i++)
r.name_input_var(i, IS1.set_var(i)->name());
-
+
for (int i = 1; i <= IS2.n_set(); i++)
- r.name_output_var(i, IS2.set_var(i)->name()+"'");
-
+ r.name_output_var(i, IS2.set_var(i)->name() + "'");
+
//fprintf(stderr, "omegatools.cc sym_src\n");
IR_Symbol *sym_src = ref_src->symbol();
IR_Symbol *sym_dst = ref_dst->symbol();
//fprintf(stderr, "omegatools.cc going to do IR_Symbol operator==\n");
//fprintf(stderr, "omegatools.cc comparing symbol 0x%x to symbol 0x%x\n", sym_src, sym_dst);
-
+
//if (!(*sym_src == *sym_dst)) fprintf(stderr, "!(*sym_src == *sym_dst)\n");
-
+
//fprintf(stderr, "calling !=\n");
//if (*sym_src != *sym_dst) fprintf(stderr, "omegatools.cc (*sym_src != *sym_dst) TRUE\n");
//else fprintf(stderr, "omegatools.cc (*sym_src != *sym_dst) FALSE\n");
-
+
//fprintf(stderr, "calling ==\n");
//if ((*sym_src == *sym_dst)) fprintf(stderr, "(*sym_src == *sym_dst)) TRUE \n");
//else fprintf(stderr, "(*sym_src == *sym_dst) FALSE \n");
-
+
if (*sym_src != *sym_dst) {
//if (!(*sym_src == *sym_dst)) {
//fprintf(stderr, "False Relation\n");
@@ -925,35 +876,34 @@ Relation arrays2relation(IR_Code *ir, std::vector<Free_Var_Decl*> &freevars,
delete sym_src;
delete sym_dst;
return r;
- }
- else {
+ } else {
delete sym_src;
delete sym_dst;
}
-
+
//fprintf(stderr, "f_root\n");
F_And *f_root = r.add_and();
-
+
//fprintf(stderr, "omegatools.cc ref_src->n_dim() %d\n", ref_src->n_dim());
for (int i = 0; i < ref_src->n_dim(); i++) {
//fprintf(stderr, "arrays2 i %d\n", i);
-
+
F_Exists *f_exists = f_root->add_exists();
Variable_ID e1 = f_exists->declare(tmp_e());
Variable_ID e2 = f_exists->declare(tmp_e());
F_And *f_and = f_exists->add_and();
-
+
CG_outputRepr *repr_src = ref_src->index(i);
CG_outputRepr *repr_dst = ref_dst->index(i);
-
+
bool has_complex_formula = false;
-
+
if (ir->QueryExpOperation(repr_src) == IR_OP_ARRAY_VARIABLE
|| ir->QueryExpOperation(repr_dst) == IR_OP_ARRAY_VARIABLE)
has_complex_formula = true;
-
+
if (!has_complex_formula) {
-
+
try {
exp2formula(ir, r, f_and, freevars, repr_src, e1, 'w', IR_COND_EQ, false,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
@@ -963,7 +913,7 @@ Relation arrays2relation(IR_Code *ir, std::vector<Free_Var_Decl*> &freevars,
catch (const ir_exp_error &e) {
has_complex_formula = true;
}
-
+
if (!has_complex_formula) {
EQ_Handle h = f_and->add_EQ();
h.update_coef(e1, 1);
@@ -975,15 +925,15 @@ Relation arrays2relation(IR_Code *ir, std::vector<Free_Var_Decl*> &freevars,
delete repr_src;
delete repr_dst;
}
-
+
// add iteration space restriction
r = Restrict_Domain(r, copy(IS1));
r = Restrict_Range(r, copy(IS2));
-
+
// reset the output variable names lost in restriction
for (int i = 1; i <= IS2.n_set(); i++)
- r.name_output_var(i, IS2.set_var(i)->name()+"'");
-
+ r.name_output_var(i, IS2.set_var(i)->name() + "'");
+
//helper = new Relation(r); fprintf(stderr, "r "); helper->print(); fflush(stdout);
//fprintf(stderr, "leaving arrays2relation\n");
return r;
@@ -994,42 +944,42 @@ Relation arrays2relation(IR_Code *ir, std::vector<Free_Var_Decl*> &freevars,
// Convert array dependence relation into set of dependence vectors, assuming
// ref_w is lexicographically before ref_r in the source code.
// -----------------------------------------------------------------------------
-std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relation2dependences (
- const IR_ArrayRef *ref_src,
- const IR_ArrayRef *ref_dst,
- const Relation &r) {
+std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relation2dependences(
+ const IR_ArrayRef *ref_src,
+ const IR_ArrayRef *ref_dst,
+ const Relation &r) {
//fprintf(stderr, "relation2dependences()\n");
assert(r.n_inp() == r.n_out());
-
- std::vector<DependenceVector> dependences1, dependences2;
+
+ std::vector<DependenceVector> dependences1, dependences2;
//std::vector<DependenceVector*> dep1, dep2;
std::stack<DependenceLevel> working;
working.push(DependenceLevel(r, r.n_inp()));
-
+
while (!working.empty()) {
//fprintf(stderr, "!empty size %d\n", working.size());
-
+
DependenceLevel dep = working.top();
working.pop();
-
+
//if (!dep.r.is_satisfiable()) fprintf(stderr, "NOT dep.r.is_satisfiable()\n");
//else fprintf(stderr, " dep.r.is_satisfiable()\n");
-
+
// No dependence exists, move on.
- if (!dep.r.is_satisfiable()) {
+ if (!dep.r.is_satisfiable()) {
//fprintf(stderr, "No dependence exists, move on.\n");
continue;
}
-
+
//fprintf(stderr, "satisfiable\n");
//fprintf(stderr, "dep.level %d r.n_inp() %d\n", dep.level, r.n_inp());
if (dep.level == r.n_inp()) {
//fprintf(stderr, "dep.level == r.n_inp()\n");
DependenceVector dv;
-
+
//fprintf(stderr, "\ndv created in if ***\n");
//DependenceVector *dv2 = new DependenceVector;
-
+
//fprintf(stderr, "for loop independent dependence dep.dir %d\n", dep.dir);
// for loop independent dependence, use lexical order to
// determine the correct source and destination
@@ -1039,59 +989,54 @@ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relatio
//fprintf(stderr, "trivial\n");
continue; // trivial self zero-dependence
}
-
+
if (ref_src->is_write()) {
if (ref_dst->is_write())
dv.type = DEP_W2W;
else
dv.type = DEP_W2R;
- }
- else {
+ } else {
if (ref_dst->is_write())
dv.type = DEP_R2W;
else
dv.type = DEP_R2R;
}
-
- }
- else if (dep.dir == 1) {
+
+ } else if (dep.dir == 1) {
//fprintf(stderr, "dep.dir == 1\n");
if (ref_src->is_write()) {
if (ref_dst->is_write())
dv.type = DEP_W2W;
else
dv.type = DEP_W2R;
- }
- else {
+ } else {
if (ref_dst->is_write())
dv.type = DEP_R2W;
else
dv.type = DEP_R2R;
}
- }
- else { // dep.dir == -1
+ } else { // dep.dir == -1
//fprintf(stderr, "dep.dir == -1\n");
if (ref_dst->is_write()) {
if (ref_src->is_write())
dv.type = DEP_W2W;
else
dv.type = DEP_W2R;
- }
- else {
+ } else {
if (ref_src->is_write())
dv.type = DEP_R2W;
else
dv.type = DEP_R2R;
}
}
-
+
dv.lbounds = dep.lbounds;
dv.ubounds = dep.ubounds;
-
+
//fprintf(stderr, "omegatools.cc calling ref_src->symbol();\n");
dv.sym = ref_src->symbol();
//fprintf(stderr, "dv.sym = %p\n", dv.sym);
-
+
//fprintf(stderr, "symbol %s ADDING A DEPENDENCE OF TYPE ", dv.sym->name().c_str());
//switch (dv.type) {
//case DEP_W2W: fprintf(stderr, "DEP_W2W to "); break;
@@ -1102,12 +1047,12 @@ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relatio
//}
//if (dep.dir == 0 || dep.dir == 1) fprintf(stderr, "dependences1\n");
//else fprintf(stderr, "dependences2\n");
-
+
if (dep.dir == 0 || dep.dir == 1) {
//fprintf(stderr, "pushing dv\n");
dependences1.push_back(dv);
//fprintf(stderr, "DONE pushing dv\n");
-
+
//fprintf(stderr, "now %d dependences1\n", dependences1.size() );
//for (int i=0; i<dependences1.size(); i++) {
// fprintf(stderr, "dependences1[%d]: ", i );
@@ -1116,12 +1061,11 @@ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relatio
// fprintf(stderr, "%s\n", dependences1[i].sym->name().c_str());
//}
//fprintf(stderr, "\n");
- }
- else {
+ } else {
//fprintf(stderr, "pushing dv\n");
dependences2.push_back(dv);
//fprintf(stderr, "DONE pushing dv\n");
-
+
//fprintf(stderr, "now %d dependences2\n", dependences2.size() );
//for (int i=0; i<dependences2.size(); i++) {
// fprintf(stderr, "dependences2[%d]: ", i);
@@ -1131,113 +1075,111 @@ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relatio
//}
//fprintf(stderr, "\n");
}
-
+
//fprintf(stderr, "dv goes out of scope ***\n");
- }
- else {
+ } else {
//fprintf(stderr, "now work on the next dimension level\n");
// now work on the next dimension level
int level = ++dep.level;
//fprintf(stderr, "level %d\n", level);
-
+
coef_t lbound, ubound;
Relation delta = Deltas(copy(dep.r));
//delta.print(); fflush(stdout);
delta.query_variable_bounds(delta.set_var(level), lbound, ubound);
//fprintf(stderr, "delta lb " coef_fmt " 0x%llx ub " coef_fmt " 0x%llx\n", lbound,lbound,ubound,ubound);
-
-
+
+
if (dep.dir == 0) {
//fprintf(stderr, "dep.dir == 0\n");
if (lbound > 0) {
dep.dir = 1;
- dep.lbounds[level-1] = lbound;
- dep.ubounds[level-1] = ubound;
-
+ dep.lbounds[level - 1] = lbound;
+ dep.ubounds[level - 1] = ubound;
+
//fprintf(stderr, "push 1\n");
working.push(dep);
- }
- else if (ubound < 0) {
+ } else if (ubound < 0) {
dep.dir = -1;
- dep.lbounds[level-1] = -ubound;
- dep.ubounds[level-1] = -lbound;
-
+ dep.lbounds[level - 1] = -ubound;
+ dep.ubounds[level - 1] = -lbound;
+
//fprintf(stderr, "push 2\n");
working.push(dep);
- }
- else {
+ } else {
// split the dependence vector into flow- and anti-dependence
// for the first non-zero distance, also separate zero distance
// at this level.
{
DependenceLevel dep2 = dep;
-
- dep2.lbounds[level-1] = 0;
- dep2.ubounds[level-1] = 0;
-
+
+ dep2.lbounds[level - 1] = 0;
+ dep2.ubounds[level - 1] = 0;
+
F_And *f_root = dep2.r.and_with_and();
EQ_Handle h = f_root->add_EQ();
h.update_coef(dep2.r.input_var(level), 1);
h.update_coef(dep2.r.output_var(level), -1);
-
+
//fprintf(stderr, "push 3\n");
working.push(dep2);
}
-
+
//fprintf(stderr, "lbound %lld 0x%llx\n", lbound, lbound);
//if (lbound < 0LL) fprintf(stderr, "lbound < 0LL\n");
//if (*ref_src != *ref_dst) fprintf(stderr, "(*ref_src != *ref_dst)\n");
//else fprintf(stderr, "(*ref_src EQUAL *ref_dst)\n");
-
+
if (lbound < 0LL && (*ref_src != *ref_dst)) { // c == c
DependenceLevel dep2 = dep;
-
+
F_And *f_root = dep2.r.and_with_and();
GEQ_Handle h = f_root->add_GEQ();
h.update_coef(dep2.r.input_var(level), 1);
h.update_coef(dep2.r.output_var(level), -1);
h.update_const(-1);
-
+
// get tighter bounds under new constraints
coef_t lbound, ubound;
delta = Deltas(copy(dep2.r));
delta.query_variable_bounds(delta.set_var(level),
lbound, ubound);
-
- dep2.dir = -1;
- dep2.lbounds[level-1] = std::max(-ubound,static_cast<coef_t>(1)); // use max() to avoid Omega retardedness
- dep2.ubounds[level-1] = -lbound;
-
+
+ dep2.dir = -1;
+ dep2.lbounds[level - 1] = std::max(-ubound,
+ static_cast<coef_t>(1)); // use max() to avoid Omega retardedness
+ dep2.ubounds[level - 1] = -lbound;
+
//fprintf(stderr, "push 4\n");
working.push(dep2);
}
-
+
//fprintf(stderr, "ubound %d\n", ubound);
if (ubound > 0) {
DependenceLevel dep2 = dep;
-
+
F_And *f_root = dep2.r.and_with_and();
GEQ_Handle h = f_root->add_GEQ();
h.update_coef(dep2.r.input_var(level), -1);
h.update_coef(dep2.r.output_var(level), 1);
h.update_const(-1);
-
+
// get tighter bonds under new constraints
coef_t lbound, ubound;
delta = Deltas(copy(dep2.r));
delta.query_variable_bounds(delta.set_var(level),
lbound, ubound);
dep2.dir = 1;
- dep2.lbounds[level-1] = std::max(lbound,static_cast<coef_t>(1)); // use max() to avoid Omega retardness
- dep2.ubounds[level-1] = ubound;
-
+ dep2.lbounds[level - 1] = std::max(lbound, static_cast<coef_t>(1)); // use max() to avoid Omega retardness
+ dep2.ubounds[level - 1] = ubound;
+
//fprintf(stderr, "push 5\n");
working.push(dep2);
}
}
}
- // now deal with dependence vector with known direction
- // determined at previous levels
+ // now deal with dependence vector with known direction
+ // determined at previous levels
else {
//fprintf(stderr, "else messy\n");
// For messy bounds, further test to see if the dependence distance
@@ -1250,7 +1192,7 @@ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relatio
h.update_coef(t.input_var(level), 1);
h.update_coef(t.output_var(level), -1);
h.update_const(-1);
-
+
if (!t.is_satisfiable()) {
lbound = 0;
}
@@ -1262,13 +1204,13 @@ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relatio
h.update_coef(t.input_var(level), -1);
h.update_coef(t.output_var(level), 1);
h.update_const(-1);
-
+
if (!t.is_satisfiable()) {
ubound = 0;
}
}
}
-
+
// Same thing as above, test to see if zero dependence
// distance possible.
if (lbound == 0 || ubound == 0) {
@@ -1277,7 +1219,7 @@ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relatio
EQ_Handle h = f_root->add_EQ();
h.update_coef(t.input_var(level), 1);
h.update_coef(t.output_var(level), -1);
-
+
if (!t.is_satisfiable()) {
if (lbound == 0)
lbound = 1;
@@ -1285,31 +1227,30 @@ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relatio
ubound = -1;
}
}
-
+
if (dep.dir == -1) {
- dep.lbounds[level-1] = -ubound;
- dep.ubounds[level-1] = -lbound;
- }
- else { // dep.dir == 1
- dep.lbounds[level-1] = lbound;
- dep.ubounds[level-1] = ubound;
+ dep.lbounds[level - 1] = -ubound;
+ dep.ubounds[level - 1] = -lbound;
+ } else { // dep.dir == 1
+ dep.lbounds[level - 1] = lbound;
+ dep.ubounds[level - 1] = ubound;
}
-
+
//fprintf(stderr, "push 6\n");
working.push(dep);
}
}
//fprintf(stderr, "at bottom, size %d\n", working.size());
-
+
}
-
+
//fprintf(stderr, "leaving relation2dependences, %d and %d dependences\n", dependences1.size(), dependences2.size());
-
-
+
+
//for (int i=0; i<dependences1.size(); i++) {
//fprintf(stderr, "dependences1[%d]: ", i);
//fprintf(stderr, "symbol %s\n", dependences1[i].sym->name().c_str());
-
+
//fprintf(stderr, "symbol %s HAS A left DEPENDENCE OF TYPE ", dependences1[i].sym->name().c_str());
//switch (dependences1[i].type) {
//case DEP_W2W: fprintf(stderr, "DEP_W2W\n"); break;
@@ -1319,10 +1260,10 @@ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relatio
//default: fprintf(stderr, "DEP_UNKNOWN\n"); break;
//}
//}
-
-
+
+
//for (int i=0; i<dependences2.size(); i++) {
-
+
//fprintf(stderr, "symbol %s HAS A right DEPENDENCE OF TYPE ", dependences2[i].sym->name().c_str());
//switch (dependences2[i].type) {
//case DEP_W2W: fprintf(stderr, "DEP_W2W\n"); break;
@@ -1332,9 +1273,9 @@ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relatio
//default: fprintf(stderr, "DEP_UNKNOWN\n"); break;
//}
//}
-
-
-
+
+
+
return std::make_pair(dependences1, dependences2);
}
@@ -1345,19 +1286,17 @@ std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > relatio
//-----------------------------------------------------------------------------
void exp2constraint(IR_Code *ir, Relation &r, F_And *f_root,
std::vector<Free_Var_Decl *> &freevars,
- CG_outputRepr *repr,
+ CG_outputRepr *repr,
bool destroy,
std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols,
- std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr)
-{
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr) {
IR_CONDITION_TYPE cond = ir->QueryBooleanExpOperation(repr);
switch (cond) {
- case IR_COND_LT:
- case IR_COND_LE:
- case IR_COND_EQ:
- case IR_COND_GT:
- case IR_COND_GE:
- {
+ case IR_COND_LT:
+ case IR_COND_LE:
+ case IR_COND_EQ:
+ case IR_COND_GT:
+ case IR_COND_GE: {
F_Exists *f_exist = f_root->add_exists();
Variable_ID e = f_exist->declare();
F_And *f_and = f_exist->add_and();
@@ -1366,13 +1305,12 @@ void exp2constraint(IR_Code *ir, Relation &r, F_And *f_root,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
exp2formula(ir, r, f_and, freevars, op[1], e, 's', cond, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
-
+
if (destroy)
delete repr;
break;
}
- case IR_COND_NE:
- {
+ case IR_COND_NE: {
F_Exists *f_exist = f_root->add_exists();
Variable_ID e = f_exist->declare();
F_Or *f_or = f_exist->add_or();
@@ -1382,19 +1320,19 @@ void exp2constraint(IR_Code *ir, Relation &r, F_And *f_root,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
exp2formula(ir, r, f_and, freevars, op[1], e, 's', IR_COND_GT, false,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
-
+
f_and = f_or->add_and();
exp2formula(ir, r, f_and, freevars, op[0], e, 's', IR_COND_EQ, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
exp2formula(ir, r, f_and, freevars, op[1], e, 's', IR_COND_LT, true,
uninterpreted_symbols, uninterpreted_symbols_stringrepr);
-
+
if (destroy)
delete repr;
break;
- }
- default:
- throw ir_exp_error("unrecognized conditional expression");
+ }
+ default:
+ throw ir_exp_error("unrecognized conditional expression");
}
}
@@ -1443,20 +1381,19 @@ void exp2constraint(IR_Code *ir, Relation &r, F_And *f_root,
// Determine whether the loop (starting from 0) in the iteration space
// has only one iteration.
//-----------------------------------------------------------------------------
-bool is_single_loop_iteration(const Relation &r,
- int level,
+bool is_single_loop_iteration(const Relation &r,
+ int level,
const Relation &known) {
int n = r.n_set();
Relation r1;
- if(n > known.n_set()) {
+ if (n > known.n_set()) {
r1 = Intersection(copy(r), Extend_Set(copy(known), n - known.n_set()));
- }
- else{
+ } else {
r1 = Intersection(copy(known), Extend_Set(copy(r), known.n_set() - n));
n = known.n_set();
}
-
-
+
+
Relation mapping(n, n);
F_And *f_root = mapping.add_and();
for (int i = 1; i <= level; i++) {
@@ -1466,7 +1403,7 @@ bool is_single_loop_iteration(const Relation &r,
}
r1 = Range(Restrict_Domain(mapping, r1));
r1.simplify();
-
+
Variable_ID v = r1.set_var(level);
for (DNF_Iterator di(r1.query_DNF()); di; di++) {
bool is_single = false;
@@ -1475,31 +1412,29 @@ bool is_single_loop_iteration(const Relation &r,
is_single = true;
break;
}
-
+
if (!is_single)
return false;
}
-
+
return true;
}
-
-
bool is_single_iteration(const Relation &r, int dim) {
assert(r.is_set());
const int n = r.n_set();
-
+
if (dim >= n)
return true;
-
+
Relation bound = get_loop_bound(r, dim);
-
+
// if (!bound.has_single_conjunct())
// return false;
-
+
// Conjunct *c = bound.query_DNF()->single_conjunct();
-
+
for (DNF_Iterator di(bound.query_DNF()); di; di++) {
bool is_single = false;
for (EQ_Iterator ei((*di)->EQs()); ei; ei++)
@@ -1507,50 +1442,50 @@ bool is_single_iteration(const Relation &r, int dim) {
is_single = true;
break;
}
-
+
if (!is_single)
return false;
}
-
+
return true;
-
-
-
-
+
+
+
+
// Relation r = copy(r_);
// const int n = r.n_set();
-
+
// if (dim >= n)
// return true;
-
+
// Relation bound = get_loop_bound(r, dim);
// bound = Approximate(bound);
// Conjunct *c = bound.query_DNF()->single_conjunct();
-
+
// return c->n_GEQs() == 0;
-
-
-
-
-
+
+
+
+
+
// Relation r = copy(r_);
// r.simplify();
// const int n = r.n_set();
-
+
// if (dim >= n)
// return true;
-
+
// for (DNF_Iterator i(r.query_DNF()); i; i++) {
// std::vector<bool> is_single(n);
// for (int j = 0; j < dim; j++)
// is_single[j] = true;
// for (int j = dim; j < n; j++)
// is_single[j] = false;
-
+
// bool found_new_single = true;
// while (found_new_single) {
// found_new_single = false;
-
+
// for (EQ_Iterator j = (*i)->EQs(); j; j++) {
// int saved_pos = -1;
// for (Constr_Vars_Iter k(*j); k; k++)
@@ -1564,21 +1499,21 @@ bool is_single_iteration(const Relation &r, int dim) {
// break;
// }
// }
-
+
// if (saved_pos != -1) {
// is_single[saved_pos] = true;
// found_new_single = true;
// }
// }
-
+
// if (is_single[dim])
// break;
// }
-
+
// if (!is_single[dim])
// return false;
// }
-
+
// return true;
}
@@ -1587,23 +1522,22 @@ bool is_single_iteration(const Relation &r, int dim) {
//-----------------------------------------------------------------------------
void assign_const(Relation &r, int dim, int val) {
const int n = r.n_out();
-
+
Relation mapping(n, n);
F_And *f_root = mapping.add_and();
-
+
for (int i = 1; i <= n; i++) {
- if (i != dim+1) {
+ if (i != dim + 1) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(mapping.output_var(i), 1);
h.update_coef(mapping.input_var(i), -1);
- }
- else {
+ } else {
EQ_Handle h = f_root->add_EQ();
h.update_coef(mapping.output_var(i), 1);
h.update_const(-val);
}
}
-
+
r = Composition(mapping, r);
}
@@ -1611,46 +1545,42 @@ void assign_const(Relation &r, int dim, int val) {
int get_const(const Relation &r, int dim, Var_Kind type) {
// Relation rr = copy(r);
Relation &rr = const_cast<Relation &>(r);
-
+
Variable_ID v;
switch (type) {
// case Set_Var:
// v = rr.set_var(dim+1);
// break;
- case Input_Var:
- v = rr.input_var(dim+1);
- break;
- case Output_Var:
- v = rr.output_var(dim+1);
- break;
- default:
- throw std::invalid_argument("unsupported variable type");
+ case Input_Var:
+ v = rr.input_var(dim + 1);
+ break;
+ case Output_Var:
+ v = rr.output_var(dim + 1);
+ break;
+ default:
+ throw std::invalid_argument("unsupported variable type");
}
-
+
for (DNF_Iterator di(rr.query_DNF()); di; di++)
for (EQ_Iterator ei = (*di)->EQs(); ei; ei++)
if ((*ei).is_const(v))
return (*ei).get_const();
-
+
throw std::runtime_error("cannot get variable's constant value");
}
-
-
-
-
//---------------------------------------------------------------------------
// Get the bound for a specific loop.
//---------------------------------------------------------------------------
Relation get_loop_bound(const Relation &r, int dim) {
assert(r.is_set());
const int n = r.n_set();
-
+
// Relation r1 = project_onto_levels(copy(r), dim+1, true);
- Relation mapping(n,n);
+ Relation mapping(n, n);
F_And *f_root = mapping.add_and();
- for (int i = 1; i <= dim+1; i++) {
+ for (int i = 1; i <= dim + 1; i++) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(mapping.input_var(i), 1);
h.update_coef(mapping.output_var(i), -1);
@@ -1659,26 +1589,25 @@ Relation get_loop_bound(const Relation &r, int dim) {
for (int i = 1; i <= n; i++)
r1.name_set_var(i, const_cast<Relation &>(r).set_var(i)->name());
r1.setup_names();
- Relation r2 = Project(copy(r1), dim+1, Set_Var);
-
+ Relation r2 = Project(copy(r1), dim + 1, Set_Var);
+
return Gist(r1, r2, 1);
}
-
Relation get_loop_bound(const Relation &r, int level, const Relation &known) {
int n1 = r.n_set();
int n = n1;
Relation r1;
- if(n > known.n_set())
+ if (n > known.n_set())
r1 = Intersection(copy(r),
Extend_Set(copy(known), n - known.n_set()));
- else{
+ else {
r1 = Intersection(copy(known),
Extend_Set(copy(r), known.n_set() - n));
n = known.n_set();
}
-
+
Relation mapping(n, n);
F_And *f_root = mapping.add_and();
for (int i = 1; i <= level; i++) {
@@ -1689,20 +1618,19 @@ Relation get_loop_bound(const Relation &r, int level, const Relation &known) {
r1 = Range(Restrict_Domain(mapping, r1));
Relation r2 = Project(copy(r1), level, Set_Var);
r1 = Gist(r1, r2, 1);
-
+
for (int i = 1; i <= n1; i++)
r1.name_set_var(i, const_cast<Relation &>(r).set_var(i)->name());
r1.setup_names();
-
+
return r1;
}
-
Relation get_max_loop_bound(const std::vector<Relation> &r, int dim) {
if (r.size() == 0)
return Relation::Null();
-
+
const int n = r[0].n_set();
Relation res(Relation::False(n));
for (int i = 0; i < r.size(); i++) {
@@ -1710,16 +1638,16 @@ Relation get_max_loop_bound(const std::vector<Relation> &r, int dim) {
if (t.is_satisfiable())
res = Union(get_loop_bound(t, dim), res);
}
-
+
res.simplify();
-
+
return res;
}
Relation get_min_loop_bound(const std::vector<Relation> &r, int dim) {
if (r.size() == 0)
return Relation::Null();
-
+
const int n = r[0].n_set();
Relation res(Relation::True(n));
for (int i = 0; i < r.size(); i++) {
@@ -1727,9 +1655,9 @@ Relation get_min_loop_bound(const std::vector<Relation> &r, int dim) {
if (t.is_satisfiable())
res = Intersection(get_loop_bound(t, dim), res);
}
-
+
res.simplify();
-
+
return res;
}
@@ -1751,47 +1679,43 @@ void add_loop_stride(Relation &r, const Relation &bound_, int dim, int stride) {
stride_eq.update_coef(e1, 1);
stride_eq.update_coef(e2, stride);
if (!r.is_set())
- stride_eq.update_coef(r.output_var(dim+1), -1);
+ stride_eq.update_coef(r.output_var(dim + 1), -1);
else
- stride_eq.update_coef(r.set_var(dim+1), -1);
+ stride_eq.update_coef(r.set_var(dim + 1), -1);
F_Or *f_or = f_and->add_or();
-
+
for (GEQ_Iterator gi = (*di)->GEQs(); gi; gi++) {
- if ((*gi).get_coef(bound.set_var(dim+1)) > 0) {
+ if ((*gi).get_coef(bound.set_var(dim + 1)) > 0) {
// copy the lower bound constraint
EQ_Handle h1 = f_or->add_and()->add_EQ();
GEQ_Handle h2 = f_and->add_GEQ();
for (Constr_Vars_Iter ci(*gi); ci; ci++) {
switch ((*ci).var->kind()) {
// case Set_Var:
- case Input_Var:
- {
+ case Input_Var: {
int pos = (*ci).var->get_position();
if (pos == dim + 1) {
h1.update_coef(e1, (*ci).coef);
h2.update_coef(e1, (*ci).coef);
- }
- else {
+ } else {
if (!r.is_set()) {
h1.update_coef(r.output_var(pos), (*ci).coef);
h2.update_coef(r.output_var(pos), (*ci).coef);
- }
- else {
+ } else {
h1.update_coef(r.set_var(pos), (*ci).coef);
h2.update_coef(r.set_var(pos), (*ci).coef);
- }
+ }
}
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = (*ci).var->get_global_var();
h1.update_coef(r.get_local(g, (*ci).var->function_of()), (*ci).coef);
h2.update_coef(r.get_local(g, (*ci).var->function_of()), (*ci).coef);
break;
}
- default:
- break;
+ default:
+ break;
}
}
h1.update_const((*gi).get_const());
@@ -1802,35 +1726,35 @@ void add_loop_stride(Relation &r, const Relation &bound_, int dim, int stride) {
}
-bool is_inner_loop_depend_on_level(const Relation &r,
+bool is_inner_loop_depend_on_level(const Relation &r,
int level,
const Relation &known) {
-
+
Relation r1;
- if(r.n_set() > known.n_set())
+ if (r.n_set() > known.n_set())
r1 = Intersection(copy(r),
Extend_Set(copy(known), r.n_set() - known.n_set()));
else
r1 = Intersection(copy(known),
Extend_Set(copy(r), known.n_set() - r.n_set()));
-
+
Relation r2 = copy(r1);
- for (int i = level+1; i <= r2.n_set(); i++)
+ for (int i = level + 1; i <= r2.n_set(); i++)
r2 = Project(r2, r2.set_var(i));
r2.simplify(2, 4);
Relation r3 = Gist(r1, r2);
-
+
Variable_ID v = r3.set_var(level);
for (DNF_Iterator di(r3.query_DNF()); di; di++) {
for (EQ_Iterator ei = (*di)->EQs(); ei; ei++)
if ((*ei).get_coef(v) != 0)
return true;
-
+
for (GEQ_Iterator gi = (*di)->GEQs(); gi; gi++)
if ((*gi).get_coef(v) != 0)
return true;
}
-
+
return false;
}
@@ -1846,14 +1770,14 @@ bool is_inner_loop_depend_on_level(const Relation &r,
Relation adjust_loop_bound(const Relation &r, int level, int adjustment) {
if (adjustment == 0)
return copy(r);
-
+
const int n = r.n_set();
Relation r1 = copy(r);
- for (int i = level+1; i <= r1.n_set(); i++)
+ for (int i = level + 1; i <= r1.n_set(); i++)
r1 = Project(r1, r1.set_var(i));
r1.simplify(2, 4);
Relation r2 = Gist(copy(r), copy(r1));
-
+
Relation mapping(n, n);
F_And *f_root = mapping.add_and();
for (int i = 1; i <= n; i++)
@@ -1862,17 +1786,16 @@ Relation adjust_loop_bound(const Relation &r, int level, int adjustment) {
h.update_coef(mapping.input_var(level), -1);
h.update_coef(mapping.output_var(level), 1);
h.update_const(static_cast<coef_t>(adjustment));
- }
- else {
+ } else {
EQ_Handle h = f_root->add_EQ();
h.update_coef(mapping.input_var(i), -1);
h.update_coef(mapping.output_var(i), 1);
}
-
+
r2 = Range(Restrict_Domain(mapping, r2));
r1 = Intersection(r1, r2);
r1.simplify();
-
+
for (int i = 1; i <= n; i++)
r1.name_set_var(i, const_cast<Relation &>(r).set_var(i)->name());
r1.setup_names();
@@ -2111,28 +2034,27 @@ Relation adjust_loop_bound(const Relation &r, int level, int adjustment) {
//-----------------------------------------------------------------------------
Relation permute_relation(const std::vector<int> &pi) {
const int n = pi.size();
-
+
Relation r(n, n);
F_And *f_root = r.add_and();
-
- for (int i = 0; i < n; i++) {
+
+ for (int i = 0; i < n; i++) {
EQ_Handle h = f_root->add_EQ();
- h.update_coef(r.output_var(i+1), 1);
- h.update_coef(r.input_var(pi[i]+1), -1);
+ h.update_coef(r.output_var(i + 1), 1);
+ h.update_coef(r.input_var(pi[i] + 1), -1);
}
-
+
return r;
}
-
//---------------------------------------------------------------------------
// Find the position index variable in a Relation by name.
//---------------------------------------------------------------------------
Variable_ID find_index(Relation &r, const std::string &s, char side) {
// Omega quirks: assure the names are propagated inside the relation
r.setup_names();
-
+
if (r.is_set()) { // side == 's'
for (int i = 1; i <= r.n_set(); i++) {
std::string ss = r.set_var(i)->name();
@@ -2140,24 +2062,22 @@ Variable_ID find_index(Relation &r, const std::string &s, char side) {
return r.set_var(i);
}
}
- }
- else if (side == 'w') {
+ } else if (side == 'w') {
for (int i = 1; i <= r.n_inp(); i++) {
std::string ss = r.input_var(i)->name();
if (s == ss) {
return r.input_var(i);
}
}
- }
- else { // side == 'r'
+ } else { // side == 'r'
for (int i = 1; i <= r.n_out(); i++) {
std::string ss = r.output_var(i)->name();
- if (s+"'" == ss) {
+ if (s + "'" == ss) {
return r.output_var(i);
}
}
}
-
+
return NULL;
}
@@ -2207,59 +2127,55 @@ bool lowerBoundIsZero(const omega::Relation &bound, int dim) {
if ((*gi).get_coef(v) >= 0 && !(*gi).is_const(v)
&& (*gi).get_const() != 0) {
return false;
- }
- else if ((*gi).get_coef(v) >= 0 && (*gi).is_const(v)
- && (*gi).get_const() == 0)
+ } else if ((*gi).get_coef(v) >= 0 && (*gi).is_const(v)
+ && (*gi).get_const() == 0)
found = true;
}
-
+
return found;
}
-
Relation replicate_IS_and_add_bound(const omega::Relation &R, int level,
omega::Relation &bound) {
-
+
if (!R.is_set())
throw std::invalid_argument("Input R has to be a set not a relation!");
-
+
Relation r(R.n_set());
-
+
for (int i = 1; i <= R.n_set(); i++) {
r.name_set_var(i + 1, const_cast<Relation &>(R).set_var(i)->name());
}
-
+
std::string new_var = bound.set_var(1)->name();
-
+
r.name_set_var(level, new_var);
-
+
F_Exists *f_exists = r.add_and()->add_exists();
F_And *f_root = f_exists->add_and();
std::map<Variable_ID, Variable_ID> exists_mapping;
-
+
for (DNF_Iterator di(const_cast<Relation &>(R).query_DNF()); di; di++) {
for (GEQ_Iterator gi((*di)->GEQs()); gi; gi++) {
GEQ_Handle h = f_root->add_GEQ();
-
+
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
-
- h.update_coef(r.input_var(v->get_position()),
- cvi.curr_coef());
-
- break;
- case Wildcard_Var:
- {
+ case Input_Var:
+
+ h.update_coef(r.input_var(v->get_position()),
+ cvi.curr_coef());
+
+ break;
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2269,36 +2185,34 @@ Relation replicate_IS_and_add_bound(const omega::Relation &R, int level,
h.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
}
h.update_const((*gi).get_const());
}
}
-
+
for (DNF_Iterator di(const_cast<Relation &>(R).query_DNF()); di; di++) {
for (EQ_Iterator gi((*di)->EQs()); gi; gi++) {
EQ_Handle h1 = f_root->add_EQ();
-
+
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
-
- h1.update_coef(r.input_var(v->get_position()),
- cvi.curr_coef());
-
- break;
- case Wildcard_Var:
- {
+ case Input_Var:
+
+ h1.update_coef(r.input_var(v->get_position()),
+ cvi.curr_coef());
+
+ break;
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h1.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2308,34 +2222,32 @@ Relation replicate_IS_and_add_bound(const omega::Relation &R, int level,
h1.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
}
h1.update_const((*gi).get_const());
}
}
-
+
for (DNF_Iterator di(bound.query_DNF()); di; di++) {
for (GEQ_Iterator gi((*di)->GEQs()); gi; gi++) {
GEQ_Handle h = f_root->add_GEQ();
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
-
- h.update_coef(r.input_var(level), cvi.curr_coef());
-
- break;
- case Wildcard_Var:
- {
+ case Input_Var:
+
+ h.update_coef(r.input_var(level), cvi.curr_coef());
+
+ break;
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2345,33 +2257,31 @@ Relation replicate_IS_and_add_bound(const omega::Relation &R, int level,
h.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
}
h.update_const((*gi).get_const());
}
}
-
+
for (DNF_Iterator di(bound.query_DNF()); di; di++) {
for (EQ_Iterator gi((*di)->EQs()); gi; gi++) {
EQ_Handle h = f_root->add_EQ();
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- h.update_coef(r.input_var(level), cvi.curr_coef());
-
- break;
- case Wildcard_Var:
- {
+ case Input_Var:
+ h.update_coef(r.input_var(level), cvi.curr_coef());
+
+ break;
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2381,8 +2291,8 @@ Relation replicate_IS_and_add_bound(const omega::Relation &R, int level,
h.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
}
h.update_const((*gi).get_const());
@@ -2394,56 +2304,51 @@ Relation replicate_IS_and_add_bound(const omega::Relation &R, int level,
}
-
-
// Replicates old_relation's bounds for set var at old_pos int o new_relation at new_pos, but position's bounds must involve constants
// only supports GEQs
//
Relation replace_set_var_as_another_set_var(const omega::Relation &new_relation,
const omega::Relation &old_relation, int new_pos, int old_pos) {
-
+
Relation r = copy(new_relation);
r.copy_names(new_relation);
r.setup_names();
-
+
F_Exists *f_exists = r.and_with_and()->add_exists();
F_And *f_root = f_exists->add_and();
std::map<Variable_ID, Variable_ID> exists_mapping;
-
+
for (DNF_Iterator di(const_cast<Relation &>(old_relation).query_DNF()); di;
di++)
for (GEQ_Iterator gi((*di)->GEQs()); gi; gi++) {
GEQ_Handle h = f_root->add_GEQ();
if (((*gi).get_coef(
- const_cast<Relation &>(old_relation).set_var(old_pos)) != 0)
+ const_cast<Relation &>(old_relation).set_var(old_pos)) != 0)
&& (*gi).is_const_except_for_global(
- const_cast<Relation &>(old_relation).set_var(
- old_pos))) {
+ const_cast<Relation &>(old_relation).set_var(
+ old_pos))) {
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- {
-
+ case Input_Var: {
+
if (v->get_position() == old_pos)
h.update_coef(r.input_var(new_pos),
cvi.curr_coef());
else
throw omega_error(
- "relation contains set vars other than that to be replicated!");
+ "relation contains set vars other than that to be replicated!");
break;
-
+
}
- case Wildcard_Var:
- {
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(
- old_relation, v, r, f_exists, f_root,
- exists_mapping);
+ old_relation, v, r, f_exists, f_root,
+ exists_mapping);
h.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2453,15 +2358,15 @@ Relation replace_set_var_as_another_set_var(const omega::Relation &new_relation,
h.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
}
h.update_const((*gi).get_const());
}
}
return r;
-
+
}
@@ -2474,28 +2379,28 @@ Relation replace_set_var_as_another_set_var(const omega::Relation &new_relation,
Relation replicate_IS_and_add_at_pos(const omega::Relation &R, int level,
omega::Relation &bound) {
-
+
if (!R.is_set())
throw std::invalid_argument("Input R has to be a set not a relation!");
-
+
Relation r(R.n_set() + 1);
-
+
for (int i = 1; i <= R.n_set(); i++) {
if (i < level)
r.name_set_var(i, const_cast<Relation &>(R).set_var(i)->name());
else
r.name_set_var(i + 1, const_cast<Relation &>(R).set_var(i)->name());
-
+
}
-
+
std::string new_var = bound.set_var(1)->name();
-
+
r.name_set_var(level, new_var);
-
+
F_Exists *f_exists = r.add_and()->add_exists();
F_And *f_root = f_exists->add_and();
std::map<Variable_ID, Variable_ID> exists_mapping;
-
+
for (int i = 1; i <= R.n_set(); i++)
for (DNF_Iterator di(const_cast<Relation &>(R).query_DNF()); di; di++) {
for (GEQ_Iterator gi((*di)->GEQs()); gi; gi++) {
@@ -2504,26 +2409,23 @@ Relation replicate_IS_and_add_at_pos(const omega::Relation &R, int level,
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- {
+ case Input_Var: {
if (i < level)
h.update_coef(r.input_var(v->get_position()),
cvi.curr_coef());
else
h.update_coef(
- r.input_var(v->get_position() + 1),
- cvi.curr_coef());
+ r.input_var(v->get_position() + 1),
+ cvi.curr_coef());
break;
}
- case Wildcard_Var:
- {
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2533,16 +2435,16 @@ Relation replicate_IS_and_add_at_pos(const omega::Relation &R, int level,
h.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
-
+
}
h.update_const((*gi).get_const());
}
}
}
-
+
for (int i = 1; i <= R.n_set(); i++)
for (DNF_Iterator di(const_cast<Relation &>(R).query_DNF()); di; di++) {
for (EQ_Iterator gi((*di)->EQs()); gi; gi++) {
@@ -2551,26 +2453,23 @@ Relation replicate_IS_and_add_at_pos(const omega::Relation &R, int level,
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- {
+ case Input_Var: {
if (i < level)
h1.update_coef(r.input_var(v->get_position()),
cvi.curr_coef());
else
h1.update_coef(
- r.input_var(v->get_position() + 1),
- cvi.curr_coef());
+ r.input_var(v->get_position() + 1),
+ cvi.curr_coef());
break;
}
- case Wildcard_Var:
- {
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h1.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2580,38 +2479,35 @@ Relation replicate_IS_and_add_at_pos(const omega::Relation &R, int level,
h1.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
}
h1.update_const((*gi).get_const());
}
}
}
-
+
for (DNF_Iterator di(bound.query_DNF()); di; di++) {
for (GEQ_Iterator gi((*di)->GEQs()); gi; gi++) {
GEQ_Handle h = f_root->add_GEQ();
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- {
+ case Input_Var: {
if (cvi.curr_var()->get_position() < level)
h.update_coef(r.input_var(level), cvi.curr_coef());
else
h.update_coef(r.input_var(level), cvi.curr_coef());
break;
}
- case Wildcard_Var:
- {
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2621,37 +2517,34 @@ Relation replicate_IS_and_add_at_pos(const omega::Relation &R, int level,
h.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
h.update_const((*gi).get_const());
}
}
}
-
+
for (DNF_Iterator di(bound.query_DNF()); di; di++) {
for (EQ_Iterator gi((*di)->EQs()); gi; gi++) {
EQ_Handle h = f_root->add_EQ();
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- {
+ case Input_Var: {
if (cvi.curr_var()->get_position() < level)
h.update_coef(r.input_var(level), cvi.curr_coef());
else
h.update_coef(r.input_var(level), cvi.curr_coef());
break;
}
- case Wildcard_Var:
- {
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2661,8 +2554,8 @@ Relation replicate_IS_and_add_at_pos(const omega::Relation &R, int level,
h.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
}
h.update_const((*gi).get_const());
@@ -2674,59 +2567,53 @@ Relation replicate_IS_and_add_at_pos(const omega::Relation &R, int level,
}
-
-
omega::Relation replace_set_var_as_Global(const omega::Relation &R, int pos,
std::vector<omega::Relation> &bound) {
-
+
if (!R.is_set())
throw std::invalid_argument("Input R has to be a set not a relation!");
-
+
Relation r(R.n_set());
F_Exists *f_exists = r.add_and()->add_exists();
F_And *f_root = f_exists->add_and();
std::map<Variable_ID, Variable_ID> exists_mapping;
int count = 1;
for (int i = 1; i <= R.n_set(); i++) {
-
+
if (i != pos) {
r.name_set_var(i, const_cast<Relation &>(R).set_var(i)->name());
-
- }
- else
+
+ } else
r.name_set_var(i, "void");
}
-
+
Free_Var_Decl *repl = new Free_Var_Decl(
- const_cast<Relation &>(R).set_var(pos)->name());
-
+ const_cast<Relation &>(R).set_var(pos)->name());
+
Variable_ID v3 = r.get_local(repl);
-
+
for (DNF_Iterator di(const_cast<Relation &>(R).query_DNF()); di; di++) {
for (EQ_Iterator gi((*di)->EQs()); gi; gi++) {
EQ_Handle h1 = f_root->add_EQ();
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- {
+ case Input_Var: {
if (v->get_position() != pos)
h1.update_coef(r.input_var(v->get_position()),
cvi.curr_coef());
else
-
+
h1.update_coef(v3, cvi.curr_coef());
break;
}
- case Wildcard_Var:
- {
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h1.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2736,14 +2623,14 @@ omega::Relation replace_set_var_as_Global(const omega::Relation &R, int pos,
h1.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
}
h1.update_const((*gi).get_const());
}
}
-
+
for (int i = 0; i < bound.size(); i++)
for (DNF_Iterator di(bound[i].query_DNF()); di; di++) {
for (GEQ_Iterator gi((*di)->GEQs()); gi; gi++) {
@@ -2752,32 +2639,29 @@ omega::Relation replace_set_var_as_Global(const omega::Relation &R, int pos,
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- {
+ case Input_Var: {
//if (i < level)
if (v->get_position() != pos)
h.update_coef(r.input_var(v->get_position()),
cvi.curr_coef());
else
-
+
h.update_coef(v3, cvi.curr_coef());
break;
-
+
//else
// h.update_coef(
// r.input_var(v->get_position() + 1),
// cvi.curr_coef());
break;
}
- case Wildcard_Var:
- {
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2787,10 +2671,10 @@ omega::Relation replace_set_var_as_Global(const omega::Relation &R, int pos,
h.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
-
+
}
h.update_const((*gi).get_const());
}
@@ -2800,24 +2684,21 @@ omega::Relation replace_set_var_as_Global(const omega::Relation &R, int pos,
}
-
-
-
//-----------------------------------------------------------------------------
// Replace an input variable's constraints as an existential in order
// to simplify other constraints in Relation
// -----------------------------------------------------------------------------
std::pair<Relation, bool> replace_set_var_as_existential(
- const omega::Relation &R, int pos,
- std::vector<omega::Relation> &bound) {
-
+ const omega::Relation &R, int pos,
+ std::vector<omega::Relation> &bound) {
+
if (!R.is_set())
throw std::invalid_argument("Input R has to be a set not a relation!");
-
+
Relation r(R.n_set());
for (int i = 1; i <= R.n_set(); i++)
r.name_set_var(i, const_cast<Relation &>(R).set_var(i)->name());
-
+
F_Exists *f_exists = r.add_and()->add_exists();
F_And *f_root = f_exists->add_and();
std::map<Variable_ID, Variable_ID> exists_mapping;
@@ -2828,28 +2709,28 @@ std::pair<Relation, bool> replace_set_var_as_existential(
&& (!(*gi).has_wildcards()))
if (coef_in_equality == 0)
coef_in_equality = (*gi).get_coef(
- const_cast<Relation &>(R).set_var(pos));
+ const_cast<Relation &>(R).set_var(pos));
else
return std::pair<Relation, bool>(copy(R), false);
-
+
if (coef_in_equality < 0)
coef_in_equality = -coef_in_equality;
-
+
std::pair<EQ_Handle, Variable_ID> result = find_simplest_stride(
- const_cast<Relation &>(R), const_cast<Relation &>(R).set_var(pos));
-
+ const_cast<Relation &>(R), const_cast<Relation &>(R).set_var(pos));
+
if (result.second == NULL && coef_in_equality != 1)
return std::pair<Relation, bool>(copy(R), false);
-
+
if (result.second != NULL) {
if (result.first.get_coef(const_cast<Relation &>(R).set_var(pos)) != 1)
return std::pair<Relation, bool>(copy(R), false);
-
+
if (result.first.get_coef(result.second) != coef_in_equality)
return std::pair<Relation, bool>(copy(R), false);
}
Variable_ID v3 = f_exists->declare();
-
+
for (DNF_Iterator di(const_cast<Relation &>(R).query_DNF()); di; di++) {
for (EQ_Iterator gi((*di)->EQs()); gi; gi++) {
EQ_Handle h1 = f_root->add_EQ();
@@ -2858,25 +2739,22 @@ std::pair<Relation, bool> replace_set_var_as_existential(
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- {
+ case Input_Var: {
if (v->get_position() != pos)
h1.update_coef(r.input_var(v->get_position()),
cvi.curr_coef());
else
-
+
h1.update_coef(v3, cvi.curr_coef());
break;
}
- case Wildcard_Var:
- {
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h1.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2886,15 +2764,15 @@ std::pair<Relation, bool> replace_set_var_as_existential(
h1.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
}
h1.update_const((*gi).get_const());
}
}
}
-
+
for (int i = 0; i < bound.size(); i++)
for (DNF_Iterator di(bound[i].query_DNF()); di; di++) {
for (GEQ_Iterator gi((*di)->GEQs()); gi; gi++) {
@@ -2903,32 +2781,29 @@ std::pair<Relation, bool> replace_set_var_as_existential(
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- {
+ case Input_Var: {
//if (i < level)
if (v->get_position() != pos)
-
+
h.update_coef(r.set_var(v->get_position()),
cvi.curr_coef());
else
-
+
h.update_coef(v3, cvi.curr_coef());
-
+
//else
// h.update_coef(
// r.input_var(v->get_position() + 1),
// cvi.curr_coef());
break;
}
- case Wildcard_Var:
- {
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -2938,24 +2813,21 @@ std::pair<Relation, bool> replace_set_var_as_existential(
h.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
-
+
}
h.update_const((*gi).get_const());
//}
}
}
-
+
//for (int i = 1; i <= R.n_set(); i++)
return std::pair<Relation, bool>(r, true);
}
-
-
-
//-----------------------------------------------------------------------------
// Copy all relations from r except those for set var v.
// And with GEQ given by g
@@ -2966,9 +2838,9 @@ Relation and_with_relation_and_replace_var(const Relation &R, Variable_ID v1,
Relation &g) {
if (!R.is_set())
throw std::invalid_argument("Input R has to be a set not a relation!");
-
+
Relation r(R.n_set());
-
+
F_Exists *f_exists = r.add_and()->add_exists();
F_And *f_root = f_exists->add_and();
std::map<Variable_ID, Variable_ID> exists_mapping;
@@ -2980,21 +2852,18 @@ Relation and_with_relation_and_replace_var(const Relation &R, Variable_ID v1,
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- {
+ case Input_Var: {
h.update_coef(r.input_var(v->get_position()),
cvi.curr_coef());
break;
}
- case Wildcard_Var:
- {
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -3004,36 +2873,33 @@ Relation and_with_relation_and_replace_var(const Relation &R, Variable_ID v1,
h.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
}
-
+
h.update_const((*gi).get_const());
}
}
-
+
for (GEQ_Iterator gi((*di)->GEQs()); gi; gi++) {
GEQ_Handle h = f_root->add_GEQ();
if ((*gi).get_coef(v1) == 0) {
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- {
+ case Input_Var: {
h.update_coef(r.input_var(v->get_position()),
cvi.curr_coef());
break;
}
- case Wildcard_Var:
- {
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -3043,8 +2909,8 @@ Relation and_with_relation_and_replace_var(const Relation &R, Variable_ID v1,
h.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
}
h.update_const((*gi).get_const());
@@ -3054,11 +2920,11 @@ Relation and_with_relation_and_replace_var(const Relation &R, Variable_ID v1,
for (DNF_Iterator di(const_cast<Relation &>(g).query_DNF()); di; di++)
for (GEQ_Iterator gi((*di)->GEQs()); gi; gi++)
r.and_with_GEQ(*gi);
-
+
for (DNF_Iterator di(const_cast<Relation &>(g).query_DNF()); di; di++)
for (EQ_Iterator gi((*di)->EQs()); gi; gi++)
r.and_with_EQ(*gi);
-
+
r.simplify();
r.copy_names(R);
r.setup_names();
@@ -3066,15 +2932,12 @@ Relation and_with_relation_and_replace_var(const Relation &R, Variable_ID v1,
}
-
-
-
omega::Relation extract_upper_bound(const Relation &R, Variable_ID v1) {
if (!R.is_set())
throw std::invalid_argument("Input R has to be a set not a relation!");
-
+
Relation r(R.n_set());
-
+
F_Exists *f_exists = r.add_and()->add_exists();
F_And *f_root = f_exists->add_and();
std::map<Variable_ID, Variable_ID> exists_mapping;
@@ -3082,23 +2945,21 @@ omega::Relation extract_upper_bound(const Relation &R, Variable_ID v1) {
for (DNF_Iterator di(const_cast<Relation &>(R).query_DNF()); di; di++)
for (GEQ_Iterator gi((*di)->GEQs()); gi; gi++)
if ((*gi).get_coef(v1) < 0) {
-
+
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
- case Input_Var:
- h.update_coef(r.input_var(v->get_position()),
- cvi.curr_coef());
- break;
- case Wildcard_Var:
- {
+ case Input_Var:
+ h.update_coef(r.input_var(v->get_position()),
+ cvi.curr_coef());
+ break;
+ case Wildcard_Var: {
Variable_ID v2 = replicate_floor_definition(R, v, r,
f_exists, f_root, exists_mapping);
h.update_coef(v2, cvi.curr_coef());
break;
}
- case Global_Var:
- {
+ case Global_Var: {
Global_Var_ID g = v->get_global_var();
Variable_ID v2;
if (g->arity() == 0)
@@ -3108,17 +2969,17 @@ omega::Relation extract_upper_bound(const Relation &R, Variable_ID v1) {
h.update_coef(v2, cvi.curr_coef());
break;
}
- default:
- assert(false);
+ default:
+ assert(false);
}
}
h.update_const((*gi).get_const());
}
-
+
r.simplify();
-
+
return r;
-
+
}
/*CG_outputRepr * modified_output_subs_repr(CG_outputBuilder * ocg, const Relation &R, const EQ_Handle &h, Variable_ID v,const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly,
@@ -3134,17 +2995,17 @@ omega::Relation extract_upper_bound(const Relation &R, Variable_ID v1) {
-CG_outputRepr * construct_int_floor(CG_outputBuilder * ocg, const Relation &R,
- const GEQ_Handle &h, Variable_ID v,
- const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly,
- std::map<std::string, std::vector<CG_outputRepr *> > unin) {
-
+CG_outputRepr *construct_int_floor(CG_outputBuilder *ocg, const Relation &R,
+ const GEQ_Handle &h, Variable_ID v,
+ const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly,
+ std::map<std::string, std::vector<CG_outputRepr *> > unin) {
+
std::set<Variable_ID> excluded_floor_vars;
const_cast<Relation &>(R).setup_names(); // hack
assert(v->kind() == Set_Var);
-
+
int a = h.get_coef(v);
-
+
CG_outputRepr *lhs = ocg->CreateIdent(v->name());
excluded_floor_vars.insert(v);
std::vector<std::pair<bool, GEQ_Handle> > result2;
@@ -3159,9 +3020,9 @@ CG_outputRepr * construct_int_floor(CG_outputBuilder * ocg, const Relation &R,
coef_t coef_ = cvi.curr_coef();
result2 = find_floor_definition_temp(R, cvi.curr_var(),
excluded_floor_vars);
-
+
for (Constr_Vars_Iter cvi_(
- result2[result2.size() - 1].second); cvi_; cvi_++) {
+ result2[result2.size() - 1].second); cvi_; cvi_++) {
if (cvi_.curr_var()->kind() != Wildcard_Var
&& cvi_.curr_var()->kind() != Set_Var) {
t = output_ident(ocg, R, cvi_.curr_var(),
@@ -3172,20 +3033,20 @@ CG_outputRepr * construct_int_floor(CG_outputBuilder * ocg, const Relation &R,
ocg->CreateInt(-coef_));
repr = ocg->CreateTimes(ocg->CreateInt(-coef_),
repr);
-
+
return repr;
-
+
}
-
+
}
-
+
};
if (!result.first) {
delete repr;
throw omega_error(
- "Can't generate bound expression with wildcard not involved in floor definition");
+ "Can't generate bound expression with wildcard not involved in floor definition");
}
-
+
try {
t = output_inequality_repr(ocg, result.second,
cvi.curr_var(), R, assigned_on_the_fly, unin,
@@ -3194,11 +3055,10 @@ CG_outputRepr * construct_int_floor(CG_outputBuilder * ocg, const Relation &R,
delete repr;
throw e;
}
- }
- else
+ } else
t = output_ident(ocg, R, cvi.curr_var(), assigned_on_the_fly,
unin);
-
+
coef_t coef = cvi.curr_coef();
if (a > 0) {
if (coef > 0) {
@@ -3207,24 +3067,21 @@ CG_outputRepr * construct_int_floor(CG_outputBuilder * ocg, const Relation &R,
else
repr = ocg->CreateMinus(repr,
ocg->CreateTimes(ocg->CreateInt(coef), t));
- }
- else {
+ } else {
if (coef == -1)
repr = ocg->CreatePlus(repr, t);
else
repr = ocg->CreatePlus(repr,
ocg->CreateTimes(ocg->CreateInt(-coef), t));
}
- }
- else {
+ } else {
if (coef > 0) {
if (coef == 1)
repr = ocg->CreatePlus(repr, t);
else
repr = ocg->CreatePlus(repr,
ocg->CreateTimes(ocg->CreateInt(coef), t));
- }
- else {
+ } else {
if (coef == -1)
repr = ocg->CreateMinus(repr, t);
else
@@ -3239,14 +3096,13 @@ CG_outputRepr * construct_int_floor(CG_outputBuilder * ocg, const Relation &R,
repr = ocg->CreateMinus(repr, ocg->CreateInt(c));
else
repr = ocg->CreatePlus(repr, ocg->CreateInt(c));
- }
- else if (c < 0) {
+ } else if (c < 0) {
if (a > 0)
repr = ocg->CreatePlus(repr, ocg->CreateInt(-c));
else
repr = ocg->CreateMinus(repr, ocg->CreateInt(-c));
}
-
+
if (abs(a) == 1)
ocg->CreateAssignment(0, lhs, repr);
else if (a > 0)
@@ -3256,7 +3112,7 @@ CG_outputRepr * construct_int_floor(CG_outputBuilder * ocg, const Relation &R,
// a < 0
return ocg->CreateAssignment(0, lhs,
ocg->CreateIntegerFloor(repr, ocg->CreateInt(-a)));
-
+
}
diff --git a/src/transformations/loop.cc b/src/transformations/loop.cc
index 570bc90..10dc7bb 100644
--- a/src/transformations/loop.cc
+++ b/src/transformations/loop.cc
@@ -43,36 +43,36 @@
#define _DEBUG_ true
-
using namespace omega;
-const std::string Loop::tmp_loop_var_name_prefix = std::string("chill_t"); // Manu:: In fortran, first character of a variable name must be a letter, so this change
+const std::string Loop::tmp_loop_var_name_prefix = std::string(
+ "chill_t"); // Manu:: In fortran, first character of a variable name must be a letter, so this change
const std::string Loop::overflow_var_name_prefix = std::string("over");
-void echocontroltype( const IR_Control *control ) {
- switch(control->type()) {
- case IR_CONTROL_BLOCK: {
- CHILL_DEBUG_PRINT("IR_CONTROL_BLOCK\n");
- break;
- }
- case IR_CONTROL_LOOP: {
- CHILL_DEBUG_PRINT("IR_CONTROL_LOOP\n");
- break;
- }
- case IR_CONTROL_IF: {
- CHILL_DEBUG_PRINT("IR_CONTROL_IF\n");
- break;
- }
- default:
- CHILL_DEBUG_PRINT("just a bunch of statements?\n");
-
+void echocontroltype(const IR_Control *control) {
+ switch (control->type()) {
+ case IR_CONTROL_BLOCK: {
+ CHILL_DEBUG_PRINT("IR_CONTROL_BLOCK\n");
+ break;
+ }
+ case IR_CONTROL_LOOP: {
+ CHILL_DEBUG_PRINT("IR_CONTROL_LOOP\n");
+ break;
+ }
+ case IR_CONTROL_IF: {
+ CHILL_DEBUG_PRINT("IR_CONTROL_IF\n");
+ break;
+ }
+ default:
+ CHILL_DEBUG_PRINT("just a bunch of statements?\n");
+
} // switch
}
omega::Relation Loop::getNewIS(int stmt_num) const {
-
+
omega::Relation result;
-
+
if (stmt[stmt_num].xform.is_null()) {
omega::Relation known = omega::Extend_Set(omega::copy(this->known),
stmt[stmt_num].IS.n_set() - this->known.n_set());
@@ -81,32 +81,31 @@ omega::Relation Loop::getNewIS(int stmt_num) const {
omega::Relation known = omega::Extend_Set(omega::copy(this->known),
stmt[stmt_num].xform.n_out() - this->known.n_set());
result = omega::Intersection(
- omega::Range(
- omega::Restrict_Domain(
- omega::copy(stmt[stmt_num].xform),
- omega::copy(stmt[stmt_num].IS))), known);
+ omega::Range(
+ omega::Restrict_Domain(
+ omega::copy(stmt[stmt_num].xform),
+ omega::copy(stmt[stmt_num].IS))), known);
}
-
+
result.simplify(2, 4);
-
+
return result;
}
-
-void Loop::reduce(int stmt_num,
- std::vector<int> &level,
+void Loop::reduce(int stmt_num,
+ std::vector<int> &level,
int param,
- std::string func_name,
+ std::string func_name,
std::vector<int> &seq_levels,
- std::vector<int> cudaized_levels,
+ std::vector<int> cudaized_levels,
int bound_level) {
// illegal instruction?? fprintf(stderr, " Loop::reduce( stmt %d, param %d, func_name (encrypted)...)\n", stmt, param); // , func_name.c_str());
-
+
//std::cout << "Reducing stmt# " << stmt_num << " at level " << level << "\n";
//ir->printStmt(stmt[stmt_num].code);
-
+
if (stmt[stmt_num].reduction != 1) {
CHILL_DEBUG_PRINT("Cannot reduce this statement\n");
return;
@@ -132,9 +131,9 @@ void Loop::reduce(int stmt_num,
delete last_compute_cg_;
last_compute_cg_ = NULL;
fprintf(stderr, "set last_compute_cg_ = NULL;\n");
-
+
omega::CG_outputBuilder *ocg = ir->builder();
-
+
omega::CG_outputRepr *funCallRepr;
std::vector<omega::CG_outputRepr *> arg_repr_list;
apply_xform(stmt_num);
@@ -144,13 +143,13 @@ void Loop::reduce(int stmt_num,
std::vector<IR_ArrayRef *> access2;
for (int j = 0; j < access[i]->n_dim(); j++) {
std::vector<IR_ArrayRef *> access3 = ir->FindArrayRef(
- access[i]->index(j));
+ access[i]->index(j));
access2.insert(access2.end(), access3.begin(), access3.end());
}
if (access2.size() == 0) {
if (names.find(access[i]->name()) == names.end()) {
arg_repr_list.push_back(
- ocg->CreateAddressOf(access[i]->convert()));
+ ocg->CreateAddressOf(access[i]->convert()));
names.insert(access[i]->name());
if (access[i]->is_write())
reduced_write_refs.insert(access[i]->name());
@@ -165,14 +164,14 @@ void Loop::reduce(int stmt_num,
}
}
}
-
+
for (int i = 0; i < seq_levels.size(); i++)
arg_repr_list.push_back(
- ocg->CreateIdent(
- stmt[stmt_num].IS.set_var(seq_levels[i])->name()));
-
+ ocg->CreateIdent(
+ stmt[stmt_num].IS.set_var(seq_levels[i])->name()));
+
if (bound_level != -1) {
-
+
omega::Relation new_IS = copy(stmt[stmt_num].IS);
new_IS.copy_names(stmt[stmt_num].IS);
new_IS.setup_names();
@@ -181,106 +180,106 @@ void Loop::reduce(int stmt_num,
//omega::Relation r = getNewIS(stmt_num);
for (int j = dim + 1; j <= new_IS.n_set(); j++)
new_IS = omega::Project(new_IS, new_IS.set_var(j));
-
+
new_IS.simplify(2, 4);
-
+
omega::Relation bound_ = get_loop_bound(copy(new_IS), dim - 1);
omega::Variable_ID v = bound_.set_var(dim);
std::vector<omega::CG_outputRepr *> ubList;
for (omega::GEQ_Iterator e(
- const_cast<omega::Relation &>(bound_).single_conjunct()->GEQs());
+ const_cast<omega::Relation &>(bound_).single_conjunct()->GEQs());
e; e++) {
if ((*e).get_coef(v) < 0) {
// && (*e).is_const_except_for_global(v))
omega::CG_outputRepr *UPPERBOUND =
- omega::output_upper_bound_repr(ir->builder(), *e, v,
- bound_,
- std::vector<
- std::pair<omega::CG_outputRepr *, int> >(
- bound_.n_set(),
- std::make_pair(
- static_cast<omega::CG_outputRepr *>(NULL),
- 0)), uninterpreted_symbols[stmt_num]);
+ omega::output_upper_bound_repr(ir->builder(), *e, v,
+ bound_,
+ std::vector<
+ std::pair<omega::CG_outputRepr *, int> >(
+ bound_.n_set(),
+ std::make_pair(
+ static_cast<omega::CG_outputRepr *>(NULL),
+ 0)), uninterpreted_symbols[stmt_num]);
if (UPPERBOUND != NULL)
ubList.push_back(UPPERBOUND);
-
+
}
-
+
}
-
- omega::CG_outputRepr * ubRepr;
+
+ omega::CG_outputRepr *ubRepr;
if (ubList.size() > 1) {
-
+
ubRepr = ir->builder()->CreateInvoke("min", ubList);
arg_repr_list.push_back(ubRepr);
} else if (ubList.size() == 1)
arg_repr_list.push_back(ubList[0]);
}
-
+
funCallRepr = ocg->CreateInvoke(func_name, arg_repr_list);
stmt[stmt_num].code = funCallRepr;
for (int i = 0; i < level.size(); i++) {
//stmt[*i].code = outputStatement(ocg, stmt[*i].code, 0, mapping, known, std::vector<CG_outputRepr *>(mapping.n_out(), NULL));
std::vector<std::string> loop_vars;
loop_vars.push_back(stmt[stmt_num].IS.set_var(level[i])->name());
-
+
std::vector<omega::CG_outputRepr *> subs;
subs.push_back(ocg->CreateInt(0));
-
+
stmt[stmt_num].code = ocg->CreateSubstitutedStmt(0, stmt[stmt_num].code,
loop_vars, subs);
-
+
}
-
+
omega::Relation new_IS = copy(stmt[stmt_num].IS);
new_IS.copy_names(stmt[stmt_num].IS);
new_IS.setup_names();
new_IS.simplify();
int old_size = new_IS.n_set();
-
+
omega::Relation R = omega::copy(stmt[stmt_num].IS);
R.copy_names(stmt[stmt_num].IS);
R.setup_names();
-
+
for (int i = level.size() - 1; i >= 0; i--) {
int j;
-
+
for (j = 0; j < cudaized_levels.size(); j++) {
if (cudaized_levels[j] == level[i])
break;
-
+
}
-
+
if (j == cudaized_levels.size()) {
R = omega::Project(R, level[i], omega::Input_Var);
R.simplify();
-
+
}
//
-
+
}
-
+
omega::F_And *f_Root = R.and_with_and();
for (int i = level.size() - 1; i >= 0; i--) {
int j;
-
+
for (j = 0; j < cudaized_levels.size(); j++) {
if (cudaized_levels[j] == level[i])
break;
-
+
}
-
+
if (j == cudaized_levels.size()) {
-
+
omega::EQ_Handle h = f_Root->add_EQ();
-
+
h.update_coef(R.set_var(level[i]), 1);
h.update_const(-1);
}
//
-
+
}
-
+
R.simplify();
stmt[stmt_num].IS = R;
}
@@ -303,22 +302,22 @@ bool Loop::isInitialized() const {
bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
std::vector<ir_tree_node *> &ir_stmt) {
-
+
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);
-
- CHILL_DEBUG_PRINT("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());
-
- CHILL_DEBUG_PRINT("%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++) {
- fprintf(stderr, "i %d\n", i);
+ fprintf(stderr, "i %d\n", i);
ir_stmt[i]->payload = i;
int t = 0;
ir_tree_node *itn = ir_stmt[i];
@@ -331,23 +330,24 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
stmt_nesting_level[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());
-
+ actual_code = std::vector<CG_outputRepr *>(ir_stmt.size());
+
stmt = std::vector<Statement>(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());
-
+ 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());
+
int n_dim = -1;
int max_loc;
//std::vector<std::string> index;
for (int i = 0; i < ir_stmt.size(); i++) {
int max_nesting_level = -1;
int loc;
-
+
// find the max nesting level and remember the statement that was at that level
for (int j = 0; j < ir_stmt.size(); j++) {
if (stmt_nesting_level[j] > max_nesting_level) {
@@ -355,23 +355,23 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
loc = j;
}
}
-
+
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) {
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];
CHILL_DEBUG_PRINT("itn = stmt[%d]\n", loc);
int cur_dim = n_dim - 1;
while (itn->parent != NULL) {
CHILL_DEBUG_PRINT("parent\n");
-
+
itn = itn->parent;
if (itn->content->type() == IR_CONTROL_LOOP) {
CHILL_DEBUG_PRINT("IR_CONTROL_LOOP cur_dim %d\n", cur_dim);
@@ -382,258 +382,264 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
}
}
}
-
+
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;
-
+
for (int t = depth; t >= 0; t--) {
int y = t;
itn = ir_stmt[loc];
-
+
while ((itn->parent != NULL) && (y >= 0)) {
itn = itn->parent;
if (itn->content->type() == IR_CONTROL_LOOP)
y--;
}
-
+
if (itn->content->type() == IR_CONTROL_LOOP && itn->payload == -1) {
CG_outputBuilder *ocg = ir->builder();
-
+
itn->payload = depth - t;
-
+
CG_outputRepr *code =
- static_cast<IR_Block *>(ir_stmt[loc]->content)->extract();
-
+ static_cast<IR_Block *>(ir_stmt[loc]->content)->extract();
+
std::vector<CG_outputRepr *> index_expr;
std::vector<std::string> old_index;
CG_outputRepr *repl = ocg->CreateIdent(index[itn->payload]);
index_expr.push_back(repl);
old_index.push_back(
- static_cast<IR_Loop *>(itn->content)->index()->name());
+ static_cast<IR_Loop *>(itn->content)->index()->name());
code = ocg->CreateSubstitutedStmt(0, code, old_index,
index_expr);
-
- replace.insert(std::pair<int, CG_outputRepr*>(loc, code));
+
+ replace.insert(std::pair<int, CG_outputRepr *>(loc, code));
//stmt[loc].code = code;
-
+
}
}
-
+
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)
-
+
CHILL_DEBUG_PRINT("Relation r(%d)\n", n_dim);
Relation r(n_dim);
F_And *f_root = r.add_and();
itn = ir_stmt[loc];
int temp_depth = depth;
while (itn->parent != NULL) {
-
+
itn = itn->parent;
if (itn->content->type() == IR_CONTROL_LOOP) {
- fprintf(stderr, "it's a loop. temp_depth %d\n", temp_depth);
+ fprintf(stderr, "it's a loop. temp_depth %d\n", temp_depth);
fprintf(stderr, "r.name_set_var( %d, %s )\n", itn->payload + 1, index[temp_depth].c_str());
r.name_set_var(itn->payload + 1, index[temp_depth]);
-
+
temp_depth--;
}
//static_cast<IR_Loop *>(itn->content)->index()->name());
}
- fprintf(stderr, "Relation r "); r.print(); fflush(stdout);
+ fprintf(stderr, "Relation r ");
+ r.print();
+ fflush(stdout);
//fprintf(stderr, "f_root "); f_root->print(stderr); fprintf(stderr, "\n");
-
+
/*while (itn->parent != NULL) {
itn = itn->parent;
if (itn->content->type() == IR_CONTROL_LOOP)
r.name_set_var(itn->payload+1, static_cast<IR_Loop *>(itn->content)->index()->name());
}*/
-
-
-
-
- fprintf(stderr, "extract information from loop/if structures\n");
+
+
+
+
+ fprintf(stderr, "extract information from loop/if structures\n");
// extract information from loop/if structures
std::vector<bool> processed(n_dim, false);
std::vector<std::string> vars_to_be_reversed;
-
+
std::vector<std::string> insp_lb;
std::vector<std::string> insp_ub;
-
+
itn = ir_stmt[loc];
while (itn->parent != NULL) { // keep heading upward
itn = itn->parent;
-
+
switch (itn->content->type()) {
- case IR_CONTROL_LOOP: {
- fprintf(stderr, "loop.cc l 462 IR_CONTROL_LOOP\n");
- IR_Loop *lp = static_cast<IR_Loop *>(itn->content);
- Variable_ID v = r.set_var(itn->payload + 1);
- int c;
-
- try {
- c = lp->step_size();
- //fprintf(stderr, "step size %d\n", c);
- if (c > 0) {
+ case IR_CONTROL_LOOP: {
+ fprintf(stderr, "loop.cc l 462 IR_CONTROL_LOOP\n");
+ IR_Loop *lp = static_cast<IR_Loop *>(itn->content);
+ Variable_ID v = r.set_var(itn->payload + 1);
+ int c;
+
+ try {
+ c = lp->step_size();
+ //fprintf(stderr, "step size %d\n", c);
+ if (c > 0) {
+ CG_outputRepr *lb = lp->lower_bound();
+ fprintf(stderr, "loop.cc, got the lower bound. it is:\n");
+ lb->dump();
+ printf("\n");
+ fflush(stdout);
+
+ exp2formula(ir, r, f_root, freevar, lb, v, 's',
+ IR_COND_GE, true, uninterpreted_symbols[i], uninterpreted_symbols_stringrepr[i]);
+
+ CG_outputRepr *ub = lp->upper_bound();
+ //fprintf(stderr, "loop.cc, got the upper bound. it is:\n");
+ //ub->dump(); printf("\n"); fflush(stdout);
+
+
+
+ IR_CONDITION_TYPE cond = lp->stop_cond();
+ if (cond == IR_COND_LT || cond == IR_COND_LE)
+ exp2formula(ir, r, f_root, freevar, ub, v, 's',
+ cond, true, uninterpreted_symbols[i], uninterpreted_symbols_stringrepr[i]);
+ else
+ throw ir_error("loop condition not supported");
+
+
+ if ((ir->QueryExpOperation(lp->lower_bound())
+ == IR_OP_ARRAY_VARIABLE)
+ && (ir->QueryExpOperation(lp->lower_bound())
+ == ir->QueryExpOperation(
+ lp->upper_bound()))) {
+
+ fprintf(stderr, "loop.cc lower and upper are both IR_OP_ARRAY_VARIABLE?\n");
+
+ std::vector<CG_outputRepr *> v =
+ ir->QueryExpOperand(lp->lower_bound());
+ IR_ArrayRef *ref =
+ static_cast<IR_ArrayRef *>(ir->Repr2Ref(
+ v[0]));
+ std::string s0 = ref->name();
+ std::vector<CG_outputRepr *> v2 =
+ ir->QueryExpOperand(lp->upper_bound());
+ IR_ArrayRef *ref2 =
+ static_cast<IR_ArrayRef *>(ir->Repr2Ref(
+ v2[0]));
+ std::string s1 = ref2->name();
+
+ if (s0 == s1) {
+ insp_lb.push_back(s0);
+ insp_ub.push_back(s1);
+
+ }
+
+ }
+
+
+ } else if (c < 0) {
+ CG_outputBuilder *ocg = ir->builder();
+ CG_outputRepr *lb = lp->lower_bound();
+ lb = ocg->CreateMinus(NULL, lb);
+ exp2formula(ir, r, f_root, freevar, lb, v, 's',
+ IR_COND_GE, true, uninterpreted_symbols[i], uninterpreted_symbols_stringrepr[i]);
+ CG_outputRepr *ub = lp->upper_bound();
+ ub = ocg->CreateMinus(NULL, ub);
+ IR_CONDITION_TYPE cond = lp->stop_cond();
+ if (cond == IR_COND_GE)
+ exp2formula(ir, r, f_root, freevar, ub, v, 's',
+ IR_COND_LE, true, uninterpreted_symbols[i], uninterpreted_symbols_stringrepr[i]);
+ else if (cond == IR_COND_GT)
+ exp2formula(ir, r, f_root, freevar, ub, v, 's',
+ IR_COND_LT, true, uninterpreted_symbols[i], uninterpreted_symbols_stringrepr[i]);
+ else
+ throw ir_error("loop condition not supported");
+
+ vars_to_be_reversed.push_back(lp->index()->name());
+ } else
+ throw ir_error("loop step size zero");
+ } catch (const ir_error &e) {
+ actual_code[loc] =
+ static_cast<IR_Block *>(ir_stmt[loc]->content)->extract();
+ for (int i = 0; i < itn->children.size(); i++)
+ delete itn->children[i];
+ itn->children = std::vector<ir_tree_node *>();
+ itn->content = itn->content->convert();
+ return false;
+ }
+
+ // check for loop increment or decrement that is not 1
+ //fprintf(stderr, "abs(c)\n");
+ if (abs(c) != 1) {
+ F_Exists *f_exists = f_root->add_exists();
+ Variable_ID e = f_exists->declare();
+ F_And *f_and = f_exists->add_and();
+ Stride_Handle h = f_and->add_stride(abs(c));
+ if (c > 0)
+ h.update_coef(e, 1);
+ else
+ h.update_coef(e, -1);
+ h.update_coef(v, -1);
CG_outputRepr *lb = lp->lower_bound();
- fprintf(stderr, "loop.cc, got the lower bound. it is:\n");
- lb->dump(); printf("\n"); fflush(stdout);
-
- exp2formula(ir, r, f_root, freevar, lb, v, 's',
- IR_COND_GE, true,uninterpreted_symbols[i],uninterpreted_symbols_stringrepr[i]);
-
- CG_outputRepr *ub = lp->upper_bound();
- //fprintf(stderr, "loop.cc, got the upper bound. it is:\n");
- //ub->dump(); printf("\n"); fflush(stdout);
-
-
-
- IR_CONDITION_TYPE cond = lp->stop_cond();
- if (cond == IR_COND_LT || cond == IR_COND_LE)
- exp2formula(ir, r, f_root, freevar, ub, v, 's',
- cond, true,uninterpreted_symbols[i],uninterpreted_symbols_stringrepr[i]);
+ exp2formula(ir, r, f_and, freevar, lb, e, 's', IR_COND_EQ,
+ true, uninterpreted_symbols[i], uninterpreted_symbols_stringrepr[i]);
+ }
+
+ processed[itn->payload] = true;
+ break;
+ }
+
+
+ case IR_CONTROL_IF: {
+ fprintf(stderr, "IR_CONTROL_IF\n");
+ IR_If *theif = static_cast<IR_If *>(itn->content);
+
+ CG_outputRepr *cond =
+ static_cast<IR_If *>(itn->content)->condition();
+
+ try {
+ if (itn->payload % 2 == 1)
+ exp2constraint(ir, r, f_root, freevar, cond, true, uninterpreted_symbols[i],
+ uninterpreted_symbols_stringrepr[i]);
+ else {
+ F_Not *f_not = f_root->add_not();
+ F_And *f_and = f_not->add_and();
+ exp2constraint(ir, r, f_and, freevar, cond, true, uninterpreted_symbols[i],
+ uninterpreted_symbols_stringrepr[i]);
+ }
+ } catch (const ir_error &e) {
+ std::vector<ir_tree_node *> *t;
+ if (itn->parent == NULL)
+ t = &ir_tree;
else
- throw ir_error("loop condition not supported");
-
-
- if ((ir->QueryExpOperation(lp->lower_bound())
- == IR_OP_ARRAY_VARIABLE)
- && (ir->QueryExpOperation(lp->lower_bound())
- == ir->QueryExpOperation(
- lp->upper_bound()))) {
-
- fprintf(stderr, "loop.cc lower and upper are both IR_OP_ARRAY_VARIABLE?\n");
-
- std::vector<CG_outputRepr *> v =
- ir->QueryExpOperand(lp->lower_bound());
- IR_ArrayRef *ref =
- static_cast<IR_ArrayRef *>(ir->Repr2Ref(
- v[0]));
- std::string s0 = ref->name();
- std::vector<CG_outputRepr *> v2 =
- ir->QueryExpOperand(lp->upper_bound());
- IR_ArrayRef *ref2 =
- static_cast<IR_ArrayRef *>(ir->Repr2Ref(
- v2[0]));
- std::string s1 = ref2->name();
-
- if (s0 == s1) {
- insp_lb.push_back(s0);
- insp_ub.push_back(s1);
-
+ t = &(itn->parent->children);
+ int id = itn->payload;
+ int i = t->size() - 1;
+ while (i >= 0) {
+ if ((*t)[i] == itn) {
+ for (int j = 0; j < itn->children.size(); j++)
+ delete itn->children[j];
+ itn->children = std::vector<ir_tree_node *>();
+ itn->content = itn->content->convert();
+ } else if ((*t)[i]->payload >> 1 == id >> 1) {
+ delete (*t)[i];
+ t->erase(t->begin() + i);
}
-
+ i--;
}
-
-
- } else if (c < 0) {
- CG_outputBuilder *ocg = ir->builder();
- CG_outputRepr *lb = lp->lower_bound();
- lb = ocg->CreateMinus(NULL, lb);
- exp2formula(ir, r, f_root, freevar, lb, v, 's',
- IR_COND_GE, true,uninterpreted_symbols[i],uninterpreted_symbols_stringrepr[i]);
- CG_outputRepr *ub = lp->upper_bound();
- ub = ocg->CreateMinus(NULL, ub);
- IR_CONDITION_TYPE cond = lp->stop_cond();
- if (cond == IR_COND_GE)
- exp2formula(ir, r, f_root, freevar, ub, v, 's',
- IR_COND_LE, true,uninterpreted_symbols[i],uninterpreted_symbols_stringrepr[i]);
- else if (cond == IR_COND_GT)
- exp2formula(ir, r, f_root, freevar, ub, v, 's',
- IR_COND_LT, true,uninterpreted_symbols[i],uninterpreted_symbols_stringrepr[i]);
- else
- throw ir_error("loop condition not supported");
-
- vars_to_be_reversed.push_back(lp->index()->name());
- } else
- throw ir_error("loop step size zero");
- } catch (const ir_error &e) {
- actual_code[loc] =
- static_cast<IR_Block *>(ir_stmt[loc]->content)->extract();
+ return false;
+ }
+
+ break;
+ }
+ default:
+ //fprintf(stderr, "default?\n");
for (int i = 0; i < itn->children.size(); i++)
delete itn->children[i];
itn->children = std::vector<ir_tree_node *>();
itn->content = itn->content->convert();
return false;
- }
-
- // check for loop increment or decrement that is not 1
- //fprintf(stderr, "abs(c)\n");
- if (abs(c) != 1) {
- F_Exists *f_exists = f_root->add_exists();
- Variable_ID e = f_exists->declare();
- F_And *f_and = f_exists->add_and();
- Stride_Handle h = f_and->add_stride(abs(c));
- if (c > 0)
- h.update_coef(e, 1);
- else
- h.update_coef(e, -1);
- h.update_coef(v, -1);
- CG_outputRepr *lb = lp->lower_bound();
- exp2formula(ir, r, f_and, freevar, lb, e, 's', IR_COND_EQ,
- true,uninterpreted_symbols[i],uninterpreted_symbols_stringrepr[i]);
- }
-
- processed[itn->payload] = true;
- break;
- }
-
-
- case IR_CONTROL_IF: {
- fprintf(stderr, "IR_CONTROL_IF\n");
- IR_If *theif = static_cast<IR_If *>(itn->content);
-
- CG_outputRepr *cond =
- static_cast<IR_If *>(itn->content)->condition();
-
- try {
- if (itn->payload % 2 == 1)
- exp2constraint(ir, r, f_root, freevar, cond, true,uninterpreted_symbols[i],uninterpreted_symbols_stringrepr[i]);
- else {
- F_Not *f_not = f_root->add_not();
- F_And *f_and = f_not->add_and();
- exp2constraint(ir, r, f_and, freevar, cond, true,uninterpreted_symbols[i],uninterpreted_symbols_stringrepr[i]);
- }
- } catch (const ir_error &e) {
- std::vector<ir_tree_node *> *t;
- if (itn->parent == NULL)
- t = &ir_tree;
- else
- t = &(itn->parent->children);
- int id = itn->payload;
- int i = t->size() - 1;
- while (i >= 0) {
- if ((*t)[i] == itn) {
- for (int j = 0; j < itn->children.size(); j++)
- delete itn->children[j];
- itn->children = std::vector<ir_tree_node *>();
- itn->content = itn->content->convert();
- } else if ((*t)[i]->payload >> 1 == id >> 1) {
- delete (*t)[i];
- t->erase(t->begin() + i);
- }
- i--;
- }
- return false;
- }
-
- break;
- }
- default:
- //fprintf(stderr, "default?\n");
- for (int i = 0; i < itn->children.size(); i++)
- delete itn->children[i];
- itn->children = std::vector<ir_tree_node *>();
- itn->content = itn->content->convert();
- return false;
}
}
-
-
+
+
//fprintf(stderr, "add information for missing loops n_dim(%d)\n", n_dim);
// add information for missing loops
for (int j = 0; j < n_dim; j++)
@@ -645,18 +651,18 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
&& itn->payload == j)
break;
}
-
+
Variable_ID v = r.set_var(j + 1);
if (loc < max_loc) {
-
+
CG_outputBuilder *ocg = ir->builder();
-
+
CG_outputRepr *lb =
- static_cast<IR_Loop *>(itn->content)->lower_bound();
-
+ static_cast<IR_Loop *>(itn->content)->lower_bound();
+
exp2formula(ir, r, f_root, freevar, lb, v, 's', IR_COND_EQ,
- false,uninterpreted_symbols[i],uninterpreted_symbols_stringrepr[i]);
-
+ false, uninterpreted_symbols[i], uninterpreted_symbols_stringrepr[i]);
+
/* if (ir->QueryExpOperation(
static_cast<IR_Loop *>(itn->content)->lower_bound())
== IR_OP_VARIABLE) {
@@ -684,15 +690,15 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
}
*/
-
+
} else { // loc > max_loc
-
+
CG_outputBuilder *ocg = ir->builder();
CG_outputRepr *ub =
- static_cast<IR_Loop *>(itn->content)->upper_bound();
-
+ static_cast<IR_Loop *>(itn->content)->upper_bound();
+
exp2formula(ir, r, f_root, freevar, ub, v, 's', IR_COND_EQ,
- false,uninterpreted_symbols[i],uninterpreted_symbols_stringrepr[i]);
+ false, uninterpreted_symbols[i], uninterpreted_symbols_stringrepr[i]);
/*if (ir->QueryExpOperation(
static_cast<IR_Loop *>(itn->content)->upper_bound())
== IR_OP_VARIABLE) {
@@ -724,29 +730,29 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
*/
}
}
-
+
r.setup_names();
r.simplify();
-
+
// THIS IS MISSING IN PROTONU's
for (int j = 0; j < insp_lb.size(); j++) {
-
+
std::string lb = insp_lb[j] + "_";
std::string ub = lb + "_";
-
+
Global_Var_ID u, l;
bool found_ub = false;
bool found_lb = false;
for (DNF_Iterator di(copy(r).query_DNF()); di; di++)
for (Constraint_Iterator ci = (*di)->constraints(); ci; ci++)
-
+
for (Constr_Vars_Iter cvi(*ci); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
if (v->kind() == Global_Var)
if (v->get_global_var()->arity() > 0) {
-
+
std::string name =
- v->get_global_var()->base_name();
+ v->get_global_var()->base_name();
if (name == lb) {
l = v->get_global_var();
found_lb = true;
@@ -755,9 +761,9 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
found_ub = true;
}
}
-
+
}
-
+
if (found_lb && found_ub) {
Relation known_(copy(r).n_set());
known_.copy_names(copy(r));
@@ -770,12 +776,12 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
g.update_coef(index_lb, -1);
g.update_const(-1);
addKnown(known_);
-
+
}
-
+
}
-
-
+
+
fprintf(stderr, "loop.cc L441 insert the statement\n");
// insert the statement
CG_outputBuilder *ocg = ir->builder();
@@ -785,36 +791,38 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
repl = ocg->CreateMinus(NULL, repl);
reverse_expr.push_back(repl);
}
- fprintf(stderr, "loop.cc before extract\n");
+ fprintf(stderr, "loop.cc before extract\n");
CG_outputRepr *code =
- static_cast<IR_Block *>(ir_stmt[loc]->content)->extract();
+ static_cast<IR_Block *>(ir_stmt[loc]->content)->extract();
fprintf(stderr, "code = ocg->CreateSubstitutedStmt(...)\n");
- ((CG_chillRepr *)code)->Dump(); fflush(stdout);
-
+ ((CG_chillRepr *) code)->Dump();
+ fflush(stdout);
+
code = ocg->CreateSubstitutedStmt(0, code, vars_to_be_reversed,
reverse_expr);
fprintf(stderr, "stmt\n");
- ((CG_chillRepr *)code)->Dump(); fflush(stdout);
+ ((CG_chillRepr *) code)->Dump();
+ fflush(stdout);
stmt[loc].code = code;
stmt[loc].IS = r;
-
+
//Anand: Add Information on uninterpreted function constraints to
//Known relation
-
- fprintf(stderr, "loop.cc stmt[%d].loop_level has size n_dim %d\n", loc, n_dim);
+
+ fprintf(stderr, "loop.cc stmt[%d].loop_level has size n_dim %d\n", loc, n_dim);
stmt[loc].loop_level = std::vector<LoopLevel>(n_dim);
stmt[loc].ir_stmt_node = ir_stmt[loc];
stmt[loc].has_inspector = false;
- fprintf(stderr, "for int i < n_dim(%d)\n", n_dim);
+ fprintf(stderr, "for int i < n_dim(%d)\n", n_dim);
for (int ii = 0; ii < n_dim; ii++) {
stmt[loc].loop_level[ii].type = LoopLevelOriginal;
stmt[loc].loop_level[ii].payload = ii;
stmt[loc].loop_level[ii].parallel_level = 0;
}
- fprintf(stderr, "whew\n");
-
+ fprintf(stderr, "whew\n");
+
stmt_nesting_level[loc] = -1;
}
dump();
@@ -824,36 +832,35 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree,
}
-
Loop::Loop(const IR_Control *control) {
-
- CHILL_DEBUG_PRINT("control type is %d ", control->type());
+
+ CHILL_DEBUG_PRINT("control type is %d \n", control->type());
echocontroltype(control);
- CHILL_DEBUG_PRINT("2set last_compute_cg_ = NULL; \n");
+ CHILL_DEBUG_PRINT("set last_compute_cg_ = NULL; \n");
last_compute_cgr_ = NULL;
last_compute_cg_ = NULL;
ir = const_cast<IR_Code *>(control->ir_); // point to the CHILL IR that this loop came from
- if (ir == 0) {
- CHILL_DEBUG_PRINT("ir gotten from control = 0x%x\n", (long)ir);
- CHILL_DEBUG_PRINT("loop.cc GONNA DIE SOON *******************************\n\n");
+ if (ir == 0) {
+ CHILL_DEBUG_PRINT("ir gotten from control = 0x%x\n", (long) ir);
+ CHILL_DEBUG_PRINT("GONNA DIE SOON *******************************\n\n");
}
-
+
init_code = NULL;
cleanup_code = NULL;
tmp_loop_var_name_counter = 1;
overflow_var_name_counter = 1;
known = Relation::True(0);
-
+
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());
-
+
// std::vector<ir_tree_node *> ir_stmt;
//fprintf(stderr, "loop.cc after build_ir_tree() %ld statements\n", stmt.size());
-
+
int count = 0;
//fprintf(stderr, "before init_loops, %d freevar\n", freevar.size());
//fprintf(stderr, "count %d\n", count++);
@@ -861,19 +868,19 @@ Loop::Loop(const IR_Control *control) {
while (!init_loop(ir_tree, ir_stmt)) {
//fprintf(stderr, "count %d\n", count++);
}
- fprintf(stderr, "after init_loop, %d freevar\n", (int)freevar.size());
-
-
- fprintf(stderr, "loop.cc after init_loop, %d statements\n", (int)stmt.size());
+ fprintf(stderr, "after init_loop, %d freevar\n", (int) freevar.size());
+
+
+ fprintf(stderr, "loop.cc after init_loop, %d statements\n", (int) stmt.size());
for (int i = 0; i < stmt.size(); i++) {
- std::map<int, CG_outputRepr*>::iterator it = replace.find(i);
-
+ std::map<int, CG_outputRepr *>::iterator it = replace.find(i);
+
if (it != replace.end())
stmt[i].code = it->second;
else
stmt[i].code = stmt[i].code;
}
-
+
if (stmt.size() != 0)
dep = DependenceGraph(stmt[0].IS.n_set());
else
@@ -881,42 +888,42 @@ Loop::Loop(const IR_Control *control) {
// init the dependence graph
for (int i = 0; i < stmt.size(); i++)
dep.insert();
-
- fprintf(stderr, "this really REALLY needs some comments\n");
+
+ fprintf(stderr, "this really REALLY needs some comments\n");
// this really REALLY needs some comments
for (int i = 0; i < stmt.size(); i++) {
- fprintf(stderr, "i %d\n", i);
+ fprintf(stderr, "i %d\n", i);
stmt[i].reduction = 0; // Manu -- initialization
for (int j = i; j < stmt.size(); j++) {
- fprintf(stderr, "j %d\n", j);
+ fprintf(stderr, "j %d\n", j);
std::pair<std::vector<DependenceVector>,
- std::vector<DependenceVector> > dv = test_data_dependences(
- ir,
- stmt[i].code,
- stmt[i].IS,
- stmt[j].code,
- stmt[j].IS,
- freevar,
- index,
- stmt_nesting_level_[i],
- stmt_nesting_level_[j],
- uninterpreted_symbols[ i ],
- uninterpreted_symbols_stringrepr[ i ]);
-
- fprintf(stderr, "dv.first.size() %d\n", (int)dv.first.size());
+ std::vector<DependenceVector> > dv = test_data_dependences(
+ ir,
+ stmt[i].code,
+ stmt[i].IS,
+ stmt[j].code,
+ stmt[j].IS,
+ freevar,
+ index,
+ stmt_nesting_level_[i],
+ stmt_nesting_level_[j],
+ uninterpreted_symbols[i],
+ uninterpreted_symbols_stringrepr[i]);
+
+ fprintf(stderr, "dv.first.size() %d\n", (int) dv.first.size());
for (int k = 0; k < dv.first.size(); k++) {
- fprintf(stderr, "k1 %d\n", k);
+ fprintf(stderr, "k1 %d\n", k);
if (is_dependence_valid(ir_stmt[i], ir_stmt[j], dv.first[k],
true))
dep.connect(i, j, dv.first[k]);
else {
dep.connect(j, i, dv.first[k].reverse());
}
-
+
}
-
- for (int k = 0; k < dv.second.size(); k++) {
- fprintf(stderr, "k2 %d\n", k);
+
+ for (int k = 0; k < dv.second.size(); k++) {
+ fprintf(stderr, "k2 %d\n", k);
if (is_dependence_valid(ir_stmt[j], ir_stmt[i], dv.second[k],
false))
dep.connect(j, i, dv.second[k]);
@@ -926,64 +933,64 @@ Loop::Loop(const IR_Control *control) {
}
}
}
-
- fprintf(stderr, "\n\n*** LOTS OF REDUCTIONS ***\n\n");
-
+
+ fprintf(stderr, "\n\n*** LOTS OF REDUCTIONS ***\n\n");
+
// TODO: Reduction check
// Manu:: Initial implementation / algorithm
std::set<int> reducCand = std::set<int>();
std::vector<int> canReduce = std::vector<int>();
- fprintf(stderr, "\ni range %d\n", stmt.size());
+ fprintf(stderr, "\ni range %d\n", stmt.size());
for (int i = 0; i < stmt.size(); i++) {
- fprintf(stderr, "i %d\n", i);
+ fprintf(stderr, "i %d\n", i);
if (!dep.hasEdge(i, i)) {
continue;
}
- fprintf(stderr, "dep.hasEdge(%d, %d)\n", i, i);
+ fprintf(stderr, "dep.hasEdge(%d, %d)\n", i, i);
// for each statement check if it has all the three dependences (RAW, WAR, WAW)
// If there is such a statement, it is a reduction candidate. Mark all reduction candidates.
std::vector<DependenceVector> tdv = dep.getEdge(i, i);
- fprintf(stderr, "tdv size %d\n", tdv.size());
+ fprintf(stderr, "tdv size %d\n", tdv.size());
for (int j = 0; j < tdv.size(); j++) {
- fprintf(stderr, "ij %d %d\n", i, j);
- if (tdv[j].is_reduction_cand) {
- fprintf(stderr, "reducCand.insert( %d )\n", i);
+ fprintf(stderr, "ij %d %d\n", i, j);
+ if (tdv[j].is_reduction_cand) {
+ fprintf(stderr, "reducCand.insert( %d )\n", i);
reducCand.insert(i);
}
}
}
-
- fprintf(stderr, "loop.cc reducCand.size() %d\n", reducCand.size());
+
+ fprintf(stderr, "loop.cc reducCand.size() %d\n", reducCand.size());
bool reduc;
std::set<int>::iterator it;
- int counter = 0;
+ int counter = 0;
for (it = reducCand.begin(); it != reducCand.end(); it++) {
- fprintf(stderr, "counter %d\n", counter);
+ fprintf(stderr, "counter %d\n", counter);
reduc = true;
for (int j = 0; j < stmt.size(); j++) {
- fprintf(stderr, "j %d\n", j);
+ fprintf(stderr, "j %d\n", j);
if ((*it != j)
&& (stmt_nesting_level_[*it] < stmt_nesting_level_[j])) {
if (dep.hasEdge(*it, j) || dep.hasEdge(j, *it)) {
- fprintf(stderr, "counter %d j %d reduc = false\n", counter, j);
+ fprintf(stderr, "counter %d j %d reduc = false\n", counter, j);
reduc = false;
break;
}
}
counter += 1;
}
-
+
if (reduc) {
- fprintf(stderr, "canReduce.push_back()\n");
+ fprintf(stderr, "canReduce.push_back()\n");
canReduce.push_back(*it);
stmt[*it].reduction = 2; // First, assume that reduction is possible with some processing
}
}
-
-
+
+
// If reduction is possible without processing, update the value of the reduction variable to 1
- fprintf(stderr, "loop.cc canReduce.size() %d\n", canReduce.size());
+ fprintf(stderr, "loop.cc canReduce.size() %d\n", canReduce.size());
for (int i = 0; i < canReduce.size(); i++) {
// Here, assuming that stmtType returns 1 when there is a single statement within stmt[i]
if (stmtType(ir, stmt[canReduce[i]].code) == 1) {
@@ -993,9 +1000,9 @@ Loop::Loop(const IR_Control *control) {
stmt[canReduce[i]].reductionOp = opType;
}
}
-
+
// printing out stuff for debugging
-
+
if (DEP_DEBUG) {
std::cout << "STATEMENTS THAT CAN BE REDUCED: \n";
for (int i = 0; i < canReduce.size(); i++) {
@@ -1015,21 +1022,21 @@ Loop::Loop(const IR_Control *control) {
}
}
// cleanup the IR tree
-
- fprintf(stderr, "init dumb transformation relations\n");
+
+ fprintf(stderr, "init dumb transformation relations\n");
// init dumb transformation relations e.g. [i, j] -> [ 0, i, 0, j, 0]
for (int i = 0; i < stmt.size(); i++) {
int n = stmt[i].IS.n_set();
stmt[i].xform = Relation(n, 2 * n + 1);
F_And *f_root = stmt[i].xform.add_and();
-
+
for (int j = 1; j <= n; j++) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(stmt[i].xform.output_var(2 * j), 1);
h.update_coef(stmt[i].xform.input_var(j), -1);
}
-
+
for (int j = 1; j <= 2 * n + 1; j += 2) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(stmt[i].xform.output_var(j), 1);
@@ -1037,7 +1044,7 @@ Loop::Loop(const IR_Control *control) {
stmt[i].xform.simplify();
}
//fprintf(stderr, "done with dumb\n");
-
+
if (stmt.size() != 0)
num_dep_dim = stmt[0].IS.n_set();
else
@@ -1056,19 +1063,19 @@ Loop::Loop(const IR_Control *control) {
}
Loop::~Loop() {
-
+
delete last_compute_cgr_;
delete last_compute_cg_;
-
+
for (int i = 0; i < stmt.size(); i++)
if (stmt[i].code != NULL) {
stmt[i].code->clear();
delete stmt[i].code;
}
-
+
for (int i = 0; i < ir_tree.size(); i++)
delete ir_tree[i];
-
+
if (init_code != NULL) {
init_code->clear();
delete init_code;
@@ -1080,54 +1087,52 @@ Loop::~Loop() {
}
-
-
int Loop::get_dep_dim_of(int stmt_num, int level) const {
if (stmt_num < 0 || stmt_num >= stmt.size())
throw std::invalid_argument("invaid statement " + to_string(stmt_num));
-
+
if (level < 1 || level > stmt[stmt_num].loop_level.size())
return -1;
-
+
int trip_count = 0;
while (true) {
switch (stmt[stmt_num].loop_level[level - 1].type) {
- case LoopLevelOriginal:
- return stmt[stmt_num].loop_level[level - 1].payload;
- case LoopLevelTile:
- level = stmt[stmt_num].loop_level[level - 1].payload;
- if (level < 1)
- return -1;
- if (level > stmt[stmt_num].loop_level.size())
- throw loop_error("incorrect loop level information for statement "
- + to_string(stmt_num));
- break;
- default:
- throw loop_error(
- "unknown loop level information for statement "
- + to_string(stmt_num));
+ case LoopLevelOriginal:
+ return stmt[stmt_num].loop_level[level - 1].payload;
+ case LoopLevelTile:
+ level = stmt[stmt_num].loop_level[level - 1].payload;
+ if (level < 1)
+ return -1;
+ if (level > stmt[stmt_num].loop_level.size())
+ throw loop_error("incorrect loop level information for statement "
+ + to_string(stmt_num));
+ break;
+ default:
+ throw loop_error(
+ "unknown loop level information for statement "
+ + to_string(stmt_num));
}
trip_count++;
if (trip_count >= stmt[stmt_num].loop_level.size())
throw loop_error(
- "incorrect loop level information for statement "
- + to_string(stmt_num));
+ "incorrect loop level information for statement "
+ + to_string(stmt_num));
}
}
int Loop::get_last_dep_dim_before(int stmt_num, int level) const {
if (stmt_num < 0 || stmt_num >= stmt.size())
throw std::invalid_argument("invaid statement " + to_string(stmt_num));
-
+
if (level < 1)
return -1;
if (level > stmt[stmt_num].loop_level.size())
level = stmt[stmt_num].loop_level.size() + 1;
-
+
for (int i = level - 1; i >= 1; i--)
if (stmt[stmt_num].loop_level[i - 1].type == LoopLevelOriginal)
return stmt[stmt_num].loop_level[i - 1].payload;
-
+
return -1;
}
@@ -1139,14 +1144,14 @@ void Loop::print_internal_loop_structure() const {
if (2 * j < lex.size())
std::cout << lex[2 * j];
switch (stmt[i].loop_level[j].type) {
- case LoopLevelOriginal:
- std::cout << "(dim:" << stmt[i].loop_level[j].payload << ")";
- break;
- case LoopLevelTile:
- std::cout << "(tile:" << stmt[i].loop_level[j].payload << ")";
- break;
- default:
- std::cout << "(unknown)";
+ case LoopLevelOriginal:
+ std::cout << "(dim:" << stmt[i].loop_level[j].payload << ")";
+ break;
+ case LoopLevelTile:
+ std::cout << "(tile:" << stmt[i].loop_level[j].payload << ")";
+ break;
+ default:
+ std::cout << "(unknown)";
}
std::cout << ' ';
}
@@ -1159,96 +1164,102 @@ void Loop::print_internal_loop_structure() const {
}
}
-void Loop::debugRelations() const {
- const int m = stmt.size();
+void Loop::debugRelations() const {
+ const int m = stmt.size();
{
std::vector<Relation> IS(m);
std::vector<Relation> xforms(m);
-
+
for (int i = 0; i < m; i++) {
IS[i] = stmt[i].IS;
xforms[i] = stmt[i].xform; // const stucks
}
-
- printf("\nxforms:\n");
- for (int i = 0; i < m; i++) { xforms[i].print(); printf("\n"); }
- printf("\nIS:\n");
- for (int i = 0; i < m; i++) { IS[i].print(); printf("\n"); }
- fflush(stdout);
+
+ printf("\nxforms:\n");
+ for (int i = 0; i < m; i++) {
+ xforms[i].print();
+ printf("\n");
+ }
+ printf("\nIS:\n");
+ for (int i = 0; i < m; i++) {
+ IS[i].print();
+ printf("\n");
+ }
+ fflush(stdout);
}
}
CG_outputRepr *Loop::getCode(int effort) const {
- fprintf(stderr,"\nloop.cc Loop::getCode( effort %d )\n", effort );
-
+ fprintf(stderr, "\nloop.cc Loop::getCode( effort %d )\n", effort);
+
const int m = stmt.size();
if (m == 0)
return NULL;
const int n = stmt[0].xform.n_out();
-
+
if (last_compute_cg_ == NULL) {
- fprintf(stderr, "Loop::getCode() last_compute_cg_ == NULL\n");
-
+ fprintf(stderr, "Loop::getCode() last_compute_cg_ == NULL\n");
+
std::vector<Relation> IS(m);
std::vector<Relation> xforms(m);
for (int i = 0; i < m; i++) {
IS[i] = stmt[i].IS;
xforms[i] = stmt[i].xform;
}
-
- debugRelations();
-
-
+
+ debugRelations();
+
+
Relation known = Extend_Set(copy(this->known), n - this->known.n_set());
- printf("\nknown:\n"); known.print(); printf("\n\n"); fflush(stdout);
-
+ printf("\nknown:\n");
+ known.print();
+ printf("\n\n");
+ fflush(stdout);
+
last_compute_cg_ = new CodeGen(xforms, IS, known);
delete last_compute_cgr_;
last_compute_cgr_ = NULL;
- }
- else {
- fprintf(stderr, "Loop::getCode() last_compute_cg_ NOT NULL\n");
+ } else {
+ fprintf(stderr, "Loop::getCode() last_compute_cg_ NOT NULL\n");
}
-
+
if (last_compute_cgr_ == NULL || last_compute_effort_ != effort) {
delete last_compute_cgr_;
last_compute_cgr_ = last_compute_cg_->buildAST(effort);
last_compute_effort_ = effort;
}
-
+
std::vector<CG_outputRepr *> stmts(m);
- fprintf(stderr, "%d stmts\n", m);
+ fprintf(stderr, "%d stmts\n", m);
for (int i = 0; i < m; i++)
stmts[i] = stmt[i].code;
CG_outputBuilder *ocg = ir->builder();
- fprintf(stderr, "calling last_compute_cgr_->printRepr()\n");
- CG_outputRepr *repr = last_compute_cgr_->printRepr(ocg, stmts,
+ fprintf(stderr, "calling last_compute_cgr_->printRepr()\n");
+ CG_outputRepr *repr = last_compute_cgr_->printRepr(ocg, stmts,
uninterpreted_symbols);
-
+
if (init_code != NULL)
repr = ocg->StmtListAppend(init_code->clone(), repr);
if (cleanup_code != NULL)
repr = ocg->StmtListAppend(repr, cleanup_code->clone());
-
- fprintf(stderr,"\nloop.cc Loop::getCode( effort %d ) DONE\n", effort );
+
+ fprintf(stderr, "\nloop.cc Loop::getCode( effort %d ) DONE\n", effort);
return repr;
}
-
-
void Loop::printCode(int effort) const {
- fprintf(stderr,"\nloop.cc Loop::printCode( effort %d )\n", effort );
+ fprintf(stderr, "\nloop.cc Loop::printCode( effort %d )\n", effort);
const int m = stmt.size();
if (m == 0)
return;
const int n = stmt[0].xform.n_out();
-
+
if (last_compute_cg_ == NULL) {
- fprintf(stderr, "Loop::printCode(), last_compute_cg_ == NULL\n");
+ fprintf(stderr, "Loop::printCode(), last_compute_cg_ == NULL\n");
std::vector<Relation> IS(m);
std::vector<Relation> xforms(m);
for (int i = 0; i < m; i++) {
@@ -1256,22 +1267,21 @@ void Loop::printCode(int effort) const {
xforms[i] = stmt[i].xform;
}
Relation known = Extend_Set(copy(this->known), n - this->known.n_set());
-
+
last_compute_cg_ = new CodeGen(xforms, IS, known);
delete last_compute_cgr_;
last_compute_cgr_ = NULL;
- }
- else fprintf(stderr, "Loop::printCode(), last_compute_cg_ NOT NULL\n");
-
+ } else fprintf(stderr, "Loop::printCode(), last_compute_cg_ NOT NULL\n");
+
if (last_compute_cgr_ == NULL || last_compute_effort_ != effort) {
delete last_compute_cgr_;
last_compute_cgr_ = last_compute_cg_->buildAST(effort);
last_compute_effort_ = effort;
}
-
+
std::string repr = last_compute_cgr_->printString(
- uninterpreted_symbols_stringrepr);
- fprintf(stderr, "leaving Loop::printCode()\n");
+ uninterpreted_symbols_stringrepr);
+ fprintf(stderr, "leaving Loop::printCode()\n");
std::cout << repr << std::endl;
}
@@ -1297,20 +1307,20 @@ void Loop::printDependenceGraph() const {
std::vector<Relation> Loop::getNewIS() const {
const int m = stmt.size();
-
+
std::vector<Relation> new_IS(m);
for (int i = 0; i < m; i++)
new_IS[i] = getNewIS(i);
-
+
return new_IS;
}
// pragmas are tied to loops only ???
void Loop::pragma(int stmt_num, int level, const std::string &pragmaText) {
// check sanity of parameters
- if(stmt_num < 0)
+ if (stmt_num < 0)
throw std::invalid_argument("invalid statement " + to_string(stmt_num));
-
+
CG_outputBuilder *ocg = ir->builder();
CG_outputRepr *code = stmt[stmt_num].code;
ocg->CreatePragmaAttribute(code, level, pragmaText);
@@ -1331,9 +1341,9 @@ void Loop::pragma(int stmt_num, int level, const std::string &pragmaText) {
void Loop::prefetch(int stmt_num, int level, const std::string &arrName, int hint) {
// check sanity of parameters
- if(stmt_num < 0)
+ if (stmt_num < 0)
throw std::invalid_argument("invalid statement " + to_string(stmt_num));
-
+
CG_outputBuilder *ocg = ir->builder();
CG_outputRepr *code = stmt[stmt_num].code;
ocg->CreatePrefetchAttribute(code, level, arrName, hint);
@@ -1341,13 +1351,13 @@ void Loop::prefetch(int stmt_num, int level, const std::string &arrName, int hin
std::vector<int> Loop::getLexicalOrder(int stmt_num) const {
assert(stmt_num < stmt.size());
-
+
const int n = stmt[stmt_num].xform.n_out();
std::vector<int> lex(n, 0);
-
+
for (int i = 0; i < n; i += 2)
lex[i] = get_const(stmt[stmt_num].xform, i, Output_Var);
-
+
return lex;
}
@@ -1356,13 +1366,13 @@ std::vector<int> Loop::getLexicalOrder(int stmt_num) const {
std::set<int> Loop::getSubLoopNest(int stmt_num, int level) const {
assert(stmt_num >= 0 && stmt_num < stmt.size());
assert(level > 0 && level <= stmt[stmt_num].loop_level.size());
-
+
std::set<int> working;
for (int i = 0; i < stmt.size(); i++)
if (const_cast<Loop *>(this)->stmt[i].IS.is_upper_bound_satisfiable()
&& stmt[i].loop_level.size() >= level)
working.insert(i);
-
+
for (int i = 1; i <= level; i++) {
int a = getLexicalOrder(stmt_num, i);
for (std::set<int>::iterator j = working.begin(); j != working.end();) {
@@ -1373,14 +1383,14 @@ std::set<int> Loop::getSubLoopNest(int stmt_num, int level) const {
++j;
}
}
-
+
return working;
}
int Loop::getLexicalOrder(int stmt_num, int level) const {
assert(stmt_num >= 0 && stmt_num < stmt.size());
- assert(level > 0 && level <= stmt[stmt_num].loop_level.size()+1);
-
+ assert(level > 0 && level <= stmt[stmt_num].loop_level.size() + 1);
+
Relation &r = const_cast<Loop *>(this)->stmt[stmt_num].xform;
for (EQ_Iterator e(r.single_conjunct()->EQs()); e; e++)
if (abs((*e).get_coef(r.output_var(2 * level - 1))) == 1) {
@@ -1395,15 +1405,15 @@ int Loop::getLexicalOrder(int stmt_num, int level) const {
return (*e).get_coef(r.output_var(2 * level - 1)) > 0 ? -t : t;
}
}
-
+
throw loop_error(
- "can't find lexical order for statement " + to_string(stmt_num)
- + "'s loop level " + to_string(level));
+ "can't find lexical order for statement " + to_string(stmt_num)
+ + "'s loop level " + to_string(level));
}
std::set<int> Loop::getStatements(const std::vector<int> &lex, int dim) const {
const int m = stmt.size();
-
+
std::set<int> same_loops;
for (int i = 0; i < m; i++) {
if (dim < 0)
@@ -1417,32 +1427,32 @@ std::set<int> Loop::getStatements(const std::vector<int> &lex, int dim) const {
if (j > dim)
same_loops.insert(i);
}
-
+
}
-
+
return same_loops;
}
void Loop::shiftLexicalOrder(const std::vector<int> &lex, int dim, int amount) {
const int m = stmt.size();
-
+
if (amount == 0)
return;
-
+
for (int i = 0; i < m; i++) {
std::vector<int> lex2 = getLexicalOrder(i);
-
+
bool need_shift = true;
-
+
for (int j = 0; j < dim; j++)
if (lex2[j] != lex[j]) {
need_shift = false;
break;
}
-
+
if (!need_shift)
continue;
-
+
if (amount > 0) {
if (lex2[dim] < lex[dim])
continue;
@@ -1450,94 +1460,94 @@ void Loop::shiftLexicalOrder(const std::vector<int> &lex, int dim, int amount) {
if (lex2[dim] > lex[dim])
continue;
}
-
+
assign_const(stmt[i].xform, dim, lex2[dim] + amount);
}
}
std::vector<std::set<int> > Loop::sort_by_same_loops(std::set<int> active,
int level) {
-
+
std::set<int> not_nested_at_this_level;
- std::map<ir_tree_node*, std::set<int> > sorted_by_loop;
+ std::map<ir_tree_node *, std::set<int> > sorted_by_loop;
std::map<int, std::set<int> > sorted_by_lex_order;
std::vector<std::set<int> > to_return;
bool lex_order_already_set = false;
for (std::set<int>::iterator it = active.begin(); it != active.end();
it++) {
-
+
if (stmt[*it].ir_stmt_node == NULL)
lex_order_already_set = true;
}
-
+
if (lex_order_already_set) {
-
+
for (std::set<int>::iterator it = active.begin(); it != active.end();
it++) {
std::map<int, std::set<int> >::iterator it2 =
- sorted_by_lex_order.find(
- get_const(stmt[*it].xform, 2 * (level - 1),
- Output_Var));
-
+ sorted_by_lex_order.find(
+ get_const(stmt[*it].xform, 2 * (level - 1),
+ Output_Var));
+
if (it2 != sorted_by_lex_order.end())
it2->second.insert(*it);
else {
-
+
std::set<int> to_insert;
-
+
to_insert.insert(*it);
-
+
sorted_by_lex_order.insert(
- std::pair<int, std::set<int> >(
- get_const(stmt[*it].xform, 2 * (level - 1),
- Output_Var), to_insert));
-
+ std::pair<int, std::set<int> >(
+ get_const(stmt[*it].xform, 2 * (level - 1),
+ Output_Var), to_insert));
+
}
-
+
}
-
+
for (std::map<int, std::set<int> >::iterator it2 =
- sorted_by_lex_order.begin(); it2 != sorted_by_lex_order.end();
+ sorted_by_lex_order.begin(); it2 != sorted_by_lex_order.end();
it2++)
to_return.push_back(it2->second);
-
+
} else {
-
+
for (std::set<int>::iterator it = active.begin(); it != active.end();
it++) {
-
- ir_tree_node* itn = stmt[*it].ir_stmt_node;
+
+ ir_tree_node *itn = stmt[*it].ir_stmt_node;
itn = itn->parent;
//while (itn->content->type() != IR_CONTROL_LOOP && itn != NULL)
// itn = itn->parent;
-
+
while ((itn != NULL) && (itn->payload != level - 1)) {
itn = itn->parent;
- while (itn != NULL && itn->content->type() != IR_CONTROL_LOOP )
+ while (itn != NULL && itn->content->type() != IR_CONTROL_LOOP)
itn = itn->parent;
}
-
+
if (itn == NULL)
not_nested_at_this_level.insert(*it);
else {
- std::map<ir_tree_node*, std::set<int> >::iterator it2 =
- sorted_by_loop.find(itn);
-
+ std::map<ir_tree_node *, std::set<int> >::iterator it2 =
+ sorted_by_loop.find(itn);
+
if (it2 != sorted_by_loop.end())
it2->second.insert(*it);
else {
std::set<int> to_insert;
-
+
to_insert.insert(*it);
-
+
sorted_by_loop.insert(
- std::pair<ir_tree_node*, std::set<int> >(itn,
- to_insert));
-
+ std::pair<ir_tree_node *, std::set<int> >(itn,
+ to_insert));
+
}
-
+
}
-
+
}
if (not_nested_at_this_level.size() > 0) {
for (std::set<int>::iterator it = not_nested_at_this_level.begin();
@@ -1545,34 +1555,34 @@ std::vector<std::set<int> > Loop::sort_by_same_loops(std::set<int> active,
std::set<int> temp;
temp.insert(*it);
to_return.push_back(temp);
-
+
}
}
- for (std::map<ir_tree_node*, std::set<int> >::iterator it2 =
- sorted_by_loop.begin(); it2 != sorted_by_loop.end(); it2++)
+ for (std::map<ir_tree_node *, std::set<int> >::iterator it2 =
+ sorted_by_loop.begin(); it2 != sorted_by_loop.end(); it2++)
to_return.push_back(it2->second);
}
return to_return;
}
-void update_successors(int n,
- int node_num[],
+void update_successors(int n,
+ int node_num[],
int cant_fuse_with[],
- Graph<std::set<int>, bool> &g,
+ Graph<std::set<int>, bool> &g,
std::list<int> &work_list,
- std::list<bool> &type_list,
+ std::list<bool> &type_list,
std::vector<bool> types) {
-
+
std::set<int> disconnect;
for (Graph<std::set<int>, bool>::EdgeList::iterator i =
- g.vertex[n].second.begin(); i != g.vertex[n].second.end(); i++) {
+ g.vertex[n].second.begin(); i != g.vertex[n].second.end(); i++) {
int m = i->first;
-
+
if (node_num[m] != -1)
throw loop_error("Graph input for fusion has cycles not a DAG!!");
-
+
std::vector<bool> check_ = g.getEdge(n, m);
-
+
bool has_bad_edge_path = false;
for (int i = 0; i < check_.size(); i++)
if (!check_[i]) {
@@ -1589,12 +1599,12 @@ void update_successors(int n,
}
disconnect.insert(m);
}
-
-
+
+
for (std::set<int>::iterator i = disconnect.begin(); i != disconnect.end();
i++) {
g.disconnect(n, *i);
-
+
bool no_incoming_edges = true;
for (int j = 0; j < g.vertex.size(); j++)
if (j != *i)
@@ -1602,7 +1612,7 @@ void update_successors(int n,
no_incoming_edges = false;
break;
}
-
+
if (no_incoming_edges) {
work_list.push_back(*i);
type_list.push_back(types[*i]);
@@ -1611,35 +1621,32 @@ void update_successors(int n,
}
-
int Loop::getMinLexValue(std::set<int> stmts, int level) {
-
+
int min;
-
+
std::set<int>::iterator it = stmts.begin();
min = getLexicalOrder(*it, level);
-
+
for (; it != stmts.end(); it++) {
int curr = getLexicalOrder(*it, level);
if (curr < min)
min = curr;
}
-
+
return min;
}
-
-
Graph<std::set<int>, bool> Loop::construct_induced_graph_at_level(
- std::vector<std::set<int> > s, DependenceGraph dep, int dep_dim) {
+ std::vector<std::set<int> > s, DependenceGraph dep, int dep_dim) {
Graph<std::set<int>, bool> g;
-
+
for (int i = 0; i < s.size(); i++)
g.insert(s[i]);
-
+
for (int i = 0; i < s.size(); i++) {
-
+
for (int j = i + 1; j < s.size(); j++) {
bool has_true_edge_i_to_j = false;
bool has_true_edge_j_to_i = false;
@@ -1647,32 +1654,32 @@ Graph<std::set<int>, bool> Loop::construct_induced_graph_at_level(
bool is_connected_j_to_i = false;
for (std::set<int>::iterator ii = s[i].begin(); ii != s[i].end();
ii++) {
-
+
for (std::set<int>::iterator jj = s[j].begin();
jj != s[j].end(); jj++) {
-
+
std::vector<DependenceVector> dvs = dep.getEdge(*ii, *jj);
for (int k = 0; k < dvs.size(); k++)
if (dvs[k].is_control_dependence()
|| (dvs[k].is_data_dependence()
&& dvs[k].has_been_carried_at(dep_dim))) {
-
+
if (dvs[k].is_data_dependence()
&& dvs[k].has_negative_been_carried_at(
- dep_dim)) {
+ dep_dim)) {
//g.connect(i, j, false);
is_connected_i_to_j = true;
break;
} else {
//g.connect(i, j, true);
-
+
has_true_edge_i_to_j = true;
//break
}
}
-
+
//if (is_connected)
-
+
// break;
// if (has_true_edge_i_to_j && !is_connected_i_to_j)
// g.connect(i, j, true);
@@ -1681,72 +1688,71 @@ Graph<std::set<int>, bool> Loop::construct_induced_graph_at_level(
if (dvs[k].is_control_dependence()
|| (dvs[k].is_data_dependence()
&& dvs[k].has_been_carried_at(dep_dim))) {
-
+
if (is_connected_i_to_j || has_true_edge_i_to_j)
throw loop_error(
- "Graph input for fusion has cycles not a DAG!!");
-
+ "Graph input for fusion has cycles not a DAG!!");
+
if (dvs[k].is_data_dependence()
&& dvs[k].has_negative_been_carried_at(
- dep_dim)) {
+ dep_dim)) {
//g.connect(i, j, false);
is_connected_j_to_i = true;
break;
} else {
//g.connect(i, j, true);
-
+
has_true_edge_j_to_i = true;
//break;
}
}
-
+
// if (is_connected)
//break;
// if (is_connected)
//break;
}
-
+
//if (is_connected)
// break;
}
-
-
+
+
if (is_connected_i_to_j)
g.connect(i, j, false);
else if (has_true_edge_i_to_j)
g.connect(i, j, true);
-
+
if (is_connected_j_to_i)
g.connect(j, i, false);
else if (has_true_edge_j_to_i)
g.connect(j, i, true);
-
+
}
}
return g;
}
-
std::vector<std::set<int> > Loop::typed_fusion(Graph<std::set<int>, bool> g,
std::vector<bool> &types) {
-
+
bool roots[g.vertex.size()];
-
+
for (int i = 0; i < g.vertex.size(); i++)
roots[i] = true;
-
+
for (int i = 0; i < g.vertex.size(); i++)
for (int j = i + 1; j < g.vertex.size(); j++) {
-
+
if (g.hasEdge(i, j))
roots[j] = false;
-
+
if (g.hasEdge(j, i))
roots[i] = false;
-
+
}
-
+
std::list<int> work_list;
std::list<bool> type_list;
int cant_fuse_with[g.vertex.size()];
@@ -1755,11 +1761,11 @@ std::vector<std::set<int> > Loop::typed_fusion(Graph<std::set<int>, bool> g,
int lastnum = 0;
std::vector<std::set<int> > s;
//Each Fused set's representative node
-
+
int node_to_fused_nodes[g.vertex.size()];
int node_num[g.vertex.size()];
int next[g.vertex.size()];
-
+
for (int i = 0; i < g.vertex.size(); i++) {
if (roots[i] == true) {
work_list.push_back(i);
@@ -1770,17 +1776,17 @@ std::vector<std::set<int> > Loop::typed_fusion(Graph<std::set<int>, bool> g,
node_num[i] = -1;
next[i] = 0;
}
-
-
+
+
// topological sort according to chun's permute algorithm
// std::vector<std::set<int> > s = g.topoSort();
std::vector<std::set<int> > s2 = g.topoSort();
if (work_list.empty() || (s2.size() != g.vertex.size())) {
-
+
std::cout << s2.size() << "\t" << g.vertex.size() << std::endl;
throw loop_error("Input for fusion not a DAG!!");
-
-
+
+
}
int fused_nodes_counter = 0;
while (!work_list.empty()) {
@@ -1802,19 +1808,19 @@ std::vector<std::set<int> > Loop::typed_fusion(Graph<std::set<int>, bool> g,
p = fused;
else
p = next[cant_fuse_with[n]];
-
+
if (p != 0) {
int rep_node = node_to_fused_nodes[p];
node_num[n] = node_num[rep_node];
-
+
try {
update_successors(n, node_num, cant_fuse_with, g, work_list,
type_list, types);
} catch (const loop_error &e) {
-
+
throw loop_error(
- "statements cannot be fused together due to negative dependence");
-
+ "statements cannot be fused together due to negative dependence");
+
}
for (std::set<int>::iterator it = g.vertex[n].first.begin();
it != g.vertex[n].first.end(); it++)
@@ -1826,81 +1832,80 @@ std::vector<std::set<int> > Loop::typed_fusion(Graph<std::set<int>, bool> g,
lastnum = lastnum + 1;
node_num[n] = lastnum;
node_to_fused_nodes[node_num[n]] = n;
-
+
if (lastfused == 0) {
fused = lastnum;
lastfused = fused;
} else {
next[lastfused] = lastnum;
lastfused = lastnum;
-
+
}
-
+
try {
update_successors(n, node_num, cant_fuse_with, g, work_list,
type_list, types);
} catch (const loop_error &e) {
-
+
throw loop_error(
- "statements cannot be fused together due to negative dependence");
-
+ "statements cannot be fused together due to negative dependence");
+
}
fused_nodes_counter++;
}
-
+
} else {
s.push_back(g.vertex[n].first);
lastnum = lastnum + 1;
node_num[n] = lastnum;
node_to_fused_nodes[node_num[n]] = n;
-
+
try {
update_successors(n, node_num, cant_fuse_with, g, work_list,
type_list, types);
} catch (const loop_error &e) {
-
+
throw loop_error(
- "statements cannot be fused together due to negative dependence");
-
+ "statements cannot be fused together due to negative dependence");
+
}
//fused_nodes_counter++;
-
+
}
-
+
}
-
+
return s;
}
-
-
void Loop::setLexicalOrder(int dim, const std::set<int> &active,
int starting_order, std::vector<std::vector<std::string> > idxNames) {
- fprintf(stderr, "Loop::setLexicalOrder() %d idxNames active size %d starting_order %d\n", idxNames.size(), active.size(), starting_order);
+ fprintf(stderr, "Loop::setLexicalOrder() %d idxNames active size %d starting_order %d\n", idxNames.size(),
+ active.size(), starting_order);
if (active.size() == 0)
return;
- for (int i=0; i< idxNames.size(); i++) {
+ for (int i = 0; i < idxNames.size(); i++) {
std::vector<std::string> what = idxNames[i];
- for (int j=0; j<what.size(); j++) {
- fprintf(stderr, "%2d %2d %s\n", i,j, what[j].c_str());
+ for (int j = 0; j < what.size(); j++) {
+ fprintf(stderr, "%2d %2d %s\n", i, j, what[j].c_str());
}
}
// check for sanity of parameters
if (dim < 0 || dim % 2 != 0)
throw std::invalid_argument(
- "invalid constant loop level to set lexicographical order");
+ "invalid constant loop level to set lexicographical order");
std::vector<int> lex;
int ref_stmt_num;
for (std::set<int>::iterator i = active.begin(); i != active.end(); i++) {
if ((*i) < 0 || (*i) >= stmt.size())
throw std::invalid_argument(
- "invalid statement number " + to_string(*i));
+ "invalid statement number " + to_string(*i));
if (dim >= stmt[*i].xform.n_out())
throw std::invalid_argument(
- "invalid constant loop level to set lexicographical order");
+ "invalid constant loop level to set lexicographical order");
if (i == active.begin()) {
lex = getLexicalOrder(*i);
ref_stmt_num = *i;
@@ -1909,10 +1914,10 @@ void Loop::setLexicalOrder(int dim, const std::set<int> &active,
for (int j = 0; j < dim; j += 2)
if (lex[j] != lex2[j])
throw std::invalid_argument(
- "statements are not in the same sub loop nest");
+ "statements are not in the same sub loop nest");
}
}
-
+
// separate statements by current loop level types
int level = (dim + 2) / 2;
std::map<std::pair<LoopLevelType, int>, std::set<int> > active_by_level_type;
@@ -1922,21 +1927,21 @@ void Loop::setLexicalOrder(int dim, const std::set<int> &active,
active_by_no_level.insert(*i);
else
active_by_level_type[std::make_pair(
- stmt[*i].loop_level[level - 1].type,
- stmt[*i].loop_level[level - 1].payload)].insert(*i);
+ stmt[*i].loop_level[level - 1].type,
+ stmt[*i].loop_level[level - 1].payload)].insert(*i);
}
-
+
// further separate statements due to control dependences
std::vector<std::set<int> > active_by_level_type_splitted;
for (std::map<std::pair<LoopLevelType, int>, std::set<int> >::iterator i =
- active_by_level_type.begin(); i != active_by_level_type.end(); i++)
+ active_by_level_type.begin(); i != active_by_level_type.end(); i++)
active_by_level_type_splitted.push_back(i->second);
for (std::set<int>::iterator i = active_by_no_level.begin();
i != active_by_no_level.end(); i++)
for (int j = active_by_level_type_splitted.size() - 1; j >= 0; j--) {
std::set<int> controlled, not_controlled;
for (std::set<int>::iterator k =
- active_by_level_type_splitted[j].begin();
+ active_by_level_type_splitted[j].begin();
k != active_by_level_type_splitted[j].end(); k++) {
std::vector<DependenceVector> dvs = dep.getEdge(*i, *k);
bool is_controlled = false;
@@ -1952,19 +1957,19 @@ void Loop::setLexicalOrder(int dim, const std::set<int> &active,
}
if (controlled.size() != 0 && not_controlled.size() != 0) {
active_by_level_type_splitted.erase(
- active_by_level_type_splitted.begin() + j);
+ active_by_level_type_splitted.begin() + j);
active_by_level_type_splitted.push_back(controlled);
active_by_level_type_splitted.push_back(not_controlled);
}
}
-
+
// set lexical order separating loops with different loop types first
if (active_by_level_type_splitted.size() + active_by_no_level.size() > 1) {
int dep_dim = get_last_dep_dim_before(ref_stmt_num, level) + 1;
-
+
Graph<std::set<int>, Empty> g;
for (std::vector<std::set<int> >::iterator i =
- active_by_level_type_splitted.begin();
+ active_by_level_type_splitted.begin();
i != active_by_level_type_splitted.end(); i++)
g.insert(*i);
for (std::set<int>::iterator i = active_by_no_level.begin();
@@ -1986,7 +1991,7 @@ void Loop::setLexicalOrder(int dim, const std::set<int> &active,
if (dvs[k].is_control_dependence()
|| (dvs[k].is_data_dependence()
&& !dvs[k].has_been_carried_before(
- dep_dim))) {
+ dep_dim))) {
g.connect(i, j);
connected = true;
break;
@@ -2010,7 +2015,7 @@ void Loop::setLexicalOrder(int dim, const std::set<int> &active,
if (dvs[k].is_control_dependence()
|| (dvs[k].is_data_dependence()
&& !dvs[k].has_been_carried_before(
- dep_dim))) {
+ dep_dim))) {
g.connect(j, i);
connected = true;
break;
@@ -2022,13 +2027,13 @@ void Loop::setLexicalOrder(int dim, const std::set<int> &active,
break;
}
}
-
+
std::vector<std::set<int> > s = g.topoSort();
if (s.size() != g.vertex.size())
throw loop_error(
- "cannot separate statements with different loop types at loop level "
- + to_string(level));
-
+ "cannot separate statements with different loop types at loop level "
+ + to_string(level));
+
// assign lexical order
int order = starting_order;
for (int i = 0; i < s.size(); i++) {
@@ -2041,19 +2046,18 @@ void Loop::setLexicalOrder(int dim, const std::set<int> &active,
assign_const(stmt[cur_stmt].xform, j, 0);
order++;
} else { // recurse !
- fprintf(stderr, "Loop:setLexicalOrder() recursing\n");
+ fprintf(stderr, "Loop:setLexicalOrder() recursing\n");
setLexicalOrder(dim, cur_scc, order, idxNames);
order += sz;
}
}
- }
- else { // set lexical order separating single iteration statements and loops
+ } else { // set lexical order separating single iteration statements and loops
std::set<int> true_singles;
std::set<int> nonsingles;
std::map<coef_t, std::set<int> > fake_singles;
std::set<int> fake_singles_;
-
+
// sort out statements that do not require loops
for (std::set<int>::iterator i = active.begin(); i != active.end();
i++) {
@@ -2071,7 +2075,7 @@ void Loop::setLexicalOrder(int dim, const std::set<int> &active,
fake_singles_.insert(*i);
try {
fake_singles[get_const(cur_IS, dim + 1, Set_Var)].insert(
- *i);
+ *i);
} catch (const std::exception &e) {
fake_singles[posInfinity].insert(*i);
}
@@ -2079,60 +2083,60 @@ void Loop::setLexicalOrder(int dim, const std::set<int> &active,
} else
nonsingles.insert(*i);
}
-
-
+
+
// split nonsingles forcibly according to negative dependences present (loop unfusible)
int dep_dim = get_dep_dim_of(ref_stmt_num, level);
-
+
if (dim < stmt[ref_stmt_num].xform.n_out() - 1) {
-
+
bool dummy_level_found = false;
-
+
std::vector<std::set<int> > s;
-
+
s = sort_by_same_loops(active, level);
bool further_levels_exist = false;
-
+
if (!idxNames.empty())
if (level <= idxNames[ref_stmt_num].size())
if (idxNames[ref_stmt_num][level - 1].length() == 0) {
// && s.size() == 1) {
int order1 = 0;
dummy_level_found = true;
-
+
for (int i = level; i < idxNames[ref_stmt_num].size();
i++)
if (idxNames[ref_stmt_num][i].length() > 0)
further_levels_exist = true;
-
+
}
-
+
//if (!dummy_level_found) {
-
+
if (s.size() > 1) {
-
+
std::vector<bool> types;
for (int i = 0; i < s.size(); i++)
types.push_back(true);
-
+
Graph<std::set<int>, bool> g = construct_induced_graph_at_level(
- s, dep, dep_dim);
+ s, dep, dep_dim);
s = typed_fusion(g, types);
}
int order = starting_order;
for (int i = 0; i < s.size(); i++) {
-
+
for (std::set<int>::iterator it = s[i].begin();
it != s[i].end(); it++) {
assign_const(stmt[*it].xform, dim, order);
stmt[*it].xform.simplify();
}
-
+
if ((dim + 2) <= (stmt[ref_stmt_num].xform.n_out() - 1)) { // recurse !
- fprintf(stderr, "Loop:setLexicalOrder() recursing\n");
+ fprintf(stderr, "Loop:setLexicalOrder() recursing\n");
setLexicalOrder(dim + 2, s[i], order, idxNames);
}
-
+
order++;
}
//}
@@ -2231,8 +2235,8 @@ void Loop::setLexicalOrder(int dim, const std::set<int> &active,
break;
}
*/
-
-
+
+
// assign lexical order
/*int order = starting_order;
for (int i = 0; i < s.size(); i++) {
@@ -2261,17 +2265,16 @@ void Loop::setLexicalOrder(int dim, const std::set<int> &active,
*/
}
- fprintf(stderr, "LEAVING Loop::setLexicalOrder() %d idxNames\n", idxNames.size());
- for (int i=0; i< idxNames.size(); i++) {
+ fprintf(stderr, "LEAVING Loop::setLexicalOrder() %d idxNames\n", idxNames.size());
+ for (int i = 0; i < idxNames.size(); i++) {
std::vector<std::string> what = idxNames[i];
- for (int j=0; j<what.size(); j++) {
- fprintf(stderr, "%2d %2d %s\n", i,j, what[j].c_str());
+ for (int j = 0; j < what.size(); j++) {
+ fprintf(stderr, "%2d %2d %s\n", i, j, what[j].c_str());
}
}
}
-
void Loop::apply_xform() {
std::set<int> active;
for (int i = 0; i < stmt.size(); i++)
@@ -2280,26 +2283,26 @@ void Loop::apply_xform() {
}
void Loop::apply_xform(int stmt_num) {
- fprintf(stderr, "apply_xform( %d )\n", stmt_num);
+ fprintf(stderr, "apply_xform( %d )\n", stmt_num);
std::set<int> active;
active.insert(stmt_num);
apply_xform(active);
}
void Loop::apply_xform(std::set<int> &active) {
- fflush(stdout);
+ fflush(stdout);
fprintf(stderr, "loop.cc apply_xform( set )\n");
-
+
int max_n = 0;
-
+
omega::CG_outputBuilder *ocg = ir->builder();
for (std::set<int>::iterator i = active.begin(); i != active.end(); i++) {
int n = stmt[*i].loop_level.size();
if (n > max_n)
max_n = n;
-
+
std::vector<int> lex = getLexicalOrder(*i);
-
+
omega::Relation mapping(2 * n + 1, n);
omega::F_And *f_root = mapping.add_and();
for (int j = 1; j <= n; j++) {
@@ -2309,7 +2312,7 @@ void Loop::apply_xform(std::set<int> &active) {
}
mapping = omega::Composition(mapping, stmt[*i].xform);
mapping.simplify();
-
+
// match omega input/output variables to variable names in the code
for (int j = 1; j <= stmt[*i].IS.n_set(); j++)
mapping.name_input_var(j, stmt[*i].IS.set_var(j)->name());
@@ -2317,28 +2320,28 @@ void Loop::apply_xform(std::set<int> &active) {
mapping.name_output_var(j,
tmp_loop_var_name_prefix
+ omega::to_string(
- tmp_loop_var_name_counter + j - 1));
+ tmp_loop_var_name_counter + j - 1));
mapping.setup_names();
mapping.print(); // "{[I] -> [_t1] : I = _t1 }
- fflush(stdout);
-
+ fflush(stdout);
+
omega::Relation known = Extend_Set(copy(this->known),
mapping.n_out() - this->known.n_set());
//stmt[*i].code = outputStatement(ocg, stmt[*i].code, 0, mapping, known, std::vector<CG_outputRepr *>(mapping.n_out(), NULL));
-
- omega::CG_outputBuilder *ocgr = ir->builder();
-
-
+
+ omega::CG_outputBuilder *ocgr = ir->builder();
+
+
//this is probably CG_chillBuilder;
-
+
omega::CG_stringBuilder *ocgs = new omega::CG_stringBuilder;
if (uninterpreted_symbols[*i].size() == 0) {
-
-
+
+
std::set<std::string> globals;
-
+
for (omega::DNF_Iterator di(stmt[*i].IS.query_DNF()); di; di++) {
-
+
for (omega::Constraint_Iterator e(*di); e; e++) {
for (omega::Constr_Vars_Iter cvi(*e); cvi; cvi++) {
omega::Variable_ID v = cvi.curr_var();
@@ -2349,105 +2352,106 @@ void Loop::apply_xform(std::set<int> &active) {
globals.insert(v->name());
std::vector<omega::CG_outputRepr *> reprs;
std::vector<omega::CG_outputRepr *> reprs2;
-
+
for (int l = 1; l <= g->arity(); l++) {
omega::CG_outputRepr *temp = ocgr->CreateIdent(
- stmt[*i].IS.set_var(l)->name());
+ stmt[*i].IS.set_var(l)->name());
omega::CG_outputRepr *temp2 = ocgs->CreateIdent(
- stmt[*i].IS.set_var(l)->name());
-
+ stmt[*i].IS.set_var(l)->name());
+
reprs.push_back(temp);
reprs2.push_back(temp2);
}
uninterpreted_symbols[*i].insert(
- std::pair<std::string,
- std::vector<omega::CG_outputRepr *> >(
- v->get_global_var()->base_name(),
- reprs));
+ std::pair<std::string,
+ std::vector<omega::CG_outputRepr *> >(
+ v->get_global_var()->base_name(),
+ reprs));
uninterpreted_symbols_stringrepr[*i].insert(
- std::pair<std::string,
- std::vector<omega::CG_outputRepr *> >(
- v->get_global_var()->base_name(),
- reprs2));
+ std::pair<std::string,
+ std::vector<omega::CG_outputRepr *> >(
+ v->get_global_var()->base_name(),
+ reprs2));
}
}
}
}
}
-
+
std::vector<std::string> loop_vars;
for (int j = 1; j <= stmt[*i].IS.n_set(); j++) {
loop_vars.push_back(stmt[*i].IS.set_var(j)->name());
}
- for (int j = 0; j<loop_vars.size(); j++) {
- fprintf(stderr, "loop vars %d %s\n", j, loop_vars[j].c_str());
+ for (int j = 0; j < loop_vars.size(); j++) {
+ fprintf(stderr, "loop vars %d %s\n", j, loop_vars[j].c_str());
}
std::vector<CG_outputRepr *> subs = output_substitutions(ocg,
Inverse(copy(mapping)),
std::vector<std::pair<CG_outputRepr *, int> >(
- mapping.n_out(),
- std::make_pair(
- static_cast<CG_outputRepr *>(NULL), 0)),
+ mapping.n_out(),
+ std::make_pair(
+ static_cast<CG_outputRepr *>(NULL), 0)),
uninterpreted_symbols[*i]);
-
+
std::vector<CG_outputRepr *> subs2;
for (int l = 0; l < subs.size(); l++)
subs2.push_back(subs[l]->clone());
-
- fprintf(stderr, "%d uninterpreted symbols\n", (int)uninterpreted_symbols.size());
- for (int j = 0; j<loop_vars.size(); j++) {
- fprintf(stderr, "loop vars %d %s\n", j, loop_vars[j].c_str());
- }
-
-
- int count = 0;
+
+ fprintf(stderr, "%d uninterpreted symbols\n", (int) uninterpreted_symbols.size());
+ for (int j = 0; j < loop_vars.size(); j++) {
+ fprintf(stderr, "loop vars %d %s\n", j, loop_vars[j].c_str());
+ }
+
+
+ int count = 0;
for (std::map<std::string, std::vector<CG_outputRepr *> >::iterator it =
- uninterpreted_symbols[*i].begin();
+ uninterpreted_symbols[*i].begin();
it != uninterpreted_symbols[*i].end(); it++) {
- fprintf(stderr, "\ncount %d\n", count);
-
+ fprintf(stderr, "\ncount %d\n", count);
+
std::vector<CG_outputRepr *> reprs_ = it->second;
- fprintf(stderr, "%d reprs_\n", (int)reprs_.size());
-
+ fprintf(stderr, "%d reprs_\n", (int) reprs_.size());
+
std::vector<CG_outputRepr *> reprs_2;
for (int k = 0; k < reprs_.size(); k++) {
- fprintf(stderr, "k %d\n", k);
+ fprintf(stderr, "k %d\n", k);
std::vector<CG_outputRepr *> subs;
for (int l = 0; l < subs2.size(); l++) {
- fprintf(stderr, "l %d\n", l);
+ fprintf(stderr, "l %d\n", l);
subs.push_back(subs2[l]->clone());
}
-
+
fprintf(stderr, "clone\n");
- CG_outputRepr *c = reprs_[k]->clone();
- c->dump(); fflush(stdout);
-
- fprintf(stderr, "createsub\n");
+ CG_outputRepr *c = reprs_[k]->clone();
+ c->dump();
+ fflush(stdout);
+
+ fprintf(stderr, "createsub\n");
CG_outputRepr *s = ocgr->CreateSubstitutedStmt(0, c,
loop_vars, subs, true);
-
- fprintf(stderr, "push back\n");
- reprs_2.push_back( s );
-
+
+ fprintf(stderr, "push back\n");
+ reprs_2.push_back(s);
+
}
-
+
it->second = reprs_2;
count++;
- fprintf(stderr, "bottom\n");
+ fprintf(stderr, "bottom\n");
}
-
+
std::vector<CG_outputRepr *> subs3 = output_substitutions(
- ocgs, Inverse(copy(mapping)),
- std::vector<std::pair<CG_outputRepr *, int> >(
- mapping.n_out(),
- std::make_pair(
- static_cast<CG_outputRepr *>(NULL), 0)),
- uninterpreted_symbols_stringrepr[*i]);
-
+ ocgs, Inverse(copy(mapping)),
+ std::vector<std::pair<CG_outputRepr *, int> >(
+ mapping.n_out(),
+ std::make_pair(
+ static_cast<CG_outputRepr *>(NULL), 0)),
+ uninterpreted_symbols_stringrepr[*i]);
+
for (std::map<std::string, std::vector<CG_outputRepr *> >::iterator it =
- uninterpreted_symbols_stringrepr[*i].begin();
+ uninterpreted_symbols_stringrepr[*i].begin();
it != uninterpreted_symbols_stringrepr[*i].end(); it++) {
-
+
std::vector<CG_outputRepr *> reprs_ = it->second;
std::vector<CG_outputRepr *> reprs_2;
for (int k = 0; k < reprs_.size(); k++) {
@@ -2460,13 +2464,13 @@ void Loop::apply_xform(std::set<int> &active) {
*/
reprs_2.push_back(subs3[k]->clone());
}
-
+
it->second = reprs_2;
-
+
}
-
-
- fprintf(stderr, "loop.cc stmt[*i].code =\n");
+
+
+ fprintf(stderr, "loop.cc stmt[*i].code =\n");
//stmt[*i].code->dump();
//fprintf(stderr, "\n");
stmt[*i].code = ocg->CreateSubstitutedStmt(0, stmt[*i].code, loop_vars,
@@ -2474,10 +2478,10 @@ void Loop::apply_xform(std::set<int> &active) {
//fprintf(stderr, "loop.cc substituted code =\n");
//stmt[*i].code->dump();
//fprintf(stderr, "\n");
-
+
stmt[*i].IS = omega::Range(Restrict_Domain(mapping, stmt[*i].IS));
stmt[*i].IS.simplify();
-
+
// replace original transformation relation with straight 1-1 mapping
//fprintf(stderr, "replace original transformation relation with straight 1-1 mapping\n");
mapping = Relation(n, 2 * n + 1);
@@ -2493,46 +2497,44 @@ void Loop::apply_xform(std::set<int> &active) {
h.update_const(-lex[j - 1]);
}
stmt[*i].xform = mapping;
-
+
//fprintf(stderr, "\ncode is: \n");
//stmt[*i].code->dump();
//fprintf(stderr, "\n\n");
-
+
}
-
+
tmp_loop_var_name_counter += max_n;
- fflush(stdout);
- fprintf(stderr, "loop.cc LEAVING apply_xform( set )\n\n");
+ fflush(stdout);
+ fprintf(stderr, "loop.cc LEAVING apply_xform( set )\n\n");
//for (std::set<int>::iterator i = active.begin(); i != active.end(); i++) {
// fprintf(stderr, "\nloop.cc stmt[i].code =\n");
// stmt[*i].code->dump();
// fprintf(stderr, "\n\n");
//}
-
-}
-
+}
void Loop::addKnown(const Relation &cond) {
-
+
// invalidate saved codegen computation
delete last_compute_cgr_;
last_compute_cgr_ = NULL;
delete last_compute_cg_;
last_compute_cg_ = NULL;
fprintf(stderr, "Loop::addKnown(), SETTING last_compute_cg_ = NULL\n");
-
+
int n1 = this->known.n_set();
-
+
Relation r = copy(cond);
int n2 = r.n_set();
-
+
if (n1 < n2)
this->known = Extend_Set(this->known, n2 - n1);
else if (n1 > n2)
r = Extend_Set(r, n1 - n2);
-
+
this->known = Intersection(this->known, r);
}
@@ -2540,11 +2542,11 @@ void Loop::removeDependence(int stmt_num_from, int stmt_num_to) {
// check for sanity of parameters
if (stmt_num_from >= stmt.size())
throw std::invalid_argument(
- "invalid statement number " + to_string(stmt_num_from));
+ "invalid statement number " + to_string(stmt_num_from));
if (stmt_num_to >= stmt.size())
throw std::invalid_argument(
- "invalid statement number " + to_string(stmt_num_to));
-
+ "invalid statement number " + to_string(stmt_num_to));
+
dep.disconnect(stmt_num_from, stmt_num_to);
}
@@ -2556,14 +2558,14 @@ void Loop::dump() const {
if (2 * j < lex.size())
std::cout << lex[2 * j];
switch (stmt[i].loop_level[j].type) {
- case LoopLevelOriginal:
- std::cout << "(dim:" << stmt[i].loop_level[j].payload << ")";
- break;
- case LoopLevelTile:
- std::cout << "(tile:" << stmt[i].loop_level[j].payload << ")";
- break;
- default:
- std::cout << "(unknown)";
+ case LoopLevelOriginal:
+ std::cout << "(dim:" << stmt[i].loop_level[j].payload << ")";
+ break;
+ case LoopLevelTile:
+ std::cout << "(tile:" << stmt[i].loop_level[j].payload << ")";
+ break;
+ default:
+ std::cout << "(unknown)";
}
std::cout << ' ';
}
@@ -2579,16 +2581,16 @@ void Loop::dump() const {
bool Loop::nonsingular(const std::vector<std::vector<int> > &T) {
if (stmt.size() == 0)
return true;
-
+
// check for sanity of parameters
for (int i = 0; i < stmt.size(); i++) {
if (stmt[i].loop_level.size() != num_dep_dim)
throw std::invalid_argument(
- "nonsingular loop transformations must be applied to original perfect loop nest");
+ "nonsingular loop transformations must be applied to original perfect loop nest");
for (int j = 0; j < stmt[i].loop_level.size(); j++)
if (stmt[i].loop_level[j].type != LoopLevelOriginal)
throw std::invalid_argument(
- "nonsingular loop transformations must be applied to original perfect loop nest");
+ "nonsingular loop transformations must be applied to original perfect loop nest");
}
if (T.size() != num_dep_dim)
throw std::invalid_argument("invalid transformation matrix");
@@ -2619,81 +2621,80 @@ bool Loop::nonsingular(const std::vector<std::vector<int> > &T) {
h.update_coef(mapping.output_var(i), -1);
h.update_coef(mapping.input_var(i), 1);
}
-
+
// update transformation relations
for (int i = 0; i < stmt.size(); i++)
stmt[i].xform = Composition(copy(mapping), stmt[i].xform);
-
+
// update dependence graph
for (int i = 0; i < dep.vertex.size(); i++)
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[i].second.begin(); j != dep.vertex[i].second.end();
+ dep.vertex[i].second.begin(); j != dep.vertex[i].second.end();
j++) {
std::vector<DependenceVector> dvs = j->second;
for (int k = 0; k < dvs.size(); k++) {
DependenceVector &dv = dvs[k];
switch (dv.type) {
- case DEP_W2R:
- case DEP_R2W:
- case DEP_W2W:
- case DEP_R2R: {
- std::vector<coef_t> lbounds(num_dep_dim), ubounds(
- num_dep_dim);
- for (int p = 0; p < num_dep_dim; p++) {
- coef_t lb = 0;
- coef_t ub = 0;
- for (int q = 0; q < num_dep_dim; q++) {
- if (T[p][q] > 0) {
- if (lb == -posInfinity
- || dv.lbounds[q] == -posInfinity)
- lb = -posInfinity;
- else
- lb += T[p][q] * dv.lbounds[q];
- if (ub == posInfinity
- || dv.ubounds[q] == posInfinity)
- ub = posInfinity;
- else
- ub += T[p][q] * dv.ubounds[q];
- } else if (T[p][q] < 0) {
- if (lb == -posInfinity
- || dv.ubounds[q] == posInfinity)
- lb = -posInfinity;
- else
- lb += T[p][q] * dv.ubounds[q];
- if (ub == posInfinity
- || dv.lbounds[q] == -posInfinity)
- ub = posInfinity;
- else
- ub += T[p][q] * dv.lbounds[q];
+ case DEP_W2R:
+ case DEP_R2W:
+ case DEP_W2W:
+ case DEP_R2R: {
+ std::vector<coef_t> lbounds(num_dep_dim), ubounds(
+ num_dep_dim);
+ for (int p = 0; p < num_dep_dim; p++) {
+ coef_t lb = 0;
+ coef_t ub = 0;
+ for (int q = 0; q < num_dep_dim; q++) {
+ if (T[p][q] > 0) {
+ if (lb == -posInfinity
+ || dv.lbounds[q] == -posInfinity)
+ lb = -posInfinity;
+ else
+ lb += T[p][q] * dv.lbounds[q];
+ if (ub == posInfinity
+ || dv.ubounds[q] == posInfinity)
+ ub = posInfinity;
+ else
+ ub += T[p][q] * dv.ubounds[q];
+ } else if (T[p][q] < 0) {
+ if (lb == -posInfinity
+ || dv.ubounds[q] == posInfinity)
+ lb = -posInfinity;
+ else
+ lb += T[p][q] * dv.ubounds[q];
+ if (ub == posInfinity
+ || dv.lbounds[q] == -posInfinity)
+ ub = posInfinity;
+ else
+ ub += T[p][q] * dv.lbounds[q];
+ }
}
+ if (T[p].size() == num_dep_dim + 1) {
+ if (lb != -posInfinity)
+ lb += T[p][num_dep_dim];
+ if (ub != posInfinity)
+ ub += T[p][num_dep_dim];
+ }
+ lbounds[p] = lb;
+ ubounds[p] = ub;
}
- if (T[p].size() == num_dep_dim + 1) {
- if (lb != -posInfinity)
- lb += T[p][num_dep_dim];
- if (ub != posInfinity)
- ub += T[p][num_dep_dim];
- }
- lbounds[p] = lb;
- ubounds[p] = ub;
+ dv.lbounds = lbounds;
+ dv.ubounds = ubounds;
+
+ break;
}
- dv.lbounds = lbounds;
- dv.ubounds = ubounds;
-
- break;
- }
- default:
- ;
+ default:;
}
}
j->second = dvs;
}
-
+
// set constant loop values
std::set<int> active;
for (int i = 0; i < stmt.size(); i++)
active.insert(i);
setLexicalOrder(0, active);
-
+
return true;
}
@@ -2706,12 +2707,11 @@ bool Loop::is_dependence_valid_based_on_lex_order(int i, int j,
if (!dv.is_scalar_dependence) {
for (last_dim = 0;
last_dim < lex_i.size() && (lex_i[last_dim] == lex_j[last_dim]);
- last_dim++)
- ;
+ last_dim++);
last_dim = last_dim / 2;
if (last_dim == 0)
return true;
-
+
for (int i = 0; i < last_dim; i++) {
if (dv.lbounds[i] > 0)
return true;
@@ -2721,9 +2721,9 @@ bool Loop::is_dependence_valid_based_on_lex_order(int i, int j,
}
if (before)
return true;
-
+
return false;
-
+
}
// Manu:: reduction operation
@@ -2731,7 +2731,7 @@ bool Loop::is_dependence_valid_based_on_lex_order(int i, int j,
void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
std::string arrName, int memory_type, int padding_alignment,
int assign_then_accumulate, int padding_stride) {
-
+
//std::cout << "In scalar_expand function: " << stmt_num << ", " << arrName << "\n";
//std::cout.flush();
@@ -2744,10 +2744,10 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
// check for sanity of parameters
bool found_non_constant_size_dimension = false;
-
+
if (stmt_num < 0 || stmt_num >= stmt.size())
throw std::invalid_argument(
- "invalid statement number " + to_string(stmt_num));
+ "invalid statement number " + to_string(stmt_num));
//Anand: adding check for privatized levels
//if (arrName != "RHS")
// throw std::invalid_argument(
@@ -2755,34 +2755,33 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
for (int i = 0; i < levels.size(); i++) {
if (levels[i] <= 0 || levels[i] > stmt[stmt_num].loop_level.size())
throw std::invalid_argument(
- "1invalid loop level " + to_string(levels[i]));
-
+ "1invalid loop level " + to_string(levels[i]));
+
if (i > 0) {
if (levels[i] < levels[i - 1])
throw std::invalid_argument(
- "loop levels must be in ascending order");
+ "loop levels must be in ascending order");
}
}
//end --adding check for privatized levels
-
+
delete last_compute_cgr_;
last_compute_cgr_ = NULL;
delete last_compute_cg_;
last_compute_cg_ = NULL;
fprintf(stderr, "Loop::scalar_expand(), SETTING last_compute_cg_ = NULL\n");
- fprintf(stderr, "\nloop.cc finding array accesses in stmt %d of the code\n",stmt_num );
+ fprintf(stderr, "\nloop.cc finding array accesses in stmt %d of the code\n", stmt_num);
std::vector<IR_ArrayRef *> access = ir->FindArrayRef(stmt[stmt_num].code);
- fprintf(stderr, "loop.cc L2726 %d access\n", access.size());
+ fprintf(stderr, "loop.cc L2726 %d access\n", access.size());
IR_ArraySymbol *sym = NULL;
- fprintf(stderr, "arrName %s\n", arrName.c_str());
- if (arrName == "RHS") {
- fprintf(stderr, "sym RHS\n");
+ fprintf(stderr, "arrName %s\n", arrName.c_str());
+ if (arrName == "RHS") {
+ fprintf(stderr, "sym RHS\n");
sym = access[0]->symbol();
- }
- else {
- fprintf(stderr, "looking for array %s in access\n", arrName.c_str());
+ } else {
+ fprintf(stderr, "looking for array %s in access\n", arrName.c_str());
for (int k = 0; k < access.size(); k++) { // BUH
//fprintf(stderr, "access[%d] = %s ", k, access[k]->getTypeString()); access[k]->print(0,stderr); fprintf(stderr, "\n");
@@ -2791,34 +2790,34 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
//fprintf(stderr, "comparing %s to %s\n", name.c_str(), arrName.c_str());
if (access[k]->symbol()->name() == arrName) {
- fprintf(stderr, "found it sym access[ k=%d ]\n", k);
+ fprintf(stderr, "found it sym access[ k=%d ]\n", k);
sym = access[k]->symbol();
- }
+ }
}
}
- if (!sym) fprintf(stderr, "DIDN'T FIND IT\n");
- fprintf(stderr, "sym %p\n", sym);
+ if (!sym) fprintf(stderr, "DIDN'T FIND IT\n");
+ fprintf(stderr, "sym %p\n", sym);
// collect array references by name
std::vector<int> lex = getLexicalOrder(stmt_num);
int dim = 2 * levels[levels.size() - 1] - 1;
std::set<int> same_loop = getStatements(lex, dim - 1);
-
+
//Anand: shifting this down
// assign_const(stmt[newStmt_num].xform, 2*level+1, 1);
-
+
// std::cout << " before temp array name \n ";
// create a temporary variable
IR_Symbol *tmp_sym;
-
+
// get the loop upperbound, that would be the size of the temp array.
omega::coef_t lb[levels.size()], ub[levels.size()], size[levels.size()];
-
+
//Anand Adding apply xform so that tiled loop bounds are reflected
fprintf(stderr, "Adding apply xform so that tiled loop bounds are reflected\n");
apply_xform(same_loop);
- fprintf(stderr, "loop.cc, back from apply_xform()\n");
-
+ fprintf(stderr, "loop.cc, back from apply_xform()\n");
+
//Anand commenting out the folowing 4 lines
/* copy(stmt[stmt_num].IS).query_variable_bounds(
copy(stmt[stmt_num].IS).set_var(level), lb, ub);
@@ -2890,32 +2889,32 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
std::vector<int> size_int;
Relation xform = copy(stmt[stmt_num].xform);
for (int i = 0; i < n_dim; i++) {
-
+
dim = 2 * levels[i] - 1;
//Anand: Commenting out the lines below: not required
// if (i != 0)
// reduced_copy_is = Project(reduced_copy_is, level - 1 + i, Set_Var);
Relation bound = get_loop_bound(copy(reduced_copy_is), levels[i] - 1);
-
+
// extract stride
std::pair<EQ_Handle, Variable_ID> result = find_simplest_stride(bound,
bound.set_var(levels[i]));
if (result.second != NULL)
index_stride[i] = abs(result.first.get_coef(result.second))
- / gcd(abs(result.first.get_coef(result.second)),
- abs(
- result.first.get_coef(
- bound.set_var(levels[i]))));
+ / gcd(abs(result.first.get_coef(result.second)),
+ abs(
+ result.first.get_coef(
+ bound.set_var(levels[i]))));
else
index_stride[i] = 1;
// std::cout << "simplest_stride 11:: " << index_stride[i] << "\n";
-
+
// check if this array index requires loop
Conjunct *c = bound.query_DNF()->single_conjunct();
for (EQ_Iterator ei(c->EQs()); ei; ei++) {
if ((*ei).has_wildcards())
continue;
-
+
int coef = (*ei).get_coef(bound.set_var(levels[i]));
if (coef != 0) {
int sign = 1;
@@ -2923,59 +2922,58 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
coef = -coef;
sign = -1;
}
-
+
CG_outputRepr *op = NULL;
for (Constr_Vars_Iter ci(*ei); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var: {
- if ((*ci).var != bound.set_var(levels[i]))
+ case Input_Var: {
+ if ((*ci).var != bound.set_var(levels[i]))
+ if ((*ci).coef * sign == 1)
+ op = ocg1->CreateMinus(op,
+ ocg1->CreateIdent((*ci).var->name()));
+ else if ((*ci).coef * sign == -1)
+ op = ocg1->CreatePlus(op,
+ ocg1->CreateIdent((*ci).var->name()));
+ else if ((*ci).coef * sign > 1) {
+ op = ocg1->CreateMinus(op,
+ ocg1->CreateTimes(
+ ocg1->CreateInt(
+ abs((*ci).coef)),
+ ocg1->CreateIdent(
+ (*ci).var->name())));
+ } else
+ // (*ci).coef*sign < -1
+ op = ocg1->CreatePlus(op,
+ ocg1->CreateTimes(
+ ocg1->CreateInt(
+ abs((*ci).coef)),
+ ocg1->CreateIdent(
+ (*ci).var->name())));
+ break;
+ }
+ case Global_Var: {
+ Global_Var_ID g = (*ci).var->get_global_var();
if ((*ci).coef * sign == 1)
op = ocg1->CreateMinus(op,
- ocg1->CreateIdent((*ci).var->name()));
+ ocg1->CreateIdent(g->base_name()));
else if ((*ci).coef * sign == -1)
op = ocg1->CreatePlus(op,
- ocg1->CreateIdent((*ci).var->name()));
- else if ((*ci).coef * sign > 1) {
+ ocg1->CreateIdent(g->base_name()));
+ else if ((*ci).coef * sign > 1)
op = ocg1->CreateMinus(op,
ocg1->CreateTimes(
- ocg1->CreateInt(
- abs((*ci).coef)),
- ocg1->CreateIdent(
- (*ci).var->name())));
- }
+ ocg1->CreateInt(abs((*ci).coef)),
+ ocg1->CreateIdent(g->base_name())));
else
// (*ci).coef*sign < -1
op = ocg1->CreatePlus(op,
ocg1->CreateTimes(
- ocg1->CreateInt(
- abs((*ci).coef)),
- ocg1->CreateIdent(
- (*ci).var->name())));
- break;
- }
- case Global_Var: {
- Global_Var_ID g = (*ci).var->get_global_var();
- if ((*ci).coef * sign == 1)
- op = ocg1->CreateMinus(op,
- ocg1->CreateIdent(g->base_name()));
- else if ((*ci).coef * sign == -1)
- op = ocg1->CreatePlus(op,
- ocg1->CreateIdent(g->base_name()));
- else if ((*ci).coef * sign > 1)
- op = ocg1->CreateMinus(op,
- ocg1->CreateTimes(
- ocg1->CreateInt(abs((*ci).coef)),
- ocg1->CreateIdent(g->base_name())));
- else
- // (*ci).coef*sign < -1
- op = ocg1->CreatePlus(op,
- ocg1->CreateTimes(
- ocg1->CreateInt(abs((*ci).coef)),
- ocg1->CreateIdent(g->base_name())));
- break;
- }
- default:
- throw loop_error("unsupported array index expression");
+ ocg1->CreateInt(abs((*ci).coef)),
+ ocg1->CreateIdent(g->base_name())));
+ break;
+ }
+ default:
+ throw loop_error("unsupported array index expression");
}
}
if ((*ei).get_const() != 0)
@@ -2983,7 +2981,7 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
ocg1->CreateInt(-sign * ((*ei).get_const())));
if (coef != 1)
op = ocg1->CreateIntegerFloor(op, ocg1->CreateInt(coef));
-
+
index_lb[i] = op;
is_index_eq[i] = true;
break;
@@ -2991,7 +2989,7 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
}
if (is_index_eq[i])
continue;
-
+
// separate lower and upper bounds
std::vector<GEQ_Handle> lb_list, ub_list;
std::set<Variable_ID> excluded_floor_vars;
@@ -3006,23 +3004,22 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
excluded_floor_vars).first) {
clean_bound = false;
break;
- }
- else
- h= find_floor_definition(bound, (*cvi).var,
- excluded_floor_vars).second;
-
+ } else
+ h = find_floor_definition(bound, (*cvi).var,
+ excluded_floor_vars).second;
+
if (!clean_bound)
continue;
- else{
+ else {
if (coef > 0)
lb_list.push_back(h);
else if (coef < 0)
ub_list.push_back(h);
- continue;
- }
-
+ continue;
+ }
+
}
-
+
if (coef > 0)
lb_list.push_back(*gi);
else if (coef < 0)
@@ -3030,7 +3027,7 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
}
if (lb_list.size() == 0 || ub_list.size() == 0)
throw loop_error("failed to calcuate array footprint size");
-
+
// build lower bound representation
std::vector<CG_outputRepr *> lb_repr_list;
/* for (int j = 0; j < lb_list.size(); j++){
@@ -3045,7 +3042,7 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
index_lb[i] = ocg1->CreateInvoke("max", lb_repr_list);
else if (lb_repr_list.size() == 1)
index_lb[i] = lb_repr_list[0];
-
+
// build temporary array size representation
{
Relation cal(copy_is.n_set(), 1);
@@ -3053,65 +3050,65 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
for (int j = 0; j < ub_list.size(); j++)
for (int k = 0; k < lb_list.size(); k++) {
GEQ_Handle h = f_root->add_GEQ();
-
+
for (Constr_Vars_Iter ci(ub_list[j]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var: {
- int pos = (*ci).var->get_position();
- h.update_coef(cal.input_var(pos), (*ci).coef);
- break;
- }
- case Global_Var: {
- Global_Var_ID g = (*ci).var->get_global_var();
- Variable_ID v;
- if (g->arity() == 0)
- v = cal.get_local(g);
- else
- v = cal.get_local(g, (*ci).var->function_of());
- h.update_coef(v, (*ci).coef);
- break;
- }
- default:
- throw loop_error(
- "cannot calculate temporay array size statically");
+ case Input_Var: {
+ int pos = (*ci).var->get_position();
+ h.update_coef(cal.input_var(pos), (*ci).coef);
+ break;
+ }
+ case Global_Var: {
+ Global_Var_ID g = (*ci).var->get_global_var();
+ Variable_ID v;
+ if (g->arity() == 0)
+ v = cal.get_local(g);
+ else
+ v = cal.get_local(g, (*ci).var->function_of());
+ h.update_coef(v, (*ci).coef);
+ break;
+ }
+ default:
+ throw loop_error(
+ "cannot calculate temporay array size statically");
}
}
h.update_const(ub_list[j].get_const());
-
+
for (Constr_Vars_Iter ci(lb_list[k]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var: {
- int pos = (*ci).var->get_position();
- h.update_coef(cal.input_var(pos), (*ci).coef);
- break;
- }
- case Global_Var: {
- Global_Var_ID g = (*ci).var->get_global_var();
- Variable_ID v;
- if (g->arity() == 0)
- v = cal.get_local(g);
- else
- v = cal.get_local(g, (*ci).var->function_of());
- h.update_coef(v, (*ci).coef);
- break;
- }
- default:
- throw loop_error(
- "cannot calculate temporay array size statically");
+ case Input_Var: {
+ int pos = (*ci).var->get_position();
+ h.update_coef(cal.input_var(pos), (*ci).coef);
+ break;
+ }
+ case Global_Var: {
+ Global_Var_ID g = (*ci).var->get_global_var();
+ Variable_ID v;
+ if (g->arity() == 0)
+ v = cal.get_local(g);
+ else
+ v = cal.get_local(g, (*ci).var->function_of());
+ h.update_coef(v, (*ci).coef);
+ break;
+ }
+ default:
+ throw loop_error(
+ "cannot calculate temporay array size statically");
}
}
h.update_const(lb_list[k].get_const());
-
+
h.update_const(1);
h.update_coef(cal.output_var(1), -1);
}
-
+
cal = Restrict_Domain(cal, copy(copy_is));
for (int j = 1; j <= cal.n_inp(); j++) {
cal = Project(cal, j, Input_Var);
}
cal.simplify();
-
+
// pad temporary array size
// TODO: for variable array size, create padding formula
//int padding_stride = 0;
@@ -3125,50 +3122,50 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
gi++)
if ((*gi).is_const(cal.output_var(1))) {
coef_t size = (*gi).get_const()
- / (-(*gi).get_coef(cal.output_var(1)));
-
+ / (-(*gi).get_coef(cal.output_var(1)));
+
if (padding_alignment > 1 && i == n_dim - 1) { // align to boundary for data packing
int residue = size % padding_alignment;
if (residue)
size = size + padding_alignment - residue;
}
-
+
index_sz.push_back(
- std::make_pair(i, ocg1->CreateInt(size)));
+ std::make_pair(i, ocg1->CreateInt(size)));
is_index_bound_const = true;
size_int.push_back(size);
size_repr.push_back(ocg1->CreateInt(size));
-
+
// std::cout << "============================== size :: "
// << size << "\n";
-
+
}
-
+
if (!is_index_bound_const) {
-
+
found_non_constant_size_dimension = true;
Conjunct *c = bound.query_DNF()->single_conjunct();
for (GEQ_Iterator gi(c->GEQs());
gi && !is_index_bound_const; gi++) {
int coef = (*gi).get_coef(bound.set_var(levels[i]));
if (coef < 0) {
-
+
size_repr.push_back(
- ocg1->CreatePlus(
- output_upper_bound_repr(ocg1, *gi,
- bound.set_var(levels[i]),
- bound,
- std::vector<
- std::pair<
- CG_outputRepr *,
- int> >(
- bound.n_set(),
- std::make_pair(
- static_cast<CG_outputRepr *>(NULL),
- 0)),
- uninterpreted_symbols[stmt_num]),
- ocg1->CreateInt(1)));
-
+ ocg1->CreatePlus(
+ output_upper_bound_repr(ocg1, *gi,
+ bound.set_var(levels[i]),
+ bound,
+ std::vector<
+ std::pair<
+ CG_outputRepr *,
+ int> >(
+ bound.n_set(),
+ std::make_pair(
+ static_cast<CG_outputRepr *>(NULL),
+ 0)),
+ uninterpreted_symbols[stmt_num]),
+ ocg1->CreateInt(1)));
+
/*CG_outputRepr *op = NULL;
for (Constr_Vars_Iter ci(*gi); ci; ci++) {
if ((*ci).var != cal.output_var(1)) {
@@ -3238,13 +3235,13 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
}
}
//size[i] = ub[i];
-
+
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
-
+
//Anand: Creating IS of new statement
-
+
//for(int l = dim; l < stmt[stmt_num].xform.n_out(); l+=2)
//std::cout << "In scalar_expand function 3: " << stmt_num << ", " << arrName << "\n";
//std::cout.flush();
@@ -3256,16 +3253,16 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
//}
//fprintf(stderr, "\n");
-
+
shiftLexicalOrder(lex, dim + 1, 1);
Statement s = stmt[stmt_num];
s.ir_stmt_node = NULL;
int newStmt_num = stmt.size();
- fprintf(stderr, "loop.cc L3249 adding stmt %d\n", stmt.size());
+ fprintf(stderr, "loop.cc L3249 adding stmt %d\n", stmt.size());
stmt.push_back(s);
-
- fprintf(stderr, "uninterpreted_symbols.push_back() newStmt_num %d\n", newStmt_num);
+
+ fprintf(stderr, "uninterpreted_symbols.push_back() newStmt_num %d\n", newStmt_num);
uninterpreted_symbols.push_back(uninterpreted_symbols[stmt_num]);
uninterpreted_symbols_stringrepr.push_back(uninterpreted_symbols_stringrepr[stmt_num]);
stmt[newStmt_num].code = stmt[stmt_num].code->clone();
@@ -3286,16 +3283,16 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
//assign_const(stmt[newStmt_num].xform, stmt[stmt_num].xform.n_out(), 1);//Anand: change from 2*level + 1 to stmt[stmt_num].xform.size()
//Anand-End creating IS of new statement
-
- CG_outputRepr * tmpArrSz;
+
+ CG_outputRepr *tmpArrSz;
CG_outputBuilder *ocg = ir->builder();
-
+
//for(int k =0; k < levels.size(); k++ )
// size_repr.push_back(ocg->CreateInt(size[k]));//Anand: copying apply_xform functionality to prevent IS modification
//due to side effects with uninterpreted function symbols and failures in omega
-
+
//int n = stmt[stmt_num].loop_level.size();
-
+
/*Relation mapping(2 * n + 1, n);
F_And *f_root = mapping.add_and();
for (int j = 1; j <= n; j++) {
@@ -3318,64 +3315,68 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
Relation size_ = omega::Range(Restrict_Domain(mapping, copy(stmt[stmt_num].IS)));
size_.simplify();
*/
-
+
//Anand -commenting out tmp sym creation as symbol may have more than one dimension
//tmp_sym = ir->CreateArraySymbol(tmpArrSz, sym);
std::vector<CG_outputRepr *> lhs_index;
CG_outputRepr *arr_ref_repr;
arr_ref_repr = ocg->CreateIdent(
- stmt[stmt_num].IS.set_var(levels[levels.size() - 1])->name());
-
+ stmt[stmt_num].IS.set_var(levels[levels.size() - 1])->name());
+
CG_outputRepr *total_size = size_repr[0];
- fprintf(stderr, "total_size = "); total_size->dump(); fflush(stdout);
+ fprintf(stderr, "total_size = ");
+ total_size->dump();
+ fflush(stdout);
for (int i = 1; i < size_repr.size(); i++) {
- fprintf(stderr, "total_size now "); total_size->dump(); fflush(stdout); fprintf(stderr, " times something\n\n");
+ fprintf(stderr, "total_size now ");
+ total_size->dump();
+ fflush(stdout);
+ fprintf(stderr, " times something\n\n");
total_size = ocg->CreateTimes(total_size->clone(),
size_repr[i]->clone());
-
+
}
-
+
// COMMENT NEEDED
//fprintf(stderr, "\nloop.cc COMMENT NEEDED\n");
for (int k = levels.size() - 2; k >= 0; k--) {
- CG_outputRepr *temp_repr =ocg->CreateIdent(stmt[stmt_num].IS.set_var(levels[k])->name());
- for (int l = k + 1; l < levels.size(); l++) {
+ CG_outputRepr *temp_repr = ocg->CreateIdent(stmt[stmt_num].IS.set_var(levels[k])->name());
+ for (int l = k + 1; l < levels.size(); l++) {
//fprintf(stderr, "\nloop.cc CREATETIMES\n");
temp_repr = ocg->CreateTimes(temp_repr->clone(),
size_repr[l]->clone());
}
-
+
//fprintf(stderr, "\nloop.cc CREATEPLUS\n");
arr_ref_repr = ocg->CreatePlus(arr_ref_repr->clone(),
temp_repr->clone());
}
-
+
//fprintf(stderr, "loop.cc, about to die\n");
std::vector<CG_outputRepr *> to_push;
to_push.push_back(total_size);
- if (!found_non_constant_size_dimension) {
- fprintf(stderr, "constant size dimension\n");
+ if (!found_non_constant_size_dimension) {
+ fprintf(stderr, "constant size dimension\n");
tmp_sym = ir->CreateArraySymbol(sym, to_push, memory_type);
- }
- else {
- fprintf(stderr, "NON constant size dimension?\n");
+ } else {
+ fprintf(stderr, "NON constant size dimension?\n");
//tmp_sym = ir->CreatePointerSymbol(sym, to_push);
tmp_sym = ir->CreatePointerSymbol(sym, to_push);
static_cast<IR_PointerSymbol *>(tmp_sym)->set_size(0, total_size); // ??
ptr_variables.push_back(static_cast<IR_PointerSymbol *>(tmp_sym));
- fprintf(stderr, "ptr_variables now has %d entries\n", ptr_variables.size());
+ fprintf(stderr, "ptr_variables now has %d entries\n", ptr_variables.size());
}
-
+
// add tmp_sym to Loop symtables ??
-
+
// std::cout << " temp array name == " << tmp_sym->name().c_str() << "\n";
-
+
// get loop index variable at the given "level"
// Relation R = omega::Range(Restrict_Domain(copy(stmt[stmt_num].xform), copy(stmt[stmt_num].IS)));
// stmt[stmt_num].IS.print();
@@ -3383,9 +3384,9 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
// std::cout << stmt[stmt_num].IS.n_set() << std::endl;
// std::string v = stmt[stmt_num].IS.set_var(level)->name();
// std::cout << "loop index variable is '" << v.c_str() << "'\n";
-
+
// create a reference for the temporary array
- fprintf(stderr, "create a reference for the temporary array\n");
+ fprintf(stderr, "create a reference for the temporary array\n");
//std::cout << "In scalar_expand function 4: " << stmt_num << ", " << arrName << "\n";
//std::cout.flush();
@@ -3396,7 +3397,7 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
//}
//fprintf(stderr, "\n");
-
+
std::vector<CG_outputRepr *> to_push2;
to_push2.push_back(arr_ref_repr); // can have only one entry
@@ -3405,21 +3406,20 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
IR_ArrayRef *tmp_array_ref;
- IR_PointerArrayRef * tmp_ptr_array_ref; // was IR_PointerArrayref
+ IR_PointerArrayRef *tmp_ptr_array_ref; // was IR_PointerArrayref
if (!found_non_constant_size_dimension) {
fprintf(stderr, "constant size\n");
tmp_array_ref = ir->CreateArrayRef(
- static_cast<IR_ArraySymbol *>(tmp_sym), to_push2);
- }
- else {
- fprintf(stderr, "NON constant size\n");
+ static_cast<IR_ArraySymbol *>(tmp_sym), to_push2);
+ } else {
+ fprintf(stderr, "NON constant size\n");
tmp_ptr_array_ref = ir->CreatePointerArrayRef(
- static_cast<IR_PointerSymbol *>(tmp_sym), to_push2);
+ static_cast<IR_PointerSymbol *>(tmp_sym), to_push2);
// TODO static_cast<IR_PointerSymbol *>(tmp_sym), to_push2);
}
- fflush(stdout);
+ fflush(stdout);
//fprintf(stderr, "\n%d statements\n", stmt.size());
//for (int i=0; i<stmt.size(); i++) {
@@ -3432,22 +3432,22 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
//std::string stemp;
//stemp = tmp_array_ref->name();
//std::cout << "Created array reference --> " << stemp.c_str() << "\n";
-
+
// get the RHS expression
- fprintf(stderr, "get the RHS expression arrName %s\n", arrName.c_str());
+ fprintf(stderr, "get the RHS expression arrName %s\n", arrName.c_str());
CG_outputRepr *rhs;
if (arrName == "RHS") {
rhs = ir->GetRHSExpression(stmt[stmt_num].code);
-
+
std::vector<IR_ArrayRef *> symbols = ir->FindArrayRef(rhs);
}
std::set<std::string> sym_names;
-
+
//for (int i = 0; i < symbols.size(); i++)
// sym_names.insert(symbols[i]->symbol()->name());
-
- fflush(stdout);
+
+ fflush(stdout);
//fprintf(stderr, "\nbefore if (arrName == RHS)\n%d statements\n", stmt.size()); // problem is after here
//for (int i=0; i<stmt.size(); i++) {
@@ -3457,15 +3457,14 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
//fprintf(stderr, "\n");
if (arrName == "RHS") {
-
+
std::vector<IR_ArrayRef *> symbols = ir->FindArrayRef(rhs);
-
+
for (int i = 0; i < symbols.size(); i++)
sym_names.insert(symbols[i]->symbol()->name());
- }
- else {
+ } else {
- fprintf(stderr, "finding array refs in stmt_num %d\n", stmt_num);
+ fprintf(stderr, "finding array refs in stmt_num %d\n", stmt_num);
//fprintf(stderr, "\n%d statements\n", stmt.size());
//for (int i=0; i<stmt.size(); i++) {
// fprintf(stderr, "%2d ", i);
@@ -3474,15 +3473,15 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
//fprintf(stderr, "\n");
std::vector<IR_ArrayRef *> refs = ir->FindArrayRef(stmt[stmt_num].code);
- fprintf(stderr, "\n%d refs\n", refs.size());
+ fprintf(stderr, "\n%d refs\n", refs.size());
+
-
bool found = false;
for (int j = 0; j < refs.size(); j++) {
- CG_outputRepr* to_replace;
+ CG_outputRepr *to_replace;
- fprintf(stderr, "j %d build new assignment statement with temporary array\n",j);
+ fprintf(stderr, "j %d build new assignment statement with temporary array\n", j);
// build new assignment statement with temporary array
if (!found_non_constant_size_dimension) {
to_replace = tmp_array_ref->convert();
@@ -3494,7 +3493,7 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
//CR->Dump();
if (refs[j]->name() == arrName) {
- fflush(stdout);
+ fflush(stdout);
fprintf(stderr, "loop.cc L353\n"); // problem is after here
//fprintf(stderr, "\n%d statements\n", stmt.size());
//for (int i=0; i<stmt.size(); i++) {
@@ -3502,15 +3501,15 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
// ((CG_chillRepr *)stmt[i].code)->Dump();
//}
//fprintf(stderr, "\n");
-
+
sym_names.insert(refs[j]->symbol()->name());
-
+
if (!found) {
- if (!found_non_constant_size_dimension) {
- fprintf(stderr, "constant size2\n");
- omega::CG_outputRepr * t = tmp_array_ref->convert();
- omega::CG_outputRepr * r = refs[j]->convert()->clone();
+ if (!found_non_constant_size_dimension) {
+ fprintf(stderr, "constant size2\n");
+ omega::CG_outputRepr *t = tmp_array_ref->convert();
+ omega::CG_outputRepr *r = refs[j]->convert()->clone();
//CR = (CG_chillRepr *) t;
//CR->Dump();
//CR = (CG_chillRepr *) r;
@@ -3518,14 +3517,13 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
//fprintf(stderr, "lhs t %p lhs r %p\n", t, r);
stmt[newStmt_num].code =
- ir->builder()->CreateAssignment(0,
- t, // tmp_array_ref->convert(),
- r); // refs[j]->convert()->clone()
- }
- else {
- fprintf(stderr, "NON constant size2\n");
- omega::CG_outputRepr * t = tmp_ptr_array_ref->convert(); // this fails
- omega::CG_outputRepr * r = refs[j]->convert()->clone();
+ ir->builder()->CreateAssignment(0,
+ t, // tmp_array_ref->convert(),
+ r); // refs[j]->convert()->clone()
+ } else {
+ fprintf(stderr, "NON constant size2\n");
+ omega::CG_outputRepr *t = tmp_ptr_array_ref->convert(); // this fails
+ omega::CG_outputRepr *r = refs[j]->convert()->clone();
//omega::CG_chillRepr *CR = (omega::CG_chillRepr *) t;
//CR->Dump();
@@ -3534,21 +3532,21 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
//fprintf(stderr, "lhs t %p lhs r %p\n", t, r);
stmt[newStmt_num].code =
- ir->builder()->CreateAssignment(0,
- t, // tmp_ptr_array_ref->convert(),
- r ); // refs[j]->convert()->clone());
+ ir->builder()->CreateAssignment(0,
+ t, // tmp_ptr_array_ref->convert(),
+ r); // refs[j]->convert()->clone());
}
found = true;
-
+
}
-
+
// refs[j] has no parent?
- fprintf(stderr, "replacing refs[%d]\n", j );
+ fprintf(stderr, "replacing refs[%d]\n", j);
ir->ReplaceExpression(refs[j], to_replace);
}
-
+
}
-
+
}
//ToDo need to update the dependence graph
//Anand adding dependence graph update
@@ -3561,10 +3559,10 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
//fprintf(stderr, "\n");
dep.insert();
-
+
//Anand:Copying Dependence checks from datacopy code, might need to be a separate function/module
// in the future
-
+
/*for (int i = 0; i < newStmt_num; i++) {
std::vector<std::vector<DependenceVector> > D;
@@ -3615,41 +3613,41 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
*/
//Anand--end dependence check
if (arrName == "RHS") {
-
+
// build new assignment statement with temporary array
if (!found_non_constant_size_dimension) {
if (assign_then_accumulate) {
stmt[newStmt_num].code = ir->builder()->CreateAssignment(0,
tmp_array_ref->convert(), rhs);
- fprintf(stderr, "ir->ReplaceRHSExpression( stmt_ num %d )\n", stmt_num);
+ fprintf(stderr, "ir->ReplaceRHSExpression( stmt_ num %d )\n", stmt_num);
ir->ReplaceRHSExpression(stmt[stmt_num].code, tmp_array_ref);
} else {
CG_outputRepr *temp = tmp_array_ref->convert()->clone();
if (ir->QueryExpOperation(stmt[stmt_num].code)
!= IR_OP_PLUS_ASSIGNMENT)
throw ir_error(
- "Statement is not a += accumulation statement");
+ "Statement is not a += accumulation statement");
- fprintf(stderr, "replacing in a +=\n");
+ fprintf(stderr, "replacing in a +=\n");
stmt[newStmt_num].code = ir->builder()->CreatePlusAssignment(0,
temp->clone(), rhs);
-
- CG_outputRepr * lhs = ir->GetLHSExpression(stmt[stmt_num].code);
-
+
+ CG_outputRepr *lhs = ir->GetLHSExpression(stmt[stmt_num].code);
+
CG_outputRepr *assignment = ir->builder()->CreateAssignment(0,
lhs, temp->clone());
Statement init_ = stmt[newStmt_num]; // copy ??
init_.ir_stmt_node = NULL;
-
+
init_.code = stmt[newStmt_num].code->clone();
init_.IS = copy(stmt[newStmt_num].IS);
init_.xform = copy(stmt[newStmt_num].xform);
init_.has_inspector = false; // ??
Relation mapping(init_.IS.n_set(), init_.IS.n_set());
-
+
F_And *f_root = mapping.add_and();
-
+
for (int i = 1; i <= mapping.n_inp(); i++) {
EQ_Handle h = f_root->add_EQ();
//if (i < levels[0]) {
@@ -3660,7 +3658,7 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
h.update_const(-1);
h.update_coef(mapping.output_var(i), 1);
}
-
+
/*else {
int j;
for (j = 0; j < levels.size(); j++)
@@ -3683,18 +3681,18 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
*/
//}
}
-
+
mapping.simplify();
// match omega input/output variables to variable names in the code
for (int j = 1; j <= init_.IS.n_set(); j++)
mapping.name_output_var(j, init_.IS.set_var(j)->name());
for (int j = 1; j <= init_.IS.n_set(); j++)
mapping.name_input_var(j, init_.IS.set_var(j)->name());
-
+
mapping.setup_names();
-
+
init_.IS = omega::Range(
- omega::Restrict_Domain(mapping, init_.IS));
+ omega::Restrict_Domain(mapping, init_.IS));
std::vector<int> lex = getLexicalOrder(newStmt_num);
int dim = 2 * levels[0] - 1;
//init_.IS.print();
@@ -3704,11 +3702,11 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
shiftLexicalOrder(lex, dim + 1, 1);
init_.reduction = stmt[newStmt_num].reduction;
init_.reductionOp = stmt[newStmt_num].reductionOp;
-
+
init_.code = ir->builder()->CreateAssignment(0, temp->clone(),
ir->builder()->CreateInt(0));
- fprintf(stderr, "loop.cc L3693 adding stmt %d\n", stmt.size());
+ fprintf(stderr, "loop.cc L3693 adding stmt %d\n", stmt.size());
stmt.push_back(init_);
uninterpreted_symbols.push_back(uninterpreted_symbols[newStmt_num]);
@@ -3726,47 +3724,45 @@ void Loop::scalar_expand(int stmt_num, const std::vector<int> &levels,
if (ir->QueryExpOperation(stmt[stmt_num].code)
!= IR_OP_PLUS_ASSIGNMENT)
throw ir_error(
- "Statement is not a += accumulation statement");
+ "Statement is not a += accumulation statement");
stmt[newStmt_num].code = ir->builder()->CreatePlusAssignment(0,
temp->clone(), rhs);
-
- CG_outputRepr * lhs = ir->GetLHSExpression(stmt[stmt_num].code);
-
+
+ CG_outputRepr *lhs = ir->GetLHSExpression(stmt[stmt_num].code);
+
CG_outputRepr *assignment = ir->builder()->CreateAssignment(0,
lhs, temp->clone());
-
+
stmt[stmt_num].code = assignment;
}
// call function to replace rhs with temporary array
}
}
-
+
//std::cout << "End of scalar_expand function!! \n";
-
+
// if(arrName == "RHS"){
DependenceVector dv;
std::vector<DependenceVector> E;
dv.lbounds = std::vector<omega::coef_t>(4);
dv.ubounds = std::vector<omega::coef_t>(4);
dv.type = DEP_W2R;
-
+
for (int k = 0; k < 4; k++) {
dv.lbounds[k] = 0;
dv.ubounds[k] = 0;
-
+
}
-
+
//std::vector<IR_ArrayRef*> array_refs = ir->FindArrayRef(stmt[newStmt_num].code);
dv.sym = tmp_sym->clone();
-
+
E.push_back(dv);
-
+
dep.connect(newStmt_num, stmt_num, E);
// }
-
-}
-
+}
std::pair<Relation, Relation> createCSRstyleISandXFORM(CG_outputBuilder *ocg,
@@ -3775,98 +3771,98 @@ std::pair<Relation, Relation> createCSRstyleISandXFORM(CG_outputBuilder *ocg,
std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols,
std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_string,
Loop *this_loop) {
-
+
Relation IS(outer_loop_bounds.size() + 1 + zero_loop_bounds.size());
Relation XFORM(outer_loop_bounds.size() + 1 + zero_loop_bounds.size(),
2 * (outer_loop_bounds.size() + 1 + zero_loop_bounds.size()) + 1);
-
- F_And * f_r_ = IS.add_and();
- F_And * f_root = XFORM.add_and();
-
+
+ F_And *f_r_ = IS.add_and();
+ F_And *f_root = XFORM.add_and();
+
if (outer_loop_bounds.size() > 0) {
for (int it = 0; it < IS.n_set(); it++) {
IS.name_set_var(it + 1,
const_cast<Relation &>(outer_loop_bounds[0]).set_var(it + 1)->name());
XFORM.name_input_var(it + 1,
const_cast<Relation &>(outer_loop_bounds[0]).set_var(it + 1)->name());
-
+
}
} else if (zero_loop_bounds.size() > 0) {
for (int it = 0; it < IS.n_set(); it++) {
IS.name_set_var(it + 1,
const_cast<Relation &>(zero_loop_bounds.begin()->second).set_var(
- it + 1)->name());
+ it + 1)->name());
XFORM.name_input_var(it + 1,
const_cast<Relation &>(zero_loop_bounds.begin()->second).set_var(
- it + 1)->name());
-
+ it + 1)->name());
+
}
-
+
}
-
+
for (int i = 0; i < outer_loop_bounds.size(); i++)
IS = replace_set_var_as_another_set_var(IS, outer_loop_bounds[i], i + 1,
i + 1);
-
+
int count = 1;
for (std::map<int, Relation>::iterator i = zero_loop_bounds.begin();
i != zero_loop_bounds.end(); i++, count++)
IS = replace_set_var_as_another_set_var(IS, i->second,
outer_loop_bounds.size() + 1 + count, i->first);
-
+
if (outer_loop_bounds.size() > 0) {
Free_Var_Decl *lb = new Free_Var_Decl(index_name + "_", 1); // index_
Variable_ID csr_lb = IS.get_local(lb, Input_Tuple);
-
+
Free_Var_Decl *ub = new Free_Var_Decl(index_name + "__", 1); // index__
Variable_ID csr_ub = IS.get_local(ub, Input_Tuple);
-
+
//lower bound
-
- F_And * f_r = IS.and_with_and();
+
+ F_And *f_r = IS.and_with_and();
GEQ_Handle lower_bound = f_r->add_GEQ();
lower_bound.update_coef(csr_lb, -1);
lower_bound.update_coef(IS.set_var(outer_loop_bounds.size() + 1), 1);
-
+
//upper bound
-
+
GEQ_Handle upper_bound = f_r->add_GEQ();
upper_bound.update_coef(csr_ub, 1);
upper_bound.update_coef(IS.set_var(outer_loop_bounds.size() + 1), -1);
upper_bound.update_const(-1);
-
+
omega::CG_stringBuilder *ocgs = new CG_stringBuilder;
-
+
std::vector<omega::CG_outputRepr *> reprs;
std::vector<omega::CG_outputRepr *> reprs2;
-
+
std::vector<omega::CG_outputRepr *> reprs3;
std::vector<omega::CG_outputRepr *> reprs4;
-
+
reprs.push_back(
- ocg->CreateIdent(IS.set_var(outer_loop_bounds.size())->name()));
+ ocg->CreateIdent(IS.set_var(outer_loop_bounds.size())->name()));
reprs2.push_back(
- ocgs->CreateIdent(
- IS.set_var(outer_loop_bounds.size())->name()));
+ ocgs->CreateIdent(
+ IS.set_var(outer_loop_bounds.size())->name()));
uninterpreted_symbols.insert(
- std::pair<std::string, std::vector<CG_outputRepr *> >(
- index_name + "_", reprs));
+ std::pair<std::string, std::vector<CG_outputRepr *> >(
+ index_name + "_", reprs));
uninterpreted_symbols_string.insert(
- std::pair<std::string, std::vector<CG_outputRepr *> >(
- index_name + "_", reprs2));
-
+ std::pair<std::string, std::vector<CG_outputRepr *> >(
+ index_name + "_", reprs2));
+
std::string arg = "(" + IS.set_var(outer_loop_bounds.size())->name()
- + ")";
- std::vector< std::string > argvec;
- argvec.push_back( arg );
-
+ + ")";
+ std::vector<std::string> argvec;
+ argvec.push_back(arg);
+
CG_outputRepr *repr = ocg->CreateArrayRefExpression(index_name,
ocg->CreateIdent(IS.set_var(outer_loop_bounds.size())->name()));
-
+
//fprintf(stderr, "( VECTOR _)\n");
//fprintf(stderr, "loop.cc calling CreateDefineMacro( %s, argvec, repr)\n", (index_name + "_").c_str());
this_loop->ir->CreateDefineMacro(index_name + "_", argvec, repr);
-
+
Relation known_(copy(IS).n_set());
known_.copy_names(copy(IS));
known_.setup_names();
@@ -3878,80 +3874,81 @@ std::pair<Relation, Relation> createCSRstyleISandXFORM(CG_outputBuilder *ocg,
g.update_coef(index_lb, -1);
g.update_const(-1);
this_loop->addKnown(known_);
-
+
reprs3.push_back(
-
- ocg->CreateIdent(IS.set_var(outer_loop_bounds.size())->name()));
+
+ ocg->CreateIdent(IS.set_var(outer_loop_bounds.size())->name()));
reprs4.push_back(
-
- ocgs->CreateIdent(IS.set_var(outer_loop_bounds.size())->name()));
-
+
+ ocgs->CreateIdent(IS.set_var(outer_loop_bounds.size())->name()));
+
CG_outputRepr *repr2 = ocg->CreateArrayRefExpression(index_name,
ocg->CreatePlus(
- ocg->CreateIdent(
- IS.set_var(outer_loop_bounds.size())->name()),
- ocg->CreateInt(1)));
-
+ ocg->CreateIdent(
+ IS.set_var(outer_loop_bounds.size())->name()),
+ ocg->CreateInt(1)));
+
//fprintf(stderr, "( VECTOR __)\n");
//fprintf(stderr, "loop.cc calling CreateDefineMacro( %s, argvec, repr)\n", (index_name + "__").c_str());
-
+
this_loop->ir->CreateDefineMacro(index_name + "__", argvec, repr2);
-
+
uninterpreted_symbols.insert(
- std::pair<std::string, std::vector<CG_outputRepr *> >(
- index_name + "__", reprs3));
+ std::pair<std::string, std::vector<CG_outputRepr *> >(
+ index_name + "__", reprs3));
uninterpreted_symbols_string.insert(
- std::pair<std::string, std::vector<CG_outputRepr *> >(
- index_name + "__", reprs4));
+ std::pair<std::string, std::vector<CG_outputRepr *> >(
+ index_name + "__", reprs4));
} else {
Free_Var_Decl *ub = new Free_Var_Decl(index_name);
Variable_ID csr_ub = IS.get_local(ub);
- F_And * f_r = IS.and_with_and();
+ F_And *f_r = IS.and_with_and();
GEQ_Handle upper_bound = f_r->add_GEQ();
upper_bound.update_coef(csr_ub, 1);
upper_bound.update_coef(IS.set_var(outer_loop_bounds.size() + 1), -1);
upper_bound.update_const(-1);
-
+
GEQ_Handle lower_bound = f_r->add_GEQ();
lower_bound.update_coef(IS.set_var(outer_loop_bounds.size() + 1), 1);
-
+
}
-
+
for (int j = 1; j <= XFORM.n_inp(); j++) {
omega::EQ_Handle h = f_root->add_EQ();
h.update_coef(XFORM.output_var(2 * j), 1);
h.update_coef(XFORM.input_var(j), -1);
}
-
+
for (int j = 1; j <= XFORM.n_out(); j += 2) {
omega::EQ_Handle h = f_root->add_EQ();
h.update_coef(XFORM.output_var(j), 1);
}
-
+
if (_DEBUG_) {
IS.print();
XFORM.print();
-
+
}
-
+
return std::pair<Relation, Relation>(IS, XFORM);
-
+
}
std::pair<Relation, Relation> construct_reduced_IS_And_XFORM(IR_Code *ir,
- const Relation &is, const Relation &xform, const std::vector<int> loops,
+ const Relation &is, const Relation &xform,
+ const std::vector<int> loops,
std::vector<int> &lex_order, Relation &known,
std::map<std::string, std::vector<CG_outputRepr *> > &uninterpreted_symbols) {
-
+
Relation IS(loops.size());
Relation XFORM(loops.size(), 2 * loops.size() + 1);
int count_ = 1;
std::map<int, int> pos_mapping;
-
+
int n = is.n_set();
Relation is_and_known = Intersection(copy(is),
Extend_Set(copy(known), n - known.n_set()));
-
+
for (int it = 0; it < loops.size(); it++, count_++) {
IS.name_set_var(count_,
const_cast<Relation &>(is).set_var(loops[it])->name());
@@ -3963,11 +3960,11 @@ std::pair<Relation, Relation> construct_reduced_IS_And_XFORM(IR_Code *ir,
const_cast<Relation &>(xform).output_var((loops[it]) * 2 - 1)->name());
pos_mapping.insert(std::pair<int, int>(count_, loops[it]));
}
-
+
XFORM.name_output_var(2 * loops.size() + 1,
const_cast<Relation &>(xform).output_var(is.n_set() * 2 + 1)->name());
-
- F_And * f_r = IS.add_and();
+
+ F_And *f_r = IS.add_and();
for (std::map<int, int>::iterator it = pos_mapping.begin();
it != pos_mapping.end(); it++)
IS = replace_set_var_as_another_set_var(IS, is_and_known, it->first,
@@ -4012,9 +4009,9 @@ std::pair<Relation, Relation> construct_reduced_IS_And_XFORM(IR_Code *ir,
CHILL_DEBUG_END
F_And *f_root = XFORM.add_and();
-
+
count_ = 1;
-
+
for (int j = 1; j <= loops.size(); j++) {
omega::EQ_Handle h = f_root->add_EQ();
h.update_coef(XFORM.output_var(2 * j), 1);
@@ -4025,7 +4022,7 @@ std::pair<Relation, Relation> construct_reduced_IS_And_XFORM(IR_Code *ir,
h.update_coef(XFORM.output_var(count_ * 2 - 1), 1);
h.update_const(-lex_order[count_ * 2 - 2]);
}
-
+
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]);
@@ -4035,34 +4032,34 @@ std::pair<Relation, Relation> construct_reduced_IS_And_XFORM(IR_Code *ir,
IS.print();
XFORM.print();
CHILL_DEBUG_END
-
+
return std::pair<Relation, Relation>(IS, XFORM);
-
+
}
std::set<std::string> inspect_repr_for_scalars(IR_Code *ir,
- CG_outputRepr * repr, std::set<std::string> ignore) {
-
+ CG_outputRepr *repr, std::set<std::string> ignore) {
+
std::vector<IR_ScalarRef *> refs = ir->FindScalarRef(repr);
std::set<std::string> loop_vars;
-
+
for (int i = 0; i < refs.size(); i++)
if (ignore.find(refs[i]->name()) == ignore.end())
loop_vars.insert(refs[i]->name());
-
+
return loop_vars;
-
+
}
std::set<std::string> inspect_loop_bounds(IR_Code *ir, const Relation &R,
int pos,
std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols) {
-
+
if (!R.is_set())
throw loop_error("Input R has to be a set not a relation!");
-
+
std::set<std::string> vars;
-
+
std::vector<CG_outputRepr *> refs;
Variable_ID v = const_cast<Relation &>(R).set_var(pos);
for (DNF_Iterator di(const_cast<Relation &>(R).query_DNF()); di; di++) {
@@ -4071,48 +4068,48 @@ std::set<std::string> inspect_loop_bounds(IR_Code *ir, const Relation &R,
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
-
- case Global_Var: {
- Global_Var_ID g = v->get_global_var();
- Variable_ID v2;
- if (g->arity() > 0) {
-
- std::string s = g->base_name();
- std::copy(
- uninterpreted_symbols.find(s)->second.begin(),
- uninterpreted_symbols.find(s)->second.end(),
- back_inserter(refs));
-
+
+ case Global_Var: {
+ Global_Var_ID g = v->get_global_var();
+ Variable_ID v2;
+ if (g->arity() > 0) {
+
+ std::string s = g->base_name();
+ std::copy(
+ uninterpreted_symbols.find(s)->second.begin(),
+ uninterpreted_symbols.find(s)->second.end(),
+ back_inserter(refs));
+
+ }
+
+ break;
}
-
- break;
- }
- default:
- break;
+ default:
+ break;
}
}
-
+
}
}
}
-
+
for (int i = 0; i < refs.size(); i++) {
std::vector<IR_ScalarRef *> refs_ = ir->FindScalarRef(refs[i]);
-
+
for (int j = 0; j < refs_.size(); j++)
vars.insert(refs_[j]->name());
-
+
}
return vars;
}
-CG_outputRepr * create_counting_loop_body(IR_Code *ir, const Relation &R,
- int pos, CG_outputRepr * count,
- std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols) {
-
+CG_outputRepr *create_counting_loop_body(IR_Code *ir, const Relation &R,
+ int pos, CG_outputRepr *count,
+ std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols) {
+
if (!R.is_set())
throw loop_error("Input R has to be a set not a relation!");
-
+
CG_outputRepr *ub, *lb;
ub = NULL;
lb = NULL;
@@ -4126,42 +4123,42 @@ CG_outputRepr * create_counting_loop_body(IR_Code *ir, const Relation &R,
for (Constr_Vars_Iter cvi(*gi); cvi; cvi++) {
Variable_ID v = cvi.curr_var();
switch (v->kind()) {
-
- case Global_Var: {
- Global_Var_ID g = v->get_global_var();
- Variable_ID v2;
- if (g->arity() > 0) {
-
- std::string s = g->base_name();
-
- if ((*gi).get_coef(v) > 0) {
- if (ub != NULL)
- throw ir_error(
- "bound expression too complex!");
-
- ub = ir->builder()->CreateInvoke(s,
- uninterpreted_symbols.find(s)->second);
- //ub = ir->builder()->CreateMinus(ub->clone(), ir->builder()->CreateInt(-(*gi).get_const()));
- same_ge_1 = true;
-
- } else {
- if (lb != NULL)
- throw ir_error(
- "bound expression too complex!");
- lb = ir->builder()->CreateInvoke(s,
- uninterpreted_symbols.find(s)->second);
- same_ge_2 = true;
-
+
+ case Global_Var: {
+ Global_Var_ID g = v->get_global_var();
+ Variable_ID v2;
+ if (g->arity() > 0) {
+
+ std::string s = g->base_name();
+
+ if ((*gi).get_coef(v) > 0) {
+ if (ub != NULL)
+ throw ir_error(
+ "bound expression too complex!");
+
+ ub = ir->builder()->CreateInvoke(s,
+ uninterpreted_symbols.find(s)->second);
+ //ub = ir->builder()->CreateMinus(ub->clone(), ir->builder()->CreateInt(-(*gi).get_const()));
+ same_ge_1 = true;
+
+ } else {
+ if (lb != NULL)
+ throw ir_error(
+ "bound expression too complex!");
+ lb = ir->builder()->CreateInvoke(s,
+ uninterpreted_symbols.find(s)->second);
+ same_ge_2 = true;
+
+ }
}
+
+ break;
}
-
- break;
- }
- default:
- break;
+ default:
+ break;
}
}
-
+
if (same_ge_1 && same_ge_2)
lb = ir->builder()->CreatePlus(lb->clone(),
ir->builder()->CreateInt(-(*gi).get_const()));
@@ -4173,181 +4170,179 @@ CG_outputRepr * create_counting_loop_body(IR_Code *ir, const Relation &R,
ir->builder()->CreateInt(-(*gi).get_const()));
}
}
-
+
}
-
+
return ir->builder()->CreatePlusAssignment(0, count,
ir->builder()->CreatePlus(
- ir->builder()->CreateMinus(ub->clone(), lb->clone()),
- ir->builder()->CreateInt(1)));
+ ir->builder()->CreateMinus(ub->clone(), lb->clone()),
+ ir->builder()->CreateInt(1)));
}
-
std::map<std::string, std::vector<std::string> > recurse_on_exp_for_arrays(
- IR_Code * ir, CG_outputRepr * exp) {
-
+ IR_Code *ir, CG_outputRepr *exp) {
+
std::map<std::string, std::vector<std::string> > arr_index_to_ref;
switch (ir->QueryExpOperation(exp)) {
-
- case IR_OP_ARRAY_VARIABLE: {
- IR_ArrayRef *ref = dynamic_cast<IR_ArrayRef *>(ir->Repr2Ref(exp));
- IR_PointerArrayRef *ref_ =
- dynamic_cast<IR_PointerArrayRef *>(ir->Repr2Ref(exp));
- if (ref == NULL && ref_ == NULL)
- throw loop_error("Array symbol unidentifiable!");
-
- if (ref != NULL) {
- std::vector<std::string> s0;
-
- for (int i = 0; i < ref->n_dim(); i++) {
- CG_outputRepr * index = ref->index(i);
- std::map<std::string, std::vector<std::string> > a0 =
- recurse_on_exp_for_arrays(ir, index);
- std::vector<std::string> s;
- for (std::map<std::string, std::vector<std::string> >::iterator j =
- a0.begin(); j != a0.end(); j++) {
- if (j->second.size() != 1 && (j->second)[0] != "")
- throw loop_error(
- "indirect array references not allowed in guard!");
- s.push_back(j->first);
+
+ case IR_OP_ARRAY_VARIABLE: {
+ IR_ArrayRef *ref = dynamic_cast<IR_ArrayRef *>(ir->Repr2Ref(exp));
+ IR_PointerArrayRef *ref_ =
+ dynamic_cast<IR_PointerArrayRef *>(ir->Repr2Ref(exp));
+ if (ref == NULL && ref_ == NULL)
+ throw loop_error("Array symbol unidentifiable!");
+
+ if (ref != NULL) {
+ std::vector<std::string> s0;
+
+ for (int i = 0; i < ref->n_dim(); i++) {
+ CG_outputRepr *index = ref->index(i);
+ std::map<std::string, std::vector<std::string> > a0 =
+ recurse_on_exp_for_arrays(ir, index);
+ std::vector<std::string> s;
+ for (std::map<std::string, std::vector<std::string> >::iterator j =
+ a0.begin(); j != a0.end(); j++) {
+ if (j->second.size() != 1 && (j->second)[0] != "")
+ throw loop_error(
+ "indirect array references not allowed in guard!");
+ s.push_back(j->first);
+ }
+ std::copy(s.begin(), s.end(), back_inserter(s0));
}
- std::copy(s.begin(), s.end(), back_inserter(s0));
- }
- arr_index_to_ref.insert(
- std::pair<std::string, std::vector<std::string> >(
- ref->name(), s0));
- } else {
- std::vector<std::string> s0;
- for (int i = 0; i < ref_->n_dim(); i++) {
- CG_outputRepr * index = ref_->index(i);
- std::map<std::string, std::vector<std::string> > a0 =
- recurse_on_exp_for_arrays(ir, index);
- std::vector<std::string> s;
- for (std::map<std::string, std::vector<std::string> >::iterator j =
- a0.begin(); j != a0.end(); j++) {
- if (j->second.size() != 1 && (j->second)[0] != "")
- throw loop_error(
- "indirect array references not allowed in guard!");
- s.push_back(j->first);
+ arr_index_to_ref.insert(
+ std::pair<std::string, std::vector<std::string> >(
+ ref->name(), s0));
+ } else {
+ std::vector<std::string> s0;
+ for (int i = 0; i < ref_->n_dim(); i++) {
+ CG_outputRepr *index = ref_->index(i);
+ std::map<std::string, std::vector<std::string> > a0 =
+ recurse_on_exp_for_arrays(ir, index);
+ std::vector<std::string> s;
+ for (std::map<std::string, std::vector<std::string> >::iterator j =
+ a0.begin(); j != a0.end(); j++) {
+ if (j->second.size() != 1 && (j->second)[0] != "")
+ throw loop_error(
+ "indirect array references not allowed in guard!");
+ s.push_back(j->first);
+ }
+ std::copy(s.begin(), s.end(), back_inserter(s0));
}
- std::copy(s.begin(), s.end(), back_inserter(s0));
+ arr_index_to_ref.insert(
+ std::pair<std::string, std::vector<std::string> >(
+ ref_->name(), s0));
}
- arr_index_to_ref.insert(
- std::pair<std::string, std::vector<std::string> >(
- ref_->name(), s0));
+ break;
}
- break;
- }
- case IR_OP_PLUS:
- case IR_OP_MINUS:
- case IR_OP_MULTIPLY:
- case IR_OP_DIVIDE: {
- std::vector<CG_outputRepr *> v = ir->QueryExpOperand(exp);
- std::map<std::string, std::vector<std::string> > a0 =
- recurse_on_exp_for_arrays(ir, v[0]);
- std::map<std::string, std::vector<std::string> > a1 =
- recurse_on_exp_for_arrays(ir, v[1]);
- arr_index_to_ref.insert(a0.begin(), a0.end());
- arr_index_to_ref.insert(a1.begin(), a1.end());
- break;
-
- }
- case IR_OP_POSITIVE:
- case IR_OP_NEGATIVE: {
- std::vector<CG_outputRepr *> v = ir->QueryExpOperand(exp);
- std::map<std::string, std::vector<std::string> > a0 =
- recurse_on_exp_for_arrays(ir, v[0]);
-
- arr_index_to_ref.insert(a0.begin(), a0.end());
- break;
-
- }
- case IR_OP_VARIABLE: {
- std::vector<CG_outputRepr *> v = ir->QueryExpOperand(exp);
- IR_ScalarRef *ref = static_cast<IR_ScalarRef *>(ir->Repr2Ref(v[0]));
-
- std::string s = ref->name();
- std::vector<std::string> to_insert;
- to_insert.push_back("");
- arr_index_to_ref.insert(
- std::pair<std::string, std::vector<std::string> >(s,
- to_insert));
- break;
- }
- case IR_OP_CONSTANT:
- break;
-
- default: {
- std::vector<CG_outputRepr *> v = ir->QueryExpOperand(exp);
-
- for (int i = 0; i < v.size(); i++) {
+ case IR_OP_PLUS:
+ case IR_OP_MINUS:
+ case IR_OP_MULTIPLY:
+ case IR_OP_DIVIDE: {
+ std::vector<CG_outputRepr *> v = ir->QueryExpOperand(exp);
std::map<std::string, std::vector<std::string> > a0 =
- recurse_on_exp_for_arrays(ir, v[i]);
-
+ recurse_on_exp_for_arrays(ir, v[0]);
+ std::map<std::string, std::vector<std::string> > a1 =
+ recurse_on_exp_for_arrays(ir, v[1]);
arr_index_to_ref.insert(a0.begin(), a0.end());
+ arr_index_to_ref.insert(a1.begin(), a1.end());
+ break;
+
+ }
+ case IR_OP_POSITIVE:
+ case IR_OP_NEGATIVE: {
+ std::vector<CG_outputRepr *> v = ir->QueryExpOperand(exp);
+ std::map<std::string, std::vector<std::string> > a0 =
+ recurse_on_exp_for_arrays(ir, v[0]);
+
+ arr_index_to_ref.insert(a0.begin(), a0.end());
+ break;
+
+ }
+ case IR_OP_VARIABLE: {
+ std::vector<CG_outputRepr *> v = ir->QueryExpOperand(exp);
+ IR_ScalarRef *ref = static_cast<IR_ScalarRef *>(ir->Repr2Ref(v[0]));
+
+ std::string s = ref->name();
+ std::vector<std::string> to_insert;
+ to_insert.push_back("");
+ arr_index_to_ref.insert(
+ std::pair<std::string, std::vector<std::string> >(s,
+ to_insert));
+ break;
+ }
+ case IR_OP_CONSTANT:
+ break;
+
+ default: {
+ std::vector<CG_outputRepr *> v = ir->QueryExpOperand(exp);
+
+ for (int i = 0; i < v.size(); i++) {
+ std::map<std::string, std::vector<std::string> > a0 =
+ recurse_on_exp_for_arrays(ir, v[i]);
+
+ arr_index_to_ref.insert(a0.begin(), a0.end());
+ }
+
+ break;
}
-
- break;
- }
}
return arr_index_to_ref;
}
-
std::vector<CG_outputRepr *> find_guards(IR_Code *ir, IR_Control *code) {
CHILL_DEBUG_PRINT("find_guards()\n");
std::vector<CG_outputRepr *> guards;
switch (code->type()) {
- case IR_CONTROL_IF: {
- 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) {
- 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) {
- CHILL_DEBUG_PRINT("recursing on then\n");
- else_body = find_guards(ir,
- dynamic_cast<IR_If*>(code)->else_body());
+ case IR_CONTROL_IF: {
+ 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) {
+ 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) {
+ CHILL_DEBUG_PRINT("recursing on then\n");
+ else_body = find_guards(ir,
+ dynamic_cast<IR_If *>(code)->else_body());
+ }
+
+ guards.push_back(cond);
+ if (then_body.size() > 0)
+ std::copy(then_body.begin(), then_body.end(),
+ back_inserter(guards));
+ if (else_body.size() > 0)
+ std::copy(else_body.begin(), else_body.end(),
+ back_inserter(guards));
+ break;
}
-
- guards.push_back(cond);
- if (then_body.size() > 0)
- std::copy(then_body.begin(), then_body.end(),
- back_inserter(guards));
- if (else_body.size() > 0)
- std::copy(else_body.begin(), else_body.end(),
- back_inserter(guards));
- break;
- }
- case IR_CONTROL_BLOCK: {
- CHILL_DEBUG_PRINT("it's a control block\n");
- IR_Block* IRCB = dynamic_cast<IR_Block*>(code);
- CHILL_DEBUG_PRINT("calling ir->FindOneLevelControlStructure(IRCB);\n");
- std::vector<IR_Control *> stmts = ir->FindOneLevelControlStructure(IRCB);
-
- for (int i = 0; i < stmts.size(); i++) {
- std::vector<CG_outputRepr *> stmt_repr = find_guards(ir, stmts[i]);
- std::copy(stmt_repr.begin(), stmt_repr.end(),
- back_inserter(guards));
+ case IR_CONTROL_BLOCK: {
+ CHILL_DEBUG_PRINT("it's a control block\n");
+ IR_Block *IRCB = dynamic_cast<IR_Block *>(code);
+ CHILL_DEBUG_PRINT("calling ir->FindOneLevelControlStructure(IRCB);\n");
+ std::vector<IR_Control *> stmts = ir->FindOneLevelControlStructure(IRCB);
+
+ for (int i = 0; i < stmts.size(); i++) {
+ std::vector<CG_outputRepr *> stmt_repr = find_guards(ir, stmts[i]);
+ std::copy(stmt_repr.begin(), stmt_repr.end(),
+ back_inserter(guards));
+ }
+ break;
}
- break;
- }
- case IR_CONTROL_LOOP: {
- 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)
- std::copy(body.begin(), body.end(), back_inserter(guards));
- break;
- } // loop
+ case IR_CONTROL_LOOP: {
+ 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)
+ std::copy(body.begin(), body.end(), back_inserter(guards));
+ break;
+ } // loop
} // switch
return guards;
}
@@ -4359,43 +4354,43 @@ bool sort_helper(std::pair<std::string, std::vector<std::string> > i,
for (int k = 0; k < i.second.size(); k++)
if (i.second[k] != "")
c1++;
-
+
for (int k = 0; k < j.second.size(); k++)
if (j.second[k] != "")
c2++;
return (c1 < c2);
-
+
}
bool sort_helper_2(std::pair<int, int> i, std::pair<int, int> j) {
-
+
return (i.second < j.second);
-
+
}
std::vector<std::string> construct_iteration_order(
- std::map<std::string, std::vector<std::string> > & input) {
+ std::map<std::string, std::vector<std::string> > &input) {
std::vector<std::string> arrays;
std::vector<std::string> scalars;
std::vector<std::pair<std::string, std::vector<std::string> > > input_aid;
-
+
for (std::map<std::string, std::vector<std::string> >::iterator j =
- input.begin(); j != input.end(); j++)
+ input.begin(); j != input.end(); j++)
input_aid.push_back(
- std::pair<std::string, std::vector<std::string> >(j->first,
- j->second));
-
+ std::pair<std::string, std::vector<std::string> >(j->first,
+ j->second));
+
std::sort(input_aid.begin(), input_aid.end(), sort_helper);
-
+
for (int j = 0; j < input_aid[input_aid.size() - 1].second.size(); j++)
if (input_aid[input_aid.size() - 1].second[j] != "") {
arrays.push_back(input_aid[input_aid.size() - 1].second[j]);
-
+
}
-
+
if (arrays.size() > 0) {
for (int i = input_aid.size() - 2; i >= 0; i--) {
-
+
int max_count = 0;
for (int j = 0; j < input_aid[i].second.size(); j++)
if (input_aid[i].second[j] != "") {
@@ -4421,7 +4416,7 @@ std::vector<std::string> construct_iteration_order(
}
}
} else {
-
+
for (int i = input_aid.size() - 1; i >= 0; i--) {
arrays.push_back(input_aid[i].first);
}
diff --git a/src/transformations/loop_basic.cc b/src/transformations/loop_basic.cc
index a058598..1be0981 100644
--- a/src/transformations/loop_basic.cc
+++ b/src/transformations/loop_basic.cc
@@ -19,7 +19,7 @@ void Loop::permute(const std::vector<int> &pi) {
std::set<int> active;
for (int i = 0; i < stmt.size(); i++)
active.insert(i);
-
+
permute(active, pi);
}
@@ -30,12 +30,13 @@ void Loop::original() {
setLexicalOrder(0, active);
//apply_xform();
}
+
void Loop::permute(int stmt_num, int level, const std::vector<int> &pi) {
// check for sanity of parameters
int starting_order;
if (stmt_num < 0 || stmt_num >= stmt.size())
throw std::invalid_argument(
- "invalid statement number " + to_string(stmt_num));
+ "invalid statement number " + to_string(stmt_num));
std::set<int> active;
if (level < 0 || level > stmt[stmt_num].loop_level.size())
throw std::invalid_argument("3invalid loop level " + to_string(level));
@@ -61,14 +62,14 @@ void Loop::permute(int stmt_num, int level, const std::vector<int> &pi) {
for (std::set<int>::iterator i = active.begin(); i != active.end(); i++)
if (level + pi.size() - 1 > stmt[*i].loop_level.size())
throw std::invalid_argument(
- "invalid permutation for statement " + to_string(*i));
-
+ "invalid permutation for statement " + to_string(*i));
+
// invalidate saved codegen computation
delete last_compute_cgr_;
last_compute_cgr_ = NULL;
delete last_compute_cg_;
last_compute_cg_ = NULL;
-
+
// Update transformation relations
for (std::set<int>::iterator i = active.begin(); i != active.end(); i++) {
int n = stmt[*i].xform.n_out();
@@ -97,7 +98,7 @@ void Loop::permute(int stmt_num, int level, const std::vector<int> &pi) {
stmt[*i].xform = Composition(mapping, stmt[*i].xform);
stmt[*i].xform.simplify();
}
-
+
// get the permuation for dependence vectors
std::vector<int> t;
for (int i = 0; i < pi.size(); i++)
@@ -122,41 +123,41 @@ void Loop::permute(int stmt_num, int level, const std::vector<int> &pi) {
dep_pi[i] = t[i - min_dep_dim];
for (int i = max_dep_dim + 1; i < dep.num_dim(); i++)
dep_pi[i] = i;
-
+
dep.permute(dep_pi, active);
-
+
// update the dependence graph
DependenceGraph g(dep.num_dim());
for (int i = 0; i < dep.vertex.size(); i++)
g.insert();
for (int i = 0; i < dep.vertex.size(); i++)
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[i].second.begin(); j != dep.vertex[i].second.end();
+ dep.vertex[i].second.begin(); j != dep.vertex[i].second.end();
j++) {
if ((active.find(i) != active.end()
&& active.find(j->first) != active.end())) {
std::vector<DependenceVector> dv = j->second;
for (int k = 0; k < dv.size(); k++) {
switch (dv[k].type) {
- case DEP_W2R:
- case DEP_R2W:
- case DEP_W2W:
- case DEP_R2R: {
- std::vector<coef_t> lbounds(dep.num_dim());
- std::vector<coef_t> ubounds(dep.num_dim());
- for (int d = 0; d < dep.num_dim(); d++) {
- lbounds[d] = dv[k].lbounds[dep_pi[d]];
- ubounds[d] = dv[k].ubounds[dep_pi[d]];
+ case DEP_W2R:
+ case DEP_R2W:
+ case DEP_W2W:
+ case DEP_R2R: {
+ std::vector<coef_t> lbounds(dep.num_dim());
+ std::vector<coef_t> ubounds(dep.num_dim());
+ for (int d = 0; d < dep.num_dim(); d++) {
+ lbounds[d] = dv[k].lbounds[dep_pi[d]];
+ ubounds[d] = dv[k].ubounds[dep_pi[d]];
+ }
+ dv[k].lbounds = lbounds;
+ dv[k].ubounds = ubounds;
+ break;
}
- dv[k].lbounds = lbounds;
- dv[k].ubounds = ubounds;
- break;
- }
- case DEP_CONTROL: {
- break;
- }
- default:
- throw loop_error("unknown dependence type");
+ case DEP_CONTROL: {
+ break;
+ }
+ default:
+ throw loop_error("unknown dependence type");
}
}
g.connect(i, j->first, dv);
@@ -168,27 +169,27 @@ void Loop::permute(int stmt_num, int level, const std::vector<int> &pi) {
std::vector<DependenceVector> dv = j->second;
for (int k = 0; k < dv.size(); k++)
switch (dv[k].type) {
- case DEP_W2R:
- case DEP_R2W:
- case DEP_W2W:
- case DEP_R2R: {
- for (int d = 0; d < dep.num_dim(); d++)
- if (dep_pi[d] != d) {
- dv[k].lbounds[d] = -posInfinity;
- dv[k].ubounds[d] = posInfinity;
- }
- break;
- }
- case DEP_CONTROL:
- break;
- default:
- throw loop_error("unknown dependence type");
+ case DEP_W2R:
+ case DEP_R2W:
+ case DEP_W2W:
+ case DEP_R2R: {
+ for (int d = 0; d < dep.num_dim(); d++)
+ if (dep_pi[d] != d) {
+ dv[k].lbounds[d] = -posInfinity;
+ dv[k].ubounds[d] = posInfinity;
+ }
+ break;
+ }
+ case DEP_CONTROL:
+ break;
+ default:
+ throw loop_error("unknown dependence type");
}
g.connect(i, j->first, dv);
}
}
dep = g;
-
+
// update loop level information
for (std::set<int>::iterator i = active.begin(); i != active.end(); i++) {
int cur_dep_dim = min_dep_dim;
@@ -196,66 +197,67 @@ void Loop::permute(int stmt_num, int level, const std::vector<int> &pi) {
for (int j = 1; j <= stmt[*i].loop_level.size(); j++)
if (j >= level && j < level + pi.size()) {
switch (stmt[*i].loop_level[pi_inverse[j - level] - 1].type) {
- case LoopLevelOriginal:
- new_loop_level[j - 1].type = LoopLevelOriginal;
- new_loop_level[j - 1].payload = cur_dep_dim++;
- new_loop_level[j - 1].parallel_level =
- stmt[*i].loop_level[pi_inverse[j - level] - 1].parallel_level;
- break;
- case LoopLevelTile: {
- new_loop_level[j - 1].type = LoopLevelTile;
- int ref_level = stmt[*i].loop_level[pi_inverse[j - level]
- - 1].payload;
- if (ref_level >= level && ref_level < level + pi.size())
- new_loop_level[j - 1].payload = pi_inverse[ref_level
- - level];
- else
- new_loop_level[j - 1].payload = ref_level;
- new_loop_level[j - 1].parallel_level = stmt[*i].loop_level[j
- - 1].parallel_level;
- break;
- }
- default:
- throw loop_error(
- "unknown loop level information for statement "
- + to_string(*i));
+ case LoopLevelOriginal:
+ new_loop_level[j - 1].type = LoopLevelOriginal;
+ new_loop_level[j - 1].payload = cur_dep_dim++;
+ new_loop_level[j - 1].parallel_level =
+ stmt[*i].loop_level[pi_inverse[j - level] - 1].parallel_level;
+ break;
+ case LoopLevelTile: {
+ new_loop_level[j - 1].type = LoopLevelTile;
+ int ref_level = stmt[*i].loop_level[pi_inverse[j - level]
+ - 1].payload;
+ if (ref_level >= level && ref_level < level + pi.size())
+ new_loop_level[j - 1].payload = pi_inverse[ref_level
+ - level];
+ else
+ new_loop_level[j - 1].payload = ref_level;
+ new_loop_level[j - 1].parallel_level = stmt[*i].loop_level[j
+ - 1].parallel_level;
+ break;
+ }
+ default:
+ throw loop_error(
+ "unknown loop level information for statement "
+ + to_string(*i));
}
} else {
switch (stmt[*i].loop_level[j - 1].type) {
- case LoopLevelOriginal:
- new_loop_level[j - 1].type = LoopLevelOriginal;
- new_loop_level[j - 1].payload =
- stmt[*i].loop_level[j - 1].payload;
- new_loop_level[j - 1].parallel_level = stmt[*i].loop_level[j
- - 1].parallel_level;
- break;
- case LoopLevelTile: {
- new_loop_level[j - 1].type = LoopLevelTile;
- int ref_level = stmt[*i].loop_level[j - 1].payload;
- if (ref_level >= level && ref_level < level + pi.size())
- new_loop_level[j - 1].payload = pi_inverse[ref_level
- - level];
- else
- new_loop_level[j - 1].payload = ref_level;
- new_loop_level[j - 1].parallel_level = stmt[*i].loop_level[j
- - 1].parallel_level;
- break;
- }
- default:
- throw loop_error(
- "unknown loop level information for statement "
- + to_string(*i));
+ case LoopLevelOriginal:
+ new_loop_level[j - 1].type = LoopLevelOriginal;
+ new_loop_level[j - 1].payload =
+ stmt[*i].loop_level[j - 1].payload;
+ new_loop_level[j - 1].parallel_level = stmt[*i].loop_level[j
+ - 1].parallel_level;
+ break;
+ case LoopLevelTile: {
+ new_loop_level[j - 1].type = LoopLevelTile;
+ int ref_level = stmt[*i].loop_level[j - 1].payload;
+ if (ref_level >= level && ref_level < level + pi.size())
+ new_loop_level[j - 1].payload = pi_inverse[ref_level
+ - level];
+ else
+ new_loop_level[j - 1].payload = ref_level;
+ new_loop_level[j - 1].parallel_level = stmt[*i].loop_level[j
+ - 1].parallel_level;
+ break;
+ }
+ default:
+ throw loop_error(
+ "unknown loop level information for statement "
+ + to_string(*i));
}
}
stmt[*i].loop_level = new_loop_level;
}
-
+
setLexicalOrder(2 * level - 2, active, starting_order);
}
+
void Loop::permute(const std::set<int> &active, const std::vector<int> &pi) {
if (active.size() == 0 || pi.size() == 0)
return;
-
+
// check for sanity of parameters
int level = pi[0];
for (int i = 1; i < pi.size(); i++)
@@ -287,14 +289,14 @@ void Loop::permute(const std::set<int> &active, const std::vector<int> &pi) {
for (int j = 0; j < 2 * level - 3; j += 2)
if (lex[j] != lex2[j])
throw std::invalid_argument(
- "statements to permute must be in the same subloop");
+ "statements to permute must be in the same subloop");
for (int j = 0; j < pi.size(); j++)
if (!(stmt[*i].loop_level[level + j - 1].type
== stmt[ref_stmt_num].loop_level[level + j - 1].type
&& stmt[*i].loop_level[level + j - 1].payload
- == stmt[ref_stmt_num].loop_level[level + j - 1].payload))
+ == stmt[ref_stmt_num].loop_level[level + j - 1].payload))
throw std::invalid_argument(
- "permuted loops must have the same loop level types");
+ "permuted loops must have the same loop level types");
}
}
// invalidate saved codegen computation
@@ -302,7 +304,7 @@ void Loop::permute(const std::set<int> &active, const std::vector<int> &pi) {
last_compute_cgr_ = NULL;
delete last_compute_cg_;
last_compute_cg_ = NULL;
-
+
// Update transformation relations
for (std::set<int>::iterator i = active.begin(); i != active.end(); i++) {
int n = stmt[*i].xform.n_out();
@@ -328,11 +330,11 @@ void Loop::permute(const std::set<int> &active, const std::vector<int> &pi) {
h.update_coef(mapping.output_var(2 * j), 1);
h.update_coef(mapping.input_var(2 * j), -1);
}
-
+
stmt[*i].xform = Composition(mapping, stmt[*i].xform);
stmt[*i].xform.simplify();
}
-
+
// get the permuation for dependence vectors
std::vector<int> t;
for (int i = 0; i < pi.size(); i++)
@@ -357,41 +359,41 @@ void Loop::permute(const std::set<int> &active, const std::vector<int> &pi) {
dep_pi[i] = t[i - min_dep_dim];
for (int i = max_dep_dim + 1; i < num_dep_dim; i++)
dep_pi[i] = i;
-
+
dep.permute(dep_pi, active);
-
+
// update the dependence graph
DependenceGraph g(dep.num_dim());
for (int i = 0; i < dep.vertex.size(); i++)
g.insert();
for (int i = 0; i < dep.vertex.size(); i++)
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[i].second.begin(); j != dep.vertex[i].second.end();
+ dep.vertex[i].second.begin(); j != dep.vertex[i].second.end();
j++) { //
if ((active.find(i) != active.end()
&& active.find(j->first) != active.end())) {
std::vector<DependenceVector> dv = j->second;
for (int k = 0; k < dv.size(); k++) {
switch (dv[k].type) {
- case DEP_W2R:
- case DEP_R2W:
- case DEP_W2W:
- case DEP_R2R: {
- std::vector<coef_t> lbounds(num_dep_dim);
- std::vector<coef_t> ubounds(num_dep_dim);
- for (int d = 0; d < num_dep_dim; d++) {
- lbounds[d] = dv[k].lbounds[dep_pi[d]];
- ubounds[d] = dv[k].ubounds[dep_pi[d]];
+ case DEP_W2R:
+ case DEP_R2W:
+ case DEP_W2W:
+ case DEP_R2R: {
+ std::vector<coef_t> lbounds(num_dep_dim);
+ std::vector<coef_t> ubounds(num_dep_dim);
+ for (int d = 0; d < num_dep_dim; d++) {
+ lbounds[d] = dv[k].lbounds[dep_pi[d]];
+ ubounds[d] = dv[k].ubounds[dep_pi[d]];
+ }
+ dv[k].lbounds = lbounds;
+ dv[k].ubounds = ubounds;
+ break;
}
- dv[k].lbounds = lbounds;
- dv[k].ubounds = ubounds;
- break;
- }
- case DEP_CONTROL: {
- break;
- }
- default:
- throw loop_error("unknown dependence type");
+ case DEP_CONTROL: {
+ break;
+ }
+ default:
+ throw loop_error("unknown dependence type");
}
}
g.connect(i, j->first, dv);
@@ -403,27 +405,27 @@ void Loop::permute(const std::set<int> &active, const std::vector<int> &pi) {
std::vector<DependenceVector> dv = j->second;
for (int k = 0; k < dv.size(); k++)
switch (dv[k].type) {
- case DEP_W2R:
- case DEP_R2W:
- case DEP_W2W:
- case DEP_R2R: {
- for (int d = 0; d < num_dep_dim; d++)
- if (dep_pi[d] != d) {
- dv[k].lbounds[d] = -posInfinity;
- dv[k].ubounds[d] = posInfinity;
- }
- break;
- }
- case DEP_CONTROL:
- break;
- default:
- throw loop_error("unknown dependence type");
+ case DEP_W2R:
+ case DEP_R2W:
+ case DEP_W2W:
+ case DEP_R2R: {
+ for (int d = 0; d < num_dep_dim; d++)
+ if (dep_pi[d] != d) {
+ dv[k].lbounds[d] = -posInfinity;
+ dv[k].ubounds[d] = posInfinity;
+ }
+ break;
+ }
+ case DEP_CONTROL:
+ break;
+ default:
+ throw loop_error("unknown dependence type");
}
g.connect(i, j->first, dv);
}
}
dep = g;
-
+
// update loop level information
for (std::set<int>::iterator i = active.begin(); i != active.end(); i++) {
int cur_dep_dim = min_dep_dim;
@@ -431,65 +433,65 @@ void Loop::permute(const std::set<int> &active, const std::vector<int> &pi) {
for (int j = 1; j <= stmt[*i].loop_level.size(); j++)
if (j >= level && j < level + pi.size()) {
switch (stmt[*i].loop_level[reverse_pi[j - level] - 1].type) {
- case LoopLevelOriginal:
- new_loop_level[j - 1].type = LoopLevelOriginal;
- new_loop_level[j - 1].payload = cur_dep_dim++;
- new_loop_level[j - 1].parallel_level =
- stmt[*i].loop_level[reverse_pi[j - level] - 1].parallel_level;
- break;
- case LoopLevelTile: {
- new_loop_level[j - 1].type = LoopLevelTile;
- int ref_level = stmt[*i].loop_level[reverse_pi[j - level]-1].payload;
- if (ref_level >= level && ref_level < level + pi.size())
- new_loop_level[j - 1].payload = reverse_pi[ref_level
- - level];
- else
- new_loop_level[j - 1].payload = ref_level;
- new_loop_level[j - 1].parallel_level =
- stmt[*i].loop_level[reverse_pi[j - level] - 1].parallel_level;
- break;
- }
- default:
- throw loop_error(
- "unknown loop level information for statement "
- + to_string(*i));
+ case LoopLevelOriginal:
+ new_loop_level[j - 1].type = LoopLevelOriginal;
+ new_loop_level[j - 1].payload = cur_dep_dim++;
+ new_loop_level[j - 1].parallel_level =
+ stmt[*i].loop_level[reverse_pi[j - level] - 1].parallel_level;
+ break;
+ case LoopLevelTile: {
+ new_loop_level[j - 1].type = LoopLevelTile;
+ int ref_level = stmt[*i].loop_level[reverse_pi[j - level] - 1].payload;
+ if (ref_level >= level && ref_level < level + pi.size())
+ new_loop_level[j - 1].payload = reverse_pi[ref_level
+ - level];
+ else
+ new_loop_level[j - 1].payload = ref_level;
+ new_loop_level[j - 1].parallel_level =
+ stmt[*i].loop_level[reverse_pi[j - level] - 1].parallel_level;
+ break;
+ }
+ default:
+ throw loop_error(
+ "unknown loop level information for statement "
+ + to_string(*i));
}
} else {
switch (stmt[*i].loop_level[j - 1].type) {
- case LoopLevelOriginal:
- new_loop_level[j - 1].type = LoopLevelOriginal;
- new_loop_level[j - 1].payload =
- stmt[*i].loop_level[j - 1].payload;
- new_loop_level[j - 1].parallel_level = stmt[*i].loop_level[j
- - 1].parallel_level;
- break;
- case LoopLevelTile: {
- new_loop_level[j - 1].type = LoopLevelTile;
- int ref_level = stmt[*i].loop_level[j - 1].payload;
- if (ref_level >= level && ref_level < level + pi.size())
- new_loop_level[j - 1].payload = reverse_pi[ref_level
- - level];
- else
- new_loop_level[j - 1].payload = ref_level;
- new_loop_level[j - 1].parallel_level = stmt[*i].loop_level[j
- - 1].parallel_level;
- break;
- }
- default:
- throw loop_error(
- "unknown loop level information for statement "
- + to_string(*i));
+ case LoopLevelOriginal:
+ new_loop_level[j - 1].type = LoopLevelOriginal;
+ new_loop_level[j - 1].payload =
+ stmt[*i].loop_level[j - 1].payload;
+ new_loop_level[j - 1].parallel_level = stmt[*i].loop_level[j
+ - 1].parallel_level;
+ break;
+ case LoopLevelTile: {
+ new_loop_level[j - 1].type = LoopLevelTile;
+ int ref_level = stmt[*i].loop_level[j - 1].payload;
+ if (ref_level >= level && ref_level < level + pi.size())
+ new_loop_level[j - 1].payload = reverse_pi[ref_level
+ - level];
+ else
+ new_loop_level[j - 1].payload = ref_level;
+ new_loop_level[j - 1].parallel_level = stmt[*i].loop_level[j
+ - 1].parallel_level;
+ break;
+ }
+ default:
+ throw loop_error(
+ "unknown loop level information for statement "
+ + to_string(*i));
}
}
stmt[*i].loop_level = new_loop_level;
}
-
+
setLexicalOrder(2 * level - 2, active);
}
-void Loop::set_array_size(std::string name, int size ){
- array_dims.insert(std::pair<std::string, int >(name, size));
+void Loop::set_array_size(std::string name, int size) {
+ array_dims.insert(std::pair<std::string, int>(name, size));
}
@@ -499,23 +501,23 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
throw std::invalid_argument("invalid statement " + to_string(stmt_num));
if (level <= 0 || level > stmt[stmt_num].loop_level.size())
throw std::invalid_argument("4invalid loop level " + to_string(level));
-
+
std::set<int> result;
int dim = 2 * level - 1;
std::vector<int> lex = getLexicalOrder(stmt_num);
std::set<int> same_loop = getStatements(lex, dim - 1);
-
+
Relation cond2 = copy(cond);
cond2.simplify();
cond2 = EQs_to_GEQs(cond2);
Conjunct *c = cond2.single_conjunct();
int cur_lex = lex[dim - 1];
-
+
for (GEQ_Iterator gi(c->GEQs()); gi; gi++) {
int max_level = (*gi).max_tuple_pos();
Relation single_cond(max_level);
single_cond.and_with_GEQ(*gi);
-
+
// TODO: should decide where to place newly created statements with
// complementary split condition from dependence graph.
bool place_after;
@@ -525,7 +527,7 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
place_after = true;
else
place_after = false;
-
+
bool temp_place_after; // = place_after;
bool assigned = false;
int part1_to_part2;
@@ -549,11 +551,11 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
Extend_Set(Complement(copy(single_cond)),
n - max_level));
}
-
+
//split dependence check
-
+
if (max_level > level) {
-
+
DNF_Iterator di1(stmt[*i].IS.query_DNF());
DNF_Iterator di2(part1.query_DNF());
for (; di1 && di2; di1++, di2++) {
@@ -569,34 +571,34 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
bool identical = false;
if (identical = !strcmp((*cvi1).var->char_name(),
(*cvi2).var->char_name())) {
-
+
for (; cvi1 && cvi2; cvi1++, cvi2++) {
-
+
if (((*cvi1).coef != (*cvi2).coef
|| (*ei1).get_const()
- != (*ei2).get_const())
+ != (*ei2).get_const())
|| (strcmp((*cvi1).var->char_name(),
(*cvi2).var->char_name()))) {
-
+
same++;
}
}
}
if ((same != 0) || !identical) {
-
+
dimension = dimension - 1;
-
+
while (stmt[*i].loop_level[dimension].type
== LoopLevelTile)
dimension =
- stmt[*i].loop_level[dimension].payload;
-
+ stmt[*i].loop_level[dimension].payload;
+
dimension = stmt[*i].loop_level[dimension].payload;
-
+
for (int i = 0; i < stmt.size(); i++) {
std::vector<std::pair<int, DependenceVector> > D;
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[i].second.begin();
+ dep.vertex[i].second.begin();
j != dep.vertex[i].second.end(); j++) {
for (int k = 0; k < j->second.size(); k++) {
DependenceVector dv = j->second[k];
@@ -604,19 +606,19 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
if (dv.hasNegative(dimension)
&& !dv.quasi)
throw loop_error(
- "loop error: Split is illegal, dependence violation!");
-
+ "loop error: Split is illegal, dependence violation!");
+
}
}
}
-
+
}
-
+
GEQ_Iterator gi1 = (*di1)->GEQs();
GEQ_Iterator gi2 = (*di2)->GEQs();
-
+
for (; gi1 && gi2; gi++, gi2++) {
-
+
Constr_Vars_Iter cvi1(*gi1);
Constr_Vars_Iter cvi2(*gi2);
int dimension = (*cvi1).var->get_position();
@@ -624,33 +626,33 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
bool identical = false;
if (identical = !strcmp((*cvi1).var->char_name(),
(*cvi2).var->char_name())) {
-
+
for (; cvi1 && cvi2; cvi1++, cvi2++) {
-
+
if (((*cvi1).coef != (*cvi2).coef
|| (*gi1).get_const()
- != (*gi2).get_const())
+ != (*gi2).get_const())
|| (strcmp((*cvi1).var->char_name(),
(*cvi2).var->char_name()))) {
-
+
same++;
}
}
}
if ((same != 0) || !identical) {
dimension = dimension - 1;
-
+
while (stmt[*i].loop_level[dimension].type
== LoopLevelTile)
stmt[*i].loop_level[dimension].payload;
-
+
dimension =
- stmt[*i].loop_level[dimension].payload;
-
+ stmt[*i].loop_level[dimension].payload;
+
for (int i = 0; i < stmt.size(); i++) {
std::vector<std::pair<int, DependenceVector> > D;
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[i].second.begin();
+ dep.vertex[i].second.begin();
j != dep.vertex[i].second.end();
j++) {
for (int k = 0; k < j->second.size();
@@ -659,22 +661,22 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
if (dv.type != DEP_CONTROL)
if (dv.hasNegative(dimension)
&& !dv.quasi)
-
+
throw loop_error(
- "loop error: Split is illegal, dependence violation!");
-
+ "loop error: Split is illegal, dependence violation!");
+
}
}
}
-
+
}
-
+
}
-
+
}
-
+
}
-
+
DNF_Iterator di3(stmt[*i].IS.query_DNF());
DNF_Iterator di4(part2.query_DNF()); //
for (; di3 && di4; di3++, di4++) {
@@ -688,52 +690,52 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
bool identical = false;
if (identical = !strcmp((*cvi1).var->char_name(),
(*cvi2).var->char_name())) {
-
+
for (; cvi1 && cvi2; cvi1++, cvi2++) {
-
+
if (((*cvi1).coef != (*cvi2).coef
|| (*ei1).get_const()
- != (*ei2).get_const())
+ != (*ei2).get_const())
|| (strcmp((*cvi1).var->char_name(),
(*cvi2).var->char_name()))) {
-
+
same++;
}
}
}
if ((same != 0) || !identical) {
dimension = dimension - 1;
-
+
while (stmt[*i].loop_level[dimension].type
== LoopLevelTile)
stmt[*i].loop_level[dimension].payload;
-
+
dimension = stmt[*i].loop_level[dimension].payload;
-
+
for (int i = 0; i < stmt.size(); i++) {
std::vector<std::pair<int, DependenceVector> > D;
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[i].second.begin();
+ dep.vertex[i].second.begin();
j != dep.vertex[i].second.end(); j++) {
for (int k = 0; k < j->second.size(); k++) {
DependenceVector dv = j->second[k];
if (dv.type != DEP_CONTROL)
if (dv.hasNegative(dimension)
&& !dv.quasi)
-
+
throw loop_error(
- "loop error: Split is illegal, dependence violation!");
-
+ "loop error: Split is illegal, dependence violation!");
+
}
}
}
-
+
}
-
+
}
GEQ_Iterator gi1 = (*di3)->GEQs();
GEQ_Iterator gi2 = (*di4)->GEQs();
-
+
for (; gi1 && gi2; gi++, gi2++) {
Constr_Vars_Iter cvi1(*gi1);
Constr_Vars_Iter cvi2(*gi2);
@@ -742,66 +744,66 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
bool identical = false;
if (identical = !strcmp((*cvi1).var->char_name(),
(*cvi2).var->char_name())) {
-
+
for (; cvi1 && cvi2; cvi1++, cvi2++) {
-
+
if (((*cvi1).coef != (*cvi2).coef
|| (*gi1).get_const()
- != (*gi2).get_const())
+ != (*gi2).get_const())
|| (strcmp((*cvi1).var->char_name(),
(*cvi2).var->char_name()))) {
-
+
same++;
}
}
}
if ((same != 0) || !identical) {
dimension = dimension - 1;
-
+
while (stmt[*i].loop_level[dimension].type //
== LoopLevelTile)
stmt[*i].loop_level[dimension].payload;
-
+
dimension = stmt[*i].loop_level[dimension].payload;
-
+
for (int i = 0; i < stmt.size(); i++) {
std::vector<std::pair<int, DependenceVector> > D;
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[i].second.begin();
+ dep.vertex[i].second.begin();
j != dep.vertex[i].second.end(); j++) {
for (int k = 0; k < j->second.size(); k++) {
DependenceVector dv = j->second[k];
if (dv.type != DEP_CONTROL)
if (dv.hasNegative(dimension)
&& !dv.quasi)
-
+
throw loop_error(
- "loop error: Split is illegal, dependence violation!");
-
+ "loop error: Split is illegal, dependence violation!");
+
}
}
}
-
+
}
-
+
}
-
+
}
-
+
}
-
+
stmt[*i].IS = part1;
-
+
int n1 = part2.n_set();
int m = this->known.n_set();
Relation test;
- if(m > n1)
+ if (m > n1)
test = Intersection(copy(this->known),
Extend_Set(copy(part2), m - part2.n_set()));
else
test = Intersection(copy(part2),
Extend_Set(copy(this->known), n1 - this->known.n_set()));
-
+
if (test.is_upper_bound_satisfiable()) {
Statement new_stmt;
new_stmt.code = stmt[*i].code->clone();
@@ -809,20 +811,20 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
new_stmt.xform = copy(stmt[*i].xform);
new_stmt.ir_stmt_node = NULL;
new_stmt.loop_level = stmt[*i].loop_level;
-
+
new_stmt.has_inspector = stmt[*i].has_inspector;
new_stmt.reduction = stmt[*i].reduction;
new_stmt.reductionOp = stmt[*i].reductionOp;
-
+
stmt_nesting_level_.push_back(stmt_nesting_level_[*i]);
-
-
+
+
if (place_after)
assign_const(new_stmt.xform, dim - 1, cur_lex + 1);
else
assign_const(new_stmt.xform, dim - 1, cur_lex - 1);
-
- fprintf(stderr, "loop_basic.cc L828 adding stmt %d\n", stmt.size());
+
+ fprintf(stderr, "loop_basic.cc L828 adding stmt %d\n", stmt.size());
stmt.push_back(new_stmt);
uninterpreted_symbols.push_back(uninterpreted_symbols[stmt_num]);
@@ -832,7 +834,7 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
if (*i == stmt_num)
result.insert(stmt.size() - 1);
}
-
+
}
// make adjacent lexical number available for new statements
if (place_after) {
@@ -846,20 +848,20 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
int dep_dim = get_dep_dim_of(stmt_num, level);
for (int i = 0; i < old_num_stmt; i++) {
std::vector<std::pair<int, std::vector<DependenceVector> > > D;
-
+
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[i].second.begin();
+ dep.vertex[i].second.begin();
j != dep.vertex[i].second.end(); j++) {
if (same_loop.find(i) != same_loop.end()) {
if (same_loop.find(j->first) != same_loop.end()) {
if (what_stmt_num.find(i) != what_stmt_num.end()
&& what_stmt_num.find(j->first)
- != what_stmt_num.end())
+ != what_stmt_num.end())
dep.connect(what_stmt_num[i],
what_stmt_num[j->first], j->second);
if (place_after
&& what_stmt_num.find(j->first)
- != what_stmt_num.end()) {
+ != what_stmt_num.end()) {
std::vector<DependenceVector> dvs;
for (int k = 0; k < j->second.size(); k++) {
DependenceVector dv = j->second[k];
@@ -871,11 +873,11 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
}
if (dvs.size() > 0)
D.push_back(
- std::make_pair(what_stmt_num[j->first],
- dvs));
+ std::make_pair(what_stmt_num[j->first],
+ dvs));
} else if (!place_after
&& what_stmt_num.find(i)
- != what_stmt_num.end()) {
+ != what_stmt_num.end()) {
std::vector<DependenceVector> dvs;
for (int k = 0; k < j->second.size(); k++) {
DependenceVector dv = j->second[k];
@@ -887,7 +889,7 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
}
if (dvs.size() > 0)
dep.connect(what_stmt_num[i], j->first, dvs);
-
+
}
} else {
if (what_stmt_num.find(i) != what_stmt_num.end())
@@ -896,17 +898,17 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) {
} else if (same_loop.find(j->first) != same_loop.end()) {
if (what_stmt_num.find(j->first) != what_stmt_num.end())
D.push_back(
- std::make_pair(what_stmt_num[j->first],
- j->second));
+ std::make_pair(what_stmt_num[j->first],
+ j->second));
}
}
-
+
for (int j = 0; j < D.size(); j++)
dep.connect(i, D[j].first, D[j].second);
}
-
+
}
-
+
return result;
}
@@ -914,28 +916,28 @@ void Loop::skew(const std::set<int> &stmt_nums, int level,
const std::vector<int> &skew_amount) {
if (stmt_nums.size() == 0)
return;
-
+
// check for sanity of parameters
int ref_stmt_num = *(stmt_nums.begin());
for (std::set<int>::const_iterator i = stmt_nums.begin();
i != stmt_nums.end(); i++) {
if (*i < 0 || *i >= stmt.size())
throw std::invalid_argument(
- "invalid statement number " + to_string(*i));
+ "invalid statement number " + to_string(*i));
if (level < 1 || level > stmt[*i].loop_level.size())
throw std::invalid_argument(
- "5invalid loop level " + to_string(level));
+ "5invalid loop level " + to_string(level));
for (int j = stmt[*i].loop_level.size(); j < skew_amount.size(); j++)
if (skew_amount[j] != 0)
throw std::invalid_argument("invalid skewing formula");
}
-
+
// invalidate saved codegen computation
delete last_compute_cgr_;
last_compute_cgr_ = NULL;
delete last_compute_cg_;
last_compute_cg_ = NULL;
-
+
// set trasformation relations
for (std::set<int>::const_iterator i = stmt_nums.begin();
i != stmt_nums.end(); i++) {
@@ -953,18 +955,18 @@ void Loop::skew(const std::set<int> &stmt_nums, int level,
for (int j = 0; j < skew_amount.size(); j++)
if (skew_amount[j] != 0)
h.update_coef(r.input_var(2 * (j + 1)), skew_amount[j]);
-
+
stmt[*i].xform = Composition(r, stmt[*i].xform);
stmt[*i].xform.simplify();
}
-
+
// update dependence graph
if (stmt[ref_stmt_num].loop_level[level - 1].type == LoopLevelOriginal) {
int dep_dim = stmt[ref_stmt_num].loop_level[level - 1].payload;
for (std::set<int>::const_iterator i = stmt_nums.begin();
i != stmt_nums.end(); i++)
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[*i].second.begin();
+ dep.vertex[*i].second.begin();
j != dep.vertex[*i].second.end(); j++)
if (stmt_nums.find(j->first) != stmt_nums.end()) {
// dependence between skewed statements
@@ -984,7 +986,7 @@ void Loop::skew(const std::set<int> &stmt_nums, int level,
else {
if (cur_dep_dim != -1
&& !(dv.lbounds[cur_dep_dim] == 0
- && dv.ubounds[cur_dep_dim]== 0))
+ && dv.ubounds[cur_dep_dim] == 0))
lb = -posInfinity;
}
if (ub != posInfinity
@@ -1022,24 +1024,24 @@ void Loop::skew(const std::set<int> &stmt_nums, int level,
}
dv.lbounds[dep_dim] = lb;
dv.ubounds[dep_dim] = ub;
- if ((dv.isCarried(dep_dim) && dv.hasPositive(dep_dim))
+ if ((dv.isCarried(dep_dim) && dv.hasPositive(dep_dim))
&& dv.quasi)
dv.quasi = false;
-
- if ((dv.isCarried(dep_dim) && dv.hasNegative(dep_dim))
+
+ if ((dv.isCarried(dep_dim) && dv.hasNegative(dep_dim))
&& !dv.quasi)
throw loop_error(
- "loop error: Skewing is illegal, dependence violation!");
+ "loop error: Skewing is illegal, dependence violation!");
dv.lbounds[dep_dim] = lb;
dv.ubounds[dep_dim] = ub;
if ((dv.isCarried(dep_dim)
&& dv.hasPositive(dep_dim)) && dv.quasi)
dv.quasi = false;
-
+
if ((dv.isCarried(dep_dim)
&& dv.hasNegative(dep_dim)) && !dv.quasi)
throw loop_error(
- "loop error: Skewing is illegal, dependence violation!");
+ "loop error: Skewing is illegal, dependence violation!");
}
}
j->second = dvs;
@@ -1059,7 +1061,7 @@ void Loop::skew(const std::set<int> &stmt_nums, int level,
for (int i = 0; i < dep.vertex.size(); i++)
if (stmt_nums.find(i) == stmt_nums.end())
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[i].second.begin();
+ dep.vertex[i].second.begin();
j != dep.vertex[i].second.end(); j++)
if (stmt_nums.find(j->first) != stmt_nums.end()) {
// dependence from unskewed statement to skewed statement becomes jumbled,
@@ -1081,34 +1083,34 @@ void Loop::skew(const std::set<int> &stmt_nums, int level,
void Loop::shift(const std::set<int> &stmt_nums, int level, int shift_amount) {
if (stmt_nums.size() == 0)
return;
-
+
// check for sanity of parameters
int ref_stmt_num = *(stmt_nums.begin());
for (std::set<int>::const_iterator i = stmt_nums.begin();
i != stmt_nums.end(); i++) {
if (*i < 0 || *i >= stmt.size())
throw std::invalid_argument(
- "invalid statement number " + to_string(*i));
+ "invalid statement number " + to_string(*i));
if (level < 1 || level > stmt[*i].loop_level.size())
throw std::invalid_argument(
- "6invalid loop level " + to_string(level));
+ "6invalid loop level " + to_string(level));
}
-
+
// do nothing
if (shift_amount == 0)
return;
-
+
// invalidate saved codegen computation
delete last_compute_cgr_;
last_compute_cgr_ = NULL;
delete last_compute_cg_;
last_compute_cg_ = NULL;
-
+
// set trasformation relations
for (std::set<int>::const_iterator i = stmt_nums.begin();
i != stmt_nums.end(); i++) {
int n = stmt[*i].xform.n_out();
-
+
Relation r(n, n);
F_And *f_root = r.add_and();
for (int j = 1; j <= n; j++) {
@@ -1118,18 +1120,18 @@ void Loop::shift(const std::set<int> &stmt_nums, int level, int shift_amount) {
if (j == 2 * level)
h.update_const(shift_amount);
}
-
+
stmt[*i].xform = Composition(r, stmt[*i].xform);
stmt[*i].xform.simplify();
}
-
+
// update dependence graph
if (stmt[ref_stmt_num].loop_level[level - 1].type == LoopLevelOriginal) {
int dep_dim = stmt[ref_stmt_num].loop_level[level - 1].payload;
for (std::set<int>::const_iterator i = stmt_nums.begin();
i != stmt_nums.end(); i++)
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[*i].second.begin();
+ dep.vertex[*i].second.begin();
j != dep.vertex[*i].second.end(); j++)
if (stmt_nums.find(j->first) == stmt_nums.end()) {
// dependence from shifted statement to unshifted statement
@@ -1148,7 +1150,7 @@ void Loop::shift(const std::set<int> &stmt_nums, int level, int shift_amount) {
for (int i = 0; i < dep.vertex.size(); i++)
if (stmt_nums.find(i) == stmt_nums.end())
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[i].second.begin();
+ dep.vertex[i].second.begin();
j != dep.vertex[i].second.end(); j++)
if (stmt_nums.find(j->first) != stmt_nums.end()) {
// dependence from unshifted statement to shifted statement
@@ -1180,35 +1182,36 @@ void Loop::reverse(const std::set<int> &stmt_nums, int level) {
void Loop::fuse(const std::set<int> &stmt_nums, int level) {
if (stmt_nums.size() == 0 || stmt_nums.size() == 1)
return;
-
+
// invalidate saved codegen computation
delete last_compute_cgr_;
last_compute_cgr_ = NULL;
delete last_compute_cg_;
last_compute_cg_ = NULL;
-
+
int dim = 2 * level - 1;
// check for sanity of parameters
std::vector<int> ref_lex;
int ref_stmt_num;
- apply_xform();
+ apply_xform();
for (std::set<int>::const_iterator i = stmt_nums.begin();
i != stmt_nums.end(); i++) {
if (*i < 0 || *i >= stmt.size()) {
- fprintf(stderr, "statement number %d should be in [0, %d)\n", *i, stmt.size());
+ fprintf(stderr, "statement number %d should be in [0, %d)\n", *i, stmt.size());
throw std::invalid_argument(
- "FUSE invalid statement number " + to_string(*i));
+ "FUSE invalid statement number " + to_string(*i));
}
if (level <= 0
- // || (level > (stmt[*i].xform.n_out() - 1) / 2
- // || level > stmt[*i].loop_level.size())
- ) {
+ // || (level > (stmt[*i].xform.n_out() - 1) / 2
+ // || level > stmt[*i].loop_level.size())
+ ) {
fprintf(stderr, "FUSE level %d ", level);
fprintf(stderr, "must be greater than zero and \n");
- fprintf(stderr, "must NOT be greater than (%d - 1)/2 == %d and\n", stmt[*i].xform.n_out(), (stmt[*i].xform.n_out() - 1) / 2);
+ fprintf(stderr, "must NOT be greater than (%d - 1)/2 == %d and\n", stmt[*i].xform.n_out(),
+ (stmt[*i].xform.n_out() - 1) / 2);
fprintf(stderr, "must NOT be greater than %d\n", stmt[*i].loop_level.size());
throw std::invalid_argument(
- "FUSE invalid loop level " + to_string(level));
+ "FUSE invalid loop level " + to_string(level));
}
if (ref_lex.size() == 0) {
ref_lex = getLexicalOrder(*i);
@@ -1218,11 +1221,11 @@ void Loop::fuse(const std::set<int> &stmt_nums, int level) {
for (int j = 0; j < dim - 1; j += 2)
if (lex[j] != ref_lex[j])
throw std::invalid_argument(
- "statements for fusion must be in the same level-"
- + to_string(level - 1) + " subloop");
+ "statements for fusion must be in the same level-"
+ + to_string(level - 1) + " subloop");
}
}
-
+
// collect lexicographical order values from to-be-fused statements
std::set<int> lex_values;
for (std::set<int>::const_iterator i = stmt_nums.begin();
@@ -1233,9 +1236,9 @@ void Loop::fuse(const std::set<int> &stmt_nums, int level) {
if (lex_values.size() == 1)
return;
// negative dependence would prevent fusion
-
+
int dep_dim = get_dep_dim_of(ref_stmt_num, level);
-
+
for (std::set<int>::iterator i = lex_values.begin(); i != lex_values.end();
i++) {
ref_lex[dim - 1] = *i;
@@ -1254,25 +1257,25 @@ void Loop::fuse(const std::set<int> &stmt_nums, int level) {
if (dvs[k].isCarried(dep_dim)
&& dvs[k].hasNegative(dep_dim))
throw loop_error(
- "loop error: statements " + to_string(*ii)
- + " and " + to_string(*jj)
- + " cannot be fused together due to negative dependence");
+ "loop error: statements " + to_string(*ii)
+ + " and " + to_string(*jj)
+ + " cannot be fused together due to negative dependence");
dvs = dep.getEdge(*jj, *ii);
for (int k = 0; k < dvs.size(); k++)
if (dvs[k].isCarried(dep_dim)
&& dvs[k].hasNegative(dep_dim))
throw loop_error(
- "loop error: statements " + to_string(*jj)
- + " and " + to_string(*ii)
- + " cannot be fused together due to negative dependence");
+ "loop error: statements " + to_string(*jj)
+ + " and " + to_string(*ii)
+ + " cannot be fused together due to negative dependence");
}
}
}
-
+
std::set<int> same_loop = getStatements(ref_lex, dim - 3);
-
+
std::vector<std::set<int> > s = sort_by_same_loops(same_loop, level);
-
+
std::vector<bool> s2;
for (int i = 0; i < s.size(); i++) {
@@ -1283,27 +1286,27 @@ void Loop::fuse(const std::set<int> &stmt_nums, int level) {
kk++)
for (int i = 0; i < s.size(); i++)
if (s[i].find(*kk) != s[i].end()) {
-
+
s2[i] = true;
}
-
+
try {
-
+
//Dependence Check for Ordering Constraint
//Graph<std::set<int>, bool> dummy = construct_induced_graph_at_level(s5,
// dep, dep_dim);
-
+
Graph<std::set<int>, bool> g = construct_induced_graph_at_level(s, dep,
dep_dim);
std::cout << g;
s = typed_fusion(g, s2);
} catch (const loop_error &e) {
-
+
throw loop_error(
- "statements cannot be fused together due to negative dependence");
-
+ "statements cannot be fused together due to negative dependence");
+
}
-
+
int order = 0;
for (int i = 0; i < s.size(); i++) {
for (std::set<int>::iterator it = s[i].begin(); it != s[i].end(); it++) {
@@ -1314,7 +1317,7 @@ void Loop::fuse(const std::set<int> &stmt_nums, int level) {
//plan for selective typed fusion
-
+
/*
1. sort the lex values of the statements
2. construct induced graph on sorted statements
@@ -1419,7 +1422,6 @@ void Loop::fuse(const std::set<int> &stmt_nums, int level) {
}
-
void Loop::distribute(const std::set<int> &stmt_nums, int level) {
if (stmt_nums.size() == 0 || stmt_nums.size() == 1)
return;
@@ -1439,13 +1441,13 @@ void Loop::distribute(const std::set<int> &stmt_nums, int level) {
i != stmt_nums.end(); i++) {
if (*i < 0 || *i >= stmt.size())
throw std::invalid_argument(
- "invalid statement number " + to_string(*i));
-
+ "invalid statement number " + to_string(*i));
+
if (level < 1
|| (level > (stmt[*i].xform.n_out() - 1) / 2
|| level > stmt[*i].loop_level.size()))
throw std::invalid_argument(
- "8invalid loop level " + to_string(level));
+ "8invalid loop level " + to_string(level));
if (ref_lex.size() == 0) {
ref_lex = getLexicalOrder(*i);
ref_stmt_num = *i;
@@ -1454,8 +1456,8 @@ void Loop::distribute(const std::set<int> &stmt_nums, int level) {
for (int j = 0; j <= dim - 1; j += 2)
if (lex[j] != ref_lex[j])
throw std::invalid_argument(
- "statements for distribution must be in the same level-"
- + to_string(level) + " subloop");
+ "statements for distribution must be in the same level-"
+ + to_string(level) + " subloop");
}
}
@@ -1517,7 +1519,7 @@ void Loop::distribute(const std::set<int> &stmt_nums, int level) {
// nothing to distribute
if (s2.size() == 1)
throw loop_error(
- "loop error: no statement can be distributed due to dependence cycle");
+ "loop error: no statement can be distributed due to dependence cycle");
std::vector<std::set<int> > s3;
for (int i = 0; i < s2.size(); i++) {
std::set<int> t;
@@ -1564,16 +1566,14 @@ void Loop::distribute(const std::set<int> &stmt_nums, int level) {
order++;
}
// no need to update dependence graph
-
+
return;
}
-
-
std::vector<IR_ArrayRef *> FindOuterArrayRefs(IR_Code *ir,
std::vector<IR_ArrayRef *> &arr_refs) {
- std::vector<IR_ArrayRef *> to_return;
+ std::vector<IR_ArrayRef *> to_return;
for (int i = 0; i < arr_refs.size(); i++)
if (!ir->parent_is_array(arr_refs[i])) {
int j;
@@ -1587,38 +1587,36 @@ std::vector<IR_ArrayRef *> FindOuterArrayRefs(IR_Code *ir,
}
-
-
-
std::vector<std::vector<std::string> > constructInspectorVariables(IR_Code *ir,
- std::set<IR_ArrayRef *> &arr, std::vector<std::string> &index) {
-
- fprintf(stderr, "constructInspectorVariables()\n");
+ std::set<IR_ArrayRef *> &arr,
+ std::vector<std::string> &index) {
+
+ fprintf(stderr, "constructInspectorVariables()\n");
std::vector<std::vector<std::string> > to_return;
-
+
for (std::set<IR_ArrayRef *>::iterator i = arr.begin(); i != arr.end();
i++) {
-
+
std::vector<std::string> per_index;
-
+
CG_outputRepr *subscript = (*i)->index(0);
-
+
if ((*i)->n_dim() > 1)
throw ir_error(
- "multi-dimensional array support non-existent for flattening currently");
-
+ "multi-dimensional array support non-existent for flattening currently");
+
while (ir->QueryExpOperation(subscript) == IR_OP_ARRAY_VARIABLE) {
-
+
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(subscript);
-
+
IR_ArrayRef *ref = static_cast<IR_ArrayRef *>(ir->Repr2Ref(v[0]));
//per_index.push_back(ref->name());
-
+
subscript = ref->index(0);
-
+
}
-
+
if (ir->QueryExpOperation(subscript) == IR_OP_VARIABLE) {
std::vector<CG_outputRepr *> v = ir->QueryExpOperand(subscript);
IR_ScalarRef *ref = static_cast<IR_ScalarRef *>(ir->Repr2Ref(v[0]));
@@ -1627,25 +1625,25 @@ std::vector<std::vector<std::string> > constructInspectorVariables(IR_Code *ir,
for (j = 0; j < index.size(); j++)
if (index[j] == ref->name())
break;
-
+
if (j == index.size())
throw ir_error("Non index variable in array expression");
-
+
int k;
for (k = 0; k < to_return.size(); k++)
if (to_return[k][0] == ref->name())
break;
- if (k == to_return.size()) {
+ if (k == to_return.size()) {
to_return.push_back(per_index);
- fprintf(stderr, "adding index %s\n", ref->name().c_str());
+ fprintf(stderr, "adding index %s\n", ref->name().c_str());
}
-
+
}
-
+
}
-
+
return to_return;
-
+
}
/*std::vector<CG_outputRepr *> constructInspectorData(IR_Code *ir, std::vector<std::vector<std::string> > &indices){
@@ -1669,99 +1667,99 @@ std::vector<std::vector<std::string> > constructInspectorVariables(IR_Code *ir,
*/
-CG_outputRepr * checkAndGenerateIndirectMappings(CG_outputBuilder * ocg,
- std::vector<std::vector<std::string> > &indices,
- CG_outputRepr * instance, CG_outputRepr * class_def,
- CG_outputRepr * count_var) {
-
+CG_outputRepr *checkAndGenerateIndirectMappings(CG_outputBuilder *ocg,
+ std::vector<std::vector<std::string> > &indices,
+ CG_outputRepr *instance, CG_outputRepr *class_def,
+ CG_outputRepr *count_var) {
+
CG_outputRepr *to_return = NULL;
-
+
for (int i = 0; i < indices.size(); i++)
if (indices[i].size() > 1) {
std::string index = indices[i][indices[i].size() - 1];
CG_outputRepr *rep = ocg->CreateArrayRefExpression(
- ocg->CreateDotExpression(instance,
- ocg->lookup_member_data(class_def, index, instance)),
- count_var);
+ ocg->CreateDotExpression(instance,
+ ocg->lookup_member_data(class_def, index, instance)),
+ count_var);
for (int j = indices[i].size() - 2; j >= 0; j--)
rep = ocg->CreateArrayRefExpression(indices[i][j], rep);
-
+
CG_outputRepr *lhs = ocg->CreateArrayRefExpression(
- ocg->CreateDotExpression(instance,
- ocg->lookup_member_data(class_def, indices[i][0], instance)),
- count_var);
-
+ ocg->CreateDotExpression(instance,
+ ocg->lookup_member_data(class_def, indices[i][0], instance)),
+ count_var);
+
to_return = ocg->StmtListAppend(to_return,
ocg->CreateAssignment(0, lhs, rep));
-
+
}
-
+
return to_return;
-
+
}
CG_outputRepr *generatePointerAssignments(CG_outputBuilder *ocg,
std::string prefix_name,
std::vector<std::vector<std::string> > &indices,
- CG_outputRepr *instance,
+ CG_outputRepr *instance,
CG_outputRepr *class_def) {
-
+
fprintf(stderr, "generatePointerAssignments()\n");
CG_outputRepr *list = NULL;
- fprintf(stderr, "prefix '%s', %d indices\n", prefix_name.c_str(), indices.size());
+ fprintf(stderr, "prefix '%s', %d indices\n", prefix_name.c_str(), indices.size());
for (int i = 0; i < indices.size(); i++) {
-
+
std::string s = prefix_name + "_" + indices[i][0];
- fprintf(stderr, "s %s\n", s.c_str());
-
+ fprintf(stderr, "s %s\n", s.c_str());
+
// create a variable definition for a pointer to int with this name
// that seems to be the only actual result of this routine ...
//chillAST_VarDecl *vd = new chillAST_VarDecl( "int", prefix_name.c_str(), "*", NULL);
//vd->print(); printf("\n"); fflush(stdout);
//vd->dump(); printf("\n"); fflush(stdout);
-
+
CG_outputRepr *ptr_exp = ocg->CreatePointer(s); // but dropped on the floor. unused
//fprintf(stderr, "ptr_exp created\n");
-
+
//CG_outputRepr *rhs = ocg->CreateDotExpression(instance,
// ocg->lookup_member_data(class_def, indices[i][0], instance));
-
+
//CG_outputRepr *ptr_assignment = ocg->CreateAssignment(0, ptr_exp, rhs);
-
+
//list = ocg->StmtListAppend(list, ptr_assignment);
-
+
}
-
+
fprintf(stderr, "generatePointerAssignments() DONE\n\n");
return list;
}
void Loop::normalize(int stmt_num, int loop_level) {
-
+
if (stmt_num < 0 || stmt_num >= stmt.size())
throw std::invalid_argument(
-
- "invalid statement number " + to_string(stmt_num));
-
+
+ "invalid statement number " + to_string(stmt_num));
+
if (loop_level <= 0)
throw std::invalid_argument(
- "12invalid loop level " + to_string(loop_level));
+ "12invalid loop level " + to_string(loop_level));
if (loop_level > stmt[stmt_num].loop_level.size())
throw std::invalid_argument(
- "there is no loop level " + to_string(loop_level)
- + " for statement " + to_string(stmt_num));
-
+ "there is no loop level " + to_string(loop_level)
+ + " for statement " + to_string(stmt_num));
+
apply_xform(stmt_num);
-
+
Relation r = copy(stmt[stmt_num].IS);
-
+
Relation bound = get_loop_bound(r, loop_level, this->known);
if (!bound.has_single_conjunct() || !bound.is_satisfiable()
|| bound.is_tautology())
throw loop_error("unable to extract loop bound for normalize");
-
+
// extract the loop stride
coef_t stride;
std::pair<EQ_Handle, Variable_ID> result = find_simplest_stride(bound,
@@ -1770,31 +1768,31 @@ void Loop::normalize(int stmt_num, int loop_level) {
stride = 1;
else
stride = abs(result.first.get_coef(result.second))
- / gcd(abs(result.first.get_coef(result.second)),
- abs(result.first.get_coef(bound.set_var(loop_level))));
-
+ / gcd(abs(result.first.get_coef(result.second)),
+ abs(result.first.get_coef(bound.set_var(loop_level))));
+
if (stride != 1)
throw loop_error(
- "normalize currently only handles unit stride, non unit stride present in loop bounds");
-
+ "normalize currently only handles unit stride, non unit stride present in loop bounds");
+
GEQ_Handle lb;
-
+
Conjunct *c = bound.query_DNF()->single_conjunct();
for (GEQ_Iterator gi(c->GEQs()); gi; gi++) {
int coef = (*gi).get_coef(bound.set_var(loop_level));
if (coef > 0)
lb = *gi;
}
-
+
//Loop bound already zero
//Nothing to do.
if (lb.is_const(bound.set_var(loop_level)) && lb.get_const() == 0)
return;
-
+
if (lb.is_const_except_for_global(bound.set_var(loop_level))) {
-
+
int n = stmt[stmt_num].xform.n_out();
-
+
Relation r(n, n);
F_And *f_root = r.add_and();
for (int j = 1; j <= n; j++)
@@ -1803,10 +1801,10 @@ void Loop::normalize(int stmt_num, int loop_level) {
h.update_coef(r.input_var(j), 1);
h.update_coef(r.output_var(j), -1);
}
-
+
stmt[stmt_num].xform = Composition(r, stmt[stmt_num].xform);
stmt[stmt_num].xform.simplify();
-
+
for (Constr_Vars_Iter ci(lb); ci; ci++) {
if ((*ci).var->kind() == Global_Var) {
Global_Var_ID g = (*ci).var->get_global_var();
@@ -1816,24 +1814,24 @@ void Loop::normalize(int stmt_num, int loop_level) {
else
v = stmt[stmt_num].xform.get_local(g,
(*ci).var->function_of());
-
+
F_And *f_super_root = stmt[stmt_num].xform.and_with_and();
F_Exists *f_exists = f_super_root->add_exists();
F_And *f_root = f_exists->add_and();
-
+
EQ_Handle h = f_root->add_EQ();
h.update_coef(stmt[stmt_num].xform.output_var(2 * loop_level),
1);
h.update_coef(stmt[stmt_num].xform.input_var(loop_level), -1);
h.update_coef(v, 1);
-
+
stmt[stmt_num].xform.simplify();
}
-
+
}
-
+
} else
throw loop_error("loop bounds too complex for normalize!");
-
+
}
diff --git a/src/transformations/loop_datacopy.cc b/src/transformations/loop_datacopy.cc
index 12d74fd..69fbd5b 100644
--- a/src/transformations/loop_datacopy.cc
+++ b/src/transformations/loop_datacopy.cc
@@ -27,7 +27,8 @@ using namespace omega;
// parameter array_ref_num=[0,2] means to copy data touched by A[i-1] and A[i]
//
bool Loop::datacopy(const std::vector<std::pair<int, std::vector<int> > > &array_ref_nums, int level,
- bool allow_extra_read, int fastest_changing_dimension, int padding_stride, int padding_alignment, int memory_type) {
+ bool allow_extra_read, int fastest_changing_dimension, int padding_stride, int padding_alignment,
+ int memory_type) {
//fprintf(stderr, "Loop::datacopy()\n");
// check for sanity of parameters
@@ -40,18 +41,17 @@ bool Loop::datacopy(const std::vector<std::pair<int, std::vector<int> > > &array
throw std::invalid_argument("invalid loop level " + to_string(level));
if (i == 0) {
std::vector<int> lex = getLexicalOrder(stmt_num);
- same_loop = getStatements(lex, 2*level-2);
- }
- else if (same_loop.find(stmt_num) == same_loop.end())
+ same_loop = getStatements(lex, 2 * level - 2);
+ } else if (same_loop.find(stmt_num) == same_loop.end())
throw std::invalid_argument("array references for data copy must be located in the same subloop");
}
-
+
// convert array reference numbering scheme to actual array references
std::vector<std::pair<int, std::vector<IR_ArrayRef *> > > selected_refs;
for (int i = 0; i < array_ref_nums.size(); i++) {
if (array_ref_nums[i].second.size() == 0)
continue;
-
+
int stmt_num = array_ref_nums[i].first;
selected_refs.push_back(std::make_pair(stmt_num, std::vector<IR_ArrayRef *>()));
std::vector<IR_ArrayRef *> refs = ir->FindArrayRef(stmt[stmt_num].code);
@@ -61,9 +61,10 @@ bool Loop::datacopy(const std::vector<std::pair<int, std::vector<int> > > &array
if (ref_num < 0 || ref_num >= refs.size()) {
for (int k = 0; k < refs.size(); k++)
delete refs[k];
- throw std::invalid_argument("invalid array reference number " + to_string(ref_num) + " in statement " + to_string(stmt_num));
+ throw std::invalid_argument(
+ "invalid array reference number " + to_string(ref_num) + " in statement " + to_string(stmt_num));
}
- selected_refs[selected_refs.size()-1].second.push_back(refs[ref_num]);
+ selected_refs[selected_refs.size() - 1].second.push_back(refs[ref_num]);
selected[ref_num] = true;
}
for (int j = 0; j < refs.size(); j++)
@@ -72,9 +73,10 @@ bool Loop::datacopy(const std::vector<std::pair<int, std::vector<int> > > &array
}
if (selected_refs.size() == 0)
throw std::invalid_argument("found no array references to copy");
-
+
// do the copy
- bool whatever = datacopy_privatized(selected_refs, level, std::vector<int>(), allow_extra_read, fastest_changing_dimension, padding_stride, padding_alignment, memory_type);
+ bool whatever = datacopy_privatized(selected_refs, level, std::vector<int>(), allow_extra_read,
+ fastest_changing_dimension, padding_stride, padding_alignment, memory_type);
return whatever;
}
@@ -84,9 +86,10 @@ bool Loop::datacopy(const std::vector<std::pair<int, std::vector<int> > > &array
// parameter array_name=A means to copy data touched by A[i-1] and A[i]
//
bool Loop::datacopy(int stmt_num, int level, const std::string &array_name,
- bool allow_extra_read, int fastest_changing_dimension, int padding_stride, int padding_alignment, int memory_type) {
+ bool allow_extra_read, int fastest_changing_dimension, int padding_stride, int padding_alignment,
+ int memory_type) {
- fflush(stdout);
+ fflush(stdout);
//fprintf(stderr, "Loop::datacopy2()\n");
//fprintf(stderr, "array name %s stmt num %d\n", array_name.c_str(), stmt_num);
@@ -95,23 +98,23 @@ bool Loop::datacopy(int stmt_num, int level, const std::string &array_name,
throw std::invalid_argument("invalid statement number " + to_string(stmt_num));
if (level <= 0 || level > stmt[stmt_num].loop_level.size())
throw std::invalid_argument("invalid loop level " + to_string(level));
-
+
// collect array references by name
std::vector<int> lex = getLexicalOrder(stmt_num);
- int dim = 2*level - 1;
- std::set<int> same_loop = getStatements(lex, dim-1);
-
+ int dim = 2 * level - 1;
+ std::set<int> same_loop = getStatements(lex, dim - 1);
+
std::vector<std::pair<int, std::vector<IR_ArrayRef *> > > selected_refs;
for (std::set<int>::iterator i = same_loop.begin(); i != same_loop.end(); i++) {
std::vector<IR_ArrayRef *> t;
- std::vector<IR_ArrayRef *> refs = ir->FindArrayRef(stmt[*i].code);
+ std::vector<IR_ArrayRef *> refs = ir->FindArrayRef(stmt[*i].code);
for (int j = 0; j < refs.size(); j++)
if (refs[j]->name() == array_name)
t.push_back(refs[j]);
else
delete refs[j];
if (t.size() != 0)
- selected_refs.push_back(std::make_pair(*i, t));
+ selected_refs.push_back(std::make_pair(*i, t));
}
//fprintf(stderr, "selected refs:\n");
@@ -122,27 +125,30 @@ bool Loop::datacopy(int stmt_num, int level, const std::string &array_name,
if (selected_refs.size() == 0)
throw std::invalid_argument("found no array references with name " + to_string(array_name) + " to copy");
-
+
IR_ArrayRef *AR = selected_refs[0].second[0];
//IR_roseArrayRef *RAR = (IR_roseArrayRef *)AR;
//fprintf(stderr, "before datacopy_privatized, ");
//AR->Dump();
-
+
// do the copy
//fprintf(stderr, "\nLoop::datacopy2 calling privatized\n");
- bool whatever = datacopy_privatized(selected_refs, level, std::vector<int>(), allow_extra_read, fastest_changing_dimension, padding_stride, padding_alignment, memory_type);
+ bool whatever = datacopy_privatized(selected_refs, level, std::vector<int>(), allow_extra_read,
+ fastest_changing_dimension, padding_stride, padding_alignment, memory_type);
//AR = selected_refs[0].second[0];
//fprintf(stderr, "after datacopy_privatized, ");
//AR->Dump();
-
+
return whatever;
}
-bool Loop::datacopy_privatized(int stmt_num, int level, const std::string &array_name, const std::vector<int> &privatized_levels,
- bool allow_extra_read, int fastest_changing_dimension, int padding_stride, int padding_alignment, int memory_type) {
+bool Loop::datacopy_privatized(int stmt_num, int level, const std::string &array_name,
+ const std::vector<int> &privatized_levels,
+ bool allow_extra_read, int fastest_changing_dimension, int padding_stride,
+ int padding_alignment, int memory_type) {
//fprintf(stderr, "Loop::datacopy_privatized()\n");
// check for sanity of parameters
@@ -150,33 +156,37 @@ bool Loop::datacopy_privatized(int stmt_num, int level, const std::string &array
throw std::invalid_argument("invalid statement number " + to_string(stmt_num));
if (level <= 0 || level > stmt[stmt_num].loop_level.size())
throw std::invalid_argument("invalid loop level " + to_string(level));
-
+
// collect array references by name
std::vector<int> lex = getLexicalOrder(stmt_num);
- int dim = 2*level - 1;
- std::set<int> same_loop = getStatements(lex, dim-1);
-
+ int dim = 2 * level - 1;
+ std::set<int> same_loop = getStatements(lex, dim - 1);
+
std::vector<std::pair<int, std::vector<IR_ArrayRef *> > > selected_refs;
for (std::set<int>::iterator i = same_loop.begin(); i != same_loop.end(); i++) {
selected_refs.push_back(std::make_pair(*i, std::vector<IR_ArrayRef *>()));
-
- std::vector<IR_ArrayRef *> refs = ir->FindArrayRef(stmt[*i].code);
+
+ std::vector<IR_ArrayRef *> refs = ir->FindArrayRef(stmt[*i].code);
for (int j = 0; j < refs.size(); j++)
if (refs[j]->name() == array_name)
- selected_refs[selected_refs.size()-1].second.push_back(refs[j]);
+ selected_refs[selected_refs.size() - 1].second.push_back(refs[j]);
else
delete refs[j];
}
if (selected_refs.size() == 0)
throw std::invalid_argument("found no array references with name " + to_string(array_name) + " to copy");
-
+
// do the copy
- bool whatever = datacopy_privatized(selected_refs, level, privatized_levels, allow_extra_read, fastest_changing_dimension, padding_stride, padding_alignment, memory_type);
+ bool whatever = datacopy_privatized(selected_refs, level, privatized_levels, allow_extra_read,
+ fastest_changing_dimension, padding_stride, padding_alignment, memory_type);
return whatever;
}
-bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<int> > > &array_ref_nums, int level, const std::vector<int> &privatized_levels, bool allow_extra_read, int fastest_changing_dimension, int padding_stride, int padding_alignment, int memory_type) {
+bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<int> > > &array_ref_nums, int level,
+ const std::vector<int> &privatized_levels, bool allow_extra_read,
+ int fastest_changing_dimension, int padding_stride, int padding_alignment,
+ int memory_type) {
//fprintf(stderr, "Loop::datacopy_privatized2()\n");
// check for sanity of parameters
@@ -189,18 +199,17 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<int>
throw std::invalid_argument("invalid loop level " + to_string(level));
if (i == 0) {
std::vector<int> lex = getLexicalOrder(stmt_num);
- same_loop = getStatements(lex, 2*level-2);
- }
- else if (same_loop.find(stmt_num) == same_loop.end())
+ same_loop = getStatements(lex, 2 * level - 2);
+ } else if (same_loop.find(stmt_num) == same_loop.end())
throw std::invalid_argument("array references for data copy must be located in the same subloop");
}
-
+
// convert array reference numbering scheme to actual array references
std::vector<std::pair<int, std::vector<IR_ArrayRef *> > > selected_refs;
for (int i = 0; i < array_ref_nums.size(); i++) {
if (array_ref_nums[i].second.size() == 0)
continue;
-
+
int stmt_num = array_ref_nums[i].first;
selected_refs.push_back(std::make_pair(stmt_num, std::vector<IR_ArrayRef *>()));
std::vector<IR_ArrayRef *> refs = ir->FindArrayRef(stmt[stmt_num].code);
@@ -210,9 +219,10 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<int>
if (ref_num < 0 || ref_num >= refs.size()) {
for (int k = 0; k < refs.size(); k++)
delete refs[k];
- throw std::invalid_argument("invalid array reference number " + to_string(ref_num) + " in statement " + to_string(stmt_num));
+ throw std::invalid_argument(
+ "invalid array reference number " + to_string(ref_num) + " in statement " + to_string(stmt_num));
}
- selected_refs[selected_refs.size()-1].second.push_back(refs[ref_num]);
+ selected_refs[selected_refs.size() - 1].second.push_back(refs[ref_num]);
selected[ref_num] = true;
}
for (int j = 0; j < refs.size(); j++)
@@ -221,10 +231,11 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<int>
}
if (selected_refs.size() == 0)
throw std::invalid_argument("found no array references to copy");
-
+
// do the copy
- bool whatever = datacopy_privatized(selected_refs, level, privatized_levels, allow_extra_read, fastest_changing_dimension, padding_stride, padding_alignment, memory_type);
- return whatever;
+ bool whatever = datacopy_privatized(selected_refs, level, privatized_levels, allow_extra_read,
+ fastest_changing_dimension, padding_stride, padding_alignment, memory_type);
+ return whatever;
}
@@ -232,13 +243,13 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<int>
// Implement low level datacopy function with lots of options.
//
-bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_ArrayRef *> > > &stmt_refs,
+bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_ArrayRef *> > > &stmt_refs,
int level,
const std::vector<int> &privatized_levels,
- bool allow_extra_read,
+ bool allow_extra_read,
int fastest_changing_dimension,
- int padding_stride,
- int padding_alignment,
+ int padding_stride,
+ int padding_alignment,
int memory_type) {
//fprintf(stderr, "\nLoop::datacopy_privatized3() *****\n");
@@ -247,7 +258,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
if (stmt_refs.size() == 0)
return true;
-
+
// check for sanity of parameters
IR_ArraySymbol *sym = NULL;
std::vector<int> lex;
@@ -258,8 +269,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
if (i == 0) {
if (privatized_levels[i] < level)
throw std::invalid_argument("privatized loop levels must be no less than level " + to_string(level));
- }
- else if (privatized_levels[i] <= privatized_levels[i-1])
+ } else if (privatized_levels[i] <= privatized_levels[i - 1])
throw std::invalid_argument("privatized loop levels must be in ascending order");
}
for (int i = 0; i < stmt_refs.size(); i++) {
@@ -268,10 +278,11 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
if (stmt_num < 0 || stmt_num >= stmt.size())
throw std::invalid_argument("invalid statement number " + to_string(stmt_num));
if (privatized_levels.size() != 0) {
- if (privatized_levels[privatized_levels.size()-1] > stmt[stmt_num].loop_level.size())
- throw std::invalid_argument("invalid loop level " + to_string(privatized_levels[privatized_levels.size()-1]) + " for statement " + to_string(stmt_num));
- }
- else {
+ if (privatized_levels[privatized_levels.size() - 1] > stmt[stmt_num].loop_level.size())
+ throw std::invalid_argument(
+ "invalid loop level " + to_string(privatized_levels[privatized_levels.size() - 1]) + " for statement " +
+ to_string(stmt_num));
+ } else {
if (level > stmt[stmt_num].loop_level.size())
throw std::invalid_argument("invalid loop level " + to_string(level) + " for statement " + to_string(stmt_num));
}
@@ -279,8 +290,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
if (sym == NULL) {
sym = stmt_refs[i].second[j]->symbol();
lex = getLexicalOrder(stmt_num);
- }
- else {
+ } else {
IR_ArraySymbol *t = stmt_refs[i].second[j]->symbol();
if (t->name() != sym->name()) {
delete t;
@@ -293,8 +303,10 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
}
//fprintf(stderr, "sym %p\n", sym);
- if (!sym) {
- fprintf(stderr, "sym NULL, gonna die\n"); int *i=0; int j=i[0];
+ if (!sym) {
+ fprintf(stderr, "sym NULL, gonna die\n");
+ int *i = 0;
+ int j = i[0];
}
if (!(fastest_changing_dimension >= -1 && fastest_changing_dimension < sym->n_dim()))
@@ -303,31 +315,31 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
throw std::invalid_argument("invalid temporary array stride requirement");
if (padding_alignment == -1 || padding_alignment == 0)
throw std::invalid_argument("invalid temporary array alignment requirement");
-
- int dim = 2*level - 1;
+
+ int dim = 2 * level - 1;
int n_dim = sym->n_dim();
-
+
if (fastest_changing_dimension == -1)
switch (sym->layout_type()) {
- case IR_ARRAY_LAYOUT_ROW_MAJOR:
- fastest_changing_dimension = n_dim - 1;
- break;
- case IR_ARRAY_LAYOUT_COLUMN_MAJOR:
- fastest_changing_dimension = 0;
- break;
- default:
- throw loop_error("unsupported array layout");
+ case IR_ARRAY_LAYOUT_ROW_MAJOR:
+ fastest_changing_dimension = n_dim - 1;
+ break;
+ case IR_ARRAY_LAYOUT_COLUMN_MAJOR:
+ fastest_changing_dimension = 0;
+ break;
+ default:
+ throw loop_error("unsupported array layout");
}
// OK, parameter sanity checked
-
+
// invalidate saved codegen computation
delete last_compute_cgr_;
last_compute_cgr_ = NULL;
delete last_compute_cg_;
last_compute_cg_ = NULL;
-
+
// build iteration spaces for all reads and for all writes separately
//fprintf(stderr, "dp3: before apply_xform() ARRAY REFS\n");
//for (int i = 0; i < stmt_refs.size(); i++) {
@@ -360,29 +372,30 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
// fprintf(stderr, "\n");
//}
-
+
bool has_write_refs = false;
bool has_read_refs = false;
- Relation wo_copy_is = Relation::False(level-1+privatized_levels.size()+n_dim);
- Relation ro_copy_is = Relation::False(level-1+privatized_levels.size()+n_dim);
+ Relation wo_copy_is = Relation::False(level - 1 + privatized_levels.size() + n_dim);
+ Relation ro_copy_is = Relation::False(level - 1 + privatized_levels.size() + n_dim);
//fprintf(stderr, "\n\ni range: 0-%d\n", -1 + stmt_refs.size());
int stmt_num = stmt_refs[0].first;
for (int i = 0; i < stmt_refs.size(); i++) {
int stmt_num = stmt_refs[i].first;
-
+
//fprintf(stderr, "j range: 0-%d\n", -1 + stmt_refs[i].second.size());
for (int j = 0; j < stmt_refs[i].second.size(); j++) {
//fprintf(stderr, "ij %d %d\n", i, j);
- Relation mapping(stmt[stmt_num].IS.n_set(), level-1+privatized_levels.size()+n_dim);
+ Relation mapping(stmt[stmt_num].IS.n_set(), level - 1 + privatized_levels.size() + n_dim);
for (int k = 1; k <= mapping.n_inp(); k++)
mapping.name_input_var(k, stmt[stmt_num].IS.set_var(k)->name());
mapping.setup_names();
- mapping.print(); fflush(stdout); // "{[I] -> [_t1] : I = _t1 }
+ mapping.print();
+ fflush(stdout); // "{[I] -> [_t1] : I = _t1 }
F_And *f_root = mapping.add_and();
- for (int k = 1; k <= level-1; k++) {
+ for (int k = 1; k <= level - 1; k++) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(mapping.input_var(k), 1);
h.update_coef(mapping.output_var(k), -1);
@@ -390,7 +403,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
for (int k = 0; k < privatized_levels.size(); k++) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(mapping.input_var(privatized_levels[k]), 1);
- h.update_coef(mapping.output_var(level+k), -1);
+ h.update_coef(mapping.output_var(level + k), -1);
}
for (int k = 0; k < n_dim; k++) {
IR_ArrayRef *AR = stmt_refs[i].second[j];
@@ -400,37 +413,39 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
CG_outputRepr *repr = stmt_refs[i].second[j]->index(k);
//fprintf(stderr, "k %d j %d repr ", k, j); repr->dump(); fflush(stdout);
- exp2formula(ir,
- mapping,
- f_root,
- freevar,
- repr,
- mapping.output_var(level-1+privatized_levels.size()+k+1),
- 'w',
- IR_COND_EQ,
+ exp2formula(ir,
+ mapping,
+ f_root,
+ freevar,
+ repr,
+ mapping.output_var(level - 1 + privatized_levels.size() + k + 1),
+ 'w',
+ IR_COND_EQ,
false,
uninterpreted_symbols[stmt_num],
uninterpreted_symbols_stringrepr[stmt_num]);
repr->clear();
delete repr;
}
- Relation r = omega::Range(Restrict_Domain(mapping, Intersection(copy(stmt[stmt_num].IS), Extend_Set(copy(this->known), stmt[stmt_num].IS.n_set() - this->known.n_set()))));
+ Relation r = omega::Range(Restrict_Domain(mapping, Intersection(copy(stmt[stmt_num].IS),
+ Extend_Set(copy(this->known),
+ stmt[stmt_num].IS.n_set() -
+ this->known.n_set()))));
if (stmt_refs[i].second[j]->is_write()) {
has_write_refs = true;
wo_copy_is = Union(wo_copy_is, r);
wo_copy_is.simplify(2, 4);
-
-
- }
- else {
+
+
+ } else {
has_read_refs = true;
ro_copy_is = Union(ro_copy_is, r);
ro_copy_is.simplify(2, 4);
-
+
}
}
}
-
+
//fprintf(stderr, "dp3: simplify\n");
// simplify read and write footprint iteration space
{
@@ -438,7 +453,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
ro_copy_is = SimpleHull(ro_copy_is, true, true);
else
ro_copy_is = ConvexRepresentation(ro_copy_is);
-
+
wo_copy_is = ConvexRepresentation(wo_copy_is);
if (wo_copy_is.number_of_conjuncts() > 1) {
Relation t = SimpleHull(wo_copy_is, true, true);
@@ -448,7 +463,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
wo_copy_is = ro_copy_is;
}
}
-
+
// make copy statement variable names match the ones in the original statements which
// already have the same names due to apply_xform
{
@@ -463,11 +478,12 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
}
for (int i = 0; i < privatized_levels.size(); i++) {
std::string s = stmt[ref_stmt].IS.input_var(privatized_levels[i])->name();
- wo_copy_is.name_set_var(level+i, s);
- ro_copy_is.name_set_var(level+i, s);
+ wo_copy_is.name_set_var(level + i, s);
+ ro_copy_is.name_set_var(level + i, s);
}
- for (int i = level+privatized_levels.size(); i < level+privatized_levels.size()+n_dim; i++) {
- std::string s = tmp_loop_var_name_prefix + to_string(tmp_loop_var_name_counter+i-level-privatized_levels.size());
+ for (int i = level + privatized_levels.size(); i < level + privatized_levels.size() + n_dim; i++) {
+ std::string s =
+ tmp_loop_var_name_prefix + to_string(tmp_loop_var_name_counter + i - level - privatized_levels.size());
wo_copy_is.name_set_var(i, s);
ro_copy_is.name_set_var(i, s);
}
@@ -475,11 +491,11 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
wo_copy_is.setup_names();
ro_copy_is.setup_names();
}
-
+
//fprintf(stderr, "\ndp3: build merged\n");
// build merged footprint iteration space for calculating temporary array size
Relation copy_is = SimpleHull(Union(copy(ro_copy_is), copy(wo_copy_is)), true, true);
-
+
// extract temporary array information
CG_outputBuilder *ocg = ir->builder();
std::vector<CG_outputRepr *> index_lb(n_dim); // initialized to NULL
@@ -487,31 +503,35 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
std::vector<bool> is_index_eq(n_dim, false);
std::vector<std::pair<int, CG_outputRepr *> > index_sz(0);
Relation reduced_copy_is = copy(copy_is);
-
+
for (int i = 0; i < n_dim; i++) {
//fprintf(stderr, "i %d/%d\n", i, n_dim);
if (i != 0)
- reduced_copy_is = Project(reduced_copy_is, level-1+privatized_levels.size()+i, Set_Var);
- Relation bound = get_loop_bound(reduced_copy_is, level-1+privatized_levels.size()+i);
-
+ reduced_copy_is = Project(reduced_copy_is, level - 1 + privatized_levels.size() + i, Set_Var);
+ Relation bound = get_loop_bound(reduced_copy_is, level - 1 + privatized_levels.size() + i);
+
//fprintf(stderr, "dp3: extract stride\n");
// extract stride
- std::pair<EQ_Handle, Variable_ID> result = find_simplest_stride(bound, bound.set_var(level-1+privatized_levels.size()+i+1));
+ std::pair<EQ_Handle, Variable_ID> result = find_simplest_stride(bound, bound.set_var(
+ level - 1 + privatized_levels.size() + i + 1));
if (result.second != NULL)
- index_stride[i] = abs(result.first.get_coef(result.second))/gcd(abs(result.first.get_coef(result.second)), abs(result.first.get_coef(bound.set_var(level-1+privatized_levels.size()+i+1))));
+ index_stride[i] = abs(result.first.get_coef(result.second)) / gcd(abs(result.first.get_coef(result.second)),
+ abs(result.first.get_coef(bound.set_var(
+ level - 1 + privatized_levels.size() + i +
+ 1))));
else
index_stride[i] = 1;
//fprintf(stderr, "dp3: index_stride[%d] = %d\n", i, index_stride[i]);
-
+
// check if this array index requires loop
Conjunct *c = bound.query_DNF()->single_conjunct();
for (EQ_Iterator ei(c->EQs()); ei; ei++) {
//fprintf(stderr, "dp3: for\n");
if ((*ei).has_wildcards())
continue;
-
+
//fprintf(stderr, "dp3: no wildcards\n");
- int coef = (*ei).get_coef(bound.set_var(level-1+privatized_levels.size()+i+1));
+ int coef = (*ei).get_coef(bound.set_var(level - 1 + privatized_levels.size() + i + 1));
if (coef != 0) {
//fprintf(stderr, "coef != 0\n");
int sign = 1;
@@ -520,51 +540,53 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
coef = -coef;
sign = -1;
}
-
+
CG_outputRepr *op = NULL;
for (Constr_Vars_Iter ci(*ei); ci; ci++) {
//fprintf(stderr, "dp3: ci\n");
switch ((*ci).var->kind()) {
- case Input_Var:
- {
- //fprintf(stderr, "dp3: Input_Var\n");
- if ((*ci).var != bound.set_var(level-1+privatized_levels.size()+i+1)) {
- //fprintf(stderr, "dp3: IF sign %d\n",(*ci).coef*sign);
-
- if ((*ci).coef*sign == 1)
- op = ocg->CreateMinus(op, ocg->CreateIdent((*ci).var->name()));
- else if ((*ci).coef*sign == -1)
- op = ocg->CreatePlus(op, ocg->CreateIdent((*ci).var->name()));
- else if ((*ci).coef*sign > 1)
- op = ocg->CreateMinus(op, ocg->CreateTimes(ocg->CreateInt(abs((*ci).coef)), ocg->CreateIdent((*ci).var->name())));
+ case Input_Var: {
+ //fprintf(stderr, "dp3: Input_Var\n");
+ if ((*ci).var != bound.set_var(level - 1 + privatized_levels.size() + i + 1)) {
+ //fprintf(stderr, "dp3: IF sign %d\n",(*ci).coef*sign);
+
+ if ((*ci).coef * sign == 1)
+ op = ocg->CreateMinus(op, ocg->CreateIdent((*ci).var->name()));
+ else if ((*ci).coef * sign == -1)
+ op = ocg->CreatePlus(op, ocg->CreateIdent((*ci).var->name()));
+ else if ((*ci).coef * sign > 1)
+ op = ocg->CreateMinus(op, ocg->CreateTimes(ocg->CreateInt(abs((*ci).coef)),
+ ocg->CreateIdent((*ci).var->name())));
+ else // (*ci).coef*sign < -1
+ op = ocg->CreatePlus(op, ocg->CreateTimes(ocg->CreateInt(abs((*ci).coef)),
+ ocg->CreateIdent((*ci).var->name())));
+ }
+ break;
+ }
+ case Global_Var: {
+ //fprintf(stderr, "dp3: Global_Var\n");
+ Global_Var_ID g = (*ci).var->get_global_var();
+ if ((*ci).coef * sign == 1)
+ op = ocg->CreateMinus(op, ocg->CreateIdent(g->base_name()));
+ else if ((*ci).coef * sign == -1)
+ op = ocg->CreatePlus(op, ocg->CreateIdent(g->base_name()));
+ else if ((*ci).coef * sign > 1)
+ op = ocg->CreateMinus(op, ocg->CreateTimes(ocg->CreateInt(abs((*ci).coef)),
+ ocg->CreateIdent(g->base_name())));
else // (*ci).coef*sign < -1
- op = ocg->CreatePlus(op, ocg->CreateTimes(ocg->CreateInt(abs((*ci).coef)), ocg->CreateIdent((*ci).var->name())));
+ op = ocg->CreatePlus(op, ocg->CreateTimes(ocg->CreateInt(abs((*ci).coef)),
+ ocg->CreateIdent(g->base_name())));
+ break;
}
- break;
- }
- case Global_Var:
- {
- //fprintf(stderr, "dp3: Global_Var\n");
- Global_Var_ID g = (*ci).var->get_global_var();
- if ((*ci).coef*sign == 1)
- op = ocg->CreateMinus(op, ocg->CreateIdent(g->base_name()));
- else if ((*ci).coef*sign == -1)
- op = ocg->CreatePlus(op, ocg->CreateIdent(g->base_name()));
- else if ((*ci).coef*sign > 1)
- op = ocg->CreateMinus(op, ocg->CreateTimes(ocg->CreateInt(abs((*ci).coef)), ocg->CreateIdent(g->base_name())));
- else // (*ci).coef*sign < -1
- op = ocg->CreatePlus(op, ocg->CreateTimes(ocg->CreateInt(abs((*ci).coef)), ocg->CreateIdent(g->base_name())));
- break;
- }
- default:
- throw loop_error("unsupported array index expression");
+ default:
+ throw loop_error("unsupported array index expression");
}
}
if ((*ei).get_const() != 0)
- op = ocg->CreatePlus(op, ocg->CreateInt(-sign*((*ei).get_const())));
+ op = ocg->CreatePlus(op, ocg->CreateInt(-sign * ((*ei).get_const())));
if (coef != 1)
op = ocg->CreateIntegerFloor(op, ocg->CreateInt(coef));
-
+
index_lb[i] = op;
is_index_eq[i] = true;
break;
@@ -572,14 +594,14 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
}
if (is_index_eq[i])
continue;
-
+
//fprintf(stderr, "dp3: separate lower and upper bounds\n");
// separate lower and upper bounds
std::vector<GEQ_Handle> lb_list, ub_list;
std::set<Variable_ID> excluded_floor_vars;
- excluded_floor_vars.insert(bound.set_var(level-1+privatized_levels.size()+i+1));
+ excluded_floor_vars.insert(bound.set_var(level - 1 + privatized_levels.size() + i + 1));
for (GEQ_Iterator gi(c->GEQs()); gi; gi++) {
- int coef = (*gi).get_coef(bound.set_var(level-1+privatized_levels.size()+i+1));
+ int coef = (*gi).get_coef(bound.set_var(level - 1 + privatized_levels.size() + i + 1));
if (coef != 0 && (*gi).has_wildcards()) {
bool clean_bound = true;
GEQ_Handle h;
@@ -591,7 +613,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
if (!clean_bound)
continue;
}
-
+
if (coef > 0)
lb_list.push_back(*gi);
else if (coef < 0)
@@ -599,41 +621,45 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
}
if (lb_list.size() == 0 || ub_list.size() == 0)
throw loop_error("failed to calcuate array footprint size");
-
+
//fprintf(stderr, "dp3: build lower bound representation\n");
// build lower bound representation
std::vector<CG_outputRepr *> lb_repr_list;
- for (int j = 0; j < lb_list.size(); j++){
- if(this->known.n_set() == 0) {
- lb_repr_list.push_back(output_lower_bound_repr(ocg,
- lb_list[j],
- bound.set_var(level-1+privatized_levels.size()+i+1),
- result.first,
- result.second,
- bound,
- Relation::True(bound.n_set()),
- std::vector<std::pair<CG_outputRepr *, int> >(bound.n_set(), std::make_pair(static_cast<CG_outputRepr *>(NULL), 0)),
+ for (int j = 0; j < lb_list.size(); j++) {
+ if (this->known.n_set() == 0) {
+ lb_repr_list.push_back(output_lower_bound_repr(ocg,
+ lb_list[j],
+ bound.set_var(level - 1 + privatized_levels.size() + i + 1),
+ result.first,
+ result.second,
+ bound,
+ Relation::True(bound.n_set()),
+ std::vector<std::pair<CG_outputRepr *, int> >(bound.n_set(),
+ std::make_pair(
+ static_cast<CG_outputRepr *>(NULL),
+ 0)),
uninterpreted_symbols[stmt_num]));
- }
- else {
- lb_repr_list.push_back(output_lower_bound_repr(ocg,
- lb_list[j],
- bound.set_var(level-1+privatized_levels.size()+i+1),
- result.first,
- result.second,
- bound,
- this->known,
- std::vector<std::pair<CG_outputRepr *, int> >(bound.n_set(), std::make_pair(static_cast<CG_outputRepr *>(NULL), 0)),
+ } else {
+ lb_repr_list.push_back(output_lower_bound_repr(ocg,
+ lb_list[j],
+ bound.set_var(level - 1 + privatized_levels.size() + i + 1),
+ result.first,
+ result.second,
+ bound,
+ this->known,
+ std::vector<std::pair<CG_outputRepr *, int> >(bound.n_set(),
+ std::make_pair(
+ static_cast<CG_outputRepr *>(NULL),
+ 0)),
uninterpreted_symbols[stmt_num]));
}
}
- if (lb_repr_list.size() > 1) {
+ if (lb_repr_list.size() > 1) {
//fprintf(stderr, "loop_datacopy.cc dp3 createInvoke( max )\n");
index_lb[i] = ocg->CreateInvoke("max", lb_repr_list);
- }
- else if (lb_repr_list.size() == 1)
+ } else if (lb_repr_list.size() == 1)
index_lb[i] = lb_repr_list[0];
-
+
//fprintf(stderr, "dp3: build temporary array size representation\n");
// build temporary array size representation
{
@@ -642,66 +668,62 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
for (int j = 0; j < ub_list.size(); j++)
for (int k = 0; k < lb_list.size(); k++) {
GEQ_Handle h = f_root->add_GEQ();
-
+
for (Constr_Vars_Iter ci(ub_list[j]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var:
- {
- int pos = (*ci).var->get_position();
- h.update_coef(cal.input_var(pos), (*ci).coef);
- break;
- }
- case Global_Var:
- {
- Global_Var_ID g = (*ci).var->get_global_var();
- Variable_ID v;
- if (g->arity() == 0)
- v = cal.get_local(g);
- else
- v = cal.get_local(g, (*ci).var->function_of());
- h.update_coef(v, (*ci).coef);
- break;
- }
- default:
- throw loop_error("cannot calculate temporay array size statically");
+ case Input_Var: {
+ int pos = (*ci).var->get_position();
+ h.update_coef(cal.input_var(pos), (*ci).coef);
+ break;
+ }
+ case Global_Var: {
+ Global_Var_ID g = (*ci).var->get_global_var();
+ Variable_ID v;
+ if (g->arity() == 0)
+ v = cal.get_local(g);
+ else
+ v = cal.get_local(g, (*ci).var->function_of());
+ h.update_coef(v, (*ci).coef);
+ break;
+ }
+ default:
+ throw loop_error("cannot calculate temporay array size statically");
}
}
h.update_const(ub_list[j].get_const());
-
+
for (Constr_Vars_Iter ci(lb_list[k]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var:
- {
- int pos = (*ci).var->get_position();
- h.update_coef(cal.input_var(pos), (*ci).coef);
- break;
- }
- case Global_Var:
- {
- Global_Var_ID g = (*ci).var->get_global_var();
- Variable_ID v;
- if (g->arity() == 0)
- v = cal.get_local(g);
- else
- v = cal.get_local(g, (*ci).var->function_of());
- h.update_coef(v, (*ci).coef);
- break;
- }
- default:
- throw loop_error("cannot calculate temporay array size statically");
+ case Input_Var: {
+ int pos = (*ci).var->get_position();
+ h.update_coef(cal.input_var(pos), (*ci).coef);
+ break;
+ }
+ case Global_Var: {
+ Global_Var_ID g = (*ci).var->get_global_var();
+ Variable_ID v;
+ if (g->arity() == 0)
+ v = cal.get_local(g);
+ else
+ v = cal.get_local(g, (*ci).var->function_of());
+ h.update_coef(v, (*ci).coef);
+ break;
+ }
+ default:
+ throw loop_error("cannot calculate temporay array size statically");
}
}
h.update_const(lb_list[k].get_const());
-
+
h.update_const(1);
h.update_coef(cal.output_var(1), -1);
}
-
+
cal = Restrict_Domain(cal, copy(copy_is));
for (int j = 1; j <= cal.n_inp(); j++)
cal = Project(cal, j, Input_Var);
cal.simplify();
-
+
//fprintf(stderr, "dp3: pad temporary array size\n");
// pad temporary array size
// TODO: for variable array size, create padding formula
@@ -719,9 +741,8 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
if (padding_alignment > 1) { // align to boundary for data packing
int residue = size % padding_alignment;
if (residue)
- size = size+padding_alignment-residue;
- }
- else if (padding_alignment < -1) { // un-alignment for memory bank conflicts
+ size = size + padding_alignment - residue;
+ } else if (padding_alignment < -1) { // un-alignment for memory bank conflicts
while (gcd(size, static_cast<coef_t>(-padding_alignment)) != 1)
size++;
}
@@ -729,7 +750,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
index_sz.push_back(std::make_pair(i, ocg->CreateInt(size)));
is_index_bound_const = true;
}
-
+
if (!is_index_bound_const) {
for (GEQ_Iterator gi(c->GEQs()); gi && !is_index_bound_const; gi++) {
int coef = (*gi).get_coef(cal.output_var(1));
@@ -737,22 +758,23 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
CG_outputRepr *op = NULL;
for (Constr_Vars_Iter ci(*gi); ci; ci++) {
if ((*ci).var != cal.output_var(1)) {
- switch((*ci).var->kind()) {
- case Global_Var:
- {
- Global_Var_ID g = (*ci).var->get_global_var();
- if ((*ci).coef == 1)
- op = ocg->CreatePlus(op, ocg->CreateIdent(g->base_name()));
- else if ((*ci).coef == -1)
- op = ocg->CreateMinus(op, ocg->CreateIdent(g->base_name()));
- else if ((*ci).coef > 1)
- op = ocg->CreatePlus(op, ocg->CreateTimes(ocg->CreateInt((*ci).coef), ocg->CreateIdent(g->base_name())));
- else // (*ci).coef < -1
- op = ocg->CreateMinus(op, ocg->CreateTimes(ocg->CreateInt(-(*ci).coef), ocg->CreateIdent(g->base_name())));
- break;
- }
- default:
- throw loop_error("failed to generate array index bound code");
+ switch ((*ci).var->kind()) {
+ case Global_Var: {
+ Global_Var_ID g = (*ci).var->get_global_var();
+ if ((*ci).coef == 1)
+ op = ocg->CreatePlus(op, ocg->CreateIdent(g->base_name()));
+ else if ((*ci).coef == -1)
+ op = ocg->CreateMinus(op, ocg->CreateIdent(g->base_name()));
+ else if ((*ci).coef > 1)
+ op = ocg->CreatePlus(op, ocg->CreateTimes(ocg->CreateInt((*ci).coef),
+ ocg->CreateIdent(g->base_name())));
+ else // (*ci).coef < -1
+ op = ocg->CreateMinus(op, ocg->CreateTimes(ocg->CreateInt(-(*ci).coef),
+ ocg->CreateIdent(g->base_name())));
+ break;
+ }
+ default:
+ throw loop_error("failed to generate array index bound code");
}
}
}
@@ -766,16 +788,16 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
coef_t g = gcd(index_stride[i], static_cast<coef_t>(padding_stride));
coef_t t1 = index_stride[i] / g;
if (t1 != 1)
- op = ocg->CreateIntegerFloor(ocg->CreatePlus(op, ocg->CreateInt(t1-1)), ocg->CreateInt(t1));
+ op = ocg->CreateIntegerFloor(ocg->CreatePlus(op, ocg->CreateInt(t1 - 1)), ocg->CreateInt(t1));
coef_t t2 = padding_stride / g;
if (t2 != 1)
op = ocg->CreateTimes(op, ocg->CreateInt(t2));
- }
- else if (index_stride[i] != 1) {
- op = ocg->CreateIntegerFloor(ocg->CreatePlus(op, ocg->CreateInt(index_stride[i]-1)), ocg->CreateInt(index_stride[i]));
+ } else if (index_stride[i] != 1) {
+ op = ocg->CreateIntegerFloor(ocg->CreatePlus(op, ocg->CreateInt(index_stride[i] - 1)),
+ ocg->CreateInt(index_stride[i]));
}
}
-
+
index_sz.push_back(std::make_pair(i, op));
break;
}
@@ -783,20 +805,20 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
}
}
}
-
+
//fprintf(stderr, "dp3: change the temporary array index order\n");
// change the temporary array index order
for (int i = 0; i < index_sz.size(); i++) {
if (index_sz[i].first == fastest_changing_dimension)
switch (sym->layout_type()) {
- case IR_ARRAY_LAYOUT_ROW_MAJOR:
- std::swap(index_sz[index_sz.size()-1], index_sz[i]);
- break;
- case IR_ARRAY_LAYOUT_COLUMN_MAJOR:
- std::swap(index_sz[0], index_sz[i]);
- break;
- default:
- throw loop_error("unsupported array layout");
+ case IR_ARRAY_LAYOUT_ROW_MAJOR:
+ std::swap(index_sz[index_sz.size() - 1], index_sz[i]);
+ break;
+ case IR_ARRAY_LAYOUT_COLUMN_MAJOR:
+ std::swap(index_sz[0], index_sz[i]);
+ break;
+ default:
+ throw loop_error("unsupported array layout");
}
}
@@ -806,51 +828,53 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
if (index_sz.size() == 0) {
//fprintf(stderr, "tmp_sym is a scalar\n");
tmp_sym = ir->CreateScalarSymbol(sym, memory_type);
- }
- else {
+ } else {
//fprintf(stderr, "tmp_sym is an array\n");
std::vector<CG_outputRepr *> tmp_array_size(index_sz.size());
- for (int i = 0; i < index_sz.size(); i++) {
+ for (int i = 0; i < index_sz.size(); i++) {
tmp_array_size[i] = index_sz[i].second->clone();
index_sz[i].second->dump(); // THIS PRINTF
}
tmp_sym = ir->CreateArraySymbol(sym, tmp_array_size, memory_type);
}
-
+
//fprintf(stderr, "dp3: create temporary array read initialization code\n");
// create temporary array read initialization code
CG_outputRepr *copy_code_read;
- if (has_read_refs) {
+ if (has_read_refs) {
//fprintf(stderr, "has read refs\n");
if (index_sz.size() == 0) {
- //fprintf(stderr, "if\n");
-
+ //fprintf(stderr, "if\n");
+
//fprintf(stderr, "tmp sym %s\n", tmp_sym->name().c_str());
- IR_ScalarRef *tmp_scalar_ref = ir->CreateScalarRef(static_cast<IR_ScalarSymbol *>(tmp_sym)); // create ref from symbol
+ IR_ScalarRef *tmp_scalar_ref = ir->CreateScalarRef(
+ static_cast<IR_ScalarSymbol *>(tmp_sym)); // create ref from symbol
// tmp_scalar_ref is incomplete
std::vector<CG_outputRepr *> rhs_index(n_dim);
- for (int i = 0; i < index_lb.size(); i++) {
+ for (int i = 0; i < index_lb.size(); i++) {
//fprintf(stderr, "i %d\n", i);
if (is_index_eq[i])
rhs_index[i] = index_lb[i]->clone();
else
- rhs_index[i] = ir->builder()->CreateIdent(copy_is.set_var(level-1+privatized_levels.size()+i+1)->name());
+ rhs_index[i] = ir->builder()->CreateIdent(
+ copy_is.set_var(level - 1 + privatized_levels.size() + i + 1)->name());
}
IR_ArrayRef *copied_array_ref = ir->CreateArrayRef(sym, rhs_index);
-
+
// IR_ScalarRef tmp_scalar_ref has no actual reference yet. It only has the variable definition.
copy_code_read = ir->builder()->CreateAssignment(0, tmp_scalar_ref->convert(), copied_array_ref->convert());
//fprintf(stderr, "if ends\n");
- }
- else {
+ } else {
//fprintf(stderr, "else\n");
std::vector<CG_outputRepr *> lhs_index(index_sz.size());
for (int i = 0; i < index_sz.size(); i++) {
int cur_index_num = index_sz[i].first;
- CG_outputRepr *cur_index_repr = ocg->CreateMinus(ocg->CreateIdent(copy_is.set_var(level-1+privatized_levels.size()+cur_index_num+1)->name()), index_lb[cur_index_num]->clone());
+ CG_outputRepr *cur_index_repr = ocg->CreateMinus(
+ ocg->CreateIdent(copy_is.set_var(level - 1 + privatized_levels.size() + cur_index_num + 1)->name()),
+ index_lb[cur_index_num]->clone());
if (padding_stride != 0) {
- if (i == n_dim-1) {
+ if (i == n_dim - 1) {
coef_t g = gcd(index_stride[cur_index_num], static_cast<coef_t>(padding_stride));
coef_t t1 = index_stride[cur_index_num] / g;
if (t1 != 1)
@@ -858,74 +882,78 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
coef_t t2 = padding_stride / g;
if (t2 != 1)
cur_index_repr = ocg->CreateTimes(cur_index_repr, ocg->CreateInt(t2));
- }
- else if (index_stride[cur_index_num] != 1) {
+ } else if (index_stride[cur_index_num] != 1) {
cur_index_repr = ocg->CreateIntegerFloor(cur_index_repr, ocg->CreateInt(index_stride[cur_index_num]));
}
}
-
+
if (ir->ArrayIndexStartAt() != 0)
cur_index_repr = ocg->CreatePlus(cur_index_repr, ocg->CreateInt(ir->ArrayIndexStartAt()));
lhs_index[i] = cur_index_repr;
}
-
+
//fprintf(stderr, "dp3: making tmp_array_ref\n");
IR_ArrayRef *tmp_array_ref = ir->CreateArrayRef(static_cast<IR_ArraySymbol *>(tmp_sym), lhs_index);
//fprintf(stderr, "dp3: DONE making tmp_array_ref\n");
-
+
std::vector<CG_outputRepr *> rhs_index(n_dim);
for (int i = 0; i < index_lb.size(); i++)
if (is_index_eq[i])
rhs_index[i] = index_lb[i]->clone();
else
- rhs_index[i] = ir->builder()->CreateIdent(copy_is.set_var(level-1+privatized_levels.size()+i+1)->name());
+ rhs_index[i] = ir->builder()->CreateIdent(
+ copy_is.set_var(level - 1 + privatized_levels.size() + i + 1)->name());
IR_ArrayRef *copied_array_ref = ir->CreateArrayRef(sym, rhs_index);
-
+
//fprintf(stderr, "dp3: loop_datacopy.cc copy_code_read = CreateAssignment\n");
//copy_code_read = ir->builder()->CreateAssignment(0, tmp_array_ref->convert(), copied_array_ref->convert());
CG_outputRepr *lhs = tmp_array_ref->convert();
CG_outputRepr *rhs = copied_array_ref->convert();
- copy_code_read = ir->builder()->CreateAssignment(0, lhs, rhs); //tmp_array_ref->convert(), copied_array_ref->convert());
+ copy_code_read = ir->builder()->CreateAssignment(0, lhs,
+ rhs); //tmp_array_ref->convert(), copied_array_ref->convert());
//fprintf(stderr, "dp3: loop_datacopy.cc copy_code_read = CreateAssignment DONE\n\n");
}
} // has read refs
-
+
//fprintf(stderr, "dp3: create temporary array write back code\n");
// create temporary array write back code
CG_outputRepr *copy_code_write;
- if (has_write_refs) {
+ if (has_write_refs) {
//fprintf(stderr, "has_write_refs\n");
if (index_sz.size() == 0) {
//fprintf(stderr, "index_sz.size() == 0\n");
IR_ScalarRef *tmp_scalar_ref = ir->CreateScalarRef(static_cast<IR_ScalarSymbol *>(tmp_sym));
-
+
std::vector<CG_outputRepr *> rhs_index(n_dim);
for (int i = 0; i < index_lb.size(); i++)
if (is_index_eq[i])
rhs_index[i] = index_lb[i]->clone();
else
- rhs_index[i] = ir->builder()->CreateIdent(copy_is.set_var(level-1+privatized_levels.size()+i+1)->name());
+ rhs_index[i] = ir->builder()->CreateIdent(
+ copy_is.set_var(level - 1 + privatized_levels.size() + i + 1)->name());
IR_ArrayRef *copied_array_ref = ir->CreateArrayRef(sym, rhs_index);
-
+
copy_code_write = ir->builder()->CreateAssignment(0, copied_array_ref->convert(), tmp_scalar_ref->convert());
- }
- else {
+ } else {
//fprintf(stderr, "index_sz.size() NOT = 0\n");
-
+
std::vector<CG_outputRepr *> lhs_index(n_dim);
for (int i = 0; i < index_lb.size(); i++)
if (is_index_eq[i])
lhs_index[i] = index_lb[i]->clone();
else
- lhs_index[i] = ir->builder()->CreateIdent(copy_is.set_var(level-1+privatized_levels.size()+i+1)->name());
+ lhs_index[i] = ir->builder()->CreateIdent(
+ copy_is.set_var(level - 1 + privatized_levels.size() + i + 1)->name());
IR_ArrayRef *copied_array_ref = ir->CreateArrayRef(sym, lhs_index);
-
+
std::vector<CG_outputRepr *> rhs_index(index_sz.size());
for (int i = 0; i < index_sz.size(); i++) {
int cur_index_num = index_sz[i].first;
- CG_outputRepr *cur_index_repr = ocg->CreateMinus(ocg->CreateIdent(copy_is.set_var(level-1+privatized_levels.size()+cur_index_num+1)->name()), index_lb[cur_index_num]->clone());
+ CG_outputRepr *cur_index_repr = ocg->CreateMinus(
+ ocg->CreateIdent(copy_is.set_var(level - 1 + privatized_levels.size() + cur_index_num + 1)->name()),
+ index_lb[cur_index_num]->clone());
if (padding_stride != 0) {
- if (i == n_dim-1) {
+ if (i == n_dim - 1) {
coef_t g = gcd(index_stride[cur_index_num], static_cast<coef_t>(padding_stride));
coef_t t1 = index_stride[cur_index_num] / g;
if (t1 != 1)
@@ -933,96 +961,98 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
coef_t t2 = padding_stride / g;
if (t2 != 1)
cur_index_repr = ocg->CreateTimes(cur_index_repr, ocg->CreateInt(t2));
- }
- else if (index_stride[cur_index_num] != 1) {
+ } else if (index_stride[cur_index_num] != 1) {
cur_index_repr = ocg->CreateIntegerFloor(cur_index_repr, ocg->CreateInt(index_stride[cur_index_num]));
}
}
-
+
if (ir->ArrayIndexStartAt() != 0)
cur_index_repr = ocg->CreatePlus(cur_index_repr, ocg->CreateInt(ir->ArrayIndexStartAt()));
rhs_index[i] = cur_index_repr;
}
IR_ArrayRef *tmp_array_ref = ir->CreateArrayRef(static_cast<IR_ArraySymbol *>(tmp_sym), rhs_index);
-
+
copy_code_write = ir->builder()->CreateAssignment(0, copied_array_ref->convert(), tmp_array_ref->convert());
}
} // has write refs
-
+
// now we can remove those loops for array indexes that are
// dependent on others
//fprintf(stderr, "dp3: now we can remove those loops\n");
if (!(index_sz.size() == n_dim && (sym->layout_type() == IR_ARRAY_LAYOUT_ROW_MAJOR || n_dim <= 1))) {
- Relation mapping(level-1+privatized_levels.size()+n_dim, level-1+privatized_levels.size()+index_sz.size());
+ Relation mapping(level - 1 + privatized_levels.size() + n_dim,
+ level - 1 + privatized_levels.size() + index_sz.size());
F_And *f_root = mapping.add_and();
- for (int i = 1; i <= level-1+privatized_levels.size(); i++) {
+ for (int i = 1; i <= level - 1 + privatized_levels.size(); i++) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(mapping.input_var(i), 1);
h.update_coef(mapping.output_var(i), -1);
}
-
+
int cur_index = 0;
std::vector<int> mapped_index(index_sz.size());
for (int i = 0; i < n_dim; i++)
if (!is_index_eq[i]) {
EQ_Handle h = f_root->add_EQ();
- h.update_coef(mapping.input_var(level-1+privatized_levels.size()+i+1), 1);
+ h.update_coef(mapping.input_var(level - 1 + privatized_levels.size() + i + 1), 1);
switch (sym->layout_type()) {
- case IR_ARRAY_LAYOUT_COLUMN_MAJOR: {
- h.update_coef(mapping.output_var(level-1+privatized_levels.size()+index_sz.size()-cur_index), -1);
- mapped_index[index_sz.size()-cur_index-1] = i;
- break;
- }
- case IR_ARRAY_LAYOUT_ROW_MAJOR: {
- h.update_coef(mapping.output_var(level-1+privatized_levels.size()+cur_index+1), -1);
- mapped_index[cur_index] = i;
- break;
- }
- default:
- throw loop_error("unsupported array layout");
+ case IR_ARRAY_LAYOUT_COLUMN_MAJOR: {
+ h.update_coef(mapping.output_var(level - 1 + privatized_levels.size() + index_sz.size() - cur_index), -1);
+ mapped_index[index_sz.size() - cur_index - 1] = i;
+ break;
+ }
+ case IR_ARRAY_LAYOUT_ROW_MAJOR: {
+ h.update_coef(mapping.output_var(level - 1 + privatized_levels.size() + cur_index + 1), -1);
+ mapped_index[cur_index] = i;
+ break;
+ }
+ default:
+ throw loop_error("unsupported array layout");
}
cur_index++;
}
-
+
wo_copy_is = omega::Range(Restrict_Domain(copy(mapping), wo_copy_is));
ro_copy_is = omega::Range(Restrict_Domain(copy(mapping), ro_copy_is));
- for (int i = 1; i <= level-1+privatized_levels.size(); i++) {
+ for (int i = 1; i <= level - 1 + privatized_levels.size(); i++) {
wo_copy_is.name_set_var(i, copy_is.set_var(i)->name());
ro_copy_is.name_set_var(i, copy_is.set_var(i)->name());
}
for (int i = 0; i < index_sz.size(); i++) {
- wo_copy_is.name_set_var(level-1+privatized_levels.size()+i+1, copy_is.set_var(level-1+privatized_levels.size()+mapped_index[i]+1)->name());
- ro_copy_is.name_set_var(level-1+privatized_levels.size()+i+1, copy_is.set_var(level-1+privatized_levels.size()+mapped_index[i]+1)->name());
+ wo_copy_is.name_set_var(level - 1 + privatized_levels.size() + i + 1,
+ copy_is.set_var(level - 1 + privatized_levels.size() + mapped_index[i] + 1)->name());
+ ro_copy_is.name_set_var(level - 1 + privatized_levels.size() + i + 1,
+ copy_is.set_var(level - 1 + privatized_levels.size() + mapped_index[i] + 1)->name());
}
wo_copy_is.setup_names();
ro_copy_is.setup_names();
}
-
+
// insert read copy statement
//fprintf(stderr, "dp3: insert read copy statement\n");
-
+
int old_num_stmt = stmt.size();
int ro_copy_stmt_num = -1;
if (has_read_refs) {
- Relation copy_xform(ro_copy_is.n_set(), 2*ro_copy_is.n_set()+1);
+ Relation copy_xform(ro_copy_is.n_set(), 2 * ro_copy_is.n_set() + 1);
{
F_And *f_root = copy_xform.add_and();
for (int i = 1; i <= ro_copy_is.n_set(); i++) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(copy_xform.input_var(i), 1);
- h.update_coef(copy_xform.output_var(2*i), -1);
+ h.update_coef(copy_xform.output_var(2 * i), -1);
}
- for (int i = 1; i <= dim; i+=2) {
+ for (int i = 1; i <= dim; i += 2) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(copy_xform.output_var(i), -1);
- h.update_const(lex[i-1]);
+ h.update_const(lex[i - 1]);
}
- for (int i = dim+2; i <= copy_xform.n_out(); i+=2) {
+ for (int i = dim + 2; i <= copy_xform.n_out(); i += 2) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(copy_xform.output_var(i), 1);
}
}
-
+
Statement copy_stmt_read;
copy_stmt_read.IS = ro_copy_is;
copy_stmt_read.xform = copy_xform;
@@ -1031,7 +1061,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
copy_stmt_read.loop_level = std::vector<LoopLevel>(ro_copy_is.n_set());
copy_stmt_read.ir_stmt_node = NULL;
copy_stmt_read.has_inspector = false;
- for (int i = 0; i < level-1; i++) {
+ for (int i = 0; i < level - 1; i++) {
copy_stmt_read.loop_level[i].type = stmt[*(active.begin())].loop_level[i].type;
if (stmt[*(active.begin())].loop_level[i].type == LoopLevelTile &&
stmt[*(active.begin())].loop_level[i].payload >= level) {
@@ -1043,32 +1073,33 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
copy_stmt_read.loop_level[i].payload = -1;
else
copy_stmt_read.loop_level[i].payload = level + j;
- }
- else
+ } else
copy_stmt_read.loop_level[i].payload = stmt[*(active.begin())].loop_level[i].payload;
copy_stmt_read.loop_level[i].parallel_level = stmt[*(active.begin())].loop_level[i].parallel_level;
}
for (int i = 0; i < privatized_levels.size(); i++) {
- copy_stmt_read.loop_level[level-1+i].type = stmt[*(active.begin())].loop_level[privatized_levels[i]].type;
- copy_stmt_read.loop_level[level-1+i].payload = stmt[*(active.begin())].loop_level[privatized_levels[i]].payload;
- copy_stmt_read.loop_level[level-1+i].parallel_level = stmt[*(active.begin())].loop_level[privatized_levels[i]].parallel_level;
+ copy_stmt_read.loop_level[level - 1 + i].type = stmt[*(active.begin())].loop_level[privatized_levels[i]].type;
+ copy_stmt_read.loop_level[level - 1 +
+ i].payload = stmt[*(active.begin())].loop_level[privatized_levels[i]].payload;
+ copy_stmt_read.loop_level[level - 1 +
+ i].parallel_level = stmt[*(active.begin())].loop_level[privatized_levels[i]].parallel_level;
}
int left_num_dim = num_dep_dim - (get_last_dep_dim_before(*(active.begin()), level) + 1);
for (int i = 0; i < std::min(left_num_dim, static_cast<int>(index_sz.size())); i++) {
- copy_stmt_read.loop_level[level-1+privatized_levels.size()+i].type = LoopLevelOriginal;
- copy_stmt_read.loop_level[level-1+privatized_levels.size()+i].payload = num_dep_dim-left_num_dim+i;
- copy_stmt_read.loop_level[level-1+privatized_levels.size()+i].parallel_level = 0;
+ copy_stmt_read.loop_level[level - 1 + privatized_levels.size() + i].type = LoopLevelOriginal;
+ copy_stmt_read.loop_level[level - 1 + privatized_levels.size() + i].payload = num_dep_dim - left_num_dim + i;
+ copy_stmt_read.loop_level[level - 1 + privatized_levels.size() + i].parallel_level = 0;
}
for (int i = std::min(left_num_dim, static_cast<int>(index_sz.size())); i < index_sz.size(); i++) {
- copy_stmt_read.loop_level[level-1+privatized_levels.size()+i].type = LoopLevelUnknown;
- copy_stmt_read.loop_level[level-1+privatized_levels.size()+i].payload = -1;
- copy_stmt_read.loop_level[level-1+privatized_levels.size()+i].parallel_level = 0;
+ copy_stmt_read.loop_level[level - 1 + privatized_levels.size() + i].type = LoopLevelUnknown;
+ copy_stmt_read.loop_level[level - 1 + privatized_levels.size() + i].payload = -1;
+ copy_stmt_read.loop_level[level - 1 + privatized_levels.size() + i].parallel_level = 0;
}
-
-
- shiftLexicalOrder(lex, dim-1, 1);
- fprintf(stderr, "loop_datacopy.cc L1071 adding stmt %d\n", stmt.size());
+
+ shiftLexicalOrder(lex, dim - 1, 1);
+
+ fprintf(stderr, "loop_datacopy.cc L1071 adding stmt %d\n", stmt.size());
stmt.push_back(copy_stmt_read);
uninterpreted_symbols.push_back(uninterpreted_symbols[*(active.begin())]);
@@ -1076,30 +1107,30 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
ro_copy_stmt_num = stmt.size() - 1;
dep.insert();
}
-
+
//fprintf(stderr, "dp3: insert write copy statement\n");
// insert write copy statement
int wo_copy_stmt_num = -1;
if (has_write_refs) {
- Relation copy_xform(wo_copy_is.n_set(), 2*wo_copy_is.n_set()+1);
+ Relation copy_xform(wo_copy_is.n_set(), 2 * wo_copy_is.n_set() + 1);
{
F_And *f_root = copy_xform.add_and();
for (int i = 1; i <= wo_copy_is.n_set(); i++) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(copy_xform.input_var(i), 1);
- h.update_coef(copy_xform.output_var(2*i), -1);
+ h.update_coef(copy_xform.output_var(2 * i), -1);
}
- for (int i = 1; i <= dim; i+=2) {
+ for (int i = 1; i <= dim; i += 2) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(copy_xform.output_var(i), -1);
- h.update_const(lex[i-1]);
+ h.update_const(lex[i - 1]);
}
- for (int i = dim+2; i <= copy_xform.n_out(); i+=2) {
+ for (int i = dim + 2; i <= copy_xform.n_out(); i += 2) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(copy_xform.output_var(i), 1);
}
}
-
+
Statement copy_stmt_write;
copy_stmt_write.IS = wo_copy_is;
copy_stmt_write.xform = copy_xform;
@@ -1107,8 +1138,8 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
copy_stmt_write.loop_level = std::vector<LoopLevel>(wo_copy_is.n_set());
copy_stmt_write.ir_stmt_node = NULL;
copy_stmt_write.has_inspector = false;
-
- for (int i = 0; i < level-1; i++) {
+
+ for (int i = 0; i < level - 1; i++) {
copy_stmt_write.loop_level[i].type = stmt[*(active.begin())].loop_level[i].type;
if (stmt[*(active.begin())].loop_level[i].type == LoopLevelTile &&
stmt[*(active.begin())].loop_level[i].payload >= level) {
@@ -1120,31 +1151,32 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
copy_stmt_write.loop_level[i].payload = -1;
else
copy_stmt_write.loop_level[i].payload = level + j;
- }
- else
+ } else
copy_stmt_write.loop_level[i].payload = stmt[*(active.begin())].loop_level[i].payload;
copy_stmt_write.loop_level[i].parallel_level = stmt[*(active.begin())].loop_level[i].parallel_level;
}
for (int i = 0; i < privatized_levels.size(); i++) {
- copy_stmt_write.loop_level[level-1+i].type = stmt[*(active.begin())].loop_level[privatized_levels[i]].type;
- copy_stmt_write.loop_level[level-1+i].payload = stmt[*(active.begin())].loop_level[privatized_levels[i]].payload;
- copy_stmt_write.loop_level[level-1+i].parallel_level = stmt[*(active.begin())].loop_level[privatized_levels[i]].parallel_level;
+ copy_stmt_write.loop_level[level - 1 + i].type = stmt[*(active.begin())].loop_level[privatized_levels[i]].type;
+ copy_stmt_write.loop_level[level - 1 +
+ i].payload = stmt[*(active.begin())].loop_level[privatized_levels[i]].payload;
+ copy_stmt_write.loop_level[level - 1 +
+ i].parallel_level = stmt[*(active.begin())].loop_level[privatized_levels[i]].parallel_level;
}
int left_num_dim = num_dep_dim - (get_last_dep_dim_before(*(active.begin()), level) + 1);
for (int i = 0; i < std::min(left_num_dim, static_cast<int>(index_sz.size())); i++) {
- copy_stmt_write.loop_level[level-1+privatized_levels.size()+i].type = LoopLevelOriginal;
- copy_stmt_write.loop_level[level-1+privatized_levels.size()+i].payload = num_dep_dim-left_num_dim+i;
- copy_stmt_write.loop_level[level-1+privatized_levels.size()+i].parallel_level = 0;
+ copy_stmt_write.loop_level[level - 1 + privatized_levels.size() + i].type = LoopLevelOriginal;
+ copy_stmt_write.loop_level[level - 1 + privatized_levels.size() + i].payload = num_dep_dim - left_num_dim + i;
+ copy_stmt_write.loop_level[level - 1 + privatized_levels.size() + i].parallel_level = 0;
}
for (int i = std::min(left_num_dim, static_cast<int>(index_sz.size())); i < index_sz.size(); i++) {
- copy_stmt_write.loop_level[level-1+privatized_levels.size()+i].type = LoopLevelUnknown;
- copy_stmt_write.loop_level[level-1+privatized_levels.size()+i].payload = -1;
- copy_stmt_write.loop_level[level-1+privatized_levels.size()+i].parallel_level = 0;
+ copy_stmt_write.loop_level[level - 1 + privatized_levels.size() + i].type = LoopLevelUnknown;
+ copy_stmt_write.loop_level[level - 1 + privatized_levels.size() + i].payload = -1;
+ copy_stmt_write.loop_level[level - 1 + privatized_levels.size() + i].parallel_level = 0;
}
- lex[dim-1]++;
- shiftLexicalOrder(lex, dim-1, -2);
+ lex[dim - 1]++;
+ shiftLexicalOrder(lex, dim - 1, -2);
- fprintf(stderr, "loop_datacopy.cc L1147 adding stmt %d\n", stmt.size());
+ fprintf(stderr, "loop_datacopy.cc L1147 adding stmt %d\n", stmt.size());
stmt.push_back(copy_stmt_write);
uninterpreted_symbols.push_back(uninterpreted_symbols[*(active.begin())]);
@@ -1152,24 +1184,24 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
wo_copy_stmt_num = stmt.size() - 1;
dep.insert();
}
-
+
//fprintf(stderr, "replace original array accesses with temporary array accesses\n");
// replace original array accesses with temporary array accesses
- for (int i =0; i < stmt_refs.size(); i++)
+ for (int i = 0; i < stmt_refs.size(); i++)
for (int j = 0; j < stmt_refs[i].second.size(); j++) {
if (index_sz.size() == 0) {
IR_ScalarRef *tmp_scalar_ref = ir->CreateScalarRef(static_cast<IR_ScalarSymbol *>(tmp_sym));
//fprintf(stderr, "dp3: loop_datacopy.cc calling ReplaceExpression i%d j%d\n", i, j);
ir->ReplaceExpression(stmt_refs[i].second[j], tmp_scalar_ref->convert());
- }
- else {
+ } else {
std::vector<CG_outputRepr *> index_repr(index_sz.size());
for (int k = 0; k < index_sz.size(); k++) {
int cur_index_num = index_sz[k].first;
-
- CG_outputRepr *cur_index_repr = ocg->CreateMinus(stmt_refs[i].second[j]->index(cur_index_num), index_lb[cur_index_num]->clone());
+
+ CG_outputRepr *cur_index_repr = ocg->CreateMinus(stmt_refs[i].second[j]->index(cur_index_num),
+ index_lb[cur_index_num]->clone());
if (padding_stride != 0) {
- if (k == n_dim-1) {
+ if (k == n_dim - 1) {
coef_t g = gcd(index_stride[cur_index_num], static_cast<coef_t>(padding_stride));
coef_t t1 = index_stride[cur_index_num] / g;
if (t1 != 1)
@@ -1177,23 +1209,22 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
coef_t t2 = padding_stride / g;
if (t2 != 1)
cur_index_repr = ocg->CreateTimes(cur_index_repr, ocg->CreateInt(t2));
- }
- else if (index_stride[cur_index_num] != 1) {
+ } else if (index_stride[cur_index_num] != 1) {
cur_index_repr = ocg->CreateIntegerFloor(cur_index_repr, ocg->CreateInt(index_stride[cur_index_num]));
}
}
-
+
if (ir->ArrayIndexStartAt() != 0)
cur_index_repr = ocg->CreatePlus(cur_index_repr, ocg->CreateInt(ir->ArrayIndexStartAt()));
index_repr[k] = cur_index_repr;
}
-
+
IR_ArrayRef *tmp_array_ref = ir->CreateArrayRef(static_cast<IR_ArraySymbol *>(tmp_sym), index_repr);
//fprintf(stderr, "loop_datacopy.cc ir->ReplaceExpression( ... )\n");
ir->ReplaceExpression(stmt_refs[i].second[j], tmp_array_ref->convert());
}
}
-
+
// update dependence graph
//fprintf(stderr, "update dependence graph\n");
@@ -1201,7 +1232,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
if (ro_copy_stmt_num != -1) {
for (int i = 0; i < old_num_stmt; i++) {
std::vector<std::vector<DependenceVector> > D;
-
+
for (DependenceGraph::EdgeList::iterator j = dep.vertex[i].second.begin(); j != dep.vertex[i].second.end();) {
if (active.find(i) != active.end() && active.find(j->first) == active.end()) {
std::vector<DependenceVector> dvs1, dvs2;
@@ -1215,8 +1246,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
j->second = dvs2;
if (dvs1.size() > 0)
dep.connect(ro_copy_stmt_num, j->first, dvs1);
- }
- else if (active.find(i) == active.end() && active.find(j->first) != active.end()) {
+ } else if (active.find(i) == active.end() && active.find(j->first) != active.end()) {
std::vector<DependenceVector> dvs1, dvs2;
for (int k = 0; k < j->second.size(); k++) {
DependenceVector dv = j->second[k];
@@ -1229,17 +1259,17 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
if (dvs1.size() > 0)
D.push_back(dvs1);
}
-
+
if (j->second.size() == 0)
dep.vertex[i].second.erase(j++);
else
j++;
}
-
+
for (int j = 0; j < D.size(); j++)
dep.connect(i, ro_copy_stmt_num, D[j]);
}
-
+
// insert dependences from copy statement loop to copied statements
//fprintf(stderr, "insert dependences from copy statement loop to copied statements\n");
@@ -1255,11 +1285,11 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
for (std::set<int>::iterator i = active.begin(); i != active.end(); i++)
dep.connect(ro_copy_stmt_num, *i, dv);
}
-
+
if (wo_copy_stmt_num != -1) {
for (int i = 0; i < old_num_stmt; i++) {
std::vector<std::vector<DependenceVector> > D;
-
+
for (DependenceGraph::EdgeList::iterator j = dep.vertex[i].second.begin(); j != dep.vertex[i].second.end();) {
if (active.find(i) != active.end() && active.find(j->first) == active.end()) {
std::vector<DependenceVector> dvs1, dvs2;
@@ -1273,8 +1303,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
j->second = dvs2;
if (dvs1.size() > 0)
dep.connect(wo_copy_stmt_num, j->first, dvs1);
- }
- else if (active.find(i) == active.end() && active.find(j->first) != active.end()) {
+ } else if (active.find(i) == active.end() && active.find(j->first) != active.end()) {
std::vector<DependenceVector> dvs1, dvs2;
for (int k = 0; k < j->second.size(); k++) {
DependenceVector dv = j->second[k];
@@ -1287,17 +1316,17 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
if (dvs1.size() > 0)
D.push_back(dvs1);
}
-
+
if (j->second.size() == 0)
dep.vertex[i].second.erase(j++);
else
j++;
}
-
+
for (int j = 0; j < D.size(); j++)
dep.connect(i, wo_copy_stmt_num, D[j]);
}
-
+
// insert dependences from copied statements to write statements
//fprintf(stderr, "dp3: insert dependences from copied statements to write statements\n");
@@ -1312,9 +1341,9 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
}
for (std::set<int>::iterator i = active.begin(); i != active.end(); i++)
dep.connect(*i, wo_copy_stmt_num, dv);
-
+
}
-
+
// update variable name for dependences among copied statements
for (int i = 0; i < old_num_stmt; i++) {
if (active.find(i) != active.end())
@@ -1325,7 +1354,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
j->second[k].sym = s;
}
}
-
+
// insert anti-dependence from write statement to read statement
if (ro_copy_stmt_num != -1 && wo_copy_stmt_num != -1)
if (dep_dim >= 0) {
@@ -1340,15 +1369,15 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
}
for (int k = 0; k < dep_dim; k++) {
if (k != 0) {
- dv.lbounds[k-1] = 0;
- dv.ubounds[k-1] = 0;
+ dv.lbounds[k - 1] = 0;
+ dv.ubounds[k - 1] = 0;
}
dv.lbounds[k] = 1;
dv.ubounds[k] = posInfinity;
dep.connect(wo_copy_stmt_num, ro_copy_stmt_num, dv);
}
}
-
+
//fprintf(stderr, "Loop::datacopy_privatized3() cleanup\n");
// cleanup
delete sym;
@@ -1361,7 +1390,7 @@ bool Loop::datacopy_privatized(const std::vector<std::pair<int, std::vector<IR_A
index_sz[i].second->clear();
delete index_sz[i].second;
}
-
+
return true;
}
diff --git a/src/transformations/loop_extra.cc b/src/transformations/loop_extra.cc
index dac05bf..ee54815 100644
--- a/src/transformations/loop_extra.cc
+++ b/src/transformations/loop_extra.cc
@@ -25,43 +25,44 @@ void Loop::shift_to(int stmt_num, int level, int absolute_position) {
// combo
tile(stmt_num, level, 1, level, CountedTile);
std::vector<int> lex = getLexicalOrder(stmt_num);
- std::set<int> active = getStatements(lex, 2*level-2);
+ std::set<int> active = getStatements(lex, 2 * level - 2);
shift(active, level, absolute_position);
-
+
// remove unnecessary tiled loop since tile size is one
for (std::set<int>::iterator i = active.begin(); i != active.end(); i++) {
int n = stmt[*i].xform.n_out();
- Relation mapping(n, n-2);
+ Relation mapping(n, n - 2);
F_And *f_root = mapping.add_and();
- for (int j = 1; j <= 2*level; j++) {
+ for (int j = 1; j <= 2 * level; j++) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(mapping.output_var(j), 1);
h.update_coef(mapping.input_var(j), -1);
}
- for (int j = 2*level+3; j <= n; j++) {
+ for (int j = 2 * level + 3; j <= n; j++) {
EQ_Handle h = f_root->add_EQ();
- h.update_coef(mapping.output_var(j-2), 1);
+ h.update_coef(mapping.output_var(j - 2), 1);
h.update_coef(mapping.input_var(j), -1);
}
stmt[*i].xform = Composition(mapping, stmt[*i].xform);
stmt[*i].xform.simplify();
-
+
for (int j = 0; j < stmt[*i].loop_level.size(); j++)
- if (j != level-1 &&
+ if (j != level - 1 &&
stmt[*i].loop_level[j].type == LoopLevelTile &&
stmt[*i].loop_level[j].payload >= level)
stmt[*i].loop_level[j].payload--;
-
- stmt[*i].loop_level.erase(stmt[*i].loop_level.begin()+level-1);
+
+ stmt[*i].loop_level.erase(stmt[*i].loop_level.begin() + level - 1);
}
}
std::set<int> Loop::unroll_extra(int stmt_num, int level, int unroll_amount, int cleanup_split_level) {
- std::set<int> cleanup_stmts = unroll(stmt_num, level, unroll_amount,std::vector< std::vector<std::string> >(), cleanup_split_level);
+ std::set<int> cleanup_stmts = unroll(stmt_num, level, unroll_amount, std::vector<std::vector<std::string> >(),
+ cleanup_split_level);
for (std::set<int>::iterator i = cleanup_stmts.begin(); i != cleanup_stmts.end(); i++)
unroll(*i, level, 0);
-
+
return cleanup_stmts;
}
@@ -71,10 +72,10 @@ void Loop::peel(int stmt_num, int level, int peel_amount) {
throw std::invalid_argument("invalid statement number " + to_string(stmt_num));
if (level <= 0 || level > stmt[stmt_num].loop_level.size())
throw std::invalid_argument("invalid loop level " + to_string(level));
-
+
if (peel_amount == 0)
return;
-
+
std::set<int> subloop = getSubLoopNest(stmt_num, level);
std::vector<Relation> Rs;
for (std::set<int>::iterator i = subloop.begin(); i != subloop.end(); i++) {
@@ -83,7 +84,7 @@ void Loop::peel(int stmt_num, int level, int peel_amount) {
F_And *f_root = f.add_and();
for (int j = 1; j <= level; j++) {
EQ_Handle h = f_root->add_EQ();
- h.update_coef(f.input_var(2*j), 1);
+ h.update_coef(f.input_var(2 * j), 1);
h.update_coef(f.output_var(j), -1);
}
r = Composition(f, r);
@@ -91,7 +92,7 @@ void Loop::peel(int stmt_num, int level, int peel_amount) {
Rs.push_back(r);
}
Relation hull = SimpleHull(Rs);
-
+
if (peel_amount > 0) {
GEQ_Handle bound_eq;
bool found_bound = false;
@@ -120,7 +121,7 @@ void Loop::peel(int stmt_num, int level, int peel_amount) {
}
if (!found_bound)
throw loop_error("can't find lower bound for peeling at loop level " + to_string(level));
-
+
for (int i = 1; i <= peel_amount; i++) {
Relation r(level);
F_Exists *f_exists = r.add_and()->add_exists();
@@ -129,34 +130,33 @@ void Loop::peel(int stmt_num, int level, int peel_amount) {
std::map<Variable_ID, Variable_ID> exists_mapping;
for (Constr_Vars_Iter cvi(bound_eq); cvi; cvi++)
switch (cvi.curr_var()->kind()) {
- case Input_Var:
- h.update_coef(r.set_var(cvi.curr_var()->get_position()), cvi.curr_coef());
- break;
- case Wildcard_Var: {
- Variable_ID v = replicate_floor_definition(hull, cvi.curr_var(), r, f_exists, f_root, exists_mapping);
- h.update_coef(v, cvi.curr_coef());
- break;
- }
- case Global_Var: {
- Global_Var_ID g = cvi.curr_var()->get_global_var();
- Variable_ID v;
- if (g->arity() == 0)
- v = r.get_local(g);
- else
- v = r.get_local(g, cvi.curr_var()->function_of());
- h.update_coef(v, cvi.curr_coef());
- break;
- }
- default:
- assert(false);
+ case Input_Var:
+ h.update_coef(r.set_var(cvi.curr_var()->get_position()), cvi.curr_coef());
+ break;
+ case Wildcard_Var: {
+ Variable_ID v = replicate_floor_definition(hull, cvi.curr_var(), r, f_exists, f_root, exists_mapping);
+ h.update_coef(v, cvi.curr_coef());
+ break;
+ }
+ case Global_Var: {
+ Global_Var_ID g = cvi.curr_var()->get_global_var();
+ Variable_ID v;
+ if (g->arity() == 0)
+ v = r.get_local(g);
+ else
+ v = r.get_local(g, cvi.curr_var()->function_of());
+ h.update_coef(v, cvi.curr_coef());
+ break;
+ }
+ default:
+ assert(false);
}
h.update_const(bound_eq.get_const() - i);
r.simplify();
-
+
split(stmt_num, level, r);
}
- }
- else { // peel_amount < 0
+ } else { // peel_amount < 0
GEQ_Handle bound_eq;
bool found_bound = false;
for (GEQ_Iterator e(hull.single_conjunct()->GEQs()); e; e++)
@@ -184,7 +184,7 @@ void Loop::peel(int stmt_num, int level, int peel_amount) {
}
if (!found_bound)
throw loop_error("can't find upper bound for peeling at loop level " + to_string(level));
-
+
for (int i = 1; i <= -peel_amount; i++) {
Relation r(level);
F_Exists *f_exists = r.add_and()->add_exists();
@@ -193,30 +193,30 @@ void Loop::peel(int stmt_num, int level, int peel_amount) {
std::map<Variable_ID, Variable_ID> exists_mapping;
for (Constr_Vars_Iter cvi(bound_eq); cvi; cvi++)
switch (cvi.curr_var()->kind()) {
- case Input_Var:
- h.update_coef(r.set_var(cvi.curr_var()->get_position()), cvi.curr_coef());
- break;
- case Wildcard_Var: {
- Variable_ID v = replicate_floor_definition(hull, cvi.curr_var(), r, f_exists, f_root, exists_mapping);
- h.update_coef(v, cvi.curr_coef());
- break;
- }
- case Global_Var: {
- Global_Var_ID g = cvi.curr_var()->get_global_var();
- Variable_ID v;
- if (g->arity() == 0)
- v = r.get_local(g);
- else
- v = r.get_local(g, cvi.curr_var()->function_of());
- h.update_coef(v, cvi.curr_coef());
- break;
- }
- default:
- assert(false);
+ case Input_Var:
+ h.update_coef(r.set_var(cvi.curr_var()->get_position()), cvi.curr_coef());
+ break;
+ case Wildcard_Var: {
+ Variable_ID v = replicate_floor_definition(hull, cvi.curr_var(), r, f_exists, f_root, exists_mapping);
+ h.update_coef(v, cvi.curr_coef());
+ break;
+ }
+ case Global_Var: {
+ Global_Var_ID g = cvi.curr_var()->get_global_var();
+ Variable_ID v;
+ if (g->arity() == 0)
+ v = r.get_local(g);
+ else
+ v = r.get_local(g, cvi.curr_var()->function_of());
+ h.update_coef(v, cvi.curr_coef());
+ break;
+ }
+ default:
+ assert(false);
}
h.update_const(bound_eq.get_const() - i);
r.simplify();
-
+
split(stmt_num, level, r);
}
}
diff --git a/src/transformations/loop_tile.cc b/src/transformations/loop_tile.cc
index 41c3e7f..0a1808b 100644
--- a/src/transformations/loop_tile.cc
+++ b/src/transformations/loop_tile.cc
@@ -14,8 +14,6 @@
using namespace omega;
-
-
void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
TilingMethodType method, int alignment_offset, int alignment_multiple) {
// check for sanity of parameters
@@ -29,30 +27,30 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
throw std::invalid_argument("invalid loop level " + to_string(level));
if (level > stmt[stmt_num].loop_level.size())
throw std::invalid_argument(
- "there is no loop level " + to_string(level) + " for statement "
- + to_string(stmt_num));
+ "there is no loop level " + to_string(level) + " for statement "
+ + to_string(stmt_num));
if (outer_level <= 0 || outer_level > level)
throw std::invalid_argument(
- "invalid tile controlling loop level "
- + to_string(outer_level));
-
+ "invalid tile controlling loop level "
+ + to_string(outer_level));
+
// invalidate saved codegen computation
delete last_compute_cgr_;
last_compute_cgr_ = NULL;
delete last_compute_cg_;
last_compute_cg_ = NULL;
-
+
int dim = 2 * level - 1;
int outer_dim = 2 * outer_level - 1;
std::vector<int> lex = getLexicalOrder(stmt_num);
std::set<int> same_tiled_loop = getStatements(lex, dim - 1);
std::set<int> same_tile_controlling_loop = getStatements(lex,
outer_dim - 1);
-
+
for (std::set<int>::iterator i = same_tiled_loop.begin();
i != same_tiled_loop.end(); i++) {
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[*i].second.begin(); j != dep.vertex[*i].second.end();
+ dep.vertex[*i].second.begin(); j != dep.vertex[*i].second.end();
j++) {
if (same_tiled_loop.find(j->first) != same_tiled_loop.end())
for (int k = 0; k < j->second.size(); k++) {
@@ -63,34 +61,34 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
dim2 = stmt[*i].loop_level[dim2].payload - 1;
}
dim2 = stmt[*i].loop_level[dim2].payload;
-
+
if (dv.hasNegative(dim2) && (!dv.quasi)) {
for (int l = outer_level; l < level; l++)
if (stmt[*i].loop_level[l - 1].type
!= LoopLevelTile) {
if (dv.isCarried(
- stmt[*i].loop_level[l - 1].payload)
+ stmt[*i].loop_level[l - 1].payload)
&& dv.hasPositive(
- stmt[*i].loop_level[l - 1].payload))
+ stmt[*i].loop_level[l - 1].payload))
throw loop_error(
- "loop error: Tiling is illegal, dependence violation!");
+ "loop error: Tiling is illegal, dependence violation!");
} else {
-
+
int dim3 = l - 1;
while (stmt[*i].loop_level[l - 1].type
!= LoopLevelTile) {
dim3 =
- stmt[*i].loop_level[l - 1].payload
- - 1;
-
+ stmt[*i].loop_level[l - 1].payload
+ - 1;
+
}
-
+
dim3 = stmt[*i].loop_level[l - 1].payload;
if (dim3 < level - 1)
if (dv.isCarried(dim3)
&& dv.hasPositive(dim3))
throw loop_error(
- "loop error: Tiling is illegal, dependence violation!");
+ "loop error: Tiling is illegal, dependence violation!");
}
}
}
@@ -117,11 +115,11 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
h.update_coef(r.input_var(j), 1);
h.update_coef(r.output_var(j + 2), -1);
}
-
+
stmt[*i].xform = Composition(copy(r), stmt[*i].xform);
}
}
- // normal tiling
+ // normal tiling
else {
std::set<int> private_stmt;
for (std::set<int>::iterator i = same_tile_controlling_loop.begin();
@@ -131,12 +129,12 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
&& overflow.find(*i) != overflow.end())
private_stmt.insert(*i);
}
-
+
// extract the union of the iteration space to be considered
Relation hull;
{
std::vector<Relation> r_list;
-
+
for (std::set<int>::iterator i = same_tile_controlling_loop.begin();
i != same_tile_controlling_loop.end(); i++)
if (private_stmt.find(*i) == private_stmt.end()) {
@@ -150,28 +148,28 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
r.simplify(2, 4);
r_list.push_back(r);
}
-
+
hull = SimpleHull(r_list);
}
-
+
// extract the bound of the dimension to be tiled
Relation bound = get_loop_bound(hull, dim);
if (!bound.has_single_conjunct()) {
// further simplify the bound
hull = Approximate(hull);
bound = get_loop_bound(hull, dim);
-
+
int i = outer_dim - 2;
while (!bound.has_single_conjunct() && i >= 0) {
hull = Project(hull, i + 1, Set_Var);
bound = get_loop_bound(hull, dim);
i -= 2;
}
-
+
if (!bound.has_single_conjunct())
throw loop_error("cannot handle tile bounds");
}
-
+
// separate lower and upper bounds
std::vector<GEQ_Handle> lb_list, ub_list;
{
@@ -186,11 +184,11 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
}
if (lb_list.size() == 0)
throw loop_error(
- "unable to calculate tile controlling loop lower bound");
+ "unable to calculate tile controlling loop lower bound");
if (ub_list.size() == 0)
throw loop_error(
- "unable to calculate tile controlling loop upper bound");
-
+ "unable to calculate tile controlling loop upper bound");
+
// find the simplest lower bound for StridedTile or simplest iteration count for CountedTile
int simplest_lb = 0, simplest_ub = 0;
if (method == StridedTile) {
@@ -199,20 +197,20 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
int cost = 0;
for (Constr_Vars_Iter ci(lb_list[i]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var: {
- cost += 5;
- break;
- }
- case Global_Var: {
- cost += 2;
- break;
- }
- default:
- cost += 15;
- break;
+ case Input_Var: {
+ cost += 5;
+ break;
+ }
+ case Global_Var: {
+ cost += 2;
+ break;
+ }
+ default:
+ cost += 15;
+ break;
}
}
-
+
if (cost < best_cost) {
best_cost = cost;
simplest_lb = i;
@@ -224,67 +222,67 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
for (int i = 0; i < lb_list.size(); i++)
for (int j = 0; j < ub_list.size(); j++) {
int cost = 0;
-
+
for (Constr_Vars_Iter ci(lb_list[i]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var: {
- s1[(*ci).var] += (*ci).coef;
- break;
- }
- case Global_Var: {
- s2[(*ci).var] += (*ci).coef;
- break;
- }
- case Exists_Var:
- case Wildcard_Var: {
- s3[(*ci).var] += (*ci).coef;
- break;
- }
- default:
- cost = INT_MAX - 2;
- break;
+ case Input_Var: {
+ s1[(*ci).var] += (*ci).coef;
+ break;
+ }
+ case Global_Var: {
+ s2[(*ci).var] += (*ci).coef;
+ break;
+ }
+ case Exists_Var:
+ case Wildcard_Var: {
+ s3[(*ci).var] += (*ci).coef;
+ break;
+ }
+ default:
+ cost = INT_MAX - 2;
+ break;
}
}
-
+
for (Constr_Vars_Iter ci(ub_list[j]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var: {
- s1[(*ci).var] += (*ci).coef;
- break;
- }
- case Global_Var: {
- s2[(*ci).var] += (*ci).coef;
- break;
- }
- case Exists_Var:
- case Wildcard_Var: {
- s3[(*ci).var] += (*ci).coef;
- break;
- }
- default:
- if (cost == INT_MAX - 2)
- cost = INT_MAX - 1;
- else
- cost = INT_MAX - 3;
- break;
+ case Input_Var: {
+ s1[(*ci).var] += (*ci).coef;
+ break;
+ }
+ case Global_Var: {
+ s2[(*ci).var] += (*ci).coef;
+ break;
+ }
+ case Exists_Var:
+ case Wildcard_Var: {
+ s3[(*ci).var] += (*ci).coef;
+ break;
+ }
+ default:
+ if (cost == INT_MAX - 2)
+ cost = INT_MAX - 1;
+ else
+ cost = INT_MAX - 3;
+ break;
}
}
-
+
if (cost == 0) {
for (std::map<Variable_ID, coef_t>::iterator k =
- s1.begin(); k != s1.end(); k++)
+ s1.begin(); k != s1.end(); k++)
if ((*k).second != 0)
cost += 5;
for (std::map<Variable_ID, coef_t>::iterator k =
- s2.begin(); k != s2.end(); k++)
+ s2.begin(); k != s2.end(); k++)
if ((*k).second != 0)
cost += 2;
for (std::map<Variable_ID, coef_t>::iterator k =
- s3.begin(); k != s3.end(); k++)
+ s3.begin(); k != s3.end(); k++)
if ((*k).second != 0)
cost += 15;
}
-
+
if (cost < best_cost) {
best_cost = cost;
simplest_lb = i;
@@ -292,7 +290,7 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
}
}
}
-
+
// prepare the new transformation relations
for (std::set<int>::iterator i = same_tile_controlling_loop.begin();
i != same_tile_controlling_loop.end(); i++) {
@@ -303,58 +301,58 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
h.update_coef(r.output_var(j + 1), 1);
h.update_coef(r.input_var(j + 1), -1);
}
-
+
for (int j = outer_dim - 1; j < stmt[*i].xform.n_out(); j++) {
EQ_Handle h = f_root->add_EQ();
h.update_coef(r.output_var(j + 3), 1);
h.update_coef(r.input_var(j + 1), -1);
}
-
+
EQ_Handle h = f_root->add_EQ();
h.update_coef(r.output_var(outer_dim), 1);
h.update_const(-lex[outer_dim - 1]);
-
+
stmt[*i].xform = Composition(r, stmt[*i].xform);
}
-
+
// add tiling constraints.
for (std::set<int>::iterator i = same_tile_controlling_loop.begin();
i != same_tile_controlling_loop.end(); i++) {
F_And *f_super_root = stmt[*i].xform.and_with_and();
F_Exists *f_exists = f_super_root->add_exists();
F_And *f_root = f_exists->add_and();
-
+
// create a lower bound variable for easy formula creation later
Variable_ID aligned_lb;
{
Variable_ID lb = f_exists->declare();
coef_t coef = lb_list[simplest_lb].get_coef(
- bound.set_var(dim + 1));
+ bound.set_var(dim + 1));
if (coef == 1) { // e.g. if i >= m+5, then LB = m+5
EQ_Handle h = f_root->add_EQ();
h.update_coef(lb, 1);
for (Constr_Vars_Iter ci(lb_list[simplest_lb]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var: {
- int pos = (*ci).var->get_position();
- if (pos != dim + 1)
- h.update_coef(stmt[*i].xform.output_var(pos),
- (*ci).coef);
- break;
- }
- case Global_Var: {
- Global_Var_ID g = (*ci).var->get_global_var();
- Variable_ID v;
- if (g->arity() == 0)
- v = stmt[*i].xform.get_local(g);
- else
- v = stmt[*i].xform.get_local(g,
- (*ci).var->function_of());
- h.update_coef(v, (*ci).coef);
- break;
- }
- default:
- throw loop_error("cannot handle tile bounds");
+ case Input_Var: {
+ int pos = (*ci).var->get_position();
+ if (pos != dim + 1)
+ h.update_coef(stmt[*i].xform.output_var(pos),
+ (*ci).coef);
+ break;
+ }
+ case Global_Var: {
+ Global_Var_ID g = (*ci).var->get_global_var();
+ Variable_ID v;
+ if (g->arity() == 0)
+ v = stmt[*i].xform.get_local(g);
+ else
+ v = stmt[*i].xform.get_local(g,
+ (*ci).var->function_of());
+ h.update_coef(v, (*ci).coef);
+ break;
+ }
+ default:
+ throw loop_error("cannot handle tile bounds");
}
}
h.update_const(lb_list[simplest_lb].get_const());
@@ -363,40 +361,40 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
GEQ_Handle h2 = f_root->add_GEQ();
for (Constr_Vars_Iter ci(lb_list[simplest_lb]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var: {
- int pos = (*ci).var->get_position();
- if (pos == dim + 1) {
- h1.update_coef(lb, (*ci).coef);
- h2.update_coef(lb, -(*ci).coef);
- } else {
- h1.update_coef(stmt[*i].xform.output_var(pos),
- (*ci).coef);
- h2.update_coef(stmt[*i].xform.output_var(pos),
- -(*ci).coef);
+ case Input_Var: {
+ int pos = (*ci).var->get_position();
+ if (pos == dim + 1) {
+ h1.update_coef(lb, (*ci).coef);
+ h2.update_coef(lb, -(*ci).coef);
+ } else {
+ h1.update_coef(stmt[*i].xform.output_var(pos),
+ (*ci).coef);
+ h2.update_coef(stmt[*i].xform.output_var(pos),
+ -(*ci).coef);
+ }
+ break;
}
- break;
- }
- case Global_Var: {
- Global_Var_ID g = (*ci).var->get_global_var();
- Variable_ID v;
- if (g->arity() == 0)
- v = stmt[*i].xform.get_local(g);
- else
- v = stmt[*i].xform.get_local(g,
- (*ci).var->function_of());
- h1.update_coef(v, (*ci).coef);
- h2.update_coef(v, -(*ci).coef);
- break;
- }
- default:
- throw loop_error("cannot handle tile bounds");
+ case Global_Var: {
+ Global_Var_ID g = (*ci).var->get_global_var();
+ Variable_ID v;
+ if (g->arity() == 0)
+ v = stmt[*i].xform.get_local(g);
+ else
+ v = stmt[*i].xform.get_local(g,
+ (*ci).var->function_of());
+ h1.update_coef(v, (*ci).coef);
+ h2.update_coef(v, -(*ci).coef);
+ break;
+ }
+ default:
+ throw loop_error("cannot handle tile bounds");
}
}
h1.update_const(lb_list[simplest_lb].get_const());
h2.update_const(-lb_list[simplest_lb].get_const());
h2.update_const(coef - 1);
}
-
+
Variable_ID offset_lb;
if (alignment_offset == 0)
offset_lb = lb;
@@ -407,17 +405,17 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
h.update_coef(lb, -1);
h.update_const(alignment_offset);
}
-
+
if (alignment_multiple == 1) { // trivial
aligned_lb = offset_lb;
} else { // e.g. to align at 4, aligned_lb = 4*alpha && LB-4 < 4*alpha <= LB
aligned_lb = f_exists->declare();
Variable_ID e = f_exists->declare();
-
+
EQ_Handle h = f_root->add_EQ();
h.update_coef(aligned_lb, 1);
h.update_coef(e, -alignment_multiple);
-
+
GEQ_Handle h1 = f_root->add_GEQ();
GEQ_Handle h2 = f_root->add_GEQ();
h1.update_coef(e, alignment_multiple);
@@ -427,37 +425,37 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
h1.update_const(alignment_multiple - 1);
}
}
-
+
// create an upper bound variable for easy formula creation later
Variable_ID ub = f_exists->declare();
{
coef_t coef = -ub_list[simplest_ub].get_coef(
- bound.set_var(dim + 1));
+ bound.set_var(dim + 1));
if (coef == 1) { // e.g. if i <= m+5, then UB = m+5
EQ_Handle h = f_root->add_EQ();
h.update_coef(ub, -1);
for (Constr_Vars_Iter ci(ub_list[simplest_ub]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var: {
- int pos = (*ci).var->get_position();
- if (pos != dim + 1)
- h.update_coef(stmt[*i].xform.output_var(pos),
- (*ci).coef);
- break;
- }
- case Global_Var: {
- Global_Var_ID g = (*ci).var->get_global_var();
- Variable_ID v;
- if (g->arity() == 0)
- v = stmt[*i].xform.get_local(g);
- else
- v = stmt[*i].xform.get_local(g,
- (*ci).var->function_of());
- h.update_coef(v, (*ci).coef);
- break;
- }
- default:
- throw loop_error("cannot handle tile bounds");
+ case Input_Var: {
+ int pos = (*ci).var->get_position();
+ if (pos != dim + 1)
+ h.update_coef(stmt[*i].xform.output_var(pos),
+ (*ci).coef);
+ break;
+ }
+ case Global_Var: {
+ Global_Var_ID g = (*ci).var->get_global_var();
+ Variable_ID v;
+ if (g->arity() == 0)
+ v = stmt[*i].xform.get_local(g);
+ else
+ v = stmt[*i].xform.get_local(g,
+ (*ci).var->function_of());
+ h.update_coef(v, (*ci).coef);
+ break;
+ }
+ default:
+ throw loop_error("cannot handle tile bounds");
}
}
h.update_const(ub_list[simplest_ub].get_const());
@@ -466,33 +464,33 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
GEQ_Handle h2 = f_root->add_GEQ();
for (Constr_Vars_Iter ci(ub_list[simplest_ub]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var: {
- int pos = (*ci).var->get_position();
- if (pos == dim + 1) {
- h1.update_coef(ub, -(*ci).coef);
- h2.update_coef(ub, (*ci).coef);
- } else {
- h1.update_coef(stmt[*i].xform.output_var(pos),
- -(*ci).coef);
- h2.update_coef(stmt[*i].xform.output_var(pos),
- (*ci).coef);
+ case Input_Var: {
+ int pos = (*ci).var->get_position();
+ if (pos == dim + 1) {
+ h1.update_coef(ub, -(*ci).coef);
+ h2.update_coef(ub, (*ci).coef);
+ } else {
+ h1.update_coef(stmt[*i].xform.output_var(pos),
+ -(*ci).coef);
+ h2.update_coef(stmt[*i].xform.output_var(pos),
+ (*ci).coef);
+ }
+ break;
}
- break;
- }
- case Global_Var: {
- Global_Var_ID g = (*ci).var->get_global_var();
- Variable_ID v;
- if (g->arity() == 0)
- v = stmt[*i].xform.get_local(g);
- else
- v = stmt[*i].xform.get_local(g,
- (*ci).var->function_of());
- h1.update_coef(v, -(*ci).coef);
- h2.update_coef(v, (*ci).coef);
- break;
- }
- default:
- throw loop_error("cannot handle tile bounds");
+ case Global_Var: {
+ Global_Var_ID g = (*ci).var->get_global_var();
+ Variable_ID v;
+ if (g->arity() == 0)
+ v = stmt[*i].xform.get_local(g);
+ else
+ v = stmt[*i].xform.get_local(g,
+ (*ci).var->function_of());
+ h1.update_coef(v, -(*ci).coef);
+ h2.update_coef(v, (*ci).coef);
+ break;
+ }
+ default:
+ throw loop_error("cannot handle tile bounds");
}
}
h1.update_const(-ub_list[simplest_ub].get_const());
@@ -500,13 +498,13 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
h1.update_const(coef - 1);
}
}
-
+
// insert tile controlling loop constraints
if (method == StridedTile) { // e.g. ii = LB + 32 * alpha && alpha >= 0
Variable_ID e = f_exists->declare();
GEQ_Handle h1 = f_root->add_GEQ();
h1.update_coef(e, 1);
-
+
EQ_Handle h2 = f_root->add_EQ();
h2.update_coef(stmt[*i].xform.output_var(outer_dim + 1), 1);
h2.update_coef(e, -tile_size);
@@ -514,14 +512,14 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
} else if (method == CountedTile) { // e.g. 0 <= ii < ceiling((UB-LB+1)/32)
GEQ_Handle h1 = f_root->add_GEQ();
h1.update_coef(stmt[*i].xform.output_var(outer_dim + 1), 1);
-
+
GEQ_Handle h2 = f_root->add_GEQ();
h2.update_coef(stmt[*i].xform.output_var(outer_dim + 1),
-tile_size);
h2.update_coef(aligned_lb, -1);
h2.update_coef(ub, 1);
}
-
+
// special care for private statements like overflow assignment
if (private_stmt.find(*i) != private_stmt.end()) { // e.g. ii <= UB
GEQ_Handle h = f_root->add_GEQ();
@@ -529,14 +527,14 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
h.update_coef(ub, 1);
}
- // restrict original loop index inside the tile
+ // restrict original loop index inside the tile
else {
if (method == StridedTile) { // e.g. ii <= i < ii + tile_size
GEQ_Handle h1 = f_root->add_GEQ();
h1.update_coef(stmt[*i].xform.output_var(dim + 3), 1);
h1.update_coef(stmt[*i].xform.output_var(outer_dim + 1),
-1);
-
+
GEQ_Handle h2 = f_root->add_GEQ();
h2.update_coef(stmt[*i].xform.output_var(dim + 3), -1);
h2.update_coef(stmt[*i].xform.output_var(outer_dim + 1), 1);
@@ -547,7 +545,7 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
-tile_size);
h1.update_coef(stmt[*i].xform.output_var(dim + 3), 1);
h1.update_coef(aligned_lb, -1);
-
+
GEQ_Handle h2 = f_root->add_GEQ();
h2.update_coef(stmt[*i].xform.output_var(outer_dim + 1),
tile_size);
@@ -558,30 +556,30 @@ void Loop::tile(int stmt_num, int level, int tile_size, int outer_level,
}
}
}
-
+
// update loop level information
for (std::set<int>::iterator i = same_tile_controlling_loop.begin();
i != same_tile_controlling_loop.end(); i++) {
for (int j = 1; j <= stmt[*i].loop_level.size(); j++)
switch (stmt[*i].loop_level[j - 1].type) {
- case LoopLevelOriginal:
- break;
- case LoopLevelTile:
- if (stmt[*i].loop_level[j - 1].payload >= outer_level)
- stmt[*i].loop_level[j - 1].payload++;
- break;
- default:
- throw loop_error(
- "unknown loop level type for statement "
- + to_string(*i));
+ case LoopLevelOriginal:
+ break;
+ case LoopLevelTile:
+ if (stmt[*i].loop_level[j - 1].payload >= outer_level)
+ stmt[*i].loop_level[j - 1].payload++;
+ break;
+ default:
+ throw loop_error(
+ "unknown loop level type for statement "
+ + to_string(*i));
}
-
+
LoopLevel ll;
ll.type = LoopLevelTile;
ll.payload = level + 1;
ll.parallel_level = 0;
stmt[*i].loop_level.insert(
- stmt[*i].loop_level.begin() + (outer_level - 1), ll);
+ stmt[*i].loop_level.begin() + (outer_level - 1), ll);
}
}
diff --git a/src/transformations/loop_unroll.cc b/src/transformations/loop_unroll.cc
index 86ffd84..3238d50 100644
--- a/src/transformations/loop_unroll.cc
+++ b/src/transformations/loop_unroll.cc
@@ -23,54 +23,54 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
// check for sanity of parameters
if (unroll_amount < 0)
throw std::invalid_argument(
- "invalid unroll amount " + to_string(unroll_amount));
+ "invalid unroll amount " + to_string(unroll_amount));
if (stmt_num < 0 || stmt_num >= stmt.size())
throw std::invalid_argument("invalid statement " + to_string(stmt_num));
if (level <= 0 || level > stmt[stmt_num].loop_level.size())
throw std::invalid_argument("invalid loop level " + to_string(level));
-
+
if (cleanup_split_level == 0)
cleanup_split_level = level;
if (cleanup_split_level > level)
throw std::invalid_argument(
- "cleanup code must be split at or outside the unrolled loop level "
- + to_string(level));
+ "cleanup code must be split at or outside the unrolled loop level "
+ + to_string(level));
if (cleanup_split_level <= 0)
throw std::invalid_argument(
- "invalid split loop level " + to_string(cleanup_split_level));
-
+ "invalid split loop level " + to_string(cleanup_split_level));
+
// invalidate saved codegen computation
delete last_compute_cgr_;
last_compute_cgr_ = NULL;
delete last_compute_cg_;
last_compute_cg_ = NULL;
-
+
int dim = 2 * level - 1;
std::vector<int> lex = getLexicalOrder(stmt_num);
std::set<int> same_loop = getStatements(lex, dim - 1);
-
+
// nothing to do
if (unroll_amount == 1)
return std::set<int>();
-
+
for (std::set<int>::iterator i = same_loop.begin(); i != same_loop.end();
i++) {
std::vector<std::pair<int, DependenceVector> > D;
int n = stmt[*i].xform.n_out();
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[*i].second.begin(); j != dep.vertex[*i].second.end();
+ dep.vertex[*i].second.begin(); j != dep.vertex[*i].second.end();
j++) {
if (same_loop.find(j->first) != same_loop.end())
for (int k = 0; k < j->second.size(); k++) {
DependenceVector dv = j->second[k];
int dim2 = level - 1;
if (dv.type != DEP_CONTROL) {
-
+
while (stmt[*i].loop_level[dim2].type == LoopLevelTile) {
dim2 = stmt[*i].loop_level[dim2].payload - 1;
}
dim2 = stmt[*i].loop_level[dim2].payload;
-
+
/*if (dv.isCarried(dim2)
&& (dv.hasNegative(dim2) && !dv.quasi))
throw loop_error(
@@ -82,11 +82,11 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
"loop error: Unrolling is illegal, dependence violation!");
*/
bool safe = false;
-
+
if (dv.isCarried(dim2) && dv.hasPositive(dim2)) {
if (dv.quasi)
throw loop_error(
- "loop error: a quasi dependence with a positive carried distance");
+ "loop error: a quasi dependence with a positive carried distance");
if (!dv.quasi) {
if (dv.lbounds[dim2] != posInfinity) {
//if (dv.lbounds[dim2] != negInfinity)
@@ -102,33 +102,33 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
} else
safe = true;
}*/
-
+
if (!safe) {
for (int l = level + 1; l <= (n - 1) / 2; l++) {
int dim3 = l - 1;
-
+
if (stmt[*i].loop_level[dim3].type
!= LoopLevelTile)
dim3 =
- stmt[*i].loop_level[dim3].payload;
+ stmt[*i].loop_level[dim3].payload;
else {
while (stmt[*i].loop_level[dim3].type
== LoopLevelTile) {
dim3 =
- stmt[*i].loop_level[dim3].payload
- - 1;
+ stmt[*i].loop_level[dim3].payload
+ - 1;
}
dim3 =
- stmt[*i].loop_level[dim3].payload;
+ stmt[*i].loop_level[dim3].payload;
}
-
+
if (dim3 > dim2) {
-
+
if (dv.hasPositive(dim3))
break;
else if (dv.hasNegative(dim3))
throw loop_error(
- "loop error: Unrolling is illegal, dependence violation!");
+ "loop error: Unrolling is illegal, dependence violation!");
}
}
}
@@ -153,7 +153,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
hull = Intersection(hull,
omega::Range(Restrict_Domain(mapping, copy(stmt[*i].IS))));
hull.simplify(2, 4);
-
+
}
}
for (int i = 1; i <= level; i++) {
@@ -161,7 +161,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
hull.name_set_var(i, name);
}
hull.setup_names();
-
+
// extract the exact loop bound of the dimension to be unrolled
if (is_single_loop_iteration(hull, level, this->known))
return std::set<int>();
@@ -169,7 +169,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
if (!bound.has_single_conjunct() || !bound.is_satisfiable()
|| bound.is_tautology())
throw loop_error("unable to extract loop bound for unrolling");
-
+
// extract the loop stride
coef_t stride;
std::pair<EQ_Handle, Variable_ID> result = find_simplest_stride(bound,
@@ -178,9 +178,9 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
stride = 1;
else
stride = abs(result.first.get_coef(result.second))
- / gcd(abs(result.first.get_coef(result.second)),
- abs(result.first.get_coef(bound.set_var(level))));
-
+ / gcd(abs(result.first.get_coef(result.second)),
+ abs(result.first.get_coef(bound.set_var(level))));
+
// separate lower and upper bounds
std::vector<GEQ_Handle> lb_list, ub_list;
{
@@ -193,17 +193,17 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
lb_list.push_back(*gi);
}
}
-
+
// simplify overflow expression for each pair of upper and lower bounds
std::vector<std::vector<std::map<Variable_ID, int> > > overflow_table(
- lb_list.size(),
- std::vector<std::map<Variable_ID, int> >(ub_list.size(),
- std::map<Variable_ID, int>()));
+ lb_list.size(),
+ std::vector<std::map<Variable_ID, int> >(ub_list.size(),
+ std::map<Variable_ID, int>()));
bool is_overflow_simplifiable = true;
for (int i = 0; i < lb_list.size(); i++) {
if (!is_overflow_simplifiable)
break;
-
+
for (int j = 0; j < ub_list.size(); j++) {
// lower bound or upper bound has non-unit coefficient, can't simplify
if (ub_list[j].get_coef(bound.set_var(level)) != -1
@@ -211,81 +211,81 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
is_overflow_simplifiable = false;
break;
}
-
+
for (Constr_Vars_Iter ci(ub_list[j]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var: {
- if ((*ci).var != bound.set_var(level))
+ case Input_Var: {
+ if ((*ci).var != bound.set_var(level))
+ overflow_table[i][j][(*ci).var] += (*ci).coef;
+
+ break;
+ }
+ case Global_Var: {
+ Global_Var_ID g = (*ci).var->get_global_var();
+ Variable_ID v;
+ if (g->arity() == 0)
+ v = bound.get_local(g);
+ else
+ v = bound.get_local(g, (*ci).var->function_of());
overflow_table[i][j][(*ci).var] += (*ci).coef;
-
- break;
- }
- case Global_Var: {
- Global_Var_ID g = (*ci).var->get_global_var();
- Variable_ID v;
- if (g->arity() == 0)
- v = bound.get_local(g);
- else
- v = bound.get_local(g, (*ci).var->function_of());
- overflow_table[i][j][(*ci).var] += (*ci).coef;
- break;
- }
- default:
- throw loop_error("failed to calculate overflow amount");
+ break;
+ }
+ default:
+ throw loop_error("failed to calculate overflow amount");
}
}
overflow_table[i][j][NULL] += ub_list[j].get_const();
-
+
for (Constr_Vars_Iter ci(lb_list[i]); ci; ci++) {
switch ((*ci).var->kind()) {
- case Input_Var: {
- if ((*ci).var != bound.set_var(level)) {
+ case Input_Var: {
+ if ((*ci).var != bound.set_var(level)) {
+ overflow_table[i][j][(*ci).var] += (*ci).coef;
+ if (overflow_table[i][j][(*ci).var] == 0)
+ overflow_table[i][j].erase(
+ overflow_table[i][j].find((*ci).var));
+ }
+ break;
+ }
+ case Global_Var: {
+ Global_Var_ID g = (*ci).var->get_global_var();
+ Variable_ID v;
+ if (g->arity() == 0)
+ v = bound.get_local(g);
+ else
+ v = bound.get_local(g, (*ci).var->function_of());
overflow_table[i][j][(*ci).var] += (*ci).coef;
if (overflow_table[i][j][(*ci).var] == 0)
overflow_table[i][j].erase(
- overflow_table[i][j].find((*ci).var));
+ overflow_table[i][j].find((*ci).var));
+ break;
}
- break;
- }
- case Global_Var: {
- Global_Var_ID g = (*ci).var->get_global_var();
- Variable_ID v;
- if (g->arity() == 0)
- v = bound.get_local(g);
- else
- v = bound.get_local(g, (*ci).var->function_of());
- overflow_table[i][j][(*ci).var] += (*ci).coef;
- if (overflow_table[i][j][(*ci).var] == 0)
- overflow_table[i][j].erase(
- overflow_table[i][j].find((*ci).var));
- break;
- }
- default:
- throw loop_error("failed to calculate overflow amount");
+ default:
+ throw loop_error("failed to calculate overflow amount");
}
}
overflow_table[i][j][NULL] += lb_list[i].get_const();
-
+
overflow_table[i][j][NULL] += stride;
if (unroll_amount == 0
|| (overflow_table[i][j].size() == 1
&& overflow_table[i][j][NULL] / stride
- < unroll_amount))
+ < unroll_amount))
unroll_amount = overflow_table[i][j][NULL] / stride;
}
}
-
+
// loop iteration count can't be determined, bail out gracefully
if (unroll_amount == 0)
return std::set<int>();
-
+
// further simply overflow calculation using coefficients' modular
if (is_overflow_simplifiable) {
for (int i = 0; i < lb_list.size(); i++)
for (int j = 0; j < ub_list.size(); j++)
if (stride == 1) {
for (std::map<Variable_ID, int>::iterator k =
- overflow_table[i][j].begin();
+ overflow_table[i][j].begin();
k != overflow_table[i][j].end();)
if ((*k).first != NULL) {
int t = int_mod_hat((*k).second, unroll_amount);
@@ -304,20 +304,20 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
}
} else
k++;
-
+
overflow_table[i][j][NULL] = int_mod_hat(
- overflow_table[i][j][NULL], unroll_amount);
-
+ overflow_table[i][j][NULL], unroll_amount);
+
// Since we don't have MODULO instruction in SUIF yet (only MOD),
// make all coef positive in the final formula
for (std::map<Variable_ID, int>::iterator k =
- overflow_table[i][j].begin();
+ overflow_table[i][j].begin();
k != overflow_table[i][j].end(); k++)
if ((*k).second < 0)
(*k).second += unroll_amount;
}
}
-
+
// build overflow statement
CG_outputBuilder *ocg = ir->builder();
CG_outputRepr *overflow_code = NULL;
@@ -331,17 +331,17 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
// upper splitting condition
GEQ_Handle h = cond_upper.and_with_GEQ(ub_list[i]);
h.update_const(
- ((overflow_table[0][i][NULL] / stride) % unroll_amount)
- * -stride);
+ ((overflow_table[0][i][NULL] / stride) % unroll_amount)
+ * -stride);
} else {
// upper splitting condition
std::string over_name = overflow_var_name_prefix
- + to_string(overflow_var_name_counter++);
+ + to_string(overflow_var_name_counter++);
Free_Var_Decl *over_free_var = new Free_Var_Decl(over_name);
over_var_list.push_back(over_free_var);
GEQ_Handle h = cond_upper.and_with_GEQ(ub_list[i]);
h.update_coef(cond_upper.get_local(over_free_var), -stride);
-
+
// insert constraint 0 <= overflow < unroll_amount
Variable_ID v = overflow_constraint.get_local(over_free_var);
GEQ_Handle h1 = overflow_constraint_root->add_GEQ();
@@ -349,20 +349,20 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
GEQ_Handle h2 = overflow_constraint_root->add_GEQ();
h2.update_coef(v, -1);
h2.update_const(unroll_amount - 1);
-
+
// create overflow assignment
bound.setup_names(); // hack to fix omega relation variable names issue
CG_outputRepr *rhs = NULL;
bool is_split_illegal = false;
for (std::map<Variable_ID, int>::iterator j =
- overflow_table[0][i].begin();
+ overflow_table[0][i].begin();
j != overflow_table[0][i].end(); j++)
if ((*j).first != NULL) {
if ((*j).first->kind() == Input_Var
&& (*j).first->get_position()
- >= cleanup_split_level)
+ >= cleanup_split_level)
is_split_illegal = true;
-
+
CG_outputRepr *t = ocg->CreateIdent((*j).first->name());
if ((*j).second != 1)
t = ocg->CreateTimes(ocg->CreateInt((*j).second),
@@ -370,20 +370,20 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
rhs = ocg->CreatePlus(rhs, t);
} else if ((*j).second != 0)
rhs = ocg->CreatePlus(rhs, ocg->CreateInt((*j).second));
-
+
if (is_split_illegal) {
rhs->clear();
delete rhs;
throw loop_error(
- "cannot split cleanup code at loop level "
- + to_string(cleanup_split_level)
- + " due to overflow variable data dependence");
+ "cannot split cleanup code at loop level "
+ + to_string(cleanup_split_level)
+ + " due to overflow variable data dependence");
}
-
+
if (stride != 1)
rhs = ocg->CreateIntegerCeil(rhs, ocg->CreateInt(stride));
rhs = ocg->CreateIntegerMod(rhs, ocg->CreateInt(unroll_amount));
-
+
CG_outputRepr *lhs = ocg->CreateIdent(over_name);
init_code = ocg->StmtListAppend(init_code,
ocg->CreateAssignment(0, lhs, ocg->CreateInt(0)));
@@ -392,12 +392,12 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
ocg->CreateAssignment(0, lhs, rhs));
}
}
-
+
// lower splitting condition
GEQ_Handle h = cond_lower.and_with_GEQ(lb_list[0]);
} else if (is_overflow_simplifiable && ub_list.size() == 1) {
for (int i = 0; i < lb_list.size(); i++) {
-
+
if (overflow_table[i][0].size() == 1) {
// lower splitting condition
GEQ_Handle h = cond_lower.and_with_GEQ(lb_list[i]);
@@ -405,12 +405,12 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
} else {
// lower splitting condition
std::string over_name = overflow_var_name_prefix
- + to_string(overflow_var_name_counter++);
+ + to_string(overflow_var_name_counter++);
Free_Var_Decl *over_free_var = new Free_Var_Decl(over_name);
over_var_list.push_back(over_free_var);
GEQ_Handle h = cond_lower.and_with_GEQ(lb_list[i]);
h.update_coef(cond_lower.get_local(over_free_var), -stride);
-
+
// insert constraint 0 <= overflow < unroll_amount
Variable_ID v = overflow_constraint.get_local(over_free_var);
GEQ_Handle h1 = overflow_constraint_root->add_GEQ();
@@ -418,12 +418,12 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
GEQ_Handle h2 = overflow_constraint_root->add_GEQ();
h2.update_coef(v, -1);
h2.update_const(unroll_amount - 1);
-
+
// create overflow assignment
bound.setup_names(); // hack to fix omega relation variable names issue
CG_outputRepr *rhs = NULL;
for (std::map<Variable_ID, int>::iterator j =
- overflow_table[0][i].begin();
+ overflow_table[0][i].begin();
j != overflow_table[0][i].end(); j++)
if ((*j).first != NULL) {
CG_outputRepr *t = ocg->CreateIdent((*j).first->name());
@@ -433,11 +433,11 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
rhs = ocg->CreatePlus(rhs, t);
} else if ((*j).second != 0)
rhs = ocg->CreatePlus(rhs, ocg->CreateInt((*j).second));
-
+
if (stride != 1)
rhs = ocg->CreateIntegerCeil(rhs, ocg->CreateInt(stride));
rhs = ocg->CreateIntegerMod(rhs, ocg->CreateInt(unroll_amount));
-
+
CG_outputRepr *lhs = ocg->CreateIdent(over_name);
init_code = ocg->StmtListAppend(init_code,
ocg->CreateAssignment(0, lhs, ocg->CreateInt(0)));
@@ -446,61 +446,59 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
ocg->CreateAssignment(0, lhs, rhs));
}
}
-
+
// upper splitting condition
GEQ_Handle h = cond_upper.and_with_GEQ(ub_list[0]);
} else {
std::string over_name = overflow_var_name_prefix
- + to_string(overflow_var_name_counter++);
+ + to_string(overflow_var_name_counter++);
Free_Var_Decl *over_free_var = new Free_Var_Decl(over_name);
over_var_list.push_back(over_free_var);
-
+
std::vector<CG_outputRepr *> lb_repr_list, ub_repr_list;
for (int i = 0; i < lb_list.size(); i++) {
lb_repr_list.push_back(
- output_lower_bound_repr(ocg,
- lb_list[i],
- bound.set_var(dim + 1), result.first, result.second,
- bound, Relation::True(bound.n_set()),
- std::vector<std::pair<CG_outputRepr *, int> >(
- bound.n_set(),
- std::make_pair(
- static_cast<CG_outputRepr *>(NULL),
- 0)),
- uninterpreted_symbols[stmt_num]));
+ output_lower_bound_repr(ocg,
+ lb_list[i],
+ bound.set_var(dim + 1), result.first, result.second,
+ bound, Relation::True(bound.n_set()),
+ std::vector<std::pair<CG_outputRepr *, int> >(
+ bound.n_set(),
+ std::make_pair(
+ static_cast<CG_outputRepr *>(NULL),
+ 0)),
+ uninterpreted_symbols[stmt_num]));
GEQ_Handle h = cond_lower.and_with_GEQ(lb_list[i]);
}
for (int i = 0; i < ub_list.size(); i++) {
ub_repr_list.push_back(
- output_upper_bound_repr(ocg, ub_list[i],
- bound.set_var(dim + 1), bound,
- std::vector<std::pair<CG_outputRepr *, int> >(
- bound.n_set(),
- std::make_pair(
- static_cast<CG_outputRepr *>(NULL),
- 0)),
- uninterpreted_symbols[stmt_num]));
+ output_upper_bound_repr(ocg, ub_list[i],
+ bound.set_var(dim + 1), bound,
+ std::vector<std::pair<CG_outputRepr *, int> >(
+ bound.n_set(),
+ std::make_pair(
+ static_cast<CG_outputRepr *>(NULL),
+ 0)),
+ uninterpreted_symbols[stmt_num]));
GEQ_Handle h = cond_upper.and_with_GEQ(ub_list[i]);
h.update_coef(cond_upper.get_local(over_free_var), -stride);
}
-
- CG_outputRepr *lbRepr, *ubRepr;
+
+ CG_outputRepr *lbRepr, *ubRepr;
if (lb_repr_list.size() > 1) {
//fprintf(stderr, "loop_unroll.cc createInvoke( max )\n");
lbRepr = ocg->CreateInvoke("max", lb_repr_list);
- }
- else if (lb_repr_list.size() == 1) {
+ } else if (lb_repr_list.size() == 1) {
lbRepr = lb_repr_list[0];
}
-
+
if (ub_repr_list.size() > 1) {
//fprintf(stderr, "loop_unroll.cc createInvoke( min )\n");
ubRepr = ocg->CreateInvoke("min", ub_repr_list);
- }
- else if (ub_repr_list.size() == 1) {
+ } else if (ub_repr_list.size() == 1) {
ubRepr = ub_repr_list[0];
}
-
+
// create overflow assignment
CG_outputRepr *rhs = ocg->CreatePlus(ocg->CreateMinus(ubRepr, lbRepr),
ocg->CreateInt(1));
@@ -512,7 +510,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
ocg->CreateAssignment(0, lhs, ocg->CreateInt(0)));
lhs = ocg->CreateIdent(over_name);
overflow_code = ocg->CreateAssignment(0, lhs, rhs);
-
+
// insert constraint 0 <= overflow < unroll_amount
Variable_ID v = overflow_constraint.get_local(over_free_var);
GEQ_Handle h1 = overflow_constraint_root->add_GEQ();
@@ -521,7 +519,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
h2.update_coef(v, -1);
h2.update_const(unroll_amount - 1);
}
-
+
// insert overflow statement
int overflow_stmt_num = -1;
if (overflow_code != NULL) {
@@ -537,7 +535,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
for (int i = 1; i < cleanup_split_level; i++)
overflow_IS.name_set_var(i, hull.set_var(i)->name());
overflow_IS.setup_names();
-
+
// build dumb transformation relation for overflow statement
Relation overflow_xform(cleanup_split_level - 1,
2 * (cleanup_split_level - 1) + 1);
@@ -546,20 +544,20 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
EQ_Handle h = f_root->add_EQ();
h.update_coef(overflow_xform.output_var(2 * i), 1);
h.update_coef(overflow_xform.input_var(i), -1);
-
+
h = f_root->add_EQ();
h.update_coef(overflow_xform.output_var(2 * i - 1), 1);
h.update_const(-lex[2 * i - 2]);
}
EQ_Handle h = f_root->add_EQ();
h.update_coef(
- overflow_xform.output_var(2 * (cleanup_split_level - 1) + 1),
- 1);
+ overflow_xform.output_var(2 * (cleanup_split_level - 1) + 1),
+ 1);
h.update_const(-lex[2 * (cleanup_split_level - 1)]);
-
+
shiftLexicalOrder(lex, 2 * cleanup_split_level - 2, 1);
Statement overflow_stmt;
-
+
overflow_stmt.code = overflow_code;
overflow_stmt.IS = overflow_IS;
overflow_stmt.xform = overflow_xform;
@@ -567,18 +565,18 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
overflow_stmt.ir_stmt_node = NULL;
for (int i = 0; i < level - 1; i++) {
overflow_stmt.loop_level[i].type =
- stmt[stmt_num].loop_level[i].type;
+ stmt[stmt_num].loop_level[i].type;
if (stmt[stmt_num].loop_level[i].type == LoopLevelTile
&& stmt[stmt_num].loop_level[i].payload >= level)
overflow_stmt.loop_level[i].payload = -1;
else
overflow_stmt.loop_level[i].payload =
- stmt[stmt_num].loop_level[i].payload;
+ stmt[stmt_num].loop_level[i].payload;
overflow_stmt.loop_level[i].parallel_level =
- stmt[stmt_num].loop_level[i].parallel_level;
+ stmt[stmt_num].loop_level[i].parallel_level;
}
-
- fprintf(stderr, "loop_unroll.cc L581 adding stmt %d\n", stmt.size());
+
+ fprintf(stderr, "loop_unroll.cc L581 adding stmt %d\n", stmt.size());
stmt.push_back(overflow_stmt);
uninterpreted_symbols.push_back(uninterpreted_symbols[stmt_num]);
@@ -586,12 +584,12 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
dep.insert();
overflow_stmt_num = stmt.size() - 1;
overflow[overflow_stmt_num] = over_var_list;
-
+
// update the global known information on overflow variable
this->known = Intersection(this->known,
Extend_Set(copy(overflow_constraint),
this->known.n_set() - overflow_constraint.n_set()));
-
+
// update dependence graph
DependenceVector dv;
dv.type = DEP_CONTROL;
@@ -628,12 +626,12 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
dep.connect(overflow_stmt_num, overflow_stmt_num, dv);
}
}
-
+
// split the loop so it can be fully unrolled
std::set<int> new_stmts = split(stmt_num, cleanup_split_level, cond_upper);
std::set<int> new_stmts2 = split(stmt_num, cleanup_split_level, cond_lower);
new_stmts.insert(new_stmts2.begin(), new_stmts2.end());
-
+
// check if unrolled statements can be trivially lumped together as one statement
bool can_be_lumped = true;
if (can_be_lumped) {
@@ -649,7 +647,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
if (!(stmt[*i].loop_level[j].type
== stmt[stmt_num].loop_level[j].type
&& stmt[*i].loop_level[j].payload
- == stmt[stmt_num].loop_level[j].payload)) {
+ == stmt[stmt_num].loop_level[j].payload)) {
can_be_lumped = false;
break;
}
@@ -690,7 +688,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
for (std::set<int>::iterator i = same_loop.begin();
i != same_loop.end(); i++) {
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[*i].second.begin();
+ dep.vertex[*i].second.begin();
j != dep.vertex[*i].second.end(); j++)
if (same_loop.find(j->first) != same_loop.end()) {
for (int k = 0; k < j->second.size(); k++)
@@ -706,38 +704,38 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
break;
}
}
-
+
// insert unrolled statements
int old_num_stmt = stmt.size();
if (!can_be_lumped) {
std::map<int, std::vector<int> > what_stmt_num;
-
+
for (int j = 1; j < unroll_amount; j++) {
for (std::set<int>::iterator i = same_loop.begin();
i != same_loop.end(); i++) {
Statement new_stmt;
-
+
std::vector<std::string> loop_vars;
std::vector<CG_outputRepr *> subs;
loop_vars.push_back(stmt[*i].IS.set_var(level)->name());
subs.push_back(
- ocg->CreatePlus(
- ocg->CreateIdent(
- stmt[*i].IS.set_var(level)->name()),
- ocg->CreateInt(j * stride)));
+ ocg->CreatePlus(
+ ocg->CreateIdent(
+ stmt[*i].IS.set_var(level)->name()),
+ ocg->CreateInt(j * stride)));
new_stmt.code = ocg->CreateSubstitutedStmt(0,
stmt[*i].code->clone(), loop_vars, subs);
-
+
new_stmt.IS = adjust_loop_bound(stmt[*i].IS, level, j * stride);
add_loop_stride(new_stmt.IS, bound, level - 1,
unroll_amount * stride);
-
+
new_stmt.xform = copy(stmt[*i].xform);
-
+
new_stmt.loop_level = stmt[*i].loop_level;
new_stmt.ir_stmt_node = NULL;
- fprintf(stderr, "loop_unroll.cc L740 adding stmt %d\n", stmt.size());
+ fprintf(stderr, "loop_unroll.cc L740 adding stmt %d\n", stmt.size());
stmt.push_back(new_stmt);
uninterpreted_symbols.push_back(uninterpreted_symbols[stmt_num]);
@@ -750,16 +748,16 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
i != same_loop.end(); i++)
add_loop_stride(stmt[*i].IS, bound, level - 1,
unroll_amount * stride);
-
+
// update dependence graph
if (stmt[stmt_num].loop_level[level - 1].type == LoopLevelOriginal) {
int dep_dim = stmt[stmt_num].loop_level[level - 1].payload;
int new_stride = unroll_amount * stride;
for (int i = 0; i < old_num_stmt; i++) {
std::vector<std::pair<int, DependenceVector> > D;
-
+
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[i].second.begin();
+ dep.vertex[i].second.begin();
j != dep.vertex[i].second.end();) {
if (same_loop.find(i) != same_loop.end()) {
if (same_loop.find(j->first) != same_loop.end()) {
@@ -772,7 +770,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
kk++)
if (what_stmt_num[i][kk] != -1
&& what_stmt_num[j->first][kk]
- != -1)
+ != -1)
dep.connect(what_stmt_num[i][kk],
what_stmt_num[j->first][kk],
dv);
@@ -782,35 +780,35 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
if (ub == lb
&& int_mod(lb,
static_cast<coef_t>(new_stride))
- == 0) {
+ == 0) {
D.push_back(
- std::make_pair(j->first, dv));
+ std::make_pair(j->first, dv));
for (int kk = 0; kk < unroll_amount - 1;
kk++)
if (what_stmt_num[i][kk] != -1
&& what_stmt_num[j->first][kk]
- != -1)
+ != -1)
dep.connect(
- what_stmt_num[i][kk],
- what_stmt_num[j->first][kk],
- dv);
+ what_stmt_num[i][kk],
+ what_stmt_num[j->first][kk],
+ dv);
} else if (lb == -posInfinity
&& ub == posInfinity) {
D.push_back(
- std::make_pair(j->first, dv));
+ std::make_pair(j->first, dv));
for (int kk = 0; kk < unroll_amount;
kk++)
if (kk == 0)
D.push_back(
- std::make_pair(j->first,
- dv));
+ std::make_pair(j->first,
+ dv));
else if (what_stmt_num[j->first][kk
- 1] != -1)
D.push_back(
- std::make_pair(
- what_stmt_num[j->first][kk
- - 1],
- dv));
+ std::make_pair(
+ what_stmt_num[j->first][kk
+ - 1],
+ dv));
for (int t = 0; t < unroll_amount - 1;
t++)
if (what_stmt_num[i][t] != -1)
@@ -819,15 +817,15 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
kk++)
if (kk == 0)
dep.connect(
- what_stmt_num[i][t],
- j->first, dv);
+ what_stmt_num[i][t],
+ j->first, dv);
else if (what_stmt_num[j->first][kk
- 1] != -1)
dep.connect(
- what_stmt_num[i][t],
- what_stmt_num[j->first][kk
- - 1],
- dv);
+ what_stmt_num[i][t],
+ what_stmt_num[j->first][kk
+ - 1],
+ dv);
} else {
for (int kk = 0; kk < unroll_amount;
kk++) {
@@ -836,49 +834,49 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
< int_mod(lb,
static_cast<coef_t>(new_stride)))
dv.lbounds[dep_dim] =
- floor(
- static_cast<double>(lb)
- / new_stride)
- * new_stride
- + new_stride;
+ floor(
+ static_cast<double>(lb)
+ / new_stride)
+ * new_stride
+ + new_stride;
else
dv.lbounds[dep_dim] =
- floor(
- static_cast<double>(lb)
- / new_stride)
- * new_stride;
+ floor(
+ static_cast<double>(lb)
+ / new_stride)
+ * new_stride;
}
if (ub != posInfinity) {
if (kk * stride
> int_mod(ub,
static_cast<coef_t>(new_stride)))
dv.ubounds[dep_dim] =
- floor(
- static_cast<double>(ub)
- / new_stride)
- * new_stride
- - new_stride;
+ floor(
+ static_cast<double>(ub)
+ / new_stride)
+ * new_stride
+ - new_stride;
else
dv.ubounds[dep_dim] =
- floor(
- static_cast<double>(ub)
- / new_stride)
- * new_stride;
+ floor(
+ static_cast<double>(ub)
+ / new_stride)
+ * new_stride;
}
if (dv.ubounds[dep_dim]
>= dv.lbounds[dep_dim]) {
if (kk == 0)
D.push_back(
- std::make_pair(
- j->first,
- dv));
+ std::make_pair(
+ j->first,
+ dv));
else if (what_stmt_num[j->first][kk
- 1] != -1)
D.push_back(
- std::make_pair(
- what_stmt_num[j->first][kk
- - 1],
- dv));
+ std::make_pair(
+ what_stmt_num[j->first][kk
+ - 1],
+ dv));
}
}
for (int t = 0; t < unroll_amount - 1;
@@ -890,80 +888,80 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
if (lb != -posInfinity) {
if (kk * stride
< int_mod(
- lb + t
- + 1,
- static_cast<coef_t>(new_stride)))
+ lb + t
+ + 1,
+ static_cast<coef_t>(new_stride)))
dv.lbounds[dep_dim] =
- floor(
- static_cast<double>(lb
- + (t
- + 1)
- * stride)
- / new_stride)
- * new_stride
- + new_stride;
+ floor(
+ static_cast<double>(lb
+ + (t
+ + 1)
+ * stride)
+ / new_stride)
+ * new_stride
+ + new_stride;
else
dv.lbounds[dep_dim] =
- floor(
- static_cast<double>(lb
- + (t
- + 1)
- * stride)
- / new_stride)
- * new_stride;
+ floor(
+ static_cast<double>(lb
+ + (t
+ + 1)
+ * stride)
+ / new_stride)
+ * new_stride;
}
if (ub != posInfinity) {
if (kk * stride
> int_mod(
- ub + t
- + 1,
- static_cast<coef_t>(new_stride)))
+ ub + t
+ + 1,
+ static_cast<coef_t>(new_stride)))
dv.ubounds[dep_dim] =
- floor(
- static_cast<double>(ub
- + (t
- + 1)
- * stride)
- / new_stride)
- * new_stride
- - new_stride;
+ floor(
+ static_cast<double>(ub
+ + (t
+ + 1)
+ * stride)
+ / new_stride)
+ * new_stride
+ - new_stride;
else
dv.ubounds[dep_dim] =
- floor(
- static_cast<double>(ub
- + (t
- + 1)
- * stride)
- / new_stride)
- * new_stride;
+ floor(
+ static_cast<double>(ub
+ + (t
+ + 1)
+ * stride)
+ / new_stride)
+ * new_stride;
}
if (dv.ubounds[dep_dim]
>= dv.lbounds[dep_dim]) {
if (kk == 0)
dep.connect(
- what_stmt_num[i][t],
- j->first,
- dv);
+ what_stmt_num[i][t],
+ j->first,
+ dv);
else if (what_stmt_num[j->first][kk
- 1] != -1)
dep.connect(
- what_stmt_num[i][t],
- what_stmt_num[j->first][kk
- - 1],
- dv);
+ what_stmt_num[i][t],
+ what_stmt_num[j->first][kk
+ - 1],
+ dv);
}
}
}
}
}
-
+
dep.vertex[i].second.erase(j++);
} else {
for (int kk = 0; kk < unroll_amount - 1; kk++)
if (what_stmt_num[i][kk] != -1)
dep.connect(what_stmt_num[i][kk], j->first,
j->second);
-
+
j++;
}
} else {
@@ -972,26 +970,26 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
for (int kk = 0; kk < unroll_amount - 1; kk++)
if (what_stmt_num[j->first][kk] != -1)
D.push_back(
- std::make_pair(
- what_stmt_num[j->first][kk],
- j->second[k]));
+ std::make_pair(
+ what_stmt_num[j->first][kk],
+ j->second[k]));
j++;
}
}
-
+
for (int j = 0; j < D.size(); j++)
dep.connect(i, D[j].first, D[j].second);
}
}
-
+
// reset lexical order for the unrolled loop body
std::set<int> new_same_loop;
-
+
int count = 0;
-
+
for (std::map<int, std::vector<int> >::iterator i =
- what_stmt_num.begin(); i != what_stmt_num.end(); i++) {
-
+ what_stmt_num.begin(); i != what_stmt_num.end(); i++) {
+
new_same_loop.insert(i->first);
for (int k = dim + 1; k < stmt[i->first].xform.n_out(); k += 2)
assign_const(stmt[i->first].xform, k,
@@ -1001,11 +999,11 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
for (int j = 0; j < i->second.size(); j++) {
new_same_loop.insert(i->second[j]);
for (int k = dim + 1; k < stmt[i->second[j]].xform.n_out(); k +=
- 2)
+ 2)
assign_const(stmt[i->second[j]].xform, k,
get_const(
- stmt[(what_stmt_num.begin())->first].xform,
- k, Output_Var) + count);
+ stmt[(what_stmt_num.begin())->first].xform,
+ k, Output_Var) + count);
count++;
}
}
@@ -1015,20 +1013,20 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
i != same_loop.end(); i++)
add_loop_stride(stmt[*i].IS, bound, level - 1,
unroll_amount * stride);
-
+
int max_level = stmt[stmt_num].loop_level.size();
std::vector<std::pair<int, int> > stmt_order;
for (std::set<int>::iterator i = same_loop.begin();
i != same_loop.end(); i++)
stmt_order.push_back(
- std::make_pair(
- get_const(stmt[*i].xform, 2 * max_level,
- Output_Var), *i));
+ std::make_pair(
+ get_const(stmt[*i].xform, 2 * max_level,
+ Output_Var), *i));
sort(stmt_order.begin(), stmt_order.end());
-
+
Statement new_stmt;
new_stmt.code = NULL;
- for (int j = 1; j < unroll_amount; j++) {
+ for (int j = 1; j < unroll_amount; j++) {
for (int i = 0; i < stmt_order.size(); i++) {
std::vector<std::string> loop_vars;
std::vector<CG_outputRepr *> subs;
@@ -1036,12 +1034,12 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
//fprintf(stderr, "loop_unroll.cc, will replace '%s with '%s+%d' ??\n",
// stmt[stmt_order[i].second].IS.set_var(level)->name().c_str(),
// stmt[stmt_order[i].second].IS.set_var(level)->name().c_str(), j * stride);
-
+
loop_vars.push_back(
- stmt[stmt_order[i].second].IS.set_var(level)->name());
+ stmt[stmt_order[i].second].IS.set_var(level)->name());
subs.push_back(
- ocg->CreatePlus(ocg->CreateIdent(stmt[stmt_order[i].second].IS.set_var(level)->name()),
- ocg->CreateInt(j * stride))); // BUG HERE
+ ocg->CreatePlus(ocg->CreateIdent(stmt[stmt_order[i].second].IS.set_var(level)->name()),
+ ocg->CreateInt(j * stride))); // BUG HERE
//fprintf(stderr, "loop_unroll.cc subs now has %d parts\n", subs.size());
//for (int k=0; k< subs.size(); k++) //fprintf(stderr, "subs[%d] = 0x%x\n", k, subs[k]);
@@ -1052,7 +1050,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
CG_outputRepr *code = ocg->CreateSubstitutedStmt(0,
- stmt[stmt_order[i].second].code->clone(),
+ stmt[stmt_order[i].second].code->clone(),
loop_vars,
subs);
@@ -1069,7 +1067,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
}
}
-
+
//fprintf(stderr, "new_stmt.IS = \n");
@@ -1084,13 +1082,13 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
if (stmt[stmt_num].has_inspector) fprintf(stderr, "OLD STMT HAS INSPECTOR\n");
else fprintf(stderr, "OLD STMT DOES NOT HAVE INSPECTOR\n");
- fprintf(stderr, "loop_unroll.cc L1083 adding stmt %d\n", stmt.size());
+ fprintf(stderr, "loop_unroll.cc L1083 adding stmt %d\n", stmt.size());
stmt.push_back(new_stmt);
uninterpreted_symbols.push_back(uninterpreted_symbols[stmt_num]);
uninterpreted_symbols_stringrepr.push_back(uninterpreted_symbols_stringrepr[stmt_num]);
dep.insert();
-
+
//fprintf(stderr, "update dependence graph\n");
// update dependence graph
if (stmt[stmt_num].loop_level[level - 1].type == LoopLevelOriginal) {
@@ -1098,14 +1096,14 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
int new_stride = unroll_amount * stride;
for (int i = 0; i < old_num_stmt; i++) {
std::vector<std::pair<int, std::vector<DependenceVector> > > D;
-
+
for (DependenceGraph::EdgeList::iterator j =
- dep.vertex[i].second.begin();
+ dep.vertex[i].second.begin();
j != dep.vertex[i].second.end();) {
if (same_loop.find(i) != same_loop.end()) {
if (same_loop.find(j->first) != same_loop.end()) {
std::vector<DependenceVector> dvs11, dvs12, dvs22,
- dvs21;
+ dvs21;
for (int k = 0; k < j->second.size(); k++) {
DependenceVector dv = j->second[k];
if (dv.type == DEP_CONTROL
@@ -1115,71 +1113,71 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
dvs22.push_back(dv);
} else
throw loop_error(
- "unrolled statements lumped together illegally");
+ "unrolled statements lumped together illegally");
} else {
coef_t lb = dv.lbounds[dep_dim];
coef_t ub = dv.ubounds[dep_dim];
if (ub == lb
&& int_mod(lb,
static_cast<coef_t>(new_stride))
- == 0) {
+ == 0) {
dvs11.push_back(dv);
dvs22.push_back(dv);
} else {
if (lb != -posInfinity)
dv.lbounds[dep_dim] = ceil(
- static_cast<double>(lb)
- / new_stride)
- * new_stride;
+ static_cast<double>(lb)
+ / new_stride)
+ * new_stride;
if (ub != posInfinity)
dv.ubounds[dep_dim] = floor(
- static_cast<double>(ub)
- / new_stride)
- * new_stride;
+ static_cast<double>(ub)
+ / new_stride)
+ * new_stride;
if (dv.ubounds[dep_dim]
>= dv.lbounds[dep_dim])
dvs11.push_back(dv);
-
+
if (lb != -posInfinity)
dv.lbounds[dep_dim] = ceil(
- static_cast<double>(lb)
- / new_stride)
- * new_stride;
+ static_cast<double>(lb)
+ / new_stride)
+ * new_stride;
if (ub != posInfinity)
dv.ubounds[dep_dim] = ceil(
- static_cast<double>(ub)
- / new_stride)
- * new_stride;
+ static_cast<double>(ub)
+ / new_stride)
+ * new_stride;
if (dv.ubounds[dep_dim]
>= dv.lbounds[dep_dim])
dvs21.push_back(dv);
-
+
if (lb != -posInfinity)
dv.lbounds[dep_dim] = floor(
- static_cast<double>(lb)
- / new_stride)
- * new_stride;
+ static_cast<double>(lb)
+ / new_stride)
+ * new_stride;
if (ub != posInfinity)
dv.ubounds[dep_dim] = floor(
- static_cast<double>(ub
- - stride)
- / new_stride)
- * new_stride;
+ static_cast<double>(ub
+ - stride)
+ / new_stride)
+ * new_stride;
if (dv.ubounds[dep_dim]
>= dv.lbounds[dep_dim])
dvs12.push_back(dv);
-
+
if (lb != -posInfinity)
dv.lbounds[dep_dim] = floor(
- static_cast<double>(lb)
- / new_stride)
- * new_stride;
+ static_cast<double>(lb)
+ / new_stride)
+ * new_stride;
if (ub != posInfinity)
dv.ubounds[dep_dim] = ceil(
- static_cast<double>(ub
- - stride)
- / new_stride)
- * new_stride;
+ static_cast<double>(ub
+ - stride)
+ / new_stride)
+ * new_stride;
if (dv.ubounds[dep_dim]
>= dv.lbounds[dep_dim])
dvs22.push_back(dv);
@@ -1192,10 +1190,10 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
dep.connect(old_num_stmt, old_num_stmt, dvs22);
if (dvs12.size() > 0)
D.push_back(
- std::make_pair(old_num_stmt, dvs12));
+ std::make_pair(old_num_stmt, dvs12));
if (dvs21.size() > 0)
dep.connect(old_num_stmt, i, dvs21);
-
+
dep.vertex[i].second.erase(j++);
} else {
dep.connect(old_num_stmt, j->first, j->second);
@@ -1204,17 +1202,17 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount,
} else {
if (same_loop.find(j->first) != same_loop.end())
D.push_back(
- std::make_pair(old_num_stmt, j->second));
+ std::make_pair(old_num_stmt, j->second));
j++;
}
}
-
+
for (int j = 0; j < D.size(); j++)
dep.connect(i, D[j].first, D[j].second);
}
}
}
-
+
//fprintf(stderr, " loop_unroll.cc returning new_stmts\n");
return new_stmts;
}