Skip to content
Snippets Groups Projects
Commit db8536cb authored by Johannes Mey's avatar Johannes Mey
Browse files

rewrite of OpenACC rewrites

parent 96c14267
No related branches found
No related tags found
No related merge requests found
...@@ -15,8 +15,10 @@ aspect Printing { ...@@ -15,8 +15,10 @@ aspect Printing {
// AccParallelStmt:AccStmt ::= AccClause* ; // AccParallelStmt:AccStmt ::= AccClause* ;
public void AccParallelStmt.prettyPrint(PrettyPrinter s) { public void AccParallelStmt.prettyPrint(PrettyPrinter s) {
s.append("!$acc parallel"); s.append("!$acc parallel");
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
...@@ -37,8 +39,10 @@ aspect Printing { ...@@ -37,8 +39,10 @@ aspect Printing {
// AccKernelsStmt:AccStmt ::= AccClause* ; // AccKernelsStmt:AccStmt ::= AccClause* ;
public void AccKernelsStmt.prettyPrint(PrettyPrinter s) { public void AccKernelsStmt.prettyPrint(PrettyPrinter s) {
s.append("!$acc kernels"); s.append("!$acc kernels");
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
...@@ -60,8 +64,10 @@ aspect Printing { ...@@ -60,8 +64,10 @@ aspect Printing {
// AccDataStmt:AccStmt ::= AccClause* ; // AccDataStmt:AccStmt ::= AccClause* ;
public void AccDataStmt.prettyPrint(PrettyPrinter s) { public void AccDataStmt.prettyPrint(PrettyPrinter s) {
s.append("!$acc data"); s.append("!$acc data");
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
...@@ -82,8 +88,10 @@ aspect Printing { ...@@ -82,8 +88,10 @@ aspect Printing {
// AccHostDataStmt:AccStmt ::= AccClause* ; // AccHostDataStmt:AccStmt ::= AccClause* ;
public void AccHostDataStmt.prettyPrint(PrettyPrinter s) { public void AccHostDataStmt.prettyPrint(PrettyPrinter s) {
s.append("!$acc host_data"); s.append("!$acc host_data");
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
...@@ -155,8 +163,10 @@ aspect Printing { ...@@ -155,8 +163,10 @@ aspect Printing {
// AccLoopStmt:AccStmt ::= AccClause* ; // AccLoopStmt:AccStmt ::= AccClause* ;
public void AccLoopStmt.prettyPrint(PrettyPrinter s) { public void AccLoopStmt.prettyPrint(PrettyPrinter s) {
s.append("!$acc loop"); s.append("!$acc loop");
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
...@@ -179,8 +189,10 @@ aspect Printing { ...@@ -179,8 +189,10 @@ aspect Printing {
// AccParallelLoopStmt:AccStmt ::= AccClause* ; // AccParallelLoopStmt:AccStmt ::= AccClause* ;
public void AccParallelLoopStmt.prettyPrint(PrettyPrinter s) { public void AccParallelLoopStmt.prettyPrint(PrettyPrinter s) {
s.append("!$acc parallel loop"); s.append("!$acc parallel loop");
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
...@@ -202,8 +214,10 @@ aspect Printing { ...@@ -202,8 +214,10 @@ aspect Printing {
// AccKernelsLoopStmt:AccStmt ::= AccClause* ; // AccKernelsLoopStmt:AccStmt ::= AccClause* ;
public void AccKernelsLoopStmt.prettyPrint(PrettyPrinter s) { public void AccKernelsLoopStmt.prettyPrint(PrettyPrinter s) {
s.append("!$acc kernels loop"); s.append("!$acc kernels loop");
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
...@@ -219,34 +233,39 @@ aspect Printing { ...@@ -219,34 +233,39 @@ aspect Printing {
// AccEnterDataDirective:AccDirective ::= AccClause* ; // AccEnterDataDirective:AccDirective ::= AccClause* ;
public void AccEnterDataDirective.prettyPrint(PrettyPrinter s) { public void AccEnterDataDirective.prettyPrint(PrettyPrinter s) {
s.append("!$acc enter data"); s.append("!$acc enter data");
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
// AccExitDataDirective:AccDirective ::= AccClause* ; // AccExitDataDirective:AccDirective ::= AccClause* ;
public void AccExitDataDirective.prettyPrint(PrettyPrinter s) { public void AccExitDataDirective.prettyPrint(PrettyPrinter s) {
s.append("!$acc exit data"); s.append("!$acc exit data");
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
// ACC 2.10 // ACC 2.10
// AccCacheDirective:AccDirective ::= Variable* ; // AccCacheDirective:AccDirective ::= Variable* ;
public void AccCacheDirective.prettyPrint(PrettyPrinter s) { public void AccCacheDirective.prettyPrint(PrettyPrinter s) {
s.append("!$acc cache"); s.append("!$acc cache").append("(");
s.ensureWs(); getVariableList().prettyPrintJoin(s, ",");
getVariableList().prettyPrintJoin(s, ", "); s.append(")").lb();
s.lb();
} }
// ACC 2.14.4 // ACC 2.14.4
// AccUpdateDirective:AccDirective ::= AccClause* ; // AccUpdateDirective:AccDirective ::= AccClause* ;
public void AccUpdateDirective.prettyPrint(PrettyPrinter s) { public void AccUpdateDirective.prettyPrint(PrettyPrinter s) {
s.append("!$acc update"); s.append("!$acc update");
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
...@@ -254,8 +273,10 @@ aspect Printing { ...@@ -254,8 +273,10 @@ aspect Printing {
// AccDeclareDirective:AccDirective ::= AccClause* ; // AccDeclareDirective:AccDirective ::= AccClause* ;
public void AccDeclareDirective.prettyPrint(PrettyPrinter s) { public void AccDeclareDirective.prettyPrint(PrettyPrinter s) {
s.append("!$acc declare"); s.append("!$acc declare");
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
...@@ -268,8 +289,10 @@ aspect Printing { ...@@ -268,8 +289,10 @@ aspect Printing {
getName().prettyPrint(s); getName().prettyPrint(s);
s.append(")"); s.append(")");
} }
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
...@@ -279,11 +302,13 @@ aspect Printing { ...@@ -279,11 +302,13 @@ aspect Printing {
s.append("!$acc wait"); s.append("!$acc wait");
if (getExprList().numChildren() > 0) { if (getExprList().numChildren() > 0) {
s.append("("); s.append("(");
getExprList().prettyPrintJoin(s, ", "); getExprList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
s.ensureWs(); for (AccClause clause : getAccClauseList()) {
getAccClauseList().prettyPrintJoin(s, " "); s.append(" ");
clause.prettyPrint(s);
}
s.lb(); s.lb();
} }
...@@ -301,7 +326,7 @@ aspect Printing { ...@@ -301,7 +326,7 @@ aspect Printing {
s.append("reduction("); s.append("reduction(");
getAccOperator().prettyPrint(s); getAccOperator().prettyPrint(s);
s.append(":"); s.append(":");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
...@@ -321,97 +346,97 @@ aspect Printing { ...@@ -321,97 +346,97 @@ aspect Printing {
public void AccCopyClause.prettyPrint(PrettyPrinter s) { public void AccCopyClause.prettyPrint(PrettyPrinter s) {
s.append("copy("); s.append("copy(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccCopyInClause.prettyPrint(PrettyPrinter s) { public void AccCopyInClause.prettyPrint(PrettyPrinter s) {
s.append("copyin("); s.append("copyin(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccCopyOutClause.prettyPrint(PrettyPrinter s) { public void AccCopyOutClause.prettyPrint(PrettyPrinter s) {
s.append("copyout("); s.append("copyout(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccCreateClause.prettyPrint(PrettyPrinter s) { public void AccCreateClause.prettyPrint(PrettyPrinter s) {
s.append("create("); s.append("create(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccDeleteClause.prettyPrint(PrettyPrinter s) { public void AccDeleteClause.prettyPrint(PrettyPrinter s) {
s.append("delete("); s.append("delete(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccDeviceClause.prettyPrint(PrettyPrinter s) { public void AccDeviceClause.prettyPrint(PrettyPrinter s) {
s.append("device("); s.append("device(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccSelfClause.prettyPrint(PrettyPrinter s) { public void AccSelfClause.prettyPrint(PrettyPrinter s) {
s.append("self("); s.append("self(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccHostClause.prettyPrint(PrettyPrinter s) { public void AccHostClause.prettyPrint(PrettyPrinter s) {
s.append("host("); s.append("host(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccFirstPrivateClause.prettyPrint(PrettyPrinter s) { public void AccFirstPrivateClause.prettyPrint(PrettyPrinter s) {
s.append("firstprivate("); s.append("firstprivate(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccPresentOrCopyClause.prettyPrint(PrettyPrinter s) { public void AccPresentOrCopyClause.prettyPrint(PrettyPrinter s) {
s.append("present_or_copy("); s.append("present_or_copy(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccPresentClause.prettyPrint(PrettyPrinter s) { public void AccPresentClause.prettyPrint(PrettyPrinter s) {
s.append("present("); s.append("present(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccPresentOrCopyInClause.prettyPrint(PrettyPrinter s) { public void AccPresentOrCopyInClause.prettyPrint(PrettyPrinter s) {
s.append("present_or_copyin("); s.append("present_or_copyin(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccPresentOrCopyOutClause.prettyPrint(PrettyPrinter s) { public void AccPresentOrCopyOutClause.prettyPrint(PrettyPrinter s) {
s.append("present_or_copyout("); s.append("present_or_copyout(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccPresentOrCreateClause.prettyPrint(PrettyPrinter s) { public void AccPresentOrCreateClause.prettyPrint(PrettyPrinter s) {
s.append("present_or_create("); s.append("present_or_create(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccPrivateClause.prettyPrint(PrettyPrinter s) { public void AccPrivateClause.prettyPrint(PrettyPrinter s) {
s.append("private("); s.append("private(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccUseDeviceClause.prettyPrint(PrettyPrinter s) { public void AccUseDeviceClause.prettyPrint(PrettyPrinter s) {
s.append("use_device("); s.append("use_device(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
...@@ -425,19 +450,19 @@ aspect Printing { ...@@ -425,19 +450,19 @@ aspect Printing {
public void AccDeviceTypeListClause.prettyPrint(PrettyPrinter s) { public void AccDeviceTypeListClause.prettyPrint(PrettyPrinter s) {
s.append("device_type("); s.append("device_type(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccTileClause.prettyPrint(PrettyPrinter s) { public void AccTileClause.prettyPrint(PrettyPrinter s) {
s.append("tile("); s.append("tile(");
getExprList().prettyPrintJoin(s, ", "); getExprList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccWaitClause.prettyPrint(PrettyPrinter s) { public void AccWaitClause.prettyPrint(PrettyPrinter s) {
s.append("wait("); s.append("wait(");
getExprList().prettyPrintJoin(s, ", "); getExprList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
...@@ -476,9 +501,9 @@ aspect Printing { ...@@ -476,9 +501,9 @@ aspect Printing {
} }
public void AccGangClause.prettyPrint(PrettyPrinter s) { public void AccGangClause.prettyPrint(PrettyPrinter s) {
if (hasNumGangs()) { if (hasNum()) {
s.append("gang("); s.append("gang(");
getNumGangs().prettyPrint(s); getNum().prettyPrint(s);
s.append(")"); s.append(")");
} else { } else {
s.append("gang"); s.append("gang");
...@@ -486,9 +511,9 @@ aspect Printing { ...@@ -486,9 +511,9 @@ aspect Printing {
} }
public void AccWorkerClause.prettyPrint(PrettyPrinter s) { public void AccWorkerClause.prettyPrint(PrettyPrinter s) {
if (hasNumWorkers()) { if (hasNum()) {
s.append("worker("); s.append("worker(");
getNumWorkers().prettyPrint(s); getNum().prettyPrint(s);
s.append(")"); s.append(")");
} else { } else {
s.append("worker"); s.append("worker");
...@@ -496,9 +521,9 @@ aspect Printing { ...@@ -496,9 +521,9 @@ aspect Printing {
} }
public void AccVectorClause.prettyPrint(PrettyPrinter s) { public void AccVectorClause.prettyPrint(PrettyPrinter s) {
if (hasVectorLength()) { if (hasNum()) {
s.append("vector("); s.append("vector(");
getVectorLength().prettyPrint(s); getNum().prettyPrint(s);
s.append(")"); s.append(")");
} else { } else {
s.append("vector"); s.append("vector");
...@@ -507,13 +532,13 @@ aspect Printing { ...@@ -507,13 +532,13 @@ aspect Printing {
public void AccDeviceResidentClause.prettyPrint(PrettyPrinter s) { public void AccDeviceResidentClause.prettyPrint(PrettyPrinter s) {
s.append("device_resident("); s.append("device_resident(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
public void AccLinkClause.prettyPrint(PrettyPrinter s) { public void AccLinkClause.prettyPrint(PrettyPrinter s) {
s.append("link("); s.append("link(");
getVariableList().prettyPrintJoin(s, ", "); getVariableList().prettyPrintJoin(s, ",");
s.append(")"); s.append(")");
} }
......
...@@ -3049,14 +3049,15 @@ Allocation allocation = ...@@ -3049,14 +3049,15 @@ Allocation allocation =
//// VariableAllocateObject:AllocateObject ::= VariableName ; //// VariableAllocateObject:AllocateObject ::= VariableName ;
//// StructureComponentAllocateObject:AllocateObject ::= StructureComponent ; //// StructureComponentAllocateObject:AllocateObject ::= StructureComponent ;
AllocateObject allocate_object = AllocateObject allocate_object =
n:name s:structure_component
{ {
yyValue = new NameAllocateObject(n); yyValue = new StructureComponentAllocateObject(s);
} }
/ s:structure_component / n:name
{ {
yyValue = new StructureComponentAllocateObject(s); yyValue = new NameAllocateObject(n);
} }
; ;
//// // R633 //// // R633
......
...@@ -27,42 +27,6 @@ aspect AmbiguityResoler { ...@@ -27,42 +27,6 @@ aspect AmbiguityResoler {
// } // }
// } // }
rewrite AccLoopStmt {
when (containedCollapseOne() != null)
to AccLoopStmt {
ASTNode parent = getParent();
if(parent!=null){
int i = containedCollapseOne().getParent().getIndexOfChild(containedCollapseOne());
if(i>-1){
parent.removeChild(i);
}
}
return this;
}
}
// TODO support the collapse optimisation in all Acc Statements
syn AccCollapseClause AccStmt.containedCollapseOne();
eq AccStmt.containedCollapseOne() = null;
eq AccLoopStmt.containedCollapseOne() {
for (AccClause clause: getAccClauseList()) {
if (clause.isCollapseOne() != null) {
return clause.isCollapseOne();
}
}
return null;
}
syn AccCollapseClause AccClause.isCollapseOne();
eq AccClause.isCollapseOne() = null;
eq AccCollapseClause.isCollapseOne() {
if (getCount().getDigitString().getDigits().equals("1")) {
return this;
} else {
return null;
}
}
/** /**
* C624 (R618) Exactly one part-ref shall have nonzero rank, and either the final part-ref shall * C624 (R618) Exactly one part-ref shall have nonzero rank, and either the final part-ref shall
......
...@@ -33,9 +33,13 @@ List<Variable> var_list = ...@@ -33,9 +33,13 @@ List<Variable> var_list =
; ;
List<Variable> p_var_list = List<Variable> p_var_list =
LPAREN vl:(COMMA yyValue:variable)* RPAREN LPAREN v:variable vl:(COMMA yyValue:variable)* RPAREN
{ {
yyValue = new List().addAll(vl.list()); yyValue = new List().add(v).addAll(vl.list());
}
/ LPAREN RPAREN
{
yyValue = new List();
} }
; ;
...@@ -49,7 +53,7 @@ List<Expr> expr_list = ...@@ -49,7 +53,7 @@ List<Expr> expr_list =
//// // An AccStmt does not have a label or a comment (unlike Fortran statements). //// // An AccStmt does not have a label or a comment (unlike Fortran statements).
//// // It must, however, begin with ""!$acc" and end with a line break //// // It must, however, begin with ""!$acc" and end with a line break
//// abstract AccStmt ; //// abstract AccStmt ;
//// abstract AccAbstractDataStmt ::= AccClause* ; //// abstract AccAbstractDataStmt:AccStmt ::= AccClause* ;
// constructs ------------------------------------------------------------------ // constructs ------------------------------------------------------------------
...@@ -549,7 +553,7 @@ AccCopyClause acc_copy_clause = ...@@ -549,7 +553,7 @@ AccCopyClause acc_copy_clause =
; ;
//// AccCopyInClause:AccDataClause ; //// AccCopyInClause:AccDataClause ;
//// AccPresentOrCopyInClause:AccCopyClause ; //// AccPresentOrCopyInClause:AccCopyInClause ;
AccCopyInClause acc_copyin_clause = AccCopyInClause acc_copyin_clause =
A_COPYIN list:p_var_list A_COPYIN list:p_var_list
{ {
...@@ -562,8 +566,8 @@ AccCopyInClause acc_copyin_clause = ...@@ -562,8 +566,8 @@ AccCopyInClause acc_copyin_clause =
; ;
//// AccCopyOutClause:AccDataClause ; //// AccCopyOutClause:AccDataClause ;
//// AccPresentOrCopyOutClause:AccCopyClause ; //// AccPresentOrCopyOutClause:AccCopyOutClause ;
AccCopyOutClause acc_copyin_clause = AccCopyOutClause acc_copyout_clause =
A_COPYOUT list:p_var_list A_COPYOUT list:p_var_list
{ {
yyValue = new AccCopyOutClause(list); yyValue = new AccCopyOutClause(list);
...@@ -804,7 +808,8 @@ AccSeqClause acc_seq_clause = ...@@ -804,7 +808,8 @@ AccSeqClause acc_seq_clause =
} }
; ;
//// AccGangClause:AccClause ::= [NumGangs:IntLiteralConstant] ; //// abstract AccExecutionModeClause:AccClause ::= [Num:IntLiteralConstant] ;
//// AccGangClause:AccExecutionModeClause ;
AccGangClause acc_gang_clause = AccGangClause acc_gang_clause =
A_GANG LPAREN n:int_literal_constant RPAREN A_GANG LPAREN n:int_literal_constant RPAREN
{ {
...@@ -816,7 +821,7 @@ AccGangClause acc_gang_clause = ...@@ -816,7 +821,7 @@ AccGangClause acc_gang_clause =
} }
; ;
//// AccWorkerClause:AccClause ::= [NumWorkers:IntLiteralConstant]; //// AccWorkerClause:AccExecutionModeClause;
AccWorkerClause acc_worker_clause = AccWorkerClause acc_worker_clause =
A_WORKER LPAREN n:int_literal_constant RPAREN A_WORKER LPAREN n:int_literal_constant RPAREN
...@@ -829,7 +834,7 @@ AccWorkerClause acc_worker_clause = ...@@ -829,7 +834,7 @@ AccWorkerClause acc_worker_clause =
} }
; ;
//// AccVectorClause:AccClause ::= [VectorLength:IntLiteralConstant] ; //// AccVectorClause:AccExecutionModeClause ;
AccVectorClause acc_vector_clause = AccVectorClause acc_vector_clause =
A_VECTOR LPAREN n:int_literal_constant RPAREN A_VECTOR LPAREN n:int_literal_constant RPAREN
{ {
......
aspect OpenAccRewrites {
rewrite AccParallelLoopConstruct {
to AccParallelConstruct {
List<AccClause> parallelClauses = new List<AccClause>();
List<AccClause> loopClauses = new List<AccClause>();
for (AccClause clause : getAccParallelLoopStmt().getAccClauseList()) {
if (clause.prefersLoop()) {
loopClauses.add(clause);
} else {
parallelClauses.add(clause);
}
}
AccLoopConstruct loop = new AccLoopConstruct(new AccLoopStmt(loopClauses), getDoConstruct(), new Opt<>(new AccEndLoopStmt()));
return new AccParallelConstruct(
new AccParallelStmt(parallelClauses),
new Block(new List<ExecutionPartConstruct>().add(new ExecutableConstruct_ExecutionPartConstruct(loop))),
new AccEndParallelStmt()
);
}
}
rewrite AccKernelsLoopConstruct {
to AccKernelsConstruct {
List<AccClause> kernelsClauses = new List<AccClause>();
List<AccClause> loopClauses = new List<AccClause>();
for (AccClause clause : getAccKernelsLoopStmt().getAccClauseList()) {
if (clause.prefersLoop()) {
loopClauses.add(clause);
} else {
kernelsClauses.add(clause);
}
}
AccLoopConstruct loop = new AccLoopConstruct(new AccLoopStmt(loopClauses), getDoConstruct(), new Opt<>(new AccEndLoopStmt()));
return new AccKernelsConstruct(
new AccKernelsStmt(kernelsClauses),
new Block(new List<ExecutionPartConstruct>().add(new ExecutableConstruct_ExecutionPartConstruct(loop))),
new AccEndKernelsStmt()
);
}
}
syn boolean AccClause.prefersLoop();
eq AccDataClause.prefersLoop() = false;
eq AccClause.prefersLoop() = false;
eq AccCollapseClause.prefersLoop() = true;
eq AccExecutionModeClause.prefersLoop() = true;
eq AccSeqClause.prefersLoop() = true;
eq AccAutoClause.prefersLoop() = true;
eq AccTileClause.prefersLoop() = true;
eq AccDeviceTypeClause.prefersLoop() = true;
eq AccIndependentClause.prefersLoop() = true;
eq AccPrivateClause.prefersLoop() = true;
eq AccReductionClause.prefersLoop() = true;
rewrite AccStmt {
when (containedRemovableClause() != null)
to AccStmt {
ASTNode parent = containedRemovableClause().getParent();
int i = parent.getIndexOfChild(containedRemovableClause());
if(i>-1){
parent.removeChild(i);
}
return this;
}
}
syn AccClause AccStmt.containedRemovableClause();
eq AccStmt.containedRemovableClause() = null;
eq AccAbstractDataStmt.containedRemovableClause() {
for (AccClause clause: getAccClauseList()) {
if (clause.canBeRemoved()) {
return clause;
}
}
return null;
}
eq AccLoopStmt.containedRemovableClause() {
for (AccClause clause: getAccClauseList()) {
if (clause.canBeRemoved()) {
return clause;
}
}
return null;
}
syn boolean AccClause.canBeRemoved() = false;
eq AccDataClause.canBeRemoved() {
return (getVariableList().numChildren() == 0);
}
eq AccCollapseClause.canBeRemoved() {
return getCount().getDigitString().getDigits().equals("1");
}
rewrite AccLoopStmt {
when (containedRemovableClause() != null)
to AccLoopStmt {
ASTNode parent = containedRemovableClause().getParent();
int i = parent.getIndexOfChild(containedRemovableClause());
if(i>-1){
parent.removeChild(i);
}
return this;
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment