Subject: Re: segment fault.

From: Zheng Gengbin <[email-masked]>
Date: Tue, 6 May 1997 10:06:19 +0800 (EAT)

That is a little bug . trans1  got the wrong  pointer in
this combine directive when converting the combine directive to separating
directive .
	Now it is ok. I will attach a new combine.C here .

On Mon, 5 May 1997, Guansong Zhang wrote:

> trans1 seems segment fault to the following program, please let me know the
> reason as soon as possible.
> 
> Thanks.
> 
>       program potts2d
>       integer ,  parameter:: m=64
>       integer ,  parameter:: n=64
>       integer ,  parameter:: q=4
> !HPF$      processors procs(4)
> !HPF$      template,distribute  (*,block) onto  procs :: RECTANGLE(m,n)
>       real ,  parameter:: cup=(-4.0)
>       integer ,  dimension(1:m,1:n):: latt
> !HPF$      align (:,:) with RECTANGLE :: latt
>       integer ,  dimension(1:m,1:n):: sh_tmp
> !HPF$      align (:,:) with RECTANGLE :: sh_tmp
>       integer ,  dimension(1:m,1:n):: add_tmp
> !HPF$      align (:,:) with RECTANGLE :: add_tmp
>       integer ,  dimension(1:m,1:n):: itmp
> !HPF$      align (:,:) with RECTANGLE :: itmp
>       real ,  dimension(1:m,1:n):: tmp,p
> !HPF$      align (:,:) with RECTANGLE :: tmp
> !HPF$      align (:,:) with RECTANGLE :: p
>       logical ,  dimension(1:m,1:n):: mask
> !HPF$      align (:,:) with RECTANGLE :: mask
> 
> 	end
> 
> 
> 

***************************************************************************
*     Zheng Gengbin                 *                                     *
*                                   *                                     *
*  Dept. of Computer Science        *  Phone:  86-10-2585088              *
*         & Technology              *  Email:                             *
*                                   *      [email-masked]   *
*  Peking University P.R.China      *  Mail:                              *
*                                   *      Room 2106 ,Building 46,        *
*                                   *      Peking University, P.R.China   *
***************************************************************************
//			combine.C
//
//		transform_combined()
//
// written by Zheng Gengbin

/*
This pass transform combined directive to several directives equally .
first delete the dimension_op , and add the dimension info directly to
the varibable list .
split the combined directive to sevaral directives by variable list according to 
every attribute .
As to align_op ,if align subscript is omitted , add it back according to the
dimension of the array .
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "compilerApi.h"
#include "pass.h"

//  add the dim in DIMENSION_OP to the var list
void	adjust_var_list(SgStatement *s,SgExpression *dim)
{
	SgExpression *var_list,*ele;

	for (var_list=s->expr(0) ; var_list; var_list=var_list->rhs()) 
	{
		ele=var_list->lhs();
		if (ele->variant() != ARRAY_REF) 
		{
			ele->thellnd->variant=ARRAY_REF;
			ele->setLhs(dim);
		}
	}
}

void create_proc_or_temp__stmt(int variant,SgStatement *s)
{
	SgStatement *decl;

	//decl=new SgVarDeclStmt(* s->expr(0),* s->expr(1)->type());
	SgExpression *type_op = new SgExpression(TYPE_OP,NULL,NULL,NULL,s->expr(1)->type());
	decl=new SgStatement(variant,NULL,NULL,s->expr(0),type_op,NULL);
	//decl->setVariant(variant);
	s->insertStmtBefore(*decl,* s->controlParent() );
}

void create_dist_or_align_stmts(int variant,SgStatement *s,SgExpression *attr)
{
	SgStatement *decl;
	SgExpression *var_list,*var,*op,*att;
	SgExpression *src_list=NULL,*spec_list=NULL;

	//op=s->expr(2)->lhs()->lhs();       //point to DISTRIBUTE_OP or ALIGN_OP
	op=attr->lhs();

	// fill in the align_source_list if missed !!
	if (op->variant() == ALIGN_OP)
	{
		SgSymbol *align_target=op->rhs()->rhs()->symbol();
		SgExpression *align_source = op->lhs();
		SgExpression *align_spec = op->rhs()->rhs()->lhs();

		if (( align_source == NULL || align_spec == NULL ) && align_target->type()->variant()==T_ARRAY)
		{
			for (int i = 0; i<((SgArrayType*)(align_target->type()))->dimension() ; i++)
			{
			   SgExpression *node;
			   if (align_spec == NULL ) {
				node=new SgExpression (DDOT,NULL,NULL,NULL);
				spec_list=new SgExpression(EXPR_LIST,node,spec_list,NULL);
                           }
			   if (align_source == NULL ) {
				node=new SgExpression (COLON_OP,NULL,NULL,NULL);
				src_list=new SgExpression(EXPR_LIST,node,src_list,NULL);
			   }
			}
		}
	}

	for (var_list=s->expr(0) ; var_list; var_list=var_list->rhs()) 
	{
		var=new SgExpression(EXPR_LIST,var_list->lhs()->copyPtr(),NULL,NULL);
		SgExpression *new_op = op->copyPtr();
		// add  align source or target list if anyone is missed
		if ( src_list )
			new_op->setLhs(src_list);
		if ( spec_list )
		{
			new_op->rhs()->rhs()->setLhs(spec_list);
			new_op->rhs()->rhs()->thellnd->variant = ARRAY_REF;
		}
		att=new SgExpression(EXPR_LIST , new_op,NULL,NULL);
		decl=new SgStatement(variant,NULL,NULL,var, s->expr(1),att);
		s->insertStmtBefore(*decl,* s->controlParent() );
	}
}

void transform_combined(SgStatement *s)
{
	SgExpression  *var_list,*attr_list,*attr;
	SgStatement   *nstmt;

	var_list=s->expr(0);
	attr_list=s->expr(2);

	// deal with dimension first
	for (attr_list=s->expr(2) ; attr_list ; attr_list=attr_list->rhs())
	{
		attr=attr_list->lhs();
		if (attr->variant() == DIMENSION_OP )
		{
			adjust_var_list(s,attr->lhs());
		}
	}

	for (attr_list=s->expr(2) ; attr_list ; attr_list=attr_list->rhs())
	{
		attr=attr_list->lhs();
		switch (attr->variant())
		{
		case PROCESSORS_VAL:
			create_proc_or_temp__stmt(PROCESSORS_STMT,s);
			break;
		case TEMPLATE_VAL:
			create_proc_or_temp__stmt(TEMPLATE_STMT,s);
			break;
		case DISTRIBUTE_ATT:
			create_dist_or_align_stmts(DISTRIBUTE_DECL,s,attr);
			break;
		case ALIGN_ATT:
			create_dist_or_align_stmts(ALIGN_DECL,s,attr);
			break;
		case INHERIT_OP:
		case DYNAMIC_OP:
			// do nothing ?
			break;
		}
	}

	// delete this statement
	s->deleteStmt();
}

---

From: Zheng Gengbin <[email-masked]>
Date: Wed, 7 May 1997 18:59:19 +0800 (EAT)

On Tue, 6 May 1997, Guansong Zhang wrote:

> On May 6, 10:06am, Zheng Gengbin wrote:
> > Subject: Re: segment fault.
> >
> >
> Please try this again, this time trans1 won't core dump, but it will produce
> some code nor parsable by hpf2dep.
> 
> !HPF$      distribute RECTANGLE(m,n)  (*,block) onto  procs
> 
> it seems the (m,n) should not be there.
> 
> Guansong
> 

	It is all right now . Try the combine.C again .

Zheng

//			combine.C
//
//		transform_combined()
//

/*

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "compilerApi.h"
#include "pass.h"

	for (var_list=s->expr(0) ; var_list; var_list=var_list->rhs()) 
	{
		SgExpression *ele = var_list->lhs();
		if ( ele->variant() == ARRAY_REF ) 
			ele = new SgVarRefExp(ele->symbol());
		else
			ele = ele->copyPtr();
		var=new SgExpression(EXPR_LIST,ele,NULL,NULL);
		SgExpression *new_op = op->copyPtr();
		// add  align source or target list if anyone is missed
		if ( src_list )
			new_op->setLhs(src_list);
		if ( spec_list )
		{
			new_op->rhs()->rhs()->setLhs(spec_list);
			new_op->rhs()->rhs()->thellnd->variant = ARRAY_REF;
		}
		att=new SgExpression(EXPR_LIST , new_op,NULL,NULL);
		decl=new SgStatement(variant,NULL,NULL,var, s->expr(1),att);
		s->insertStmtBefore(*decl,* s->controlParent() );
	}
}

	var_list=s->expr(0);
	attr_list=s->expr(2);

	// delete this statement
	s->deleteStmt();
}