summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/chillAST/chillAST_node.hh2
-rwxr-xr-xinclude/ir_clang.hh13
-rw-r--r--include/ir_code.hh55
-rw-r--r--include/loop.hh4
-rwxr-xr-xlib/chillcg/include/code_gen/CG_chillRepr.h5
-rwxr-xr-xlib/chillcg/src/CG_chillBuilder.cc42
-rw-r--r--lib/codegen/CMakeLists.txt25
-rw-r--r--src/ast/node.cpp8
-rwxr-xr-xsrc/ir_clang.cc7
-rw-r--r--src/irtools.cc1
10 files changed, 68 insertions, 94 deletions
diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh
index 95480a4..0c92372 100644
--- a/include/chillAST/chillAST_node.hh
+++ b/include/chillAST/chillAST_node.hh
@@ -405,6 +405,8 @@ public:
//! Public interface for fixing child info, which can be called from anynode.
void fixChildInfo();
+
+ chillAST_Node* findContainingStmt();
};
diff --git a/include/ir_clang.hh b/include/ir_clang.hh
index 9b9e4be..4344f68 100755
--- a/include/ir_clang.hh
+++ b/include/ir_clang.hh
@@ -224,22 +224,13 @@ struct IR_chillScalarRef : public IR_ScalarRef {
struct IR_chillArrayRef : public IR_ArrayRef {
- //DeclRefExpr *as_;
- //chillAST_DeclRefExpr *chillDRE;
chillAST_ArraySubscriptExpr *chillASE;
int iswrite;
-
- // IR_chillArrayRef(const IR_Code *ir, DeclRefExpr *as, ParentMap *pMap = NULL) {
- // ir_ = ir;
- // fprintf(stderr, "new IR_chillArrayRef() CLANG ERROR\n"); exit(-1);
- //}
-
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;
- iswrite = write; // ase->imwrittento;
+ iswrite = write;
}
bool is_write() const;
@@ -492,6 +483,8 @@ public:
IR_ArrayRef *CreateArrayRef(const IR_ArraySymbol *sym, std::vector<omega::CG_outputRepr *> &index);
+ virtual bool FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B);
+
int ArrayIndexStartAt() { return 0; } // TODO FORTRAN
std::vector<IR_ScalarRef *> FindScalarRef(const omega::CG_outputRepr *repr) const;
diff --git a/include/ir_code.hh b/include/ir_code.hh
index 813fc0d..8de0f01 100644
--- a/include/ir_code.hh
+++ b/include/ir_code.hh
@@ -360,7 +360,7 @@ public:
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 = "") {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
@@ -370,26 +370,26 @@ public:
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");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
virtual IR_PointerSymbol *CreatePointerSymbol(const IR_Symbol *sym,
std::vector<omega::CG_outputRepr *> &size_repr) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
virtual IR_PointerSymbol *CreatePointerSymbol(const IR_CONSTANT_TYPE type,
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");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
virtual IR_PointerSymbol *CreatePointerSymbol(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");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
@@ -399,46 +399,46 @@ public:
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");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
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");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
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");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
}
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");
+ CHILL_ERROR("NOT IMPLEMENTED\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) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
virtual omega::CG_outputRepr *CreatePointerType(IR_CONSTANT_TYPE type) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
virtual omega::CG_outputRepr *CreatePointerType(omega::CG_outputRepr *type) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
virtual omega::CG_outputRepr *CreateScalarType(IR_CONSTANT_TYPE type) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
@@ -450,6 +450,7 @@ public:
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");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return std::vector<IR_PointerArrayRef *>();
}
@@ -457,6 +458,7 @@ public:
virtual bool parent_is_array(IR_ArrayRef *a) {
fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return false;
}
@@ -471,7 +473,7 @@ public:
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");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
@@ -488,66 +490,65 @@ public:
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) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
virtual void printStmt(const omega::CG_outputRepr *repr) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
}
virtual int getStmtType(const omega::CG_outputRepr *repr) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return 0;
}
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");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return IR_OP_MINUS;
}
virtual IR_Control *FromForStmt(const omega::CG_outputRepr *repr) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
// Manu:: Added functions for scalar expansion
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");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
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");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
virtual omega::CG_outputRepr *GetRHSExpression(omega::CG_outputRepr *code) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
virtual omega::CG_outputRepr *GetLHSExpression(omega::CG_outputRepr *code) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
virtual omega::CG_outputRepr *CreateMalloc(const IR_CONSTANT_TYPE type, std::string lhs,
omega::CG_outputRepr *size_repr) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
virtual omega::CG_outputRepr *CreateMalloc(omega::CG_outputRepr *type, std::string variable,
omega::CG_outputRepr *size_repr) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
virtual omega::CG_outputRepr *CreateFree(omega::CG_outputRepr *exp) {
- fprintf(stderr, "ir_code.hh SOME SUBCLASS OF ir_code did not implement CreateArrayRefRepr()\n");
+ CHILL_ERROR("NOT IMPLEMENTED\n");
return NULL;
}
diff --git a/include/loop.hh b/include/loop.hh
index 5af9975..554b005 100644
--- a/include/loop.hh
+++ b/include/loop.hh
@@ -117,12 +117,12 @@ public:
Loop(const IR_Control *control);
~Loop();
- omega::CG_outputRepr *getCode(int effort = 3) const; // TODO was 1
+ omega::CG_outputRepr *getCode(int effort = 1) const; // TODO was 1
//chillAST_Node* getCode(int effort, std::set<int> stmts) const;
void stencilASEPadded(int stmt_num);
- void printCode(int effort = 3) const;
+ void printCode(int effort = 1) const;
void addKnown(const omega::Relation &cond);
void print_internal_loop_structure() const;
bool isInitialized() const;
diff --git a/lib/chillcg/include/code_gen/CG_chillRepr.h b/lib/chillcg/include/code_gen/CG_chillRepr.h
index 34e9876..ea2048b 100755
--- a/lib/chillcg/include/code_gen/CG_chillRepr.h
+++ b/lib/chillcg/include/code_gen/CG_chillRepr.h
@@ -39,13 +39,11 @@ namespace omega {
CG_chillRepr(chillAST_Node *chillast) {
stmtclassname = strdup(chillast->getTypeString());
- //fprintf(stderr, "made new chillRepr of class %s\n", stmtclassname);
if (chillast->getType() == CHILLAST_NODE_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); // ??
@@ -72,12 +70,9 @@ namespace omega {
void dump() const { printChillNodes(); };
void Dump() const;
- //void DumpToFile(FILE *fp = stderr) const;
private:
-
char *stmtclassname; // chill
-
};
diff --git a/lib/chillcg/src/CG_chillBuilder.cc b/lib/chillcg/src/CG_chillBuilder.cc
index 51a02be..ef53e27 100755
--- a/lib/chillcg/src/CG_chillBuilder.cc
+++ b/lib/chillcg/src/CG_chillBuilder.cc
@@ -36,13 +36,6 @@ namespace omega {
chillAST_Node *SubCompoundStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
chillAST_Node *SubMemberExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
-
-
- // chillAST_Node *Sub( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); // fwd decl
-
-
-
-
chillAST_Node *substituteChill( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
if (n == NULL) {
fprintf(stderr, "substituteChill() pointer n == NULL\n"); // DIE
@@ -235,9 +228,6 @@ namespace omega {
chillAST_Node *SubCallExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
chillAST_CallExpr *CE = (chillAST_CallExpr *) n;
- //fprintf(stderr, "substituting for oldvar %s in ", oldvar );
- //CE->print(); printf("\n"); fflush(stdout);
-
int nargs = CE->getNumChildren();
for (int i=1; i<nargs; i++) {
CE->setChild(i,substituteChill( oldvar, newvar, CE->getChild(i), CE));
@@ -248,8 +238,6 @@ namespace omega {
chillAST_Node *SubReturnStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- //fprintf(stderr, "SubReturnStmt()\n");
-
chillAST_ReturnStmt *RS = (chillAST_ReturnStmt *)n;
if (RS->getRetVal()) RS->setRetVal(substituteChill(oldvar, newvar, RS->getRetVal(), RS));
return RS;
@@ -261,17 +249,18 @@ namespace omega {
chillAST_IfStmt *IS = (chillAST_IfStmt *)n;
//IS->print(0, stderr); fprintf(stderr, "\n\n");
chillAST_Node *sub;
- if ( sub = IS->getCond() ) IS->setCond( substituteChill(oldvar, newvar, sub, IS));
- if ( sub = IS->getThen() ) IS->setThen( substituteChill(oldvar, newvar, sub, IS));
- sub = IS->getElse(); //fprintf(stderr, "sub(else) = %p\n", sub);
- if ( sub = IS->getElse() ) IS->setElse( substituteChill(oldvar, newvar, sub, IS));
+ sub = IS->getCond();
+ if ( sub ) IS->setCond( substituteChill(oldvar, newvar, sub, IS));
+ sub = IS->getThen();
+ if ( sub ) IS->setThen( substituteChill(oldvar, newvar, sub, IS));
+ sub = IS->getElse();
+ if ( sub ) IS->setElse( substituteChill(oldvar, newvar, sub, IS));
return IS;
}
chillAST_Node *SubCompoundStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- //fprintf(stderr, "SubCompoundStmt()\n");
chillAST_CompoundStmt *CS = (chillAST_CompoundStmt *)n;
int numchildren = CS->getNumChildren();
@@ -285,14 +274,9 @@ namespace omega {
chillAST_Node *SubMemberExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- //fprintf(stderr, "SubMemberExpr( oldvar %s ) \n", oldvar);
chillAST_MemberExpr *ME = (chillAST_MemberExpr *)n;
-
- ME->base = substituteChill(oldvar, newvar, ME->base, ME );
-
-
- //
- return ME;
+ ME->base = substituteChill(oldvar, newvar, ME->base, ME );
+ return ME;
}
@@ -304,19 +288,11 @@ namespace omega {
}
CG_chillBuilder::CG_chillBuilder(chillAST_SourceFile *top, chillAST_FunctionDecl *func) {
- //fprintf(stderr, "\nCG_chillBuilder::CG_chillBuilder()\n");
toplevel = top;
currentfunction = func;
- //fprintf(stderr, "\nfunction is:\n"); currentfunction->print(); printf("\n\n"); fflush(stdout);
-
- symtab_ = currentfunction->getSymbolTable();
+ symtab_ = currentfunction->getParameters();
symtab2_ = currentfunction->getBody()->getSymbolTable();
-
- //printf("\nsymtab_:\n"); fflush(stdout);
- //printSymbolTable( symtab_ );
- //printf("\n\nsymtab2_:\n"); fflush(stdout);
- //printSymbolTable( symtab2_ );
}
CG_chillBuilder::~CG_chillBuilder() {
diff --git a/lib/codegen/CMakeLists.txt b/lib/codegen/CMakeLists.txt
index 324dd32..c414691 100644
--- a/lib/codegen/CMakeLists.txt
+++ b/lib/codegen/CMakeLists.txt
@@ -1,22 +1,23 @@
set(CG_SRC
- src/codegen.cc
- src/CG.cc
- src/CG_stringBuilder.cc
- src/CG_utils.cc
- )
+ src/codegen.cc
+ src/CG.cc
+ src/CG_stringBuilder.cc
+ src/CG_stringRepr.cc
+ src/CG_utils.cc
+ )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-write-strings")
include_directories(
- include
- ${OMEGAROOT}/include
- )
+ include
+ ${OMEGAROOT}/include
+)
add_library(codegen
- ${CG_SRC}
- )
+ ${CG_SRC}
+ )
install(TARGETS codegen
- ARCHIVE DESTINATION lib)
+ ARCHIVE DESTINATION lib)
install(DIRECTORY include
- DESTINATION .)
+ DESTINATION .)
diff --git a/src/ast/node.cpp b/src/ast/node.cpp
index dc0a913..c8a3c08 100644
--- a/src/ast/node.cpp
+++ b/src/ast/node.cpp
@@ -356,5 +356,11 @@ void chillAST_Node::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
}
}
-
+chillAST_Node* chillAST_Node::findContainingStmt() {
+ chillAST_Node* p = getParent();
+ if (p->isCompoundStmt()) return this;
+ if (p->isForStmt()) return this;
+ if (p->isIfStmt()) return this;
+ return p->findContainingStmt();
+}
diff --git a/src/ir_clang.cc b/src/ir_clang.cc
index 3f70856..e667411 100755
--- a/src/ir_clang.cc
+++ b/src/ir_clang.cc
@@ -2247,10 +2247,8 @@ IR_clangCode::IR_clangCode(const char *fname, const char *proc_name) : IR_Code()
localFD->dump();
CHILL_DEBUG_END
- 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
+ ocg_ = new omega::CG_chillBuilder(localFD->getSourceFile(),localFD); // ocg == omega code gen
chillfunc = localFD;
}
@@ -2408,6 +2406,9 @@ IR_ScalarRef *IR_clangCode::CreateScalarRef(const IR_ScalarSymbol *sym) {
//return (IR_ScalarRef *)NULL;
}
+bool IR_clangCode::FromSameStmt(IR_ArrayRef *A, IR_ArrayRef *B) {
+ return ((IR_chillArrayRef*)A)->chillASE->findContainingStmt() == ((IR_chillArrayRef*)A)->chillASE->findContainingStmt();
+}
IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector<omega::CG_outputRepr *> &index) {
fprintf(stderr, "IR_clangCode::CreateArrayRef() ir_clang.cc\n");
diff --git a/src/irtools.cc b/src/irtools.cc
index 68c9eac..55ef57f 100644
--- a/src/irtools.cc
+++ b/src/irtools.cc
@@ -536,7 +536,6 @@ 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);
}