diff options
-rw-r--r-- | include/chillAST/chillAST_def.hh | 6 | ||||
-rw-r--r-- | include/loop.hh | 1 | ||||
-rw-r--r-- | src/chillASTs.cc | 67 | ||||
-rwxr-xr-x | src/ir_clang.cc | 24 | ||||
-rw-r--r-- | src/printer/cfamily.cpp | 4 |
5 files changed, 29 insertions, 73 deletions
diff --git a/include/chillAST/chillAST_def.hh b/include/chillAST/chillAST_def.hh index acdce08..7a9528e 100644 --- a/include/chillAST/chillAST_def.hh +++ b/include/chillAST/chillAST_def.hh @@ -87,6 +87,7 @@ enum CHILLAST_PREPROCESSING_POSITION { // when tied to another statement CHILLAST_PREPROCESSING_IMMEDIATELYBEFORE // on same line }; +//! Parse to the most basic type char *parseUnderlyingType(const char *sometype); char *parseArrayParts(char *sometype); @@ -95,7 +96,10 @@ bool isRestrict(const char *sometype); char *splitTypeInfo(char *underlyingtype); -//! change "1024UL" to "1024" +//! remove UL from numbers, MODIFIES the argument! +/*! + * change "1024UL" to "1024" + */ char *ulhack(char *brackets); //! remove __restrict__ , MODIFIES the argument! diff --git a/include/loop.hh b/include/loop.hh index 7c746f6..8aa7851 100644 --- a/include/loop.hh +++ b/include/loop.hh @@ -162,6 +162,7 @@ public: void permute(const std::set<int> &active, const std::vector<int> &pi); void permute(int stmt_num, int level, const std::vector<int> &pi); void permute(const std::vector<int> &pi); + // TODO doc and usage needed void original(); void tile(int stmt_num, int level, int tile_size, int outer_level = 1, TilingMethodType method = StridedTile, int alignment_offset = 0, int alignment_multiple = 1); diff --git a/src/chillASTs.cc b/src/chillASTs.cc index 2711bb0..701832e 100644 --- a/src/chillASTs.cc +++ b/src/chillASTs.cc @@ -11,7 +11,6 @@ bool streq(const char *a, const char *b) { return !strcmp(a, b); } -//! Parse to the most basic type char *parseUnderlyingType(const char *sometype) { int len = strlen(sometype); CHILL_DEBUG_PRINT("parseUnderlyingType( %s )\n", sometype); @@ -116,7 +115,6 @@ chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table, cons return variableDeclFindSubpart(vd, subpart); } -//! remove UL from numbers, MODIFIES the argument! char *ulhack(char *brackets) { CHILL_DEBUG_PRINT("ulhack( \"%s\" -> \n", brackets); int len = strlen(brackets); @@ -132,8 +130,6 @@ char *ulhack(char *brackets) { return brackets; } - -//! remove __restrict__ , MODIFIES the argument! char *restricthack(char *typeinfo) { CHILL_DEBUG_PRINT("restricthack( \"%s\" -> \n", typeinfo); std::string r("__restrict__"); @@ -292,24 +288,17 @@ chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *a, char *p) { }; chillAST_VarDecl *chillAST_TypedefDecl::findSubpart(const char *name) { - //fprintf(stderr, "chillAST_TypedefDecl::findSubpart( %s )\n", name); - //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; } // 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, "subpart not found\n"); - - + CHILL_ERROR("subpart not found\n"); return NULL; } @@ -334,11 +323,8 @@ chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, const char *orig) { 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++) { - //fprintf(stderr, "comparing to '%s' to '%s'\n", nam, subparts[i]->varname); if (!strcmp(nam, subparts[i]->varname)) return subparts[i]; } fprintf(stderr, "chillAST_RecordDecl::findSubpart() couldn't find member NAMED %s in ", nam); @@ -349,26 +335,19 @@ chillAST_VarDecl *chillAST_RecordDecl::findSubpart(const char *nam) { 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++) { - //fprintf(stderr, "comparing '%s' to '%s'\n", typ, subparts[i]->vartype); 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); - return NULL; } 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! } void chillAST_RecordDecl::printStructure(int indent, FILE *fp) { - //fprintf(stderr, "chillAST_RecordDecl::printStructure()\n"); chillindent(indent, fp); if (isStruct) { fprintf(fp, "struct { ", name); @@ -2471,7 +2450,7 @@ chillAST_ParenExpr::chillAST_ParenExpr() { children.push_back(NULL); } -chillAST_ParenExpr::chillAST_ParenExpr(chillAST_Node *sub) { +chillAST_ParenExpr::chillAST_ParenExpr(chillAST_Node *sub):chillAST_ParenExpr() { setSubExpr(sub); } @@ -2626,12 +2605,11 @@ bool chillAST_IfStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, boo chillAST_Node *lessthanmacro(chillAST_Node *left, chillAST_Node *right) { - chillAST_ParenExpr *lp1 = new chillAST_ParenExpr(left); - chillAST_ParenExpr *rp1 = new chillAST_ParenExpr(right); + chillAST_Node *lp1 = left->clone(); + chillAST_Node *rp1 = right->clone(); chillAST_BinaryOperator *cond = new chillAST_BinaryOperator(lp1, "<", rp1); - - chillAST_ParenExpr *lp2 = new chillAST_ParenExpr(left); - chillAST_ParenExpr *rp2 = new chillAST_ParenExpr(right); + chillAST_Node *lp2 = left->clone(); + chillAST_Node *rp2 = right->clone(); chillAST_TernaryOperator *t = new chillAST_TernaryOperator("?", cond, lp2, rp2); @@ -2641,21 +2619,12 @@ chillAST_Node *lessthanmacro(chillAST_Node *left, chillAST_Node *right) { // 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()) { 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, "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 - // quit recursing. probably not correct in some horrible case return; } - //else fprintf(stderr, "this is not the function we're looking for\n"); } @@ -2687,21 +2656,18 @@ chillAST_FunctionDecl *findFunctionDecl(chillAST_Node *node, const char *procnam findFunctionDeclRecursive(node, procname, functions); if (functions.size() == 0) { - fprintf(stderr, "could not find function named '%s'\n", procname); + CHILL_ERROR("could not find function named '%s'\n", procname); exit(-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"); + CHILL_ERROR("oddly, found %d functions named '%s'\n", functions.size(), procname); for (int f = 0; f < functions.size(); f++) { - fprintf(stderr, "function %d %p %s\n", f, functions[f], functions[f]->functionName); + CHILL_ERROR("function %d %p %s\n", f, functions[f], functions[f]->functionName); } exit(-1); } - - //fprintf(stderr, "found the procedure named %s\n", procname); return functions[0]; } @@ -2710,33 +2676,18 @@ chillAST_SymbolTable *addSymbolToTable(chillAST_SymbolTable *st, chillAST_VarDec { chillAST_SymbolTable *s = st; 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++) { - //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); - - //printf("before:\n"); - //printSymbolTable( s ); fflush(stdout); - s->push_back(vd); // add it - - //printf("after:\n"); - //printSymbolTable( s ); fflush(stdout); return s; } diff --git a/src/ir_clang.cc b/src/ir_clang.cc index 5a14a63..51e5388 100755 --- a/src/ir_clang.cc +++ b/src/ir_clang.cc @@ -1782,22 +1782,25 @@ IR_clangCode::CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outp // 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); + + const omega::CG_chillRepr *crepr = static_cast<const omega::CG_chillRepr *>(repr); + std::vector<chillAST_Node *> chillstmts = crepr->getChillCode(); + + std::vector<chillAST_DeclRefExpr *> refs; + for (int i = 0; i < chillstmts.size(); i++) { + chillstmts[i]->gatherScalarRefs(refs,false); + } + for (int i = 0; i < refs.size(); i++) { + scalars.push_back(new IR_chillScalarRef(this, refs[i])); + } 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, new chillAST_DeclRefExpr( ((IR_chillScalarSymbol *) sym)->chillvd)); // uses VarDecl to mak a declrefexpr - //fprintf(stderr, "returning ScalarRef with dre 0x%x\n", sr->dre); return sr; - //return (IR_ScalarRef *)NULL; } bool IR_clangCode::FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B) { @@ -1817,15 +1820,12 @@ IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector chillAST_VarDecl *vd = c_sym->chillvd; 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]; int numnodes = CR->chillnodes.size(); if (1 != numnodes) { - fprintf(stderr, - "IR_clangCode::CreateArrayRef() array dimension %d has %d chillnodes\n", - i, numnodes); + CHILL_ERROR("IR_clangCode::CreateArrayRef() array dimension %d has %d chillnodes\n", i, numnodes); exit(-1); } diff --git a/src/printer/cfamily.cpp b/src/printer/cfamily.cpp index 552947a..488c884 100644 --- a/src/printer/cfamily.cpp +++ b/src/printer/cfamily.cpp @@ -357,9 +357,9 @@ int CFamily::getPrecS(chillAST_TernaryOperator *n) { void CFamily::printS(std::string ident, chillAST_TernaryOperator *n, std::ostream &o) { int prec = getPrec(n); printPrec(ident, n->getCond(), o, prec); - o << "" << n->op << ""; + o << " " << n->op << " "; printPrec(ident, n->getLHS(), o, prec); - o << ":"; + o << " : "; printPrec(ident, n->getRHS(), o, prec); } |